cpuidle44xx.c 4.8 KB

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