All of lore.kernel.org
 help / color / mirror / Atom feed
* [U-Boot] [PATCH 1/8] core: Add uclass_{first,next}_device_compat
@ 2018-03-28 12:38 Mario Six
  2018-03-28 12:38 ` [U-Boot] [PATCH 2/8] test: Add tests for uclass_{first, next}_device_compat Mario Six
                   ` (7 more replies)
  0 siblings, 8 replies; 22+ messages in thread
From: Mario Six @ 2018-03-28 12:38 UTC (permalink / raw)
  To: u-boot

A lot of times one wants to cycle through the devices in a uclass, but
only certain ones, especially ones identified by their compatibility
string, and ignore all others (in the best case this procedure should
not even activate the devices one is not interested in).

Hence, we add a pair of functions similar to uclass_{first,next}_device,
but taking a compatibility string as an additional argument, which cycle
through the devices of a uclass that conform to this compatibility
string.

Signed-off-by: Mario Six <mario.six@gdsys.cc>
---
 drivers/core/uclass.c | 33 +++++++++++++++++++++++++++++++++
 include/dm/uclass.h   | 37 +++++++++++++++++++++++++++++++++++++
 2 files changed, 70 insertions(+)

diff --git a/drivers/core/uclass.c b/drivers/core/uclass.c
index 1aedaa08f0..19cec1e929 100644
--- a/drivers/core/uclass.c
+++ b/drivers/core/uclass.c
@@ -469,6 +469,23 @@ int uclass_get_device_by_phandle(enum uclass_id id, struct udevice *parent,
 }
 #endif
 
+int uclass_first_device_compat(enum uclass_id id, struct udevice **devp,
+			       const char *compat)
+{
+	struct udevice *dev;
+	int ret;
+
+	*devp = NULL;
+	ret = uclass_find_first_device(id, &dev);
+	if (!dev)
+		return 0;
+	if (!device_is_compatible(dev, compat)) {
+		*devp = dev;
+		return uclass_next_device_compat(devp, compat);
+	}
+	return uclass_get_device_tail(dev, ret, devp);
+}
+
 int uclass_first_device(enum uclass_id id, struct udevice **devp)
 {
 	struct udevice *dev;
@@ -494,6 +511,22 @@ int uclass_first_device_err(enum uclass_id id, struct udevice **devp)
 	return 0;
 }
 
+int uclass_next_device_compat(struct udevice **devp, const char *compat)
+{
+	struct udevice *dev = *devp;
+	int ret;
+
+	*devp = NULL;
+	ret = uclass_find_next_device(&dev);
+	if (!dev)
+		return 0;
+	if (!device_is_compatible(dev, compat)) {
+		*devp = dev;
+		return uclass_next_device_compat(devp, compat);
+	}
+	return uclass_get_device_tail(dev, ret, devp);
+}
+
 int uclass_next_device(struct udevice **devp)
 {
 	struct udevice *dev = *devp;
diff --git a/include/dm/uclass.h b/include/dm/uclass.h
index 3a01abc239..0320f1fbee 100644
--- a/include/dm/uclass.h
+++ b/include/dm/uclass.h
@@ -260,6 +260,25 @@ int uclass_get_device_by_driver(enum uclass_id id, const struct driver *drv,
  */
 int uclass_first_device(enum uclass_id id, struct udevice **devp);
 
+/**
+ * uclass_first_device_compat() - Get the first device in a uclass compatible
+ *				  to a given compat string
+ *
+ * The device returned is probed if necessary, and ready for use.
+ *
+ * This function is useful to start iterating through a list of devices which
+ * are functioning correctly, can be probed, and are compatible with a certain
+ * compat string.
+ *
+ * @id: Uclass ID to look up
+ * @devp: Returns pointer to the first device in that uclass if no error
+ * occurred, or NULL if there is no first device, or an error occurred with
+ * that device.
+ * @compat: The compatible string the device has to adhere to
+ * @return 0 if OK (found or not found), other -ve on error
+ */
+int uclass_first_device_compat(enum uclass_id id, struct udevice **devp, const char *compat);
+
 /**
  * uclass_first_device_err() - Get the first device in a uclass
  *
@@ -286,6 +305,24 @@ int uclass_first_device_err(enum uclass_id id, struct udevice **devp);
  */
 int uclass_next_device(struct udevice **devp);
 
+/**
+ * uclass_next_device_compat() - Get the next device in a uclass compatible to
+ *				 a given compat string
+ *
+ * The device returned is probed if necessary, and ready for use
+ *
+ * This function is useful to start iterating through a list of devices which
+ * are functioning correctly, can be probed, and are compatible with a certain
+ * compat string.
+ *
+ * @devp: On entry, pointer to device to lookup. On exit, returns pointer
+ * to the next device in the uclass if no error occurred, or NULL if there is
+ * no next device, or an error occurred with that next device.
+ * @compat: The compatible string the device has to adhere to
+ * @return 0 if OK (found or not found), other -ve on error
+ */
+int uclass_next_device_compat(struct udevice **devp, const char *compat);
+
 /**
  * uclass_first_device() - Get the first device in a uclass
  *
-- 
2.16.1

^ permalink raw reply related	[flat|nested] 22+ messages in thread

end of thread, other threads:[~2018-04-27 12:16 UTC | newest]

Thread overview: 22+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2018-03-28 12:38 [U-Boot] [PATCH 1/8] core: Add uclass_{first,next}_device_compat Mario Six
2018-03-28 12:38 ` [U-Boot] [PATCH 2/8] test: Add tests for uclass_{first, next}_device_compat Mario Six
2018-03-28 12:38 ` [U-Boot] [PATCH 3/8] ram: Add driver for MPC83xx Mario Six
2018-03-28 12:38 ` [U-Boot] [PATCH 4/8] clk: Add MPC83xx clock driver Mario Six
2018-03-28 12:38 ` [U-Boot] [PATCH 5/8] timer: Add MPC83xx timer driver Mario Six
2018-03-28 12:38 ` [U-Boot] [PATCH 6/8] cpu: Add cpu_print_info function Mario Six
2018-03-30  8:41   ` Simon Glass
2018-04-11  6:39     ` Mario Six
2018-04-12 16:37       ` Simon Glass
2018-04-18  8:35         ` Mario Six
2018-04-18 15:45           ` Simon Glass
2018-04-19  7:50             ` Mario Six
2018-04-24 21:53               ` Simon Glass
2018-04-26  6:07                 ` Mario Six
2018-04-26 14:40                   ` Simon Glass
2018-04-27 12:16                     ` Mario Six
2018-03-28 12:38 ` [U-Boot] [PATCH 7/8] cpu: Add MPC83xx CPU driver Mario Six
2018-03-28 12:38 ` [U-Boot] [PATCH 8/8] misc: Add MPC83xx serdes driver Mario Six
2018-03-30  8:41 ` [U-Boot] [PATCH 1/8] core: Add uclass_{first, next}_device_compat Simon Glass
2018-04-11  7:15   ` Mario Six
2018-04-12 16:31     ` Simon Glass
2018-04-18  9:02       ` Mario Six

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.