Linux驱动(设备树)

提示:本文为系统的本地化文档,想要按照本文档完成系统的移植,需要你提前准备好Android的原生SDK。


前言

提示:感谢北京迅为电子

感谢【北京迅为电子】,本文是参考北京迅为电子的相关视频总结而成。


提示:以下是本篇文章正文内容

第一部分 设备树

一、设备树基础

术语描述
DTS源文件
DTSI源文件的包含文件
DTB二进制文件
DTC编译器
DTC编译
DTC反编译
DTS DTSI
DTB

二、设备树基本语法

1.根节点
/dts-v1/; // 设备树版本信息
/ {
	// 根节点开始
	/*
	在这里可以添加注释,描述根节点的属性和配置
	*/
};
2.子节点
//标签(可选)  名称  单元地址(区分相同类型的不同实例)
[label:] node-name@[unit-address] {
	[properties definitions]	//属性
	[child nodes]				//子节点
};
/
cpus
cpu@0
cpu@1
memoey@0
uart@fe001000
ethernet@fe00200
ethernet@fe00300
3.属性
节点描述例程
reg寄存器地址和大小单值:
my_device {
compatible = “vendor,device”;
// 0x1000(0x4)
reg = <0x1000 0x4>;
}
列表:
my_device {
compatible = “vendor,device”;
// 0x1000(0x8) 与 0x2000(0x4)
reg = <0x1000 0x8 0x2000 0x4>;
};
cells单元位数address-cells:地址单元位数
size-cells:大小单元位数
model设备型号(可选)
my_device {
//优先competible
compatible = “vendor,device”;
//compatible相同时通过model判断
model = “My Device XYZ”;
};
status节点状态okay disabled reserved fail
compatible设备兼容单字符串:“vendor,device”
字符串列表: [“vendor,device1”, “vendor,device2”]
通配符:“vendor,*”
4.节点
节点位置描述
aliases根部设备别名
aliases {
mmc0 = &sdmmc0;
mmc1 = &sdmmc1;
mmc2 = &sdhci;
serial0 = “/simple@fe000000/seria1@11c500”;
};
& 符号用于引用设备树中的节点
chosen根部传递和存储系统引导和配置的相关信息。
chosen {
bootargs = “root=/dev/nfs rw nfsroot=192.168.1.1 console=ttyS0,115200”;
};
bootargs:用于存储引导内核时传递的命令行参数。
stdout-path:用于指定用于标准输出的设备路径。
firmware-name:用于指定系统固件的名称。
linux,initrd-start 和 linux,initrd-end:这些属性用于指定 Linux 内核初始化 RAM 磁盘(initrd)的起始地址和结束地址。
其他自定义属性:chosen 节点还可以包含其他自定义属性,用于存储特定于系统引导和配置的信息。
device_type描述设备类型的节点
cpu:表示中央处理器。
memory:表示内存设备。
display:表示显示设备,如液晶显示屏。
serial:表示串行通信设备,如串口。
ethernet:表示以太网设备。
usb:表示通用串行总线设备。
i2c:表示使用
I2C (Inter-Integrated Circuit) 总线通信的设备。
spi:表示使用 SPI (Serial Peripheral Interface) 总线通信的设备。
gpio:表示通用输入/输出设备。
pwm:表示脉宽调制设备。

三、中断

1.说明
gpio0: gpio@fdd60000 {
	compatible = "rockchip,gpio-bank";
	reg = <0x0 0xfdd60000 0x0 0x100>;
	//中断控制器类型  中断号  中断触发类型
	interrupts = <GIC_SPI 33 IRQ_TYPE_LEVEL_HIGH>;
	clocks = <&pmucru PCLK_GPI00>, <&pmucru DBCLK_GPI00>;
	gpio-controller;
	#gpio-cells = <2>;
	gpio-ranges = <&pinctrl 0 0 32>;
	interrupt-controller;//中断控制器
	#interrupt-cells = <2>;
};

ft5x06: ft5x06@38 {
	status = "disabled";
	compatible = "edt,edt-ft5306";
	reg = <0x38>;
	touch-gpio = <&gpio0 RK_PB5 IRQ_TYPE_EDGE_RISING>;
	//所属中断控制器
	interrupt-parent = <&gpio0>;
	interrupts = <RK_PB5 IRQ_TYPE_LEVEL_LOW>;
	reset-gpios = <&gpio0 RK_PB6 GPIO_ACTIVE_LOW>;
	touchscreen-size-x = <800>;
	touchscreen-size-y = <1280>;
	touch_type = <1>;
};
2.例程
网络标号引脚
V1.2TP_INT_L_GPIO0_B5GPIO0_B5
V1.7TP_INT_L_GPIO3_A5GPIO3_A5

drivers/input/touchscreen/edt-ft5x06.c

#ifdef CONFIG_OF
static const struct of_device_id edt_ft5x06_of_match[] = {
	{ .compatible = "edt,edt-ft5206", .data = &edt_ft5x06_data },
	{ .compatible = "edt,edt-ft5306", .data = &edt_ft5x06_data },
	{ .compatible = "edt,edt-ft5406", .data = &edt_ft5x06_data },
	{ .compatible = "edt,edt-ft5506", .data = &edt_ft5506_data },
	/* Note focaltech vendor prefix for compatibility with ft6236.c */
	{ .compatible = "focaltech,ft6236", .data = &edt_ft6236_data },
	{ /* sentinel */ }
};
MODULE_DEVICE_TABLE(of, edt_ft5x06_of_match);
#endif

include/dt-bindings/pinctrl/rockchip.h

#ifndef __DT_BINDINGS_ROCKCHIP_PINCTRL_H__
#define __DT_BINDINGS_ROCKCHIP_PINCTRL_H__

#define RK_GPIO0	0
#define RK_GPIO1	1
#define RK_GPIO2	2
#define RK_GPIO3	3
#define RK_GPIO4	4
#define RK_GPIO6	6

#define RK_PA0		0
#define RK_PA1		1
#define RK_PA2		2
#define RK_PA3		3

//V1.2

/dts-v1/;//设备树文件的头部,指定了使用的设备树语法版本。
#include "dt-bindings/pinctrl/rockchip.h"//定义 Rockchip 平台的引脚控制器相关的绑定。
#include "dt-bindings/interrupt-controller/irq.h"//定义中断控制器相关的绑定。
/{	//根节点开始
model = "This is my devicetree!";	//模型名称
	ft5x06@38 {
		compatible = "edt,edt-ft5206";
		interrupt-parent = <&gpio0>;	//中断控制器所在节点
		interrupts = <RK_PB5 IRQ_TYPE_EDGE_RISING>;	//中断信号的配置
	};
};

//V1.7

/dts-v1/;
#include "dt-bindings/pinctrl/rockchip.h"
#include "dt-bindings/interrupt-controller/irq.h"
/{
model = "This is my devicetree!";
	ft5x06@38 {
		compatible = "edt,edt-ft5206";
		interrupt-parent = <&gpio3>;
		interrupts = <RK_PA5 IRQ_TYPE_EDGE_RISING>;
	};
};

四、时钟

1.时钟生产者
//单时钟
osc24m: osc24m {
	compatible = "clock";
	clock-frequency = <24000000>;//时钟频率
	clock-output-names = "osc24m";
	#clock-cells = <O>;//时钟编号位,0:但始终,1:多时钟
};
//多时钟
clock: clock {
	#clock-cells = <1>;
	clock-output-names = "clock1", "clock2";
};

scpi_dvfs: clocks-0 {
	#clock-cells = <1>;
	clock-indices = <0>, <1>, <2>;
	clock-output-names = "atlclk", "aplclk", "gpuclk";
};
scpi_clk: clocks-1 {
	#clock-cells = <1>;
	clock-indices = <3>;
	clock-output-names = "pxlclk";
};

clock: clock {
	assigned-clocks = <&clkcon 0>, <&pll 2>;//时钟源编号:clkcon 0 和 pll 2
	assigned-clock-parents = <&pll 2>;//父时钟:pll 2
	assigned-clock-rates = <115200>, <9600>;//时钟源频率:115200,9600
};
2.时钟消费者
clock: clock {
	clocks = <&cru CLK_VOP>;//时钟源,引用了 cru 节点中的 CLK_VOP 时钟源
	clock-names = "clk_vop";//时钟源名称,可选
};

五、CPU

六、GPIO

gpio0: gpio@fdd60000 {
	compatible = "rockchip,gpio-bank";
	reg = <0x0 0xfdd60000 0x0 0x100>;
	interrupts = <GIC_SPI 33 IRQ_TYPE_LEVEL_HIGH>;
	clocks = <&pmucru PCLK_GPI00>, <&pmucru DBCLK_GPI00>;
	gpio-controller;
	#gpio-cells = <2>;
	gpio-ranges = <&pinctrl 0 0 32>;
	interrupt-controller;
	#interrupt-cells = <2>;
};
ft5x06: ft5x06@38 {
	status = "disabled";
	compatible = "edt,edt-ft5306";
	reg = <0x38>;
	touch-gpio = <&gpio0 RK_PB5 IRQ_TYPE_EDGE_RISING>;
	interrupt-parent = <&gpio0>;
	interrupts = <RK_PB5 IRQ_TYPE_LEVEL_LOW>;
	reset-gpios = <&gpio0 RK_PB6 GPIO_ACTIVE_LOW>;
	touchscreen-size-x = <800>;
	touchscreen-size-y = <1280>;
	touch_type = <1>;
};

七、pinctrl

第二部分 设备树插件

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值