对platform_driver_probe理解

对platform_driver_probe理解/***platform_driver_probe-registerdriverfornon-hotpluggabledevice*@drv:platformdriverstructure*@probe:thedriverproberoutine,probablyfroman__initsection**Usethisinste…

/**
 * 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;
}

 

今天的文章对platform_driver_probe理解分享到此就结束了,感谢您的阅读,如果确实帮到您,您可以动动手指转发给其他人。

版权声明:本文内容由互联网用户自发贡献,该文观点仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 举报,一经查实,本站将立刻删除。
如需转载请保留出处:https://bianchenghao.cn/25976.html

(0)
编程小号编程小号

相关推荐

发表回复

您的电子邮箱地址不会被公开。 必填项已用*标注