dev_t dev_num;
struct file_operations fops =
{
.open = //define function
.read = //define function
.write = //define function
};
struct cdev dev;
demo_init()
{
MKDEV();
cdev_init();
cdev_add();
register_chrdev_region();
//class_create();
//device_create();
}
demo_exit()
{
//init的反向操作
}
module_init(demo_init); //注册函数
module_exit(demo_exit); //注销函数
MODULE_LISENCE("GPL"); //许可证声明
IOCTL函数接口调用
应用层:????????????????ioctl(fd, cmd, ...);
驱动程序:????????????ioctl(struct file, unsigned int, unsigned long);
cmd | 幻数 | 方向 | 序号 | (类型)大小 |
8bit | 2bit | 8bit | 14bit | |
Led | ‘x’ | 0 | ||
Adc
|
‘y’
|
100
| ||
101 |
struct platform_device {
const char * name; //匹配的名字
int id; // -1
struct device dev;
u32 num_resources; //资源数
struct resource * resource; //资源
struct platform_device_id *id_entry; //匹配的id
/* arch specific additions */
struct pdev_archdata archdata;
};
struct resource {
resource_size_t start;
resource_size_t end;
const char *name;
unsigned long flags;
struct resource *parent, *sibling, *child;
};
extern int platform_device_register(struct platform_device *);
extern void platform_device_unregister(struct platform_device *);
struct platform_driver {
int (*probe)(struct platform_device *);
int (*remove)(struct platform_device *);
void (*shutdown)(struct platform_device *);
int (*suspend)(struct platform_device *, pm_message_t state);
int (*resume)(struct platform_device *);
struct device_driver driver; // ------匹配的名字 ->name
struct platform_device_id *id_table; //匹配的id
};
extern int platform_driver_register(struct platform_driver *);
extern void platform_driver_unregister(struct platform_driver *);