pm-s3c2410.c 4.0 KB

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