Gregory CLEMENT | f50ee82 | 2014-07-23 15:00:48 +0200 | [diff] [blame] | 1 | /* |
Thomas Petazzoni | c16788b | 2014-07-23 15:00:50 +0200 | [diff] [blame] | 2 | * Marvell Armada 370, 38x and XP SoC cpuidle driver |
Gregory CLEMENT | f50ee82 | 2014-07-23 15:00:48 +0200 | [diff] [blame] | 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 | |
| 26 | static int (*mvebu_v7_cpu_suspend)(int); |
| 27 | |
| 28 | static 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); |
Gregory CLEMENT | 43b6887 | 2015-02-26 18:20:48 +0100 | [diff] [blame] | 40 | cpu_pm_exit(); |
| 41 | |
Gregory CLEMENT | f50ee82 | 2014-07-23 15:00:48 +0200 | [diff] [blame] | 42 | if (ret) |
| 43 | return ret; |
| 44 | |
Gregory CLEMENT | f50ee82 | 2014-07-23 15:00:48 +0200 | [diff] [blame] | 45 | return index; |
| 46 | } |
| 47 | |
| 48 | static 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, |
Sebastien Rannou | ce6031c | 2015-02-13 15:55:03 +0100 | [diff] [blame] | 53 | .exit_latency = 100, |
Gregory CLEMENT | f50ee82 | 2014-07-23 15:00:48 +0200 | [diff] [blame] | 54 | .power_usage = 50, |
Sebastien Rannou | ce6031c | 2015-02-13 15:55:03 +0100 | [diff] [blame] | 55 | .target_residency = 1000, |
Gregory CLEMENT | f50ee82 | 2014-07-23 15:00:48 +0200 | [diff] [blame] | 56 | .name = "MV CPU IDLE", |
| 57 | .desc = "CPU power down", |
| 58 | }, |
| 59 | .states[2] = { |
| 60 | .enter = mvebu_v7_enter_idle, |
Sebastien Rannou | ce6031c | 2015-02-13 15:55:03 +0100 | [diff] [blame] | 61 | .exit_latency = 1000, |
Gregory CLEMENT | f50ee82 | 2014-07-23 15:00:48 +0200 | [diff] [blame] | 62 | .power_usage = 5, |
Sebastien Rannou | ce6031c | 2015-02-13 15:55:03 +0100 | [diff] [blame] | 63 | .target_residency = 10000, |
Daniel Lezcano | b82b6cc | 2014-11-12 16:03:50 +0100 | [diff] [blame] | 64 | .flags = MVEBU_V7_FLAG_DEEP_IDLE, |
Gregory CLEMENT | f50ee82 | 2014-07-23 15:00:48 +0200 | [diff] [blame] | 65 | .name = "MV CPU DEEP IDLE", |
| 66 | .desc = "CPU and L2 Fabric power down", |
| 67 | }, |
| 68 | .state_count = 3, |
| 69 | }; |
| 70 | |
Thomas Petazzoni | c3c7fe7 | 2014-07-23 15:00:49 +0200 | [diff] [blame] | 71 | static 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 Lezcano | b82b6cc | 2014-11-12 16:03:50 +0100 | [diff] [blame] | 79 | .flags = MVEBU_V7_FLAG_DEEP_IDLE, |
Thomas Petazzoni | c3c7fe7 | 2014-07-23 15:00:49 +0200 | [diff] [blame] | 80 | .name = "Deep Idle", |
| 81 | .desc = "CPU and L2 Fabric power down", |
| 82 | }, |
| 83 | .state_count = 2, |
| 84 | }; |
| 85 | |
Thomas Petazzoni | c16788b | 2014-07-23 15:00:50 +0200 | [diff] [blame] | 86 | static 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 Petazzoni | c16788b | 2014-07-23 15:00:50 +0200 | [diff] [blame] | 94 | .name = "Idle", |
| 95 | .desc = "CPU and SCU power down", |
| 96 | }, |
| 97 | .state_count = 2, |
| 98 | }; |
| 99 | |
Gregory CLEMENT | f50ee82 | 2014-07-23 15:00:48 +0200 | [diff] [blame] | 100 | static int mvebu_v7_cpuidle_probe(struct platform_device *pdev) |
| 101 | { |
Russell King | da1a64f | 2015-10-03 00:24:25 +0100 | [diff] [blame^] | 102 | const struct platform_device_id *id = pdev->id_entry; |
| 103 | |
| 104 | if (!id) |
| 105 | return -EINVAL; |
| 106 | |
Gregory CLEMENT | f50ee82 | 2014-07-23 15:00:48 +0200 | [diff] [blame] | 107 | mvebu_v7_cpu_suspend = pdev->dev.platform_data; |
Thomas Petazzoni | c3c7fe7 | 2014-07-23 15:00:49 +0200 | [diff] [blame] | 108 | |
Russell King | da1a64f | 2015-10-03 00:24:25 +0100 | [diff] [blame^] | 109 | return cpuidle_register((struct cpuidle_driver *)id->driver_data, NULL); |
Gregory CLEMENT | f50ee82 | 2014-07-23 15:00:48 +0200 | [diff] [blame] | 110 | } |
| 111 | |
Russell King | da1a64f | 2015-10-03 00:24:25 +0100 | [diff] [blame^] | 112 | static const struct platform_device_id mvebu_cpuidle_ids[] = { |
| 113 | { |
Gregory CLEMENT | f50ee82 | 2014-07-23 15:00:48 +0200 | [diff] [blame] | 114 | .name = "cpuidle-armada-xp", |
Russell King | da1a64f | 2015-10-03 00:24:25 +0100 | [diff] [blame^] | 115 | .driver_data = (unsigned long)&armadaxp_idle_driver, |
| 116 | }, { |
Thomas Petazzoni | c3c7fe7 | 2014-07-23 15:00:49 +0200 | [diff] [blame] | 117 | .name = "cpuidle-armada-370", |
Russell King | da1a64f | 2015-10-03 00:24:25 +0100 | [diff] [blame^] | 118 | .driver_data = (unsigned long)&armada370_idle_driver, |
| 119 | }, { |
Thomas Petazzoni | c16788b | 2014-07-23 15:00:50 +0200 | [diff] [blame] | 120 | .name = "cpuidle-armada-38x", |
Russell King | da1a64f | 2015-10-03 00:24:25 +0100 | [diff] [blame^] | 121 | .driver_data = (unsigned long)&armada38x_idle_driver, |
Thomas Petazzoni | c16788b | 2014-07-23 15:00:50 +0200 | [diff] [blame] | 122 | }, |
Russell King | da1a64f | 2015-10-03 00:24:25 +0100 | [diff] [blame^] | 123 | {} |
Thomas Petazzoni | c16788b | 2014-07-23 15:00:50 +0200 | [diff] [blame] | 124 | }; |
| 125 | |
Russell King | da1a64f | 2015-10-03 00:24:25 +0100 | [diff] [blame^] | 126 | static struct platform_driver mvebu_cpuidle_driver = { |
| 127 | .probe = mvebu_v7_cpuidle_probe, |
| 128 | .driver = { |
| 129 | .name = "cpuidle-mbevu", |
| 130 | }, |
| 131 | .id_table = mvebu_cpuidle_ids, |
| 132 | }; |
| 133 | |
| 134 | module_platform_driver(mvebu_cpuidle_driver); |
Thomas Petazzoni | c16788b | 2014-07-23 15:00:50 +0200 | [diff] [blame] | 135 | |
Gregory CLEMENT | f50ee82 | 2014-07-23 15:00:48 +0200 | [diff] [blame] | 136 | MODULE_AUTHOR("Gregory CLEMENT <gregory.clement@free-electrons.com>"); |
| 137 | MODULE_DESCRIPTION("Marvell EBU v7 cpuidle driver"); |
| 138 | MODULE_LICENSE("GPL"); |