blob: 93178f67420ee55f175b9a5ef9e32cfa505e966e [file] [log] [blame]
Albin Tonnerre1ea60cf2009-11-01 18:40:50 +01001/*
2 * based on arch/arm/mach-kirkwood/cpuidle.c
3 *
4 * CPU idle support for AT91 SoC
5 *
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.
9 *
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
14 */
15
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>
21#include <linux/io.h>
22
23#include "pm.h"
24
25#define AT91_MAX_STATES 2
26
27static DEFINE_PER_CPU(struct cpuidle_device, at91_cpuidle_device);
28
29static struct cpuidle_driver at91_idle_driver = {
30 .name = "at91_idle",
31 .owner = THIS_MODULE,
32};
33
34/* Actual code that puts the SoC in different idle states */
35static int at91_enter_idle(struct cpuidle_device *dev,
Deepthi Dharwar46bcfad2011-10-28 16:20:42 +053036 struct cpuidle_driver *drv,
Deepthi Dharware978aa72011-10-28 16:20:09 +053037 int index)
Albin Tonnerre1ea60cf2009-11-01 18:40:50 +010038{
39 struct timeval before, after;
40 int idle_time;
41 u32 saved_lpr;
42
43 local_irq_disable();
44 do_gettimeofday(&before);
Deepthi Dharware978aa72011-10-28 16:20:09 +053045 if (index == 0)
Albin Tonnerre1ea60cf2009-11-01 18:40:50 +010046 /* Wait for interrupt state */
47 cpu_do_idle();
Deepthi Dharware978aa72011-10-28 16:20:09 +053048 else if (index == 1) {
Albin Tonnerre1ea60cf2009-11-01 18:40:50 +010049 asm("b 1f; .align 5; 1:");
50 asm("mcr p15, 0, r0, c7, c10, 4"); /* drain write buffer */
51 saved_lpr = sdram_selfrefresh_enable();
52 cpu_do_idle();
53 sdram_selfrefresh_disable(saved_lpr);
54 }
55 do_gettimeofday(&after);
56 local_irq_enable();
57 idle_time = (after.tv_sec - before.tv_sec) * USEC_PER_SEC +
58 (after.tv_usec - before.tv_usec);
Deepthi Dharware978aa72011-10-28 16:20:09 +053059
60 dev->last_residency = idle_time;
61 return index;
Albin Tonnerre1ea60cf2009-11-01 18:40:50 +010062}
63
64/* Initialize CPU idle by registering the idle states */
65static int at91_init_cpuidle(void)
66{
67 struct cpuidle_device *device;
Deepthi Dharwar46bcfad2011-10-28 16:20:42 +053068 struct cpuidle_driver *driver = &at91_idle_driver;
Albin Tonnerre1ea60cf2009-11-01 18:40:50 +010069
70 device = &per_cpu(at91_cpuidle_device, smp_processor_id());
71 device->state_count = AT91_MAX_STATES;
Deepthi Dharwar46bcfad2011-10-28 16:20:42 +053072 driver->state_count = AT91_MAX_STATES;
Albin Tonnerre1ea60cf2009-11-01 18:40:50 +010073
74 /* Wait for interrupt state */
Deepthi Dharwar46bcfad2011-10-28 16:20:42 +053075 driver->states[0].enter = at91_enter_idle;
76 driver->states[0].exit_latency = 1;
77 driver->states[0].target_residency = 10000;
78 driver->states[0].flags = CPUIDLE_FLAG_TIME_VALID;
79 strcpy(driver->states[0].name, "WFI");
80 strcpy(driver->states[0].desc, "Wait for interrupt");
Albin Tonnerre1ea60cf2009-11-01 18:40:50 +010081
82 /* Wait for interrupt and RAM self refresh state */
Deepthi Dharwar46bcfad2011-10-28 16:20:42 +053083 driver->states[1].enter = at91_enter_idle;
84 driver->states[1].exit_latency = 10;
85 driver->states[1].target_residency = 10000;
86 driver->states[1].flags = CPUIDLE_FLAG_TIME_VALID;
87 strcpy(driver->states[1].name, "RAM_SR");
88 strcpy(driver->states[1].desc, "WFI and RAM Self Refresh");
89
90 cpuidle_register_driver(&at91_idle_driver);
Albin Tonnerre1ea60cf2009-11-01 18:40:50 +010091
92 if (cpuidle_register_device(device)) {
93 printk(KERN_ERR "at91_init_cpuidle: Failed registering\n");
94 return -EIO;
95 }
96 return 0;
97}
98
99device_initcall(at91_init_cpuidle);