(十三)Linux sysfs device_attribute
/***************************************************************************
* Linux sysfs device_attribute
* 声明:
* 本文主要是记录linux驱动中如何在sysfs中生成设备属性。
*
**************************************************************************/ static ssize_t show_firmware_version(struct device *dev, <----------+
struct device_attribute *attr, char *buf) |
{ |
struct bq27x00_device_info *di = dev_get_drvdata(dev); |
int ver; |
|
ver = bq27x00_battery_read_fw_version(di); |
|
return sprintf(buf, "%d\n", ver); |
} |
|
static ssize_t show_dataflash_version(struct device *dev, <----------*-+
struct device_attribute *attr, char *buf) | |
{ | |
struct bq27x00_device_info *di = dev_get_drvdata(dev); | |
int ver; | |
| |
ver = bq27x00_battery_read_dataflash_version(di); | |
| |
return sprintf(buf, "%d\n", ver); | |
} | |
| |
static ssize_t show_device_type(struct device *dev, <-----------*-*-+
struct device_attribute *attr, char *buf) | | |
{ | | |
struct bq27x00_device_info *di = dev_get_drvdata(dev); | | |
int dev_type; | | |
| | |
dev_type = bq27x00_battery_read_device_type(di); | | |
| | |
return sprintf(buf, "%d\n", dev_type); | | |
} | | |
| | |
static ssize_t show_reset(struct device *dev, <----------*-*-*-+
struct device_attribute *attr, char *buf) | | | |
{ | | | |
struct bq27x00_device_info *di = dev_get_drvdata(dev); | | | |
| | | |
bq27x00_battery_reset(di); | | | |
| | | |
return sprintf(buf, "okay\n"); | | | |
} | | | |
| | | |
static DEVICE_ATTR(fw_version, S_IRUGO, show_firmware_version, NULL); <------+ | | |
static DEVICE_ATTR(df_version, S_IRUGO, show_dataflash_version, NULL); <------|-+ | |
static DEVICE_ATTR(device_type, S_IRUGO, show_device_type, NULL); <------|-|-+ |
static DEVICE_ATTR(reset, S_IRUGO, show_reset, NULL); <------|-|-|-+
| | | |
static struct attribute *bq27x00_attributes[] = { <---------+ | | | |
&dev_attr_fw_version.attr, ---------*-----+ | | |
&dev_attr_df_version.attr, ---------*-------+ | |
&dev_attr_device_type.attr, ---------*---------+ |
&dev_attr_reset.attr, ---------*-----------+
NULL |
}; |
|
static const struct attribute_group bq27x00_attr_group = { <---------*------+
.attrs = bq27x00_attributes, ------+ |
}; |
|
static int __init bq27x00_battery_probe(struct i2c_client *client, |
const struct i2c_device_id *id) |
{ |
...... |
retval = sysfs_create_group(&client->dev.kobj, &bq27x00_attr_group); -------+
if (retval)
dev_err(&client->dev, "could not create sysfs files\n"); return ;
......
} /**
* root@android:/sys/bus/i2c/devices/2-0055 # ls
* device_type
* df_version
* driver
* fw_version
* modalias
* name
* power
* power_supply
* reset
* subsystem
* uevent
* root@android:/sys/bus/i2c/devices/2-0055 #
*/
(十三)Linux sysfs device_attribute的更多相关文章
- Linux sysfs device_attribute
/*************************************************************************** * Linux sysfs device_at ...
- [knowledge][linux][sysfs] sysfs文件系统
https://en.wikipedia.org/wiki/Sysfs http://man7.org/linux/man-pages/man5/sysfs.5.html https://www.ke ...
- SpringBoot进阶教程(二十三)Linux部署Quartz
在之前的一篇文章中<SpringBoot(九)定时任务Schedule>,已经详细介绍了关于schedule框架的配置和使用,有收到一些朋友关于部署的私信,所以抽时间整理一个linux部署 ...
- linux sysfs文件系统
个人理解:sysfs向用户空间展示了驱动设备的层次结构.我们都知道设备和对应的驱动都是由内核管理的,这些对于用户空间是不可见的.现在通过sysfs,可以在用户空间直观的了解设备驱动的层次结构. 我们来 ...
- Linux设备管理(四)_从sysfs回到ktype
sysfs是一个基于ramfs的文件系统,在2.6内核开始引入,用来导出内核对象(kernel object)的数据.属性到用户空间.与同样用于查看内核数据的proc不同,sysfs只关心具有层次结构 ...
- Linux设备管理(四)_从sysfs回到ktype【转】
转自:https://www.cnblogs.com/xiaojiang1025/archive/2016/12/21/6202298.html sysfs是一个基于ramfs的文件系统,在2.6内核 ...
- Linux设备管理(五)_写自己的sysfs接口
我们在Linux设备管理(一)_kobject, kset,ktype分析一文中介绍了kobject的相关知识,在Linux设备管理(二)_从cdev_add说起和Linux设备管理(三)_总线设备的 ...
- linux设备驱动程序--sysfs用户接口的使用
linux sysfs文件系统 本文部分内容参考自官方文档 自2.6版本开始,linux内核开始使用sysfs文件系统,它的作用是将设备和驱动程序的信息导出到用户空间,方便了用户读取设备信息,同时支持 ...
- Linux 内核 低级 sysfs 操作
kobject 是在 sysfs 虚拟文件系统之后的机制. 对每个在 sysfs 中发现的目录, 有一个 kobject 潜伏在内核某处. 每个感兴趣的 kobject 也输出一个或多个属性, 它出现 ...
随机推荐
- (转载)详解Javascript中prototype属性(推荐)
在典型的面向对象的语言中,如java,都存在类(class)的概念,类就是对象的模板,对象就是类的实例.但是在Javascript语言体系中,是不存在类(Class)的概念的,javascript中不 ...
- java中,有关移位运算符的有关讨论
java中有三种移位运算符 << : 左移运算符,num << 1,相当于num乘以2 >> : 右移运算符,num >& ...
- HTML基础知识自学教程
HTML 是用来描述网页的一套标记标签,是我们在web前端开发中的基础.下面PHP程序员雷雪松主要结合自己的经验给大家分享下HTML的基础知识,以及在自学过程中一些比较常用的和重要的HTML知识点. ...
- 【CodeForces - 598D】Igor In the Museum(bfs)
Igor In the Museum Descriptions 给你一个n*m的方格图表示一个博物馆的分布图.每个方格上用'*'表示墙,用'.'表示空位.每一个空格和相邻的墙之间都有一幅画.(相邻指的 ...
- Kubernetes 相关镜像pull 不下来问题收集
1. 可在相关的镜像前添加 keveon 或者 mirrorgooglecontainers 就可以下载镜像, 然后在修改 tag docker pull mirrorgooglecontainers ...
- IntelliJ IDEA打jar时常遇见的问题
1.打包的时候提示 manifest.mf already exists in vfs 解决方案:这个文件夹删除掉,再重新build打包即可 2. 第一个选择“extract to the targ ...
- Node流操作(启动器forever)
详情: https://www.cnblogs.com/lalalagq/p/9749680.html 流:读取流,写入流,双向读写流. 读写流——压缩.加密 数据库不能直接接受流 sf.readFi ...
- [bzoj3162]独钓寒江雪_树hash_树形dp
独钓寒江雪 题目链接:https://www.lydsy.com/JudgeOnline/problem.php?id=3162 题解: 首先,如果没有那个本质相同的限制这就是个傻逼题. 直接树形dp ...
- [转帖]【架构系列】龙芯loongson简介
[架构系列]龙芯loongson简介 https://blog.csdn.net/SoaringLee_fighting/article/details/97759305 2019年07月30日 10 ...
- [转帖]LINUX网络配置---nmtui&nmcli
LINUX网络配置---nmtui&nmcli https://blog.51cto.com/13625527/2151853?source=dra 两年前曾经打打印过 几页命令 里面就有 n ...