Skip to content

Commit fb38f31

Browse files
andy-shevrafaeljw
authored andcommitted
device property: Unify access to of_node
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 <[email protected]> Signed-off-by: Rafael J. Wysocki <[email protected]>
1 parent 3d7c821 commit fb38f31

File tree

2 files changed

+14
-17
lines changed

2 files changed

+14
-17
lines changed

drivers/base/property.c

Lines changed: 13 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -759,13 +759,8 @@ EXPORT_SYMBOL_GPL(fwnode_get_next_available_child_node);
759759
struct fwnode_handle *device_get_next_child_node(struct device *dev,
760760
struct fwnode_handle *child)
761761
{
762-
struct acpi_device *adev = ACPI_COMPANION(dev);
763-
struct fwnode_handle *fwnode = NULL, *next;
764-
765-
if (dev->of_node)
766-
fwnode = of_fwnode_handle(dev->of_node);
767-
else if (adev)
768-
fwnode = acpi_fwnode_handle(adev);
762+
const struct fwnode_handle *fwnode = dev_fwnode(dev);
763+
struct fwnode_handle *next;
769764

770765
/* Try to find a child in primary fwnode */
771766
next = fwnode_get_next_child_node(fwnode, child);
@@ -868,28 +863,31 @@ EXPORT_SYMBOL_GPL(device_get_child_node_count);
868863

869864
bool device_dma_supported(struct device *dev)
870865
{
866+
const struct fwnode_handle *fwnode = dev_fwnode(dev);
867+
871868
/* For DT, this is always supported.
872869
* For ACPI, this depends on CCA, which
873870
* is determined by the acpi_dma_supported().
874871
*/
875-
if (IS_ENABLED(CONFIG_OF) && dev->of_node)
872+
if (is_of_node(fwnode))
876873
return true;
877874

878-
return acpi_dma_supported(ACPI_COMPANION(dev));
875+
return acpi_dma_supported(to_acpi_device_node(fwnode));
879876
}
880877
EXPORT_SYMBOL_GPL(device_dma_supported);
881878

882879
enum dev_dma_attr device_get_dma_attr(struct device *dev)
883880
{
881+
const struct fwnode_handle *fwnode = dev_fwnode(dev);
884882
enum dev_dma_attr attr = DEV_DMA_NOT_SUPPORTED;
885883

886-
if (IS_ENABLED(CONFIG_OF) && dev->of_node) {
887-
if (of_dma_is_coherent(dev->of_node))
884+
if (is_of_node(fwnode)) {
885+
if (of_dma_is_coherent(to_of_node(fwnode)))
888886
attr = DEV_DMA_COHERENT;
889887
else
890888
attr = DEV_DMA_NON_COHERENT;
891889
} else
892-
attr = acpi_get_dma_attr(ACPI_COMPANION(dev));
890+
attr = acpi_get_dma_attr(to_acpi_device_node(fwnode));
893891

894892
return attr;
895893
}
@@ -1007,14 +1005,13 @@ EXPORT_SYMBOL(device_get_mac_address);
10071005
* Returns Linux IRQ number on success. Other values are determined
10081006
* accordingly to acpi_/of_ irq_get() operation.
10091007
*/
1010-
int fwnode_irq_get(struct fwnode_handle *fwnode, unsigned int index)
1008+
int fwnode_irq_get(const struct fwnode_handle *fwnode, unsigned int index)
10111009
{
1012-
struct device_node *of_node = to_of_node(fwnode);
10131010
struct resource res;
10141011
int ret;
10151012

1016-
if (IS_ENABLED(CONFIG_OF) && of_node)
1017-
return of_irq_get(of_node, index);
1013+
if (is_of_node(fwnode))
1014+
return of_irq_get(to_of_node(fwnode), index);
10181015

10191016
ret = acpi_irq_get(ACPI_HANDLE_FWNODE(fwnode), index, &res);
10201017
if (ret)

include/linux/property.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -119,7 +119,7 @@ struct fwnode_handle *device_get_named_child_node(struct device *dev,
119119
struct fwnode_handle *fwnode_handle_get(struct fwnode_handle *fwnode);
120120
void fwnode_handle_put(struct fwnode_handle *fwnode);
121121

122-
int fwnode_irq_get(struct fwnode_handle *fwnode, unsigned int index);
122+
int fwnode_irq_get(const struct fwnode_handle *fwnode, unsigned int index);
123123

124124
unsigned int device_get_child_node_count(struct device *dev);
125125

0 commit comments

Comments
 (0)