General on-line information about USB gadget is based on Linux2.6.32 or prior versions, and the author focuses on the Linux2.6.37 and Linux3.0.4 versions of the kernel, USB Some of the gadget APIs are already different from the Linux2.6.32. But the key data structures are still the same. Linux USB Gadget Three-tier architecture: hierarchical relationship from top to bottom: USB Gadget functional layer. Bsp/driver developers typically implement this layer to achieve a specific device driver, such as anddroid adb,mtp,mass_storage in this layer. Browsing the reference to this layer of code, you will find that "composite" is the keyword of this layer, the key data structure in this layer is: struct usb_composite_driver. The driver files for this layer are generally: DRIVER/USB/GADGET/ANDROID.C (Android-implemented) or DRIVER/USB/GADGET/SERIAL.C (USB-to-serial port for traditional Linux implementations). Second layer: USB device layer. This layer is implemented by the Linux kernel development maintainers, and we do not have much to worry about, we only care about some of its interfaces on the line. Browsing the reference to this layer, you will find that "gadget" is the keyword of this layer, the key data structure of this layer is: Usb_gadget_driver,usb_composite_dev. One of the main drivers for this layer is: DRIVER/USB/GADGET/COMPOSITE.C layer three: USB device controller driver layer. This layer is mainly related to CPU, CPU USB controller, closely related to hardware, this layer is also more headache, mainly it and the USB controller involved, involving a register, clock, DMA and so on. But this layer is often implemented by chip manufacturers. We generally only need to handle the required USB interface in the board level file. The key word of this layer is "UDC", the main driver file named with "UDC" keyword, generally related to CPU or chip manufacturers, such as DRIVER/USB/GADGET/XXX_UDC.C.
Linux USB drive--gadget code Introduction