patch-1.3.40 linux/drivers/char/keyboard.c
Next file: linux/drivers/char/vga.c
Previous file: linux/drivers/char/console.c
Back to the patch index
Back to the overall index
- Lines: 268
- Date:
Sat Nov 11 11:18:58 1995
- Orig file:
v1.3.39/linux/drivers/char/keyboard.c
- Orig date:
Wed Nov 8 07:11:31 1995
diff -u --recursive --new-file v1.3.39/linux/drivers/char/keyboard.c linux/drivers/char/keyboard.c
@@ -36,6 +36,17 @@
#include "diacr.h"
#include "vt_kern.h"
+/*
+ * On non-x86 hardware we do a full keyboard controller
+ * initialization, in case the bootup software hasn't done
+ * it. On a x86, the BIOS will already have initialized the
+ * keyboard.
+ */
+#ifndef __i386__
+#define INIT_KBD
+static int initialize_kbd(void);
+#endif
+
#define SIZE(x) (sizeof(x)/sizeof((x)[0]))
#define KBD_REPORT_ERR
@@ -1195,35 +1206,15 @@
bh_base[KEYBOARD_BH].routine = kbd_bh;
request_irq(KEYBOARD_IRQ, keyboard_interrupt, 0, "keyboard");
request_region(0x60,16,"kbd");
-#ifdef __alpha__
-#if 0
- /* if there is an input byte left, eat it up: */
- if (inb(0x64) & 0x01) {
- inb(0x60);
- }
-
- /* enable keyboard interrupts, PC/AT mode */
- kb_wait();
- outb(0x60,0x64); /* write PS/2 Mode Register */
- kb_wait();
- outb(0x65,0x60); /* KCC | DMS | SYS | EKI */
- kb_wait();
- if (!send_data(0xf0) || !send_data(0x02))
- printk("Scanmode 2 change failed\n");
-#else /* 0 */
- {
- static int alpha_kbd_init(void); /* forward decl */
-
- alpha_kbd_init();
- }
-#endif /* 0 */
-#endif /* __alpha __ */
+#ifdef INIT_KBD
+ initialize_kbd();
+#endif
mark_bh(KEYBOARD_BH);
enable_bh(KEYBOARD_BH);
return 0;
}
-#ifdef __alpha__
+#ifdef INIT_KBD
/*
* keyboard controller registers
*/
@@ -1260,11 +1251,13 @@
* keyboard controller mode register bits
*/
#define KBD_EKI (unsigned int) 0x01
+#define KBD_SYS (unsigned int) 0x04
+#define KBD_DMS (unsigned int) 0x20
+#define KBD_KCC (unsigned int) 0x40
#define TIMEOUT_CONST 500000
-static int
-kbd_wait_for_input(void)
+static int kbd_wait_for_input(void)
{
int n;
int status, data;
@@ -1297,105 +1290,102 @@
return (-1); /* timed-out if fell through to here... */
}
-static void
-kbd_write(int address, int data)
+static void kbd_write(int address, int data)
{
- int status;
-
- do {
- status = inb(KBD_STATUS_REG); /* spin until input buffer empty*/
- } while (status & KBD_IBF);
- outb(data, address); /* write out the data*/
-}
-
-static int
-alpha_kbd_init(void)
-{
- unsigned long flags;
-
- save_flags(flags); cli();
-
- /* Flush any pending input. */
- while (kbd_wait_for_input() != -1)
- continue;
-
- /*
- * Test the keyboard interface.
- * This seems to be the only way to get it going.
- * If the test is successful a x55 is placed in the input buffer.
- */
- kbd_write(KBD_CNTL_REG, KBD_SELF_TEST);
- if (kbd_wait_for_input() != 0x55) {
- printk("alpha_kbd_init: keyboard failed self test.\n");
- restore_flags(flags);
- return(-1);
- }
+ int status;
- /*
- * Perform a keyboard interface test. This causes the controller
- * to test the keyboard clock and data lines. The results of the
- * test are placed in the input buffer.
- */
- kbd_write(KBD_CNTL_REG, KBD_SELF_TEST2);
- if (kbd_wait_for_input() != 0x00) {
- printk("alpha_kbd_init: keyboard failed self test 2.\n");
- restore_flags(flags);
- return(-1);
- }
+ do {
+ status = inb(KBD_STATUS_REG); /* spin until input buffer empty*/
+ } while (status & KBD_IBF);
+ outb(data, address); /* write out the data*/
+}
- /* Enable the keyboard by allowing the keyboard clock to run. */
- kbd_write(KBD_CNTL_REG, KBD_CNTL_ENABLE);
+static int initialize_kbd(void)
+{
+ unsigned long flags;
- /*
- * Reset keyboard. If the read times out
- * then the assumption is that no keyboard is
- * plugged into the machine.
- * This defaults the keyboard to scan-code set 2.
- */
- kbd_write(KBD_DATA_REG, KBD_RESET);
- if (kbd_wait_for_input() != KBD_ACK) {
- printk("alpha_kbd_init: reset kbd failed, no ACK.\n");
- restore_flags(flags);
- return(-1);
- }
+ save_flags(flags); cli();
- if (kbd_wait_for_input() != KBD_POR) {
- printk("alpha_kbd_init: reset kbd failed, not POR.\n");
- restore_flags(flags);
- return(-1);
- }
+ /* Flush any pending input. */
+ while (kbd_wait_for_input() != -1)
+ continue;
- /*
- * now do a DEFAULTS_DISABLE always
- */
- kbd_write(KBD_DATA_REG, KBD_DISABLE);
- if (kbd_wait_for_input() != KBD_ACK) {
- printk("alpha_kbd_init: disable kbd failed, no ACK.\n");
- restore_flags(flags);
- return(-1);
- }
+ /*
+ * Test the keyboard interface.
+ * This seems to be the only way to get it going.
+ * If the test is successful a x55 is placed in the input buffer.
+ */
+ kbd_write(KBD_CNTL_REG, KBD_SELF_TEST);
+ if (kbd_wait_for_input() != 0x55) {
+ printk("initialize_kbd: keyboard failed self test.\n");
+ restore_flags(flags);
+ return(-1);
+ }
- /*
- * enable keyboard interrupt, operate in "real" mode,
- * Enable keyboard (by clearing the disable keyboard bit),
- * no conversion of keycodes.
- */
- kbd_write(KBD_CNTL_REG, KBD_WRITE_MODE);
- kbd_write(KBD_DATA_REG, KBD_EKI);
-
- /*
- * now ENABLE the keyboard to set it scanning...
- */
- kbd_write(KBD_DATA_REG, KBD_ENABLE);
- if (kbd_wait_for_input() != KBD_ACK) {
- printk("alpha_kbd_init: keyboard enable failed.\n");
- restore_flags(flags);
- return(-1);
- }
+ /*
+ * Perform a keyboard interface test. This causes the controller
+ * to test the keyboard clock and data lines. The results of the
+ * test are placed in the input buffer.
+ */
+ kbd_write(KBD_CNTL_REG, KBD_SELF_TEST2);
+ if (kbd_wait_for_input() != 0x00) {
+ printk("initialize_kbd: keyboard failed self test 2.\n");
+ restore_flags(flags);
+ return(-1);
+ }
+
+ /* Enable the keyboard by allowing the keyboard clock to run. */
+ kbd_write(KBD_CNTL_REG, KBD_CNTL_ENABLE);
+
+ /*
+ * Reset keyboard. If the read times out
+ * then the assumption is that no keyboard is
+ * plugged into the machine.
+ * This defaults the keyboard to scan-code set 2.
+ */
+ kbd_write(KBD_DATA_REG, KBD_RESET);
+ if (kbd_wait_for_input() != KBD_ACK) {
+ printk("initialize_kbd: reset kbd failed, no ACK.\n");
+ restore_flags(flags);
+ return(-1);
+ }
+
+ if (kbd_wait_for_input() != KBD_POR) {
+ printk("initialize_kbd: reset kbd failed, not POR.\n");
+ restore_flags(flags);
+ return(-1);
+ }
+
+ /*
+ * now do a DEFAULTS_DISABLE always
+ */
+ kbd_write(KBD_DATA_REG, KBD_DISABLE);
+ if (kbd_wait_for_input() != KBD_ACK) {
+ printk("initialize_kbd: disable kbd failed, no ACK.\n");
+ restore_flags(flags);
+ return(-1);
+ }
- restore_flags(flags);
+ /*
+ * Enable keyboard interrupt, operate in "sys" mode,
+ * enable keyboard (by clearing the disable keyboard bit),
+ * disable mouse, do conversion of keycodes.
+ */
+ kbd_write(KBD_CNTL_REG, KBD_WRITE_MODE);
+ kbd_write(KBD_DATA_REG, KBD_EKI|KBD_SYS|KBD_DMS|KBD_KCC);
+
+ /*
+ * now ENABLE the keyboard to set it scanning...
+ */
+ kbd_write(KBD_DATA_REG, KBD_ENABLE);
+ if (kbd_wait_for_input() != KBD_ACK) {
+ printk("initialize_kbd: keyboard enable failed.\n");
+ restore_flags(flags);
+ return(-1);
+ }
- return (1);
+ restore_flags(flags);
+ return (1);
}
-#endif /* __alpha__ */
+#endif /* INIT_KBD */
FUNET's LINUX-ADM group, linux-adm@nic.funet.fi
TCL-scripts by Sam Shen, slshen@lbl.gov
with Sam's (original) version of this