dm: core: add support for getting register address and size
Current dev_read_*() API lacks support to get address and size of a "reg" property by name or index. Add support for the same. Livetree support has been added but not tested on real hardware. The existing unit tests testing reading address from device-tree have been updated to test address as well as size. Reviewed-by: Lokesh Vutla <lokeshvutla@ti.com> Signed-off-by: Sekhar Nori <nsekhar@ti.com>
This commit is contained in:
parent
acbb7cd4d3
commit
f5b904796f
@ -129,6 +129,23 @@ fdt_addr_t devfdt_get_addr_name(struct udevice *dev, const char *name)
|
||||
#endif
|
||||
}
|
||||
|
||||
fdt_addr_t devfdt_get_addr_size_name(struct udevice *dev, const char *name,
|
||||
fdt_size_t *size)
|
||||
{
|
||||
#if CONFIG_IS_ENABLED(OF_CONTROL)
|
||||
int index;
|
||||
|
||||
index = fdt_stringlist_search(gd->fdt_blob, dev_of_offset(dev),
|
||||
"reg-names", name);
|
||||
if (index < 0)
|
||||
return index;
|
||||
|
||||
return devfdt_get_addr_size_index(dev, index, size);
|
||||
#else
|
||||
return FDT_ADDR_T_NONE;
|
||||
#endif
|
||||
}
|
||||
|
||||
fdt_addr_t devfdt_get_addr(struct udevice *dev)
|
||||
{
|
||||
return devfdt_get_addr_index(dev, 0);
|
||||
|
@ -82,6 +82,15 @@ fdt_addr_t dev_read_addr_index(struct udevice *dev, int index)
|
||||
return devfdt_get_addr_index(dev, index);
|
||||
}
|
||||
|
||||
fdt_addr_t dev_read_addr_size_index(struct udevice *dev, int index,
|
||||
fdt_size_t *size)
|
||||
{
|
||||
if (ofnode_is_np(dev_ofnode(dev)))
|
||||
return ofnode_get_addr_size_index(dev_ofnode(dev), index, size);
|
||||
else
|
||||
return devfdt_get_addr_size_index(dev, index, size);
|
||||
}
|
||||
|
||||
void *dev_remap_addr_index(struct udevice *dev, int index)
|
||||
{
|
||||
fdt_addr_t addr = dev_read_addr_index(dev, index);
|
||||
@ -102,6 +111,17 @@ fdt_addr_t dev_read_addr_name(struct udevice *dev, const char *name)
|
||||
return dev_read_addr_index(dev, index);
|
||||
}
|
||||
|
||||
fdt_addr_t dev_read_addr_size_name(struct udevice *dev, const char *name,
|
||||
fdt_size_t *size)
|
||||
{
|
||||
int index = dev_read_stringlist_search(dev, "reg-names", name);
|
||||
|
||||
if (index < 0)
|
||||
return FDT_ADDR_T_NONE;
|
||||
else
|
||||
return dev_read_addr_size_index(dev, index, size);
|
||||
}
|
||||
|
||||
void *dev_remap_addr_name(struct udevice *dev, const char *name)
|
||||
{
|
||||
fdt_addr_t addr = dev_read_addr_name(dev, name);
|
||||
|
@ -120,4 +120,22 @@ fdt_addr_t devfdt_get_addr_size_index(struct udevice *dev, int index,
|
||||
*/
|
||||
fdt_addr_t devfdt_get_addr_name(struct udevice *dev, const char *name);
|
||||
|
||||
/**
|
||||
* devfdt_get_addr_size_name() - Get the reg property and its size for a device,
|
||||
* indexed by name
|
||||
*
|
||||
* Returns the address and size specified in the 'reg' property of a device.
|
||||
*
|
||||
* @dev: Pointer to a device
|
||||
* @name: the 'reg' property can hold a list of <addr, size> pairs, with the
|
||||
* 'reg-names' property providing named-based identification. @index
|
||||
* indicates the value to search for in 'reg-names'.
|
||||
* @size: Pointer to size variable - this function returns the size
|
||||
* specified in the 'reg' property here
|
||||
*
|
||||
* @return addr
|
||||
*/
|
||||
fdt_addr_t devfdt_get_addr_size_name(struct udevice *dev, const char *name,
|
||||
fdt_size_t *size);
|
||||
|
||||
#endif
|
||||
|
@ -144,6 +144,19 @@ int dev_read_size(struct udevice *dev, const char *propname);
|
||||
*/
|
||||
fdt_addr_t dev_read_addr_index(struct udevice *dev, int index);
|
||||
|
||||
/**
|
||||
* dev_read_addr_size_index() - Get the indexed reg property of a device
|
||||
*
|
||||
* @dev: Device to read from
|
||||
* @index: the 'reg' property can hold a list of <addr, size> pairs
|
||||
* and @index is used to select which one is required
|
||||
* @size: place to put size value (on success)
|
||||
*
|
||||
* @return address or FDT_ADDR_T_NONE if not found
|
||||
*/
|
||||
fdt_addr_t dev_read_addr_size_index(struct udevice *dev, int index,
|
||||
fdt_size_t *size);
|
||||
|
||||
/**
|
||||
* dev_remap_addr_index() - Get the indexed reg property of a device
|
||||
* as a memory-mapped I/O pointer
|
||||
@ -168,6 +181,20 @@ void *dev_remap_addr_index(struct udevice *dev, int index);
|
||||
*/
|
||||
fdt_addr_t dev_read_addr_name(struct udevice *dev, const char* name);
|
||||
|
||||
/**
|
||||
* dev_read_addr_size_name() - Get the reg property of a device, indexed by name
|
||||
*
|
||||
* @dev: Device to read from
|
||||
* @name: the 'reg' property can hold a list of <addr, size> pairs, with the
|
||||
* 'reg-names' property providing named-based identification. @index
|
||||
* indicates the value to search for in 'reg-names'.
|
||||
* @size: place to put size value (on success)
|
||||
*
|
||||
* @return address or FDT_ADDR_T_NONE if not found
|
||||
*/
|
||||
fdt_addr_t dev_read_addr_size_name(struct udevice *dev, const char *name,
|
||||
fdt_size_t *size);
|
||||
|
||||
/**
|
||||
* dev_remap_addr_name() - Get the reg property of a device, indexed by name,
|
||||
* as a memory-mapped I/O pointer
|
||||
@ -601,12 +628,26 @@ static inline fdt_addr_t dev_read_addr_index(struct udevice *dev, int index)
|
||||
return devfdt_get_addr_index(dev, index);
|
||||
}
|
||||
|
||||
static inline fdt_addr_t dev_read_addr_size_index(struct udevice *dev,
|
||||
int index,
|
||||
fdt_size_t *size)
|
||||
{
|
||||
return devfdt_get_addr_size_index(dev, index, size);
|
||||
}
|
||||
|
||||
static inline fdt_addr_t dev_read_addr_name(struct udevice *dev,
|
||||
const char *name)
|
||||
{
|
||||
return devfdt_get_addr_name(dev, name);
|
||||
}
|
||||
|
||||
static inline fdt_addr_t dev_read_addr_size_name(struct udevice *dev,
|
||||
const char *name,
|
||||
fdt_size_t *size)
|
||||
{
|
||||
return devfdt_get_addr_size_name(dev, name, size);
|
||||
}
|
||||
|
||||
static inline fdt_addr_t dev_read_addr(struct udevice *dev)
|
||||
{
|
||||
return devfdt_get_addr(dev);
|
||||
|
@ -549,12 +549,14 @@ static int dm_test_fdt_remap_addr_index_flat(struct unit_test_state *uts)
|
||||
{
|
||||
struct udevice *dev;
|
||||
fdt_addr_t addr;
|
||||
fdt_size_t size;
|
||||
void *paddr;
|
||||
|
||||
ut_assertok(uclass_find_device_by_seq(UCLASS_TEST_DUMMY, 0, true, &dev));
|
||||
|
||||
addr = devfdt_get_addr_index(dev, 0);
|
||||
addr = devfdt_get_addr_size_index(dev, 0, &size);
|
||||
ut_asserteq(0x8000, addr);
|
||||
ut_asserteq(0x1000, size);
|
||||
|
||||
paddr = map_physmem(addr, 0, MAP_NOCACHE);
|
||||
ut_assertnonnull(paddr);
|
||||
@ -569,12 +571,14 @@ static int dm_test_fdt_remap_addr_name_flat(struct unit_test_state *uts)
|
||||
{
|
||||
struct udevice *dev;
|
||||
fdt_addr_t addr;
|
||||
fdt_size_t size;
|
||||
void *paddr;
|
||||
|
||||
ut_assertok(uclass_find_device_by_seq(UCLASS_TEST_DUMMY, 0, true, &dev));
|
||||
|
||||
addr = devfdt_get_addr_name(dev, "sandbox-dummy-0");
|
||||
addr = devfdt_get_addr_size_name(dev, "sandbox-dummy-0", &size);
|
||||
ut_asserteq(0x8000, addr);
|
||||
ut_asserteq(0x1000, size);
|
||||
|
||||
paddr = map_physmem(addr, 0, MAP_NOCACHE);
|
||||
ut_assertnonnull(paddr);
|
||||
@ -609,12 +613,14 @@ static int dm_test_fdt_remap_addr_index_live(struct unit_test_state *uts)
|
||||
{
|
||||
struct udevice *dev;
|
||||
fdt_addr_t addr;
|
||||
fdt_size_t size;
|
||||
void *paddr;
|
||||
|
||||
ut_assertok(uclass_find_device_by_seq(UCLASS_TEST_DUMMY, 0, true, &dev));
|
||||
|
||||
addr = dev_read_addr_index(dev, 0);
|
||||
addr = dev_read_addr_size_index(dev, 0, &size);
|
||||
ut_asserteq(0x8000, addr);
|
||||
ut_asserteq(0x1000, size);
|
||||
|
||||
paddr = map_physmem(addr, 0, MAP_NOCACHE);
|
||||
ut_assertnonnull(paddr);
|
||||
@ -629,12 +635,14 @@ static int dm_test_fdt_remap_addr_name_live(struct unit_test_state *uts)
|
||||
{
|
||||
struct udevice *dev;
|
||||
fdt_addr_t addr;
|
||||
fdt_size_t size;
|
||||
void *paddr;
|
||||
|
||||
ut_assertok(uclass_find_device_by_seq(UCLASS_TEST_DUMMY, 0, true, &dev));
|
||||
|
||||
addr = dev_read_addr_name(dev, "sandbox-dummy-0");
|
||||
addr = dev_read_addr_size_name(dev, "sandbox-dummy-0", &size);
|
||||
ut_asserteq(0x8000, addr);
|
||||
ut_asserteq(0x1000, size);
|
||||
|
||||
paddr = map_physmem(addr, 0, MAP_NOCACHE);
|
||||
ut_assertnonnull(paddr);
|
||||
|
Loading…
Reference in New Issue
Block a user