cpuidle-tegra114.c 2.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697
  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 "pm.h"
  27. #include "sleep.h"
  28. #ifdef CONFIG_PM_SLEEP
  29. #define TEGRA114_MAX_STATES 2
  30. #else
  31. #define TEGRA114_MAX_STATES 1
  32. #endif
  33. #ifdef CONFIG_PM_SLEEP
  34. static int tegra114_idle_power_down(struct cpuidle_device *dev,
  35. struct cpuidle_driver *drv,
  36. int index)
  37. {
  38. local_fiq_disable();
  39. tegra_set_cpu_in_lp2();
  40. cpu_pm_enter();
  41. call_firmware_op(prepare_idle);
  42. /* Do suspend by ourselves if the firmware does not implement it */
  43. if (call_firmware_op(do_idle, 0) == -ENOSYS)
  44. cpu_suspend(0, tegra30_sleep_cpu_secondary_finish);
  45. cpu_pm_exit();
  46. tegra_clear_cpu_in_lp2();
  47. local_fiq_enable();
  48. return index;
  49. }
  50. static void tegra114_idle_enter_freeze(struct cpuidle_device *dev,
  51. struct cpuidle_driver *drv,
  52. int index)
  53. {
  54. tegra114_idle_power_down(dev, drv, index);
  55. }
  56. #endif
  57. static struct cpuidle_driver tegra_idle_driver = {
  58. .name = "tegra_idle",
  59. .owner = THIS_MODULE,
  60. .state_count = TEGRA114_MAX_STATES,
  61. .states = {
  62. [0] = ARM_CPUIDLE_WFI_STATE_PWR(600),
  63. #ifdef CONFIG_PM_SLEEP
  64. [1] = {
  65. .enter = tegra114_idle_power_down,
  66. .enter_freeze = tegra114_idle_enter_freeze,
  67. .exit_latency = 500,
  68. .target_residency = 1000,
  69. .flags = CPUIDLE_FLAG_TIMER_STOP,
  70. .power_usage = 0,
  71. .name = "powered-down",
  72. .desc = "CPU power gated",
  73. },
  74. #endif
  75. },
  76. };
  77. int __init tegra114_cpuidle_init(void)
  78. {
  79. if (!psci_smp_available())
  80. return cpuidle_register(&tegra_idle_driver, NULL);
  81. return 0;
  82. }