【Linux内核驱动】基于platform总线的miscdevice驱动(LED)
来源:互联网 发布:mac找不到图片文件夹 编辑:程序博客网 时间:2024/06/06 01:45
驱动模块编写步骤:
- 查找并调用所需的内核函数,同时为所需的结构体命名
- 补全所需的结构体,使用vim -t查找结构体声明
- 通过结构体声明所在的文件补全头文件
#include <linux/kernel.h>#include <linux/module.h>#include <linux/platform_device.h>#include <linux/miscdevice.h>#include <linux/gpio.h> //gpio_request#include <plat/gpio-cfg.h> //s3c_gpio_cfgpin#include <mach/gpio.h> //GPIO 宏 #include <linux/fs.h>#define DRIVER_NAME "led_test"#define DEVICE_NAME "led_dev"MODULE_LICENSE("Dual BSD/GPL");MODULE_AUTHOR("colorfulshark@hotmail.com");//避免出现struct declared inside parameter liststruct platform_deivce;struct miscdevice;static int led_plat_probe(struct platform_device *pdev);static int led_plat_remove(struct platform_deivce *pdev);struct platform_driver led_pdri = { .probe = led_plat_probe, .remove = led_plat_remove, .driver = { .name = DRIVER_NAME, .owner = THIS_MODULE, }};static int led_open(struct inode *inode, struct file *filp);static int led_release(struct inode *inode, struct file *filp);static long led_ioctl(struct file *filp, unsigned int cmd, unsigned int arg);struct file_operations led_fops = { .open = led_open, .release = led_release, .unlocked_ioctl = led_ioctl,};struct miscdevice led_mdev = { .minor = 10, .name = DEVICE_NAME, .fops = &led_fops,};/*define file operation functions*/static int led_open(struct inode *inode, struct file *filp){ printk("led open\n"); return 0;}static int led_release(struct inode *inode, struct file *filp){ printk("led release\n"); return 0;}static long led_ioctl(struct file *filp, unsigned int cmd, unsigned int arg){ printk("led ioctl\n"); switch(cmd) { case 0: gpio_set_value(EXYNOS4_GPL2(0), 0); break; case 1: gpio_set_value(EXYNOS4_GPL2(0), 1); break; default: printk("wrong cmd\n"); } return 0;}/*define platform driver functions*/static int led_plat_probe(struct platform_device *pdev){ int error; printk("led platform driver probe\n"); error = gpio_request(EXYNOS4_GPL2(0), "led1"); if(error < 0) goto err_gpio_request; s3c_gpio_cfgpin(EXYNOS4_GPL2(0), S3C_GPIO_OUTPUT); misc_register(&led_mdev); return 0;err_gpio_request: printk("fail to request gpio\n"); return error;}static int led_plat_remove(struct platform_deivce *pdev){ printk("led platform driver remove\n"); misc_deregister(&led_mdev); gpio_free(EXYNOS4_GPL2(0)); return 0;}static int led_mod_init(void){ int error; printk("led module init\n"); printk("register led platform driver\n"); error = platform_driver_register(&led_pdri); if(error < 0) goto error_register_platform_driver; printk("register platform driver success\n"); return 0;error_register_platform_driver: printk("fail to register platform driver\n"); return -1;}static void led_mod_exit(void){ printk("led module exit\n"); printk("unregister led platform driver\n"); platform_driver_unregister(&led_pdri);}module_init(led_mod_init);module_exit(led_mod_exit);
阅读全文
0 0
- 【Linux内核驱动】基于platform总线的miscdevice驱动(LED)
- 基于linux platform总线的LED驱动
- 基于platform总线的ok6410 LED 驱动
- Linux下基于Platform总线led驱动学习(一)
- 基于platform总线的mini2440的led设备驱动例子
- 基于platform驱动模型的LED驱动
- 基于platform总线的驱动分析
- 基于linux2.6.30.4和s3c2440的 platform总线 led驱动
- Linux下基于Platform的led驱动(二)——测试
- 基于S3C2440的嵌入式Linux驱动——DS18B20温度传感器(添加使用platform总线机制)
- 基于S3C2440的嵌入式Linux驱动——DS18B20温度传感器(添加使用platform总线机制)
- 基于S3C2440的嵌入式Linux驱动——DS18B20温度传感器(添加使用platform总线机制)
- linux内核驱动:TQ2440的LED驱动
- Linux驱动下的platform总线架构
- Linux驱动下的platform总线架构
- Linux下的platform总线驱动
- Linux下的Platform总线驱动
- Linux下的platform总线驱动
- HDOJ 1016 Prime Ring Problem(DFS深度优先搜索)
- STM32加密库—ECC,ECDSA相关
- 第八章El表达式第四节el表达式对象操作
- pandas reshape
- 迭代器失效的总结
- 【Linux内核驱动】基于platform总线的miscdevice驱动(LED)
- 树莓派
- 启动本地项目方法
- spark 编译安装
- tomcat6-源码分析(2)
- mysql的event schedule 可以让你设置你的mysql数据库再某段时间执行你想要的动作【mysql事件调度器】
- ICSE 2017 Do Developers Read Compiler Error Messages? 阅读笔记
- H5PostMessages实现跨页面通信
- Netty浅析