blob: 38e68618513a4728fe637a46b6a6ce79edb54730 [file] [log] [blame]
Gregory CLEMENTf50ee822014-07-23 15:00:48 +02001/*
Thomas Petazzonic16788b2014-07-23 15:00:50 +02002 * Marvell Armada 370, 38x and XP SoC cpuidle driver
Gregory CLEMENTf50ee822014-07-23 15:00:48 +02003 *
4 * Copyright (C) 2014 Marvell
5 *
6 * Nadav Haklai <nadavh@marvell.com>
7 * Gregory CLEMENT <gregory.clement@free-electrons.com>
8 *
9 * This file is licensed under the terms of the GNU General Public
10 * License version 2. This program is licensed "as is" without any
11 * warranty of any kind, whether express or implied.
12 *
13 * Maintainer: Gregory CLEMENT <gregory.clement@free-electrons.com>
14 */
15
16#include <linux/cpu_pm.h>
17#include <linux/cpuidle.h>
18#include <linux/module.h>
19#include <linux/of.h>
20#include <linux/suspend.h>
21#include <linux/platform_device.h>
22#include <asm/cpuidle.h>
23
24#define MVEBU_V7_FLAG_DEEP_IDLE 0x10000
25
26static int (*mvebu_v7_cpu_suspend)(int);
27
28static int mvebu_v7_enter_idle(struct cpuidle_device *dev,
29 struct cpuidle_driver *drv,
30 int index)
31{
32 int ret;
33 bool deepidle = false;
34 cpu_pm_enter();
35
36 if (drv->states[index].flags & MVEBU_V7_FLAG_DEEP_IDLE)
37 deepidle = true;
38
39 ret = mvebu_v7_cpu_suspend(deepidle);
40 if (ret)
41 return ret;
42
43 cpu_pm_exit();
44
45 return index;
46}
47
48static struct cpuidle_driver armadaxp_idle_driver = {
49 .name = "armada_xp_idle",
50 .states[0] = ARM_CPUIDLE_WFI_STATE,
51 .states[1] = {
52 .enter = mvebu_v7_enter_idle,
53 .exit_latency = 10,
54 .power_usage = 50,
55 .target_residency = 100,
Gregory CLEMENTf50ee822014-07-23 15:00:48 +020056 .name = "MV CPU IDLE",
57 .desc = "CPU power down",
58 },
59 .states[2] = {
60 .enter = mvebu_v7_enter_idle,
61 .exit_latency = 100,
62 .power_usage = 5,
63 .target_residency = 1000,
Daniel Lezcanob82b6cc2014-11-12 16:03:50 +010064 .flags = MVEBU_V7_FLAG_DEEP_IDLE,
Gregory CLEMENTf50ee822014-07-23 15:00:48 +020065 .name = "MV CPU DEEP IDLE",
66 .desc = "CPU and L2 Fabric power down",
67 },
68 .state_count = 3,
69};
70
Thomas Petazzonic3c7fe72014-07-23 15:00:49 +020071static struct cpuidle_driver armada370_idle_driver = {
72 .name = "armada_370_idle",
73 .states[0] = ARM_CPUIDLE_WFI_STATE,
74 .states[1] = {
75 .enter = mvebu_v7_enter_idle,
76 .exit_latency = 100,
77 .power_usage = 5,
78 .target_residency = 1000,
Daniel Lezcanob82b6cc2014-11-12 16:03:50 +010079 .flags = MVEBU_V7_FLAG_DEEP_IDLE,
Thomas Petazzonic3c7fe72014-07-23 15:00:49 +020080 .name = "Deep Idle",
81 .desc = "CPU and L2 Fabric power down",
82 },
83 .state_count = 2,
84};
85
Thomas Petazzonic16788b2014-07-23 15:00:50 +020086static struct cpuidle_driver armada38x_idle_driver = {
87 .name = "armada_38x_idle",
88 .states[0] = ARM_CPUIDLE_WFI_STATE,
89 .states[1] = {
90 .enter = mvebu_v7_enter_idle,
91 .exit_latency = 10,
92 .power_usage = 5,
93 .target_residency = 100,
Thomas Petazzonic16788b2014-07-23 15:00:50 +020094 .name = "Idle",
95 .desc = "CPU and SCU power down",
96 },
97 .state_count = 2,
98};
99
Gregory CLEMENTf50ee822014-07-23 15:00:48 +0200100static int mvebu_v7_cpuidle_probe(struct platform_device *pdev)
101{
Gregory CLEMENTf50ee822014-07-23 15:00:48 +0200102 mvebu_v7_cpu_suspend = pdev->dev.platform_data;
Thomas Petazzonic3c7fe72014-07-23 15:00:49 +0200103
104 if (!strcmp(pdev->dev.driver->name, "cpuidle-armada-xp"))
105 return cpuidle_register(&armadaxp_idle_driver, NULL);
106 else if (!strcmp(pdev->dev.driver->name, "cpuidle-armada-370"))
107 return cpuidle_register(&armada370_idle_driver, NULL);
Thomas Petazzonic16788b2014-07-23 15:00:50 +0200108 else if (!strcmp(pdev->dev.driver->name, "cpuidle-armada-38x"))
109 return cpuidle_register(&armada38x_idle_driver, NULL);
Thomas Petazzonic3c7fe72014-07-23 15:00:49 +0200110 else
111 return -EINVAL;
Gregory CLEMENTf50ee822014-07-23 15:00:48 +0200112}
113
114static struct platform_driver armadaxp_cpuidle_plat_driver = {
115 .driver = {
116 .name = "cpuidle-armada-xp",
Gregory CLEMENTf50ee822014-07-23 15:00:48 +0200117 },
118 .probe = mvebu_v7_cpuidle_probe,
119};
120
121module_platform_driver(armadaxp_cpuidle_plat_driver);
122
Thomas Petazzonic3c7fe72014-07-23 15:00:49 +0200123static struct platform_driver armada370_cpuidle_plat_driver = {
124 .driver = {
125 .name = "cpuidle-armada-370",
Thomas Petazzonic3c7fe72014-07-23 15:00:49 +0200126 },
127 .probe = mvebu_v7_cpuidle_probe,
128};
129
130module_platform_driver(armada370_cpuidle_plat_driver);
131
Thomas Petazzonic16788b2014-07-23 15:00:50 +0200132static struct platform_driver armada38x_cpuidle_plat_driver = {
133 .driver = {
134 .name = "cpuidle-armada-38x",
Thomas Petazzonic16788b2014-07-23 15:00:50 +0200135 },
136 .probe = mvebu_v7_cpuidle_probe,
137};
138
139module_platform_driver(armada38x_cpuidle_plat_driver);
140
Gregory CLEMENTf50ee822014-07-23 15:00:48 +0200141MODULE_AUTHOR("Gregory CLEMENT <gregory.clement@free-electrons.com>");
142MODULE_DESCRIPTION("Marvell EBU v7 cpuidle driver");
143MODULE_LICENSE("GPL");