查找节点的of函数

设备都是以节点的形式挂载到设备树上

  • 因此要想获取这个设备的其他属性信息,必须先获取到这个设备的节点
  • Linux 内核使用 device_node 结构体来描述一个节点,此结构体定义在文件include/linux/of.h
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 属性 */
    struct device_node *parent;  /* 父节点 */
    struct device_node *child;   /* 子节点 */
    struct device_node *sibling;
    struct kobject kobj;
    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
};

节点的属性信息里面保存了驱动所需要的内容,

  • Linux 内核中使用结构体property表示属性,此结构体同样定义在文件 include/linux/of.h
struct property
{
    char *name;            /* 属性名字 */
    int length;            /* 属性长度 */
    void *value;           /* 属性值 */
    struct property *next; /* 下一个属性 */
    unsigned long _flags;
    unsigned int unique_id;
    struct bin_attribute attr;
};

获得设备树文件节点里面资源的步骤

  • 步骤一:查找我们要找的节点
  • 步骤二:获取我们需要的属性值

查找节点

of_find_node_by_path()

of_get_parent()

of_get_next_child()

获取属性值的of函数

  • of_property_read_u8()
  • of_property_read_u16()
  • of_property_read_u32()
  • of_property_read_u64()

  • of_property_read_u8_array()
  • of_property_read_u16_array()
  • of_property_read_u32_array()
  • of_property_read_u64_array()

of_find_property()

of_property_read_string()

of_iomap()

OF函数实验