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

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 运维知识 > linux >内容正文

linux

七、linux驱动注册

發布時間:2025/4/5 linux 20 豆豆
生活随笔 收集整理的這篇文章主要介紹了 七、linux驱动注册 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

一、驅動注冊結構體

????????驅動注冊使用結構體platform_driver,該結構體在頭文件“vim include/linux/platform_device.h”中,和剛剛那個設備注冊的驅動在同一個頭文件。

  • ? ? ? ? 驅動注冊platform_driver_register
  • ????????驅動卸載函數platform_driver_unregister

???????也在這個頭文件中,這兩個函數的參數都只有結構體platform_driver

????????驅動常見的幾種狀態,初始化,移除,休眠,復位
????????就像PC一樣,有的驅動休眠之后無法使用,有的可以使用;有的系統喚醒之后,驅動需要重新啟動才能正常工作,也有直接就可以使用等等

?????????? probe函數

????????????????– platform_match函數匹配之后,驅動調用的初始化函數

????????? remove函數?

????????????????– 移除驅動函數

???????????suspend函數

????????????????– 懸掛(休眠)驅動函數

?????????? resume函數

????????????????– 休眠后恢復驅動

????????? device_driver數據結構的兩個參數

????????????????– name和注冊的設備name要一致
????????????????– owner一般賦值THIS_MODULE

二、驅動源碼

我們在前面最小驅動的代碼基礎上修改,主要實現platform_driver結構體中定義的函數,然后再通過platform_driver_register和platform_driver_unregister注冊和卸載:

#include <linux/init.h> #include <linux/module.h>/*驅動注冊的頭文件,包含驅動的結構體和注冊和卸載的函數*/ #include <linux/platform_device.h>#define DRIVER_NAME "hello_ctl"MODULE_LICENSE("Dual BSD/GPL"); MODULE_AUTHOR("TOPEET");static int hello_probe(struct platform_device *pdv){printk(KERN_EMERG "\tinitialized\n");return 0; }static int hello_remove(struct platform_device *pdv){return 0; }static void hello_shutdown(struct platform_device *pdv){; }static int hello_suspend(struct platform_device *pdv){return 0; }static int hello_resume(struct platform_device *pdv){return 0; }struct platform_driver hello_driver = {.probe = hello_probe,.remove = hello_remove,.shutdown = hello_shutdown,.suspend = hello_suspend,.resume = hello_resume,.driver = {.name = DRIVER_NAME,.owner = THIS_MODULE,} };static int hello_init(void) {int DriverState;printk(KERN_EMERG "HELLO WORLD enter!\n");DriverState = platform_driver_register(&hello_driver); // 注冊驅動printk(KERN_EMERG "\tDriverState is %d\n",DriverState);return 0; }static void hello_exit(void) {printk(KERN_EMERG "HELLO WORLD exit!\n");platform_driver_unregister(&hello_driver); // 注銷驅動 }module_init(hello_init);// 模塊入口 module_exit(hello_exit);

?運行如下:當遇到驅動無法卸載時,請按照下面操作解決

?

《新程序員》:云原生和全面數字化實踐50位技術專家共同創作,文字、視頻、音頻交互閱讀

總結

以上是生活随笔為你收集整理的七、linux驱动注册的全部內容,希望文章能夠幫你解決所遇到的問題。

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