linux---device_driver驱动理论详解--bus总线高级篇

驱动程序的描述结构体

struct device_driver {
const char *name;/*驱动程序的名称*/
struct bus_type *bus;/*驱动程序所在的总线*/

struct module *owner;
const char *mod_name; /* used for built-in modules */

bool suppress_bind_attrs; /* disables bind/unbind via sysfs */

#if defined(CONFIG_OF)
const struct of_device_id *of_match_table;
#endif

int (*probe) (struct device *dev);/*驱动处理函数*/
int (*remove) (struct device *dev);
void (*shutdown) (struct device *dev);
int (*suspend) (struct device *dev, pm_message_t state);
int (*resume) (struct device *dev);
const struct attribute_group **groups;

const struct dev_pm_ops *pm;

struct driver_private *p;
};


设备驱动注册

driver_register(struct device_driver *drv);

设备驱动注销

driver_unregister(struct device_driver *drv);


驱动属性描述结构体

struct driver_attribute {
struct attribute attr;
ssize_t (*show)(struct device_driver *driver, char *buf);//读取时调用的函数
ssize_t (*store)(struct device_driver *driver, const char *buf,
size_t count);//写入的时候 调用的函数
};

但是属性文件的创建都是使用下面的这个宏来创建

#define DRIVER_ATTR(_name, _mode, _show, _store)\注意参数的意义:
struct driver_attribute driver_attr_##_name = \//根据 宏的第一个参数 来创建名为driver_attr_name的属性文件
__ATTR(_name, _mode, _show, _store)//


创建属性文件的函数

driver_create_file(struct device_driver *driver,const struct driver_attribute *attr);//注意参数 第一个是 自己的定义驱动结构体,第二个是 驱动属性文件

删除属性文件

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值