irq.c 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136
  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 NUM_ICTLRS 4
  40. #define FIRST_LEGACY_IRQ 32
  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. };
  47. static inline void tegra_irq_write_mask(unsigned int irq, unsigned long reg)
  48. {
  49. void __iomem *base;
  50. u32 mask;
  51. BUG_ON(irq < FIRST_LEGACY_IRQ ||
  52. irq >= FIRST_LEGACY_IRQ + NUM_ICTLRS * 32);
  53. base = ictlr_reg_base[(irq - FIRST_LEGACY_IRQ) / 32];
  54. mask = BIT((irq - FIRST_LEGACY_IRQ) % 32);
  55. __raw_writel(mask, base + reg);
  56. }
  57. static void tegra_mask(struct irq_data *d)
  58. {
  59. if (d->irq < FIRST_LEGACY_IRQ)
  60. return;
  61. tegra_irq_write_mask(d->irq, ICTLR_CPU_IER_CLR);
  62. }
  63. static void tegra_unmask(struct irq_data *d)
  64. {
  65. if (d->irq < FIRST_LEGACY_IRQ)
  66. return;
  67. tegra_irq_write_mask(d->irq, ICTLR_CPU_IER_SET);
  68. }
  69. static void tegra_ack(struct irq_data *d)
  70. {
  71. if (d->irq < FIRST_LEGACY_IRQ)
  72. return;
  73. tegra_irq_write_mask(d->irq, ICTLR_CPU_IEP_FIR_CLR);
  74. }
  75. static void tegra_eoi(struct irq_data *d)
  76. {
  77. if (d->irq < FIRST_LEGACY_IRQ)
  78. return;
  79. tegra_irq_write_mask(d->irq, ICTLR_CPU_IEP_FIR_CLR);
  80. }
  81. static int tegra_retrigger(struct irq_data *d)
  82. {
  83. if (d->irq < FIRST_LEGACY_IRQ)
  84. return 0;
  85. tegra_irq_write_mask(d->irq, ICTLR_CPU_IEP_FIR_SET);
  86. return 1;
  87. }
  88. void __init tegra_init_irq(void)
  89. {
  90. int i;
  91. for (i = 0; i < NUM_ICTLRS; i++) {
  92. void __iomem *ictlr = ictlr_reg_base[i];
  93. writel(~0, ictlr + ICTLR_CPU_IER_CLR);
  94. writel(0, ictlr + ICTLR_CPU_IEP_CLASS);
  95. }
  96. gic_arch_extn.irq_ack = tegra_ack;
  97. gic_arch_extn.irq_eoi = tegra_eoi;
  98. gic_arch_extn.irq_mask = tegra_mask;
  99. gic_arch_extn.irq_unmask = tegra_unmask;
  100. gic_arch_extn.irq_retrigger = tegra_retrigger;
  101. /*
  102. * Check if there is a devicetree present, since the GIC will be
  103. * initialized elsewhere under DT.
  104. */
  105. if (!of_have_populated_dt())
  106. gic_init(0, 29, IO_ADDRESS(TEGRA_ARM_INT_DIST_BASE),
  107. IO_ADDRESS(TEGRA_ARM_PERIF_BASE + 0x100));
  108. }