pm.c 4.3 KB

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