pm34xx.c 22 KB

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