Rafael J. Wysocki | 624f6ec | 2010-03-26 23:53:42 +0100 | [diff] [blame] | 1 | Device Power Management |
| 2 | |
Rafael J. Wysocki | 7538e3d | 2011-02-16 21:53:17 +0100 | [diff] [blame] | 3 | Copyright (c) 2010-2011 Rafael J. Wysocki <rjw@sisk.pl>, Novell Inc. |
Alan Stern | d6f9cda | 2010-03-26 23:53:55 +0100 | [diff] [blame] | 4 | Copyright (c) 2010 Alan Stern <stern@rowland.harvard.edu> |
| 5 | |
Rafael J. Wysocki | 624f6ec | 2010-03-26 23:53:42 +0100 | [diff] [blame] | 6 | |
David Brownell | 4fc0840 | 2006-08-10 16:38:28 -0700 | [diff] [blame] | 7 | Most of the code in Linux is device drivers, so most of the Linux power |
Alan Stern | d6f9cda | 2010-03-26 23:53:55 +0100 | [diff] [blame] | 8 | management (PM) code is also driver-specific. Most drivers will do very |
| 9 | little; others, especially for platforms with small batteries (like cell |
| 10 | phones), will do a lot. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 11 | |
David Brownell | 4fc0840 | 2006-08-10 16:38:28 -0700 | [diff] [blame] | 12 | This writeup gives an overview of how drivers interact with system-wide |
| 13 | power management goals, emphasizing the models and interfaces that are |
| 14 | shared by everything that hooks up to the driver model core. Read it as |
| 15 | background for the domain-specific work you'd do with any specific driver. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 16 | |
| 17 | |
David Brownell | 4fc0840 | 2006-08-10 16:38:28 -0700 | [diff] [blame] | 18 | Two Models for Device Power Management |
| 19 | ====================================== |
| 20 | Drivers will use one or both of these models to put devices into low-power |
| 21 | states: |
| 22 | |
| 23 | System Sleep model: |
Alan Stern | d6f9cda | 2010-03-26 23:53:55 +0100 | [diff] [blame] | 24 | Drivers can enter low-power states as part of entering system-wide |
| 25 | low-power states like "suspend" (also known as "suspend-to-RAM"), or |
| 26 | (mostly for systems with disks) "hibernation" (also known as |
| 27 | "suspend-to-disk"). |
David Brownell | 4fc0840 | 2006-08-10 16:38:28 -0700 | [diff] [blame] | 28 | |
| 29 | This is something that device, bus, and class drivers collaborate on |
| 30 | by implementing various role-specific suspend and resume methods to |
| 31 | cleanly power down hardware and software subsystems, then reactivate |
| 32 | them without loss of data. |
| 33 | |
| 34 | Some drivers can manage hardware wakeup events, which make the system |
Alan Stern | d6f9cda | 2010-03-26 23:53:55 +0100 | [diff] [blame] | 35 | leave the low-power state. This feature may be enabled or disabled |
Rafael J. Wysocki | 624f6ec | 2010-03-26 23:53:42 +0100 | [diff] [blame] | 36 | using the relevant /sys/devices/.../power/wakeup file (for Ethernet |
| 37 | drivers the ioctl interface used by ethtool may also be used for this |
| 38 | purpose); enabling it may cost some power usage, but let the whole |
Alan Stern | d6f9cda | 2010-03-26 23:53:55 +0100 | [diff] [blame] | 39 | system enter low-power states more often. |
David Brownell | 4fc0840 | 2006-08-10 16:38:28 -0700 | [diff] [blame] | 40 | |
| 41 | Runtime Power Management model: |
Alan Stern | d6f9cda | 2010-03-26 23:53:55 +0100 | [diff] [blame] | 42 | Devices may also be put into low-power states while the system is |
Rafael J. Wysocki | 624f6ec | 2010-03-26 23:53:42 +0100 | [diff] [blame] | 43 | running, independently of other power management activity in principle. |
| 44 | However, devices are not generally independent of each other (for |
Alan Stern | d6f9cda | 2010-03-26 23:53:55 +0100 | [diff] [blame] | 45 | example, a parent device cannot be suspended unless all of its child |
| 46 | devices have been suspended). Moreover, depending on the bus type the |
Rafael J. Wysocki | 624f6ec | 2010-03-26 23:53:42 +0100 | [diff] [blame] | 47 | device is on, it may be necessary to carry out some bus-specific |
Alan Stern | d6f9cda | 2010-03-26 23:53:55 +0100 | [diff] [blame] | 48 | operations on the device for this purpose. Devices put into low power |
| 49 | states at run time may require special handling during system-wide power |
| 50 | transitions (suspend or hibernation). |
David Brownell | 4fc0840 | 2006-08-10 16:38:28 -0700 | [diff] [blame] | 51 | |
Rafael J. Wysocki | 624f6ec | 2010-03-26 23:53:42 +0100 | [diff] [blame] | 52 | For these reasons not only the device driver itself, but also the |
Alan Stern | d6f9cda | 2010-03-26 23:53:55 +0100 | [diff] [blame] | 53 | appropriate subsystem (bus type, device type or device class) driver and |
| 54 | the PM core are involved in runtime power management. As in the system |
| 55 | sleep power management case, they need to collaborate by implementing |
| 56 | various role-specific suspend and resume methods, so that the hardware |
| 57 | is cleanly powered down and reactivated without data or service loss. |
David Brownell | 4fc0840 | 2006-08-10 16:38:28 -0700 | [diff] [blame] | 58 | |
Alan Stern | d6f9cda | 2010-03-26 23:53:55 +0100 | [diff] [blame] | 59 | There's not a lot to be said about those low-power states except that they are |
| 60 | very system-specific, and often device-specific. Also, that if enough devices |
| 61 | have been put into low-power states (at runtime), the effect may be very similar |
| 62 | to entering some system-wide low-power state (system sleep) ... and that |
| 63 | synergies exist, so that several drivers using runtime PM might put the system |
| 64 | into a state where even deeper power saving options are available. |
David Brownell | 4fc0840 | 2006-08-10 16:38:28 -0700 | [diff] [blame] | 65 | |
Alan Stern | d6f9cda | 2010-03-26 23:53:55 +0100 | [diff] [blame] | 66 | Most suspended devices will have quiesced all I/O: no more DMA or IRQs (except |
| 67 | for wakeup events), no more data read or written, and requests from upstream |
| 68 | drivers are no longer accepted. A given bus or platform may have different |
| 69 | requirements though. |
David Brownell | 4fc0840 | 2006-08-10 16:38:28 -0700 | [diff] [blame] | 70 | |
| 71 | Examples of hardware wakeup events include an alarm from a real time clock, |
| 72 | network wake-on-LAN packets, keyboard or mouse activity, and media insertion |
| 73 | or removal (for PCMCIA, MMC/SD, USB, and so on). |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 74 | |
| 75 | |
David Brownell | 4fc0840 | 2006-08-10 16:38:28 -0700 | [diff] [blame] | 76 | Interfaces for Entering System Sleep States |
| 77 | =========================================== |
Alan Stern | d6f9cda | 2010-03-26 23:53:55 +0100 | [diff] [blame] | 78 | There are programming interfaces provided for subsystems (bus type, device type, |
| 79 | device class) and device drivers to allow them to participate in the power |
| 80 | management of devices they are concerned with. These interfaces cover both |
| 81 | system sleep and runtime power management. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 82 | |
David Brownell | 4fc0840 | 2006-08-10 16:38:28 -0700 | [diff] [blame] | 83 | |
Rafael J. Wysocki | 624f6ec | 2010-03-26 23:53:42 +0100 | [diff] [blame] | 84 | Device Power Management Operations |
| 85 | ---------------------------------- |
| 86 | Device power management operations, at the subsystem level as well as at the |
| 87 | device driver level, are implemented by defining and populating objects of type |
| 88 | struct dev_pm_ops: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 89 | |
Rafael J. Wysocki | 624f6ec | 2010-03-26 23:53:42 +0100 | [diff] [blame] | 90 | struct dev_pm_ops { |
| 91 | int (*prepare)(struct device *dev); |
| 92 | void (*complete)(struct device *dev); |
| 93 | int (*suspend)(struct device *dev); |
| 94 | int (*resume)(struct device *dev); |
| 95 | int (*freeze)(struct device *dev); |
| 96 | int (*thaw)(struct device *dev); |
| 97 | int (*poweroff)(struct device *dev); |
| 98 | int (*restore)(struct device *dev); |
| 99 | int (*suspend_noirq)(struct device *dev); |
| 100 | int (*resume_noirq)(struct device *dev); |
| 101 | int (*freeze_noirq)(struct device *dev); |
| 102 | int (*thaw_noirq)(struct device *dev); |
| 103 | int (*poweroff_noirq)(struct device *dev); |
| 104 | int (*restore_noirq)(struct device *dev); |
| 105 | int (*runtime_suspend)(struct device *dev); |
| 106 | int (*runtime_resume)(struct device *dev); |
| 107 | int (*runtime_idle)(struct device *dev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 108 | }; |
| 109 | |
Rafael J. Wysocki | 624f6ec | 2010-03-26 23:53:42 +0100 | [diff] [blame] | 110 | This structure is defined in include/linux/pm.h and the methods included in it |
| 111 | are also described in that file. Their roles will be explained in what follows. |
Alan Stern | d6f9cda | 2010-03-26 23:53:55 +0100 | [diff] [blame] | 112 | For now, it should be sufficient to remember that the last three methods are |
| 113 | specific to runtime power management while the remaining ones are used during |
Rafael J. Wysocki | 624f6ec | 2010-03-26 23:53:42 +0100 | [diff] [blame] | 114 | system-wide power transitions. |
| 115 | |
Alan Stern | d6f9cda | 2010-03-26 23:53:55 +0100 | [diff] [blame] | 116 | There also is a deprecated "old" or "legacy" interface for power management |
| 117 | operations available at least for some subsystems. This approach does not use |
| 118 | struct dev_pm_ops objects and it is suitable only for implementing system sleep |
| 119 | power management methods. Therefore it is not described in this document, so |
| 120 | please refer directly to the source code for more information about it. |
Rafael J. Wysocki | 624f6ec | 2010-03-26 23:53:42 +0100 | [diff] [blame] | 121 | |
| 122 | |
| 123 | Subsystem-Level Methods |
| 124 | ----------------------- |
| 125 | The core methods to suspend and resume devices reside in struct dev_pm_ops |
Rafael J. Wysocki | 5841eb6 | 2011-11-23 21:18:39 +0100 | [diff] [blame] | 126 | pointed to by the ops member of struct dev_pm_domain, or by the pm member of |
| 127 | struct bus_type, struct device_type and struct class. They are mostly of |
| 128 | interest to the people writing infrastructure for platforms and buses, like PCI |
Rafael J. Wysocki | 35cd133 | 2011-12-18 00:34:13 +0100 | [diff] [blame] | 129 | or USB, or device type and device class drivers. They also are relevant to the |
| 130 | writers of device drivers whose subsystems (PM domains, device types, device |
| 131 | classes and bus types) don't provide all power management methods. |
Rafael J. Wysocki | 624f6ec | 2010-03-26 23:53:42 +0100 | [diff] [blame] | 132 | |
Alan Stern | d6f9cda | 2010-03-26 23:53:55 +0100 | [diff] [blame] | 133 | Bus drivers implement these methods as appropriate for the hardware and the |
| 134 | drivers using it; PCI works differently from USB, and so on. Not many people |
| 135 | write subsystem-level drivers; most driver code is a "device driver" that builds |
| 136 | on top of bus-specific framework code. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 137 | |
David Brownell | 4fc0840 | 2006-08-10 16:38:28 -0700 | [diff] [blame] | 138 | For more information on these driver calls, see the description later; |
| 139 | they are called in phases for every device, respecting the parent-child |
Rafael J. Wysocki | 624f6ec | 2010-03-26 23:53:42 +0100 | [diff] [blame] | 140 | sequencing in the driver model tree. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 141 | |
| 142 | |
David Brownell | 4fc0840 | 2006-08-10 16:38:28 -0700 | [diff] [blame] | 143 | /sys/devices/.../power/wakeup files |
| 144 | ----------------------------------- |
Rafael J. Wysocki | fafba48 | 2011-11-23 21:20:15 +0100 | [diff] [blame] | 145 | All device objects in the driver model contain fields that control the handling |
| 146 | of system wakeup events (hardware signals that can force the system out of a |
| 147 | sleep state). These fields are initialized by bus or device driver code using |
Alan Stern | d6f9cda | 2010-03-26 23:53:55 +0100 | [diff] [blame] | 148 | device_set_wakeup_capable() and device_set_wakeup_enable(), defined in |
| 149 | include/linux/pm_wakeup.h. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 150 | |
Rafael J. Wysocki | fafba48 | 2011-11-23 21:20:15 +0100 | [diff] [blame] | 151 | The "power.can_wakeup" flag just records whether the device (and its driver) can |
Alan Stern | d6f9cda | 2010-03-26 23:53:55 +0100 | [diff] [blame] | 152 | physically support wakeup events. The device_set_wakeup_capable() routine |
Rafael J. Wysocki | fafba48 | 2011-11-23 21:20:15 +0100 | [diff] [blame] | 153 | affects this flag. The "power.wakeup" field is a pointer to an object of type |
| 154 | struct wakeup_source used for controlling whether or not the device should use |
| 155 | its system wakeup mechanism and for notifying the PM core of system wakeup |
| 156 | events signaled by the device. This object is only present for wakeup-capable |
| 157 | devices (i.e. devices whose "can_wakeup" flags are set) and is created (or |
| 158 | removed) by device_set_wakeup_capable(). |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 159 | |
Alan Stern | d6f9cda | 2010-03-26 23:53:55 +0100 | [diff] [blame] | 160 | Whether or not a device is capable of issuing wakeup events is a hardware |
| 161 | matter, and the kernel is responsible for keeping track of it. By contrast, |
| 162 | whether or not a wakeup-capable device should issue wakeup events is a policy |
| 163 | decision, and it is managed by user space through a sysfs attribute: the |
Rafael J. Wysocki | fafba48 | 2011-11-23 21:20:15 +0100 | [diff] [blame] | 164 | "power/wakeup" file. User space can write the strings "enabled" or "disabled" |
| 165 | to it to indicate whether or not, respectively, the device is supposed to signal |
| 166 | system wakeup. This file is only present if the "power.wakeup" object exists |
| 167 | for the given device and is created (or removed) along with that object, by |
| 168 | device_set_wakeup_capable(). Reads from the file will return the corresponding |
| 169 | string. |
Alan Stern | d6f9cda | 2010-03-26 23:53:55 +0100 | [diff] [blame] | 170 | |
Rafael J. Wysocki | fafba48 | 2011-11-23 21:20:15 +0100 | [diff] [blame] | 171 | The "power/wakeup" file is supposed to contain the "disabled" string initially |
| 172 | for the majority of devices; the major exceptions are power buttons, keyboards, |
| 173 | and Ethernet adapters whose WoL (wake-on-LAN) feature has been set up with |
| 174 | ethtool. It should also default to "enabled" for devices that don't generate |
| 175 | wakeup requests on their own but merely forward wakeup requests from one bus to |
| 176 | another (like PCI Express ports). |
| 177 | |
| 178 | The device_may_wakeup() routine returns true only if the "power.wakeup" object |
| 179 | exists and the corresponding "power/wakeup" file contains the string "enabled". |
Rafael J. Wysocki | cb8f51b | 2011-02-08 23:26:02 +0100 | [diff] [blame] | 180 | This information is used by subsystems, like the PCI bus type code, to see |
| 181 | whether or not to enable the devices' wakeup mechanisms. If device wakeup |
| 182 | mechanisms are enabled or disabled directly by drivers, they also should use |
| 183 | device_may_wakeup() to decide what to do during a system sleep transition. |
Rafael J. Wysocki | fafba48 | 2011-11-23 21:20:15 +0100 | [diff] [blame] | 184 | Device drivers, however, are not supposed to call device_set_wakeup_enable() |
| 185 | directly in any case. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 186 | |
Rafael J. Wysocki | fafba48 | 2011-11-23 21:20:15 +0100 | [diff] [blame] | 187 | It ought to be noted that system wakeup is conceptually different from "remote |
| 188 | wakeup" used by runtime power management, although it may be supported by the |
| 189 | same physical mechanism. Remote wakeup is a feature allowing devices in |
| 190 | low-power states to trigger specific interrupts to signal conditions in which |
| 191 | they should be put into the full-power state. Those interrupts may or may not |
| 192 | be used to signal system wakeup events, depending on the hardware design. On |
| 193 | some systems it is impossible to trigger them from system sleep states. In any |
| 194 | case, remote wakeup should always be enabled for runtime power management for |
| 195 | all devices and drivers that support it. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 196 | |
Rafael J. Wysocki | 624f6ec | 2010-03-26 23:53:42 +0100 | [diff] [blame] | 197 | /sys/devices/.../power/control files |
| 198 | ------------------------------------ |
Alan Stern | d6f9cda | 2010-03-26 23:53:55 +0100 | [diff] [blame] | 199 | Each device in the driver model has a flag to control whether it is subject to |
| 200 | runtime power management. This flag, called runtime_auto, is initialized by the |
| 201 | bus type (or generally subsystem) code using pm_runtime_allow() or |
| 202 | pm_runtime_forbid(); the default is to allow runtime power management. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 203 | |
Alan Stern | d6f9cda | 2010-03-26 23:53:55 +0100 | [diff] [blame] | 204 | The setting can be adjusted by user space by writing either "on" or "auto" to |
| 205 | the device's power/control sysfs file. Writing "auto" calls pm_runtime_allow(), |
| 206 | setting the flag and allowing the device to be runtime power-managed by its |
| 207 | driver. Writing "on" calls pm_runtime_forbid(), clearing the flag, returning |
| 208 | the device to full power if it was in a low-power state, and preventing the |
| 209 | device from being runtime power-managed. User space can check the current value |
| 210 | of the runtime_auto flag by reading the file. |
David Brownell | 4fc0840 | 2006-08-10 16:38:28 -0700 | [diff] [blame] | 211 | |
Rafael J. Wysocki | 624f6ec | 2010-03-26 23:53:42 +0100 | [diff] [blame] | 212 | The device's runtime_auto flag has no effect on the handling of system-wide |
Alan Stern | d6f9cda | 2010-03-26 23:53:55 +0100 | [diff] [blame] | 213 | power transitions. In particular, the device can (and in the majority of cases |
| 214 | should and will) be put into a low-power state during a system-wide transition |
| 215 | to a sleep state even though its runtime_auto flag is clear. |
David Brownell | 4fc0840 | 2006-08-10 16:38:28 -0700 | [diff] [blame] | 216 | |
Alan Stern | d6f9cda | 2010-03-26 23:53:55 +0100 | [diff] [blame] | 217 | For more information about the runtime power management framework, refer to |
| 218 | Documentation/power/runtime_pm.txt. |
David Brownell | 4fc0840 | 2006-08-10 16:38:28 -0700 | [diff] [blame] | 219 | |
| 220 | |
Alan Stern | d6f9cda | 2010-03-26 23:53:55 +0100 | [diff] [blame] | 221 | Calling Drivers to Enter and Leave System Sleep States |
| 222 | ====================================================== |
| 223 | When the system goes into a sleep state, each device's driver is asked to |
| 224 | suspend the device by putting it into a state compatible with the target |
David Brownell | 4fc0840 | 2006-08-10 16:38:28 -0700 | [diff] [blame] | 225 | system state. That's usually some version of "off", but the details are |
| 226 | system-specific. Also, wakeup-enabled devices will usually stay partly |
| 227 | functional in order to wake the system. |
| 228 | |
Alan Stern | d6f9cda | 2010-03-26 23:53:55 +0100 | [diff] [blame] | 229 | When the system leaves that low-power state, the device's driver is asked to |
| 230 | resume it by returning it to full power. The suspend and resume operations |
| 231 | always go together, and both are multi-phase operations. |
David Brownell | 4fc0840 | 2006-08-10 16:38:28 -0700 | [diff] [blame] | 232 | |
Alan Stern | d6f9cda | 2010-03-26 23:53:55 +0100 | [diff] [blame] | 233 | For simple drivers, suspend might quiesce the device using class code |
| 234 | and then turn its hardware as "off" as possible during suspend_noirq. The |
David Brownell | 4fc0840 | 2006-08-10 16:38:28 -0700 | [diff] [blame] | 235 | matching resume calls would then completely reinitialize the hardware |
| 236 | before reactivating its class I/O queues. |
| 237 | |
Rafael J. Wysocki | 624f6ec | 2010-03-26 23:53:42 +0100 | [diff] [blame] | 238 | More power-aware drivers might prepare the devices for triggering system wakeup |
| 239 | events. |
David Brownell | 4fc0840 | 2006-08-10 16:38:28 -0700 | [diff] [blame] | 240 | |
| 241 | |
| 242 | Call Sequence Guarantees |
| 243 | ------------------------ |
Rafael J. Wysocki | 624f6ec | 2010-03-26 23:53:42 +0100 | [diff] [blame] | 244 | To ensure that bridges and similar links needing to talk to a device are |
David Brownell | 4fc0840 | 2006-08-10 16:38:28 -0700 | [diff] [blame] | 245 | available when the device is suspended or resumed, the device tree is |
| 246 | walked in a bottom-up order to suspend devices. A top-down order is |
| 247 | used to resume those devices. |
| 248 | |
| 249 | The ordering of the device tree is defined by the order in which devices |
| 250 | get registered: a child can never be registered, probed or resumed before |
| 251 | its parent; and can't be removed or suspended after that parent. |
| 252 | |
| 253 | The policy is that the device tree should match hardware bus topology. |
| 254 | (Or at least the control bus, for devices which use multiple busses.) |
Rafael J. Wysocki | 58aca23 | 2008-03-12 00:57:22 +0100 | [diff] [blame] | 255 | In particular, this means that a device registration may fail if the parent of |
Rafael J. Wysocki | 624f6ec | 2010-03-26 23:53:42 +0100 | [diff] [blame] | 256 | the device is suspending (i.e. has been chosen by the PM core as the next |
Rafael J. Wysocki | 58aca23 | 2008-03-12 00:57:22 +0100 | [diff] [blame] | 257 | device to suspend) or has already suspended, as well as after all of the other |
| 258 | devices have been suspended. Device drivers must be prepared to cope with such |
| 259 | situations. |
David Brownell | 4fc0840 | 2006-08-10 16:38:28 -0700 | [diff] [blame] | 260 | |
| 261 | |
Alan Stern | d6f9cda | 2010-03-26 23:53:55 +0100 | [diff] [blame] | 262 | System Power Management Phases |
| 263 | ------------------------------ |
| 264 | Suspending or resuming the system is done in several phases. Different phases |
| 265 | are used for standby or memory sleep states ("suspend-to-RAM") and the |
| 266 | hibernation state ("suspend-to-disk"). Each phase involves executing callbacks |
| 267 | for every device before the next phase begins. Not all busses or classes |
| 268 | support all these callbacks and not all drivers use all the callbacks. The |
| 269 | various phases always run after tasks have been frozen and before they are |
| 270 | unfrozen. Furthermore, the *_noirq phases run at a time when IRQ handlers have |
Rafael J. Wysocki | fa8ce72 | 2011-11-23 21:19:57 +0100 | [diff] [blame] | 271 | been disabled (except for those marked with the IRQF_NO_SUSPEND flag). |
David Brownell | 4fc0840 | 2006-08-10 16:38:28 -0700 | [diff] [blame] | 272 | |
Rafael J. Wysocki | 35cd133 | 2011-12-18 00:34:13 +0100 | [diff] [blame] | 273 | All phases use PM domain, bus, type, class or driver callbacks (that is, methods |
| 274 | defined in dev->pm_domain->ops, dev->bus->pm, dev->type->pm, dev->class->pm or |
| 275 | dev->driver->pm). These callbacks are regarded by the PM core as mutually |
| 276 | exclusive. Moreover, PM domain callbacks always take precedence over all of the |
| 277 | other callbacks and, for example, type callbacks take precedence over bus, class |
| 278 | and driver callbacks. To be precise, the following rules are used to determine |
| 279 | which callback to execute in the given phase: |
Rafael J. Wysocki | 5841eb6 | 2011-11-23 21:18:39 +0100 | [diff] [blame] | 280 | |
Rafael J. Wysocki | 35cd133 | 2011-12-18 00:34:13 +0100 | [diff] [blame] | 281 | 1. If dev->pm_domain is present, the PM core will choose the callback |
| 282 | included in dev->pm_domain->ops for execution |
Rafael J. Wysocki | 5841eb6 | 2011-11-23 21:18:39 +0100 | [diff] [blame] | 283 | |
| 284 | 2. Otherwise, if both dev->type and dev->type->pm are present, the callback |
Rafael J. Wysocki | 35cd133 | 2011-12-18 00:34:13 +0100 | [diff] [blame] | 285 | included in dev->type->pm will be chosen for execution. |
Rafael J. Wysocki | 5841eb6 | 2011-11-23 21:18:39 +0100 | [diff] [blame] | 286 | |
| 287 | 3. Otherwise, if both dev->class and dev->class->pm are present, the |
Rafael J. Wysocki | 35cd133 | 2011-12-18 00:34:13 +0100 | [diff] [blame] | 288 | callback included in dev->class->pm will be chosen for execution. |
Rafael J. Wysocki | 5841eb6 | 2011-11-23 21:18:39 +0100 | [diff] [blame] | 289 | |
| 290 | 4. Otherwise, if both dev->bus and dev->bus->pm are present, the callback |
Rafael J. Wysocki | 35cd133 | 2011-12-18 00:34:13 +0100 | [diff] [blame] | 291 | included in dev->bus->pm will be chosen for execution. |
Rafael J. Wysocki | 5841eb6 | 2011-11-23 21:18:39 +0100 | [diff] [blame] | 292 | |
| 293 | This allows PM domains and device types to override callbacks provided by bus |
| 294 | types or device classes if necessary. |
David Brownell | 4fc0840 | 2006-08-10 16:38:28 -0700 | [diff] [blame] | 295 | |
Rafael J. Wysocki | 35cd133 | 2011-12-18 00:34:13 +0100 | [diff] [blame] | 296 | The PM domain, type, class and bus callbacks may in turn invoke device- or |
| 297 | driver-specific methods stored in dev->driver->pm, but they don't have to do |
| 298 | that. |
| 299 | |
| 300 | If the subsystem callback chosen for execution is not present, the PM core will |
| 301 | execute the corresponding method from dev->driver->pm instead if there is one. |
David Brownell | 4fc0840 | 2006-08-10 16:38:28 -0700 | [diff] [blame] | 302 | |
Rafael J. Wysocki | 624f6ec | 2010-03-26 23:53:42 +0100 | [diff] [blame] | 303 | |
Alan Stern | d6f9cda | 2010-03-26 23:53:55 +0100 | [diff] [blame] | 304 | Entering System Suspend |
| 305 | ----------------------- |
| 306 | When the system goes into the standby or memory sleep state, the phases are: |
Rafael J. Wysocki | 624f6ec | 2010-03-26 23:53:42 +0100 | [diff] [blame] | 307 | |
Alan Stern | d6f9cda | 2010-03-26 23:53:55 +0100 | [diff] [blame] | 308 | prepare, suspend, suspend_noirq. |
Rafael J. Wysocki | 624f6ec | 2010-03-26 23:53:42 +0100 | [diff] [blame] | 309 | |
Alan Stern | d6f9cda | 2010-03-26 23:53:55 +0100 | [diff] [blame] | 310 | 1. The prepare phase is meant to prevent races by preventing new devices |
| 311 | from being registered; the PM core would never know that all the |
| 312 | children of a device had been suspended if new children could be |
| 313 | registered at will. (By contrast, devices may be unregistered at any |
| 314 | time.) Unlike the other suspend-related phases, during the prepare |
| 315 | phase the device tree is traversed top-down. |
Rafael J. Wysocki | 624f6ec | 2010-03-26 23:53:42 +0100 | [diff] [blame] | 316 | |
Rafael J. Wysocki | 91e7c75 | 2011-05-17 23:26:00 +0200 | [diff] [blame] | 317 | After the prepare callback method returns, no new children may be |
| 318 | registered below the device. The method may also prepare the device or |
Rafael J. Wysocki | fa8ce72 | 2011-11-23 21:19:57 +0100 | [diff] [blame] | 319 | driver in some way for the upcoming system power transition, but it |
| 320 | should not put the device into a low-power state. |
Alan Stern | d6f9cda | 2010-03-26 23:53:55 +0100 | [diff] [blame] | 321 | |
| 322 | 2. The suspend methods should quiesce the device to stop it from performing |
| 323 | I/O. They also may save the device registers and put it into the |
| 324 | appropriate low-power state, depending on the bus type the device is on, |
| 325 | and they may enable wakeup events. |
| 326 | |
| 327 | 3. The suspend_noirq phase occurs after IRQ handlers have been disabled, |
| 328 | which means that the driver's interrupt handler will not be called while |
| 329 | the callback method is running. The methods should save the values of |
| 330 | the device's registers that weren't saved previously and finally put the |
| 331 | device into the appropriate low-power state. |
Rafael J. Wysocki | 624f6ec | 2010-03-26 23:53:42 +0100 | [diff] [blame] | 332 | |
| 333 | The majority of subsystems and device drivers need not implement this |
Alan Stern | d6f9cda | 2010-03-26 23:53:55 +0100 | [diff] [blame] | 334 | callback. However, bus types allowing devices to share interrupt |
| 335 | vectors, like PCI, generally need it; otherwise a driver might encounter |
| 336 | an error during the suspend phase by fielding a shared interrupt |
| 337 | generated by some other device after its own device had been set to low |
| 338 | power. |
David Brownell | 4fc0840 | 2006-08-10 16:38:28 -0700 | [diff] [blame] | 339 | |
Alan Stern | d6f9cda | 2010-03-26 23:53:55 +0100 | [diff] [blame] | 340 | At the end of these phases, drivers should have stopped all I/O transactions |
| 341 | (DMA, IRQs), saved enough state that they can re-initialize or restore previous |
| 342 | state (as needed by the hardware), and placed the device into a low-power state. |
| 343 | On many platforms they will gate off one or more clock sources; sometimes they |
| 344 | will also switch off power supplies or reduce voltages. (Drivers supporting |
| 345 | runtime PM may already have performed some or all of these steps.) |
David Brownell | 4fc0840 | 2006-08-10 16:38:28 -0700 | [diff] [blame] | 346 | |
Rafael J. Wysocki | 624f6ec | 2010-03-26 23:53:42 +0100 | [diff] [blame] | 347 | If device_may_wakeup(dev) returns true, the device should be prepared for |
Alan Stern | d6f9cda | 2010-03-26 23:53:55 +0100 | [diff] [blame] | 348 | generating hardware wakeup signals to trigger a system wakeup event when the |
| 349 | system is in the sleep state. For example, enable_irq_wake() might identify |
Rafael J. Wysocki | 624f6ec | 2010-03-26 23:53:42 +0100 | [diff] [blame] | 350 | GPIO signals hooked up to a switch or other external hardware, and |
| 351 | pci_enable_wake() does something similar for the PCI PME signal. |
David Brownell | 4fc0840 | 2006-08-10 16:38:28 -0700 | [diff] [blame] | 352 | |
Alan Stern | d6f9cda | 2010-03-26 23:53:55 +0100 | [diff] [blame] | 353 | If any of these callbacks returns an error, the system won't enter the desired |
| 354 | low-power state. Instead the PM core will unwind its actions by resuming all |
| 355 | the devices that were suspended. |
David Brownell | 4fc0840 | 2006-08-10 16:38:28 -0700 | [diff] [blame] | 356 | |
Rafael J. Wysocki | 624f6ec | 2010-03-26 23:53:42 +0100 | [diff] [blame] | 357 | |
Alan Stern | d6f9cda | 2010-03-26 23:53:55 +0100 | [diff] [blame] | 358 | Leaving System Suspend |
| 359 | ---------------------- |
| 360 | When resuming from standby or memory sleep, the phases are: |
| 361 | |
| 362 | resume_noirq, resume, complete. |
| 363 | |
| 364 | 1. The resume_noirq callback methods should perform any actions needed |
| 365 | before the driver's interrupt handlers are invoked. This generally |
| 366 | means undoing the actions of the suspend_noirq phase. If the bus type |
| 367 | permits devices to share interrupt vectors, like PCI, the method should |
| 368 | bring the device and its driver into a state in which the driver can |
| 369 | recognize if the device is the source of incoming interrupts, if any, |
| 370 | and handle them correctly. |
| 371 | |
| 372 | For example, the PCI bus type's ->pm.resume_noirq() puts the device into |
| 373 | the full-power state (D0 in the PCI terminology) and restores the |
| 374 | standard configuration registers of the device. Then it calls the |
| 375 | device driver's ->pm.resume_noirq() method to perform device-specific |
| 376 | actions. |
| 377 | |
| 378 | 2. The resume methods should bring the the device back to its operating |
| 379 | state, so that it can perform normal I/O. This generally involves |
| 380 | undoing the actions of the suspend phase. |
| 381 | |
| 382 | 3. The complete phase uses only a bus callback. The method should undo the |
| 383 | actions of the prepare phase. Note, however, that new children may be |
| 384 | registered below the device as soon as the resume callbacks occur; it's |
| 385 | not necessary to wait until the complete phase. |
| 386 | |
| 387 | At the end of these phases, drivers should be as functional as they were before |
| 388 | suspending: I/O can be performed using DMA and IRQs, and the relevant clocks are |
| 389 | gated on. Even if the device was in a low-power state before the system sleep |
| 390 | because of runtime power management, afterwards it should be back in its |
| 391 | full-power state. There are multiple reasons why it's best to do this; they are |
| 392 | discussed in more detail in Documentation/power/runtime_pm.txt. |
| 393 | |
| 394 | However, the details here may again be platform-specific. For example, |
| 395 | some systems support multiple "run" states, and the mode in effect at |
| 396 | the end of resume might not be the one which preceded suspension. |
| 397 | That means availability of certain clocks or power supplies changed, |
| 398 | which could easily affect how a driver works. |
| 399 | |
| 400 | Drivers need to be able to handle hardware which has been reset since the |
| 401 | suspend methods were called, for example by complete reinitialization. |
| 402 | This may be the hardest part, and the one most protected by NDA'd documents |
| 403 | and chip errata. It's simplest if the hardware state hasn't changed since |
Lucas De Marchi | 25985ed | 2011-03-30 22:57:33 -0300 | [diff] [blame] | 404 | the suspend was carried out, but that can't be guaranteed (in fact, it usually |
Alan Stern | d6f9cda | 2010-03-26 23:53:55 +0100 | [diff] [blame] | 405 | is not the case). |
| 406 | |
| 407 | Drivers must also be prepared to notice that the device has been removed |
| 408 | while the system was powered down, whenever that's physically possible. |
| 409 | PCMCIA, MMC, USB, Firewire, SCSI, and even IDE are common examples of busses |
| 410 | where common Linux platforms will see such removal. Details of how drivers |
| 411 | will notice and handle such removals are currently bus-specific, and often |
| 412 | involve a separate thread. |
| 413 | |
| 414 | These callbacks may return an error value, but the PM core will ignore such |
| 415 | errors since there's nothing it can do about them other than printing them in |
| 416 | the system log. |
| 417 | |
| 418 | |
| 419 | Entering Hibernation |
| 420 | -------------------- |
Rafael J. Wysocki | 624f6ec | 2010-03-26 23:53:42 +0100 | [diff] [blame] | 421 | Hibernating the system is more complicated than putting it into the standby or |
Alan Stern | d6f9cda | 2010-03-26 23:53:55 +0100 | [diff] [blame] | 422 | memory sleep state, because it involves creating and saving a system image. |
| 423 | Therefore there are more phases for hibernation, with a different set of |
| 424 | callbacks. These phases always run after tasks have been frozen and memory has |
| 425 | been freed. |
Rafael J. Wysocki | 624f6ec | 2010-03-26 23:53:42 +0100 | [diff] [blame] | 426 | |
Alan Stern | d6f9cda | 2010-03-26 23:53:55 +0100 | [diff] [blame] | 427 | The general procedure for hibernation is to quiesce all devices (freeze), create |
| 428 | an image of the system memory while everything is stable, reactivate all |
| 429 | devices (thaw), write the image to permanent storage, and finally shut down the |
| 430 | system (poweroff). The phases used to accomplish this are: |
Rafael J. Wysocki | 624f6ec | 2010-03-26 23:53:42 +0100 | [diff] [blame] | 431 | |
Alan Stern | d6f9cda | 2010-03-26 23:53:55 +0100 | [diff] [blame] | 432 | prepare, freeze, freeze_noirq, thaw_noirq, thaw, complete, |
| 433 | prepare, poweroff, poweroff_noirq |
Rafael J. Wysocki | 624f6ec | 2010-03-26 23:53:42 +0100 | [diff] [blame] | 434 | |
Alan Stern | d6f9cda | 2010-03-26 23:53:55 +0100 | [diff] [blame] | 435 | 1. The prepare phase is discussed in the "Entering System Suspend" section |
| 436 | above. |
Rafael J. Wysocki | 624f6ec | 2010-03-26 23:53:42 +0100 | [diff] [blame] | 437 | |
Alan Stern | d6f9cda | 2010-03-26 23:53:55 +0100 | [diff] [blame] | 438 | 2. The freeze methods should quiesce the device so that it doesn't generate |
| 439 | IRQs or DMA, and they may need to save the values of device registers. |
| 440 | However the device does not have to be put in a low-power state, and to |
| 441 | save time it's best not to do so. Also, the device should not be |
| 442 | prepared to generate wakeup events. |
Rafael J. Wysocki | 624f6ec | 2010-03-26 23:53:42 +0100 | [diff] [blame] | 443 | |
Alan Stern | d6f9cda | 2010-03-26 23:53:55 +0100 | [diff] [blame] | 444 | 3. The freeze_noirq phase is analogous to the suspend_noirq phase discussed |
| 445 | above, except again that the device should not be put in a low-power |
| 446 | state and should not be allowed to generate wakeup events. |
Rafael J. Wysocki | 624f6ec | 2010-03-26 23:53:42 +0100 | [diff] [blame] | 447 | |
Alan Stern | d6f9cda | 2010-03-26 23:53:55 +0100 | [diff] [blame] | 448 | At this point the system image is created. All devices should be inactive and |
| 449 | the contents of memory should remain undisturbed while this happens, so that the |
| 450 | image forms an atomic snapshot of the system state. |
Rafael J. Wysocki | 624f6ec | 2010-03-26 23:53:42 +0100 | [diff] [blame] | 451 | |
Alan Stern | d6f9cda | 2010-03-26 23:53:55 +0100 | [diff] [blame] | 452 | 4. The thaw_noirq phase is analogous to the resume_noirq phase discussed |
| 453 | above. The main difference is that its methods can assume the device is |
| 454 | in the same state as at the end of the freeze_noirq phase. |
Rafael J. Wysocki | 624f6ec | 2010-03-26 23:53:42 +0100 | [diff] [blame] | 455 | |
Alan Stern | d6f9cda | 2010-03-26 23:53:55 +0100 | [diff] [blame] | 456 | 5. The thaw phase is analogous to the resume phase discussed above. Its |
| 457 | methods should bring the device back to an operating state, so that it |
| 458 | can be used for saving the image if necessary. |
Rafael J. Wysocki | 624f6ec | 2010-03-26 23:53:42 +0100 | [diff] [blame] | 459 | |
Alan Stern | d6f9cda | 2010-03-26 23:53:55 +0100 | [diff] [blame] | 460 | 6. The complete phase is discussed in the "Leaving System Suspend" section |
| 461 | above. |
Rafael J. Wysocki | 624f6ec | 2010-03-26 23:53:42 +0100 | [diff] [blame] | 462 | |
Alan Stern | d6f9cda | 2010-03-26 23:53:55 +0100 | [diff] [blame] | 463 | At this point the system image is saved, and the devices then need to be |
| 464 | prepared for the upcoming system shutdown. This is much like suspending them |
| 465 | before putting the system into the standby or memory sleep state, and the phases |
| 466 | are similar. |
Rafael J. Wysocki | 624f6ec | 2010-03-26 23:53:42 +0100 | [diff] [blame] | 467 | |
Alan Stern | d6f9cda | 2010-03-26 23:53:55 +0100 | [diff] [blame] | 468 | 7. The prepare phase is discussed above. |
Rafael J. Wysocki | 624f6ec | 2010-03-26 23:53:42 +0100 | [diff] [blame] | 469 | |
Alan Stern | d6f9cda | 2010-03-26 23:53:55 +0100 | [diff] [blame] | 470 | 8. The poweroff phase is analogous to the suspend phase. |
Rafael J. Wysocki | 624f6ec | 2010-03-26 23:53:42 +0100 | [diff] [blame] | 471 | |
Alan Stern | d6f9cda | 2010-03-26 23:53:55 +0100 | [diff] [blame] | 472 | 9. The poweroff_noirq phase is analogous to the suspend_noirq phase. |
Rafael J. Wysocki | 624f6ec | 2010-03-26 23:53:42 +0100 | [diff] [blame] | 473 | |
Alan Stern | d6f9cda | 2010-03-26 23:53:55 +0100 | [diff] [blame] | 474 | The poweroff and poweroff_noirq callbacks should do essentially the same things |
| 475 | as the suspend and suspend_noirq callbacks. The only notable difference is that |
| 476 | they need not store the device register values, because the registers should |
| 477 | already have been stored during the freeze or freeze_noirq phases. |
Rafael J. Wysocki | 624f6ec | 2010-03-26 23:53:42 +0100 | [diff] [blame] | 478 | |
Rafael J. Wysocki | 624f6ec | 2010-03-26 23:53:42 +0100 | [diff] [blame] | 479 | |
Alan Stern | d6f9cda | 2010-03-26 23:53:55 +0100 | [diff] [blame] | 480 | Leaving Hibernation |
| 481 | ------------------- |
| 482 | Resuming from hibernation is, again, more complicated than resuming from a sleep |
| 483 | state in which the contents of main memory are preserved, because it requires |
| 484 | a system image to be loaded into memory and the pre-hibernation memory contents |
| 485 | to be restored before control can be passed back to the image kernel. |
Rafael J. Wysocki | 624f6ec | 2010-03-26 23:53:42 +0100 | [diff] [blame] | 486 | |
Alan Stern | d6f9cda | 2010-03-26 23:53:55 +0100 | [diff] [blame] | 487 | Although in principle, the image might be loaded into memory and the |
| 488 | pre-hibernation memory contents restored by the boot loader, in practice this |
| 489 | can't be done because boot loaders aren't smart enough and there is no |
| 490 | established protocol for passing the necessary information. So instead, the |
| 491 | boot loader loads a fresh instance of the kernel, called the boot kernel, into |
| 492 | memory and passes control to it in the usual way. Then the boot kernel reads |
| 493 | the system image, restores the pre-hibernation memory contents, and passes |
| 494 | control to the image kernel. Thus two different kernels are involved in |
| 495 | resuming from hibernation. In fact, the boot kernel may be completely different |
| 496 | from the image kernel: a different configuration and even a different version. |
| 497 | This has important consequences for device drivers and their subsystems. |
Rafael J. Wysocki | 624f6ec | 2010-03-26 23:53:42 +0100 | [diff] [blame] | 498 | |
Alan Stern | d6f9cda | 2010-03-26 23:53:55 +0100 | [diff] [blame] | 499 | To be able to load the system image into memory, the boot kernel needs to |
| 500 | include at least a subset of device drivers allowing it to access the storage |
| 501 | medium containing the image, although it doesn't need to include all of the |
| 502 | drivers present in the image kernel. After the image has been loaded, the |
| 503 | devices managed by the boot kernel need to be prepared for passing control back |
| 504 | to the image kernel. This is very similar to the initial steps involved in |
| 505 | creating a system image, and it is accomplished in the same way, using prepare, |
| 506 | freeze, and freeze_noirq phases. However the devices affected by these phases |
| 507 | are only those having drivers in the boot kernel; other devices will still be in |
| 508 | whatever state the boot loader left them. |
Rafael J. Wysocki | 624f6ec | 2010-03-26 23:53:42 +0100 | [diff] [blame] | 509 | |
Alan Stern | d6f9cda | 2010-03-26 23:53:55 +0100 | [diff] [blame] | 510 | Should the restoration of the pre-hibernation memory contents fail, the boot |
| 511 | kernel would go through the "thawing" procedure described above, using the |
| 512 | thaw_noirq, thaw, and complete phases, and then continue running normally. This |
| 513 | happens only rarely. Most often the pre-hibernation memory contents are |
| 514 | restored successfully and control is passed to the image kernel, which then |
| 515 | becomes responsible for bringing the system back to the working state. |
Rafael J. Wysocki | 624f6ec | 2010-03-26 23:53:42 +0100 | [diff] [blame] | 516 | |
Alan Stern | d6f9cda | 2010-03-26 23:53:55 +0100 | [diff] [blame] | 517 | To achieve this, the image kernel must restore the devices' pre-hibernation |
| 518 | functionality. The operation is much like waking up from the memory sleep |
| 519 | state, although it involves different phases: |
Rafael J. Wysocki | 624f6ec | 2010-03-26 23:53:42 +0100 | [diff] [blame] | 520 | |
Alan Stern | d6f9cda | 2010-03-26 23:53:55 +0100 | [diff] [blame] | 521 | restore_noirq, restore, complete |
| 522 | |
| 523 | 1. The restore_noirq phase is analogous to the resume_noirq phase. |
| 524 | |
| 525 | 2. The restore phase is analogous to the resume phase. |
| 526 | |
| 527 | 3. The complete phase is discussed above. |
| 528 | |
| 529 | The main difference from resume[_noirq] is that restore[_noirq] must assume the |
| 530 | device has been accessed and reconfigured by the boot loader or the boot kernel. |
| 531 | Consequently the state of the device may be different from the state remembered |
| 532 | from the freeze and freeze_noirq phases. The device may even need to be reset |
| 533 | and completely re-initialized. In many cases this difference doesn't matter, so |
| 534 | the resume[_noirq] and restore[_norq] method pointers can be set to the same |
| 535 | routines. Nevertheless, different callback pointers are used in case there is a |
| 536 | situation where it actually matters. |
| 537 | |
| 538 | |
Rafael J. Wysocki | 564b905 | 2011-06-23 01:52:55 +0200 | [diff] [blame] | 539 | Device Power Management Domains |
| 540 | ------------------------------- |
Rafael J. Wysocki | 7538e3d | 2011-02-16 21:53:17 +0100 | [diff] [blame] | 541 | Sometimes devices share reference clocks or other power resources. In those |
| 542 | cases it generally is not possible to put devices into low-power states |
| 543 | individually. Instead, a set of devices sharing a power resource can be put |
| 544 | into a low-power state together at the same time by turning off the shared |
| 545 | power resource. Of course, they also need to be put into the full-power state |
| 546 | together, by turning the shared power resource on. A set of devices with this |
| 547 | property is often referred to as a power domain. |
| 548 | |
Rafael J. Wysocki | 564b905 | 2011-06-23 01:52:55 +0200 | [diff] [blame] | 549 | Support for power domains is provided through the pm_domain field of struct |
| 550 | device. This field is a pointer to an object of type struct dev_pm_domain, |
Rafael J. Wysocki | 7538e3d | 2011-02-16 21:53:17 +0100 | [diff] [blame] | 551 | defined in include/linux/pm.h, providing a set of power management callbacks |
| 552 | analogous to the subsystem-level and device driver callbacks that are executed |
Rafael J. Wysocki | ca9c689 | 2011-06-21 23:25:32 +0200 | [diff] [blame] | 553 | for the given device during all power transitions, instead of the respective |
| 554 | subsystem-level callbacks. Specifically, if a device's pm_domain pointer is |
| 555 | not NULL, the ->suspend() callback from the object pointed to by it will be |
| 556 | executed instead of its subsystem's (e.g. bus type's) ->suspend() callback and |
| 557 | anlogously for all of the remaining callbacks. In other words, power management |
| 558 | domain callbacks, if defined for the given device, always take precedence over |
| 559 | the callbacks provided by the device's subsystem (e.g. bus type). |
Rafael J. Wysocki | 7538e3d | 2011-02-16 21:53:17 +0100 | [diff] [blame] | 560 | |
Rafael J. Wysocki | ca9c689 | 2011-06-21 23:25:32 +0200 | [diff] [blame] | 561 | The support for device power management domains is only relevant to platforms |
| 562 | needing to use the same device driver power management callbacks in many |
| 563 | different power domain configurations and wanting to avoid incorporating the |
| 564 | support for power domains into subsystem-level callbacks, for example by |
| 565 | modifying the platform bus type. Other platforms need not implement it or take |
| 566 | it into account in any way. |
Rafael J. Wysocki | 7538e3d | 2011-02-16 21:53:17 +0100 | [diff] [blame] | 567 | |
| 568 | |
David Brownell | 4fc0840 | 2006-08-10 16:38:28 -0700 | [diff] [blame] | 569 | Device Low Power (suspend) States |
| 570 | --------------------------------- |
Rafael J. Wysocki | 624f6ec | 2010-03-26 23:53:42 +0100 | [diff] [blame] | 571 | Device low-power states aren't standard. One device might only handle |
David Brownell | 4fc0840 | 2006-08-10 16:38:28 -0700 | [diff] [blame] | 572 | "on" and "off, while another might support a dozen different versions of |
| 573 | "on" (how many engines are active?), plus a state that gets back to "on" |
| 574 | faster than from a full "off". |
| 575 | |
| 576 | Some busses define rules about what different suspend states mean. PCI |
| 577 | gives one example: after the suspend sequence completes, a non-legacy |
| 578 | PCI device may not perform DMA or issue IRQs, and any wakeup events it |
| 579 | issues would be issued through the PME# bus signal. Plus, there are |
| 580 | several PCI-standard device states, some of which are optional. |
| 581 | |
Rafael J. Wysocki | 624f6ec | 2010-03-26 23:53:42 +0100 | [diff] [blame] | 582 | In contrast, integrated system-on-chip processors often use IRQs as the |
David Brownell | 4fc0840 | 2006-08-10 16:38:28 -0700 | [diff] [blame] | 583 | wakeup event sources (so drivers would call enable_irq_wake) and might |
| 584 | be able to treat DMA completion as a wakeup event (sometimes DMA can stay |
| 585 | active too, it'd only be the CPU and some peripherals that sleep). |
| 586 | |
| 587 | Some details here may be platform-specific. Systems may have devices that |
| 588 | can be fully active in certain sleep states, such as an LCD display that's |
| 589 | refreshed using DMA while most of the system is sleeping lightly ... and |
| 590 | its frame buffer might even be updated by a DSP or other non-Linux CPU while |
| 591 | the Linux control processor stays idle. |
| 592 | |
| 593 | Moreover, the specific actions taken may depend on the target system state. |
| 594 | One target system state might allow a given device to be very operational; |
| 595 | another might require a hard shut down with re-initialization on resume. |
| 596 | And two different target systems might use the same device in different |
| 597 | ways; the aforementioned LCD might be active in one product's "standby", |
| 598 | but a different product using the same SOC might work differently. |
| 599 | |
| 600 | |
Rafael J. Wysocki | 624f6ec | 2010-03-26 23:53:42 +0100 | [diff] [blame] | 601 | Power Management Notifiers |
| 602 | -------------------------- |
Alan Stern | d6f9cda | 2010-03-26 23:53:55 +0100 | [diff] [blame] | 603 | There are some operations that cannot be carried out by the power management |
| 604 | callbacks discussed above, because the callbacks occur too late or too early. |
| 605 | To handle these cases, subsystems and device drivers may register power |
| 606 | management notifiers that are called before tasks are frozen and after they have |
| 607 | been thawed. Generally speaking, the PM notifiers are suitable for performing |
| 608 | actions that either require user space to be available, or at least won't |
| 609 | interfere with user space. |
Rafael J. Wysocki | 624f6ec | 2010-03-26 23:53:42 +0100 | [diff] [blame] | 610 | |
| 611 | For details refer to Documentation/power/notifiers.txt. |
| 612 | |
| 613 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 614 | Runtime Power Management |
David Brownell | 4fc0840 | 2006-08-10 16:38:28 -0700 | [diff] [blame] | 615 | ======================== |
| 616 | Many devices are able to dynamically power down while the system is still |
| 617 | running. This feature is useful for devices that are not being used, and |
| 618 | can offer significant power savings on a running system. These devices |
| 619 | often support a range of runtime power states, which might use names such |
| 620 | as "off", "sleep", "idle", "active", and so on. Those states will in some |
Alan Stern | d6f9cda | 2010-03-26 23:53:55 +0100 | [diff] [blame] | 621 | cases (like PCI) be partially constrained by the bus the device uses, and will |
David Brownell | 4fc0840 | 2006-08-10 16:38:28 -0700 | [diff] [blame] | 622 | usually include hardware states that are also used in system sleep states. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 623 | |
Alan Stern | d6f9cda | 2010-03-26 23:53:55 +0100 | [diff] [blame] | 624 | A system-wide power transition can be started while some devices are in low |
| 625 | power states due to runtime power management. The system sleep PM callbacks |
| 626 | should recognize such situations and react to them appropriately, but the |
| 627 | necessary actions are subsystem-specific. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 628 | |
Alan Stern | d6f9cda | 2010-03-26 23:53:55 +0100 | [diff] [blame] | 629 | In some cases the decision may be made at the subsystem level while in other |
| 630 | cases the device driver may be left to decide. In some cases it may be |
| 631 | desirable to leave a suspended device in that state during a system-wide power |
| 632 | transition, but in other cases the device must be put back into the full-power |
| 633 | state temporarily, for example so that its system wakeup capability can be |
| 634 | disabled. This all depends on the hardware and the design of the subsystem and |
| 635 | device driver in question. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 636 | |
Rafael J. Wysocki | 455716e | 2011-07-01 22:29:05 +0200 | [diff] [blame] | 637 | During system-wide resume from a sleep state it's easiest to put devices into |
| 638 | the full-power state, as explained in Documentation/power/runtime_pm.txt. Refer |
| 639 | to that document for more information regarding this particular issue as well as |
Rafael J. Wysocki | 624f6ec | 2010-03-26 23:53:42 +0100 | [diff] [blame] | 640 | for information on the device runtime power management framework in general. |