USB bus driver

USB Host Controller : UHCI OHCI EHCI

UHCI: intel low speed (1.5Mbps) (USB1.1) / full-speed (12Mbps) (USB2.0, USB2.0 is divided into full and high speed)
the OHCI: Microsoft: low / full
EHCI: high speed (480Mbps)

USB bus driver action :
1. Identify the USB device
1.1 allocate addresses
1.2 and tell the USB device (SET address)
1.3 issue a command descriptor obtaining
information descriptor can be seen in include \ linux \ usb \ ch9.h in

2. Find and install the device driver corresponding
3. The USB provides read and write functions

How the program is called, simply look at:

In the drivers / usb / core / hub.c file:
Each controller comes with a USB hub

hub_irq
  kick_khubd
    hub_thread
      hub_events
        hub_port_connect_change
          choose_devnum to the new device // select a new number (address)
          hub_port_init
            hub_set_address // the number (address) told a USB device, the future will use this address.
            usb_get_device_descriptor (udev, 8); // Get Device Descriptor
            retval = usb_get_device_descriptor (the udev, USB_DT_DEVICE_SIZE);

          usb_new_device (the udev)

                // put the bus into the device dev list, remove the driver from the bus driver in the list, if it can match to call driver's Probe
            device_add (& udev-> dev);

Note: This interrupt is registered inside the host controller interrupt, usb device is not interrupted. When connected to a USB device, the hardware makes hands D + or D- from low to high, the hardware on the perception of a USB device is connected, which will generate an interrupt. Thus there is a calling procedure above.

hub_port_connect_change
  choose_devnum // select a new number (address) to the new device
  / * the Try the Next to the allocate at The Beginning BUS- DevNum, AT> devnum_next. * /
  // Find Next 0, obviously an address with the corresponding inside address will be set to 1, indicating that the address is in use. From 1 128 to find, if not, you will find from scratch. Suppose the last time you plug in a USB device number, it devnum = 5, then it will start looking for from 5 to find after 128, if not found, it will find from the beginning. That is, after looking around, if not found, then come back. Can be seen from this place, a USB host controller can connect up to 128 USB devices.
  devnum = find_next_zero_bit (bus-> devmap.devicemap, 128, bus-> devnum_next);

2, analysis of several important data structures

Device descriptor:

/* USB_DT_DEVICE: Device descriptor */
struct usb_device_descriptor {
__u8 bLength;
__u8 bDescriptorType;

__le16 bcdUSB; //USB版本号
__u8 bDeviceClass;
__u8 bDeviceSubClass;
__u8 bDeviceProtocol;
__u8 bMaxPacketSize0; //最大包大小,0表示端点0.每个设备都有端点0,因为是通过端点0识别出USB设备的
__le16 idVendor; //厂家ID
__le16 idProduct; //产品ID
__le16 bcdDevice;
__u8 iManufacturer;
__u8 iProduct;
__u8 iSerialNumber;
__u8 bNumConfigurations;
} __attribute__ ((packed));

配置描述符:
struct usb_config_descriptor {
__u8 bLength;
__u8 bDescriptorType;

__le16 wTotalLength;
__u8 bNumInterfaces;
__u8 bConfigurationValue;
__u8 iConfiguration;
__u8 bmAttributes;
__u8 bMaxPower;
} __attribute__ ((packed));

接口描述符:
/* USB_DT_INTERFACE: Interface descriptor */
struct usb_interface_descriptor {
__u8 bLength;
__u8 bDescriptorType;

__u8 bInterfaceNumber;
__u8 bAlternateSetting;
__u8 bNumEndpoints;
__u8 bInterfaceClass;
__u8 bInterfaceSubClass;
__u8 bInterfaceProtocol;
__u8 iInterface;
} __attribute__ ((packed));

端点描述符
/* USB_DT_ENDPOINT: Endpoint descriptor */
struct usb_endpoint_descriptor {
__u8 bLength;
__u8 bDescriptorType;

__u8 bEndpointAddress;
__u8 bmAttributes;
__le16 wMaxPacketSize; //从端点中一次写入或读出多少数据
__u8 bInterval;用查询的方式实现实时性的,此变量就表示查询的时间间隔。

/* NOTE: these two are _only_ in audio endpoints. */
/* use USB_DT_ENDPOINT*_SIZE in bLength, not sizeof. */
__u8 bRefresh;
__u8 bSynchAddress;
} __attribute__ ((packed));

它们的关系:

每一个USB设备,都有一个设备描述符,可以发出某些命令,得到USB设备描述符。一个硬件里面有一个设备描述符,
一个设备描述符里面还有配置描述符,一个设备描述符里面可能有多个配置描述符。

 

 本节只是进行了简单的分析,并没有进行深入分析。

Guess you like

Origin www.cnblogs.com/-glb/p/11568992.html