From a3412be19e5c4121ee65160f634bc16f4c6b6045 Mon Sep 17 00:00:00 2001 From: Simon Glass Date: Thu, 5 Nov 2020 14:59:00 -0700 Subject: 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 Signed-off-by: Wealian Liao Signed-off-by: Mulin Chao Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/2523839 Commit-Queue: Jack Rosenthal Reviewed-by: Jack Rosenthal --- zephyr/shim/chip/npcx/CMakeLists.txt | 2 + zephyr/shim/chip/npcx/clock.c | 31 +++++++++++++ zephyr/shim/chip/npcx/keyboard_raw.c | 90 ++++++++++++++++++++++++++++++++++++ 3 files changed, 123 insertions(+) create mode 100644 zephyr/shim/chip/npcx/clock.c create mode 100644 zephyr/shim/chip/npcx/keyboard_raw.c (limited to 'zephyr/shim/chip/npcx') 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 +#include +#include +#include +#include +#include +#include + +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 +#include +#include +#include +#include +#include + +#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; +} -- cgit v1.2.1