- patches.apparmor/remove_suid_new_case_in_2.6.22.diff: Merge fix.
[linux-flexiantxendom0-3.2.10.git] / arch / powerpc / platforms / pasemi / idle.c
1 /*
2  * Copyright (C) 2006-2007 PA Semi, Inc
3  *
4  * Maintained by: Olof Johansson <olof@lixom.net>
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  * This program is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13  * GNU General Public License for more details.
14  *
15  * You should have received a copy of the GNU General Public License
16  * along with this program; if not, write to the Free Software
17  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
18  *
19  */
20
21 #undef DEBUG
22
23 #include <linux/kernel.h>
24 #include <linux/string.h>
25 #include <linux/irq.h>
26
27 #include <asm/machdep.h>
28 #include <asm/reg.h>
29
30 #include "pasemi.h"
31
32 struct sleep_mode {
33         char *name;
34         void (*entry)(void);
35 };
36
37 static struct sleep_mode modes[] = {
38         { .name = "spin", .entry = &idle_spin },
39         { .name = "doze", .entry = &idle_doze },
40 };
41
42 static int current_mode = 0;
43
44 static int pasemi_system_reset_exception(struct pt_regs *regs)
45 {
46         /* If we were woken up from power savings, we need to return
47          * to the calling function, since nip is not saved across
48          * all modes.
49          */
50
51         if (regs->msr & SRR1_WAKEMASK)
52                 regs->nip = regs->link;
53
54         switch (regs->msr & SRR1_WAKEMASK) {
55         case SRR1_WAKEEE:
56                 do_IRQ(regs);
57                 break;
58         case SRR1_WAKEDEC:
59                 timer_interrupt(regs);
60                 break;
61         default:
62                 /* do system reset */
63                 return 0;
64         }
65
66         /* Set higher astate since we come out of power savings at 0 */
67         restore_astate(hard_smp_processor_id());
68
69         /* everything handled */
70         regs->msr |= MSR_RI;
71         return 1;
72 }
73
74 void __init pasemi_idle_init(void)
75 {
76 #ifndef CONFIG_PPC_PASEMI_CPUFREQ
77         printk(KERN_WARNING "No cpufreq driver, powersavings modes disabled\n");
78         current_mode = 0;
79 #endif
80
81         ppc_md.system_reset_exception = pasemi_system_reset_exception;
82         ppc_md.power_save = modes[current_mode].entry;
83         printk(KERN_INFO "Using PA6T idle loop (%s)\n", modes[current_mode].name);
84 }
85
86 static int __init idle_param(char *p)
87 {
88         int i;
89         for (i = 0; i < sizeof(modes)/sizeof(struct sleep_mode); i++) {
90                 if (!strcmp(modes[i].name, p)) {
91                         current_mode = i;
92                         break;
93                 }
94         }
95         return 0;
96 }
97
98 early_param("idle", idle_param);