pm.c 20 KB

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