-
-#if CONFIG_IS_ENABLED(SERIAL_IRQ_BUFFER)
-
-#define BUF_COUNT 256
-
-static void rx_fifo_to_buf(struct udevice *dev)
-{
- struct NS16550 *const com_port = dev_get_priv(dev);
- struct ns16550_platdata *plat = dev->platdata;
-
- /* Read all available chars into buffer */
- while ((serial_in(&com_port->lsr) & UART_LSR_DR)) {
- plat->buf[plat->wr_ptr++] = serial_in(&com_port->rbr);
- plat->wr_ptr %= BUF_COUNT;
- }
-}
-
-static int rx_pending(struct udevice *dev)
-{
- struct ns16550_platdata *plat = dev->platdata;
-
- /*
- * At startup it may happen, that some already received chars are
- * "stuck" in the RX FIFO, even with the interrupt enabled. This
- * RX FIFO flushing makes sure, that these chars are read out and
- * the RX interrupts works as expected.
- */
- rx_fifo_to_buf(dev);
-
- return plat->rd_ptr != plat->wr_ptr ? 1 : 0;
-}
-
-static int rx_get(struct udevice *dev)
-{
- struct ns16550_platdata *plat = dev->platdata;
- char val;
-
- val = plat->buf[plat->rd_ptr++];
- plat->rd_ptr %= BUF_COUNT;
-
- return val;
-}
-
-void ns16550_handle_irq(void *data)
-{
- struct udevice *dev = (struct udevice *)data;
- struct NS16550 *const com_port = dev_get_priv(dev);
-
- /* Check if interrupt is pending */
- if (serial_in(&com_port->iir) & UART_IIR_NO_INT)
- return;
-
- /* Flush all available characters from the RX FIFO into the RX buffer */
- rx_fifo_to_buf(dev);
-}
-
-#else /* CONFIG_SERIAL_IRQ_BUFFER */
-
-static int rx_pending(struct udevice *dev)
-{
- struct NS16550 *const com_port = dev_get_priv(dev);
-
- return serial_in(&com_port->lsr) & UART_LSR_DR ? 1 : 0;
-}
-
-static int rx_get(struct udevice *dev)
-{
- struct NS16550 *const com_port = dev_get_priv(dev);
-
- return serial_in(&com_port->rbr);
-}
-
-#endif /* CONFIG_SERIAL_IRQ_BUFFER */
-