pm.c 5.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242
  1. /*
  2. * PXA250/210 Power Management Routines
  3. *
  4. * Original code for the SA11x0:
  5. * Copyright (c) 2001 Cliff Brake <cbrake@accelent.com>
  6. *
  7. * Modified for the PXA250 by Nicolas Pitre:
  8. * Copyright (c) 2002 Monta Vista Software, Inc.
  9. *
  10. * This program is free software; you can redistribute it and/or
  11. * modify it under the terms of the GNU General Public License.
  12. */
  13. #include <linux/init.h>
  14. #include <linux/module.h>
  15. #include <linux/suspend.h>
  16. #include <linux/errno.h>
  17. #include <linux/time.h>
  18. #include <asm/hardware.h>
  19. #include <asm/memory.h>
  20. #include <asm/system.h>
  21. #include <asm/arch/pm.h>
  22. #include <asm/arch/pxa-regs.h>
  23. #include <asm/arch/lubbock.h>
  24. #include <asm/mach/time.h>
  25. /*
  26. * Debug macros
  27. */
  28. #undef DEBUG
  29. #define SAVE(x) sleep_save[SLEEP_SAVE_##x] = x
  30. #define RESTORE(x) x = sleep_save[SLEEP_SAVE_##x]
  31. #define RESTORE_GPLEVEL(n) do { \
  32. GPSR##n = sleep_save[SLEEP_SAVE_GPLR##n]; \
  33. GPCR##n = ~sleep_save[SLEEP_SAVE_GPLR##n]; \
  34. } while (0)
  35. /*
  36. * List of global PXA peripheral registers to preserve.
  37. * More ones like CP and general purpose register values are preserved
  38. * with the stack pointer in sleep.S.
  39. */
  40. enum { SLEEP_SAVE_START = 0,
  41. SLEEP_SAVE_GPLR0, SLEEP_SAVE_GPLR1, SLEEP_SAVE_GPLR2, SLEEP_SAVE_GPLR3,
  42. SLEEP_SAVE_GPDR0, SLEEP_SAVE_GPDR1, SLEEP_SAVE_GPDR2, SLEEP_SAVE_GPDR3,
  43. SLEEP_SAVE_GRER0, SLEEP_SAVE_GRER1, SLEEP_SAVE_GRER2, SLEEP_SAVE_GRER3,
  44. SLEEP_SAVE_GFER0, SLEEP_SAVE_GFER1, SLEEP_SAVE_GFER2, SLEEP_SAVE_GFER3,
  45. SLEEP_SAVE_PGSR0, SLEEP_SAVE_PGSR1, SLEEP_SAVE_PGSR2, SLEEP_SAVE_PGSR3,
  46. SLEEP_SAVE_GAFR0_L, SLEEP_SAVE_GAFR0_U,
  47. SLEEP_SAVE_GAFR1_L, SLEEP_SAVE_GAFR1_U,
  48. SLEEP_SAVE_GAFR2_L, SLEEP_SAVE_GAFR2_U,
  49. SLEEP_SAVE_GAFR3_L, SLEEP_SAVE_GAFR3_U,
  50. SLEEP_SAVE_PSTR,
  51. SLEEP_SAVE_ICMR,
  52. SLEEP_SAVE_CKEN,
  53. #ifdef CONFIG_PXA27x
  54. SLEEP_SAVE_MDREFR,
  55. SLEEP_SAVE_PWER, SLEEP_SAVE_PCFR, SLEEP_SAVE_PRER,
  56. SLEEP_SAVE_PFER, SLEEP_SAVE_PKWR,
  57. #endif
  58. SLEEP_SAVE_CKSUM,
  59. SLEEP_SAVE_SIZE
  60. };
  61. int pxa_pm_enter(suspend_state_t state)
  62. {
  63. unsigned long sleep_save[SLEEP_SAVE_SIZE];
  64. unsigned long checksum = 0;
  65. struct timespec delta, rtc;
  66. int i;
  67. extern void pxa_cpu_pm_enter(suspend_state_t state);
  68. #ifdef CONFIG_IWMMXT
  69. /* force any iWMMXt context to ram **/
  70. if (elf_hwcap & HWCAP_IWMMXT)
  71. iwmmxt_task_disable(NULL);
  72. #endif
  73. /* preserve current time */
  74. rtc.tv_sec = RCNR;
  75. rtc.tv_nsec = 0;
  76. save_time_delta(&delta, &rtc);
  77. SAVE(GPLR0); SAVE(GPLR1); SAVE(GPLR2);
  78. SAVE(GPDR0); SAVE(GPDR1); SAVE(GPDR2);
  79. SAVE(GRER0); SAVE(GRER1); SAVE(GRER2);
  80. SAVE(GFER0); SAVE(GFER1); SAVE(GFER2);
  81. SAVE(PGSR0); SAVE(PGSR1); SAVE(PGSR2);
  82. SAVE(GAFR0_L); SAVE(GAFR0_U);
  83. SAVE(GAFR1_L); SAVE(GAFR1_U);
  84. SAVE(GAFR2_L); SAVE(GAFR2_U);
  85. #ifdef CONFIG_PXA27x
  86. SAVE(MDREFR);
  87. SAVE(GPLR3); SAVE(GPDR3); SAVE(GRER3); SAVE(GFER3); SAVE(PGSR3);
  88. SAVE(GAFR3_L); SAVE(GAFR3_U);
  89. SAVE(PWER); SAVE(PCFR); SAVE(PRER);
  90. SAVE(PFER); SAVE(PKWR);
  91. #endif
  92. SAVE(ICMR);
  93. ICMR = 0;
  94. SAVE(CKEN);
  95. SAVE(PSTR);
  96. /* Note: wake up source are set up in each machine specific files */
  97. /* clear GPIO transition detect bits */
  98. GEDR0 = GEDR0; GEDR1 = GEDR1; GEDR2 = GEDR2;
  99. #ifdef CONFIG_PXA27x
  100. GEDR3 = GEDR3;
  101. #endif
  102. /* Clear sleep reset status */
  103. RCSR = RCSR_SMR;
  104. /* before sleeping, calculate and save a checksum */
  105. for (i = 0; i < SLEEP_SAVE_SIZE - 1; i++)
  106. checksum += sleep_save[i];
  107. sleep_save[SLEEP_SAVE_CKSUM] = checksum;
  108. /* *** go zzz *** */
  109. pxa_cpu_pm_enter(state);
  110. cpu_init();
  111. /* after sleeping, validate the checksum */
  112. checksum = 0;
  113. for (i = 0; i < SLEEP_SAVE_SIZE - 1; i++)
  114. checksum += sleep_save[i];
  115. /* if invalid, display message and wait for a hardware reset */
  116. if (checksum != sleep_save[SLEEP_SAVE_CKSUM]) {
  117. #ifdef CONFIG_ARCH_LUBBOCK
  118. LUB_HEXLED = 0xbadbadc5;
  119. #endif
  120. while (1)
  121. pxa_cpu_pm_enter(state);
  122. }
  123. /* ensure not to come back here if it wasn't intended */
  124. PSPR = 0;
  125. /* restore registers */
  126. RESTORE_GPLEVEL(0); RESTORE_GPLEVEL(1); RESTORE_GPLEVEL(2);
  127. RESTORE(GPDR0); RESTORE(GPDR1); RESTORE(GPDR2);
  128. RESTORE(GAFR0_L); RESTORE(GAFR0_U);
  129. RESTORE(GAFR1_L); RESTORE(GAFR1_U);
  130. RESTORE(GAFR2_L); RESTORE(GAFR2_U);
  131. RESTORE(GRER0); RESTORE(GRER1); RESTORE(GRER2);
  132. RESTORE(GFER0); RESTORE(GFER1); RESTORE(GFER2);
  133. RESTORE(PGSR0); RESTORE(PGSR1); RESTORE(PGSR2);
  134. #ifdef CONFIG_PXA27x
  135. RESTORE(MDREFR);
  136. RESTORE_GPLEVEL(3); RESTORE(GPDR3);
  137. RESTORE(GAFR3_L); RESTORE(GAFR3_U);
  138. RESTORE(GRER3); RESTORE(GFER3); RESTORE(PGSR3);
  139. RESTORE(PWER); RESTORE(PCFR); RESTORE(PRER);
  140. RESTORE(PFER); RESTORE(PKWR);
  141. #endif
  142. PSSR = PSSR_RDH | PSSR_PH;
  143. RESTORE(CKEN);
  144. ICLR = 0;
  145. ICCR = 1;
  146. RESTORE(ICMR);
  147. RESTORE(PSTR);
  148. /* restore current time */
  149. rtc.tv_sec = RCNR;
  150. restore_time_delta(&delta, &rtc);
  151. #ifdef DEBUG
  152. printk(KERN_DEBUG "*** made it back from resume\n");
  153. #endif
  154. return 0;
  155. }
  156. EXPORT_SYMBOL_GPL(pxa_pm_enter);
  157. unsigned long sleep_phys_sp(void *sp)
  158. {
  159. return virt_to_phys(sp);
  160. }
  161. /*
  162. * Called after processes are frozen, but before we shut down devices.
  163. */
  164. int pxa_pm_prepare(suspend_state_t state)
  165. {
  166. extern int pxa_cpu_pm_prepare(suspend_state_t state);
  167. return pxa_cpu_pm_prepare(state);
  168. }
  169. EXPORT_SYMBOL_GPL(pxa_pm_prepare);
  170. /*
  171. * Called after devices are re-setup, but before processes are thawed.
  172. */
  173. int pxa_pm_finish(suspend_state_t state)
  174. {
  175. return 0;
  176. }
  177. EXPORT_SYMBOL_GPL(pxa_pm_finish);
  178. /*
  179. * Set to PM_DISK_FIRMWARE so we can quickly veto suspend-to-disk.
  180. */
  181. static struct pm_ops pxa_pm_ops = {
  182. .pm_disk_mode = PM_DISK_FIRMWARE,
  183. .prepare = pxa_pm_prepare,
  184. .enter = pxa_pm_enter,
  185. .finish = pxa_pm_finish,
  186. };
  187. static int __init pxa_pm_init(void)
  188. {
  189. pm_set_ops(&pxa_pm_ops);
  190. return 0;
  191. }
  192. device_initcall(pxa_pm_init);