设备树介绍:

设备树是一个描述设备硬件资源的文件,该文件是由节点组成的树形结构。如下:

/ {

node1 {

a-string-property = "A string";

a-string-list-property = "first string", "second string";

// hex is implied in byte arrays. no '0x' prefix is required

a-byte-data-property = [01 23 34 56];

child-node1 {

first-child-property;

second-child-property = <1>;

a-string-property = "Hello, world";

};

child-node2 {

};

};

node2 {

an-empty-property;

a-cell-property = <1 2 3 4>; /* each number (cell) is a uint32 */

child-node1 {

};

};

};

① “/”是根节点,node1和node2,是其子节点;

② “child-node1” 和 “child-node2”,是node1的子节点;

③ a-string-property,是字符串属性;

④ a-string-list-property,字符串列表属性;

⑤ a-byte-data-property,是字节数据属性;

节点与属性:

节点的定义:

[label:][@unit-address] {

properties;

child-node {

[...]

};

};

常见属性:

compatible,用来匹配驱动,一般有"供应商,产品"

#address-cells,决定子节点reg属性的地址cell数,cell是u32

#size-cells,决定子节点reg属性的地址长度cell数,cell是u32

reg,一般为设备寄存器地址及范围,如

设备树实例:

添加LED节点:

$ vim arch/arm/boot/dts/exynos4412-fs4412.dts

fs4412-led {

compatible = "farsight,fs4412-led";

reg = <0x114001E0 0x8>;

};

$ cd ../../../..

$ make dtbs

$ cp arch/arm/boot/dts/exynos4412-fs4412.dtb /tftpboot

代码:

1 #include

2 #include

3 #include

4 #include

5 #include

6

7 #define GPF3CON 0x0

8 #define GPF3DAT 0x4

9

10

11 void __iomem *led_va;

12 int led_probe(struct platform_device *pdev)

13 {

14 unsigned int regval;

15 struct resource *res;

16

17 printk("led probe\n");

18 /* 1. 获取资源,中断或者内存 */

19 res = platform_get_resource(pdev, IORESOURCE_MEM, 0);

20 if (!res) {

21 printk("get platform resource failure\n");

22 return -EINVAL;

23 }

24

25 /* 2. 内存映射,并初始化设备 */

26 led_va = ioremap(res->start, resource_size(res)); /* 内存映射得到虚拟地址 */

27 regval = readl(led_va + GPF3CON); /* (led_va + GPF3CON) 寄存器的虚拟地址*/

28 regval &= ~(0xf<<20); /* GPFCON[23:20]清零 */

29 regval |= 0x1<<20; /* 配置GPF3_5引脚功能为输出 */

30 writel(regval, led_va + GPF3CON);

31 regval = readl(led_va + GPF3DAT);

32 regval |= 0x1<<5; /* 控制GPF3_5输出高电平 */

33 writel(regval, led_va + GPF3DAT);

34 return 0; /* 0表示成功,<0表示失败 */

35 }

36

37 int led_remove(struct platform_device *pdev)

38 {

39 unsigned int regval;

40 printk("led remove\n");

41 regval = readl(led_va + GPF3CON); /* (led_va + GPF3CON) 寄存器的虚拟地址*/

42 regval &= ~(0xf<<20); /* GPFCON[23:20]清零 */

43 writel(regval, led_va + GPF3CON);

44 iounmap(led_va);

45 return 0;

46 }

47

48 /* 用来匹配平台设备的列表 */

49 const struct of_device_id of_device_table[] = {

50 {.compatible = "farsight,fs4412-led"},

51 {}

52 };

53

54 struct platform_driver pdrv = {

55 .probe = led_probe,

56 .remove = led_remove,

57 .driver = {

58 .owner = THIS_MODULE,

59 .name = "fs4412-led",

60 .of_match_table = of_match_ptr(of_device_table),

61 },

62 };

63

64 static int hello_init(void)

65 {

66 printk("Hello, Kernel!\n");

67 return platform_driver_register(&pdrv);

68 }

69

70 static void hello_exit(void)

71 {

72 printk("Goodbye, Kernel!\n");

73 platform_driver_unregister(&pdrv);

74 }

75

76 module_init(hello_init); /* 声明模块加载函数 */

77 module_exit(hello_exit); /* 声明模块卸载函数 */

78

79 MODULE_LICENSE("GPL"); /* 声明模块遵守的开源协议 */

80 MODULE_AUTHOR("zhufeng "); /* 模块作者 */

81 MODULE_DESCRIPTION("hello module"); /* 模块描述信息 */

设备树(Device Tree)的更多相关文章

  1. 【转载】Linux设备树(Device Tree)机制

    转:Linux设备树(Device Tree)机制   目录 1. 设备树(Device Tree)基本概念及作用2. 设备树的组成和使用 2.1. DTS和DTSI 2.2. DTC 2.3. DT ...

  2. ARM Linux 3.x的设备树(Device Tree)

    1. ARM Device Tree起源 Linus Torvalds在2011年3月17日的ARM Linux邮件列表宣称“this whole ARM thing is a f*cking pai ...

  3. 转:Linux设备树(Device Tree)机制

    目录 1. 设备树(Device  Tree)基本概念及作用 2. 设备树的组成和使用 2.1. DTS和DTSI 2.2. DTC 2.3. DTB 2.4. Bootloader 3. 设备树中d ...

  4. 我眼中的Linux设备树(一 概述)

    一 概述设备树(Device tree)是一套用来描述硬件属相的规则.ARM Linux采用设备树机制源于2011年3月份Linux创始人Linus Torvalds发的一封邮件,在这封邮件中他提倡A ...

  5. Linux设备树(一 概述)

    一 概述 设备树(Device tree)是一套用来描述硬件属相的规则.ARM Linux采用设备树机制源于2011年3月份Linux创始人Linus Torvalds发的一封邮件,在这封邮件中他提倡 ...

  6. linux 设备树【转】

    转自:http://blog.csdn.net/chenqianleo/article/details/77779439 [-] linux 设备树 为什么要使用设备树Device Tree 设备树的 ...

  7. 翻译:A Tutorial on the Device Tree (Zynq) -- Part I

    A Tutorial on the Device Tree (Zynq) -- Part I 此教程的目的 本教程是针对Xilinx' Zynq-7000 EPP设备(一个集成了FPGA的ARM Co ...

  8. linux设备树笔记__dts基本概念及语法【转】

    转自:http://www.360doc.com/content/15/1113/11/15700426_512794532.shtml 设备树手册(Device Tree Usage)原文地址:ht ...

  9. ARM Linux 3.x的设备树(Device Tree)

    http://blog.csdn.net/21cnbao/article/details/8457546 宋宝华 Barry Song <21cnbao@gmail.com> 1.     ...

  10. 【转】 ARM Linux 3.x的设备树(Device Tree)

    1.    ARM Device Tree起源 http://blog.csdn.net/21cnbao/article/details/8457546 Linus Torvalds在2011年3月1 ...

随机推荐

  1. js获取或设置当前窗口url参数

    直接上代码 // 获取当前窗口url中param参数的值 function get_param(param){ var query = location.search.substring(1).spl ...

  2. Good Bye 2015 F - New Year and Cleaning

    F - New Year and Cleaning 这题简直是丧心病狂折磨王.. 思路:容易想到这样一个转换,把整个矩形一起移动,矩形移出去的时候相当于一行或者一列. 为了优化找到下一个消去的点,我先 ...

  3. 十 使用dict和set

    dict Python内置了字典:dict的支持,dict全称dictionary,在其他语言中也称为map,使用键-值(key-value)存储,具有极快的查找速度. 举个例子,假设要根据同学的名字 ...

  4. AOSP编译

    AOSP编译 1 编译环境Win10系统安装VMplayer14,主机16G内存,I3-4170 ,虚拟机ubuntu-16.04.1-desktop-amd64,12G内存. 2 软件安装sudo ...

  5. 最大公约数or最小公倍数

    最大公约数or最小公倍数 import org.junit.Test; public class 最大公约数or最小公倍数 { public int maxGYS(int m,int n) { int ...

  6. gVim 启动时窗口自动居中

    最近折腾 vim, 除了配置巨麻烦外, 另一个很蛋疼的就是窗口位置问题了, 折腾了半天无法启动时自动居中, 找遍各地也只有保存上次位置, 下次启动时恢复的方法 废话不多说, 直接上代码, 丢到 vim ...

  7. 【leetcode】22. Generate Parentheses

    题目描述: Given n pairs of parentheses, write a function to generate all combinations of well-formed par ...

  8. CodeForces 909D Colorful Points

    题解: 暴力,模拟. 把字符串压缩一下,相同的处理成一位,记录下个数,然后暴力模拟即可. #include <bits/stdc++.h> using namespace std; con ...

  9. Docker应用系列(四)| 部署java应用

    本示例基于Centos 7,假设目前使用的账号为release,拥有sudo权限. 由于Docker官方镜像下载较慢,可以开启阿里云的Docker镜像下载加速器,可参考此文进行配置. 主机上服务安装步 ...

  10. 【LeetCode】shell

    195. Tenth Line 输出file.txt中的第十行 答案: # Read from the file file.txt and output the tenth line to stdou ...