EmbedFire i.MX 6ull开发板学习笔记(七)---of函数
Linux定义了大量的函数用于查询,获取设备树的内容,这些函数都是以of开头,所以又称为of函数。定义在include/linux目录下以of开头的头文件,如of.h、of_gpio.h等;以及drivers/of目录下。
便于描述设备中的节点,Linux定义了device_node结构体,定义在include/linux/of.h文件里,一些常用的of函数原型定义也在该文件里。
一、查询节点的of函数
1、
struct device_node *of_find_node_by_name(struct device_node *from, const char *name);
功能:根据节点名称查找节点
from:开始查找的节点,为NULL表示从根节点开始;
name:节点名称,如i2c1;
返回值:找到的节点,未找到为NULL
2、
struct device_node *of_find_node_by_type(struct device_node *from, const char *type);
功能:根据device_type属性值查找节点
from:开始查找的节点,为NULL表示从根节点开始;
type:device_type属性值
返回值:找到的节点,未找到为NULL
3、
struct device_node *of_find_compatible_node(struct device_node *from, const char *type, const char *compat);
功能:根据device_type和compatible属性值查找节点
from:开始查找的节点,为NULL表示从根节点开始;
type:device_type属性值,可为NULL,表示可忽悠;
compat:compatible属性列表;
返回值:找到的节点,未找到为NULL
4、
struct device_node *of_find_matching_node_and_match(
struct device_node *from,
const struct of_device_id *matches,
const struct of_device_id **match)
功能:根据匹配表查找节点
from:开始查找的节点,为NULL表示从根节点开始;
matches:of_device_id 匹配表,按此匹配表
match:找到的匹配表;
返回值:找到的节点,未找到为NULL
5、
struct device_node *of_find_node_opts_by_path(const char *path, const char **opts);
功能:根据节点路径查找节点
path:节点的全路径,可为别名,如/leds
opts:附加在路径末尾带“:”的部分,即path使用了别名。如路径/cpu/leds/led3:cpu。可为NULL。
返回值:找到的节点,未找到为NULL
6、
struct device_node *of_find_node_by_path(const char *path);
功能:上面of_find_node_opts_by_path(const char *path, const char **opts) opts为NULL即为此函数
path:节点的全路径,可为别名
返回值:找到的节点,未找到为NULL。
7、
struct device_node *of_find_node_by_phandle(phandle handle);
功能:根据节点phandle指令查找节点
handle:指向节点的指针,编译后得到,用于指向&lable
返回值:找到的节点,为找到单位NULL。
8、
struct device_node *of_find_node_with_property(struct device_node *from, const char</