struct device_node {
const char *name;
const char *type;
phandle phandle;
const char *full_name;
struct fwnode_handle fwnode;
struct property *properties;
struct property *deadprops; /* removed properties */
struct device_node *parent;
struct device_node *child;
struct device_node *sibling;
#if defined(CONFIG_OF_KOBJ)
struct kobject kobj;
#endif
unsigned long _flags;
void *data;
#if defined(CONFIG_SPARC)
const char *path_component_name;
unsigned int unique_id;
struct of_irq_controller *irq_trans;
#endif
};
struct property {
char *name;
int length;
void *value;
struct property *next;
#if defined(CONFIG_OF_DYNAMIC) || defined(CONFIG_SPARC)
unsigned long _flags;
#endif
#if defined(CONFIG_OF_PROMTREE)
unsigned int unique_id;
#endif
#if defined(CONFIG_OF_KOBJ)
struct bin_attribute attr;
#endif
};
demo@123456789 { /*节点名demo,规则:'节点名@地址;,'节点名','路径引用:节点名'*/
compatible = "fs4412,demo"; /*节点属性compatible:匹配节点的字符串,规则"厂商,节点名"*/
reg = <0x11111111 0x2 0x22222222 0x4>; /*通用属性:资源I/O地址,数组存储,2维:2列N行*/
interrupts = <0 1 2>, <1 2 4>; /*通用属性:<中断类型 中断号 中断标志>,数组存储,2维:3列N行*/
item1 = "a1","b2","c3"; /*自定义属性:传递一个字符串常量首地址*/
item2,flag; /*自定义属性:不传递内容,可能是开关或标志*/
};
struct device_node *node = NULL;
struct property *pp = NULL;
unsigned long *preg = NULL;
unsigned long *pint = NULL;
unsigned char *pstr = NULL;
node = of_find_node_by_path("/demo@123456789");
if (!IS_ENABLED(CONFIG_OF) || !node){
printk(KERN_ERR "of find node fail. \n");
return -EINVAL;
}
pp = of_find_property(node, "reg", NULL);
printk(KERN_INFO"%s: %x\n", pp->name, pp->length);
preg = pp->value;
for(index = 0; index < (pp->length/sizeof(unsigned long)); index++){
printk(KERN_INFO"[%d]: %lx\n", index, be32_to_cpu(preg[index]));
}
pp = of_find_property(node, "interrupts", NULL);
if (!pp){
printk(KERN_ERR"Not find interrupts\n");
}else{
printk(KERN_INFO"%s: %x\n", pp->name, pp->length);
pint = pp->value;
for(index = 0; index < (pp->length/sizeof(unsigned long)); index++){
printk(KERN_INFO"[%d]: %lx\n", index, be32_to_cpu(pint[index]));
}
}