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 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 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, 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 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 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 104 static int mvebu_v7_cpuidle_probe(struct platform_device *pdev) 105 { 106 mvebu_v7_cpu_suspend = pdev->dev.platform_data; 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); 112 else if (!strcmp(pdev->dev.driver->name, "cpuidle-armada-38x")) 113 return cpuidle_register(&armada38x_idle_driver, NULL); 114 else 115 return -EINVAL; 116 } 117 118 static struct platform_driver armadaxp_cpuidle_plat_driver = { 119 .driver = { 120 .name = "cpuidle-armada-xp", 121 .owner = THIS_MODULE, 122 }, 123 .probe = mvebu_v7_cpuidle_probe, 124 }; 125 126 module_platform_driver(armadaxp_cpuidle_plat_driver); 127 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 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 148 MODULE_AUTHOR("Gregory CLEMENT <gregory.clement@free-electrons.com>"); 149 MODULE_DESCRIPTION("Marvell EBU v7 cpuidle driver"); 150 MODULE_LICENSE("GPL"); 151