在driver文件中添加sysfs节点供debug用
2015-11-16 10:18
309 查看
首先
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中对应的目录下。
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中对应的目录下。
相关文章推荐
- JavaScript 数组字符互转
- storm简介
- 【Mysql】Mysql在大型网站的应用架构演变
- 几款主流PHP框架的优缺点评比
- JS开发HTML5游戏《神奇的六边形》(三)
- STL之next()函数和iota函数
- js 对html的基本操作
- [LeetCode]83. Intersection of Two Lists两条单链表的交点
- ubuntu安装64位谷歌浏览器
- matlab colormap
- 电梯层数
- PHP 底层的运行机制与原理
- [LeetCode]83. Intersection of Two Lists两条单链表的交点
- cassandra 公司内分享 ppt
- (数学)空中加油问题
- 关于数据类型与指针的小笔记--初始化问题&&数组
- 集体智慧总结和使用范围归纳(二)
- iOS字符串截取字符
- Qt使用教程之指定生成设置(三)
- C++ 动态特性