Skip to content

Commit 109a90e

Browse files
drivers: serial: uart_mcux_lpuart: Fix pinctrl flow control
Currently the driver code does not actually request the flow control state, it only checks if the state exists. To fix this we should simply call pinctrl_apply_state() and if that fails, meaning no flow control state exists, fall back to default pin mux settings. Another case that needed fixing is run time flow control enabling ie in the case where we have a WIFI/bluetooth module connected and we initially operate without flow control but later enable it after firmware download. This patch addresses this as well by making a generic function to achieve this. Signed-off-by: Bas van Loon <[email protected]>
1 parent d5201e1 commit 109a90e

File tree

1 file changed

+35
-15
lines changed

1 file changed

+35
-15
lines changed

drivers/serial/uart_mcux_lpuart.c

+35-15
Original file line numberDiff line numberDiff line change
@@ -974,9 +974,31 @@ static void mcux_lpuart_isr(const struct device *dev)
974974
}
975975
#endif /* CONFIG_UART_MCUX_LPUART_ISR_SUPPORT */
976976

977+
static int mcux_lpuart_config_pinctrl(const struct device *dev, uint8_t flow_ctrl)
978+
{
979+
const struct mcux_lpuart_config *config = dev->config;
980+
int err;
981+
982+
if (flow_ctrl) {
983+
err = pinctrl_apply_state(config->pincfg, PINCTRL_STATE_FLOWCONTROL);
984+
if (err < 0) {
985+
LOG_WRN("Failed to set flowcontrol state, using default state");
986+
/* Fallback to default state if flow-control pins are not set */
987+
err = pinctrl_apply_state(config->pincfg, PINCTRL_STATE_DEFAULT);
988+
}
989+
} else {
990+
err = pinctrl_apply_state(config->pincfg, PINCTRL_STATE_DEFAULT);
991+
}
992+
993+
return err;
994+
}
995+
977996
#if LPUART_HAS_MODEM
978-
static int mcux_lpuart_config_flowctrl(uint8_t flow_ctrl, lpuart_config_t *uart_config)
997+
static int mcux_lpuart_config_flowctrl(const struct device *dev, uint8_t flow_ctrl,
998+
lpuart_config_t *uart_config)
979999
{
1000+
int ret = 0;
1001+
9801002
switch (flow_ctrl) {
9811003
case UART_CFG_FLOW_CTRL_NONE:
9821004
case UART_CFG_FLOW_CTRL_RS485:
@@ -990,13 +1012,20 @@ static int mcux_lpuart_config_flowctrl(uint8_t flow_ctrl, lpuart_config_t *uart_
9901012
break;
9911013

9921014
default:
993-
return -ENOTSUP;
1015+
ret = -ENOTSUP;
1016+
break;
9941017
}
9951018

996-
return 0;
1019+
if (ret == 0) {
1020+
/* Configure the pinctrl for flow control */
1021+
ret = mcux_lpuart_config_pinctrl(dev, flow_ctrl);
1022+
}
1023+
1024+
return ret;
9971025
}
9981026
#else
999-
static int mcux_lpuart_config_flowctrl(uint8_t flow_ctrl, lpuart_config_t *uart_config)
1027+
static int mcux_lpuart_config_flowctrl(const struct device *dev, uint8_t flow_ctrl,
1028+
lpuart_config_t *uart_config)
10001029
{
10011030
if (flow_ctrl != UART_CFG_FLOW_CTRL_NONE) {
10021031
return -ENOTSUP;
@@ -1059,7 +1088,7 @@ static int mcux_lpuart_configure_basic(const struct device *dev, const struct ua
10591088
return -ENOTSUP;
10601089
}
10611090

1062-
ret = mcux_lpuart_config_flowctrl(cfg->flow_ctrl, uart_config);
1091+
ret = mcux_lpuart_config_flowctrl(dev, cfg->flow_ctrl, uart_config);
10631092
if (ret) {
10641093
return ret;
10651094
}
@@ -1322,16 +1351,7 @@ static int mcux_lpuart_init(const struct device *dev)
13221351

13231352
/* set initial configuration */
13241353
mcux_lpuart_configure_init(dev, uart_api_config);
1325-
if (config->flow_ctrl) {
1326-
const struct pinctrl_state *state;
1327-
1328-
err = pinctrl_lookup_state(config->pincfg, PINCTRL_STATE_FLOWCONTROL, &state);
1329-
if (err < 0) {
1330-
err = pinctrl_apply_state(config->pincfg, PINCTRL_STATE_DEFAULT);
1331-
}
1332-
} else {
1333-
err = pinctrl_apply_state(config->pincfg, PINCTRL_STATE_DEFAULT);
1334-
}
1354+
err = mcux_lpuart_config_pinctrl(dev, config->flow_ctrl);
13351355
if (err < 0) {
13361356
return err;
13371357
}

0 commit comments

Comments
 (0)