Magnus Damm | 0af4817 | 2011-04-29 02:36:07 +0900 | [diff] [blame] | 1 | /* |
| 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> |
Magnus Damm | 0af4817 | 2011-04-29 02:36:07 +0900 | [diff] [blame] | 16 | #include <asm/io.h> |
| 17 | |
| 18 | static void shmobile_enter_wfi(void) |
| 19 | { |
| 20 | cpu_do_idle(); |
| 21 | } |
| 22 | |
| 23 | void (*shmobile_cpuidle_modes[CPUIDLE_STATE_MAX])(void) = { |
| 24 | shmobile_enter_wfi, /* regular sleep mode */ |
| 25 | }; |
| 26 | |
| 27 | static int shmobile_cpuidle_enter(struct cpuidle_device *dev, |
Magnus Damm | b73b5c4 | 2011-11-11 14:01:30 +0900 | [diff] [blame] | 28 | struct cpuidle_driver *drv, |
| 29 | int index) |
Magnus Damm | 0af4817 | 2011-04-29 02:36:07 +0900 | [diff] [blame] | 30 | { |
| 31 | ktime_t before, after; |
Magnus Damm | 0af4817 | 2011-04-29 02:36:07 +0900 | [diff] [blame] | 32 | |
Magnus Damm | 0af4817 | 2011-04-29 02:36:07 +0900 | [diff] [blame] | 33 | before = ktime_get(); |
| 34 | |
| 35 | local_irq_disable(); |
| 36 | local_fiq_disable(); |
| 37 | |
Magnus Damm | b73b5c4 | 2011-11-11 14:01:30 +0900 | [diff] [blame] | 38 | shmobile_cpuidle_modes[index](); |
Magnus Damm | 0af4817 | 2011-04-29 02:36:07 +0900 | [diff] [blame] | 39 | |
| 40 | local_irq_enable(); |
| 41 | local_fiq_enable(); |
| 42 | |
| 43 | after = ktime_get(); |
Magnus Damm | b73b5c4 | 2011-11-11 14:01:30 +0900 | [diff] [blame] | 44 | dev->last_residency = ktime_to_ns(ktime_sub(after, before)) >> 10; |
| 45 | |
| 46 | return index; |
Magnus Damm | 0af4817 | 2011-04-29 02:36:07 +0900 | [diff] [blame] | 47 | } |
| 48 | |
| 49 | static struct cpuidle_device shmobile_cpuidle_dev; |
| 50 | static struct cpuidle_driver shmobile_cpuidle_driver = { |
| 51 | .name = "shmobile_cpuidle", |
| 52 | .owner = THIS_MODULE, |
Magnus Damm | b73b5c4 | 2011-11-11 14:01:30 +0900 | [diff] [blame] | 53 | .states[0] = { |
| 54 | .name = "C1", |
| 55 | .desc = "WFI", |
| 56 | .exit_latency = 1, |
| 57 | .target_residency = 1 * 2, |
| 58 | .flags = CPUIDLE_FLAG_TIME_VALID, |
| 59 | }, |
| 60 | .safe_state_index = 0, /* C1 */ |
| 61 | .state_count = 1, |
Magnus Damm | 0af4817 | 2011-04-29 02:36:07 +0900 | [diff] [blame] | 62 | }; |
| 63 | |
Magnus Damm | b73b5c4 | 2011-11-11 14:01:30 +0900 | [diff] [blame] | 64 | void (*shmobile_cpuidle_setup)(struct cpuidle_driver *drv); |
Magnus Damm | 0af4817 | 2011-04-29 02:36:07 +0900 | [diff] [blame] | 65 | |
| 66 | static int shmobile_cpuidle_init(void) |
| 67 | { |
| 68 | struct cpuidle_device *dev = &shmobile_cpuidle_dev; |
Magnus Damm | b73b5c4 | 2011-11-11 14:01:30 +0900 | [diff] [blame] | 69 | struct cpuidle_driver *drv = &shmobile_cpuidle_driver; |
Magnus Damm | 0af4817 | 2011-04-29 02:36:07 +0900 | [diff] [blame] | 70 | int i; |
| 71 | |
Magnus Damm | b73b5c4 | 2011-11-11 14:01:30 +0900 | [diff] [blame] | 72 | for (i = 0; i < CPUIDLE_STATE_MAX; i++) |
| 73 | drv->states[i].enter = shmobile_cpuidle_enter; |
Magnus Damm | 0af4817 | 2011-04-29 02:36:07 +0900 | [diff] [blame] | 74 | |
| 75 | if (shmobile_cpuidle_setup) |
Magnus Damm | b73b5c4 | 2011-11-11 14:01:30 +0900 | [diff] [blame] | 76 | shmobile_cpuidle_setup(drv); |
Magnus Damm | 0af4817 | 2011-04-29 02:36:07 +0900 | [diff] [blame] | 77 | |
Magnus Damm | b73b5c4 | 2011-11-11 14:01:30 +0900 | [diff] [blame] | 78 | cpuidle_register_driver(drv); |
| 79 | |
| 80 | dev->state_count = drv->state_count; |
Magnus Damm | 0af4817 | 2011-04-29 02:36:07 +0900 | [diff] [blame] | 81 | cpuidle_register_device(dev); |
| 82 | |
| 83 | return 0; |
| 84 | } |
| 85 | late_initcall(shmobile_cpuidle_init); |