intc.c 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175
  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/irqdomain.h>
  12. #include <linux/irq.h>
  13. #include <asm/page.h>
  14. #include <linux/io.h>
  15. #include <linux/bug.h>
  16. #include <asm/prom.h>
  17. #include <asm/irq.h>
  18. #ifdef CONFIG_SELFMOD_INTC
  19. #include <asm/selfmod.h>
  20. #define INTC_BASE BARRIER_BASE_ADDR
  21. #else
  22. static unsigned int intc_baseaddr;
  23. #define INTC_BASE intc_baseaddr
  24. #endif
  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->hwirq;
  39. pr_debug("enable_or_unmask: %ld\n", d->hwirq);
  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: %ld\n", d->hwirq);
  51. out_be32(INTC_BASE + CIE, 1 << d->hwirq);
  52. }
  53. static void intc_ack(struct irq_data *d)
  54. {
  55. pr_debug("ack: %ld\n", d->hwirq);
  56. out_be32(INTC_BASE + IAR, 1 << d->hwirq);
  57. }
  58. static void intc_mask_ack(struct irq_data *d)
  59. {
  60. unsigned long mask = 1 << d->hwirq;
  61. pr_debug("disable_and_ack: %ld\n", d->hwirq);
  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. static struct irq_domain *root_domain;
  73. unsigned int get_irq(void)
  74. {
  75. unsigned int hwirq, irq = -1;
  76. hwirq = in_be32(INTC_BASE + IVR);
  77. if (hwirq != -1U)
  78. irq = irq_find_mapping(root_domain, hwirq);
  79. pr_debug("get_irq: hwirq=%d, irq=%d\n", hwirq, irq);
  80. return irq;
  81. }
  82. int xintc_map(struct irq_domain *d, unsigned int irq, irq_hw_number_t hw)
  83. {
  84. u32 intr_mask = (u32)d->host_data;
  85. if (intr_mask & (1 << hw)) {
  86. irq_set_chip_and_handler_name(irq, &intc_dev,
  87. handle_edge_irq, "edge");
  88. irq_clear_status_flags(irq, IRQ_LEVEL);
  89. } else {
  90. irq_set_chip_and_handler_name(irq, &intc_dev,
  91. handle_level_irq, "level");
  92. irq_set_status_flags(irq, IRQ_LEVEL);
  93. }
  94. return 0;
  95. }
  96. static const struct irq_domain_ops xintc_irq_domain_ops = {
  97. .xlate = irq_domain_xlate_onetwocell,
  98. .map = xintc_map,
  99. };
  100. void __init init_IRQ(void)
  101. {
  102. u32 nr_irq, intr_mask;
  103. struct device_node *intc = NULL;
  104. #ifdef CONFIG_SELFMOD_INTC
  105. unsigned int intc_baseaddr = 0;
  106. static int arr_func[] = {
  107. (int)&get_irq,
  108. (int)&intc_enable_or_unmask,
  109. (int)&intc_disable_or_mask,
  110. (int)&intc_mask_ack,
  111. (int)&intc_ack,
  112. (int)&intc_end,
  113. 0
  114. };
  115. #endif
  116. intc = of_find_compatible_node(NULL, NULL, "xlnx,xps-intc-1.00.a");
  117. BUG_ON(!intc);
  118. intc_baseaddr = be32_to_cpup(of_get_property(intc, "reg", NULL));
  119. intc_baseaddr = (unsigned long) ioremap(intc_baseaddr, PAGE_SIZE);
  120. nr_irq = be32_to_cpup(of_get_property(intc,
  121. "xlnx,num-intr-inputs", NULL));
  122. intr_mask =
  123. be32_to_cpup(of_get_property(intc, "xlnx,kind-of-intr", NULL));
  124. if (intr_mask > (u32)((1ULL << nr_irq) - 1))
  125. printk(KERN_INFO " ERROR: Mismatch in kind-of-intr param\n");
  126. #ifdef CONFIG_SELFMOD_INTC
  127. selfmod_function((int *) arr_func, intc_baseaddr);
  128. #endif
  129. printk(KERN_INFO "%s #0 at 0x%08x, num_irq=%d, edge=0x%x\n",
  130. intc->name, intc_baseaddr, nr_irq, intr_mask);
  131. /*
  132. * Disable all external interrupts until they are
  133. * explicity requested.
  134. */
  135. out_be32(intc_baseaddr + IER, 0);
  136. /* Acknowledge any pending interrupts just in case. */
  137. out_be32(intc_baseaddr + IAR, 0xffffffff);
  138. /* Turn on the Master Enable. */
  139. out_be32(intc_baseaddr + MER, MER_HIE | MER_ME);
  140. /* Yeah, okay, casting the intr_mask to a void* is butt-ugly, but I'm
  141. * lazy and Michal can clean it up to something nicer when he tests
  142. * and commits this patch. ~~gcl */
  143. root_domain = irq_domain_add_linear(intc, nr_irq, &xintc_irq_domain_ops,
  144. (void *)intr_mask);
  145. }