Create successful ePaper yourself
Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.
511 * @driver: the driver model core driver structure.<br />
512 *<br />
513 * USB drivers must provide a name, probe() and disconnect() methods,<br />
514 * and an id_table. Other driver fields are optional.<br />
515 *<br />
516 * The id_table is used in hotplugging. It holds a set <strong>of</strong> descriptors,<br />
517 * and specialized data may be associated with each entry. That table<br />
518 * is used by both user and kernel mode hotplugging support.<br />
519 *<br />
520 * The probe() and disconnect() methods are called in a context where<br />
521 * they can sleep, but they should avoid abusing the privilege. Most<br />
522 * work to connect to a device should be done when the device is opened,<br />
523 * and undone at the last close. The disconnect code needs to address<br />
524 * concurrency issues with respect to open() and close() methods, as<br />
525 * well as forcing all pending I/O requests to complete (by unlinking<br />
526 * them as necessary, and blocking until the unlinks complete).<br />
527 */<br />
528 struct usb_driver {<br />
529 struct module *owner;<br />
530<br />
531 const char *name;<br />
532<br />
533 int (*probe) (struct usb_interface *intf,<br />
534 const struct usb_device_id *id);<br />
535<br />
536 void (*disconnect) (struct usb_interface *intf);<br />
537<br />
538 int (*ioctl) (struct usb_interface *intf, unsigned int code, void *buf);<br />
539<br />
540 int (*suspend) (struct usb_interface *intf, u32 state);<br />
541 int (*resume) (struct usb_interface *intf);<br />
542<br />
543 const struct usb_device_id *id_table;<br />
544<br />
15<br />
545 struct device_driver driver;<br />
546 };<br />
547 #define to_usb_driver(d) container_<strong>of</strong>(d, struct usb_driver, driver)<br />
看似很长一段,实际上也就是注释为主.而此刻我们只需注意到其中的struct device_driver<br />
driver 这个成员,usb core 为每一个设备驱动准备了一个函数,让它把自己的这个struct<br />
device_driver driver 插入到usb_bus_type 中的drivers 链表中去.而这个函数正是我们此<br />
前看到的usb_register.而与之对应的usb_deregister 所从事的正是与之相反的工作,把这个<br />
结构体从drivers 链表中删除.可以说,usb core 的确是用心良苦,为每一个usb 设备驱动做足<br />
了