aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAndre Przywara <andre.przywara@arm.com>2020-03-26 12:51:21 +0000
committerAndre Przywara <andre.przywara@arm.com>2020-04-28 15:56:31 +0100
commit52a616b48c617fe8721106f29f2910ca4681afea (patch)
tree9c38f82d440ef555adcf36f710127625cad519b2
parent6e3a89f449fa5b4c0153990a64124211197f426a (diff)
downloadtrusted-firmware-a-52a616b48c617fe8721106f29f2910ca4681afea.tar.gz
plat/stm32: Use generic fdt_read_uint32_array() implementation
The device tree parsing code for the STM32 platform is using its own FDT helper functions, some of them being rather generic. In particular the existing fdt_read_uint32_array() implementation is now almost identical to the new generic code in fdt_wrappers.c, so we can remove the ST specific version and adjust the existing callers. Compared to the original ST implementation the new version takes a pointer to the DTB as the first argument, and also swaps the order of the number of cells and the pointer. Change-Id: Id06b0f1ba4db1ad1f733be40e82c34f46638551a Signed-off-by: Andre Przywara <andre.przywara@arm.com>
-rw-r--r--drivers/st/clk/stm32mp1_clk.c22
-rw-r--r--drivers/st/clk/stm32mp_clkfunc.c7
-rw-r--r--drivers/st/ddr/stm32mp1_ram.c7
-rw-r--r--include/drivers/st/stm32mp_clkfunc.h4
-rw-r--r--plat/st/common/include/stm32mp_dt.h2
-rw-r--r--plat/st/common/stm32mp_dt.c38
-rw-r--r--plat/st/stm32mp1/platform.mk3
7 files changed, 29 insertions, 54 deletions
diff --git a/drivers/st/clk/stm32mp1_clk.c b/drivers/st/clk/stm32mp1_clk.c
index 0cc87cc71d..a16f36dcc2 100644
--- a/drivers/st/clk/stm32mp1_clk.c
+++ b/drivers/st/clk/stm32mp1_clk.c
@@ -16,6 +16,7 @@
#include <arch.h>
#include <arch_helpers.h>
#include <common/debug.h>
+#include <common/fdt_wrappers.h>
#include <drivers/delay_timer.h>
#include <drivers/generic_delay_timer.h>
#include <drivers/st/stm32mp_clkfunc.h>
@@ -1600,20 +1601,25 @@ int stm32mp1_clk_init(void)
bool pll4_preserve = false;
bool pll4_bootrom = false;
const fdt32_t *pkcs_cell;
+ void *fdt;
+
+ if (fdt_get_address(&fdt) == 0) {
+ return false;
+ }
/* Check status field to disable security */
if (!fdt_get_rcc_secure_status()) {
mmio_write_32(rcc_base + RCC_TZCR, 0);
}
- ret = fdt_rcc_read_uint32_array("st,clksrc", clksrc,
- (uint32_t)CLKSRC_NB);
+ ret = fdt_rcc_read_uint32_array("st,clksrc", (uint32_t)CLKSRC_NB,
+ clksrc);
if (ret < 0) {
return -FDT_ERR_NOTFOUND;
}
- ret = fdt_rcc_read_uint32_array("st,clkdiv", clkdiv,
- (uint32_t)CLKDIV_NB);
+ ret = fdt_rcc_read_uint32_array("st,clkdiv", (uint32_t)CLKDIV_NB,
+ clkdiv);
if (ret < 0) {
return -FDT_ERR_NOTFOUND;
}
@@ -1628,8 +1634,8 @@ int stm32mp1_clk_init(void)
continue;
}
- ret = fdt_read_uint32_array(plloff[i], "cfg",
- pllcfg[i], (int)PLLCFG_NB);
+ ret = fdt_read_uint32_array(fdt, plloff[i], "cfg",
+ (int)PLLCFG_NB, pllcfg[i]);
if (ret < 0) {
return -FDT_ERR_NOTFOUND;
}
@@ -1800,8 +1806,8 @@ int stm32mp1_clk_init(void)
if (ret != 0) {
return ret;
}
- ret = fdt_read_uint32_array(plloff[i], "csg", csg,
- (uint32_t)PLLCSG_NB);
+ ret = fdt_read_uint32_array(fdt, plloff[i], "csg",
+ (uint32_t)PLLCSG_NB, csg);
if (ret == 0) {
stm32mp1_pll_csg(i, csg);
} else if (ret != -FDT_ERR_NOTFOUND) {
diff --git a/drivers/st/clk/stm32mp_clkfunc.c b/drivers/st/clk/stm32mp_clkfunc.c
index 87c8e2b840..6404d9933c 100644
--- a/drivers/st/clk/stm32mp_clkfunc.c
+++ b/drivers/st/clk/stm32mp_clkfunc.c
@@ -10,6 +10,7 @@
#include <platform_def.h>
+#include <common/fdt_wrappers.h>
#include <drivers/st/stm32_gpio.h>
#include <drivers/st/stm32mp_clkfunc.h>
@@ -200,8 +201,8 @@ uint32_t fdt_rcc_read_addr(void)
* @param count: number of parameters to be read
* @return: 0 on succes or a negative value on error
*/
-int fdt_rcc_read_uint32_array(const char *prop_name,
- uint32_t *array, uint32_t count)
+int fdt_rcc_read_uint32_array(const char *prop_name, uint32_t count,
+ uint32_t *array)
{
int node;
void *fdt;
@@ -215,7 +216,7 @@ int fdt_rcc_read_uint32_array(const char *prop_name,
return -FDT_ERR_NOTFOUND;
}
- return fdt_read_uint32_array(node, prop_name, array, count);
+ return fdt_read_uint32_array(fdt, node, prop_name, count, array);
}
/*
diff --git a/drivers/st/ddr/stm32mp1_ram.c b/drivers/st/ddr/stm32mp1_ram.c
index 40cd4554fa..273dec0df4 100644
--- a/drivers/st/ddr/stm32mp1_ram.c
+++ b/drivers/st/ddr/stm32mp1_ram.c
@@ -12,6 +12,7 @@
#include <arch_helpers.h>
#include <common/debug.h>
+#include <common/fdt_wrappers.h>
#include <drivers/st/stm32mp1_ddr.h>
#include <drivers/st/stm32mp1_ddr_helpers.h>
#include <drivers/st/stm32mp1_ram.h>
@@ -223,10 +224,10 @@ static int stm32mp1_ddr_setup(void)
INFO("RAM: %s\n", config.info.name);
for (idx = 0; idx < ARRAY_SIZE(param); idx++) {
- ret = fdt_read_uint32_array(node, param[idx].name,
+ ret = fdt_read_uint32_array(fdt, node, param[idx].name,
+ param[idx].size,
(void *)((uintptr_t)&config +
- param[idx].offset),
- param[idx].size);
+ param[idx].offset));
VERBOSE("%s: %s[0x%x] = %d\n", __func__,
param[idx].name, param[idx].size, ret);
diff --git a/include/drivers/st/stm32mp_clkfunc.h b/include/drivers/st/stm32mp_clkfunc.h
index 0769167304..0902f445d1 100644
--- a/include/drivers/st/stm32mp_clkfunc.h
+++ b/include/drivers/st/stm32mp_clkfunc.h
@@ -21,8 +21,8 @@ uint32_t fdt_osc_read_uint32_default(enum stm32mp_osc_id osc_id,
int fdt_get_rcc_node(void *fdt);
uint32_t fdt_rcc_read_addr(void);
-int fdt_rcc_read_uint32_array(const char *prop_name,
- uint32_t *array, uint32_t count);
+int fdt_rcc_read_uint32_array(const char *prop_name, uint32_t count,
+ uint32_t *array);
int fdt_rcc_subnode_offset(const char *name);
const fdt32_t *fdt_rcc_read_prop(const char *prop_name, int *lenp);
bool fdt_get_rcc_secure_status(void);
diff --git a/plat/st/common/include/stm32mp_dt.h b/plat/st/common/include/stm32mp_dt.h
index a29d9148d0..92f3d65287 100644
--- a/plat/st/common/include/stm32mp_dt.h
+++ b/plat/st/common/include/stm32mp_dt.h
@@ -30,8 +30,6 @@ 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_read_uint32_array(int node, const char *prop_name,
- uint32_t *array, uint32_t count);
int fdt_get_reg_props_by_name(int node, const char *name, uintptr_t *base,
size_t *size);
int dt_set_stdout_pinctrl(void);
diff --git a/plat/st/common/stm32mp_dt.c b/plat/st/common/stm32mp_dt.c
index acb323cf29..6b76424ae3 100644
--- a/plat/st/common/stm32mp_dt.c
+++ b/plat/st/common/stm32mp_dt.c
@@ -12,6 +12,7 @@
#include <platform_def.h>
#include <common/debug.h>
+#include <common/fdt_wrappers.h>
#include <drivers/st/stm32_gpio.h>
#include <drivers/st/stm32mp1_ddr.h>
#include <drivers/st/stm32mp1_ram.h>
@@ -155,39 +156,6 @@ uint32_t fdt_read_uint32_default(int node, const char *prop_name,
}
/*******************************************************************************
- * This function reads a series of parameters in a node property
- * (generic use of fdt library).
- * It reads the values inside the device tree, from property name and node.
- * The number of parameters is also indicated as entry parameter.
- * Returns 0 on success and a negative FDT error code on failure.
- * If success, values are stored at the third parameter address.
- ******************************************************************************/
-int fdt_read_uint32_array(int node, const char *prop_name, uint32_t *array,
- uint32_t count)
-{
- const fdt32_t *cuint;
- int len;
- uint32_t i;
-
- cuint = fdt_getprop(fdt, node, prop_name, &len);
- if (cuint == NULL) {
- return -FDT_ERR_NOTFOUND;
- }
-
- if ((uint32_t)len != (count * sizeof(uint32_t))) {
- return -FDT_ERR_BADLAYOUT;
- }
-
- for (i = 0; i < ((uint32_t)len / sizeof(uint32_t)); i++) {
- *array = fdt32_to_cpu(*cuint);
- array++;
- cuint++;
- }
-
- 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.
@@ -396,7 +364,7 @@ uintptr_t dt_get_ddrctrl_base(void)
assert((fdt_get_node_parent_address_cells(node) == 1) &&
(fdt_get_node_parent_size_cells(node) == 1));
- if (fdt_read_uint32_array(node, "reg", array, 4) < 0) {
+ if (fdt_read_uint32_array(fdt, node, "reg", 4, array) < 0) {
return 0;
}
@@ -421,7 +389,7 @@ uintptr_t dt_get_ddrphyc_base(void)
assert((fdt_get_node_parent_address_cells(node) == 1) &&
(fdt_get_node_parent_size_cells(node) == 1));
- if (fdt_read_uint32_array(node, "reg", array, 4) < 0) {
+ if (fdt_read_uint32_array(fdt, node, "reg", 4, array) < 0) {
return 0;
}
diff --git a/plat/st/stm32mp1/platform.mk b/plat/st/stm32mp1/platform.mk
index 5ce7a9c4f7..b0ba82abfd 100644
--- a/plat/st/stm32mp1/platform.mk
+++ b/plat/st/stm32mp1/platform.mk
@@ -62,7 +62,8 @@ DTC_FLAGS += -Wno-unit_address_vs_reg
include lib/libfdt/libfdt.mk
-PLAT_BL_COMMON_SOURCES := plat/st/common/stm32mp_common.c \
+PLAT_BL_COMMON_SOURCES := common/fdt_wrappers.c \
+ plat/st/common/stm32mp_common.c \
plat/st/stm32mp1/stm32mp1_private.c
PLAT_BL_COMMON_SOURCES += drivers/st/uart/aarch32/stm32_console.S