From aa64550a3f01704c1a23aeab057bfb58e96100b7 Mon Sep 17 00:00:00 2001 From: Simon Glass Date: Sun, 24 Jun 2012 12:00:07 -0700 Subject: [PATCH] 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 Reviewed-on: https://gerrit.chromium.org/gerrit/26175 --- chip/stm32/gpio-stm32f100.c | 7 +++++++ include/gpio.h | 12 ++++++++++++ 2 files changed, 19 insertions(+) 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 @@ -65,6 +65,18 @@ int gpio_pre_init(void); /* Get the current value of a signal (0=low, 1=hi). */ 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. *