diff options
author | Anton Staaf <robotboy@chromium.org> | 2016-01-13 11:32:05 -0800 |
---|---|---|
committer | chrome-bot <chrome-bot@chromium.org> | 2016-01-20 14:25:32 -0800 |
commit | 4c290b058a3393e8842de1583b29310d99c93d9a (patch) | |
tree | 070a341c8af014347489a69d41cd16345429c08f /common/gpio.c | |
parent | d5ae5bc3702946c27ec5d9a84dfa3b32bb3664d2 (diff) | |
download | chrome-ec-4c290b058a3393e8842de1583b29310d99c93d9a.tar.gz |
GPIO: Simplify configuration
Previously there were only two uses of gpio_config_pins, one was
gpio_config_module, which passed in GPIO_CONFIG_ALL_PORTS (the only
place this is used), the other was the common I2C code when it needs to
return the SDA and SCL lines to their alternate function after unwedging
the bus.
These uses are so different that it doesn't make much sense to keep a
single API for them. This change adds a gpio_config_pin that is
simpler to use as it just takes a gpio_signal enum to select the GPIO
to configure and makes gpio_config_pins and GPIO_CONFIG_ALL_PORTS
internal to gpio.c
Signed-off-by: Anton Staaf <robotboy@chromium.org>
BRANCH=None
BUG=None
TEST=make buildall -j
Change-Id: I92bfb0b520b0aa2165655b2ff5076e428c88631f
Reviewed-on: https://chromium-review.googlesource.com/322437
Commit-Ready: Anton Staaf <robotboy@chromium.org>
Tested-by: Anton Staaf <robotboy@chromium.org>
Reviewed-by: Aseda Aboagye <aaboagye@chromium.org>
Diffstat (limited to 'common/gpio.c')
-rw-r--r-- | common/gpio.c | 37 |
1 files changed, 27 insertions, 10 deletions
diff --git a/common/gpio.c b/common/gpio.c index 0fd34d4a79..167207318f 100644 --- a/common/gpio.c +++ b/common/gpio.c @@ -58,17 +58,17 @@ static int last_val_changed(int i, int v) } } -/*****************************************************************************/ -/* GPIO API */ - -void gpio_config_module(enum module_id id, int enable) -{ - /* Set all the alternate functions for this module. */ - gpio_config_pins(id, GPIO_CONFIG_ALL_PORTS, 0, enable); -} +/* + * GPIO_CONFIG_ALL_PORTS signifies a "don't care" for the GPIO port. This is + * used in gpio_config_pins(). When the port parameter is set to this, the + * pin_mask parameter is ignored. + */ +#define GPIO_CONFIG_ALL_PORTS 0xFFFFFFFF -int gpio_config_pins(enum module_id id, - uint32_t port, uint32_t pin_mask, int enable) +static int gpio_config_pins(enum module_id id, + uint32_t port, + uint32_t pin_mask, + int enable) { const struct gpio_alt_func *af; int rv = EC_ERROR_INVAL; @@ -107,6 +107,23 @@ int gpio_config_pins(enum module_id id, return rv; } +/*****************************************************************************/ +/* GPIO API */ + +int gpio_config_module(enum module_id id, int enable) +{ + /* Set all the alternate functions for this module. */ + return gpio_config_pins(id, GPIO_CONFIG_ALL_PORTS, 0, enable); +} + +int gpio_config_pin(enum module_id id, enum gpio_signal signal, int enable) +{ + return gpio_config_pins(id, + gpio_list[signal].port, + gpio_list[signal].mask, + enable); +} + void gpio_set_flags(enum gpio_signal signal, int flags) { const struct gpio_info *g = gpio_list + signal; |