summaryrefslogtreecommitdiff
path: root/zephyr/shim/chip/npcx
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/shim/chip/npcx
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/shim/chip/npcx')
-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
3 files changed, 123 insertions, 0 deletions
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;
+}