cpuidle-imx6sx.c 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115
  1. // SPDX-License-Identifier: GPL-2.0-only
  2. /*
  3. * Copyright (C) 2014 Freescale Semiconductor, Inc.
  4. */
  5. #include <linux/cpuidle.h>
  6. #include <linux/cpu_pm.h>
  7. #include <linux/module.h>
  8. #include <asm/cacheflush.h>
  9. #include <asm/cpuidle.h>
  10. #include <asm/suspend.h>
  11. #include "common.h"
  12. #include "cpuidle.h"
  13. #include "hardware.h"
  14. static int imx6sx_idle_finish(unsigned long val)
  15. {
  16. /*
  17. * for Cortex-A7 which has an internal L2
  18. * cache, need to flush it before powering
  19. * down ARM platform, since flushing L1 cache
  20. * here again has very small overhead, compared
  21. * to adding conditional code for L2 cache type,
  22. * just call flush_cache_all() is fine.
  23. */
  24. flush_cache_all();
  25. cpu_do_idle();
  26. return 0;
  27. }
  28. static int imx6sx_enter_wait(struct cpuidle_device *dev,
  29. struct cpuidle_driver *drv, int index)
  30. {
  31. imx6_set_lpm(WAIT_UNCLOCKED);
  32. switch (index) {
  33. case 1:
  34. cpu_do_idle();
  35. break;
  36. case 2:
  37. imx6_enable_rbc(true);
  38. imx_gpc_set_arm_power_in_lpm(true);
  39. imx_set_cpu_jump(0, v7_cpu_resume);
  40. /* Need to notify there is a cpu pm operation. */
  41. cpu_pm_enter();
  42. cpu_cluster_pm_enter();
  43. cpu_suspend(0, imx6sx_idle_finish);
  44. cpu_cluster_pm_exit();
  45. cpu_pm_exit();
  46. imx_gpc_set_arm_power_in_lpm(false);
  47. imx6_enable_rbc(false);
  48. break;
  49. default:
  50. break;
  51. }
  52. imx6_set_lpm(WAIT_CLOCKED);
  53. return index;
  54. }
  55. static struct cpuidle_driver imx6sx_cpuidle_driver = {
  56. .name = "imx6sx_cpuidle",
  57. .owner = THIS_MODULE,
  58. .states = {
  59. /* WFI */
  60. ARM_CPUIDLE_WFI_STATE,
  61. /* WAIT */
  62. {
  63. .exit_latency = 50,
  64. .target_residency = 75,
  65. .flags = CPUIDLE_FLAG_TIMER_STOP,
  66. .enter = imx6sx_enter_wait,
  67. .name = "WAIT",
  68. .desc = "Clock off",
  69. },
  70. /* WAIT + ARM power off */
  71. {
  72. /*
  73. * ARM gating 31us * 5 + RBC clear 65us
  74. * and some margin for SW execution, here set it
  75. * to 300us.
  76. */
  77. .exit_latency = 300,
  78. .target_residency = 500,
  79. .flags = CPUIDLE_FLAG_TIMER_STOP,
  80. .enter = imx6sx_enter_wait,
  81. .name = "LOW-POWER-IDLE",
  82. .desc = "ARM power off",
  83. },
  84. },
  85. .state_count = 3,
  86. .safe_state_index = 0,
  87. };
  88. int __init imx6sx_cpuidle_init(void)
  89. {
  90. imx6_set_int_mem_clk_lpm(true);
  91. imx6_enable_rbc(false);
  92. imx_gpc_set_l2_mem_power_in_lpm(false);
  93. /*
  94. * set ARM power up/down timing to the fastest,
  95. * sw2iso and sw can be set to one 32K cycle = 31us
  96. * except for power up sw2iso which need to be
  97. * larger than LDO ramp up time.
  98. */
  99. imx_gpc_set_arm_power_up_timing(cpu_is_imx6sx() ? 0xf : 0x2, 1);
  100. imx_gpc_set_arm_power_down_timing(1, 1);
  101. return cpuidle_register(&imx6sx_cpuidle_driver, NULL);
  102. }