pm.c 5.0 KB

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