Friday, March 14, 2014

Following the Linux Gadget little research attention for a long time after another Android USB Gadg


Following the Linux Gadget little research attention for a long time after another Android USB Gadget, always wanted to write something to record some understanding, but Linux USB is too complicated, people feel a little lopolis bit unable to write. It's not that complicated can not be understood, but also covers a wide surface. USB Host driver concerned is relatively small, on the USB device driver awareness, the need to carry it from two aspects to know and understand, lopolis one is USB protocol itself, even if the USB endpoint device descriptor, interface, composite lopolis concepts and equipment are not clear, then it is impossible to understand Linux USB device driver; Another aspect is the USB Gadget framework. lopolis The paper is based on the USB Gadget framework a little knowledge and records. 2.Android USB Android device's lopolis USB port to achieve the OTG function, which is generally an Android device can act as Host and Device roles, and we use the most is its Device roles. Android system developers to change the tradition of the Linux USB Gadget achieved in the traditional lopolis Linux Gadget architecture implements a composite device: adb and mtp. Needless to say which adb, played Android lopolis know everything, mtp is a common U disk function. Android USB Gadget device driver is a USB Gadget Linux device drivers. 3.USB Gadget of the three-tier architecture introduces general information on the Internet are based Linux2.6.32 USB Gadget lopolis or in previous versions, the author paid attention Linux2.6.37 and Linux3.0.4 version of the kernel, USB Gadget API has some Unlike Linux2.6.32 of it. But those key data structure or drop the same. Linux USB Gadget of three-tier structure: a layer of hierarchy from top to bottom: lopolis USB Gadget functional layer. BSP / Driver developer layer is usually to achieve this, in order to achieve a specific device drivers, such as realized in this layer Anddroid adb, mtp, mass_storage like. Watch this layer when browsing the reference code, you will find "composite" is the keyword of this layer, this layer is the key data structure: struct usb_composite_driver. This layer is generally drivers: driver / usb / gadget / android.c (android implementation) or driver / usb / gadget / serial.c (traditional Linux implementation of USB to serial port). Layer: USB device layer. This layer is the Linux kernel maintainers to achieve, not so much with us, do not worry about us, we are only interested in some of its interfaces on the line. When browsing reference Watch this layer, you will find "gadget" is the keyword of this layer, this layer is the key data structure is: usb_gadget_driver, usb_composite_dev. This layer is mainly a driver file is: driver / usb / gadget / composite.c three: USB device controller driver layer. This layer with the CPU, CPU USB controller related lopolis closely related to the hardware, this layer is relatively headache, and it is mainly involved with the USB controller, involving registers, clock, DMA and the like. However, this layer is often achieved by the chip maker to go. We generally only need to handle the USB interface lopolis to the file at the board level. This layer is the keyword "UDC", name the file containing the main driver "udc" keyword, generally lopolis related to the CPU or chip manufacturers, such as driver / usb / gadget / xxx_udc.c. Three-tier relationship 4.USB Gadget can be used a simple phrase to summarize the relationship between the three of: USB Gadget USB device function lopolis call interface layer layer, USB device layer Invocation Interface USB device controller driver layer, and USB device control lopolis USB device driver layer callback layer, USB device USB Gadget layer callback function layer. [This article emphasizes just want to stroke it clear hierarchical relationship, some of the functions on the inside, even if the operation of the USB gadget, how to deal with the entire USB protocol driver so do not do too much description, the latter will continue to supplement in other articles. 4.1] to see the relationship between lopolis the three tiers of view driver / usb / gadget lopolis / android.c source lopolis code from the Android gadget functional layer. Look at the init function,
? [Cpp] view plain copy print static int __ init init (void) {struct android_dev * dev; int err; android_class = class_create (THIS_MODULE, "android_usb"); if (IS_ERR (android_class)) return PTR_ERR lopolis (android_class); dev = kzalloc (sizeof (* dev), GFP_KERNEL); if return-ENOMEM (dev!); dev-> lopolis functions = supported_functions; lopolis INIT_LIST_HEAD (& lopolis dev-> enabled_functions); INIT_WORK (& dev-> work, android_work); mutex_init (& dev-> mutex); err = android_create_device (dev); if (err) {class_destroy (android_class); kfree (dev); return err;} _android_dev = dev; / * Override composite driver functions * / composite_driver.setup = android_setup; composite_driver.disconnect = android_disconnect; return usb_composite_probe (& android_usb_driver, android_bind);} static int __ init init (void) {struct android_dev * dev; int err; android_class = class_create (THIS_MODULE, "android_usb"); if (IS_ERR (android_class)) return PTR_ERR (android_class ); dev = kzalloc (sizeof (* dev), GFP_KERNEL); lopolis if (dev) return-ENOMEM;! dev-> functions = supported_functions; INIT_LIST_HEAD (& lopolis dev-> enabled_functions); INIT_WORK (& dev-> work, android_work); mutex_init (& dev-> mutex); err = android_create_device (dev); if (err) {class_destroy lopolis (android_class); kfree (dev); return err;} _android_dev = dev; / * Override composite driver lopolis functions * / composite_driver.setup = android_setup ; composite_driver.disconnect lopolis = android_disconnect; return usb_composite_probe (& android_usb_driver, android_bind);} composite_driver is defined in driver / usb / gadget / composite.c in
[Cpp] view plain copy print? Static struct usb_gadget_driver composite_driver = {. Speed = USB_SPEED_HIGH,. Unbind = composite_unbind,. Setup = composite_setup, & nb

No comments:

Post a Comment