From 85110d5bcbf1223f171df905ecff2af3fde56724 Mon Sep 17 00:00:00 2001 From: Shawn Nematbakhsh Date: Fri, 18 Sep 2015 10:00:51 -0700 Subject: gpio: i2c: Correctly restore pins after i2cunwedge Set pins as inputs when going to hi-Z, and restore them to default when returning to functional. BUG=chrome-os-partner:45520 TEST=`i2cunwedge` on samus, verify that i2c bus is still functional BRANCH=None Signed-off-by: Shawn Nematbakhsh Change-Id: Ie19d4e5afdee7f0b2437afdfaa8175ff77b73c78 Reviewed-on: https://chromium-review.googlesource.com/300785 Commit-Ready: Shawn N Tested-by: Shawn N Reviewed-by: Gwendal Grignou --- common/gpio.c | 39 +++++++++++++++++++-------------------- 1 file changed, 19 insertions(+), 20 deletions(-) diff --git a/common/gpio.c b/common/gpio.c index 0547f669d5..b9c687fd7c 100644 --- a/common/gpio.c +++ b/common/gpio.c @@ -72,18 +72,15 @@ void gpio_config_module(enum module_id id, int enable) if (id != af->module_id) continue; /* Pins for some other module */ - if (enable) { - 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 { - 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); - } + if (!(af->flags & GPIO_DEFAULT)) + gpio_set_flags_by_mask( + af->port, + af->mask, + enable ? af->flags : GPIO_INPUT); + gpio_set_alternate_function( + af->port, + af->mask, + enable ? af->func : -1); } } @@ -91,21 +88,23 @@ int gpio_config_pins(enum module_id id, uint32_t port, uint32_t pin_mask, int enable) { const struct gpio_alt_func *af; - int i = 0; /* Find pins and set to alternate functions */ for (af = gpio_alt_funcs; af < gpio_alt_funcs + gpio_alt_funcs_count; - af++, i++) { + af++) { if (af->module_id != id) continue; /* Pins for some other module */ if (af->port == port && (af->mask & pin_mask) == pin_mask) { - if (enable) - gpio_set_alternate_function( - af->port, pin_mask, af->func); - else - gpio_set_alternate_function( - af->port, pin_mask, -1); + if (!(af->flags & GPIO_DEFAULT)) + gpio_set_flags_by_mask( + af->port, + pin_mask, + enable ? af->flags : GPIO_INPUT); + gpio_set_alternate_function( + af->port, + pin_mask, + enable ? af->func : -1); return EC_SUCCESS; } } -- cgit v1.2.1