Video Tutorial
Lesson 3 — Linux Device Trees (Chinese)
Introduction
Learning Approach
The Taishan Pi Linux device tree contains roughly 9,000 lines. Start with syntax and existing examples. Kernel drivers use this configuration, so understanding the entire system also requires studying those drivers.
Linux and SoC hardware are more complex than STM32 or 8051 projects. Start with device-tree changes, simple drivers, and applications, then investigate details as your projects raise questions.
Why Learn This?
Vendor SDKs include many common drivers. Adapting a board often involves editing device-tree configuration, making it a practical starting point.
When Is It Needed?
The author learned bare-metal programming, system porting, and drivers first. With an existing SDK, you can start with device-tree changes for GPIO, MIPI, eDP, HDMI, LEDs, infrared controls, and Wi-Fi. Learn the underlying drivers as you need them.
Device Tree Basics
A device tree describes hardware as nodes and properties. It starts at a root node. Child nodes describe devices or resources; their properties specify addresses, interrupts, and other settings. Each node has a path such as /cpu@0 and can contain further nodes.
Terminology
Device tree: A portable data structure describing hardware and resource connections.
DTS (Device Tree Source): Human-readable source, comparable to a C
.cfile.DTSI (Device Tree Include): Reusable definitions included in source files, comparable to a C header.
DTC (Device Tree Compiler): Compiles DTS into DTB.
DTB (Device Tree Blob): The compiled binary.
Node: A device or resource with a unique path and properties.
Property: A named setting, such as an address or interrupt.
Property value: Data such as an integer, string, or Boolean.
Parent and child nodes: A hierarchy describing hardware relationships.
Learning Goals
- Understand basic device-tree structure and syntax.
- Read the main Taishan Pi device-tree files.
- Modify the display-related properties used in later lessons.
- Follow Rockchip's device-tree documentation to configure specific functions.
Device Tree File Structure
Write source in .dts and .dtsi files. DTC compiles them into a .dtb binary that the kernel loads at startup. Their relationship is shown below.
Rockchip's device trees for 64-bit SoCs and boards, including Taishan Pi, are in this directory:
泰山派SDK/kernel/arch/arm64/boot/dts/rockchip$A shortened directory listing:
泰山派SDK/kernel/arch/arm64/boot/dts/rockchip$ ls -a
Makefile
rk3326-863-lp3-v10.dts rk3566-box-demo-v10-android9.dts
rk3326-863-lp3-v10.dtsi rk3566-box-demo-v10.dts
rk3326-863-lp3-v10-rkisp1.dts rk3566-box-demo-v10.dtsi
rk3326-86v-v10.dts rk3566-box.dtsi
rk3326.dtsi rk3566.dtsi
rk3326-evb-ai-va-v10.dts rk3566-eink.dtsi
rk3326-evb-ai-va-v11.dts rk3566-evb1-ddr4-v10.dts
rk3326-evb-ai-va-v11-i2s-dmic.dts rk3566-evb1-ddr4-v10.dtsi
rk3326-evb-ai-va-v12.dts rk3566-evb1-ddr4-v10-linux.dts
rk3326-evb-ext-sii902x-rgb-to-hdmi-v10.dtsi rk3566-evb1-ddr4-v10-lvds.dts
rk3326-evb-lp3-v10-avb.dts rk3566-evb2-lp4x-v10.dts
rk3326-evb-lp3-v10.dts rk3566-evb2-lp4x-v10.dtsi
rk3326-evb-lp3-v10.dtsi rk3566-evb2-lp4x-v10-edp.dts
rk3326-evb-lp3-v10-linux.dts rk3566-evb2-lp4x-v10-eink.dts
rk3326-evb-lp3-v10-robot-linux.dts rk3566-evb2-lp4x-v10-i2s-mic-array.dts
rk3326-evb-lp3-v10-robot-no-gpu-linux.dts rk3566-evb2-lp4x-v10-linux.dts
rk3326-evb-lp3-v11-avb.dts rk3566-evb2-lp4x-v10-pdm-mic-array.dts
rk3326-evb-lp3-v11.dts rk3566-evb3-ddr3-v10.dts
rk3326-evb-lp3-v12-linux.dts rk3566-evb3-ddr3-v10.dtsi
rk3326-linux.dtsi rk3566-evb3-ddr3-v10-linux.dts
rk3328-android.dtsi rk3566-evb5-lp4x-v10.dts
rk3328-box-liantong-avb.dts rk3566-evb5-lp4x-v10.dtsi
rk3328-box-liantong.dts rk3566-evb.dtsi
rk3328-box-liantong.dtsi rk3566-evb-mipitest-v10.dts
rk3328-box-plus-dram-timing.dtsi rk3566-evb-mipitest-v10.dtsi
rk3328-dram-2layer-timing.dtsi rk3566-rk817-eink.dts
rk3328-dram-default-timing.dtsi rk3566-rk817-eink-w103.dts
rk3328.dtsi rk3566-rk817-eink-w6.dts
rk3328-evb-android-avb.dts rk3566-rk817-tablet.dts
rk3328-evb-android.dts rk3566-rk817-tablet-k108.dts
rk3328-evb-android.dtsi rk3566-rk817-tablet-rkg11.dts
rk3328-evb.dts rk3566-rk817-tablet-v10.dts
rk3328-roc-cc.dts rk3568-amp.dtsi
rk3328-rock64-android-avb.dts rk3568-android9.dtsi
rk3328-rock64-android.dts rk3568-android.dtsi
rk3328-rock64-android.dtsi rk3568-dram-default-timing.dtsi
rk3328-rock64.dts rk3568.dtsi
rk3358.dtsi rk3568-evb1-ddr4-v10-android9.dts
rk3358-evb-ddr3.dtsi rk3568-evb1-ddr4-v10.dts
rk3358-evb-ddr3-v10-linux.dts rk3568-evb1-ddr4-v10.dtsi
rk3358-linux.dtsi rk3568-evb1-ddr4-v10.dtsi3
rk3358m-vehicle-ddr3.dtsi rk3568-evb1-ddr4-v10-linux.dts
rk3358m-vehicle-v10.dts rk3568-evb1-ddr4-v10-linux-spi-nor.dts
rk3368-808.dtsi rk3568-evb2-lp4x-v10-bt1120-to-hdmi.dts
rk3368-808-evb.dts rk3568-evb2-lp4x-v10.dts
rk3368a-817-tablet-bnd.dts rk3568-evb2-lp4x-v10.dtsi
rk3368a-817-tablet.dts rk3568-evb4-lp3-v10.dts
rk3368-android.dtsi rk3568-evb5-ddr4-v10.dts
rk3368-cif-sensor.dtsi rk3568-evb5-ddr4-v10.dtsi
rk3368-dram-default-timing.dtsi rk3568-evb6-ddr3-v10.dts
rk3368.dtsi rk3568-evb6-ddr3-v10.dtsi
rk3368-evb-act8846.dts rk3568-evb6-ddr3-v10-linux.dts
rk3368-evb.dtsi rk3568-evb6-ddr3-v10-rk628-bt1120-to-hdmi.dts
rk3368-geekbox.dts rk3568-evb6-ddr3-v10-rk628-rgb2hdmi.dts
rk3368-lion.dtsi rk3568-evb6-ddr3-v10-rk630-bt656-to-cvbs.dts
rk3368-lion-haikou.dts rk3568-evb7-ddr4-v10.dts
rk3368-orion-r68-meta.dts rk3568-evb.dtsi
rk3368-p9-avb.dts rk3568-iotest-ddr3-v10.dts
rk3368-p9.dts rk3568-iotest-ddr3-v10-linux.dts
rk3368-p9.dtsi rk3568-linux.dtsi
rk3368-px5-evb-android.dts rk3568-nvr-demo-v10.dts
rk3368-px5-evb.dts rk3568-nvr-demo-v10.dtsi
rk3368-r88-dcdc.dts rk3568-nvr-demo-v10-linux.dts
rk3368-r88.dts rk3568-nvr-demo-v10-linux-spi-nand.dts
rk3368-sheep.dts rk3568-nvr-demo-v12.dtsi
rk3368-sheep-lvds.dts rk3568-nvr-demo-v12-linux.dts
rk3368-sziauto-rk618.dts rk3568-nvr-demo-v12-linux-spi-nand.dts
rk3368-tablet.dts rk3568-nvr.dtsi
rk3368-xikp-avb.dts rk3568-nvr-linux.dtsi
rk3368-xikp.dts rk3568-pinctrl.dtsi
rk3368-xikp.dtsi rk630.dtsi
rk3399-android.dtsi rk630-rk3568-ddr3-v10.dts
rk3399-box.dtsi rockchip-pinconf.dtsi
rk3399-box-rev1.dts tspi-rk3566-core-v10.dtsi
rk3399-box-rev2.dts tspi-rk3566-csi-v10.dtsi
rk3399-dram-default-timing.dtsi tspi-rk3566-dsi-v10.dtsi
rk3399.dtsi tspi-rk3566-edp-v10.dtsi
rk3399-early-opp.dtsi tspi-rk3566-gmac1-v10.dtsi
rk3399-evb-cros.dtsi tspi-rk3566-hdmi-v10.dtsi
rk3399-evb.dts tspi-rk3566-user-v10-linux.dtb
rk3399-evb.dtsi .tspi-rk3566-user-v10-linux.dtb.cmd
rk3399-evb-ind.dtsi .tspi-rk3566-user-v10-linux.dtb.d.dtc.tmp
rk3399-evb-ind-lpddr4-android-avb.dts .tspi-rk3566-user-v10-linux.dtb.d.pre.tmp
rk3399-evb-ind-lpddr4-android.dts .tspi-rk3566-user-v10-linux.dtb.dts.tmp
rk3399-evb-ind-lpddr4-linux.dts .tspi-rk3566-user-v10-linux.dtb.dts.tmp.domain
rk3399-evb-ind-lpddr4-v13-android-avb.dts tspi-rk3566-user-v10-linux.dts
rk3399-evb-rev1-android.dts2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
These files cover many Rockchip boards. Focus on four file types: DTS, DTSI, DTB, and Makefile.
DTS (
.dts): Source describing device names, types, addresses, and interrupts.DTSI (
.dtsi): Common definitions reused by multiple device trees.DTB (
.dtb): Compiled binary loaded by the operating system.Makefile: Automates device-tree compilation.
As with C source and headers, practical edits mainly concern .dts and .dtsi.
Taishan Pi device-tree files:
tspi-rk3566-core-v10.dtsi tspi-rk3566-dsi-v10.dtsi tspi-rk3566-gmac1-v10.dtsi tspi-rk3566-user-v10-linux.dtb
tspi-rk3566-csi-v10.dtsi tspi-rk3566-edp-v10.dtsi tspi-rk3566-hdmi-v10.dtsi tspi-rk3566-user-v10-linux.dts
rk3568-dram-default-timing.dtsi rk3566.dtsi rk3568.dtsi2
3
rk3568.dtsi — SoC configuration rk3566.dtsi — includes rk3568.dtsi tspi-rk3566-core-v10.dtsi — core board configuration, rarely changed in later exercises tspi-rk3566-edp-v10.dtsi — eDP display tspi-rk3566-dsi-v10.dtsi — MIPI display tspi-rk3566-hdmi-v10.dtsi — HDMI tspi-rk3566-csi-v10.dtsi — MIPI camera tspi-rk3566-gmac1-v10.dtsi — Ethernet tspi-rk3566-user-v10.dts — user configuration including the files above
Include Relationships
Starting with tspi-rk3566-user-v10.dts, trace its includes to see how the files relate. Includes are explained below.
tspi-rk3566-user-v10.dts
rk3566.dtsi
rk3568.dtsi
rk3568-dram-default-timing.dtsi
rk3568-android.dtsi
tspi-rk3566-core-v10.dtsi
tspi-rk3566-edp-v10.dtsi
tspi-rk3566-dsi-v10.dtsi
tspi-rk3566-hdmi-v10.dtsi
tspi-rk3566-csi-v10.dtsi
tspi-rk3566-gmac1-v10.dtsi2
3
4
5
6
7
8
9
10
11
DTC Compiler
A full SDK build generates tspi-rk3566-user-v10-linux.dtb in SDK/kernel/arch/arm64/boot/dts/rockchip. DTC source and its executable are in SDK/kernel/scripts/dtc. Record that absolute path with pwd for the examples below.
You can also install DTC to practice without downloading the SDK.
- Update the package list:
sudo apt update- Install
device-tree-compilerwith apt:
sudo apt install device-tree-compiler- Check the installed DTC version:
dtc --versionCompile DTS to DTB
Compile device-tree source (.dts) into a device-tree blob (.dtb):
dtc -I dts -O dtb -o output_file.dtb input_file.dts-I dtsspecifies the input file format as Device Tree Source.-O dtbspecifies the output file format as Device Tree Blob.-o output_file.dtbsets the name of the output file.input_file.dtsis the .dts file you want to compile.
Decompile DTB
Decompile a device-tree blob into source:
dtc -I dtb -O dts -o output_file.dts input_file.dtb-I dtbspecifies the input file format as Device Tree Blob.-O dtsspecifies the output file format as Device Tree Source.-o output_file.dtssets the name of the output file.input_file.dtbis the blob to decompile.
Try It
Compile Test
Create input_file.dts with this content.
/dts-v1/;
/ {
};2
3
4
Compile it, replacing the DTC executable path with your own.
dtc -I dts -O dtb -o output_file.dtb input_file.dtsSuccessful compilation:
Decompile
Decompile the binary. Include the full path when using the SDK's DTC. A separately installed DTC can be called directly.
dtc -I dtb -O dts -o backoutput_file.dts output_file.dtbSuccessful decompilation:
Use ls to check for backoutput_file.dts.
Use cat to compare the decompiled content with the original.
Device Tree Syntax
Think of the node hierarchy as a tree with information tags on its branches.
- Nodes
- A node represents a hardware unit, from a CPU to an I/O port.
- The root represents the whole system. Branches represent devices and subsystems at different levels.
- Properties
- Properties attach information to nodes.
- Like tags on branches, properties carry configuration details.
- Each node can have a different property set.
Version
Place /dts-v1/; near the beginning of a DTS file to declare its syntax version.
/dts-v1/; // 指定这是一个设备树文件的版本(v1)Comments
As in C, comments use these two forms:
/* 这是一个注释 */
// 这是一个注释2
Include Files
DTS source can include reusable definitions in two ways.
DTS Includes
Use device-tree syntax to include a file:
/include/ "xxxx.dtsi" //xxxx是你要包含的文件名称Try It
Create device_tree.dtsi with this content:
/dts-v1/;
/{
};2
3
4
Create device_tree.dts with this content:
/dts-v1/;
/include/ "device_tree.dtsi" //这里去包含上面的头文件2
Build
dtc -I dts -O dtb -o device_tree.dtb device_tree.dtsDecompile the result:
dtc -I dtb -O dts -o backdevice_tree.dts device_tree.dtbInspect the decompiled source to confirm that the DTSI content was included.
cat backdevice_tree.dtsResult
C Includes
C preprocessor includes can include both .dtsi and .h files.
#include "xxxx.dtsi" //xxxx是你要包含的dtsi文件名称
或者
#include "xxxx.h" //xxxx是你要包含的.h文件名称2
3
#include is C preprocessor syntax. Run cpp to expand it into temporary source, then compile that with DTC. Rockchip's build follows this process.
Preprocess the Source
Use cpp to expand includes from xxxx.dts into xxxx.dtb.dts.tmp.
cpp -nostdinc -I[dir_with_dts_includes] -x assembler-with-cpp [src_dts_file] > [tmp_dts_file]-nostdinc: Do not use a standard system header directory to avoid unnecessary error reporting.-I[dir_with_dts_includes]: This is the directory of headers. Use-I.if this is the current directory.[src_dts_file]is your source device tree file (.dts).[tmp_dts_file]is the preprocessed output. This tutorial uses the Rockchip naming stylexxxxxxxxxxxx.dtb.dts.tmp.
Try It
Create device_tree.h with this content:
#define LCKFB "www.lckfb.com"Create device_tree.dtsi with this content:
#include "device_tree.h" //这里去包含上面的头文件
/{
model = LCKFB;
};2
3
4
Create device_tree.dts with this content:
/dts-v1/;
#include "device_tree.dtsi" //这里去包含上面的头文件2
Preprocess:
cpp -nostdinc -I. -x assembler-with-cpp device_tree.dts > device_tree.dtb.dts.tmpInspect the preprocessing result. Includes are expanded and model = LCKFB; becomes model = "www.lckfb.com";.
cat device_tree.dtb.dts.tmpBuild
dtc -I dts -O dtb -o device_tree.dtb device_tree.dtb.dts.tmpDecompile the result:
dtc -I dtb -O dts -o backdevice_tree.dts device_tree.dtbInspect the decompiled source to confirm the included definitions.
cat backdevice_tree.dtsDevice Tree Node
Root Node
The root node is the top of the hierarchy. Its name is /.
/dts-v1/; // 指定这是一个设备树文件的版本(v1)
/ {// 根节点定义开始
/* 这里是根节点,它代表整个设备树的基础。
在这里可以定义一些全局属性或者包含更多的子节点。 */
}; // 根节点定义结束2
3
4
5
6
Child Node
A child node has these elements:
- Node name and optional unit address: Identify the hardware function and distinguish instances, such as devices at different addresses.
- Braces
{}: Enclose the node's properties and children. - Properties: Name/value pairs separated by
=. Values can be strings, numbers, or arrays. - Child nodes: Nested nodes create the hardware hierarchy.
标签: 节点名[@单元地址] { // 标签: 和 @单元地址不是必须
子节点名1 {
子节点1的子节点 {
};
};
子节点名2 {
};
};2
3
4
5
6
7
8
9
Node Example
/dts-v1/; // 设备树编译器版本信息
/ { // 根节点
node1 { // 第一个子节点
child_node { // node1 的子节点
// 空节点,没有定义任何属性或子节点
};
};
node2 { // 第二个子节点
// 空节点,没有定义任何属性或子节点
};
};2
3
4
5
6
7
8
9
10
11
12
13
Node Names
Use Descriptive Names
Choose a name that describes the device or hardware function.
/dts-v1/;
/ {
// 串口设备
serial {
};
// I2C 控制器及设备
i2c {
};
// USB 控制器
usb {
};
}2
3
4
5
6
7
8
9
10
11
12
13
14
Follow the Existing Style
The SDK uses lowercase names. Multiword names commonly use underscores or hyphens; follow existing examples.
/dts-v1/;
/ {
serial_port {//比如我们看这个就知道是串口端口的意思
};
gpio-controller {//比如我们看这个就知道是gpio控制器的意思
};
}2
3
4
5
6
7
Follow Existing Conventions
Reuse vendor examples for hardware already described in the SDK.
//绑定文档
SDK/kernel/Documentation/devicetree/bindings
//64位设备树
SDK/linux/kernel/arch/arm64/boot/dts
//32位设备树
SDK/linux/kernel/arch/arm/boot/dts2
3
4
5
6
Invalid Names
The examples below show invalid names. Check device-tree naming syntax if compilation fails. Invalid example:
/dts-v1/;
/{
node1\1{ //这里有一个特殊字符
child_node{
};
};
node2{
};
};2
3
4
5
6
7
8
9
10
11
Unique Sibling Names
Nodes at the same level need unique names. Distinguish instances by an address or other identifying information. Invalid example:
/dts-v1/;
/{
node1{ //节点命相同
child_node{
};
};
node1{//节点命相同
};
};2
3
4
5
6
7
8
9
10
Nodes under different parents can have the same name.
/dts-v1/;
/{
node1{
child_node{//节点命相同
};
};
node2{
child_node{//节点命相同
};
};
};2
3
4
5
6
7
8
9
10
11
12
Unit Address
i2c@1c2c0000 identifies an I²C controller instance. Its unit address helps distinguish it; the register resources are described by reg.
/dts-v1/;
/ {
// 串口设备示例,地址不同
serial@80000000 {
};
// 串口设备示例,地址不同
serial@90000000 {
};
// I2C 控制器及设备示例
i2c@91000000 {
};
// USB 控制器示例
usb@92000000 {
};
};2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
The simplified example compiles with warnings because properties such as reg are missing.
Labels
A label references a node without repeating its path. This example adds node_add2 under serial@80000000 by referencing uart1. Create device_tree.dts with this content:
/dts-v1/;
/ {
// 串口设备示例,地址不同,uart1是标签
uart1: serial@80000000 {
node_add1{
};
};
// 串口设备示例,地址不同,uart2是标签
uart2: serial@90000000 {
};
// I2C 控制器及设备示例,i2c1是标签
i2c1: i2c@91000000 {
};
// USB 控制器示例,USB是标签
usb1: usb@92000000 {
};
};
&uart1{ // 通过引用标签的方式往 serial@80000000 中追加一个节点非覆盖。
node_add2{
};
};2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
Build
dtc -I dts -O dtb -o device_tree.dtb device_tree.dtsIgnore Warnings
Decompile
dtc -I dtb -O dts -o backdevice_tree.dts device_tree.dtbIgnore Warnings
View
cat backdevice_tree.dtsReferencing the label adds node_add2 to serial@80000000. Taishan Pi uses this pattern throughout its device trees.
Aliases
The special aliases node maps short identifiers to node paths. Labels name nodes in source; aliases provide path mappings for code to look up.
//通过aliases来定义别名
aliases{
//这里面描述的都是别名
[别名]=[标签]
[别名]=[节点路径]
};2
3
4
5
6
/dts-v1/;
/ {
// 别名定义
aliases {
uart1 = &uart1; // uart1 别名指向名为 uart1 的设备节点
uart2 = &uart2; // uart2 别名指向名为 uart2 的设备节点
uart3 = "/serial@10000000"; // uart3 别名指向路径为 /serial@10000000 的设备节点,这里的/表示根目录
};
// 串口设备示例,地址不同,uart1 是标签
uart1: serial@80000000 {
// 可在此处添加串口设备的配置信息
};
// 串口设备示例,地址不同,uart2 是标签
uart2: serial@90000000 {
// 可在此处添加串口设备的配置信息
};
// 串口设备示例,地址不同,uart3 是标签,通过路径方式定义
serial@10000000 {
// 可在此处添加串口设备的配置信息
};
};2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
Label or Alias
Labels simplify source references. Aliases let kernel code find nodes without hardcoding full paths. Find a node by its full path:
Find a node through an alias:
Properties
Properties are name/value pairs describing hardware. The examples below introduce common value forms and standard properties.
- String:
- Property name:
compatible- Example:
compatible = "lckfb,tspi-v10", "rockchip,rk3566";- Description: Identifies compatible devices or drivers.
- Integer:
- Property name:
reg- Example:
reg = <0x1000>;.- Description: Defines the physical address and size of the device, which is usually used to describe the I/O resources of the memory map.
- Array:
- Property name:
reg- Example:
reg = <0x1000,0x10>;.- Description: Defines the physical address and size of the device, which is usually used to describe the I/O resources of the memory map.
- List:
- Property name:
interrupts- Example:
interrupts = <0 39 4>, <0 41 4>,<0 40 4>;.- Description: A list of interrupt specifiers, each containing fields such as the interrupt number and trigger type.
- Empty property:
- Property name:
regulator-always-on;- Example:
regulator-always-on;- Description: Marks the regulator as always enabled.
- Reference:
- Property name:
gpios- Example:
gpios = <&gpio1 RK_PB0 GPIO_ACTIVE_LOW>;- Description: References another node, typically through its label.
model
The model string identifies the board.
/{
model = "lckfb tspi V10 Board";
}2
3
compatible
The operating system uses compatible strings to match devices with drivers.
rk_headset: rk-headset {
compatible = "rockchip_headset","rockchip_headset2";
};2
3
The headset-detection driver matches "rockchip_headset": kernel/drivers/headset_observe/rockchip_headset_core.c
.......
static const struct of_device_id rockchip_headset_of_match[] = {
{ .compatible = "rockchip_headset", }, // 定义设备树匹配项,指定兼容性字符串,与上面的设备树匹配
{}, // 结束符号
};
MODULE_DEVICE_TABLE(of, rockchip_headset_of_match); // 定义设备树匹配表供内核使用
static struct platform_driver rockchip_headset_driver = {
.probe = rockchip_headset_probe, // 注册设备探测函数
.remove = rockchip_headset_remove, // 注册设备移除函数
.resume = rockchip_headset_resume, // 注册设备恢复函数
.suspend = rockchip_headset_suspend, // 注册设备挂起函数
.driver = {
.name = "rockchip_headset", // 设备名称
.owner = THIS_MODULE, // 持有模块的指针
.of_match_table = of_match_ptr(rockchip_headset_of_match), // 设备树匹配表指针
},
};
.........2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
reg
reg describes address ranges using the parent's #address-cells and #size-cells.
gmac1: ethernet@fe010000 {
reg = <0x0 0xfe010000 0x0 0x10000>;
}2
3
Address and Size Cells
These properties define how a parent interprets the reg values of its children. General reg format:
reg = <[address1] [length1] [address2] [length2] ...>;[addressN]is the starting address.#address-cellsdefines how many 32-bit cells encode it: one for 32 bits, two for 64 bits.[lengthN]is the range length.#size-cellsdetermines its cell count. Each address/length pair can therefore occupy two, three, four, or more cells. For address0x03F02000and size0x1000, with#address-cells = <1>and#size-cells = <1>, write:
reg = <0x03F02000 0x1000>;For a 64-bit address, with #address-cells = <2> and #size-cells = <1>, the following encodes address 0x00000001 0x03F02000 and size 0x1000:
reg = <0x00000001 0x03F02000 0x1000>;Example:
/ {
#address-cells = <2>;
#size-cells = <2>;
cpus {
#address-cells = <2>;
#size-cells = <0>;
cpu0: cpu@0 {
受cpus节点的影响
#address-cells = <2>;
#size-cells = <0>;
所以地址就是0x0,大小就是 0x0
*/
reg = <0x0 0x0>;
};
};
gmac1: ethernet@fe010000 {
/*
受根节点的影响
#address-cells = <2>;
#size-cells = <2>;
所以地址就是0xfe010000 ,大小就是 0x10000
*/
reg = <0x0 0xfe010000 0x0 0x10000>;
};
};2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
status
Enable or disable nodes through status. The most common values are okay and disabled. status attribute values include:
"okay"marks the device as operational."disabled"disables it in this configuration."fail"marks it as unavailable because of an error."fail-sss"includes error-specific information.
//用户三色灯
&leds {
status = "okay";
};
//耳机插入检测,不使用扩展板情况需关闭,否则默认会检测到耳机插入
&rk_headset {
status = "disabled";
};2
3
4
5
6
7
8
device_type
CPU and memory nodes commonly use device_type = "cpu" and device_type = "memory".
device_type = "cpu";Custom Fields
Use descriptive custom property names and avoid conflicts with standard properties.
/ {
my_custom_node { /* 自定节点 */
compatible = "myvendor,my-custom-device"; /* 兼容性属性 */
my_custom_property = <1>; /* 自定义属性,假设为整数类型 */
my_custom_string_property = "My custom value"; /* 自定义字符串属性 */
};
};2
3
4
5
6
7
Worked Example
Exercises
- [ ] Make the red user LED blink every second, blue every two seconds, and green every three seconds.
- [ ] Disable the three user LEDs.
- [ ] Disable and enable HDMI.
- [ ] Disable Ethernet and check whether repeated missing-interface messages disappear from the serial console.
- [ ] Change the debug baud rate from 1500000 to 115200.
- [ ] Change the infrared remote-control values.