drivers/media/platform/mediatek/jpeg/mtk_jpeg_core.c
Source file repositories/reference/linux-study-clean/drivers/media/platform/mediatek/jpeg/mtk_jpeg_core.c
File Facts
- System
- Linux kernel
- Corpus path
drivers/media/platform/mediatek/jpeg/mtk_jpeg_core.c- Extension
.c- Size
- 53860 bytes
- Lines
- 1968
- 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
linux/clk.hlinux/err.hlinux/interrupt.hlinux/io.hlinux/kernel.hlinux/module.hlinux/of_platform.hlinux/platform_device.hlinux/pm_runtime.hlinux/slab.hlinux/spinlock.hmedia/v4l2-event.hmedia/v4l2-mem2mem.hmedia/v4l2-ioctl.hmedia/videobuf2-core.hmedia/videobuf2-dma-contig.hmtk_jpeg_enc_hw.hmtk_jpeg_dec_hw.hmtk_jpeg_core.hmtk_jpeg_dec_parse.h
Detected Declarations
function mtk_jpeg_querycapfunction vidioc_jpeg_enc_s_ctrlfunction mtk_jpeg_enc_ctrls_setupfunction mtk_jpeg_enum_fmtfunction mtk_jpeg_enum_fmt_vid_capfunction mtk_jpeg_enum_fmt_vid_outfunction mtk_jpeg_find_formatfunction mtk_jpeg_try_fmt_mplanefunction mtk_jpeg_g_fmt_vid_mplanefunction mtk_jpeg_try_fmt_vid_cap_mplanefunction mtk_jpeg_try_fmt_vid_out_mplanefunction mtk_jpeg_s_fmt_mplanefunction mtk_jpeg_s_fmt_vid_out_mplanefunction mtk_jpeg_s_fmt_vid_cap_mplanefunction mtk_jpeg_queue_src_chg_eventfunction mtk_jpeg_subscribe_eventfunction mtk_jpeg_enc_g_selectionfunction mtk_jpeg_dec_g_selectionfunction mtk_jpeg_enc_s_selectionfunction mtk_jpeg_qbuffunction mtk_jpeg_queue_setupfunction mtk_jpeg_buf_preparefunction mtk_jpeg_check_resolution_changefunction mtk_jpeg_find_formatfunction mtk_jpeg_set_queue_datafunction mtk_jpeg_enc_buf_queuefunction mtk_jpeg_dec_buf_queuefunction mtk_jpeg_enc_stop_streamingfunction mtk_jpeg_dec_stop_streamingfunction V4L2_TYPE_IS_CAPTUREfunction mtk_jpeg_set_dec_srcfunction mtk_jpeg_set_dec_dstfunction mtk_jpeg_enc_device_runfunction mtk_jpeg_multicore_enc_device_runfunction mtk_jpeg_multicore_dec_device_runfunction mtk_jpeg_dec_device_runfunction mtk_jpeg_dec_job_readyfunction mtk_jpeg_queue_initfunction mtk_jpeg_clk_onfunction mtk_jpeg_clk_offfunction mtk_jpeg_set_default_paramsfunction mtk_jpeg_openfunction mtk_jpeg_releasefunction mtk_jpeg_job_timeout_workfunction mtk_jpeg_single_core_initfunction mtk_jpeg_destroy_workqueuefunction mtk_jpeg_probefunction mtk_jpeg_remove
Annotated Snippet
if (mtk_jpeg_formats[i].flags & type) {
if (num == f->index)
break;
++num;
}
}
if (i >= n)
return -EINVAL;
f->pixelformat = mtk_jpeg_formats[i].fourcc;
return 0;
}
static int mtk_jpeg_enum_fmt_vid_cap(struct file *file, void *priv,
struct v4l2_fmtdesc *f)
{
struct mtk_jpeg_ctx *ctx = mtk_jpeg_file_to_ctx(file);
struct mtk_jpeg_dev *jpeg = ctx->jpeg;
return mtk_jpeg_enum_fmt(jpeg->variant->formats,
jpeg->variant->num_formats, f,
MTK_JPEG_FMT_FLAG_CAPTURE);
}
static int mtk_jpeg_enum_fmt_vid_out(struct file *file, void *priv,
struct v4l2_fmtdesc *f)
{
struct mtk_jpeg_ctx *ctx = mtk_jpeg_file_to_ctx(file);
struct mtk_jpeg_dev *jpeg = ctx->jpeg;
return mtk_jpeg_enum_fmt(jpeg->variant->formats,
jpeg->variant->num_formats, f,
MTK_JPEG_FMT_FLAG_OUTPUT);
}
static struct mtk_jpeg_q_data *mtk_jpeg_get_q_data(struct mtk_jpeg_ctx *ctx,
enum v4l2_buf_type type)
{
if (V4L2_TYPE_IS_OUTPUT(type))
return &ctx->out_q;
return &ctx->cap_q;
}
static struct mtk_jpeg_fmt *
mtk_jpeg_find_format(struct mtk_jpeg_fmt *mtk_jpeg_formats, int num_formats,
u32 pixelformat, unsigned int fmt_type)
{
unsigned int k;
struct mtk_jpeg_fmt *fmt;
for (k = 0; k < num_formats; k++) {
fmt = &mtk_jpeg_formats[k];
if (fmt->fourcc == pixelformat && fmt->flags & fmt_type)
return fmt;
}
return NULL;
}
static int mtk_jpeg_try_fmt_mplane(struct v4l2_pix_format_mplane *pix_mp,
struct mtk_jpeg_fmt *fmt)
{
int i;
pix_mp->field = V4L2_FIELD_NONE;
pix_mp->num_planes = fmt->colplanes;
pix_mp->pixelformat = fmt->fourcc;
if (fmt->fourcc == V4L2_PIX_FMT_JPEG) {
struct v4l2_plane_pix_format *pfmt = &pix_mp->plane_fmt[0];
pix_mp->height = clamp(pix_mp->height, MTK_JPEG_MIN_HEIGHT,
MTK_JPEG_MAX_HEIGHT);
pix_mp->width = clamp(pix_mp->width, MTK_JPEG_MIN_WIDTH,
MTK_JPEG_MAX_WIDTH);
pfmt->bytesperline = 0;
/* Source size must be aligned to 128 */
pfmt->sizeimage = round_up(pfmt->sizeimage, 128);
if (pfmt->sizeimage == 0)
pfmt->sizeimage = MTK_JPEG_DEFAULT_SIZEIMAGE;
return 0;
}
/* other fourcc */
pix_mp->height = clamp(round_up(pix_mp->height, fmt->v_align),
Annotation
- Immediate include surface: `linux/clk.h`, `linux/err.h`, `linux/interrupt.h`, `linux/io.h`, `linux/kernel.h`, `linux/module.h`, `linux/of_platform.h`, `linux/platform_device.h`.
- Detected declarations: `function mtk_jpeg_querycap`, `function vidioc_jpeg_enc_s_ctrl`, `function mtk_jpeg_enc_ctrls_setup`, `function mtk_jpeg_enum_fmt`, `function mtk_jpeg_enum_fmt_vid_cap`, `function mtk_jpeg_enum_fmt_vid_out`, `function mtk_jpeg_find_format`, `function mtk_jpeg_try_fmt_mplane`, `function mtk_jpeg_g_fmt_vid_mplane`, `function mtk_jpeg_try_fmt_vid_cap_mplane`.
- 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.