irq.c 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149
  1. /*
  2. * Copyright (C) 2011 Google, Inc.
  3. *
  4. * Author:
  5. * Colin Cross <ccross@android.com>
  6. *
  7. * Copyright (C) 2010, NVIDIA Corporation
  8. *
  9. * This software is licensed under the terms of the GNU General Public
  10. * License version 2, as published by the Free Software Foundation, and
  11. * may be copied, distributed, and modified under those terms.
  12. *
  13. * This program is distributed in the hope that it will be useful,
  14. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  15. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  16. * GNU General Public License for more details.
  17. *
  18. */
  19. #include <linux/kernel.h>
  20. #include <linux/interrupt.h>
  21. #include <linux/irq.h>
  22. #include <linux/io.h>
  23. #include <linux/of.h>
  24. #include <asm/hardware/gic.h>
  25. #include <mach/iomap.h>
  26. #include "board.h"
  27. #define ICTLR_CPU_IEP_VFIQ 0x08
  28. #define ICTLR_CPU_IEP_FIR 0x14
  29. #define ICTLR_CPU_IEP_FIR_SET 0x18
  30. #define ICTLR_CPU_IEP_FIR_CLR 0x1c
  31. #define ICTLR_CPU_IER 0x20
  32. #define ICTLR_CPU_IER_SET 0x24
  33. #define ICTLR_CPU_IER_CLR 0x28
  34. #define ICTLR_CPU_IEP_CLASS 0x2C
  35. #define ICTLR_COP_IER 0x30
  36. #define ICTLR_COP_IER_SET 0x34
  37. #define ICTLR_COP_IER_CLR 0x38
  38. #define ICTLR_COP_IEP_CLASS 0x3c
  39. #define FIRST_LEGACY_IRQ 32
  40. static int num_ictlrs;
  41. static void __iomem *ictlr_reg_base[] = {
  42. IO_ADDRESS(TEGRA_PRIMARY_ICTLR_BASE),
  43. IO_ADDRESS(TEGRA_SECONDARY_ICTLR_BASE),
  44. IO_ADDRESS(TEGRA_TERTIARY_ICTLR_BASE),
  45. IO_ADDRESS(TEGRA_QUATERNARY_ICTLR_BASE),
  46. IO_ADDRESS(TEGRA_QUINARY_ICTLR_BASE),
  47. };
  48. static inline void tegra_irq_write_mask(unsigned int irq, unsigned long reg)
  49. {
  50. void __iomem *base;
  51. u32 mask;
  52. BUG_ON(irq < FIRST_LEGACY_IRQ ||
  53. irq >= FIRST_LEGACY_IRQ + num_ictlrs * 32);
  54. base = ictlr_reg_base[(irq - FIRST_LEGACY_IRQ) / 32];
  55. mask = BIT((irq - FIRST_LEGACY_IRQ) % 32);
  56. __raw_writel(mask, base + reg);
  57. }
  58. static void tegra_mask(struct irq_data *d)
  59. {
  60. if (d->irq < FIRST_LEGACY_IRQ)
  61. return;
  62. tegra_irq_write_mask(d->irq, ICTLR_CPU_IER_CLR);
  63. }
  64. static void tegra_unmask(struct irq_data *d)
  65. {
  66. if (d->irq < FIRST_LEGACY_IRQ)
  67. return;
  68. tegra_irq_write_mask(d->irq, ICTLR_CPU_IER_SET);
  69. }
  70. static void tegra_ack(struct irq_data *d)
  71. {
  72. if (d->irq < FIRST_LEGACY_IRQ)
  73. return;
  74. tegra_irq_write_mask(d->irq, ICTLR_CPU_IEP_FIR_CLR);
  75. }
  76. static void tegra_eoi(struct irq_data *d)
  77. {
  78. if (d->irq < FIRST_LEGACY_IRQ)
  79. return;
  80. tegra_irq_write_mask(d->irq, ICTLR_CPU_IEP_FIR_CLR);
  81. }
  82. static int tegra_retrigger(struct irq_data *d)
  83. {
  84. if (d->irq < FIRST_LEGACY_IRQ)
  85. return 0;
  86. tegra_irq_write_mask(d->irq, ICTLR_CPU_IEP_FIR_SET);
  87. return 1;
  88. }
  89. void __init tegra_init_irq(void)
  90. {
  91. int i;
  92. void __iomem *distbase;
  93. distbase = IO_ADDRESS(TEGRA_ARM_INT_DIST_BASE);
  94. num_ictlrs = readl_relaxed(distbase + GIC_DIST_CTR) & 0x1f;
  95. if (num_ictlrs > ARRAY_SIZE(ictlr_reg_base)) {
  96. WARN(1, "Too many (%d) interrupt controllers found. Maximum is %d.",
  97. num_ictlrs, ARRAY_SIZE(ictlr_reg_base));
  98. num_ictlrs = ARRAY_SIZE(ictlr_reg_base);
  99. }
  100. for (i = 0; i < num_ictlrs; i++) {
  101. void __iomem *ictlr = ictlr_reg_base[i];
  102. writel(~0, ictlr + ICTLR_CPU_IER_CLR);
  103. writel(0, ictlr + ICTLR_CPU_IEP_CLASS);
  104. }
  105. gic_arch_extn.irq_ack = tegra_ack;
  106. gic_arch_extn.irq_eoi = tegra_eoi;
  107. gic_arch_extn.irq_mask = tegra_mask;
  108. gic_arch_extn.irq_unmask = tegra_unmask;
  109. gic_arch_extn.irq_retrigger = tegra_retrigger;
  110. /*
  111. * Check if there is a devicetree present, since the GIC will be
  112. * initialized elsewhere under DT.
  113. */
  114. if (!of_have_populated_dt())
  115. gic_init(0, 29, distbase,
  116. IO_ADDRESS(TEGRA_ARM_PERIF_BASE + 0x100));
  117. }