intc.c 4.3 KB

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