Skip to content

Commit 7160d4f

Browse files
hakehuangdanieldegrasse
authored andcommitted
driver: lpuart: add pinctrl support in mcux lpuart
enable pinctrl in lpuart Signed-off-by: Hake Huang <[email protected]>
1 parent 7aa2340 commit 7160d4f

File tree

1 file changed

+54
-0
lines changed

1 file changed

+54
-0
lines changed

drivers/serial/uart_mcux_lpuart.c

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,10 +13,16 @@
1313
#include <device.h>
1414
#include <drivers/uart.h>
1515
#include <drivers/clock_control.h>
16+
#ifdef CONFIG_PINCTRL
17+
#include <drivers/pinctrl.h>
18+
#endif
1619

1720
struct mcux_lpuart_config {
1821
LPUART_Type *base;
1922
const struct device *clock_dev;
23+
#ifdef CONFIG_PINCTRL
24+
const struct pinctrl_dev_config *pinctrl;
25+
#endif
2026
clock_control_subsys_t clock_subsys;
2127
uint32_t baud_rate;
2228
uint8_t flow_ctrl;
@@ -353,6 +359,9 @@ static int mcux_lpuart_init(const struct device *dev)
353359
const struct mcux_lpuart_config *config = dev->config;
354360
struct mcux_lpuart_data *data = dev->data;
355361
struct uart_config *uart_api_config = &data->uart_config;
362+
#ifdef CONFIG_PINCTRL
363+
int err;
364+
#endif
356365

357366
uart_api_config->baudrate = config->baud_rate;
358367
uart_api_config->parity = UART_CFG_PARITY_NONE;
@@ -362,6 +371,12 @@ static int mcux_lpuart_init(const struct device *dev)
362371

363372
/* set initial configuration */
364373
mcux_lpuart_configure_init(dev, uart_api_config);
374+
#ifdef CONFIG_PINCTRL
375+
err = pinctrl_apply_state(config->pinctrl, PINCTRL_STATE_DEFAULT);
376+
if (err < 0) {
377+
return err;
378+
}
379+
#endif
365380

366381
#ifdef CONFIG_UART_INTERRUPT_DRIVEN
367382
config->irq_config_func(dev);
@@ -425,10 +440,13 @@ static const struct uart_driver_api mcux_lpuart_driver_api = {
425440
LPUART_MCUX_DECLARE_CFG(n, LPUART_MCUX_IRQ_CFG_FUNC_INIT)
426441
#endif
427442

443+
#if CONFIG_PINCTRL
444+
428445
#define LPUART_MCUX_DECLARE_CFG(n, IRQ_FUNC_INIT) \
429446
static const struct mcux_lpuart_config mcux_lpuart_##n##_config = { \
430447
.base = (LPUART_Type *) DT_INST_REG_ADDR(n), \
431448
.clock_dev = DEVICE_DT_GET(DT_INST_CLOCKS_CTLR(n)), \
449+
.pinctrl = PINCTRL_DT_INST_DEV_CONFIG_GET(n), \
432450
.clock_subsys = (clock_control_subsys_t)DT_INST_CLOCKS_CELL(n, name),\
433451
.baud_rate = DT_INST_PROP(n, current_speed), \
434452
.flow_ctrl = DT_INST_PROP(n, hw_flow_control) ? \
@@ -440,6 +458,8 @@ static const struct mcux_lpuart_config mcux_lpuart_##n##_config = { \
440458
\
441459
static struct mcux_lpuart_data mcux_lpuart_##n##_data; \
442460
\
461+
PINCTRL_DT_INST_DEFINE(n); \
462+
\
443463
static const struct mcux_lpuart_config mcux_lpuart_##n##_config;\
444464
\
445465
DEVICE_DT_INST_DEFINE(n, \
@@ -456,3 +476,37 @@ static const struct mcux_lpuart_config mcux_lpuart_##n##_config = { \
456476
LPUART_MCUX_INIT_CFG(n);
457477

458478
DT_INST_FOREACH_STATUS_OKAY(LPUART_MCUX_INIT)
479+
#else
480+
481+
#define LPUART_MCUX_DECLARE_CFG(n, IRQ_FUNC_INIT) \
482+
static const struct mcux_lpuart_config mcux_lpuart_##n##_config = { \
483+
.base = (LPUART_Type *) DT_INST_REG_ADDR(n), \
484+
.clock_dev = DEVICE_DT_GET(DT_INST_CLOCKS_CTLR(n)), \
485+
.clock_subsys = (clock_control_subsys_t)DT_INST_CLOCKS_CELL(n, name),\
486+
.baud_rate = DT_INST_PROP(n, current_speed), \
487+
.flow_ctrl = DT_INST_PROP(n, hw_flow_control) ? \
488+
UART_CFG_FLOW_CTRL_RTS_CTS : UART_CFG_FLOW_CTRL_NONE,\
489+
IRQ_FUNC_INIT \
490+
}
491+
492+
#define LPUART_MCUX_INIT(n) \
493+
\
494+
static struct mcux_lpuart_data mcux_lpuart_##n##_data; \
495+
\
496+
static const struct mcux_lpuart_config mcux_lpuart_##n##_config;\
497+
\
498+
DEVICE_DT_INST_DEFINE(n, \
499+
&mcux_lpuart_init, \
500+
NULL, \
501+
&mcux_lpuart_##n##_data, \
502+
&mcux_lpuart_##n##_config, \
503+
PRE_KERNEL_1, \
504+
CONFIG_SERIAL_INIT_PRIORITY, \
505+
&mcux_lpuart_driver_api); \
506+
\
507+
LPUART_MCUX_CONFIG_FUNC(n) \
508+
\
509+
LPUART_MCUX_INIT_CFG(n);
510+
511+
DT_INST_FOREACH_STATUS_OKAY(LPUART_MCUX_INIT)
512+
#endif

0 commit comments

Comments
 (0)