[2023.7.30]2.2.18 V4L2 Media Controller functions and data structures

int v4l2_mc_create_media_graph(struct media_device *mdev)
Create a connection to the Media Controller on the graph.
parameter
struct media_device *mdev: pointer to the media_device structure.
describe
Add connections between common PC client hardware entities on the V4L2 (Video4Linux2) side:
Camera sensors, audio and video PLL-IF decoders, tuners, analog TV decoders, and I/O entities (video, VBI, and software-defined radio).
Note: Webcams follow a very simple model: the sensor is connected directly to the I/O entity. All details such as scalers and cropping hardware (crop HW) are hidden. While this mapping is sufficient for v4l2 interface-centric PC client hardware, this routine should not be used for V4L2 subdevice-centric camera hardware as it will not build correct graphics.
int v4l_enable_media_source(struct video_device *vdev)
If the media source is free, it is reserved for exclusive use.
parameter
struct video_device *vdev: pointer to struct video_device.
describe
This interface calls the enable_source handler to determine if a media source is free and available. The enable_source handler is responsible for checking if the media source is free and starting a pipeline between the media entities associated with the video device. This interface should be called from the v4l2-core and dvb-core interfaces changing the source configuration.
return value
Returns zero on success, otherwise a negative error code.
void v4l_disable_media_source(struct video_device *vdev)
Release the media source.
parameter
struct video_device *vdev: pointer to struct video_device.
describe
This interface calls the disable_source handler to release the media source. The disable_source handler stops the active media pipeline between the video device’s associated media entity and the media source.
return value
Returns zero on success, otherwise a negative error code.
int v4l2_create_fwnode_links_to_pad(struct v4l2_subdev *src_sd, struct media_pad *sink, u32 flags)
Create fwnode based link from source subdevice to pad of target subdevice.
parameter
struct v4l2_subdev *src_sd: pointer to source subdevice.
struct media_pad *sink: A pointer to the pad of the target sub-device.
u32 flags: Link flags.
describe
This function searches for fwnode endpoint connections from a source subdevice to a single target pad, and translates the appropriate connection into a media link to that pad. This function can be called by the target subdevice in its v4l2-async notifier subdev binding callback to create a link from the bound source subdev.
The flags parameter specifies the flags for the link. The caller should ensure that the flags are valid no matter how many links are created. For example, setting the MEDIA_LNK_FL_ENABLED flag will cause all created links to be enabled, and have no effect if multiple links are created.
NOTE: Any target subdevice that calls this function must implement the .get_fwnode_pad media operation to verify that the endpoint passed to the target is owned by the target.
Returns 0 on success, and a negative error code on failure.
int v4l2_create_fwnode_links(struct v4l2_subdev *src_sd, struct v4l2_subdev *sink_sd)
Creates a fwnode-based link from a source subdevice to a target subdevice.
parameter
struct v4l2_subdev *src_sd: pointer to source subdevice.
struct v4l2_subdev *sink_sd: pointer to the target subdevice.
describe
This function searches for all fwnode endpoint connections between the source subdevice and target subdevice and converts them to media links. This function can be called by the target subdevice in its v4l2-async notifier subdev binding callback to create all links from the bound source subdevice to the target subdev.
NOTE: Any target subdevice that calls this function must implement the .get_fwnode_pad media operation to verify that the endpoint passed to the target is owned by the target.
Returns 0 on success, and a negative error code on failure.
int v4l2_pipeline_pm_get(struct media_entity *entity)
Increment the usage count of the pipe.
parameter
struct media_entity *entity: the root entity of the pipeline.
describe
Updates the usage counts of all entities in the pipeline, and powers on required power entities.
This function is intended to be called when a video node is opened. It uses struct media_entity.use_count to keep track of power state. Use of this function should be used in pairs with v4l2_pipeline_link_notify().
Returns 0 on success, and a negative error code on failure.
void v4l2_pipeline_pm_put(struct media_entity *entity)
Decrease the usage count of the pipe.
parameter
struct media_entity *entity: the root entity of the pipeline.
describe
Updates usage counts for all entities in the pipeline, and turns off power entities that are no longer in use.
This function is intended to be called when the video node is released. It uses struct media_entity.use_count to keep track of power state. Use of this function should be used in pairs with v4l2_pipeline_link_notify().
int v4l2_pipeline_link_notify(struct media_link *link, u32 flags, unsigned int notification)
Link management notification callback function
parameter
struct media_link *link: link object
u32 flags: new link flags to be applied
unsigned int notification: notification type of link state change (MEDIA_DEV_NOTIFY_*)
describe
Responds to link management on started pipelines by updating usage counts for all entities on the source and destination sides. The corresponding entity will be powered on or off. Use of this function should be used in pairs with v4l2_pipeline_pm_{get, put}().
Returns 0 on success, and a negative error code on failure. Powering off entities is assumed to never fail. This function will not fail on a disconnect event.

2.2.19 V4L2 Media Bus functions and data structures
enum v4l2_mbus_type

Media bus type
constant
V4L2_MBUS_UNKNOWN: Unknown bus type, no V4L2 media bus configuration
V4L2_MBUS_PARALLEL: Parallel interface using hsync and vsync
V4L2_MBUS_BT656: Parallel interface with embedded synchronization, can also be used for BT.1120
V4L2_MBUS_CSI1: MIPI CSI-1 serial interface
V4L2_MBUS_CCP2: CCP2 (Compact Camera Port 2)
V4L2_MBUS_CSI2_DPHY: MIPI CSI-2 serial interface with D-PHY
V4L2_MBUS_CSI2_CPHY: MIPI CSI-2 serial interface with C-PHY
V4L2_MBUS_INVALID: invalid bus type (keep last)
struct v4l2_mbus_config
Media bus configuration
definition

struct v4l2_mbus_config {
    enum v4l2_mbus_type type;
    unsigned int flags;
};

member
type (input): interface type
flags (in/out): configuration flags, depending on type
void v4l2_fill_pix_format(struct v4l2_pix_format *pix_fmt, const struct v4l2_mbus_framefmt *mbus_fmt)
Helper function to fill fields of struct v4l2_pix_format from struct v4l2_mbus_framefmt.
parameter
struct v4l2_pix_format *pix_fmt: pointer to struct v4l2_pix_format to fill
const struct v4l2_mbus_framefmt *mbus_fmt: Pointer to struct v4l2_mbus_framefmt to be used as template.
void v4l2_fill_mbus_format(struct v4l2_mbus_framefmt *mbus_fmt, const struct v4l2_pix_format *pix_fmt, u32 code)
Auxiliary function to fill struct v4l2_mbus_framefmt according to struct v4l2_pix_format and data format code.
parameter
struct v4l2_mbus_framefmt *mbus_fmt: pointer to struct v4l2_mbus_framefmt to be filled
const struct v4l2_pix_format *pix_fmt: pointer to struct v4l2_pix_format to be used as template
u32 code: data format code (from enum v4l2_mbus_pixelcode)
void v4l2_fill_pix_format_mplane(struct v4l2_pix_format_mplane *pix_mp_fmt, const struct v4l2_mbus_framefmt *mbus_fmt)
Helper function to fill the fields of struct v4l2_pix_format_mplane according to the media bus structure.
parameter
struct v4l2_pix_format_mplane *pix_mp_fmt: pointer to struct v4l2_pix_format_mplane to be filled
const struct v4l2_mbus_framefmt *mbus_fmt: Pointer to struct v4l2_mbus_framefmt to be used as template.
void v4l2_fill_mbus_format_mplane(struct v4l2_mbus_framefmt *mbus_fmt, const struct v4l2_pix_format_mplane *pix_mp_fmt)
Auxiliary function to fill the fields of struct v4l2_mbus_framefmt according to struct v4l2_pix_format_mplane.
parameter
struct v4l2_mbus_framefmt *mbus_fmt: pointer to struct v4l2_mbus_framefmt to be filled
const struct v4l2_pix_format_mplane *pix_mp_fmt: Pointer to struct v4l2_pix_format_mplane to use as model.