Linux Device Driver Subsystem IV-USB Gadget__linux

Source: Internet
Author: User

1. Foreword

2. Source Code Architecture

3. Enumeration process

1. Foreword

Gadget, small ornaments. USB Gadget, refers to the development of electronic devices to USB from the device mode through the USB connection to the host. For example, when a mobile phone is plugged into a PC with a USB cable, the handset is a USB Gadget. Taking Mavell as an example, this paper analyzes the architecture of USB gadget with the whole process of inserting gadget into the main line.

2. Source Code Architecture

USB source code is located in the/drivers/usb folder, including core layer, main controller host,u disk storage, as well as USB gadget.

The gadget folder stores the USB gadget controller drivers supported by each chip manufacturer, such as the Mavell pxa9xx series USB gadget driver for mv_gadget.c, as shown in the following figure.

2.1 Gadget Controller Driver

The equipment must have the gadget function, the hardware must integrate the gadget controller, the software must have the gadget controller actuation.

The first is the data structure of the drive struct Mv_usb_dev,

-> struct Usb_gadget, a data member required by a Linux-defined gadget, contains sturct Usb_ep.

-> struct Mv_usb_ep, where the struct USB_EP is a member of the Linux defined endpoint, refer to the USB protocol for endpoint.

-> struct Usb_gadget_driver, the driver that should be gadget the function of the device, the following section will be described in detail.

-> void *mv_usb_handle, the pointer points to the data structure of the chip controller.

In a nutshell, the gadget controller driver completes five tasks, initializing gadget chips and related data (light gray) with platform_data and resource to gadget chip physical address, interrupt number, etc. struct Gadget (blue) initialization data struct USB_EP (pink) Registration gadget Service

Gadget services, i.e. the gadget capabilities of the device, such as Reset, suspend, resume, speed, and enumeration features that need to be focused on mv_usb_ep0_complete_service. Note that the first parameter of the registration service function Usb_device_register_service () Mv_usb_handle is used to get data from the underlying chip, and the third parameter callback function implements the specific function.

2.2 Gadget device driver

The gadget device driver needs to be distinguished from the gadget controller driver mentioned in the previous section. Gadget device driver, refers to the device is inserted after the function of the host, the drive is hung under the struct usb_gadget_driver. For example, the mobile phone into the PC as a U disk, then u disk driver is the so-called gadget device driver.

(*bind) binding device functions, such as U disk.

(*setup) Implements an enumeration of USB devices.

2.3 Composite

If a device is plugged into a host and has multiple functions, such as a U disk and an Android debugging feature, then the device is called a composite multiplexing device. Its data structure is as follows,

Bind various features of the device through (*bind).

3. Enumeration process

The process by which the system initializes the USB device is the enumeration process.

According to USB protocol, the process of initializing USB device is attached->powered->default->address->configured.

When the device is plugged into the host, it waits for the interrupt signal from the host to enter the interrupt handler function via REQUEST_IRQ ().

By reading the value of the controller State Register, the device obtains feedback from the host and performs the corresponding task, an enumeration is one of the tasks that begins the enumeration process by invoking the gadget controller to drive the enumerated service that has already been registered.

The enumeration service is summed up in two steps,

The first step, by reading the gadget controller, get the request from the host, stored to mv_ctrl_req.

The second step, through the switch (mv_ctrl_req), the specific request for specific treatment, processing categories can be divided into two categories.

1 standard request, that is, all USB devices can be universal request, specific get status request, set/clear feature request, set address request.

2 USB device request, that is, according to the specific equipment, processing specific requests, through the callback function Mv_dev->driver->setup () to achieve.

PS: About requests, see USB protocol CH9.

Focus on the enumeration process of Mv_dev->driver->setup (), the essence of which is that the host gets the descriptor from the USB device.

The mv_dev->driver here is the gadget device driver mentioned in 2.2 above, with Driver->bind binding specific drive function, if it is composite multiplexing device, bind Usb_composite_ Driver structure, through DRIVER->SETUP implementation of the device enumeration process, the code below, where the Get_descriptor, set_configuration, and F->setup is the necessary enumeration process.

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.