uart-irq.c 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145
  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 <linux/sched.h>
  19. #include <linux/kernel_stat.h>
  20. #include <asm/io.h>
  21. #include <asm/irq.h>
  22. #include "ocelot_c_fpga.h"
  23. static inline int ls1bit8(unsigned int x)
  24. {
  25. int b = 7, s;
  26. s = 4; if (((unsigned char)(x << 4)) == 0) s = 0; b -= s; x <<= s;
  27. s = 2; if (((unsigned char)(x << 2)) == 0) s = 0; b -= s; x <<= s;
  28. s = 1; if (((unsigned char)(x << 1)) == 0) s = 0; b -= s;
  29. return b;
  30. }
  31. /* mask off an interrupt -- 0 is enable, 1 is disable */
  32. static inline void mask_uart_irq(unsigned int irq)
  33. {
  34. uint8_t value;
  35. value = OCELOT_FPGA_READ(UART_INTMASK);
  36. value |= 1 << (irq - 74);
  37. OCELOT_FPGA_WRITE(value, UART_INTMASK);
  38. /* read the value back to assure that it's really been written */
  39. value = OCELOT_FPGA_READ(UART_INTMASK);
  40. }
  41. /* unmask an interrupt -- 0 is enable, 1 is disable */
  42. static inline void unmask_uart_irq(unsigned int irq)
  43. {
  44. uint8_t value;
  45. value = OCELOT_FPGA_READ(UART_INTMASK);
  46. value &= ~(1 << (irq - 74));
  47. OCELOT_FPGA_WRITE(value, UART_INTMASK);
  48. /* read the value back to assure that it's really been written */
  49. value = OCELOT_FPGA_READ(UART_INTMASK);
  50. }
  51. /*
  52. * Enables the IRQ in the FPGA
  53. */
  54. static void enable_uart_irq(unsigned int irq)
  55. {
  56. unmask_uart_irq(irq);
  57. }
  58. /*
  59. * Initialize the IRQ in the FPGA
  60. */
  61. static unsigned int startup_uart_irq(unsigned int irq)
  62. {
  63. unmask_uart_irq(irq);
  64. return 0;
  65. }
  66. /*
  67. * Disables the IRQ in the FPGA
  68. */
  69. static void disable_uart_irq(unsigned int irq)
  70. {
  71. mask_uart_irq(irq);
  72. }
  73. /*
  74. * Masks and ACKs an IRQ
  75. */
  76. static void mask_and_ack_uart_irq(unsigned int irq)
  77. {
  78. mask_uart_irq(irq);
  79. }
  80. /*
  81. * End IRQ processing
  82. */
  83. static void end_uart_irq(unsigned int irq)
  84. {
  85. if (!(irq_desc[irq].status & (IRQ_DISABLED|IRQ_INPROGRESS)))
  86. unmask_uart_irq(irq);
  87. }
  88. /*
  89. * Interrupt handler for interrupts coming from the FPGA chip.
  90. */
  91. void ll_uart_irq(void)
  92. {
  93. unsigned int irq_src, irq_mask;
  94. /* read the interrupt status registers */
  95. irq_src = OCELOT_FPGA_READ(UART_INTSTAT);
  96. irq_mask = OCELOT_FPGA_READ(UART_INTMASK);
  97. /* mask for just the interrupts we want */
  98. irq_src &= ~irq_mask;
  99. do_IRQ(ls1bit8(irq_src) + 74);
  100. }
  101. #define shutdown_uart_irq disable_uart_irq
  102. struct irq_chip uart_irq_type = {
  103. .typename = "UART/FPGA",
  104. .startup = startup_uart_irq,
  105. .shutdown = shutdown_uart_irq,
  106. .enable = enable_uart_irq,
  107. .disable = disable_uart_irq,
  108. .ack = mask_and_ack_uart_irq,
  109. .end = end_uart_irq,
  110. };
  111. void uart_irq_init(void)
  112. {
  113. /* Reset irq handlers pointers to NULL */
  114. irq_desc[80].status = IRQ_DISABLED;
  115. irq_desc[80].action = 0;
  116. irq_desc[80].depth = 2;
  117. irq_desc[80].chip = &uart_irq_type;
  118. irq_desc[81].status = IRQ_DISABLED;
  119. irq_desc[81].action = 0;
  120. irq_desc[81].depth = 2;
  121. irq_desc[81].chip = &uart_irq_type;
  122. }