pm.c 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169
  1. /*
  2. * SA1100 Power Management Routines
  3. *
  4. * Copyright (c) 2001 Cliff Brake <cbrake@accelent.com>
  5. *
  6. * This program is free software; you can redistribute it and/or
  7. * modify it under the terms of the GNU General Public License.
  8. *
  9. * History:
  10. *
  11. * 2001-02-06: Cliff Brake Initial code
  12. *
  13. * 2001-02-25: Sukjae Cho <sjcho@east.isi.edu> &
  14. * Chester Kuo <chester@linux.org.tw>
  15. * Save more value for the resume function! Support
  16. * Bitsy/Assabet/Freebird board
  17. *
  18. * 2001-08-29: Nicolas Pitre <nico@cam.org>
  19. * Cleaned up, pushed platform dependent stuff
  20. * in the platform specific files.
  21. *
  22. * 2002-05-27: Nicolas Pitre Killed sleep.h and the kmalloced save array.
  23. * Storage is local on the stack now.
  24. */
  25. #include <linux/init.h>
  26. #include <linux/suspend.h>
  27. #include <linux/errno.h>
  28. #include <linux/time.h>
  29. #include <asm/hardware.h>
  30. #include <asm/memory.h>
  31. #include <asm/system.h>
  32. #include <asm/mach/time.h>
  33. extern void sa1100_cpu_suspend(void);
  34. extern void sa1100_cpu_resume(void);
  35. #define SAVE(x) sleep_save[SLEEP_SAVE_##x] = x
  36. #define RESTORE(x) x = sleep_save[SLEEP_SAVE_##x]
  37. /*
  38. * List of global SA11x0 peripheral registers to preserve.
  39. * More ones like CP and general purpose register values are preserved
  40. * on the stack and then the stack pointer is stored last in sleep.S.
  41. */
  42. enum { SLEEP_SAVE_SP = 0,
  43. SLEEP_SAVE_GPDR, SLEEP_SAVE_GAFR,
  44. SLEEP_SAVE_PPDR, SLEEP_SAVE_PPSR, SLEEP_SAVE_PPAR, SLEEP_SAVE_PSDR,
  45. SLEEP_SAVE_Ser1SDCR0,
  46. SLEEP_SAVE_SIZE
  47. };
  48. static int sa11x0_pm_enter(suspend_state_t state)
  49. {
  50. unsigned long gpio, sleep_save[SLEEP_SAVE_SIZE];
  51. struct timespec delta, rtc;
  52. if (state != PM_SUSPEND_MEM)
  53. return -EINVAL;
  54. /* preserve current time */
  55. rtc.tv_sec = RCNR;
  56. rtc.tv_nsec = 0;
  57. save_time_delta(&delta, &rtc);
  58. gpio = GPLR;
  59. /* save vital registers */
  60. SAVE(GPDR);
  61. SAVE(GAFR);
  62. SAVE(PPDR);
  63. SAVE(PPSR);
  64. SAVE(PPAR);
  65. SAVE(PSDR);
  66. SAVE(Ser1SDCR0);
  67. /* Clear previous reset status */
  68. RCSR = RCSR_HWR | RCSR_SWR | RCSR_WDR | RCSR_SMR;
  69. /* set resume return address */
  70. PSPR = virt_to_phys(sa1100_cpu_resume);
  71. /* go zzz */
  72. sa1100_cpu_suspend();
  73. cpu_init();
  74. /*
  75. * Ensure not to come back here if it wasn't intended
  76. */
  77. PSPR = 0;
  78. /*
  79. * Ensure interrupt sources are disabled; we will re-init
  80. * the interrupt subsystem via the device manager.
  81. */
  82. ICLR = 0;
  83. ICCR = 1;
  84. ICMR = 0;
  85. /* restore registers */
  86. RESTORE(GPDR);
  87. RESTORE(GAFR);
  88. RESTORE(PPDR);
  89. RESTORE(PPSR);
  90. RESTORE(PPAR);
  91. RESTORE(PSDR);
  92. RESTORE(Ser1SDCR0);
  93. GPSR = gpio;
  94. GPCR = ~gpio;
  95. /*
  96. * Clear the peripheral sleep-hold bit.
  97. */
  98. PSSR = PSSR_PH;
  99. /* restore current time */
  100. rtc.tv_sec = RCNR;
  101. restore_time_delta(&delta, &rtc);
  102. return 0;
  103. }
  104. unsigned long sleep_phys_sp(void *sp)
  105. {
  106. return virt_to_phys(sp);
  107. }
  108. /*
  109. * Called after processes are frozen, but before we shut down devices.
  110. */
  111. static int sa11x0_pm_prepare(suspend_state_t state)
  112. {
  113. return 0;
  114. }
  115. /*
  116. * Called after devices are re-setup, but before processes are thawed.
  117. */
  118. static int sa11x0_pm_finish(suspend_state_t state)
  119. {
  120. return 0;
  121. }
  122. /*
  123. * Set to PM_DISK_FIRMWARE so we can quickly veto suspend-to-disk.
  124. */
  125. static struct pm_ops sa11x0_pm_ops = {
  126. .pm_disk_mode = PM_DISK_FIRMWARE,
  127. .prepare = sa11x0_pm_prepare,
  128. .enter = sa11x0_pm_enter,
  129. .finish = sa11x0_pm_finish,
  130. };
  131. static int __init sa11x0_pm_init(void)
  132. {
  133. pm_set_ops(&sa11x0_pm_ops);
  134. return 0;
  135. }
  136. late_initcall(sa11x0_pm_init);