[PATCH] pata_pdc2027x iomem annotations
[linux-2.6/libata-dev.git] / drivers / base / power / resume.c
blob826093ef4c7eb0e83cd0fa5fc8564cf6416144ea
1 /*
2 * resume.c - Functions for waking devices up.
4 * Copyright (c) 2003 Patrick Mochel
5 * Copyright (c) 2003 Open Source Development Labs
7 * This file is released under the GPLv2
9 */
11 #include <linux/device.h>
12 #include <linux/resume-trace.h>
13 #include "../base.h"
14 #include "power.h"
17 /**
18 * resume_device - Restore state for one device.
19 * @dev: Device.
23 int resume_device(struct device * dev)
25 int error = 0;
27 TRACE_DEVICE(dev);
28 TRACE_RESUME(0);
29 down(&dev->sem);
30 if (dev->power.pm_parent
31 && dev->power.pm_parent->power.power_state.event) {
32 dev_err(dev, "PM: resume from %d, parent %s still %d\n",
33 dev->power.power_state.event,
34 dev->power.pm_parent->bus_id,
35 dev->power.pm_parent->power.power_state.event);
37 if (dev->bus && dev->bus->resume) {
38 dev_dbg(dev,"resuming\n");
39 error = dev->bus->resume(dev);
41 up(&dev->sem);
42 TRACE_RESUME(error);
43 return error;
48 void dpm_resume(void)
50 down(&dpm_list_sem);
51 while(!list_empty(&dpm_off)) {
52 struct list_head * entry = dpm_off.next;
53 struct device * dev = to_device(entry);
55 get_device(dev);
56 list_move_tail(entry, &dpm_active);
58 up(&dpm_list_sem);
59 if (!dev->power.prev_state.event)
60 resume_device(dev);
61 down(&dpm_list_sem);
62 put_device(dev);
64 up(&dpm_list_sem);
68 /**
69 * device_resume - Restore state of each device in system.
71 * Walk the dpm_off list, remove each entry, resume the device,
72 * then add it to the dpm_active list.
75 void device_resume(void)
77 down(&dpm_sem);
78 dpm_resume();
79 up(&dpm_sem);
82 EXPORT_SYMBOL_GPL(device_resume);
85 /**
86 * device_power_up_irq - Power on some devices.
88 * Walk the dpm_off_irq list and power each device up. This
89 * is used for devices that required they be powered down with
90 * interrupts disabled. As devices are powered on, they are moved to
91 * the dpm_suspended list.
93 * Interrupts must be disabled when calling this.
96 void dpm_power_up(void)
98 while(!list_empty(&dpm_off_irq)) {
99 struct list_head * entry = dpm_off_irq.next;
100 struct device * dev = to_device(entry);
102 get_device(dev);
103 list_move_tail(entry, &dpm_active);
104 resume_device(dev);
105 put_device(dev);
111 * device_pm_power_up - Turn on all devices that need special attention.
113 * Power on system devices then devices that required we shut them down
114 * with interrupts disabled.
115 * Called with interrupts disabled.
118 void device_power_up(void)
120 sysdev_resume();
121 dpm_power_up();
124 EXPORT_SYMBOL_GPL(device_power_up);