Linux--驱动内核----platform_driver_register,i2c_add_driver分析

 

platform_driver_register()
   driver_register()
      driver_find()(确定driver没有被注册)
      bus_add_driver()
          driver_attach()(匹配dev-driver并绑定)
              bus_for_each_dev()(搜索设备链表里的所有设备)
                 __driver_attach()
                    driver_match_device()(调用总线的platform_match匹配函数 比对of_match_table)
                    driver_probe_device()(匹配上就调用总线的probe 如果没有就调用drv的probe)
        module_add_driver()
        driver_create_file()
        driver_add_attrs()

 

 

i2c_add_driver(&drv_i2c_driver);
   i2c_register_driver(THIS_MODULE, driver)
      driver_register(&driver->driver);
        bus_add_driver(drv);
          driver_attach(drv);
           bus_for_each_dev(drv->bus, NULL, drv, __driver_attach); //循环查找总线上所有dev
            __driver_attach(drv); //返回一直是0
              driver_match_device(drv, dev);//检测能够匹配上的dev 如果匹配上返回i2c_device_match结果1
                drv->bus->match(dev, drv) 
                  i2c_device_match(struct device *dev, struct device_driver *drv)//如果匹配上返回1
                    of_driver_match_device(dev, drv) //如果匹配上了就会返回一个of_device_id指针
                      of_match_device(drv->of_match_table, dev)
                        of_match_node(matches, dev->of_node);
                            __of_match_node(matches, node);比较"compatible"的名字
                              match =match &( __of_device_is_compatible(node,matches->compatible));
               driver_probe_device(drv, dev);//如果dev没有和驱动绑定过则调用probe
                  really_probe(dev, drv);
                    i2c_device_probe(struct device *dev)//总线probe 设备驱动里一定要有id_table和probe否则返回错误
                       driver->probe(client, i2c_match_id(driver->id_table, client));//驱动probe 获取dev资源i2c_client已经包含了所有特定必要资源
      i2c_for_each_dev(driver, __process_new_driver);//
          __process_new_driver(struct device *dev, void *data)
              i2c_do_add_adapter(data, to_i2c_adapter(dev));
                  i2c_detect(adap, driver);//如果i2c_driver定义了detect和address_list  将i2c_cliect和i2c_driver以及i2c_adapter相连
                     i2c_detect_address(temp_client, driver);//检查设备地址是否已被使用并且有效(发送数据等待实际硬件是否有回应)
                        driver->detect(temp_client, &info);//调用设备驱动里的detect函数进行检测实际硬件是否存在
                   driver->attach_adapter(adap);//如果i2c_driver定义了attach_adapter 进行检测实际硬件是否存在

在设备驱动的probe里就可以去查询有没有真正的硬件设备比如at24c02,如果有就可以建立设备节点,提供file_operation里的open,write函数

 

 

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章