intc.c 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182
  1. /*
  2. * Copyright (C) 2007-2009 Michal Simek <monstr@monstr.eu>
  3. * Copyright (C) 2007-2009 PetaLogix
  4. * Copyright (C) 2006 Atmark Techno, Inc.
  5. *
  6. * This file is subject to the terms and conditions of the GNU General Public
  7. * License. See the file "COPYING" in the main directory of this archive
  8. * for more details.
  9. */
  10. #include <linux/init.h>
  11. #include <linux/irq.h>
  12. #include <asm/page.h>
  13. #include <linux/io.h>
  14. #include <linux/bug.h>
  15. #include <asm/prom.h>
  16. #include <asm/irq.h>
  17. #ifdef CONFIG_SELFMOD_INTC
  18. #include <asm/selfmod.h>
  19. #define INTC_BASE BARRIER_BASE_ADDR
  20. #else
  21. static unsigned int intc_baseaddr;
  22. #define INTC_BASE intc_baseaddr
  23. #endif
  24. unsigned int nr_irq;
  25. /* No one else should require these constants, so define them locally here. */
  26. #define ISR 0x00 /* Interrupt Status Register */
  27. #define IPR 0x04 /* Interrupt Pending Register */
  28. #define IER 0x08 /* Interrupt Enable Register */
  29. #define IAR 0x0c /* Interrupt Acknowledge Register */
  30. #define SIE 0x10 /* Set Interrupt Enable bits */
  31. #define CIE 0x14 /* Clear Interrupt Enable bits */
  32. #define IVR 0x18 /* Interrupt Vector Register */
  33. #define MER 0x1c /* Master Enable Register */
  34. #define MER_ME (1<<0)
  35. #define MER_HIE (1<<1)
  36. static void intc_enable_or_unmask(unsigned int irq)
  37. {
  38. unsigned long mask = 1 << irq;
  39. pr_debug("enable_or_unmask: %d\n", irq);
  40. out_be32(INTC_BASE + SIE, mask);
  41. /* ack level irqs because they can't be acked during
  42. * ack function since the handle_level_irq function
  43. * acks the irq before calling the interrupt handler
  44. */
  45. if (irq_desc[irq].status & IRQ_LEVEL)
  46. out_be32(INTC_BASE + IAR, mask);
  47. }
  48. static void intc_disable_or_mask(unsigned int irq)
  49. {
  50. pr_debug("disable: %d\n", irq);
  51. out_be32(INTC_BASE + CIE, 1 << irq);
  52. }
  53. static void intc_ack(unsigned int irq)
  54. {
  55. pr_debug("ack: %d\n", irq);
  56. out_be32(INTC_BASE + IAR, 1 << irq);
  57. }
  58. static void intc_mask_ack(unsigned int irq)
  59. {
  60. unsigned long mask = 1 << irq;
  61. pr_debug("disable_and_ack: %d\n", irq);
  62. out_be32(INTC_BASE + CIE, mask);
  63. out_be32(INTC_BASE + IAR, mask);
  64. }
  65. static void intc_end(unsigned int irq)
  66. {
  67. unsigned long mask = 1 << irq;
  68. pr_debug("end: %d\n", irq);
  69. if (!(irq_desc[irq].status & (IRQ_DISABLED | IRQ_INPROGRESS))) {
  70. out_be32(INTC_BASE + SIE, mask);
  71. /* ack level sensitive intr */
  72. if (irq_desc[irq].status & IRQ_LEVEL)
  73. out_be32(INTC_BASE + IAR, mask);
  74. }
  75. }
  76. static struct irq_chip intc_dev = {
  77. .name = "Xilinx INTC",
  78. .unmask = intc_enable_or_unmask,
  79. .mask = intc_disable_or_mask,
  80. .ack = intc_ack,
  81. .mask_ack = intc_mask_ack,
  82. .end = intc_end,
  83. };
  84. unsigned int get_irq(struct pt_regs *regs)
  85. {
  86. int irq;
  87. /*
  88. * NOTE: This function is the one that needs to be improved in
  89. * order to handle multiple interrupt controllers. It currently
  90. * is hardcoded to check for interrupts only on the first INTC.
  91. */
  92. irq = in_be32(INTC_BASE + IVR);
  93. pr_debug("get_irq: %d\n", irq);
  94. return irq;
  95. }
  96. void __init init_IRQ(void)
  97. {
  98. u32 i, j, intr_type;
  99. struct device_node *intc = NULL;
  100. #ifdef CONFIG_SELFMOD_INTC
  101. unsigned int intc_baseaddr = 0;
  102. static int arr_func[] = {
  103. (int)&get_irq,
  104. (int)&intc_enable_or_unmask,
  105. (int)&intc_disable_or_mask,
  106. (int)&intc_mask_ack,
  107. (int)&intc_ack,
  108. (int)&intc_end,
  109. 0
  110. };
  111. #endif
  112. static char *intc_list[] = {
  113. "xlnx,xps-intc-1.00.a",
  114. "xlnx,opb-intc-1.00.c",
  115. "xlnx,opb-intc-1.00.b",
  116. "xlnx,opb-intc-1.00.a",
  117. NULL
  118. };
  119. for (j = 0; intc_list[j] != NULL; j++) {
  120. intc = of_find_compatible_node(NULL, NULL, intc_list[j]);
  121. if (intc)
  122. break;
  123. }
  124. BUG_ON(!intc);
  125. intc_baseaddr = *(int *) of_get_property(intc, "reg", NULL);
  126. intc_baseaddr = (unsigned long) ioremap(intc_baseaddr, PAGE_SIZE);
  127. nr_irq = *(int *) of_get_property(intc, "xlnx,num-intr-inputs", NULL);
  128. intr_type =
  129. *(int *) of_get_property(intc, "xlnx,kind-of-intr", NULL);
  130. if (intr_type >= (1 << (nr_irq + 1)))
  131. printk(KERN_INFO " ERROR: Mismatch in kind-of-intr param\n");
  132. #ifdef CONFIG_SELFMOD_INTC
  133. selfmod_function((int *) arr_func, intc_baseaddr);
  134. #endif
  135. printk(KERN_INFO "%s #0 at 0x%08x, num_irq=%d, edge=0x%x\n",
  136. intc_list[j], intc_baseaddr, nr_irq, intr_type);
  137. /*
  138. * Disable all external interrupts until they are
  139. * explicity requested.
  140. */
  141. out_be32(intc_baseaddr + IER, 0);
  142. /* Acknowledge any pending interrupts just in case. */
  143. out_be32(intc_baseaddr + IAR, 0xffffffff);
  144. /* Turn on the Master Enable. */
  145. out_be32(intc_baseaddr + MER, MER_HIE | MER_ME);
  146. for (i = 0; i < nr_irq; ++i) {
  147. if (intr_type & (0x00000001 << i)) {
  148. set_irq_chip_and_handler_name(i, &intc_dev,
  149. handle_edge_irq, intc_dev.name);
  150. irq_desc[i].status &= ~IRQ_LEVEL;
  151. } else {
  152. set_irq_chip_and_handler_name(i, &intc_dev,
  153. handle_level_irq, intc_dev.name);
  154. irq_desc[i].status |= IRQ_LEVEL;
  155. }
  156. }
  157. }