模块驱动调试记录 ——platform_driver_register

当前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 阅读( ...) 评论( ...) 编辑 收藏

转载于:https://www.cnblogs.com/rex-2018-cloud/p/10442539.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值