8250_fsl.c 2.3 KB

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