drivers/media/pci/mgb4/mgb4_vin.c
Source file repositories/reference/linux-study-clean/drivers/media/pci/mgb4/mgb4_vin.c
File Facts
- System
- Linux kernel
- Corpus path
drivers/media/pci/mgb4/mgb4_vin.c- Extension
.c- Size
- 30751 bytes
- Lines
- 1079
- Domain
- Driver Families
- Bucket
- drivers/media
- Inferred role
- Driver Families: implementation source
- Status
- source 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.
- Touches user memory; correctness depends on fault-safe copying and privilege boundary handling.
- Uses kernel synchronization; read lock ordering, sleepability, and interrupt context assumptions before translating.
- Touches IRQ or DMA behavior; this matters for the representative real-device path.
- Allocates kernel memory; connect allocation flags and lifetime to context constraints.
- Defines or uses C structs; map object ownership, embedded links, reference counts, and lock ownership.
Dependency Surface
linux/pci.hlinux/workqueue.hlinux/align.hlinux/dma/amd_xdma.hlinux/v4l2-dv-timings.hmedia/v4l2-ioctl.hmedia/videobuf2-v4l2.hmedia/videobuf2-dma-sg.hmedia/v4l2-dv-timings.hmedia/v4l2-event.hmgb4_core.hmgb4_dma.hmgb4_sysfs.hmgb4_io.hmgb4_vout.hmgb4_vin.h
Detected Declarations
function loopback_activefunction set_loopback_paddingfunction get_timingsfunction return_all_buffersfunction queue_setupfunction buffer_initfunction buffer_preparefunction buffer_queuefunction stop_streamingfunction start_streamingfunction fh_openfunction vidioc_querycapfunction vidioc_enum_fmtfunction vidioc_enum_frameintervalsfunction vidioc_g_fmtfunction vidioc_try_fmtfunction vidioc_s_fmtfunction vidioc_enum_inputfunction vidioc_enum_framesizesfunction vidioc_s_inputfunction vidioc_g_inputfunction vidioc_g_parmfunction vidioc_s_parmfunction vidioc_s_dv_timingsfunction vidioc_g_dv_timingsfunction vidioc_query_dv_timingsfunction vidioc_enum_dv_timingsfunction vidioc_dv_timings_capfunction vidioc_subscribe_eventfunction dma_transferfunction signal_changefunction vin_handlerfunction err_handlerfunction deser_initfunction fpga_initfunction create_debugfsfunction mgb4_vin_free
Annotated Snippet
if (config & (1U << 20)) {
f->fmt.pix.colorspace = V4L2_COLORSPACE_REC709;
} else {
if (config & (1U << 19))
f->fmt.pix.colorspace = V4L2_COLORSPACE_SMPTE170M;
else
f->fmt.pix.colorspace = V4L2_COLORSPACE_SRGB;
}
f->fmt.pix.bytesperline = (f->fmt.pix.width + vindev->padding) * 2;
} else {
f->fmt.pix.pixelformat = V4L2_PIX_FMT_ABGR32;
f->fmt.pix.colorspace = V4L2_COLORSPACE_RAW;
f->fmt.pix.bytesperline = (f->fmt.pix.width + vindev->padding) * 4;
}
f->fmt.pix.sizeimage = f->fmt.pix.bytesperline * f->fmt.pix.height;
return 0;
}
static int vidioc_try_fmt(struct file *file, void *priv, struct v4l2_format *f)
{
struct mgb4_vin_dev *vindev = video_drvdata(file);
struct mgb4_regs *video = &vindev->mgbdev->video;
u32 pixelsize;
f->fmt.pix.width = vindev->timings.bt.width;
f->fmt.pix.height = vindev->timings.bt.height;
f->fmt.pix.field = V4L2_FIELD_NONE;
if (has_yuv(video) && f->fmt.pix.pixelformat == V4L2_PIX_FMT_YUYV) {
pixelsize = 2;
if (!(f->fmt.pix.colorspace == V4L2_COLORSPACE_REC709 ||
f->fmt.pix.colorspace == V4L2_COLORSPACE_SMPTE170M))
f->fmt.pix.colorspace = V4L2_COLORSPACE_SRGB;
} else {
pixelsize = 4;
f->fmt.pix.pixelformat = V4L2_PIX_FMT_ABGR32;
f->fmt.pix.colorspace = V4L2_COLORSPACE_RAW;
}
if (f->fmt.pix.bytesperline > f->fmt.pix.width * pixelsize &&
f->fmt.pix.bytesperline < f->fmt.pix.width * pixelsize * 2)
f->fmt.pix.bytesperline = ALIGN(f->fmt.pix.bytesperline,
pixelsize);
else
f->fmt.pix.bytesperline = f->fmt.pix.width * pixelsize;
f->fmt.pix.sizeimage = f->fmt.pix.bytesperline * f->fmt.pix.height;
return 0;
}
static int vidioc_s_fmt(struct file *file, void *priv, struct v4l2_format *f)
{
struct mgb4_vin_dev *vindev = video_drvdata(file);
struct mgb4_regs *video = &vindev->mgbdev->video;
u32 config, pixelsize;
if (vb2_is_busy(&vindev->queue))
return -EBUSY;
vidioc_try_fmt(file, priv, f);
config = mgb4_read_reg(video, vindev->config->regs.config);
if (f->fmt.pix.pixelformat == V4L2_PIX_FMT_YUYV) {
pixelsize = 2;
config |= 1U << 16;
if (f->fmt.pix.colorspace == V4L2_COLORSPACE_REC709) {
config |= 1U << 20;
config |= 1U << 19;
} else if (f->fmt.pix.colorspace == V4L2_COLORSPACE_SMPTE170M) {
config &= ~(1U << 20);
config |= 1U << 19;
} else {
config &= ~(1U << 20);
config &= ~(1U << 19);
}
} else {
pixelsize = 4;
config &= ~(1U << 16);
}
mgb4_write_reg(video, vindev->config->regs.config, config);
vindev->padding = (f->fmt.pix.bytesperline - (f->fmt.pix.width
* pixelsize)) / pixelsize;
return 0;
}
static int vidioc_enum_input(struct file *file, void *priv,
Annotation
- Immediate include surface: `linux/pci.h`, `linux/workqueue.h`, `linux/align.h`, `linux/dma/amd_xdma.h`, `linux/v4l2-dv-timings.h`, `media/v4l2-ioctl.h`, `media/videobuf2-v4l2.h`, `media/videobuf2-dma-sg.h`.
- Detected declarations: `function loopback_active`, `function set_loopback_padding`, `function get_timings`, `function return_all_buffers`, `function queue_setup`, `function buffer_init`, `function buffer_prepare`, `function buffer_queue`, `function stop_streaming`, `function start_streaming`.
- Atlas domain: Driver Families / drivers/media.
- Implementation status: source implementation candidate.
- This snippet crosses the user/kernel memory boundary; validate fault handling and access checks before translating the pattern.
- Synchronization appears in or near this file; preserve lock ordering, sleepability, and interrupt-context constraints.
- IRQ or DMA behavior appears here, which is relevant to the selected PCIe/NVMe device path.
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.