Commit | Line | Data |
---|---|---|
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 | 26 | static int (*mvebu_v7_cpu_suspend)(int); |
b858fbc1 | 27 | |
f50ee824 | 28 | static 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 |
48 | static 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 |
73 | static 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 | ||
c16788b4 TP |
89 | static struct cpuidle_driver armada38x_idle_driver = { |
90 | .name = "armada_38x_idle", | |
91 | .states[0] = ARM_CPUIDLE_WFI_STATE, | |
92 | .states[1] = { | |
93 | .enter = mvebu_v7_enter_idle, | |
94 | .exit_latency = 10, | |
95 | .power_usage = 5, | |
96 | .target_residency = 100, | |
97 | .flags = CPUIDLE_FLAG_TIME_VALID, | |
98 | .name = "Idle", | |
99 | .desc = "CPU and SCU power down", | |
100 | }, | |
101 | .state_count = 2, | |
102 | }; | |
103 | ||
f50ee824 | 104 | static int mvebu_v7_cpuidle_probe(struct platform_device *pdev) |
b858fbc1 | 105 | { |
f50ee824 | 106 | mvebu_v7_cpu_suspend = pdev->dev.platform_data; |
c3c7fe7c TP |
107 | |
108 | if (!strcmp(pdev->dev.driver->name, "cpuidle-armada-xp")) | |
109 | return cpuidle_register(&armadaxp_idle_driver, NULL); | |
110 | else if (!strcmp(pdev->dev.driver->name, "cpuidle-armada-370")) | |
111 | return cpuidle_register(&armada370_idle_driver, NULL); | |
c16788b4 TP |
112 | else if (!strcmp(pdev->dev.driver->name, "cpuidle-armada-38x")) |
113 | return cpuidle_register(&armada38x_idle_driver, NULL); | |
c3c7fe7c TP |
114 | else |
115 | return -EINVAL; | |
b858fbc1 GC |
116 | } |
117 | ||
f50ee824 | 118 | static struct platform_driver armadaxp_cpuidle_plat_driver = { |
b858fbc1 | 119 | .driver = { |
f50ee824 | 120 | .name = "cpuidle-armada-xp", |
b858fbc1 GC |
121 | .owner = THIS_MODULE, |
122 | }, | |
f50ee824 | 123 | .probe = mvebu_v7_cpuidle_probe, |
b858fbc1 GC |
124 | }; |
125 | ||
f50ee824 | 126 | module_platform_driver(armadaxp_cpuidle_plat_driver); |
b858fbc1 | 127 | |
c3c7fe7c TP |
128 | static struct platform_driver armada370_cpuidle_plat_driver = { |
129 | .driver = { | |
130 | .name = "cpuidle-armada-370", | |
131 | .owner = THIS_MODULE, | |
132 | }, | |
133 | .probe = mvebu_v7_cpuidle_probe, | |
134 | }; | |
135 | ||
136 | module_platform_driver(armada370_cpuidle_plat_driver); | |
137 | ||
c16788b4 TP |
138 | static struct platform_driver armada38x_cpuidle_plat_driver = { |
139 | .driver = { | |
140 | .name = "cpuidle-armada-38x", | |
141 | .owner = THIS_MODULE, | |
142 | }, | |
143 | .probe = mvebu_v7_cpuidle_probe, | |
144 | }; | |
145 | ||
146 | module_platform_driver(armada38x_cpuidle_plat_driver); | |
147 | ||
b858fbc1 | 148 | MODULE_AUTHOR("Gregory CLEMENT <gregory.clement@free-electrons.com>"); |
f50ee824 | 149 | MODULE_DESCRIPTION("Marvell EBU v7 cpuidle driver"); |
b858fbc1 | 150 | MODULE_LICENSE("GPL"); |