USB device driver

Source: Internet
Author: User

1. Linux USB Architecture

 

USB communication is initiated by the host. The USB device driver allocates and initializes an urb and sends it to the USB core. The USB core is changed and sent to the USB host controller driver. The USB host controller driver parses it into a package and transmits it on the bus. USB core is implemented by the kernel. In fact, the functions in the Host Control driver are abstracted to a more centralized level, it is used to shield the host control from the driver of the top USB device.

 

2. location in the kernel


USB drivers exist in different kernel subsystems and USB hardware controllers. The USB core provides an interface for USB driver to access and control USB hardware. There is no need to consider the various types of USB hardware controllers currently in the system.

 

3. USB device composition, including configuration, interface and Endpoint


This section describes the structure of a Linux USB device. Each interface represents a function and corresponds to a driver.

 

4. USB device driver description

In the Linux kernel, use the structusb_driver structure to describe a USB driver.

Struct usb_driver {

Const char * Name;/* driver name */

 

/* Call this function when the USB core discovers the USB interface that the driver can process */

INT (* probe) (structusb_interface * INTF,

Const struct usb_device_id * ID );

 

/* Call this function when the corresponding USB interface is removed */

Void (* disconnect) (struct usb_interface * INTF );

 

/* List of devices that the USB driver can process */

Const structusb_device_id * id_table;

......

};

The enumeration process of USB devices is slightly different from that we usually see. For example, for I2C devices, we need to register I2C device information (such as device names and some hardware configuration information) in the Board file ), the USB bus will automatically enumerate the USB device. If it can match id_table, it will be able to enumerate successfully and then load the corresponding driver.

 

5. USB device description

The Linux kernel uses struct usb_device to describe a USB device.

Struct usb_device {

Int devnum;/* USB device Number */

Char devpath [16];/* device ID string */

Enum usb_device_state state;/* device status: not connected, configured */

Enum usb_device_speed speed;/* high speed, full speed, low speed */

 

Struct usb_device * parent;

Struct usb_bus * bus;

Structusb_host_endpoint ep0;

 

Struct device dev;

 

Structusb_device_descriptor descriptor;/* USB device descriptor, defined according to the USB protocol */

Struct usb_host_config * config;

 

Struct usb_host_config * actconfig;

Structusb_host_endpoint * ep_in [16];

Structusb_host_endpoint * ep_out [16];

 

/* Static strings fromthe device */

Char * product;/* Product Number */

Char * manufacturer;/* producer */

Char * serial;/* Device serial number */

};

 

6. USB descriptor

Several descriptor structures are defined in the Linux kernel in strict accordance with the USB protocol:

Device descriptor: general information about a device, such as the producer ID and product ID;

Configuration descriptor: number of interfaces in this configuration, supported suspension and recovery capabilities, and power requirements;

Interface descriptor: Interface Class, subclass and applicable protocol, number of digital and Endpoint configured for backup interface;

Endpoint descriptor: the endpoint address, direction, and type. It supports the maximum package size. If it is an endpoint of the interrupt type, it also includes the polling frequency.

String descriptor: other descriptors provide string indexes for certain fields, which are sadly used to retrieve descriptive strings.

 

7. urb

The USB request block (urb) is the basic carrier and core data structure used in the USB device driver to describe the communication with the USB device. It is very similar to the sk_buff structure in the network device driver.

 

1. the USB device driver creates and initializes a urb that accesses a specific endpoint of a specific USB device and submits it to the USB core;

2. the USB core submits the urb to the USB master controller driver;

3. the USB master controller driver accesses the USB device according to the URL description;

4. When the device access ends, the USB master control driver notifies the USB device driver.

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.