dm: core: Use dev_has_ofnode() instead of dev_of_valid()

We have two functions which do the same thing. Standardise on
dev_has_ofnode() since there is no such thing as an 'invalid' ofnode in
normal operation: it is either null or missing.

Also move the functions into one place.

Signed-off-by: Simon Glass <sjg@chromium.org>
Reviewed-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
diff --git a/drivers/clk/clk-uclass.c b/drivers/clk/clk-uclass.c
index ac954a3..5cfd00c 100644
--- a/drivers/clk/clk-uclass.c
+++ b/drivers/clk/clk-uclass.c
@@ -345,7 +345,7 @@
 {
 	int ret;
 
-	if (!dev_of_valid(dev))
+	if (!dev_has_ofnode(dev))
 		return 0;
 
 	/* If this not in SPL and pre-reloc state, don't take any action. */
diff --git a/drivers/core/device.c b/drivers/core/device.c
index 8c7ce22..bd4ecc9 100644
--- a/drivers/core/device.c
+++ b/drivers/core/device.c
@@ -485,7 +485,7 @@
 	}
 
 	/* Only handle devices that have a valid ofnode */
-	if (dev_of_valid(dev)) {
+	if (dev_has_ofnode(dev)) {
 		/*
 		 * Process 'assigned-{clocks/clock-parents/clock-rates}'
 		 * properties
diff --git a/drivers/gpio/sandbox.c b/drivers/gpio/sandbox.c
index 489271b..f8fa4ba 100644
--- a/drivers/gpio/sandbox.c
+++ b/drivers/gpio/sandbox.c
@@ -294,7 +294,7 @@
 {
 	struct gpio_dev_priv *uc_priv = dev_get_uclass_priv(dev);
 
-	if (!dev_of_valid(dev))
+	if (!dev_has_ofnode(dev))
 		/* Tell the uclass how many GPIOs we have */
 		uc_priv->gpio_count = CONFIG_SANDBOX_GPIO_COUNT;
 
diff --git a/drivers/i2c/designware_i2c_pci.c b/drivers/i2c/designware_i2c_pci.c
index 18eef62..ec0cdf6 100644
--- a/drivers/i2c/designware_i2c_pci.c
+++ b/drivers/i2c/designware_i2c_pci.c
@@ -92,7 +92,7 @@
 {
 	char name[20];
 
-	if (dev_of_valid(dev))
+	if (dev_has_ofnode(dev))
 		return 0;
 
 	sprintf(name, "i2c_designware#%u", dev_seq(dev));
@@ -152,7 +152,7 @@
 	int ret;
 
 	/* If no device-tree node, ignore this since we assume it isn't used */
-	if (!dev_of_valid(dev))
+	if (!dev_has_ofnode(dev))
 		return 0;
 
 	ret = acpi_device_path(dev, path, sizeof(path));
diff --git a/drivers/i2c/i2c-uclass.c b/drivers/i2c/i2c-uclass.c
index 456cf3b..be56785 100644
--- a/drivers/i2c/i2c-uclass.c
+++ b/drivers/i2c/i2c-uclass.c
@@ -678,7 +678,7 @@
 #if CONFIG_IS_ENABLED(OF_CONTROL) && !CONFIG_IS_ENABLED(OF_PLATDATA)
 	struct dm_i2c_chip *plat = dev_get_parent_plat(dev);
 
-	if (!dev_of_valid(dev))
+	if (!dev_has_ofnode(dev))
 		return 0;
 	return i2c_chip_of_to_plat(dev, plat);
 #else
diff --git a/drivers/mmc/pci_mmc.c b/drivers/mmc/pci_mmc.c
index fc09ad9..c71c495 100644
--- a/drivers/mmc/pci_mmc.c
+++ b/drivers/mmc/pci_mmc.c
@@ -75,7 +75,7 @@
 	struct acpi_dp *dp;
 	int ret;
 
-	if (!dev_of_valid(dev))
+	if (!dev_has_ofnode(dev))
 		return 0;
 
 	ret = gpio_get_acpi(&priv->cd_gpio, &gpio);
diff --git a/drivers/pci/pci-uclass.c b/drivers/pci/pci-uclass.c
index 1f6c51f..4cdd06b 100644
--- a/drivers/pci/pci-uclass.c
+++ b/drivers/pci/pci-uclass.c
@@ -540,7 +540,7 @@
 		int ret;
 
 		debug("%s: device %s\n", __func__, dev->name);
-		if (dev_of_valid(dev) &&
+		if (dev_has_ofnode(dev) &&
 		    dev_read_bool(dev, "pci,no-autoconfig"))
 			continue;
 		ret = dm_pciauto_config_device(dev);
@@ -1036,7 +1036,7 @@
 	hose->bus = bus;
 	hose->first_busno = dev_seq(bus);
 	hose->last_busno = dev_seq(bus);
-	if (dev_of_valid(bus)) {
+	if (dev_has_ofnode(bus)) {
 		hose->skip_auto_config_until_reloc =
 			dev_read_bool(bus,
 				      "u-boot,skip-auto-config-until-reloc");
@@ -1091,7 +1091,7 @@
 {
 	struct pci_child_plat *pplat;
 
-	if (!dev_of_valid(dev))
+	if (!dev_has_ofnode(dev))
 		return 0;
 
 	pplat = dev_get_parent_plat(dev);
diff --git a/drivers/pinctrl/pinctrl-uclass.c b/drivers/pinctrl/pinctrl-uclass.c
index 4653e86..7919e54 100644
--- a/drivers/pinctrl/pinctrl-uclass.c
+++ b/drivers/pinctrl/pinctrl-uclass.c
@@ -112,7 +112,7 @@
 	ofnode node;
 	int ret;
 
-	if (!dev_of_valid(dev))
+	if (!dev_has_ofnode(dev))
 		return 0;
 
 	dev_for_each_subnode(node, dev) {
diff --git a/drivers/spi/spi-uclass.c b/drivers/spi/spi-uclass.c
index a392a93..ba325cf 100644
--- a/drivers/spi/spi-uclass.c
+++ b/drivers/spi/spi-uclass.c
@@ -160,7 +160,7 @@
 {
 	struct dm_spi_slave_plat *plat = dev_get_parent_plat(dev);
 
-	if (!dev_of_valid(dev))
+	if (!dev_has_ofnode(dev))
 		return 0;
 
 	return spi_slave_of_to_plat(dev, plat);
diff --git a/drivers/sysreset/sysreset_sandbox.c b/drivers/sysreset/sysreset_sandbox.c
index 7026a48..8eca7d8 100644
--- a/drivers/sysreset/sysreset_sandbox.c
+++ b/drivers/sysreset/sysreset_sandbox.c
@@ -50,7 +50,7 @@
 	 * (see the U_BOOT_DEVICE() declaration below) should not do anything.
 	 * If we are that device, return an error.
 	 */
-	if (state->fdt_fname && !dev_of_valid(dev))
+	if (state->fdt_fname && !dev_has_ofnode(dev))
 		return -ENODEV;
 
 	switch (type) {
diff --git a/drivers/timer/timer-uclass.c b/drivers/timer/timer-uclass.c
index 8e63c17..da1a72f 100644
--- a/drivers/timer/timer-uclass.c
+++ b/drivers/timer/timer-uclass.c
@@ -54,7 +54,7 @@
 	ulong ret;
 
 	/* It is possible that a timer device has a null ofnode */
-	if (!dev_of_valid(dev))
+	if (!dev_has_ofnode(dev))
 		return 0;
 
 	err = clk_get_by_index(dev, 0, &timer_clk);
diff --git a/drivers/usb/host/usb-uclass.c b/drivers/usb/host/usb-uclass.c
index ae6b145..e3b616c 100644
--- a/drivers/usb/host/usb-uclass.c
+++ b/drivers/usb/host/usb-uclass.c
@@ -773,7 +773,7 @@
 	struct usb_dev_plat *plat = dev_get_parent_plat(dev);
 	int val;
 
-	if (!dev_of_valid(dev))
+	if (!dev_has_ofnode(dev))
 		return 0;
 
 	/* We only support matching a few things */
diff --git a/include/dm/device.h b/include/dm/device.h
index b15a14e..4a1224b 100644
--- a/include/dm/device.h
+++ b/include/dm/device.h
@@ -192,6 +192,17 @@
 	dev->flags_ &= ~bic;
 }
 
+/**
+ * dev_ofnode() - get the DT node reference associated with a udevice
+ *
+ * @dev:	device to check
+ * @return reference of the the device's DT node
+ */
+static inline ofnode dev_ofnode(const struct udevice *dev)
+{
+	return dev->node;
+}
+
 /* Returns non-zero if the device is active (probed and not removed) */
 #define device_active(dev)	(dev_get_flags(dev) & DM_FLAG_ACTIVATED)
 
@@ -200,7 +211,7 @@
 	return ofnode_to_offset(dev->node);
 }
 
-static inline bool dev_has_ofnode(struct udevice *dev)
+static inline bool dev_has_ofnode(const struct udevice *dev)
 {
 	return ofnode_valid(dev->node);
 }
diff --git a/include/dm/read.h b/include/dm/read.h
index 0585eb1..d5cdd87 100644
--- a/include/dm/read.h
+++ b/include/dm/read.h
@@ -30,22 +30,6 @@
 }
 #endif
 
-/**
- * dev_ofnode() - get the DT node reference associated with a udevice
- *
- * @dev:	device to check
- * @return reference of the the device's DT node
- */
-static inline ofnode dev_ofnode(const struct udevice *dev)
-{
-	return dev->node;
-}
-
-static inline bool dev_of_valid(const struct udevice *dev)
-{
-	return ofnode_valid(dev_ofnode(dev));
-}
-
 #ifndef CONFIG_DM_DEV_READ_INLINE
 
 /**
diff --git a/test/dm/pci.c b/test/dm/pci.c
index 76490be..fa2e4a8 100644
--- a/test/dm/pci.c
+++ b/test/dm/pci.c
@@ -120,13 +120,13 @@
 
 	ut_assertok(dm_pci_bus_find_bdf(PCI_BDF(1, 0x08, 0), &swap));
 	ut_asserteq(SWAP_CASE_DRV_DATA, swap->driver_data);
-	ut_assertok(dev_of_valid(swap));
+	ut_assertok(dev_has_ofnode(swap));
 	ut_assertok(dm_pci_bus_find_bdf(PCI_BDF(1, 0x0c, 0), &swap));
 	ut_asserteq(SWAP_CASE_DRV_DATA, swap->driver_data);
-	ut_assertok(dev_of_valid(swap));
+	ut_assertok(dev_has_ofnode(swap));
 	ut_assertok(dm_pci_bus_find_bdf(PCI_BDF(1, 0x10, 0), &swap));
 	ut_asserteq(SWAP_CASE_DRV_DATA, swap->driver_data);
-	ut_assertok(!dev_of_valid(swap));
+	ut_assertok(!dev_has_ofnode(swap));
 
 	return 0;
 }