dm: core: Clarify uclass_first/next_device() comments
PATCH 1/3 dm: core: Clarify uclass_first/next_device() comments
These are not as clear as they could be. Tidy them up a bit. Also fix a tiny code-style nit.
Signed-off-by Simon Glass <[email protected]>
---
drivers/core/uclass.c | 3 +-- include/dm/uclass.h | 13 +++++++++++-- 2 files changed, 12 insertions(+), 4 deletions(-)
drivers/core/uclass.c +1 -2
@@ -342,8 +342,7 @@ int uclass_get_device_by_driver(enum uclass_id id,return -ENODEV ; } -int uclass_get_device_tail (struct udevice *dev,int ret, -struct udevice **devp) +int uclass_get_device_tail (struct udevice *dev,int ret,struct udevice **devp) {if (ret)return ret;
include/dm/uclass.h +11 -2
@@ -224,8 +224,13 @@ int uclass_get_device_by_driver(enum uclass_id id, const struct driver *drv,* * 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 and can be probed. +* * @id: Uclass ID to look up -* @devp: Returns pointer to the first device in that uclass, or NULL if none +* @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. * @return 0 if OK (found or not found), other -ve on error */ int uclass_first_device (enum uclass_id id,struct udevice **devp);
@@ -246,8 +251,12 @@ int uclass_first_device_err(enum uclass_id id, struct udevice **devp);* * 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 and can be probed. +* * @devp: On entry, pointer to device to lookup. On exit, returns pointer -* to the next device in the same uclass, or NULL if none +* 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. * @return 0 if OK (found or not found), other -ve on error */ int uclass_next_device (struct udevice **devp);
Signature · 1 line
2.12.2.816.g2cccc81164-goog
PATCH 2/3 dm: core: Test uclass_first/next_device() on probe failure
Add some tests which check the behaviour of uclass_first_device() and uclass_next_device() when probing of a device fails.
Signed-off-by Simon Glass <[email protected]>
---
arch/sandbox/dts/test.dts | 19 +++++++++++++ include/dm/uclass-id.h | 1 + test/dm/test-fdt.c | 72 +++++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 92 insertions(+)
arch/sandbox/dts/test.dts +19 -0
@@ -418,6 +418,25 @@ }; }; }; + + probing { + compatible = "simple-bus"; + test1 { + compatible = "denx,u-boot-probe-test"; + }; + + test2 { + compatible = "denx,u-boot-probe-test"; + }; + + test3 { + compatible = "denx,u-boot-probe-test"; + }; + + test4 { + compatible = "denx,u-boot-probe-test"; + }; + }; }; #include "sandbox_pmic.dtsi"
include/dm/uclass-id.h +1 -0
@@ -18,6 +18,7 @@ enum uclass_id {UCLASS_TEST ,UCLASS_TEST_FDT ,UCLASS_TEST_BUS , +UCLASS_TEST_PROBE ,UCLASS_SPI_EMUL ,/* sandbox SPI device emulator */ UCLASS_I2C_EMUL ,/* sandbox I2C device emulator */ UCLASS_PCI_EMUL, /* sandbox PCI device emulator */
test/dm/test-fdt.c +72 -0
87 lines not on this page · raw message
Signature · 1 line
2.12.2.816.g2cccc81164-goog
PATCH 3/3 dm: core: Add uclass_first/next_ok_device()
In reply to Simon GlassSometimes it is useful to iterate through all devices in a uclass and skip over those which do not work correctly (e.g fail to probe). Add two new functions to provide this feature.
Signed-off-by Simon Glass <[email protected]>
---
drivers/core/uclass.c | 29 +++++++++++++++++++++++++++++ include/dm/uclass.h | 31 +++++++++++++++++++++++++++++++ test/dm/test-fdt.c | 45 +++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 105 insertions(+)
drivers/core/uclass.c +29 -0
@@ -456,6 +456,35 @@ int uclass_next_device(struct udevice **devp)return uclass_get_device_tail (dev, ret, devp); } +struct udevice *uclass_first_ok_device (enum uclass_id id) +{ +struct udevice *dev; +int ret; + + ret =uclass_find_first_device (id, &dev); +if (!dev) +return NULL ; + ret =device_probe (dev); +if (ret) +return uclass_next_ok_device (dev); + +return dev; +} + +struct udevice *uclass_next_ok_device (struct udevice *dev) +{ +int ret; + +do { + ret =uclass_find_next_device (&dev); +if (!dev) +return NULL ; + ret =device_probe (dev); + }while (ret); + +return dev; +} +int uclass_bind_device (struct udevice *dev) {struct uclass *uc;
include/dm/uclass.h +31 -0
@@ -262,6 +262,37 @@ int uclass_first_device_err(enum uclass_id id, struct udevice **devp);int uclass_next_device (struct udevice **devp);/** +* uclass_first_ok_device() - Get the first functioning device in a uclass +* +* The device returned is probed if necessary, and ready for use. Any devices +* which fail to probe are skipped. It is not possible to discover the error +* for any devices which fail to probe. You should use uclass_first_device() +* if you care about that. +* +* @id: Uclass ID to look up +* @return: pointer to the first functioning device in that uclass if one +* can be found, or NULL if there is no such device (e.g. if the rest of the +* devices cannot be probed). +*/ +struct udevice *uclass_first_ok_device (enum uclass_id id); + +/** +* uclass_next_ok_device() - Get the next functioning device in a uclass +* +* The device returned is probed if necessary, and ready for use. Any devices +* which fail to probe are skipped. It is not possible to discover the error +* for any devices which fail to probe. You should use uclass_next_device() +* if you care about that. +* +* @dev: Pointer to the previous device (e.g. returned from +* uclass_first_ok_device() or uclass_next_ok_device() +* @return: pointer to the next functioning device in the same uclass if one +* can be found, or NULL if there is no such device (e.g. if the rest of the +* devices cannot be probed). +*/ +struct udevice *uclass_next_ok_device (struct udevice *dev); + +/** * uclass_resolve_seq() - Resolve a device's sequence number * * On entry dev->seq is -1, and dev->req_seq may be -1 (to allocate a
test/dm/test-fdt.c +45 -0
48 lines not on this page · raw message
Signature · 1 line
2.12.2.816.g2cccc81164-goog