Linux-driven probe function call

Source: Internet
Author: User

Refer:

Http://blog.chinaunix.net/space.php? Uid = 15887868 & Do = Blog & id = 2758294

Http://www.cnblogs.com/hoys/archive/2011/04/01/2002299.html
1. driver_register registers the driver to the bus.

/*** Driver_register-register driver with bus * @ DRV: Driver to register * We pass off most of the work to the bus_add_driver () call, * Since most of the things we have to do deal with the bus * structures. */INT driver_register (struct device_driver * DRV ){........................ If (DRV-> bus-> probe & DRV-> probe) | (DRV-> bus-> remove & DRV-> remove) | (DRV-> bus-> shutdown & DRV-> shutdown) ret = bus_add_driver (DRV); // run the DRV driver, register to the bus ........................}

2. The implementation function that the driver registers to the bus

/*** Bus_add_driver-Add a driver to the bus. ----- Add a driver to the bus * @ DRV: Driver. */INT bus_add_driver (struct device_driver * DRV ){.................. If (DRV-> bus-> P-> drivers_autoprobe) {error = driver_attach (DRV); // driver matching function ..................}

3, driver_attach ()

/*** Driver_attach-try to bind driver to devices. * @ DRV: Driver. ** walk the list of devices that the bus has on it and try to * match the driver with each one. if driver_probe_device () * returns 0 and the @ Dev-> driver is set, we 've found a * compatible pair. */INT driver_attach (struct device_driver * DRV) {return bus_for_each_dev (DRV-> bus, null, DRV, _ driver_attach ); // note _ driver_attach} export_symbol_gpl (driver_attach) here );

What actually works above is _ driver_attach:

Static int _ driver_attach (struct device * Dev, void * Data) {struct device_driver * DRV = data;/** Lock Device and try to bind to it. we drop the error * here and always return 0, because we need to keep trying * to bind to devices and some drivers will return an error * simply if it didn't support the device. ** driver_probe_device () will spit a warning if there * is an error. */If (! Driver_match_device (DRV, Dev) return 0; If (Dev-> parent)/* needed for USB */device_lock (Dev-> parent); device_lock (Dev); If (! Dev-> driver) driver_probe_device (DRV, Dev); // check the implementation process of this function: device_unlock (Dev); If (Dev-> parent) device_unlock (Dev-> parent); Return 0;} int driver_probe_device (structdevice_driver * DRV, struct device * Dev ){... // 1. first, determine whether the bus matches: If (DRV-> bus-> match &&! DRV-> bus-> match (Dev, DRV) goto done; // 2. Run Probe: ret = really_probe (Dev, DRV );...}

4. really_probe is the function we are looking.

Static int really_probe (struct device * Dev, struct device_driver * DRV ){........................ // 1. first, call the probe function of the bus to which the driver belongs: If (Dev-> bus-> probe) {ret = Dev-> bus-> probe (Dev); If (RET) goto probe_failed;} // 2. then call the probe function in the driver: else if (DRV-> probe) {ret = DRV-> probe (Dev); If (RET) goto probe_failed;} driver_bound (Dev ); ret = 1; pr_debug ("Bus: '% s': % s: bound device % s to driver % s \ n", DRV-> bus-> name, _ FUNC __, dev_name (Dev), DRV-> name); // you can view the registered driver, device, and bus information goto done; ..................}

The printed driver information is as follows:

..................

[0.588087] Bus: 'platform': really_probe: bound device powerbench to driverpower // Bus: platform device: power.0 DRIVER: Power
[0.661226] Bus: 'platform': really_probe: bound device s3c24xx-pwm.0 to driver s3c24xx-pwm
[0.678552] Bus: 'platform': really_probe: bound device s3c24xx-pwm.1 to driver s3c24xx-pwm
[0.695971] Bus: 'platform': really_probe: bound device s3c24xx-pwm.2 to driver s3c24xx-pwm
[0.713389 Bus: 'platform': really_probe: bound device s3c24xx-pwm.3 to driver
........................

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.