summaryrefslogtreecommitdiff
path: root/zephyr/shim/chip/it8xxx2
diff options
context:
space:
mode:
Diffstat (limited to 'zephyr/shim/chip/it8xxx2')
-rw-r--r--zephyr/shim/chip/it8xxx2/gpio.c72
-rw-r--r--zephyr/shim/chip/it8xxx2/include/gpio_it8xxx2.h28
-rw-r--r--zephyr/shim/chip/it8xxx2/keyboard_raw.c27
3 files changed, 121 insertions, 6 deletions
diff --git a/zephyr/shim/chip/it8xxx2/gpio.c b/zephyr/shim/chip/it8xxx2/gpio.c
index 16eb7a3963..78aa504140 100644
--- a/zephyr/shim/chip/it8xxx2/gpio.c
+++ b/zephyr/shim/chip/it8xxx2/gpio.c
@@ -4,6 +4,9 @@
*/
#include "gpio/gpio.h"
+#include "gpio_it8xxx2.h"
+
+#include <errno.h>
#include <zephyr/device.h>
#include <zephyr/drivers/gpio.h>
@@ -52,3 +55,72 @@ int gpio_config_unused_pins(void)
return 0;
}
+
+int gpio_configure_port_pin(int port, int id, int flags)
+{
+ const struct device *dev;
+
+ /*
+ * Port number mapping to node
+ * 0 gpioa
+ * ... ...
+ * 50 gpioksi
+ * 51 gpioksoh
+ * 52 gpioksol
+ */
+ switch ((enum gpio_port_to_node)port) {
+ case GPIO_A:
+ dev = DEVICE_DT_GET(DT_NODELABEL(gpioa));
+ break;
+ case GPIO_B:
+ dev = DEVICE_DT_GET(DT_NODELABEL(gpiob));
+ break;
+ case GPIO_C:
+ dev = DEVICE_DT_GET(DT_NODELABEL(gpioc));
+ break;
+ case GPIO_D:
+ dev = DEVICE_DT_GET(DT_NODELABEL(gpiod));
+ break;
+ case GPIO_E:
+ dev = DEVICE_DT_GET(DT_NODELABEL(gpioe));
+ break;
+ case GPIO_F:
+ dev = DEVICE_DT_GET(DT_NODELABEL(gpiof));
+ break;
+ case GPIO_G:
+ dev = DEVICE_DT_GET(DT_NODELABEL(gpiog));
+ break;
+ case GPIO_H:
+ dev = DEVICE_DT_GET(DT_NODELABEL(gpioh));
+ break;
+ case GPIO_I:
+ dev = DEVICE_DT_GET(DT_NODELABEL(gpioi));
+ break;
+ case GPIO_J:
+ dev = DEVICE_DT_GET(DT_NODELABEL(gpioj));
+ break;
+ case GPIO_K:
+ dev = DEVICE_DT_GET(DT_NODELABEL(gpiok));
+ break;
+ case GPIO_L:
+ dev = DEVICE_DT_GET(DT_NODELABEL(gpiol));
+ break;
+ case GPIO_M:
+ dev = DEVICE_DT_GET(DT_NODELABEL(gpiom));
+ break;
+ case GPIO_KSI:
+ dev = DEVICE_DT_GET(DT_NODELABEL(gpioksi));
+ break;
+ case GPIO_KSOH:
+ dev = DEVICE_DT_GET(DT_NODELABEL(gpioksoh));
+ break;
+ case GPIO_KSOL:
+ dev = DEVICE_DT_GET(DT_NODELABEL(gpioksol));
+ break;
+ default:
+ printk("Error port number %d\n", port);
+ return -EINVAL;
+ }
+
+ return gpio_pin_configure(dev, id, flags);
+}
diff --git a/zephyr/shim/chip/it8xxx2/include/gpio_it8xxx2.h b/zephyr/shim/chip/it8xxx2/include/gpio_it8xxx2.h
new file mode 100644
index 0000000000..7abf9f560a
--- /dev/null
+++ b/zephyr/shim/chip/it8xxx2/include/gpio_it8xxx2.h
@@ -0,0 +1,28 @@
+/* Copyright 2023 The ChromiumOS Authors
+ * Use of this source code is governed by a BSD-style license that can be
+ * found in the LICENSE file.
+ */
+
+#ifndef __CROS_EC_GPIO_IT8XXX2_H
+#define __CROS_EC_GPIO_IT8XXX2_H
+
+enum gpio_port_to_node {
+ GPIO_A,
+ GPIO_B,
+ GPIO_C,
+ GPIO_D,
+ GPIO_E,
+ GPIO_F,
+ GPIO_G,
+ GPIO_H,
+ GPIO_I,
+ GPIO_J,
+ GPIO_K,
+ GPIO_L,
+ GPIO_M,
+ GPIO_KSI = 50,
+ GPIO_KSOH = 51,
+ GPIO_KSOL = 52
+};
+
+#endif /* __CROS_EC_GPIO_IT8XXX2_H */
diff --git a/zephyr/shim/chip/it8xxx2/keyboard_raw.c b/zephyr/shim/chip/it8xxx2/keyboard_raw.c
index 5fe99b7efa..442b51a59a 100644
--- a/zephyr/shim/chip/it8xxx2/keyboard_raw.c
+++ b/zephyr/shim/chip/it8xxx2/keyboard_raw.c
@@ -6,6 +6,7 @@
/* Functions needed by keyboard scanner module for Chrome EC */
#include "drivers/cros_kb_raw.h"
+#include "gpio_it8xxx2.h"
#include "keyboard_raw.h"
#include <zephyr/device.h>
@@ -15,13 +16,27 @@
#include <soc.h>
/**
- * Return true if the current value of the given input GPIO port is zero
+ * Return true if the current value of the given gpioksi/gpioksoh/gpioksol
+ * port is zero
*/
int keyboard_raw_is_input_low(int port, int id)
{
- /*
- * TODO: implement for factory testing KSI and KSO pin as GPIO
- * function.
- */
- return 0;
+ const struct device *dev;
+
+ switch ((enum gpio_port_to_node)port) {
+ case GPIO_KSI:
+ dev = DEVICE_DT_GET(DT_NODELABEL(gpioksi));
+ break;
+ case GPIO_KSOH:
+ dev = DEVICE_DT_GET(DT_NODELABEL(gpioksoh));
+ break;
+ case GPIO_KSOL:
+ dev = DEVICE_DT_GET(DT_NODELABEL(gpioksol));
+ break;
+ default:
+ printk("Error port number %d, return 0\n", port);
+ return 0;
+ }
+
+ return (gpio_pin_get_raw(dev, id) == 0);
}