基于RV1126 Video分析-----链接 isp 与mipi csi 的media模块
创始人
2024-03-04 09:07:20
0

从前文:<<图像处理模块所代表的V4L2设备注册>> 中了解到。rkcif_mipi设备注册的过程就是以设备通知器为线索,从顶向下,依次找到下一级设备,添加到V4L2设备种,循环处理。将全部的子设备整理到 V4L2设备中,这样可以通过V4L2设备直接管理所包含的各个子设备。 其中各自探测到子设备后,会分别执行各自的bound()函数。
即 rkcif_mipi,mipi csi, mipi csi dphy 三个模块的 bound()函数!!!

最后执行 rkcif_mipi 的 complete()函数

所以 这里 我们就只分析:
1 rkcif_mipi 的 bound()函数
2 rkcif_mipi 的 complete()函数

有下面的分析可以知道,最终
在这里插入图片描述

即从这里:

rkcif_plat_proberkcif_plat_initrkcif_register_platform_subdevscif_subdev_notifierv4l2_async_notifier_register__v4l2_async_notifier_registerstatic int __v4l2_async_notifier_register(struct v4l2_async_notifier *notifier)
{struct device *dev =notifier->v4l2_dev ? notifier->v4l2_dev->dev : NULL;struct v4l2_async_subdev *asd;int ret;int i;/*动作4工作struct rkcif_devicestruct device *dev;struct device_node	*of_node; //A associated device tree node           如 节点 rkcif_mipi_lvds                      struct	device_node *child;  //Aa                 第一个子节点      如 节点 	port 				struct	device_node *child; // Aa-1           第一个子节点      如 节点 		cif_mipi_in: endpointstruct fwnode_handle fwnode;				struct v4l2_async_notifier notifier;	const struct v4l2_async_notifier_operations *ops ;(init)+---struct list_head waiting;//等待通知链表|	struct v4l2_async_subdev **subdevs;//subdevs数组 保存 对应的远端关联节点的父节点信息			+-------|//subdevs[n] 将远端目标节点封装为 v4l2_async_subdev 结构 保存在该数组				|enum v4l2_async_match_type match_type = V4L2_ASYNC_MATCH_FWNODE  设备树fwnode匹配方式 				|union match				struct fwnode_handle *fwnode;----------------------------->>>>>------------------------相连接的远程节点 mipi_csi2_output 的 父节点port的 fwnode							*/for (i = 0; i < notifier->num_subdevs; i++) {//获取  对应的远端关联节点的父节点信息asd = notifier->subdevs[i];//挂载 到等待队列list_add_tail(&asd->list, ¬ifier->waiting);}/*这里是一个循环探索的过程第一轮:传入参数:struct rkcif_devicestruct v4l2_async_notifier notifierrkcif_device 设备1 遍历全局链表 subdev_list ,搜索到当前异步通知器是waiting链表中的子设备信息,即mipi csi设备。说明探索到已挂在的子设备2 将mipi csi设备 添加到  V4L2 子设备链表中 !!3 执行 rkcif_device设备的 notifier->ops->bound()函数4 绑定 mipi csi设备 通知器struct rkcif_device		  struct v4l2_async_notifier notifier ----------+|struct csi2_dev                                   |struct v4l2_async_notifier notifier-----------+struct v4l2_async_notifier *parent;-------+第二轮:传入参数:struct csi2_dev  struct v4l2_async_notifier notifiermipi cis 设备1 遍历全局链表 subdev_list ,搜索到当前异步通知器是waiting链表中的子设备信息,即 mipi csi dphy 设备。说明探索到已挂在的子设备2 将 mipi csi dphy 设备 添加到  V4L2 子设备链表中 !!3 执行 mipi cis 设备的 notifier->ops->bound()函数4 绑定 mipi csi dphy 设备 通知器struct rkcif_device		  struct v4l2_async_notifier notifier ----------+|struct csi2_dev                                   |struct v4l2_async_notifier notifier-----------+struct v4l2_async_notifier *parent;-------+|struct mipidphy_priv                              |struct v4l2_async_notifier notifier-----------+struct v4l2_async_notifier *parent;-------+第三轮: 传入参数 struct mipidphy_priv  struct v4l2_async_notifier notifiermipi csi dphy 设备1 遍历全局链表 subdev_list ,搜索到当前异步通知器是waiting链表中的子设备信息,即 sensor 设备。说明探索到已挂在的子设备2 将 sensor 设备 添加到  V4L2 子设备链表中 !!3 执行 mipi csi dphy 设备的 notifier->ops->bound()函数4 绑定 sensor 设备 通知器struct rkcif_device		  struct v4l2_async_notifier notifier ----------+|struct csi2_dev                                   |struct v4l2_async_notifier notifier-----------+struct v4l2_async_notifier *parent;-------+|struct mipidphy_priv                              |struct v4l2_async_notifier notifier-----------+struct v4l2_async_notifier *parent;-------+|struct techpoint                                  |struct v4l2_async_notifier notifier-----------+struct v4l2_async_notifier *parent;-------+第四轮:传入参数:struct techpointstruct v4l2_async_notifier notifiersensor 设备由于sensort 已经是最后一级模块,他没有子设备。直接返回 !!!*/ret = v4l2_async_notifier_try_all_subdevs(notifier);if (ret < 0)goto err_unbind;/*  	参数1  当前设备异步通知器				* 条件不满足,暂时不进入分析,不满足原因如下* 1. notifier->parent == NULL* 2. notifier->v4l2_dev == NULL所以其他三个subdev设备 独自初始化时 不满足该函数运行条件只有 rkcif_mipi 能执行该函数*/ret = v4l2_async_notifier_try_complete(notifier);if (ret < 0)goto err_unbind;/** 以上2个函数可以看出来,v4l2_dev为空时都不会执行* 将这个notifer挂载到链表notifier_list上*//* Keep also completed notifiers on the list */list_add(¬ifier->list, ¬ifier_list);mutex_unlock(&list_lock);return 0;err_unbind:/** On failure, unbind all sub-devices registered through this notifier.*/v4l2_async_notifier_unbind_all_subdevs(notifier);err_unlock:mutex_unlock(&list_lock);return ret;
}

这里会按照顺序 分别执行各自的bound()函数。
即 rkcif_mipi,mipi csi, mipi csi dphy 三个模块的 bound()函数!!!

首先 先看 rkcif_mipi 模块的 bound()函数

struct rkcif_devicestruct v4l2_async_notifier notifier;const struct v4l2_async_notifier_operations *ops ;(init).bound = subdev_notifier_bound,// V4L4 异步通知操作集
static const struct v4l2_async_notifier_operations subdev_notifier_ops = {.bound = subdev_notifier_bound,.complete = subdev_notifier_complete,
};//已经成功探测到其中一个子设备,只是把子设备 mipi csi的subdev放入cif_dev->sensors的数组中存储/*参数1 rkcif_device->v4l2_async_notifier参数2 相关联的 mipi csi 的 v4l2_subdev参数3 相关联的 mipi csi 的dts节点*/
static int subdev_notifier_bound(struct v4l2_async_notifier *notifier,struct v4l2_subdev *subdev,struct v4l2_async_subdev *asd)
{//当前 rkcif_device 设备信息struct rkcif_device *cif_dev = container_of(notifier,struct rkcif_device, notifier);struct rkcif_async_subdev *s_asd = container_of(asd,struct rkcif_async_subdev, asd);if (cif_dev->num_sensors == ARRAY_SIZE(cif_dev->sensors)) {v4l2_err(&cif_dev->v4l2_dev,"%s: the num of subdev is beyond %d\n",__func__, cif_dev->num_sensors);return -EBUSY;}//将  相关联的 mipi csi 的 v4l2_subdev 添加到 rkcif_device设备的子sensor[]数组中cif_dev->sensors[cif_dev->num_sensors].lanes = s_asd->lanes;cif_dev->sensors[cif_dev->num_sensors].mbus = s_asd->mbus;cif_dev->sensors[cif_dev->num_sensors].sd = subdev;++cif_dev->num_sensors;v4l2_err(subdev, "Async registered subdev\n");return 0;
}

其实没干啥

只是把子设备 mipi csi的subdev放入cif_dev->sensors的数组中存储

再看看 rkcif_mipi 的complete()

static int subdev_notifier_complete(struct v4l2_async_notifier *notifier)
{struct rkcif_device *dev;struct rkcif_sensor_info *sensor;struct v4l2_subdev *sd;struct v4l2_device *v4l2_dev = NULL;int ret, index;// 通过 rkcif_mipi 通知器地址 得到 rkcif_device 地址dev = container_of(notifier, struct rkcif_device, notifier);// 获取 rkcif_mipi设备的  v4l2_device信息(v4l2设备)v4l2_dev = &dev->v4l2_dev;.../*参数:rkcif_mipi对应的 v4l2设备*/ret = rkcif_create_links(dev);if (ret < 0)goto unregister_lvds;...return ret;
}/*参数:rkcif_mipi 对应的 v4l2设备
*/
static int rkcif_create_links(struct rkcif_device *dev)
{int ret;u32 flags;unsigned int s, pad, id, stream_num = 0;bool mipi_lvds_linked = false;//stream_num =4  if (dev->chip_id < CHIP_RV1126_CIF) {if (dev->inf_id == RKCIF_MIPI_LVDS)stream_num = RKCIF_MAX_STREAM_MIPI;elsestream_num = RKCIF_SINGLE_STREAM;} else {stream_num = RKCIF_MAX_STREAM_MIPI;}/* sensor links(or mipi-phy) */for (s = 0; s < dev->num_sensors; ++s) {/*已经知道 mipi csi的subdev 存储在 cif_dev->sensors[] 数组中*/struct rkcif_sensor_info *sensor = &dev->sensors[s];struct rkcif_sensor_info linked_sensor;//用来代表 mipi csi 信息struct media_entity *source_entity, *sink_entity;linked_sensor.lanes = sensor->lanes;//拿到 mipi csi 的 subdev(描述一个V4L2子设备 )linked_sensor.sd = sensor->sd;...//遍历 mipi csi 模块抽象的 五个 端口抽象 四个source,1个linkfor (pad = 0; pad < linked_sensor.sd->entity.num_pads; pad++) {//目标是 四个sourceif (linked_sensor.sd->entity.pads[pad].flags &MEDIA_PAD_FL_SOURCE) {if (pad == linked_sensor.sd->entity.num_pads) {dev_err(dev->dev,"failed to find src pad for %s\n",linked_sensor.sd->name);break;}...for (id = 0; id < stream_num; id++) {//拿到 mipi csi 模块抽象source_entity = &linked_sensor.sd->entity;// struct video_device 用于创建和管理V4L2设备的结构/*struct rkcif_devicestruct rkcif_stream		stream[RKCIF_MULTI_STREAMS_NUM]; //理解为四个流,每个流代表一个 video_device 设备struct rkcif_vdev_node		vnode;struct video_device vdev;//每个流代表一个 video_device 设备struct media_entity entity; //每个  video_device 设备 的模块抽象*/sink_entity = &dev->stream[id].vnode.vdev.entity;if ((dev->chip_id != CHIP_RK1808_CIF &&dev->chip_id != CHIP_RV1126_CIF &&dev->chip_id != CHIP_RV1126_CIF_LITE &&dev->chip_id != CHIP_RK3568_CIF) ||(id == pad - 1 && !mipi_lvds_linked))flags = MEDIA_LNK_FL_ENABLED;elseflags = 0;//ret = media_create_pad_link(source_entity,pad,sink_entity,0,flags);}}}}...return 0;
}/*工作mipi csi link                       		rkcif_mipi  /dev/videoX |----------------------------------|    	|---------------------------|mipi csi					    	|  #-------------# #-------------# |    	|		media_device        |       |----------------------------------|	    +---|->| source pad  | | | sink  pad |-|---+    |							|      |    entity                     	  |	    |	|  #-------------# #-------------# |   | 	|		#------------#   	| |                 #-------------#  |     |  	|----------------------------------|   | 	|	    |  entity    |      | |                 | sourceX pad |--|---->|	                                       | 	| #-----------#      |      |  	|                 #-------------#  |	    |		mipi csi link                      +->--| | link pad  |      |     	|  |                 				  |	    |	|----------------------------------|   |	| #-----------#      |	    | |   #----------#  				--|-    |	|  #-------------# #-------------# |   |    |		|            |      | ---|-->| sink pad |  				  |     +---|->| source pad  | | | sink  pad |-|---+    |		#------------#      | |   #----------#  				  |     	|  #-------------# #-------------# |        |		                    | |                 				--|-      	|----------------------------------|        |---------------------------| |                 				  |		|                 				  | 	...| 				 				--|-	...|                 				  |		...|----------------------------------|		...此时 mipi csi 设备抽象   ----    mipi csi   抽象链接  ----   rkcif_mipi设备抽象----    mipi csi 反向抽象链接  ----关联 这两个link : link和backlink*/
int media_create_pad_link(struct media_entity *source, u16 source_pad,struct media_entity *sink, u16 sink_pad, u32 flags)
{struct media_link *link;struct media_link *backlink;BUG_ON(source == NULL || sink == NULL);BUG_ON(source_pad >= source->num_pads);BUG_ON(sink_pad >= sink->num_pads);/*参数 子设备 mipi csi 的entity中的 links创建子设备的 entity	的连接抽象(media_link) struct media_entity {                             struct media_link {struct list_head links;	-----------创建绑定---------->struct list_head list;并返回 media_link*/link = media_add_link(&source->links);if (link == NULL)return -ENOMEM;//初始化 子设备的entity中的 连接抽象(media_link) 	/* 	 										链接管道 子设备 mipi csi -----  正向link ----- rkcif_mipi( dev/deviceX)rkcif_mipi  /dev/videoX|---------------------------|	|		media_device        |  	mipi csi																	|							|  |----------------------------------|			mipi csi link                       	|		#------------#   	|  |    entity                     	  |		|----------------------------------|    	|	    |  entity    |      ||                 #-------------#  | 	|  #-------------# #-------------# |    	| #-----------#      |      |       |                 | sourceX pad |--|-----|->| source pad  | | | sink  pad |-|------->| | link pad  |      |     	|      |                 #-------------#  |		|  #-------------# #-------------# |    	| #-----------#      |	    ||                 				  |	  	|----------------------------------|    	|		|            |      |  |   #----------#  				--|-	                                        	|		#------------#      |  	---|-->| sink pad |  				  | 	                                        	|		                    |  |   #----------#  				  | 	                                        	|---------------------------|  |                 				--|-	|                 				  |		|                 				  | 	| 				 				--|-	|                 				  |		|----------------------------------|		*/                                                                          link->source = &source->pads[source_pad];                                      										link->sink = &sink->pads[sink_pad];link->flags = flags & ~MEDIA_LNK_FL_INTERFACE_LINK;/* Initialize graph object embedded at the new link 绑定 子设备 mipi csi -----  link ----- 多媒体设备struct csi2_devstruct v4l2_subdev sd;          绑定 entity---linkstruct media_entity entity;		|	struct media_linkstruct list_head links; ---------> 	struct list_head list; struct media_gobj graph_obj;struct media_device	*mdev------+    struct list_head	list; -----|--->-+|     |struct media_gobj graph_obj;                   绑定 多媒体设备--link   |     |struct media_device	*mdev;	-----------------------------------+     | 挂载到多媒体设备中的 links 链表struct list_head links; ------------------<----------------------+*/media_gobj_create(source->graph_obj.mdev, MEDIA_GRAPH_LINK,&link->graph_obj);//关于反向链接 /* struct csi2_devstruct v4l2_subdev	sd;                        	反向linkstruct media_entity entity;				 struct media_link {struct list_head links;-----创建绑定-----> struct list_head list;*/backlink = media_add_link(&sink->links);if (backlink == NULL) {__media_entity_remove_link(source, link);return -ENOMEM;}/*链接管道 子设备 mipi csi -----  反向link ----- mipi csi phy rkcif_mipi  /dev/videoX|---------------------------|	|		media_device        |  	mipi csi																	|							|  |----------------------------------|			mipi csi back link                      |		#------------#   	|  |    entity                     	  |		|----------------------------------|    	|	    |  entity    |      ||                 #-------------#  | 	|  #-------------# #-------------# |    	| #-----------#      |      |       |                 | sourceX pad |--|-----|->| source pad  | | | sink  pad |-|------->| | link pad  |      |     	|      |                 #-------------#  |		|  #-------------# #-------------# |    	| #-----------#      |	    ||                 				  |	  	|----------------------------------|    	|		|            |      |  |   #----------#  				--|-	                                        	|		#------------#      |  	---|-->| sink pad |  				  | 	                                        	|		                    |  |   #----------#  				  | 	                                        	|---------------------------|  |                 				--|-	|                 				  |		|                 				  | 	| 				 				--|-	|                 				  |		|----------------------------------|		*/backlink->source = &source->pads[source_pad];backlink->sink = &sink->pads[sink_pad];backlink->flags = flags;backlink->is_backlink = true;/* 绑定 子设备 mipi csi -----  反向link ----- 多媒体设备struct csi2_devstruct v4l2_subdev	sd;              绑定 entity---backlinkstruct media_entity entity;         	|       struct media_link {struct list_head links;	---创建绑定--->	struct list_head list;struct media_gobj graph_obj------+struct list_head	list; ---|------+|      |struct media_gobj graph_obj	                           绑定 多媒体设备--backlink |      |struct media_device	*mdev; --------------------------------------------------+      | 挂载到多媒体设备中的 links 链表struct list_head links ---------------------------------------------------------+*/media_gobj_create(sink->graph_obj.mdev, MEDIA_GRAPH_LINK,&backlink->graph_obj);/*    * link和backlink关联起来*/link->reverse = backlink;backlink->reverse = link;sink->num_backlinks++;sink->num_links++;source->num_links++;return 0;
}
EXPORT_SYMBOL_GPL(media_create_pad_link);

相关内容

热门资讯

AWSECS:访问外部网络时出... 如果您在AWS ECS中部署了应用程序,并且该应用程序需要访问外部网络,但是无法正常访问,可能是因为...
AWSElasticBeans... 在Dockerfile中手动配置nginx反向代理。例如,在Dockerfile中添加以下代码:FR...
银河麒麟V10SP1高级服务器... 银河麒麟高级服务器操作系统简介: 银河麒麟高级服务器操作系统V10是针对企业级关键业务...
北信源内网安全管理卸载 北信源内网安全管理是一款网络安全管理软件,主要用于保护内网安全。在日常使用过程中,卸载该软件是一种常...
AWR报告解读 WORKLOAD REPOSITORY PDB report (PDB snapshots) AW...
AWS管理控制台菜单和权限 要在AWS管理控制台中创建菜单和权限,您可以使用AWS Identity and Access Ma...
​ToDesk 远程工具安装及... 目录 前言 ToDesk 优势 ToDesk 下载安装 ToDesk 功能展示 文件传输 设备链接 ...
群晖外网访问终极解决方法:IP... 写在前面的话 受够了群晖的quickconnet的小水管了,急需一个新的解决方法&#x...
不能访问光猫的的管理页面 光猫是现代家庭宽带网络的重要组成部分,它可以提供高速稳定的网络连接。但是,有时候我们会遇到不能访问光...
Azure构建流程(Power... 这可能是由于配置错误导致的问题。请检查构建流程任务中的“发布构建制品”步骤,确保正确配置了“Arti...