xref: /openbmc/linux/include/media/v4l2-mc.h (revision 1ac731c529cd4d6adbce134754b51ff7d822b145)
1c942fddfSThomas Gleixner /* SPDX-License-Identifier: GPL-2.0-or-later */
26aad127dSMauro Carvalho Chehab /*
36aad127dSMauro Carvalho Chehab  * v4l2-mc.h - Media Controller V4L2 types and prototypes
46aad127dSMauro Carvalho Chehab  *
5dc19ed15SMauro Carvalho Chehab  * Copyright (C) 2016 Mauro Carvalho Chehab <mchehab@kernel.org>
676413791SSakari Ailus  * Copyright (C) 2006-2010 Nokia Corporation
776413791SSakari Ailus  * Copyright (c) 2016 Intel Corporation.
86aad127dSMauro Carvalho Chehab  */
96aad127dSMauro Carvalho Chehab 
10db152276SMauro Carvalho Chehab #ifndef _V4L2_MC_H
11db152276SMauro Carvalho Chehab #define _V4L2_MC_H
12db152276SMauro Carvalho Chehab 
1354d0dbacSMauro Carvalho Chehab #include <media/media-device.h>
14d0a164f5SShuah Khan #include <media/v4l2-dev.h>
150d3c81e8SSteve Longerbeam #include <media/v4l2-subdev.h>
1676413791SSakari Ailus #include <linux/types.h>
1754d0dbacSMauro Carvalho Chehab 
18eee7d353SMauro Carvalho Chehab /* We don't need to include pci.h or usb.h here */
19eee7d353SMauro Carvalho Chehab struct pci_dev;
20eee7d353SMauro Carvalho Chehab struct usb_device;
217047f298SMauro Carvalho Chehab 
227047f298SMauro Carvalho Chehab #ifdef CONFIG_MEDIA_CONTROLLER
2354d0dbacSMauro Carvalho Chehab /**
2454d0dbacSMauro Carvalho Chehab  * v4l2_mc_create_media_graph() - create Media Controller links at the graph.
2554d0dbacSMauro Carvalho Chehab  *
2654d0dbacSMauro Carvalho Chehab  * @mdev:	pointer to the &media_device struct.
2754d0dbacSMauro Carvalho Chehab  *
2854d0dbacSMauro Carvalho Chehab  * Add links between the entities commonly found on PC customer's hardware at
2954d0dbacSMauro Carvalho Chehab  * the V4L2 side: camera sensors, audio and video PLL-IF decoders, tuners,
3054d0dbacSMauro Carvalho Chehab  * analog TV decoder and I/O entities (video, VBI and Software Defined Radio).
3189cb3ddbSMauro Carvalho Chehab  *
3289cb3ddbSMauro Carvalho Chehab  * .. note::
3389cb3ddbSMauro Carvalho Chehab  *
3489cb3ddbSMauro Carvalho Chehab  *    Webcams are modelled on a very simple way: the sensor is
3554d0dbacSMauro Carvalho Chehab  *    connected directly to the I/O entity. All dirty details, like
3654d0dbacSMauro Carvalho Chehab  *    scaler and crop HW are hidden. While such mapping is enough for v4l2
3754d0dbacSMauro Carvalho Chehab  *    interface centric PC-consumer's hardware, V4L2 subdev centric camera
3854d0dbacSMauro Carvalho Chehab  *    hardware should not use this routine, as it will not build the right graph.
3954d0dbacSMauro Carvalho Chehab  */
4054d0dbacSMauro Carvalho Chehab int v4l2_mc_create_media_graph(struct media_device *mdev);
417047f298SMauro Carvalho Chehab 
42d0a164f5SShuah Khan /**
43d0a164f5SShuah Khan  * v4l_enable_media_source() -	Hold media source for exclusive use
44d0a164f5SShuah Khan  *				if free
45d0a164f5SShuah Khan  *
464f27dba6SMauro Carvalho Chehab  * @vdev:	pointer to struct video_device
47d0a164f5SShuah Khan  *
48d0a164f5SShuah Khan  * This interface calls enable_source handler to determine if
49d0a164f5SShuah Khan  * media source is free for use. The enable_source handler is
50d0a164f5SShuah Khan  * responsible for checking is the media source is free and
51d0a164f5SShuah Khan  * start a pipeline between the media source and the media
52d0a164f5SShuah Khan  * entity associated with the video device. This interface
53d0a164f5SShuah Khan  * should be called from v4l2-core and dvb-core interfaces
54d0a164f5SShuah Khan  * that change the source configuration.
55d0a164f5SShuah Khan  *
56d0a164f5SShuah Khan  * Return: returns zero on success or a negative error code.
57d0a164f5SShuah Khan  */
58d0a164f5SShuah Khan int v4l_enable_media_source(struct video_device *vdev);
59d0a164f5SShuah Khan 
60d0a164f5SShuah Khan /**
61d0a164f5SShuah Khan  * v4l_disable_media_source() -	Release media source
62d0a164f5SShuah Khan  *
634f27dba6SMauro Carvalho Chehab  * @vdev:	pointer to struct video_device
64d0a164f5SShuah Khan  *
65d0a164f5SShuah Khan  * This interface calls disable_source handler to release
66d0a164f5SShuah Khan  * the media source. The disable_source handler stops the
67d0a164f5SShuah Khan  * active media pipeline between the media source and the
68d0a164f5SShuah Khan  * media entity associated with the video device.
69d0a164f5SShuah Khan  *
70d0a164f5SShuah Khan  * Return: returns zero on success or a negative error code.
71d0a164f5SShuah Khan  */
72d0a164f5SShuah Khan void v4l_disable_media_source(struct video_device *vdev);
73d0a164f5SShuah Khan 
74d0a164f5SShuah Khan /*
75d0a164f5SShuah Khan  * v4l_vb2q_enable_media_tuner -  Hold media source for exclusive use
76d0a164f5SShuah Khan  *				  if free.
77d0a164f5SShuah Khan  * @q - pointer to struct vb2_queue
78d0a164f5SShuah Khan  *
79d0a164f5SShuah Khan  * Wrapper for v4l_enable_media_source(). This function should
80d0a164f5SShuah Khan  * be called from v4l2-core to enable the media source with
81d0a164f5SShuah Khan  * pointer to struct vb2_queue as the input argument. Some
82d0a164f5SShuah Khan  * v4l2-core interfaces don't have access to video device and
83d0a164f5SShuah Khan  * this interface finds the struct video_device for the q and
84d0a164f5SShuah Khan  * calls v4l_enable_media_source().
85d0a164f5SShuah Khan  */
86d0a164f5SShuah Khan int v4l_vb2q_enable_media_source(struct vb2_queue *q);
87d0a164f5SShuah Khan 
880d3c81e8SSteve Longerbeam /**
890d3c81e8SSteve Longerbeam  * v4l2_create_fwnode_links_to_pad - Create fwnode-based links from a
90*bd5a03bcSLaurent Pinchart  *                                   source subdev to a sink pad.
910d3c81e8SSteve Longerbeam  *
926d10fc2bSColton Lewis  * @src_sd: pointer to a source subdev
93*bd5a03bcSLaurent Pinchart  * @sink:  pointer to a sink pad
94dbedd2f4SLaurent Pinchart  * @flags: the link flags
950d3c81e8SSteve Longerbeam  *
960d3c81e8SSteve Longerbeam  * This function searches for fwnode endpoint connections from a source
970d3c81e8SSteve Longerbeam  * subdevice to a single sink pad, and if suitable connections are found,
980d3c81e8SSteve Longerbeam  * translates them into media links to that pad. The function can be
99*bd5a03bcSLaurent Pinchart  * called by the sink, in its v4l2-async notifier bound callback, to create
100*bd5a03bcSLaurent Pinchart  * links from a bound source subdevice.
1010d3c81e8SSteve Longerbeam  *
102dbedd2f4SLaurent Pinchart  * The @flags argument specifies the link flags. The caller shall ensure that
103dbedd2f4SLaurent Pinchart  * the flags are valid regardless of the number of links that may be created.
104dbedd2f4SLaurent Pinchart  * For instance, setting the MEDIA_LNK_FL_ENABLED flag will cause all created
105dbedd2f4SLaurent Pinchart  * links to be enabled, which isn't valid if more than one link is created.
106dbedd2f4SLaurent Pinchart  *
1070d3c81e8SSteve Longerbeam  * .. note::
1080d3c81e8SSteve Longerbeam  *
1090d3c81e8SSteve Longerbeam  *    Any sink subdevice that calls this function must implement the
1100d3c81e8SSteve Longerbeam  *    .get_fwnode_pad media operation in order to verify endpoints passed
1110d3c81e8SSteve Longerbeam  *    to the sink are owned by the sink.
1120d3c81e8SSteve Longerbeam  *
1130d3c81e8SSteve Longerbeam  * Return 0 on success or a negative error code on failure.
1140d3c81e8SSteve Longerbeam  */
1150d3c81e8SSteve Longerbeam int v4l2_create_fwnode_links_to_pad(struct v4l2_subdev *src_sd,
116dbedd2f4SLaurent Pinchart 				    struct media_pad *sink, u32 flags);
1170d3c81e8SSteve Longerbeam 
1180d3c81e8SSteve Longerbeam /**
1190d3c81e8SSteve Longerbeam  * v4l2_create_fwnode_links - Create fwnode-based links from a source
1200d3c81e8SSteve Longerbeam  *                            subdev to a sink subdev.
1210d3c81e8SSteve Longerbeam  *
1226d10fc2bSColton Lewis  * @src_sd: pointer to a source subdevice
1236d10fc2bSColton Lewis  * @sink_sd: pointer to a sink subdevice
1240d3c81e8SSteve Longerbeam  *
1250d3c81e8SSteve Longerbeam  * This function searches for any and all fwnode endpoint connections
1260d3c81e8SSteve Longerbeam  * between source and sink subdevices, and translates them into media
1270d3c81e8SSteve Longerbeam  * links. The function can be called by the sink subdevice, in its
1280d3c81e8SSteve Longerbeam  * v4l2-async notifier subdev bound callback, to create all links from
1290d3c81e8SSteve Longerbeam  * a bound source subdevice.
1300d3c81e8SSteve Longerbeam  *
1310d3c81e8SSteve Longerbeam  * .. note::
1320d3c81e8SSteve Longerbeam  *
1330d3c81e8SSteve Longerbeam  *    Any sink subdevice that calls this function must implement the
1340d3c81e8SSteve Longerbeam  *    .get_fwnode_pad media operation in order to verify endpoints passed
1350d3c81e8SSteve Longerbeam  *    to the sink are owned by the sink.
1360d3c81e8SSteve Longerbeam  *
1370d3c81e8SSteve Longerbeam  * Return 0 on success or a negative error code on failure.
1380d3c81e8SSteve Longerbeam  */
1390d3c81e8SSteve Longerbeam int v4l2_create_fwnode_links(struct v4l2_subdev *src_sd,
1400d3c81e8SSteve Longerbeam 			     struct v4l2_subdev *sink_sd);
14176413791SSakari Ailus 
14276413791SSakari Ailus /**
1438fd390b8SEzequiel Garcia  * v4l2_pipeline_pm_get - Increase the use count of a pipeline
1448fd390b8SEzequiel Garcia  * @entity: The root entity of a pipeline
14576413791SSakari Ailus  *
1468fd390b8SEzequiel Garcia  * Update the use count of all entities in the pipeline and power entities on.
14776413791SSakari Ailus  *
1488fd390b8SEzequiel Garcia  * This function is intended to be called in video node open. It uses
1498fd390b8SEzequiel Garcia  * struct media_entity.use_count to track the power status. The use
1508fd390b8SEzequiel Garcia  * of this function should be paired with v4l2_pipeline_link_notify().
15176413791SSakari Ailus  *
1528fd390b8SEzequiel Garcia  * Return 0 on success or a negative error code on failure.
15376413791SSakari Ailus  */
1548fd390b8SEzequiel Garcia int v4l2_pipeline_pm_get(struct media_entity *entity);
1558fd390b8SEzequiel Garcia 
1568fd390b8SEzequiel Garcia /**
1578fd390b8SEzequiel Garcia  * v4l2_pipeline_pm_put - Decrease the use count of a pipeline
1588fd390b8SEzequiel Garcia  * @entity: The root entity of a pipeline
1598fd390b8SEzequiel Garcia  *
1608fd390b8SEzequiel Garcia  * Update the use count of all entities in the pipeline and power entities off.
1618fd390b8SEzequiel Garcia  *
1628fd390b8SEzequiel Garcia  * This function is intended to be called in video node release. It uses
1638fd390b8SEzequiel Garcia  * struct media_entity.use_count to track the power status. The use
1648fd390b8SEzequiel Garcia  * of this function should be paired with v4l2_pipeline_link_notify().
1658fd390b8SEzequiel Garcia  */
1668fd390b8SEzequiel Garcia void v4l2_pipeline_pm_put(struct media_entity *entity);
16776413791SSakari Ailus 
16876413791SSakari Ailus 
16976413791SSakari Ailus /**
17076413791SSakari Ailus  * v4l2_pipeline_link_notify - Link management notification callback
17176413791SSakari Ailus  * @link: The link
17276413791SSakari Ailus  * @flags: New link flags that will be applied
17376413791SSakari Ailus  * @notification: The link's state change notification type (MEDIA_DEV_NOTIFY_*)
17476413791SSakari Ailus  *
17576413791SSakari Ailus  * React to link management on powered pipelines by updating the use count of
17676413791SSakari Ailus  * all entities in the source and sink sides of the link. Entities are powered
17776413791SSakari Ailus  * on or off accordingly. The use of this function should be paired
1788fd390b8SEzequiel Garcia  * with v4l2_pipeline_pm_{get,put}().
17976413791SSakari Ailus  *
18076413791SSakari Ailus  * Return 0 on success or a negative error code on failure. Powering entities
18176413791SSakari Ailus  * off is assumed to never fail. This function will not fail for disconnection
18276413791SSakari Ailus  * events.
18376413791SSakari Ailus  */
18476413791SSakari Ailus int v4l2_pipeline_link_notify(struct media_link *link, u32 flags,
18576413791SSakari Ailus 			      unsigned int notification);
18676413791SSakari Ailus 
187a77bf704SMauro Carvalho Chehab #else /* CONFIG_MEDIA_CONTROLLER */
188d0a164f5SShuah Khan 
v4l2_mc_create_media_graph(struct media_device * mdev)18954d0dbacSMauro Carvalho Chehab static inline int v4l2_mc_create_media_graph(struct media_device *mdev)
19054d0dbacSMauro Carvalho Chehab {
19154d0dbacSMauro Carvalho Chehab 	return 0;
19254d0dbacSMauro Carvalho Chehab }
1937047f298SMauro Carvalho Chehab 
v4l_enable_media_source(struct video_device * vdev)1949532e6bbSHans Verkuil static inline int v4l_enable_media_source(struct video_device *vdev)
195d0a164f5SShuah Khan {
196d0a164f5SShuah Khan 	return 0;
197d0a164f5SShuah Khan }
198d0a164f5SShuah Khan 
v4l_disable_media_source(struct video_device * vdev)1999532e6bbSHans Verkuil static inline void v4l_disable_media_source(struct video_device *vdev)
200d0a164f5SShuah Khan {
201d0a164f5SShuah Khan }
202d0a164f5SShuah Khan 
v4l_vb2q_enable_media_source(struct vb2_queue * q)2039532e6bbSHans Verkuil static inline int v4l_vb2q_enable_media_source(struct vb2_queue *q)
204d0a164f5SShuah Khan {
205d0a164f5SShuah Khan 	return 0;
206d0a164f5SShuah Khan }
207a77bf704SMauro Carvalho Chehab 
v4l2_pipeline_pm_get(struct media_entity * entity)2088fd390b8SEzequiel Garcia static inline int v4l2_pipeline_pm_get(struct media_entity *entity)
209a77bf704SMauro Carvalho Chehab {
210a77bf704SMauro Carvalho Chehab 	return 0;
211a77bf704SMauro Carvalho Chehab }
212a77bf704SMauro Carvalho Chehab 
v4l2_pipeline_pm_put(struct media_entity * entity)2138fd390b8SEzequiel Garcia static inline void v4l2_pipeline_pm_put(struct media_entity *entity)
2148fd390b8SEzequiel Garcia {}
2158fd390b8SEzequiel Garcia 
v4l2_pipeline_link_notify(struct media_link * link,u32 flags,unsigned int notification)2161e89f584SHans Verkuil static inline int v4l2_pipeline_link_notify(struct media_link *link, u32 flags,
2171e89f584SHans Verkuil 					    unsigned int notification)
218a77bf704SMauro Carvalho Chehab {
219a77bf704SMauro Carvalho Chehab 	return 0;
220a77bf704SMauro Carvalho Chehab }
221a77bf704SMauro Carvalho Chehab 
222a77bf704SMauro Carvalho Chehab #endif /* CONFIG_MEDIA_CONTROLLER */
223d0a164f5SShuah Khan #endif /* _V4L2_MC_H */
224