icoll.c 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125
  1. /*
  2. * Copyright (C) 2009-2010 Freescale Semiconductor, Inc. All Rights Reserved.
  3. *
  4. * This program is free software; you can redistribute it and/or modify
  5. * it under the terms of the GNU General Public License as published by
  6. * the Free Software Foundation; either version 2 of the License, or
  7. * (at your option) any later version.
  8. *
  9. * This program is distributed in the hope that it will be useful,
  10. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  12. * GNU General Public License for more details.
  13. *
  14. * You should have received a copy of the GNU General Public License along
  15. * with this program; if not, write to the Free Software Foundation, Inc.,
  16. * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
  17. */
  18. #include <linux/kernel.h>
  19. #include <linux/init.h>
  20. #include <linux/irq.h>
  21. #include <linux/irqdomain.h>
  22. #include <linux/io.h>
  23. #include <linux/of.h>
  24. #include <linux/of_irq.h>
  25. #include <asm/exception.h>
  26. #include <mach/mxs.h>
  27. #include <mach/common.h>
  28. #define HW_ICOLL_VECTOR 0x0000
  29. #define HW_ICOLL_LEVELACK 0x0010
  30. #define HW_ICOLL_CTRL 0x0020
  31. #define HW_ICOLL_STAT_OFFSET 0x0070
  32. #define HW_ICOLL_INTERRUPTn_SET(n) (0x0124 + (n) * 0x10)
  33. #define HW_ICOLL_INTERRUPTn_CLR(n) (0x0128 + (n) * 0x10)
  34. #define BM_ICOLL_INTERRUPTn_ENABLE 0x00000004
  35. #define BV_ICOLL_LEVELACK_IRQLEVELACK__LEVEL0 0x1
  36. #define ICOLL_NUM_IRQS 128
  37. static void __iomem *icoll_base = MXS_IO_ADDRESS(MXS_ICOLL_BASE_ADDR);
  38. static struct irq_domain *icoll_domain;
  39. static void icoll_ack_irq(struct irq_data *d)
  40. {
  41. /*
  42. * The Interrupt Collector is able to prioritize irqs.
  43. * Currently only level 0 is used. So acking can use
  44. * BV_ICOLL_LEVELACK_IRQLEVELACK__LEVEL0 unconditionally.
  45. */
  46. __raw_writel(BV_ICOLL_LEVELACK_IRQLEVELACK__LEVEL0,
  47. icoll_base + HW_ICOLL_LEVELACK);
  48. }
  49. static void icoll_mask_irq(struct irq_data *d)
  50. {
  51. __raw_writel(BM_ICOLL_INTERRUPTn_ENABLE,
  52. icoll_base + HW_ICOLL_INTERRUPTn_CLR(d->hwirq));
  53. }
  54. static void icoll_unmask_irq(struct irq_data *d)
  55. {
  56. __raw_writel(BM_ICOLL_INTERRUPTn_ENABLE,
  57. icoll_base + HW_ICOLL_INTERRUPTn_SET(d->hwirq));
  58. }
  59. static struct irq_chip mxs_icoll_chip = {
  60. .irq_ack = icoll_ack_irq,
  61. .irq_mask = icoll_mask_irq,
  62. .irq_unmask = icoll_unmask_irq,
  63. };
  64. asmlinkage void __exception_irq_entry icoll_handle_irq(struct pt_regs *regs)
  65. {
  66. u32 irqnr;
  67. do {
  68. irqnr = __raw_readl(icoll_base + HW_ICOLL_STAT_OFFSET);
  69. if (irqnr != 0x7f) {
  70. __raw_writel(irqnr, icoll_base + HW_ICOLL_VECTOR);
  71. irqnr = irq_find_mapping(icoll_domain, irqnr);
  72. handle_IRQ(irqnr, regs);
  73. continue;
  74. }
  75. break;
  76. } while (1);
  77. }
  78. static int icoll_irq_domain_map(struct irq_domain *d, unsigned int virq,
  79. irq_hw_number_t hw)
  80. {
  81. irq_set_chip_and_handler(virq, &mxs_icoll_chip, handle_level_irq);
  82. set_irq_flags(virq, IRQF_VALID);
  83. return 0;
  84. }
  85. static struct irq_domain_ops icoll_irq_domain_ops = {
  86. .map = icoll_irq_domain_map,
  87. .xlate = irq_domain_xlate_onecell,
  88. };
  89. void __init icoll_of_init(struct device_node *np,
  90. struct device_node *interrupt_parent)
  91. {
  92. /*
  93. * Interrupt Collector reset, which initializes the priority
  94. * for each irq to level 0.
  95. */
  96. mxs_reset_block(icoll_base + HW_ICOLL_CTRL);
  97. icoll_domain = irq_domain_add_linear(np, ICOLL_NUM_IRQS,
  98. &icoll_irq_domain_ops, NULL);
  99. WARN_ON(!icoll_domain);
  100. }
  101. static const struct of_device_id icoll_of_match[] __initconst = {
  102. {.compatible = "fsl,icoll", .data = icoll_of_init},
  103. { /* sentinel */ }
  104. };
  105. void __init icoll_init_irq(void)
  106. {
  107. of_irq_init(icoll_of_match);
  108. }