pm.c 17 KB

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