1 /* $NetBSD: tskp.c,v 1.6 2008/04/28 20:23:17 martin Exp $ */
4 * Copyright (c) 2005 The NetBSD Foundation, Inc.
7 * This code is from software contributed to The NetBSD Foundation
10 * Redistribution and use in source and binary forms, with or without
11 * modification, are permitted provided that the following conditions
13 * 1. Redistributions of source code must retain the above copyright
14 * notice, this list of conditions and the following disclaimer.
15 * 2. Redistributions in binary form must reproduce the above copyright
16 * notice, this list of conditions and the following disclaimer in the
17 * documentation and/or other materials provided with the distribution.
19 * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
20 * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
21 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
22 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
23 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
24 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
25 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
26 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
27 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
28 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
29 * POSSIBILITY OF SUCH DAMAGE.
31 #include <sys/cdefs.h>
32 __KERNEL_RCSID(0, "$NetBSD: tskp.c,v 1.6 2008/04/28 20:23:17 martin Exp $");
34 #include <sys/param.h>
35 #include <sys/systm.h>
40 #include <sys/types.h>
41 #include <sys/kernel.h>
42 #include <sys/device.h>
43 #include <sys/callout.h>
44 #include <sys/select.h>
46 #include <machine/bus.h>
47 #include <machine/autoconf.h>
49 #include <dev/wscons/wsconsio.h>
50 #include <dev/wscons/wskbdvar.h>
51 #include <dev/wscons/wsksymdef.h>
52 #include <dev/wscons/wsksymvar.h>
54 #include <arm/ep93xx/ep93xxreg.h>
55 #include <arm/ep93xx/epgpioreg.h>
56 #include <dev/ic/matrixkpvar.h>
57 #include <evbarm/tsarm/tspldvar.h>
58 #include <evbarm/tsarm/tsarmreg.h>
62 struct matrixkp_softc sc_mxkp
;
63 bus_space_tag_t sc_iot
;
64 bus_space_handle_t sc_gpioh
;
67 #define KC(n) KS_KEYCODE(n)
68 static const keysym_t mxkp_keydesc_default
[] = {
69 /* pos normal shifted */
84 KC(14), KS_numbersign
,
88 #define KBD_MAP(name, base, map) \
89 { name, base, sizeof(map)/sizeof(keysym_t), map }
90 const struct wscons_keydesc mxkp_keydesctab
[] = {
91 KBD_MAP(KB_US
, 0, mxkp_keydesc_default
),
96 struct wskbd_mapdata mxkp_keymapdata
= {
101 static int tskp_match(struct device
*, struct cfdata
*, void *);
102 static void tskp_attach(struct device
*, struct device
*, void *);
103 static void tskp_scankeys(struct matrixkp_softc
*, u_int32_t
*);
105 CFATTACH_DECL(tskp
, sizeof(struct tskp_softc
),
106 tskp_match
, tskp_attach
, NULL
, NULL
);
109 tskp_match(struct device
*parent
, struct cfdata
*match
, void *aux
)
114 #define GPIO_GET(x) bus_space_read_1(sc->sc_iot, sc->sc_gpioh, \
117 #define GPIO_SET(x, y) bus_space_write_1(sc->sc_iot, sc->sc_gpioh, \
118 (EP93XX_GPIO_ ## x), (y))
120 #define GPIO_SETBITS(x, y) bus_space_write_1(sc->sc_iot, sc->sc_gpioh, \
121 (EP93XX_GPIO_ ## x), GPIO_GET(x) | (y))
123 #define GPIO_CLEARBITS(x, y) bus_space_write_1(sc->sc_iot, sc->sc_gpioh, \
124 (EP93XX_GPIO_ ## x), GPIO_GET(x) & (~(y)))
127 tskp_attach(struct device
*parent
, struct device
*self
, void *aux
)
129 struct tskp_softc
*sc
= (void *)self
;
130 struct tspld_attach_args
*taa
= aux
;
131 struct wskbddev_attach_args wa
;
133 sc
->sc_iot
= taa
->ta_iot
;
134 if (bus_space_map(sc
->sc_iot
, EP93XX_APB_HWBASE
+ EP93XX_APB_GPIO
,
135 EP93XX_APB_GPIO_SIZE
, 0, &sc
->sc_gpioh
))
136 panic("tskp_attach: couldn't map GPIO registers");
138 sc
->sc_mxkp
.mxkp_scankeys
= tskp_scankeys
;
139 sc
->sc_mxkp
.mxkp_event
= mxkp_wskbd_event
;
140 sc
->sc_mxkp
.mxkp_nkeys
= 16; /* 4 x 4 matrix keypad */
141 sc
->sc_mxkp
.debounce_stable_ms
= 3;
142 sc
->sc_mxkp
.sc_dev
= self
;
143 sc
->sc_mxkp
.poll_freq
= hz
;
145 GPIO_SET(PBDDR
, 0xff); /* tristate all lines */
147 printf(": 4x4 matrix keypad, polling at %d hz\n", hz
);
149 mxkp_attach(&sc
->sc_mxkp
);
151 wa
.keymap
= &mxkp_keymapdata
;
152 wa
.accessops
= &mxkp_accessops
;
153 wa
.accesscookie
= &sc
->sc_mxkp
;
154 sc
->sc_mxkp
.sc_wskbddev
= config_found(self
, &wa
, wskbddevprint
);
158 tskp_scankeys(struct matrixkp_softc
*mxkp_sc
, u_int32_t
*keys
)
160 struct tskp_softc
*sc
= (void *)mxkp_sc
->sc_dev
;
163 for(pos
= 0; pos
< 4; pos
++) {
164 GPIO_SET(PBDDR
, (1 << pos
));
165 GPIO_SET(PBDR
, ~(1 << pos
));
167 keys
[0] |= (~(GPIO_GET(PBDR
) >> 4) & 0xf) << (4 * pos
);