u-boot device_0f_to_plat函数

 

 //

//递归函数来设定设备dev的数据,

  1. 分配设备的私有数据

 

int device_of_to_plat(struct udevice *dev)
{
    const struct driver *drv;
    int ret;

    if (!dev)
        return -EINVAL;

    if (dev_get_flags(dev) & DM_FLAG_PLATDATA_VALID)
        return 0;

    /*
     * This is not needed if binding is disabled, since data is allocated
     * at build time.
     */
    if (!CONFIG_IS_ENABLED(OF_PLATDATA_NO_BIND)) {
        /* Ensure all parents have ofdata */
        if (dev->parent) {
            ret = device_of_to_plat(dev->parent);
            if (ret)
                goto fail;

            /*
             * The device might have already been probed during
             * the call to device_probe() on its parent device
             * (e.g. PCI bridge devices). Test the flags again
             * so that we don't mess up the device.
             */
            if (dev_get_flags(dev) & DM_FLAG_PLATDATA_VALID)
                return 0;
        }
//设定设备dev的私有数据
        ret = device_alloc_priv(dev);
        if (ret)
            goto fail;
    }
    drv = dev->driver;
    assert(drv);
 
//调用设备驱动程序的操作of_to_plat
    if (drv->of_to_plat &&
        (CONFIG_IS_ENABLED(OF_PLATDATA) || dev_has_ofnode(dev))) {
        ret = drv->of_to_plat(dev);
        if (ret)
            goto fail;
    }
 
//设定设备dev的flag
    dev_or_flags(dev, DM_FLAG_PLATDATA_VALID);

    return 0;
fail:
    device_free(dev);

    return ret;
}
posted @ 2022-02-21 22:12  liujunhuasd  阅读(186)  评论(0编辑  收藏  举报