aboutsummaryrefslogtreecommitdiffstats
path: root/Documentation/usb
diff options
context:
space:
mode:
authorLan Tianyu <tianyu.lan@intel.com>2014-05-29 15:58:52 -0400
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>2014-07-09 18:43:12 -0400
commitf64c51975dd635eba2a65f258013a95859b3d04a (patch)
tree3baeb53ae2570d60dc89d873d328463daaefee49 /Documentation/usb
parent3cd12f91514da6893954de479dc60b16d3b381f4 (diff)
usb: documentation for usb port power off mechanisms
describe the mechanisms for controlling port power policy and discovering the port power state. [oliver]: fixes, clarification of wakeup vs port-power-control [sarah]: wordsmithing [djbw]: updates for peer port changes [alan]: review and fixes Cc: Oliver Neukum <oneukum@suse.de> Signed-off-by: Lan Tianyu <tianyu.lan@intel.com> Signed-off-by: Dan Williams <dan.j.williams@intel.com> Acked-by: Alan Stern <stern@rowland.harvard.edu> Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Diffstat (limited to 'Documentation/usb')
-rw-r--r--Documentation/usb/power-management.txt245
1 files changed, 243 insertions, 2 deletions
diff --git a/Documentation/usb/power-management.txt b/Documentation/usb/power-management.txt
index 1392b61d6ebe..7b90fe034c4b 100644
--- a/Documentation/usb/power-management.txt
+++ b/Documentation/usb/power-management.txt
@@ -2,8 +2,27 @@
2 2
3 Alan Stern <stern@rowland.harvard.edu> 3 Alan Stern <stern@rowland.harvard.edu>
4 4
5 October 28, 2010 5 Last-updated: February 2014
6 6
7
8 Contents:
9 ---------
10 * What is Power Management?
11 * What is Remote Wakeup?
12 * When is a USB device idle?
13 * Forms of dynamic PM
14 * The user interface for dynamic PM
15 * Changing the default idle-delay time
16 * Warnings
17 * The driver interface for Power Management
18 * The driver interface for autosuspend and autoresume
19 * Other parts of the driver interface
20 * Mutual exclusion
21 * Interaction between dynamic PM and system PM
22 * xHCI hardware link PM
23 * USB Port Power Control
24 * User Interface for Port Power Control
25 * Suggested Userspace Port Power Policy
7 26
8 27
9 What is Power Management? 28 What is Power Management?
@@ -516,3 +535,225 @@ relevant attribute files is usb2_hardware_lpm.
516 driver will enable hardware LPM for the device. You 535 driver will enable hardware LPM for the device. You
517 can write y/Y/1 or n/N/0 to the file to enable/disable 536 can write y/Y/1 or n/N/0 to the file to enable/disable
518 USB2 hardware LPM manually. This is for test purpose mainly. 537 USB2 hardware LPM manually. This is for test purpose mainly.
538
539
540 USB Port Power Control
541 ----------------------
542
543In addition to suspending endpoint devices and enabling hardware
544controlled link power management, the USB subsystem also has the
545capability to disable power to ports under some conditions. Power is
546controlled through Set/ClearPortFeature(PORT_POWER) requests to a hub.
547In the case of a root or platform-internal hub the host controller
548driver translates PORT_POWER requests into platform firmware (ACPI)
549method calls to set the port power state. For more background see the
550Linux Plumbers Conference 2012 slides [1] and video [2]:
551
552Upon receiving a ClearPortFeature(PORT_POWER) request a USB port is
553logically off, and may trigger the actual loss of VBUS to the port [3].
554VBUS may be maintained in the case where a hub gangs multiple ports into
555a shared power well causing power to remain until all ports in the gang
556are turned off. VBUS may also be maintained by hub ports configured for
557a charging application. In any event a logically off port will lose
558connection with its device, not respond to hotplug events, and not
559respond to remote wakeup events*.
560
561WARNING: turning off a port may result in the inability to hot add a device.
562Please see "User Interface for Port Power Control" for details.
563
564As far as the effect on the device itself it is similar to what a device
565goes through during system suspend, i.e. the power session is lost. Any
566USB device or driver that misbehaves with system suspend will be
567similarly affected by a port power cycle event. For this reason the
568implementation shares the same device recovery path (and honors the same
569quirks) as the system resume path for the hub.
570
571[1]: http://dl.dropbox.com/u/96820575/sarah-sharp-lpt-port-power-off2-mini.pdf
572[2]: http://linuxplumbers.ubicast.tv/videos/usb-port-power-off-kerneluserspace-api/
573[3]: USB 3.1 Section 10.12
574* wakeup note: if a device is configured to send wakeup events the port
575 power control implementation will block poweroff attempts on that
576 port.
577
578
579 User Interface for Port Power Control
580 -------------------------------------
581
582The port power control mechanism uses the PM runtime system. Poweroff is
583requested by clearing the power/pm_qos_no_power_off flag of the port device
584(defaults to 1). If the port is disconnected it will immediately receive a
585ClearPortFeature(PORT_POWER) request. Otherwise, it will honor the pm runtime
586rules and require the attached child device and all descendants to be suspended.
587This mechanism is dependent on the hub advertising port power switching in its
588hub descriptor (wHubCharacteristics logical power switching mode field).
589
590Note, some interface devices/drivers do not support autosuspend. Userspace may
591need to unbind the interface drivers before the usb_device will suspend. An
592unbound interface device is suspended by default. When unbinding, be careful
593to unbind interface drivers, not the driver of the parent usb device. Also,
594leave hub interface drivers bound. If the driver for the usb device (not
595interface) is unbound the kernel is no longer able to resume the device. If a
596hub interface driver is unbound, control of its child ports is lost and all
597attached child-devices will disconnect. A good rule of thumb is that if the
598'driver/module' link for a device points to /sys/module/usbcore then unbinding
599it will interfere with port power control.
600
601Example of the relevant files for port power control. Note, in this example
602these files are relative to a usb hub device (prefix).
603
604 prefix=/sys/devices/pci0000:00/0000:00:14.0/usb3/3-1
605
606 attached child device +
607 hub port device + |
608 hub interface device + | |
609 v v v
610 $prefix/3-1:1.0/3-1-port1/device
611
612 $prefix/3-1:1.0/3-1-port1/power/pm_qos_no_power_off
613 $prefix/3-1:1.0/3-1-port1/device/power/control
614 $prefix/3-1:1.0/3-1-port1/device/3-1.1:<intf0>/driver/unbind
615 $prefix/3-1:1.0/3-1-port1/device/3-1.1:<intf1>/driver/unbind
616 ...
617 $prefix/3-1:1.0/3-1-port1/device/3-1.1:<intfN>/driver/unbind
618
619In addition to these files some ports may have a 'peer' link to a port on
620another hub. The expectation is that all superspeed ports have a
621hi-speed peer.
622
623$prefix/3-1:1.0/3-1-port1/peer -> ../../../../usb2/2-1/2-1:1.0/2-1-port1
624../../../../usb2/2-1/2-1:1.0/2-1-port1/peer -> ../../../../usb3/3-1/3-1:1.0/3-1-port1
625
626Distinct from 'companion ports', or 'ehci/xhci shared switchover ports'
627peer ports are simply the hi-speed and superspeed interface pins that
628are combined into a single usb3 connector. Peer ports share the same
629ancestor XHCI device.
630
631While a superspeed port is powered off a device may downgrade its
632connection and attempt to connect to the hi-speed pins. The
633implementation takes steps to prevent this:
634
6351/ Port suspend is sequenced to guarantee that hi-speed ports are powered-off
636 before their superspeed peer is permitted to power-off. The implication is
637 that the setting pm_qos_no_power_off to zero on a superspeed port may not cause
638 the port to power-off until its highspeed peer has gone to its runtime suspend
639 state. Userspace must take care to order the suspensions if it wants to
640 guarantee that a superspeed port will power-off.
641
6422/ Port resume is sequenced to force a superspeed port to power-on prior to its
643 highspeed peer.
644
6453/ Port resume always triggers an attached child device to resume. After a
646 power session is lost the device may have been removed, or need reset.
647 Resuming the child device when the parent port regains power resolves those
648 states and clamps the maximum port power cycle frequency at the rate the child
649 device can suspend (autosuspend-delay) and resume (reset-resume latency).
650
651Sysfs files relevant for port power control:
652 <hubdev-portX>/power/pm_qos_no_power_off:
653 This writable flag controls the state of an idle port.
654 Once all children and descendants have suspended the
655 port may suspend/poweroff provided that
656 pm_qos_no_power_off is '0'. If pm_qos_no_power_off is
657 '1' the port will remain active/powered regardless of
658 the stats of descendants. Defaults to 1.
659
660 <hubdev-portX>/power/runtime_status:
661 This file reflects whether the port is 'active' (power is on)
662 or 'suspended' (logically off). There is no indication to
663 userspace whether VBUS is still supplied.
664
665 <hubdev-portX>/connect_type:
666 An advisory read-only flag to userspace indicating the
667 location and connection type of the port. It returns
668 one of four values 'hotplug', 'hardwired', 'not used',
669 and 'unknown'. All values, besides unknown, are set by
670 platform firmware.
671
672 "hotplug" indicates an externally connectable/visible
673 port on the platform. Typically userspace would choose
674 to keep such a port powered to handle new device
675 connection events.
676
677 "hardwired" refers to a port that is not visible but
678 connectable. Examples are internal ports for USB
679 bluetooth that can be disconnected via an external
680 switch or a port with a hardwired USB camera. It is
681 expected to be safe to allow these ports to suspend
682 provided pm_qos_no_power_off is coordinated with any
683 switch that gates connections. Userspace must arrange
684 for the device to be connected prior to the port
685 powering off, or to activate the port prior to enabling
686 connection via a switch.
687
688 "not used" refers to an internal port that is expected
689 to never have a device connected to it. These may be
690 empty internal ports, or ports that are not physically
691 exposed on a platform. Considered safe to be
692 powered-off at all times.
693
694 "unknown" means platform firmware does not provide
695 information for this port. Most commonly refers to
696 external hub ports which should be considered 'hotplug'
697 for policy decisions.
698
699 NOTE1: since we are relying on the BIOS to get this ACPI
700 information correct, the USB port descriptions may be
701 missing or wrong.
702
703 NOTE2: Take care in clearing pm_qos_no_power_off. Once
704 power is off this port will
705 not respond to new connect events.
706
707 Once a child device is attached additional constraints are
708 applied before the port is allowed to poweroff.
709
710 <child>/power/control:
711 Must be 'auto', and the port will not
712 power down until <child>/power/runtime_status
713 reflects the 'suspended' state. Default
714 value is controlled by child device driver.
715
716 <child>/power/persist:
717 This defaults to '1' for most devices and indicates if
718 kernel can persist the device's configuration across a
719 power session loss (suspend / port-power event). When
720 this value is '0' (quirky devices), port poweroff is
721 disabled.
722
723 <child>/driver/unbind:
724 Wakeup capable devices will block port poweroff. At
725 this time the only mechanism to clear the usb-internal
726 wakeup-capability for an interface device is to unbind
727 its driver.
728
729Summary of poweroff pre-requisite settings relative to a port device:
730
731 echo 0 > power/pm_qos_no_power_off
732 echo 0 > peer/power/pm_qos_no_power_off # if it exists
733 echo auto > power/control # this is the default value
734 echo auto > <child>/power/control
735 echo 1 > <child>/power/persist # this is the default value
736
737 Suggested Userspace Port Power Policy
738 -------------------------------------
739
740As noted above userspace needs to be careful and deliberate about what
741ports are enabled for poweroff.
742
743The default configuration is that all ports start with
744power/pm_qos_no_power_off set to '1' causing ports to always remain
745active.
746
747Given confidence in the platform firmware's description of the ports
748(ACPI _PLD record for a port populates 'connect_type') userspace can
749clear pm_qos_no_power_off for all 'not used' ports. The same can be
750done for 'hardwired' ports provided poweroff is coordinated with any
751connection switch for the port.
752
753A more aggressive userspace policy is to enable USB port power off for
754all ports (set <hubdev-portX>/power/pm_qos_no_power_off to '0') when
755some external factor indicates the user has stopped interacting with the
756system. For example, a distro may want to enable power off all USB
757ports when the screen blanks, and re-power them when the screen becomes
758active. Smart phones and tablets may want to power off USB ports when
759the user pushes the power button.