summaryrefslogtreecommitdiff
path: root/include/dm
diff options
context:
space:
mode:
authorSimon Glass <sjg@chromium.org>2016-07-17 21:23:15 (GMT)
committerSimon Glass <sjg@chromium.org>2016-07-26 02:46:43 (GMT)
commitc57f806bf2e745c4273dc33c9827781cff46427c (patch)
treed0df31d54e5762a985d7c19768c2dfb37f693889 /include/dm
parentc3f03ffbe31ae886f0eb670edf47fc208d667c19 (diff)
downloadu-boot-c57f806bf2e745c4273dc33c9827781cff46427c.tar.xz
dm: core: Add a way to find a device by its driver
Some SoCs have a single clock device. Provide a way to find it given its driver name. This is handled by the linker so will fail if the name is not found, avoiding strange errors when names change and do not match. It is also faster than a string comparison. Signed-off-by: Simon Glass <sjg@chromium.org>
Diffstat (limited to 'include/dm')
-rw-r--r--include/dm/device.h4
-rw-r--r--include/dm/uclass.h18
2 files changed, 22 insertions, 0 deletions
diff --git a/include/dm/device.h b/include/dm/device.h
index c825d47..705849b 100644
--- a/include/dm/device.h
+++ b/include/dm/device.h
@@ -207,6 +207,10 @@ struct driver {
#define U_BOOT_DRIVER(__name) \
ll_entry_declare(struct driver, __name, driver)
+/* Get a pointer to a given driver */
+#define DM_GET_DRIVER(__name) \
+ ll_entry_get(struct driver, __name, driver)
+
/**
* dev_get_platdata() - Get the platform data for a device
*
diff --git a/include/dm/uclass.h b/include/dm/uclass.h
index fd368b6..84f05bc 100644
--- a/include/dm/uclass.h
+++ b/include/dm/uclass.h
@@ -38,6 +38,7 @@ struct uclass {
struct list_head sibling_node;
};
+struct driver;
struct udevice;
/* Members of this uclass sequence themselves with aliases */
@@ -194,6 +195,23 @@ int uclass_get_device_by_phandle(enum uclass_id id, struct udevice *parent,
const char *name, struct udevice **devp);
/**
+ * uclass_get_device_by_driver() - Get a uclass device for a driver
+ *
+ * This searches the devices in the uclass for one that uses the given
+ * driver. Use DM_GET_DRIVER(name) for the @drv argument, where 'name' is
+ * the driver name - as used in U_BOOT_DRIVER(name).
+ *
+ * The device is probed to activate it ready for use.
+ *
+ * @id: ID to look up
+ * @drv: Driver to look for
+ * @devp: Returns pointer to the first device with that driver
+ * @return 0 if OK, -ve on error
+ */
+int uclass_get_device_by_driver(enum uclass_id id, const struct driver *drv,
+ struct udevice **devp);
+
+/**
* uclass_first_device() - Get the first device in a uclass
*
* The device returned is probed if necessary, and ready for use