platfrom 裝置總結

來源:互聯網
上載者:User

 

註冊裝置的兩種方式:

方法一:

 一:對於平台裝置可以直接在板檔案中添加代碼(arch / arm / mach-s3cxxxx / mach-smdk2440.c)

 代碼 1: static struct platfrom_device hello_device = {

                      .name     = "hello ",

                      .id             = -1,

                     .resource  = hello_resource,                      

                       ...................

                       .......................

                       };  添加裝置結構體

代碼2:繼續添加裝置資源(arch / arm / mach-s3cxxxx / mach-smdk2440.c)

          

static struct resource  hello_resource[] = {  

      [0] = {  //IO連接埠資源    

              .start = S3C24XX_PA_WATCHDOG,   

              .end   = S3C24XX_PA_WATCHDOG + S3C24XX_SZ_WATCHDOG - 1,   

              .flags = IORESOURCE_MEM,  

       },  

       [1] = {  //中斷資源   

              .start = IRQ_WDT,                 .end   = IRQ_WDT,  

             .flags = IORESOURCE_IRQ,  

       }  

};  

3:繼續把裝置加入到裝置數組中去arch / arm / mach-s3cxxxx / mach-smdk2440.c

  • static struct platform_device *smdk2440_devices[] __initdata = {  
  •        &s3c_device_usb,  
  •        &s3c_device_lcd,  
  •        &s3c_device_wdt,  
  •        &s3c_device_i2c0,  
  •        &s3c_device_iis,  
  •   &hello_device,   
  • };  
  •   

    之後系統在載入該驅動的時候會自動的調用platform_add_devices把裝置註冊到系統中去,該函數內部會調用platfrom_device_register().裝置註冊完閉

     

    方法二:

    直接定義即可:1。定義裝置結構體

    static struct platfrom_device hello_device = {

                          .name     = "hello ",

                          .id             = -1,

                         .resource  = hello_resource,                      

                           ...................

                           .......................

                           }; 

    2。定義裝置資源

    static struct resource  hello_resource[] = {  

          [0] = {  //IO連接埠資源    

                  .start = S3C24XX_PA_WATCHDOG,   

                  .end   = S3C24XX_PA_WATCHDOG + S3C24XX_SZ_WATCHDOG - 1,   

                  .flags = IORESOURCE_MEM,  

           },  

     

    3。註冊裝置 platfrom_device_register().

    static int __init  hello_init(void)  

    {  

           printk(banner);  

           return platform_device_register(&hello_device);  

    }  

    static void __exit hello_exit(void)  

    {  

           platform_device_unregister(&hello_device );  

    }  

      

    module_init(hello_init);  

    module_exit(hello_exit);  

     

     

     

  • 聯繫我們

    該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

    如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

    A Free Trial That Lets You Build Big!

    Start building with 50+ products and up to 12 months usage for Elastic Compute Service

    • Sales Support

      1 on 1 presale consultation

    • After-Sales Support

      24/7 Technical Support 6 Free Tickets per Quarter Faster Response

    • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.