pm.c 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155
  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/suspend.h>
  18. #include <linux/delay.h>
  19. #include <linux/clk.h>
  20. #include <linux/io.h>
  21. #include <linux/slab.h>
  22. #include <asm/cacheflush.h>
  23. #include <mach/hardware.h>
  24. #include <mach/pm.h>
  25. #include <mach/clock.h>
  26. #define SRAM_VA IO_ADDRESS(PNX4008_IRAM_BASE)
  27. static void *saved_sram;
  28. static struct clk *pll4_clk;
  29. static inline void pnx4008_standby(void)
  30. {
  31. void (*pnx4008_cpu_standby_ptr) (void);
  32. local_irq_disable();
  33. local_fiq_disable();
  34. clk_disable(pll4_clk);
  35. /*saving portion of SRAM to be used by suspend function. */
  36. memcpy(saved_sram, (void *)SRAM_VA, pnx4008_cpu_standby_sz);
  37. /*make sure SRAM copy gets physically written into SDRAM.
  38. SDRAM will be placed into self-refresh during power down */
  39. flush_cache_all();
  40. /*copy suspend function into SRAM */
  41. memcpy((void *)SRAM_VA, pnx4008_cpu_standby, pnx4008_cpu_standby_sz);
  42. /*do suspend */
  43. pnx4008_cpu_standby_ptr = (void *)SRAM_VA;
  44. pnx4008_cpu_standby_ptr();
  45. /*restoring portion of SRAM that was used by suspend function */
  46. memcpy((void *)SRAM_VA, saved_sram, pnx4008_cpu_standby_sz);
  47. clk_enable(pll4_clk);
  48. local_fiq_enable();
  49. local_irq_enable();
  50. }
  51. static inline void pnx4008_suspend(void)
  52. {
  53. void (*pnx4008_cpu_suspend_ptr) (void);
  54. local_irq_disable();
  55. local_fiq_disable();
  56. clk_disable(pll4_clk);
  57. __raw_writel(0xffffffff, START_INT_RSR_REG(SE_PIN_BASE_INT));
  58. __raw_writel(0xffffffff, START_INT_RSR_REG(SE_INT_BASE_INT));
  59. /*saving portion of SRAM to be used by suspend function. */
  60. memcpy(saved_sram, (void *)SRAM_VA, pnx4008_cpu_suspend_sz);
  61. /*make sure SRAM copy gets physically written into SDRAM.
  62. SDRAM will be placed into self-refresh during power down */
  63. flush_cache_all();
  64. /*copy suspend function into SRAM */
  65. memcpy((void *)SRAM_VA, pnx4008_cpu_suspend, pnx4008_cpu_suspend_sz);
  66. /*do suspend */
  67. pnx4008_cpu_suspend_ptr = (void *)SRAM_VA;
  68. pnx4008_cpu_suspend_ptr();
  69. /*restoring portion of SRAM that was used by suspend function */
  70. memcpy((void *)SRAM_VA, saved_sram, pnx4008_cpu_suspend_sz);
  71. clk_enable(pll4_clk);
  72. local_fiq_enable();
  73. local_irq_enable();
  74. }
  75. static int pnx4008_pm_enter(suspend_state_t state)
  76. {
  77. switch (state) {
  78. case PM_SUSPEND_STANDBY:
  79. pnx4008_standby();
  80. break;
  81. case PM_SUSPEND_MEM:
  82. pnx4008_suspend();
  83. break;
  84. }
  85. return 0;
  86. }
  87. static int pnx4008_pm_valid(suspend_state_t state)
  88. {
  89. return (state == PM_SUSPEND_STANDBY) ||
  90. (state == PM_SUSPEND_MEM);
  91. }
  92. static struct platform_suspend_ops pnx4008_pm_ops = {
  93. .enter = pnx4008_pm_enter,
  94. .valid = pnx4008_pm_valid,
  95. };
  96. static int __init pnx4008_pm_init(void)
  97. {
  98. u32 sram_size_to_allocate;
  99. pll4_clk = clk_get(0, "ck_pll4");
  100. if (IS_ERR(pll4_clk)) {
  101. printk(KERN_ERR
  102. "PM Suspend cannot acquire ARM(PLL4) clock control\n");
  103. return PTR_ERR(pll4_clk);
  104. }
  105. if (pnx4008_cpu_standby_sz > pnx4008_cpu_suspend_sz)
  106. sram_size_to_allocate = pnx4008_cpu_standby_sz;
  107. else
  108. sram_size_to_allocate = pnx4008_cpu_suspend_sz;
  109. saved_sram = kmalloc(sram_size_to_allocate, GFP_ATOMIC);
  110. if (!saved_sram) {
  111. printk(KERN_ERR
  112. "PM Suspend: cannot allocate memory to save portion of SRAM\n");
  113. clk_put(pll4_clk);
  114. return -ENOMEM;
  115. }
  116. suspend_set_ops(&pnx4008_pm_ops);
  117. return 0;
  118. }
  119. late_initcall(pnx4008_pm_init);