2 * Copyright 2012 Freescale Semiconductor, Inc.
3 * Copyright 2012 Linaro Ltd.
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:
9 * http://www.opensource.org/licenses/gpl-license.html
10 * http://www.gnu.org/copyleft/gpl.html
13 #include <linux/cpuidle.h>
14 #include <linux/err.h>
15 #include <linux/hrtimer.h>
17 #include <linux/kernel.h>
18 #include <linux/slab.h>
20 static struct cpuidle_device __percpu
* imx_cpuidle_devices
;
22 static void __init
imx_cpuidle_devices_uninit(void)
25 struct cpuidle_device
*dev
;
27 for_each_possible_cpu(cpu_id
) {
28 dev
= per_cpu_ptr(imx_cpuidle_devices
, cpu_id
);
29 cpuidle_unregister_device(dev
);
32 free_percpu(imx_cpuidle_devices
);
35 int __init
imx_cpuidle_init(struct cpuidle_driver
*drv
)
37 struct cpuidle_device
*dev
;
40 if (drv
->state_count
> CPUIDLE_STATE_MAX
) {
41 pr_err("%s: state_count exceeds maximum\n", __func__
);
45 ret
= cpuidle_register_driver(drv
);
47 pr_err("%s: Failed to register cpuidle driver with error: %d\n",
52 imx_cpuidle_devices
= alloc_percpu(struct cpuidle_device
);
53 if (imx_cpuidle_devices
== NULL
) {
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
);
62 dev
->state_count
= drv
->state_count
;
64 ret
= cpuidle_register_device(dev
);
66 pr_err("%s: Failed to register cpu %u, error: %d\n",
67 __func__
, cpu_id
, ret
);
75 imx_cpuidle_devices_uninit();
78 cpuidle_unregister_driver(drv
);