From d99998f76ed2e8676be25e31e9479a90c16c7098 Mon Sep 17 00:00:00 2001 From: Patrick Delaunay Date: Thu, 14 Apr 2022 11:19:03 +0200 Subject: [PATCH] feat(st-uart): add initialization with the device tree Add the pincontrol configuration and clock enable in UART driver with information found in the device tree. This patch avoids an issue on STM32MP13x platform because the UART configuration is reset by the ROM code for UART serial boot (STM32MP_UART_PROGRAMMER=1). Signed-off-by: Patrick Delaunay Change-Id: I575fd0e1026b857059abcfd4a3166eb3a239e1fd --- drivers/st/uart/stm32_uart.c | 32 +++++++++++++++++++++++++++++++- 1 file changed, 31 insertions(+), 1 deletion(-) diff --git a/drivers/st/uart/stm32_uart.c b/drivers/st/uart/stm32_uart.c index 08bd77b9a..63970c76d 100644 --- a/drivers/st/uart/stm32_uart.c +++ b/drivers/st/uart/stm32_uart.c @@ -9,7 +9,9 @@ #include #include +#include #include +#include #include #include #include @@ -300,12 +302,14 @@ void stm32_uart_stop(uintptr_t base) * @param init: UART initialization parameter. * @retval UART status. */ - int stm32_uart_init(struct stm32_uart_handle_s *huart, uintptr_t base_addr, const struct stm32_uart_init_s *init) { int ret; + int uart_node; + int clk; + void *fdt = NULL; if (huart == NULL || init == NULL || base_addr == 0U) { return -EINVAL; @@ -313,6 +317,32 @@ int stm32_uart_init(struct stm32_uart_handle_s *huart, huart->base = base_addr; + /* Search UART instance in DT */ + if (fdt_get_address(&fdt) == 0) { + return -FDT_ERR_NOTFOUND; + } + + if (fdt == NULL) { + return -FDT_ERR_NOTFOUND; + } + + uart_node = dt_match_instance_by_compatible(DT_UART_COMPAT, base_addr); + if (uart_node == -FDT_ERR_NOTFOUND) { + return -FDT_ERR_NOTFOUND; + } + + /* Pinctrl initialization */ + if (dt_set_pinctrl_config(uart_node) != 0) { + return -FDT_ERR_BADVALUE; + } + + /* Clock initialization */ + clk = fdt_get_clock_id(uart_node); + if (clk < 0) { + return -FDT_ERR_NOTFOUND; + } + clk_enable(clk); + /* Disable the peripheral */ stm32_uart_stop(huart->base); -- 2.39.5