pm34xx.c 25 KB

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