1.在驱动中添加sysfs文件结点
static ssize_t backlight_store(struct device *dev,
struct device_attribute *attr,
const char *buf, size_t count)
{
struct data *data = dev_get_drvdata(dev);
int ret;
int level;
u8 write_buf[4];
u8 command[4];
ret = kstrtoint(buf,10,&level);//10表示10进制
if(ret < 0)
{
dev_err(&data->client->dev,"%s failed\n");
return -EINVAL;
}
if(level < 1 || level > 100)
{
dev_err(&data->client->dev,"%s,level %d unsupported",__func__,level);
return -EINVAL;
}
````
return count;
}
static DEVICE_ATTR(backlight_control,S_IWUSR,NULL,gac_ts_backlight_store);
//最后一项必须以NUll结尾
static struct attribute *sysfs_attrs[] = {
&dev_attr_backlight_control.attr,
NULL,
};
static const struct attribute_group attr_grp = {
.attrs = sysfs_attrs,
};
static int bl_probe(struct i2c_client *client,
const struct i2c_device_id *id)
{
···
sysfs_create_group(&client->dev.kobj,&attr_grp);
````
}
生成的结点为:
/sys/devices/platform/soc/4a84000.i2c/i2c-0/0-0030/backlight_control
2.修改结点权限
在device/qcom(平台)/XXX(项目名)/init.target.rc中添加
#backlight control
chown root system /sys/devices/platform/soc/4a84000.i2c/i2c-0/0-0030/backlight_control
chmod 0666 /sys/devices/platform/soc/4a84000.i2c/i2c-0/0-0030/backlight_control