162306a36Sopenharmony_ci/* SPDX-License-Identifier: GPL-2.0-or-later */ 262306a36Sopenharmony_ci/* 362306a36Sopenharmony_ci * v4l2-mc.h - Media Controller V4L2 types and prototypes 462306a36Sopenharmony_ci * 562306a36Sopenharmony_ci * Copyright (C) 2016 Mauro Carvalho Chehab <mchehab@kernel.org> 662306a36Sopenharmony_ci * Copyright (C) 2006-2010 Nokia Corporation 762306a36Sopenharmony_ci * Copyright (c) 2016 Intel Corporation. 862306a36Sopenharmony_ci */ 962306a36Sopenharmony_ci 1062306a36Sopenharmony_ci#ifndef _V4L2_MC_H 1162306a36Sopenharmony_ci#define _V4L2_MC_H 1262306a36Sopenharmony_ci 1362306a36Sopenharmony_ci#include <media/media-device.h> 1462306a36Sopenharmony_ci#include <media/v4l2-dev.h> 1562306a36Sopenharmony_ci#include <media/v4l2-subdev.h> 1662306a36Sopenharmony_ci#include <linux/types.h> 1762306a36Sopenharmony_ci 1862306a36Sopenharmony_ci/* We don't need to include pci.h or usb.h here */ 1962306a36Sopenharmony_cistruct pci_dev; 2062306a36Sopenharmony_cistruct usb_device; 2162306a36Sopenharmony_ci 2262306a36Sopenharmony_ci#ifdef CONFIG_MEDIA_CONTROLLER 2362306a36Sopenharmony_ci/** 2462306a36Sopenharmony_ci * v4l2_mc_create_media_graph() - create Media Controller links at the graph. 2562306a36Sopenharmony_ci * 2662306a36Sopenharmony_ci * @mdev: pointer to the &media_device struct. 2762306a36Sopenharmony_ci * 2862306a36Sopenharmony_ci * Add links between the entities commonly found on PC customer's hardware at 2962306a36Sopenharmony_ci * the V4L2 side: camera sensors, audio and video PLL-IF decoders, tuners, 3062306a36Sopenharmony_ci * analog TV decoder and I/O entities (video, VBI and Software Defined Radio). 3162306a36Sopenharmony_ci * 3262306a36Sopenharmony_ci * .. note:: 3362306a36Sopenharmony_ci * 3462306a36Sopenharmony_ci * Webcams are modelled on a very simple way: the sensor is 3562306a36Sopenharmony_ci * connected directly to the I/O entity. All dirty details, like 3662306a36Sopenharmony_ci * scaler and crop HW are hidden. While such mapping is enough for v4l2 3762306a36Sopenharmony_ci * interface centric PC-consumer's hardware, V4L2 subdev centric camera 3862306a36Sopenharmony_ci * hardware should not use this routine, as it will not build the right graph. 3962306a36Sopenharmony_ci */ 4062306a36Sopenharmony_ciint v4l2_mc_create_media_graph(struct media_device *mdev); 4162306a36Sopenharmony_ci 4262306a36Sopenharmony_ci/** 4362306a36Sopenharmony_ci * v4l_enable_media_source() - Hold media source for exclusive use 4462306a36Sopenharmony_ci * if free 4562306a36Sopenharmony_ci * 4662306a36Sopenharmony_ci * @vdev: pointer to struct video_device 4762306a36Sopenharmony_ci * 4862306a36Sopenharmony_ci * This interface calls enable_source handler to determine if 4962306a36Sopenharmony_ci * media source is free for use. The enable_source handler is 5062306a36Sopenharmony_ci * responsible for checking is the media source is free and 5162306a36Sopenharmony_ci * start a pipeline between the media source and the media 5262306a36Sopenharmony_ci * entity associated with the video device. This interface 5362306a36Sopenharmony_ci * should be called from v4l2-core and dvb-core interfaces 5462306a36Sopenharmony_ci * that change the source configuration. 5562306a36Sopenharmony_ci * 5662306a36Sopenharmony_ci * Return: returns zero on success or a negative error code. 5762306a36Sopenharmony_ci */ 5862306a36Sopenharmony_ciint v4l_enable_media_source(struct video_device *vdev); 5962306a36Sopenharmony_ci 6062306a36Sopenharmony_ci/** 6162306a36Sopenharmony_ci * v4l_disable_media_source() - Release media source 6262306a36Sopenharmony_ci * 6362306a36Sopenharmony_ci * @vdev: pointer to struct video_device 6462306a36Sopenharmony_ci * 6562306a36Sopenharmony_ci * This interface calls disable_source handler to release 6662306a36Sopenharmony_ci * the media source. The disable_source handler stops the 6762306a36Sopenharmony_ci * active media pipeline between the media source and the 6862306a36Sopenharmony_ci * media entity associated with the video device. 6962306a36Sopenharmony_ci * 7062306a36Sopenharmony_ci * Return: returns zero on success or a negative error code. 7162306a36Sopenharmony_ci */ 7262306a36Sopenharmony_civoid v4l_disable_media_source(struct video_device *vdev); 7362306a36Sopenharmony_ci 7462306a36Sopenharmony_ci/* 7562306a36Sopenharmony_ci * v4l_vb2q_enable_media_tuner - Hold media source for exclusive use 7662306a36Sopenharmony_ci * if free. 7762306a36Sopenharmony_ci * @q - pointer to struct vb2_queue 7862306a36Sopenharmony_ci * 7962306a36Sopenharmony_ci * Wrapper for v4l_enable_media_source(). This function should 8062306a36Sopenharmony_ci * be called from v4l2-core to enable the media source with 8162306a36Sopenharmony_ci * pointer to struct vb2_queue as the input argument. Some 8262306a36Sopenharmony_ci * v4l2-core interfaces don't have access to video device and 8362306a36Sopenharmony_ci * this interface finds the struct video_device for the q and 8462306a36Sopenharmony_ci * calls v4l_enable_media_source(). 8562306a36Sopenharmony_ci */ 8662306a36Sopenharmony_ciint v4l_vb2q_enable_media_source(struct vb2_queue *q); 8762306a36Sopenharmony_ci 8862306a36Sopenharmony_ci/** 8962306a36Sopenharmony_ci * v4l2_create_fwnode_links_to_pad - Create fwnode-based links from a 9062306a36Sopenharmony_ci * source subdev to a sink pad. 9162306a36Sopenharmony_ci * 9262306a36Sopenharmony_ci * @src_sd: pointer to a source subdev 9362306a36Sopenharmony_ci * @sink: pointer to a sink pad 9462306a36Sopenharmony_ci * @flags: the link flags 9562306a36Sopenharmony_ci * 9662306a36Sopenharmony_ci * This function searches for fwnode endpoint connections from a source 9762306a36Sopenharmony_ci * subdevice to a single sink pad, and if suitable connections are found, 9862306a36Sopenharmony_ci * translates them into media links to that pad. The function can be 9962306a36Sopenharmony_ci * called by the sink, in its v4l2-async notifier bound callback, to create 10062306a36Sopenharmony_ci * links from a bound source subdevice. 10162306a36Sopenharmony_ci * 10262306a36Sopenharmony_ci * The @flags argument specifies the link flags. The caller shall ensure that 10362306a36Sopenharmony_ci * the flags are valid regardless of the number of links that may be created. 10462306a36Sopenharmony_ci * For instance, setting the MEDIA_LNK_FL_ENABLED flag will cause all created 10562306a36Sopenharmony_ci * links to be enabled, which isn't valid if more than one link is created. 10662306a36Sopenharmony_ci * 10762306a36Sopenharmony_ci * .. note:: 10862306a36Sopenharmony_ci * 10962306a36Sopenharmony_ci * Any sink subdevice that calls this function must implement the 11062306a36Sopenharmony_ci * .get_fwnode_pad media operation in order to verify endpoints passed 11162306a36Sopenharmony_ci * to the sink are owned by the sink. 11262306a36Sopenharmony_ci * 11362306a36Sopenharmony_ci * Return 0 on success or a negative error code on failure. 11462306a36Sopenharmony_ci */ 11562306a36Sopenharmony_ciint v4l2_create_fwnode_links_to_pad(struct v4l2_subdev *src_sd, 11662306a36Sopenharmony_ci struct media_pad *sink, u32 flags); 11762306a36Sopenharmony_ci 11862306a36Sopenharmony_ci/** 11962306a36Sopenharmony_ci * v4l2_create_fwnode_links - Create fwnode-based links from a source 12062306a36Sopenharmony_ci * subdev to a sink subdev. 12162306a36Sopenharmony_ci * 12262306a36Sopenharmony_ci * @src_sd: pointer to a source subdevice 12362306a36Sopenharmony_ci * @sink_sd: pointer to a sink subdevice 12462306a36Sopenharmony_ci * 12562306a36Sopenharmony_ci * This function searches for any and all fwnode endpoint connections 12662306a36Sopenharmony_ci * between source and sink subdevices, and translates them into media 12762306a36Sopenharmony_ci * links. The function can be called by the sink subdevice, in its 12862306a36Sopenharmony_ci * v4l2-async notifier subdev bound callback, to create all links from 12962306a36Sopenharmony_ci * a bound source subdevice. 13062306a36Sopenharmony_ci * 13162306a36Sopenharmony_ci * .. note:: 13262306a36Sopenharmony_ci * 13362306a36Sopenharmony_ci * Any sink subdevice that calls this function must implement the 13462306a36Sopenharmony_ci * .get_fwnode_pad media operation in order to verify endpoints passed 13562306a36Sopenharmony_ci * to the sink are owned by the sink. 13662306a36Sopenharmony_ci * 13762306a36Sopenharmony_ci * Return 0 on success or a negative error code on failure. 13862306a36Sopenharmony_ci */ 13962306a36Sopenharmony_ciint v4l2_create_fwnode_links(struct v4l2_subdev *src_sd, 14062306a36Sopenharmony_ci struct v4l2_subdev *sink_sd); 14162306a36Sopenharmony_ci 14262306a36Sopenharmony_ci/** 14362306a36Sopenharmony_ci * v4l2_pipeline_pm_get - Increase the use count of a pipeline 14462306a36Sopenharmony_ci * @entity: The root entity of a pipeline 14562306a36Sopenharmony_ci * 14662306a36Sopenharmony_ci * Update the use count of all entities in the pipeline and power entities on. 14762306a36Sopenharmony_ci * 14862306a36Sopenharmony_ci * This function is intended to be called in video node open. It uses 14962306a36Sopenharmony_ci * struct media_entity.use_count to track the power status. The use 15062306a36Sopenharmony_ci * of this function should be paired with v4l2_pipeline_link_notify(). 15162306a36Sopenharmony_ci * 15262306a36Sopenharmony_ci * Return 0 on success or a negative error code on failure. 15362306a36Sopenharmony_ci */ 15462306a36Sopenharmony_ciint v4l2_pipeline_pm_get(struct media_entity *entity); 15562306a36Sopenharmony_ci 15662306a36Sopenharmony_ci/** 15762306a36Sopenharmony_ci * v4l2_pipeline_pm_put - Decrease the use count of a pipeline 15862306a36Sopenharmony_ci * @entity: The root entity of a pipeline 15962306a36Sopenharmony_ci * 16062306a36Sopenharmony_ci * Update the use count of all entities in the pipeline and power entities off. 16162306a36Sopenharmony_ci * 16262306a36Sopenharmony_ci * This function is intended to be called in video node release. It uses 16362306a36Sopenharmony_ci * struct media_entity.use_count to track the power status. The use 16462306a36Sopenharmony_ci * of this function should be paired with v4l2_pipeline_link_notify(). 16562306a36Sopenharmony_ci */ 16662306a36Sopenharmony_civoid v4l2_pipeline_pm_put(struct media_entity *entity); 16762306a36Sopenharmony_ci 16862306a36Sopenharmony_ci 16962306a36Sopenharmony_ci/** 17062306a36Sopenharmony_ci * v4l2_pipeline_link_notify - Link management notification callback 17162306a36Sopenharmony_ci * @link: The link 17262306a36Sopenharmony_ci * @flags: New link flags that will be applied 17362306a36Sopenharmony_ci * @notification: The link's state change notification type (MEDIA_DEV_NOTIFY_*) 17462306a36Sopenharmony_ci * 17562306a36Sopenharmony_ci * React to link management on powered pipelines by updating the use count of 17662306a36Sopenharmony_ci * all entities in the source and sink sides of the link. Entities are powered 17762306a36Sopenharmony_ci * on or off accordingly. The use of this function should be paired 17862306a36Sopenharmony_ci * with v4l2_pipeline_pm_{get,put}(). 17962306a36Sopenharmony_ci * 18062306a36Sopenharmony_ci * Return 0 on success or a negative error code on failure. Powering entities 18162306a36Sopenharmony_ci * off is assumed to never fail. This function will not fail for disconnection 18262306a36Sopenharmony_ci * events. 18362306a36Sopenharmony_ci */ 18462306a36Sopenharmony_ciint v4l2_pipeline_link_notify(struct media_link *link, u32 flags, 18562306a36Sopenharmony_ci unsigned int notification); 18662306a36Sopenharmony_ci 18762306a36Sopenharmony_ci#else /* CONFIG_MEDIA_CONTROLLER */ 18862306a36Sopenharmony_ci 18962306a36Sopenharmony_cistatic inline int v4l2_mc_create_media_graph(struct media_device *mdev) 19062306a36Sopenharmony_ci{ 19162306a36Sopenharmony_ci return 0; 19262306a36Sopenharmony_ci} 19362306a36Sopenharmony_ci 19462306a36Sopenharmony_cistatic inline int v4l_enable_media_source(struct video_device *vdev) 19562306a36Sopenharmony_ci{ 19662306a36Sopenharmony_ci return 0; 19762306a36Sopenharmony_ci} 19862306a36Sopenharmony_ci 19962306a36Sopenharmony_cistatic inline void v4l_disable_media_source(struct video_device *vdev) 20062306a36Sopenharmony_ci{ 20162306a36Sopenharmony_ci} 20262306a36Sopenharmony_ci 20362306a36Sopenharmony_cistatic inline int v4l_vb2q_enable_media_source(struct vb2_queue *q) 20462306a36Sopenharmony_ci{ 20562306a36Sopenharmony_ci return 0; 20662306a36Sopenharmony_ci} 20762306a36Sopenharmony_ci 20862306a36Sopenharmony_cistatic inline int v4l2_pipeline_pm_get(struct media_entity *entity) 20962306a36Sopenharmony_ci{ 21062306a36Sopenharmony_ci return 0; 21162306a36Sopenharmony_ci} 21262306a36Sopenharmony_ci 21362306a36Sopenharmony_cistatic inline void v4l2_pipeline_pm_put(struct media_entity *entity) 21462306a36Sopenharmony_ci{} 21562306a36Sopenharmony_ci 21662306a36Sopenharmony_cistatic inline int v4l2_pipeline_link_notify(struct media_link *link, u32 flags, 21762306a36Sopenharmony_ci unsigned int notification) 21862306a36Sopenharmony_ci{ 21962306a36Sopenharmony_ci return 0; 22062306a36Sopenharmony_ci} 22162306a36Sopenharmony_ci 22262306a36Sopenharmony_ci#endif /* CONFIG_MEDIA_CONTROLLER */ 22362306a36Sopenharmony_ci#endif /* _V4L2_MC_H */ 224