cpuidle-tegra30.c 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147
  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/clockchips.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 "pm.h"
  31. #include "sleep.h"
  32. #ifdef CONFIG_PM_SLEEP
  33. static int tegra30_idle_lp2(struct cpuidle_device *dev,
  34. struct cpuidle_driver *drv,
  35. int index);
  36. #endif
  37. static struct cpuidle_driver tegra_idle_driver = {
  38. .name = "tegra_idle",
  39. .owner = THIS_MODULE,
  40. #ifdef CONFIG_PM_SLEEP
  41. .state_count = 2,
  42. #else
  43. .state_count = 1,
  44. #endif
  45. .states = {
  46. [0] = ARM_CPUIDLE_WFI_STATE_PWR(600),
  47. #ifdef CONFIG_PM_SLEEP
  48. [1] = {
  49. .enter = tegra30_idle_lp2,
  50. .exit_latency = 2000,
  51. .target_residency = 2200,
  52. .power_usage = 0,
  53. .name = "powered-down",
  54. .desc = "CPU power gated",
  55. },
  56. #endif
  57. },
  58. };
  59. #ifdef CONFIG_PM_SLEEP
  60. static bool tegra30_cpu_cluster_power_down(struct cpuidle_device *dev,
  61. struct cpuidle_driver *drv,
  62. int index)
  63. {
  64. /* All CPUs entering LP2 is not working.
  65. * Don't let CPU0 enter LP2 when any secondary CPU is online.
  66. */
  67. if (num_online_cpus() > 1 || !tegra_cpu_rail_off_ready()) {
  68. cpu_do_idle();
  69. return false;
  70. }
  71. clockevents_notify(CLOCK_EVT_NOTIFY_BROADCAST_ENTER, &dev->cpu);
  72. tegra_idle_lp2_last();
  73. clockevents_notify(CLOCK_EVT_NOTIFY_BROADCAST_EXIT, &dev->cpu);
  74. return true;
  75. }
  76. #ifdef CONFIG_SMP
  77. static bool tegra30_cpu_core_power_down(struct cpuidle_device *dev,
  78. struct cpuidle_driver *drv,
  79. int index)
  80. {
  81. clockevents_notify(CLOCK_EVT_NOTIFY_BROADCAST_ENTER, &dev->cpu);
  82. smp_wmb();
  83. cpu_suspend(0, tegra30_sleep_cpu_secondary_finish);
  84. clockevents_notify(CLOCK_EVT_NOTIFY_BROADCAST_EXIT, &dev->cpu);
  85. return true;
  86. }
  87. #else
  88. static inline bool tegra30_cpu_core_power_down(struct cpuidle_device *dev,
  89. struct cpuidle_driver *drv,
  90. int index)
  91. {
  92. return true;
  93. }
  94. #endif
  95. static int tegra30_idle_lp2(struct cpuidle_device *dev,
  96. struct cpuidle_driver *drv,
  97. int index)
  98. {
  99. bool entered_lp2 = false;
  100. bool last_cpu;
  101. local_fiq_disable();
  102. last_cpu = tegra_set_cpu_in_lp2();
  103. cpu_pm_enter();
  104. if (dev->cpu == 0) {
  105. if (last_cpu)
  106. entered_lp2 = tegra30_cpu_cluster_power_down(dev, drv,
  107. index);
  108. else
  109. cpu_do_idle();
  110. } else {
  111. entered_lp2 = tegra30_cpu_core_power_down(dev, drv, index);
  112. }
  113. cpu_pm_exit();
  114. tegra_clear_cpu_in_lp2();
  115. local_fiq_enable();
  116. smp_rmb();
  117. return (entered_lp2) ? index : 0;
  118. }
  119. #endif
  120. int __init tegra30_cpuidle_init(void)
  121. {
  122. return cpuidle_register(&tegra_idle_driver, NULL);
  123. }