篆体字作品 | 篆体字知识 | 加入收藏 篆体字转换器软件可转换多种篆体字在线预览 网页版 V2.0
篆体字转换器

当前位置:篆体字网 > 知识库 >

platform_device

时间:2024-01-07 03:03:45 编辑:篆字君 来源:篆体字网

看2410的驱动,始终没弄清楚设备和总线是如何勾搭上的,顺藤摸瓜就找到了下面这个函数,好好的分析一下吧。对驱动模型理解的不是太透彻,不对的地方您尽管仍(最好是鸡蛋,现在都买不起了)

int platform_device_add(struct platform_device *pdev)
{
int i, ret=0;

if (!pdev)
return -EINVAL;

if (!pdev->dev.parent)/*都说总线有两个链表,一个是设备链表(通过device内嵌)一个是驱动链表(通过device_driver内嵌)这里如果pdev->dev.parent为0,说明设备链表还没有设备,因此处理办法是将platform_bus作为设备链表的开始,一直感觉platform_bus和platform_bus_type很难区分,不过在这里清楚了platform_bus是一个设备,platform_bus_type才是真正的总线*/
pdev->dev.parent=&platform_bus;

pdev->dev.bus=&platform_bus_type;

if (pdev->id !=-1)
snprintf(pdev->dev.bus_id, BUS_ID_SIZE, "%s.%d", pdev->name,
pdev->id);
else
strlcpy(pdev->dev.bus_id, pdev->name, BUS_ID_SIZE);

for (i=0; i< pdev->num_resources; i++) {
struct resource *p, *r=&pdev->resource[i];

if (r->name==NULL)
r->name=pdev->dev.bus_id;

p=r->parent;
if (!p) {
if (r->flags & IORESOURCE_MEM)
p=&iomem_resource;
else if (r->flags & IORESOURCE_IO)
p=&ioport_resource;
}

if (p && insert_resource(p, r)) {
printk(KERN_ERR
"%s: failed to claim resource %d",
pdev->dev.bus_id, i);
ret=-EBUSY;
goto failed;
}
}

pr_debug("Registering platform device '%s'. Parent at %s",
pdev->dev.bus_id, pdev->dev.parent->bus_id);

ret=device_add(&pdev->dev);
if (ret==0)
return ret;

failed:
while (--i >=0)
if (pdev->resource[i].flags & (IORESOURCE_MEM|IORESOURCE_IO))
release_resource(&pdev->resource[i]);
return ret;
}
EXPORT_SYMBOL_GPL(platform_device_add);

Copyright:2021-2023 篆体字转换器 www.dddtedu.com All rights reserved.