driver/usb/core/hub.c :
usb->hun_thread()->hub->events()->hub_port_connect_change()
driver/usb/core/hub.c
hub_port_connect_change() //检测到新设备连接
usb_new_device(udev) //注册新设备
usb_get_configuration(udev) //获得设备各种描述符
device_add(&udev->dev) //把这个设备注册到usb系统中
bus_attach_device(dev) //把这个设备天骄到相应bus的设备列表中
device_attach() //为设备找到相应的设备驱动程序
bus_for_each_drv(dev->bus,NULL,dev,__device_attach) //从总线上已注册的所有驱动中找出匹配的驱动程序
while((drv=next_driver(&i))&&!error)
error=fn(drv,data);//返回0将机械搜索,返回错误将停止搜索
next_driver(&i) //遍历bus上的所有驱动程序
fn(drv,data) //查看驱动是否匹配
driver_probe_device(drv,dev) //检查设备
usb_register_device_driver() //注册我们的驱动程序
//bus_register(&usb_bus_type) drivers/usb/core/usb.c
//usb_bus_type drivers/usb/core/driver.c
usb/core/driver.c
对于usb驱动会首先调用usb_device_match()
is_usb_device(dev) //dev代表整个usb设备
usb_match_id()
usb_math_dynamic_id() //dev代表usb设备interface
really_probe() //进一步匹配
usb设备两种分支:设备级别的,接口级别的。其他的被usb_device_match过滤掉了
设备级别
drv肯定是usb_generic_driver
在usb系统中只有driver是代表整个设备的驱动,它是在usb_init中被注册的,而我们通常写的usb驱动都是代表一个interface
choose_configuration()
usb_set_configuration(); //设置配置,并注册interface
device_add() //这里进行相应的接口分析,就会进入我们所说的分支2,接口。
usb_probe_interface()
driver->probe(); //这里调用自己的代码就可以了。这个函数就是我们自己写的probe函数。
以上内容是我对下面转载的简单简写,可以提供些参考。
2.6.22下的一个USB设备插上linux系统的PC后是如何一步一步调到我们的usb设备驱动的probe函数的, 我们知道我们的U