Skip to contentSkip to conversation

Add Mediatek JPEG Decoder

PATCH Superseded Rick Chang 2 participants 8 messages Nov 30, 2016 – Dec 14, 2016

Subsystems (3)

v8 of 9 Superseded Latest is v9 →

lore
Share & tools
lore

Rick Chang

author
#0 lore raw

v8 cover Add Mediatek JPEG Decoder

This series of patches provide a v4l2 driver to control Mediatek JPEG decoder for decoding JPEG image and Motion JPEG bitstream.

changes since v7:
- Update MAINTAINERS

changes since v6:
- fix kbuild test fail
- Add patch for MAINTAINERS

changes since v5:
- remove redundant name from struct mtk_jpeg_fmt
- Set state of all buffers to VB2_BUF_STATE_QUEUED if fail in start streaming
- Remove VB2_USERPTR
- Add check for buffer index

changes since v4:
- Change file name of binding documentation
- Revise DT binding documentation
- Revise compatible string

changes since v3:
- Revise DT binding documentation
- Revise compatible string

changes since v2:
- Revise DT binding documentation

changes since v1:
- Rebase for v4.9-rc1.
- Update Compliance test version and result
- Remove redundant path in Makefile
- Fix potential build error without CONFIG_PM_RUNTIME and CONFIG_PM_SLEEP
- Fix warnings from patch check and smatch check

* Dependency
The patch "arm: dts: mt2701: Add node for JPEG decoder" depends on:
CCF "Add clock support for Mediatek MT2701"[1]
iommu and smi "Add the dtsi node of iommu and smi for mt2701"[2]

[1] http://lists.infradead.org/pipermail/linux-mediatek/2016-October/007271.html
[2] https://patchwork.kernel.org/patch/9164013/

* Compliance test
v4l2-compliance SHA : 4ad7174b908a36c4f315e3fe2efa7e2f8a6f375a

Driver Info:

        Driver name   : mtk-jpeg decode
        Card type     : mtk-jpeg decoder
        Bus info      : platform:15004000.jpegdec

Driver version: 4.9.0
Capabilities : 0x84204000
Video Memory-to-Memory Multiplanar Streaming
Extended Pix Format
Device Capabilities
Device Caps : 0x04204000
Video Memory-to-Memory Multiplanar Streaming
Extended Pix Format

Compliance test for device /dev/video3 (not using libv4l2):

Required ioctls:
test VIDIOC_QUERYCAP: OK

Allow for multiple opens:
test second video open: OK
test VIDIOC_QUERYCAP: OK
test VIDIOC_G/S_PRIORITY: OK
test for unlimited opens: OK

Debug ioctls:
test VIDIOC_DBG_G/S_REGISTER: OK (Not Supported) test VIDIOC_LOG_STATUS: OK (Not Supported)

Input ioctls:
test VIDIOC_G/S_TUNER/ENUM_FREQ_BANDS: OK (Not Supported) test VIDIOC_G/S_FREQUENCY: OK (Not Supported) test VIDIOC_S_HW_FREQ_SEEK: OK (Not Supported) test VIDIOC_ENUMAUDIO: OK (Not Supported)
test VIDIOC_G/S/ENUMINPUT: OK (Not Supported) test VIDIOC_G/S_AUDIO: OK (Not Supported)
Inputs: 0 Audio Inputs: 0 Tuners: 0

Output ioctls:
test VIDIOC_G/S_MODULATOR: OK (Not Supported) test VIDIOC_G/S_FREQUENCY: OK (Not Supported) test VIDIOC_ENUMAUDOUT: OK (Not Supported) test VIDIOC_G/S/ENUMOUTPUT: OK (Not Supported) test VIDIOC_G/S_AUDOUT: OK (Not Supported)
Outputs: 0 Audio Outputs: 0 Modulators: 0

Input/Output configuration ioctls:
test VIDIOC_ENUM/G/S/QUERY_STD: OK (Not Supported) test VIDIOC_ENUM/G/S/QUERY_DV_TIMINGS: OK (Not Supported) test VIDIOC_DV_TIMINGS_CAP: OK (Not Supported) test VIDIOC_G/S_EDID: OK (Not Supported)

Control ioctls:
test VIDIOC_QUERY_EXT_CTRL/QUERYMENU: OK (Not Supported) test VIDIOC_QUERYCTRL: OK (Not Supported)
test VIDIOC_G/S_CTRL: OK (Not Supported)
test VIDIOC_G/S/TRY_EXT_CTRLS: OK (Not Supported) test VIDIOC_(UN)SUBSCRIBE_EVENT/DQEVENT: OK (Not Supported) test VIDIOC_G/S_JPEGCOMP: OK (Not Supported) Standard Controls: 0 Private Controls: 0

Format ioctls:
test VIDIOC_ENUM_FMT/FRAMESIZES/FRAMEINTERVALS: OK test VIDIOC_G/S_PARM: OK (Not Supported) test VIDIOC_G_FBUF: OK (Not Supported) test VIDIOC_G_FMT: OK
test VIDIOC_TRY_FMT: OK
test VIDIOC_S_FMT: OK
test VIDIOC_G_SLICED_VBI_CAP: OK (Not Supported) test Cropping: OK (Not Supported)
test Composing: OK
test Scaling: OK

Codec ioctls:
test VIDIOC_(TRY_)ENCODER_CMD: OK (Not Supported) test VIDIOC_G_ENC_INDEX: OK (Not Supported) test VIDIOC_(TRY_)DECODER_CMD: OK (Not Supported)

Buffer ioctls:
test VIDIOC_REQBUFS/CREATE_BUFS/QUERYBUF: OK test VIDIOC_EXPBUF: OK

Test input 0:

Total: 43, Succeeded: 43, Failed: 0, Warnings: 0

Rick Chang (4):
dt-bindings: mediatek: Add a binding for Mediatek JPEG Decoder
vcodec: mediatek: Add Mediatek JPEG Decoder Driver
arm: dts: mt2701: Add node for Mediatek JPEG Decoder
vcodec: mediatek: Add Maintainers entry for Mediatek JPEG driver

 .../bindings/media/mediatek-jpeg-decoder.txt       |   37 +
 MAINTAINERS                                        |    7 +
 arch/arm/boot/dts/mt2701.dtsi                      |   14 +
 drivers/media/platform/Kconfig                     |   15 +
 drivers/media/platform/Makefile                    |    2 +
 drivers/media/platform/mtk-jpeg/Makefile           |    2 +
 drivers/media/platform/mtk-jpeg/mtk_jpeg_core.c    | 1302 ++++++++++++++++++++
 drivers/media/platform/mtk-jpeg/mtk_jpeg_core.h    |  139 +++
 drivers/media/platform/mtk-jpeg/mtk_jpeg_hw.c      |  417 +++++++
 drivers/media/platform/mtk-jpeg/mtk_jpeg_hw.h      |   91 ++
 drivers/media/platform/mtk-jpeg/mtk_jpeg_parse.c   |  160 +++
 drivers/media/platform/mtk-jpeg/mtk_jpeg_parse.h   |   25 +
 drivers/media/platform/mtk-jpeg/mtk_jpeg_reg.h     |   58 +
 13 files changed, 2269 insertions(+)
 create mode 100644 Documentation/devicetree/bindings/media/mediatek-jpeg-decoder.txt
 create mode 100644 drivers/media/platform/mtk-jpeg/Makefile
 create mode 100644 drivers/media/platform/mtk-jpeg/mtk_jpeg_core.c
 create mode 100644 drivers/media/platform/mtk-jpeg/mtk_jpeg_core.h
 create mode 100644 drivers/media/platform/mtk-jpeg/mtk_jpeg_hw.c
 create mode 100644 drivers/media/platform/mtk-jpeg/mtk_jpeg_hw.h
 create mode 100644 drivers/media/platform/mtk-jpeg/mtk_jpeg_parse.c
 create mode 100644 drivers/media/platform/mtk-jpeg/mtk_jpeg_parse.h
 create mode 100644 drivers/media/platform/mtk-jpeg/mtk_jpeg_reg.h
Signature · 1 line
1.9.1
author
#1 lore raw

PATCH v8 1/4 dt-bindings: mediatek: Add a binding for Mediatek JPEG Decoder

Add a DT binding documentation for Mediatek JPEG Decoder of MT2701 SoC.

---
 .../bindings/media/mediatek-jpeg-decoder.txt       | 37 ++++++++++++++++++++++
 1 file changed, 37 insertions(+)
 create mode 100644 Documentation/devicetree/bindings/media/mediatek-jpeg-decoder.txt
Documentation/devicetree/bindings/media/mediatek-jpeg-decoder.txt new file +37 -0
new file mode 100644
index 0000000..3813947
@@ -0,0 +1,37 @@
+* Mediatek JPEG Decoder
+
+Mediatek JPEG Decoder is the JPEG decode hardware present in Mediatek SoCs
+
+Required properties:
+- compatible : must be one of the following string:
+	"mediatek,mt8173-jpgdec"
+	"mediatek,mt2701-jpgdec"
+- reg : physical base address of the jpeg decoder registers and length of
+  memory mapped region.
+- interrupts : interrupt number to the interrupt controller.
+- clocks: device clocks, see
+  Documentation/devicetree/bindings/clock/clock-bindings.txt for details.
+- clock-names: must contain "jpgdec-smi" and "jpgdec".
+- power-domains: a phandle to the power domain, see
+  Documentation/devicetree/bindings/power/power_domain.txt for details.
+- mediatek,larb: must contain the local arbiters in the current Socs, see
+  Documentation/devicetree/bindings/memory-controllers/mediatek,smi-larb.txt
+  for details.
+- iommus: should point to the respective IOMMU block with master port as
+  argument, see Documentation/devicetree/bindings/iommu/mediatek,iommu.txt
+  for details.
+
+Example:
+	jpegdec: jpegdec at 15004000 {
+		compatible = "mediatek,mt2701-jpgdec";
+		reg = <0 0x15004000 0 0x1000>;
+		interrupts = <GIC_SPI 143 IRQ_TYPE_LEVEL_LOW>;
+		clocks =  <&imgsys CLK_IMG_JPGDEC_SMI>,
+			  <&imgsys CLK_IMG_JPGDEC>;
+		clock-names = "jpgdec-smi",
+			      "jpgdec";
+		power-domains = <&scpsys MT2701_POWER_DOMAIN_ISP>;
+		mediatek,larb = <&larb2>;
+		iommus = <&iommu MT2701_M4U_PORT_JPGDEC_WDMA>,
+			 <&iommu MT2701_M4U_PORT_JPGDEC_BSDMA>;
+	};
Signature · 1 line
1.9.1
author
#2 lore raw

PATCH v8 2/4 vcodec: mediatek: Add Mediatek JPEG Decoder Driver

In reply to Rick Chang

Add v4l2 driver for Mediatek JPEG Decoder

---
 drivers/media/platform/Kconfig                   |   15 +
 drivers/media/platform/Makefile                  |    2 +
 drivers/media/platform/mtk-jpeg/Makefile         |    2 +
 drivers/media/platform/mtk-jpeg/mtk_jpeg_core.c  | 1302 ++++++++++++++++++++++
 drivers/media/platform/mtk-jpeg/mtk_jpeg_core.h  |  139 +++
 drivers/media/platform/mtk-jpeg/mtk_jpeg_hw.c    |  417 +++++++
 drivers/media/platform/mtk-jpeg/mtk_jpeg_hw.h    |   91 ++
 drivers/media/platform/mtk-jpeg/mtk_jpeg_parse.c |  160 +++
 drivers/media/platform/mtk-jpeg/mtk_jpeg_parse.h |   25 +
 drivers/media/platform/mtk-jpeg/mtk_jpeg_reg.h   |   58 +
 10 files changed, 2211 insertions(+)
 create mode 100644 drivers/media/platform/mtk-jpeg/Makefile
 create mode 100644 drivers/media/platform/mtk-jpeg/mtk_jpeg_core.c
 create mode 100644 drivers/media/platform/mtk-jpeg/mtk_jpeg_core.h
 create mode 100644 drivers/media/platform/mtk-jpeg/mtk_jpeg_hw.c
 create mode 100644 drivers/media/platform/mtk-jpeg/mtk_jpeg_hw.h
 create mode 100644 drivers/media/platform/mtk-jpeg/mtk_jpeg_parse.c
 create mode 100644 drivers/media/platform/mtk-jpeg/mtk_jpeg_parse.h
 create mode 100644 drivers/media/platform/mtk-jpeg/mtk_jpeg_reg.h
drivers/media/platform/Kconfig +15 -0
index 754edbf1..96c9887 100644
@@ -162,6 +162,21 @@ config VIDEO_CODA
 	   Coda is a range of video codec IPs that supports
 	   H.264, MPEG-4, and other video formats.
 
+config VIDEO_MEDIATEK_JPEG
+	tristate "Mediatek JPEG Codec driver"
+	depends on MTK_IOMMU_V1 || COMPILE_TEST
+	depends on VIDEO_DEV && VIDEO_V4L2
+	depends on ARCH_MEDIATEK || COMPILE_TEST
+	depends on HAS_DMA
+	select VIDEOBUF2_DMA_CONTIG
+	select V4L2_MEM2MEM_DEV
+	---help---
+	  Mediatek jpeg codec driver provides HW capability to decode
+	  JPEG format
+
+	  To compile this driver as a module, choose M here: the
+	  module will be called mtk-jpeg
+
 config VIDEO_MEDIATEK_VPU
 	tristate "Mediatek Video Processor Unit"
 	depends on VIDEO_DEV && VIDEO_V4L2 && HAS_DMA
drivers/media/platform/Makefile +2 -0
index f842933..cf701e3 100644
@@ -68,3 +68,5 @@ obj-$(CONFIG_VIDEO_MEDIATEK_VPU)	+= mtk-vpu/
 obj-$(CONFIG_VIDEO_MEDIATEK_VCODEC)	+= mtk-vcodec/
 
 obj-$(CONFIG_VIDEO_MEDIATEK_MDP)	+= mtk-mdp/
+
+obj-$(CONFIG_VIDEO_MEDIATEK_JPEG)	+= mtk-jpeg/
drivers/media/platform/mtk-jpeg/Makefile new file +2 -0
new file mode 100644
index 0000000..b2e6069
@@ -0,0 +1,2 @@
+mtk_jpeg-objs := mtk_jpeg_core.o mtk_jpeg_hw.o mtk_jpeg_parse.o
+obj-$(CONFIG_VIDEO_MEDIATEK_JPEG) += mtk_jpeg.o
drivers/media/platform/mtk-jpeg/mtk_jpeg_core.c new file +1302 -0

1,302 lines not on this page · raw message

drivers/media/platform/mtk-jpeg/mtk_jpeg_core.h new file +139 -0

139 lines not on this page · raw message

drivers/media/platform/mtk-jpeg/mtk_jpeg_hw.c new file +417 -0

417 lines not on this page · raw message

drivers/media/platform/mtk-jpeg/mtk_jpeg_hw.h new file +91 -0

91 lines not on this page · raw message

drivers/media/platform/mtk-jpeg/mtk_jpeg_parse.c new file +160 -0

160 lines not on this page · raw message

drivers/media/platform/mtk-jpeg/mtk_jpeg_parse.h new file +25 -0
new file mode 100644
index 0000000..5d92340
@@ -0,0 +1,25 @@
+/*
+ * Copyright (c) 2016 MediaTek Inc.
+ * Author: Ming Hsiu Tsai <[email protected]>
+ *         Rick Chang <[email protected]>
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2 as
+ * published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ */
+
+#ifndef _MTK_JPEG_PARSE_H
+#define _MTK_JPEG_PARSE_H
+
+#include "mtk_jpeg_hw.h"
+
+bool mtk_jpeg_parse(struct mtk_jpeg_dec_param *param, u8 *src_addr_va,
+		    u32 src_size);
+
+#endif /* _MTK_JPEG_PARSE_H */
+
drivers/media/platform/mtk-jpeg/mtk_jpeg_reg.h new file +58 -0

58 lines not on this page · raw message

Signature · 1 line
1.9.1
#3 lore raw

Re: [PATCH v8 2/4] vcodec: mediatek: Add Mediatek JPEG Decoder Driver

Hi Rick,

Quoted 4 lines · Rick Chang

Add v4l2 driver for Mediatek JPEG Decoder

<snip...>

Quoted 19 lines
drivers/media/platform/mtk-jpeg/mtk_jpeg_core.c new file +19 -0
+static bool mtk_jpeg_check_resolution_change(struct mtk_jpeg_ctx *ctx,
+                                            struct mtk_jpeg_dec_param *param)
+{
+       struct mtk_jpeg_dev *jpeg = ctx->jpeg;
+       struct mtk_jpeg_q_data *q_data;
+
+       q_data = &ctx->out_q;
+       if (q_data->w != param->pic_w || q_data->h != param->pic_h) {
+               v4l2_dbg(1, debug, &jpeg->v4l2_dev, "Picture size change\n");
+               return true;
+       }
+
+       q_data = &ctx->cap_q;
+       if (q_data->fmt != mtk_jpeg_find_format(ctx, param->dst_fourcc,
+                                               MTK_JPEG_FMT_TYPE_CAPTURE)) {
+               v4l2_dbg(1, debug, &jpeg->v4l2_dev, "format change\n");
+               return true;
+       }
+       return false;

<snip...>

Quoted 19 lines
drivers/media/platform/mtk-jpeg/mtk_jpeg_core.c new file +19 -0
+static void mtk_jpeg_device_run(void *priv)
+{
+       struct mtk_jpeg_ctx *ctx = priv;
+       struct mtk_jpeg_dev *jpeg = ctx->jpeg;
+       struct vb2_buffer *src_buf, *dst_buf;
+       enum vb2_buffer_state buf_state = VB2_BUF_STATE_ERROR;
+       unsigned long flags;
+       struct mtk_jpeg_src_buf *jpeg_src_buf;
+       struct mtk_jpeg_bs bs;
+       struct mtk_jpeg_fb fb;
+       int i;
+
+       src_buf = v4l2_m2m_next_src_buf(ctx->fh.m2m_ctx);
+       dst_buf = v4l2_m2m_next_dst_buf(ctx->fh.m2m_ctx);
+       jpeg_src_buf = mtk_jpeg_vb2_to_srcbuf(src_buf);
+
+       if (jpeg_src_buf->flags & MTK_JPEG_BUF_FLAGS_LAST_FRAME) {
+               for (i = 0; i < dst_buf->num_planes; i++)
+                       vb2_set_plane_payload(dst_buf, i, 0);

drivers/media/platform/mtk-jpeg/mtk_jpeg_core.c line 829

Quoted 10 lines
drivers/media/platform/mtk-jpeg/mtk_jpeg_core.c new file +10 -0
+               buf_state = VB2_BUF_STATE_DONE;
+               goto dec_end;
+       }
+
+       if (mtk_jpeg_check_resolution_change(ctx, &jpeg_src_buf->dec_param)) {
+               mtk_jpeg_queue_src_chg_event(ctx);
+               ctx->state = MTK_JPEG_SOURCE_CHANGE;
+               v4l2_m2m_job_finish(jpeg->m2m_dev, ctx->fh.m2m_ctx);
+               return;
+       }

This only detects source change if multiple OUPUT buffers are queued. It does not catch the source change in the following scenario:

- OUPUT buffers for jpeg1 enqueued
- OUTPUT queue STREAMON
- userspace creates CAPTURE buffers
- CAPTURE buffers enqueued
- CAPTURE queue STREAMON
- decode
- OUTPUT queue STREAMOFF
- userspace recreates OUTPUT buffers for jpeg2
- OUTPUT buffers for jpeg2 enqueued
- OUTPUT queue STREAMON

In the above sequence if jpeg2's decoded size is larger than jpeg1 the function fails to detect that the existing CAPTURE buffers are not big enough to hold the decoded data.

A possible fix is to pass *dst_buf to mtk_jpeg_check_resolution_change(), and check in the function that all the dst_buf planes are large enough to hold the decoded data.

Quoted 21 lines
drivers/media/platform/mtk-jpeg/mtk_jpeg_core.c new file +21 -0
+
+       mtk_jpeg_set_dec_src(ctx, src_buf, &bs);
+       if (mtk_jpeg_set_dec_dst(ctx, &jpeg_src_buf->dec_param, dst_buf, &fb))
+               goto dec_end;
+
+       spin_lock_irqsave(&jpeg->hw_lock, flags);
+       mtk_jpeg_dec_reset(jpeg->dec_reg_base);
+       mtk_jpeg_dec_set_config(jpeg->dec_reg_base,
+                               &jpeg_src_buf->dec_param, &bs, &fb);
+
+       mtk_jpeg_dec_start(jpeg->dec_reg_base);
+       spin_unlock_irqrestore(&jpeg->hw_lock, flags);
+       return;
+
+dec_end:
+       v4l2_m2m_src_buf_remove(ctx->fh.m2m_ctx);
+       v4l2_m2m_dst_buf_remove(ctx->fh.m2m_ctx);
+       v4l2_m2m_buf_done(to_vb2_v4l2_buffer(src_buf), buf_state);
+       v4l2_m2m_buf_done(to_vb2_v4l2_buffer(dst_buf), buf_state);
+       v4l2_m2m_job_finish(jpeg->m2m_dev, ctx->fh.m2m_ctx);
+}

<snip...>

author
#4 lore raw

Re: [PATCH v8 2/4] vcodec: mediatek: Add Mediatek JPEG Decoder Driver

Hi Ricky,

Thanks for your feedback. We will fix the problem in another patch.

Quoted 107 lines · Ricky Liang

Hi Rick,

Quoted 4 lines · Rick Chang

Add v4l2 driver for Mediatek JPEG Decoder

<snip...>

Quoted 19 lines
drivers/media/platform/mtk-jpeg/mtk_jpeg_core.c new file +19 -0
+static bool mtk_jpeg_check_resolution_change(struct mtk_jpeg_ctx *ctx,
+                                            struct mtk_jpeg_dec_param *param)
+{
+       struct mtk_jpeg_dev *jpeg = ctx->jpeg;
+       struct mtk_jpeg_q_data *q_data;
+
+       q_data = &ctx->out_q;
+       if (q_data->w != param->pic_w || q_data->h != param->pic_h) {
+               v4l2_dbg(1, debug, &jpeg->v4l2_dev, "Picture size change\n");
+               return true;
+       }
+
+       q_data = &ctx->cap_q;
+       if (q_data->fmt != mtk_jpeg_find_format(ctx, param->dst_fourcc,
+                                               MTK_JPEG_FMT_TYPE_CAPTURE)) {
+               v4l2_dbg(1, debug, &jpeg->v4l2_dev, "format change\n");
+               return true;
+       }
+       return false;

<snip...>

Quoted 19 lines
drivers/media/platform/mtk-jpeg/mtk_jpeg_core.c new file +19 -0
+static void mtk_jpeg_device_run(void *priv)
+{
+       struct mtk_jpeg_ctx *ctx = priv;
+       struct mtk_jpeg_dev *jpeg = ctx->jpeg;
+       struct vb2_buffer *src_buf, *dst_buf;
+       enum vb2_buffer_state buf_state = VB2_BUF_STATE_ERROR;
+       unsigned long flags;
+       struct mtk_jpeg_src_buf *jpeg_src_buf;
+       struct mtk_jpeg_bs bs;
+       struct mtk_jpeg_fb fb;
+       int i;
+
+       src_buf = v4l2_m2m_next_src_buf(ctx->fh.m2m_ctx);
+       dst_buf = v4l2_m2m_next_dst_buf(ctx->fh.m2m_ctx);
+       jpeg_src_buf = mtk_jpeg_vb2_to_srcbuf(src_buf);
+
+       if (jpeg_src_buf->flags & MTK_JPEG_BUF_FLAGS_LAST_FRAME) {
+               for (i = 0; i < dst_buf->num_planes; i++)
+                       vb2_set_plane_payload(dst_buf, i, 0);

drivers/media/platform/mtk-jpeg/mtk_jpeg_core.c line 829

Quoted 10 lines
drivers/media/platform/mtk-jpeg/mtk_jpeg_core.c new file +10 -0
+               buf_state = VB2_BUF_STATE_DONE;
+               goto dec_end;
+       }
+
+       if (mtk_jpeg_check_resolution_change(ctx, &jpeg_src_buf->dec_param)) {
+               mtk_jpeg_queue_src_chg_event(ctx);
+               ctx->state = MTK_JPEG_SOURCE_CHANGE;
+               v4l2_m2m_job_finish(jpeg->m2m_dev, ctx->fh.m2m_ctx);
+               return;
+       }

This only detects source change if multiple OUPUT buffers are queued. It does not catch the source change in the following scenario:

- OUPUT buffers for jpeg1 enqueued
- OUTPUT queue STREAMON
- userspace creates CAPTURE buffers
- CAPTURE buffers enqueued
- CAPTURE queue STREAMON
- decode
- OUTPUT queue STREAMOFF
- userspace recreates OUTPUT buffers for jpeg2
- OUTPUT buffers for jpeg2 enqueued
- OUTPUT queue STREAMON

In the above sequence if jpeg2's decoded size is larger than jpeg1 the function fails to detect that the existing CAPTURE buffers are not big enough to hold the decoded data.

A possible fix is to pass *dst_buf to mtk_jpeg_check_resolution_change(), and check in the function that all the dst_buf planes are large enough to hold the decoded data.

Quoted 21 lines
drivers/media/platform/mtk-jpeg/mtk_jpeg_core.c new file +21 -0
+
+       mtk_jpeg_set_dec_src(ctx, src_buf, &bs);
+       if (mtk_jpeg_set_dec_dst(ctx, &jpeg_src_buf->dec_param, dst_buf, &fb))
+               goto dec_end;
+
+       spin_lock_irqsave(&jpeg->hw_lock, flags);
+       mtk_jpeg_dec_reset(jpeg->dec_reg_base);
+       mtk_jpeg_dec_set_config(jpeg->dec_reg_base,
+                               &jpeg_src_buf->dec_param, &bs, &fb);
+
+       mtk_jpeg_dec_start(jpeg->dec_reg_base);
+       spin_unlock_irqrestore(&jpeg->hw_lock, flags);
+       return;
+
+dec_end:
+       v4l2_m2m_src_buf_remove(ctx->fh.m2m_ctx);
+       v4l2_m2m_dst_buf_remove(ctx->fh.m2m_ctx);
+       v4l2_m2m_buf_done(to_vb2_v4l2_buffer(src_buf), buf_state);
+       v4l2_m2m_buf_done(to_vb2_v4l2_buffer(dst_buf), buf_state);
+       v4l2_m2m_job_finish(jpeg->m2m_dev, ctx->fh.m2m_ctx);
+}

<snip...>

#5 lore raw

Re: [PATCH v8 2/4] vcodec: mediatek: Add Mediatek JPEG Decoder Driver

Hi Rick,

Can you upload patchset v9 to address the issue? Thanks!

Quoted 114 lines · Rick Chang

Hi Ricky,

Thanks for your feedback. We will fix the problem in another patch.

Quoted 107 lines · Ricky Liang

Hi Rick,

Quoted 4 lines · Rick Chang

Add v4l2 driver for Mediatek JPEG Decoder

<snip...>

Quoted 19 lines
drivers/media/platform/mtk-jpeg/mtk_jpeg_core.c new file +19 -0
+static bool mtk_jpeg_check_resolution_change(struct mtk_jpeg_ctx *ctx,
+                                            struct mtk_jpeg_dec_param *param)
+{
+       struct mtk_jpeg_dev *jpeg = ctx->jpeg;
+       struct mtk_jpeg_q_data *q_data;
+
+       q_data = &ctx->out_q;
+       if (q_data->w != param->pic_w || q_data->h != param->pic_h) {
+               v4l2_dbg(1, debug, &jpeg->v4l2_dev, "Picture size change\n");
+               return true;
+       }
+
+       q_data = &ctx->cap_q;
+       if (q_data->fmt != mtk_jpeg_find_format(ctx, param->dst_fourcc,
+                                               MTK_JPEG_FMT_TYPE_CAPTURE)) {
+               v4l2_dbg(1, debug, &jpeg->v4l2_dev, "format change\n");
+               return true;
+       }
+       return false;

<snip...>

Quoted 19 lines
drivers/media/platform/mtk-jpeg/mtk_jpeg_core.c new file +19 -0
+static void mtk_jpeg_device_run(void *priv)
+{
+       struct mtk_jpeg_ctx *ctx = priv;
+       struct mtk_jpeg_dev *jpeg = ctx->jpeg;
+       struct vb2_buffer *src_buf, *dst_buf;
+       enum vb2_buffer_state buf_state = VB2_BUF_STATE_ERROR;
+       unsigned long flags;
+       struct mtk_jpeg_src_buf *jpeg_src_buf;
+       struct mtk_jpeg_bs bs;
+       struct mtk_jpeg_fb fb;
+       int i;
+
+       src_buf = v4l2_m2m_next_src_buf(ctx->fh.m2m_ctx);
+       dst_buf = v4l2_m2m_next_dst_buf(ctx->fh.m2m_ctx);
+       jpeg_src_buf = mtk_jpeg_vb2_to_srcbuf(src_buf);
+
+       if (jpeg_src_buf->flags & MTK_JPEG_BUF_FLAGS_LAST_FRAME) {
+               for (i = 0; i < dst_buf->num_planes; i++)
+                       vb2_set_plane_payload(dst_buf, i, 0);

drivers/media/platform/mtk-jpeg/mtk_jpeg_core.c line 829

Quoted 10 lines
drivers/media/platform/mtk-jpeg/mtk_jpeg_core.c new file +10 -0
+               buf_state = VB2_BUF_STATE_DONE;
+               goto dec_end;
+       }
+
+       if (mtk_jpeg_check_resolution_change(ctx, &jpeg_src_buf->dec_param)) {
+               mtk_jpeg_queue_src_chg_event(ctx);
+               ctx->state = MTK_JPEG_SOURCE_CHANGE;
+               v4l2_m2m_job_finish(jpeg->m2m_dev, ctx->fh.m2m_ctx);
+               return;
+       }

This only detects source change if multiple OUPUT buffers are queued. It does not catch the source change in the following scenario:

- OUPUT buffers for jpeg1 enqueued
- OUTPUT queue STREAMON
- userspace creates CAPTURE buffers
- CAPTURE buffers enqueued
- CAPTURE queue STREAMON
- decode
- OUTPUT queue STREAMOFF
- userspace recreates OUTPUT buffers for jpeg2
- OUTPUT buffers for jpeg2 enqueued
- OUTPUT queue STREAMON

In the above sequence if jpeg2's decoded size is larger than jpeg1 the function fails to detect that the existing CAPTURE buffers are not big enough to hold the decoded data.

A possible fix is to pass *dst_buf to mtk_jpeg_check_resolution_change(), and check in the function that all the dst_buf planes are large enough to hold the decoded data.

Quoted 21 lines
drivers/media/platform/mtk-jpeg/mtk_jpeg_core.c new file +21 -0
+
+       mtk_jpeg_set_dec_src(ctx, src_buf, &bs);
+       if (mtk_jpeg_set_dec_dst(ctx, &jpeg_src_buf->dec_param, dst_buf, &fb))
+               goto dec_end;
+
+       spin_lock_irqsave(&jpeg->hw_lock, flags);
+       mtk_jpeg_dec_reset(jpeg->dec_reg_base);
+       mtk_jpeg_dec_set_config(jpeg->dec_reg_base,
+                               &jpeg_src_buf->dec_param, &bs, &fb);
+
+       mtk_jpeg_dec_start(jpeg->dec_reg_base);
+       spin_unlock_irqrestore(&jpeg->hw_lock, flags);
+       return;
+
+dec_end:
+       v4l2_m2m_src_buf_remove(ctx->fh.m2m_ctx);
+       v4l2_m2m_dst_buf_remove(ctx->fh.m2m_ctx);
+       v4l2_m2m_buf_done(to_vb2_v4l2_buffer(src_buf), buf_state);
+       v4l2_m2m_buf_done(to_vb2_v4l2_buffer(dst_buf), buf_state);
+       v4l2_m2m_job_finish(jpeg->m2m_dev, ctx->fh.m2m_ctx);
+}

<snip...>

author
#6 lore raw

PATCH v8 3/4 arm: dts: mt2701: Add node for Mediatek JPEG Decoder

In reply to Rick Chang

---
This patch depends on:
CCF "Add clock support for Mediatek MT2701"[1]
iommu and smi "Add the dtsi node of iommu and smi for mt2701"[2]

[1] http://lists.infradead.org/pipermail/linux-mediatek/2016-October/007271.html
[2] https://patchwork.kernel.org/patch/9164013/

---
 arch/arm/boot/dts/mt2701.dtsi | 14 ++++++++++++++
 1 file changed, 14 insertions(+)
arch/arm/boot/dts/mt2701.dtsi +14 -0
index 8f13c70..4dd5048 100644
@@ -298,6 +298,20 @@
 		power-domains = <&scpsys MT2701_POWER_DOMAIN_ISP>;
 	};
 
+	jpegdec: jpegdec at 15004000 {
+		compatible = "mediatek,mt2701-jpgdec";
+		reg = <0 0x15004000 0 0x1000>;
+		interrupts = <GIC_SPI 143 IRQ_TYPE_LEVEL_LOW>;
+		clocks =  <&imgsys CLK_IMG_JPGDEC_SMI>,
+			  <&imgsys CLK_IMG_JPGDEC>;
+		clock-names = "jpgdec-smi",
+			      "jpgdec";
+		power-domains = <&scpsys MT2701_POWER_DOMAIN_ISP>;
+		mediatek,larb = <&larb2>;
+		iommus = <&iommu MT2701_M4U_PORT_JPGDEC_WDMA>,
+			 <&iommu MT2701_M4U_PORT_JPGDEC_BSDMA>;
+	};
+
 	vdecsys: syscon at 16000000 {
 		compatible = "mediatek,mt2701-vdecsys", "syscon";
 		reg = <0 0x16000000 0 0x1000>;
Signature · 1 line
1.9.1
author
#7 lore raw

PATCH v8 4/4 vcodec: mediatek: Add Maintainers entry for Mediatek JPEG driver

In reply to Rick Chang
---
 MAINTAINERS | 7 +++++++
 1 file changed, 7 insertions(+)
MAINTAINERS +7 -0
index 93e9f42..6f68fb6 100644
@@ -7818,6 +7818,13 @@ L:	netdev at vger.kernel.org
 S:	Maintained
 F:	drivers/net/ethernet/mediatek/
 
+MEDIATEK JPEG DRIVER
+M:	Rick Chang <[email protected]>
+M:	Bin Liu <[email protected]>
+S:	Supported
+F:	drivers/media/platform/mtk-jpeg/
+F:	Documentation/devicetree/bindings/media/mediatek-jpeg-decoder.txt
+
 MEDIATEK MEDIA DRIVER
 M:	Tiffany Lin <[email protected]>
 M:	Andrew-CT Chen <[email protected]>
Signature · 1 line
1.9.1