cpuidle-tegra20.c 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148
  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 <asm/cpuidle.h>
  27. #include <asm/proc-fns.h>
  28. #include <asm/suspend.h>
  29. #include <asm/smp_plat.h>
  30. #include "pm.h"
  31. #include "sleep.h"
  32. #ifdef CONFIG_PM_SLEEP
  33. static int tegra20_idle_lp2(struct cpuidle_device *dev,
  34. struct cpuidle_driver *drv,
  35. int index);
  36. #endif
  37. static struct cpuidle_state tegra_idle_states[] = {
  38. [0] = ARM_CPUIDLE_WFI_STATE_PWR(600),
  39. #ifdef CONFIG_PM_SLEEP
  40. [1] = {
  41. .enter = tegra20_idle_lp2,
  42. .exit_latency = 5000,
  43. .target_residency = 10000,
  44. .power_usage = 0,
  45. .flags = CPUIDLE_FLAG_TIME_VALID,
  46. .name = "powered-down",
  47. .desc = "CPU power gated",
  48. },
  49. #endif
  50. };
  51. static struct cpuidle_driver tegra_idle_driver = {
  52. .name = "tegra_idle",
  53. .owner = THIS_MODULE,
  54. .en_core_tk_irqen = 1,
  55. };
  56. static DEFINE_PER_CPU(struct cpuidle_device, tegra_idle_device);
  57. #ifdef CONFIG_PM_SLEEP
  58. #ifdef CONFIG_SMP
  59. static bool tegra20_idle_enter_lp2_cpu_1(struct cpuidle_device *dev,
  60. struct cpuidle_driver *drv,
  61. int index)
  62. {
  63. clockevents_notify(CLOCK_EVT_NOTIFY_BROADCAST_ENTER, &dev->cpu);
  64. cpu_suspend(0, tegra20_sleep_cpu_secondary_finish);
  65. tegra20_cpu_clear_resettable();
  66. clockevents_notify(CLOCK_EVT_NOTIFY_BROADCAST_EXIT, &dev->cpu);
  67. return true;
  68. }
  69. #else
  70. static inline bool tegra20_idle_enter_lp2_cpu_1(struct cpuidle_device *dev,
  71. struct cpuidle_driver *drv,
  72. int index)
  73. {
  74. return true;
  75. }
  76. #endif
  77. static int tegra20_idle_lp2(struct cpuidle_device *dev,
  78. struct cpuidle_driver *drv,
  79. int index)
  80. {
  81. u32 cpu = is_smp() ? cpu_logical_map(dev->cpu) : dev->cpu;
  82. bool entered_lp2 = false;
  83. local_fiq_disable();
  84. tegra_set_cpu_in_lp2(cpu);
  85. cpu_pm_enter();
  86. if (cpu == 0)
  87. cpu_do_idle();
  88. else
  89. entered_lp2 = tegra20_idle_enter_lp2_cpu_1(dev, drv, index);
  90. cpu_pm_exit();
  91. tegra_clear_cpu_in_lp2(cpu);
  92. local_fiq_enable();
  93. smp_rmb();
  94. return entered_lp2 ? index : 0;
  95. }
  96. #endif
  97. int __init tegra20_cpuidle_init(void)
  98. {
  99. int ret;
  100. unsigned int cpu;
  101. struct cpuidle_device *dev;
  102. struct cpuidle_driver *drv = &tegra_idle_driver;
  103. drv->state_count = ARRAY_SIZE(tegra_idle_states);
  104. memcpy(drv->states, tegra_idle_states,
  105. drv->state_count * sizeof(drv->states[0]));
  106. ret = cpuidle_register_driver(&tegra_idle_driver);
  107. if (ret) {
  108. pr_err("CPUidle driver registration failed\n");
  109. return ret;
  110. }
  111. for_each_possible_cpu(cpu) {
  112. dev = &per_cpu(tegra_idle_device, cpu);
  113. dev->cpu = cpu;
  114. dev->state_count = drv->state_count;
  115. ret = cpuidle_register_device(dev);
  116. if (ret) {
  117. pr_err("CPU%u: CPUidle device registration failed\n",
  118. cpu);
  119. return ret;
  120. }
  121. }
  122. return 0;
  123. }