pm.c 5.1 KB

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