模塊驅動調試記錄 ——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;

 

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM