[U-Boot] [PATCH v2 05/10] dm: core: Export uclass_find_device_by_phandle()

Simon Glass sjg at chromium.org
Sun Nov 18 15:14:30 UTC 2018


This function may be useful to code outside of the code driver-model
implementation. Export it and add a test.

Signed-off-by: Simon Glass <sjg at chromium.org>
---

Changes in v2: None

 drivers/core/uclass.c        |  6 ++----
 include/dm/uclass-internal.h | 17 +++++++++++++++++
 test/dm/test-fdt.c           | 20 ++++++++++++++++++++
 3 files changed, 39 insertions(+), 4 deletions(-)

diff --git a/drivers/core/uclass.c b/drivers/core/uclass.c
index d9c5719a878..9766aeabd19 100644
--- a/drivers/core/uclass.c
+++ b/drivers/core/uclass.c
@@ -354,10 +354,8 @@ done:
 }
 
 #if CONFIG_IS_ENABLED(OF_CONTROL)
-static int uclass_find_device_by_phandle(enum uclass_id id,
-					 struct udevice *parent,
-					 const char *name,
-					 struct udevice **devp)
+int uclass_find_device_by_phandle(enum uclass_id id, struct udevice *parent,
+				  const char *name, struct udevice **devp)
 {
 	struct udevice *dev;
 	struct uclass *uc;
diff --git a/include/dm/uclass-internal.h b/include/dm/uclass-internal.h
index 30d5a4fb9bf..8a4839ee882 100644
--- a/include/dm/uclass-internal.h
+++ b/include/dm/uclass-internal.h
@@ -142,6 +142,23 @@ int uclass_find_device_by_of_offset(enum uclass_id id, int node,
 int uclass_find_device_by_ofnode(enum uclass_id id, ofnode node,
 				 struct udevice **devp);
 
+/**
+ * uclass_find_device_by_phandle() - Find a uclass device by phandle
+ *
+ * This searches the devices in the uclass for one with the given phandle.
+ *
+ * The device is NOT probed, it is merely returned.
+ *
+ * @id: ID to look up
+ * @parent: Parent device containing the phandle pointer
+ * @name: Name of property in the parent device node
+ * @devp: Returns pointer to device (there is only one for each node)
+ * @return 0 if OK, -ENOENT if there is no @name present in the node, other
+ *	-ve on error
+ */
+int uclass_find_device_by_phandle(enum uclass_id id, struct udevice *parent,
+				  const char *name, struct udevice **devp);
+
 /**
  * uclass_bind_device() - Associate device with a uclass
  *
diff --git a/test/dm/test-fdt.c b/test/dm/test-fdt.c
index e43acb21d5e..b70e3fa18ac 100644
--- a/test/dm/test-fdt.c
+++ b/test/dm/test-fdt.c
@@ -611,3 +611,23 @@ static int dm_test_fdt_disable_enable_by_path(struct unit_test_state *uts)
 }
 DM_TEST(dm_test_fdt_disable_enable_by_path, DM_TESTF_SCAN_PDATA |
 					    DM_TESTF_SCAN_FDT);
+
+/* Test a few uclass phandle functions */
+static int dm_test_fdt_phandle(struct unit_test_state *uts)
+{
+	struct udevice *back, *dev, *dev2;
+
+	ut_assertok(uclass_find_first_device(UCLASS_PANEL_BACKLIGHT, &back));
+	ut_asserteq(-ENOENT, uclass_find_device_by_phandle(UCLASS_REGULATOR,
+							back, "missing", &dev));
+	ut_assertok(uclass_find_device_by_phandle(UCLASS_REGULATOR, back,
+						  "power-supply", &dev));
+	ut_asserteq(0, device_active(dev));
+	ut_asserteq_str("ldo1", dev->name);
+	ut_assertok(uclass_get_device_by_phandle(UCLASS_REGULATOR, back,
+						 "power-supply", &dev2));
+	ut_asserteq_ptr(dev, dev2);
+
+	return 0;
+}
+DM_TEST(dm_test_fdt_phandle, DM_TESTF_SCAN_PDATA | DM_TESTF_SCAN_FDT);
-- 
2.19.1.1215.g8438c0b245-goog



More information about the U-Boot mailing list