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