/***************************************************************************
* 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的更多相关文章

  1. Linux sysfs device_attribute

    /*************************************************************************** * Linux sysfs device_at ...

  2. [knowledge][linux][sysfs] sysfs文件系统

    https://en.wikipedia.org/wiki/Sysfs http://man7.org/linux/man-pages/man5/sysfs.5.html https://www.ke ...

  3. SpringBoot进阶教程(二十三)Linux部署Quartz

    在之前的一篇文章中<SpringBoot(九)定时任务Schedule>,已经详细介绍了关于schedule框架的配置和使用,有收到一些朋友关于部署的私信,所以抽时间整理一个linux部署 ...

  4. linux sysfs文件系统

    个人理解:sysfs向用户空间展示了驱动设备的层次结构.我们都知道设备和对应的驱动都是由内核管理的,这些对于用户空间是不可见的.现在通过sysfs,可以在用户空间直观的了解设备驱动的层次结构. 我们来 ...

  5. Linux设备管理(四)_从sysfs回到ktype

    sysfs是一个基于ramfs的文件系统,在2.6内核开始引入,用来导出内核对象(kernel object)的数据.属性到用户空间.与同样用于查看内核数据的proc不同,sysfs只关心具有层次结构 ...

  6. Linux设备管理(四)_从sysfs回到ktype【转】

    转自:https://www.cnblogs.com/xiaojiang1025/archive/2016/12/21/6202298.html sysfs是一个基于ramfs的文件系统,在2.6内核 ...

  7. Linux设备管理(五)_写自己的sysfs接口

    我们在Linux设备管理(一)_kobject, kset,ktype分析一文中介绍了kobject的相关知识,在Linux设备管理(二)_从cdev_add说起和Linux设备管理(三)_总线设备的 ...

  8. linux设备驱动程序--sysfs用户接口的使用

    linux sysfs文件系统 本文部分内容参考自官方文档 自2.6版本开始,linux内核开始使用sysfs文件系统,它的作用是将设备和驱动程序的信息导出到用户空间,方便了用户读取设备信息,同时支持 ...

  9. Linux 内核 低级 sysfs 操作

    kobject 是在 sysfs 虚拟文件系统之后的机制. 对每个在 sysfs 中发现的目录, 有一个 kobject 潜伏在内核某处. 每个感兴趣的 kobject 也输出一个或多个属性, 它出现 ...

随机推荐

  1. #dokcer部署code-server web版vscode+golang

    codercom/code-server:latest不支持插件在线安装 codercom/code-server:v2目前为最新版1. #创建 docker rm -f vscode docker ...

  2. Python中使用第三方库xlrd来写入Excel文件示例

    Python中使用第三方库xlrd来写入Excel文件示例 这一篇文章就来介绍下,如何来写Excel,写Excel我们需要使用第三方库xlwt,和xlrd一样,xlrd表示read xls,xlwt表 ...

  3. kubeadm安装集群系列-5.其他操作

    常用的一些操作记录 imagePullSecrets kubectl -n [namespace] create secret docker-registry regsecret --docker-s ...

  4. 通过火狐谋智查询API

    谋智中文版网址 https://developer.mozilla.org 示例 site: developer.mozilla.org window 通过百度高级用法查API site: 网址 搜索 ...

  5. ZOJ Problem Set - 1006

    注意:A的ascii为65,a为97就行了 其他没什么,略过. 代码参看: http://my.oschina.net/dianpaopao/blog/124545

  6. Power Management of Hybrid DRAM/PRAM-Based Main Memory

    0.ABSTRACT (1)non-volatile memory——low standby power DRAM——high performance and better active power ...

  7. 学习笔记:CentOS 7学习之十一:文件的重定向

    1.文件描述符定义 文件描述符:是内核为了高效管理已被而打开的文件所创建的缩影,用于指向被打开的文件,所有执行I/O操作的系统调用都通过文件描述符:文件描述符是一个简单的非负整数,用于标明每一个被进程 ...

  8. luoguP2634聪聪可可(点分治)

    题目链接:https://www.luogu.org/problem/P2634 题意:给一颗树,求距离的模3为0的点对数量,注意(1,1)算一个点对,(1,2)和(2,1)算两个点对. 思路:和点分 ...

  9. sqlalchemy定义mysql时间戳字段

    update_time = Column(TIMESTAMP, nullable=False, comment='更新时间戳', server_default=text('CURRENT_TIMEST ...

  10. python-open函数操作实例

    一.这个是源配置文件: global               log 127.0.0.1 local2        daemon        maxconn 256        log 12 ...