3.是谁掀起了你的盖头来?
对linux驱动模型有一点了解的兄弟知道,一个驱动,特别是挂上总线的驱动,
真正开始执行都是始于probe函数。我们这里的lis3lv02d_i2c驱动,是挂在系统的i2c总线上的,
因而也就会从probe开始执行。那么是谁来调用这个probe内?就好像驱动通过总线介绍,嫁给了设备,
那到底是哪个设备去掀起驱动的红盖头呢?我们从i2c_register_driver看开去。
代码在kernel/driver/i2c/i2c-core.c中:
872 /*
873 * An i2c_driver is used with one or more i2c_client (device) nodes to access
874 * i2c slave chips, on a bus instance associated with some i2c_adapter.
875 */
876
877 int i2c_register_driver(struct module *owner, struct i2c_driver *driver)
878 {
879 int res;
880
881 /* Can't register until after driver model init */
882 if (unlikely(WARN_ON(!i2c_bus_type.p)))
883 return -EAGAIN;
884
885 /* add the driver to the list of i2c drivers in the driver core */
886 driver->driver.owner = owner;
887 driver->driver.bus = &i2c_bus_type;
888
889 /* When registration returns, the driver core
890 * will have called probe() for all matching-but-unbound devices.
891 */
892 res = driver_register(&driver->driver);
893 if (res)
894 return res;
895
896 pr_debug("i2c-core: driver [%s] registered\n", driver->driver.name);
897
898 INIT_LIST_HEAD(&driver->clients);
899 /* Walk the adapters that are already present */
900 mutex_lock(&core_lock);
901 bus_for_each_dev(&i2c_bus_type, NULL, driver, __attach_adapter);
902 mutex_unlock(&core_lock);
903 ///WTT DEBUG
904 printk("***** WTT DEBUG i2c_register_driver to return 0\
对linux驱动模型有一点了解的兄弟知道,一个驱动,特别是挂上总线的驱动,
真正开始执行都是始于probe函数。我们这里的lis3lv02d_i2c驱动,是挂在系统的i2c总线上的,
因而也就会从probe开始执行。那么是谁来调用这个probe内?就好像驱动通过总线介绍,嫁给了设备,
那到底是哪个设备去掀起驱动的红盖头呢?我们从i2c_register_driver看开去。
代码在kernel/driver/i2c/i2c-core.c中:
872 /*
873 * An i2c_driver is used with one or more i2c_client (device) nodes to access
874 * i2c slave chips, on a bus instance associated with some i2c_adapter.
875 */
876
877 int i2c_register_driver(struct module *owner, struct i2c_driver *driver)
878 {
879 int res;
880
881 /* Can't register until after driver model init */
882 if (unlikely(WARN_ON(!i2c_bus_type.p)))
883 return -EAGAIN;
884
885 /* add the driver to the list of i2c drivers in the driver core */
886 driver->driver.owner = owner;
887 driver->driver.bus = &i2c_bus_type;
888
889 /* When registration returns, the driver core
890 * will have called probe() for all matching-but-unbound devices.
891 */
892 res = driver_register(&driver->driver);
893 if (res)
894 return res;
895
896 pr_debug("i2c-core: driver [%s] registered\n", driver->driver.name);
897
898 INIT_LIST_HEAD(&driver->clients);
899 /* Walk the adapters that are already present */
900 mutex_lock(&core_lock);
901 bus_for_each_dev(&i2c_bus_type, NULL, driver, __attach_adapter);
902 mutex_unlock(&core_lock);
903 ///WTT DEBUG
904 printk("***** WTT DEBUG i2c_register_driver to return 0\

本文深入探讨Linux驱动模型中的I2C驱动,讲解如何从i2c_register_driver开始,通过i2c_device_match进行驱动与设备匹配,最终调用i2c_device_probe函数进行设备探测。分析了i2c_driver结构体和i2c_device_probe的工作流程,包括设备验证、初始化等步骤。
最低0.47元/天 解锁文章

被折叠的 条评论
为什么被折叠?



