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