cpuidle-mt6735.c 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153
  1. /*
  2. * Copyright (C) 2015 MediaTek 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/cpumask.h>
  10. #include <linux/cpu_pm.h>
  11. #include <linux/kernel.h>
  12. #include <linux/module.h>
  13. #include <linux/of.h>
  14. #include <asm/cpuidle.h>
  15. #include <asm/suspend.h>
  16. #include "dt_idle_states.h"
  17. #define IDLE_TAG "[Power/swap]"
  18. #define idle_dbg(fmt, args...) pr_debug(IDLE_TAG fmt, ##args) /* pr_debug show nothing */
  19. int __attribute__((weak)) dpidle_enter(int cpu)
  20. {
  21. return 1;
  22. }
  23. int __attribute__((weak)) soidle_enter(int cpu)
  24. {
  25. return 1;
  26. }
  27. int __attribute__((weak)) slidle_enter(int cpu)
  28. {
  29. return 1;
  30. }
  31. int __attribute__((weak)) rgidle_enter(int cpu)
  32. {
  33. return 1;
  34. }
  35. static int mt_dpidle_enter(struct cpuidle_device *dev,
  36. struct cpuidle_driver *drv, int index)
  37. {
  38. return dpidle_enter(smp_processor_id());
  39. }
  40. static int mt_soidle_enter(struct cpuidle_device *dev,
  41. struct cpuidle_driver *drv, int index)
  42. {
  43. return soidle_enter(smp_processor_id());
  44. }
  45. static int mt_slidle_enter(struct cpuidle_device *dev,
  46. struct cpuidle_driver *drv, int index)
  47. {
  48. return slidle_enter(smp_processor_id());
  49. }
  50. static int mt_rgidle_enter(struct cpuidle_device *dev,
  51. struct cpuidle_driver *drv, int index)
  52. {
  53. return rgidle_enter(smp_processor_id());
  54. }
  55. static struct cpuidle_driver mt6735_cpuidle_driver = {
  56. .name = "mt6735_cpuidle",
  57. .owner = THIS_MODULE,
  58. .states[0] = {
  59. .enter = mt_dpidle_enter,
  60. .exit_latency = 2000, /* 2 ms */
  61. .target_residency = 1,
  62. .flags = CPUIDLE_FLAG_TIME_VALID,
  63. .name = "dpidle",
  64. .desc = "deepidle",
  65. },
  66. .states[1] = {
  67. .enter = mt_soidle_enter,
  68. .exit_latency = 2000, /* 2 ms */
  69. .target_residency = 1,
  70. .flags = CPUIDLE_FLAG_TIME_VALID,
  71. .name = "SODI",
  72. .desc = "SODI",
  73. },
  74. .states[2] = {
  75. .enter = mt_slidle_enter,
  76. .exit_latency = 2000, /* 2 ms */
  77. .target_residency = 1,
  78. .flags = CPUIDLE_FLAG_TIME_VALID,
  79. .name = "slidle",
  80. .desc = "slidle",
  81. },
  82. .states[3] = {
  83. .enter = mt_rgidle_enter,
  84. .exit_latency = 2000, /* 2 ms */
  85. .target_residency = 1,
  86. .flags = CPUIDLE_FLAG_TIME_VALID,
  87. .name = "rgidle",
  88. .desc = "WFI",
  89. },
  90. .state_count = 4,
  91. .safe_state_index = 0,
  92. };
  93. #ifdef CONFIG_ARM64
  94. static const struct of_device_id mt6735_idle_state_match[] __initconst = {
  95. { .compatible = "arm,idle-state" },
  96. { },
  97. };
  98. /*
  99. * arm64_idle_init
  100. *
  101. * Registers the arm64 specific cpuidle driver with the cpuidle
  102. * framework. It relies on core code to parse the idle states
  103. * and initialize them using driver data structures accordingly.
  104. */
  105. int __init mt6735_cpuidle_init(void)
  106. {
  107. int cpu, ret;
  108. struct cpuidle_driver *drv = &mt6735_cpuidle_driver;
  109. /*
  110. * Call arch CPU operations in order to initialize
  111. * idle states suspend back-end specific data
  112. */
  113. for_each_possible_cpu(cpu) {
  114. ret = cpu_init_idle(cpu);
  115. if (ret) {
  116. pr_err("CPU %d failed to init idle CPU ops\n", cpu);
  117. return ret;
  118. }
  119. }
  120. ret = cpuidle_register(drv, NULL);
  121. if (ret) {
  122. pr_err("failed to register cpuidle driver\n");
  123. return ret;
  124. }
  125. return 0;
  126. }
  127. #else
  128. int __init mt6735_cpuidle_init(void)
  129. {
  130. return cpuidle_register(&mt6735_cpuidle_driver, NULL);
  131. }
  132. #endif
  133. device_initcall(mt6735_cpuidle_init);