Rex_Zhang

  博客园  :: 首页  :: 新随笔  :: 联系 :: 订阅 订阅  :: 管理

当前module_init中使用 platform_driver_register(&dev_driver)注册了设备驱动,在 /sys/bus/platform/drivers 生成了以dev_driver->driver.name命名的驱动分支;

但是发现没有调用probe函数;

了解一下platform_driver_register 驱动注册的流程;

驱动注册的时候platform_driver_register()->driver_register()->bus_add_driver()->driver_attach()->bus_for_each_dev()
对每个挂在虚拟的platform bus的设备作match操作;
如果相符就调用platform_drv_probe()->driver->probe(),如果probe成功则绑定该设备到该驱动.

具体platform驱动和设备是如何match的呢?

当前platform_driverde 结构如下:
static struct platform_driver hisi_poe_driver = {
    .probe = xxx_poe_probe,
    .remove = xxx_poe_remove,
    .driver = {
        .name = XXX_POE_DRV_NAME,
        .of_match_table = xxx_poe_match,
        .acpi_match_table = ACPI_PTR(xxx_poe_acpi_ids),
    },
};

有name、of_match_table、acpi_match_table三个字段;总线上的device和driver进行匹配的时候会调用bus的match函数,对于platform bus而言就是platform_match: 

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); 

    /* 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); 
} 

很明显,先匹配of_match_table,再是acpi_match_table,然后是id_table,最后才是匹配name;

 

 

posted on 2019-02-27 11:26  Rex_Zhang  阅读(6302)  评论(0编辑  收藏  举报