intc.c 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160
  1. /*
  2. * Copyright (C) 2007-2013 Michal Simek <monstr@monstr.eu>
  3. * Copyright (C) 2012-2013 Xilinx, Inc.
  4. * Copyright (C) 2007-2009 PetaLogix
  5. * Copyright (C) 2006 Atmark Techno, Inc.
  6. *
  7. * This file is subject to the terms and conditions of the GNU General Public
  8. * License. See the file "COPYING" in the main directory of this archive
  9. * for more details.
  10. */
  11. #include <linux/init.h>
  12. #include <linux/irqdomain.h>
  13. #include <linux/irq.h>
  14. #include <asm/page.h>
  15. #include <linux/io.h>
  16. #include <linux/bug.h>
  17. #include <asm/prom.h>
  18. #include <asm/irq.h>
  19. #include "../../drivers/irqchip/irqchip.h"
  20. static unsigned int intc_baseaddr;
  21. /* No one else should require these constants, so define them locally here. */
  22. #define ISR 0x00 /* Interrupt Status Register */
  23. #define IPR 0x04 /* Interrupt Pending Register */
  24. #define IER 0x08 /* Interrupt Enable Register */
  25. #define IAR 0x0c /* Interrupt Acknowledge Register */
  26. #define SIE 0x10 /* Set Interrupt Enable bits */
  27. #define CIE 0x14 /* Clear Interrupt Enable bits */
  28. #define IVR 0x18 /* Interrupt Vector Register */
  29. #define MER 0x1c /* Master Enable Register */
  30. #define MER_ME (1<<0)
  31. #define MER_HIE (1<<1)
  32. static void intc_enable_or_unmask(struct irq_data *d)
  33. {
  34. unsigned long mask = 1 << d->hwirq;
  35. pr_debug("enable_or_unmask: %ld\n", d->hwirq);
  36. /* ack level irqs because they can't be acked during
  37. * ack function since the handle_level_irq function
  38. * acks the irq before calling the interrupt handler
  39. */
  40. if (irqd_is_level_type(d))
  41. out_be32(intc_baseaddr + IAR, mask);
  42. out_be32(intc_baseaddr + SIE, mask);
  43. }
  44. static void intc_disable_or_mask(struct irq_data *d)
  45. {
  46. pr_debug("disable: %ld\n", d->hwirq);
  47. out_be32(intc_baseaddr + CIE, 1 << d->hwirq);
  48. }
  49. static void intc_ack(struct irq_data *d)
  50. {
  51. pr_debug("ack: %ld\n", d->hwirq);
  52. out_be32(intc_baseaddr + IAR, 1 << d->hwirq);
  53. }
  54. static void intc_mask_ack(struct irq_data *d)
  55. {
  56. unsigned long mask = 1 << d->hwirq;
  57. pr_debug("disable_and_ack: %ld\n", d->hwirq);
  58. out_be32(intc_baseaddr + CIE, mask);
  59. out_be32(intc_baseaddr + IAR, mask);
  60. }
  61. static struct irq_chip intc_dev = {
  62. .name = "Xilinx INTC",
  63. .irq_unmask = intc_enable_or_unmask,
  64. .irq_mask = intc_disable_or_mask,
  65. .irq_ack = intc_ack,
  66. .irq_mask_ack = intc_mask_ack,
  67. };
  68. static struct irq_domain *root_domain;
  69. unsigned int get_irq(void)
  70. {
  71. unsigned int hwirq, irq = -1;
  72. hwirq = in_be32(intc_baseaddr + IVR);
  73. if (hwirq != -1U)
  74. irq = irq_find_mapping(root_domain, hwirq);
  75. pr_debug("get_irq: hwirq=%d, irq=%d\n", hwirq, irq);
  76. return irq;
  77. }
  78. static int xintc_map(struct irq_domain *d, unsigned int irq, irq_hw_number_t hw)
  79. {
  80. u32 intr_mask = (u32)d->host_data;
  81. if (intr_mask & (1 << hw)) {
  82. irq_set_chip_and_handler_name(irq, &intc_dev,
  83. handle_edge_irq, "edge");
  84. irq_clear_status_flags(irq, IRQ_LEVEL);
  85. } else {
  86. irq_set_chip_and_handler_name(irq, &intc_dev,
  87. handle_level_irq, "level");
  88. irq_set_status_flags(irq, IRQ_LEVEL);
  89. }
  90. return 0;
  91. }
  92. static const struct irq_domain_ops xintc_irq_domain_ops = {
  93. .xlate = irq_domain_xlate_onetwocell,
  94. .map = xintc_map,
  95. };
  96. static int __init xilinx_intc_of_init(struct device_node *intc,
  97. struct device_node *parent)
  98. {
  99. u32 nr_irq, intr_mask;
  100. intc_baseaddr = be32_to_cpup(of_get_property(intc, "reg", NULL));
  101. intc_baseaddr = (unsigned long) ioremap(intc_baseaddr, PAGE_SIZE);
  102. nr_irq = be32_to_cpup(of_get_property(intc,
  103. "xlnx,num-intr-inputs", NULL));
  104. intr_mask =
  105. be32_to_cpup(of_get_property(intc, "xlnx,kind-of-intr", NULL));
  106. if (intr_mask > (u32)((1ULL << nr_irq) - 1))
  107. pr_info(" ERROR: Mismatch in kind-of-intr param\n");
  108. pr_info("%s #0 at 0x%08x, num_irq=%d, edge=0x%x\n",
  109. intc->name, intc_baseaddr, nr_irq, intr_mask);
  110. /*
  111. * Disable all external interrupts until they are
  112. * explicity requested.
  113. */
  114. out_be32(intc_baseaddr + IER, 0);
  115. /* Acknowledge any pending interrupts just in case. */
  116. out_be32(intc_baseaddr + IAR, 0xffffffff);
  117. /* Turn on the Master Enable. */
  118. out_be32(intc_baseaddr + MER, MER_HIE | MER_ME);
  119. /* Yeah, okay, casting the intr_mask to a void* is butt-ugly, but I'm
  120. * lazy and Michal can clean it up to something nicer when he tests
  121. * and commits this patch. ~~gcl */
  122. root_domain = irq_domain_add_linear(intc, nr_irq, &xintc_irq_domain_ops,
  123. (void *)intr_mask);
  124. irq_set_default_host(root_domain);
  125. return 0;
  126. }
  127. IRQCHIP_DECLARE(xilinx_intc, "xlnx,xps-intc-1.00.a", xilinx_intc_of_init);