diff options
author | Aseda Aboagye <aaboagye@google.com> | 2015-09-25 13:22:32 -0700 |
---|---|---|
committer | chrome-bot <chrome-bot@chromium.org> | 2015-09-26 01:07:39 -0700 |
commit | 747056ec93b7d55a117be812a5d77452b0851086 (patch) | |
tree | e8bbe84cbf4b35a0c496067b890c2f7fe0435c88 /common | |
parent | c121a3287c2917cf2abed497bd22371fabea6474 (diff) | |
download | chrome-ec-747056ec93b7d55a117be812a5d77452b0851086.tar.gz |
gpio: Merge config_module into config_pins.
gpio_config_module() and gpio_config_pins() had very similar code. This
commit moves the functionality of gpio_config_module into
gpio_config_pins. That is, gpio_config_pins() can now configure an
entire module. This is accomplished by passing in GPIO_CONFIG_ALL_PORTS
as the port parameter.
BUG=chromium:533539
BRANCH=None
TEST=Build and flash on samus. Verify that lightbar, charging, power
button, sensors, all functional.
TEST=make -j buildall tests
Change-Id: I7c9122ebf7b0e2716af2d55b842c4806d8099a63
Signed-off-by: Aseda Aboagye <aaboagye@google.com>
Reviewed-on: https://chromium-review.googlesource.com/302479
Commit-Ready: Aseda Aboagye <aaboagye@chromium.org>
Tested-by: Aseda Aboagye <aaboagye@chromium.org>
Reviewed-by: Gwendal Grignou <gwendal@chromium.org>
Reviewed-by: Shawn N <shawnn@chromium.org>
Diffstat (limited to 'common')
-rw-r--r-- | common/gpio.c | 46 |
1 files changed, 21 insertions, 25 deletions
diff --git a/common/gpio.c b/common/gpio.c index b9c687fd7c..44b77c337e 100644 --- a/common/gpio.c +++ b/common/gpio.c @@ -63,31 +63,15 @@ static int last_val_changed(int i, int v) void gpio_config_module(enum module_id id, int enable) { - const struct gpio_alt_func *af = gpio_alt_funcs; - int count = gpio_alt_funcs_count; - int i; - - /* Set module's pins to alternate functions */ - for (i = 0; i < count; i++, af++) { - if (id != af->module_id) - continue; /* Pins for some other module */ - - 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); - } + /* Set all the alternate functions for this module. */ + gpio_config_pins(id, GPIO_CONFIG_ALL_PORTS, 0, enable); } int gpio_config_pins(enum module_id id, - uint32_t port, uint32_t pin_mask, int enable) + uint32_t port, uint32_t pin_mask, int enable) { const struct gpio_alt_func *af; + int rv = EC_ERROR_INVAL; /* Find pins and set to alternate functions */ for (af = gpio_alt_funcs; af < gpio_alt_funcs + gpio_alt_funcs_count; @@ -95,20 +79,32 @@ int gpio_config_pins(enum module_id id, if (af->module_id != id) continue; /* Pins for some other module */ - if (af->port == port && (af->mask & pin_mask) == pin_mask) { + /* Check to see if the requested port matches. */ + if ((port != GPIO_CONFIG_ALL_PORTS) && (port != af->port)) + continue; + + /* If we don't care which port, enable all applicable pins. */ + if (port == GPIO_CONFIG_ALL_PORTS) + pin_mask = af->mask; + + if ((af->mask & pin_mask) == pin_mask) { if (!(af->flags & GPIO_DEFAULT)) gpio_set_flags_by_mask( af->port, - pin_mask, + (af->mask & pin_mask), enable ? af->flags : GPIO_INPUT); gpio_set_alternate_function( af->port, - pin_mask, + (af->mask & pin_mask), enable ? af->func : -1); - return EC_SUCCESS; + rv = EC_SUCCESS; + /* We're done here if we were just setting one port. */ + if (port != GPIO_CONFIG_ALL_PORTS) + break; } } - return EC_ERROR_INVAL; + + return rv; } void gpio_set_flags(enum gpio_signal signal, int flags) |