cpuidle-mt67xx_v2.c 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188
  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. int __attribute__((weak)) dpidle_enter(int cpu)
  18. {
  19. return 1;
  20. }
  21. int __attribute__((weak)) soidle3_enter(int cpu)
  22. {
  23. return 1;
  24. }
  25. int __attribute__((weak)) soidle_enter(int cpu)
  26. {
  27. return 1;
  28. }
  29. int __attribute__((weak)) mcidle_enter(int cpu)
  30. {
  31. return 1;
  32. }
  33. int __attribute__((weak)) slidle_enter(int cpu)
  34. {
  35. return 1;
  36. }
  37. int __attribute__((weak)) rgidle_enter(int cpu)
  38. {
  39. return 1;
  40. }
  41. static int mt_dpidle_enter(struct cpuidle_device *dev,
  42. struct cpuidle_driver *drv, int index)
  43. {
  44. return dpidle_enter(smp_processor_id());
  45. }
  46. static int mt_soidle3_enter(struct cpuidle_device *dev,
  47. struct cpuidle_driver *drv, int index)
  48. {
  49. return soidle3_enter(smp_processor_id());
  50. }
  51. static int mt_soidle_enter(struct cpuidle_device *dev,
  52. struct cpuidle_driver *drv, int index)
  53. {
  54. return soidle_enter(smp_processor_id());
  55. }
  56. static int mt_mcidle_enter(struct cpuidle_device *dev,
  57. struct cpuidle_driver *drv, int index)
  58. {
  59. return mcidle_enter(smp_processor_id());
  60. }
  61. static int mt_slidle_enter(struct cpuidle_device *dev,
  62. struct cpuidle_driver *drv, int index)
  63. {
  64. return slidle_enter(smp_processor_id());
  65. }
  66. static int mt_rgidle_enter(struct cpuidle_device *dev,
  67. struct cpuidle_driver *drv, int index)
  68. {
  69. return rgidle_enter(smp_processor_id());
  70. }
  71. static struct cpuidle_driver mt67xx_v2_cpuidle_driver = {
  72. .name = "mt67xx_v2_cpuidle",
  73. .owner = THIS_MODULE,
  74. .states[0] = {
  75. .enter = mt_dpidle_enter,
  76. .exit_latency = 2000, /* 2 ms */
  77. .target_residency = 1,
  78. .flags = CPUIDLE_FLAG_TIME_VALID,
  79. .name = "dpidle",
  80. .desc = "deepidle",
  81. },
  82. .states[1] = {
  83. .enter = mt_soidle3_enter,
  84. .exit_latency = 5000, /* 5 ms */
  85. .target_residency = 1,
  86. .flags = CPUIDLE_FLAG_TIME_VALID,
  87. .name = "SODI3",
  88. .desc = "SODI3",
  89. },
  90. .states[2] = {
  91. .enter = mt_soidle_enter,
  92. .exit_latency = 2000, /* 2 ms */
  93. .target_residency = 1,
  94. .flags = CPUIDLE_FLAG_TIME_VALID,
  95. .name = "SODI",
  96. .desc = "SODI",
  97. },
  98. .states[3] = {
  99. .enter = mt_mcidle_enter,
  100. .exit_latency = 2000, /* 2 ms */
  101. .target_residency = 1,
  102. .flags = CPUIDLE_FLAG_TIME_VALID,
  103. .name = "MCDI",
  104. .desc = "MCDI",
  105. },
  106. .states[4] = {
  107. .enter = mt_slidle_enter,
  108. .exit_latency = 2000, /* 2 ms */
  109. .target_residency = 1,
  110. .flags = CPUIDLE_FLAG_TIME_VALID,
  111. .name = "slidle",
  112. .desc = "slidle",
  113. },
  114. .states[5] = {
  115. .enter = mt_rgidle_enter,
  116. .exit_latency = 2000, /* 2 ms */
  117. .target_residency = 1,
  118. .flags = CPUIDLE_FLAG_TIME_VALID,
  119. .name = "rgidle",
  120. .desc = "WFI",
  121. },
  122. .state_count = 6,
  123. .safe_state_index = 0,
  124. };
  125. #ifdef CONFIG_ARM64
  126. static const struct of_device_id mt67xx_v2_idle_state_match[] __initconst = {
  127. { .compatible = "arm,idle-state" },
  128. { },
  129. };
  130. /*
  131. * arm64_idle_init
  132. *
  133. * Registers the arm64 specific cpuidle driver with the cpuidle
  134. * framework. It relies on core code to parse the idle states
  135. * and initialize them using driver data structures accordingly.
  136. */
  137. int __init mt67xx_v2_cpuidle_init(void)
  138. {
  139. int cpu, ret;
  140. struct cpuidle_driver *drv = &mt67xx_v2_cpuidle_driver;
  141. /*
  142. * Call arch CPU operations in order to initialize
  143. * idle states suspend back-end specific data
  144. */
  145. for_each_possible_cpu(cpu) {
  146. ret = cpu_init_idle(cpu);
  147. if (ret) {
  148. pr_err("CPU %d failed to init idle CPU ops\n", cpu);
  149. return ret;
  150. }
  151. }
  152. ret = cpuidle_register(drv, NULL);
  153. if (ret) {
  154. pr_err("failed to register cpuidle driver\n");
  155. return ret;
  156. }
  157. return 0;
  158. }
  159. #else
  160. int __init mt67xx_v2_cpuidle_init(void)
  161. {
  162. return cpuidle_register(&mt67xx_v2_cpuidle_driver, NULL);
  163. }
  164. #endif
  165. device_initcall(mt67xx_v2_cpuidle_init);