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.
- 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.
- Exports symbols or registers init work; inspect boot/module ordering and who consumes the exported contract.
- Uses kernel synchronization; read lock ordering, sleepability, and interrupt context assumptions before translating.
- Defines or uses C structs; map object ownership, embedded links, reference counts, and lock ownership.
Dependency Surface
linux/module.hlinux/pci.hlinux/usb.hmedia/media-device.hmedia/media-entity.hmedia/v4l2-fh.hmedia/v4l2-mc.hmedia/v4l2-subdev.hmedia/videobuf2-core.h
Detected Declarations
function Copyrightfunction media_device_for_each_entityfunction media_device_for_each_entityfunction v4l_enable_media_sourcefunction v4l_disable_media_sourcefunction v4l_vb2q_enable_media_sourcefunction v4l2_create_fwnode_links_to_padfunction fwnode_graph_for_each_endpointfunction v4l2_create_fwnode_linksfunction closefunction pipeline_pm_power_onefunction pipeline_pm_powerfunction v4l2_pipeline_pm_usefunction v4l2_pipeline_pm_getfunction v4l2_pipeline_pm_putfunction v4l2_pipeline_link_notifyexport v4l2_mc_create_media_graphexport v4l_enable_media_sourceexport v4l_disable_media_sourceexport v4l_vb2q_enable_media_sourceexport v4l2_create_fwnode_links_to_padexport v4l2_create_fwnode_linksexport v4l2_pipeline_pm_getexport v4l2_pipeline_pm_putexport v4l2_pipeline_link_notify
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
- Immediate include surface: `linux/module.h`, `linux/pci.h`, `linux/usb.h`, `media/media-device.h`, `media/media-entity.h`, `media/v4l2-fh.h`, `media/v4l2-mc.h`, `media/v4l2-subdev.h`.
- Detected declarations: `function Copyright`, `function media_device_for_each_entity`, `function media_device_for_each_entity`, `function v4l_enable_media_source`, `function v4l_disable_media_source`, `function v4l_vb2q_enable_media_source`, `function v4l2_create_fwnode_links_to_pad`, `function fwnode_graph_for_each_endpoint`, `function v4l2_create_fwnode_links`, `function close`.
- Atlas domain: Driver Families / drivers/media.
- Implementation status: integration implementation candidate.
- Synchronization appears in or near this file; preserve lock ordering, sleepability, and interrupt-context constraints.
Implementation Notes
- This generated page is the file-by-file coverage layer; curated subsystem chapters should link here when they synthesize a multi-file control flow.
- Core OS pages should be promoted from atlas-only to deep-reviewed when they explain data structures, invariants, locking, lifecycle, and C implementation snippets.
- Driver-family pages are intentionally pattern-oriented unless they are part of the selected PCIe/NVMe representative device path.