Skip to content

Commit fbf3353

Browse files
nirav-agrawalkartben
authored andcommitted
drivers: serial: add support for uart_line_ctrl_set()
- For MCUX LPUART driver, added support to control RTS line High/Low from other driver/app code. - This control is required to wakeup other device which is in sleep and configured its wakeup-source as UART-CTS line. Signed-off-by: Nirav Agrawal <[email protected]>
1 parent 761c6fb commit fbf3353

File tree

1 file changed

+48
-1
lines changed

1 file changed

+48
-1
lines changed

drivers/serial/uart_mcux_lpuart.c

Lines changed: 48 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2017,2021,2023-2024 NXP
2+
* Copyright 2017,2021,2023-2025 NXP
33
* Copyright (c) 2020 Softube
44
*
55
* SPDX-License-Identifier: Apache-2.0
@@ -30,6 +30,12 @@ LOG_MODULE_REGISTER(uart_mcux_lpuart, LOG_LEVEL_ERR);
3030

3131
#define PINCTRL_STATE_FLOWCONTROL PINCTRL_STATE_PRIV_START
3232

33+
#if defined(CONFIG_UART_LINE_CTRL) && \
34+
defined(FSL_FEATURE_LPUART_HAS_MODEM_SUPPORT) && \
35+
(FSL_FEATURE_LPUART_HAS_MODEM_SUPPORT)
36+
#define UART_LINE_CTRL_ENABLE
37+
#endif
38+
3339
#if defined(CONFIG_UART_ASYNC_API) && defined(CONFIG_UART_INTERRUPT_DRIVEN)
3440
/* there are already going to be build errors, but at least this message will
3541
* be the first error from this driver making the reason clear
@@ -1179,6 +1185,44 @@ static int mcux_lpuart_configure(const struct device *dev,
11791185
}
11801186
#endif /* CONFIG_UART_USE_RUNTIME_CONFIGURE */
11811187

1188+
#ifdef UART_LINE_CTRL_ENABLE
1189+
static void mcux_lpuart_line_ctrl_set_rts(const struct mcux_lpuart_config *config,
1190+
uint32_t val)
1191+
{
1192+
if (val >= 1U) {
1193+
/* Reset TXRTS to set RXRTSE bit, this provides high-level on RTS line */
1194+
config->base->MODIR &= ~(LPUART_MODIR_TXRTSPOL_MASK | LPUART_MODIR_TXRTSE_MASK);
1195+
config->base->MODIR |= LPUART_MODIR_RXRTSE_MASK;
1196+
} else {
1197+
/* Set TXRTSE to reset RXRTSE bit,this provide low-level on RTS line*/
1198+
config->base->MODIR &= ~(LPUART_MODIR_RXRTSE_MASK);
1199+
config->base->MODIR |= (LPUART_MODIR_TXRTSPOL_MASK | LPUART_MODIR_TXRTSE_MASK);
1200+
}
1201+
}
1202+
1203+
static int mcux_lpuart_line_ctrl_set(const struct device *dev,
1204+
uint32_t ctrl, uint32_t val)
1205+
{
1206+
const struct mcux_lpuart_config *config = dev->config;
1207+
int ret = 0;
1208+
1209+
switch (ctrl) {
1210+
case UART_LINE_CTRL_RTS:
1211+
/* Disable Transmitter and Receiver */
1212+
config->base->CTRL &= ~(LPUART_CTRL_TE_MASK | LPUART_CTRL_RE_MASK);
1213+
1214+
mcux_lpuart_line_ctrl_set_rts(config, val);
1215+
1216+
break;
1217+
1218+
default:
1219+
ret = -ENOTSUP;
1220+
}
1221+
1222+
return ret;
1223+
}
1224+
#endif /* UART_LINE_CTRL_ENABLE */
1225+
11821226
static int mcux_lpuart_init(const struct device *dev)
11831227
{
11841228
const struct mcux_lpuart_config *config = dev->config;
@@ -1257,6 +1301,9 @@ static DEVICE_API(uart, mcux_lpuart_driver_api) = {
12571301
.rx_buf_rsp = mcux_lpuart_rx_buf_rsp,
12581302
.rx_disable = mcux_lpuart_rx_disable,
12591303
#endif /* CONFIG_UART_ASYNC_API */
1304+
#ifdef UART_LINE_CTRL_ENABLE
1305+
.line_ctrl_set = mcux_lpuart_line_ctrl_set,
1306+
#endif /* UART_LINE_CTRL_ENABLE */
12601307
};
12611308

12621309

0 commit comments

Comments
 (0)