pm34xx.c 22 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809
  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 <plat/sram.h>
  33. #include "clockdomain.h"
  34. #include "powerdomain.h"
  35. #include <plat/sdrc.h>
  36. #include <plat/prcm.h>
  37. #include <plat/gpmc.h>
  38. #include <plat/dma.h>
  39. #include "common.h"
  40. #include "cm2xxx_3xxx.h"
  41. #include "cm-regbits-34xx.h"
  42. #include "prm-regbits-34xx.h"
  43. #include "prm2xxx_3xxx.h"
  44. #include "pm.h"
  45. #include "sdrc.h"
  46. #include "control.h"
  47. /* pm34xx errata defined in pm.h */
  48. u16 pm34xx_errata;
  49. struct power_state {
  50. struct powerdomain *pwrdm;
  51. u32 next_state;
  52. #ifdef CONFIG_SUSPEND
  53. u32 saved_state;
  54. #endif
  55. struct list_head node;
  56. };
  57. static LIST_HEAD(pwrst_list);
  58. static int (*_omap_save_secure_sram)(u32 *addr);
  59. void (*omap3_do_wfi_sram)(void);
  60. static struct powerdomain *mpu_pwrdm, *neon_pwrdm;
  61. static struct powerdomain *core_pwrdm, *per_pwrdm;
  62. static struct powerdomain *cam_pwrdm;
  63. static void omap3_enable_io_chain(void)
  64. {
  65. int timeout = 0;
  66. omap2_prm_set_mod_reg_bits(OMAP3430_EN_IO_CHAIN_MASK, WKUP_MOD,
  67. PM_WKEN);
  68. /* Do a readback to assure write has been done */
  69. omap2_prm_read_mod_reg(WKUP_MOD, PM_WKEN);
  70. while (!(omap2_prm_read_mod_reg(WKUP_MOD, PM_WKEN) &
  71. OMAP3430_ST_IO_CHAIN_MASK)) {
  72. timeout++;
  73. if (timeout > 1000) {
  74. pr_err("Wake up daisy chain activation failed.\n");
  75. return;
  76. }
  77. omap2_prm_set_mod_reg_bits(OMAP3430_ST_IO_CHAIN_MASK,
  78. WKUP_MOD, PM_WKEN);
  79. }
  80. }
  81. static void omap3_disable_io_chain(void)
  82. {
  83. omap2_prm_clear_mod_reg_bits(OMAP3430_EN_IO_CHAIN_MASK, WKUP_MOD,
  84. PM_WKEN);
  85. }
  86. static void omap3_core_save_context(void)
  87. {
  88. omap3_ctrl_save_padconf();
  89. /*
  90. * Force write last pad into memory, as this can fail in some
  91. * cases according to errata 1.157, 1.185
  92. */
  93. omap_ctrl_writel(omap_ctrl_readl(OMAP343X_PADCONF_ETK_D14),
  94. OMAP343X_CONTROL_MEM_WKUP + 0x2a0);
  95. /* Save the Interrupt controller context */
  96. omap_intc_save_context();
  97. /* Save the GPMC context */
  98. omap3_gpmc_save_context();
  99. /* Save the system control module context, padconf already save above*/
  100. omap3_control_save_context();
  101. omap_dma_global_context_save();
  102. }
  103. static void omap3_core_restore_context(void)
  104. {
  105. /* Restore the control module context, padconf restored by h/w */
  106. omap3_control_restore_context();
  107. /* Restore the GPMC context */
  108. omap3_gpmc_restore_context();
  109. /* Restore the interrupt controller context */
  110. omap_intc_restore_context();
  111. omap_dma_global_context_restore();
  112. }
  113. /*
  114. * FIXME: This function should be called before entering off-mode after
  115. * OMAP3 secure services have been accessed. Currently it is only called
  116. * once during boot sequence, but this works as we are not using secure
  117. * services.
  118. */
  119. static void omap3_save_secure_ram_context(void)
  120. {
  121. u32 ret;
  122. int mpu_next_state = pwrdm_read_next_pwrst(mpu_pwrdm);
  123. if (omap_type() != OMAP2_DEVICE_TYPE_GP) {
  124. /*
  125. * MPU next state must be set to POWER_ON temporarily,
  126. * otherwise the WFI executed inside the ROM code
  127. * will hang the system.
  128. */
  129. pwrdm_set_next_pwrst(mpu_pwrdm, PWRDM_POWER_ON);
  130. ret = _omap_save_secure_sram((u32 *)
  131. __pa(omap3_secure_ram_storage));
  132. pwrdm_set_next_pwrst(mpu_pwrdm, mpu_next_state);
  133. /* Following is for error tracking, it should not happen */
  134. if (ret) {
  135. printk(KERN_ERR "save_secure_sram() returns %08x\n",
  136. 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. printk(KERN_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. printk(KERN_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. printk(KERN_ERR "Could not enter target state in pm_suspend\n");
  390. else
  391. printk(KERN_INFO "Successfully put all powerdomains "
  392. "to target state\n");
  393. return ret;
  394. }
  395. #endif /* CONFIG_SUSPEND */
  396. /**
  397. * omap3_iva_idle(): ensure IVA is in idle so it can be put into
  398. * retention
  399. *
  400. * In cases where IVA2 is activated by bootcode, it may prevent
  401. * full-chip retention or off-mode because it is not idle. This
  402. * function forces the IVA2 into idle state so it can go
  403. * into retention/off and thus allow full-chip retention/off.
  404. *
  405. **/
  406. static void __init omap3_iva_idle(void)
  407. {
  408. /* ensure IVA2 clock is disabled */
  409. omap2_cm_write_mod_reg(0, OMAP3430_IVA2_MOD, CM_FCLKEN);
  410. /* if no clock activity, nothing else to do */
  411. if (!(omap2_cm_read_mod_reg(OMAP3430_IVA2_MOD, OMAP3430_CM_CLKSTST) &
  412. OMAP3430_CLKACTIVITY_IVA2_MASK))
  413. return;
  414. /* Reset IVA2 */
  415. omap2_prm_write_mod_reg(OMAP3430_RST1_IVA2_MASK |
  416. OMAP3430_RST2_IVA2_MASK |
  417. OMAP3430_RST3_IVA2_MASK,
  418. OMAP3430_IVA2_MOD, OMAP2_RM_RSTCTRL);
  419. /* Enable IVA2 clock */
  420. omap2_cm_write_mod_reg(OMAP3430_CM_FCLKEN_IVA2_EN_IVA2_MASK,
  421. OMAP3430_IVA2_MOD, CM_FCLKEN);
  422. /* Set IVA2 boot mode to 'idle' */
  423. omap_ctrl_writel(OMAP3_IVA2_BOOTMOD_IDLE,
  424. OMAP343X_CONTROL_IVA2_BOOTMOD);
  425. /* Un-reset IVA2 */
  426. omap2_prm_write_mod_reg(0, OMAP3430_IVA2_MOD, OMAP2_RM_RSTCTRL);
  427. /* Disable IVA2 clock */
  428. omap2_cm_write_mod_reg(0, OMAP3430_IVA2_MOD, CM_FCLKEN);
  429. /* Reset IVA2 */
  430. omap2_prm_write_mod_reg(OMAP3430_RST1_IVA2_MASK |
  431. OMAP3430_RST2_IVA2_MASK |
  432. OMAP3430_RST3_IVA2_MASK,
  433. OMAP3430_IVA2_MOD, OMAP2_RM_RSTCTRL);
  434. }
  435. static void __init omap3_d2d_idle(void)
  436. {
  437. u16 mask, padconf;
  438. /* In a stand alone OMAP3430 where there is not a stacked
  439. * modem for the D2D Idle Ack and D2D MStandby must be pulled
  440. * high. S CONTROL_PADCONF_SAD2D_IDLEACK and
  441. * CONTROL_PADCONF_SAD2D_MSTDBY to have a pull up. */
  442. mask = (1 << 4) | (1 << 3); /* pull-up, enabled */
  443. padconf = omap_ctrl_readw(OMAP3_PADCONF_SAD2D_MSTANDBY);
  444. padconf |= mask;
  445. omap_ctrl_writew(padconf, OMAP3_PADCONF_SAD2D_MSTANDBY);
  446. padconf = omap_ctrl_readw(OMAP3_PADCONF_SAD2D_IDLEACK);
  447. padconf |= mask;
  448. omap_ctrl_writew(padconf, OMAP3_PADCONF_SAD2D_IDLEACK);
  449. /* reset modem */
  450. omap2_prm_write_mod_reg(OMAP3430_RM_RSTCTRL_CORE_MODEM_SW_RSTPWRON_MASK |
  451. OMAP3430_RM_RSTCTRL_CORE_MODEM_SW_RST_MASK,
  452. CORE_MOD, OMAP2_RM_RSTCTRL);
  453. omap2_prm_write_mod_reg(0, CORE_MOD, OMAP2_RM_RSTCTRL);
  454. }
  455. static void __init prcm_setup_regs(void)
  456. {
  457. u32 omap3630_en_uart4_mask = cpu_is_omap3630() ?
  458. OMAP3630_EN_UART4_MASK : 0;
  459. u32 omap3630_grpsel_uart4_mask = cpu_is_omap3630() ?
  460. OMAP3630_GRPSEL_UART4_MASK : 0;
  461. /* XXX This should be handled by hwmod code or SCM init code */
  462. omap_ctrl_writel(OMAP3430_AUTOIDLE_MASK, OMAP2_CONTROL_SYSCONFIG);
  463. /*
  464. * Enable control of expternal oscillator through
  465. * sys_clkreq. In the long run clock framework should
  466. * take care of this.
  467. */
  468. omap2_prm_rmw_mod_reg_bits(OMAP_AUTOEXTCLKMODE_MASK,
  469. 1 << OMAP_AUTOEXTCLKMODE_SHIFT,
  470. OMAP3430_GR_MOD,
  471. OMAP3_PRM_CLKSRC_CTRL_OFFSET);
  472. /* setup wakup source */
  473. omap2_prm_write_mod_reg(OMAP3430_EN_IO_MASK | OMAP3430_EN_GPIO1_MASK |
  474. OMAP3430_EN_GPT1_MASK | OMAP3430_EN_GPT12_MASK,
  475. WKUP_MOD, PM_WKEN);
  476. /* No need to write EN_IO, that is always enabled */
  477. omap2_prm_write_mod_reg(OMAP3430_GRPSEL_GPIO1_MASK |
  478. OMAP3430_GRPSEL_GPT1_MASK |
  479. OMAP3430_GRPSEL_GPT12_MASK,
  480. WKUP_MOD, OMAP3430_PM_MPUGRPSEL);
  481. /* Enable PM_WKEN to support DSS LPR */
  482. omap2_prm_write_mod_reg(OMAP3430_PM_WKEN_DSS_EN_DSS_MASK,
  483. OMAP3430_DSS_MOD, PM_WKEN);
  484. /* Enable wakeups in PER */
  485. omap2_prm_write_mod_reg(omap3630_en_uart4_mask |
  486. OMAP3430_EN_GPIO2_MASK | OMAP3430_EN_GPIO3_MASK |
  487. OMAP3430_EN_GPIO4_MASK | OMAP3430_EN_GPIO5_MASK |
  488. OMAP3430_EN_GPIO6_MASK | OMAP3430_EN_UART3_MASK |
  489. OMAP3430_EN_MCBSP2_MASK | OMAP3430_EN_MCBSP3_MASK |
  490. OMAP3430_EN_MCBSP4_MASK,
  491. OMAP3430_PER_MOD, PM_WKEN);
  492. /* and allow them to wake up MPU */
  493. omap2_prm_write_mod_reg(omap3630_grpsel_uart4_mask |
  494. OMAP3430_GRPSEL_GPIO2_MASK |
  495. OMAP3430_GRPSEL_GPIO3_MASK |
  496. OMAP3430_GRPSEL_GPIO4_MASK |
  497. OMAP3430_GRPSEL_GPIO5_MASK |
  498. OMAP3430_GRPSEL_GPIO6_MASK |
  499. OMAP3430_GRPSEL_UART3_MASK |
  500. OMAP3430_GRPSEL_MCBSP2_MASK |
  501. OMAP3430_GRPSEL_MCBSP3_MASK |
  502. OMAP3430_GRPSEL_MCBSP4_MASK,
  503. OMAP3430_PER_MOD, OMAP3430_PM_MPUGRPSEL);
  504. /* Don't attach IVA interrupts */
  505. omap2_prm_write_mod_reg(0, WKUP_MOD, OMAP3430_PM_IVAGRPSEL);
  506. omap2_prm_write_mod_reg(0, CORE_MOD, OMAP3430_PM_IVAGRPSEL1);
  507. omap2_prm_write_mod_reg(0, CORE_MOD, OMAP3430ES2_PM_IVAGRPSEL3);
  508. omap2_prm_write_mod_reg(0, OMAP3430_PER_MOD, OMAP3430_PM_IVAGRPSEL);
  509. /* Clear any pending 'reset' flags */
  510. omap2_prm_write_mod_reg(0xffffffff, MPU_MOD, OMAP2_RM_RSTST);
  511. omap2_prm_write_mod_reg(0xffffffff, CORE_MOD, OMAP2_RM_RSTST);
  512. omap2_prm_write_mod_reg(0xffffffff, OMAP3430_PER_MOD, OMAP2_RM_RSTST);
  513. omap2_prm_write_mod_reg(0xffffffff, OMAP3430_EMU_MOD, OMAP2_RM_RSTST);
  514. omap2_prm_write_mod_reg(0xffffffff, OMAP3430_NEON_MOD, OMAP2_RM_RSTST);
  515. omap2_prm_write_mod_reg(0xffffffff, OMAP3430_DSS_MOD, OMAP2_RM_RSTST);
  516. omap2_prm_write_mod_reg(0xffffffff, OMAP3430ES2_USBHOST_MOD, OMAP2_RM_RSTST);
  517. /* Clear any pending PRCM interrupts */
  518. omap2_prm_write_mod_reg(0, OCP_MOD, OMAP3_PRM_IRQSTATUS_MPU_OFFSET);
  519. omap3_iva_idle();
  520. omap3_d2d_idle();
  521. }
  522. void omap3_pm_off_mode_enable(int enable)
  523. {
  524. struct power_state *pwrst;
  525. u32 state;
  526. if (enable)
  527. state = PWRDM_POWER_OFF;
  528. else
  529. state = PWRDM_POWER_RET;
  530. list_for_each_entry(pwrst, &pwrst_list, node) {
  531. if (IS_PM34XX_ERRATUM(PM_SDRC_WAKEUP_ERRATUM_i583) &&
  532. pwrst->pwrdm == core_pwrdm &&
  533. state == PWRDM_POWER_OFF) {
  534. pwrst->next_state = PWRDM_POWER_RET;
  535. pr_warn("%s: Core OFF disabled due to errata i583\n",
  536. __func__);
  537. } else {
  538. pwrst->next_state = state;
  539. }
  540. omap_set_pwrdm_state(pwrst->pwrdm, pwrst->next_state);
  541. }
  542. }
  543. int omap3_pm_get_suspend_state(struct powerdomain *pwrdm)
  544. {
  545. struct power_state *pwrst;
  546. list_for_each_entry(pwrst, &pwrst_list, node) {
  547. if (pwrst->pwrdm == pwrdm)
  548. return pwrst->next_state;
  549. }
  550. return -EINVAL;
  551. }
  552. int omap3_pm_set_suspend_state(struct powerdomain *pwrdm, int state)
  553. {
  554. struct power_state *pwrst;
  555. list_for_each_entry(pwrst, &pwrst_list, node) {
  556. if (pwrst->pwrdm == pwrdm) {
  557. pwrst->next_state = state;
  558. return 0;
  559. }
  560. }
  561. return -EINVAL;
  562. }
  563. static int __init pwrdms_setup(struct powerdomain *pwrdm, void *unused)
  564. {
  565. struct power_state *pwrst;
  566. if (!pwrdm->pwrsts)
  567. return 0;
  568. pwrst = kmalloc(sizeof(struct power_state), GFP_ATOMIC);
  569. if (!pwrst)
  570. return -ENOMEM;
  571. pwrst->pwrdm = pwrdm;
  572. pwrst->next_state = PWRDM_POWER_RET;
  573. list_add(&pwrst->node, &pwrst_list);
  574. if (pwrdm_has_hdwr_sar(pwrdm))
  575. pwrdm_enable_hdwr_sar(pwrdm);
  576. return omap_set_pwrdm_state(pwrst->pwrdm, pwrst->next_state);
  577. }
  578. /*
  579. * Push functions to SRAM
  580. *
  581. * The minimum set of functions is pushed to SRAM for execution:
  582. * - omap3_do_wfi for erratum i581 WA,
  583. * - save_secure_ram_context for security extensions.
  584. */
  585. void omap_push_sram_idle(void)
  586. {
  587. omap3_do_wfi_sram = omap_sram_push(omap3_do_wfi, omap3_do_wfi_sz);
  588. if (omap_type() != OMAP2_DEVICE_TYPE_GP)
  589. _omap_save_secure_sram = omap_sram_push(save_secure_ram_context,
  590. save_secure_ram_context_sz);
  591. }
  592. static void __init pm_errata_configure(void)
  593. {
  594. if (cpu_is_omap3630()) {
  595. pm34xx_errata |= PM_RTA_ERRATUM_i608;
  596. /* Enable the l2 cache toggling in sleep logic */
  597. enable_omap3630_toggle_l2_on_restore();
  598. if (omap_rev() < OMAP3630_REV_ES1_2)
  599. pm34xx_errata |= PM_SDRC_WAKEUP_ERRATUM_i583;
  600. }
  601. }
  602. static int __init omap3_pm_init(void)
  603. {
  604. struct power_state *pwrst, *tmp;
  605. struct clockdomain *neon_clkdm, *per_clkdm, *mpu_clkdm, *core_clkdm;
  606. int ret;
  607. if (!cpu_is_omap34xx())
  608. return -ENODEV;
  609. if (!omap3_has_io_chain_ctrl())
  610. pr_warning("PM: no software I/O chain control; some wakeups may be lost\n");
  611. pm_errata_configure();
  612. /* XXX prcm_setup_regs needs to be before enabling hw
  613. * supervised mode for powerdomains */
  614. prcm_setup_regs();
  615. ret = request_irq(omap_prcm_event_to_irq("wkup"),
  616. _prcm_int_handle_wakeup, IRQF_NO_SUSPEND, "pm_wkup", NULL);
  617. if (ret) {
  618. pr_err("pm: Failed to request pm_wkup irq\n");
  619. goto err1;
  620. }
  621. /* IO interrupt is shared with mux code */
  622. ret = request_irq(omap_prcm_event_to_irq("io"),
  623. _prcm_int_handle_io, IRQF_SHARED | IRQF_NO_SUSPEND, "pm_io",
  624. omap3_pm_init);
  625. if (ret) {
  626. pr_err("pm: Failed to request pm_io irq\n");
  627. goto err1;
  628. }
  629. ret = pwrdm_for_each(pwrdms_setup, NULL);
  630. if (ret) {
  631. printk(KERN_ERR "Failed to setup powerdomains\n");
  632. goto err2;
  633. }
  634. (void) clkdm_for_each(omap_pm_clkdms_setup, NULL);
  635. mpu_pwrdm = pwrdm_lookup("mpu_pwrdm");
  636. if (mpu_pwrdm == NULL) {
  637. printk(KERN_ERR "Failed to get mpu_pwrdm\n");
  638. goto err2;
  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. printk(KERN_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. err1:
  677. return ret;
  678. err2:
  679. free_irq(INT_34XX_PRCM_MPU_IRQ, NULL);
  680. list_for_each_entry_safe(pwrst, tmp, &pwrst_list, node) {
  681. list_del(&pwrst->node);
  682. kfree(pwrst);
  683. }
  684. return ret;
  685. }
  686. late_initcall(omap3_pm_init);