Expand PMF_FN_* macros.
[netbsd-mini2440.git] / sys / arch / news68k / dev / kb.c
blob7b82d24fb77831122342193816c79e3fb3d338e8
1 /* $NetBSD: kb.c,v 1.8 2007/03/04 06:00:24 christos Exp $ */
3 /*-
4 * Copyright (c) 2001 Izumi Tsutsui. All rights reserved.
6 * Redistribution and use in source and binary forms, with or without
7 * modification, are permitted provided that the following conditions
8 * are met:
9 * 1. Redistributions of source code must retain the above copyright
10 * notice, this list of conditions and the following disclaimer.
11 * 2. Redistributions in binary form must reproduce the above copyright
12 * notice, this list of conditions and the following disclaimer in the
13 * documentation and/or other materials provided with the distribution.
15 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
16 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
17 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
18 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
19 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
20 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
21 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
22 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
23 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
24 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
28 * Copyright (c) 2000 Tsubai Masanari.
29 * All rights reserved.
31 * Redistribution and use in source and binary forms, with or without
32 * modification, are permitted provided that the following conditions
33 * are met:
34 * 1. Redistributions of source code must retain the above copyright
35 * notice, this list of conditions and the following disclaimer.
36 * 2. Redistributions in binary form must reproduce the above copyright
37 * notice, this list of conditions and the following disclaimer in the
38 * documentation and/or other materials provided with the distribution.
39 * 3. The name of the author may not be used to endorse or promote products
40 * derived from this software without specific prior written permission.
42 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
43 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
44 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
45 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
46 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
47 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
48 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
49 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
50 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
51 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
54 #include <sys/cdefs.h>
55 __KERNEL_RCSID(0, "$NetBSD: kb.c,v 1.8 2007/03/04 06:00:24 christos Exp $");
57 #include <sys/param.h>
58 #include <sys/systm.h>
59 #include <sys/device.h>
61 #include <dev/wscons/wsconsio.h>
62 #include <dev/wscons/wskbdvar.h>
63 #include <dev/wscons/wsksymdef.h>
64 #include <dev/wscons/wsksymvar.h>
66 #include <machine/bus.h>
68 #include <arch/news68k/dev/kbvar.h>
70 /* #define KB_DEBUG */
72 void kb_cngetc(void *, u_int *, int *);
73 void kb_cnpollc(void *, int);
74 int kb_enable(void *, int);
75 void kb_set_leds(void *, int);
76 int kb_ioctl(void *, u_long, void *, int, struct lwp *);
78 extern struct wscons_keydesc newskb_keydesctab[];
80 struct wskbd_accessops kb_accessops = {
81 kb_enable,
82 kb_set_leds,
83 kb_ioctl,
86 struct wskbd_consops kb_consops = {
87 kb_cngetc,
88 kb_cnpollc,
91 struct wskbd_mapdata kb_keymapdata = {
92 newskb_keydesctab,
93 KB_JP,
96 void
97 kb_intr(struct kb_softc *sc)
99 struct console_softc *kb_conssc = sc->sc_conssc;
100 bus_space_tag_t bt = sc->sc_bt;
101 bus_space_handle_t bh = sc->sc_bh;
102 bus_size_t offset = sc->sc_offset;
103 int key, val;
104 u_int type;
106 kb_conssc->cs_nkeyevents++;
108 key = bus_space_read_1(bt, bh, offset);
109 type = (key & 0x80) ? WSCONS_EVENT_KEY_UP : WSCONS_EVENT_KEY_DOWN;
110 val = key & 0x7f;
112 #ifdef KB_DEBUG
113 printf("kb_intr: key=%02x, type=%d, val=%02x\n", key, type, val);
114 #endif
115 kb_conssc->cs_key = key;
116 kb_conssc->cs_type = type;
117 kb_conssc->cs_val = val;
119 if (!kb_conssc->cs_polling)
120 wskbd_input(sc->sc_wskbddev, type, val);
124 kb_cnattach(struct console_softc *conssc_p)
127 wskbd_cnattach(&kb_consops, conssc_p, &kb_keymapdata);
128 return 0;
131 void
132 kb_cngetc(void *v, u_int *type, int *data)
134 struct console_softc *conssc = v;
135 u_int nkey;
137 /* set to polling mode */
138 conssc->cs_polling = 1;
140 /* wait until any keyevent occur */
141 nkey = conssc->cs_nkeyevents;
142 while (conssc->cs_nkeyevents == nkey)
145 /* get last keyevent */
146 *data = conssc->cs_val;
147 *type = conssc->cs_type;
149 conssc->cs_polling = 0;
152 void
153 kb_cnpollc(void *v, int on)
158 kb_enable(void *v, int on)
161 return 0;
164 void
165 kb_set_leds(void *v, int on)
170 kb_ioctl(void *v, u_long cmd, void *data, int flag, struct lwp *l)
172 #if 0
173 struct console_softc *cs = v;
174 #endif
176 switch (cmd) {
177 case WSKBDIO_GTYPE:
178 *(int *)data = 0; /* XXX */
179 return 0;
180 case WSKBDIO_SETLEDS:
181 return 0;
182 case WSKBDIO_GETLEDS:
183 *(int *)data = 0;
184 return 0;
185 case WSKBDIO_COMPLEXBELL:
186 return 0;
189 return EPASSTHROUGH;