summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDaisuke Nojiri <dnojiri@chromium.org>2022-06-17 21:50:49 +0000
committerChromeos LUCI <chromeos-scoped@luci-project-accounts.iam.gserviceaccount.com>2023-02-28 15:27:56 +0000
commitb04910e1964fb31cba9ef8fdfb6b8c885074cce0 (patch)
tree09beed3cb7e8ebb632e559ea121e01f2ac281df5
parent3a6067fbdee184f72cda62d48d6add90022f40ee (diff)
downloadchrome-ec-b04910e1964fb31cba9ef8fdfb6b8c885074cce0.tar.gz
gpio: Wrap gpio_get_default_flags by gpio_get_flags
Currently, gpio_get_flags returns the runtime GPIO flags while gpio_get_default_flags return the compile time flags. This patch makes gpio_get_flags call gpio_get_default_flags if CONFIG_GPIO_GET_EXTENDED isn't defined so that callers will get the runtime flags by default and fall back to the compile time flags only if runtime flags aren't available. This patch itself introduces no behavior change (since currently gpio_get_flags is defined only if CONFIG_GPIO_GET_EXTENDED is defined). Callers should individually switch to gpio_get_flags if it's calling gpio_get_default_flags by mistake. BUG=None BRANCH=None TEST=buildall Signed-off-by: Daisuke Nojiri <dnojiri@chromium.org> Change-Id: I714bf8ea135d3c91a8cefcc3a1ba577f5650200d Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/3712029 Reviewed-by: Jes Klinke <jbk@chromium.org>
-rw-r--r--common/gpio.c7
-rw-r--r--common/gpio_commands.c9
-rw-r--r--zephyr/shim/src/gpio.c5
3 files changed, 11 insertions, 10 deletions
diff --git a/common/gpio.c b/common/gpio.c
index 2e76116e4c..b69878eca3 100644
--- a/common/gpio.c
+++ b/common/gpio.c
@@ -110,14 +110,15 @@ void gpio_set_flags(enum gpio_signal signal, int flags)
gpio_set_flags_by_mask(g->port, g->mask, flags);
}
-#ifdef CONFIG_GPIO_GET_EXTENDED
int gpio_get_flags(enum gpio_signal signal)
{
const struct gpio_info *g = gpio_list + signal;
- return gpio_get_flags_by_mask(g->port, g->mask);
+ if (IS_ENABLED(CONFIG_GPIO_GET_EXTENDED))
+ return gpio_get_flags_by_mask(g->port, g->mask);
+ else
+ return gpio_get_default_flags(signal);
}
-#endif
int gpio_get_default_flags(enum gpio_signal signal)
{
diff --git a/common/gpio_commands.c b/common/gpio_commands.c
index 06e0203090..892144ce7b 100644
--- a/common/gpio_commands.c
+++ b/common/gpio_commands.c
@@ -67,13 +67,8 @@ static enum ec_error_list set(const char *name, int value)
if (!gpio_is_implemented(signal))
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;
- }
+ if (!(gpio_get_flags(signal) & GPIO_OUTPUT))
+ return EC_ERROR_INVAL;
gpio_set_level(signal, value);
diff --git a/zephyr/shim/src/gpio.c b/zephyr/shim/src/gpio.c
index 574b23ea4d..142f106e02 100644
--- a/zephyr/shim/src/gpio.c
+++ b/zephyr/shim/src/gpio.c
@@ -240,6 +240,11 @@ gpio_flags_t convert_to_zephyr_flags(int ec_flags)
return zephyr_flags;
}
+int gpio_get_flags(enum gpio_signal signal)
+{
+ return gpio_get_default_flags(signal);
+}
+
int gpio_get_default_flags(enum gpio_signal signal)
{
if (!gpio_is_implemented(signal))