[PATCH v2 1/3] drivers: gpio-uclass: support PMIC GPIO children

Svyatoslav Ryhel clamor95 at gmail.com
Mon Nov 6 10:00:44 CET 2023


UCLASS_PMIC may have GPIO children without exposed fdt node,
in this case if requesting fails, check if uclass is PMIC.
If so, iterate through its children to find correct device.

Signed-off-by: Svyatoslav Ryhel <clamor95 at gmail.com>
---
 drivers/gpio/gpio-uclass.c | 19 +++++++++++++++++++
 1 file changed, 19 insertions(+)

diff --git a/drivers/gpio/gpio-uclass.c b/drivers/gpio/gpio-uclass.c
index 7aece85a70..6ef7cb4b78 100644
--- a/drivers/gpio/gpio-uclass.c
+++ b/drivers/gpio/gpio-uclass.c
@@ -1143,9 +1143,28 @@ static int gpio_request_tail(int ret, const char *nodename,
 		ret = uclass_get_device_by_ofnode(UCLASS_GPIO, args->node,
 						  &desc->dev);
 		if (ret) {
+#if CONFIG_IS_ENABLED(DM_PMIC)
+			struct udevice *pmic;
+			ret = uclass_get_device_by_ofnode(UCLASS_PMIC, args->node,
+							  &pmic);
+			if (ret) {
+				log_err("PMIC device get failed, err %d\n", ret);
+				goto err;
+			}
+
+			device_foreach_child(desc->dev, pmic) {
+				if (device_get_uclass_id(desc->dev) == UCLASS_GPIO)
+					break;
+			}
+
+			/* if loop exits without GPIO device return error */
+			if (device_get_uclass_id(desc->dev) != UCLASS_GPIO)
+				goto err;
+#else
 			debug("%s: uclass_get_device_by_ofnode failed\n",
 			      __func__);
 			goto err;
+#endif
 		}
 	}
 	ret = gpio_find_and_xlate(desc, args);
-- 
2.40.1



More information about the U-Boot mailing list