Module Name: src Committed By: khorben Date: Sat Apr 20 03:37:56 UTC 2013
Modified Files: src/sys/arch/evbarm/conf: N900 files.n900 src/sys/arch/evbarm/n900: n900_acad.c n900_lckbtn.c Added Files: src/sys/arch/evbarm/n900: n900_cambtn.c n900_camcvr.c n900_kbdsld.c Log Message: Imported the n900cambtn(4), n900camcvr(4) and n900kbdsld(4) drivers for the Nokia N900, all attaching to the GPIO bus, respectively handling: - the camera button (focus and capture) - the camera cover slide; - the keypad slide. To generate a diff of this commit: cvs rdiff -u -r1.10 -r1.11 src/sys/arch/evbarm/conf/N900 cvs rdiff -u -r1.3 -r1.4 src/sys/arch/evbarm/conf/files.n900 cvs rdiff -u -r1.4 -r1.5 src/sys/arch/evbarm/n900/n900_acad.c cvs rdiff -u -r0 -r1.1 src/sys/arch/evbarm/n900/n900_cambtn.c \ src/sys/arch/evbarm/n900/n900_camcvr.c \ src/sys/arch/evbarm/n900/n900_kbdsld.c cvs rdiff -u -r1.2 -r1.3 src/sys/arch/evbarm/n900/n900_lckbtn.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/N900 diff -u src/sys/arch/evbarm/conf/N900:1.10 src/sys/arch/evbarm/conf/N900:1.11 --- src/sys/arch/evbarm/conf/N900:1.10 Wed Apr 17 01:06:13 2013 +++ src/sys/arch/evbarm/conf/N900 Sat Apr 20 03:37:55 2013 @@ -1,5 +1,5 @@ # -# $NetBSD: N900,v 1.10 2013/04/17 01:06:13 khorben Exp $ +# $NetBSD: N900,v 1.11 2013/04/20 03:37:55 khorben Exp $ # # N900 -- Nokia N900 Kernel # @@ -217,6 +217,15 @@ gpio* at omapgpio? # Charging sensor n900acad0 at gpio0 offset 7 mask 0x1 #intr 103 +# Camera button +n900cambtn0 at gpio2 offset 4 mask 0x3 #intr 164, 165 + +# Keyboard slide +n900kbdsld0 at gpio2 offset 7 mask 0x1 #intr 167 + +# Camera cover +n900camcvr0 at gpio3 offset 14 mask 0x1 #intr 206 + # Lock button n900lckbtn0 at gpio3 offset 17 mask 0x1 #intr 209 @@ -229,7 +238,8 @@ omapiic1 at obio0 addr 0x48072000 size 0 omapiic2 at obio0 addr 0x48060000 size 0x80 iic* at omapiic? -# Power Managent and System Companion Device +# I2C devices +# Power Management and System Companion Device tps65950pm0 at iic0 addr 0x48 tps65950pm1 at iic0 addr 0x49 tps65950pm2 at iic0 addr 0x4a Index: src/sys/arch/evbarm/conf/files.n900 diff -u src/sys/arch/evbarm/conf/files.n900:1.3 src/sys/arch/evbarm/conf/files.n900:1.4 --- src/sys/arch/evbarm/conf/files.n900:1.3 Wed Apr 17 01:06:14 2013 +++ src/sys/arch/evbarm/conf/files.n900 Sat Apr 20 03:37:55 2013 @@ -1,4 +1,4 @@ -# $NetBSD: files.n900,v 1.3 2013/04/17 01:06:14 khorben Exp $ +# $NetBSD: files.n900,v 1.4 2013/04/20 03:37:55 khorben Exp $ # # Nokia N900 configuration info # @@ -20,11 +20,26 @@ attach com at obio with obiouart file arch/arm/omap/obio_com.c obiouart defparam opt_com.h CONSADDR CONSPEED CONMODE +# Camera button +device n900cambtn: sysmon_envsys +attach n900cambtn at gpio with n900cambtn +file arch/evbarm/n900/n900_cambtn.c n900cambtn + +# Camera cover +device n900camcvr: sysmon_envsys +attach n900camcvr at gpio with n900camcvr +file arch/evbarm/n900/n900_camcvr.c n900camcvr + # Charging sensor device n900acad: sysmon_envsys attach n900acad at gpio with n900acad file arch/evbarm/n900/n900_acad.c n900acad +# Keyboard slide +device n900kbdsld: sysmon_envsys +attach n900kbdsld at gpio with n900kbdsld +file arch/evbarm/n900/n900_kbdsld.c n900kbdsld + # Lock button device n900lckbtn: sysmon_envsys attach n900lckbtn at gpio with n900lckbtn Index: src/sys/arch/evbarm/n900/n900_acad.c diff -u src/sys/arch/evbarm/n900/n900_acad.c:1.4 src/sys/arch/evbarm/n900/n900_acad.c:1.5 --- src/sys/arch/evbarm/n900/n900_acad.c:1.4 Thu Apr 18 02:08:11 2013 +++ src/sys/arch/evbarm/n900/n900_acad.c Sat Apr 20 03:37:55 2013 @@ -1,4 +1,4 @@ -/* $NetBSD: n900_acad.c,v 1.4 2013/04/18 02:08:11 khorben Exp $ */ +/* $NetBSD: n900_acad.c,v 1.5 2013/04/20 03:37:55 khorben Exp $ */ /* * AC adapter driver for the Nokia N900. @@ -32,7 +32,7 @@ */ #include <sys/cdefs.h> -__KERNEL_RCSID(0, "$NetBSD: n900_acad.c,v 1.4 2013/04/18 02:08:11 khorben Exp $"); +__KERNEL_RCSID(0, "$NetBSD: n900_acad.c,v 1.5 2013/04/20 03:37:55 khorben Exp $"); #include <sys/param.h> #include <sys/systm.h> @@ -113,7 +113,7 @@ n900acad_attach(device_t parent, device_ 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(": could not map the pins\n"); + aprint_error(": couldn't map the pins\n"); return; } @@ -130,7 +130,7 @@ n900acad_attach(device_t parent, device_ sc->sc_intr = intr_establish(N900ACAD_GPIO_BASE + ga->ga_offset, IPL_VM, IST_EDGE_RISING, n900acad_intr, sc); if (sc->sc_intr == NULL) { - aprint_error(": could not establish interrupt\n"); + aprint_error(": couldn't establish interrupt\n"); gpio_pin_unmap(sc->sc_gpio, &sc->sc_map); return; } @@ -140,7 +140,7 @@ n900acad_attach(device_t parent, device_ if (!pmf_device_register(sc->sc_dev, NULL, NULL)) { aprint_error_dev(sc->sc_dev, - "could not establish power handler\n"); + "couldn't establish power handler\n"); } sc->sc_smpsw.smpsw_name = device_xname(self); Index: src/sys/arch/evbarm/n900/n900_lckbtn.c diff -u src/sys/arch/evbarm/n900/n900_lckbtn.c:1.2 src/sys/arch/evbarm/n900/n900_lckbtn.c:1.3 --- src/sys/arch/evbarm/n900/n900_lckbtn.c:1.2 Thu Apr 18 02:08:11 2013 +++ src/sys/arch/evbarm/n900/n900_lckbtn.c Sat Apr 20 03:37:55 2013 @@ -1,4 +1,4 @@ -/* $NetBSD: n900_lckbtn.c,v 1.2 2013/04/18 02:08:11 khorben Exp $ */ +/* $NetBSD: n900_lckbtn.c,v 1.3 2013/04/20 03:37:55 khorben Exp $ */ /* * Lock button driver for the Nokia N900. @@ -32,7 +32,7 @@ */ #include <sys/cdefs.h> -__KERNEL_RCSID(0, "$NetBSD: n900_lckbtn.c,v 1.2 2013/04/18 02:08:11 khorben Exp $"); +__KERNEL_RCSID(0, "$NetBSD: n900_lckbtn.c,v 1.3 2013/04/20 03:37:55 khorben Exp $"); #include <sys/param.h> #include <sys/systm.h> @@ -64,7 +64,7 @@ struct n900lckbtn_softc int sc_map_pins[N900LCKBTN_NPINS]; struct sysmon_pswitch sc_smpsw; - int sc_event; + int sc_state; }; static int n900lckbtn_match(device_t, cfdata_t, void *); @@ -114,7 +114,7 @@ n900lckbtn_attach(device_t parent, devic 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(": could not map the pins\n"); + aprint_error(": couldn't map the pins\n"); return; } @@ -131,7 +131,7 @@ n900lckbtn_attach(device_t parent, devic sc->sc_intr = intr_establish(N900LCKBTN_GPIO_BASE + ga->ga_offset, IPL_VM, IST_EDGE_BOTH, n900lckbtn_intr, sc); if (sc->sc_intr == NULL) { - aprint_error(": could not establish interrupt\n"); + aprint_error(": couldn't establish interrupt\n"); gpio_pin_unmap(sc->sc_gpio, &sc->sc_map); return; } @@ -141,12 +141,12 @@ n900lckbtn_attach(device_t parent, devic if (!pmf_device_register(sc->sc_dev, NULL, NULL)) { aprint_error_dev(sc->sc_dev, - "could not establish power handler\n"); + "couldn't establish power handler\n"); } sc->sc_smpsw.smpsw_name = device_xname(self); sc->sc_smpsw.smpsw_type = PSWITCH_TYPE_HOTKEY; - sc->sc_event = PSWITCH_EVENT_RELEASED; + sc->sc_state = PSWITCH_EVENT_RELEASED; sysmon_pswitch_register(&sc->sc_smpsw); } @@ -185,9 +185,9 @@ n900lckbtn_refresh(struct n900lckbtn_sof ? PSWITCH_EVENT_RELEASED : PSWITCH_EVENT_PRESSED; /* crude way to avoid duplicate events */ - if(event == sc->sc_event) + if(event == sc->sc_state) return; - sc->sc_event = event; + sc->sc_state = event; /* report the event */ sysmon_pswitch_event(&sc->sc_smpsw, event); Added files: Index: src/sys/arch/evbarm/n900/n900_cambtn.c diff -u /dev/null src/sys/arch/evbarm/n900/n900_cambtn.c:1.1 --- /dev/null Sat Apr 20 03:37:56 2013 +++ src/sys/arch/evbarm/n900/n900_cambtn.c Sat Apr 20 03:37:55 2013 @@ -0,0 +1,225 @@ +/* $NetBSD: n900_cambtn.c,v 1.1 2013/04/20 03:37:55 khorben Exp $ */ + +/* + * Camera button driver for the Nokia N900. + * + * Copyright (c) 2013 The NetBSD Foundation, Inc. + * All rights reserved. + * + * This code is derived from software contributed to The NetBSD Foundation + * by Pierre Pronchery (khor...@defora.org). + * + * 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 NETBSD FOUNDATION, INC. AND CONTRIBUTORS + * ``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 FOUNDATION OR CONTRIBUTORS + * 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: n900_cambtn.c,v 1.1 2013/04/20 03:37:55 khorben Exp $"); + +#include <sys/param.h> +#include <sys/systm.h> +#include <sys/device.h> +#include <sys/gpio.h> +#include <sys/kmem.h> + +#include <dev/gpio/gpiovar.h> +#include <dev/sysmon/sysmonvar.h> + +#include <arm/omap/omap2_gpio.h> + + +/* The base interrupt for the corresponding GPIO device where this driver + * attaches. This is an ugly workaround the current limitations of gpio(4), + * which does not seem to allow a better way to locate the interrupt yet. */ +#define N900CAMBTN_GPIO_BASE 160 + +#define N900CAMBTN_PIN_FOCUS 0 +#define N900CAMBTN_PIN_CAPTURE 1 +#define N900CAMBTN_NPINS 2 + + +struct n900cambtn_softc +{ + device_t sc_dev; + void * sc_gpio; + void * sc_intr[N900CAMBTN_NPINS]; + + struct gpio_pinmap sc_map; + int sc_map_pins[N900CAMBTN_NPINS]; + + struct sysmon_pswitch sc_smpsw[N900CAMBTN_NPINS]; + int sc_state[N900CAMBTN_NPINS]; +}; + +static int n900cambtn_match(device_t, cfdata_t, void *); +static void n900cambtn_attach(device_t, device_t, void *); +static int n900cambtn_detach(device_t, int); + +CFATTACH_DECL_NEW(n900cambtn, sizeof(struct n900cambtn_softc), + n900cambtn_match, n900cambtn_attach, n900cambtn_detach, NULL); + +static void n900cambtn_refresh_pin(struct n900cambtn_softc *, int); + +static int n900cambtn_intr(void *v); + + +static int +n900cambtn_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) != N900CAMBTN_NPINS) { + aprint_debug("%s: invalid pin mask 0x%02x\n", cf->cf_name, + ga->ga_mask); + return 0; + } + + return 1; +} + +static void +n900cambtn_attach(device_t parent, device_t self, void *aux) +{ + struct n900cambtn_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 capture pin */ + caps = gpio_pin_caps(sc->sc_gpio, &sc->sc_map, N900CAMBTN_PIN_CAPTURE); + 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, N900CAMBTN_PIN_CAPTURE, + GPIO_PIN_INPUT); + + /* configure the focus pin */ + caps = gpio_pin_caps(sc->sc_gpio, &sc->sc_map, N900CAMBTN_PIN_FOCUS); + 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, N900CAMBTN_PIN_FOCUS, + GPIO_PIN_INPUT); + + sc->sc_intr[0] = intr_establish(N900CAMBTN_GPIO_BASE + ga->ga_offset, + IPL_VM, IST_EDGE_BOTH, n900cambtn_intr, sc); + if (sc->sc_intr[0] == NULL) { + aprint_error(": couldn't establish interrupt\n"); + return; + } + + sc->sc_intr[1] = intr_establish(N900CAMBTN_GPIO_BASE + ga->ga_offset + + 1, IPL_VM, IST_EDGE_BOTH, n900cambtn_intr, sc); + if (sc->sc_intr[1] == NULL) { + aprint_error(": couldn't establish interrupt\n"); + intr_disestablish(sc->sc_intr[0]); + return; + } + + aprint_normal(": N900 camera button\n"); + aprint_naive(": N900 camera button\n"); + + if (!pmf_device_register(sc->sc_dev, NULL, NULL)) { + aprint_error_dev(sc->sc_dev, + "couldn't establish power handler\n"); + } + + /* focus button */ + sc->sc_smpsw[0].smpsw_name = kmem_asprintf("%s%s", device_xname(self), + "focus"); + sc->sc_smpsw[0].smpsw_type = PSWITCH_TYPE_HOTKEY; + sc->sc_state[0] = PSWITCH_EVENT_RELEASED; + sysmon_pswitch_register(&sc->sc_smpsw[0]); + + /* capture button */ + sc->sc_smpsw[1].smpsw_name = kmem_asprintf("%s%s", device_xname(self), + "capture"); + sc->sc_smpsw[1].smpsw_type = PSWITCH_TYPE_HOTKEY; + sc->sc_state[1] = PSWITCH_EVENT_RELEASED; + sysmon_pswitch_register(&sc->sc_smpsw[1]); +} + +static int +n900cambtn_detach(device_t self, int flags) +{ + struct n900cambtn_softc *sc = device_private(self); + + if (sc->sc_intr[0] != NULL) { + intr_disestablish(sc->sc_intr[0]); + } + + if (sc->sc_intr[1] != NULL) { + intr_disestablish(sc->sc_intr[1]); + } + + gpio_pin_unmap(sc->sc_gpio, &sc->sc_map); + pmf_device_deregister(self); + + return 0; +} + +static int +n900cambtn_intr(void *v) +{ + struct n900cambtn_softc *sc = v; + + n900cambtn_refresh_pin(sc, N900CAMBTN_PIN_CAPTURE); + n900cambtn_refresh_pin(sc, N900CAMBTN_PIN_FOCUS); + return 1; +} + +static void +n900cambtn_refresh_pin(struct n900cambtn_softc *sc, int pin) +{ + int i; + int event; + + i = gpio_pin_read(sc->sc_gpio, &sc->sc_map, pin); + event = (i == GPIO_PIN_HIGH) + ? PSWITCH_EVENT_RELEASED : PSWITCH_EVENT_PRESSED; + + /* report the event if relevant */ + if(sc->sc_state[pin] != event) { + sysmon_pswitch_event(&sc->sc_smpsw[pin], event); + sc->sc_state[pin] = event; + } +} Index: src/sys/arch/evbarm/n900/n900_camcvr.c diff -u /dev/null src/sys/arch/evbarm/n900/n900_camcvr.c:1.1 --- /dev/null Sat Apr 20 03:37:56 2013 +++ src/sys/arch/evbarm/n900/n900_camcvr.c Sat Apr 20 03:37:55 2013 @@ -0,0 +1,190 @@ +/* $NetBSD: n900_camcvr.c,v 1.1 2013/04/20 03:37:55 khorben Exp $ */ + +/* + * Camera cover driver for the Nokia N900. + * + * Copyright (c) 2013 The NetBSD Foundation, Inc. + * All rights reserved. + * + * This code is derived from software contributed to The NetBSD Foundation + * by Pierre Pronchery (khor...@defora.org). + * + * 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 NETBSD FOUNDATION, INC. AND CONTRIBUTORS + * ``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 FOUNDATION OR CONTRIBUTORS + * 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: n900_camcvr.c,v 1.1 2013/04/20 03:37:55 khorben 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 <arm/omap/omap2_gpio.h> + + +/* The base interrupt for the corresponding GPIO device where this driver + * attaches. This is an ugly workaround the current limitations of gpio(4), + * which does not seem to allow a better way to locate the interrupt yet. */ +#define N900CAMCVR_GPIO_BASE 192 + +#define N900CAMCVR_PIN_INPUT 0 +#define N900CAMCVR_NPINS 1 + + +struct n900camcvr_softc +{ + device_t sc_dev; + void * sc_gpio; + void * sc_intr; + + struct gpio_pinmap sc_map; + int sc_map_pins[N900CAMCVR_NPINS]; + + struct sysmon_pswitch sc_smpsw; +}; + +static int n900camcvr_match(device_t, cfdata_t, void *); +static void n900camcvr_attach(device_t, device_t, void *); +static int n900camcvr_detach(device_t, int); + +CFATTACH_DECL_NEW(n900camcvr, sizeof(struct n900camcvr_softc), + n900camcvr_match, n900camcvr_attach, n900camcvr_detach, NULL); + +static void n900camcvr_refresh(struct n900camcvr_softc *); + +static int n900camcvr_intr(void *v); + + +static int +n900camcvr_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) != N900CAMCVR_NPINS) { + aprint_debug("%s: invalid pin mask 0x%02x\n", cf->cf_name, + ga->ga_mask); + return 0; + } + + return 1; +} + +static void +n900camcvr_attach(device_t parent, device_t self, void *aux) +{ + struct n900camcvr_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, N900CAMCVR_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, N900CAMCVR_PIN_INPUT, + GPIO_PIN_INPUT); + + sc->sc_intr = intr_establish(N900CAMCVR_GPIO_BASE + ga->ga_offset, + IPL_VM, IST_EDGE_BOTH, n900camcvr_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(": N900 camera cover\n"); + aprint_naive(": N900 camera cover\n"); + + if (!pmf_device_register(sc->sc_dev, NULL, NULL)) { + aprint_error_dev(sc->sc_dev, + "couldn't establish power handler\n"); + } + + sc->sc_smpsw.smpsw_name = device_xname(self); + sc->sc_smpsw.smpsw_type = PSWITCH_TYPE_HOTKEY; + sysmon_pswitch_register(&sc->sc_smpsw); + + /* FIXME report an event only if opened instead */ + n900camcvr_refresh(sc); +} + +static int +n900camcvr_detach(device_t self, int flags) +{ + struct n900camcvr_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); + + return 0; +} + +static int +n900camcvr_intr(void *v) +{ + struct n900camcvr_softc *sc = v; + + n900camcvr_refresh(sc); + return 1; +} + +static void +n900camcvr_refresh(struct n900camcvr_softc *sc) +{ + int i; + int event; + + i = gpio_pin_read(sc->sc_gpio, &sc->sc_map, N900CAMCVR_PIN_INPUT); + event = (i == GPIO_PIN_HIGH) + ? PSWITCH_EVENT_RELEASED : PSWITCH_EVENT_PRESSED; + + /* report the event */ + sysmon_pswitch_event(&sc->sc_smpsw, event); +} Index: src/sys/arch/evbarm/n900/n900_kbdsld.c diff -u /dev/null src/sys/arch/evbarm/n900/n900_kbdsld.c:1.1 --- /dev/null Sat Apr 20 03:37:56 2013 +++ src/sys/arch/evbarm/n900/n900_kbdsld.c Sat Apr 20 03:37:55 2013 @@ -0,0 +1,189 @@ +/* $NetBSD: n900_kbdsld.c,v 1.1 2013/04/20 03:37:55 khorben Exp $ */ + +/* + * Keypad slide driver for the Nokia N900. + * + * Copyright (c) 2013 The NetBSD Foundation, Inc. + * All rights reserved. + * + * This code is derived from software contributed to The NetBSD Foundation + * by Pierre Pronchery (khor...@defora.org). + * + * 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 NETBSD FOUNDATION, INC. AND CONTRIBUTORS + * ``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 FOUNDATION OR CONTRIBUTORS + * 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: n900_kbdsld.c,v 1.1 2013/04/20 03:37:55 khorben 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 <arm/omap/omap2_gpio.h> + + +/* The base interrupt for the corresponding GPIO device where this driver + * attaches. This is an ugly workaround the current limitations of gpio(4), + * which does not seem to allow a better way to locate the interrupt yet. */ +#define N900KBDSLD_GPIO_BASE 160 + +#define N900KBDSLD_PIN_INPUT 0 +#define N900KBDSLD_NPINS 1 + + +struct n900kbdsld_softc +{ + device_t sc_dev; + void * sc_gpio; + void * sc_intr; + + struct gpio_pinmap sc_map; + int sc_map_pins[N900KBDSLD_NPINS]; + + struct sysmon_pswitch sc_smpsw; +}; + +static int n900kbdsld_match(device_t, cfdata_t, void *); +static void n900kbdsld_attach(device_t, device_t, void *); +static int n900kbdsld_detach(device_t, int); + +CFATTACH_DECL_NEW(n900kbdsld, sizeof(struct n900kbdsld_softc), + n900kbdsld_match, n900kbdsld_attach, n900kbdsld_detach, NULL); + +static void n900kbdsld_refresh(struct n900kbdsld_softc *); + +static int n900kbdsld_intr(void *v); + + +static int +n900kbdsld_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) != N900KBDSLD_NPINS) { + aprint_debug("%s: invalid pin mask 0x%02x\n", cf->cf_name, + ga->ga_mask); + return 0; + } + + return 1; +} + +static void +n900kbdsld_attach(device_t parent, device_t self, void *aux) +{ + struct n900kbdsld_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, N900KBDSLD_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, N900KBDSLD_PIN_INPUT, + GPIO_PIN_INPUT); + + sc->sc_intr = intr_establish(N900KBDSLD_GPIO_BASE + ga->ga_offset, + IPL_VM, IST_EDGE_BOTH, n900kbdsld_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(": N900 keypad slide\n"); + aprint_naive(": N900 keypad slide\n"); + + if (!pmf_device_register(sc->sc_dev, NULL, NULL)) { + aprint_error_dev(sc->sc_dev, + "couldn't establish power handler\n"); + } + + sc->sc_smpsw.smpsw_name = device_xname(self); + sc->sc_smpsw.smpsw_type = PSWITCH_TYPE_HOTKEY; + sysmon_pswitch_register(&sc->sc_smpsw); + + n900kbdsld_refresh(sc); +} + +static int +n900kbdsld_detach(device_t self, int flags) +{ + struct n900kbdsld_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); + + return 0; +} + +static int +n900kbdsld_intr(void *v) +{ + struct n900kbdsld_softc *sc = v; + + n900kbdsld_refresh(sc); + return 1; +} + +static void +n900kbdsld_refresh(struct n900kbdsld_softc *sc) +{ + int i; + int event; + + i = gpio_pin_read(sc->sc_gpio, &sc->sc_map, N900KBDSLD_PIN_INPUT); + event = (i == GPIO_PIN_HIGH) + ? PSWITCH_EVENT_PRESSED : PSWITCH_EVENT_RELEASED; + + /* report the event */ + sysmon_pswitch_event(&sc->sc_smpsw, event); +}