Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Who calls "probe" function in driver code?

I am trying to understand this driver code of mcspi for omap2 panda board.

I don't understand who calls the probe function and what is the call chain in this driver code?

How does the driver is informed when the device is connected?

like image 762
Sagar Jain Avatar asked Mar 28 '14 20:03

Sagar Jain


People also ask

What is driver probe function?

The kernel then calls the driver's probe() function once for each device. This probe function starts the per-device initialization: initializing hardware, allocating resources, and registering the device with the kernel as a block or network device or whatever it is.

What is probe in Linux kernel?

Kernel probes are a set of tools to collect Linux kernel debugging and performance information. Developers and system administrators usually use them either to debug the kernel, or to find system performance bottlenecks. The reported data can then be used to tune the system for better performance.

How do kernel drivers work?

The kernel calls device drivers during system initialization to determine which devices are available and to initialize those devices. System calls from user processes. The kernel calls a device driver to perform I/O operations on the device such as open(2), read(2), and ioctl(2). User-level requests.

What is Of_match_table?

OF match style is the first matching mechanism performed by the platform core in order to match devices with their drivers. It uses a device tree's compatible property to match the device entry in of_match_table , which is a field of the struct driver substructure.


1 Answers

The probe function from spi-omap2-mcspi.c is saved in the static struct platform_driver omap2_mcspi_driver, which is registered with module_platform_driver(omap2_mcspi_driver); (at the end of file). The module_platform_driver macro, defined in platform_device.h will pass the struct to platform_driver_register macro and __platform_driver_register function from drivers/base/platform.c

527 /**
528  * __platform_driver_register - register a driver for platform-level devices
529  * @drv: platform driver structure
530  * @owner: owning module/driver
531  */
532 int __platform_driver_register(struct platform_driver *drv,
533                                 struct module *owner)
534 {
...
536         drv->driver.bus = &platform_bus_type;
537         if (drv->probe)
538                 drv->driver.probe = platform_drv_probe;
...
544         return driver_register(&drv->driver);
545 }
546 EXPORT_SYMBOL_GPL(__platform_driver_register);

The probe now passed to driver_register function from drivers/base/driver.c

139 /**
140  * driver_register - register driver with bus
141  * @drv: driver to register
142  *
143  * We pass off most of the work to the bus_add_driver() call,
144  * since most of the things we have to do deal with the bus
145  * structures.
146  */
147 int driver_register(struct device_driver *drv)
148 {
...
154         if ((drv->bus->probe && drv->probe) ||
...
167         ret = bus_add_driver(drv);
...
178 }

So, now the driver is registered in the bus (platform_bus_type).

Actual call to probe is done via driver_probe_device drivers/base/dd.c, then really_probe (same file line 265):

265 static int really_probe(struct device *dev, struct device_driver *drv)
266 {
...
270         pr_debug("bus: '%s': %s: probing driver %s with device %s\n",
271                  drv->bus->name, __func__, drv->name, dev_name(dev));
...
287         if (dev->bus->probe) {
288                 ret = dev->bus->probe(dev);       /// <<<< HERE
289                 if (ret)
290                         goto probe_failed;
291         } else if (drv->probe) {
292                 ret = drv->probe(dev);            /// <<<< OR HERE
293                 if (ret)
294                         goto probe_failed;
295         }
296 
297         driver_bound(dev);
298         ret = 1;
299         pr_debug("bus: '%s': %s: bound device %s to driver %s\n",
300                  drv->bus->name, __func__, dev_name(dev), drv->name);
301         goto done;
like image 60
osgx Avatar answered Oct 24 '22 08:10

osgx