在driver文件中添加sysfs节点供debug用

来源:互联网 发布:国内经济数据 编辑:程序博客网 时间:2024/04/28 15:21
首先
static ssize_t switch_glove_mode_show(struct device *dev, struct device_attribute *attr, char *buf)
{
return sprintf(buf, "%d \n", ftxxxx_ts->glove_mode_eable);
}

static ssize_t switch_dclick_mode_store(struct device *dev, struct device_attribute *attr, const char *buf, size_t count)
{
int tmp = 0;
tmp = buf[0] - 48;
if (tmp == 0) {
ftxxxx_ts->dclick_mode_eable = false;
printk("[Focal][Touch] dclick_mode_disable ! \n");
} else if (tmp == 1) {
ftxxxx_ts->dclick_mode_eable = true;
printk("[Focal][Touch] dclick_mode_enable ! \n");
}

return count;

}

static DEVICE_ATTR(glove_mode, Focal_RW_ATTR, switch_glove_mode_show, switch_glove_mode_store);


static struct attribute *ftxxxx_attributes[] = {
   ......
   &dev_attr_glove_mode.attr,
   ......
   NULL
}


static struct attribute_group ftxxxx_attribute_group = {
.attrs = ftxxxx_attributes
};


static struct kobject *android_touch_kobj; /* Sys kobject variable*/

int ftxxxx_create_sysfs(struct i2c_client * client) //这个函数被probe函数调用,这个client参数是从probe中传入的
{
int err;
G_Client = client;
err = sysfs_create_group(&client->dev.kobj, &ftxxxx_attribute_group);
if (0 != err) {

sysfs_remove_group(&client->dev.kobj, &ftxxxx_attribute_group);
return -EIO;

android_touch_kobj = kobject_create_and_add("android_touch", NULL);

if (sysfs_create_file(android_touch_kobj, &dev_attr_ftsfwupgradeapp.attr)) {
printk("[Focal][TOUCH_ERR] : create_file ftsfwupgradeapp failed\n");
return -1;
}

HidI2c_To_StdI2c(client);
return err;
}


int ftxxxx_remove_sysfs(struct i2c_client * client)
{
sysfs_remove_group(&client->dev.kobj, &ftxxxx_attribute_group);
return 0;

}


使用DEVICE_ATTR,可以在sys fs中添加“文件”,通过修改该文件内容,可以实现在运行过程中动态控制device的目的。
类似的还有DRIVER_ATTR,BUS_ATTR,CLASS_ATTR。
这几个东东的区别就是,DEVICE_ATTR对应的文件在/sys/devices/目录中对应的device下面。
而其他几个分别在driver,bus,class中对应的目录下。

0 0
原创粉丝点击