DTS-函数汇总

1. property函数

1.1 of_find_property

作用: 在指定device_node查找是否有指定name的property,如果存在这property,则返回property。

input:
np: 查找节点
name: 查找property的name
output:
return: 返回这个property的指针
lenp: 这个property的name的value的长度。

 238 struct property *of_find_property(const struct device_node *np,                 
 239                                   const char *name,                             
 240                                   int *lenp)                                    
 241 {                                                                               
 242         struct property *pp;                                                    
 243         unsigned long flags;                                                    
 244                                                                                 
 245         raw_spin_lock_irqsave(&devtree_lock, flags);                            
 246         pp = __of_find_property(np, name, lenp);                                
 247         raw_spin_unlock_irqrestore(&devtree_lock, flags);                       
 248                                                                                 
 249         return pp;                                                                                                                                                                                  
 250 }  

1.2 of_get_property

作用: 在指定device_node查找是否有指定name的property,如果存在这property,则返回这个property中的name的value。

input:
np: 查找节点
name: 查找property的name
output:
return: 返回这个name的value
lenp: 这个property的name的value的长度。

 308 const void *of_get_property(const struct device_node *np, const char *name,     
 309                             int *lenp)                                          
 310 {                                                                               
 311         struct property *pp = of_find_property(np, name, lenp);                                                                                                                                                                                                                      
 312         return pp ? pp->value : NULL;                                           
 313 } 

比如

160         gic: interrupt-controller@1e001000 {                                                                                                                                                             
161                 compatible = "arm,cortex-a9-gic";                               
162                 #interrupt-cells = <3>;                                         
163                 #address-cells = <0>;                                           
164                 interrupt-controller;                                           
165                 reg = <0x1e001000 0x1000>,                                      
166                       <0x1e000100 0x100>;                                       
167         }; 

假设np1节点是gic节点对象:

struct property *pp=  of_find_property(np1, "compatible", &len);
pp->name=compatible pp->value="arm,cortex-a9-gic"property->length=16

const __be32 *list;
list = of_get_property(np, list_name, &size); 
be32_to_cpup(list)='a'
be32_to_cpup(list+1)='r'
be32_to_cpup(list)='m'
be32_to_cpup(list+1)=','

2.1 通过phandle list找到指定node

1615 /**                                                                                                      
1616  * of_parse_phandle_with_args() - Find a node pointed by phandle in a list      
1617  * @np:         pointer to a device tree node containing a list                 
1618  * @list_name:  property name that contains a list                              
1619  * @cells_name: property name that specifies phandles' arguments count          
1620  * @index:      index of a phandle to parse out                                 
1621  * @out_args:   optional pointer to output arguments structure (will be filled) 
1622  *                                                                              
1623  * This function is useful to parse lists of phandles and their arguments.      
1624  * Returns 0 on success and fills out_args, on error returns appropriate        
1625  * errno value.                                                                 
1626  *                                                                              
1627  * Caller is responsible to call of_node_put() on the returned out_args->np     
1628  * pointer.                                                                     
1629  *                                                                              
1630  * Example:                                                                     
1631  *                                                                              
1632  * phandle1: node1 {                                                            
1633  *      #list-cells = <2>;                                                      
1634  * }                                                                            
1635  *                                                                              
1636  * phandle2: node2 {                                                            
1637  *      #list-cells = <1>;                                                      
1638  * }                                                                            
1639  *                                                                              
1640  * node3 {                                                                      
1641  *      list = <&phandle1 1 2 &phandle2 3>;                                     
1642  * }                                                                            
1643  *                                                                              
1644  * To get a device_node of the `node2' node you may call this:                  
1645  * of_parse_phandle_with_args(node3, "list", "#list-cells", 1, &args);          
1646  */                                                                             
1647 int of_parse_phandle_with_args(const struct device_node *np, const char *list_name,
1648                                 const char *cells_name, int index,              
1649                                 struct of_phandle_args *out_args)               
1650 {                                                                               
1651         if (index < 0)                                                          
1652                 return -EINVAL;                                                 
1653         return __of_parse_phandle_with_args(np, list_name, cells_name, 0,                                                                                 
1654                                             index, out_args);                   
1655 } 

np: 包含链表的节点,在这个例子中是node3
list_name: 链表的名字,在这个例子中是list
cells_name: 节点中指定phandle的个数的property,cell_name="#list-cells"
index:就是第几个phandle要parse,现在list = <&phandle1 1 2 &phandle2 3>; 通过phandle1的#list-cells=2,通过phandle2的#list-cells=1,这样list可以分为两个,index=0----&phandle1 1 2 ,index=1-- &phandle2 3

这样通过of_parse_phandle_with_args(node3, “list”, “#list-cells”, 1, &args)寻找到node节点,把结果放入out_args->np=node2

  • 1
    点赞
  • 13
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值