pm-s3c2410.c 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171
  1. // SPDX-License-Identifier: GPL-2.0+
  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. #include <linux/init.h>
  8. #include <linux/suspend.h>
  9. #include <linux/errno.h>
  10. #include <linux/time.h>
  11. #include <linux/device.h>
  12. #include <linux/syscore_ops.h>
  13. #include <linux/gpio.h>
  14. #include <linux/io.h>
  15. #include <asm/mach-types.h>
  16. #include <mach/hardware.h>
  17. #include <mach/regs-gpio.h>
  18. #include <mach/gpio-samsung.h>
  19. #include <plat/gpio-cfg.h>
  20. #include <plat/cpu.h>
  21. #include <plat/pm.h>
  22. #include "h1940.h"
  23. static void s3c2410_pm_prepare(void)
  24. {
  25. /* ensure at least GSTATUS3 has the resume address */
  26. __raw_writel(__pa_symbol(s3c_cpu_resume), S3C2410_GSTATUS3);
  27. S3C_PMDBG("GSTATUS3 0x%08x\n", __raw_readl(S3C2410_GSTATUS3));
  28. S3C_PMDBG("GSTATUS4 0x%08x\n", __raw_readl(S3C2410_GSTATUS4));
  29. if (machine_is_h1940()) {
  30. void *base = phys_to_virt(H1940_SUSPEND_CHECK);
  31. unsigned long ptr;
  32. unsigned long calc = 0;
  33. /* generate check for the bootloader to check on resume */
  34. for (ptr = 0; ptr < 0x40000; ptr += 0x400)
  35. calc += __raw_readl(base+ptr);
  36. __raw_writel(calc, phys_to_virt(H1940_SUSPEND_CHECKSUM));
  37. }
  38. /* RX3715 and RX1950 use similar to H1940 code and the
  39. * same offsets for resume and checksum pointers */
  40. if (machine_is_rx3715() || machine_is_rx1950()) {
  41. void *base = phys_to_virt(H1940_SUSPEND_CHECK);
  42. unsigned long ptr;
  43. unsigned long calc = 0;
  44. /* generate check for the bootloader to check on resume */
  45. for (ptr = 0; ptr < 0x40000; ptr += 0x4)
  46. calc += __raw_readl(base+ptr);
  47. __raw_writel(calc, phys_to_virt(H1940_SUSPEND_CHECKSUM));
  48. }
  49. if (machine_is_aml_m5900()) {
  50. gpio_request_one(S3C2410_GPF(2), GPIOF_OUT_INIT_HIGH, NULL);
  51. gpio_free(S3C2410_GPF(2));
  52. }
  53. if (machine_is_rx1950()) {
  54. /* According to S3C2442 user's manual, page 7-17,
  55. * when the system is operating in NAND boot mode,
  56. * the hardware pin configuration - EINT[23:21] –
  57. * must be set as input for starting up after
  58. * wakeup from sleep mode
  59. */
  60. s3c_gpio_cfgpin(S3C2410_GPG(13), S3C2410_GPIO_INPUT);
  61. s3c_gpio_cfgpin(S3C2410_GPG(14), S3C2410_GPIO_INPUT);
  62. s3c_gpio_cfgpin(S3C2410_GPG(15), S3C2410_GPIO_INPUT);
  63. }
  64. }
  65. static void s3c2410_pm_resume(void)
  66. {
  67. unsigned long tmp;
  68. /* unset the return-from-sleep flag, to ensure reset */
  69. tmp = __raw_readl(S3C2410_GSTATUS2);
  70. tmp &= S3C2410_GSTATUS2_OFFRESET;
  71. __raw_writel(tmp, S3C2410_GSTATUS2);
  72. if (machine_is_aml_m5900()) {
  73. gpio_request_one(S3C2410_GPF(2), GPIOF_OUT_INIT_LOW, NULL);
  74. gpio_free(S3C2410_GPF(2));
  75. }
  76. }
  77. struct syscore_ops s3c2410_pm_syscore_ops = {
  78. .resume = s3c2410_pm_resume,
  79. };
  80. static int s3c2410_pm_add(struct device *dev, struct subsys_interface *sif)
  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 subsys_interface s3c2410_pm_interface = {
  88. .name = "s3c2410_pm",
  89. .subsys = &s3c2410_subsys,
  90. .add_dev = s3c2410_pm_add,
  91. };
  92. /* register ourselves */
  93. static int __init s3c2410_pm_drvinit(void)
  94. {
  95. return subsys_interface_register(&s3c2410_pm_interface);
  96. }
  97. arch_initcall(s3c2410_pm_drvinit);
  98. static struct subsys_interface s3c2410a_pm_interface = {
  99. .name = "s3c2410a_pm",
  100. .subsys = &s3c2410a_subsys,
  101. .add_dev = s3c2410_pm_add,
  102. };
  103. static int __init s3c2410a_pm_drvinit(void)
  104. {
  105. return subsys_interface_register(&s3c2410a_pm_interface);
  106. }
  107. arch_initcall(s3c2410a_pm_drvinit);
  108. #endif
  109. #if defined(CONFIG_CPU_S3C2440)
  110. static struct subsys_interface s3c2440_pm_interface = {
  111. .name = "s3c2440_pm",
  112. .subsys = &s3c2440_subsys,
  113. .add_dev = s3c2410_pm_add,
  114. };
  115. static int __init s3c2440_pm_drvinit(void)
  116. {
  117. return subsys_interface_register(&s3c2440_pm_interface);
  118. }
  119. arch_initcall(s3c2440_pm_drvinit);
  120. #endif
  121. #if defined(CONFIG_CPU_S3C2442)
  122. static struct subsys_interface s3c2442_pm_interface = {
  123. .name = "s3c2442_pm",
  124. .subsys = &s3c2442_subsys,
  125. .add_dev = s3c2410_pm_add,
  126. };
  127. static int __init s3c2442_pm_drvinit(void)
  128. {
  129. return subsys_interface_register(&s3c2442_pm_interface);
  130. }
  131. arch_initcall(s3c2442_pm_drvinit);
  132. #endif