cpuidle34xx.c 8.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347
  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/sched.h>
  25. #include <linux/cpuidle.h>
  26. #include <linux/export.h>
  27. #include <linux/cpu_pm.h>
  28. #include <asm/cpuidle.h>
  29. #include "powerdomain.h"
  30. #include "clockdomain.h"
  31. #include "pm.h"
  32. #include "control.h"
  33. #include "common.h"
  34. /* Mach specific information to be recorded in the C-state driver_data */
  35. struct omap3_idle_statedata {
  36. u8 mpu_state;
  37. u8 core_state;
  38. u8 per_min_state;
  39. u8 flags;
  40. };
  41. static struct powerdomain *mpu_pd, *core_pd, *per_pd, *cam_pd;
  42. /*
  43. * Possible flag bits for struct omap3_idle_statedata.flags:
  44. *
  45. * OMAP_CPUIDLE_CX_NO_CLKDM_IDLE: don't allow the MPU clockdomain to go
  46. * inactive. This in turn prevents the MPU DPLL from entering autoidle
  47. * mode, so wakeup latency is greatly reduced, at the cost of additional
  48. * energy consumption. This also prevents the CORE clockdomain from
  49. * entering idle.
  50. */
  51. #define OMAP_CPUIDLE_CX_NO_CLKDM_IDLE BIT(0)
  52. /*
  53. * Prevent PER OFF if CORE is not in RETention or OFF as this would
  54. * disable PER wakeups completely.
  55. */
  56. static struct omap3_idle_statedata omap3_idle_data[] = {
  57. {
  58. .mpu_state = PWRDM_POWER_ON,
  59. .core_state = PWRDM_POWER_ON,
  60. /* In C1 do not allow PER state lower than CORE state */
  61. .per_min_state = PWRDM_POWER_ON,
  62. .flags = OMAP_CPUIDLE_CX_NO_CLKDM_IDLE,
  63. },
  64. {
  65. .mpu_state = PWRDM_POWER_ON,
  66. .core_state = PWRDM_POWER_ON,
  67. .per_min_state = PWRDM_POWER_RET,
  68. },
  69. {
  70. .mpu_state = PWRDM_POWER_RET,
  71. .core_state = PWRDM_POWER_ON,
  72. .per_min_state = PWRDM_POWER_RET,
  73. },
  74. {
  75. .mpu_state = PWRDM_POWER_OFF,
  76. .core_state = PWRDM_POWER_ON,
  77. .per_min_state = PWRDM_POWER_RET,
  78. },
  79. {
  80. .mpu_state = PWRDM_POWER_RET,
  81. .core_state = PWRDM_POWER_RET,
  82. .per_min_state = PWRDM_POWER_OFF,
  83. },
  84. {
  85. .mpu_state = PWRDM_POWER_OFF,
  86. .core_state = PWRDM_POWER_RET,
  87. .per_min_state = PWRDM_POWER_OFF,
  88. },
  89. {
  90. .mpu_state = PWRDM_POWER_OFF,
  91. .core_state = PWRDM_POWER_OFF,
  92. .per_min_state = PWRDM_POWER_OFF,
  93. },
  94. };
  95. /**
  96. * omap3_enter_idle - Programs OMAP3 to enter the specified state
  97. * @dev: cpuidle device
  98. * @drv: cpuidle driver
  99. * @index: the index of state to be entered
  100. */
  101. static int omap3_enter_idle(struct cpuidle_device *dev,
  102. struct cpuidle_driver *drv,
  103. int index)
  104. {
  105. struct omap3_idle_statedata *cx = &omap3_idle_data[index];
  106. local_fiq_disable();
  107. if (omap_irq_pending() || need_resched())
  108. goto return_sleep_time;
  109. /* Deny idle for C1 */
  110. if (cx->flags & OMAP_CPUIDLE_CX_NO_CLKDM_IDLE) {
  111. clkdm_deny_idle(mpu_pd->pwrdm_clkdms[0]);
  112. } else {
  113. pwrdm_set_next_pwrst(mpu_pd, cx->mpu_state);
  114. pwrdm_set_next_pwrst(core_pd, cx->core_state);
  115. }
  116. /*
  117. * Call idle CPU PM enter notifier chain so that
  118. * VFP context is saved.
  119. */
  120. if (cx->mpu_state == PWRDM_POWER_OFF)
  121. cpu_pm_enter();
  122. /* Execute ARM wfi */
  123. omap_sram_idle();
  124. /*
  125. * Call idle CPU PM enter notifier chain to restore
  126. * VFP context.
  127. */
  128. if (cx->mpu_state == PWRDM_POWER_OFF &&
  129. pwrdm_read_prev_pwrst(mpu_pd) == PWRDM_POWER_OFF)
  130. cpu_pm_exit();
  131. /* Re-allow idle for C1 */
  132. if (cx->flags & OMAP_CPUIDLE_CX_NO_CLKDM_IDLE)
  133. clkdm_allow_idle(mpu_pd->pwrdm_clkdms[0]);
  134. return_sleep_time:
  135. local_fiq_enable();
  136. return index;
  137. }
  138. /**
  139. * next_valid_state - Find next valid C-state
  140. * @dev: cpuidle device
  141. * @drv: cpuidle driver
  142. * @index: Index of currently selected c-state
  143. *
  144. * If the state corresponding to index is valid, index is returned back
  145. * to the caller. Else, this function searches for a lower c-state which is
  146. * still valid (as defined in omap3_power_states[]) and returns its index.
  147. *
  148. * A state is valid if the 'valid' field is enabled and
  149. * if it satisfies the enable_off_mode condition.
  150. */
  151. static int next_valid_state(struct cpuidle_device *dev,
  152. struct cpuidle_driver *drv, int index)
  153. {
  154. struct omap3_idle_statedata *cx = &omap3_idle_data[index];
  155. u32 mpu_deepest_state = PWRDM_POWER_RET;
  156. u32 core_deepest_state = PWRDM_POWER_RET;
  157. int idx;
  158. int next_index = 0; /* C1 is the default value */
  159. if (enable_off_mode) {
  160. mpu_deepest_state = PWRDM_POWER_OFF;
  161. /*
  162. * Erratum i583: valable for ES rev < Es1.2 on 3630.
  163. * CORE OFF mode is not supported in a stable form, restrict
  164. * instead the CORE state to RET.
  165. */
  166. if (!IS_PM34XX_ERRATUM(PM_SDRC_WAKEUP_ERRATUM_i583))
  167. core_deepest_state = PWRDM_POWER_OFF;
  168. }
  169. /* Check if current state is valid */
  170. if ((cx->mpu_state >= mpu_deepest_state) &&
  171. (cx->core_state >= core_deepest_state))
  172. return index;
  173. /*
  174. * Drop to next valid state.
  175. * Start search from the next (lower) state.
  176. */
  177. for (idx = index - 1; idx >= 0; idx--) {
  178. cx = &omap3_idle_data[idx];
  179. if ((cx->mpu_state >= mpu_deepest_state) &&
  180. (cx->core_state >= core_deepest_state)) {
  181. next_index = idx;
  182. break;
  183. }
  184. }
  185. return next_index;
  186. }
  187. /**
  188. * omap3_enter_idle_bm - Checks for any bus activity
  189. * @dev: cpuidle device
  190. * @drv: cpuidle driver
  191. * @index: array index of target state to be programmed
  192. *
  193. * This function checks for any pending activity and then programs
  194. * the device to the specified or a safer state.
  195. */
  196. static int omap3_enter_idle_bm(struct cpuidle_device *dev,
  197. struct cpuidle_driver *drv,
  198. int index)
  199. {
  200. int new_state_idx, ret;
  201. u8 per_next_state, per_saved_state;
  202. struct omap3_idle_statedata *cx;
  203. /*
  204. * Use only C1 if CAM is active.
  205. * CAM does not have wakeup capability in OMAP3.
  206. */
  207. if (pwrdm_read_pwrst(cam_pd) == PWRDM_POWER_ON)
  208. new_state_idx = drv->safe_state_index;
  209. else
  210. new_state_idx = next_valid_state(dev, drv, index);
  211. /*
  212. * FIXME: we currently manage device-specific idle states
  213. * for PER and CORE in combination with CPU-specific
  214. * idle states. This is wrong, and device-specific
  215. * idle management needs to be separated out into
  216. * its own code.
  217. */
  218. /* Program PER state */
  219. cx = &omap3_idle_data[new_state_idx];
  220. per_next_state = pwrdm_read_next_pwrst(per_pd);
  221. per_saved_state = per_next_state;
  222. if (per_next_state < cx->per_min_state) {
  223. per_next_state = cx->per_min_state;
  224. pwrdm_set_next_pwrst(per_pd, per_next_state);
  225. }
  226. ret = omap3_enter_idle(dev, drv, new_state_idx);
  227. /* Restore original PER state if it was modified */
  228. if (per_next_state != per_saved_state)
  229. pwrdm_set_next_pwrst(per_pd, per_saved_state);
  230. return ret;
  231. }
  232. static struct cpuidle_driver omap3_idle_driver = {
  233. .name = "omap3_idle",
  234. .owner = THIS_MODULE,
  235. .states = {
  236. {
  237. .enter = omap3_enter_idle_bm,
  238. .exit_latency = 2 + 2,
  239. .target_residency = 5,
  240. .flags = CPUIDLE_FLAG_TIME_VALID,
  241. .name = "C1",
  242. .desc = "MPU ON + CORE ON",
  243. },
  244. {
  245. .enter = omap3_enter_idle_bm,
  246. .exit_latency = 10 + 10,
  247. .target_residency = 30,
  248. .flags = CPUIDLE_FLAG_TIME_VALID,
  249. .name = "C2",
  250. .desc = "MPU ON + CORE ON",
  251. },
  252. {
  253. .enter = omap3_enter_idle_bm,
  254. .exit_latency = 50 + 50,
  255. .target_residency = 300,
  256. .flags = CPUIDLE_FLAG_TIME_VALID,
  257. .name = "C3",
  258. .desc = "MPU RET + CORE ON",
  259. },
  260. {
  261. .enter = omap3_enter_idle_bm,
  262. .exit_latency = 1500 + 1800,
  263. .target_residency = 4000,
  264. .flags = CPUIDLE_FLAG_TIME_VALID,
  265. .name = "C4",
  266. .desc = "MPU OFF + CORE ON",
  267. },
  268. {
  269. .enter = omap3_enter_idle_bm,
  270. .exit_latency = 2500 + 7500,
  271. .target_residency = 12000,
  272. .flags = CPUIDLE_FLAG_TIME_VALID,
  273. .name = "C5",
  274. .desc = "MPU RET + CORE RET",
  275. },
  276. {
  277. .enter = omap3_enter_idle_bm,
  278. .exit_latency = 3000 + 8500,
  279. .target_residency = 15000,
  280. .flags = CPUIDLE_FLAG_TIME_VALID,
  281. .name = "C6",
  282. .desc = "MPU OFF + CORE RET",
  283. },
  284. {
  285. .enter = omap3_enter_idle_bm,
  286. .exit_latency = 10000 + 30000,
  287. .target_residency = 30000,
  288. .flags = CPUIDLE_FLAG_TIME_VALID,
  289. .name = "C7",
  290. .desc = "MPU OFF + CORE OFF",
  291. },
  292. },
  293. .state_count = ARRAY_SIZE(omap3_idle_data),
  294. .safe_state_index = 0,
  295. };
  296. /* Public functions */
  297. /**
  298. * omap3_idle_init - Init routine for OMAP3 idle
  299. *
  300. * Registers the OMAP3 specific cpuidle driver to the cpuidle
  301. * framework with the valid set of states.
  302. */
  303. int __init omap3_idle_init(void)
  304. {
  305. mpu_pd = pwrdm_lookup("mpu_pwrdm");
  306. core_pd = pwrdm_lookup("core_pwrdm");
  307. per_pd = pwrdm_lookup("per_pwrdm");
  308. cam_pd = pwrdm_lookup("cam_pwrdm");
  309. if (!mpu_pd || !core_pd || !per_pd || !cam_pd)
  310. return -ENODEV;
  311. return cpuidle_register(&omap3_idle_driver, NULL);
  312. }