Linux设备模型之platform(3)

  int platform_device_add(struct platform_device *pdev)
    {
                   int i, ret = 0;
                   if (!pdev)
                               return -EINVAL;
                   if (!pdev->dev.parent)
                               pdev->dev.parent = &platform_bus;                  //挂接到platform_bus下面
                   pdev->dev.bus = &platform_bus_type;                          //指定bus类型为platform_bus_type
                   if (pdev->id != -1)
                               dev_set_name(&pdev->dev, "%s.%d",

                                                   pdev->name,  pdev->id);              //设置名字,将platform下的名字传到内部device,最终会
                   else                                                                          //传到kobj
                               dev_set_name(&pdev->dev, "%s", pdev->name);
                    for (i = 0; i < pdev->num_resources; i++) {                   //设置资源层次结构
                                struct resource *p, *r = &pdev->resource[i];
                                if (r->name == NULL)                                     //资源名称为NULL则把设备名称设置给它
                                                   r->name = dev_name(&pdev->dev);
                                p = r->parent;                                                //取得资源的父节点,资源在内核中也是层次安排的,
                                if (!p) {                                                           //具有父节点,兄弟节点,子节点
                                                   if (resource_type(r) == IORESOURCE_MEM)       //如果父节点为NULL,并且资源类型为
                                                                p = &iomem_resource;                          //IORESOURCE_MEM,则把父节点设置

内容版权声明:除非注明,否则皆为本站原创文章。

转载注明出处:https://www.heiqu.com/22707.html