PM / AVS: rockchip-io: add io selectors and supplies for rk3399
[linux-2.6-block.git] / drivers / cpuidle / cpuidle-mvebu-v7.c
CommitLineData
b858fbc1 1/*
c16788b4 2 * Marvell Armada 370, 38x and XP SoC cpuidle driver
b858fbc1
GC
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);
43b68879
GC
40 cpu_pm_exit();
41
b858fbc1
GC
42 if (ret)
43 return ret;
44
b858fbc1
GC
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,
ce6031c8 53 .exit_latency = 100,
b858fbc1 54 .power_usage = 50,
ce6031c8 55 .target_residency = 1000,
b858fbc1
GC
56 .name = "MV CPU IDLE",
57 .desc = "CPU power down",
58 },
59 .states[2] = {
f50ee824 60 .enter = mvebu_v7_enter_idle,
ce6031c8 61 .exit_latency = 1000,
b858fbc1 62 .power_usage = 5,
ce6031c8 63 .target_residency = 10000,
b82b6cca 64 .flags = MVEBU_V7_FLAG_DEEP_IDLE,
b858fbc1
GC
65 .name = "MV CPU DEEP IDLE",
66 .desc = "CPU and L2 Fabric power down",
67 },
f50ee824 68 .state_count = 3,
b858fbc1
GC
69};
70
c3c7fe7c
TP
71static 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,
b82b6cca 79 .flags = MVEBU_V7_FLAG_DEEP_IDLE,
c3c7fe7c
TP
80 .name = "Deep Idle",
81 .desc = "CPU and L2 Fabric power down",
82 },
83 .state_count = 2,
84};
85
c16788b4
TP
86static 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,
c16788b4
TP
94 .name = "Idle",
95 .desc = "CPU and SCU power down",
96 },
97 .state_count = 2,
98};
99
f50ee824 100static int mvebu_v7_cpuidle_probe(struct platform_device *pdev)
b858fbc1 101{
da1a64f8 102 const struct platform_device_id *id = pdev->id_entry;
c3c7fe7c 103
da1a64f8 104 if (!id)
c3c7fe7c 105 return -EINVAL;
b858fbc1 106
da1a64f8 107 mvebu_v7_cpu_suspend = pdev->dev.platform_data;
b858fbc1 108
da1a64f8
RK
109 return cpuidle_register((struct cpuidle_driver *)id->driver_data, NULL);
110}
b858fbc1 111
da1a64f8
RK
112static const struct platform_device_id mvebu_cpuidle_ids[] = {
113 {
114 .name = "cpuidle-armada-xp",
115 .driver_data = (unsigned long)&armadaxp_idle_driver,
116 }, {
c3c7fe7c 117 .name = "cpuidle-armada-370",
da1a64f8
RK
118 .driver_data = (unsigned long)&armada370_idle_driver,
119 }, {
120 .name = "cpuidle-armada-38x",
121 .driver_data = (unsigned long)&armada38x_idle_driver,
c3c7fe7c 122 },
da1a64f8 123 {}
c3c7fe7c
TP
124};
125
da1a64f8
RK
126static struct platform_driver mvebu_cpuidle_driver = {
127 .probe = mvebu_v7_cpuidle_probe,
c16788b4 128 .driver = {
da1a64f8 129 .name = "cpuidle-mbevu",
ab319939 130 .suppress_bind_attrs = true,
c16788b4 131 },
da1a64f8 132 .id_table = mvebu_cpuidle_ids,
c16788b4
TP
133};
134
ab319939 135builtin_platform_driver(mvebu_cpuidle_driver);
c16788b4 136
b858fbc1 137MODULE_AUTHOR("Gregory CLEMENT <gregory.clement@free-electrons.com>");
f50ee824 138MODULE_DESCRIPTION("Marvell EBU v7 cpuidle driver");
b858fbc1 139MODULE_LICENSE("GPL");