Detailed description of USB gadget devices in Linux

Source: Internet
Author: User
Detailed description of USB gadget devices in Linux

What is USB gadget? The Linux-USB Gadget driver framework (hereinafter referred to as Gadget) provides software functions for devices defined by the USB protocol. Compared with the Linux USB Host driver, the Gadget driver appears later than 2.4.23.

The Gadget Framework proposes a set of standard APIs. At the underlying layer, the USB Device Controller (UDC) driver implements this set of APIs. Different UDC (usually part of SOC) different drivers are required, and even different boards based on the same UDC need to be modified. This layer is called a platform-related layer.

Based on the API, the Gadget driver implements a set of hardware-independent functions, which can basically correspond to various USB classes in the USB protocol, such as the USB Gadget Generic Serial driver, no corresponding Class. Of course, the Gadget driver is still limited by the features provided by the underlying layer. For example, some classes require USB Isochronous endpoints, so we cannot support this Class.

A general Gadget driver only implements one function (for example, a u disk or a usb Nic ). Composite devices support multiple functions. The realization of composite devices will be carefully studied later. Devices such as smartphones and PDAs support a wide range of endpoints and DMA buffers, providing the software with a foundation to support the combination of functions.

There are two points worth noting. The first is that the usb gaget driver framework does not have the concept of usb core on the usb host. The usb host may support hundreds of types of peripherals, which makes sense to abstract general functions. Usb device usually does not have this requirement. Some general functions can be abstracted in some Helper functions. The second is the OTG concept proposed in usb 2.0, which can support the host and device functions on the same interface. OTG is a complicated specification and will be studied later.

  Controller Driver

Common usb devices include usb drive, usb mouse, keyboard, usb bluetooth module, usb card reader, and so on. These devices are relatively simple and usually do not run Linux. Running Linux Gadget is usually a SOC (System-on-Chip) that integrates CPU and many peripheral interfaces. the CPU is usually a 32-bit CPU, udc is also part of the SOC (along with DMA channels and FIFO ).

The Linux standard kernel supports mainstream SOC udc drivers. make menuconfig and you can see the specific list. It is worth mentioning that dummy_hcd is a software-simulated udc, it is helpful when developing a new gadget driver.

The controller driver processes a small number of USB control requests (mainly the hardware is responsible ). All other control requests, such as the return descriptor, set the current configuration, which is completed by the Gadget Driver. A major responsibility of the controller Driver is to manage the I/O queues of various endpoints and transmit data (usually through DMA) between the buffer of the Gadget Driver and the hardware buffer ).

We mentioned earlier that the upper-layer Gadget driver depends on the hardware conditions provided by the underlying layer to implement any functions. For example, a composite device requires at least five endpoints. These hardware features are implemented using a set of gadget_is _ * () functions.

  Gadget driver

Based on the resources provided by the underlying layer, the Gadget driver can run on various hardware platforms. Important drivers include:

Gadget Zero, similar to dummy hcd, is used to test the udc driver. It will help you test through a USB-IF.

Ethernet over USB, which is used to simulate an Ethernet port. It supports multiple operating modes:

CDC Ethernet: communication Device Class "Ethernet Model" protocol specified by usb specifications.

CDC Subset: a method that has the lowest hardware requirements. It is mainly supported by Linux Hosts.

RNDIS: Microsoft's implementation of the CDC Ethernet variant.

File-backed Storage Gadget is the most common U disk function implementation.

Serial Gadget implementation, including:

Generic Serial implementation (only the Bulk-in/Bulk-out endpoint + ep0 is required)

Cdc acm specification implementation.

The Gadget Filesystem exposes the Gadget API to the application layer to implement the user mode driver at the application layer.

MIDI: exposes the ALSA interface and provides recording and playback functions.

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.