drivers/media/test-drivers/vimc/vimc-capture.c
Source file repositories/reference/linux-study-clean/drivers/media/test-drivers/vimc/vimc-capture.c
File Facts
- System
- Linux kernel
- Corpus path
drivers/media/test-drivers/vimc/vimc-capture.c- Extension
.c- Size
- 13974 bytes
- Lines
- 494
- 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.
- 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
media/v4l2-ioctl.hmedia/videobuf2-core.hmedia/videobuf2-dma-contig.hmedia/videobuf2-vmalloc.hvimc-common.hvimc-streamer.h
Detected Declarations
struct vimc_capture_devicestruct vimc_capture_bufferfunction vimc_capture_querycapfunction vimc_capture_get_formatfunction vimc_capture_g_fmt_vid_capfunction vimc_capture_try_fmt_vid_capfunction vimc_capture_s_fmt_vid_capfunction vimc_capture_enum_fmt_vid_capfunction vimc_capture_enum_framesizesfunction vimc_capture_return_all_buffersfunction list_for_each_entry_safefunction vimc_capture_start_streamingfunction vimc_capture_stop_streamingfunction vimc_capture_buf_queuefunction vimc_capture_queue_setupfunction vimc_capture_buffer_preparefunction vimc_capture_releasefunction vimc_capture_unregister
Annotated Snippet
struct vimc_capture_device {
struct vimc_ent_device ved;
struct video_device vdev;
struct v4l2_pix_format format;
struct vb2_queue queue;
struct list_head buf_list;
/*
* NOTE: in a real driver, a spin lock must be used to access the
* queue because the frames are generated from a hardware interruption
* and the isr is not allowed to sleep.
* Even if it is not necessary a spinlock in the vimc driver, we
* use it here as a code reference
*/
spinlock_t qlock;
struct mutex lock;
u32 sequence;
struct vimc_stream stream;
struct media_pad pad;
};
static const struct v4l2_pix_format fmt_default = {
.width = 640,
.height = 480,
.pixelformat = V4L2_PIX_FMT_RGB24,
.field = V4L2_FIELD_NONE,
.colorspace = V4L2_COLORSPACE_SRGB,
};
struct vimc_capture_buffer {
/*
* struct vb2_v4l2_buffer must be the first element
* the videobuf2 framework will allocate this struct based on
* buf_struct_size and use the first sizeof(struct vb2_buffer) bytes of
* memory as a vb2_buffer
*/
struct vb2_v4l2_buffer vb2;
struct list_head list;
};
static int vimc_capture_querycap(struct file *file, void *priv,
struct v4l2_capability *cap)
{
strscpy(cap->driver, VIMC_PDEV_NAME, sizeof(cap->driver));
strscpy(cap->card, KBUILD_MODNAME, sizeof(cap->card));
return 0;
}
static void vimc_capture_get_format(struct vimc_ent_device *ved,
struct v4l2_pix_format *fmt)
{
struct vimc_capture_device *vcapture = container_of(ved, struct vimc_capture_device,
ved);
*fmt = vcapture->format;
}
static int vimc_capture_g_fmt_vid_cap(struct file *file, void *priv,
struct v4l2_format *f)
{
struct vimc_capture_device *vcapture = video_drvdata(file);
f->fmt.pix = vcapture->format;
return 0;
}
static int vimc_capture_try_fmt_vid_cap(struct file *file, void *priv,
struct v4l2_format *f)
{
struct v4l2_pix_format *format = &f->fmt.pix;
const struct vimc_pix_map *vpix;
format->width = clamp_t(u32, format->width, VIMC_FRAME_MIN_WIDTH,
VIMC_FRAME_MAX_WIDTH) & ~1;
format->height = clamp_t(u32, format->height, VIMC_FRAME_MIN_HEIGHT,
VIMC_FRAME_MAX_HEIGHT) & ~1;
/* Don't accept a pixelformat that is not on the table */
vpix = vimc_pix_map_by_pixelformat(format->pixelformat);
if (!vpix) {
format->pixelformat = fmt_default.pixelformat;
vpix = vimc_pix_map_by_pixelformat(format->pixelformat);
}
/* TODO: Add support for custom bytesperline values */
format->bytesperline = format->width * vpix->bpp;
format->sizeimage = format->bytesperline * format->height;
if (format->field == V4L2_FIELD_ANY)
format->field = fmt_default.field;
Annotation
- Immediate include surface: `media/v4l2-ioctl.h`, `media/videobuf2-core.h`, `media/videobuf2-dma-contig.h`, `media/videobuf2-vmalloc.h`, `vimc-common.h`, `vimc-streamer.h`.
- Detected declarations: `struct vimc_capture_device`, `struct vimc_capture_buffer`, `function vimc_capture_querycap`, `function vimc_capture_get_format`, `function vimc_capture_g_fmt_vid_cap`, `function vimc_capture_try_fmt_vid_cap`, `function vimc_capture_s_fmt_vid_cap`, `function vimc_capture_enum_fmt_vid_cap`, `function vimc_capture_enum_framesizes`, `function vimc_capture_return_all_buffers`.
- Atlas domain: Driver Families / drivers/media.
- Implementation status: source implementation candidate.
- 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.