pm34xx.c 21 KB

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