Page MenuHomeFreeBSD

D29137.id85365.diff
No OneTemporary

D29137.id85365.diff

diff --git a/share/man/man9/pwmbus.9 b/share/man/man9/pwmbus.9
--- a/share/man/man9/pwmbus.9
+++ b/share/man/man9/pwmbus.9
@@ -40,13 +40,13 @@
.Cd "device pwm"
.In "pwmbus_if.h"
.Ft int
-.Fn PWMBUS_CHANNEL_CONFIG "device_t bus" "int channel" "uint64_t period" "uint64_t duty"
+.Fn PWMBUS_CHANNEL_CONFIG "device_t bus" "int channel" "u_int period" "u_int duty"
.Ft int
.Fn PWMBUS_CHANNEL_COUNT "device_t bus" "int channel" "int *nchannel"
.Ft int
.Fn PWMBUS_CHANNEL_ENABLE "device_t bus" "int channel" "bool enable"
.Ft int
-.Fn PWMBUS_CHANNEL_GET_CONFIG "device_t bus" "int channel" "uint64_t *period" "uint64_t *duty"
+.Fn PWMBUS_CHANNEL_GET_CONFIG "device_t bus" "int channel" "u_int *period" "u_int *duty"
.Ft int
.Fn PWMBUS_CHANNEL_GET_FLAGS "device_t bus" "int channel" "uint32_t *flags"
.Ft int
@@ -76,7 +76,7 @@
details on channels that share resources.
.Sh INTERFACE
.Bl -tag -width indent
-.It Fn PWMBUS_CHANNEL_CONFIG "device_t bus" "int channel" "uint64_t period" "uint64_t duty"
+.It Fn PWMBUS_CHANNEL_CONFIG "device_t bus" "int channel" "u_int period" "u_int duty"
Configure the period and duty (in nanoseconds) in the PWM controller on the bus
for the specified channel.
Returns 0 on success or
@@ -89,7 +89,7 @@
Get the number of channels supported by the controller.
.It Fn PWMBUS_CHANNEL_ENABLE "device_t bus" "int channel" "bool enable"
Enable the PWM channel.
-.It Fn PWMBUS_CHANNEL_GET_CONFIG "device_t bus" "int channel" "uint64_t *period" "uint64_t *duty"
+.It Fn PWMBUS_CHANNEL_GET_CONFIG "device_t bus" "int channel" "u_int *period" "u_int *duty"
Get the current configuration of the period and duty for the specified channel.
.It Fn PWMBUS_CHANNEL_GET_FLAGS "device_t bus" "int channel" "uint32_t *flags"
Get the current flags for the channel.
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,8 @@
{
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 +89,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 +106,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();
@@ -167,15 +174,17 @@
/* Fill the common args */
if (ioctl(fd, PWMGETSTATE, &state) == -1) {
- fprintf(stderr, "Cannot get current state of the pwm controller\n");
+ fprintf(stderr,
+ "Cannot get current state of the pwm controller\n");
goto fail;
}
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 +192,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;

File Metadata

Mime Type
text/plain
Expires
Wed, Sep 25, 3:17 AM (8 h, 45 m)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
12725526
Default Alt Text
D29137.id85365.diff (4 KB)

Event Timeline