2 * CPUIdle support code for SH-Mobile ARM
4 * Copyright (C) 2011 Magnus Damm
6 * This file is subject to the terms and conditions of the GNU General Public
7 * License. See the file "COPYING" in the main directory of this archive
12 #include <linux/cpuidle.h>
13 #include <linux/suspend.h>
14 #include <linux/module.h>
15 #include <linux/err.h>
18 static void shmobile_enter_wfi(void)
23 void (*shmobile_cpuidle_modes[CPUIDLE_STATE_MAX])(void) = {
24 shmobile_enter_wfi, /* regular sleep mode */
27 static int shmobile_cpuidle_enter(struct cpuidle_device *dev,
28 struct cpuidle_driver *drv,
31 ktime_t before, after;
38 shmobile_cpuidle_modes[index]();
44 dev->last_residency = ktime_to_ns(ktime_sub(after, before)) >> 10;
49 static struct cpuidle_device shmobile_cpuidle_dev;
50 static struct cpuidle_driver shmobile_cpuidle_driver = {
51 .name = "shmobile_cpuidle",
57 .target_residency = 1 * 2,
58 .flags = CPUIDLE_FLAG_TIME_VALID,
60 .safe_state_index = 0, /* C1 */
64 void (*shmobile_cpuidle_setup)(struct cpuidle_driver *drv);
66 static int shmobile_cpuidle_init(void)
68 struct cpuidle_device *dev = &shmobile_cpuidle_dev;
69 struct cpuidle_driver *drv = &shmobile_cpuidle_driver;
72 for (i = 0; i < CPUIDLE_STATE_MAX; i++)
73 drv->states[i].enter = shmobile_cpuidle_enter;
75 if (shmobile_cpuidle_setup)
76 shmobile_cpuidle_setup(drv);
78 cpuidle_register_driver(drv);
80 dev->state_count = drv->state_count;
81 cpuidle_register_device(dev);
85 late_initcall(shmobile_cpuidle_init);