CVS commit: src/sys/dev/gpio

2018-06-01 Thread Jason R Thorpe
Module Name:src
Committed By:   thorpej
Date:   Fri Jun  1 13:42:14 UTC 2018

Modified Files:
src/sys/dev/gpio: gpiopps.c

Log Message:
Fix a paste-o that prevented the 2-pin interrupt messages from being
printed correctly (but no other harmful effects).  Pointed out by
Brad Spencer.


To generate a diff of this commit:
cvs rdiff -u -r1.1 -r1.2 src/sys/dev/gpio/gpiopps.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/gpiopps.c
diff -u src/sys/dev/gpio/gpiopps.c:1.1 src/sys/dev/gpio/gpiopps.c:1.2
--- src/sys/dev/gpio/gpiopps.c:1.1	Sun May 20 14:08:33 2018
+++ src/sys/dev/gpio/gpiopps.c	Fri Jun  1 13:42:14 2018
@@ -1,4 +1,4 @@
-/* $NetBSD: gpiopps.c,v 1.1 2018/05/20 14:08:33 thorpej Exp $ */
+/* $NetBSD: gpiopps.c,v 1.2 2018/06/01 13:42:14 thorpej Exp $ */
 
 /*
  * Copyright (c) 2016 Brad Spencer 
@@ -26,7 +26,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: gpiopps.c,v 1.1 2018/05/20 14:08:33 thorpej Exp $");
+__KERNEL_RCSID(0, "$NetBSD: gpiopps.c,v 1.2 2018/06/01 13:42:14 thorpej Exp $");
 
 /*
  * GPIO interface to the pps subsystem for ntp support.
@@ -213,9 +213,9 @@ gpiopps_attach(device_t parent, device_t
 			return;
 		}
 		sc->sc_intrs[1].sc_irqmode = clear_edge;
-		if (!gpio_intr_str(sc->sc_gpio, >sc_map, 0,
-   sc->sc_intrs[0].sc_irqmode,
-   sc->sc_intrs[0].sc_intrstr,
+		if (!gpio_intr_str(sc->sc_gpio, >sc_map, 1,
+   sc->sc_intrs[1].sc_irqmode,
+   sc->sc_intrs[1].sc_intrstr,
    sizeof(sc->sc_intrs[1].sc_intrstr))) {
 			aprint_error_dev(self,
 			"failed to decode CLEAR interrupt\n");



CVS commit: src/sys/dev/gpio

2017-07-06 Thread Jared D. McNeill
Module Name:src
Committed By:   jmcneill
Date:   Thu Jul  6 10:43:06 UTC 2017

Modified Files:
src/sys/dev/gpio: gpio.c gpiovar.h

Log Message:
Let the controller provide a default name for pins. This makes pins easier
to locate when we have multiple banks and a variable number of pins per
bank.


To generate a diff of this commit:
cvs rdiff -u -r1.58 -r1.59 src/sys/dev/gpio/gpio.c
cvs rdiff -u -r1.16 -r1.17 src/sys/dev/gpio/gpiovar.h

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.58 src/sys/dev/gpio/gpio.c:1.59
--- src/sys/dev/gpio/gpio.c:1.58	Wed May 11 18:33:40 2016
+++ src/sys/dev/gpio/gpio.c	Thu Jul  6 10:43:06 2017
@@ -1,4 +1,4 @@
-/* $NetBSD: gpio.c,v 1.58 2016/05/11 18:33:40 bouyer Exp $ */
+/* $NetBSD: gpio.c,v 1.59 2017/07/06 10:43:06 jmcneill Exp $ */
 /*	$OpenBSD: gpio.c,v 1.6 2006/01/14 12:33:49 grange Exp $	*/
 
 /*
@@ -19,7 +19,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: gpio.c,v 1.58 2016/05/11 18:33:40 bouyer Exp $");
+__KERNEL_RCSID(0, "$NetBSD: gpio.c,v 1.59 2017/07/06 10:43:06 jmcneill Exp $");
 
 /*
  * General Purpose Input/Output framework.
@@ -202,6 +202,8 @@ gpio_attach(device_t parent, device_t se
 {
 	struct gpio_softc *sc = device_private(self);
 	struct gpiobus_attach_args *gba = aux;
+	struct gpio_name *nm;
+	int pin;
 
 	sc->sc_dev = self;
 	sc->sc_gc = gba->gba_gc;
@@ -211,6 +213,17 @@ gpio_attach(device_t parent, device_t se
 	aprint_normal(": %d pins\n", sc->sc_npins);
 	aprint_naive("\n");
 
+	/* Configure default pin names */
+	for (pin = 0; pin < sc->sc_npins; pin++) {
+		if (sc->sc_pins[pin].pin_defname[0] == '\0')
+			continue;
+		nm = kmem_alloc(sizeof(*nm), KM_SLEEP);
+		strlcpy(nm->gp_name, sc->sc_pins[pin].pin_defname,
+		sizeof(nm->gp_name));
+		nm->gp_pin = pin;
+		LIST_INSERT_HEAD(>sc_names, nm, gp_next);
+	}
+
 	if (!pmf_device_register(self, NULL, gpio_resume))
 		aprint_error_dev(self, "couldn't establish power handler\n");
 	mutex_init(>sc_mtx, MUTEX_DEFAULT, IPL_VM);

Index: src/sys/dev/gpio/gpiovar.h
diff -u src/sys/dev/gpio/gpiovar.h:1.16 src/sys/dev/gpio/gpiovar.h:1.17
--- src/sys/dev/gpio/gpiovar.h:1.16	Wed May 11 18:33:40 2016
+++ src/sys/dev/gpio/gpiovar.h	Thu Jul  6 10:43:06 2017
@@ -1,4 +1,4 @@
-/* $NetBSD: gpiovar.h,v 1.16 2016/05/11 18:33:40 bouyer Exp $ */
+/* $NetBSD: gpiovar.h,v 1.17 2017/07/06 10:43:06 jmcneill Exp $ */
 /*	$OpenBSD: gpiovar.h,v 1.3 2006/01/14 12:33:49 grange Exp $	*/
 
 /*
@@ -44,6 +44,7 @@ typedef struct gpio_pin {
 	gpio_chipset_tag_t	pin_gc;		/* reference the controller */
 	void			(*pin_callback)(void *); /* irq callback */
 	void *			pin_callback_arg; /* callback arg */
+	char			pin_defname[GPIOMAXNAME]; /* default name */
 } gpio_pin_t;
 
 /* Attach GPIO framework to the controller */



CVS commit: src/sys/dev/gpio

2015-10-15 Thread Jared D. McNeill
Module Name:src
Committed By:   jmcneill
Date:   Thu Oct 15 09:07:49 UTC 2015

Modified Files:
src/sys/dev/gpio: files.gpio

Log Message:
pull in sysmon_taskq


To generate a diff of this commit:
cvs rdiff -u -r1.13 -r1.14 src/sys/dev/gpio/files.gpio

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/files.gpio
diff -u src/sys/dev/gpio/files.gpio:1.13 src/sys/dev/gpio/files.gpio:1.14
--- src/sys/dev/gpio/files.gpio:1.13	Thu Aug 20 12:09:22 2015
+++ src/sys/dev/gpio/files.gpio	Thu Oct 15 09:07:49 2015
@@ -1,4 +1,4 @@
-# $NetBSD: files.gpio,v 1.13 2015/08/20 12:09:22 uebayasi Exp $
+# $NetBSD: files.gpio,v 1.14 2015/10/15 09:07:49 jmcneill Exp $
 
 define	gpio {[offset = -1], [mask = 0], [flag = 0]}
 
@@ -36,6 +36,6 @@ attach	gpiorfkill at gpio
 file	dev/gpio/gpiorfkill.c			gpiorfkill
 
 # Button
-device	gpiobutton: gpiobus, sysmon_power
+device	gpiobutton: gpiobus, sysmon_power, sysmon_taskq
 attach	gpiobutton at gpio
 file	dev/gpio/gpiobutton.c			gpiobutton



CVS commit: src/sys/dev/gpio

2015-10-04 Thread Jared D. McNeill
Module Name:src
Committed By:   jmcneill
Date:   Sun Oct  4 18:35:44 UTC 2015

Modified Files:
src/sys/dev/gpio: gpiobutton.c

Log Message:
Use sysmon_taskq instead of our own workqueue for submitting button events.


To generate a diff of this commit:
cvs rdiff -u -r1.2 -r1.3 src/sys/dev/gpio/gpiobutton.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/gpiobutton.c
diff -u src/sys/dev/gpio/gpiobutton.c:1.2 src/sys/dev/gpio/gpiobutton.c:1.3
--- src/sys/dev/gpio/gpiobutton.c:1.2	Sat May 30 17:12:16 2015
+++ src/sys/dev/gpio/gpiobutton.c	Sun Oct  4 18:35:44 2015
@@ -1,4 +1,4 @@
-/* $NetBSD: gpiobutton.c,v 1.2 2015/05/30 17:12:16 jmcneill Exp $ */
+/* $NetBSD: gpiobutton.c,v 1.3 2015/10/04 18:35:44 jmcneill Exp $ */
 
 /*-
  * Copyright (c) 2015 Jared D. McNeill 
@@ -29,7 +29,7 @@
 #include "locators.h"
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: gpiobutton.c,v 1.2 2015/05/30 17:12:16 jmcneill Exp $");
+__KERNEL_RCSID(0, "$NetBSD: gpiobutton.c,v 1.3 2015/10/04 18:35:44 jmcneill Exp $");
 
 #include 
 #include 
@@ -37,10 +37,10 @@ __KERNEL_RCSID(0, "$NetBSD: gpiobutton.c
 #include 
 #include 
 #include 
-#include 
 #include 
 
 #include 
+#include 
 
 #include 
 
@@ -65,15 +65,13 @@ struct gpiobutton_softc {
 
 	struct sysmon_pswitch	sc_smpsw;
 
-	struct workqueue	*sc_wq;
 	callout_t		sc_tick;
 	bool			sc_state;
-	struct work		sc_work;
 };
 
 static bool	gpiobutton_is_pressed(struct gpiobutton_softc *);
 static void	gpiobutton_tick(void *);
-static void	gpiobutton_task(struct work *, void *);
+static void	gpiobutton_task(void *);
 
 CFATTACH_DECL_NEW(gpiobutton, sizeof(struct gpiobutton_softc),
 	gpiobutton_match, gpiobutton_attach, NULL, NULL);
@@ -106,7 +104,7 @@ gpiobutton_attach(device_t parent, devic
 	struct gpiobutton_softc * const sc = device_private(self);
 	struct gpio_attach_args * const ga = aux;
 	const char *desc;
-	int caps, error;
+	int caps;
 
 	const u_int type = __SHIFTOUT(ga->ga_flags, GPIOBUTTON_TYPE_MASK);
 	const u_int pol = __SHIFTOUT(ga->ga_flags, GPIOBUTTON_POLARITY_MASK);
@@ -151,15 +149,7 @@ gpiobutton_attach(device_t parent, devic
 	callout_init(>sc_tick, CALLOUT_MPSAFE);
 	callout_setfunc(>sc_tick, gpiobutton_tick, sc);
 
-	error = workqueue_create(>sc_wq, device_xname(self),
-	gpiobutton_task, sc, PRI_NONE, IPL_VM, WQ_MPSAFE);
-	if (error) {
-		aprint_error_dev(self, "couldn't create workqueue: %d\n",
-		error);
-		return;
-	}
-
-	gpiobutton_task(>sc_work, sc);
+	gpiobutton_tick(sc);
 }
 
 static bool
@@ -179,20 +169,19 @@ gpiobutton_tick(void *priv)
 {
 	struct gpiobutton_softc * const sc = priv;
 
-	workqueue_enqueue(sc->sc_wq, >sc_work, NULL);
+	const bool new_state = gpiobutton_is_pressed(sc);
+	if (new_state != sc->sc_state) {
+		sc->sc_state = new_state;
+		sysmon_task_queue_sched(0, gpiobutton_task, sc);
+	}
+	callout_schedule(>sc_tick, GPIOBUTTON_POLL_INTERVAL);
 }
 
 static void
-gpiobutton_task(struct work *wk, void *priv)
+gpiobutton_task(void *priv)
 {
 	struct gpiobutton_softc * const sc = priv;
 
-	const bool new_state = gpiobutton_is_pressed(sc);
-	if (new_state != sc->sc_state) {
-		aprint_debug_dev(sc->sc_dev, "button pressed\n");
-		sysmon_pswitch_event(>sc_smpsw, PSWITCH_EVENT_PRESSED);
-		sc->sc_state = new_state;
-	}
-
-	callout_schedule(>sc_tick, GPIOBUTTON_POLL_INTERVAL);
+	sysmon_pswitch_event(>sc_smpsw,
+	sc->sc_state ? PSWITCH_EVENT_PRESSED : PSWITCH_EVENT_RELEASED);
 }



CVS commit: src/sys/dev/gpio

2015-09-01 Thread Frank Wille
Module Name:src
Committed By:   phx
Date:   Tue Sep  1 19:25:32 UTC 2015

Modified Files:
src/sys/dev/gpio: gpioiic.c

Log Message:
i2c_acquire_bus() should return 0 on success.
Fixed bug in gpioiic_bb_set_bits(), which was introduced with the SDA/SCL-
reverse feature.
Now the driver is confirmed to work. Tested with Raspberry Pi GPIO.


To generate a diff of this commit:
cvs rdiff -u -r1.6 -r1.7 src/sys/dev/gpio/gpioiic.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/gpioiic.c
diff -u src/sys/dev/gpio/gpioiic.c:1.6 src/sys/dev/gpio/gpioiic.c:1.7
--- src/sys/dev/gpio/gpioiic.c:1.6	Sat Oct 27 17:18:16 2012
+++ src/sys/dev/gpio/gpioiic.c	Tue Sep  1 19:25:32 2015
@@ -1,4 +1,4 @@
-/* $NetBSD: gpioiic.c,v 1.6 2012/10/27 17:18:16 chs Exp $ */
+/* $NetBSD: gpioiic.c,v 1.7 2015/09/01 19:25:32 phx Exp $ */
 /*	$OpenBSD: gpioiic.c,v 1.8 2008/11/24 12:12:12 mbalmer Exp $	*/
 
 /*
@@ -18,7 +18,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: gpioiic.c,v 1.6 2012/10/27 17:18:16 chs Exp $");
+__KERNEL_RCSID(0, "$NetBSD: gpioiic.c,v 1.7 2015/09/01 19:25:32 phx Exp $");
 
 /*
  * I2C bus bit-banging through GPIO pins.
@@ -232,10 +232,10 @@ gpioiic_i2c_acquire_bus(void *cookie, in
 	struct gpioiic_softc *sc = cookie;
 
 	if (flags & I2C_F_POLL)
-		return 0;
+		return 1;
 
 	rw_enter(>sc_i2c_lock, RW_WRITER);
-	return 1;
+	return 0;
 }
 
 void
@@ -286,8 +286,8 @@ gpioiic_bb_set_bits(void *cookie, uint32
 
 	gpio_pin_write(sc->sc_gpio, >sc_map, sc->sc_pin_sda,
 	bits & GPIOIIC_SDA ? GPIO_PIN_HIGH : GPIO_PIN_LOW);
-	gpio_pin_write(sc->sc_gpio, >sc_map, GPIOIIC_PIN_SCL,
-	bits & GPIOIIC_SCL ? GPIO_PIN_HIGH : sc->sc_pin_scl);
+	gpio_pin_write(sc->sc_gpio, >sc_map, sc->sc_pin_scl,
+	bits & GPIOIIC_SCL ? GPIO_PIN_HIGH : GPIO_PIN_LOW);
 }
 
 void



CVS commit: src/sys/dev/gpio

2015-08-20 Thread Masao Uebayashi
Module Name:src
Committed By:   uebayasi
Date:   Thu Aug 20 12:09:22 UTC 2015

Modified Files:
src/sys/dev/gpio: files.gpio gpiosim.c

Log Message:
Use needs-count for # of pseudo instances; suggested by cube@.


To generate a diff of this commit:
cvs rdiff -u -r1.12 -r1.13 src/sys/dev/gpio/files.gpio
cvs rdiff -u -r1.16 -r1.17 src/sys/dev/gpio/gpiosim.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/files.gpio
diff -u src/sys/dev/gpio/files.gpio:1.12 src/sys/dev/gpio/files.gpio:1.13
--- src/sys/dev/gpio/files.gpio:1.12	Sat May 30 15:35:51 2015
+++ src/sys/dev/gpio/files.gpio	Thu Aug 20 12:09:22 2015
@@ -1,4 +1,4 @@
-# $NetBSD: files.gpio,v 1.12 2015/05/30 15:35:51 jmcneill Exp $
+# $NetBSD: files.gpio,v 1.13 2015/08/20 12:09:22 uebayasi Exp $
 
 define	gpio {[offset = -1], [mask = 0], [flag = 0]}
 
@@ -8,7 +8,7 @@ file	dev/gpio/gpio.cgpio	needs-flag
 
 # GPIO simulator
 defpseudodev	gpiosim: gpiobus
-file	dev/gpio/gpiosim.c			gpiosim
+file	dev/gpio/gpiosim.c			gpiosim	needs-count
 
 # I2C bus bit-banging
 device	gpioiic: i2cbus, i2c_bitbang

Index: src/sys/dev/gpio/gpiosim.c
diff -u src/sys/dev/gpio/gpiosim.c:1.16 src/sys/dev/gpio/gpiosim.c:1.17
--- src/sys/dev/gpio/gpiosim.c:1.16	Tue Feb 25 18:30:09 2014
+++ src/sys/dev/gpio/gpiosim.c	Thu Aug 20 12:09:22 2015
@@ -1,4 +1,4 @@
-/* $NetBSD: gpiosim.c,v 1.16 2014/02/25 18:30:09 pooka Exp $ */
+/* $NetBSD: gpiosim.c,v 1.17 2015/08/20 12:09:22 uebayasi Exp $ */
 /*  $OpenBSD: gpiosim.c,v 1.1 2008/11/23 18:46:49 mbalmer Exp $	*/
 
 /*
@@ -30,6 +30,8 @@
 #include sys/ioccom.h
 #include dev/gpio/gpiovar.h
 
+#include gpiosim.h
+
 #define	GPIOSIM_NPINS	64
 
 struct gpiosim_softc {
@@ -64,7 +66,7 @@ gpiosim_match(device_t parent, cfdata_t 
 }
 
 void
-gpiosimattach(int num)
+gpiosimattach(int num __unused)
 {
 	cfdata_t cf;
 	int n, err;
@@ -73,7 +75,7 @@ gpiosimattach(int num)
 	if (err)
 		printf(%s: unable to register cfattach\n, gpiosim_cd.cd_name);
 
-	for (n = 0; n  num; n++) {
+	for (n = 0; n  NGPIOSIM; n++) {
 		cf = malloc(sizeof(*cf), M_DEVBUF, M_WAITOK);
 		cf-cf_name = gpiosim;
 		cf-cf_atname = gpiosim;



CVS commit: src/sys/dev/gpio

2015-05-30 Thread Jared D. McNeill
Module Name:src
Committed By:   jmcneill
Date:   Sat May 30 17:12:16 UTC 2015

Modified Files:
src/sys/dev/gpio: gpiobutton.c

Log Message:
remove debug printf


To generate a diff of this commit:
cvs rdiff -u -r1.1 -r1.2 src/sys/dev/gpio/gpiobutton.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/gpiobutton.c
diff -u src/sys/dev/gpio/gpiobutton.c:1.1 src/sys/dev/gpio/gpiobutton.c:1.2
--- src/sys/dev/gpio/gpiobutton.c:1.1	Sat May 30 15:35:51 2015
+++ src/sys/dev/gpio/gpiobutton.c	Sat May 30 17:12:16 2015
@@ -1,4 +1,4 @@
-/* $NetBSD: gpiobutton.c,v 1.1 2015/05/30 15:35:51 jmcneill Exp $ */
+/* $NetBSD: gpiobutton.c,v 1.2 2015/05/30 17:12:16 jmcneill Exp $ */
 
 /*-
  * Copyright (c) 2015 Jared D. McNeill jmcne...@invisible.ca
@@ -29,7 +29,7 @@
 #include locators.h
 
 #include sys/cdefs.h
-__KERNEL_RCSID(0, $NetBSD: gpiobutton.c,v 1.1 2015/05/30 15:35:51 jmcneill Exp $);
+__KERNEL_RCSID(0, $NetBSD: gpiobutton.c,v 1.2 2015/05/30 17:12:16 jmcneill Exp $);
 
 #include sys/param.h
 #include sys/bus.h
@@ -90,7 +90,7 @@ gpiobutton_match(device_t parent, cfdata
 		return 0;
 
 	const u_int type = __SHIFTOUT(ga-ga_flags, GPIOBUTTON_TYPE_MASK);
-	printf(%s: type is %u, flags %#x\n, __func__, type, ga-ga_flags);
+
 	switch (type) {
 	case GPIOBUTTON_TYPE_POWER:
 	case GPIOBUTTON_TYPE_SLEEP:



CVS commit: src/sys/dev/gpio

2015-05-30 Thread Jared D. McNeill
Module Name:src
Committed By:   jmcneill
Date:   Sat May 30 15:35:51 UTC 2015

Modified Files:
src/sys/dev/gpio: files.gpio
Added Files:
src/sys/dev/gpio: gpiobutton.c

Log Message:
Simple driver for GPIO power/sleep buttons.


To generate a diff of this commit:
cvs rdiff -u -r1.11 -r1.12 src/sys/dev/gpio/files.gpio
cvs rdiff -u -r0 -r1.1 src/sys/dev/gpio/gpiobutton.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/files.gpio
diff -u src/sys/dev/gpio/files.gpio:1.11 src/sys/dev/gpio/files.gpio:1.12
--- src/sys/dev/gpio/files.gpio:1.11	Fri May 29 23:17:13 2015
+++ src/sys/dev/gpio/files.gpio	Sat May 30 15:35:51 2015
@@ -1,4 +1,4 @@
-# $NetBSD: files.gpio,v 1.11 2015/05/29 23:17:13 jmcneill Exp $
+# $NetBSD: files.gpio,v 1.12 2015/05/30 15:35:51 jmcneill Exp $
 
 define	gpio {[offset = -1], [mask = 0], [flag = 0]}
 
@@ -34,3 +34,8 @@ file	dev/gpio/gpiopwm.c			gpiopwm
 device	gpiorfkill: gpiobus
 attach	gpiorfkill at gpio
 file	dev/gpio/gpiorfkill.c			gpiorfkill
+
+# Button
+device	gpiobutton: gpiobus, sysmon_power
+attach	gpiobutton at gpio
+file	dev/gpio/gpiobutton.c			gpiobutton

Added files:

Index: src/sys/dev/gpio/gpiobutton.c
diff -u /dev/null src/sys/dev/gpio/gpiobutton.c:1.1
--- /dev/null	Sat May 30 15:35:51 2015
+++ src/sys/dev/gpio/gpiobutton.c	Sat May 30 15:35:51 2015
@@ -0,0 +1,198 @@
+/* $NetBSD: gpiobutton.c,v 1.1 2015/05/30 15:35:51 jmcneill Exp $ */
+
+/*-
+ * Copyright (c) 2015 Jared D. McNeill jmcne...@invisible.ca
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *notice, this list of conditions and the following disclaimer in the
+ *documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
+ * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
+ * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
+ * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
+ * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
+ * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
+ * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
+ * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
+ * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ */
+
+#include locators.h
+
+#include sys/cdefs.h
+__KERNEL_RCSID(0, $NetBSD: gpiobutton.c,v 1.1 2015/05/30 15:35:51 jmcneill Exp $);
+
+#include sys/param.h
+#include sys/bus.h
+#include sys/device.h
+#include sys/intr.h
+#include sys/systm.h
+#include sys/kernel.h
+#include sys/workqueue.h
+#include sys/gpio.h
+
+#include dev/sysmon/sysmonvar.h
+
+#include dev/gpio/gpiovar.h
+
+#define GPIOBUTTON_POLL_INTERVAL	mstohz(200)
+
+#define GPIOBUTTON_POLARITY_MASK	0x80
+#define GPIOBUTTON_POLARITY_ACTIVE_LOW	0
+#define GPIOBUTTON_POLARITY_ACTIVE_HIGH	1
+#define GPIOBUTTON_TYPE_MASK		0x0f
+#define GPIOBUTTON_TYPE_POWER		1
+#define GPIOBUTTON_TYPE_SLEEP		2
+
+static int	gpiobutton_match(device_t, cfdata_t, void *);
+static void	gpiobutton_attach(device_t, device_t, void *);
+
+struct gpiobutton_softc {
+	device_t		sc_dev;
+	void			*sc_gpio;
+	struct gpio_pinmap	sc_map;
+	int			sc_pinmap[1];
+	bool			sc_active_high;
+
+	struct sysmon_pswitch	sc_smpsw;
+
+	struct workqueue	*sc_wq;
+	callout_t		sc_tick;
+	bool			sc_state;
+	struct work		sc_work;
+};
+
+static bool	gpiobutton_is_pressed(struct gpiobutton_softc *);
+static void	gpiobutton_tick(void *);
+static void	gpiobutton_task(struct work *, void *);
+
+CFATTACH_DECL_NEW(gpiobutton, sizeof(struct gpiobutton_softc),
+	gpiobutton_match, gpiobutton_attach, NULL, NULL);
+
+static int
+gpiobutton_match(device_t parent, cfdata_t cf, void *aux)
+{
+	struct gpio_attach_args * const ga = aux;
+
+	if (strcmp(ga-ga_dvname, cf-cf_name) != 0)
+		return 0;
+
+	if (ga-ga_offset == -1 || gpio_npins(ga-ga_mask) != 1)
+		return 0;
+
+	const u_int type = __SHIFTOUT(ga-ga_flags, GPIOBUTTON_TYPE_MASK);
+	printf(%s: type is %u, flags %#x\n, __func__, type, ga-ga_flags);
+	switch (type) {
+	case GPIOBUTTON_TYPE_POWER:
+	case GPIOBUTTON_TYPE_SLEEP:
+		return 1;
+	default:
+		return 0;
+	}
+}
+
+static void
+gpiobutton_attach(device_t parent, device_t self, void *aux)
+{
+	struct gpiobutton_softc * const sc = device_private(self);
+	struct gpio_attach_args * const ga = aux;
+	const char *desc;
+	int caps, error;
+
+	const u_int type = 

CVS commit: src/sys/dev/gpio

2015-05-29 Thread Jared D. McNeill
Module Name:src
Committed By:   jmcneill
Date:   Fri May 29 23:17:13 UTC 2015

Modified Files:
src/sys/dev/gpio: files.gpio
Added Files:
src/sys/dev/gpio: gpiorfkill.c

Log Message:
Simple driver for gpio control of rf enable/disable pins.


To generate a diff of this commit:
cvs rdiff -u -r1.10 -r1.11 src/sys/dev/gpio/files.gpio
cvs rdiff -u -r0 -r1.1 src/sys/dev/gpio/gpiorfkill.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/files.gpio
diff -u src/sys/dev/gpio/files.gpio:1.10 src/sys/dev/gpio/files.gpio:1.11
--- src/sys/dev/gpio/files.gpio:1.10	Sun Nov 13 12:33:00 2011
+++ src/sys/dev/gpio/files.gpio	Fri May 29 23:17:13 2015
@@ -1,4 +1,4 @@
-# $NetBSD: files.gpio,v 1.10 2011/11/13 12:33:00 mbalmer Exp $
+# $NetBSD: files.gpio,v 1.11 2015/05/29 23:17:13 jmcneill Exp $
 
 define	gpio {[offset = -1], [mask = 0], [flag = 0]}
 
@@ -29,3 +29,8 @@ file	dev/gpio/gpiolock.c			gpiolock
 device	gpiopwm: gpiobus
 attach	gpiopwm at gpio
 file	dev/gpio/gpiopwm.c			gpiopwm
+
+# RF kill
+device	gpiorfkill: gpiobus
+attach	gpiorfkill at gpio
+file	dev/gpio/gpiorfkill.c			gpiorfkill

Added files:

Index: src/sys/dev/gpio/gpiorfkill.c
diff -u /dev/null src/sys/dev/gpio/gpiorfkill.c:1.1
--- /dev/null	Fri May 29 23:17:13 2015
+++ src/sys/dev/gpio/gpiorfkill.c	Fri May 29 23:17:13 2015
@@ -0,0 +1,166 @@
+/* $NetBSD: gpiorfkill.c,v 1.1 2015/05/29 23:17:13 jmcneill Exp $ */
+
+/*-
+ * Copyright (c) 2015 Jared D. McNeill jmcne...@invisible.ca
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *notice, this list of conditions and the following disclaimer in the
+ *documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
+ * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
+ * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
+ * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
+ * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
+ * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
+ * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
+ * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
+ * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ */
+
+#include locators.h
+
+#include sys/cdefs.h
+__KERNEL_RCSID(0, $NetBSD: gpiorfkill.c,v 1.1 2015/05/29 23:17:13 jmcneill Exp $);
+
+#include sys/param.h
+#include sys/bus.h
+#include sys/device.h
+#include sys/intr.h
+#include sys/systm.h
+#include sys/kernel.h
+#include sys/sysctl.h
+#include sys/gpio.h
+
+#include dev/gpio/gpiovar.h
+
+static int	gpiorfkill_match(device_t, cfdata_t, void *);
+static void	gpiorfkill_attach(device_t, device_t, void *);
+
+struct gpiorfkill_softc {
+	device_t		sc_dev;
+	void			*sc_gpio;
+	struct gpio_pinmap	sc_map;
+	int			sc_pinmap[1];
+
+	int			sc_state;
+
+	struct sysctllog	*sc_sysctllog;
+	int			sc_sysctlnode;
+};
+
+static void	gpiorfkill_enable(struct gpiorfkill_softc *, int);
+static void	gpiorfkill_sysctl_init(struct gpiorfkill_softc *);
+static int	gpiorfkill_enable_helper(SYSCTLFN_PROTO);
+
+CFATTACH_DECL_NEW(gpiorfkill, sizeof(struct gpiorfkill_softc),
+	gpiorfkill_match, gpiorfkill_attach, NULL, NULL);
+
+static int
+gpiorfkill_match(device_t parent, cfdata_t cf, void *aux)
+{
+	struct gpio_attach_args * const ga = aux;
+
+	if (strcmp(ga-ga_dvname, cf-cf_name) != 0)
+		return 0;
+
+	if (ga-ga_offset == -1 || gpio_npins(ga-ga_mask) != 1)
+		return 0;
+
+	return 1;
+}
+
+static void
+gpiorfkill_attach(device_t parent, device_t self, void *aux)
+{
+	struct gpiorfkill_softc * const sc = device_private(self);
+	struct gpio_attach_args * const ga = aux;
+	int caps;
+
+	sc-sc_dev = self;
+	sc-sc_gpio = ga-ga_gpio;
+	sc-sc_map.pm_map = sc-sc_pinmap;
+	if (gpio_pin_map(sc-sc_gpio, ga-ga_offset, ga-ga_mask,
+	sc-sc_map)) {
+		aprint_error(: couldn't map pins\n);
+		return;
+	}
+
+	caps = gpio_pin_caps(sc-sc_gpio, sc-sc_map, 0);
+	if ((caps  GPIO_PIN_OUTPUT) == 0) {
+		aprint_error(: pin is not an output pin\n);
+		return;
+	}
+
+	gpio_pin_ctl(sc-sc_gpio, sc-sc_map, 0, GPIO_PIN_OUTPUT);
+
+	aprint_naive(\n);
+	aprint_normal(\n);
+
+	gpiorfkill_enable(sc, 1);
+	gpiorfkill_sysctl_init(sc);
+}
+
+static void
+gpiorfkill_enable(struct gpiorfkill_softc *sc, int enable)
+{
+	sc-sc_state = enable;
+	gpio_pin_write(sc-sc_gpio, sc-sc_map, 0, 

CVS commit: src/sys/dev/gpio

2014-06-29 Thread Frank Kardel
Module Name:src
Committed By:   kardel
Date:   Sun Jun 29 09:32:24 UTC 2014

Modified Files:
src/sys/dev/gpio: gpio.c

Log Message:
make implementation match gpio(4) man entry. do no change configuration
if no flags are be set (allows non-destructive inquiry via GPIOSET again).


To generate a diff of this commit:
cvs rdiff -u -r1.55 -r1.56 src/sys/dev/gpio/gpio.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.55 src/sys/dev/gpio/gpio.c:1.56
--- src/sys/dev/gpio/gpio.c:1.55	Fri May 23 13:57:04 2014
+++ src/sys/dev/gpio/gpio.c	Sun Jun 29 09:32:24 2014
@@ -1,4 +1,4 @@
-/* $NetBSD: gpio.c,v 1.55 2014/05/23 13:57:04 msaitoh Exp $ */
+/* $NetBSD: gpio.c,v 1.56 2014/06/29 09:32:24 kardel 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.55 2014/05/23 13:57:04 msaitoh Exp $);
+__KERNEL_RCSID(0, $NetBSD: gpio.c,v 1.56 2014/06/29 09:32:24 kardel Exp $);
 
 /*
  * General Purpose Input/Output framework.
@@ -699,12 +699,14 @@ gpio_ioctl(struct gpio_softc *sc, u_long
 		/* check that the controller supports all requested flags */
 		if ((flags  sc-sc_pins[pin].pin_caps) != flags)
 			return ENODEV;
-		flags = set-gp_flags | GPIO_PIN_SET;
+		flags = set-gp_flags;
 
 		set-gp_caps = sc-sc_pins[pin].pin_caps;
 		/* return old value */
 		set-gp_flags = sc-sc_pins[pin].pin_flags;
+
 		if (flags  0) {
+			flags |= GPIO_PIN_SET;
 			gpiobus_pin_ctl(gc, pin, flags);
 			/* update current value */
 			sc-sc_pins[pin].pin_flags = flags;



CVS commit: src/sys/dev/gpio

2013-05-20 Thread Marc Balmer
Module Name:src
Committed By:   mbalmer
Date:   Mon May 20 15:46:41 UTC 2013

Modified Files:
src/sys/dev/gpio: gpio.c

Log Message:
When returning the old value, use the value read from the device.


To generate a diff of this commit:
cvs rdiff -u -r1.51 -r1.52 src/sys/dev/gpio/gpio.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.51 src/sys/dev/gpio/gpio.c:1.52
--- src/sys/dev/gpio/gpio.c:1.51	Wed Oct 17 21:35:39 2012
+++ src/sys/dev/gpio/gpio.c	Mon May 20 15:46:41 2013
@@ -1,4 +1,4 @@
-/* $NetBSD: gpio.c,v 1.51 2012/10/17 21:35:39 dyoung Exp $ */
+/* $NetBSD: gpio.c,v 1.52 2013/05/20 15:46:41 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.51 2012/10/17 21:35:39 dyoung Exp $);
+__KERNEL_RCSID(0, $NetBSD: gpio.c,v 1.52 2013/05/20 15:46:41 mbalmer Exp $);
 
 /*
  * General Purpose Input/Output framework.
@@ -562,9 +562,9 @@ gpio_ioctl(struct gpio_softc *sc, u_long
 		if (value != GPIO_PIN_LOW  value != GPIO_PIN_HIGH)
 			return EINVAL;
 
-		gpiobus_pin_write(gc, pin, value);
 		/* return old value */
-		req-gp_value = sc-sc_pins[pin].pin_state;
+		req-gp_value = gpiobus_pin_read(gc, pin);
+		gpiobus_pin_write(gc, pin, value);
 		/* update current value */
 		sc-sc_pins[pin].pin_state = value;
 		break;



CVS commit: src/sys/dev/gpio

2013-05-20 Thread Marc Balmer
Module Name:src
Committed By:   mbalmer
Date:   Mon May 20 15:48:25 UTC 2013

Modified Files:
src/sys/dev/gpio: gpiosim.c

Log Message:
Make the gpiosim(4) device a 64 bit wide GPIO.


To generate a diff of this commit:
cvs rdiff -u -r1.14 -r1.15 src/sys/dev/gpio/gpiosim.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/gpiosim.c
diff -u src/sys/dev/gpio/gpiosim.c:1.14 src/sys/dev/gpio/gpiosim.c:1.15
--- src/sys/dev/gpio/gpiosim.c:1.14	Sat Jun  2 21:36:44 2012
+++ src/sys/dev/gpio/gpiosim.c	Mon May 20 15:48:25 2013
@@ -1,8 +1,8 @@
-/* $NetBSD: gpiosim.c,v 1.14 2012/06/02 21:36:44 dsl Exp $ */
+/* $NetBSD: gpiosim.c,v 1.15 2013/05/20 15:48:25 mbalmer Exp $ */
 /*  $OpenBSD: gpiosim.c,v 1.1 2008/11/23 18:46:49 mbalmer Exp $	*/
 
 /*
- * Copyright (c) 2007, 2008, 2009, 2010, 2011 Marc Balmer m...@msys.ch
+ * Copyright (c) 2007 - 2011, 2013 Marc Balmer m...@msys.ch
  * All rights reserved.
  *
  * Permission to use, copy, modify, and distribute this software for any
@@ -18,7 +18,7 @@
  * OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
  */
 
-/* 32 bit wide GPIO simulator  */
+/* 64 bit wide GPIO simulator  */
 
 #include sys/param.h
 #include sys/systm.h
@@ -30,12 +30,12 @@
 #include sys/ioccom.h
 #include dev/gpio/gpiovar.h
 
-#define	GPIOSIM_NPINS	32
+#define	GPIOSIM_NPINS	64
 
 struct gpiosim_softc {
 	device_t		sc_dev;
 	device_t		sc_gdev;	/* gpio that attaches here */
-	uint32_t		sc_state;
+	uint64_t		sc_state;
 	struct gpio_chipset_tag	sc_gpio_gc;
 	gpio_pin_t		sc_gpio_pins[GPIOSIM_NPINS];
 
@@ -105,19 +105,19 @@ gpiosim_attach(device_t parent, device_t
 
 		/* read initial state */
 		sc-sc_gpio_pins[i].pin_flags = GPIO_PIN_INPUT;
-		sc-sc_state = 0;
-
-		/* create controller tag */
-		sc-sc_gpio_gc.gp_cookie = sc;
-		sc-sc_gpio_gc.gp_pin_read = gpiosim_pin_read;
-		sc-sc_gpio_gc.gp_pin_write = gpiosim_pin_write;
-		sc-sc_gpio_gc.gp_pin_ctl = gpiosim_pin_ctl;
-
-		/* gba.gba_name = gpio; */
-		gba.gba_gc = sc-sc_gpio_gc;
-		gba.gba_pins = sc-sc_gpio_pins;
-		gba.gba_npins = GPIOSIM_NPINS;
 	}
+	sc-sc_state = 0;
+
+	/* create controller tag */
+	sc-sc_gpio_gc.gp_cookie = sc;
+	sc-sc_gpio_gc.gp_pin_read = gpiosim_pin_read;
+	sc-sc_gpio_gc.gp_pin_write = gpiosim_pin_write;
+	sc-sc_gpio_gc.gp_pin_ctl = gpiosim_pin_ctl;
+
+	/* gba.gba_name = gpio; */
+	gba.gba_gc = sc-sc_gpio_gc;
+	gba.gba_pins = sc-sc_gpio_pins;
+	gba.gba_npins = GPIOSIM_NPINS;
 
 	pmf_device_register(self, NULL, NULL);
 
@@ -140,7 +140,7 @@ gpiosim_attach(device_t parent, device_t
 
 sysctl_createv(sc-sc_log, 0, node, NULL,
 CTLFLAG_READWRITE,
-CTLTYPE_INT, value,
+CTLTYPE_QUAD, value,
 SYSCTL_DESCR(Current GPIO simulator value),
 gpiosim_sysctl, 0, (void *)sc, 0,
 	CTL_CREATE, CTL_EOL);
@@ -171,7 +171,7 @@ gpiosim_sysctl(SYSCTLFN_ARGS)
 {
 	struct sysctlnode node;
 	struct gpiosim_softc *sc;
-	int val, error;
+	uint64_t val, error;
 
 	node = *rnode;
 	sc = node.sysctl_data;
@@ -192,7 +192,7 @@ gpiosim_pin_read(void *arg, int pin)
 {
 	struct gpiosim_softc *sc = arg;
 
-	if (sc-sc_state  (1  pin))
+	if (sc-sc_state  (1LL  pin))
 		return GPIO_PIN_HIGH;
 	else
 		return GPIO_PIN_LOW;
@@ -204,9 +204,9 @@ gpiosim_pin_write(void *arg, int pin, in
 	struct gpiosim_softc *sc = arg;
 
 	if (value == 0)
-		sc-sc_state = ~(1  pin);
+		sc-sc_state = ~(1LL  pin);
 	else
-		sc-sc_state |= (1  pin);
+		sc-sc_state |= (1LL  pin);
 }
 
 static void



CVS commit: src/sys/dev/gpio

2011-11-25 Thread Marc Balmer
Module Name:src
Committed By:   mbalmer
Date:   Fri Nov 25 13:49:43 UTC 2011

Modified Files:
src/sys/dev/gpio: gpio.c

Log Message:
Don't ignore the gpiobus_close() return value.  Found by joerg@ using clang.


To generate a diff of this commit:
cvs rdiff -u -r1.49 -r1.50 src/sys/dev/gpio/gpio.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.49 src/sys/dev/gpio/gpio.c:1.50
--- src/sys/dev/gpio/gpio.c:1.49	Mon Nov 14 07:45:54 2011
+++ src/sys/dev/gpio/gpio.c	Fri Nov 25 13:49:43 2011
@@ -1,4 +1,4 @@
-/* $NetBSD: gpio.c,v 1.49 2011/11/14 07:45:54 mbalmer Exp $ */
+/* $NetBSD: gpio.c,v 1.50 2011/11/25 13:49:43 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.49 2011/11/14 07:45:54 mbalmer Exp $);
+__KERNEL_RCSID(0, $NetBSD: gpio.c,v 1.50 2011/11/25 13:49:43 mbalmer Exp $);
 
 /*
  * General Purpose Input/Output framework.
@@ -442,8 +442,7 @@ gpioclose(dev_t dev, int flag, int mode,
 	struct gpio_softc *sc;
 
 	sc = device_lookup_private(gpio_cd, minor(dev));
-	gpiobus_close(sc-sc_gc, sc-sc_dev);
-	return 0;
+	return gpiobus_close(sc-sc_gc, sc-sc_dev);
 }
 
 static int



CVS commit: src/sys/dev/gpio

2011-11-13 Thread Marc Balmer
Module Name:src
Committed By:   mbalmer
Date:   Sun Nov 13 12:33:01 UTC 2011

Modified Files:
src/sys/dev/gpio: files.gpio
Added Files:
src/sys/dev/gpio: gpiopwm.c

Log Message:
gpiopwm(4) is a driver to pulse GPIO pins in software.  This obsoletes
the software pulsing facilities in gpio(4) (and gpioctl(8)) which will
later be removed.


To generate a diff of this commit:
cvs rdiff -u -r1.9 -r1.10 src/sys/dev/gpio/files.gpio
cvs rdiff -u -r0 -r1.1 src/sys/dev/gpio/gpiopwm.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/files.gpio
diff -u src/sys/dev/gpio/files.gpio:1.9 src/sys/dev/gpio/files.gpio:1.10
--- src/sys/dev/gpio/files.gpio:1.9	Sun Oct  2 10:01:25 2011
+++ src/sys/dev/gpio/files.gpio	Sun Nov 13 12:33:00 2011
@@ -1,4 +1,4 @@
-# $NetBSD: files.gpio,v 1.9 2011/10/02 10:01:25 mbalmer Exp $
+# $NetBSD: files.gpio,v 1.10 2011/11/13 12:33:00 mbalmer Exp $
 
 define	gpio {[offset = -1], [mask = 0], [flag = 0]}
 
@@ -24,3 +24,8 @@ file	dev/gpio/gpioow.c			gpioow
 device	gpiolock: gpiobus
 attach	gpiolock at gpio
 file	dev/gpio/gpiolock.c			gpiolock
+
+# PWM
+device	gpiopwm: gpiobus
+attach	gpiopwm at gpio
+file	dev/gpio/gpiopwm.c			gpiopwm

Added files:

Index: src/sys/dev/gpio/gpiopwm.c
diff -u /dev/null src/sys/dev/gpio/gpiopwm.c:1.1
--- /dev/null	Sun Nov 13 12:33:01 2011
+++ src/sys/dev/gpio/gpiopwm.c	Sun Nov 13 12:33:01 2011
@@ -0,0 +1,246 @@
+/* $NetBSD: gpiopwm.c,v 1.1 2011/11/13 12:33:01 mbalmer Exp $ */
+
+/*
+ * Copyright (c) 2011 Marc Balmer m...@msys.ch
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *notice, this list of conditions and the following disclaimer in the
+ *documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
+ * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
+ * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
+ * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
+ * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
+ * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+ * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+ * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
+ * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+/*
+ * Driver for pulsing GPIO pins in software
+ */
+
+#include sys/param.h
+#include sys/device.h
+#include sys/gpio.h
+#include sys/sysctl.h
+
+#include dev/gpio/gpiovar.h
+
+#define GPIOPWM_NPINS	1
+
+struct gpiopwm_softc {
+	device_t		 sc_dev;
+	void			*sc_gpio;
+	struct gpio_pinmap	 sc_map;
+	int			 _map[GPIOPWM_NPINS];
+
+	callout_t		 sc_pulse;
+	int			 sc_ticks_on;
+	int			 sc_ticks_off;
+
+	struct sysctllog	*sc_log;
+	int			 sc_dying;
+};
+
+int gpiopwm_match(device_t, cfdata_t, void *);
+void gpiopwm_attach(device_t, device_t, void *);
+int gpiopwm_detach(device_t, int);
+int gpiopwm_activate(device_t, enum devact);
+static int gpiopwm_set_on(SYSCTLFN_ARGS);
+static int gpiopwm_set_off(SYSCTLFN_ARGS);
+static void gpiopwm_pulse(void *);
+
+CFATTACH_DECL_NEW(gpiopwm, sizeof(struct gpiopwm_softc),
+	gpiopwm_match, gpiopwm_attach, gpiopwm_detach, gpiopwm_activate);
+
+extern struct cfdriver gpiopwm_cd;
+
+int
+gpiopwm_match(device_t parent, cfdata_t cf,
+void *aux)
+{
+	struct gpio_attach_args *ga = aux;
+
+	if (strcmp(ga-ga_dvname, cf-cf_name))
+		return 0;
+
+	if (ga-ga_offset == -1)
+		return 0;
+
+	/* Check number of pins, must be 1 */
+	if (gpio_npins(ga-ga_mask) != GPIOPWM_NPINS) {
+		aprint_debug(%s: invalid pin mask 0x%02x\n, cf-cf_name,
+		ga-ga_mask);
+		return 0;
+	}
+	return 1;
+}
+
+void
+gpiopwm_attach(device_t parent, device_t self, void *aux)
+{
+	struct gpiopwm_softc *sc = device_private(self);
+	struct gpio_attach_args *ga = aux;
+	const struct sysctlnode *node;
+
+	sc-sc_dev = self;
+
+	/* Map pin */
+	sc-sc_gpio = ga-ga_gpio;
+	sc-sc_map.pm_map = sc-_map;
+	if (gpio_pin_map(sc-sc_gpio, ga-ga_offset, ga-ga_mask,
+	sc-sc_map)) {
+		aprint_error(: can't map pin\n);
+		return;
+	}
+	aprint_normal( [%d], sc-sc_map.pm_map[0]);
+	pmf_device_register(self, NULL, NULL);
+
+	callout_init(sc-sc_pulse, CALLOUT_MPSAFE);
+	callout_setfunc(sc-sc_pulse, gpiopwm_pulse, sc);
+
+	sysctl_createv(NULL, 0, NULL, NULL,
+CTLFLAG_PERMANENT,
+CTLTYPE_NODE, hw, NULL,
+NULL, 0, NULL, 0,
+ 

CVS commit: src/sys/dev/gpio

2011-11-13 Thread Marc Balmer
Module Name:src
Committed By:   mbalmer
Date:   Sun Nov 13 13:16:33 UTC 2011

Modified Files:
src/sys/dev/gpio: gpiopwm.c

Log Message:
On detach, set the pin to low state.


To generate a diff of this commit:
cvs rdiff -u -r1.1 -r1.2 src/sys/dev/gpio/gpiopwm.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/gpiopwm.c
diff -u src/sys/dev/gpio/gpiopwm.c:1.1 src/sys/dev/gpio/gpiopwm.c:1.2
--- src/sys/dev/gpio/gpiopwm.c:1.1	Sun Nov 13 12:33:01 2011
+++ src/sys/dev/gpio/gpiopwm.c	Sun Nov 13 13:16:33 2011
@@ -1,4 +1,4 @@
-/* $NetBSD: gpiopwm.c,v 1.1 2011/11/13 12:33:01 mbalmer Exp $ */
+/* $NetBSD: gpiopwm.c,v 1.2 2011/11/13 13:16:33 mbalmer Exp $ */
 
 /*
  * Copyright (c) 2011 Marc Balmer m...@msys.ch
@@ -150,6 +150,7 @@ gpiopwm_detach(device_t self, int flags)
 
 	callout_halt(sc-sc_pulse, NULL);
 	callout_destroy(sc-sc_pulse);
+	gpio_pin_write(sc-sc_gpio, sc-sc_map, 0, GPIO_PIN_LOW);
 
 	pmf_device_deregister(self);
 	gpio_pin_unmap(sc-sc_gpio, sc-sc_map);



CVS commit: src/sys/dev/gpio

2011-11-13 Thread Marc Balmer
Module Name:src
Committed By:   mbalmer
Date:   Sun Nov 13 14:02:01 UTC 2011

Modified Files:
src/sys/dev/gpio: gpio.c

Log Message:
Remove an unused variable.


To generate a diff of this commit:
cvs rdiff -u -r1.47 -r1.48 src/sys/dev/gpio/gpio.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.47 src/sys/dev/gpio/gpio.c:1.48
--- src/sys/dev/gpio/gpio.c:1.47	Sun Nov 13 13:20:02 2011
+++ src/sys/dev/gpio/gpio.c	Sun Nov 13 14:02:01 2011
@@ -1,4 +1,4 @@
-/* $NetBSD: gpio.c,v 1.47 2011/11/13 13:20:02 mbalmer Exp $ */
+/* $NetBSD: gpio.c,v 1.48 2011/11/13 14:02:01 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.47 2011/11/13 13:20:02 mbalmer Exp $);
+__KERNEL_RCSID(0, $NetBSD: gpio.c,v 1.48 2011/11/13 14:02:01 mbalmer Exp $);
 
 /*
  * General Purpose Input/Output framework.
@@ -479,7 +479,6 @@ gpio_ioctl(struct gpio_softc *sc, u_long
 	struct gpio_req *req;
 	struct gpio_name *nm;
 	struct gpio_set *set;
-	struct gpio_pin *gpin;
 #ifdef COMPAT_50
 	struct gpio_dev *gdev;
 #endif



CVS commit: src/sys/dev/gpio

2011-10-03 Thread Marc Balmer
Module Name:src
Committed By:   mbalmer
Date:   Mon Oct  3 08:23:58 UTC 2011

Modified Files:
src/sys/dev/gpio: gpio.c

Log Message:
Don't cast void pointers.


To generate a diff of this commit:
cvs rdiff -u -r1.42 -r1.43 src/sys/dev/gpio/gpio.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.42 src/sys/dev/gpio/gpio.c:1.43
--- src/sys/dev/gpio/gpio.c:1.42	Sun Oct  2 09:33:19 2011
+++ src/sys/dev/gpio/gpio.c	Mon Oct  3 08:23:58 2011
@@ -1,4 +1,4 @@
-/* $NetBSD: gpio.c,v 1.42 2011/10/02 09:33:19 mbalmer Exp $ */
+/* $NetBSD: gpio.c,v 1.43 2011/10/03 08:23:58 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.42 2011/10/02 09:33:19 mbalmer Exp $);
+__KERNEL_RCSID(0, $NetBSD: gpio.c,v 1.43 2011/10/03 08:23:58 mbalmer Exp $);
 
 /*
  * General Purpose Input/Output framework.
@@ -403,7 +403,7 @@ gpio_lock(void *data)
 	int error;
 
 	error = 0;
-	sc = (struct gpio_softc *)data;
+	sc = data;
 	mutex_enter(sc-sc_mtx);
 	while (sc-sc_ioctl_busy) {
 		error = cv_wait_sig(sc-sc_ioctl, sc-sc_mtx);
@@ -421,7 +421,7 @@ gpio_unlock(void *data)
 {
 	struct gpio_softc *sc;
 
-	sc = (struct gpio_softc *)data;
+	sc = data;
 	mutex_enter(sc-sc_mtx);
 	sc-sc_ioctl_busy = 0;
 	cv_signal(sc-sc_ioctl);
@@ -466,7 +466,7 @@ gpio_pulse(void *arg)
 {
 	struct gpio_pin *pin;
 
-	pin = (struct gpio_pin *)arg;
+	pin = arg;
 	if ((pin-pin_state  GPIO_PIN_PULSE) == 0)
 		return;
 
@@ -531,7 +531,7 @@ gpio_ioctl(struct gpio_softc *sc, u_long
 
 	switch (cmd) {
 	case GPIOINFO:
-		info = (struct gpio_info *)data;
+		info = data;
 		if (!kauth_authorize_device(cred, KAUTH_DEVICE_GPIO_PINSET,
 		NULL, NULL, NULL, NULL))
 			info-gpio_npins = sc-sc_npins;
@@ -543,7 +543,7 @@ gpio_ioctl(struct gpio_softc *sc, u_long
 		}
 		break;
 	case GPIOREAD:
-		req = (struct gpio_req *)data;
+		req = data;
 
 		if (req-gp_name[0] != '\0')
 			pin = gpio_pinbyname(sc, req-gp_name);
@@ -565,7 +565,7 @@ gpio_ioctl(struct gpio_softc *sc, u_long
 		if ((flag  FWRITE) == 0)
 			return EBADF;
 
-		req = (struct gpio_req *)data;
+		req = data;
 
 		if (req-gp_name[0] != '\0')
 			pin = gpio_pinbyname(sc, req-gp_name);
@@ -601,7 +601,7 @@ gpio_ioctl(struct gpio_softc *sc, u_long
 		if ((flag  FWRITE) == 0)
 			return EBADF;
 
-		pulse = (struct gpio_pulse *)data;
+		pulse = data;
 		if (pulse-gp_name[0] != '\0')
 			pin = gpio_pinbyname(sc, pulse-gp_name);
 		else
@@ -644,7 +644,7 @@ gpio_ioctl(struct gpio_softc *sc, u_long
 		if ((flag  FWRITE) == 0)
 			return EBADF;
 
-		req = (struct gpio_req *)data;
+		req = data;
 
 		if (req-gp_name[0] != '\0')
 			pin = gpio_pinbyname(sc, req-gp_name);
@@ -671,7 +671,7 @@ gpio_ioctl(struct gpio_softc *sc, u_long
 		sc-sc_pins[pin].pin_state = value;
 		break;
 	case GPIOATTACH:
-		attach = (struct gpio_attach *)data;
+		attach = data;
 		ga.ga_flags = attach-ga_flags;
 #ifdef COMPAT_50
 		/* FALLTHROUGH */
@@ -683,7 +683,7 @@ gpio_ioctl(struct gpio_softc *sc, u_long
 		 * GPIOATTACH50 ioctl(2), which had not the ga_flags field
 		 * in struct gpio_attach.
 		 */
-		attach = (struct gpio_attach *)data;
+		attach = data;
 #endif
 		if (kauth_authorize_device(cred, KAUTH_DEVICE_GPIO_PINSET,
 		NULL, NULL, NULL, NULL))
@@ -759,7 +759,7 @@ gpio_ioctl(struct gpio_softc *sc, u_long
 		if (error)
 			return EBUSY;
 
-		attach = (struct gpio_attach *)data;
+		attach = data;
 		LIST_FOREACH(gdev, sc-sc_devs, sc_next) {
 			if (strcmp(device_xname(gdev-sc_dev),
 			attach-ga_dvname) == 0) {
@@ -785,7 +785,7 @@ gpio_ioctl(struct gpio_softc *sc, u_long
 		NULL, NULL, NULL, NULL))
 			return EPERM;
 
-		set = (struct gpio_set *)data;
+		set = data;
 
 		if (set-gp_name[0] != '\0')
 			pin = gpio_pinbyname(sc, set-gp_name);
@@ -840,7 +840,7 @@ gpio_ioctl(struct gpio_softc *sc, u_long
 		NULL, NULL, NULL, NULL))
 			return EPERM;
 
-		set = (struct gpio_set *)data;
+		set = data;
 		if (set-gp_name[0] != '\0')
 			pin = gpio_pinbyname(sc, set-gp_name);
 		else
@@ -888,7 +888,7 @@ gpio_ioctl_oapi(struct gpio_softc *sc, u
 
 	switch (cmd) {
 	case GPIOPINREAD:
-		op = (struct gpio_pin_op *)data;
+		op = data;
 
 		pin = op-gp_pin;
 
@@ -907,7 +907,7 @@ gpio_ioctl_oapi(struct gpio_softc *sc, u
 		if ((flag  FWRITE) == 0)
 			return EBADF;
 
-		op = (struct gpio_pin_op *)data;
+		op = data;
 
 		pin = op-gp_pin;
 
@@ -936,7 +936,7 @@ gpio_ioctl_oapi(struct gpio_softc *sc, u
 		if ((flag  FWRITE) == 0)
 			return EBADF;
 
-		op = (struct gpio_pin_op *)data;
+		op = data;
 
 		pin = op-gp_pin;
 
@@ -960,7 +960,7 @@ gpio_ioctl_oapi(struct gpio_softc *sc, u
 		sc-sc_pins[pin].pin_state = value;
 		break;
 	case GPIOPINCTL:
-		ctl = (struct gpio_pin_ctl *) data;
+		ctl = data;
 
 		if (kauth_authorize_device(cred, KAUTH_DEVICE_GPIO_PINSET,
 		

CVS commit: src/sys/dev/gpio

2011-10-03 Thread Marc Balmer
Module Name:src
Committed By:   mbalmer
Date:   Mon Oct  3 11:28:28 UTC 2011

Modified Files:
src/sys/dev/gpio: gpio.c

Log Message:
Unbreak and move the list of child devices to COMPAT_50.


To generate a diff of this commit:
cvs rdiff -u -r1.44 -r1.45 src/sys/dev/gpio/gpio.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.44 src/sys/dev/gpio/gpio.c:1.45
--- src/sys/dev/gpio/gpio.c:1.44	Mon Oct  3 11:16:47 2011
+++ src/sys/dev/gpio/gpio.c	Mon Oct  3 11:28:28 2011
@@ -1,4 +1,4 @@
-/* $NetBSD: gpio.c,v 1.44 2011/10/03 11:16:47 mbalmer Exp $ */
+/* $NetBSD: gpio.c,v 1.45 2011/10/03 11:28:28 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.44 2011/10/03 11:16:47 mbalmer Exp $);
+__KERNEL_RCSID(0, $NetBSD: gpio.c,v 1.45 2011/10/03 11:28:28 mbalmer Exp $);
 
 /*
  * General Purpose Input/Output framework.
@@ -65,7 +65,9 @@ struct gpio_softc {
 	int			 sc_ioctl_busy;	/* ioctl is busy */
 	kcondvar_t		 sc_attach;	/* attach/detach in progress */
 	int			 sc_attach_busy;/* busy in attach/detach */
+#ifdef COMPAT_50
 	LIST_HEAD(, gpio_dev)	 sc_devs;	/* devices */
+#endif
 	LIST_HEAD(, gpio_name)	 sc_names;	/* named pins */
 };
 
@@ -138,6 +140,7 @@ gpio_resume(device_t self, const pmf_qua
 static void
 gpio_childdetached(device_t self, device_t child)
 {
+#ifdef COMPAT_50
 	struct gpio_dev *gdev;
 	struct gpio_softc *sc;
 	int error;
@@ -172,6 +175,7 @@ gpio_childdetached(device_t self, device
 	sc-sc_attach_busy = 0;
 	cv_signal(sc-sc_attach);
 	mutex_exit(sc-sc_mtx);
+#endif
 }
 
 static int
@@ -506,8 +510,8 @@ gpio_ioctl(struct gpio_softc *sc, u_long
 	struct gpio_info *info;
 	struct gpio_attach *attach;
 	struct gpio_attach_args ga;
-	struct gpio_dev *gdev;
 	struct gpio_req *req;
+	struct gpio_dev *gdev;
 	struct gpio_pulse *pulse;
 	struct gpio_name *nm;
 	struct gpio_set *set;
@@ -723,6 +727,7 @@ gpio_ioctl(struct gpio_softc *sc, u_long
 		if (cf != NULL) {
 			dv = config_attach_loc(sc-sc_dev, cf, locs, ga,
 			gpiobus_print);
+#ifdef COMPAT_50
 			if (dv != NULL) {
 gdev = kmem_alloc(sizeof(struct gpio_dev),
 KM_SLEEP);
@@ -730,6 +735,10 @@ gpio_ioctl(struct gpio_softc *sc, u_long
 LIST_INSERT_HEAD(sc-sc_devs, gdev, sc_next);
 			} else
 error = EINVAL;
+#else
+			if (dv == NULL)
+error = EINVAL;
+#endif
 		} else
 			error = EINVAL;
 		mutex_enter(sc-sc_mtx);
@@ -839,7 +848,10 @@ gpio_ioctl_oapi(struct gpio_softc *sc, u
 	gpio_chipset_tag_t gc;
 	struct gpio_pin_op *op;
 	struct gpio_pin_ctl *ctl;
-	int pin, value, flags;
+	struct gpio_attach *attach;
+	struct gpio_dev *gdev;
+
+	int error, pin, value, flags;
 
 	gc = sc-sc_gc;
 



CVS commit: src/sys/dev/gpio

2011-10-03 Thread Marc Balmer
Module Name:src
Committed By:   mbalmer
Date:   Mon Oct  3 11:31:56 UTC 2011

Modified Files:
src/sys/dev/gpio: gpio.c

Log Message:
Fix non-COMPAT_50 compilation.


To generate a diff of this commit:
cvs rdiff -u -r1.45 -r1.46 src/sys/dev/gpio/gpio.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.45 src/sys/dev/gpio/gpio.c:1.46
--- src/sys/dev/gpio/gpio.c:1.45	Mon Oct  3 11:28:28 2011
+++ src/sys/dev/gpio/gpio.c	Mon Oct  3 11:31:56 2011
@@ -1,4 +1,4 @@
-/* $NetBSD: gpio.c,v 1.45 2011/10/03 11:28:28 mbalmer Exp $ */
+/* $NetBSD: gpio.c,v 1.46 2011/10/03 11:31:56 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.45 2011/10/03 11:28:28 mbalmer Exp $);
+__KERNEL_RCSID(0, $NetBSD: gpio.c,v 1.46 2011/10/03 11:31:56 mbalmer Exp $);
 
 /*
  * General Purpose Input/Output framework.
@@ -511,11 +511,13 @@ gpio_ioctl(struct gpio_softc *sc, u_long
 	struct gpio_attach *attach;
 	struct gpio_attach_args ga;
 	struct gpio_req *req;
-	struct gpio_dev *gdev;
 	struct gpio_pulse *pulse;
 	struct gpio_name *nm;
 	struct gpio_set *set;
 	struct gpio_pin *gpin;
+#ifdef COMPAT_50
+	struct gpio_dev *gdev;
+#endif
 	device_t dv;
 	cfdata_t cf;
 	kauth_cred_t cred;



CVS commit: src/sys/dev/gpio

2011-10-02 Thread Marc Balmer
Module Name:src
Committed By:   mbalmer
Date:   Sun Oct  2 10:01:25 UTC 2011

Modified Files:
src/sys/dev/gpio: files.gpio

Log Message:
Add the flag locator (missed in the previous commit).


To generate a diff of this commit:
cvs rdiff -u -r1.8 -r1.9 src/sys/dev/gpio/files.gpio

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/files.gpio
diff -u src/sys/dev/gpio/files.gpio:1.8 src/sys/dev/gpio/files.gpio:1.9
--- src/sys/dev/gpio/files.gpio:1.8	Fri Aug 14 21:17:22 2009
+++ src/sys/dev/gpio/files.gpio	Sun Oct  2 10:01:25 2011
@@ -1,6 +1,6 @@
-# $NetBSD: files.gpio,v 1.8 2009/08/14 21:17:22 mbalmer Exp $
+# $NetBSD: files.gpio,v 1.9 2011/10/02 10:01:25 mbalmer Exp $
 
-define	gpio {[offset = -1], [mask = 0]}
+define	gpio {[offset = -1], [mask = 0], [flag = 0]}
 
 device	gpio: gpio
 attach	gpio at gpiobus



CVS commit: src/sys/dev/gpio

2011-09-07 Thread Marc Balmer
Module Name:src
Committed By:   mbalmer
Date:   Wed Sep  7 07:43:05 UTC 2011

Modified Files:
src/sys/dev/gpio: gpioow.c

Log Message:
Newline is \n, not /n.


To generate a diff of this commit:
cvs rdiff -u -r1.13 -r1.14 src/sys/dev/gpio/gpioow.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/gpioow.c
diff -u src/sys/dev/gpio/gpioow.c:1.13 src/sys/dev/gpio/gpioow.c:1.14
--- src/sys/dev/gpio/gpioow.c:1.13	Wed Aug 31 12:23:32 2011
+++ src/sys/dev/gpio/gpioow.c	Wed Sep  7 07:43:05 2011
@@ -1,4 +1,4 @@
-/* $NetBSD: gpioow.c,v 1.13 2011/08/31 12:23:32 mbalmer Exp $ */
+/* $NetBSD: gpioow.c,v 1.14 2011/09/07 07:43:05 mbalmer Exp $ */
 /*	$OpenBSD: gpioow.c,v 1.1 2006/03/04 16:27:03 grange Exp $	*/
 
 /*
@@ -18,7 +18,7 @@
  */
 
 #include sys/cdefs.h
-__KERNEL_RCSID(0, $NetBSD: gpioow.c,v 1.13 2011/08/31 12:23:32 mbalmer Exp $);
+__KERNEL_RCSID(0, $NetBSD: gpioow.c,v 1.14 2011/09/07 07:43:05 mbalmer Exp $);
 
 /*
  * 1-Wire bus bit-banging through GPIO pin.
@@ -87,7 +87,7 @@
 
 	/* Check that we have enough pins */
 	if (gpio_npins(ga-ga_mask) != GPIOOW_NPINS) {
-		aprint_debug(%s: invalid pin mask 0x%02x/n, cf-cf_name,
+		aprint_debug(%s: invalid pin mask 0x%02x\n, cf-cf_name,
 		ga-ga_mask);
 		return 0;
 	}



CVS commit: src/sys/dev/gpio

2011-09-02 Thread Marc Balmer
Module Name:src
Committed By:   mbalmer
Date:   Fri Sep  2 06:50:21 UTC 2011

Modified Files:
src/sys/dev/gpio: gpio.c

Log Message:
Make sure error is not used unitialized when sc-sc_attach_busy is 0.


To generate a diff of this commit:
cvs rdiff -u -r1.40 -r1.41 src/sys/dev/gpio/gpio.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.40 src/sys/dev/gpio/gpio.c:1.41
--- src/sys/dev/gpio/gpio.c:1.40	Wed Aug 31 12:20:35 2011
+++ src/sys/dev/gpio/gpio.c	Fri Sep  2 06:50:20 2011
@@ -1,4 +1,4 @@
-/* $NetBSD: gpio.c,v 1.40 2011/08/31 12:20:35 mbalmer Exp $ */
+/* $NetBSD: gpio.c,v 1.41 2011/09/02 06:50:20 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.40 2011/08/31 12:20:35 mbalmer Exp $);
+__KERNEL_RCSID(0, $NetBSD: gpio.c,v 1.41 2011/09/02 06:50:20 mbalmer Exp $);
 
 /*
  * General Purpose Input/Output framework.
@@ -724,6 +724,7 @@
 		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);



CVS commit: src/sys/dev/gpio

2011-08-31 Thread Marc Balmer
Module Name:src
Committed By:   mbalmer
Date:   Wed Aug 31 12:07:26 UTC 2011

Modified Files:
src/sys/dev/gpio: gpio.c

Log Message:
gpio(4) keeps track of child devices attached using the GPIOATTACH ioctl(),
so remove those references and free the memory in gpio_childdetached().
Protect access to the list of child devices with a kcondvar.


To generate a diff of this commit:
cvs rdiff -u -r1.38 -r1.39 src/sys/dev/gpio/gpio.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.38 src/sys/dev/gpio/gpio.c:1.39
--- src/sys/dev/gpio/gpio.c:1.38	Tue Aug 30 07:22:11 2011
+++ src/sys/dev/gpio/gpio.c	Wed Aug 31 12:07:26 2011
@@ -1,4 +1,4 @@
-/* $NetBSD: gpio.c,v 1.38 2011/08/30 07:22:11 mbalmer Exp $ */
+/* $NetBSD: gpio.c,v 1.39 2011/08/31 12:07:26 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.38 2011/08/30 07:22:11 mbalmer Exp $);
+__KERNEL_RCSID(0, $NetBSD: gpio.c,v 1.39 2011/08/31 12:07:26 mbalmer Exp $);
 
 /*
  * General Purpose Input/Output framework.
@@ -63,6 +63,8 @@
 	kmutex_t		 sc_mtx;
 	kcondvar_t		 sc_ioctl;	/* ioctl in progress */
 	int			 sc_ioctl_busy;	/* ioctl is busy */
+	kcondvar_t		 sc_attach;	/* attach/detach in progress */
+	int			 sc_attach_busy;/* busy in attach/detach */
 	LIST_HEAD(, gpio_dev)	 sc_devs;	/* devices */
 	LIST_HEAD(, gpio_name)	 sc_names;	/* named pins */
 };
@@ -134,7 +136,40 @@
 static void
 gpio_childdetached(device_t self, device_t child)
 {
-	/* gpio(4) keeps no references to its children, so do nothing. */
+	struct gpio_dev *gdev;
+	struct gpio_softc *sc;
+	int error;
+
+	/*
+	 * gpio_childetached is serialized because it can be entered in
+	 * different ways concurrently, e.g. via the GPIODETACH ioctl and
+	 * drvctl(8) or modunload(8).
+	 */
+	sc = device_private(self);
+	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;
+
+	LIST_FOREACH(gdev, sc-sc_devs, sc_next)
+		if (gdev-sc_dev == child) {
+			LIST_REMOVE(gdev, sc_next);
+			kmem_free(gdev, sizeof(struct gpio_dev));
+			break;
+		}
+
+	mutex_enter(sc-sc_mtx);
+	sc-sc_attach_busy = 0;
+	cv_signal(sc-sc_attach);
+	mutex_exit(sc-sc_mtx);
 }
 
 static int
@@ -169,7 +204,7 @@
 		aprint_error_dev(self, couldn't establish power handler\n);
 	mutex_init(sc-sc_mtx, MUTEX_DEFAULT, IPL_VM);
 	cv_init(sc-sc_ioctl, gpioctl);
-
+	cv_init(sc-sc_attach, gpioatch);
 	/*
 	 * Attach all devices that can be connected to the GPIO pins
 	 * described in the kernel configuration file.
@@ -478,7 +513,7 @@
 	cfdata_t cf;
 	kauth_cred_t cred;
 	int locs[GPIOCF_NLOCS];
-	int pin, value, flags, npins;
+	int error, pin, value, flags, npins;
 
 	gc = sc-sc_gc;
 
@@ -642,6 +677,19 @@
 		if (!gpio_pin_can_map(sc, attach-ga_offset, attach-ga_mask))
 			return EBUSY;
 
+		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;
+
 		ga.ga_gpio = sc;
 		ga.ga_dvname = attach-ga_dvname;
 		ga.ga_offset = attach-ga_offset;
@@ -664,28 +712,51 @@
 gdev-sc_dev = dv;
 LIST_INSERT_HEAD(sc-sc_devs, gdev, sc_next);
 			} else
-return EINVAL;
+error = EINVAL;
 		} else
-			return EINVAL;
-		return 0;
+			error = EINVAL;
+		mutex_enter(sc-sc_mtx);
+		sc-sc_attach_busy = 0;
+		cv_signal(sc-sc_attach);
+		mutex_exit(sc-sc_mtx);
+		return error;
 	case GPIODETACH:
 		if (kauth_authorize_device(cred, KAUTH_DEVICE_GPIO_PINSET,
 		NULL, NULL, NULL, NULL))
 			return EPERM;
 
+		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 = (struct gpio_attach *)data;
 		LIST_FOREACH(gdev, sc-sc_devs, sc_next) {
 			if (strcmp(device_xname(gdev-sc_dev),
 			attach-ga_dvname) == 0) {
-if (config_detach(gdev-sc_dev, 0) == 0) {
-	LIST_REMOVE(gdev, sc_next);
-	kmem_free(gdev,
-	sizeof(struct gpio_dev));
+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,



CVS commit: src/sys/dev/gpio

2011-08-31 Thread Marc Balmer
Module Name:src
Committed By:   mbalmer
Date:   Wed Aug 31 12:20:35 UTC 2011

Modified Files:
src/sys/dev/gpio: gpio.c gpiovar.h

Log Message:
Remove what I committed accidentally...


To generate a diff of this commit:
cvs rdiff -u -r1.39 -r1.40 src/sys/dev/gpio/gpio.c
cvs rdiff -u -r1.12 -r1.13 src/sys/dev/gpio/gpiovar.h

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.39 src/sys/dev/gpio/gpio.c:1.40
--- src/sys/dev/gpio/gpio.c:1.39	Wed Aug 31 12:07:26 2011
+++ src/sys/dev/gpio/gpio.c	Wed Aug 31 12:20:35 2011
@@ -1,4 +1,4 @@
-/* $NetBSD: gpio.c,v 1.39 2011/08/31 12:07:26 mbalmer Exp $ */
+/* $NetBSD: gpio.c,v 1.40 2011/08/31 12:20:35 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.39 2011/08/31 12:07:26 mbalmer Exp $);
+__KERNEL_RCSID(0, $NetBSD: gpio.c,v 1.40 2011/08/31 12:20:35 mbalmer Exp $);
 
 /*
  * General Purpose Input/Output framework.
@@ -694,7 +694,6 @@
 		ga.ga_dvname = attach-ga_dvname;
 		ga.ga_offset = attach-ga_offset;
 		ga.ga_mask = attach-ga_mask;
-		ga.ga_nolock = 1;
 		DPRINTF((%s: attach %s with offset %d and mask 
 		0x%02x\n, device_xname(sc-sc_dev), ga.ga_dvname,
 		ga.ga_offset, ga.ga_mask));

Index: src/sys/dev/gpio/gpiovar.h
diff -u src/sys/dev/gpio/gpiovar.h:1.12 src/sys/dev/gpio/gpiovar.h:1.13
--- src/sys/dev/gpio/gpiovar.h:1.12	Sun Aug 28 07:48:50 2011
+++ src/sys/dev/gpio/gpiovar.h	Wed Aug 31 12:20:35 2011
@@ -1,4 +1,4 @@
-/* $NetBSD: gpiovar.h,v 1.12 2011/08/28 07:48:50 mbalmer Exp $ */
+/* $NetBSD: gpiovar.h,v 1.13 2011/08/31 12:20:35 mbalmer Exp $ */
 /*	$OpenBSD: gpiovar.h,v 1.3 2006/01/14 12:33:49 grange Exp $	*/
 
 /*
@@ -73,7 +73,6 @@
 	int		 ga_offset;
 	uint32_t	 ga_mask;
 	char		*ga_dvname;
-	int		 ga_nolock;
 };
 
 /* GPIO pin map */



CVS commit: src/sys/dev/gpio

2011-08-31 Thread Marc Balmer
Module Name:src
Committed By:   mbalmer
Date:   Wed Aug 31 12:23:32 UTC 2011

Modified Files:
src/sys/dev/gpio: gpioow.c

Log Message:
Add glue code to build as module.


To generate a diff of this commit:
cvs rdiff -u -r1.12 -r1.13 src/sys/dev/gpio/gpioow.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/gpioow.c
diff -u src/sys/dev/gpio/gpioow.c:1.12 src/sys/dev/gpio/gpioow.c:1.13
--- src/sys/dev/gpio/gpioow.c:1.12	Thu Nov 12 19:22:08 2009
+++ src/sys/dev/gpio/gpioow.c	Wed Aug 31 12:23:32 2011
@@ -1,4 +1,4 @@
-/* $NetBSD: gpioow.c,v 1.12 2009/11/12 19:22:08 dyoung Exp $ */
+/* $NetBSD: gpioow.c,v 1.13 2011/08/31 12:23:32 mbalmer Exp $ */
 /*	$OpenBSD: gpioow.c,v 1.1 2006/03/04 16:27:03 grange Exp $	*/
 
 /*
@@ -18,7 +18,7 @@
  */
 
 #include sys/cdefs.h
-__KERNEL_RCSID(0, $NetBSD: gpioow.c,v 1.12 2009/11/12 19:22:08 dyoung Exp $);
+__KERNEL_RCSID(0, $NetBSD: gpioow.c,v 1.13 2011/08/31 12:23:32 mbalmer Exp $);
 
 /*
  * 1-Wire bus bit-banging through GPIO pin.
@@ -28,6 +28,7 @@
 #include sys/systm.h
 #include sys/device.h
 #include sys/gpio.h
+#include sys/module.h
 
 #include dev/gpio/gpiovar.h
 
@@ -107,18 +108,20 @@
 	if (gpio_pin_map(sc-sc_gpio, ga-ga_offset, ga-ga_mask,
 	sc-sc_map)) {
 		aprint_error(: can't map pins\n);
-		return;
+		goto finish;
 	}
 
 	/* Configure data pin */
 	caps = gpio_pin_caps(sc-sc_gpio, sc-sc_map, GPIOOW_PIN_DATA);
 	if (!(caps  GPIO_PIN_OUTPUT)) {
 		aprint_error(: data pin is unable to drive output\n);
-		goto fail;
+		gpio_pin_unmap(sc-sc_gpio, sc-sc_map);
+		goto finish;
 	}
 	if (!(caps  GPIO_PIN_INPUT)) {
 		aprint_error(: data pin is unable to read input\n);
-		goto fail;
+		gpio_pin_unmap(sc-sc_gpio, sc-sc_map);
+		goto finish;
 	}
 	aprint_normal(: DATA[%d], sc-sc_map.pm_map[GPIOOW_PIN_DATA]);
 	sc-sc_data = GPIO_PIN_OUTPUT;
@@ -149,10 +152,8 @@
 	if (!pmf_device_register(self, NULL, NULL))
 		aprint_error(%s: could not establish power handler\n,
 		device_xname(self));
+finish:
 	return;
-
-fail:
-	gpio_pin_unmap(sc-sc_gpio, sc-sc_map);
 }
 
 int
@@ -246,3 +247,37 @@
 	gpio_pin_write(sc-sc_gpio, sc-sc_map, GPIOOW_PIN_DATA,
 	value ? GPIO_PIN_HIGH : GPIO_PIN_LOW);
 }
+
+MODULE(MODULE_CLASS_DRIVER, gpioow, gpio,onewire);
+
+#ifdef _MODULE
+#include ioconf.c
+#endif
+
+static int
+gpioow_modcmd(modcmd_t cmd, void *opaque)
+{
+	int error;
+
+	error = 0;
+	switch (cmd) {
+	case MODULE_CMD_INIT:
+#ifdef _MODULE
+		error = config_init_component(cfdriver_ioconf_gpioow,
+		cfattach_ioconf_gpioow, cfdata_ioconf_gpioow);
+		if (error)
+			aprint_error(%s: unable to init component\n,
+			gpioow_cd.cd_name);
+#endif
+		break;
+	case MODULE_CMD_FINI:
+#ifdef _MODULE
+		config_fini_component(cfdriver_ioconf_gpioow,
+		cfattach_ioconf_gpioow, cfdata_ioconf_gpioow);
+#endif
+		break;
+	default:
+		error = ENOTTY;
+	}
+	return error;
+}



CVS commit: src/sys/dev/gpio

2011-08-31 Thread Marc Balmer
Module Name:src
Committed By:   mbalmer
Date:   Wed Aug 31 12:25:05 UTC 2011

Modified Files:
src/sys/dev/gpio: gpioiic.c

Log Message:
Switch von u_int_XY to uintXY


To generate a diff of this commit:
cvs rdiff -u -r1.3 -r1.4 src/sys/dev/gpio/gpioiic.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/gpioiic.c
diff -u src/sys/dev/gpio/gpioiic.c:1.3 src/sys/dev/gpio/gpioiic.c:1.4
--- src/sys/dev/gpio/gpioiic.c:1.3	Sat Jul 23 09:03:38 2011
+++ src/sys/dev/gpio/gpioiic.c	Wed Aug 31 12:25:05 2011
@@ -1,4 +1,4 @@
-/* $NetBSD: gpioiic.c,v 1.3 2011/07/23 09:03:38 mbalmer Exp $ */
+/* $NetBSD: gpioiic.c,v 1.4 2011/08/31 12:25:05 mbalmer Exp $ */
 /*	$OpenBSD: gpioiic.c,v 1.8 2008/11/24 12:12:12 mbalmer Exp $	*/
 
 /*
@@ -18,7 +18,7 @@
  */
 
 #include sys/cdefs.h
-__KERNEL_RCSID(0, $NetBSD: gpioiic.c,v 1.3 2011/07/23 09:03:38 mbalmer Exp $);
+__KERNEL_RCSID(0, $NetBSD: gpioiic.c,v 1.4 2011/08/31 12:25:05 mbalmer Exp $);
 
 /*
  * I2C bus bit-banging through GPIO pins.
@@ -64,12 +64,12 @@
 int		gpioiic_i2c_send_start(void *, int);
 int		gpioiic_i2c_send_stop(void *, int);
 int		gpioiic_i2c_initiate_xfer(void *, i2c_addr_t, int);
-int		gpioiic_i2c_read_byte(void *, u_int8_t *, int);
-int		gpioiic_i2c_write_byte(void *, u_int8_t, int);
+int		gpioiic_i2c_read_byte(void *, uint8_t *, int);
+int		gpioiic_i2c_write_byte(void *, uint8_t, int);
 
-void		gpioiic_bb_set_bits(void *, u_int32_t);
-void		gpioiic_bb_set_dir(void *, u_int32_t);
-u_int32_t	gpioiic_bb_read_bits(void *);
+void		gpioiic_bb_set_bits(void *, uint32_t);
+void		gpioiic_bb_set_dir(void *, uint32_t);
+uint32_t	gpioiic_bb_read_bits(void *);
 
 CFATTACH_DECL_NEW(gpioiic, sizeof(struct gpioiic_softc),
 	gpioiic_match, gpioiic_attach, gpioiic_detach, NULL);
@@ -252,19 +252,19 @@
 }
 
 int
-gpioiic_i2c_read_byte(void *cookie, u_int8_t *bytep, int flags)
+gpioiic_i2c_read_byte(void *cookie, uint8_t *bytep, int flags)
 {
 	return i2c_bitbang_read_byte(cookie, bytep, flags, gpioiic_bbops);
 }
 
 int
-gpioiic_i2c_write_byte(void *cookie, u_int8_t byte, int flags)
+gpioiic_i2c_write_byte(void *cookie, uint8_t byte, int flags)
 {
 	return i2c_bitbang_write_byte(cookie, byte, flags, gpioiic_bbops);
 }
 
 void
-gpioiic_bb_set_bits(void *cookie, u_int32_t bits)
+gpioiic_bb_set_bits(void *cookie, uint32_t bits)
 {
 	struct gpioiic_softc *sc = cookie;
 
@@ -275,7 +275,7 @@
 }
 
 void
-gpioiic_bb_set_dir(void *cookie, u_int32_t bits)
+gpioiic_bb_set_dir(void *cookie, uint32_t bits)
 {
 	struct gpioiic_softc *sc = cookie;
 	int sda = sc-sc_sda;
@@ -291,11 +291,11 @@
 	}
 }
 
-u_int32_t
+uint32_t
 gpioiic_bb_read_bits(void *cookie)
 {
 	struct gpioiic_softc *sc = cookie;
-	u_int32_t bits = 0;
+	uint32_t bits = 0;
 
 	if (gpio_pin_read(sc-sc_gpio, sc-sc_map,
 	GPIOIIC_PIN_SDA) == GPIO_PIN_HIGH)



CVS commit: src/sys/dev/gpio

2011-08-29 Thread Marc Balmer
Module Name:src
Committed By:   mbalmer
Date:   Mon Aug 29 15:14:04 UTC 2011

Modified Files:
src/sys/dev/gpio: gpio.c gpiosim.c

Log Message:
Register as built-in module when compiled wo/ _MODULE.


To generate a diff of this commit:
cvs rdiff -u -r1.36 -r1.37 src/sys/dev/gpio/gpio.c
cvs rdiff -u -r1.11 -r1.12 src/sys/dev/gpio/gpiosim.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.36 src/sys/dev/gpio/gpio.c:1.37
--- src/sys/dev/gpio/gpio.c:1.36	Sun Aug 28 07:48:50 2011
+++ src/sys/dev/gpio/gpio.c	Mon Aug 29 15:14:04 2011
@@ -1,4 +1,4 @@
-/* $NetBSD: gpio.c,v 1.36 2011/08/28 07:48:50 mbalmer Exp $ */
+/* $NetBSD: gpio.c,v 1.37 2011/08/29 15:14:04 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.36 2011/08/28 07:48:50 mbalmer Exp $);
+__KERNEL_RCSID(0, $NetBSD: gpio.c,v 1.37 2011/08/29 15:14:04 mbalmer Exp $);
 
 /*
  * General Purpose Input/Output framework.
@@ -897,19 +897,22 @@
 	return 0;
 }
 
-#ifdef _MODULE
 MODULE(MODULE_CLASS_DRIVER, gpio, NULL);
 
+#ifdef _MODULE
 #include ioconf.c
+#endif
 
 static int
 gpio_modcmd(modcmd_t cmd, void *opaque)
 {
+#ifdef _MODULE
 	devmajor_t cmajor = NODEVMAJOR, bmajor = NODEVMAJOR;
 	int error;
-
+#endif
 	switch (cmd) {
 	case MODULE_CMD_INIT:
+#ifdef _MODULE
 		error = config_init_component(cfdriver_ioconf_gpio,
 		cfattach_ioconf_gpio, cfdata_ioconf_gpio);
 		if (error) {
@@ -925,14 +928,16 @@
 			return config_fini_component(cfdriver_ioconf_gpio,
 			cfattach_ioconf_gpio, cfdata_ioconf_gpio);
 		}
+#endif
 		return 0;
 	case MODULE_CMD_FINI:
+#ifdef _MODULE
 		config_fini_component(cfdriver_ioconf_gpio,
 		cfattach_ioconf_gpio, cfdata_ioconf_gpio);
 		devsw_detach(NULL, gpio_cdevsw);
+#endif
 		return 0;
 	default:
 		return ENOTTY;
 	}
 }
-#endif

Index: src/sys/dev/gpio/gpiosim.c
diff -u src/sys/dev/gpio/gpiosim.c:1.11 src/sys/dev/gpio/gpiosim.c:1.12
--- src/sys/dev/gpio/gpiosim.c:1.11	Sun Aug 28 11:36:17 2011
+++ src/sys/dev/gpio/gpiosim.c	Mon Aug 29 15:14:04 2011
@@ -1,4 +1,4 @@
-/* $NetBSD: gpiosim.c,v 1.11 2011/08/28 11:36:17 jmcneill Exp $ */
+/* $NetBSD: gpiosim.c,v 1.12 2011/08/29 15:14:04 mbalmer Exp $ */
 /*  $OpenBSD: gpiosim.c,v 1.1 2008/11/23 18:46:49 mbalmer Exp $	*/
 
 /*
@@ -219,9 +219,9 @@
 	sc-sc_gpio_pins[pin].pin_flags = flags;
 }
 
-#ifdef _MODULE
 MODULE(MODULE_CLASS_DRIVER, gpiosim, gpio);
 
+#ifdef _MODULE
 static const struct cfiattrdata gpiobus_iattrdata = {
 	gpiobus, 0, { { NULL, NULL, 0 },}
 };
@@ -247,14 +247,17 @@
 	},
 	{ NULL, NULL, 0, FSTATE_NOTFOUND, NULL, 0, NULL }
 };
+#endif
 
 static int
 gpiosim_modcmd(modcmd_t cmd, void *opaque)
 {
+#ifdef _MODULE
 	int error = 0;
-
+#endif
 	switch (cmd) {
 	case MODULE_CMD_INIT:
+#ifdef _MODULE
 		error = config_cfdriver_attach(gpiosim_cd);
 		if (error)
 			return error;
@@ -276,15 +279,18 @@
 			gpiosim_cd.cd_name);
 			return error;
 		}
-		(void)config_attach_pseudo(gpiosim_cfdata);
+		config_attach_pseudo(gpiosim_cfdata);
+#endif
 		return 0;
 	case MODULE_CMD_FINI:
+#ifdef _MODULE
 		error = config_cfdata_detach(gpiosim_cfdata);
 		if (error)
 			return error;
 
 		config_cfattach_detach(gpiosim_cd.cd_name, gpiosim_ca);
 		config_cfdriver_detach(gpiosim_cd);
+#endif
 		return 0;
 	case MODULE_CMD_AUTOUNLOAD:
 		/* no auto-unload */
@@ -293,4 +299,3 @@
 		return ENOTTY;
 	}
 }
-#endif



CVS commit: src/sys/dev/gpio

2011-08-28 Thread Jared D. McNeill
Module Name:src
Committed By:   jmcneill
Date:   Sun Aug 28 11:36:17 UTC 2011

Modified Files:
src/sys/dev/gpio: gpiosim.c

Log Message:
build with WARNS=3


To generate a diff of this commit:
cvs rdiff -u -r1.10 -r1.11 src/sys/dev/gpio/gpiosim.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/gpiosim.c
diff -u src/sys/dev/gpio/gpiosim.c:1.10 src/sys/dev/gpio/gpiosim.c:1.11
--- src/sys/dev/gpio/gpiosim.c:1.10	Fri Aug 26 15:00:07 2011
+++ src/sys/dev/gpio/gpiosim.c	Sun Aug 28 11:36:17 2011
@@ -1,4 +1,4 @@
-/* $NetBSD: gpiosim.c,v 1.10 2011/08/26 15:00:07 mbalmer Exp $ */
+/* $NetBSD: gpiosim.c,v 1.11 2011/08/28 11:36:17 jmcneill Exp $ */
 /*  $OpenBSD: gpiosim.c,v 1.1 2008/11/23 18:46:49 mbalmer Exp $	*/
 
 /*
@@ -245,7 +245,7 @@
 		.cf_flags = 0,
 		.cf_pspec = NULL,
 	},
-	{ NULL }
+	{ NULL, NULL, 0, FSTATE_NOTFOUND, NULL, 0, NULL }
 };
 
 static int



CVS commit: src/sys/dev/gpio

2011-08-26 Thread Marc Balmer
Module Name:src
Committed By:   mbalmer
Date:   Fri Aug 26 15:00:07 UTC 2011

Modified Files:
src/sys/dev/gpio: gpiosim.c

Log Message:
u_int32_t - uin32_t.


To generate a diff of this commit:
cvs rdiff -u -r1.9 -r1.10 src/sys/dev/gpio/gpiosim.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/gpiosim.c
diff -u src/sys/dev/gpio/gpiosim.c:1.9 src/sys/dev/gpio/gpiosim.c:1.10
--- src/sys/dev/gpio/gpiosim.c:1.9	Sun Aug 14 18:49:17 2011
+++ src/sys/dev/gpio/gpiosim.c	Fri Aug 26 15:00:07 2011
@@ -1,4 +1,4 @@
-/* $NetBSD: gpiosim.c,v 1.9 2011/08/14 18:49:17 mbalmer Exp $ */
+/* $NetBSD: gpiosim.c,v 1.10 2011/08/26 15:00:07 mbalmer Exp $ */
 /*  $OpenBSD: gpiosim.c,v 1.1 2008/11/23 18:46:49 mbalmer Exp $	*/
 
 /*
@@ -19,6 +19,7 @@
  */
 
 /* 32 bit wide GPIO simulator  */
+
 #include sys/param.h
 #include sys/systm.h
 #include sys/device.h
@@ -36,7 +37,7 @@
 struct gpiosim_softc {
 	device_t		sc_dev;
 	device_t		sc_gdev;	/* gpio that attaches here */
-	u_int32_t		sc_state;
+	uint32_t		sc_state;
 	struct gpio_chipset_tag	sc_gpio_gc;
 	gpio_pin_t		sc_gpio_pins[GPIOSIM_NPINS];
 



CVS commit: src/sys/dev/gpio

2011-08-14 Thread Marc Balmer
Module Name:src
Committed By:   mbalmer
Date:   Sun Aug 14 18:49:18 UTC 2011

Modified Files:
src/sys/dev/gpio: gpiosim.c

Log Message:
fix indents


To generate a diff of this commit:
cvs rdiff -u -r1.8 -r1.9 src/sys/dev/gpio/gpiosim.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/gpiosim.c
diff -u src/sys/dev/gpio/gpiosim.c:1.8 src/sys/dev/gpio/gpiosim.c:1.9
--- src/sys/dev/gpio/gpiosim.c:1.8	Fri Aug 12 08:00:52 2011
+++ src/sys/dev/gpio/gpiosim.c	Sun Aug 14 18:49:17 2011
@@ -1,4 +1,4 @@
-/* $NetBSD: gpiosim.c,v 1.8 2011/08/12 08:00:52 mbalmer Exp $ */
+/* $NetBSD: gpiosim.c,v 1.9 2011/08/14 18:49:17 mbalmer Exp $ */
 /*  $OpenBSD: gpiosim.c,v 1.1 2008/11/23 18:46:49 mbalmer Exp $	*/
 
 /*
@@ -263,17 +263,16 @@
 		if (error) {
 			config_cfdriver_detach(gpiosim_cd);
 			aprint_error(%s: unable to register cfattach\n,
-gpiosim_cd.cd_name);
+			gpiosim_cd.cd_name);
 			return error;
 		}
-
 		error = config_cfdata_attach(gpiosim_cfdata, 1);
 		if (error) {
 			config_cfattach_detach(gpiosim_cd.cd_name,
 			gpiosim_ca);
 			config_cfdriver_detach(gpiosim_cd);
 			aprint_error(%s: unable to register cfdata\n,
-gpiosim_cd.cd_name);
+			gpiosim_cd.cd_name);
 			return error;
 		}
 		(void)config_attach_pseudo(gpiosim_cfdata);



CVS commit: src/sys/dev/gpio

2011-07-23 Thread Marc Balmer
Module Name:src
Committed By:   mbalmer
Date:   Sat Jul 23 09:03:38 UTC 2011

Modified Files:
src/sys/dev/gpio: gpioiic.c

Log Message:
When reading the bits from the I2C bus, also report SCL.  Fixes PR43275.
Fix originally from Maxim Weber, thanks.


To generate a diff of this commit:
cvs rdiff -u -r1.2 -r1.3 src/sys/dev/gpio/gpioiic.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/gpioiic.c
diff -u src/sys/dev/gpio/gpioiic.c:1.2 src/sys/dev/gpio/gpioiic.c:1.3
--- src/sys/dev/gpio/gpioiic.c:1.2	Sun Dec  6 22:33:44 2009
+++ src/sys/dev/gpio/gpioiic.c	Sat Jul 23 09:03:38 2011
@@ -1,4 +1,4 @@
-/* $NetBSD: gpioiic.c,v 1.2 2009/12/06 22:33:44 dyoung Exp $ */
+/* $NetBSD: gpioiic.c,v 1.3 2011/07/23 09:03:38 mbalmer Exp $ */
 /*	$OpenBSD: gpioiic.c,v 1.8 2008/11/24 12:12:12 mbalmer Exp $	*/
 
 /*
@@ -18,7 +18,7 @@
  */
 
 #include sys/cdefs.h
-__KERNEL_RCSID(0, $NetBSD: gpioiic.c,v 1.2 2009/12/06 22:33:44 dyoung Exp $);
+__KERNEL_RCSID(0, $NetBSD: gpioiic.c,v 1.3 2011/07/23 09:03:38 mbalmer Exp $);
 
 /*
  * I2C bus bit-banging through GPIO pins.
@@ -295,7 +295,14 @@
 gpioiic_bb_read_bits(void *cookie)
 {
 	struct gpioiic_softc *sc = cookie;
+	u_int32_t bits = 0;
 
-	return gpio_pin_read(sc-sc_gpio, sc-sc_map,
-	GPIOIIC_PIN_SDA) == GPIO_PIN_HIGH ? GPIOIIC_SDA : 0;
+	if (gpio_pin_read(sc-sc_gpio, sc-sc_map,
+	GPIOIIC_PIN_SDA) == GPIO_PIN_HIGH)
+		bits |= GPIOIIC_SDA;
+	if (gpio_pin_read(sc-sc_gpio, sc-sc_map,
+	GPIOIIC_PIN_SCL) == GPIO_PIN_HIGH)
+		bits |= GPIOIIC_SCL;
+
+	return bits;
 }



CVS commit: src/sys/dev/gpio

2011-06-09 Thread Joerg Sonnenberger
Module Name:src
Committed By:   joerg
Date:   Thu Jun  9 14:46:06 UTC 2011

Modified Files:
src/sys/dev/gpio: gpio.c

Log Message:
Annotate that gpiobus_close's return value is undesired here


To generate a diff of this commit:
cvs rdiff -u -r1.33 -r1.34 src/sys/dev/gpio/gpio.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.33 src/sys/dev/gpio/gpio.c:1.34
--- src/sys/dev/gpio/gpio.c:1.33	Sun Apr 25 11:23:34 2010
+++ src/sys/dev/gpio/gpio.c	Thu Jun  9 14:46:06 2011
@@ -1,4 +1,4 @@
-/* $NetBSD: gpio.c,v 1.33 2010/04/25 11:23:34 ad Exp $ */
+/* $NetBSD: gpio.c,v 1.34 2011/06/09 14:46:06 joerg 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.33 2010/04/25 11:23:34 ad Exp $);
+__KERNEL_RCSID(0, $NetBSD: gpio.c,v 1.34 2011/06/09 14:46:06 joerg Exp $);
 
 /*
  * General Purpose Input/Output framework.
@@ -362,7 +362,7 @@
 
 	sc = device_lookup_private(gpio_cd, minor(dev));
 	DPRINTF((%s: closing\n, device_xname(sc-sc_dev)));
-	gpiobus_close(sc-sc_gc, sc-sc_dev);
+	(void)gpiobus_close(sc-sc_gc, sc-sc_dev);
 	sc-sc_opened = 0;
 
 	return 0;



CVS commit: src/sys/dev/gpio

2010-04-25 Thread Andrew Doran
Module Name:src
Committed By:   ad
Date:   Sun Apr 25 11:23:34 UTC 2010

Modified Files:
src/sys/dev/gpio: gpio.c

Log Message:
console spam


To generate a diff of this commit:
cvs rdiff -u -r1.32 -r1.33 src/sys/dev/gpio/gpio.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.32 src/sys/dev/gpio/gpio.c:1.33
--- src/sys/dev/gpio/gpio.c:1.32	Wed Feb 24 22:37:57 2010
+++ src/sys/dev/gpio/gpio.c	Sun Apr 25 11:23:34 2010
@@ -1,4 +1,4 @@
-/* $NetBSD: gpio.c,v 1.32 2010/02/24 22:37:57 dyoung Exp $ */
+/* $NetBSD: gpio.c,v 1.33 2010/04/25 11:23:34 ad 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.32 2010/02/24 22:37:57 dyoung Exp $);
+__KERNEL_RCSID(0, $NetBSD: gpio.c,v 1.33 2010/04/25 11:23:34 ad Exp $);
 
 /*
  * General Purpose Input/Output framework.
@@ -218,7 +218,7 @@
 	struct gpiobus_attach_args *gba = aux;
 #endif
 	if (pnp != NULL)
-		printf(gpiobus at %s, pnp);
+		aprint_normal(gpiobus at %s, pnp);
 
 	return UNCONF;
 }



CVS commit: src/sys/dev/gpio

2010-01-24 Thread Marc Balmer
Module Name:src
Committed By:   mbalmer
Date:   Sun Jan 24 12:25:20 UTC 2010

Modified Files:
src/sys/dev/gpio: gpio.c

Log Message:
Unfold, bump copyright.


To generate a diff of this commit:
cvs rdiff -u -r1.30 -r1.31 src/sys/dev/gpio/gpio.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.30 src/sys/dev/gpio/gpio.c:1.31
--- src/sys/dev/gpio/gpio.c:1.30	Fri Jan  8 19:48:18 2010
+++ src/sys/dev/gpio/gpio.c	Sun Jan 24 12:25:20 2010
@@ -1,8 +1,8 @@
-/* $NetBSD: gpio.c,v 1.30 2010/01/08 19:48:18 dyoung Exp $ */
+/* $NetBSD: gpio.c,v 1.31 2010/01/24 12:25:20 mbalmer Exp $ */
 /*	$OpenBSD: gpio.c,v 1.6 2006/01/14 12:33:49 grange Exp $	*/
 
 /*
- * Copyright (c) 2008, 2009 Marc Balmer m...@msys.ch
+ * Copyright (c) 2008, 2009, 2010 Marc Balmer m...@msys.ch
  * Copyright (c) 2004, 2006 Alexander Yurchenko gra...@openbsd.org
  *
  * Permission to use, copy, modify, and distribute this software for any
@@ -19,7 +19,7 @@
  */
 
 #include sys/cdefs.h
-__KERNEL_RCSID(0, $NetBSD: gpio.c,v 1.30 2010/01/08 19:48:18 dyoung Exp $);
+__KERNEL_RCSID(0, $NetBSD: gpio.c,v 1.31 2010/01/24 12:25:20 mbalmer Exp $);
 
 /*
  * General Purpose Input/Output framework.
@@ -183,8 +183,7 @@
 }
 
 int
-gpio_search(device_t parent, cfdata_t cf,
-const int *ldesc, void *aux)
+gpio_search(device_t parent, cfdata_t cf, const int *ldesc, void *aux)
 {
 	struct gpio_attach_args ga;
 
@@ -225,7 +224,6 @@
 }
 
 /* return 1 if all pins can be mapped, 0 if not */
-
 int
 gpio_pin_can_map(void *gpio, int offset, u_int32_t mask)
 {



CVS commit: src/sys/dev/gpio

2010-01-08 Thread David Young
Module Name:src
Committed By:   dyoung
Date:   Fri Jan  8 19:48:18 UTC 2010

Modified Files:
src/sys/dev/gpio: gpio.c

Log Message:
Expand PMF_FN_* macros.


To generate a diff of this commit:
cvs rdiff -u -r1.29 -r1.30 src/sys/dev/gpio/gpio.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.29 src/sys/dev/gpio/gpio.c:1.30
--- src/sys/dev/gpio/gpio.c:1.29	Thu Nov  5 18:20:40 2009
+++ src/sys/dev/gpio/gpio.c	Fri Jan  8 19:48:18 2010
@@ -1,4 +1,4 @@
-/* $NetBSD: gpio.c,v 1.29 2009/11/05 18:20:40 dyoung Exp $ */
+/* $NetBSD: gpio.c,v 1.30 2010/01/08 19:48:18 dyoung 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.29 2009/11/05 18:20:40 dyoung Exp $);
+__KERNEL_RCSID(0, $NetBSD: gpio.c,v 1.30 2010/01/08 19:48:18 dyoung Exp $);
 
 /*
  * General Purpose Input/Output framework.
@@ -66,7 +66,7 @@
 void	gpio_attach(device_t, device_t, void *);
 int	gpio_rescan(device_t, const char *, const int *);
 void	gpio_childdetached(device_t, device_t);
-bool	gpio_resume(device_t PMF_FN_PROTO);
+bool	gpio_resume(device_t, pmf_qual_t);
 int	gpio_detach(device_t, int);
 int	gpio_search(device_t, cfdata_t, const int *, void *);
 int	gpio_print(void *, const char *);
@@ -108,7 +108,7 @@
 }
 
 bool
-gpio_resume(device_t self PMF_FN_ARGS)
+gpio_resume(device_t self, pmf_qual_t qual)
 {
 	struct gpio_softc *sc = device_private(self);
 	int pin;



CVS commit: src/sys/dev/gpio

2009-12-06 Thread David Young
Module Name:src
Committed By:   dyoung
Date:   Sun Dec  6 22:33:44 UTC 2009

Modified Files:
src/sys/dev/gpio: gpioiic.c gpiolock.c gpiosim.c

Log Message:
Delete unnecessary device-activation hooks.  Simplify the rest.


To generate a diff of this commit:
cvs rdiff -u -r1.1 -r1.2 src/sys/dev/gpio/gpioiic.c
cvs rdiff -u -r1.2 -r1.3 src/sys/dev/gpio/gpiolock.c
cvs rdiff -u -r1.6 -r1.7 src/sys/dev/gpio/gpiosim.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/gpioiic.c
diff -u src/sys/dev/gpio/gpioiic.c:1.1 src/sys/dev/gpio/gpioiic.c:1.2
--- src/sys/dev/gpio/gpioiic.c:1.1	Sun Aug  9 08:18:00 2009
+++ src/sys/dev/gpio/gpioiic.c	Sun Dec  6 22:33:44 2009
@@ -1,4 +1,4 @@
-/* $NetBSD: gpioiic.c,v 1.1 2009/08/09 08:18:00 mbalmer Exp $ */
+/* $NetBSD: gpioiic.c,v 1.2 2009/12/06 22:33:44 dyoung Exp $ */
 /*	$OpenBSD: gpioiic.c,v 1.8 2008/11/24 12:12:12 mbalmer Exp $	*/
 
 /*
@@ -18,7 +18,7 @@
  */
 
 #include sys/cdefs.h
-__KERNEL_RCSID(0, $NetBSD: gpioiic.c,v 1.1 2009/08/09 08:18:00 mbalmer Exp $);
+__KERNEL_RCSID(0, $NetBSD: gpioiic.c,v 1.2 2009/12/06 22:33:44 dyoung Exp $);
 
 /*
  * I2C bus bit-banging through GPIO pins.
@@ -58,7 +58,6 @@
 int		gpioiic_match(device_t, cfdata_t, void *);
 void		gpioiic_attach(device_t, device_t, void *);
 int		gpioiic_detach(device_t, int);
-int		gpioiic_activate(device_t, enum devact);
 
 int		gpioiic_i2c_acquire_bus(void *, int);
 void		gpioiic_i2c_release_bus(void *, int);
@@ -73,7 +72,7 @@
 u_int32_t	gpioiic_bb_read_bits(void *);
 
 CFATTACH_DECL_NEW(gpioiic, sizeof(struct gpioiic_softc),
-	gpioiic_match, gpioiic_attach, gpioiic_detach, gpioiic_activate);
+	gpioiic_match, gpioiic_attach, gpioiic_detach, NULL);
 
 extern struct cfdriver gpioiic_cd;
 
@@ -212,20 +211,6 @@
 }
 
 int
-gpioiic_activate(device_t self, enum devact act)
-{
-	int rv = 0;
-
-	switch (act) {
-	case DVACT_ACTIVATE:
-		return EOPNOTSUPP;
-	case DVACT_DEACTIVATE:
-		break;
-	}
-	return rv;
-}
-
-int
 gpioiic_i2c_acquire_bus(void *cookie, int flags)
 {
 	struct gpioiic_softc *sc = cookie;

Index: src/sys/dev/gpio/gpiolock.c
diff -u src/sys/dev/gpio/gpiolock.c:1.2 src/sys/dev/gpio/gpiolock.c:1.3
--- src/sys/dev/gpio/gpiolock.c:1.2	Sat Aug 15 09:43:59 2009
+++ src/sys/dev/gpio/gpiolock.c	Sun Dec  6 22:33:44 2009
@@ -1,4 +1,4 @@
-/* $NetBSD: gpiolock.c,v 1.2 2009/08/15 09:43:59 mbalmer Exp $ */
+/* $NetBSD: gpiolock.c,v 1.3 2009/12/06 22:33:44 dyoung Exp $ */
 
 /*
  * Copyright (c) 2009 Marc Balmer m...@msys.ch
@@ -152,14 +152,13 @@
 	struct gpiolock_softc *sc = device_private(self);
 
 	switch (act) {
-	case DVACT_ACTIVATE:
-		return EOPNOTSUPP;
 	case DVACT_DEACTIVATE:
 		sc-sc_dying = 1;
-		break;
+		return 0;
+	default:
+		return EOPNOTSUPP;
 	}
 
-	return 0;
 }
 
 int

Index: src/sys/dev/gpio/gpiosim.c
diff -u src/sys/dev/gpio/gpiosim.c:1.6 src/sys/dev/gpio/gpiosim.c:1.7
--- src/sys/dev/gpio/gpiosim.c:1.6	Fri Aug  7 08:08:18 2009
+++ src/sys/dev/gpio/gpiosim.c	Sun Dec  6 22:33:44 2009
@@ -1,4 +1,4 @@
-/* $NetBSD: gpiosim.c,v 1.6 2009/08/07 08:08:18 mbalmer Exp $ */
+/* $NetBSD: gpiosim.c,v 1.7 2009/12/06 22:33:44 dyoung Exp $ */
 /*  $OpenBSD: gpiosim.c,v 1.1 2008/11/23 18:46:49 mbalmer Exp $	*/
 
 /*
@@ -45,7 +45,6 @@
 void	gpiosimattach(int);
 void	gpiosim_attach(device_t, device_t, void *);
 int	gpiosim_detach(device_t, int);
-int	gpiosim_activate(device_t, enum devact);
 int	gpiosim_sysctl(SYSCTLFN_PROTO);
 
 int	gpiosim_pin_read(void *, int);
@@ -53,7 +52,7 @@
 void	gpiosim_pin_ctl(void *, int, int);
 
 CFATTACH_DECL_NEW(gpiosim, sizeof(struct gpiosim_softc), gpiosim_match,
-gpiosim_attach, gpiosim_detach, gpiosim_activate);
+gpiosim_attach, gpiosim_detach, NULL);
 
 extern struct cfdriver gpiosim_cd;
 
@@ -167,18 +166,6 @@
 }
 
 int
-gpiosim_activate(device_t self, enum devact act)
-{
-	switch (act) {
-	case DVACT_ACTIVATE:
-		return EOPNOTSUPP;
-	case DVACT_DEACTIVATE:
-		break;
-	}
-	return 0;
-}
-
-int
 gpiosim_sysctl(SYSCTLFN_ARGS)
 {
 	struct sysctlnode node;



CVS commit: src/sys/dev/gpio

2009-11-12 Thread David Young
Module Name:src
Committed By:   dyoung
Date:   Thu Nov 12 19:22:08 UTC 2009

Modified Files:
src/sys/dev/gpio: gpioow.c

Log Message:
Simplify activation hook.


To generate a diff of this commit:
cvs rdiff -u -r1.11 -r1.12 src/sys/dev/gpio/gpioow.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/gpioow.c
diff -u src/sys/dev/gpio/gpioow.c:1.11 src/sys/dev/gpio/gpioow.c:1.12
--- src/sys/dev/gpio/gpioow.c:1.11	Sat Aug  8 10:38:17 2009
+++ src/sys/dev/gpio/gpioow.c	Thu Nov 12 19:22:08 2009
@@ -1,4 +1,4 @@
-/* $NetBSD: gpioow.c,v 1.11 2009/08/08 10:38:17 mbalmer Exp $ */
+/* $NetBSD: gpioow.c,v 1.12 2009/11/12 19:22:08 dyoung Exp $ */
 /*	$OpenBSD: gpioow.c,v 1.1 2006/03/04 16:27:03 grange Exp $	*/
 
 /*
@@ -18,7 +18,7 @@
  */
 
 #include sys/cdefs.h
-__KERNEL_RCSID(0, $NetBSD: gpioow.c,v 1.11 2009/08/08 10:38:17 mbalmer Exp $);
+__KERNEL_RCSID(0, $NetBSD: gpioow.c,v 1.12 2009/11/12 19:22:08 dyoung Exp $);
 
 /*
  * 1-Wire bus bit-banging through GPIO pin.
@@ -175,18 +175,14 @@
 gpioow_activate(device_t self, enum devact act)
 {
 	struct gpioow_softc *sc = device_private(self);
-	int rv = 0;
 
 	switch (act) {
-	case DVACT_ACTIVATE:
-		return EOPNOTSUPP;
 	case DVACT_DEACTIVATE:
 		sc-sc_dying = 1;
-		if (sc-sc_ow_dev != NULL)
-			rv = config_deactivate(sc-sc_ow_dev);
-		break;
+		return 0;
+	default:
+		return EOPNOTSUPP;
 	}
-	return rv;
 }
 
 int



CVS commit: src/sys/dev/gpio

2009-08-23 Thread Marc Balmer
Module Name:src
Committed By:   mbalmer
Date:   Sun Aug 23 12:08:57 UTC 2009

Modified Files:
src/sys/dev/gpio: gpio.c

Log Message:
Prevent the creation of duplicate pin names in GPIOPINSET.
Problem noticed by rmind a while ago.


To generate a diff of this commit:
cvs rdiff -u -r1.27 -r1.28 src/sys/dev/gpio/gpio.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.27 src/sys/dev/gpio/gpio.c:1.28
--- src/sys/dev/gpio/gpio.c:1.27	Fri Aug 21 12:53:42 2009
+++ src/sys/dev/gpio/gpio.c	Sun Aug 23 12:08:56 2009
@@ -1,4 +1,4 @@
-/* $NetBSD: gpio.c,v 1.27 2009/08/21 12:53:42 mbalmer Exp $ */
+/* $NetBSD: gpio.c,v 1.28 2009/08/23 12:08:56 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.27 2009/08/21 12:53:42 mbalmer Exp $);
+__KERNEL_RCSID(0, $NetBSD: gpio.c,v 1.28 2009/08/23 12:08:56 mbalmer Exp $);
 
 /*
  * General Purpose Input/Output framework.
@@ -390,7 +390,7 @@
 	cfdata_t cf;
 	kauth_cred_t cred;
 	int locs[GPIOCF_NLOCS];
-	int pin, value, flags, npins, found;
+	int pin, value, flags, npins;
 
 	sc = device_lookup_private(gpio_cd, minor(dev));
 	gc = sc-sc_gc;
@@ -591,17 +591,21 @@
 		}
 
 		/* rename pin or new pin? */
-		/* XXX avoid the creation of duplicates */
 		if (set-gp_name2[0] != '\0') {
-			found = 0;
-			LIST_FOREACH(nm, sc-sc_names, gp_next)
-if (nm-gp_pin == pin) {
-	strlcpy(nm-gp_name, set-gp_name2,
-	sizeof(nm-gp_name));
-	found = 1;
-	break;
-}
-			if (!found) {
+			struct gpio_name *gnm;
+
+			gnm = NULL;
+			LIST_FOREACH(nm, sc-sc_names, gp_next) {
+if (!strcmp(nm-gp_name, set-gp_name2) 
+nm-gp_pin != pin)
+	return EINVAL;	/* duplicate name */
+if (nm-gp_pin == pin)
+	gnm = nm;
+			}
+			if (gnm != NULL)
+strlcpy(gnm-gp_name, set-gp_name2,
+sizeof(gnm-gp_name));
+			else  {
 nm = kmem_alloc(sizeof(struct gpio_name),
 KM_SLEEP);
 strlcpy(nm-gp_name, set-gp_name2,



CVS commit: src/sys/dev/gpio

2009-08-21 Thread Marc Balmer
Module Name:src
Committed By:   mbalmer
Date:   Fri Aug 21 12:53:42 UTC 2009

Modified Files:
src/sys/dev/gpio: gpio.c gpiovar.h

Log Message:
Before trying to attach a child device driver, make sure the GPIO pins can
be mapped.  This prevents drivers from later failing in the attach routine.
Problem found by me, solution suggested by jmcneill.


To generate a diff of this commit:
cvs rdiff -u -r1.26 -r1.27 src/sys/dev/gpio/gpio.c
cvs rdiff -u -r1.9 -r1.10 src/sys/dev/gpio/gpiovar.h

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.26 src/sys/dev/gpio/gpio.c:1.27
--- src/sys/dev/gpio/gpio.c:1.26	Mon Aug 17 12:44:44 2009
+++ src/sys/dev/gpio/gpio.c	Fri Aug 21 12:53:42 2009
@@ -1,4 +1,4 @@
-/* $NetBSD: gpio.c,v 1.26 2009/08/17 12:44:44 mbalmer Exp $ */
+/* $NetBSD: gpio.c,v 1.27 2009/08/21 12:53:42 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.26 2009/08/17 12:44:44 mbalmer Exp $);
+__KERNEL_RCSID(0, $NetBSD: gpio.c,v 1.27 2009/08/21 12:53:42 mbalmer Exp $);
 
 /*
  * General Purpose Input/Output framework.
@@ -217,6 +217,30 @@
 	return UNCONF;
 }
 
+/* return 1 if all pins can be mapped, 0 if not */
+
+int
+gpio_pin_can_map(void *gpio, int offset, u_int32_t mask)
+{
+	struct gpio_softc *sc = gpio;
+	int npins, pin, i;
+
+	npins = gpio_npins(mask);
+	if (npins  sc-sc_npins)
+		return 0;
+
+	for (npins = 0, i = 0; i  32; i++)
+		if (mask  (1  i)) {
+			pin = offset + i;
+			if (pin  0 || pin = sc-sc_npins)
+return 0;
+			if (sc-sc_pins[pin].pin_mapped)
+return 0;
+		}
+
+	return 1;
+}
+
 int
 gpio_pin_map(void *gpio, int offset, u_int32_t mask, struct gpio_pinmap *map)
 {
@@ -483,8 +507,13 @@
 		if (kauth_authorize_device(cred, KAUTH_DEVICE_GPIO_PINSET,
 		NULL, NULL, NULL, NULL))
 			return EPERM;
-
+
 		attach = (struct gpio_attach *)data;
+
+		/* do not try to attach if the pins are already mapped */
+		if (!gpio_pin_can_map(sc, attach-ga_offset, attach-ga_mask))
+			return EBUSY;
+
 		ga.ga_gpio = sc;
 		ga.ga_dvname = attach-ga_dvname;
 		ga.ga_offset = attach-ga_offset;

Index: src/sys/dev/gpio/gpiovar.h
diff -u src/sys/dev/gpio/gpiovar.h:1.9 src/sys/dev/gpio/gpiovar.h:1.10
--- src/sys/dev/gpio/gpiovar.h:1.9	Sat Jul 25 16:30:44 2009
+++ src/sys/dev/gpio/gpiovar.h	Fri Aug 21 12:53:42 2009
@@ -1,4 +1,4 @@
-/* $NetBSD: gpiovar.h,v 1.9 2009/07/25 16:30:44 mbalmer Exp $ */
+/* $NetBSD: gpiovar.h,v 1.10 2009/08/21 12:53:42 mbalmer Exp $ */
 /*	$OpenBSD: gpiovar.h,v 1.3 2006/01/14 12:33:49 grange Exp $	*/
 
 /*
@@ -88,6 +88,7 @@
 	LIST_ENTRY(gpio_name)	gp_next;
 };
 
+int	gpio_pin_can_map(void *, int, u_int32_t);
 int	gpio_pin_map(void *, int, u_int32_t, struct gpio_pinmap *);
 void	gpio_pin_unmap(void *, struct gpio_pinmap *);
 int	gpio_pin_read(void *, struct gpio_pinmap *, int);



CVS commit: src/sys/dev/gpio

2009-08-17 Thread Marc Balmer
Module Name:src
Committed By:   mbalmer
Date:   Mon Aug 17 12:44:44 UTC 2009

Modified Files:
src/sys/dev/gpio: gpio.c

Log Message:
unfold short lines, fold long line.


To generate a diff of this commit:
cvs rdiff -u -r1.25 -r1.26 src/sys/dev/gpio/gpio.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.25 src/sys/dev/gpio/gpio.c:1.26
--- src/sys/dev/gpio/gpio.c:1.25	Fri Aug  7 08:05:48 2009
+++ src/sys/dev/gpio/gpio.c	Mon Aug 17 12:44:44 2009
@@ -1,4 +1,4 @@
-/* $NetBSD: gpio.c,v 1.25 2009/08/07 08:05:48 mbalmer Exp $ */
+/* $NetBSD: gpio.c,v 1.26 2009/08/17 12:44:44 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.25 2009/08/07 08:05:48 mbalmer Exp $);
+__KERNEL_RCSID(0, $NetBSD: gpio.c,v 1.26 2009/08/17 12:44:44 mbalmer Exp $);
 
 /*
  * General Purpose Input/Output framework.
@@ -300,8 +300,7 @@
 }
 
 int
-gpioopen(dev_t dev, int flag, int mode,
-struct lwp *l)
+gpioopen(dev_t dev, int flag, int mode, struct lwp *l)
 {
 	struct gpio_softc *sc;
 	int ret;
@@ -328,8 +327,7 @@
 }
 
 int
-gpioclose(dev_t dev, int flag, int mode,
-struct lwp *l)
+gpioclose(dev_t dev, int flag, int mode, struct lwp *l)
 {
 	struct gpio_softc *sc;
 
@@ -353,8 +351,7 @@
 }
 
 int
-gpioioctl(dev_t dev, u_long cmd, void *data, int flag,
-struct lwp *l)
+gpioioctl(dev_t dev, u_long cmd, void *data, int flag, struct lwp *l)
 {
 	struct gpio_softc *sc;
 	gpio_chipset_tag_t gc;
@@ -375,7 +372,8 @@
 	gc = sc-sc_gc;
 
 	if (cmd != GPIOINFO  !device_is_active(sc-sc_dev)) {
-		DPRINTF((%s: device is not active\n, device_xname(sc-sc_dev)));
+		DPRINTF((%s: device is not active\n,
+		device_xname(sc-sc_dev)));
 		return EBUSY;
 	}
 	



CVS commit: src/sys/dev/gpio

2009-08-07 Thread Marc Balmer
Module Name:src
Committed By:   mbalmer
Date:   Fri Aug  7 08:05:48 UTC 2009

Modified Files:
src/sys/dev/gpio: gpio.c

Log Message:
Fold long line.


To generate a diff of this commit:
cvs rdiff -u -r1.24 -r1.25 src/sys/dev/gpio/gpio.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.24 src/sys/dev/gpio/gpio.c:1.25
--- src/sys/dev/gpio/gpio.c:1.24	Mon Aug  3 12:43:56 2009
+++ src/sys/dev/gpio/gpio.c	Fri Aug  7 08:05:48 2009
@@ -1,4 +1,4 @@
-/* $NetBSD: gpio.c,v 1.24 2009/08/03 12:43:56 mbalmer Exp $ */
+/* $NetBSD: gpio.c,v 1.25 2009/08/07 08:05:48 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.24 2009/08/03 12:43:56 mbalmer Exp $);
+__KERNEL_RCSID(0, $NetBSD: gpio.c,v 1.25 2009/08/07 08:05:48 mbalmer Exp $);
 
 /*
  * General Purpose Input/Output framework.
@@ -316,7 +316,8 @@
 	}
 
 	if ((ret = gpiobus_open(sc-sc_gc, sc-sc_dev))) {
-		DPRINTF((%s: gpiobus_open returned %d\n, device_xname(sc-sc_dev),
+		DPRINTF((%s: gpiobus_open returned %d\n,
+		device_xname(sc-sc_dev),
 		ret));
 		return ret;
 	}



CVS commit: src/sys/dev/gpio

2009-08-07 Thread Marc Balmer
Module Name:src
Committed By:   mbalmer
Date:   Fri Aug  7 08:08:18 UTC 2009

Modified Files:
src/sys/dev/gpio: gpiosim.c

Log Message:
Properly teardown the sysctl node and detach child driver if gpiosim gets
detached itself (e.g. when the 'drvctl -d gpiosimX' command is entered).


To generate a diff of this commit:
cvs rdiff -u -r1.5 -r1.6 src/sys/dev/gpio/gpiosim.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/gpiosim.c
diff -u src/sys/dev/gpio/gpiosim.c:1.5 src/sys/dev/gpio/gpiosim.c:1.6
--- src/sys/dev/gpio/gpiosim.c:1.5	Thu Aug  6 13:16:49 2009
+++ src/sys/dev/gpio/gpiosim.c	Fri Aug  7 08:08:18 2009
@@ -1,4 +1,4 @@
-/* $NetBSD: gpiosim.c,v 1.5 2009/08/06 13:16:49 mbalmer Exp $ */
+/* $NetBSD: gpiosim.c,v 1.6 2009/08/07 08:08:18 mbalmer Exp $ */
 /*  $OpenBSD: gpiosim.c,v 1.1 2008/11/23 18:46:49 mbalmer Exp $	*/
 
 /*
@@ -33,11 +33,12 @@
 
 struct gpiosim_softc {
 	device_t		sc_dev;
+	device_t		sc_gdev;	/* gpio that attaches here */
 	u_int32_t		sc_state;
 	struct gpio_chipset_tag	sc_gpio_gc;
 	gpio_pin_t		sc_gpio_pins[GPIOSIM_NPINS];
 
-	const struct sysctlnode *sc_node;
+	struct sysctllog	*sc_log;
 };
 
 int	gpiosim_match(device_t, cfdata_t, void *);
@@ -87,6 +88,7 @@
 {
 	struct gpiosim_softc *sc = device_private(self);
 	struct gpiobus_attach_args gba;
+	const struct sysctlnode *node;
 	int i;
 
 	sc-sc_dev = self;
@@ -124,19 +126,19 @@
 CTLTYPE_NODE, hw, NULL,
 NULL, 0, NULL, 0,
 CTL_HW, CTL_EOL);
-sysctl_createv(NULL, 0, NULL, sc-sc_node,
+sysctl_createv(sc-sc_log, 0, NULL, node,
 0,
 CTLTYPE_NODE, device_xname(sc-sc_dev),
 SYSCTL_DESCR(GPIO simulator),
 NULL, 0, NULL, 0,
 CTL_HW, CTL_CREATE, CTL_EOL);
 
-if (sc-sc_node == NULL) {
+if (node == NULL) {
 		printf(: can't create sysctl node\n);
 return;
 	}
 
-sysctl_createv(NULL, 0, sc-sc_node, NULL,
+sysctl_createv(sc-sc_log, 0, node, NULL,
 CTLFLAG_READWRITE,
 CTLTYPE_INT, value,
 SYSCTL_DESCR(Current GPIO simulator value),
@@ -144,22 +146,23 @@
 	CTL_CREATE, CTL_EOL);
 
 	printf(: simulating %d pins\n, GPIOSIM_NPINS);
-	config_found_ia(self, gpiobus, gba, gpiobus_print);
+	sc-sc_gdev = config_found_ia(self, gpiobus, gba, gpiobus_print);
 }
 
 int
 gpiosim_detach(device_t self, int flags)
 {
 	struct gpiosim_softc *sc = device_private(self);
-	struct sysctlnode node;
+
+	/* Detach the gpio driver that attached here */
+	if (sc-sc_gdev != NULL)
+		config_detach(sc-sc_gdev, 0);
 
 	pmf_device_deregister(self);
-	if (sc-sc_node != NULL) {
-		node = *sc-sc_node;
-		sysctl_destroyv(node, CTL_EOL);
-		sc-sc_node = NULL;
+	if (sc-sc_log != NULL) {
+		sysctl_teardown(sc-sc_log);
+		sc-sc_log = NULL;
 	}
-
 	return 0;
 }
 
@@ -172,7 +175,6 @@
 	case DVACT_DEACTIVATE:
 		break;
 	}
-
 	return 0;
 }
 
@@ -200,7 +202,7 @@
 int
 gpiosim_pin_read(void *arg, int pin)
 {
-	struct gpiosim_softc *sc = (struct gpiosim_softc *)arg;
+	struct gpiosim_softc *sc = arg;
 
 	if (sc-sc_state  (1  pin))
 		return GPIO_PIN_HIGH;
@@ -211,7 +213,7 @@
 void
 gpiosim_pin_write(void *arg, int pin, int value)
 {
-	struct gpiosim_softc *sc = (struct gpiosim_softc *)arg;
+	struct gpiosim_softc *sc = arg;
 
 	if (value == 0)
 		sc-sc_state = ~(1  pin);
@@ -222,7 +224,7 @@
 void
 gpiosim_pin_ctl(void *arg, int pin, int flags)
 {
-	struct gpiosim_softc *sc = (struct gpiosim_softc *)arg;
+	struct gpiosim_softc *sc = arg;
 
 	sc-sc_gpio_pins[pin].pin_flags = flags;
 }



CVS commit: src/sys/dev/gpio

2009-08-07 Thread Marc Balmer
Module Name:src
Committed By:   mbalmer
Date:   Fri Aug  7 08:15:52 UTC 2009

Modified Files:
src/sys/dev/gpio: gpioow.c

Log Message:
Don't use an identifier name that probably clashes with the C standard.
Requested by many.


To generate a diff of this commit:
cvs rdiff -u -r1.9 -r1.10 src/sys/dev/gpio/gpioow.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/gpioow.c
diff -u src/sys/dev/gpio/gpioow.c:1.9 src/sys/dev/gpio/gpioow.c:1.10
--- src/sys/dev/gpio/gpioow.c:1.9	Mon Aug  3 17:24:40 2009
+++ src/sys/dev/gpio/gpioow.c	Fri Aug  7 08:15:52 2009
@@ -1,4 +1,4 @@
-/* $NetBSD: gpioow.c,v 1.9 2009/08/03 17:24:40 mbalmer Exp $ */
+/* $NetBSD: gpioow.c,v 1.10 2009/08/07 08:15:52 mbalmer Exp $ */
 /*	$OpenBSD: gpioow.c,v 1.1 2006/03/04 16:27:03 grange Exp $	*/
 
 /*
@@ -18,7 +18,7 @@
  */
 
 #include sys/cdefs.h
-__KERNEL_RCSID(0, $NetBSD: gpioow.c,v 1.9 2009/08/03 17:24:40 mbalmer Exp $);
+__KERNEL_RCSID(0, $NetBSD: gpioow.c,v 1.10 2009/08/07 08:15:52 mbalmer Exp $);
 
 /*
  * 1-Wire bus bit-banging through GPIO pin.
@@ -39,7 +39,7 @@
 struct gpioow_softc {
 	void *			sc_gpio;
 	struct gpio_pinmap	sc_map;
-	int			__map[GPIOOW_NPINS];
+	int			_map[GPIOOW_NPINS];
 
 	struct onewire_bus	sc_ow_bus;
 	device_t		sc_ow_dev;
@@ -103,7 +103,7 @@
 
 	/* Map pins */
 	sc-sc_gpio = ga-ga_gpio;
-	sc-sc_map.pm_map = sc-__map;
+	sc-sc_map.pm_map = sc-_map;
 	if (gpio_pin_map(sc-sc_gpio, ga-ga_offset, ga-ga_mask,
 	sc-sc_map)) {
 		aprint_error(: can't map pins\n);



CVS commit: src/sys/dev/gpio

2009-08-06 Thread Marc Balmer
Module Name:src
Committed By:   mbalmer
Date:   Thu Aug  6 13:16:49 UTC 2009

Modified Files:
src/sys/dev/gpio: gpiosim.c

Log Message:
For the sake of correctness, call pmf_device_deregister() in the detach
function.


To generate a diff of this commit:
cvs rdiff -u -r1.4 -r1.5 src/sys/dev/gpio/gpiosim.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/gpiosim.c
diff -u src/sys/dev/gpio/gpiosim.c:1.4 src/sys/dev/gpio/gpiosim.c:1.5
--- src/sys/dev/gpio/gpiosim.c:1.4	Tue Jul 28 15:28:24 2009
+++ src/sys/dev/gpio/gpiosim.c	Thu Aug  6 13:16:49 2009
@@ -1,4 +1,4 @@
-/* $NetBSD: gpiosim.c,v 1.4 2009/07/28 15:28:24 drochner Exp $ */
+/* $NetBSD: gpiosim.c,v 1.5 2009/08/06 13:16:49 mbalmer Exp $ */
 /*  $OpenBSD: gpiosim.c,v 1.1 2008/11/23 18:46:49 mbalmer Exp $	*/
 
 /*
@@ -153,6 +153,7 @@
 	struct gpiosim_softc *sc = device_private(self);
 	struct sysctlnode node;
 
+	pmf_device_deregister(self);
 	if (sc-sc_node != NULL) {
 		node = *sc-sc_node;
 		sysctl_destroyv(node, CTL_EOL);



CVS commit: src/sys/dev/gpio

2009-08-03 Thread Marc Balmer
Module Name:src
Committed By:   mbalmer
Date:   Mon Aug  3 12:42:45 UTC 2009

Modified Files:
src/sys/dev/gpio: gpioow.c

Log Message:
A better match routine that checks also the number of pins instead
of checking the pins in the attach routine; malconfigured devices will
no longer attach.  While here, replace some printf uses by aprint_


To generate a diff of this commit:
cvs rdiff -u -r1.7 -r1.8 src/sys/dev/gpio/gpioow.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/gpioow.c
diff -u src/sys/dev/gpio/gpioow.c:1.7 src/sys/dev/gpio/gpioow.c:1.8
--- src/sys/dev/gpio/gpioow.c:1.7	Sat Jul 25 16:17:10 2009
+++ src/sys/dev/gpio/gpioow.c	Mon Aug  3 12:42:45 2009
@@ -1,4 +1,4 @@
-/* $NetBSD: gpioow.c,v 1.7 2009/07/25 16:17:10 mbalmer Exp $ */
+/* $NetBSD: gpioow.c,v 1.8 2009/08/03 12:42:45 mbalmer Exp $ */
 /*	$OpenBSD: gpioow.c,v 1.1 2006/03/04 16:27:03 grange Exp $	*/
 
 /*
@@ -18,7 +18,7 @@
  */
 
 #include sys/cdefs.h
-__KERNEL_RCSID(0, $NetBSD: gpioow.c,v 1.7 2009/07/25 16:17:10 mbalmer Exp $);
+__KERNEL_RCSID(0, $NetBSD: gpioow.c,v 1.8 2009/08/03 12:42:45 mbalmer Exp $);
 
 /*
  * 1-Wire bus bit-banging through GPIO pin.
@@ -79,10 +79,19 @@
 {
 	struct gpio_attach_args *ga = aux;
 
+	if (strcmp(ga-ga_dvname, cf-cf_name))
+		return 0;
+
 	if (ga-ga_offset == -1)
 		return 0;
 
-	return strcmp(ga-ga_dvname, cf-cf_name) == 0;
+	/* Check that we have enough pins */
+	if (gpio_npins(ga-ga_mask) != GPIOOW_NPINS) {
+		aprint_debug(%s: invalid pin mask 0x%02x/n, cf-cf_name,
+		ga-ga_mask);
+		return 0;
+	}
+	return 1;
 }
 
 void
@@ -93,47 +102,41 @@
 	struct onewirebus_attach_args oba;
 	int caps;
 
-	/* Check that we have enough pins */
-	if (gpio_npins(ga-ga_mask) != GPIOOW_NPINS) {
-		printf(: invalid pin mask 0x%02x\n, ga-ga_mask);
-		return;
-	}
-
 	/* Map pins */
 	sc-sc_gpio = ga-ga_gpio;
 	sc-sc_map.pm_map = sc-__map;
 	if (gpio_pin_map(sc-sc_gpio, ga-ga_offset, ga-ga_mask,
 	sc-sc_map)) {
-		printf(: can't map pins\n);
+		aprint_error(: can't map pins\n);
 		return;
 	}
 
 	/* Configure data pin */
 	caps = gpio_pin_caps(sc-sc_gpio, sc-sc_map, GPIOOW_PIN_DATA);
 	if (!(caps  GPIO_PIN_OUTPUT)) {
-		printf(: data pin is unable to drive output\n);
+		aprint_error(: data pin is unable to drive output\n);
 		goto fail;
 	}
 	if (!(caps  GPIO_PIN_INPUT)) {
-		printf(: data pin is unable to read input\n);
+		aprint_error(: data pin is unable to read input\n);
 		goto fail;
 	}
-	printf(: DATA[%d], sc-sc_map.pm_map[GPIOOW_PIN_DATA]);
+	aprint_normal(: DATA[%d], sc-sc_map.pm_map[GPIOOW_PIN_DATA]);
 	sc-sc_data = GPIO_PIN_OUTPUT;
 	if (caps  GPIO_PIN_OPENDRAIN) {
-		printf( open-drain);
+		aprint_normal( open-drain);
 		sc-sc_data |= GPIO_PIN_OPENDRAIN;
 	} else if ((caps  GPIO_PIN_PUSHPULL)  (caps  GPIO_PIN_TRISTATE)) {
-		printf( push-pull tri-state);
+		aprint_normal( push-pull tri-state);
 		sc-sc_data |= GPIO_PIN_PUSHPULL;
 	}
 	if (caps  GPIO_PIN_PULLUP) {
-		printf( pull-up);
+		aprint_normal( pull-up);
 		sc-sc_data |= GPIO_PIN_PULLUP;
 	}
 	gpio_pin_ctl(sc-sc_gpio, sc-sc_map, GPIOOW_PIN_DATA, sc-sc_data);
 
-	printf(\n);
+	aprint_normal(\n);
 
 	/* Attach 1-Wire bus */
 	sc-sc_ow_bus.bus_cookie = sc;



CVS commit: src/sys/dev/gpio

2009-08-03 Thread Marc Balmer
Module Name:src
Committed By:   mbalmer
Date:   Mon Aug  3 12:43:56 UTC 2009

Modified Files:
src/sys/dev/gpio: gpio.c

Log Message:
Be more careful when attaching drivers at runtime, call the drivers match
routine before attaching the device.  Prevents non-working driver instances
from being created.


To generate a diff of this commit:
cvs rdiff -u -r1.23 -r1.24 src/sys/dev/gpio/gpio.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.23 src/sys/dev/gpio/gpio.c:1.24
--- src/sys/dev/gpio/gpio.c:1.23	Sun Jul 26 14:06:05 2009
+++ src/sys/dev/gpio/gpio.c	Mon Aug  3 12:43:56 2009
@@ -1,4 +1,4 @@
-/* $NetBSD: gpio.c,v 1.23 2009/07/26 14:06:05 mbalmer Exp $ */
+/* $NetBSD: gpio.c,v 1.24 2009/08/03 12:43:56 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.23 2009/07/26 14:06:05 mbalmer Exp $);
+__KERNEL_RCSID(0, $NetBSD: gpio.c,v 1.24 2009/08/03 12:43:56 mbalmer Exp $);
 
 /*
  * General Purpose Input/Output framework.
@@ -365,6 +365,7 @@
 	struct gpio_name *nm;
 	struct gpio_set *set;
 	device_t dv;
+	cfdata_t cf;
 	kauth_cred_t cred;
 	int locs[GPIOCF_NLOCS];
 	int pin, value, flags, npins, found;
@@ -496,12 +497,17 @@
 		locs[GPIOCF_OFFSET] = ga.ga_offset;
 		locs[GPIOCF_MASK] = ga.ga_mask;
 
-		dv = config_found_sm_loc(sc-sc_dev, gpio, locs, ga,
-		gpiobus_print, gpio_submatch);
-		if (dv != NULL) {
-			gdev = kmem_alloc(sizeof(struct gpio_dev), KM_SLEEP);
-			gdev-sc_dev = dv;
-			LIST_INSERT_HEAD(sc-sc_devs, gdev, sc_next);
+		cf = config_search_loc(NULL, sc-sc_dev, gpio, locs, ga);
+		if (cf != NULL) {
+			dv = config_attach_loc(sc-sc_dev, cf, locs, ga,
+			gpiobus_print);
+			if (dv != NULL) {
+gdev = kmem_alloc(sizeof(struct gpio_dev),
+KM_SLEEP);
+gdev-sc_dev = dv;
+LIST_INSERT_HEAD(sc-sc_devs, gdev, sc_next);
+			} else
+return EINVAL;
 		} else
 			return EINVAL;
 		break;



CVS commit: src/sys/dev/gpio

2009-08-03 Thread Marc Balmer
Module Name:src
Committed By:   mbalmer
Date:   Mon Aug  3 17:24:40 UTC 2009

Modified Files:
src/sys/dev/gpio: gpioow.c

Log Message:
unfold short line; debracket


To generate a diff of this commit:
cvs rdiff -u -r1.8 -r1.9 src/sys/dev/gpio/gpioow.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/gpioow.c
diff -u src/sys/dev/gpio/gpioow.c:1.8 src/sys/dev/gpio/gpioow.c:1.9
--- src/sys/dev/gpio/gpioow.c:1.8	Mon Aug  3 12:42:45 2009
+++ src/sys/dev/gpio/gpioow.c	Mon Aug  3 17:24:40 2009
@@ -1,4 +1,4 @@
-/* $NetBSD: gpioow.c,v 1.8 2009/08/03 12:42:45 mbalmer Exp $ */
+/* $NetBSD: gpioow.c,v 1.9 2009/08/03 17:24:40 mbalmer Exp $ */
 /*	$OpenBSD: gpioow.c,v 1.1 2006/03/04 16:27:03 grange Exp $	*/
 
 /*
@@ -18,7 +18,7 @@
  */
 
 #include sys/cdefs.h
-__KERNEL_RCSID(0, $NetBSD: gpioow.c,v 1.8 2009/08/03 12:42:45 mbalmer Exp $);
+__KERNEL_RCSID(0, $NetBSD: gpioow.c,v 1.9 2009/08/03 17:24:40 mbalmer Exp $);
 
 /*
  * 1-Wire bus bit-banging through GPIO pin.
@@ -74,8 +74,7 @@
 };
 
 int
-gpioow_match(device_t parent, cfdata_t cf,
-void *aux)
+gpioow_match(device_t parent, cfdata_t cf, void *aux)
 {
 	struct gpio_attach_args *ga = aux;
 
@@ -175,15 +174,14 @@
 
 	switch (act) {
 	case DVACT_ACTIVATE:
-		return (EOPNOTSUPP);
+		return EOPNOTSUPP;
 	case DVACT_DEACTIVATE:
 		sc-sc_dying = 1;
 		if (sc-sc_ow_dev != NULL)
 			rv = config_deactivate(sc-sc_ow_dev);
 		break;
 	}
-
-	return (rv);
+	return rv;
 }
 
 int



CVS commit: src/sys/dev/gpio

2009-07-28 Thread Matthias Drochner
Module Name:src
Committed By:   drochner
Date:   Tue Jul 28 15:28:24 UTC 2009

Modified Files:
src/sys/dev/gpio: gpiosim.c

Log Message:
add dummy pmf registration to allow suspend


To generate a diff of this commit:
cvs rdiff -u -r1.3 -r1.4 src/sys/dev/gpio/gpiosim.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/gpiosim.c
diff -u src/sys/dev/gpio/gpiosim.c:1.3 src/sys/dev/gpio/gpiosim.c:1.4
--- src/sys/dev/gpio/gpiosim.c:1.3	Mon Jul 27 17:40:58 2009
+++ src/sys/dev/gpio/gpiosim.c	Tue Jul 28 15:28:24 2009
@@ -1,4 +1,4 @@
-/* $NetBSD: gpiosim.c,v 1.3 2009/07/27 17:40:58 mbalmer Exp $ */
+/* $NetBSD: gpiosim.c,v 1.4 2009/07/28 15:28:24 drochner Exp $ */
 /*  $OpenBSD: gpiosim.c,v 1.1 2008/11/23 18:46:49 mbalmer Exp $	*/
 
 /*
@@ -117,6 +117,8 @@
 		gba.gba_npins = GPIOSIM_NPINS;
 	}
 
+	pmf_device_register(self, NULL, NULL);
+
 	sysctl_createv(NULL, 0, NULL, NULL,
 CTLFLAG_PERMANENT,
 CTLTYPE_NODE, hw, NULL,



CVS commit: src/sys/dev/gpio

2009-07-25 Thread Marc Balmer
Module Name:src
Committed By:   mbalmer
Date:   Sat Jul 25 16:41:58 UTC 2009

Modified Files:
src/sys/dev/gpio: gpio.c

Log Message:
Change one more struct device * to device_t, noticed by cegger.


To generate a diff of this commit:
cvs rdiff -u -r1.19 -r1.20 src/sys/dev/gpio/gpio.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.19 src/sys/dev/gpio/gpio.c:1.20
--- src/sys/dev/gpio/gpio.c:1.19	Sat Jul 25 16:17:10 2009
+++ src/sys/dev/gpio/gpio.c	Sat Jul 25 16:41:58 2009
@@ -1,4 +1,4 @@
-/* $NetBSD: gpio.c,v 1.19 2009/07/25 16:17:10 mbalmer Exp $ */
+/* $NetBSD: gpio.c,v 1.20 2009/07/25 16:41:58 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.19 2009/07/25 16:17:10 mbalmer Exp $);
+__KERNEL_RCSID(0, $NetBSD: gpio.c,v 1.20 2009/07/25 16:41:58 mbalmer Exp $);
 
 /*
  * General Purpose Input/Output framework.
@@ -364,7 +364,7 @@
 	struct gpio_req *req;
 	struct gpio_name *nm;
 	struct gpio_set *set;
-	struct device *dv;
+	device_t dv;
 	kauth_cred_t cred;
 	int locs[GPIOCF_NLOCS];
 	int pin, value, flags, npins, found;



CVS commit: src/sys/dev/gpio

2009-07-25 Thread Christoph Egger
Module Name:src
Committed By:   cegger
Date:   Sat Jul 25 19:01:56 UTC 2009

Modified Files:
src/sys/dev/gpio: gpio.c

Log Message:
make this build w/ GPIO_DEBUG


To generate a diff of this commit:
cvs rdiff -u -r1.20 -r1.21 src/sys/dev/gpio/gpio.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.20 src/sys/dev/gpio/gpio.c:1.21
--- src/sys/dev/gpio/gpio.c:1.20	Sat Jul 25 16:41:58 2009
+++ src/sys/dev/gpio/gpio.c	Sat Jul 25 19:01:55 2009
@@ -1,4 +1,4 @@
-/* $NetBSD: gpio.c,v 1.20 2009/07/25 16:41:58 mbalmer Exp $ */
+/* $NetBSD: gpio.c,v 1.21 2009/07/25 19:01:55 cegger 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.20 2009/07/25 16:41:58 mbalmer Exp $);
+__KERNEL_RCSID(0, $NetBSD: gpio.c,v 1.21 2009/07/25 19:01:55 cegger Exp $);
 
 /*
  * General Purpose Input/Output framework.
@@ -42,7 +42,7 @@
 #include locators.h
 
 #ifdef GPIO_DEBUG
-#define DPRINTF(n, x)	do { if (gpiodebug  (n)) printf x; } while (0)
+#define DPRINTFN(n, x)	do { if (gpiodebug  (n)) printf x; } while (0)
 int gpiodebug = 0;
 #else
 #define DPRINTFN(n, x)



CVS commit: src/sys/dev/gpio

2009-07-25 Thread Christoph Egger
Module Name:src
Committed By:   cegger
Date:   Sat Jul 25 19:18:01 UTC 2009

Modified Files:
src/sys/dev/gpio: gpio.c

Log Message:
use device_xname


To generate a diff of this commit:
cvs rdiff -u -r1.21 -r1.22 src/sys/dev/gpio/gpio.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.21 src/sys/dev/gpio/gpio.c:1.22
--- src/sys/dev/gpio/gpio.c:1.21	Sat Jul 25 19:01:55 2009
+++ src/sys/dev/gpio/gpio.c	Sat Jul 25 19:18:01 2009
@@ -1,4 +1,4 @@
-/* $NetBSD: gpio.c,v 1.21 2009/07/25 19:01:55 cegger Exp $ */
+/* $NetBSD: gpio.c,v 1.22 2009/07/25 19:18:01 cegger 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.21 2009/07/25 19:01:55 cegger Exp $);
+__KERNEL_RCSID(0, $NetBSD: gpio.c,v 1.22 2009/07/25 19:18:01 cegger Exp $);
 
 /*
  * General Purpose Input/Output framework.
@@ -309,14 +309,14 @@
 	sc = device_lookup_private(gpio_cd, minor(dev));
 	if (sc == NULL)
 		return ENXIO;
-	DPRINTF((%s: opening\n, sc-sc_dev-dv_xname));
+	DPRINTF((%s: opening\n, device_xname(sc-sc_dev)));
 	if (sc-sc_opened) {
-		DPRINTF((%s: already opened\n, sc-sc_dev-dv_xname));
+		DPRINTF((%s: already opened\n, device_xname(sc-sc_dev)));
 		return EBUSY;
 	}
 
 	if ((ret = gpiobus_open(sc-sc_gc, sc-sc_dev))) {
-		DPRINTF((%s: gpiobus_open returned %d\n, sc-sc_dev-dv_xname,
+		DPRINTF((%s: gpiobus_open returned %d\n, device_xname(sc-sc_dev),
 		ret));
 		return ret;
 	}
@@ -333,7 +333,7 @@
 	struct gpio_softc *sc;
 
 	sc = device_lookup_private(gpio_cd, minor(dev));
-	DPRINTF((%s: closing\n, sc-sc_dev-dv_xname));
+	DPRINTF((%s: closing\n, device_xname(sc-sc_dev)));
 	gpiobus_close(sc-sc_gc, sc-sc_dev);
 	sc-sc_opened = 0;
 
@@ -373,7 +373,7 @@
 	gc = sc-sc_gc;
 
 	if (cmd != GPIOINFO  !device_is_active(sc-sc_dev)) {
-		DPRINTF((%s: device is not active\n, sc-sc_dev-dv_xname));
+		DPRINTF((%s: device is not active\n, device_xname(sc-sc_dev)));
 		return EBUSY;
 	}
 	
@@ -490,7 +490,7 @@
 		ga.ga_offset = attach-ga_offset;
 		ga.ga_mask = attach-ga_mask;
 		DPRINTF((%s: attach %s with offset %d and mask 0x%02x\n,
-		sc-sc_dev-dv_xname, ga.ga_dvname, ga.ga_offset,
+		device_xname(sc-sc_dev), ga.ga_dvname, ga.ga_offset,
 		ga.ga_mask));
 
 		locs[GPIOCF_OFFSET] = ga.ga_offset;
@@ -512,7 +512,7 @@
 
 		attach = (struct gpio_attach *)data;
 		LIST_FOREACH(gdev, sc-sc_devs, sc_next) {
-			if (strcmp(gdev-sc_dev-dv_xname, attach-ga_dvname)
+			if (strcmp(device_xname(gdev-sc_dev), attach-ga_dvname)
 			== 0) {
 if (config_detach(gdev-sc_dev, 0) == 0) {
 	LIST_REMOVE(gdev, sc_next);
@@ -607,7 +607,7 @@
 		break;
 	default:
 		/* Try the old API */
-		DPRINTF((%s: trying the old API\n, sc-sc_dev-dv_xname));
+		DPRINTF((%s: trying the old API\n, device_xname(sc-sc_dev)));
 		return gpio_ioctl_oapi(sc, cmd, data, flag, cred);
 	}
 	return 0;