blob: 596ed13c416678b8ad32edf86d93e8c03d7790f9 [file] [log] [blame]
Jongpill Leec9347102012-02-17 09:49:54 +09001/*
2 * Copyright (c) 2011-2012 Samsung Electronics Co., Ltd.
Jaecheol Lee16638952011-03-10 13:33:59 +09003 * http://www.samsung.com
4 *
Jongpill Leec9347102012-02-17 09:49:54 +09005 * EXYNOS - Power Management support
Jaecheol Lee16638952011-03-10 13:33:59 +09006 *
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>
Rafael J. Wysockibb072c32011-04-22 22:03:21 +020018#include <linux/syscore_ops.h>
Jaecheol Lee16638952011-03-10 13:33:59 +090019#include <linux/io.h>
Jaecheol Lee56c03d92011-07-18 19:25:13 +090020#include <linux/err.h>
21#include <linux/clk.h>
Jaecheol Lee16638952011-03-10 13:33:59 +090022
23#include <asm/cacheflush.h>
24#include <asm/hardware/cache-l2x0.h>
Shawn Guo63b870f2011-11-17 01:19:11 +090025#include <asm/smp_scu.h>
Jaecheol Lee16638952011-03-10 13:33:59 +090026
27#include <plat/cpu.h>
28#include <plat/pm.h>
Jaecheol Lee56c03d92011-07-18 19:25:13 +090029#include <plat/pll.h>
MyungJoo Hamb93cb912011-07-21 11:25:23 +090030#include <plat/regs-srom.h>
Jaecheol Lee16638952011-03-10 13:33:59 +090031
Kukjin Kim9c9239a2013-12-19 04:19:59 +090032#include <mach/map.h>
Jaecheol Lee16638952011-03-10 13:33:59 +090033#include <mach/pm-core.h>
Kukjin Kimccd458c2012-12-31 10:06:48 -080034
35#include "common.h"
Kukjin Kim65c9a852013-12-19 04:06:56 +090036#include "regs-pmu.h"
Jaecheol Lee16638952011-03-10 13:33:59 +090037
Abhilash Kesavan86ffb0e2012-11-20 18:20:45 +090038static struct sleep_save exynos5_sys_save[] = {
39 SAVE_ITEM(EXYNOS5_SYS_I2C_CFG),
40};
41
Jongpill Leec9347102012-02-17 09:49:54 +090042static struct sleep_save exynos_core_save[] = {
MyungJoo Hamb93cb912011-07-21 11:25:23 +090043 /* SROM side */
44 SAVE_ITEM(S5P_SROM_BW),
45 SAVE_ITEM(S5P_SROM_BC0),
46 SAVE_ITEM(S5P_SROM_BC1),
47 SAVE_ITEM(S5P_SROM_BC2),
48 SAVE_ITEM(S5P_SROM_BC3),
Jaecheol Lee16638952011-03-10 13:33:59 +090049};
50
Jaecheol Lee16638952011-03-10 13:33:59 +090051
Jaecheol Leef4ba4b02011-07-18 19:25:03 +090052/* For Cortex-A9 Diagnostic and Power control register */
53static unsigned int save_arm_register[2];
54
Jongpill Leec9347102012-02-17 09:49:54 +090055static int exynos_cpu_suspend(unsigned long arg)
Jaecheol Lee16638952011-03-10 13:33:59 +090056{
Jongpill Lee60e49ca2012-02-17 12:23:51 +090057#ifdef CONFIG_CACHE_L2X0
Jaecheol Lee16638952011-03-10 13:33:59 +090058 outer_flush_all();
Jongpill Lee60e49ca2012-02-17 12:23:51 +090059#endif
Jaecheol Lee16638952011-03-10 13:33:59 +090060
Abhilash Kesavan573e5bb2012-11-22 14:46:40 +090061 if (soc_is_exynos5250())
62 flush_cache_all();
63
Jaecheol Lee16638952011-03-10 13:33:59 +090064 /* issue the standby signal into the pm unit. */
65 cpu_do_idle();
66
Abhilash Kesavand3fcacf2013-01-25 10:40:19 -080067 pr_info("Failed to suspend the system\n");
68 return 1; /* Aborting suspend */
Jaecheol Lee16638952011-03-10 13:33:59 +090069}
70
Jongpill Leec9347102012-02-17 09:49:54 +090071static void exynos_pm_prepare(void)
Jaecheol Lee16638952011-03-10 13:33:59 +090072{
Jongpill Lee60e49ca2012-02-17 12:23:51 +090073 unsigned int tmp;
Jaecheol Lee16638952011-03-10 13:33:59 +090074
Jongpill Leec9347102012-02-17 09:49:54 +090075 s3c_pm_do_save(exynos_core_save, ARRAY_SIZE(exynos_core_save));
Jaecheol Lee16638952011-03-10 13:33:59 +090076
Tomasz Figae11d9192014-02-14 08:16:01 +090077 if (soc_is_exynos5250()) {
Abhilash Kesavan86ffb0e2012-11-20 18:20:45 +090078 s3c_pm_do_save(exynos5_sys_save, ARRAY_SIZE(exynos5_sys_save));
Jongpill Lee60e49ca2012-02-17 12:23:51 +090079 /* Disable USE_RETENTION of JPEG_MEM_OPTION */
80 tmp = __raw_readl(EXYNOS5_JPEG_MEM_OPTION);
81 tmp &= ~EXYNOS5_OPTION_USE_RETENTION;
82 __raw_writel(tmp, EXYNOS5_JPEG_MEM_OPTION);
83 }
Jaecheol Lee16638952011-03-10 13:33:59 +090084
85 /* Set value of power down register for sleep mode */
86
Jongpill Lee7d44d2b2012-02-17 09:51:31 +090087 exynos_sys_powerdown_conf(SYS_SLEEP);
Jaecheol Lee16638952011-03-10 13:33:59 +090088 __raw_writel(S5P_CHECK_SLEEP, S5P_INFORM1);
89
90 /* ensure at least INFORM0 has the resume address */
91
92 __raw_writel(virt_to_phys(s3c_cpu_resume), S5P_INFORM0);
Jaecheol Lee16638952011-03-10 13:33:59 +090093}
94
Jongpill Leec9347102012-02-17 09:49:54 +090095static int exynos_pm_suspend(void)
Jaecheol Lee12974e92011-07-18 19:21:41 +090096{
97 unsigned long tmp;
98
99 /* Setting Central Sequence Register for power down mode */
100
101 tmp = __raw_readl(S5P_CENTRAL_SEQ_CONFIGURATION);
102 tmp &= ~S5P_CENTRAL_LOWPWR_CFG;
103 __raw_writel(tmp, S5P_CENTRAL_SEQ_CONFIGURATION);
104
Jongpill Lee60e49ca2012-02-17 12:23:51 +0900105 /* Setting SEQ_OPTION register */
106
107 tmp = (S5P_USE_STANDBY_WFI0 | S5P_USE_STANDBY_WFE0);
108 __raw_writel(tmp, S5P_CENTRAL_SEQ_OPTION);
109
110 if (!soc_is_exynos5250()) {
111 /* Save Power control register */
112 asm ("mrc p15, 0, %0, c15, c0, 0"
113 : "=r" (tmp) : : "cc");
114 save_arm_register[0] = tmp;
115
116 /* Save Diagnostic register */
117 asm ("mrc p15, 0, %0, c15, c0, 1"
118 : "=r" (tmp) : : "cc");
119 save_arm_register[1] = tmp;
Jongpill Lee00a351f2011-09-27 07:26:04 +0900120 }
121
Jaecheol Lee12974e92011-07-18 19:21:41 +0900122 return 0;
123}
124
Jongpill Leec9347102012-02-17 09:49:54 +0900125static void exynos_pm_resume(void)
Jaecheol Lee16638952011-03-10 13:33:59 +0900126{
Jaecheol Leee240ab1c2011-07-18 19:21:34 +0900127 unsigned long tmp;
128
129 /*
130 * If PMU failed while entering sleep mode, WFI will be
131 * ignored by PMU and then exiting cpu_do_idle().
132 * S5P_CENTRAL_LOWPWR_CFG bit will not be set automatically
133 * in this situation.
134 */
135 tmp = __raw_readl(S5P_CENTRAL_SEQ_CONFIGURATION);
136 if (!(tmp & S5P_CENTRAL_LOWPWR_CFG)) {
137 tmp |= S5P_CENTRAL_LOWPWR_CFG;
138 __raw_writel(tmp, S5P_CENTRAL_SEQ_CONFIGURATION);
Abhilash Kesavand3fcacf2013-01-25 10:40:19 -0800139 /* clear the wakeup state register */
140 __raw_writel(0x0, S5P_WAKEUP_STAT);
Jaecheol Leee240ab1c2011-07-18 19:21:34 +0900141 /* No need to perform below restore code */
142 goto early_wakeup;
143 }
Jongpill Lee60e49ca2012-02-17 12:23:51 +0900144 if (!soc_is_exynos5250()) {
145 /* Restore Power control register */
146 tmp = save_arm_register[0];
147 asm volatile ("mcr p15, 0, %0, c15, c0, 0"
148 : : "r" (tmp)
149 : "cc");
Jaecheol Leef4ba4b02011-07-18 19:25:03 +0900150
Jongpill Lee60e49ca2012-02-17 12:23:51 +0900151 /* Restore Diagnostic register */
152 tmp = save_arm_register[1];
153 asm volatile ("mcr p15, 0, %0, c15, c0, 1"
154 : : "r" (tmp)
155 : "cc");
156 }
Jaecheol Leee240ab1c2011-07-18 19:21:34 +0900157
Jaecheol Lee16638952011-03-10 13:33:59 +0900158 /* For release retention */
159
160 __raw_writel((1 << 28), S5P_PAD_RET_MAUDIO_OPTION);
161 __raw_writel((1 << 28), S5P_PAD_RET_GPIO_OPTION);
162 __raw_writel((1 << 28), S5P_PAD_RET_UART_OPTION);
163 __raw_writel((1 << 28), S5P_PAD_RET_MMCA_OPTION);
164 __raw_writel((1 << 28), S5P_PAD_RET_MMCB_OPTION);
165 __raw_writel((1 << 28), S5P_PAD_RET_EBIA_OPTION);
166 __raw_writel((1 << 28), S5P_PAD_RET_EBIB_OPTION);
167
Abhilash Kesavan86ffb0e2012-11-20 18:20:45 +0900168 if (soc_is_exynos5250())
169 s3c_pm_do_restore(exynos5_sys_save,
170 ARRAY_SIZE(exynos5_sys_save));
171
Jongpill Leec9347102012-02-17 09:49:54 +0900172 s3c_pm_do_restore_core(exynos_core_save, ARRAY_SIZE(exynos_core_save));
Jaecheol Lee16638952011-03-10 13:33:59 +0900173
Tomasz Figae11d9192014-02-14 08:16:01 +0900174 if (IS_ENABLED(CONFIG_SMP) && !soc_is_exynos5250())
Jongpill Lee60e49ca2012-02-17 12:23:51 +0900175 scu_enable(S5P_VA_SCU);
Jaecheol Lee16638952011-03-10 13:33:59 +0900176
Jaecheol Leee240ab1c2011-07-18 19:21:34 +0900177early_wakeup:
Inderpal Singhebee8542012-11-22 14:46:27 +0900178
179 /* Clear SLEEP mode set in INFORM1 */
180 __raw_writel(0x0, S5P_INFORM1);
181
Jaecheol Leee240ab1c2011-07-18 19:21:34 +0900182 return;
Jaecheol Lee16638952011-03-10 13:33:59 +0900183}
184
Jongpill Leec9347102012-02-17 09:49:54 +0900185static struct syscore_ops exynos_pm_syscore_ops = {
186 .suspend = exynos_pm_suspend,
187 .resume = exynos_pm_resume,
Jaecheol Lee16638952011-03-10 13:33:59 +0900188};
189
Tomasz Figa559ba232014-03-18 07:28:22 +0900190void __init exynos_pm_init(void)
Jaecheol Lee16638952011-03-10 13:33:59 +0900191{
Tomasz Figa559ba232014-03-18 07:28:22 +0900192 u32 tmp;
193
194 pm_cpu_prep = exynos_pm_prepare;
195 pm_cpu_sleep = exynos_cpu_suspend;
196
197 s3c_pm_init();
198
199 /* All wakeup disable */
200 tmp = __raw_readl(S5P_WAKEUP_MASK);
201 tmp |= ((0xFF << 8) | (0x1F << 1));
202 __raw_writel(tmp, S5P_WAKEUP_MASK);
Kukjin Kime085cad2013-06-26 22:29:44 +0900203
Jongpill Leec9347102012-02-17 09:49:54 +0900204 register_syscore_ops(&exynos_pm_syscore_ops);
Jaecheol Lee16638952011-03-10 13:33:59 +0900205}