博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
Linux-3.5-Exynos4412驱动分层分离
阅读量:7176 次
发布时间:2019-06-29

本文共 3837 字,大约阅读时间需要 12 分钟。

 

linux-3.5/Documentation/driver-model/bus.txt

先写一个简单的例子,是为了给学习platform做准备。

dev.h

1 #ifndef  JASON_DEV_H_ 2 #define JASON_DEV_H_ 3  4 #include 
5 6 struct pridevice { 7 struct device device; 8 char *name; 9 };10 11 12 #endif
1 #include 
2 #include
3 #include
4 #include
5 #include
6 7 #include "dev.h" 8 9 static int mara_match(struct device *dev, struct device_driver *drv)10 {11 struct pridevice *pdev = container_of(dev, struct pridevice, device);12 13 printk("match: %s device try match %s driver...\n", pdev->name, drv->name);14 15 return !strcmp(pdev->name, drv->name );16 //返回值为1代表匹配成功,为0则失败17 }18 19 static struct bus_type demobus = {20 .name = "marathon",21 .match = mara_match,22 };23 EXPORT_SYMBOL_GPL(demobus);24 25 module_driver(demobus, bus_register, bus_unregister);26 27 MODULE_LICENSE("GPL");28 29 MODULE_AUTHOR("no name");30 MODULE_VERSION("J-15");31 MODULE_DESCRIPTION("a simple demo for driver module");
bus.c
1 #include 
2 #include
3 #include
4 #include
5 #include
6 7 #include "dev.h" 8 9 extern struct bus_type demobus;10 11 static void demo_release(struct device *dev)12 {13 struct pridevice *pdev = container_of(dev, struct pridevice, device);14 15 printk("%s device is released....\n", pdev->name);16 }17 18 static struct pridevice demodev1 = {19 .device = {20 .init_name = "spring_1", 21 .bus = &demobus,22 .release = demo_release,23 },24 .name = "spring",25 };26 27 static int demo_init1(void)28 {29 return device_register(&demodev1.device);30 }31 32 /*此宏用于指定驱动的入口函数, 内核启动或插入模块到内核时被调用*/33 module_init(demo_init1);34 35 36 static void demo_exit1(void)37 {38 device_unregister(&demodev1.device);39 }40 41 /*此宏用于指定驱动模块输出函数*/42 module_exit(demo_exit1);43 44 MODULE_LICENSE("GPL");45 46 MODULE_AUTHOR("no name");47 MODULE_VERSION("J-15");48 MODULE_DESCRIPTION("a simple demo for driver module");
dev.c
1 #include 
2 #include
3 #include
4 #include
5 #include
6 7 #include "dev.h" 8 9 extern struct bus_type demobus;10 11 static int demo_probe (struct device *dev)12 {13 /*14 当总线的match函数返回1时,则由内核调用驱动对象的probe指针指向的15 函数16 */17 18 struct pridevice *pdev = container_of(dev, struct pridevice, device);19 struct device_driver *pdrv = dev->driver;20 21 printk("probe: %s driver do %s device...\n",22 pdrv->name, pdev->name);23 24 return 0;25 }26 27 static int demo_remove (struct device *dev)28 {29 struct pridevice *pdev = container_of(dev, struct pridevice, device);30 struct device_driver *pdrv = dev->driver;31 32 printk("remove: %s driver remove %s device...\n",33 pdrv->name, pdev->name);34 35 return 0;36 }37 38 static struct device_driver demodrv1 = {39 .name = "spring",40 .bus = &demobus, 41 .probe = demo_probe,42 .remove = demo_remove,43 };44 45 module_driver(demodrv1, driver_register, driver_unregister);46 47 MODULE_LICENSE("GPL");48 49 MODULE_AUTHOR("no name");50 MODULE_VERSION("J-15");51 MODULE_DESCRIPTION("a simple demo for driver module");
drv.c

查看总线:

insmod bus.ko     查看总线:

生成的:marathon

目前还没有加载dev       drv

加载驱动后:

 

 

 

 

platform 总线是内核自身已经注册好的一种总线,我们无须再注册,直接根据总线的匹配规则

来管理设备对象和驱动对象。那么设备对象和驱动对象的类型如下:

参考手册:linux-3.5/Documentation/driver-model/platform.txt

 

匹配规则:

看完理解之后,常用第二种和第三种匹配规则:

第二种匹配规则:

  

 

转载于:https://www.cnblogs.com/jason-linux/p/10478422.html

你可能感兴趣的文章
数据科学入门 (一) —— 数据
查看>>
Android源码设计模式-中介者模式
查看>>
优化体系结构 - 数据外置减少中间表
查看>>
用户超5亿,三年投10亿,开发者如何抢滩支付宝小程序蓝海?
查看>>
教育部下令中小学推广编程教育,全民AI真的要来了
查看>>
SOA旅程:从了解业务到敏捷架构
查看>>
华为2018:年收入首破千亿美元大关,研发投入过千亿
查看>>
Mysql数据库备份和还原
查看>>
[译] 通过后台数据预获取技术实现性能提升
查看>>
ANGULAR JS常用指令NG-IF、NG-CLASS、NG-OPTION、NG-VALUE、NG-CLICK是如何使用的?
查看>>
cocos creator 视频交互游戏
查看>>
Android学习笔记15-从源码分析Activity的创建过程
查看>>
SpringMVC jsonView 注解笔记
查看>>
学习第二天笔记
查看>>
学习笔记
查看>>
Android做按住显密码的View
查看>>
静态路由原理及实验
查看>>
Android——自定义Dialog
查看>>
编码原理(附二)----二值化
查看>>
技能大赛规程
查看>>