summaryrefslogtreecommitdiff
path: root/common/gpio_commands.c
diff options
context:
space:
mode:
authorJes B. Klinke <jbk@chromium.org>2022-06-16 08:40:08 -0700
committerChromeos LUCI <chromeos-scoped@luci-project-accounts.iam.gserviceaccount.com>2022-06-21 16:09:57 +0000
commit1aeecb1765888e216b303f096066275892effc40 (patch)
tree1cc243f669318882068e0540f87d85ede0cc259d /common/gpio_commands.c
parentda4bcc79bb782234e74e3637a89c4b4c8ad50a4f (diff)
downloadchrome-ec-1aeecb1765888e216b303f096066275892effc40.tar.gz
common/gpio_commands.c: set() considers GPIO reconfiguration
The set() method allows manually setting the level of a named GPIO pin, provided that the pin is configured for output. Existing code considered only the compile-time configuration of the pin. With this change, if support has been selected, the method will inspect the current configuration of the particular GPIO pin. To be fair, the current state does not usually cause issues, since the set() method is not called by command_gpio_set() in case CONFIG_CMD_GPIO_EXTENDED is enabled, which allows reconfiguration of pins from input to output. On my board (HyperDebug) I do not want to enable CONFIG_CMD_GPIO_EXTENDED, since doing so causes e.g. "gpioset 1" to both reconfigure the pin to be output, and set its level. I want to keep "gpioset" for only setting 0/1, and I want it to reject operation on input-only pins. At the same time I have implemented a separate custom command which allows modifying the pin input/output and pullup configuration in the ways needed for the use case. Without this change, however, I am not able to use the standard "gpioset" command. BUG=b:192262089 TEST=Use HyperDebug to manipulate the RESET line of AndreiBoard BRANCH=none Signed-off-by: Jes B. Klinke <jbk@chromium.org> Change-Id: Ia66dc01fe3ca2ce4330b09431f6edc85bdeec75d Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/3706990 Reviewed-by: Daisuke Nojiri <dnojiri@chromium.org>
Diffstat (limited to 'common/gpio_commands.c')
-rw-r--r--common/gpio_commands.c9
1 files changed, 7 insertions, 2 deletions
diff --git a/common/gpio_commands.c b/common/gpio_commands.c
index b044524797..758a0ad8dc 100644
--- a/common/gpio_commands.c
+++ b/common/gpio_commands.c
@@ -67,8 +67,13 @@ static enum ec_error_list set(const char *name, int value)
if (!gpio_is_implemented(signal))
return EC_ERROR_INVAL;
- if (!(gpio_get_default_flags(signal) & GPIO_OUTPUT))
- return EC_ERROR_INVAL;
+ if (IS_ENABLED(CONFIG_GPIO_GET_EXTENDED)) {
+ if (!(gpio_get_flags(signal) & GPIO_OUTPUT))
+ return EC_ERROR_INVAL;
+ } else {
+ if (!(gpio_get_default_flags(signal) & GPIO_OUTPUT))
+ return EC_ERROR_INVAL;
+ }
gpio_set_level(signal, value);