From 3b390264a415ce121a8c6f8db9fa9c42c647aaec Mon Sep 17 00:00:00 2001 From: Vijay Hiremath Date: Fri, 25 Oct 2019 03:38:30 -0700 Subject: Cleanup: Correct GPIO alternate function parameter Added code to correct the GPIO alternate function parameter at Chipset level. Optionally board level functions can cleanup the code in additional change lists. BUG=b:139427854 BRANCH=none TEST=make buildall -j Change-Id: I1171ca36a703291070fc89f972f84414adcf04fc Signed-off-by: Vijay Hiremath Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/1880974 Reviewed-by: Keith Short --- chip/nrf51/gpio.c | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) (limited to 'chip/nrf51') diff --git a/chip/nrf51/gpio.c b/chip/nrf51/gpio.c index 48c9f39895..53694b5a74 100644 --- a/chip/nrf51/gpio.c +++ b/chip/nrf51/gpio.c @@ -53,7 +53,8 @@ volatile uint32_t * const nrf51_alt_funcs[] = { const unsigned int nrf51_alt_func_count = ARRAY_SIZE(nrf51_alt_funcs); /* Make sure the function table and defines stay in sync */ -BUILD_ASSERT(NRF51_MAX_ALT_FUNCS == ARRAY_SIZE(nrf51_alt_funcs)); +BUILD_ASSERT(ARRAY_SIZE(nrf51_alt_funcs) == NRF51_MAX_ALT_FUNCS && + NRF51_MAX_ALT_FUNCS <= GPIO_ALT_FUNC_MAX); void gpio_set_flags_by_mask(uint32_t port, uint32_t mask, uint32_t flags) { @@ -160,16 +161,18 @@ void gpio_pre_init(void) * NRF51 doesn't have an alternate function table. * Use the pin select registers in place of the function number. */ -void gpio_set_alternate_function(uint32_t port, uint32_t mask, int func) +void gpio_set_alternate_function(uint32_t port, uint32_t mask, + enum gpio_alternate_func func) { uint32_t bit = GPIO_MASK_TO_NUM(mask); ASSERT((~mask & BIT(bit)) == 0); /* Only one bit set. */ ASSERT(port == GPIO_0); - ASSERT((func >= 0 && func < nrf51_alt_func_count) || func == -1); + ASSERT((func >= GPIO_ALT_FUNC_DEFAULT && func < nrf51_alt_func_count) || + func == GPIO_ALT_FUNC_NONE); /* Remove the previous setting(s) */ - if (func == -1) { + if (func == GPIO_ALT_FUNC_NONE) { int i; for (i = 0; i < nrf51_alt_func_count; i++) { if (*(nrf51_alt_funcs[i]) == bit) -- cgit v1.2.1