1 // SPDX-License-Identifier: GPL-2.0
3 // Copyright 2008 Openmoko, Inc.
4 // Copyright 2008 Simtec Electronics
5 // Ben Dooks <ben@simtec.co.uk>
6 // http://armlinux.simtec.co.uk/
8 // S3C64XX CPU PM support.
10 #include <linux/init.h>
11 #include <linux/suspend.h>
12 #include <linux/serial_core.h>
14 #include <linux/gpio.h>
15 #include <linux/pm_domain.h>
23 #include "wakeup-mask.h"
25 #include "regs-gpio.h"
26 #include "regs-clock.h"
27 #include "gpio-samsung.h"
29 #include "regs-gpio-memport-s3c64xx.h"
30 #include "regs-modem-s3c64xx.h"
31 #include "regs-sys-s3c64xx.h"
32 #include "regs-syscon-power-s3c64xx.h"
34 struct s3c64xx_pm_domain
{
38 struct generic_pm_domain pd
;
41 static int s3c64xx_pd_off(struct generic_pm_domain
*domain
)
43 struct s3c64xx_pm_domain
*pd
;
46 pd
= container_of(domain
, struct s3c64xx_pm_domain
, pd
);
48 val
= __raw_readl(S3C64XX_NORMAL_CFG
);
50 __raw_writel(val
, S3C64XX_NORMAL_CFG
);
55 static int s3c64xx_pd_on(struct generic_pm_domain
*domain
)
57 struct s3c64xx_pm_domain
*pd
;
59 long retry
= 1000000L;
61 pd
= container_of(domain
, struct s3c64xx_pm_domain
, pd
);
63 val
= __raw_readl(S3C64XX_NORMAL_CFG
);
65 __raw_writel(val
, S3C64XX_NORMAL_CFG
);
67 /* Not all domains provide power status readback */
71 if (__raw_readl(S3C64XX_BLK_PWR_STAT
) & pd
->pwr_stat
)
76 pr_err("Failed to start domain %s\n", pd
->name
);
84 static struct s3c64xx_pm_domain s3c64xx_pm_irom
= {
86 .ena
= S3C64XX_NORMALCFG_IROM_ON
,
88 .power_off
= s3c64xx_pd_off
,
89 .power_on
= s3c64xx_pd_on
,
93 static struct s3c64xx_pm_domain s3c64xx_pm_etm
= {
95 .ena
= S3C64XX_NORMALCFG_DOMAIN_ETM_ON
,
96 .pwr_stat
= S3C64XX_BLKPWRSTAT_ETM
,
98 .power_off
= s3c64xx_pd_off
,
99 .power_on
= s3c64xx_pd_on
,
103 static struct s3c64xx_pm_domain s3c64xx_pm_s
= {
105 .ena
= S3C64XX_NORMALCFG_DOMAIN_S_ON
,
106 .pwr_stat
= S3C64XX_BLKPWRSTAT_S
,
108 .power_off
= s3c64xx_pd_off
,
109 .power_on
= s3c64xx_pd_on
,
113 static struct s3c64xx_pm_domain s3c64xx_pm_f
= {
115 .ena
= S3C64XX_NORMALCFG_DOMAIN_F_ON
,
116 .pwr_stat
= S3C64XX_BLKPWRSTAT_F
,
118 .power_off
= s3c64xx_pd_off
,
119 .power_on
= s3c64xx_pd_on
,
123 static struct s3c64xx_pm_domain s3c64xx_pm_p
= {
125 .ena
= S3C64XX_NORMALCFG_DOMAIN_P_ON
,
126 .pwr_stat
= S3C64XX_BLKPWRSTAT_P
,
128 .power_off
= s3c64xx_pd_off
,
129 .power_on
= s3c64xx_pd_on
,
133 static struct s3c64xx_pm_domain s3c64xx_pm_i
= {
135 .ena
= S3C64XX_NORMALCFG_DOMAIN_I_ON
,
136 .pwr_stat
= S3C64XX_BLKPWRSTAT_I
,
138 .power_off
= s3c64xx_pd_off
,
139 .power_on
= s3c64xx_pd_on
,
143 static struct s3c64xx_pm_domain s3c64xx_pm_g
= {
145 .ena
= S3C64XX_NORMALCFG_DOMAIN_G_ON
,
147 .power_off
= s3c64xx_pd_off
,
148 .power_on
= s3c64xx_pd_on
,
152 static struct s3c64xx_pm_domain s3c64xx_pm_v
= {
154 .ena
= S3C64XX_NORMALCFG_DOMAIN_V_ON
,
155 .pwr_stat
= S3C64XX_BLKPWRSTAT_V
,
157 .power_off
= s3c64xx_pd_off
,
158 .power_on
= s3c64xx_pd_on
,
162 static struct s3c64xx_pm_domain
*s3c64xx_always_on_pm_domains
[] = {
166 static struct s3c64xx_pm_domain
*s3c64xx_pm_domains
[] = {
176 #ifdef CONFIG_PM_SLEEP
177 static struct sleep_save core_save
[] = {
178 SAVE_ITEM(S3C64XX_MEM0DRVCON
),
179 SAVE_ITEM(S3C64XX_MEM1DRVCON
),
182 static struct sleep_save misc_save
[] = {
183 SAVE_ITEM(S3C64XX_AHB_CON0
),
184 SAVE_ITEM(S3C64XX_AHB_CON1
),
185 SAVE_ITEM(S3C64XX_AHB_CON2
),
187 SAVE_ITEM(S3C64XX_SPCON
),
189 SAVE_ITEM(S3C64XX_MEM0CONSTOP
),
190 SAVE_ITEM(S3C64XX_MEM1CONSTOP
),
191 SAVE_ITEM(S3C64XX_MEM0CONSLP0
),
192 SAVE_ITEM(S3C64XX_MEM0CONSLP1
),
193 SAVE_ITEM(S3C64XX_MEM1CONSLP
),
195 SAVE_ITEM(S3C64XX_SDMA_SEL
),
196 SAVE_ITEM(S3C64XX_MODEM_MIFPCON
),
198 SAVE_ITEM(S3C64XX_NORMAL_CFG
),
201 void s3c_pm_configure_extint(void)
203 __raw_writel(s3c_irqwake_eintmask
, S3C64XX_EINT_MASK
);
206 void s3c_pm_restore_core(void)
208 __raw_writel(0, S3C64XX_EINT_MASK
);
210 s3c_pm_do_restore_core(core_save
, ARRAY_SIZE(core_save
));
211 s3c_pm_do_restore(misc_save
, ARRAY_SIZE(misc_save
));
214 void s3c_pm_save_core(void)
216 s3c_pm_do_save(misc_save
, ARRAY_SIZE(misc_save
));
217 s3c_pm_do_save(core_save
, ARRAY_SIZE(core_save
));
221 /* since both s3c6400 and s3c6410 share the same sleep pm calls, we
222 * put the per-cpu code in here until any new cpu comes along and changes
226 static int s3c64xx_cpu_suspend(unsigned long arg
)
230 /* set our standby method to sleep */
232 tmp
= __raw_readl(S3C64XX_PWR_CFG
);
233 tmp
&= ~S3C64XX_PWRCFG_CFG_WFI_MASK
;
234 tmp
|= S3C64XX_PWRCFG_CFG_WFI_SLEEP
;
235 __raw_writel(tmp
, S3C64XX_PWR_CFG
);
237 /* clear any old wakeup */
239 __raw_writel(__raw_readl(S3C64XX_WAKEUP_STAT
),
240 S3C64XX_WAKEUP_STAT
);
242 /* issue the standby signal into the pm unit. Note, we
243 * issue a write-buffer drain just in case */
250 "mcr p15, 0, %0, c7, c10, 5\n\t"
251 "mcr p15, 0, %0, c7, c10, 4\n\t"
252 "mcr p15, 0, %0, c7, c0, 4" :: "r" (tmp
));
254 /* we should never get past here */
256 pr_info("Failed to suspend the system\n");
257 return 1; /* Aborting suspend */
260 /* mapping of interrupts to parts of the wakeup mask */
261 static const struct samsung_wakeup_mask wake_irqs
[] = {
262 { .irq
= IRQ_RTC_ALARM
, .bit
= S3C64XX_PWRCFG_RTC_ALARM_DISABLE
, },
263 { .irq
= IRQ_RTC_TIC
, .bit
= S3C64XX_PWRCFG_RTC_TICK_DISABLE
, },
264 { .irq
= IRQ_PENDN
, .bit
= S3C64XX_PWRCFG_TS_DISABLE
, },
265 { .irq
= IRQ_HSMMC0
, .bit
= S3C64XX_PWRCFG_MMC0_DISABLE
, },
266 { .irq
= IRQ_HSMMC1
, .bit
= S3C64XX_PWRCFG_MMC1_DISABLE
, },
267 { .irq
= IRQ_HSMMC2
, .bit
= S3C64XX_PWRCFG_MMC2_DISABLE
, },
268 { .irq
= NO_WAKEUP_IRQ
, .bit
= S3C64XX_PWRCFG_BATF_DISABLE
},
269 { .irq
= NO_WAKEUP_IRQ
, .bit
= S3C64XX_PWRCFG_MSM_DISABLE
},
270 { .irq
= NO_WAKEUP_IRQ
, .bit
= S3C64XX_PWRCFG_HSI_DISABLE
},
271 { .irq
= NO_WAKEUP_IRQ
, .bit
= S3C64XX_PWRCFG_MSM_DISABLE
},
274 static void s3c64xx_pm_prepare(void)
276 samsung_sync_wakemask(S3C64XX_PWR_CFG
,
277 wake_irqs
, ARRAY_SIZE(wake_irqs
));
279 /* store address of resume. */
280 __raw_writel(__pa_symbol(s3c_cpu_resume
), S3C64XX_INFORM0
);
282 /* ensure previous wakeup state is cleared before sleeping */
283 __raw_writel(__raw_readl(S3C64XX_WAKEUP_STAT
), S3C64XX_WAKEUP_STAT
);
286 int __init
s3c64xx_pm_init(void)
292 for (i
= 0; i
< ARRAY_SIZE(s3c64xx_always_on_pm_domains
); i
++)
293 pm_genpd_init(&s3c64xx_always_on_pm_domains
[i
]->pd
,
294 &pm_domain_always_on_gov
, false);
296 for (i
= 0; i
< ARRAY_SIZE(s3c64xx_pm_domains
); i
++)
297 pm_genpd_init(&s3c64xx_pm_domains
[i
]->pd
, NULL
, false);
299 #ifdef CONFIG_S3C_DEV_FB
300 if (dev_get_platdata(&s3c_device_fb
.dev
))
301 pm_genpd_add_device(&s3c64xx_pm_f
.pd
, &s3c_device_fb
.dev
);
307 static __init
int s3c64xx_pm_initcall(void)
309 if (!soc_is_s3c64xx())
312 pm_cpu_prep
= s3c64xx_pm_prepare
;
313 pm_cpu_sleep
= s3c64xx_cpu_suspend
;
317 arch_initcall(s3c64xx_pm_initcall
);