作家
登录

Linux平台总线驱动设备模型

作者: 来源: 2017-11-16 16:05:49 阅读 我要评论

  •     struct platform_device_id   *id_entry;   
  • };   
  • 个中有个重要的成员是resource,是设备的资本信息,如IO地址,中断号等。

    有的设备可能有多个资本,平日应用platform_get_resource函数来获取资本

    1. /**  
    2.  * platform_get_resource - get a resource for a device  
    3.  * @dev: platform device  
    4.  * @type: resource type  
    5.  * @num: resource index  
    6.  */   
    7. struct resource *platform_get_resource(struct platform_device *dev,   
    8.                        unsigned int type, unsigned int num)   
    9. {   
    10.     int i;   
    11.    
    12.     for (i = 0; i < dev->num_resources; i++) {   
    13.         struct resource *r = &dev->resource[i];   
    14.    
    15.         if (type == resource_type(r) && num-- == 0)   
    16.             return r;   
    17.     }   
    18.     return NULL;   
    19. }   

    平台设备的注册,应用platform_device_register函数

    1. int platform_device_register(struct platform_device *pdev)   
    2. {   
    3.     device_initialize(&pdev->dev);   
    4.     return platform_device_add(pdev);   
    5. }   

    platform_device_register函数先经由过程device_initialize函数初始化platform_device的device成员,然后调用platform_device_add向内核添加一个平台设备。

    platform_device_add最终调用device_add来完成平台设备的注册。

    相反地,如不雅要刊出平台设备则应用platform_device_unregister函数

    1. void platform_device_unregister(struct platform_device *pdev)   
    2. {   
    3.     platform_device_del(pdev);   
    4.     platform_device_put(pdev);   
    5. }   

    platform_device_unregister函数调用platform_device_del函数来刊出平台设备

    1. void platform_device_del(struct platform_device *pdev)   
    2. {   
    3.     int i;   
    4.    
    5.     if (pdev) {   
    6.         device_del(&pdev->dev);   
    7.    
    8.         for (i = 0; i < pdev->num_resources; i++) {   

        推荐阅读

        Linux Lite第一个支持Linux 4.14及如何安装

      Tech Neo技巧沙龙 | 11月25号,九州云/ZStack与您一路商量云时代收集界线治理实践 Linux Lite保护者Jerry Bezencon再次初次在Twitter上宣布他的基于Ubuntu的发行版的软件库中最新的Linux内>>>详细阅读


      本文标题:Linux平台总线驱动设备模型

      地址:http://www.17bianji.com/lsqh/38937.html

    关键词: 探索发现

    乐购科技部分新闻及文章转载自互联网,供读者交流和学习,若有涉及作者版权等问题请及时与我们联系,以便更正、删除或按规定办理。感谢所有提供资讯的网站,欢迎各类媒体与乐购科技进行文章共享合作。

    网友点评
    自媒体专栏

    评论

    热度

    精彩导读
    栏目ID=71的表不存在(操作类型=0)