From 3f00af41c41d35fec50090a48796db5c24d0a6d3 Mon Sep 17 00:00:00 2001 From: Louis Yung-Chieh Lo Date: Thu, 26 Dec 2013 11:38:01 -0800 Subject: nyan: don't touch GPIO setting while init alternate functions. Old code reset some GPIO configurations with af->flags = 0 while gpio_config_module(). This is bad because it could lead unexpected behavior on the bus. New code accepts GPIO_DEFAULT flag so that it doesn't touch the GPIO setting while configuring alternate functions. This should not effect other boards unless the GPIO_DEFAULT is set on that board. BUG=chrome-os-partner:24607 BRANCH=nyan TEST=run on nyan rev 3.12. No "SPI rx bad data" at boot. UART and i2c good. Change-Id: Id451cfae21e1d764452429dc5adfe1317ff5b140 Signed-off-by: Louis Yung-Chieh Lo Reviewed-on: https://chromium-review.googlesource.com/181135 Reviewed-by: Randall Spangler --- board/nyan/board.c | 6 +++--- common/gpio.c | 8 ++++++-- 2 files changed, 9 insertions(+), 5 deletions(-) diff --git a/board/nyan/board.c b/board/nyan/board.c index bbaa1cc261..060b9a40e1 100644 --- a/board/nyan/board.c +++ b/board/nyan/board.c @@ -91,9 +91,9 @@ BUILD_ASSERT(ARRAY_SIZE(gpio_list) == GPIO_COUNT); /* Pins with alternate functions */ const struct gpio_alt_func gpio_alt_funcs[] = { - {GPIO_A, 0x00f0, GPIO_ALT_SPI, MODULE_SPI}, - {GPIO_A, 0x0600, GPIO_ALT_USART, MODULE_UART}, - {GPIO_B, 0x00c0, GPIO_ALT_I2C, MODULE_I2C}, + {GPIO_A, 0x00f0, GPIO_ALT_SPI, MODULE_SPI, GPIO_DEFAULT}, + {GPIO_A, 0x0600, GPIO_ALT_USART, MODULE_UART, GPIO_DEFAULT}, + {GPIO_B, 0x00c0, GPIO_ALT_I2C, MODULE_I2C, GPIO_DEFAULT}, }; const int gpio_alt_funcs_count = ARRAY_SIZE(gpio_alt_funcs); diff --git a/common/gpio.c b/common/gpio.c index 43abdad0d4..13775ea449 100644 --- a/common/gpio.c +++ b/common/gpio.c @@ -73,11 +73,15 @@ void gpio_config_module(enum module_id id, int enable) continue; /* Pins for some other module */ if (enable) { - gpio_set_flags_by_mask(af->port, af->mask, af->flags); + if (!(af->flags & GPIO_DEFAULT)) + gpio_set_flags_by_mask(af->port, + af->mask, af->flags); gpio_set_alternate_function(af->port, af->mask, af->func); } else { - gpio_set_flags_by_mask(af->port, af->mask, GPIO_INPUT); + if (!(af->flags & GPIO_DEFAULT)) + gpio_set_flags_by_mask(af->port, + af->mask, GPIO_INPUT); gpio_set_alternate_function(af->port, af->mask, -1); } } -- cgit v1.2.1