pm.c 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198
  1. /* linux/arch/arm/plat-s3c64xx/pm.c
  2. *
  3. * Copyright 2008 Openmoko, Inc.
  4. * Copyright 2008 Simtec Electronics
  5. * Ben Dooks <ben@simtec.co.uk>
  6. * http://armlinux.simtec.co.uk/
  7. *
  8. * S3C64XX CPU PM 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/serial_core.h>
  17. #include <linux/io.h>
  18. #include <linux/gpio.h>
  19. #include <mach/map.h>
  20. #include <mach/irqs.h>
  21. #include <plat/pm.h>
  22. #include <plat/wakeup-mask.h>
  23. #include <mach/regs-sys.h>
  24. #include <mach/regs-gpio.h>
  25. #include <mach/regs-clock.h>
  26. #include <mach/regs-syscon-power.h>
  27. #include <mach/regs-gpio-memport.h>
  28. #ifdef CONFIG_S3C_PM_DEBUG_LED_SMDK
  29. void s3c_pm_debug_smdkled(u32 set, u32 clear)
  30. {
  31. unsigned long flags;
  32. int i;
  33. local_irq_save(flags);
  34. for (i = 0; i < 4; i++) {
  35. if (clear & (1 << i))
  36. gpio_set_value(S3C64XX_GPN(12 + i), 0);
  37. if (set & (1 << i))
  38. gpio_set_value(S3C64XX_GPN(12 + i), 1);
  39. }
  40. local_irq_restore(flags);
  41. }
  42. #endif
  43. static struct sleep_save core_save[] = {
  44. SAVE_ITEM(S3C_APLL_LOCK),
  45. SAVE_ITEM(S3C_MPLL_LOCK),
  46. SAVE_ITEM(S3C_EPLL_LOCK),
  47. SAVE_ITEM(S3C_CLK_SRC),
  48. SAVE_ITEM(S3C_CLK_DIV0),
  49. SAVE_ITEM(S3C_CLK_DIV1),
  50. SAVE_ITEM(S3C_CLK_DIV2),
  51. SAVE_ITEM(S3C_CLK_OUT),
  52. SAVE_ITEM(S3C_HCLK_GATE),
  53. SAVE_ITEM(S3C_PCLK_GATE),
  54. SAVE_ITEM(S3C_SCLK_GATE),
  55. SAVE_ITEM(S3C_MEM0_GATE),
  56. SAVE_ITEM(S3C_EPLL_CON1),
  57. SAVE_ITEM(S3C_EPLL_CON0),
  58. SAVE_ITEM(S3C64XX_MEM0DRVCON),
  59. SAVE_ITEM(S3C64XX_MEM1DRVCON),
  60. #ifndef CONFIG_CPU_FREQ
  61. SAVE_ITEM(S3C_APLL_CON),
  62. SAVE_ITEM(S3C_MPLL_CON),
  63. #endif
  64. };
  65. static struct sleep_save misc_save[] = {
  66. SAVE_ITEM(S3C64XX_AHB_CON0),
  67. SAVE_ITEM(S3C64XX_AHB_CON1),
  68. SAVE_ITEM(S3C64XX_AHB_CON2),
  69. SAVE_ITEM(S3C64XX_SPCON),
  70. SAVE_ITEM(S3C64XX_MEM0CONSTOP),
  71. SAVE_ITEM(S3C64XX_MEM1CONSTOP),
  72. SAVE_ITEM(S3C64XX_MEM0CONSLP0),
  73. SAVE_ITEM(S3C64XX_MEM0CONSLP1),
  74. SAVE_ITEM(S3C64XX_MEM1CONSLP),
  75. };
  76. void s3c_pm_configure_extint(void)
  77. {
  78. __raw_writel(s3c_irqwake_eintmask, S3C64XX_EINT_MASK);
  79. }
  80. void s3c_pm_restore_core(void)
  81. {
  82. __raw_writel(0, S3C64XX_EINT_MASK);
  83. s3c_pm_debug_smdkled(1 << 2, 0);
  84. s3c_pm_do_restore_core(core_save, ARRAY_SIZE(core_save));
  85. s3c_pm_do_restore(misc_save, ARRAY_SIZE(misc_save));
  86. }
  87. void s3c_pm_save_core(void)
  88. {
  89. s3c_pm_do_save(misc_save, ARRAY_SIZE(misc_save));
  90. s3c_pm_do_save(core_save, ARRAY_SIZE(core_save));
  91. }
  92. /* since both s3c6400 and s3c6410 share the same sleep pm calls, we
  93. * put the per-cpu code in here until any new cpu comes along and changes
  94. * this.
  95. */
  96. static int s3c64xx_cpu_suspend(unsigned long arg)
  97. {
  98. unsigned long tmp;
  99. /* set our standby method to sleep */
  100. tmp = __raw_readl(S3C64XX_PWR_CFG);
  101. tmp &= ~S3C64XX_PWRCFG_CFG_WFI_MASK;
  102. tmp |= S3C64XX_PWRCFG_CFG_WFI_SLEEP;
  103. __raw_writel(tmp, S3C64XX_PWR_CFG);
  104. /* clear any old wakeup */
  105. __raw_writel(__raw_readl(S3C64XX_WAKEUP_STAT),
  106. S3C64XX_WAKEUP_STAT);
  107. /* set the LED state to 0110 over sleep */
  108. s3c_pm_debug_smdkled(3 << 1, 0xf);
  109. /* issue the standby signal into the pm unit. Note, we
  110. * issue a write-buffer drain just in case */
  111. tmp = 0;
  112. asm("b 1f\n\t"
  113. ".align 5\n\t"
  114. "1:\n\t"
  115. "mcr p15, 0, %0, c7, c10, 5\n\t"
  116. "mcr p15, 0, %0, c7, c10, 4\n\t"
  117. "mcr p15, 0, %0, c7, c0, 4" :: "r" (tmp));
  118. /* we should never get past here */
  119. panic("sleep resumed to originator?");
  120. }
  121. /* mapping of interrupts to parts of the wakeup mask */
  122. static struct samsung_wakeup_mask wake_irqs[] = {
  123. { .irq = IRQ_RTC_ALARM, .bit = S3C64XX_PWRCFG_RTC_ALARM_DISABLE, },
  124. { .irq = IRQ_RTC_TIC, .bit = S3C64XX_PWRCFG_RTC_TICK_DISABLE, },
  125. { .irq = IRQ_PENDN, .bit = S3C64XX_PWRCFG_TS_DISABLE, },
  126. { .irq = IRQ_HSMMC0, .bit = S3C64XX_PWRCFG_MMC0_DISABLE, },
  127. { .irq = IRQ_HSMMC1, .bit = S3C64XX_PWRCFG_MMC1_DISABLE, },
  128. { .irq = IRQ_HSMMC2, .bit = S3C64XX_PWRCFG_MMC2_DISABLE, },
  129. { .irq = NO_WAKEUP_IRQ, .bit = S3C64XX_PWRCFG_BATF_DISABLE},
  130. { .irq = NO_WAKEUP_IRQ, .bit = S3C64XX_PWRCFG_MSM_DISABLE },
  131. { .irq = NO_WAKEUP_IRQ, .bit = S3C64XX_PWRCFG_HSI_DISABLE },
  132. { .irq = NO_WAKEUP_IRQ, .bit = S3C64XX_PWRCFG_MSM_DISABLE },
  133. };
  134. static void s3c64xx_pm_prepare(void)
  135. {
  136. samsung_sync_wakemask(S3C64XX_PWR_CFG,
  137. wake_irqs, ARRAY_SIZE(wake_irqs));
  138. /* store address of resume. */
  139. __raw_writel(virt_to_phys(s3c_cpu_resume), S3C64XX_INFORM0);
  140. /* ensure previous wakeup state is cleared before sleeping */
  141. __raw_writel(__raw_readl(S3C64XX_WAKEUP_STAT), S3C64XX_WAKEUP_STAT);
  142. }
  143. static int s3c64xx_pm_init(void)
  144. {
  145. pm_cpu_prep = s3c64xx_pm_prepare;
  146. pm_cpu_sleep = s3c64xx_cpu_suspend;
  147. pm_uart_udivslot = 1;
  148. #ifdef CONFIG_S3C_PM_DEBUG_LED_SMDK
  149. gpio_request(S3C64XX_GPN(12), "DEBUG_LED0");
  150. gpio_request(S3C64XX_GPN(13), "DEBUG_LED1");
  151. gpio_request(S3C64XX_GPN(14), "DEBUG_LED2");
  152. gpio_request(S3C64XX_GPN(15), "DEBUG_LED3");
  153. gpio_direction_output(S3C64XX_GPN(12), 0);
  154. gpio_direction_output(S3C64XX_GPN(13), 0);
  155. gpio_direction_output(S3C64XX_GPN(14), 0);
  156. gpio_direction_output(S3C64XX_GPN(15), 0);
  157. #endif
  158. return 0;
  159. }
  160. arch_initcall(s3c64xx_pm_init);