/**
* platform_driver_probe - register driver for non-hotpluggable device
* @drv: platform driver structure
* @probe: the driver probe routine, probably from an __init section
*
* Use this instead of platform_driver_register() when you know the device
* is not hotpluggable and has already been registered, and you want to
* remove its run-once probe() infrastructure from memory after the driver
* has bound to the device.
*
* One typical use for this would be with drivers for controllers integrated
* into system-on-chip processors, where the controller devices have been
* configured as part of board setup.
*
* Returns zero if the driver registered and bound to a device, else returns
* a negative error code and with the driver not registered.
*/
//匹配执行probe,没有设备匹配退出注册队列
//probe只执行platform_driver_probe调用的那次
//如果设备注册匹配到这个驱动,也不会调用到probe函数
int __init_or_module platform_driver_probe(struct platform_driver *drv,
int (*probe)(struct platform_device *))
{
int retval, code;
//在这里把probe函数指向传入的函数
/* temporary section violation during probe() */
drv->probe = probe;
retval = code = platform_driver_register(drv);
/* Fixup that section violation, being paranoid about code scanning
* the list of drivers in order to probe new devices. Check to see
* if the probe was successful, and make sure any forced probes of
* new devices fail.
*/
spin_lock(&platform_bus_type.p->klist_drivers.k_lock);
//注册好驱动后,把drv->probe清空,指向NULL
//结果就是1、当设备不存在时,不会调用probe函数。
//2、如果是驱动先注册,设备后注册,也不会调用probe,就是说不支持热拔插
//platform_driver_probe可以理解为注册驱动,匹配就调用probe,不存在就以后就再也不会调用
drv->probe = NULL;
//判断是否有设备匹配,没有就retval = -ENODEV;
if (code == 0 && list_empty(&drv->driver.p->klist_devices.k_list))
retval = -ENODEV;
drv->driver.probe = platform_drv_probe_fail;
spin_unlock(&platform_bus_type.p->klist_drivers.k_lock);
//没有匹配到设备,就会执行platform_driver_unregister,卸载掉已注册的设备驱动
if (code != retval)
platform_driver_unregister(drv);
return retval;
}