summaryrefslogtreecommitdiff
path: root/common/keyboard.c
diff options
context:
space:
mode:
authorLouis Yung-Chieh Lo <yjlou@chromium.org>2012-04-20 09:58:32 +0800
committerLouis Yung-Chieh Lo <yjlou@chromium.org>2012-04-23 17:57:41 +0800
commit913473db710090101e5f3bae695a249a3abe3e49 (patch)
tree526849a5d8483c622d539d1a934d995ece7302ce /common/keyboard.c
parent9f552ff5aa043eddc5b6d59db09728d83faf97dd (diff)
downloadchrome-ec-913473db710090101e5f3bae695a249a3abe3e49.tar.gz
Keyboard hook up for SYSJUMP and INIT.
During the reboot_ec command, the keyboard state is lost after jump. We need to restore info including: - code set - controller_ram[0]: - XLATE - KB/TP disabled - KB/TP IRQ enabled Remove the un-necessary keyboard_init() function. BUG=chrome-os-partner:9102 TEST=tested on link. EC runs on A % ectool reboot_ec A keyboard still working % ectool reboot_ec RO keybaord still working % ectool reboot_ec RO keybaord still working ESC + power yo reset all system repeat above steps and the keyboard keeps working. Change-Id: I0fe21f7876459fc8047ff018fbfaaef5311cc49b
Diffstat (limited to 'common/keyboard.c')
-rw-r--r--common/keyboard.c59
1 files changed, 49 insertions, 10 deletions
diff --git a/common/keyboard.c b/common/keyboard.c
index 56fc8fd8c3..c9f1eac8a9 100644
--- a/common/keyboard.c
+++ b/common/keyboard.c
@@ -10,6 +10,7 @@
#include "console.h"
#include "keyboard.h"
#include "i8042.h"
+#include "hooks.h"
#include "lightbar.h"
#include "lpc.h"
#include "lpc_commands.h"
@@ -24,6 +25,7 @@
#define KEYBOARD_DEBUG 1
+
#undef ASSERT
#define ASSERT(expr) do { \
if (!(expr)) { \
@@ -76,6 +78,16 @@ static int typematic_len = 0; /* length of typematic_scan_code */
static uint8_t typematic_scan_code[MAX_SCAN_CODE_LEN];
+#define KB_SYSJUMP_TAG 0x4b42 // "KB"
+#define KB_HOOK_VERSION 1
+/* the previous keyboard state before reboot_ec. */
+struct kb_state {
+ uint8_t codeset;
+ uint8_t ctlram;
+ uint8_t pad[2]; // pad to 4 bytes for system_add_jump_tag().
+};
+
+
/* The standard Chrome OS keyboard matrix table. */
#define CROS_ROW_NUM 8 /* TODO: +1 for power button. */
#define CROS_COL_NUM 13
@@ -826,17 +838,44 @@ static int command_keyboard_press(int argc, char **argv)
DECLARE_CONSOLE_COMMAND(kbpress, command_keyboard_press);
-int keyboard_init(void)
+/* Preserves the states of keyboard controller to keep the initialized states
+ * between reboot_ec commands. Saving info include:
+ *
+ * - code set
+ * - controller_ram[0]:
+ * - XLATE
+ * - KB/TP disabled
+ * - KB/TP IRQ enabled
+ */
+static int keyboard_preserve_state(void)
{
- /* If the host is still alive during the EC resets (ex. reboot_ec),
- * we should restore keyboard states so that the user can type. */
- enum system_reset_cause_t reset_cause = system_get_reset_cause();
- if (reset_cause == SYSTEM_RESET_SOFT_WARM ||
- reset_cause == SYSTEM_RESET_WATCHDOG ||
- reset_cause == SYSTEM_RESET_SOFT_COLD ) {
- i8042_enable_keyboard_irq();
- controller_ram[0] &= ~I8042_XLATE;
+ struct kb_state state;
+
+ state.codeset = scancode_set;
+ state.ctlram = controller_ram[0];
+
+ system_add_jump_tag(KB_SYSJUMP_TAG, KB_HOOK_VERSION,
+ sizeof(state), &state);
+
+ return EC_SUCCESS;
+}
+DECLARE_HOOK(HOOK_SYSJUMP, keyboard_preserve_state, HOOK_PRIO_DEFAULT);
+
+
+/* Restores the keyboard states after reboot_ec command. See above function. */
+static int keyboard_restore_state(void)
+{
+ const struct kb_state *prev;
+ int version, size;
+
+ prev = (const struct kb_state *)system_get_jump_tag(KB_SYSJUMP_TAG,
+ &version, &size);
+ if (prev && version == KB_HOOK_VERSION && size == sizeof(*prev)) {
+ // Coming back from a sysjump, so restore settings.
+ scancode_set = prev->codeset;
+ update_ctl_ram(0, prev->ctlram);
}
- return 0;
+ return EC_SUCCESS;
}
+DECLARE_HOOK(HOOK_INIT, keyboard_restore_state, HOOK_PRIO_DEFAULT);