pm34xx.c 22 KB

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