Module Name:    src
Committed By:   hkenken
Date:           Tue May  6 11:08:51 UTC 2014

Modified Files:
        src/sys/arch/evbarm/conf: NETWALKER files.netwalker
        src/sys/arch/evbarm/netwalker: netwalker.h netwalker_btn.c
Added Files:
        src/sys/arch/evbarm/netwalker: netwalker_lid.c netwalker_pwr.c

Log Message:
Imported pwrbtn and lidsw drivers for NetWalker. Those attached to GPIO bus.
+ power button
+ lid close switch


To generate a diff of this commit:
cvs rdiff -u -r1.25 -r1.26 src/sys/arch/evbarm/conf/NETWALKER
cvs rdiff -u -r1.5 -r1.6 src/sys/arch/evbarm/conf/files.netwalker
cvs rdiff -u -r1.1 -r1.2 src/sys/arch/evbarm/netwalker/netwalker.h \
    src/sys/arch/evbarm/netwalker/netwalker_btn.c
cvs rdiff -u -r0 -r1.1 src/sys/arch/evbarm/netwalker/netwalker_lid.c \
    src/sys/arch/evbarm/netwalker/netwalker_pwr.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/arch/evbarm/conf/NETWALKER
diff -u src/sys/arch/evbarm/conf/NETWALKER:1.25 src/sys/arch/evbarm/conf/NETWALKER:1.26
--- src/sys/arch/evbarm/conf/NETWALKER:1.25	Sat Mar 29 12:00:27 2014
+++ src/sys/arch/evbarm/conf/NETWALKER	Tue May  6 11:08:51 2014
@@ -1,4 +1,4 @@
-#	$NetBSD: NETWALKER,v 1.25 2014/03/29 12:00:27 hkenken Exp $
+#	$NetBSD: NETWALKER,v 1.26 2014/05/06 11:08:51 hkenken Exp $
 #
 #	NETWALKER -- http://www.sharp.co.jp/netwalker/
 #
@@ -149,6 +149,17 @@ makeoptions	DEBUG="-g"	# compile full sy
 #options	SCSIPI_DEBUG_TARGET=0
 #options	SCSIPI_DEBUG_LUN=0
 
+# Valid options for BOOT_ARGS:
+#  single		Boot to single user only
+#  kdb			Give control to kernel debugger
+#  ask			Ask for file name to reboot from
+#  pmapdebug=<n>	If PMAP_DEBUG, set pmap_debug_level to <n>
+#  memorydisk=<n>	Set memorydisk size to <n> KB
+#  quiet		Show aprint_naive output
+#  verbose		Show aprint_normal and aprint_verbose output
+#options		BOOT_ARGS="\"verbose\""
+#options		BOOT_ARGS="\"pmapdebug=1\""
+
 # Kernel root file system and dump configuration.
 config		netbsd		root on ? type ?
 config		netbsd-ld0	root on ld0 type ffs
@@ -214,14 +225,18 @@ options		IMXSPINSLAVES=3
 #options	IMXSPI_DEBUG=10
 
 # Optical Joystick
-mousebtn0	at gpio1 offset 22 mask 0x03 # intr 182, 183
-#options	MOUSEBTN_POLLING
 oj6sh0		at spi0 slave 2
 #options	OJ6SH_DEBUG=4
 options		OJ6SH_UP_X_LEFT_Y
 wsmouse*	at oj6sh? mux 0
+
+mousebtn0	at gpio1 offset 22 mask 0x03 # intr 182, 183
+#options	MOUSEBTN_POLLING
 wsmouse*	at mousebtn? mux 0
 
+pwrbtn0		at gpio1 offset 21 mask 0x01 # intr 181
+lidsw0		at gpio3 offset 12 mask 0x01 # intr 236
+
 # SPI NOR-Flash
 #spiflash0	at spiflashbus?
 #m25p0		at spi0 slave 1

Index: src/sys/arch/evbarm/conf/files.netwalker
diff -u src/sys/arch/evbarm/conf/files.netwalker:1.5 src/sys/arch/evbarm/conf/files.netwalker:1.6
--- src/sys/arch/evbarm/conf/files.netwalker:1.5	Sat Mar 29 12:00:27 2014
+++ src/sys/arch/evbarm/conf/files.netwalker	Tue May  6 11:08:51 2014
@@ -1,4 +1,4 @@
-#	$NetBSD: files.netwalker,v 1.5 2014/03/29 12:00:27 hkenken Exp $
+#	$NetBSD: files.netwalker,v 1.6 2014/05/06 11:08:51 hkenken Exp $
 #
 # Sharp Netwalker configuration info
 #
@@ -30,10 +30,20 @@ file	arch/evbarm/netwalker/netwalker_spi
 
 # Mouse button
 device	mousebtn: wsmousedev
-attach	mousebtn at gpio with btn_netwalker
-file	arch/evbarm/netwalker/netwalker_btn.c	btn_netwalker
+attach	mousebtn at gpio with netwalker_btn
+file	arch/evbarm/netwalker/netwalker_btn.c	netwalker_btn
 defflag	opt_mousebtn.h				MOUSEBTN_POLLING
 
+# Power button
+device	pwrbtn: sysmon_envsys
+attach	pwrbtn at gpio with netwalker_pwr
+file	arch/evbarm/netwalker/netwalker_pwr.c	netwalker_pwr
+
+# Lid close switch
+device	lidsw: sysmon_envsys
+attach	lidsw at gpio with netwalker_lid
+file	arch/evbarm/netwalker/netwalker_lid.c	netwalker_lid
+
 # OJ6SH-T25 Optical Joystick
 device  oj6sh: wsmousedev
 attach  oj6sh at spi

Index: src/sys/arch/evbarm/netwalker/netwalker.h
diff -u src/sys/arch/evbarm/netwalker/netwalker.h:1.1 src/sys/arch/evbarm/netwalker/netwalker.h:1.2
--- src/sys/arch/evbarm/netwalker/netwalker.h:1.1	Wed Apr  9 04:00:50 2014
+++ src/sys/arch/evbarm/netwalker/netwalker.h	Tue May  6 11:08:51 2014
@@ -1,4 +1,4 @@
-/*	$NetBSD: netwalker.h,v 1.1 2014/04/09 04:00:50 hkenken Exp $	*/
+/*	$NetBSD: netwalker.h,v 1.2 2014/05/06 11:08:51 hkenken Exp $	*/
 
 /*
  * Copyright (c) 2014  Genetec Corporation.  All rights reserved.
@@ -35,4 +35,9 @@
 #define KERNEL_VM_BASE		0xc0000000
 #define KERNEL_VM_SIZE		0x20000000
 
+#define GPIO0_IRQBASE		128
+#define GPIO1_IRQBASE		160
+#define GPIO2_IRQBASE		192
+#define GPIO3_IRQBASE		224
+
 #endif /* _EVBARM_NETWALKER_NETWALKER_H */
Index: src/sys/arch/evbarm/netwalker/netwalker_btn.c
diff -u src/sys/arch/evbarm/netwalker/netwalker_btn.c:1.1 src/sys/arch/evbarm/netwalker/netwalker_btn.c:1.2
--- src/sys/arch/evbarm/netwalker/netwalker_btn.c:1.1	Sat Mar 29 12:00:27 2014
+++ src/sys/arch/evbarm/netwalker/netwalker_btn.c	Tue May  6 11:08:51 2014
@@ -1,4 +1,4 @@
-/*	$NetBSD: netwalker_btn.c,v 1.1 2014/03/29 12:00:27 hkenken Exp $	*/
+/*	$NetBSD: netwalker_btn.c,v 1.2 2014/05/06 11:08:51 hkenken Exp $	*/
 
 /*
  * Copyright (c) 2014  Genetec Corporation.  All rights reserved.
@@ -27,7 +27,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: netwalker_btn.c,v 1.1 2014/03/29 12:00:27 hkenken Exp $");
+__KERNEL_RCSID(0, "$NetBSD: netwalker_btn.c,v 1.2 2014/05/06 11:08:51 hkenken Exp $");
 
 #include "opt_imxspi.h"
 #include "opt_mousebtn.h"
@@ -77,8 +77,8 @@ static int mousebtn_match(device_t, cfda
 static void mousebtn_attach(device_t, device_t, void *);
 static int mousebtn_detach(device_t, int);
 
-CFATTACH_DECL_NEW(btn_netwalker, sizeof(struct mousebtn_softc),
-	mousebtn_match, mousebtn_attach, mousebtn_detach, NULL);
+CFATTACH_DECL_NEW(netwalker_btn, sizeof(struct mousebtn_softc),
+    mousebtn_match, mousebtn_attach, mousebtn_detach, NULL);
 
 static void mousebtn_poll(void *);
 static int mousebtn_intr(void *);

Added files:

Index: src/sys/arch/evbarm/netwalker/netwalker_lid.c
diff -u /dev/null src/sys/arch/evbarm/netwalker/netwalker_lid.c:1.1
--- /dev/null	Tue May  6 11:08:51 2014
+++ src/sys/arch/evbarm/netwalker/netwalker_lid.c	Tue May  6 11:08:51 2014
@@ -0,0 +1,181 @@
+/*	$NetBSD: netwalker_lid.c,v 1.1 2014/05/06 11:08:51 hkenken Exp $	*/
+
+/*
+ * Copyright (c) 2014  Genetec Corporation.  All rights reserved.
+ * Written by Hashimoto Kenichi for Genetec Corporation.
+ *
+ * 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 GENETEC CORPORATION ``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 GENETEC CORPORATION
+ * 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 <sys/cdefs.h>
+__KERNEL_RCSID(0, "$NetBSD: netwalker_lid.c,v 1.1 2014/05/06 11:08:51 hkenken Exp $");
+
+#include <sys/param.h>
+#include <sys/systm.h>
+#include <sys/device.h>
+#include <sys/gpio.h>
+
+#include <dev/gpio/gpiovar.h>
+#include <dev/sysmon/sysmonvar.h>
+#include <dev/sysmon/sysmon_taskq.h>
+
+#include <dev/gpio/gpiovar.h>
+
+#include <evbarm/netwalker/netwalker.h>
+
+#define LID_PIN_INPUT	0
+#define LID_NPINS	1
+
+struct netwalker_lid_softc {
+	device_t sc_dev;
+	void *sc_gpio;
+	void *sc_intr;
+
+	struct gpio_pinmap sc_map;
+	int sc_map_pins[LID_NPINS];
+
+	struct sysmon_pswitch sc_smpsw;
+	int sc_state;
+};
+
+static int netwalker_lid_match(device_t, cfdata_t, void *);
+static void netwalker_lid_attach(device_t, device_t, void *);
+static int netwalker_lid_detach(device_t, int);
+
+CFATTACH_DECL_NEW(netwalker_lid, sizeof(struct netwalker_lid_softc),
+    netwalker_lid_match, netwalker_lid_attach, netwalker_lid_detach, NULL);
+
+static void netwalker_lid_refresh(void *);
+static int netwalker_lid_intr(void *);
+
+
+static int
+netwalker_lid_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 that we have enough pins */
+	if (gpio_npins(ga->ga_mask) != LID_NPINS) {
+		aprint_debug("%s: invalid pin mask 0x%02x\n", cf->cf_name,
+		    ga->ga_mask);
+		return 0;
+	}
+
+	return 1;
+}
+
+static void
+netwalker_lid_attach(device_t parent, device_t self, void *aux)
+{
+	struct netwalker_lid_softc *sc = device_private(self);
+	struct gpio_attach_args *ga = aux;
+	int caps;
+
+	sc->sc_dev = self;
+	sc->sc_gpio = ga->ga_gpio;
+
+	/* map pins */
+	sc->sc_map.pm_map = sc->sc_map_pins;
+	if (gpio_pin_map(sc->sc_gpio, ga->ga_offset, ga->ga_mask, &sc->sc_map)) {
+		aprint_error(": couldn't map the pins\n");
+		return;
+	}
+
+	/* configure the input pin */
+	caps = gpio_pin_caps(sc->sc_gpio, &sc->sc_map, LID_PIN_INPUT);
+	if (!(caps & GPIO_PIN_INPUT)) {
+		aprint_error(": pin is unable to read input\n");
+		gpio_pin_unmap(sc->sc_gpio, &sc->sc_map);
+		return;
+	}
+	gpio_pin_ctl(sc->sc_gpio, &sc->sc_map, LID_PIN_INPUT,
+	    GPIO_PIN_INPUT);
+
+	sc->sc_intr = intr_establish(GPIO3_IRQBASE + ga->ga_offset,
+	    IPL_VM, IST_EDGE_BOTH, netwalker_lid_intr, sc);
+	if (sc->sc_intr == NULL) {
+		aprint_error(": couldn't establish interrupt\n");
+		gpio_pin_unmap(sc->sc_gpio, &sc->sc_map);
+		return;
+	}
+
+	aprint_normal(": NETWALKER lid switch\n");
+	aprint_naive(": NETWALKER lid switch\n");
+
+	if (!pmf_device_register(sc->sc_dev, NULL, NULL)) {
+		aprint_error_dev(sc->sc_dev,
+		    "couldn't establish lid handler\n");
+	}
+
+	sysmon_task_queue_init();
+	sc->sc_smpsw.smpsw_name = device_xname(self);
+	sc->sc_smpsw.smpsw_type = PSWITCH_TYPE_LID;
+	sc->sc_state = PSWITCH_EVENT_RELEASED;
+	sysmon_pswitch_register(&sc->sc_smpsw);
+}
+
+static int
+netwalker_lid_detach(device_t self, int flags)
+{
+	struct netwalker_lid_softc *sc = device_private(self);
+
+	if (sc->sc_intr != NULL)
+		intr_disestablish(sc->sc_intr);
+
+	gpio_pin_unmap(sc->sc_gpio, &sc->sc_map);
+	pmf_device_deregister(self);
+	sysmon_task_queue_fini();
+	return 0;
+}
+
+static int
+netwalker_lid_intr(void *v)
+{
+	struct netwalker_lid_softc *sc = v;
+
+	sysmon_task_queue_sched(0, netwalker_lid_refresh, sc);
+	return 1;
+}
+
+static void
+netwalker_lid_refresh(void *v)
+{
+	struct netwalker_lid_softc *sc = v;
+	int lid;
+	int event;
+
+	lid = gpio_pin_read(sc->sc_gpio, &sc->sc_map, LID_PIN_INPUT);
+	event = (lid == GPIO_PIN_HIGH) ?
+	    PSWITCH_EVENT_RELEASED : PSWITCH_EVENT_PRESSED;
+
+	/* crude way to avoid duplicate events */
+	if(event == sc->sc_state)
+		return;
+
+	sc->sc_state = event;
+	/* report the event */
+	sysmon_pswitch_event(&sc->sc_smpsw, event);
+}
Index: src/sys/arch/evbarm/netwalker/netwalker_pwr.c
diff -u /dev/null src/sys/arch/evbarm/netwalker/netwalker_pwr.c:1.1
--- /dev/null	Tue May  6 11:08:51 2014
+++ src/sys/arch/evbarm/netwalker/netwalker_pwr.c	Tue May  6 11:08:51 2014
@@ -0,0 +1,183 @@
+/*	$NetBSD: netwalker_pwr.c,v 1.1 2014/05/06 11:08:51 hkenken Exp $	*/
+
+/*
+ * Copyright (c) 2014  Genetec Corporation.  All rights reserved.
+ * Written by Hashimoto Kenichi for Genetec Corporation.
+ *
+ * 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 GENETEC CORPORATION ``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 GENETEC CORPORATION
+ * 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 <sys/cdefs.h>
+__KERNEL_RCSID(0, "$NetBSD: netwalker_pwr.c,v 1.1 2014/05/06 11:08:51 hkenken Exp $");
+
+#include <sys/param.h>
+#include <sys/systm.h>
+#include <sys/device.h>
+#include <sys/gpio.h>
+
+#include <dev/gpio/gpiovar.h>
+#include <dev/sysmon/sysmonvar.h>
+#include <dev/sysmon/sysmon_taskq.h>
+
+#include <dev/gpio/gpiovar.h>
+
+#include <evbarm/netwalker/netwalker.h>
+
+#define PWR_PIN_INPUT	0
+#define PWR_NPINS	1
+
+
+struct netwalker_pwr_softc {
+	device_t sc_dev;
+	void *sc_gpio;
+	void *sc_intr;
+
+	struct gpio_pinmap sc_map;
+	int sc_map_pins[PWR_NPINS];
+
+	struct sysmon_pswitch sc_smpsw;
+	int sc_state;
+};
+
+static int netwalker_pwr_match(device_t, cfdata_t, void *);
+static void netwalker_pwr_attach(device_t, device_t, void *);
+static int netwalker_pwr_detach(device_t, int);
+
+CFATTACH_DECL_NEW(netwalker_pwr, sizeof(struct netwalker_pwr_softc),
+    netwalker_pwr_match, netwalker_pwr_attach, netwalker_pwr_detach, NULL);
+
+static void netwalker_pwr_refresh(void *);
+static int netwalker_pwr_intr(void *);
+
+
+static int
+netwalker_pwr_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 that we have enough pins */
+	if (gpio_npins(ga->ga_mask) != PWR_NPINS) {
+		aprint_debug("%s: invalid pin mask 0x%02x\n", cf->cf_name,
+		    ga->ga_mask);
+		return 0;
+	}
+
+	return 1;
+}
+
+static void
+netwalker_pwr_attach(device_t parent, device_t self, void *aux)
+{
+	struct netwalker_pwr_softc *sc = device_private(self);
+	struct gpio_attach_args *ga = aux;
+	int caps;
+
+	sc->sc_dev = self;
+	sc->sc_gpio = ga->ga_gpio;
+
+	/* map pins */
+	sc->sc_map.pm_map = sc->sc_map_pins;
+	if (gpio_pin_map(sc->sc_gpio, ga->ga_offset, ga->ga_mask, &sc->sc_map)) {
+		aprint_error(": couldn't map the pins\n");
+		return;
+	}
+
+	/* configure the input pin */
+	caps = gpio_pin_caps(sc->sc_gpio, &sc->sc_map, PWR_PIN_INPUT);
+	if (!(caps & GPIO_PIN_INPUT)) {
+		aprint_error(": pin is unable to read input\n");
+		gpio_pin_unmap(sc->sc_gpio, &sc->sc_map);
+		return;
+	}
+	gpio_pin_ctl(sc->sc_gpio, &sc->sc_map, PWR_PIN_INPUT,
+	    GPIO_PIN_INPUT);
+
+	sc->sc_intr = intr_establish(GPIO1_IRQBASE + ga->ga_offset,
+	    IPL_VM, IST_EDGE_BOTH, netwalker_pwr_intr, sc);
+	if (sc->sc_intr == NULL) {
+		aprint_error(": couldn't establish interrupt\n");
+		gpio_pin_unmap(sc->sc_gpio, &sc->sc_map);
+		return;
+	}
+
+	aprint_normal(": NETWALKER power button\n");
+	aprint_naive(": NETWALKER power button\n");
+
+	if (!pmf_device_register(sc->sc_dev, NULL, NULL)) {
+		aprint_error_dev(sc->sc_dev,
+		    "couldn't establish power handler\n");
+	}
+
+	sysmon_task_queue_init();
+	sc->sc_smpsw.smpsw_name = device_xname(self);
+	sc->sc_smpsw.smpsw_type = PSWITCH_TYPE_POWER;
+	sc->sc_state = PSWITCH_EVENT_RELEASED;
+	sysmon_pswitch_register(&sc->sc_smpsw);
+}
+
+static int
+netwalker_pwr_detach(device_t self, int flags)
+{
+	struct netwalker_pwr_softc *sc = device_private(self);
+
+	if (sc->sc_intr != NULL)
+		intr_disestablish(sc->sc_intr);
+
+	gpio_pin_unmap(sc->sc_gpio, &sc->sc_map);
+	pmf_device_deregister(self);
+	sysmon_task_queue_fini();
+
+	return 0;
+}
+
+static int
+netwalker_pwr_intr(void *v)
+{
+	struct netwalker_pwr_softc *sc = v;
+
+	sysmon_task_queue_sched(0, netwalker_pwr_refresh, sc);
+	return 1;
+}
+
+static void
+netwalker_pwr_refresh(void *v)
+{
+	struct netwalker_pwr_softc *sc = v;
+	int pwr;
+	int event;
+
+	pwr = gpio_pin_read(sc->sc_gpio, &sc->sc_map, PWR_PIN_INPUT);
+	event = (pwr == GPIO_PIN_HIGH) ?
+	    PSWITCH_EVENT_RELEASED : PSWITCH_EVENT_PRESSED;
+
+	/* crude way to avoid duplicate events */
+	if(event == sc->sc_state)
+		return;
+
+	sc->sc_state = event;
+	/* report the event */
+	sysmon_pswitch_event(&sc->sc_smpsw, event);
+}

Reply via email to