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 */
55 static devclass_t pckbd_devclass;
57 static int pckbdprobe(device_t dev);
58 static int pckbdattach(device_t dev);
59 static int pckbdresume(device_t dev);
60 static void pckbd_isa_intr(void *arg);
62 static device_method_t pckbd_methods[] = {
63 /* Device interface */
64 DEVMETHOD(device_probe, pckbdprobe),
65 DEVMETHOD(device_attach, pckbdattach),
66 DEVMETHOD(device_resume, pckbdresume),
70 static driver_t pckbd_driver = {
76 DRIVER_MODULE(pckbd, isa, pckbd_driver, pckbd_devclass, 0, 0);
78 static bus_addr_t pckbd_iat[] = {0, 2};
80 static int pckbd_probe_unit(device_t dev, int port, int irq,
82 static int pckbd_attach_unit(device_t dev, keyboard_t **kbd,
83 int port, int irq, int flags);
84 static timeout_t pckbd_timeout;
88 pckbdprobe(device_t dev)
93 /* Check isapnp ids */
94 if (isa_get_vendorid(dev))
97 device_set_desc(dev, "PC-98 Keyboard");
100 res = isa_alloc_resourcev(dev, SYS_RES_IOPORT, &rid, pckbd_iat, 2,
104 isa_load_resourcev(res, pckbd_iat, 2);
106 error = pckbd_probe_unit(dev,
108 (1 << isa_get_irq(dev)),
109 device_get_flags(dev));
111 bus_release_resource(dev, SYS_RES_IOPORT, rid, res);
117 pckbdattach(device_t dev)
121 struct resource *res;
125 res = isa_alloc_resourcev(dev, SYS_RES_IOPORT, &rid, pckbd_iat, 2,
129 isa_load_resourcev(res, pckbd_iat, 2);
131 error = pckbd_attach_unit(dev, &kbd,
133 (1 << isa_get_irq(dev)),
134 device_get_flags(dev));
137 res = bus_alloc_resource_any(dev, SYS_RES_IRQ, &rid, RF_ACTIVE);
140 bus_setup_intr(dev, res, INTR_TYPE_TTY, NULL, pckbd_isa_intr, kbd, &ih);
146 pckbdresume(device_t dev)
150 kbd = kbd_get_keyboard(kbd_find_keyboard(DRIVER_NAME,
151 device_get_unit(dev)));
153 kbdd_clear_state(kbd);
159 pckbd_isa_intr(void *arg)
161 keyboard_t *kbd = arg;
163 kbdd_intr(kbd, NULL);
167 pckbd_probe_unit(device_t dev, int port, int irq, int flags)
169 keyboard_switch_t *sw;
173 sw = kbd_get_switch(DRIVER_NAME);
179 error = (*sw->probe)(device_get_unit(dev), args, flags);
186 pckbd_attach_unit(device_t dev, keyboard_t **kbd, int port, int irq, int flags)
188 keyboard_switch_t *sw;
193 sw = kbd_get_switch(DRIVER_NAME);
197 /* reset, initialize and enable the device */
198 unit = device_get_unit(dev);
202 error = (*sw->probe)(unit, args, flags);
205 error = (*sw->init)(unit, kbd, args, flags);
210 #ifdef KBD_INSTALL_CDEV
211 /* attach a virtual keyboard cdev */
212 error = kbd_attach(*kbd);
215 #endif /* KBD_INSTALL_CDEV */
218 * This is a kludge to compensate for lost keyboard interrupts.
219 * A similar code used to be in syscons. See below. XXX
224 (*sw->diag)(*kbd, bootverbose);
230 pckbd_timeout(void *arg)
235 /* The following comments are extracted from syscons.c (1.287) */
237 * With release 2.1 of the Xaccel server, the keyboard is left
238 * hanging pretty often. Apparently an interrupt from the
239 * keyboard is lost, and I don't know why (yet).
240 * This ugly hack calls scintr if input is ready for the keyboard
241 * and conveniently hides the problem. XXX
244 * Try removing anything stuck in the keyboard controller; whether
245 * it's a keyboard scan code or mouse data. `scintr()' doesn't
246 * read the mouse data directly, but `kbdio' routines will, as a
250 kbd = (keyboard_t *)arg;
251 if (kbdd_lock(kbd, TRUE)) {
253 * We have seen the lock flag is not set. Let's reset
254 * the flag early, otherwise the LED update routine fails
255 * which may want the lock during the interrupt routine.
257 kbdd_lock(kbd, FALSE);
258 if (kbdd_check_char(kbd))
259 kbdd_intr(kbd, NULL);
262 timeout(pckbd_timeout, arg, hz/10);
267 #include <sys/limits.h>
269 #define PC98KBD_DEFAULT 0
271 typedef caddr_t KBDC;
273 typedef struct pckbd_state {
274 KBDC kbdc; /* keyboard controller */
275 int ks_mode; /* input mode (K_XLATE,K_RAW,K_CODE) */
276 int ks_flags; /* flags */
277 #define COMPOSE (1 << 0)
278 int ks_state; /* shift/lock key state */
279 int ks_accents; /* accent key index (> 0) */
280 u_int ks_composed_char; /* composed char code (> 0) */
283 /* keyboard driver declaration */
284 static int pckbd_configure(int flags);
285 static kbd_probe_t pckbd_probe;
286 static kbd_init_t pckbd_init;
287 static kbd_term_t pckbd_term;
288 static kbd_intr_t pckbd_intr;
289 static kbd_test_if_t pckbd_test_if;
290 static kbd_enable_t pckbd_enable;
291 static kbd_disable_t pckbd_disable;
292 static kbd_read_t pckbd_read;
293 static kbd_check_t pckbd_check;
294 static kbd_read_char_t pckbd_read_char;
295 static kbd_check_char_t pckbd_check_char;
296 static kbd_ioctl_t pckbd_ioctl;
297 static kbd_lock_t pckbd_lock;
298 static kbd_clear_state_t pckbd_clear_state;
299 static kbd_get_state_t pckbd_get_state;
300 static kbd_set_state_t pckbd_set_state;
301 static kbd_poll_mode_t pckbd_poll;
303 keyboard_switch_t pckbdsw = {
325 KEYBOARD_DRIVER(pckbd, pckbdsw, pckbd_configure);
328 int port; /* base port address */
329 int lock; /* FIXME: XXX not quite a semaphore... */
332 /* local functions */
333 static int probe_keyboard(KBDC kbdc, int flags);
334 static int init_keyboard(KBDC kbdc, int *type, int flags);
335 static KBDC kbdc_open(int port);
336 static int kbdc_lock(KBDC kbdc, int lock);
337 static int kbdc_data_ready(KBDC kbdc);
338 static int read_kbd_data(KBDC kbdc);
339 static int read_kbd_data_no_wait(KBDC kbdc);
340 static int wait_for_kbd_data(struct kbdc_softc *kbdc);
342 /* local variables */
344 /* the initial key map, accent map and fkey strings */
345 #include <pc98/cbus/pckbdtables.h>
347 /* structures for the default keyboard */
348 static keyboard_t default_kbd;
349 static pckbd_state_t default_kbd_state;
350 static keymap_t default_keymap;
351 static accentmap_t default_accentmap;
352 static fkeytab_t default_fkeytab[NUM_FKEYS];
355 * The back door to the keyboard driver!
356 * This function is called by the console driver, via the kbdio module,
357 * to tickle keyboard drivers when the low-level console is being initialized.
358 * Almost nothing in the kernel has been initialied yet. Try to probe
359 * keyboards if possible.
360 * NOTE: because of the way the low-level conole is initialized, this routine
361 * may be called more than once!!
364 pckbd_configure(int flags)
370 /* XXX: a kludge to obtain the device configuration flags */
371 if (resource_int_value(DRIVER_NAME, 0, "flags", &i) == 0) {
373 /* if the driver is disabled, unregister the keyboard if any */
374 if (resource_disabled(DRIVER_NAME, 0)) {
375 i = kbd_find_keyboard(DRIVER_NAME, PC98KBD_DEFAULT);
377 kbd = kbd_get_keyboard(i);
379 kbd->kb_flags &= ~KB_REGISTERED;
385 /* probe the default keyboard */
389 if (pckbd_probe(PC98KBD_DEFAULT, arg, flags))
391 if (pckbd_init(PC98KBD_DEFAULT, &kbd, arg, flags))
394 /* return the number of found keyboards */
398 /* low-level functions */
400 /* detect a keyboard */
402 pckbd_probe(int unit, void *arg, int flags)
405 int *data = (int *)arg;
407 if (unit != PC98KBD_DEFAULT)
409 if (KBD_IS_PROBED(&default_kbd))
412 kbdc = kbdc_open(data[0]);
415 if (probe_keyboard(kbdc, flags)) {
416 if (flags & KB_CONF_FAIL_IF_NO_KBD)
422 /* reset and initialize the device */
424 pckbd_init(int unit, keyboard_t **kbdp, void *arg, int flags)
427 pckbd_state_t *state;
432 int *data = (int *)arg;
434 if (unit != PC98KBD_DEFAULT) /* shouldn't happen */
437 *kbdp = kbd = &default_kbd;
438 state = &default_kbd_state;
439 if (!KBD_IS_PROBED(kbd)) {
440 keymap = &default_keymap;
441 accmap = &default_accentmap;
442 fkeymap = default_fkeytab;
444 sizeof(default_fkeytab)/sizeof(default_fkeytab[0]);
446 state->kbdc = kbdc_open(data[0]);
447 if (state->kbdc == NULL)
449 kbd_init_struct(kbd, DRIVER_NAME, KB_OTHER, unit, flags,
450 data[0], IO_KBDSIZE);
451 bcopy(&key_map, keymap, sizeof(key_map));
452 bcopy(&accent_map, accmap, sizeof(accent_map));
453 bcopy(fkey_tab, fkeymap,
454 imin(fkeymap_size*sizeof(fkeymap[0]), sizeof(fkey_tab)));
455 kbd_set_maps(kbd, keymap, accmap, fkeymap, fkeymap_size);
456 kbd->kb_data = (void *)state;
458 if (probe_keyboard(state->kbdc, flags)) {/* shouldn't happen */
459 if (flags & KB_CONF_FAIL_IF_NO_KBD)
462 KBD_FOUND_DEVICE(kbd);
464 pckbd_clear_state(kbd);
465 state->ks_mode = K_XLATE;
468 if (!KBD_IS_INITIALIZED(kbd) && !(flags & KB_CONF_PROBE_ONLY)) {
469 if (KBD_HAS_DEVICE(kbd)
470 && init_keyboard(state->kbdc, &kbd->kb_type, kbd->kb_config)
471 && (kbd->kb_config & KB_CONF_FAIL_IF_NO_KBD))
473 pckbd_ioctl(kbd, KDSETLED, (caddr_t)&state->ks_state);
476 if (!KBD_IS_CONFIGURED(kbd)) {
477 if (kbd_register(kbd) < 0)
479 KBD_CONFIG_DONE(kbd);
485 /* finish using this keyboard */
487 pckbd_term(keyboard_t *kbd)
493 /* keyboard interrupt routine */
495 pckbd_intr(keyboard_t *kbd, void *arg)
499 if (KBD_IS_ACTIVE(kbd) && KBD_IS_BUSY(kbd)) {
500 /* let the callback function to process the input */
501 (*kbd->kb_callback.kc_func)(kbd, KBDIO_KEYINPUT,
502 kbd->kb_callback.kc_arg);
504 /* read and discard the input; no one is waiting for input */
506 c = pckbd_read_char(kbd, FALSE);
507 } while (c != NOKEY);
512 /* test the interface to the device */
514 pckbd_test_if(keyboard_t *kbd)
520 * Enable the access to the device; until this function is called,
521 * the client cannot read from the keyboard.
524 pckbd_enable(keyboard_t *kbd)
534 /* disallow the access to the device */
536 pckbd_disable(keyboard_t *kbd)
546 /* read one byte from the keyboard if it's allowed */
548 pckbd_read(keyboard_t *kbd, int wait)
553 c = read_kbd_data(((pckbd_state_t *)kbd->kb_data)->kbdc);
555 c = read_kbd_data_no_wait(((pckbd_state_t *)kbd->kb_data)->kbdc);
558 return (KBD_IS_ACTIVE(kbd) ? c : -1);
561 /* check if data is waiting */
563 pckbd_check(keyboard_t *kbd)
565 if (!KBD_IS_ACTIVE(kbd))
567 return kbdc_data_ready(((pckbd_state_t *)kbd->kb_data)->kbdc);
570 /* read char from the keyboard */
572 pckbd_read_char(keyboard_t *kbd, int wait)
574 pckbd_state_t *state;
579 state = (pckbd_state_t *)kbd->kb_data;
581 /* do we have a composed char to return? */
582 if (!(state->ks_flags & COMPOSE) && (state->ks_composed_char > 0)) {
583 action = state->ks_composed_char;
584 state->ks_composed_char = 0;
585 if (action > UCHAR_MAX)
590 /* see if there is something in the keyboard port */
593 scancode = read_kbd_data(state->kbdc);
594 } while (scancode == -1);
596 scancode = read_kbd_data_no_wait(state->kbdc);
603 printf("pckbd_read_char(): scancode:0x%x\n", scancode);
606 /* return the byte as is for the K_RAW mode */
607 if (state->ks_mode == K_RAW)
610 /* translate the scan code into a keycode */
611 keycode = scancode & 0x7F;
613 case 0xF3: /* GRPH (compose key) released */
614 if (state->ks_flags & COMPOSE) {
615 state->ks_flags &= ~COMPOSE;
616 if (state->ks_composed_char > UCHAR_MAX)
617 state->ks_composed_char = 0;
620 case 0x73: /* GRPH (compose key) pressed */
621 if (!(state->ks_flags & COMPOSE)) {
622 state->ks_flags |= COMPOSE;
623 state->ks_composed_char = 0;
628 /* return the key code in the K_CODE mode */
629 if (state->ks_mode == K_CODE)
630 return (keycode | (scancode & 0x80));
632 /* compose a character code */
633 if (state->ks_flags & COMPOSE) {
635 /* key pressed, process it */
636 case 0x42: case 0x43: case 0x44: /* keypad 7,8,9 */
637 state->ks_composed_char *= 10;
638 state->ks_composed_char += scancode - 0x3B;
639 if (state->ks_composed_char > UCHAR_MAX)
642 case 0x46: case 0x47: case 0x48: /* keypad 4,5,6 */
643 state->ks_composed_char *= 10;
644 state->ks_composed_char += scancode - 0x42;
645 if (state->ks_composed_char > UCHAR_MAX)
648 case 0x4A: case 0x4B: case 0x4C: /* keypad 1,2,3 */
649 state->ks_composed_char *= 10;
650 state->ks_composed_char += scancode - 0x49;
651 if (state->ks_composed_char > UCHAR_MAX)
654 case 0x4E: /* keypad 0 */
655 state->ks_composed_char *= 10;
656 if (state->ks_composed_char > UCHAR_MAX)
660 /* key released, no interest here */
661 case 0xC2: case 0xC3: case 0xC4: /* keypad 7,8,9 */
662 case 0xC6: case 0xC7: case 0xC8: /* keypad 4,5,6 */
663 case 0xCA: case 0xCB: case 0xCC: /* keypad 1,2,3 */
664 case 0xCE: /* keypad 0 */
667 case 0x73: /* GRPH key */
671 if (state->ks_composed_char > 0) {
672 state->ks_flags &= ~COMPOSE;
673 state->ks_composed_char = 0;
680 /* keycode to key action */
681 action = genkbd_keyaction(kbd, keycode, scancode & 0x80,
682 &state->ks_state, &state->ks_accents);
689 /* check if char is waiting */
691 pckbd_check_char(keyboard_t *kbd)
693 pckbd_state_t *state;
695 if (!KBD_IS_ACTIVE(kbd))
697 state = (pckbd_state_t *)kbd->kb_data;
698 if (!(state->ks_flags & COMPOSE) && (state->ks_composed_char > 0))
700 return kbdc_data_ready(state->kbdc);
703 /* some useful control functions */
705 pckbd_ioctl(keyboard_t *kbd, u_long cmd, caddr_t arg)
707 pckbd_state_t *state = kbd->kb_data;
710 #if defined(COMPAT_FREEBSD6) || defined(COMPAT_FREEBSD5) || \
711 defined(COMPAT_FREEBSD4) || defined(COMPAT_43)
718 case KDGKBMODE: /* get keyboard mode */
719 *(int *)arg = state->ks_mode;
721 #if defined(COMPAT_FREEBSD6) || defined(COMPAT_FREEBSD5) || \
722 defined(COMPAT_FREEBSD4) || defined(COMPAT_43)
724 ival = IOCPARM_IVAL(arg);
725 arg = (caddr_t)&ival;
728 case KDSKBMODE: /* set keyboard mode */
729 switch (*(int *)arg) {
731 if (state->ks_mode != K_XLATE) {
732 /* make lock key state and LED state match */
733 state->ks_state &= ~LOCK_MASK;
734 state->ks_state |= KBD_LED_VAL(kbd);
739 if (state->ks_mode != *(int *)arg) {
740 pckbd_clear_state(kbd);
741 state->ks_mode = *(int *)arg;
750 case KDGETLED: /* get keyboard LED */
751 *(int *)arg = KBD_LED_VAL(kbd);
753 #if defined(COMPAT_FREEBSD6) || defined(COMPAT_FREEBSD5) || \
754 defined(COMPAT_FREEBSD4) || defined(COMPAT_43)
756 ival = IOCPARM_IVAL(arg);
757 arg = (caddr_t)&ival;
760 case KDSETLED: /* set keyboard LED */
761 /* NOTE: lock key state in ks_state won't be changed */
762 if (*(int *)arg & ~LOCK_MASK) {
767 /* replace CAPS LED with ALTGR LED for ALTGR keyboards */
768 if (kbd->kb_keymap->n_keys > ALTGR_OFFSET) {
774 KBD_LED_VAL(kbd) = *(int *)arg;
777 case KDGKBSTATE: /* get lock key state */
778 *(int *)arg = state->ks_state & LOCK_MASK;
780 #if defined(COMPAT_FREEBSD6) || defined(COMPAT_FREEBSD5) || \
781 defined(COMPAT_FREEBSD4) || defined(COMPAT_43)
783 ival = IOCPARM_IVAL(arg);
784 arg = (caddr_t)&ival;
787 case KDSKBSTATE: /* set lock key state */
788 if (*(int *)arg & ~LOCK_MASK) {
792 state->ks_state &= ~LOCK_MASK;
793 state->ks_state |= *(int *)arg;
795 /* set LEDs and quit */
796 return pckbd_ioctl(kbd, KDSETLED, arg);
798 case KDSETRAD: /* set keyboard repeat rate (old interface)*/
800 case KDSETREPEAT: /* set keyboard repeat rate (new interface) */
803 case PIO_KEYMAP: /* set keyboard translation table */
804 case OPIO_KEYMAP: /* set keyboard translation table (compat) */
805 case PIO_KEYMAPENT: /* set keyboard translation table entry */
806 case PIO_DEADKEYMAP: /* set accent key translation table */
807 state->ks_accents = 0;
811 return genkbd_commonioctl(kbd, cmd, arg);
818 /* lock the access to the keyboard */
820 pckbd_lock(keyboard_t *kbd, int lock)
822 return kbdc_lock(((pckbd_state_t *)kbd->kb_data)->kbdc, lock);
825 /* clear the internal state of the keyboard */
827 pckbd_clear_state(keyboard_t *kbd)
829 pckbd_state_t *state;
831 state = (pckbd_state_t *)kbd->kb_data;
833 state->ks_state &= LOCK_MASK; /* preserve locking key state */
834 state->ks_accents = 0;
835 state->ks_composed_char = 0;
838 /* save the internal state */
840 pckbd_get_state(keyboard_t *kbd, void *buf, size_t len)
843 return sizeof(pckbd_state_t);
844 if (len < sizeof(pckbd_state_t))
846 bcopy(kbd->kb_data, buf, sizeof(pckbd_state_t));
850 /* set the internal state */
852 pckbd_set_state(keyboard_t *kbd, void *buf, size_t len)
854 if (len < sizeof(pckbd_state_t))
856 if (((pckbd_state_t *)kbd->kb_data)->kbdc
857 != ((pckbd_state_t *)buf)->kbdc)
859 bcopy(buf, kbd->kb_data, sizeof(pckbd_state_t));
863 /* set polling mode */
865 pckbd_poll(keyboard_t *kbd, int on)
870 /* local functions */
873 probe_keyboard(KBDC kbdc, int flags)
879 init_keyboard(KBDC kbdc, int *type, int flags)
885 /* keyboard I/O routines */
889 #define KBD_MAXRETRY 3
892 /* timing parameters */
893 #ifndef KBD_RESETDELAY
894 #define KBD_RESETDELAY 200 /* wait 200msec after kbd/mouse reset */
897 #define KBD_MAXWAIT 5 /* wait 5 times at most after reset */
900 /* I/O recovery time */
901 #define KBDC_DELAYTIME 37
902 #define KBDD_DELAYTIME 37
905 #define KBD_STATUS_PORT 2 /* status port, read */
906 #define KBD_DATA_PORT 0 /* data port, read */
908 /* status bits (KBD_STATUS_PORT) */
909 #define KBDS_BUFFER_FULL 0x0002
913 #define kbdcp(p) ((struct kbdc_softc *)(p))
915 /* local variables */
917 static struct kbdc_softc kbdc_softc[1] = { { 0 }, };
919 /* associate a port number with a KBDC */
927 /* PC-98 has only one keyboard I/F */
928 kbdc_softc[0].port = port;
929 kbdc_softc[0].lock = FALSE;
930 return (KBDC)&kbdc_softc[0];
933 /* set/reset polling lock */
935 kbdc_lock(KBDC p, int lock)
939 prevlock = kbdcp(p)->lock;
940 kbdcp(p)->lock = lock;
942 return (prevlock != lock);
945 /* check if any data is waiting to be processed */
947 kbdc_data_ready(KBDC p)
949 return (inb(kbdcp(p)->port + KBD_STATUS_PORT) & KBDS_BUFFER_FULL);
952 /* wait for data from the keyboard */
954 wait_for_kbd_data(struct kbdc_softc *kbdc)
956 /* CPU will stay inside the loop for 200msec at most */
958 int port = kbdc->port;
960 while (!(inb(port + KBD_STATUS_PORT) & KBDS_BUFFER_FULL)) {
961 DELAY(KBDD_DELAYTIME);
962 DELAY(KBDC_DELAYTIME);
966 DELAY(KBDD_DELAYTIME);
970 /* read one byte from the keyboard */
972 read_kbd_data(KBDC p)
974 if (!wait_for_kbd_data(kbdcp(p)))
975 return -1; /* timeout */
976 DELAY(KBDC_DELAYTIME);
977 return inb(kbdcp(p)->port + KBD_DATA_PORT);
980 /* read one byte from the keyboard, but return immediately if
984 read_kbd_data_no_wait(KBDC p)
986 if (inb(kbdcp(p)->port + KBD_STATUS_PORT) & KBDS_BUFFER_FULL) {
987 DELAY(KBDD_DELAYTIME);
988 return inb(kbdcp(p)->port + KBD_DATA_PORT);
990 return -1; /* no data */