pm.c 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148
  1. /* linux/arch/arm/plat-s3c24xx/pm.c
  2. *
  3. * Copyright (c) 2004,2006 Simtec Electronics
  4. * Ben Dooks <ben@simtec.co.uk>
  5. *
  6. * S3C24XX Power Manager (Suspend-To-RAM) support
  7. *
  8. * See Documentation/arm/Samsung-S3C24XX/Suspend.txt for more information
  9. *
  10. * This program is free software; you can redistribute it and/or modify
  11. * it under the terms of the GNU General Public License as published by
  12. * the Free Software Foundation; either version 2 of the License, or
  13. * (at your option) any later version.
  14. *
  15. * This program is distributed in the hope that it will be useful,
  16. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  17. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  18. * GNU General Public License for more details.
  19. *
  20. * You should have received a copy of the GNU General Public License
  21. * along with this program; if not, write to the Free Software
  22. * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
  23. *
  24. * Parts based on arch/arm/mach-pxa/pm.c
  25. *
  26. * Thanks to Dimitry Andric for debugging
  27. */
  28. #include <linux/init.h>
  29. #include <linux/suspend.h>
  30. #include <linux/errno.h>
  31. #include <linux/time.h>
  32. #include <linux/gpio.h>
  33. #include <linux/interrupt.h>
  34. #include <linux/serial_core.h>
  35. #include <linux/io.h>
  36. #include <plat/regs-serial.h>
  37. #include <mach/regs-clock.h>
  38. #include <mach/regs-gpio.h>
  39. #include <mach/regs-mem.h>
  40. #include <mach/regs-irq.h>
  41. #include <asm/mach/time.h>
  42. #include <plat/pm.h>
  43. #define PFX "s3c24xx-pm: "
  44. static struct sleep_save core_save[] = {
  45. SAVE_ITEM(S3C2410_LOCKTIME),
  46. SAVE_ITEM(S3C2410_CLKCON),
  47. /* we restore the timings here, with the proviso that the board
  48. * brings the system up in an slower, or equal frequency setting
  49. * to the original system.
  50. *
  51. * if we cannot guarantee this, then things are going to go very
  52. * wrong here, as we modify the refresh and both pll settings.
  53. */
  54. SAVE_ITEM(S3C2410_BWSCON),
  55. SAVE_ITEM(S3C2410_BANKCON0),
  56. SAVE_ITEM(S3C2410_BANKCON1),
  57. SAVE_ITEM(S3C2410_BANKCON2),
  58. SAVE_ITEM(S3C2410_BANKCON3),
  59. SAVE_ITEM(S3C2410_BANKCON4),
  60. SAVE_ITEM(S3C2410_BANKCON5),
  61. #ifndef CONFIG_CPU_FREQ
  62. SAVE_ITEM(S3C2410_CLKDIVN),
  63. SAVE_ITEM(S3C2410_MPLLCON),
  64. SAVE_ITEM(S3C2410_REFRESH),
  65. #endif
  66. SAVE_ITEM(S3C2410_UPLLCON),
  67. SAVE_ITEM(S3C2410_CLKSLOW),
  68. };
  69. static struct sleep_save misc_save[] = {
  70. SAVE_ITEM(S3C2410_DCLKCON),
  71. };
  72. /* s3c_pm_check_resume_pin
  73. *
  74. * check to see if the pin is configured correctly for sleep mode, and
  75. * make any necessary adjustments if it is not
  76. */
  77. static void s3c_pm_check_resume_pin(unsigned int pin, unsigned int irqoffs)
  78. {
  79. unsigned long irqstate;
  80. unsigned long pinstate;
  81. int irq = s3c2410_gpio_getirq(pin);
  82. if (irqoffs < 4)
  83. irqstate = s3c_irqwake_intmask & (1L<<irqoffs);
  84. else
  85. irqstate = s3c_irqwake_eintmask & (1L<<irqoffs);
  86. pinstate = s3c2410_gpio_getcfg(pin);
  87. if (!irqstate) {
  88. if (pinstate == S3C2410_GPIO_IRQ)
  89. S3C_PMDBG("Leaving IRQ %d (pin %d) enabled\n", irq, pin);
  90. } else {
  91. if (pinstate == S3C2410_GPIO_IRQ) {
  92. S3C_PMDBG("Disabling IRQ %d (pin %d)\n", irq, pin);
  93. s3c2410_gpio_cfgpin(pin, S3C2410_GPIO_INPUT);
  94. }
  95. }
  96. }
  97. /* s3c_pm_configure_extint
  98. *
  99. * configure all external interrupt pins
  100. */
  101. void s3c_pm_configure_extint(void)
  102. {
  103. int pin;
  104. /* for each of the external interrupts (EINT0..EINT15) we
  105. * need to check wether it is an external interrupt source,
  106. * and then configure it as an input if it is not
  107. */
  108. for (pin = S3C2410_GPF(0); pin <= S3C2410_GPF(7); pin++) {
  109. s3c_pm_check_resume_pin(pin, pin - S3C2410_GPF(0));
  110. }
  111. for (pin = S3C2410_GPG(0); pin <= S3C2410_GPG(7); pin++) {
  112. s3c_pm_check_resume_pin(pin, (pin - S3C2410_GPG(0))+8);
  113. }
  114. }
  115. void s3c_pm_restore_core(void)
  116. {
  117. s3c_pm_do_restore_core(core_save, ARRAY_SIZE(core_save));
  118. s3c_pm_do_restore(misc_save, ARRAY_SIZE(misc_save));
  119. }
  120. void s3c_pm_save_core(void)
  121. {
  122. s3c_pm_do_save(misc_save, ARRAY_SIZE(misc_save));
  123. s3c_pm_do_save(core_save, ARRAY_SIZE(core_save));
  124. }