kbd.c revision 1.8 1 1.8 leo /* $NetBSD: kbd.c,v 1.8 1996/03/27 12:15:28 leo Exp $ */
2 1.1 leo
3 1.1 leo /*
4 1.1 leo * Copyright (c) 1995 Leo Weppelman
5 1.1 leo * Copyright (c) 1982, 1986, 1990 The Regents of the University of California.
6 1.1 leo * All rights reserved.
7 1.1 leo *
8 1.1 leo * Redistribution and use in source and binary forms, with or without
9 1.1 leo * modification, are permitted provided that the following conditions
10 1.1 leo * are met:
11 1.1 leo * 1. Redistributions of source code must retain the above copyright
12 1.1 leo * notice, this list of conditions and the following disclaimer.
13 1.1 leo * 2. Redistributions in binary form must reproduce the above copyright
14 1.1 leo * notice, this list of conditions and the following disclaimer in the
15 1.1 leo * documentation and/or other materials provided with the distribution.
16 1.1 leo * 3. All advertising materials mentioning features or use of this software
17 1.1 leo * must display the following acknowledgement:
18 1.1 leo * This product includes software developed by the University of
19 1.1 leo * California, Berkeley and its contributors.
20 1.1 leo * 4. Neither the name of the University nor the names of its contributors
21 1.1 leo * may be used to endorse or promote products derived from this software
22 1.1 leo * without specific prior written permission.
23 1.1 leo *
24 1.1 leo * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
25 1.1 leo * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
26 1.1 leo * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
27 1.1 leo * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
28 1.1 leo * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
29 1.1 leo * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
30 1.1 leo * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
31 1.1 leo * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
32 1.1 leo * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
33 1.1 leo * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
34 1.1 leo * SUCH DAMAGE.
35 1.1 leo */
36 1.1 leo
37 1.1 leo #include <sys/param.h>
38 1.1 leo #include <sys/systm.h>
39 1.1 leo #include <sys/device.h>
40 1.1 leo #include <sys/ioctl.h>
41 1.1 leo #include <sys/tty.h>
42 1.1 leo #include <sys/proc.h>
43 1.1 leo #include <sys/conf.h>
44 1.1 leo #include <sys/file.h>
45 1.1 leo #include <sys/kernel.h>
46 1.1 leo #include <sys/syslog.h>
47 1.1 leo #include <dev/cons.h>
48 1.1 leo #include <machine/cpu.h>
49 1.1 leo #include <machine/iomap.h>
50 1.1 leo #include <machine/mfp.h>
51 1.1 leo #include <machine/acia.h>
52 1.8 leo #include <atari/dev/ym2149reg.h>
53 1.1 leo #include <atari/dev/itevar.h>
54 1.1 leo #include <atari/dev/kbdreg.h>
55 1.1 leo #include <atari/dev/event_var.h>
56 1.1 leo #include <atari/dev/vuid_event.h>
57 1.1 leo
58 1.5 leo #include "mouse.h"
59 1.5 leo
60 1.1 leo /*
61 1.1 leo * The ringbuffer is the interface between the hard and soft interrupt handler.
62 1.1 leo * The hard interrupt runs straight from the MFP interrupt.
63 1.1 leo */
64 1.3 leo #define KBD_RING_SIZE 256 /* Sz of input ring buffer, must be power of 2 */
65 1.3 leo #define KBD_RING_MASK 255 /* Modulo mask for above */
66 1.1 leo
67 1.1 leo static u_char kbd_ring[KBD_RING_SIZE];
68 1.1 leo static volatile u_int kbd_rbput = 0; /* 'put' index */
69 1.1 leo static u_int kbd_rbget = 0; /* 'get' index */
70 1.1 leo static u_char kbd_soft = 0; /* 1: Softint has been scheduled*/
71 1.1 leo
72 1.1 leo struct kbd_softc {
73 1.1 leo int k_event_mode; /* if 1, collect events, */
74 1.1 leo /* else pass to ite */
75 1.1 leo struct evvar k_events; /* event queue state */
76 1.3 leo u_char k_soft_cs; /* control-reg. copy */
77 1.3 leo u_char k_package[20]; /* XXX package being build */
78 1.3 leo u_char k_pkg_size; /* Size of the package */
79 1.3 leo u_char k_pkg_idx;
80 1.3 leo u_char *k_sendp; /* Output pointer */
81 1.3 leo int k_send_cnt; /* Chars left for output */
82 1.1 leo };
83 1.1 leo
84 1.1 leo static struct kbd_softc kbd_softc;
85 1.1 leo
86 1.6 leo /* {b,c}devsw[] function prototypes */
87 1.6 leo dev_type_open(kbdopen);
88 1.6 leo dev_type_close(kbdclose);
89 1.6 leo dev_type_read(kbdread);
90 1.6 leo dev_type_ioctl(kbdioctl);
91 1.6 leo dev_type_select(kbdselect);
92 1.6 leo
93 1.6 leo /* Interrupt handler */
94 1.6 leo void kbdintr __P((int));
95 1.6 leo
96 1.4 leo void kbd_write __P((u_char *, int));
97 1.4 leo
98 1.1 leo static void kbdsoft __P((void));
99 1.1 leo static void kbdattach __P((struct device *, struct device *, void *));
100 1.7 thorpej static int kbdmatch __P((struct device *, void *, void *));
101 1.4 leo static int kbd_write_poll __P((u_char *, int));
102 1.3 leo static void kbd_pkg_start __P((struct kbd_softc *, u_char));
103 1.1 leo
104 1.7 thorpej struct cfattach kbd_ca = {
105 1.7 thorpej sizeof(struct device), kbdmatch, kbdattach
106 1.7 thorpej };
107 1.1 leo
108 1.7 thorpej struct cfdriver kbd_cd = {
109 1.7 thorpej NULL, "kbd", DV_DULL, NULL, 0
110 1.7 thorpej };
111 1.1 leo
112 1.1 leo /*ARGSUSED*/
113 1.1 leo static int
114 1.7 thorpej kbdmatch(pdp, match, auxp)
115 1.1 leo struct device *pdp;
116 1.7 thorpej void *match, *auxp;
117 1.1 leo {
118 1.3 leo if (!strcmp((char *)auxp, "kbd"))
119 1.3 leo return (1);
120 1.3 leo return (0);
121 1.1 leo }
122 1.1 leo
123 1.1 leo /*ARGSUSED*/
124 1.1 leo static void
125 1.1 leo kbdattach(pdp, dp, auxp)
126 1.1 leo struct device *pdp, *dp;
127 1.1 leo void *auxp;
128 1.1 leo {
129 1.3 leo int timeout;
130 1.4 leo u_char kbd_rst[] = { 0x80, 0x01 };
131 1.4 leo u_char kbd_icmd[] = { 0x12, 0x15 };
132 1.3 leo
133 1.3 leo /*
134 1.3 leo * Disable keyboard interrupts from MFP
135 1.3 leo */
136 1.3 leo MFP->mf_ierb &= ~IB_AINT;
137 1.3 leo
138 1.3 leo /*
139 1.3 leo * Reset ACIA and intialize to:
140 1.3 leo * divide by 16, 8 data, 1 stop, no parity, enable RX interrupts
141 1.3 leo */
142 1.3 leo KBD->ac_cs = A_RESET;
143 1.3 leo delay(100); /* XXX: enough? */
144 1.3 leo KBD->ac_cs = kbd_softc.k_soft_cs = KBD_INIT | A_RXINT;
145 1.3 leo
146 1.3 leo /*
147 1.3 leo * Clear error conditions
148 1.3 leo */
149 1.3 leo while (KBD->ac_cs & (A_IRQ|A_RXRDY))
150 1.3 leo timeout = KBD->ac_da;
151 1.3 leo
152 1.3 leo /*
153 1.3 leo * Now send the reset string, and read+ignore it's response
154 1.3 leo */
155 1.4 leo if (!kbd_write_poll(kbd_rst, 2))
156 1.3 leo printf("kbd: error cannot reset keyboard\n");
157 1.3 leo for (timeout = 1000; timeout > 0; timeout--) {
158 1.3 leo if (KBD->ac_cs & (A_IRQ|A_RXRDY)) {
159 1.3 leo timeout = KBD->ac_da;
160 1.3 leo timeout = 100;
161 1.3 leo }
162 1.3 leo delay(100);
163 1.3 leo }
164 1.4 leo /*
165 1.4 leo * Send init command: disable mice & joysticks
166 1.4 leo */
167 1.4 leo kbd_write_poll(kbd_icmd, sizeof(kbd_icmd));
168 1.3 leo
169 1.1 leo printf("\n");
170 1.1 leo }
171 1.1 leo
172 1.1 leo /* definitions for atari keyboard encoding. */
173 1.3 leo #define KEY_CODE(c) ((u_char)(c) & 0x7f)
174 1.3 leo #define KEY_UP(c) ((u_char)(c) & 0x80)
175 1.3 leo #define IS_KEY(c) ((u_char)(c) < 0xf6)
176 1.1 leo
177 1.1 leo void
178 1.1 leo kbdenable()
179 1.1 leo {
180 1.3 leo int s, code;
181 1.1 leo
182 1.1 leo s = spltty();
183 1.3 leo
184 1.1 leo /*
185 1.3 leo * Clear error conditions...
186 1.1 leo */
187 1.3 leo while (KBD->ac_cs & (A_IRQ|A_RXRDY))
188 1.3 leo code = KBD->ac_da;
189 1.1 leo /*
190 1.1 leo * Enable interrupts from MFP
191 1.1 leo */
192 1.1 leo MFP->mf_iprb &= ~IB_AINT;
193 1.1 leo MFP->mf_ierb |= IB_AINT;
194 1.1 leo MFP->mf_imrb |= IB_AINT;
195 1.1 leo
196 1.1 leo kbd_softc.k_event_mode = 0;
197 1.1 leo kbd_softc.k_events.ev_io = 0;
198 1.3 leo kbd_softc.k_pkg_size = 0;
199 1.1 leo splx(s);
200 1.1 leo }
201 1.1 leo
202 1.1 leo int kbdopen(dev_t dev, int flags, int mode, struct proc *p)
203 1.1 leo {
204 1.3 leo if (kbd_softc.k_events.ev_io)
205 1.1 leo return EBUSY;
206 1.1 leo
207 1.1 leo kbd_softc.k_events.ev_io = p;
208 1.1 leo ev_init(&kbd_softc.k_events);
209 1.1 leo return (0);
210 1.1 leo }
211 1.1 leo
212 1.1 leo int
213 1.1 leo kbdclose(dev_t dev, int flags, int mode, struct proc *p)
214 1.1 leo {
215 1.1 leo /* Turn off event mode, dump the queue */
216 1.1 leo kbd_softc.k_event_mode = 0;
217 1.1 leo ev_fini(&kbd_softc.k_events);
218 1.1 leo kbd_softc.k_events.ev_io = NULL;
219 1.1 leo return (0);
220 1.1 leo }
221 1.1 leo
222 1.1 leo int
223 1.1 leo kbdread(dev_t dev, struct uio *uio, int flags)
224 1.1 leo {
225 1.1 leo return ev_read(&kbd_softc.k_events, uio, flags);
226 1.1 leo }
227 1.1 leo
228 1.1 leo int
229 1.1 leo kbdioctl(dev_t dev,u_long cmd,register caddr_t data,int flag,struct proc *p)
230 1.1 leo {
231 1.1 leo register struct kbd_softc *k = &kbd_softc;
232 1.1 leo
233 1.1 leo switch (cmd) {
234 1.1 leo case KIOCTRANS:
235 1.3 leo if (*(int *)data == TR_UNTRANS_EVENT)
236 1.1 leo return 0;
237 1.1 leo break;
238 1.1 leo
239 1.1 leo case KIOCGTRANS:
240 1.1 leo /*
241 1.1 leo * Get translation mode
242 1.1 leo */
243 1.1 leo *(int *)data = TR_UNTRANS_EVENT;
244 1.1 leo return 0;
245 1.1 leo
246 1.1 leo case KIOCSDIRECT:
247 1.1 leo k->k_event_mode = *(int *)data;
248 1.1 leo return 0;
249 1.1 leo
250 1.1 leo case FIONBIO: /* we will remove this someday (soon???) */
251 1.1 leo return 0;
252 1.1 leo
253 1.1 leo case FIOASYNC:
254 1.1 leo k->k_events.ev_async = *(int *)data != 0;
255 1.1 leo return 0;
256 1.1 leo
257 1.1 leo case TIOCSPGRP:
258 1.3 leo if (*(int *)data != k->k_events.ev_io->p_pgid)
259 1.1 leo return EPERM;
260 1.1 leo return 0;
261 1.1 leo
262 1.1 leo default:
263 1.1 leo return ENOTTY;
264 1.1 leo }
265 1.1 leo
266 1.1 leo /*
267 1.1 leo * We identified the ioctl, but we do not handle it.
268 1.1 leo */
269 1.1 leo return EOPNOTSUPP; /* misuse, but what the heck */
270 1.1 leo }
271 1.1 leo
272 1.1 leo int
273 1.1 leo kbdselect (dev_t dev, int rw, struct proc *p)
274 1.1 leo {
275 1.1 leo return ev_select (&kbd_softc.k_events, rw, p);
276 1.1 leo }
277 1.1 leo
278 1.1 leo /*
279 1.3 leo * Keyboard interrupt handler called straight from MFP at spl6.
280 1.1 leo */
281 1.6 leo void
282 1.1 leo kbdintr(sr)
283 1.1 leo int sr; /* sr at time of interrupt */
284 1.1 leo {
285 1.1 leo int code;
286 1.3 leo int got_char = 0;
287 1.1 leo
288 1.1 leo /*
289 1.1 leo * There may be multiple keys available. Read them all.
290 1.1 leo */
291 1.3 leo while (KBD->ac_cs & (A_RXRDY|A_OE|A_PE)) {
292 1.3 leo got_char = 1;
293 1.3 leo if (KBD->ac_cs & (A_OE|A_PE)) {
294 1.3 leo code = KBD->ac_da; /* Silently ignore errors */
295 1.1 leo continue;
296 1.1 leo }
297 1.1 leo kbd_ring[kbd_rbput++ & KBD_RING_MASK] = KBD->ac_da;
298 1.1 leo }
299 1.3 leo
300 1.3 leo /*
301 1.3 leo * If characters are waiting for transmit, send them.
302 1.3 leo */
303 1.3 leo if ((kbd_softc.k_soft_cs & A_TXINT) && (KBD->ac_cs & A_TXRDY)) {
304 1.3 leo if (kbd_softc.k_sendp != NULL)
305 1.3 leo KBD->ac_da = *kbd_softc.k_sendp++;
306 1.3 leo if (--kbd_softc.k_send_cnt <= 0) {
307 1.3 leo /*
308 1.3 leo * The total package has been transmitted,
309 1.3 leo * wakeup anyone waiting for it.
310 1.3 leo */
311 1.3 leo KBD->ac_cs = (kbd_softc.k_soft_cs &= ~A_TXINT);
312 1.3 leo kbd_softc.k_sendp = NULL;
313 1.3 leo kbd_softc.k_send_cnt = 0;
314 1.3 leo wakeup((caddr_t)&kbd_softc.k_send_cnt);
315 1.3 leo }
316 1.3 leo }
317 1.3 leo
318 1.3 leo /*
319 1.3 leo * Activate software-level to handle possible input.
320 1.3 leo */
321 1.3 leo if (got_char) {
322 1.3 leo if (!BASEPRI(sr)) {
323 1.3 leo if (!kbd_soft++)
324 1.3 leo add_sicallback(kbdsoft, 0, 0);
325 1.3 leo } else {
326 1.3 leo spl1();
327 1.3 leo kbdsoft();
328 1.3 leo }
329 1.1 leo }
330 1.1 leo }
331 1.1 leo
332 1.1 leo /*
333 1.1 leo * Keyboard soft interrupt handler
334 1.1 leo */
335 1.1 leo void
336 1.1 leo kbdsoft()
337 1.1 leo {
338 1.1 leo int s;
339 1.1 leo u_char code;
340 1.1 leo struct kbd_softc *k = &kbd_softc;
341 1.1 leo struct firm_event *fe;
342 1.1 leo int put;
343 1.1 leo int n, get;
344 1.1 leo
345 1.1 leo kbd_soft = 0;
346 1.1 leo get = kbd_rbget;
347 1.1 leo
348 1.3 leo for (;;) {
349 1.1 leo n = kbd_rbput;
350 1.3 leo if (get == n) /* We're done */
351 1.1 leo break;
352 1.1 leo n -= get;
353 1.3 leo if (n > KBD_RING_SIZE) { /* Ring buffer overflow */
354 1.1 leo get += n - KBD_RING_SIZE;
355 1.1 leo n = KBD_RING_SIZE;
356 1.1 leo }
357 1.3 leo while (--n >= 0) {
358 1.1 leo code = kbd_ring[get++ & KBD_RING_MASK];
359 1.1 leo
360 1.1 leo /*
361 1.3 leo * If collecting a package, stuff it in and
362 1.3 leo * continue.
363 1.3 leo */
364 1.3 leo if (k->k_pkg_size && (k->k_pkg_idx < k->k_pkg_size)) {
365 1.3 leo k->k_package[k->k_pkg_idx++] = code;
366 1.3 leo if (k->k_pkg_idx == k->k_pkg_size) {
367 1.3 leo k->k_pkg_size = 0;
368 1.5 leo #if NMOUSE > 0
369 1.3 leo /*
370 1.3 leo * Package is complete, we can now
371 1.4 leo * send it to the mouse driver...
372 1.3 leo */
373 1.4 leo mouse_soft(k->k_package, k->k_pkg_size);
374 1.5 leo #endif /* NMOUSE */
375 1.3 leo }
376 1.3 leo continue;
377 1.3 leo }
378 1.3 leo /*
379 1.3 leo * If this is a package header, init pkg. handling.
380 1.3 leo */
381 1.3 leo if (!IS_KEY(code)) {
382 1.3 leo kbd_pkg_start(k, code);
383 1.3 leo continue;
384 1.3 leo }
385 1.3 leo /*
386 1.1 leo * if not in event mode, deliver straight to ite to
387 1.1 leo * process key stroke
388 1.1 leo */
389 1.3 leo if (!k->k_event_mode) {
390 1.1 leo /* Gets to spltty() by itself */
391 1.1 leo ite_filter(code, ITEFILT_TTY);
392 1.1 leo continue;
393 1.1 leo }
394 1.1 leo
395 1.1 leo /*
396 1.1 leo * Keyboard is generating events. Turn this keystroke
397 1.1 leo * into an event and put it in the queue. If the queue
398 1.1 leo * is full, the keystroke is lost (sorry!).
399 1.1 leo */
400 1.1 leo s = spltty();
401 1.1 leo put = k->k_events.ev_put;
402 1.1 leo fe = &k->k_events.ev_q[put];
403 1.1 leo put = (put + 1) % EV_QSIZE;
404 1.3 leo if (put == k->k_events.ev_get) {
405 1.1 leo log(LOG_WARNING,
406 1.1 leo "keyboard event queue overflow\n");
407 1.1 leo splx(s);
408 1.1 leo continue;
409 1.1 leo }
410 1.1 leo fe->id = KEY_CODE(code);
411 1.1 leo fe->value = KEY_UP(code) ? VKEY_UP : VKEY_DOWN;
412 1.1 leo fe->time = time;
413 1.1 leo k->k_events.ev_put = put;
414 1.1 leo EV_WAKEUP(&k->k_events);
415 1.1 leo splx(s);
416 1.1 leo }
417 1.1 leo kbd_rbget = get;
418 1.1 leo }
419 1.1 leo }
420 1.1 leo
421 1.1 leo static char sound[] = {
422 1.1 leo 0xA8,0x01,0xA9,0x01,0xAA,0x01,0x00,
423 1.1 leo 0xF8,0x10,0x10,0x10,0x00,0x20,0x03
424 1.1 leo };
425 1.1 leo
426 1.6 leo void
427 1.1 leo kbdbell()
428 1.1 leo {
429 1.3 leo register int i, sps;
430 1.1 leo
431 1.3 leo sps = spltty();
432 1.3 leo for (i = 0; i < sizeof(sound); i++) {
433 1.8 leo YM2149->sd_selr = i;
434 1.8 leo YM2149->sd_wdat = sound[i];
435 1.3 leo }
436 1.3 leo splx(sps);
437 1.1 leo }
438 1.1 leo
439 1.1 leo int
440 1.1 leo kbdgetcn()
441 1.1 leo {
442 1.1 leo u_char code;
443 1.4 leo int s = spltty();
444 1.4 leo int ints_active;
445 1.1 leo
446 1.4 leo ints_active = 0;
447 1.4 leo if (MFP->mf_imrb & IB_AINT) {
448 1.4 leo ints_active = 1;
449 1.4 leo MFP->mf_imrb &= ~IB_AINT;
450 1.4 leo }
451 1.3 leo for (;;) {
452 1.4 leo while (!((KBD->ac_cs & (A_IRQ|A_RXRDY)) == (A_IRQ|A_RXRDY)))
453 1.3 leo ; /* Wait for key */
454 1.3 leo if (KBD->ac_cs & (A_OE|A_PE)) {
455 1.3 leo code = KBD->ac_da; /* Silently ignore errors */
456 1.3 leo continue;
457 1.3 leo }
458 1.3 leo break;
459 1.3 leo }
460 1.1 leo
461 1.4 leo code = KBD->ac_da;
462 1.4 leo if (ints_active) {
463 1.4 leo MFP->mf_iprb &= ~IB_AINT;
464 1.4 leo MFP->mf_imrb |= IB_AINT;
465 1.4 leo }
466 1.1 leo
467 1.1 leo splx (s);
468 1.1 leo return code;
469 1.3 leo }
470 1.3 leo
471 1.3 leo /*
472 1.3 leo * Write a command to the keyboard in 'polled' mode.
473 1.3 leo */
474 1.3 leo static int
475 1.4 leo kbd_write_poll(cmd, len)
476 1.3 leo u_char *cmd;
477 1.3 leo int len;
478 1.3 leo {
479 1.3 leo int timeout;
480 1.3 leo
481 1.3 leo while (len-- > 0) {
482 1.3 leo KBD->ac_da = *cmd++;
483 1.3 leo for (timeout = 100; !(KBD->ac_cs & A_TXRDY); timeout--)
484 1.3 leo delay(10);
485 1.3 leo if (!(KBD->ac_cs & A_TXRDY))
486 1.3 leo return (0);
487 1.3 leo }
488 1.3 leo return (1);
489 1.3 leo }
490 1.3 leo
491 1.3 leo /*
492 1.3 leo * Write a command to the keyboard. Return when command is send.
493 1.3 leo */
494 1.4 leo void
495 1.3 leo kbd_write(cmd, len)
496 1.3 leo u_char *cmd;
497 1.3 leo int len;
498 1.3 leo {
499 1.3 leo struct kbd_softc *k = &kbd_softc;
500 1.3 leo int sps;
501 1.3 leo
502 1.3 leo /*
503 1.3 leo * Get to splhigh, 'real' interrupts arrive at spl6!
504 1.3 leo */
505 1.3 leo sps = splhigh();
506 1.3 leo
507 1.3 leo /*
508 1.3 leo * Make sure any privious write has ended...
509 1.3 leo */
510 1.3 leo while (k->k_sendp != NULL)
511 1.3 leo tsleep((caddr_t)&k->k_sendp, TTOPRI, "kbd_write1", 0);
512 1.3 leo
513 1.3 leo /*
514 1.3 leo * If the KBD-acia is not currently busy, send the first
515 1.3 leo * character now.
516 1.3 leo */
517 1.3 leo KBD->ac_cs = (k->k_soft_cs |= A_TXINT);
518 1.3 leo if (KBD->ac_cs & A_TXRDY) {
519 1.3 leo KBD->ac_da = *cmd++;
520 1.3 leo len--;
521 1.3 leo }
522 1.3 leo
523 1.3 leo /*
524 1.3 leo * If we're not yet done, wait until all characters are send.
525 1.3 leo */
526 1.3 leo if (len > 0) {
527 1.3 leo k->k_sendp = cmd;
528 1.3 leo k->k_send_cnt = len;
529 1.3 leo tsleep((caddr_t)&k->k_send_cnt, TTOPRI, "kbd_write2", 0);
530 1.3 leo }
531 1.3 leo splx(sps);
532 1.3 leo
533 1.3 leo /*
534 1.3 leo * Wakeup all procs waiting for us.
535 1.3 leo */
536 1.3 leo wakeup((caddr_t)&k->k_sendp);
537 1.3 leo }
538 1.3 leo
539 1.3 leo /*
540 1.3 leo * Setup softc-fields to assemble a keyboard package.
541 1.3 leo */
542 1.3 leo static void
543 1.3 leo kbd_pkg_start(kp, msg_start)
544 1.3 leo struct kbd_softc *kp;
545 1.3 leo u_char msg_start;
546 1.3 leo {
547 1.3 leo kp->k_pkg_idx = 1;
548 1.3 leo kp->k_package[0] = msg_start;
549 1.3 leo switch (msg_start) {
550 1.3 leo case 0xf6:
551 1.3 leo kp->k_pkg_size = 8;
552 1.3 leo break;
553 1.3 leo case 0xf7:
554 1.3 leo kp->k_pkg_size = 6;
555 1.3 leo break;
556 1.3 leo case 0xf8:
557 1.3 leo case 0xf9:
558 1.3 leo case 0xfa:
559 1.3 leo case 0xfb:
560 1.3 leo kp->k_pkg_size = 3;
561 1.3 leo break;
562 1.3 leo case 0xfc:
563 1.3 leo kp->k_pkg_size = 7;
564 1.3 leo break;
565 1.3 leo case 0xfe:
566 1.3 leo case 0xff:
567 1.3 leo kp->k_pkg_size = 2;
568 1.3 leo break;
569 1.3 leo default:
570 1.3 leo printf("kbd: Unknown packet 0x%x\n", msg_start);
571 1.3 leo break;
572 1.3 leo }
573 1.1 leo }
574