驱动程序的描述结构体
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);//注意参数 第一个是 自己的定义驱动结构体,第二个是驱动属性文件