Chinaunix首页 | 论坛 | 博客
  • 博客访问: 1685637
  • 博文数量: 511
  • 博客积分: 967
  • 博客等级: 准尉
  • 技术积分: 2560
  • 用 户 组: 普通用户
  • 注册时间: 2012-07-06 14:19
文章分类

全部博文(511)

文章存档

2016年(11)

2015年(61)

2014年(257)

2013年(63)

2012年(119)

分类: Android平台

2014-12-05 15:47:18

devicetree中数据和structdevice有什么关系

总体来说,devicetreestructdevice的关系应该还是在其生成platformdevice的时候,一直传递的structdevice *parent参数。下面先把其源码中传递过程描述如下(仍以At91rm9200为例):

.init_machine =at91_dt_device_init,

staticvoid __init at91_dt_device_init(void)

*of_platform_populate() - Populate platform_devices from device treedata

*@parent: parent to hook devicesfrom, NULL for toplevel

*Similar to of_platform_bus_probe(), this function walks the devicetree

*and creates devices from nodes. It differs in that it follows themodern

*convention of requiring all device nodes to have a 'compatible'property,

*and it is suitable for creating devices which are children of theroot

//devicetree数据中populateplatform devices

intof_platform_populate(structdevice_node *root,

conststruct of_device_id *matches,

conststruct of_dev_auxdata *lookup,

structdevice *parent)

structdevice_node *child;

//生成platformdevice

*of_platform_bus_create() - Create a device for a node and itschildren.

*@bus: device node of the bus to instantiate

*@lookup: auxdata table for matching id and platform_data with devicenodes

*@parent: parent for new device, or NULL for top level.

*Creates a platform_device for the provided device_node, andoptionally

*recursively create devices for all the child nodes.

staticint of_platform_bus_create(structdevice_node *bus,

const struct of_device_id *matches,

const struct of_dev_auxdata *lookup,

struct device *parent, boolstrict)

conststruct of_dev_auxdata *auxdata;

structdevice_node *child;

structplatform_device *dev;

auxdata= of_dev_lookup(lookup, bus);

if(of_device_is_compatible(bus, "arm,primecell")) {

of_amba_device_create(bus,bus_id, platform_data, parent);

dev= of_platform_device_create_pdata(bus,bus_id, platform_data, parent);

if(!dev || !of_match_node(matches, bus))

rc= of_platform_bus_create(child, matches, lookup, &dev->dev,strict);

staticstruct amba_device *of_amba_device_create(structdevice_node *node,

struct device *parent)

structamba_device *dev;

pr_debug("Creatingamba device %s\n", node->full_name);

if(!of_device_is_available(node))

dev= amba_device_alloc(NULL, 0, 0);

if(!dev)

/*setup generic device info */

dev->dev.coherent_dma_mask= ~0;

dev->dev.of_node= of_node_get(node);

dev->dev.parent= parent;

dev->dev.platform_data= platform_data;

*of_platform_device_create_pdata - Alloc, initialize and register anof_device

*@np: pointer to node to create device for

*@bus_id: name to assign device

*@parent: Linux device model parentdevice.

*Returns pointer to created platform device, or NULL if a device wasnot

*registered. Unavailable devices will not get registered.

//分配内存,初始化和注册一个of_device

structplatform_device *of_platform_device_create_pdata(

structdevice_node *np,

structdevice *parent)

structplatform_device *dev;

if(!of_device_is_available(np))

dev= of_device_alloc(np,bus_id, parent);

returndev;

*of_device_alloc - Allocate and initialize an of_device

*@np: device node to assign to device

*@bus_id: Name to assign to the device. May be null to use defaultname.

*@parent: Parent device.

//分配内存和初始化of_device

structplatform_device *of_device_alloc(structdevice_node *np,

struct device *parent)

structplatform_device *dev;

dev= platform_device_alloc("", -1);

if(!dev)

platform_device_put(dev);

dev->num_resources= num_reg + num_irq;

dev->resource= res;

dev->dev.of_node= of_node_get(np);

dev->dev.dma_mask= &dev->archdata.dma_mask;

dev->dev.parent= parent;

dev_set_name(&dev->dev,"%s", bus_id);

of_device_make_bus_id(&dev->dev);

returndev;

总的分析:parent参数开始初始化为NULL,其中一直没有赋值,直到最后赋值给platformdevicedev.parent属性。其中关系耐人寻味。

阅读(1241) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~