Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1 | /* |
| 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 Torvalds | d02f40e | 2006-06-24 14:32:18 -0700 | [diff] [blame^] | 12 | #include <linux/resume-trace.h> |
Adrian Bunk | f67d115 | 2006-01-19 17:30:17 +0100 | [diff] [blame] | 13 | #include "../base.h" |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 14 | #include "power.h" |
| 15 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 16 | |
| 17 | /** |
| 18 | * resume_device - Restore state for one device. |
| 19 | * @dev: Device. |
| 20 | * |
| 21 | */ |
| 22 | |
| 23 | int resume_device(struct device * dev) |
| 24 | { |
mochel@digitalimplant.org | af70316 | 2005-03-21 10:41:04 -0800 | [diff] [blame] | 25 | int error = 0; |
| 26 | |
Linus Torvalds | d02f40e | 2006-06-24 14:32:18 -0700 | [diff] [blame^] | 27 | TRACE_DEVICE(dev); |
| 28 | TRACE_RESUME(0); |
mochel@digitalimplant.org | af70316 | 2005-03-21 10:41:04 -0800 | [diff] [blame] | 29 | down(&dev->sem); |
David Brownell | 82428b6 | 2005-05-09 08:07:00 -0700 | [diff] [blame] | 30 | if (dev->power.pm_parent |
Pavel Machek | ca078ba | 2005-09-03 15:56:57 -0700 | [diff] [blame] | 31 | && dev->power.pm_parent->power.power_state.event) { |
David Brownell | 82428b6 | 2005-05-09 08:07:00 -0700 | [diff] [blame] | 32 | dev_err(dev, "PM: resume from %d, parent %s still %d\n", |
Pavel Machek | ca078ba | 2005-09-03 15:56:57 -0700 | [diff] [blame] | 33 | dev->power.power_state.event, |
David Brownell | 82428b6 | 2005-05-09 08:07:00 -0700 | [diff] [blame] | 34 | dev->power.pm_parent->bus_id, |
Pavel Machek | ca078ba | 2005-09-03 15:56:57 -0700 | [diff] [blame] | 35 | dev->power.pm_parent->power.power_state.event); |
David Brownell | 82428b6 | 2005-05-09 08:07:00 -0700 | [diff] [blame] | 36 | } |
| 37 | if (dev->bus && dev->bus->resume) { |
| 38 | dev_dbg(dev,"resuming\n"); |
mochel@digitalimplant.org | af70316 | 2005-03-21 10:41:04 -0800 | [diff] [blame] | 39 | error = dev->bus->resume(dev); |
David Brownell | 82428b6 | 2005-05-09 08:07:00 -0700 | [diff] [blame] | 40 | } |
mochel@digitalimplant.org | af70316 | 2005-03-21 10:41:04 -0800 | [diff] [blame] | 41 | up(&dev->sem); |
Linus Torvalds | d02f40e | 2006-06-24 14:32:18 -0700 | [diff] [blame^] | 42 | TRACE_RESUME(error); |
mochel@digitalimplant.org | af70316 | 2005-03-21 10:41:04 -0800 | [diff] [blame] | 43 | return error; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 44 | } |
| 45 | |
| 46 | |
| 47 | |
| 48 | void 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 Machek | ca078ba | 2005-09-03 15:56:57 -0700 | [diff] [blame] | 60 | if (!dev->power.prev_state.event) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 61 | 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 | |
| 76 | void device_resume(void) |
| 77 | { |
| 78 | down(&dpm_sem); |
| 79 | dpm_resume(); |
| 80 | up(&dpm_sem); |
| 81 | } |
| 82 | |
| 83 | EXPORT_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 | |
| 97 | void 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 | |
| 120 | void device_power_up(void) |
| 121 | { |
| 122 | sysdev_resume(); |
| 123 | dpm_power_up(); |
| 124 | } |
| 125 | |
| 126 | EXPORT_SYMBOL_GPL(device_power_up); |
| 127 | |
| 128 | |