blob: 079d999b8b2316b04c5950dda85adfb43eec2f61 [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
42/**
43 * struct exynos_wkup_irq - Exynos GIC to PMU IRQ mapping
44 * @hwirq: Hardware IRQ signal of the GIC
45 * @mask: Mask in PMU wake-up mask register
46 */
47struct exynos_wkup_irq {
48 unsigned int hwirq;
49 u32 mask;
50};
51
52static struct sleep_save exynos5_sys_save[] = {
53 SAVE_ITEM(EXYNOS5_SYS_I2C_CFG),
54};
55
56static struct sleep_save exynos_core_save[] = {
57 /* SROM side */
58 SAVE_ITEM(S5P_SROM_BW),
59 SAVE_ITEM(S5P_SROM_BC0),
60 SAVE_ITEM(S5P_SROM_BC1),
61 SAVE_ITEM(S5P_SROM_BC2),
62 SAVE_ITEM(S5P_SROM_BC3),
63};
64
65struct exynos_pm_data {
66 const struct exynos_wkup_irq *wkup_irq;
67 struct sleep_save *extra_save;
68 int num_extra_save;
69 unsigned int wake_disable_mask;
70 unsigned int *release_ret_regs;
71
72 void (*pm_prepare)(void);
73 void (*pm_resume)(void);
74 int (*pm_suspend)(void);
75 int (*cpu_suspend)(unsigned long);
76};
77
78struct exynos_pm_data *pm_data;
79
80/*
81 * GIC wake-up support
82 */
83
84static u32 exynos_irqwake_intmask = 0xffffffff;
85
86static const struct exynos_wkup_irq exynos4_wkup_irq[] = {
87 { 76, BIT(1) }, /* RTC alarm */
88 { 77, BIT(2) }, /* RTC tick */
89 { /* sentinel */ },
90};
91
92static const struct exynos_wkup_irq exynos5250_wkup_irq[] = {
93 { 75, BIT(1) }, /* RTC alarm */
94 { 76, BIT(2) }, /* RTC tick */
95 { /* sentinel */ },
96};
97
98unsigned int exynos_release_ret_regs[] = {
99 S5P_PAD_RET_MAUDIO_OPTION,
100 S5P_PAD_RET_GPIO_OPTION,
101 S5P_PAD_RET_UART_OPTION,
102 S5P_PAD_RET_MMCA_OPTION,
103 S5P_PAD_RET_MMCB_OPTION,
104 S5P_PAD_RET_EBIA_OPTION,
105 S5P_PAD_RET_EBIB_OPTION,
106 REG_TABLE_END,
107};
108
109static int exynos_irq_set_wake(struct irq_data *data, unsigned int state)
110{
111 const struct exynos_wkup_irq *wkup_irq;
112
113 if (!pm_data->wkup_irq)
114 return -ENOENT;
115 wkup_irq = pm_data->wkup_irq;
116
117 while (wkup_irq->mask) {
118 if (wkup_irq->hwirq == data->hwirq) {
119 if (!state)
120 exynos_irqwake_intmask |= wkup_irq->mask;
121 else
122 exynos_irqwake_intmask &= ~wkup_irq->mask;
123 return 0;
124 }
125 ++wkup_irq;
126 }
127
128 return -ENOENT;
129}
130
131static int exynos_cpu_do_idle(void)
132{
133 /* issue the standby signal into the pm unit. */
134 cpu_do_idle();
135
136 pr_info("Failed to suspend the system\n");
137 return 1; /* Aborting suspend */
138}
139
140static int exynos_cpu_suspend(unsigned long arg)
141{
142 flush_cache_all();
143 outer_flush_all();
144 return exynos_cpu_do_idle();
145}
146
147static void exynos_pm_set_wakeup_mask(void)
148{
149 /* Set wake-up mask registers */
150 pmu_raw_writel(exynos_get_eint_wake_mask(), S5P_EINT_WAKEUP_MASK);
151 pmu_raw_writel(exynos_irqwake_intmask & ~(1 << 31), S5P_WAKEUP_MASK);
152}
153
154static void exynos_pm_enter_sleep_mode(void)
155{
156 /* Set value of power down register for sleep mode */
157 exynos_sys_powerdown_conf(SYS_SLEEP);
158 pmu_raw_writel(S5P_CHECK_SLEEP, S5P_INFORM1);
159
160 /* ensure at least INFORM0 has the resume address */
161 pmu_raw_writel(virt_to_phys(exynos_cpu_resume), S5P_INFORM0);
162}
163
164static void exynos_pm_prepare(void)
165{
166 /* Set wake-up mask registers */
167 exynos_pm_set_wakeup_mask();
168
169 s3c_pm_do_save(exynos_core_save, ARRAY_SIZE(exynos_core_save));
170
171 if (pm_data->extra_save)
172 s3c_pm_do_save(pm_data->extra_save,
173 pm_data->num_extra_save);
174
175 exynos_pm_enter_sleep_mode();
176}
177
178static int exynos_pm_suspend(void)
179{
180 exynos_pm_central_suspend();
181
182 if (read_cpuid_part() == ARM_CPU_PART_CORTEX_A9)
183 exynos_cpu_save_register();
184
185 return 0;
186}
187
188static void exynos_pm_release_retention(void)
189{
190 unsigned int i;
191
192 for (i = 0; (pm_data->release_ret_regs[i] != REG_TABLE_END); i++)
193 pmu_raw_writel(EXYNOS_WAKEUP_FROM_LOWPWR,
194 pm_data->release_ret_regs[i]);
195}
196
197static void exynos_pm_resume(void)
198{
199 u32 cpuid = read_cpuid_part();
200
201 if (exynos_pm_central_resume())
202 goto early_wakeup;
203
204 /* For release retention */
205 exynos_pm_release_retention();
206
207 if (pm_data->extra_save)
208 s3c_pm_do_restore_core(pm_data->extra_save,
209 pm_data->num_extra_save);
210
211 s3c_pm_do_restore_core(exynos_core_save, ARRAY_SIZE(exynos_core_save));
212
213 if (cpuid == ARM_CPU_PART_CORTEX_A9)
214 scu_enable(S5P_VA_SCU);
215
216 if (call_firmware_op(resume) == -ENOSYS
217 && cpuid == ARM_CPU_PART_CORTEX_A9)
218 exynos_cpu_restore_register();
219
220early_wakeup:
221
222 /* Clear SLEEP mode set in INFORM1 */
223 pmu_raw_writel(0x0, S5P_INFORM1);
224}
225
226/*
227 * Suspend Ops
228 */
229
230static int exynos_suspend_enter(suspend_state_t state)
231{
232 int ret;
233
234 s3c_pm_debug_init();
235
236 S3C_PMDBG("%s: suspending the system...\n", __func__);
237
238 S3C_PMDBG("%s: wakeup masks: %08x,%08x\n", __func__,
239 exynos_irqwake_intmask, exynos_get_eint_wake_mask());
240
241 if (exynos_irqwake_intmask == -1U
242 && exynos_get_eint_wake_mask() == -1U) {
243 pr_err("%s: No wake-up sources!\n", __func__);
244 pr_err("%s: Aborting sleep\n", __func__);
245 return -EINVAL;
246 }
247
248 s3c_pm_save_uarts();
249 if (pm_data->pm_prepare)
250 pm_data->pm_prepare();
251 flush_cache_all();
252 s3c_pm_check_store();
253
254 ret = call_firmware_op(suspend);
255 if (ret == -ENOSYS)
256 ret = cpu_suspend(0, pm_data->cpu_suspend);
257 if (ret)
258 return ret;
259
260 s3c_pm_restore_uarts();
261
262 S3C_PMDBG("%s: wakeup stat: %08x\n", __func__,
263 pmu_raw_readl(S5P_WAKEUP_STAT));
264
265 s3c_pm_check_restore();
266
267 S3C_PMDBG("%s: resuming the system...\n", __func__);
268
269 return 0;
270}
271
272static int exynos_suspend_prepare(void)
273{
274 s3c_pm_check_prepare();
275
276 return 0;
277}
278
279static void exynos_suspend_finish(void)
280{
281 s3c_pm_check_cleanup();
282}
283
284static const struct platform_suspend_ops exynos_suspend_ops = {
285 .enter = exynos_suspend_enter,
286 .prepare = exynos_suspend_prepare,
287 .finish = exynos_suspend_finish,
288 .valid = suspend_valid_only_mem,
289};
290
291static const struct exynos_pm_data exynos4_pm_data = {
292 .wkup_irq = exynos4_wkup_irq,
293 .wake_disable_mask = ((0xFF << 8) | (0x1F << 1)),
294 .release_ret_regs = exynos_release_ret_regs,
295 .pm_suspend = exynos_pm_suspend,
296 .pm_resume = exynos_pm_resume,
297 .pm_prepare = exynos_pm_prepare,
298 .cpu_suspend = exynos_cpu_suspend,
299};
300
301static const struct exynos_pm_data exynos5250_pm_data = {
302 .wkup_irq = exynos5250_wkup_irq,
303 .wake_disable_mask = ((0xFF << 8) | (0x1F << 1)),
304 .release_ret_regs = exynos_release_ret_regs,
305 .extra_save = exynos5_sys_save,
306 .num_extra_save = ARRAY_SIZE(exynos5_sys_save),
307 .pm_suspend = exynos_pm_suspend,
308 .pm_resume = exynos_pm_resume,
309 .pm_prepare = exynos_pm_prepare,
310 .cpu_suspend = exynos_cpu_suspend,
311};
312
313static struct of_device_id exynos_pmu_of_device_ids[] = {
314 {
315 .compatible = "samsung,exynos4210-pmu",
316 .data = &exynos4_pm_data,
317 }, {
318 .compatible = "samsung,exynos4212-pmu",
319 .data = &exynos4_pm_data,
320 }, {
321 .compatible = "samsung,exynos4412-pmu",
322 .data = &exynos4_pm_data,
323 }, {
324 .compatible = "samsung,exynos5250-pmu",
325 .data = &exynos5250_pm_data,
326 },
327 { /*sentinel*/ },
328};
329
330static struct syscore_ops exynos_pm_syscore_ops;
331
332void __init exynos_pm_init(void)
333{
334 const struct of_device_id *match;
335 u32 tmp;
336
337 of_find_matching_node_and_match(NULL, exynos_pmu_of_device_ids, &match);
338 if (!match) {
339 pr_err("Failed to find PMU node\n");
340 return;
341 }
342 pm_data = (struct exynos_pm_data *) match->data;
343
344 /* Platform-specific GIC callback */
345 gic_arch_extn.irq_set_wake = exynos_irq_set_wake;
346
347 /* All wakeup disable */
348 tmp = pmu_raw_readl(S5P_WAKEUP_MASK);
349 tmp |= pm_data->wake_disable_mask;
350 pmu_raw_writel(tmp, S5P_WAKEUP_MASK);
351
352 exynos_pm_syscore_ops.suspend = pm_data->pm_suspend;
353 exynos_pm_syscore_ops.resume = pm_data->pm_resume;
354
355 register_syscore_ops(&exynos_pm_syscore_ops);
356 suspend_set_ops(&exynos_suspend_ops);
357}