summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAndrew McRae <amcrae@google.com>2022-01-13 14:44:29 +1100
committerCommit Bot <commit-bot@chromium.org>2022-01-19 05:13:04 +0000
commit9e0ecceff7aec7283677682d78d34044c12a0e7a (patch)
treebba718695a6eef9457bef3c51d02d12b293fa031
parent845462f05455ccb400f358d5510772b854130bf0 (diff)
downloadchrome-ec-9e0ecceff7aec7283677682d78d34044c12a0e7a.tar.gz
zephyr: Instantiate all GPIOs in gpio_config list
Instantiate all GPIOs in the common gpio_config list. For GPIOs with no enum-name property, create an internal enum name from the ordinal. Test by checking that all GPIOs are seen via gpioget BUG=b:214316663 TEST=zmake configure -b nivviks; flash and run BRANCH=none Signed-off-by: Andrew McRae <amcrae@google.com> Change-Id: If6193e25123d6e3cc85c89a2349e4fd384d27080 Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/3384979 Reviewed-by: Keith Short <keithshort@chromium.org>
-rw-r--r--zephyr/include/drivers/cros_system.h4
-rw-r--r--zephyr/shim/include/zephyr_gpio_signal.h33
-rw-r--r--zephyr/shim/src/gpio.c20
3 files changed, 40 insertions, 17 deletions
diff --git a/zephyr/include/drivers/cros_system.h b/zephyr/include/drivers/cros_system.h
index b0e06f1b59..0d2f2f69b2 100644
--- a/zephyr/include/drivers/cros_system.h
+++ b/zephyr/include/drivers/cros_system.h
@@ -72,9 +72,7 @@ enum system_reset_cause {
* @return GPIO enumeration
*/
#define SYSTEM_DT_WAKEUP_GPIO_ENUM_BY_IDX(i, _) \
- COND_CODE_1(DT_NODE_HAS_PROP(SYSTEM_DT_NODE_WAKEUP_PIN_BY_IDX(i), \
- enum_name), \
- (GPIO_SIGNAL(SYSTEM_DT_NODE_WAKEUP_PIN_BY_IDX(i)), ), ())
+ GPIO_SIGNAL(SYSTEM_DT_NODE_WAKEUP_PIN_BY_IDX(i)),
/**
* @typedef cros_system_get_reset_cause_api
diff --git a/zephyr/shim/include/zephyr_gpio_signal.h b/zephyr/shim/include/zephyr_gpio_signal.h
index e3a3752723..5376bec3ed 100644
--- a/zephyr/shim/include/zephyr_gpio_signal.h
+++ b/zephyr/shim/include/zephyr_gpio_signal.h
@@ -11,9 +11,37 @@
#include <devicetree.h>
#include <toolchain.h>
-#define GPIO_SIGNAL(id) DT_STRING_UPPER_TOKEN(id, enum_name)
+/** @brief Returns the enum-name property as a token
+ *
+ * Returns the enum-name property for this node as an upper case token
+ * suitable for use as a GPIO signal name.
+ * The enum-name property must exist, so this macro should only
+ * be called conditionally upon checking the property exists.
+ */
+#define GPIO_SIGNAL_NAME_FROM_ENUM(id) DT_STRING_UPPER_TOKEN(id, enum_name)
+
+/** @brief Creates a GPIO signal name using the DTS ordinal number
+ *
+ * Create a GPIO signal name for a GPIO that does not contain
+ * the enum-name property. The DTS ordinal number is used
+ * to generate a unique name for this GPIO.
+ */
+#define GPIO_SIGNAL_NAME_FROM_ORD(ord) DT_CAT(GPIO_ORD_, ord)
+
+/** @brief Generate a GPIO signal name for this id
+ *
+ * Depending on whether the enum-name property exists, create
+ * a GPIO signal name from either the enum-name or a
+ * unique name generated using the DTS ordinal.
+ */
+#define GPIO_SIGNAL_NAME(id) \
+ COND_CODE_1(DT_NODE_HAS_PROP(id, enum_name), \
+ (GPIO_SIGNAL_NAME_FROM_ENUM(id)), \
+ (GPIO_SIGNAL_NAME_FROM_ORD(id ## _ORD)))
+
+#define GPIO_SIGNAL(id) GPIO_SIGNAL_NAME(id)
#define GPIO_SIGNAL_WITH_COMMA(id) \
- COND_CODE_1(DT_NODE_HAS_PROP(id, enum_name), (GPIO_SIGNAL(id), ), ())
+ GPIO_SIGNAL(id),
enum gpio_signal {
GPIO_UNIMPLEMENTED = -1,
#if DT_NODE_EXISTS(DT_PATH(named_gpios))
@@ -23,6 +51,7 @@ enum gpio_signal {
GPIO_LIMIT = 0x0FFF,
};
#undef GPIO_SIGNAL_WITH_COMMA
+
BUILD_ASSERT(GPIO_COUNT < GPIO_LIMIT);
/** @brief Converts a node identifier under named gpios to enum
diff --git a/zephyr/shim/src/gpio.c b/zephyr/shim/src/gpio.c
index 8ebff4cdf3..506e51b3d5 100644
--- a/zephyr/shim/src/gpio.c
+++ b/zephyr/shim/src/gpio.c
@@ -32,18 +32,14 @@ struct gpio_config {
bool no_auto_init;
};
-#define GPIO_CONFIG(id) \
- COND_CODE_1( \
- DT_NODE_HAS_PROP(id, enum_name), \
- ( \
- { \
- .name = DT_NODE_FULL_NAME(id), \
- .dev = DEVICE_DT_GET(DT_PHANDLE(id, gpios)), \
- .pin = DT_GPIO_PIN(id, gpios), \
- .init_flags = DT_GPIO_FLAGS(id, gpios), \
- .no_auto_init = DT_PROP(id, no_auto_init), \
- }, ), \
- ())
+#define GPIO_CONFIG(id) \
+ { \
+ .name = DT_NODE_FULL_NAME(id), \
+ .dev = DEVICE_DT_GET(DT_PHANDLE(id, gpios)), \
+ .pin = DT_GPIO_PIN(id, gpios), \
+ .init_flags = DT_GPIO_FLAGS(id, gpios), \
+ .no_auto_init = DT_PROP(id, no_auto_init), \
+ },
static const struct gpio_config configs[] = {
#if DT_NODE_EXISTS(DT_PATH(named_gpios))
DT_FOREACH_CHILD(DT_PATH(named_gpios), GPIO_CONFIG)