Linux i2c子系统(三) _解决probe没法执行

若是你也遇到了填充了id_match_table,compitible怎么看都同样,但probe就是不执行(让我哭一会),你能够回头看一下上一篇的模板,咱们这里虽然使用的是设备树匹配,但和platform的设备树匹配只填充i2c_match_table不一样,i2c_driver的设备树匹配须要同时填充i2c_match_table和id_table两个域,虽而后者是个空。若是你没有填充后面的成员,不妨试一下个人这种写法,我敢打赌你的probe也没有执行^-^。
问题是明确的,探索是漫长的,可是至少答案必定在源码中,也必定出在匹配的源码中,带着这样的思路,我从"i2c_add_driver"开始一路狂追,结论是使用设备树的话,只要id_match_table,不须要id_table!, 下面的i2c_device_match便可看出。node

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数组

/home/jiang/Pictures/Selection_20170224_001.png
[Selection_20170224_001.png-6.4kB][1]函数

//3.14.0/drivers/i2c/i2c-core.c
  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的检测code

下面是我追的源码树,你们能够验证一下orm

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_idblog

因此,结论是:即便使用设备树来匹配,也要对id_table进行有效的赋值,不然probe不会被回调!!!若是你也遇到了这个问题, 能够试试在驱动中定义一个空数组, 将其赋值给id_table^-^源码

相关文章
相关标签/搜索