pm.c 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165
  1. /*
  2. * CPU complex suspend & resume functions for Tegra SoCs
  3. *
  4. * Copyright (c) 2009-2012, NVIDIA Corporation. All rights reserved.
  5. *
  6. * This program is free software; you can redistribute it and/or modify it
  7. * under the terms and conditions of the GNU General Public License,
  8. * version 2, as published by the Free Software Foundation.
  9. *
  10. * This program is distributed in the hope it will be useful, but WITHOUT
  11. * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  12. * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
  13. * more details.
  14. *
  15. * You should have received a copy of the GNU General Public License
  16. * along with this program. If not, see <http://www.gnu.org/licenses/>.
  17. */
  18. #include <linux/kernel.h>
  19. #include <linux/spinlock.h>
  20. #include <linux/io.h>
  21. #include <linux/cpumask.h>
  22. #include <linux/delay.h>
  23. #include <linux/cpu_pm.h>
  24. #include <linux/err.h>
  25. #include <linux/clk/tegra.h>
  26. #include <asm/smp_plat.h>
  27. #include <asm/cacheflush.h>
  28. #include <asm/suspend.h>
  29. #include <asm/idmap.h>
  30. #include <asm/proc-fns.h>
  31. #include <asm/tlbflush.h>
  32. #include "iomap.h"
  33. #include "reset.h"
  34. #include "flowctrl.h"
  35. #include "fuse.h"
  36. #include "pmc.h"
  37. #include "sleep.h"
  38. #define TEGRA_POWER_CPU_PWRREQ_OE (1 << 16) /* CPU pwr req enable */
  39. #define PMC_CTRL 0x0
  40. #ifdef CONFIG_PM_SLEEP
  41. static DEFINE_SPINLOCK(tegra_lp2_lock);
  42. static void __iomem *pmc = IO_ADDRESS(TEGRA_PMC_BASE);
  43. void (*tegra_tear_down_cpu)(void);
  44. /*
  45. * restore_cpu_complex
  46. *
  47. * restores cpu clock setting, clears flow controller
  48. *
  49. * Always called on CPU 0.
  50. */
  51. static void restore_cpu_complex(void)
  52. {
  53. int cpu = smp_processor_id();
  54. BUG_ON(cpu != 0);
  55. #ifdef CONFIG_SMP
  56. cpu = cpu_logical_map(cpu);
  57. #endif
  58. /* Restore the CPU clock settings */
  59. tegra_cpu_clock_resume();
  60. flowctrl_cpu_suspend_exit(cpu);
  61. }
  62. /*
  63. * suspend_cpu_complex
  64. *
  65. * saves pll state for use by restart_plls, prepares flow controller for
  66. * transition to suspend state
  67. *
  68. * Must always be called on cpu 0.
  69. */
  70. static void suspend_cpu_complex(void)
  71. {
  72. int cpu = smp_processor_id();
  73. BUG_ON(cpu != 0);
  74. #ifdef CONFIG_SMP
  75. cpu = cpu_logical_map(cpu);
  76. #endif
  77. /* Save the CPU clock settings */
  78. tegra_cpu_clock_suspend();
  79. flowctrl_cpu_suspend_enter(cpu);
  80. }
  81. void tegra_clear_cpu_in_lp2(int phy_cpu_id)
  82. {
  83. u32 *cpu_in_lp2 = tegra_cpu_lp2_mask;
  84. spin_lock(&tegra_lp2_lock);
  85. BUG_ON(!(*cpu_in_lp2 & BIT(phy_cpu_id)));
  86. *cpu_in_lp2 &= ~BIT(phy_cpu_id);
  87. spin_unlock(&tegra_lp2_lock);
  88. }
  89. bool tegra_set_cpu_in_lp2(int phy_cpu_id)
  90. {
  91. bool last_cpu = false;
  92. cpumask_t *cpu_lp2_mask = tegra_cpu_lp2_mask;
  93. u32 *cpu_in_lp2 = tegra_cpu_lp2_mask;
  94. spin_lock(&tegra_lp2_lock);
  95. BUG_ON((*cpu_in_lp2 & BIT(phy_cpu_id)));
  96. *cpu_in_lp2 |= BIT(phy_cpu_id);
  97. if ((phy_cpu_id == 0) && cpumask_equal(cpu_lp2_mask, cpu_online_mask))
  98. last_cpu = true;
  99. else if (tegra_chip_id == TEGRA20 && phy_cpu_id == 1)
  100. tegra20_cpu_set_resettable_soon();
  101. spin_unlock(&tegra_lp2_lock);
  102. return last_cpu;
  103. }
  104. static int tegra_sleep_cpu(unsigned long v2p)
  105. {
  106. /* Switch to the identity mapping. */
  107. cpu_switch_mm(idmap_pgd, &init_mm);
  108. /* Flush the TLB. */
  109. local_flush_tlb_all();
  110. tegra_sleep_cpu_finish(v2p);
  111. /* should never here */
  112. BUG();
  113. return 0;
  114. }
  115. void tegra_idle_lp2_last(u32 cpu_on_time, u32 cpu_off_time)
  116. {
  117. u32 mode;
  118. /* Only the last cpu down does the final suspend steps */
  119. mode = readl(pmc + PMC_CTRL);
  120. mode |= TEGRA_POWER_CPU_PWRREQ_OE;
  121. writel(mode, pmc + PMC_CTRL);
  122. set_power_timers(cpu_on_time, cpu_off_time);
  123. cpu_cluster_pm_enter();
  124. suspend_cpu_complex();
  125. cpu_suspend(PHYS_OFFSET - PAGE_OFFSET, &tegra_sleep_cpu);
  126. restore_cpu_complex();
  127. cpu_cluster_pm_exit();
  128. }
  129. #endif