(十三)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 也输出一个或多个属性, 它出现 ...
随机推荐
- 权限控制(delphi actionlist)
权限控制(delphi TActionList方案)在软件开发中,为软件加入权限控制功能,使不同的用户有不同的使用权限,是非常重要的一项功能,由其在开发数据库方面的应用,这项功能更为重要.但是,要为一 ...
- Spring Boot Mybatis简单使用
Spring Boot Mybatis简单使用 步骤说明 build.gradle:依赖添加 application.properties:配置添加 代码编写 测试 build.gradle:依赖添加 ...
- appium+python+Windows自动化测试文档
appium+python自动化测试文档 一.认识appium 1. 什么是appium appium是开源的移动端自动化测试框架: appium可以测试原生的.混合的.以及移动端的web项目: ...
- MariaDB知识点总结03--从主+多主集群
一.从主架构 1.从主复制原理 从库生成两个线程,一个I/O线程,一个SQL线程: i/o线程去请求主库 的binlog,并将得到的binlog日志写到relay log(中继日志) 文件中:主库会生 ...
- web代码审计题
@题名:code i春秋https://www.ichunqiu.com/battalion wp:https://www.ichunqiu.com/writeup/detail/4139
- Python学习笔记——集合
1. 定义 num = {} print(type(num)) num2 = {1,2,3,4,5} print(type(num2)) <class 'dict'> <class ...
- C学习笔记-函数
函数的定义 返回值类型 函数名([[参数类型 参数名1],[参数类型 参数名2],···,[参数类型 参数n]]) { //执行语句 return 返回值; } 返回值类型:用于限定函数返回值的数据类 ...
- D3 GEO应用专题(一):绘制旋转的3D地球
https://gallery.echartsjs.com/explore.html#sort=rank~timeframe=all~author=all 雷达图 https://blog.csdn. ...
- Linux文件属性之用户与用户组基础知识回顾
回顾: 用户.用户组的概念: 每个文件和进程,都需要对应一个用户和用户组. linux系统通过UID和GID来识别用户和组的. 用户名相当于人名 UID和GID 身份证号 管理员:root do ...
- Elasticsearch5.x 引擎健康情况
查看引擎健康情况 [root@w]# curl -XGET "http://localhost:9200/_cat/health?v" epoch timestamp cluste ...