blob: 520679ce53a88c04598599665bccd0251fcceb13 [file] [log] [blame]
Linus Torvalds1da177e2005-04-16 15:20:36 -07001/*
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>
Linus Torvaldsd02f40e2006-06-24 14:32:18 -070012#include <linux/resume-trace.h>
Adrian Bunkf67d1152006-01-19 17:30:17 +010013#include "../base.h"
Linus Torvalds1da177e2005-04-16 15:20:36 -070014#include "power.h"
15
Linus Torvalds1da177e2005-04-16 15:20:36 -070016
17/**
18 * resume_device - Restore state for one device.
19 * @dev: Device.
20 *
21 */
22
23int resume_device(struct device * dev)
24{
mochel@digitalimplant.orgaf703162005-03-21 10:41:04 -080025 int error = 0;
26
Linus Torvaldsd02f40e2006-06-24 14:32:18 -070027 TRACE_DEVICE(dev);
28 TRACE_RESUME(0);
mochel@digitalimplant.orgaf703162005-03-21 10:41:04 -080029 down(&dev->sem);
David Brownell82428b62005-05-09 08:07:00 -070030 if (dev->power.pm_parent
Pavel Machekca078ba2005-09-03 15:56:57 -070031 && dev->power.pm_parent->power.power_state.event) {
David Brownell82428b62005-05-09 08:07:00 -070032 dev_err(dev, "PM: resume from %d, parent %s still %d\n",
Pavel Machekca078ba2005-09-03 15:56:57 -070033 dev->power.power_state.event,
David Brownell82428b62005-05-09 08:07:00 -070034 dev->power.pm_parent->bus_id,
Pavel Machekca078ba2005-09-03 15:56:57 -070035 dev->power.pm_parent->power.power_state.event);
David Brownell82428b62005-05-09 08:07:00 -070036 }
37 if (dev->bus && dev->bus->resume) {
38 dev_dbg(dev,"resuming\n");
mochel@digitalimplant.orgaf703162005-03-21 10:41:04 -080039 error = dev->bus->resume(dev);
David Brownell82428b62005-05-09 08:07:00 -070040 }
mochel@digitalimplant.orgaf703162005-03-21 10:41:04 -080041 up(&dev->sem);
Linus Torvaldsd02f40e2006-06-24 14:32:18 -070042 TRACE_RESUME(error);
mochel@digitalimplant.orgaf703162005-03-21 10:41:04 -080043 return error;
Linus Torvalds1da177e2005-04-16 15:20:36 -070044}
45
46
47
48void dpm_resume(void)
49{
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);
54
55 get_device(dev);
56 list_del_init(entry);
57 list_add_tail(entry, &dpm_active);
58
59 up(&dpm_list_sem);
Pavel Machekca078ba2005-09-03 15:56:57 -070060 if (!dev->power.prev_state.event)
Linus Torvalds1da177e2005-04-16 15:20:36 -070061 resume_device(dev);
62 down(&dpm_list_sem);
63 put_device(dev);
64 }
65 up(&dpm_list_sem);
66}
67
68
69/**
70 * device_resume - Restore state of each device in system.
71 *
72 * Walk the dpm_off list, remove each entry, resume the device,
73 * then add it to the dpm_active list.
74 */
75
76void device_resume(void)
77{
78 down(&dpm_sem);
79 dpm_resume();
80 up(&dpm_sem);
81}
82
83EXPORT_SYMBOL_GPL(device_resume);
84
85
86/**
87 * device_power_up_irq - Power on some devices.
88 *
89 * Walk the dpm_off_irq list and power each device up. This
90 * is used for devices that required they be powered down with
91 * interrupts disabled. As devices are powered on, they are moved to
92 * the dpm_suspended list.
93 *
94 * Interrupts must be disabled when calling this.
95 */
96
97void dpm_power_up(void)
98{
99 while(!list_empty(&dpm_off_irq)) {
100 struct list_head * entry = dpm_off_irq.next;
101 struct device * dev = to_device(entry);
102
103 get_device(dev);
104 list_del_init(entry);
105 list_add_tail(entry, &dpm_active);
106 resume_device(dev);
107 put_device(dev);
108 }
109}
110
111
112/**
113 * device_pm_power_up - Turn on all devices that need special attention.
114 *
115 * Power on system devices then devices that required we shut them down
116 * with interrupts disabled.
117 * Called with interrupts disabled.
118 */
119
120void device_power_up(void)
121{
122 sysdev_resume();
123 dpm_power_up();
124}
125
126EXPORT_SYMBOL_GPL(device_power_up);
127
128