gpio: search gpio-line-names property in dm_gpio_lookup_name
PATCH v2 1/1 gpio: search gpio-line-names property in dm_gpio_lookup_name
In scripts as well as interactively, it's much nicer to be able to refer to GPIOs via their names defined in the device tree property "gpio-line-names", instead of the rather opaque names derived from the bank name with a _xx suffix. E.g.
gpio read factory_reset FACTORY_RESET
if test $factory_reset = 1 ; then ...
versus
gpio read factory_reset gpio@481ac000_16
if test $factory_reset = 1 ; then ...
This is also consistent with the move on the linux/userspace side towards using line names instead of legacy chip+offset or the even more legacy global gpio numbering in sysfs.
As this seems to only add about ~50 bytes of code to U-Boot proper, and dm_gpio_lookup_name() most often ends up being GC'ed for SPL, so adds no overhead there, adding yet another config knob (or two, if it also needed an SPL variant) for this does not seem warranted.
---
v2: guard the the dev_read_stringlist_search() call by CONFIG_IS_ENABLED(OF_CONTROL) to avoid link failure on !OF_CONTROL platforms.
drivers/gpio/gpio-uclass.c | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-)
drivers/gpio/gpio-uclass.c +10 -1
@@ -164,7 +164,7 @@ int dm_gpio_lookup_name(const char *name, struct gpio_desc *desc)for (uclass_first_device (UCLASS_GPIO , &dev); dev;uclass_next_device (&dev)) { -int len; +int len, ret; uc_priv =dev_get_uclass_priv (dev);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))break ; + +/* Also search the "gpio-line-names" property in DT for a match. */ +if (CONFIG_IS_ENABLED (OF_CONTROL )) { + ret =dev_read_stringlist_search (dev,"gpio-line-names" , name); +if (ret >=0 ) { + offset = ret; +break ; + } + } }if (!dev)
Signature · 1 line
2.51.0
Quoted 22 lines · Rasmus Villemoes
In scripts as well as interactively, it's much nicer to be able to refer to GPIOs via their names defined in the device tree property "gpio-line-names", instead of the rather opaque names derived from the bank name with a
_xxsuffix. E.g.gpio read
factory_resetFACTORY_RESET
if test $factory_reset = 1 ; then ...versus
gpio read
factory_resetgpio@481ac000_16
if test $factory_reset = 1 ; then ...This is also consistent with the move on the linux/userspace side towards using line names instead of legacy chip+offset or the even more legacy global gpio numbering in sysfs.
As this seems to only add about ~50 bytes of code to U-Boot proper, and
dm_gpio_lookup_name()most often ends up being GC'ed for SPL, so adds no overhead there, adding yet another config knob (or two, if it also needed an SPL variant) for this does not seem warranted.
Quoted 6 lines
Signed-off-by Rasmus Villemoes <[email protected]>---
v2: guard the the
dev_read_stringlist_search()call byCONFIG_IS_ENABLED(OF_CONTROL)to avoid link failure on !OF_CONTROL platforms.
Frustratingly this is still a failure to build for imx28_btt3 and imx28_xea, in SPL.
Signature · 1 line
Tom