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