akbd.c revision 1.15 1 1.15 nathanw /* $NetBSD: akbd.c,v 1.15 2001/07/12 04:16:58 nathanw Exp $ */
2 1.1 tsubai
3 1.1 tsubai /*
4 1.1 tsubai * Copyright (C) 1998 Colin Wood
5 1.1 tsubai * All rights reserved.
6 1.1 tsubai *
7 1.1 tsubai * Redistribution and use in source and binary forms, with or without
8 1.1 tsubai * modification, are permitted provided that the following conditions
9 1.1 tsubai * are met:
10 1.1 tsubai * 1. Redistributions of source code must retain the above copyright
11 1.1 tsubai * notice, this list of conditions and the following disclaimer.
12 1.1 tsubai * 2. Redistributions in binary form must reproduce the above copyright
13 1.1 tsubai * notice, this list of conditions and the following disclaimer in the
14 1.1 tsubai * documentation and/or other materials provided with the distribution.
15 1.1 tsubai * 3. All advertising materials mentioning features or use of this software
16 1.1 tsubai * must display the following acknowledgement:
17 1.1 tsubai * This product includes software developed by Colin Wood.
18 1.1 tsubai * 4. The name of the author may not be used to endorse or promote products
19 1.1 tsubai * derived from this software without specific prior written permission.
20 1.1 tsubai *
21 1.1 tsubai * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
22 1.1 tsubai * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
23 1.1 tsubai * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
24 1.1 tsubai * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
25 1.1 tsubai * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
26 1.1 tsubai * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
27 1.1 tsubai * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
28 1.1 tsubai * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
29 1.1 tsubai * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
30 1.1 tsubai * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
31 1.1 tsubai */
32 1.1 tsubai
33 1.1 tsubai #include <sys/param.h>
34 1.1 tsubai #include <sys/device.h>
35 1.1 tsubai #include <sys/fcntl.h>
36 1.1 tsubai #include <sys/poll.h>
37 1.1 tsubai #include <sys/select.h>
38 1.1 tsubai #include <sys/proc.h>
39 1.1 tsubai #include <sys/signalvar.h>
40 1.1 tsubai #include <sys/systm.h>
41 1.1 tsubai
42 1.2 tsubai #include <dev/wscons/wsconsio.h>
43 1.2 tsubai #include <dev/wscons/wskbdvar.h>
44 1.2 tsubai #include <dev/wscons/wsksymdef.h>
45 1.2 tsubai #include <dev/wscons/wsksymvar.h>
46 1.2 tsubai
47 1.1 tsubai #include <machine/autoconf.h>
48 1.2 tsubai #define KEYBOARD_ARRAY
49 1.2 tsubai #include <machine/keyboard.h>
50 1.1 tsubai
51 1.1 tsubai #include <macppc/dev/adbvar.h>
52 1.14 matt #include <macppc/dev/pm_direct.h>
53 1.1 tsubai #include <macppc/dev/aedvar.h>
54 1.2 tsubai #include <macppc/dev/akbdmap.h>
55 1.1 tsubai #include <macppc/dev/akbdvar.h>
56 1.1 tsubai
57 1.3 tsubai #include "aed.h"
58 1.3 tsubai
59 1.1 tsubai /*
60 1.1 tsubai * Function declarations.
61 1.1 tsubai */
62 1.2 tsubai static int akbdmatch __P((struct device *, struct cfdata *, void *));
63 1.2 tsubai static void akbdattach __P((struct device *, struct device *, void *));
64 1.1 tsubai void kbd_adbcomplete __P((caddr_t buffer, caddr_t data_area, int adb_command));
65 1.2 tsubai static void kbd_processevent __P((adb_event_t *event, struct akbd_softc *));
66 1.1 tsubai #ifdef notyet
67 1.1 tsubai static u_char getleds __P((int));
68 1.2 tsubai static int setleds __P((struct akbd_softc *, u_char));
69 1.2 tsubai static void blinkleds __P((struct akbd_softc *));
70 1.1 tsubai #endif
71 1.1 tsubai
72 1.1 tsubai /* Driver definition. */
73 1.1 tsubai struct cfattach akbd_ca = {
74 1.2 tsubai sizeof(struct akbd_softc), akbdmatch, akbdattach
75 1.2 tsubai };
76 1.2 tsubai
77 1.2 tsubai extern struct cfdriver akbd_cd;
78 1.2 tsubai
79 1.2 tsubai int akbd_enable __P((void *, int));
80 1.2 tsubai void akbd_set_leds __P((void *, int));
81 1.2 tsubai int akbd_ioctl __P((void *, u_long, caddr_t, int, struct proc *));
82 1.2 tsubai
83 1.2 tsubai struct wskbd_accessops akbd_accessops = {
84 1.2 tsubai akbd_enable,
85 1.2 tsubai akbd_set_leds,
86 1.2 tsubai akbd_ioctl,
87 1.2 tsubai };
88 1.2 tsubai
89 1.2 tsubai void akbd_cngetc __P((void *, u_int *, int *));
90 1.2 tsubai void akbd_cnpollc __P((void *, int));
91 1.2 tsubai
92 1.2 tsubai struct wskbd_consops akbd_consops = {
93 1.2 tsubai akbd_cngetc,
94 1.2 tsubai akbd_cnpollc,
95 1.2 tsubai };
96 1.2 tsubai
97 1.2 tsubai struct wskbd_mapdata akbd_keymapdata = {
98 1.2 tsubai akbd_keydesctab,
99 1.10 tsubai #ifdef AKBD_LAYOUT
100 1.10 tsubai AKBD_LAYOUT,
101 1.10 tsubai #else
102 1.2 tsubai KB_US,
103 1.10 tsubai #endif
104 1.1 tsubai };
105 1.1 tsubai
106 1.7 thorpej static int akbd_is_console;
107 1.1 tsubai
108 1.1 tsubai static int
109 1.2 tsubai akbdmatch(parent, cf, aux)
110 1.1 tsubai struct device *parent;
111 1.1 tsubai struct cfdata *cf;
112 1.1 tsubai void *aux;
113 1.1 tsubai {
114 1.12 tsubai struct adb_attach_args *aa_args = aux;
115 1.1 tsubai
116 1.1 tsubai if (aa_args->origaddr == ADBADDR_KBD)
117 1.1 tsubai return 1;
118 1.1 tsubai else
119 1.1 tsubai return 0;
120 1.1 tsubai }
121 1.1 tsubai
122 1.1 tsubai static void
123 1.2 tsubai akbdattach(parent, self, aux)
124 1.1 tsubai struct device *parent, *self;
125 1.1 tsubai void *aux;
126 1.1 tsubai {
127 1.1 tsubai ADBSetInfoBlock adbinfo;
128 1.2 tsubai struct akbd_softc *sc = (struct akbd_softc *)self;
129 1.12 tsubai struct adb_attach_args *aa_args = aux;
130 1.11 tsubai int error, kbd_done;
131 1.1 tsubai short cmd;
132 1.1 tsubai u_char buffer[9];
133 1.2 tsubai struct wskbddev_attach_args a;
134 1.1 tsubai
135 1.1 tsubai sc->origaddr = aa_args->origaddr;
136 1.1 tsubai sc->adbaddr = aa_args->adbaddr;
137 1.1 tsubai sc->handler_id = aa_args->handler_id;
138 1.1 tsubai
139 1.1 tsubai sc->sc_leds = (u_int8_t)0x00; /* initially off */
140 1.1 tsubai
141 1.1 tsubai adbinfo.siServiceRtPtr = (Ptr)kbd_adbcomplete;
142 1.1 tsubai adbinfo.siDataAreaAddr = (caddr_t)sc;
143 1.1 tsubai
144 1.1 tsubai switch (sc->handler_id) {
145 1.1 tsubai case ADB_STDKBD:
146 1.1 tsubai printf("standard keyboard\n");
147 1.1 tsubai break;
148 1.1 tsubai case ADB_ISOKBD:
149 1.1 tsubai printf("standard keyboard (ISO layout)\n");
150 1.1 tsubai break;
151 1.1 tsubai case ADB_EXTKBD:
152 1.11 tsubai cmd = ADBTALK(sc->adbaddr, 1);
153 1.11 tsubai kbd_done =
154 1.11 tsubai (adb_op_sync((Ptr)buffer, (Ptr)0, (Ptr)0, cmd) == 0);
155 1.1 tsubai
156 1.1 tsubai /* Ignore Logitech MouseMan/Trackman pseudo keyboard */
157 1.1 tsubai if (kbd_done && buffer[1] == 0x9a && buffer[2] == 0x20) {
158 1.1 tsubai printf("Mouseman (non-EMP) pseudo keyboard\n");
159 1.1 tsubai adbinfo.siServiceRtPtr = (Ptr)0;
160 1.1 tsubai adbinfo.siDataAreaAddr = (Ptr)0;
161 1.1 tsubai } else if (kbd_done && buffer[1] == 0x9a && buffer[2] == 0x21) {
162 1.1 tsubai printf("Trackman (non-EMP) pseudo keyboard\n");
163 1.1 tsubai adbinfo.siServiceRtPtr = (Ptr)0;
164 1.1 tsubai adbinfo.siDataAreaAddr = (Ptr)0;
165 1.1 tsubai } else {
166 1.1 tsubai printf("extended keyboard\n");
167 1.8 tsubai #ifdef notyet
168 1.1 tsubai blinkleds(sc);
169 1.1 tsubai #endif
170 1.1 tsubai }
171 1.1 tsubai break;
172 1.1 tsubai case ADB_EXTISOKBD:
173 1.1 tsubai printf("extended keyboard (ISO layout)\n");
174 1.1 tsubai #ifdef notyet
175 1.1 tsubai blinkleds(sc);
176 1.1 tsubai #endif
177 1.1 tsubai break;
178 1.1 tsubai case ADB_KBDII:
179 1.1 tsubai printf("keyboard II\n");
180 1.1 tsubai break;
181 1.1 tsubai case ADB_ISOKBDII:
182 1.1 tsubai printf("keyboard II (ISO layout)\n");
183 1.1 tsubai break;
184 1.1 tsubai case ADB_PBKBD:
185 1.1 tsubai printf("PowerBook keyboard\n");
186 1.1 tsubai break;
187 1.1 tsubai case ADB_PBISOKBD:
188 1.1 tsubai printf("PowerBook keyboard (ISO layout)\n");
189 1.1 tsubai break;
190 1.1 tsubai case ADB_ADJKPD:
191 1.1 tsubai printf("adjustable keypad\n");
192 1.1 tsubai break;
193 1.1 tsubai case ADB_ADJKBD:
194 1.1 tsubai printf("adjustable keyboard\n");
195 1.1 tsubai break;
196 1.1 tsubai case ADB_ADJISOKBD:
197 1.1 tsubai printf("adjustable keyboard (ISO layout)\n");
198 1.1 tsubai break;
199 1.1 tsubai case ADB_ADJJAPKBD:
200 1.1 tsubai printf("adjustable keyboard (Japanese layout)\n");
201 1.1 tsubai break;
202 1.1 tsubai case ADB_PBEXTISOKBD:
203 1.1 tsubai printf("PowerBook extended keyboard (ISO layout)\n");
204 1.1 tsubai break;
205 1.1 tsubai case ADB_PBEXTJAPKBD:
206 1.1 tsubai printf("PowerBook extended keyboard (Japanese layout)\n");
207 1.1 tsubai break;
208 1.4 tsubai case ADB_JPKBDII:
209 1.1 tsubai printf("keyboard II (Japanese layout)\n");
210 1.1 tsubai break;
211 1.1 tsubai case ADB_PBEXTKBD:
212 1.1 tsubai printf("PowerBook extended keyboard\n");
213 1.1 tsubai break;
214 1.1 tsubai case ADB_DESIGNKBD:
215 1.1 tsubai printf("extended keyboard\n");
216 1.1 tsubai #ifdef notyet
217 1.1 tsubai blinkleds(sc);
218 1.1 tsubai #endif
219 1.1 tsubai break;
220 1.4 tsubai case ADB_PBJPKBD:
221 1.4 tsubai printf("PowerBook keyboard (Japanese layout)\n");
222 1.15 nathanw break;
223 1.15 nathanw case ADB_TIBKBD:
224 1.15 nathanw printf("PowerBook G4/iBook (dual USB) keyboard\n");
225 1.8 tsubai break;
226 1.8 tsubai case ADB_PBG3JPKBD:
227 1.8 tsubai printf("PowerBook G3 keyboard (Japanese layout)\n");
228 1.4 tsubai break;
229 1.1 tsubai default:
230 1.1 tsubai printf("mapped device (%d)\n", sc->handler_id);
231 1.1 tsubai break;
232 1.1 tsubai }
233 1.1 tsubai error = SetADBInfo(&adbinfo, sc->adbaddr);
234 1.1 tsubai #ifdef ADB_DEBUG
235 1.1 tsubai if (adb_debug)
236 1.11 tsubai printf("akbd: returned %d from SetADBInfo\n", error);
237 1.1 tsubai #endif
238 1.2 tsubai
239 1.7 thorpej a.console = akbd_is_console;
240 1.2 tsubai a.keymap = &akbd_keymapdata;
241 1.2 tsubai a.accessops = &akbd_accessops;
242 1.2 tsubai a.accesscookie = sc;
243 1.2 tsubai
244 1.2 tsubai sc->sc_wskbddev = config_found(self, &a, wskbddevprint);
245 1.1 tsubai }
246 1.1 tsubai
247 1.1 tsubai
248 1.1 tsubai /*
249 1.1 tsubai * Handle putting the keyboard data received from the ADB into
250 1.1 tsubai * an ADB event record.
251 1.1 tsubai */
252 1.1 tsubai void
253 1.1 tsubai kbd_adbcomplete(buffer, data_area, adb_command)
254 1.1 tsubai caddr_t buffer;
255 1.1 tsubai caddr_t data_area;
256 1.1 tsubai int adb_command;
257 1.1 tsubai {
258 1.1 tsubai adb_event_t event;
259 1.2 tsubai struct akbd_softc *ksc;
260 1.1 tsubai int adbaddr;
261 1.1 tsubai #ifdef ADB_DEBUG
262 1.1 tsubai int i;
263 1.1 tsubai
264 1.1 tsubai if (adb_debug)
265 1.1 tsubai printf("adb: transaction completion\n");
266 1.1 tsubai #endif
267 1.1 tsubai
268 1.11 tsubai adbaddr = ADB_CMDADDR(adb_command);
269 1.2 tsubai ksc = (struct akbd_softc *)data_area;
270 1.1 tsubai
271 1.1 tsubai event.addr = adbaddr;
272 1.1 tsubai event.hand_id = ksc->handler_id;
273 1.1 tsubai event.def_addr = ksc->origaddr;
274 1.1 tsubai event.byte_count = buffer[0];
275 1.1 tsubai memcpy(event.bytes, buffer + 1, event.byte_count);
276 1.1 tsubai
277 1.1 tsubai #ifdef ADB_DEBUG
278 1.1 tsubai if (adb_debug) {
279 1.11 tsubai printf("akbd: from %d at %d (org %d) %d:", event.addr,
280 1.1 tsubai event.hand_id, event.def_addr, buffer[0]);
281 1.1 tsubai for (i = 1; i <= buffer[0]; i++)
282 1.1 tsubai printf(" %x", buffer[i]);
283 1.1 tsubai printf("\n");
284 1.1 tsubai }
285 1.1 tsubai #endif
286 1.1 tsubai
287 1.1 tsubai microtime(&event.timestamp);
288 1.1 tsubai
289 1.1 tsubai kbd_processevent(&event, ksc);
290 1.1 tsubai }
291 1.1 tsubai
292 1.1 tsubai /*
293 1.1 tsubai * Given a keyboard ADB event, record the keycodes and call the key
294 1.1 tsubai * repeat handler, optionally passing the event through the mouse
295 1.1 tsubai * button emulation handler first.
296 1.1 tsubai */
297 1.1 tsubai static void
298 1.1 tsubai kbd_processevent(event, ksc)
299 1.1 tsubai adb_event_t *event;
300 1.2 tsubai struct akbd_softc *ksc;
301 1.1 tsubai {
302 1.1 tsubai adb_event_t new_event;
303 1.1 tsubai
304 1.1 tsubai new_event = *event;
305 1.1 tsubai new_event.u.k.key = event->bytes[0];
306 1.1 tsubai new_event.bytes[1] = 0xff;
307 1.3 tsubai kbd_intr(&new_event);
308 1.3 tsubai #if NAED > 0
309 1.1 tsubai aed_input(&new_event);
310 1.3 tsubai #endif
311 1.1 tsubai if (event->bytes[1] != 0xff) {
312 1.1 tsubai new_event.u.k.key = event->bytes[1];
313 1.1 tsubai new_event.bytes[0] = event->bytes[1];
314 1.1 tsubai new_event.bytes[1] = 0xff;
315 1.3 tsubai kbd_intr(&new_event);
316 1.3 tsubai #if NAED > 0
317 1.1 tsubai aed_input(&new_event);
318 1.3 tsubai #endif
319 1.1 tsubai }
320 1.1 tsubai
321 1.1 tsubai }
322 1.1 tsubai
323 1.1 tsubai #ifdef notyet
324 1.1 tsubai /*
325 1.1 tsubai * Get the actual hardware LED state and convert it to softc format.
326 1.1 tsubai */
327 1.1 tsubai static u_char
328 1.1 tsubai getleds(addr)
329 1.1 tsubai int addr;
330 1.1 tsubai {
331 1.1 tsubai short cmd;
332 1.1 tsubai u_char buffer[9], leds;
333 1.1 tsubai
334 1.1 tsubai leds = 0x00; /* all off */
335 1.1 tsubai buffer[0] = 0;
336 1.1 tsubai
337 1.1 tsubai /* talk R2 */
338 1.11 tsubai cmd = ADBTALK(addr, 2);
339 1.11 tsubai if (adb_op_sync((Ptr)buffer, (Ptr)0, (Ptr)0, cmd) == 0 &&
340 1.11 tsubai buffer[0] > 0)
341 1.1 tsubai leds = ~(buffer[2]) & 0x07;
342 1.1 tsubai
343 1.1 tsubai return (leds);
344 1.1 tsubai }
345 1.1 tsubai
346 1.1 tsubai /*
347 1.1 tsubai * Set the keyboard LED's.
348 1.1 tsubai *
349 1.1 tsubai * Automatically translates from ioctl/softc format to the
350 1.1 tsubai * actual keyboard register format
351 1.1 tsubai */
352 1.1 tsubai static int
353 1.1 tsubai setleds(ksc, leds)
354 1.2 tsubai struct akbd_softc *ksc;
355 1.1 tsubai u_char leds;
356 1.1 tsubai {
357 1.1 tsubai int addr;
358 1.1 tsubai short cmd;
359 1.1 tsubai u_char buffer[9];
360 1.1 tsubai
361 1.1 tsubai if ((leds & 0x07) == (ksc->sc_leds & 0x07))
362 1.1 tsubai return (0);
363 1.1 tsubai
364 1.6 tsubai addr = ksc->adbaddr;
365 1.1 tsubai buffer[0] = 0;
366 1.1 tsubai
367 1.11 tsubai cmd = ADBTALK(addr, 2);
368 1.11 tsubai if (adb_op_sync((Ptr)buffer, (Ptr)0, (Ptr)0, cmd) || buffer[0] == 0)
369 1.1 tsubai return (EIO);
370 1.1 tsubai
371 1.1 tsubai leds = ~leds & 0x07;
372 1.1 tsubai buffer[2] &= 0xf8;
373 1.1 tsubai buffer[2] |= leds;
374 1.1 tsubai
375 1.11 tsubai cmd = ADBLISTEN(addr, 2);
376 1.11 tsubai adb_op_sync((Ptr)buffer, (Ptr)0, (Ptr)0, cmd);
377 1.1 tsubai
378 1.11 tsubai cmd = ADBTALK(addr, 2);
379 1.11 tsubai if (adb_op_sync((Ptr)buffer, (Ptr)0, (Ptr)0, cmd) || buffer[0] == 0)
380 1.1 tsubai return (EIO);
381 1.1 tsubai
382 1.1 tsubai ksc->sc_leds = ~((u_int8_t)buffer[2]) & 0x07;
383 1.1 tsubai
384 1.1 tsubai if ((buffer[2] & 0xf8) != leds)
385 1.1 tsubai return (EIO);
386 1.1 tsubai else
387 1.1 tsubai return (0);
388 1.1 tsubai }
389 1.1 tsubai
390 1.1 tsubai /*
391 1.1 tsubai * Toggle all of the LED's on and off, just for show.
392 1.1 tsubai */
393 1.1 tsubai static void
394 1.1 tsubai blinkleds(ksc)
395 1.2 tsubai struct akbd_softc *ksc;
396 1.1 tsubai {
397 1.1 tsubai int addr, i;
398 1.1 tsubai u_char blinkleds, origleds;
399 1.1 tsubai
400 1.6 tsubai addr = ksc->adbaddr;
401 1.1 tsubai origleds = getleds(addr);
402 1.1 tsubai blinkleds = LED_NUMLOCK | LED_CAPSLOCK | LED_SCROLL_LOCK;
403 1.1 tsubai
404 1.1 tsubai (void)setleds(ksc, blinkleds);
405 1.1 tsubai
406 1.1 tsubai for (i = 0; i < 10000; i++)
407 1.1 tsubai delay(50);
408 1.1 tsubai
409 1.1 tsubai /* make sure that we restore the LED settings */
410 1.1 tsubai i = 10;
411 1.1 tsubai do {
412 1.1 tsubai (void)setleds(ksc, (u_char)0x00);
413 1.1 tsubai } while (setleds(ksc, (u_char)0x00) && (i-- > 0));
414 1.1 tsubai
415 1.1 tsubai return;
416 1.1 tsubai }
417 1.1 tsubai #endif
418 1.1 tsubai
419 1.1 tsubai int
420 1.2 tsubai akbd_enable(v, on)
421 1.2 tsubai void *v;
422 1.2 tsubai int on;
423 1.2 tsubai {
424 1.2 tsubai return 0;
425 1.2 tsubai }
426 1.2 tsubai
427 1.2 tsubai void
428 1.2 tsubai akbd_set_leds(v, on)
429 1.2 tsubai void *v;
430 1.2 tsubai int on;
431 1.2 tsubai {
432 1.2 tsubai }
433 1.2 tsubai
434 1.2 tsubai int
435 1.2 tsubai akbd_ioctl(v, cmd, data, flag, p)
436 1.2 tsubai void *v;
437 1.2 tsubai u_long cmd;
438 1.1 tsubai caddr_t data;
439 1.2 tsubai int flag;
440 1.1 tsubai struct proc *p;
441 1.1 tsubai {
442 1.2 tsubai switch (cmd) {
443 1.2 tsubai
444 1.2 tsubai case WSKBDIO_GTYPE:
445 1.2 tsubai *(int *)data = 0; /* XXX */
446 1.2 tsubai return 0;
447 1.2 tsubai case WSKBDIO_SETLEDS:
448 1.2 tsubai return 0;
449 1.2 tsubai case WSKBDIO_GETLEDS:
450 1.2 tsubai *(int *)data = 0;
451 1.2 tsubai return 0;
452 1.2 tsubai }
453 1.2 tsubai /* kbdioctl(...); */
454 1.2 tsubai
455 1.2 tsubai return -1;
456 1.2 tsubai }
457 1.2 tsubai
458 1.2 tsubai static int polledkey;
459 1.2 tsubai extern int adb_polling;
460 1.2 tsubai
461 1.2 tsubai int
462 1.14 matt kbd_intr(arg)
463 1.14 matt void *arg;
464 1.2 tsubai {
465 1.14 matt adb_event_t *event = arg;
466 1.2 tsubai int key, press, val;
467 1.2 tsubai int type;
468 1.2 tsubai
469 1.2 tsubai struct akbd_softc *sc = akbd_cd.cd_devs[0];
470 1.1 tsubai
471 1.2 tsubai key = event->u.k.key;
472 1.2 tsubai press = ADBK_PRESS(key);
473 1.2 tsubai val = ADBK_KEYVAL(key);
474 1.1 tsubai
475 1.2 tsubai type = press ? WSCONS_EVENT_KEY_DOWN : WSCONS_EVENT_KEY_UP;
476 1.2 tsubai
477 1.9 tsubai switch (key) {
478 1.13 tsubai case 57: /* Caps Lock pressed */
479 1.9 tsubai case 185: /* Caps Lock released */
480 1.2 tsubai type = WSCONS_EVENT_KEY_DOWN;
481 1.2 tsubai wskbd_input(sc->sc_wskbddev, type, val);
482 1.2 tsubai type = WSCONS_EVENT_KEY_UP;
483 1.9 tsubai break;
484 1.9 tsubai case 245:
485 1.9 tsubai pm_eject_pcmcia(0);
486 1.9 tsubai break;
487 1.9 tsubai case 244:
488 1.9 tsubai pm_eject_pcmcia(1);
489 1.9 tsubai break;
490 1.2 tsubai }
491 1.2 tsubai
492 1.2 tsubai if (adb_polling)
493 1.2 tsubai polledkey = key;
494 1.2 tsubai else
495 1.2 tsubai wskbd_input(sc->sc_wskbddev, type, val);
496 1.2 tsubai
497 1.2 tsubai return 0;
498 1.2 tsubai }
499 1.2 tsubai
500 1.2 tsubai int
501 1.2 tsubai akbd_cnattach()
502 1.2 tsubai {
503 1.5 tsubai
504 1.7 thorpej akbd_is_console = 1;
505 1.2 tsubai wskbd_cnattach(&akbd_consops, NULL, &akbd_keymapdata);
506 1.2 tsubai return 0;
507 1.2 tsubai }
508 1.2 tsubai
509 1.2 tsubai void
510 1.2 tsubai akbd_cngetc(v, type, data)
511 1.2 tsubai void *v;
512 1.2 tsubai u_int *type;
513 1.2 tsubai int *data;
514 1.2 tsubai {
515 1.2 tsubai int key, press, val;
516 1.2 tsubai int s;
517 1.2 tsubai
518 1.2 tsubai s = splhigh();
519 1.2 tsubai
520 1.2 tsubai polledkey = -1;
521 1.2 tsubai adb_polling = 1;
522 1.2 tsubai
523 1.2 tsubai while (polledkey == -1) {
524 1.4 tsubai adb_intr();
525 1.2 tsubai DELAY(10000); /* XXX */
526 1.1 tsubai }
527 1.2 tsubai
528 1.2 tsubai adb_polling = 0;
529 1.2 tsubai splx(s);
530 1.2 tsubai
531 1.2 tsubai key = polledkey;
532 1.2 tsubai press = ADBK_PRESS(key);
533 1.2 tsubai val = ADBK_KEYVAL(key);
534 1.2 tsubai
535 1.2 tsubai *data = val;
536 1.2 tsubai *type = press ? WSCONS_EVENT_KEY_DOWN : WSCONS_EVENT_KEY_UP;
537 1.2 tsubai }
538 1.2 tsubai
539 1.2 tsubai void
540 1.2 tsubai akbd_cnpollc(v, on)
541 1.2 tsubai void *v;
542 1.2 tsubai int on;
543 1.2 tsubai {
544 1.1 tsubai }
545