ftp://ftp.kernel.org/pub/linux/kernel/v2.6/linux-2.6.6.tar.bz2
[linux-2.6.git] / drivers / base / power / resume.c
1 /*
2  * resume.c - Functions for waking devices up.
3  *
4  * Copyright (c) 2003 Patrick Mochel
5  * Copyright (c) 2003 Open Source Development Labs
6  *
7  * This file is released under the GPLv2
8  *
9  */
10
11 #include <linux/device.h>
12 #include "power.h"
13
14 extern int sysdev_resume(void);
15
16
17 /**
18  *      resume_device - Restore state for one device.
19  *      @dev:   Device.
20  *
21  */
22
23 int resume_device(struct device * dev)
24 {
25         if (dev->bus && dev->bus->resume)
26                 return dev->bus->resume(dev);
27         return 0;
28 }
29
30
31
32 void dpm_resume(void)
33 {
34         while(!list_empty(&dpm_off)) {
35                 struct list_head * entry = dpm_off.next;
36                 struct device * dev = to_device(entry);
37                 list_del_init(entry);
38                 resume_device(dev);
39                 list_add_tail(entry,&dpm_active);
40         }
41 }
42
43
44 /**
45  *      device_resume - Restore state of each device in system.
46  *
47  *      Walk the dpm_off list, remove each entry, resume the device,
48  *      then add it to the dpm_active list. 
49  */
50
51 void device_resume(void)
52 {
53         down(&dpm_sem);
54         dpm_resume();
55         up(&dpm_sem);
56 }
57
58 EXPORT_SYMBOL(device_resume);
59
60
61 /**
62  *      device_power_up_irq - Power on some devices. 
63  *
64  *      Walk the dpm_off_irq list and power each device up. This 
65  *      is used for devices that required they be powered down with
66  *      interrupts disabled. As devices are powered on, they are moved to
67  *      the dpm_suspended list.
68  *
69  *      Interrupts must be disabled when calling this. 
70  */
71
72 void dpm_power_up(void)
73 {
74         while(!list_empty(&dpm_off_irq)) {
75                 struct list_head * entry = dpm_off_irq.next;
76                 list_del_init(entry);
77                 resume_device(to_device(entry));
78                 list_add_tail(entry,&dpm_active);
79         }
80 }
81
82
83 /**
84  *      device_pm_power_up - Turn on all devices that need special attention.
85  *
86  *      Power on system devices then devices that required we shut them down
87  *      with interrupts disabled.
88  *      Called with interrupts disabled.
89  */
90
91 void device_power_up(void)
92 {
93         sysdev_resume();
94         dpm_power_up();
95 }
96
97 EXPORT_SYMBOL(device_power_up);
98
99