2 * based on arch/arm/mach-kirkwood/cpuidle.c
4 * CPU idle support for AT91 SoC
6 * This file is licensed under the terms of the GNU General Public
7 * License version 2. This program is licensed "as is" without any
8 * warranty of any kind, whether express or implied.
10 * The cpu idle uses wait-for-interrupt and RAM self refresh in order
11 * to implement two idle states -
12 * #1 wait-for-interrupt
13 * #2 wait-for-interrupt and RAM self refresh
16 #include <linux/kernel.h>
17 #include <linux/init.h>
18 #include <linux/platform_device.h>
19 #include <linux/cpuidle.h>
20 #include <asm/proc-fns.h>
22 #include <linux/export.h>
26 #define AT91_MAX_STATES 2
28 static DEFINE_PER_CPU(struct cpuidle_device
, at91_cpuidle_device
);
30 static struct cpuidle_driver at91_idle_driver
= {
35 /* Actual code that puts the SoC in different idle states */
36 static int at91_enter_idle(struct cpuidle_device
*dev
,
37 struct cpuidle_driver
*drv
,
40 struct timeval before
, after
;
44 do_gettimeofday(&before
);
46 /* Wait for interrupt state */
51 do_gettimeofday(&after
);
53 idle_time
= (after
.tv_sec
- before
.tv_sec
) * USEC_PER_SEC
+
54 (after
.tv_usec
- before
.tv_usec
);
56 dev
->last_residency
= idle_time
;
60 /* Initialize CPU idle by registering the idle states */
61 static int at91_init_cpuidle(void)
63 struct cpuidle_device
*device
;
64 struct cpuidle_driver
*driver
= &at91_idle_driver
;
66 device
= &per_cpu(at91_cpuidle_device
, smp_processor_id());
67 device
->state_count
= AT91_MAX_STATES
;
68 driver
->state_count
= AT91_MAX_STATES
;
70 /* Wait for interrupt state */
71 driver
->states
[0].enter
= at91_enter_idle
;
72 driver
->states
[0].exit_latency
= 1;
73 driver
->states
[0].target_residency
= 10000;
74 driver
->states
[0].flags
= CPUIDLE_FLAG_TIME_VALID
;
75 strcpy(driver
->states
[0].name
, "WFI");
76 strcpy(driver
->states
[0].desc
, "Wait for interrupt");
78 /* Wait for interrupt and RAM self refresh state */
79 driver
->states
[1].enter
= at91_enter_idle
;
80 driver
->states
[1].exit_latency
= 10;
81 driver
->states
[1].target_residency
= 10000;
82 driver
->states
[1].flags
= CPUIDLE_FLAG_TIME_VALID
;
83 strcpy(driver
->states
[1].name
, "RAM_SR");
84 strcpy(driver
->states
[1].desc
, "WFI and RAM Self Refresh");
86 cpuidle_register_driver(&at91_idle_driver
);
88 if (cpuidle_register_device(device
)) {
89 printk(KERN_ERR
"at91_init_cpuidle: Failed registering\n");
95 device_initcall(at91_init_cpuidle
);