上文platform驱动虽然可用,但内层要要写misc驱动,所以不使用设备提供的资源会更加简便。可以如下改一下
Makefile,同上文

ifneq ($(KERNELRELEASE),)
obj-m :=  platform_dev.o  platform_drv.o
else
KDIR := /opt/FriendlyARM/mini2440/linux-2.6.32.2
#KDIR := /lib/modules/`uname -r`/build
all:  make -C $(KDIR) M=$(PWD) modules
clean:  rm -f *.ko *.o *.mod.o *.mod.c *.symvers
endif  

设备中去掉资源项,并使用内核alloc的设备在将其add到平台总线,不必registe设备了

/******************platfrom_dev.c***************************/
#include <linux/module.h>
#include <linux/device.h>
#include <linux/platform_device.h>
#include <linux/string.h>
#include <linux/init.h>
#include <linux/kernel.h>#define DEVICE_NAME "song_rfid"
static struct platform_device *my_device;static int __init my_init(void)
{int ret=0;my_device= platform_device_alloc(DEVICE_NAME,-1);//this name is matched for driver,song_rfidret=platform_device_add(my_device);if (ret == 0) {printk("Register %s\n",DEVICE_NAME);} else {printk("Register  error.\n");platform_device_put(my_device);}return ret;
}static void __exit my_exit(void)
{platform_device_unregister(my_device);printk("Unregister %s\n",DEVICE_NAME);
}module_init(my_init);
module_exit(my_exit);MODULE_LICENSE("GPL");
MODULE_VERSION("1.5");
/******************platfrom_drv.c***************************/
#include <linux/module.h>
#include <linux/device.h>
#include <linux/platform_device.h>
#include <linux/string.h>
#include <linux/init.h>
#include <linux/kernel.h>
#include <linux/io.h>#define DRIVER_NAME "song_rfid"static int  my_probe(struct platform_device *pdev)
{printk("driver find device : %s which can handle\n",DRIVER_NAME);return 0;
}static int  my_remove(struct platform_device *pdev)
{printk("driver found device : %s unpluged\n",DRIVER_NAME);return 0;
}static struct platform_driver my_driver = {.probe         = my_probe,.remove     = my_remove,.driver    = {.owner  = THIS_MODULE,.name    = DRIVER_NAME,//this name is matched for driver,song_rfid},
};static int __init my_init(void)
{printk("Register my_driver.\n");return platform_driver_register(&my_driver);
}static void __exit my_exit(void)
{printk("Unregister my_driver.\n");platform_driver_unregister(&my_driver);
}module_init(my_init);
module_exit(my_exit);MODULE_LICENSE("GPL");
[root@FriendlyARM plg]# lsmod
[root@FriendlyARM plg]# insmod platform_dev.ko
Register song_rfid
[root@FriendlyARM plg]# insmod platform_drv.ko
Register my_driver.
driver find device : song_rfid which can handle
[root@FriendlyARM plg]# ls /sys/bus/platform/devices/
dm9000             s3c2410-rtc        s3c2440-sdi        s3c24xx_uda134x.0
regulatory.0       s3c2410-spi.0      s3c2440-uart.0     soc-audio
s3c2410-iis        s3c2410-wdt        s3c2440-uart.1     song_rfid
s3c2410-lcd        s3c2440-i2c        s3c2440-uart.2
s3c2410-ohci       s3c2440-nand       s3c2440-usbgadget
[root@FriendlyARM plg]# ls /sys/bus/platform/drivers
dm9000           s3c2410-ohci     s3c2440-uart     song_rfid
s3c-i2c          s3c2410-rtc      s3c24xx-nand
s3c-sdi          s3c2410-spi      s3c24xx_uda134x
s3c2410-lcd      s3c2412-lcd      soc-audio
[root@FriendlyARM plg]# rmmod platform_dev
driver found device : song_rfid unpluged
Unregister song_rfid
rmmod: module 'platform_dev' not found
[root@FriendlyARM plg]# rmmod platform_drv
Unregister my_driver.
rmmod: module 'platform_drv' not found
[root@FriendlyARM plg]# lsmod
[root@FriendlyARM plg]# 

转载于:https://www.cnblogs.com/-song/archive/2011/10/25/3331941.html

rfid5-写成platform驱动相关推荐

  1. rfid3-micro2440,linux2.6.32.2,写成misc驱动

    接上文的进度,将keil下已经成功的读卡程序写成linux驱动的形式 采用misc来写比较方便简单,仅是为了方便测试,好多都在驱动中实现. 主文件是rfid.c #include "rc52 ...

  2. rfid4-写成platform驱动

    适应时代发展,将misc驱动封装到platfrom总线里面去, platform平台总线模型,把设备和驱动分开,即一个东东要分成两个部分去写和去insmod,是不是有点麻烦.--对于固定于一个cpu平 ...

  3. rfid6-写成platform驱动

    将前面rfid的misc挂到platform平台上,因为misc驱动都有了,所以很简单,代码复制过来就好了 设备侧就用上文的那个就好 /******************platfrom_dev.c ...

  4. linux platform 驱动模型分析

    一. 概述     platform设备和驱动与linux设备模型密切相关.platform在linux设备模型中,其实就是一种虚拟总线没有对应的硬件结构.它的主要作用就是管理系统的外设资源,比如io ...

  5. platform驱动模型使用总结

    platform平台总线驱动的编写主要分为两个部分: 一个是platform_device部分,主要是提供设备本身对驱动处理所要求的参数. 另一个是platform_driver部分,主要是利用pla ...

  6. 驱动程序开发:无设备树和有设备树的platform驱动

    1.Linux 驱动的分离与分层   对与对IO进行最简单的读写操作,无需考虑太多的怎么使它重用性强,而像I2C. SPI.LCD 等这些复杂外设的驱动,Linux 系统要考虑到驱动的可重用性,因此提 ...

  7. platform驱动

    目录 1.Linux驱动的分离与分层 1)驱动的分隔与分离 2)驱动的分层 2.platform平台驱动模型简介 1)platform总线 2)platform驱动 3)platform设备 3.试验 ...

  8. <Linux开发>驱动开发 -之-platform 驱动

    <Linux开发>驱动开发 -之-platform 驱动 交叉编译环境搭建: <Linux开发> linux开发工具-之-交叉编译环境搭建 uboot移植可参考以下: < ...

  9. Linux dts设备树和platform驱动详解

    概念 小麦大叔 2019-05-06 22:56:31 12603 收藏 135 什么是设备树 dts(device tree)? 设备树(Device Tree)是描述计算机的特定硬件设备信息的数据 ...

最新文章

  1. 少侠,找个千手观音来帮你营销可好?
  2. mysql的or能去重吗_mysql条件查询中AND与OR联合使用的注意事项!
  3. apache 添加下载文件头
  4. 快抢!猪年之前最后一波送书福利,错过只能等“明年”
  5. css transition过渡
  6. Android ------ handler 异步处理消息
  7. Grasshopper GHPython 报错: Solution exception:找不到方法: “Void Microsoft.Scripting.Utils
  8. 国际科学数据服务平台 - csdb_拔剑-浆糊的传说_新浪博客
  9. 服务器状态 fadein,aria2-BT服务器地址的可用trackers列表(已接手)
  10. HEW3工程链接错误(L2330 (E) Relocation size overflow )及解决
  11. 推荐系统论文11月组队学习
  12. 【简单】字符串中最长元音字符串的长度
  13. Kaggle教程 机器学习入门3 你的第一个机器学习模型
  14. requests.exceptions.SSLError: HTTPSConnectionPool(host='api.bilibili.com', port=443)
  15. OSPF路由协议详解与实战演练
  16. 支持向量机SVM(1)——间隔最大化
  17. ASP音乐网站的设计与实现
  18. Cadence Allegro如何制作椭圆形通孔焊盘?
  19. CMD命令之ECHO大全
  20. 烤仔的朋友们丨大饼破万,以太飞天,牛来了还是狼来了?

热门文章

  1. OSPF DR选举的先后
  2. 解决错误:Re-installation failed due to different application signatures
  3. (android实战)Service 生命周期和使用注意项
  4. AndroidManifest.xml配置文件属性详解
  5. BAT批处理中的字符串处理详解(字符串截取)
  6. 创建型模式—单例模式
  7. RuntimeError: dictionary changed size during iteration
  8. mvc4 利用filters特性来 实现自己的权限验证 之二
  9. json学习系列(7)JSONBuilder的用法
  10. 大家看看这个参数inctype你是否使用过?我做了以下测试,欢迎拍砖!