cpuidle-tegra30.c 3.4 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/kernel.h>
  22. #include <linux/module.h>
  23. #include <linux/cpuidle.h>
  24. #include <linux/cpu_pm.h>
  25. #include <linux/clockchips.h>
  26. #include <linux/clk/tegra.h>
  27. #include <asm/cpuidle.h>
  28. #include <asm/proc-fns.h>
  29. #include <asm/suspend.h>
  30. #include <asm/smp_plat.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. .flags = CPUIDLE_FLAG_TIME_VALID,
  55. .name = "powered-down",
  56. .desc = "CPU power gated",
  57. },
  58. #endif
  59. },
  60. };
  61. #ifdef CONFIG_PM_SLEEP
  62. static bool tegra30_cpu_cluster_power_down(struct cpuidle_device *dev,
  63. struct cpuidle_driver *drv,
  64. int index)
  65. {
  66. /* All CPUs entering LP2 is not working.
  67. * Don't let CPU0 enter LP2 when any secondary CPU is online.
  68. */
  69. if (num_online_cpus() > 1 || !tegra_cpu_rail_off_ready()) {
  70. cpu_do_idle();
  71. return false;
  72. }
  73. clockevents_notify(CLOCK_EVT_NOTIFY_BROADCAST_ENTER, &dev->cpu);
  74. tegra_idle_lp2_last();
  75. clockevents_notify(CLOCK_EVT_NOTIFY_BROADCAST_EXIT, &dev->cpu);
  76. return true;
  77. }
  78. #ifdef CONFIG_SMP
  79. static bool tegra30_cpu_core_power_down(struct cpuidle_device *dev,
  80. struct cpuidle_driver *drv,
  81. int index)
  82. {
  83. clockevents_notify(CLOCK_EVT_NOTIFY_BROADCAST_ENTER, &dev->cpu);
  84. smp_wmb();
  85. cpu_suspend(0, tegra30_sleep_cpu_secondary_finish);
  86. clockevents_notify(CLOCK_EVT_NOTIFY_BROADCAST_EXIT, &dev->cpu);
  87. return true;
  88. }
  89. #else
  90. static inline bool tegra30_cpu_core_power_down(struct cpuidle_device *dev,
  91. struct cpuidle_driver *drv,
  92. int index)
  93. {
  94. return true;
  95. }
  96. #endif
  97. static int tegra30_idle_lp2(struct cpuidle_device *dev,
  98. struct cpuidle_driver *drv,
  99. int index)
  100. {
  101. bool entered_lp2 = false;
  102. bool last_cpu;
  103. local_fiq_disable();
  104. last_cpu = tegra_set_cpu_in_lp2();
  105. cpu_pm_enter();
  106. if (dev->cpu == 0) {
  107. if (last_cpu)
  108. entered_lp2 = tegra30_cpu_cluster_power_down(dev, drv,
  109. index);
  110. else
  111. cpu_do_idle();
  112. } else {
  113. entered_lp2 = tegra30_cpu_core_power_down(dev, drv, index);
  114. }
  115. cpu_pm_exit();
  116. tegra_clear_cpu_in_lp2();
  117. local_fiq_enable();
  118. smp_rmb();
  119. return (entered_lp2) ? index : 0;
  120. }
  121. #endif
  122. int __init tegra30_cpuidle_init(void)
  123. {
  124. return cpuidle_register(&tegra_idle_driver, NULL);
  125. }