From c4b8bec5fee4e30a165fd14a188cf3ab8eccd095 Mon Sep 17 00:00:00 2001 From: Vladimir Serbinenko Date: Tue, 9 May 2017 14:27:52 +0200 Subject: [PATCH 036/227] at_keyboard: Fix falco chromebook case. EC is slow, so we need few delays for it to toggle the bits correctly. Command to enable clock and keyboard were not sent. --- grub-core/term/at_keyboard.c | 23 ++++++++++++++--------- include/grub/at_keyboard.h | 2 ++ 2 files changed, 16 insertions(+), 9 deletions(-) diff --git a/grub-core/term/at_keyboard.c b/grub-core/term/at_keyboard.c index 3ab4e205f40..f0a986eb176 100644 --- a/grub-core/term/at_keyboard.c +++ b/grub-core/term/at_keyboard.c @@ -40,6 +40,8 @@ grub_keyboard_controller_init (void); static void keyboard_controller_wait_until_ready (void) { + /* 50 us would be enough but our current time resolution is 1ms. */ + grub_millisleep (1); while (! KEYBOARD_COMMAND_ISREADY (grub_inb (KEYBOARD_REG_STATUS))); } @@ -50,10 +52,11 @@ wait_ack (void) grub_uint8_t ack; endtime = grub_get_time_ms () + 20; - do + do { + keyboard_controller_wait_until_ready (); ack = grub_inb (KEYBOARD_REG_DATA); - while (ack != GRUB_AT_ACK && ack != GRUB_AT_NACK - && grub_get_time_ms () < endtime); + } while (ack != GRUB_AT_ACK && ack != GRUB_AT_NACK + && grub_get_time_ms () < endtime); return ack; } @@ -135,12 +138,10 @@ query_mode (void) if (!e) return 0; - keyboard_controller_wait_until_ready (); - - do + do { + keyboard_controller_wait_until_ready (); ret = grub_inb (KEYBOARD_REG_DATA); - while (ret == GRUB_AT_ACK); - + } while (ret == GRUB_AT_ACK); /* QEMU translates the set even in no-translate mode. */ if (ret == 0x43 || ret == 1) return 1; @@ -169,7 +170,11 @@ set_scancodes (void) #else grub_keyboard_controller_write (grub_keyboard_controller_orig - & ~KEYBOARD_AT_TRANSLATE); + & ~KEYBOARD_AT_TRANSLATE + & ~KEYBOARD_AT_DISABLE); + + keyboard_controller_wait_until_ready (); + grub_outb (KEYBOARD_COMMAND_ENABLE, KEYBOARD_REG_DATA); write_mode (2); ps2_state.current_set = query_mode (); diff --git a/include/grub/at_keyboard.h b/include/grub/at_keyboard.h index b031523eb7d..bcb4d9ba78f 100644 --- a/include/grub/at_keyboard.h +++ b/include/grub/at_keyboard.h @@ -23,9 +23,11 @@ #define KEYBOARD_COMMAND_ISREADY(x) !((x) & 0x02) #define KEYBOARD_COMMAND_READ 0x20 #define KEYBOARD_COMMAND_WRITE 0x60 +#define KEYBOARD_COMMAND_ENABLE 0xf4 #define KEYBOARD_COMMAND_REBOOT 0xfe #define KEYBOARD_AT_TRANSLATE 0x40 +#define KEYBOARD_AT_DISABLE 0x10 #define KEYBOARD_ISMAKE(x) !((x) & 0x80) #define KEYBOARD_ISREADY(x) ((x) & 0x01) -- 2.15.0