fixed netfilter errors and missing dependencies
[htc-linux.git] / kernel / power / main.c
blobfab47ca3fa6ba15070a4e2d0d9452c918f4cf770
1 /*
2 * kernel/power/main.c - PM subsystem core functionality.
4 * Copyright (c) 2003 Patrick Mochel
5 * Copyright (c) 2003 Open Source Development Lab
6 *
7 * This file is released under the GPLv2
9 */
11 #include <linux/kobject.h>
12 #include <linux/string.h>
13 #include <linux/resume-trace.h>
14 #include <linux/workqueue.h>
16 #include "power.h"
18 DEFINE_MUTEX(pm_mutex);
20 unsigned int pm_flags;
21 EXPORT_SYMBOL(pm_flags);
23 #ifdef CONFIG_PM_SLEEP
25 /* Routines for PM-transition notifications */
27 static BLOCKING_NOTIFIER_HEAD(pm_chain_head);
29 int register_pm_notifier(struct notifier_block *nb)
31 return blocking_notifier_chain_register(&pm_chain_head, nb);
33 EXPORT_SYMBOL_GPL(register_pm_notifier);
35 int unregister_pm_notifier(struct notifier_block *nb)
37 return blocking_notifier_chain_unregister(&pm_chain_head, nb);
39 EXPORT_SYMBOL_GPL(unregister_pm_notifier);
41 int pm_notifier_call_chain(unsigned long val)
43 return (blocking_notifier_call_chain(&pm_chain_head, val, NULL)
44 == NOTIFY_BAD) ? -EINVAL : 0;
47 #ifdef CONFIG_PM_DEBUG
48 int pm_test_level = TEST_NONE;
50 static const char * const pm_tests[__TEST_AFTER_LAST] = {
51 [TEST_NONE] = "none",
52 [TEST_CORE] = "core",
53 [TEST_CPUS] = "processors",
54 [TEST_PLATFORM] = "platform",
55 [TEST_DEVICES] = "devices",
56 [TEST_FREEZER] = "freezer",
59 static ssize_t pm_test_show(struct kobject *kobj, struct kobj_attribute *attr,
60 char *buf)
62 char *s = buf;
63 int level;
65 for (level = TEST_FIRST; level <= TEST_MAX; level++)
66 if (pm_tests[level]) {
67 if (level == pm_test_level)
68 s += sprintf(s, "[%s] ", pm_tests[level]);
69 else
70 s += sprintf(s, "%s ", pm_tests[level]);
73 if (s != buf)
74 /* convert the last space to a newline */
75 *(s-1) = '\n';
77 return (s - buf);
80 static ssize_t pm_test_store(struct kobject *kobj, struct kobj_attribute *attr,
81 const char *buf, size_t n)
83 const char * const *s;
84 int level;
85 char *p;
86 int len;
87 int error = -EINVAL;
89 p = memchr(buf, '\n', n);
90 len = p ? p - buf : n;
92 mutex_lock(&pm_mutex);
94 level = TEST_FIRST;
95 for (s = &pm_tests[level]; level <= TEST_MAX; s++, level++)
96 if (*s && len == strlen(*s) && !strncmp(buf, *s, len)) {
97 pm_test_level = level;
98 error = 0;
99 break;
102 mutex_unlock(&pm_mutex);
104 return error ? error : n;
107 power_attr(pm_test);
108 #endif /* CONFIG_PM_DEBUG */
110 #endif /* CONFIG_PM_SLEEP */
112 struct kobject *power_kobj;
115 * state - control system power state.
117 * show() returns what states are supported, which is hard-coded to
118 * 'standby' (Power-On Suspend), 'mem' (Suspend-to-RAM), and
119 * 'disk' (Suspend-to-Disk).
121 * store() accepts one of those strings, translates it into the
122 * proper enumerated value, and initiates a suspend transition.
124 static ssize_t state_show(struct kobject *kobj, struct kobj_attribute *attr,
125 char *buf)
127 char *s = buf;
128 #ifdef CONFIG_SUSPEND
129 int i;
131 for (i = 0; i < PM_SUSPEND_MAX; i++) {
132 if (pm_states[i] && valid_state(i))
133 s += sprintf(s,"%s ", pm_states[i]);
135 #endif
136 #ifdef CONFIG_HIBERNATION
137 s += sprintf(s, "%s\n", "disk");
138 #else
139 if (s != buf)
140 /* convert the last space to a newline */
141 *(s-1) = '\n';
142 #endif
143 return (s - buf);
146 static ssize_t state_store(struct kobject *kobj, struct kobj_attribute *attr,
147 const char *buf, size_t n)
149 #ifdef CONFIG_SUSPEND
150 #ifdef CONFIG_EARLYSUSPEND
151 suspend_state_t state = PM_SUSPEND_ON;
152 #else
153 suspend_state_t state = PM_SUSPEND_STANDBY;
154 #endif
155 const char * const *s;
156 #endif
157 char *p;
158 int len;
159 int error = -EINVAL;
161 p = memchr(buf, '\n', n);
162 len = p ? p - buf : n;
164 /* First, check if we are requested to hibernate */
165 if (len == 4 && !strncmp(buf, "disk", len)) {
166 error = hibernate();
167 goto Exit;
170 #ifdef CONFIG_SUSPEND
171 for (s = &pm_states[state]; state < PM_SUSPEND_MAX; s++, state++) {
172 if (*s && len == strlen(*s) && !strncmp(buf, *s, len))
173 break;
175 if (state < PM_SUSPEND_MAX && *s)
176 #ifdef CONFIG_EARLYSUSPEND
177 if (state == PM_SUSPEND_ON || valid_state(state)) {
178 error = 0;
179 request_suspend_state(state);
181 #else
182 error = enter_state(state);
183 #endif
184 #endif
186 Exit:
187 return error ? error : n;
190 power_attr(state);
192 #ifdef CONFIG_PM_TRACE
193 int pm_trace_enabled;
195 static ssize_t pm_trace_show(struct kobject *kobj, struct kobj_attribute *attr,
196 char *buf)
198 return sprintf(buf, "%d\n", pm_trace_enabled);
201 static ssize_t
202 pm_trace_store(struct kobject *kobj, struct kobj_attribute *attr,
203 const char *buf, size_t n)
205 int val;
207 if (sscanf(buf, "%d", &val) == 1) {
208 pm_trace_enabled = !!val;
209 return n;
211 return -EINVAL;
215 power_attr(pm_trace);
217 int pm_trace_mask;
218 static ssize_t
219 pm_trace_mask_show(struct kobject *kobj, struct kobj_attribute *attr,
220 char *buf)
222 return sprintf(buf, "%d\n", pm_trace_mask);
225 static ssize_t
226 pm_trace_mask_store(struct kobject *kobj, struct kobj_attribute *attr,
227 const char *buf, size_t n)
229 int val;
231 if (sscanf(buf, "%d", &val) > 0) {
232 pm_trace_mask = val;
233 return n;
235 return -EINVAL;
239 power_attr(pm_trace_mask);
240 #endif /* CONFIG_PM_TRACE */
242 #ifdef CONFIG_USER_WAKELOCK
243 power_attr(wake_lock);
244 power_attr(wake_unlock);
245 #endif
247 static struct attribute * g[] = {
248 &state_attr.attr,
249 #ifdef CONFIG_PM_TRACE
250 &pm_trace_attr.attr,
251 &pm_trace_mask_attr.attr,
252 #endif
253 #if defined(CONFIG_PM_SLEEP) && defined(CONFIG_PM_DEBUG)
254 &pm_test_attr.attr,
255 #endif
256 #ifdef CONFIG_USER_WAKELOCK
257 &wake_lock_attr.attr,
258 &wake_unlock_attr.attr,
259 #endif
260 NULL,
263 static struct attribute_group attr_group = {
264 .attrs = g,
267 #ifdef CONFIG_PM_RUNTIME
268 struct workqueue_struct *pm_wq;
270 static int __init pm_start_workqueue(void)
272 pm_wq = create_freezeable_workqueue("pm");
274 return pm_wq ? 0 : -ENOMEM;
276 #else
277 static inline int pm_start_workqueue(void) { return 0; }
278 #endif
280 static int __init pm_init(void)
282 int error = pm_start_workqueue();
283 if (error)
284 return error;
285 power_kobj = kobject_create_and_add("power", NULL);
286 if (!power_kobj)
287 return -ENOMEM;
288 return sysfs_create_group(power_kobj, &attr_group);
291 core_initcall(pm_init);