drivers: serial: rv32m1: lpuart: add pinctrl support
Add pinctrl support to the OpenISA RV32M1 LPUART serial driver. Signed-off-by: Henrik Brix Andersen <henrik@brixandersen.dk>
This commit is contained in:
parent
9ba953d13a
commit
738e9f57f9
2 changed files with 28 additions and 1 deletions
|
@ -13,6 +13,9 @@
|
|||
#include <drivers/clock_control.h>
|
||||
#include <fsl_lpuart.h>
|
||||
#include <soc.h>
|
||||
#ifdef CONFIG_PINCTRL
|
||||
#include <drivers/pinctrl.h>
|
||||
#endif
|
||||
|
||||
struct rv32m1_lpuart_config {
|
||||
LPUART_Type *base;
|
||||
|
@ -25,6 +28,9 @@ struct rv32m1_lpuart_config {
|
|||
#ifdef CONFIG_UART_INTERRUPT_DRIVEN
|
||||
void (*irq_config_func)(const struct device *dev);
|
||||
#endif
|
||||
#ifdef CONFIG_PINCTRL
|
||||
const struct pinctrl_dev_config *pincfg;
|
||||
#endif
|
||||
};
|
||||
|
||||
struct rv32m1_lpuart_data {
|
||||
|
@ -240,6 +246,9 @@ static int rv32m1_lpuart_init(const struct device *dev)
|
|||
const struct rv32m1_lpuart_config *config = dev->config;
|
||||
lpuart_config_t uart_config;
|
||||
uint32_t clock_freq;
|
||||
#ifdef CONFIG_PINCTRL
|
||||
int err;
|
||||
#endif
|
||||
|
||||
/* set clock source */
|
||||
/* TODO: Don't change if another core has configured */
|
||||
|
@ -261,6 +270,13 @@ static int rv32m1_lpuart_init(const struct device *dev)
|
|||
|
||||
LPUART_Init(config->base, &uart_config, clock_freq);
|
||||
|
||||
#ifdef CONFIG_PINCTRL
|
||||
err = pinctrl_apply_state(config->pincfg, PINCTRL_STATE_DEFAULT);
|
||||
if (err != 0) {
|
||||
return err;
|
||||
}
|
||||
#endif
|
||||
|
||||
#ifdef CONFIG_UART_INTERRUPT_DRIVEN
|
||||
config->irq_config_func(dev);
|
||||
#endif
|
||||
|
@ -290,6 +306,14 @@ static const struct uart_driver_api rv32m1_lpuart_driver_api = {
|
|||
#endif
|
||||
};
|
||||
|
||||
#ifdef CONFIG_PINCTRL
|
||||
#define PINCTRL_INIT(n) .pincfg = PINCTRL_DT_INST_DEV_CONFIG_GET(n),
|
||||
#define PINCTRL_DEFINE(n) PINCTRL_DT_INST_DEFINE(n);
|
||||
#else
|
||||
#define PINCTRL_DEFINE(n)
|
||||
#define PINCTRL_INIT(n)
|
||||
#endif
|
||||
|
||||
#define RV32M1_LPUART_DECLARE_CFG(n, IRQ_FUNC_INIT) \
|
||||
static const struct rv32m1_lpuart_config rv32m1_lpuart_##n##_cfg = {\
|
||||
.base = (LPUART_Type *)DT_INST_REG_ADDR(n), \
|
||||
|
@ -300,6 +324,7 @@ static const struct uart_driver_api rv32m1_lpuart_driver_api = {
|
|||
.clock_ip_src = kCLOCK_IpSrcFircAsync, \
|
||||
.baud_rate = DT_INST_PROP(n, current_speed), \
|
||||
.hw_flow_control = DT_INST_PROP(n, hw_flow_control), \
|
||||
PINCTRL_INIT(n) \
|
||||
IRQ_FUNC_INIT \
|
||||
}
|
||||
|
||||
|
@ -324,6 +349,8 @@ static const struct uart_driver_api rv32m1_lpuart_driver_api = {
|
|||
#endif
|
||||
|
||||
#define RV32M1_LPUART_INIT(n) \
|
||||
PINCTRL_DEFINE(n) \
|
||||
\
|
||||
static struct rv32m1_lpuart_data rv32m1_lpuart_##n##_data; \
|
||||
\
|
||||
static const struct rv32m1_lpuart_config rv32m1_lpuart_##n##_cfg;\
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue