mirror of
https://github.com/Fishwaldo/u-boot.git
synced 2025-03-21 22:51:37 +00:00
dm: core: Add a new api to get indexed device address
Add new api to get device address based on index. Signed-off-by: Mugunthan V N <mugunthanvnm@ti.com> Acked-by: Jagan Teki <jteki@openedev.com> [Rebased on master] Signed-off-by: Jagan Teki <jteki@openedev.com>
This commit is contained in:
parent
425846ed8f
commit
69b41388ba
2 changed files with 38 additions and 4 deletions
|
@ -581,17 +581,35 @@ const char *dev_get_uclass_name(struct udevice *dev)
|
||||||
return dev->uclass->uc_drv->name;
|
return dev->uclass->uc_drv->name;
|
||||||
}
|
}
|
||||||
|
|
||||||
fdt_addr_t dev_get_addr(struct udevice *dev)
|
fdt_addr_t dev_get_addr_index(struct udevice *dev, int index)
|
||||||
{
|
{
|
||||||
#if CONFIG_IS_ENABLED(OF_CONTROL)
|
#if CONFIG_IS_ENABLED(OF_CONTROL)
|
||||||
fdt_addr_t addr;
|
fdt_addr_t addr;
|
||||||
|
|
||||||
if (CONFIG_IS_ENABLED(OF_TRANSLATE)) {
|
if (CONFIG_IS_ENABLED(OF_TRANSLATE)) {
|
||||||
const fdt32_t *reg;
|
const fdt32_t *reg;
|
||||||
|
int len = 0;
|
||||||
|
int na, ns;
|
||||||
|
|
||||||
reg = fdt_getprop(gd->fdt_blob, dev->of_offset, "reg", NULL);
|
na = fdt_address_cells(gd->fdt_blob, dev->parent->of_offset);
|
||||||
if (!reg)
|
if (na < 1) {
|
||||||
|
debug("bad #address-cells\n");
|
||||||
return FDT_ADDR_T_NONE;
|
return FDT_ADDR_T_NONE;
|
||||||
|
}
|
||||||
|
|
||||||
|
ns = fdt_size_cells(gd->fdt_blob, dev->parent->of_offset);
|
||||||
|
if (ns < 0) {
|
||||||
|
debug("bad #size-cells\n");
|
||||||
|
return FDT_ADDR_T_NONE;
|
||||||
|
}
|
||||||
|
|
||||||
|
reg = fdt_getprop(gd->fdt_blob, dev->of_offset, "reg", &len);
|
||||||
|
if (!reg || (len <= (index * sizeof(fdt32_t) * (na + ns)))) {
|
||||||
|
debug("Req index out of range\n");
|
||||||
|
return FDT_ADDR_T_NONE;
|
||||||
|
}
|
||||||
|
|
||||||
|
reg += index * (na + ns);
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Use the full-fledged translate function for complex
|
* Use the full-fledged translate function for complex
|
||||||
|
@ -607,7 +625,7 @@ fdt_addr_t dev_get_addr(struct udevice *dev)
|
||||||
addr = fdtdec_get_addr_size_auto_parent(gd->fdt_blob,
|
addr = fdtdec_get_addr_size_auto_parent(gd->fdt_blob,
|
||||||
dev->parent->of_offset,
|
dev->parent->of_offset,
|
||||||
dev->of_offset, "reg",
|
dev->of_offset, "reg",
|
||||||
0, NULL);
|
index, NULL);
|
||||||
if (CONFIG_IS_ENABLED(SIMPLE_BUS) && addr != FDT_ADDR_T_NONE) {
|
if (CONFIG_IS_ENABLED(SIMPLE_BUS) && addr != FDT_ADDR_T_NONE) {
|
||||||
if (device_get_uclass_id(dev->parent) ==
|
if (device_get_uclass_id(dev->parent) ==
|
||||||
UCLASS_SIMPLE_BUS)
|
UCLASS_SIMPLE_BUS)
|
||||||
|
@ -629,6 +647,11 @@ fdt_addr_t dev_get_addr(struct udevice *dev)
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fdt_addr_t dev_get_addr(struct udevice *dev)
|
||||||
|
{
|
||||||
|
return dev_get_addr_index(dev, 0);
|
||||||
|
}
|
||||||
|
|
||||||
bool device_has_children(struct udevice *dev)
|
bool device_has_children(struct udevice *dev)
|
||||||
{
|
{
|
||||||
return !list_empty(&dev->child_head);
|
return !list_empty(&dev->child_head);
|
||||||
|
|
|
@ -453,6 +453,17 @@ int device_find_next_child(struct udevice **devp);
|
||||||
*/
|
*/
|
||||||
fdt_addr_t dev_get_addr(struct udevice *dev);
|
fdt_addr_t dev_get_addr(struct udevice *dev);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* dev_get_addr_index() - Get the indexed reg property of a device
|
||||||
|
*
|
||||||
|
* @dev: Pointer to a device
|
||||||
|
* @index: the 'reg' property can hold a list of <addr, size> pairs
|
||||||
|
* and @index is used to select which one is required
|
||||||
|
*
|
||||||
|
* @return addr
|
||||||
|
*/
|
||||||
|
fdt_addr_t dev_get_addr_index(struct udevice *dev, int index);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* device_has_children() - check if a device has any children
|
* device_has_children() - check if a device has any children
|
||||||
*
|
*
|
||||||
|
|
Loading…
Add table
Reference in a new issue