判斷設備結點的compatible 屬性是否包含compat指定的字符串
int of_device_is_compatible(const struct device_node *device,const char *compat);
根據compatible屬性,獲得設備結點
struct device_node *of_find_compatible_node(struct device_node *from,const char *type, const char *compatible);
讀取設備結點np的屬性名為propname,類型為8、16、32、64位整型數組的屬性
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); int of_property_read_u64(const struct device_node *np, const char* propname, u64 *out_value);
最常用的是of_property_read_u32_array()
有些情況下,整形屬性的長度可能為1,於是內核為了方便調用者,又在上述API的基礎上封裝出了更加簡單的讀單一整形屬性的API
static inline int of_property_read_u8(const struct device_node *np, const char *propname, u8 *out_value) { return of_property_read_u8_array(np, propname, out_value, 1); }
static inline int of_property_read_u16(const struct device_node *np, const char *propname, u16 *out_value) { return of_property_read_u16_array(np, propname, out_value, 1); }
static inline int of_property_read_u32(const struct device_node *np, const char *propname, u32 *out_value) { return of_property_read_u32_array(np, propname, out_value, 1); }
讀取字符串屬性
int of_property_read_string(struct device_node *np, const char*propname, const char **out_string);
讀取字符串數組屬性中的第index個字符串
int of_property_read_string_index(struct device_node *np, const char *propname, int index, const char **output);
如果設備結點np含有propname屬性,則返回true,否則返回false。一般用於檢查空屬性是否存在
static inline bool of_property_read_bool(const struct device_node *np,const char *propname);
通過設備結點直接進行設備內存區間的 ioremap(),index是內存段的索引。若設備結點的reg屬性有多段,可通過index標示要ioremap的是哪一段,只有1段的情況,index為0。
采用Device Tree后,大量的設備驅動通過of_iomap()進行映射,而不再通過傳統的ioremap。
void __iomem *of_iomap(struct device_node *node, int index);
透過Device Tree或者設備的中斷號,實際上是從.dts中的interrupts屬性解析出中斷號。若設備使用了多個中斷,index指定中斷的索引號。
unsigned int irq_of_parse_and_map(struct device_node *dev, int index);