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 ;
0 commit comments