第一:
All USB related functions or data structures follow the same naming convention and start with usb_. The following shows the structure needed to register a USB device driver at the subsystem.
第二:
The USB driver framework adds two entry points to normal device drivers:
The dev argument specifies the device context, which contains pointers to all USB descriptors. The interface argument specifies the interface number. If a USB driver wants to bind itself to a particular device and interface it has to return a pointer. This pointer normally references the device driver's context structure.
Probing normally is done by checking the vendor and product identifications or the class and subclass definitions. If they match the interface number is compared with the ones supported by the driver. When probing is done class based it might be necessary to parse some more USB descriptors because the device properties can differ in a wide range.
A simple probe routine is shown:
void disconnect(struct usb_device *dev, void *drv_context); This function is called whenever a device which was served by this driver is disconnected.
The argument dev specifies the device context and the driver_context returns a pointer to the previously registered driver_context of the probe function. After returning from the disconnect function the USB framework completly deallocates all data structures associated with this device. So especially the usb_device structure must not be used any longer by the usb driver.
第三:
Framework functions:
This function is used to register a new USB device driver at the subsystem. The argument drv points to a completely initialized usb_driver structure. On success 0 is returned otherwise an error value is returned.
This function deregisters a formerly registerd USB device driver at the subsystem.
This function is intended to be used by USB device drivers that need to claim more than one interface on a device at once when probing. The argument driver points to a completely initialized usb_driver structure. The iface argument points to a usb_interface structure which is part of the usb_config_descriptor which is accesible from the usb_device structure (given in the probe function). The drv_context pointer normally references the device driver's context structure (see return value of the probe function).
This function is used to check if another device driver already has claimed the specified interface. The return value is 0 if the interface was not claimed by any driver.
If a driver wants to release a previously claimed interface it has to call this function. In the disconnect function you do not have to release any interfaces that were additionally claimed in the probe function.
欢迎光临 电子技术论坛_中国专业的电子工程师学习交流社区-中电网技术论坛 (http://bbs.eccn.com/) | Powered by Discuz! 7.0.0 |