cpuidle-tegra114.c 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788
  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 "pm.h"
  26. #include "sleep.h"
  27. #ifdef CONFIG_PM_SLEEP
  28. #define TEGRA114_MAX_STATES 2
  29. #else
  30. #define TEGRA114_MAX_STATES 1
  31. #endif
  32. #ifdef CONFIG_PM_SLEEP
  33. static int tegra114_idle_power_down(struct cpuidle_device *dev,
  34. struct cpuidle_driver *drv,
  35. int index)
  36. {
  37. local_fiq_disable();
  38. tegra_set_cpu_in_lp2();
  39. cpu_pm_enter();
  40. tick_broadcast_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. tick_broadcast_exit();
  46. cpu_pm_exit();
  47. tegra_clear_cpu_in_lp2();
  48. local_fiq_enable();
  49. return index;
  50. }
  51. #endif
  52. static struct cpuidle_driver tegra_idle_driver = {
  53. .name = "tegra_idle",
  54. .owner = THIS_MODULE,
  55. .state_count = TEGRA114_MAX_STATES,
  56. .states = {
  57. [0] = ARM_CPUIDLE_WFI_STATE_PWR(600),
  58. #ifdef CONFIG_PM_SLEEP
  59. [1] = {
  60. .enter = tegra114_idle_power_down,
  61. .exit_latency = 500,
  62. .target_residency = 1000,
  63. .power_usage = 0,
  64. .name = "powered-down",
  65. .desc = "CPU power gated",
  66. },
  67. #endif
  68. },
  69. };
  70. int __init tegra114_cpuidle_init(void)
  71. {
  72. return cpuidle_register(&tegra_idle_driver, NULL);
  73. }