Merge with /pub/scm/linux/kernel/git/torvalds/linux-2.6.git
[linux-2.6] / 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 "../base.h"
13 #include "power.h"
14
15
16 /**
17  *      resume_device - Restore state for one device.
18  *      @dev:   Device.
19  *
20  */
21
22 int resume_device(struct device * dev)
23 {
24         int error = 0;
25
26         down(&dev->sem);
27         if (dev->power.pm_parent
28                         && dev->power.pm_parent->power.power_state.event) {
29                 dev_err(dev, "PM: resume from %d, parent %s still %d\n",
30                         dev->power.power_state.event,
31                         dev->power.pm_parent->bus_id,
32                         dev->power.pm_parent->power.power_state.event);
33         }
34         if (dev->bus && dev->bus->resume) {
35                 dev_dbg(dev,"resuming\n");
36                 error = dev->bus->resume(dev);
37         }
38         up(&dev->sem);
39         return error;
40 }
41
42
43
44 void dpm_resume(void)
45 {
46         down(&dpm_list_sem);
47         while(!list_empty(&dpm_off)) {
48                 struct list_head * entry = dpm_off.next;
49                 struct device * dev = to_device(entry);
50
51                 get_device(dev);
52                 list_del_init(entry);
53                 list_add_tail(entry, &dpm_active);
54
55                 up(&dpm_list_sem);
56                 if (!dev->power.prev_state.event)
57                         resume_device(dev);
58                 down(&dpm_list_sem);
59                 put_device(dev);
60         }
61         up(&dpm_list_sem);
62 }
63
64
65 /**
66  *      device_resume - Restore state of each device in system.
67  *
68  *      Walk the dpm_off list, remove each entry, resume the device,
69  *      then add it to the dpm_active list.
70  */
71
72 void device_resume(void)
73 {
74         down(&dpm_sem);
75         dpm_resume();
76         up(&dpm_sem);
77 }
78
79 EXPORT_SYMBOL_GPL(device_resume);
80
81
82 /**
83  *      device_power_up_irq - Power on some devices.
84  *
85  *      Walk the dpm_off_irq list and power each device up. This
86  *      is used for devices that required they be powered down with
87  *      interrupts disabled. As devices are powered on, they are moved to
88  *      the dpm_suspended list.
89  *
90  *      Interrupts must be disabled when calling this.
91  */
92
93 void dpm_power_up(void)
94 {
95         while(!list_empty(&dpm_off_irq)) {
96                 struct list_head * entry = dpm_off_irq.next;
97                 struct device * dev = to_device(entry);
98
99                 get_device(dev);
100                 list_del_init(entry);
101                 list_add_tail(entry, &dpm_active);
102                 resume_device(dev);
103                 put_device(dev);
104         }
105 }
106
107
108 /**
109  *      device_pm_power_up - Turn on all devices that need special attention.
110  *
111  *      Power on system devices then devices that required we shut them down
112  *      with interrupts disabled.
113  *      Called with interrupts disabled.
114  */
115
116 void device_power_up(void)
117 {
118         sysdev_resume();
119         dpm_power_up();
120 }
121
122 EXPORT_SYMBOL_GPL(device_power_up);
123
124