Module Name: src
Committed By: mbalmer
Date: Sun Nov 13 13:20:02 UTC 2011
Modified Files:
src/sys/dev/gpio: gpio.c gpiovar.h
src/sys/sys: gpio.h
src/usr.sbin/gpioctl: gpioctl.8 gpioctl.c
Log Message:
Remove software pulsing in gpio(4), this functionality is now provided
by the gpiopwm(4) driver.
To generate a diff of this commit:
cvs rdiff -u -r1.46 -r1.47 src/sys/dev/gpio/gpio.c
cvs rdiff -u -r1.14 -r1.15 src/sys/dev/gpio/gpiovar.h
cvs rdiff -u -r1.11 -r1.12 src/sys/sys/gpio.h
cvs rdiff -u -r1.14 -r1.15 src/usr.sbin/gpioctl/gpioctl.8
cvs rdiff -u -r1.18 -r1.19 src/usr.sbin/gpioctl/gpioctl.c
Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.
Modified files:
Index: src/sys/dev/gpio/gpio.c
diff -u src/sys/dev/gpio/gpio.c:1.46 src/sys/dev/gpio/gpio.c:1.47
--- src/sys/dev/gpio/gpio.c:1.46 Mon Oct 3 11:31:56 2011
+++ src/sys/dev/gpio/gpio.c Sun Nov 13 13:20:02 2011
@@ -1,4 +1,4 @@
-/* $NetBSD: gpio.c,v 1.46 2011/10/03 11:31:56 mbalmer Exp $ */
+/* $NetBSD: gpio.c,v 1.47 2011/11/13 13:20:02 mbalmer Exp $ */
/* $OpenBSD: gpio.c,v 1.6 2006/01/14 12:33:49 grange Exp $ */
/*
@@ -19,7 +19,7 @@
*/
#include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: gpio.c,v 1.46 2011/10/03 11:31:56 mbalmer Exp $");
+__KERNEL_RCSID(0, "$NetBSD: gpio.c,v 1.47 2011/11/13 13:20:02 mbalmer Exp $");
/*
* General Purpose Input/Output framework.
@@ -81,7 +81,6 @@ static int gpio_detach(device_t, int);
static int gpio_search(device_t, cfdata_t, const int *, void *);
static int gpio_print(void *, const char *);
static int gpio_pinbyname(struct gpio_softc *, char *);
-static void gpio_pulse(void *);
static int gpio_ioctl(struct gpio_softc *, u_long, void *, int,
struct lwp *);
@@ -193,7 +192,7 @@ gpio_attach(device_t parent, device_t se
{
struct gpio_softc *sc = device_private(self);
struct gpiobus_attach_args *gba = aux;
- int pin;
+
sc->sc_dev = self;
sc->sc_gc = gba->gba_gc;
sc->sc_pins = gba->gba_pins;
@@ -201,11 +200,6 @@ gpio_attach(device_t parent, device_t se
printf(": %d pins\n", sc->sc_npins);
- for (pin = 0; pin < sc->sc_npins; pin++) {
- callout_init(&sc->sc_pins[pin].pin_pulse, CALLOUT_MPSAFE);
- callout_setfunc(&sc->sc_pins[pin].pin_pulse, gpio_pulse,
- &sc->sc_pins[pin]);
- }
if (!pmf_device_register(self, NULL, gpio_resume))
aprint_error_dev(self, "couldn't establish power handler\n");
mutex_init(&sc->sc_mtx, MUTEX_DEFAULT, IPL_VM);
@@ -222,18 +216,10 @@ static int
gpio_detach(device_t self, int flags)
{
struct gpio_softc *sc;
- int pin, rc;
+ int rc;
sc = device_private(self);
- for (pin = 0; pin < sc->sc_npins; pin++) {
- if (sc->sc_pins[pin].pin_state & GPIO_PIN_PULSE) {
- callout_halt(&sc->sc_pins[pin].pin_pulse, NULL);
- callout_destroy(&sc->sc_pins[pin].pin_pulse);
- sc->sc_pins[pin].pin_state &= ~GPIO_PIN_PULSE;
- }
- }
-
if ((rc = config_detach_children(self, flags)) != 0)
return rc;
mutex_destroy(&sc->sc_mtx);
@@ -465,26 +451,6 @@ gpio_pinbyname(struct gpio_softc *sc, ch
return -1;
}
-static void
-gpio_pulse(void *arg)
-{
- struct gpio_pin *pin;
-
- pin = arg;
- if ((pin->pin_state & GPIO_PIN_PULSE) == 0)
- return;
-
- if (pin->pin_state & GPIO_PIN_HIGH) {
- gpiobus_pin_write(pin->pin_gc, pin->pin_num, GPIO_PIN_LOW);
- pin->pin_state &= ~GPIO_PIN_HIGH;
- callout_schedule(&pin->pin_pulse, pin->pin_ticks_off);
- } else {
- gpiobus_pin_write(pin->pin_gc, pin->pin_num, GPIO_PIN_HIGH);
- pin->pin_state |= GPIO_PIN_HIGH;
- callout_schedule(&pin->pin_pulse, pin->pin_ticks_on);
- }
-}
-
int
gpioioctl(dev_t dev, u_long cmd, void *data, int flag, struct lwp *l)
{
@@ -511,7 +477,6 @@ gpio_ioctl(struct gpio_softc *sc, u_long
struct gpio_attach *attach;
struct gpio_attach_args ga;
struct gpio_req *req;
- struct gpio_pulse *pulse;
struct gpio_name *nm;
struct gpio_set *set;
struct gpio_pin *gpin;
@@ -593,59 +558,12 @@ gpio_ioctl(struct gpio_softc *sc, u_long
if (value != GPIO_PIN_LOW && value != GPIO_PIN_HIGH)
return EINVAL;
- if (sc->sc_pins[pin].pin_state & GPIO_PIN_PULSE) {
- callout_halt(&sc->sc_pins[pin].pin_pulse, NULL);
- sc->sc_pins[pin].pin_state &= ~GPIO_PIN_PULSE;
- }
gpiobus_pin_write(gc, pin, value);
/* return old value */
req->gp_value = sc->sc_pins[pin].pin_state;
/* update current value */
sc->sc_pins[pin].pin_state = value;
break;
- case GPIOPULSE:
- if ((flag & FWRITE) == 0)
- return EBADF;
-
- pulse = data;
- if (pulse->gp_name[0] != '\0')
- pin = gpio_pinbyname(sc, pulse->gp_name);
- else
- pin = pulse->gp_pin;
-
- if (pin < 0 || pin >= sc->sc_npins)
- return EINVAL;
-
- gpin = &sc->sc_pins[pin];
- if (gpin->pin_mapped)
- return EBUSY;
-
- if (!(gpin->pin_flags & GPIO_PIN_SET) &&
- kauth_authorize_device(cred, KAUTH_DEVICE_GPIO_PINSET,
- NULL, NULL, NULL, NULL))
- return EPERM;
-
- if (gpin->pin_flags & GPIO_PIN_PULSATE) {
- gpiobus_pin_write(gc, pin, GPIO_PIN_HIGH);
- gpin->pin_state = GPIO_PIN_PULSE;
- return 0;
- }
-
- if (gpin->pin_state & GPIO_PIN_PULSE)
- callout_halt(&gpin->pin_pulse, NULL);
-
- gpin->pin_gc = gc;
-
- gpin->pin_ticks_on = tvtohz(&pulse->gp_pulse_on);
- gpin->pin_ticks_off = tvtohz(&pulse->gp_pulse_off);
- if (gpin->pin_ticks_on == 0 || gpin->pin_ticks_off == 0) {
- gpin->pin_ticks_on = hz / 2;
- gpin->pin_ticks_off = hz / 2;
- }
- gpiobus_pin_write(gc, pin, GPIO_PIN_HIGH);
- gpin->pin_state = GPIO_PIN_HIGH | GPIO_PIN_PULSE;
- callout_schedule(&gpin->pin_pulse, gpin->pin_ticks_on);
- break;
case GPIOTOGGLE:
if ((flag & FWRITE) == 0)
return EBADF;
Index: src/sys/dev/gpio/gpiovar.h
diff -u src/sys/dev/gpio/gpiovar.h:1.14 src/sys/dev/gpio/gpiovar.h:1.15
--- src/sys/dev/gpio/gpiovar.h:1.14 Sun Oct 2 09:33:19 2011
+++ src/sys/dev/gpio/gpiovar.h Sun Nov 13 13:20:02 2011
@@ -1,4 +1,4 @@
-/* $NetBSD: gpiovar.h,v 1.14 2011/10/02 09:33:19 mbalmer Exp $ */
+/* $NetBSD: gpiovar.h,v 1.15 2011/11/13 13:20:02 mbalmer Exp $ */
/* $OpenBSD: gpiovar.h,v 1.3 2006/01/14 12:33:49 grange Exp $ */
/*
@@ -40,9 +40,6 @@ typedef struct gpio_pin {
int pin_flags; /* current configuration */
int pin_state; /* current state */
int pin_mapped; /* is mapped */
- callout_t pin_pulse; /* for pulsing */
- int pin_ticks_on; /* "on" period */
- int pin_ticks_off; /* "off" period */
gpio_chipset_tag_t pin_gc; /* reference the controller */
} gpio_pin_t;
Index: src/sys/sys/gpio.h
diff -u src/sys/sys/gpio.h:1.11 src/sys/sys/gpio.h:1.12
--- src/sys/sys/gpio.h:1.11 Mon Oct 3 11:16:47 2011
+++ src/sys/sys/gpio.h Sun Nov 13 13:20:02 2011
@@ -1,4 +1,4 @@
-/* $NetBSD: gpio.h,v 1.11 2011/10/03 11:16:47 mbalmer Exp $ */
+/* $NetBSD: gpio.h,v 1.12 2011/11/13 13:20:02 mbalmer Exp $ */
/* $OpenBSD: gpio.h,v 1.7 2008/11/26 14:51:20 mbalmer Exp $ */
/*
* Copyright (c) 2009, 2011 Marc Balmer <[email protected]>
@@ -25,7 +25,6 @@
/* GPIO pin states */
#define GPIO_PIN_LOW 0x00 /* low level (logical 0) */
#define GPIO_PIN_HIGH 0x01 /* high level (logical 1) */
-#define GPIO_PIN_PULSE 0x02 /* pulsing, or-ed with state */
/* Max name length of a pin */
#define GPIOMAXNAME 64
@@ -59,14 +58,6 @@ struct gpio_req {
int gp_value; /* value */
};
-/* GPIO pulse request */
-struct gpio_pulse {
- char gp_name[GPIOMAXNAME]; /* pin name */
- int gp_pin; /* pin number */
- struct timeval gp_pulse_on; /* "on" period */
- struct timeval gp_pulse_off; /* "off" period */
-};
-
/* GPIO pin configuration */
struct gpio_set {
char gp_name[GPIOMAXNAME];
@@ -92,7 +83,6 @@ struct gpio_attach {
#define GPIOWRITE _IOWR('G', 8, struct gpio_req)
#define GPIOTOGGLE _IOWR('G', 9, struct gpio_req)
#define GPIOATTACH _IOWR('G', 10, struct gpio_attach)
-#define GPIOPULSE _IOWR('G', 12, struct gpio_pulse)
#ifdef COMPAT_50
/* Old structure to attach/detach devices */
Index: src/usr.sbin/gpioctl/gpioctl.8
diff -u src/usr.sbin/gpioctl/gpioctl.8:1.14 src/usr.sbin/gpioctl/gpioctl.8:1.15
--- src/usr.sbin/gpioctl/gpioctl.8:1.14 Thu Oct 6 11:06:44 2011
+++ src/usr.sbin/gpioctl/gpioctl.8 Sun Nov 13 13:20:02 2011
@@ -1,4 +1,4 @@
-.\" $NetBSD: gpioctl.8,v 1.14 2011/10/06 11:06:44 wiz Exp $
+.\" $NetBSD: gpioctl.8,v 1.15 2011/11/13 13:20:02 mbalmer Exp $
.\"
.\" Copyright (c) 2009, 2010, 2011 Marc Balmer <[email protected]>
.\" Copyright (c) 2004 Alexander Yurchenko <[email protected]>
@@ -15,7 +15,7 @@
.\" ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
.\" OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
.\"
-.Dd October 3, 2011
+.Dd November 13, 2011
.Dt GPIOCTL 8
.Os
.Sh NAME
@@ -41,11 +41,6 @@
.Ar pin
.Op Ar on | off | toggle
.Nm gpioctl
-.Op Fl q
-.Ar device
-.Ar pin
-.Cm pulse
-.Op Ar frequency Op Ar duty cycle
.Nm gpioctl
.Op Fl q
.Ar device
@@ -105,17 +100,6 @@ or
can be used.
.Pp
To
-.Dq pulse
-a pin, use the pulse command line option with an optional frequency value
-in hertz and an optional duty cycle in percent.
-If no frequency is specified, 1 Hz is assumed.
-If no duty cycle is specified, 50% are assumed.
-If the underlying hardware is not capable of pulsing in hardware,
-pulsing is done in software using the
-.Xr callout 9
-facility.
-The frequency and duty cycle arguments are ignored for pins that are able to
-pulse in hardware.
.Pp
Only pins that have been configured at securelevel 0, typically during system
startup, are accessible once the securelevel has been raised.
@@ -227,5 +211,5 @@ The
.Nm
program was written by
.An Alexander Yurchenko Aq [email protected] .
-Device attachment and pulsing was added by
+Device attachment was added by
.An Marc Balmer Aq [email protected] .
Index: src/usr.sbin/gpioctl/gpioctl.c
diff -u src/usr.sbin/gpioctl/gpioctl.c:1.18 src/usr.sbin/gpioctl/gpioctl.c:1.19
--- src/usr.sbin/gpioctl/gpioctl.c:1.18 Sat Nov 12 16:34:03 2011
+++ src/usr.sbin/gpioctl/gpioctl.c Sun Nov 13 13:20:02 2011
@@ -1,4 +1,4 @@
-/* $NetBSD: gpioctl.c,v 1.18 2011/11/12 16:34:03 mbalmer Exp $ */
+/* $NetBSD: gpioctl.c,v 1.19 2011/11/13 13:20:02 mbalmer Exp $ */
/*
* Copyright (c) 2008, 2010, 2011 Marc Balmer <[email protected]>
@@ -43,7 +43,6 @@ static int quiet = 0;
static void getinfo(void);
static void gpioread(int, char *);
static void gpiowrite(int, char *, int);
-static void gpiopulse(int, char *, double, double);
static void gpioset(int pin, char *name, int flags, char *alias);
static void gpiounset(int pin, char *name);
static void devattach(char *, int, uint32_t, uint32_t);
@@ -74,7 +73,6 @@ int
main(int argc, char *argv[])
{
const struct bitstr *bs;
- double freq, dc;
int pin, ch, n, fl = 0, value = 0;
const char *errstr;
char *ep;
@@ -102,8 +100,6 @@ main(int argc, char *argv[])
usage();
dev = argv[0];
- freq = dc = 0.0;
-
if (strncmp(_PATH_DEV, dev, sizeof(_PATH_DEV) - 1)) {
(void)snprintf(devn, sizeof(devn), "%s%s", _PATH_DEV, dev);
dev = devn;
@@ -174,19 +170,9 @@ main(int argc, char *argv[])
nam = argv[n];
}
gpioset(pin, nm, fl, nam);
- } else if (!strcmp(argv[2], "unset")) {
+ } else if (!strcmp(argv[2], "unset"))
gpiounset(pin, nm);
- } else if (!strcmp(argv[2], "pulse")) {
- if (argc == 4) {
- freq = atof(argv[3]);
- dc = 50.0;
- } else if (argc == 5) {
- freq = atof(argv[3]);
- dc = atof(argv[4]);
- } else
- freq = dc = 0.0;
- gpiopulse(pin, nm, freq, dc);
- } else {
+ else {
value = strtonum(argv[2], INT_MIN, INT_MAX,
&errstr);
if (errstr) {
@@ -282,62 +268,6 @@ gpiowrite(int pin, char *gp_name, int va
}
static void
-gpiopulse(int pin, char *gp_name, double freq, double dc)
-{
- struct gpio_pulse pulse;
- suseconds_t period, on, off;
-
- if (freq < 0.0 || (dc < 0.0 || dc >= 100.0))
- errx(EXIT_FAILURE, "%.f Hz, %.f%% duty cycle: invalid value",
- freq, dc);
-
- memset(&pulse, 0, sizeof(pulse));
- if (gp_name != NULL)
- strlcpy(pulse.gp_name, gp_name, sizeof(pulse.gp_name));
- else
- pulse.gp_pin = pin;
-
- if (freq > 0.0 && dc > 0.0) {
- period = 1000000 / freq;
- on = period * dc / 100;
- off = period - on;
-
- if (on >= 1000000) {
- pulse.gp_pulse_on.tv_sec = on / 1000000;
- on -= pulse.gp_pulse_on.tv_sec * 1000000;
- pulse.gp_pulse_on.tv_usec = on;
- } else {
- pulse.gp_pulse_on.tv_sec = 0;
- pulse.gp_pulse_on.tv_usec = on;
- }
- if (off >= 1000000) {
- pulse.gp_pulse_off.tv_sec = off / 1000000;
- off -= pulse.gp_pulse_off.tv_sec * 1000000;
- pulse.gp_pulse_off.tv_usec = off;
- } else {
- pulse.gp_pulse_off.tv_sec = 0;
- pulse.gp_pulse_off.tv_usec = off;
- }
- } else { /* gpio(4) defaults */
- freq = 1.0;
- dc = 50.0;
- }
-
- if (ioctl(devfd, GPIOPULSE, &pulse) == -1)
- err(EXIT_FAILURE, "GPIOPULSE");
-
- if (quiet)
- return;
-
- if (gp_name)
- printf("pin %s: pulse at %.f Hz with a %.f%% duty cycle\n",
- gp_name, freq, dc);
- else
- printf("pin %d: pulse at %.f Hz with a %.f%% duty cycle\n",
- pin, freq, dc);
-}
-
-static void
gpioset(int pin, char *name, int fl, char *alias)
{
struct gpio_set set;
@@ -416,8 +346,6 @@ usage(void)
progname = getprogname();
fprintf(stderr, "usage: %s [-q] device [pin] [0 | 1 | 2 | "
"on | off | toggle]\n", progname);
- fprintf(stderr, "usage: %s [-q] device pin pulse [frequency "
- "[duty cycle]]\n", progname);
fprintf(stderr, " %s [-q] device pin set [flags] [name]\n",
progname);
fprintf(stderr, " %s [-q] device pin unset\n", progname);