drivers/media/platform/mediatek/jpeg/mtk_jpeg_enc_hw.c
Source file repositories/reference/linux-study-clean/drivers/media/platform/mediatek/jpeg/mtk_jpeg_enc_hw.c
File Facts
- System
- Linux kernel
- Corpus path
drivers/media/platform/mediatek/jpeg/mtk_jpeg_enc_hw.c- Extension
.c- Size
- 11950 bytes
- Lines
- 408
- 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.
- 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/bitfield.hlinux/bits.hlinux/clk.hlinux/interrupt.hlinux/irq.hlinux/io.hlinux/kernel.hlinux/mod_devicetable.hlinux/module.hlinux/platform_device.hlinux/pm_runtime.hlinux/slab.hmedia/media-device.hmedia/videobuf2-core.hmedia/videobuf2-dma-contig.hmedia/videobuf2-v4l2.hmedia/v4l2-mem2mem.hmedia/v4l2-dev.hmedia/v4l2-device.hmedia/v4l2-fh.hmedia/v4l2-event.hmtk_jpeg_core.hmtk_jpeg_enc_hw.h
Detected Declarations
function mtk_jpeg_enc_resetfunction mtk_jpeg_enc_get_file_sizefunction mtk_jpeg_enc_startfunction mtk_jpeg_set_enc_srcfunction mtk_jpeg_set_enc_dstfunction mtk_jpeg_set_enc_paramsfunction mtk_jpegenc_put_buffunction list_for_each_prev_safefunction mtk_jpegenc_timeout_workfunction mtk_jpegenc_hw_irq_handlerfunction mtk_jpegenc_hw_init_irqfunction mtk_jpegenc_hw_probeexport mtk_jpeg_enc_resetexport mtk_jpeg_enc_get_file_sizeexport mtk_jpeg_enc_startexport mtk_jpeg_set_enc_srcexport mtk_jpeg_set_enc_dstexport mtk_jpeg_set_enc_params
Annotated Snippet
if (support_34bit) {
addr_ext = FIELD_PREP(MTK_JPEG_ADDR_MASK, upper_32_bits(dma_addr));
if (i == 0)
writel(addr_ext, base + JPEG_ENC_SRC_LUMA_ADDR_EXT);
else
writel(addr_ext, base + JPEG_ENC_SRC_CHRO_ADDR_EXT);
}
}
}
EXPORT_SYMBOL_GPL(mtk_jpeg_set_enc_src);
void mtk_jpeg_set_enc_dst(struct mtk_jpeg_ctx *ctx, void __iomem *base,
struct vb2_buffer *dst_buf)
{
dma_addr_t dma_addr;
size_t size;
u32 dma_addr_offset;
u32 dma_addr_offsetmask;
u32 addr_ext;
bool support_34bit = ctx->jpeg->variant->support_34bit;
dma_addr = vb2_dma_contig_plane_dma_addr(dst_buf, 0);
dma_addr_offset = ctx->enable_exif ? MTK_JPEG_MAX_EXIF_SIZE : 0;
dma_addr_offsetmask = dma_addr & JPEG_ENC_DST_ADDR_OFFSET_MASK;
size = vb2_plane_size(dst_buf, 0);
writel(dma_addr_offset & ~0xf, base + JPEG_ENC_OFFSET_ADDR);
writel(dma_addr_offsetmask & 0xf, base + JPEG_ENC_BYTE_OFFSET_MASK);
writel(dma_addr & ~0xf, base + JPEG_ENC_DST_ADDR0);
writel((dma_addr + size) & ~0xf, base + JPEG_ENC_STALL_ADDR0);
if (support_34bit) {
addr_ext = FIELD_PREP(MTK_JPEG_ADDR_MASK, upper_32_bits(dma_addr));
writel(addr_ext, base + JPEG_ENC_DEST_ADDR0_EXT);
writel(addr_ext + size, base + JPEG_ENC_STALL_ADDR0_EXT);
}
}
EXPORT_SYMBOL_GPL(mtk_jpeg_set_enc_dst);
void mtk_jpeg_set_enc_params(struct mtk_jpeg_ctx *ctx, void __iomem *base)
{
u32 value;
u32 width = ctx->out_q.enc_crop_rect.width;
u32 height = ctx->out_q.enc_crop_rect.height;
u32 enc_format = ctx->out_q.fmt->fourcc;
u32 bytesperline = ctx->out_q.pix_mp.plane_fmt[0].bytesperline;
u32 blk_num;
u32 img_stride;
u32 mem_stride;
u32 i, enc_quality;
u32 nr_enc_quality = ARRAY_SIZE(mtk_jpeg_enc_quality);
value = width << 16 | height;
writel(value, base + JPEG_ENC_IMG_SIZE);
if (enc_format == V4L2_PIX_FMT_NV12M ||
enc_format == V4L2_PIX_FMT_NV21M)
/*
* Total 8 x 8 block number of luma and chroma.
* The number of blocks is counted from 0.
*/
blk_num = DIV_ROUND_UP(width, 16) *
DIV_ROUND_UP(height, 16) * 6 - 1;
else
blk_num = DIV_ROUND_UP(width, 16) *
DIV_ROUND_UP(height, 8) * 4 - 1;
writel(blk_num, base + JPEG_ENC_BLK_NUM);
if (enc_format == V4L2_PIX_FMT_NV12M ||
enc_format == V4L2_PIX_FMT_NV21M) {
/* 4:2:0 */
img_stride = round_up(width, 16);
mem_stride = bytesperline;
} else {
/* 4:2:2 */
img_stride = round_up(width * 2, 32);
mem_stride = img_stride;
}
writel(img_stride, base + JPEG_ENC_IMG_STRIDE);
writel(mem_stride, base + JPEG_ENC_STRIDE);
enc_quality = mtk_jpeg_enc_quality[nr_enc_quality - 1].hardware_value;
for (i = 0; i < nr_enc_quality; i++) {
if (ctx->enc_quality <= mtk_jpeg_enc_quality[i].quality_param) {
enc_quality = mtk_jpeg_enc_quality[i].hardware_value;
break;
}
}
writel(enc_quality, base + JPEG_ENC_QUALITY);
Annotation
- Immediate include surface: `linux/bitfield.h`, `linux/bits.h`, `linux/clk.h`, `linux/interrupt.h`, `linux/irq.h`, `linux/io.h`, `linux/kernel.h`, `linux/mod_devicetable.h`.
- Detected declarations: `function mtk_jpeg_enc_reset`, `function mtk_jpeg_enc_get_file_size`, `function mtk_jpeg_enc_start`, `function mtk_jpeg_set_enc_src`, `function mtk_jpeg_set_enc_dst`, `function mtk_jpeg_set_enc_params`, `function mtk_jpegenc_put_buf`, `function list_for_each_prev_safe`, `function mtk_jpegenc_timeout_work`, `function mtk_jpegenc_hw_irq_handler`.
- 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.
- 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.