blob: 84e1ae63bb8c5aea8e020bb53ac95184c87a638f [file] [log] [blame]
Linus Torvalds1da177e2005-04-16 15:20:36 -07001/*
2 * kernel/power/main.c - PM subsystem core functionality.
3 *
4 * Copyright (c) 2003 Patrick Mochel
5 * Copyright (c) 2003 Open Source Development Lab
6 *
7 * This file is released under the GPLv2
8 *
9 */
10
Ralf Baechle4cf30342006-12-06 20:36:06 -080011#include <linux/module.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070012#include <linux/suspend.h>
13#include <linux/kobject.h>
14#include <linux/string.h>
15#include <linux/delay.h>
16#include <linux/errno.h>
17#include <linux/init.h>
Andrew Morton6cc07192006-06-22 14:47:18 -070018#include <linux/console.h>
Rafael J. Wysockie3920fb2006-09-25 23:32:48 -070019#include <linux/cpu.h>
Rafael J. Wysockic5c6ba42006-09-25 23:32:58 -070020#include <linux/resume-trace.h>
Nigel Cunningham7dfb7102006-12-06 20:34:23 -080021#include <linux/freezer.h>
Christoph Lameter96177292007-02-10 01:43:03 -080022#include <linux/vmstat.h>
Rafael J. Wysocki232b1432007-10-18 03:04:44 -070023#include <linux/syscalls.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070024
25#include "power.h"
26
Rafael J. Wysockib10d9112007-07-19 01:47:36 -070027BLOCKING_NOTIFIER_HEAD(pm_chain_head);
28
Stephen Hemmingera6d70982006-12-06 20:34:35 -080029DEFINE_MUTEX(pm_mutex);
Linus Torvalds1da177e2005-04-16 15:20:36 -070030
Len Brown9f9adec2007-12-13 17:38:03 -050031unsigned int pm_flags;
32EXPORT_SYMBOL(pm_flags);
33
Rafael J. Wysocki0e7d56e2007-11-19 23:41:19 +010034#ifdef CONFIG_PM_DEBUG
35int pm_test_level = TEST_NONE;
36
37static int suspend_test(int level)
38{
39 if (pm_test_level == level) {
40 printk(KERN_INFO "suspend debug: Waiting for 5 seconds.\n");
41 mdelay(5000);
42 return 1;
43 }
44 return 0;
45}
46
47static const char * const pm_tests[__TEST_AFTER_LAST] = {
48 [TEST_NONE] = "none",
49 [TEST_CORE] = "core",
50 [TEST_CPUS] = "processors",
51 [TEST_PLATFORM] = "platform",
52 [TEST_DEVICES] = "devices",
53 [TEST_FREEZER] = "freezer",
54};
55
56static ssize_t pm_test_show(struct kset *kset, char *buf)
57{
58 char *s = buf;
59 int level;
60
61 for (level = TEST_FIRST; level <= TEST_MAX; level++)
62 if (pm_tests[level]) {
63 if (level == pm_test_level)
64 s += sprintf(s, "[%s] ", pm_tests[level]);
65 else
66 s += sprintf(s, "%s ", pm_tests[level]);
67 }
68
69 if (s != buf)
70 /* convert the last space to a newline */
71 *(s-1) = '\n';
72
73 return (s - buf);
74}
75
76static ssize_t pm_test_store(struct kset *kset, const char *buf, size_t n)
77{
78 const char * const *s;
79 int level;
80 char *p;
81 int len;
82 int error = -EINVAL;
83
84 p = memchr(buf, '\n', n);
85 len = p ? p - buf : n;
86
87 mutex_lock(&pm_mutex);
88
89 level = TEST_FIRST;
90 for (s = &pm_tests[level]; level <= TEST_MAX; s++, level++)
91 if (*s && len == strlen(*s) && !strncmp(buf, *s, len)) {
92 pm_test_level = level;
93 error = 0;
94 break;
95 }
96
97 mutex_unlock(&pm_mutex);
98
99 return error ? error : n;
100}
101
102power_attr(pm_test);
103#else /* !CONFIG_PM_DEBUG */
104static inline int suspend_test(int level) { return 0; }
105#endif /* !CONFIG_PM_DEBUG */
106
Rafael J. Wysocki296699d2007-07-29 23:27:18 +0200107#ifdef CONFIG_SUSPEND
108
109/* This is just an arbitrary number */
110#define FREE_PAGE_NUMBER (100)
111
Rafael J. Wysockif242d912007-10-18 03:04:41 -0700112static struct platform_suspend_ops *suspend_ops;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700113
114/**
Rafael J. Wysocki26398a72007-10-18 03:04:40 -0700115 * suspend_set_ops - Set the global suspend method table.
Linus Torvalds1da177e2005-04-16 15:20:36 -0700116 * @ops: Pointer to ops structure.
117 */
118
Rafael J. Wysocki26398a72007-10-18 03:04:40 -0700119void suspend_set_ops(struct platform_suspend_ops *ops)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700120{
Stephen Hemmingera6d70982006-12-06 20:34:35 -0800121 mutex_lock(&pm_mutex);
Rafael J. Wysocki26398a72007-10-18 03:04:40 -0700122 suspend_ops = ops;
Stephen Hemmingera6d70982006-12-06 20:34:35 -0800123 mutex_unlock(&pm_mutex);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700124}
125
Johannes Berge8c9c502007-04-30 15:09:54 -0700126/**
Rafael J. Wysocki26398a72007-10-18 03:04:40 -0700127 * suspend_valid_only_mem - generic memory-only valid callback
Johannes Berge8c9c502007-04-30 15:09:54 -0700128 *
Rafael J. Wysocki26398a72007-10-18 03:04:40 -0700129 * Platform drivers that implement mem suspend only and only need
Johannes Berge8c9c502007-04-30 15:09:54 -0700130 * to check for that in their .valid callback can use this instead
131 * of rolling their own .valid callback.
132 */
Rafael J. Wysocki26398a72007-10-18 03:04:40 -0700133int suspend_valid_only_mem(suspend_state_t state)
Johannes Berge8c9c502007-04-30 15:09:54 -0700134{
135 return state == PM_SUSPEND_MEM;
136}
137
Linus Torvalds1da177e2005-04-16 15:20:36 -0700138/**
139 * suspend_prepare - Do prep work before entering low-power state.
Linus Torvalds1da177e2005-04-16 15:20:36 -0700140 *
Rafael J. Wysocki6c961df2007-07-19 01:47:38 -0700141 * This is common code that is called for each state that we're entering.
142 * Run suspend notifiers, allocate a console and stop all processes.
Linus Torvalds1da177e2005-04-16 15:20:36 -0700143 */
Rafael J. Wysocki6c961df2007-07-19 01:47:38 -0700144static int suspend_prepare(void)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700145{
Rafael J. Wysockie3920fb2006-09-25 23:32:48 -0700146 int error;
David Shaohua Li5ae947e2005-03-18 16:27:13 -0500147 unsigned int free_pages;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700148
Rafael J. Wysocki26398a72007-10-18 03:04:40 -0700149 if (!suspend_ops || !suspend_ops->enter)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700150 return -EPERM;
151
Rafael J. Wysockib10d9112007-07-19 01:47:36 -0700152 error = pm_notifier_call_chain(PM_SUSPEND_PREPARE);
153 if (error)
154 goto Finish;
155
Linus Torvalds1da177e2005-04-16 15:20:36 -0700156 pm_prepare_console();
157
158 if (freeze_processes()) {
159 error = -EAGAIN;
160 goto Thaw;
161 }
162
Rafael J. Wysocki6c961df2007-07-19 01:47:38 -0700163 free_pages = global_page_state(NR_FREE_PAGES);
164 if (free_pages < FREE_PAGE_NUMBER) {
David Shaohua Li5ae947e2005-03-18 16:27:13 -0500165 pr_debug("PM: free some memory\n");
166 shrink_all_memory(FREE_PAGE_NUMBER - free_pages);
167 if (nr_free_pages() < FREE_PAGE_NUMBER) {
168 error = -ENOMEM;
169 printk(KERN_ERR "PM: No enough memory\n");
David Shaohua Li5ae947e2005-03-18 16:27:13 -0500170 }
171 }
Rafael J. Wysockie3c7db622007-02-10 01:43:31 -0800172 if (!error)
173 return 0;
174
Linus Torvalds1da177e2005-04-16 15:20:36 -0700175 Thaw:
176 thaw_processes();
177 pm_restore_console();
Rafael J. Wysockib10d9112007-07-19 01:47:36 -0700178 Finish:
179 pm_notifier_call_chain(PM_POST_SUSPEND);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700180 return error;
181}
182
Johannes Berga53c46d2007-04-26 11:43:58 +0200183/* default implementation */
184void __attribute__ ((weak)) arch_suspend_disable_irqs(void)
185{
186 local_irq_disable();
187}
188
189/* default implementation */
190void __attribute__ ((weak)) arch_suspend_enable_irqs(void)
191{
192 local_irq_enable();
193}
Linus Torvalds1da177e2005-04-16 15:20:36 -0700194
Rafael J. Wysocki6c961df2007-07-19 01:47:38 -0700195/**
196 * suspend_enter - enter the desired system sleep state.
197 * @state: state to enter
198 *
199 * This function should be called after devices have been suspended.
200 */
Adrian Bunka065c862007-10-18 03:04:37 -0700201static int suspend_enter(suspend_state_t state)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700202{
203 int error = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700204
Johannes Berga53c46d2007-04-26 11:43:58 +0200205 arch_suspend_disable_irqs();
206 BUG_ON(!irqs_disabled());
Linus Torvalds1da177e2005-04-16 15:20:36 -0700207
208 if ((error = device_power_down(PMSG_SUSPEND))) {
209 printk(KERN_ERR "Some devices failed to power down\n");
210 goto Done;
211 }
Rafael J. Wysocki0e7d56e2007-11-19 23:41:19 +0100212
213 if (!suspend_test(TEST_CORE))
214 error = suspend_ops->enter(state);
215
Linus Torvalds1da177e2005-04-16 15:20:36 -0700216 device_power_up();
217 Done:
Johannes Berga53c46d2007-04-26 11:43:58 +0200218 arch_suspend_enable_irqs();
219 BUG_ON(irqs_disabled());
Linus Torvalds1da177e2005-04-16 15:20:36 -0700220 return error;
221}
222
Rafael J. Wysocki6c961df2007-07-19 01:47:38 -0700223/**
224 * suspend_devices_and_enter - suspend devices and enter the desired system sleep
225 * state.
226 * @state: state to enter
227 */
228int suspend_devices_and_enter(suspend_state_t state)
229{
230 int error;
231
Rafael J. Wysocki26398a72007-10-18 03:04:40 -0700232 if (!suspend_ops)
Rafael J. Wysocki6c961df2007-07-19 01:47:38 -0700233 return -ENOSYS;
234
Rafael J. Wysocki26398a72007-10-18 03:04:40 -0700235 if (suspend_ops->set_target) {
236 error = suspend_ops->set_target(state);
Rafael J. Wysocki6c961df2007-07-19 01:47:38 -0700237 if (error)
238 return error;
239 }
240 suspend_console();
241 error = device_suspend(PMSG_SUSPEND);
242 if (error) {
243 printk(KERN_ERR "Some devices failed to suspend\n");
244 goto Resume_console;
245 }
Rafael J. Wysocki0e7d56e2007-11-19 23:41:19 +0100246
247 if (suspend_test(TEST_DEVICES))
248 goto Resume_devices;
249
Rafael J. Wysocki26398a72007-10-18 03:04:40 -0700250 if (suspend_ops->prepare) {
Rafael J. Wysockie6c5eb92007-10-18 03:04:41 -0700251 error = suspend_ops->prepare();
Rafael J. Wysocki6c961df2007-07-19 01:47:38 -0700252 if (error)
253 goto Resume_devices;
254 }
Rafael J. Wysocki0e7d56e2007-11-19 23:41:19 +0100255
256 if (suspend_test(TEST_PLATFORM))
257 goto Finish;
258
Rafael J. Wysocki6c961df2007-07-19 01:47:38 -0700259 error = disable_nonboot_cpus();
Rafael J. Wysocki0e7d56e2007-11-19 23:41:19 +0100260 if (!error && !suspend_test(TEST_CPUS))
Rafael J. Wysocki6c961df2007-07-19 01:47:38 -0700261 suspend_enter(state);
262
263 enable_nonboot_cpus();
Rafael J. Wysocki0e7d56e2007-11-19 23:41:19 +0100264 Finish:
Rafael J. Wysockie6c5eb92007-10-18 03:04:41 -0700265 if (suspend_ops->finish)
266 suspend_ops->finish();
Rafael J. Wysocki6c961df2007-07-19 01:47:38 -0700267 Resume_devices:
268 device_resume();
269 Resume_console:
270 resume_console();
271 return error;
272}
Linus Torvalds1da177e2005-04-16 15:20:36 -0700273
274/**
275 * suspend_finish - Do final work before exiting suspend sequence.
Linus Torvalds1da177e2005-04-16 15:20:36 -0700276 *
277 * Call platform code to clean up, restart processes, and free the
278 * console that we've allocated. This is not called for suspend-to-disk.
279 */
Rafael J. Wysocki6c961df2007-07-19 01:47:38 -0700280static void suspend_finish(void)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700281{
Linus Torvalds1da177e2005-04-16 15:20:36 -0700282 thaw_processes();
283 pm_restore_console();
Rafael J. Wysockib10d9112007-07-19 01:47:36 -0700284 pm_notifier_call_chain(PM_POST_SUSPEND);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700285}
286
287
288
289
Andreas Mohr3b364b82006-06-25 05:47:56 -0700290static const char * const pm_states[PM_SUSPEND_MAX] = {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700291 [PM_SUSPEND_STANDBY] = "standby",
292 [PM_SUSPEND_MEM] = "mem",
Linus Torvalds1da177e2005-04-16 15:20:36 -0700293};
294
Pavel Machek123d3c12005-11-29 19:34:37 -0800295static inline int valid_state(suspend_state_t state)
296{
Rafael J. Wysockia3d25c22007-05-09 02:33:18 -0700297 /* All states need lowlevel support and need to be valid
298 * to the lowlevel implementation, no valid callback
Johannes Berg9684e512007-04-30 15:09:55 -0700299 * implies that none are valid. */
Rafael J. Wysocki26398a72007-10-18 03:04:40 -0700300 if (!suspend_ops || !suspend_ops->valid || !suspend_ops->valid(state))
Pavel Machek123d3c12005-11-29 19:34:37 -0800301 return 0;
302 return 1;
303}
304
Linus Torvalds1da177e2005-04-16 15:20:36 -0700305
306/**
307 * enter_state - Do common work of entering low-power state.
308 * @state: pm_state structure for state we're entering.
309 *
310 * Make sure we're the only ones trying to enter a sleep state. Fail
311 * if someone has beat us to it, since we don't want anything weird to
312 * happen when we wake up.
313 * Then, do the setup for suspend, enter the state, and cleaup (after
314 * we've woken up).
315 */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700316static int enter_state(suspend_state_t state)
317{
318 int error;
319
Pavel Machek123d3c12005-11-29 19:34:37 -0800320 if (!valid_state(state))
Shaohua Lieb9289e2005-10-30 15:00:01 -0800321 return -ENODEV;
Rafael J. Wysocki232b1432007-10-18 03:04:44 -0700322
Stephen Hemmingera6d70982006-12-06 20:34:35 -0800323 if (!mutex_trylock(&pm_mutex))
Linus Torvalds1da177e2005-04-16 15:20:36 -0700324 return -EBUSY;
325
Rafael J. Wysocki232b1432007-10-18 03:04:44 -0700326 printk("Syncing filesystems ... ");
327 sys_sync();
328 printk("done.\n");
329
David Brownell82428b62005-05-09 08:07:00 -0700330 pr_debug("PM: Preparing system for %s sleep\n", pm_states[state]);
Rafael J. Wysocki0e7d56e2007-11-19 23:41:19 +0100331 error = suspend_prepare();
332 if (error)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700333 goto Unlock;
334
Rafael J. Wysocki0e7d56e2007-11-19 23:41:19 +0100335 if (suspend_test(TEST_FREEZER))
336 goto Finish;
337
David Brownell82428b62005-05-09 08:07:00 -0700338 pr_debug("PM: Entering %s sleep\n", pm_states[state]);
Rafael J. Wysocki6c961df2007-07-19 01:47:38 -0700339 error = suspend_devices_and_enter(state);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700340
Rafael J. Wysocki0e7d56e2007-11-19 23:41:19 +0100341 Finish:
David Brownell82428b62005-05-09 08:07:00 -0700342 pr_debug("PM: Finishing wakeup.\n");
Rafael J. Wysocki6c961df2007-07-19 01:47:38 -0700343 suspend_finish();
Linus Torvalds1da177e2005-04-16 15:20:36 -0700344 Unlock:
Stephen Hemmingera6d70982006-12-06 20:34:35 -0800345 mutex_unlock(&pm_mutex);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700346 return error;
347}
348
Linus Torvalds1da177e2005-04-16 15:20:36 -0700349
350/**
351 * pm_suspend - Externally visible function for suspending system.
Rafael J. Wysockia3d25c22007-05-09 02:33:18 -0700352 * @state: Enumerated value of state to enter.
Linus Torvalds1da177e2005-04-16 15:20:36 -0700353 *
354 * Determine whether or not value is within range, get state
355 * structure, and enter (above).
356 */
357
358int pm_suspend(suspend_state_t state)
359{
Alexey Starikovskiye2a5b422005-03-18 16:20:46 -0500360 if (state > PM_SUSPEND_ON && state <= PM_SUSPEND_MAX)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700361 return enter_state(state);
362 return -EINVAL;
363}
364
Ralf Baechle4cf30342006-12-06 20:36:06 -0800365EXPORT_SYMBOL(pm_suspend);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700366
Rafael J. Wysocki296699d2007-07-29 23:27:18 +0200367#endif /* CONFIG_SUSPEND */
368
Greg Kroah-Hartmand76e15f2007-11-27 11:28:26 -0800369struct kobject *power_kobj;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700370
371/**
372 * state - control system power state.
373 *
374 * show() returns what states are supported, which is hard-coded to
375 * 'standby' (Power-On Suspend), 'mem' (Suspend-to-RAM), and
376 * 'disk' (Suspend-to-Disk).
377 *
378 * store() accepts one of those strings, translates it into the
379 * proper enumerated value, and initiates a suspend transition.
380 */
381
Kay Sievers386f2752007-11-02 13:47:53 +0100382static ssize_t state_show(struct kobject *kobj, struct kobj_attribute *attr,
383 char *buf)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700384{
Rafael J. Wysocki296699d2007-07-29 23:27:18 +0200385 char *s = buf;
386#ifdef CONFIG_SUSPEND
Linus Torvalds1da177e2005-04-16 15:20:36 -0700387 int i;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700388
389 for (i = 0; i < PM_SUSPEND_MAX; i++) {
Pavel Machek123d3c12005-11-29 19:34:37 -0800390 if (pm_states[i] && valid_state(i))
391 s += sprintf(s,"%s ", pm_states[i]);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700392 }
Rafael J. Wysocki296699d2007-07-29 23:27:18 +0200393#endif
Rafael J. Wysockib0cb1a12007-07-29 23:24:36 +0200394#ifdef CONFIG_HIBERNATION
Rafael J. Wysockia3d25c22007-05-09 02:33:18 -0700395 s += sprintf(s, "%s\n", "disk");
396#else
397 if (s != buf)
398 /* convert the last space to a newline */
399 *(s-1) = '\n';
400#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -0700401 return (s - buf);
402}
403
Kay Sievers386f2752007-11-02 13:47:53 +0100404static ssize_t state_store(struct kobject *kobj, struct kobj_attribute *attr,
405 const char *buf, size_t n)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700406{
Rafael J. Wysocki296699d2007-07-29 23:27:18 +0200407#ifdef CONFIG_SUSPEND
Linus Torvalds1da177e2005-04-16 15:20:36 -0700408 suspend_state_t state = PM_SUSPEND_STANDBY;
Andreas Mohr3b364b82006-06-25 05:47:56 -0700409 const char * const *s;
Rafael J. Wysocki296699d2007-07-29 23:27:18 +0200410#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -0700411 char *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700412 int len;
Rafael J. Wysocki296699d2007-07-29 23:27:18 +0200413 int error = -EINVAL;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700414
415 p = memchr(buf, '\n', n);
416 len = p ? p - buf : n;
417
Rafael J. Wysockia3d25c22007-05-09 02:33:18 -0700418 /* First, check if we are requested to hibernate */
Rafael J. Wysocki8d98a692007-05-16 22:11:19 -0700419 if (len == 4 && !strncmp(buf, "disk", len)) {
Rafael J. Wysockia3d25c22007-05-09 02:33:18 -0700420 error = hibernate();
Rafael J. Wysocki296699d2007-07-29 23:27:18 +0200421 goto Exit;
Rafael J. Wysockia3d25c22007-05-09 02:33:18 -0700422 }
423
Rafael J. Wysocki296699d2007-07-29 23:27:18 +0200424#ifdef CONFIG_SUSPEND
Linus Torvalds1da177e2005-04-16 15:20:36 -0700425 for (s = &pm_states[state]; state < PM_SUSPEND_MAX; s++, state++) {
Rafael J. Wysocki8d98a692007-05-16 22:11:19 -0700426 if (*s && len == strlen(*s) && !strncmp(buf, *s, len))
Linus Torvalds1da177e2005-04-16 15:20:36 -0700427 break;
428 }
dean gaudet47bb7892006-04-27 18:39:17 -0700429 if (state < PM_SUSPEND_MAX && *s)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700430 error = enter_state(state);
Rafael J. Wysocki296699d2007-07-29 23:27:18 +0200431#endif
432
433 Exit:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700434 return error ? error : n;
435}
436
437power_attr(state);
438
Rafael J. Wysockic5c6ba42006-09-25 23:32:58 -0700439#ifdef CONFIG_PM_TRACE
440int pm_trace_enabled;
441
Kay Sievers386f2752007-11-02 13:47:53 +0100442static ssize_t pm_trace_show(struct kobject *kobj, struct kobj_attribute *attr,
443 char *buf)
Rafael J. Wysockic5c6ba42006-09-25 23:32:58 -0700444{
445 return sprintf(buf, "%d\n", pm_trace_enabled);
446}
447
448static ssize_t
Kay Sievers386f2752007-11-02 13:47:53 +0100449pm_trace_store(struct kobject *kobj, struct kobj_attribute *attr,
450 const char *buf, size_t n)
Rafael J. Wysockic5c6ba42006-09-25 23:32:58 -0700451{
452 int val;
453
454 if (sscanf(buf, "%d", &val) == 1) {
455 pm_trace_enabled = !!val;
456 return n;
457 }
458 return -EINVAL;
459}
460
461power_attr(pm_trace);
Rafael J. Wysocki0e7d56e2007-11-19 23:41:19 +0100462#endif /* CONFIG_PM_TRACE */
Rafael J. Wysockic5c6ba42006-09-25 23:32:58 -0700463
464static struct attribute * g[] = {
465 &state_attr.attr,
Rafael J. Wysocki0e7d56e2007-11-19 23:41:19 +0100466#ifdef CONFIG_PM_TRACE
Rafael J. Wysockic5c6ba42006-09-25 23:32:58 -0700467 &pm_trace_attr.attr,
Rafael J. Wysocki0e7d56e2007-11-19 23:41:19 +0100468#endif
469#ifdef CONFIG_PM_DEBUG
470 &pm_test_attr.attr,
471#endif
Rafael J. Wysockic5c6ba42006-09-25 23:32:58 -0700472 NULL,
473};
Linus Torvalds1da177e2005-04-16 15:20:36 -0700474
475static struct attribute_group attr_group = {
476 .attrs = g,
477};
478
479
480static int __init pm_init(void)
481{
Greg Kroah-Hartmand76e15f2007-11-27 11:28:26 -0800482 power_kobj = kobject_create_and_add("power", NULL);
483 if (!power_kobj)
Greg Kroah-Hartman039a5dc2007-11-01 10:39:50 -0700484 return -ENOMEM;
Greg Kroah-Hartmand76e15f2007-11-27 11:28:26 -0800485 return sysfs_create_group(power_kobj, &attr_group);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700486}
487
488core_initcall(pm_init);