summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorShawn Nematbakhsh <shawnn@chromium.org>2015-09-18 10:00:51 -0700
committerchrome-bot <chrome-bot@chromium.org>2015-09-21 11:23:28 -0700
commit85110d5bcbf1223f171df905ecff2af3fde56724 (patch)
treea78e6aff47a9bb593268d8f05745da146f2b66a6
parent735e5a6ee2df4f04420b739b3ef05e6d1a81792a (diff)
downloadchrome-ec-85110d5bcbf1223f171df905ecff2af3fde56724.tar.gz
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 <shawnn@chromium.org> Change-Id: Ie19d4e5afdee7f0b2437afdfaa8175ff77b73c78 Reviewed-on: https://chromium-review.googlesource.com/300785 Commit-Ready: Shawn N <shawnn@chromium.org> Tested-by: Shawn N <shawnn@chromium.org> Reviewed-by: Gwendal Grignou <gwendal@chromium.org>
-rw-r--r--common/gpio.c39
1 files 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;
}
}