pm34xx.c 30 KB

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