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:
parent
ff4e6c35c9
commit
be858cffa9
|
@ -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);
|
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,
|
int fdt_read_uint64(const void *dtb, int node, const char *prop_name,
|
||||||
uint64_t *value)
|
uint64_t *value)
|
||||||
{
|
{
|
||||||
|
|
|
@ -1240,7 +1240,8 @@ static bool stm32mp1_check_pll_conf(enum stm32mp1_pll_id pll_id,
|
||||||
uintptr_t clksrc_address = rcc_base + (clksrc >> 4);
|
uintptr_t clksrc_address = rcc_base + (clksrc >> 4);
|
||||||
unsigned long refclk;
|
unsigned long refclk;
|
||||||
uint32_t ifrge = 0U;
|
uint32_t ifrge = 0U;
|
||||||
uint32_t src, value, fracv;
|
uint32_t src, value, fracv = 0;
|
||||||
|
void *fdt;
|
||||||
|
|
||||||
/* Check PLL output */
|
/* Check PLL output */
|
||||||
if (mmio_read_32(pllxcr) != RCC_PLLNCR_PLLON) {
|
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 */
|
/* 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 = fracv << RCC_PLLNFRACR_FRACV_SHIFT;
|
||||||
value |= RCC_PLLNFRACR_FRACLE;
|
value |= RCC_PLLNFRACR_FRACLE;
|
||||||
|
@ -1800,7 +1803,7 @@ int stm32mp1_clk_init(void)
|
||||||
continue;
|
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);
|
ret = stm32mp1_pll_config(i, pllcfg[i], fracv);
|
||||||
if (ret != 0) {
|
if (ret != 0) {
|
||||||
|
|
|
@ -151,7 +151,8 @@ uint32_t fdt_osc_read_uint32_default(enum stm32mp_osc_id osc_id,
|
||||||
continue;
|
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;
|
return dflt_value;
|
||||||
|
|
|
@ -206,13 +206,13 @@ static int stm32mp1_ddr_setup(void)
|
||||||
return -EINVAL;
|
return -EINVAL;
|
||||||
}
|
}
|
||||||
|
|
||||||
config.info.speed = fdt_read_uint32_default(node, "st,mem-speed", 0);
|
ret = fdt_read_uint32(fdt, node, "st,mem-speed", &config.info.speed);
|
||||||
if (!config.info.speed) {
|
if (ret < 0) {
|
||||||
VERBOSE("%s: no st,mem-speed\n", __func__);
|
VERBOSE("%s: no st,mem-speed\n", __func__);
|
||||||
return -EINVAL;
|
return -EINVAL;
|
||||||
}
|
}
|
||||||
config.info.size = fdt_read_uint32_default(node, "st,mem-size", 0);
|
ret = fdt_read_uint32(fdt, node, "st,mem-size", &config.info.size);
|
||||||
if (!config.info.size) {
|
if (ret < 0) {
|
||||||
VERBOSE("%s: no st,mem-size\n", __func__);
|
VERBOSE("%s: no st,mem-size\n", __func__);
|
||||||
return -EINVAL;
|
return -EINVAL;
|
||||||
}
|
}
|
||||||
|
|
|
@ -14,6 +14,8 @@
|
||||||
|
|
||||||
int fdt_read_uint32(const void *dtb, int node, const char *prop_name,
|
int fdt_read_uint32(const void *dtb, int node, const char *prop_name,
|
||||||
uint32_t *value);
|
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,
|
int fdt_read_uint64(const void *dtb, int node, const char *prop_name,
|
||||||
uint64_t *value);
|
uint64_t *value);
|
||||||
int fdt_read_uint32_array(const void *dtb, int node, const char *prop_name,
|
int fdt_read_uint32_array(const void *dtb, int node, const char *prop_name,
|
||||||
|
|
|
@ -28,8 +28,6 @@ int dt_open_and_check(void);
|
||||||
int fdt_get_address(void **fdt_addr);
|
int fdt_get_address(void **fdt_addr);
|
||||||
bool fdt_check_node(int node);
|
bool fdt_check_node(int node);
|
||||||
uint8_t fdt_get_status(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,
|
int fdt_get_reg_props_by_name(int node, const char *name, uintptr_t *base,
|
||||||
size_t *size);
|
size_t *size);
|
||||||
int dt_set_stdout_pinctrl(void);
|
int dt_set_stdout_pinctrl(void);
|
||||||
|
|
|
@ -135,26 +135,6 @@ static int fdt_get_node_parent_size_cells(int node)
|
||||||
}
|
}
|
||||||
#endif
|
#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
|
* This function fills reg node info (base & size) with an index found by
|
||||||
* checking the reg-names node.
|
* checking the reg-names node.
|
||||||
|
@ -343,7 +323,7 @@ uint32_t dt_get_ddr_size(void)
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
return fdt_read_uint32_default(node, "st,mem-size", 0);
|
return fdt_read_uint32_default(fdt, node, "st,mem-size", 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
/*******************************************************************************
|
/*******************************************************************************
|
||||||
|
|
Loading…
Reference in New Issue