driver.c:

#include <linux/kernel.h>
#include <linux/module.h>
#include <linux/init.h>
#include <linux/types.h>
#include <linux/device.h>
#include <linux/platform_device.h> #define DRIVER_NAME "my_dev" static int my_probe(struct device *dev)
{
printk("driver found device !!\n");
return ;
} static int my_remove(struct device *dev)
{
printk("driver found device unpluged !!\n");
return ;
} struct platform_driver my_driver={
.probe=my_probe,
.remove=my_remove,
.driver={ //platform_driver内嵌device_driver
.owner=THIS_MODULE,
.name =DRIVER_NAME,//最重要的是对name的赋值,因为在匹配的时候要用!!!!
},
}; static int __init my_driver_init(void)
{
int ret =; /*注册平台驱动*/
ret=platform_driver_register(&my_driver); return ret;
} static void __exit my_driver_exit(void)
{
/*注销平台驱动*/
platform_driver_unregister(&my_driver);
} MODULE_AUTHOR("mhb@SEU");
MODULE_LICENSE("GPL"); module_init(my_driver_init);
module_exit(my_driver_exit);

device.c:

#include <linux/kernel.h>
#include <linux/module.h>
#include <linux/init.h>
#include <linux/types.h>
#include <linux/platform_device.h>
#include <linux/device.h> #define DEVICE_NAME "my_dev" struct platform_device *my_device; static int __init my_device_init(void)
{
int ret=; /*分配结构体内存*/
my_device=platform_device_alloc(DEVICE_NAME,-); /*注册平台设备*/
ret=platform_device_add(my_device);//在platform_device_alloc中已经init了,所以调用add而不是register
if(ret)
platform_device_put(my_device);/*注册失败,释放相关内存*/ return ret;
} static void __exit my_device_exit(void)
{
platform_device_unregister(my_device);
} MODULE_AUTHOR("mhb@SEU");
MODULE_LICENSE("GPL"); module_init(my_device_init);
module_exit(my_device_exit);

platform平台设备驱动简化示例代码的更多相关文章

  1. 【总结】设备树对platform平台设备驱动带来的变化(史上最强分析)【转】

    本文转载自:http://blog.csdn.net/fengyuwuzu0519/article/details/74375086 版权声明:本文为博主原创文章,转载请注明http://blog.c ...

  2. Linux Platform devices 平台设备驱动

    设备总线驱动模型:http://blog.csdn.net/lizuobin2/article/details/51570196 本文主要参考:http://www.wowotech.net/devi ...

  3. Linux驱动之平台设备驱动模型简析(驱动分离分层概念的建立)

    Linux设备模型的目的:为内核建立一个统一的设备模型,从而有一个对系统结构的一般性抽象描述.换句话说,Linux设备模型提取了设备操作的共同属性,进行抽象,并将这部分共同的属性在内核中实现,而为需要 ...

  4. 字符设备驱动、平台设备驱动、设备驱动模型、sysfs的比较和关联

    转载自:http://www.kancloud.cn/yueqian_scut/emlinux/106829 学习Linux设备驱动开发的过程中自然会遇到字符设备驱动.平台设备驱动.设备驱动模型和sy ...

  5. 【Linux高级驱动】平台设备驱动机制的编程流程与编译进内核

    [平台设备驱动机制的编程流程] [如何将驱动静态的编译进内核镜像] 1.添加资源(dev-led.c) 1.1:一般来说,系统习惯上将资源放在arch/arm/plat-samsung/目录中 cp ...

  6. [kernel]字符设备驱动、平台设备驱动、设备驱动模型、sysfs几者之间的比较和关联

    转自:http://www.2cto.com/kf/201510/444943.html Linux驱动开发经验总结,绝对干货! 学习Linux设备驱动开发的过程中自然会遇到字符设备驱动.平台设备驱动 ...

  7. 嵌入式Linux驱动学习之路(十七)驱动程序分层分离概念-平台设备驱动

    平台设备驱动: 包含BUS(总线).DEVICE.DRIVER. DEVICE:硬件相关的代码 DRIVER:比较稳定的代码 BUS有一个driver链表和device链表. ①把device放入bu ...

  8. 【Linux高级驱动】linux设备驱动模型之平台设备驱动机制

    [1:引言: linux字符设备驱动的基本编程流程] 1.实现模块加载函数  a.申请主设备号    register_chrdev(major,name,file_operations);  b.创 ...

  9. Linux中总线设备驱动模型及平台设备驱动实例

    本文将简要地介绍Linux总线设备驱动模型及其实现方式,并不会过多地涉及其在内核中的具体实现,最后,本文将会以平台总线为例介绍设备和驱动程序的实现过程. 目录: 一.总线设备驱动模型总体介绍及其实现方 ...

随机推荐

  1. 优化 MySQL 中的分页

    英文:Robert Eisele 译者:Giraffe 链接:http://yemengying.com/2016/05/28/optimized-pagiantion-mysql/ 一道面试的问题, ...

  2. java_类泛型基本实例

    package ming; public class Apple2<T> { public T info; public Apple2(T info) { this.info = info ...

  3. C#_delegate EndInvoke

    using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.T ...

  4. 查看MAC系统JRE和JDK版本

    经常有些软件有JRE或者JDK的版本要求,但怎么查询MAC上现在的JRE或JDK的版本呢?很简单,用这两个命令 这个是查询JRE的版本: $ java -version java version &q ...

  5. 【转】Split strings the right way – or the next best way

      I know many people are bored of the string splitting problem, but it still seems to come up almost ...

  6. Linux操作系统的简单认识

    1:Linux操作系统的历史 Linux操作系统是由unix操作系统发展而来的,但是Unix是收费的系统,而Linux操作系统的免费的,开源的,所以使用比较广泛,但是它是基于命令行的,不提供图形化用户 ...

  7. Vim 的补全模式加速器,轻松玩转全部 15 种自动补全模式

    1. 关于 Vim 补全模式    ---- Vim 一共提供了 15 种自动补全的模式(:help ins-completion).其中有两种的补全列表内容与另外两种相同,只是排序不同,这 15 种 ...

  8. hibernate--could not initialize proxy - no Session--懒加载问题

    今天在学习hibernate时,出现了以下错误: 错误分析: 如果我们取单个对象可以用get方法没有问题:但是如果我们取的的对象还有关联对象时用get就有问题,因为它不会把关联的对象取出来 参考博客: ...

  9. powerdesign设置实体显示格式

    工具-显示参数选择中,如下图:

  10. Oracle笔记(三)单行函数

    -函数 函数像一个黑盒子一样(看不到里边的构造),有参数返回值,可以为我们完成一定的功能. -单行 这种函数会对结果中的每一行计算一次,每行返回一个结果,单行概念区别于分组函数. 单行函数主要分为以下 ...