cpuidle-tegra114.c 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899
  1. /*
  2. * Copyright (c) 2013, NVIDIA Corporation. All rights reserved.
  3. *
  4. * This program is free software; you can redistribute it and/or modify it
  5. * under the terms and conditions of the GNU General Public License,
  6. * version 2, as published by the Free Software Foundation.
  7. *
  8. * This program is distributed in the hope it will be useful, but WITHOUT
  9. * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  10. * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
  11. * more details.
  12. *
  13. * You should have received a copy of the GNU General Public License
  14. * along with this program. If not, see <http://www.gnu.org/licenses/>.
  15. */
  16. #include <asm/firmware.h>
  17. #include <linux/tick.h>
  18. #include <linux/cpuidle.h>
  19. #include <linux/cpu_pm.h>
  20. #include <linux/kernel.h>
  21. #include <linux/module.h>
  22. #include <asm/cpuidle.h>
  23. #include <asm/smp_plat.h>
  24. #include <asm/suspend.h>
  25. #include <asm/psci.h>
  26. #include "cpuidle.h"
  27. #include "pm.h"
  28. #include "sleep.h"
  29. #ifdef CONFIG_PM_SLEEP
  30. #define TEGRA114_MAX_STATES 2
  31. #else
  32. #define TEGRA114_MAX_STATES 1
  33. #endif
  34. #ifdef CONFIG_PM_SLEEP
  35. static int tegra114_idle_power_down(struct cpuidle_device *dev,
  36. struct cpuidle_driver *drv,
  37. int index)
  38. {
  39. local_fiq_disable();
  40. tegra_set_cpu_in_lp2();
  41. cpu_pm_enter();
  42. call_firmware_op(prepare_idle);
  43. /* Do suspend by ourselves if the firmware does not implement it */
  44. if (call_firmware_op(do_idle, 0) == -ENOSYS)
  45. cpu_suspend(0, tegra30_sleep_cpu_secondary_finish);
  46. cpu_pm_exit();
  47. tegra_clear_cpu_in_lp2();
  48. local_fiq_enable();
  49. return index;
  50. }
  51. static void tegra114_idle_enter_s2idle(struct cpuidle_device *dev,
  52. struct cpuidle_driver *drv,
  53. int index)
  54. {
  55. tegra114_idle_power_down(dev, drv, index);
  56. }
  57. #endif
  58. static struct cpuidle_driver tegra_idle_driver = {
  59. .name = "tegra_idle",
  60. .owner = THIS_MODULE,
  61. .state_count = TEGRA114_MAX_STATES,
  62. .states = {
  63. [0] = ARM_CPUIDLE_WFI_STATE_PWR(600),
  64. #ifdef CONFIG_PM_SLEEP
  65. [1] = {
  66. .enter = tegra114_idle_power_down,
  67. .enter_s2idle = tegra114_idle_enter_s2idle,
  68. .exit_latency = 500,
  69. .target_residency = 1000,
  70. .flags = CPUIDLE_FLAG_TIMER_STOP,
  71. .power_usage = 0,
  72. .name = "powered-down",
  73. .desc = "CPU power gated",
  74. },
  75. #endif
  76. },
  77. };
  78. int __init tegra114_cpuidle_init(void)
  79. {
  80. if (!psci_smp_available())
  81. return cpuidle_register(&tegra_idle_driver, NULL);
  82. return 0;
  83. }