Lines Matching +full:disable +full:- +full:port +full:- +full:power +full:- +full:control

1 .. _usb-power-management:
3 Power Management for USB
7 :Date: Last-updated: February 2014
11 ---------
12 * What is Power Management?
17 * Changing the default idle-delay time
19 * The driver interface for Power Management
25 * USB Port Power Control
26 * User Interface for Port Power Control
27 * Suggested Userspace Port Power Policy
30 What is Power Management?
31 -------------------------
33 Power Management (PM) is the practice of saving energy by suspending
35 component is ``suspended`` it is in a nonfunctional low-power state; it
37 ``resumed`` (returned to a functional full-power state) when the kernel
49 covered to some extent (see ``Documentation/power/*.rst`` for more
67 ----------------------
72 by pressing a power button or opening the cover.
85 --------------------------
101 -------------------
106 of time, the so-called idle-delay time.
118 usblp, usblcd, and usb-skeleton (which doesn't count). If a
119 non-supporting driver is bound to a device, the device won't be
123 We can categorize power management events in two broad classes:
134 ---------------------------------
136 The user interface for controlling dynamic PM is located in the ``power/``
138 ``/sys/bus/usb/devices/.../power/`` where "..." is the device's ID. The
139 relevant attribute files are: wakeup, control, and
142 ``control`` file. In 2.6.38 the ``autosuspend`` file will be deprecated
148 ``power/wakeup``
159 ``power/control``
165 - ``on`` means that the device should be resumed and
169 - ``auto`` is the normal state in which the kernel is
177 ``power/autosuspend_delay_ms``
181 before the kernel will autosuspend it (the idle-delay
186 idle-delay time.
188 Writing ``-1`` to ``power/autosuspend_delay_ms`` and writing ``on`` to
189 ``power/control`` do essentially the same thing -- they both prevent the
193 (In 2.6.21 writing ``0`` to ``power/autosuspend`` would prevent the device
195 ``power/autosuspend`` attribute did not exist prior to 2.6.21, and the
196 ``power/level`` attribute did not exist prior to 2.6.22. ``power/control``
197 was added in 2.6.34, and ``power/autosuspend_delay_ms`` was added in
201 Changing the default idle-delay time
202 ------------------------------------
204 The default autosuspend idle-delay time (in seconds) is controlled by
233 then each new USB device will have its autosuspend idle-delay
234 initialized to 5. (The idle-delay values for already existing devices
237 Setting the initial default idle-delay to -1 will prevent any
243 --------
245 The USB specification states that all USB devices must support power
254 ``power/control`` attribute is initialized to ``on``) for all devices other
255 than hubs. Hubs, at least, appear to be reasonably well-behaved in
262 This means that non-hub devices won't be autosuspended unless the user
268 also change the idle-delay time; 2 seconds is not the best choice for
283 of them will issue a remote-wakeup request in response to button
292 The driver interface for Power Management
293 -----------------------------------------
295 The requirements for a USB driver to support external power management
305 - The ``suspend`` method is called to warn the driver that the
311 - The ``resume`` method is called to tell the driver that the
315 - The ``reset_resume`` method is called to tell the driver that
327 possible to work around the hibernation-forces-disconnect problem by
331 :ref:`usb-persist`) and it can also be used under certain
350 ---------------------------------------------------
379 has returned -- say from within a work-queue routine -- provided they
395 their non-async counterparts. The big difference is that they
413 reason or another. For example, the ``power/control`` attribute might be
417 carry out the operation automatically when the autosuspend idle-delay
422 autosuspend, there's no idle-delay for an autoresume.
426 -----------------------------------
434 writing ``auto`` to the device's ``power/control`` attribute. Likewise,
435 drivers can disable autosuspend by calling::
439 This is exactly the same as writing ``on`` to the ``power/control`` attribute.
445 ``intf->needs_remote_wakeup`` to 1, the kernel won't autosuspend the
460 busy and therefore the next autosuspend idle-delay expiration should
462 so drivers need to worry only when interrupt-driven input arrives.
470 cause autosuspends to fail with -EBUSY if the driver needs to use the
481 ----------------
483 For external events -- but not necessarily for autosuspend or
484 autoresume -- the device semaphore (udev->dev.sem) will be held when a
499 --------------------------------------------
501 Dynamic power management and system power management can interact in
512 Secondly, a dynamic power-management event may occur as a system
515 For example, a suspended device may send a remote-wakeup signal while
525 ---------------------
527 xHCI host controller provides hardware link power management to usb2.0
530 lower power state(L1 for usb2.0 devices, or U1/U2 for usb3.0 devices),
534 ``power/`` subdirectory of each USB device's sysfs directory, that is, in
535 ``/sys/bus/usb/devices/.../power/`` where "..." is the device's ID. The
538 ``power/usb2_hardware_lpm``
546 can write y/Y/1 or n/N/0 to the file to enable/disable
549 ``power/usb3_hardware_lpm_u1``
550 ``power/usb3_hardware_lpm_u2``
552 When a USB 3.0 lpm-capable device is plugged in to a
558 The files hold a string value (enable or disable)
562 USB Port Power Control
563 ----------------------
566 controlled link power management, the USB subsystem also has the
567 capability to disable power to ports under some conditions. Power is
569 In the case of a root or platform-internal hub the host controller
571 method calls to set the port power state. For more background see the
574 Upon receiving a ``ClearPortFeature(PORT_POWER)`` request a USB port is
575 logically off, and may trigger the actual loss of VBUS to the port [#f3]_.
577 a shared power well causing power to remain until all ports in the gang
579 a charging application. In any event a logically off port will lose
585 turning off a port may result in the inability to hot add a device.
586 Please see "User Interface for Port Power Control" for details.
589 goes through during system suspend, i.e. the power session is lost. Any
591 similarly affected by a port power cycle event. For this reason the
597 http://dl.dropbox.com/u/96820575/sarah-sharp-lpt-port-power-off2-mini.pdf
601 http://linuxplumbers.ubicast.tv/videos/usb-port-power-off-kerneluserspace-api/
607 wakeup note: if a device is configured to send wakeup events the port
608 power control implementation will block poweroff attempts on that
609 port.
612 User Interface for Port Power Control
613 -------------------------------------
615 The port power control mechanism uses the PM runtime system. Poweroff is
616 requested by clearing the ``power/pm_qos_no_power_off`` flag of the port device
617 (defaults to 1). If the port is disconnected it will immediately receive a
620 suspended. This mechanism is dependent on the hub advertising port power
621 switching in its hub descriptor (wHubCharacteristics logical power switching
630 device. If a hub interface driver is unbound, control of its child ports is
631 lost and all attached child-devices will disconnect. A good rule of thumb is
633 ``/sys/module/usbcore`` then unbinding it will interfere with port power
634 control.
636 Example of the relevant files for port power control. Note, in this example
639 prefix=/sys/devices/pci0000:00/0000:00:14.0/usb3/3-1
642 hub port device + |
645 $prefix/3-1:1.0/3-1-port1/device
647 $prefix/3-1:1.0/3-1-port1/power/pm_qos_no_power_off
648 $prefix/3-1:1.0/3-1-port1/device/power/control
649 $prefix/3-1:1.0/3-1-port1/device/3-1.1:<intf0>/driver/unbind
650 $prefix/3-1:1.0/3-1-port1/device/3-1.1:<intf1>/driver/unbind
652 $prefix/3-1:1.0/3-1-port1/device/3-1.1:<intfN>/driver/unbind
654 In addition to these files some ports may have a 'peer' link to a port on
656 hi-speed peer::
658 $prefix/3-1:1.0/3-1-port1/peer -> ../../../../usb2/2-1/2-1:1.0/2-1-port1
659 ../../../../usb2/2-1/2-1:1.0/2-1-port1/peer -> ../../../../usb3/3-1/3-1:1.0/3-1-port1
662 peer ports are simply the hi-speed and superspeed interface pins that
666 While a superspeed port is powered off a device may downgrade its
667 connection and attempt to connect to the hi-speed pins. The
670 1. Port suspend is sequenced to guarantee that hi-speed ports are powered-off
671 before their superspeed peer is permitted to power-off. The implication is
672 that the setting ``pm_qos_no_power_off`` to zero on a superspeed port may
673 not cause the port to power-off until its highspeed peer has gone to its
675 if it wants to guarantee that a superspeed port will power-off.
677 2. Port resume is sequenced to force a superspeed port to power-on prior to its
680 3. Port resume always triggers an attached child device to resume. After a
681 power session is lost the device may have been removed, or need reset.
682 Resuming the child device when the parent port regains power resolves those
683 states and clamps the maximum port power cycle frequency at the rate the
684 child device can suspend (autosuspend-delay) and resume (reset-resume
687 Sysfs files relevant for port power control:
689 ``<hubdev-portX>/power/pm_qos_no_power_off``:
690 This writable flag controls the state of an idle port.
692 port may suspend/poweroff provided that
694 '1' the port will remain active/powered regardless of
697 ``<hubdev-portX>/power/runtime_status``:
698 This file reflects whether the port is 'active' (power is on)
702 ``<hubdev-portX>/connect_type``:
703 An advisory read-only flag to userspace indicating the
704 location and connection type of the port. It returns
710 port on the platform. Typically userspace would choose
711 to keep such a port powered to handle new device
714 ``hardwired`` refers to a port that is not visible but
717 switch or a port with a hardwired USB camera. It is
721 for the device to be connected prior to the port
722 powering off, or to activate the port prior to enabling
725 ``not used`` refers to an internal port that is expected
729 powered-off at all times.
732 information for this port. Most commonly refers to
738 - since we are relying on the BIOS to get this ACPI
739 information correct, the USB port descriptions may
742 - Take care in clearing ``pm_qos_no_power_off``. Once
743 power is off this port will
747 applied before the port is allowed to poweroff.
749 ``<child>/power/control``:
750 Must be ``auto``, and the port will not
751 power down until ``<child>/power/runtime_status``
755 ``<child>/power/persist``:
758 power session loss (suspend / port-power event). When
759 this value is ``0`` (quirky devices), port poweroff is
763 Wakeup capable devices will block port poweroff. At
764 this time the only mechanism to clear the usb-internal
765 wakeup-capability for an interface device is to unbind
768 Summary of poweroff pre-requisite settings relative to a port device::
770 echo 0 > power/pm_qos_no_power_off
771 echo 0 > peer/power/pm_qos_no_power_off # if it exists
772 echo auto > power/control # this is the default value
773 echo auto > <child>/power/control
774 echo 1 > <child>/power/persist # this is the default value
776 Suggested Userspace Port Power Policy
777 -------------------------------------
783 ``power/pm_qos_no_power_off`` set to ``1`` causing ports to always remain
787 (ACPI _PLD record for a port populates 'connect_type') userspace can
790 connection switch for the port.
792 A more aggressive userspace policy is to enable USB port power off for
793 all ports (set ``<hubdev-portX>/power/pm_qos_no_power_off`` to ``0``) when
795 system. For example, a distro may want to enable power off all USB
796 ports when the screen blanks, and re-power them when the screen becomes
797 active. Smart phones and tablets may want to power off USB ports when
798 the user pushes the power button.