cpuidle34xx.c 7.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255
  1. /*
  2. * linux/arch/arm/mach-omap2/cpuidle34xx.c
  3. *
  4. * OMAP3 CPU IDLE Routines
  5. *
  6. * Copyright (C) 2008 Texas Instruments, Inc.
  7. * Rajendra Nayak <rnayak@ti.com>
  8. *
  9. * Copyright (C) 2007 Texas Instruments, Inc.
  10. * Karthik Dasu <karthik-dp@ti.com>
  11. *
  12. * Copyright (C) 2006 Nokia Corporation
  13. * Tony Lindgren <tony@atomide.com>
  14. *
  15. * Copyright (C) 2005 Texas Instruments, Inc.
  16. * Richard Woodruff <r-woodruff2@ti.com>
  17. *
  18. * Based on pm.c for omap2
  19. *
  20. * This program is free software; you can redistribute it and/or modify
  21. * it under the terms of the GNU General Public License version 2 as
  22. * published by the Free Software Foundation.
  23. */
  24. #include <linux/cpuidle.h>
  25. #include <plat/prcm.h>
  26. #include <plat/powerdomain.h>
  27. #ifdef CONFIG_CPU_IDLE
  28. #define OMAP3_MAX_STATES 7
  29. #define OMAP3_STATE_C1 1 /* C1 - MPU WFI + Core active */
  30. #define OMAP3_STATE_C2 2 /* C2 - MPU CSWR + Core active */
  31. #define OMAP3_STATE_C3 3 /* C3 - MPU OFF + Core active */
  32. #define OMAP3_STATE_C4 4 /* C4 - MPU RET + Core RET */
  33. #define OMAP3_STATE_C5 5 /* C5 - MPU OFF + Core RET */
  34. #define OMAP3_STATE_C6 6 /* C6 - MPU OFF + Core OFF */
  35. struct omap3_processor_cx {
  36. u8 valid;
  37. u8 type;
  38. u32 sleep_latency;
  39. u32 wakeup_latency;
  40. u32 mpu_state;
  41. u32 core_state;
  42. u32 threshold;
  43. u32 flags;
  44. };
  45. struct omap3_processor_cx omap3_power_states[OMAP3_MAX_STATES];
  46. struct omap3_processor_cx current_cx_state;
  47. struct powerdomain *mpu_pd;
  48. static int omap3_idle_bm_check(void)
  49. {
  50. return 0;
  51. }
  52. /**
  53. * omap3_enter_idle - Programs OMAP3 to enter the specified state
  54. * @dev: cpuidle device
  55. * @state: The target state to be programmed
  56. *
  57. * Called from the CPUidle framework to program the device to the
  58. * specified target state selected by the governor.
  59. */
  60. static int omap3_enter_idle(struct cpuidle_device *dev,
  61. struct cpuidle_state *state)
  62. {
  63. struct omap3_processor_cx *cx = cpuidle_get_statedata(state);
  64. struct timespec ts_preidle, ts_postidle, ts_idle;
  65. current_cx_state = *cx;
  66. /* Used to keep track of the total time in idle */
  67. getnstimeofday(&ts_preidle);
  68. local_irq_disable();
  69. local_fiq_disable();
  70. /* Program MPU to target state */
  71. if (cx->mpu_state < PWRDM_POWER_ON)
  72. pwrdm_set_next_pwrst(mpu_pd, cx->mpu_state);
  73. /* Execute ARM wfi */
  74. omap_sram_idle();
  75. /* Program MPU to ON */
  76. if (cx->mpu_state < PWRDM_POWER_ON)
  77. pwrdm_set_next_pwrst(mpu_pd, PWRDM_POWER_ON);
  78. getnstimeofday(&ts_postidle);
  79. ts_idle = timespec_sub(ts_postidle, ts_preidle);
  80. local_irq_enable();
  81. local_fiq_enable();
  82. return timespec_to_ns(&ts_idle);
  83. }
  84. /**
  85. * omap3_enter_idle_bm - Checks for any bus activity
  86. * @dev: cpuidle device
  87. * @state: The target state to be programmed
  88. *
  89. * Used for C states with CPUIDLE_FLAG_CHECK_BM flag set. This
  90. * function checks for any pending activity and then programs the
  91. * device to the specified or a safer state.
  92. */
  93. static int omap3_enter_idle_bm(struct cpuidle_device *dev,
  94. struct cpuidle_state *state)
  95. {
  96. if ((state->flags & CPUIDLE_FLAG_CHECK_BM) && omap3_idle_bm_check()) {
  97. if (dev->safe_state)
  98. return dev->safe_state->enter(dev, dev->safe_state);
  99. }
  100. return omap3_enter_idle(dev, state);
  101. }
  102. DEFINE_PER_CPU(struct cpuidle_device, omap3_idle_dev);
  103. /* omap3_init_power_states - Initialises the OMAP3 specific C states.
  104. *
  105. * Below is the desciption of each C state.
  106. * C1 . MPU WFI + Core active
  107. * C2 . MPU CSWR + Core active
  108. * C3 . MPU OFF + Core active
  109. * C4 . MPU CSWR + Core CSWR
  110. * C5 . MPU OFF + Core CSWR
  111. * C6 . MPU OFF + Core OFF
  112. */
  113. void omap_init_power_states(void)
  114. {
  115. /* C1 . MPU WFI + Core active */
  116. omap3_power_states[OMAP3_STATE_C1].valid = 1;
  117. omap3_power_states[OMAP3_STATE_C1].type = OMAP3_STATE_C1;
  118. omap3_power_states[OMAP3_STATE_C1].sleep_latency = 10;
  119. omap3_power_states[OMAP3_STATE_C1].wakeup_latency = 10;
  120. omap3_power_states[OMAP3_STATE_C1].threshold = 30;
  121. omap3_power_states[OMAP3_STATE_C1].mpu_state = PWRDM_POWER_ON;
  122. omap3_power_states[OMAP3_STATE_C1].core_state = PWRDM_POWER_ON;
  123. omap3_power_states[OMAP3_STATE_C1].flags = CPUIDLE_FLAG_TIME_VALID;
  124. /* C2 . MPU CSWR + Core active */
  125. omap3_power_states[OMAP3_STATE_C2].valid = 1;
  126. omap3_power_states[OMAP3_STATE_C2].type = OMAP3_STATE_C2;
  127. omap3_power_states[OMAP3_STATE_C2].sleep_latency = 50;
  128. omap3_power_states[OMAP3_STATE_C2].wakeup_latency = 50;
  129. omap3_power_states[OMAP3_STATE_C2].threshold = 300;
  130. omap3_power_states[OMAP3_STATE_C2].mpu_state = PWRDM_POWER_RET;
  131. omap3_power_states[OMAP3_STATE_C2].core_state = PWRDM_POWER_ON;
  132. omap3_power_states[OMAP3_STATE_C2].flags = CPUIDLE_FLAG_TIME_VALID;
  133. /* C3 . MPU OFF + Core active */
  134. omap3_power_states[OMAP3_STATE_C3].valid = 0;
  135. omap3_power_states[OMAP3_STATE_C3].type = OMAP3_STATE_C3;
  136. omap3_power_states[OMAP3_STATE_C3].sleep_latency = 1500;
  137. omap3_power_states[OMAP3_STATE_C3].wakeup_latency = 1800;
  138. omap3_power_states[OMAP3_STATE_C3].threshold = 4000;
  139. omap3_power_states[OMAP3_STATE_C3].mpu_state = PWRDM_POWER_OFF;
  140. omap3_power_states[OMAP3_STATE_C3].core_state = PWRDM_POWER_ON;
  141. omap3_power_states[OMAP3_STATE_C3].flags = CPUIDLE_FLAG_TIME_VALID;
  142. /* C4 . MPU CSWR + Core CSWR*/
  143. omap3_power_states[OMAP3_STATE_C4].valid = 0;
  144. omap3_power_states[OMAP3_STATE_C4].type = OMAP3_STATE_C4;
  145. omap3_power_states[OMAP3_STATE_C4].sleep_latency = 2500;
  146. omap3_power_states[OMAP3_STATE_C4].wakeup_latency = 7500;
  147. omap3_power_states[OMAP3_STATE_C4].threshold = 12000;
  148. omap3_power_states[OMAP3_STATE_C4].mpu_state = PWRDM_POWER_RET;
  149. omap3_power_states[OMAP3_STATE_C4].core_state = PWRDM_POWER_RET;
  150. omap3_power_states[OMAP3_STATE_C4].flags = CPUIDLE_FLAG_TIME_VALID |
  151. CPUIDLE_FLAG_CHECK_BM;
  152. /* C5 . MPU OFF + Core CSWR */
  153. omap3_power_states[OMAP3_STATE_C5].valid = 0;
  154. omap3_power_states[OMAP3_STATE_C5].type = OMAP3_STATE_C5;
  155. omap3_power_states[OMAP3_STATE_C5].sleep_latency = 3000;
  156. omap3_power_states[OMAP3_STATE_C5].wakeup_latency = 8500;
  157. omap3_power_states[OMAP3_STATE_C5].threshold = 15000;
  158. omap3_power_states[OMAP3_STATE_C5].mpu_state = PWRDM_POWER_OFF;
  159. omap3_power_states[OMAP3_STATE_C5].core_state = PWRDM_POWER_RET;
  160. omap3_power_states[OMAP3_STATE_C5].flags = CPUIDLE_FLAG_TIME_VALID |
  161. CPUIDLE_FLAG_CHECK_BM;
  162. /* C6 . MPU OFF + Core OFF */
  163. omap3_power_states[OMAP3_STATE_C6].valid = 0;
  164. omap3_power_states[OMAP3_STATE_C6].type = OMAP3_STATE_C6;
  165. omap3_power_states[OMAP3_STATE_C6].sleep_latency = 10000;
  166. omap3_power_states[OMAP3_STATE_C6].wakeup_latency = 30000;
  167. omap3_power_states[OMAP3_STATE_C6].threshold = 300000;
  168. omap3_power_states[OMAP3_STATE_C6].mpu_state = PWRDM_POWER_OFF;
  169. omap3_power_states[OMAP3_STATE_C6].core_state = PWRDM_POWER_OFF;
  170. omap3_power_states[OMAP3_STATE_C6].flags = CPUIDLE_FLAG_TIME_VALID |
  171. CPUIDLE_FLAG_CHECK_BM;
  172. }
  173. struct cpuidle_driver omap3_idle_driver = {
  174. .name = "omap3_idle",
  175. .owner = THIS_MODULE,
  176. };
  177. /**
  178. * omap3_idle_init - Init routine for OMAP3 idle
  179. *
  180. * Registers the OMAP3 specific cpuidle driver with the cpuidle
  181. * framework with the valid set of states.
  182. */
  183. int omap3_idle_init(void)
  184. {
  185. int i, count = 0;
  186. struct omap3_processor_cx *cx;
  187. struct cpuidle_state *state;
  188. struct cpuidle_device *dev;
  189. mpu_pd = pwrdm_lookup("mpu_pwrdm");
  190. omap_init_power_states();
  191. cpuidle_register_driver(&omap3_idle_driver);
  192. dev = &per_cpu(omap3_idle_dev, smp_processor_id());
  193. for (i = 1; i < OMAP3_MAX_STATES; i++) {
  194. cx = &omap3_power_states[i];
  195. state = &dev->states[count];
  196. if (!cx->valid)
  197. continue;
  198. cpuidle_set_statedata(state, cx);
  199. state->exit_latency = cx->sleep_latency + cx->wakeup_latency;
  200. state->target_residency = cx->threshold;
  201. state->flags = cx->flags;
  202. state->enter = (state->flags & CPUIDLE_FLAG_CHECK_BM) ?
  203. omap3_enter_idle_bm : omap3_enter_idle;
  204. if (cx->type == OMAP3_STATE_C1)
  205. dev->safe_state = state;
  206. sprintf(state->name, "C%d", count+1);
  207. count++;
  208. }
  209. if (!count)
  210. return -EINVAL;
  211. dev->state_count = count;
  212. if (cpuidle_register_device(dev)) {
  213. printk(KERN_ERR "%s: CPUidle register device failed\n",
  214. __func__);
  215. return -EIO;
  216. }
  217. return 0;
  218. }
  219. device_initcall(omap3_idle_init);
  220. #endif /* CONFIG_CPU_IDLE */