libpayload: Fix handling of CAPS LOCK key on PS/2 keyboards
[coreboot.git] / payloads / libpayload / drivers / keyboard.c
index 95827463ca2b3827fd0ac47c265413857a4175b7..717ee5541cd70919e0a8e9130ac8e1dabbf47961 100644 (file)
@@ -27,8 +27,8 @@
  * SUCH DAMAGE.
  */
 
+#include <libpayload-config.h>
 #include <libpayload.h>
-#include <config.h>
 #include <curses.h>
 
 #define I8042_CMD_READ_MODE  0x20
 
 #define I8042_MODE_XLATE     0x40
 
-static void (*reset_handler)(void) = NULL;
-
 struct layout_maps {
-       char *country;
-       unsigned short map[4][0x57];
+       const char *country;
+       const unsigned short map[4][0x57];
 };
 
-struct layout_maps *map;
+static struct layout_maps *map;
 
-struct layout_maps keyboard_layouts[] = {
+static struct layout_maps keyboard_layouts[] = {
 #ifdef CONFIG_PC_KEYBOARD_LAYOUT_US
 { .country = "us", .map = {
        { /* No modifier */
@@ -168,11 +166,13 @@ struct layout_maps keyboard_layouts[] = {
 
 static void keyboard_cmd(unsigned char cmd, unsigned char val)
 {
+       while (inb(0x64) & 2);
        outb(cmd, 0x60);
-       /* wait until keyboard controller accepts cmds: */
+       mdelay(20);
+
        while (inb(0x64) & 2);
        outb(val, 0x60);
-       while (inb(0x64) & 2);
+       mdelay(20);
 }
 
 int keyboard_havechar(void)
@@ -263,22 +263,22 @@ int keyboard_getchar(void)
 
 static int keyboard_wait_read(void)
 {
-       int timeout = 10000;
+       int retries = 10000;
 
-       while(timeout-- && !(inb(0x64) & 0x01))
+       while(retries-- && !(inb(0x64) & 0x01))
                udelay(50);
 
-       return (timeout <= 0) ? -1 : 0;
+       return (retries <= 0) ? -1 : 0;
 }
 
 static int keyboard_wait_write(void)
 {
-       int timeout = 10000;
+       int retries = 10000;
 
-       while(timeout-- && (inb(0x64) & 0x02))
+       while(retries-- && (inb(0x64) & 0x02))
                udelay(50);
 
-       return (timeout <= 0) ? -1 : 0;
+       return (retries <= 0) ? -1 : 0;
 }
 
 static unsigned char keyboard_get_mode(void)
@@ -297,7 +297,7 @@ static void keyboard_set_mode(unsigned char mode)
 
 /**
  * Set keyboard layout
- * @param country string describing the keyboard layout language. 
+ * @param country string describing the keyboard layout language.
  * Valid values are "us", "de".
  */
 
@@ -319,12 +319,10 @@ int keyboard_set_layout(char *country)
        return -1;
 }
 
-int keyboard_add_reset_handler(void (*new_handler)(void))
-{
-       reset_handler = new_handler;
-
-       return 0;
-}
+static struct console_input_driver cons = {
+       .havekey = keyboard_havechar,
+       .getchar = keyboard_getchar
+};
 
 void keyboard_init(void)
 {
@@ -350,5 +348,7 @@ void keyboard_init(void)
 
        /* Write the new mode */
        keyboard_set_mode(mode);
+
+       console_add_input_driver(&cons);
 }