常用 API
常用API
1.根据compatible找到对应的devicenode结构
struct device_node*of_find_compatible_node(struct device_node *from,
constchar *type, const char *compatible)
更加full path 找到对应的device node
struct device_node*of_find_node_by_path(const char *path)
2. 在device node 中获取属性值
struct property *of_find_property(conststruct device_node *np,
const char *name,
int *lenp)
3. 检查device node的是否与compa匹配
int of_device_is_compatible(const structdevice_node *device,
constchar *compat)
4. 读取属性值
static inline intof_property_read_u32(const struct device_node *np,
const char *propname,
u32 *out_value)
5. 通过phandle引用node
struct device_node *of_parse_phandle(conststruct device_node *np,
const char *phandle_name, int index)
6.映射中断
unsigned int irq_of_
5. 使用案例
以触摸屏为来说明如何使用.
另外i2c设备必须是i2c控制器的子设备才能顺利添加到系统中.
Dts文件如下:
/{
bus{
I2C2@0x11009000{
status="okay";
#size-cells = <0>;
synaptics_touch@20{
compatible = "synaptics,touch" ;
reg= <0x20>;
touch_irq=<2>;
};
};
};
驱动中添加:
static struct i2c_driversynaptics_i2c_driver = {
.driver = {
.name = TPD_DEVICE,
.owner = THIS_MODULE,
#ifdef CONFIG_OF
.of_match_table = &of_match,
#endif
},
.probe = synaptics_rmi4_probe,
.remove = synaptics_rmi4_remove,
.id_table = tp_id,
};
static const struct of_device_id of_match[]= {
{.compatible = "synaptics,touch",},/* 要和dts中的compatible匹配*/
{/*sentinel */},
};