pm34xx.c 22 KB

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