pm.c 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156
  1. /* linux/arch/arm/mach-s3c2410/pm.c
  2. *
  3. * Copyright (c) 2006 Simtec Electronics
  4. * Ben Dooks <ben@simtec.co.uk>
  5. *
  6. * S3C2410 (and compatible) Power Manager (Suspend-To-RAM) support
  7. *
  8. * This program is free software; you can redistribute it and/or modify
  9. * it under the terms of the GNU General Public License as published by
  10. * the Free Software Foundation; either version 2 of the License, or
  11. * (at your option) any later version.
  12. *
  13. * This program is distributed in the hope that it will be useful,
  14. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  15. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  16. * GNU General Public License for more details.
  17. *
  18. * You should have received a copy of the GNU General Public License
  19. * along with this program; if not, write to the Free Software
  20. * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
  21. */
  22. #include <linux/init.h>
  23. #include <linux/suspend.h>
  24. #include <linux/errno.h>
  25. #include <linux/time.h>
  26. #include <linux/sysdev.h>
  27. #include <asm/hardware.h>
  28. #include <asm/io.h>
  29. #include <asm/mach-types.h>
  30. #include <asm/arch/regs-gpio.h>
  31. #include <asm/arch/h1940.h>
  32. #include <asm/plat-s3c24xx/cpu.h>
  33. #include <asm/plat-s3c24xx/pm.h>
  34. #ifdef CONFIG_S3C2410_PM_DEBUG
  35. extern void pm_dbg(const char *fmt, ...);
  36. #define DBG(fmt...) pm_dbg(fmt)
  37. #else
  38. #define DBG(fmt...) printk(KERN_DEBUG fmt)
  39. #endif
  40. static void s3c2410_pm_prepare(void)
  41. {
  42. /* ensure at least GSTATUS3 has the resume address */
  43. __raw_writel(virt_to_phys(s3c2410_cpu_resume), S3C2410_GSTATUS3);
  44. DBG("GSTATUS3 0x%08x\n", __raw_readl(S3C2410_GSTATUS3));
  45. DBG("GSTATUS4 0x%08x\n", __raw_readl(S3C2410_GSTATUS4));
  46. if (machine_is_h1940()) {
  47. void *base = phys_to_virt(H1940_SUSPEND_CHECK);
  48. unsigned long ptr;
  49. unsigned long calc = 0;
  50. /* generate check for the bootloader to check on resume */
  51. for (ptr = 0; ptr < 0x40000; ptr += 0x400)
  52. calc += __raw_readl(base+ptr);
  53. __raw_writel(calc, phys_to_virt(H1940_SUSPEND_CHECKSUM));
  54. }
  55. /* the RX3715 uses similar code and the same H1940 and the
  56. * same offsets for resume and checksum pointers */
  57. if (machine_is_rx3715()) {
  58. void *base = phys_to_virt(H1940_SUSPEND_CHECK);
  59. unsigned long ptr;
  60. unsigned long calc = 0;
  61. /* generate check for the bootloader to check on resume */
  62. for (ptr = 0; ptr < 0x40000; ptr += 0x4)
  63. calc += __raw_readl(base+ptr);
  64. __raw_writel(calc, phys_to_virt(H1940_SUSPEND_CHECKSUM));
  65. }
  66. if ( machine_is_aml_m5900() )
  67. s3c2410_gpio_setpin(S3C2410_GPF2, 1);
  68. }
  69. static int s3c2410_pm_resume(struct sys_device *dev)
  70. {
  71. unsigned long tmp;
  72. /* unset the return-from-sleep flag, to ensure reset */
  73. tmp = __raw_readl(S3C2410_GSTATUS2);
  74. tmp &= S3C2410_GSTATUS2_OFFRESET;
  75. __raw_writel(tmp, S3C2410_GSTATUS2);
  76. if ( machine_is_aml_m5900() )
  77. s3c2410_gpio_setpin(S3C2410_GPF2, 0);
  78. return 0;
  79. }
  80. static int s3c2410_pm_add(struct sys_device *dev)
  81. {
  82. pm_cpu_prep = s3c2410_pm_prepare;
  83. pm_cpu_sleep = s3c2410_cpu_suspend;
  84. return 0;
  85. }
  86. #if defined(CONFIG_CPU_S3C2410)
  87. static struct sysdev_driver s3c2410_pm_driver = {
  88. .add = s3c2410_pm_add,
  89. .resume = s3c2410_pm_resume,
  90. };
  91. /* register ourselves */
  92. static int __init s3c2410_pm_drvinit(void)
  93. {
  94. return sysdev_driver_register(&s3c2410_sysclass, &s3c2410_pm_driver);
  95. }
  96. arch_initcall(s3c2410_pm_drvinit);
  97. #endif
  98. #if defined(CONFIG_CPU_S3C2440)
  99. static struct sysdev_driver s3c2440_pm_driver = {
  100. .add = s3c2410_pm_add,
  101. .resume = s3c2410_pm_resume,
  102. };
  103. static int __init s3c2440_pm_drvinit(void)
  104. {
  105. return sysdev_driver_register(&s3c2440_sysclass, &s3c2440_pm_driver);
  106. }
  107. arch_initcall(s3c2440_pm_drvinit);
  108. #endif
  109. #if defined(CONFIG_CPU_S3C2442)
  110. static struct sysdev_driver s3c2442_pm_driver = {
  111. .add = s3c2410_pm_add,
  112. .resume = s3c2410_pm_resume,
  113. };
  114. static int __init s3c2442_pm_drvinit(void)
  115. {
  116. return sysdev_driver_register(&s3c2442_sysclass, &s3c2442_pm_driver);
  117. }
  118. arch_initcall(s3c2442_pm_drvinit);
  119. #endif