linux学习-设备树

设备树

一,格式

label:node-name@unit-address

二,标准属性

1.compatible属性

格式:“manufacturer,model”厂商,驱动名字

根节点的compatible属性是为了匹配linux内核是否支持此设备

2.model属性

model也是一个字符串,描述设备模块信息

exp:model=“wm8960-audio”

3.status属性

也是字符串,表示设备的状态

描述
okay可操作设备
disabled不可操作,但可变可操作
fail不可操作
fail-sss与上面相同,sss为检测到错误内容

4.#address-cells和#size-cells属性

#address-cells表示该节点的地址

#size-cells表示该节点所占的地址长度

//此为.dts文件
//example 1
/ {
    #address-cells = <0x1>; 
    //在 root node下使用1个u32来代表address。
    #size-cells = <0x0>; 
    // 在root node下使用0个u32来代表size。
    ...
    ...
    memory {        
        // memory device
        ...
        reg = <0x90000000>;
        // 0x90000000是存取memory的address
        ...
    };
    ...
    ...
}

/ {
    #address-cells = <0x1>; 
    //在root node下使用1个u32来代表address。
    #size-cells = <0x1>;
    //在root node下使用1个u32来代表size。
    ...
    ...
    memory { 
        // memory device
        ...
        reg = <0x90000000 0x800000>;
        // 0x90000000 是存取 memory 的 address
        // 0x800000 是 memory 的 size。
        ...
    };
    ...
    ...
}

/ {
    #address-cells = <0x2>; 
    // 在root node下使用2个u32来代表address。
    #size-cells = <0x1>; 
    // 在root node下使用1个u32来代表size。
    ...
    ...
    memory { 
        // memory device
        ...
        reg = <0x90000000 00000000 0x800000>;
    // 0x90000000 00000000 是存取memory的address
    // 0x800000 是memory的size。
        ...
    };
    ...
    ...
}

/ {
    #address-cells = <0x2>; 
    // 在root node下使用2个u32来代表address。
    #size-cells = <0x2>; 
    // 在root node下使用2个u32来代表size。
    ...
    ...
    memory { 
        // memory device
        ...
        reg = <0x90000000 00000000 0x800000 00000000>;
   // 0x90000000 00000000 是存取memory的address
   // 0x800000 00000000 是memory的size。
        ...
    };
    ...
    ...
}

**reg格式:reg=

注意:reg格式与csdn例子有些不一样还需深究!!!

5.reg属性

主要描述节点的设备地址空间资源信息!

6.ranges属性

格式:ranges=<child-bus-add,parent-bus-add,length>

三.特殊节点

1.aliases子节点

aliases:别名

通常使用label:&label来方便访问节点

2.chosen子节点

功能:传递

四.驱动获取设备树操作函数

**这些函数都有个统一的前缀of_,所以统称为OF函数

1.查找节点的OF函数

of_find_node_by_name函数

原型:struct device_node *of_find_node_by_name( struct device_node *from const char *name)

from:起始节点;name:寻找节点;

从from节点开始递归查找相应的name,如果from为NULL,则从根节点开始

of_find_node_by_type函数

原型:struct device_node *of_find_node_by_type( struct device_node *from const char *type)

from:起始节点;type:寻找type字符串;

of_find_node_by_compatible函数

原型:struct device_node *of_find_node_by_compatible( struct device_node *from const char *type const char *compatible)

from:起始节点;type:寻找type字符串;; compatible:对于的compatible属性列表

of_find_node_by_path

原型:inline struct device_node *of_find_node_by_path(const char *path)

2.查找父/子节点的OF函数

struct device_node *of_get_parent(const struct device_node *node)
struct device_node *of_get_next_child(
​ const struct device_node *node,
​ struct device_node *prev)

3.提取属性值的OF函数

property *of_find_property(const struct device_node *np,
const char *name,int *lenp)
np:设备节点;name:属性名字;lenp:属性值的字节数
return: 找到的属性

int of_property_count_elems_of_size(const struct device_node *np,const char *propname,int elem_size)
**exp:获取属性中元素数量,比如reg属性值是个数组,即该函数返回数组的大小。
**
np:设备节点;proname:需要统计属性名字;elem_size:元素长度

int of_property_read_u32_index(const struct device_node *np
,const char *proname, u32 index,u32 *out_value)
index:读取值的标号;out_value:读取到的值

**同样地,也有相似的函数:
1.of_property_read_u8_array(const struct device_node *np,const char *proname,u8 *out_values,size_t sz)
2.of_property_read_u16_array(…)
3.of_property_read_u32_array(…)
4.of_property_read_u64_array(…)
5.of_property_read_string(struct device_node *np,
const char *proname,const char ****out_string)
6.of_n_addr_cells(struct device_node *np)
7.of_n_size_cells(struct device_node *np)

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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值