pm34xx.c 22 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786
  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/suspend.h>
  33. #include <asm/system_misc.h>
  34. #include "clockdomain.h"
  35. #include "powerdomain.h"
  36. #include <plat-omap/dma-omap.h>
  37. #include "../plat-omap/sram.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 "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. pwrdm_pre_transition(NULL);
  242. /* PER */
  243. if (per_next_state < PWRDM_POWER_ON) {
  244. per_going_off = (per_next_state == PWRDM_POWER_OFF) ? 1 : 0;
  245. omap2_gpio_prepare_for_idle(per_going_off);
  246. }
  247. /* CORE */
  248. if (core_next_state < PWRDM_POWER_ON) {
  249. if (core_next_state == PWRDM_POWER_OFF) {
  250. omap3_core_save_context();
  251. omap3_cm_save_context();
  252. }
  253. }
  254. omap3_intc_prepare_idle();
  255. /*
  256. * On EMU/HS devices ROM code restores a SRDC value
  257. * from scratchpad which has automatic self refresh on timeout
  258. * of AUTO_CNT = 1 enabled. This takes care of erratum ID i443.
  259. * Hence store/restore the SDRC_POWER register here.
  260. */
  261. if (cpu_is_omap3430() && omap_rev() >= OMAP3430_REV_ES3_0 &&
  262. (omap_type() == OMAP2_DEVICE_TYPE_EMU ||
  263. omap_type() == OMAP2_DEVICE_TYPE_SEC) &&
  264. core_next_state == PWRDM_POWER_OFF)
  265. sdrc_pwr = sdrc_read_reg(SDRC_POWER);
  266. /*
  267. * omap3_arm_context is the location where some ARM context
  268. * get saved. The rest is placed on the stack, and restored
  269. * from there before resuming.
  270. */
  271. if (save_state)
  272. omap34xx_save_context(omap3_arm_context);
  273. if (save_state == 1 || save_state == 3)
  274. cpu_suspend(save_state, omap34xx_do_sram_idle);
  275. else
  276. omap34xx_do_sram_idle(save_state);
  277. /* Restore normal SDRC POWER settings */
  278. if (cpu_is_omap3430() && omap_rev() >= OMAP3430_REV_ES3_0 &&
  279. (omap_type() == OMAP2_DEVICE_TYPE_EMU ||
  280. omap_type() == OMAP2_DEVICE_TYPE_SEC) &&
  281. core_next_state == PWRDM_POWER_OFF)
  282. sdrc_write_reg(sdrc_pwr, SDRC_POWER);
  283. /* CORE */
  284. if (core_next_state < PWRDM_POWER_ON) {
  285. core_prev_state = pwrdm_read_prev_pwrst(core_pwrdm);
  286. if (core_prev_state == PWRDM_POWER_OFF) {
  287. omap3_core_restore_context();
  288. omap3_cm_restore_context();
  289. omap3_sram_restore_context();
  290. omap2_sms_restore_context();
  291. }
  292. if (core_next_state == PWRDM_POWER_OFF)
  293. omap2_prm_clear_mod_reg_bits(OMAP3430_AUTO_OFF_MASK,
  294. OMAP3430_GR_MOD,
  295. OMAP3_PRM_VOLTCTRL_OFFSET);
  296. }
  297. omap3_intc_resume_idle();
  298. pwrdm_post_transition(NULL);
  299. /* PER */
  300. if (per_next_state < PWRDM_POWER_ON)
  301. omap2_gpio_resume_after_idle();
  302. }
  303. static void omap3_pm_idle(void)
  304. {
  305. local_fiq_disable();
  306. if (omap_irq_pending())
  307. goto out;
  308. trace_power_start(POWER_CSTATE, 1, smp_processor_id());
  309. trace_cpu_idle(1, smp_processor_id());
  310. omap_sram_idle();
  311. trace_power_end(smp_processor_id());
  312. trace_cpu_idle(PWR_EVENT_EXIT, smp_processor_id());
  313. out:
  314. local_fiq_enable();
  315. }
  316. #ifdef CONFIG_SUSPEND
  317. static int omap3_pm_suspend(void)
  318. {
  319. struct power_state *pwrst;
  320. int state, ret = 0;
  321. /* Read current next_pwrsts */
  322. list_for_each_entry(pwrst, &pwrst_list, node)
  323. pwrst->saved_state = pwrdm_read_next_pwrst(pwrst->pwrdm);
  324. /* Set ones wanted by suspend */
  325. list_for_each_entry(pwrst, &pwrst_list, node) {
  326. if (omap_set_pwrdm_state(pwrst->pwrdm, pwrst->next_state))
  327. goto restore;
  328. if (pwrdm_clear_all_prev_pwrst(pwrst->pwrdm))
  329. goto restore;
  330. }
  331. omap3_intc_suspend();
  332. omap_sram_idle();
  333. restore:
  334. /* Restore next_pwrsts */
  335. list_for_each_entry(pwrst, &pwrst_list, node) {
  336. state = pwrdm_read_prev_pwrst(pwrst->pwrdm);
  337. if (state > pwrst->next_state) {
  338. pr_info("Powerdomain (%s) didn't enter target state %d\n",
  339. pwrst->pwrdm->name, pwrst->next_state);
  340. ret = -1;
  341. }
  342. omap_set_pwrdm_state(pwrst->pwrdm, pwrst->saved_state);
  343. }
  344. if (ret)
  345. pr_err("Could not enter target state in pm_suspend\n");
  346. else
  347. pr_info("Successfully put all powerdomains to target state\n");
  348. return ret;
  349. }
  350. #endif /* CONFIG_SUSPEND */
  351. /**
  352. * omap3_iva_idle(): ensure IVA is in idle so it can be put into
  353. * retention
  354. *
  355. * In cases where IVA2 is activated by bootcode, it may prevent
  356. * full-chip retention or off-mode because it is not idle. This
  357. * function forces the IVA2 into idle state so it can go
  358. * into retention/off and thus allow full-chip retention/off.
  359. *
  360. **/
  361. static void __init omap3_iva_idle(void)
  362. {
  363. /* ensure IVA2 clock is disabled */
  364. omap2_cm_write_mod_reg(0, OMAP3430_IVA2_MOD, CM_FCLKEN);
  365. /* if no clock activity, nothing else to do */
  366. if (!(omap2_cm_read_mod_reg(OMAP3430_IVA2_MOD, OMAP3430_CM_CLKSTST) &
  367. OMAP3430_CLKACTIVITY_IVA2_MASK))
  368. return;
  369. /* Reset IVA2 */
  370. omap2_prm_write_mod_reg(OMAP3430_RST1_IVA2_MASK |
  371. OMAP3430_RST2_IVA2_MASK |
  372. OMAP3430_RST3_IVA2_MASK,
  373. OMAP3430_IVA2_MOD, OMAP2_RM_RSTCTRL);
  374. /* Enable IVA2 clock */
  375. omap2_cm_write_mod_reg(OMAP3430_CM_FCLKEN_IVA2_EN_IVA2_MASK,
  376. OMAP3430_IVA2_MOD, CM_FCLKEN);
  377. /* Set IVA2 boot mode to 'idle' */
  378. omap_ctrl_writel(OMAP3_IVA2_BOOTMOD_IDLE,
  379. OMAP343X_CONTROL_IVA2_BOOTMOD);
  380. /* Un-reset IVA2 */
  381. omap2_prm_write_mod_reg(0, OMAP3430_IVA2_MOD, OMAP2_RM_RSTCTRL);
  382. /* Disable IVA2 clock */
  383. omap2_cm_write_mod_reg(0, OMAP3430_IVA2_MOD, CM_FCLKEN);
  384. /* Reset IVA2 */
  385. omap2_prm_write_mod_reg(OMAP3430_RST1_IVA2_MASK |
  386. OMAP3430_RST2_IVA2_MASK |
  387. OMAP3430_RST3_IVA2_MASK,
  388. OMAP3430_IVA2_MOD, OMAP2_RM_RSTCTRL);
  389. }
  390. static void __init omap3_d2d_idle(void)
  391. {
  392. u16 mask, padconf;
  393. /* In a stand alone OMAP3430 where there is not a stacked
  394. * modem for the D2D Idle Ack and D2D MStandby must be pulled
  395. * high. S CONTROL_PADCONF_SAD2D_IDLEACK and
  396. * CONTROL_PADCONF_SAD2D_MSTDBY to have a pull up. */
  397. mask = (1 << 4) | (1 << 3); /* pull-up, enabled */
  398. padconf = omap_ctrl_readw(OMAP3_PADCONF_SAD2D_MSTANDBY);
  399. padconf |= mask;
  400. omap_ctrl_writew(padconf, OMAP3_PADCONF_SAD2D_MSTANDBY);
  401. padconf = omap_ctrl_readw(OMAP3_PADCONF_SAD2D_IDLEACK);
  402. padconf |= mask;
  403. omap_ctrl_writew(padconf, OMAP3_PADCONF_SAD2D_IDLEACK);
  404. /* reset modem */
  405. omap2_prm_write_mod_reg(OMAP3430_RM_RSTCTRL_CORE_MODEM_SW_RSTPWRON_MASK |
  406. OMAP3430_RM_RSTCTRL_CORE_MODEM_SW_RST_MASK,
  407. CORE_MOD, OMAP2_RM_RSTCTRL);
  408. omap2_prm_write_mod_reg(0, CORE_MOD, OMAP2_RM_RSTCTRL);
  409. }
  410. static void __init prcm_setup_regs(void)
  411. {
  412. u32 omap3630_en_uart4_mask = cpu_is_omap3630() ?
  413. OMAP3630_EN_UART4_MASK : 0;
  414. u32 omap3630_grpsel_uart4_mask = cpu_is_omap3630() ?
  415. OMAP3630_GRPSEL_UART4_MASK : 0;
  416. /* XXX This should be handled by hwmod code or SCM init code */
  417. omap_ctrl_writel(OMAP3430_AUTOIDLE_MASK, OMAP2_CONTROL_SYSCONFIG);
  418. /*
  419. * Enable control of expternal oscillator through
  420. * sys_clkreq. In the long run clock framework should
  421. * take care of this.
  422. */
  423. omap2_prm_rmw_mod_reg_bits(OMAP_AUTOEXTCLKMODE_MASK,
  424. 1 << OMAP_AUTOEXTCLKMODE_SHIFT,
  425. OMAP3430_GR_MOD,
  426. OMAP3_PRM_CLKSRC_CTRL_OFFSET);
  427. /* setup wakup source */
  428. omap2_prm_write_mod_reg(OMAP3430_EN_IO_MASK | OMAP3430_EN_GPIO1_MASK |
  429. OMAP3430_EN_GPT1_MASK | OMAP3430_EN_GPT12_MASK,
  430. WKUP_MOD, PM_WKEN);
  431. /* No need to write EN_IO, that is always enabled */
  432. omap2_prm_write_mod_reg(OMAP3430_GRPSEL_GPIO1_MASK |
  433. OMAP3430_GRPSEL_GPT1_MASK |
  434. OMAP3430_GRPSEL_GPT12_MASK,
  435. WKUP_MOD, OMAP3430_PM_MPUGRPSEL);
  436. /* Enable PM_WKEN to support DSS LPR */
  437. omap2_prm_write_mod_reg(OMAP3430_PM_WKEN_DSS_EN_DSS_MASK,
  438. OMAP3430_DSS_MOD, PM_WKEN);
  439. /* Enable wakeups in PER */
  440. omap2_prm_write_mod_reg(omap3630_en_uart4_mask |
  441. OMAP3430_EN_GPIO2_MASK | OMAP3430_EN_GPIO3_MASK |
  442. OMAP3430_EN_GPIO4_MASK | OMAP3430_EN_GPIO5_MASK |
  443. OMAP3430_EN_GPIO6_MASK | OMAP3430_EN_UART3_MASK |
  444. OMAP3430_EN_MCBSP2_MASK | OMAP3430_EN_MCBSP3_MASK |
  445. OMAP3430_EN_MCBSP4_MASK,
  446. OMAP3430_PER_MOD, PM_WKEN);
  447. /* and allow them to wake up MPU */
  448. omap2_prm_write_mod_reg(omap3630_grpsel_uart4_mask |
  449. OMAP3430_GRPSEL_GPIO2_MASK |
  450. OMAP3430_GRPSEL_GPIO3_MASK |
  451. OMAP3430_GRPSEL_GPIO4_MASK |
  452. OMAP3430_GRPSEL_GPIO5_MASK |
  453. OMAP3430_GRPSEL_GPIO6_MASK |
  454. OMAP3430_GRPSEL_UART3_MASK |
  455. OMAP3430_GRPSEL_MCBSP2_MASK |
  456. OMAP3430_GRPSEL_MCBSP3_MASK |
  457. OMAP3430_GRPSEL_MCBSP4_MASK,
  458. OMAP3430_PER_MOD, OMAP3430_PM_MPUGRPSEL);
  459. /* Don't attach IVA interrupts */
  460. if (omap3_has_iva()) {
  461. omap2_prm_write_mod_reg(0, WKUP_MOD, OMAP3430_PM_IVAGRPSEL);
  462. omap2_prm_write_mod_reg(0, CORE_MOD, OMAP3430_PM_IVAGRPSEL1);
  463. omap2_prm_write_mod_reg(0, CORE_MOD, OMAP3430ES2_PM_IVAGRPSEL3);
  464. omap2_prm_write_mod_reg(0, OMAP3430_PER_MOD,
  465. OMAP3430_PM_IVAGRPSEL);
  466. }
  467. /* Clear any pending 'reset' flags */
  468. omap2_prm_write_mod_reg(0xffffffff, MPU_MOD, OMAP2_RM_RSTST);
  469. omap2_prm_write_mod_reg(0xffffffff, CORE_MOD, OMAP2_RM_RSTST);
  470. omap2_prm_write_mod_reg(0xffffffff, OMAP3430_PER_MOD, OMAP2_RM_RSTST);
  471. omap2_prm_write_mod_reg(0xffffffff, OMAP3430_EMU_MOD, OMAP2_RM_RSTST);
  472. omap2_prm_write_mod_reg(0xffffffff, OMAP3430_NEON_MOD, OMAP2_RM_RSTST);
  473. omap2_prm_write_mod_reg(0xffffffff, OMAP3430_DSS_MOD, OMAP2_RM_RSTST);
  474. omap2_prm_write_mod_reg(0xffffffff, OMAP3430ES2_USBHOST_MOD, OMAP2_RM_RSTST);
  475. /* Clear any pending PRCM interrupts */
  476. omap2_prm_write_mod_reg(0, OCP_MOD, OMAP3_PRM_IRQSTATUS_MPU_OFFSET);
  477. if (omap3_has_iva())
  478. omap3_iva_idle();
  479. omap3_d2d_idle();
  480. }
  481. void omap3_pm_off_mode_enable(int enable)
  482. {
  483. struct power_state *pwrst;
  484. u32 state;
  485. if (enable)
  486. state = PWRDM_POWER_OFF;
  487. else
  488. state = PWRDM_POWER_RET;
  489. list_for_each_entry(pwrst, &pwrst_list, node) {
  490. if (IS_PM34XX_ERRATUM(PM_SDRC_WAKEUP_ERRATUM_i583) &&
  491. pwrst->pwrdm == core_pwrdm &&
  492. state == PWRDM_POWER_OFF) {
  493. pwrst->next_state = PWRDM_POWER_RET;
  494. pr_warn("%s: Core OFF disabled due to errata i583\n",
  495. __func__);
  496. } else {
  497. pwrst->next_state = state;
  498. }
  499. omap_set_pwrdm_state(pwrst->pwrdm, pwrst->next_state);
  500. }
  501. }
  502. int omap3_pm_get_suspend_state(struct powerdomain *pwrdm)
  503. {
  504. struct power_state *pwrst;
  505. list_for_each_entry(pwrst, &pwrst_list, node) {
  506. if (pwrst->pwrdm == pwrdm)
  507. return pwrst->next_state;
  508. }
  509. return -EINVAL;
  510. }
  511. int omap3_pm_set_suspend_state(struct powerdomain *pwrdm, int state)
  512. {
  513. struct power_state *pwrst;
  514. list_for_each_entry(pwrst, &pwrst_list, node) {
  515. if (pwrst->pwrdm == pwrdm) {
  516. pwrst->next_state = state;
  517. return 0;
  518. }
  519. }
  520. return -EINVAL;
  521. }
  522. static int __init pwrdms_setup(struct powerdomain *pwrdm, void *unused)
  523. {
  524. struct power_state *pwrst;
  525. if (!pwrdm->pwrsts)
  526. return 0;
  527. pwrst = kmalloc(sizeof(struct power_state), GFP_ATOMIC);
  528. if (!pwrst)
  529. return -ENOMEM;
  530. pwrst->pwrdm = pwrdm;
  531. pwrst->next_state = PWRDM_POWER_RET;
  532. list_add(&pwrst->node, &pwrst_list);
  533. if (pwrdm_has_hdwr_sar(pwrdm))
  534. pwrdm_enable_hdwr_sar(pwrdm);
  535. return omap_set_pwrdm_state(pwrst->pwrdm, pwrst->next_state);
  536. }
  537. /*
  538. * Push functions to SRAM
  539. *
  540. * The minimum set of functions is pushed to SRAM for execution:
  541. * - omap3_do_wfi for erratum i581 WA,
  542. * - save_secure_ram_context for security extensions.
  543. */
  544. void omap_push_sram_idle(void)
  545. {
  546. omap3_do_wfi_sram = omap_sram_push(omap3_do_wfi, omap3_do_wfi_sz);
  547. if (omap_type() != OMAP2_DEVICE_TYPE_GP)
  548. _omap_save_secure_sram = omap_sram_push(save_secure_ram_context,
  549. save_secure_ram_context_sz);
  550. }
  551. static void __init pm_errata_configure(void)
  552. {
  553. if (cpu_is_omap3630()) {
  554. pm34xx_errata |= PM_RTA_ERRATUM_i608;
  555. /* Enable the l2 cache toggling in sleep logic */
  556. enable_omap3630_toggle_l2_on_restore();
  557. if (omap_rev() < OMAP3630_REV_ES1_2)
  558. pm34xx_errata |= (PM_SDRC_WAKEUP_ERRATUM_i583 |
  559. PM_PER_MEMORIES_ERRATUM_i582);
  560. } else if (cpu_is_omap34xx()) {
  561. pm34xx_errata |= PM_PER_MEMORIES_ERRATUM_i582;
  562. }
  563. }
  564. int __init omap3_pm_init(void)
  565. {
  566. struct power_state *pwrst, *tmp;
  567. struct clockdomain *neon_clkdm, *mpu_clkdm, *per_clkdm, *wkup_clkdm;
  568. int ret;
  569. if (!omap3_has_io_chain_ctrl())
  570. pr_warning("PM: no software I/O chain control; some wakeups may be lost\n");
  571. pm_errata_configure();
  572. /* XXX prcm_setup_regs needs to be before enabling hw
  573. * supervised mode for powerdomains */
  574. prcm_setup_regs();
  575. ret = request_irq(omap_prcm_event_to_irq("wkup"),
  576. _prcm_int_handle_wakeup, IRQF_NO_SUSPEND, "pm_wkup", NULL);
  577. if (ret) {
  578. pr_err("pm: Failed to request pm_wkup irq\n");
  579. goto err1;
  580. }
  581. /* IO interrupt is shared with mux code */
  582. ret = request_irq(omap_prcm_event_to_irq("io"),
  583. _prcm_int_handle_io, IRQF_SHARED | IRQF_NO_SUSPEND, "pm_io",
  584. omap3_pm_init);
  585. enable_irq(omap_prcm_event_to_irq("io"));
  586. if (ret) {
  587. pr_err("pm: Failed to request pm_io irq\n");
  588. goto err2;
  589. }
  590. ret = pwrdm_for_each(pwrdms_setup, NULL);
  591. if (ret) {
  592. pr_err("Failed to setup powerdomains\n");
  593. goto err3;
  594. }
  595. (void) clkdm_for_each(omap_pm_clkdms_setup, NULL);
  596. mpu_pwrdm = pwrdm_lookup("mpu_pwrdm");
  597. if (mpu_pwrdm == NULL) {
  598. pr_err("Failed to get mpu_pwrdm\n");
  599. ret = -EINVAL;
  600. goto err3;
  601. }
  602. neon_pwrdm = pwrdm_lookup("neon_pwrdm");
  603. per_pwrdm = pwrdm_lookup("per_pwrdm");
  604. core_pwrdm = pwrdm_lookup("core_pwrdm");
  605. neon_clkdm = clkdm_lookup("neon_clkdm");
  606. mpu_clkdm = clkdm_lookup("mpu_clkdm");
  607. per_clkdm = clkdm_lookup("per_clkdm");
  608. wkup_clkdm = clkdm_lookup("wkup_clkdm");
  609. #ifdef CONFIG_SUSPEND
  610. omap_pm_suspend = omap3_pm_suspend;
  611. #endif
  612. arm_pm_idle = omap3_pm_idle;
  613. omap3_idle_init();
  614. /*
  615. * RTA is disabled during initialization as per erratum i608
  616. * it is safer to disable RTA by the bootloader, but we would like
  617. * to be doubly sure here and prevent any mishaps.
  618. */
  619. if (IS_PM34XX_ERRATUM(PM_RTA_ERRATUM_i608))
  620. omap3630_ctrl_disable_rta();
  621. /*
  622. * The UART3/4 FIFO and the sidetone memory in McBSP2/3 are
  623. * not correctly reset when the PER powerdomain comes back
  624. * from OFF or OSWR when the CORE powerdomain is kept active.
  625. * See OMAP36xx Erratum i582 "PER Domain reset issue after
  626. * Domain-OFF/OSWR Wakeup". This wakeup dependency is not a
  627. * complete workaround. The kernel must also prevent the PER
  628. * powerdomain from going to OSWR/OFF while the CORE
  629. * powerdomain is not going to OSWR/OFF. And if PER last
  630. * power state was off while CORE last power state was ON, the
  631. * UART3/4 and McBSP2/3 SIDETONE devices need to run a
  632. * self-test using their loopback tests; if that fails, those
  633. * devices are unusable until the PER/CORE can complete a transition
  634. * from ON to OSWR/OFF and then back to ON.
  635. *
  636. * XXX Technically this workaround is only needed if off-mode
  637. * or OSWR is enabled.
  638. */
  639. if (IS_PM34XX_ERRATUM(PM_PER_MEMORIES_ERRATUM_i582))
  640. clkdm_add_wkdep(per_clkdm, wkup_clkdm);
  641. clkdm_add_wkdep(neon_clkdm, mpu_clkdm);
  642. if (omap_type() != OMAP2_DEVICE_TYPE_GP) {
  643. omap3_secure_ram_storage =
  644. kmalloc(0x803F, GFP_KERNEL);
  645. if (!omap3_secure_ram_storage)
  646. pr_err("Memory allocation failed when allocating for secure sram context\n");
  647. local_irq_disable();
  648. local_fiq_disable();
  649. omap_dma_global_context_save();
  650. omap3_save_secure_ram_context();
  651. omap_dma_global_context_restore();
  652. local_irq_enable();
  653. local_fiq_enable();
  654. }
  655. omap3_save_scratchpad_contents();
  656. return ret;
  657. err3:
  658. list_for_each_entry_safe(pwrst, tmp, &pwrst_list, node) {
  659. list_del(&pwrst->node);
  660. kfree(pwrst);
  661. }
  662. free_irq(omap_prcm_event_to_irq("io"), omap3_pm_init);
  663. err2:
  664. free_irq(omap_prcm_event_to_irq("wkup"), NULL);
  665. err1:
  666. return ret;
  667. }