media: hantro: Hook up RK3399 JPEG encoder output
authorChen-Yu Tsai <wenst@chromium.org>
Fri, 19 Nov 2021 07:46:54 +0000 (08:46 +0100)
committerMauro Carvalho Chehab <mchehab+huawei@kernel.org>
Tue, 30 Nov 2021 11:20:04 +0000 (12:20 +0100)
The JPEG encoder found in the Hantro H1 encoder block only produces a
raw entropy-encoded scan. The driver is responsible for building a JPEG
compliant bitstream and placing the entropy-encoded scan in it. Right
now the driver uses a bounce buffer for the hardware to output the raw
scan to.

In commit e765dba11ec2 ("hantro: Move hantro_enc_buf_finish to JPEG
codec_ops.done"), the code that copies the raw scan from the bounce
buffer to the capture buffer was moved, but was only hooked up for the
Hantro H1 (then RK3288) variant. The RK3399 variant was broken,
producing a JPEG bitstream without the scan, and the capture buffer's
.bytesused field unset.

Fix this by duplicating the code that is executed when the JPEG encoder
finishes encoding a frame. As the encoded length is read back from
hardware, and the variants having different register layouts, the
code is duplicated rather than shared.

Fixes: e765dba11ec2 ("hantro: Move hantro_enc_buf_finish to JPEG codec_ops.done")
Signed-off-by: Chen-Yu Tsai <wenst@chromium.org>
Tested-by: Nicolas Dufresne <nicolas.dufresne@collabora.com>
Signed-off-by: Hans Verkuil <hverkuil-cisco@xs4all.nl>
Signed-off-by: Mauro Carvalho Chehab <mchehab+huawei@kernel.org>
drivers/staging/media/hantro/hantro_h1_jpeg_enc.c
drivers/staging/media/hantro/hantro_hw.h
drivers/staging/media/hantro/rockchip_vpu2_hw_jpeg_enc.c
drivers/staging/media/hantro/rockchip_vpu_hw.c

index 20dafd6eb6b9fd2d1d6396a92aa80be376454176..1450013d3685d3560917dfaf7fa042faf155d945 100644 (file)
@@ -139,7 +139,7 @@ int hantro_h1_jpeg_enc_run(struct hantro_ctx *ctx)
        return 0;
 }
 
-void hantro_jpeg_enc_done(struct hantro_ctx *ctx)
+void hantro_h1_jpeg_enc_done(struct hantro_ctx *ctx)
 {
        struct hantro_dev *vpu = ctx->dev;
        u32 bytesused = vepu_read(vpu, H1_REG_STR_BUF_LIMIT) / 8;
index dbe51303724be5a78bd93ef9212decced011c0f0..cff817ca8d22c663a5c9f4aabeec3e4d613f644b 100644 (file)
@@ -328,7 +328,8 @@ int hantro_h1_jpeg_enc_run(struct hantro_ctx *ctx);
 int rockchip_vpu2_jpeg_enc_run(struct hantro_ctx *ctx);
 int hantro_jpeg_enc_init(struct hantro_ctx *ctx);
 void hantro_jpeg_enc_exit(struct hantro_ctx *ctx);
-void hantro_jpeg_enc_done(struct hantro_ctx *ctx);
+void hantro_h1_jpeg_enc_done(struct hantro_ctx *ctx);
+void rockchip_vpu2_jpeg_enc_done(struct hantro_ctx *ctx);
 
 dma_addr_t hantro_h264_get_ref_buf(struct hantro_ctx *ctx,
                                   unsigned int dpb_idx);
index 37f9707c3691a1d473d5cdcd91889c3f2bb8fa4d..4df16f59fb975a898541bec0ce150a51dedcf492 100644 (file)
@@ -170,3 +170,20 @@ int rockchip_vpu2_jpeg_enc_run(struct hantro_ctx *ctx)
 
        return 0;
 }
+
+void rockchip_vpu2_jpeg_enc_done(struct hantro_ctx *ctx)
+{
+       struct hantro_dev *vpu = ctx->dev;
+       u32 bytesused = vepu_read(vpu, VEPU_REG_STR_BUF_LIMIT) / 8;
+       struct vb2_v4l2_buffer *dst_buf = hantro_get_dst_buf(ctx);
+
+       /*
+        * TODO: Rework the JPEG encoder to eliminate the need
+        * for a bounce buffer.
+        */
+       memcpy(vb2_plane_vaddr(&dst_buf->vb2_buf, 0) +
+              ctx->vpu_dst_fmt->header_size,
+              ctx->jpeg_enc.bounce_buffer.cpu, bytesused);
+       vb2_set_plane_payload(&dst_buf->vb2_buf, 0,
+                             ctx->vpu_dst_fmt->header_size + bytesused);
+}
index f372f767d4ffbb4ab3f8088b16d454b789739efc..c203b606e6e755febb6470e9cc14c7faa5fbb23e 100644 (file)
@@ -344,7 +344,7 @@ static const struct hantro_codec_ops rk3066_vpu_codec_ops[] = {
                .run = hantro_h1_jpeg_enc_run,
                .reset = rockchip_vpu1_enc_reset,
                .init = hantro_jpeg_enc_init,
-               .done = hantro_jpeg_enc_done,
+               .done = hantro_h1_jpeg_enc_done,
                .exit = hantro_jpeg_enc_exit,
        },
        [HANTRO_MODE_H264_DEC] = {
@@ -372,7 +372,7 @@ static const struct hantro_codec_ops rk3288_vpu_codec_ops[] = {
                .run = hantro_h1_jpeg_enc_run,
                .reset = rockchip_vpu1_enc_reset,
                .init = hantro_jpeg_enc_init,
-               .done = hantro_jpeg_enc_done,
+               .done = hantro_h1_jpeg_enc_done,
                .exit = hantro_jpeg_enc_exit,
        },
        [HANTRO_MODE_H264_DEC] = {
@@ -400,6 +400,7 @@ static const struct hantro_codec_ops rk3399_vpu_codec_ops[] = {
                .run = rockchip_vpu2_jpeg_enc_run,
                .reset = rockchip_vpu2_enc_reset,
                .init = hantro_jpeg_enc_init,
+               .done = rockchip_vpu2_jpeg_enc_done,
                .exit = hantro_jpeg_enc_exit,
        },
        [HANTRO_MODE_H264_DEC] = {