pm.c 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184
  1. /*
  2. * arch/arm/mach-pnx4008/pm.c
  3. *
  4. * Power Management driver for PNX4008
  5. *
  6. * Authors: Vitaly Wool, Dmitry Chigirev <source@mvista.com>
  7. *
  8. * 2005 (c) MontaVista Software, Inc. This file is licensed under
  9. * the terms of the GNU General Public License version 2. This program
  10. * is licensed "as is" without any warranty of any kind, whether express
  11. * or implied.
  12. */
  13. #include <linux/pm.h>
  14. #include <linux/rtc.h>
  15. #include <linux/sched.h>
  16. #include <linux/proc_fs.h>
  17. #include <linux/pm.h>
  18. #include <linux/delay.h>
  19. #include <linux/clk.h>
  20. #include <asm/io.h>
  21. #include <asm/mach-types.h>
  22. #include <asm/cacheflush.h>
  23. #include <asm/arch/pm.h>
  24. #include <asm/arch/clock.h>
  25. #define SRAM_VA IO_ADDRESS(PNX4008_IRAM_BASE)
  26. static void *saved_sram;
  27. static struct clk *pll4_clk;
  28. static inline void pnx4008_standby(void)
  29. {
  30. void (*pnx4008_cpu_standby_ptr) (void);
  31. local_irq_disable();
  32. local_fiq_disable();
  33. clk_disable(pll4_clk);
  34. /*saving portion of SRAM to be used by suspend function. */
  35. memcpy(saved_sram, (void *)SRAM_VA, pnx4008_cpu_standby_sz);
  36. /*make sure SRAM copy gets physically written into SDRAM.
  37. SDRAM will be placed into self-refresh during power down */
  38. flush_cache_all();
  39. /*copy suspend function into SRAM */
  40. memcpy((void *)SRAM_VA, pnx4008_cpu_standby, pnx4008_cpu_standby_sz);
  41. /*do suspend */
  42. pnx4008_cpu_standby_ptr = (void *)SRAM_VA;
  43. pnx4008_cpu_standby_ptr();
  44. /*restoring portion of SRAM that was used by suspend function */
  45. memcpy((void *)SRAM_VA, saved_sram, pnx4008_cpu_standby_sz);
  46. clk_enable(pll4_clk);
  47. local_fiq_enable();
  48. local_irq_enable();
  49. }
  50. static inline void pnx4008_suspend(void)
  51. {
  52. void (*pnx4008_cpu_suspend_ptr) (void);
  53. local_irq_disable();
  54. local_fiq_disable();
  55. clk_disable(pll4_clk);
  56. __raw_writel(0xffffffff, START_INT_RSR_REG(SE_PIN_BASE_INT));
  57. __raw_writel(0xffffffff, START_INT_RSR_REG(SE_INT_BASE_INT));
  58. /*saving portion of SRAM to be used by suspend function. */
  59. memcpy(saved_sram, (void *)SRAM_VA, pnx4008_cpu_suspend_sz);
  60. /*make sure SRAM copy gets physically written into SDRAM.
  61. SDRAM will be placed into self-refresh during power down */
  62. flush_cache_all();
  63. /*copy suspend function into SRAM */
  64. memcpy((void *)SRAM_VA, pnx4008_cpu_suspend, pnx4008_cpu_suspend_sz);
  65. /*do suspend */
  66. pnx4008_cpu_suspend_ptr = (void *)SRAM_VA;
  67. pnx4008_cpu_suspend_ptr();
  68. /*restoring portion of SRAM that was used by suspend function */
  69. memcpy((void *)SRAM_VA, saved_sram, pnx4008_cpu_suspend_sz);
  70. clk_enable(pll4_clk);
  71. local_fiq_enable();
  72. local_irq_enable();
  73. }
  74. static int pnx4008_pm_enter(suspend_state_t state)
  75. {
  76. switch (state) {
  77. case PM_SUSPEND_STANDBY:
  78. pnx4008_standby();
  79. break;
  80. case PM_SUSPEND_MEM:
  81. pnx4008_suspend();
  82. break;
  83. case PM_SUSPEND_DISK:
  84. return -ENOTSUPP;
  85. default:
  86. return -EINVAL;
  87. }
  88. return 0;
  89. }
  90. /*
  91. * Called after processes are frozen, but before we shut down devices.
  92. */
  93. static int pnx4008_pm_prepare(suspend_state_t state)
  94. {
  95. switch (state) {
  96. case PM_SUSPEND_STANDBY:
  97. case PM_SUSPEND_MEM:
  98. break;
  99. case PM_SUSPEND_DISK:
  100. return -ENOTSUPP;
  101. break;
  102. default:
  103. return -EINVAL;
  104. break;
  105. }
  106. return 0;
  107. }
  108. /*
  109. * Called after devices are re-setup, but before processes are thawed.
  110. */
  111. static int pnx4008_pm_finish(suspend_state_t state)
  112. {
  113. return 0;
  114. }
  115. /*
  116. * Set to PM_DISK_FIRMWARE so we can quickly veto suspend-to-disk.
  117. */
  118. static struct pm_ops pnx4008_pm_ops = {
  119. .prepare = pnx4008_pm_prepare,
  120. .enter = pnx4008_pm_enter,
  121. .finish = pnx4008_pm_finish,
  122. };
  123. static int __init pnx4008_pm_init(void)
  124. {
  125. u32 sram_size_to_allocate;
  126. pll4_clk = clk_get(0, "ck_pll4");
  127. if (IS_ERR(pll4_clk)) {
  128. printk(KERN_ERR
  129. "PM Suspend cannot acquire ARM(PLL4) clock control\n");
  130. return PTR_ERR(pll4_clk);
  131. }
  132. if (pnx4008_cpu_standby_sz > pnx4008_cpu_suspend_sz)
  133. sram_size_to_allocate = pnx4008_cpu_standby_sz;
  134. else
  135. sram_size_to_allocate = pnx4008_cpu_suspend_sz;
  136. saved_sram = kmalloc(sram_size_to_allocate, GFP_ATOMIC);
  137. if (!saved_sram) {
  138. printk(KERN_ERR
  139. "PM Suspend: cannot allocate memory to save portion of SRAM\n");
  140. clk_put(pll4_clk);
  141. return -ENOMEM;
  142. }
  143. pm_set_ops(&pnx4008_pm_ops);
  144. return 0;
  145. }
  146. late_initcall(pnx4008_pm_init);