日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

rfid5-写成platform驱动

發布時間:2024/4/14 编程问答 45 豆豆
生活随笔 收集整理的這篇文章主要介紹了 rfid5-写成platform驱动 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
上文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驱动的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。