On 10/3/24 10:37 PM, Marek Vasut wrote:
This driver depends on i2c emulator via DT phandle. Make sure the
dependency is probed before this driver is probed, not when it is
first used during transfer. This fixes the following i2c_emul_find()
error:
"
$ ./u-boot -Dc ""
...
i2c_emul_find() No emulators for device 'sandbox_pmic'
sandbox_pmic_write() write error to device: 0000000018c568d0 register: 0x0!
out_set_value() PMIC write failed: -5
i2c_emul_find() No emulators for device 'sandbox_pmic'
sandbox_pmic_write() write error to device: 0000000018c568d0 register: 0x0!
out_set_value() PMIC write failed: -5
...
"
Signed-off-by: Marek Vasut <[email protected]>
---
Cc: Heiko Schocher <[email protected]>
Cc: Simon Glass <[email protected]>
Cc: Tom Rini <[email protected]>
Cc: [email protected]
---
drivers/i2c/sandbox_i2c.c | 9 +++++++++
1 file changed, 9 insertions(+)
diff --git a/drivers/i2c/sandbox_i2c.c b/drivers/i2c/sandbox_i2c.c
index 74bb5e93397..9a39ac14fb4 100644
--- a/drivers/i2c/sandbox_i2c.c
+++ b/drivers/i2c/sandbox_i2c.c
@@ -80,6 +80,14 @@ static int sandbox_i2c_xfer(struct udevice *bus, struct
i2c_msg *msg,
return ops->xfer(emul, msg, nmsgs);
}
+static int sandbox_i2c_probe(struct udevice *dev)
+{
+ struct udevice *emul;
+
+ return uclass_get_device_by_phandle(UCLASS_I2C_EMUL, dev,
+ "sandbox,emul", &emul);
+}
Hmmm, no, this does not do it, but it does show what the issue is --
sandbox_i2c_xfer is misused to defer access to this emulator until the
first I2C transfer, so the emulator can hopefully probe in the meantime.
This is fragile and now it broke. What I am not quite sure about is why
this uclass_get_device_by_phandle() returns -2 here instead of probing
the emulator ?