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);
+}
+
static const struct dm_i2c_ops sandbox_i2c_ops = {
.xfer = sandbox_i2c_xfer,
};
@@ -95,4 +103,5 @@ U_BOOT_DRIVER(sandbox_i2c) = {
.of_match = sandbox_i2c_ids,
.ops = &sandbox_i2c_ops,
.priv_auto = sizeof(struct sandbox_i2c_priv),
+ .probe = sandbox_i2c_probe,
};
--
2.45.2