יום שלישי, 28 במאי 2013

MODULE_USB_DRIVER macro part1

The module_usb_driver macro is an helper macro that wrap the module_init and module_exit macros for using to register usb module.
The input parameter is a structure of type struct usb_driver containing the interfaces for the driver.
The parameters:
const char *name;
The name of the usb driver module should be unique.

const struct usb_device_id *id_table;
The table of device id of this device. This value must be set in order to cause the kernel to call this device.
Atypical id_table looks like this:

  1:  static const struct usb_device_id usbduxsigma_usb_table[] = {
  2:          { USB_DEVICE(0x13d8, 0x0020) },
  3:          { USB_DEVICE(0x13d8, 0x0021) },
  4:          { USB_DEVICE(0x13d8, 0x0022) },
  5:          { }
  6:  };

Where the USB_DEVICE macro contains the vendor and the device id

int (*probe) (struct usb_interface *intf,const struct usb_device_id *id);
This callback return if a particular  device can be managed by this module.
If the module can handle the device the module initialization is done in this callback .
The device_id struct

  1:  struct usb_device_id {
  2:       /* which fields to match against? */
  3:       __u16           match_flags;
  4: 
  5:       /* Used for product specific matches; range is inclusive */
  6:       __u16           idVendor;
  7:       __u16           idProduct;
  8:       __u16           bcdDevice_lo;
  9:       __u16           bcdDevice_hi;
 10: 
 11:       /* Used for device class matches */
 12:       __u8            bDeviceClass;
 13:       __u8            bDeviceSubClass;
 14:       __u8            bDeviceProtocol;
 15: 
 16:       /* Used for interface class matches */
 17:       __u8            bInterfaceClass;
 18:       __u8            bInterfaceSubClass;
 19:       __u8            bInterfaceProtocol;
 20: 
 21:       /* Used for vendor-specific interface matches */
 22:       __u8            bInterfaceNumber;
 23: 
 24:       /* not matched against */
 25:       kernel_ulong_t  driver_info
 26:               __attribute__((aligned(sizeof(kernel_ulong_t))));
 27: 

Contains the idVendor and idProducts tfrom the id tables

struct usb_interface - what usb device drivers talk to



אין תגובות:

הוסף רשומת תגובה