1 /* 2 * Marvell Armada 370, 38x and 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 26 static int (*mvebu_v7_cpu_suspend)(int); 27 28 static __cpuidle 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 ct_cpuidle_enter(); 40 ret = mvebu_v7_cpu_suspend(deepidle); 41 ct_cpuidle_exit(); 42 43 cpu_pm_exit(); 44 45 if (ret) 46 return ret; 47 48 return index; 49 } 50 51 static struct cpuidle_driver armadaxp_idle_driver = { 52 .name = "armada_xp_idle", 53 .states[0] = ARM_CPUIDLE_WFI_STATE, 54 .states[1] = { 55 .flags = CPUIDLE_FLAG_RCU_IDLE, 56 .enter = mvebu_v7_enter_idle, 57 .exit_latency = 100, 58 .power_usage = 50, 59 .target_residency = 1000, 60 .name = "MV CPU IDLE", 61 .desc = "CPU power down", 62 }, 63 .states[2] = { 64 .flags = CPUIDLE_FLAG_RCU_IDLE, 65 .enter = mvebu_v7_enter_idle, 66 .exit_latency = 1000, 67 .power_usage = 5, 68 .target_residency = 10000, 69 .flags = MVEBU_V7_FLAG_DEEP_IDLE, 70 .name = "MV CPU DEEP IDLE", 71 .desc = "CPU and L2 Fabric power down", 72 }, 73 .state_count = 3, 74 }; 75 76 static struct cpuidle_driver armada370_idle_driver = { 77 .name = "armada_370_idle", 78 .states[0] = ARM_CPUIDLE_WFI_STATE, 79 .states[1] = { 80 .flags = CPUIDLE_FLAG_RCU_IDLE, 81 .enter = mvebu_v7_enter_idle, 82 .exit_latency = 100, 83 .power_usage = 5, 84 .target_residency = 1000, 85 .flags = MVEBU_V7_FLAG_DEEP_IDLE, 86 .name = "Deep Idle", 87 .desc = "CPU and L2 Fabric power down", 88 }, 89 .state_count = 2, 90 }; 91 92 static struct cpuidle_driver armada38x_idle_driver = { 93 .name = "armada_38x_idle", 94 .states[0] = ARM_CPUIDLE_WFI_STATE, 95 .states[1] = { 96 .flags = CPUIDLE_FLAG_RCU_IDLE, 97 .enter = mvebu_v7_enter_idle, 98 .exit_latency = 10, 99 .power_usage = 5, 100 .target_residency = 100, 101 .name = "Idle", 102 .desc = "CPU and SCU power down", 103 }, 104 .state_count = 2, 105 }; 106 107 static int mvebu_v7_cpuidle_probe(struct platform_device *pdev) 108 { 109 const struct platform_device_id *id = pdev->id_entry; 110 111 if (!id) 112 return -EINVAL; 113 114 mvebu_v7_cpu_suspend = pdev->dev.platform_data; 115 116 return cpuidle_register((struct cpuidle_driver *)id->driver_data, NULL); 117 } 118 119 static const struct platform_device_id mvebu_cpuidle_ids[] = { 120 { 121 .name = "cpuidle-armada-xp", 122 .driver_data = (unsigned long)&armadaxp_idle_driver, 123 }, { 124 .name = "cpuidle-armada-370", 125 .driver_data = (unsigned long)&armada370_idle_driver, 126 }, { 127 .name = "cpuidle-armada-38x", 128 .driver_data = (unsigned long)&armada38x_idle_driver, 129 }, 130 {} 131 }; 132 133 static struct platform_driver mvebu_cpuidle_driver = { 134 .probe = mvebu_v7_cpuidle_probe, 135 .driver = { 136 .name = "cpuidle-mbevu", 137 .suppress_bind_attrs = true, 138 }, 139 .id_table = mvebu_cpuidle_ids, 140 }; 141 142 builtin_platform_driver(mvebu_cpuidle_driver); 143 144 MODULE_AUTHOR("Gregory CLEMENT <gregory.clement@free-electrons.com>"); 145 MODULE_DESCRIPTION("Marvell EBU v7 cpuidle driver"); 146 MODULE_LICENSE("GPL"); 147