]> www.pilppa.org Git - linux-2.6-omap-h63xx.git/blob - arch/arm/mach-omap2/pm.c
34XX: PM: Initial version of suspend and dynamic retention
[linux-2.6-omap-h63xx.git] / arch / arm / mach-omap2 / pm.c
1 /*
2  * linux/arch/arm/mach-omap2/pm.c
3  *
4  * OMAP Power Management Common Routines
5  *
6  * Copyright (C) 2005 Texas Instruments, Inc.
7  * Copyright (C) 2006-2008 Nokia Corporation
8  *
9  * Written by:
10  * Richard Woodruff <r-woodruff2@ti.com>
11  * Tony Lindgren
12  * Juha Yrjola
13  * Amit Kucheria <amit.kucheria@nokia.com>
14  * Igor Stoppa <igor.stoppa@nokia.com>
15  * Jouni Hogander
16  *
17  * Based on pm.c for omap1
18  *
19  * This program is free software; you can redistribute it and/or modify
20  * it under the terms of the GNU General Public License version 2 as
21  * published by the Free Software Foundation.
22  */
23
24 #include <linux/suspend.h>
25 #include <linux/time.h>
26
27 #include <asm/arch/cpu.h>
28 #include <asm/mach/time.h>
29 #include <asm/atomic.h>
30
31 #include "pm.h"
32
33 unsigned short enable_dyn_sleep;
34 atomic_t sleep_block = ATOMIC_INIT(0);
35
36 static ssize_t idle_show(struct kobject *kobj, struct kobj_attribute *attr,
37                          char *buf)
38 {
39         return sprintf(buf, "%hu\n", enable_dyn_sleep);
40 }
41
42 static ssize_t idle_store(struct kobject *kobj, struct kobj_attribute *attr,
43                           const char *buf, size_t n)
44 {
45         unsigned short value;
46         if (sscanf(buf, "%hu", &value) != 1 ||
47             (value != 0 && value != 1)) {
48                 printk(KERN_ERR "idle_sleep_store: Invalid value\n");
49                 return -EINVAL;
50         }
51         enable_dyn_sleep = value;
52         return n;
53 }
54
55 static struct kobj_attribute sleep_while_idle_attr =
56         __ATTR(sleep_while_idle, 0644, idle_show, idle_store);
57
58 void omap2_block_sleep(void)
59 {
60         atomic_inc(&sleep_block);
61 }
62
63 void omap2_allow_sleep(void)
64 {
65         int i;
66
67         i = atomic_dec_return(&sleep_block);
68         BUG_ON(i < 0);
69 }
70
71 int __init omap_pm_init(void)
72 {
73         int error = -1;
74
75         if (cpu_is_omap24xx())
76                 error = omap2_pm_init();
77         if (cpu_is_omap34xx())
78                 error = omap3_pm_init();
79         if (error) {
80                 printk(KERN_ERR "omap2|3_pm_init failed: %d\n", error);
81                 return error;
82         }
83
84         /* disabled till drivers are fixed */
85         enable_dyn_sleep = 0;
86         error = sysfs_create_file(power_kobj, &sleep_while_idle_attr.attr);
87         if (error)
88                 printk(KERN_ERR "sysfs_create_file failed: %d\n", error);
89
90         return error;
91 }
92
93 late_initcall(omap_pm_init);