intc.c 4.3 KB

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