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 */
