linux 驱动之设备树

简介

设备树的作用是代替device.c来描述硬件。paltform的匹配方式不变,而且使用设备树,对硬件的改动就不需要去改动device.c重新编译到内核中,而是可以直接通过bootloader传递给内核,所以设备树也是platform平台设备驱动的一部分,是platform平台设备驱动框架的一种优化编写形式。
 

设备树相关文件:

dts、dtsi、dtc、dtb

dts:设备树文件;

dtsi:通用设备树文件;(soc级)类似头文件被include。

dtc:设备树编译器

dtb:通过设备树编译器将,dts(dtsi)编译成dtb

dts的规范

属性的定义

value取值类型:属性名=值

值有三种取法:

第一种 ,比如<1 0x3 0x123> (术语叫arrays of cells,一个或多个32位数据)

第二种 ,“字符串” (用双引号括起来的字符串,比如“memory”)

第三种, 比如[ 00 11 22] (术语叫byte string, 16进制,表示的一个或者多个字节) 一个 byte string必须用2位16进制数表示 。字节之间的空格可以省略,可组合多种类型的值,之间用逗号分开。

示例:

a.Arrays of cells (cell就是一个32位的数据)

interrupts= < 170xc>;

b. 64bit数据使用2个cell来表示:

clock-frequency= < 0x00000001 0x00000000>;

c. 有结束符的字符串(A null-terminated string):

compatible= "simple-bus";

d. A bytestring(字节序列) :

local-mac-address= [ 000012345678]; 每个byte使用 2个 16进制数来表示

e. 可以是各种值的组合, 用逗号隔开:

compatible= "ns16550", "ns8250";
 

设备节点的定义

[ label:] node-name[@unit-address] {

[ properties definitions]

[ child nodes]

};

示例:

	sditomipi_cam0: sditomipi@3f {
					compatible = "mine,sditomipi";
					/* I2C device address */
					reg = <0x3f>;

					/* Physical dimensions of sensor */
					physical_w = "4.713";
					physical_h = "3.494";

					/* Sensor Model */
					sensor_model ="sditomipi";
					devnode ="video0";
					ports {
						#address-cells = <1>;
						#size-cells = <0>;

						port@0 {
							reg = <0>;
							sditomipi_out0: endpoint {
								port-index = <0>;
								bus-width = <2>;
								remote-endpoint = <&sditomipi_csi_in0>;
							};
						};
					};
			};
			sditomipi_cam1: sditomipi@2f {
				compatible = "mine,sditomipi";
				/* I2C device address */
				reg = <0x2f>;

				/* Physical dimensions of sensor */
				physical_w = "4.713";
				physical_h = "3.494";

				/* Sensor Model */
				sensor_model ="sditomipi";
				devnode ="video1";
				ports {
					#address-cells = <1>;
					#size-cells = <0>;

					port@0 {
						reg = <0>;
						sditomipi_out1: endpoint {
							port-index = <0>;
							bus-width = <2>;
							remote-endpoint = <&sditomipi_csi_in1>;
						};
					};
				};
			};

其中@3f和@2f中的3f、2f是内存首地址,用来区分其他同名设备。

设备节点中常见的属性

compatible:设备标识符。Linux 内核使用此关键字将设备驱动程序绑定到特定设备。(linux按照这个字符串来绑定驱动和设备)

reg:I2C从地址(协议格式中第一个字节(为slave address)由7位地址和一位R/W读写位组成的,这字节是个器件地址)

status:有两种值禁止或者启用设备(disable或者okay),默认不写这个属性为启用。

#address-cells:  在它的子节点的reg属性中, 使用多少个u32整数来描述地址(address)。

#size-cells:  在它的子节点的reg属性中, 使用多少个u32整数来描述大小(size)。

bus-width:数据总线位宽,默认值是<1>,也可以是<4>或者<8>。

  • 0
    点赞
  • 4
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值