From 2e3f1ff63f50f36e74d46f939823241856ebf1bd Mon Sep 17 00:00:00 2001
From: Simon Glass <sjg@chromium.org>
Date: Tue, 5 Jul 2016 17:10:09 -0600
Subject: [PATCH] dm: Convert users from dm_scan_fdt_node() to
 dm_scan_fdt_dev()

This new function is more convenient for callers, and handles pre-relocation
situations automatically.

Signed-off-by: Simon Glass <sjg@chromium.org>
---
 arch/x86/lib/lpc-uclass.c                 |  4 +---
 common/usb_hub.c                          |  3 +--
 drivers/core/simple-bus.c                 |  3 +--
 drivers/i2c/i2c-uclass.c                  |  3 +--
 drivers/i2c/sandbox_i2c.c                 |  4 +---
 drivers/misc/cros_ec.c                    |  3 +--
 drivers/pch/pch-uclass.c                  |  4 +---
 drivers/pci/pci-uclass.c                  | 11 +----------
 drivers/pci/pci_sandbox.c                 |  3 +--
 drivers/pinctrl/pinctrl_pic32.c           |  3 +--
 drivers/pinctrl/rockchip/pinctrl_rk3036.c |  3 +--
 drivers/pinctrl/rockchip/pinctrl_rk3288.c |  4 +---
 drivers/power/pmic/pm8916.c               |  3 +--
 drivers/power/regulator/Kconfig           |  2 +-
 drivers/spi/spi-uclass.c                  |  3 +--
 drivers/spmi/spmi-uclass.c                |  3 +--
 drivers/usb/emul/usb-emul-uclass.c        |  3 +--
 drivers/usb/host/usb-uclass.c             |  4 +---
 include/power/regulator.h                 |  2 +-
 test/dm/bus.c                             |  3 +--
 20 files changed, 20 insertions(+), 51 deletions(-)

diff --git a/arch/x86/lib/lpc-uclass.c b/arch/x86/lib/lpc-uclass.c
index c6e8f73d22..b8254ff48c 100644
--- a/arch/x86/lib/lpc-uclass.c
+++ b/arch/x86/lib/lpc-uclass.c
@@ -7,7 +7,6 @@
 
 #include <common.h>
 #include <dm.h>
-#include <dm/root.h>
 
 DECLARE_GLOBAL_DATA_PTR;
 
@@ -19,8 +18,7 @@ static int lpc_uclass_post_bind(struct udevice *bus)
 	 * Before relocation, only bind devices marked for pre-relocation
 	 * use.
 	 */
-	return dm_scan_fdt_node(bus, gd->fdt_blob, bus->of_offset,
-				gd->flags & GD_FLG_RELOC ? false : true);
+	return dm_scan_fdt_dev(bus);
 }
 
 UCLASS_DRIVER(lpc) = {
diff --git a/common/usb_hub.c b/common/usb_hub.c
index 0f39c9faf7..26ee13e149 100644
--- a/common/usb_hub.c
+++ b/common/usb_hub.c
@@ -36,7 +36,6 @@
 #include <asm/state.h>
 #endif
 #include <asm/unaligned.h>
-#include <dm/root.h>
 
 DECLARE_GLOBAL_DATA_PTR;
 
@@ -758,7 +757,7 @@ int usb_hub_scan(struct udevice *hub)
 static int usb_hub_post_bind(struct udevice *dev)
 {
 	/* Scan the bus for devices */
-	return dm_scan_fdt_node(dev, gd->fdt_blob, dev->of_offset, false);
+	return dm_scan_fdt_dev(dev);
 }
 
 static int usb_hub_post_probe(struct udevice *dev)
diff --git a/drivers/core/simple-bus.c b/drivers/core/simple-bus.c
index 1a9c864ef3..5c955da334 100644
--- a/drivers/core/simple-bus.c
+++ b/drivers/core/simple-bus.c
@@ -6,7 +6,6 @@
 
 #include <common.h>
 #include <dm.h>
-#include <dm/root.h>
 
 DECLARE_GLOBAL_DATA_PTR;
 
@@ -41,7 +40,7 @@ static int simple_bus_post_bind(struct udevice *dev)
 		plat->size = cell[2];
 	}
 
-	return dm_scan_fdt_node(dev, gd->fdt_blob, dev->of_offset, false);
+	return dm_scan_fdt_dev(dev);
 }
 
 UCLASS_DRIVER(simple_bus) = {
diff --git a/drivers/i2c/i2c-uclass.c b/drivers/i2c/i2c-uclass.c
index 20b30ffbeb..16447b896b 100644
--- a/drivers/i2c/i2c-uclass.c
+++ b/drivers/i2c/i2c-uclass.c
@@ -12,7 +12,6 @@
 #include <malloc.h>
 #include <dm/device-internal.h>
 #include <dm/lists.h>
-#include <dm/root.h>
 
 DECLARE_GLOBAL_DATA_PTR;
 
@@ -503,7 +502,7 @@ static int i2c_post_bind(struct udevice *dev)
 {
 #if CONFIG_IS_ENABLED(OF_CONTROL)
 	/* Scan the bus for devices */
-	return dm_scan_fdt_node(dev, gd->fdt_blob, dev->of_offset, false);
+        return dm_scan_fdt_dev(dev);
 #else
 	return 0;
 #endif
diff --git a/drivers/i2c/sandbox_i2c.c b/drivers/i2c/sandbox_i2c.c
index 2c84c41643..4696a1ae62 100644
--- a/drivers/i2c/sandbox_i2c.c
+++ b/drivers/i2c/sandbox_i2c.c
@@ -14,7 +14,6 @@
 #include <asm/test.h>
 #include <dm/lists.h>
 #include <dm/device-internal.h>
-#include <dm/root.h>
 
 DECLARE_GLOBAL_DATA_PTR;
 
@@ -33,8 +32,7 @@ static int get_emul(struct udevice *dev, struct udevice **devp,
 	*opsp = NULL;
 	plat = dev_get_parent_platdata(dev);
 	if (!plat->emul) {
-		ret = dm_scan_fdt_node(dev, gd->fdt_blob, dev->of_offset,
-				       false);
+		ret = dm_scan_fdt_dev(dev);
 		if (ret)
 			return ret;
 
diff --git a/drivers/misc/cros_ec.c b/drivers/misc/cros_ec.c
index e3229efed0..f50e73fea6 100644
--- a/drivers/misc/cros_ec.c
+++ b/drivers/misc/cros_ec.c
@@ -26,7 +26,6 @@
 #include <asm/io.h>
 #include <asm-generic/gpio.h>
 #include <dm/device-internal.h>
-#include <dm/root.h>
 #include <dm/uclass-internal.h>
 
 #ifdef DEBUG_TRACE
@@ -1453,7 +1452,7 @@ static int do_cros_ec(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
 int cros_ec_post_bind(struct udevice *dev)
 {
 	/* Scan for available EC devices (e.g. I2C tunnel) */
-	return dm_scan_fdt_node(dev, gd->fdt_blob, dev->of_offset, false);
+	return dm_scan_fdt_dev(dev);
 }
 
 U_BOOT_CMD(
diff --git a/drivers/pch/pch-uclass.c b/drivers/pch/pch-uclass.c
index 7216660a24..5b2fa1f0a5 100644
--- a/drivers/pch/pch-uclass.c
+++ b/drivers/pch/pch-uclass.c
@@ -8,7 +8,6 @@
 #include <common.h>
 #include <dm.h>
 #include <pch.h>
-#include <dm/root.h>
 
 DECLARE_GLOBAL_DATA_PTR;
 
@@ -63,8 +62,7 @@ static int pch_uclass_post_bind(struct udevice *bus)
 	 * Before relocation, only bind devices marked for pre-relocation
 	 * use.
 	 */
-	return dm_scan_fdt_node(bus, gd->fdt_blob, bus->of_offset,
-				gd->flags & GD_FLG_RELOC ? false : true);
+	return dm_scan_fdt_dev(bus);
 }
 
 UCLASS_DRIVER(pch) = {
diff --git a/drivers/pci/pci-uclass.c b/drivers/pci/pci-uclass.c
index 32590ce498..230d18142d 100644
--- a/drivers/pci/pci-uclass.c
+++ b/drivers/pci/pci-uclass.c
@@ -13,7 +13,6 @@
 #include <pci.h>
 #include <asm/io.h>
 #include <dm/lists.h>
-#include <dm/root.h>
 #include <dm/device-internal.h>
 #if defined(CONFIG_X86) && defined(CONFIG_HAVE_FSP)
 #include <asm/fsp/fsp_support.h>
@@ -755,13 +754,6 @@ error:
 
 static int pci_uclass_post_bind(struct udevice *bus)
 {
-	/*
-	 * If there is no pci device listed in the device tree,
-	 * don't bother scanning the device tree.
-	 */
-	if (bus->of_offset == -1)
-		return 0;
-
 	/*
 	 * Scan the device tree for devices. This does not probe the PCI bus,
 	 * as this is not permitted while binding. It just finds devices
@@ -770,8 +762,7 @@ static int pci_uclass_post_bind(struct udevice *bus)
 	 * Before relocation, only bind devices marked for pre-relocation
 	 * use.
 	 */
-	return dm_scan_fdt_node(bus, gd->fdt_blob, bus->of_offset,
-				gd->flags & GD_FLG_RELOC ? false : true);
+	return dm_scan_fdt_dev(bus);
 }
 
 static int decode_regions(struct pci_controller *hose, const void *blob,
diff --git a/drivers/pci/pci_sandbox.c b/drivers/pci/pci_sandbox.c
index 6de5130c2a..b5628139b3 100644
--- a/drivers/pci/pci_sandbox.c
+++ b/drivers/pci/pci_sandbox.c
@@ -10,7 +10,6 @@
 #include <fdtdec.h>
 #include <inttypes.h>
 #include <pci.h>
-#include <dm/root.h>
 
 DECLARE_GLOBAL_DATA_PTR;
 
@@ -55,7 +54,7 @@ static int sandbox_pci_read_config(struct udevice *bus, pci_dev_t devfn,
 static int sandbox_pci_child_post_bind(struct udevice *dev)
 {
 	/* Attach an emulator if we can */
-	return dm_scan_fdt_node(dev, gd->fdt_blob, dev->of_offset, false);
+	return dm_scan_fdt_dev(dev);
 }
 
 static const struct dm_pci_ops sandbox_pci_ops = {
diff --git a/drivers/pinctrl/pinctrl_pic32.c b/drivers/pinctrl/pinctrl_pic32.c
index 5cf97ecec8..5636f8f47f 100644
--- a/drivers/pinctrl/pinctrl_pic32.c
+++ b/drivers/pinctrl/pinctrl_pic32.c
@@ -10,7 +10,6 @@
 #include <errno.h>
 #include <asm/io.h>
 #include <dm/pinctrl.h>
-#include <dm/root.h>
 #include <mach/pic32.h>
 
 DECLARE_GLOBAL_DATA_PTR;
@@ -344,7 +343,7 @@ static int pic32_pinctrl_probe(struct udevice *dev)
 static int pic32_pinctrl_bind(struct udevice *dev)
 {
 	/* scan child GPIO banks */
-	return dm_scan_fdt_node(dev, gd->fdt_blob, dev->of_offset, false);
+	return dm_scan_fdt_dev(dev);
 }
 
 static const struct udevice_id pic32_pinctrl_ids[] = {
diff --git a/drivers/pinctrl/rockchip/pinctrl_rk3036.c b/drivers/pinctrl/rockchip/pinctrl_rk3036.c
index 1f78bf862d..3648678e15 100644
--- a/drivers/pinctrl/rockchip/pinctrl_rk3036.c
+++ b/drivers/pinctrl/rockchip/pinctrl_rk3036.c
@@ -15,7 +15,6 @@
 #include <asm/arch/hardware.h>
 #include <asm/arch/periph.h>
 #include <dm/pinctrl.h>
-#include <dm/root.h>
 
 DECLARE_GLOBAL_DATA_PTR;
 
@@ -256,7 +255,7 @@ static struct pinctrl_ops rk3036_pinctrl_ops = {
 static int rk3036_pinctrl_bind(struct udevice *dev)
 {
 	/* scan child GPIO banks */
-	return dm_scan_fdt_node(dev, gd->fdt_blob, dev->of_offset, false);
+	return dm_scan_fdt_dev(dev);
 }
 
 static int rk3036_pinctrl_probe(struct udevice *dev)
diff --git a/drivers/pinctrl/rockchip/pinctrl_rk3288.c b/drivers/pinctrl/rockchip/pinctrl_rk3288.c
index 8cb3b8228e..4650066a3c 100644
--- a/drivers/pinctrl/rockchip/pinctrl_rk3288.c
+++ b/drivers/pinctrl/rockchip/pinctrl_rk3288.c
@@ -17,7 +17,6 @@
 #include <asm/arch/periph.h>
 #include <asm/arch/pmu_rk3288.h>
 #include <dm/pinctrl.h>
-#include <dm/root.h>
 
 DECLARE_GLOBAL_DATA_PTR;
 
@@ -669,8 +668,7 @@ static int rk3288_pinctrl_bind(struct udevice *dev)
 #if CONFIG_IS_ENABLED(OF_PLATDATA)
 	return 0;
 #else
-	/* scan child GPIO banks */
-	return dm_scan_fdt_node(dev, gd->fdt_blob, dev->of_offset, false);
+	return dm_scan_fdt_dev(dev);
 #endif
 }
 
diff --git a/drivers/power/pmic/pm8916.c b/drivers/power/pmic/pm8916.c
index d4c7d4adff..6f5608e456 100644
--- a/drivers/power/pmic/pm8916.c
+++ b/drivers/power/pmic/pm8916.c
@@ -7,7 +7,6 @@
  */
 #include <common.h>
 #include <dm.h>
-#include <dm/root.h>
 #include <power/pmic.h>
 #include <spmi/spmi.h>
 
@@ -82,7 +81,7 @@ static int pm8916_probe(struct udevice *dev)
 
 static int pm8916_bind(struct udevice *dev)
 {
-	return dm_scan_fdt_node(dev, gd->fdt_blob, dev->of_offset, false);
+	return dm_scan_fdt_dev(dev);
 }
 
 U_BOOT_DRIVER(pmic_pm8916) = {
diff --git a/drivers/power/regulator/Kconfig b/drivers/power/regulator/Kconfig
index 465ff3fda6..17f22dda2b 100644
--- a/drivers/power/regulator/Kconfig
+++ b/drivers/power/regulator/Kconfig
@@ -13,7 +13,7 @@ config DM_REGULATOR
 	- 'drivers/power/pmic/regulator-uclass.c'
 	It's important to call the device_bind() with the proper node offset,
 	when binding the regulator devices. The pmic_bind_childs() can be used
-	for this purpose if PMIC I/O driver is implemented or dm_scan_fdt_node()
+	for this purpose if PMIC I/O driver is implemented or dm_scan_fdt_dev()
 	otherwise. Detailed information can be found in the header file.
 
 config SPL_DM_REGULATOR
diff --git a/drivers/spi/spi-uclass.c b/drivers/spi/spi-uclass.c
index 8003f9bfc8..3d3005c226 100644
--- a/drivers/spi/spi-uclass.c
+++ b/drivers/spi/spi-uclass.c
@@ -12,7 +12,6 @@
 #include <spi.h>
 #include <dm/device-internal.h>
 #include <dm/uclass-internal.h>
-#include <dm/root.h>
 #include <dm/lists.h>
 #include <dm/util.h>
 
@@ -112,7 +111,7 @@ int spi_xfer(struct spi_slave *slave, unsigned int bitlen,
 static int spi_post_bind(struct udevice *dev)
 {
 	/* Scan the bus for devices */
-	return dm_scan_fdt_node(dev, gd->fdt_blob, dev->of_offset, false);
+	return dm_scan_fdt_dev(dev);
 }
 
 static int spi_child_post_bind(struct udevice *dev)
diff --git a/drivers/spmi/spmi-uclass.c b/drivers/spmi/spmi-uclass.c
index 4ddd51b556..9fa330b8e9 100644
--- a/drivers/spmi/spmi-uclass.c
+++ b/drivers/spmi/spmi-uclass.c
@@ -9,7 +9,6 @@
 #include <common.h>
 #include <dm.h>
 #include <errno.h>
-#include <dm/root.h>
 #include <spmi/spmi.h>
 #include <linux/ctype.h>
 
@@ -38,7 +37,7 @@ int spmi_reg_write(struct udevice *dev, int usid, int pid, int reg,
 
 static int spmi_post_bind(struct udevice *dev)
 {
-	return dm_scan_fdt_node(dev, gd->fdt_blob, dev->of_offset, false);
+	return dm_scan_fdt_dev(dev);
 }
 
 UCLASS_DRIVER(spmi) = {
diff --git a/drivers/usb/emul/usb-emul-uclass.c b/drivers/usb/emul/usb-emul-uclass.c
index ee7ea5ad91..da91d04a08 100644
--- a/drivers/usb/emul/usb-emul-uclass.c
+++ b/drivers/usb/emul/usb-emul-uclass.c
@@ -8,7 +8,6 @@
 #include <common.h>
 #include <dm.h>
 #include <usb.h>
-#include <dm/root.h>
 #include <dm/device-internal.h>
 
 DECLARE_GLOBAL_DATA_PTR;
@@ -268,7 +267,7 @@ int usb_emul_setup_device(struct udevice *dev, int maxpacketsize,
 int usb_emul_post_bind(struct udevice *dev)
 {
 	/* Scan the bus for devices */
-	return dm_scan_fdt_node(dev, gd->fdt_blob, dev->of_offset, false);
+	return dm_scan_fdt_dev(dev);
 }
 
 void usb_emul_reset(struct udevice *dev)
diff --git a/drivers/usb/host/usb-uclass.c b/drivers/usb/host/usb-uclass.c
index 69c9a504eb..070e271db8 100644
--- a/drivers/usb/host/usb-uclass.c
+++ b/drivers/usb/host/usb-uclass.c
@@ -14,7 +14,6 @@
 #include <usb.h>
 #include <dm/device-internal.h>
 #include <dm/lists.h>
-#include <dm/root.h>
 #include <dm/uclass-internal.h>
 
 DECLARE_GLOBAL_DATA_PTR;
@@ -351,8 +350,7 @@ struct usb_device *usb_get_dev_index(struct udevice *bus, int index)
 
 int usb_post_bind(struct udevice *dev)
 {
-	/* Scan the bus for devices */
-	return dm_scan_fdt_node(dev, gd->fdt_blob, dev->of_offset, false);
+	return dm_scan_fdt_dev(dev);
 }
 
 int usb_setup_ehci_gadget(struct ehci_ctrl **ctlrp)
diff --git a/include/power/regulator.h b/include/power/regulator.h
index 63c0814fe8..9bcd728120 100644
--- a/include/power/regulator.h
+++ b/include/power/regulator.h
@@ -54,7 +54,7 @@
  * which does the scan on the device node, for the 'regulator-name' constraint.
  * If the parent is not a PMIC device, and the child is not bind by function:
  * 'pmic_bind_childs()', then it's recommended to bind the device by call to
- * dm_scan_fdt_node() - this is usually done automatically for bus devices,
+ * dm_scan_fdt_dev() - this is usually done automatically for bus devices,
  * as a post bind method.
  *
  * Regulator get:
diff --git a/test/dm/bus.c b/test/dm/bus.c
index 3b5a23b934..d94dcf7a60 100644
--- a/test/dm/bus.c
+++ b/test/dm/bus.c
@@ -7,7 +7,6 @@
 #include <common.h>
 #include <dm.h>
 #include <dm/device-internal.h>
-#include <dm/root.h>
 #include <dm/test.h>
 #include <dm/uclass-internal.h>
 #include <dm/util.h>
@@ -30,7 +29,7 @@ static struct dm_test_state *test_state;
 
 static int testbus_drv_probe(struct udevice *dev)
 {
-	return dm_scan_fdt_node(dev, gd->fdt_blob, dev->of_offset, false);
+	return dm_scan_fdt_dev(dev);
 }
 
 static int testbus_child_post_bind(struct udevice *dev)
-- 
2.39.5