diff options
author | Jett Rink <jettrink@chromium.org> | 2018-06-08 16:10:31 -0600 |
---|---|---|
committer | chrome-bot <chrome-bot@chromium.org> | 2018-06-11 17:29:48 -0700 |
commit | 7d36fb8991e7a249ae56db508078480c27914f2e (patch) | |
tree | bac641d2be2a906670a1a882040c0cece711e948 /common/gpio.c | |
parent | 7c6f336362770c85a5df02064fd274eee1ff8555 (diff) | |
download | chrome-ec-7d36fb8991e7a249ae56db508078480c27914f2e.tar.gz |
gpio: extend flags size to accommodate GPIO_ flags
Widen the flags field from 16-bit to 32-bit to fit all of the
current GPIO_flags. Also reorder fields within struct to allow arm
compiler to use 16-bit instructions instead of 32-bit instructions when
accessing fields (which is important for kevin board, otherwise
it runs out of space)
Lastly, re-tool macros to all reordering of gpio_alt_func struct fields.
BRANCH=none
BUG=b:109884927
TEST=builds on all boards
Change-Id: I20b136c94a607c19031a88bddd255cc34cc57bbd
Signed-off-by: Jett Rink <jettrink@chromium.org>
Reviewed-on: https://chromium-review.googlesource.com/1096018
Reviewed-by: Furquan Shaikh <furquan@chromium.org>
Diffstat (limited to 'common/gpio.c')
-rw-r--r-- | common/gpio.c | 51 |
1 files changed, 22 insertions, 29 deletions
diff --git a/common/gpio.c b/common/gpio.c index 0fa949dedb..60d4973d61 100644 --- a/common/gpio.c +++ b/common/gpio.c @@ -13,31 +13,32 @@ /* GPIO alternate function structure */ struct gpio_alt_func { + /* Module ID (as uint8_t, since enum would be 32-bit) */ + uint8_t module_id; + + /* Alternate function number */ + uint8_t func; + /* Port base address */ uint32_t port; /* Bitmask on that port (multiple bits allowed) */ uint32_t mask; - /* Alternate function number */ - uint8_t func; - - /* Module ID (as uint8_t, since enum would be 32-bit) */ - uint8_t module_id; - /* Flags (GPIO_*; see above). */ - uint16_t flags; + uint32_t flags; }; /* * Construct the gpio_alt_funcs array. This array is used by gpio_config_module * to enable and disable GPIO alternate functions on a module by module basis. */ -#define ALTERNATE(pinmask, function, module, flags) \ - {GPIO_##pinmask, function, module, flags}, +#define ALTERNATE(pinmask, function, module, flagz) \ + {GPIO_##pinmask, .func = (function), .module_id = (module), \ + .flags = (flagz)}, static const struct gpio_alt_func gpio_alt_funcs[] = { - #include "gpio.wrap" +#include "gpio.wrap" }; /* @@ -47,9 +48,7 @@ static const struct gpio_alt_func gpio_alt_funcs[] = { */ #define GPIO_CONFIG_ALL_PORTS 0xFFFFFFFF -static int gpio_config_pins(enum module_id id, - uint32_t port, - uint32_t pin_mask, +static int gpio_config_pins(enum module_id id, uint32_t port, uint32_t pin_mask, int enable) { const struct gpio_alt_func *af; @@ -57,10 +56,9 @@ static int gpio_config_pins(enum module_id id, /* Find pins and set to alternate functions */ for (af = gpio_alt_funcs; - af < gpio_alt_funcs + ARRAY_SIZE(gpio_alt_funcs); - af++) { + af < gpio_alt_funcs + ARRAY_SIZE(gpio_alt_funcs); af++) { if (af->module_id != id) - continue; /* Pins for some other module */ + continue; /* Pins for some other module */ /* Check to see if the requested port matches. */ if ((port != GPIO_CONFIG_ALL_PORTS) && (port != af->port)) @@ -73,13 +71,11 @@ static int gpio_config_pins(enum module_id id, if ((af->mask & pin_mask) == pin_mask) { if (!(af->flags & GPIO_DEFAULT)) gpio_set_flags_by_mask( - af->port, - (af->mask & pin_mask), + af->port, (af->mask & pin_mask), enable ? af->flags : GPIO_INPUT); - gpio_set_alternate_function( - af->port, - (af->mask & pin_mask), - enable ? af->func : -1); + gpio_set_alternate_function(af->port, + (af->mask & pin_mask), + enable ? af->func : -1); rv = EC_SUCCESS; /* We're done here if we were just setting one port. */ if (port != GPIO_CONFIG_ALL_PORTS) @@ -101,10 +97,8 @@ int gpio_config_module(enum module_id id, int 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); + return gpio_config_pins(id, gpio_list[signal].port, + gpio_list[signal].mask, enable); } void gpio_set_flags(enum gpio_signal signal, int flags) @@ -189,10 +183,9 @@ int gpio_power_down_module(enum module_id id) /* Find pins and power down */ for (af = gpio_alt_funcs; - af < gpio_alt_funcs + ARRAY_SIZE(gpio_alt_funcs); - af++) { + af < gpio_alt_funcs + ARRAY_SIZE(gpio_alt_funcs); af++) { if (af->module_id != id) - continue; /* Pins for some other module */ + continue; /* Pins for some other module */ gpio_set_flags_by_mask(af->port, af->mask, GPIO_POWER_DOWN); rv = EC_SUCCESS; |