xilinx_intc.c 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157
  1. /*
  2. * Interrupt controller driver for Xilinx Virtex FPGAs
  3. *
  4. * Copyright (C) 2007 Secret Lab Technologies Ltd.
  5. *
  6. * This file is licensed under the terms of the GNU General Public License
  7. * version 2. This program is licensed "as is" without any warranty of any
  8. * kind, whether express or implied.
  9. *
  10. */
  11. /*
  12. * This is a driver for the interrupt controller typically found in
  13. * Xilinx Virtex FPGA designs.
  14. *
  15. * The interrupt sense levels are hard coded into the FPGA design with
  16. * typically a 1:1 relationship between irq lines and devices (no shared
  17. * irq lines). Therefore, this driver does not attempt to handle edge
  18. * and level interrupts differently.
  19. */
  20. #undef DEBUG
  21. #include <linux/kernel.h>
  22. #include <linux/irq.h>
  23. #include <linux/of.h>
  24. #include <asm/io.h>
  25. #include <asm/processor.h>
  26. #include <asm/irq.h>
  27. /*
  28. * INTC Registers
  29. */
  30. #define XINTC_ISR 0 /* Interrupt Status */
  31. #define XINTC_IPR 4 /* Interrupt Pending */
  32. #define XINTC_IER 8 /* Interrupt Enable */
  33. #define XINTC_IAR 12 /* Interrupt Acknowledge */
  34. #define XINTC_SIE 16 /* Set Interrupt Enable bits */
  35. #define XINTC_CIE 20 /* Clear Interrupt Enable bits */
  36. #define XINTC_IVR 24 /* Interrupt Vector */
  37. #define XINTC_MER 28 /* Master Enable */
  38. static struct irq_host *master_irqhost;
  39. /*
  40. * IRQ Chip operations
  41. */
  42. static void xilinx_intc_mask(unsigned int virq)
  43. {
  44. int irq = virq_to_hw(virq);
  45. void * regs = get_irq_chip_data(virq);
  46. pr_debug("mask: %d\n", irq);
  47. out_be32(regs + XINTC_CIE, 1 << irq);
  48. }
  49. static void xilinx_intc_unmask(unsigned int virq)
  50. {
  51. int irq = virq_to_hw(virq);
  52. void * regs = get_irq_chip_data(virq);
  53. pr_debug("unmask: %d\n", irq);
  54. out_be32(regs + XINTC_SIE, 1 << irq);
  55. }
  56. static void xilinx_intc_ack(unsigned int virq)
  57. {
  58. int irq = virq_to_hw(virq);
  59. void * regs = get_irq_chip_data(virq);
  60. pr_debug("ack: %d\n", irq);
  61. out_be32(regs + XINTC_IAR, 1 << irq);
  62. }
  63. static struct irq_chip xilinx_intc_irqchip = {
  64. .typename = "Xilinx INTC",
  65. .mask = xilinx_intc_mask,
  66. .unmask = xilinx_intc_unmask,
  67. .ack = xilinx_intc_ack,
  68. };
  69. /*
  70. * IRQ Host operations
  71. */
  72. static int xilinx_intc_map(struct irq_host *h, unsigned int virq,
  73. irq_hw_number_t irq)
  74. {
  75. set_irq_chip_data(virq, h->host_data);
  76. set_irq_chip_and_handler(virq, &xilinx_intc_irqchip, handle_level_irq);
  77. set_irq_type(virq, IRQ_TYPE_NONE);
  78. return 0;
  79. }
  80. static struct irq_host_ops xilinx_intc_ops = {
  81. .map = xilinx_intc_map,
  82. };
  83. struct irq_host * __init
  84. xilinx_intc_init(struct device_node *np)
  85. {
  86. struct irq_host * irq;
  87. struct resource res;
  88. void * regs;
  89. int rc;
  90. /* Find and map the intc registers */
  91. rc = of_address_to_resource(np, 0, &res);
  92. if (rc) {
  93. printk(KERN_ERR __FILE__ ": of_address_to_resource() failed\n");
  94. return NULL;
  95. }
  96. regs = ioremap(res.start, 32);
  97. printk(KERN_INFO "Xilinx intc at 0x%08LX mapped to 0x%p\n",
  98. res.start, regs);
  99. /* Setup interrupt controller */
  100. out_be32(regs + XINTC_IER, 0); /* disable all irqs */
  101. out_be32(regs + XINTC_IAR, ~(u32) 0); /* Acknowledge pending irqs */
  102. out_be32(regs + XINTC_MER, 0x3UL); /* Turn on the Master Enable. */
  103. /* Allocate and initialize an irq_host structure. */
  104. irq = irq_alloc_host(np, IRQ_HOST_MAP_LINEAR, 32, &xilinx_intc_ops, -1);
  105. if (!irq)
  106. panic(__FILE__ ": Cannot allocate IRQ host\n");
  107. irq->host_data = regs;
  108. return irq;
  109. }
  110. int xilinx_intc_get_irq(void)
  111. {
  112. void * regs = master_irqhost->host_data;
  113. pr_debug("get_irq:\n");
  114. return irq_linear_revmap(master_irqhost, in_be32(regs + XINTC_IVR));
  115. }
  116. void __init xilinx_intc_init_tree(void)
  117. {
  118. struct device_node *np;
  119. /* find top level interrupt controller */
  120. for_each_compatible_node(np, NULL, "xlnx,opb-intc-1.00.c") {
  121. if (!of_get_property(np, "interrupts", NULL))
  122. break;
  123. }
  124. if (!np) {
  125. for_each_compatible_node(np, NULL, "xlnx,xps-intc-1.00.a") {
  126. if (!of_get_property(np, "interrupts", NULL))
  127. break;
  128. }
  129. }
  130. /* xilinx interrupt controller needs to be top level */
  131. BUG_ON(!np);
  132. master_irqhost = xilinx_intc_init(np);
  133. BUG_ON(!master_irqhost);
  134. irq_set_default_host(master_irqhost);
  135. of_node_put(np);
  136. }