#include <linux/init.h>
#include <linux/module.h>
#include <linux/of.h>
/*mynode@0x12345678{
compatible = "hqyj,mynode";
astring = "hello 22071";
unit = <0xaabbccdd 0x11223344>;
binarry = [00 0c 29 7b f9 be]
mixed = "hello",[11 22],<0x12345678>;
};
*/
//定义指针指向获取的设备树结点
struct device_node *node;
struct property* pr;
int len,i,ret;
unsigned int val;
unsigned int array[2];
const char *str;
static int __init mycdev_init(void)
{
//通过路径获取设备树结点信息
node = of_find_node_by_path("/mynode@0x12345678");
if(node == NULL)
{
printk("of_find_node_by_path is error\n");
return -EFAULT;
}
printk("of_find_node_by_path is success\n");
// printk("name = %s,value = %s\n",node->properties->name,(char *)node->properties->value);
// printk("name = %s,value = %s\n",node->properties->next->name,(char *)node->properties->next->value);
// printk("name = %s,value = %s\n",node->properties->next->next->name,_be32_to_cpup((int *)node->properties->next->next->value),_be32_to_cpup((int *)node->properties->next->next->value+1));
//解析单字节属性
// pr = of_find_property(node,"astring",&len);
// if(pr == NULL)
// {
// printk("of_find_property is error\n");
// return -EFAULT;
// }
// for(i = 0;i < len;i++)
// {
// printk("name = %s,value = %#x\n",pr->name,*((char *)pr->value+i));
// }
//获取u32的值
ret = of_property_read_u32_index(node,"uint",1,&val);
if(ret)
{
printk("of_property_read_u32_index is error\n");
return EFAULT;
}
printk("value = %#x\n",val);
return 0;
}
static void __exit mycdev_exit(void)
{
}
module_init(mycdev_init);
module_exit(mycdev_exit);
MODULE_LICENSE("GPL");