blob: d23597f25093740c706ff1eb43cf5980b1d23026 [file] [log] [blame]
Gregory CLEMENTf50ee822014-07-23 15:00:48 +02001/*
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
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,
56 .flags = CPUIDLE_FLAG_TIME_VALID,
57 .name = "MV CPU IDLE",
58 .desc = "CPU power down",
59 },
60 .states[2] = {
61 .enter = mvebu_v7_enter_idle,
62 .exit_latency = 100,
63 .power_usage = 5,
64 .target_residency = 1000,
65 .flags = CPUIDLE_FLAG_TIME_VALID |
66 MVEBU_V7_FLAG_DEEP_IDLE,
67 .name = "MV CPU DEEP IDLE",
68 .desc = "CPU and L2 Fabric power down",
69 },
70 .state_count = 3,
71};
72
Thomas Petazzonic3c7fe72014-07-23 15:00:49 +020073static 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
Gregory CLEMENTf50ee822014-07-23 15:00:48 +020089static int mvebu_v7_cpuidle_probe(struct platform_device *pdev)
90{
Gregory CLEMENTf50ee822014-07-23 15:00:48 +020091 mvebu_v7_cpu_suspend = pdev->dev.platform_data;
Thomas Petazzonic3c7fe72014-07-23 15:00:49 +020092
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;
Gregory CLEMENTf50ee822014-07-23 15:00:48 +020099}
100
101static struct platform_driver armadaxp_cpuidle_plat_driver = {
102 .driver = {
103 .name = "cpuidle-armada-xp",
104 .owner = THIS_MODULE,
105 },
106 .probe = mvebu_v7_cpuidle_probe,
107};
108
109module_platform_driver(armadaxp_cpuidle_plat_driver);
110
Thomas Petazzonic3c7fe72014-07-23 15:00:49 +0200111static 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
Gregory CLEMENTf50ee822014-07-23 15:00:48 +0200121MODULE_AUTHOR("Gregory CLEMENT <gregory.clement@free-electrons.com>");
122MODULE_DESCRIPTION("Marvell EBU v7 cpuidle driver");
123MODULE_LICENSE("GPL");