GUI: Fix Tomato RAF theme for all builds. Compilation typo.
[tomato.git] / release / src-rt-6.x.4708 / linux / linux-2.6.36 / arch / frv / kernel / pm.c
blobbb7fe5eff1261c475763605049a1d993727a655c
1 /*
2 * FR-V Power Management Routines
4 * Copyright (c) 2004 Red Hat, Inc.
6 * Based on SA1100 version:
7 * Copyright (c) 2001 Cliff Brake <cbrake@accelent.com>
9 * This program is free software; you can redistribute it and/or
10 * modify it under the terms of the GNU General Public License.
14 #include <linux/init.h>
15 #include <linux/module.h>
16 #include <linux/pm.h>
17 #include <linux/sched.h>
18 #include <linux/interrupt.h>
19 #include <linux/sysctl.h>
20 #include <linux/errno.h>
21 #include <linux/delay.h>
22 #include <asm/uaccess.h>
24 #include <asm/mb86943a.h>
26 #include "local.h"
29 * Debug macros
31 #define DEBUG
33 int pm_do_suspend(void)
35 local_irq_disable();
37 __set_LEDS(0xb1);
39 /* go zzz */
40 frv_cpu_suspend(pdm_suspend_mode);
42 __set_LEDS(0xb2);
44 local_irq_enable();
46 return 0;
49 static unsigned long __irq_mask;
52 * Setup interrupt masks, etc to enable wakeup by power switch
54 static void __default_power_switch_setup(void)
56 /* default is to mask all interrupt sources. */
57 __irq_mask = *(unsigned long *)0xfeff9820;
58 *(unsigned long *)0xfeff9820 = 0xfffe0000;
62 * Cleanup interrupt masks, etc after wakeup by power switch
64 static void __default_power_switch_cleanup(void)
66 *(unsigned long *)0xfeff9820 = __irq_mask;
70 * Return non-zero if wakeup irq was caused by power switch
72 static int __default_power_switch_check(void)
74 return 1;
77 void (*__power_switch_wake_setup)(void) = __default_power_switch_setup;
78 int (*__power_switch_wake_check)(void) = __default_power_switch_check;
79 void (*__power_switch_wake_cleanup)(void) = __default_power_switch_cleanup;
81 int pm_do_bus_sleep(void)
83 local_irq_disable();
86 * Here is where we need some platform-dependent setup
87 * of the interrupt state so that appropriate wakeup
88 * sources are allowed and all others are masked.
90 __power_switch_wake_setup();
92 __set_LEDS(0xa1);
94 /* go zzz
96 * This is in a loop in case power switch shares an irq with other
97 * devices. The wake_check() tells us if we need to finish waking
98 * or go back to sleep.
100 do {
101 frv_cpu_suspend(HSR0_PDM_BUS_SLEEP);
102 } while (__power_switch_wake_check && !__power_switch_wake_check());
104 __set_LEDS(0xa2);
107 * Here is where we need some platform-dependent restore
108 * of the interrupt state prior to being called.
110 __power_switch_wake_cleanup();
112 local_irq_enable();
114 return 0;
117 unsigned long sleep_phys_sp(void *sp)
119 return virt_to_phys(sp);
122 #ifdef CONFIG_SYSCTL
124 * Use a temporary sysctl number. Horrid, but will be cleaned up in 2.6
125 * when all the PM interfaces exist nicely.
127 #define CTL_PM_SUSPEND 1
128 #define CTL_PM_CMODE 2
129 #define CTL_PM_P0 4
130 #define CTL_PM_CM 5
132 static int user_atoi(char __user *ubuf, size_t len)
134 char buf[16];
135 unsigned long ret;
137 if (len > 15)
138 return -EINVAL;
140 if (copy_from_user(buf, ubuf, len))
141 return -EFAULT;
143 buf[len] = 0;
144 ret = simple_strtoul(buf, NULL, 0);
145 if (ret > INT_MAX)
146 return -ERANGE;
147 return ret;
151 * Send us to sleep.
153 static int sysctl_pm_do_suspend(ctl_table *ctl, int write,
154 void __user *buffer, size_t *lenp, loff_t *fpos)
156 int retval, mode;
158 if (*lenp <= 0)
159 return -EIO;
161 mode = user_atoi(buffer, *lenp);
162 if ((mode != 1) && (mode != 5))
163 return -EINVAL;
165 if (retval == 0) {
166 if (mode == 5)
167 retval = pm_do_bus_sleep();
168 else
169 retval = pm_do_suspend();
172 return retval;
175 static int try_set_cmode(int new_cmode)
177 if (new_cmode > 15)
178 return -EINVAL;
179 if (!(clock_cmodes_permitted & (1<<new_cmode)))
180 return -EINVAL;
182 /* now change cmode */
183 local_irq_disable();
184 frv_dma_pause_all();
186 frv_change_cmode(new_cmode);
188 determine_clocks(0);
189 time_divisor_init();
191 #ifdef DEBUG
192 determine_clocks(1);
193 #endif
194 frv_dma_resume_all();
195 local_irq_enable();
197 return 0;
201 static int cmode_procctl(ctl_table *ctl, int write,
202 void __user *buffer, size_t *lenp, loff_t *fpos)
204 int new_cmode;
206 if (!write)
207 return proc_dointvec(ctl, write, buffer, lenp, fpos);
209 new_cmode = user_atoi(buffer, *lenp);
211 return try_set_cmode(new_cmode)?:*lenp;
214 static int try_set_p0(int new_p0)
216 unsigned long flags, clkc;
218 if (new_p0 < 0 || new_p0 > 1)
219 return -EINVAL;
221 local_irq_save(flags);
222 __set_PSR(flags & ~PSR_ET);
224 frv_dma_pause_all();
226 clkc = __get_CLKC();
227 if (new_p0)
228 clkc |= CLKC_P0;
229 else
230 clkc &= ~CLKC_P0;
231 __set_CLKC(clkc);
233 determine_clocks(0);
234 time_divisor_init();
236 #ifdef DEBUG
237 determine_clocks(1);
238 #endif
239 frv_dma_resume_all();
240 local_irq_restore(flags);
241 return 0;
244 static int try_set_cm(int new_cm)
246 unsigned long flags, clkc;
248 if (new_cm < 0 || new_cm > 1)
249 return -EINVAL;
251 local_irq_save(flags);
252 __set_PSR(flags & ~PSR_ET);
254 frv_dma_pause_all();
256 clkc = __get_CLKC();
257 clkc &= ~CLKC_CM;
258 clkc |= new_cm;
259 __set_CLKC(clkc);
261 determine_clocks(0);
262 time_divisor_init();
264 determine_clocks(1);
266 frv_dma_resume_all();
267 local_irq_restore(flags);
268 return 0;
271 static int p0_procctl(ctl_table *ctl, int write,
272 void __user *buffer, size_t *lenp, loff_t *fpos)
274 int new_p0;
276 if (!write)
277 return proc_dointvec(ctl, write, buffer, lenp, fpos);
279 new_p0 = user_atoi(buffer, *lenp);
281 return try_set_p0(new_p0)?:*lenp;
284 static int cm_procctl(ctl_table *ctl, int write,
285 void __user *buffer, size_t *lenp, loff_t *fpos)
287 int new_cm;
289 if (!write)
290 return proc_dointvec(ctl, write, buffer, lenp, fpos);
292 new_cm = user_atoi(buffer, *lenp);
294 return try_set_cm(new_cm)?:*lenp;
297 static struct ctl_table pm_table[] =
300 .procname = "suspend",
301 .data = NULL,
302 .maxlen = 0,
303 .mode = 0200,
304 .proc_handler = sysctl_pm_do_suspend,
307 .procname = "cmode",
308 .data = &clock_cmode_current,
309 .maxlen = sizeof(int),
310 .mode = 0644,
311 .proc_handler = cmode_procctl,
314 .procname = "p0",
315 .data = &clock_p0_current,
316 .maxlen = sizeof(int),
317 .mode = 0644,
318 .proc_handler = p0_procctl,
321 .procname = "cm",
322 .data = &clock_cm_current,
323 .maxlen = sizeof(int),
324 .mode = 0644,
325 .proc_handler = cm_procctl,
330 static struct ctl_table pm_dir_table[] =
333 .procname = "pm",
334 .mode = 0555,
335 .child = pm_table,
341 * Initialize power interface
343 static int __init pm_init(void)
345 register_sysctl_table(pm_dir_table);
346 return 0;
349 __initcall(pm_init);
351 #endif