From owner-svn-src-head@freebsd.org Mon Jun 17 16:43:35 2019 Return-Path: Delivered-To: svn-src-head@mailman.ysv.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mailman.ysv.freebsd.org (Postfix) with ESMTP id BD87215BF0C1; Mon, 17 Jun 2019 16:43:34 +0000 (UTC) (envelope-from ian@FreeBSD.org) Received: from mxrelay.nyi.freebsd.org (mxrelay.nyi.freebsd.org [IPv6:2610:1c1:1:606c::19:3]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) server-signature RSA-PSS (4096 bits) client-signature RSA-PSS (4096 bits) client-digest SHA256) (Client CN "mxrelay.nyi.freebsd.org", Issuer "Let's Encrypt Authority X3" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 604797168F; Mon, 17 Jun 2019 16:43:34 +0000 (UTC) (envelope-from ian@FreeBSD.org) Received: from repo.freebsd.org (repo.freebsd.org [IPv6:2610:1c1:1:6068::e6a:0]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (Client did not present a certificate) by mxrelay.nyi.freebsd.org (Postfix) with ESMTPS id 38E39670; Mon, 17 Jun 2019 16:43:34 +0000 (UTC) (envelope-from ian@FreeBSD.org) Received: from repo.freebsd.org ([127.0.1.37]) by repo.freebsd.org (8.15.2/8.15.2) with ESMTP id x5HGhYC4098330; Mon, 17 Jun 2019 16:43:34 GMT (envelope-from ian@FreeBSD.org) Received: (from ian@localhost) by repo.freebsd.org (8.15.2/8.15.2/Submit) id x5HGhXq8098329; Mon, 17 Jun 2019 16:43:33 GMT (envelope-from ian@FreeBSD.org) Message-Id: <201906171643.x5HGhXq8098329@repo.freebsd.org> X-Authentication-Warning: repo.freebsd.org: ian set sender to ian@FreeBSD.org using -f From: Ian Lepore Date: Mon, 17 Jun 2019 16:43:33 +0000 (UTC) To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org Subject: svn commit: r349144 - head/usr.sbin/pwm X-SVN-Group: head X-SVN-Commit-Author: ian X-SVN-Commit-Paths: head/usr.sbin/pwm X-SVN-Commit-Revision: 349144 X-SVN-Commit-Repository: base MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-Rspamd-Queue-Id: 604797168F X-Spamd-Bar: -- Authentication-Results: mx1.freebsd.org X-Spamd-Result: default: False [-2.98 / 15.00]; local_wl_from(0.00)[FreeBSD.org]; NEURAL_HAM_MEDIUM(-1.00)[-0.999,0]; NEURAL_HAM_SHORT(-0.98)[-0.977,0]; NEURAL_HAM_LONG(-1.00)[-1.000,0]; ASN(0.00)[asn:11403, ipnet:2610:1c1:1::/48, country:US] X-BeenThere: svn-src-head@freebsd.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: SVN commit messages for the src tree for head/-current List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Mon, 17 Jun 2019 16:43:35 -0000 Author: ian Date: Mon Jun 17 16:43:33 2019 New Revision: 349144 URL: https://svnweb.freebsd.org/changeset/base/349144 Log: Follow changes in the pwmc(4) driver in relation to device filenames. The driver now names its cdev nodes pwmcX.Y where X is unit number and Y is the channel within that unit. Change the default device name from pwmc0 to pwmc0.0. The driver now puts cdev files and label aliases in the /dev/pwm directory, so allow the user to provide unqualified names with -f and automatically prepend the /dev/pwm part for them. Update the examples in the manpage to show the new device name format and location within /dev/pwm. Modified: head/usr.sbin/pwm/pwm.8 head/usr.sbin/pwm/pwm.c Modified: head/usr.sbin/pwm/pwm.8 ============================================================================== --- head/usr.sbin/pwm/pwm.8 Mon Jun 17 16:26:43 2019 (r349143) +++ head/usr.sbin/pwm/pwm.8 Mon Jun 17 16:43:33 2019 (r349144) @@ -22,7 +22,7 @@ .\" .\" $FreeBSD$ .\" -.Dd January 12, 2019 +.Dd June 17, 2019 .Dt PWM 8 .Os .Sh NAME @@ -61,8 +61,11 @@ Channel number to operate on .It Fl f Ar device Device to operate on. If not specified, -.Pa /dev/pwmc0 +.Pa /dev/pwm/pwmc0.0 is used. +If an unqualified name is provided, +.Pa /dev/pwm +is automatically prepended. .It Fl E Enable the pwm channel .It Fl D @@ -79,17 +82,21 @@ Configure the duty (in nanoseconds or percentage) of t .It Show the configuration of the pwm channel: .Bd -literal -pwm -f /dev/pwmc0 -C +pwm -f /dev/pwm/pwmc0.1 -C .Ed .It -Configure a 50000 ns period and a 25000 duty cycle: +Configure a 50000 ns period and a 25000 ns duty cycle: .Bd -literal -pwm -f /dev/pwmc0 -p 50000 -d 25000 +pwm -f pwmc1.1 -p 50000 -d 25000 .Ed .It -Configure a 50% duty cycle: +Configure a 50% duty cycle on the device and channel which +were configured in +.Xr pwmc 4 +to have the label +.Pa backlight : .Bd -literal -pwm -f /dev/pwmc0 -d 50% +pwm -f backlight -d 50% .Ed .El .Sh SEE ALSO Modified: head/usr.sbin/pwm/pwm.c ============================================================================== --- head/usr.sbin/pwm/pwm.c Mon Jun 17 16:26:43 2019 (r349143) +++ head/usr.sbin/pwm/pwm.c Mon Jun 17 16:43:33 2019 (r349144) @@ -37,6 +37,7 @@ #include #include #include +#include #include #include #include @@ -49,7 +50,19 @@ #define PWM_PERIOD 0x0008 #define PWM_DUTY 0x0010 +static char device_name[PATH_MAX] = "/dev/pwm/pwmc0.0"; + static void +set_device_name(const char *name) +{ + + if (name[0] == '/') + strlcpy(device_name, name, sizeof(device_name)); + else + snprintf(device_name, sizeof(device_name), "/dev/pwm/%s", name); +} + +static void usage(void) { fprintf(stderr, "Usage:\n"); @@ -72,8 +85,10 @@ main(int argc, char *argv[]) cap_rights_t right_ioctl; const unsigned long pwm_ioctls[] = {PWMGETSTATE, PWMSETSTATE, PWMMAXCHANNEL}; char *percent; + bool setname; action = 0; + setname = false; fd = -1; channel = -1u; period = duty = -1; @@ -115,24 +130,23 @@ main(int argc, char *argv[]) channel = strtoul(optarg, NULL, 10); break; case 'f': - if ((fd = open(optarg, O_RDWR)) < 0) { - fprintf(stderr, "pwm: cannot open %s %s\n", - optarg, strerror(errno)); - exit(1); - } + setname = true; + set_device_name(optarg); + break; } } - if (fd == -1) { - if ((fd = open("/dev/pwmc0", O_RDWR)) < 0) { - fprintf(stderr, "pwm: cannot open %s %s\n", - optarg, strerror(errno)); + if (action == 0) + usage(); + + if ((fd = open(device_name, O_RDWR)) == -1) { + fprintf(stderr, "pwm: cannot open %s: %s\n", + device_name, strerror(errno)); + if (setname) exit(1); - } + else + usage(); } - - if (action == 0 || fd == -1) - usage(); if (caph_limit_stdio() < 0) { fprintf(stderr, "can't limit stdio rights");