forked from ~ljy/RK356X_SDK_RELEASE

hc
2023-12-11 6778948f9de86c3cfaf36725a7c87dcff9ba247f
kernel/drivers/media/platform/s5p-mfc/s5p_mfc_dec.c
....@@ -1,14 +1,10 @@
1
+// SPDX-License-Identifier: GPL-2.0-or-later
12 /*
23 * linux/drivers/media/platform/s5p-mfc/s5p_mfc_dec.c
34 *
45 * Copyright (C) 2011 Samsung Electronics Co., Ltd.
56 * http://www.samsung.com/
67 * Kamil Debski, <k.debski@samsung.com>
7
- *
8
- * This program is free software; you can redistribute it and/or modify
9
- * it under the terms of the GNU General Public License as published by
10
- * the Free Software Foundation; either version 2 of the License, or
11
- * (at your option) any later version.
128 */
139
1410 #include <linux/clk.h>
....@@ -33,7 +29,6 @@
3329
3430 static struct s5p_mfc_fmt formats[] = {
3531 {
36
- .name = "4:2:0 2 Planes 16x16 Tiles",
3732 .fourcc = V4L2_PIX_FMT_NV12MT_16X16,
3833 .codec_mode = S5P_MFC_CODEC_NONE,
3934 .type = MFC_FMT_RAW,
....@@ -41,7 +36,6 @@
4136 .versions = MFC_V6_BIT | MFC_V7_BIT,
4237 },
4338 {
44
- .name = "4:2:0 2 Planes 64x32 Tiles",
4539 .fourcc = V4L2_PIX_FMT_NV12MT,
4640 .codec_mode = S5P_MFC_CODEC_NONE,
4741 .type = MFC_FMT_RAW,
....@@ -49,7 +43,6 @@
4943 .versions = MFC_V5_BIT,
5044 },
5145 {
52
- .name = "4:2:0 2 Planes Y/CbCr",
5346 .fourcc = V4L2_PIX_FMT_NV12M,
5447 .codec_mode = S5P_MFC_CODEC_NONE,
5548 .type = MFC_FMT_RAW,
....@@ -57,7 +50,6 @@
5750 .versions = MFC_V6PLUS_BITS,
5851 },
5952 {
60
- .name = "4:2:0 2 Planes Y/CrCb",
6153 .fourcc = V4L2_PIX_FMT_NV21M,
6254 .codec_mode = S5P_MFC_CODEC_NONE,
6355 .type = MFC_FMT_RAW,
....@@ -65,7 +57,6 @@
6557 .versions = MFC_V6PLUS_BITS,
6658 },
6759 {
68
- .name = "H264 Encoded Stream",
6960 .fourcc = V4L2_PIX_FMT_H264,
7061 .codec_mode = S5P_MFC_CODEC_H264_DEC,
7162 .type = MFC_FMT_DEC,
....@@ -73,7 +64,6 @@
7364 .versions = MFC_V5PLUS_BITS,
7465 },
7566 {
76
- .name = "H264/MVC Encoded Stream",
7767 .fourcc = V4L2_PIX_FMT_H264_MVC,
7868 .codec_mode = S5P_MFC_CODEC_H264_MVC_DEC,
7969 .type = MFC_FMT_DEC,
....@@ -81,7 +71,6 @@
8171 .versions = MFC_V6PLUS_BITS,
8272 },
8373 {
84
- .name = "H263 Encoded Stream",
8574 .fourcc = V4L2_PIX_FMT_H263,
8675 .codec_mode = S5P_MFC_CODEC_H263_DEC,
8776 .type = MFC_FMT_DEC,
....@@ -89,7 +78,6 @@
8978 .versions = MFC_V5PLUS_BITS,
9079 },
9180 {
92
- .name = "MPEG1 Encoded Stream",
9381 .fourcc = V4L2_PIX_FMT_MPEG1,
9482 .codec_mode = S5P_MFC_CODEC_MPEG2_DEC,
9583 .type = MFC_FMT_DEC,
....@@ -97,7 +85,6 @@
9785 .versions = MFC_V5PLUS_BITS,
9886 },
9987 {
100
- .name = "MPEG2 Encoded Stream",
10188 .fourcc = V4L2_PIX_FMT_MPEG2,
10289 .codec_mode = S5P_MFC_CODEC_MPEG2_DEC,
10390 .type = MFC_FMT_DEC,
....@@ -105,7 +92,6 @@
10592 .versions = MFC_V5PLUS_BITS,
10693 },
10794 {
108
- .name = "MPEG4 Encoded Stream",
10995 .fourcc = V4L2_PIX_FMT_MPEG4,
11096 .codec_mode = S5P_MFC_CODEC_MPEG4_DEC,
11197 .type = MFC_FMT_DEC,
....@@ -113,7 +99,6 @@
11399 .versions = MFC_V5PLUS_BITS,
114100 },
115101 {
116
- .name = "XviD Encoded Stream",
117102 .fourcc = V4L2_PIX_FMT_XVID,
118103 .codec_mode = S5P_MFC_CODEC_MPEG4_DEC,
119104 .type = MFC_FMT_DEC,
....@@ -121,7 +106,6 @@
121106 .versions = MFC_V5PLUS_BITS,
122107 },
123108 {
124
- .name = "VC1 Encoded Stream",
125109 .fourcc = V4L2_PIX_FMT_VC1_ANNEX_G,
126110 .codec_mode = S5P_MFC_CODEC_VC1_DEC,
127111 .type = MFC_FMT_DEC,
....@@ -129,7 +113,6 @@
129113 .versions = MFC_V5PLUS_BITS,
130114 },
131115 {
132
- .name = "VC1 RCV Encoded Stream",
133116 .fourcc = V4L2_PIX_FMT_VC1_ANNEX_L,
134117 .codec_mode = S5P_MFC_CODEC_VC1RCV_DEC,
135118 .type = MFC_FMT_DEC,
....@@ -137,7 +120,6 @@
137120 .versions = MFC_V5PLUS_BITS,
138121 },
139122 {
140
- .name = "VP8 Encoded Stream",
141123 .fourcc = V4L2_PIX_FMT_VP8,
142124 .codec_mode = S5P_MFC_CODEC_VP8_DEC,
143125 .type = MFC_FMT_DEC,
....@@ -186,12 +168,27 @@
186168 .default_value = 0,
187169 },
188170 {
171
+ .id = V4L2_CID_MPEG_VIDEO_DEC_DISPLAY_DELAY,
172
+ .type = V4L2_CTRL_TYPE_INTEGER,
173
+ .minimum = 0,
174
+ .maximum = 16383,
175
+ .step = 1,
176
+ .default_value = 0,
177
+ },
178
+ {
189179 .id = V4L2_CID_MPEG_MFC51_VIDEO_DECODER_H264_DISPLAY_DELAY_ENABLE,
190180 .type = V4L2_CTRL_TYPE_BOOLEAN,
191181 .name = "H264 Display Delay Enable",
192182 .minimum = 0,
193183 .maximum = 1,
194184 .step = 1,
185
+ .default_value = 0,
186
+ },
187
+ {
188
+ .id = V4L2_CID_MPEG_VIDEO_DEC_DISPLAY_DELAY_ENABLE,
189
+ .type = V4L2_CTRL_TYPE_BOOLEAN,
190
+ .minimum = 0,
191
+ .maximum = 1,
195192 .default_value = 0,
196193 },
197194 {
....@@ -271,17 +268,10 @@
271268 {
272269 struct s5p_mfc_dev *dev = video_drvdata(file);
273270
274
- strlcpy(cap->driver, S5P_MFC_NAME, sizeof(cap->driver));
275
- strlcpy(cap->card, dev->vfd_dec->name, sizeof(cap->card));
271
+ strscpy(cap->driver, S5P_MFC_NAME, sizeof(cap->driver));
272
+ strscpy(cap->card, dev->vfd_dec->name, sizeof(cap->card));
276273 snprintf(cap->bus_info, sizeof(cap->bus_info), "platform:%s",
277274 dev_name(&dev->plat_dev->dev));
278
- /*
279
- * This is only a mem-to-mem video device. The capture and output
280
- * device capability flags are left only for backward compatibility
281
- * and are scheduled for removal.
282
- */
283
- cap->device_caps = V4L2_CAP_VIDEO_M2M_MPLANE | V4L2_CAP_STREAMING;
284
- cap->capabilities = cap->device_caps | V4L2_CAP_DEVICE_CAPS;
285275 return 0;
286276 }
287277
....@@ -290,7 +280,6 @@
290280 bool out)
291281 {
292282 struct s5p_mfc_dev *dev = video_drvdata(file);
293
- struct s5p_mfc_fmt *fmt;
294283 int i, j = 0;
295284
296285 for (i = 0; i < ARRAY_SIZE(formats); ++i) {
....@@ -307,20 +296,18 @@
307296 }
308297 if (i == ARRAY_SIZE(formats))
309298 return -EINVAL;
310
- fmt = &formats[i];
311
- strlcpy(f->description, fmt->name, sizeof(f->description));
312
- f->pixelformat = fmt->fourcc;
299
+ f->pixelformat = formats[i].fourcc;
313300 return 0;
314301 }
315302
316
-static int vidioc_enum_fmt_vid_cap_mplane(struct file *file, void *pirv,
317
- struct v4l2_fmtdesc *f)
303
+static int vidioc_enum_fmt_vid_cap(struct file *file, void *pirv,
304
+ struct v4l2_fmtdesc *f)
318305 {
319306 return vidioc_enum_fmt(file, f, false);
320307 }
321308
322
-static int vidioc_enum_fmt_vid_out_mplane(struct file *file, void *priv,
323
- struct v4l2_fmtdesc *f)
309
+static int vidioc_enum_fmt_vid_out(struct file *file, void *priv,
310
+ struct v4l2_fmtdesc *f)
324311 {
325312 return vidioc_enum_fmt(file, f, true);
326313 }
....@@ -602,7 +589,7 @@
602589 int i;
603590
604591 if (buf->memory != V4L2_MEMORY_MMAP) {
605
- mfc_err("Only mmaped buffers can be used\n");
592
+ mfc_err("Only mmapped buffers can be used\n");
606593 return -EINVAL;
607594 }
608595 mfc_debug(2, "State: %d, buf->type: %d\n", ctx->state, buf->type);
....@@ -632,9 +619,9 @@
632619 return -EIO;
633620 }
634621 if (buf->type == V4L2_BUF_TYPE_VIDEO_OUTPUT_MPLANE)
635
- return vb2_qbuf(&ctx->vq_src, buf);
622
+ return vb2_qbuf(&ctx->vq_src, NULL, buf);
636623 else if (buf->type == V4L2_BUF_TYPE_VIDEO_CAPTURE_MPLANE)
637
- return vb2_qbuf(&ctx->vq_dst, buf);
624
+ return vb2_qbuf(&ctx->vq_dst, NULL, buf);
638625 return -EINVAL;
639626 }
640627
....@@ -718,9 +705,11 @@
718705
719706 switch (ctrl->id) {
720707 case V4L2_CID_MPEG_MFC51_VIDEO_DECODER_H264_DISPLAY_DELAY:
708
+ case V4L2_CID_MPEG_VIDEO_DEC_DISPLAY_DELAY:
721709 ctx->display_delay = ctrl->val;
722710 break;
723711 case V4L2_CID_MPEG_MFC51_VIDEO_DECODER_H264_DISPLAY_DELAY_ENABLE:
712
+ case V4L2_CID_MPEG_VIDEO_DEC_DISPLAY_DELAY_ENABLE:
724713 ctx->display_delay_enable = ctrl->val;
725714 break;
726715 case V4L2_CID_MPEG_VIDEO_DECODER_MPEG4_DEBLOCK_FILTER:
....@@ -773,19 +762,23 @@
773762 .g_volatile_ctrl = s5p_mfc_dec_g_v_ctrl,
774763 };
775764
776
-/* Get cropping information */
777
-static int vidioc_g_crop(struct file *file, void *priv,
778
- struct v4l2_crop *cr)
765
+/* Get compose information */
766
+static int vidioc_g_selection(struct file *file, void *priv,
767
+ struct v4l2_selection *s)
779768 {
780769 struct s5p_mfc_ctx *ctx = fh_to_ctx(priv);
781770 struct s5p_mfc_dev *dev = ctx->dev;
782771 u32 left, right, top, bottom;
772
+ u32 width, height;
773
+
774
+ if (s->type != V4L2_BUF_TYPE_VIDEO_CAPTURE)
775
+ return -EINVAL;
783776
784777 if (ctx->state != MFCINST_HEAD_PARSED &&
785778 ctx->state != MFCINST_RUNNING &&
786779 ctx->state != MFCINST_FINISHING &&
787780 ctx->state != MFCINST_FINISHED) {
788
- mfc_err("Can not get crop information\n");
781
+ mfc_err("Can not get compose information\n");
789782 return -EINVAL;
790783 }
791784 if (ctx->src_fmt->fourcc == V4L2_PIX_FMT_H264) {
....@@ -795,21 +788,32 @@
795788 top = s5p_mfc_hw_call(dev->mfc_ops, get_crop_info_v, ctx);
796789 bottom = top >> S5P_FIMV_SHARED_CROP_BOTTOM_SHIFT;
797790 top = top & S5P_FIMV_SHARED_CROP_TOP_MASK;
798
- cr->c.left = left;
799
- cr->c.top = top;
800
- cr->c.width = ctx->img_width - left - right;
801
- cr->c.height = ctx->img_height - top - bottom;
802
- mfc_debug(2, "Cropping info [h264]: l=%d t=%d w=%d h=%d (r=%d b=%d fw=%d fh=%d\n",
803
- left, top, cr->c.width, cr->c.height, right, bottom,
791
+ width = ctx->img_width - left - right;
792
+ height = ctx->img_height - top - bottom;
793
+ mfc_debug(2, "Composing info [h264]: l=%d t=%d w=%d h=%d (r=%d b=%d fw=%d fh=%d\n",
794
+ left, top, s->r.width, s->r.height, right, bottom,
804795 ctx->buf_width, ctx->buf_height);
805796 } else {
806
- cr->c.left = 0;
807
- cr->c.top = 0;
808
- cr->c.width = ctx->img_width;
809
- cr->c.height = ctx->img_height;
810
- mfc_debug(2, "Cropping info: w=%d h=%d fw=%d fh=%d\n",
811
- cr->c.width, cr->c.height, ctx->buf_width,
797
+ left = 0;
798
+ top = 0;
799
+ width = ctx->img_width;
800
+ height = ctx->img_height;
801
+ mfc_debug(2, "Composing info: w=%d h=%d fw=%d fh=%d\n",
802
+ s->r.width, s->r.height, ctx->buf_width,
812803 ctx->buf_height);
804
+ }
805
+
806
+ switch (s->target) {
807
+ case V4L2_SEL_TGT_COMPOSE:
808
+ case V4L2_SEL_TGT_COMPOSE_DEFAULT:
809
+ case V4L2_SEL_TGT_COMPOSE_BOUNDS:
810
+ s->r.left = left;
811
+ s->r.top = top;
812
+ s->r.width = width;
813
+ s->r.height = height;
814
+ break;
815
+ default:
816
+ return -EINVAL;
813817 }
814818 return 0;
815819 }
....@@ -872,8 +876,8 @@
872876 /* v4l2_ioctl_ops */
873877 static const struct v4l2_ioctl_ops s5p_mfc_dec_ioctl_ops = {
874878 .vidioc_querycap = vidioc_querycap,
875
- .vidioc_enum_fmt_vid_cap_mplane = vidioc_enum_fmt_vid_cap_mplane,
876
- .vidioc_enum_fmt_vid_out_mplane = vidioc_enum_fmt_vid_out_mplane,
879
+ .vidioc_enum_fmt_vid_cap = vidioc_enum_fmt_vid_cap,
880
+ .vidioc_enum_fmt_vid_out = vidioc_enum_fmt_vid_out,
877881 .vidioc_g_fmt_vid_cap_mplane = vidioc_g_fmt,
878882 .vidioc_g_fmt_vid_out_mplane = vidioc_g_fmt,
879883 .vidioc_try_fmt_vid_cap_mplane = vidioc_try_fmt,
....@@ -887,7 +891,7 @@
887891 .vidioc_expbuf = vidioc_expbuf,
888892 .vidioc_streamon = vidioc_streamon,
889893 .vidioc_streamoff = vidioc_streamoff,
890
- .vidioc_g_crop = vidioc_g_crop,
894
+ .vidioc_g_selection = vidioc_g_selection,
891895 .vidioc_decoder_cmd = vidioc_decoder_cmd,
892896 .vidioc_subscribe_event = vidioc_subscribe_event,
893897 .vidioc_unsubscribe_event = v4l2_event_unsubscribe,