Decoding of the camera driver framework based on the Linux 3.0.8 Samsung FIMC (s5pv210)

Source: Internet
Author: User
Tags goto

Splashing splashing liukun321

From: http://blog.csdn.net/liukun321


FIMC the name should be from the beginning of the s5p100, the definition in s5pv210 is the camera interface, but it also has the role of color space conversion image data. The exynos4412 definition looks clearer, and the camera interface is defined as Fimc-lite. The hardware structure of the color space conversion is defined as Fimc-is. Not much to say, let's take a look at Linux3.0.8 Samsung's BSP package with FIMC driver-related files.



The above source files make up the entire FIMC driver framework. The naming of the. c file can also roughly guess several uses of FIMC:

1,Capture , camera Interface for control camera, and to operate

2,Output, this use can be simply regarded as: only use the FIMC function, here FIMC is actually a color space conversion function of high-speed DMA.

3,Overlay, such as Android Overlay rely on the fimc of this function, you can simply think of it as a m2fb, of course, in essence, or.

The general purpose of the FIMC is clear. Again, what role does each C file play in the FIMC driver framework:

csis.c file, the camera device for the MIPI interface, there's not much to say anymore.

fimc_dev.c is an abstraction of the top layer of the FIMC hardware device in the drive, which is described in more detail later.

fimc_v4l2.c Linux drives, the FIMC device's functional Operation interface (Capture,output,overlay) is encapsulated with the V4L2 framework. In the application layer with the camera device, or in the application layer using the FMIC device to complete the user-friendly operation of the friends should be clear, FIMC through the layer of packaging, the final exposure to users space is V4L2 standard interface device file VideoX. This also leads to a question that we should be concerned about: How the FIMC device is associated with the camera device on the software layer.

The fimc_capture.c implements a control operation on the camera Interface, which is based on hardware-related camera drivers (eg.ov965x.c/ov5642.c, etc.). and provide the following function interfaces, further encapsulated by the fimc_v4l2.c file

int fimc_g_parm (struct file *file, void*fh, struct v4l2_streamparm *a)

int fimc_s_parm (struct file *file, void*fh, struct v4l2_streamparm *a)

Intfimc_queryctrl (struct file *file, void *fh, struct V4l2_queryctrl *qc)

Intfimc_querymenu (struct file *file, void *fh, struct v4l2_querymenu *qm)

Intfimc_enum_input (struct file *file, void *fh, struct v4l2_input *inp)

Intfimc_g_input (struct file *file, void *fh, unsigned int *i)

Intfimc_release_subdev (struct Fimc_control *ctrl)

Intfimc_s_input (struct file *file, void *fh, unsigned int i)

Intfimc_enum_fmt_vid_capture (struct file *file, void *fh,struct v4l2_fmtdesc *f)

Intfimc_g_fmt_vid_capture (struct file *file, void *fh, struct v4l2_format *f)

Intfimc_s_fmt_vid_capture (struct file *file, void *fh, struct v4l2_format *f)

Intfimc_try_fmt_vid_capture (struct file *file, void *fh, struct v4l2_format *f)

Intfimc_reqbufs_capture (void *fh, struct v4l2_requestbuffers *b)

Intfimc_querybuf_capture (void *fh, struct v4l2_buffer *b)

Intfimc_g_ctrl_capture (void *fh, struct V4l2_control *c)

Intfimc_s_ctrl_capture (void *fh, struct V4l2_control *c)

Intfimc_s_ext_ctrls_capture (void *fh, struct v4l2_ext_controls *c)

Intfimc_cropcap_capture (void *fh, struct v4l2_cropcap *a)

Intfimc_g_crop_capture (void *fh, struct v4l2_crop *a)

Intfimc_s_crop_capture (void *fh, struct v4l2_crop *a)

Intfimc_start_capture (struct Fimc_control *ctrl)

Intfimc_stop_capture (struct Fimc_control *ctrl)

Intfimc_streamon_capture (void *fh)

Intfimc_streamoff_capture (void *fh)

Intfimc_qbuf_capture (void *fh, struct v4l2_buffer *b)

Intfimc_dqbuf_capture (void *fh, struct v4l2_buffer *b)

fimc_output.c Implementation of FIMC, the need to use FIMC to achieve the hardware color space conversion, the function of this file is sent, in addition, in the FIMC for capture and overlay process in nature also contains the operation of the work. Therefore, in addition to providing a functional interface, further encapsulation by the fimc_v4l2.c file. A number of function functions are also provided for FIMC_DEV.C calls, such as srcaddr (source address) and dstaddr (destination) for setting up a process. This part of the interface too much will not be posted out.

fimc_overlay.c implements FIMC overlay operation. also provides a function interface, further encapsulated by the fimc_v4l2.c file.

FIMC_REGS.C FIMC hardware-related operations, basic register configuration, etc. This file provides a function interface for fimc_capture.c,fimc_output.c,fimc_overlay.c called.

Through the analysis just now, we can summarize the following source code structure diagram:


Well, the framework has, and then look at the source is much easier

Next, let's look at the registration process for the FIMC device. Take FIMC-0 For example, say/dev/video0 This device file is how to come out.

Let's look at a few key structures:

The first is S3C_PLATFORM_FIMCFIMC_PLAT_LSI, the data structure of the abstract FIMC module, and Fimc_plat_lsi also contains a. Camera member. The structure is initialized as follows

static struct S3C_PLATFORM_FIMC  Fimc_plat_lsi = {. Srclk_name= "MOUT_MPLL",. Clk_name= "Sclk_fimc",. Lclk_name= " Fimc ",. clk_rate= 166750000, #if defined (CONFIG_VIDEO_S5K4EA). default_cam= Camera_csi_c, #else #ifdef Cam_itu_ch_ A.default_cam= camera_par_a, #else. default_cam= Camera_par_b, #endif #endif.camera= {#ifdef CONFIG_VIDEO_S5K4ECGX &S5K4ECGX, #endif #ifdef config_video_s5ka3dfx&s5ka3dfx, #endif #ifdef CONFIG_VIDEO_S5K4BA&S5K4BA, #endif #ifdef Config_video_s5k4ea&s5k4ea, #endif #ifdef config_video_tvp5150&tvp5150, #endif #ifdef config_video_ ov9650&ov9650, #endif},.hw_ver= 0x43,};

You can see that there is a camera member in S3C_PLATFORM_FIMC. Here's a look at ov9650. Expand ov9650


static struct S3c_platform_camera ov9650 = {#ifdef cam_itu_ch_a.id= camera_par_a, #else. id= camera_par_b, #endif. type= cam_type_itu,.fmt= itu_601_ycbcr422_8bit,.order422= cam_order422_8bit_ycbycr,.i2c_busnum= 0,.info= &ov9650_i2c _info,.pixelformat= v4l2_pix_fmt_yuyv,.srclk_name= "MOUT_MPLL",/*. srclk_name= "Xusbxti", */.clk_name= "sclk_cam1",. clk_rate= 40000000,.line_length= 1920,.width= 1280,.height= 1024,.window= {. left= 0,.top= 0,.width= 1280,.height= 1024, },/* polarity */.inv_pclk= 1,.inv_vsync= 1,.inv_href= 0,.inv_hsync= 0,.initialized= 0,.cam_power= ov9650_power_en,};

This structure realizes the abstraction of the hardware structure of the OV9650 camera. The key parameters and basic characteristics of the camera are defined.

Because the FIMC device is loaded as a platform device in the linux3.0.8 kernel, the S3c_platform_fimcfimc_plat_lsi mentioned above is only the abstract data of FIMC and not the device. This requires that the abstract FIMC structure be used as a private data of the FIMC Platform_device. So there is the following process. The S3C_PLATFORM_FIMCFIMC_PLAT_LSI structure is passed in as an argument in the board-level device initialization xxx_machine_init (void) process as a s3c_fimc0_set_platdata. Then Fimc_plat_lsi became the FIMC device.Platform_data.


S3c_fimc0_set_platdata (&FIMC_PLAT_LSI); S3c_fimc1_set_platdata (&FIMC_PLAT_LSI); S3c_fimc2_set_platdata ( &FIMC_PLAT_LSI);

Take S3c_fimc0_set_platdata as an example to expand


void __init s3c_fimc0_set_platdata (struct S3C_PLATFORM_FIMC *pd) {struct S3C_PLATFORM_FIMC *npd;if (!pd) PD = & DEFAULT_FIMC0_DATA;NPD = Kmemdup (PD, sizeof (struct S3C_PLATFORM_FIMC), Gfp_kernel), if (!NPD) printk (kern_err "%s:no Memory for platform data\n ", __func__), else {if (!npd->cfg_gpio) Npd->cfg_gpio = s3c_fimc0_cfg_gpio;if (!npd-> clk_on) npd->clk_on = s3c_fimc_clk_on;if (!npd->clk_off) Npd->clk_off = S3c_fimc_clk_off;npd->hw_ver = 0x45 ;/* Starting Physical Address of memory Region */npd->pmem_start = S5p_get_media_memory_bank (s5p_mdev_fimc0, 1);/* Siz E of memory Region */npd->pmem_size = S5p_get_media_memsize_bank (s5p_mdev_fimc0, 1); s3c_device_fimc0.dev.platform_ data = NPD;}}

The last sentence is the key s3c_device_fimc0.dev.platform_data = NPD;

Take a look at the S3C_DEVICE_FIMC0 definition:


struct Platform_device s3c_device_fimc0 = {. Name= "S3c-fimc",. id= 0,.num_resources= array_size (S3c_fimc0_resource),. Resource= S3c_fimc0_resource,};

FIMC's abstract data is included in the S3C_DEVICE_FIMC0 structure as its private data. The final definition of the FIMC platform device was completed here. The definition of this platform device is s3c_device_fimc0 added to the Platform_device list of the entire hardware platform and eventually calls Platform_add_devices in the xxx_machine_init (void) function (  Mini210_devices, Array_size (mini210_devices)); Complete registration of all Platform_device:


static struct Platform_device *mini210_devices[] __initdata = {&S3C_DEVICE_ADC,&S3C_DEVICE_CFCON,&S3C_ Device_nand,。。。 &s3c_device_fb,&mini210_lcd_dev, #ifdef CONFIG_VIDEO_FIMC&S3C_DEVICE_FIMC0,&S3C_DEVICE_FIMC1, &S3C_DEVICE_FIMC2,}

Platform_add_devices (Mini210_devices, Array_size (mini210_devices));

Platform_deviceafter being loaded, wait for it to match thePlatform_driver. If thisFIMC Driverthe driver module is loaded. This time,fimc_dev.cin the file.static int __devinit fimc_probe (structplatform_device *pdev)function to play.


static int __devinit fimc_probe (struct platform_device *pdev) {struct S3C_PLATFORM_FIMC *pdata;struct fimc_control *ctrl ; struct CLK *srclk;int ret;if (!fimc_dev) {Fimc_dev = Kzalloc (sizeof (*fimc_dev), gfp_kernel); if (!fimc_dev) {Dev_err (& Amp;pdev->dev, "%s:not enough memory\n", __func__); return-enomem;}} CTRL = Fimc_register_controller (Pdev), if (!ctrl) {PRINTK (kern_err "%s:cannot register fimc\n", __func__); Goto Err_alloc ;} pdata = To_fimc_plat (&pdev->dev), if (Pdata->cfg_gpio) Pdata->cfg_gpio (Pdev), #ifdef regulator_fimc/* Get FIMC Power domain Regulator */ctrl->regulator = regulator_get (&pdev->dev, "PD"); if (Is_err (ctrl-> Regulator) {Fimc_err ("%s:failed to get Resource%s\n", __func__, "S3C-FIMC"); return Ptr_err (Ctrl->regulator);} #endif//regulator_fimc/* FIMC Source Clock */srclk = Clk_get (&pdev->dev, pdata->srclk_name); if (Is_err (SRCLK ) {Fimc_err ("%s:failed to get source clock of fimc\n", __func__); goto ERR_V4L2;} /* FIMC Clock */CTRL-&GT;CLK = Clk_get (&pdev->dev, Pdata->clk_name), if (Is_err (CTRL-&GT;CLK)) {Fimc_err ("%s:failed to get FIMC clock source \ n ", __func__); goto ERR_V4L2;} /* Set Parent for MCLK */clk_set_parent (CTRL-&GT;CLK, SRCLK);/* set rate for MCLK */clk_set_rate (CTRL-&GT;CLK, Pdata->c Lk_rate);/* V4l2 Device-subdev Registration */ret = V4l2_device_register (&pdev->dev, &ctrl->v4l2_dev); if (ret) {fimc_err ("%S:V4L2 Device Register failed\n", __func__); goto ERR_FIMC;} /* Things to initialize once */if (!fimc_dev->initialized) {ret = Fimc_init_global (Pdev); if (ret) goto ERR_V4L2;} /* Video Device Register */ret = Video_register_device (CTRL-&GT;VD, Vfl_type_grabber, ctrl->id); if (ret) {fimc_err ("% S:cannot Register Video driver\n ", __func__); goto ERR_V4L2;} Video_set_drvdata (CTRL-&GT;VD, ctrl), ret = Device_create_file (& (Pdev->dev), &dev_attr_log_level), if (ret < 0) {Fimc_err ("failed to add Sysfs entries\n"); goto Err_global;} PRINTK (kern_info "fimc%d registered successfully\n", CTRL-&GT;ID); return 0;err_global:video_unregister_device (CTRL-&GT;VD); Err_v4l2:v4l2_device_unregister (& Ctrl->v4l2_dev); Err_fimc:fimc_unregister_controller (Pdev); Err_alloc:kfree (Fimc_dev); return-einval;}

There is a section in the Fimc_probe function

if (!fimc_dev->initialized) {                   ret = Fimc_init_global (Pdev);                   if (ret)                            goto err_v4l2;         }


This code executes the procedure: first to determine whether the FIMC has been initialized (at this point Fimc is busy), if not initialized, execute Fimc_init_global (Pdev), function, Its function is to determine whether the camera structure is initialized in the platform data (that is, the previously mentioned. Camera member), get the camera clock frequency from the platform data, and save the S3c_platform_camera structure data embedded in the platform data to the driver module global FIMC_ Dev, interested friends can expand this function to see, here is no longer posted.

This code is followed by a two very critical process:

Ret= V4l2_device_register (&pdev->dev, &ctrl->v4l2_dev);         if (ret) {                   fimc_err ("%s:v4l2device register failed\n", __func__);                   Goto ERR_FIMC;         }


The core of this function completes the initialization of the V4l2_dev->subdev-Link header and associates the Ctrl->v4l2_dev with the Driver_data member of the private data of the PDEV->DEV structure (that is, the pdev-> Dev->p->driver_data= ctrl->v4l2_dev; ), which is the process of registering v4l2_dev to the kernel structure.

Ret= Video_register_device (CTRL->VD, Vfl_type_grabber, ctrl->id);         if (ret) {                   fimc_err ("%s:cannotregister video driver\n", __func__);                   Goto err_v4l2;         }          Video_set_drvdata (CTRL->VD, ctrl);          ret = Device_create_file (& (Pdev->dev), &dev_attr_log_level);


The above procedure completes the registration of the Video_device device and generates a corresponding property file in the Sys directory. If the system is ported with Mdev, the corresponding device node/dev/videox will be generated.

In fact, so far, only completed the FIMC device primary data structure initialization and registration, almost no operation of the FIMC or camera hardware register. There is also no software association to complete the driver module for the FIMC drive and the camera. How can we control the effect of the camera device by simply operating the FIMC device node/dev/videox? Tell ...

Related Article

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.