cpuidle44xx.c 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207
  1. /*
  2. * OMAP4 CPU idle Routines
  3. *
  4. * Copyright (C) 2011 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 <linux/clockchips.h>
  17. #include <asm/proc-fns.h>
  18. #include "common.h"
  19. #include "pm.h"
  20. #include "prm.h"
  21. #ifdef CONFIG_CPU_IDLE
  22. /* Machine specific information */
  23. struct omap4_idle_statedata {
  24. u32 cpu_state;
  25. u32 mpu_logic_state;
  26. u32 mpu_state;
  27. };
  28. static struct omap4_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, *cpu0_pd, *cpu1_pd;
  46. /**
  47. * omap4_enter_idle - Programs OMAP4 to enter the specified state
  48. * @dev: cpuidle device
  49. * @drv: cpuidle driver
  50. * @index: the index of state to be entered
  51. *
  52. * Called from the CPUidle framework to program the device to the
  53. * specified low power state selected by the governor.
  54. * Returns the amount of time spent in the low power state.
  55. */
  56. static int omap4_enter_idle(struct cpuidle_device *dev,
  57. struct cpuidle_driver *drv,
  58. int index)
  59. {
  60. struct omap4_idle_statedata *cx = &omap4_idle_data[index];
  61. u32 cpu1_state;
  62. int cpu_id = smp_processor_id();
  63. local_fiq_disable();
  64. /*
  65. * CPU0 has to stay ON (i.e in C1) until CPU1 is OFF state.
  66. * This is necessary to honour hardware recommondation
  67. * of triggeing all the possible low power modes once CPU1 is
  68. * out of coherency and in OFF mode.
  69. * Update dev->last_state so that governor stats reflects right
  70. * data.
  71. */
  72. cpu1_state = pwrdm_read_pwrst(cpu1_pd);
  73. if (cpu1_state != PWRDM_POWER_OFF) {
  74. index = drv->safe_state_index;
  75. cx = &omap4_idle_data[index];
  76. }
  77. if (index > 0)
  78. clockevents_notify(CLOCK_EVT_NOTIFY_BROADCAST_ENTER, &cpu_id);
  79. /*
  80. * Call idle CPU PM enter notifier chain so that
  81. * VFP and per CPU interrupt context is saved.
  82. */
  83. if (cx->cpu_state == PWRDM_POWER_OFF)
  84. cpu_pm_enter();
  85. pwrdm_set_logic_retst(mpu_pd, cx->mpu_logic_state);
  86. omap_set_pwrdm_state(mpu_pd, cx->mpu_state);
  87. /*
  88. * Call idle CPU cluster PM enter notifier chain
  89. * to save GIC and wakeupgen context.
  90. */
  91. if ((cx->mpu_state == PWRDM_POWER_RET) &&
  92. (cx->mpu_logic_state == PWRDM_POWER_OFF))
  93. cpu_cluster_pm_enter();
  94. omap4_enter_lowpower(dev->cpu, cx->cpu_state);
  95. /*
  96. * Call idle CPU PM exit notifier chain to restore
  97. * VFP and per CPU IRQ context. Only CPU0 state is
  98. * considered since CPU1 is managed by CPU hotplug.
  99. */
  100. if (pwrdm_read_prev_pwrst(cpu0_pd) == PWRDM_POWER_OFF)
  101. cpu_pm_exit();
  102. /*
  103. * Call idle CPU cluster PM exit notifier chain
  104. * to restore GIC and wakeupgen context.
  105. */
  106. if (omap4_mpuss_read_prev_context_state())
  107. cpu_cluster_pm_exit();
  108. if (index > 0)
  109. clockevents_notify(CLOCK_EVT_NOTIFY_BROADCAST_EXIT, &cpu_id);
  110. local_fiq_enable();
  111. return index;
  112. }
  113. DEFINE_PER_CPU(struct cpuidle_device, omap4_idle_dev);
  114. struct cpuidle_driver omap4_idle_driver = {
  115. .name = "omap4_idle",
  116. .owner = THIS_MODULE,
  117. .en_core_tk_irqen = 1,
  118. .states = {
  119. {
  120. /* C1 - CPU0 ON + CPU1 ON + MPU ON */
  121. .exit_latency = 2 + 2,
  122. .target_residency = 5,
  123. .flags = CPUIDLE_FLAG_TIME_VALID,
  124. .enter = omap4_enter_idle,
  125. .name = "C1",
  126. .desc = "MPUSS ON"
  127. },
  128. {
  129. /* C2 - CPU0 OFF + CPU1 OFF + MPU CSWR */
  130. .exit_latency = 328 + 440,
  131. .target_residency = 960,
  132. .flags = CPUIDLE_FLAG_TIME_VALID,
  133. .enter = omap4_enter_idle,
  134. .name = "C2",
  135. .desc = "MPUSS CSWR",
  136. },
  137. {
  138. /* C3 - CPU0 OFF + CPU1 OFF + MPU OSWR */
  139. .exit_latency = 460 + 518,
  140. .target_residency = 1100,
  141. .flags = CPUIDLE_FLAG_TIME_VALID,
  142. .enter = omap4_enter_idle,
  143. .name = "C3",
  144. .desc = "MPUSS OSWR",
  145. },
  146. },
  147. .state_count = ARRAY_SIZE(omap4_idle_data),
  148. .safe_state_index = 0,
  149. };
  150. /**
  151. * omap4_idle_init - Init routine for OMAP4 idle
  152. *
  153. * Registers the OMAP4 specific cpuidle driver to the cpuidle
  154. * framework with the valid set of states.
  155. */
  156. int __init omap4_idle_init(void)
  157. {
  158. struct cpuidle_device *dev;
  159. unsigned int cpu_id = 0;
  160. mpu_pd = pwrdm_lookup("mpu_pwrdm");
  161. cpu0_pd = pwrdm_lookup("cpu0_pwrdm");
  162. cpu1_pd = pwrdm_lookup("cpu1_pwrdm");
  163. if ((!mpu_pd) || (!cpu0_pd) || (!cpu1_pd))
  164. return -ENODEV;
  165. dev = &per_cpu(omap4_idle_dev, cpu_id);
  166. dev->cpu = cpu_id;
  167. cpuidle_register_driver(&omap4_idle_driver);
  168. if (cpuidle_register_device(dev)) {
  169. pr_err("%s: CPUidle register device failed\n", __func__);
  170. return -EIO;
  171. }
  172. return 0;
  173. }
  174. #else
  175. int __init omap4_idle_init(void)
  176. {
  177. return 0;
  178. }
  179. #endif /* CONFIG_CPU_IDLE */