1 // SPDX-License-Identifier: GPL-2.0
3 * arch/sh/kernel/cpu/shmobile/cpuidle.c
5 * Cpuidle support code for SuperH Mobile
7 * Copyright (C) 2009 Magnus Damm
9 #include <linux/init.h>
10 #include <linux/kernel.h>
12 #include <linux/suspend.h>
13 #include <linux/cpuidle.h>
14 #include <linux/export.h>
15 #include <asm/suspend.h>
16 #include <linux/uaccess.h>
18 static unsigned long cpuidle_mode[] = {
19 SUSP_SH_SLEEP, /* regular sleep mode */
20 SUSP_SH_SLEEP | SUSP_SH_SF, /* sleep mode + self refresh */
21 SUSP_SH_STANDBY | SUSP_SH_SF, /* software standby mode + self refresh */
24 static int cpuidle_sleep_enter(struct cpuidle_device *dev,
25 struct cpuidle_driver *drv,
28 unsigned long allowed_mode = SUSP_SH_SLEEP;
29 int requested_state = index;
33 /* convert allowed mode to allowed state */
34 for (k = ARRAY_SIZE(cpuidle_mode) - 1; k > 0; k--)
35 if (cpuidle_mode[k] == allowed_mode)
40 /* take the following into account for sleep mode selection:
41 * - allowed_state: best mode allowed by hardware (clock deps)
42 * - requested_state: best mode allowed by software (latencies)
44 k = min_t(int, allowed_state, requested_state);
46 sh_mobile_call_standby(cpuidle_mode[k]);
51 static struct cpuidle_driver cpuidle_driver = {
57 .target_residency = 1 * 2,
59 .enter = cpuidle_sleep_enter,
61 .desc = "SuperH Sleep Mode",
65 .target_residency = 1 * 2,
67 .enter = cpuidle_sleep_enter,
69 .desc = "SuperH Sleep Mode [SF]",
74 .target_residency = 1 * 2,
76 .enter = cpuidle_sleep_enter,
78 .desc = "SuperH Mobile Standby Mode [SF]",
82 .safe_state_index = 0,
86 int __init sh_mobile_setup_cpuidle(void)
88 if (sh_mobile_sleep_supported & SUSP_SH_SF)
89 cpuidle_driver.states[1].disabled = false;
91 if (sh_mobile_sleep_supported & SUSP_SH_STANDBY)
92 cpuidle_driver.states[2].disabled = false;
94 return cpuidle_register(&cpuidle_driver, NULL);