patch-2_6_7-vs1_9_1_12
[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
39                 if (!dev->power.prev_state)
40                         resume_device(dev);
41
42                 list_add_tail(entry,&dpm_active);
43         }
44 }
45
46
47 /**
48  *      device_resume - Restore state of each device in system.
49  *
50  *      Walk the dpm_off list, remove each entry, resume the device,
51  *      then add it to the dpm_active list. 
52  */
53
54 void device_resume(void)
55 {
56         down(&dpm_sem);
57         dpm_resume();
58         up(&dpm_sem);
59 }
60
61 EXPORT_SYMBOL(device_resume);
62
63
64 /**
65  *      device_power_up_irq - Power on some devices. 
66  *
67  *      Walk the dpm_off_irq list and power each device up. This 
68  *      is used for devices that required they be powered down with
69  *      interrupts disabled. As devices are powered on, they are moved to
70  *      the dpm_suspended list.
71  *
72  *      Interrupts must be disabled when calling this. 
73  */
74
75 void dpm_power_up(void)
76 {
77         while(!list_empty(&dpm_off_irq)) {
78                 struct list_head * entry = dpm_off_irq.next;
79                 list_del_init(entry);
80                 resume_device(to_device(entry));
81                 list_add_tail(entry,&dpm_active);
82         }
83 }
84
85
86 /**
87  *      device_pm_power_up - Turn on all devices that need special attention.
88  *
89  *      Power on system devices then devices that required we shut them down
90  *      with interrupts disabled.
91  *      Called with interrupts disabled.
92  */
93
94 void device_power_up(void)
95 {
96         sysdev_resume();
97         dpm_power_up();
98 }
99
100 EXPORT_SYMBOL(device_power_up);
101
102