diff options
author | Daniel Lezcano <daniel.lezcano@linaro.org> | 2013-04-23 04:54:45 -0400 |
---|---|---|
committer | Rafael J. Wysocki <rafael.j.wysocki@intel.com> | 2013-04-23 07:45:23 -0400 |
commit | 54a4644b7a31b017375018d8266a22d3eabfcf0e (patch) | |
tree | 0b7452cb2f8fa25abacfd16e42e30f6bfc8c2513 /arch/arm | |
parent | 3aec034590d98cb268b3a1f434a602b3d53b0ad2 (diff) |
ARM: imx: cpuidle: use init/exit common routine
The code intializes the cpuidle driver at different places.
The cpuidle driver for :
* imx5 : is in the pm-imx5.c, the init function is in cpuidle.c
* imx6 : is in cpuidle-imx6q.c, the init function is in cpuidle.c
and cpuidle-imx6q.c
Instead of having the cpuidle code spread across different files,
let's create a driver for each SoC and use the common register function.
Signed-off-by: Daniel Lezcano <daniel.lezcano@linaro.org>
Acked-by: Shawn Guo <shawn.guo@linaro.org>
Signed-off-by: Rafael J. Wysocki <rafael.j.wysocki@intel.com>
Diffstat (limited to 'arch/arm')
-rw-r--r-- | arch/arm/mach-imx/Makefile | 2 | ||||
-rw-r--r-- | arch/arm/mach-imx/cpuidle-imx5.c | 37 | ||||
-rw-r--r-- | arch/arm/mach-imx/cpuidle-imx6q.c | 2 | ||||
-rw-r--r-- | arch/arm/mach-imx/cpuidle.c | 80 | ||||
-rw-r--r-- | arch/arm/mach-imx/cpuidle.h | 10 | ||||
-rw-r--r-- | arch/arm/mach-imx/pm-imx5.c | 29 |
6 files changed, 44 insertions, 116 deletions
diff --git a/arch/arm/mach-imx/Makefile b/arch/arm/mach-imx/Makefile index c4ce0906d76a..cb70961b6239 100644 --- a/arch/arm/mach-imx/Makefile +++ b/arch/arm/mach-imx/Makefile | |||
@@ -30,7 +30,7 @@ obj-$(CONFIG_MXC_DEBUG_BOARD) += 3ds_debugboard.o | |||
30 | obj-$(CONFIG_CPU_FREQ_IMX) += cpufreq.o | 30 | obj-$(CONFIG_CPU_FREQ_IMX) += cpufreq.o |
31 | 31 | ||
32 | ifeq ($(CONFIG_CPU_IDLE),y) | 32 | ifeq ($(CONFIG_CPU_IDLE),y) |
33 | obj-y += cpuidle.o | 33 | obj-$(CONFIG_SOC_IMX5) += cpuidle-imx5.o |
34 | obj-$(CONFIG_SOC_IMX6Q) += cpuidle-imx6q.o | 34 | obj-$(CONFIG_SOC_IMX6Q) += cpuidle-imx6q.o |
35 | endif | 35 | endif |
36 | 36 | ||
diff --git a/arch/arm/mach-imx/cpuidle-imx5.c b/arch/arm/mach-imx/cpuidle-imx5.c new file mode 100644 index 000000000000..5a47e3c6172f --- /dev/null +++ b/arch/arm/mach-imx/cpuidle-imx5.c | |||
@@ -0,0 +1,37 @@ | |||
1 | /* | ||
2 | * Copyright (C) 2012 Freescale Semiconductor, Inc. | ||
3 | * | ||
4 | * This program is free software; you can redistribute it and/or modify | ||
5 | * it under the terms of the GNU General Public License version 2 as | ||
6 | * published by the Free Software Foundation. | ||
7 | */ | ||
8 | |||
9 | #include <linux/cpuidle.h> | ||
10 | #include <linux/module.h> | ||
11 | #include <asm/system_misc.h> | ||
12 | |||
13 | static int imx5_cpuidle_enter(struct cpuidle_device *dev, | ||
14 | struct cpuidle_driver *drv, int index) | ||
15 | { | ||
16 | arm_pm_idle(); | ||
17 | return index; | ||
18 | } | ||
19 | |||
20 | static struct cpuidle_driver imx5_cpuidle_driver = { | ||
21 | .name = "imx5_cpuidle", | ||
22 | .owner = THIS_MODULE, | ||
23 | .states[0] = { | ||
24 | .enter = imx5_cpuidle_enter, | ||
25 | .exit_latency = 2, | ||
26 | .target_residency = 1, | ||
27 | .flags = CPUIDLE_FLAG_TIME_VALID, | ||
28 | .name = "IMX5 SRPG", | ||
29 | .desc = "CPU state retained,powered off", | ||
30 | }, | ||
31 | .state_count = 1, | ||
32 | }; | ||
33 | |||
34 | int __init imx5_cpuidle_init(void) | ||
35 | { | ||
36 | return cpuidle_register(&imx5_cpuidle_driver, NULL); | ||
37 | } | ||
diff --git a/arch/arm/mach-imx/cpuidle-imx6q.c b/arch/arm/mach-imx/cpuidle-imx6q.c index e2739adf093a..23ddfb693b2d 100644 --- a/arch/arm/mach-imx/cpuidle-imx6q.c +++ b/arch/arm/mach-imx/cpuidle-imx6q.c | |||
@@ -71,5 +71,5 @@ int __init imx6q_cpuidle_init(void) | |||
71 | /* Set chicken bit to get a reliable WAIT mode support */ | 71 | /* Set chicken bit to get a reliable WAIT mode support */ |
72 | imx6q_set_chicken_bit(); | 72 | imx6q_set_chicken_bit(); |
73 | 73 | ||
74 | return imx_cpuidle_init(&imx6q_cpuidle_driver); | 74 | return cpuidle_register(&imx6q_cpuidle_driver, NULL); |
75 | } | 75 | } |
diff --git a/arch/arm/mach-imx/cpuidle.c b/arch/arm/mach-imx/cpuidle.c deleted file mode 100644 index d4cb511a44a8..000000000000 --- a/arch/arm/mach-imx/cpuidle.c +++ /dev/null | |||
@@ -1,80 +0,0 @@ | |||
1 | /* | ||
2 | * Copyright 2012 Freescale Semiconductor, Inc. | ||
3 | * Copyright 2012 Linaro Ltd. | ||
4 | * | ||
5 | * The code contained herein is licensed under the GNU General Public | ||
6 | * License. You may obtain a copy of the GNU General Public License | ||
7 | * Version 2 or later at the following locations: | ||
8 | * | ||
9 | * http://www.opensource.org/licenses/gpl-license.html | ||
10 | * http://www.gnu.org/copyleft/gpl.html | ||
11 | */ | ||
12 | |||
13 | #include <linux/cpuidle.h> | ||
14 | #include <linux/err.h> | ||
15 | #include <linux/hrtimer.h> | ||
16 | #include <linux/io.h> | ||
17 | #include <linux/kernel.h> | ||
18 | #include <linux/slab.h> | ||
19 | |||
20 | static struct cpuidle_device __percpu * imx_cpuidle_devices; | ||
21 | |||
22 | static void __init imx_cpuidle_devices_uninit(void) | ||
23 | { | ||
24 | int cpu_id; | ||
25 | struct cpuidle_device *dev; | ||
26 | |||
27 | for_each_possible_cpu(cpu_id) { | ||
28 | dev = per_cpu_ptr(imx_cpuidle_devices, cpu_id); | ||
29 | cpuidle_unregister_device(dev); | ||
30 | } | ||
31 | |||
32 | free_percpu(imx_cpuidle_devices); | ||
33 | } | ||
34 | |||
35 | int __init imx_cpuidle_init(struct cpuidle_driver *drv) | ||
36 | { | ||
37 | struct cpuidle_device *dev; | ||
38 | int cpu_id, ret; | ||
39 | |||
40 | if (drv->state_count > CPUIDLE_STATE_MAX) { | ||
41 | pr_err("%s: state_count exceeds maximum\n", __func__); | ||
42 | return -EINVAL; | ||
43 | } | ||
44 | |||
45 | ret = cpuidle_register_driver(drv); | ||
46 | if (ret) { | ||
47 | pr_err("%s: Failed to register cpuidle driver with error: %d\n", | ||
48 | __func__, ret); | ||
49 | return ret; | ||
50 | } | ||
51 | |||
52 | imx_cpuidle_devices = alloc_percpu(struct cpuidle_device); | ||
53 | if (imx_cpuidle_devices == NULL) { | ||
54 | ret = -ENOMEM; | ||
55 | goto unregister_drv; | ||
56 | } | ||
57 | |||
58 | /* initialize state data for each cpuidle_device */ | ||
59 | for_each_possible_cpu(cpu_id) { | ||
60 | dev = per_cpu_ptr(imx_cpuidle_devices, cpu_id); | ||
61 | dev->cpu = cpu_id; | ||
62 | dev->state_count = drv->state_count; | ||
63 | |||
64 | ret = cpuidle_register_device(dev); | ||
65 | if (ret) { | ||
66 | pr_err("%s: Failed to register cpu %u, error: %d\n", | ||
67 | __func__, cpu_id, ret); | ||
68 | goto uninit; | ||
69 | } | ||
70 | } | ||
71 | |||
72 | return 0; | ||
73 | |||
74 | uninit: | ||
75 | imx_cpuidle_devices_uninit(); | ||
76 | |||
77 | unregister_drv: | ||
78 | cpuidle_unregister_driver(drv); | ||
79 | return ret; | ||
80 | } | ||
diff --git a/arch/arm/mach-imx/cpuidle.h b/arch/arm/mach-imx/cpuidle.h index e092d1359d94..786f98ecc145 100644 --- a/arch/arm/mach-imx/cpuidle.h +++ b/arch/arm/mach-imx/cpuidle.h | |||
@@ -10,18 +10,16 @@ | |||
10 | * http://www.gnu.org/copyleft/gpl.html | 10 | * http://www.gnu.org/copyleft/gpl.html |
11 | */ | 11 | */ |
12 | 12 | ||
13 | #include <linux/cpuidle.h> | ||
14 | |||
15 | #ifdef CONFIG_CPU_IDLE | 13 | #ifdef CONFIG_CPU_IDLE |
16 | extern int imx_cpuidle_init(struct cpuidle_driver *drv); | 14 | extern int imx5_cpuidle_init(void); |
17 | extern int imx6q_cpuidle_init(void); | 15 | extern int imx6q_cpuidle_init(void); |
18 | #else | 16 | #else |
19 | static inline int imx_cpuidle_init(struct cpuidle_driver *drv) | 17 | static inline int imx5_cpuidle_init(void) |
20 | { | 18 | { |
21 | return -ENODEV; | 19 | return 0; |
22 | } | 20 | } |
23 | static inline int imx6q_cpuidle_init(void) | 21 | static inline int imx6q_cpuidle_init(void) |
24 | { | 22 | { |
25 | return -ENODEV; | 23 | return 0; |
26 | } | 24 | } |
27 | #endif | 25 | #endif |
diff --git a/arch/arm/mach-imx/pm-imx5.c b/arch/arm/mach-imx/pm-imx5.c index 4b52b3e028ab..82e79c658eb2 100644 --- a/arch/arm/mach-imx/pm-imx5.c +++ b/arch/arm/mach-imx/pm-imx5.c | |||
@@ -149,32 +149,6 @@ static void imx5_pm_idle(void) | |||
149 | imx5_cpu_do_idle(); | 149 | imx5_cpu_do_idle(); |
150 | } | 150 | } |
151 | 151 | ||
152 | static int imx5_cpuidle_enter(struct cpuidle_device *dev, | ||
153 | struct cpuidle_driver *drv, int idx) | ||
154 | { | ||
155 | int ret; | ||
156 | |||
157 | ret = imx5_cpu_do_idle(); | ||
158 | if (ret < 0) | ||
159 | return ret; | ||
160 | |||
161 | return idx; | ||
162 | } | ||
163 | |||
164 | static struct cpuidle_driver imx5_cpuidle_driver = { | ||
165 | .name = "imx5_cpuidle", | ||
166 | .owner = THIS_MODULE, | ||
167 | .states[0] = { | ||
168 | .enter = imx5_cpuidle_enter, | ||
169 | .exit_latency = 2, | ||
170 | .target_residency = 1, | ||
171 | .flags = CPUIDLE_FLAG_TIME_VALID, | ||
172 | .name = "IMX5 SRPG", | ||
173 | .desc = "CPU state retained,powered off", | ||
174 | }, | ||
175 | .state_count = 1, | ||
176 | }; | ||
177 | |||
178 | static int __init imx5_pm_common_init(void) | 152 | static int __init imx5_pm_common_init(void) |
179 | { | 153 | { |
180 | int ret; | 154 | int ret; |
@@ -192,8 +166,7 @@ static int __init imx5_pm_common_init(void) | |||
192 | /* Set the registers to the default cpu idle state. */ | 166 | /* Set the registers to the default cpu idle state. */ |
193 | mx5_cpu_lp_set(IMX5_DEFAULT_CPU_IDLE_STATE); | 167 | mx5_cpu_lp_set(IMX5_DEFAULT_CPU_IDLE_STATE); |
194 | 168 | ||
195 | imx_cpuidle_init(&imx5_cpuidle_driver); | 169 | return imx5_cpuidle_init(); |
196 | return 0; | ||
197 | } | 170 | } |
198 | 171 | ||
199 | void __init imx51_pm_init(void) | 172 | void __init imx51_pm_init(void) |