第一:
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.
- name: Usually the name of the module.
- probe: The entry point of the probe function.
- disconnect: The entry point of the disconnect function.
- driver_list: For internal use of the subsystem - initialize to {NULL,NULL}
- fops: The usual list of file operations for a driver
- minor: The base minor number assigned to this device (the value has to be a multiple of 16)
- serialize:
- ioctl:
- id_table:
第二:
The USB driver framework adds two entry points to normal device drivers:
- void *probe(struct usb_device *dev, unsigned int interface, const struct usb_device_id *id_table); This entry point is called whenever a new device is attached to the bus. Then the device driver has to create a new instance of its internal data structures for the new device.
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:
int usb_register(struct usb_driver *drv);
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.
void usb_deregister(struct usb_driver *drv);
This function deregisters a formerly registerd USB device driver at the subsystem.
void usb_driver_claim_interface(struct usb_driver *driver, struct usb_interface *iface, void *drv_context);
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).
int usb_interface_claimed(struct usb_interface *iface);
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.
void usb_driver_release_interface(struct usb_driver *driver, struct usb_interface *iface);
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.
|