Merge tag 'usb-5.11-rc3' of git://git.kernel.org/pub/scm/linux/kernel/git/gregkh/usb
[linux/fpc-iii.git] / arch / arm / mach-s5pv210 / pm.c
blobd59c094cdea8bad55171c2fa22af5644b4aa3453
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>
12 #include <linux/init.h>
13 #include <linux/suspend.h>
14 #include <linux/syscore_ops.h>
15 #include <linux/io.h>
16 #include <linux/soc/samsung/s3c-pm.h>
18 #include <asm/cacheflush.h>
19 #include <asm/suspend.h>
21 #include "common.h"
22 #include "regs-clock.h"
24 /* helper functions to save and restore register state */
25 struct sleep_save {
26 void __iomem *reg;
27 unsigned long val;
30 #define SAVE_ITEM(x) \
31 { .reg = (x) }
33 /**
34 * s3c_pm_do_save() - save a set of registers for restoration on resume.
35 * @ptr: Pointer to an array of registers.
36 * @count: Size of the ptr array.
38 * Run through the list of registers given, saving their contents in the
39 * array for later restoration when we wakeup.
41 static void s3c_pm_do_save(struct sleep_save *ptr, int count)
43 for (; count > 0; count--, ptr++) {
44 ptr->val = readl_relaxed(ptr->reg);
45 S3C_PMDBG("saved %p value %08lx\n", ptr->reg, ptr->val);
49 /**
50 * s3c_pm_do_restore() - restore register values from the save list.
51 * @ptr: Pointer to an array of registers.
52 * @count: Size of the ptr array.
54 * Restore the register values saved from s3c_pm_do_save().
56 * WARNING: Do not put any debug in here that may effect memory or use
57 * peripherals, as things may be changing!
60 static void s3c_pm_do_restore_core(const struct sleep_save *ptr, int count)
62 for (; count > 0; count--, ptr++)
63 writel_relaxed(ptr->val, ptr->reg);
66 static struct sleep_save s5pv210_core_save[] = {
67 /* Clock ETC */
68 SAVE_ITEM(S5P_MDNIE_SEL),
72 * VIC wake-up support (TODO)
74 static u32 s5pv210_irqwake_intmask = 0xffffffff;
76 static u32 s5pv210_read_eint_wakeup_mask(void)
78 return __raw_readl(S5P_EINT_WAKEUP_MASK);
82 * Suspend helpers.
84 static int s5pv210_cpu_suspend(unsigned long arg)
86 unsigned long tmp;
88 /* issue the standby signal into the pm unit. Note, we
89 * issue a write-buffer drain just in case */
91 tmp = 0;
93 asm("b 1f\n\t"
94 ".align 5\n\t"
95 "1:\n\t"
96 "mcr p15, 0, %0, c7, c10, 5\n\t"
97 "mcr p15, 0, %0, c7, c10, 4\n\t"
98 "wfi" : : "r" (tmp));
100 pr_info("Failed to suspend the system\n");
101 return 1; /* Aborting suspend */
104 static void s5pv210_pm_prepare(void)
106 unsigned int tmp;
109 * Set wake-up mask registers
110 * S5P_EINT_WAKEUP_MASK is set by pinctrl driver in late suspend.
112 __raw_writel(s5pv210_irqwake_intmask, S5P_WAKEUP_MASK);
114 /* ensure at least INFORM0 has the resume address */
115 __raw_writel(__pa_symbol(s5pv210_cpu_resume), S5P_INFORM0);
117 tmp = __raw_readl(S5P_SLEEP_CFG);
118 tmp &= ~(S5P_SLEEP_CFG_OSC_EN | S5P_SLEEP_CFG_USBOSC_EN);
119 __raw_writel(tmp, S5P_SLEEP_CFG);
121 /* WFI for SLEEP mode configuration by SYSCON */
122 tmp = __raw_readl(S5P_PWR_CFG);
123 tmp &= S5P_CFG_WFI_CLEAN;
124 tmp |= S5P_CFG_WFI_SLEEP;
125 __raw_writel(tmp, S5P_PWR_CFG);
127 /* SYSCON interrupt handling disable */
128 tmp = __raw_readl(S5P_OTHERS);
129 tmp |= S5P_OTHER_SYSC_INTOFF;
130 __raw_writel(tmp, S5P_OTHERS);
132 s3c_pm_do_save(s5pv210_core_save, ARRAY_SIZE(s5pv210_core_save));
136 * Suspend operations.
138 static int s5pv210_suspend_enter(suspend_state_t state)
140 u32 eint_wakeup_mask = s5pv210_read_eint_wakeup_mask();
141 int ret;
143 S3C_PMDBG("%s: suspending the system...\n", __func__);
145 S3C_PMDBG("%s: wakeup masks: %08x,%08x\n", __func__,
146 s5pv210_irqwake_intmask, eint_wakeup_mask);
148 if (s5pv210_irqwake_intmask == -1U
149 && eint_wakeup_mask == -1U) {
150 pr_err("%s: No wake-up sources!\n", __func__);
151 pr_err("%s: Aborting sleep\n", __func__);
152 return -EINVAL;
155 s3c_pm_save_uarts(false);
156 s5pv210_pm_prepare();
157 flush_cache_all();
158 s3c_pm_check_store();
160 ret = cpu_suspend(0, s5pv210_cpu_suspend);
161 if (ret)
162 return ret;
164 s3c_pm_restore_uarts(false);
166 S3C_PMDBG("%s: wakeup stat: %08x\n", __func__,
167 __raw_readl(S5P_WAKEUP_STAT));
169 s3c_pm_check_restore();
171 S3C_PMDBG("%s: resuming the system...\n", __func__);
173 return 0;
176 static int s5pv210_suspend_prepare(void)
178 s3c_pm_check_prepare();
180 return 0;
183 static void s5pv210_suspend_finish(void)
185 s3c_pm_check_cleanup();
188 static const struct platform_suspend_ops s5pv210_suspend_ops = {
189 .enter = s5pv210_suspend_enter,
190 .prepare = s5pv210_suspend_prepare,
191 .finish = s5pv210_suspend_finish,
192 .valid = suspend_valid_only_mem,
196 * Syscore operations used to delay restore of certain registers.
198 static void s5pv210_pm_resume(void)
200 s3c_pm_do_restore_core(s5pv210_core_save, ARRAY_SIZE(s5pv210_core_save));
203 static struct syscore_ops s5pv210_pm_syscore_ops = {
204 .resume = s5pv210_pm_resume,
208 * Initialization entry point.
210 void __init s5pv210_pm_init(void)
212 register_syscore_ops(&s5pv210_pm_syscore_ops);
213 suspend_set_ops(&s5pv210_suspend_ops);