Merge patch series "reenable dm_gpio tests, add support for gpio-line-names lookup"

Rasmus Villemoes <ravi@prevas.dk> says:

Hopefully third time's the charm.

I merely wanted to add support (mostly for use by the 'gpio' shell
command) for looking up a gpio via the gpio-line-names DT property. We
already have a "gpio_request_by_line_name()", but cmd/gpio.c does a
separate "lookup + request", so it felt more natural to teach the
lookup machinery this as well. That ran into
OF_CONTROL-but-not-OF_LIBFDT being a thing for SPL, so here's yet
another attempt.

Now, when trying to do my civic duty and add tests for this, I found
that test/dm/gpio.c has been defunct for a couple of years, and
reinstating it is not entirely trivial.

After a couple of rounds CI is now happy with this:
https://github.com/u-boot/u-boot/pull/828

Link: https://lore.kernel.org/r/20251104174458.3385564-1-ravi@prevas.dk
This commit is contained in:
Tom Rini 2025-11-11 14:53:47 -06:00
commit 10fec1b7a3
5 changed files with 48 additions and 7 deletions

View File

@ -823,6 +823,7 @@
#gpio-cells = <1>; #gpio-cells = <1>;
gpio-bank-name = "a"; gpio-bank-name = "a";
sandbox,gpio-count = <25>; sandbox,gpio-count = <25>;
gpio-line-names = "", "eth1-reset", "rtc-irq";
hog_input_active_low { hog_input_active_low {
gpio-hog; gpio-hog;
input; input;
@ -851,6 +852,7 @@
#gpio-cells = <5>; #gpio-cells = <5>;
gpio-bank-name = "b"; gpio-bank-name = "b";
sandbox,gpio-count = <10>; sandbox,gpio-count = <10>;
gpio-line-names = "factory-reset";
}; };
gpio_c: pinmux-gpios { gpio_c: pinmux-gpios {

View File

@ -97,6 +97,22 @@ config SPL_DM_GPIO_LOOKUP_LABEL
different gpios on different hardware versions different gpios on different hardware versions
for the same functionality in board code. for the same functionality in board code.
config DM_GPIO_LOOKUP_LINE_NAME
def_bool y
depends on OF_CONTROL && OF_LIBFDT
help
This option enables specifying a GPIO by referring to its
name as defined by the "gpio-line-names" property in the
gpio controller's devicetree node.
config SPL_DM_GPIO_LOOKUP_LINE_NAME
def_bool y
depends on SPL_OF_CONTROL && SPL_OF_LIBFDT
help
This option enables specifying a GPIO by referring to its
name as defined by the "gpio-line-names" property in the
gpio controller's devicetree node.
config ADI_GPIO config ADI_GPIO
bool "ADI GPIO driver" bool "ADI GPIO driver"
depends on DM_GPIO && ARCH_SC5XX depends on DM_GPIO && ARCH_SC5XX

View File

@ -164,7 +164,7 @@ int dm_gpio_lookup_name(const char *name, struct gpio_desc *desc)
for (uclass_first_device(UCLASS_GPIO, &dev); for (uclass_first_device(UCLASS_GPIO, &dev);
dev; dev;
uclass_next_device(&dev)) { uclass_next_device(&dev)) {
int len; int len, ret;
uc_priv = dev_get_uclass_priv(dev); uc_priv = dev_get_uclass_priv(dev);
if (numeric != -1) { if (numeric != -1) {
@ -188,6 +188,15 @@ int dm_gpio_lookup_name(const char *name, struct gpio_desc *desc)
*/ */
if (!dm_gpio_lookup_label(name, uc_priv, &offset)) if (!dm_gpio_lookup_label(name, uc_priv, &offset))
break; break;
/* Also search the "gpio-line-names" property in DT for a match. */
if (CONFIG_IS_ENABLED(DM_GPIO_LOOKUP_LINE_NAME)) {
ret = dev_read_stringlist_search(dev, "gpio-line-names", name);
if (ret >= 0) {
offset = ret;
break;
}
}
} }
if (!dev) if (!dev)

View File

@ -25,7 +25,7 @@ ifeq ($(CONFIG_ACPIGEN),y)
obj-y += acpi.o obj-y += acpi.o
obj-y += acpigen.o obj-y += acpigen.o
obj-y += acpi_dp.o obj-y += acpi_dp.o
obj-(CONFIG_DM_GPIO) += gpio.o obj-$(CONFIG_DM_GPIO) += gpio.o
obj-y += irq.o obj-y += irq.o
endif endif
obj-$(CONFIG_ADC) += adc.o obj-$(CONFIG_ADC) += adc.o

View File

@ -29,14 +29,14 @@ static int dm_test_gpio(struct unit_test_state *uts)
/* /*
* We expect to get 4 banks. One is anonymous (just numbered) and * We expect to get 4 banks. One is anonymous (just numbered) and
* comes from plat. The other are named a (20 gpios), * comes from plat. The other are named a (25 gpios),
* b (10 gpios) and c (10 gpios) and come from the device tree. See * b (10 gpios) and c (10 gpios) and come from the device tree. See
* test/dm/test.dts. * test/dm/test.dts.
*/ */
ut_assertok(gpio_lookup_name("b4", &dev, &offset, &gpio)); ut_assertok(gpio_lookup_name("b4", &dev, &offset, &gpio));
ut_asserteq_str(dev->name, "extra-gpios"); ut_asserteq_str(dev->name, "extra-gpios");
ut_asserteq(4, offset); ut_asserteq(4, offset);
ut_asserteq(CONFIG_SANDBOX_GPIO_COUNT + 20 + 4, gpio); ut_asserteq(CONFIG_SANDBOX_GPIO_COUNT + 25 + 4, gpio);
name = gpio_get_bank_info(dev, &offset_count); name = gpio_get_bank_info(dev, &offset_count);
ut_asserteq_str("b", name); ut_asserteq_str("b", name);
@ -110,7 +110,7 @@ static int dm_test_gpio(struct unit_test_state *uts)
name = gpio_get_bank_info(dev, &offset_count); name = gpio_get_bank_info(dev, &offset_count);
ut_asserteq_str("a", name); ut_asserteq_str("a", name);
ut_asserteq(20, offset_count); ut_asserteq(25, offset_count);
/* add gpio hog tests */ /* add gpio hog tests */
ut_assertok(gpio_hog_lookup_name("hog_input_active_low", &desc)); ut_assertok(gpio_hog_lookup_name("hog_input_active_low", &desc));
@ -135,7 +135,7 @@ static int dm_test_gpio(struct unit_test_state *uts)
ut_asserteq(0, dm_gpio_get_value(desc)); ut_asserteq(0, dm_gpio_get_value(desc));
/* Check if lookup for labels work */ /* Check if lookup for labels work */
ut_assertok(gpio_lookup_name("hog_input_active_low", &dev, &offset, ut_assertok(gpio_lookup_name("hog_input_active_low.gpio-hog", &dev, &offset,
&gpio)); &gpio));
ut_asserteq_str(dev->name, "base-gpios"); ut_asserteq_str(dev->name, "base-gpios");
ut_asserteq(10, offset); ut_asserteq(10, offset);
@ -143,6 +143,17 @@ static int dm_test_gpio(struct unit_test_state *uts)
ut_assert(gpio_lookup_name("hog_not_exist", &dev, &offset, ut_assert(gpio_lookup_name("hog_not_exist", &dev, &offset,
&gpio)); &gpio));
/* Check if lookup for gpio-line-names work */
ut_assertok(gpio_lookup_name("factory-reset", &dev, &offset, &gpio));
ut_asserteq_str(dev->name, "extra-gpios");
ut_asserteq(0, offset);
ut_asserteq(CONFIG_SANDBOX_GPIO_COUNT + 25 + 0, gpio);
ut_assertok(gpio_lookup_name("rtc-irq", &dev, &offset, &gpio));
ut_asserteq_str(dev->name, "base-gpios");
ut_asserteq(2, offset);
ut_asserteq(CONFIG_SANDBOX_GPIO_COUNT + 2, gpio);
return 0; return 0;
} }
DM_TEST(dm_test_gpio, UTF_SCAN_PDATA | UTF_SCAN_FDT); DM_TEST(dm_test_gpio, UTF_SCAN_PDATA | UTF_SCAN_FDT);
@ -161,7 +172,7 @@ static int dm_test_gpio_opendrain_opensource(struct unit_test_state *uts)
ut_asserteq_str("pinmux-gpios", gpio_c->name); ut_asserteq_str("pinmux-gpios", gpio_c->name);
ut_asserteq(8, gpio_request_list_by_name(dev, "test3-gpios", desc_list, ut_asserteq(8, gpio_request_list_by_name(dev, "test3-gpios", desc_list,
ARRAY_SIZE(desc_list), 0)) ARRAY_SIZE(desc_list), 0));
ut_asserteq(true, !!device_active(gpio_c)); ut_asserteq(true, !!device_active(gpio_c));
ut_asserteq_ptr(gpio_c, desc_list[0].dev); ut_asserteq_ptr(gpio_c, desc_list[0].dev);
@ -309,6 +320,8 @@ static int dm_test_gpio_copy(struct unit_test_state *uts)
DM_TEST(dm_test_gpio_copy, UTF_SCAN_PDATA | UTF_SCAN_FDT); DM_TEST(dm_test_gpio_copy, UTF_SCAN_PDATA | UTF_SCAN_FDT);
/* Test that we don't leak memory with GPIOs */ /* Test that we don't leak memory with GPIOs */
/* Disabled for now as there seems to be a leak in the test framework itself. */
#if 0
static int dm_test_gpio_leak(struct unit_test_state *uts) static int dm_test_gpio_leak(struct unit_test_state *uts)
{ {
ut_assertok(dm_test_gpio(uts)); ut_assertok(dm_test_gpio(uts));
@ -319,6 +332,7 @@ static int dm_test_gpio_leak(struct unit_test_state *uts)
return 0; return 0;
} }
DM_TEST(dm_test_gpio_leak, UTF_SCAN_PDATA | UTF_SCAN_FDT); DM_TEST(dm_test_gpio_leak, UTF_SCAN_PDATA | UTF_SCAN_FDT);
#endif
/* Test that we can find GPIOs using phandles */ /* Test that we can find GPIOs using phandles */
static int dm_test_gpio_phandles(struct unit_test_state *uts) static int dm_test_gpio_phandles(struct unit_test_state *uts)