pm.c 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153
  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. }
  84. return 0;
  85. }
  86. static int pnx4008_pm_valid(suspend_state_t state)
  87. {
  88. return (state == PM_SUSPEND_STANDBY) ||
  89. (state == PM_SUSPEND_MEM);
  90. }
  91. static struct pm_ops pnx4008_pm_ops = {
  92. .enter = pnx4008_pm_enter,
  93. .valid = pnx4008_pm_valid,
  94. };
  95. static int __init pnx4008_pm_init(void)
  96. {
  97. u32 sram_size_to_allocate;
  98. pll4_clk = clk_get(0, "ck_pll4");
  99. if (IS_ERR(pll4_clk)) {
  100. printk(KERN_ERR
  101. "PM Suspend cannot acquire ARM(PLL4) clock control\n");
  102. return PTR_ERR(pll4_clk);
  103. }
  104. if (pnx4008_cpu_standby_sz > pnx4008_cpu_suspend_sz)
  105. sram_size_to_allocate = pnx4008_cpu_standby_sz;
  106. else
  107. sram_size_to_allocate = pnx4008_cpu_suspend_sz;
  108. saved_sram = kmalloc(sram_size_to_allocate, GFP_ATOMIC);
  109. if (!saved_sram) {
  110. printk(KERN_ERR
  111. "PM Suspend: cannot allocate memory to save portion of SRAM\n");
  112. clk_put(pll4_clk);
  113. return -ENOMEM;
  114. }
  115. pm_set_ops(&pnx4008_pm_ops);
  116. return 0;
  117. }
  118. late_initcall(pnx4008_pm_init);