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