常用的of API

判断设备结点的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,类型为8163264位整型数组的属性

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段的情况,index0

采用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);

猜你喜欢

转载自www.cnblogs.com/liushuhe1990/p/9704119.html