]> git.dujemihanovic.xyz Git - u-boot.git/commitdiff
dm: Rename device_get_by_driver_info_idx()
authorSimon Glass <sjg@chromium.org>
Mon, 15 Mar 2021 04:25:28 +0000 (17:25 +1300)
committerSimon Glass <sjg@chromium.org>
Fri, 26 Mar 2021 04:03:08 +0000 (17:03 +1300)
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>
Signed-off-by: Simon Glass <sjg@chromium.org>
drivers/clk/clk-uclass.c
drivers/core/device.c
drivers/misc/irq-uclass.c
drivers/mmc/fsl_esdhc_imx.c
include/dm/device.h
test/dm/of_platdata.c

index b87288da7a2a000fca13f7917aeb4a164689ba48..4ab3c402ed834163019516fb5341d11a50653f95 100644 (file)
@@ -39,7 +39,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];
index 2399f6f70cec75cee1896be92a742938a65bf433..1990b6f69f808e46b50a942b08df28b513144d62 100644 (file)
@@ -811,12 +811,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);
index 24b27962a7d0da6262f7b7ddb425d9438ad005e7..3aa26f61d9e60b2feed41227bab77073ef083345 100644 (file)
@@ -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];
index 6a9403dc004e15afe79b6ac37d2c27762a5a767d..09a5cd61e3bee6fb8ff904c03162a0c07227ea70 100644 (file)
@@ -1530,8 +1530,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;
 
index ca796059e0c8aaa0234baa0903fcc3908a1f9cf5..9183356468fa3d44b90fc529d84ae2da60d57eff 100644 (file)
@@ -667,18 +667,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
index d68c59128289371c5a75718639ceff504566edd3..e5f32a0f1c476e16c79ef50ec4d2462bd4315466 100644 (file)
@@ -158,12 +158,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));
                }
        }
 
@@ -181,22 +180,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]);