blob: 826093ef4c7eb0e83cd0fa5fc8564cf6416144ea [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);
Akinobu Mita1bfba4e2006-06-26 00:24:40 -070056 list_move_tail(entry, &dpm_active);
Linus Torvalds1da177e2005-04-16 15:20:36 -070057
58 up(&dpm_list_sem);
Pavel Machekca078ba2005-09-03 15:56:57 -070059 if (!dev->power.prev_state.event)
Linus Torvalds1da177e2005-04-16 15:20:36 -070060 resume_device(dev);
61 down(&dpm_list_sem);
62 put_device(dev);
63 }
64 up(&dpm_list_sem);
65}
66
67
68/**
69 * device_resume - Restore state of each device in system.
70 *
71 * Walk the dpm_off list, remove each entry, resume the device,
72 * then add it to the dpm_active list.
73 */
74
75void device_resume(void)
76{
77 down(&dpm_sem);
78 dpm_resume();
79 up(&dpm_sem);
80}
81
82EXPORT_SYMBOL_GPL(device_resume);
83
84
85/**
86 * device_power_up_irq - Power on some devices.
87 *
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.
92 *
93 * Interrupts must be disabled when calling this.
94 */
95
96void dpm_power_up(void)
97{
98 while(!list_empty(&dpm_off_irq)) {
99 struct list_head * entry = dpm_off_irq.next;
100 struct device * dev = to_device(entry);
101
102 get_device(dev);
Akinobu Mita1bfba4e2006-06-26 00:24:40 -0700103 list_move_tail(entry, &dpm_active);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700104 resume_device(dev);
105 put_device(dev);
106 }
107}
108
109
110/**
111 * device_pm_power_up - Turn on all devices that need special attention.
112 *
113 * Power on system devices then devices that required we shut them down
114 * with interrupts disabled.
115 * Called with interrupts disabled.
116 */
117
118void device_power_up(void)
119{
120 sysdev_resume();
121 dpm_power_up();
122}
123
124EXPORT_SYMBOL_GPL(device_power_up);
125
126