Probe function in Linux USB device driver in brief

The probe function is called when a device is installed that the USB core thinks this driver should handle; the probe function should perform checks on the information passed to it about the device and decide whether the driver is really appropriate for that device.


In the probe function callback, the USB driver should initialize any local structures that it might use to manage the USB device. It should also save any information that it needs about the device to the local structure, as it is usually easier to do so at this time. As an example, USB drivers usually want to detect what the endpoint address and buffer sizes are for the device, as they are needed in order to communicate with the device. 

The probe function has following prototype,

static int test_probe(struct usb_interface *interface, const struct usb_device_id *id)

Typical flow of detecting the endpoints' information, driver:
  • loops over every endpoint that is present in provided interface 
  • looks for endpoint direction(IN or OUT) which can be tested by seeing whether the bitmask USB_DIR_* is contained in bEndPointAddress 
  • determines whether the endpoint type is what driver expects by first masking off the bmAttributes variable with the USB_ENDPOINT_XFERTYPE_MASK bitmask, and then checking if it matches the value of expected endpoint type USB_ENDPOINT_XFER_* 
If all of these tests are true, the driver knows it found the proper type of endpoint and can save the information about the endpoint that it will later need to communicate over it in a local structure.

After identifying appropriate endpoint, driver: 
  • saves it's local data structure into usb_interface using usb_set_intfdata and this local data structure can be retrieved using usb_get_intfdata. usb_get_intfdata is usually called in driver's open and disconnect function 
  • registers itself with usb core using usb_register_dev at last
References: 

Comments

Popular posts from this blog

MBR partitioning with 'parted' utility

Replace default splash screen in Yocto

Disk Partitioning: MBR vs GPT