summaryrefslogtreecommitdiff
path: root/zephyr/include
diff options
context:
space:
mode:
authorSimon Glass <sjg@chromium.org>2020-11-06 11:04:06 -0700
committerCommit Bot <commit-bot@chromium.org>2021-01-15 03:55:24 +0000
commitc3d4badd49ab9c6239c67ea67f566ee810796793 (patch)
treec2433a4b4b2f962652b8f26f075d1c8db2a408cc /zephyr/include
parentf3f18351567b7ac37724b5668285eaad4359b226 (diff)
downloadchrome-ec-c3d4badd49ab9c6239c67ea67f566ee810796793.tar.gz
drivers: add NPCX7 cros_kb_raw driver
NPCX keyboard scanning module is supported by up to 18 open-drain output signals and 8 input signals. Switch-based keyboard matrices are supported by Schmitt trigger inputs that have internal pull-up resistors. For power efficiency, the inputs include interrupt and wake-up capability so that pressing/releasing keys can be identified without scanning the keyboard matrix in either Active, Sleep or Deep Sleep power state. The CL also includes: — Add npcx cros_kb_raw device tree declarations. — cros_kb_raw api implementations - Enable Volteer keyboard scan task BRANCH=none BUG=b:167405015, b:172676906 TEST=build pass by zmake configure -B ./build projects/experimental/volteer. TEST=check all the keys on volteer platform by "ksstate". Change-Id: I1cbdaa0e81cbb4447daede82774711f4d50f613d 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/zephyr-chrome/+/2523940 Commit-Queue: Jack Rosenthal <jrosenth@chromium.org> Reviewed-by: Yuval Peress <peress@chromium.org> Reviewed-by: Jett Rink <jettrink@chromium.org> Reviewed-by: Jack Rosenthal <jrosenth@chromium.org> Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/2630148 Tested-by: Jack Rosenthal <jrosenth@chromium.org>
Diffstat (limited to 'zephyr/include')
-rw-r--r--zephyr/include/drivers/cros_kb_raw.h169
-rw-r--r--zephyr/include/dt-bindings/cros-kb-raw/npcx_cros_kb_raw.h9
-rw-r--r--zephyr/include/soc/nuvoton_npcx/reg_def_cros.h59
3 files changed, 237 insertions, 0 deletions
diff --git a/zephyr/include/drivers/cros_kb_raw.h b/zephyr/include/drivers/cros_kb_raw.h
new file mode 100644
index 0000000000..1724f59d95
--- /dev/null
+++ b/zephyr/include/drivers/cros_kb_raw.h
@@ -0,0 +1,169 @@
+/*
+ * Copyright 2020 Google LLC
+ *
+ * SPDX-License-Identifier: Apache-2.0
+ */
+
+/**
+ * @file
+ * @brief Chrome OS-specific API for raw keyboard access
+ * This exists only support the interface expected by the Chrome OS EC. It seems
+ * better to implement this so we can make use of most of the existing code in
+ * its keyboard_scan.c file and thus make sure we operate the same way.
+ *
+ * It provides raw access to keyboard GPIOs.
+ *
+ * The keyboard matrix is read (by the caller, keyboard_scan.c in ECOS) by
+ * driving output signals on the column lines and reading the row lines.
+ *
+ * This API and any drivers should be removed once we can safely move to using
+ * the Zephyr kscan API.
+ */
+
+#ifndef ZEPHYR_INCLUDE_DRIVERS_CROS_KB_RAW_H_
+#define ZEPHYR_INCLUDE_DRIVERS_CROS_KB_RAW_H_
+
+#include <kernel.h>
+#include <device.h>
+
+/**
+ * @brief CROS Keyboard Raw Driver APIs
+ * @defgroup cros_kb_raw_interface CROS Keyboard Raw Driver APIs
+ * @ingroup io_interfaces
+ * @{
+ */
+
+/**
+ * @cond INTERNAL_HIDDEN
+ *
+ * cros keyboard raw driver API definition and system call entry points
+ *
+ * (Internal use only.)
+ */
+typedef int (*cros_kb_raw_api_init)(const struct device *dev);
+
+typedef int (*cros_kb_raw_api_drive_column)(const struct device *dev, int col);
+
+typedef int (*cros_kb_raw_api_read_rows)(const struct device *dev);
+
+typedef int (*cros_kb_raw_api_enable_interrupt)(const struct device *dev,
+ int enable);
+
+__subsystem struct cros_kb_raw_driver_api {
+ cros_kb_raw_api_init init;
+ cros_kb_raw_api_drive_column drive_colum;
+ cros_kb_raw_api_read_rows read_rows;
+ cros_kb_raw_api_enable_interrupt enable_interrupt;
+};
+
+/**
+ * @endcond
+ */
+
+/**
+ * @brief Initialize the raw keyboard interface.
+ *
+ * Must be called before any other functions in this interface.
+ *
+ * @param dev Pointer to the device structure for the keyboard driver instance.
+ *
+ * @return 0 If successful.
+ * @retval -ENOTSUP Not supported api function.
+ */
+__syscall int cros_kb_raw_init(const struct device *dev);
+
+static inline int z_impl_cros_kb_raw_init(const struct device *dev)
+{
+ const struct cros_kb_raw_driver_api *api =
+ (const struct cros_kb_raw_driver_api *)dev->api;
+
+ if (!api->init) {
+ return -ENOTSUP;
+ }
+
+ return api->init(dev);
+}
+
+/**
+ * @brief Drive the specified column low.
+ *
+ * Other columns are tristated. See enum keyboard_column_index for special
+ * values for <col>.
+ *
+ * @param dev Pointer to the device structure for the keyboard driver instance.
+ * @param col Specified column is driven to low.
+ *
+ * @return 0 If successful.
+ * @retval -ENOTSUP Not supported api function.
+ */
+__syscall int cros_kb_raw_drive_column(const struct device *dev, int col);
+static inline int z_impl_cros_kb_raw_drive_column(const struct device *dev,
+ int col)
+{
+ const struct cros_kb_raw_driver_api *api =
+ (const struct cros_kb_raw_driver_api *)dev->api;
+
+ if (!api->drive_colum) {
+ return -ENOTSUP;
+ }
+
+ return api->drive_colum(dev, col);
+}
+
+/**
+ * @brief Read raw row state.
+ *
+ * Bits are 1 if signal is present, 0 if not present.
+ *
+ * @param dev Pointer to the device structure for the keyboard driver instance.
+ *
+ * @return current raw row state value.
+ */
+__syscall int cros_kb_raw_read_rows(const struct device *dev);
+static inline int z_impl_cros_kb_raw_read_rows(const struct device *dev)
+{
+ const struct cros_kb_raw_driver_api *api =
+ (const struct cros_kb_raw_driver_api *)dev->api;
+
+ if (!api->read_rows) {
+ return 0;
+ }
+
+ return api->read_rows(dev);
+}
+
+/**
+ * @brief Enable or disable keyboard interrupts.
+ *
+ * Enabling interrupts will clear any pending interrupt bits. To avoid missing
+ * any interrupts that occur between the end of scanning and then, you should
+ * call cros_kb_raw_read_rows() after this. If it returns non-zero, disable
+ * interrupts and go back to polling mode instead of waiting for an interrupt.
+ *
+ * @param dev Pointer to the device structure for the keyboard driver instance.
+ * @param enable If 1, enable keyboard interrupt. Otherwise, disable it.
+ *
+ * @return 0 If successful.
+ * @retval -ENOTSUP Not supported api function.
+ */
+__syscall int cros_kb_raw_enable_interrupt(const struct device *dev,
+ int enable);
+
+static inline int z_impl_cros_kb_raw_enable_interrupt(const struct device *dev,
+ int enable)
+{
+ const struct cros_kb_raw_driver_api *api =
+ (const struct cros_kb_raw_driver_api *)dev->api;
+
+ if (!api->enable_interrupt) {
+ return -ENOTSUP;
+ }
+
+ return api->enable_interrupt(dev, enable);
+}
+
+/**
+ * @}
+ */
+#include <syscalls/cros_kb_raw.h>
+#endif /* ZEPHYR_INCLUDE_DRIVERS_CROS_KB_RAW_H_ */
diff --git a/zephyr/include/dt-bindings/cros-kb-raw/npcx_cros_kb_raw.h b/zephyr/include/dt-bindings/cros-kb-raw/npcx_cros_kb_raw.h
new file mode 100644
index 0000000000..f979ae8481
--- /dev/null
+++ b/zephyr/include/dt-bindings/cros-kb-raw/npcx_cros_kb_raw.h
@@ -0,0 +1,9 @@
+/*
+ * Copyright 2020 Google LLC
+ *
+ * SPDX-License-Identifier: Apache-2.0
+ */
+#ifndef ZEPHYR_INCLUDE_DT_BINDINGS_CROS_KB_RAW_NPCX_CROS_KB_RAW_H_
+#define ZEPHYR_INCLUDE_DT_BINDINGS_CROS_KB_RAW_NPCX_CROS_KB_RAW_H_
+
+#endif /* ZEPHYR_INCLUDE_DT_BINDINGS_CROS_KB_RAW_NPCX_CROS_KB_RAW_H_ */
diff --git a/zephyr/include/soc/nuvoton_npcx/reg_def_cros.h b/zephyr/include/soc/nuvoton_npcx/reg_def_cros.h
new file mode 100644
index 0000000000..022c58fc24
--- /dev/null
+++ b/zephyr/include/soc/nuvoton_npcx/reg_def_cros.h
@@ -0,0 +1,59 @@
+/*
+ * Copyright (c) 2020 Nuvoton Technology Corporation.
+ *
+ * SPDX-License-Identifier: Apache-2.0
+ */
+
+/*
+ * @file
+ * @brief Nuvoton NPCX register structure definitions used by the Chrome OS EC.
+ */
+
+#ifndef _NUVOTON_NPCX_REG_DEF_CROS_H
+#define _NUVOTON_NPCX_REG_DEF_CROS_H
+
+/*
+ * KBS (Keyboard Scan) device registers
+ */
+struct kbs_reg {
+ volatile uint8_t reserved1[4];
+ /* 0x004: Keyboard Scan In */
+ volatile uint8_t KBSIN;
+ /* 0x005: Keyboard Scan In Pull-Up Enable */
+ volatile uint8_t KBSINPU;
+ /* 0x006: Keyboard Scan Out 0 */
+ volatile uint16_t KBSOUT0;
+ /* 0x008: Keyboard Scan Out 1 */
+ volatile uint16_t KBSOUT1;
+ /* 0x00A: Keyboard Scan Buffer Index */
+ volatile uint8_t KBS_BUF_INDX;
+ /* 0x00B: Keyboard Scan Buffer Data */
+ volatile uint8_t KBS_BUF_DATA;
+ /* 0x00C: Keyboard Scan Event */
+ volatile uint8_t KBSEVT;
+ /* 0x00D: Keyboard Scan Control */
+ volatile uint8_t KBSCTL;
+ /* 0x00E: Keyboard Scan Configuration Index */
+ volatile uint8_t KBS_CFG_INDX;
+ /* 0x00F: Keyboard Scan Configuration Data */
+ volatile uint8_t KBS_CFG_DATA;
+};
+
+/* KBS register fields */
+#define NPCX_KBSBUFINDX 0
+#define NPCX_KBSEVT_KBSDONE 0
+#define NPCX_KBSEVT_KBSERR 1
+#define NPCX_KBSCTL_START 0
+#define NPCX_KBSCTL_KBSMODE 1
+#define NPCX_KBSCTL_KBSIEN 2
+#define NPCX_KBSCTL_KBSINC 3
+#define NPCX_KBSCTL_KBHDRV_FIELD FIELD(6, 2)
+#define NPCX_KBSCFGINDX 0
+/* Index of 'Automatic Scan' configuration register */
+#define KBS_CFG_INDX_DLY1 0 /* Keyboard Scan Delay T1 Byte */
+#define KBS_CFG_INDX_DLY2 1 /* Keyboard Scan Delay T2 Byte */
+#define KBS_CFG_INDX_RTYTO 2 /* Keyboard Scan Retry Timeout */
+#define KBS_CFG_INDX_CNUM 3 /* Keyboard Scan Columns Number */
+#define KBS_CFG_INDX_CDIV 4 /* Keyboard Scan Clock Divisor */
+
+#endif /* _NUVOTON_NPCX_REG_DEF_CROS_H */