pm.c 19 KB

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