blob: 35f6502144ae14c9ffa989066f51add9ee084375 [file] [log] [blame]
Jaecheol Lee3d739982011-03-16 07:28:23 +09001/* 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
18static int exynos4_enter_idle(struct cpuidle_device *dev,
Deepthi Dharwar46bcfad2011-10-28 16:20:42 +053019 struct cpuidle_driver *drv,
Deepthi Dharware978aa72011-10-28 16:20:09 +053020 int index);
Jaecheol Lee3d739982011-03-16 07:28:23 +090021
22static struct cpuidle_state exynos4_cpuidle_set[] = {
23 [0] = {
24 .enter = exynos4_enter_idle,
25 .exit_latency = 1,
26 .target_residency = 100000,
27 .flags = CPUIDLE_FLAG_TIME_VALID,
28 .name = "IDLE",
29 .desc = "ARM clock gating(WFI)",
30 },
31};
32
33static DEFINE_PER_CPU(struct cpuidle_device, exynos4_cpuidle_device);
34
35static struct cpuidle_driver exynos4_idle_driver = {
36 .name = "exynos4_idle",
37 .owner = THIS_MODULE,
38};
39
40static int exynos4_enter_idle(struct cpuidle_device *dev,
Deepthi Dharwar46bcfad2011-10-28 16:20:42 +053041 struct cpuidle_driver *drv,
Deepthi Dharware978aa72011-10-28 16:20:09 +053042 int index)
Jaecheol Lee3d739982011-03-16 07:28:23 +090043{
44 struct timeval before, after;
45 int idle_time;
46
47 local_irq_disable();
48 do_gettimeofday(&before);
49
50 cpu_do_idle();
51
52 do_gettimeofday(&after);
53 local_irq_enable();
54 idle_time = (after.tv_sec - before.tv_sec) * USEC_PER_SEC +
55 (after.tv_usec - before.tv_usec);
56
Deepthi Dharware978aa72011-10-28 16:20:09 +053057 dev->last_residency = idle_time;
58 return index;
Jaecheol Lee3d739982011-03-16 07:28:23 +090059}
60
61static int __init exynos4_init_cpuidle(void)
62{
63 int i, max_cpuidle_state, cpu_id;
64 struct cpuidle_device *device;
Deepthi Dharwar46bcfad2011-10-28 16:20:42 +053065 struct cpuidle_driver *drv = &exynos4_idle_driver;
Jaecheol Lee3d739982011-03-16 07:28:23 +090066
Deepthi Dharwar46bcfad2011-10-28 16:20:42 +053067 /* Setup cpuidle driver */
68 drv->state_count = (sizeof(exynos4_cpuidle_set) /
69 sizeof(struct cpuidle_state));
70 max_cpuidle_state = drv->state_count;
71 for (i = 0; i < max_cpuidle_state; i++) {
72 memcpy(&drv->states[i], &exynos4_cpuidle_set[i],
73 sizeof(struct cpuidle_state));
74 }
Jaecheol Lee3d739982011-03-16 07:28:23 +090075 cpuidle_register_driver(&exynos4_idle_driver);
76
77 for_each_cpu(cpu_id, cpu_online_mask) {
78 device = &per_cpu(exynos4_cpuidle_device, cpu_id);
79 device->cpu = cpu_id;
80
Deepthi Dharwar46bcfad2011-10-28 16:20:42 +053081 device->state_count = drv->state_count;
Jaecheol Lee3d739982011-03-16 07:28:23 +090082
83 if (cpuidle_register_device(device)) {
84 printk(KERN_ERR "CPUidle register device failed\n,");
85 return -EIO;
86 }
87 }
88 return 0;
89}
90device_initcall(exynos4_init_cpuidle);