rfid5-写成platform驱动
来源:互联网 发布:运动毛巾 知乎 编辑:程序博客网 时间:2024/06/05 12:03
上文platform驱动虽然可用,但内层要要写misc驱动,所以不使用设备提供的资源会更加简便。可以如下改一下
Makefile,同上文
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`/buildall: 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.0regulatory.0 s3c2410-spi.0 s3c2440-uart.0 soc-audios3c2410-iis s3c2410-wdt s3c2440-uart.1 song_rfids3c2410-lcd s3c2440-i2c s3c2440-uart.2s3c2410-ohci s3c2440-nand s3c2440-usbgadget[root@FriendlyARM plg]# ls /sys/bus/platform/driversdm9000 s3c2410-ohci s3c2440-uart song_rfids3c-i2c s3c2410-rtc s3c24xx-nands3c-sdi s3c2410-spi s3c24xx_uda134xs3c2410-lcd s3c2412-lcd soc-audio[root@FriendlyARM plg]# rmmod platform_dev driver found device : song_rfid unplugedUnregister song_rfidrmmod: module 'platform_dev' not found[root@FriendlyARM plg]# rmmod platform_drvUnregister my_driver.rmmod: module 'platform_drv' not found[root@FriendlyARM plg]# lsmod [root@FriendlyARM plg]#
- rfid5-写成platform驱动
- rfid4-写成platform驱动
- rfid6-写成platform驱动
- usb5-写成usb驱动
- linux的platform驱动
- Linux驱动中的platform
- platform平台总线驱动
- platform驱动管理机制
- platform驱动模型
- Linux驱动中的platform
- platform设备驱动
- platform设备驱动
- Linux驱动中的platform
- linux驱动-platform详解
- platform设备驱动
- Linux驱动中的platform
- Linux驱动中的platform
- platform设备驱动简介
- 一个留美女博士的七年----分享给所有还相信梦想的朋友(zz 喜欢~~)
- SVN仓库迁移(将一个仓库从一台机器上上转移到另一台机器上)
- 杂感-关于登录系统中用户不能重复登录的问题
- Web所有父窗体与子窗体的交互方法列举(子调用父窗体函数)
- Android UI 设计最佳实践
- rfid5-写成platform驱动
- java.lang.NullPointerException错误,请大家帮忙解决下啊~
- 基于TI Davinci架构的双核嵌入式应用处理器OMAPL138开发入门
- php多维数组遍历
- Effective Android设计
- 10月23日笔试小结
- windows hook技术入门
- 补码详解
- jdk 1.5 循环的新特性