pm34xx.c 30 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117
  1. /*
  2. * OMAP3 Power Management Routines
  3. *
  4. * Copyright (C) 2006-2008 Nokia Corporation
  5. * Tony Lindgren <tony@atomide.com>
  6. * Jouni Hogander
  7. *
  8. * Copyright (C) 2007 Texas Instruments, Inc.
  9. * Rajendra Nayak <rnayak@ti.com>
  10. *
  11. * Copyright (C) 2005 Texas Instruments, Inc.
  12. * Richard Woodruff <r-woodruff2@ti.com>
  13. *
  14. * Based on pm.c for omap1
  15. *
  16. * This program is free software; you can redistribute it and/or modify
  17. * it under the terms of the GNU General Public License version 2 as
  18. * published by the Free Software Foundation.
  19. */
  20. #include <linux/pm.h>
  21. #include <linux/suspend.h>
  22. #include <linux/interrupt.h>
  23. #include <linux/module.h>
  24. #include <linux/list.h>
  25. #include <linux/err.h>
  26. #include <linux/gpio.h>
  27. #include <linux/clk.h>
  28. #include <linux/delay.h>
  29. #include <linux/slab.h>
  30. #include <linux/console.h>
  31. #include <plat/sram.h>
  32. #include "clockdomain.h"
  33. #include "powerdomain.h"
  34. #include <plat/serial.h>
  35. #include <plat/sdrc.h>
  36. #include <plat/prcm.h>
  37. #include <plat/gpmc.h>
  38. #include <plat/dma.h>
  39. #include <asm/tlbflush.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. #ifdef CONFIG_SUSPEND
  48. static suspend_state_t suspend_state = PM_SUSPEND_ON;
  49. static inline bool is_suspending(void)
  50. {
  51. return (suspend_state != PM_SUSPEND_ON);
  52. }
  53. #else
  54. static inline bool is_suspending(void)
  55. {
  56. return false;
  57. }
  58. #endif
  59. /* Scratchpad offsets */
  60. #define OMAP343X_TABLE_ADDRESS_OFFSET 0xc4
  61. #define OMAP343X_TABLE_VALUE_OFFSET 0xc0
  62. #define OMAP343X_CONTROL_REG_VALUE_OFFSET 0xc8
  63. /* pm34xx errata defined in pm.h */
  64. u16 pm34xx_errata;
  65. struct power_state {
  66. struct powerdomain *pwrdm;
  67. u32 next_state;
  68. #ifdef CONFIG_SUSPEND
  69. u32 saved_state;
  70. #endif
  71. struct list_head node;
  72. };
  73. static LIST_HEAD(pwrst_list);
  74. static void (*_omap_sram_idle)(u32 *addr, int save_state);
  75. static int (*_omap_save_secure_sram)(u32 *addr);
  76. static struct powerdomain *mpu_pwrdm, *neon_pwrdm;
  77. static struct powerdomain *core_pwrdm, *per_pwrdm;
  78. static struct powerdomain *cam_pwrdm;
  79. static inline void omap3_per_save_context(void)
  80. {
  81. omap_gpio_save_context();
  82. }
  83. static inline void omap3_per_restore_context(void)
  84. {
  85. omap_gpio_restore_context();
  86. }
  87. static void omap3_enable_io_chain(void)
  88. {
  89. int timeout = 0;
  90. if (omap_rev() >= OMAP3430_REV_ES3_1) {
  91. omap2_prm_set_mod_reg_bits(OMAP3430_EN_IO_CHAIN_MASK, WKUP_MOD,
  92. PM_WKEN);
  93. /* Do a readback to assure write has been done */
  94. omap2_prm_read_mod_reg(WKUP_MOD, PM_WKEN);
  95. while (!(omap2_prm_read_mod_reg(WKUP_MOD, PM_WKEN) &
  96. OMAP3430_ST_IO_CHAIN_MASK)) {
  97. timeout++;
  98. if (timeout > 1000) {
  99. printk(KERN_ERR "Wake up daisy chain "
  100. "activation failed.\n");
  101. return;
  102. }
  103. omap2_prm_set_mod_reg_bits(OMAP3430_ST_IO_CHAIN_MASK,
  104. WKUP_MOD, PM_WKEN);
  105. }
  106. }
  107. }
  108. static void omap3_disable_io_chain(void)
  109. {
  110. if (omap_rev() >= OMAP3430_REV_ES3_1)
  111. omap2_prm_clear_mod_reg_bits(OMAP3430_EN_IO_CHAIN_MASK, WKUP_MOD,
  112. PM_WKEN);
  113. }
  114. static void omap3_core_save_context(void)
  115. {
  116. omap3_ctrl_save_padconf();
  117. /*
  118. * Force write last pad into memory, as this can fail in some
  119. * cases according to errata 1.157, 1.185
  120. */
  121. omap_ctrl_writel(omap_ctrl_readl(OMAP343X_PADCONF_ETK_D14),
  122. OMAP343X_CONTROL_MEM_WKUP + 0x2a0);
  123. /* Save the Interrupt controller context */
  124. omap_intc_save_context();
  125. /* Save the GPMC context */
  126. omap3_gpmc_save_context();
  127. /* Save the system control module context, padconf already save above*/
  128. omap3_control_save_context();
  129. omap_dma_global_context_save();
  130. }
  131. static void omap3_core_restore_context(void)
  132. {
  133. /* Restore the control module context, padconf restored by h/w */
  134. omap3_control_restore_context();
  135. /* Restore the GPMC context */
  136. omap3_gpmc_restore_context();
  137. /* Restore the interrupt controller context */
  138. omap_intc_restore_context();
  139. omap_dma_global_context_restore();
  140. }
  141. /*
  142. * FIXME: This function should be called before entering off-mode after
  143. * OMAP3 secure services have been accessed. Currently it is only called
  144. * once during boot sequence, but this works as we are not using secure
  145. * services.
  146. */
  147. static void omap3_save_secure_ram_context(void)
  148. {
  149. u32 ret;
  150. int mpu_next_state = pwrdm_read_next_pwrst(mpu_pwrdm);
  151. if (omap_type() != OMAP2_DEVICE_TYPE_GP) {
  152. /*
  153. * MPU next state must be set to POWER_ON temporarily,
  154. * otherwise the WFI executed inside the ROM code
  155. * will hang the system.
  156. */
  157. pwrdm_set_next_pwrst(mpu_pwrdm, PWRDM_POWER_ON);
  158. ret = _omap_save_secure_sram((u32 *)
  159. __pa(omap3_secure_ram_storage));
  160. pwrdm_set_next_pwrst(mpu_pwrdm, mpu_next_state);
  161. /* Following is for error tracking, it should not happen */
  162. if (ret) {
  163. printk(KERN_ERR "save_secure_sram() returns %08x\n",
  164. ret);
  165. while (1)
  166. ;
  167. }
  168. }
  169. }
  170. /*
  171. * PRCM Interrupt Handler Helper Function
  172. *
  173. * The purpose of this function is to clear any wake-up events latched
  174. * in the PRCM PM_WKST_x registers. It is possible that a wake-up event
  175. * may occur whilst attempting to clear a PM_WKST_x register and thus
  176. * set another bit in this register. A while loop is used to ensure
  177. * that any peripheral wake-up events occurring while attempting to
  178. * clear the PM_WKST_x are detected and cleared.
  179. */
  180. static int prcm_clear_mod_irqs(s16 module, u8 regs)
  181. {
  182. u32 wkst, fclk, iclk, clken;
  183. u16 wkst_off = (regs == 3) ? OMAP3430ES2_PM_WKST3 : PM_WKST1;
  184. u16 fclk_off = (regs == 3) ? OMAP3430ES2_CM_FCLKEN3 : CM_FCLKEN1;
  185. u16 iclk_off = (regs == 3) ? CM_ICLKEN3 : CM_ICLKEN1;
  186. u16 grpsel_off = (regs == 3) ?
  187. OMAP3430ES2_PM_MPUGRPSEL3 : OMAP3430_PM_MPUGRPSEL;
  188. int c = 0;
  189. wkst = omap2_prm_read_mod_reg(module, wkst_off);
  190. wkst &= omap2_prm_read_mod_reg(module, grpsel_off);
  191. if (wkst) {
  192. iclk = omap2_cm_read_mod_reg(module, iclk_off);
  193. fclk = omap2_cm_read_mod_reg(module, fclk_off);
  194. while (wkst) {
  195. clken = wkst;
  196. omap2_cm_set_mod_reg_bits(clken, module, iclk_off);
  197. /*
  198. * For USBHOST, we don't know whether HOST1 or
  199. * HOST2 woke us up, so enable both f-clocks
  200. */
  201. if (module == OMAP3430ES2_USBHOST_MOD)
  202. clken |= 1 << OMAP3430ES2_EN_USBHOST2_SHIFT;
  203. omap2_cm_set_mod_reg_bits(clken, module, fclk_off);
  204. omap2_prm_write_mod_reg(wkst, module, wkst_off);
  205. wkst = omap2_prm_read_mod_reg(module, wkst_off);
  206. c++;
  207. }
  208. omap2_cm_write_mod_reg(iclk, module, iclk_off);
  209. omap2_cm_write_mod_reg(fclk, module, fclk_off);
  210. }
  211. return c;
  212. }
  213. static int _prcm_int_handle_wakeup(void)
  214. {
  215. int c;
  216. c = prcm_clear_mod_irqs(WKUP_MOD, 1);
  217. c += prcm_clear_mod_irqs(CORE_MOD, 1);
  218. c += prcm_clear_mod_irqs(OMAP3430_PER_MOD, 1);
  219. if (omap_rev() > OMAP3430_REV_ES1_0) {
  220. c += prcm_clear_mod_irqs(CORE_MOD, 3);
  221. c += prcm_clear_mod_irqs(OMAP3430ES2_USBHOST_MOD, 1);
  222. }
  223. return c;
  224. }
  225. /*
  226. * PRCM Interrupt Handler
  227. *
  228. * The PRM_IRQSTATUS_MPU register indicates if there are any pending
  229. * interrupts from the PRCM for the MPU. These bits must be cleared in
  230. * order to clear the PRCM interrupt. The PRCM interrupt handler is
  231. * implemented to simply clear the PRM_IRQSTATUS_MPU in order to clear
  232. * the PRCM interrupt. Please note that bit 0 of the PRM_IRQSTATUS_MPU
  233. * register indicates that a wake-up event is pending for the MPU and
  234. * this bit can only be cleared if the all the wake-up events latched
  235. * in the various PM_WKST_x registers have been cleared. The interrupt
  236. * handler is implemented using a do-while loop so that if a wake-up
  237. * event occurred during the processing of the prcm interrupt handler
  238. * (setting a bit in the corresponding PM_WKST_x register and thus
  239. * preventing us from clearing bit 0 of the PRM_IRQSTATUS_MPU register)
  240. * this would be handled.
  241. */
  242. static irqreturn_t prcm_interrupt_handler (int irq, void *dev_id)
  243. {
  244. u32 irqenable_mpu, irqstatus_mpu;
  245. int c = 0;
  246. irqenable_mpu = omap2_prm_read_mod_reg(OCP_MOD,
  247. OMAP3_PRM_IRQENABLE_MPU_OFFSET);
  248. irqstatus_mpu = omap2_prm_read_mod_reg(OCP_MOD,
  249. OMAP3_PRM_IRQSTATUS_MPU_OFFSET);
  250. irqstatus_mpu &= irqenable_mpu;
  251. do {
  252. if (irqstatus_mpu & (OMAP3430_WKUP_ST_MASK |
  253. OMAP3430_IO_ST_MASK)) {
  254. c = _prcm_int_handle_wakeup();
  255. /*
  256. * Is the MPU PRCM interrupt handler racing with the
  257. * IVA2 PRCM interrupt handler ?
  258. */
  259. WARN(c == 0, "prcm: WARNING: PRCM indicated MPU wakeup "
  260. "but no wakeup sources are marked\n");
  261. } else {
  262. /* XXX we need to expand our PRCM interrupt handler */
  263. WARN(1, "prcm: WARNING: PRCM interrupt received, but "
  264. "no code to handle it (%08x)\n", irqstatus_mpu);
  265. }
  266. omap2_prm_write_mod_reg(irqstatus_mpu, OCP_MOD,
  267. OMAP3_PRM_IRQSTATUS_MPU_OFFSET);
  268. irqstatus_mpu = omap2_prm_read_mod_reg(OCP_MOD,
  269. OMAP3_PRM_IRQSTATUS_MPU_OFFSET);
  270. irqstatus_mpu &= irqenable_mpu;
  271. } while (irqstatus_mpu);
  272. return IRQ_HANDLED;
  273. }
  274. static void restore_control_register(u32 val)
  275. {
  276. __asm__ __volatile__ ("mcr p15, 0, %0, c1, c0, 0" : : "r" (val));
  277. }
  278. /* Function to restore the table entry that was modified for enabling MMU */
  279. static void restore_table_entry(void)
  280. {
  281. void __iomem *scratchpad_address;
  282. u32 previous_value, control_reg_value;
  283. u32 *address;
  284. scratchpad_address = OMAP2_L4_IO_ADDRESS(OMAP343X_SCRATCHPAD);
  285. /* Get address of entry that was modified */
  286. address = (u32 *)__raw_readl(scratchpad_address +
  287. OMAP343X_TABLE_ADDRESS_OFFSET);
  288. /* Get the previous value which needs to be restored */
  289. previous_value = __raw_readl(scratchpad_address +
  290. OMAP343X_TABLE_VALUE_OFFSET);
  291. address = __va(address);
  292. *address = previous_value;
  293. flush_tlb_all();
  294. control_reg_value = __raw_readl(scratchpad_address
  295. + OMAP343X_CONTROL_REG_VALUE_OFFSET);
  296. /* This will enable caches and prediction */
  297. restore_control_register(control_reg_value);
  298. }
  299. void omap_sram_idle(void)
  300. {
  301. /* Variable to tell what needs to be saved and restored
  302. * in omap_sram_idle*/
  303. /* save_state = 0 => Nothing to save and restored */
  304. /* save_state = 1 => Only L1 and logic lost */
  305. /* save_state = 2 => Only L2 lost */
  306. /* save_state = 3 => L1, L2 and logic lost */
  307. int save_state = 0;
  308. int mpu_next_state = PWRDM_POWER_ON;
  309. int per_next_state = PWRDM_POWER_ON;
  310. int core_next_state = PWRDM_POWER_ON;
  311. int per_going_off;
  312. int core_prev_state, per_prev_state;
  313. u32 sdrc_pwr = 0;
  314. if (!_omap_sram_idle)
  315. return;
  316. pwrdm_clear_all_prev_pwrst(mpu_pwrdm);
  317. pwrdm_clear_all_prev_pwrst(neon_pwrdm);
  318. pwrdm_clear_all_prev_pwrst(core_pwrdm);
  319. pwrdm_clear_all_prev_pwrst(per_pwrdm);
  320. mpu_next_state = pwrdm_read_next_pwrst(mpu_pwrdm);
  321. switch (mpu_next_state) {
  322. case PWRDM_POWER_ON:
  323. case PWRDM_POWER_RET:
  324. /* No need to save context */
  325. save_state = 0;
  326. break;
  327. case PWRDM_POWER_OFF:
  328. save_state = 3;
  329. break;
  330. default:
  331. /* Invalid state */
  332. printk(KERN_ERR "Invalid mpu state in sram_idle\n");
  333. return;
  334. }
  335. pwrdm_pre_transition();
  336. /* NEON control */
  337. if (pwrdm_read_pwrst(neon_pwrdm) == PWRDM_POWER_ON)
  338. pwrdm_set_next_pwrst(neon_pwrdm, mpu_next_state);
  339. /* Enable IO-PAD and IO-CHAIN wakeups */
  340. per_next_state = pwrdm_read_next_pwrst(per_pwrdm);
  341. core_next_state = pwrdm_read_next_pwrst(core_pwrdm);
  342. if (omap3_has_io_wakeup() &&
  343. (per_next_state < PWRDM_POWER_ON ||
  344. core_next_state < PWRDM_POWER_ON)) {
  345. omap2_prm_set_mod_reg_bits(OMAP3430_EN_IO_MASK, WKUP_MOD, PM_WKEN);
  346. omap3_enable_io_chain();
  347. }
  348. /* Block console output in case it is on one of the OMAP UARTs */
  349. if (!is_suspending())
  350. if (per_next_state < PWRDM_POWER_ON ||
  351. core_next_state < PWRDM_POWER_ON)
  352. if (!console_trylock())
  353. goto console_still_active;
  354. /* PER */
  355. if (per_next_state < PWRDM_POWER_ON) {
  356. per_going_off = (per_next_state == PWRDM_POWER_OFF) ? 1 : 0;
  357. omap_uart_prepare_idle(2);
  358. omap_uart_prepare_idle(3);
  359. omap2_gpio_prepare_for_idle(per_going_off);
  360. if (per_next_state == PWRDM_POWER_OFF)
  361. omap3_per_save_context();
  362. }
  363. /* CORE */
  364. if (core_next_state < PWRDM_POWER_ON) {
  365. omap_uart_prepare_idle(0);
  366. omap_uart_prepare_idle(1);
  367. if (core_next_state == PWRDM_POWER_OFF) {
  368. omap3_core_save_context();
  369. omap3_cm_save_context();
  370. }
  371. }
  372. omap3_intc_prepare_idle();
  373. /*
  374. * On EMU/HS devices ROM code restores a SRDC value
  375. * from scratchpad which has automatic self refresh on timeout
  376. * of AUTO_CNT = 1 enabled. This takes care of erratum ID i443.
  377. * Hence store/restore the SDRC_POWER register here.
  378. */
  379. if (omap_rev() >= OMAP3430_REV_ES3_0 &&
  380. omap_type() != OMAP2_DEVICE_TYPE_GP &&
  381. core_next_state == PWRDM_POWER_OFF)
  382. sdrc_pwr = sdrc_read_reg(SDRC_POWER);
  383. /*
  384. * omap3_arm_context is the location where ARM registers
  385. * get saved. The restore path then reads from this
  386. * location and restores them back.
  387. */
  388. _omap_sram_idle(omap3_arm_context, save_state);
  389. cpu_init();
  390. /* Restore normal SDRC POWER settings */
  391. if (omap_rev() >= OMAP3430_REV_ES3_0 &&
  392. omap_type() != OMAP2_DEVICE_TYPE_GP &&
  393. core_next_state == PWRDM_POWER_OFF)
  394. sdrc_write_reg(sdrc_pwr, SDRC_POWER);
  395. /* Restore table entry modified during MMU restoration */
  396. if (pwrdm_read_prev_pwrst(mpu_pwrdm) == PWRDM_POWER_OFF)
  397. restore_table_entry();
  398. /* CORE */
  399. if (core_next_state < PWRDM_POWER_ON) {
  400. core_prev_state = pwrdm_read_prev_pwrst(core_pwrdm);
  401. if (core_prev_state == PWRDM_POWER_OFF) {
  402. omap3_core_restore_context();
  403. omap3_cm_restore_context();
  404. omap3_sram_restore_context();
  405. omap2_sms_restore_context();
  406. }
  407. omap_uart_resume_idle(0);
  408. omap_uart_resume_idle(1);
  409. if (core_next_state == PWRDM_POWER_OFF)
  410. omap2_prm_clear_mod_reg_bits(OMAP3430_AUTO_OFF_MASK,
  411. OMAP3430_GR_MOD,
  412. OMAP3_PRM_VOLTCTRL_OFFSET);
  413. }
  414. omap3_intc_resume_idle();
  415. /* PER */
  416. if (per_next_state < PWRDM_POWER_ON) {
  417. per_prev_state = pwrdm_read_prev_pwrst(per_pwrdm);
  418. omap2_gpio_resume_after_idle();
  419. if (per_prev_state == PWRDM_POWER_OFF)
  420. omap3_per_restore_context();
  421. omap_uart_resume_idle(2);
  422. omap_uart_resume_idle(3);
  423. }
  424. if (!is_suspending())
  425. console_unlock();
  426. console_still_active:
  427. /* Disable IO-PAD and IO-CHAIN wakeup */
  428. if (omap3_has_io_wakeup() &&
  429. (per_next_state < PWRDM_POWER_ON ||
  430. core_next_state < PWRDM_POWER_ON)) {
  431. omap2_prm_clear_mod_reg_bits(OMAP3430_EN_IO_MASK, WKUP_MOD,
  432. PM_WKEN);
  433. omap3_disable_io_chain();
  434. }
  435. pwrdm_post_transition();
  436. omap2_clkdm_allow_idle(mpu_pwrdm->pwrdm_clkdms[0]);
  437. }
  438. int omap3_can_sleep(void)
  439. {
  440. if (!sleep_while_idle)
  441. return 0;
  442. if (!omap_uart_can_sleep())
  443. return 0;
  444. return 1;
  445. }
  446. static void omap3_pm_idle(void)
  447. {
  448. local_irq_disable();
  449. local_fiq_disable();
  450. if (!omap3_can_sleep())
  451. goto out;
  452. if (omap_irq_pending() || need_resched())
  453. goto out;
  454. omap_sram_idle();
  455. out:
  456. local_fiq_enable();
  457. local_irq_enable();
  458. }
  459. #ifdef CONFIG_SUSPEND
  460. static int omap3_pm_suspend(void)
  461. {
  462. struct power_state *pwrst;
  463. int state, ret = 0;
  464. if (wakeup_timer_seconds || wakeup_timer_milliseconds)
  465. omap2_pm_wakeup_on_timer(wakeup_timer_seconds,
  466. wakeup_timer_milliseconds);
  467. /* Read current next_pwrsts */
  468. list_for_each_entry(pwrst, &pwrst_list, node)
  469. pwrst->saved_state = pwrdm_read_next_pwrst(pwrst->pwrdm);
  470. /* Set ones wanted by suspend */
  471. list_for_each_entry(pwrst, &pwrst_list, node) {
  472. if (omap_set_pwrdm_state(pwrst->pwrdm, pwrst->next_state))
  473. goto restore;
  474. if (pwrdm_clear_all_prev_pwrst(pwrst->pwrdm))
  475. goto restore;
  476. }
  477. omap_uart_prepare_suspend();
  478. omap3_intc_suspend();
  479. omap_sram_idle();
  480. restore:
  481. /* Restore next_pwrsts */
  482. list_for_each_entry(pwrst, &pwrst_list, node) {
  483. state = pwrdm_read_prev_pwrst(pwrst->pwrdm);
  484. if (state > pwrst->next_state) {
  485. printk(KERN_INFO "Powerdomain (%s) didn't enter "
  486. "target state %d\n",
  487. pwrst->pwrdm->name, pwrst->next_state);
  488. ret = -1;
  489. }
  490. omap_set_pwrdm_state(pwrst->pwrdm, pwrst->saved_state);
  491. }
  492. if (ret)
  493. printk(KERN_ERR "Could not enter target state in pm_suspend\n");
  494. else
  495. printk(KERN_INFO "Successfully put all powerdomains "
  496. "to target state\n");
  497. return ret;
  498. }
  499. static int omap3_pm_enter(suspend_state_t unused)
  500. {
  501. int ret = 0;
  502. switch (suspend_state) {
  503. case PM_SUSPEND_STANDBY:
  504. case PM_SUSPEND_MEM:
  505. ret = omap3_pm_suspend();
  506. break;
  507. default:
  508. ret = -EINVAL;
  509. }
  510. return ret;
  511. }
  512. /* Hooks to enable / disable UART interrupts during suspend */
  513. static int omap3_pm_begin(suspend_state_t state)
  514. {
  515. disable_hlt();
  516. suspend_state = state;
  517. omap_uart_enable_irqs(0);
  518. return 0;
  519. }
  520. static void omap3_pm_end(void)
  521. {
  522. suspend_state = PM_SUSPEND_ON;
  523. omap_uart_enable_irqs(1);
  524. enable_hlt();
  525. return;
  526. }
  527. static const struct platform_suspend_ops omap_pm_ops = {
  528. .begin = omap3_pm_begin,
  529. .end = omap3_pm_end,
  530. .enter = omap3_pm_enter,
  531. .valid = suspend_valid_only_mem,
  532. };
  533. #endif /* CONFIG_SUSPEND */
  534. /**
  535. * omap3_iva_idle(): ensure IVA is in idle so it can be put into
  536. * retention
  537. *
  538. * In cases where IVA2 is activated by bootcode, it may prevent
  539. * full-chip retention or off-mode because it is not idle. This
  540. * function forces the IVA2 into idle state so it can go
  541. * into retention/off and thus allow full-chip retention/off.
  542. *
  543. **/
  544. static void __init omap3_iva_idle(void)
  545. {
  546. /* ensure IVA2 clock is disabled */
  547. omap2_cm_write_mod_reg(0, OMAP3430_IVA2_MOD, CM_FCLKEN);
  548. /* if no clock activity, nothing else to do */
  549. if (!(omap2_cm_read_mod_reg(OMAP3430_IVA2_MOD, OMAP3430_CM_CLKSTST) &
  550. OMAP3430_CLKACTIVITY_IVA2_MASK))
  551. return;
  552. /* Reset IVA2 */
  553. omap2_prm_write_mod_reg(OMAP3430_RST1_IVA2_MASK |
  554. OMAP3430_RST2_IVA2_MASK |
  555. OMAP3430_RST3_IVA2_MASK,
  556. OMAP3430_IVA2_MOD, OMAP2_RM_RSTCTRL);
  557. /* Enable IVA2 clock */
  558. omap2_cm_write_mod_reg(OMAP3430_CM_FCLKEN_IVA2_EN_IVA2_MASK,
  559. OMAP3430_IVA2_MOD, CM_FCLKEN);
  560. /* Set IVA2 boot mode to 'idle' */
  561. omap_ctrl_writel(OMAP3_IVA2_BOOTMOD_IDLE,
  562. OMAP343X_CONTROL_IVA2_BOOTMOD);
  563. /* Un-reset IVA2 */
  564. omap2_prm_write_mod_reg(0, OMAP3430_IVA2_MOD, OMAP2_RM_RSTCTRL);
  565. /* Disable IVA2 clock */
  566. omap2_cm_write_mod_reg(0, OMAP3430_IVA2_MOD, CM_FCLKEN);
  567. /* Reset IVA2 */
  568. omap2_prm_write_mod_reg(OMAP3430_RST1_IVA2_MASK |
  569. OMAP3430_RST2_IVA2_MASK |
  570. OMAP3430_RST3_IVA2_MASK,
  571. OMAP3430_IVA2_MOD, OMAP2_RM_RSTCTRL);
  572. }
  573. static void __init omap3_d2d_idle(void)
  574. {
  575. u16 mask, padconf;
  576. /* In a stand alone OMAP3430 where there is not a stacked
  577. * modem for the D2D Idle Ack and D2D MStandby must be pulled
  578. * high. S CONTROL_PADCONF_SAD2D_IDLEACK and
  579. * CONTROL_PADCONF_SAD2D_MSTDBY to have a pull up. */
  580. mask = (1 << 4) | (1 << 3); /* pull-up, enabled */
  581. padconf = omap_ctrl_readw(OMAP3_PADCONF_SAD2D_MSTANDBY);
  582. padconf |= mask;
  583. omap_ctrl_writew(padconf, OMAP3_PADCONF_SAD2D_MSTANDBY);
  584. padconf = omap_ctrl_readw(OMAP3_PADCONF_SAD2D_IDLEACK);
  585. padconf |= mask;
  586. omap_ctrl_writew(padconf, OMAP3_PADCONF_SAD2D_IDLEACK);
  587. /* reset modem */
  588. omap2_prm_write_mod_reg(OMAP3430_RM_RSTCTRL_CORE_MODEM_SW_RSTPWRON_MASK |
  589. OMAP3430_RM_RSTCTRL_CORE_MODEM_SW_RST_MASK,
  590. CORE_MOD, OMAP2_RM_RSTCTRL);
  591. omap2_prm_write_mod_reg(0, CORE_MOD, OMAP2_RM_RSTCTRL);
  592. }
  593. static void __init prcm_setup_regs(void)
  594. {
  595. u32 omap3630_auto_uart4_mask = cpu_is_omap3630() ?
  596. OMAP3630_AUTO_UART4_MASK : 0;
  597. u32 omap3630_en_uart4_mask = cpu_is_omap3630() ?
  598. OMAP3630_EN_UART4_MASK : 0;
  599. u32 omap3630_grpsel_uart4_mask = cpu_is_omap3630() ?
  600. OMAP3630_GRPSEL_UART4_MASK : 0;
  601. /* XXX Reset all wkdeps. This should be done when initializing
  602. * powerdomains */
  603. omap2_prm_write_mod_reg(0, OMAP3430_IVA2_MOD, PM_WKDEP);
  604. omap2_prm_write_mod_reg(0, MPU_MOD, PM_WKDEP);
  605. omap2_prm_write_mod_reg(0, OMAP3430_DSS_MOD, PM_WKDEP);
  606. omap2_prm_write_mod_reg(0, OMAP3430_NEON_MOD, PM_WKDEP);
  607. omap2_prm_write_mod_reg(0, OMAP3430_CAM_MOD, PM_WKDEP);
  608. omap2_prm_write_mod_reg(0, OMAP3430_PER_MOD, PM_WKDEP);
  609. if (omap_rev() > OMAP3430_REV_ES1_0) {
  610. omap2_prm_write_mod_reg(0, OMAP3430ES2_SGX_MOD, PM_WKDEP);
  611. omap2_prm_write_mod_reg(0, OMAP3430ES2_USBHOST_MOD, PM_WKDEP);
  612. } else
  613. omap2_prm_write_mod_reg(0, GFX_MOD, PM_WKDEP);
  614. /*
  615. * Enable interface clock autoidle for all modules.
  616. * Note that in the long run this should be done by clockfw
  617. */
  618. omap2_cm_write_mod_reg(
  619. OMAP3430_AUTO_MODEM_MASK |
  620. OMAP3430ES2_AUTO_MMC3_MASK |
  621. OMAP3430ES2_AUTO_ICR_MASK |
  622. OMAP3430_AUTO_AES2_MASK |
  623. OMAP3430_AUTO_SHA12_MASK |
  624. OMAP3430_AUTO_DES2_MASK |
  625. OMAP3430_AUTO_MMC2_MASK |
  626. OMAP3430_AUTO_MMC1_MASK |
  627. OMAP3430_AUTO_MSPRO_MASK |
  628. OMAP3430_AUTO_HDQ_MASK |
  629. OMAP3430_AUTO_MCSPI4_MASK |
  630. OMAP3430_AUTO_MCSPI3_MASK |
  631. OMAP3430_AUTO_MCSPI2_MASK |
  632. OMAP3430_AUTO_MCSPI1_MASK |
  633. OMAP3430_AUTO_I2C3_MASK |
  634. OMAP3430_AUTO_I2C2_MASK |
  635. OMAP3430_AUTO_I2C1_MASK |
  636. OMAP3430_AUTO_UART2_MASK |
  637. OMAP3430_AUTO_UART1_MASK |
  638. OMAP3430_AUTO_GPT11_MASK |
  639. OMAP3430_AUTO_GPT10_MASK |
  640. OMAP3430_AUTO_MCBSP5_MASK |
  641. OMAP3430_AUTO_MCBSP1_MASK |
  642. OMAP3430ES1_AUTO_FAC_MASK | /* This is es1 only */
  643. OMAP3430_AUTO_MAILBOXES_MASK |
  644. OMAP3430_AUTO_OMAPCTRL_MASK |
  645. OMAP3430ES1_AUTO_FSHOSTUSB_MASK |
  646. OMAP3430_AUTO_HSOTGUSB_MASK |
  647. OMAP3430_AUTO_SAD2D_MASK |
  648. OMAP3430_AUTO_SSI_MASK,
  649. CORE_MOD, CM_AUTOIDLE1);
  650. omap2_cm_write_mod_reg(
  651. OMAP3430_AUTO_PKA_MASK |
  652. OMAP3430_AUTO_AES1_MASK |
  653. OMAP3430_AUTO_RNG_MASK |
  654. OMAP3430_AUTO_SHA11_MASK |
  655. OMAP3430_AUTO_DES1_MASK,
  656. CORE_MOD, CM_AUTOIDLE2);
  657. if (omap_rev() > OMAP3430_REV_ES1_0) {
  658. omap2_cm_write_mod_reg(
  659. OMAP3430_AUTO_MAD2D_MASK |
  660. OMAP3430ES2_AUTO_USBTLL_MASK,
  661. CORE_MOD, CM_AUTOIDLE3);
  662. }
  663. omap2_cm_write_mod_reg(
  664. OMAP3430_AUTO_WDT2_MASK |
  665. OMAP3430_AUTO_WDT1_MASK |
  666. OMAP3430_AUTO_GPIO1_MASK |
  667. OMAP3430_AUTO_32KSYNC_MASK |
  668. OMAP3430_AUTO_GPT12_MASK |
  669. OMAP3430_AUTO_GPT1_MASK,
  670. WKUP_MOD, CM_AUTOIDLE);
  671. omap2_cm_write_mod_reg(
  672. OMAP3430_AUTO_DSS_MASK,
  673. OMAP3430_DSS_MOD,
  674. CM_AUTOIDLE);
  675. omap2_cm_write_mod_reg(
  676. OMAP3430_AUTO_CAM_MASK,
  677. OMAP3430_CAM_MOD,
  678. CM_AUTOIDLE);
  679. omap2_cm_write_mod_reg(
  680. omap3630_auto_uart4_mask |
  681. OMAP3430_AUTO_GPIO6_MASK |
  682. OMAP3430_AUTO_GPIO5_MASK |
  683. OMAP3430_AUTO_GPIO4_MASK |
  684. OMAP3430_AUTO_GPIO3_MASK |
  685. OMAP3430_AUTO_GPIO2_MASK |
  686. OMAP3430_AUTO_WDT3_MASK |
  687. OMAP3430_AUTO_UART3_MASK |
  688. OMAP3430_AUTO_GPT9_MASK |
  689. OMAP3430_AUTO_GPT8_MASK |
  690. OMAP3430_AUTO_GPT7_MASK |
  691. OMAP3430_AUTO_GPT6_MASK |
  692. OMAP3430_AUTO_GPT5_MASK |
  693. OMAP3430_AUTO_GPT4_MASK |
  694. OMAP3430_AUTO_GPT3_MASK |
  695. OMAP3430_AUTO_GPT2_MASK |
  696. OMAP3430_AUTO_MCBSP4_MASK |
  697. OMAP3430_AUTO_MCBSP3_MASK |
  698. OMAP3430_AUTO_MCBSP2_MASK,
  699. OMAP3430_PER_MOD,
  700. CM_AUTOIDLE);
  701. if (omap_rev() > OMAP3430_REV_ES1_0) {
  702. omap2_cm_write_mod_reg(
  703. OMAP3430ES2_AUTO_USBHOST_MASK,
  704. OMAP3430ES2_USBHOST_MOD,
  705. CM_AUTOIDLE);
  706. }
  707. omap_ctrl_writel(OMAP3430_AUTOIDLE_MASK, OMAP2_CONTROL_SYSCONFIG);
  708. /*
  709. * Set all plls to autoidle. This is needed until autoidle is
  710. * enabled by clockfw
  711. */
  712. omap2_cm_write_mod_reg(1 << OMAP3430_AUTO_IVA2_DPLL_SHIFT,
  713. OMAP3430_IVA2_MOD, CM_AUTOIDLE2);
  714. omap2_cm_write_mod_reg(1 << OMAP3430_AUTO_MPU_DPLL_SHIFT,
  715. MPU_MOD,
  716. CM_AUTOIDLE2);
  717. omap2_cm_write_mod_reg((1 << OMAP3430_AUTO_PERIPH_DPLL_SHIFT) |
  718. (1 << OMAP3430_AUTO_CORE_DPLL_SHIFT),
  719. PLL_MOD,
  720. CM_AUTOIDLE);
  721. omap2_cm_write_mod_reg(1 << OMAP3430ES2_AUTO_PERIPH2_DPLL_SHIFT,
  722. PLL_MOD,
  723. CM_AUTOIDLE2);
  724. /*
  725. * Enable control of expternal oscillator through
  726. * sys_clkreq. In the long run clock framework should
  727. * take care of this.
  728. */
  729. omap2_prm_rmw_mod_reg_bits(OMAP_AUTOEXTCLKMODE_MASK,
  730. 1 << OMAP_AUTOEXTCLKMODE_SHIFT,
  731. OMAP3430_GR_MOD,
  732. OMAP3_PRM_CLKSRC_CTRL_OFFSET);
  733. /* setup wakup source */
  734. omap2_prm_write_mod_reg(OMAP3430_EN_IO_MASK | OMAP3430_EN_GPIO1_MASK |
  735. OMAP3430_EN_GPT1_MASK | OMAP3430_EN_GPT12_MASK,
  736. WKUP_MOD, PM_WKEN);
  737. /* No need to write EN_IO, that is always enabled */
  738. omap2_prm_write_mod_reg(OMAP3430_GRPSEL_GPIO1_MASK |
  739. OMAP3430_GRPSEL_GPT1_MASK |
  740. OMAP3430_GRPSEL_GPT12_MASK,
  741. WKUP_MOD, OMAP3430_PM_MPUGRPSEL);
  742. /* For some reason IO doesn't generate wakeup event even if
  743. * it is selected to mpu wakeup goup */
  744. omap2_prm_write_mod_reg(OMAP3430_IO_EN_MASK | OMAP3430_WKUP_EN_MASK,
  745. OCP_MOD, OMAP3_PRM_IRQENABLE_MPU_OFFSET);
  746. /* Enable PM_WKEN to support DSS LPR */
  747. omap2_prm_write_mod_reg(OMAP3430_PM_WKEN_DSS_EN_DSS_MASK,
  748. OMAP3430_DSS_MOD, PM_WKEN);
  749. /* Enable wakeups in PER */
  750. omap2_prm_write_mod_reg(omap3630_en_uart4_mask |
  751. OMAP3430_EN_GPIO2_MASK | OMAP3430_EN_GPIO3_MASK |
  752. OMAP3430_EN_GPIO4_MASK | OMAP3430_EN_GPIO5_MASK |
  753. OMAP3430_EN_GPIO6_MASK | OMAP3430_EN_UART3_MASK |
  754. OMAP3430_EN_MCBSP2_MASK | OMAP3430_EN_MCBSP3_MASK |
  755. OMAP3430_EN_MCBSP4_MASK,
  756. OMAP3430_PER_MOD, PM_WKEN);
  757. /* and allow them to wake up MPU */
  758. omap2_prm_write_mod_reg(omap3630_grpsel_uart4_mask |
  759. OMAP3430_GRPSEL_GPIO2_MASK |
  760. OMAP3430_GRPSEL_GPIO3_MASK |
  761. OMAP3430_GRPSEL_GPIO4_MASK |
  762. OMAP3430_GRPSEL_GPIO5_MASK |
  763. OMAP3430_GRPSEL_GPIO6_MASK |
  764. OMAP3430_GRPSEL_UART3_MASK |
  765. OMAP3430_GRPSEL_MCBSP2_MASK |
  766. OMAP3430_GRPSEL_MCBSP3_MASK |
  767. OMAP3430_GRPSEL_MCBSP4_MASK,
  768. OMAP3430_PER_MOD, OMAP3430_PM_MPUGRPSEL);
  769. /* Don't attach IVA interrupts */
  770. omap2_prm_write_mod_reg(0, WKUP_MOD, OMAP3430_PM_IVAGRPSEL);
  771. omap2_prm_write_mod_reg(0, CORE_MOD, OMAP3430_PM_IVAGRPSEL1);
  772. omap2_prm_write_mod_reg(0, CORE_MOD, OMAP3430ES2_PM_IVAGRPSEL3);
  773. omap2_prm_write_mod_reg(0, OMAP3430_PER_MOD, OMAP3430_PM_IVAGRPSEL);
  774. /* Clear any pending 'reset' flags */
  775. omap2_prm_write_mod_reg(0xffffffff, MPU_MOD, OMAP2_RM_RSTST);
  776. omap2_prm_write_mod_reg(0xffffffff, CORE_MOD, OMAP2_RM_RSTST);
  777. omap2_prm_write_mod_reg(0xffffffff, OMAP3430_PER_MOD, OMAP2_RM_RSTST);
  778. omap2_prm_write_mod_reg(0xffffffff, OMAP3430_EMU_MOD, OMAP2_RM_RSTST);
  779. omap2_prm_write_mod_reg(0xffffffff, OMAP3430_NEON_MOD, OMAP2_RM_RSTST);
  780. omap2_prm_write_mod_reg(0xffffffff, OMAP3430_DSS_MOD, OMAP2_RM_RSTST);
  781. omap2_prm_write_mod_reg(0xffffffff, OMAP3430ES2_USBHOST_MOD, OMAP2_RM_RSTST);
  782. /* Clear any pending PRCM interrupts */
  783. omap2_prm_write_mod_reg(0, OCP_MOD, OMAP3_PRM_IRQSTATUS_MPU_OFFSET);
  784. omap3_iva_idle();
  785. omap3_d2d_idle();
  786. }
  787. void omap3_pm_off_mode_enable(int enable)
  788. {
  789. struct power_state *pwrst;
  790. u32 state;
  791. if (enable)
  792. state = PWRDM_POWER_OFF;
  793. else
  794. state = PWRDM_POWER_RET;
  795. #ifdef CONFIG_CPU_IDLE
  796. /*
  797. * Erratum i583: implementation for ES rev < Es1.2 on 3630. We cannot
  798. * enable OFF mode in a stable form for previous revisions, restrict
  799. * instead to RET
  800. */
  801. if (IS_PM34XX_ERRATUM(PM_SDRC_WAKEUP_ERRATUM_i583))
  802. omap3_cpuidle_update_states(state, PWRDM_POWER_RET);
  803. else
  804. omap3_cpuidle_update_states(state, state);
  805. #endif
  806. list_for_each_entry(pwrst, &pwrst_list, node) {
  807. if (IS_PM34XX_ERRATUM(PM_SDRC_WAKEUP_ERRATUM_i583) &&
  808. pwrst->pwrdm == core_pwrdm &&
  809. state == PWRDM_POWER_OFF) {
  810. pwrst->next_state = PWRDM_POWER_RET;
  811. WARN_ONCE(1,
  812. "%s: Core OFF disabled due to errata i583\n",
  813. __func__);
  814. } else {
  815. pwrst->next_state = state;
  816. }
  817. omap_set_pwrdm_state(pwrst->pwrdm, pwrst->next_state);
  818. }
  819. }
  820. int omap3_pm_get_suspend_state(struct powerdomain *pwrdm)
  821. {
  822. struct power_state *pwrst;
  823. list_for_each_entry(pwrst, &pwrst_list, node) {
  824. if (pwrst->pwrdm == pwrdm)
  825. return pwrst->next_state;
  826. }
  827. return -EINVAL;
  828. }
  829. int omap3_pm_set_suspend_state(struct powerdomain *pwrdm, int state)
  830. {
  831. struct power_state *pwrst;
  832. list_for_each_entry(pwrst, &pwrst_list, node) {
  833. if (pwrst->pwrdm == pwrdm) {
  834. pwrst->next_state = state;
  835. return 0;
  836. }
  837. }
  838. return -EINVAL;
  839. }
  840. static int __init pwrdms_setup(struct powerdomain *pwrdm, void *unused)
  841. {
  842. struct power_state *pwrst;
  843. if (!pwrdm->pwrsts)
  844. return 0;
  845. pwrst = kmalloc(sizeof(struct power_state), GFP_ATOMIC);
  846. if (!pwrst)
  847. return -ENOMEM;
  848. pwrst->pwrdm = pwrdm;
  849. pwrst->next_state = PWRDM_POWER_RET;
  850. list_add(&pwrst->node, &pwrst_list);
  851. if (pwrdm_has_hdwr_sar(pwrdm))
  852. pwrdm_enable_hdwr_sar(pwrdm);
  853. return omap_set_pwrdm_state(pwrst->pwrdm, pwrst->next_state);
  854. }
  855. /*
  856. * Enable hw supervised mode for all clockdomains if it's
  857. * supported. Initiate sleep transition for other clockdomains, if
  858. * they are not used
  859. */
  860. static int __init clkdms_setup(struct clockdomain *clkdm, void *unused)
  861. {
  862. if (clkdm->flags & CLKDM_CAN_ENABLE_AUTO)
  863. omap2_clkdm_allow_idle(clkdm);
  864. else if (clkdm->flags & CLKDM_CAN_FORCE_SLEEP &&
  865. atomic_read(&clkdm->usecount) == 0)
  866. omap2_clkdm_sleep(clkdm);
  867. return 0;
  868. }
  869. void omap_push_sram_idle(void)
  870. {
  871. _omap_sram_idle = omap_sram_push(omap34xx_cpu_suspend,
  872. omap34xx_cpu_suspend_sz);
  873. if (omap_type() != OMAP2_DEVICE_TYPE_GP)
  874. _omap_save_secure_sram = omap_sram_push(save_secure_ram_context,
  875. save_secure_ram_context_sz);
  876. }
  877. static void __init pm_errata_configure(void)
  878. {
  879. if (cpu_is_omap3630()) {
  880. pm34xx_errata |= PM_RTA_ERRATUM_i608;
  881. /* Enable the l2 cache toggling in sleep logic */
  882. enable_omap3630_toggle_l2_on_restore();
  883. if (omap_rev() < OMAP3630_REV_ES1_2)
  884. pm34xx_errata |= PM_SDRC_WAKEUP_ERRATUM_i583;
  885. }
  886. }
  887. static int __init omap3_pm_init(void)
  888. {
  889. struct power_state *pwrst, *tmp;
  890. struct clockdomain *neon_clkdm, *per_clkdm, *mpu_clkdm, *core_clkdm;
  891. int ret;
  892. if (!cpu_is_omap34xx())
  893. return -ENODEV;
  894. pm_errata_configure();
  895. printk(KERN_ERR "Power Management for TI OMAP3.\n");
  896. /* XXX prcm_setup_regs needs to be before enabling hw
  897. * supervised mode for powerdomains */
  898. prcm_setup_regs();
  899. ret = request_irq(INT_34XX_PRCM_MPU_IRQ,
  900. (irq_handler_t)prcm_interrupt_handler,
  901. IRQF_DISABLED, "prcm", NULL);
  902. if (ret) {
  903. printk(KERN_ERR "request_irq failed to register for 0x%x\n",
  904. INT_34XX_PRCM_MPU_IRQ);
  905. goto err1;
  906. }
  907. ret = pwrdm_for_each(pwrdms_setup, NULL);
  908. if (ret) {
  909. printk(KERN_ERR "Failed to setup powerdomains\n");
  910. goto err2;
  911. }
  912. (void) clkdm_for_each(clkdms_setup, NULL);
  913. mpu_pwrdm = pwrdm_lookup("mpu_pwrdm");
  914. if (mpu_pwrdm == NULL) {
  915. printk(KERN_ERR "Failed to get mpu_pwrdm\n");
  916. goto err2;
  917. }
  918. neon_pwrdm = pwrdm_lookup("neon_pwrdm");
  919. per_pwrdm = pwrdm_lookup("per_pwrdm");
  920. core_pwrdm = pwrdm_lookup("core_pwrdm");
  921. cam_pwrdm = pwrdm_lookup("cam_pwrdm");
  922. neon_clkdm = clkdm_lookup("neon_clkdm");
  923. mpu_clkdm = clkdm_lookup("mpu_clkdm");
  924. per_clkdm = clkdm_lookup("per_clkdm");
  925. core_clkdm = clkdm_lookup("core_clkdm");
  926. omap_push_sram_idle();
  927. #ifdef CONFIG_SUSPEND
  928. suspend_set_ops(&omap_pm_ops);
  929. #endif /* CONFIG_SUSPEND */
  930. pm_idle = omap3_pm_idle;
  931. omap3_idle_init();
  932. /*
  933. * RTA is disabled during initialization as per erratum i608
  934. * it is safer to disable RTA by the bootloader, but we would like
  935. * to be doubly sure here and prevent any mishaps.
  936. */
  937. if (IS_PM34XX_ERRATUM(PM_RTA_ERRATUM_i608))
  938. omap3630_ctrl_disable_rta();
  939. clkdm_add_wkdep(neon_clkdm, mpu_clkdm);
  940. if (omap_type() != OMAP2_DEVICE_TYPE_GP) {
  941. omap3_secure_ram_storage =
  942. kmalloc(0x803F, GFP_KERNEL);
  943. if (!omap3_secure_ram_storage)
  944. printk(KERN_ERR "Memory allocation failed when"
  945. "allocating for secure sram context\n");
  946. local_irq_disable();
  947. local_fiq_disable();
  948. omap_dma_global_context_save();
  949. omap3_save_secure_ram_context();
  950. omap_dma_global_context_restore();
  951. local_irq_enable();
  952. local_fiq_enable();
  953. }
  954. omap3_save_scratchpad_contents();
  955. err1:
  956. return ret;
  957. err2:
  958. free_irq(INT_34XX_PRCM_MPU_IRQ, NULL);
  959. list_for_each_entry_safe(pwrst, tmp, &pwrst_list, node) {
  960. list_del(&pwrst->node);
  961. kfree(pwrst);
  962. }
  963. return ret;
  964. }
  965. late_initcall(omap3_pm_init);