/***************************************************************************
* Linux sysfs device_attribute
* 声明:
* 本文主要是记录linux驱动中如何在sysfs中生成设备属性。
*
* 2016-2-22 深圳 南山平山村 曾剑锋
**************************************************************************/ 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. linux sysfs文件系统

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

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

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

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

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

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

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

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

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

  8. Linux 内核 低级 sysfs 操作

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

  9. linux设备驱动归纳总结(八):1.总线、设备和驱动【转】

    本文转载自:http://blog.chinaunix.net/uid-25014876-id-109733.html linux设备驱动归纳总结(八):1.总线.设备和驱动 xxxxxxxxxxxx ...

随机推荐

  1. lua5.3调用C/C++

    马上面临毕业设计,打算做点跟网游有关的,先从做周边工具开始,目前正在做一个协议序列化和反序列化的东西,广告一波先: https://github.com/Anti-Magic/rproto 目前非常简 ...

  2. iOS 基础 第四天(0809)

    0809 - 内存管理,只对oc对象生效. alloc.retain.release.retainCount 局部变量是放在栈里面的,oc对象是放在堆里面的.栈里面的内容系统自动回收,而堆里面的内容还 ...

  3. Spring Aop实例之xml配置

    AOP的配置方式有2种方式:xml配置和AspectJ注解方式.今天我们就来实践一下xml配置方式. 我采用的jdk代理,所以首先将接口和实现类代码附上 package com.tgb.aop; pu ...

  4. 在百万数据中找出重复的数据sql

    select * from (select count(name) as isone, name from tbl_org_departments group by name) t where t.i ...

  5. maven+tomcat6-maven-plugin实现热部署及调试

    maven project,特别是maven module项目默认情况下是是无法直接通过tomcat等容器部署的,如图,我要部署fastdev_web这个maven module,可以看出在tomca ...

  6. JAVA CAS单点登录(SSO) 教程

    一.教程前言 教程目的:从头到尾细细道来单点登录服务器及客户端应用的每个步骤 单点登录(SSO):请看百科解释猛击这里打开 本教程使用的SSO服务器是Yelu大学研发的CAS(Central Auth ...

  7. Exploring the 7 Different Types of Data Stories

    Exploring the 7 Different Types of Data Stories What makes a story truly data-driven? For one, the n ...

  8. NIO的Selector

    参考自 Java NIO系列教程(六) Selector Java-NIO-Selector java.nio.channels.Selector NIO新功能Top 10(下) 出发点: 如何管理多 ...

  9. IIC驱动分析

    IIC设备是一种通过IIC总线连接的设备,由于其简单性,被广泛引用于电子系统中.在现代电子系统中,有很多的IIC设备需要进行相互之间通信 IIC总线是由PHILIPS公司开发的两线式串行总线,用于连接 ...

  10. 获取Android系统时间

    目的: 输入 2014-09-09 14:02:03    输出 等待:1小时20分 注意: HH:mm:ss 为获取手机 24小时格式的时间  15:03    hh:mm:ss 为12小时模式的时 ...