drivers/mfd/Mfd-core.c
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的注册和添加删除工作。
- int mfd_add_devices(struct device *parent, int id,
- struct mfd_cell *cells, int n_devs,
- struct resource *mem_base,
- int irq_base)
- {
- int i;
- int ret = 0;
- atomic_t *cnts;
- /* initialize reference counting for all cells */
- cnts = kcalloc(n_devs, sizeof(*cnts), GFP_KERNEL);
- if (!cnts)
- return -ENOMEM;
- for (i = 0; i < n_devs; i++) {
- atomic_set(&cnts[i], 0);
- cells[i].usage_count = &cnts[i];
- ret = mfd_add_device(parent, id, cells + i, mem_base, irq_base); 调用mfd_add_device()
- if (ret)
- break;
- }
- if (ret)
- mfd_remove_devices(parent);
- return ret;
- }
- EXPORT_SYMBOL(mfd_add_devices);
在这个函数中,参数cells是数组,个数为参数n_devs。用户调用此函数前初始化了cells部分内容,但其中成员由本函数初始化:
- /*
- * This struct describes the MFD part ("cell").
- * After registration the copy of this structure will become the platform data
- * of the resulting platform_device
- */
- struct mfd_cell { //个人理解:注册mfd_cell后等效为platform_device
- const char *name;
- int id;
- /* refcounting for multiple drivers to use a single cell */
- atomic_t *usage_count; //本函数初始化
- int (*enable)(struct platform_device *dev);
- int (*disable)(struct platform_device *dev);
- int (*suspend)(struct platform_device *dev);
- int (*resume)(struct platform_device *dev);
- /* platform data passed to the sub devices drivers */
- void *platform_data;
- size_t pdata_size;
- /*
- * These resources can be specified relative to the parent device.
- * For accessing hardware you should use resources from the platform dev
- */
- int num_resources;
- const struct resource *resources;
- /* don't check for resource conflicts */
- bool ignore_resource_conflicts;
- /*
- * Disable runtime PM callbacks for this subdevice - see
- * pm_runtime_no_callbacks().
- */
- bool pm_runtime_no_callbacks;
- };
再来看mfd_add_device()
- static int mfd_add_device(struct device *parent, int id,
- const struct mfd_cell *cell,
- struct resource *mem_base,
- int irq_base)
- {
- struct resource *res;
- struct platform_device *pdev;
- int ret = -ENOMEM;
- int r;
- pdev = platform_device_alloc(cell->name, id + cell->id); //申请pdev内存并初始化name和id
- if (!pdev)
- goto fail_alloc;
- res = kzalloc(sizeof(*res) * cell->num_resources, GFP_KERNEL);
- if (!res)
- goto fail_device;
- pdev->dev.parent = parent;
- pdev->dev.type = &mfd_dev_type;
- if (cell->pdata_size) { //重新分配pdev->dev. platform_data内存并将cell->platform_data赋给它。
- ret = platform_device_add_data(pdev,
- cell->platform_data, cell->pdata_size);
- if (ret)
- goto fail_res;
- }
- ret = mfd_platform_add_cell(pdev, cell); //重新分配pdev->mfd_cell内存并将cell赋给它。
- if (ret)
- goto fail_res;
- //初始化cell->num_resources 个数量的res将它赋给pdev->resource
- for (r = 0; r < cell->num_resources; r++) {
- res[r].name = cell->resources[r].name;
- res[r].flags = cell->resources[r].flags;
- /* Find out base to use */
- if ((cell->resources[r].flags & IORESOURCE_MEM) && mem_base) {
- res[r].parent = mem_base;
- res[r].start = mem_base->start + //cell中的每个内存start都要加上mem_base->start
- cell->resources[r].start;
- res[r].end = mem_base->start +
- cell->resources[r].end;
- } else if (cell->resources[r].flags & IORESOURCE_IRQ) {
- res[r].start = irq_base + //每个cell中的irq都要加上irq_base。
- cell->resources[r].start;
- res[r].end = irq_base +
- cell->resources[r].end;
- } else {
- res[r].parent = cell->resources[r].parent;
- res[r].start = cell->resources[r].start;
- res[r].end = cell->resources[r].end;
- }
- if (!cell->ignore_resource_conflicts) {
- ret = acpi_check_resource_conflict(&res[r]);
- if (ret)
- goto fail_res;
- }
- }
- ret = platform_device_add_resources(pdev, res, cell->num_resources);//将多个res赋给pdev
- if (ret)
- goto fail_res;
- ret = platform_device_add(pdev); //添加一个platform_device到系统,这时在dev的驱动中会使用这些res数据。
- if (ret)
- goto fail_res;
- if (cell->pm_runtime_no_callbacks)
- pm_runtime_no_callbacks(&pdev->dev);
- kfree(res);
- return 0;
- fail_res:
- kfree(res);
- fail_device:
- platform_device_put(pdev);
- fail_alloc:
- return ret;
- }
drivers/mfd/Mfd-core.c的更多相关文章
- 解析天启rk3288源码 /kernel/drivers/char/virtd
virtd为编译后产生的中间文件,可使用ELF格式逆向 1.ELF文件内容解析readelf: 可解析ELF文件的所有内容;strings: 查看ELF文件中的字符串;file : 查看ELF文件 ...
- u-boot 学习系列 1 - SPL
u-boot这个东西从自我N年前使用到现在,变化好多,今天开始重新研究下,本系列的研究都是基于BeagleBoneBlack(bbb)开发板和 u-boot v201801版本的. SPL介绍 在源代 ...
- [uboot] (第四章)uboot流程——uboot编译流程
http://blog.csdn.net/ooonebook/article/details/53000893 以下例子都以project X项目tiny210(s5pv210平台,armv7架构)为 ...
- 五、u-boot 启动流程---u-boot.lds
5.1 u-boot.lds 链接脚本分析 uboot 编译出来的第一个链接脚本就是执行 u-boot.lds 链接脚本,去掉里面无用的和没有定义的,进行分析. /* 配置头文件,自动生成的,包含芯 ...
- uboot makefile构建分析-续
前言 这篇博文是 uboot makefile构建分析的续篇,继续分析uboot构建u-boot.bin的过程 构建u-boot.bin过程分析 makefile一开始,就是确定链接脚本.在构建ubo ...
- bootrom/spl/uboot/linux逐级加载是如何实现的?
关键词:bootrom.spl.uboot.linux.mksheader.sb_header.mkimage.image_header_t等等. 首先看一个典型的bootrom->spl-&g ...
- [uboot] (第四章)uboot流程——uboot编译流程 (转)
以下例子都以project X项目tiny210(s5pv210平台,armv7架构)为例 [uboot] uboot流程系列:[project X] tiny210(s5pv210)上电启动流程(B ...
- s3c2440液晶屏驱动 (非内核自带) linux-4.1.24
对于,不想逐一检查内核自带驱动,想自己编写驱动. 1,make menuconfig 去掉 编译到内核,改为 M 编译为 模块(因为要用到里面的3个.ko 驱动) Device Drivers --- ...
- windows10 IOT +Azure会议概要总结
windows10 IOT +Azure会议概要总结 会议资料将放到https://channel9.msdn.com/Blogs/WinHEC FAQ:msftsziot@microsoft.com ...
- mongodb .net driver
1.介绍 The official MongoDB .NET Driver provides asynchronous interaction with MongoDB. Powering the d ...
随机推荐
- Lintcode: Flip Bits
Determine the number of bits required to flip if you want to convert integer n to integer m. Have yo ...
- Leetcode: Majority Element II
Given an integer array of size n, find all elements that appear more than ⌊ n/3 ⌋ times. The algorit ...
- Lintcode: Search Range in Binary Search Tree
Given two values k1 and k2 (where k1 < k2) and a root pointer to a Binary Search Tree. Find all t ...
- shell学习笔记(2)替换命令··与()的区别
·CMD·在执行的时候,shell不管··中的内容是什么,先进性解释,再把解释后的最终结果送给shell,如果解释后的结果不是shell可以行的命令,就会报错.但是仅仅把cmd的执行结果作为文本输出, ...
- 不同版本mysql语句不兼容原因
一般是sql_mode不相同,可以认为规则不一致.(语法的变化非常小,一般可以忽略) 如果想要导入不同版本的数据.可以: 手动处理一些导入错误或者采用其他的办法. 或者 修改sql_mode.具体修改 ...
- DDR3简介(一)
JEDEC成立于1958年,作为电子产业协会联盟(EIA)的一部分,为新兴的半导体产业制定标准.主要功能包括术语定义,产品特征描述,测试方法,固态存储器,DRAM,闪存卡及射频识别标签等的确定与标准化 ...
- java 网络编程(二)----UDP基础级的示例
下面介绍UDP基础级的代码示例: 首先了解创建UDP传输的发送端的思路: 1.创建UDP的Socket服务.2.将要发送的数据封装到数据包中.3.通过UDP的socket服务将数据包发送出去.4.关闭 ...
- 什么是商业智能BI和实施BI的解决方案【转】
商业智能,或BI,是一种统称,泛指用于对一个企业的原始数据进行分析的各种各样的软件系统.商业智能(BI)是由若干相关的活动组成的领域,包括数据挖掘,在线分析处理,查询和报表. 企业用商业智能(BI)来 ...
- 随讲MyIsam和InnoDB的区别
mysiam表不支持事务处理,同时mysiam表不支持外键.外键不用说了吧?不知道的话,找度娘. 同时,在执行数据库写入的操作(insert,update,delete)的时候,mysiam表会锁表, ...
- 【python cookbook】【字符串与文本】5.查找和替换文本
问题:对字符串中的文本做查找和替换 解决方案: 1.对于简单模式:str.replace(old, new[, max]) 2.复杂模式:使用re模块中的re.sub(匹配的模式, newstring ...