mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Irui Wang <irui.wang@mediatek.com>
To: Hans Verkuil <hverkuil-cisco@xs4all.nl>,
	Mauro Carvalho Chehab <mchehab@kernel.org>,
	Matthias Brugger <matthias.bgg@gmail.com>,
	<angelogioacchino.delregno@collabora.com>,
	<nicolas.dufresne@collabora.com>,
	kyrie wu <kyrie.wu@mediatek.com>
Cc: <Project_Global_Chrome_Upstream_Group@mediatek.com>,
	<linux-media@vger.kernel.org>, <linux-kernel@vger.kernel.org>,
	<linux-arm-kernel@lists.infradead.org>,
	<linux-mediatek@lists.infradead.org>,
	Tomasz Figa <tfiga@chromium.org>, <xia.jiang@mediatek.com>,
	<maoguang.meng@mediatek.com>,
	Yunfei Dong <yunfei.dong@mediatek.com>,
	Irui Wang <irui.wang@mediatek.com>
Subject: [V1] media: mtk-jpeg: fixes use standard huffman table issue
Date: Thu, 16 Mar 2023 16:19:25 +0800	[thread overview]
Message-ID: <20230316081925.10247-1-irui.wang@mediatek.com> (raw)

From: kyrie wu <kyrie.wu@mediatek.com>

if no found huffman table in file, hw use standard table

Signed-off-by: kyrie wu <kyrie.wu@mediatek.com>
Signed-off-by: irui wang <irui.wang@mediatek.com>
---
This patch dependents on:
https://patchwork.linuxtv.org/project/linux-media/cover/20230310062355.9963-1-irui.wang@mediatek.com/
---
 .../platform/mediatek/jpeg/mtk_jpeg_dec_hw.c  |  9 ++
 .../platform/mediatek/jpeg/mtk_jpeg_dec_hw.h  |  1 +
 .../mediatek/jpeg/mtk_jpeg_dec_parse.c        | 97 +++++++++++--------
 .../platform/mediatek/jpeg/mtk_jpeg_dec_reg.h |  2 +
 4 files changed, 69 insertions(+), 40 deletions(-)

diff --git a/drivers/media/platform/mediatek/jpeg/mtk_jpeg_dec_hw.c b/drivers/media/platform/mediatek/jpeg/mtk_jpeg_dec_hw.c
index 869068fac5e2..62119ef959dc 100644
--- a/drivers/media/platform/mediatek/jpeg/mtk_jpeg_dec_hw.c
+++ b/drivers/media/platform/mediatek/jpeg/mtk_jpeg_dec_hw.c
@@ -378,6 +378,14 @@ static void mtk_jpeg_dec_set_q_table(void __iomem *base, u32 id0, u32 id1,
 	writel(val, base + JPGDEC_REG_QT_ID);
 }
 
+static void mtk_jpeg_dec_set_huffman_mode(void __iomem *base, u8 huffman_tb_exist)
+{
+	if (!huffman_tb_exist) {
+		writel(0x1, base + JPGDEC_REG_ST_HUFFMAN_EN);
+		writel(0x0, base + JPGDEC_REG_BUILD_HUFF_INDEX);
+	}
+}
+
 static void mtk_jpeg_dec_set_dma_group(void __iomem *base, u32 mcu_group,
 				       u32 group_num, u32 last_mcu)
 {
@@ -423,6 +431,7 @@ void mtk_jpeg_dec_set_config(void __iomem *base,
 				 cfg->comp_id[2]);
 	mtk_jpeg_dec_set_q_table(base, cfg->qtbl_num[0],
 				 cfg->qtbl_num[1], cfg->qtbl_num[2]);
+	mtk_jpeg_dec_set_huffman_mode(base, cfg->huffman_tb_exist);
 	mtk_jpeg_dec_set_sampling_factor(base, cfg->comp_num,
 					 cfg->sampling_w[0],
 					 cfg->sampling_h[0],
diff --git a/drivers/media/platform/mediatek/jpeg/mtk_jpeg_dec_hw.h b/drivers/media/platform/mediatek/jpeg/mtk_jpeg_dec_hw.h
index 8c31c6b12417..660df1bee463 100644
--- a/drivers/media/platform/mediatek/jpeg/mtk_jpeg_dec_hw.h
+++ b/drivers/media/platform/mediatek/jpeg/mtk_jpeg_dec_hw.h
@@ -54,6 +54,7 @@ struct mtk_jpeg_dec_param {
 	u32 uv_size;
 	u32 dec_size;
 	u8 uv_brz_w;
+	u8 huffman_tb_exist;
 };
 
 struct mtk_jpeg_bs {
diff --git a/drivers/media/platform/mediatek/jpeg/mtk_jpeg_dec_parse.c b/drivers/media/platform/mediatek/jpeg/mtk_jpeg_dec_parse.c
index b95c45791c29..d0f7a87b3e4b 100644
--- a/drivers/media/platform/mediatek/jpeg/mtk_jpeg_dec_parse.c
+++ b/drivers/media/platform/mediatek/jpeg/mtk_jpeg_dec_parse.c
@@ -12,6 +12,7 @@
 
 #define TEM	0x01
 #define SOF0	0xc0
+#define DHT	0xc4
 #define RST	0xd0
 #define SOI	0xd8
 #define EOI	0xd9
@@ -54,17 +55,65 @@ static void read_skip(struct mtk_jpeg_stream *stream, long len)
 		read_byte(stream);
 }
 
+static bool parse_header(struct mtk_jpeg_stream *stream,
+			 struct mtk_jpeg_dec_param *param)
+{
+	int i, byte;
+	u32 word;
+
+	/* length */
+	if (read_word_be(stream, &word))
+		goto parse_end;
+
+	/* precision */
+	if (read_byte(stream) == -1)
+		goto parse_end;
+
+	if (read_word_be(stream, &word))
+		goto parse_end;
+	param->pic_h = word;
+
+	if (read_word_be(stream, &word))
+		goto parse_end;
+	param->pic_w = word;
+
+	param->comp_num = read_byte(stream);
+	if (param->comp_num != 1 && param->comp_num != 3)
+		goto parse_end;
+
+	for (i = 0; i < param->comp_num; i++) {
+		param->comp_id[i] = read_byte(stream);
+		if (param->comp_id[i] == -1)
+			break;
+
+		/* sampling */
+		byte = read_byte(stream);
+		if (byte == -1)
+			break;
+		param->sampling_w[i] = (byte >> 4) & 0x0F;
+		param->sampling_h[i] = byte & 0x0F;
+
+		param->qtbl_num[i] = read_byte(stream);
+		if (param->qtbl_num[i] == -1)
+			break;
+	}
+
+parse_end:
+	return !(i == param->comp_num);
+}
+
 static bool mtk_jpeg_do_parse(struct mtk_jpeg_dec_param *param, u8 *src_addr_va,
 			      u32 src_size)
 {
 	bool notfound = true;
+	bool file_end = false;
 	struct mtk_jpeg_stream stream;
 
 	stream.addr = src_addr_va;
 	stream.size = src_size;
 	stream.curr = 0;
 
-	while (notfound) {
+	while (!file_end && (!param->huffman_tb_exist || notfound)) {
 		int i, length, byte;
 		u32 word;
 
@@ -84,50 +133,18 @@ static bool mtk_jpeg_do_parse(struct mtk_jpeg_dec_param *param, u8 *src_addr_va,
 		length = 0;
 		switch (byte) {
 		case 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);
-				if (param->comp_id[i] == -1)
-					break;
-
-				/* sampling */
-				byte = read_byte(&stream);
-				if (byte == -1)
-					break;
-				param->sampling_w[i] = (byte >> 4) & 0x0F;
-				param->sampling_h[i] = byte & 0x0F;
-
-				param->qtbl_num[i] = read_byte(&stream);
-				if (param->qtbl_num[i] == -1)
-					break;
-			}
-
-			notfound = !(i == param->comp_num);
+			notfound = parse_header(&stream, param);
 			break;
 		case RST ... RST + 7:
 		case SOI:
-		case EOI:
 		case TEM:
 			break;
+		case EOI:
+			file_end = true;
+			break;
+		case DHT:
+			param->huffman_tb_exist = 1;
+			break;
 		default:
 			if (read_word_be(&stream, &word))
 				break;
diff --git a/drivers/media/platform/mediatek/jpeg/mtk_jpeg_dec_reg.h b/drivers/media/platform/mediatek/jpeg/mtk_jpeg_dec_reg.h
index 27b7711ca341..b5ae4d9fe0a8 100644
--- a/drivers/media/platform/mediatek/jpeg/mtk_jpeg_dec_reg.h
+++ b/drivers/media/platform/mediatek/jpeg/mtk_jpeg_dec_reg.h
@@ -45,6 +45,8 @@
 #define JPGDEC_REG_QT_ID		0x0270
 #define JPGDEC_REG_INTERRUPT_STATUS	0x0274
 #define JPGDEC_REG_STATUS		0x0278
+#define JPGDEC_REG_ST_HUFFMAN_EN	0x320
+#define JPGDEC_REG_BUILD_HUFF_INDEX	0x330
 #define JPGDEC_REG_BIT_STREAM_SIZE	0x0344
 
 #endif /* _MTK_JPEG_REG_H */
-- 
2.18.0


             reply	other threads:[~2023-03-16  8:34 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-03-16  8:19 Irui Wang [this message]
2023-03-17 16:46 ` kernel test robot

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20230316081925.10247-1-irui.wang@mediatek.com \
    --to=irui.wang@mediatek.com \
    --cc=Project_Global_Chrome_Upstream_Group@mediatek.com \
    --cc=angelogioacchino.delregno@collabora.com \
    --cc=hverkuil-cisco@xs4all.nl \
    --cc=kyrie.wu@mediatek.com \
    --cc=linux-arm-kernel@lists.infradead.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-media@vger.kernel.org \
    --cc=linux-mediatek@lists.infradead.org \
    --cc=maoguang.meng@mediatek.com \
    --cc=matthias.bgg@gmail.com \
    --cc=mchehab@kernel.org \
    --cc=nicolas.dufresne@collabora.com \
    --cc=tfiga@chromium.org \
    --cc=xia.jiang@mediatek.com \
    --cc=yunfei.dong@mediatek.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®