When a USB device is plugged into the system, the kernel need to load the appropriate drive.

It works as follows:

  1. Each driver in the code exposes its vendor/device id using:
  MODULE_DEVICE_TABLE(of, omap_mcspi_of_match);
  1. At compilation time the build process extracts this infomation from all the drivers and prepares a device table.
  2. When you insert the device, the device table is referred by the kernel and if an entry is found matching the device/vendor id of the added device, then its module is loaded and initialized.
static struct usb_driver led_driver = {
	.owner =	THIS_MODULE,
	.name =		"usbled",
	.probe =	led_probe,
	.disconnect =	led_disconnect,
	.id_table =	id_table,
};
 

The id_table variable is defined as:

static struct usb_device_id id_table [] = {
	{ USB_DEVICE(VENDOR_ID, PRODUCT_ID) },
	{ },
};
MODULE_DEVICE_TABLE (usb, id_table);
 


🌱 Back to Garden