diff --git a/sys/dev/pwm/pwmc.c b/sys/dev/pwm/pwmc.c --- a/sys/dev/pwm/pwmc.c +++ b/sys/dev/pwm/pwmc.c @@ -80,9 +80,16 @@ 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 @@ &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) diff --git a/usr.sbin/pwm/pwm.8 b/usr.sbin/pwm/pwm.8 --- a/usr.sbin/pwm/pwm.8 +++ b/usr.sbin/pwm/pwm.8 @@ -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 @@ 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 diff --git a/usr.sbin/pwm/pwm.c b/usr.sbin/pwm/pwm.c --- a/usr.sbin/pwm/pwm.c +++ b/usr.sbin/pwm/pwm.c @@ -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 @@ { 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 @@ 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 @@ 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 @@ } 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 @@ 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;