summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAndrew McRae <amcrae@google.com>2022-01-28 16:33:26 +1100
committerCommit Bot <commit-bot@chromium.org>2022-01-28 22:21:50 +0000
commit2b7f6681c7522d67637bfe62678be721f6ba3b4f (patch)
treed45df43e958e985715ca4a674f932fe1be8866d4
parentb9e67c438a5b14fc8e4a67fa7b6082d80762781a (diff)
downloadchrome-ec-2b7f6681c7522d67637bfe62678be721f6ba3b4f.tar.gz
zephyr: Remove legacy interrupt support
Now that EC_CROS_GPIO_INTERRUPTS has been completely removed, remove the legacy interrupt support. BUG=b:214608987 TEST=zmake testall BRANCH=none Signed-off-by: Andrew McRae <amcrae@google.com> Change-Id: I82fac3ab2cf1af6297cd2df485426144510ba3bf Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/3422862 Reviewed-by: Keith Short <keithshort@chromium.org>
-rw-r--r--zephyr/shim/src/gpio_int.c212
1 files changed, 9 insertions, 203 deletions
diff --git a/zephyr/shim/src/gpio_int.c b/zephyr/shim/src/gpio_int.c
index 4357ee67ac..ca619fadae 100644
--- a/zephyr/shim/src/gpio_int.c
+++ b/zephyr/shim/src/gpio_int.c
@@ -16,136 +16,6 @@
LOG_MODULE_REGISTER(gpio_int, LOG_LEVEL_ERR);
/*
- * TODO(b:214608987): Once all interrupts have been transitioned to
- * the new API, the legacy interrupt handling can be removed.
- */
-
-/* Maps platform/ec gpio callback information */
-struct gpio_signal_callback {
- /* The platform/ec gpio_signal */
- const enum gpio_signal signal;
- /* IRQ handler from platform/ec code */
- void (*const irq_handler)(enum gpio_signal signal);
- /* Interrupt-related gpio flags */
- const gpio_flags_t flags;
-};
-
-/*
- * EC_CROS_GPIO_INTERRUPTS is now deprecated, and new boards should
- * use the "cros-ec,gpio-interrupts" bindings instead.
- * This will be removed once all boards are converted.
- *
- * Each zephyr project should define EC_CROS_GPIO_INTERRUPTS in their gpio_map.h
- * file if there are any interrupts that should be registered. The
- * corresponding handler will be declared here, which will prevent
- * needing to include headers with complex dependencies in gpio_map.h.
- *
- * EC_CROS_GPIO_INTERRUPTS is a space-separated list of GPIO_INT items.
- */
-
-#if (defined(EC_CROS_GPIO_INTERRUPTS) && \
- DT_HAS_COMPAT_STATUS_OKAY(cros_ec_gpio_interrupts))
-#error "Cannot use both EC_CROS_GPIO_INTERRUPTS and cros_ec_gpio_interrupts"
-#endif
-
-/*
- * Validate interrupt flags are valid for the Zephyr GPIO driver.
- */
-#define GPIO_INT(sig, f, cb) \
- BUILD_ASSERT(VALID_GPIO_INTERRUPT_FLAG(f), \
- STRINGIFY(sig) " is not using Zephyr interrupt flags");
-#ifdef EC_CROS_GPIO_INTERRUPTS
- EC_CROS_GPIO_INTERRUPTS
-#endif
-#undef GPIO_INT
-
-/*
- * Create unique enum values for each GPIO_INT entry, which also sets
- * the ZEPHYR_GPIO_INT_COUNT value.
- */
-#define ZEPHYR_GPIO_INT_ID(sig) INT_##sig
-#define GPIO_INT(sig, f, cb) ZEPHYR_GPIO_INT_ID(sig),
-enum zephyr_gpio_int_id {
-#ifdef EC_CROS_GPIO_INTERRUPTS
- EC_CROS_GPIO_INTERRUPTS
-#endif
- ZEPHYR_GPIO_INT_COUNT,
-};
-#undef GPIO_INT
-
-/* Create prototypes for each GPIO IRQ handler */
-#define GPIO_INT(sig, f, cb) void cb(enum gpio_signal signal);
-#ifdef EC_CROS_GPIO_INTERRUPTS
-EC_CROS_GPIO_INTERRUPTS
-#endif
-#undef GPIO_INT
-
-/*
- * The Zephyr gpio_callback data needs to be updated at runtime, so allocate
- * into uninitialized data (BSS). The constant data pulled from
- * EC_CROS_GPIO_INTERRUPTS is stored separately in the gpio_interrupts[] array.
- */
-static struct gpio_callback zephyr_gpio_callbacks[ZEPHYR_GPIO_INT_COUNT];
-
-#define ZEPHYR_GPIO_CALLBACK_TO_INDEX(cb) \
- (int)(((int)(cb) - (int)&zephyr_gpio_callbacks) / \
- sizeof(struct gpio_callback))
-
-#define GPIO_INT(sig, f, cb) \
- { \
- .signal = sig, \
- .flags = f, \
- .irq_handler = cb, \
- },
-const static struct gpio_signal_callback
- gpio_interrupts[ZEPHYR_GPIO_INT_COUNT] = {
-#ifdef EC_CROS_GPIO_INTERRUPTS
- EC_CROS_GPIO_INTERRUPTS
-#endif
-#undef GPIO_INT
- };
-
-/* The single zephyr gpio handler that routes to appropriate platform/ec cb */
-static void gpio_handler_shim(const struct device *port,
- struct gpio_callback *cb, gpio_port_pins_t pins)
-{
- int callback_index = ZEPHYR_GPIO_CALLBACK_TO_INDEX(cb);
- const struct gpio_signal_callback *const gpio =
- &gpio_interrupts[callback_index];
-
- /* Call the platform/ec gpio interrupt handler */
- gpio->irq_handler(gpio->signal);
-}
-
-/**
- * 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.
- */
-const static struct gpio_signal_callback *
-get_interrupt_from_signal(enum gpio_signal signal)
-{
- if (!gpio_is_implemented(signal))
- return NULL;
-
- 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", gpio_get_name(signal));
- return NULL;
-}
-
-/*
- * Zephyr based interrupt handling.
- */
-
-/*
* Structure containing the callback block for a GPIO interrupt,
* as well as the initial flags and the handler vector.
* Everything except the callback data is const, so potentially
@@ -279,89 +149,25 @@ static struct gpio_int_config *signal_to_interrupt(enum gpio_signal signal)
return NULL;
}
+/*
+ * Legacy API calls to enable/disable interrupts.
+ */
int gpio_enable_interrupt(enum gpio_signal signal)
{
- int rv;
- const struct gpio_signal_callback *interrupt;
-
- struct gpio_int_config *ic;
-
- ic = signal_to_interrupt(signal);
- if (ic) {
- return gpio_enable_dt_interrupt(ic);
- }
- interrupt = get_interrupt_from_signal(signal);
+ struct gpio_int_config *ic = signal_to_interrupt(signal);
- if (!interrupt)
+ if (ic == NULL)
return -1;
- /*
- * Config interrupt flags (e.g. INT_EDGE_BOTH) & enable interrupt
- * together.
- */
- rv = gpio_pin_interrupt_configure_dt(gpio_get_dt_spec(signal),
- (interrupt->flags |
- GPIO_INT_ENABLE) &
- ~GPIO_INT_DISABLE);
- if (rv < 0) {
- LOG_ERR("Failed to enable interrupt on %s (%d)",
- gpio_get_name(signal), rv);
- }
-
- return rv;
+ return gpio_enable_dt_interrupt(ic);
}
int gpio_disable_interrupt(enum gpio_signal signal)
{
- int rv;
-
- struct gpio_int_config *ic;
+ struct gpio_int_config *ic = signal_to_interrupt(signal);
- ic = signal_to_interrupt(signal);
- if (ic) {
- return gpio_disable_dt_interrupt(ic);
- }
- if (!gpio_is_implemented(signal))
+ if (ic == NULL)
return -1;
- rv = gpio_pin_interrupt_configure_dt(gpio_get_dt_spec(signal),
- GPIO_INT_DISABLE);
- if (rv < 0) {
- LOG_ERR("Failed to disable interrupt on %s (%d)",
- gpio_get_name(signal), rv);
- }
-
- return rv;
-}
-
-static int init_gpio_ints(const struct device *unused)
-{
- ARG_UNUSED(unused);
-
- /*
- * Loop through all interrupt pins and set their callback.
- */
- for (size_t i = 0; i < ARRAY_SIZE(gpio_interrupts); ++i) {
- const enum gpio_signal signal = gpio_interrupts[i].signal;
- int rv;
-
- if (signal == GPIO_UNIMPLEMENTED)
- continue;
-
- const struct gpio_dt_spec *spec = gpio_get_dt_spec(signal);
- gpio_init_callback(&zephyr_gpio_callbacks[i], gpio_handler_shim,
- BIT(spec->pin));
- rv = gpio_add_callback(spec->port, &zephyr_gpio_callbacks[i]);
-
- if (rv < 0) {
- LOG_ERR("Callback reg failed %s (%d)",
- gpio_get_name(signal), rv);
- continue;
- }
- }
- return 0;
+ return gpio_disable_dt_interrupt(ic);
}
-#if CONFIG_PLATFORM_EC_GPIO_INIT_PRIORITY <= CONFIG_KERNEL_INIT_PRIORITY_DEFAULT
-#error "GPIO interrupts must initialize after the kernel default initialization"
-#endif
-SYS_INIT(init_gpio_ints, POST_KERNEL, CONFIG_PLATFORM_EC_GPIO_INIT_PRIORITY);