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