From addf358bac1d2bd087b77be7d4d95a2a2e5dfcaf Mon Sep 17 00:00:00 2001 From: Walter Lozano Date: Thu, 25 Jun 2020 01:10:06 -0300 Subject: core: add support for U_BOOT_DRIVER_ALIAS Currently when using OF_PLATDATA the binding between devices and drivers is done trying to match the compatible string in the node with a driver name. However, usually a single driver supports multiple compatible strings which causes that only devices which its compatible string matches a driver name get bound. To overcome this issue, this patch adds the U_BOOT_DRIVER_ALIAS macro, which generates no code at all, but allows an easy way to declare driver name aliases. Thanks to this, dtoc could be improve to look for the driver name based on its alias when it populates the U_BOOT_DEVICE entry. Signed-off-by: Walter Lozano Reviewed-by: Simon Glass --- include/dm/device.h | 7 +++++++ 1 file changed, 7 insertions(+) (limited to 'include/dm/device.h') diff --git a/include/dm/device.h b/include/dm/device.h index 975eec5d0e..2cfe10766f 100644 --- a/include/dm/device.h +++ b/include/dm/device.h @@ -282,6 +282,13 @@ struct driver { #define DM_GET_DRIVER(__name) \ ll_entry_get(struct driver, __name, driver) +/** + * Declare a macro to state a alias for a driver name. This macro will + * produce no code but its information will be parsed by tools like + * dtoc + */ +#define U_BOOT_DRIVER_ALIAS(__name, __alias) + /** * dev_get_platdata() - Get the platform data for a device * -- cgit From fed0f891c6821d475710e1f7033253ec4723ee09 Mon Sep 17 00:00:00 2001 From: Walter Lozano Date: Thu, 25 Jun 2020 01:10:11 -0300 Subject: core: extend struct driver_info to point to device Currently when creating an U_BOOT_DEVICE entry a struct driver_info is declared, which contains the data needed to instantiate the device. However, the actual device is created at runtime and there is no proper way to get the device based on its struct driver_info. This patch extends struct driver_info adding a pointer to udevice which is populated during the bind process, allowing to generate a set of functions to get the device based on its struct driver_info. Signed-off-by: Walter Lozano Reviewed-by: Simon Glass --- include/dm/device.h | 15 +++++++++++++++ 1 file changed, 15 insertions(+) (limited to 'include/dm/device.h') diff --git a/include/dm/device.h b/include/dm/device.h index 2cfe10766f..f5738a0cee 100644 --- a/include/dm/device.h +++ b/include/dm/device.h @@ -538,6 +538,21 @@ int device_find_global_by_ofnode(ofnode node, struct udevice **devp); */ int device_get_global_by_ofnode(ofnode node, struct udevice **devp); +/** + * device_get_by_driver_info() - Get a device based on driver_info + * + * Locates a device by its struct driver_info, by using its reference which + * is updated during the bind process. + * + * The device is probed to activate it ready for use. + * + * @info: Struct driver_info + * @devp: Returns pointer to device if found, otherwise this is set to NULL + * @return 0 if OK, -ve on error + */ +int device_get_by_driver_info(const struct driver_info *info, + struct udevice **devp); + /** * device_find_first_child() - Find the first child of a device * -- cgit