From a4e494dabda23e842a6861506af43c265a0bf7b5 Mon Sep 17 00:00:00 2001 From: Patryk Duda Date: Thu, 15 Jul 2021 19:18:53 +0000 Subject: common/gpio: Set GPIO flags after setting alternate function On STM32, gpio_set_alternate_function() called with GPIO_ALT_FUNC_NONE argument causes the pin to be set to input. In gpio_reset() function, we are setting flags first and then we are changing pin function to GPIO. As a result, using gpio_reset() on STM32 boards causes pin to be configured as input, regardles of gpio.inc file. To fix this, we should always change pin functionality to GPIO before setting GPIO flags and/or state. This approach seems to be natural also. BUG=b:170432597 BRANCH=none TEST=Flash EC on some STM32 based board (eg. dartmonkey). Use gpio_reset() function on some GPIO pin which is configured as GPIO_OUT_LOW/GPIO_OUT_HIGH in gpio.inc file (eg. FP_RST_ODL on dartmonkey). Use `gpioset` and `gpioget` command to change state of the GPIO pin, and verify it works. Signed-off-by: Patryk Duda Change-Id: I0a6c2ee8d1c1cf33b14bd54bb432c63b820427be Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/3033241 Reviewed-by: Aseda Aboagye --- common/gpio.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'common') diff --git a/common/gpio.c b/common/gpio.c index 42a9d2a2e6..9fa8512e27 100644 --- a/common/gpio.c +++ b/common/gpio.c @@ -127,8 +127,8 @@ void gpio_reset(enum gpio_signal signal) { const struct gpio_info *g = gpio_list + signal; - gpio_set_flags_by_mask(g->port, g->mask, g->flags); gpio_set_alternate_function(g->port, g->mask, GPIO_ALT_FUNC_NONE); + gpio_set_flags_by_mask(g->port, g->mask, g->flags); } const char *gpio_get_name(enum gpio_signal signal) -- cgit v1.2.1