[coreboot] [patch 3/4] libpayload: Enable keyboard translation so that we can use scancode set 1
Peter Stuge
peter at stuge.se
Fri Apr 25 20:56:27 CEST 2008
On Fri, Apr 25, 2008 at 09:52:12AM -0600, jordan.crouse at amd.com wrote:
> 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 at amd.com>
Acked-by: Peter Stuge <peter at stuge.se>
> Index: libpayload/drivers/keyboard.c
> ===================================================================
> --- libpayload.orig/drivers/keyboard.c 2008-04-23 17:33:07.000000000 -0600
> +++ libpayload/drivers/keyboard.c 2008-04-23 17:33:27.000000000 -0600
> @@ -29,6 +29,11 @@
>
> #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 @@
>
> 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: libpayload/include/libpayload.h
> ===================================================================
> --- libpayload.orig/include/libpayload.h 2008-04-23 17:33:07.000000000 -0600
> +++ libpayload/include/libpayload.h 2008-04-24 08:59:35.000000000 -0600
> @@ -67,6 +67,7 @@
> 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: libpayload/libc/console.c
> ===================================================================
> --- libpayload.orig/libc/console.c 2008-04-23 17:33:07.000000000 -0600
> +++ libpayload/libc/console.c 2008-04-23 17:33:18.000000000 -0600
> @@ -37,6 +37,9 @@
> #ifdef CONFIG_SERIAL_CONSOLE
> serial_init();
> #endif
> +#ifdef CONFIG_PC_KEYBOARD
> + keyboard_init();
> +#endif
> }
>
> static void device_putchar(unsigned char c)
More information about the coreboot
mailing list