summaryrefslogtreecommitdiff
path: root/chip/nrf51/gpio.c
diff options
context:
space:
mode:
authorAseda Aboagye <aaboagye@google.com>2015-04-08 16:42:55 -0700
committerChromeOS Commit Bot <chromeos-commit-bot@chromium.org>2015-04-10 22:08:25 +0000
commite9883124ff1600db5788e44c332a403499fb5da6 (patch)
tree5e5b64b72e89037845cc549e1c4262bf9d224a04 /chip/nrf51/gpio.c
parent0b043fed030129ea99272f1ba729307fafaa93e2 (diff)
downloadchrome-ec-e9883124ff1600db5788e44c332a403499fb5da6.tar.gz
gpio: Refactor IRQ handler pointer out of gpio_list
In the gpio_info struct, we had a irq_handler pointer defined even though a majority of the GPIOs did not have irq handlers associated. By removing the irq_handler pointer out of the struct, we can save some space with some targets saving more than others. (For example, ~260 bytes for samus_pd). This change also brings about a new define: GPIO_INT(name, port, pin, flags, signal) And the existing GPIO macro has had the signal parameter removed since they were just NULL. GPIO(name, port, pin, flags) In each of the gpio.inc files, all the GPIOs with irq handlers must be defined at the top of the file. This is because their enum values from gpio_signal are used as the index to the gpio_irq_handlers table. BUG=chromium:471331 BRANCH=none TEST=Flashed ec to samus and samus_pd, verified lightbar tap, lid, power button, keyboard, charging, all still working. TEST=Moved a GPIO_INT declaration after a GPIO declaration and watched the build fail. TEST=make -j BOARD=peppy tests TEST=make -j BOARD=auron tests TEST=make -j BOARD=link tests Change-Id: Id6e261b0a3cd63223ca92f2e96a80c95e85cdefb Signed-off-by: Aseda Aboagye <aaboagye@google.com> Reviewed-on: https://chromium-review.googlesource.com/263973 Reviewed-by: Randall Spangler <rspangler@chromium.org> Tested-by: Aseda Aboagye <aaboagye@chromium.org> Commit-Queue: Aseda Aboagye <aaboagye@chromium.org> Trybot-Ready: Aseda Aboagye <aaboagye@chromium.org> Reviewed-by: Alec Berg <alecaberg@chromium.org>
Diffstat (limited to 'chip/nrf51/gpio.c')
-rw-r--r--chip/nrf51/gpio.c15
1 files changed, 9 insertions, 6 deletions
diff --git a/chip/nrf51/gpio.c b/chip/nrf51/gpio.c
index ccb453d0c2..22a7d95fa1 100644
--- a/chip/nrf51/gpio.c
+++ b/chip/nrf51/gpio.c
@@ -193,7 +193,7 @@ int gpio_enable_interrupt(enum gpio_signal signal)
const struct gpio_info *g = gpio_list + signal;
/* Fail if not implemented or no interrupt handler */
- if (!g->mask || !g->irq_handler)
+ if (!g->mask || signal >= GPIO_IH_COUNT)
return EC_ERROR_INVAL;
/* If it's not shared, use INT0-INT3, otherwise use PORT. */
@@ -253,7 +253,7 @@ int gpio_disable_interrupt(enum gpio_signal signal)
int i;
/* Fail if not implemented or no interrupt handler */
- if (!g->mask || !g->irq_handler)
+ if (!g->mask || signal >= GPIO_IH_COUNT)
return EC_ERROR_INVAL;
/* If it's not shared, use INT0-INT3, otherwise use PORT. */
@@ -285,21 +285,24 @@ void gpio_interrupt(void)
{
const struct gpio_info *g;
int i;
+ int signal;
for (i = 0; i < NRF51_GPIOTE_IN_COUNT; i++) {
if (NRF51_GPIOTE_IN(i)) {
NRF51_GPIOTE_IN(i) = 0;
g = gpio_ints[i];
- if (g && g->irq_handler)
- g->irq_handler(g - gpio_list);
+ signal = g - gpio_list;
+ if (g && signal < GPIO_IH_COUNT)
+ gpio_irq_handlers[signal](signal);
}
}
if (NRF51_GPIOTE_PORT) {
NRF51_GPIOTE_PORT = 0;
g = gpio_int_port;
- if (g && g->irq_handler)
- g->irq_handler(g - gpio_list);
+ signal = g - gpio_list;
+ if (g && signal < GPIO_IH_COUNT)
+ gpio_irq_handlers[signal](signal);
}
}
DECLARE_IRQ(NRF51_PERID_GPIOTE, gpio_interrupt, 1);