libpayload: Enable keyboard translation so that we can use scancode set 1
authorJordan Crouse <jordan.crouse@amd.com>
Fri, 25 Apr 2008 23:09:39 +0000 (23:09 +0000)
committerJordan Crouse <jordan.crouse@amd.com>
Fri, 25 Apr 2008 23:09:39 +0000 (23:09 +0000)
The qemu keyboard controller defaults to using scancode set 2, we use set 1.
Turn on the translate mode in the keyboard controller to force the issue.

Signed-off-by: Jordan Crouse <jordan.crouse@amd.com>
Acked-by: Peter Stuge <peter@stuge.se>
git-svn-id: svn://svn.coreboot.org/coreboot/trunk@3270 2b7e53f0-3cfb-0310-b3e9-8179ed1497e1

payloads/libpayload/drivers/keyboard.c
payloads/libpayload/include/libpayload.h
payloads/libpayload/libc/console.c

index 1049b9ccec909dba82ee73bf21100ed67b0a3515..540936dae5fa769e13e1d0d9d6e41f9823521ec1 100644 (file)
 
 #include <libpayload.h>
 
+#define I8042_CMD_READ_MODE  0x20
+#define I8042_CMD_WRITE_MODE 0x60
+
+#define I8042_MODE_XLATE     0x40
+
 unsigned char map[2][0x57] = {
        {
         0x00, 0x1B, 0x31, 0x32, 0x33, 0x34, 0x35, 0x36,
@@ -118,3 +123,54 @@ int keyboard_getchar(void)
 
        return ret;
 }
+
+static int keyboard_wait_read(void)
+{
+       int timeout = 10000;
+
+       while(timeout-- && !(inb(0x64) & 0x01))
+               udelay(50);
+
+       return (timeout <= 0) ? -1 : 0;
+}
+
+static int keyboard_wait_write(void)
+{
+       int timeout = 10000;
+
+       while(timeout-- && (inb(0x64) & 0x02))
+               udelay(50);
+
+       return (timeout <= 0) ? -1 : 0;
+}
+
+static unsigned char keyboard_get_mode(void)
+{
+       outb(I8042_CMD_READ_MODE, 0x64);
+       keyboard_wait_read();
+       return inb(0x60);
+}
+
+static void keyboard_set_mode(unsigned char mode)
+{
+       outb(I8042_CMD_WRITE_MODE, 0x64);
+       keyboard_wait_write();
+       outb(mode, 0x60);
+}
+
+void keyboard_init(void)
+{
+       u8 mode;
+
+       /* Read the current mode */
+       mode = keyboard_get_mode();
+
+       /* Turn on scancode translate mode so that we can
+          use the scancode set 1 tables */
+
+       mode |= I8042_MODE_XLATE;
+
+       /* Write the new mode */
+       keyboard_set_mode(mode);
+}
+
index 611f65e43238f1513c54987bf7a60b30a596d936..d557eeff697a65d8de7bf37435c2d83a658bac65 100644 (file)
@@ -67,6 +67,7 @@ u8 nvram_read(u8 addr);
 void nvram_write(u8 val, u8 addr);
 
 /* drivers/keyboard.c */
+void keyboard_init(void);
 int keyboard_havechar(void);
 unsigned char keyboard_get_scancode(void);
 int keyboard_getchar(void);
index b0bfe241c058a6a8787364a28dc495853bf5ad09..292cac9ca3963d6ea9068ba7e58e50ac72c018ed 100644 (file)
@@ -37,6 +37,9 @@ void console_init(void)
 #ifdef CONFIG_SERIAL_CONSOLE
        serial_init();
 #endif
+#ifdef CONFIG_PC_KEYBOARD
+       keyboard_init();
+#endif
 }
 
 static void device_putchar(unsigned char c)