diff options
author | Vic Yang <victoryang@chromium.org> | 2013-08-28 10:28:08 +0800 |
---|---|---|
committer | chrome-internal-fetch <chrome-internal-fetch@google.com> | 2013-09-04 05:45:52 +0000 |
commit | 2270f2bb03c2031bad455ba5f8179a9d99cc3999 (patch) | |
tree | 496418ddfebf04e0b010c9916bb7b6f0c0036d5d | |
parent | b99f91310721c50ea30fd204aa127928af37a41f (diff) | |
download | chrome-ec-2270f2bb03c2031bad455ba5f8179a9d99cc3999.tar.gz |
Fix a bug that GPIO cannot be set as input on stm32l
GPIO_INPUT is defined as 0, and any GPIO flag cannot be examined against
GPIO_INPUT. Change GPIO_INPUT to non-zero value to avoid this.
BUG=chrome-os-partner:22275
TEST=On Kirby, set a GPIO to output and pull it low, and then set it back to
input. Check it can be pull high externally.
TEST=Build all boards.
TEST=Boot link and spring.
BRANCH=None (unless this bug hits some other boards.)
Change-Id: I84b9936c24af538ac59c36129fda27ca879bf9d1
Signed-off-by: Vic Yang <victoryang@chromium.org>
Reviewed-on: https://chromium-review.googlesource.com/167190
Reviewed-by: Vincent Palatin <vpalatin@chromium.org>
-rw-r--r-- | board/daisy/board.c | 2 | ||||
-rw-r--r-- | board/link/board.c | 14 | ||||
-rw-r--r-- | chip/lm4/gpio.c | 6 | ||||
-rw-r--r-- | chip/stm32/gpio-stm32f.c | 6 | ||||
-rw-r--r-- | chip/stm32/gpio-stm32l.c | 6 | ||||
-rw-r--r-- | chip/stm32/spi.c | 2 | ||||
-rw-r--r-- | include/gpio.h | 48 |
7 files changed, 44 insertions, 40 deletions
diff --git a/board/daisy/board.c b/board/daisy/board.c index eb1769916d..c0651be2e5 100644 --- a/board/daisy/board.c +++ b/board/daisy/board.c @@ -61,7 +61,7 @@ const struct gpio_info gpio_list[] = { keyboard_raw_gpio_interrupt}, /* Other inputs */ {"AC_PWRBTN_L", GPIO_A, (1<<0), GPIO_INT_BOTH, NULL}, - {"SPI1_NSS", GPIO_A, (1<<4), GPIO_PULL_UP, NULL}, + {"SPI1_NSS", GPIO_A, (1<<4), GPIO_INPUT | GPIO_PULL_UP, NULL}, /* * I2C pins should be configured as inputs until I2C module is * initialized. This will avoid driving the lines unintentionally. diff --git a/board/link/board.c b/board/link/board.c index 618700f388..701f67e24c 100644 --- a/board/link/board.c +++ b/board/link/board.c @@ -37,13 +37,13 @@ const struct gpio_info gpio_list[] = { {"LID_OPEN", LM4_GPIO_K, (1<<5), GPIO_INT_BOTH, lid_interrupt}, /* Other inputs */ - {"THERMAL_DATA_READY_L", LM4_GPIO_B, (1<<4), 0, NULL}, + {"THERMAL_DATA_READY_L", LM4_GPIO_B, (1<<4), GPIO_INPUT, NULL}, {"AC_PRESENT", LM4_GPIO_H, (1<<3), GPIO_INT_BOTH, extpower_interrupt}, - {"BOARD_VERSION1", LM4_GPIO_H, (1<<6), 0, NULL}, - {"BOARD_VERSION2", LM4_GPIO_L, (1<<6), 0, NULL}, - {"BOARD_VERSION3", LM4_GPIO_L, (1<<7), 0, NULL}, - {"ONEWIRE", LM4_GPIO_H, (1<<2), 0, NULL}, + {"BOARD_VERSION1", LM4_GPIO_H, (1<<6), GPIO_INPUT, NULL}, + {"BOARD_VERSION2", LM4_GPIO_L, (1<<6), GPIO_INPUT, NULL}, + {"BOARD_VERSION3", LM4_GPIO_L, (1<<7), GPIO_INPUT, NULL}, + {"ONEWIRE", LM4_GPIO_H, (1<<2), GPIO_INPUT, NULL}, {"PCH_BKLTEN", LM4_GPIO_J, (1<<3), GPIO_INT_BOTH, backlight_interrupt}, {"PCH_SLP_A_L", LM4_GPIO_G, (1<<5), GPIO_INT_BOTH, @@ -78,8 +78,8 @@ const struct gpio_info gpio_list[] = { x86_interrupt}, {"RECOVERY_L", LM4_GPIO_H, (1<<7), GPIO_INT_BOTH, switch_interrupt}, - {"USB1_STATUS_L", LM4_GPIO_E, (1<<7), 0, NULL}, - {"USB2_STATUS_L", LM4_GPIO_E, (1<<1), 0, NULL}, + {"USB1_STATUS_L", LM4_GPIO_E, (1<<7), GPIO_INPUT, NULL}, + {"USB2_STATUS_L", LM4_GPIO_E, (1<<1), GPIO_INPUT, NULL}, {"WP", LM4_GPIO_J, (1<<4), GPIO_INT_BOTH, switch_interrupt}, /* Outputs; all unasserted by default except for reset signals */ diff --git a/chip/lm4/gpio.c b/chip/lm4/gpio.c index d3a060904d..25945ddc28 100644 --- a/chip/lm4/gpio.c +++ b/chip/lm4/gpio.c @@ -120,17 +120,17 @@ void gpio_set_flags_by_mask(uint32_t port, uint32_t mask, uint32_t flags) } /* Set up interrupt type */ - if (flags & GPIO_INT_LEVEL) + if (flags & (GPIO_INT_F_LOW | GPIO_INT_F_HIGH)) LM4_GPIO_IS(port) |= mask; else LM4_GPIO_IS(port) &= ~mask; - if (flags & (GPIO_INT_RISING | GPIO_INT_HIGH)) + if (flags & (GPIO_INT_F_RISING | GPIO_INT_F_HIGH)) LM4_GPIO_IEV(port) |= mask; else LM4_GPIO_IEV(port) &= ~mask; - if (flags & GPIO_INT_BOTH) + if (flags & GPIO_INT_F_BOTH) LM4_GPIO_IBE(port) |= mask; else LM4_GPIO_IBE(port) &= ~mask; diff --git a/chip/stm32/gpio-stm32f.c b/chip/stm32/gpio-stm32f.c index 0917bd5349..450169f3f8 100644 --- a/chip/stm32/gpio-stm32f.c +++ b/chip/stm32/gpio-stm32f.c @@ -103,10 +103,10 @@ void gpio_set_flags_by_mask(uint32_t port, uint32_t pmask, uint32_t flags) } /* Set up interrupts if necessary */ - ASSERT(!(flags & GPIO_INT_LEVEL)); - if (flags & (GPIO_INT_RISING | GPIO_INT_BOTH)) + ASSERT(!(flags & (GPIO_INT_F_LOW | GPIO_INT_F_HIGH))); + if (flags & (GPIO_INT_F_RISING | GPIO_INT_F_BOTH)) STM32_EXTI_RTSR |= pmask; - if (flags & (GPIO_INT_FALLING | GPIO_INT_BOTH)) + if (flags & (GPIO_INT_F_FALLING | GPIO_INT_F_BOTH)) STM32_EXTI_FTSR |= pmask; /* Interrupt is enabled by gpio_enable_interrupt() */ } diff --git a/chip/stm32/gpio-stm32l.c b/chip/stm32/gpio-stm32l.c index 22d1350362..09cc0ad4b3 100644 --- a/chip/stm32/gpio-stm32l.c +++ b/chip/stm32/gpio-stm32l.c @@ -63,10 +63,10 @@ void gpio_set_flags_by_mask(uint32_t port, uint32_t mask, uint32_t flags) } /* Set up interrupts if necessary */ - ASSERT(!(flags & GPIO_INT_LEVEL)); - if (flags & (GPIO_INT_RISING | GPIO_INT_BOTH)) + ASSERT(!(flags & (GPIO_INT_F_LOW | GPIO_INT_F_HIGH))); + if (flags & (GPIO_INT_F_RISING | GPIO_INT_F_BOTH)) STM32_EXTI_RTSR |= mask; - if (flags & (GPIO_INT_FALLING | GPIO_INT_BOTH)) + if (flags & (GPIO_INT_F_FALLING | GPIO_INT_F_BOTH)) STM32_EXTI_FTSR |= mask; /* Interrupt is enabled by gpio_enable_interrupt() */ } diff --git a/chip/stm32/spi.c b/chip/stm32/spi.c index a646f8143e..d11b696672 100644 --- a/chip/stm32/spi.c +++ b/chip/stm32/spi.c @@ -495,7 +495,7 @@ static void spi_chipset_shutdown(void) state = SPI_STATE_DISABLED; /* Disable pullup and interrupts on NSS */ - gpio_set_flags(GPIO_SPI1_NSS, 0); + gpio_set_flags(GPIO_SPI1_NSS, GPIO_INPUT); /* Set SPI pins to inputs so we don't leak power when AP is off */ gpio_config_module(MODULE_SPI, 0); diff --git a/include/gpio.h b/include/gpio.h index eee7711ee3..ce2de2b126 100644 --- a/include/gpio.h +++ b/include/gpio.h @@ -12,32 +12,36 @@ /* Flag definitions for gpio_info and gpio_alt_func */ /* The following are valid for both gpio_info and gpio_alt_func: */ -#define GPIO_OPEN_DRAIN (1 << 0) /* Output type is open-drain */ -#define GPIO_PULL_UP (1 << 1) /* Enable on-chip pullup */ -#define GPIO_PULL_DOWN (1 << 2) /* Enable on-chip pulldown */ +#define GPIO_OPEN_DRAIN (1 << 0) /* Output type is open-drain */ +#define GPIO_PULL_UP (1 << 1) /* Enable on-chip pullup */ +#define GPIO_PULL_DOWN (1 << 2) /* Enable on-chip pulldown */ /* The following are valid for gpio_alt_func only */ -#define GPIO_ANALOG (1 << 3) /* Set pin to analog-mode */ +#define GPIO_ANALOG (1 << 3) /* Set pin to analog-mode */ /* The following are valid for gpio_info only */ -#define GPIO_INPUT 0 /* Input */ -#define GPIO_OUTPUT (1 << 4) /* Output */ -#define GPIO_LOW (1 << 5) /* If GPIO_OUTPUT, set level low */ -#define GPIO_HIGH (1 << 6) /* If GPIO_OUTPUT, set level high */ -#define GPIO_INT_RISING (1 << 7) /* Interrupt on rising edge */ -#define GPIO_INT_FALLING (1 << 8) /* Interrupt on falling edge */ -#define GPIO_INT_BOTH (1 << 9) /* Interrupt on both edges */ -#define GPIO_INT_LOW (1 << 10) /* Interrupt on low level */ -#define GPIO_INT_HIGH (1 << 11) /* Interrupt on high level */ -#define GPIO_DEFAULT (1 << 12) /* Don't set up on boot */ +#define GPIO_INPUT (1 << 4) /* Input */ +#define GPIO_OUTPUT (1 << 5) /* Output */ +#define GPIO_LOW (1 << 6) /* If GPIO_OUTPUT, set level low */ +#define GPIO_HIGH (1 << 7) /* If GPIO_OUTPUT, set level high */ +#define GPIO_INT_F_RISING (1 << 8) /* Interrupt on rising edge */ +#define GPIO_INT_F_FALLING (1 << 9) /* Interrupt on falling edge */ +#define GPIO_INT_F_BOTH (1 << 10) /* Interrupt on both edges */ +#define GPIO_INT_F_LOW (1 << 11) /* Interrupt on low level */ +#define GPIO_INT_F_HIGH (1 << 12) /* Interrupt on high level */ +#define GPIO_DEFAULT (1 << 13) /* Don't set up on boot */ /* Common flag combinations */ -#define GPIO_OUT_LOW (GPIO_OUTPUT | GPIO_LOW) -#define GPIO_OUT_HIGH (GPIO_OUTPUT | GPIO_HIGH) -#define GPIO_ODR_HIGH (GPIO_OUTPUT | GPIO_OPEN_DRAIN | GPIO_HIGH) -#define GPIO_ODR_LOW (GPIO_OUTPUT | GPIO_OPEN_DRAIN | GPIO_LOW) -#define GPIO_INT_EDGE (GPIO_INT_RISING | GPIO_INT_FALLING | GPIO_INT_BOTH) -#define GPIO_INT_LEVEL (GPIO_INT_LOW | GPIO_INT_HIGH) -#define GPIO_INT_ANY (GPIO_INT_EDGE | GPIO_INT_LEVEL) -/* Note that if no flags are present, the signal is a high-Z input */ +#define GPIO_OUT_LOW (GPIO_OUTPUT | GPIO_LOW) +#define GPIO_OUT_HIGH (GPIO_OUTPUT | GPIO_HIGH) +#define GPIO_ODR_HIGH (GPIO_OUTPUT | GPIO_OPEN_DRAIN | GPIO_HIGH) +#define GPIO_ODR_LOW (GPIO_OUTPUT | GPIO_OPEN_DRAIN | GPIO_LOW) +#define GPIO_INT_RISING (GPIO_INPUT | GPIO_INT_F_RISING) +#define GPIO_INT_FALLING (GPIO_INPUT | GPIO_INT_F_FALLING) +#define GPIO_INT_BOTH (GPIO_INPUT | GPIO_INT_F_BOTH) +#define GPIO_INT_LOW (GPIO_INPUT | GPIO_INT_F_LOW) +#define GPIO_INT_HIGH (GPIO_INPUT | GPIO_INT_F_HIGH) +#define GPIO_INT_EDGE (GPIO_INT_RISING | GPIO_INT_FALLING | GPIO_INT_BOTH) +#define GPIO_INT_LEVEL (GPIO_INT_LOW | GPIO_INT_HIGH) +#define GPIO_INT_ANY (GPIO_INT_EDGE | GPIO_INT_LEVEL) /* GPIO signal definition structure, for use by board.c */ struct gpio_info { |