dm: core: Use dev_has_ofnode() instead of dev_of_valid()
authorSimon Glass <sjg@chromium.org>
Sat, 19 Dec 2020 17:40:13 +0000 (10:40 -0700)
committerSimon Glass <sjg@chromium.org>
Tue, 5 Jan 2021 19:24:41 +0000 (12:24 -0700)
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>
15 files changed:
drivers/clk/clk-uclass.c
drivers/core/device.c
drivers/gpio/sandbox.c
drivers/i2c/designware_i2c_pci.c
drivers/i2c/i2c-uclass.c
drivers/mmc/pci_mmc.c
drivers/pci/pci-uclass.c
drivers/pinctrl/pinctrl-uclass.c
drivers/spi/spi-uclass.c
drivers/sysreset/sysreset_sandbox.c
drivers/timer/timer-uclass.c
drivers/usb/host/usb-uclass.c
include/dm/device.h
include/dm/read.h
test/dm/pci.c

index ac954a34d27ffd7a1c1cfbd34a1e0a4fbb4354ae..5cfd00ce7710440fe377abd5af2624ce74d4457c 100644 (file)
@@ -345,7 +345,7 @@ int clk_set_defaults(struct udevice *dev, int stage)
 {
        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. */
index 8c7ce220f84dfd76623d394ab3eee85430e4a137..bd4ecc9e24dab0033216b2d9380c5795346ffaf2 100644 (file)
@@ -485,7 +485,7 @@ int device_probe(struct udevice *dev)
        }
 
        /* 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
index 489271b560e7a69a5ca081e358664752fe209d9e..f8fa4baa2c30b24a29ba643fd7425d48257571da 100644 (file)
@@ -294,7 +294,7 @@ static int gpio_sandbox_probe(struct udevice *dev)
 {
        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;
 
index 18eef625f0f2faf7fd8c11b63455aff2b1529555..ec0cdf622076e84c11b9db7ee295ffc355963240 100644 (file)
@@ -92,7 +92,7 @@ static int designware_i2c_pci_bind(struct udevice *dev)
 {
        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 @@ static int dw_i2c_acpi_fill_ssdt(const struct udevice *dev,
        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));
index 456cf3b85fb2800fb5d6bafa1e334a98d47461bf..be56785217c3bc51d7da1e7647a845034f2b05eb 100644 (file)
@@ -678,7 +678,7 @@ static int i2c_child_post_bind(struct udevice *dev)
 #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
index fc09ad99e5ead95002d3889808b603e7fb54df76..c71c495d581f2ac6bc7ea4dd597e9c2748a6898d 100644 (file)
@@ -75,7 +75,7 @@ static int pci_mmc_acpi_fill_ssdt(const struct udevice *dev,
        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);
index 1f6c51f1e8db0a160d34233b35118ba202591710..4cdd06b1257d00ccee3727b88c18c33daf5ed52f 100644 (file)
@@ -540,7 +540,7 @@ int pci_auto_config_devices(struct udevice *bus)
                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 @@ static int pci_uclass_pre_probe(struct udevice *bus)
        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 @@ static int pci_uclass_child_post_bind(struct udevice *dev)
 {
        struct pci_child_plat *pplat;
 
-       if (!dev_of_valid(dev))
+       if (!dev_has_ofnode(dev))
                return 0;
 
        pplat = dev_get_parent_plat(dev);
index 4653e86ba46accb908a5d00eebdc949d8ecd803f..7919e54e8de8d72323f137821e7f41186df65324 100644 (file)
@@ -112,7 +112,7 @@ static int pinconfig_post_bind(struct udevice *dev)
        ofnode node;
        int ret;
 
-       if (!dev_of_valid(dev))
+       if (!dev_has_ofnode(dev))
                return 0;
 
        dev_for_each_subnode(node, dev) {
index a392a93aa1b320dbcd50cbc0a3e06d42c724ce66..ba325cf4e0d91340d48755c58047fc5d1e338bc2 100644 (file)
@@ -160,7 +160,7 @@ static int spi_child_post_bind(struct udevice *dev)
 {
        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);
index 7026a48c4b23be7e1ceff7721211775debd52177..8eca7d8bfda4ec186493754cb107000bc8b2e705 100644 (file)
@@ -50,7 +50,7 @@ static int sandbox_sysreset_request(struct udevice *dev, enum sysreset_t type)
         * (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) {
index 8e63c17e9f3bf76ed127aec3f4da76ecf408e44e..da1a72f0252bb8a0ca5cac54a064c9c995c7db5b 100644 (file)
@@ -54,7 +54,7 @@ static int timer_pre_probe(struct udevice *dev)
        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);
index ae6b1450d3a67010fe0024977b83d73c18f9ea61..e3b616c3266ae7ffa6c4843bd09a9c027aefdb17 100644 (file)
@@ -773,7 +773,7 @@ static int usb_child_post_bind(struct udevice *dev)
        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 */
index b15a14ec33070bb6ce35013fd17b6254471e0de9..4a1224bcc26bc94b0c1c608017cbca2caed803df 100644 (file)
@@ -192,6 +192,17 @@ static inline void dev_bic_flags(struct udevice *dev, u32 bic)
        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 @@ static inline int dev_of_offset(const struct udevice *dev)
        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);
 }
index 0585eb12281c792761404885728f891fb18a816e..d5cdd87911d73a949eaeea1fde628697a08d5a82 100644 (file)
@@ -30,22 +30,6 @@ static inline const struct device_node *dev_np(const struct udevice *dev)
 }
 #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
 
 /**
index 76490befdf50d0c0a61e3a8f2ec6d16e99b13993..fa2e4a85596c61c55011b7fd65f6d83e9e315f46 100644 (file)
@@ -120,13 +120,13 @@ static int dm_test_pci_drvdata(struct unit_test_state *uts)
 
        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;
 }