Skip to content

Commit 90e33f6

Browse files
committed
of/address: Add of_find_matching_node_by_address helper
of_find_matching_node_by_address() can be used to find a device tree node for a device at a specific address. Signed-off-by: Grant Likely <grant.likely@secretlab.ca>
1 parent 8c11642 commit 90e33f6

2 files changed

Lines changed: 22 additions & 0 deletions

File tree

‎drivers/of/address.c‎

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -577,6 +577,24 @@ int of_address_to_resource(struct device_node *dev, int index,
577577
}
578578
EXPORT_SYMBOL_GPL(of_address_to_resource);
579579

580+
struct device_node *of_find_matching_node_by_address(struct device_node *from,
581+
const struct of_device_id *matches,
582+
u64 base_address)
583+
{
584+
struct device_node *dn = of_find_matching_node(from, matches);
585+
struct resource res;
586+
587+
while (dn) {
588+
if (of_address_to_resource(dn, 0, &res))
589+
continue;
590+
if (res.start == base_address)
591+
return dn;
592+
dn = of_find_matching_node(dn, matches);
593+
}
594+
595+
return NULL;
596+
}
597+
580598

581599
/**
582600
* of_iomap - Maps the memory mapped IO for a given device_node

‎include/linux/of_address.h‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,10 @@
66
extern u64 of_translate_address(struct device_node *np, const __be32 *addr);
77
extern int of_address_to_resource(struct device_node *dev, int index,
88
struct resource *r);
9+
extern struct device_node *of_find_matching_node_by_address(
10+
struct device_node *from,
11+
const struct of_device_id *matches,
12+
u64 base_address);
913
extern void __iomem *of_iomap(struct device_node *device, int index);
1014

1115
/* Extract an address from a device, returns the region size and

0 commit comments

Comments
 (0)