fs4412_demo{
compatible = "farsight,hqyj";
string = "hello world";
bi-array = [0c 19 20 54];
word-array = <32 45 67 89>;
string-list = "aaa" , "bbb" , "ccc";
pin = <5>;
};
头文件:<linux/of.h>
/**
*of_find_compatible_node - 通过compatible属性查找设备树中指定节点
* @from - 指向开始路径的节点,如果为NULL,则从根节点开始
* @type - device_type设备类型,可以为NULL
* @compat - 指向节点的compatible属性的值(字符串)的首地址
* 成功:得到节点的首地址;失败:NULL
*/
struct device_node * of_find_compatible_node(struct device_node *from,const char *type, const char *compat);
static struct device_node *np = NULL;
np = of_find_compatible_node(NULL,NULL,"farsight,hqyj");
/**
* of_find_node_by_path - 通过路径查找指定节点
* path - 带全路径的节点名,也可以是节点的别名
* 成功:得到节点的首地址;失败:NULL
*/
struct device_node *of_find_node_by_path(const char *path);
/**
* of_property_read_string - 提取节点中的字符串(属性值)
* @np - 设备节点指针
* @propname - 属性名称
* @out_string - 输出参数,指向字符串(属性值)
* 成功:0;失败:负数,绝对值是错误码
*/
int of_property_read_string(struct device_node *np, const char *propname, const char **out_string);
int ret = 0;
const char *str = NULL;
ret = of_property_read_string(np, "string",&str);
if(ret < 0){
printk("of_property_read_string failed...\n");
return ret;
}
printk("str:%s\n",str);
/**
* of_property_read_u32 - 提取节点中类型为无符号×××32位的(属性值)
* @np - 设备节点指针
* @propname - 属性名称
* @out_value - 输出参数,指向(属性值)
* 成功:0;失败:负数,绝对值是错误码
*/
int of_property_read_u32(const struct device_node *np, const char *propname, u32 *out_value);
int num = 0;
of_property_read_u32(np,"pin",&num);
/**
*of_property_read_u32_array -提取节点中类型为无符号×××32位×××数组的(属性值)
*@np - 设备节点指针
* @propname - 属性名称
*@out_value - 输出参数,指向数组(属性值)
*成功:0;失败:负数,绝对值是错误码
*/
int of_property_read_u32_array(const struct device_node *np, const char *propname, u32 *out_values, size_t sz);
int arr[4] = {0};
of_property_read_u32_array(np,"word-array",arr,4);
转载于:https://blog.51cto.com/5468775/2087889