xilinx_pic.c 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157
  1. /*
  2. * arch/ppc/syslib/xilinx_pic.c
  3. *
  4. * Interrupt controller driver for Xilinx Virtex-II Pro.
  5. *
  6. * Author: MontaVista Software, Inc.
  7. * source@mvista.com
  8. *
  9. * 2002-2004 (c) MontaVista Software, Inc. This file is licensed under
  10. * the terms of the GNU General Public License version 2. This program
  11. * is licensed "as is" without any warranty of any kind, whether express
  12. * or implied.
  13. */
  14. #include <linux/init.h>
  15. #include <linux/irq.h>
  16. #include <asm/io.h>
  17. #include <asm/xparameters.h>
  18. #include <asm/ibm4xx.h>
  19. /* No one else should require these constants, so define them locally here. */
  20. #define ISR 0 /* Interrupt Status Register */
  21. #define IPR 1 /* Interrupt Pending Register */
  22. #define IER 2 /* Interrupt Enable Register */
  23. #define IAR 3 /* Interrupt Acknowledge Register */
  24. #define SIE 4 /* Set Interrupt Enable bits */
  25. #define CIE 5 /* Clear Interrupt Enable bits */
  26. #define IVR 6 /* Interrupt Vector Register */
  27. #define MER 7 /* Master Enable Register */
  28. #if XPAR_XINTC_USE_DCR == 0
  29. static volatile u32 *intc;
  30. #define intc_out_be32(addr, mask) out_be32((addr), (mask))
  31. #define intc_in_be32(addr) in_be32((addr))
  32. #else
  33. #define intc XPAR_INTC_0_BASEADDR
  34. #define intc_out_be32(addr, mask) mtdcr((addr), (mask))
  35. #define intc_in_be32(addr) mfdcr((addr))
  36. #endif
  37. static void
  38. xilinx_intc_enable(unsigned int irq)
  39. {
  40. unsigned long mask = (0x00000001 << (irq & 31));
  41. pr_debug("enable: %d\n", irq);
  42. intc_out_be32(intc + SIE, mask);
  43. }
  44. static void
  45. xilinx_intc_disable(unsigned int irq)
  46. {
  47. unsigned long mask = (0x00000001 << (irq & 31));
  48. pr_debug("disable: %d\n", irq);
  49. intc_out_be32(intc + CIE, mask);
  50. }
  51. static void
  52. xilinx_intc_disable_and_ack(unsigned int irq)
  53. {
  54. unsigned long mask = (0x00000001 << (irq & 31));
  55. pr_debug("disable_and_ack: %d\n", irq);
  56. intc_out_be32(intc + CIE, mask);
  57. if (!(irq_desc[irq].status & IRQ_LEVEL))
  58. intc_out_be32(intc + IAR, mask); /* ack edge triggered intr */
  59. }
  60. static void
  61. xilinx_intc_end(unsigned int irq)
  62. {
  63. unsigned long mask = (0x00000001 << (irq & 31));
  64. pr_debug("end: %d\n", irq);
  65. if (!(irq_desc[irq].status & (IRQ_DISABLED | IRQ_INPROGRESS))) {
  66. intc_out_be32(intc + SIE, mask);
  67. /* ack level sensitive intr */
  68. if (irq_desc[irq].status & IRQ_LEVEL)
  69. intc_out_be32(intc + IAR, mask);
  70. }
  71. }
  72. static struct hw_interrupt_type xilinx_intc = {
  73. "Xilinx Interrupt Controller",
  74. NULL,
  75. NULL,
  76. xilinx_intc_enable,
  77. xilinx_intc_disable,
  78. xilinx_intc_disable_and_ack,
  79. xilinx_intc_end,
  80. 0
  81. };
  82. int
  83. xilinx_pic_get_irq(struct pt_regs *regs)
  84. {
  85. int irq;
  86. /*
  87. * NOTE: This function is the one that needs to be improved in
  88. * order to handle multiple interrupt controllers. It currently
  89. * is hardcoded to check for interrupts only on the first INTC.
  90. */
  91. irq = intc_in_be32(intc + IVR);
  92. if (irq != -1)
  93. irq = irq;
  94. pr_debug("get_irq: %d\n", irq);
  95. return (irq);
  96. }
  97. void __init
  98. ppc4xx_pic_init(void)
  99. {
  100. int i;
  101. /*
  102. * NOTE: The assumption here is that NR_IRQS is 32 or less
  103. * (NR_IRQS is 32 for PowerPC 405 cores by default).
  104. */
  105. #if (NR_IRQS > 32)
  106. #error NR_IRQS > 32 not supported
  107. #endif
  108. #if XPAR_XINTC_USE_DCR == 0
  109. intc = ioremap(XPAR_INTC_0_BASEADDR, 32);
  110. printk(KERN_INFO "Xilinx INTC #0 at 0x%08lX mapped to 0x%08lX\n",
  111. (unsigned long) XPAR_INTC_0_BASEADDR, (unsigned long) intc);
  112. #else
  113. printk(KERN_INFO "Xilinx INTC #0 at 0x%08lX (DCR)\n",
  114. (unsigned long) XPAR_INTC_0_BASEADDR);
  115. #endif
  116. /*
  117. * Disable all external interrupts until they are
  118. * explicity requested.
  119. */
  120. intc_out_be32(intc + IER, 0);
  121. /* Acknowledge any pending interrupts just in case. */
  122. intc_out_be32(intc + IAR, ~(u32) 0);
  123. /* Turn on the Master Enable. */
  124. intc_out_be32(intc + MER, 0x3UL);
  125. ppc_md.get_irq = xilinx_pic_get_irq;
  126. for (i = 0; i < NR_IRQS; ++i) {
  127. irq_desc[i].handler = &xilinx_intc;
  128. if (XPAR_INTC_0_KIND_OF_INTR & (0x00000001 << i))
  129. irq_desc[i].status &= ~IRQ_LEVEL;
  130. else
  131. irq_desc[i].status |= IRQ_LEVEL;
  132. }
  133. }