Board logo

标题: 浅谈如何编写LINUX环境里的USB驱动 [打印本页]

作者: BlueSeaHaiChao    时间: 2006-7-14 04:59     标题: 浅谈如何编写LINUX环境里的USB驱动

第一:


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.









\begin{figure}
\centering\index{struct usb\_driver}
\begin{verbatim}struct usb...
... void *buf);
const struct usb_device_id *id_table;
};\end{verbatim}\end{figure}




 


第二:


The USB driver framework adds two entry points to normal device drivers:




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.




  •  






    欢迎光临 电子技术论坛_中国专业的电子工程师学习交流社区-中电网技术论坛 (http://bbs.eccn.com/) Powered by Discuz! 7.0.0