Module Name: src
Committed By: mbalmer
Date: Mon Oct 3 11:16:48 UTC 2011
Modified Files:
src/share/man/man4: gpio.4
src/sys/dev/gpio: gpio.c
src/sys/sys: gpio.h
src/usr.sbin/gpioctl: gpioctl.8 gpioctl.c
Log Message:
Remove the GPIODETACH gpio(4) ioctl (it is still available in COMPAT_50) and
the 'detach' command line option from gpioctl(8). Drivers that are
attached to gpio pins can be detached using the drvctl(8) command.
To generate a diff of this commit:
cvs rdiff -u -r1.20 -r1.21 src/share/man/man4/gpio.4
cvs rdiff -u -r1.43 -r1.44 src/sys/dev/gpio/gpio.c
cvs rdiff -u -r1.10 -r1.11 src/sys/sys/gpio.h
cvs rdiff -u -r1.12 -r1.13 src/usr.sbin/gpioctl/gpioctl.8
cvs rdiff -u -r1.15 -r1.16 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/share/man/man4/gpio.4
diff -u src/share/man/man4/gpio.4:1.20 src/share/man/man4/gpio.4:1.21
--- src/share/man/man4/gpio.4:1.20 Sun Oct 2 09:33:18 2011
+++ src/share/man/man4/gpio.4 Mon Oct 3 11:16:47 2011
@@ -1,4 +1,4 @@
-.\" $NetBSD: gpio.4,v 1.20 2011/10/02 09:33:18 mbalmer Exp $
+.\" $NetBSD: gpio.4,v 1.21 2011/10/03 11:16:47 mbalmer Exp $
.\" $OpenBSD: gpio.4,v 1.5 2004/11/23 09:39:29 reyk Exp $
.\"
.\" 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 2, 2011
+.Dd October 3, 2011
.Dt GPIO 4
.Os
.Sh NAME
@@ -220,18 +220,10 @@ struct gpio_attach {
uint32_t ga_flags; /* driver dependent */
};
.Ed
-.It Dv GPIODETACH (struct gpio_attach)
-Detach a device from this gpio device that was previously attached using the
-.Dv GPIOATTACH
-.Xr ioctl 2 .
+.Pp
The
-.Fa ga_offset ,
-.Fa ga_mask ,
-and
-.Fa ga_flags
-fields of the
-.Fa gpio_attach
-structure are ignored.
+.Xr drvctl 8
+command can be used to detach a device from a gpio pin.
.El
.Sh FILES
.Bl -tag -width "/dev/gpiou" -compact
@@ -241,6 +233,7 @@ GPIO device unit
file.
.El
.Sh SEE ALSO
+.Xr drvctl 8 ,
.Xr ioctl 2 ,
.Xr gpioctl 8
.Sh HISTORY
Index: src/sys/dev/gpio/gpio.c
diff -u src/sys/dev/gpio/gpio.c:1.43 src/sys/dev/gpio/gpio.c:1.44
--- src/sys/dev/gpio/gpio.c:1.43 Mon Oct 3 08:23:58 2011
+++ src/sys/dev/gpio/gpio.c Mon Oct 3 11:16:47 2011
@@ -1,4 +1,4 @@
-/* $NetBSD: gpio.c,v 1.43 2011/10/03 08:23:58 mbalmer Exp $ */
+/* $NetBSD: gpio.c,v 1.44 2011/10/03 11:16:47 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.43 2011/10/03 08:23:58 mbalmer Exp $");
+__KERNEL_RCSID(0, "$NetBSD: gpio.c,v 1.44 2011/10/03 11:16:47 mbalmer Exp $");
/*
* General Purpose Input/Output framework.
@@ -737,49 +737,6 @@ gpio_ioctl(struct gpio_softc *sc, u_long
cv_signal(&sc->sc_attach);
mutex_exit(&sc->sc_mtx);
return error;
-#ifdef COMPAT_50
- case GPIODETACH50:
- /* FALLTHOUGH */
-#endif
- case GPIODETACH:
- if (kauth_authorize_device(cred, KAUTH_DEVICE_GPIO_PINSET,
- NULL, NULL, NULL, NULL))
- return EPERM;
-
- error = 0;
- mutex_enter(&sc->sc_mtx);
- while (sc->sc_attach_busy) {
- error = cv_wait_sig(&sc->sc_attach, &sc->sc_mtx);
- if (error)
- break;
- }
- if (!error)
- sc->sc_attach_busy = 1;
- mutex_exit(&sc->sc_mtx);
- if (error)
- return EBUSY;
-
- attach = data;
- LIST_FOREACH(gdev, &sc->sc_devs, sc_next) {
- if (strcmp(device_xname(gdev->sc_dev),
- attach->ga_dvname) == 0) {
- mutex_enter(&sc->sc_mtx);
- sc->sc_attach_busy = 0;
- cv_signal(&sc->sc_attach);
- mutex_exit(&sc->sc_mtx);
-
- if (config_detach(gdev->sc_dev, 0) == 0)
- return 0;
- break;
- }
- }
- if (gdev == NULL) {
- mutex_enter(&sc->sc_mtx);
- sc->sc_attach_busy = 0;
- cv_signal(&sc->sc_attach);
- mutex_exit(&sc->sc_mtx);
- }
- return EINVAL;
case GPIOSET:
if (kauth_authorize_device(cred, KAUTH_DEVICE_GPIO_PINSET,
NULL, NULL, NULL, NULL))
@@ -987,6 +944,48 @@ gpio_ioctl_oapi(struct gpio_softc *sc, u
sc->sc_pins[pin].pin_flags = flags;
}
break;
+ case GPIODETACH50:
+ /* FALLTHOUGH */
+ case GPIODETACH:
+ if (kauth_authorize_device(cred, KAUTH_DEVICE_GPIO_PINSET,
+ NULL, NULL, NULL, NULL))
+ return EPERM;
+
+ error = 0;
+ mutex_enter(&sc->sc_mtx);
+ while (sc->sc_attach_busy) {
+ error = cv_wait_sig(&sc->sc_attach, &sc->sc_mtx);
+ if (error)
+ break;
+ }
+ if (!error)
+ sc->sc_attach_busy = 1;
+ mutex_exit(&sc->sc_mtx);
+ if (error)
+ return EBUSY;
+
+ attach = data;
+ LIST_FOREACH(gdev, &sc->sc_devs, sc_next) {
+ if (strcmp(device_xname(gdev->sc_dev),
+ attach->ga_dvname) == 0) {
+ mutex_enter(&sc->sc_mtx);
+ sc->sc_attach_busy = 0;
+ cv_signal(&sc->sc_attach);
+ mutex_exit(&sc->sc_mtx);
+
+ if (config_detach(gdev->sc_dev, 0) == 0)
+ return 0;
+ break;
+ }
+ }
+ if (gdev == NULL) {
+ mutex_enter(&sc->sc_mtx);
+ sc->sc_attach_busy = 0;
+ cv_signal(&sc->sc_attach);
+ mutex_exit(&sc->sc_mtx);
+ }
+ return EINVAL;
+
default:
return ENOTTY;
}
Index: src/sys/sys/gpio.h
diff -u src/sys/sys/gpio.h:1.10 src/sys/sys/gpio.h:1.11
--- src/sys/sys/gpio.h:1.10 Sun Oct 2 09:33:19 2011
+++ src/sys/sys/gpio.h Mon Oct 3 11:16:47 2011
@@ -1,4 +1,4 @@
-/* $NetBSD: gpio.h,v 1.10 2011/10/02 09:33:19 mbalmer Exp $ */
+/* $NetBSD: gpio.h,v 1.11 2011/10/03 11:16:47 mbalmer Exp $ */
/* $OpenBSD: gpio.h,v 1.7 2008/11/26 14:51:20 mbalmer Exp $ */
/*
* Copyright (c) 2009, 2011 Marc Balmer <[email protected]>
@@ -76,7 +76,7 @@ struct gpio_set {
char gp_name2[GPIOMAXNAME]; /* new name */
};
-/* Attach/detach device drivers that use GPIO pins */
+/* Attach device drivers that use GPIO pins */
struct gpio_attach {
char ga_dvname[16]; /* device name */
int ga_offset; /* pin number */
@@ -92,7 +92,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 GPIODETACH _IOWR('G', 11, struct gpio_attach)
#define GPIOPULSE _IOWR('G', 12, struct gpio_pulse)
#ifdef COMPAT_50
@@ -123,6 +122,7 @@ struct gpio_pin_op {
#define GPIOPINCTL _IOWR('G', 4, struct gpio_pin_ctl)
#define GPIOATTACH50 _IOWR('G', 10, struct gpio_attach50)
#define GPIODETACH50 _IOWR('G', 11, struct gpio_attach50)
+#define GPIODETACH _IOWR('G', 11, struct gpio_attach)
#endif /* COMPAT_50 */
#endif /* !_SYS_GPIO_H_ */
Index: src/usr.sbin/gpioctl/gpioctl.8
diff -u src/usr.sbin/gpioctl/gpioctl.8:1.12 src/usr.sbin/gpioctl/gpioctl.8:1.13
--- src/usr.sbin/gpioctl/gpioctl.8:1.12 Sun Oct 2 12:43:53 2011
+++ src/usr.sbin/gpioctl/gpioctl.8 Mon Oct 3 11:16:48 2011
@@ -1,4 +1,4 @@
-.\" $NetBSD: gpioctl.8,v 1.12 2011/10/02 12:43:53 mbalmer Exp $
+.\" $NetBSD: gpioctl.8,v 1.13 2011/10/03 11:16:48 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 2, 2011
+.Dd October 3, 2011
.Dt GPIOCTL 8
.Os
.Sh NAME
@@ -33,11 +33,6 @@
.Nm gpioctl
.Op Fl q
.Ar device
-.Cm detach
-.Ar device
-.Nm gpioctl
-.Op Fl q
-.Ar device
.Ar pin
.Op Ar 0 | 1 | 2
.Nm gpioctl
@@ -131,6 +126,9 @@ attached to a
device using the
.Nm
command.
+Such drivers can be detached at runtime using the
+.Xr drvctl 8
+command.
.Pp
The following configuration
.Ar flags
@@ -204,7 +202,7 @@ device on pin 4:
.Pp
Detach the gpioow0 device:
.Pp
-.Dl # gpioctl gpio0 detach gpioow0
+.Dl # drvctl -d gpioow0
.Pp
Configure pin 5 as output and name it error_led:
.Pp
@@ -214,6 +212,7 @@ Toggle the error_led:
.Pp
.Dl # gpioctl gpio0 error_led 2
.Sh SEE ALSO
+.Xr drvctl 8 ,
.Xr gpio 4
.Sh HISTORY
The
Index: src/usr.sbin/gpioctl/gpioctl.c
diff -u src/usr.sbin/gpioctl/gpioctl.c:1.15 src/usr.sbin/gpioctl/gpioctl.c:1.16
--- src/usr.sbin/gpioctl/gpioctl.c:1.15 Sun Oct 2 12:43:53 2011
+++ src/usr.sbin/gpioctl/gpioctl.c Mon Oct 3 11:16:48 2011
@@ -1,4 +1,4 @@
-/* $NetBSD: gpioctl.c,v 1.15 2011/10/02 12:43:53 mbalmer Exp $ */
+/* $NetBSD: gpioctl.c,v 1.16 2011/10/03 11:16:48 mbalmer Exp $ */
/*
* Copyright (c) 2008, 2010, 2011 Marc Balmer <[email protected]>
@@ -47,7 +47,6 @@ static void gpiopulse(int, char *, doubl
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);
-static void devdetach(char *);
__dead static void usage(void);
extern long long strtonum(const char *numstr, long long minval,
@@ -153,10 +152,6 @@ main(int argc, char *argv[])
}
devattach(driver, ga_offset, ga_mask, ga_flags);
return EXIT_SUCCESS;
- } else if (!strcmp(argv[1], "detach")) {
- if (argc != 3)
- usage();
- devdetach(argv[2]);
} else {
char *nm = NULL;
@@ -414,17 +409,6 @@ devattach(char *dvname, int offset, uint
}
static void
-devdetach(char *dvname)
-{
- struct gpio_attach attach;
-
- memset(&attach, 0, sizeof(attach));
- strlcpy(attach.ga_dvname, dvname, sizeof(attach.ga_dvname));
- if (ioctl(devfd, GPIODETACH, &attach) == -1)
- err(EXIT_FAILURE, "GPIODETACH");
-}
-
-static void
usage(void)
{
const char *progname;
@@ -440,7 +424,6 @@ usage(void)
fprintf(stderr, " %s [-q] device attach device offset mask "
"[flag]\n",
progname);
- fprintf(stderr, " %s [-q] device detach device\n", progname);
exit(EXIT_FAILURE);
}