summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJunLin <CHLin56@nuvoton.com>2021-01-29 18:40:23 +0800
committerCommit Bot <commit-bot@chromium.org>2021-02-03 16:16:15 +0000
commit67d7d755568a3a7584022bc8a7f1ccc0655e02cf (patch)
tree7e448dbd5dfebc9fbf2be709c6ae913d8d7b7524
parent514f95316006de1915a41f28e575ed8773687e3a (diff)
downloadchrome-ec-67d7d755568a3a7584022bc8a7f1ccc0655e02cf.tar.gz
zephyr: shim keyboard_8042 function
This CL Connects Zephyr host interface APIs for KBC to lpc_keyboard_* functions. BUG=b:178747744 BRANCH=None. TEST=pass "make buildall" TEST=pass "zmake testall" TEST=check console, see 8042 protocol hankshaking messages printed: 21-02-01 16:22:22.142 [25.885700 KB Clear Buffer] 21-02-01 16:22:22.143 [25.887600 KB enable] 21-02-01 16:22:22.143 [25.888900 KS enable] 21-02-01 16:22:22.143 [25.890800 KB Clear Buffer] 21-02-01 16:22:22.143 [25.893700 KB scancode set to 1] 21-02-01 16:22:22.151 [25.896400 KB Clear Buffer] 21-02-01 16:22:22.151 [25.899000 KB Clear Buffer] 21-02-01 16:22:23.144 [00025887] <inf> espi_shim: KB put 55 21-02-01 16:22:23.144 [00025887] <inf> espi_shim: KB put 00 21-02<inf> espi_shim: KB put fa 21-02-01 16:22:23.156 [00025898] <inf> espi_shim: KB put fa 21-02-01 16:22:23.156 [00025901] <inf> espi_shim: KB put fa Signed-off-by: JunLin <CHLin56@nuvoton.com> Change-Id: I39ee19630da8561e392de34a277c043dbeae4c6c Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/2659137 Tested-by: CH Lin <chlin56@nuvoton.com> Reviewed-by: Simon Glass <sjg@chromium.org> Commit-Queue: Simon Glass <sjg@chromium.org>
-rw-r--r--common/keyboard_8042.c9
-rw-r--r--zephyr/shim/src/espi.c77
2 files changed, 77 insertions, 9 deletions
diff --git a/common/keyboard_8042.c b/common/keyboard_8042.c
index 9fbde467a0..a9b4c32bd8 100644
--- a/common/keyboard_8042.c
+++ b/common/keyboard_8042.c
@@ -49,15 +49,6 @@
#define CMD_KEYBOARD_LOG 0
#endif
-#ifdef CONFIG_ZEPHYR
-/* b/171815541: Implement these when LPC is ready */
-void lpc_keyboard_clear_buffer(void) {}
-void lpc_keyboard_resume_irq(void) {}
-int lpc_keyboard_has_char(void) { return 0; }
-void lpc_keyboard_put_char(uint8_t chr, int send_irq) {}
-int lpc_keyboard_input_pending(void) { return 0; }
-#endif
-
static enum {
STATE_NORMAL = 0,
STATE_SCANCODE,
diff --git a/zephyr/shim/src/espi.c b/zephyr/shim/src/espi.c
index 5292a0e507..a480ca6709 100644
--- a/zephyr/shim/src/espi.c
+++ b/zephyr/shim/src/espi.c
@@ -17,10 +17,13 @@
#include "espi.h"
#include "gpio.h"
#include "hooks.h"
+#include "i8042_protocol.h"
+#include "keyboard_protocol.h"
#include "lpc.h"
#include "port80.h"
#include "power.h"
#include "soc_espi.h"
+#include "task.h"
#include "timer.h"
#include "zephyr_espi_shim.h"
@@ -136,6 +139,7 @@ static void espi_vwire_handler(const struct device *dev,
static void handle_host_write(uint32_t data);
static void handle_acpi_write(uint32_t data);
+static void kbc_ibf_obe_handler(uint32_t data);
static void espi_peripheral_handler(const struct device *dev,
struct espi_callback *cb,
@@ -157,6 +161,12 @@ static void espi_peripheral_handler(const struct device *dev,
event_type == ESPI_PERIPHERAL_EC_HOST_CMD) {
handle_host_write(event.evt_data);
}
+
+ if (IS_ENABLED(CONFIG_ESPI_PERIPHERAL_8042_KBC) &&
+ IS_ENABLED(HAS_TASK_KEYPROTO) &&
+ event_type == ESPI_PERIPHERAL_8042_KBC) {
+ kbc_ibf_obe_handler(event.evt_data);
+ }
}
#ifdef CONFIG_PLATFORM_EC_CHIPSET_RESET_HOOK
@@ -491,3 +501,70 @@ static enum ec_status lpc_get_protocol_info(struct host_cmd_handler_args *args)
}
DECLARE_HOST_COMMAND(EC_CMD_GET_PROTOCOL_INFO, lpc_get_protocol_info,
EC_VER_MASK(0));
+
+#if defined(CONFIG_ESPI_PERIPHERAL_8042_KBC)
+/*
+ * This function is needed only for the obsolete platform which uses the GPIO
+ * for KBC's IRQ.
+ */
+void lpc_keyboard_resume_irq(void) {}
+
+void lpc_keyboard_clear_buffer(void)
+{
+ /* Clear OBF flag in host STATUS and HIKMST regs */
+ espi_write_lpc_request(espi_dev, E8042_CLEAR_OBF, 0);
+}
+int lpc_keyboard_has_char(void)
+{
+ uint32_t status;
+
+ /* if OBF bit is '1', that mean still have a data in DBBOUT */
+ espi_read_lpc_request(espi_dev, E8042_OBF_HAS_CHAR, &status);
+ return status;
+}
+
+void lpc_keyboard_put_char(uint8_t chr, int send_irq)
+{
+ uint32_t kb_char = chr;
+
+ espi_write_lpc_request(espi_dev, E8042_WRITE_KB_CHAR, &kb_char);
+ LOG_INF("KB put %02x", kb_char);
+}
+
+/* Put an aux char to host buffer by HIMDO and assert status bit 5. */
+void lpc_aux_put_char(uint8_t chr, int send_irq)
+{
+ uint32_t kb_char = chr;
+ uint32_t status = I8042_AUX_DATA;
+
+ espi_write_lpc_request(espi_dev, E8042_SET_FLAG, &status);
+ espi_write_lpc_request(espi_dev, E8042_WRITE_KB_CHAR, &kb_char);
+ LOG_INF("AUX put %02x", kb_char);
+}
+
+#ifdef HAS_TASK_KEYPROTO
+static void kbc_ibf_obe_handler(uint32_t data)
+{
+ uint8_t is_ibf = (data >> NPCX_8042_EVT_POS) & NPCX_8042_EVT_IBF;
+ uint32_t status = I8042_AUX_DATA;
+
+ if (is_ibf) {
+ keyboard_host_write((data >> NPCX_8042_DATA_POS) & 0xFF,
+ (data >> NPCX_8042_TYPE_POS) & 0xFF);
+ } else if (IS_ENABLED(CONFIG_8042_AUX)) {
+ espi_write_lpc_request(espi_dev, E8042_CLEAR_FLAG, &status);
+ }
+ task_wake(TASK_ID_KEYPROTO);
+}
+#endif
+
+int lpc_keyboard_input_pending(void)
+{
+ uint32_t status;
+
+ /* if IBF bit is '1', that mean still have a data in DBBIN */
+ espi_read_lpc_request(espi_dev, E8042_IBF_HAS_CHAR, &status);
+ return status;
+}
+
+#endif