drivers: serial: numicro: use pinctrl instead of hard-coded values

This commit enables the numicro serial driver to configure the UART
pins using the pinctrl API.

Signed-off-by: Filip Brozovic <fbrozovic@gmail.com>
This commit is contained in:
Filip Brozovic 2022-09-23 18:37:54 +02:00 committed by Carles Cufí
parent 3453a3b247
commit 617aa8cc65
2 changed files with 14 additions and 6 deletions

View file

@ -5,6 +5,7 @@
* Author: Saravanan Sekar <saravanan@linumiz.com>
*/
#include <zephyr/drivers/pinctrl.h>
#include <zephyr/drivers/uart.h>
#include <NuMicro.h>
#include <string.h>
@ -15,6 +16,7 @@ struct uart_numicro_config {
UART_T *uart;
uint32_t id_rst;
uint32_t id_clk;
const struct pinctrl_dev_config *pincfg;
};
struct uart_numicro_data {
@ -146,6 +148,7 @@ static int uart_numicro_init(const struct device *dev)
{
const struct uart_numicro_config *config = dev->config;
struct uart_numicro_data *ddata = dev->data;
int err;
SYS_ResetModule(config->id_rst);
@ -158,13 +161,13 @@ static int uart_numicro_init(const struct device *dev)
CLK_SetModuleClock(config->id_clk, CLK_CLKSEL1_UART0SEL_PLL,
CLK_CLKDIV0_UART0(0));
/* Set pinctrl for UART0 RXD and TXD */
SYS->GPB_MFPH &= ~(SYS_GPB_MFPH_PB12MFP_Msk | SYS_GPB_MFPH_PB13MFP_Msk);
SYS->GPB_MFPH |= (SYS_GPB_MFPH_PB12MFP_UART0_RXD |
SYS_GPB_MFPH_PB13MFP_UART0_TXD);
SYS_LockReg();
err = pinctrl_apply_state(config->pincfg, PINCTRL_STATE_DEFAULT);
if (err != 0) {
return err;
}
UART_Open(config->uart, ddata->ucfg.baudrate);
return 0;
@ -181,11 +184,13 @@ static const struct uart_driver_api uart_numicro_driver_api = {
};
#define NUMICRO_INIT(index) \
PINCTRL_DT_INST_DEFINE(index); \
\
static const struct uart_numicro_config uart_numicro_cfg_##index = { \
.uart = (UART_T *)DT_INST_REG_ADDR(index), \
.id_rst = UART##index##_RST, \
.id_clk = UART##index##_MODULE, \
.pincfg = PINCTRL_DT_INST_DEV_CONFIG_GET(index), \
}; \
\
static struct uart_numicro_data uart_numicro_data_##index = { \

View file

@ -2,8 +2,11 @@ description: NUVOTON NUMICRO FAMILY UART
compatible: "nuvoton,numicro-uart"
include: uart-controller.yaml
include: [uart-controller.yaml, pinctrl-device.yaml]
properties:
reg:
required: true
pinctrl-0:
required: true