xref: /openbmc/linux/arch/arm/mach-s5pv210/pm.c (revision bc05aa6e)
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 /*
36  * Suspend helpers.
37  */
38 static int s5pv210_cpu_suspend(unsigned long arg)
39 {
40 	unsigned long tmp;
41 
42 	/* issue the standby signal into the pm unit. Note, we
43 	 * issue a write-buffer drain just in case */
44 
45 	tmp = 0;
46 
47 	asm("b 1f\n\t"
48 	    ".align 5\n\t"
49 	    "1:\n\t"
50 	    "mcr p15, 0, %0, c7, c10, 5\n\t"
51 	    "mcr p15, 0, %0, c7, c10, 4\n\t"
52 	    "wfi" : : "r" (tmp));
53 
54 	pr_info("Failed to suspend the system\n");
55 	return 1; /* Aborting suspend */
56 }
57 
58 static void s5pv210_pm_prepare(void)
59 {
60 	unsigned int tmp;
61 
62 	/* Set wake-up mask registers */
63 	__raw_writel(exynos_get_eint_wake_mask(), S5P_EINT_WAKEUP_MASK);
64 	__raw_writel(s5pv210_irqwake_intmask, S5P_WAKEUP_MASK);
65 
66 	/* ensure at least INFORM0 has the resume address */
67 	__raw_writel(__pa_symbol(s5pv210_cpu_resume), S5P_INFORM0);
68 
69 	tmp = __raw_readl(S5P_SLEEP_CFG);
70 	tmp &= ~(S5P_SLEEP_CFG_OSC_EN | S5P_SLEEP_CFG_USBOSC_EN);
71 	__raw_writel(tmp, S5P_SLEEP_CFG);
72 
73 	/* WFI for SLEEP mode configuration by SYSCON */
74 	tmp = __raw_readl(S5P_PWR_CFG);
75 	tmp &= S5P_CFG_WFI_CLEAN;
76 	tmp |= S5P_CFG_WFI_SLEEP;
77 	__raw_writel(tmp, S5P_PWR_CFG);
78 
79 	/* SYSCON interrupt handling disable */
80 	tmp = __raw_readl(S5P_OTHERS);
81 	tmp |= S5P_OTHER_SYSC_INTOFF;
82 	__raw_writel(tmp, S5P_OTHERS);
83 
84 	s3c_pm_do_save(s5pv210_core_save, ARRAY_SIZE(s5pv210_core_save));
85 }
86 
87 /*
88  * Suspend operations.
89  */
90 static int s5pv210_suspend_enter(suspend_state_t state)
91 {
92 	int ret;
93 
94 	s3c_pm_debug_init();
95 
96 	S3C_PMDBG("%s: suspending the system...\n", __func__);
97 
98 	S3C_PMDBG("%s: wakeup masks: %08x,%08x\n", __func__,
99 			s5pv210_irqwake_intmask, exynos_get_eint_wake_mask());
100 
101 	if (s5pv210_irqwake_intmask == -1U
102 	    && exynos_get_eint_wake_mask() == -1U) {
103 		pr_err("%s: No wake-up sources!\n", __func__);
104 		pr_err("%s: Aborting sleep\n", __func__);
105 		return -EINVAL;
106 	}
107 
108 	s3c_pm_save_uarts();
109 	s5pv210_pm_prepare();
110 	flush_cache_all();
111 	s3c_pm_check_store();
112 
113 	ret = cpu_suspend(0, s5pv210_cpu_suspend);
114 	if (ret)
115 		return ret;
116 
117 	s3c_pm_restore_uarts();
118 
119 	S3C_PMDBG("%s: wakeup stat: %08x\n", __func__,
120 			__raw_readl(S5P_WAKEUP_STAT));
121 
122 	s3c_pm_check_restore();
123 
124 	S3C_PMDBG("%s: resuming the system...\n", __func__);
125 
126 	return 0;
127 }
128 
129 static int s5pv210_suspend_prepare(void)
130 {
131 	s3c_pm_check_prepare();
132 
133 	return 0;
134 }
135 
136 static void s5pv210_suspend_finish(void)
137 {
138 	s3c_pm_check_cleanup();
139 }
140 
141 static const struct platform_suspend_ops s5pv210_suspend_ops = {
142 	.enter		= s5pv210_suspend_enter,
143 	.prepare	= s5pv210_suspend_prepare,
144 	.finish		= s5pv210_suspend_finish,
145 	.valid		= suspend_valid_only_mem,
146 };
147 
148 /*
149  * Syscore operations used to delay restore of certain registers.
150  */
151 static void s5pv210_pm_resume(void)
152 {
153 	s3c_pm_do_restore_core(s5pv210_core_save, ARRAY_SIZE(s5pv210_core_save));
154 }
155 
156 static struct syscore_ops s5pv210_pm_syscore_ops = {
157 	.resume		= s5pv210_pm_resume,
158 };
159 
160 /*
161  * Initialization entry point.
162  */
163 void __init s5pv210_pm_init(void)
164 {
165 	register_syscore_ops(&s5pv210_pm_syscore_ops);
166 	suspend_set_ops(&s5pv210_suspend_ops);
167 }
168