blob: 00fd84ae6e66f955855f39286b66632c50b0e3dc [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);
Dmitry Torokhovf89cbc32007-04-03 01:08:40 -040029
mochel@digitalimplant.orgaf703162005-03-21 10:41:04 -080030 down(&dev->sem);
Dmitry Torokhovf89cbc32007-04-03 01:08:40 -040031
David Brownell82428b62005-05-09 08:07:00 -070032 if (dev->bus && dev->bus->resume) {
33 dev_dbg(dev,"resuming\n");
mochel@digitalimplant.orgaf703162005-03-21 10:41:04 -080034 error = dev->bus->resume(dev);
David Brownell82428b62005-05-09 08:07:00 -070035 }
Dmitry Torokhovf89cbc32007-04-03 01:08:40 -040036
37 if (!error && dev->type && dev->type->resume) {
38 dev_dbg(dev,"resuming\n");
39 error = dev->type->resume(dev);
40 }
41
42 if (!error && dev->class && dev->class->resume) {
Linus Torvalds7c8265f2006-06-24 14:50:29 -070043 dev_dbg(dev,"class resume\n");
44 error = dev->class->resume(dev);
45 }
Dmitry Torokhovf89cbc32007-04-03 01:08:40 -040046
mochel@digitalimplant.orgaf703162005-03-21 10:41:04 -080047 up(&dev->sem);
Dmitry Torokhovf89cbc32007-04-03 01:08:40 -040048
Linus Torvaldsd02f40e2006-06-24 14:32:18 -070049 TRACE_RESUME(error);
mochel@digitalimplant.orgaf703162005-03-21 10:41:04 -080050 return error;
Linus Torvalds1da177e2005-04-16 15:20:36 -070051}
52
53
Linus Torvalds7c8265f2006-06-24 14:50:29 -070054static int resume_device_early(struct device * dev)
55{
56 int error = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -070057
Linus Torvalds7c8265f2006-06-24 14:50:29 -070058 TRACE_DEVICE(dev);
59 TRACE_RESUME(0);
60 if (dev->bus && dev->bus->resume_early) {
61 dev_dbg(dev,"EARLY resume\n");
62 error = dev->bus->resume_early(dev);
63 }
64 TRACE_RESUME(error);
65 return error;
66}
67
68/*
69 * Resume the devices that have either not gone through
70 * the late suspend, or that did go through it but also
71 * went through the early resume
72 */
Linus Torvalds1da177e2005-04-16 15:20:36 -070073void dpm_resume(void)
74{
Matthias Kaehlcke11048dc2007-05-23 14:19:41 -070075 mutex_lock(&dpm_list_mtx);
Linus Torvalds1da177e2005-04-16 15:20:36 -070076 while(!list_empty(&dpm_off)) {
77 struct list_head * entry = dpm_off.next;
78 struct device * dev = to_device(entry);
79
80 get_device(dev);
Akinobu Mita1bfba4e2006-06-26 00:24:40 -070081 list_move_tail(entry, &dpm_active);
Linus Torvalds1da177e2005-04-16 15:20:36 -070082
Matthias Kaehlcke11048dc2007-05-23 14:19:41 -070083 mutex_unlock(&dpm_list_mtx);
Rafael J. Wysocki515c5352007-06-17 19:48:06 +020084 resume_device(dev);
Matthias Kaehlcke11048dc2007-05-23 14:19:41 -070085 mutex_lock(&dpm_list_mtx);
Linus Torvalds1da177e2005-04-16 15:20:36 -070086 put_device(dev);
87 }
Matthias Kaehlcke11048dc2007-05-23 14:19:41 -070088 mutex_unlock(&dpm_list_mtx);
Linus Torvalds1da177e2005-04-16 15:20:36 -070089}
90
91
92/**
93 * device_resume - Restore state of each device in system.
94 *
95 * Walk the dpm_off list, remove each entry, resume the device,
96 * then add it to the dpm_active list.
97 */
98
99void device_resume(void)
100{
Pavel Machekbb84c892006-08-31 22:02:11 -0700101 might_sleep();
Matthias Kaehlcke11048dc2007-05-23 14:19:41 -0700102 mutex_lock(&dpm_mtx);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700103 dpm_resume();
Matthias Kaehlcke11048dc2007-05-23 14:19:41 -0700104 mutex_unlock(&dpm_mtx);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700105}
106
107EXPORT_SYMBOL_GPL(device_resume);
108
109
110/**
Dmitry Torokhov9de72ee2006-07-15 00:31:54 -0400111 * dpm_power_up - Power on some devices.
Linus Torvalds1da177e2005-04-16 15:20:36 -0700112 *
113 * Walk the dpm_off_irq list and power each device up. This
114 * is used for devices that required they be powered down with
Dmitry Torokhov9de72ee2006-07-15 00:31:54 -0400115 * interrupts disabled. As devices are powered on, they are moved
116 * to the dpm_active list.
Linus Torvalds1da177e2005-04-16 15:20:36 -0700117 *
118 * Interrupts must be disabled when calling this.
119 */
120
121void dpm_power_up(void)
122{
123 while(!list_empty(&dpm_off_irq)) {
124 struct list_head * entry = dpm_off_irq.next;
125 struct device * dev = to_device(entry);
126
Linus Torvalds7c8265f2006-06-24 14:50:29 -0700127 list_move_tail(entry, &dpm_off);
128 resume_device_early(dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700129 }
130}
131
132
133/**
Dmitry Torokhov9de72ee2006-07-15 00:31:54 -0400134 * device_power_up - Turn on all devices that need special attention.
Linus Torvalds1da177e2005-04-16 15:20:36 -0700135 *
136 * Power on system devices then devices that required we shut them down
137 * with interrupts disabled.
138 * Called with interrupts disabled.
139 */
140
141void device_power_up(void)
142{
143 sysdev_resume();
144 dpm_power_up();
145}
146
147EXPORT_SYMBOL_GPL(device_power_up);
148
149