OSDN Git Service

SH: cpuidle: initialize the driver's states directly
[uclinux-h8/linux.git] / arch / sh / kernel / cpu / shmobile / cpuidle.c
1 /*
2  * arch/sh/kernel/cpu/shmobile/cpuidle.c
3  *
4  * Cpuidle support code for SuperH Mobile
5  *
6  *  Copyright (C) 2009 Magnus Damm
7  *
8  * This file is subject to the terms and conditions of the GNU General Public
9  * License.  See the file "COPYING" in the main directory of this archive
10  * for more details.
11  */
12 #include <linux/init.h>
13 #include <linux/kernel.h>
14 #include <linux/io.h>
15 #include <linux/suspend.h>
16 #include <linux/cpuidle.h>
17 #include <linux/export.h>
18 #include <asm/suspend.h>
19 #include <asm/uaccess.h>
20
21 static unsigned long cpuidle_mode[] = {
22         SUSP_SH_SLEEP, /* regular sleep mode */
23         SUSP_SH_SLEEP | SUSP_SH_SF, /* sleep mode + self refresh */
24         SUSP_SH_STANDBY | SUSP_SH_SF, /* software standby mode + self refresh */
25 };
26
27 static int cpuidle_sleep_enter(struct cpuidle_device *dev,
28                                 struct cpuidle_driver *drv,
29                                 int index)
30 {
31         unsigned long allowed_mode = SUSP_SH_SLEEP;
32         int requested_state = index;
33         int allowed_state;
34         int k;
35
36         /* convert allowed mode to allowed state */
37         for (k = ARRAY_SIZE(cpuidle_mode) - 1; k > 0; k--)
38                 if (cpuidle_mode[k] == allowed_mode)
39                         break;
40
41         allowed_state = k;
42
43         /* take the following into account for sleep mode selection:
44          * - allowed_state: best mode allowed by hardware (clock deps)
45          * - requested_state: best mode allowed by software (latencies)
46          */
47         k = min_t(int, allowed_state, requested_state);
48
49         sh_mobile_call_standby(cpuidle_mode[k]);
50
51         return k;
52 }
53
54 static struct cpuidle_device cpuidle_dev;
55 static struct cpuidle_driver cpuidle_driver = {
56         .name   = "sh_idle",
57         .owner  = THIS_MODULE,
58         .en_core_tk_irqen = 1,
59         .states = {
60                 {
61                         .exit_latency = 1,
62                         .target_residency = 1 * 2,
63                         .power_usage = 3,
64                         .flags = CPUIDLE_FLAG_TIME_VALID,
65                         .enter = cpuidle_sleep_enter,
66                         .name = "C1",
67                         .desc = "SuperH Sleep Mode",
68                 },
69                 {
70                         .exit_latency = 100,
71                         .target_residency = 1 * 2,
72                         .power_usage = 1,
73                         .flags = CPUIDLE_FLAG_TIME_VALID,
74                         .enter = cpuidle_sleep_enter,
75                         .name = "C2",
76                         .desc = "SuperH Sleep Mode [SF]",
77                         .disabled = true,
78                 },
79                 {
80                         .exit_latency = 2300,
81                         .target_residency = 1 * 2,
82                         .power_usage = 1,
83                         .flags = CPUIDLE_FLAG_TIME_VALID,
84                         .enter = cpuidle_sleep_enter,
85                         .name = "C3",
86                         .desc = "SuperH Mobile Standby Mode [SF]",
87                         .disabled = true,
88                 },
89         },
90         .safe_state_index = 0,
91         .state_count = 3,
92 };
93
94 void sh_mobile_setup_cpuidle(void)
95 {
96         if (sh_mobile_sleep_supported & SUSP_SH_SF)
97                 cpuidle_driver.states[1].disabled = false;
98
99         if (sh_mobile_sleep_supported & SUSP_SH_STANDBY)
100                 cpuidle_driver.states[2].disabled = false;
101
102         if (!cpuidle_register_driver(&cpuidle_driver))
103                 cpuidle_register_device(&cpuidle_dev);
104 }