2 * Copyright (c) 2011-2014 Samsung Electronics Co., Ltd.
3 * http://www.samsung.com
5 * EXYNOS - Power Management support
7 * Based on arch/arm/mach-s3c2410/pm.c
8 * Copyright (c) 2006 Simtec Electronics
9 * Ben Dooks <ben@simtec.co.uk>
11 * This program is free software; you can redistribute it and/or modify
12 * it under the terms of the GNU General Public License version 2 as
13 * published by the Free Software Foundation.
16 #include <linux/init.h>
17 #include <linux/suspend.h>
18 #include <linux/cpu_pm.h>
20 #include <linux/err.h>
22 #include <asm/firmware.h>
23 #include <asm/smp_scu.h>
24 #include <asm/suspend.h>
28 #include <plat/pm-common.h>
31 #include "exynos-pmu.h"
34 static inline void __iomem
*exynos_boot_vector_addr(void)
36 if (samsung_rev() == EXYNOS4210_REV_1_1
)
37 return pmu_base_addr
+ S5P_INFORM7
;
38 else if (samsung_rev() == EXYNOS4210_REV_1_0
)
39 return sysram_base_addr
+ 0x24;
40 return pmu_base_addr
+ S5P_INFORM0
;
43 static inline void __iomem
*exynos_boot_vector_flag(void)
45 if (samsung_rev() == EXYNOS4210_REV_1_1
)
46 return pmu_base_addr
+ S5P_INFORM6
;
47 else if (samsung_rev() == EXYNOS4210_REV_1_0
)
48 return sysram_base_addr
+ 0x20;
49 return pmu_base_addr
+ S5P_INFORM1
;
52 #define S5P_CHECK_AFTR 0xFCBA0D10
54 /* For Cortex-A9 Diagnostic and Power control register */
55 static unsigned int save_arm_register
[2];
57 void exynos_cpu_save_register(void)
61 /* Save Power control register */
62 asm ("mrc p15, 0, %0, c15, c0, 0"
63 : "=r" (tmp
) : : "cc");
65 save_arm_register
[0] = tmp
;
67 /* Save Diagnostic register */
68 asm ("mrc p15, 0, %0, c15, c0, 1"
69 : "=r" (tmp
) : : "cc");
71 save_arm_register
[1] = tmp
;
74 void exynos_cpu_restore_register(void)
78 /* Restore Power control register */
79 tmp
= save_arm_register
[0];
81 asm volatile ("mcr p15, 0, %0, c15, c0, 0"
85 /* Restore Diagnostic register */
86 tmp
= save_arm_register
[1];
88 asm volatile ("mcr p15, 0, %0, c15, c0, 1"
93 void exynos_pm_central_suspend(void)
97 /* Setting Central Sequence Register for power down mode */
98 tmp
= pmu_raw_readl(S5P_CENTRAL_SEQ_CONFIGURATION
);
99 tmp
&= ~S5P_CENTRAL_LOWPWR_CFG
;
100 pmu_raw_writel(tmp
, S5P_CENTRAL_SEQ_CONFIGURATION
);
103 int exynos_pm_central_resume(void)
108 * If PMU failed while entering sleep mode, WFI will be
109 * ignored by PMU and then exiting cpu_do_idle().
110 * S5P_CENTRAL_LOWPWR_CFG bit will not be set automatically
113 tmp
= pmu_raw_readl(S5P_CENTRAL_SEQ_CONFIGURATION
);
114 if (!(tmp
& S5P_CENTRAL_LOWPWR_CFG
)) {
115 tmp
|= S5P_CENTRAL_LOWPWR_CFG
;
116 pmu_raw_writel(tmp
, S5P_CENTRAL_SEQ_CONFIGURATION
);
117 /* clear the wakeup state register */
118 pmu_raw_writel(0x0, S5P_WAKEUP_STAT
);
119 /* No need to perform below restore code */
126 /* Ext-GIC nIRQ/nFIQ is the only wakeup source in AFTR */
127 static void exynos_set_wakeupmask(long mask
)
129 pmu_raw_writel(mask
, S5P_WAKEUP_MASK
);
130 if (soc_is_exynos3250())
131 pmu_raw_writel(0x0, S5P_WAKEUP_MASK2
);
134 static void exynos_cpu_set_boot_vector(long flags
)
136 __raw_writel(virt_to_phys(exynos_cpu_resume
),
137 exynos_boot_vector_addr());
138 __raw_writel(flags
, exynos_boot_vector_flag());
141 static int exynos_aftr_finisher(unsigned long flags
)
145 exynos_set_wakeupmask(soc_is_exynos3250() ? 0x40003ffe : 0x0000ff3e);
146 /* Set value of power down register for aftr mode */
147 exynos_sys_powerdown_conf(SYS_AFTR
);
149 ret
= call_firmware_op(do_idle
, FW_DO_IDLE_AFTR
);
150 if (ret
== -ENOSYS
) {
151 if (read_cpuid_part() == ARM_CPU_PART_CORTEX_A9
)
152 exynos_cpu_save_register();
153 exynos_cpu_set_boot_vector(S5P_CHECK_AFTR
);
160 void exynos_enter_aftr(void)
162 unsigned int cpuid
= smp_processor_id();
166 if (soc_is_exynos3250())
167 exynos_set_boot_flag(cpuid
, C2_STATE
);
169 exynos_pm_central_suspend();
171 if (of_machine_is_compatible("samsung,exynos4212") ||
172 of_machine_is_compatible("samsung,exynos4412")) {
173 /* Setting SEQ_OPTION register */
174 pmu_raw_writel(S5P_USE_STANDBY_WFI0
| S5P_USE_STANDBY_WFE0
,
175 S5P_CENTRAL_SEQ_OPTION
);
178 cpu_suspend(0, exynos_aftr_finisher
);
180 if (read_cpuid_part() == ARM_CPU_PART_CORTEX_A9
) {
181 scu_enable(S5P_VA_SCU
);
182 if (call_firmware_op(resume
) == -ENOSYS
)
183 exynos_cpu_restore_register();
186 exynos_pm_central_resume();
188 if (soc_is_exynos3250())
189 exynos_clear_boot_flag(cpuid
, C2_STATE
);
194 #if defined(CONFIG_SMP) && defined(CONFIG_ARM_EXYNOS_CPUIDLE)
195 static atomic_t cpu1_wakeup
= ATOMIC_INIT(0);
197 static int exynos_cpu0_enter_aftr(void)
202 * If the other cpu is powered on, we have to power it off, because
203 * the AFTR state won't work otherwise
207 * We reach a sync point with the coupled idle state, we know
208 * the other cpu will power down itself or will abort the
209 * sequence, let's wait for one of these to happen
211 while (exynos_cpu_power_state(1)) {
213 * The other cpu may skip idle and boot back
216 if (atomic_read(&cpu1_wakeup
))
220 * The other cpu may bounce through idle and
221 * boot back up again, getting stuck in the
224 if (__raw_readl(cpu_boot_reg_base()) == 0)
237 * Set the boot vector to something non-zero
239 __raw_writel(virt_to_phys(exynos_cpu_resume
),
240 cpu_boot_reg_base());
244 * Turn on cpu1 and wait for it to be on
246 exynos_cpu_power_up(1);
247 while (exynos_cpu_power_state(1) != S5P_CORE_LOCAL_PWR_EN
)
250 while (!atomic_read(&cpu1_wakeup
)) {
252 * Poke cpu1 out of the boot rom
254 __raw_writel(virt_to_phys(exynos_cpu_resume
),
255 cpu_boot_reg_base());
257 arch_send_wakeup_ipi_mask(cpumask_of(1));
264 static int exynos_wfi_finisher(unsigned long flags
)
271 static int exynos_cpu1_powerdown(void)
276 * Idle sequence for cpu1
284 exynos_cpu_power_down(1);
286 ret
= cpu_suspend(0, exynos_wfi_finisher
);
293 * Notify cpu 0 that cpu 1 is awake
295 atomic_set(&cpu1_wakeup
, 1);
300 static void exynos_pre_enter_aftr(void)
302 __raw_writel(virt_to_phys(exynos_cpu_resume
), cpu_boot_reg_base());
305 static void exynos_post_enter_aftr(void)
307 atomic_set(&cpu1_wakeup
, 0);
310 struct cpuidle_exynos_data cpuidle_coupled_exynos_data
= {
311 .cpu0_enter_aftr
= exynos_cpu0_enter_aftr
,
312 .cpu1_powerdown
= exynos_cpu1_powerdown
,
313 .pre_enter_aftr
= exynos_pre_enter_aftr
,
314 .post_enter_aftr
= exynos_post_enter_aftr
,
316 #endif /* CONFIG_SMP && CONFIG_ARM_EXYNOS_CPUIDLE */