pm.c 3.6 KB

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