OSDN Git Service

device property: Unify access to of_node
authorAndy Shevchenko <andriy.shevchenko@linux.intel.com>
Fri, 4 Jun 2021 16:50:47 +0000 (19:50 +0300)
committerRafael J. Wysocki <rafael.j.wysocki@intel.com>
Mon, 7 Jun 2021 12:43:41 +0000 (14:43 +0200)
Historically we have a few variants how we access dev->fwnode
and dev->of_node. Some of the functions during development
gained different versions of the getters. Unify access to of_node
and as a side change slightly refactor ACPI specific branches.

Signed-off-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
Signed-off-by: Rafael J. Wysocki <rafael.j.wysocki@intel.com>
drivers/base/property.c
include/linux/property.h

index dd98759..1f533b3 100644 (file)
@@ -759,13 +759,8 @@ EXPORT_SYMBOL_GPL(fwnode_get_next_available_child_node);
 struct fwnode_handle *device_get_next_child_node(struct device *dev,
                                                 struct fwnode_handle *child)
 {
-       struct acpi_device *adev = ACPI_COMPANION(dev);
-       struct fwnode_handle *fwnode = NULL, *next;
-
-       if (dev->of_node)
-               fwnode = of_fwnode_handle(dev->of_node);
-       else if (adev)
-               fwnode = acpi_fwnode_handle(adev);
+       const struct fwnode_handle *fwnode = dev_fwnode(dev);
+       struct fwnode_handle *next;
 
        /* Try to find a child in primary fwnode */
        next = fwnode_get_next_child_node(fwnode, child);
@@ -868,28 +863,31 @@ EXPORT_SYMBOL_GPL(device_get_child_node_count);
 
 bool device_dma_supported(struct device *dev)
 {
+       const struct fwnode_handle *fwnode = dev_fwnode(dev);
+
        /* For DT, this is always supported.
         * For ACPI, this depends on CCA, which
         * is determined by the acpi_dma_supported().
         */
-       if (IS_ENABLED(CONFIG_OF) && dev->of_node)
+       if (is_of_node(fwnode))
                return true;
 
-       return acpi_dma_supported(ACPI_COMPANION(dev));
+       return acpi_dma_supported(to_acpi_device_node(fwnode));
 }
 EXPORT_SYMBOL_GPL(device_dma_supported);
 
 enum dev_dma_attr device_get_dma_attr(struct device *dev)
 {
+       const struct fwnode_handle *fwnode = dev_fwnode(dev);
        enum dev_dma_attr attr = DEV_DMA_NOT_SUPPORTED;
 
-       if (IS_ENABLED(CONFIG_OF) && dev->of_node) {
-               if (of_dma_is_coherent(dev->of_node))
+       if (is_of_node(fwnode)) {
+               if (of_dma_is_coherent(to_of_node(fwnode)))
                        attr = DEV_DMA_COHERENT;
                else
                        attr = DEV_DMA_NON_COHERENT;
        } else
-               attr = acpi_get_dma_attr(ACPI_COMPANION(dev));
+               attr = acpi_get_dma_attr(to_acpi_device_node(fwnode));
 
        return attr;
 }
@@ -1007,14 +1005,13 @@ EXPORT_SYMBOL(device_get_mac_address);
  * Returns Linux IRQ number on success. Other values are determined
  * accordingly to acpi_/of_ irq_get() operation.
  */
-int fwnode_irq_get(struct fwnode_handle *fwnode, unsigned int index)
+int fwnode_irq_get(const struct fwnode_handle *fwnode, unsigned int index)
 {
-       struct device_node *of_node = to_of_node(fwnode);
        struct resource res;
        int ret;
 
-       if (IS_ENABLED(CONFIG_OF) && of_node)
-               return of_irq_get(of_node, index);
+       if (is_of_node(fwnode))
+               return of_irq_get(to_of_node(fwnode), index);
 
        ret = acpi_irq_get(ACPI_HANDLE_FWNODE(fwnode), index, &res);
        if (ret)
index 0d87631..073e680 100644 (file)
@@ -119,7 +119,7 @@ struct fwnode_handle *device_get_named_child_node(struct device *dev,
 struct fwnode_handle *fwnode_handle_get(struct fwnode_handle *fwnode);
 void fwnode_handle_put(struct fwnode_handle *fwnode);
 
-int fwnode_irq_get(struct fwnode_handle *fwnode, unsigned int index);
+int fwnode_irq_get(const struct fwnode_handle *fwnode, unsigned int index);
 
 unsigned int device_get_child_node_count(struct device *dev);