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>
This commit is contained in:
parent
abaed70990
commit
728d04cc72
3 changed files with 43 additions and 2 deletions
|
@ -31,14 +31,27 @@ struct udevice *i2c_emul_get_device(struct udevice *emul)
|
||||||
return uc_plat->dev;
|
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)
|
int i2c_emul_find(struct udevice *dev, struct udevice **emulp)
|
||||||
{
|
{
|
||||||
struct i2c_emul_uc_plat *uc_plat;
|
struct i2c_emul_uc_plat *uc_plat;
|
||||||
struct udevice *emul;
|
struct udevice *emul;
|
||||||
int ret;
|
int ret;
|
||||||
|
|
||||||
ret = uclass_find_device_by_phandle(UCLASS_I2C_EMUL, dev,
|
if (!CONFIG_IS_ENABLED(OF_PLATDATA)) {
|
||||||
"sandbox,emul", &emul);
|
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) {
|
if (ret) {
|
||||||
log_err("No emulators for device '%s'\n", dev->name);
|
log_err("No emulators for device '%s'\n", dev->name);
|
||||||
return ret;
|
return ret;
|
||||||
|
|
|
@ -79,6 +79,18 @@ struct acpi_ops sandbox_rtc_acpi_ops = {
|
||||||
};
|
};
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
static int sandbox_rtc_bind(struct udevice *dev)
|
||||||
|
{
|
||||||
|
#if CONFIG_IS_ENABLED(PLATDATA)
|
||||||
|
struct sandbox_i2c_rtc_plat_data *plat = dev_get_plat(dev);
|
||||||
|
|
||||||
|
/* Set up the emul_idx for i2c_emul_find() */
|
||||||
|
i2c_emul_set_idx(dev, plat->dtplat.sandbox_emul->idx);
|
||||||
|
#endif
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
static const struct rtc_ops sandbox_rtc_ops = {
|
static const struct rtc_ops sandbox_rtc_ops = {
|
||||||
.get = sandbox_rtc_get,
|
.get = sandbox_rtc_get,
|
||||||
.set = sandbox_rtc_set,
|
.set = sandbox_rtc_set,
|
||||||
|
@ -97,5 +109,6 @@ U_BOOT_DRIVER(sandbox_rtc) = {
|
||||||
.id = UCLASS_RTC,
|
.id = UCLASS_RTC,
|
||||||
.of_match = sandbox_rtc_ids,
|
.of_match = sandbox_rtc_ids,
|
||||||
.ops = &sandbox_rtc_ops,
|
.ops = &sandbox_rtc_ops,
|
||||||
|
.bind = sandbox_rtc_bind,
|
||||||
ACPI_OPS_PTR(&sandbox_rtc_acpi_ops)
|
ACPI_OPS_PTR(&sandbox_rtc_acpi_ops)
|
||||||
};
|
};
|
||||||
|
|
|
@ -93,6 +93,8 @@ struct udevice;
|
||||||
* datasheet explains it's usage of this addressing
|
* datasheet explains it's usage of this addressing
|
||||||
* mode.
|
* mode.
|
||||||
* @emul: Emulator for this chip address (only used for emulation)
|
* @emul: Emulator for this chip address (only used for emulation)
|
||||||
|
* @emul_idx: Emulator index, used for of-platdata and set by each i2c chip's
|
||||||
|
* bind() method. This allows i2c_emul_find() to work with of-platdata.
|
||||||
*/
|
*/
|
||||||
struct dm_i2c_chip {
|
struct dm_i2c_chip {
|
||||||
uint chip_addr;
|
uint chip_addr;
|
||||||
|
@ -102,6 +104,7 @@ struct dm_i2c_chip {
|
||||||
#ifdef CONFIG_SANDBOX
|
#ifdef CONFIG_SANDBOX
|
||||||
struct udevice *emul;
|
struct udevice *emul;
|
||||||
bool test_mode;
|
bool test_mode;
|
||||||
|
int emul_idx;
|
||||||
#endif
|
#endif
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -554,6 +557,18 @@ void i2c_dump_msgs(struct i2c_msg *msg, int nmsgs);
|
||||||
*/
|
*/
|
||||||
int i2c_emul_find(struct udevice *dev, struct udevice **emulp);
|
int i2c_emul_find(struct udevice *dev, struct udevice **emulp);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* i2c_emul_set_idx() - Set the emulator index for an i2c sandbox device
|
||||||
|
*
|
||||||
|
* With of-platdata we cannot find the emulator using the device tree, so rely
|
||||||
|
* on the bind() method of each i2c driver calling this function to tell us
|
||||||
|
* the of-platdata idx of the emulator
|
||||||
|
*
|
||||||
|
* @dev: i2c device to set the emulator for
|
||||||
|
* @emul_idx: of-platdata index for that emulator
|
||||||
|
*/
|
||||||
|
void i2c_emul_set_idx(struct udevice *dev, int emul_idx);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* i2c_emul_get_device() - Find the device being emulated
|
* i2c_emul_get_device() - Find the device being emulated
|
||||||
*
|
*
|
||||||
|
|
Loading…
Reference in a new issue