blob: 123163dd2ab0b394c100eda6c828cf644fb3e495 [file] [log] [blame]
Jongpill Leeea31fd42010-10-02 19:13:42 +09001/* linux/arch/arm/mach-s5pv210/pm.c
2 *
Tomasz Figa0a90d4d2014-07-02 19:37:45 +02003 * Copyright (c) 2010-2014 Samsung Electronics Co., Ltd.
Jongpill Leeea31fd42010-10-02 19:13:42 +09004 * 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 * This program is free software; you can redistribute it and/or modify
13 * it under the terms of the GNU General Public License version 2 as
14 * published by the Free Software Foundation.
15*/
16
17#include <linux/init.h>
18#include <linux/suspend.h>
Rafael J. Wysockibb072c32011-04-22 22:03:21 +020019#include <linux/syscore_ops.h>
Jongpill Leeea31fd42010-10-02 19:13:42 +090020#include <linux/io.h>
21
Tomasz Figa0a90d4d2014-07-02 19:37:45 +020022#include <asm/cacheflush.h>
23#include <asm/suspend.h>
Jongpill Leeea31fd42010-10-02 19:13:42 +090024
Tomasz Figa0a90d4d2014-07-02 19:37:45 +020025#include <plat/pm-common.h>
26
Jongpill Leeea31fd42010-10-02 19:13:42 +090027#include <mach/regs-clock.h>
28
Tomasz Figa0a90d4d2014-07-02 19:37:45 +020029#include "common.h"
30
Jongpill Leeea31fd42010-10-02 19:13:42 +090031static struct sleep_save s5pv210_core_save[] = {
Jongpill Leeea31fd42010-10-02 19:13:42 +090032 /* Clock ETC */
Jongpill Leeea31fd42010-10-02 19:13:42 +090033 SAVE_ITEM(S5P_MDNIE_SEL),
Jongpill Leeea31fd42010-10-02 19:13:42 +090034};
35
Tomasz Figa0a90d4d2014-07-02 19:37:45 +020036/*
37 * VIC wake-up support (TODO)
38 */
39static u32 s5pv210_irqwake_intmask = 0xffffffff;
40
41/*
42 * Suspend helpers.
43 */
Abhilash Kesavan7e1291d2011-08-13 10:34:56 +090044static int s5pv210_cpu_suspend(unsigned long arg)
Jongpill Leeea31fd42010-10-02 19:13:42 +090045{
46 unsigned long tmp;
47
48 /* issue the standby signal into the pm unit. Note, we
49 * issue a write-buffer drain just in case */
50
51 tmp = 0;
52
53 asm("b 1f\n\t"
54 ".align 5\n\t"
55 "1:\n\t"
56 "mcr p15, 0, %0, c7, c10, 5\n\t"
57 "mcr p15, 0, %0, c7, c10, 4\n\t"
58 "wfi" : : "r" (tmp));
59
Abhilash Kesavand3fcacf2013-01-25 10:40:19 -080060 pr_info("Failed to suspend the system\n");
61 return 1; /* Aborting suspend */
Jongpill Leeea31fd42010-10-02 19:13:42 +090062}
63
64static void s5pv210_pm_prepare(void)
65{
66 unsigned int tmp;
67
Tomasz Figa0a90d4d2014-07-02 19:37:45 +020068 /* Set wake-up mask registers */
69 __raw_writel(exynos_get_eint_wake_mask(), S5P_EINT_WAKEUP_MASK);
70 __raw_writel(s5pv210_irqwake_intmask, S5P_WAKEUP_MASK);
71
Jongpill Leeea31fd42010-10-02 19:13:42 +090072 /* ensure at least INFORM0 has the resume address */
Tomasz Figa0a90d4d2014-07-02 19:37:45 +020073 __raw_writel(virt_to_phys(s5pv210_cpu_resume), S5P_INFORM0);
Jongpill Leeea31fd42010-10-02 19:13:42 +090074
75 tmp = __raw_readl(S5P_SLEEP_CFG);
76 tmp &= ~(S5P_SLEEP_CFG_OSC_EN | S5P_SLEEP_CFG_USBOSC_EN);
77 __raw_writel(tmp, S5P_SLEEP_CFG);
78
79 /* WFI for SLEEP mode configuration by SYSCON */
80 tmp = __raw_readl(S5P_PWR_CFG);
81 tmp &= S5P_CFG_WFI_CLEAN;
82 tmp |= S5P_CFG_WFI_SLEEP;
83 __raw_writel(tmp, S5P_PWR_CFG);
84
85 /* SYSCON interrupt handling disable */
86 tmp = __raw_readl(S5P_OTHERS);
87 tmp |= S5P_OTHER_SYSC_INTOFF;
88 __raw_writel(tmp, S5P_OTHERS);
89
90 s3c_pm_do_save(s5pv210_core_save, ARRAY_SIZE(s5pv210_core_save));
91}
92
Tomasz Figa0a90d4d2014-07-02 19:37:45 +020093/*
94 * Suspend operations.
95 */
96static int s5pv210_suspend_enter(suspend_state_t state)
97{
98 int ret;
99
100 s3c_pm_debug_init();
101
102 S3C_PMDBG("%s: suspending the system...\n", __func__);
103
104 S3C_PMDBG("%s: wakeup masks: %08x,%08x\n", __func__,
105 s5pv210_irqwake_intmask, exynos_get_eint_wake_mask());
106
107 if (s5pv210_irqwake_intmask == -1U
108 && exynos_get_eint_wake_mask() == -1U) {
109 pr_err("%s: No wake-up sources!\n", __func__);
110 pr_err("%s: Aborting sleep\n", __func__);
111 return -EINVAL;
112 }
113
114 s3c_pm_save_uarts();
115 s5pv210_pm_prepare();
116 flush_cache_all();
117 s3c_pm_check_store();
118
119 ret = cpu_suspend(0, s5pv210_cpu_suspend);
120 if (ret)
121 return ret;
122
123 s3c_pm_restore_uarts();
124
125 S3C_PMDBG("%s: wakeup stat: %08x\n", __func__,
126 __raw_readl(S5P_WAKEUP_STAT));
127
128 s3c_pm_check_restore();
129
130 S3C_PMDBG("%s: resuming the system...\n", __func__);
131
132 return 0;
133}
134
135static int s5pv210_suspend_prepare(void)
136{
137 s3c_pm_check_prepare();
138
139 return 0;
140}
141
142static void s5pv210_suspend_finish(void)
143{
144 s3c_pm_check_cleanup();
145}
146
147static const struct platform_suspend_ops s5pv210_suspend_ops = {
148 .enter = s5pv210_suspend_enter,
149 .prepare = s5pv210_suspend_prepare,
150 .finish = s5pv210_suspend_finish,
151 .valid = suspend_valid_only_mem,
152};
153
154/*
155 * Syscore operations used to delay restore of certain registers.
156 */
Rafael J. Wysockibb072c32011-04-22 22:03:21 +0200157static void s5pv210_pm_resume(void)
Jongpill Leeea31fd42010-10-02 19:13:42 +0900158{
159 u32 tmp;
160
161 tmp = __raw_readl(S5P_OTHERS);
162 tmp |= (S5P_OTHERS_RET_IO | S5P_OTHERS_RET_CF |\
163 S5P_OTHERS_RET_MMC | S5P_OTHERS_RET_UART);
164 __raw_writel(tmp , S5P_OTHERS);
165
166 s3c_pm_do_restore_core(s5pv210_core_save, ARRAY_SIZE(s5pv210_core_save));
Jongpill Leeea31fd42010-10-02 19:13:42 +0900167}
168
Rafael J. Wysockibb072c32011-04-22 22:03:21 +0200169static struct syscore_ops s5pv210_pm_syscore_ops = {
Jongpill Leeea31fd42010-10-02 19:13:42 +0900170 .resume = s5pv210_pm_resume,
171};
172
Tomasz Figa0a90d4d2014-07-02 19:37:45 +0200173/*
174 * Initialization entry point.
175 */
176void __init s5pv210_pm_init(void)
Jongpill Leeea31fd42010-10-02 19:13:42 +0900177{
Rafael J. Wysockibb072c32011-04-22 22:03:21 +0200178 register_syscore_ops(&s5pv210_pm_syscore_ops);
Tomasz Figa0a90d4d2014-07-02 19:37:45 +0200179 suspend_set_ops(&s5pv210_suspend_ops);
Jongpill Leeea31fd42010-10-02 19:13:42 +0900180}