Home | History | Annotate | Line # | Download | only in tsarm
tskp.c revision 1.2.12.2
      1  1.2.12.2  yamt /* $NetBSD: tskp.c,v 1.2.12.2 2007/02/26 09:06:21 yamt Exp $ */
      2       1.1  joff 
      3       1.1  joff /*-
      4       1.1  joff  * Copyright (c) 2005 The NetBSD Foundation, Inc.
      5       1.1  joff  * All rights reserved.
      6       1.1  joff  *
      7       1.1  joff  * This code is from software contributed to The NetBSD Foundation
      8       1.1  joff  * by Jesse Off.
      9       1.1  joff  *
     10       1.1  joff  * Redistribution and use in source and binary forms, with or without
     11       1.1  joff  * modification, are permitted provided that the following conditions
     12       1.1  joff  * are met:
     13       1.1  joff  * 1. Redistributions of source code must retain the above copyright
     14       1.1  joff  *    notice, this list of conditions and the following disclaimer.
     15       1.1  joff  * 2. Redistributions in binary form must reproduce the above copyright
     16       1.1  joff  *    notice, this list of conditions and the following disclaimer in the
     17       1.1  joff  *    documentation and/or other materials provided with the distribution.
     18       1.1  joff  * 3. All advertising materials mentioning features or use of this software
     19       1.1  joff  *    must display the following acknowledgement:
     20       1.1  joff  *	This product includes software developed by the NetBSD
     21       1.1  joff  *	Foundation, Inc. and its contributors.
     22       1.1  joff  * 4. Neither the name of The NetBSD Foundation nor the names of its
     23       1.1  joff  *    contributors may be used to endorse or promote products derived
     24       1.1  joff  *    from this software without specific prior written permission.
     25       1.1  joff  *
     26       1.1  joff  * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
     27       1.1  joff  * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
     28       1.1  joff  * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
     29       1.1  joff  * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
     30       1.1  joff  * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
     31       1.1  joff  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
     32       1.1  joff  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
     33       1.1  joff  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
     34       1.1  joff  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
     35       1.1  joff  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
     36       1.1  joff  * POSSIBILITY OF SUCH DAMAGE.
     37       1.1  joff  */
     38       1.1  joff #include <sys/cdefs.h>
     39  1.2.12.2  yamt __KERNEL_RCSID(0, "$NetBSD: tskp.c,v 1.2.12.2 2007/02/26 09:06:21 yamt Exp $");
     40       1.1  joff 
     41       1.1  joff #include <sys/param.h>
     42       1.1  joff #include <sys/systm.h>
     43       1.1  joff #include <sys/proc.h>
     44       1.1  joff #include <sys/poll.h>
     45       1.1  joff #include <sys/conf.h>
     46       1.1  joff #include <sys/uio.h>
     47       1.1  joff #include <sys/types.h>
     48       1.1  joff #include <sys/kernel.h>
     49       1.1  joff #include <sys/device.h>
     50       1.1  joff #include <sys/callout.h>
     51       1.1  joff #include <sys/select.h>
     52       1.1  joff 
     53       1.1  joff #include <machine/bus.h>
     54       1.1  joff #include <machine/autoconf.h>
     55       1.1  joff 
     56       1.1  joff #include <dev/wscons/wsconsio.h>
     57       1.1  joff #include <dev/wscons/wskbdvar.h>
     58       1.1  joff #include <dev/wscons/wsksymdef.h>
     59       1.1  joff #include <dev/wscons/wsksymvar.h>
     60       1.1  joff 
     61       1.1  joff #include <arm/ep93xx/ep93xxreg.h>
     62  1.2.12.1  yamt #include <arm/ep93xx/epgpioreg.h>
     63       1.1  joff #include <dev/ic/matrixkpvar.h>
     64       1.1  joff #include <evbarm/tsarm/tspldvar.h>
     65       1.1  joff #include <evbarm/tsarm/tsarmreg.h>
     66       1.1  joff 
     67       1.1  joff struct tskp_softc {
     68       1.1  joff 	struct device sc_dev;
     69       1.1  joff 	struct matrixkp_softc sc_mxkp;
     70       1.1  joff 	bus_space_tag_t sc_iot;
     71       1.1  joff 	bus_space_handle_t sc_gpioh;
     72       1.1  joff };
     73       1.1  joff 
     74       1.1  joff #define KC(n) KS_KEYCODE(n)
     75       1.1  joff static const keysym_t mxkp_keydesc_default[] = {
     76       1.1  joff /*  pos				normal			shifted		*/
     77       1.2  joff 	KC(0), 			KS_1,
     78       1.2  joff 	KC(1), 			KS_2,
     79       1.2  joff 	KC(2), 			KS_3,
     80       1.2  joff 	KC(3), 			KS_A,
     81       1.2  joff 	KC(4), 			KS_4,
     82       1.2  joff 	KC(5), 			KS_5,
     83       1.2  joff 	KC(6), 			KS_6,
     84       1.2  joff 	KC(7), 			KS_B,
     85       1.2  joff 	KC(8), 			KS_7,
     86       1.2  joff 	KC(9),	 		KS_8,
     87       1.2  joff 	KC(10), 		KS_9,
     88       1.2  joff 	KC(11), 		KS_C,
     89       1.2  joff 	KC(12), 		KS_asterisk,
     90       1.2  joff 	KC(13), 		KS_0,
     91       1.2  joff 	KC(14), 		KS_numbersign,
     92       1.2  joff 	KC(15), 		KS_D,
     93       1.1  joff };
     94       1.1  joff #undef KC
     95       1.1  joff #define KBD_MAP(name, base, map) \
     96       1.1  joff 			{ name, base, sizeof(map)/sizeof(keysym_t), map }
     97       1.1  joff const struct wscons_keydesc mxkp_keydesctab[] = {
     98       1.1  joff 	KBD_MAP(KB_US,		0,	mxkp_keydesc_default),
     99       1.1  joff 	{0, 0, 0, 0}
    100       1.1  joff };
    101       1.1  joff #undef KBD_MAP
    102       1.1  joff 
    103       1.1  joff struct wskbd_mapdata mxkp_keymapdata = {
    104       1.1  joff 	mxkp_keydesctab,
    105       1.1  joff 	KB_US,
    106       1.1  joff };
    107       1.1  joff 
    108       1.1  joff static int	tskp_match(struct device *, struct cfdata *, void *);
    109       1.1  joff static void	tskp_attach(struct device *, struct device *, void *);
    110       1.1  joff static void	tskp_scankeys(struct matrixkp_softc *, u_int32_t *);
    111       1.1  joff 
    112       1.1  joff CFATTACH_DECL(tskp, sizeof(struct tskp_softc),
    113       1.1  joff     tskp_match, tskp_attach, NULL, NULL);
    114       1.1  joff 
    115       1.1  joff static int
    116       1.1  joff tskp_match(parent, match, aux)
    117       1.1  joff 	struct device *parent;
    118       1.1  joff 	struct cfdata *match;
    119       1.1  joff 	void *aux;
    120       1.1  joff {
    121       1.1  joff 	return 1;
    122       1.1  joff }
    123       1.1  joff 
    124       1.1  joff #define GPIO_GET(x)	bus_space_read_1(sc->sc_iot, sc->sc_gpioh, \
    125       1.1  joff 	(EP93XX_GPIO_ ## x))
    126       1.1  joff 
    127       1.1  joff #define GPIO_SET(x, y)	bus_space_write_1(sc->sc_iot, sc->sc_gpioh, \
    128       1.1  joff 	(EP93XX_GPIO_ ## x), (y))
    129       1.1  joff 
    130       1.1  joff #define GPIO_SETBITS(x, y)	bus_space_write_1(sc->sc_iot, sc->sc_gpioh, \
    131       1.1  joff 	(EP93XX_GPIO_ ## x), GPIO_GET(x) | (y))
    132       1.1  joff 
    133       1.1  joff #define GPIO_CLEARBITS(x, y)	bus_space_write_1(sc->sc_iot, sc->sc_gpioh, \
    134       1.1  joff 	(EP93XX_GPIO_ ## x), GPIO_GET(x) & (~(y)))
    135       1.1  joff 
    136       1.1  joff static void
    137       1.1  joff tskp_attach(parent, self, aux)
    138       1.1  joff 	struct device *parent;
    139       1.1  joff 	struct device *self;
    140       1.1  joff 	void *aux;
    141       1.1  joff {
    142       1.1  joff 	struct tskp_softc *sc = (void *)self;
    143       1.1  joff 	struct tspld_attach_args *taa = aux;
    144       1.1  joff 	struct wskbddev_attach_args wa;
    145       1.1  joff 
    146       1.1  joff 	sc->sc_iot = taa->ta_iot;
    147       1.1  joff 	if (bus_space_map(sc->sc_iot, EP93XX_APB_HWBASE + EP93XX_APB_GPIO,
    148       1.1  joff 		EP93XX_APB_GPIO_SIZE, 0, &sc->sc_gpioh))
    149       1.1  joff 		panic("tskp_attach: couldn't map GPIO registers");
    150       1.1  joff 
    151       1.1  joff 	sc->sc_mxkp.mxkp_scankeys = tskp_scankeys;
    152       1.1  joff 	sc->sc_mxkp.mxkp_event = mxkp_wskbd_event;
    153       1.1  joff 	sc->sc_mxkp.mxkp_nkeys = 16; 	/* 4 x 4 matrix keypad */
    154       1.1  joff 	sc->sc_mxkp.debounce_stable_ms = 3;
    155       1.1  joff 	sc->sc_mxkp.sc_dev = self;
    156       1.1  joff 	sc->sc_mxkp.poll_freq = hz;
    157       1.1  joff 
    158       1.1  joff 	GPIO_SET(PBDDR, 0xff);		/* tristate all lines */
    159       1.1  joff 
    160       1.1  joff 	printf(": 4x4 matrix keypad, polling at %d hz\n", hz);
    161       1.1  joff 
    162       1.1  joff 	mxkp_attach(&sc->sc_mxkp);
    163       1.1  joff 	wa.console = 0;
    164       1.1  joff 	wa.keymap = &mxkp_keymapdata;
    165       1.1  joff 	wa.accessops = &mxkp_accessops;
    166       1.1  joff 	wa.accesscookie = &sc->sc_mxkp;
    167       1.1  joff 	sc->sc_mxkp.sc_wskbddev = config_found(self, &wa, wskbddevprint);
    168       1.1  joff }
    169       1.1  joff 
    170       1.1  joff static void
    171       1.1  joff tskp_scankeys(mxkp_sc, keys)
    172       1.1  joff 	struct matrixkp_softc *mxkp_sc;
    173       1.1  joff 	u_int32_t *keys;
    174       1.1  joff {
    175       1.1  joff 	struct tskp_softc *sc = (void *)mxkp_sc->sc_dev;
    176       1.1  joff 	u_int32_t pos;
    177       1.1  joff 
    178       1.1  joff 	for(pos = 0; pos < 4; pos++) {
    179       1.1  joff 		GPIO_SET(PBDDR, (1 << pos));
    180       1.1  joff 		GPIO_SET(PBDR, ~(1 << pos));
    181       1.1  joff 		delay(1);
    182       1.1  joff 		keys[0] |= (~(GPIO_GET(PBDR) >> 4) & 0xf) << (4 * pos);
    183       1.1  joff 	}
    184       1.1  joff }
    185