/***************************************************************************
* 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. RabbitMQ基础总结

    MQ全称为Message Queue, 消息队列(MQ)是一种应用程序对应用程序的通信方法.应用程序通过读写出入队列的消息(针对应用程序的数据)来通信,而无需专用连接来链接它们.消 息传递指的是程序之 ...

  2. 50个C++源码学习网站

    C/C++是最主要的编程语言.这里列出了50名优秀网站和网页清单,这些网站提供c/c++源代码 .这份清单提供了源代码的链接以及它们的小说明.我已尽力包括最佳的C/C++源代码的网站.这不是一个完整的 ...

  3. Beaglebone Back学习六(Can总线测试)

    Can总线测试 1 Can总线 控制器局域网 (Controller Area Network, 简称 CAN 或 CANbus)是一种通信协议,其特点是允许网络上的设备直接互相通信,网络上不需要主机 ...

  4. 巧用system函数个性化屏幕显示

    函数名:system 功  能: 发出一个DOS命令 用  法: system("DOS命令");             (system函数需加头文件<stdlib.h&g ...

  5. Printer Queue

    Description The only printer in the computer science students' union is experiencing an extremely he ...

  6. fedora 取消自动升级

    fedora启动时经常CPU使用很高,看下进程原来是yumBackend.这是个yum的自动更新进程 只要关闭自动更新就可以了 gsettings set org.gnome.settings-dae ...

  7. C#网络编程(1)

    1.Purpose 1.什么是网络编程 2.TCP/IP协议 3.什么是套接字 4.多线程深入理解 二.Basic Concept 1.网络编程:主要实现进程(线程)相互之间的通信和基本的网络应用原理 ...

  8. EXTJS 4.2 资料 控件之Grid Columns 列renderer 绑定事件

    columns: [ { header: '序号', xtype: 'rownumberer', align: 'center', width: 100 }, { header: 'CompanyId ...

  9. Homework3

    1. 切换路径到想要保存的目录下,使用git init创建仓库: 2. 在仓库下创建文件Readme.txt,使用git add命令添加到暂存区和 git commit 命令提交到仓库: 3.  修改 ...

  10. 应该如何入门deep learning呢?从UFLDL开始!

    抱歉,大家,这里不是要分享如何学习deep learning,而是想要记录自己学习deep learning的小历程,算是给自己的一点小动力吧,希望各位业内前辈能够多多指教! 看到有网友提到,Andr ...