blob: 4093fea849c39c1a4400b0ad460450dfc3f2e905 [file] [log] [blame]
Jaecheol Lee16638952011-03-10 13:33:59 +09001/* linux/arch/arm/mach-exynos4/pm.c
2 *
3 * Copyright (c) 2011 Samsung Electronics Co., Ltd.
4 * http://www.samsung.com
5 *
6 * EXYNOS4210 - Power Management support
7 *
8 * Based on arch/arm/mach-s3c2410/pm.c
9 * Copyright (c) 2006 Simtec Electronics
10 * Ben Dooks <ben@simtec.co.uk>
11 *
12 * This program is free software; you can redistribute it and/or modify
13 * it under the terms of the GNU General Public License version 2 as
14 * published by the Free Software Foundation.
15*/
16
17#include <linux/init.h>
18#include <linux/suspend.h>
Rafael J. Wysockibb072c32011-04-22 22:03:21 +020019#include <linux/syscore_ops.h>
Jaecheol Lee16638952011-03-10 13:33:59 +090020#include <linux/io.h>
Jaecheol Lee56c03d92011-07-18 19:25:13 +090021#include <linux/err.h>
22#include <linux/clk.h>
Jaecheol Lee16638952011-03-10 13:33:59 +090023
24#include <asm/cacheflush.h>
25#include <asm/hardware/cache-l2x0.h>
Shawn Guo63b870f2011-11-17 01:19:11 +090026#include <asm/smp_scu.h>
Jaecheol Lee16638952011-03-10 13:33:59 +090027
28#include <plat/cpu.h>
29#include <plat/pm.h>
Jaecheol Lee56c03d92011-07-18 19:25:13 +090030#include <plat/pll.h>
MyungJoo Hamb93cb912011-07-21 11:25:23 +090031#include <plat/regs-srom.h>
Jaecheol Lee16638952011-03-10 13:33:59 +090032
33#include <mach/regs-irq.h>
34#include <mach/regs-gpio.h>
35#include <mach/regs-clock.h>
36#include <mach/regs-pmu.h>
37#include <mach/pm-core.h>
Jaecheol Leee4cf2d12011-07-18 19:21:27 +090038#include <mach/pmu.h>
Jaecheol Lee16638952011-03-10 13:33:59 +090039
40static struct sleep_save exynos4_set_clksrc[] = {
41 { .reg = S5P_CLKSRC_MASK_TOP , .val = 0x00000001, },
42 { .reg = S5P_CLKSRC_MASK_CAM , .val = 0x11111111, },
43 { .reg = S5P_CLKSRC_MASK_TV , .val = 0x00000111, },
44 { .reg = S5P_CLKSRC_MASK_LCD0 , .val = 0x00001111, },
Jaecheol Lee16638952011-03-10 13:33:59 +090045 { .reg = S5P_CLKSRC_MASK_MAUDIO , .val = 0x00000001, },
46 { .reg = S5P_CLKSRC_MASK_FSYS , .val = 0x01011111, },
47 { .reg = S5P_CLKSRC_MASK_PERIL0 , .val = 0x01111111, },
48 { .reg = S5P_CLKSRC_MASK_PERIL1 , .val = 0x01110111, },
49 { .reg = S5P_CLKSRC_MASK_DMC , .val = 0x00010000, },
50};
51
Jonghwan Choiacd35612011-08-24 21:52:45 +090052static struct sleep_save exynos4210_set_clksrc[] = {
53 { .reg = S5P_CLKSRC_MASK_LCD1 , .val = 0x00001111, },
54};
55
Jaecheol Lee56c03d92011-07-18 19:25:13 +090056static struct sleep_save exynos4_epll_save[] = {
57 SAVE_ITEM(S5P_EPLL_CON0),
58 SAVE_ITEM(S5P_EPLL_CON1),
59};
60
61static struct sleep_save exynos4_vpll_save[] = {
62 SAVE_ITEM(S5P_VPLL_CON0),
63 SAVE_ITEM(S5P_VPLL_CON1),
64};
65
Jaecheol Lee16638952011-03-10 13:33:59 +090066static struct sleep_save exynos4_core_save[] = {
Jaecheol Lee16638952011-03-10 13:33:59 +090067 /* GIC side */
68 SAVE_ITEM(S5P_VA_GIC_CPU + 0x000),
69 SAVE_ITEM(S5P_VA_GIC_CPU + 0x004),
70 SAVE_ITEM(S5P_VA_GIC_CPU + 0x008),
71 SAVE_ITEM(S5P_VA_GIC_CPU + 0x00C),
72 SAVE_ITEM(S5P_VA_GIC_CPU + 0x014),
73 SAVE_ITEM(S5P_VA_GIC_CPU + 0x018),
74 SAVE_ITEM(S5P_VA_GIC_DIST + 0x000),
75 SAVE_ITEM(S5P_VA_GIC_DIST + 0x004),
76 SAVE_ITEM(S5P_VA_GIC_DIST + 0x100),
77 SAVE_ITEM(S5P_VA_GIC_DIST + 0x104),
78 SAVE_ITEM(S5P_VA_GIC_DIST + 0x108),
79 SAVE_ITEM(S5P_VA_GIC_DIST + 0x300),
80 SAVE_ITEM(S5P_VA_GIC_DIST + 0x304),
81 SAVE_ITEM(S5P_VA_GIC_DIST + 0x308),
82 SAVE_ITEM(S5P_VA_GIC_DIST + 0x400),
83 SAVE_ITEM(S5P_VA_GIC_DIST + 0x404),
84 SAVE_ITEM(S5P_VA_GIC_DIST + 0x408),
85 SAVE_ITEM(S5P_VA_GIC_DIST + 0x40C),
86 SAVE_ITEM(S5P_VA_GIC_DIST + 0x410),
87 SAVE_ITEM(S5P_VA_GIC_DIST + 0x414),
88 SAVE_ITEM(S5P_VA_GIC_DIST + 0x418),
89 SAVE_ITEM(S5P_VA_GIC_DIST + 0x41C),
90 SAVE_ITEM(S5P_VA_GIC_DIST + 0x420),
91 SAVE_ITEM(S5P_VA_GIC_DIST + 0x424),
92 SAVE_ITEM(S5P_VA_GIC_DIST + 0x428),
93 SAVE_ITEM(S5P_VA_GIC_DIST + 0x42C),
94 SAVE_ITEM(S5P_VA_GIC_DIST + 0x430),
95 SAVE_ITEM(S5P_VA_GIC_DIST + 0x434),
96 SAVE_ITEM(S5P_VA_GIC_DIST + 0x438),
97 SAVE_ITEM(S5P_VA_GIC_DIST + 0x43C),
98 SAVE_ITEM(S5P_VA_GIC_DIST + 0x440),
99 SAVE_ITEM(S5P_VA_GIC_DIST + 0x444),
100 SAVE_ITEM(S5P_VA_GIC_DIST + 0x448),
101 SAVE_ITEM(S5P_VA_GIC_DIST + 0x44C),
102 SAVE_ITEM(S5P_VA_GIC_DIST + 0x450),
103 SAVE_ITEM(S5P_VA_GIC_DIST + 0x454),
104 SAVE_ITEM(S5P_VA_GIC_DIST + 0x458),
105 SAVE_ITEM(S5P_VA_GIC_DIST + 0x45C),
106
107 SAVE_ITEM(S5P_VA_GIC_DIST + 0x800),
108 SAVE_ITEM(S5P_VA_GIC_DIST + 0x804),
109 SAVE_ITEM(S5P_VA_GIC_DIST + 0x808),
110 SAVE_ITEM(S5P_VA_GIC_DIST + 0x80C),
111 SAVE_ITEM(S5P_VA_GIC_DIST + 0x810),
112 SAVE_ITEM(S5P_VA_GIC_DIST + 0x814),
113 SAVE_ITEM(S5P_VA_GIC_DIST + 0x818),
114 SAVE_ITEM(S5P_VA_GIC_DIST + 0x81C),
115 SAVE_ITEM(S5P_VA_GIC_DIST + 0x820),
116 SAVE_ITEM(S5P_VA_GIC_DIST + 0x824),
117 SAVE_ITEM(S5P_VA_GIC_DIST + 0x828),
118 SAVE_ITEM(S5P_VA_GIC_DIST + 0x82C),
119 SAVE_ITEM(S5P_VA_GIC_DIST + 0x830),
120 SAVE_ITEM(S5P_VA_GIC_DIST + 0x834),
121 SAVE_ITEM(S5P_VA_GIC_DIST + 0x838),
122 SAVE_ITEM(S5P_VA_GIC_DIST + 0x83C),
123 SAVE_ITEM(S5P_VA_GIC_DIST + 0x840),
124 SAVE_ITEM(S5P_VA_GIC_DIST + 0x844),
125 SAVE_ITEM(S5P_VA_GIC_DIST + 0x848),
126 SAVE_ITEM(S5P_VA_GIC_DIST + 0x84C),
127 SAVE_ITEM(S5P_VA_GIC_DIST + 0x850),
128 SAVE_ITEM(S5P_VA_GIC_DIST + 0x854),
129 SAVE_ITEM(S5P_VA_GIC_DIST + 0x858),
130 SAVE_ITEM(S5P_VA_GIC_DIST + 0x85C),
131
132 SAVE_ITEM(S5P_VA_GIC_DIST + 0xC00),
133 SAVE_ITEM(S5P_VA_GIC_DIST + 0xC04),
134 SAVE_ITEM(S5P_VA_GIC_DIST + 0xC08),
135 SAVE_ITEM(S5P_VA_GIC_DIST + 0xC0C),
136 SAVE_ITEM(S5P_VA_GIC_DIST + 0xC10),
137 SAVE_ITEM(S5P_VA_GIC_DIST + 0xC14),
138
139 SAVE_ITEM(S5P_VA_COMBINER_BASE + 0x000),
140 SAVE_ITEM(S5P_VA_COMBINER_BASE + 0x010),
141 SAVE_ITEM(S5P_VA_COMBINER_BASE + 0x020),
142 SAVE_ITEM(S5P_VA_COMBINER_BASE + 0x030),
143 SAVE_ITEM(S5P_VA_COMBINER_BASE + 0x040),
144 SAVE_ITEM(S5P_VA_COMBINER_BASE + 0x050),
145 SAVE_ITEM(S5P_VA_COMBINER_BASE + 0x060),
146 SAVE_ITEM(S5P_VA_COMBINER_BASE + 0x070),
147 SAVE_ITEM(S5P_VA_COMBINER_BASE + 0x080),
148 SAVE_ITEM(S5P_VA_COMBINER_BASE + 0x090),
MyungJoo Hamb93cb912011-07-21 11:25:23 +0900149
150 /* SROM side */
151 SAVE_ITEM(S5P_SROM_BW),
152 SAVE_ITEM(S5P_SROM_BC0),
153 SAVE_ITEM(S5P_SROM_BC1),
154 SAVE_ITEM(S5P_SROM_BC2),
155 SAVE_ITEM(S5P_SROM_BC3),
Jaecheol Lee16638952011-03-10 13:33:59 +0900156};
157
158static struct sleep_save exynos4_l2cc_save[] = {
159 SAVE_ITEM(S5P_VA_L2CC + L2X0_TAG_LATENCY_CTRL),
160 SAVE_ITEM(S5P_VA_L2CC + L2X0_DATA_LATENCY_CTRL),
161 SAVE_ITEM(S5P_VA_L2CC + L2X0_PREFETCH_CTRL),
162 SAVE_ITEM(S5P_VA_L2CC + L2X0_POWER_CTRL),
163 SAVE_ITEM(S5P_VA_L2CC + L2X0_AUX_CTRL),
164};
165
Jaecheol Leef4ba4b02011-07-18 19:25:03 +0900166/* For Cortex-A9 Diagnostic and Power control register */
167static unsigned int save_arm_register[2];
168
Russell King29cb3cd2011-07-02 09:54:01 +0100169static int exynos4_cpu_suspend(unsigned long arg)
Jaecheol Lee16638952011-03-10 13:33:59 +0900170{
Jaecheol Lee16638952011-03-10 13:33:59 +0900171 outer_flush_all();
172
173 /* issue the standby signal into the pm unit. */
174 cpu_do_idle();
175
176 /* we should never get past here */
177 panic("sleep resumed to originator?");
178}
179
180static void exynos4_pm_prepare(void)
181{
182 u32 tmp;
183
184 s3c_pm_do_save(exynos4_core_save, ARRAY_SIZE(exynos4_core_save));
185 s3c_pm_do_save(exynos4_l2cc_save, ARRAY_SIZE(exynos4_l2cc_save));
Jaecheol Lee56c03d92011-07-18 19:25:13 +0900186 s3c_pm_do_save(exynos4_epll_save, ARRAY_SIZE(exynos4_epll_save));
187 s3c_pm_do_save(exynos4_vpll_save, ARRAY_SIZE(exynos4_vpll_save));
Jaecheol Lee16638952011-03-10 13:33:59 +0900188
189 tmp = __raw_readl(S5P_INFORM1);
190
191 /* Set value of power down register for sleep mode */
192
Jaecheol Leee4cf2d12011-07-18 19:21:27 +0900193 exynos4_sys_powerdown_conf(SYS_SLEEP);
Jaecheol Lee16638952011-03-10 13:33:59 +0900194 __raw_writel(S5P_CHECK_SLEEP, S5P_INFORM1);
195
196 /* ensure at least INFORM0 has the resume address */
197
198 __raw_writel(virt_to_phys(s3c_cpu_resume), S5P_INFORM0);
199
200 /* Before enter central sequence mode, clock src register have to set */
201
202 s3c_pm_do_restore_core(exynos4_set_clksrc, ARRAY_SIZE(exynos4_set_clksrc));
203
Jonghwan Choiacd35612011-08-24 21:52:45 +0900204 if (soc_is_exynos4210())
205 s3c_pm_do_restore_core(exynos4210_set_clksrc, ARRAY_SIZE(exynos4210_set_clksrc));
206
Jaecheol Lee16638952011-03-10 13:33:59 +0900207}
208
209static int exynos4_pm_add(struct sys_device *sysdev)
210{
211 pm_cpu_prep = exynos4_pm_prepare;
212 pm_cpu_sleep = exynos4_cpu_suspend;
213
214 return 0;
215}
216
Jaecheol Lee56c03d92011-07-18 19:25:13 +0900217static unsigned long pll_base_rate;
218
219static void exynos4_restore_pll(void)
220{
221 unsigned long pll_con, locktime, lockcnt;
222 unsigned long pll_in_rate;
223 unsigned int p_div, epll_wait = 0, vpll_wait = 0;
224
225 if (pll_base_rate == 0)
226 return;
227
228 pll_in_rate = pll_base_rate;
229
230 /* EPLL */
231 pll_con = exynos4_epll_save[0].val;
232
233 if (pll_con & (1 << 31)) {
234 pll_con &= (PLL46XX_PDIV_MASK << PLL46XX_PDIV_SHIFT);
235 p_div = (pll_con >> PLL46XX_PDIV_SHIFT);
236
237 pll_in_rate /= 1000000;
238
239 locktime = (3000 / pll_in_rate) * p_div;
240 lockcnt = locktime * 10000 / (10000 / pll_in_rate);
241
242 __raw_writel(lockcnt, S5P_EPLL_LOCK);
243
244 s3c_pm_do_restore_core(exynos4_epll_save,
245 ARRAY_SIZE(exynos4_epll_save));
246 epll_wait = 1;
247 }
248
249 pll_in_rate = pll_base_rate;
250
251 /* VPLL */
252 pll_con = exynos4_vpll_save[0].val;
253
254 if (pll_con & (1 << 31)) {
255 pll_in_rate /= 1000000;
256 /* 750us */
257 locktime = 750;
258 lockcnt = locktime * 10000 / (10000 / pll_in_rate);
259
260 __raw_writel(lockcnt, S5P_VPLL_LOCK);
261
262 s3c_pm_do_restore_core(exynos4_vpll_save,
263 ARRAY_SIZE(exynos4_vpll_save));
264 vpll_wait = 1;
265 }
266
267 /* Wait PLL locking */
268
269 do {
270 if (epll_wait) {
271 pll_con = __raw_readl(S5P_EPLL_CON0);
272 if (pll_con & (1 << S5P_EPLLCON0_LOCKED_SHIFT))
273 epll_wait = 0;
274 }
275
276 if (vpll_wait) {
277 pll_con = __raw_readl(S5P_VPLL_CON0);
278 if (pll_con & (1 << S5P_VPLLCON0_LOCKED_SHIFT))
279 vpll_wait = 0;
280 }
281 } while (epll_wait || vpll_wait);
282}
283
Rafael J. Wysockibb072c32011-04-22 22:03:21 +0200284static struct sysdev_driver exynos4_pm_driver = {
285 .add = exynos4_pm_add,
286};
287
288static __init int exynos4_pm_drvinit(void)
289{
Jaecheol Lee56c03d92011-07-18 19:25:13 +0900290 struct clk *pll_base;
Rafael J. Wysockibb072c32011-04-22 22:03:21 +0200291 unsigned int tmp;
292
293 s3c_pm_init();
294
295 /* All wakeup disable */
296
297 tmp = __raw_readl(S5P_WAKEUP_MASK);
298 tmp |= ((0xFF << 8) | (0x1F << 1));
299 __raw_writel(tmp, S5P_WAKEUP_MASK);
300
Jaecheol Lee56c03d92011-07-18 19:25:13 +0900301 pll_base = clk_get(NULL, "xtal");
302
303 if (!IS_ERR(pll_base)) {
304 pll_base_rate = clk_get_rate(pll_base);
305 clk_put(pll_base);
306 }
307
Rafael J. Wysockibb072c32011-04-22 22:03:21 +0200308 return sysdev_driver_register(&exynos4_sysclass, &exynos4_pm_driver);
309}
310arch_initcall(exynos4_pm_drvinit);
311
Jaecheol Lee12974e92011-07-18 19:21:41 +0900312static int exynos4_pm_suspend(void)
313{
314 unsigned long tmp;
315
316 /* Setting Central Sequence Register for power down mode */
317
318 tmp = __raw_readl(S5P_CENTRAL_SEQ_CONFIGURATION);
319 tmp &= ~S5P_CENTRAL_LOWPWR_CFG;
320 __raw_writel(tmp, S5P_CENTRAL_SEQ_CONFIGURATION);
321
Jongpill Lee00a351f2011-09-27 07:26:04 +0900322 if (soc_is_exynos4212()) {
323 tmp = __raw_readl(S5P_CENTRAL_SEQ_OPTION);
324 tmp &= ~(S5P_USE_STANDBYWFI_ISP_ARM |
325 S5P_USE_STANDBYWFE_ISP_ARM);
326 __raw_writel(tmp, S5P_CENTRAL_SEQ_OPTION);
327 }
328
Jaecheol Leef4ba4b02011-07-18 19:25:03 +0900329 /* Save Power control register */
330 asm ("mrc p15, 0, %0, c15, c0, 0"
331 : "=r" (tmp) : : "cc");
332 save_arm_register[0] = tmp;
333
334 /* Save Diagnostic register */
335 asm ("mrc p15, 0, %0, c15, c0, 1"
336 : "=r" (tmp) : : "cc");
337 save_arm_register[1] = tmp;
338
Jaecheol Lee12974e92011-07-18 19:21:41 +0900339 return 0;
340}
341
Rafael J. Wysockibb072c32011-04-22 22:03:21 +0200342static void exynos4_pm_resume(void)
Jaecheol Lee16638952011-03-10 13:33:59 +0900343{
Jaecheol Leee240ab1c2011-07-18 19:21:34 +0900344 unsigned long tmp;
345
346 /*
347 * If PMU failed while entering sleep mode, WFI will be
348 * ignored by PMU and then exiting cpu_do_idle().
349 * S5P_CENTRAL_LOWPWR_CFG bit will not be set automatically
350 * in this situation.
351 */
352 tmp = __raw_readl(S5P_CENTRAL_SEQ_CONFIGURATION);
353 if (!(tmp & S5P_CENTRAL_LOWPWR_CFG)) {
354 tmp |= S5P_CENTRAL_LOWPWR_CFG;
355 __raw_writel(tmp, S5P_CENTRAL_SEQ_CONFIGURATION);
356 /* No need to perform below restore code */
357 goto early_wakeup;
358 }
Jaecheol Leef4ba4b02011-07-18 19:25:03 +0900359 /* Restore Power control register */
360 tmp = save_arm_register[0];
361 asm volatile ("mcr p15, 0, %0, c15, c0, 0"
362 : : "r" (tmp)
363 : "cc");
364
365 /* Restore Diagnostic register */
366 tmp = save_arm_register[1];
367 asm volatile ("mcr p15, 0, %0, c15, c0, 1"
368 : : "r" (tmp)
369 : "cc");
Jaecheol Leee240ab1c2011-07-18 19:21:34 +0900370
Jaecheol Lee16638952011-03-10 13:33:59 +0900371 /* For release retention */
372
373 __raw_writel((1 << 28), S5P_PAD_RET_MAUDIO_OPTION);
374 __raw_writel((1 << 28), S5P_PAD_RET_GPIO_OPTION);
375 __raw_writel((1 << 28), S5P_PAD_RET_UART_OPTION);
376 __raw_writel((1 << 28), S5P_PAD_RET_MMCA_OPTION);
377 __raw_writel((1 << 28), S5P_PAD_RET_MMCB_OPTION);
378 __raw_writel((1 << 28), S5P_PAD_RET_EBIA_OPTION);
379 __raw_writel((1 << 28), S5P_PAD_RET_EBIB_OPTION);
380
381 s3c_pm_do_restore_core(exynos4_core_save, ARRAY_SIZE(exynos4_core_save));
382
Jaecheol Lee56c03d92011-07-18 19:25:13 +0900383 exynos4_restore_pll();
384
Shawn Guo63b870f2011-11-17 01:19:11 +0900385 scu_enable(S5P_VA_SCU);
Jaecheol Lee16638952011-03-10 13:33:59 +0900386
387#ifdef CONFIG_CACHE_L2X0
388 s3c_pm_do_restore_core(exynos4_l2cc_save, ARRAY_SIZE(exynos4_l2cc_save));
389 outer_inv_all();
390 /* enable L2X0*/
391 writel_relaxed(1, S5P_VA_L2CC + L2X0_CTRL);
392#endif
Jaecheol Leee240ab1c2011-07-18 19:21:34 +0900393
394early_wakeup:
395 return;
Jaecheol Lee16638952011-03-10 13:33:59 +0900396}
397
Rafael J. Wysockibb072c32011-04-22 22:03:21 +0200398static struct syscore_ops exynos4_pm_syscore_ops = {
Jaecheol Lee12974e92011-07-18 19:21:41 +0900399 .suspend = exynos4_pm_suspend,
Jaecheol Lee16638952011-03-10 13:33:59 +0900400 .resume = exynos4_pm_resume,
401};
402
Rafael J. Wysockibb072c32011-04-22 22:03:21 +0200403static __init int exynos4_pm_syscore_init(void)
Jaecheol Lee16638952011-03-10 13:33:59 +0900404{
Rafael J. Wysockibb072c32011-04-22 22:03:21 +0200405 register_syscore_ops(&exynos4_pm_syscore_ops);
406 return 0;
Jaecheol Lee16638952011-03-10 13:33:59 +0900407}
Rafael J. Wysockibb072c32011-04-22 22:03:21 +0200408arch_initcall(exynos4_pm_syscore_init);