summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJack Rosenthal <jrosenth@chromium.org>2020-11-06 11:57:10 -0700
committerCommit Bot <commit-bot@chromium.org>2020-11-07 10:41:20 +0000
commit644fda4eeac6bd70542ea3a3d45940e749c04d0f (patch)
tree120576ecd05e412bfb38c44fbe37b80408099693
parent5773fade5e363800a9d8d1952f45c4dd4c49fd8e (diff)
downloadchrome-ec-644fda4eeac6bd70542ea3a3d45940e749c04d0f.tar.gz
zephyr: gpio: shim gpio_{en,dis}able_interrupt
These two platform/ec functions are used pretty widely across common code, and enables/disables the interrupt functionality on a GPIO PIN. BUG=b:172652088 BRANCH=none TEST=compile with lid switch shim, observe lid state change Signed-off-by: Jack Rosenthal <jrosenth@chromium.org> Change-Id: Iad662397da24b58e577537d835c4a2d532307bb3 Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/2523455 Reviewed-by: Jett Rink <jettrink@chromium.org>
-rw-r--r--zephyr/shim/src/gpio.c56
1 files changed, 56 insertions, 0 deletions
diff --git a/zephyr/shim/src/gpio.c b/zephyr/shim/src/gpio.c
index d0ffcdc373..bf0d1fd1a5 100644
--- a/zephyr/shim/src/gpio.c
+++ b/zephyr/shim/src/gpio.c
@@ -93,6 +93,27 @@ struct gpio_signal_callback gpio_interrupts[] = {
#endif
};
+/**
+ * get_interrupt_from_signal() - Translate a gpio_signal to the
+ * corresponding gpio_signal_callback
+ *
+ * @signal The signal to convert.
+ *
+ * Return: A pointer to the corresponding entry in gpio_interrupts, or
+ * NULL if one does not exist.
+ */
+static struct gpio_signal_callback *
+get_interrupt_from_signal(enum gpio_signal signal)
+{
+ for (size_t i = 0; i < ARRAY_SIZE(gpio_interrupts); i++) {
+ if (gpio_interrupts[i].signal == signal)
+ return &gpio_interrupts[i];
+ }
+
+ LOG_ERR("No interrupt defined for GPIO %s", configs[signal].name);
+ return NULL;
+}
+
int gpio_is_implemented(enum gpio_signal signal)
{
/* All GPIOs listed in Device Tree are consider implemented */
@@ -201,3 +222,38 @@ static int init_gpios(const struct device *unused)
return 0;
}
SYS_INIT(init_gpios, PRE_KERNEL_1, 50);
+
+int gpio_enable_interrupt(enum gpio_signal signal)
+{
+ int rv;
+ struct gpio_signal_callback *interrupt;
+
+ interrupt = get_interrupt_from_signal(signal);
+
+ if (!interrupt)
+ return -1;
+
+ rv = gpio_pin_interrupt_configure(data[signal].dev, configs[signal].pin,
+ (interrupt->flags | GPIO_INT_ENABLE) &
+ ~GPIO_INT_DISABLE);
+ if (rv < 0) {
+ LOG_ERR("Failed to enable interrupt on %s (%d)",
+ configs[signal].name, rv);
+ }
+
+ return rv;
+}
+
+int gpio_disable_interrupt(enum gpio_signal signal)
+{
+ int rv;
+
+ rv = gpio_pin_interrupt_configure(data[signal].dev, configs[signal].pin,
+ GPIO_INT_DISABLE);
+ if (rv < 0) {
+ LOG_ERR("Failed to enable interrupt on %s (%d)",
+ configs[signal].name, rv);
+ }
+
+ return rv;
+}