intc.c 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174
  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. pr_debug("enable_or_unmask: %d\n", irq);
  39. out_be32(INTC_BASE + SIE, 1 << irq);
  40. }
  41. static void intc_disable_or_mask(unsigned int irq)
  42. {
  43. pr_debug("disable: %d\n", irq);
  44. out_be32(INTC_BASE + CIE, 1 << irq);
  45. }
  46. static void intc_ack(unsigned int irq)
  47. {
  48. pr_debug("ack: %d\n", irq);
  49. out_be32(INTC_BASE + IAR, 1 << irq);
  50. }
  51. static void intc_mask_ack(unsigned int irq)
  52. {
  53. unsigned long mask = 1 << irq;
  54. pr_debug("disable_and_ack: %d\n", irq);
  55. out_be32(INTC_BASE + CIE, mask);
  56. out_be32(INTC_BASE + IAR, mask);
  57. }
  58. static void intc_end(unsigned int irq)
  59. {
  60. unsigned long mask = 1 << irq;
  61. pr_debug("end: %d\n", irq);
  62. if (!(irq_desc[irq].status & (IRQ_DISABLED | IRQ_INPROGRESS))) {
  63. out_be32(INTC_BASE + SIE, mask);
  64. /* ack level sensitive intr */
  65. if (irq_desc[irq].status & IRQ_LEVEL)
  66. out_be32(INTC_BASE + IAR, mask);
  67. }
  68. }
  69. static struct irq_chip intc_dev = {
  70. .name = "Xilinx INTC",
  71. .unmask = intc_enable_or_unmask,
  72. .mask = intc_disable_or_mask,
  73. .ack = intc_ack,
  74. .mask_ack = intc_mask_ack,
  75. .end = intc_end,
  76. };
  77. unsigned int get_irq(struct pt_regs *regs)
  78. {
  79. int irq;
  80. /*
  81. * NOTE: This function is the one that needs to be improved in
  82. * order to handle multiple interrupt controllers. It currently
  83. * is hardcoded to check for interrupts only on the first INTC.
  84. */
  85. irq = in_be32(INTC_BASE + IVR);
  86. pr_debug("get_irq: %d\n", irq);
  87. return irq;
  88. }
  89. void __init init_IRQ(void)
  90. {
  91. u32 i, j, intr_type;
  92. struct device_node *intc = NULL;
  93. #ifdef CONFIG_SELFMOD_INTC
  94. unsigned int intc_baseaddr = 0;
  95. static int arr_func[] = {
  96. (int)&get_irq,
  97. (int)&intc_enable_or_unmask,
  98. (int)&intc_disable_or_mask,
  99. (int)&intc_mask_ack,
  100. (int)&intc_ack,
  101. (int)&intc_end,
  102. 0
  103. };
  104. #endif
  105. static char *intc_list[] = {
  106. "xlnx,xps-intc-1.00.a",
  107. "xlnx,opb-intc-1.00.c",
  108. "xlnx,opb-intc-1.00.b",
  109. "xlnx,opb-intc-1.00.a",
  110. NULL
  111. };
  112. for (j = 0; intc_list[j] != NULL; j++) {
  113. intc = of_find_compatible_node(NULL, NULL, intc_list[j]);
  114. if (intc)
  115. break;
  116. }
  117. BUG_ON(!intc);
  118. intc_baseaddr = *(int *) of_get_property(intc, "reg", NULL);
  119. intc_baseaddr = (unsigned long) ioremap(intc_baseaddr, PAGE_SIZE);
  120. nr_irq = *(int *) of_get_property(intc, "xlnx,num-intr-inputs", NULL);
  121. intr_type =
  122. *(int *) of_get_property(intc, "xlnx,kind-of-intr", NULL);
  123. if (intr_type >= (1 << (nr_irq + 1)))
  124. printk(KERN_INFO " ERROR: Mismatch in kind-of-intr param\n");
  125. #ifdef CONFIG_SELFMOD_INTC
  126. selfmod_function((int *) arr_func, intc_baseaddr);
  127. #endif
  128. printk(KERN_INFO "%s #0 at 0x%08x, num_irq=%d, edge=0x%x\n",
  129. intc_list[j], intc_baseaddr, nr_irq, intr_type);
  130. /*
  131. * Disable all external interrupts until they are
  132. * explicity requested.
  133. */
  134. out_be32(intc_baseaddr + IER, 0);
  135. /* Acknowledge any pending interrupts just in case. */
  136. out_be32(intc_baseaddr + IAR, 0xffffffff);
  137. /* Turn on the Master Enable. */
  138. out_be32(intc_baseaddr + MER, MER_HIE | MER_ME);
  139. for (i = 0; i < nr_irq; ++i) {
  140. if (intr_type & (0x00000001 << i)) {
  141. set_irq_chip_and_handler_name(i, &intc_dev,
  142. handle_edge_irq, intc_dev.name);
  143. irq_desc[i].status &= ~IRQ_LEVEL;
  144. } else {
  145. set_irq_chip_and_handler_name(i, &intc_dev,
  146. handle_level_irq, intc_dev.name);
  147. irq_desc[i].status |= IRQ_LEVEL;
  148. }
  149. }
  150. }