pm.c 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228
  1. /* linux/arch/arm/plat-s3c/pm.c
  2. *
  3. * Copyright 2008 Openmoko, Inc.
  4. * Copyright 2004-2008 Simtec Electronics
  5. * Ben Dooks <ben@simtec.co.uk>
  6. * http://armlinux.simtec.co.uk/
  7. *
  8. * S3C common power management (suspend to ram) support.
  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 version 2 as
  12. * published by the Free Software Foundation.
  13. */
  14. #include <linux/init.h>
  15. #include <linux/suspend.h>
  16. #include <linux/errno.h>
  17. #include <linux/delay.h>
  18. #include <linux/of.h>
  19. #include <linux/serial_s3c.h>
  20. #include <linux/io.h>
  21. #include <asm/cacheflush.h>
  22. #include <asm/suspend.h>
  23. #ifdef CONFIG_SAMSUNG_ATAGS
  24. #include <mach/map.h>
  25. #ifndef CONFIG_ARCH_EXYNOS
  26. #include <mach/regs-clock.h>
  27. #include <mach/regs-irq.h>
  28. #endif
  29. #include <mach/irqs.h>
  30. #endif
  31. #include <asm/irq.h>
  32. #include <plat/pm.h>
  33. #include <mach/pm-core.h>
  34. /* for external use */
  35. unsigned long s3c_pm_flags;
  36. /* The IRQ ext-int code goes here, it is too small to currently bother
  37. * with its own file. */
  38. unsigned long s3c_irqwake_intmask = 0xffffffffL;
  39. unsigned long s3c_irqwake_eintmask = 0xffffffffL;
  40. int s3c_irqext_wake(struct irq_data *data, unsigned int state)
  41. {
  42. unsigned long bit = 1L << IRQ_EINT_BIT(data->irq);
  43. if (!(s3c_irqwake_eintallow & bit))
  44. return -ENOENT;
  45. printk(KERN_INFO "wake %s for irq %d\n",
  46. state ? "enabled" : "disabled", data->irq);
  47. if (!state)
  48. s3c_irqwake_eintmask |= bit;
  49. else
  50. s3c_irqwake_eintmask &= ~bit;
  51. return 0;
  52. }
  53. /* s3c2410_pm_show_resume_irqs
  54. *
  55. * print any IRQs asserted at resume time (ie, we woke from)
  56. */
  57. static void __maybe_unused s3c_pm_show_resume_irqs(int start,
  58. unsigned long which,
  59. unsigned long mask)
  60. {
  61. int i;
  62. which &= ~mask;
  63. for (i = 0; i <= 31; i++) {
  64. if (which & (1L<<i)) {
  65. S3C_PMDBG("IRQ %d asserted at resume\n", start+i);
  66. }
  67. }
  68. }
  69. void (*pm_cpu_prep)(void);
  70. int (*pm_cpu_sleep)(unsigned long);
  71. #define any_allowed(mask, allow) (((mask) & (allow)) != (allow))
  72. /* s3c_pm_enter
  73. *
  74. * central control for sleep/resume process
  75. */
  76. static int s3c_pm_enter(suspend_state_t state)
  77. {
  78. int ret;
  79. /* ensure the debug is initialised (if enabled) */
  80. s3c_pm_debug_init();
  81. S3C_PMDBG("%s(%d)\n", __func__, state);
  82. if (pm_cpu_prep == NULL || pm_cpu_sleep == NULL) {
  83. printk(KERN_ERR "%s: error: no cpu sleep function\n", __func__);
  84. return -EINVAL;
  85. }
  86. /* check if we have anything to wake-up with... bad things seem
  87. * to happen if you suspend with no wakeup (system will often
  88. * require a full power-cycle)
  89. */
  90. if (!of_have_populated_dt() &&
  91. !any_allowed(s3c_irqwake_intmask, s3c_irqwake_intallow) &&
  92. !any_allowed(s3c_irqwake_eintmask, s3c_irqwake_eintallow)) {
  93. printk(KERN_ERR "%s: No wake-up sources!\n", __func__);
  94. printk(KERN_ERR "%s: Aborting sleep\n", __func__);
  95. return -EINVAL;
  96. }
  97. /* save all necessary core registers not covered by the drivers */
  98. if (!of_have_populated_dt()) {
  99. samsung_pm_save_gpios();
  100. samsung_pm_saved_gpios();
  101. }
  102. s3c_pm_save_uarts();
  103. s3c_pm_save_core();
  104. /* set the irq configuration for wake */
  105. s3c_pm_configure_extint();
  106. S3C_PMDBG("sleep: irq wakeup masks: %08lx,%08lx\n",
  107. s3c_irqwake_intmask, s3c_irqwake_eintmask);
  108. s3c_pm_arch_prepare_irqs();
  109. /* call cpu specific preparation */
  110. pm_cpu_prep();
  111. /* flush cache back to ram */
  112. flush_cache_all();
  113. s3c_pm_check_store();
  114. /* send the cpu to sleep... */
  115. s3c_pm_arch_stop_clocks();
  116. /* this will also act as our return point from when
  117. * we resume as it saves its own register state and restores it
  118. * during the resume. */
  119. ret = cpu_suspend(0, pm_cpu_sleep);
  120. if (ret)
  121. return ret;
  122. /* restore the system state */
  123. s3c_pm_restore_core();
  124. s3c_pm_restore_uarts();
  125. if (!of_have_populated_dt()) {
  126. samsung_pm_restore_gpios();
  127. s3c_pm_restored_gpios();
  128. }
  129. s3c_pm_debug_init();
  130. /* check what irq (if any) restored the system */
  131. s3c_pm_arch_show_resume_irqs();
  132. S3C_PMDBG("%s: post sleep, preparing to return\n", __func__);
  133. /* LEDs should now be 1110 */
  134. s3c_pm_debug_smdkled(1 << 1, 0);
  135. s3c_pm_check_restore();
  136. /* ok, let's return from sleep */
  137. S3C_PMDBG("S3C PM Resume (post-restore)\n");
  138. return 0;
  139. }
  140. static int s3c_pm_prepare(void)
  141. {
  142. /* prepare check area if configured */
  143. s3c_pm_check_prepare();
  144. return 0;
  145. }
  146. static void s3c_pm_finish(void)
  147. {
  148. s3c_pm_check_cleanup();
  149. }
  150. static const struct platform_suspend_ops s3c_pm_ops = {
  151. .enter = s3c_pm_enter,
  152. .prepare = s3c_pm_prepare,
  153. .finish = s3c_pm_finish,
  154. .valid = suspend_valid_only_mem,
  155. };
  156. /* s3c_pm_init
  157. *
  158. * Attach the power management functions. This should be called
  159. * from the board specific initialisation if the board supports
  160. * it.
  161. */
  162. int __init s3c_pm_init(void)
  163. {
  164. printk("S3C Power Management, Copyright 2004 Simtec Electronics\n");
  165. suspend_set_ops(&s3c_pm_ops);
  166. return 0;
  167. }