pm34xx.c 30 KB

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