第七章 驱动程序开发-LED驱动-7.9.设备树再学习

    原本以为LED驱动已经结束了,下面是按键驱动,看了才发现还没结束,还有pinctrl+gpio子系统的内容,尴尬!

7.9.设备树再学习

    看《devicetree-specification-v0.2》

    DTSpec specifies a construct called a devicetree to describe system hardware. Each node has exactly one parent except for the root node, which has no parent.

7.9.1.Node-name

    节点名字:node-name@unit-address,node-name长度在1~31位之间,可以用特殊符号、数字、大小写字母表示,通常是以小写或者大写字母开头,能够清楚表达节点所属的设备类型。比如上图看到了cpus、memory、uart等,最好通用并且能表示出节点的功能。另外,节点名字中也可以包含一些非标准的字符,例如公司名字、组织名字,例如fsl飞思卡尔,ibm,linux。

    unit-address表示bus type,总线类型,使用ASCII字节命名类似node-name,必须和reg中定义的起始地址匹配,如果没有定义reg,可以不写。

    根节点没有名字和地址,直接就是一个/;

7.9.2.Node-properties 

    Standard Properties

1.compatible<stringlist>,字符串列表,用于设备驱动选择,还是看原话:

    They allow a device to express its compatibility(兼容性) with a family of similar devices, potentially allowing a single device driver to match against several devices.

常用的格式是compatible = "manufacturer,model",例如:compatible = "fsl,mpc8641", "ns16550";

2.model <string>,字符串,和compatible类似,不过只能是单个字符串,举例:model = "fsl,MPC8349EMITX";

3.phandle<u32>,ID,大多数情况下在编译dts文件时会自动分配;

4.status <string> ,有4种状态,"okay""disabled""fail""fail-sss",如果有节点不使用可以disiabled;

5.#address-cells, #size-cells,<u32>,address-cells用来定义子节点的32位的地址范围,size-cells用来定义子节点的几个32位的地址范围,

6.Reg,<prop-encoded-array>,一般包含起始地址和长度;a 32-byte block at offset 0x3000 in the SOC and a 256-byte block at offset 0xFE00.可以表示为reg = <0x3000 0x20 0xFE00 0x100>;

7. virtual-reg, <u32>,

8.Ranges,<empty> or <prop-encoded-array>, (child-bus-address, parentbus-address, length)

soc {
    compatible = "simple-bus";
    #address-cells = <1>;
    #size-cells = <1>;
    ranges = <0x0 0xe0000000 0x00100000>;

    serial {
        device_type = "serial";
        compatible = "ns16550";
        reg = <0x4600 0x100>;
        clock-frequency = <0>;
        interrupts = <0xA 0x8>;
        interrupt-parent = <&ipic>;
    };
};

    This property value specifies that for an 1024KB range of address space, a child node addressed at physical 0x0 maps to a parent address of physical 0xe0000000. With this mapping, the serial device node can be addressed by a load or store at address 0xe0004600, an offset of 0x4600 (specified in reg) plus the 0xe0000000 mapping specified in ranges.

    也就时说一个节点要具备以上几个特性,demo:

parent-node{
    compatible = "fsl,mpc8641";
    model = “fsl,MPC8349EMITX”;
    phandle = <1>;
    status = "okay";
    #address-cells = <1>;
    #size-cells = <1>;
    ranges = <0x0 0xe0000000 0x00100000>;

    serial {
        device_type = "serial";
        compatible = "ns16550";
        reg = <0x4600 0x100>;
        clock-frequency = <0>;
        interrupts = <0xA 0x8>;
        interrupt-parent = <&ipic>;
    };
};

7.9.3.Interrupts and Interrupt Mapping
    暂时不看,还没有用到中断。

7.9.4.Device Node Requirements
    暂且跳过。
7.9.5.Device Bindings
    讲了常用的几种设备总线在创建节点时需要的Standard Properties,像led应该时简单的设备,可以只用compatible和ranges 2个Properties就行。
    小结:创建一个节点参考其他节点或者该文档,主要是定义各个Properties,以及child节点。
    静下来看,其实发现不难的,老外写的文档,简单明了,没有废话,还是可以读得懂的。

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值