pm.c 19 KB

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