Oct 21, 2012

USB On-The-Go

USB On-The-Go, often abbreviated USB OTG, is a specification that allows USB devices such as digital audio players or mobile phones to act as a host, allowing other USB devices like a USB flash drive, mouse, or keyboard to be attached to them. Unlike conventional USB systems, USB OTG systems can drop the hosting role and act as normal USB devices when attached to another host. This can be used to allow a mobile phone to act as host for a flash drive and read its contents, downloading music for instance, but then act as a flash drive when plugged into a host computer and allow the host to read off the new content.


Architecture

Standard USB uses a master/slave architecture; a host acts as the master device for the entire bus, and a USB device acts as the slave. Devices
are designed from the start to act in one role or the other - computers are generally set up to be hosts, while printers (for instance) are normally slaves.

When a device is plugged into the USB bus, the master device, or host, sets up communications with the device and handles service provisioning. The host is responsible for all data transfers over the bus, with the devices only able to signal that they require attention. To transfer data between two devices, from a phone to a printer for instance, the host first reads the data from one device then writes it to the other. This allows the devices to be greatly simplified compared to the host; a mouse, for instance, contains very little logic and relies on the host to do almost all of work.

While the master/slave arrangement works for some devices, there are many devices that might want to act as a master or a slave depending on who else shares the bus. For instance, a computer printer is normally a slave device, but one can imagine the case where a USB flash drive of images is plugged into the USB port of the printer with no computer present, or at least turned off. In this scenario, it would be useful for the printer to take on the role of host, allowing it to communicate with the flash drive directly and print the images on it.

USB On-The-Go introduces the concept that a device can perform both the master and slave roles, and so subtly changes the terminology. With OTG, a device can be either a host when acting as the link master, or a peripheral when acting as the link slave. The choice of whether to be host or peripheral is handled entirely by which end of the cable the device is plugged into. The device connected to the "A" end of the cable at start-up, known as the "A-device", acts as the default host, while the "B" end acts as the default peripheral, known as the "B-device".

After initial startup, setup for the bus operates as it does with the normal USB standard, with the A-device setting up the B-device and managing all communications. However, when that same A-device is plugged into another USB system, or a dedicated host becomes available, it may become a slave.

USB On-The-Go does not preclude using a USB hub, but it describes host/peripheral role swapping only for the case of a one-to-one connection where two OTG devices are directly connected. Role swapping does not work through a standard hub, as one device will act as the host and the other as the peripheral until they are disconnected.

Specifications

USB OTG is part of a supplement[1] to the Universal Serial Bus (USB) 2.0 specification originally agreed upon in late 2001 and later revised.[2] The latest version of this supplement also defines behavior for an Embedded Host which has targeted abilities and the same USB Standard-A port used by PCs.

SuperSpeed OTG devices, Embedded Hosts and peripherals are supported through the USB On-The-Go and Embedded Host Supplement[3] to the USB 3.0 specification.

Protocols

The USB On-The-Go and Embedded Host Supplement to the USB 2.0 specification introduced three new protocols, Attach Detection Protocol (ADP), Session Request Protocol (SRP) and Host Negotiation Protocol (HNP).
ADP allows an OTG device, Embedded host or USB device to determine attachment status in the absence of power on the USB bus. This enables both insertion based behavior and the possibility for a device to display attachment status. It does this by periodically measuring the capacitance on the USB port to determine whether there is another device attached, a dangling cable or no cable. When a change in capacitance, large enough to indicate device attachment is detected then an A-device will provide power to the USB bus and look for device connection. A B-device will generate SRP and wait for the USB bus to become powered.
SRP allows both communicating devices to control when the link's power session is active; in standard USB, only the host is capable of doing so. That allows fine control over the power consumption, which is very important for battery operated devices such as cameras and mobile phones. The OTG or Embedded host can leave the USB link unpowered until the peripheral (which can be an OTG or standard USB device) asks it to start delivering power. OTG and Embedded hosts may not have much power to spare from their batteries, and leaving the USB link unpowered helps stretch battery life.
HNP allows the two devices to exchange their host/peripheral roles, provided both are OTG dual-role devices. By using HNP for reversing host/peripheral roles, the USB OTG device is capable of acquiring control of data-transfer scheduling. Thus, any OTG device is capable of initiating data-transfer over USB OTG bus. The latest version of the supplement also introduced the idea of HNP polling whereby the device in host role periodically polls the peripheral, during an active session, to determine whether it wishes to become a host.

The main purpose of HNP is to accommodate users who have connected the A and B devices (see below) in the wrong direction for the task they want to perform. For example, a printer is connected as the A-device (host), but cannot function as a host for a particular camera, since it doesn't understand the camera's representation of print jobs. When that camera knows how to talk to the printer, the printer will use HNP to switch to the slave role, making the camera the host to the printer so that the user's pictures will get printed without juggling cables. These new OTG protocols cannot pass through a standard USB hub since they are based on physical electrical-signaling.

The USB On-The-Go and Embedded Host Supplement to the USB 3.0 specification introduces an additional protocol, Role Swap Protocol (RSP). This achieves the same purpose as HNP (i.e. role swapping) by extending standard mechanisms provided by the USB 3.0 specification. Products following the USB On-The-Go and Embedded Host Supplement to the USB 3.0 specification are also required to follow the USB 2.0 supplement in order to maintain backwards compatibility. SuperSpeed OTG devices (SS-OTG) are required to support RSP. SuperSpeed Peripheral Capable OTG devices (SSPC-OTG) are not required to support RSP since they can only operate at SuperSpeed as a peripheral; they have no SuperSpeed host and so can only role swap using HNP at USB 2.0 data rates.


Adapted From