Merge branch 'for-linus' of git://git.kernel.org/pub/scm/linux/kernel/git/mason/linux...
[GitHub/LineageOS/android_kernel_motorola_exynos9610.git] / arch / sh / kernel / cpu / shmobile / cpuidle.c
CommitLineData
7426394f
MD
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>
f7be3455 17#include <linux/export.h>
7426394f
MD
18#include <asm/suspend.h>
19#include <asm/uaccess.h>
7426394f
MD
20
21static unsigned long cpuidle_mode[] = {
22 SUSP_SH_SLEEP, /* regular sleep mode */
23 SUSP_SH_SLEEP | SUSP_SH_SF, /* sleep mode + self refresh */
63cd91df 24 SUSP_SH_STANDBY | SUSP_SH_SF, /* software standby mode + self refresh */
7426394f
MD
25};
26
27static int cpuidle_sleep_enter(struct cpuidle_device *dev,
46bcfad7 28 struct cpuidle_driver *drv,
e978aa7d 29 int index)
7426394f 30{
4be88734 31 unsigned long allowed_mode = SUSP_SH_SLEEP;
e978aa7d 32 int requested_state = index;
7426394f
MD
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
7426394f 49 sh_mobile_call_standby(cpuidle_mode[k]);
e978aa7d
DD
50
51 return k;
7426394f
MD
52}
53
7426394f 54static struct cpuidle_driver cpuidle_driver = {
0a4f841e
DL
55 .name = "sh_idle",
56 .owner = THIS_MODULE,
0a4f841e
DL
57 .states = {
58 {
59 .exit_latency = 1,
60 .target_residency = 1 * 2,
61 .power_usage = 3,
0a4f841e
DL
62 .enter = cpuidle_sleep_enter,
63 .name = "C1",
64 .desc = "SuperH Sleep Mode",
65 },
66 {
67 .exit_latency = 100,
68 .target_residency = 1 * 2,
69 .power_usage = 1,
0a4f841e
DL
70 .enter = cpuidle_sleep_enter,
71 .name = "C2",
72 .desc = "SuperH Sleep Mode [SF]",
73 .disabled = true,
74 },
75 {
76 .exit_latency = 2300,
77 .target_residency = 1 * 2,
78 .power_usage = 1,
0a4f841e
DL
79 .enter = cpuidle_sleep_enter,
80 .name = "C3",
81 .desc = "SuperH Mobile Standby Mode [SF]",
82 .disabled = true,
83 },
84 },
85 .safe_state_index = 0,
86 .state_count = 3,
7426394f
MD
87};
88
38a94f41 89int __init sh_mobile_setup_cpuidle(void)
7426394f 90{
0a4f841e
DL
91 if (sh_mobile_sleep_supported & SUSP_SH_SF)
92 cpuidle_driver.states[1].disabled = false;
7426394f 93
0a4f841e
DL
94 if (sh_mobile_sleep_supported & SUSP_SH_STANDBY)
95 cpuidle_driver.states[2].disabled = false;
7426394f 96
c78e4360 97 return cpuidle_register(&cpuidle_driver, NULL);
7426394f 98}