hilkbd.c revision 1.4 1 1.4 tsutsui /* $NetBSD: hilkbd.c,v 1.4 2017/04/08 17:04:56 tsutsui Exp $ */
2 1.1 tsutsui /* $OpenBSD: hilkbd.c,v 1.14 2009/01/21 21:53:59 grange Exp $ */
3 1.1 tsutsui /*
4 1.1 tsutsui * Copyright (c) 2003, Miodrag Vallat.
5 1.1 tsutsui * All rights reserved.
6 1.1 tsutsui *
7 1.1 tsutsui * Redistribution and use in source and binary forms, with or without
8 1.1 tsutsui * modification, are permitted provided that the following conditions
9 1.1 tsutsui * are met:
10 1.1 tsutsui * 1. Redistributions of source code must retain the above copyright
11 1.1 tsutsui * notice, this list of conditions and the following disclaimer.
12 1.1 tsutsui * 2. Redistributions in binary form must reproduce the above copyright
13 1.1 tsutsui * notice, this list of conditions and the following disclaimer in the
14 1.1 tsutsui * documentation and/or other materials provided with the distribution.
15 1.1 tsutsui *
16 1.1 tsutsui * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
17 1.1 tsutsui * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
18 1.1 tsutsui * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
19 1.1 tsutsui * DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT,
20 1.1 tsutsui * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
21 1.1 tsutsui * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
22 1.1 tsutsui * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
23 1.1 tsutsui * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
24 1.1 tsutsui * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
25 1.1 tsutsui * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
26 1.1 tsutsui * POSSIBILITY OF SUCH DAMAGE.
27 1.1 tsutsui *
28 1.1 tsutsui */
29 1.1 tsutsui
30 1.1 tsutsui #include "opt_wsdisplay_compat.h"
31 1.1 tsutsui
32 1.1 tsutsui #include <sys/param.h>
33 1.1 tsutsui #include <sys/systm.h>
34 1.1 tsutsui #include <sys/device.h>
35 1.1 tsutsui #include <sys/ioctl.h>
36 1.1 tsutsui #include <sys/kernel.h>
37 1.1 tsutsui #include <sys/callout.h>
38 1.1 tsutsui #include <sys/bus.h>
39 1.1 tsutsui #include <sys/cpu.h>
40 1.1 tsutsui
41 1.1 tsutsui #include <machine/autoconf.h>
42 1.1 tsutsui
43 1.1 tsutsui #include <dev/hil/hilreg.h>
44 1.1 tsutsui #include <dev/hil/hilvar.h>
45 1.1 tsutsui #include <dev/hil/hildevs.h>
46 1.1 tsutsui
47 1.1 tsutsui #include <dev/wscons/wsconsio.h>
48 1.1 tsutsui #include <dev/wscons/wskbdvar.h>
49 1.1 tsutsui #include <dev/wscons/wsksymdef.h>
50 1.1 tsutsui #include <dev/wscons/wsksymvar.h>
51 1.1 tsutsui
52 1.1 tsutsui #include <dev/hil/hilkbdmap.h>
53 1.1 tsutsui
54 1.1 tsutsui struct hilkbd_softc {
55 1.1 tsutsui struct hildev_softc sc_hildev;
56 1.1 tsutsui
57 1.1 tsutsui int sc_numleds;
58 1.1 tsutsui int sc_ledstate;
59 1.1 tsutsui int sc_enabled;
60 1.1 tsutsui int sc_console;
61 1.1 tsutsui int sc_lastarrow;
62 1.1 tsutsui
63 1.1 tsutsui device_t sc_wskbddev;
64 1.1 tsutsui
65 1.1 tsutsui #ifdef WSDISPLAY_COMPAT_RAWKBD
66 1.1 tsutsui int sc_rawkbd;
67 1.1 tsutsui #endif
68 1.1 tsutsui };
69 1.1 tsutsui
70 1.2 tsutsui static int hilkbdprobe(device_t, cfdata_t, void *);
71 1.2 tsutsui static void hilkbdattach(device_t, device_t, void *);
72 1.2 tsutsui static int hilkbddetach(device_t, int);
73 1.1 tsutsui
74 1.1 tsutsui CFATTACH_DECL_NEW(hilkbd, sizeof(struct hilkbd_softc),
75 1.1 tsutsui hilkbdprobe, hilkbdattach, hilkbddetach, NULL);
76 1.1 tsutsui
77 1.2 tsutsui static int hilkbd_enable(void *, int);
78 1.2 tsutsui static void hilkbd_set_leds(void *, int);
79 1.2 tsutsui static int hilkbd_ioctl(void *, u_long, void *, int, struct lwp *);
80 1.1 tsutsui
81 1.2 tsutsui static const struct wskbd_accessops hilkbd_accessops = {
82 1.1 tsutsui hilkbd_enable,
83 1.1 tsutsui hilkbd_set_leds,
84 1.1 tsutsui hilkbd_ioctl,
85 1.1 tsutsui };
86 1.1 tsutsui
87 1.2 tsutsui static void hilkbd_cngetc(void *, u_int *, int *);
88 1.2 tsutsui static void hilkbd_cnpollc(void *, int);
89 1.2 tsutsui static void hilkbd_cnbell(void *, u_int, u_int, u_int);
90 1.1 tsutsui
91 1.2 tsutsui static const struct wskbd_consops hilkbd_consops = {
92 1.1 tsutsui hilkbd_cngetc,
93 1.1 tsutsui hilkbd_cnpollc,
94 1.1 tsutsui hilkbd_cnbell,
95 1.1 tsutsui };
96 1.1 tsutsui
97 1.2 tsutsui static struct wskbd_mapdata hilkbd_keymapdata = {
98 1.1 tsutsui hilkbd_keydesctab,
99 1.1 tsutsui #ifdef HILKBD_LAYOUT
100 1.1 tsutsui HILKBD_LAYOUT,
101 1.1 tsutsui #else
102 1.1 tsutsui KB_US,
103 1.1 tsutsui #endif
104 1.1 tsutsui };
105 1.1 tsutsui
106 1.2 tsutsui static struct wskbd_mapdata hilkbd_keymapdata_ps2 = {
107 1.1 tsutsui hilkbd_keydesctab_ps2,
108 1.1 tsutsui #ifdef HILKBD_LAYOUT
109 1.1 tsutsui HILKBD_LAYOUT,
110 1.1 tsutsui #else
111 1.1 tsutsui KB_US,
112 1.1 tsutsui #endif
113 1.1 tsutsui };
114 1.1 tsutsui
115 1.2 tsutsui static void hilkbd_bell(struct hil_softc *, u_int, u_int, u_int);
116 1.2 tsutsui static void hilkbd_callback(struct hildev_softc *, u_int, uint8_t *);
117 1.2 tsutsui static void hilkbd_decode(struct hilkbd_softc *, uint8_t, u_int *, int *,
118 1.2 tsutsui int);
119 1.2 tsutsui static int hilkbd_is_console(int);
120 1.1 tsutsui
121 1.2 tsutsui static int seen_hilkbd_console;
122 1.1 tsutsui
123 1.1 tsutsui int
124 1.1 tsutsui hilkbdprobe(device_t parent, cfdata_t cf, void *aux)
125 1.1 tsutsui {
126 1.1 tsutsui struct hil_attach_args *ha = aux;
127 1.1 tsutsui
128 1.1 tsutsui if (ha->ha_type != HIL_DEVICE_KEYBOARD &&
129 1.1 tsutsui ha->ha_type != HIL_DEVICE_BUTTONBOX)
130 1.2 tsutsui return 0;
131 1.1 tsutsui
132 1.2 tsutsui return 1;
133 1.1 tsutsui }
134 1.1 tsutsui
135 1.1 tsutsui void
136 1.1 tsutsui hilkbdattach(device_t parent, device_t self, void *aux)
137 1.1 tsutsui {
138 1.1 tsutsui struct hilkbd_softc *sc = device_private(self);
139 1.1 tsutsui struct hil_attach_args *ha = aux;
140 1.1 tsutsui struct wskbddev_attach_args a;
141 1.2 tsutsui uint8_t layoutcode;
142 1.1 tsutsui int ps2;
143 1.1 tsutsui
144 1.1 tsutsui sc->sc_hildev.sc_dev = self;
145 1.1 tsutsui sc->hd_code = ha->ha_code;
146 1.1 tsutsui sc->hd_type = ha->ha_type;
147 1.1 tsutsui sc->hd_infolen = ha->ha_infolen;
148 1.1 tsutsui memcpy(sc->hd_info, ha->ha_info, ha->ha_infolen);
149 1.1 tsutsui sc->hd_fn = hilkbd_callback;
150 1.1 tsutsui
151 1.1 tsutsui if (ha->ha_type == HIL_DEVICE_KEYBOARD) {
152 1.1 tsutsui /*
153 1.1 tsutsui * Determine the keyboard language configuration, but don't
154 1.1 tsutsui * override a user-specified setting.
155 1.1 tsutsui */
156 1.1 tsutsui layoutcode = ha->ha_id & (MAXHILKBDLAYOUT - 1);
157 1.1 tsutsui #ifndef HILKBD_LAYOUT
158 1.1 tsutsui if (layoutcode < MAXHILKBDLAYOUT &&
159 1.1 tsutsui hilkbd_layouts[layoutcode] != -1)
160 1.1 tsutsui hilkbd_keymapdata.layout =
161 1.1 tsutsui hilkbd_keymapdata_ps2.layout =
162 1.1 tsutsui hilkbd_layouts[layoutcode];
163 1.1 tsutsui #endif
164 1.1 tsutsui
165 1.2 tsutsui aprint_normal(", layout %x", layoutcode);
166 1.1 tsutsui }
167 1.1 tsutsui
168 1.1 tsutsui /*
169 1.1 tsutsui * Interpret the identification bytes, if any
170 1.1 tsutsui */
171 1.1 tsutsui if (ha->ha_infolen > 2 && (ha->ha_info[1] & HIL_IOB) != 0) {
172 1.1 tsutsui /* HILIOB_PROMPT is not always reported... */
173 1.1 tsutsui sc->sc_numleds = (ha->ha_info[2] & HILIOB_PMASK) >> 4;
174 1.1 tsutsui if (sc->sc_numleds != 0)
175 1.2 tsutsui aprint_normal(", %d leds", sc->sc_numleds);
176 1.1 tsutsui }
177 1.1 tsutsui
178 1.2 tsutsui aprint_normal("\n");
179 1.1 tsutsui
180 1.1 tsutsui /*
181 1.1 tsutsui * Red lettered keyboards come in two flavours, the old one
182 1.1 tsutsui * with only one control key, to the left of the escape key,
183 1.1 tsutsui * and the modern one which has a PS/2 like layout, and leds.
184 1.1 tsutsui *
185 1.1 tsutsui * Unfortunately for us, they use the same device ID range.
186 1.1 tsutsui * We'll differentiate them by looking at the leds property.
187 1.1 tsutsui */
188 1.1 tsutsui ps2 = (sc->sc_numleds != 0);
189 1.1 tsutsui
190 1.1 tsutsui /* Do not consider button boxes as console devices. */
191 1.1 tsutsui if (ha->ha_type == HIL_DEVICE_BUTTONBOX)
192 1.1 tsutsui a.console = 0;
193 1.1 tsutsui else
194 1.1 tsutsui a.console = hilkbd_is_console(ha->ha_console);
195 1.1 tsutsui a.keymap = ps2 ? &hilkbd_keymapdata_ps2 : &hilkbd_keymapdata;
196 1.1 tsutsui a.accessops = &hilkbd_accessops;
197 1.1 tsutsui a.accesscookie = sc;
198 1.1 tsutsui
199 1.1 tsutsui if (a.console) {
200 1.1 tsutsui sc->sc_console = sc->sc_enabled = 1;
201 1.1 tsutsui wskbd_cnattach(&hilkbd_consops, sc, a.keymap);
202 1.1 tsutsui } else {
203 1.1 tsutsui sc->sc_console = sc->sc_enabled = 0;
204 1.1 tsutsui }
205 1.1 tsutsui
206 1.1 tsutsui sc->sc_wskbddev = config_found(self, &a, wskbddevprint);
207 1.1 tsutsui
208 1.1 tsutsui /*
209 1.1 tsutsui * If this is an old keyboard with a numeric pad but no ``num lock''
210 1.1 tsutsui * key, simulate it being pressed so that the keyboard runs in
211 1.1 tsutsui * numeric mode.
212 1.1 tsutsui */
213 1.1 tsutsui if (!ps2 && sc->sc_wskbddev != NULL) {
214 1.1 tsutsui wskbd_input(sc->sc_wskbddev, WSCONS_EVENT_KEY_DOWN, 80);
215 1.1 tsutsui wskbd_input(sc->sc_wskbddev, WSCONS_EVENT_KEY_UP, 80);
216 1.1 tsutsui }
217 1.1 tsutsui }
218 1.1 tsutsui
219 1.1 tsutsui int
220 1.2 tsutsui hilkbddetach(device_t self, int flags)
221 1.1 tsutsui {
222 1.1 tsutsui struct hilkbd_softc *sc = device_private(self);
223 1.1 tsutsui
224 1.1 tsutsui /*
225 1.1 tsutsui * Handle console keyboard for the best. It should have been set
226 1.1 tsutsui * as the first device in the loop anyways.
227 1.1 tsutsui */
228 1.1 tsutsui if (sc->sc_console) {
229 1.1 tsutsui wskbd_cndetach();
230 1.1 tsutsui seen_hilkbd_console = 0;
231 1.1 tsutsui }
232 1.1 tsutsui
233 1.1 tsutsui if (sc->sc_wskbddev != NULL)
234 1.1 tsutsui return config_detach(sc->sc_wskbddev, flags);
235 1.1 tsutsui
236 1.2 tsutsui return 0;
237 1.1 tsutsui }
238 1.1 tsutsui
239 1.1 tsutsui int
240 1.1 tsutsui hilkbd_enable(void *v, int on)
241 1.1 tsutsui {
242 1.1 tsutsui struct hilkbd_softc *sc = v;
243 1.1 tsutsui
244 1.1 tsutsui if (on) {
245 1.1 tsutsui if (sc->sc_enabled)
246 1.2 tsutsui return EBUSY;
247 1.1 tsutsui } else {
248 1.1 tsutsui if (sc->sc_console)
249 1.2 tsutsui return EBUSY;
250 1.1 tsutsui }
251 1.1 tsutsui
252 1.1 tsutsui sc->sc_enabled = on;
253 1.1 tsutsui
254 1.2 tsutsui return 0;
255 1.1 tsutsui }
256 1.1 tsutsui
257 1.1 tsutsui void
258 1.1 tsutsui hilkbd_set_leds(void *v, int leds)
259 1.1 tsutsui {
260 1.1 tsutsui struct hilkbd_softc *sc = v;
261 1.1 tsutsui struct hildev_softc *hdsc = &sc->sc_hildev;
262 1.1 tsutsui int changemask;
263 1.1 tsutsui
264 1.1 tsutsui if (sc->sc_numleds == 0)
265 1.1 tsutsui return;
266 1.1 tsutsui
267 1.1 tsutsui changemask = leds ^ sc->sc_ledstate;
268 1.1 tsutsui if (changemask == 0)
269 1.1 tsutsui return;
270 1.1 tsutsui
271 1.1 tsutsui /* We do not handle more than 3 leds here */
272 1.1 tsutsui if (changemask & WSKBD_LED_SCROLL)
273 1.1 tsutsui send_hildev_cmd(hdsc,
274 1.1 tsutsui (leds & WSKBD_LED_SCROLL) ? HIL_PROMPT1 : HIL_ACK1,
275 1.1 tsutsui NULL, NULL);
276 1.1 tsutsui if (changemask & WSKBD_LED_NUM)
277 1.1 tsutsui send_hildev_cmd(hdsc,
278 1.1 tsutsui (leds & WSKBD_LED_NUM) ? HIL_PROMPT2 : HIL_ACK2,
279 1.1 tsutsui NULL, NULL);
280 1.1 tsutsui if (changemask & WSKBD_LED_CAPS)
281 1.1 tsutsui send_hildev_cmd(hdsc,
282 1.1 tsutsui (leds & WSKBD_LED_CAPS) ? HIL_PROMPT3 : HIL_ACK3,
283 1.1 tsutsui NULL, NULL);
284 1.1 tsutsui
285 1.1 tsutsui sc->sc_ledstate = leds;
286 1.1 tsutsui }
287 1.1 tsutsui
288 1.1 tsutsui int
289 1.1 tsutsui hilkbd_ioctl(void *v, u_long cmd, void *data, int flag, struct lwp *l)
290 1.1 tsutsui {
291 1.1 tsutsui struct hilkbd_softc *sc = v;
292 1.1 tsutsui
293 1.1 tsutsui switch (cmd) {
294 1.1 tsutsui case WSKBDIO_GTYPE:
295 1.1 tsutsui *(int *)data = WSKBD_TYPE_HIL;
296 1.1 tsutsui return 0;
297 1.1 tsutsui case WSKBDIO_SETLEDS:
298 1.1 tsutsui hilkbd_set_leds(v, *(int *)data);
299 1.1 tsutsui return 0;
300 1.1 tsutsui case WSKBDIO_GETLEDS:
301 1.1 tsutsui *(int *)data = sc->sc_ledstate;
302 1.1 tsutsui return 0;
303 1.1 tsutsui #ifdef WSDISPLAY_COMPAT_RAWKBD
304 1.1 tsutsui case WSKBDIO_SETMODE:
305 1.1 tsutsui sc->sc_rawkbd = *(int *)data == WSKBD_RAW;
306 1.1 tsutsui return 0;
307 1.1 tsutsui #endif
308 1.1 tsutsui case WSKBDIO_COMPLEXBELL:
309 1.1 tsutsui #define d ((struct wskbd_bell_data *)data)
310 1.1 tsutsui hilkbd_bell(device_private(device_parent(sc->sc_hildev.sc_dev)),
311 1.1 tsutsui d->pitch, d->period, d->volume);
312 1.1 tsutsui #undef d
313 1.1 tsutsui return 0;
314 1.1 tsutsui }
315 1.1 tsutsui
316 1.1 tsutsui return EPASSTHROUGH;
317 1.1 tsutsui }
318 1.1 tsutsui
319 1.1 tsutsui void
320 1.1 tsutsui hilkbd_cngetc(void *v, u_int *type, int *data)
321 1.1 tsutsui {
322 1.1 tsutsui struct hilkbd_softc *sc = v;
323 1.1 tsutsui struct hildev_softc *hdsc = &sc->sc_hildev;
324 1.2 tsutsui uint8_t c, stat;
325 1.1 tsutsui
326 1.1 tsutsui for (;;) {
327 1.1 tsutsui while (hil_poll_data(hdsc, &stat, &c) != 0)
328 1.1 tsutsui ;
329 1.1 tsutsui
330 1.1 tsutsui /*
331 1.1 tsutsui * Disregard keyboard data packet header.
332 1.1 tsutsui * Note that no key generates it, so we're safe.
333 1.1 tsutsui */
334 1.1 tsutsui if (c != HIL_KBDBUTTON)
335 1.1 tsutsui break;
336 1.1 tsutsui }
337 1.1 tsutsui
338 1.1 tsutsui hilkbd_decode(sc, c, type, data, HIL_KBDBUTTON);
339 1.1 tsutsui }
340 1.1 tsutsui
341 1.1 tsutsui void
342 1.1 tsutsui hilkbd_cnpollc(void *v, int on)
343 1.1 tsutsui {
344 1.1 tsutsui struct hilkbd_softc *sc = v;
345 1.1 tsutsui
346 1.1 tsutsui hil_set_poll(device_private(device_parent(sc->sc_hildev.sc_dev)), on);
347 1.1 tsutsui }
348 1.1 tsutsui
349 1.1 tsutsui void
350 1.1 tsutsui hilkbd_cnbell(void *v, u_int pitch, u_int period, u_int volume)
351 1.1 tsutsui {
352 1.1 tsutsui struct hilkbd_softc *sc = v;
353 1.1 tsutsui
354 1.1 tsutsui hilkbd_bell(device_private(device_parent(sc->sc_hildev.sc_dev)),
355 1.1 tsutsui pitch, period, volume);
356 1.1 tsutsui }
357 1.1 tsutsui
358 1.1 tsutsui void
359 1.1 tsutsui hilkbd_bell(struct hil_softc *sc, u_int pitch, u_int period, u_int volume)
360 1.1 tsutsui {
361 1.2 tsutsui uint8_t buf[2];
362 1.1 tsutsui
363 1.1 tsutsui /* XXX there could be at least a pitch -> HIL pitch conversion here */
364 1.1 tsutsui #define BELLDUR 80 /* tone duration in msec (10-2560) */
365 1.1 tsutsui #define BELLFREQ 8 /* tone frequency (0-63) */
366 1.1 tsutsui buf[0] = ar_format(period - 10);
367 1.1 tsutsui buf[1] = BELLFREQ;
368 1.1 tsutsui send_hil_cmd(sc, HIL_SETTONE, buf, 2, NULL);
369 1.1 tsutsui }
370 1.1 tsutsui
371 1.1 tsutsui void
372 1.2 tsutsui hilkbd_callback(struct hildev_softc *hdsc, u_int buflen, uint8_t *buf)
373 1.1 tsutsui {
374 1.1 tsutsui struct hilkbd_softc *sc = device_private(hdsc->sc_dev);
375 1.1 tsutsui u_int type;
376 1.1 tsutsui int kbdtype, key;
377 1.1 tsutsui int i, s;
378 1.1 tsutsui
379 1.1 tsutsui /*
380 1.1 tsutsui * Ignore packet if we don't need it
381 1.1 tsutsui */
382 1.1 tsutsui if (sc->sc_enabled == 0)
383 1.1 tsutsui return;
384 1.1 tsutsui
385 1.1 tsutsui if (buflen == 0)
386 1.1 tsutsui return;
387 1.1 tsutsui switch ((kbdtype = *buf & HIL_KBDDATA)) {
388 1.1 tsutsui case HIL_BUTTONBOX:
389 1.1 tsutsui case HIL_KBDBUTTON:
390 1.1 tsutsui break;
391 1.1 tsutsui default:
392 1.1 tsutsui return;
393 1.1 tsutsui }
394 1.1 tsutsui
395 1.1 tsutsui #ifdef WSDISPLAY_COMPAT_RAWKBD
396 1.1 tsutsui if (sc->sc_rawkbd) {
397 1.2 tsutsui uint8_t cbuf[HILBUFSIZE * 2];
398 1.4 tsutsui int c, j;
399 1.1 tsutsui
400 1.4 tsutsui j = 0;
401 1.1 tsutsui for (i = 1, buf++; i < buflen; i++) {
402 1.1 tsutsui hilkbd_decode(sc, *buf++, &type, &key, kbdtype);
403 1.1 tsutsui c = hilkbd_raw[key];
404 1.1 tsutsui if (c == 0)
405 1.1 tsutsui continue;
406 1.1 tsutsui /* fake extended scancode if necessary */
407 1.1 tsutsui if (c & 0x80)
408 1.1 tsutsui cbuf[j++] = 0xe0;
409 1.1 tsutsui cbuf[j] = c & 0x7f;
410 1.1 tsutsui if (type == WSCONS_EVENT_KEY_UP)
411 1.1 tsutsui cbuf[j] |= 0x80;
412 1.1 tsutsui j++;
413 1.1 tsutsui }
414 1.1 tsutsui
415 1.1 tsutsui s = spltty();
416 1.1 tsutsui wskbd_rawinput(sc->sc_wskbddev, cbuf, j);
417 1.1 tsutsui splx(s);
418 1.1 tsutsui } else
419 1.1 tsutsui #endif
420 1.1 tsutsui {
421 1.1 tsutsui s = spltty();
422 1.1 tsutsui for (i = 1, buf++; i < buflen; i++) {
423 1.1 tsutsui hilkbd_decode(sc, *buf++, &type, &key, kbdtype);
424 1.1 tsutsui if (sc->sc_wskbddev != NULL)
425 1.1 tsutsui wskbd_input(sc->sc_wskbddev, type, key);
426 1.1 tsutsui }
427 1.1 tsutsui splx(s);
428 1.1 tsutsui }
429 1.1 tsutsui }
430 1.1 tsutsui
431 1.1 tsutsui void
432 1.2 tsutsui hilkbd_decode(struct hilkbd_softc *sc, uint8_t data, u_int *type, int *key,
433 1.1 tsutsui int kbdtype)
434 1.1 tsutsui {
435 1.2 tsutsui
436 1.1 tsutsui if (kbdtype == HIL_BUTTONBOX) {
437 1.1 tsutsui if (data == 0x02) /* repeat arrow */
438 1.1 tsutsui data = sc->sc_lastarrow;
439 1.1 tsutsui else if (data >= 0xf8)
440 1.1 tsutsui sc->sc_lastarrow = data;
441 1.1 tsutsui }
442 1.1 tsutsui
443 1.1 tsutsui *type = (data & 1) ? WSCONS_EVENT_KEY_UP : WSCONS_EVENT_KEY_DOWN;
444 1.1 tsutsui *key = data >> 1;
445 1.1 tsutsui }
446 1.1 tsutsui
447 1.1 tsutsui int
448 1.1 tsutsui hilkbd_is_console(int hil_is_console)
449 1.1 tsutsui {
450 1.2 tsutsui
451 1.1 tsutsui /* if not first hil keyboard, then not the console */
452 1.1 tsutsui if (seen_hilkbd_console)
453 1.2 tsutsui return 0;
454 1.1 tsutsui
455 1.1 tsutsui /* if PDC console does not match hil bus path, then not the console */
456 1.1 tsutsui if (hil_is_console == 0)
457 1.2 tsutsui return 0;
458 1.1 tsutsui
459 1.1 tsutsui seen_hilkbd_console = 1;
460 1.2 tsutsui return 1;
461 1.1 tsutsui }
462