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 <patrick.delaunay@foss.st.com>
Change-Id: I575fd0e1026b857059abcfd4a3166eb3a239e1fd
This commit is contained in:
Patrick Delaunay 2022-04-14 11:19:03 +02:00 committed by Yann Gautier
parent 7d197d6281
commit d99998f76e

View file

@ -9,7 +9,9 @@
#include <string.h> #include <string.h>
#include <common/bl_common.h> #include <common/bl_common.h>
#include <drivers/clk.h>
#include <drivers/delay_timer.h> #include <drivers/delay_timer.h>
#include <drivers/st/stm32_gpio.h>
#include <drivers/st/stm32_uart.h> #include <drivers/st/stm32_uart.h>
#include <drivers/st/stm32_uart_regs.h> #include <drivers/st/stm32_uart_regs.h>
#include <drivers/st/stm32mp_clkfunc.h> #include <drivers/st/stm32mp_clkfunc.h>
@ -300,12 +302,14 @@ void stm32_uart_stop(uintptr_t base)
* @param init: UART initialization parameter. * @param init: UART initialization parameter.
* @retval UART status. * @retval UART status.
*/ */
int stm32_uart_init(struct stm32_uart_handle_s *huart, int stm32_uart_init(struct stm32_uart_handle_s *huart,
uintptr_t base_addr, uintptr_t base_addr,
const struct stm32_uart_init_s *init) const struct stm32_uart_init_s *init)
{ {
int ret; int ret;
int uart_node;
int clk;
void *fdt = NULL;
if (huart == NULL || init == NULL || base_addr == 0U) { if (huart == NULL || init == NULL || base_addr == 0U) {
return -EINVAL; return -EINVAL;
@ -313,6 +317,32 @@ int stm32_uart_init(struct stm32_uart_handle_s *huart,
huart->base = base_addr; 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 */ /* Disable the peripheral */
stm32_uart_stop(huart->base); stm32_uart_stop(huart->base);