aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPatrice Chotard <patrice.chotard@foss.st.com>2022-08-30 14:09:14 +0200
committerTom Rini <trini@konsulko.com>2022-09-15 09:55:30 -0400
commitf6f681642f0d730887bfe944b029cb6f76a35fb6 (patch)
tree0c2b7993902b2a1ade43b7dce4bcb00b12d8fd02
parent2c38f7c31806c5724a2f9c58a47cf76979fd6f0a (diff)
downloadu-boot-f6f681642f0d730887bfe944b029cb6f76a35fb6.zip
u-boot-f6f681642f0d730887bfe944b029cb6f76a35fb6.tar.gz
u-boot-f6f681642f0d730887bfe944b029cb6f76a35fb6.tar.bz2
gpio: sandbox: Add GPIOD_IS_AF for gpio configured in alternate function
This allows to test if a pin's label if displayed using gpio_get_status() when this pin is configured in alternate function. Signed-off-by: Patrice Chotard <patrice.chotard@foss.st.com> Reviewed-by: Simon Glass <sjg@chromium.org> Reviewed-by: Patrick Delaunay <patrick.delaunay@foss.st.com>
-rw-r--r--drivers/gpio/sandbox.c5
-rw-r--r--include/asm-generic/gpio.h1
-rw-r--r--include/dt-bindings/gpio/sandbox-gpio.h3
-rw-r--r--test/dm/gpio.c30
4 files changed, 39 insertions, 0 deletions
diff --git a/drivers/gpio/sandbox.c b/drivers/gpio/sandbox.c
index 106b2a7..305f9a6 100644
--- a/drivers/gpio/sandbox.c
+++ b/drivers/gpio/sandbox.c
@@ -196,6 +196,8 @@ static int sb_gpio_get_function(struct udevice *dev, unsigned offset)
return GPIOF_OUTPUT;
if (get_gpio_flag(dev, offset, GPIOD_IS_IN))
return GPIOF_INPUT;
+ if (get_gpio_flag(dev, offset, GPIOD_IS_AF))
+ return GPIOF_FUNC;
return GPIOF_INPUT; /*GPIO is not configurated */
}
@@ -219,6 +221,9 @@ static int sb_gpio_xlate(struct udevice *dev, struct gpio_desc *desc,
if (args->args[1] & GPIO_OUT_ACTIVE)
desc->flags |= GPIOD_IS_OUT_ACTIVE;
+ if (args->args[1] & GPIO_AF)
+ desc->flags |= GPIOD_IS_AF;
+
return 0;
}
diff --git a/include/asm-generic/gpio.h b/include/asm-generic/gpio.h
index 81f63f0..0fcf709 100644
--- a/include/asm-generic/gpio.h
+++ b/include/asm-generic/gpio.h
@@ -127,6 +127,7 @@ struct gpio_desc {
#define GPIOD_OPEN_SOURCE BIT(6) /* GPIO is open source type */
#define GPIOD_PULL_UP BIT(7) /* GPIO has pull-up enabled */
#define GPIOD_PULL_DOWN BIT(8) /* GPIO has pull-down enabled */
+#define GPIOD_IS_AF BIT(9) /* GPIO is an alternate function */
/* Flags for updating the above */
#define GPIOD_MASK_DIR (GPIOD_IS_OUT | GPIOD_IS_IN | \
diff --git a/include/dt-bindings/gpio/sandbox-gpio.h b/include/dt-bindings/gpio/sandbox-gpio.h
index e4bfdb3..05f9836 100644
--- a/include/dt-bindings/gpio/sandbox-gpio.h
+++ b/include/dt-bindings/gpio/sandbox-gpio.h
@@ -21,4 +21,7 @@
/* Bit 18 express GPIO output is active */
#define GPIO_OUT_ACTIVE 0x40000
+/* Bit 19 express GPIO set as alternate function */
+#define GPIO_AF 0x80000
+
#endif
diff --git a/test/dm/gpio.c b/test/dm/gpio.c
index 33ae987..a8c35d4 100644
--- a/test/dm/gpio.c
+++ b/test/dm/gpio.c
@@ -778,3 +778,33 @@ static int dm_test_gpio_get_values_as_int_base3(struct unit_test_state *uts)
}
DM_TEST(dm_test_gpio_get_values_as_int_base3,
UT_TESTF_SCAN_PDATA | UT_TESTF_SCAN_FDT);
+
+/* Check that gpio_get_status return the label of a GPIO configured as GPIOD_AF */
+static int dm_test_gpio_function(struct unit_test_state *uts)
+{
+ struct gpio_desc desc;
+ struct udevice *dev;
+ ulong flags;
+ unsigned int offset, gpio;
+ char buf[80];
+
+ ut_assertok(uclass_get_device(UCLASS_TEST_FDT, 0, &dev));
+ ut_asserteq_str("a-test", dev->name);
+
+ /* request gpio_b 5 */
+ ut_assertok(gpio_request_by_name(dev, "test-gpios", 2, &desc, 0));
+ /* update gpio_b 5 function to GPIO_AF */
+ ut_assertok(dm_gpio_clrset_flags(&desc, GPIOD_IS_AF, GPIOD_IS_AF));
+ ut_assertok(dm_gpio_get_flags(&desc, &flags));
+ ut_asserteq(GPIOD_IS_AF, flags);
+ /* check using gpio_get_status that label is displayed for a pin with GPIO_AF function */
+ ut_assertok(gpio_lookup_name("b5", &dev, &offset, &gpio));
+ ut_assertok(gpio_get_status(dev, offset, buf, sizeof(buf)));
+ ut_asserteq_str("b5: func a-test.test-gpios2", buf);
+
+ ut_assertok(dm_gpio_free(dev, &desc));
+
+ return 0;
+}
+DM_TEST(dm_test_gpio_function,
+ UT_TESTF_SCAN_PDATA | UT_TESTF_SCAN_FDT);