platform_driver构造体有device_driver成员,该成员的各自字段如上所示,device_driver也有probe、remove、shutdown等函数,在平台驱动注册的时刻被初始化。
前面说过,当体系中存在有平台设备和平台驱动经由过程总线的match函数匹配后则会调用platform_driver的probe函数,参数为platform_device,有时刻也经由过程id_table来断定是否匹配。
- int platform_device_add(struct platform_device *pdev)
- {
- int i, ret = 0;
- if (!pdev) /* 如不雅pdev为空则返回EINVAL */
- return -EINVAL;
- /* 如不雅pdev->dev.parent为空则将pdev->dev.parent设置为platform_bus */
- if (!pdev->dev.parent)
- pdev->dev.parent = &platform_bus;
- pdev->dev.bus = &platform_bus_type; /* 设置总线类型 */
- if (pdev->id != -1) /* 如不雅id = -1则表示主动分派name */
- dev_set_name(&pdev->dev, "%s.%d", pdev->name, pdev->id);
- else
- dev_set_name(&pdev->dev, pdev->name);
- for (i = 0; i < pdev->num_resources; i++) {
- struct resource *p, *r = &pdev->resource[i]; /* 获取资本 */
- if (r->name == NULL)
- r->name = dev_name(&pdev->dev);
- p = r->parent;
- if (!p) {
- if (resource_type(r) == IORESOURCE_MEM) /* 设置资本类型 */
- p = &iomem_resource;
- else if (resource_type(r) == IORESOURCE_IO)
- p = &ioport_resource;
- }
- if (p && insert_resource(p, r)) {
推荐阅读
Linux Lite第一个支持Linux 4.14及如何安装
Tech Neo技巧沙龙 | 11月25号,九州云/ZStack与您一路商量云时代收集界线治理实践 Linux Lite保护者Jerry Bezencon再次初次在Twitter上宣布他的基于Ubuntu的发行版的软件库中最新的Linux内>>>详细阅读
本文标题:Linux平台总线驱动设备模型
地址:http://www.17bianji.com/lsqh/38937.html
1/2 1