Skip to content

Commit 4a69c1b

Browse files
maass-hamburgkartben
authored andcommitted
drivers: serial: litex: add support for rx-fifo-rx-we
add support for rx-fifo-rx-we, whci got added to LiteX in enjoy-digital/litex#2319 Signed-off-by: Fin Maaß <[email protected]>
1 parent a39ab55 commit 4a69c1b

File tree

2 files changed

+26
-2
lines changed

2 files changed

+26
-2
lines changed

drivers/serial/uart_litex.c

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,14 @@
1616

1717
#include <soc.h>
1818

19+
#if DT_ANY_INST_HAS_BOOL_STATUS_OKAY(rx_fifo_rx_we)
20+
#define USES_RX_FIFO_RX_WE 1
21+
#endif
22+
23+
BUILD_ASSERT(DT_ANY_INST_HAS_BOOL_STATUS_OKAY(rx_fifo_rx_we) ==
24+
DT_ALL_INST_HAS_BOOL_STATUS_OKAY(rx_fifo_rx_we),
25+
"rx-fifo-rx-we property must be set for all or none of the instances");
26+
1927
#define UART_EV_TX BIT(0)
2028
#define UART_EV_RX BIT(1)
2129

@@ -73,11 +81,12 @@ static int uart_litex_poll_in(const struct device *dev, unsigned char *c)
7381

7482
if (!litex_read8(config->rxempty_addr)) {
7583
*c = litex_read8(config->rxtx_addr);
76-
84+
#ifndef USES_RX_FIFO_RX_WE
7785
/* refresh UART_RXEMPTY by writing UART_EV_RX
7886
* to UART_EV_PENDING
7987
*/
8088
litex_write8(UART_EV_RX, config->ev_pending_addr);
89+
#endif
8190
return 0;
8291
}
8392

@@ -193,6 +202,12 @@ static int uart_litex_fifo_fill(const struct device *dev,
193202
litex_write8(tx_data[i], config->rxtx_addr);
194203
}
195204

205+
#ifndef USES_RX_FIFO_RX_WE
206+
/* LiteX uses EventSourceLevel for the UART since 22.09.2025,
207+
* where TX event is level triggered and pending is self-flushing,
208+
* so this is not needed anymore for new designs. When the dt property
209+
* rx-fifo-rx-we is set, we assume the design is new enough.
210+
*/
196211
if (litex_read8(config->txfull_addr)) {
197212
/* only flush TX event if TX is really full */
198213
litex_write8(UART_EV_TX, config->ev_pending_addr);
@@ -202,6 +217,7 @@ static int uart_litex_fifo_fill(const struct device *dev,
202217
litex_write8(0, config->rxtx_addr);
203218
}
204219
}
220+
#endif
205221

206222
return i;
207223
}
@@ -223,11 +239,12 @@ static int uart_litex_fifo_read(const struct device *dev,
223239

224240
for (i = 0; i < size && !litex_read8(config->rxempty_addr); i++) {
225241
rx_data[i] = litex_read8(config->rxtx_addr);
226-
242+
#ifndef USES_RX_FIFO_RX_WE
227243
/* refresh UART_RXEMPTY by writing UART_EV_RX
228244
* to UART_EV_PENDING
229245
*/
230246
litex_write8(UART_EV_RX, config->ev_pending_addr);
247+
#endif
231248
}
232249

233250
return i;

dts/bindings/serial/litex,uart.yaml

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,3 +13,10 @@ properties:
1313

1414
interrupts:
1515
required: true
16+
17+
rx-fifo-rx-we:
18+
type: boolean
19+
description: |
20+
If true, the RX FIFO read will also remove that item from the FIFO.
21+
Set this property if the uart_rx_fifo_rx_we parameter in LiteX is
22+
set to true.

0 commit comments

Comments
 (0)