drivers: uart: add pinctrl driver support

Replace soc-specific pin functions with Zephyr pinctrl api functions for
pin-mux configuration in uart driver.

Signed-off-by: Mulin Chao <mlchao@nuvoton.com>
This commit is contained in:
Mulin Chao 2022-02-21 01:52:53 -08:00 committed by Maureen Helm
commit 8efc935288
6 changed files with 18 additions and 17 deletions

View file

@ -8,6 +8,7 @@
#include <zephyr/sys/__assert.h>
#include <zephyr/drivers/gpio.h>
#include <zephyr/drivers/pinctrl.h>
#include <zephyr/drivers/uart.h>
#include <zephyr/drivers/clock_control.h>
#include <zephyr/kernel.h>
@ -31,8 +32,7 @@ struct uart_npcx_config {
/* int-mux configuration */
const struct npcx_wui uart_rx_wui;
/* pinmux configuration */
const uint8_t alts_size;
const struct npcx_alt *alts_list;
const struct pinctrl_dev_config *pcfg;
};
enum uart_pm_policy_state_flag {
@ -499,7 +499,11 @@ static int uart_npcx_init(const struct device *dev)
}
/* Configure pin-mux for uart device */
npcx_pinctrl_mux_configure(config->alts_list, config->alts_size, 1);
ret = pinctrl_apply_state(config->pcfg, PINCTRL_STATE_DEFAULT);
if (ret < 0) {
LOG_ERR("UART pinctrl setup failed (%d)", ret);
return ret;
}
return 0;
}
@ -524,14 +528,13 @@ static int uart_npcx_init(const struct device *dev)
#define NPCX_UART_INIT(i) \
NPCX_UART_IRQ_CONFIG_FUNC_DECL(i); \
\
static const struct npcx_alt uart_alts##i[] = NPCX_DT_ALT_ITEMS_LIST(i); \
PINCTRL_DT_INST_DEFINE(i); \
\
static const struct uart_npcx_config uart_npcx_cfg_##i = { \
.inst = (struct uart_reg *)DT_INST_REG_ADDR(i), \
.clk_cfg = NPCX_DT_CLK_CFG_ITEM(i), \
.uart_rx_wui = NPCX_DT_WUI_ITEM_BY_NAME(0, uart_rx), \
.alts_size = ARRAY_SIZE(uart_alts##i), \
.alts_list = uart_alts##i, \
.pcfg = PINCTRL_DT_INST_DEV_CONFIG_GET(i), \
NPCX_UART_IRQ_CONFIG_FUNC_INIT(i) \
}; \
\