cpuidle-imx6sx.c 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104
  1. /*
  2. * Copyright (C) 2014 Freescale Semiconductor, Inc.
  3. *
  4. * This program is free software; you can redistribute it and/or modify
  5. * it under the terms of the GNU General Public License version 2 as
  6. * published by the Free Software Foundation.
  7. */
  8. #include <linux/cpuidle.h>
  9. #include <linux/cpu_pm.h>
  10. #include <linux/module.h>
  11. #include <asm/cpuidle.h>
  12. #include <asm/suspend.h>
  13. #include "common.h"
  14. #include "cpuidle.h"
  15. static int imx6sx_idle_finish(unsigned long val)
  16. {
  17. cpu_do_idle();
  18. return 0;
  19. }
  20. static int imx6sx_enter_wait(struct cpuidle_device *dev,
  21. struct cpuidle_driver *drv, int index)
  22. {
  23. imx6q_set_lpm(WAIT_UNCLOCKED);
  24. switch (index) {
  25. case 1:
  26. cpu_do_idle();
  27. break;
  28. case 2:
  29. imx6_enable_rbc(true);
  30. imx_gpc_set_arm_power_in_lpm(true);
  31. imx_set_cpu_jump(0, v7_cpu_resume);
  32. /* Need to notify there is a cpu pm operation. */
  33. cpu_pm_enter();
  34. cpu_cluster_pm_enter();
  35. cpu_suspend(0, imx6sx_idle_finish);
  36. cpu_cluster_pm_exit();
  37. cpu_pm_exit();
  38. imx_gpc_set_arm_power_in_lpm(false);
  39. imx6_enable_rbc(false);
  40. break;
  41. default:
  42. break;
  43. }
  44. imx6q_set_lpm(WAIT_CLOCKED);
  45. return index;
  46. }
  47. static struct cpuidle_driver imx6sx_cpuidle_driver = {
  48. .name = "imx6sx_cpuidle",
  49. .owner = THIS_MODULE,
  50. .states = {
  51. /* WFI */
  52. ARM_CPUIDLE_WFI_STATE,
  53. /* WAIT */
  54. {
  55. .exit_latency = 50,
  56. .target_residency = 75,
  57. .flags = CPUIDLE_FLAG_TIMER_STOP,
  58. .enter = imx6sx_enter_wait,
  59. .name = "WAIT",
  60. .desc = "Clock off",
  61. },
  62. /* WAIT + ARM power off */
  63. {
  64. /*
  65. * ARM gating 31us * 5 + RBC clear 65us
  66. * and some margin for SW execution, here set it
  67. * to 300us.
  68. */
  69. .exit_latency = 300,
  70. .target_residency = 500,
  71. .enter = imx6sx_enter_wait,
  72. .name = "LOW-POWER-IDLE",
  73. .desc = "ARM power off",
  74. },
  75. },
  76. .state_count = 3,
  77. .safe_state_index = 0,
  78. };
  79. int __init imx6sx_cpuidle_init(void)
  80. {
  81. imx6_enable_rbc(false);
  82. /*
  83. * set ARM power up/down timing to the fastest,
  84. * sw2iso and sw can be set to one 32K cycle = 31us
  85. * except for power up sw2iso which need to be
  86. * larger than LDO ramp up time.
  87. */
  88. imx_gpc_set_arm_power_up_timing(2, 1);
  89. imx_gpc_set_arm_power_down_timing(1, 1);
  90. return cpuidle_register(&imx6sx_cpuidle_driver, NULL);
  91. }