Skip to contentSkip to conversation

Add V4L2 driver for i.MX8 JPEG Encoder/Decoder

PATCH Superseded Mirela Rabulea (OSS) 3 participants 15 messages Dec 15, 2020 – Jan 4, 2021

Subsystems (4)

v6 of 9 Superseded Latest is v9 →

lore
Share & tools
lore
#0 lore raw

v6 cover Add V4L2 driver for i.MX8 JPEG Encoder/Decoder

From: Mirela Rabulea <[email protected]>

This patch set adds the V4L2 driver for i.MX8QXP/QM JPEG encoder/decoder and it's dependencies.
The driver was tested on i.MX8QXP, using a unit test application and the v4l2-compliance tool, including the streaming tests for decoder & encoder.

The output of latest v4l2-compliance on i.MX8QXP, decoder & encoder:

root@imx8qxpmek:/unit_tests/JPEG# ./v4l2-compliance-master -d /dev/video0 -s
v4l2-compliance 1.21.0-4686, 64 bits, 64-bit time_t
v4l2-compliance SHA: e0e4114f9714 2020-12-10 13:23:07

Compliance test for mxc-jpeg decode device /dev/video0:

Driver Info:

	Driver name      : mxc-jpeg decode
	Card type        : mxc-jpeg decoder
	Bus info         : platform:58400000.jpegdec
	Driver version   : 5.10.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
Detected JPEG Decoder

Required ioctls:
test VIDIOC_QUERYCAP: OK

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

test invalid ioctls: 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 (Not Supported)
test Scaling: OK

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

Buffer ioctls:
test VIDIOC_REQBUFS/CREATE_BUFS/QUERYBUF: OK test VIDIOC_EXPBUF: OK
test Requests: OK (Not Supported)

Test input 0:

Streaming ioctls:
test read/write: OK (Not Supported)
test blocking wait: OK
Video Capture Multiplanar: Captured 58 buffers test MMAP (no poll): OK
Video Capture Multiplanar: Captured 58 buffers test MMAP (select): OK
Video Capture Multiplanar: Captured 58 buffers test MMAP (epoll): OK
test USERPTR (no poll): OK (Not Supported) test USERPTR (select): OK (Not Supported) test DMABUF: Cannot test, specify --expbuf-device

Total for mxc-jpeg decode device /dev/video0: 52, Succeeded: 52, Failed: 0, Warnings: 0

root@imx8qxpmek:/unit_tests/JPEG# ./v4l2-compliance-master -d /dev/video1 -s
v4l2-compliance 1.21.0-4686, 64 bits, 64-bit time_t
v4l2-compliance SHA: e0e4114f9714 2020-12-10 13:23:07

Compliance test for mxc-jpeg decode device /dev/video1:

Driver Info:

	Driver name      : mxc-jpeg decode
	Card type        : mxc-jpeg decoder
	Bus info         : platform:58450000.jpegenc
	Driver version   : 5.10.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
Detected JPEG Encoder

Required ioctls:
test VIDIOC_QUERYCAP: OK

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

test invalid ioctls: 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 (Not Supported)
test Scaling: OK (Not Supported)

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

Buffer ioctls:
test VIDIOC_REQBUFS/CREATE_BUFS/QUERYBUF: OK test VIDIOC_EXPBUF: OK
test Requests: OK (Not Supported)

Test input 0:

Streaming ioctls:
test read/write: OK (Not Supported)
test blocking wait: OK
Video Capture Multiplanar: Captured 58 buffers test MMAP (no poll): OK
Video Capture Multiplanar: Captured 58 buffers test MMAP (select): OK
Video Capture Multiplanar: Captured 58 buffers test MMAP (epoll): OK
test USERPTR (no poll): OK (Not Supported) test USERPTR (select): OK (Not Supported) test DMABUF: Cannot test, specify --expbuf-device

Total for mxc-jpeg decode device /dev/video1: 52, Succeeded: 52, Failed: 0, Warnings: 0

Mirela Rabulea (9):
media: v4l: Add packed YUV444 24bpp pixel format
media: dt-bindings: Add bindings for i.MX8QXP/QM JPEG driver
media: imx-jpeg: Add V4L2 driver for i.MX8 JPEG Encoder/Decoder
arm64: dts: imx8qxp: Add jpeg encoder/decoder nodes Add maintainer for IMX jpeg v4l2 driver
media: Add parsing for APP14 data segment in jpeg helpers
media: Quit parsing stream if doesn't start with SOI
media: Avoid parsing quantization and huffman tables
media: imx-jpeg: Use v4l2 jpeg helpers in mxc-jpeg

 .../bindings/media/nxp,imx8-jpeg.yaml         |   84 +
 .../media/v4l/pixfmt-packed-yuv.rst           |   10 +
 MAINTAINERS                                   |    8 +
 arch/arm64/boot/dts/freescale/imx8qxp.dtsi    |   35 +
 drivers/media/platform/Kconfig                |    2 +
 drivers/media/platform/Makefile               |    1 +
 drivers/media/platform/imx-jpeg/Kconfig       |   11 +
 drivers/media/platform/imx-jpeg/Makefile      |    3 +
 drivers/media/platform/imx-jpeg/mxc-jpeg-hw.c |  168 ++
 drivers/media/platform/imx-jpeg/mxc-jpeg-hw.h |  140 ++
 drivers/media/platform/imx-jpeg/mxc-jpeg.c    | 2193 +++++++++++++++++
 drivers/media/platform/imx-jpeg/mxc-jpeg.h    |  180 ++
 drivers/media/v4l2-core/v4l2-ioctl.c          |    1 +
 drivers/media/v4l2-core/v4l2-jpeg.c           |   58 +-
 include/media/v4l2-jpeg.h                     |   18 +
 include/uapi/linux/videodev2.h                |    1 +
 16 files changed, 2906 insertions(+), 7 deletions(-)
 create mode 100644 Documentation/devicetree/bindings/media/nxp,imx8-jpeg.yaml
 create mode 100644 drivers/media/platform/imx-jpeg/Kconfig
 create mode 100644 drivers/media/platform/imx-jpeg/Makefile
 create mode 100644 drivers/media/platform/imx-jpeg/mxc-jpeg-hw.c
 create mode 100644 drivers/media/platform/imx-jpeg/mxc-jpeg-hw.h
 create mode 100644 drivers/media/platform/imx-jpeg/mxc-jpeg.c
 create mode 100644 drivers/media/platform/imx-jpeg/mxc-jpeg.h
Signature · 1 line
2.17.1
#1 lore raw

PATCH v6 1/9 media: v4l: Add packed YUV444 24bpp pixel format

From: Mirela Rabulea <[email protected]>

The added format is V4L2_PIX_FMT_YUV24, this is a packed YUV 4:4:4 format, with 8 bits for each component, 24 bits per sample.

This format is used by the i.MX 8QuadMax and i.MX 8DualXPlus/8QuadXPlus JPEG encoder/decoder.

---
Changes in v6:
Updates due to Laurent Pinchart's commit:
2f2a387e9fa4 media: doc: pixfmt-packed-yuv: Express 4:4:4 formats in a more compact way

Added V4L2_PIX_FMT_YUV24 in the "Packed YUV Image Formats (8bpc)" table

 .../userspace-api/media/v4l/pixfmt-packed-yuv.rst      | 10 ++++++++++
 drivers/media/v4l2-core/v4l2-ioctl.c                   |  1 +
 include/uapi/linux/videodev2.h                         |  1 +
 3 files changed, 12 insertions(+)
Documentation/userspace-api/media/v4l/pixfmt-packed-yuv.rst +10 -0
index eb551b57557e..4515f713decf 100644
@@ -220,6 +220,16 @@ the second byte and Y'\ :sub:`7-0` in the third byte.
       - Y'\ :sub:`7-0`
       - X\ :sub:`7-0`
 
+    * .. _V4L2-PIX-FMT-YUV24:
+
+      - ``V4L2_PIX_FMT_YUV24``
+      - 'YUV3'
+
+      - Y'\ :sub:`7-0`
+      - Cb\ :sub:`7-0`
+      - Cr\ :sub:`7-0`
+      - -\
+
 .. note::
 
     - The alpha component is expected to contain a meaningful value that can be
drivers/media/v4l2-core/v4l2-ioctl.c +1 -0
index 3198abdd538c..611768409d0b 100644
@@ -1304,6 +1304,7 @@ static void v4l_fill_fmtdesc(struct v4l2_fmtdesc *fmt)
 	case V4L2_PIX_FMT_YUV444:	descr = "16-bit A/XYUV 4-4-4-4"; break;
 	case V4L2_PIX_FMT_YUV555:	descr = "16-bit A/XYUV 1-5-5-5"; break;
 	case V4L2_PIX_FMT_YUV565:	descr = "16-bit YUV 5-6-5"; break;
+	case V4L2_PIX_FMT_YUV24:	descr = "24-bit YUV 4:4:4 8-8-8"; break;
 	case V4L2_PIX_FMT_YUV32:	descr = "32-bit A/XYUV 8-8-8-8"; break;
 	case V4L2_PIX_FMT_AYUV32:	descr = "32-bit AYUV 8-8-8-8"; break;
 	case V4L2_PIX_FMT_XYUV32:	descr = "32-bit XYUV 8-8-8-8"; break;
include/uapi/linux/videodev2.h +1 -0
index 79dbde3bcf8d..9e4359be04eb 100644
@@ -586,6 +586,7 @@ struct v4l2_pix_format {
 #define V4L2_PIX_FMT_YUV444  v4l2_fourcc('Y', '4', '4', '4') /* 16  xxxxyyyy uuuuvvvv */
 #define V4L2_PIX_FMT_YUV555  v4l2_fourcc('Y', 'U', 'V', 'O') /* 16  YUV-5-5-5     */
 #define V4L2_PIX_FMT_YUV565  v4l2_fourcc('Y', 'U', 'V', 'P') /* 16  YUV-5-6-5     */
+#define V4L2_PIX_FMT_YUV24   v4l2_fourcc('Y', 'U', 'V', '3') /* 24  YUV-8-8-8     */
 #define V4L2_PIX_FMT_YUV32   v4l2_fourcc('Y', 'U', 'V', '4') /* 32  YUV-8-8-8-8   */
 #define V4L2_PIX_FMT_AYUV32  v4l2_fourcc('A', 'Y', 'U', 'V') /* 32  AYUV-8-8-8-8  */
 #define V4L2_PIX_FMT_XYUV32  v4l2_fourcc('X', 'Y', 'U', 'V') /* 32  XYUV-8-8-8-8  */
Signature · 1 line
2.17.1
#2 lore raw

PATCH v6 2/9 media: dt-bindings: Add bindings for i.MX8QXP/QM JPEG driver

In reply to Mirela Rabulea (OSS)

From: Mirela Rabulea <[email protected]>

Add bindings documentation for i.MX8QXP/QM JPEG decoder & encoder driver.

---
Changes in v6:

 .../bindings/media/nxp,imx8-jpeg.yaml         | 84 +++++++++++++++++++
 1 file changed, 84 insertions(+)
 create mode 100644 Documentation/devicetree/bindings/media/nxp,imx8-jpeg.yaml
Documentation/devicetree/bindings/media/nxp,imx8-jpeg.yaml new file +84 -0
new file mode 100644
index 000000000000..5d13cbb5251b
@@ -0,0 +1,84 @@
+# SPDX-License-Identifier: (GPL-2.0 OR BSD-2-Clause)
+%YAML 1.2
+---
+$id: http://devicetree.org/schemas/media/nxp,imx8-jpeg.yaml#
+$schema: http://devicetree.org/meta-schemas/core.yaml#
+
+title: i.MX8QXP/QM JPEG decoder/encoder Device Tree Bindings
+
+maintainers:
+  - Mirela Rabulea <[email protected]>
+
+description: |-
+  The JPEG decoder/encoder present in iMX8QXP and iMX8QM SoCs is an
+  ISO/IEC 10918-1 JPEG standard compliant decoder/encoder, for Baseline
+  and Extended Sequential DCT modes.
+
+properties:
+  compatible:
+    items:
+      - enum:
+            # JPEG decoder
+          - nxp,imx8qxp-jpgdec
+            # JPEG encoder
+          - nxp,imx8qxp-jpgenc
+
+  reg:
+    maxItems: 1
+
+  interrupts:
+    description: |
+      There are 4 slots available in the IP, which the driver may use
+      If a certain slot is used, it should have an associated interrupt
+      The interrupt with index i is assumed to be for slot i
+    minItems: 1               # At least one slot is needed by the driver
+    maxItems: 4               # The IP has 4 slots available for use
+
+  power-domains:
+    description:
+      List of phandle and PM domain specifier as documented in
+      Documentation/devicetree/bindings/power/power_domain.txt
+    minItems: 2               # Wrapper and 1 slot
+    maxItems: 5               # Wrapper and 4 slots
+
+required:
+  - compatible
+  - reg
+  - interrupts
+  - power-domains
+
+additionalProperties: false
+
+examples:
+  - |
+    #include <dt-bindings/interrupt-controller/arm-gic.h>
+    #include <dt-bindings/firmware/imx/rsrc.h>
+
+    jpegdec: jpegdec@58400000 {
+        compatible = "nxp,imx8qxp-jpgdec";
+        reg = <0x58400000 0x00050000 >;
+        interrupts = <GIC_SPI 309 IRQ_TYPE_LEVEL_HIGH>,
+                     <GIC_SPI 310 IRQ_TYPE_LEVEL_HIGH>,
+                     <GIC_SPI 311 IRQ_TYPE_LEVEL_HIGH>,
+                     <GIC_SPI 312 IRQ_TYPE_LEVEL_HIGH>;
+        power-domains = <&pd IMX_SC_R_MJPEG_DEC_MP>,
+                        <&pd IMX_SC_R_MJPEG_DEC_S0>,
+                        <&pd IMX_SC_R_MJPEG_DEC_S1>,
+                        <&pd IMX_SC_R_MJPEG_DEC_S2>,
+                        <&pd IMX_SC_R_MJPEG_DEC_S3>;
+    };
+
+    jpegenc: jpegenc@58450000 {
+        compatible = "nxp,imx8qxp-jpgenc";
+        reg = <0x58450000 0x00050000 >;
+        interrupts = <GIC_SPI 305 IRQ_TYPE_LEVEL_HIGH>,
+                     <GIC_SPI 306 IRQ_TYPE_LEVEL_HIGH>,
+                     <GIC_SPI 307 IRQ_TYPE_LEVEL_HIGH>,
+                     <GIC_SPI 308 IRQ_TYPE_LEVEL_HIGH>;
+        power-domains = <&pd IMX_SC_R_MJPEG_ENC_MP>,
+                        <&pd IMX_SC_R_MJPEG_ENC_S0>,
+                        <&pd IMX_SC_R_MJPEG_ENC_S1>,
+                        <&pd IMX_SC_R_MJPEG_ENC_S2>,
+                        <&pd IMX_SC_R_MJPEG_ENC_S3>;
+    };
+...
Signature · 1 line
2.17.1
#3 lore raw

PATCH v6 3/9 media: imx-jpeg: Add V4L2 driver for i.MX8 JPEG Encoder/Decoder

In reply to Mirela Rabulea (OSS)

From: Mirela Rabulea <[email protected]>

V4L2 driver for the JPEG encoder/decoder from i.MX8QXP/i.MX8QM application processors.
The multi-planar buffers API is used.

Baseline and extended sequential jpeg decoding is supported. Progressive jpeg decoding is not supported by the IP. Supports encode and decode of various formats:

     YUV444, YUV422, YUV420, RGB, ARGB, Gray

YUV420 is the only multi-planar format supported. Minimum resolution is 64 x 64, maximum 8192 x 8192.
The alignment requirements for the resolution depend on the format, multiple of 16 resolutions should work for all formats.

v4l2-compliance tests are passing, including the
streaming tests, "v4l2-compliance -s"

---
 drivers/media/platform/Kconfig                |    2 +
 drivers/media/platform/Makefile               |    1 +
 drivers/media/platform/imx-jpeg/Kconfig       |   10 +
 drivers/media/platform/imx-jpeg/Makefile      |    3 +
 drivers/media/platform/imx-jpeg/mxc-jpeg-hw.c |  168 ++
 drivers/media/platform/imx-jpeg/mxc-jpeg-hw.h |  140 +
 drivers/media/platform/imx-jpeg/mxc-jpeg.c    | 2324 +++++++++++++++++
 drivers/media/platform/imx-jpeg/mxc-jpeg.h    |  184 ++
 8 files changed, 2832 insertions(+)
 create mode 100644 drivers/media/platform/imx-jpeg/Kconfig
 create mode 100644 drivers/media/platform/imx-jpeg/Makefile
 create mode 100644 drivers/media/platform/imx-jpeg/mxc-jpeg-hw.c
 create mode 100644 drivers/media/platform/imx-jpeg/mxc-jpeg-hw.h
 create mode 100644 drivers/media/platform/imx-jpeg/mxc-jpeg.c
 create mode 100644 drivers/media/platform/imx-jpeg/mxc-jpeg.h
drivers/media/platform/Kconfig +2 -0
index 35a18d388f3f..60e5faf6b6a6 100644
@@ -224,6 +224,8 @@ config VIDEO_IMX_PXP
 	  The i.MX Pixel Pipeline is a memory-to-memory engine for scaling,
 	  color space conversion, and rotation.
 
+source "drivers/media/platform/imx-jpeg/Kconfig"
+
 config VIDEO_MEDIATEK_JPEG
 	tristate "Mediatek JPEG Codec driver"
 	depends on MTK_IOMMU_V1 || MTK_IOMMU || COMPILE_TEST
drivers/media/platform/Makefile +1 -0
index 1d63aa956bcd..42188ea28a3f 100644
@@ -20,6 +20,7 @@ obj-$(CONFIG_VIDEO_MX2_EMMAPRP)		+= mx2_emmaprp.o
 obj-$(CONFIG_VIDEO_CODA)		+= coda/
 
 obj-$(CONFIG_VIDEO_IMX_PXP)		+= imx-pxp.o
+obj-$(CONFIG_VIDEO_IMX8_JPEG)		+= imx-jpeg/
 
 obj-$(CONFIG_VIDEO_MEM2MEM_DEINTERLACE)	+= m2m-deinterlace.o
 
drivers/media/platform/imx-jpeg/Kconfig new file +10 -0
new file mode 100644
index 000000000000..7cc89e5eff90
@@ -0,0 +1,10 @@
+# SPDX-License-Identifier: GPL-2.0
+config VIDEO_IMX8_JPEG
+	tristate "IMX8 JPEG Encoder/Decoder"
+	depends on VIDEO_DEV && VIDEO_V4L2
+	select VIDEOBUF2_DMA_CONTIG
+	select V4L2_MEM2MEM_DEV
+	default m
+	help
+	  This is a video4linux2 driver for the i.MX8 QXP/QM integrated
+	  JPEG encoder/decoder.
drivers/media/platform/imx-jpeg/Makefile new file +3 -0
new file mode 100644
index 000000000000..bf19c82e61b4
@@ -0,0 +1,3 @@
+# SPDX-License-Identifier: GPL-2.0
+mxc-jpeg-encdec-objs := mxc-jpeg-hw.o mxc-jpeg.o
+obj-$(CONFIG_VIDEO_IMX8_JPEG) += mxc-jpeg-encdec.o
drivers/media/platform/imx-jpeg/mxc-jpeg-hw.c new file +168 -0

168 lines not on this page · raw message

drivers/media/platform/imx-jpeg/mxc-jpeg-hw.h new file +140 -0

140 lines not on this page · raw message

drivers/media/platform/imx-jpeg/mxc-jpeg.c new file +2324 -0

2,324 lines not on this page · raw message

drivers/media/platform/imx-jpeg/mxc-jpeg.h new file +184 -0

184 lines not on this page · raw message

Signature · 1 line
2.17.1
#7 lore raw

PATCH v6 4/9 arm64: dts: imx8qxp: Add jpeg encoder/decoder nodes

In reply to Mirela Rabulea (OSS)

From: Mirela Rabulea <[email protected]>

Add jpeg decoder/encoder nodes, for now on imx8qxp only. The same should work on imx8qm, but it was not tested.

---
Changes in v6:
Pure memory-to-memory are typically not enabled per-board, but just per-platform Thanks Ezequiel for feedback.

 arch/arm64/boot/dts/freescale/imx8qxp.dtsi | 35 ++++++++++++++++++++++
 1 file changed, 35 insertions(+)
arch/arm64/boot/dts/freescale/imx8qxp.dtsi +35 -0
index e46faac1fe71..ee822560af54 100644
@@ -629,4 +629,39 @@
 			};
 		};
 	};
+
+	img_subsys: bus@58000000 {
+		compatible = "simple-bus";
+		#address-cells = <1>;
+		#size-cells = <1>;
+		ranges = <0x58000000 0x0 0x58000000 0x1000000>;
+
+		jpegdec: jpegdec@58400000 {
+			compatible = "nxp,imx8qxp-jpgdec";
+			reg = <0x58400000 0x00050000 >;
+			interrupts = <GIC_SPI 309 IRQ_TYPE_LEVEL_HIGH>,
+				     <GIC_SPI 310 IRQ_TYPE_LEVEL_HIGH>,
+				     <GIC_SPI 311 IRQ_TYPE_LEVEL_HIGH>,
+				     <GIC_SPI 312 IRQ_TYPE_LEVEL_HIGH>;
+			power-domains = <&pd IMX_SC_R_MJPEG_DEC_MP>,
+					<&pd IMX_SC_R_MJPEG_DEC_S0>,
+					<&pd IMX_SC_R_MJPEG_DEC_S1>,
+					<&pd IMX_SC_R_MJPEG_DEC_S2>,
+					<&pd IMX_SC_R_MJPEG_DEC_S3>;
+		};
+
+		jpegenc: jpegenc@58450000 {
+			compatible = "nxp,imx8qxp-jpgenc";
+			reg = <0x58450000 0x00050000 >;
+			interrupts = <GIC_SPI 305 IRQ_TYPE_LEVEL_HIGH>,
+				     <GIC_SPI 306 IRQ_TYPE_LEVEL_HIGH>,
+				     <GIC_SPI 307 IRQ_TYPE_LEVEL_HIGH>,
+				     <GIC_SPI 308 IRQ_TYPE_LEVEL_HIGH>;
+			power-domains = <&pd IMX_SC_R_MJPEG_ENC_MP>,
+					<&pd IMX_SC_R_MJPEG_ENC_S0>,
+					<&pd IMX_SC_R_MJPEG_ENC_S1>,
+					<&pd IMX_SC_R_MJPEG_ENC_S2>,
+					<&pd IMX_SC_R_MJPEG_ENC_S3>;
+		};
+	};
 };
Signature · 1 line
2.17.1
#11 lore raw

PATCH v6 7/9 media: Quit parsing stream if doesn't start with SOI

In reply to Mirela Rabulea (OSS)

From: Mirela Rabulea <[email protected]>

In the case we get an invalid stream, such as from v4l2-compliance streaming test, jpeg_next_marker will end up parsing the entire stream. The standard describes the high level syntax of a jpeg as starting with SOI, ending with EOI, so return error if the very first 2 bytes are not SOI.

---
Changes in v6:

 drivers/media/v4l2-core/v4l2-jpeg.c | 7 ++-----
 1 file changed, 2 insertions(+), 5 deletions(-)
drivers/media/v4l2-core/v4l2-jpeg.c +2 -5
index d1483e7a775c..dc9def4c2648 100644
@@ -503,11 +503,8 @@ int v4l2_jpeg_parse_header(void *buf, size_t len, struct v4l2_jpeg_header *out)
 	out->num_dht = 0;
 	out->num_dqt = 0;
 
-	/* the first marker must be SOI */
-	marker = jpeg_next_marker(&stream);
-	if (marker < 0)
-		return marker;
-	if (marker != SOI)
+	/* the first bytes must be SOI, B.2.1 High-level syntax */
+	if (jpeg_get_word_be(&stream) != SOI)
 		return -EINVAL;
 
 	/* init value to signal if this marker is not present */
Signature · 1 line
2.17.1
#9 lore raw

PATCH v6 6/9 media: Add parsing for APP14 data segment in jpeg helpers

In reply to Mirela Rabulea (OSS)

From: Mirela Rabulea <[email protected]>

According to Rec. ITU-T T.872 (06/2012) 6.5.3
APP14 segment is for color encoding, it contains a transform flag, which may have values of 0, 1 and 2 and are interpreted as follows:
0 - CMYK for images that are encoded with four components
- RGB for images that are encoded with three components
1 - An image encoded with three components using YCbCr colour encoding. 2 - An image encoded with four components using YCCK colour encoding.

This is used in imx-jpeg decoder, to distinguish between YUV444 and RGB24.

---
Changes in v6:
Switch variable to lowercase Lp->lp
Check for "Adobe\0" in Ap1..6
Make the transform flag an enum
Removed a change in comment section, a leftover from a previous version Thanks Philipp for feedback.

 drivers/media/v4l2-core/v4l2-jpeg.c | 43 +++++++++++++++++++++++++++--
 include/media/v4l2-jpeg.h           | 18 ++++++++++++
 2 files changed, 59 insertions(+), 2 deletions(-)
drivers/media/v4l2-core/v4l2-jpeg.c +41 -2
index 8947fd95c6f1..d1483e7a775c 100644
@@ -45,6 +45,7 @@ MODULE_LICENSE("GPL");
 #define DHP	0xffde	/* hierarchical progression */
 #define EXP	0xffdf	/* expand reference */
 #define APP0	0xffe0	/* application data */
+#define APP14	0xffee	/* application data for colour encoding */
 #define APP15	0xffef
 #define JPG0	0xfff0	/* extensions */
 #define JPG13	0xfffd
@@ -444,8 +445,41 @@ static int jpeg_skip_segment(struct jpeg_stream *stream)
 	return jpeg_skip(stream, len - 2);
 }
 
+/* Rec. ITU-T T.872 (06/2012) 6.5.3 */
+static int jpeg_parse_app14_data(struct jpeg_stream *stream)
+{
+	int ret;
+	int lp;
+	int skip;
+	int tf;
+
+	lp = jpeg_get_word_be(stream);
+	if (lp < 0)
+		return lp;
+
+	/* Check for "Adobe\0" in Ap1..6 */
+	if (strncmp(stream->curr, "Adobe\0", 6))
+		return -EINVAL;
+
+	/* get to Ap12 */
+	ret = jpeg_skip(stream, 11);
+	if (ret < 0)
+		return -EINVAL;
+
+	tf = jpeg_get_byte(stream);
+	if (tf < 0)
+		return tf;
+
+	skip = lp - 2 - 11;
+	ret = jpeg_skip(stream, skip);
+	if (ret < 0)
+		return -EINVAL;
+	else
+		return tf;
+}
+
 /**
- * jpeg_parse_header - locate marker segments and optionally parse headers
+ * v4l2_jpeg_parse_header - locate marker segments and optionally parse headers
  * @buf: address of the JPEG buffer, should start with a SOI marker
  * @len: length of the JPEG buffer
  * @out: returns marker segment positions and optionally parsed headers
@@ -476,6 +510,9 @@ int v4l2_jpeg_parse_header(void *buf, size_t len, struct v4l2_jpeg_header *out)
 	if (marker != SOI)
 		return -EINVAL;
 
+	/* init value to signal if this marker is not present */
+	out->app14_tf = -EINVAL;
+
 	/* loop through marker segments */
 	while ((marker = jpeg_next_marker(&stream)) >= 0) {
 		switch (marker) {
@@ -519,7 +556,9 @@ int v4l2_jpeg_parse_header(void *buf, size_t len, struct v4l2_jpeg_header *out)
 			ret = jpeg_parse_restart_interval(&stream,
 							&out->restart_interval);
 			break;
-
+		case APP14:
+			out->app14_tf = jpeg_parse_app14_data(&stream);
+			break;
 		case SOS:
 			ret = jpeg_reference_segment(&stream, &out->sos);
 			if (ret < 0)
include/media/v4l2-jpeg.h +18 -0
index ddba2a56c321..c1904aa3f7cc 100644
@@ -87,6 +87,22 @@ struct v4l2_jpeg_scan_header {
 	/* Ss, Se, Ah, and Al are not used by any driver */
 };
 
+/**
+ * enum v4l2_jpeg_app14_tf - APP14 transform flag
+ * According to Rec. ITU-T T.872 (06/2012) 6.5.3
+ * APP14 segment is for color encoding, it contains a transform flag,
+ * which may have values of 0, 1 and 2 and are interpreted as follows:
+ * @V4L2_JPEG_APP14_TF_CMYK_RGB: CMYK for images encoded with four components
+ *                               RGB for images encoded with three components
+ * @V4L2_JPEG_APP14_TF_YCBCR: an image encoded with three components using YCbCr
+ * @V4L2_JPEG_APP14_TF_YCCK: an image encoded with four components using YCCK
+ */
+enum v4l2_jpeg_app14_tf {
+	V4L2_JPEG_APP14_TF_CMYK_RGB	= 0,
+	V4L2_JPEG_APP14_TF_YCBCR	= 1,
+	V4L2_JPEG_APP14_TF_YCCK		= 2,
+};
+
 /**
  * struct v4l2_jpeg_header - parsed JPEG header
  * @sof: pointer to frame header and size
@@ -100,6 +116,7 @@ struct v4l2_jpeg_scan_header {
  *                  order, optional
  * @restart_interval: number of MCU per restart interval, Ri
  * @ecs_offset: buffer offset in bytes to the entropy coded segment
+ * @app14_tf: transform flag from app14 data
  *
  * When this structure is passed to v4l2_jpeg_parse_header, the optional scan,
  * quantization_tables, and huffman_tables pointers must be initialized to NULL
@@ -119,6 +136,7 @@ struct v4l2_jpeg_header {
 	struct v4l2_jpeg_reference *huffman_tables;
 	u16 restart_interval;
 	size_t ecs_offset;
+	enum v4l2_jpeg_app14_tf app14_tf;
 };
 
 int v4l2_jpeg_parse_header(void *buf, size_t len, struct v4l2_jpeg_header *out);
Signature · 1 line
2.17.1
#12 lore raw

PATCH v6 8/9 media: Avoid parsing quantization and huffman tables

In reply to Mirela Rabulea (OSS)

From: Mirela Rabulea <[email protected]>

These are optional in struct v4l2_jpeg_header, so skip DHT/DQT segment parsing if huffman_tables/quantization_tables were not requested by user, to save time.
However, do count them (num_dht/num_dqt).

---
Changes in v6:
Call jpeg_skip_segment() instead of jpeg_parse_quantization_table()/jpeg_parse_huffman_tables(), when quantization/huffman tables are not requested by user.
Remove the NULL pointer check in the lower-level function.
Thanks Philipp & Hans for feedback

 drivers/media/v4l2-core/v4l2-jpeg.c | 8 ++++++++
 1 file changed, 8 insertions(+)
drivers/media/v4l2-core/v4l2-jpeg.c +8 -0
index dc9def4c2648..f3d03d39defb 100644
@@ -537,6 +537,10 @@ int v4l2_jpeg_parse_header(void *buf, size_t len, struct v4l2_jpeg_header *out)
 					&out->dht[out->num_dht++ % 4]);
 			if (ret < 0)
 				return ret;
+			if (!out->huffman_tables) {
+				ret = jpeg_skip_segment(&stream);
+				break;
+			}
 			ret = jpeg_parse_huffman_tables(&stream,
 							out->huffman_tables);
 			break;
@@ -545,6 +549,10 @@ int v4l2_jpeg_parse_header(void *buf, size_t len, struct v4l2_jpeg_header *out)
 					&out->dqt[out->num_dqt++ % 4]);
 			if (ret < 0)
 				return ret;
+			if (!out->quantization_tables) {
+				ret = jpeg_skip_segment(&stream);
+				break;
+			}
 			ret = jpeg_parse_quantization_tables(&stream,
 					out->frame.precision,
 					out->quantization_tables);
Signature · 1 line
2.17.1
#14 lore raw

PATCH v6 9/9 media: imx-jpeg: Use v4l2 jpeg helpers in mxc-jpeg

In reply to Mirela Rabulea (OSS)

From: Mirela Rabulea <[email protected]>

Use v4l2_jpeg_parse_header in mxc_jpeg_parse, remove the old parsing way, which was duplicated in other jpeg drivers.

---
Changes in v6:
Use the app14 transform flag enum

 drivers/media/platform/imx-jpeg/Kconfig    |   1 +
 drivers/media/platform/imx-jpeg/mxc-jpeg.c | 267 ++++++---------------
 drivers/media/platform/imx-jpeg/mxc-jpeg.h |  26 +-
 3 files changed, 80 insertions(+), 214 deletions(-)
drivers/media/platform/imx-jpeg/Kconfig +1 -0
index 7cc89e5eff90..d875f7c88cda 100644
@@ -4,6 +4,7 @@ config VIDEO_IMX8_JPEG
 	depends on VIDEO_DEV && VIDEO_V4L2
 	select VIDEOBUF2_DMA_CONTIG
 	select V4L2_MEM2MEM_DEV
+	select V4L2_JPEG_HELPER
 	default m
 	help
 	  This is a video4linux2 driver for the i.MX8 QXP/QM integrated
drivers/media/platform/imx-jpeg/mxc-jpeg.c +68 -199

390 lines not on this page · raw message

drivers/media/platform/imx-jpeg/mxc-jpeg.h +11 -15
index ef1670dafeb4..313b09f831a4 100644
@@ -42,6 +42,8 @@ enum mxc_jpeg_mode {
  * struct jpeg_fmt - driver's internal color format data
  * @name:	format description
  * @fourcc:	fourcc code, 0 if not applicable
+ * @subsampling subsampling of jpeg components
+ * @nc:		number of color components
  * @depth:	number of bits per pixel
  * @colplanes:	number of color planes (1 for packed formats)
  * @h_align:	horizontal alignment order (align to 2^h_align)
@@ -49,13 +51,15 @@ enum mxc_jpeg_mode {
  * @flags:	flags describing format applicability
  */
 struct mxc_jpeg_fmt {
-	char	*name;
-	u32	fourcc;
-	int	depth;
-	int	colplanes;
-	int	h_align;
-	int	v_align;
-	u32	flags;
+	char					*name;
+	u32					fourcc;
+	enum v4l2_jpeg_chroma_subsampling	subsampling;
+	int					nc;
+	int					depth;
+	int					colplanes;
+	int					h_align;
+	int					v_align;
+	u32					flags;
 };
 
 struct mxc_jpeg_desc {
@@ -117,14 +121,6 @@ struct mxc_jpeg_dev {
 	struct device_link		**pd_link;
 };
 
-/* JPEG marker identifiers */
-#define SOF0				0xC0
-#define SOF1				0xC1
-#define SOF2				0xC2
-#define SOS				0xDA
-#define DHT				0xC4
-#define APP14				0xEE
-
 /**
  * struct mxc_jpeg_sof_comp - JPEG Start Of Frame component fields
  * @id:				component id
Signature · 1 line
2.17.1
#8 lore raw

PATCH v6 5/9 Add maintainer for IMX jpeg v4l2 driver

In reply to Mirela Rabulea (OSS)

From: Mirela Rabulea <[email protected]>

The driver is located in drivers/media/platform/imx-jpeg, and it applies to the JPEG decoder from i.MX QXP and QM.

---
 MAINTAINERS | 8 ++++++++
 1 file changed, 8 insertions(+)
MAINTAINERS +8 -0
index c9e221929961..09050a727d57 100644
@@ -12818,6 +12818,14 @@ L:	[email protected] (moderated for non-subscribers)
 S:	Supported
 F:	drivers/nfc/nxp-nci
 
+NXP i.MX 8QXP/8QM JPEG V4L2 DRIVER
+M:	Mirela Rabulea <[email protected]>
+R:	NXP Linux Team <[email protected]>
+L:	[email protected]
+S:	Maintained
+F:	Documentation/devicetree/bindings/media/imx8-jpeg.yaml
+F:	drivers/media/platform/imx-jpeg
+
 OBJAGG
 M:	Jiri Pirko <[email protected]>
 L:	[email protected]
Signature · 1 line
2.17.1
#4 lore raw

Re: [PATCH v6 3/9] media: imx-jpeg: Add V4L2 driver for i.MX8 JPEG Encoder/Decoder

In reply to Mirela Rabulea (OSS)
Thank you for the patch! Perhaps something to improve:

Hi "Mirela,

Thank you for the patch! Perhaps something to improve:

[auto build test WARNING on linuxtv-media/master]
[also build test WARNING on linus/master next-20201215] [cannot apply to shawnguo/for-next robh/for-next v5.10]
[If your patch is applied to the wrong git tree, kindly drop us a note. And when submitting patch, we suggest to use '--base' as documented in
https://git-scm.com/docs/git-format-patch]

url:    https://github.com/0day-ci/linux/commits/Mirela-Rabulea-OSS/Add-V4L2-driver-for-i-MX8-JPEG-Encoder-Decoder/20201215-192653
base:   git://linuxtv.org/media_tree.git master
config: x86_64-randconfig-m001-20201215 (attached as .config)
compiler: gcc-9 (Debian 9.3.0-15) 9.3.0

If you fix the issue, kindly add following tag as appropriate

smatch warnings:
drivers/media/platform/imx-jpeg/mxc-jpeg.c:1408 mxc_jpeg_parse() warn: inconsistent indenting

vim +1408 drivers/media/platform/imx-jpeg/mxc-jpeg.c

1321
1322 static int mxc_jpeg_parse(struct mxc_jpeg_ctx *ctx,
1323 u8 *src_addr, u32 size, bool *dht_needed)
1324 {
1325 struct device *dev = ctx->mxc_jpeg->dev;
1326 struct mxc_jpeg_q_data *q_data_out, *q_data_cap;
1327 enum v4l2_buf_type cap_type = V4L2_BUF_TYPE_VIDEO_CAPTURE_MPLANE;
1328 struct mxc_jpeg_stream stream;
1329 bool notfound = true;
1330 bool app14 = false;
1331 bool src_chg = false;
1332 u8 app14_transform = 0;
1333 struct mxc_jpeg_sof sof, *psof = NULL;
1334 struct mxc_jpeg_sos *psos = NULL;
1335 int byte;
1336 u8 *next = NULL;
1337 enum mxc_jpeg_image_format img_fmt;
1338 u32 fourcc;
1339
1340 memset(&sof, 0, sizeof(struct mxc_jpeg_sof));
1341 stream.addr = src_addr;
1342 stream.end = size;
1343 stream.loc = 0;
1344 *dht_needed = true;
1345
1346 /* check stream starts with SOI */
1347 byte = get_byte(&stream);
1348 if (byte == -1 || byte != 0xFF)
1349 return -EINVAL;
1350 byte = get_byte(&stream);
1351 if (byte == -1 || byte != 0xD8)
1352 return -EINVAL;
1353
1354 while (notfound) {
1355 byte = get_byte(&stream);
1356 if (byte == -1)
1357 return -EINVAL;
1358 if (byte != 0xff)
1359 continue;
1360 do {
1361 byte = get_byte(&stream);
1362 } while (byte == 0xff);
1363 if (byte == -1)
1364 return false;
1365 if (byte == 0)
1366 continue;
1367 switch (byte) {
1368 case DHT:
1369 /* DHT marker present, no need to inject default one */
1370 *dht_needed = false;
1371 break;
1372 case SOF2: /* Progressive DCF frame definition */
1373 dev_err(dev,
1374 "Progressive JPEG not supported by hardware");
1375 return -EINVAL;
1376 case SOF1: /* Extended sequential DCF frame definition */
1377 case SOF0: /* Baseline sequential DCF frame definition */
1378 if (get_sof(dev, &stream, &sof) == -1)
1379 break;
1380 next = stream.addr + stream.loc;
1381 psof = (struct mxc_jpeg_sof *)next;
1382 break;
1383 case SOS:
1384 next = stream.addr + stream.loc;
1385 psos = (struct mxc_jpeg_sos *)next;
1386 notfound = false;
1387 break;
1388 case APP14:
1389 app14 = true;
1390 /*
1391 * Application Data Syntax is:
1392 * 2 bytes(APPn:0xFF,0xEE), 2 bytes(Lp), Ap1...ApLp-2
1393 * The transform flag is in Ap12
1394 * stream.loc is now on APPn-0xEE byte
1395 */
1396 app14_transform = *(stream.addr + stream.loc + 12 + 1);
1397 break;
1398 default:
1399 notfound = true;
1400 }
1401 }
1402 q_data_out = mxc_jpeg_get_q_data(ctx,
1403 V4L2_BUF_TYPE_VIDEO_OUTPUT_MPLANE);
1404 if (q_data_out->w == 0 && q_data_out->h == 0) {
1405 dev_warn(dev, "Invalid user resolution 0x0");
1406 dev_warn(dev, "Keeping resolution from JPEG: %dx%d",
1407 sof.width, sof.height);

> 1408			 q_data_out->w = sof.width;
  1409			 q_data_out->h = sof.height;
  1410		} else if (sof.width != q_data_out->w || sof.height != q_data_out->h) {
  1411			dev_err(dev,
  1412				"Resolution mismatch: %dx%d (JPEG) versus %dx%d(user)",
  1413				sof.width, sof.height, q_data_out->w, q_data_out->h);
  1414			return -EINVAL;
  1415		}
  1416		if (sof.width % 8 != 0 || sof.height % 8 != 0) {
  1417			dev_err(dev, "JPEG width or height not multiple of 8: %dx%d\n",
  1418				sof.width, sof.height);
  1419			return -EINVAL;
  1420		}
  1421		if (sof.width > MXC_JPEG_MAX_WIDTH ||
  1422		    sof.height > MXC_JPEG_MAX_HEIGHT) {
  1423			dev_err(dev, "JPEG width or height should be <= 8192: %dx%d\n",
  1424				sof.width, sof.height);
  1425			return -EINVAL;
  1426		}
  1427		if (sof.width < MXC_JPEG_MIN_WIDTH ||
  1428		    sof.height < MXC_JPEG_MIN_HEIGHT) {
  1429			dev_err(dev, "JPEG width or height should be > 64: %dx%d\n",
  1430				sof.width, sof.height);
  1431			return -EINVAL;
  1432		}
  1433		if (sof.components_no > MXC_JPEG_MAX_COMPONENTS) {
  1434			dev_err(dev, "JPEG number of components should be <=%d",
  1435				MXC_JPEG_MAX_COMPONENTS);
  1436			return -EINVAL;
  1437		}
  1438		/* check and, if necessary, patch component IDs*/
  1439		if (!mxc_jpeg_valid_comp_id(dev, psof, psos))
  1440			dev_warn(dev, "JPEG component ids should be 0-3 or 1-4");
  1441	
  1442		img_fmt = mxc_jpeg_get_image_format(dev, &sof);
  1443		if (img_fmt == MXC_JPEG_INVALID)
  1444			return -EINVAL;
  1445	
  1446		/*
  1447		 * If the transform flag from APP14 marker is 0, images that are
  1448		 * encoded with 3 components have RGB colorspace, see Recommendation
  1449		 * ITU-T T.872 chapter 6.5.3 APP14 marker segment for colour encoding
  1450		 */
  1451		if (img_fmt == MXC_JPEG_YUV444 && app14 && app14_transform == 0)
  1452			img_fmt = MXC_JPEG_RGB;
  1453	
  1454		if (mxc_jpeg_imgfmt_to_fourcc(img_fmt, &fourcc)) {
  1455			dev_err(dev, "Fourcc not found for %d", img_fmt);
  1456			return -EINVAL;
  1457		}
  1458	
  1459		/*
  1460		 * set-up the capture queue with the pixelformat and resolution
  1461		 * detected from the jpeg output stream
  1462		 */
  1463		q_data_cap = mxc_jpeg_get_q_data(ctx, cap_type);
  1464		if (q_data_cap->w != sof.width || q_data_cap->h != sof.height)
  1465			src_chg = true;
  1466		q_data_cap->w = sof.width;
  1467		q_data_cap->h = sof.height;
  1468		q_data_cap->fmt = mxc_jpeg_find_format(ctx, fourcc);
  1469		q_data_cap->w_adjusted = q_data_cap->w;
  1470		q_data_cap->h_adjusted = q_data_cap->h;
  1471		/*
  1472		 * align up the resolution for CAST IP,
  1473		 * but leave the buffer resolution unchanged
  1474		 */
  1475		v4l_bound_align_image(&q_data_cap->w_adjusted,
  1476				      q_data_cap->w_adjusted,  /* adjust up */
  1477				      MXC_JPEG_MAX_WIDTH,
  1478				      q_data_cap->fmt->h_align,
  1479				      &q_data_cap->h_adjusted,
  1480				      q_data_cap->h_adjusted, /* adjust up */
  1481				      MXC_JPEG_MAX_HEIGHT,
  1482				      q_data_cap->fmt->v_align,
  1483				      0);

1484 dev_dbg(dev, "Detected jpeg res=(%dx%d)->(%dx%d), pixfmt=%c%c%c%c\n",
1485 q_data_cap->w, q_data_cap->h,
1486 q_data_cap->w_adjusted, q_data_cap->h_adjusted,
1487 (fourcc & 0xff),
1488 (fourcc >> 8) & 0xff,
1489 (fourcc >> 16) & 0xff,
1490 (fourcc >> 24) & 0xff);
1491
1492 /* setup bytesperline/sizeimage for capture queue */
1493 mxc_jpeg_bytesperline(q_data_cap, sof.precision);
1494 mxc_jpeg_sizeimage(q_data_cap);
1495
1496 /*
1497 * if the CAPTURE format was updated with new values, regardless of
1498 * whether they match the values set by the client or not, signal
1499 * a source change event
1500 */
1501 if (src_chg)
1502 notify_src_chg(ctx);
1503
1504 return 0;
1505 }
1506

---
0-DAY CI Kernel Test Service, Intel Corporation
https://lists.01.org/hyperkitty/list/kbuild-all(a)lists.01.org

#5 lore raw

Re: [PATCH v6 3/9] media: imx-jpeg: Add V4L2 driver for i.MX8 JPEG Encoder/Decoder

In reply to Mirela Rabulea (OSS)
Thank you for the patch! Perhaps something to improve:

Hi "Mirela,

Thank you for the patch! Perhaps something to improve:

[auto build test WARNING on linuxtv-media/master]
[also build test WARNING on linus/master next-20201218] [cannot apply to shawnguo/for-next robh/for-next v5.10]
[If your patch is applied to the wrong git tree, kindly drop us a note. And when submitting patch, we suggest to use '--base' as documented in
https://git-scm.com/docs/git-format-patch]

url:    https://github.com/0day-ci/linux/commits/Mirela-Rabulea-OSS/Add-V4L2-driver-for-i-MX8-JPEG-Encoder-Decoder/20201215-192653
base:   git://linuxtv.org/media_tree.git master
config: powerpc-randconfig-r025-20201217 (attached as .config)
compiler: clang version 12.0.0 (https://github.com/llvm/llvm-project cee1e7d14f4628d6174b33640d502bff3b54ae45)

reproduce (this is a W=1 build):
wget https://raw.githubusercontent.com/intel/lkp-tests/master/sbin/make.cross -O ~/bin/make.cross chmod +x ~/bin/make.cross
# install powerpc cross compiling tool for clang build
# apt-get install binutils-powerpc-linux-gnu
# https://github.com/0day-ci/linux/commit/a1f8ecc90da72e5845877eab95b332aee5410db8
git remote add linux-review https://github.com/0day-ci/linux
git fetch --no-tags linux-review Mirela-Rabulea-OSS/Add-V4L2-driver-for-i-MX8-JPEG-Encoder-Decoder/20201215-192653 git checkout a1f8ecc90da72e5845877eab95b332aee5410db8
# save the attached .config to linux build tree
COMPILER_INSTALL_PATH=$HOME/0day COMPILER=clang make.cross ARCH=powerpc

If you fix the issue, kindly add following tag as appropriate

All warnings (new ones prefixed by >>):

>> drivers/media/platform/imx-jpeg/mxc-jpeg.c:926:45: warning: format specifies type 'unsigned long long' but the argument has type 'dma_addr_t' (aka 'unsigned int') [-Wformat]
           dev_dbg(jpeg->dev, "cfg_desc - 0x%llx:\n", cfg_desc_handle);
                                            ~~~~      ^~~~~~~~~~~~~~~
                                            %x
   include/linux/dev_printk.h:131:47: note: expanded from macro 'dev_dbg'
                   dev_printk(KERN_DEBUG, dev, dev_fmt(fmt), ##__VA_ARGS__); \
                                                       ~~~     ^~~~~~~~~~~
   drivers/media/platform/imx-jpeg/mxc-jpeg.c:928:45: warning: format specifies type 'unsigned long long' but the argument has type 'dma_addr_t' (aka 'unsigned int') [-Wformat]
           dev_dbg(jpeg->dev, "enc desc - 0x%llx:\n", desc_handle);
                                            ~~~~      ^~~~~~~~~~~
                                            %x
   include/linux/dev_printk.h:131:47: note: expanded from macro 'dev_dbg'
                   dev_printk(KERN_DEBUG, dev, dev_fmt(fmt), ##__VA_ARGS__); \
                                                       ~~~     ^~~~~~~~~~~

2 warnings generated.

vim +926 drivers/media/platform/imx-jpeg/mxc-jpeg.c

875
876 static void mxc_jpeg_config_enc_desc(struct vb2_buffer *out_buf,

   877					     struct mxc_jpeg_ctx *ctx,
   878					     struct vb2_buffer *src_buf,
   879					     struct vb2_buffer *dst_buf)
   880	{
   881		struct mxc_jpeg_dev *jpeg = ctx->mxc_jpeg;
   882		void __iomem *reg = jpeg->base_reg;
   883		unsigned int slot = ctx->slot;
   884		struct mxc_jpeg_desc *desc = jpeg->slot_data[slot].desc;
   885		struct mxc_jpeg_desc *cfg_desc = jpeg->slot_data[slot].cfg_desc;
   886		dma_addr_t desc_handle = jpeg->slot_data[slot].desc_handle;
   887		dma_addr_t cfg_desc_handle = jpeg->slot_data[slot].cfg_desc_handle;
   888		void *cfg_stream_vaddr = jpeg->slot_data[slot].cfg_stream_vaddr;
   889		struct mxc_jpeg_q_data *q_data;
   890		enum mxc_jpeg_image_format img_fmt;
   891		int w, h;
   892	
   893		q_data = mxc_jpeg_get_q_data(ctx, src_buf->vb2_queue->type);
   894	
   895		jpeg->slot_data[slot].cfg_stream_size =
   896				mxc_jpeg_setup_cfg_stream(cfg_stream_vaddr,
   897							  q_data->fmt->fourcc,
   898							  q_data->w_adjusted,
   899							  q_data->h_adjusted);
   900	
   901		/* chain the config descriptor with the encoding descriptor */
   902		cfg_desc->next_descpt_ptr = desc_handle | MXC_NXT_DESCPT_EN;
   903	
   904		cfg_desc->buf_base0 = jpeg->slot_data[slot].cfg_stream_handle;
   905		cfg_desc->buf_base1 = 0;
   906		cfg_desc->line_pitch = 0;
   907		cfg_desc->stm_bufbase = 0; /* no output expected */
   908		cfg_desc->stm_bufsize = 0x0;
   909		cfg_desc->imgsize = 0;
   910		cfg_desc->stm_ctrl = STM_CTRL_CONFIG_MOD(1);
   911	
   912		desc->next_descpt_ptr = 0; /* end of chain */
   913	
   914		/* use adjusted resolution for CAST IP job */
   915		w = q_data->w_adjusted;
   916		h = q_data->h_adjusted;
   917		mxc_jpeg_set_res(desc, w, h);
   918		mxc_jpeg_set_line_pitch(desc, w * (q_data->fmt->depth / 8));
   919		mxc_jpeg_set_bufsize(desc, desc->line_pitch * h);
   920		img_fmt = mxc_jpeg_fourcc_to_imgfmt(q_data->fmt->fourcc);
   921		if (img_fmt == MXC_JPEG_INVALID)
   922			dev_err(jpeg->dev, "No valid image format detected\n");
   923		desc->stm_ctrl = STM_CTRL_CONFIG_MOD(0) |
   924				 STM_CTRL_IMAGE_FORMAT(img_fmt);
   925		mxc_jpeg_addrs(desc, src_buf, dst_buf, 0);
 > 926		dev_dbg(jpeg->dev, "cfg_desc - 0x%llx:\n", cfg_desc_handle);

927 print_descriptor_info(jpeg->dev, cfg_desc);
928 dev_dbg(jpeg->dev, "enc desc - 0x%llx:\n", desc_handle);
929 print_descriptor_info(jpeg->dev, desc);
930 print_wrapper_info(jpeg->dev, reg);
931 print_cast_status(jpeg->dev, reg, MXC_JPEG_ENCODE);
932
933 /* validate the configuration descriptor */
934 mxc_jpeg_set_desc(cfg_desc_handle, reg, slot);
935 }
936

---
0-DAY CI Kernel Test Service, Intel Corporation
https://lists.01.org/hyperkitty/list/kbuild-all(a)lists.01.org

#6 lore raw

Re: [PATCH v6 3/9] media: imx-jpeg: Add V4L2 driver for i.MX8 JPEG Encoder/Decoder

In reply to Mirela Rabulea (OSS)
Thank you for the patch! Perhaps something to improve:

Hi "Mirela,

Thank you for the patch! Perhaps something to improve:

[auto build test WARNING on linuxtv-media/master]
[also build test WARNING on linus/master next-20201218] [cannot apply to shawnguo/for-next robh/for-next v5.10]
[If your patch is applied to the wrong git tree, kindly drop us a note. And when submitting patch, we suggest to use '--base' as documented in
https://git-scm.com/docs/git-format-patch]

url:    https://github.com/0day-ci/linux/commits/Mirela-Rabulea-OSS/Add-V4L2-driver-for-i-MX8-JPEG-Encoder-Decoder/20201215-192653
base:   git://linuxtv.org/media_tree.git master
config: powerpc-randconfig-r025-20201217 (attached as .config)
compiler: clang version 12.0.0 (https://github.com/llvm/llvm-project cee1e7d14f4628d6174b33640d502bff3b54ae45)

reproduce (this is a W=1 build):
wget https://raw.githubusercontent.com/intel/lkp-tests/master/sbin/make.cross -O ~/bin/make.cross chmod +x ~/bin/make.cross
# install powerpc cross compiling tool for clang build
# apt-get install binutils-powerpc-linux-gnu
# https://github.com/0day-ci/linux/commit/a1f8ecc90da72e5845877eab95b332aee5410db8
git remote add linux-review https://github.com/0day-ci/linux
git fetch --no-tags linux-review Mirela-Rabulea-OSS/Add-V4L2-driver-for-i-MX8-JPEG-Encoder-Decoder/20201215-192653 git checkout a1f8ecc90da72e5845877eab95b332aee5410db8
# save the attached .config to linux build tree
COMPILER_INSTALL_PATH=$HOME/0day COMPILER=clang make.cross ARCH=powerpc

If you fix the issue, kindly add following tag as appropriate

All warnings (new ones prefixed by >>):

>> drivers/media/platform/imx-jpeg/mxc-jpeg.c:926:45: warning: format specifies type 'unsigned long long' but the argument has type 'dma_addr_t' (aka 'unsigned int') [-Wformat]
           dev_dbg(jpeg->dev, "cfg_desc - 0x%llx:\n", cfg_desc_handle);
                                            ~~~~      ^~~~~~~~~~~~~~~
                                            %x
   include/linux/dev_printk.h:131:47: note: expanded from macro 'dev_dbg'
                   dev_printk(KERN_DEBUG, dev, dev_fmt(fmt), ##__VA_ARGS__); \
                                                       ~~~     ^~~~~~~~~~~
   drivers/media/platform/imx-jpeg/mxc-jpeg.c:928:45: warning: format specifies type 'unsigned long long' but the argument has type 'dma_addr_t' (aka 'unsigned int') [-Wformat]
           dev_dbg(jpeg->dev, "enc desc - 0x%llx:\n", desc_handle);
                                            ~~~~      ^~~~~~~~~~~
                                            %x
   include/linux/dev_printk.h:131:47: note: expanded from macro 'dev_dbg'
                   dev_printk(KERN_DEBUG, dev, dev_fmt(fmt), ##__VA_ARGS__); \
                                                       ~~~     ^~~~~~~~~~~

2 warnings generated.

vim +926 drivers/media/platform/imx-jpeg/mxc-jpeg.c

875
876 static void mxc_jpeg_config_enc_desc(struct vb2_buffer *out_buf,

   877					     struct mxc_jpeg_ctx *ctx,
   878					     struct vb2_buffer *src_buf,
   879					     struct vb2_buffer *dst_buf)
   880	{
   881		struct mxc_jpeg_dev *jpeg = ctx->mxc_jpeg;
   882		void __iomem *reg = jpeg->base_reg;
   883		unsigned int slot = ctx->slot;
   884		struct mxc_jpeg_desc *desc = jpeg->slot_data[slot].desc;
   885		struct mxc_jpeg_desc *cfg_desc = jpeg->slot_data[slot].cfg_desc;
   886		dma_addr_t desc_handle = jpeg->slot_data[slot].desc_handle;
   887		dma_addr_t cfg_desc_handle = jpeg->slot_data[slot].cfg_desc_handle;
   888		void *cfg_stream_vaddr = jpeg->slot_data[slot].cfg_stream_vaddr;
   889		struct mxc_jpeg_q_data *q_data;
   890		enum mxc_jpeg_image_format img_fmt;
   891		int w, h;
   892	
   893		q_data = mxc_jpeg_get_q_data(ctx, src_buf->vb2_queue->type);
   894	
   895		jpeg->slot_data[slot].cfg_stream_size =
   896				mxc_jpeg_setup_cfg_stream(cfg_stream_vaddr,
   897							  q_data->fmt->fourcc,
   898							  q_data->w_adjusted,
   899							  q_data->h_adjusted);
   900	
   901		/* chain the config descriptor with the encoding descriptor */
   902		cfg_desc->next_descpt_ptr = desc_handle | MXC_NXT_DESCPT_EN;
   903	
   904		cfg_desc->buf_base0 = jpeg->slot_data[slot].cfg_stream_handle;
   905		cfg_desc->buf_base1 = 0;
   906		cfg_desc->line_pitch = 0;
   907		cfg_desc->stm_bufbase = 0; /* no output expected */
   908		cfg_desc->stm_bufsize = 0x0;
   909		cfg_desc->imgsize = 0;
   910		cfg_desc->stm_ctrl = STM_CTRL_CONFIG_MOD(1);
   911	
   912		desc->next_descpt_ptr = 0; /* end of chain */
   913	
   914		/* use adjusted resolution for CAST IP job */
   915		w = q_data->w_adjusted;
   916		h = q_data->h_adjusted;
   917		mxc_jpeg_set_res(desc, w, h);
   918		mxc_jpeg_set_line_pitch(desc, w * (q_data->fmt->depth / 8));
   919		mxc_jpeg_set_bufsize(desc, desc->line_pitch * h);
   920		img_fmt = mxc_jpeg_fourcc_to_imgfmt(q_data->fmt->fourcc);
   921		if (img_fmt == MXC_JPEG_INVALID)
   922			dev_err(jpeg->dev, "No valid image format detected\n");
   923		desc->stm_ctrl = STM_CTRL_CONFIG_MOD(0) |
   924				 STM_CTRL_IMAGE_FORMAT(img_fmt);
   925		mxc_jpeg_addrs(desc, src_buf, dst_buf, 0);
 > 926		dev_dbg(jpeg->dev, "cfg_desc - 0x%llx:\n", cfg_desc_handle);

927 print_descriptor_info(jpeg->dev, cfg_desc);
928 dev_dbg(jpeg->dev, "enc desc - 0x%llx:\n", desc_handle);
929 print_descriptor_info(jpeg->dev, desc);
930 print_wrapper_info(jpeg->dev, reg);
931 print_cast_status(jpeg->dev, reg, MXC_JPEG_ENCODE);
932
933 /* validate the configuration descriptor */
934 mxc_jpeg_set_desc(cfg_desc_handle, reg, slot);
935 }
936

---
0-DAY CI Kernel Test Service, Intel Corporation
https://lists.01.org/hyperkitty/list/kbuild-all(a)lists.01.org

Reviewed-by on v6 6/9
#10 lore raw

Re: [PATCH v6 6/9] media: Add parsing for APP14 data segment in jpeg helpers

In reply to Mirela Rabulea (OSS)

Hi Mirela,

thank you for the update. Just two issues below:

Quoted 43 lines · Mirela Rabulea (OSS)

From: Mirela Rabulea <[email protected]>

According to Rec. ITU-T T.872 (06/2012) 6.5.3
APP14 segment is for color encoding, it contains a transform flag, which may have values of 0, 1 and 2 and are interpreted as follows:
0 - CMYK for images that are encoded with four components
- RGB for images that are encoded with three components
1 - An image encoded with three components using YCbCr colour encoding. 2 - An image encoded with four components using YCCK colour encoding.

This is used in imx-jpeg decoder, to distinguish between YUV444 and RGB24.

---
Changes in v6:
Switch variable to lowercase Lp->lp
Check for "Adobe\0" in Ap1..6
Make the transform flag an enum
Removed a change in comment section, a leftover from a previous version Thanks Philipp for feedback.

 drivers/media/v4l2-core/v4l2-jpeg.c | 43 +++++++++++++++++++++++++++--
 include/media/v4l2-jpeg.h           | 18 ++++++++++++
 2 files changed, 59 insertions(+), 2 deletions(-)
drivers/media/v4l2-core/v4l2-jpeg.c +2 -0
index 8947fd95c6f1..d1483e7a775c 100644
@@ -45,6 +45,7 @@ MODULE_LICENSE("GPL");
 #define DHP	0xffde	/* hierarchical progression */
 #define EXP	0xffdf	/* expand reference */
 #define APP0	0xffe0	/* application data */
+#define APP14	0xffee	/* application data for colour encoding */
 #define APP15	0xffef
 #define JPG0	0xfff0	/* extensions */
 #define JPG13	0xfffd
@@ -444,8 +445,41 @@ static int jpeg_skip_segment(struct jpeg_stream *stream)
 	return jpeg_skip(stream, len - 2);
 }
 
+/* Rec. ITU-T T.872 (06/2012) 6.5.3 */

drivers/media/v4l2-core/v4l2-jpeg.c static int jpeg_skip_segment(struct jpeg_stream *stream) · line 458

Quoted 10 lines
drivers/media/v4l2-core/v4l2-jpeg.c +10 -0
+static int jpeg_parse_app14_data(struct jpeg_stream *stream)
+{
+	int ret;
+	int lp;
+	int skip;
+	int tf;
+
+	lp = jpeg_get_word_be(stream);
+	if (lp < 0)
+		return lp;

Here we should check that there are still 6 bytes available to compare:

	if (stream->curr + 6 > stream->end)
		return -EINVAL;
Quoted 28 lines
drivers/media/v4l2-core/v4l2-jpeg.c +22 -1
+	/* Check for "Adobe\0" in Ap1..6 */
+	if (strncmp(stream->curr, "Adobe\0", 6))
+		return -EINVAL;
+
+	/* get to Ap12 */
+	ret = jpeg_skip(stream, 11);
+	if (ret < 0)
+		return -EINVAL;
+
+	tf = jpeg_get_byte(stream);
+	if (tf < 0)
+		return tf;
+
+	skip = lp - 2 - 11;
+	ret = jpeg_skip(stream, skip);
+	if (ret < 0)
+		return -EINVAL;
+	else
+		return tf;
+}
+
 /**
- * jpeg_parse_header - locate marker segments and optionally parse headers
+ * v4l2_jpeg_parse_header - locate marker segments and optionally parse headers
  * @buf: address of the JPEG buffer, should start with a SOI marker
  * @len: length of the JPEG buffer
  * @out: returns marker segment positions and optionally parsed headers

drivers/media/v4l2-core/v4l2-jpeg.c int v4l2_jpeg_parse_header(void *buf, size_t len, struct v4l2_jpeg_header *out) · line 515

Quoted 6 lines
drivers/media/v4l2-core/v4l2-jpeg.c +3 -0
@@ -476,6 +510,9 @@ int v4l2_jpeg_parse_header(void *buf, size_t len, struct v4l2_jpeg_header *out)
 	if (marker != SOI)
 		return -EINVAL;
 
+	/* init value to signal if this marker is not present */
+	out->app14_tf = -EINVAL;
+

Here we set app14_tf to a value that is not part of the enum. You could define a value V4L2_JPEG_APP14_TF_UNKNOWN for the uninitialized / error state.

drivers/media/v4l2-core/v4l2-jpeg.c int v4l2_jpeg_parse_header(void *buf, size_t len, struct v4l2_jpeg_header *out) · line 560

Quoted 10 lines
drivers/media/v4l2-core/v4l2-jpeg.c +2 -1
 	/* loop through marker segments */
 	while ((marker = jpeg_next_marker(&stream)) >= 0) {
 		switch (marker) {
@@ -519,7 +556,9 @@ int v4l2_jpeg_parse_header(void *buf, size_t len, struct v4l2_jpeg_header *out)
 			ret = jpeg_parse_restart_interval(&stream,
 							&out->restart_interval);
 			break;
-
+		case APP14:
+			out->app14_tf = jpeg_parse_app14_data(&stream);

Same as above in case of -EINVAL return. Apart from this,

regards
Philipp

Reviewed-by on v6 8/9
#13 lore raw

Re: [PATCH v6 8/9] media: Avoid parsing quantization and huffman tables

In reply to Mirela Rabulea (OSS)
Quoted 34 lines · Mirela Rabulea (OSS)

From: Mirela Rabulea <[email protected]>

These are optional in struct v4l2_jpeg_header, so skip DHT/DQT segment parsing if huffman_tables/quantization_tables were not requested by user, to save time.
However, do count them (num_dht/num_dqt).

---
Changes in v6:
Call jpeg_skip_segment() instead of jpeg_parse_quantization_table()/jpeg_parse_huffman_tables(), when quantization/huffman tables are not requested by user.
Remove the NULL pointer check in the lower-level function.
Thanks Philipp & Hans for feedback

 drivers/media/v4l2-core/v4l2-jpeg.c | 8 ++++++++
 1 file changed, 8 insertions(+)
drivers/media/v4l2-core/v4l2-jpeg.c +4 -0
index dc9def4c2648..f3d03d39defb 100644
@@ -537,6 +537,10 @@ int v4l2_jpeg_parse_header(void *buf, size_t len, struct v4l2_jpeg_header *out)
 					&out->dht[out->num_dht++ % 4]);
 			if (ret < 0)
 				return ret;
+			if (!out->huffman_tables) {
+				ret = jpeg_skip_segment(&stream);
+				break;
+			}
 			ret = jpeg_parse_huffman_tables(&stream,
 							out->huffman_tables);
 			break;

drivers/media/v4l2-core/v4l2-jpeg.c int v4l2_jpeg_parse_header(void *buf, size_t len, struct v4l2_jpeg_header *out) · line 558

Quoted 10 lines
drivers/media/v4l2-core/v4l2-jpeg.c +4 -0
@@ -545,6 +549,10 @@ int v4l2_jpeg_parse_header(void *buf, size_t len, struct v4l2_jpeg_header *out)
 					&out->dqt[out->num_dqt++ % 4]);
 			if (ret < 0)
 				return ret;
+			if (!out->quantization_tables) {
+				ret = jpeg_skip_segment(&stream);
+				break;
+			}
 			ret = jpeg_parse_quantization_tables(&stream,
 					out->frame.precision,
 					out->quantization_tables);

regards
Philipp