pm.c 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167
  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. /*
  74. * Ensure not to come back here if it wasn't intended
  75. */
  76. PSPR = 0;
  77. /*
  78. * Ensure interrupt sources are disabled; we will re-init
  79. * the interrupt subsystem via the device manager.
  80. */
  81. ICLR = 0;
  82. ICCR = 1;
  83. ICMR = 0;
  84. /* restore registers */
  85. RESTORE(GPDR);
  86. RESTORE(GAFR);
  87. RESTORE(PPDR);
  88. RESTORE(PPSR);
  89. RESTORE(PPAR);
  90. RESTORE(PSDR);
  91. RESTORE(Ser1SDCR0);
  92. GPSR = gpio;
  93. GPCR = ~gpio;
  94. /*
  95. * Clear the peripheral sleep-hold bit.
  96. */
  97. PSSR = PSSR_PH;
  98. /* restore current time */
  99. rtc.tv_sec = RCNR;
  100. restore_time_delta(&delta, &rtc);
  101. return 0;
  102. }
  103. unsigned long sleep_phys_sp(void *sp)
  104. {
  105. return virt_to_phys(sp);
  106. }
  107. /*
  108. * Called after processes are frozen, but before we shut down devices.
  109. */
  110. static int sa11x0_pm_prepare(suspend_state_t state)
  111. {
  112. return 0;
  113. }
  114. /*
  115. * Called after devices are re-setup, but before processes are thawed.
  116. */
  117. static int sa11x0_pm_finish(suspend_state_t state)
  118. {
  119. return 0;
  120. }
  121. /*
  122. * Set to PM_DISK_FIRMWARE so we can quickly veto suspend-to-disk.
  123. */
  124. static struct pm_ops sa11x0_pm_ops = {
  125. .pm_disk_mode = PM_DISK_FIRMWARE,
  126. .prepare = sa11x0_pm_prepare,
  127. .enter = sa11x0_pm_enter,
  128. .finish = sa11x0_pm_finish,
  129. };
  130. static int __init sa11x0_pm_init(void)
  131. {
  132. pm_set_ops(&sa11x0_pm_ops);
  133. return 0;
  134. }
  135. late_initcall(sa11x0_pm_init);