pm34xx.c 22 KB

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