drivers/staging/media/imx/imx-media-capture.c
Source file repositories/reference/linux-study-clean/drivers/staging/media/imx/imx-media-capture.c
File Facts
- System
- Linux kernel
- Corpus path
drivers/staging/media/imx/imx-media-capture.c- Extension
.c- Size
- 27479 bytes
- Lines
- 1056
- Domain
- Driver Families
- Bucket
- drivers/staging
- 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.
- 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/delay.hlinux/fs.hlinux/module.hlinux/pinctrl/consumer.hlinux/platform_device.hlinux/sched.hlinux/slab.hlinux/spinlock.hlinux/timer.hmedia/v4l2-ctrls.hmedia/v4l2-device.hmedia/v4l2-event.hmedia/v4l2-fwnode.hmedia/v4l2-ioctl.hmedia/v4l2-mc.hmedia/v4l2-subdev.hmedia/videobuf2-dma-contig.hvideo/imx-ipu-v3.hmedia/imx.himx-media.h
Detected Declarations
struct capture_privfunction capture_querycapfunction capture_enum_fmt_vid_capfunction capture_enum_framesizesfunction capture_g_fmt_vid_capfunction __capture_try_fmtfunction capture_try_fmt_vid_capfunction capture_s_fmt_vid_capfunction capture_g_selectionfunction capture_subscribe_eventfunction capture_legacy_enum_framesizesfunction capture_legacy_enum_frameintervalsfunction capture_legacy_enum_fmt_vid_capfunction __capture_legacy_try_fmtfunction capture_legacy_try_fmt_vid_capfunction capture_legacy_s_fmt_vid_capfunction capture_legacy_querystdfunction capture_legacy_g_stdfunction capture_legacy_s_stdfunction capture_legacy_g_parmfunction capture_legacy_s_parmfunction capture_legacy_subscribe_eventfunction capture_queue_setupfunction capture_buf_initfunction capture_buf_preparefunction capture_buf_queuefunction capture_validate_fmtfunction capture_start_streamingfunction capture_stop_streamingfunction capture_openfunction capture_releasefunction imx_media_capture_device_next_buffunction imx_media_capture_device_errorfunction capture_init_formatfunction imx_media_capture_device_registerfunction imx_media_capture_device_unregisterfunction imx_media_capture_device_initfunction imx_media_capture_device_removeexport imx_media_capture_device_next_bufexport imx_media_capture_device_errorexport imx_media_capture_device_registerexport imx_media_capture_device_unregisterexport imx_media_capture_device_initexport imx_media_capture_device_remove
Annotated Snippet
struct capture_priv {
struct imx_media_dev *md; /* Media device */
struct device *dev; /* Physical device */
struct imx_media_video_dev vdev; /* Video device */
struct media_pad vdev_pad; /* Video device pad */
struct v4l2_subdev *src_sd; /* Source subdev */
int src_sd_pad; /* Source subdev pad */
struct mutex mutex; /* Protect vdev operations */
struct vb2_queue q; /* The videobuf2 queue */
struct list_head ready_q; /* List of queued buffers */
spinlock_t q_lock; /* Protect ready_q */
struct v4l2_ctrl_handler ctrl_hdlr; /* Controls inherited from subdevs */
bool legacy_api; /* Use the legacy (pre-MC) API */
};
#define to_capture_priv(v) container_of(v, struct capture_priv, vdev)
/* In bytes, per queue */
#define VID_MEM_LIMIT SZ_64M
/* -----------------------------------------------------------------------------
* MC-Centric Video IOCTLs
*/
static const struct imx_media_pixfmt *capture_find_format(u32 code, u32 fourcc)
{
const struct imx_media_pixfmt *cc;
cc = imx_media_find_ipu_format(code, PIXFMT_SEL_YUV_RGB);
if (cc) {
enum imx_pixfmt_sel fmt_sel = cc->cs == IPUV3_COLORSPACE_YUV
? PIXFMT_SEL_YUV : PIXFMT_SEL_RGB;
cc = imx_media_find_pixel_format(fourcc, fmt_sel);
if (!cc) {
imx_media_enum_pixel_formats(&fourcc, 0, fmt_sel, 0);
cc = imx_media_find_pixel_format(fourcc, fmt_sel);
}
return cc;
}
return imx_media_find_mbus_format(code, PIXFMT_SEL_ANY);
}
static int capture_querycap(struct file *file, void *fh,
struct v4l2_capability *cap)
{
struct capture_priv *priv = video_drvdata(file);
strscpy(cap->driver, IMX_CAPTURE_NAME, sizeof(cap->driver));
strscpy(cap->card, IMX_CAPTURE_NAME, sizeof(cap->card));
snprintf(cap->bus_info, sizeof(cap->bus_info),
"platform:%s", dev_name(priv->dev));
return 0;
}
static int capture_enum_fmt_vid_cap(struct file *file, void *fh,
struct v4l2_fmtdesc *f)
{
return imx_media_enum_pixel_formats(&f->pixelformat, f->index,
PIXFMT_SEL_ANY, f->mbus_code);
}
static int capture_enum_framesizes(struct file *file, void *fh,
struct v4l2_frmsizeenum *fsize)
{
const struct imx_media_pixfmt *cc;
if (fsize->index > 0)
return -EINVAL;
cc = imx_media_find_pixel_format(fsize->pixel_format, PIXFMT_SEL_ANY);
if (!cc)
return -EINVAL;
/*
* TODO: The constraints are hardware-specific and may depend on the
* pixel format. This should come from the driver using
* imx_media_capture.
*/
fsize->type = V4L2_FRMSIZE_TYPE_CONTINUOUS;
fsize->stepwise.min_width = 1;
Annotation
- Immediate include surface: `linux/delay.h`, `linux/fs.h`, `linux/module.h`, `linux/pinctrl/consumer.h`, `linux/platform_device.h`, `linux/sched.h`, `linux/slab.h`, `linux/spinlock.h`.
- Detected declarations: `struct capture_priv`, `function capture_querycap`, `function capture_enum_fmt_vid_cap`, `function capture_enum_framesizes`, `function capture_g_fmt_vid_cap`, `function __capture_try_fmt`, `function capture_try_fmt_vid_cap`, `function capture_s_fmt_vid_cap`, `function capture_g_selection`, `function capture_subscribe_event`.
- Atlas domain: Driver Families / drivers/staging.
- Implementation status: integration 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.