summaryrefslogtreecommitdiff
path: root/include/i2c.h
diff options
context:
space:
mode:
authorSimon Glass <sjg@chromium.org>2021-03-15 07:25:30 +0300
committerSimon Glass <sjg@chromium.org>2021-03-26 07:03:08 +0300
commit728d04cc72855e23f6a9116e68911dcac5be4693 (patch)
treee363c8a2c362a9d144fe80c75fafc0a731f0de96 /include/i2c.h
parentabaed70990bd8eb2c9992a16465f8a9daa4c5f61 (diff)
downloadu-boot-728d04cc72855e23f6a9116e68911dcac5be4693.tar.xz
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 'include/i2c.h')
-rw-r--r--include/i2c.h15
1 files changed, 15 insertions, 0 deletions
diff --git a/include/i2c.h b/include/i2c.h
index 7ae0c42706..c0fe94c1f3 100644
--- a/include/i2c.h
+++ b/include/i2c.h
@@ -93,6 +93,8 @@ struct udevice;
* datasheet explains it's usage of this addressing
* mode.
* @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 {
uint chip_addr;
@@ -102,6 +104,7 @@ struct dm_i2c_chip {
#ifdef CONFIG_SANDBOX
struct udevice *emul;
bool test_mode;
+ int emul_idx;
#endif
};
@@ -555,6 +558,18 @@ void i2c_dump_msgs(struct i2c_msg *msg, int nmsgs);
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
*
* Given an emulator this returns the associated device