pm34xx.c 22 KB

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