1*4882a593Smuzhiyun /* SPDX-License-Identifier: GPL-2.0-or-later */
2*4882a593Smuzhiyun /*
3*4882a593Smuzhiyun * v4l2-mc.h - Media Controller V4L2 types and prototypes
4*4882a593Smuzhiyun *
5*4882a593Smuzhiyun * Copyright (C) 2016 Mauro Carvalho Chehab <mchehab@kernel.org>
6*4882a593Smuzhiyun * Copyright (C) 2006-2010 Nokia Corporation
7*4882a593Smuzhiyun * Copyright (c) 2016 Intel Corporation.
8*4882a593Smuzhiyun */
9*4882a593Smuzhiyun
10*4882a593Smuzhiyun #ifndef _V4L2_MC_H
11*4882a593Smuzhiyun #define _V4L2_MC_H
12*4882a593Smuzhiyun
13*4882a593Smuzhiyun #include <media/media-device.h>
14*4882a593Smuzhiyun #include <media/v4l2-dev.h>
15*4882a593Smuzhiyun #include <media/v4l2-subdev.h>
16*4882a593Smuzhiyun #include <linux/types.h>
17*4882a593Smuzhiyun
18*4882a593Smuzhiyun /* We don't need to include pci.h or usb.h here */
19*4882a593Smuzhiyun struct pci_dev;
20*4882a593Smuzhiyun struct usb_device;
21*4882a593Smuzhiyun
22*4882a593Smuzhiyun #ifdef CONFIG_MEDIA_CONTROLLER
23*4882a593Smuzhiyun /**
24*4882a593Smuzhiyun * v4l2_mc_create_media_graph() - create Media Controller links at the graph.
25*4882a593Smuzhiyun *
26*4882a593Smuzhiyun * @mdev: pointer to the &media_device struct.
27*4882a593Smuzhiyun *
28*4882a593Smuzhiyun * Add links between the entities commonly found on PC customer's hardware at
29*4882a593Smuzhiyun * the V4L2 side: camera sensors, audio and video PLL-IF decoders, tuners,
30*4882a593Smuzhiyun * analog TV decoder and I/O entities (video, VBI and Software Defined Radio).
31*4882a593Smuzhiyun *
32*4882a593Smuzhiyun * .. note::
33*4882a593Smuzhiyun *
34*4882a593Smuzhiyun * Webcams are modelled on a very simple way: the sensor is
35*4882a593Smuzhiyun * connected directly to the I/O entity. All dirty details, like
36*4882a593Smuzhiyun * scaler and crop HW are hidden. While such mapping is enough for v4l2
37*4882a593Smuzhiyun * interface centric PC-consumer's hardware, V4L2 subdev centric camera
38*4882a593Smuzhiyun * hardware should not use this routine, as it will not build the right graph.
39*4882a593Smuzhiyun */
40*4882a593Smuzhiyun int v4l2_mc_create_media_graph(struct media_device *mdev);
41*4882a593Smuzhiyun
42*4882a593Smuzhiyun /**
43*4882a593Smuzhiyun * v4l_enable_media_source() - Hold media source for exclusive use
44*4882a593Smuzhiyun * if free
45*4882a593Smuzhiyun *
46*4882a593Smuzhiyun * @vdev: pointer to struct video_device
47*4882a593Smuzhiyun *
48*4882a593Smuzhiyun * This interface calls enable_source handler to determine if
49*4882a593Smuzhiyun * media source is free for use. The enable_source handler is
50*4882a593Smuzhiyun * responsible for checking is the media source is free and
51*4882a593Smuzhiyun * start a pipeline between the media source and the media
52*4882a593Smuzhiyun * entity associated with the video device. This interface
53*4882a593Smuzhiyun * should be called from v4l2-core and dvb-core interfaces
54*4882a593Smuzhiyun * that change the source configuration.
55*4882a593Smuzhiyun *
56*4882a593Smuzhiyun * Return: returns zero on success or a negative error code.
57*4882a593Smuzhiyun */
58*4882a593Smuzhiyun int v4l_enable_media_source(struct video_device *vdev);
59*4882a593Smuzhiyun
60*4882a593Smuzhiyun /**
61*4882a593Smuzhiyun * v4l_disable_media_source() - Release media source
62*4882a593Smuzhiyun *
63*4882a593Smuzhiyun * @vdev: pointer to struct video_device
64*4882a593Smuzhiyun *
65*4882a593Smuzhiyun * This interface calls disable_source handler to release
66*4882a593Smuzhiyun * the media source. The disable_source handler stops the
67*4882a593Smuzhiyun * active media pipeline between the media source and the
68*4882a593Smuzhiyun * media entity associated with the video device.
69*4882a593Smuzhiyun *
70*4882a593Smuzhiyun * Return: returns zero on success or a negative error code.
71*4882a593Smuzhiyun */
72*4882a593Smuzhiyun void v4l_disable_media_source(struct video_device *vdev);
73*4882a593Smuzhiyun
74*4882a593Smuzhiyun /*
75*4882a593Smuzhiyun * v4l_vb2q_enable_media_tuner - Hold media source for exclusive use
76*4882a593Smuzhiyun * if free.
77*4882a593Smuzhiyun * @q - pointer to struct vb2_queue
78*4882a593Smuzhiyun *
79*4882a593Smuzhiyun * Wrapper for v4l_enable_media_source(). This function should
80*4882a593Smuzhiyun * be called from v4l2-core to enable the media source with
81*4882a593Smuzhiyun * pointer to struct vb2_queue as the input argument. Some
82*4882a593Smuzhiyun * v4l2-core interfaces don't have access to video device and
83*4882a593Smuzhiyun * this interface finds the struct video_device for the q and
84*4882a593Smuzhiyun * calls v4l_enable_media_source().
85*4882a593Smuzhiyun */
86*4882a593Smuzhiyun int v4l_vb2q_enable_media_source(struct vb2_queue *q);
87*4882a593Smuzhiyun
88*4882a593Smuzhiyun /**
89*4882a593Smuzhiyun * v4l2_create_fwnode_links_to_pad - Create fwnode-based links from a
90*4882a593Smuzhiyun * source subdev to a sink subdev pad.
91*4882a593Smuzhiyun *
92*4882a593Smuzhiyun * @src_sd: pointer to a source subdev
93*4882a593Smuzhiyun * @sink: pointer to a subdev sink pad
94*4882a593Smuzhiyun *
95*4882a593Smuzhiyun * This function searches for fwnode endpoint connections from a source
96*4882a593Smuzhiyun * subdevice to a single sink pad, and if suitable connections are found,
97*4882a593Smuzhiyun * translates them into media links to that pad. The function can be
98*4882a593Smuzhiyun * called by the sink subdevice, in its v4l2-async notifier subdev bound
99*4882a593Smuzhiyun * callback, to create links from a bound source subdevice.
100*4882a593Smuzhiyun *
101*4882a593Smuzhiyun * .. note::
102*4882a593Smuzhiyun *
103*4882a593Smuzhiyun * Any sink subdevice that calls this function must implement the
104*4882a593Smuzhiyun * .get_fwnode_pad media operation in order to verify endpoints passed
105*4882a593Smuzhiyun * to the sink are owned by the sink.
106*4882a593Smuzhiyun *
107*4882a593Smuzhiyun * Return 0 on success or a negative error code on failure.
108*4882a593Smuzhiyun */
109*4882a593Smuzhiyun int v4l2_create_fwnode_links_to_pad(struct v4l2_subdev *src_sd,
110*4882a593Smuzhiyun struct media_pad *sink);
111*4882a593Smuzhiyun
112*4882a593Smuzhiyun /**
113*4882a593Smuzhiyun * v4l2_create_fwnode_links - Create fwnode-based links from a source
114*4882a593Smuzhiyun * subdev to a sink subdev.
115*4882a593Smuzhiyun *
116*4882a593Smuzhiyun * @src_sd: pointer to a source subdevice
117*4882a593Smuzhiyun * @sink_sd: pointer to a sink subdevice
118*4882a593Smuzhiyun *
119*4882a593Smuzhiyun * This function searches for any and all fwnode endpoint connections
120*4882a593Smuzhiyun * between source and sink subdevices, and translates them into media
121*4882a593Smuzhiyun * links. The function can be called by the sink subdevice, in its
122*4882a593Smuzhiyun * v4l2-async notifier subdev bound callback, to create all links from
123*4882a593Smuzhiyun * a bound source subdevice.
124*4882a593Smuzhiyun *
125*4882a593Smuzhiyun * .. note::
126*4882a593Smuzhiyun *
127*4882a593Smuzhiyun * Any sink subdevice that calls this function must implement the
128*4882a593Smuzhiyun * .get_fwnode_pad media operation in order to verify endpoints passed
129*4882a593Smuzhiyun * to the sink are owned by the sink.
130*4882a593Smuzhiyun *
131*4882a593Smuzhiyun * Return 0 on success or a negative error code on failure.
132*4882a593Smuzhiyun */
133*4882a593Smuzhiyun int v4l2_create_fwnode_links(struct v4l2_subdev *src_sd,
134*4882a593Smuzhiyun struct v4l2_subdev *sink_sd);
135*4882a593Smuzhiyun
136*4882a593Smuzhiyun /**
137*4882a593Smuzhiyun * v4l2_pipeline_pm_get - Increase the use count of a pipeline
138*4882a593Smuzhiyun * @entity: The root entity of a pipeline
139*4882a593Smuzhiyun *
140*4882a593Smuzhiyun * Update the use count of all entities in the pipeline and power entities on.
141*4882a593Smuzhiyun *
142*4882a593Smuzhiyun * This function is intended to be called in video node open. It uses
143*4882a593Smuzhiyun * struct media_entity.use_count to track the power status. The use
144*4882a593Smuzhiyun * of this function should be paired with v4l2_pipeline_link_notify().
145*4882a593Smuzhiyun *
146*4882a593Smuzhiyun * Return 0 on success or a negative error code on failure.
147*4882a593Smuzhiyun */
148*4882a593Smuzhiyun int v4l2_pipeline_pm_get(struct media_entity *entity);
149*4882a593Smuzhiyun
150*4882a593Smuzhiyun /**
151*4882a593Smuzhiyun * v4l2_pipeline_pm_put - Decrease the use count of a pipeline
152*4882a593Smuzhiyun * @entity: The root entity of a pipeline
153*4882a593Smuzhiyun *
154*4882a593Smuzhiyun * Update the use count of all entities in the pipeline and power entities off.
155*4882a593Smuzhiyun *
156*4882a593Smuzhiyun * This function is intended to be called in video node release. It uses
157*4882a593Smuzhiyun * struct media_entity.use_count to track the power status. The use
158*4882a593Smuzhiyun * of this function should be paired with v4l2_pipeline_link_notify().
159*4882a593Smuzhiyun */
160*4882a593Smuzhiyun void v4l2_pipeline_pm_put(struct media_entity *entity);
161*4882a593Smuzhiyun
162*4882a593Smuzhiyun
163*4882a593Smuzhiyun /**
164*4882a593Smuzhiyun * v4l2_pipeline_link_notify - Link management notification callback
165*4882a593Smuzhiyun * @link: The link
166*4882a593Smuzhiyun * @flags: New link flags that will be applied
167*4882a593Smuzhiyun * @notification: The link's state change notification type (MEDIA_DEV_NOTIFY_*)
168*4882a593Smuzhiyun *
169*4882a593Smuzhiyun * React to link management on powered pipelines by updating the use count of
170*4882a593Smuzhiyun * all entities in the source and sink sides of the link. Entities are powered
171*4882a593Smuzhiyun * on or off accordingly. The use of this function should be paired
172*4882a593Smuzhiyun * with v4l2_pipeline_pm_{get,put}().
173*4882a593Smuzhiyun *
174*4882a593Smuzhiyun * Return 0 on success or a negative error code on failure. Powering entities
175*4882a593Smuzhiyun * off is assumed to never fail. This function will not fail for disconnection
176*4882a593Smuzhiyun * events.
177*4882a593Smuzhiyun */
178*4882a593Smuzhiyun int v4l2_pipeline_link_notify(struct media_link *link, u32 flags,
179*4882a593Smuzhiyun unsigned int notification);
180*4882a593Smuzhiyun
181*4882a593Smuzhiyun #else /* CONFIG_MEDIA_CONTROLLER */
182*4882a593Smuzhiyun
v4l2_mc_create_media_graph(struct media_device * mdev)183*4882a593Smuzhiyun static inline int v4l2_mc_create_media_graph(struct media_device *mdev)
184*4882a593Smuzhiyun {
185*4882a593Smuzhiyun return 0;
186*4882a593Smuzhiyun }
187*4882a593Smuzhiyun
v4l_enable_media_source(struct video_device * vdev)188*4882a593Smuzhiyun static inline int v4l_enable_media_source(struct video_device *vdev)
189*4882a593Smuzhiyun {
190*4882a593Smuzhiyun return 0;
191*4882a593Smuzhiyun }
192*4882a593Smuzhiyun
v4l_disable_media_source(struct video_device * vdev)193*4882a593Smuzhiyun static inline void v4l_disable_media_source(struct video_device *vdev)
194*4882a593Smuzhiyun {
195*4882a593Smuzhiyun }
196*4882a593Smuzhiyun
v4l_vb2q_enable_media_source(struct vb2_queue * q)197*4882a593Smuzhiyun static inline int v4l_vb2q_enable_media_source(struct vb2_queue *q)
198*4882a593Smuzhiyun {
199*4882a593Smuzhiyun return 0;
200*4882a593Smuzhiyun }
201*4882a593Smuzhiyun
v4l2_pipeline_pm_get(struct media_entity * entity)202*4882a593Smuzhiyun static inline int v4l2_pipeline_pm_get(struct media_entity *entity)
203*4882a593Smuzhiyun {
204*4882a593Smuzhiyun return 0;
205*4882a593Smuzhiyun }
206*4882a593Smuzhiyun
v4l2_pipeline_pm_put(struct media_entity * entity)207*4882a593Smuzhiyun static inline void v4l2_pipeline_pm_put(struct media_entity *entity)
208*4882a593Smuzhiyun {}
209*4882a593Smuzhiyun
v4l2_pipeline_link_notify(struct media_link * link,u32 flags,unsigned int notification)210*4882a593Smuzhiyun static inline int v4l2_pipeline_link_notify(struct media_link *link, u32 flags,
211*4882a593Smuzhiyun unsigned int notification)
212*4882a593Smuzhiyun {
213*4882a593Smuzhiyun return 0;
214*4882a593Smuzhiyun }
215*4882a593Smuzhiyun
216*4882a593Smuzhiyun #endif /* CONFIG_MEDIA_CONTROLLER */
217*4882a593Smuzhiyun #endif /* _V4L2_MC_H */
218