hilkbd.c revision 1.1 1 1.1 tsutsui /* $NetBSD: hilkbd.c,v 1.1 2011/02/06 18:26:54 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 int sc_nrep;
68 1.1 tsutsui char sc_rep[HILBUFSIZE * 2];
69 1.1 tsutsui struct callout sc_rawrepeat_ch;
70 1.1 tsutsui #define REP_DELAY1 400
71 1.1 tsutsui #define REP_DELAYN 100
72 1.1 tsutsui #endif
73 1.1 tsutsui };
74 1.1 tsutsui
75 1.1 tsutsui int hilkbdprobe(device_t, cfdata_t, void *);
76 1.1 tsutsui void hilkbdattach(device_t, device_t, void *);
77 1.1 tsutsui int hilkbddetach(device_t, int);
78 1.1 tsutsui
79 1.1 tsutsui CFATTACH_DECL_NEW(hilkbd, sizeof(struct hilkbd_softc),
80 1.1 tsutsui hilkbdprobe, hilkbdattach, hilkbddetach, NULL);
81 1.1 tsutsui
82 1.1 tsutsui int hilkbd_enable(void *, int);
83 1.1 tsutsui void hilkbd_set_leds(void *, int);
84 1.1 tsutsui int hilkbd_ioctl(void *, u_long, void *, int, struct lwp *);
85 1.1 tsutsui
86 1.1 tsutsui const struct wskbd_accessops hilkbd_accessops = {
87 1.1 tsutsui hilkbd_enable,
88 1.1 tsutsui hilkbd_set_leds,
89 1.1 tsutsui hilkbd_ioctl,
90 1.1 tsutsui };
91 1.1 tsutsui
92 1.1 tsutsui void hilkbd_cngetc(void *, u_int *, int *);
93 1.1 tsutsui void hilkbd_cnpollc(void *, int);
94 1.1 tsutsui void hilkbd_cnbell(void *, u_int, u_int, u_int);
95 1.1 tsutsui
96 1.1 tsutsui const struct wskbd_consops hilkbd_consops = {
97 1.1 tsutsui hilkbd_cngetc,
98 1.1 tsutsui hilkbd_cnpollc,
99 1.1 tsutsui hilkbd_cnbell,
100 1.1 tsutsui };
101 1.1 tsutsui
102 1.1 tsutsui struct wskbd_mapdata hilkbd_keymapdata = {
103 1.1 tsutsui hilkbd_keydesctab,
104 1.1 tsutsui #ifdef HILKBD_LAYOUT
105 1.1 tsutsui HILKBD_LAYOUT,
106 1.1 tsutsui #else
107 1.1 tsutsui KB_US,
108 1.1 tsutsui #endif
109 1.1 tsutsui };
110 1.1 tsutsui
111 1.1 tsutsui struct wskbd_mapdata hilkbd_keymapdata_ps2 = {
112 1.1 tsutsui hilkbd_keydesctab_ps2,
113 1.1 tsutsui #ifdef HILKBD_LAYOUT
114 1.1 tsutsui HILKBD_LAYOUT,
115 1.1 tsutsui #else
116 1.1 tsutsui KB_US,
117 1.1 tsutsui #endif
118 1.1 tsutsui };
119 1.1 tsutsui
120 1.1 tsutsui void hilkbd_bell(struct hil_softc *, u_int, u_int, u_int);
121 1.1 tsutsui void hilkbd_callback(struct hildev_softc *, u_int, u_int8_t *);
122 1.1 tsutsui void hilkbd_decode(struct hilkbd_softc *, u_int8_t, u_int *, int *, int);
123 1.1 tsutsui int hilkbd_is_console(int);
124 1.1 tsutsui void hilkbd_rawrepeat(void *);
125 1.1 tsutsui
126 1.1 tsutsui int seen_hilkbd_console;
127 1.1 tsutsui
128 1.1 tsutsui int
129 1.1 tsutsui hilkbdprobe(device_t parent, cfdata_t cf, void *aux)
130 1.1 tsutsui {
131 1.1 tsutsui struct hil_attach_args *ha = aux;
132 1.1 tsutsui
133 1.1 tsutsui if (ha->ha_type != HIL_DEVICE_KEYBOARD &&
134 1.1 tsutsui ha->ha_type != HIL_DEVICE_BUTTONBOX)
135 1.1 tsutsui return (0);
136 1.1 tsutsui
137 1.1 tsutsui return (1);
138 1.1 tsutsui }
139 1.1 tsutsui
140 1.1 tsutsui void
141 1.1 tsutsui hilkbdattach(device_t parent, device_t self, void *aux)
142 1.1 tsutsui {
143 1.1 tsutsui struct hilkbd_softc *sc = device_private(self);
144 1.1 tsutsui struct hil_attach_args *ha = aux;
145 1.1 tsutsui struct wskbddev_attach_args a;
146 1.1 tsutsui u_int8_t layoutcode;
147 1.1 tsutsui int ps2;
148 1.1 tsutsui
149 1.1 tsutsui sc->sc_hildev.sc_dev = self;
150 1.1 tsutsui sc->hd_code = ha->ha_code;
151 1.1 tsutsui sc->hd_type = ha->ha_type;
152 1.1 tsutsui sc->hd_infolen = ha->ha_infolen;
153 1.1 tsutsui memcpy(sc->hd_info, ha->ha_info, ha->ha_infolen);
154 1.1 tsutsui sc->hd_fn = hilkbd_callback;
155 1.1 tsutsui
156 1.1 tsutsui if (ha->ha_type == HIL_DEVICE_KEYBOARD) {
157 1.1 tsutsui /*
158 1.1 tsutsui * Determine the keyboard language configuration, but don't
159 1.1 tsutsui * override a user-specified setting.
160 1.1 tsutsui */
161 1.1 tsutsui layoutcode = ha->ha_id & (MAXHILKBDLAYOUT - 1);
162 1.1 tsutsui #ifndef HILKBD_LAYOUT
163 1.1 tsutsui if (layoutcode < MAXHILKBDLAYOUT &&
164 1.1 tsutsui hilkbd_layouts[layoutcode] != -1)
165 1.1 tsutsui hilkbd_keymapdata.layout =
166 1.1 tsutsui hilkbd_keymapdata_ps2.layout =
167 1.1 tsutsui hilkbd_layouts[layoutcode];
168 1.1 tsutsui #endif
169 1.1 tsutsui
170 1.1 tsutsui printf(", layout %x", layoutcode);
171 1.1 tsutsui }
172 1.1 tsutsui
173 1.1 tsutsui /*
174 1.1 tsutsui * Interpret the identification bytes, if any
175 1.1 tsutsui */
176 1.1 tsutsui if (ha->ha_infolen > 2 && (ha->ha_info[1] & HIL_IOB) != 0) {
177 1.1 tsutsui /* HILIOB_PROMPT is not always reported... */
178 1.1 tsutsui sc->sc_numleds = (ha->ha_info[2] & HILIOB_PMASK) >> 4;
179 1.1 tsutsui if (sc->sc_numleds != 0)
180 1.1 tsutsui printf(", %d leds", sc->sc_numleds);
181 1.1 tsutsui }
182 1.1 tsutsui
183 1.1 tsutsui printf("\n");
184 1.1 tsutsui
185 1.1 tsutsui /*
186 1.1 tsutsui * Red lettered keyboards come in two flavours, the old one
187 1.1 tsutsui * with only one control key, to the left of the escape key,
188 1.1 tsutsui * and the modern one which has a PS/2 like layout, and leds.
189 1.1 tsutsui *
190 1.1 tsutsui * Unfortunately for us, they use the same device ID range.
191 1.1 tsutsui * We'll differentiate them by looking at the leds property.
192 1.1 tsutsui */
193 1.1 tsutsui ps2 = (sc->sc_numleds != 0);
194 1.1 tsutsui
195 1.1 tsutsui #ifdef WSDISPLAY_COMPAT_RAWKBD
196 1.1 tsutsui callout_init(&sc->sc_rawrepeat_ch, 0);
197 1.1 tsutsui callout_setfunc(&sc->sc_rawrepeat_ch, hilkbd_rawrepeat, sc);
198 1.1 tsutsui #endif
199 1.1 tsutsui
200 1.1 tsutsui /* Do not consider button boxes as console devices. */
201 1.1 tsutsui if (ha->ha_type == HIL_DEVICE_BUTTONBOX)
202 1.1 tsutsui a.console = 0;
203 1.1 tsutsui else
204 1.1 tsutsui a.console = hilkbd_is_console(ha->ha_console);
205 1.1 tsutsui a.keymap = ps2 ? &hilkbd_keymapdata_ps2 : &hilkbd_keymapdata;
206 1.1 tsutsui a.accessops = &hilkbd_accessops;
207 1.1 tsutsui a.accesscookie = sc;
208 1.1 tsutsui
209 1.1 tsutsui if (a.console) {
210 1.1 tsutsui sc->sc_console = sc->sc_enabled = 1;
211 1.1 tsutsui wskbd_cnattach(&hilkbd_consops, sc, a.keymap);
212 1.1 tsutsui } else {
213 1.1 tsutsui sc->sc_console = sc->sc_enabled = 0;
214 1.1 tsutsui }
215 1.1 tsutsui
216 1.1 tsutsui sc->sc_wskbddev = config_found(self, &a, wskbddevprint);
217 1.1 tsutsui
218 1.1 tsutsui /*
219 1.1 tsutsui * If this is an old keyboard with a numeric pad but no ``num lock''
220 1.1 tsutsui * key, simulate it being pressed so that the keyboard runs in
221 1.1 tsutsui * numeric mode.
222 1.1 tsutsui */
223 1.1 tsutsui if (!ps2 && sc->sc_wskbddev != NULL) {
224 1.1 tsutsui wskbd_input(sc->sc_wskbddev, WSCONS_EVENT_KEY_DOWN, 80);
225 1.1 tsutsui wskbd_input(sc->sc_wskbddev, WSCONS_EVENT_KEY_UP, 80);
226 1.1 tsutsui }
227 1.1 tsutsui }
228 1.1 tsutsui
229 1.1 tsutsui int
230 1.1 tsutsui hilkbddetach(struct device *self, int flags)
231 1.1 tsutsui {
232 1.1 tsutsui struct hilkbd_softc *sc = device_private(self);
233 1.1 tsutsui
234 1.1 tsutsui /*
235 1.1 tsutsui * Handle console keyboard for the best. It should have been set
236 1.1 tsutsui * as the first device in the loop anyways.
237 1.1 tsutsui */
238 1.1 tsutsui if (sc->sc_console) {
239 1.1 tsutsui wskbd_cndetach();
240 1.1 tsutsui seen_hilkbd_console = 0;
241 1.1 tsutsui }
242 1.1 tsutsui
243 1.1 tsutsui if (sc->sc_wskbddev != NULL)
244 1.1 tsutsui return config_detach(sc->sc_wskbddev, flags);
245 1.1 tsutsui
246 1.1 tsutsui return (0);
247 1.1 tsutsui }
248 1.1 tsutsui
249 1.1 tsutsui int
250 1.1 tsutsui hilkbd_enable(void *v, int on)
251 1.1 tsutsui {
252 1.1 tsutsui struct hilkbd_softc *sc = v;
253 1.1 tsutsui
254 1.1 tsutsui if (on) {
255 1.1 tsutsui if (sc->sc_enabled)
256 1.1 tsutsui return (EBUSY);
257 1.1 tsutsui } else {
258 1.1 tsutsui if (sc->sc_console)
259 1.1 tsutsui return (EBUSY);
260 1.1 tsutsui }
261 1.1 tsutsui
262 1.1 tsutsui sc->sc_enabled = on;
263 1.1 tsutsui
264 1.1 tsutsui return (0);
265 1.1 tsutsui }
266 1.1 tsutsui
267 1.1 tsutsui void
268 1.1 tsutsui hilkbd_set_leds(void *v, int leds)
269 1.1 tsutsui {
270 1.1 tsutsui struct hilkbd_softc *sc = v;
271 1.1 tsutsui struct hildev_softc *hdsc = &sc->sc_hildev;
272 1.1 tsutsui int changemask;
273 1.1 tsutsui
274 1.1 tsutsui if (sc->sc_numleds == 0)
275 1.1 tsutsui return;
276 1.1 tsutsui
277 1.1 tsutsui changemask = leds ^ sc->sc_ledstate;
278 1.1 tsutsui if (changemask == 0)
279 1.1 tsutsui return;
280 1.1 tsutsui
281 1.1 tsutsui /* We do not handle more than 3 leds here */
282 1.1 tsutsui if (changemask & WSKBD_LED_SCROLL)
283 1.1 tsutsui send_hildev_cmd(hdsc,
284 1.1 tsutsui (leds & WSKBD_LED_SCROLL) ? HIL_PROMPT1 : HIL_ACK1,
285 1.1 tsutsui NULL, NULL);
286 1.1 tsutsui if (changemask & WSKBD_LED_NUM)
287 1.1 tsutsui send_hildev_cmd(hdsc,
288 1.1 tsutsui (leds & WSKBD_LED_NUM) ? HIL_PROMPT2 : HIL_ACK2,
289 1.1 tsutsui NULL, NULL);
290 1.1 tsutsui if (changemask & WSKBD_LED_CAPS)
291 1.1 tsutsui send_hildev_cmd(hdsc,
292 1.1 tsutsui (leds & WSKBD_LED_CAPS) ? HIL_PROMPT3 : HIL_ACK3,
293 1.1 tsutsui NULL, NULL);
294 1.1 tsutsui
295 1.1 tsutsui sc->sc_ledstate = leds;
296 1.1 tsutsui }
297 1.1 tsutsui
298 1.1 tsutsui int
299 1.1 tsutsui hilkbd_ioctl(void *v, u_long cmd, void *data, int flag, struct lwp *l)
300 1.1 tsutsui {
301 1.1 tsutsui struct hilkbd_softc *sc = v;
302 1.1 tsutsui
303 1.1 tsutsui switch (cmd) {
304 1.1 tsutsui case WSKBDIO_GTYPE:
305 1.1 tsutsui *(int *)data = WSKBD_TYPE_HIL;
306 1.1 tsutsui return 0;
307 1.1 tsutsui case WSKBDIO_SETLEDS:
308 1.1 tsutsui hilkbd_set_leds(v, *(int *)data);
309 1.1 tsutsui return 0;
310 1.1 tsutsui case WSKBDIO_GETLEDS:
311 1.1 tsutsui *(int *)data = sc->sc_ledstate;
312 1.1 tsutsui return 0;
313 1.1 tsutsui #ifdef WSDISPLAY_COMPAT_RAWKBD
314 1.1 tsutsui case WSKBDIO_SETMODE:
315 1.1 tsutsui sc->sc_rawkbd = *(int *)data == WSKBD_RAW;
316 1.1 tsutsui callout_stop(&sc->sc_rawrepeat_ch);
317 1.1 tsutsui return 0;
318 1.1 tsutsui #endif
319 1.1 tsutsui case WSKBDIO_COMPLEXBELL:
320 1.1 tsutsui #define d ((struct wskbd_bell_data *)data)
321 1.1 tsutsui hilkbd_bell(device_private(device_parent(sc->sc_hildev.sc_dev)),
322 1.1 tsutsui d->pitch, d->period, d->volume);
323 1.1 tsutsui #undef d
324 1.1 tsutsui return 0;
325 1.1 tsutsui }
326 1.1 tsutsui
327 1.1 tsutsui return EPASSTHROUGH;
328 1.1 tsutsui }
329 1.1 tsutsui
330 1.1 tsutsui void
331 1.1 tsutsui hilkbd_cngetc(void *v, u_int *type, int *data)
332 1.1 tsutsui {
333 1.1 tsutsui struct hilkbd_softc *sc = v;
334 1.1 tsutsui struct hildev_softc *hdsc = &sc->sc_hildev;
335 1.1 tsutsui u_int8_t c, stat;
336 1.1 tsutsui
337 1.1 tsutsui for (;;) {
338 1.1 tsutsui while (hil_poll_data(hdsc, &stat, &c) != 0)
339 1.1 tsutsui ;
340 1.1 tsutsui
341 1.1 tsutsui /*
342 1.1 tsutsui * Disregard keyboard data packet header.
343 1.1 tsutsui * Note that no key generates it, so we're safe.
344 1.1 tsutsui */
345 1.1 tsutsui if (c != HIL_KBDBUTTON)
346 1.1 tsutsui break;
347 1.1 tsutsui }
348 1.1 tsutsui
349 1.1 tsutsui hilkbd_decode(sc, c, type, data, HIL_KBDBUTTON);
350 1.1 tsutsui }
351 1.1 tsutsui
352 1.1 tsutsui void
353 1.1 tsutsui hilkbd_cnpollc(void *v, int on)
354 1.1 tsutsui {
355 1.1 tsutsui struct hilkbd_softc *sc = v;
356 1.1 tsutsui
357 1.1 tsutsui hil_set_poll(device_private(device_parent(sc->sc_hildev.sc_dev)), on);
358 1.1 tsutsui }
359 1.1 tsutsui
360 1.1 tsutsui void
361 1.1 tsutsui hilkbd_cnbell(void *v, u_int pitch, u_int period, u_int volume)
362 1.1 tsutsui {
363 1.1 tsutsui struct hilkbd_softc *sc = v;
364 1.1 tsutsui
365 1.1 tsutsui hilkbd_bell(device_private(device_parent(sc->sc_hildev.sc_dev)),
366 1.1 tsutsui pitch, period, volume);
367 1.1 tsutsui }
368 1.1 tsutsui
369 1.1 tsutsui void
370 1.1 tsutsui hilkbd_bell(struct hil_softc *sc, u_int pitch, u_int period, u_int volume)
371 1.1 tsutsui {
372 1.1 tsutsui u_int8_t buf[2];
373 1.1 tsutsui
374 1.1 tsutsui /* XXX there could be at least a pitch -> HIL pitch conversion here */
375 1.1 tsutsui #define BELLDUR 80 /* tone duration in msec (10-2560) */
376 1.1 tsutsui #define BELLFREQ 8 /* tone frequency (0-63) */
377 1.1 tsutsui buf[0] = ar_format(period - 10);
378 1.1 tsutsui buf[1] = BELLFREQ;
379 1.1 tsutsui send_hil_cmd(sc, HIL_SETTONE, buf, 2, NULL);
380 1.1 tsutsui }
381 1.1 tsutsui
382 1.1 tsutsui void
383 1.1 tsutsui hilkbd_callback(struct hildev_softc *hdsc, u_int buflen, u_int8_t *buf)
384 1.1 tsutsui {
385 1.1 tsutsui struct hilkbd_softc *sc = device_private(hdsc->sc_dev);
386 1.1 tsutsui u_int type;
387 1.1 tsutsui int kbdtype, key;
388 1.1 tsutsui int i, s;
389 1.1 tsutsui
390 1.1 tsutsui /*
391 1.1 tsutsui * Ignore packet if we don't need it
392 1.1 tsutsui */
393 1.1 tsutsui if (sc->sc_enabled == 0)
394 1.1 tsutsui return;
395 1.1 tsutsui
396 1.1 tsutsui if (buflen == 0)
397 1.1 tsutsui return;
398 1.1 tsutsui switch ((kbdtype = *buf & HIL_KBDDATA)) {
399 1.1 tsutsui case HIL_BUTTONBOX:
400 1.1 tsutsui case HIL_KBDBUTTON:
401 1.1 tsutsui break;
402 1.1 tsutsui default:
403 1.1 tsutsui return;
404 1.1 tsutsui }
405 1.1 tsutsui
406 1.1 tsutsui #ifdef WSDISPLAY_COMPAT_RAWKBD
407 1.1 tsutsui if (sc->sc_rawkbd) {
408 1.1 tsutsui u_char cbuf[HILBUFSIZE * 2];
409 1.1 tsutsui int c, j, npress;
410 1.1 tsutsui
411 1.1 tsutsui npress = j = 0;
412 1.1 tsutsui for (i = 1, buf++; i < buflen; i++) {
413 1.1 tsutsui hilkbd_decode(sc, *buf++, &type, &key, kbdtype);
414 1.1 tsutsui c = hilkbd_raw[key];
415 1.1 tsutsui if (c == 0)
416 1.1 tsutsui continue;
417 1.1 tsutsui /* fake extended scancode if necessary */
418 1.1 tsutsui if (c & 0x80)
419 1.1 tsutsui cbuf[j++] = 0xe0;
420 1.1 tsutsui cbuf[j] = c & 0x7f;
421 1.1 tsutsui if (type == WSCONS_EVENT_KEY_UP)
422 1.1 tsutsui cbuf[j] |= 0x80;
423 1.1 tsutsui else {
424 1.1 tsutsui /* remember pressed keys for autorepeat */
425 1.1 tsutsui if (c & 0x80)
426 1.1 tsutsui sc->sc_rep[npress++] = 0xe0;
427 1.1 tsutsui sc->sc_rep[npress++] = c & 0x7f;
428 1.1 tsutsui }
429 1.1 tsutsui j++;
430 1.1 tsutsui }
431 1.1 tsutsui
432 1.1 tsutsui s = spltty();
433 1.1 tsutsui wskbd_rawinput(sc->sc_wskbddev, cbuf, j);
434 1.1 tsutsui splx(s);
435 1.1 tsutsui callout_stop(&sc->sc_rawrepeat_ch);
436 1.1 tsutsui sc->sc_nrep = npress;
437 1.1 tsutsui if (npress != 0) {
438 1.1 tsutsui callout_schedule(&sc->sc_rawrepeat_ch,
439 1.1 tsutsui mstohz(REP_DELAY1));
440 1.1 tsutsui }
441 1.1 tsutsui } else
442 1.1 tsutsui #endif
443 1.1 tsutsui {
444 1.1 tsutsui s = spltty();
445 1.1 tsutsui for (i = 1, buf++; i < buflen; i++) {
446 1.1 tsutsui hilkbd_decode(sc, *buf++, &type, &key, kbdtype);
447 1.1 tsutsui if (sc->sc_wskbddev != NULL)
448 1.1 tsutsui wskbd_input(sc->sc_wskbddev, type, key);
449 1.1 tsutsui }
450 1.1 tsutsui splx(s);
451 1.1 tsutsui }
452 1.1 tsutsui }
453 1.1 tsutsui
454 1.1 tsutsui void
455 1.1 tsutsui hilkbd_decode(struct hilkbd_softc *sc, u_int8_t data, u_int *type, int *key,
456 1.1 tsutsui int kbdtype)
457 1.1 tsutsui {
458 1.1 tsutsui if (kbdtype == HIL_BUTTONBOX) {
459 1.1 tsutsui if (data == 0x02) /* repeat arrow */
460 1.1 tsutsui data = sc->sc_lastarrow;
461 1.1 tsutsui else if (data >= 0xf8)
462 1.1 tsutsui sc->sc_lastarrow = data;
463 1.1 tsutsui }
464 1.1 tsutsui
465 1.1 tsutsui *type = (data & 1) ? WSCONS_EVENT_KEY_UP : WSCONS_EVENT_KEY_DOWN;
466 1.1 tsutsui *key = data >> 1;
467 1.1 tsutsui }
468 1.1 tsutsui
469 1.1 tsutsui int
470 1.1 tsutsui hilkbd_is_console(int hil_is_console)
471 1.1 tsutsui {
472 1.1 tsutsui /* if not first hil keyboard, then not the console */
473 1.1 tsutsui if (seen_hilkbd_console)
474 1.1 tsutsui return (0);
475 1.1 tsutsui
476 1.1 tsutsui /* if PDC console does not match hil bus path, then not the console */
477 1.1 tsutsui if (hil_is_console == 0)
478 1.1 tsutsui return (0);
479 1.1 tsutsui
480 1.1 tsutsui seen_hilkbd_console = 1;
481 1.1 tsutsui return (1);
482 1.1 tsutsui }
483 1.1 tsutsui
484 1.1 tsutsui #ifdef WSDISPLAY_COMPAT_RAWKBD
485 1.1 tsutsui void
486 1.1 tsutsui hilkbd_rawrepeat(void *v)
487 1.1 tsutsui {
488 1.1 tsutsui struct hilkbd_softc *sc = v;
489 1.1 tsutsui int s;
490 1.1 tsutsui
491 1.1 tsutsui s = spltty();
492 1.1 tsutsui wskbd_rawinput(sc->sc_wskbddev, sc->sc_rep, sc->sc_nrep);
493 1.1 tsutsui splx(s);
494 1.1 tsutsui callout_schedule(&sc->sc_rawrepeat_ch, mstohz(REP_DELAYN));
495 1.1 tsutsui }
496 1.1 tsutsui #endif
497