uart-irq.c 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147
  1. /*
  2. * Copyright 2002 Momentum Computer
  3. * Author: mdharm@momenco.com
  4. *
  5. * arch/mips/momentum/ocelot_c/uart-irq.c
  6. * Interrupt routines for UARTs. Interrupt numbers are assigned from
  7. * 80 to 81 (2 interrupt sources).
  8. *
  9. * This program is free software; you can redistribute it and/or modify it
  10. * under the terms of the GNU General Public License as published by the
  11. * Free Software Foundation; either version 2 of the License, or (at your
  12. * option) any later version.
  13. */
  14. #include <linux/module.h>
  15. #include <linux/interrupt.h>
  16. #include <linux/irq.h>
  17. #include <linux/kernel.h>
  18. #include <asm/ptrace.h>
  19. #include <linux/sched.h>
  20. #include <linux/kernel_stat.h>
  21. #include <asm/io.h>
  22. #include <asm/irq.h>
  23. #include "ocelot_c_fpga.h"
  24. static inline int ls1bit8(unsigned int x)
  25. {
  26. int b = 7, s;
  27. s = 4; if (((unsigned char)(x << 4)) == 0) s = 0; b -= s; x <<= s;
  28. s = 2; if (((unsigned char)(x << 2)) == 0) s = 0; b -= s; x <<= s;
  29. s = 1; if (((unsigned char)(x << 1)) == 0) s = 0; b -= s;
  30. return b;
  31. }
  32. /* mask off an interrupt -- 0 is enable, 1 is disable */
  33. static inline void mask_uart_irq(unsigned int irq)
  34. {
  35. uint8_t value;
  36. value = OCELOT_FPGA_READ(UART_INTMASK);
  37. value |= 1 << (irq - 74);
  38. OCELOT_FPGA_WRITE(value, UART_INTMASK);
  39. /* read the value back to assure that it's really been written */
  40. value = OCELOT_FPGA_READ(UART_INTMASK);
  41. }
  42. /* unmask an interrupt -- 0 is enable, 1 is disable */
  43. static inline void unmask_uart_irq(unsigned int irq)
  44. {
  45. uint8_t value;
  46. value = OCELOT_FPGA_READ(UART_INTMASK);
  47. value &= ~(1 << (irq - 74));
  48. OCELOT_FPGA_WRITE(value, UART_INTMASK);
  49. /* read the value back to assure that it's really been written */
  50. value = OCELOT_FPGA_READ(UART_INTMASK);
  51. }
  52. /*
  53. * Enables the IRQ in the FPGA
  54. */
  55. static void enable_uart_irq(unsigned int irq)
  56. {
  57. unmask_uart_irq(irq);
  58. }
  59. /*
  60. * Initialize the IRQ in the FPGA
  61. */
  62. static unsigned int startup_uart_irq(unsigned int irq)
  63. {
  64. unmask_uart_irq(irq);
  65. return 0;
  66. }
  67. /*
  68. * Disables the IRQ in the FPGA
  69. */
  70. static void disable_uart_irq(unsigned int irq)
  71. {
  72. mask_uart_irq(irq);
  73. }
  74. /*
  75. * Masks and ACKs an IRQ
  76. */
  77. static void mask_and_ack_uart_irq(unsigned int irq)
  78. {
  79. mask_uart_irq(irq);
  80. }
  81. /*
  82. * End IRQ processing
  83. */
  84. static void end_uart_irq(unsigned int irq)
  85. {
  86. if (!(irq_desc[irq].status & (IRQ_DISABLED|IRQ_INPROGRESS)))
  87. unmask_uart_irq(irq);
  88. }
  89. /*
  90. * Interrupt handler for interrupts coming from the FPGA chip.
  91. */
  92. void ll_uart_irq(struct pt_regs *regs)
  93. {
  94. unsigned int irq_src, irq_mask;
  95. /* read the interrupt status registers */
  96. irq_src = OCELOT_FPGA_READ(UART_INTSTAT);
  97. irq_mask = OCELOT_FPGA_READ(UART_INTMASK);
  98. /* mask for just the interrupts we want */
  99. irq_src &= ~irq_mask;
  100. do_IRQ(ls1bit8(irq_src) + 74, regs);
  101. }
  102. #define shutdown_uart_irq disable_uart_irq
  103. struct hw_interrupt_type uart_irq_type = {
  104. "UART/FPGA",
  105. startup_uart_irq,
  106. shutdown_uart_irq,
  107. enable_uart_irq,
  108. disable_uart_irq,
  109. mask_and_ack_uart_irq,
  110. end_uart_irq,
  111. NULL
  112. };
  113. void uart_irq_init(void)
  114. {
  115. /* Reset irq handlers pointers to NULL */
  116. irq_desc[80].status = IRQ_DISABLED;
  117. irq_desc[80].action = 0;
  118. irq_desc[80].depth = 2;
  119. irq_desc[80].handler = &uart_irq_type;
  120. irq_desc[81].status = IRQ_DISABLED;
  121. irq_desc[81].action = 0;
  122. irq_desc[81].depth = 2;
  123. irq_desc[81].handler = &uart_irq_type;
  124. }