u-boot device_0f_to_plat函数
//
//递归函数来设定设备dev的数据,
- 分配设备的私有数据
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; }