dm: core: add function uclass_probe_all() to probe all devices

Support a common method to probe all devices associated with uclass.

This includes data structures and code for finding the first device and
looping for remaining devices associated with uclasses (groups of devices
with the same purpose, e.g. all SERIAL ports will be in the same uclass).

An example is SBSA compliant PL011 UART IP, where firmware does the serial
port initialization and prepare uart device to let the kernel use it for
sending and reveiving the characters.SERIAL uclass will use this function
to initialize PL011 UART ports.

The feature is enabled with CONFIG_DM.

Signed-off-by: Vabhav Sharma <vabhav.sharma@nxp.com>
Reviewed-by: Stefan Roese <sr@denx.de>
Reviewed-by: Simon Glass <sjg@chromium.org>
Reviewed-by: Sean Anderson <seanga2@gmail.com>
This commit is contained in:
Vabhav Sharma 2020-12-09 10:42:03 +05:30 committed by Tom Rini
parent 449efce69a
commit a59153dfeb
2 changed files with 30 additions and 0 deletions

View file

@ -757,6 +757,25 @@ int uclass_pre_remove_device(struct udevice *dev)
}
#endif
int uclass_probe_all(enum uclass_id id)
{
struct udevice *dev;
int ret;
ret = uclass_first_device(id, &dev);
if (ret || !dev)
return ret;
/* Scanning uclass to probe all devices */
while (dev) {
ret = uclass_next_device(&dev);
if (ret)
return ret;
}
return 0;
}
UCLASS_DRIVER(nop) = {
.id = UCLASS_NOP,
.name = "nop",

View file

@ -376,6 +376,17 @@ int uclass_next_device_check(struct udevice **devp);
int uclass_first_device_drvdata(enum uclass_id id, ulong driver_data,
struct udevice **devp);
/**
* uclass_probe_all() - Probe all devices based on an uclass ID
*
* This function probes all devices associated with a uclass by
* looking for its ID.
*
* @id: uclass ID to look up
* @return 0 if OK, other -ve on error
*/
int uclass_probe_all(enum uclass_id id);
/**
* uclass_id_foreach_dev() - Helper function to iteration through devices
*