gpio status -a does not have labels: the existing path walks
the per-bank requested label table.
Issue: The boards that populate the standard gpio-line-names
property in their device tree end up with anonymous entries,
which is not logic with the purpose of having those names in the DT.

No impact with boards that does not set gpio-line-names.

Signed-off-by: Vincent Jardin <[email protected]>

---

 drivers/gpio/gpio-uclass.c | 13 ++++++++++++-
 1 file changed, 12 insertions(+), 1 deletion(-)

diff --git a/drivers/gpio/gpio-uclass.c b/drivers/gpio/gpio-uclass.c
index 7651d5360d6..4d40738e5aa 100644
--- a/drivers/gpio/gpio-uclass.c
+++ b/drivers/gpio/gpio-uclass.c
@@ -877,8 +877,19 @@ static int get_function(struct udevice *dev, int offset, 
bool skip_unused,
                return -ENODEV;
        if (offset < 0 || offset >= uc_priv->gpio_count)
                return -EINVAL;
-       if (namep)
+       if (namep) {
                *namep = uc_priv->name[offset];
+               /* Fall back to DT "gpio-line-names" for unrequested pins. */
+               if (CONFIG_IS_ENABLED(DM_GPIO_LOOKUP_LINE_NAME) &&
+                   (!*namep || !**namep)) {
+                       const char *dt_name = NULL;
+
+                       if (!dev_read_string_index(dev, "gpio-line-names",
+                                                  offset, &dt_name) &&
+                           dt_name && *dt_name)
+                               *namep = dt_name;
+               }
+       }
        if (skip_unused && !gpio_is_claimed(uc_priv, offset))
                return GPIOF_UNUSED;
        if (ops->get_function) {
-- 
2.43.0

base-commit: bfe90a308a94caa9d855440683521ff04122ae2a
branch: for-upstream/gpio-show-line-names

Reply via email to