diff options
author | Gerrit <chrome-bot@google.com> | 2012-04-24 10:44:39 -0700 |
---|---|---|
committer | Gerrit Code Review <gerrit@gerrit.golo.chromium.org> | 2012-04-24 10:44:39 -0700 |
commit | 3a4cd3f8f387bb8d6127f8dc00a0cb2b9e2c727c (patch) | |
tree | 78497afdbfc7f61d5af0e9e934a083087149e885 | |
parent | 507532d0811f610147cdae618117cb1666fbb56b (diff) | |
parent | 97a49113d937774aacebd2a5c92e2e15d0e39464 (diff) | |
download | chrome-ec-3a4cd3f8f387bb8d6127f8dc00a0cb2b9e2c727c.tar.gz |
Merge "stm32l: clear and then set GPIO mode and pull-up/down settings"
-rw-r--r-- | chip/stm32l/gpio.c | 16 |
1 files changed, 10 insertions, 6 deletions
diff --git a/chip/stm32l/gpio.c b/chip/stm32l/gpio.c index 0f3e7f44a5..d56efa32d4 100644 --- a/chip/stm32l/gpio.c +++ b/chip/stm32l/gpio.c @@ -29,15 +29,17 @@ int gpio_pre_init(void) */ STM32L_RCC_AHBENR |= 0x3f; - /* Set all GPIOs to defaults */ for (i = 0; i < GPIO_COUNT; i++, g++) { /* bitmask for registers with 2 bits per GPIO pin */ uint32_t mask2 = (g->mask * g->mask) | (g->mask * g->mask * 2); + uint32_t val; + val = STM32L_GPIO_PUPDR_OFF(g->port) & ~mask2; if (g->flags & GPIO_PULL_UP) /* Pull Up = 01 */ - STM32L_GPIO_PUPDR_OFF(g->port) |= 0x55555555 & mask2; + val |= 0x55555555 & mask2; else if (g->flags & GPIO_PULL_DOWN) /* Pull Down = 10 */ - STM32L_GPIO_PUPDR_OFF(g->port) |= 0xaaaaaaaa & mask2; + val |= 0xaaaaaaaa & mask2; + STM32L_GPIO_PUPDR_OFF(g->port) = val; if (g->flags & GPIO_OPEN_DRAIN) STM32L_GPIO_OTYPER_OFF(g->port) |= g->mask; @@ -47,11 +49,13 @@ int gpio_pre_init(void) * potential damage, e.g. driving an open-drain output * high before it has been configured as such. */ + val = STM32L_GPIO_MODER_OFF(g->port) & ~mask2; if (g->flags & GPIO_OUTPUT) { /* General purpose, MODE = 01 */ - STM32L_GPIO_MODER_OFF(g->port) |= 0x55555555 & mask2; + val |= 0x55555555 & mask2; + STM32L_GPIO_MODER_OFF(g->port) = val; gpio_set_level(i, g->flags & GPIO_HIGH); - } else if (g->flags & GPIO_INPUT) { - STM32L_GPIO_MODER_OFF(g->port) &= ~mask2; + } else if (g->flags & GPIO_INPUT) { /* Input, MODE=00 */ + STM32L_GPIO_MODER_OFF(g->port) = val; } /* Set up interrupts if necessary */ |