cpuidle44xx.c 5.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217
  1. /*
  2. * OMAP4+ CPU idle Routines
  3. *
  4. * Copyright (C) 2011-2013 Texas Instruments, Inc.
  5. * Santosh Shilimkar <santosh.shilimkar@ti.com>
  6. * Rajendra Nayak <rnayak@ti.com>
  7. *
  8. * This program is free software; you can redistribute it and/or modify
  9. * it under the terms of the GNU General Public License version 2 as
  10. * published by the Free Software Foundation.
  11. */
  12. #include <linux/sched.h>
  13. #include <linux/cpuidle.h>
  14. #include <linux/cpu_pm.h>
  15. #include <linux/export.h>
  16. #include <asm/cpuidle.h>
  17. #include <asm/proc-fns.h>
  18. #include "common.h"
  19. #include "pm.h"
  20. #include "prm.h"
  21. #include "clockdomain.h"
  22. /* Machine specific information */
  23. struct idle_statedata {
  24. u32 cpu_state;
  25. u32 mpu_logic_state;
  26. u32 mpu_state;
  27. };
  28. static struct idle_statedata omap4_idle_data[] = {
  29. {
  30. .cpu_state = PWRDM_POWER_ON,
  31. .mpu_state = PWRDM_POWER_ON,
  32. .mpu_logic_state = PWRDM_POWER_RET,
  33. },
  34. {
  35. .cpu_state = PWRDM_POWER_OFF,
  36. .mpu_state = PWRDM_POWER_RET,
  37. .mpu_logic_state = PWRDM_POWER_RET,
  38. },
  39. {
  40. .cpu_state = PWRDM_POWER_OFF,
  41. .mpu_state = PWRDM_POWER_RET,
  42. .mpu_logic_state = PWRDM_POWER_OFF,
  43. },
  44. };
  45. static struct powerdomain *mpu_pd, *cpu_pd[NR_CPUS];
  46. static struct clockdomain *cpu_clkdm[NR_CPUS];
  47. static atomic_t abort_barrier;
  48. static bool cpu_done[NR_CPUS];
  49. static struct idle_statedata *state_ptr = &omap4_idle_data[0];
  50. /* Private functions */
  51. /**
  52. * omap_enter_idle_[simple/coupled] - OMAP4PLUS cpuidle entry functions
  53. * @dev: cpuidle device
  54. * @drv: cpuidle driver
  55. * @index: the index of state to be entered
  56. *
  57. * Called from the CPUidle framework to program the device to the
  58. * specified low power state selected by the governor.
  59. * Returns the amount of time spent in the low power state.
  60. */
  61. static int omap_enter_idle_simple(struct cpuidle_device *dev,
  62. struct cpuidle_driver *drv,
  63. int index)
  64. {
  65. omap_do_wfi();
  66. return index;
  67. }
  68. static int omap_enter_idle_coupled(struct cpuidle_device *dev,
  69. struct cpuidle_driver *drv,
  70. int index)
  71. {
  72. struct idle_statedata *cx = state_ptr + index;
  73. /*
  74. * CPU0 has to wait and stay ON until CPU1 is OFF state.
  75. * This is necessary to honour hardware recommondation
  76. * of triggeing all the possible low power modes once CPU1 is
  77. * out of coherency and in OFF mode.
  78. */
  79. if (dev->cpu == 0 && cpumask_test_cpu(1, cpu_online_mask)) {
  80. while (pwrdm_read_pwrst(cpu_pd[1]) != PWRDM_POWER_OFF) {
  81. cpu_relax();
  82. /*
  83. * CPU1 could have already entered & exited idle
  84. * without hitting off because of a wakeup
  85. * or a failed attempt to hit off mode. Check for
  86. * that here, otherwise we could spin forever
  87. * waiting for CPU1 off.
  88. */
  89. if (cpu_done[1])
  90. goto fail;
  91. }
  92. }
  93. /*
  94. * Call idle CPU PM enter notifier chain so that
  95. * VFP and per CPU interrupt context is saved.
  96. */
  97. cpu_pm_enter();
  98. if (dev->cpu == 0) {
  99. pwrdm_set_logic_retst(mpu_pd, cx->mpu_logic_state);
  100. omap_set_pwrdm_state(mpu_pd, cx->mpu_state);
  101. /*
  102. * Call idle CPU cluster PM enter notifier chain
  103. * to save GIC and wakeupgen context.
  104. */
  105. if ((cx->mpu_state == PWRDM_POWER_RET) &&
  106. (cx->mpu_logic_state == PWRDM_POWER_OFF))
  107. cpu_cluster_pm_enter();
  108. }
  109. omap4_enter_lowpower(dev->cpu, cx->cpu_state);
  110. cpu_done[dev->cpu] = true;
  111. /* Wakeup CPU1 only if it is not offlined */
  112. if (dev->cpu == 0 && cpumask_test_cpu(1, cpu_online_mask)) {
  113. clkdm_wakeup(cpu_clkdm[1]);
  114. omap_set_pwrdm_state(cpu_pd[1], PWRDM_POWER_ON);
  115. clkdm_allow_idle(cpu_clkdm[1]);
  116. }
  117. /*
  118. * Call idle CPU PM exit notifier chain to restore
  119. * VFP and per CPU IRQ context.
  120. */
  121. cpu_pm_exit();
  122. /*
  123. * Call idle CPU cluster PM exit notifier chain
  124. * to restore GIC and wakeupgen context.
  125. */
  126. if ((cx->mpu_state == PWRDM_POWER_RET) &&
  127. (cx->mpu_logic_state == PWRDM_POWER_OFF))
  128. cpu_cluster_pm_exit();
  129. fail:
  130. cpuidle_coupled_parallel_barrier(dev, &abort_barrier);
  131. cpu_done[dev->cpu] = false;
  132. return index;
  133. }
  134. static struct cpuidle_driver omap4_idle_driver = {
  135. .name = "omap4_idle",
  136. .owner = THIS_MODULE,
  137. .states = {
  138. {
  139. /* C1 - CPU0 ON + CPU1 ON + MPU ON */
  140. .exit_latency = 2 + 2,
  141. .target_residency = 5,
  142. .flags = CPUIDLE_FLAG_TIME_VALID,
  143. .enter = omap_enter_idle_simple,
  144. .name = "C1",
  145. .desc = "CPUx ON, MPUSS ON"
  146. },
  147. {
  148. /* C2 - CPU0 OFF + CPU1 OFF + MPU CSWR */
  149. .exit_latency = 328 + 440,
  150. .target_residency = 960,
  151. .flags = CPUIDLE_FLAG_TIME_VALID | CPUIDLE_FLAG_COUPLED |
  152. CPUIDLE_FLAG_TIMER_STOP,
  153. .enter = omap_enter_idle_coupled,
  154. .name = "C2",
  155. .desc = "CPUx OFF, MPUSS CSWR",
  156. },
  157. {
  158. /* C3 - CPU0 OFF + CPU1 OFF + MPU OSWR */
  159. .exit_latency = 460 + 518,
  160. .target_residency = 1100,
  161. .flags = CPUIDLE_FLAG_TIME_VALID | CPUIDLE_FLAG_COUPLED |
  162. CPUIDLE_FLAG_TIMER_STOP,
  163. .enter = omap_enter_idle_coupled,
  164. .name = "C3",
  165. .desc = "CPUx OFF, MPUSS OSWR",
  166. },
  167. },
  168. .state_count = ARRAY_SIZE(omap4_idle_data),
  169. .safe_state_index = 0,
  170. };
  171. /* Public functions */
  172. /**
  173. * omap4_idle_init - Init routine for OMAP4+ idle
  174. *
  175. * Registers the OMAP4+ specific cpuidle driver to the cpuidle
  176. * framework with the valid set of states.
  177. */
  178. int __init omap4_idle_init(void)
  179. {
  180. mpu_pd = pwrdm_lookup("mpu_pwrdm");
  181. cpu_pd[0] = pwrdm_lookup("cpu0_pwrdm");
  182. cpu_pd[1] = pwrdm_lookup("cpu1_pwrdm");
  183. if ((!mpu_pd) || (!cpu_pd[0]) || (!cpu_pd[1]))
  184. return -ENODEV;
  185. cpu_clkdm[0] = clkdm_lookup("mpu0_clkdm");
  186. cpu_clkdm[1] = clkdm_lookup("mpu1_clkdm");
  187. if (!cpu_clkdm[0] || !cpu_clkdm[1])
  188. return -ENODEV;
  189. return cpuidle_register(&omap4_idle_driver, cpu_online_mask);
  190. }