linux 设备数 of,linux下devicetree中惯用的of函数
linux下devicetree中常用的of函數(shù)
從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);
從設(shè)備結(jié)點(diǎn)np中讀取屬性名為propname,類(lèi)型為8、16、32、位整型數(shù)組的屬性值,并放入out_values,sz指明了要讀取的個(gè)數(shù)。
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)
從設(shè)備結(jié)點(diǎn)np中讀取屬性名為propname,類(lèi)型為8、16、32位的屬性值,并放入out_values。實(shí)際上這里調(diào)用的就是sz為1的XXX_array函數(shù)。
int of_property_read_u32_index(const struct device_node *np,const char*propname,u32 index, u32 *out_value)
從設(shè)備結(jié)點(diǎn)np中讀取屬性名為propname的屬性值中第index個(gè)u32數(shù)值給out_value
int of_property_read_u64(conststruct device_node *np, const char *propname,u64 *out_value)
從設(shè)備結(jié)點(diǎn)np中讀取屬性名為propname,類(lèi)型為64位的屬性值,并放入out_values
int of_property_read_string(struct device_node *np, const char *propname,const char**out_string)
從設(shè)備結(jié)點(diǎn)np中讀取屬性名為propname的字符串型屬性值
int of_property_read_string_index(struct device_node *np, const char *propname,intindex, const char **output)
從設(shè)備結(jié)點(diǎn)np中讀取屬性名為propname的字符串型屬性值數(shù)組中的第index個(gè)字符串
int of_property_count_strings(struct device_node *np, const char *propname)
從設(shè)備結(jié)點(diǎn)np中讀取屬性名為propname的字符串型屬性值的個(gè)數(shù)
unsigned int?irq_of_parse_and_map(struct device_node *dev, int index)
從設(shè)備節(jié)點(diǎn)dev中讀取第index個(gè)irq號(hào)
int?of_irq_to_resource(struct device_node *dev, int index, struct resource *r)
從設(shè)備節(jié)點(diǎn)dev中讀取第index個(gè)irq號(hào),并填充一個(gè)irq資源結(jié)構(gòu)體
int?of_irq_count(struct device_node *dev)
獲取設(shè)備節(jié)點(diǎn)dev的irq個(gè)數(shù)
static inline bool of_property_read_bool(const struct device_node *np,const char *propname);
如果設(shè)備結(jié)點(diǎn)np含有propname屬性,則返回true,否則返回false。一般用于檢查空屬性是否存在。
struct property* of_find_property(const struct device_node *np,const char *name,int *lenp)
根據(jù)name參數(shù),在指定的設(shè)備結(jié)點(diǎn)np中查找匹配的property,并返回這個(gè)property
const void *?of_get_property(const struct device_node *np, const char *name,int *lenp)
根據(jù)name參數(shù),在指定的設(shè)備結(jié)點(diǎn)np中查找匹配的property,并返回這個(gè)property的屬性值
struct device_node*?of_get_parent(const struct device_node *node)
獲得node節(jié)點(diǎn)的父節(jié)點(diǎn)的device node
int?of_device_is_compatible(const struct device_node *device,const char *compat);
判斷設(shè)備結(jié)點(diǎn)device的compatible屬性是否包含compat指定的字符串
從of_allnodes中查找信息:
struct device_node* of_find_node_by_path(const char *path)
根據(jù)路徑參數(shù),在全局鏈表of_allnodes中,查找匹配的device_node
struct device_node* of_find_node_by_name(struct device_node *from,const char *name)
則根據(jù)name在全局鏈表of_allnodes中查找匹配的device_node,若from=NULL表示從頭開(kāi)始查找
struct device_node* of_find_node_by_type(struct device_node *from,const char *type)
根據(jù)設(shè)備類(lèi)型在全局鏈表of_allnodes中查找匹配的device_node
struct device_node * of_find_compatible_node(struct device_node *from, const char*type, const char,*compatible);
根據(jù)compatible的屬性值在全局鏈表of_allnodes中查找匹配的device_node,大多數(shù)情況下,from、type為NULL。
struct device_node* of_find_node_with_property(struct device_node *from,const char *prop_name)
根據(jù)節(jié)點(diǎn)屬性的name在全局鏈表of_allnodes中查找匹配的device_node
struct device_node* of_find_node_by_phandle(phandle handle)
根據(jù)phandle在全局鏈表of_allnodes中查找匹配的device_node
雜:
void __iomem* of_iomap(struct device_node *node, int index);
通過(guò)設(shè)備結(jié)點(diǎn)直接進(jìn)行設(shè)備內(nèi)存區(qū)間的 ioremap(),index是內(nèi)存段的索引。若設(shè)備結(jié)點(diǎn)的reg屬性有多段,可通過(guò)index標(biāo)示要ioremap的是哪一段,只有1段的情況,index為0
unsigned long __init of_get_flat_dt_root(void)
用來(lái)查找在dtb中的根節(jié)點(diǎn),好像返回的都是0
int of_alias_get_id(struct device_node *np, const char *stem)
獲取節(jié)點(diǎn)np對(duì)應(yīng)的aliasid號(hào)
struct device_node* of_node_get(struct device_node *node)
void of_node_put(struct device_node *node)
device node計(jì)數(shù)增加/減少
const struct of_device_id* of_match_node(const struct of_device_id *matches,const struct device_node*node)
將matches數(shù)組中of_device_id結(jié)構(gòu)的name和type與device node的compatible和type匹配,返回匹配度最高的of_device_id結(jié)構(gòu)
platform_device和resource相關(guān):
int of_address_to_resource(struct device_node *dev, int index,struct resource *r)
根據(jù)設(shè)備節(jié)點(diǎn)dev的reg屬性值,填充資源結(jié)構(gòu)體r。Index參數(shù)指明了使用reg屬性中第幾個(gè)屬性值,一般設(shè)置為0,表示第一個(gè)。
struct platform_device* of_device_alloc(struct device_node *np,const char *bus_id,struct device *parent)
根據(jù)device node,bus_id以及父節(jié)點(diǎn)創(chuàng)建該設(shè)備的platform_device結(jié)構(gòu),同時(shí)會(huì)初始化它的resource成員。
int of_platform_bus_probe(struct device_node *root,const struct of_device_id *matches,struct device *parent)
遍歷of_allnodes中的節(jié)點(diǎn)掛接到of_platform_bus_type總線(xiàn)上,由于此時(shí)of_platform_bus_type總線(xiàn)上還沒(méi)有驅(qū)動(dòng),所以此時(shí)不進(jìn)行匹配
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中的所有節(jié)點(diǎn),生成并初始化所以節(jié)點(diǎn)的platform_device結(jié)構(gòu)
struct platform_device* of_find_device_by_node(struct device_node *np)
根據(jù)device_node查找返回該設(shè)備對(duì)應(yīng)的platform_device結(jié)構(gòu)
總結(jié)
以上是生活随笔為你收集整理的linux 设备数 of,linux下devicetree中惯用的of函数的全部?jī)?nèi)容,希望文章能夠幫你解決所遇到的問(wèn)題。
- 上一篇: Saprk排序
- 下一篇: Codeforces Round #69