linux驱动编写(摄像头驱动)

【 声明:版权所有,欢迎转载,请勿用于商业用途。 联系信箱:feixiaoxing @163.com

 

    对于现代嵌入式设备,特别是手机来说,摄像头是很重要的一个设备。很多同学买手机,一看颜值,第二就看摄像头拍照如何。所以,从某个角度来说,摄像头是各个厂家主打的应用功能。那么,linux是如何支持摄像头的,我们可以来看一下?

 

1、代码目录地址

drivers/media

 

2、v4l2框架

目前linux上的camera都是按照v4l2框架来设计,它的地址位于drivers/media/v4l2-core

 

3、查看三星soc是如何支持camera的,可以查看drviers/media/platform/Kconfig

config VIDEO_S3C_CAMIF
	tristate "Samsung S3C24XX/S3C64XX SoC Camera Interface driver"
	depends on VIDEO_V4L2 && I2C && VIDEO_V4L2_SUBDEV_API
	depends on PM
	depends on ARCH_S3C64XX || PLAT_S3C24XX || COMPILE_TEST
	depends on HAS_DMA
	select VIDEOBUF2_DMA_CONTIG
	---help---
	  This is a v4l2 driver for s3c24xx and s3c64xx SoC series camera
	  host interface (CAMIF).

	  To compile this driver as a module, choose M here: the module
	  will be called s3c-camif.

 

4、从Kconfig确认除了VIDEO_V4L2和VIDEO_V4L2_SUBDEV_API之外,它只依赖自己的目录

obj-$(CONFIG_VIDEO_S3C_CAMIF)		+= s3c-camif/

 

5、继续查看s3c-camif目录的代码结构

# Makefile for s3c244x/s3c64xx CAMIF driver

s3c-camif-objs := camif-core.o camif-capture.o camif-regs.o

obj-$(CONFIG_VIDEO_S3C_CAMIF) += s3c-camif.o

 

6、Makefile说的很清楚,它主要依赖camif-*.c三个文件

 

通过阅读,确认camif-core.c是注册文件

camif-regs.c是寄存器读写文件

camif-capture.c是主要的操作文件、接口文件

 

7、确认v4l2的函数操作接口

static const struct v4l2_ioctl_ops s3c_camif_ioctl_ops = {
	.vidioc_querycap	  = s3c_camif_vidioc_querycap,
	.vidioc_enum_input	  = s3c_camif_vidioc_enum_input,
	.vidioc_g_input		  = s3c_camif_vidioc_g_input,
	.vidioc_s_input		  = s3c_camif_vidioc_s_input,
	.vidioc_enum_fmt_vid_cap  = s3c_camif_vidioc_enum_fmt,
	.vidioc_try_fmt_vid_cap	  = s3c_camif_vidioc_try_fmt,
	.vidioc_s_fmt_vid_cap	  = s3c_camif_vidioc_s_fmt,
	.vidioc_g_fmt_vid_cap	  = s3c_camif_vidioc_g_fmt,
	.vidioc_g_selection	  = s3c_camif_g_selection,
	.vidioc_s_selection	  = s3c_camif_s_selection,
	.vidioc_reqbufs		  = s3c_camif_reqbufs,
	.vidioc_querybuf	  = s3c_camif_querybuf,
	.vidioc_prepare_buf	  = s3c_camif_prepare_buf,
	.vidioc_create_bufs	  = s3c_camif_create_bufs,
	.vidioc_qbuf		  = s3c_camif_qbuf,
	.vidioc_dqbuf		  = s3c_camif_dqbuf,
	.vidioc_streamon	  = s3c_camif_streamon,
	.vidioc_streamoff	  = s3c_camif_streamoff,
	.vidioc_subscribe_event	  = v4l2_ctrl_subscribe_event,
	.vidioc_unsubscribe_event = v4l2_event_unsubscribe,
	.vidioc_log_status	  = v4l2_ctrl_log_status,
};

and

 static const struct v4l2_file_operations s3c_camif_fops = {
         .owner          = THIS_MODULE,
         .open           = s3c_camif_open,
         .release        = s3c_camif_close,
         .poll           = s3c_camif_poll,
         .unlocked_ioctl = video_ioctl2,
         .mmap           = s3c_camif_mmap,
 };
static const struct vb2_ops s3c_camif_qops = {
	.queue_setup	 = queue_setup,
	.buf_prepare	 = buffer_prepare,
	.buf_queue	 = buffer_queue,
	.wait_prepare	 = vb2_ops_wait_prepare,
	.wait_finish	 = vb2_ops_wait_finish,
	.start_streaming = start_streaming,
	.stop_streaming	 = stop_streaming,
};
const struct vb2_mem_ops vb2_dma_contig_memops = {
	.alloc		= vb2_dc_alloc,
	.put		= vb2_dc_put,
	.get_dmabuf	= vb2_dc_get_dmabuf,
	.cookie		= vb2_dc_cookie,
	.vaddr		= vb2_dc_vaddr,
	.mmap		= vb2_dc_mmap,
	.get_userptr	= vb2_dc_get_userptr,
	.put_userptr	= vb2_dc_put_userptr,
	.prepare	= vb2_dc_prepare,
	.finish		= vb2_dc_finish,
	.map_dmabuf	= vb2_dc_map_dmabuf,
	.unmap_dmabuf	= vb2_dc_unmap_dmabuf,
	.attach_dmabuf	= vb2_dc_attach_dmabuf,
	.detach_dmabuf	= vb2_dc_detach_dmabuf,
	.num_users	= vb2_dc_num_users,
};

 

8、和sd一样,接口比较简单,但是要深入了解camera,v4l2是绕不过去的。

这一点和sd卡、usb、asoc是一样的。

 

你可能感兴趣的:(linux驱动编写)