pm.c 5.3 KB

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