2 * Media Controller ancillary functions
4 * Copyright (c) 2016 Mauro Carvalho Chehab <mchehab@osg.samsung.com>
5 * Copyright (C) 2016 Shuah Khan <shuahkh@osg.samsung.com>
7 * This program is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation; either version 2 of the License, or
10 * (at your option) any later version.
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
18 #include <linux/module.h>
19 #include <media/media-entity.h>
20 #include <media/media-device.h>
21 #include <media/v4l2-fh.h>
22 #include <media/v4l2-mc.h>
23 #include <media/videobuf2-core.h>
25 int v4l2_mc_create_media_graph(struct media_device
*mdev
)
28 struct media_entity
*entity
;
29 struct media_entity
*if_vid
= NULL
, *if_aud
= NULL
;
30 struct media_entity
*tuner
= NULL
, *decoder
= NULL
;
31 struct media_entity
*io_v4l
= NULL
, *io_vbi
= NULL
, *io_swradio
= NULL
;
32 bool is_webcam
= false;
39 media_device_for_each_entity(entity
, mdev
) {
40 switch (entity
->function
) {
41 case MEDIA_ENT_F_IF_VID_DECODER
:
44 case MEDIA_ENT_F_IF_AUD_DECODER
:
47 case MEDIA_ENT_F_TUNER
:
50 case MEDIA_ENT_F_ATV_DECODER
:
53 case MEDIA_ENT_F_IO_V4L
:
56 case MEDIA_ENT_F_IO_VBI
:
59 case MEDIA_ENT_F_IO_SWRADIO
:
62 case MEDIA_ENT_F_CAM_SENSOR
:
68 /* It should have at least one I/O entity */
69 if (!io_v4l
&& !io_vbi
&& !io_swradio
)
73 * Here, webcams are modelled on a very simple way: the sensor is
74 * connected directly to the I/O entity. All dirty details, like
75 * scaler and crop HW are hidden. While such mapping is not enough
76 * for mc-centric hardware, it is enough for v4l2 interface centric
77 * PC-consumer's hardware.
83 media_device_for_each_entity(entity
, mdev
) {
84 if (entity
->function
!= MEDIA_ENT_F_CAM_SENSOR
)
86 ret
= media_create_pad_link(entity
, 0,
88 MEDIA_LNK_FL_ENABLED
);
96 /* The device isn't a webcam. So, it should have a decoder */
100 /* Link the tuner and IF video output pads */
103 ret
= media_create_pad_link(tuner
, TUNER_PAD_OUTPUT
,
105 IF_VID_DEC_PAD_IF_INPUT
,
106 MEDIA_LNK_FL_ENABLED
);
109 ret
= media_create_pad_link(if_vid
, IF_VID_DEC_PAD_OUT
,
110 decoder
, DEMOD_PAD_IF_INPUT
,
111 MEDIA_LNK_FL_ENABLED
);
115 ret
= media_create_pad_link(tuner
, TUNER_PAD_OUTPUT
,
116 decoder
, DEMOD_PAD_IF_INPUT
,
117 MEDIA_LNK_FL_ENABLED
);
123 ret
= media_create_pad_link(tuner
, TUNER_PAD_AUD_OUT
,
125 IF_AUD_DEC_PAD_IF_INPUT
,
126 MEDIA_LNK_FL_ENABLED
);
135 /* Create demod to V4L, VBI and SDR radio links */
137 ret
= media_create_pad_link(decoder
, DEMOD_PAD_VID_OUT
,
139 MEDIA_LNK_FL_ENABLED
);
145 ret
= media_create_pad_link(decoder
, DEMOD_PAD_VID_OUT
,
147 MEDIA_LNK_FL_ENABLED
);
153 ret
= media_create_pad_link(decoder
, DEMOD_PAD_VBI_OUT
,
155 MEDIA_LNK_FL_ENABLED
);
160 /* Create links for the media connectors */
161 flags
= MEDIA_LNK_FL_ENABLED
;
162 media_device_for_each_entity(entity
, mdev
) {
163 switch (entity
->function
) {
164 case MEDIA_ENT_F_CONN_RF
:
168 ret
= media_create_pad_link(entity
, 0, tuner
,
172 case MEDIA_ENT_F_CONN_SVIDEO
:
173 case MEDIA_ENT_F_CONN_COMPOSITE
:
174 ret
= media_create_pad_link(entity
, 0, decoder
,
188 EXPORT_SYMBOL_GPL(v4l2_mc_create_media_graph
);
190 int v4l_enable_media_source(struct video_device
*vdev
)
192 struct media_device
*mdev
= vdev
->entity
.graph_obj
.mdev
;
195 if (!mdev
|| !mdev
->enable_source
)
197 ret
= mdev
->enable_source(&vdev
->entity
, &vdev
->pipe
);
202 EXPORT_SYMBOL_GPL(v4l_enable_media_source
);
204 void v4l_disable_media_source(struct video_device
*vdev
)
206 struct media_device
*mdev
= vdev
->entity
.graph_obj
.mdev
;
208 if (mdev
&& mdev
->disable_source
)
209 mdev
->disable_source(&vdev
->entity
);
211 EXPORT_SYMBOL_GPL(v4l_disable_media_source
);
213 int v4l_vb2q_enable_media_source(struct vb2_queue
*q
)
215 struct v4l2_fh
*fh
= q
->owner
;
217 return v4l_enable_media_source(fh
->vdev
);
219 EXPORT_SYMBOL_GPL(v4l_vb2q_enable_media_source
);