blob: 8cef6141c408a4752e17ed45838e1d4a8e2df5a0 [file] [log] [blame]
Bartlomiej Zolnierkiewicz0d713cf2014-09-25 18:02:45 +09001/*
2 * Copyright (c) 2011-2014 Samsung Electronics Co., Ltd.
3 * http://www.samsung.com
4 *
5 * EXYNOS - Suspend support
6 *
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>
18#include <linux/syscore_ops.h>
19#include <linux/cpu_pm.h>
20#include <linux/io.h>
21#include <linux/irqchip/arm-gic.h>
22#include <linux/err.h>
23
24#include <asm/cacheflush.h>
25#include <asm/hardware/cache-l2x0.h>
26#include <asm/firmware.h>
27#include <asm/smp_scu.h>
28#include <asm/suspend.h>
29
30#include <plat/pm-common.h>
31#include <plat/regs-srom.h>
32
33#include "common.h"
34#include "regs-pmu.h"
35#include "regs-sys.h"
Pankaj Dubey6b7bfd82014-11-07 09:26:47 +090036#include "exynos-pmu.h"
Bartlomiej Zolnierkiewicz0d713cf2014-09-25 18:02:45 +090037
38#define S5P_CHECK_SLEEP 0x00000BAD
39
40#define REG_TABLE_END (-1U)
41
Vikas Sajjan0fdf0882014-11-07 09:17:36 +090042#define EXYNOS5420_CPU_STATE 0x28
43
Bartlomiej Zolnierkiewicz0d713cf2014-09-25 18:02:45 +090044/**
45 * struct exynos_wkup_irq - Exynos GIC to PMU IRQ mapping
46 * @hwirq: Hardware IRQ signal of the GIC
47 * @mask: Mask in PMU wake-up mask register
48 */
49struct exynos_wkup_irq {
50 unsigned int hwirq;
51 u32 mask;
52};
53
54static struct sleep_save exynos5_sys_save[] = {
55 SAVE_ITEM(EXYNOS5_SYS_I2C_CFG),
56};
57
58static struct sleep_save exynos_core_save[] = {
59 /* SROM side */
60 SAVE_ITEM(S5P_SROM_BW),
61 SAVE_ITEM(S5P_SROM_BC0),
62 SAVE_ITEM(S5P_SROM_BC1),
63 SAVE_ITEM(S5P_SROM_BC2),
64 SAVE_ITEM(S5P_SROM_BC3),
65};
66
67struct exynos_pm_data {
68 const struct exynos_wkup_irq *wkup_irq;
69 struct sleep_save *extra_save;
70 int num_extra_save;
71 unsigned int wake_disable_mask;
72 unsigned int *release_ret_regs;
73
74 void (*pm_prepare)(void);
75 void (*pm_resume)(void);
76 int (*pm_suspend)(void);
77 int (*cpu_suspend)(unsigned long);
78};
79
80struct exynos_pm_data *pm_data;
81
Vikas Sajjan0fdf0882014-11-07 09:17:36 +090082static int exynos5420_cpu_state;
83static unsigned int exynos_pmu_spare3;
84
Bartlomiej Zolnierkiewicz0d713cf2014-09-25 18:02:45 +090085/*
86 * GIC wake-up support
87 */
88
89static u32 exynos_irqwake_intmask = 0xffffffff;
90
91static const struct exynos_wkup_irq exynos4_wkup_irq[] = {
92 { 76, BIT(1) }, /* RTC alarm */
93 { 77, BIT(2) }, /* RTC tick */
94 { /* sentinel */ },
95};
96
97static const struct exynos_wkup_irq exynos5250_wkup_irq[] = {
98 { 75, BIT(1) }, /* RTC alarm */
99 { 76, BIT(2) }, /* RTC tick */
100 { /* sentinel */ },
101};
102
103unsigned int exynos_release_ret_regs[] = {
104 S5P_PAD_RET_MAUDIO_OPTION,
105 S5P_PAD_RET_GPIO_OPTION,
106 S5P_PAD_RET_UART_OPTION,
107 S5P_PAD_RET_MMCA_OPTION,
108 S5P_PAD_RET_MMCB_OPTION,
109 S5P_PAD_RET_EBIA_OPTION,
110 S5P_PAD_RET_EBIB_OPTION,
111 REG_TABLE_END,
112};
113
Vikas Sajjan0fdf0882014-11-07 09:17:36 +0900114unsigned int exynos5420_release_ret_regs[] = {
115 EXYNOS_PAD_RET_DRAM_OPTION,
116 EXYNOS_PAD_RET_MAUDIO_OPTION,
117 EXYNOS_PAD_RET_JTAG_OPTION,
118 EXYNOS5420_PAD_RET_GPIO_OPTION,
119 EXYNOS5420_PAD_RET_UART_OPTION,
120 EXYNOS5420_PAD_RET_MMCA_OPTION,
121 EXYNOS5420_PAD_RET_MMCB_OPTION,
122 EXYNOS5420_PAD_RET_MMCC_OPTION,
123 EXYNOS5420_PAD_RET_HSI_OPTION,
124 EXYNOS_PAD_RET_EBIA_OPTION,
125 EXYNOS_PAD_RET_EBIB_OPTION,
126 EXYNOS5420_PAD_RET_SPI_OPTION,
127 EXYNOS5420_PAD_RET_DRAM_COREBLK_OPTION,
128 REG_TABLE_END,
129};
130
Bartlomiej Zolnierkiewicz0d713cf2014-09-25 18:02:45 +0900131static int exynos_irq_set_wake(struct irq_data *data, unsigned int state)
132{
133 const struct exynos_wkup_irq *wkup_irq;
134
135 if (!pm_data->wkup_irq)
136 return -ENOENT;
137 wkup_irq = pm_data->wkup_irq;
138
139 while (wkup_irq->mask) {
140 if (wkup_irq->hwirq == data->hwirq) {
141 if (!state)
142 exynos_irqwake_intmask |= wkup_irq->mask;
143 else
144 exynos_irqwake_intmask &= ~wkup_irq->mask;
145 return 0;
146 }
147 ++wkup_irq;
148 }
149
150 return -ENOENT;
151}
152
153static int exynos_cpu_do_idle(void)
154{
155 /* issue the standby signal into the pm unit. */
156 cpu_do_idle();
157
158 pr_info("Failed to suspend the system\n");
159 return 1; /* Aborting suspend */
160}
Vikas Sajjan0fdf0882014-11-07 09:17:36 +0900161static void exynos_flush_cache_all(void)
Bartlomiej Zolnierkiewicz0d713cf2014-09-25 18:02:45 +0900162{
163 flush_cache_all();
164 outer_flush_all();
Vikas Sajjan0fdf0882014-11-07 09:17:36 +0900165}
166
167static int exynos_cpu_suspend(unsigned long arg)
168{
169 exynos_flush_cache_all();
170 return exynos_cpu_do_idle();
171}
172
173static int exynos5420_cpu_suspend(unsigned long arg)
174{
175 exynos_flush_cache_all();
176 __raw_writel(0x0, sysram_base_addr + EXYNOS5420_CPU_STATE);
Bartlomiej Zolnierkiewicz0d713cf2014-09-25 18:02:45 +0900177 return exynos_cpu_do_idle();
178}
179
180static void exynos_pm_set_wakeup_mask(void)
181{
182 /* Set wake-up mask registers */
183 pmu_raw_writel(exynos_get_eint_wake_mask(), S5P_EINT_WAKEUP_MASK);
184 pmu_raw_writel(exynos_irqwake_intmask & ~(1 << 31), S5P_WAKEUP_MASK);
185}
186
187static void exynos_pm_enter_sleep_mode(void)
188{
189 /* Set value of power down register for sleep mode */
190 exynos_sys_powerdown_conf(SYS_SLEEP);
191 pmu_raw_writel(S5P_CHECK_SLEEP, S5P_INFORM1);
192
193 /* ensure at least INFORM0 has the resume address */
194 pmu_raw_writel(virt_to_phys(exynos_cpu_resume), S5P_INFORM0);
195}
196
197static void exynos_pm_prepare(void)
198{
199 /* Set wake-up mask registers */
200 exynos_pm_set_wakeup_mask();
201
202 s3c_pm_do_save(exynos_core_save, ARRAY_SIZE(exynos_core_save));
203
204 if (pm_data->extra_save)
205 s3c_pm_do_save(pm_data->extra_save,
206 pm_data->num_extra_save);
207
208 exynos_pm_enter_sleep_mode();
209}
210
Vikas Sajjan0fdf0882014-11-07 09:17:36 +0900211static void exynos5420_pm_prepare(void)
212{
213 unsigned int tmp;
214
215 /* Set wake-up mask registers */
216 exynos_pm_set_wakeup_mask();
217
218 s3c_pm_do_save(exynos_core_save, ARRAY_SIZE(exynos_core_save));
219
220 exynos_pmu_spare3 = pmu_raw_readl(S5P_PMU_SPARE3);
221 /*
222 * The cpu state needs to be saved and restored so that the
223 * secondary CPUs will enter low power start. Though the U-Boot
224 * is setting the cpu state with low power flag, the kernel
225 * needs to restore it back in case, the primary cpu fails to
226 * suspend for any reason.
227 */
228 exynos5420_cpu_state = __raw_readl(sysram_base_addr +
229 EXYNOS5420_CPU_STATE);
230
231 exynos_pm_enter_sleep_mode();
232
233 tmp = pmu_raw_readl(EXYNOS5_ARM_L2_OPTION);
234 tmp &= ~EXYNOS5_USE_RETENTION;
235 pmu_raw_writel(tmp, EXYNOS5_ARM_L2_OPTION);
236
237 tmp = pmu_raw_readl(EXYNOS5420_SFR_AXI_CGDIS1);
238 tmp |= EXYNOS5420_UFS;
239 pmu_raw_writel(tmp, EXYNOS5420_SFR_AXI_CGDIS1);
240
241 tmp = pmu_raw_readl(EXYNOS5420_ARM_COMMON_OPTION);
242 tmp &= ~EXYNOS5420_L2RSTDISABLE_VALUE;
243 pmu_raw_writel(tmp, EXYNOS5420_ARM_COMMON_OPTION);
244
245 tmp = pmu_raw_readl(EXYNOS5420_FSYS2_OPTION);
246 tmp |= EXYNOS5420_EMULATION;
247 pmu_raw_writel(tmp, EXYNOS5420_FSYS2_OPTION);
248
249 tmp = pmu_raw_readl(EXYNOS5420_PSGEN_OPTION);
250 tmp |= EXYNOS5420_EMULATION;
251 pmu_raw_writel(tmp, EXYNOS5420_PSGEN_OPTION);
252}
253
254
Bartlomiej Zolnierkiewicz0d713cf2014-09-25 18:02:45 +0900255static int exynos_pm_suspend(void)
256{
257 exynos_pm_central_suspend();
258
259 if (read_cpuid_part() == ARM_CPU_PART_CORTEX_A9)
260 exynos_cpu_save_register();
261
262 return 0;
263}
264
Vikas Sajjan0fdf0882014-11-07 09:17:36 +0900265static int exynos5420_pm_suspend(void)
266{
267 u32 this_cluster;
268
269 exynos_pm_central_suspend();
270
271 /* Setting SEQ_OPTION register */
272
273 this_cluster = MPIDR_AFFINITY_LEVEL(read_cpuid_mpidr(), 1);
274 if (!this_cluster)
275 pmu_raw_writel(EXYNOS5420_ARM_USE_STANDBY_WFI0,
276 S5P_CENTRAL_SEQ_OPTION);
277 else
278 pmu_raw_writel(EXYNOS5420_KFC_USE_STANDBY_WFI0,
279 S5P_CENTRAL_SEQ_OPTION);
280 return 0;
281}
282
Bartlomiej Zolnierkiewicz0d713cf2014-09-25 18:02:45 +0900283static void exynos_pm_release_retention(void)
284{
285 unsigned int i;
286
287 for (i = 0; (pm_data->release_ret_regs[i] != REG_TABLE_END); i++)
288 pmu_raw_writel(EXYNOS_WAKEUP_FROM_LOWPWR,
289 pm_data->release_ret_regs[i]);
290}
291
292static void exynos_pm_resume(void)
293{
294 u32 cpuid = read_cpuid_part();
295
296 if (exynos_pm_central_resume())
297 goto early_wakeup;
298
299 /* For release retention */
300 exynos_pm_release_retention();
301
302 if (pm_data->extra_save)
303 s3c_pm_do_restore_core(pm_data->extra_save,
304 pm_data->num_extra_save);
305
306 s3c_pm_do_restore_core(exynos_core_save, ARRAY_SIZE(exynos_core_save));
307
308 if (cpuid == ARM_CPU_PART_CORTEX_A9)
309 scu_enable(S5P_VA_SCU);
310
311 if (call_firmware_op(resume) == -ENOSYS
312 && cpuid == ARM_CPU_PART_CORTEX_A9)
313 exynos_cpu_restore_register();
314
315early_wakeup:
316
317 /* Clear SLEEP mode set in INFORM1 */
318 pmu_raw_writel(0x0, S5P_INFORM1);
319}
320
Vikas Sajjan0fdf0882014-11-07 09:17:36 +0900321static void exynos5420_pm_resume(void)
322{
323 unsigned long tmp;
324
325 /* Restore the sysram cpu state register */
326 __raw_writel(exynos5420_cpu_state,
327 sysram_base_addr + EXYNOS5420_CPU_STATE);
328
329 pmu_raw_writel(EXYNOS5420_USE_STANDBY_WFI_ALL,
330 S5P_CENTRAL_SEQ_OPTION);
331
332 if (exynos_pm_central_resume())
333 goto early_wakeup;
334
335 /* For release retention */
336 exynos_pm_release_retention();
337
338 pmu_raw_writel(exynos_pmu_spare3, S5P_PMU_SPARE3);
339
340 s3c_pm_do_restore_core(exynos_core_save, ARRAY_SIZE(exynos_core_save));
341
342early_wakeup:
343
344 tmp = pmu_raw_readl(EXYNOS5420_SFR_AXI_CGDIS1);
345 tmp &= ~EXYNOS5420_UFS;
346 pmu_raw_writel(tmp, EXYNOS5420_SFR_AXI_CGDIS1);
347
348 tmp = pmu_raw_readl(EXYNOS5420_FSYS2_OPTION);
349 tmp &= ~EXYNOS5420_EMULATION;
350 pmu_raw_writel(tmp, EXYNOS5420_FSYS2_OPTION);
351
352 tmp = pmu_raw_readl(EXYNOS5420_PSGEN_OPTION);
353 tmp &= ~EXYNOS5420_EMULATION;
354 pmu_raw_writel(tmp, EXYNOS5420_PSGEN_OPTION);
355
356 /* Clear SLEEP mode set in INFORM1 */
357 pmu_raw_writel(0x0, S5P_INFORM1);
358}
359
Bartlomiej Zolnierkiewicz0d713cf2014-09-25 18:02:45 +0900360/*
361 * Suspend Ops
362 */
363
364static int exynos_suspend_enter(suspend_state_t state)
365{
366 int ret;
367
368 s3c_pm_debug_init();
369
370 S3C_PMDBG("%s: suspending the system...\n", __func__);
371
372 S3C_PMDBG("%s: wakeup masks: %08x,%08x\n", __func__,
373 exynos_irqwake_intmask, exynos_get_eint_wake_mask());
374
375 if (exynos_irqwake_intmask == -1U
376 && exynos_get_eint_wake_mask() == -1U) {
377 pr_err("%s: No wake-up sources!\n", __func__);
378 pr_err("%s: Aborting sleep\n", __func__);
379 return -EINVAL;
380 }
381
382 s3c_pm_save_uarts();
383 if (pm_data->pm_prepare)
384 pm_data->pm_prepare();
385 flush_cache_all();
386 s3c_pm_check_store();
387
388 ret = call_firmware_op(suspend);
389 if (ret == -ENOSYS)
390 ret = cpu_suspend(0, pm_data->cpu_suspend);
391 if (ret)
392 return ret;
393
394 s3c_pm_restore_uarts();
395
396 S3C_PMDBG("%s: wakeup stat: %08x\n", __func__,
397 pmu_raw_readl(S5P_WAKEUP_STAT));
398
399 s3c_pm_check_restore();
400
401 S3C_PMDBG("%s: resuming the system...\n", __func__);
402
403 return 0;
404}
405
406static int exynos_suspend_prepare(void)
407{
408 s3c_pm_check_prepare();
409
410 return 0;
411}
412
413static void exynos_suspend_finish(void)
414{
415 s3c_pm_check_cleanup();
416}
417
418static const struct platform_suspend_ops exynos_suspend_ops = {
419 .enter = exynos_suspend_enter,
420 .prepare = exynos_suspend_prepare,
421 .finish = exynos_suspend_finish,
422 .valid = suspend_valid_only_mem,
423};
424
425static const struct exynos_pm_data exynos4_pm_data = {
426 .wkup_irq = exynos4_wkup_irq,
427 .wake_disable_mask = ((0xFF << 8) | (0x1F << 1)),
428 .release_ret_regs = exynos_release_ret_regs,
429 .pm_suspend = exynos_pm_suspend,
430 .pm_resume = exynos_pm_resume,
431 .pm_prepare = exynos_pm_prepare,
432 .cpu_suspend = exynos_cpu_suspend,
433};
434
435static const struct exynos_pm_data exynos5250_pm_data = {
436 .wkup_irq = exynos5250_wkup_irq,
437 .wake_disable_mask = ((0xFF << 8) | (0x1F << 1)),
438 .release_ret_regs = exynos_release_ret_regs,
439 .extra_save = exynos5_sys_save,
440 .num_extra_save = ARRAY_SIZE(exynos5_sys_save),
441 .pm_suspend = exynos_pm_suspend,
442 .pm_resume = exynos_pm_resume,
443 .pm_prepare = exynos_pm_prepare,
444 .cpu_suspend = exynos_cpu_suspend,
445};
446
Vikas Sajjan0fdf0882014-11-07 09:17:36 +0900447static struct exynos_pm_data exynos5420_pm_data = {
448 .wkup_irq = exynos5250_wkup_irq,
449 .wake_disable_mask = (0x7F << 7) | (0x1F << 1),
450 .release_ret_regs = exynos5420_release_ret_regs,
451 .pm_resume = exynos5420_pm_resume,
452 .pm_suspend = exynos5420_pm_suspend,
453 .pm_prepare = exynos5420_pm_prepare,
454 .cpu_suspend = exynos5420_cpu_suspend,
455};
456
Bartlomiej Zolnierkiewicz0d713cf2014-09-25 18:02:45 +0900457static struct of_device_id exynos_pmu_of_device_ids[] = {
458 {
459 .compatible = "samsung,exynos4210-pmu",
460 .data = &exynos4_pm_data,
461 }, {
462 .compatible = "samsung,exynos4212-pmu",
463 .data = &exynos4_pm_data,
464 }, {
465 .compatible = "samsung,exynos4412-pmu",
466 .data = &exynos4_pm_data,
467 }, {
468 .compatible = "samsung,exynos5250-pmu",
469 .data = &exynos5250_pm_data,
Vikas Sajjan0fdf0882014-11-07 09:17:36 +0900470 }, {
471 .compatible = "samsung,exynos5420-pmu",
472 .data = &exynos5420_pm_data,
Bartlomiej Zolnierkiewicz0d713cf2014-09-25 18:02:45 +0900473 },
474 { /*sentinel*/ },
475};
476
477static struct syscore_ops exynos_pm_syscore_ops;
478
479void __init exynos_pm_init(void)
480{
481 const struct of_device_id *match;
482 u32 tmp;
483
484 of_find_matching_node_and_match(NULL, exynos_pmu_of_device_ids, &match);
485 if (!match) {
486 pr_err("Failed to find PMU node\n");
487 return;
488 }
489 pm_data = (struct exynos_pm_data *) match->data;
490
491 /* Platform-specific GIC callback */
492 gic_arch_extn.irq_set_wake = exynos_irq_set_wake;
493
494 /* All wakeup disable */
495 tmp = pmu_raw_readl(S5P_WAKEUP_MASK);
496 tmp |= pm_data->wake_disable_mask;
497 pmu_raw_writel(tmp, S5P_WAKEUP_MASK);
498
499 exynos_pm_syscore_ops.suspend = pm_data->pm_suspend;
500 exynos_pm_syscore_ops.resume = pm_data->pm_resume;
501
502 register_syscore_ops(&exynos_pm_syscore_ops);
503 suspend_set_ops(&exynos_suspend_ops);
504}