drivers/media/v4l2-core/v4l2-mc.c

Source file repositories/reference/linux-study-clean/drivers/media/v4l2-core/v4l2-mc.c

File Facts

System
Linux kernel
Corpus path
drivers/media/v4l2-core/v4l2-mc.c
Extension
.c
Size
16185 bytes
Lines
615
Domain
Driver Families
Bucket
drivers/media
Inferred role
Driver Families: exported/initcall integration point
Status
integration implementation candidate

Why This File Exists

Repeatable hardware-adapter layer. Deep compatibility for every driver is out of scope; this atlas records patterns, probe lifecycles, bus glue, IRQ/DMA usage, and links back to core abstractions.

Dependency Surface

Detected Declarations

Annotated Snippet

switch (entity->function) {
		case MEDIA_ENT_F_IF_VID_DECODER:
			if_vid = entity;
			break;
		case MEDIA_ENT_F_IF_AUD_DECODER:
			if_aud = entity;
			break;
		case MEDIA_ENT_F_TUNER:
			tuner = entity;
			break;
		case MEDIA_ENT_F_ATV_DECODER:
			decoder = entity;
			break;
		case MEDIA_ENT_F_IO_V4L:
			io_v4l = entity;
			break;
		case MEDIA_ENT_F_IO_VBI:
			io_vbi = entity;
			break;
		case MEDIA_ENT_F_IO_SWRADIO:
			io_swradio = entity;
			break;
		case MEDIA_ENT_F_CAM_SENSOR:
			is_webcam = true;
			break;
		}
	}

	/* It should have at least one I/O entity */
	if (!io_v4l && !io_vbi && !io_swradio) {
		dev_warn(mdev->dev, "Didn't find any I/O entity\n");
		return -EINVAL;
	}

	/*
	 * Here, webcams are modelled on a very simple way: the sensor is
	 * connected directly to the I/O entity. All dirty details, like
	 * scaler and crop HW are hidden. While such mapping is not enough
	 * for mc-centric hardware, it is enough for v4l2 interface centric
	 * PC-consumer's hardware.
	 */
	if (is_webcam) {
		if (!io_v4l) {
			dev_warn(mdev->dev, "Didn't find a MEDIA_ENT_F_IO_V4L\n");
			return -EINVAL;
		}

		media_device_for_each_entity(entity, mdev) {
			if (entity->function != MEDIA_ENT_F_CAM_SENSOR)
				continue;
			ret = media_create_pad_link(entity, 0,
						    io_v4l, 0,
						    MEDIA_LNK_FL_ENABLED);
			if (ret) {
				dev_warn(mdev->dev, "Failed to create a sensor link\n");
				return ret;
			}
		}
		if (!decoder)
			return 0;
	}

	/* The device isn't a webcam. So, it should have a decoder */
	if (!decoder) {
		dev_warn(mdev->dev, "Decoder not found\n");
		return -EINVAL;
	}

	/* Link the tuner and IF video output pads */
	if (tuner) {
		if (if_vid) {
			pad_source = media_get_pad_index(tuner,
							 MEDIA_PAD_FL_SOURCE,
							 PAD_SIGNAL_ANALOG);
			pad_sink = media_get_pad_index(if_vid,
						       MEDIA_PAD_FL_SINK,
						       PAD_SIGNAL_ANALOG);
			if (pad_source < 0 || pad_sink < 0) {
				dev_warn(mdev->dev, "Couldn't get tuner and/or PLL pad(s): (%d, %d)\n",
					 pad_source, pad_sink);
				return -EINVAL;
			}
			ret = media_create_pad_link(tuner, pad_source,
						    if_vid, pad_sink,
						    MEDIA_LNK_FL_ENABLED);
			if (ret) {
				dev_warn(mdev->dev, "Couldn't create tuner->PLL link)\n");
				return ret;
			}

Annotation

Implementation Notes