diff options
author | Simon Glass <sjg@chromium.org> | 2021-03-15 17:25:30 +1300 |
---|---|---|
committer | Simon Glass <sjg@chromium.org> | 2021-03-26 17:03:08 +1300 |
commit | 728d04cc72855e23f6a9116e68911dcac5be4693 (patch) | |
tree | e363c8a2c362a9d144fe80c75fafc0a731f0de96 /drivers/i2c | |
parent | abaed70990bd8eb2c9992a16465f8a9daa4c5f61 (diff) | |
download | u-boot-728d04cc72855e23f6a9116e68911dcac5be4693.zip u-boot-728d04cc72855e23f6a9116e68911dcac5be4693.tar.gz u-boot-728d04cc72855e23f6a9116e68911dcac5be4693.tar.bz2 |
sandbox: i2c: Support i2c emulation with of-platdata
At present the i2c emulators require access to the devicetree, which is
not possible (by design) with of-platdata.
Add a way for drivers to record the of-platdata index of their emulator,
so that we can still find the emulator.
This allows i2c emulation to work with of-platdata.
Signed-off-by: Simon Glass <sjg@chromium.org>
Signed-off-by: Simon Glass <sjg@chromium.org>
Diffstat (limited to 'drivers/i2c')
-rw-r--r-- | drivers/i2c/i2c-emul-uclass.c | 17 |
1 files changed, 15 insertions, 2 deletions
diff --git a/drivers/i2c/i2c-emul-uclass.c b/drivers/i2c/i2c-emul-uclass.c index 9ef4651..7917b63 100644 --- a/drivers/i2c/i2c-emul-uclass.c +++ b/drivers/i2c/i2c-emul-uclass.c @@ -31,14 +31,27 @@ struct udevice *i2c_emul_get_device(struct udevice *emul) return uc_plat->dev; } +void i2c_emul_set_idx(struct udevice *dev, int emul_idx) +{ + struct dm_i2c_chip *plat = dev_get_parent_plat(dev); + + plat->emul_idx = emul_idx; +} + int i2c_emul_find(struct udevice *dev, struct udevice **emulp) { struct i2c_emul_uc_plat *uc_plat; struct udevice *emul; int ret; - ret = uclass_find_device_by_phandle(UCLASS_I2C_EMUL, dev, - "sandbox,emul", &emul); + if (!CONFIG_IS_ENABLED(OF_PLATDATA)) { + ret = uclass_find_device_by_phandle(UCLASS_I2C_EMUL, dev, + "sandbox,emul", &emul); + } else { + struct dm_i2c_chip *plat = dev_get_parent_plat(dev); + + ret = device_get_by_ofplat_idx(plat->emul_idx, &emul); + } if (ret) { log_err("No emulators for device '%s'\n", dev->name); return ret; |