cpci-irq.c 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153
  1. /*
  2. * Copyright 2002 Momentum Computer
  3. * Author: mdharm@momenco.com
  4. *
  5. * arch/mips/momentum/ocelot_c/cpci-irq.c
  6. * Interrupt routines for cpci. Interrupt numbers are assigned from
  7. * CPCI_IRQ_BASE to CPCI_IRQ_BASE+8 (8 interrupt sources).
  8. *
  9. * Note that the high-level software will need to be careful about using
  10. * these interrupts. If this board is asserting a cPCI interrupt, it will
  11. * also see the asserted interrupt. Care must be taken to avoid an
  12. * interrupt flood.
  13. *
  14. * This program is free software; you can redistribute it and/or modify it
  15. * under the terms of the GNU General Public License as published by the
  16. * Free Software Foundation; either version 2 of the License, or (at your
  17. * option) any later version.
  18. */
  19. #include <linux/module.h>
  20. #include <linux/interrupt.h>
  21. #include <linux/irq.h>
  22. #include <linux/kernel.h>
  23. #include <asm/ptrace.h>
  24. #include <linux/sched.h>
  25. #include <linux/kernel_stat.h>
  26. #include <asm/io.h>
  27. #include "ocelot_c_fpga.h"
  28. #define CPCI_IRQ_BASE 8
  29. static inline int ls1bit8(unsigned int x)
  30. {
  31. int b = 7, s;
  32. s = 4; if (((unsigned char)(x << 4)) == 0) s = 0; b -= s; x <<= s;
  33. s = 2; if (((unsigned char)(x << 2)) == 0) s = 0; b -= s; x <<= s;
  34. s = 1; if (((unsigned char)(x << 1)) == 0) s = 0; b -= s;
  35. return b;
  36. }
  37. /* mask off an interrupt -- 0 is enable, 1 is disable */
  38. static inline void mask_cpci_irq(unsigned int irq)
  39. {
  40. uint32_t value;
  41. value = OCELOT_FPGA_READ(INTMASK);
  42. value |= 1 << (irq - CPCI_IRQ_BASE);
  43. OCELOT_FPGA_WRITE(value, INTMASK);
  44. /* read the value back to assure that it's really been written */
  45. value = OCELOT_FPGA_READ(INTMASK);
  46. }
  47. /* unmask an interrupt -- 0 is enable, 1 is disable */
  48. static inline void unmask_cpci_irq(unsigned int irq)
  49. {
  50. uint32_t value;
  51. value = OCELOT_FPGA_READ(INTMASK);
  52. value &= ~(1 << (irq - CPCI_IRQ_BASE));
  53. OCELOT_FPGA_WRITE(value, INTMASK);
  54. /* read the value back to assure that it's really been written */
  55. value = OCELOT_FPGA_READ(INTMASK);
  56. }
  57. /*
  58. * Enables the IRQ in the FPGA
  59. */
  60. static void enable_cpci_irq(unsigned int irq)
  61. {
  62. unmask_cpci_irq(irq);
  63. }
  64. /*
  65. * Initialize the IRQ in the FPGA
  66. */
  67. static unsigned int startup_cpci_irq(unsigned int irq)
  68. {
  69. unmask_cpci_irq(irq);
  70. return 0;
  71. }
  72. /*
  73. * Disables the IRQ in the FPGA
  74. */
  75. static void disable_cpci_irq(unsigned int irq)
  76. {
  77. mask_cpci_irq(irq);
  78. }
  79. /*
  80. * Masks and ACKs an IRQ
  81. */
  82. static void mask_and_ack_cpci_irq(unsigned int irq)
  83. {
  84. mask_cpci_irq(irq);
  85. }
  86. /*
  87. * End IRQ processing
  88. */
  89. static void end_cpci_irq(unsigned int irq)
  90. {
  91. if (!(irq_desc[irq].status & (IRQ_DISABLED|IRQ_INPROGRESS)))
  92. unmask_cpci_irq(irq);
  93. }
  94. /*
  95. * Interrupt handler for interrupts coming from the FPGA chip.
  96. * It could be built in ethernet ports etc...
  97. */
  98. void ll_cpci_irq(struct pt_regs *regs)
  99. {
  100. unsigned int irq_src, irq_mask;
  101. /* read the interrupt status registers */
  102. irq_src = OCELOT_FPGA_READ(INTSTAT);
  103. irq_mask = OCELOT_FPGA_READ(INTMASK);
  104. /* mask for just the interrupts we want */
  105. irq_src &= ~irq_mask;
  106. do_IRQ(ls1bit8(irq_src) + CPCI_IRQ_BASE, regs);
  107. }
  108. #define shutdown_cpci_irq disable_cpci_irq
  109. struct hw_interrupt_type cpci_irq_type = {
  110. "CPCI/FPGA",
  111. startup_cpci_irq,
  112. shutdown_cpci_irq,
  113. enable_cpci_irq,
  114. disable_cpci_irq,
  115. mask_and_ack_cpci_irq,
  116. end_cpci_irq,
  117. NULL
  118. };
  119. void cpci_irq_init(void)
  120. {
  121. int i;
  122. /* Reset irq handlers pointers to NULL */
  123. for (i = CPCI_IRQ_BASE; i < (CPCI_IRQ_BASE + 8); i++) {
  124. irq_desc[i].status = IRQ_DISABLED;
  125. irq_desc[i].action = 0;
  126. irq_desc[i].depth = 2;
  127. irq_desc[i].handler = &cpci_irq_type;
  128. }
  129. }