usr.sbin/pwm/pwm add support for flags
The pwm utility cant set the only flag defined (PWM_POLARITY_INVERTED) so this patch add the option -I (capital letter i) to send it to the drivers. None of existing PWM driver have implemented support for flags. But soon:ish I will put up an review of a pwm driver using TI OMAP DMTimer. Differential Revision: https://reviews.freebsd.org/D29137 MFC after: 2 weeks
This commit is contained in:
parent
7d4a5de84d
commit
17b14d8f77
@ -80,9 +80,16 @@ pwm_ioctl(struct cdev *dev, u_long cmd, caddr_t data,
|
||||
bcopy(data, &state, sizeof(state));
|
||||
rv = PWMBUS_CHANNEL_CONFIG(bus, sc->chan,
|
||||
state.period, state.duty);
|
||||
if (rv == 0)
|
||||
rv = PWMBUS_CHANNEL_ENABLE(bus, sc->chan,
|
||||
state.enable);
|
||||
if (rv != 0)
|
||||
return (rv);
|
||||
|
||||
rv = PWMBUS_CHANNEL_SET_FLAGS(bus,
|
||||
sc->chan, state.flags);
|
||||
if (rv != 0 && rv != EOPNOTSUPP)
|
||||
return (rv);
|
||||
|
||||
rv = PWMBUS_CHANNEL_ENABLE(bus, sc->chan,
|
||||
state.enable);
|
||||
break;
|
||||
case PWMGETSTATE:
|
||||
bcopy(data, &state, sizeof(state));
|
||||
@ -90,6 +97,12 @@ pwm_ioctl(struct cdev *dev, u_long cmd, caddr_t data,
|
||||
&state.period, &state.duty);
|
||||
if (rv != 0)
|
||||
return (rv);
|
||||
|
||||
rv = PWMBUS_CHANNEL_GET_FLAGS(bus, sc->chan,
|
||||
&state.flags);
|
||||
if (rv != 0)
|
||||
return (rv);
|
||||
|
||||
rv = PWMBUS_CHANNEL_IS_ENABLED(bus, sc->chan,
|
||||
&state.enable);
|
||||
if (rv != 0)
|
||||
|
@ -35,6 +35,7 @@
|
||||
.Nm
|
||||
.Op Fl f Ar device
|
||||
.Op Fl D | Fl E
|
||||
.Op Fl I
|
||||
.Op Fl p Ar period
|
||||
.Op Fl d Ar duty
|
||||
.Sh DESCRIPTION
|
||||
@ -82,6 +83,8 @@ during which the signal is asserted.
|
||||
Enable the PWM channel.
|
||||
.It Fl p Ar period
|
||||
Configure the period (in nanoseconds) of the PWM channel.
|
||||
.It Fl I
|
||||
Invert PWM signal polarity
|
||||
.El
|
||||
.Sh EXAMPLES
|
||||
.Bl -bullet
|
||||
|
@ -48,6 +48,7 @@
|
||||
#define PWM_SHOW_CONFIG 0x0004
|
||||
#define PWM_PERIOD 0x0008
|
||||
#define PWM_DUTY 0x0010
|
||||
#define PWM_INVERTED 0x0020
|
||||
|
||||
static char device_name[PATH_MAX] = "/dev/pwm/pwmc0.0";
|
||||
|
||||
@ -66,7 +67,7 @@ usage(void)
|
||||
{
|
||||
fprintf(stderr, "Usage:\n");
|
||||
fprintf(stderr, "\tpwm [-f dev] -C\n");
|
||||
fprintf(stderr, "\tpwm [-f dev] [-D | -E] [-p period] [-d duty[%%]]\n");
|
||||
fprintf(stderr, "\tpwm [-f dev] [-D | -E] [-I] [-p period] [-d duty[%%]]\n");
|
||||
exit(1);
|
||||
}
|
||||
|
||||
@ -87,7 +88,7 @@ main(int argc, char *argv[])
|
||||
fd = -1;
|
||||
period = duty = -1;
|
||||
|
||||
while ((ch = getopt(argc, argv, "f:EDCp:d:")) != -1) {
|
||||
while ((ch = getopt(argc, argv, "f:EDCIp:d:")) != -1) {
|
||||
switch (ch) {
|
||||
case 'E':
|
||||
if (action & (PWM_DISABLE | PWM_SHOW_CONFIG))
|
||||
@ -104,6 +105,11 @@ main(int argc, char *argv[])
|
||||
usage();
|
||||
action = PWM_SHOW_CONFIG;
|
||||
break;
|
||||
case 'I':
|
||||
if (action & PWM_SHOW_CONFIG)
|
||||
usage();
|
||||
action |= PWM_INVERTED;
|
||||
break;
|
||||
case 'p':
|
||||
if (action & PWM_SHOW_CONFIG)
|
||||
usage();
|
||||
@ -172,10 +178,11 @@ main(int argc, char *argv[])
|
||||
}
|
||||
|
||||
if (action == PWM_SHOW_CONFIG) {
|
||||
printf("period: %u\nduty: %u\nenabled:%d\n",
|
||||
printf("period: %u\nduty: %u\nenabled:%d\ninverted:%d\n",
|
||||
state.period,
|
||||
state.duty,
|
||||
state.enable);
|
||||
state.enable,
|
||||
state.flags & PWM_POLARITY_INVERTED);
|
||||
} else {
|
||||
if (action & PWM_ENABLE)
|
||||
state.enable = true;
|
||||
@ -183,6 +190,10 @@ main(int argc, char *argv[])
|
||||
state.enable = false;
|
||||
if (action & PWM_PERIOD)
|
||||
state.period = period;
|
||||
if (action & PWM_INVERTED)
|
||||
state.flags |= PWM_POLARITY_INVERTED;
|
||||
else
|
||||
state.flags &= ~PWM_POLARITY_INVERTED;
|
||||
if (action & PWM_DUTY) {
|
||||
if (*percent != '\0')
|
||||
state.duty = (uint64_t)state.period * duty / 100;
|
||||
|
Loading…
Reference in New Issue
Block a user