Linux下v4l2-camera子系统分析之初始(一)

Linux下v4l2-camera子系统分析之初始(一)
平台:君正x1000
linux kernel: 3.10
camera sensor:ov7725
参考:
https://www.cnblogs.com/rongpmcu/p/7662738.html
https://www.cnblogs.com/rongpmcu/p/7662741.html
https://www.cnblogs.com/rongpmcu/p/7662745.html
https://blog.csdn.net/hp0773/article/details/49968063

首先理解几个名词:
camera:即整个做好摄像头模块,一般有mipi、lvds等接口,usb接口比较特殊暂不考虑。
sensor:即嵌入进camera内部的传感器,一般是i2c接口。
host:即cpu内部的模块控制器。
在学习中看到下图的结构比较明了,也贴出来。
Linux下v4l2-camera子系统分析之初始(一)_第1张图片
从上图我们可以看从,camera子系统分为camera_host和camera_device,并且是基于v4l2框架的,那么它就和v4l2联系紧密,那么我们来理解soc_camera_host,soc_camera_device,v4l2_device,v4l2_subdev之间的关系:
soc_camera_host可以看作是cpu内部的camera控制器,soc_camera_device可以看作是物理接口,接口上挂camera设备。
理论上系统内可以有多个soc_camera_host,驱动是由平台厂商实现的,向上实现soc_camera_host_ops接口,向下操作Camera host硬件以及通过平台特定的接口操作Soc camera device,每个soc_camera_host对应一个v4l2_device, 一个soc_camera_host可以对应多个soc_camera_device,系统会为他们创建设备节点/dev/videoX。
v4l2_subdev可以是camera内部的sensor、video AD芯片,每个soc_camera_device可以管理多个v4l2_subdev。
v4l2_subdev可以通过i2c挂接到v4l2_device,也可以通过soc_camera_link提供的add_device来增加,这依赖于sensor和video AD芯片挂接到MCU camera接口的方式。
再认识几个结构体,记住这几个结构体的成员及字节对齐方式,再后面的系统分析中很重要。

/*   \include\media\soc_camera.h   */
struct soc_camera_link {
/*  Subdevice part - 与struct soc_camera_subdev_desc 兼容*/
	unsigned long flags;
	void *priv;
	struct regulator_bulk_data *regulators;
	int num_regulators;
	int (*power)(struct device *, int);
	int (*reset)(struct device *);
	int (*set_bus_param)(struct soc_camera_link *, unsigned long flags);
	unsigned long (*query_bus_param)(struct soc_camera_link *);
	void (*free_bus)(struct soc_camera_link *);
	
	/*   Host part – 与 struct soc_camera_host_desc兼容    */
	int bus_id;  /* soc camera host总线 */ 
	int i2c_adapter_id; 
	struct i2c_board_info *board_info;
	const char *module_name;
	int (*add_device)(struct soc_camera_device *);
	void (*del_device)(struct soc_camera_device *);
};

以上struct soc_camera_link结构有15*4=60个字节,在系统实现中会被拆分为以下结构体,注释中也表明了兼容以下结构体,正好字节对齐。

struct soc_camera_desc {
	struct soc_camera_subdev_desc	 subdev_desc;
	struct soc_camera_host_desc	 host_desc;
};
struct soc_camera_subdev_desc subdev_desc
{
	unsigned long flags;
	void *priv;
	struct regulator_bulk_data *regulators;
	int num_regulators;
	int (*power)(struct device *, int);
	int (*reset)(struct device *);
	int (*set_bus_param)(struct soc_camera_link *, unsigned long flags);
	unsigned long (*query_bus_param)(struct soc_camera_link *);
	void (*free_bus)(struct soc_camera_link *);
}
struct soc_camera_host_desc host_desc
{ 
	int bus_id; /* soc camera host总线 */ 
	int i2c_adapter_id;
	struct i2c_board_info *board_info;
	const char *module_name;
	int (*add_device)(struct soc_camera_device *);
	void (*del_device)(struct soc_camera_device *);
}

struct soc_camera_device管理其下挂接的sensor

struct soc_camera_device {
	struct list_head list;		/* list of all registered devices */
	struct soc_camera_desc *sdesc;
	struct device *pdev;		/* Platform device */
	struct device *parent;		/* Camera host device */
	struct device *control;		/* E.g., the i2c client */
	s32 user_width;
	s32 user_height;
....
}

你可能感兴趣的:(linux,v4l2-camera,linux,嵌入式)