Video Drive V4L2 subsystem driver Architecture-Drive framework

Source: Internet
Author: User
Article series

Video Drive V4L2 subsystem driver Architecture-Drive framework
Video-driven V4L2 subsystem driver architecture-IOCTL

Based on linux4.6.3 V4L2 Drive Framework

V4L2 driver architecture as shown in the picture, V4L2 is the video for Linux two, so that means there is one, v4l2 front and v4l

The chip module corresponds to each of the SOC modules, the VIDEO_DEVICE structure is mainly used to control the SOC video module, V4l2_device will contain multiple v4l2_subdev, each V4l2_subdev to control the respective sub modules, Some drivers do not need v4l2_subdev, and rely on the video module to achieve the function

V4L2 driver code in the Drivers\media\v4l2-core folder, the file looks a lot, but the basic functionality is understood by its literal meaning. VIDEOBUF is the realization of video memory allocation, for V4L2 and v4l respectively corresponding to different files, such as Videobuf-core and Videobuf2-core;v4l2-dev,v4l2-device, V4l2-subdev respectively corresponding to Video_device,v4l2_device, V4l2_subdev implementation, V4L2-IOCTL is to achieve ioctl and so on.

Video driver code in the driver/media/directory, below a lot of subdirectories, platform directory is stored in different SOC driver code, corresponding to Video_device, most other subdirectories such as I2C, MMC, USB, tuners, The realization of radio and other corresponding Subdev

V4L2 Drive Framework The most important thing is to understand IOCTL, another article in this article series will be described in detail, in addition to the V4L2 driver framework is the main function of each IOCTL implementation, these implementations need to be more understanding in the actual operation, not difficult. V4l2 Core Introduction Video_device

Video module for SOC implementation

struct Video_device {#if defined (config_media_controller) struct media_entity;
    struct Media_intf_devnode *intf_devnode;
struct Media_pipeline pipe; #endif/* Device OPS/const struct V4l2_file_operations *fops--------------------------Specific Video module implementation function/* SY      SFS * * struct device dev;      /* v4l Device * * struct CDEV *cdev;   /* character device * *--------------------Upper interface struct V4l2_device *v4l2_dev;  /* V4l2_device Parent/----------v4l2_device/* Only set Parent if this can ' t be deduced from V4l2_dev * * struct  Device *dev_parent; /* Device Parent//////////////* Control handler associated May is NULL.

    * * struct V4l2_ctrl_handler *ctrl_handler; /* Vb2_queue associated with this device node. May is NULL.

    * * struct vb2_queue *queue; /* Priority state. If NULL, then V4l2_dev->prio would be used.

    * * struct v4l2_prio_state *prio;
    /* Device Info */char name[32]; int vfl_type;  /* Device type */int vfl_dir; /* receiver, transmitter or M2M *////* ' minor ' is set to-1 if the registration failed/int minor;---------------
    -----------------------------------------video-x number U16 num;
    /* 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_t fh_lock; /* Lock for all V4L2_FHS */struct list_head fh_list;

    /* List of struct V4L2_FH * * * Internal device Debug flags, not as use by drivers/int dev_debug;        /* Video Standard VARs * * v4l2_std_id tvnorms;

    /* Supported TV norms */////* Callbacks/Void (*release) (struct video_device); /* IOCTL callbacks/const struct V4L2_IOCTL_OPS *ioctl_ops; implementation function for-------------------------specific functions Declare_bitmap (val

    Id_ioctls, base_vidioc_private); /* Serialization Lock */Declare_bitmap (Disable_lockiNg, Base_vidioc_private);
struct Mutex *lock; };

Function Description:

Registration function
static inline int __must_check video_register_device (struct video_device *vdev,
        int type, int nr)
// Uninstall function
void Video_unregister_device (struct video_device *vdev);    
V4l2_device

The implementation of the corresponding sub module, including multiple sub modules

struct V4l2_device {/* Dev->driver_data points to this struct. Note:dev might be NULL if there is no parent device as are the case with e.g. ISA devices.
* * struct device *dev;
#if defined (config_media_controller) struct media_device *mdev;
    #endif/* Used to keep track of the registered Subdevs/struct list_head; /* lock this struct; Can be used by the driver as so if this struct was embedded into a larger struct.
    * * spinlock_t lock;
    /* Unique device name, by default of the driver name + bus ID/char name[v4l2_device_name_size]; /* Notify callback called by some sub-devices.
    */void (*notify) (struct V4l2_subdev *sd, unsigned int notification, void *arg); /* The control handler. May is NULL.
    * * struct V4l2_ctrl_handler *ctrl_handler;
    /* Device ' s priority state */struct v4l2_prio_state prio; /* Keep track of the references to this struct.
    * * struct KREF ref; /* ReleaseThe function is called then the ref count goes to 0.
*/void (*release) (struct v4l2_device *v4l2_dev); };

Function Description:

Registration function
int __must_check v4l2_device_register (struct device *dev, struct v4l2_device);
int __must_check v4l2_device_register_subdev (struct v4l2_device *v4l2_dev, struct V4l2_subdev
                        );
Uninstall function
void V4l2_device_unregister (struct v4l2_device *v4l2_dev);
int __must_check v4l2_device_register_subdev (struct v4l2_device *v4l2_dev, struct V4l2_subdev
                        );
V4l2_subdev

Implementation of specific sub-modules

struct V4l2_subdev {#if defined (config_media_controller) struct media_entity; #endif entity struct list
    ;
    struct module *owner;
    BOOL Owner_v4l2_dev;
    U32 flags;
    struct V4l2_device *v4l2_dev; const struct V4l2_subdev_ops *ops;--------------------------function Implementation function/* Never call this internal ops from within a driv er!
    * * const struct V4L2_SUBDEV_INTERNAL_OPS *internal_ops; /* The control handler of this subdev. May is NULL.
    * * struct V4l2_ctrl_handler *ctrl_handler;
    /* Name must be unique * * Char name[v4l2_subdev_name_size];
    /* can be used to group similar subdevs, the value is driver-specific * * u32 grp_id;
    /* Pointer to private data */void *dev_priv;
    void *host_priv;
    /* Subdev Device node */struct Video_device *devnode;
    /* Pointer to the physical device, if any * struct device *dev; /* The Device_node of the Subdev, usually the same as Dev->of_node.
    * * struct Device_node *of_node;/* Links This subdev to a global subdev_list or @notifier->done list.
    * * struct list_head async_list; /* Pointer to respective struct V4L2_ASYNC_SUBDEV.
    * * struct V4l2_async_subdev *asd; /* Pointer to the managing notifier.
    * * struct v4l2_async_notifier *notifier;
/* Common part of Subdevice platform data */struct v4l2_subdev_platform_data *pdata; };
Each module corresponding to the implementation function
struct V4l2_subdev_ops {
    const struct v4l2_subdev_core_ops   *core;
    const struct V4l2_subdev_tuner_ops  *tuner;
    const struct V4l2_subdev_audio_ops  *audio;
    const struct V4l2_subdev_video_ops  *video;
    const struct V4l2_subdev_vbi_ops    *vbi;
    const struct V4l2_subdev_ir_ops     *ir;
    const struct V4l2_subdev_sensor_ops *sensor;
    const struct V4l2_subdev_pad_ops    *pad;

Function Description:

Registration function
struct V4l2_subdev *v4l2_i2c_new_subdev (struct v4l2_device *v4l2_dev, struct i2c_adapter
        , const char *client_type,
        U8 addr, const unsigned short *probe_addrs);
struct V4l2_subdev *v4l2_spi_new_subdev (struct v4l2_device *v4l2_dev,
        struct spi_master *master, struct spi_board _info *info);

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.