Merge branch 'tboot' into release
[linux-flexiantxendom0-3.2.10.git] / arch / arm / mach-shmobile / cpuidle.c
1 /*
2  * CPUIdle support code for SH-Mobile ARM
3  *
4  *  Copyright (C) 2011 Magnus Damm
5  *
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
8  * for more details.
9  */
10
11 #include <linux/pm.h>
12 #include <linux/cpuidle.h>
13 #include <linux/suspend.h>
14 #include <linux/module.h>
15 #include <linux/err.h>
16 #include <asm/system.h>
17 #include <asm/cpuidle.h>
18 #include <asm/io.h>
19
20 static void shmobile_enter_wfi(void)
21 {
22         cpu_do_idle();
23 }
24
25 void (*shmobile_cpuidle_modes[CPUIDLE_STATE_MAX])(void) = {
26         shmobile_enter_wfi, /* regular sleep mode */
27 };
28
29 static int shmobile_cpuidle_enter(struct cpuidle_device *dev,
30                                   struct cpuidle_driver *drv,
31                                   int index)
32 {
33         shmobile_cpuidle_modes[index]();
34
35         return index;
36 }
37
38 static struct cpuidle_device shmobile_cpuidle_dev;
39 static struct cpuidle_driver shmobile_cpuidle_driver = {
40         .name                   = "shmobile_cpuidle",
41         .owner                  = THIS_MODULE,
42         .en_core_tk_irqen       = 1,
43         .states[0]              = ARM_CPUIDLE_WFI_STATE,
44         .safe_state_index       = 0, /* C1 */
45         .state_count            = 1,
46 };
47
48 void (*shmobile_cpuidle_setup)(struct cpuidle_driver *drv);
49
50 static int shmobile_cpuidle_init(void)
51 {
52         struct cpuidle_device *dev = &shmobile_cpuidle_dev;
53         struct cpuidle_driver *drv = &shmobile_cpuidle_driver;
54         int i;
55
56         for (i = 0; i < CPUIDLE_STATE_MAX; i++)
57                 drv->states[i].enter = shmobile_cpuidle_enter;
58
59         if (shmobile_cpuidle_setup)
60                 shmobile_cpuidle_setup(drv);
61
62         cpuidle_register_driver(drv);
63
64         dev->state_count = drv->state_count;
65         cpuidle_register_device(dev);
66
67         return 0;
68 }
69 late_initcall(shmobile_cpuidle_init);