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 <linux/export.h>
18 #include <asm/suspend.h>
19 #include <asm/uaccess.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,
28 struct cpuidle_driver *drv,
31 unsigned long allowed_mode = SUSP_SH_SLEEP;
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);
49 sh_mobile_call_standby(cpuidle_mode[k]);
54 static struct cpuidle_device cpuidle_dev;
55 static struct cpuidle_driver cpuidle_driver = {
58 .en_core_tk_irqen = 1,
61 void sh_mobile_setup_cpuidle(void)
63 struct cpuidle_device *dev = &cpuidle_dev;
64 struct cpuidle_driver *drv = &cpuidle_driver;
65 struct cpuidle_state *state;
68 i = CPUIDLE_DRIVER_STATE_START;
70 state = &drv->states[i++];
71 snprintf(state->name, CPUIDLE_NAME_LEN, "C1");
72 strncpy(state->desc, "SuperH Sleep Mode", CPUIDLE_DESC_LEN);
73 state->exit_latency = 1;
74 state->target_residency = 1 * 2;
75 state->power_usage = 3;
77 state->flags |= CPUIDLE_FLAG_TIME_VALID;
78 state->enter = cpuidle_sleep_enter;
80 drv->safe_state_index = i-1;
82 if (sh_mobile_sleep_supported & SUSP_SH_SF) {
83 state = &drv->states[i++];
84 snprintf(state->name, CPUIDLE_NAME_LEN, "C2");
85 strncpy(state->desc, "SuperH Sleep Mode [SF]",
87 state->exit_latency = 100;
88 state->target_residency = 1 * 2;
89 state->power_usage = 1;
91 state->flags |= CPUIDLE_FLAG_TIME_VALID;
92 state->enter = cpuidle_sleep_enter;
95 if (sh_mobile_sleep_supported & SUSP_SH_STANDBY) {
96 state = &drv->states[i++];
97 snprintf(state->name, CPUIDLE_NAME_LEN, "C3");
98 strncpy(state->desc, "SuperH Mobile Standby Mode [SF]",
100 state->exit_latency = 2300;
101 state->target_residency = 1 * 2;
102 state->power_usage = 1;
104 state->flags |= CPUIDLE_FLAG_TIME_VALID;
105 state->enter = cpuidle_sleep_enter;
108 drv->state_count = i;
109 dev->state_count = i;
111 cpuidle_register_driver(&cpuidle_driver);
113 cpuidle_register_device(dev);