2 * Copyright (c) 2011-2012 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/syscore_ops.h>
20 #include <linux/err.h>
21 #include <linux/clk.h>
23 #include <asm/cacheflush.h>
24 #include <asm/hardware/cache-l2x0.h>
25 #include <asm/smp_scu.h>
30 #include <plat/regs-srom.h>
33 #include <mach/pm-core.h>
38 static struct sleep_save exynos5_sys_save[] = {
39 SAVE_ITEM(EXYNOS5_SYS_I2C_CFG),
42 static struct sleep_save exynos_core_save[] = {
44 SAVE_ITEM(S5P_SROM_BW),
45 SAVE_ITEM(S5P_SROM_BC0),
46 SAVE_ITEM(S5P_SROM_BC1),
47 SAVE_ITEM(S5P_SROM_BC2),
48 SAVE_ITEM(S5P_SROM_BC3),
52 /* For Cortex-A9 Diagnostic and Power control register */
53 static unsigned int save_arm_register[2];
55 static int exynos_cpu_suspend(unsigned long arg)
57 #ifdef CONFIG_CACHE_L2X0
61 if (soc_is_exynos5250())
64 /* issue the standby signal into the pm unit. */
67 pr_info("Failed to suspend the system\n");
68 return 1; /* Aborting suspend */
71 static void exynos_pm_prepare(void)
75 s3c_pm_do_save(exynos_core_save, ARRAY_SIZE(exynos_core_save));
77 if (soc_is_exynos5250()) {
78 s3c_pm_do_save(exynos5_sys_save, ARRAY_SIZE(exynos5_sys_save));
79 /* Disable USE_RETENTION of JPEG_MEM_OPTION */
80 tmp = __raw_readl(EXYNOS5_JPEG_MEM_OPTION);
81 tmp &= ~EXYNOS5_OPTION_USE_RETENTION;
82 __raw_writel(tmp, EXYNOS5_JPEG_MEM_OPTION);
85 /* Set value of power down register for sleep mode */
87 exynos_sys_powerdown_conf(SYS_SLEEP);
88 __raw_writel(S5P_CHECK_SLEEP, S5P_INFORM1);
90 /* ensure at least INFORM0 has the resume address */
92 __raw_writel(virt_to_phys(s3c_cpu_resume), S5P_INFORM0);
95 static int exynos_pm_add(struct device *dev, struct subsys_interface *sif)
97 pm_cpu_prep = exynos_pm_prepare;
98 pm_cpu_sleep = exynos_cpu_suspend;
103 static struct subsys_interface exynos_pm_interface = {
105 .subsys = &exynos_subsys,
106 .add_dev = exynos_pm_add,
109 static __init int exynos_pm_drvinit(void)
113 if (soc_is_exynos5440())
118 /* All wakeup disable */
120 tmp = __raw_readl(S5P_WAKEUP_MASK);
121 tmp |= ((0xFF << 8) | (0x1F << 1));
122 __raw_writel(tmp, S5P_WAKEUP_MASK);
124 return subsys_interface_register(&exynos_pm_interface);
126 arch_initcall(exynos_pm_drvinit);
128 static int exynos_pm_suspend(void)
132 /* Setting Central Sequence Register for power down mode */
134 tmp = __raw_readl(S5P_CENTRAL_SEQ_CONFIGURATION);
135 tmp &= ~S5P_CENTRAL_LOWPWR_CFG;
136 __raw_writel(tmp, S5P_CENTRAL_SEQ_CONFIGURATION);
138 /* Setting SEQ_OPTION register */
140 tmp = (S5P_USE_STANDBY_WFI0 | S5P_USE_STANDBY_WFE0);
141 __raw_writel(tmp, S5P_CENTRAL_SEQ_OPTION);
143 if (!soc_is_exynos5250()) {
144 /* Save Power control register */
145 asm ("mrc p15, 0, %0, c15, c0, 0"
146 : "=r" (tmp) : : "cc");
147 save_arm_register[0] = tmp;
149 /* Save Diagnostic register */
150 asm ("mrc p15, 0, %0, c15, c0, 1"
151 : "=r" (tmp) : : "cc");
152 save_arm_register[1] = tmp;
158 static void exynos_pm_resume(void)
163 * If PMU failed while entering sleep mode, WFI will be
164 * ignored by PMU and then exiting cpu_do_idle().
165 * S5P_CENTRAL_LOWPWR_CFG bit will not be set automatically
168 tmp = __raw_readl(S5P_CENTRAL_SEQ_CONFIGURATION);
169 if (!(tmp & S5P_CENTRAL_LOWPWR_CFG)) {
170 tmp |= S5P_CENTRAL_LOWPWR_CFG;
171 __raw_writel(tmp, S5P_CENTRAL_SEQ_CONFIGURATION);
172 /* clear the wakeup state register */
173 __raw_writel(0x0, S5P_WAKEUP_STAT);
174 /* No need to perform below restore code */
177 if (!soc_is_exynos5250()) {
178 /* Restore Power control register */
179 tmp = save_arm_register[0];
180 asm volatile ("mcr p15, 0, %0, c15, c0, 0"
184 /* Restore Diagnostic register */
185 tmp = save_arm_register[1];
186 asm volatile ("mcr p15, 0, %0, c15, c0, 1"
191 /* For release retention */
193 __raw_writel((1 << 28), S5P_PAD_RET_MAUDIO_OPTION);
194 __raw_writel((1 << 28), S5P_PAD_RET_GPIO_OPTION);
195 __raw_writel((1 << 28), S5P_PAD_RET_UART_OPTION);
196 __raw_writel((1 << 28), S5P_PAD_RET_MMCA_OPTION);
197 __raw_writel((1 << 28), S5P_PAD_RET_MMCB_OPTION);
198 __raw_writel((1 << 28), S5P_PAD_RET_EBIA_OPTION);
199 __raw_writel((1 << 28), S5P_PAD_RET_EBIB_OPTION);
201 if (soc_is_exynos5250())
202 s3c_pm_do_restore(exynos5_sys_save,
203 ARRAY_SIZE(exynos5_sys_save));
205 s3c_pm_do_restore_core(exynos_core_save, ARRAY_SIZE(exynos_core_save));
207 if (IS_ENABLED(CONFIG_SMP) && !soc_is_exynos5250())
208 scu_enable(S5P_VA_SCU);
212 /* Clear SLEEP mode set in INFORM1 */
213 __raw_writel(0x0, S5P_INFORM1);
218 static struct syscore_ops exynos_pm_syscore_ops = {
219 .suspend = exynos_pm_suspend,
220 .resume = exynos_pm_resume,
223 static __init int exynos_pm_syscore_init(void)
225 if (soc_is_exynos5440())
228 register_syscore_ops(&exynos_pm_syscore_ops);
231 arch_initcall(exynos_pm_syscore_init);