全部博文(668)
分类:
2009-05-12 16:13:20
driver_register() --> bus_add_driver() /usr/src/linux-2.6.21.5/drivers/base/bus.c bus_add_driver - Add a driver to the bus. bus_add_driver() -- 将驱动添加到总线上,并与总线上的设备匹配 int bus_add_driver(struct device_driver *drv) { 查找与驱动程序相关的总线 |-------------------------------------------------| | struct bus_type * bus = get_bus(drv->bus); | |-------------------------------------------------| int error = 0; if (!bus) return 0; 根据驱动程序的名字以及相关的总线,创建驱动程序的sysfs目录 |--------------------------------------------------------------| | pr_debug("bus %s: add driver %s\n", bus->name, drv->name); | | error = kobject_set_name(&drv->kobj, "%s", drv->name); | | if (error) | | goto out_put_bus; | | drv->kobj.kset = &bus->drivers; | | if ((error = kobject_register(&drv->kobj))) | | goto out_put_bus; | |--------------------------------------------------------------| 遍历总线上的所有设备,搜寻与驱动匹配的设备 |----------------------------------| | error = driver_attach(drv); | | if (error) | | goto out_unregister; | |----------------------------------| klist_add_tail(&drv->knode_bus, &bus->klist_drivers); module_add_driver(drv->owner, drv); |-------------------------------------------------------------| | error = driver_add_attrs(bus, drv); | | if (error) { | | printk(KERN_ERR "%s: driver_add_attrs(%s) failed\n", -| | __FUNCTION__, drv->name); | | } | | error = add_bind_files(drv); | | if (error) { | | printk(KERN_ERR "%s: add_bind_files(%s) failed\n", | | __FUNCTION__, drv->name); | | } | |-------------------------------------------------------------| return error; out_unregister: kobject_unregister(&drv->kobj); out_put_bus: put_bus(bus); return error; } |