platfrom 设备总结

 

注册设备的两种方式:

方法一:

 一:对于平台设备可以直接在板文件中添加代码(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);  


     

     

     

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值