linux下devicetree中常用的of函數

來源:互聯網
上載者:User

標籤: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結構


 

linux下devicetree中常用的of函數

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.