All of lore.kernel.org
 help / color / mirror / Atom feed
From: Simon Glass <sjg@chromium.org>
To: u-boot@lists.denx.de
Subject: [PATCH v2 19/37] sandbox: i2c: Support i2c emulation with of-platdata
Date: Wed,  3 Feb 2021 09:43:35 -0700	[thread overview]
Message-ID: <20210203164353.2577985-9-sjg@chromium.org> (raw)
In-Reply-To: <20210203164353.2577985-1-sjg@chromium.org>

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>
---

(no changes since v1)

 drivers/i2c/i2c-emul-uclass.c | 13 +++++++++++++
 drivers/rtc/sandbox_rtc.c     | 13 +++++++++++++
 include/i2c.h                 | 15 +++++++++++++++
 3 files changed, 41 insertions(+)

diff --git a/drivers/i2c/i2c-emul-uclass.c b/drivers/i2c/i2c-emul-uclass.c
index 9ef4651fa43..bb6ef59914b 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;
 
+#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);
+#endif
 	if (ret) {
 		log_err("No emulators for device '%s'\n", dev->name);
 		return ret;
diff --git a/drivers/rtc/sandbox_rtc.c b/drivers/rtc/sandbox_rtc.c
index d0864b1df97..657e5c7be2c 100644
--- a/drivers/rtc/sandbox_rtc.c
+++ b/drivers/rtc/sandbox_rtc.c
@@ -79,6 +79,18 @@ struct acpi_ops sandbox_rtc_acpi_ops = {
 };
 #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 = {
 	.get = sandbox_rtc_get,
 	.set = sandbox_rtc_set,
@@ -97,5 +109,6 @@ U_BOOT_DRIVER(sandbox_rtc) = {
 	.id	= UCLASS_RTC,
 	.of_match = sandbox_rtc_ids,
 	.ops	= &sandbox_rtc_ops,
+	.bind	= sandbox_rtc_bind,
 	ACPI_OPS_PTR(&sandbox_rtc_acpi_ops)
 };
diff --git a/include/i2c.h b/include/i2c.h
index e45e33f5037..7eb7eea58e8 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
 };
 
@@ -554,6 +557,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
  *
-- 
2.30.0.365.g02bc693789-goog

  parent reply	other threads:[~2021-02-03 16:43 UTC|newest]

Thread overview: 46+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-02-03 16:43 [PATCH v2 00/37] dm: Implement OF_PLATDATA_INST in driver model (part E) Simon Glass
2021-02-03 16:43 ` [PATCH v2 01/37] sandbox: Drop debug message in os_spl_to_uboot() Simon Glass
2021-02-04 13:36   ` Heinrich Schuchardt
2021-02-03 16:43 ` [PATCH v2 02/37] linker_lists: Allow use in data structures Simon Glass
2021-02-04 13:54   ` Heinrich Schuchardt
2021-02-07 14:37     ` Simon Glass
2021-02-03 16:43 ` [PATCH v2 03/37] dm: core: Add macros to access the new linker lists Simon Glass
2021-02-04 13:46   ` Heinrich Schuchardt
2021-02-03 16:43 ` [PATCH v2 04/37] dm: core: Allow dropping run-time binding of devices Simon Glass
2021-02-04 13:57   ` Heinrich Schuchardt
2021-02-03 16:43 ` [PATCH v2 05/37] dm: core: Adjust uclass setup with of-platdata Simon Glass
2021-02-03 16:43 ` [PATCH v2 06/37] dm: core: Set up driver model for OF_PLATDATA_INST Simon Glass
2021-02-03 16:43 ` [PATCH v2 07/37] dm: core: Skip adding uclasses with OF_PLATDATA_INST Simon Glass
2021-02-03 16:43 ` [PATCH v2 08/37] dm: Add the new dtoc-generated files to the build Simon Glass
2021-02-03 16:43 ` [PATCH v2 09/37] dm: core: Include dt-decl.h automatically Simon Glass
2021-02-03 16:43 ` [PATCH v2 10/37] dm: test: Avoid destroying uclasses with of-platdata-inst Simon Glass
2021-02-03 16:43 ` [PATCH v2 11/37] clk: sandbox: Move priv/plat data to a header file Simon Glass
2021-02-03 16:43 ` [PATCH v2 12/37] clk: fixed-rate: Export driver parts for OF_PLATDATA_INST Simon Glass
2021-02-03 16:43 ` [PATCH v2 13/37] clk: sandbox: Create a special fixed-rate driver Simon Glass
2021-02-03 16:43 ` [PATCH v2 14/37] dm: core: Drop device_get_by_driver_info() Simon Glass
2021-02-03 16:43 ` [PATCH v2 15/37] dm: core: Drop uclass_find_device_by_phandle() with of-platdata Simon Glass
2021-02-03 16:43 ` [PATCH v2 16/37] sandbox: i2c: Move platdata structs to header files Simon Glass
2021-02-03 16:43 ` [PATCH v2 17/37] dm: Rename device_get_by_driver_info_idx() Simon Glass
2021-02-03 16:43 ` [PATCH v2 18/37] sandbox_spl: Increase SPL malloc() size Simon Glass
2021-02-04 14:01   ` Heinrich Schuchardt
2021-02-03 16:43 ` Simon Glass [this message]
2021-02-03 16:43 ` [PATCH v2 20/37] Revert "sandbox: Disable I2C emulators in SPL" Simon Glass
2021-02-03 16:43 ` [PATCH v2 21/37] sandbox: Create a new sandbox_noinst build Simon Glass
2021-02-03 16:43 ` [PATCH v2 22/37] test: Run sandbox_spl tests on sandbox_noinst Simon Glass
2021-02-03 16:43 ` [PATCH v2 23/37] azure/gitlab: Add tests for sandbox_noinst Simon Glass
2021-02-03 16:43 ` [PATCH v2 24/37] dm: core: Add an option to support SPL in read-only memory Simon Glass
2021-02-03 16:43 ` [PATCH v2 25/37] dm: core: Create a struct for device runtime info Simon Glass
2021-02-03 16:43 ` [PATCH v2 26/37] dm: core: Move flags to device-runtime info Simon Glass
2021-02-03 16:43 ` [PATCH v2 27/37] dm: core: Allow storing priv/plat data separately Simon Glass
2021-02-03 16:43 ` [PATCH v2 28/37] sandbox: Define a region for device priv/plat data Simon Glass
2021-02-03 16:43 ` [PATCH v2 29/37] dm: core: Use separate priv/plat data region Simon Glass
2021-02-03 16:43 ` [PATCH v2 30/37] x86: Define a region for device priv/plat data Simon Glass
2021-02-03 16:43 ` [PATCH v2 31/37] x86: apl: Fix the header order in pmc Simon Glass
2021-02-03 16:43 ` [PATCH v2 32/37] x86: apl: Tell of-platdata about a required header file Simon Glass
2021-02-03 16:43 ` [PATCH v2 33/37] x86: itss: Tidy up bind() for of-platdata-inst Simon Glass
2021-02-03 16:43 ` [PATCH v2 34/37] x86: Support a fake PCI device with of-platdata-inst Simon Glass
2021-02-03 16:43 ` [PATCH v2 35/37] x86: Don't include reset driver in SPL Simon Glass
2021-02-03 16:43 ` [PATCH v2 36/37] x86: coral: Drop ACPI properties from of-platdata Simon Glass
2021-02-03 16:43 ` [PATCH v2 37/37] x86: apl: Use read-only SPL and new of-platdata Simon Glass
2021-02-04  7:48 ` [PATCH v2 00/37] dm: Implement OF_PLATDATA_INST in driver model (part E) Heinrich Schuchardt
2021-02-04 15:08   ` Simon Glass

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20210203164353.2577985-9-sjg@chromium.org \
    --to=sjg@chromium.org \
    --cc=u-boot@lists.denx.de \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.