summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSimon Glass <sjg@chromium.org>2012-06-24 12:00:07 -0700
committerGerrit <chrome-bot@google.com>2012-07-02 22:35:52 -0700
commitaa64550a3f01704c1a23aeab057bfb58e96100b7 (patch)
tree0e0b23d288feff36eb6fb59a850c306439f7846a
parent9a4eff992fa0efdbbe909ed0e635b7139f178948 (diff)
downloadchrome-ec-aa64550a3f01704c1a23aeab057bfb58e96100b7.tar.gz
gpio: Add fast access to GPIO level
The current gpio_get_level() is pretty slow because it looks things up each time. Add a new function to find out the register address and mask to use to check the value for a particular GPIO. Time-critical code can then use this to check a GPIO. BUG=chrome-os-partner:10146 TEST=manual: build and boot on snow; Power on the board, hold power button for 10s and see that it powers off Power control still works, thus GPIOs are functional Change-Id: Ifc6c56f5cb811e0243e7712725a51948eabd42ab Signed-off-by: Simon Glass <sjg@chromium.org> Reviewed-on: https://gerrit.chromium.org/gerrit/26175
-rw-r--r--chip/stm32/gpio-stm32f100.c7
-rw-r--r--include/gpio.h12
2 files changed, 19 insertions, 0 deletions
diff --git a/chip/stm32/gpio-stm32f100.c b/chip/stm32/gpio-stm32f100.c
index e1a28b8d7a..50c732bc27 100644
--- a/chip/stm32/gpio-stm32f100.c
+++ b/chip/stm32/gpio-stm32f100.c
@@ -174,6 +174,13 @@ void gpio_set_alternate_function(int port, int mask, int func)
}
+uint16_t *gpio_get_level_reg(enum gpio_signal signal, uint32_t *mask)
+{
+ *mask = gpio_list[signal].mask;
+ return (uint16_t *)&STM32_GPIO_IDR_OFF(gpio_list[signal].port);
+}
+
+
int gpio_get_level(enum gpio_signal signal)
{
return !!(STM32_GPIO_IDR_OFF(gpio_list[signal].port) &
diff --git a/include/gpio.h b/include/gpio.h
index b70e40f9a1..e03acfb0c9 100644
--- a/include/gpio.h
+++ b/include/gpio.h
@@ -66,6 +66,18 @@ int gpio_pre_init(void);
int gpio_get_level(enum gpio_signal signal);
/**
+ * Get faster access to a GPIO level
+ *
+ * Use this function to find out the register address and mask for a GPIO
+ * value. Then you can just check that instead of calling gpio_get_level().
+ *
+ * @param signal Signal to return details for
+ * @param mask Mask value to use
+ * @return pointer to register to read to get GPIO value
+ */
+uint16_t *gpio_get_level_reg(enum gpio_signal signal, uint32_t *mask);
+
+/**
* Returns the name of a given GPIO signal.
*
* @param signal Signal to return.