xref: /linux/arch/arm/mach-s5pv210/pm.c (revision 6fdcba32711044c35c0e1b094cbd8f3f0b4472c9)
1 // SPDX-License-Identifier: GPL-2.0
2 //
3 // Copyright (c) 2010-2014 Samsung Electronics Co., Ltd.
4 //		http://www.samsung.com
5 //
6 // S5PV210 - 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 #include <linux/init.h>
13 #include <linux/suspend.h>
14 #include <linux/syscore_ops.h>
15 #include <linux/io.h>
16 
17 #include <asm/cacheflush.h>
18 #include <asm/suspend.h>
19 
20 #include <plat/pm-common.h>
21 
22 #include "common.h"
23 #include "regs-clock.h"
24 
25 static struct sleep_save s5pv210_core_save[] = {
26 	/* Clock ETC */
27 	SAVE_ITEM(S5P_MDNIE_SEL),
28 };
29 
30 /*
31  * VIC wake-up support (TODO)
32  */
33 static u32 s5pv210_irqwake_intmask = 0xffffffff;
34 
35 static u32 s5pv210_read_eint_wakeup_mask(void)
36 {
37 	return __raw_readl(S5P_EINT_WAKEUP_MASK);
38 }
39 
40 /*
41  * Suspend helpers.
42  */
43 static int s5pv210_cpu_suspend(unsigned long arg)
44 {
45 	unsigned long tmp;
46 
47 	/* issue the standby signal into the pm unit. Note, we
48 	 * issue a write-buffer drain just in case */
49 
50 	tmp = 0;
51 
52 	asm("b 1f\n\t"
53 	    ".align 5\n\t"
54 	    "1:\n\t"
55 	    "mcr p15, 0, %0, c7, c10, 5\n\t"
56 	    "mcr p15, 0, %0, c7, c10, 4\n\t"
57 	    "wfi" : : "r" (tmp));
58 
59 	pr_info("Failed to suspend the system\n");
60 	return 1; /* Aborting suspend */
61 }
62 
63 static void s5pv210_pm_prepare(void)
64 {
65 	unsigned int tmp;
66 
67 	/*
68 	 * Set wake-up mask registers
69 	 * S5P_EINT_WAKEUP_MASK is set by pinctrl driver in late suspend.
70 	 */
71 	__raw_writel(s5pv210_irqwake_intmask, S5P_WAKEUP_MASK);
72 
73 	/* ensure at least INFORM0 has the resume address */
74 	__raw_writel(__pa_symbol(s5pv210_cpu_resume), S5P_INFORM0);
75 
76 	tmp = __raw_readl(S5P_SLEEP_CFG);
77 	tmp &= ~(S5P_SLEEP_CFG_OSC_EN | S5P_SLEEP_CFG_USBOSC_EN);
78 	__raw_writel(tmp, S5P_SLEEP_CFG);
79 
80 	/* WFI for SLEEP mode configuration by SYSCON */
81 	tmp = __raw_readl(S5P_PWR_CFG);
82 	tmp &= S5P_CFG_WFI_CLEAN;
83 	tmp |= S5P_CFG_WFI_SLEEP;
84 	__raw_writel(tmp, S5P_PWR_CFG);
85 
86 	/* SYSCON interrupt handling disable */
87 	tmp = __raw_readl(S5P_OTHERS);
88 	tmp |= S5P_OTHER_SYSC_INTOFF;
89 	__raw_writel(tmp, S5P_OTHERS);
90 
91 	s3c_pm_do_save(s5pv210_core_save, ARRAY_SIZE(s5pv210_core_save));
92 }
93 
94 /*
95  * Suspend operations.
96  */
97 static int s5pv210_suspend_enter(suspend_state_t state)
98 {
99 	u32 eint_wakeup_mask = s5pv210_read_eint_wakeup_mask();
100 	int ret;
101 
102 	s3c_pm_debug_init();
103 
104 	S3C_PMDBG("%s: suspending the system...\n", __func__);
105 
106 	S3C_PMDBG("%s: wakeup masks: %08x,%08x\n", __func__,
107 			s5pv210_irqwake_intmask, eint_wakeup_mask);
108 
109 	if (s5pv210_irqwake_intmask == -1U
110 	    && eint_wakeup_mask == -1U) {
111 		pr_err("%s: No wake-up sources!\n", __func__);
112 		pr_err("%s: Aborting sleep\n", __func__);
113 		return -EINVAL;
114 	}
115 
116 	s3c_pm_save_uarts();
117 	s5pv210_pm_prepare();
118 	flush_cache_all();
119 	s3c_pm_check_store();
120 
121 	ret = cpu_suspend(0, s5pv210_cpu_suspend);
122 	if (ret)
123 		return ret;
124 
125 	s3c_pm_restore_uarts();
126 
127 	S3C_PMDBG("%s: wakeup stat: %08x\n", __func__,
128 			__raw_readl(S5P_WAKEUP_STAT));
129 
130 	s3c_pm_check_restore();
131 
132 	S3C_PMDBG("%s: resuming the system...\n", __func__);
133 
134 	return 0;
135 }
136 
137 static int s5pv210_suspend_prepare(void)
138 {
139 	s3c_pm_check_prepare();
140 
141 	return 0;
142 }
143 
144 static void s5pv210_suspend_finish(void)
145 {
146 	s3c_pm_check_cleanup();
147 }
148 
149 static const struct platform_suspend_ops s5pv210_suspend_ops = {
150 	.enter		= s5pv210_suspend_enter,
151 	.prepare	= s5pv210_suspend_prepare,
152 	.finish		= s5pv210_suspend_finish,
153 	.valid		= suspend_valid_only_mem,
154 };
155 
156 /*
157  * Syscore operations used to delay restore of certain registers.
158  */
159 static void s5pv210_pm_resume(void)
160 {
161 	s3c_pm_do_restore_core(s5pv210_core_save, ARRAY_SIZE(s5pv210_core_save));
162 }
163 
164 static struct syscore_ops s5pv210_pm_syscore_ops = {
165 	.resume		= s5pv210_pm_resume,
166 };
167 
168 /*
169  * Initialization entry point.
170  */
171 void __init s5pv210_pm_init(void)
172 {
173 	register_syscore_ops(&s5pv210_pm_syscore_ops);
174 	suspend_set_ops(&s5pv210_suspend_ops);
175 }
176