_解决probe无法执行

在写linux 驱动中,使用dts/dtsi 会发现在填充 struct i2c_driver 与 struct platform_driver 是不一样,

struct i2c_driver 需要id_match_table,同时需要id_table,而struct platform_driver 只要id_match_table,不需要id_table。

来一探究竟吧

i2c_add_driver()
           └── i2c_register_driver
                      └── driver_register
                                 ├── driver_find
                                 │   ├── kset_find_obj
                                 │   ├── kobject_put
                                 │   └── to_driver
                                 └── bus_add_driver
                                            └── driver_attach
                                                       └── bus_for_each_dev
                                                                  ├── next_device
                                                                  └── __driver_attach
                                                                             └─ driver_match_device
                                                                                        └── i2c_device_match
                                                                                                   ├── acpi_driver_match_device
                                                                                                   ├── i2c_match_id
                                                                                                   └── of_driver_match_device
                                                                                                   └── of_match_device
                                                                                                              └── of_match_node
                                                                                                                         └── __of_match_node
                                                                                                                                    └── __of_device_is_compatible

  78 static int i2c_device_match(struct device *dev, struct device_driver *drv)
  79 {
  80         struct i2c_client       *client = i2c_verify_client(dev);
  81         struct i2c_driver       *driver;
  82 
  83         if (!client)
  84                 return 0;
  85 
  86         /* Attempt an OF style match */
  87         if (of_driver_match_device(dev, drv))
  88                 return 1;
  89 
  90         /* Then ACPI style match */
  91         if (acpi_driver_match_device(dev, drv))
  92                 return 1;
  93 
  94         driver = to_i2c_driver(drv);
  95         /* match on an id table if there is one */
  96         if (driver->id_table)              
  97                 return i2c_match_id(driver->id_table, client) != NULL;
  98 
  99         return 0;
 100 }

从i2c_device_match的定义可以看出, 和platform总线一样, i2c的match函数也是优先选择设备树, 如果设备树已经匹配了, 函数就会返回, 不会再最平台文件的设备信息进行判断, 即不会理会id_table的值, 确保匹配是一定不需要id_table了,而事实上probe确实没有执行,那么问题就可能出现在probe的回调过程了,和所有的总线设备一样,回调probe的过程始于driver_match_id,于是又是一路狂追,终于在i2c_device_probe()中找到了我臆想中的对id_table的检测

i2c_add_driver()
           └── i2c_register_driver
                      └── driver_register
                                 ├── driver_find
                                 │   ├── kset_find_obj
                                 │   ├── kobject_put
                                 │   └── to_driver
                                 └── bus_add_driver
                                            └── driver_attach
                                                       └── bus_for_each_dev
                                                                  ├── next_device
                                                                  └── __driver_attach
                                                                             ├── driver_match_device
                                                                             └── driver_probe_device
                                                                                        └── really_probe
                                                                                                   └── i2c_device_probe
                                                                                                              └── i2c_match_id

所以,结论是:即使使用设备树来匹配,也要对id_table进行有效的赋值,否则probe不会被回调!!!如果你也遇到了这个问题, 可以试试在驱动中定义一个空数组, 将其赋值给id_table

参考:https://www.cnblogs.com/xiaojiang1025/p/6501956.html

  • 1
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值