xilinx_pic.c 3.9 KB

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