blob: 41c20692a13f0f189c1acaf011831048b6944a0a [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
32#include <mach/regs-irq.h>
Jaecheol Lee16638952011-03-10 13:33:59 +090033#include <mach/regs-clock.h>
34#include <mach/regs-pmu.h>
35#include <mach/pm-core.h>
Kukjin Kimccd458c2012-12-31 10:06:48 -080036
37#include "common.h"
Jaecheol Lee16638952011-03-10 13:33:59 +090038
39static struct sleep_save exynos4_set_clksrc[] = {
Kukjin Kima8550392012-03-09 14:19:10 -080040 { .reg = EXYNOS4_CLKSRC_MASK_TOP , .val = 0x00000001, },
41 { .reg = EXYNOS4_CLKSRC_MASK_CAM , .val = 0x11111111, },
42 { .reg = EXYNOS4_CLKSRC_MASK_TV , .val = 0x00000111, },
43 { .reg = EXYNOS4_CLKSRC_MASK_LCD0 , .val = 0x00001111, },
44 { .reg = EXYNOS4_CLKSRC_MASK_MAUDIO , .val = 0x00000001, },
45 { .reg = EXYNOS4_CLKSRC_MASK_FSYS , .val = 0x01011111, },
46 { .reg = EXYNOS4_CLKSRC_MASK_PERIL0 , .val = 0x01111111, },
47 { .reg = EXYNOS4_CLKSRC_MASK_PERIL1 , .val = 0x01110111, },
48 { .reg = EXYNOS4_CLKSRC_MASK_DMC , .val = 0x00010000, },
Jaecheol Lee16638952011-03-10 13:33:59 +090049};
50
Jonghwan Choiacd35612011-08-24 21:52:45 +090051static struct sleep_save exynos4210_set_clksrc[] = {
Kukjin Kima8550392012-03-09 14:19:10 -080052 { .reg = EXYNOS4210_CLKSRC_MASK_LCD1 , .val = 0x00001111, },
Jonghwan Choiacd35612011-08-24 21:52:45 +090053};
54
Jaecheol Lee56c03d92011-07-18 19:25:13 +090055static struct sleep_save exynos4_epll_save[] = {
Kukjin Kima8550392012-03-09 14:19:10 -080056 SAVE_ITEM(EXYNOS4_EPLL_CON0),
57 SAVE_ITEM(EXYNOS4_EPLL_CON1),
Jaecheol Lee56c03d92011-07-18 19:25:13 +090058};
59
60static struct sleep_save exynos4_vpll_save[] = {
Kukjin Kima8550392012-03-09 14:19:10 -080061 SAVE_ITEM(EXYNOS4_VPLL_CON0),
62 SAVE_ITEM(EXYNOS4_VPLL_CON1),
Jaecheol Lee56c03d92011-07-18 19:25:13 +090063};
64
Abhilash Kesavan86ffb0e2012-11-20 18:20:45 +090065static struct sleep_save exynos5_sys_save[] = {
66 SAVE_ITEM(EXYNOS5_SYS_I2C_CFG),
67};
68
Jongpill Leec9347102012-02-17 09:49:54 +090069static struct sleep_save exynos_core_save[] = {
MyungJoo Hamb93cb912011-07-21 11:25:23 +090070 /* SROM side */
71 SAVE_ITEM(S5P_SROM_BW),
72 SAVE_ITEM(S5P_SROM_BC0),
73 SAVE_ITEM(S5P_SROM_BC1),
74 SAVE_ITEM(S5P_SROM_BC2),
75 SAVE_ITEM(S5P_SROM_BC3),
Jaecheol Lee16638952011-03-10 13:33:59 +090076};
77
Jaecheol Lee16638952011-03-10 13:33:59 +090078
Jaecheol Leef4ba4b02011-07-18 19:25:03 +090079/* For Cortex-A9 Diagnostic and Power control register */
80static unsigned int save_arm_register[2];
81
Jongpill Leec9347102012-02-17 09:49:54 +090082static int exynos_cpu_suspend(unsigned long arg)
Jaecheol Lee16638952011-03-10 13:33:59 +090083{
Jongpill Lee60e49ca2012-02-17 12:23:51 +090084#ifdef CONFIG_CACHE_L2X0
Jaecheol Lee16638952011-03-10 13:33:59 +090085 outer_flush_all();
Jongpill Lee60e49ca2012-02-17 12:23:51 +090086#endif
Jaecheol Lee16638952011-03-10 13:33:59 +090087
Abhilash Kesavan573e5bb2012-11-22 14:46:40 +090088 if (soc_is_exynos5250())
89 flush_cache_all();
90
Jaecheol Lee16638952011-03-10 13:33:59 +090091 /* issue the standby signal into the pm unit. */
92 cpu_do_idle();
93
Abhilash Kesavand3fcacf2013-01-25 10:40:19 -080094 pr_info("Failed to suspend the system\n");
95 return 1; /* Aborting suspend */
Jaecheol Lee16638952011-03-10 13:33:59 +090096}
97
Jongpill Leec9347102012-02-17 09:49:54 +090098static void exynos_pm_prepare(void)
Jaecheol Lee16638952011-03-10 13:33:59 +090099{
Jongpill Lee60e49ca2012-02-17 12:23:51 +0900100 unsigned int tmp;
Jaecheol Lee16638952011-03-10 13:33:59 +0900101
Jongpill Leec9347102012-02-17 09:49:54 +0900102 s3c_pm_do_save(exynos_core_save, ARRAY_SIZE(exynos_core_save));
Jaecheol Lee16638952011-03-10 13:33:59 +0900103
Jongpill Lee60e49ca2012-02-17 12:23:51 +0900104 if (!soc_is_exynos5250()) {
105 s3c_pm_do_save(exynos4_epll_save, ARRAY_SIZE(exynos4_epll_save));
106 s3c_pm_do_save(exynos4_vpll_save, ARRAY_SIZE(exynos4_vpll_save));
107 } else {
Abhilash Kesavan86ffb0e2012-11-20 18:20:45 +0900108 s3c_pm_do_save(exynos5_sys_save, ARRAY_SIZE(exynos5_sys_save));
Jongpill Lee60e49ca2012-02-17 12:23:51 +0900109 /* Disable USE_RETENTION of JPEG_MEM_OPTION */
110 tmp = __raw_readl(EXYNOS5_JPEG_MEM_OPTION);
111 tmp &= ~EXYNOS5_OPTION_USE_RETENTION;
112 __raw_writel(tmp, EXYNOS5_JPEG_MEM_OPTION);
113 }
Jaecheol Lee16638952011-03-10 13:33:59 +0900114
115 /* Set value of power down register for sleep mode */
116
Jongpill Lee7d44d2b2012-02-17 09:51:31 +0900117 exynos_sys_powerdown_conf(SYS_SLEEP);
Jaecheol Lee16638952011-03-10 13:33:59 +0900118 __raw_writel(S5P_CHECK_SLEEP, S5P_INFORM1);
119
120 /* ensure at least INFORM0 has the resume address */
121
122 __raw_writel(virt_to_phys(s3c_cpu_resume), S5P_INFORM0);
123
124 /* Before enter central sequence mode, clock src register have to set */
125
Jongpill Lee60e49ca2012-02-17 12:23:51 +0900126 if (!soc_is_exynos5250())
127 s3c_pm_do_restore_core(exynos4_set_clksrc, ARRAY_SIZE(exynos4_set_clksrc));
Jaecheol Lee16638952011-03-10 13:33:59 +0900128
Jonghwan Choiacd35612011-08-24 21:52:45 +0900129 if (soc_is_exynos4210())
130 s3c_pm_do_restore_core(exynos4210_set_clksrc, ARRAY_SIZE(exynos4210_set_clksrc));
131
Jaecheol Lee16638952011-03-10 13:33:59 +0900132}
133
Jongpill Leec9347102012-02-17 09:49:54 +0900134static int exynos_pm_add(struct device *dev, struct subsys_interface *sif)
Jaecheol Lee16638952011-03-10 13:33:59 +0900135{
Jongpill Leec9347102012-02-17 09:49:54 +0900136 pm_cpu_prep = exynos_pm_prepare;
137 pm_cpu_sleep = exynos_cpu_suspend;
Jaecheol Lee16638952011-03-10 13:33:59 +0900138
139 return 0;
140}
141
Jaecheol Lee56c03d92011-07-18 19:25:13 +0900142static unsigned long pll_base_rate;
143
144static void exynos4_restore_pll(void)
145{
146 unsigned long pll_con, locktime, lockcnt;
147 unsigned long pll_in_rate;
148 unsigned int p_div, epll_wait = 0, vpll_wait = 0;
149
150 if (pll_base_rate == 0)
151 return;
152
153 pll_in_rate = pll_base_rate;
154
155 /* EPLL */
156 pll_con = exynos4_epll_save[0].val;
157
158 if (pll_con & (1 << 31)) {
159 pll_con &= (PLL46XX_PDIV_MASK << PLL46XX_PDIV_SHIFT);
160 p_div = (pll_con >> PLL46XX_PDIV_SHIFT);
161
162 pll_in_rate /= 1000000;
163
164 locktime = (3000 / pll_in_rate) * p_div;
165 lockcnt = locktime * 10000 / (10000 / pll_in_rate);
166
Kukjin Kima8550392012-03-09 14:19:10 -0800167 __raw_writel(lockcnt, EXYNOS4_EPLL_LOCK);
Jaecheol Lee56c03d92011-07-18 19:25:13 +0900168
169 s3c_pm_do_restore_core(exynos4_epll_save,
170 ARRAY_SIZE(exynos4_epll_save));
171 epll_wait = 1;
172 }
173
174 pll_in_rate = pll_base_rate;
175
176 /* VPLL */
177 pll_con = exynos4_vpll_save[0].val;
178
179 if (pll_con & (1 << 31)) {
180 pll_in_rate /= 1000000;
181 /* 750us */
182 locktime = 750;
183 lockcnt = locktime * 10000 / (10000 / pll_in_rate);
184
Kukjin Kima8550392012-03-09 14:19:10 -0800185 __raw_writel(lockcnt, EXYNOS4_VPLL_LOCK);
Jaecheol Lee56c03d92011-07-18 19:25:13 +0900186
187 s3c_pm_do_restore_core(exynos4_vpll_save,
188 ARRAY_SIZE(exynos4_vpll_save));
189 vpll_wait = 1;
190 }
191
192 /* Wait PLL locking */
193
194 do {
195 if (epll_wait) {
Kukjin Kima8550392012-03-09 14:19:10 -0800196 pll_con = __raw_readl(EXYNOS4_EPLL_CON0);
197 if (pll_con & (1 << EXYNOS4_EPLLCON0_LOCKED_SHIFT))
Jaecheol Lee56c03d92011-07-18 19:25:13 +0900198 epll_wait = 0;
199 }
200
201 if (vpll_wait) {
Kukjin Kima8550392012-03-09 14:19:10 -0800202 pll_con = __raw_readl(EXYNOS4_VPLL_CON0);
203 if (pll_con & (1 << EXYNOS4_VPLLCON0_LOCKED_SHIFT))
Jaecheol Lee56c03d92011-07-18 19:25:13 +0900204 vpll_wait = 0;
205 }
206 } while (epll_wait || vpll_wait);
207}
208
Jongpill Leec9347102012-02-17 09:49:54 +0900209static struct subsys_interface exynos_pm_interface = {
Jongpill Lee60e49ca2012-02-17 12:23:51 +0900210 .name = "exynos_pm",
Thomas Abraham9ee6af92012-05-15 15:47:40 +0900211 .subsys = &exynos_subsys,
Jongpill Leec9347102012-02-17 09:49:54 +0900212 .add_dev = exynos_pm_add,
Rafael J. Wysockibb072c32011-04-22 22:03:21 +0200213};
214
Jongpill Leec9347102012-02-17 09:49:54 +0900215static __init int exynos_pm_drvinit(void)
Rafael J. Wysockibb072c32011-04-22 22:03:21 +0200216{
Jaecheol Lee56c03d92011-07-18 19:25:13 +0900217 struct clk *pll_base;
Rafael J. Wysockibb072c32011-04-22 22:03:21 +0200218 unsigned int tmp;
219
220 s3c_pm_init();
221
222 /* All wakeup disable */
223
224 tmp = __raw_readl(S5P_WAKEUP_MASK);
225 tmp |= ((0xFF << 8) | (0x1F << 1));
226 __raw_writel(tmp, S5P_WAKEUP_MASK);
227
Jongpill Leec9347102012-02-17 09:49:54 +0900228 if (!soc_is_exynos5250()) {
229 pll_base = clk_get(NULL, "xtal");
Jaecheol Lee56c03d92011-07-18 19:25:13 +0900230
Jongpill Leec9347102012-02-17 09:49:54 +0900231 if (!IS_ERR(pll_base)) {
232 pll_base_rate = clk_get_rate(pll_base);
233 clk_put(pll_base);
234 }
Jaecheol Lee56c03d92011-07-18 19:25:13 +0900235 }
236
Jongpill Leec9347102012-02-17 09:49:54 +0900237 return subsys_interface_register(&exynos_pm_interface);
Rafael J. Wysockibb072c32011-04-22 22:03:21 +0200238}
Jongpill Leec9347102012-02-17 09:49:54 +0900239arch_initcall(exynos_pm_drvinit);
Rafael J. Wysockibb072c32011-04-22 22:03:21 +0200240
Jongpill Leec9347102012-02-17 09:49:54 +0900241static int exynos_pm_suspend(void)
Jaecheol Lee12974e92011-07-18 19:21:41 +0900242{
243 unsigned long tmp;
244
245 /* Setting Central Sequence Register for power down mode */
246
247 tmp = __raw_readl(S5P_CENTRAL_SEQ_CONFIGURATION);
248 tmp &= ~S5P_CENTRAL_LOWPWR_CFG;
249 __raw_writel(tmp, S5P_CENTRAL_SEQ_CONFIGURATION);
250
Jongpill Lee60e49ca2012-02-17 12:23:51 +0900251 /* Setting SEQ_OPTION register */
252
253 tmp = (S5P_USE_STANDBY_WFI0 | S5P_USE_STANDBY_WFE0);
254 __raw_writel(tmp, S5P_CENTRAL_SEQ_OPTION);
255
256 if (!soc_is_exynos5250()) {
257 /* Save Power control register */
258 asm ("mrc p15, 0, %0, c15, c0, 0"
259 : "=r" (tmp) : : "cc");
260 save_arm_register[0] = tmp;
261
262 /* Save Diagnostic register */
263 asm ("mrc p15, 0, %0, c15, c0, 1"
264 : "=r" (tmp) : : "cc");
265 save_arm_register[1] = tmp;
Jongpill Lee00a351f2011-09-27 07:26:04 +0900266 }
267
Jaecheol Lee12974e92011-07-18 19:21:41 +0900268 return 0;
269}
270
Jongpill Leec9347102012-02-17 09:49:54 +0900271static void exynos_pm_resume(void)
Jaecheol Lee16638952011-03-10 13:33:59 +0900272{
Jaecheol Leee240ab1c2011-07-18 19:21:34 +0900273 unsigned long tmp;
274
275 /*
276 * If PMU failed while entering sleep mode, WFI will be
277 * ignored by PMU and then exiting cpu_do_idle().
278 * S5P_CENTRAL_LOWPWR_CFG bit will not be set automatically
279 * in this situation.
280 */
281 tmp = __raw_readl(S5P_CENTRAL_SEQ_CONFIGURATION);
282 if (!(tmp & S5P_CENTRAL_LOWPWR_CFG)) {
283 tmp |= S5P_CENTRAL_LOWPWR_CFG;
284 __raw_writel(tmp, S5P_CENTRAL_SEQ_CONFIGURATION);
Abhilash Kesavand3fcacf2013-01-25 10:40:19 -0800285 /* clear the wakeup state register */
286 __raw_writel(0x0, S5P_WAKEUP_STAT);
Jaecheol Leee240ab1c2011-07-18 19:21:34 +0900287 /* No need to perform below restore code */
288 goto early_wakeup;
289 }
Jongpill Lee60e49ca2012-02-17 12:23:51 +0900290 if (!soc_is_exynos5250()) {
291 /* Restore Power control register */
292 tmp = save_arm_register[0];
293 asm volatile ("mcr p15, 0, %0, c15, c0, 0"
294 : : "r" (tmp)
295 : "cc");
Jaecheol Leef4ba4b02011-07-18 19:25:03 +0900296
Jongpill Lee60e49ca2012-02-17 12:23:51 +0900297 /* Restore Diagnostic register */
298 tmp = save_arm_register[1];
299 asm volatile ("mcr p15, 0, %0, c15, c0, 1"
300 : : "r" (tmp)
301 : "cc");
302 }
Jaecheol Leee240ab1c2011-07-18 19:21:34 +0900303
Jaecheol Lee16638952011-03-10 13:33:59 +0900304 /* For release retention */
305
306 __raw_writel((1 << 28), S5P_PAD_RET_MAUDIO_OPTION);
307 __raw_writel((1 << 28), S5P_PAD_RET_GPIO_OPTION);
308 __raw_writel((1 << 28), S5P_PAD_RET_UART_OPTION);
309 __raw_writel((1 << 28), S5P_PAD_RET_MMCA_OPTION);
310 __raw_writel((1 << 28), S5P_PAD_RET_MMCB_OPTION);
311 __raw_writel((1 << 28), S5P_PAD_RET_EBIA_OPTION);
312 __raw_writel((1 << 28), S5P_PAD_RET_EBIB_OPTION);
313
Abhilash Kesavan86ffb0e2012-11-20 18:20:45 +0900314 if (soc_is_exynos5250())
315 s3c_pm_do_restore(exynos5_sys_save,
316 ARRAY_SIZE(exynos5_sys_save));
317
Jongpill Leec9347102012-02-17 09:49:54 +0900318 s3c_pm_do_restore_core(exynos_core_save, ARRAY_SIZE(exynos_core_save));
Jaecheol Lee16638952011-03-10 13:33:59 +0900319
Jongpill Lee60e49ca2012-02-17 12:23:51 +0900320 if (!soc_is_exynos5250()) {
321 exynos4_restore_pll();
Jaecheol Lee56c03d92011-07-18 19:25:13 +0900322
Marek Szyprowski556ef3e2012-01-27 14:47:45 +0900323#ifdef CONFIG_SMP
Jongpill Lee60e49ca2012-02-17 12:23:51 +0900324 scu_enable(S5P_VA_SCU);
Marek Szyprowski556ef3e2012-01-27 14:47:45 +0900325#endif
Jongpill Lee60e49ca2012-02-17 12:23:51 +0900326 }
Jaecheol Lee16638952011-03-10 13:33:59 +0900327
Jaecheol Leee240ab1c2011-07-18 19:21:34 +0900328early_wakeup:
Inderpal Singhebee8542012-11-22 14:46:27 +0900329
330 /* Clear SLEEP mode set in INFORM1 */
331 __raw_writel(0x0, S5P_INFORM1);
332
Jaecheol Leee240ab1c2011-07-18 19:21:34 +0900333 return;
Jaecheol Lee16638952011-03-10 13:33:59 +0900334}
335
Jongpill Leec9347102012-02-17 09:49:54 +0900336static struct syscore_ops exynos_pm_syscore_ops = {
337 .suspend = exynos_pm_suspend,
338 .resume = exynos_pm_resume,
Jaecheol Lee16638952011-03-10 13:33:59 +0900339};
340
Jongpill Lee60e49ca2012-02-17 12:23:51 +0900341static __init int exynos_pm_syscore_init(void)
Jaecheol Lee16638952011-03-10 13:33:59 +0900342{
Jongpill Leec9347102012-02-17 09:49:54 +0900343 register_syscore_ops(&exynos_pm_syscore_ops);
Rafael J. Wysockibb072c32011-04-22 22:03:21 +0200344 return 0;
Jaecheol Lee16638952011-03-10 13:33:59 +0900345}
Jongpill Lee60e49ca2012-02-17 12:23:51 +0900346arch_initcall(exynos_pm_syscore_init);