irq.c 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140
  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 INT_SYS_NR (INT_GPIO_BASE - INT_PRI_BASE)
  28. #define INT_SYS_SZ (INT_SEC_BASE - INT_PRI_BASE)
  29. #define PPI_NR ((INT_SYS_NR+INT_SYS_SZ-1)/INT_SYS_SZ)
  30. #define ICTLR_CPU_IEP_VFIQ 0x08
  31. #define ICTLR_CPU_IEP_FIR 0x14
  32. #define ICTLR_CPU_IEP_FIR_SET 0x18
  33. #define ICTLR_CPU_IEP_FIR_CLR 0x1c
  34. #define ICTLR_CPU_IER 0x20
  35. #define ICTLR_CPU_IER_SET 0x24
  36. #define ICTLR_CPU_IER_CLR 0x28
  37. #define ICTLR_CPU_IEP_CLASS 0x2C
  38. #define ICTLR_COP_IER 0x30
  39. #define ICTLR_COP_IER_SET 0x34
  40. #define ICTLR_COP_IER_CLR 0x38
  41. #define ICTLR_COP_IEP_CLASS 0x3c
  42. #define NUM_ICTLRS 4
  43. #define FIRST_LEGACY_IRQ 32
  44. static void __iomem *ictlr_reg_base[] = {
  45. IO_ADDRESS(TEGRA_PRIMARY_ICTLR_BASE),
  46. IO_ADDRESS(TEGRA_SECONDARY_ICTLR_BASE),
  47. IO_ADDRESS(TEGRA_TERTIARY_ICTLR_BASE),
  48. IO_ADDRESS(TEGRA_QUATERNARY_ICTLR_BASE),
  49. };
  50. static inline void tegra_irq_write_mask(unsigned int irq, unsigned long reg)
  51. {
  52. void __iomem *base;
  53. u32 mask;
  54. BUG_ON(irq < FIRST_LEGACY_IRQ ||
  55. irq >= FIRST_LEGACY_IRQ + NUM_ICTLRS * 32);
  56. base = ictlr_reg_base[(irq - FIRST_LEGACY_IRQ) / 32];
  57. mask = BIT((irq - FIRST_LEGACY_IRQ) % 32);
  58. __raw_writel(mask, base + reg);
  59. }
  60. static void tegra_mask(struct irq_data *d)
  61. {
  62. if (d->irq < FIRST_LEGACY_IRQ)
  63. return;
  64. tegra_irq_write_mask(d->irq, ICTLR_CPU_IER_CLR);
  65. }
  66. static void tegra_unmask(struct irq_data *d)
  67. {
  68. if (d->irq < FIRST_LEGACY_IRQ)
  69. return;
  70. tegra_irq_write_mask(d->irq, ICTLR_CPU_IER_SET);
  71. }
  72. static void tegra_ack(struct irq_data *d)
  73. {
  74. if (d->irq < FIRST_LEGACY_IRQ)
  75. return;
  76. tegra_irq_write_mask(d->irq, ICTLR_CPU_IEP_FIR_CLR);
  77. }
  78. static void tegra_eoi(struct irq_data *d)
  79. {
  80. if (d->irq < FIRST_LEGACY_IRQ)
  81. return;
  82. tegra_irq_write_mask(d->irq, ICTLR_CPU_IEP_FIR_CLR);
  83. }
  84. static int tegra_retrigger(struct irq_data *d)
  85. {
  86. if (d->irq < FIRST_LEGACY_IRQ)
  87. return 0;
  88. tegra_irq_write_mask(d->irq, ICTLR_CPU_IEP_FIR_SET);
  89. return 1;
  90. }
  91. void __init tegra_init_irq(void)
  92. {
  93. int i;
  94. for (i = 0; i < NUM_ICTLRS; i++) {
  95. void __iomem *ictlr = ictlr_reg_base[i];
  96. writel(~0, ictlr + ICTLR_CPU_IER_CLR);
  97. writel(0, ictlr + ICTLR_CPU_IEP_CLASS);
  98. }
  99. gic_arch_extn.irq_ack = tegra_ack;
  100. gic_arch_extn.irq_eoi = tegra_eoi;
  101. gic_arch_extn.irq_mask = tegra_mask;
  102. gic_arch_extn.irq_unmask = tegra_unmask;
  103. gic_arch_extn.irq_retrigger = tegra_retrigger;
  104. /*
  105. * Check if there is a devicetree present, since the GIC will be
  106. * initialized elsewhere under DT.
  107. */
  108. if (!of_have_populated_dt())
  109. gic_init(0, 29, IO_ADDRESS(TEGRA_ARM_INT_DIST_BASE),
  110. IO_ADDRESS(TEGRA_ARM_PERIF_BASE + 0x100));
  111. }