drivers/media/platform/mediatek/jpeg/mtk_jpeg_dec_parse.c

Source file repositories/reference/linux-study-clean/drivers/media/platform/mediatek/jpeg/mtk_jpeg_dec_parse.c

File Facts

System
Linux kernel
Corpus path
drivers/media/platform/mediatek/jpeg/mtk_jpeg_dec_parse.c
Extension
.c
Size
2825 bytes
Lines
148
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.

Dependency Surface

Detected Declarations

Annotated Snippet

struct mtk_jpeg_stream {
	u8 *addr;
	u32 size;
	u32 curr;
};

static int read_byte(struct mtk_jpeg_stream *stream)
{
	if (stream->curr >= stream->size)
		return -1;
	return stream->addr[stream->curr++];
}

static int read_word_be(struct mtk_jpeg_stream *stream, u32 *word)
{
	u32 temp;
	int byte;

	byte = read_byte(stream);
	if (byte == -1)
		return -1;
	temp = byte << 8;
	byte = read_byte(stream);
	if (byte == -1)
		return -1;
	*word = (u32)byte | temp;

	return 0;
}

static void read_skip(struct mtk_jpeg_stream *stream, long len)
{
	if (len <= 0)
		return;
	while (len--)
		read_byte(stream);
}

static bool mtk_jpeg_do_parse(struct mtk_jpeg_dec_param *param, u8 *src_addr_va,
			      u32 src_size)
{
	bool notfound = true;
	struct mtk_jpeg_stream stream;

	stream.addr = src_addr_va;
	stream.size = src_size;
	stream.curr = 0;

	while (notfound) {
		int i, length, byte;
		u32 word;

		byte = read_byte(&stream);
		if (byte == -1)
			return false;
		if (byte != 0xff)
			continue;
		do
			byte = read_byte(&stream);
		while (byte == 0xff);
		if (byte == -1)
			return false;
		if (byte == 0)
			continue;

		length = 0;
		switch (byte) {
		case JPEG_MARKER_SOF0:
			/* length */
			if (read_word_be(&stream, &word))
				break;

			/* precision */
			if (read_byte(&stream) == -1)
				break;

			if (read_word_be(&stream, &word))
				break;
			param->pic_h = word;

			if (read_word_be(&stream, &word))
				break;
			param->pic_w = word;

			param->comp_num = read_byte(&stream);
			if (param->comp_num != 1 && param->comp_num != 3)
				break;

			for (i = 0; i < param->comp_num; i++) {
				param->comp_id[i] = read_byte(&stream);

Annotation

Implementation Notes