blob: b5f0a9cc8185c593688a9b9f75b0ec6547800da3 [file] [log] [blame]
Bartlomiej Zolnierkiewicz712eddf2015-01-24 14:05:50 +09001/*
2 * Copyright (c) 2011-2014 Samsung Electronics Co., Ltd.
Jaecheol Lee3d739982011-03-16 07:28:23 +09003 * http://www.samsung.com
4 *
Bartlomiej Zolnierkiewicz712eddf2015-01-24 14:05:50 +09005 * Coupled cpuidle support based on the work of:
6 * Colin Cross <ccross@android.com>
7 * Daniel Lezcano <daniel.lezcano@linaro.org>
8 *
Jaecheol Lee3d739982011-03-16 07:28:23 +09009 * This program is free software; you can redistribute it and/or modify
10 * it under the terms of the GNU General Public License version 2 as
11 * published by the Free Software Foundation.
12*/
13
Jaecheol Lee3d739982011-03-16 07:28:23 +090014#include <linux/cpuidle.h>
Amit Daniel Kachhap67173ca2012-03-08 02:07:27 -080015#include <linux/cpu_pm.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>
Bartlomiej Zolnierkiewicz35baa332013-08-30 12:15:04 +020018#include <linux/platform_device.h>
Bartlomiej Zolnierkiewicz712eddf2015-01-24 14:05:50 +090019#include <linux/of.h>
20#include <linux/platform_data/cpuidle-exynos.h>
Jaecheol Lee3d739982011-03-16 07:28:23 +090021
Amit Daniel Kachhap67173ca2012-03-08 02:07:27 -080022#include <asm/suspend.h>
Amit Daniel Kachhap06c77b32012-05-12 16:29:21 +090023#include <asm/cpuidle.h>
Amit Daniel Kachhap67173ca2012-03-08 02:07:27 -080024
Bartlomiej Zolnierkiewicz712eddf2015-01-24 14:05:50 +090025static atomic_t exynos_idle_barrier;
26
27static struct cpuidle_exynos_data *exynos_cpuidle_pdata;
Daniel Lezcano277f5042014-05-09 06:56:29 +090028static void (*exynos_enter_aftr)(void);
Kukjin Kimccd458c2012-12-31 10:06:48 -080029
Bartlomiej Zolnierkiewicz712eddf2015-01-24 14:05:50 +090030static int exynos_enter_coupled_lowpower(struct cpuidle_device *dev,
31 struct cpuidle_driver *drv,
32 int index)
33{
34 int ret;
35
36 exynos_cpuidle_pdata->pre_enter_aftr();
37
38 /*
39 * Waiting all cpus to reach this point at the same moment
40 */
41 cpuidle_coupled_parallel_barrier(dev, &exynos_idle_barrier);
42
43 /*
44 * Both cpus will reach this point at the same time
45 */
46 ret = dev->cpu ? exynos_cpuidle_pdata->cpu1_powerdown()
47 : exynos_cpuidle_pdata->cpu0_enter_aftr();
48 if (ret)
49 index = ret;
50
51 /*
52 * Waiting all cpus to finish the power sequence before going further
53 */
54 cpuidle_coupled_parallel_barrier(dev, &exynos_idle_barrier);
55
56 exynos_cpuidle_pdata->post_enter_aftr();
57
58 return index;
59}
60
Daniel Lezcano7880e452014-05-09 06:43:26 +090061static int exynos_enter_lowpower(struct cpuidle_device *dev,
Amit Daniel Kachhap67173ca2012-03-08 02:07:27 -080062 struct cpuidle_driver *drv,
63 int index)
64{
65 int new_index = index;
66
Bartlomiej Zolnierkiewicz118f5c12013-12-20 19:47:23 +010067 /* AFTR can only be entered when cores other than CPU0 are offline */
68 if (num_online_cpus() > 1 || dev->cpu != 0)
Amit Daniel Kachhap67173ca2012-03-08 02:07:27 -080069 new_index = drv->safe_state_index;
70
71 if (new_index == 0)
Amit Daniel Kachhap06c77b32012-05-12 16:29:21 +090072 return arm_cpuidle_simple_enter(dev, drv, new_index);
Tomasz Figa01601b32014-08-05 14:43:10 +020073
74 exynos_enter_aftr();
75
76 return new_index;
Amit Daniel Kachhap67173ca2012-03-08 02:07:27 -080077}
78
Daniel Lezcano7880e452014-05-09 06:43:26 +090079static struct cpuidle_driver exynos_idle_driver = {
80 .name = "exynos_idle",
Daniel Lezcano53af16a2014-05-09 06:43:26 +090081 .owner = THIS_MODULE,
82 .states = {
83 [0] = ARM_CPUIDLE_WFI_STATE,
84 [1] = {
Daniel Lezcano7880e452014-05-09 06:43:26 +090085 .enter = exynos_enter_lowpower,
Daniel Lezcano53af16a2014-05-09 06:43:26 +090086 .exit_latency = 300,
87 .target_residency = 100000,
Daniel Lezcano53af16a2014-05-09 06:43:26 +090088 .name = "C1",
89 .desc = "ARM power down",
90 },
91 },
92 .state_count = 2,
93 .safe_state_index = 0,
94};
95
Bartlomiej Zolnierkiewicz712eddf2015-01-24 14:05:50 +090096static struct cpuidle_driver exynos_coupled_idle_driver = {
97 .name = "exynos_coupled_idle",
98 .owner = THIS_MODULE,
99 .states = {
100 [0] = ARM_CPUIDLE_WFI_STATE,
101 [1] = {
102 .enter = exynos_enter_coupled_lowpower,
103 .exit_latency = 5000,
104 .target_residency = 10000,
105 .flags = CPUIDLE_FLAG_COUPLED |
106 CPUIDLE_FLAG_TIMER_STOP,
107 .name = "C1",
108 .desc = "ARM power down",
109 },
110 },
111 .state_count = 2,
112 .safe_state_index = 0,
113};
114
Jingoo Hanf612a4f2013-10-21 10:53:03 +0900115static int exynos_cpuidle_probe(struct platform_device *pdev)
Jaecheol Lee3d739982011-03-16 07:28:23 +0900116{
Daniel Lezcano043c86b2014-05-09 06:43:26 +0900117 int ret;
Jaecheol Lee3d739982011-03-16 07:28:23 +0900118
Bartlomiej Zolnierkiewiczcfdda352015-03-18 03:26:11 +0900119 if (IS_ENABLED(CONFIG_SMP) &&
120 of_machine_is_compatible("samsung,exynos4210")) {
Bartlomiej Zolnierkiewicz712eddf2015-01-24 14:05:50 +0900121 exynos_cpuidle_pdata = pdev->dev.platform_data;
Daniel Lezcano277f5042014-05-09 06:56:29 +0900122
Bartlomiej Zolnierkiewicz712eddf2015-01-24 14:05:50 +0900123 ret = cpuidle_register(&exynos_coupled_idle_driver,
124 cpu_possible_mask);
125 } else {
126 exynos_enter_aftr = (void *)(pdev->dev.platform_data);
127
128 ret = cpuidle_register(&exynos_idle_driver, NULL);
129 }
130
Daniel Lezcano5db9f432013-01-18 21:57:58 -0800131 if (ret) {
Jingoo Hanae7c4c82013-10-21 10:52:15 +0900132 dev_err(&pdev->dev, "failed to register cpuidle driver\n");
Daniel Lezcano5db9f432013-01-18 21:57:58 -0800133 return ret;
Deepthi Dharwar46bcfad2011-10-28 16:20:42 +0530134 }
Jaecheol Lee3d739982011-03-16 07:28:23 +0900135
Jaecheol Lee3d739982011-03-16 07:28:23 +0900136 return 0;
137}
Bartlomiej Zolnierkiewicz35baa332013-08-30 12:15:04 +0200138
139static struct platform_driver exynos_cpuidle_driver = {
140 .probe = exynos_cpuidle_probe,
141 .driver = {
142 .name = "exynos_cpuidle",
Bartlomiej Zolnierkiewicz35baa332013-08-30 12:15:04 +0200143 },
144};
145
146module_platform_driver(exynos_cpuidle_driver);