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 17/37] dm: Rename device_get_by_driver_info_idx()
Date: Wed,  3 Feb 2021 09:43:33 -0700	[thread overview]
Message-ID: <20210203164353.2577985-7-sjg@chromium.org> (raw)
In-Reply-To: <20210203164353.2577985-1-sjg@chromium.org>

This function finds a device by its driver_info index. With
of-platdata-inst we do not use driver_info, but instead instantiate
udevice records at build-time.

However the semantics of using the function are the same in each case:
the caller provides an index and gets back a device.

So rename the function to device_get_by_ofplat_idx(), so that it can be
used for both situations. The caller does not really need to worry about
the details.

Signed-off-by: Simon Glass <sjg@chromium.org>
---

(no changes since v1)

 drivers/clk/clk-uclass.c    |  2 +-
 drivers/core/device.c       | 13 ++++++++++---
 drivers/misc/irq-uclass.c   |  2 +-
 drivers/mmc/fsl_esdhc_imx.c |  3 +--
 include/dm/device.h         | 16 +++++++++++-----
 test/dm/of_platdata.c       | 15 +++++++--------
 6 files changed, 31 insertions(+), 20 deletions(-)

diff --git a/drivers/clk/clk-uclass.c b/drivers/clk/clk-uclass.c
index d5c4e3cbe51..0e62c49d7a8 100644
--- a/drivers/clk/clk-uclass.c
+++ b/drivers/clk/clk-uclass.c
@@ -38,7 +38,7 @@ int clk_get_by_driver_info(struct udevice *dev, struct phandle_1_arg *cells,
 {
 	int ret;
 
-	ret = device_get_by_driver_info_idx(cells->idx, &clk->dev);
+	ret = device_get_by_ofplat_idx(cells->idx, &clk->dev);
 	if (ret)
 		return ret;
 	clk->id = cells->arg[0];
diff --git a/drivers/core/device.c b/drivers/core/device.c
index 51516391d16..657ddcc12b6 100644
--- a/drivers/core/device.c
+++ b/drivers/core/device.c
@@ -753,12 +753,19 @@ int device_get_global_by_ofnode(ofnode ofnode, struct udevice **devp)
 }
 
 #if CONFIG_IS_ENABLED(OF_PLATDATA)
-int device_get_by_driver_info_idx(uint idx, struct udevice **devp)
+int device_get_by_ofplat_idx(uint idx, struct udevice **devp)
 {
-	struct driver_rt *drt = gd_dm_driver_rt() + idx;
 	struct udevice *dev;
 
-	dev = drt->dev;
+	if (CONFIG_IS_ENABLED(OF_PLATDATA_INST)) {
+		struct udevice *base = ll_entry_start(struct udevice, udevice);
+
+		dev = base + idx;
+	} else {
+		struct driver_rt *drt = gd_dm_driver_rt() + idx;
+
+		dev = drt->dev;
+	}
 	*devp = NULL;
 
 	return device_get_device_tail(dev, dev ? 0 : -ENOENT, devp);
diff --git a/drivers/misc/irq-uclass.c b/drivers/misc/irq-uclass.c
index 24b27962a7d..3aa26f61d9e 100644
--- a/drivers/misc/irq-uclass.c
+++ b/drivers/misc/irq-uclass.c
@@ -69,7 +69,7 @@ int irq_get_by_driver_info(struct udevice *dev,
 {
 	int ret;
 
-	ret = device_get_by_driver_info_idx(cells->idx, &irq->dev);
+	ret = device_get_by_ofplat_idx(cells->idx, &irq->dev);
 	if (ret)
 		return ret;
 	irq->id = cells->arg[0];
diff --git a/drivers/mmc/fsl_esdhc_imx.c b/drivers/mmc/fsl_esdhc_imx.c
index 8ac859797f0..fbdf21acb8c 100644
--- a/drivers/mmc/fsl_esdhc_imx.c
+++ b/drivers/mmc/fsl_esdhc_imx.c
@@ -1523,8 +1523,7 @@ static int fsl_esdhc_probe(struct udevice *dev)
 	if (CONFIG_IS_ENABLED(DM_GPIO) && !priv->non_removable) {
 		struct udevice *gpiodev;
 
-		ret = device_get_by_driver_info_idx(dtplat->cd_gpios->idx,
-						    &gpiodev);
+		ret = device_get_by_ofplat_idx(dtplat->cd_gpios->idx, &gpiodev);
 		if (ret)
 			return ret;
 
diff --git a/include/dm/device.h b/include/dm/device.h
index c9afa4dce50..891a5f84243 100644
--- a/include/dm/device.h
+++ b/include/dm/device.h
@@ -632,18 +632,24 @@ int device_find_global_by_ofnode(ofnode node, struct udevice **devp);
 int device_get_global_by_ofnode(ofnode node, struct udevice **devp);
 
 /**
- * device_get_by_driver_info_idx() - Get a device based on driver_info index
+ * device_get_by_ofplat_idx() - Get a device based on of-platdata index
  *
- * Locates a device by its struct driver_info, by using its index number which
- * is written into the idx field of struct phandle_1_arg, etc.
+ * Locates a device by either its struct driver_info index, or its
+ * struct udevice index. The latter is used with OF_PLATDATA_INST, since we have
+ * a list of build-time instantiated struct udevice records, The former is used
+ * with !OF_PLATDATA_INST since in that case we have a list of
+ * struct driver_info records.
+ *
+ * The index number is written into the idx field of struct phandle_1_arg, etc.
+ * It is the position of this driver_info/udevice in its linker list.
  *
  * The device is probed to activate it ready for use.
  *
- * @idx: Index number of the driver_info structure (0=first)
+ * @idx: Index number of the driver_info/udevice structure (0=first)
  * @devp: Returns pointer to device if found, otherwise this is set to NULL
  * @return 0 if OK, -ve on error
  */
-int device_get_by_driver_info_idx(uint idx, struct udevice **devp);
+int device_get_by_ofplat_idx(uint idx, struct udevice **devp);
 
 /**
  * device_find_first_child() - Find the first child of a device
diff --git a/test/dm/of_platdata.c b/test/dm/of_platdata.c
index 0de4ab5dafa..1b46bdf555a 100644
--- a/test/dm/of_platdata.c
+++ b/test/dm/of_platdata.c
@@ -157,12 +157,11 @@ static int dm_test_of_plat_dev(struct unit_test_state *uts)
 		if (found[i]) {
 			/* Make sure we can find it */
 			ut_assertnonnull(drt->dev);
-			ut_assertok(device_get_by_driver_info_idx(i, &dev));
+			ut_assertok(device_get_by_ofplat_idx(i, &dev));
 			ut_asserteq_ptr(dev, drt->dev);
 		} else {
 			ut_assertnull(drt->dev);
-			ut_asserteq(-ENOENT,
-				    device_get_by_driver_info_idx(i, &dev));
+			ut_asserteq(-ENOENT, device_get_by_ofplat_idx(i, &dev));
 		}
 	}
 
@@ -180,22 +179,22 @@ static int dm_test_of_plat_phandle(struct unit_test_state *uts)
 	ut_asserteq_str("sandbox_clk_test", dev->name);
 	plat = dev_get_plat(dev);
 
-	ut_assertok(device_get_by_driver_info_idx(plat->clocks[0].idx, &clk));
+	ut_assertok(device_get_by_ofplat_idx(plat->clocks[0].idx, &clk));
 	ut_asserteq_str("sandbox_fixed_clock", clk->name);
 
-	ut_assertok(device_get_by_driver_info_idx(plat->clocks[1].idx, &clk));
+	ut_assertok(device_get_by_ofplat_idx(plat->clocks[1].idx, &clk));
 	ut_asserteq_str("sandbox_clk", clk->name);
 	ut_asserteq(1, plat->clocks[1].arg[0]);
 
-	ut_assertok(device_get_by_driver_info_idx(plat->clocks[2].idx, &clk));
+	ut_assertok(device_get_by_ofplat_idx(plat->clocks[2].idx, &clk));
 	ut_asserteq_str("sandbox_clk", clk->name);
 	ut_asserteq(0, plat->clocks[2].arg[0]);
 
-	ut_assertok(device_get_by_driver_info_idx(plat->clocks[3].idx, &clk));
+	ut_assertok(device_get_by_ofplat_idx(plat->clocks[3].idx, &clk));
 	ut_asserteq_str("sandbox_clk", clk->name);
 	ut_asserteq(3, plat->clocks[3].arg[0]);
 
-	ut_assertok(device_get_by_driver_info_idx(plat->clocks[4].idx, &clk));
+	ut_assertok(device_get_by_ofplat_idx(plat->clocks[4].idx, &clk));
 	ut_asserteq_str("sandbox_clk", clk->name);
 	ut_asserteq(2, plat->clocks[4].arg[0]);
 
-- 
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 ` Simon Glass [this message]
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 ` [PATCH v2 19/37] sandbox: i2c: Support i2c emulation with of-platdata Simon Glass
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-7-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.