zoukankan      html  css  js  c++  java
  • 模块驱动调试记录 ——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;

     

  • 相关阅读:
    Mbps、Kbps、bps、kb、mb区别和换算
    Python导入模块方法
    C# WinForm 程序免安装 .NET Framework(XP/win7/win10环境运行)
    生成缩略图
    WCF 的优势和特点
    不要在using语句中调用WCF服务
    pb getchild获取DropDownDW子窗体后进行取值
    Bootstrap后台管理模板调研
    PB调用C#编写的DLL
    PowerBuilder与嵌入浏览器交互
  • 原文地址:https://www.cnblogs.com/rex-2018-cloud/p/10442539.html
Copyright © 2011-2022 走看看