summaryrefslogtreecommitdiff
path: root/zephyr
diff options
context:
space:
mode:
authorSimon Glass <sjg@chromium.org>2020-11-05 14:59:00 -0700
committerCommit Bot <commit-bot@chromium.org>2020-12-01 04:11:18 +0000
commita3412be19e5c4121ee65160f634bc16f4c6b6045 (patch)
tree9e9e4b489bb926e6d5504aec42d8c197a849c62b /zephyr
parent80964208e12d90d42dc9cecea7138776a73c6bb7 (diff)
downloadchrome-ec-a3412be19e5c4121ee65160f634bc16f4c6b6045.tar.gz
zephyr: shim the keyboard scan
It shims the keyboard_scan task by introducing another keyboard_raw.c which calls down to the zephyr-chrome cros_kb_raw driver. BRANCH=none BUG=b:167405015 TEST=Build pass by zmake configure -B ./build projects/experimental/volteer. TEST=Check all the keys on volteer platform by "ksstate". Change-Id: Ic87f67c28779f7feafa350020a07ba87e3600ecd Signed-off-by: Simon Glass <sjg@chromium.org> Signed-off-by: Wealian Liao <whliao@nuvoton.corp-partner.google.com> Signed-off-by: Mulin Chao <MLChao@nuvoton.com> Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/2523839 Commit-Queue: Jack Rosenthal <jrosenth@chromium.org> Reviewed-by: Jack Rosenthal <jrosenth@chromium.org>
Diffstat (limited to 'zephyr')
-rw-r--r--zephyr/CMakeLists.txt5
-rw-r--r--zephyr/Kconfig9
-rw-r--r--zephyr/shim/chip/npcx/CMakeLists.txt2
-rw-r--r--zephyr/shim/chip/npcx/clock.c31
-rw-r--r--zephyr/shim/chip/npcx/keyboard_raw.c90
-rw-r--r--zephyr/shim/include/config_chip.h5
6 files changed, 141 insertions, 1 deletions
diff --git a/zephyr/CMakeLists.txt b/zephyr/CMakeLists.txt
index e0f53e39fc..30ae1d0f48 100644
--- a/zephyr/CMakeLists.txt
+++ b/zephyr/CMakeLists.txt
@@ -44,7 +44,10 @@ zephyr_sources_ifdef(CONFIG_PLATFORM_EC_HOSTCMD "${PLATFORM_EC}/common/host_comm
zephyr_sources_ifdef(CONFIG_PLATFORM_EC_HOSTCMD "${PLATFORM_EC}/common/host_event_commands.c")
zephyr_sources_ifdef(CONFIG_PLATFORM_EC_I2C "${PLATFORM_EC}/common/i2c_master.c")
zephyr_sources_ifdef(CONFIG_PLATFORM_EC_KEYBOARD_PROTOCOL_8042
- "${PLATFORM_EC}/common/keyboard_8042.c")
+ "${PLATFORM_EC}/common/keyboard_8042.c"
+ "${PLATFORM_EC}/common/keyboard_8042_sharedlib.c")
+zephyr_sources_ifdef(CONFIG_PLATFORM_EC_KEYBOARD
+ "${PLATFORM_EC}/common/keyboard_scan.c")
zephyr_sources_ifdef(CONFIG_PLATFORM_EC_LID_SWITCH
"${PLATFORM_EC}/common/lid_switch.c")
zephyr_sources_ifdef(CONFIG_PLATFORM_EC_POWER_BUTTON
diff --git a/zephyr/Kconfig b/zephyr/Kconfig
index 03db724612..2a979fb615 100644
--- a/zephyr/Kconfig
+++ b/zephyr/Kconfig
@@ -66,6 +66,15 @@ config PLATFORM_EC_KEYBOARD_PROTOCOL_8042
endchoice # PLATFORM_EC_KEYBOARD
+config PLATFORM_EC_KEYBOARD_COL2_INVERTED
+ bool "A mechanism for passing KSO2 to H1 which inverts the signal."
+ help
+ This option enables a mechanism for passing the column 2
+ to H1 which inverts the signal. The signal passing through H1
+ adds more delay. Need a larger delay value. Otherwise, pressing
+ Refresh key will also trigger T key, which is in the next scanning
+ column line. See http://b/156007029.
+
endif # PLATFORM_EC_KEYBOARD
config PLATFORM_EC_CONSOLE_CMD_KEYBOARD_8042
diff --git a/zephyr/shim/chip/npcx/CMakeLists.txt b/zephyr/shim/chip/npcx/CMakeLists.txt
index d464cc3e0b..0c08b9cedd 100644
--- a/zephyr/shim/chip/npcx/CMakeLists.txt
+++ b/zephyr/shim/chip/npcx/CMakeLists.txt
@@ -4,3 +4,5 @@
string(TOLOWER "i2c-${CHIP_FAMILY}.c" chip_specific_i2c_shim)
zephyr_sources(${chip_specific_i2c_shim})
+zephyr_sources(clock.c)
+zephyr_sources(keyboard_raw.c)
diff --git a/zephyr/shim/chip/npcx/clock.c b/zephyr/shim/chip/npcx/clock.c
new file mode 100644
index 0000000000..8321d5f6d3
--- /dev/null
+++ b/zephyr/shim/chip/npcx/clock.c
@@ -0,0 +1,31 @@
+/* Copyright 2020 The Chromium OS Authors. All rights reserved.
+ * Use of this source code is governed by a BSD-style license that can be
+ * found in the LICENSE file.
+ */
+
+#include <device.h>
+#include <drivers/clock_control.h>
+#include <dt-bindings/clock/npcx_clock.h>
+#include <kernel.h>
+#include <logging/log.h>
+#include <soc.h>
+#include <zephyr.h>
+
+LOG_MODULE_REGISTER(shim_clock, LOG_LEVEL_ERR);
+
+int clock_get_freq(void)
+{
+ const struct device *clk_dev = device_get_binding(NPCX_CLK_CTRL_NAME);
+ const struct npcx_clk_cfg clk_cfg = {
+ .bus = NPCX_CLOCK_BUS_CORE,
+ };
+ uint32_t rate;
+
+ if (clock_control_get_rate(clk_dev, (clock_control_subsys_t *)&clk_cfg,
+ &rate) != 0) {
+ LOG_ERR("Get %s clock rate error", clk_dev->name);
+ return -EIO;
+ }
+
+ return rate;
+}
diff --git a/zephyr/shim/chip/npcx/keyboard_raw.c b/zephyr/shim/chip/npcx/keyboard_raw.c
new file mode 100644
index 0000000000..f19b26d873
--- /dev/null
+++ b/zephyr/shim/chip/npcx/keyboard_raw.c
@@ -0,0 +1,90 @@
+/* Copyright 2020 The Chromium OS Authors. All rights reserved.
+ * Use of this source code is governed by a BSD-style license that can be
+ * found in the LICENSE file.
+ */
+
+/* Functions needed by keyboard scanner module for Chrome EC */
+
+#include <device.h>
+#include <drivers/clock_control.h>
+#include <dt-bindings/clock/npcx_clock.h>
+#include <logging/log.h>
+#include <soc.h>
+#include <zephyr.h>
+
+#include "drivers/cros_kb_raw.h"
+#include "keyboard_raw.h"
+
+LOG_MODULE_REGISTER(shim_cros_kb_raw, LOG_LEVEL_ERR);
+
+#define CROS_KB_RAW_DEV DT_LABEL(DT_NODELABEL(cros_kb_raw))
+static const struct device *cros_kb_raw_dev;
+
+/**
+ * Initialize the raw keyboard interface.
+ */
+void keyboard_raw_init(void)
+{
+ cros_kb_raw_dev = device_get_binding(CROS_KB_RAW_DEV);
+ if (!cros_kb_raw_dev) {
+ LOG_ERR("Fail to find %s", CROS_KB_RAW_DEV);
+ return;
+ }
+
+ LOG_INF("%s", __func__);
+ cros_kb_raw_init(cros_kb_raw_dev);
+}
+
+/**
+ * Finish initialization after task scheduling has started.
+ */
+void keyboard_raw_task_start(void)
+{
+ keyboard_raw_enable_interrupt(1);
+}
+
+/**
+ * Drive the specified column low.
+ */
+test_mockable void keyboard_raw_drive_column(int col)
+{
+ if (cros_kb_raw_dev)
+ cros_kb_raw_drive_column(cros_kb_raw_dev, col);
+ else
+ LOG_ERR("%s: no cros_kb_raw device!", __func__);
+}
+
+/**
+ * Read raw row state.
+ * Bits are 1 if signal is present, 0 if not present.
+ */
+test_mockable int keyboard_raw_read_rows(void)
+{
+ if (cros_kb_raw_dev) {
+ return cros_kb_raw_read_rows(cros_kb_raw_dev);
+ } else {
+ LOG_ERR("%s: no cros_kb_raw device!", __func__);
+ return -EIO;
+ }
+}
+
+/**
+ * Enable or disable keyboard interrupts.
+ */
+void keyboard_raw_enable_interrupt(int enable)
+{
+ if (cros_kb_raw_dev)
+ cros_kb_raw_enable_interrupt(cros_kb_raw_dev, enable);
+ else
+ LOG_ERR("%s: no cros_kb_raw device!", __func__);
+}
+
+/**
+ * Return true if the current value of the given input GPIO port is zero
+ */
+int keyboard_raw_is_input_low(int port, int id)
+{
+ const struct device *io_dev = npcx_get_gpio_dev(port);
+
+ return gpio_pin_get_raw(io_dev, id) == 0;
+}
diff --git a/zephyr/shim/include/config_chip.h b/zephyr/shim/include/config_chip.h
index e673630cb6..2c1a588fc6 100644
--- a/zephyr/shim/include/config_chip.h
+++ b/zephyr/shim/include/config_chip.h
@@ -91,6 +91,11 @@
#define CONFIG_HOSTCMD_ESPI_VW_SLP_S4
#endif
+#undef CONFIG_KEYBOARD_COL2_INVERTED
+#ifdef CONFIG_PLATFORM_EC_KEYBOARD_COL2_INVERTED
+#define CONFIG_KEYBOARD_COL2_INVERTED
+#endif /* CONFIG_PLATFORM_EC_KEYBOARD_COL2_INVERTED */
+
/*
* Load the chip family specific header. Normally for npcx, this would be done
* by chip/npcx/config_chip.h but since this file is replacing that header