From 130531ab8ca916de4934315264353bfbfcda7871 Mon Sep 17 00:00:00 2001 From: Simon Glass Date: Wed, 22 Aug 2012 03:15:52 +0100 Subject: [PATCH] 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 Reviewed-on: https://gerrit.chromium.org/gerrit/31302 Reviewed-by: David Hendricks --- chip/lm4/gpio.c | 2 ++ chip/stm32/gpio-stm32f100.c | 2 ++ chip/stm32/gpio-stm32l15x.c | 2 ++ include/gpio.h | 2 +- 4 files changed, 7 insertions(+), 1 deletion(-) diff --git a/chip/lm4/gpio.c b/chip/lm4/gpio.c index 665b261483..f5eca38a79 100644 --- a/chip/lm4/gpio.c +++ b/chip/lm4/gpio.c @@ -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 diff --git a/chip/stm32/gpio-stm32f100.c b/chip/stm32/gpio-stm32f100.c index 8c071394e4..0cc79a0856 100644 --- a/chip/stm32/gpio-stm32f100.c +++ b/chip/stm32/gpio-stm32f100.c @@ -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); diff --git a/chip/stm32/gpio-stm32l15x.c b/chip/stm32/gpio-stm32l15x.c index f5513dafb8..cb5f17a1d4 100644 --- a/chip/stm32/gpio-stm32l15x.c +++ b/chip/stm32/gpio-stm32l15x.c @@ -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 */ diff --git a/include/gpio.h b/include/gpio.h index e03acfb0c9..0007e07cfa 100644 --- a/include/gpio.h +++ b/include/gpio.h @@ -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