blob: 020be36705a6827f38bfa15c83a304672b9e9c55 [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 }
Linus Torvalds7c8265f2006-06-24 14:50:29 -070041 if (dev->class && dev->class->resume) {
42 dev_dbg(dev,"class resume\n");
43 error = dev->class->resume(dev);
44 }
mochel@digitalimplant.orgaf703162005-03-21 10:41:04 -080045 up(&dev->sem);
Linus Torvaldsd02f40e2006-06-24 14:32:18 -070046 TRACE_RESUME(error);
mochel@digitalimplant.orgaf703162005-03-21 10:41:04 -080047 return error;
Linus Torvalds1da177e2005-04-16 15:20:36 -070048}
49
50
Linus Torvalds7c8265f2006-06-24 14:50:29 -070051static int resume_device_early(struct device * dev)
52{
53 int error = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -070054
Linus Torvalds7c8265f2006-06-24 14:50:29 -070055 TRACE_DEVICE(dev);
56 TRACE_RESUME(0);
57 if (dev->bus && dev->bus->resume_early) {
58 dev_dbg(dev,"EARLY resume\n");
59 error = dev->bus->resume_early(dev);
60 }
61 TRACE_RESUME(error);
62 return error;
63}
64
65/*
66 * Resume the devices that have either not gone through
67 * the late suspend, or that did go through it but also
68 * went through the early resume
69 */
Linus Torvalds1da177e2005-04-16 15:20:36 -070070void dpm_resume(void)
71{
72 down(&dpm_list_sem);
73 while(!list_empty(&dpm_off)) {
74 struct list_head * entry = dpm_off.next;
75 struct device * dev = to_device(entry);
76
77 get_device(dev);
Akinobu Mita1bfba4e2006-06-26 00:24:40 -070078 list_move_tail(entry, &dpm_active);
Linus Torvalds1da177e2005-04-16 15:20:36 -070079
80 up(&dpm_list_sem);
Pavel Machekca078ba2005-09-03 15:56:57 -070081 if (!dev->power.prev_state.event)
Linus Torvalds1da177e2005-04-16 15:20:36 -070082 resume_device(dev);
83 down(&dpm_list_sem);
84 put_device(dev);
85 }
86 up(&dpm_list_sem);
87}
88
89
90/**
91 * device_resume - Restore state of each device in system.
92 *
93 * Walk the dpm_off list, remove each entry, resume the device,
94 * then add it to the dpm_active list.
95 */
96
97void device_resume(void)
98{
Pavel Machekbb84c892006-08-31 22:02:11 -070099 might_sleep();
Linus Torvalds1da177e2005-04-16 15:20:36 -0700100 down(&dpm_sem);
101 dpm_resume();
102 up(&dpm_sem);
103}
104
105EXPORT_SYMBOL_GPL(device_resume);
106
107
108/**
Dmitry Torokhov9de72ee2006-07-15 00:31:54 -0400109 * dpm_power_up - Power on some devices.
Linus Torvalds1da177e2005-04-16 15:20:36 -0700110 *
111 * Walk the dpm_off_irq list and power each device up. This
112 * is used for devices that required they be powered down with
Dmitry Torokhov9de72ee2006-07-15 00:31:54 -0400113 * interrupts disabled. As devices are powered on, they are moved
114 * to the dpm_active list.
Linus Torvalds1da177e2005-04-16 15:20:36 -0700115 *
116 * Interrupts must be disabled when calling this.
117 */
118
119void dpm_power_up(void)
120{
121 while(!list_empty(&dpm_off_irq)) {
122 struct list_head * entry = dpm_off_irq.next;
123 struct device * dev = to_device(entry);
124
Linus Torvalds7c8265f2006-06-24 14:50:29 -0700125 list_move_tail(entry, &dpm_off);
126 resume_device_early(dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700127 }
128}
129
130
131/**
Dmitry Torokhov9de72ee2006-07-15 00:31:54 -0400132 * device_power_up - Turn on all devices that need special attention.
Linus Torvalds1da177e2005-04-16 15:20:36 -0700133 *
134 * Power on system devices then devices that required we shut them down
135 * with interrupts disabled.
136 * Called with interrupts disabled.
137 */
138
139void device_power_up(void)
140{
141 sysdev_resume();
142 dpm_power_up();
143}
144
145EXPORT_SYMBOL_GPL(device_power_up);
146
147