blob: 1b2334277e85d5cbad17a126698fdbc39aaefd7b [file] [log] [blame]
Magnus Damm0af48172011-04-29 02:36:07 +09001/*
2 * CPUIdle support code for SH-Mobile ARM
3 *
4 * Copyright (C) 2011 Magnus Damm
5 *
6 * This file is subject to the terms and conditions of the GNU General Public
7 * License. See the file "COPYING" in the main directory of this archive
8 * for more details.
9 */
10
11#include <linux/pm.h>
12#include <linux/cpuidle.h>
13#include <linux/suspend.h>
14#include <linux/module.h>
15#include <linux/err.h>
16#include <asm/system.h>
17#include <asm/io.h>
18
19static void shmobile_enter_wfi(void)
20{
21 cpu_do_idle();
22}
23
24void (*shmobile_cpuidle_modes[CPUIDLE_STATE_MAX])(void) = {
25 shmobile_enter_wfi, /* regular sleep mode */
26};
27
28static int shmobile_cpuidle_enter(struct cpuidle_device *dev,
Magnus Dammb73b5c42011-11-11 14:01:30 +090029 struct cpuidle_driver *drv,
30 int index)
Magnus Damm0af48172011-04-29 02:36:07 +090031{
32 ktime_t before, after;
Magnus Damm0af48172011-04-29 02:36:07 +090033
Magnus Damm0af48172011-04-29 02:36:07 +090034 before = ktime_get();
35
36 local_irq_disable();
37 local_fiq_disable();
38
Magnus Dammb73b5c42011-11-11 14:01:30 +090039 shmobile_cpuidle_modes[index]();
Magnus Damm0af48172011-04-29 02:36:07 +090040
41 local_irq_enable();
42 local_fiq_enable();
43
44 after = ktime_get();
Magnus Dammb73b5c42011-11-11 14:01:30 +090045 dev->last_residency = ktime_to_ns(ktime_sub(after, before)) >> 10;
46
47 return index;
Magnus Damm0af48172011-04-29 02:36:07 +090048}
49
50static struct cpuidle_device shmobile_cpuidle_dev;
51static struct cpuidle_driver shmobile_cpuidle_driver = {
52 .name = "shmobile_cpuidle",
53 .owner = THIS_MODULE,
Magnus Dammb73b5c42011-11-11 14:01:30 +090054 .states[0] = {
55 .name = "C1",
56 .desc = "WFI",
57 .exit_latency = 1,
58 .target_residency = 1 * 2,
59 .flags = CPUIDLE_FLAG_TIME_VALID,
60 },
61 .safe_state_index = 0, /* C1 */
62 .state_count = 1,
Magnus Damm0af48172011-04-29 02:36:07 +090063};
64
Magnus Dammb73b5c42011-11-11 14:01:30 +090065void (*shmobile_cpuidle_setup)(struct cpuidle_driver *drv);
Magnus Damm0af48172011-04-29 02:36:07 +090066
67static int shmobile_cpuidle_init(void)
68{
69 struct cpuidle_device *dev = &shmobile_cpuidle_dev;
Magnus Dammb73b5c42011-11-11 14:01:30 +090070 struct cpuidle_driver *drv = &shmobile_cpuidle_driver;
Magnus Damm0af48172011-04-29 02:36:07 +090071 int i;
72
Magnus Dammb73b5c42011-11-11 14:01:30 +090073 for (i = 0; i < CPUIDLE_STATE_MAX; i++)
74 drv->states[i].enter = shmobile_cpuidle_enter;
Magnus Damm0af48172011-04-29 02:36:07 +090075
76 if (shmobile_cpuidle_setup)
Magnus Dammb73b5c42011-11-11 14:01:30 +090077 shmobile_cpuidle_setup(drv);
Magnus Damm0af48172011-04-29 02:36:07 +090078
Magnus Dammb73b5c42011-11-11 14:01:30 +090079 cpuidle_register_driver(drv);
80
81 dev->state_count = drv->state_count;
Magnus Damm0af48172011-04-29 02:36:07 +090082 cpuidle_register_device(dev);
83
84 return 0;
85}
86late_initcall(shmobile_cpuidle_init);