2 * arch/sh/kernel/cpu/shmobile/cpuidle.c
4 * Cpuidle support code for SuperH Mobile
6 * Copyright (C) 2009 Magnus Damm
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
12 #include <linux/init.h>
13 #include <linux/kernel.h>
15 #include <linux/suspend.h>
16 #include <linux/cpuidle.h>
17 #include <asm/suspend.h>
18 #include <asm/uaccess.h>
19 #include <asm/hwblk.h>
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 */
27 static int cpuidle_sleep_enter(struct cpuidle_device
*dev
,
30 unsigned long allowed_mode
= arch_hwblk_sleep_mode();
31 ktime_t before
, after
;
32 int requested_state
= index
;
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
)
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)
47 k
= min_t(int, allowed_state
, requested_state
);
50 sh_mobile_call_standby(cpuidle_mode
[k
]);
53 dev
->last_residency
= (int)ktime_to_ns(ktime_sub(after
, before
)) >> 10;
58 static struct cpuidle_device cpuidle_dev
;
59 static struct cpuidle_driver cpuidle_driver
= {
64 void sh_mobile_setup_cpuidle(void)
66 struct cpuidle_device
*dev
= &cpuidle_dev
;
67 struct cpuidle_state
*state
;
70 cpuidle_register_driver(&cpuidle_driver
);
72 for (i
= 0; i
< CPUIDLE_STATE_MAX
; i
++) {
73 dev
->states
[i
].name
[0] = '\0';
74 dev
->states
[i
].desc
[0] = '\0';
77 i
= CPUIDLE_DRIVER_STATE_START
;
79 state
= &dev
->states
[i
++];
80 snprintf(state
->name
, CPUIDLE_NAME_LEN
, "C1");
81 strncpy(state
->desc
, "SuperH Sleep Mode", CPUIDLE_DESC_LEN
);
82 state
->exit_latency
= 1;
83 state
->target_residency
= 1 * 2;
84 state
->power_usage
= 3;
86 state
->flags
|= CPUIDLE_FLAG_TIME_VALID
;
87 state
->enter
= cpuidle_sleep_enter
;
89 dev
->safe_state_index
= i
-1;
91 if (sh_mobile_sleep_supported
& SUSP_SH_SF
) {
92 state
= &dev
->states
[i
++];
93 snprintf(state
->name
, CPUIDLE_NAME_LEN
, "C2");
94 strncpy(state
->desc
, "SuperH Sleep Mode [SF]",
96 state
->exit_latency
= 100;
97 state
->target_residency
= 1 * 2;
98 state
->power_usage
= 1;
100 state
->flags
|= CPUIDLE_FLAG_TIME_VALID
;
101 state
->enter
= cpuidle_sleep_enter
;
104 if (sh_mobile_sleep_supported
& SUSP_SH_STANDBY
) {
105 state
= &dev
->states
[i
++];
106 snprintf(state
->name
, CPUIDLE_NAME_LEN
, "C3");
107 strncpy(state
->desc
, "SuperH Mobile Standby Mode [SF]",
109 state
->exit_latency
= 2300;
110 state
->target_residency
= 1 * 2;
111 state
->power_usage
= 1;
113 state
->flags
|= CPUIDLE_FLAG_TIME_VALID
;
114 state
->enter
= cpuidle_sleep_enter
;
117 dev
->state_count
= i
;
119 cpuidle_register_device(dev
);