Lines Matching refs:the

8 Most of the code in Linux is device drivers, so most of the Linux power
14 power management goals, emphasizing the models and interfaces that are
15 shared by everything that hooks up to the driver model core. Read it as
16 background for the domain-specific work you'd do with any specific driver.
35 Some drivers can manage hardware wakeup events, which make the system
36 leave the low-power state. This feature may be enabled or disabled
37 using the relevant /sys/devices/.../power/wakeup file (for Ethernet
38 drivers the ioctl interface used by ethtool may also be used for this
39 purpose); enabling it may cost some power usage, but let the whole
43 Devices may also be put into low-power states while the system is
47 devices have been suspended). Moreover, depending on the bus type the
49 operations on the device for this purpose. Devices put into low power
53 For these reasons not only the device driver itself, but also the
55 the PM core are involved in runtime power management. As in the system
57 various role-specific suspend and resume methods, so that the hardware
62 have been put into low-power states (at runtime), the effect may be very similar
64 synergies exist, so that several drivers using runtime PM might put the system
80 device class) and device drivers to allow them to participate in the power
87 Device power management operations, at the subsystem level as well as at the
117 This structure is defined in include/linux/pm.h and the methods included in it
119 For now, it should be sufficient to remember that the last three methods are
120 specific to runtime power management while the remaining ones are used during
127 please refer directly to the source code for more information about it.
133 pointed to by the ops member of struct dev_pm_domain, or by the pm member of
135 interest to the people writing infrastructure for platforms and buses, like PCI
136 or USB, or device type and device class drivers. They also are relevant to the
140 Bus drivers implement these methods as appropriate for the hardware and the
145 For more information on these driver calls, see the description later;
146 they are called in phases for every device, respecting the parent-child
147 sequencing in the driver model tree.
152 All device objects in the driver model contain fields that control the handling
153 of system wakeup events (hardware signals that can force the system out of a
158 The "power.can_wakeup" flag just records whether the device (and its driver) can
161 struct wakeup_source used for controlling whether or not the device should use
162 its system wakeup mechanism and for notifying the PM core of system wakeup
163 events signaled by the device. This object is only present for wakeup-capable
168 matter, and the kernel is responsible for keeping track of it. By contrast,
170 decision, and it is managed by user space through a sysfs attribute: the
171 "power/wakeup" file. User space can write the strings "enabled" or "disabled"
172 to it to indicate whether or not, respectively, the device is supposed to signal
173 system wakeup. This file is only present if the "power.wakeup" object exists
174 for the given device and is created (or removed) along with that object, by
175 device_set_wakeup_capable(). Reads from the file will return the corresponding
178 The "power/wakeup" file is supposed to contain the "disabled" string initially
179 for the majority of devices; the major exceptions are power buttons, keyboards,
185 The device_may_wakeup() routine returns true only if the "power.wakeup" object
186 exists and the corresponding "power/wakeup" file contains the string "enabled".
187 This information is used by subsystems, like the PCI bus type code, to see
188 whether or not to enable the devices' wakeup mechanisms. If device wakeup
195 wakeup" used by runtime power management, although it may be supported by the
198 they should be put into the full-power state. Those interrupts may or may not
199 be used to signal system wakeup events, depending on the hardware design. On
206 Each device in the driver model has a flag to control whether it is subject to
207 runtime power management. This flag, called runtime_auto, is initialized by the
209 pm_runtime_forbid(); the default is to allow runtime power management.
212 the device's power/control sysfs file. Writing "auto" calls pm_runtime_allow(),
213 setting the flag and allowing the device to be runtime power-managed by its
214 driver. Writing "on" calls pm_runtime_forbid(), clearing the flag, returning
215 the device to full power if it was in a low-power state, and preventing the
216 device from being runtime power-managed. User space can check the current value
217 of the runtime_auto flag by reading the file.
219 The device's runtime_auto flag has no effect on the handling of system-wide
220 power transitions. In particular, the device can (and in the majority of cases
224 For more information about the runtime power management framework, refer to
230 When the system goes into a sleep state, each device's driver is asked to
231 suspend the device by putting it into a state compatible with the target
232 system state. That's usually some version of "off", but the details are
234 functional in order to wake the system.
236 When the system leaves that low-power state, the device's driver is asked to
240 For simple drivers, suspend might quiesce the device using class code
242 matching resume calls would then completely reinitialize the hardware
245 More power-aware drivers might prepare the devices for triggering system wakeup
252 available when the device is suspended or resumed, the device tree is
256 The ordering of the device tree is defined by the order in which devices
260 The policy is that the device tree should match hardware bus topology.
261 (Or at least the control bus, for devices which use multiple busses.)
262 In particular, this means that a device registration may fail if the parent of
263 the device is suspending (i.e. has been chosen by the PM core as the next
264 device to suspend) or has already suspended, as well as after all of the other
271 Suspending or resuming the system is done in several phases. Different phases
272 are used for freeze, standby, and memory sleep states ("suspend-to-RAM") and the
274 for every device before the next phase begins. Not all busses or classes
275 support all these callbacks and not all drivers use all the callbacks. The
277 unfrozen. Furthermore, the *_noirq phases run at a time when IRQ handlers have
278 been disabled (except for those marked with the IRQF_NO_SUSPEND flag).
282 dev->driver->pm). These callbacks are regarded by the PM core as mutually
283 exclusive. Moreover, PM domain callbacks always take precedence over all of the
285 and driver callbacks. To be precise, the following rules are used to determine
286 which callback to execute in the given phase:
288 1. If dev->pm_domain is present, the PM core will choose the callback
291 2. Otherwise, if both dev->type and dev->type->pm are present, the callback
294 3. Otherwise, if both dev->class and dev->class->pm are present, the
297 4. Otherwise, if both dev->bus and dev->bus->pm are present, the callback
307 If the subsystem callback chosen for execution is not present, the PM core will
308 execute the corresponding method from dev->driver->pm instead if there is one.
313 When the system goes into the freeze, standby or memory sleep state,
314 the phases are:
319 from being registered; the PM core would never know that all the
322 time.) Unlike the other suspend-related phases, during the prepare
323 phase the device tree is traversed top-down.
325 After the prepare callback method returns, no new children may be
326 registered below the device. The method may also prepare the device or
327 driver in some way for the upcoming system power transition, but it
328 should not put the device into a low-power state.
330 For devices supporting runtime power management, the return value of the
331 prepare callback can be used to indicate to the PM core that it may
332 safely leave the device in runtime suspend (if runtime-suspended
333 already), provided that all of the device's descendants are also left in
334 runtime suspend. Namely, if the prepare callback returns a positive
335 number and that happens for all of the descendants of the device too,
336 and all of them (including the device itself) are runtime-suspended, the
337 PM core will skip the suspend, suspend_late and suspend_noirq suspend
338 phases as well as the resume_noirq, resume_early and resume phases of
339 the following system resume for all of these devices. In that case,
340 the complete callback will be called directly after the prepare callback
341 and is entirely responsible for bringing the device back to the
344 2. The suspend methods should quiesce the device to stop it from performing
345 I/O. They also may save the device registers and put it into the
346 appropriate low-power state, depending on the bus type the device is on,
349 3 For a number of devices it is convenient to split suspend into the
351 suspend_late is meant to do the latter. It is always executed after
355 which means that the driver's interrupt handler will not be called while
356 the callback method is running. The methods should save the values of
357 the device's registers that weren't saved previously and finally put the
358 device into the appropriate low-power state.
363 an error during the suspend phase by fielding a shared interrupt
367 At the end of these phases, drivers should have stopped all I/O transactions
369 state (as needed by the hardware), and placed the device into a low-power state.
374 If device_may_wakeup(dev) returns true, the device should be prepared for
375 generating hardware wakeup signals to trigger a system wakeup event when the
376 system is in the sleep state. For example, enable_irq_wake() might identify
378 pci_enable_wake() does something similar for the PCI PME signal.
380 If any of these callbacks returns an error, the system won't enter the desired
381 low-power state. Instead the PM core will unwind its actions by resuming all
382 the devices that were suspended.
387 When resuming from freeze, standby or memory sleep, the phases are:
392 before the driver's interrupt handlers are invoked. This generally
393 means undoing the actions of the suspend_noirq phase. If the bus type
394 permits devices to share interrupt vectors, like PCI, the method should
395 bring the device and its driver into a state in which the driver can
396 recognize if the device is the source of incoming interrupts, if any,
399 For example, the PCI bus type's ->pm.resume_noirq() puts the device into
400 the full-power state (D0 in the PCI terminology) and restores the
401 standard configuration registers of the device. Then it calls the
405 2. The resume_early methods should prepare devices for the execution of
406 the resume methods. This generally involves undoing the actions of the
409 3 The resume methods should bring the device back to its operating
411 undoing the actions of the suspend phase.
413 4. The complete phase should undo the actions of the prepare phase. Note,
414 however, that new children may be registered below the device as soon as
415 the resume callbacks occur; it's not necessary to wait until the
418 Moreover, if the preceding prepare callback returned a positive number,
419 the device may have been left in runtime suspend throughout the whole
420 system suspend and resume (the suspend, suspend_late, suspend_noirq
421 phases of system suspend and the resume_noirq, resume_early, resume
423 the complete callback is entirely responsible for bringing the device
424 back to the functional state after system suspend if necessary. [For
425 example, it may need to queue up a runtime resume request for the device
426 for this purpose.] To check if that is the case, the complete callback
427 can consult the device's power.direct_complete flag. Namely, if that
428 flag is set when the complete callback is being run, it has been called
429 directly after the preceding prepare and special action may be required
430 to make the device work correctly afterward.
432 At the end of these phases, drivers should be as functional as they were before
433 suspending: I/O can be performed using DMA and IRQs, and the relevant clocks are
436 However, the details here may again be platform-specific. For example,
437 some systems support multiple "run" states, and the mode in effect at
438 the end of resume might not be the one which preceded suspension.
442 Drivers need to be able to handle hardware which has been reset since the
444 This may be the hardest part, and the one most protected by NDA'd documents
445 and chip errata. It's simplest if the hardware state hasn't changed since
446 the suspend was carried out, but that can't be guaranteed (in fact, it usually
447 is not the case).
449 Drivers must also be prepared to notice that the device has been removed
450 while the system was powered down, whenever that's physically possible.
456 These callbacks may return an error value, but the PM core will ignore such
458 the system log.
463 Hibernating the system is more complicated than putting it into the other
470 an image of the system memory while everything is stable, reactivate all
471 devices (thaw), write the image to permanent storage, and finally shut down the
477 1. The prepare phase is discussed in the "Entering System Suspend" section
480 2. The freeze methods should quiesce the device so that it doesn't generate
481 IRQs or DMA, and they may need to save the values of device registers.
482 However the device does not have to be put in a low-power state, and to
483 save time it's best not to do so. Also, the device should not be
486 3. The freeze_late phase is analogous to the suspend_late phase described
487 above, except that the device should not be put in a low-power state and
490 4. The freeze_noirq phase is analogous to the suspend_noirq phase discussed
491 above, except again that the device should not be put in a low-power
494 At this point the system image is created. All devices should be inactive and
495 the contents of memory should remain undisturbed while this happens, so that the
496 image forms an atomic snapshot of the system state.
498 5. The thaw_noirq phase is analogous to the resume_noirq phase discussed
499 above. The main difference is that its methods can assume the device is
500 in the same state as at the end of the freeze_noirq phase.
502 6. The thaw_early phase is analogous to the resume_early phase described
503 above. Its methods should undo the actions of the preceding
506 7. The thaw phase is analogous to the resume phase discussed above. Its
507 methods should bring the device back to an operating state, so that it
508 can be used for saving the image if necessary.
510 8. The complete phase is discussed in the "Leaving System Suspend" section
513 At this point the system image is saved, and the devices then need to be
514 prepared for the upcoming system shutdown. This is much like suspending them
515 before putting the system into the freeze, standby or memory sleep state,
516 and the phases are similar.
520 10. The poweroff phase is analogous to the suspend phase.
522 11. The poweroff_late phase is analogous to the suspend_late phase.
524 12. The poweroff_noirq phase is analogous to the suspend_noirq phase.
527 the same things as the suspend, suspend_late and suspend_noirq callbacks,
528 respectively. The only notable difference is that they need not store the
529 device register values, because the registers should already have been stored
530 during the freeze, freeze_late or freeze_noirq phases.
536 state in which the contents of main memory are preserved, because it requires
537 a system image to be loaded into memory and the pre-hibernation memory contents
538 to be restored before control can be passed back to the image kernel.
540 Although in principle, the image might be loaded into memory and the
541 pre-hibernation memory contents restored by the boot loader, in practice this
543 established protocol for passing the necessary information. So instead, the
544 boot loader loads a fresh instance of the kernel, called the boot kernel, into
545 memory and passes control to it in the usual way. Then the boot kernel reads
546 the system image, restores the pre-hibernation memory contents, and passes
547 control to the image kernel. Thus two different kernels are involved in
548 resuming from hibernation. In fact, the boot kernel may be completely different
549 from the image kernel: a different configuration and even a different version.
552 To be able to load the system image into memory, the boot kernel needs to
553 include at least a subset of device drivers allowing it to access the storage
554 medium containing the image, although it doesn't need to include all of the
555 drivers present in the image kernel. After the image has been loaded, the
556 devices managed by the boot kernel need to be prepared for passing control back
557 to the image kernel. This is very similar to the initial steps involved in
558 creating a system image, and it is accomplished in the same way, using prepare,
559 freeze, and freeze_noirq phases. However the devices affected by these phases
560 are only those having drivers in the boot kernel; other devices will still be in
561 whatever state the boot loader left them.
563 Should the restoration of the pre-hibernation memory contents fail, the boot
564 kernel would go through the "thawing" procedure described above, using the
566 happens only rarely. Most often the pre-hibernation memory contents are
567 restored successfully and control is passed to the image kernel, which then
568 becomes responsible for bringing the system back to the working state.
570 To achieve this, the image kernel must restore the devices' pre-hibernation
571 functionality. The operation is much like waking up from the memory sleep
576 1. The restore_noirq phase is analogous to the resume_noirq phase.
578 2. The restore_early phase is analogous to the resume_early phase.
580 3. The restore phase is analogous to the resume phase.
585 must assume the device has been accessed and reconfigured by the boot loader or
586 the boot kernel. Consequently the state of the device may be different from the
587 state remembered from the freeze, freeze_late and freeze_noirq phases. The
589 this difference doesn't matter, so the resume[_early|_noirq] and
590 restore[_early|_norq] method pointers can be set to the same routines.
600 into a low-power state together at the same time by turning off the shared
601 power resource. Of course, they also need to be put into the full-power state
602 together, by turning the shared power resource on. A set of devices with this
605 Support for power domains is provided through the pm_domain field of struct
608 analogous to the subsystem-level and device driver callbacks that are executed
609 for the given device during all power transitions, instead of the respective
611 not NULL, the ->suspend() callback from the object pointed to by it will be
613 analogously for all of the remaining callbacks. In other words, power
614 management domain callbacks, if defined for the given device, always take
615 precedence over the callbacks provided by the device's subsystem (e.g. bus
619 needing to use the same device driver power management callbacks in many
620 different power domain configurations and wanting to avoid incorporating the
622 modifying the platform bus type. Other platforms need not implement it or take
634 gives one example: after the suspend sequence completes, a non-legacy
636 issues would be issued through the PME# bus signal. Plus, there are
639 In contrast, integrated system-on-chip processors often use IRQs as the
642 active too, it'd only be the CPU and some peripherals that sleep).
646 refreshed using DMA while most of the system is sleeping lightly ... and
648 the Linux control processor stays idle.
650 Moreover, the specific actions taken may depend on the target system state.
653 And two different target systems might use the same device in different
654 ways; the aforementioned LCD might be active in one product's "standby",
655 but a different product using the same SOC might work differently.
660 There are some operations that cannot be carried out by the power management
661 callbacks discussed above, because the callbacks occur too late or too early.
664 been thawed. Generally speaking, the PM notifiers are suitable for performing
673 Many devices are able to dynamically power down while the system is still
678 cases (like PCI) be partially constrained by the bus the device uses, and will
683 should recognize such situations and react to them appropriately, but the
686 In some cases the decision may be made at the subsystem level while in other
687 cases the device driver may be left to decide. In some cases it may be
689 transition, but in other cases the device must be put back into the full-power
691 disabled. This all depends on the hardware and the design of the subsystem and
695 the full-power state, as explained in Documentation/power/runtime_pm.txt. Refer
697 for information on the device runtime power management framework in general.