forked from ~ljy/RK356X_SDK_RELEASE

hc
2024-12-19 9370bb92b2d16684ee45cf24e879c93c509162da
kernel/drivers/media/platform/s5p-mfc/s5p_mfc_enc.c
....@@ -1,3 +1,4 @@
1
+// SPDX-License-Identifier: GPL-2.0-or-later
12 /*
23 * linux/drivers/media/platform/s5p-mfc/s5p_mfc_enc.c
34 *
....@@ -6,11 +7,6 @@
67 *
78 * Jeongtae Park <jtp.park@samsung.com>
89 * Kamil Debski <k.debski@samsung.com>
9
- *
10
- * This program is free software; you can redistribute it and/or modify
11
- * it under the terms of the GNU General Public License as published by
12
- * the Free Software Foundation; either version 2 of the License, or
13
- * (at your option) any later version.
1410 */
1511
1612 #include <linux/clk.h>
....@@ -36,7 +32,6 @@
3632
3733 static struct s5p_mfc_fmt formats[] = {
3834 {
39
- .name = "4:2:0 2 Planes 16x16 Tiles",
4035 .fourcc = V4L2_PIX_FMT_NV12MT_16X16,
4136 .codec_mode = S5P_MFC_CODEC_NONE,
4237 .type = MFC_FMT_RAW,
....@@ -44,7 +39,6 @@
4439 .versions = MFC_V6_BIT | MFC_V7_BIT,
4540 },
4641 {
47
- .name = "4:2:0 2 Planes 64x32 Tiles",
4842 .fourcc = V4L2_PIX_FMT_NV12MT,
4943 .codec_mode = S5P_MFC_CODEC_NONE,
5044 .type = MFC_FMT_RAW,
....@@ -52,7 +46,6 @@
5246 .versions = MFC_V5_BIT,
5347 },
5448 {
55
- .name = "4:2:0 2 Planes Y/CbCr",
5649 .fourcc = V4L2_PIX_FMT_NV12M,
5750 .codec_mode = S5P_MFC_CODEC_NONE,
5851 .type = MFC_FMT_RAW,
....@@ -60,7 +53,6 @@
6053 .versions = MFC_V5PLUS_BITS,
6154 },
6255 {
63
- .name = "4:2:0 2 Planes Y/CrCb",
6456 .fourcc = V4L2_PIX_FMT_NV21M,
6557 .codec_mode = S5P_MFC_CODEC_NONE,
6658 .type = MFC_FMT_RAW,
....@@ -68,7 +60,6 @@
6860 .versions = MFC_V6PLUS_BITS,
6961 },
7062 {
71
- .name = "H264 Encoded Stream",
7263 .fourcc = V4L2_PIX_FMT_H264,
7364 .codec_mode = S5P_MFC_CODEC_H264_ENC,
7465 .type = MFC_FMT_ENC,
....@@ -76,7 +67,6 @@
7667 .versions = MFC_V5PLUS_BITS,
7768 },
7869 {
79
- .name = "MPEG4 Encoded Stream",
8070 .fourcc = V4L2_PIX_FMT_MPEG4,
8171 .codec_mode = S5P_MFC_CODEC_MPEG4_ENC,
8272 .type = MFC_FMT_ENC,
....@@ -84,7 +74,6 @@
8474 .versions = MFC_V5PLUS_BITS,
8575 },
8676 {
87
- .name = "H263 Encoded Stream",
8877 .fourcc = V4L2_PIX_FMT_H263,
8978 .codec_mode = S5P_MFC_CODEC_H263_ENC,
9079 .type = MFC_FMT_ENC,
....@@ -92,7 +81,6 @@
9281 .versions = MFC_V5PLUS_BITS,
9382 },
9483 {
95
- .name = "VP8 Encoded Stream",
9684 .fourcc = V4L2_PIX_FMT_VP8,
9785 .codec_mode = S5P_MFC_CODEC_VP8_ENC,
9886 .type = MFC_FMT_ENC,
....@@ -134,7 +122,7 @@
134122 .id = V4L2_CID_MPEG_VIDEO_MULTI_SLICE_MODE,
135123 .type = V4L2_CTRL_TYPE_MENU,
136124 .minimum = V4L2_MPEG_VIDEO_MULTI_SLICE_MODE_SINGLE,
137
- .maximum = V4L2_MPEG_VIDEO_MULTI_SICE_MODE_MAX_BYTES,
125
+ .maximum = V4L2_MPEG_VIDEO_MULTI_SLICE_MODE_MAX_BYTES,
138126 .default_value = V4L2_MPEG_VIDEO_MULTI_SLICE_MODE_SINGLE,
139127 .menu_skip_mask = 0,
140128 },
....@@ -272,6 +260,12 @@
272260 .maximum = V4L2_MPEG_MFC51_VIDEO_FRAME_SKIP_MODE_BUF_LIMIT,
273261 .menu_skip_mask = 0,
274262 .default_value = V4L2_MPEG_MFC51_VIDEO_FRAME_SKIP_MODE_DISABLED,
263
+ },
264
+ {
265
+ .id = V4L2_CID_MPEG_VIDEO_FRAME_SKIP_MODE,
266
+ .type = V4L2_CTRL_TYPE_MENU,
267
+ .maximum = V4L2_MPEG_VIDEO_FRAME_SKIP_MODE_BUF_LIMIT,
268
+ .default_value = V4L2_MPEG_VIDEO_FRAME_SKIP_MODE_DISABLED,
275269 },
276270 {
277271 .id = V4L2_CID_MPEG_MFC51_VIDEO_RC_FIXED_TARGET_BIT,
....@@ -1224,6 +1218,7 @@
12241218 unsigned long mb_y_addr, mb_c_addr;
12251219 int slice_type;
12261220 unsigned int strm_size;
1221
+ bool src_ready;
12271222
12281223 slice_type = s5p_mfc_hw_call(dev->mfc_ops, get_enc_slice_type, dev);
12291224 strm_size = s5p_mfc_hw_call(dev->mfc_ops, get_enc_strm_size, dev);
....@@ -1263,7 +1258,8 @@
12631258 }
12641259 }
12651260 }
1266
- if ((ctx->src_queue_cnt > 0) && (ctx->state == MFCINST_RUNNING)) {
1261
+ if (ctx->src_queue_cnt > 0 && (ctx->state == MFCINST_RUNNING ||
1262
+ ctx->state == MFCINST_FINISHING)) {
12671263 mb_entry = list_entry(ctx->src_queue.next, struct s5p_mfc_buf,
12681264 list);
12691265 if (mb_entry->flags & MFC_BUF_FLAG_USED) {
....@@ -1294,7 +1290,13 @@
12941290 vb2_set_plane_payload(&mb_entry->b->vb2_buf, 0, strm_size);
12951291 vb2_buffer_done(&mb_entry->b->vb2_buf, VB2_BUF_STATE_DONE);
12961292 }
1297
- if ((ctx->src_queue_cnt == 0) || (ctx->dst_queue_cnt == 0))
1293
+
1294
+ src_ready = true;
1295
+ if (ctx->state == MFCINST_RUNNING && ctx->src_queue_cnt == 0)
1296
+ src_ready = false;
1297
+ if (ctx->state == MFCINST_FINISHING && ctx->ref_queue_cnt == 0)
1298
+ src_ready = false;
1299
+ if (!src_ready || ctx->dst_queue_cnt == 0)
12981300 clear_work_bit(ctx);
12991301
13001302 return 0;
....@@ -1313,17 +1315,10 @@
13131315 {
13141316 struct s5p_mfc_dev *dev = video_drvdata(file);
13151317
1316
- strlcpy(cap->driver, S5P_MFC_NAME, sizeof(cap->driver));
1317
- strlcpy(cap->card, dev->vfd_enc->name, sizeof(cap->card));
1318
+ strscpy(cap->driver, S5P_MFC_NAME, sizeof(cap->driver));
1319
+ strscpy(cap->card, dev->vfd_enc->name, sizeof(cap->card));
13181320 snprintf(cap->bus_info, sizeof(cap->bus_info), "platform:%s",
13191321 dev_name(&dev->plat_dev->dev));
1320
- /*
1321
- * This is only a mem-to-mem video device. The capture and output
1322
- * device capability flags are left only for backward compatibility
1323
- * and are scheduled for removal.
1324
- */
1325
- cap->device_caps = V4L2_CAP_VIDEO_M2M_MPLANE | V4L2_CAP_STREAMING;
1326
- cap->capabilities = cap->device_caps | V4L2_CAP_DEVICE_CAPS;
13271322 return 0;
13281323 }
13291324
....@@ -1331,7 +1326,6 @@
13311326 bool out)
13321327 {
13331328 struct s5p_mfc_dev *dev = video_drvdata(file);
1334
- struct s5p_mfc_fmt *fmt;
13351329 int i, j = 0;
13361330
13371331 for (i = 0; i < ARRAY_SIZE(formats); ++i) {
....@@ -1343,10 +1337,7 @@
13431337 continue;
13441338
13451339 if (j == f->index) {
1346
- fmt = &formats[i];
1347
- strlcpy(f->description, fmt->name,
1348
- sizeof(f->description));
1349
- f->pixelformat = fmt->fourcc;
1340
+ f->pixelformat = formats[i].fourcc;
13501341 return 0;
13511342 }
13521343 ++j;
....@@ -1354,14 +1345,14 @@
13541345 return -EINVAL;
13551346 }
13561347
1357
-static int vidioc_enum_fmt_vid_cap_mplane(struct file *file, void *pirv,
1358
- struct v4l2_fmtdesc *f)
1348
+static int vidioc_enum_fmt_vid_cap(struct file *file, void *pirv,
1349
+ struct v4l2_fmtdesc *f)
13591350 {
13601351 return vidioc_enum_fmt(file, f, false);
13611352 }
13621353
1363
-static int vidioc_enum_fmt_vid_out_mplane(struct file *file, void *prov,
1364
- struct v4l2_fmtdesc *f)
1354
+static int vidioc_enum_fmt_vid_out(struct file *file, void *priv,
1355
+ struct v4l2_fmtdesc *f)
13651356 {
13661357 return vidioc_enum_fmt(file, f, true);
13671358 }
....@@ -1621,9 +1612,9 @@
16211612 mfc_err("Call on QBUF after EOS command\n");
16221613 return -EIO;
16231614 }
1624
- return vb2_qbuf(&ctx->vq_src, buf);
1615
+ return vb2_qbuf(&ctx->vq_src, NULL, buf);
16251616 } else if (buf->type == V4L2_BUF_TYPE_VIDEO_CAPTURE_MPLANE) {
1626
- return vb2_qbuf(&ctx->vq_dst, buf);
1617
+ return vb2_qbuf(&ctx->vq_dst, NULL, buf);
16271618 }
16281619 return -EINVAL;
16291620 }
....@@ -1872,6 +1863,7 @@
18721863 p->seq_hdr_mode = ctrl->val;
18731864 break;
18741865 case V4L2_CID_MPEG_MFC51_VIDEO_FRAME_SKIP_MODE:
1866
+ case V4L2_CID_MPEG_VIDEO_FRAME_SKIP_MODE:
18751867 p->frame_skip_mode = ctrl->val;
18761868 break;
18771869 case V4L2_CID_MPEG_MFC51_VIDEO_RC_FIXED_TARGET_BIT:
....@@ -2343,8 +2335,8 @@
23432335
23442336 static const struct v4l2_ioctl_ops s5p_mfc_enc_ioctl_ops = {
23452337 .vidioc_querycap = vidioc_querycap,
2346
- .vidioc_enum_fmt_vid_cap_mplane = vidioc_enum_fmt_vid_cap_mplane,
2347
- .vidioc_enum_fmt_vid_out_mplane = vidioc_enum_fmt_vid_out_mplane,
2338
+ .vidioc_enum_fmt_vid_cap = vidioc_enum_fmt_vid_cap,
2339
+ .vidioc_enum_fmt_vid_out = vidioc_enum_fmt_vid_out,
23482340 .vidioc_g_fmt_vid_cap_mplane = vidioc_g_fmt,
23492341 .vidioc_g_fmt_vid_out_mplane = vidioc_g_fmt,
23502342 .vidioc_try_fmt_vid_cap_mplane = vidioc_try_fmt,