![](https://csdnimg.cn/release/download_crawler_static/86318018/bg5.jpg)
1.2.6 添加驱动描述信息
在驱动代码中我们需要添加 LICENSE 信息和作者信息等驱动描述信息,其中 LICENSE 是
必须添加的,方法如下:
MODULE_LICENSE("GPL");
现在我们已经知道了注册驱动入口和出口函数、注册和注销字符设备、需要实现的设备
操作函数,大致可以写出如下的框架:
1. /* 驱动名称 */
2. #define DEVICE_NAME "gpio_leds"
3. /* 驱动主设备号 */
4. #define GPIO_LED_MAJOR 200
5.
6. /* open 函数实现, 对应到 Linux 系统调用函数的 open 函数 */
7. static int gpio_leds_open(struct inode *inode_p, struct file *file_p)
8. {
9. return 0;
10. }
11.
12. /* write 函数实现, 对应到 Linux 系统调用函数的 write 函数 */
13. static ssize_t gpio_leds_write(struct file *file_p, const char __user *buf, size_t len, lof
f_t *loff_t_p)
14. {
15. return 0;
16. }
17.
18. /* release 函数实现, 对应到 Linux 系统调用函数的 close 函数 */
19. static int gpio_leds_release(struct inode *inode_p, struct file *file_p)
20. {
21. return 0;
22. }
23.
24. /* file_operations 结构体声明, 是上面 open、write 实现函数与系统调用函数对应的关键 */
25. static struct file_operations gpio_leds_fops = {
26. .owner = THIS_MODULE,
27. .open = gpio_leds_open,
28. .write = gpio_leds_write,
29. .release = gpio_leds_release,
30. };
31.
32. /* 模块加载时会调用的函数 */
33. static int __init gpio_led_init(void)
34. {
35. int ret;