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.
This commit is contained in:
parent
b5d67730ee
commit
7d763870e4
Notes:
svn2git
2020-12-20 02:59:44 +00:00
svn path=/head/; revision=349144
@ -22,7 +22,7 @@
|
|||||||
.\"
|
.\"
|
||||||
.\" $FreeBSD$
|
.\" $FreeBSD$
|
||||||
.\"
|
.\"
|
||||||
.Dd January 12, 2019
|
.Dd June 17, 2019
|
||||||
.Dt PWM 8
|
.Dt PWM 8
|
||||||
.Os
|
.Os
|
||||||
.Sh NAME
|
.Sh NAME
|
||||||
@ -61,8 +61,11 @@ Channel number to operate on
|
|||||||
.It Fl f Ar device
|
.It Fl f Ar device
|
||||||
Device to operate on.
|
Device to operate on.
|
||||||
If not specified,
|
If not specified,
|
||||||
.Pa /dev/pwmc0
|
.Pa /dev/pwm/pwmc0.0
|
||||||
is used.
|
is used.
|
||||||
|
If an unqualified name is provided,
|
||||||
|
.Pa /dev/pwm
|
||||||
|
is automatically prepended.
|
||||||
.It Fl E
|
.It Fl E
|
||||||
Enable the pwm channel
|
Enable the pwm channel
|
||||||
.It Fl D
|
.It Fl D
|
||||||
@ -79,17 +82,21 @@ Configure the duty (in nanoseconds or percentage) of the pwm channel
|
|||||||
.It
|
.It
|
||||||
Show the configuration of the pwm channel:
|
Show the configuration of the pwm channel:
|
||||||
.Bd -literal
|
.Bd -literal
|
||||||
pwm -f /dev/pwmc0 -C
|
pwm -f /dev/pwm/pwmc0.1 -C
|
||||||
.Ed
|
.Ed
|
||||||
.It
|
.It
|
||||||
Configure a 50000 ns period and a 25000 duty cycle:
|
Configure a 50000 ns period and a 25000 ns duty cycle:
|
||||||
.Bd -literal
|
.Bd -literal
|
||||||
pwm -f /dev/pwmc0 -p 50000 -d 25000
|
pwm -f pwmc1.1 -p 50000 -d 25000
|
||||||
.Ed
|
.Ed
|
||||||
.It
|
.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
|
.Bd -literal
|
||||||
pwm -f /dev/pwmc0 -d 50%
|
pwm -f backlight -d 50%
|
||||||
.Ed
|
.Ed
|
||||||
.El
|
.El
|
||||||
.Sh SEE ALSO
|
.Sh SEE ALSO
|
||||||
|
@ -37,6 +37,7 @@
|
|||||||
#include <err.h>
|
#include <err.h>
|
||||||
#include <errno.h>
|
#include <errno.h>
|
||||||
#include <fcntl.h>
|
#include <fcntl.h>
|
||||||
|
#include <limits.h>
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
@ -49,6 +50,18 @@
|
|||||||
#define PWM_PERIOD 0x0008
|
#define PWM_PERIOD 0x0008
|
||||||
#define PWM_DUTY 0x0010
|
#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
|
static void
|
||||||
usage(void)
|
usage(void)
|
||||||
{
|
{
|
||||||
@ -72,8 +85,10 @@ main(int argc, char *argv[])
|
|||||||
cap_rights_t right_ioctl;
|
cap_rights_t right_ioctl;
|
||||||
const unsigned long pwm_ioctls[] = {PWMGETSTATE, PWMSETSTATE, PWMMAXCHANNEL};
|
const unsigned long pwm_ioctls[] = {PWMGETSTATE, PWMSETSTATE, PWMMAXCHANNEL};
|
||||||
char *percent;
|
char *percent;
|
||||||
|
bool setname;
|
||||||
|
|
||||||
action = 0;
|
action = 0;
|
||||||
|
setname = false;
|
||||||
fd = -1;
|
fd = -1;
|
||||||
channel = -1u;
|
channel = -1u;
|
||||||
period = duty = -1;
|
period = duty = -1;
|
||||||
@ -115,25 +130,24 @@ main(int argc, char *argv[])
|
|||||||
channel = strtoul(optarg, NULL, 10);
|
channel = strtoul(optarg, NULL, 10);
|
||||||
break;
|
break;
|
||||||
case 'f':
|
case 'f':
|
||||||
if ((fd = open(optarg, O_RDWR)) < 0) {
|
setname = true;
|
||||||
fprintf(stderr, "pwm: cannot open %s %s\n",
|
set_device_name(optarg);
|
||||||
optarg, strerror(errno));
|
break;
|
||||||
exit(1);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (fd == -1) {
|
if (action == 0)
|
||||||
if ((fd = open("/dev/pwmc0", O_RDWR)) < 0) {
|
|
||||||
fprintf(stderr, "pwm: cannot open %s %s\n",
|
|
||||||
optarg, strerror(errno));
|
|
||||||
exit(1);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (action == 0 || fd == -1)
|
|
||||||
usage();
|
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 (caph_limit_stdio() < 0) {
|
if (caph_limit_stdio() < 0) {
|
||||||
fprintf(stderr, "can't limit stdio rights");
|
fprintf(stderr, "can't limit stdio rights");
|
||||||
goto fail;
|
goto fail;
|
||||||
|
Loading…
Reference in New Issue
Block a user