迅为iMX6UL开发板驱动-设备树节点名称和子节点获取设备树数据

文档介绍迅为IMX6UL开发板设备树通过节点名称获取设备树数据,以及获取子设备数据。

1 驱动介绍

驱动源码在压缩包“itop_of_get_trees_demon1.tar.gz”中,其中 “itop_of_get_trees_demon1.c”为驱动源码。

以下按照执行顺序依次介绍函数功能:

static int treesum_init(void)函数中:

of_find_node_by_path:通过路径和名称,获取设备树节点。

of_property_read_string:通过设备节点和属性名,获取 string 数据。

of_property_count_strings:通过设备节点和属性名,获取 strings 数量。

of_property_read_string_index:通过设备节点和属性名,以及编号,获取对应string。

of_property_read_u32:通过设备节点和属性名,获取 u32 数据。

of_property_read_u32_array:通过设备节点和属性名,获取 u32 数组。

of_property_read_u8_array:通过设备节点和属性名,获取 u8 数组。

of_get_child_by_name:通过路径和名称,获取设备树子节点。

static int treesum_probe(struct platform_device * pdev)函数中:

device_property_read_string:通过 dev 和属性名,获取 string 数据。

device_property_read_string_array:通过 dev 和属性名,获取 string 数组。

device_property_read_u32:通过 dev 和属性名,获取 u32 数据。

device_property_read_u32_array:通过 dev 和属性名,获取 u32 数组。

device_property_read_u8_array:通过 dev 和属性名,获取 u8 数组。

device_for_each_child_node:通过设备节点,遍历子节点。

fwnode_property_read_string:通过 fwnode_handle 和属性名,获取 string 数据。

fwnode_property_read_string_array:通过 fwnode_handle 和属性名,获取 string 数 组。

fwnode_property_read_u32_array:通过 fwnode_handle 和属性名,u32 数组。

以上函数原型分布在:“include/linux/property.h”“linux/gpio/consumer.h”

"include/linux/of.h"头文件中。

2 设备树

设备树增加以下内容:

 

3 测试

将修改之后的设备树文件编译,烧写到开发板中。启动之后,使用命令“ls

proc/device-tree”,如下图所示,可以看到设备树的节点“itop4412-tree-sum”。

 

通过 U 盘或者 NFS 共享目录(参考迅为对应的文档)将编译出的

itop_of_get_trees_demon1.ko 文件拷贝到开发板,使用命令“insmod

itop_of_get_trees_demon1.ko”加载驱动,如下图所示,可以看到所有的设备树信息被打印 了两次,如下图所示。

 

rmmod 模块,使用命令“mkdir /lib/modules”,然后继续卸载,发现还是有提示“4.1.15-g833979a-dirty”。继续根据提示使用命令“mkdir /lib/modules/4.1.15-g833979a-dirty”新建提示的目录,缺少的目录只需要新建一次即可。

转自:http://topeetboard.com

猜你喜欢

转载自www.cnblogs.com/topeet/p/11003687.html