Linux driver programming based on V4L2 framework __linux

Source: Internet
Author: User
V4L2 Linux driver Framework for 6467T VPIF

In Linux, the V4L2 framework is used to manage video capture devices. The V4L2 framework consists mainly of two layers: V4l2device and V4l2 subdevice, where V4L2 device is a virtual device to manage V4l2 Subdevice, and Subdevice is the real physical device, For example, a variety of video ad chips and sensor.


As you can see from the diagram above, there are two ways to write a imagesensor driver, one is to directly imagesensor as a video_device, and the other is to call it a subdevice. Considering that if you write a driver directly as a video_device, you need to deal with some memory management problems yourself, which is more complicated, so we use the second approach. Imagesensor


Write an image sensor driver

Since Linux already has a V4L2 framework for video device drivers, the main function when writing a sensor driver is to initialize it and write API functions.

First, as a v4l2 subdevice, the following functions in the sensor driver must be implemented.

The name of the function

function

__init int E2v570_mod_init ()

Module initialization

__exit void E2v570_mod_exit ()

Clean up memory when module exits

E2v570_probe ()

Probe the device when registering

E2v570_remove ()

Running when removing a device

Then, because vpif to invoke the sensor driver, there are other functions that are used in the process, mainly including the following sections.

The name of the function

function

E2V570_QUERYSTD ()

Query sensor supported video formats

E2v570_s_stream ()

Enable/close sensor output

E2v570_cropcap ()

Get the clipping function of the video

E2V570_S_STD ()

Set the video format for sensor output

In addition, since e2v570 is using the SPI bus to access its registers, it is also necessary to write register access functions, mainly including the following sections.

The name of the function

function

Reg_read ()

Read e2v570 Registers

Reg_write ()

Write e2v570 Registers

E2v570_write_array ()

Write a series of registers to e2v570

Reg_write16 ()

Write 16-bit registers

After you have written all the basic API functions, use the following code to pass these API functions to some structures, and then you can implement the kernel's unified management of all the drivers.


V4L2 Video operation function static const struct V4l2_subdev_video_ops e2v570_subdev_video_ops = {. QUERYSTD = E2v570_query
STD,. s_stream = E2v570_s_stream,. cropcap = E2v570_cropcap,}; V4L2 the core operation function of the sub device static const struct V4l2_subdev_core_ops e2v570_subdev_core_ops = {. S_STD = E2v570_s_st
D,. g_chip_ident = E2v570_g_chip_ident,}; All API static const struct V4l2_subdev_ops E2v570_subdev_ops = {. Core = & E2v570_subdev_co for V4L2 child devices
 
Re_ops,. Video = & E2v570_subdev_video_ops,};
         The structure for the SPI driver, defines the e2v570 SPI device ID, and adds to the SPI device table static const struct SPI_DEVICE_ID e2v570_id[] = {{"e2v570", 0},
{ }
};
Module_device_table (SPI, e2v570_id); The driver function for the SPI device is static struct Spi_driver e2v570_ spi _driver = {. Driver = {. Owner = This_modu            LE,. Name = "e2v570",},. probe = E2v570_probe,. Remove = E2V570_remove,. id_table = e2v570_id,};
Defines the function module_init (E2v570_mod_init) that runs when the module is initialized and exited;
 Module_exit (E2v570_mod_exit);

When the system is powered on, the kernel extracts and runs in memory, and the initialization function in the e2v570 driver E2v570_mod_init () is first invoked, the SPI device and the SPI device driver are added, and then VPIF driver initialization invokes the E2 in the e2v570 driver The V570_probe () function, which initializes a series of e2v570 and registers as a V4L2 child device.

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.