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>
This commit is contained in:
Shawn Nematbakhsh
2015-09-18 10:00:51 -07:00
committed by chrome-bot
parent 735e5a6ee2
commit 85110d5bcb

View File

@@ -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;
}
}