diff options
author | Simon Glass <sjg@chromium.org> | 2018-11-18 08:14:33 -0700 |
---|---|---|
committer | Simon Glass <sjg@chromium.org> | 2018-11-29 09:30:05 -0700 |
commit | b7c25b11b6a1e3f840464224309b72a91b65bc56 (patch) | |
tree | 5ba2f88e1ad0cb5b19e65f78e2aed409a01e77e0 /include/i2c.h | |
parent | 25cbb47090d83a5c4a4abb20a2474c0e51d21933 (diff) | |
download | u-boot-b7c25b11b6a1e3f840464224309b72a91b65bc56.tar.gz |
dm: sandbox: i2c: Add a new 'emulation parent' uclass
Sandbox i2c works using emulation drivers which are currently children of
the i2c device:
rtc_0: rtc@43 {
reg = <0x43>;
compatible = "sandbox-rtc";
emul {
compatible = "sandbox,i2c-rtc";
};
};
In this case the emulation device is attached to i2c bus on address 0x43
and provides the Real-Time-Clock (RTC) functionality.
However this is not ideal, since every device on an I2C bus has a child
device. This is only really the case for sandbox, but we want to avoid
special-case code for sandbox.
A better approach seems to be to add a separate node on the bus, an
'emulation parent'. This can be given a bogus address (such as 0xff) and
hides all the emulators away. Then we can use a phandle to point from the
device to the correct emualtor, and only on sandbox. The code to find an
emulator does not interfere with normal i2c operation.
Add a new UCLASS_I2C_EMUL_PARENT uclass which allows finding an emulator
given a bus, and finding a bus given an emulator. This will be used in a
follow-on patch.
Signed-off-by: Simon Glass <sjg@chromium.org>
Diffstat (limited to 'include/i2c.h')
-rw-r--r-- | include/i2c.h | 21 |
1 files changed, 21 insertions, 0 deletions
diff --git a/include/i2c.h b/include/i2c.h index d33f827500..ccffc19552 100644 --- a/include/i2c.h +++ b/include/i2c.h @@ -536,6 +536,27 @@ int i2c_chip_ofdata_to_platdata(struct udevice *dev, struct dm_i2c_chip *chip); */ void i2c_dump_msgs(struct i2c_msg *msg, int nmsgs); +/** + * i2c_emul_find() - Find an emulator for an i2c sandbox device + * + * This looks at the device's 'emul' phandle + * + * @dev: Device to find an emulator for + * @emulp: Returns the associated emulator, if found * + * @return 0 if OK, -ENOENT or -ENODEV if not found + */ +int i2c_emul_find(struct udevice *dev, struct udevice **emulp); + +/** + * i2c_emul_get_device() - Find the device being emulated + * + * Given an emulator this returns the associated device + * + * @emul: Emulator for the device + * @return device that @emul is emulating + */ +struct udevice *i2c_emul_get_device(struct udevice *emul); + #ifndef CONFIG_DM_I2C /* |