cpuidle-tegra30.c 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149
  1. /*
  2. * CPU idle driver for Tegra CPUs
  3. *
  4. * Copyright (c) 2010-2012, NVIDIA Corporation.
  5. * Copyright (c) 2011 Google, Inc.
  6. * Author: Colin Cross <ccross@android.com>
  7. * Gary King <gking@nvidia.com>
  8. *
  9. * Rework for 3.3 by Peter De Schrijver <pdeschrijver@nvidia.com>
  10. *
  11. * This program is free software; you can redistribute it and/or modify
  12. * it under the terms of the GNU General Public License as published by
  13. * the Free Software Foundation; either version 2 of the License, or
  14. * (at your option) any later version.
  15. *
  16. * This program is distributed in the hope that it will be useful, but WITHOUT
  17. * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  18. * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
  19. * more details.
  20. */
  21. #include <linux/clk/tegra.h>
  22. #include <linux/tick.h>
  23. #include <linux/cpuidle.h>
  24. #include <linux/cpu_pm.h>
  25. #include <linux/kernel.h>
  26. #include <linux/module.h>
  27. #include <asm/cpuidle.h>
  28. #include <asm/smp_plat.h>
  29. #include <asm/suspend.h>
  30. #include "cpuidle.h"
  31. #include "pm.h"
  32. #include "sleep.h"
  33. #ifdef CONFIG_PM_SLEEP
  34. static int tegra30_idle_lp2(struct cpuidle_device *dev,
  35. struct cpuidle_driver *drv,
  36. int index);
  37. #endif
  38. static struct cpuidle_driver tegra_idle_driver = {
  39. .name = "tegra_idle",
  40. .owner = THIS_MODULE,
  41. #ifdef CONFIG_PM_SLEEP
  42. .state_count = 2,
  43. #else
  44. .state_count = 1,
  45. #endif
  46. .states = {
  47. [0] = ARM_CPUIDLE_WFI_STATE_PWR(600),
  48. #ifdef CONFIG_PM_SLEEP
  49. [1] = {
  50. .enter = tegra30_idle_lp2,
  51. .exit_latency = 2000,
  52. .target_residency = 2200,
  53. .power_usage = 0,
  54. .name = "powered-down",
  55. .desc = "CPU power gated",
  56. },
  57. #endif
  58. },
  59. };
  60. #ifdef CONFIG_PM_SLEEP
  61. static bool tegra30_cpu_cluster_power_down(struct cpuidle_device *dev,
  62. struct cpuidle_driver *drv,
  63. int index)
  64. {
  65. /* All CPUs entering LP2 is not working.
  66. * Don't let CPU0 enter LP2 when any secondary CPU is online.
  67. */
  68. if (num_online_cpus() > 1 || !tegra_cpu_rail_off_ready()) {
  69. cpu_do_idle();
  70. return false;
  71. }
  72. tick_broadcast_enter();
  73. tegra_idle_lp2_last();
  74. tick_broadcast_exit();
  75. return true;
  76. }
  77. #ifdef CONFIG_SMP
  78. static bool tegra30_cpu_core_power_down(struct cpuidle_device *dev,
  79. struct cpuidle_driver *drv,
  80. int index)
  81. {
  82. tick_broadcast_enter();
  83. smp_wmb();
  84. cpu_suspend(0, tegra30_sleep_cpu_secondary_finish);
  85. tick_broadcast_exit();
  86. return true;
  87. }
  88. #else
  89. static inline bool tegra30_cpu_core_power_down(struct cpuidle_device *dev,
  90. struct cpuidle_driver *drv,
  91. int index)
  92. {
  93. return true;
  94. }
  95. #endif
  96. static int tegra30_idle_lp2(struct cpuidle_device *dev,
  97. struct cpuidle_driver *drv,
  98. int index)
  99. {
  100. bool entered_lp2 = false;
  101. bool last_cpu;
  102. local_fiq_disable();
  103. last_cpu = tegra_set_cpu_in_lp2();
  104. cpu_pm_enter();
  105. if (dev->cpu == 0) {
  106. if (last_cpu)
  107. entered_lp2 = tegra30_cpu_cluster_power_down(dev, drv,
  108. index);
  109. else
  110. cpu_do_idle();
  111. } else {
  112. entered_lp2 = tegra30_cpu_core_power_down(dev, drv, index);
  113. }
  114. cpu_pm_exit();
  115. tegra_clear_cpu_in_lp2();
  116. local_fiq_enable();
  117. smp_rmb();
  118. return (entered_lp2) ? index : 0;
  119. }
  120. #endif
  121. int __init tegra30_cpuidle_init(void)
  122. {
  123. return cpuidle_register(&tegra_idle_driver, NULL);
  124. }