plat/stm32: Use generic fdt_get_reg_props_by_name()

The STM32 platform port parse DT nodes to find base address to
peripherals. It does this by using its own implementation, even though
this functionality is generic and actually widely useful outside of the
STM32 code.

Re-implement fdt_get_reg_props_by_name() on top of the newly introduced
fdt_get_reg_props_by_index() function, and move it to fdt_wrapper.c.
This is removes the assumption that #address-cells and #size-cells are
always one.

Change-Id: I6d584930262c732b6e0356d98aea50b2654f789d
Signed-off-by: Andre Przywara <andre.przywara@arm.com>
This commit is contained in:
Andre Przywara 2020-03-26 12:11:34 +00:00
parent 658086747d
commit 7ad6d36201
7 changed files with 25 additions and 44 deletions

View File

@ -276,3 +276,21 @@ int fdt_get_reg_props_by_index(const void *dtb, int node, int index,
return 0;
}
/*******************************************************************************
* This function fills reg node info (base & size) with an index found by
* checking the reg-names node.
* Returns 0 on success and a negative FDT error code on failure.
******************************************************************************/
int fdt_get_reg_props_by_name(const void *dtb, int node, const char *name,
uintptr_t *base, size_t *size)
{
int index;
index = fdt_stringlist_search(dtb, node, "reg-names", name);
if (index < 0) {
return index;
}
return fdt_get_reg_props_by_index(dtb, node, index, base, size);
}

View File

@ -9,6 +9,7 @@
#include <platform_def.h>
#include <common/debug.h>
#include <common/fdt_wrappers.h>
#include <drivers/delay_timer.h>
#include <drivers/spi_mem.h>
#include <drivers/st/stm32_gpio.h>
@ -465,13 +466,13 @@ int stm32_qspi_init(void)
return -FDT_ERR_NOTFOUND;
}
ret = fdt_get_reg_props_by_name(qspi_node, "qspi",
ret = fdt_get_reg_props_by_name(fdt, qspi_node, "qspi",
&stm32_qspi.reg_base, &size);
if (ret != 0) {
return ret;
}
ret = fdt_get_reg_props_by_name(qspi_node, "qspi_mm",
ret = fdt_get_reg_props_by_name(fdt, qspi_node, "qspi_mm",
&stm32_qspi.mm_base,
&stm32_qspi.mm_size);
if (ret != 0) {

View File

@ -30,5 +30,7 @@ int fdtw_write_inplace_bytes(void *dtb, int node, const char *prop,
unsigned int length, const void *data);
int fdt_get_reg_props_by_index(const void *dtb, int node, int index,
uintptr_t *base, size_t *size);
int fdt_get_reg_props_by_name(const void *dtb, int node, const char *name,
uintptr_t *base, size_t *size);
#endif /* FDT_WRAPPERS_H */

View File

@ -28,6 +28,7 @@ fdt fdt_subnode_offset
fdt fdt_address_cells
fdt fdt_size_cells
fdt fdt_parent_offset
fdt fdt_stringlist_search
mbedtls mbedtls_asn1_get_alg
mbedtls mbedtls_asn1_get_alg_null
mbedtls mbedtls_asn1_get_bitstring_null

View File

@ -24,6 +24,7 @@ fdt fdt_setprop_inplace_namelen_partial
fdt fdt_first_subnode
fdt fdt_next_subnode
fdt fdt_parent_offset
fdt fdt_stringlist_search
mbedtls mbedtls_asn1_get_alg
mbedtls mbedtls_asn1_get_alg_null
mbedtls mbedtls_asn1_get_bitstring_null

View File

@ -28,8 +28,6 @@ int dt_open_and_check(void);
int fdt_get_address(void **fdt_addr);
bool fdt_check_node(int node);
uint8_t fdt_get_status(int node);
int fdt_get_reg_props_by_name(int node, const char *name, uintptr_t *base,
size_t *size);
int dt_set_stdout_pinctrl(void);
void dt_fill_device_info(struct dt_node_info *info, int node);
int dt_get_node(struct dt_node_info *info, int offset, const char *compat);

View File

@ -135,46 +135,6 @@ static int fdt_get_node_parent_size_cells(int node)
}
#endif
/*******************************************************************************
* This function fills reg node info (base & size) with an index found by
* checking the reg-names node.
* Returns 0 on success and a negative FDT error code on failure.
******************************************************************************/
int fdt_get_reg_props_by_name(int node, const char *name, uintptr_t *base,
size_t *size)
{
const fdt32_t *cuint;
int index, len;
assert((fdt_get_node_parent_address_cells(node) == 1) &&
(fdt_get_node_parent_size_cells(node) == 1));
index = fdt_stringlist_search(fdt, node, "reg-names", name);
if (index < 0) {
return index;
}
cuint = fdt_getprop(fdt, node, "reg", &len);
if (cuint == NULL) {
return -FDT_ERR_NOTFOUND;
}
if ((index * (int)sizeof(uint32_t)) > len) {
return -FDT_ERR_BADVALUE;
}
cuint += index << 1;
if (base != NULL) {
*base = fdt32_to_cpu(*cuint);
}
cuint++;
if (size != NULL) {
*size = fdt32_to_cpu(*cuint);
}
return 0;
}
/*******************************************************************************
* This function gets the stdout path node.
* It reads the value indicated inside the device tree.