Android camera (III): Camera v4l2 fimc

Source: Internet
Author: User

Keywords:Camera Parameter of the android camera CMM module camif v4l2
Platform information:
Kernel:
Linux
System:Android

Platform:S5pv310 (Samsung exynos 4210)

Author: xubin341719 (You are welcome to reprint it. Please note the author)

Android camera (1): CMM introduction to the camera Module

Android camera (II): Camera working principle, s5pv310 camera interface (camif)

Android camera (III): Camera v4l2 fimc

Android camera (iv): camera driver gt2005

Download: Common camera specifications (some Android drivers): Bf3703 30 W, gc0308 30 W, ov7670, gt2005 200 W, gt2015 200 W, nt99250 200 W, s5k5ba 200 W, s5k4ba

I have mentioned a little more in the previous two articles, but it is good to know more about things. When you encounter problems, you can have more ideas. The real driver starts from this one. In general, BSP's camera is intact. We only need to care about the driver.

1. v4l2

1) Introduction

In Linux, the camera has a high degree of standardization, which is the v4l2 driver, which is also recognized in the industry.

V4l is short for video for Linux. It is a standard video driver in Linux kernel. Currently, video for Linux 2 (v4l2 for short) is used in many versions. It provides a unified interface for the video driver in Linux, so that applications can use a unified API to operate different video devices. From kernel space to user space, the main data stream and control classes are defined by the framework of the v4l2 driver.

V4l2 drivers generally only provide video data, but how to implement video preview, how to send data to the upper layer, and how to organize actual services such as pure video stream, viewfinder, and video recording, all work that camera's Hardware Abstraction Layer is responsible.

The core implementation of the v4l2 driver is the following file: Drivers/Media/Video/v4l2-dev.c.

The video_device defined in the V4l2-dev.h is the core data structure of the v4l2 driver, which provides interface calls for the specific camera sensor driver.

Collection Process of v4l2 (Application ):

1) Open the device and obtain the file descriptor;

2) set the image format;

3) allocate a buffer;

4) Start the collection process and read data;

5) Stop collection and disable the device.

 

2) Data Structure

The main data structure of v4l2 is video_device, which is defined in v4l2_dev.h:

Struct video_device {/* Device ops */const struct v4l2_file_operations * fops;/* interface function pointer * // * sysfs */struct device dev; /* v4l device structure */struct cdev * cdev;/* character device structure * // * set either parent or v4l2_dev if your driver uses v4l2_device */struct device * parent; /* Device parent pointer */struct v4l2_device * v4l2_dev;/* v4l2 device pointer */* Device info */Char name [32];/* device name */INT vfl_type; /* 'minor' is set to-1 if the registration failed */INT minor;/* times the device Number */2010num; /* use bitops to set/clear/test flags */unsigned long flags;/* attribute to differentiate multiple indices on one physical device */INT index; /* v4l2 file handles */spinlock_tfh_lock;/* lock for all v4l2_fhs */struct list_headfh_list;/* List of struct v4l2_fh */INT debug; /* debug level * // * video standard variable */v4l2_std_id tvnorms;/* supported TV norms */v4l2_std_id current_norm; /* Current tvnorm * // * callback function */void (* release) (struct video_device * vdev);/* IOCTL callback function */const struct v4l2_ioctl_ops * ioctl_ops ;};

Main interface functions include:

Intvideo_register_device (struct video_device * vdev, int type, int nr );

Static intv4l2_ioctl (struct inode * inode, struct file * filp, unsigned int cmd, unsigned long Arg );

2. fimc

1) Introduction

The fimc module is not only a control interface of the camera, but also the output and overlay functions of v4l2.

Position of the fimc driver in the kernel: Drivers/Media/Video/Samsung/fimc

It contains the following files:

Fimc_regs.c
Fimc_capture.c
Fimc_dev.c
Fimc_output.c
Fimc_overlay.c
Fimc_v4l2.c

Their organizational relationships are as follows:

It can be seen that the fimc driver implements all the interfaces of v4l2, which can be divided into v4l2-input device interface, v4l2-output device interface and v4l2-overlay device interface. Here we focus on the v4l2-input device interface, because the camera is a video input device.

Fimc_v4l2.c registers many callback functions to implement the standard interfaces of v4l2. However, these callback functions are basically not implemented in fimc_v4l2.c, but are implemented accordingly. C is implemented separately. For example:

Operation Implementation of v4l2-input equipment: fimc_capture.c
Operation Implementation of v4l2-output equipment: fimc_output.c
Operation Implementation of v4l2-overlay equipment: fimc_overlay.c

These codes are not related to specific hardware operations. This driver writes all the code for operating the hardware register to a file, which is fimc40_regs.c. In this way, the hardware-related code and hardware-independent code are separated to implement code reuse to the maximum extent.

2) Data Structure

 

The main data structure fimc_control of fimc is defined in fimc. h:

Struct fimc_control {intid;/* controller ID */charname [16]; atomic_tin_use; void _ iomem * regs;/* Register I/O */struct CLK * CLK; /* interface clock */struct regulator * regulator;/* PD regulator */struct fimc_meminfomem;/* for reserved mem */* kernel helpers */struct mutexlock; /* controller lock */struct mutexalloc_lock; struct mutexv4l2_lock; wait_queue_head_twq; struct device * dev; intirq;/* v4l2 related */struct video_device * vd; struct cancel; /* fimc specific */struct fimc_limit * limit;/* H/W limitation */struct initi_platform_camera * Cam;/* activated camera */struct fimc_capinfo * cap; /* capture dev info */struct fimc_outinfo * out;/* output dev info */struct fimc_fbinfofb;/* fimd info */struct fimc_scalersc;/* scaler info */struct fimc_effectfe; /* fimc effect info */Enum fimc_statusstatus; Enum fimc_loglog; u32ctx_busy [fimc_max_ctxs];};

Because fimc has three identical controllers (fimc0, fimc1, fimc2), an array is used to describe the driver:

struct video_device fimc_video_device[FIMC_DEVICES] = {[0] = {.fops = &fimc_fops,.ioctl_ops = &fimc_v4l2_ops,.release = fimc_vdev_release,},[1] = {.fops = &fimc_fops,.ioctl_ops = &fimc_v4l2_ops,.release = fimc_vdev_release,},[2] = {.fops = &fimc_fops,.ioctl_ops = &fimc_v4l2_ops,.release = fimc_vdev_release,},};

The fb_ops struct is a basic operation for v4l2 devices. It is defined as follows:

static const struct v4l2_file_operations fimc_fops = {.owner= THIS_MODULE,.open= fimc_open,.release= fimc_release,.ioctl= video_ioctl2,.read= fimc_read,.write= fimc_write,.mmap= fimc_mmap,.poll= fimc_poll,};

3) fimc initial settings

In s5pv210, The fimc initial setup code is in/Drivers/ARCH/ARM/mach-s5pv210/mach-smdkv310.c:

static struct s3c_platform_fimc fimc_plat = {.srclk_name= "mout_mpll",.clk_name= "sclk_fimc",.lclk_name= "sclk_fimc_lclk",.clk_rate= 166750000,.default_cam= CAMERA_CSI_C,     .camera= {&mt9p111,//5M back cam&s5k6aafx,///1.3M front cam},.hw_ver= 0x43,};

The configuration code for gpio is in/Drivers/ARCH/ARM/mach-s5pv210/setup-fimc0.c:

oid s3c_fimc0_cfg_gpio(struct platform_device *pdev){int i = 0;/* CAM A port(b0010) : PCLK, VSYNC, HREF, DATA[0-4] */for (i = 0; i < 8; i++) {s3c_gpio_cfgpin(S5PV210_GPE0(i), S3C_GPIO_SFN(2));s3c_gpio_setpull(S5PV210_GPE0(i), S3C_GPIO_PULL_NONE);}/* CAM A port(b0010) : DATA[5-7], CLKOUT(MIPI CAM also), FIELD */for (i = 0; i < 5; i++) {s3c_gpio_cfgpin(S5PV210_GPE1(i), S3C_GPIO_SFN(2));s3c_gpio_setpull(S5PV210_GPE1(i), S3C_GPIO_PULL_NONE);}/* CAM B port(b0011) : DATA[0-7] */for (i = 0; i < 8; i++) {s3c_gpio_cfgpin(S5PV210_GPJ0(i), S3C_GPIO_SFN(3));s3c_gpio_setpull(S5PV210_GPJ0(i), S3C_GPIO_PULL_NONE);}/* CAM B port(b0011) : PCLK, VSYNC, HREF, FIELD, CLCKOUT */for (i = 0; i < 5; i++) {s3c_gpio_cfgpin(S5PV210_GPJ1(i), S3C_GPIO_SFN(3));s3c_gpio_setpull(S5PV210_GPJ1(i), S3C_GPIO_PULL_NONE);}}

4) interface functions

The main callback function of fimc is as follows, which is implemented in fimc_v4l2.c:

onst struct v4l2_ioctl_ops fimc_v4l2_ops = {.vidioc_querycap= fimc_querycap,.vidioc_reqbufs= fimc_reqbufs,.vidioc_querybuf= fimc_querybuf,.vidioc_g_ctrl= fimc_g_ctrl,.vidioc_s_ctrl= fimc_s_ctrl,.vidioc_s_ext_ctrls= fimc_s_ext_ctrls,.vidioc_cropcap= fimc_cropcap,.vidioc_g_crop= fimc_g_crop,.vidioc_s_crop= fimc_s_crop,.vidioc_streamon= fimc_streamon,.vidioc_streamoff= fimc_streamoff,.vidioc_qbuf= fimc_qbuf,.vidioc_dqbuf= fimc_dqbuf,.vidioc_enum_fmt_vid_cap= fimc_enum_fmt_vid_capture,.vidioc_g_fmt_vid_cap= fimc_g_fmt_vid_capture,.vidioc_s_fmt_vid_cap= fimc_s_fmt_vid_capture,.vidioc_try_fmt_vid_cap= fimc_try_fmt_vid_capture,.vidioc_enum_input= fimc_enum_input,.vidioc_g_input= fimc_g_input,.vidioc_s_input= fimc_s_input,.vidioc_g_parm= fimc_g_parm,.vidioc_s_parm= fimc_s_parm,.vidioc_queryctrl= fimc_queryctrl,.vidioc_querymenu= fimc_querymenu,.vidioc_g_fmt_vid_out= fimc_g_fmt_vid_out,.vidioc_s_fmt_vid_out= fimc_s_fmt_vid_out,.vidioc_try_fmt_vid_out= fimc_try_fmt_vid_out,.vidioc_g_fbuf= fimc_g_fbuf,.vidioc_s_fbuf= fimc_s_fbuf,.vidioc_try_fmt_vid_overlay= fimc_try_fmt_overlay,.vidioc_g_fmt_vid_overlay= fimc_g_fmt_vid_overlay,.vidioc_s_fmt_vid_overlay= fimc_s_fmt_vid_overlay,};

All register operations are performed in the fimc_regs.c file, as shown in figure

int fimc_hwset_camera_source(struct fimc_control *ctrl){struct s3c_platform_camera *cam = ctrl->cam;u32 cfg = 0;cfg |= S3C_CISRCFMT_ITU601_8BIT;cfg |= cam->order422;if (cam->type == CAM_TYPE_ITU)cfg |= cam->fmt;cfg |= S3C_CISRCFMT_SOURCEHSIZE(cam->width);cfg |= S3C_CISRCFMT_SOURCEVSIZE(cam->height);writel(cfg, ctrl->regs + S3C_CISRCFMT);return 0;}int fimc_hwset_enable_irq(struct fimc_control *ctrl, int overflow, int level){u32 cfg = readl(ctrl->regs + S3C_CIGCTRL);cfg &= ~(S3C_CIGCTRL_IRQ_OVFEN | S3C_CIGCTRL_IRQ_LEVEL);cfg |= S3C_CIGCTRL_IRQ_ENABLE;if (overflow)cfg |= S3C_CIGCTRL_IRQ_OVFEN;if (level)cfg |= S3C_CIGCTRL_IRQ_LEVEL;writel(cfg, ctrl->regs + S3C_CIGCTRL);return 0;}

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.