All of lore.kernel.org
 help / color / mirror / Atom feed
* [RFC][PATCH] syscon: Add syscon_regmap_lookup_by_compatible wrapper
@ 2024-03-21 16:23 Marek Vasut
  0 siblings, 0 replies; only message in thread
From: Marek Vasut @ 2024-03-21 16:23 UTC (permalink / raw)
  To: u-boot; +Cc: Marek Vasut, Johan Jonker, Simon Glass, Sumit Garg, Tom Rini

Add a wrapper to look up a system controller by a compatible string.

This operates by looking up the given name in the device (device
tree property) of the device using the system controller.

Signed-off-by: Marek Vasut <marex@denx.de>
---
Cc: Johan Jonker <jbx6244@gmail.com>
Cc: Simon Glass <sjg@chromium.org>
Cc: Sumit Garg <sumit.garg@linaro.org>
Cc: Tom Rini <trini@konsulko.com>
---
 drivers/core/syscon-uclass.c | 27 +++++++++++++++++++++++++++
 include/syscon.h             | 13 +++++++++++++
 2 files changed, 40 insertions(+)

diff --git a/drivers/core/syscon-uclass.c b/drivers/core/syscon-uclass.c
index a47b8bd3c01..b89006c030d 100644
--- a/drivers/core/syscon-uclass.c
+++ b/drivers/core/syscon-uclass.c
@@ -111,6 +111,33 @@ static int syscon_probe_by_ofnode(ofnode node, struct udevice **devp)
 	return 0;
 }
 
+struct regmap *syscon_regmap_lookup_by_compatible(struct udevice *dev,
+					          const char *compatible)
+{
+	struct udevice *syscon;
+	struct regmap *r;
+	ofnode node;
+	int err;
+
+	node = ofnode_by_compatible(ofnode_null(), compatible);
+	if (!ofnode_valid(node)) {
+		dev_dbg(dev, "unable to find syscon device\n");
+		return ERR_PTR(-EINVAL);
+	}
+
+	err = syscon_probe_by_ofnode(node, &syscon);
+	if (err)
+		return ERR_PTR(-ENODEV);
+
+	r = syscon_get_regmap(syscon);
+	if (!r) {
+		dev_dbg(dev, "unable to find regmap\n");
+		return ERR_PTR(-ENODEV);
+	}
+
+	return r;
+}
+
 struct regmap *syscon_regmap_lookup_by_phandle(struct udevice *dev,
 					       const char *name)
 {
diff --git a/include/syscon.h b/include/syscon.h
index 7a5ee3fa26b..88f264d801b 100644
--- a/include/syscon.h
+++ b/include/syscon.h
@@ -60,6 +60,19 @@ int syscon_get_by_driver_data(ulong driver_data, struct udevice **devp);
  */
 struct regmap *syscon_get_regmap_by_driver_data(ulong driver_data);
 
+/**
+ * syscon_regmap_lookup_by_compatible() - Look up a controller by a compatible string
+ *
+ * This operates by looking up the given name in the device (device
+ * tree property) of the device using the system controller.
+ *
+ * @dev:	Device using the system controller
+ * @compatible:	Compatible string of the system controller
+ * Return:	A pointer to the regmap if found, ERR_PTR(-ve) on error
+ */
+struct regmap *syscon_regmap_lookup_by_compatible(struct udevice *dev,
+						  const char *compatible);
+
 /**
  * syscon_regmap_lookup_by_phandle() - Look up a controller by a phandle
  *
-- 
2.43.0


^ permalink raw reply related	[flat|nested] only message in thread

only message in thread, other threads:[~2024-03-21 16:26 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2024-03-21 16:23 [RFC][PATCH] syscon: Add syscon_regmap_lookup_by_compatible wrapper Marek Vasut

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.