mfd: multifunction device drivers---多功能设备驱动开发;
A product or device that has multiple functions. An example of this might be a printer that also makes copies, faxes, and scans. Another example is a CD or DVD that might contain multiple applications on the same disk; this may be a Mac and PC version of the same software or media meant to be played on more than one platform. Also called multi function product (MFP), all-in-one.

源码主要是做了一些platform_device的注册和添加删除工作。

  1. int mfd_add_devices(struct device *parent, int id,
  2. struct mfd_cell *cells, int n_devs,
  3. struct resource *mem_base,
  4. int irq_base)
  5. {
  6. int i;
  7. int ret = 0;
  8. atomic_t *cnts;
  9. /* initialize reference counting for all cells */
  10. cnts = kcalloc(n_devs, sizeof(*cnts), GFP_KERNEL);
  11. if (!cnts)
  12. return -ENOMEM;
  13. for (i = 0; i < n_devs; i++) {
  14. atomic_set(&cnts[i], 0);
  15. cells[i].usage_count = &cnts[i];
  16. ret = mfd_add_device(parent, id, cells + i, mem_base, irq_base); 调用mfd_add_device()
  17. if (ret)
  18. break;
  19. }
  20. if (ret)
  21. mfd_remove_devices(parent);
  22. return ret;
  23. }
  24. EXPORT_SYMBOL(mfd_add_devices);

在这个函数中,参数cells是数组,个数为参数n_devs。用户调用此函数前初始化了cells部分内容,但其中成员由本函数初始化:

  1. /*
  2. * This struct describes the MFD part ("cell").
  3. * After registration the copy of this structure will become the platform data
  4. * of the resulting platform_device
  5. */
  6. struct mfd_cell {  //个人理解:注册mfd_cell后等效为platform_device
  7. const char      *name;     
  8. int         id;
  9. /* refcounting for multiple drivers to use a single cell */
  10. atomic_t        *usage_count;    //本函数初始化
  11. int         (*enable)(struct platform_device *dev);
  12. int         (*disable)(struct platform_device *dev);
  13. int         (*suspend)(struct platform_device *dev);
  14. int         (*resume)(struct platform_device *dev);
  15. /* platform data passed to the sub devices drivers */
  16. void            *platform_data;
  17. size_t          pdata_size;
  18. /*
  19. * These resources can be specified relative to the parent device.
  20. * For accessing hardware you should use resources from the platform dev
  21. */
  22. int         num_resources;
  23. const struct resource   *resources;
  24. /* don't check for resource conflicts */
  25. bool            ignore_resource_conflicts;
  26. /*
  27. * Disable runtime PM callbacks for this subdevice - see
  28. * pm_runtime_no_callbacks().
  29. */
  30. bool            pm_runtime_no_callbacks;
  31. };

再来看mfd_add_device()

  1. static int mfd_add_device(struct device *parent, int id,
  2. const struct mfd_cell *cell,
  3. struct resource *mem_base,
  4. int irq_base)
  5. {
  6. struct resource *res;
  7. struct platform_device *pdev;
  8. int ret = -ENOMEM;
  9. int r;
  10. pdev = platform_device_alloc(cell->name, id + cell->id); //申请pdev内存并初始化name和id
  11. if (!pdev)
  12. goto fail_alloc;
  13. res = kzalloc(sizeof(*res) * cell->num_resources, GFP_KERNEL);
  14. if (!res)
  15. goto fail_device;
  16. pdev->dev.parent = parent;
  17. pdev->dev.type = &mfd_dev_type;
  18. if (cell->pdata_size) {  //重新分配pdev->dev. platform_data内存并将cell->platform_data赋给它。
  19. ret = platform_device_add_data(pdev,
  20. cell->platform_data, cell->pdata_size);
  21. if (ret)
  22. goto fail_res;
  23. }
  24. ret = mfd_platform_add_cell(pdev, cell); //重新分配pdev->mfd_cell内存并将cell赋给它。
  25. if (ret)
  26. goto fail_res;
  27. //初始化cell->num_resources 个数量的res将它赋给pdev->resource
  28. for (r = 0; r < cell->num_resources; r++) {
  29. res[r].name = cell->resources[r].name;
  30. res[r].flags = cell->resources[r].flags;
  31. /* Find out base to use */
  32. if ((cell->resources[r].flags & IORESOURCE_MEM) && mem_base) {
  33. res[r].parent = mem_base;
  34. res[r].start = mem_base->start +    //cell中的每个内存start都要加上mem_base->start
  35. cell->resources[r].start;
  36. res[r].end = mem_base->start +
  37. cell->resources[r].end;
  38. } else if (cell->resources[r].flags & IORESOURCE_IRQ) {
  39. res[r].start = irq_base +           //每个cell中的irq都要加上irq_base。
  40. cell->resources[r].start;
  41. res[r].end   = irq_base +
  42. cell->resources[r].end;
  43. } else {
  44. res[r].parent = cell->resources[r].parent;
  45. res[r].start = cell->resources[r].start;
  46. res[r].end   = cell->resources[r].end;
  47. }
  48. if (!cell->ignore_resource_conflicts) {
  49. ret = acpi_check_resource_conflict(&res[r]);
  50. if (ret)
  51. goto fail_res;
  52. }
  53. }
  54. ret = platform_device_add_resources(pdev, res, cell->num_resources);//将多个res赋给pdev
  55. if (ret)
  56. goto fail_res;
  57. ret = platform_device_add(pdev); //添加一个platform_device到系统,这时在dev的驱动中会使用这些res数据。
  58. if (ret)
  59. goto fail_res;
  60. if (cell->pm_runtime_no_callbacks)
  61. pm_runtime_no_callbacks(&pdev->dev);
  62. kfree(res);
  63. return 0;
  64. fail_res:
  65. kfree(res);
  66. fail_device:
  67. platform_device_put(pdev);
  68. fail_alloc:
  69. return ret;
  70. }

drivers/mfd/Mfd-core.c的更多相关文章

  1. 解析天启rk3288源码 /kernel/drivers/char/virtd

    virtd为编译后产生的中间文件,可使用ELF格式逆向 1.ELF文件内容解析readelf: 可解析ELF文件的所有内容;strings: 查看ELF文件中的字符串;file   : 查看ELF文件 ...

  2. u-boot 学习系列 1 - SPL

    u-boot这个东西从自我N年前使用到现在,变化好多,今天开始重新研究下,本系列的研究都是基于BeagleBoneBlack(bbb)开发板和 u-boot v201801版本的. SPL介绍 在源代 ...

  3. [uboot] (第四章)uboot流程——uboot编译流程

    http://blog.csdn.net/ooonebook/article/details/53000893 以下例子都以project X项目tiny210(s5pv210平台,armv7架构)为 ...

  4. 五、u-boot 启动流程---u-boot.lds

    5.1 u-boot.lds  链接脚本分析 uboot 编译出来的第一个链接脚本就是执行 u-boot.lds 链接脚本,去掉里面无用的和没有定义的,进行分析. /* 配置头文件,自动生成的,包含芯 ...

  5. uboot makefile构建分析-续

    前言 这篇博文是 uboot makefile构建分析的续篇,继续分析uboot构建u-boot.bin的过程 构建u-boot.bin过程分析 makefile一开始,就是确定链接脚本.在构建ubo ...

  6. bootrom/spl/uboot/linux逐级加载是如何实现的?

    关键词:bootrom.spl.uboot.linux.mksheader.sb_header.mkimage.image_header_t等等. 首先看一个典型的bootrom->spl-&g ...

  7. [uboot] (第四章)uboot流程——uboot编译流程 (转)

    以下例子都以project X项目tiny210(s5pv210平台,armv7架构)为例 [uboot] uboot流程系列:[project X] tiny210(s5pv210)上电启动流程(B ...

  8. s3c2440液晶屏驱动 (非内核自带) linux-4.1.24

    对于,不想逐一检查内核自带驱动,想自己编写驱动. 1,make menuconfig 去掉 编译到内核,改为 M 编译为 模块(因为要用到里面的3个.ko 驱动) Device Drivers --- ...

  9. windows10 IOT +Azure会议概要总结

    windows10 IOT +Azure会议概要总结 会议资料将放到https://channel9.msdn.com/Blogs/WinHEC FAQ:msftsziot@microsoft.com ...

  10. mongodb .net driver

    1.介绍 The official MongoDB .NET Driver provides asynchronous interaction with MongoDB. Powering the d ...

随机推荐

  1. [原创]java WEB学习笔记60:Struts2学习之路--Actioin-声明式异常处理

    本博客的目的:①总结自己的学习过程,相当于学习笔记 ②将自己的经验分享给大家,相互学习,互相交流,不可商用 内容难免出现问题,欢迎指正,交流,探讨,可以留言,也可以通过以下方式联系. 本人互联网技术爱 ...

  2. Java基础(63):正则表达式的运用

    Java 正则表达式 正则表达式定义了字符串的模式. 正则表达式可以用来搜索.编辑或处理文本. 正则表达式并不仅限于某一种语言,但是在每种语言中有细微的差别. Java正则表达式和Perl的是最为相似 ...

  3. org.openqa.selenium.WebDriverException: f.QueryInterface is not a function Command duration or timeout:

    今天偶遇一个问题,运行项目时,发现这个问题: org.openqa.selenium.WebDriverException: f.QueryInterface is not a functionCom ...

  4. ScrollView属性总结

    结构 继承关系 public class ScrollView extends FrameLayout java.lang.Object android.view.View android.view. ...

  5. 建立一个Hello World级别的Spring项目

    package com.sevenhu.domain; import org.springframework.context.ApplicationContext; import org.spring ...

  6. C#.Net GC(garbage Collector) 垃圾回收器

    以前一直以为gc的原理很简单,也就是分代处理堆数据,直到我的膝盖中了一箭(好吧 直到有天汪涛和我说他面试携程的面试题 关于服务器和 工作站gc 的区别)其实我当时尚不知道 工作站和服务器有什么区别更不 ...

  7. 夺命雷公狗---linux之centos的安装

    由于要玩node.js了,所以还是来复习下linux系统才行,所以夺命雷公狗分享两套安装linux的方法,这是centos的安装方法,,, 管理员默认帐号为:root,密码则是刚才您输入的那个...

  8. SqlServer中使用Select语句给变量赋值的时候需要注意的一个问题

    我们知道在SqlServer中可以用Select语句给变量赋值,比如如下语句就为int类型的变量@id赋值 ; select @id=id from ( as id union all as id u ...

  9. 使用 TC 对LInux中vpn 上传下载进行限速(转)

    TC 无需安装,Linux 内核自带 例:将vpn IP地址段192.168.1.0/24 上传下载限速为 5M 将以下内容添加到/etc/ppp/ip-up文件exit 0上面. down=5Mbi ...

  10. 从追MM谈Java的23种设计模式(转)

    从追MM谈Java的23种设计模式    这个是从某个文章转载过来的.但是忘了原文链接.如果知道的,我追加一下. 1.FACTORY-追MM少不了请吃饭了,麦当劳的鸡翅和肯德基的鸡翅都是MM爱吃的东西 ...