***此文章只是个人学习笔记,为了以后方便随时查看,若有错误,欢迎指正,谢谢~~**
`/*需要包含以下的头文件*/
#include <linux/kernel.h>//驱动要写入内核,与内核相关的头文件
#include <linux/gpio.h>//操作系统相关的IO口文件
#include <linux/of_gpio.h>//获取 GPIO口 信息的设备树接口的相关头文件
#include <linux/of_device.h>//包含了device、class 等结构的定义
#include <linux/slab.h>//包含了kcalloc、kzalloc内存分配函数的定义。
#include <linux/delay.h> //延时头文件
#define OUTPUT_HIGH 1
#define OUTPUT_LOW 0
unsigned int usb_host0; //定义一个无符号整型的 变量
#undef __ATTR //
#define __ATTR(_name, _mode, _show, _store) {
.attr = {.name = __stringify(_name),
.mode = _mode},
.show = _show,
.store = _store,
}
/*
struct device_attribute {
struct attribute attr; // 内置的attribute 结构体
ssize_t (*show)(struct device *dev, struct device_attribute *attr, //属性文件的show方法(也就是读)
char *buf);
ssize_t (*store)(struct device *dev, struct device_attribute *attr, //属性文件的store方法(也就是写)
const char *buf, size_t count);
};
*/
/*
struct attribute { //结构体
const char *name; // 属性文件的名字
struct module *owner; // 属性文件的所有者
mode_t mode;
#ifdef CONFIG_DEBUG_LOCK_ALLOC
struct lock_class