Jaecheol Lee | 3d73998 | 2011-03-16 07:28:23 +0900 | [diff] [blame] | 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> |
Kyungmin Park | 76ee455 | 2011-11-08 19:57:59 +0900 | [diff] [blame] | 15 | #include <linux/export.h> |
| 16 | #include <linux/time.h> |
Jaecheol Lee | 3d73998 | 2011-03-16 07:28:23 +0900 | [diff] [blame] | 17 | |
| 18 | #include <asm/proc-fns.h> |
| 19 | |
| 20 | static int exynos4_enter_idle(struct cpuidle_device *dev, |
Deepthi Dharwar | 46bcfad | 2011-10-28 16:20:42 +0530 | [diff] [blame] | 21 | struct cpuidle_driver *drv, |
Deepthi Dharwar | e978aa7 | 2011-10-28 16:20:09 +0530 | [diff] [blame] | 22 | int index); |
Jaecheol Lee | 3d73998 | 2011-03-16 07:28:23 +0900 | [diff] [blame] | 23 | |
| 24 | static struct cpuidle_state exynos4_cpuidle_set[] = { |
| 25 | [0] = { |
| 26 | .enter = exynos4_enter_idle, |
| 27 | .exit_latency = 1, |
| 28 | .target_residency = 100000, |
| 29 | .flags = CPUIDLE_FLAG_TIME_VALID, |
| 30 | .name = "IDLE", |
| 31 | .desc = "ARM clock gating(WFI)", |
| 32 | }, |
| 33 | }; |
| 34 | |
| 35 | static DEFINE_PER_CPU(struct cpuidle_device, exynos4_cpuidle_device); |
| 36 | |
| 37 | static struct cpuidle_driver exynos4_idle_driver = { |
| 38 | .name = "exynos4_idle", |
| 39 | .owner = THIS_MODULE, |
| 40 | }; |
| 41 | |
| 42 | static int exynos4_enter_idle(struct cpuidle_device *dev, |
Deepthi Dharwar | 46bcfad | 2011-10-28 16:20:42 +0530 | [diff] [blame] | 43 | struct cpuidle_driver *drv, |
Deepthi Dharwar | e978aa7 | 2011-10-28 16:20:09 +0530 | [diff] [blame] | 44 | int index) |
Jaecheol Lee | 3d73998 | 2011-03-16 07:28:23 +0900 | [diff] [blame] | 45 | { |
| 46 | struct timeval before, after; |
| 47 | int idle_time; |
| 48 | |
| 49 | local_irq_disable(); |
| 50 | do_gettimeofday(&before); |
| 51 | |
| 52 | cpu_do_idle(); |
| 53 | |
| 54 | do_gettimeofday(&after); |
| 55 | local_irq_enable(); |
| 56 | idle_time = (after.tv_sec - before.tv_sec) * USEC_PER_SEC + |
| 57 | (after.tv_usec - before.tv_usec); |
| 58 | |
Deepthi Dharwar | e978aa7 | 2011-10-28 16:20:09 +0530 | [diff] [blame] | 59 | dev->last_residency = idle_time; |
| 60 | return index; |
Jaecheol Lee | 3d73998 | 2011-03-16 07:28:23 +0900 | [diff] [blame] | 61 | } |
| 62 | |
| 63 | static int __init exynos4_init_cpuidle(void) |
| 64 | { |
| 65 | int i, max_cpuidle_state, cpu_id; |
| 66 | struct cpuidle_device *device; |
Deepthi Dharwar | 46bcfad | 2011-10-28 16:20:42 +0530 | [diff] [blame] | 67 | struct cpuidle_driver *drv = &exynos4_idle_driver; |
Jaecheol Lee | 3d73998 | 2011-03-16 07:28:23 +0900 | [diff] [blame] | 68 | |
Deepthi Dharwar | 46bcfad | 2011-10-28 16:20:42 +0530 | [diff] [blame] | 69 | /* Setup cpuidle driver */ |
| 70 | drv->state_count = (sizeof(exynos4_cpuidle_set) / |
| 71 | sizeof(struct cpuidle_state)); |
| 72 | max_cpuidle_state = drv->state_count; |
| 73 | for (i = 0; i < max_cpuidle_state; i++) { |
| 74 | memcpy(&drv->states[i], &exynos4_cpuidle_set[i], |
| 75 | sizeof(struct cpuidle_state)); |
| 76 | } |
Jaecheol Lee | 3d73998 | 2011-03-16 07:28:23 +0900 | [diff] [blame] | 77 | cpuidle_register_driver(&exynos4_idle_driver); |
| 78 | |
| 79 | for_each_cpu(cpu_id, cpu_online_mask) { |
| 80 | device = &per_cpu(exynos4_cpuidle_device, cpu_id); |
| 81 | device->cpu = cpu_id; |
| 82 | |
Deepthi Dharwar | 46bcfad | 2011-10-28 16:20:42 +0530 | [diff] [blame] | 83 | device->state_count = drv->state_count; |
Jaecheol Lee | 3d73998 | 2011-03-16 07:28:23 +0900 | [diff] [blame] | 84 | |
| 85 | if (cpuidle_register_device(device)) { |
| 86 | printk(KERN_ERR "CPUidle register device failed\n,"); |
| 87 | return -EIO; |
| 88 | } |
| 89 | } |
| 90 | return 0; |
| 91 | } |
| 92 | device_initcall(exynos4_init_cpuidle); |