fixed netfilter errors and missing dependencies
[htc-linux.git] / kernel / power / fbearlysuspend.c
blob83104fe4710381127aa64e3bb690d0aec3f32577
1 /* kernel/power/fbearlysuspend.c
3 * Copyright (C) 2005-2008 Google, Inc.
5 * This software is licensed under the terms of the GNU General Public
6 * License version 2, as published by the Free Software Foundation, and
7 * may be copied, distributed, and modified under those terms.
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
16 #include <linux/earlysuspend.h>
17 #include <linux/module.h>
18 #include <linux/wait.h>
20 #include "power.h"
22 static wait_queue_head_t fb_state_wq;
23 static DEFINE_SPINLOCK(fb_state_lock);
24 static enum {
25 FB_STATE_STOPPED_DRAWING,
26 FB_STATE_REQUEST_STOP_DRAWING,
27 FB_STATE_DRAWING_OK,
28 } fb_state;
30 /* tell userspace to stop drawing, wait for it to stop */
31 static void stop_drawing_early_suspend(struct early_suspend *h)
33 int ret;
34 unsigned long irq_flags;
36 spin_lock_irqsave(&fb_state_lock, irq_flags);
37 fb_state = FB_STATE_REQUEST_STOP_DRAWING;
38 spin_unlock_irqrestore(&fb_state_lock, irq_flags);
40 wake_up_all(&fb_state_wq);
41 ret = wait_event_timeout(fb_state_wq,
42 fb_state == FB_STATE_STOPPED_DRAWING,
43 HZ);
44 if (unlikely(fb_state != FB_STATE_STOPPED_DRAWING))
45 pr_warning("stop_drawing_early_suspend: timeout waiting for "
46 "userspace to stop drawing\n");
49 /* tell userspace to start drawing */
50 void start_drawing_late_resume(struct early_suspend *h)
52 unsigned long irq_flags;
54 spin_lock_irqsave(&fb_state_lock, irq_flags);
55 fb_state = FB_STATE_DRAWING_OK;
56 spin_unlock_irqrestore(&fb_state_lock, irq_flags);
57 wake_up(&fb_state_wq);
60 static struct early_suspend stop_drawing_early_suspend_desc = {
61 .level = EARLY_SUSPEND_LEVEL_STOP_DRAWING,
62 .suspend = stop_drawing_early_suspend,
63 .resume = start_drawing_late_resume,
66 static ssize_t wait_for_fb_sleep_show(struct kobject *kobj,
67 struct kobj_attribute *attr, char *buf)
69 char *s = buf;
70 int ret;
72 ret = wait_event_interruptible(fb_state_wq,
73 fb_state != FB_STATE_DRAWING_OK);
74 if (ret && fb_state == FB_STATE_DRAWING_OK)
75 return ret;
76 else
77 s += sprintf(buf, "sleeping");
78 return s - buf;
81 static ssize_t wait_for_fb_wake_show(struct kobject *kobj,
82 struct kobj_attribute *attr, char *buf)
84 char *s = buf;
85 int ret;
86 unsigned long irq_flags;
88 spin_lock_irqsave(&fb_state_lock, irq_flags);
89 if (fb_state == FB_STATE_REQUEST_STOP_DRAWING) {
90 fb_state = FB_STATE_STOPPED_DRAWING;
91 wake_up(&fb_state_wq);
93 spin_unlock_irqrestore(&fb_state_lock, irq_flags);
95 ret = wait_event_interruptible(fb_state_wq,
96 fb_state == FB_STATE_DRAWING_OK);
97 if (ret && fb_state != FB_STATE_DRAWING_OK)
98 return ret;
99 else
100 s += sprintf(buf, "awake");
102 return s - buf;
105 #define power_ro_attr(_name) \
106 static struct kobj_attribute _name##_attr = { \
107 .attr = { \
108 .name = __stringify(_name), \
109 .mode = 0444, \
110 }, \
111 .show = _name##_show, \
112 .store = NULL, \
115 power_ro_attr(wait_for_fb_sleep);
116 power_ro_attr(wait_for_fb_wake);
118 static struct attribute *g[] = {
119 &wait_for_fb_sleep_attr.attr,
120 &wait_for_fb_wake_attr.attr,
121 NULL,
124 static struct attribute_group attr_group = {
125 .attrs = g,
128 static int __init android_power_init(void)
130 int ret;
132 init_waitqueue_head(&fb_state_wq);
133 fb_state = FB_STATE_DRAWING_OK;
135 ret = sysfs_create_group(power_kobj, &attr_group);
136 if (ret) {
137 pr_err("android_power_init: sysfs_create_group failed\n");
138 return ret;
141 register_early_suspend(&stop_drawing_early_suspend_desc);
142 return 0;
145 static void __exit android_power_exit(void)
147 unregister_early_suspend(&stop_drawing_early_suspend_desc);
148 sysfs_remove_group(power_kobj, &attr_group);
151 module_init(android_power_init);
152 module_exit(android_power_exit);