2 * Copyright (c) 1999 FreeBSD(98) port team.
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
8 * 1. Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer as
10 * the first lines of this file unmodified.
11 * 2. Redistributions in binary form must reproduce the above copyright
12 * notice, this list of conditions and the following disclaimer in the
13 * documentation and/or other materials provided with the distribution.
14 * 3. The name of the author may not be used to endorse or promote products
15 * derived from this software without specific prior written permission.
17 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
18 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
19 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
20 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
21 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
22 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
23 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
24 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
25 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
26 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
31 #include "opt_compat.h"
34 #include <sys/param.h>
35 #include <sys/systm.h>
36 #include <sys/kernel.h>
37 #include <sys/module.h>
39 #include <machine/bus.h>
43 #include <machine/resource.h>
45 #include <dev/kbd/kbdreg.h>
47 #include <pc98/cbus/cbus.h>
48 #include <isa/isavar.h>
50 #define DRIVER_NAME "pckbd"
52 /* device configuration flags */
53 #define KB_CONF_FAIL_IF_NO_KBD (1 << 0) /* don't install if no kbd is found */
57 typedef struct pckbd_state {
58 KBDC kbdc; /* keyboard controller */
59 int ks_mode; /* input mode (K_XLATE,K_RAW,K_CODE) */
60 int ks_flags; /* flags */
61 #define COMPOSE (1 << 0)
62 int ks_state; /* shift/lock key state */
63 int ks_accents; /* accent key index (> 0) */
64 u_int ks_composed_char; /* composed char code (> 0) */
65 struct callout ks_timer;
68 static devclass_t pckbd_devclass;
70 static int pckbdprobe(device_t dev);
71 static int pckbdattach(device_t dev);
72 static int pckbdresume(device_t dev);
73 static void pckbd_isa_intr(void *arg);
75 static device_method_t pckbd_methods[] = {
76 /* Device interface */
77 DEVMETHOD(device_probe, pckbdprobe),
78 DEVMETHOD(device_attach, pckbdattach),
79 DEVMETHOD(device_resume, pckbdresume),
83 static driver_t pckbd_driver = {
89 DRIVER_MODULE(pckbd, isa, pckbd_driver, pckbd_devclass, 0, 0);
91 static bus_addr_t pckbd_iat[] = {0, 2};
93 static int pckbd_probe_unit(device_t dev, int port, int irq,
95 static int pckbd_attach_unit(device_t dev, keyboard_t **kbd,
96 int port, int irq, int flags);
97 static timeout_t pckbd_timeout;
101 pckbdprobe(device_t dev)
103 struct resource *res;
106 /* Check isapnp ids */
107 if (isa_get_vendorid(dev))
110 device_set_desc(dev, "PC-98 Keyboard");
113 res = isa_alloc_resourcev(dev, SYS_RES_IOPORT, &rid, pckbd_iat, 2,
117 isa_load_resourcev(res, pckbd_iat, 2);
119 error = pckbd_probe_unit(dev,
121 (1 << isa_get_irq(dev)),
122 device_get_flags(dev));
124 bus_release_resource(dev, SYS_RES_IOPORT, rid, res);
130 pckbdattach(device_t dev)
134 struct resource *res;
138 res = isa_alloc_resourcev(dev, SYS_RES_IOPORT, &rid, pckbd_iat, 2,
142 isa_load_resourcev(res, pckbd_iat, 2);
144 error = pckbd_attach_unit(dev, &kbd,
146 (1 << isa_get_irq(dev)),
147 device_get_flags(dev));
150 res = bus_alloc_resource_any(dev, SYS_RES_IRQ, &rid, RF_ACTIVE);
153 bus_setup_intr(dev, res, INTR_TYPE_TTY, NULL, pckbd_isa_intr, kbd, &ih);
159 pckbdresume(device_t dev)
163 kbd = kbd_get_keyboard(kbd_find_keyboard(DRIVER_NAME,
164 device_get_unit(dev)));
166 kbdd_clear_state(kbd);
172 pckbd_isa_intr(void *arg)
174 keyboard_t *kbd = arg;
176 kbdd_intr(kbd, NULL);
180 pckbd_probe_unit(device_t dev, int port, int irq, int flags)
182 keyboard_switch_t *sw;
186 sw = kbd_get_switch(DRIVER_NAME);
192 error = (*sw->probe)(device_get_unit(dev), args, flags);
199 pckbd_attach_unit(device_t dev, keyboard_t **kbd, int port, int irq, int flags)
201 keyboard_switch_t *sw;
202 pckbd_state_t *state;
207 sw = kbd_get_switch(DRIVER_NAME);
211 /* reset, initialize and enable the device */
212 unit = device_get_unit(dev);
216 error = (*sw->probe)(unit, args, flags);
219 error = (*sw->init)(unit, kbd, args, flags);
224 #ifdef KBD_INSTALL_CDEV
225 /* attach a virtual keyboard cdev */
226 error = kbd_attach(*kbd);
229 #endif /* KBD_INSTALL_CDEV */
232 * This is a kludge to compensate for lost keyboard interrupts.
233 * A similar code used to be in syscons. See below. XXX
235 state = (pckbd_state_t *)(*kbd)->kb_data;
236 callout_init(&state->ks_timer, 0);
240 (*sw->diag)(*kbd, bootverbose);
246 pckbd_timeout(void *arg)
248 pckbd_state_t *state;
252 /* The following comments are extracted from syscons.c (1.287) */
254 * With release 2.1 of the Xaccel server, the keyboard is left
255 * hanging pretty often. Apparently an interrupt from the
256 * keyboard is lost, and I don't know why (yet).
257 * This ugly hack calls scintr if input is ready for the keyboard
258 * and conveniently hides the problem. XXX
261 * Try removing anything stuck in the keyboard controller; whether
262 * it's a keyboard scan code or mouse data. `scintr()' doesn't
263 * read the mouse data directly, but `kbdio' routines will, as a
267 kbd = (keyboard_t *)arg;
268 if (kbdd_lock(kbd, TRUE)) {
270 * We have seen the lock flag is not set. Let's reset
271 * the flag early, otherwise the LED update routine fails
272 * which may want the lock during the interrupt routine.
274 kbdd_lock(kbd, FALSE);
275 if (kbdd_check_char(kbd))
276 kbdd_intr(kbd, NULL);
279 state = (pckbd_state_t *)kbd->kb_data;
280 callout_reset(&state->ks_timer, hz / 10, pckbd_timeout, arg);
285 #include <sys/limits.h>
287 #define PC98KBD_DEFAULT 0
289 /* keyboard driver declaration */
290 static int pckbd_configure(int flags);
291 static kbd_probe_t pckbd_probe;
292 static kbd_init_t pckbd_init;
293 static kbd_term_t pckbd_term;
294 static kbd_intr_t pckbd_intr;
295 static kbd_test_if_t pckbd_test_if;
296 static kbd_enable_t pckbd_enable;
297 static kbd_disable_t pckbd_disable;
298 static kbd_read_t pckbd_read;
299 static kbd_check_t pckbd_check;
300 static kbd_read_char_t pckbd_read_char;
301 static kbd_check_char_t pckbd_check_char;
302 static kbd_ioctl_t pckbd_ioctl;
303 static kbd_lock_t pckbd_lock;
304 static kbd_clear_state_t pckbd_clear_state;
305 static kbd_get_state_t pckbd_get_state;
306 static kbd_set_state_t pckbd_set_state;
307 static kbd_poll_mode_t pckbd_poll;
309 keyboard_switch_t pckbdsw = {
331 KEYBOARD_DRIVER(pckbd, pckbdsw, pckbd_configure);
334 int port; /* base port address */
335 int lock; /* FIXME: XXX not quite a semaphore... */
338 /* local functions */
339 static int probe_keyboard(KBDC kbdc, int flags);
340 static int init_keyboard(KBDC kbdc, int *type, int flags);
341 static KBDC kbdc_open(int port);
342 static int kbdc_lock(KBDC kbdc, int lock);
343 static int kbdc_data_ready(KBDC kbdc);
344 static int read_kbd_data(KBDC kbdc);
345 static int read_kbd_data_no_wait(KBDC kbdc);
346 static int wait_for_kbd_data(struct kbdc_softc *kbdc);
348 /* local variables */
350 /* the initial key map, accent map and fkey strings */
351 #include <pc98/cbus/pckbdtables.h>
353 /* structures for the default keyboard */
354 static keyboard_t default_kbd;
355 static pckbd_state_t default_kbd_state;
356 static keymap_t default_keymap;
357 static accentmap_t default_accentmap;
358 static fkeytab_t default_fkeytab[NUM_FKEYS];
361 * The back door to the keyboard driver!
362 * This function is called by the console driver, via the kbdio module,
363 * to tickle keyboard drivers when the low-level console is being initialized.
364 * Almost nothing in the kernel has been initialied yet. Try to probe
365 * keyboards if possible.
366 * NOTE: because of the way the low-level conole is initialized, this routine
367 * may be called more than once!!
370 pckbd_configure(int flags)
376 /* XXX: a kludge to obtain the device configuration flags */
377 if (resource_int_value(DRIVER_NAME, 0, "flags", &i) == 0) {
379 /* if the driver is disabled, unregister the keyboard if any */
380 if (resource_disabled(DRIVER_NAME, 0)) {
381 i = kbd_find_keyboard(DRIVER_NAME, PC98KBD_DEFAULT);
383 kbd = kbd_get_keyboard(i);
385 kbd->kb_flags &= ~KB_REGISTERED;
391 /* probe the default keyboard */
395 if (pckbd_probe(PC98KBD_DEFAULT, arg, flags))
397 if (pckbd_init(PC98KBD_DEFAULT, &kbd, arg, flags))
400 /* return the number of found keyboards */
404 /* low-level functions */
406 /* detect a keyboard */
408 pckbd_probe(int unit, void *arg, int flags)
411 int *data = (int *)arg;
413 if (unit != PC98KBD_DEFAULT)
415 if (KBD_IS_PROBED(&default_kbd))
418 kbdc = kbdc_open(data[0]);
421 if (probe_keyboard(kbdc, flags)) {
422 if (flags & KB_CONF_FAIL_IF_NO_KBD)
428 /* reset and initialize the device */
430 pckbd_init(int unit, keyboard_t **kbdp, void *arg, int flags)
433 pckbd_state_t *state;
438 int *data = (int *)arg;
440 if (unit != PC98KBD_DEFAULT) /* shouldn't happen */
443 *kbdp = kbd = &default_kbd;
444 state = &default_kbd_state;
445 if (!KBD_IS_PROBED(kbd)) {
446 keymap = &default_keymap;
447 accmap = &default_accentmap;
448 fkeymap = default_fkeytab;
450 sizeof(default_fkeytab)/sizeof(default_fkeytab[0]);
452 state->kbdc = kbdc_open(data[0]);
453 if (state->kbdc == NULL)
455 kbd_init_struct(kbd, DRIVER_NAME, KB_OTHER, unit, flags,
456 data[0], IO_KBDSIZE);
457 bcopy(&key_map, keymap, sizeof(key_map));
458 bcopy(&accent_map, accmap, sizeof(accent_map));
459 bcopy(fkey_tab, fkeymap,
460 imin(fkeymap_size*sizeof(fkeymap[0]), sizeof(fkey_tab)));
461 kbd_set_maps(kbd, keymap, accmap, fkeymap, fkeymap_size);
462 kbd->kb_data = (void *)state;
464 if (probe_keyboard(state->kbdc, flags)) {/* shouldn't happen */
465 if (flags & KB_CONF_FAIL_IF_NO_KBD)
468 KBD_FOUND_DEVICE(kbd);
470 pckbd_clear_state(kbd);
471 state->ks_mode = K_XLATE;
474 if (!KBD_IS_INITIALIZED(kbd) && !(flags & KB_CONF_PROBE_ONLY)) {
475 if (KBD_HAS_DEVICE(kbd)
476 && init_keyboard(state->kbdc, &kbd->kb_type, kbd->kb_config)
477 && (kbd->kb_config & KB_CONF_FAIL_IF_NO_KBD))
479 pckbd_ioctl(kbd, KDSETLED, (caddr_t)&state->ks_state);
482 if (!KBD_IS_CONFIGURED(kbd)) {
483 if (kbd_register(kbd) < 0)
485 KBD_CONFIG_DONE(kbd);
491 /* finish using this keyboard */
493 pckbd_term(keyboard_t *kbd)
495 pckbd_state_t *state = (pckbd_state_t *)kbd->kb_data;
498 callout_drain(&state->ks_timer);
502 /* keyboard interrupt routine */
504 pckbd_intr(keyboard_t *kbd, void *arg)
508 if (KBD_IS_ACTIVE(kbd) && KBD_IS_BUSY(kbd)) {
509 /* let the callback function to process the input */
510 (*kbd->kb_callback.kc_func)(kbd, KBDIO_KEYINPUT,
511 kbd->kb_callback.kc_arg);
513 /* read and discard the input; no one is waiting for input */
515 c = pckbd_read_char(kbd, FALSE);
516 } while (c != NOKEY);
521 /* test the interface to the device */
523 pckbd_test_if(keyboard_t *kbd)
529 * Enable the access to the device; until this function is called,
530 * the client cannot read from the keyboard.
533 pckbd_enable(keyboard_t *kbd)
543 /* disallow the access to the device */
545 pckbd_disable(keyboard_t *kbd)
555 /* read one byte from the keyboard if it's allowed */
557 pckbd_read(keyboard_t *kbd, int wait)
562 c = read_kbd_data(((pckbd_state_t *)kbd->kb_data)->kbdc);
564 c = read_kbd_data_no_wait(((pckbd_state_t *)kbd->kb_data)->kbdc);
567 return (KBD_IS_ACTIVE(kbd) ? c : -1);
570 /* check if data is waiting */
572 pckbd_check(keyboard_t *kbd)
574 if (!KBD_IS_ACTIVE(kbd))
576 return kbdc_data_ready(((pckbd_state_t *)kbd->kb_data)->kbdc);
579 /* read char from the keyboard */
581 pckbd_read_char(keyboard_t *kbd, int wait)
583 pckbd_state_t *state;
588 state = (pckbd_state_t *)kbd->kb_data;
590 /* do we have a composed char to return? */
591 if (!(state->ks_flags & COMPOSE) && (state->ks_composed_char > 0)) {
592 action = state->ks_composed_char;
593 state->ks_composed_char = 0;
594 if (action > UCHAR_MAX)
599 /* see if there is something in the keyboard port */
602 scancode = read_kbd_data(state->kbdc);
603 } while (scancode == -1);
605 scancode = read_kbd_data_no_wait(state->kbdc);
612 printf("pckbd_read_char(): scancode:0x%x\n", scancode);
615 /* return the byte as is for the K_RAW mode */
616 if (state->ks_mode == K_RAW)
619 /* translate the scan code into a keycode */
620 keycode = scancode & 0x7F;
622 case 0xF3: /* GRPH (compose key) released */
623 if (state->ks_flags & COMPOSE) {
624 state->ks_flags &= ~COMPOSE;
625 if (state->ks_composed_char > UCHAR_MAX)
626 state->ks_composed_char = 0;
629 case 0x73: /* GRPH (compose key) pressed */
630 if (!(state->ks_flags & COMPOSE)) {
631 state->ks_flags |= COMPOSE;
632 state->ks_composed_char = 0;
637 /* return the key code in the K_CODE mode */
638 if (state->ks_mode == K_CODE)
639 return (keycode | (scancode & 0x80));
641 /* compose a character code */
642 if (state->ks_flags & COMPOSE) {
644 /* key pressed, process it */
645 case 0x42: case 0x43: case 0x44: /* keypad 7,8,9 */
646 state->ks_composed_char *= 10;
647 state->ks_composed_char += scancode - 0x3B;
648 if (state->ks_composed_char > UCHAR_MAX)
651 case 0x46: case 0x47: case 0x48: /* keypad 4,5,6 */
652 state->ks_composed_char *= 10;
653 state->ks_composed_char += scancode - 0x42;
654 if (state->ks_composed_char > UCHAR_MAX)
657 case 0x4A: case 0x4B: case 0x4C: /* keypad 1,2,3 */
658 state->ks_composed_char *= 10;
659 state->ks_composed_char += scancode - 0x49;
660 if (state->ks_composed_char > UCHAR_MAX)
663 case 0x4E: /* keypad 0 */
664 state->ks_composed_char *= 10;
665 if (state->ks_composed_char > UCHAR_MAX)
669 /* key released, no interest here */
670 case 0xC2: case 0xC3: case 0xC4: /* keypad 7,8,9 */
671 case 0xC6: case 0xC7: case 0xC8: /* keypad 4,5,6 */
672 case 0xCA: case 0xCB: case 0xCC: /* keypad 1,2,3 */
673 case 0xCE: /* keypad 0 */
676 case 0x73: /* GRPH key */
680 if (state->ks_composed_char > 0) {
681 state->ks_flags &= ~COMPOSE;
682 state->ks_composed_char = 0;
689 /* keycode to key action */
690 action = genkbd_keyaction(kbd, keycode, scancode & 0x80,
691 &state->ks_state, &state->ks_accents);
698 /* check if char is waiting */
700 pckbd_check_char(keyboard_t *kbd)
702 pckbd_state_t *state;
704 if (!KBD_IS_ACTIVE(kbd))
706 state = (pckbd_state_t *)kbd->kb_data;
707 if (!(state->ks_flags & COMPOSE) && (state->ks_composed_char > 0))
709 return kbdc_data_ready(state->kbdc);
712 /* some useful control functions */
714 pckbd_ioctl(keyboard_t *kbd, u_long cmd, caddr_t arg)
716 pckbd_state_t *state = kbd->kb_data;
719 #if defined(COMPAT_FREEBSD6) || defined(COMPAT_FREEBSD5) || \
720 defined(COMPAT_FREEBSD4) || defined(COMPAT_43)
727 case KDGKBMODE: /* get keyboard mode */
728 *(int *)arg = state->ks_mode;
730 #if defined(COMPAT_FREEBSD6) || defined(COMPAT_FREEBSD5) || \
731 defined(COMPAT_FREEBSD4) || defined(COMPAT_43)
733 ival = IOCPARM_IVAL(arg);
734 arg = (caddr_t)&ival;
737 case KDSKBMODE: /* set keyboard mode */
738 switch (*(int *)arg) {
740 if (state->ks_mode != K_XLATE) {
741 /* make lock key state and LED state match */
742 state->ks_state &= ~LOCK_MASK;
743 state->ks_state |= KBD_LED_VAL(kbd);
748 if (state->ks_mode != *(int *)arg) {
749 pckbd_clear_state(kbd);
750 state->ks_mode = *(int *)arg;
759 case KDGETLED: /* get keyboard LED */
760 *(int *)arg = KBD_LED_VAL(kbd);
762 #if defined(COMPAT_FREEBSD6) || defined(COMPAT_FREEBSD5) || \
763 defined(COMPAT_FREEBSD4) || defined(COMPAT_43)
765 ival = IOCPARM_IVAL(arg);
766 arg = (caddr_t)&ival;
769 case KDSETLED: /* set keyboard LED */
770 /* NOTE: lock key state in ks_state won't be changed */
771 if (*(int *)arg & ~LOCK_MASK) {
776 /* replace CAPS LED with ALTGR LED for ALTGR keyboards */
777 if (kbd->kb_keymap->n_keys > ALTGR_OFFSET) {
783 KBD_LED_VAL(kbd) = *(int *)arg;
786 case KDGKBSTATE: /* get lock key state */
787 *(int *)arg = state->ks_state & LOCK_MASK;
789 #if defined(COMPAT_FREEBSD6) || defined(COMPAT_FREEBSD5) || \
790 defined(COMPAT_FREEBSD4) || defined(COMPAT_43)
792 ival = IOCPARM_IVAL(arg);
793 arg = (caddr_t)&ival;
796 case KDSKBSTATE: /* set lock key state */
797 if (*(int *)arg & ~LOCK_MASK) {
801 state->ks_state &= ~LOCK_MASK;
802 state->ks_state |= *(int *)arg;
804 /* set LEDs and quit */
805 return pckbd_ioctl(kbd, KDSETLED, arg);
807 case KDSETRAD: /* set keyboard repeat rate (old interface)*/
809 case KDSETREPEAT: /* set keyboard repeat rate (new interface) */
812 case PIO_KEYMAP: /* set keyboard translation table */
813 case OPIO_KEYMAP: /* set keyboard translation table (compat) */
814 case PIO_KEYMAPENT: /* set keyboard translation table entry */
815 case PIO_DEADKEYMAP: /* set accent key translation table */
816 state->ks_accents = 0;
820 return genkbd_commonioctl(kbd, cmd, arg);
827 /* lock the access to the keyboard */
829 pckbd_lock(keyboard_t *kbd, int lock)
831 return kbdc_lock(((pckbd_state_t *)kbd->kb_data)->kbdc, lock);
834 /* clear the internal state of the keyboard */
836 pckbd_clear_state(keyboard_t *kbd)
838 pckbd_state_t *state;
840 state = (pckbd_state_t *)kbd->kb_data;
842 state->ks_state &= LOCK_MASK; /* preserve locking key state */
843 state->ks_accents = 0;
844 state->ks_composed_char = 0;
847 /* save the internal state */
849 pckbd_get_state(keyboard_t *kbd, void *buf, size_t len)
852 return sizeof(pckbd_state_t);
853 if (len < sizeof(pckbd_state_t))
855 bcopy(kbd->kb_data, buf, sizeof(pckbd_state_t));
859 /* set the internal state */
861 pckbd_set_state(keyboard_t *kbd, void *buf, size_t len)
863 if (len < sizeof(pckbd_state_t))
865 if (((pckbd_state_t *)kbd->kb_data)->kbdc
866 != ((pckbd_state_t *)buf)->kbdc)
868 bcopy(buf, kbd->kb_data, sizeof(pckbd_state_t));
872 /* set polling mode */
874 pckbd_poll(keyboard_t *kbd, int on)
879 /* local functions */
882 probe_keyboard(KBDC kbdc, int flags)
888 init_keyboard(KBDC kbdc, int *type, int flags)
894 /* keyboard I/O routines */
898 #define KBD_MAXRETRY 3
901 /* timing parameters */
902 #ifndef KBD_RESETDELAY
903 #define KBD_RESETDELAY 200 /* wait 200msec after kbd/mouse reset */
906 #define KBD_MAXWAIT 5 /* wait 5 times at most after reset */
909 /* I/O recovery time */
910 #define KBDC_DELAYTIME 37
911 #define KBDD_DELAYTIME 37
914 #define KBD_STATUS_PORT 2 /* status port, read */
915 #define KBD_DATA_PORT 0 /* data port, read */
917 /* status bits (KBD_STATUS_PORT) */
918 #define KBDS_BUFFER_FULL 0x0002
922 #define kbdcp(p) ((struct kbdc_softc *)(p))
924 /* local variables */
926 static struct kbdc_softc kbdc_softc[1] = { { 0 }, };
928 /* associate a port number with a KBDC */
936 /* PC-98 has only one keyboard I/F */
937 kbdc_softc[0].port = port;
938 kbdc_softc[0].lock = FALSE;
939 return (KBDC)&kbdc_softc[0];
942 /* set/reset polling lock */
944 kbdc_lock(KBDC p, int lock)
948 prevlock = kbdcp(p)->lock;
949 kbdcp(p)->lock = lock;
951 return (prevlock != lock);
954 /* check if any data is waiting to be processed */
956 kbdc_data_ready(KBDC p)
958 return (inb(kbdcp(p)->port + KBD_STATUS_PORT) & KBDS_BUFFER_FULL);
961 /* wait for data from the keyboard */
963 wait_for_kbd_data(struct kbdc_softc *kbdc)
965 /* CPU will stay inside the loop for 200msec at most */
967 int port = kbdc->port;
969 while (!(inb(port + KBD_STATUS_PORT) & KBDS_BUFFER_FULL)) {
970 DELAY(KBDD_DELAYTIME);
971 DELAY(KBDC_DELAYTIME);
975 DELAY(KBDD_DELAYTIME);
979 /* read one byte from the keyboard */
981 read_kbd_data(KBDC p)
983 if (!wait_for_kbd_data(kbdcp(p)))
984 return -1; /* timeout */
985 DELAY(KBDC_DELAYTIME);
986 return inb(kbdcp(p)->port + KBD_DATA_PORT);
989 /* read one byte from the keyboard, but return immediately if
993 read_kbd_data_no_wait(KBDC p)
995 if (inb(kbdcp(p)->port + KBD_STATUS_PORT) & KBDS_BUFFER_FULL) {
996 DELAY(KBDD_DELAYTIME);
997 return inb(kbdcp(p)->port + KBD_DATA_PORT);
999 return -1; /* no data */