==== This article is the original site. You are welcome to reprint it! Reprinted please indicate the source: http://blog.csdn.net/yyplc====
After the registration is complete, how is the device connected to the driver? It turns out that the device has been connected in driver_register () registration.
The serial port is a platform device. The device registration is completed in the system framework setup_arch (), and the device registration is prior to the driver registration. Finally, the connection between the serial port device and the driver is in driver_register () --> bus_add_driver.
Int bus_add_driver (struct device_driver * DRV) {intret; structdevice_driver * Other ;... If (DRV-> bus-> P-> drivers_autoprobe) {// platfrom_but_type = 1 automatic platfrom device error = driver_attach (DRV); If (error) goto out_unregister ;} ....}
Finally, driver_attach () --> bus_for_each_dev () to connect the serial device to the driver.
Int bus_for_each_dev (struct bus_type * bus, struct device * Start, void * data, INT (* fN) (struct device *, void *) {structklist_iter I; structdevice * dev; interror = 0; If (! Bus) Return-einval; klist_iter_init_node (& bus-> P-> klist_devices, & I, (start? & START-> P-> knode_bus: NULL); While (Dev = next_device (& I ))&&! Error) // traverse all corresponding devices. Error = FN (Dev, data); klist_iter_exit (& I); Return Error ;}