pm.c 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732
  1. /*
  2. * linux/arch/arm/mach-omap1/pm.c
  3. *
  4. * OMAP Power Management Routines
  5. *
  6. * Original code for the SA11x0:
  7. * Copyright (c) 2001 Cliff Brake <cbrake@accelent.com>
  8. *
  9. * Modified for the PXA250 by Nicolas Pitre:
  10. * Copyright (c) 2002 Monta Vista Software, Inc.
  11. *
  12. * Modified for the OMAP1510 by David Singleton:
  13. * Copyright (c) 2002 Monta Vista Software, Inc.
  14. *
  15. * Cleanup 2004 for OMAP1510/1610 by Dirk Behme <dirk.behme@de.bosch.com>
  16. *
  17. * This program is free software; you can redistribute it and/or modify it
  18. * under the terms of the GNU General Public License as published by the
  19. * Free Software Foundation; either version 2 of the License, or (at your
  20. * option) any later version.
  21. *
  22. * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED
  23. * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
  24. * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN
  25. * NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
  26. * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
  27. * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
  28. * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
  29. * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
  30. * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
  31. * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  32. *
  33. * You should have received a copy of the GNU General Public License along
  34. * with this program; if not, write to the Free Software Foundation, Inc.,
  35. * 675 Mass Ave, Cambridge, MA 02139, USA.
  36. */
  37. #include <linux/suspend.h>
  38. #include <linux/sched.h>
  39. #include <linux/proc_fs.h>
  40. #include <linux/interrupt.h>
  41. #include <linux/sysfs.h>
  42. #include <linux/module.h>
  43. #include <asm/io.h>
  44. #include <asm/irq.h>
  45. #include <asm/atomic.h>
  46. #include <asm/mach/time.h>
  47. #include <asm/mach/irq.h>
  48. #include <asm/mach-types.h>
  49. #include <asm/arch/cpu.h>
  50. #include <asm/arch/irqs.h>
  51. #include <asm/arch/clock.h>
  52. #include <asm/arch/sram.h>
  53. #include <asm/arch/tc.h>
  54. #include <asm/arch/pm.h>
  55. #include <asm/arch/mux.h>
  56. #include <asm/arch/dma.h>
  57. #include <asm/arch/dmtimer.h>
  58. static unsigned int arm_sleep_save[ARM_SLEEP_SAVE_SIZE];
  59. static unsigned short dsp_sleep_save[DSP_SLEEP_SAVE_SIZE];
  60. static unsigned short ulpd_sleep_save[ULPD_SLEEP_SAVE_SIZE];
  61. static unsigned int mpui730_sleep_save[MPUI730_SLEEP_SAVE_SIZE];
  62. static unsigned int mpui1510_sleep_save[MPUI1510_SLEEP_SAVE_SIZE];
  63. static unsigned int mpui1610_sleep_save[MPUI1610_SLEEP_SAVE_SIZE];
  64. #ifdef CONFIG_OMAP_32K_TIMER
  65. static unsigned short enable_dyn_sleep = 1;
  66. static ssize_t idle_show(struct kobject *kobj, struct kobj_attribute *attr,
  67. char *buf)
  68. {
  69. return sprintf(buf, "%hu\n", enable_dyn_sleep);
  70. }
  71. static ssize_t idle_store(struct kobject *kobj, struct kobj_attribute *attr,
  72. const char * buf, size_t n)
  73. {
  74. unsigned short value;
  75. if (sscanf(buf, "%hu", &value) != 1 ||
  76. (value != 0 && value != 1)) {
  77. printk(KERN_ERR "idle_sleep_store: Invalid value\n");
  78. return -EINVAL;
  79. }
  80. enable_dyn_sleep = value;
  81. return n;
  82. }
  83. static struct kobj_attribute sleep_while_idle_attr =
  84. __ATTR(sleep_while_idle, 0644, idle_show, idle_store);
  85. #endif
  86. static void (*omap_sram_suspend)(unsigned long r0, unsigned long r1) = NULL;
  87. /*
  88. * Let's power down on idle, but only if we are really
  89. * idle, because once we start down the path of
  90. * going idle we continue to do idle even if we get
  91. * a clock tick interrupt . .
  92. */
  93. void omap_pm_idle(void)
  94. {
  95. extern __u32 arm_idlect1_mask;
  96. __u32 use_idlect1 = arm_idlect1_mask;
  97. int do_sleep = 0;
  98. local_irq_disable();
  99. local_fiq_disable();
  100. if (need_resched()) {
  101. local_fiq_enable();
  102. local_irq_enable();
  103. return;
  104. }
  105. /*
  106. * Since an interrupt may set up a timer, we don't want to
  107. * reprogram the hardware timer with interrupts enabled.
  108. * Re-enable interrupts only after returning from idle.
  109. */
  110. timer_dyn_reprogram();
  111. #ifdef CONFIG_OMAP_MPU_TIMER
  112. #warning Enable 32kHz OS timer in order to allow sleep states in idle
  113. use_idlect1 = use_idlect1 & ~(1 << 9);
  114. #else
  115. while (enable_dyn_sleep) {
  116. #ifdef CONFIG_CBUS_TAHVO_USB
  117. extern int vbus_active;
  118. /* Clock requirements? */
  119. if (vbus_active)
  120. break;
  121. #endif
  122. do_sleep = 1;
  123. break;
  124. }
  125. #endif
  126. #ifdef CONFIG_OMAP_DM_TIMER
  127. use_idlect1 = omap_dm_timer_modify_idlect_mask(use_idlect1);
  128. #endif
  129. if (omap_dma_running())
  130. use_idlect1 &= ~(1 << 6);
  131. /* We should be able to remove the do_sleep variable and multiple
  132. * tests above as soon as drivers, timer and DMA code have been fixed.
  133. * Even the sleep block count should become obsolete. */
  134. if ((use_idlect1 != ~0) || !do_sleep) {
  135. __u32 saved_idlect1 = omap_readl(ARM_IDLECT1);
  136. if (cpu_is_omap15xx())
  137. use_idlect1 &= OMAP1510_BIG_SLEEP_REQUEST;
  138. else
  139. use_idlect1 &= OMAP1610_IDLECT1_SLEEP_VAL;
  140. omap_writel(use_idlect1, ARM_IDLECT1);
  141. __asm__ volatile ("mcr p15, 0, r0, c7, c0, 4");
  142. omap_writel(saved_idlect1, ARM_IDLECT1);
  143. local_fiq_enable();
  144. local_irq_enable();
  145. return;
  146. }
  147. omap_sram_suspend(omap_readl(ARM_IDLECT1),
  148. omap_readl(ARM_IDLECT2));
  149. local_fiq_enable();
  150. local_irq_enable();
  151. }
  152. /*
  153. * Configuration of the wakeup event is board specific. For the
  154. * moment we put it into this helper function. Later it may move
  155. * to board specific files.
  156. */
  157. static void omap_pm_wakeup_setup(void)
  158. {
  159. u32 level1_wake = 0;
  160. u32 level2_wake = OMAP_IRQ_BIT(INT_UART2);
  161. /*
  162. * Turn off all interrupts except GPIO bank 1, L1-2nd level cascade,
  163. * and the L2 wakeup interrupts: keypad and UART2. Note that the
  164. * drivers must still separately call omap_set_gpio_wakeup() to
  165. * wake up to a GPIO interrupt.
  166. */
  167. if (cpu_is_omap730())
  168. level1_wake = OMAP_IRQ_BIT(INT_730_GPIO_BANK1) |
  169. OMAP_IRQ_BIT(INT_730_IH2_IRQ);
  170. else if (cpu_is_omap15xx())
  171. level1_wake = OMAP_IRQ_BIT(INT_GPIO_BANK1) |
  172. OMAP_IRQ_BIT(INT_1510_IH2_IRQ);
  173. else if (cpu_is_omap16xx())
  174. level1_wake = OMAP_IRQ_BIT(INT_GPIO_BANK1) |
  175. OMAP_IRQ_BIT(INT_1610_IH2_IRQ);
  176. omap_writel(~level1_wake, OMAP_IH1_MIR);
  177. if (cpu_is_omap730()) {
  178. omap_writel(~level2_wake, OMAP_IH2_0_MIR);
  179. omap_writel(~(OMAP_IRQ_BIT(INT_730_WAKE_UP_REQ) |
  180. OMAP_IRQ_BIT(INT_730_MPUIO_KEYPAD)),
  181. OMAP_IH2_1_MIR);
  182. } else if (cpu_is_omap15xx()) {
  183. level2_wake |= OMAP_IRQ_BIT(INT_KEYBOARD);
  184. omap_writel(~level2_wake, OMAP_IH2_MIR);
  185. } else if (cpu_is_omap16xx()) {
  186. level2_wake |= OMAP_IRQ_BIT(INT_KEYBOARD);
  187. omap_writel(~level2_wake, OMAP_IH2_0_MIR);
  188. /* INT_1610_WAKE_UP_REQ is needed for GPIO wakeup... */
  189. omap_writel(~OMAP_IRQ_BIT(INT_1610_WAKE_UP_REQ),
  190. OMAP_IH2_1_MIR);
  191. omap_writel(~0x0, OMAP_IH2_2_MIR);
  192. omap_writel(~0x0, OMAP_IH2_3_MIR);
  193. }
  194. /* New IRQ agreement, recalculate in cascade order */
  195. omap_writel(1, OMAP_IH2_CONTROL);
  196. omap_writel(1, OMAP_IH1_CONTROL);
  197. }
  198. #define EN_DSPCK 13 /* ARM_CKCTL */
  199. #define EN_APICK 6 /* ARM_IDLECT2 */
  200. #define DSP_EN 1 /* ARM_RSTCT1 */
  201. void omap_pm_suspend(void)
  202. {
  203. unsigned long arg0 = 0, arg1 = 0;
  204. printk("PM: OMAP%x is trying to enter deep sleep...\n", system_rev);
  205. omap_serial_wake_trigger(1);
  206. if (!cpu_is_omap15xx())
  207. omap_writew(0xffff, ULPD_SOFT_DISABLE_REQ_REG);
  208. /*
  209. * Step 1: turn off interrupts (FIXME: NOTE: already disabled)
  210. */
  211. local_irq_disable();
  212. local_fiq_disable();
  213. /*
  214. * Step 2: save registers
  215. *
  216. * The omap is a strange/beautiful device. The caches, memory
  217. * and register state are preserved across power saves.
  218. * We have to save and restore very little register state to
  219. * idle the omap.
  220. *
  221. * Save interrupt, MPUI, ARM and UPLD control registers.
  222. */
  223. if (cpu_is_omap730()) {
  224. MPUI730_SAVE(OMAP_IH1_MIR);
  225. MPUI730_SAVE(OMAP_IH2_0_MIR);
  226. MPUI730_SAVE(OMAP_IH2_1_MIR);
  227. MPUI730_SAVE(MPUI_CTRL);
  228. MPUI730_SAVE(MPUI_DSP_BOOT_CONFIG);
  229. MPUI730_SAVE(MPUI_DSP_API_CONFIG);
  230. MPUI730_SAVE(EMIFS_CONFIG);
  231. MPUI730_SAVE(EMIFF_SDRAM_CONFIG);
  232. } else if (cpu_is_omap15xx()) {
  233. MPUI1510_SAVE(OMAP_IH1_MIR);
  234. MPUI1510_SAVE(OMAP_IH2_MIR);
  235. MPUI1510_SAVE(MPUI_CTRL);
  236. MPUI1510_SAVE(MPUI_DSP_BOOT_CONFIG);
  237. MPUI1510_SAVE(MPUI_DSP_API_CONFIG);
  238. MPUI1510_SAVE(EMIFS_CONFIG);
  239. MPUI1510_SAVE(EMIFF_SDRAM_CONFIG);
  240. } else if (cpu_is_omap16xx()) {
  241. MPUI1610_SAVE(OMAP_IH1_MIR);
  242. MPUI1610_SAVE(OMAP_IH2_0_MIR);
  243. MPUI1610_SAVE(OMAP_IH2_1_MIR);
  244. MPUI1610_SAVE(OMAP_IH2_2_MIR);
  245. MPUI1610_SAVE(OMAP_IH2_3_MIR);
  246. MPUI1610_SAVE(MPUI_CTRL);
  247. MPUI1610_SAVE(MPUI_DSP_BOOT_CONFIG);
  248. MPUI1610_SAVE(MPUI_DSP_API_CONFIG);
  249. MPUI1610_SAVE(EMIFS_CONFIG);
  250. MPUI1610_SAVE(EMIFF_SDRAM_CONFIG);
  251. }
  252. ARM_SAVE(ARM_CKCTL);
  253. ARM_SAVE(ARM_IDLECT1);
  254. ARM_SAVE(ARM_IDLECT2);
  255. if (!(cpu_is_omap15xx()))
  256. ARM_SAVE(ARM_IDLECT3);
  257. ARM_SAVE(ARM_EWUPCT);
  258. ARM_SAVE(ARM_RSTCT1);
  259. ARM_SAVE(ARM_RSTCT2);
  260. ARM_SAVE(ARM_SYSST);
  261. ULPD_SAVE(ULPD_CLOCK_CTRL);
  262. ULPD_SAVE(ULPD_STATUS_REQ);
  263. /* (Step 3 removed - we now allow deep sleep by default) */
  264. /*
  265. * Step 4: OMAP DSP Shutdown
  266. */
  267. /* stop DSP */
  268. omap_writew(omap_readw(ARM_RSTCT1) & ~(1 << DSP_EN), ARM_RSTCT1);
  269. /* shut down dsp_ck */
  270. if (!cpu_is_omap730())
  271. omap_writew(omap_readw(ARM_CKCTL) & ~(1 << EN_DSPCK), ARM_CKCTL);
  272. /* temporarily enabling api_ck to access DSP registers */
  273. omap_writew(omap_readw(ARM_IDLECT2) | 1 << EN_APICK, ARM_IDLECT2);
  274. /* save DSP registers */
  275. DSP_SAVE(DSP_IDLECT2);
  276. /* Stop all DSP domain clocks */
  277. __raw_writew(0, DSP_IDLECT2);
  278. /*
  279. * Step 5: Wakeup Event Setup
  280. */
  281. omap_pm_wakeup_setup();
  282. /*
  283. * Step 6: ARM and Traffic controller shutdown
  284. */
  285. /* disable ARM watchdog */
  286. omap_writel(0x00F5, OMAP_WDT_TIMER_MODE);
  287. omap_writel(0x00A0, OMAP_WDT_TIMER_MODE);
  288. /*
  289. * Step 6b: ARM and Traffic controller shutdown
  290. *
  291. * Step 6 continues here. Prepare jump to power management
  292. * assembly code in internal SRAM.
  293. *
  294. * Since the omap_cpu_suspend routine has been copied to
  295. * SRAM, we'll do an indirect procedure call to it and pass the
  296. * contents of arm_idlect1 and arm_idlect2 so it can restore
  297. * them when it wakes up and it will return.
  298. */
  299. arg0 = arm_sleep_save[ARM_SLEEP_SAVE_ARM_IDLECT1];
  300. arg1 = arm_sleep_save[ARM_SLEEP_SAVE_ARM_IDLECT2];
  301. /*
  302. * Step 6c: ARM and Traffic controller shutdown
  303. *
  304. * Jump to assembly code. The processor will stay there
  305. * until wake up.
  306. */
  307. omap_sram_suspend(arg0, arg1);
  308. /*
  309. * If we are here, processor is woken up!
  310. */
  311. /*
  312. * Restore DSP clocks
  313. */
  314. /* again temporarily enabling api_ck to access DSP registers */
  315. omap_writew(omap_readw(ARM_IDLECT2) | 1 << EN_APICK, ARM_IDLECT2);
  316. /* Restore DSP domain clocks */
  317. DSP_RESTORE(DSP_IDLECT2);
  318. /*
  319. * Restore ARM state, except ARM_IDLECT1/2 which omap_cpu_suspend did
  320. */
  321. if (!(cpu_is_omap15xx()))
  322. ARM_RESTORE(ARM_IDLECT3);
  323. ARM_RESTORE(ARM_CKCTL);
  324. ARM_RESTORE(ARM_EWUPCT);
  325. ARM_RESTORE(ARM_RSTCT1);
  326. ARM_RESTORE(ARM_RSTCT2);
  327. ARM_RESTORE(ARM_SYSST);
  328. ULPD_RESTORE(ULPD_CLOCK_CTRL);
  329. ULPD_RESTORE(ULPD_STATUS_REQ);
  330. if (cpu_is_omap730()) {
  331. MPUI730_RESTORE(EMIFS_CONFIG);
  332. MPUI730_RESTORE(EMIFF_SDRAM_CONFIG);
  333. MPUI730_RESTORE(OMAP_IH1_MIR);
  334. MPUI730_RESTORE(OMAP_IH2_0_MIR);
  335. MPUI730_RESTORE(OMAP_IH2_1_MIR);
  336. } else if (cpu_is_omap15xx()) {
  337. MPUI1510_RESTORE(MPUI_CTRL);
  338. MPUI1510_RESTORE(MPUI_DSP_BOOT_CONFIG);
  339. MPUI1510_RESTORE(MPUI_DSP_API_CONFIG);
  340. MPUI1510_RESTORE(EMIFS_CONFIG);
  341. MPUI1510_RESTORE(EMIFF_SDRAM_CONFIG);
  342. MPUI1510_RESTORE(OMAP_IH1_MIR);
  343. MPUI1510_RESTORE(OMAP_IH2_MIR);
  344. } else if (cpu_is_omap16xx()) {
  345. MPUI1610_RESTORE(MPUI_CTRL);
  346. MPUI1610_RESTORE(MPUI_DSP_BOOT_CONFIG);
  347. MPUI1610_RESTORE(MPUI_DSP_API_CONFIG);
  348. MPUI1610_RESTORE(EMIFS_CONFIG);
  349. MPUI1610_RESTORE(EMIFF_SDRAM_CONFIG);
  350. MPUI1610_RESTORE(OMAP_IH1_MIR);
  351. MPUI1610_RESTORE(OMAP_IH2_0_MIR);
  352. MPUI1610_RESTORE(OMAP_IH2_1_MIR);
  353. MPUI1610_RESTORE(OMAP_IH2_2_MIR);
  354. MPUI1610_RESTORE(OMAP_IH2_3_MIR);
  355. }
  356. if (!cpu_is_omap15xx())
  357. omap_writew(0, ULPD_SOFT_DISABLE_REQ_REG);
  358. /*
  359. * Re-enable interrupts
  360. */
  361. local_irq_enable();
  362. local_fiq_enable();
  363. omap_serial_wake_trigger(0);
  364. printk("PM: OMAP%x is re-starting from deep sleep...\n", system_rev);
  365. }
  366. #if defined(DEBUG) && defined(CONFIG_PROC_FS)
  367. static int g_read_completed;
  368. /*
  369. * Read system PM registers for debugging
  370. */
  371. static int omap_pm_read_proc(
  372. char *page_buffer,
  373. char **my_first_byte,
  374. off_t virtual_start,
  375. int length,
  376. int *eof,
  377. void *data)
  378. {
  379. int my_buffer_offset = 0;
  380. char * const my_base = page_buffer;
  381. ARM_SAVE(ARM_CKCTL);
  382. ARM_SAVE(ARM_IDLECT1);
  383. ARM_SAVE(ARM_IDLECT2);
  384. if (!(cpu_is_omap15xx()))
  385. ARM_SAVE(ARM_IDLECT3);
  386. ARM_SAVE(ARM_EWUPCT);
  387. ARM_SAVE(ARM_RSTCT1);
  388. ARM_SAVE(ARM_RSTCT2);
  389. ARM_SAVE(ARM_SYSST);
  390. ULPD_SAVE(ULPD_IT_STATUS);
  391. ULPD_SAVE(ULPD_CLOCK_CTRL);
  392. ULPD_SAVE(ULPD_SOFT_REQ);
  393. ULPD_SAVE(ULPD_STATUS_REQ);
  394. ULPD_SAVE(ULPD_DPLL_CTRL);
  395. ULPD_SAVE(ULPD_POWER_CTRL);
  396. if (cpu_is_omap730()) {
  397. MPUI730_SAVE(MPUI_CTRL);
  398. MPUI730_SAVE(MPUI_DSP_STATUS);
  399. MPUI730_SAVE(MPUI_DSP_BOOT_CONFIG);
  400. MPUI730_SAVE(MPUI_DSP_API_CONFIG);
  401. MPUI730_SAVE(EMIFF_SDRAM_CONFIG);
  402. MPUI730_SAVE(EMIFS_CONFIG);
  403. } else if (cpu_is_omap15xx()) {
  404. MPUI1510_SAVE(MPUI_CTRL);
  405. MPUI1510_SAVE(MPUI_DSP_STATUS);
  406. MPUI1510_SAVE(MPUI_DSP_BOOT_CONFIG);
  407. MPUI1510_SAVE(MPUI_DSP_API_CONFIG);
  408. MPUI1510_SAVE(EMIFF_SDRAM_CONFIG);
  409. MPUI1510_SAVE(EMIFS_CONFIG);
  410. } else if (cpu_is_omap16xx()) {
  411. MPUI1610_SAVE(MPUI_CTRL);
  412. MPUI1610_SAVE(MPUI_DSP_STATUS);
  413. MPUI1610_SAVE(MPUI_DSP_BOOT_CONFIG);
  414. MPUI1610_SAVE(MPUI_DSP_API_CONFIG);
  415. MPUI1610_SAVE(EMIFF_SDRAM_CONFIG);
  416. MPUI1610_SAVE(EMIFS_CONFIG);
  417. }
  418. if (virtual_start == 0) {
  419. g_read_completed = 0;
  420. my_buffer_offset += sprintf(my_base + my_buffer_offset,
  421. "ARM_CKCTL_REG: 0x%-8x \n"
  422. "ARM_IDLECT1_REG: 0x%-8x \n"
  423. "ARM_IDLECT2_REG: 0x%-8x \n"
  424. "ARM_IDLECT3_REG: 0x%-8x \n"
  425. "ARM_EWUPCT_REG: 0x%-8x \n"
  426. "ARM_RSTCT1_REG: 0x%-8x \n"
  427. "ARM_RSTCT2_REG: 0x%-8x \n"
  428. "ARM_SYSST_REG: 0x%-8x \n"
  429. "ULPD_IT_STATUS_REG: 0x%-4x \n"
  430. "ULPD_CLOCK_CTRL_REG: 0x%-4x \n"
  431. "ULPD_SOFT_REQ_REG: 0x%-4x \n"
  432. "ULPD_DPLL_CTRL_REG: 0x%-4x \n"
  433. "ULPD_STATUS_REQ_REG: 0x%-4x \n"
  434. "ULPD_POWER_CTRL_REG: 0x%-4x \n",
  435. ARM_SHOW(ARM_CKCTL),
  436. ARM_SHOW(ARM_IDLECT1),
  437. ARM_SHOW(ARM_IDLECT2),
  438. ARM_SHOW(ARM_IDLECT3),
  439. ARM_SHOW(ARM_EWUPCT),
  440. ARM_SHOW(ARM_RSTCT1),
  441. ARM_SHOW(ARM_RSTCT2),
  442. ARM_SHOW(ARM_SYSST),
  443. ULPD_SHOW(ULPD_IT_STATUS),
  444. ULPD_SHOW(ULPD_CLOCK_CTRL),
  445. ULPD_SHOW(ULPD_SOFT_REQ),
  446. ULPD_SHOW(ULPD_DPLL_CTRL),
  447. ULPD_SHOW(ULPD_STATUS_REQ),
  448. ULPD_SHOW(ULPD_POWER_CTRL));
  449. if (cpu_is_omap730()) {
  450. my_buffer_offset += sprintf(my_base + my_buffer_offset,
  451. "MPUI730_CTRL_REG 0x%-8x \n"
  452. "MPUI730_DSP_STATUS_REG: 0x%-8x \n"
  453. "MPUI730_DSP_BOOT_CONFIG_REG: 0x%-8x \n"
  454. "MPUI730_DSP_API_CONFIG_REG: 0x%-8x \n"
  455. "MPUI730_SDRAM_CONFIG_REG: 0x%-8x \n"
  456. "MPUI730_EMIFS_CONFIG_REG: 0x%-8x \n",
  457. MPUI730_SHOW(MPUI_CTRL),
  458. MPUI730_SHOW(MPUI_DSP_STATUS),
  459. MPUI730_SHOW(MPUI_DSP_BOOT_CONFIG),
  460. MPUI730_SHOW(MPUI_DSP_API_CONFIG),
  461. MPUI730_SHOW(EMIFF_SDRAM_CONFIG),
  462. MPUI730_SHOW(EMIFS_CONFIG));
  463. } else if (cpu_is_omap15xx()) {
  464. my_buffer_offset += sprintf(my_base + my_buffer_offset,
  465. "MPUI1510_CTRL_REG 0x%-8x \n"
  466. "MPUI1510_DSP_STATUS_REG: 0x%-8x \n"
  467. "MPUI1510_DSP_BOOT_CONFIG_REG: 0x%-8x \n"
  468. "MPUI1510_DSP_API_CONFIG_REG: 0x%-8x \n"
  469. "MPUI1510_SDRAM_CONFIG_REG: 0x%-8x \n"
  470. "MPUI1510_EMIFS_CONFIG_REG: 0x%-8x \n",
  471. MPUI1510_SHOW(MPUI_CTRL),
  472. MPUI1510_SHOW(MPUI_DSP_STATUS),
  473. MPUI1510_SHOW(MPUI_DSP_BOOT_CONFIG),
  474. MPUI1510_SHOW(MPUI_DSP_API_CONFIG),
  475. MPUI1510_SHOW(EMIFF_SDRAM_CONFIG),
  476. MPUI1510_SHOW(EMIFS_CONFIG));
  477. } else if (cpu_is_omap16xx()) {
  478. my_buffer_offset += sprintf(my_base + my_buffer_offset,
  479. "MPUI1610_CTRL_REG 0x%-8x \n"
  480. "MPUI1610_DSP_STATUS_REG: 0x%-8x \n"
  481. "MPUI1610_DSP_BOOT_CONFIG_REG: 0x%-8x \n"
  482. "MPUI1610_DSP_API_CONFIG_REG: 0x%-8x \n"
  483. "MPUI1610_SDRAM_CONFIG_REG: 0x%-8x \n"
  484. "MPUI1610_EMIFS_CONFIG_REG: 0x%-8x \n",
  485. MPUI1610_SHOW(MPUI_CTRL),
  486. MPUI1610_SHOW(MPUI_DSP_STATUS),
  487. MPUI1610_SHOW(MPUI_DSP_BOOT_CONFIG),
  488. MPUI1610_SHOW(MPUI_DSP_API_CONFIG),
  489. MPUI1610_SHOW(EMIFF_SDRAM_CONFIG),
  490. MPUI1610_SHOW(EMIFS_CONFIG));
  491. }
  492. g_read_completed++;
  493. } else if (g_read_completed >= 1) {
  494. *eof = 1;
  495. return 0;
  496. }
  497. g_read_completed++;
  498. *my_first_byte = page_buffer;
  499. return my_buffer_offset;
  500. }
  501. static void omap_pm_init_proc(void)
  502. {
  503. struct proc_dir_entry *entry;
  504. entry = create_proc_read_entry("driver/omap_pm",
  505. S_IWUSR | S_IRUGO, NULL,
  506. omap_pm_read_proc, NULL);
  507. }
  508. #endif /* DEBUG && CONFIG_PROC_FS */
  509. static void (*saved_idle)(void) = NULL;
  510. /*
  511. * omap_pm_prepare - Do preliminary suspend work.
  512. *
  513. */
  514. static int omap_pm_prepare(void)
  515. {
  516. /* We cannot sleep in idle until we have resumed */
  517. saved_idle = pm_idle;
  518. pm_idle = NULL;
  519. return 0;
  520. }
  521. /*
  522. * omap_pm_enter - Actually enter a sleep state.
  523. * @state: State we're entering.
  524. *
  525. */
  526. static int omap_pm_enter(suspend_state_t state)
  527. {
  528. switch (state)
  529. {
  530. case PM_SUSPEND_STANDBY:
  531. case PM_SUSPEND_MEM:
  532. omap_pm_suspend();
  533. break;
  534. default:
  535. return -EINVAL;
  536. }
  537. return 0;
  538. }
  539. /**
  540. * omap_pm_finish - Finish up suspend sequence.
  541. *
  542. * This is called after we wake back up (or if entering the sleep state
  543. * failed).
  544. */
  545. static void omap_pm_finish(void)
  546. {
  547. pm_idle = saved_idle;
  548. }
  549. static irqreturn_t omap_wakeup_interrupt(int irq, void *dev)
  550. {
  551. return IRQ_HANDLED;
  552. }
  553. static struct irqaction omap_wakeup_irq = {
  554. .name = "peripheral wakeup",
  555. .flags = IRQF_DISABLED,
  556. .handler = omap_wakeup_interrupt
  557. };
  558. static struct platform_suspend_ops omap_pm_ops ={
  559. .prepare = omap_pm_prepare,
  560. .enter = omap_pm_enter,
  561. .finish = omap_pm_finish,
  562. .valid = suspend_valid_only_mem,
  563. };
  564. static int __init omap_pm_init(void)
  565. {
  566. #ifdef CONFIG_OMAP_32K_TIMER
  567. int error;
  568. #endif
  569. printk("Power Management for TI OMAP.\n");
  570. /*
  571. * We copy the assembler sleep/wakeup routines to SRAM.
  572. * These routines need to be in SRAM as that's the only
  573. * memory the MPU can see when it wakes up.
  574. */
  575. if (cpu_is_omap730()) {
  576. omap_sram_suspend = omap_sram_push(omap730_cpu_suspend,
  577. omap730_cpu_suspend_sz);
  578. } else if (cpu_is_omap15xx()) {
  579. omap_sram_suspend = omap_sram_push(omap1510_cpu_suspend,
  580. omap1510_cpu_suspend_sz);
  581. } else if (cpu_is_omap16xx()) {
  582. omap_sram_suspend = omap_sram_push(omap1610_cpu_suspend,
  583. omap1610_cpu_suspend_sz);
  584. }
  585. if (omap_sram_suspend == NULL) {
  586. printk(KERN_ERR "PM not initialized: Missing SRAM support\n");
  587. return -ENODEV;
  588. }
  589. pm_idle = omap_pm_idle;
  590. if (cpu_is_omap730())
  591. setup_irq(INT_730_WAKE_UP_REQ, &omap_wakeup_irq);
  592. else if (cpu_is_omap16xx())
  593. setup_irq(INT_1610_WAKE_UP_REQ, &omap_wakeup_irq);
  594. /* Program new power ramp-up time
  595. * (0 for most boards since we don't lower voltage when in deep sleep)
  596. */
  597. omap_writew(ULPD_SETUP_ANALOG_CELL_3_VAL, ULPD_SETUP_ANALOG_CELL_3);
  598. /* Setup ULPD POWER_CTRL_REG - enter deep sleep whenever possible */
  599. omap_writew(ULPD_POWER_CTRL_REG_VAL, ULPD_POWER_CTRL);
  600. /* Configure IDLECT3 */
  601. if (cpu_is_omap730())
  602. omap_writel(OMAP730_IDLECT3_VAL, OMAP730_IDLECT3);
  603. else if (cpu_is_omap16xx())
  604. omap_writel(OMAP1610_IDLECT3_VAL, OMAP1610_IDLECT3);
  605. suspend_set_ops(&omap_pm_ops);
  606. #if defined(DEBUG) && defined(CONFIG_PROC_FS)
  607. omap_pm_init_proc();
  608. #endif
  609. #ifdef CONFIG_OMAP_32K_TIMER
  610. error = sysfs_create_file(power_kobj, &sleep_while_idle_attr.attr);
  611. if (error)
  612. printk(KERN_ERR "sysfs_create_file failed: %d\n", error);
  613. #endif
  614. if (cpu_is_omap16xx()) {
  615. /* configure LOW_PWR pin */
  616. omap_cfg_reg(T20_1610_LOW_PWR);
  617. }
  618. return 0;
  619. }
  620. __initcall(omap_pm_init);