From e940c15ebb25269923db9a8a912727046cfffa77 Mon Sep 17 00:00:00 2001 From: Ralf Baechle Date: Thu, 24 Jul 1997 01:55:37 +0000 Subject: Cleanup the architecture specifics of keyboard and PS/2 mouse drivers. --- drivers/char/pc_keyb.c | 63 +++++++++++++++++++++++++++++--------------------- 1 file changed, 37 insertions(+), 26 deletions(-) (limited to 'drivers/char/pc_keyb.c') diff --git a/drivers/char/pc_keyb.c b/drivers/char/pc_keyb.c index 9e3267aaf..fd1c8e862 100644 --- a/drivers/char/pc_keyb.c +++ b/drivers/char/pc_keyb.c @@ -16,15 +16,15 @@ #include #include -/* Some configuration switches are present in the include file... */ - -#include "pc_keyb.h" - #include #include #include #include +/* Some configuration switches are present in the include file... */ + +#include "pc_keyb.h" + /* * In case we run on a non-x86 hardware we need to initialize both the keyboard * controller and the keyboard. On a x86, the BIOS will already have initialized @@ -40,7 +40,7 @@ __initfunc(static int kbd_wait_for_input(void)) n = KBD_TIMEOUT; do { - status = kbd_inb(KBD_STATUS_REG); + status = kbd_read_status(); /* * Wait for input data to become available. This bit will * then be cleared by the following read of the DATA @@ -50,7 +50,7 @@ __initfunc(static int kbd_wait_for_input(void)) if (!(status & KBD_STAT_OBF)) continue; - data = kbd_inb(KBD_DATA_REG); + data = kbd_read_input(); /* * Check to see if a timeout error has occurred. This means @@ -66,14 +66,24 @@ __initfunc(static int kbd_wait_for_input(void)) return -1; /* timed-out if fell through to here... */ } -__initfunc(static void kbd_write(int address, int data)) +__initfunc(static void init_write_command(int data)) +{ + int status; + + do { + status = kbd_read_status(); + } while (status & KBD_STAT_IBF); + kbd_write_command(data); +} + +__initfunc(static void init_write_output(int data)) { int status; do { - status = kbd_inb(KBD_STATUS_REG); + status = kbd_read_status(); } while (status & KBD_STAT_IBF); - kbd_outb(data, address); + kbd_write_output(data); } __initfunc(static char *initialize_kbd2(void)) @@ -89,7 +99,7 @@ __initfunc(static char *initialize_kbd2(void)) * If the test is successful a x55 is placed in the input buffer. */ - kbd_write(KBD_CNTL_REG, KBD_CCMD_SELF_TEST); + init_write_command(KBD_CCMD_SELF_TEST); if (kbd_wait_for_input() != 0x55) return "Keyboard failed self test"; @@ -99,13 +109,13 @@ __initfunc(static char *initialize_kbd2(void)) * test are placed in the input buffer. */ - kbd_write(KBD_CNTL_REG, KBD_CCMD_KBD_TEST); + init_write_command(KBD_CCMD_KBD_TEST); if (kbd_wait_for_input() != 0x00) return "Keyboard interface failed self test"; /* Enable the keyboard by allowing the keyboard clock to run. */ - kbd_write(KBD_CNTL_REG, KBD_CCMD_KBD_ENABLE); + init_write_command(KBD_CCMD_KBD_ENABLE); /* * Reset keyboard. If the read times out @@ -114,7 +124,7 @@ __initfunc(static char *initialize_kbd2(void)) * This defaults the keyboard to scan-code set 2. */ - kbd_write(KBD_DATA_REG, KBD_CMD_RESET); + init_write_output(KBD_CMD_RESET); if (kbd_wait_for_input() != KBD_REPLY_ACK) return "Keyboard reset failed, no ACK"; if (kbd_wait_for_input() != KBD_REPLY_POR) @@ -125,17 +135,17 @@ __initfunc(static char *initialize_kbd2(void)) * in the disabled state. */ - kbd_write(KBD_DATA_REG, KBD_CMD_DISABLE); + init_write_output(KBD_CMD_DISABLE); if (kbd_wait_for_input() != KBD_REPLY_ACK) return "Disable keyboard: no ACK"; - kbd_write(KBD_CNTL_REG, KBD_CCMD_WRITE_MODE); - kbd_write(KBD_DATA_REG, KBD_MODE_KBD_INT + init_write_command(KBD_CCMD_WRITE_MODE); + init_write_output(KBD_MODE_KBD_INT | KBD_MODE_SYS | KBD_MODE_DISABLE_MOUSE | KBD_MODE_KCC); - kbd_write(KBD_DATA_REG, KBD_CMD_ENABLE); + init_write_output(KBD_CMD_ENABLE); if (kbd_wait_for_input() != KBD_REPLY_ACK) return "Enable keyboard: no ACK"; @@ -143,10 +153,10 @@ __initfunc(static char *initialize_kbd2(void)) * Finally, set the typematic rate to maximum. */ - kbd_write(KBD_DATA_REG, KBD_CMD_SET_RATE); + init_write_output(KBD_CMD_SET_RATE); if (kbd_wait_for_input() != KBD_REPLY_ACK) return "Set rate: no ACK"; - kbd_write(KBD_DATA_REG, 0x00); + init_write_output(0x00); if (kbd_wait_for_input() != KBD_REPLY_ACK) return "Set rate: no ACK"; @@ -184,7 +194,7 @@ static inline void kb_wait(void) int i; for (i=0; i