cpuidle34xx.c 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405
  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. #include "soc.h"
  35. /* Mach specific information to be recorded in the C-state driver_data */
  36. struct omap3_idle_statedata {
  37. u8 mpu_state;
  38. u8 core_state;
  39. u8 per_min_state;
  40. u8 flags;
  41. };
  42. static struct powerdomain *mpu_pd, *core_pd, *per_pd, *cam_pd;
  43. /*
  44. * Possible flag bits for struct omap3_idle_statedata.flags:
  45. *
  46. * OMAP_CPUIDLE_CX_NO_CLKDM_IDLE: don't allow the MPU clockdomain to go
  47. * inactive. This in turn prevents the MPU DPLL from entering autoidle
  48. * mode, so wakeup latency is greatly reduced, at the cost of additional
  49. * energy consumption. This also prevents the CORE clockdomain from
  50. * entering idle.
  51. */
  52. #define OMAP_CPUIDLE_CX_NO_CLKDM_IDLE BIT(0)
  53. /*
  54. * Prevent PER OFF if CORE is not in RETention or OFF as this would
  55. * disable PER wakeups completely.
  56. */
  57. static struct omap3_idle_statedata omap3_idle_data[] = {
  58. {
  59. .mpu_state = PWRDM_POWER_ON,
  60. .core_state = PWRDM_POWER_ON,
  61. /* In C1 do not allow PER state lower than CORE state */
  62. .per_min_state = PWRDM_POWER_ON,
  63. .flags = OMAP_CPUIDLE_CX_NO_CLKDM_IDLE,
  64. },
  65. {
  66. .mpu_state = PWRDM_POWER_ON,
  67. .core_state = PWRDM_POWER_ON,
  68. .per_min_state = PWRDM_POWER_RET,
  69. },
  70. {
  71. .mpu_state = PWRDM_POWER_RET,
  72. .core_state = PWRDM_POWER_ON,
  73. .per_min_state = PWRDM_POWER_RET,
  74. },
  75. {
  76. .mpu_state = PWRDM_POWER_OFF,
  77. .core_state = PWRDM_POWER_ON,
  78. .per_min_state = PWRDM_POWER_RET,
  79. },
  80. {
  81. .mpu_state = PWRDM_POWER_RET,
  82. .core_state = PWRDM_POWER_RET,
  83. .per_min_state = PWRDM_POWER_OFF,
  84. },
  85. {
  86. .mpu_state = PWRDM_POWER_OFF,
  87. .core_state = PWRDM_POWER_RET,
  88. .per_min_state = PWRDM_POWER_OFF,
  89. },
  90. {
  91. .mpu_state = PWRDM_POWER_OFF,
  92. .core_state = PWRDM_POWER_OFF,
  93. .per_min_state = PWRDM_POWER_OFF,
  94. },
  95. };
  96. /**
  97. * omap3_enter_idle - Programs OMAP3 to enter the specified state
  98. * @dev: cpuidle device
  99. * @drv: cpuidle driver
  100. * @index: the index of state to be entered
  101. */
  102. static int omap3_enter_idle(struct cpuidle_device *dev,
  103. struct cpuidle_driver *drv,
  104. int index)
  105. {
  106. struct omap3_idle_statedata *cx = &omap3_idle_data[index];
  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. return index;
  136. }
  137. /**
  138. * next_valid_state - Find next valid C-state
  139. * @dev: cpuidle device
  140. * @drv: cpuidle driver
  141. * @index: Index of currently selected c-state
  142. *
  143. * If the state corresponding to index is valid, index is returned back
  144. * to the caller. Else, this function searches for a lower c-state which is
  145. * still valid (as defined in omap3_power_states[]) and returns its index.
  146. *
  147. * A state is valid if the 'valid' field is enabled and
  148. * if it satisfies the enable_off_mode condition.
  149. */
  150. static int next_valid_state(struct cpuidle_device *dev,
  151. struct cpuidle_driver *drv, int index)
  152. {
  153. struct omap3_idle_statedata *cx = &omap3_idle_data[index];
  154. u32 mpu_deepest_state = PWRDM_POWER_RET;
  155. u32 core_deepest_state = PWRDM_POWER_RET;
  156. int idx;
  157. int next_index = 0; /* C1 is the default value */
  158. if (enable_off_mode) {
  159. mpu_deepest_state = PWRDM_POWER_OFF;
  160. /*
  161. * Erratum i583: valable for ES rev < Es1.2 on 3630.
  162. * CORE OFF mode is not supported in a stable form, restrict
  163. * instead the CORE state to RET.
  164. */
  165. if (!IS_PM34XX_ERRATUM(PM_SDRC_WAKEUP_ERRATUM_i583))
  166. core_deepest_state = PWRDM_POWER_OFF;
  167. }
  168. /* Check if current state is valid */
  169. if ((cx->mpu_state >= mpu_deepest_state) &&
  170. (cx->core_state >= core_deepest_state))
  171. return index;
  172. /*
  173. * Drop to next valid state.
  174. * Start search from the next (lower) state.
  175. */
  176. for (idx = index - 1; idx >= 0; idx--) {
  177. cx = &omap3_idle_data[idx];
  178. if ((cx->mpu_state >= mpu_deepest_state) &&
  179. (cx->core_state >= core_deepest_state)) {
  180. next_index = idx;
  181. break;
  182. }
  183. }
  184. return next_index;
  185. }
  186. /**
  187. * omap3_enter_idle_bm - Checks for any bus activity
  188. * @dev: cpuidle device
  189. * @drv: cpuidle driver
  190. * @index: array index of target state to be programmed
  191. *
  192. * This function checks for any pending activity and then programs
  193. * the device to the specified or a safer state.
  194. */
  195. static int omap3_enter_idle_bm(struct cpuidle_device *dev,
  196. struct cpuidle_driver *drv,
  197. int index)
  198. {
  199. int new_state_idx, ret;
  200. u8 per_next_state, per_saved_state;
  201. struct omap3_idle_statedata *cx;
  202. /*
  203. * Use only C1 if CAM is active.
  204. * CAM does not have wakeup capability in OMAP3.
  205. */
  206. if (pwrdm_read_pwrst(cam_pd) == PWRDM_POWER_ON)
  207. new_state_idx = drv->safe_state_index;
  208. else
  209. new_state_idx = next_valid_state(dev, drv, index);
  210. /*
  211. * FIXME: we currently manage device-specific idle states
  212. * for PER and CORE in combination with CPU-specific
  213. * idle states. This is wrong, and device-specific
  214. * idle management needs to be separated out into
  215. * its own code.
  216. */
  217. /* Program PER state */
  218. cx = &omap3_idle_data[new_state_idx];
  219. per_next_state = pwrdm_read_next_pwrst(per_pd);
  220. per_saved_state = per_next_state;
  221. if (per_next_state < cx->per_min_state) {
  222. per_next_state = cx->per_min_state;
  223. pwrdm_set_next_pwrst(per_pd, per_next_state);
  224. }
  225. ret = omap3_enter_idle(dev, drv, new_state_idx);
  226. /* Restore original PER state if it was modified */
  227. if (per_next_state != per_saved_state)
  228. pwrdm_set_next_pwrst(per_pd, per_saved_state);
  229. return ret;
  230. }
  231. static struct cpuidle_driver omap3_idle_driver = {
  232. .name = "omap3_idle",
  233. .owner = THIS_MODULE,
  234. .states = {
  235. {
  236. .enter = omap3_enter_idle_bm,
  237. .exit_latency = 2 + 2,
  238. .target_residency = 5,
  239. .name = "C1",
  240. .desc = "MPU ON + CORE ON",
  241. },
  242. {
  243. .enter = omap3_enter_idle_bm,
  244. .exit_latency = 10 + 10,
  245. .target_residency = 30,
  246. .name = "C2",
  247. .desc = "MPU ON + CORE ON",
  248. },
  249. {
  250. .enter = omap3_enter_idle_bm,
  251. .exit_latency = 50 + 50,
  252. .target_residency = 300,
  253. .name = "C3",
  254. .desc = "MPU RET + CORE ON",
  255. },
  256. {
  257. .enter = omap3_enter_idle_bm,
  258. .exit_latency = 1500 + 1800,
  259. .target_residency = 4000,
  260. .name = "C4",
  261. .desc = "MPU OFF + CORE ON",
  262. },
  263. {
  264. .enter = omap3_enter_idle_bm,
  265. .exit_latency = 2500 + 7500,
  266. .target_residency = 12000,
  267. .name = "C5",
  268. .desc = "MPU RET + CORE RET",
  269. },
  270. {
  271. .enter = omap3_enter_idle_bm,
  272. .exit_latency = 3000 + 8500,
  273. .target_residency = 15000,
  274. .name = "C6",
  275. .desc = "MPU OFF + CORE RET",
  276. },
  277. {
  278. .enter = omap3_enter_idle_bm,
  279. .exit_latency = 10000 + 30000,
  280. .target_residency = 30000,
  281. .name = "C7",
  282. .desc = "MPU OFF + CORE OFF",
  283. },
  284. },
  285. .state_count = ARRAY_SIZE(omap3_idle_data),
  286. .safe_state_index = 0,
  287. };
  288. /*
  289. * Numbers based on measurements made in October 2009 for PM optimized kernel
  290. * with CPU freq enabled on device Nokia N900. Assumes OPP2 (main idle OPP,
  291. * and worst case latencies).
  292. */
  293. static struct cpuidle_driver omap3430_idle_driver = {
  294. .name = "omap3430_idle",
  295. .owner = THIS_MODULE,
  296. .states = {
  297. {
  298. .enter = omap3_enter_idle_bm,
  299. .exit_latency = 110 + 162,
  300. .target_residency = 5,
  301. .name = "C1",
  302. .desc = "MPU ON + CORE ON",
  303. },
  304. {
  305. .enter = omap3_enter_idle_bm,
  306. .exit_latency = 106 + 180,
  307. .target_residency = 309,
  308. .name = "C2",
  309. .desc = "MPU ON + CORE ON",
  310. },
  311. {
  312. .enter = omap3_enter_idle_bm,
  313. .exit_latency = 107 + 410,
  314. .target_residency = 46057,
  315. .name = "C3",
  316. .desc = "MPU RET + CORE ON",
  317. },
  318. {
  319. .enter = omap3_enter_idle_bm,
  320. .exit_latency = 121 + 3374,
  321. .target_residency = 46057,
  322. .name = "C4",
  323. .desc = "MPU OFF + CORE ON",
  324. },
  325. {
  326. .enter = omap3_enter_idle_bm,
  327. .exit_latency = 855 + 1146,
  328. .target_residency = 46057,
  329. .name = "C5",
  330. .desc = "MPU RET + CORE RET",
  331. },
  332. {
  333. .enter = omap3_enter_idle_bm,
  334. .exit_latency = 7580 + 4134,
  335. .target_residency = 484329,
  336. .name = "C6",
  337. .desc = "MPU OFF + CORE RET",
  338. },
  339. {
  340. .enter = omap3_enter_idle_bm,
  341. .exit_latency = 7505 + 15274,
  342. .target_residency = 484329,
  343. .name = "C7",
  344. .desc = "MPU OFF + CORE OFF",
  345. },
  346. },
  347. .state_count = ARRAY_SIZE(omap3_idle_data),
  348. .safe_state_index = 0,
  349. };
  350. /* Public functions */
  351. /**
  352. * omap3_idle_init - Init routine for OMAP3 idle
  353. *
  354. * Registers the OMAP3 specific cpuidle driver to the cpuidle
  355. * framework with the valid set of states.
  356. */
  357. int __init omap3_idle_init(void)
  358. {
  359. mpu_pd = pwrdm_lookup("mpu_pwrdm");
  360. core_pd = pwrdm_lookup("core_pwrdm");
  361. per_pd = pwrdm_lookup("per_pwrdm");
  362. cam_pd = pwrdm_lookup("cam_pwrdm");
  363. if (!mpu_pd || !core_pd || !per_pd || !cam_pd)
  364. return -ENODEV;
  365. if (cpu_is_omap3430())
  366. return cpuidle_register(&omap3430_idle_driver, NULL);
  367. else
  368. return cpuidle_register(&omap3_idle_driver, NULL);
  369. }