irq.c 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160
  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/delay.h>
  21. #include <linux/init.h>
  22. #include <linux/interrupt.h>
  23. #include <linux/irq.h>
  24. #include <linux/io.h>
  25. #include <asm/hardware/gic.h>
  26. #include <mach/iomap.h>
  27. #include <mach/legacy_irq.h>
  28. #include <mach/suspend.h>
  29. #include "board.h"
  30. #define PMC_CTRL 0x0
  31. #define PMC_CTRL_LATCH_WAKEUPS (1 << 5)
  32. #define PMC_WAKE_MASK 0xc
  33. #define PMC_WAKE_LEVEL 0x10
  34. #define PMC_WAKE_STATUS 0x14
  35. #define PMC_SW_WAKE_STATUS 0x18
  36. #define PMC_DPD_SAMPLE 0x20
  37. static void __iomem *pmc = IO_ADDRESS(TEGRA_PMC_BASE);
  38. static u32 tegra_lp0_wake_enb;
  39. static u32 tegra_lp0_wake_level;
  40. static u32 tegra_lp0_wake_level_any;
  41. static void (*tegra_gic_mask_irq)(struct irq_data *d);
  42. static void (*tegra_gic_unmask_irq)(struct irq_data *d);
  43. static void (*tegra_gic_ack_irq)(struct irq_data *d);
  44. /* ensures that sufficient time is passed for a register write to
  45. * serialize into the 32KHz domain */
  46. static void pmc_32kwritel(u32 val, unsigned long offs)
  47. {
  48. writel(val, pmc + offs);
  49. udelay(130);
  50. }
  51. int tegra_set_lp1_wake(int irq, int enable)
  52. {
  53. return tegra_legacy_irq_set_wake(irq, enable);
  54. }
  55. void tegra_set_lp0_wake_pads(u32 wake_enb, u32 wake_level, u32 wake_any)
  56. {
  57. u32 temp;
  58. u32 status;
  59. u32 lvl;
  60. wake_level &= wake_enb;
  61. wake_any &= wake_enb;
  62. wake_level |= (tegra_lp0_wake_level & tegra_lp0_wake_enb);
  63. wake_any |= (tegra_lp0_wake_level_any & tegra_lp0_wake_enb);
  64. wake_enb |= tegra_lp0_wake_enb;
  65. pmc_32kwritel(0, PMC_SW_WAKE_STATUS);
  66. temp = readl(pmc + PMC_CTRL);
  67. temp |= PMC_CTRL_LATCH_WAKEUPS;
  68. pmc_32kwritel(temp, PMC_CTRL);
  69. temp &= ~PMC_CTRL_LATCH_WAKEUPS;
  70. pmc_32kwritel(temp, PMC_CTRL);
  71. status = readl(pmc + PMC_SW_WAKE_STATUS);
  72. lvl = readl(pmc + PMC_WAKE_LEVEL);
  73. /* flip the wakeup trigger for any-edge triggered pads
  74. * which are currently asserting as wakeups */
  75. lvl ^= status;
  76. lvl &= wake_any;
  77. wake_level |= lvl;
  78. writel(wake_level, pmc + PMC_WAKE_LEVEL);
  79. /* Enable DPD sample to trigger sampling pads data and direction
  80. * in which pad will be driven during lp0 mode*/
  81. writel(0x1, pmc + PMC_DPD_SAMPLE);
  82. writel(wake_enb, pmc + PMC_WAKE_MASK);
  83. }
  84. static void tegra_mask(struct irq_data *d)
  85. {
  86. tegra_gic_mask_irq(d);
  87. tegra_legacy_mask_irq(d->irq);
  88. }
  89. static void tegra_unmask(struct irq_data *d)
  90. {
  91. tegra_gic_unmask_irq(d);
  92. tegra_legacy_unmask_irq(d->irq);
  93. }
  94. static void tegra_ack(struct irq_data *d)
  95. {
  96. tegra_legacy_force_irq_clr(d->irq);
  97. tegra_gic_ack_irq(d);
  98. }
  99. static int tegra_retrigger(struct irq_data *d)
  100. {
  101. tegra_legacy_force_irq_set(d->irq);
  102. return 1;
  103. }
  104. static struct irq_chip tegra_irq = {
  105. .name = "PPI",
  106. .irq_ack = tegra_ack,
  107. .irq_mask = tegra_mask,
  108. .irq_unmask = tegra_unmask,
  109. .irq_retrigger = tegra_retrigger,
  110. };
  111. void __init tegra_init_irq(void)
  112. {
  113. struct irq_chip *gic;
  114. unsigned int i;
  115. int irq;
  116. tegra_init_legacy_irq();
  117. gic_init(0, 29, IO_ADDRESS(TEGRA_ARM_INT_DIST_BASE),
  118. IO_ADDRESS(TEGRA_ARM_PERIF_BASE + 0x100));
  119. gic = irq_get_chip(29);
  120. tegra_gic_unmask_irq = gic->irq_unmask;
  121. tegra_gic_mask_irq = gic->irq_mask;
  122. tegra_gic_ack_irq = gic->irq_ack;
  123. #ifdef CONFIG_SMP
  124. tegra_irq.irq_set_affinity = gic->irq_set_affinity;
  125. #endif
  126. for (i = 0; i < INT_MAIN_NR; i++) {
  127. irq = INT_PRI_BASE + i;
  128. irq_set_chip_and_handler(irq, &tegra_irq, handle_level_irq);
  129. set_irq_flags(irq, IRQF_VALID);
  130. }
  131. }