summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorKeith Short <keithshort@chromium.org>2022-03-15 13:45:33 -0600
committerCommit Bot <commit-bot@chromium.org>2022-03-16 00:49:00 +0000
commit8840c71b910438ed90f5af7372bc6710d3cf07f7 (patch)
tree5c4948bfce31b604af523c9bb936c48ac7e4afe9
parentc07ccd305631fab82edf31c7dfe47884ae7f2cf0 (diff)
downloadchrome-ec-8840c71b910438ed90f5af7372bc6710d3cf07f7.tar.gz
zephyr: Directly map GPIO flags
Directly map legacy GPIO flags to the Zephyr equivalent when possible. The interrupt flags are still handled separately. BUG=b:224821728 BRANCH=none TEST=zmake testall TEST=compare_build.sh TEST=verify Herobrine boots the AP Signed-off-by: Keith Short <keithshort@chromium.org> Change-Id: I379d95036dbf5630a0a6aed708c49cfcfc084802 Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/3526271 Reviewed-by: Jack Rosenthal <jrosenth@chromium.org>
-rw-r--r--common/gpio_commands.c6
-rw-r--r--include/gpio.h57
-rw-r--r--zephyr/shim/src/gpio.c45
-rw-r--r--zephyr/test/drivers/src/gpio.c1
4 files changed, 61 insertions, 48 deletions
diff --git a/common/gpio_commands.c b/common/gpio_commands.c
index 967d051f6c..2f6293dbf6 100644
--- a/common/gpio_commands.c
+++ b/common/gpio_commands.c
@@ -87,13 +87,19 @@ const struct gpio_flag_description gpio_descriptions[] = {
{GPIO_OUTPUT, "O"},
{GPIO_LOW, "L"},
{GPIO_HIGH, "H"},
+#ifndef CONFIG_ZEPHYR
{GPIO_ANALOG, "A"},
+#endif
{GPIO_OPEN_DRAIN, "ODR"},
{GPIO_PULL_UP, "PU"},
{GPIO_PULL_DOWN, "PD"},
+#ifndef CONFIG_ZEPHYR
{GPIO_ALTERNATE, "ALT"},
+#endif
{GPIO_SEL_1P8V, "1P8"},
+#ifndef CONFIG_ZEPHYR
{GPIO_LOCKED, "LCK"}
+#endif
};
static void print_gpio_info(int gpio)
diff --git a/include/gpio.h b/include/gpio.h
index 16d0086d5e..e581021e09 100644
--- a/include/gpio.h
+++ b/include/gpio.h
@@ -53,15 +53,42 @@
#error GPIO_INT_DEBOUNCE values are not the same!
#endif
-/* Otherwise define overlapping GPIO_ flags ourselves */
-#else /* !CONFIG_ZEPHYR */
-#define GPIO_OPEN_DRAIN (BIT(1) | BIT(2)) /* Output type is open-drain */
-#define GPIO_PULL_UP BIT(4) /* Enable on-chip pullup */
-#define GPIO_PULL_DOWN BIT(5) /* Enable on-chip pulldown */
-#define GPIO_INPUT BIT(8) /* Input */
-#define GPIO_OUTPUT BIT(9) /* Output */
-#endif /* CONFIG_ZEPHYR */
+/*
+ * Map the legacy EC GPIO flags to the Zephyr equivalent.
+ * Refer to the descriptions below.
+ */
+#define GPIO_FLAG_NONE GPIO_DISCONNECTED
+/* GPIO_ANALOG not supported by Zephyr */
+/* GPIO_OPEN_DRAIN already defined by Zephyr */
+/* GPIO_DEFAULT not supported by Zephyr */
+/* GPIO_PULL_UP already defined by Zephyr */
+/* GPIO_PULL_DOWN already defined by Zephyr */
+#define GPIO_LOW GPIO_OUTPUT_INIT_LOW
+#define GPIO_HIGH GPIO_OUTPUT_INIT_HIGH
+/* GPIO_INPUT already defined by Zephyr */
+/* GPIO_OUTPUT already defined by Zephyr */
+
+/*
+ * One to one mapping of interrupt flags isn't possible. So map these
+ * flags to not conflict with any Zephyr flags.
+ */
+#define GPIO_INT_F_RISING BIT(28)
+#define GPIO_INT_F_FALLING BIT(29)
+#define GPIO_INT_F_LOW BIT(30)
+#define GPIO_INT_F_HIGH BIT(31)
+/* GPIO_INT_DSLEEP not supported by Zephyr */
+/* GPIO_INT_SHARED not supported by Zephyr */
+
+#define GPIO_SEL_1P8V GPIO_VOLTAGE_1P8
+/* GPIO_ALTERNATE not supported by Zephyr */
+/* GPIO_LOCKED not supported by Zephyr */
+/* GPIO_HIB_WAKE_HIGH not supported by Zephyr */
+/* GPIO_HIB_WAKE_LOW not supported by Zephyr */
+/* GPIO_HIB_WAKE_RISING not supported by Zephyr */
+/* GPIO_HIB_WAKE_FALLING not supported by Zephyr */
+/* GPIO_POWER_DOWN not supported by Zephyr */
+#else /* !CONFIG_ZEPHYR */
/*
* All flags supported by gpio_info expect GPIO_ANALOG
*
@@ -73,14 +100,14 @@
*/
#define GPIO_FLAG_NONE 0 /* No flag needed, default setting */
#define GPIO_ANALOG BIT(0) /* Set pin to analog-mode */
-/* GPIO_OPEN_DRAIN BIT(1) | BIT(2) Output type is open-drain */
-#define GPIO_DEFAULT BIT(3) /* Don't set up on boot */
-/* GPIO_PULL_UP BIT(4) Enable on-chip pullup */
-/* GPIO_PULL_DOWN BIT(5) Enable on-chip pulldown */
+#define GPIO_OPEN_DRAIN (BIT(1) | BIT(2)) /* Output type is open-drain */
+#define GPIO_DEFAULT BIT(3) /* Don't set up on boot */
+#define GPIO_PULL_UP BIT(4) /* Enable on-chip pullup */
+#define GPIO_PULL_DOWN BIT(5) /* Enable on-chip pulldown */
#define GPIO_LOW BIT(6) /* If GPIO_OUTPUT, set level low */
#define GPIO_HIGH BIT(7) /* If GPIO_OUTPUT, set level high */
-/* GPIO_INPUT BIT(8) Input */
-/* GPIO_OUTPUT BIT(9) Output */
+#define GPIO_INPUT BIT(8) /* Input */
+#define GPIO_OUTPUT BIT(9) /* Output */
#define GPIO_INT_F_RISING BIT(10) /* Interrupt on rising edge */
#define GPIO_INT_F_FALLING BIT(11) /* Interrupt on falling edge */
#define GPIO_INT_F_LOW BIT(12) /* Interrupt on low level */
@@ -98,6 +125,8 @@
#define GPIO_POWER_DOWN BIT(23) /* Pin and pad is powered off */
#endif
+#endif /* CONFIG_ZEPHYR */
+
/* Common flag combinations */
#define GPIO_OUT_LOW (GPIO_OUTPUT | GPIO_LOW)
#define GPIO_OUT_HIGH (GPIO_OUTPUT | GPIO_HIGH)
diff --git a/zephyr/shim/src/gpio.c b/zephyr/shim/src/gpio.c
index c068aae8bc..59d59d78f7 100644
--- a/zephyr/shim/src/gpio.c
+++ b/zephyr/shim/src/gpio.c
@@ -169,21 +169,18 @@ int gpio_or_ioex_get_level(int signal, int *value)
}
/* GPIO flags which are the same in Zephyr and this codebase */
-#define GPIO_CONVERSION_SAME_BITS \
- (GPIO_OPEN_DRAIN | GPIO_PULL_UP | GPIO_PULL_DOWN | GPIO_INPUT | \
- GPIO_OUTPUT)
-
-#define FLAGS_HANDLED_FROM_ZEPHYR \
- (GPIO_DISCONNECTED | GPIO_OPEN_DRAIN | GPIO_PULL_UP | GPIO_PULL_DOWN | \
- GPIO_OUTPUT_INIT_LOW | GPIO_OUTPUT_INIT_HIGH | GPIO_INPUT | \
- GPIO_OUTPUT | GPIO_INT_ENABLE | GPIO_INT_EDGE | GPIO_INT_HIGH_1 | \
- GPIO_INT_LOW_0 | GPIO_VOLTAGE_1P8)
-
-#define FLAGS_HANDLED_TO_ZEPHYR \
- (GPIO_FLAG_NONE | GPIO_OPEN_DRAIN | GPIO_PULL_UP | GPIO_PULL_DOWN | \
- GPIO_LOW | GPIO_HIGH | GPIO_INPUT | GPIO_OUTPUT | GPIO_INT_F_RISING | \
- GPIO_INT_F_FALLING | GPIO_INT_F_LOW | GPIO_INT_F_HIGH | \
- GPIO_SEL_1P8V)
+#define GPIO_CONVERSION_SAME_BITS \
+ (GPIO_OPEN_DRAIN | GPIO_PULL_UP | GPIO_PULL_DOWN | GPIO_VOLTAGE_1P8 | \
+ GPIO_INPUT | GPIO_OUTPUT | GPIO_OUTPUT_INIT_LOW | \
+ GPIO_OUTPUT_INIT_HIGH)
+
+#define FLAGS_HANDLED_FROM_ZEPHYR \
+ (GPIO_CONVERSION_SAME_BITS | GPIO_INT_ENABLE | GPIO_INT_EDGE | \
+ GPIO_INT_HIGH_1 | GPIO_INT_LOW_0)
+
+#define FLAGS_HANDLED_TO_ZEPHYR \
+ (GPIO_CONVERSION_SAME_BITS | GPIO_INT_F_RISING | GPIO_INT_F_FALLING | \
+ GPIO_INT_F_LOW | GPIO_INT_F_HIGH)
int convert_from_zephyr_flags(const gpio_flags_t zephyr)
{
@@ -197,13 +194,6 @@ int convert_from_zephyr_flags(const gpio_flags_t zephyr)
unhandled_flags);
}
- if (zephyr == GPIO_DISCONNECTED)
- ec_flags = GPIO_FLAG_NONE;
- if (zephyr & GPIO_OUTPUT_INIT_LOW)
- ec_flags |= GPIO_LOW;
- if (zephyr & GPIO_OUTPUT_INIT_HIGH)
- ec_flags |= GPIO_HIGH;
-
if (zephyr & GPIO_INT_ENABLE) {
if (zephyr & GPIO_INT_EDGE) {
if (zephyr & GPIO_INT_HIGH_1)
@@ -218,9 +208,6 @@ int convert_from_zephyr_flags(const gpio_flags_t zephyr)
}
}
- if (zephyr & GPIO_VOLTAGE_1P8)
- ec_flags |= GPIO_SEL_1P8V;
-
return ec_flags;
}
@@ -236,12 +223,6 @@ gpio_flags_t convert_to_zephyr_flags(int ec_flags)
unhandled_flags);
}
- if (ec_flags == GPIO_FLAG_NONE)
- zephyr_flags = GPIO_DISCONNECTED;
- if (ec_flags & GPIO_LOW)
- zephyr_flags |= GPIO_OUTPUT_INIT_LOW;
- if (ec_flags & GPIO_HIGH)
- zephyr_flags |= GPIO_OUTPUT_INIT_HIGH;
if (ec_flags & GPIO_INT_F_RISING)
zephyr_flags |= GPIO_INT_ENABLE
| GPIO_INT_EDGE | GPIO_INT_HIGH_1;
@@ -252,8 +233,6 @@ gpio_flags_t convert_to_zephyr_flags(int ec_flags)
zephyr_flags |= GPIO_INT_ENABLE | GPIO_INT_LOW_0;
if (ec_flags & GPIO_INT_F_HIGH)
zephyr_flags |= GPIO_INT_ENABLE | GPIO_INT_HIGH_1;
- if (ec_flags & GPIO_SEL_1P8V)
- zephyr_flags |= GPIO_VOLTAGE_1P8;
return zephyr_flags;
}
diff --git a/zephyr/test/drivers/src/gpio.c b/zephyr/test/drivers/src/gpio.c
index f0053b9560..0edb389a3e 100644
--- a/zephyr/test/drivers/src/gpio.c
+++ b/zephyr/test/drivers/src/gpio.c
@@ -94,7 +94,6 @@ ZTEST(gpio, test_convert_to_zephyr_flags)
{ GPIO_INT_F_LOW, GPIO_INT_ENABLE | GPIO_INT_LOW_0 },
{ GPIO_INT_F_HIGH, GPIO_INT_ENABLE | GPIO_INT_HIGH_1 },
{ GPIO_SEL_1P8V, GPIO_VOLTAGE_1P8 },
- { GPIO_LOCKED, 0 },
};
int num_tests = ARRAY_SIZE(validate);