akbd.c revision 1.18.4.3 1 1.18.4.3 nathanw /* $NetBSD: akbd.c,v 1.18.4.3 2002/02/28 04:10:39 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.2 nathanw static int pcmcia_soft_eject;
110 1.18.4.2 nathanw
111 1.18.4.2 nathanw static int
112 1.18.4.2 nathanw akbdmatch(parent, cf, aux)
113 1.18.4.2 nathanw struct device *parent;
114 1.18.4.2 nathanw struct cfdata *cf;
115 1.18.4.2 nathanw void *aux;
116 1.18.4.2 nathanw {
117 1.18.4.2 nathanw struct adb_attach_args *aa_args = aux;
118 1.18.4.2 nathanw
119 1.18.4.2 nathanw if (aa_args->origaddr == ADBADDR_KBD)
120 1.18.4.2 nathanw return 1;
121 1.18.4.2 nathanw else
122 1.18.4.2 nathanw return 0;
123 1.18.4.2 nathanw }
124 1.18.4.2 nathanw
125 1.18.4.2 nathanw static void
126 1.18.4.2 nathanw akbdattach(parent, self, aux)
127 1.18.4.2 nathanw struct device *parent, *self;
128 1.18.4.2 nathanw void *aux;
129 1.18.4.2 nathanw {
130 1.18.4.2 nathanw ADBSetInfoBlock adbinfo;
131 1.18.4.2 nathanw struct akbd_softc *sc = (struct akbd_softc *)self;
132 1.18.4.2 nathanw struct adb_attach_args *aa_args = aux;
133 1.18.4.2 nathanw int error, kbd_done;
134 1.18.4.2 nathanw short cmd;
135 1.18.4.2 nathanw u_char buffer[9];
136 1.18.4.2 nathanw struct wskbddev_attach_args a;
137 1.18.4.2 nathanw
138 1.18.4.2 nathanw /* ohare based models have soft ejectable card slot. */
139 1.18.4.2 nathanw if (OF_finddevice("/bandit/ohare") != -1)
140 1.18.4.2 nathanw pcmcia_soft_eject = 1;
141 1.18.4.2 nathanw
142 1.18.4.2 nathanw sc->origaddr = aa_args->origaddr;
143 1.18.4.2 nathanw sc->adbaddr = aa_args->adbaddr;
144 1.18.4.2 nathanw sc->handler_id = aa_args->handler_id;
145 1.18.4.2 nathanw
146 1.18.4.2 nathanw sc->sc_leds = (u_int8_t)0x00; /* initially off */
147 1.18.4.2 nathanw
148 1.18.4.2 nathanw adbinfo.siServiceRtPtr = (Ptr)kbd_adbcomplete;
149 1.18.4.2 nathanw adbinfo.siDataAreaAddr = (caddr_t)sc;
150 1.18.4.2 nathanw
151 1.18.4.2 nathanw switch (sc->handler_id) {
152 1.18.4.2 nathanw case ADB_STDKBD:
153 1.18.4.2 nathanw printf("standard keyboard\n");
154 1.18.4.2 nathanw break;
155 1.18.4.2 nathanw case ADB_ISOKBD:
156 1.18.4.2 nathanw printf("standard keyboard (ISO layout)\n");
157 1.18.4.2 nathanw break;
158 1.18.4.2 nathanw case ADB_EXTKBD:
159 1.18.4.2 nathanw cmd = ADBTALK(sc->adbaddr, 1);
160 1.18.4.2 nathanw kbd_done =
161 1.18.4.2 nathanw (adb_op_sync((Ptr)buffer, (Ptr)0, (Ptr)0, cmd) == 0);
162 1.18.4.2 nathanw
163 1.18.4.2 nathanw /* Ignore Logitech MouseMan/Trackman pseudo keyboard */
164 1.18.4.2 nathanw if (kbd_done && buffer[1] == 0x9a && buffer[2] == 0x20) {
165 1.18.4.2 nathanw printf("Mouseman (non-EMP) pseudo keyboard\n");
166 1.18.4.2 nathanw adbinfo.siServiceRtPtr = (Ptr)0;
167 1.18.4.2 nathanw adbinfo.siDataAreaAddr = (Ptr)0;
168 1.18.4.2 nathanw } else if (kbd_done && buffer[1] == 0x9a && buffer[2] == 0x21) {
169 1.18.4.2 nathanw printf("Trackman (non-EMP) pseudo keyboard\n");
170 1.18.4.2 nathanw adbinfo.siServiceRtPtr = (Ptr)0;
171 1.18.4.2 nathanw adbinfo.siDataAreaAddr = (Ptr)0;
172 1.18.4.2 nathanw } else {
173 1.18.4.2 nathanw printf("extended keyboard\n");
174 1.18.4.2 nathanw #ifdef notyet
175 1.18.4.2 nathanw blinkleds(sc);
176 1.18.4.2 nathanw #endif
177 1.18.4.2 nathanw }
178 1.18.4.2 nathanw break;
179 1.18.4.2 nathanw case ADB_EXTISOKBD:
180 1.18.4.2 nathanw printf("extended keyboard (ISO layout)\n");
181 1.18.4.2 nathanw #ifdef notyet
182 1.18.4.2 nathanw blinkleds(sc);
183 1.18.4.2 nathanw #endif
184 1.18.4.2 nathanw break;
185 1.18.4.2 nathanw case ADB_KBDII:
186 1.18.4.2 nathanw printf("keyboard II\n");
187 1.18.4.2 nathanw break;
188 1.18.4.2 nathanw case ADB_ISOKBDII:
189 1.18.4.2 nathanw printf("keyboard II (ISO layout)\n");
190 1.18.4.2 nathanw break;
191 1.18.4.2 nathanw case ADB_PBKBD:
192 1.18.4.2 nathanw printf("PowerBook keyboard\n");
193 1.18.4.2 nathanw break;
194 1.18.4.2 nathanw case ADB_PBISOKBD:
195 1.18.4.2 nathanw printf("PowerBook keyboard (ISO layout)\n");
196 1.18.4.2 nathanw break;
197 1.18.4.2 nathanw case ADB_ADJKPD:
198 1.18.4.2 nathanw printf("adjustable keypad\n");
199 1.18.4.2 nathanw break;
200 1.18.4.2 nathanw case ADB_ADJKBD:
201 1.18.4.2 nathanw printf("adjustable keyboard\n");
202 1.18.4.2 nathanw break;
203 1.18.4.2 nathanw case ADB_ADJISOKBD:
204 1.18.4.2 nathanw printf("adjustable keyboard (ISO layout)\n");
205 1.18.4.2 nathanw break;
206 1.18.4.2 nathanw case ADB_ADJJAPKBD:
207 1.18.4.2 nathanw printf("adjustable keyboard (Japanese layout)\n");
208 1.18.4.2 nathanw break;
209 1.18.4.2 nathanw case ADB_PBEXTISOKBD:
210 1.18.4.2 nathanw printf("PowerBook extended keyboard (ISO layout)\n");
211 1.18.4.2 nathanw break;
212 1.18.4.2 nathanw case ADB_PBEXTJAPKBD:
213 1.18.4.2 nathanw printf("PowerBook extended keyboard (Japanese layout)\n");
214 1.18.4.2 nathanw break;
215 1.18.4.2 nathanw case ADB_JPKBDII:
216 1.18.4.2 nathanw printf("keyboard II (Japanese layout)\n");
217 1.18.4.2 nathanw break;
218 1.18.4.2 nathanw case ADB_PBEXTKBD:
219 1.18.4.2 nathanw printf("PowerBook extended keyboard\n");
220 1.18.4.2 nathanw break;
221 1.18.4.2 nathanw case ADB_DESIGNKBD:
222 1.18.4.2 nathanw printf("extended keyboard\n");
223 1.18.4.2 nathanw #ifdef notyet
224 1.18.4.2 nathanw blinkleds(sc);
225 1.18.4.2 nathanw #endif
226 1.18.4.2 nathanw break;
227 1.18.4.2 nathanw case ADB_PBJPKBD:
228 1.18.4.2 nathanw printf("PowerBook keyboard (Japanese layout)\n");
229 1.18.4.2 nathanw break;
230 1.18.4.2 nathanw case ADB_PBG3KBD:
231 1.18.4.2 nathanw printf("PowerBook G3 keyboard\n");
232 1.18.4.2 nathanw break;
233 1.18.4.2 nathanw case ADB_PBG3JPKBD:
234 1.18.4.2 nathanw printf("PowerBook G3 keyboard (Japanese layout)\n");
235 1.18.4.2 nathanw break;
236 1.18.4.2 nathanw default:
237 1.18.4.2 nathanw printf("mapped device (%d)\n", sc->handler_id);
238 1.18.4.2 nathanw break;
239 1.18.4.2 nathanw }
240 1.18.4.2 nathanw error = SetADBInfo(&adbinfo, sc->adbaddr);
241 1.18.4.2 nathanw #ifdef ADB_DEBUG
242 1.18.4.2 nathanw if (adb_debug)
243 1.18.4.2 nathanw printf("akbd: returned %d from SetADBInfo\n", error);
244 1.18.4.2 nathanw #endif
245 1.18.4.2 nathanw
246 1.18.4.2 nathanw if (akbd_is_console) {
247 1.18.4.3 nathanw wskbd_cnattach(&akbd_consops, sc, &akbd_keymapdata);
248 1.18.4.2 nathanw }
249 1.18.4.2 nathanw
250 1.18.4.2 nathanw a.console = akbd_is_console;
251 1.18.4.2 nathanw a.keymap = &akbd_keymapdata;
252 1.18.4.2 nathanw a.accessops = &akbd_accessops;
253 1.18.4.2 nathanw a.accesscookie = sc;
254 1.18.4.2 nathanw
255 1.18.4.2 nathanw sc->sc_wskbddev = config_found(self, &a, wskbddevprint);
256 1.18.4.2 nathanw }
257 1.18.4.2 nathanw
258 1.18.4.2 nathanw
259 1.18.4.2 nathanw /*
260 1.18.4.2 nathanw * Handle putting the keyboard data received from the ADB into
261 1.18.4.2 nathanw * an ADB event record.
262 1.18.4.2 nathanw */
263 1.18.4.2 nathanw void
264 1.18.4.2 nathanw kbd_adbcomplete(buffer, data_area, adb_command)
265 1.18.4.2 nathanw caddr_t buffer;
266 1.18.4.2 nathanw caddr_t data_area;
267 1.18.4.2 nathanw int adb_command;
268 1.18.4.2 nathanw {
269 1.18.4.2 nathanw adb_event_t event;
270 1.18.4.2 nathanw struct akbd_softc *ksc;
271 1.18.4.2 nathanw int adbaddr;
272 1.18.4.2 nathanw #ifdef ADB_DEBUG
273 1.18.4.2 nathanw int i;
274 1.18.4.2 nathanw
275 1.18.4.2 nathanw if (adb_debug)
276 1.18.4.2 nathanw printf("adb: transaction completion\n");
277 1.18.4.2 nathanw #endif
278 1.18.4.2 nathanw
279 1.18.4.2 nathanw adbaddr = ADB_CMDADDR(adb_command);
280 1.18.4.2 nathanw ksc = (struct akbd_softc *)data_area;
281 1.18.4.2 nathanw
282 1.18.4.2 nathanw event.addr = adbaddr;
283 1.18.4.2 nathanw event.hand_id = ksc->handler_id;
284 1.18.4.2 nathanw event.def_addr = ksc->origaddr;
285 1.18.4.2 nathanw event.byte_count = buffer[0];
286 1.18.4.2 nathanw memcpy(event.bytes, buffer + 1, event.byte_count);
287 1.18.4.2 nathanw
288 1.18.4.2 nathanw #ifdef ADB_DEBUG
289 1.18.4.2 nathanw if (adb_debug) {
290 1.18.4.2 nathanw printf("akbd: from %d at %d (org %d) %d:", event.addr,
291 1.18.4.2 nathanw event.hand_id, event.def_addr, buffer[0]);
292 1.18.4.2 nathanw for (i = 1; i <= buffer[0]; i++)
293 1.18.4.2 nathanw printf(" %x", buffer[i]);
294 1.18.4.2 nathanw printf("\n");
295 1.18.4.2 nathanw }
296 1.18.4.2 nathanw #endif
297 1.18.4.2 nathanw
298 1.18.4.2 nathanw microtime(&event.timestamp);
299 1.18.4.2 nathanw
300 1.18.4.2 nathanw kbd_processevent(&event, ksc);
301 1.18.4.2 nathanw }
302 1.18.4.2 nathanw
303 1.18.4.2 nathanw /*
304 1.18.4.2 nathanw * Given a keyboard ADB event, record the keycodes and call the key
305 1.18.4.2 nathanw * repeat handler, optionally passing the event through the mouse
306 1.18.4.2 nathanw * button emulation handler first.
307 1.18.4.2 nathanw */
308 1.18.4.2 nathanw static void
309 1.18.4.2 nathanw kbd_processevent(event, ksc)
310 1.18.4.2 nathanw adb_event_t *event;
311 1.18.4.2 nathanw struct akbd_softc *ksc;
312 1.18.4.2 nathanw {
313 1.18.4.2 nathanw adb_event_t new_event;
314 1.18.4.2 nathanw
315 1.18.4.2 nathanw new_event = *event;
316 1.18.4.2 nathanw new_event.u.k.key = event->bytes[0];
317 1.18.4.2 nathanw new_event.bytes[1] = 0xff;
318 1.18.4.2 nathanw kbd_intr(&new_event);
319 1.18.4.2 nathanw #if NAED > 0
320 1.18.4.2 nathanw aed_input(&new_event);
321 1.18.4.2 nathanw #endif
322 1.18.4.2 nathanw if (event->bytes[1] != 0xff) {
323 1.18.4.2 nathanw new_event.u.k.key = event->bytes[1];
324 1.18.4.2 nathanw new_event.bytes[0] = event->bytes[1];
325 1.18.4.2 nathanw new_event.bytes[1] = 0xff;
326 1.18.4.2 nathanw kbd_intr(&new_event);
327 1.18.4.2 nathanw #if NAED > 0
328 1.18.4.2 nathanw aed_input(&new_event);
329 1.18.4.2 nathanw #endif
330 1.18.4.2 nathanw }
331 1.18.4.2 nathanw
332 1.18.4.2 nathanw }
333 1.18.4.2 nathanw
334 1.18.4.2 nathanw #ifdef notyet
335 1.18.4.2 nathanw /*
336 1.18.4.2 nathanw * Get the actual hardware LED state and convert it to softc format.
337 1.18.4.2 nathanw */
338 1.18.4.2 nathanw static u_char
339 1.18.4.2 nathanw getleds(addr)
340 1.18.4.2 nathanw int addr;
341 1.18.4.2 nathanw {
342 1.18.4.2 nathanw short cmd;
343 1.18.4.2 nathanw u_char buffer[9], leds;
344 1.18.4.2 nathanw
345 1.18.4.2 nathanw leds = 0x00; /* all off */
346 1.18.4.2 nathanw buffer[0] = 0;
347 1.18.4.2 nathanw
348 1.18.4.2 nathanw /* talk R2 */
349 1.18.4.2 nathanw cmd = ADBTALK(addr, 2);
350 1.18.4.2 nathanw if (adb_op_sync((Ptr)buffer, (Ptr)0, (Ptr)0, cmd) == 0 &&
351 1.18.4.2 nathanw buffer[0] > 0)
352 1.18.4.2 nathanw leds = ~(buffer[2]) & 0x07;
353 1.18.4.2 nathanw
354 1.18.4.2 nathanw return (leds);
355 1.18.4.2 nathanw }
356 1.18.4.2 nathanw
357 1.18.4.2 nathanw /*
358 1.18.4.2 nathanw * Set the keyboard LED's.
359 1.18.4.2 nathanw *
360 1.18.4.2 nathanw * Automatically translates from ioctl/softc format to the
361 1.18.4.2 nathanw * actual keyboard register format
362 1.18.4.2 nathanw */
363 1.18.4.2 nathanw static int
364 1.18.4.2 nathanw setleds(ksc, leds)
365 1.18.4.2 nathanw struct akbd_softc *ksc;
366 1.18.4.2 nathanw u_char leds;
367 1.18.4.2 nathanw {
368 1.18.4.2 nathanw int addr;
369 1.18.4.2 nathanw short cmd;
370 1.18.4.2 nathanw u_char buffer[9];
371 1.18.4.2 nathanw
372 1.18.4.2 nathanw if ((leds & 0x07) == (ksc->sc_leds & 0x07))
373 1.18.4.2 nathanw return (0);
374 1.18.4.2 nathanw
375 1.18.4.2 nathanw addr = ksc->adbaddr;
376 1.18.4.2 nathanw buffer[0] = 0;
377 1.18.4.2 nathanw
378 1.18.4.2 nathanw cmd = ADBTALK(addr, 2);
379 1.18.4.2 nathanw if (adb_op_sync((Ptr)buffer, (Ptr)0, (Ptr)0, cmd) || buffer[0] == 0)
380 1.18.4.2 nathanw return (EIO);
381 1.18.4.2 nathanw
382 1.18.4.2 nathanw leds = ~leds & 0x07;
383 1.18.4.2 nathanw buffer[2] &= 0xf8;
384 1.18.4.2 nathanw buffer[2] |= leds;
385 1.18.4.2 nathanw
386 1.18.4.2 nathanw cmd = ADBLISTEN(addr, 2);
387 1.18.4.2 nathanw adb_op_sync((Ptr)buffer, (Ptr)0, (Ptr)0, cmd);
388 1.18.4.2 nathanw
389 1.18.4.2 nathanw cmd = ADBTALK(addr, 2);
390 1.18.4.2 nathanw if (adb_op_sync((Ptr)buffer, (Ptr)0, (Ptr)0, cmd) || buffer[0] == 0)
391 1.18.4.2 nathanw return (EIO);
392 1.18.4.2 nathanw
393 1.18.4.2 nathanw ksc->sc_leds = ~((u_int8_t)buffer[2]) & 0x07;
394 1.18.4.2 nathanw
395 1.18.4.2 nathanw if ((buffer[2] & 0xf8) != leds)
396 1.18.4.2 nathanw return (EIO);
397 1.18.4.2 nathanw else
398 1.18.4.2 nathanw return (0);
399 1.18.4.2 nathanw }
400 1.18.4.2 nathanw
401 1.18.4.2 nathanw /*
402 1.18.4.2 nathanw * Toggle all of the LED's on and off, just for show.
403 1.18.4.2 nathanw */
404 1.18.4.2 nathanw static void
405 1.18.4.2 nathanw blinkleds(ksc)
406 1.18.4.2 nathanw struct akbd_softc *ksc;
407 1.18.4.2 nathanw {
408 1.18.4.2 nathanw int addr, i;
409 1.18.4.2 nathanw u_char blinkleds, origleds;
410 1.18.4.2 nathanw
411 1.18.4.2 nathanw addr = ksc->adbaddr;
412 1.18.4.2 nathanw origleds = getleds(addr);
413 1.18.4.2 nathanw blinkleds = LED_NUMLOCK | LED_CAPSLOCK | LED_SCROLL_LOCK;
414 1.18.4.2 nathanw
415 1.18.4.2 nathanw (void)setleds(ksc, blinkleds);
416 1.18.4.2 nathanw
417 1.18.4.2 nathanw for (i = 0; i < 10000; i++)
418 1.18.4.2 nathanw delay(50);
419 1.18.4.2 nathanw
420 1.18.4.2 nathanw /* make sure that we restore the LED settings */
421 1.18.4.2 nathanw i = 10;
422 1.18.4.2 nathanw do {
423 1.18.4.2 nathanw (void)setleds(ksc, (u_char)0x00);
424 1.18.4.2 nathanw } while (setleds(ksc, (u_char)0x00) && (i-- > 0));
425 1.18.4.2 nathanw
426 1.18.4.2 nathanw return;
427 1.18.4.2 nathanw }
428 1.18.4.2 nathanw #endif
429 1.18.4.2 nathanw
430 1.18.4.2 nathanw int
431 1.18.4.2 nathanw akbd_enable(v, on)
432 1.18.4.2 nathanw void *v;
433 1.18.4.2 nathanw int on;
434 1.18.4.2 nathanw {
435 1.18.4.2 nathanw return 0;
436 1.18.4.2 nathanw }
437 1.18.4.2 nathanw
438 1.18.4.2 nathanw void
439 1.18.4.2 nathanw akbd_set_leds(v, on)
440 1.18.4.2 nathanw void *v;
441 1.18.4.2 nathanw int on;
442 1.18.4.2 nathanw {
443 1.18.4.2 nathanw }
444 1.18.4.2 nathanw
445 1.18.4.2 nathanw int
446 1.18.4.2 nathanw akbd_ioctl(v, cmd, data, flag, p)
447 1.18.4.2 nathanw void *v;
448 1.18.4.2 nathanw u_long cmd;
449 1.18.4.2 nathanw caddr_t data;
450 1.18.4.2 nathanw int flag;
451 1.18.4.2 nathanw struct proc *p;
452 1.18.4.2 nathanw {
453 1.18.4.2 nathanw switch (cmd) {
454 1.18.4.2 nathanw
455 1.18.4.2 nathanw case WSKBDIO_GTYPE:
456 1.18.4.2 nathanw *(int *)data = WSKBD_TYPE_ADB;
457 1.18.4.2 nathanw return 0;
458 1.18.4.2 nathanw case WSKBDIO_SETLEDS:
459 1.18.4.2 nathanw return 0;
460 1.18.4.2 nathanw case WSKBDIO_GETLEDS:
461 1.18.4.2 nathanw *(int *)data = 0;
462 1.18.4.2 nathanw return 0;
463 1.18.4.2 nathanw }
464 1.18.4.2 nathanw /* kbdioctl(...); */
465 1.18.4.2 nathanw
466 1.18.4.2 nathanw return -1;
467 1.18.4.2 nathanw }
468 1.18.4.2 nathanw
469 1.18.4.2 nathanw extern int adb_polling;
470 1.18.4.2 nathanw
471 1.18.4.3 nathanw void
472 1.18.4.3 nathanw kbd_passup(sc,key)
473 1.18.4.3 nathanw struct akbd_softc *sc;
474 1.18.4.3 nathanw int key;
475 1.18.4.3 nathanw {
476 1.18.4.3 nathanw if (sc->sc_polling) {
477 1.18.4.3 nathanw if (sc->sc_npolledkeys <
478 1.18.4.3 nathanw (sizeof(sc->sc_polledkeys)/sizeof(unsigned char))) {
479 1.18.4.3 nathanw sc->sc_polledkeys[sc->sc_npolledkeys++] = key;
480 1.18.4.3 nathanw }
481 1.18.4.3 nathanw #ifdef ADB_DEBUG
482 1.18.4.3 nathanw else {
483 1.18.4.3 nathanw printf("akbd: dumping polled key 0x%02x\n",key);
484 1.18.4.3 nathanw }
485 1.18.4.3 nathanw #endif
486 1.18.4.3 nathanw } else {
487 1.18.4.3 nathanw int press, val;
488 1.18.4.3 nathanw int type;
489 1.18.4.3 nathanw
490 1.18.4.3 nathanw press = ADBK_PRESS(key);
491 1.18.4.3 nathanw val = ADBK_KEYVAL(key);
492 1.18.4.3 nathanw
493 1.18.4.3 nathanw type = press ? WSCONS_EVENT_KEY_DOWN : WSCONS_EVENT_KEY_UP;
494 1.18.4.3 nathanw
495 1.18.4.3 nathanw wskbd_input(sc->sc_wskbddev, type, val);
496 1.18.4.3 nathanw }
497 1.18.4.3 nathanw }
498 1.18.4.3 nathanw
499 1.18.4.2 nathanw int
500 1.18.4.2 nathanw kbd_intr(arg)
501 1.18.4.2 nathanw void *arg;
502 1.18.4.2 nathanw {
503 1.18.4.2 nathanw adb_event_t *event = arg;
504 1.18.4.3 nathanw int key;
505 1.18.4.2 nathanw
506 1.18.4.2 nathanw struct akbd_softc *sc = akbd_cd.cd_devs[0];
507 1.18.4.2 nathanw
508 1.18.4.2 nathanw key = event->u.k.key;
509 1.18.4.2 nathanw
510 1.18.4.2 nathanw switch (key) {
511 1.18.4.2 nathanw case 57: /* Caps Lock pressed */
512 1.18.4.2 nathanw case 185: /* Caps Lock released */
513 1.18.4.3 nathanw key = ADBK_KEYDOWN(ADBK_KEYVAL(key));
514 1.18.4.3 nathanw kbd_passup(sc,key);
515 1.18.4.3 nathanw key = ADBK_KEYUP(ADBK_KEYVAL(key));
516 1.18.4.2 nathanw break;
517 1.18.4.2 nathanw case 245:
518 1.18.4.2 nathanw if (pcmcia_soft_eject)
519 1.18.4.2 nathanw pm_eject_pcmcia(0);
520 1.18.4.2 nathanw break;
521 1.18.4.2 nathanw case 244:
522 1.18.4.2 nathanw if (pcmcia_soft_eject)
523 1.18.4.2 nathanw pm_eject_pcmcia(1);
524 1.18.4.2 nathanw break;
525 1.18.4.2 nathanw }
526 1.18.4.2 nathanw
527 1.18.4.3 nathanw kbd_passup(sc,key);
528 1.18.4.2 nathanw
529 1.18.4.2 nathanw return 0;
530 1.18.4.2 nathanw }
531 1.18.4.2 nathanw
532 1.18.4.2 nathanw int
533 1.18.4.2 nathanw akbd_cnattach()
534 1.18.4.2 nathanw {
535 1.18.4.2 nathanw
536 1.18.4.2 nathanw akbd_is_console = 1;
537 1.18.4.2 nathanw return 0;
538 1.18.4.2 nathanw }
539 1.18.4.2 nathanw
540 1.18.4.2 nathanw void
541 1.18.4.2 nathanw akbd_cngetc(v, type, data)
542 1.18.4.2 nathanw void *v;
543 1.18.4.2 nathanw u_int *type;
544 1.18.4.2 nathanw int *data;
545 1.18.4.2 nathanw {
546 1.18.4.2 nathanw int key, press, val;
547 1.18.4.2 nathanw int s;
548 1.18.4.3 nathanw struct akbd_softc *sc = v;
549 1.18.4.2 nathanw
550 1.18.4.2 nathanw s = splhigh();
551 1.18.4.2 nathanw
552 1.18.4.3 nathanw KASSERT(sc->sc_polling);
553 1.18.4.3 nathanw KASSERT(adb_polling);
554 1.18.4.2 nathanw
555 1.18.4.3 nathanw while (sc->sc_npolledkeys == 0) {
556 1.18.4.2 nathanw adb_intr();
557 1.18.4.2 nathanw DELAY(10000); /* XXX */
558 1.18.4.2 nathanw }
559 1.18.4.2 nathanw
560 1.18.4.2 nathanw splx(s);
561 1.18.4.2 nathanw
562 1.18.4.3 nathanw key = sc->sc_polledkeys[0];
563 1.18.4.3 nathanw sc->sc_npolledkeys--;
564 1.18.4.3 nathanw memmove(sc->sc_polledkeys,sc->sc_polledkeys+1,
565 1.18.4.3 nathanw sc->sc_npolledkeys * sizeof(unsigned char));
566 1.18.4.3 nathanw
567 1.18.4.2 nathanw press = ADBK_PRESS(key);
568 1.18.4.2 nathanw val = ADBK_KEYVAL(key);
569 1.18.4.2 nathanw
570 1.18.4.2 nathanw *data = val;
571 1.18.4.2 nathanw *type = press ? WSCONS_EVENT_KEY_DOWN : WSCONS_EVENT_KEY_UP;
572 1.18.4.2 nathanw }
573 1.18.4.2 nathanw
574 1.18.4.2 nathanw void
575 1.18.4.2 nathanw akbd_cnpollc(v, on)
576 1.18.4.2 nathanw void *v;
577 1.18.4.2 nathanw int on;
578 1.18.4.2 nathanw {
579 1.18.4.3 nathanw struct akbd_softc *sc = v;
580 1.18.4.3 nathanw sc->sc_polling = on;
581 1.18.4.3 nathanw if (!on) {
582 1.18.4.3 nathanw int i;
583 1.18.4.3 nathanw for(i=0;i<sc->sc_npolledkeys;i++) {
584 1.18.4.3 nathanw kbd_passup(sc,sc->sc_polledkeys[i]);
585 1.18.4.3 nathanw }
586 1.18.4.3 nathanw sc->sc_npolledkeys = 0;
587 1.18.4.3 nathanw }
588 1.18.4.3 nathanw adb_polling = on;
589 1.18.4.2 nathanw }
590