Allow GPIOs to be set up later

At present GPIOs must be staticly defined in a table. This is efficient
but inflexible, and requires error-prone and correponding #ifdefs both
in the board's gpio.h and gpio.c files.

Create a GPIO_UNSET option for GPIOs. This allows them to be assigned
an enum value, but have the actual use under program control.

BUG=chrome-os-partner:13064
BRANCH=snow,link
TEST=manual
build and boot on snow with later changes. See the AC power GPIO does
not change when un/plugging power.

Change-Id: Iab58275923d7d6cfce62c890b5db9b6758279a4c
Signed-off-by: Simon Glass <sjg@chromium.org>
Reviewed-on: https://gerrit.chromium.org/gerrit/31302
Reviewed-by: David Hendricks <dhendrix@chromium.org>
This commit is contained in:
Simon Glass
2012-08-22 03:15:52 +01:00
committed by Gerrit
parent ecd4e1b5d6
commit 130531ab8c
4 changed files with 7 additions and 1 deletions

View File

@@ -180,6 +180,8 @@ int gpio_set_flags(enum gpio_signal signal, int flags)
{
const struct gpio_info *g = gpio_list + signal;
if (flags & GPIO_DEFAULT)
return EC_SUCCESS;
if (flags & GPIO_OUTPUT) {
/* Output */
/* Select open drain first, so that we don't glitch the signal

View File

@@ -57,6 +57,8 @@ int gpio_set_flags(enum gpio_signal signal, int flags)
const struct gpio_info *g = gpio_list + signal;
uint32_t addr, cnf, mode, mask;
if (flags & GPIO_DEFAULT)
return EC_SUCCESS;
gpio_config_info(g, &addr, &mode, &cnf);
mask = REG32(addr) & ~(cnf | mode);

View File

@@ -41,6 +41,8 @@ int gpio_pre_init(void)
uint32_t mask2 = (g->mask * g->mask) | (g->mask * g->mask * 2);
uint32_t val;
if (g->mask & GPIO_DEFAULT)
continue;
val = STM32_GPIO_PUPDR_OFF(g->port) & ~mask2;
if ((g->flags & GPIO_PULL_UP) == GPIO_PULL_UP)
/* Pull Up = 01 */

View File

@@ -25,7 +25,7 @@
#define GPIO_INT_BOTH 0x0040 /* Interrupt on both edges */
#define GPIO_INT_LOW 0x0080 /* Interrupt on low level */
#define GPIO_INT_HIGH 0x0100 /* Interrupt on high level */
#define GPIO_DEFAULT 0x0200 /* Don't set up on boot */
/* Common flag combinations */
#define GPIO_OUT_LOW GPIO_OUTPUT