irq.c 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171
  1. /*
  2. * Copyright (C) 2010 Google, Inc.
  3. *
  4. * Author:
  5. * Colin Cross <ccross@google.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/init.h>
  21. #include <linux/interrupt.h>
  22. #include <linux/irq.h>
  23. #include <linux/io.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 APBDMA_IRQ_STA_CPU 0x14
  31. #define APBDMA_IRQ_MASK_SET 0x20
  32. #define APBDMA_IRQ_MASK_CLR 0x24
  33. #define ICTLR_CPU_IER 0x20
  34. #define ICTLR_CPU_IER_SET 0x24
  35. #define ICTLR_CPU_IER_CLR 0x28
  36. #define ICTLR_CPU_IEP_CLASS 0x2c
  37. #define ICTLR_COP_IER 0x30
  38. #define ICTLR_COP_IER_SET 0x34
  39. #define ICTLR_COP_IER_CLR 0x38
  40. #define ICTLR_COP_IEP_CLASS 0x3c
  41. static void (*gic_mask_irq)(unsigned int irq);
  42. static void (*gic_unmask_irq)(unsigned int irq);
  43. #define irq_to_ictlr(irq) (((irq)-32) >> 5)
  44. static void __iomem *tegra_ictlr_base = IO_ADDRESS(TEGRA_PRIMARY_ICTLR_BASE);
  45. #define ictlr_to_virt(ictlr) (tegra_ictlr_base + (ictlr)*0x100)
  46. static void tegra_mask(unsigned int irq)
  47. {
  48. void __iomem *addr = ictlr_to_virt(irq_to_ictlr(irq));
  49. gic_mask_irq(irq);
  50. writel(1<<(irq&31), addr+ICTLR_CPU_IER_CLR);
  51. }
  52. static void tegra_unmask(unsigned int irq)
  53. {
  54. void __iomem *addr = ictlr_to_virt(irq_to_ictlr(irq));
  55. gic_unmask_irq(irq);
  56. writel(1<<(irq&31), addr+ICTLR_CPU_IER_SET);
  57. }
  58. #ifdef CONFIG_PM
  59. static int tegra_set_wake(unsigned int irq, unsigned int on)
  60. {
  61. return 0;
  62. }
  63. #endif
  64. static struct irq_chip tegra_irq = {
  65. .name = "PPI",
  66. .mask = tegra_mask,
  67. .unmask = tegra_unmask,
  68. #ifdef CONFIG_PM
  69. .set_wake = tegra_set_wake,
  70. #endif
  71. };
  72. void __init tegra_init_irq(void)
  73. {
  74. struct irq_chip *gic;
  75. unsigned int i;
  76. for (i = 0; i < PPI_NR; i++) {
  77. writel(~0, ictlr_to_virt(i) + ICTLR_CPU_IER_CLR);
  78. writel(0, ictlr_to_virt(i) + ICTLR_CPU_IEP_CLASS);
  79. }
  80. gic_dist_init(0, IO_ADDRESS(TEGRA_ARM_INT_DIST_BASE), 29);
  81. gic_cpu_init(0, IO_ADDRESS(TEGRA_ARM_PERIF_BASE + 0x100));
  82. gic = get_irq_chip(29);
  83. gic_unmask_irq = gic->unmask;
  84. gic_mask_irq = gic->mask;
  85. tegra_irq.ack = gic->ack;
  86. #ifdef CONFIG_SMP
  87. tegra_irq.set_affinity = gic->set_affinity;
  88. #endif
  89. for (i = INT_PRI_BASE; i < INT_GPIO_BASE; i++) {
  90. set_irq_chip(i, &tegra_irq);
  91. set_irq_handler(i, handle_level_irq);
  92. set_irq_flags(i, IRQF_VALID);
  93. }
  94. }
  95. #ifdef CONFIG_PM
  96. static u32 cop_ier[PPI_NR];
  97. static u32 cpu_ier[PPI_NR];
  98. static u32 cpu_iep[PPI_NR];
  99. void tegra_irq_suspend(void)
  100. {
  101. unsigned long flags;
  102. int i;
  103. for (i = INT_PRI_BASE; i < INT_GPIO_BASE; i++) {
  104. struct irq_desc *desc = irq_to_desc(i);
  105. if (!desc)
  106. continue;
  107. if (desc->status & IRQ_WAKEUP) {
  108. pr_debug("irq %d is wakeup\n", i);
  109. continue;
  110. }
  111. disable_irq(i);
  112. }
  113. local_irq_save(flags);
  114. for (i = 0; i < PPI_NR; i++) {
  115. void __iomem *ictlr = ictlr_to_virt(i);
  116. cpu_ier[i] = readl(ictlr + ICTLR_CPU_IER);
  117. cpu_iep[i] = readl(ictlr + ICTLR_CPU_IEP_CLASS);
  118. cop_ier[i] = readl(ictlr + ICTLR_COP_IER);
  119. writel(~0, ictlr + ICTLR_COP_IER_CLR);
  120. }
  121. local_irq_restore(flags);
  122. }
  123. void tegra_irq_resume(void)
  124. {
  125. unsigned long flags;
  126. int i;
  127. local_irq_save(flags);
  128. for (i = 0; i < PPI_NR; i++) {
  129. void __iomem *ictlr = ictlr_to_virt(i);
  130. writel(cpu_iep[i], ictlr + ICTLR_CPU_IEP_CLASS);
  131. writel(~0ul, ictlr + ICTLR_CPU_IER_CLR);
  132. writel(cpu_ier[i], ictlr + ICTLR_CPU_IER_SET);
  133. writel(0, ictlr + ICTLR_COP_IEP_CLASS);
  134. writel(~0ul, ictlr + ICTLR_COP_IER_CLR);
  135. writel(cop_ier[i], ictlr + ICTLR_COP_IER_SET);
  136. }
  137. local_irq_restore(flags);
  138. for (i = INT_PRI_BASE; i < INT_GPIO_BASE; i++) {
  139. struct irq_desc *desc = irq_to_desc(i);
  140. if (!desc || (desc->status & IRQ_WAKEUP))
  141. continue;
  142. enable_irq(i);
  143. }
  144. }
  145. #endif