]> git.proxmox.com Git - mirror_ubuntu-artful-kernel.git/blob - arch/arm/mach-exynos4/cpuidle.c
cpuidle: Move dev->last_residency update to driver enter routine; remove dev->last_state
[mirror_ubuntu-artful-kernel.git] / arch / arm / mach-exynos4 / cpuidle.c
1 /* linux/arch/arm/mach-exynos4/cpuidle.c
2 *
3 * Copyright (c) 2011 Samsung Electronics Co., Ltd.
4 * http://www.samsung.com
5 *
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License version 2 as
8 * published by the Free Software Foundation.
9 */
10
11 #include <linux/kernel.h>
12 #include <linux/init.h>
13 #include <linux/cpuidle.h>
14 #include <linux/io.h>
15
16 #include <asm/proc-fns.h>
17
18 static int exynos4_enter_idle(struct cpuidle_device *dev,
19 int index);
20
21 static struct cpuidle_state exynos4_cpuidle_set[] = {
22 [0] = {
23 .enter = exynos4_enter_idle,
24 .exit_latency = 1,
25 .target_residency = 100000,
26 .flags = CPUIDLE_FLAG_TIME_VALID,
27 .name = "IDLE",
28 .desc = "ARM clock gating(WFI)",
29 },
30 };
31
32 static DEFINE_PER_CPU(struct cpuidle_device, exynos4_cpuidle_device);
33
34 static struct cpuidle_driver exynos4_idle_driver = {
35 .name = "exynos4_idle",
36 .owner = THIS_MODULE,
37 };
38
39 static int exynos4_enter_idle(struct cpuidle_device *dev,
40 int index)
41 {
42 struct timeval before, after;
43 int idle_time;
44
45 local_irq_disable();
46 do_gettimeofday(&before);
47
48 cpu_do_idle();
49
50 do_gettimeofday(&after);
51 local_irq_enable();
52 idle_time = (after.tv_sec - before.tv_sec) * USEC_PER_SEC +
53 (after.tv_usec - before.tv_usec);
54
55 dev->last_residency = idle_time;
56 return index;
57 }
58
59 static int __init exynos4_init_cpuidle(void)
60 {
61 int i, max_cpuidle_state, cpu_id;
62 struct cpuidle_device *device;
63
64 cpuidle_register_driver(&exynos4_idle_driver);
65
66 for_each_cpu(cpu_id, cpu_online_mask) {
67 device = &per_cpu(exynos4_cpuidle_device, cpu_id);
68 device->cpu = cpu_id;
69
70 device->state_count = (sizeof(exynos4_cpuidle_set) /
71 sizeof(struct cpuidle_state));
72
73 max_cpuidle_state = device->state_count;
74
75 for (i = 0; i < max_cpuidle_state; i++) {
76 memcpy(&device->states[i], &exynos4_cpuidle_set[i],
77 sizeof(struct cpuidle_state));
78 }
79
80 if (cpuidle_register_device(device)) {
81 printk(KERN_ERR "CPUidle register device failed\n,");
82 return -EIO;
83 }
84 }
85 return 0;
86 }
87 device_initcall(exynos4_init_cpuidle);