pm34xx.c 22 KB

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