git: 120e7f7399fc - stable/13 - usr.sbin/pwm/pwm add support for flags

Emmanuel Vadot manu at FreeBSD.org
Thu Jul 22 16:40:40 UTC 2021


The branch stable/13 has been updated by manu:

URL: https://cgit.FreeBSD.org/src/commit/?id=120e7f7399fc47648049fa80e28f249cff5ce18f

commit 120e7f7399fc47648049fa80e28f249cff5ce18f
Author:     Oskar Holmund <oskar.holmlund at ohdata.se>
AuthorDate: 2021-03-11 08:55:23 +0000
Commit:     Emmanuel Vadot <manu at FreeBSD.org>
CommitDate: 2021-07-22 16:39:57 +0000

    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
    
    (cherry picked from commit 17b14d8f7733d39397ae5fc104547e358f5f7ddf)
---
 sys/dev/pwm/pwmc.c | 19 ++++++++++++++++---
 usr.sbin/pwm/pwm.8 |  3 +++
 usr.sbin/pwm/pwm.c | 19 +++++++++++++++----
 3 files changed, 34 insertions(+), 7 deletions(-)

diff --git a/sys/dev/pwm/pwmc.c b/sys/dev/pwm/pwmc.c
index c49d1e894488..b2f12add3e2b 100644
--- a/sys/dev/pwm/pwmc.c
+++ b/sys/dev/pwm/pwmc.c
@@ -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)
diff --git a/usr.sbin/pwm/pwm.8 b/usr.sbin/pwm/pwm.8
index 37c1aa8fec49..94be5af7f703 100644
--- 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 @@ 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
diff --git a/usr.sbin/pwm/pwm.c b/usr.sbin/pwm/pwm.c
index a69fe16fea22..441181917afd 100644
--- 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 @@ 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;


More information about the dev-commits-src-all mailing list