节点信息"/>
驱动获取设备树节点信息
mycdev.c
#include <linux/init.h>
#include <linux/module.h>
#include <linux/of.h>struct device_node *dnode; //解析得到的设备树节点对象指针
struct property *pr;
unsigned int lenth;
static int __init mycdev_init(void)
{//解析设备树节点信息dnode = of_find_node_by_name(NULL,"mynode");if(dnode == NULL){printk("解析设备树节点失败\n");return -ENXIO;}//解析uint属性pr = of_find_property(dnode,"unit",&lenth);if(pr == NULL){printk("属性解析失败\n");return -ENXIO;}printk("name=%s,value %x,%x\n",pr->name,__be32_to_cpup((u32 *)pr->value),__be32_to_cpup((u32 *)pr->value+1));pr = of_find_property(dnode,"binarry",&lenth);if(pr == NULL){printk("属性解析失败\n");return -ENXIO;}int i;for(i=0;i<lenth;i++){printk("name=%s,value=%x\n",pr->name,*((u8 *)pr->value+i));}return 0;
}
static void __exit mycdev_exit(void)
{}
module_init(mycdev_init);
module_exit(mycdev_exit);
MODULE_LICENSE("GPL");
更多推荐
驱动获取设备树节点信息
发布评论