-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
ARM: imx: Add common imx cpuidle init functionality.
Add common cpuidle init functionality that can be used by various imx platforms. Signed-off-by: Robert Lee <rob.lee@linaro.org> Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
- Loading branch information
Robert Lee
authored and
Sascha Hauer
committed
Jun 5, 2012
1 parent
aa96a18
commit 2da50e6
Showing
3 changed files
with
103 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,80 @@ | ||
/* | ||
* Copyright 2012 Freescale Semiconductor, Inc. | ||
* Copyright 2012 Linaro Ltd. | ||
* | ||
* The code contained herein is licensed under the GNU General Public | ||
* License. You may obtain a copy of the GNU General Public License | ||
* Version 2 or later at the following locations: | ||
* | ||
* http://www.opensource.org/licenses/gpl-license.html | ||
* http://www.gnu.org/copyleft/gpl.html | ||
*/ | ||
|
||
#include <linux/cpuidle.h> | ||
#include <linux/err.h> | ||
#include <linux/hrtimer.h> | ||
#include <linux/io.h> | ||
#include <linux/kernel.h> | ||
#include <linux/slab.h> | ||
|
||
static struct cpuidle_device __percpu * imx_cpuidle_devices; | ||
|
||
static void __init imx_cpuidle_devices_uninit(void) | ||
{ | ||
int cpu_id; | ||
struct cpuidle_device *dev; | ||
|
||
for_each_possible_cpu(cpu_id) { | ||
dev = per_cpu_ptr(imx_cpuidle_devices, cpu_id); | ||
cpuidle_unregister_device(dev); | ||
} | ||
|
||
free_percpu(imx_cpuidle_devices); | ||
} | ||
|
||
int __init imx_cpuidle_init(struct cpuidle_driver *drv) | ||
{ | ||
struct cpuidle_device *dev; | ||
int cpu_id, ret; | ||
|
||
if (drv->state_count > CPUIDLE_STATE_MAX) { | ||
pr_err("%s: state_count exceeds maximum\n", __func__); | ||
return -EINVAL; | ||
} | ||
|
||
ret = cpuidle_register_driver(drv); | ||
if (ret) { | ||
pr_err("%s: Failed to register cpuidle driver with error: %d\n", | ||
__func__, ret); | ||
return ret; | ||
} | ||
|
||
imx_cpuidle_devices = alloc_percpu(struct cpuidle_device); | ||
if (imx_cpuidle_devices == NULL) { | ||
ret = -ENOMEM; | ||
goto unregister_drv; | ||
} | ||
|
||
/* initialize state data for each cpuidle_device */ | ||
for_each_possible_cpu(cpu_id) { | ||
dev = per_cpu_ptr(imx_cpuidle_devices, cpu_id); | ||
dev->cpu = cpu_id; | ||
dev->state_count = drv->state_count; | ||
|
||
ret = cpuidle_register_device(dev); | ||
if (ret) { | ||
pr_err("%s: Failed to register cpu %u, error: %d\n", | ||
__func__, cpu_id, ret); | ||
goto uninit; | ||
} | ||
} | ||
|
||
return 0; | ||
|
||
uninit: | ||
imx_cpuidle_devices_uninit(); | ||
|
||
unregister_drv: | ||
cpuidle_unregister_driver(drv); | ||
return ret; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
/* | ||
* Copyright 2012 Freescale Semiconductor, Inc. | ||
* Copyright 2012 Linaro Ltd. | ||
* | ||
* The code contained herein is licensed under the GNU General Public | ||
* License. You may obtain a copy of the GNU General Public License | ||
* Version 2 or later at the following locations: | ||
* | ||
* http://www.opensource.org/licenses/gpl-license.html | ||
* http://www.gnu.org/copyleft/gpl.html | ||
*/ | ||
|
||
#include <linux/cpuidle.h> | ||
|
||
#ifdef CONFIG_CPU_IDLE | ||
extern int imx_cpuidle_init(struct cpuidle_driver *drv); | ||
#else | ||
static inline int imx_cpuidle_init(struct cpuidle_driver *drv) | ||
{ | ||
return -ENODEV; | ||
} | ||
#endif |