pm34xx.c 22 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810
  1. /*
  2. * OMAP3 Power Management Routines
  3. *
  4. * Copyright (C) 2006-2008 Nokia Corporation
  5. * Tony Lindgren <tony@atomide.com>
  6. * Jouni Hogander
  7. *
  8. * Copyright (C) 2007 Texas Instruments, Inc.
  9. * Rajendra Nayak <rnayak@ti.com>
  10. *
  11. * Copyright (C) 2005 Texas Instruments, Inc.
  12. * Richard Woodruff <r-woodruff2@ti.com>
  13. *
  14. * Based on pm.c for omap1
  15. *
  16. * This program is free software; you can redistribute it and/or modify
  17. * it under the terms of the GNU General Public License version 2 as
  18. * published by the Free Software Foundation.
  19. */
  20. #include <linux/pm.h>
  21. #include <linux/suspend.h>
  22. #include <linux/interrupt.h>
  23. #include <linux/module.h>
  24. #include <linux/list.h>
  25. #include <linux/err.h>
  26. #include <linux/gpio.h>
  27. #include <linux/clk.h>
  28. #include <linux/delay.h>
  29. #include <linux/slab.h>
  30. #include <trace/events/power.h>
  31. #include <asm/suspend.h>
  32. #include <asm/system_misc.h>
  33. #include <plat/sram.h>
  34. #include "clockdomain.h"
  35. #include "powerdomain.h"
  36. #include <plat/sdrc.h>
  37. #include <plat/prcm.h>
  38. #include <plat/gpmc.h>
  39. #include <plat/dma.h>
  40. #include "common.h"
  41. #include "cm2xxx_3xxx.h"
  42. #include "cm-regbits-34xx.h"
  43. #include "prm-regbits-34xx.h"
  44. #include "prm2xxx_3xxx.h"
  45. #include "pm.h"
  46. #include "sdrc.h"
  47. #include "control.h"
  48. /* pm34xx errata defined in pm.h */
  49. u16 pm34xx_errata;
  50. struct power_state {
  51. struct powerdomain *pwrdm;
  52. u32 next_state;
  53. #ifdef CONFIG_SUSPEND
  54. u32 saved_state;
  55. #endif
  56. struct list_head node;
  57. };
  58. static LIST_HEAD(pwrst_list);
  59. static int (*_omap_save_secure_sram)(u32 *addr);
  60. void (*omap3_do_wfi_sram)(void);
  61. static struct powerdomain *mpu_pwrdm, *neon_pwrdm;
  62. static struct powerdomain *core_pwrdm, *per_pwrdm;
  63. static struct powerdomain *cam_pwrdm;
  64. static void omap3_enable_io_chain(void)
  65. {
  66. int timeout = 0;
  67. omap2_prm_set_mod_reg_bits(OMAP3430_EN_IO_CHAIN_MASK, WKUP_MOD,
  68. PM_WKEN);
  69. /* Do a readback to assure write has been done */
  70. omap2_prm_read_mod_reg(WKUP_MOD, PM_WKEN);
  71. while (!(omap2_prm_read_mod_reg(WKUP_MOD, PM_WKEN) &
  72. OMAP3430_ST_IO_CHAIN_MASK)) {
  73. timeout++;
  74. if (timeout > 1000) {
  75. pr_err("Wake up daisy chain activation failed.\n");
  76. return;
  77. }
  78. omap2_prm_set_mod_reg_bits(OMAP3430_ST_IO_CHAIN_MASK,
  79. WKUP_MOD, PM_WKEN);
  80. }
  81. }
  82. static void omap3_disable_io_chain(void)
  83. {
  84. omap2_prm_clear_mod_reg_bits(OMAP3430_EN_IO_CHAIN_MASK, WKUP_MOD,
  85. PM_WKEN);
  86. }
  87. static void omap3_core_save_context(void)
  88. {
  89. omap3_ctrl_save_padconf();
  90. /*
  91. * Force write last pad into memory, as this can fail in some
  92. * cases according to errata 1.157, 1.185
  93. */
  94. omap_ctrl_writel(omap_ctrl_readl(OMAP343X_PADCONF_ETK_D14),
  95. OMAP343X_CONTROL_MEM_WKUP + 0x2a0);
  96. /* Save the Interrupt controller context */
  97. omap_intc_save_context();
  98. /* Save the GPMC context */
  99. omap3_gpmc_save_context();
  100. /* Save the system control module context, padconf already save above*/
  101. omap3_control_save_context();
  102. omap_dma_global_context_save();
  103. }
  104. static void omap3_core_restore_context(void)
  105. {
  106. /* Restore the control module context, padconf restored by h/w */
  107. omap3_control_restore_context();
  108. /* Restore the GPMC context */
  109. omap3_gpmc_restore_context();
  110. /* Restore the interrupt controller context */
  111. omap_intc_restore_context();
  112. omap_dma_global_context_restore();
  113. }
  114. /*
  115. * FIXME: This function should be called before entering off-mode after
  116. * OMAP3 secure services have been accessed. Currently it is only called
  117. * once during boot sequence, but this works as we are not using secure
  118. * services.
  119. */
  120. static void omap3_save_secure_ram_context(void)
  121. {
  122. u32 ret;
  123. int mpu_next_state = pwrdm_read_next_pwrst(mpu_pwrdm);
  124. if (omap_type() != OMAP2_DEVICE_TYPE_GP) {
  125. /*
  126. * MPU next state must be set to POWER_ON temporarily,
  127. * otherwise the WFI executed inside the ROM code
  128. * will hang the system.
  129. */
  130. pwrdm_set_next_pwrst(mpu_pwrdm, PWRDM_POWER_ON);
  131. ret = _omap_save_secure_sram((u32 *)
  132. __pa(omap3_secure_ram_storage));
  133. pwrdm_set_next_pwrst(mpu_pwrdm, mpu_next_state);
  134. /* Following is for error tracking, it should not happen */
  135. if (ret) {
  136. printk(KERN_ERR "save_secure_sram() returns %08x\n",
  137. ret);
  138. while (1)
  139. ;
  140. }
  141. }
  142. }
  143. /*
  144. * PRCM Interrupt Handler Helper Function
  145. *
  146. * The purpose of this function is to clear any wake-up events latched
  147. * in the PRCM PM_WKST_x registers. It is possible that a wake-up event
  148. * may occur whilst attempting to clear a PM_WKST_x register and thus
  149. * set another bit in this register. A while loop is used to ensure
  150. * that any peripheral wake-up events occurring while attempting to
  151. * clear the PM_WKST_x are detected and cleared.
  152. */
  153. static int prcm_clear_mod_irqs(s16 module, u8 regs, u32 ignore_bits)
  154. {
  155. u32 wkst, fclk, iclk, clken;
  156. u16 wkst_off = (regs == 3) ? OMAP3430ES2_PM_WKST3 : PM_WKST1;
  157. u16 fclk_off = (regs == 3) ? OMAP3430ES2_CM_FCLKEN3 : CM_FCLKEN1;
  158. u16 iclk_off = (regs == 3) ? CM_ICLKEN3 : CM_ICLKEN1;
  159. u16 grpsel_off = (regs == 3) ?
  160. OMAP3430ES2_PM_MPUGRPSEL3 : OMAP3430_PM_MPUGRPSEL;
  161. int c = 0;
  162. wkst = omap2_prm_read_mod_reg(module, wkst_off);
  163. wkst &= omap2_prm_read_mod_reg(module, grpsel_off);
  164. wkst &= ~ignore_bits;
  165. if (wkst) {
  166. iclk = omap2_cm_read_mod_reg(module, iclk_off);
  167. fclk = omap2_cm_read_mod_reg(module, fclk_off);
  168. while (wkst) {
  169. clken = wkst;
  170. omap2_cm_set_mod_reg_bits(clken, module, iclk_off);
  171. /*
  172. * For USBHOST, we don't know whether HOST1 or
  173. * HOST2 woke us up, so enable both f-clocks
  174. */
  175. if (module == OMAP3430ES2_USBHOST_MOD)
  176. clken |= 1 << OMAP3430ES2_EN_USBHOST2_SHIFT;
  177. omap2_cm_set_mod_reg_bits(clken, module, fclk_off);
  178. omap2_prm_write_mod_reg(wkst, module, wkst_off);
  179. wkst = omap2_prm_read_mod_reg(module, wkst_off);
  180. wkst &= ~ignore_bits;
  181. c++;
  182. }
  183. omap2_cm_write_mod_reg(iclk, module, iclk_off);
  184. omap2_cm_write_mod_reg(fclk, module, fclk_off);
  185. }
  186. return c;
  187. }
  188. static irqreturn_t _prcm_int_handle_io(int irq, void *unused)
  189. {
  190. int c;
  191. c = prcm_clear_mod_irqs(WKUP_MOD, 1,
  192. ~(OMAP3430_ST_IO_MASK | OMAP3430_ST_IO_CHAIN_MASK));
  193. return c ? IRQ_HANDLED : IRQ_NONE;
  194. }
  195. static irqreturn_t _prcm_int_handle_wakeup(int irq, void *unused)
  196. {
  197. int c;
  198. /*
  199. * Clear all except ST_IO and ST_IO_CHAIN for wkup module,
  200. * these are handled in a separate handler to avoid acking
  201. * IO events before parsing in mux code
  202. */
  203. c = prcm_clear_mod_irqs(WKUP_MOD, 1,
  204. OMAP3430_ST_IO_MASK | OMAP3430_ST_IO_CHAIN_MASK);
  205. c += prcm_clear_mod_irqs(CORE_MOD, 1, 0);
  206. c += prcm_clear_mod_irqs(OMAP3430_PER_MOD, 1, 0);
  207. if (omap_rev() > OMAP3430_REV_ES1_0) {
  208. c += prcm_clear_mod_irqs(CORE_MOD, 3, 0);
  209. c += prcm_clear_mod_irqs(OMAP3430ES2_USBHOST_MOD, 1, 0);
  210. }
  211. return c ? IRQ_HANDLED : IRQ_NONE;
  212. }
  213. static void omap34xx_save_context(u32 *save)
  214. {
  215. u32 val;
  216. /* Read Auxiliary Control Register */
  217. asm("mrc p15, 0, %0, c1, c0, 1" : "=r" (val));
  218. *save++ = 1;
  219. *save++ = val;
  220. /* Read L2 AUX ctrl register */
  221. asm("mrc p15, 1, %0, c9, c0, 2" : "=r" (val));
  222. *save++ = 1;
  223. *save++ = val;
  224. }
  225. static int omap34xx_do_sram_idle(unsigned long save_state)
  226. {
  227. omap34xx_cpu_suspend(save_state);
  228. return 0;
  229. }
  230. void omap_sram_idle(void)
  231. {
  232. /* Variable to tell what needs to be saved and restored
  233. * in omap_sram_idle*/
  234. /* save_state = 0 => Nothing to save and restored */
  235. /* save_state = 1 => Only L1 and logic lost */
  236. /* save_state = 2 => Only L2 lost */
  237. /* save_state = 3 => L1, L2 and logic lost */
  238. int save_state = 0;
  239. int mpu_next_state = PWRDM_POWER_ON;
  240. int per_next_state = PWRDM_POWER_ON;
  241. int core_next_state = PWRDM_POWER_ON;
  242. int per_going_off;
  243. int core_prev_state, per_prev_state;
  244. u32 sdrc_pwr = 0;
  245. mpu_next_state = pwrdm_read_next_pwrst(mpu_pwrdm);
  246. switch (mpu_next_state) {
  247. case PWRDM_POWER_ON:
  248. case PWRDM_POWER_RET:
  249. /* No need to save context */
  250. save_state = 0;
  251. break;
  252. case PWRDM_POWER_OFF:
  253. save_state = 3;
  254. break;
  255. default:
  256. /* Invalid state */
  257. printk(KERN_ERR "Invalid mpu state in sram_idle\n");
  258. return;
  259. }
  260. /* NEON control */
  261. if (pwrdm_read_pwrst(neon_pwrdm) == PWRDM_POWER_ON)
  262. pwrdm_set_next_pwrst(neon_pwrdm, mpu_next_state);
  263. /* Enable IO-PAD and IO-CHAIN wakeups */
  264. per_next_state = pwrdm_read_next_pwrst(per_pwrdm);
  265. core_next_state = pwrdm_read_next_pwrst(core_pwrdm);
  266. if (omap3_has_io_wakeup() &&
  267. (per_next_state < PWRDM_POWER_ON ||
  268. core_next_state < PWRDM_POWER_ON)) {
  269. omap2_prm_set_mod_reg_bits(OMAP3430_EN_IO_MASK, WKUP_MOD, PM_WKEN);
  270. if (omap3_has_io_chain_ctrl())
  271. omap3_enable_io_chain();
  272. }
  273. pwrdm_pre_transition();
  274. /* PER */
  275. if (per_next_state < PWRDM_POWER_ON) {
  276. per_going_off = (per_next_state == PWRDM_POWER_OFF) ? 1 : 0;
  277. omap2_gpio_prepare_for_idle(per_going_off);
  278. }
  279. /* CORE */
  280. if (core_next_state < PWRDM_POWER_ON) {
  281. if (core_next_state == PWRDM_POWER_OFF) {
  282. omap3_core_save_context();
  283. omap3_cm_save_context();
  284. }
  285. }
  286. omap3_intc_prepare_idle();
  287. /*
  288. * On EMU/HS devices ROM code restores a SRDC value
  289. * from scratchpad which has automatic self refresh on timeout
  290. * of AUTO_CNT = 1 enabled. This takes care of erratum ID i443.
  291. * Hence store/restore the SDRC_POWER register here.
  292. */
  293. if (cpu_is_omap3430() && omap_rev() >= OMAP3430_REV_ES3_0 &&
  294. (omap_type() == OMAP2_DEVICE_TYPE_EMU ||
  295. omap_type() == OMAP2_DEVICE_TYPE_SEC) &&
  296. core_next_state == PWRDM_POWER_OFF)
  297. sdrc_pwr = sdrc_read_reg(SDRC_POWER);
  298. /*
  299. * omap3_arm_context is the location where some ARM context
  300. * get saved. The rest is placed on the stack, and restored
  301. * from there before resuming.
  302. */
  303. if (save_state)
  304. omap34xx_save_context(omap3_arm_context);
  305. if (save_state == 1 || save_state == 3)
  306. cpu_suspend(save_state, omap34xx_do_sram_idle);
  307. else
  308. omap34xx_do_sram_idle(save_state);
  309. /* Restore normal SDRC POWER settings */
  310. if (cpu_is_omap3430() && omap_rev() >= OMAP3430_REV_ES3_0 &&
  311. (omap_type() == OMAP2_DEVICE_TYPE_EMU ||
  312. omap_type() == OMAP2_DEVICE_TYPE_SEC) &&
  313. core_next_state == PWRDM_POWER_OFF)
  314. sdrc_write_reg(sdrc_pwr, SDRC_POWER);
  315. /* CORE */
  316. if (core_next_state < PWRDM_POWER_ON) {
  317. core_prev_state = pwrdm_read_prev_pwrst(core_pwrdm);
  318. if (core_prev_state == PWRDM_POWER_OFF) {
  319. omap3_core_restore_context();
  320. omap3_cm_restore_context();
  321. omap3_sram_restore_context();
  322. omap2_sms_restore_context();
  323. }
  324. if (core_next_state == PWRDM_POWER_OFF)
  325. omap2_prm_clear_mod_reg_bits(OMAP3430_AUTO_OFF_MASK,
  326. OMAP3430_GR_MOD,
  327. OMAP3_PRM_VOLTCTRL_OFFSET);
  328. }
  329. omap3_intc_resume_idle();
  330. pwrdm_post_transition();
  331. /* PER */
  332. if (per_next_state < PWRDM_POWER_ON) {
  333. per_prev_state = pwrdm_read_prev_pwrst(per_pwrdm);
  334. omap2_gpio_resume_after_idle();
  335. }
  336. /* Disable IO-PAD and IO-CHAIN wakeup */
  337. if (omap3_has_io_wakeup() &&
  338. (per_next_state < PWRDM_POWER_ON ||
  339. core_next_state < PWRDM_POWER_ON)) {
  340. omap2_prm_clear_mod_reg_bits(OMAP3430_EN_IO_MASK, WKUP_MOD,
  341. PM_WKEN);
  342. if (omap3_has_io_chain_ctrl())
  343. omap3_disable_io_chain();
  344. }
  345. clkdm_allow_idle(mpu_pwrdm->pwrdm_clkdms[0]);
  346. }
  347. static void omap3_pm_idle(void)
  348. {
  349. local_fiq_disable();
  350. if (omap_irq_pending())
  351. goto out;
  352. trace_power_start(POWER_CSTATE, 1, smp_processor_id());
  353. trace_cpu_idle(1, smp_processor_id());
  354. omap_sram_idle();
  355. trace_power_end(smp_processor_id());
  356. trace_cpu_idle(PWR_EVENT_EXIT, smp_processor_id());
  357. out:
  358. local_fiq_enable();
  359. }
  360. #ifdef CONFIG_SUSPEND
  361. static int omap3_pm_suspend(void)
  362. {
  363. struct power_state *pwrst;
  364. int state, ret = 0;
  365. /* Read current next_pwrsts */
  366. list_for_each_entry(pwrst, &pwrst_list, node)
  367. pwrst->saved_state = pwrdm_read_next_pwrst(pwrst->pwrdm);
  368. /* Set ones wanted by suspend */
  369. list_for_each_entry(pwrst, &pwrst_list, node) {
  370. if (omap_set_pwrdm_state(pwrst->pwrdm, pwrst->next_state))
  371. goto restore;
  372. if (pwrdm_clear_all_prev_pwrst(pwrst->pwrdm))
  373. goto restore;
  374. }
  375. omap3_intc_suspend();
  376. omap_sram_idle();
  377. restore:
  378. /* Restore next_pwrsts */
  379. list_for_each_entry(pwrst, &pwrst_list, node) {
  380. state = pwrdm_read_prev_pwrst(pwrst->pwrdm);
  381. if (state > pwrst->next_state) {
  382. printk(KERN_INFO "Powerdomain (%s) didn't enter "
  383. "target state %d\n",
  384. pwrst->pwrdm->name, pwrst->next_state);
  385. ret = -1;
  386. }
  387. omap_set_pwrdm_state(pwrst->pwrdm, pwrst->saved_state);
  388. }
  389. if (ret)
  390. printk(KERN_ERR "Could not enter target state in pm_suspend\n");
  391. else
  392. printk(KERN_INFO "Successfully put all powerdomains "
  393. "to target state\n");
  394. return ret;
  395. }
  396. #endif /* CONFIG_SUSPEND */
  397. /**
  398. * omap3_iva_idle(): ensure IVA is in idle so it can be put into
  399. * retention
  400. *
  401. * In cases where IVA2 is activated by bootcode, it may prevent
  402. * full-chip retention or off-mode because it is not idle. This
  403. * function forces the IVA2 into idle state so it can go
  404. * into retention/off and thus allow full-chip retention/off.
  405. *
  406. **/
  407. static void __init omap3_iva_idle(void)
  408. {
  409. /* ensure IVA2 clock is disabled */
  410. omap2_cm_write_mod_reg(0, OMAP3430_IVA2_MOD, CM_FCLKEN);
  411. /* if no clock activity, nothing else to do */
  412. if (!(omap2_cm_read_mod_reg(OMAP3430_IVA2_MOD, OMAP3430_CM_CLKSTST) &
  413. OMAP3430_CLKACTIVITY_IVA2_MASK))
  414. return;
  415. /* Reset IVA2 */
  416. omap2_prm_write_mod_reg(OMAP3430_RST1_IVA2_MASK |
  417. OMAP3430_RST2_IVA2_MASK |
  418. OMAP3430_RST3_IVA2_MASK,
  419. OMAP3430_IVA2_MOD, OMAP2_RM_RSTCTRL);
  420. /* Enable IVA2 clock */
  421. omap2_cm_write_mod_reg(OMAP3430_CM_FCLKEN_IVA2_EN_IVA2_MASK,
  422. OMAP3430_IVA2_MOD, CM_FCLKEN);
  423. /* Set IVA2 boot mode to 'idle' */
  424. omap_ctrl_writel(OMAP3_IVA2_BOOTMOD_IDLE,
  425. OMAP343X_CONTROL_IVA2_BOOTMOD);
  426. /* Un-reset IVA2 */
  427. omap2_prm_write_mod_reg(0, OMAP3430_IVA2_MOD, OMAP2_RM_RSTCTRL);
  428. /* Disable IVA2 clock */
  429. omap2_cm_write_mod_reg(0, OMAP3430_IVA2_MOD, CM_FCLKEN);
  430. /* Reset IVA2 */
  431. omap2_prm_write_mod_reg(OMAP3430_RST1_IVA2_MASK |
  432. OMAP3430_RST2_IVA2_MASK |
  433. OMAP3430_RST3_IVA2_MASK,
  434. OMAP3430_IVA2_MOD, OMAP2_RM_RSTCTRL);
  435. }
  436. static void __init omap3_d2d_idle(void)
  437. {
  438. u16 mask, padconf;
  439. /* In a stand alone OMAP3430 where there is not a stacked
  440. * modem for the D2D Idle Ack and D2D MStandby must be pulled
  441. * high. S CONTROL_PADCONF_SAD2D_IDLEACK and
  442. * CONTROL_PADCONF_SAD2D_MSTDBY to have a pull up. */
  443. mask = (1 << 4) | (1 << 3); /* pull-up, enabled */
  444. padconf = omap_ctrl_readw(OMAP3_PADCONF_SAD2D_MSTANDBY);
  445. padconf |= mask;
  446. omap_ctrl_writew(padconf, OMAP3_PADCONF_SAD2D_MSTANDBY);
  447. padconf = omap_ctrl_readw(OMAP3_PADCONF_SAD2D_IDLEACK);
  448. padconf |= mask;
  449. omap_ctrl_writew(padconf, OMAP3_PADCONF_SAD2D_IDLEACK);
  450. /* reset modem */
  451. omap2_prm_write_mod_reg(OMAP3430_RM_RSTCTRL_CORE_MODEM_SW_RSTPWRON_MASK |
  452. OMAP3430_RM_RSTCTRL_CORE_MODEM_SW_RST_MASK,
  453. CORE_MOD, OMAP2_RM_RSTCTRL);
  454. omap2_prm_write_mod_reg(0, CORE_MOD, OMAP2_RM_RSTCTRL);
  455. }
  456. static void __init prcm_setup_regs(void)
  457. {
  458. u32 omap3630_en_uart4_mask = cpu_is_omap3630() ?
  459. OMAP3630_EN_UART4_MASK : 0;
  460. u32 omap3630_grpsel_uart4_mask = cpu_is_omap3630() ?
  461. OMAP3630_GRPSEL_UART4_MASK : 0;
  462. /* XXX This should be handled by hwmod code or SCM init code */
  463. omap_ctrl_writel(OMAP3430_AUTOIDLE_MASK, OMAP2_CONTROL_SYSCONFIG);
  464. /*
  465. * Enable control of expternal oscillator through
  466. * sys_clkreq. In the long run clock framework should
  467. * take care of this.
  468. */
  469. omap2_prm_rmw_mod_reg_bits(OMAP_AUTOEXTCLKMODE_MASK,
  470. 1 << OMAP_AUTOEXTCLKMODE_SHIFT,
  471. OMAP3430_GR_MOD,
  472. OMAP3_PRM_CLKSRC_CTRL_OFFSET);
  473. /* setup wakup source */
  474. omap2_prm_write_mod_reg(OMAP3430_EN_IO_MASK | OMAP3430_EN_GPIO1_MASK |
  475. OMAP3430_EN_GPT1_MASK | OMAP3430_EN_GPT12_MASK,
  476. WKUP_MOD, PM_WKEN);
  477. /* No need to write EN_IO, that is always enabled */
  478. omap2_prm_write_mod_reg(OMAP3430_GRPSEL_GPIO1_MASK |
  479. OMAP3430_GRPSEL_GPT1_MASK |
  480. OMAP3430_GRPSEL_GPT12_MASK,
  481. WKUP_MOD, OMAP3430_PM_MPUGRPSEL);
  482. /* Enable PM_WKEN to support DSS LPR */
  483. omap2_prm_write_mod_reg(OMAP3430_PM_WKEN_DSS_EN_DSS_MASK,
  484. OMAP3430_DSS_MOD, PM_WKEN);
  485. /* Enable wakeups in PER */
  486. omap2_prm_write_mod_reg(omap3630_en_uart4_mask |
  487. OMAP3430_EN_GPIO2_MASK | OMAP3430_EN_GPIO3_MASK |
  488. OMAP3430_EN_GPIO4_MASK | OMAP3430_EN_GPIO5_MASK |
  489. OMAP3430_EN_GPIO6_MASK | OMAP3430_EN_UART3_MASK |
  490. OMAP3430_EN_MCBSP2_MASK | OMAP3430_EN_MCBSP3_MASK |
  491. OMAP3430_EN_MCBSP4_MASK,
  492. OMAP3430_PER_MOD, PM_WKEN);
  493. /* and allow them to wake up MPU */
  494. omap2_prm_write_mod_reg(omap3630_grpsel_uart4_mask |
  495. OMAP3430_GRPSEL_GPIO2_MASK |
  496. OMAP3430_GRPSEL_GPIO3_MASK |
  497. OMAP3430_GRPSEL_GPIO4_MASK |
  498. OMAP3430_GRPSEL_GPIO5_MASK |
  499. OMAP3430_GRPSEL_GPIO6_MASK |
  500. OMAP3430_GRPSEL_UART3_MASK |
  501. OMAP3430_GRPSEL_MCBSP2_MASK |
  502. OMAP3430_GRPSEL_MCBSP3_MASK |
  503. OMAP3430_GRPSEL_MCBSP4_MASK,
  504. OMAP3430_PER_MOD, OMAP3430_PM_MPUGRPSEL);
  505. /* Don't attach IVA interrupts */
  506. omap2_prm_write_mod_reg(0, WKUP_MOD, OMAP3430_PM_IVAGRPSEL);
  507. omap2_prm_write_mod_reg(0, CORE_MOD, OMAP3430_PM_IVAGRPSEL1);
  508. omap2_prm_write_mod_reg(0, CORE_MOD, OMAP3430ES2_PM_IVAGRPSEL3);
  509. omap2_prm_write_mod_reg(0, OMAP3430_PER_MOD, OMAP3430_PM_IVAGRPSEL);
  510. /* Clear any pending 'reset' flags */
  511. omap2_prm_write_mod_reg(0xffffffff, MPU_MOD, OMAP2_RM_RSTST);
  512. omap2_prm_write_mod_reg(0xffffffff, CORE_MOD, OMAP2_RM_RSTST);
  513. omap2_prm_write_mod_reg(0xffffffff, OMAP3430_PER_MOD, OMAP2_RM_RSTST);
  514. omap2_prm_write_mod_reg(0xffffffff, OMAP3430_EMU_MOD, OMAP2_RM_RSTST);
  515. omap2_prm_write_mod_reg(0xffffffff, OMAP3430_NEON_MOD, OMAP2_RM_RSTST);
  516. omap2_prm_write_mod_reg(0xffffffff, OMAP3430_DSS_MOD, OMAP2_RM_RSTST);
  517. omap2_prm_write_mod_reg(0xffffffff, OMAP3430ES2_USBHOST_MOD, OMAP2_RM_RSTST);
  518. /* Clear any pending PRCM interrupts */
  519. omap2_prm_write_mod_reg(0, OCP_MOD, OMAP3_PRM_IRQSTATUS_MPU_OFFSET);
  520. omap3_iva_idle();
  521. omap3_d2d_idle();
  522. }
  523. void omap3_pm_off_mode_enable(int enable)
  524. {
  525. struct power_state *pwrst;
  526. u32 state;
  527. if (enable)
  528. state = PWRDM_POWER_OFF;
  529. else
  530. state = PWRDM_POWER_RET;
  531. list_for_each_entry(pwrst, &pwrst_list, node) {
  532. if (IS_PM34XX_ERRATUM(PM_SDRC_WAKEUP_ERRATUM_i583) &&
  533. pwrst->pwrdm == core_pwrdm &&
  534. state == PWRDM_POWER_OFF) {
  535. pwrst->next_state = PWRDM_POWER_RET;
  536. pr_warn("%s: Core OFF disabled due to errata i583\n",
  537. __func__);
  538. } else {
  539. pwrst->next_state = state;
  540. }
  541. omap_set_pwrdm_state(pwrst->pwrdm, pwrst->next_state);
  542. }
  543. }
  544. int omap3_pm_get_suspend_state(struct powerdomain *pwrdm)
  545. {
  546. struct power_state *pwrst;
  547. list_for_each_entry(pwrst, &pwrst_list, node) {
  548. if (pwrst->pwrdm == pwrdm)
  549. return pwrst->next_state;
  550. }
  551. return -EINVAL;
  552. }
  553. int omap3_pm_set_suspend_state(struct powerdomain *pwrdm, int state)
  554. {
  555. struct power_state *pwrst;
  556. list_for_each_entry(pwrst, &pwrst_list, node) {
  557. if (pwrst->pwrdm == pwrdm) {
  558. pwrst->next_state = state;
  559. return 0;
  560. }
  561. }
  562. return -EINVAL;
  563. }
  564. static int __init pwrdms_setup(struct powerdomain *pwrdm, void *unused)
  565. {
  566. struct power_state *pwrst;
  567. if (!pwrdm->pwrsts)
  568. return 0;
  569. pwrst = kmalloc(sizeof(struct power_state), GFP_ATOMIC);
  570. if (!pwrst)
  571. return -ENOMEM;
  572. pwrst->pwrdm = pwrdm;
  573. pwrst->next_state = PWRDM_POWER_RET;
  574. list_add(&pwrst->node, &pwrst_list);
  575. if (pwrdm_has_hdwr_sar(pwrdm))
  576. pwrdm_enable_hdwr_sar(pwrdm);
  577. return omap_set_pwrdm_state(pwrst->pwrdm, pwrst->next_state);
  578. }
  579. /*
  580. * Push functions to SRAM
  581. *
  582. * The minimum set of functions is pushed to SRAM for execution:
  583. * - omap3_do_wfi for erratum i581 WA,
  584. * - save_secure_ram_context for security extensions.
  585. */
  586. void omap_push_sram_idle(void)
  587. {
  588. omap3_do_wfi_sram = omap_sram_push(omap3_do_wfi, omap3_do_wfi_sz);
  589. if (omap_type() != OMAP2_DEVICE_TYPE_GP)
  590. _omap_save_secure_sram = omap_sram_push(save_secure_ram_context,
  591. save_secure_ram_context_sz);
  592. }
  593. static void __init pm_errata_configure(void)
  594. {
  595. if (cpu_is_omap3630()) {
  596. pm34xx_errata |= PM_RTA_ERRATUM_i608;
  597. /* Enable the l2 cache toggling in sleep logic */
  598. enable_omap3630_toggle_l2_on_restore();
  599. if (omap_rev() < OMAP3630_REV_ES1_2)
  600. pm34xx_errata |= PM_SDRC_WAKEUP_ERRATUM_i583;
  601. }
  602. }
  603. static int __init omap3_pm_init(void)
  604. {
  605. struct power_state *pwrst, *tmp;
  606. struct clockdomain *neon_clkdm, *per_clkdm, *mpu_clkdm, *core_clkdm;
  607. int ret;
  608. if (!cpu_is_omap34xx())
  609. return -ENODEV;
  610. if (!omap3_has_io_chain_ctrl())
  611. pr_warning("PM: no software I/O chain control; some wakeups may be lost\n");
  612. pm_errata_configure();
  613. /* XXX prcm_setup_regs needs to be before enabling hw
  614. * supervised mode for powerdomains */
  615. prcm_setup_regs();
  616. ret = request_irq(omap_prcm_event_to_irq("wkup"),
  617. _prcm_int_handle_wakeup, IRQF_NO_SUSPEND, "pm_wkup", NULL);
  618. if (ret) {
  619. pr_err("pm: Failed to request pm_wkup irq\n");
  620. goto err1;
  621. }
  622. /* IO interrupt is shared with mux code */
  623. ret = request_irq(omap_prcm_event_to_irq("io"),
  624. _prcm_int_handle_io, IRQF_SHARED | IRQF_NO_SUSPEND, "pm_io",
  625. omap3_pm_init);
  626. if (ret) {
  627. pr_err("pm: Failed to request pm_io irq\n");
  628. goto err1;
  629. }
  630. ret = pwrdm_for_each(pwrdms_setup, NULL);
  631. if (ret) {
  632. printk(KERN_ERR "Failed to setup powerdomains\n");
  633. goto err2;
  634. }
  635. (void) clkdm_for_each(omap_pm_clkdms_setup, NULL);
  636. mpu_pwrdm = pwrdm_lookup("mpu_pwrdm");
  637. if (mpu_pwrdm == NULL) {
  638. printk(KERN_ERR "Failed to get mpu_pwrdm\n");
  639. goto err2;
  640. }
  641. neon_pwrdm = pwrdm_lookup("neon_pwrdm");
  642. per_pwrdm = pwrdm_lookup("per_pwrdm");
  643. core_pwrdm = pwrdm_lookup("core_pwrdm");
  644. cam_pwrdm = pwrdm_lookup("cam_pwrdm");
  645. neon_clkdm = clkdm_lookup("neon_clkdm");
  646. mpu_clkdm = clkdm_lookup("mpu_clkdm");
  647. per_clkdm = clkdm_lookup("per_clkdm");
  648. core_clkdm = clkdm_lookup("core_clkdm");
  649. #ifdef CONFIG_SUSPEND
  650. omap_pm_suspend = omap3_pm_suspend;
  651. #endif
  652. arm_pm_idle = omap3_pm_idle;
  653. omap3_idle_init();
  654. /*
  655. * RTA is disabled during initialization as per erratum i608
  656. * it is safer to disable RTA by the bootloader, but we would like
  657. * to be doubly sure here and prevent any mishaps.
  658. */
  659. if (IS_PM34XX_ERRATUM(PM_RTA_ERRATUM_i608))
  660. omap3630_ctrl_disable_rta();
  661. clkdm_add_wkdep(neon_clkdm, mpu_clkdm);
  662. if (omap_type() != OMAP2_DEVICE_TYPE_GP) {
  663. omap3_secure_ram_storage =
  664. kmalloc(0x803F, GFP_KERNEL);
  665. if (!omap3_secure_ram_storage)
  666. printk(KERN_ERR "Memory allocation failed when"
  667. "allocating for secure sram context\n");
  668. local_irq_disable();
  669. local_fiq_disable();
  670. omap_dma_global_context_save();
  671. omap3_save_secure_ram_context();
  672. omap_dma_global_context_restore();
  673. local_irq_enable();
  674. local_fiq_enable();
  675. }
  676. omap3_save_scratchpad_contents();
  677. err1:
  678. return ret;
  679. err2:
  680. free_irq(INT_34XX_PRCM_MPU_IRQ, NULL);
  681. list_for_each_entry_safe(pwrst, tmp, &pwrst_list, node) {
  682. list_del(&pwrst->node);
  683. kfree(pwrst);
  684. }
  685. return ret;
  686. }
  687. late_initcall(omap3_pm_init);