]> www.pilppa.org Git - linux-2.6-omap-h63xx.git/blob - arch/arm/mach-omap2/pm.c
4652136de15f7150b61496d0bd190bb0e785cd1b
[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 <mach/cpu.h>
28 #include <asm/mach/time.h>
29 #include <asm/atomic.h>
30
31 #include <mach/pm.h>
32 #include "pm.h"
33
34 unsigned short enable_dyn_sleep;
35 unsigned short clocks_off_while_idle;
36 atomic_t sleep_block = ATOMIC_INIT(0);
37
38 static ssize_t idle_show(struct kobject *, struct kobj_attribute *, char *);
39 static ssize_t idle_store(struct kobject *k, struct kobj_attribute *,
40                           const char *buf, size_t n);
41
42 static struct kobj_attribute sleep_while_idle_attr =
43         __ATTR(sleep_while_idle, 0644, idle_show, idle_store);
44
45 static struct kobj_attribute clocks_off_while_idle_attr =
46         __ATTR(clocks_off_while_idle, 0644, idle_show, idle_store);
47
48 static ssize_t idle_show(struct kobject *kobj, struct kobj_attribute *attr,
49                          char *buf)
50 {
51         if (attr == &sleep_while_idle_attr)
52                 return sprintf(buf, "%hu\n", enable_dyn_sleep);
53         else if (attr == &clocks_off_while_idle_attr)
54                 return sprintf(buf, "%hu\n", clocks_off_while_idle);
55         else
56                 return -EINVAL;
57 }
58
59 static ssize_t idle_store(struct kobject *kobj, struct kobj_attribute *attr,
60                           const char *buf, size_t n)
61 {
62         unsigned short value;
63
64         if (sscanf(buf, "%hu", &value) != 1 ||
65             (value != 0 && value != 1)) {
66                 printk(KERN_ERR "idle_store: Invalid value\n");
67                 return -EINVAL;
68         }
69
70         if (attr == &sleep_while_idle_attr)
71                 enable_dyn_sleep = value;
72         else if (attr == &clocks_off_while_idle_attr)
73                 clocks_off_while_idle = value;
74         else
75                 return -EINVAL;
76
77         return n;
78 }
79
80 void omap2_block_sleep(void)
81 {
82         atomic_inc(&sleep_block);
83 }
84
85 void omap2_allow_sleep(void)
86 {
87         int i;
88
89         i = atomic_dec_return(&sleep_block);
90         BUG_ON(i < 0);
91 }
92
93 static int __init omap_pm_init(void)
94 {
95         int error = -1;
96
97         if (cpu_is_omap24xx())
98                 error = omap2_pm_init();
99         if (cpu_is_omap34xx())
100                 error = omap3_pm_init();
101         if (error) {
102                 printk(KERN_ERR "omap2|3_pm_init failed: %d\n", error);
103                 return error;
104         }
105
106         /* disabled till drivers are fixed */
107         enable_dyn_sleep = 0;
108         error = sysfs_create_file(power_kobj, &sleep_while_idle_attr.attr);
109         if (error)
110                 printk(KERN_ERR "sysfs_create_file failed: %d\n", error);
111         error = sysfs_create_file(power_kobj,
112                                   &clocks_off_while_idle_attr.attr);
113         if (error)
114                 printk(KERN_ERR "sysfs_create_file failed: %d\n", error);
115
116         return error;
117 }
118
119 late_initcall(omap_pm_init);