打开打印后,如下:
1. bus: 'i2c': add driver at24
2. bus: 'i2c': driver_probe_device: matched device 0-0056 with driver at24
3. bus: 'i2c': really_probe: probing driver at24 with device 0-0056
4. at24 0-0056: no default pinctrl state
5. devices_kset: Moving 0-0056 to end of list
6. at24 0-0056: probe
7 .addr: 0x56,name:24c256
8. driver: 'at24': driver_bound: bound to device '0-0056'
9. bus: 'i2c': really_probe: bound device 0-0056 to driver at24
10. i2c-core: driver [at24] registered
看函数过程:
i2c_register_driver(struct module *owner, struct i2c_driver *driver)
driver->driver.bus = &i2c_bus_type; //设置总线类型为I2C,里面包含match和probe函数
driver_register(&driver->driver);
driver_find(drv->name, drv->bus); //查看是否重复注册
bus_add_driver(drv);
pr_debug("bus: '%s': add driver %s\n", bus->name, drv->name); //打印1
driver_attach(drv);
bus_for_each_dev(drv->bus, NULL, drv, __driver_attach);
error = fn(dev, data); //调用函数指针fn = __driver_attach
__driver_attach(struct device *dev, void *data)
driver_probe_device
pr_debug("bus: '%s': %s: matched device %s with drive%s\n",//打印2
really_probe(dev, drv);//准备调用i2c_bus_type中的probe
pr_debug("bus: '%s': %s: probing driver %s with device //打印3
ret = dev->bus->probe(dev);//调用probe
下面继续深入,了解i2c_bus_type
struct bus_type i2c_bus_type = {
.name = "i2c",
.match = i2c_device_match,
.probe = i2c_device_probe,
.remove = i2c_device_remove,
.shutdown = i2c_device_shutdown,
};
1. match函数
i2c_device_match
i2c_match_id(driver->id_table, client)
if (strcmp(client->name, id->name) == 0)//比较dts中的name和driver提供的id name是否一致,一致则匹配成功
2.probe 函数
上面已经讲述到,会调用此probe函数
driver->probe(client, i2c_match_id(driver->id_table, client)) //调用driver probe。打印6和7