blob: ba18214c9acad4853b02389e42b8d8895144d0f0 [file] [log] [blame]
Jongpill Leec9347102012-02-17 09:49:54 +09001/*
2 * Copyright (c) 2011-2012 Samsung Electronics Co., Ltd.
Jaecheol Lee16638952011-03-10 13:33:59 +09003 * http://www.samsung.com
4 *
Jongpill Leec9347102012-02-17 09:49:54 +09005 * EXYNOS - Power Management support
Jaecheol Lee16638952011-03-10 13:33:59 +09006 *
7 * Based on arch/arm/mach-s3c2410/pm.c
8 * Copyright (c) 2006 Simtec Electronics
9 * Ben Dooks <ben@simtec.co.uk>
10 *
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.
14*/
15
16#include <linux/init.h>
17#include <linux/suspend.h>
Rafael J. Wysockibb072c32011-04-22 22:03:21 +020018#include <linux/syscore_ops.h>
Jaecheol Lee16638952011-03-10 13:33:59 +090019#include <linux/io.h>
Jaecheol Lee56c03d92011-07-18 19:25:13 +090020#include <linux/err.h>
21#include <linux/clk.h>
Jaecheol Lee16638952011-03-10 13:33:59 +090022
23#include <asm/cacheflush.h>
24#include <asm/hardware/cache-l2x0.h>
Shawn Guo63b870f2011-11-17 01:19:11 +090025#include <asm/smp_scu.h>
Jaecheol Lee16638952011-03-10 13:33:59 +090026
27#include <plat/cpu.h>
28#include <plat/pm.h>
Jaecheol Lee56c03d92011-07-18 19:25:13 +090029#include <plat/pll.h>
MyungJoo Hamb93cb912011-07-21 11:25:23 +090030#include <plat/regs-srom.h>
Jaecheol Lee16638952011-03-10 13:33:59 +090031
Kukjin Kim9c9239a2013-12-19 04:19:59 +090032#include <mach/map.h>
Jaecheol Lee16638952011-03-10 13:33:59 +090033#include <mach/pm-core.h>
Kukjin Kimccd458c2012-12-31 10:06:48 -080034
35#include "common.h"
Kukjin Kim65c9a852013-12-19 04:06:56 +090036#include "regs-pmu.h"
Jaecheol Lee16638952011-03-10 13:33:59 +090037
Abhilash Kesavan86ffb0e2012-11-20 18:20:45 +090038static struct sleep_save exynos5_sys_save[] = {
39 SAVE_ITEM(EXYNOS5_SYS_I2C_CFG),
40};
41
Jongpill Leec9347102012-02-17 09:49:54 +090042static struct sleep_save exynos_core_save[] = {
MyungJoo Hamb93cb912011-07-21 11:25:23 +090043 /* SROM side */
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),
Jaecheol Lee16638952011-03-10 13:33:59 +090049};
50
Jaecheol Lee16638952011-03-10 13:33:59 +090051
Jaecheol Leef4ba4b02011-07-18 19:25:03 +090052/* For Cortex-A9 Diagnostic and Power control register */
53static unsigned int save_arm_register[2];
54
Jongpill Leec9347102012-02-17 09:49:54 +090055static int exynos_cpu_suspend(unsigned long arg)
Jaecheol Lee16638952011-03-10 13:33:59 +090056{
Jongpill Lee60e49ca2012-02-17 12:23:51 +090057#ifdef CONFIG_CACHE_L2X0
Jaecheol Lee16638952011-03-10 13:33:59 +090058 outer_flush_all();
Jongpill Lee60e49ca2012-02-17 12:23:51 +090059#endif
Jaecheol Lee16638952011-03-10 13:33:59 +090060
Abhilash Kesavan573e5bb2012-11-22 14:46:40 +090061 if (soc_is_exynos5250())
62 flush_cache_all();
63
Jaecheol Lee16638952011-03-10 13:33:59 +090064 /* issue the standby signal into the pm unit. */
65 cpu_do_idle();
66
Abhilash Kesavand3fcacf2013-01-25 10:40:19 -080067 pr_info("Failed to suspend the system\n");
68 return 1; /* Aborting suspend */
Jaecheol Lee16638952011-03-10 13:33:59 +090069}
70
Jongpill Leec9347102012-02-17 09:49:54 +090071static void exynos_pm_prepare(void)
Jaecheol Lee16638952011-03-10 13:33:59 +090072{
Jongpill Lee60e49ca2012-02-17 12:23:51 +090073 unsigned int tmp;
Jaecheol Lee16638952011-03-10 13:33:59 +090074
Jongpill Leec9347102012-02-17 09:49:54 +090075 s3c_pm_do_save(exynos_core_save, ARRAY_SIZE(exynos_core_save));
Jaecheol Lee16638952011-03-10 13:33:59 +090076
Tomasz Figae11d9192014-02-14 08:16:01 +090077 if (soc_is_exynos5250()) {
Abhilash Kesavan86ffb0e2012-11-20 18:20:45 +090078 s3c_pm_do_save(exynos5_sys_save, ARRAY_SIZE(exynos5_sys_save));
Jongpill Lee60e49ca2012-02-17 12:23:51 +090079 /* 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);
83 }
Jaecheol Lee16638952011-03-10 13:33:59 +090084
85 /* Set value of power down register for sleep mode */
86
Jongpill Lee7d44d2b2012-02-17 09:51:31 +090087 exynos_sys_powerdown_conf(SYS_SLEEP);
Jaecheol Lee16638952011-03-10 13:33:59 +090088 __raw_writel(S5P_CHECK_SLEEP, S5P_INFORM1);
89
90 /* ensure at least INFORM0 has the resume address */
91
92 __raw_writel(virt_to_phys(s3c_cpu_resume), S5P_INFORM0);
Jaecheol Lee16638952011-03-10 13:33:59 +090093}
94
Jongpill Leec9347102012-02-17 09:49:54 +090095static int exynos_pm_add(struct device *dev, struct subsys_interface *sif)
Jaecheol Lee16638952011-03-10 13:33:59 +090096{
Jongpill Leec9347102012-02-17 09:49:54 +090097 pm_cpu_prep = exynos_pm_prepare;
98 pm_cpu_sleep = exynos_cpu_suspend;
Jaecheol Lee16638952011-03-10 13:33:59 +090099
100 return 0;
101}
102
Jongpill Leec9347102012-02-17 09:49:54 +0900103static struct subsys_interface exynos_pm_interface = {
Jongpill Lee60e49ca2012-02-17 12:23:51 +0900104 .name = "exynos_pm",
Thomas Abraham9ee6af92012-05-15 15:47:40 +0900105 .subsys = &exynos_subsys,
Jongpill Leec9347102012-02-17 09:49:54 +0900106 .add_dev = exynos_pm_add,
Rafael J. Wysockibb072c32011-04-22 22:03:21 +0200107};
108
Jongpill Leec9347102012-02-17 09:49:54 +0900109static __init int exynos_pm_drvinit(void)
Rafael J. Wysockibb072c32011-04-22 22:03:21 +0200110{
111 unsigned int tmp;
112
Kukjin Kime085cad2013-06-26 22:29:44 +0900113 if (soc_is_exynos5440())
114 return 0;
115
Rafael J. Wysockibb072c32011-04-22 22:03:21 +0200116 s3c_pm_init();
117
118 /* All wakeup disable */
119
120 tmp = __raw_readl(S5P_WAKEUP_MASK);
121 tmp |= ((0xFF << 8) | (0x1F << 1));
122 __raw_writel(tmp, S5P_WAKEUP_MASK);
123
Jongpill Leec9347102012-02-17 09:49:54 +0900124 return subsys_interface_register(&exynos_pm_interface);
Rafael J. Wysockibb072c32011-04-22 22:03:21 +0200125}
Jongpill Leec9347102012-02-17 09:49:54 +0900126arch_initcall(exynos_pm_drvinit);
Rafael J. Wysockibb072c32011-04-22 22:03:21 +0200127
Jongpill Leec9347102012-02-17 09:49:54 +0900128static int exynos_pm_suspend(void)
Jaecheol Lee12974e92011-07-18 19:21:41 +0900129{
130 unsigned long tmp;
131
132 /* Setting Central Sequence Register for power down mode */
133
134 tmp = __raw_readl(S5P_CENTRAL_SEQ_CONFIGURATION);
135 tmp &= ~S5P_CENTRAL_LOWPWR_CFG;
136 __raw_writel(tmp, S5P_CENTRAL_SEQ_CONFIGURATION);
137
Jongpill Lee60e49ca2012-02-17 12:23:51 +0900138 /* Setting SEQ_OPTION register */
139
140 tmp = (S5P_USE_STANDBY_WFI0 | S5P_USE_STANDBY_WFE0);
141 __raw_writel(tmp, S5P_CENTRAL_SEQ_OPTION);
142
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;
148
149 /* Save Diagnostic register */
150 asm ("mrc p15, 0, %0, c15, c0, 1"
151 : "=r" (tmp) : : "cc");
152 save_arm_register[1] = tmp;
Jongpill Lee00a351f2011-09-27 07:26:04 +0900153 }
154
Jaecheol Lee12974e92011-07-18 19:21:41 +0900155 return 0;
156}
157
Jongpill Leec9347102012-02-17 09:49:54 +0900158static void exynos_pm_resume(void)
Jaecheol Lee16638952011-03-10 13:33:59 +0900159{
Jaecheol Leee240ab1c2011-07-18 19:21:34 +0900160 unsigned long tmp;
161
162 /*
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
166 * in this situation.
167 */
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);
Abhilash Kesavand3fcacf2013-01-25 10:40:19 -0800172 /* clear the wakeup state register */
173 __raw_writel(0x0, S5P_WAKEUP_STAT);
Jaecheol Leee240ab1c2011-07-18 19:21:34 +0900174 /* No need to perform below restore code */
175 goto early_wakeup;
176 }
Jongpill Lee60e49ca2012-02-17 12:23:51 +0900177 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"
181 : : "r" (tmp)
182 : "cc");
Jaecheol Leef4ba4b02011-07-18 19:25:03 +0900183
Jongpill Lee60e49ca2012-02-17 12:23:51 +0900184 /* Restore Diagnostic register */
185 tmp = save_arm_register[1];
186 asm volatile ("mcr p15, 0, %0, c15, c0, 1"
187 : : "r" (tmp)
188 : "cc");
189 }
Jaecheol Leee240ab1c2011-07-18 19:21:34 +0900190
Jaecheol Lee16638952011-03-10 13:33:59 +0900191 /* For release retention */
192
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);
200
Abhilash Kesavan86ffb0e2012-11-20 18:20:45 +0900201 if (soc_is_exynos5250())
202 s3c_pm_do_restore(exynos5_sys_save,
203 ARRAY_SIZE(exynos5_sys_save));
204
Jongpill Leec9347102012-02-17 09:49:54 +0900205 s3c_pm_do_restore_core(exynos_core_save, ARRAY_SIZE(exynos_core_save));
Jaecheol Lee16638952011-03-10 13:33:59 +0900206
Tomasz Figae11d9192014-02-14 08:16:01 +0900207 if (IS_ENABLED(CONFIG_SMP) && !soc_is_exynos5250())
Jongpill Lee60e49ca2012-02-17 12:23:51 +0900208 scu_enable(S5P_VA_SCU);
Jaecheol Lee16638952011-03-10 13:33:59 +0900209
Jaecheol Leee240ab1c2011-07-18 19:21:34 +0900210early_wakeup:
Inderpal Singhebee8542012-11-22 14:46:27 +0900211
212 /* Clear SLEEP mode set in INFORM1 */
213 __raw_writel(0x0, S5P_INFORM1);
214
Jaecheol Leee240ab1c2011-07-18 19:21:34 +0900215 return;
Jaecheol Lee16638952011-03-10 13:33:59 +0900216}
217
Jongpill Leec9347102012-02-17 09:49:54 +0900218static struct syscore_ops exynos_pm_syscore_ops = {
219 .suspend = exynos_pm_suspend,
220 .resume = exynos_pm_resume,
Jaecheol Lee16638952011-03-10 13:33:59 +0900221};
222
Jongpill Lee60e49ca2012-02-17 12:23:51 +0900223static __init int exynos_pm_syscore_init(void)
Jaecheol Lee16638952011-03-10 13:33:59 +0900224{
Kukjin Kime085cad2013-06-26 22:29:44 +0900225 if (soc_is_exynos5440())
226 return 0;
227
Jongpill Leec9347102012-02-17 09:49:54 +0900228 register_syscore_ops(&exynos_pm_syscore_ops);
Rafael J. Wysockibb072c32011-04-22 22:03:21 +0200229 return 0;
Jaecheol Lee16638952011-03-10 13:33:59 +0900230}
Jongpill Lee60e49ca2012-02-17 12:23:51 +0900231arch_initcall(exynos_pm_syscore_init);