Linux Driver 和Device的匹配过程

platform_driver_register()
->driver_register()
->bus_add_driver()
->driver_attach()
->bus_for_each_dev()

对每个挂在虚拟的platform bus的设备作
__driver_attach()
->driver_probe_device()
->drv->bus->match()==platform_match()
->比较strncmp(pdev->name, drv->name, BUS_ID_SIZE)
如果相符就调用platform_drv_probe()->driver->probe(),如果probe成功则绑定该设备到该驱动.

static int platform_match(struct device *dev, struct device_driver *drv)
{
	struct platform_device *pdev = to_platform_device(dev);
	struct platform_driver *pdrv = to_platform_driver(drv);

	/* When driver_override is set, only bind to the matching driver */
	if (pdev->driver_override)
		return !strcmp(pdev->driver_override, drv->name);

	/* Attempt an OF style match first */
	if (of_driver_match_device(dev, drv))
		return 1;

	/* Then try ACPI style match */
	if (acpi_driver_match_device(dev, drv))
		return 1;

	/* Then try to match against the id table */
	if (pdrv->id_table)
		return platform_match_id(pdrv->id_table, pdev) != NULL;

	/* fall-back to driver name match */
	return (strcmp(pdev->name, drv->name) == 0);
}

你可能感兴趣的:(linux)