]> git.proxmox.com Git - mirror_ubuntu-zesty-kernel.git/blame - drivers/cpuidle/cpuidle-mvebu-v7.c
cpuidle: mvebu: add Armada 370 support
[mirror_ubuntu-zesty-kernel.git] / drivers / cpuidle / cpuidle-mvebu-v7.c
CommitLineData
b858fbc1
GC
1/*
2 * Marvell Armada 370 and Armada XP SoC cpuidle driver
3 *
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
f50ee824 24#define MVEBU_V7_FLAG_DEEP_IDLE 0x10000
b858fbc1 25
f50ee824 26static int (*mvebu_v7_cpu_suspend)(int);
b858fbc1 27
f50ee824 28static int mvebu_v7_enter_idle(struct cpuidle_device *dev,
b858fbc1
GC
29 struct cpuidle_driver *drv,
30 int index)
31{
32 int ret;
33 bool deepidle = false;
34 cpu_pm_enter();
35
f50ee824 36 if (drv->states[index].flags & MVEBU_V7_FLAG_DEEP_IDLE)
b858fbc1
GC
37 deepidle = true;
38
f50ee824 39 ret = mvebu_v7_cpu_suspend(deepidle);
b858fbc1
GC
40 if (ret)
41 return ret;
42
43 cpu_pm_exit();
44
45 return index;
46}
47
f50ee824
GC
48static struct cpuidle_driver armadaxp_idle_driver = {
49 .name = "armada_xp_idle",
b858fbc1
GC
50 .states[0] = ARM_CPUIDLE_WFI_STATE,
51 .states[1] = {
f50ee824 52 .enter = mvebu_v7_enter_idle,
b858fbc1
GC
53 .exit_latency = 10,
54 .power_usage = 50,
55 .target_residency = 100,
56 .flags = CPUIDLE_FLAG_TIME_VALID,
57 .name = "MV CPU IDLE",
58 .desc = "CPU power down",
59 },
60 .states[2] = {
f50ee824 61 .enter = mvebu_v7_enter_idle,
b858fbc1
GC
62 .exit_latency = 100,
63 .power_usage = 5,
64 .target_residency = 1000,
65 .flags = CPUIDLE_FLAG_TIME_VALID |
f50ee824 66 MVEBU_V7_FLAG_DEEP_IDLE,
b858fbc1
GC
67 .name = "MV CPU DEEP IDLE",
68 .desc = "CPU and L2 Fabric power down",
69 },
f50ee824 70 .state_count = 3,
b858fbc1
GC
71};
72
c3c7fe7c
TP
73static struct cpuidle_driver armada370_idle_driver = {
74 .name = "armada_370_idle",
75 .states[0] = ARM_CPUIDLE_WFI_STATE,
76 .states[1] = {
77 .enter = mvebu_v7_enter_idle,
78 .exit_latency = 100,
79 .power_usage = 5,
80 .target_residency = 1000,
81 .flags = (CPUIDLE_FLAG_TIME_VALID |
82 MVEBU_V7_FLAG_DEEP_IDLE),
83 .name = "Deep Idle",
84 .desc = "CPU and L2 Fabric power down",
85 },
86 .state_count = 2,
87};
88
f50ee824 89static int mvebu_v7_cpuidle_probe(struct platform_device *pdev)
b858fbc1 90{
f50ee824 91 mvebu_v7_cpu_suspend = pdev->dev.platform_data;
c3c7fe7c
TP
92
93 if (!strcmp(pdev->dev.driver->name, "cpuidle-armada-xp"))
94 return cpuidle_register(&armadaxp_idle_driver, NULL);
95 else if (!strcmp(pdev->dev.driver->name, "cpuidle-armada-370"))
96 return cpuidle_register(&armada370_idle_driver, NULL);
97 else
98 return -EINVAL;
b858fbc1
GC
99}
100
f50ee824 101static struct platform_driver armadaxp_cpuidle_plat_driver = {
b858fbc1 102 .driver = {
f50ee824 103 .name = "cpuidle-armada-xp",
b858fbc1
GC
104 .owner = THIS_MODULE,
105 },
f50ee824 106 .probe = mvebu_v7_cpuidle_probe,
b858fbc1
GC
107};
108
f50ee824 109module_platform_driver(armadaxp_cpuidle_plat_driver);
b858fbc1 110
c3c7fe7c
TP
111static struct platform_driver armada370_cpuidle_plat_driver = {
112 .driver = {
113 .name = "cpuidle-armada-370",
114 .owner = THIS_MODULE,
115 },
116 .probe = mvebu_v7_cpuidle_probe,
117};
118
119module_platform_driver(armada370_cpuidle_plat_driver);
120
b858fbc1 121MODULE_AUTHOR("Gregory CLEMENT <gregory.clement@free-electrons.com>");
f50ee824 122MODULE_DESCRIPTION("Marvell EBU v7 cpuidle driver");
b858fbc1 123MODULE_LICENSE("GPL");