mirror of
https://github.com/Telecominfraproject/OpenCellular.git
synced 2025-12-27 18:25:05 +00:00
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
This commit is contained in:
@@ -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) &
|
||||
|
||||
@@ -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.
|
||||
*
|
||||
|
||||
Reference in New Issue
Block a user