七、linux驱动注册
一、驱动注册结构体
驱动注册使用结构体platform_driver,该结构体在头文件“vim include/linux/platform_device.h”中,和刚刚那个设备注册的驱动在同一个头文件。
- 驱动注册platform_driver_register
- 驱动卸载函数platform_driver_unregister
也在这个头文件中,这两个函数的参数都只有结构体platform_driver
驱动常见的几种状态,初始化,移除,休眠,复位
就像PC一样,有的驱动休眠之后无法使用,有的可以使用;有的系统唤醒之后,驱动需要重新启动才能正常工作,也有直接就可以使用等等
• probe函数
– platform_match函数匹配之后,驱动调用的初始化函数
• remove函数
– 移除驱动函数
• suspend函数
– 悬挂(休眠)驱动函数
• resume函数
– 休眠后恢复驱动
• device_driver数据结构的两个参数
– name和注册的设备name要一致
– owner一般赋值THIS_MODULE
二、驱动源码
我们在前面最小驱动的代码基础上修改,主要实现platform_driver结构体中定义的函数,然后再通过platform_driver_register和platform_driver_unregister注册和卸载:
#include <linux/init.h>
#include <linux/module.h>/*驱动注册的头文件,包含驱动的结构体和注册和卸载的函数*/
#include <linux/platform_device.h>#define DRIVER_NAME "hello_ctl"MODULE_LICENSE("Dual BSD/GPL");
MODULE_AUTHOR("TOPEET");static int hello_probe(struct platform_device *pdv){printk(KERN_EMERG "\tinitialized\n");return 0;
}static int hello_remove(struct platform_device *pdv){return 0;
}static void hello_shutdown(struct platform_device *pdv){;
}static int hello_suspend(struct platform_device *pdv){return 0;
}static int hello_resume(struct platform_device *pdv){return 0;
}struct platform_driver hello_driver = {.probe = hello_probe,.remove = hello_remove,.shutdown = hello_shutdown,.suspend = hello_suspend,.resume = hello_resume,.driver = {.name = DRIVER_NAME,.owner = THIS_MODULE,}
};static int hello_init(void)
{int DriverState;printk(KERN_EMERG "HELLO WORLD enter!\n");DriverState = platform_driver_register(&hello_driver); // 注册驱动printk(KERN_EMERG "\tDriverState is %d\n",DriverState);return 0;
}static void hello_exit(void)
{printk(KERN_EMERG "HELLO WORLD exit!\n");platform_driver_unregister(&hello_driver); // 注销驱动
}module_init(hello_init);// 模块入口
module_exit(hello_exit);
运行如下:当遇到驱动无法卸载时,请按照下面操作解决
七、linux驱动注册相关推荐
- linux驱动篇之 driver_register 过程分析(一)
linux驱动注册过程分析--driver_register(一) 个人笔记,欢迎转载,请注明出处,共同分享 共同进步 http://blog.csdn.net/richard_liujh/artic ...
- Linux驱动——sd type card(七)
Linux驱动--sd type card(七) 备注: 1. Kernel版本:5.4 2. 使用工具:Source Insight 4.0 3. 参考博客: [mmc subsyste ...
- 五、linux总线中设备和驱动注册流程详解
一.注册流程图( 建议大家先看这张图3分钟. ) 由上图可以看出,linux中,有各种总线(bus),其中的平台总线(platform)是我们字符设备和驱动注册的地方.通过platform_devic ...
- linux设备和驱动注册,Linux驱动第五篇-----驱动注册和生成设备节点
加载驱动的指令是:insmod xx.ko 查看驱动的指令是: lsmod 卸载驱动的指令是:rmmod xx 在include/linux/platform_device.h这个文件中定义了平台驱动 ...
- Linux驱动(10)--注册驱动
注册驱动 1. 注册驱动所使用的结构体 2. 注册驱动的源文件 3. 注册驱动的步骤 1. 注册驱动所使用的结构体 驱动注册所使用的结构体是platform_driver,在文件: /LinuxKer ...
- Linux驱动(9)--注册设备
注册设备 1. 总线设备驱动注册流程 2. 以内核的方式注册设备 3. 以module的方式注册设备 4. 注意 1. 总线设备驱动注册流程 Linux下的总线设备驱动注册流程如下图所示: ① Lin ...
- Linux驱动之----Linux2.6方式设备注册
Linux2.6方式设备注册API 杂项设备注册和经典设备注册方法可参考我前俩篇博客 Linux驱动之----杂项设备注册 Linux驱动之----经典方式注册 在linux2.6里面设备号的申请方式 ...
- 嵌入式开发--STM32上实现驱动注册initcall机制(类linux)
一.前言 上一节我们实现了代码应用层和硬件层的分离管理,但是代码中还存在一个问题,每个硬件如LED控制,GPIO口需要初始化,初始化函数bsp_led_init();这个函数需要在主函数中调用初始化, ...
- Linux驱动开发 -- touch驱动注册
Linux i2c驱动开发 – touch 驱动 文章目录 Linux i2c驱动开发 -- touch 驱动 前言 一.i2c 驱动框架 二.Linux的MODULE声明 1. MODULE相关声明 ...
最新文章
- Python - 移除List中重复项的五种常用方法
- matlab的基础使用
- 在JSP客户端限制表单重复提交
- 【RL】快速强化学习实战案例
- seo从入门到精通_SEO入门到精通(七):SEO工作的流程是什么?
- Java 14 发布了,终于可以扔掉Lombok了?
- 挑战程序设计竞赛部分题目选择排序、二分查找找出下标、深度优先算法、求三角形max周长、蚂蚁算法、操作excel
- 【Ray Tracing The Next Week 超详解】 光线追踪2-4 Perlin noise
- ACT的摘要可以告诉我们的内容
- 各型号交换机端口镜像配置方法和命令
- linux移植1.3寸oled屏幕,芯片SH1106
- ubuntu14 teamviewer使用
- nios自学笔记三:nios常用外设C函数整理
- 我是培训机构出身的程序员,不敢告诉任何人!
- Java学习体系(骨灰级详细)
- Qt学习笔记(五):菜单栏
- 服务器推送小程序,小程序之主动推送消息(订阅消息)
- 侍魂胧月传说服务器维护,12月9日停机维护更新公告
- JZOJ5952. 【NOIP2018模拟11.5A组】凯旋而归
- android m和6.0的区别吗,清甜棉花糖:安卓M/Android 6.0上手体验评测