plat/stm32: Implement fdt_read_uint32_default() as a wrapper

The STM32 platform code uses its own set of FDT helper functions,
although some of them are fairly generic.

Remove the implementation of fdt_read_uint32_default() and implement it
on top of the newly introduced fdt_read_uint32() function, then convert
all users over.

This also fixes two callers, which were slightly abusing the "default"
semantic.

Change-Id: I570533362b4846e58dd797a92347de3e0e5abb75
Signed-off-by: Andre Przywara <andre.przywara@arm.com>
This commit is contained in:
Andre Przywara 2020-03-26 11:50:33 +00:00
parent ff4e6c35c9
commit be858cffa9
7 changed files with 28 additions and 31 deletions

View File

@ -56,6 +56,19 @@ int fdt_read_uint32(const void *dtb, int node, const char *prop_name,
return fdt_read_uint32_array(dtb, node, prop_name, 1, value);
}
uint32_t fdt_read_uint32_default(const void *dtb, int node,
const char *prop_name, uint32_t dflt_value)
{
uint32_t ret = dflt_value;
int err = fdt_read_uint32(dtb, node, prop_name, &ret);
if (err < 0) {
return dflt_value;
}
return ret;
}
int fdt_read_uint64(const void *dtb, int node, const char *prop_name,
uint64_t *value)
{

View File

@ -1240,7 +1240,8 @@ static bool stm32mp1_check_pll_conf(enum stm32mp1_pll_id pll_id,
uintptr_t clksrc_address = rcc_base + (clksrc >> 4);
unsigned long refclk;
uint32_t ifrge = 0U;
uint32_t src, value, fracv;
uint32_t src, value, fracv = 0;
void *fdt;
/* Check PLL output */
if (mmio_read_32(pllxcr) != RCC_PLLNCR_PLLON) {
@ -1279,7 +1280,9 @@ static bool stm32mp1_check_pll_conf(enum stm32mp1_pll_id pll_id,
}
/* Fractional configuration */
fracv = fdt_read_uint32_default(plloff, "frac", 0);
if (fdt_get_address(&fdt) == 1) {
fracv = fdt_read_uint32_default(fdt, plloff, "frac", 0);
}
value = fracv << RCC_PLLNFRACR_FRACV_SHIFT;
value |= RCC_PLLNFRACR_FRACLE;
@ -1800,7 +1803,7 @@ int stm32mp1_clk_init(void)
continue;
}
fracv = fdt_read_uint32_default(plloff[i], "frac", 0);
fracv = fdt_read_uint32_default(fdt, plloff[i], "frac", 0);
ret = stm32mp1_pll_config(i, pllcfg[i], fracv);
if (ret != 0) {

View File

@ -151,7 +151,8 @@ uint32_t fdt_osc_read_uint32_default(enum stm32mp_osc_id osc_id,
continue;
}
return fdt_read_uint32_default(subnode, prop_name, dflt_value);
return fdt_read_uint32_default(fdt, subnode, prop_name,
dflt_value);
}
return dflt_value;

View File

@ -206,13 +206,13 @@ static int stm32mp1_ddr_setup(void)
return -EINVAL;
}
config.info.speed = fdt_read_uint32_default(node, "st,mem-speed", 0);
if (!config.info.speed) {
ret = fdt_read_uint32(fdt, node, "st,mem-speed", &config.info.speed);
if (ret < 0) {
VERBOSE("%s: no st,mem-speed\n", __func__);
return -EINVAL;
}
config.info.size = fdt_read_uint32_default(node, "st,mem-size", 0);
if (!config.info.size) {
ret = fdt_read_uint32(fdt, node, "st,mem-size", &config.info.size);
if (ret < 0) {
VERBOSE("%s: no st,mem-size\n", __func__);
return -EINVAL;
}

View File

@ -14,6 +14,8 @@
int fdt_read_uint32(const void *dtb, int node, const char *prop_name,
uint32_t *value);
uint32_t fdt_read_uint32_default(const void *dtb, int node,
const char *prop_name, uint32_t dflt_value);
int fdt_read_uint64(const void *dtb, int node, const char *prop_name,
uint64_t *value);
int fdt_read_uint32_array(const void *dtb, int node, const char *prop_name,

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);
uint32_t fdt_read_uint32_default(int node, const char *prop_name,
uint32_t dflt_value);
int fdt_get_reg_props_by_name(int node, const char *name, uintptr_t *base,
size_t *size);
int dt_set_stdout_pinctrl(void);

View File

@ -135,26 +135,6 @@ static int fdt_get_node_parent_size_cells(int node)
}
#endif
/*******************************************************************************
* This function reads a value of a node property (generic use of fdt
* library).
* Returns value if success, and a default value if property not found.
* Default value is passed as parameter.
******************************************************************************/
uint32_t fdt_read_uint32_default(int node, const char *prop_name,
uint32_t dflt_value)
{
const fdt32_t *cuint;
int lenp;
cuint = fdt_getprop(fdt, node, prop_name, &lenp);
if (cuint == NULL) {
return dflt_value;
}
return fdt32_to_cpu(*cuint);
}
/*******************************************************************************
* This function fills reg node info (base & size) with an index found by
* checking the reg-names node.
@ -343,7 +323,7 @@ uint32_t dt_get_ddr_size(void)
return 0;
}
return fdt_read_uint32_default(node, "st,mem-size", 0);
return fdt_read_uint32_default(fdt, node, "st,mem-size", 0);
}
/*******************************************************************************