8250_fsl.c 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  1. // SPDX-License-Identifier: GPL-2.0
  2. #include <linux/serial_reg.h>
  3. #include <linux/serial_8250.h>
  4. #include "8250.h"
  5. /*
  6. * Freescale 16550 UART "driver", Copyright (C) 2011 Paul Gortmaker.
  7. *
  8. * This isn't a full driver; it just provides an alternate IRQ
  9. * handler to deal with an errata. Everything else is just
  10. * using the bog standard 8250 support.
  11. *
  12. * We follow code flow of serial8250_default_handle_irq() but add
  13. * a check for a break and insert a dummy read on the Rx for the
  14. * immediately following IRQ event.
  15. *
  16. * We re-use the already existing "bug handling" lsr_saved_flags
  17. * field to carry the "what we just did" information from the one
  18. * IRQ event to the next one.
  19. */
  20. int fsl8250_handle_irq(struct uart_port *port)
  21. {
  22. unsigned char lsr, orig_lsr;
  23. unsigned long flags;
  24. unsigned int iir;
  25. struct uart_8250_port *up = up_to_u8250p(port);
  26. spin_lock_irqsave(&up->port.lock, flags);
  27. iir = port->serial_in(port, UART_IIR);
  28. if (iir & UART_IIR_NO_INT) {
  29. spin_unlock_irqrestore(&up->port.lock, flags);
  30. return 0;
  31. }
  32. /* This is the WAR; if last event was BRK, then read and return */
  33. if (unlikely(up->lsr_saved_flags & UART_LSR_BI)) {
  34. up->lsr_saved_flags &= ~UART_LSR_BI;
  35. port->serial_in(port, UART_RX);
  36. spin_unlock_irqrestore(&up->port.lock, flags);
  37. return 1;
  38. }
  39. lsr = orig_lsr = up->port.serial_in(&up->port, UART_LSR);
  40. /* Process incoming characters first */
  41. if ((lsr & (UART_LSR_DR | UART_LSR_BI)) &&
  42. (up->ier & (UART_IER_RLSI | UART_IER_RDI))) {
  43. lsr = serial8250_rx_chars(up, lsr);
  44. }
  45. /* Stop processing interrupts on input overrun */
  46. if ((orig_lsr & UART_LSR_OE) && (up->overrun_backoff_time_ms > 0)) {
  47. unsigned long delay;
  48. up->ier = port->serial_in(port, UART_IER);
  49. if (up->ier & (UART_IER_RLSI | UART_IER_RDI)) {
  50. port->ops->stop_rx(port);
  51. } else {
  52. /* Keep restarting the timer until
  53. * the input overrun subsides.
  54. */
  55. cancel_delayed_work(&up->overrun_backoff);
  56. }
  57. delay = msecs_to_jiffies(up->overrun_backoff_time_ms);
  58. schedule_delayed_work(&up->overrun_backoff, delay);
  59. }
  60. serial8250_modem_status(up);
  61. if (lsr & UART_LSR_THRE)
  62. serial8250_tx_chars(up);
  63. up->lsr_saved_flags = orig_lsr;
  64. spin_unlock_irqrestore(&up->port.lock, flags);
  65. return 1;
  66. }
  67. EXPORT_SYMBOL_GPL(fsl8250_handle_irq);