of/address: Add new API of_iomap_by_name and of_get_address_by_name

Create new API of_iomap_by_name and of_get_address_by_name, which
would read "reg-names" property and get the reg address by its
name.

Change-Id: I7ce30da5a7cbc29f8349641af97ac7ed16b4f506
Signed-off-by: Xiaocheng Li <lix@codeaurora.org>
[imaund@codeaurora.org: Resolved trivial context conflicts.]
Signed-off-by: Ian Maund <imaund@codeaurora.org>
This commit is contained in:
Xiaocheng Li 2014-10-22 09:20:06 +05:30 committed by Rohit Vaswani
parent 828516323c
commit 0a9312ff44
2 changed files with 36 additions and 0 deletions

View file

@ -788,6 +788,22 @@ unsigned long __weak pci_address_to_pio(phys_addr_t address)
#endif
}
const __be32 *of_get_address_by_name(struct device_node *dev, const char *name,
u64 *size, unsigned int *flags)
{
int index;
if (!name)
return NULL;
/* Try to read "reg-names" property and get the index by name */
index = of_property_match_string(dev, "reg-names", name);
if (index < 0)
return NULL;
return of_get_address(dev, index, size, flags);
}
EXPORT_SYMBOL(of_get_address_by_name);
static int __of_address_to_resource(struct device_node *dev,
const __be32 *addrp, u64 size, unsigned int flags,
const char *name, struct resource *r)
@ -1026,3 +1042,19 @@ bool of_dma_is_coherent(struct device_node *np)
return false;
}
EXPORT_SYMBOL_GPL(of_dma_is_coherent);
void __iomem *of_iomap_by_name(struct device_node *np, const char *name)
{
int index;
if (!name)
return NULL;
/* Try to read "reg-names" property and get the index by name */
index = of_property_match_string(np, "reg-names", name);
if (index < 0)
return NULL;
return of_iomap(np, index);
}
EXPORT_SYMBOL(of_iomap_by_name);

View file

@ -36,6 +36,8 @@ extern struct device_node *of_find_matching_node_by_address(
const struct of_device_id *matches,
u64 base_address);
extern void __iomem *of_iomap(struct device_node *device, int index);
extern void __iomem *of_iomap_by_name(struct device_node *device,
const char *name);
/* Extract an address from a device, returns the region size and
* the address space flags too. The PCI version uses a BAR number
@ -43,6 +45,8 @@ extern void __iomem *of_iomap(struct device_node *device, int index);
*/
extern const __be32 *of_get_address(struct device_node *dev, int index,
u64 *size, unsigned int *flags);
extern const __be32 *of_get_address_by_name(struct device_node *dev,
const char *name, u64 *size, unsigned int *flags);
extern int pci_register_io_range(phys_addr_t addr, resource_size_t size);
extern unsigned long pci_address_to_pio(phys_addr_t addr);