blob: 317edbf0feca6b383fb95980968c28b9947e2970 [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>
Adrian Bunkf67d1152006-01-19 17:30:17 +010012#include "../base.h"
Linus Torvalds1da177e2005-04-16 15:20:36 -070013#include "power.h"
14
Linus Torvalds1da177e2005-04-16 15:20:36 -070015
16/**
17 * resume_device - Restore state for one device.
18 * @dev: Device.
19 *
20 */
21
22int resume_device(struct device * dev)
23{
mochel@digitalimplant.orgaf703162005-03-21 10:41:04 -080024 int error = 0;
25
26 down(&dev->sem);
David Brownell82428b62005-05-09 08:07:00 -070027 if (dev->power.pm_parent
Pavel Machekca078ba2005-09-03 15:56:57 -070028 && dev->power.pm_parent->power.power_state.event) {
David Brownell82428b62005-05-09 08:07:00 -070029 dev_err(dev, "PM: resume from %d, parent %s still %d\n",
Pavel Machekca078ba2005-09-03 15:56:57 -070030 dev->power.power_state.event,
David Brownell82428b62005-05-09 08:07:00 -070031 dev->power.pm_parent->bus_id,
Pavel Machekca078ba2005-09-03 15:56:57 -070032 dev->power.pm_parent->power.power_state.event);
David Brownell82428b62005-05-09 08:07:00 -070033 }
34 if (dev->bus && dev->bus->resume) {
35 dev_dbg(dev,"resuming\n");
mochel@digitalimplant.orgaf703162005-03-21 10:41:04 -080036 error = dev->bus->resume(dev);
David Brownell82428b62005-05-09 08:07:00 -070037 }
mochel@digitalimplant.orgaf703162005-03-21 10:41:04 -080038 up(&dev->sem);
39 return error;
Linus Torvalds1da177e2005-04-16 15:20:36 -070040}
41
42
43
44void dpm_resume(void)
45{
46 down(&dpm_list_sem);
47 while(!list_empty(&dpm_off)) {
48 struct list_head * entry = dpm_off.next;
49 struct device * dev = to_device(entry);
50
51 get_device(dev);
52 list_del_init(entry);
53 list_add_tail(entry, &dpm_active);
54
55 up(&dpm_list_sem);
Pavel Machekca078ba2005-09-03 15:56:57 -070056 if (!dev->power.prev_state.event)
Linus Torvalds1da177e2005-04-16 15:20:36 -070057 resume_device(dev);
58 down(&dpm_list_sem);
59 put_device(dev);
60 }
61 up(&dpm_list_sem);
62}
63
64
65/**
66 * device_resume - Restore state of each device in system.
67 *
68 * Walk the dpm_off list, remove each entry, resume the device,
69 * then add it to the dpm_active list.
70 */
71
72void device_resume(void)
73{
74 down(&dpm_sem);
75 dpm_resume();
76 up(&dpm_sem);
77}
78
79EXPORT_SYMBOL_GPL(device_resume);
80
81
82/**
83 * device_power_up_irq - Power on some devices.
84 *
85 * Walk the dpm_off_irq list and power each device up. This
86 * is used for devices that required they be powered down with
87 * interrupts disabled. As devices are powered on, they are moved to
88 * the dpm_suspended list.
89 *
90 * Interrupts must be disabled when calling this.
91 */
92
93void dpm_power_up(void)
94{
95 while(!list_empty(&dpm_off_irq)) {
96 struct list_head * entry = dpm_off_irq.next;
97 struct device * dev = to_device(entry);
98
99 get_device(dev);
100 list_del_init(entry);
101 list_add_tail(entry, &dpm_active);
102 resume_device(dev);
103 put_device(dev);
104 }
105}
106
107
108/**
109 * device_pm_power_up - Turn on all devices that need special attention.
110 *
111 * Power on system devices then devices that required we shut them down
112 * with interrupts disabled.
113 * Called with interrupts disabled.
114 */
115
116void device_power_up(void)
117{
118 sysdev_resume();
119 dpm_power_up();
120}
121
122EXPORT_SYMBOL_GPL(device_power_up);
123
124