调用of_platform_populate函数创建platform device
转载于 : http://www.voidcn.com/blog/bin_linux96/article/p-1210202.html
解析完DTB以后,会调用of_platform_populate函数创建platform device,调用顺序如下: of_platform_populate of_platform_bus_create of_platform_device_create_pdata of_device_alloc of_device_add staticint of_platform_bus_create(struct device_node *bus, const struct of_device_id *matches, const struct of_dev_auxdata *lookup, struct device *parent, bool strict) { conststruct of_dev_auxdata *auxdata; structdevice_node *child; structplatform_device *dev; constchar *bus_id = NULL; void*platform_data = NULL; intrc = 0; /*创建platformdevice结构 */ dev= of_platform_device_create_pdata(bus, bus_id, platform_data, parent); if(!dev || !of_match_node(matches, bus))/*如果不匹配matchs,则不需要为子节点创建platform_device*/ return0; /*遍历所有子节点,递归条用of_platform_bus_create*/ for_each_child_of_node(bus,child) { pr_debug(" create child: %s\n",child->full_name); rc= of_platform_bus_create(child, matches, lookup, &dev->dev, strict); } returnrc; } struct platform_device*of_platform_device_create_pdata( structdevice_node *np, constchar *bus_id, void*platform_data, structdevice *parent) { structplatform_device *dev; /*分配platform_device结构 */ dev= of_device_alloc(np, bus_id, parent); if(!dev) returnNULL; dev->dev.coherent_dma_mask= DMA_BIT_MASK(32); dev->dev.bus= &platform_bus_type; dev->dev.platform_data= platform_data; /*把pltatform添加到系统中 */ if(of_device_add(dev) != 0) { platform_device_put(dev); returnNULL; } returndev; }
posted on 2017-02-23 12:46 Red_Point 阅读(2462) 评论(0) 编辑 收藏 举报