2 * Media Controller ancillary functions
4 * (c) 2016 Mauro Carvalho Chehab <mchehab@osg.samsung.com>
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2 of the License, or
9 * (at your option) any later version.
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
17 #include <linux/module.h>
18 #include <linux/pci.h>
19 #include <media/media-entity.h>
20 #include <media/v4l2-mc.h>
23 struct media_device *v4l2_mc_pci_media_device_init(struct pci_dev *pci_dev,
27 struct media_device *mdev;
29 mdev = kzalloc(sizeof(*mdev), GFP_KERNEL);
33 mdev->dev = &pci_dev->dev;
36 strlcpy(mdev->model, name, sizeof(mdev->model));
38 strlcpy(mdev->model, pci_name(pci_dev), sizeof(mdev->model));
40 sprintf(mdev->bus_info, "PCI:%s", pci_name(pci_dev));
42 mdev->hw_revision = pci_dev->subsystem_vendor << 16
43 || pci_dev->subsystem_device;
45 mdev->driver_version = LINUX_VERSION_CODE;
47 media_device_init(mdev);
54 EXPORT_SYMBOL_GPL(v4l2_mc_pci_media_device_init);
56 int v4l2_mc_create_media_graph(struct media_device *mdev)
59 struct media_entity *entity;
60 struct media_entity *if_vid = NULL, *if_aud = NULL, *sensor = NULL;
61 struct media_entity *tuner = NULL, *decoder = NULL;
62 struct media_entity *io_v4l = NULL, *io_vbi = NULL, *io_swradio = NULL;
63 bool is_webcam = false;
70 media_device_for_each_entity(entity, mdev) {
71 switch (entity->function) {
72 case MEDIA_ENT_F_IF_VID_DECODER:
75 case MEDIA_ENT_F_IF_AUD_DECODER:
78 case MEDIA_ENT_F_TUNER:
81 case MEDIA_ENT_F_ATV_DECODER:
84 case MEDIA_ENT_F_IO_V4L:
87 case MEDIA_ENT_F_IO_VBI:
90 case MEDIA_ENT_F_IO_SWRADIO:
93 case MEDIA_ENT_F_CAM_SENSOR:
100 /* It should have at least one I/O entity */
101 if (!io_v4l && !io_vbi && !io_swradio)
105 * Here, webcams are modelled on a very simple way: the sensor is
106 * connected directly to the I/O entity. All dirty details, like
107 * scaler and crop HW are hidden. While such mapping is not enough
108 * for mc-centric hardware, it is enough for v4l2 interface centric
109 * PC-consumer's hardware.
115 media_device_for_each_entity(entity, mdev) {
116 if (entity->function != MEDIA_ENT_F_CAM_SENSOR)
118 ret = media_create_pad_link(entity, 0,
120 MEDIA_LNK_FL_ENABLED);
128 /* The device isn't a webcam. So, it should have a decoder */
132 /* Link the tuner and IF video output pads */
135 ret = media_create_pad_link(tuner, TUNER_PAD_OUTPUT,
137 IF_VID_DEC_PAD_IF_INPUT,
138 MEDIA_LNK_FL_ENABLED);
141 ret = media_create_pad_link(if_vid, IF_VID_DEC_PAD_OUT,
142 decoder, DEMOD_PAD_IF_INPUT,
143 MEDIA_LNK_FL_ENABLED);
147 ret = media_create_pad_link(tuner, TUNER_PAD_OUTPUT,
148 decoder, DEMOD_PAD_IF_INPUT,
149 MEDIA_LNK_FL_ENABLED);
155 ret = media_create_pad_link(tuner, TUNER_PAD_AUD_OUT,
157 IF_AUD_DEC_PAD_IF_INPUT,
158 MEDIA_LNK_FL_ENABLED);
167 /* Create demod to V4L, VBI and SDR radio links */
169 ret = media_create_pad_link(decoder, DEMOD_PAD_VID_OUT,
171 MEDIA_LNK_FL_ENABLED);
177 ret = media_create_pad_link(decoder, DEMOD_PAD_VID_OUT,
179 MEDIA_LNK_FL_ENABLED);
185 ret = media_create_pad_link(decoder, DEMOD_PAD_VBI_OUT,
187 MEDIA_LNK_FL_ENABLED);
192 /* Create links for the media connectors */
193 flags = MEDIA_LNK_FL_ENABLED;
194 media_device_for_each_entity(entity, mdev) {
195 switch (entity->function) {
196 case MEDIA_ENT_F_CONN_RF:
200 ret = media_create_pad_link(entity, 0, tuner,
204 case MEDIA_ENT_F_CONN_SVIDEO:
205 case MEDIA_ENT_F_CONN_COMPOSITE:
206 case MEDIA_ENT_F_CONN_TEST:
207 ret = media_create_pad_link(entity, 0, decoder,
221 EXPORT_SYMBOL_GPL(v4l2_mc_create_media_graph);