1. 程式人生 > >android 裝置樹中的devices_node的資料獲取

android 裝置樹中的devices_node的資料獲取

android/linux下devicetree中常用的of函式

從device_node中獲取資訊:

int of_property_read_u8_array(const struct device_node *np, const char *propname,u8 *out_values, size_t sz);

int of_property_read_u16_array(const struct device_node *np, const char *propname,u16 *out_values, size_t sz);

int of_property_read_u32_array(const struct device_node *np, const char *propname,u32 *out_values, size_t sz);

從裝置結點np中讀取屬性名為propname,型別為8、16、32、位整型陣列的屬性值,並放入out_values,sz指明瞭要讀取的個數。

static inline int of_property_read_u8(const struct device_node *np,const char *propname,u8 *out_value)

static inline int of_property_read_u16(const struct device_node *np,const char *propname,u8 *out_value)

static inline int of_property_read_u32(const struct device_node *np,const char *propname,u8 *out_value)

從裝置結點np中讀取屬性名為propname,型別為8、16、32位的屬性值,並放入out_values。實際上這裡呼叫的就是sz為1的XXX_array函式。

int of_property_read_u32_index(const struct device_node *np,const char*propname,u32 index, u32 *out_value)

從裝置結點np中讀取屬性名為propname的屬性值中第index個u32數值給out_value

int of_property_read_u64(conststruct device_node *np, const char *propname,u64 *out_value)

從裝置結點np中讀取屬性名為propname,型別為64位的屬性值,並放入out_values

int of_property_read_string(struct device_node *np, const char *propname,const char**out_string)

從裝置結點np中讀取屬性名為propname的字串型屬性值

int of_property_read_string_index(struct device_node *np, const char *propname,intindex, const char **output)

從裝置結點np中讀取屬性名為propname的字串型屬性值陣列中的第index個字串

int of_property_count_strings(struct device_node *np, const char *propname)

從裝置結點np中讀取屬性名為propname的字串型屬性值的個數

unsigned int irq_of_parse_and_map(struct device_node *dev, int index)

從裝置節點dev中讀取第index個irq號

int of_irq_to_resource(struct device_node *dev, int index, struct resource *r)

從裝置節點dev中讀取第index個irq號,並填充一個irq資源結構體

int of_irq_count(struct device_node *dev)

獲取裝置節點dev的irq個數

static inline bool of_property_read_bool(const struct device_node *np,const char *propname);

如果裝置結點np含有propname屬性,則返回true,否則返回false。一般用於檢查空屬性是否存在。

struct property* of_find_property(const struct device_node *np,const char *name,int *lenp)

根據name引數,在指定的裝置結點np中查詢匹配的property,並返回這個property

const void * of_get_property(const struct device_node *np, const char *name,int *lenp)

根據name引數,在指定的裝置結點np中查詢匹配的property,並返回這個property的屬性值

struct device_node* of_get_parent(const struct device_node *node)

獲得node節點的父節點的device node

int of_device_is_compatible(const struct device_node *device,const char *compat);

判斷裝置結點device的compatible屬性是否包含compat指定的字串

從of_allnodes中查詢資訊:

struct device_node* of_find_node_by_path(const char *path)
根據路徑引數,在全域性連結串列of_allnodes中,查詢匹配的device_node

struct device_node* of_find_node_by_name(struct device_node *from,const char *name)
則根據name在全域性連結串列of_allnodes中查詢匹配的device_node,若from=NULL表示從頭開始查詢

struct device_node* of_find_node_by_type(struct device_node *from,const char *type)

根據裝置型別在全域性連結串列of_allnodes中查詢匹配的device_node

struct device_node * of_find_compatible_node(struct device_node *from, const char*type, const char,*compatible);

根據compatible的屬性值在全域性連結串列of_allnodes中查詢匹配的device_node,大多數情況下,from、type為NULL。

struct device_node* of_find_node_with_property(struct device_node *from,const char *prop_name)

根據節點屬性的name在全域性連結串列of_allnodes中查詢匹配的device_node

struct device_node* of_find_node_by_phandle(phandle handle)

根據phandle在全域性連結串列of_allnodes中查詢匹配的device_node

雜:

void __iomem* of_iomap(struct device_node *node, int index);

通過裝置結點直接進行裝置記憶體區間的 ioremap(),index是記憶體段的索引。若裝置結點的reg屬性有多段,可通過index標示要ioremap的是哪一段,只有1段的情況,index為0

unsigned long __init of_get_flat_dt_root(void)

用來查詢在dtb中的根節點,好像返回的都是0

int of_alias_get_id(struct device_node *np, const char *stem)

獲取節點np對應的aliasid號

struct device_node* of_node_get(struct device_node *node)

void of_node_put(struct device_node *node)

device node計數增加/減少

const struct of_device_id* of_match_node(const struct of_device_id *matches,const struct device_node*node)

將matches陣列中of_device_id結構的name和type與device node的compatible和type匹配,返回匹配度最高的of_device_id結構

platform_device和resource相關:

int of_address_to_resource(struct device_node *dev, int index,struct resource *r)

根據裝置節點dev的reg屬性值,填充資源結構體r。Index引數指明瞭使用reg屬性中第幾個屬性值,一般設定為0,表示第一個。

struct platform_device* of_device_alloc(struct device_node *np,const char *bus_id,struct device *parent)

根據device node,bus_id以及父節點建立該裝置的platform_device結構,同時會初始化它的resource成員。

int of_platform_bus_probe(struct device_node *root,const struct of_device_id *matches,struct device *parent)

遍歷of_allnodes中的節點掛接到of_platform_bus_type總線上,由於此時of_platform_bus_type總線上還沒有驅動,所以此時不進行匹配

int of_platform_populate(struct device_node *root,const struct of_device_id *matches,const struct of_dev_auxdata *lookup,struct device *parent)

遍歷of_allnodes中的所有節點,生成並初始化所以節點的platform_device結構

struct platform_device* of_find_device_by_node(struct device_node *np)

根據device_node查詢返回該裝置對應的platform_device結構