akbd.c revision 1.27 1 1.27 aymeric /* $NetBSD: akbd.c,v 1.27 2002/08/14 13:02:58 aymeric 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.16 tsubai #include <dev/ofw/openfirm.h>
47 1.2 tsubai
48 1.1 tsubai #include <machine/autoconf.h>
49 1.2 tsubai #define KEYBOARD_ARRAY
50 1.2 tsubai #include <machine/keyboard.h>
51 1.1 tsubai
52 1.1 tsubai #include <macppc/dev/adbvar.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.16 tsubai #include <macppc/dev/pm_direct.h>
57 1.1 tsubai
58 1.3 tsubai #include "aed.h"
59 1.3 tsubai
60 1.1 tsubai /*
61 1.1 tsubai * Function declarations.
62 1.1 tsubai */
63 1.2 tsubai static int akbdmatch __P((struct device *, struct cfdata *, void *));
64 1.2 tsubai static void akbdattach __P((struct device *, struct device *, void *));
65 1.1 tsubai void kbd_adbcomplete __P((caddr_t buffer, caddr_t data_area, int adb_command));
66 1.2 tsubai static void kbd_processevent __P((adb_event_t *event, struct akbd_softc *));
67 1.21 dbj static void kbd_passup __P((struct akbd_softc *sc, int));
68 1.1 tsubai #ifdef notyet
69 1.1 tsubai static u_char getleds __P((int));
70 1.2 tsubai static int setleds __P((struct akbd_softc *, u_char));
71 1.2 tsubai static void blinkleds __P((struct akbd_softc *));
72 1.1 tsubai #endif
73 1.1 tsubai
74 1.1 tsubai /* Driver definition. */
75 1.1 tsubai struct cfattach akbd_ca = {
76 1.2 tsubai sizeof(struct akbd_softc), akbdmatch, akbdattach
77 1.2 tsubai };
78 1.2 tsubai
79 1.2 tsubai extern struct cfdriver akbd_cd;
80 1.2 tsubai
81 1.2 tsubai int akbd_enable __P((void *, int));
82 1.2 tsubai void akbd_set_leds __P((void *, int));
83 1.2 tsubai int akbd_ioctl __P((void *, u_long, caddr_t, int, struct proc *));
84 1.2 tsubai
85 1.2 tsubai struct wskbd_accessops akbd_accessops = {
86 1.2 tsubai akbd_enable,
87 1.2 tsubai akbd_set_leds,
88 1.2 tsubai akbd_ioctl,
89 1.2 tsubai };
90 1.2 tsubai
91 1.2 tsubai void akbd_cngetc __P((void *, u_int *, int *));
92 1.2 tsubai void akbd_cnpollc __P((void *, int));
93 1.2 tsubai
94 1.2 tsubai struct wskbd_consops akbd_consops = {
95 1.2 tsubai akbd_cngetc,
96 1.2 tsubai akbd_cnpollc,
97 1.2 tsubai };
98 1.2 tsubai
99 1.2 tsubai struct wskbd_mapdata akbd_keymapdata = {
100 1.2 tsubai akbd_keydesctab,
101 1.10 tsubai #ifdef AKBD_LAYOUT
102 1.10 tsubai AKBD_LAYOUT,
103 1.10 tsubai #else
104 1.2 tsubai KB_US,
105 1.10 tsubai #endif
106 1.1 tsubai };
107 1.1 tsubai
108 1.7 thorpej static int akbd_is_console;
109 1.22 wrstuden static int akbd_console_attached;
110 1.16 tsubai static int pcmcia_soft_eject;
111 1.1 tsubai
112 1.1 tsubai static int
113 1.2 tsubai akbdmatch(parent, cf, aux)
114 1.1 tsubai struct device *parent;
115 1.1 tsubai struct cfdata *cf;
116 1.1 tsubai void *aux;
117 1.1 tsubai {
118 1.12 tsubai struct adb_attach_args *aa_args = aux;
119 1.1 tsubai
120 1.1 tsubai if (aa_args->origaddr == ADBADDR_KBD)
121 1.1 tsubai return 1;
122 1.1 tsubai else
123 1.1 tsubai return 0;
124 1.1 tsubai }
125 1.1 tsubai
126 1.1 tsubai static void
127 1.2 tsubai akbdattach(parent, self, aux)
128 1.1 tsubai struct device *parent, *self;
129 1.1 tsubai void *aux;
130 1.1 tsubai {
131 1.1 tsubai ADBSetInfoBlock adbinfo;
132 1.2 tsubai struct akbd_softc *sc = (struct akbd_softc *)self;
133 1.12 tsubai struct adb_attach_args *aa_args = aux;
134 1.11 tsubai int error, kbd_done;
135 1.1 tsubai short cmd;
136 1.1 tsubai u_char buffer[9];
137 1.2 tsubai struct wskbddev_attach_args a;
138 1.1 tsubai
139 1.16 tsubai /* ohare based models have soft ejectable card slot. */
140 1.16 tsubai if (OF_finddevice("/bandit/ohare") != -1)
141 1.16 tsubai pcmcia_soft_eject = 1;
142 1.16 tsubai
143 1.1 tsubai sc->origaddr = aa_args->origaddr;
144 1.1 tsubai sc->adbaddr = aa_args->adbaddr;
145 1.1 tsubai sc->handler_id = aa_args->handler_id;
146 1.1 tsubai
147 1.1 tsubai sc->sc_leds = (u_int8_t)0x00; /* initially off */
148 1.1 tsubai
149 1.1 tsubai adbinfo.siServiceRtPtr = (Ptr)kbd_adbcomplete;
150 1.1 tsubai adbinfo.siDataAreaAddr = (caddr_t)sc;
151 1.1 tsubai
152 1.1 tsubai switch (sc->handler_id) {
153 1.1 tsubai case ADB_STDKBD:
154 1.1 tsubai printf("standard keyboard\n");
155 1.1 tsubai break;
156 1.1 tsubai case ADB_ISOKBD:
157 1.1 tsubai printf("standard keyboard (ISO layout)\n");
158 1.1 tsubai break;
159 1.1 tsubai case ADB_EXTKBD:
160 1.11 tsubai cmd = ADBTALK(sc->adbaddr, 1);
161 1.11 tsubai kbd_done =
162 1.11 tsubai (adb_op_sync((Ptr)buffer, (Ptr)0, (Ptr)0, cmd) == 0);
163 1.1 tsubai
164 1.1 tsubai /* Ignore Logitech MouseMan/Trackman pseudo keyboard */
165 1.1 tsubai if (kbd_done && buffer[1] == 0x9a && buffer[2] == 0x20) {
166 1.1 tsubai printf("Mouseman (non-EMP) pseudo keyboard\n");
167 1.1 tsubai adbinfo.siServiceRtPtr = (Ptr)0;
168 1.1 tsubai adbinfo.siDataAreaAddr = (Ptr)0;
169 1.1 tsubai } else if (kbd_done && buffer[1] == 0x9a && buffer[2] == 0x21) {
170 1.1 tsubai printf("Trackman (non-EMP) pseudo keyboard\n");
171 1.1 tsubai adbinfo.siServiceRtPtr = (Ptr)0;
172 1.1 tsubai adbinfo.siDataAreaAddr = (Ptr)0;
173 1.1 tsubai } else {
174 1.1 tsubai printf("extended keyboard\n");
175 1.8 tsubai #ifdef notyet
176 1.1 tsubai blinkleds(sc);
177 1.1 tsubai #endif
178 1.1 tsubai }
179 1.1 tsubai break;
180 1.1 tsubai case ADB_EXTISOKBD:
181 1.1 tsubai printf("extended keyboard (ISO layout)\n");
182 1.1 tsubai #ifdef notyet
183 1.1 tsubai blinkleds(sc);
184 1.1 tsubai #endif
185 1.1 tsubai break;
186 1.1 tsubai case ADB_KBDII:
187 1.1 tsubai printf("keyboard II\n");
188 1.1 tsubai break;
189 1.1 tsubai case ADB_ISOKBDII:
190 1.1 tsubai printf("keyboard II (ISO layout)\n");
191 1.1 tsubai break;
192 1.1 tsubai case ADB_PBKBD:
193 1.1 tsubai printf("PowerBook keyboard\n");
194 1.1 tsubai break;
195 1.1 tsubai case ADB_PBISOKBD:
196 1.1 tsubai printf("PowerBook keyboard (ISO layout)\n");
197 1.1 tsubai break;
198 1.1 tsubai case ADB_ADJKPD:
199 1.1 tsubai printf("adjustable keypad\n");
200 1.1 tsubai break;
201 1.1 tsubai case ADB_ADJKBD:
202 1.1 tsubai printf("adjustable keyboard\n");
203 1.1 tsubai break;
204 1.1 tsubai case ADB_ADJISOKBD:
205 1.1 tsubai printf("adjustable keyboard (ISO layout)\n");
206 1.1 tsubai break;
207 1.1 tsubai case ADB_ADJJAPKBD:
208 1.1 tsubai printf("adjustable keyboard (Japanese layout)\n");
209 1.1 tsubai break;
210 1.1 tsubai case ADB_PBEXTISOKBD:
211 1.1 tsubai printf("PowerBook extended keyboard (ISO layout)\n");
212 1.1 tsubai break;
213 1.1 tsubai case ADB_PBEXTJAPKBD:
214 1.1 tsubai printf("PowerBook extended keyboard (Japanese layout)\n");
215 1.1 tsubai break;
216 1.4 tsubai case ADB_JPKBDII:
217 1.1 tsubai printf("keyboard II (Japanese layout)\n");
218 1.1 tsubai break;
219 1.1 tsubai case ADB_PBEXTKBD:
220 1.1 tsubai printf("PowerBook extended keyboard\n");
221 1.1 tsubai break;
222 1.1 tsubai case ADB_DESIGNKBD:
223 1.1 tsubai printf("extended keyboard\n");
224 1.1 tsubai #ifdef notyet
225 1.1 tsubai blinkleds(sc);
226 1.1 tsubai #endif
227 1.1 tsubai break;
228 1.4 tsubai case ADB_PBJPKBD:
229 1.4 tsubai printf("PowerBook keyboard (Japanese layout)\n");
230 1.15 nathanw break;
231 1.17 tsubai case ADB_PBG3KBD:
232 1.17 tsubai printf("PowerBook G3 keyboard\n");
233 1.8 tsubai break;
234 1.8 tsubai case ADB_PBG3JPKBD:
235 1.8 tsubai printf("PowerBook G3 keyboard (Japanese layout)\n");
236 1.4 tsubai break;
237 1.1 tsubai default:
238 1.1 tsubai printf("mapped device (%d)\n", sc->handler_id);
239 1.1 tsubai break;
240 1.1 tsubai }
241 1.1 tsubai error = SetADBInfo(&adbinfo, sc->adbaddr);
242 1.1 tsubai #ifdef ADB_DEBUG
243 1.1 tsubai if (adb_debug)
244 1.11 tsubai printf("akbd: returned %d from SetADBInfo\n", error);
245 1.1 tsubai #endif
246 1.2 tsubai
247 1.22 wrstuden if (akbd_is_console && !akbd_console_attached) {
248 1.21 dbj wskbd_cnattach(&akbd_consops, sc, &akbd_keymapdata);
249 1.22 wrstuden akbd_console_attached = 1;
250 1.19 dbj }
251 1.19 dbj
252 1.7 thorpej a.console = akbd_is_console;
253 1.2 tsubai a.keymap = &akbd_keymapdata;
254 1.2 tsubai a.accessops = &akbd_accessops;
255 1.2 tsubai a.accesscookie = sc;
256 1.2 tsubai
257 1.2 tsubai sc->sc_wskbddev = config_found(self, &a, wskbddevprint);
258 1.1 tsubai }
259 1.1 tsubai
260 1.1 tsubai
261 1.1 tsubai /*
262 1.1 tsubai * Handle putting the keyboard data received from the ADB into
263 1.1 tsubai * an ADB event record.
264 1.1 tsubai */
265 1.1 tsubai void
266 1.1 tsubai kbd_adbcomplete(buffer, data_area, adb_command)
267 1.1 tsubai caddr_t buffer;
268 1.1 tsubai caddr_t data_area;
269 1.1 tsubai int adb_command;
270 1.1 tsubai {
271 1.1 tsubai adb_event_t event;
272 1.2 tsubai struct akbd_softc *ksc;
273 1.1 tsubai int adbaddr;
274 1.1 tsubai #ifdef ADB_DEBUG
275 1.1 tsubai int i;
276 1.1 tsubai
277 1.1 tsubai if (adb_debug)
278 1.1 tsubai printf("adb: transaction completion\n");
279 1.1 tsubai #endif
280 1.1 tsubai
281 1.11 tsubai adbaddr = ADB_CMDADDR(adb_command);
282 1.2 tsubai ksc = (struct akbd_softc *)data_area;
283 1.1 tsubai
284 1.1 tsubai event.addr = adbaddr;
285 1.1 tsubai event.hand_id = ksc->handler_id;
286 1.1 tsubai event.def_addr = ksc->origaddr;
287 1.1 tsubai event.byte_count = buffer[0];
288 1.1 tsubai memcpy(event.bytes, buffer + 1, event.byte_count);
289 1.1 tsubai
290 1.1 tsubai #ifdef ADB_DEBUG
291 1.1 tsubai if (adb_debug) {
292 1.11 tsubai printf("akbd: from %d at %d (org %d) %d:", event.addr,
293 1.1 tsubai event.hand_id, event.def_addr, buffer[0]);
294 1.1 tsubai for (i = 1; i <= buffer[0]; i++)
295 1.1 tsubai printf(" %x", buffer[i]);
296 1.1 tsubai printf("\n");
297 1.1 tsubai }
298 1.1 tsubai #endif
299 1.1 tsubai
300 1.1 tsubai microtime(&event.timestamp);
301 1.1 tsubai
302 1.1 tsubai kbd_processevent(&event, ksc);
303 1.1 tsubai }
304 1.1 tsubai
305 1.1 tsubai /*
306 1.1 tsubai * Given a keyboard ADB event, record the keycodes and call the key
307 1.1 tsubai * repeat handler, optionally passing the event through the mouse
308 1.1 tsubai * button emulation handler first.
309 1.1 tsubai */
310 1.1 tsubai static void
311 1.1 tsubai kbd_processevent(event, ksc)
312 1.1 tsubai adb_event_t *event;
313 1.2 tsubai struct akbd_softc *ksc;
314 1.1 tsubai {
315 1.1 tsubai adb_event_t new_event;
316 1.1 tsubai
317 1.1 tsubai new_event = *event;
318 1.1 tsubai new_event.u.k.key = event->bytes[0];
319 1.1 tsubai new_event.bytes[1] = 0xff;
320 1.3 tsubai kbd_intr(&new_event);
321 1.3 tsubai #if NAED > 0
322 1.1 tsubai aed_input(&new_event);
323 1.3 tsubai #endif
324 1.1 tsubai if (event->bytes[1] != 0xff) {
325 1.1 tsubai new_event.u.k.key = event->bytes[1];
326 1.1 tsubai new_event.bytes[0] = event->bytes[1];
327 1.1 tsubai new_event.bytes[1] = 0xff;
328 1.3 tsubai kbd_intr(&new_event);
329 1.3 tsubai #if NAED > 0
330 1.1 tsubai aed_input(&new_event);
331 1.3 tsubai #endif
332 1.1 tsubai }
333 1.1 tsubai
334 1.1 tsubai }
335 1.1 tsubai
336 1.1 tsubai #ifdef notyet
337 1.1 tsubai /*
338 1.1 tsubai * Get the actual hardware LED state and convert it to softc format.
339 1.1 tsubai */
340 1.1 tsubai static u_char
341 1.1 tsubai getleds(addr)
342 1.1 tsubai int addr;
343 1.1 tsubai {
344 1.1 tsubai short cmd;
345 1.1 tsubai u_char buffer[9], leds;
346 1.1 tsubai
347 1.1 tsubai leds = 0x00; /* all off */
348 1.1 tsubai buffer[0] = 0;
349 1.1 tsubai
350 1.1 tsubai /* talk R2 */
351 1.11 tsubai cmd = ADBTALK(addr, 2);
352 1.11 tsubai if (adb_op_sync((Ptr)buffer, (Ptr)0, (Ptr)0, cmd) == 0 &&
353 1.11 tsubai buffer[0] > 0)
354 1.1 tsubai leds = ~(buffer[2]) & 0x07;
355 1.1 tsubai
356 1.1 tsubai return (leds);
357 1.1 tsubai }
358 1.1 tsubai
359 1.1 tsubai /*
360 1.1 tsubai * Set the keyboard LED's.
361 1.1 tsubai *
362 1.1 tsubai * Automatically translates from ioctl/softc format to the
363 1.1 tsubai * actual keyboard register format
364 1.1 tsubai */
365 1.1 tsubai static int
366 1.1 tsubai setleds(ksc, leds)
367 1.2 tsubai struct akbd_softc *ksc;
368 1.1 tsubai u_char leds;
369 1.1 tsubai {
370 1.1 tsubai int addr;
371 1.1 tsubai short cmd;
372 1.1 tsubai u_char buffer[9];
373 1.1 tsubai
374 1.1 tsubai if ((leds & 0x07) == (ksc->sc_leds & 0x07))
375 1.1 tsubai return (0);
376 1.1 tsubai
377 1.6 tsubai addr = ksc->adbaddr;
378 1.1 tsubai buffer[0] = 0;
379 1.1 tsubai
380 1.11 tsubai cmd = ADBTALK(addr, 2);
381 1.11 tsubai if (adb_op_sync((Ptr)buffer, (Ptr)0, (Ptr)0, cmd) || buffer[0] == 0)
382 1.1 tsubai return (EIO);
383 1.1 tsubai
384 1.1 tsubai leds = ~leds & 0x07;
385 1.1 tsubai buffer[2] &= 0xf8;
386 1.1 tsubai buffer[2] |= leds;
387 1.1 tsubai
388 1.11 tsubai cmd = ADBLISTEN(addr, 2);
389 1.11 tsubai adb_op_sync((Ptr)buffer, (Ptr)0, (Ptr)0, cmd);
390 1.1 tsubai
391 1.11 tsubai cmd = ADBTALK(addr, 2);
392 1.11 tsubai if (adb_op_sync((Ptr)buffer, (Ptr)0, (Ptr)0, cmd) || buffer[0] == 0)
393 1.1 tsubai return (EIO);
394 1.1 tsubai
395 1.1 tsubai ksc->sc_leds = ~((u_int8_t)buffer[2]) & 0x07;
396 1.1 tsubai
397 1.1 tsubai if ((buffer[2] & 0xf8) != leds)
398 1.1 tsubai return (EIO);
399 1.1 tsubai else
400 1.1 tsubai return (0);
401 1.1 tsubai }
402 1.1 tsubai
403 1.1 tsubai /*
404 1.1 tsubai * Toggle all of the LED's on and off, just for show.
405 1.1 tsubai */
406 1.1 tsubai static void
407 1.1 tsubai blinkleds(ksc)
408 1.2 tsubai struct akbd_softc *ksc;
409 1.1 tsubai {
410 1.1 tsubai int addr, i;
411 1.1 tsubai u_char blinkleds, origleds;
412 1.1 tsubai
413 1.6 tsubai addr = ksc->adbaddr;
414 1.1 tsubai origleds = getleds(addr);
415 1.1 tsubai blinkleds = LED_NUMLOCK | LED_CAPSLOCK | LED_SCROLL_LOCK;
416 1.1 tsubai
417 1.1 tsubai (void)setleds(ksc, blinkleds);
418 1.1 tsubai
419 1.1 tsubai for (i = 0; i < 10000; i++)
420 1.1 tsubai delay(50);
421 1.1 tsubai
422 1.1 tsubai /* make sure that we restore the LED settings */
423 1.1 tsubai i = 10;
424 1.1 tsubai do {
425 1.1 tsubai (void)setleds(ksc, (u_char)0x00);
426 1.1 tsubai } while (setleds(ksc, (u_char)0x00) && (i-- > 0));
427 1.1 tsubai
428 1.1 tsubai return;
429 1.1 tsubai }
430 1.1 tsubai #endif
431 1.1 tsubai
432 1.1 tsubai int
433 1.2 tsubai akbd_enable(v, on)
434 1.2 tsubai void *v;
435 1.2 tsubai int on;
436 1.2 tsubai {
437 1.2 tsubai return 0;
438 1.2 tsubai }
439 1.2 tsubai
440 1.2 tsubai void
441 1.2 tsubai akbd_set_leds(v, on)
442 1.2 tsubai void *v;
443 1.2 tsubai int on;
444 1.2 tsubai {
445 1.2 tsubai }
446 1.2 tsubai
447 1.2 tsubai int
448 1.2 tsubai akbd_ioctl(v, cmd, data, flag, p)
449 1.2 tsubai void *v;
450 1.2 tsubai u_long cmd;
451 1.1 tsubai caddr_t data;
452 1.2 tsubai int flag;
453 1.1 tsubai struct proc *p;
454 1.1 tsubai {
455 1.26 aymeric #ifdef WSDISPLAY_COMPAT_RAWKBD
456 1.26 aymeric struct akbd_softc *sc = (struct akbd_softc *) v;
457 1.26 aymeric #endif
458 1.26 aymeric
459 1.2 tsubai switch (cmd) {
460 1.2 tsubai
461 1.2 tsubai case WSKBDIO_GTYPE:
462 1.18 mycroft *(int *)data = WSKBD_TYPE_ADB;
463 1.2 tsubai return 0;
464 1.2 tsubai case WSKBDIO_SETLEDS:
465 1.2 tsubai return 0;
466 1.2 tsubai case WSKBDIO_GETLEDS:
467 1.2 tsubai *(int *)data = 0;
468 1.2 tsubai return 0;
469 1.26 aymeric #ifdef WSDISPLAY_COMPAT_RAWKBD
470 1.26 aymeric case WSKBDIO_SETMODE:
471 1.26 aymeric sc->sc_rawkbd = *(int *)data == WSKBD_RAW;
472 1.26 aymeric return 0;
473 1.26 aymeric #endif
474 1.2 tsubai }
475 1.2 tsubai /* kbdioctl(...); */
476 1.2 tsubai
477 1.23 atatat return EPASSTHROUGH;
478 1.2 tsubai }
479 1.2 tsubai
480 1.2 tsubai extern int adb_polling;
481 1.2 tsubai
482 1.21 dbj void
483 1.21 dbj kbd_passup(sc,key)
484 1.21 dbj struct akbd_softc *sc;
485 1.21 dbj int key;
486 1.21 dbj {
487 1.21 dbj if (sc->sc_polling) {
488 1.21 dbj if (sc->sc_npolledkeys <
489 1.21 dbj (sizeof(sc->sc_polledkeys)/sizeof(unsigned char))) {
490 1.21 dbj sc->sc_polledkeys[sc->sc_npolledkeys++] = key;
491 1.21 dbj }
492 1.21 dbj #ifdef ADB_DEBUG
493 1.21 dbj else {
494 1.21 dbj printf("akbd: dumping polled key 0x%02x\n",key);
495 1.21 dbj }
496 1.26 aymeric #endif
497 1.26 aymeric #ifdef WSDISPLAY_COMPAT_RAWKBD
498 1.26 aymeric } else if (sc->sc_rawkbd) {
499 1.27 aymeric char cbuf[2];
500 1.26 aymeric int s;
501 1.26 aymeric int j = 0;
502 1.26 aymeric int c = keyboard[ADBK_KEYVAL(key)][3];
503 1.26 aymeric
504 1.26 aymeric if (c == 0) /* XXX */
505 1.26 aymeric return;
506 1.26 aymeric
507 1.26 aymeric if (c & 0x80)
508 1.26 aymeric cbuf[j++] = 0xe0;
509 1.26 aymeric
510 1.27 aymeric cbuf[j++] = (c & 0x7f) | (ADBK_PRESS(key)? 0 : 0x80);
511 1.26 aymeric
512 1.26 aymeric s = spltty();
513 1.26 aymeric wskbd_rawinput(sc->sc_wskbddev, cbuf, j);
514 1.26 aymeric splx(s);
515 1.21 dbj #endif
516 1.21 dbj } else {
517 1.21 dbj int press, val;
518 1.21 dbj int type;
519 1.21 dbj
520 1.21 dbj press = ADBK_PRESS(key);
521 1.21 dbj val = ADBK_KEYVAL(key);
522 1.21 dbj
523 1.21 dbj type = press ? WSCONS_EVENT_KEY_DOWN : WSCONS_EVENT_KEY_UP;
524 1.21 dbj
525 1.21 dbj wskbd_input(sc->sc_wskbddev, type, val);
526 1.21 dbj }
527 1.21 dbj }
528 1.21 dbj
529 1.2 tsubai int
530 1.14 matt kbd_intr(arg)
531 1.14 matt void *arg;
532 1.2 tsubai {
533 1.14 matt adb_event_t *event = arg;
534 1.21 dbj int key;
535 1.24 itojun #ifdef CAPS_IS_CONTROL
536 1.24 itojun static int shift;
537 1.24 itojun #endif
538 1.2 tsubai
539 1.2 tsubai struct akbd_softc *sc = akbd_cd.cd_devs[0];
540 1.1 tsubai
541 1.2 tsubai key = event->u.k.key;
542 1.25 itojun
543 1.24 itojun #ifdef CAPS_IS_CONTROL
544 1.24 itojun /*
545 1.24 itojun * Caps lock is weird. The key sequence generated is:
546 1.24 itojun * press: down(57) [57] (LED turns on)
547 1.24 itojun * release: up(127) [255]
548 1.24 itojun * press: up(127) [255]
549 1.24 itojun * release: up(57) [185] (LED turns off)
550 1.24 itojun */
551 1.24 itojun if ((key == 57) || (key == 185))
552 1.24 itojun shift = 0;
553 1.24 itojun
554 1.24 itojun if (key == 255) {
555 1.24 itojun if (shift == 0) {
556 1.24 itojun key = 185;
557 1.24 itojun shift = 1;
558 1.24 itojun } else {
559 1.24 itojun key = 57;
560 1.24 itojun shift = 0;
561 1.24 itojun }
562 1.24 itojun }
563 1.24 itojun #endif
564 1.2 tsubai
565 1.9 tsubai switch (key) {
566 1.24 itojun #ifndef CAPS_IS_CONTROL
567 1.13 tsubai case 57: /* Caps Lock pressed */
568 1.9 tsubai case 185: /* Caps Lock released */
569 1.21 dbj key = ADBK_KEYDOWN(ADBK_KEYVAL(key));
570 1.21 dbj kbd_passup(sc,key);
571 1.21 dbj key = ADBK_KEYUP(ADBK_KEYVAL(key));
572 1.9 tsubai break;
573 1.24 itojun #endif
574 1.9 tsubai case 245:
575 1.16 tsubai if (pcmcia_soft_eject)
576 1.16 tsubai pm_eject_pcmcia(0);
577 1.9 tsubai break;
578 1.9 tsubai case 244:
579 1.16 tsubai if (pcmcia_soft_eject)
580 1.16 tsubai pm_eject_pcmcia(1);
581 1.9 tsubai break;
582 1.2 tsubai }
583 1.2 tsubai
584 1.21 dbj kbd_passup(sc,key);
585 1.2 tsubai
586 1.2 tsubai return 0;
587 1.2 tsubai }
588 1.2 tsubai
589 1.2 tsubai int
590 1.2 tsubai akbd_cnattach()
591 1.2 tsubai {
592 1.5 tsubai
593 1.7 thorpej akbd_is_console = 1;
594 1.2 tsubai return 0;
595 1.2 tsubai }
596 1.2 tsubai
597 1.2 tsubai void
598 1.2 tsubai akbd_cngetc(v, type, data)
599 1.2 tsubai void *v;
600 1.2 tsubai u_int *type;
601 1.2 tsubai int *data;
602 1.2 tsubai {
603 1.2 tsubai int key, press, val;
604 1.2 tsubai int s;
605 1.21 dbj struct akbd_softc *sc = v;
606 1.2 tsubai
607 1.2 tsubai s = splhigh();
608 1.2 tsubai
609 1.21 dbj KASSERT(sc->sc_polling);
610 1.20 dbj KASSERT(adb_polling);
611 1.2 tsubai
612 1.21 dbj while (sc->sc_npolledkeys == 0) {
613 1.4 tsubai adb_intr();
614 1.2 tsubai DELAY(10000); /* XXX */
615 1.1 tsubai }
616 1.2 tsubai
617 1.2 tsubai splx(s);
618 1.2 tsubai
619 1.21 dbj key = sc->sc_polledkeys[0];
620 1.21 dbj sc->sc_npolledkeys--;
621 1.21 dbj memmove(sc->sc_polledkeys,sc->sc_polledkeys+1,
622 1.21 dbj sc->sc_npolledkeys * sizeof(unsigned char));
623 1.21 dbj
624 1.2 tsubai press = ADBK_PRESS(key);
625 1.2 tsubai val = ADBK_KEYVAL(key);
626 1.2 tsubai
627 1.2 tsubai *data = val;
628 1.2 tsubai *type = press ? WSCONS_EVENT_KEY_DOWN : WSCONS_EVENT_KEY_UP;
629 1.2 tsubai }
630 1.2 tsubai
631 1.2 tsubai void
632 1.2 tsubai akbd_cnpollc(v, on)
633 1.2 tsubai void *v;
634 1.2 tsubai int on;
635 1.2 tsubai {
636 1.21 dbj struct akbd_softc *sc = v;
637 1.21 dbj sc->sc_polling = on;
638 1.21 dbj if (!on) {
639 1.21 dbj int i;
640 1.21 dbj for(i=0;i<sc->sc_npolledkeys;i++) {
641 1.21 dbj kbd_passup(sc,sc->sc_polledkeys[i]);
642 1.21 dbj }
643 1.21 dbj sc->sc_npolledkeys = 0;
644 1.21 dbj }
645 1.20 dbj adb_polling = on;
646 1.1 tsubai }
647