
Hi Marek!
On 03.10.24 22:47, Marek Vasut wrote:
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 marex@denx.de
Cc: Heiko Schocher hs@denx.de Cc: Simon Glass sjg@chromium.org Cc: Tom Rini trini@konsulko.com Cc: u-boot@lists.denx.de
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 ?
Hmm... -2 means it does not find such a device ... why, I don;t know ... do you have a chance to debug?
Just a fast grep (I must admit, never looked into this parts...)) may it helps if you use
int i2c_emul_find(struct udevice *dev, struct udevice **emulp)
found in file:
./drivers/i2c/i2c-emul-uclass.c
instead?
bye, Heiko