]> git.proxmox.com Git - mirror_ubuntu-focal-kernel.git/commitdiff
media: coda: add coda_slice_mode() function
authorPhilipp Zabel <p.zabel@pengutronix.de>
Tue, 18 Jun 2019 16:45:34 +0000 (12:45 -0400)
committerMauro Carvalho Chehab <mchehab+samsung@kernel.org>
Mon, 24 Jun 2019 18:47:39 +0000 (14:47 -0400)
Changing slice mode dynamically while encoding will require to calculate
the register value again, so split it out into a separate function.

Signed-off-by: Philipp Zabel <p.zabel@pengutronix.de>
Signed-off-by: Hans Verkuil <hverkuil-cisco@xs4all.nl>
Signed-off-by: Mauro Carvalho Chehab <mchehab+samsung@kernel.org>
drivers/media/platform/coda/coda-bit.c

index de6a4216a1821769adc02c2b745863db922d3044..b59cb16f75a1ef2313459621dd049f714c454b9a 100644 (file)
@@ -675,6 +675,29 @@ static int coda_encode_header(struct coda_ctx *ctx, struct vb2_v4l2_buffer *buf,
        return 0;
 }
 
+static u32 coda_slice_mode(struct coda_ctx *ctx)
+{
+       int size, unit;
+
+       switch (ctx->params.slice_mode) {
+       case V4L2_MPEG_VIDEO_MULTI_SLICE_MODE_SINGLE:
+       default:
+               return 0;
+       case V4L2_MPEG_VIDEO_MULTI_SLICE_MODE_MAX_MB:
+               size = ctx->params.slice_max_mb;
+               unit = 1;
+               break;
+       case V4L2_MPEG_VIDEO_MULTI_SLICE_MODE_MAX_BYTES:
+               size = ctx->params.slice_max_bits;
+               unit = 0;
+               break;
+       }
+
+       return ((size & CODA_SLICING_SIZE_MASK) << CODA_SLICING_SIZE_OFFSET) |
+              ((unit & CODA_SLICING_UNIT_MASK) << CODA_SLICING_UNIT_OFFSET) |
+              ((1 & CODA_SLICING_MODE_MASK) << CODA_SLICING_MODE_OFFSET);
+}
+
 static phys_addr_t coda_iram_alloc(struct coda_iram_info *iram, size_t size)
 {
        phys_addr_t ret;
@@ -1113,27 +1136,7 @@ static int coda_start_encoding(struct coda_ctx *ctx)
         * in JPEG mode
         */
        if (dst_fourcc != V4L2_PIX_FMT_JPEG) {
-               switch (ctx->params.slice_mode) {
-               case V4L2_MPEG_VIDEO_MULTI_SLICE_MODE_SINGLE:
-                       value = 0;
-                       break;
-               case V4L2_MPEG_VIDEO_MULTI_SLICE_MODE_MAX_MB:
-                       value  = (ctx->params.slice_max_mb &
-                                 CODA_SLICING_SIZE_MASK)
-                                << CODA_SLICING_SIZE_OFFSET;
-                       value |= (1 & CODA_SLICING_UNIT_MASK)
-                                << CODA_SLICING_UNIT_OFFSET;
-                       value |=  1 & CODA_SLICING_MODE_MASK;
-                       break;
-               case V4L2_MPEG_VIDEO_MULTI_SLICE_MODE_MAX_BYTES:
-                       value  = (ctx->params.slice_max_bits &
-                                 CODA_SLICING_SIZE_MASK)
-                                << CODA_SLICING_SIZE_OFFSET;
-                       value |= (0 & CODA_SLICING_UNIT_MASK)
-                                << CODA_SLICING_UNIT_OFFSET;
-                       value |=  1 & CODA_SLICING_MODE_MASK;
-                       break;
-               }
+               value = coda_slice_mode(ctx);
                coda_write(dev, value, CODA_CMD_ENC_SEQ_SLICE_MODE);
                value = ctx->params.gop_size;
                coda_write(dev, value, CODA_CMD_ENC_SEQ_GOP_SIZE);