xref: /linux/drivers/cpuidle/cpuidle-exynos.c (revision 92a578b064d0227a3a7fbbdb9e29dbab7f8d400e)
1 /* linux/arch/arm/mach-exynos/cpuidle.c
2  *
3  * Copyright (c) 2011 Samsung Electronics Co., Ltd.
4  *		http://www.samsung.com
5  *
6  * This program is free software; you can redistribute it and/or modify
7  * it under the terms of the GNU General Public License version 2 as
8  * published by the Free Software Foundation.
9 */
10 
11 #include <linux/cpuidle.h>
12 #include <linux/cpu_pm.h>
13 #include <linux/export.h>
14 #include <linux/module.h>
15 #include <linux/platform_device.h>
16 
17 #include <asm/proc-fns.h>
18 #include <asm/suspend.h>
19 #include <asm/cpuidle.h>
20 
21 static void (*exynos_enter_aftr)(void);
22 
23 static int exynos_enter_lowpower(struct cpuidle_device *dev,
24 				struct cpuidle_driver *drv,
25 				int index)
26 {
27 	int new_index = index;
28 
29 	/* AFTR can only be entered when cores other than CPU0 are offline */
30 	if (num_online_cpus() > 1 || dev->cpu != 0)
31 		new_index = drv->safe_state_index;
32 
33 	if (new_index == 0)
34 		return arm_cpuidle_simple_enter(dev, drv, new_index);
35 
36 	exynos_enter_aftr();
37 
38 	return new_index;
39 }
40 
41 static struct cpuidle_driver exynos_idle_driver = {
42 	.name			= "exynos_idle",
43 	.owner			= THIS_MODULE,
44 	.states = {
45 		[0] = ARM_CPUIDLE_WFI_STATE,
46 		[1] = {
47 			.enter			= exynos_enter_lowpower,
48 			.exit_latency		= 300,
49 			.target_residency	= 100000,
50 			.name			= "C1",
51 			.desc			= "ARM power down",
52 		},
53 	},
54 	.state_count = 2,
55 	.safe_state_index = 0,
56 };
57 
58 static int exynos_cpuidle_probe(struct platform_device *pdev)
59 {
60 	int ret;
61 
62 	exynos_enter_aftr = (void *)(pdev->dev.platform_data);
63 
64 	ret = cpuidle_register(&exynos_idle_driver, NULL);
65 	if (ret) {
66 		dev_err(&pdev->dev, "failed to register cpuidle driver\n");
67 		return ret;
68 	}
69 
70 	return 0;
71 }
72 
73 static struct platform_driver exynos_cpuidle_driver = {
74 	.probe	= exynos_cpuidle_probe,
75 	.driver = {
76 		.name = "exynos_cpuidle",
77 		.owner = THIS_MODULE,
78 	},
79 };
80 
81 module_platform_driver(exynos_cpuidle_driver);
82