Skip to content

Commit 19c1f9f

Browse files
xudongzhengnashif
authored andcommitted
drivers: serial: pl011: add support for hardware flow control
Flow control will be enabled for UART if hw-flow-control is set. Signed-off-by: Xudong Zheng <[email protected]>
1 parent 94b752d commit 19c1f9f

File tree

1 file changed

+22
-2
lines changed

1 file changed

+22
-2
lines changed

drivers/serial/uart_pl011.c

Lines changed: 22 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,20 @@ static void pl011_disable_fifo(const struct device *dev)
8888
get_uart(dev)->lcr_h &= ~PL011_LCRH_FEN;
8989
}
9090

91+
static void pl011_set_flow_control(const struct device *dev, bool rts, bool cts)
92+
{
93+
if (rts) {
94+
get_uart(dev)->cr |= PL011_CR_RTSEn;
95+
} else {
96+
get_uart(dev)->cr &= ~PL011_CR_RTSEn;
97+
}
98+
if (cts) {
99+
get_uart(dev)->cr |= PL011_CR_CTSEn;
100+
} else {
101+
get_uart(dev)->cr &= ~PL011_CR_CTSEn;
102+
}
103+
}
104+
91105
static int pl011_set_baudrate(const struct device *dev,
92106
uint32_t clk, uint32_t baudrate)
93107
{
@@ -240,6 +254,10 @@ static int pl011_runtime_configure_internal(const struct device *dev,
240254

241255
switch (cfg->flow_ctrl) {
242256
case UART_CFG_FLOW_CTRL_NONE:
257+
pl011_set_flow_control(dev, false, false);
258+
break;
259+
case UART_CFG_FLOW_CTRL_RTS_CTS:
260+
pl011_set_flow_control(dev, true, true);
243261
break;
244262
default:
245263
goto enable;
@@ -506,7 +524,7 @@ static int pl011_init(const struct device *dev)
506524
if (!data->sbsa) {
507525
get_uart(dev)->dmacr = 0U;
508526
barrier_isync_fence_full();
509-
get_uart(dev)->cr &= ~(BIT(14) | BIT(15) | BIT(1));
527+
get_uart(dev)->cr &= ~PL011_CR_SIREN;
510528
get_uart(dev)->cr |= PL011_CR_RXE | PL011_CR_TXE;
511529
barrier_isync_fence_full();
512530
}
@@ -641,7 +659,9 @@ void pl011_isr(const struct device *dev)
641659
.parity = UART_CFG_PARITY_NONE, \
642660
.stop_bits = UART_CFG_STOP_BITS_1, \
643661
.data_bits = UART_CFG_DATA_BITS_8, \
644-
.flow_ctrl = UART_CFG_FLOW_CTRL_NONE, \
662+
.flow_ctrl = DT_INST_PROP(n, hw_flow_control) \
663+
? UART_CFG_FLOW_CTRL_RTS_CTS \
664+
: UART_CFG_FLOW_CTRL_NONE, \
645665
}, \
646666
.clk_freq = COND_CODE_1( \
647667
DT_NODE_HAS_COMPAT(DT_INST_CLOCKS_CTLR(n), fixed_clock), \

0 commit comments

Comments
 (0)