blob: 8125a153409378b7f389521499d2a9269475b2f3 [file] [log] [blame]
Jaecheol Lee3d739982011-03-16 07:28:23 +09001/* linux/arch/arm/mach-exynos4/cpuidle.c
2 *
3 * Copyright (c) 2011 Samsung Electronics Co., Ltd.
4 * http://www.samsung.com
5 *
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License version 2 as
8 * published by the Free Software Foundation.
9*/
10
11#include <linux/kernel.h>
12#include <linux/init.h>
13#include <linux/cpuidle.h>
Amit Daniel Kachhap67173ca2012-03-08 02:07:27 -080014#include <linux/cpu_pm.h>
Jaecheol Lee3d739982011-03-16 07:28:23 +090015#include <linux/io.h>
Kyungmin Park76ee4552011-11-08 19:57:59 +090016#include <linux/export.h>
Arnd Bergmann96c3a252014-03-19 18:29:36 +010017#include <linux/module.h>
Kyungmin Park76ee4552011-11-08 19:57:59 +090018#include <linux/time.h>
Bartlomiej Zolnierkiewicz35baa332013-08-30 12:15:04 +020019#include <linux/platform_device.h>
Jaecheol Lee3d739982011-03-16 07:28:23 +090020
21#include <asm/proc-fns.h>
Amit Daniel Kachhap67173ca2012-03-08 02:07:27 -080022#include <asm/smp_scu.h>
23#include <asm/suspend.h>
24#include <asm/unified.h>
Amit Daniel Kachhap06c77b32012-05-12 16:29:21 +090025#include <asm/cpuidle.h>
Amit Daniel Kachhap67173ca2012-03-08 02:07:27 -080026
27#include <plat/cpu.h>
Amit Daniel Kachhap89693012013-07-24 14:06:13 +090028#include <plat/pm.h>
Amit Daniel Kachhap67173ca2012-03-08 02:07:27 -080029
Kukjin Kimb5fd1302013-12-19 04:22:09 +090030#include <mach/map.h>
31
Kukjin Kimccd458c2012-12-31 10:06:48 -080032#include "common.h"
Kukjin Kim65c9a852013-12-19 04:06:56 +090033#include "regs-pmu.h"
Kukjin Kimccd458c2012-12-31 10:06:48 -080034
Amit Daniel Kachhap67173ca2012-03-08 02:07:27 -080035#define REG_DIRECTGO_ADDR (samsung_rev() == EXYNOS4210_REV_1_1 ? \
36 S5P_INFORM7 : (samsung_rev() == EXYNOS4210_REV_1_0 ? \
37 (S5P_VA_SYSRAM + 0x24) : S5P_INFORM0))
38#define REG_DIRECTGO_FLAG (samsung_rev() == EXYNOS4210_REV_1_1 ? \
39 S5P_INFORM6 : (samsung_rev() == EXYNOS4210_REV_1_0 ? \
40 (S5P_VA_SYSRAM + 0x20) : S5P_INFORM1))
41
42#define S5P_CHECK_AFTR 0xFCBA0D10
Jaecheol Lee3d739982011-03-16 07:28:23 +090043
Amit Daniel Kachhap67173ca2012-03-08 02:07:27 -080044static int exynos4_enter_lowpower(struct cpuidle_device *dev,
45 struct cpuidle_driver *drv,
46 int index);
Jaecheol Lee3d739982011-03-16 07:28:23 +090047
Jaecheol Lee3d739982011-03-16 07:28:23 +090048static DEFINE_PER_CPU(struct cpuidle_device, exynos4_cpuidle_device);
49
50static struct cpuidle_driver exynos4_idle_driver = {
Amit Daniel Kachhap06c77b32012-05-12 16:29:21 +090051 .name = "exynos4_idle",
52 .owner = THIS_MODULE,
Daniel Lezcano2eb89f82013-01-18 21:57:58 -080053 .states = {
54 [0] = ARM_CPUIDLE_WFI_STATE,
55 [1] = {
56 .enter = exynos4_enter_lowpower,
57 .exit_latency = 300,
58 .target_residency = 100000,
59 .flags = CPUIDLE_FLAG_TIME_VALID,
60 .name = "C1",
61 .desc = "ARM power down",
62 },
63 },
64 .state_count = 2,
65 .safe_state_index = 0,
Jaecheol Lee3d739982011-03-16 07:28:23 +090066};
67
Amit Daniel Kachhap67173ca2012-03-08 02:07:27 -080068/* Ext-GIC nIRQ/nFIQ is the only wakeup source in AFTR */
69static void exynos4_set_wakeupmask(void)
70{
71 __raw_writel(0x0000ff3e, S5P_WAKEUP_MASK);
72}
73
74static unsigned int g_pwr_ctrl, g_diag_reg;
75
76static void save_cpu_arch_register(void)
77{
78 /*read power control register*/
79 asm("mrc p15, 0, %0, c15, c0, 0" : "=r"(g_pwr_ctrl) : : "cc");
80 /*read diagnostic register*/
81 asm("mrc p15, 0, %0, c15, c0, 1" : "=r"(g_diag_reg) : : "cc");
82 return;
83}
84
85static void restore_cpu_arch_register(void)
86{
87 /*write power control register*/
88 asm("mcr p15, 0, %0, c15, c0, 0" : : "r"(g_pwr_ctrl) : "cc");
89 /*write diagnostic register*/
90 asm("mcr p15, 0, %0, c15, c0, 1" : : "r"(g_diag_reg) : "cc");
91 return;
92}
93
94static int idle_finisher(unsigned long flags)
95{
96 cpu_do_idle();
97 return 1;
98}
99
100static int exynos4_enter_core0_aftr(struct cpuidle_device *dev,
101 struct cpuidle_driver *drv,
102 int index)
103{
Amit Daniel Kachhap67173ca2012-03-08 02:07:27 -0800104 unsigned long tmp;
105
Amit Daniel Kachhap67173ca2012-03-08 02:07:27 -0800106 exynos4_set_wakeupmask();
107
108 /* Set value of power down register for aftr mode */
Jongpill Lee7d44d2b2012-02-17 09:51:31 +0900109 exynos_sys_powerdown_conf(SYS_AFTR);
Amit Daniel Kachhap67173ca2012-03-08 02:07:27 -0800110
Tomasz Figa8dec0672014-03-21 02:59:30 +0900111 __raw_writel(virt_to_phys(exynos_cpu_resume), REG_DIRECTGO_ADDR);
Amit Daniel Kachhap67173ca2012-03-08 02:07:27 -0800112 __raw_writel(S5P_CHECK_AFTR, REG_DIRECTGO_FLAG);
113
114 save_cpu_arch_register();
115
116 /* Setting Central Sequence Register for power down mode */
117 tmp = __raw_readl(S5P_CENTRAL_SEQ_CONFIGURATION);
118 tmp &= ~S5P_CENTRAL_LOWPWR_CFG;
119 __raw_writel(tmp, S5P_CENTRAL_SEQ_CONFIGURATION);
120
121 cpu_pm_enter();
122 cpu_suspend(0, idle_finisher);
123
124#ifdef CONFIG_SMP
Abhilash Kesavana6332082012-11-22 14:46:34 +0900125 if (!soc_is_exynos5250())
126 scu_enable(S5P_VA_SCU);
Amit Daniel Kachhap67173ca2012-03-08 02:07:27 -0800127#endif
128 cpu_pm_exit();
129
130 restore_cpu_arch_register();
131
132 /*
133 * If PMU failed while entering sleep mode, WFI will be
134 * ignored by PMU and then exiting cpu_do_idle().
135 * S5P_CENTRAL_LOWPWR_CFG bit will not be set automatically
136 * in this situation.
137 */
138 tmp = __raw_readl(S5P_CENTRAL_SEQ_CONFIGURATION);
139 if (!(tmp & S5P_CENTRAL_LOWPWR_CFG)) {
140 tmp |= S5P_CENTRAL_LOWPWR_CFG;
141 __raw_writel(tmp, S5P_CENTRAL_SEQ_CONFIGURATION);
142 }
143
144 /* Clear wakeup state register */
145 __raw_writel(0x0, S5P_WAKEUP_STAT);
146
Deepthi Dharware978aa72011-10-28 16:20:09 +0530147 return index;
Jaecheol Lee3d739982011-03-16 07:28:23 +0900148}
149
Amit Daniel Kachhap67173ca2012-03-08 02:07:27 -0800150static int exynos4_enter_lowpower(struct cpuidle_device *dev,
151 struct cpuidle_driver *drv,
152 int index)
153{
154 int new_index = index;
155
Bartlomiej Zolnierkiewicz118f5c12013-12-20 19:47:23 +0100156 /* AFTR can only be entered when cores other than CPU0 are offline */
157 if (num_online_cpus() > 1 || dev->cpu != 0)
Amit Daniel Kachhap67173ca2012-03-08 02:07:27 -0800158 new_index = drv->safe_state_index;
159
160 if (new_index == 0)
Amit Daniel Kachhap06c77b32012-05-12 16:29:21 +0900161 return arm_cpuidle_simple_enter(dev, drv, new_index);
Amit Daniel Kachhap67173ca2012-03-08 02:07:27 -0800162 else
163 return exynos4_enter_core0_aftr(dev, drv, new_index);
164}
165
Jingoo Hanf612a4f2013-10-21 10:53:03 +0900166static int exynos_cpuidle_probe(struct platform_device *pdev)
Jaecheol Lee3d739982011-03-16 07:28:23 +0900167{
Daniel Lezcano5db9f432013-01-18 21:57:58 -0800168 int cpu_id, ret;
Jaecheol Lee3d739982011-03-16 07:28:23 +0900169 struct cpuidle_device *device;
170
Amit Daniel Kachhap1e9fec02013-08-28 00:48:24 +0900171 if (soc_is_exynos5440())
172 exynos4_idle_driver.state_count = 1;
173
Daniel Lezcano5db9f432013-01-18 21:57:58 -0800174 ret = cpuidle_register_driver(&exynos4_idle_driver);
175 if (ret) {
Jingoo Hanae7c4c82013-10-21 10:52:15 +0900176 dev_err(&pdev->dev, "failed to register cpuidle driver\n");
Daniel Lezcano5db9f432013-01-18 21:57:58 -0800177 return ret;
Deepthi Dharwar46bcfad2011-10-28 16:20:42 +0530178 }
Jaecheol Lee3d739982011-03-16 07:28:23 +0900179
Daniel Lezcano329afd22013-01-18 21:57:58 -0800180 for_each_online_cpu(cpu_id) {
Jaecheol Lee3d739982011-03-16 07:28:23 +0900181 device = &per_cpu(exynos4_cpuidle_device, cpu_id);
182 device->cpu = cpu_id;
183
Daniel Lezcano5db9f432013-01-18 21:57:58 -0800184 ret = cpuidle_register_device(device);
185 if (ret) {
Jingoo Hanae7c4c82013-10-21 10:52:15 +0900186 dev_err(&pdev->dev, "failed to register cpuidle device\n");
Daniel Lezcano5db9f432013-01-18 21:57:58 -0800187 return ret;
Jaecheol Lee3d739982011-03-16 07:28:23 +0900188 }
189 }
Amit Daniel Kachhap67173ca2012-03-08 02:07:27 -0800190
Jaecheol Lee3d739982011-03-16 07:28:23 +0900191 return 0;
192}
Bartlomiej Zolnierkiewicz35baa332013-08-30 12:15:04 +0200193
194static struct platform_driver exynos_cpuidle_driver = {
195 .probe = exynos_cpuidle_probe,
196 .driver = {
197 .name = "exynos_cpuidle",
198 .owner = THIS_MODULE,
199 },
200};
201
202module_platform_driver(exynos_cpuidle_driver);