blob: d40b3f317f7f7058ff29b657033b3cc0d747dce9 [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>
Albin Tonnerre1ea60cf2009-11-01 18:40:50 +010020#include <linux/io.h>
Paul Gortmakerdc280942011-07-31 16:17:29 -040021#include <linux/export.h>
Robert Lee7e348b92012-03-20 15:22:43 -050022#include <asm/proc-fns.h>
23#include <asm/cpuidle.h>
Albin Tonnerre1ea60cf2009-11-01 18:40:50 +010024
25#include "pm.h"
26
27#define AT91_MAX_STATES 2
28
29static DEFINE_PER_CPU(struct cpuidle_device, at91_cpuidle_device);
30
Albin Tonnerre1ea60cf2009-11-01 18:40:50 +010031/* Actual code that puts the SoC in different idle states */
32static int at91_enter_idle(struct cpuidle_device *dev,
Deepthi Dharwar46bcfad2011-10-28 16:20:42 +053033 struct cpuidle_driver *drv,
Deepthi Dharware978aa72011-10-28 16:20:09 +053034 int index)
Albin Tonnerre1ea60cf2009-11-01 18:40:50 +010035{
Albin Tonnerre1ea60cf2009-11-01 18:40:50 +010036 u32 saved_lpr;
37
Robert Lee7e348b92012-03-20 15:22:43 -050038 __asm__("b 1f; .align 5; 1:\n"
39 " mcr p15, 0, r0, c7, c10, 4"); /* drain write buffer */
Deepthi Dharware978aa72011-10-28 16:20:09 +053040
Robert Lee7e348b92012-03-20 15:22:43 -050041 saved_lpr = sdram_selfrefresh_enable();
42 cpu_do_idle();
43 sdram_selfrefresh_disable(saved_lpr);
44
Deepthi Dharware978aa72011-10-28 16:20:09 +053045 return index;
Albin Tonnerre1ea60cf2009-11-01 18:40:50 +010046}
47
Robert Lee7e348b92012-03-20 15:22:43 -050048static struct cpuidle_driver at91_idle_driver = {
49 .name = "at91_idle",
50 .owner = THIS_MODULE,
51 .en_core_tk_irqen = 1,
52 .states[0] = ARM_CPUIDLE_WFI_STATE,
53 .states[1] = {
54 .enter = at91_enter_idle,
55 .exit_latency = 10,
56 .target_residency = 100000,
57 .flags = CPUIDLE_FLAG_TIME_VALID,
58 .name = "RAM_SR",
59 .desc = "WFI and DDR Self Refresh",
60 },
61 .state_count = AT91_MAX_STATES,
62};
63
Albin Tonnerre1ea60cf2009-11-01 18:40:50 +010064/* Initialize CPU idle by registering the idle states */
65static int at91_init_cpuidle(void)
66{
67 struct cpuidle_device *device;
Albin Tonnerre1ea60cf2009-11-01 18:40:50 +010068
69 device = &per_cpu(at91_cpuidle_device, smp_processor_id());
70 device->state_count = AT91_MAX_STATES;
Deepthi Dharwar46bcfad2011-10-28 16:20:42 +053071
72 cpuidle_register_driver(&at91_idle_driver);
Albin Tonnerre1ea60cf2009-11-01 18:40:50 +010073
74 if (cpuidle_register_device(device)) {
75 printk(KERN_ERR "at91_init_cpuidle: Failed registering\n");
76 return -EIO;
77 }
78 return 0;
79}
80
81device_initcall(at91_init_cpuidle);