ARM: EXYNOS: Add generic cluster power control functions
[linux-2.6/btrfs-unstable.git] / arch / arm / mach-exynos / pm.c
blob3f2ae864582ec3c742f3ceabf5a0066549a52ceb
1 /*
2 * Copyright (c) 2011-2012 Samsung Electronics Co., Ltd.
3 * http://www.samsung.com
5 * EXYNOS - Power Management support
7 * Based on arch/arm/mach-s3c2410/pm.c
8 * Copyright (c) 2006 Simtec Electronics
9 * Ben Dooks <ben@simtec.co.uk>
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.
16 #include <linux/init.h>
17 #include <linux/suspend.h>
18 #include <linux/syscore_ops.h>
19 #include <linux/io.h>
20 #include <linux/irqchip/arm-gic.h>
21 #include <linux/err.h>
22 #include <linux/clk.h>
24 #include <asm/cacheflush.h>
25 #include <asm/hardware/cache-l2x0.h>
26 #include <asm/smp_scu.h>
27 #include <asm/suspend.h>
29 #include <plat/cpu.h>
30 #include <plat/pm-common.h>
31 #include <plat/pll.h>
32 #include <plat/regs-srom.h>
34 #include <mach/map.h>
36 #include "common.h"
37 #include "regs-pmu.h"
39 /**
40 * struct exynos_wkup_irq - Exynos GIC to PMU IRQ mapping
41 * @hwirq: Hardware IRQ signal of the GIC
42 * @mask: Mask in PMU wake-up mask register
44 struct exynos_wkup_irq {
45 unsigned int hwirq;
46 u32 mask;
49 static struct sleep_save exynos5_sys_save[] = {
50 SAVE_ITEM(EXYNOS5_SYS_I2C_CFG),
53 static struct sleep_save exynos_core_save[] = {
54 /* SROM side */
55 SAVE_ITEM(S5P_SROM_BW),
56 SAVE_ITEM(S5P_SROM_BC0),
57 SAVE_ITEM(S5P_SROM_BC1),
58 SAVE_ITEM(S5P_SROM_BC2),
59 SAVE_ITEM(S5P_SROM_BC3),
63 * GIC wake-up support
66 static u32 exynos_irqwake_intmask = 0xffffffff;
68 static const struct exynos_wkup_irq exynos4_wkup_irq[] = {
69 { 76, BIT(1) }, /* RTC alarm */
70 { 77, BIT(2) }, /* RTC tick */
71 { /* sentinel */ },
74 static const struct exynos_wkup_irq exynos5250_wkup_irq[] = {
75 { 75, BIT(1) }, /* RTC alarm */
76 { 76, BIT(2) }, /* RTC tick */
77 { /* sentinel */ },
80 static int exynos_irq_set_wake(struct irq_data *data, unsigned int state)
82 const struct exynos_wkup_irq *wkup_irq;
84 if (soc_is_exynos5250())
85 wkup_irq = exynos5250_wkup_irq;
86 else
87 wkup_irq = exynos4_wkup_irq;
89 while (wkup_irq->mask) {
90 if (wkup_irq->hwirq == data->hwirq) {
91 if (!state)
92 exynos_irqwake_intmask |= wkup_irq->mask;
93 else
94 exynos_irqwake_intmask &= ~wkup_irq->mask;
95 return 0;
97 ++wkup_irq;
100 return -ENOENT;
104 * exynos_core_power_down : power down the specified cpu
105 * @cpu : the cpu to power down
107 * Power down the specified cpu. The sequence must be finished by a
108 * call to cpu_do_idle()
111 void exynos_cpu_power_down(int cpu)
113 __raw_writel(0, EXYNOS_ARM_CORE_CONFIGURATION(cpu));
117 * exynos_cpu_power_up : power up the specified cpu
118 * @cpu : the cpu to power up
120 * Power up the specified cpu
122 void exynos_cpu_power_up(int cpu)
124 __raw_writel(S5P_CORE_LOCAL_PWR_EN,
125 EXYNOS_ARM_CORE_CONFIGURATION(cpu));
129 * exynos_cpu_power_state : returns the power state of the cpu
130 * @cpu : the cpu to retrieve the power state from
133 int exynos_cpu_power_state(int cpu)
135 return (__raw_readl(EXYNOS_ARM_CORE_STATUS(cpu)) &
136 S5P_CORE_LOCAL_PWR_EN);
140 * exynos_cluster_power_down : power down the specified cluster
141 * @cluster : the cluster to power down
143 void exynos_cluster_power_down(int cluster)
145 __raw_writel(0, EXYNOS_COMMON_CONFIGURATION(cluster));
149 * exynos_cluster_power_up : power up the specified cluster
150 * @cluster : the cluster to power up
152 void exynos_cluster_power_up(int cluster)
154 __raw_writel(S5P_CORE_LOCAL_PWR_EN,
155 EXYNOS_COMMON_CONFIGURATION(cluster));
159 * exynos_cluster_power_state : returns the power state of the cluster
160 * @cluster : the cluster to retrieve the power state from
163 int exynos_cluster_power_state(int cluster)
165 return (__raw_readl(EXYNOS_COMMON_STATUS(cluster)) &
166 S5P_CORE_LOCAL_PWR_EN);
169 /* For Cortex-A9 Diagnostic and Power control register */
170 static unsigned int save_arm_register[2];
172 static int exynos_cpu_suspend(unsigned long arg)
174 #ifdef CONFIG_CACHE_L2X0
175 outer_flush_all();
176 #endif
178 if (soc_is_exynos5250())
179 flush_cache_all();
181 /* issue the standby signal into the pm unit. */
182 cpu_do_idle();
184 pr_info("Failed to suspend the system\n");
185 return 1; /* Aborting suspend */
188 static void exynos_pm_prepare(void)
190 unsigned int tmp;
192 /* Set wake-up mask registers */
193 __raw_writel(exynos_get_eint_wake_mask(), S5P_EINT_WAKEUP_MASK);
194 __raw_writel(exynos_irqwake_intmask & ~(1 << 31), S5P_WAKEUP_MASK);
196 s3c_pm_do_save(exynos_core_save, ARRAY_SIZE(exynos_core_save));
198 if (soc_is_exynos5250()) {
199 s3c_pm_do_save(exynos5_sys_save, ARRAY_SIZE(exynos5_sys_save));
200 /* Disable USE_RETENTION of JPEG_MEM_OPTION */
201 tmp = __raw_readl(EXYNOS5_JPEG_MEM_OPTION);
202 tmp &= ~EXYNOS5_OPTION_USE_RETENTION;
203 __raw_writel(tmp, EXYNOS5_JPEG_MEM_OPTION);
206 /* Set value of power down register for sleep mode */
208 exynos_sys_powerdown_conf(SYS_SLEEP);
209 __raw_writel(S5P_CHECK_SLEEP, S5P_INFORM1);
211 /* ensure at least INFORM0 has the resume address */
213 __raw_writel(virt_to_phys(exynos_cpu_resume), S5P_INFORM0);
216 static int exynos_pm_suspend(void)
218 unsigned long tmp;
220 /* Setting Central Sequence Register for power down mode */
222 tmp = __raw_readl(S5P_CENTRAL_SEQ_CONFIGURATION);
223 tmp &= ~S5P_CENTRAL_LOWPWR_CFG;
224 __raw_writel(tmp, S5P_CENTRAL_SEQ_CONFIGURATION);
226 /* Setting SEQ_OPTION register */
228 tmp = (S5P_USE_STANDBY_WFI0 | S5P_USE_STANDBY_WFE0);
229 __raw_writel(tmp, S5P_CENTRAL_SEQ_OPTION);
231 if (!soc_is_exynos5250()) {
232 /* Save Power control register */
233 asm ("mrc p15, 0, %0, c15, c0, 0"
234 : "=r" (tmp) : : "cc");
235 save_arm_register[0] = tmp;
237 /* Save Diagnostic register */
238 asm ("mrc p15, 0, %0, c15, c0, 1"
239 : "=r" (tmp) : : "cc");
240 save_arm_register[1] = tmp;
243 return 0;
246 static void exynos_pm_resume(void)
248 unsigned long tmp;
251 * If PMU failed while entering sleep mode, WFI will be
252 * ignored by PMU and then exiting cpu_do_idle().
253 * S5P_CENTRAL_LOWPWR_CFG bit will not be set automatically
254 * in this situation.
256 tmp = __raw_readl(S5P_CENTRAL_SEQ_CONFIGURATION);
257 if (!(tmp & S5P_CENTRAL_LOWPWR_CFG)) {
258 tmp |= S5P_CENTRAL_LOWPWR_CFG;
259 __raw_writel(tmp, S5P_CENTRAL_SEQ_CONFIGURATION);
260 /* clear the wakeup state register */
261 __raw_writel(0x0, S5P_WAKEUP_STAT);
262 /* No need to perform below restore code */
263 goto early_wakeup;
265 if (!soc_is_exynos5250()) {
266 /* Restore Power control register */
267 tmp = save_arm_register[0];
268 asm volatile ("mcr p15, 0, %0, c15, c0, 0"
269 : : "r" (tmp)
270 : "cc");
272 /* Restore Diagnostic register */
273 tmp = save_arm_register[1];
274 asm volatile ("mcr p15, 0, %0, c15, c0, 1"
275 : : "r" (tmp)
276 : "cc");
279 /* For release retention */
281 __raw_writel((1 << 28), S5P_PAD_RET_MAUDIO_OPTION);
282 __raw_writel((1 << 28), S5P_PAD_RET_GPIO_OPTION);
283 __raw_writel((1 << 28), S5P_PAD_RET_UART_OPTION);
284 __raw_writel((1 << 28), S5P_PAD_RET_MMCA_OPTION);
285 __raw_writel((1 << 28), S5P_PAD_RET_MMCB_OPTION);
286 __raw_writel((1 << 28), S5P_PAD_RET_EBIA_OPTION);
287 __raw_writel((1 << 28), S5P_PAD_RET_EBIB_OPTION);
289 if (soc_is_exynos5250())
290 s3c_pm_do_restore(exynos5_sys_save,
291 ARRAY_SIZE(exynos5_sys_save));
293 s3c_pm_do_restore_core(exynos_core_save, ARRAY_SIZE(exynos_core_save));
295 if (IS_ENABLED(CONFIG_SMP) && !soc_is_exynos5250())
296 scu_enable(S5P_VA_SCU);
298 early_wakeup:
300 /* Clear SLEEP mode set in INFORM1 */
301 __raw_writel(0x0, S5P_INFORM1);
303 return;
306 static struct syscore_ops exynos_pm_syscore_ops = {
307 .suspend = exynos_pm_suspend,
308 .resume = exynos_pm_resume,
312 * Suspend Ops
315 static int exynos_suspend_enter(suspend_state_t state)
317 int ret;
319 s3c_pm_debug_init();
321 S3C_PMDBG("%s: suspending the system...\n", __func__);
323 S3C_PMDBG("%s: wakeup masks: %08x,%08x\n", __func__,
324 exynos_irqwake_intmask, exynos_get_eint_wake_mask());
326 if (exynos_irqwake_intmask == -1U
327 && exynos_get_eint_wake_mask() == -1U) {
328 pr_err("%s: No wake-up sources!\n", __func__);
329 pr_err("%s: Aborting sleep\n", __func__);
330 return -EINVAL;
333 s3c_pm_save_uarts();
334 exynos_pm_prepare();
335 flush_cache_all();
336 s3c_pm_check_store();
338 ret = cpu_suspend(0, exynos_cpu_suspend);
339 if (ret)
340 return ret;
342 s3c_pm_restore_uarts();
344 S3C_PMDBG("%s: wakeup stat: %08x\n", __func__,
345 __raw_readl(S5P_WAKEUP_STAT));
347 s3c_pm_check_restore();
349 S3C_PMDBG("%s: resuming the system...\n", __func__);
351 return 0;
354 static int exynos_suspend_prepare(void)
356 s3c_pm_check_prepare();
358 return 0;
361 static void exynos_suspend_finish(void)
363 s3c_pm_check_cleanup();
366 static const struct platform_suspend_ops exynos_suspend_ops = {
367 .enter = exynos_suspend_enter,
368 .prepare = exynos_suspend_prepare,
369 .finish = exynos_suspend_finish,
370 .valid = suspend_valid_only_mem,
373 void __init exynos_pm_init(void)
375 u32 tmp;
377 /* Platform-specific GIC callback */
378 gic_arch_extn.irq_set_wake = exynos_irq_set_wake;
380 /* All wakeup disable */
381 tmp = __raw_readl(S5P_WAKEUP_MASK);
382 tmp |= ((0xFF << 8) | (0x1F << 1));
383 __raw_writel(tmp, S5P_WAKEUP_MASK);
385 register_syscore_ops(&exynos_pm_syscore_ops);
386 suspend_set_ops(&exynos_suspend_ops);