hc
2023-12-11 d2ccde1c8e90d38cee87a1b0309ad2827f3fd30d
kernel/drivers/media/platform/coda/coda-common.c
....@@ -1,14 +1,10 @@
1
+// SPDX-License-Identifier: GPL-2.0-or-later
12 /*
23 * Coda multi-standard codec IP
34 *
45 * Copyright (C) 2012 Vista Silicon S.L.
56 * Javier Martin, <javier.martin@vista-silicon.com>
67 * Xavier Duret
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>
....@@ -51,8 +47,8 @@
5147
5248 #define CODA_ISRAM_SIZE (2048 * 2)
5349
54
-#define MIN_W 176
55
-#define MIN_H 144
50
+#define MIN_W 48
51
+#define MIN_H 16
5652
5753 #define S_ALIGN 1 /* multiple of 2 */
5854 #define W_ALIGN 1 /* multiple of 2 */
....@@ -78,7 +74,7 @@
7874
7975 void coda_write(struct coda_dev *dev, u32 data, u32 reg)
8076 {
81
- v4l2_dbg(2, coda_debug, &dev->v4l2_dev,
77
+ v4l2_dbg(3, coda_debug, &dev->v4l2_dev,
8278 "%s: data=0x%x, reg=0x%x\n", __func__, data, reg);
8379 writel(data, dev->regs_base + reg);
8480 }
....@@ -88,7 +84,7 @@
8884 u32 data;
8985
9086 data = readl(dev->regs_base + reg);
91
- v4l2_dbg(2, coda_debug, &dev->v4l2_dev,
87
+ v4l2_dbg(3, coda_debug, &dev->v4l2_dev,
9288 "%s: data=0x%x, reg=0x%x\n", __func__, data, reg);
9389 return data;
9490 }
....@@ -159,9 +155,11 @@
159155 static const struct coda_codec coda9_codecs[] = {
160156 CODA_CODEC(CODA9_MODE_ENCODE_H264, V4L2_PIX_FMT_YUV420, V4L2_PIX_FMT_H264, 1920, 1088),
161157 CODA_CODEC(CODA9_MODE_ENCODE_MP4, V4L2_PIX_FMT_YUV420, V4L2_PIX_FMT_MPEG4, 1920, 1088),
158
+ CODA_CODEC(CODA9_MODE_ENCODE_MJPG, V4L2_PIX_FMT_YUV420, V4L2_PIX_FMT_JPEG, 8192, 8192),
162159 CODA_CODEC(CODA9_MODE_DECODE_H264, V4L2_PIX_FMT_H264, V4L2_PIX_FMT_YUV420, 1920, 1088),
163160 CODA_CODEC(CODA9_MODE_DECODE_MP2, V4L2_PIX_FMT_MPEG2, V4L2_PIX_FMT_YUV420, 1920, 1088),
164161 CODA_CODEC(CODA9_MODE_DECODE_MP4, V4L2_PIX_FMT_MPEG4, V4L2_PIX_FMT_YUV420, 1920, 1088),
162
+ CODA_CODEC(CODA9_MODE_DECODE_MJPG, V4L2_PIX_FMT_JPEG, V4L2_PIX_FMT_YUV420, 8192, 8192),
165163 };
166164
167165 struct coda_video_device {
....@@ -239,6 +237,38 @@
239237 },
240238 };
241239
240
+static const struct coda_video_device coda9_jpeg_encoder = {
241
+ .name = "coda-jpeg-encoder",
242
+ .type = CODA_INST_ENCODER,
243
+ .ops = &coda9_jpeg_encode_ops,
244
+ .direct = true,
245
+ .src_formats = {
246
+ V4L2_PIX_FMT_NV12,
247
+ V4L2_PIX_FMT_YUV420,
248
+ V4L2_PIX_FMT_YVU420,
249
+ V4L2_PIX_FMT_YUV422P,
250
+ },
251
+ .dst_formats = {
252
+ V4L2_PIX_FMT_JPEG,
253
+ },
254
+};
255
+
256
+static const struct coda_video_device coda9_jpeg_decoder = {
257
+ .name = "coda-jpeg-decoder",
258
+ .type = CODA_INST_DECODER,
259
+ .ops = &coda9_jpeg_decode_ops,
260
+ .direct = true,
261
+ .src_formats = {
262
+ V4L2_PIX_FMT_JPEG,
263
+ },
264
+ .dst_formats = {
265
+ V4L2_PIX_FMT_NV12,
266
+ V4L2_PIX_FMT_YUV420,
267
+ V4L2_PIX_FMT_YVU420,
268
+ V4L2_PIX_FMT_YUV422P,
269
+ },
270
+};
271
+
242272 static const struct coda_video_device *codadx6_video_devices[] = {
243273 &coda_bit_encoder,
244274 };
....@@ -256,6 +286,8 @@
256286 };
257287
258288 static const struct coda_video_device *coda9_video_devices[] = {
289
+ &coda9_jpeg_encoder,
290
+ &coda9_jpeg_decoder,
259291 &coda_bit_encoder,
260292 &coda_bit_decoder,
261293 };
....@@ -376,9 +408,9 @@
376408 if (!vdoa_data)
377409 vdoa_data = ERR_PTR(-EPROBE_DEFER);
378410
411
+ put_device(&vdoa_pdev->dev);
379412 out:
380
- if (vdoa_node)
381
- of_node_put(vdoa_node);
413
+ of_node_put(vdoa_node);
382414
383415 return vdoa_data;
384416 }
....@@ -391,15 +423,18 @@
391423 {
392424 struct coda_ctx *ctx = fh_to_ctx(priv);
393425
394
- strlcpy(cap->driver, CODA_NAME, sizeof(cap->driver));
395
- strlcpy(cap->card, coda_product_name(ctx->dev->devtype->product),
426
+ strscpy(cap->driver, CODA_NAME, sizeof(cap->driver));
427
+ strscpy(cap->card, coda_product_name(ctx->dev->devtype->product),
396428 sizeof(cap->card));
397
- strlcpy(cap->bus_info, "platform:" CODA_NAME, sizeof(cap->bus_info));
398
- cap->device_caps = V4L2_CAP_VIDEO_M2M | V4L2_CAP_STREAMING;
399
- cap->capabilities = cap->device_caps | V4L2_CAP_DEVICE_CAPS;
400
-
429
+ strscpy(cap->bus_info, "platform:" CODA_NAME, sizeof(cap->bus_info));
401430 return 0;
402431 }
432
+
433
+static const u32 coda_formats_420[CODA_MAX_FORMATS] = {
434
+ V4L2_PIX_FMT_NV12,
435
+ V4L2_PIX_FMT_YUV420,
436
+ V4L2_PIX_FMT_YVU420,
437
+};
403438
404439 static int coda_enum_fmt(struct file *file, void *priv,
405440 struct v4l2_fmtdesc *f)
....@@ -411,10 +446,33 @@
411446
412447 if (f->type == V4L2_BUF_TYPE_VIDEO_OUTPUT)
413448 formats = cvd->src_formats;
414
- else if (f->type == V4L2_BUF_TYPE_VIDEO_CAPTURE)
449
+ else if (f->type == V4L2_BUF_TYPE_VIDEO_CAPTURE) {
450
+ struct coda_q_data *q_data_src;
451
+ struct vb2_queue *src_vq;
452
+
415453 formats = cvd->dst_formats;
416
- else
454
+
455
+ /*
456
+ * If the source format is already fixed, only allow the same
457
+ * chroma subsampling.
458
+ */
459
+ q_data_src = get_q_data(ctx, V4L2_BUF_TYPE_VIDEO_OUTPUT);
460
+ src_vq = v4l2_m2m_get_vq(ctx->fh.m2m_ctx,
461
+ V4L2_BUF_TYPE_VIDEO_OUTPUT);
462
+ if (q_data_src->fourcc == V4L2_PIX_FMT_JPEG &&
463
+ vb2_is_streaming(src_vq)) {
464
+ if (ctx->params.jpeg_chroma_subsampling ==
465
+ V4L2_JPEG_CHROMA_SUBSAMPLING_420) {
466
+ formats = coda_formats_420;
467
+ } else if (ctx->params.jpeg_chroma_subsampling ==
468
+ V4L2_JPEG_CHROMA_SUBSAMPLING_422) {
469
+ f->pixelformat = V4L2_PIX_FMT_YUV422P;
470
+ return f->index ? -EINVAL : 0;
471
+ }
472
+ }
473
+ } else {
417474 return -EINVAL;
475
+ }
418476
419477 if (f->index >= CODA_MAX_FORMATS || formats[f->index] == 0)
420478 return -EINVAL;
....@@ -604,12 +662,23 @@
604662
605663 /*
606664 * If the source format is already fixed, only allow the same output
607
- * resolution
665
+ * resolution. When decoding JPEG images, we also have to make sure to
666
+ * use the same chroma subsampling.
608667 */
609668 src_vq = v4l2_m2m_get_vq(ctx->fh.m2m_ctx, V4L2_BUF_TYPE_VIDEO_OUTPUT);
610669 if (vb2_is_streaming(src_vq)) {
611670 f->fmt.pix.width = q_data_src->width;
612671 f->fmt.pix.height = q_data_src->height;
672
+
673
+ if (q_data_src->fourcc == V4L2_PIX_FMT_JPEG) {
674
+ if (ctx->params.jpeg_chroma_subsampling ==
675
+ V4L2_JPEG_CHROMA_SUBSAMPLING_420 &&
676
+ f->fmt.pix.pixelformat == V4L2_PIX_FMT_YUV422P)
677
+ f->fmt.pix.pixelformat = V4L2_PIX_FMT_NV12;
678
+ else if (ctx->params.jpeg_chroma_subsampling ==
679
+ V4L2_JPEG_CHROMA_SUBSAMPLING_422)
680
+ f->fmt.pix.pixelformat = V4L2_PIX_FMT_YUV422P;
681
+ }
613682 }
614683
615684 f->fmt.pix.colorspace = ctx->colorspace;
....@@ -627,12 +696,18 @@
627696 if (ret < 0)
628697 return ret;
629698
630
- /* The h.264 decoder only returns complete 16x16 macroblocks */
631
- if (codec && codec->src_fourcc == V4L2_PIX_FMT_H264) {
632
- f->fmt.pix.height = round_up(f->fmt.pix.height, 16);
699
+ /* The decoders always write complete macroblocks or MCUs */
700
+ if (ctx->inst_type == CODA_INST_DECODER) {
633701 f->fmt.pix.bytesperline = round_up(f->fmt.pix.width, 16);
634
- f->fmt.pix.sizeimage = f->fmt.pix.bytesperline *
635
- f->fmt.pix.height * 3 / 2;
702
+ f->fmt.pix.height = round_up(f->fmt.pix.height, 16);
703
+ if (codec->src_fourcc == V4L2_PIX_FMT_JPEG &&
704
+ f->fmt.pix.pixelformat == V4L2_PIX_FMT_YUV422P) {
705
+ f->fmt.pix.sizeimage = f->fmt.pix.bytesperline *
706
+ f->fmt.pix.height * 2;
707
+ } else {
708
+ f->fmt.pix.sizeimage = f->fmt.pix.bytesperline *
709
+ f->fmt.pix.height * 3 / 2;
710
+ }
636711
637712 ret = coda_try_fmt_vdoa(ctx, f, &use_vdoa);
638713 if (ret < 0)
....@@ -705,7 +780,8 @@
705780 return -EINVAL;
706781
707782 if (vb2_is_busy(vq)) {
708
- v4l2_err(&ctx->dev->v4l2_dev, "%s queue busy\n", __func__);
783
+ v4l2_err(&ctx->dev->v4l2_dev, "%s: %s queue busy: %d\n",
784
+ __func__, v4l2_type_names[f->type], vq->num_buffers);
709785 return -EBUSY;
710786 }
711787
....@@ -728,13 +804,15 @@
728804 ctx->tiled_map_type = GDI_TILED_FRAME_MB_RASTER_MAP;
729805 break;
730806 case V4L2_PIX_FMT_NV12:
731
- if (!disable_tiling) {
807
+ if (!disable_tiling && ctx->use_bit &&
808
+ ctx->dev->devtype->product == CODA_960) {
732809 ctx->tiled_map_type = GDI_TILED_FRAME_MB_RASTER_MAP;
733810 break;
734811 }
735
- /* else fall through */
812
+ fallthrough;
736813 case V4L2_PIX_FMT_YUV420:
737814 case V4L2_PIX_FMT_YVU420:
815
+ case V4L2_PIX_FMT_YUV422P:
738816 ctx->tiled_map_type = GDI_LINEAR_FRAME_MAP;
739817 break;
740818 default:
....@@ -751,11 +829,10 @@
751829 else
752830 ctx->use_vdoa = false;
753831
754
- v4l2_dbg(1, coda_debug, &ctx->dev->v4l2_dev,
755
- "Setting format for type %d, wxh: %dx%d, fmt: %4.4s %c\n",
756
- f->type, q_data->width, q_data->height,
757
- (char *)&q_data->fourcc,
758
- (ctx->tiled_map_type == GDI_LINEAR_FRAME_MAP) ? 'L' : 'T');
832
+ coda_dbg(1, ctx, "Setting %s format, wxh: %dx%d, fmt: %4.4s %c\n",
833
+ v4l2_type_names[f->type], q_data->width, q_data->height,
834
+ (char *)&q_data->fourcc,
835
+ (ctx->tiled_map_type == GDI_LINEAR_FRAME_MAP) ? 'L' : 'T');
759836
760837 return 0;
761838 }
....@@ -765,6 +842,7 @@
765842 {
766843 struct coda_ctx *ctx = fh_to_ctx(priv);
767844 struct coda_q_data *q_data_src;
845
+ const struct coda_codec *codec;
768846 struct v4l2_rect r;
769847 int ret;
770848
....@@ -785,6 +863,15 @@
785863 if (ctx->inst_type != CODA_INST_ENCODER)
786864 return 0;
787865
866
+ /* Setting the coded format determines the selected codec */
867
+ codec = coda_find_codec(ctx->dev, q_data_src->fourcc,
868
+ f->fmt.pix.pixelformat);
869
+ if (!codec) {
870
+ v4l2_err(&ctx->dev->v4l2_dev, "failed to determine codec\n");
871
+ return -EINVAL;
872
+ }
873
+ ctx->codec = codec;
874
+
788875 ctx->colorspace = f->fmt.pix.colorspace;
789876 ctx->xfer_func = f->fmt.pix.xfer_func;
790877 ctx->ycbcr_enc = f->fmt.pix.ycbcr_enc;
....@@ -797,6 +884,7 @@
797884 struct v4l2_format *f)
798885 {
799886 struct coda_ctx *ctx = fh_to_ctx(priv);
887
+ const struct coda_codec *codec;
800888 struct v4l2_format f_cap;
801889 struct vb2_queue *dst_vq;
802890 int ret;
....@@ -809,13 +897,22 @@
809897 if (ret)
810898 return ret;
811899
812
- if (ctx->inst_type != CODA_INST_DECODER)
813
- return 0;
814
-
815900 ctx->colorspace = f->fmt.pix.colorspace;
816901 ctx->xfer_func = f->fmt.pix.xfer_func;
817902 ctx->ycbcr_enc = f->fmt.pix.ycbcr_enc;
818903 ctx->quantization = f->fmt.pix.quantization;
904
+
905
+ if (ctx->inst_type != CODA_INST_DECODER)
906
+ return 0;
907
+
908
+ /* Setting the coded format determines the selected codec */
909
+ codec = coda_find_codec(ctx->dev, f->fmt.pix.pixelformat,
910
+ V4L2_PIX_FMT_YUV420);
911
+ if (!codec) {
912
+ v4l2_err(&ctx->dev->v4l2_dev, "failed to determine codec\n");
913
+ return -EINVAL;
914
+ }
915
+ ctx->codec = codec;
819916
820917 dst_vq = v4l2_m2m_get_vq(ctx->fh.m2m_ctx, V4L2_BUF_TYPE_VIDEO_CAPTURE);
821918 if (!dst_vq)
....@@ -864,14 +961,25 @@
864961 {
865962 struct coda_ctx *ctx = fh_to_ctx(priv);
866963
964
+ if (ctx->inst_type == CODA_INST_DECODER &&
965
+ buf->type == V4L2_BUF_TYPE_VIDEO_OUTPUT)
966
+ buf->flags &= ~V4L2_BUF_FLAG_LAST;
967
+
867968 return v4l2_m2m_qbuf(file, ctx->fh.m2m_ctx, buf);
868969 }
869970
870
-static bool coda_buf_is_end_of_stream(struct coda_ctx *ctx,
871
- struct vb2_v4l2_buffer *buf)
971
+static int coda_dqbuf(struct file *file, void *priv, struct v4l2_buffer *buf)
872972 {
873
- return ((ctx->bit_stream_param & CODA_BIT_STREAM_END_FLAG) &&
874
- (buf->sequence == (ctx->qsequence - 1)));
973
+ struct coda_ctx *ctx = fh_to_ctx(priv);
974
+ int ret;
975
+
976
+ ret = v4l2_m2m_dqbuf(file, ctx->fh.m2m_ctx, buf);
977
+
978
+ if (ctx->inst_type == CODA_INST_DECODER &&
979
+ buf->type == V4L2_BUF_TYPE_VIDEO_OUTPUT)
980
+ buf->flags &= ~V4L2_BUF_FLAG_LAST;
981
+
982
+ return ret;
875983 }
876984
877985 void coda_m2m_buf_done(struct coda_ctx *ctx, struct vb2_v4l2_buffer *buf,
....@@ -881,11 +989,8 @@
881989 .type = V4L2_EVENT_EOS
882990 };
883991
884
- if (coda_buf_is_end_of_stream(ctx, buf)) {
885
- buf->flags |= V4L2_BUF_FLAG_LAST;
886
-
992
+ if (buf->flags & V4L2_BUF_FLAG_LAST)
887993 v4l2_event_queue_fh(&ctx->fh, &eos_event);
888
- }
889994
890995 v4l2_m2m_buf_done(buf, state);
891996 }
....@@ -911,18 +1016,20 @@
9111016 case V4L2_SEL_TGT_CROP_DEFAULT:
9121017 case V4L2_SEL_TGT_CROP_BOUNDS:
9131018 rsel = &r;
914
- /* fallthrough */
1019
+ fallthrough;
9151020 case V4L2_SEL_TGT_CROP:
916
- if (s->type != V4L2_BUF_TYPE_VIDEO_OUTPUT)
1021
+ if (s->type != V4L2_BUF_TYPE_VIDEO_OUTPUT ||
1022
+ ctx->inst_type == CODA_INST_DECODER)
9171023 return -EINVAL;
9181024 break;
9191025 case V4L2_SEL_TGT_COMPOSE_BOUNDS:
9201026 case V4L2_SEL_TGT_COMPOSE_PADDED:
9211027 rsel = &r;
922
- /* fallthrough */
1028
+ fallthrough;
9231029 case V4L2_SEL_TGT_COMPOSE:
9241030 case V4L2_SEL_TGT_COMPOSE_DEFAULT:
925
- if (s->type != V4L2_BUF_TYPE_VIDEO_CAPTURE)
1031
+ if (s->type != V4L2_BUF_TYPE_VIDEO_CAPTURE ||
1032
+ ctx->inst_type == CODA_INST_ENCODER)
9261033 return -EINVAL;
9271034 break;
9281035 default:
....@@ -940,73 +1047,98 @@
9401047 struct coda_ctx *ctx = fh_to_ctx(fh);
9411048 struct coda_q_data *q_data;
9421049
943
- if (ctx->inst_type == CODA_INST_ENCODER &&
944
- s->type == V4L2_BUF_TYPE_VIDEO_OUTPUT &&
945
- s->target == V4L2_SEL_TGT_CROP) {
946
- q_data = get_q_data(ctx, s->type);
947
- if (!q_data)
948
- return -EINVAL;
1050
+ switch (s->target) {
1051
+ case V4L2_SEL_TGT_CROP:
1052
+ if (ctx->inst_type == CODA_INST_ENCODER &&
1053
+ s->type == V4L2_BUF_TYPE_VIDEO_OUTPUT) {
1054
+ q_data = get_q_data(ctx, s->type);
1055
+ if (!q_data)
1056
+ return -EINVAL;
9491057
950
- s->r.left = 0;
951
- s->r.top = 0;
952
- s->r.width = clamp(s->r.width, 2U, q_data->width);
953
- s->r.height = clamp(s->r.height, 2U, q_data->height);
1058
+ s->r.left = 0;
1059
+ s->r.top = 0;
1060
+ s->r.width = clamp(s->r.width, 2U, q_data->width);
1061
+ s->r.height = clamp(s->r.height, 2U, q_data->height);
9541062
955
- if (s->flags & V4L2_SEL_FLAG_LE) {
956
- s->r.width = round_up(s->r.width, 2);
957
- s->r.height = round_up(s->r.height, 2);
958
- } else {
959
- s->r.width = round_down(s->r.width, 2);
960
- s->r.height = round_down(s->r.height, 2);
1063
+ if (s->flags & V4L2_SEL_FLAG_LE) {
1064
+ s->r.width = round_up(s->r.width, 2);
1065
+ s->r.height = round_up(s->r.height, 2);
1066
+ } else {
1067
+ s->r.width = round_down(s->r.width, 2);
1068
+ s->r.height = round_down(s->r.height, 2);
1069
+ }
1070
+
1071
+ q_data->rect = s->r;
1072
+
1073
+ coda_dbg(1, ctx, "Setting crop rectangle: %dx%d\n",
1074
+ s->r.width, s->r.height);
1075
+
1076
+ return 0;
9611077 }
962
-
963
- q_data->rect = s->r;
964
-
965
- return 0;
1078
+ fallthrough;
1079
+ case V4L2_SEL_TGT_NATIVE_SIZE:
1080
+ case V4L2_SEL_TGT_COMPOSE:
1081
+ return coda_g_selection(file, fh, s);
1082
+ default:
1083
+ /* v4l2-compliance expects this to fail for read-only targets */
1084
+ return -EINVAL;
9661085 }
967
-
968
- return coda_g_selection(file, fh, s);
9691086 }
9701087
9711088 static int coda_try_encoder_cmd(struct file *file, void *fh,
9721089 struct v4l2_encoder_cmd *ec)
9731090 {
974
- if (ec->cmd != V4L2_ENC_CMD_STOP)
975
- return -EINVAL;
1091
+ struct coda_ctx *ctx = fh_to_ctx(fh);
9761092
977
- if (ec->flags & V4L2_ENC_CMD_STOP_AT_GOP_END)
978
- return -EINVAL;
1093
+ if (ctx->inst_type != CODA_INST_ENCODER)
1094
+ return -ENOTTY;
9791095
980
- return 0;
1096
+ return v4l2_m2m_ioctl_try_encoder_cmd(file, fh, ec);
1097
+}
1098
+
1099
+static void coda_wake_up_capture_queue(struct coda_ctx *ctx)
1100
+{
1101
+ struct vb2_queue *dst_vq;
1102
+
1103
+ coda_dbg(1, ctx, "waking up capture queue\n");
1104
+
1105
+ dst_vq = v4l2_m2m_get_vq(ctx->fh.m2m_ctx, V4L2_BUF_TYPE_VIDEO_CAPTURE);
1106
+ dst_vq->last_buffer_dequeued = true;
1107
+ wake_up(&dst_vq->done_wq);
9811108 }
9821109
9831110 static int coda_encoder_cmd(struct file *file, void *fh,
9841111 struct v4l2_encoder_cmd *ec)
9851112 {
9861113 struct coda_ctx *ctx = fh_to_ctx(fh);
987
- struct vb2_queue *dst_vq;
1114
+ struct vb2_v4l2_buffer *buf;
9881115 int ret;
9891116
9901117 ret = coda_try_encoder_cmd(file, fh, ec);
9911118 if (ret < 0)
9921119 return ret;
9931120
994
- /* Ignore encoder stop command silently in decoder context */
995
- if (ctx->inst_type != CODA_INST_ENCODER)
996
- return 0;
1121
+ mutex_lock(&ctx->wakeup_mutex);
1122
+ buf = v4l2_m2m_last_src_buf(ctx->fh.m2m_ctx);
1123
+ if (buf) {
1124
+ /*
1125
+ * If the last output buffer is still on the queue, make sure
1126
+ * that decoder finish_run will see the last flag and report it
1127
+ * to userspace.
1128
+ */
1129
+ buf->flags |= V4L2_BUF_FLAG_LAST;
1130
+ } else {
1131
+ /* Set the stream-end flag on this context */
1132
+ ctx->bit_stream_param |= CODA_BIT_STREAM_END_FLAG;
9971133
998
- /* Set the stream-end flag on this context */
999
- ctx->bit_stream_param |= CODA_BIT_STREAM_END_FLAG;
1000
-
1001
- flush_work(&ctx->pic_run_work);
1002
-
1003
- /* If there is no buffer in flight, wake up */
1004
- if (!ctx->streamon_out || ctx->qsequence == ctx->osequence) {
1005
- dst_vq = v4l2_m2m_get_vq(ctx->fh.m2m_ctx,
1006
- V4L2_BUF_TYPE_VIDEO_CAPTURE);
1007
- dst_vq->last_buffer_dequeued = true;
1008
- wake_up(&dst_vq->done_wq);
1134
+ /*
1135
+ * If the last output buffer has already been taken from the
1136
+ * queue, wake up the capture queue and signal end of stream
1137
+ * via the -EPIPE mechanism.
1138
+ */
1139
+ coda_wake_up_capture_queue(ctx);
10091140 }
1141
+ mutex_unlock(&ctx->wakeup_mutex);
10101142
10111143 return 0;
10121144 }
....@@ -1014,36 +1146,210 @@
10141146 static int coda_try_decoder_cmd(struct file *file, void *fh,
10151147 struct v4l2_decoder_cmd *dc)
10161148 {
1017
- if (dc->cmd != V4L2_DEC_CMD_STOP)
1018
- return -EINVAL;
1149
+ struct coda_ctx *ctx = fh_to_ctx(fh);
10191150
1020
- if (dc->flags & V4L2_DEC_CMD_STOP_TO_BLACK)
1021
- return -EINVAL;
1151
+ if (ctx->inst_type != CODA_INST_DECODER)
1152
+ return -ENOTTY;
10221153
1023
- if (!(dc->flags & V4L2_DEC_CMD_STOP_IMMEDIATELY) && (dc->stop.pts != 0))
1024
- return -EINVAL;
1154
+ return v4l2_m2m_ioctl_try_decoder_cmd(file, fh, dc);
1155
+}
10251156
1026
- return 0;
1157
+static bool coda_mark_last_meta(struct coda_ctx *ctx)
1158
+{
1159
+ struct coda_buffer_meta *meta;
1160
+
1161
+ coda_dbg(1, ctx, "marking last meta\n");
1162
+
1163
+ spin_lock(&ctx->buffer_meta_lock);
1164
+ if (list_empty(&ctx->buffer_meta_list)) {
1165
+ spin_unlock(&ctx->buffer_meta_lock);
1166
+ return false;
1167
+ }
1168
+
1169
+ meta = list_last_entry(&ctx->buffer_meta_list, struct coda_buffer_meta,
1170
+ list);
1171
+ meta->last = true;
1172
+
1173
+ spin_unlock(&ctx->buffer_meta_lock);
1174
+ return true;
1175
+}
1176
+
1177
+static bool coda_mark_last_dst_buf(struct coda_ctx *ctx)
1178
+{
1179
+ struct vb2_v4l2_buffer *buf;
1180
+ struct vb2_buffer *dst_vb;
1181
+ struct vb2_queue *dst_vq;
1182
+ unsigned long flags;
1183
+
1184
+ coda_dbg(1, ctx, "marking last capture buffer\n");
1185
+
1186
+ dst_vq = v4l2_m2m_get_vq(ctx->fh.m2m_ctx, V4L2_BUF_TYPE_VIDEO_CAPTURE);
1187
+ spin_lock_irqsave(&dst_vq->done_lock, flags);
1188
+ if (list_empty(&dst_vq->done_list)) {
1189
+ spin_unlock_irqrestore(&dst_vq->done_lock, flags);
1190
+ return false;
1191
+ }
1192
+
1193
+ dst_vb = list_last_entry(&dst_vq->done_list, struct vb2_buffer,
1194
+ done_entry);
1195
+ buf = to_vb2_v4l2_buffer(dst_vb);
1196
+ buf->flags |= V4L2_BUF_FLAG_LAST;
1197
+
1198
+ spin_unlock_irqrestore(&dst_vq->done_lock, flags);
1199
+ return true;
10271200 }
10281201
10291202 static int coda_decoder_cmd(struct file *file, void *fh,
10301203 struct v4l2_decoder_cmd *dc)
10311204 {
10321205 struct coda_ctx *ctx = fh_to_ctx(fh);
1206
+ struct coda_dev *dev = ctx->dev;
1207
+ struct vb2_v4l2_buffer *buf;
1208
+ struct vb2_queue *dst_vq;
1209
+ bool stream_end;
1210
+ bool wakeup;
10331211 int ret;
10341212
10351213 ret = coda_try_decoder_cmd(file, fh, dc);
10361214 if (ret < 0)
10371215 return ret;
10381216
1039
- /* Ignore decoder stop command silently in encoder context */
1040
- if (ctx->inst_type != CODA_INST_DECODER)
1041
- return 0;
1217
+ switch (dc->cmd) {
1218
+ case V4L2_DEC_CMD_START:
1219
+ mutex_lock(&dev->coda_mutex);
1220
+ mutex_lock(&ctx->bitstream_mutex);
1221
+ coda_bitstream_flush(ctx);
1222
+ dst_vq = v4l2_m2m_get_vq(ctx->fh.m2m_ctx,
1223
+ V4L2_BUF_TYPE_VIDEO_CAPTURE);
1224
+ vb2_clear_last_buffer_dequeued(dst_vq);
1225
+ ctx->bit_stream_param &= ~CODA_BIT_STREAM_END_FLAG;
1226
+ coda_fill_bitstream(ctx, NULL);
1227
+ mutex_unlock(&ctx->bitstream_mutex);
1228
+ mutex_unlock(&dev->coda_mutex);
1229
+ break;
1230
+ case V4L2_DEC_CMD_STOP:
1231
+ stream_end = false;
1232
+ wakeup = false;
10421233
1043
- /* Set the stream-end flag on this context */
1044
- coda_bit_stream_end_flag(ctx);
1045
- ctx->hold = false;
1046
- v4l2_m2m_try_schedule(ctx->fh.m2m_ctx);
1234
+ mutex_lock(&ctx->wakeup_mutex);
1235
+
1236
+ buf = v4l2_m2m_last_src_buf(ctx->fh.m2m_ctx);
1237
+ if (buf) {
1238
+ coda_dbg(1, ctx, "marking last pending buffer\n");
1239
+
1240
+ /* Mark last buffer */
1241
+ buf->flags |= V4L2_BUF_FLAG_LAST;
1242
+
1243
+ if (v4l2_m2m_num_src_bufs_ready(ctx->fh.m2m_ctx) == 0) {
1244
+ coda_dbg(1, ctx, "all remaining buffers queued\n");
1245
+ stream_end = true;
1246
+ }
1247
+ } else {
1248
+ if (ctx->use_bit)
1249
+ if (coda_mark_last_meta(ctx))
1250
+ stream_end = true;
1251
+ else
1252
+ wakeup = true;
1253
+ else
1254
+ if (!coda_mark_last_dst_buf(ctx))
1255
+ wakeup = true;
1256
+ }
1257
+
1258
+ if (stream_end) {
1259
+ coda_dbg(1, ctx, "all remaining buffers queued\n");
1260
+
1261
+ /* Set the stream-end flag on this context */
1262
+ coda_bit_stream_end_flag(ctx);
1263
+ ctx->hold = false;
1264
+ v4l2_m2m_try_schedule(ctx->fh.m2m_ctx);
1265
+ }
1266
+
1267
+ if (wakeup) {
1268
+ /* If there is no buffer in flight, wake up */
1269
+ coda_wake_up_capture_queue(ctx);
1270
+ }
1271
+
1272
+ mutex_unlock(&ctx->wakeup_mutex);
1273
+ break;
1274
+ default:
1275
+ return -EINVAL;
1276
+ }
1277
+
1278
+ return 0;
1279
+}
1280
+
1281
+static int coda_enum_framesizes(struct file *file, void *fh,
1282
+ struct v4l2_frmsizeenum *fsize)
1283
+{
1284
+ struct coda_ctx *ctx = fh_to_ctx(fh);
1285
+ struct coda_q_data *q_data_dst;
1286
+ const struct coda_codec *codec;
1287
+
1288
+ if (ctx->inst_type != CODA_INST_ENCODER)
1289
+ return -ENOTTY;
1290
+
1291
+ if (fsize->index)
1292
+ return -EINVAL;
1293
+
1294
+ if (coda_format_normalize_yuv(fsize->pixel_format) ==
1295
+ V4L2_PIX_FMT_YUV420) {
1296
+ q_data_dst = get_q_data(ctx, V4L2_BUF_TYPE_VIDEO_CAPTURE);
1297
+ codec = coda_find_codec(ctx->dev, fsize->pixel_format,
1298
+ q_data_dst->fourcc);
1299
+ } else {
1300
+ codec = coda_find_codec(ctx->dev, V4L2_PIX_FMT_YUV420,
1301
+ fsize->pixel_format);
1302
+ }
1303
+ if (!codec)
1304
+ return -EINVAL;
1305
+
1306
+ fsize->type = V4L2_FRMSIZE_TYPE_CONTINUOUS;
1307
+ fsize->stepwise.min_width = MIN_W;
1308
+ fsize->stepwise.max_width = codec->max_w;
1309
+ fsize->stepwise.step_width = 1;
1310
+ fsize->stepwise.min_height = MIN_H;
1311
+ fsize->stepwise.max_height = codec->max_h;
1312
+ fsize->stepwise.step_height = 1;
1313
+
1314
+ return 0;
1315
+}
1316
+
1317
+static int coda_enum_frameintervals(struct file *file, void *fh,
1318
+ struct v4l2_frmivalenum *f)
1319
+{
1320
+ struct coda_ctx *ctx = fh_to_ctx(fh);
1321
+ struct coda_q_data *q_data;
1322
+ const struct coda_codec *codec;
1323
+
1324
+ if (f->index)
1325
+ return -EINVAL;
1326
+
1327
+ /* Disallow YUYV if the vdoa is not available */
1328
+ if (!ctx->vdoa && f->pixel_format == V4L2_PIX_FMT_YUYV)
1329
+ return -EINVAL;
1330
+
1331
+ if (coda_format_normalize_yuv(f->pixel_format) == V4L2_PIX_FMT_YUV420) {
1332
+ q_data = get_q_data(ctx, V4L2_BUF_TYPE_VIDEO_CAPTURE);
1333
+ codec = coda_find_codec(ctx->dev, f->pixel_format,
1334
+ q_data->fourcc);
1335
+ } else {
1336
+ codec = coda_find_codec(ctx->dev, V4L2_PIX_FMT_YUV420,
1337
+ f->pixel_format);
1338
+ }
1339
+ if (!codec)
1340
+ return -EINVAL;
1341
+
1342
+ if (f->width < MIN_W || f->width > codec->max_w ||
1343
+ f->height < MIN_H || f->height > codec->max_h)
1344
+ return -EINVAL;
1345
+
1346
+ f->type = V4L2_FRMIVAL_TYPE_CONTINUOUS;
1347
+ f->stepwise.min.numerator = 1;
1348
+ f->stepwise.min.denominator = 65535;
1349
+ f->stepwise.max.numerator = 65536;
1350
+ f->stepwise.max.denominator = 1;
1351
+ f->stepwise.step.numerator = 1;
1352
+ f->stepwise.step.denominator = 1;
10471353
10481354 return 0;
10491355 }
....@@ -1084,10 +1390,10 @@
10841390 return;
10851391 }
10861392
1087
- /* Upper bound is 65536/1, map everything above to infinity */
1393
+ /* Upper bound is 65536/1 */
10881394 if (s.denominator == 0 || s.numerator / s.denominator > 65536) {
1089
- timeperframe->numerator = 1;
1090
- timeperframe->denominator = 0;
1395
+ timeperframe->numerator = 65536;
1396
+ timeperframe->denominator = 1;
10911397 return;
10921398 }
10931399
....@@ -1139,9 +1445,11 @@
11391445 if (a->type != V4L2_BUF_TYPE_VIDEO_OUTPUT)
11401446 return -EINVAL;
11411447
1448
+ a->parm.output.capability = V4L2_CAP_TIMEPERFRAME;
11421449 tpf = &a->parm.output.timeperframe;
11431450 coda_approximate_timeperframe(tpf);
11441451 ctx->params.framerate = coda_timeperframe_to_frate(tpf);
1452
+ ctx->params.framerate_changed = true;
11451453
11461454 return 0;
11471455 }
....@@ -1149,9 +1457,16 @@
11491457 static int coda_subscribe_event(struct v4l2_fh *fh,
11501458 const struct v4l2_event_subscription *sub)
11511459 {
1460
+ struct coda_ctx *ctx = fh_to_ctx(fh);
1461
+
11521462 switch (sub->type) {
11531463 case V4L2_EVENT_EOS:
11541464 return v4l2_event_subscribe(fh, sub, 0, NULL);
1465
+ case V4L2_EVENT_SOURCE_CHANGE:
1466
+ if (ctx->inst_type == CODA_INST_DECODER)
1467
+ return v4l2_event_subscribe(fh, sub, 0, NULL);
1468
+ else
1469
+ return -EINVAL;
11551470 default:
11561471 return v4l2_ctrl_subscribe_event(fh, sub);
11571472 }
....@@ -1175,7 +1490,7 @@
11751490
11761491 .vidioc_qbuf = coda_qbuf,
11771492 .vidioc_expbuf = v4l2_m2m_ioctl_expbuf,
1178
- .vidioc_dqbuf = v4l2_m2m_ioctl_dqbuf,
1493
+ .vidioc_dqbuf = coda_dqbuf,
11791494 .vidioc_create_bufs = v4l2_m2m_ioctl_create_bufs,
11801495 .vidioc_prepare_buf = v4l2_m2m_ioctl_prepare_buf,
11811496
....@@ -1192,6 +1507,9 @@
11921507
11931508 .vidioc_g_parm = coda_g_parm,
11941509 .vidioc_s_parm = coda_s_parm,
1510
+
1511
+ .vidioc_enum_framesizes = coda_enum_framesizes,
1512
+ .vidioc_enum_frameintervals = coda_enum_frameintervals,
11951513
11961514 .vidioc_subscribe_event = coda_subscribe_event,
11971515 .vidioc_unsubscribe_event = v4l2_event_unsubscribe,
....@@ -1228,15 +1546,17 @@
12281546
12291547 if (!wait_for_completion_timeout(&ctx->completion,
12301548 msecs_to_jiffies(1000))) {
1231
- dev_err(&dev->plat_dev->dev, "CODA PIC_RUN timeout\n");
1549
+ if (ctx->use_bit) {
1550
+ dev_err(dev->dev, "CODA PIC_RUN timeout\n");
12321551
1233
- ctx->hold = true;
1552
+ ctx->hold = true;
12341553
1235
- coda_hw_reset(ctx);
1554
+ coda_hw_reset(ctx);
1555
+ }
12361556
12371557 if (ctx->ops->run_timeout)
12381558 ctx->ops->run_timeout(ctx);
1239
- } else if (!ctx->aborting) {
1559
+ } else {
12401560 ctx->ops->finish_run(ctx);
12411561 }
12421562
....@@ -1261,14 +1581,12 @@
12611581 * the compressed frame can be in the bitstream.
12621582 */
12631583 if (!src_bufs && ctx->inst_type != CODA_INST_DECODER) {
1264
- v4l2_dbg(1, coda_debug, &ctx->dev->v4l2_dev,
1265
- "not ready: not enough video buffers.\n");
1584
+ coda_dbg(1, ctx, "not ready: not enough vid-out buffers.\n");
12661585 return 0;
12671586 }
12681587
12691588 if (!v4l2_m2m_num_dst_bufs_ready(ctx->fh.m2m_ctx)) {
1270
- v4l2_dbg(1, coda_debug, &ctx->dev->v4l2_dev,
1271
- "not ready: not enough video capture buffers.\n");
1589
+ coda_dbg(1, ctx, "not ready: not enough vid-cap buffers.\n");
12721590 return 0;
12731591 }
12741592
....@@ -1276,49 +1594,48 @@
12761594 bool stream_end = ctx->bit_stream_param &
12771595 CODA_BIT_STREAM_END_FLAG;
12781596 int num_metas = ctx->num_metas;
1597
+ struct coda_buffer_meta *meta;
12791598 unsigned int count;
12801599
12811600 count = hweight32(ctx->frm_dis_flg);
12821601 if (ctx->use_vdoa && count >= (ctx->num_internal_frames - 1)) {
1283
- v4l2_dbg(1, coda_debug, &ctx->dev->v4l2_dev,
1284
- "%d: not ready: all internal buffers in use: %d/%d (0x%x)",
1285
- ctx->idx, count, ctx->num_internal_frames,
1602
+ coda_dbg(1, ctx,
1603
+ "not ready: all internal buffers in use: %d/%d (0x%x)",
1604
+ count, ctx->num_internal_frames,
12861605 ctx->frm_dis_flg);
12871606 return 0;
12881607 }
12891608
12901609 if (ctx->hold && !src_bufs) {
1291
- v4l2_dbg(1, coda_debug, &ctx->dev->v4l2_dev,
1292
- "%d: not ready: on hold for more buffers.\n",
1293
- ctx->idx);
1610
+ coda_dbg(1, ctx,
1611
+ "not ready: on hold for more buffers.\n");
12941612 return 0;
12951613 }
12961614
12971615 if (!stream_end && (num_metas + src_bufs) < 2) {
1298
- v4l2_dbg(1, coda_debug, &ctx->dev->v4l2_dev,
1299
- "%d: not ready: need 2 buffers available (%d, %d)\n",
1300
- ctx->idx, num_metas, src_bufs);
1616
+ coda_dbg(1, ctx,
1617
+ "not ready: need 2 buffers available (queue:%d + bitstream:%d)\n",
1618
+ num_metas, src_bufs);
13011619 return 0;
13021620 }
13031621
1304
-
1305
- if (!src_bufs && !stream_end &&
1306
- (coda_get_bitstream_payload(ctx) < 512)) {
1307
- v4l2_dbg(1, coda_debug, &ctx->dev->v4l2_dev,
1308
- "%d: not ready: not enough bitstream data (%d).\n",
1309
- ctx->idx, coda_get_bitstream_payload(ctx));
1622
+ meta = list_first_entry(&ctx->buffer_meta_list,
1623
+ struct coda_buffer_meta, list);
1624
+ if (!coda_bitstream_can_fetch_past(ctx, meta->end) &&
1625
+ !stream_end) {
1626
+ coda_dbg(1, ctx,
1627
+ "not ready: not enough bitstream data to read past %u (%u)\n",
1628
+ meta->end, ctx->bitstream_fifo.kfifo.in);
13101629 return 0;
13111630 }
13121631 }
13131632
13141633 if (ctx->aborting) {
1315
- v4l2_dbg(1, coda_debug, &ctx->dev->v4l2_dev,
1316
- "not ready: aborting\n");
1634
+ coda_dbg(1, ctx, "not ready: aborting\n");
13171635 return 0;
13181636 }
13191637
1320
- v4l2_dbg(1, coda_debug, &ctx->dev->v4l2_dev,
1321
- "job ready\n");
1638
+ coda_dbg(2, ctx, "job ready\n");
13221639
13231640 return 1;
13241641 }
....@@ -1329,8 +1646,7 @@
13291646
13301647 ctx->aborting = 1;
13311648
1332
- v4l2_dbg(1, coda_debug, &ctx->dev->v4l2_dev,
1333
- "Aborting task\n");
1649
+ coda_dbg(1, ctx, "job abort\n");
13341650 }
13351651
13361652 static const struct v4l2_m2m_ops coda_m2m_ops = {
....@@ -1404,21 +1720,34 @@
14041720 q_data = get_q_data(ctx, vq->type);
14051721 size = q_data->sizeimage;
14061722
1723
+ if (*nplanes)
1724
+ return sizes[0] < size ? -EINVAL : 0;
1725
+
14071726 *nplanes = 1;
14081727 sizes[0] = size;
14091728
1410
- v4l2_dbg(1, coda_debug, &ctx->dev->v4l2_dev,
1411
- "get %d buffer(s) of size %d each.\n", *nbuffers, size);
1729
+ coda_dbg(1, ctx, "get %d buffer(s) of size %d each.\n", *nbuffers,
1730
+ size);
14121731
14131732 return 0;
14141733 }
14151734
14161735 static int coda_buf_prepare(struct vb2_buffer *vb)
14171736 {
1737
+ struct vb2_v4l2_buffer *vbuf = to_vb2_v4l2_buffer(vb);
14181738 struct coda_ctx *ctx = vb2_get_drv_priv(vb->vb2_queue);
14191739 struct coda_q_data *q_data;
14201740
14211741 q_data = get_q_data(ctx, vb->vb2_queue->type);
1742
+ if (V4L2_TYPE_IS_OUTPUT(vb->vb2_queue->type)) {
1743
+ if (vbuf->field == V4L2_FIELD_ANY)
1744
+ vbuf->field = V4L2_FIELD_NONE;
1745
+ if (vbuf->field != V4L2_FIELD_NONE) {
1746
+ v4l2_warn(&ctx->dev->v4l2_dev,
1747
+ "%s field isn't supported\n", __func__);
1748
+ return -EINVAL;
1749
+ }
1750
+ }
14221751
14231752 if (vb2_plane_size(vb, 0) < q_data->sizeimage) {
14241753 v4l2_warn(&ctx->dev->v4l2_dev,
....@@ -1457,44 +1786,81 @@
14571786 v4l2_ctrl_unlock(ctrl);
14581787 }
14591788
1460
-static void coda_update_h264_profile_ctrl(struct coda_ctx *ctx)
1789
+void coda_update_profile_level_ctrls(struct coda_ctx *ctx, u8 profile_idc,
1790
+ u8 level_idc)
14611791 {
14621792 const char * const *profile_names;
1463
- int profile;
1464
-
1465
- profile = coda_h264_profile(ctx->params.h264_profile_idc);
1466
- if (profile < 0) {
1467
- v4l2_warn(&ctx->dev->v4l2_dev, "Invalid H264 Profile: %u\n",
1468
- ctx->params.h264_profile_idc);
1469
- return;
1470
- }
1471
-
1472
- coda_update_menu_ctrl(ctx->h264_profile_ctrl, profile);
1473
-
1474
- profile_names = v4l2_ctrl_get_menu(V4L2_CID_MPEG_VIDEO_H264_PROFILE);
1475
-
1476
- v4l2_dbg(1, coda_debug, &ctx->dev->v4l2_dev, "Parsed H264 Profile: %s\n",
1477
- profile_names[profile]);
1478
-}
1479
-
1480
-static void coda_update_h264_level_ctrl(struct coda_ctx *ctx)
1481
-{
14821793 const char * const *level_names;
1794
+ struct v4l2_ctrl *profile_ctrl;
1795
+ struct v4l2_ctrl *level_ctrl;
1796
+ const char *codec_name;
1797
+ u32 profile_cid;
1798
+ u32 level_cid;
1799
+ int profile;
14831800 int level;
14841801
1485
- level = coda_h264_level(ctx->params.h264_level_idc);
1486
- if (level < 0) {
1487
- v4l2_warn(&ctx->dev->v4l2_dev, "Invalid H264 Level: %u\n",
1488
- ctx->params.h264_level_idc);
1802
+ switch (ctx->codec->src_fourcc) {
1803
+ case V4L2_PIX_FMT_H264:
1804
+ codec_name = "H264";
1805
+ profile_cid = V4L2_CID_MPEG_VIDEO_H264_PROFILE;
1806
+ level_cid = V4L2_CID_MPEG_VIDEO_H264_LEVEL;
1807
+ profile_ctrl = ctx->h264_profile_ctrl;
1808
+ level_ctrl = ctx->h264_level_ctrl;
1809
+ profile = coda_h264_profile(profile_idc);
1810
+ level = coda_h264_level(level_idc);
1811
+ break;
1812
+ case V4L2_PIX_FMT_MPEG2:
1813
+ codec_name = "MPEG-2";
1814
+ profile_cid = V4L2_CID_MPEG_VIDEO_MPEG2_PROFILE;
1815
+ level_cid = V4L2_CID_MPEG_VIDEO_MPEG2_LEVEL;
1816
+ profile_ctrl = ctx->mpeg2_profile_ctrl;
1817
+ level_ctrl = ctx->mpeg2_level_ctrl;
1818
+ profile = coda_mpeg2_profile(profile_idc);
1819
+ level = coda_mpeg2_level(level_idc);
1820
+ break;
1821
+ case V4L2_PIX_FMT_MPEG4:
1822
+ codec_name = "MPEG-4";
1823
+ profile_cid = V4L2_CID_MPEG_VIDEO_MPEG4_PROFILE;
1824
+ level_cid = V4L2_CID_MPEG_VIDEO_MPEG4_LEVEL;
1825
+ profile_ctrl = ctx->mpeg4_profile_ctrl;
1826
+ level_ctrl = ctx->mpeg4_level_ctrl;
1827
+ profile = coda_mpeg4_profile(profile_idc);
1828
+ level = coda_mpeg4_level(level_idc);
1829
+ break;
1830
+ default:
14891831 return;
14901832 }
14911833
1492
- coda_update_menu_ctrl(ctx->h264_level_ctrl, level);
1834
+ profile_names = v4l2_ctrl_get_menu(profile_cid);
1835
+ level_names = v4l2_ctrl_get_menu(level_cid);
14931836
1494
- level_names = v4l2_ctrl_get_menu(V4L2_CID_MPEG_VIDEO_H264_LEVEL);
1837
+ if (profile < 0) {
1838
+ v4l2_warn(&ctx->dev->v4l2_dev, "Invalid %s profile: %u\n",
1839
+ codec_name, profile_idc);
1840
+ } else {
1841
+ coda_dbg(1, ctx, "Parsed %s profile: %s\n", codec_name,
1842
+ profile_names[profile]);
1843
+ coda_update_menu_ctrl(profile_ctrl, profile);
1844
+ }
14951845
1496
- v4l2_dbg(1, coda_debug, &ctx->dev->v4l2_dev, "Parsed H264 Level: %s\n",
1497
- level_names[level]);
1846
+ if (level < 0) {
1847
+ v4l2_warn(&ctx->dev->v4l2_dev, "Invalid %s level: %u\n",
1848
+ codec_name, level_idc);
1849
+ } else {
1850
+ coda_dbg(1, ctx, "Parsed %s level: %s\n", codec_name,
1851
+ level_names[level]);
1852
+ coda_update_menu_ctrl(level_ctrl, level);
1853
+ }
1854
+}
1855
+
1856
+static void coda_queue_source_change_event(struct coda_ctx *ctx)
1857
+{
1858
+ static const struct v4l2_event source_change_event = {
1859
+ .type = V4L2_EVENT_SOURCE_CHANGE,
1860
+ .u.src_change.changes = V4L2_EVENT_SRC_CH_RESOLUTION,
1861
+ };
1862
+
1863
+ v4l2_event_queue_fh(&ctx->fh, &source_change_event);
14981864 }
14991865
15001866 static void coda_buf_queue(struct vb2_buffer *vb)
....@@ -1527,8 +1893,9 @@
15271893 */
15281894 if (!ctx->params.h264_profile_idc) {
15291895 coda_sps_parse_profile(ctx, vb);
1530
- coda_update_h264_profile_ctrl(ctx);
1531
- coda_update_h264_level_ctrl(ctx);
1896
+ coda_update_profile_level_ctrls(ctx,
1897
+ ctx->params.h264_profile_idc,
1898
+ ctx->params.h264_level_idc);
15321899 }
15331900 }
15341901
....@@ -1538,8 +1905,24 @@
15381905 /* This set buf->sequence = ctx->qsequence++ */
15391906 coda_fill_bitstream(ctx, NULL);
15401907 mutex_unlock(&ctx->bitstream_mutex);
1908
+
1909
+ if (!ctx->initialized) {
1910
+ /*
1911
+ * Run sequence initialization in case the queued
1912
+ * buffer contained headers.
1913
+ */
1914
+ if (vb2_is_streaming(vb->vb2_queue) &&
1915
+ ctx->ops->seq_init_work) {
1916
+ queue_work(ctx->dev->workqueue,
1917
+ &ctx->seq_init_work);
1918
+ flush_work(&ctx->seq_init_work);
1919
+ }
1920
+
1921
+ if (ctx->initialized)
1922
+ coda_queue_source_change_event(ctx);
1923
+ }
15411924 } else {
1542
- if (ctx->inst_type == CODA_INST_ENCODER &&
1925
+ if ((ctx->inst_type == CODA_INST_ENCODER || !ctx->use_bit) &&
15431926 vq->type == V4L2_BUF_TYPE_VIDEO_OUTPUT)
15441927 vbuf->sequence = ctx->qsequence++;
15451928 v4l2_m2m_buf_queue(ctx->fh.m2m_ctx, vbuf);
....@@ -1549,7 +1932,7 @@
15491932 int coda_alloc_aux_buf(struct coda_dev *dev, struct coda_aux_buf *buf,
15501933 size_t size, const char *name, struct dentry *parent)
15511934 {
1552
- buf->vaddr = dma_alloc_coherent(&dev->plat_dev->dev, size, &buf->paddr,
1935
+ buf->vaddr = dma_alloc_coherent(dev->dev, size, &buf->paddr,
15531936 GFP_KERNEL);
15541937 if (!buf->vaddr) {
15551938 v4l2_err(&dev->v4l2_dev,
....@@ -1565,9 +1948,6 @@
15651948 buf->blob.size = size;
15661949 buf->dentry = debugfs_create_blob(name, 0644, parent,
15671950 &buf->blob);
1568
- if (!buf->dentry)
1569
- dev_warn(&dev->plat_dev->dev,
1570
- "failed to create debugfs entry %s\n", name);
15711951 }
15721952
15731953 return 0;
....@@ -1577,8 +1957,7 @@
15771957 struct coda_aux_buf *buf)
15781958 {
15791959 if (buf->vaddr) {
1580
- dma_free_coherent(&dev->plat_dev->dev, buf->size,
1581
- buf->vaddr, buf->paddr);
1960
+ dma_free_coherent(dev->dev, buf->size, buf->vaddr, buf->paddr);
15821961 buf->vaddr = NULL;
15831962 buf->size = 0;
15841963 debugfs_remove(buf->dentry);
....@@ -1599,6 +1978,8 @@
15991978 if (count < 1)
16001979 return -EINVAL;
16011980
1981
+ coda_dbg(1, ctx, "start streaming %s\n", v4l2_type_names[q->type]);
1982
+
16021983 INIT_LIST_HEAD(&list);
16031984
16041985 q_data_src = get_q_data(ctx, V4L2_BUF_TYPE_VIDEO_OUTPUT);
....@@ -1609,12 +1990,59 @@
16091990 coda_fill_bitstream(ctx, &list);
16101991 mutex_unlock(&ctx->bitstream_mutex);
16111992
1612
- if (coda_get_bitstream_payload(ctx) < 512) {
1993
+ if (ctx->dev->devtype->product != CODA_960 &&
1994
+ coda_get_bitstream_payload(ctx) < 512) {
1995
+ v4l2_err(v4l2_dev, "start payload < 512\n");
16131996 ret = -EINVAL;
16141997 goto err;
16151998 }
1999
+
2000
+ if (!ctx->initialized) {
2001
+ /* Run sequence initialization */
2002
+ if (ctx->ops->seq_init_work) {
2003
+ queue_work(ctx->dev->workqueue,
2004
+ &ctx->seq_init_work);
2005
+ flush_work(&ctx->seq_init_work);
2006
+ }
2007
+ }
16162008 }
16172009
2010
+ /*
2011
+ * Check the first input JPEG buffer to determine chroma
2012
+ * subsampling.
2013
+ */
2014
+ if (q_data_src->fourcc == V4L2_PIX_FMT_JPEG) {
2015
+ buf = v4l2_m2m_next_src_buf(ctx->fh.m2m_ctx);
2016
+ ret = coda_jpeg_decode_header(ctx, &buf->vb2_buf);
2017
+ if (ret < 0) {
2018
+ v4l2_err(v4l2_dev,
2019
+ "failed to decode JPEG header: %d\n",
2020
+ ret);
2021
+ goto err;
2022
+ }
2023
+
2024
+ q_data_dst = get_q_data(ctx, V4L2_BUF_TYPE_VIDEO_CAPTURE);
2025
+ q_data_dst->width = round_up(q_data_src->width, 16);
2026
+ q_data_dst->height = round_up(q_data_src->height, 16);
2027
+ q_data_dst->bytesperline = q_data_dst->width;
2028
+ if (ctx->params.jpeg_chroma_subsampling ==
2029
+ V4L2_JPEG_CHROMA_SUBSAMPLING_420) {
2030
+ q_data_dst->sizeimage =
2031
+ q_data_dst->bytesperline *
2032
+ q_data_dst->height * 3 / 2;
2033
+ if (q_data_dst->fourcc != V4L2_PIX_FMT_YUV420)
2034
+ q_data_dst->fourcc = V4L2_PIX_FMT_NV12;
2035
+ } else {
2036
+ q_data_dst->sizeimage =
2037
+ q_data_dst->bytesperline *
2038
+ q_data_dst->height * 2;
2039
+ q_data_dst->fourcc = V4L2_PIX_FMT_YUV422P;
2040
+ }
2041
+ q_data_dst->rect.left = 0;
2042
+ q_data_dst->rect.top = 0;
2043
+ q_data_dst->rect.width = q_data_src->width;
2044
+ q_data_dst->rect.height = q_data_src->height;
2045
+ }
16182046 ctx->streamon_out = 1;
16192047 } else {
16202048 ctx->streamon_cap = 1;
....@@ -1641,14 +2069,6 @@
16412069 v4l2_m2m_set_src_buffered(ctx->fh.m2m_ctx, true);
16422070
16432071 ctx->gopcounter = ctx->params.gop_size - 1;
1644
-
1645
- ctx->codec = coda_find_codec(ctx->dev, q_data_src->fourcc,
1646
- q_data_dst->fourcc);
1647
- if (!ctx->codec) {
1648
- v4l2_err(v4l2_dev, "couldn't tell instance type.\n");
1649
- ret = -EINVAL;
1650
- goto err;
1651
- }
16522072
16532073 if (q_data_dst->fourcc == V4L2_PIX_FMT_JPEG)
16542074 ctx->params.gop_size = 1;
....@@ -1691,14 +2111,13 @@
16912111 struct coda_ctx *ctx = vb2_get_drv_priv(q);
16922112 struct coda_dev *dev = ctx->dev;
16932113 struct vb2_v4l2_buffer *buf;
1694
- unsigned long flags;
16952114 bool stop;
16962115
16972116 stop = ctx->streamon_out && ctx->streamon_cap;
16982117
2118
+ coda_dbg(1, ctx, "stop streaming %s\n", v4l2_type_names[q->type]);
2119
+
16992120 if (q->type == V4L2_BUF_TYPE_VIDEO_OUTPUT) {
1700
- v4l2_dbg(1, coda_debug, &dev->v4l2_dev,
1701
- "%s: output\n", __func__);
17022121 ctx->streamon_out = 0;
17032122
17042123 coda_bit_stream_end_flag(ctx);
....@@ -1708,8 +2127,6 @@
17082127 while ((buf = v4l2_m2m_src_buf_remove(ctx->fh.m2m_ctx)))
17092128 v4l2_m2m_buf_done(buf, VB2_BUF_STATE_ERROR);
17102129 } else {
1711
- v4l2_dbg(1, coda_debug, &dev->v4l2_dev,
1712
- "%s: capture\n", __func__);
17132130 ctx->streamon_cap = 0;
17142131
17152132 ctx->osequence = 0;
....@@ -1726,7 +2143,7 @@
17262143 queue_work(dev->workqueue, &ctx->seq_end_work);
17272144 flush_work(&ctx->seq_end_work);
17282145 }
1729
- spin_lock_irqsave(&ctx->buffer_meta_lock, flags);
2146
+ spin_lock(&ctx->buffer_meta_lock);
17302147 while (!list_empty(&ctx->buffer_meta_list)) {
17312148 meta = list_first_entry(&ctx->buffer_meta_list,
17322149 struct coda_buffer_meta, list);
....@@ -1734,7 +2151,7 @@
17342151 kfree(meta);
17352152 }
17362153 ctx->num_metas = 0;
1737
- spin_unlock_irqrestore(&ctx->buffer_meta_lock, flags);
2154
+ spin_unlock(&ctx->buffer_meta_lock);
17382155 kfifo_init(&ctx->bitstream_fifo,
17392156 ctx->bitstream.vaddr, ctx->bitstream.size);
17402157 ctx->runcounter = 0;
....@@ -1758,11 +2175,16 @@
17582175
17592176 static int coda_s_ctrl(struct v4l2_ctrl *ctrl)
17602177 {
2178
+ const char * const *val_names = v4l2_ctrl_get_menu(ctrl->id);
17612179 struct coda_ctx *ctx =
17622180 container_of(ctrl->handler, struct coda_ctx, ctrls);
17632181
1764
- v4l2_dbg(1, coda_debug, &ctx->dev->v4l2_dev,
1765
- "s_ctrl: id = %d, val = %d\n", ctrl->id, ctrl->val);
2182
+ if (val_names)
2183
+ coda_dbg(2, ctx, "s_ctrl: id = 0x%x, name = \"%s\", val = %d (\"%s\")\n",
2184
+ ctrl->id, ctrl->name, ctrl->val, val_names[ctrl->val]);
2185
+ else
2186
+ coda_dbg(2, ctx, "s_ctrl: id = 0x%x, name = \"%s\", val = %d\n",
2187
+ ctrl->id, ctrl->name, ctrl->val);
17662188
17672189 switch (ctrl->id) {
17682190 case V4L2_CID_HFLIP:
....@@ -1779,12 +2201,14 @@
17792201 break;
17802202 case V4L2_CID_MPEG_VIDEO_BITRATE:
17812203 ctx->params.bitrate = ctrl->val / 1000;
2204
+ ctx->params.bitrate_changed = true;
17822205 break;
17832206 case V4L2_CID_MPEG_VIDEO_GOP_SIZE:
17842207 ctx->params.gop_size = ctrl->val;
17852208 break;
17862209 case V4L2_CID_MPEG_VIDEO_H264_I_FRAME_QP:
17872210 ctx->params.h264_intra_qp = ctrl->val;
2211
+ ctx->params.h264_intra_qp_changed = true;
17882212 break;
17892213 case V4L2_CID_MPEG_VIDEO_H264_P_FRAME_QP:
17902214 ctx->params.h264_inter_qp = ctrl->val;
....@@ -1804,6 +2228,18 @@
18042228 case V4L2_CID_MPEG_VIDEO_H264_LOOP_FILTER_MODE:
18052229 ctx->params.h264_disable_deblocking_filter_idc = ctrl->val;
18062230 break;
2231
+ case V4L2_CID_MPEG_VIDEO_H264_CONSTRAINED_INTRA_PREDICTION:
2232
+ ctx->params.h264_constrained_intra_pred_flag = ctrl->val;
2233
+ break;
2234
+ case V4L2_CID_MPEG_VIDEO_FRAME_RC_ENABLE:
2235
+ ctx->params.frame_rc_enable = ctrl->val;
2236
+ break;
2237
+ case V4L2_CID_MPEG_VIDEO_MB_RC_ENABLE:
2238
+ ctx->params.mb_rc_enable = ctrl->val;
2239
+ break;
2240
+ case V4L2_CID_MPEG_VIDEO_H264_CHROMA_QP_INDEX_OFFSET:
2241
+ ctx->params.h264_chroma_qp_index_offset = ctrl->val;
2242
+ break;
18072243 case V4L2_CID_MPEG_VIDEO_H264_PROFILE:
18082244 /* TODO: switch between baseline and constrained baseline */
18092245 if (ctx->inst_type == CODA_INST_ENCODER)
....@@ -1818,23 +2254,29 @@
18182254 case V4L2_CID_MPEG_VIDEO_MPEG4_P_FRAME_QP:
18192255 ctx->params.mpeg4_inter_qp = ctrl->val;
18202256 break;
2257
+ case V4L2_CID_MPEG_VIDEO_MPEG2_PROFILE:
2258
+ case V4L2_CID_MPEG_VIDEO_MPEG2_LEVEL:
18212259 case V4L2_CID_MPEG_VIDEO_MPEG4_PROFILE:
18222260 case V4L2_CID_MPEG_VIDEO_MPEG4_LEVEL:
18232261 /* nothing to do, these are fixed */
18242262 break;
18252263 case V4L2_CID_MPEG_VIDEO_MULTI_SLICE_MODE:
18262264 ctx->params.slice_mode = ctrl->val;
2265
+ ctx->params.slice_mode_changed = true;
18272266 break;
18282267 case V4L2_CID_MPEG_VIDEO_MULTI_SLICE_MAX_MB:
18292268 ctx->params.slice_max_mb = ctrl->val;
2269
+ ctx->params.slice_mode_changed = true;
18302270 break;
18312271 case V4L2_CID_MPEG_VIDEO_MULTI_SLICE_MAX_BYTES:
18322272 ctx->params.slice_max_bits = ctrl->val * 8;
2273
+ ctx->params.slice_mode_changed = true;
18332274 break;
18342275 case V4L2_CID_MPEG_VIDEO_HEADER_MODE:
18352276 break;
18362277 case V4L2_CID_MPEG_VIDEO_CYCLIC_INTRA_REFRESH_MB:
18372278 ctx->params.intra_refresh = ctrl->val;
2279
+ ctx->params.intra_refresh_changed = true;
18382280 break;
18392281 case V4L2_CID_MPEG_VIDEO_FORCE_KEY_FRAME:
18402282 ctx->params.force_ipicture = true;
....@@ -1852,9 +2294,8 @@
18522294 ctx->params.vbv_size = min(ctrl->val * 8192, 0x7fffffff);
18532295 break;
18542296 default:
1855
- v4l2_dbg(1, coda_debug, &ctx->dev->v4l2_dev,
1856
- "Invalid control, id=%d, val=%d\n",
1857
- ctrl->id, ctrl->val);
2297
+ coda_dbg(1, ctx, "Invalid control, id=%d, val=%d\n",
2298
+ ctrl->id, ctrl->val);
18582299 return -EINVAL;
18592300 }
18602301
....@@ -1891,10 +2332,19 @@
18912332 V4L2_CID_MPEG_VIDEO_H264_LOOP_FILTER_MODE,
18922333 V4L2_MPEG_VIDEO_H264_LOOP_FILTER_MODE_DISABLED_AT_SLICE_BOUNDARY,
18932334 0x0, V4L2_MPEG_VIDEO_H264_LOOP_FILTER_MODE_ENABLED);
2335
+ v4l2_ctrl_new_std(&ctx->ctrls, &coda_ctrl_ops,
2336
+ V4L2_CID_MPEG_VIDEO_H264_CONSTRAINED_INTRA_PREDICTION, 0, 1, 1,
2337
+ 0);
2338
+ v4l2_ctrl_new_std(&ctx->ctrls, &coda_ctrl_ops,
2339
+ V4L2_CID_MPEG_VIDEO_FRAME_RC_ENABLE, 0, 1, 1, 1);
2340
+ v4l2_ctrl_new_std(&ctx->ctrls, &coda_ctrl_ops,
2341
+ V4L2_CID_MPEG_VIDEO_MB_RC_ENABLE, 0, 1, 1, 1);
2342
+ v4l2_ctrl_new_std(&ctx->ctrls, &coda_ctrl_ops,
2343
+ V4L2_CID_MPEG_VIDEO_H264_CHROMA_QP_INDEX_OFFSET, -12, 12, 1, 0);
18942344 v4l2_ctrl_new_std_menu(&ctx->ctrls, &coda_ctrl_ops,
18952345 V4L2_CID_MPEG_VIDEO_H264_PROFILE,
1896
- V4L2_MPEG_VIDEO_H264_PROFILE_BASELINE, 0x0,
1897
- V4L2_MPEG_VIDEO_H264_PROFILE_BASELINE);
2346
+ V4L2_MPEG_VIDEO_H264_PROFILE_CONSTRAINED_BASELINE, 0x0,
2347
+ V4L2_MPEG_VIDEO_H264_PROFILE_CONSTRAINED_BASELINE);
18982348 if (ctx->dev->devtype->product == CODA_HX4 ||
18992349 ctx->dev->devtype->product == CODA_7541) {
19002350 v4l2_ctrl_new_std_menu(&ctx->ctrls, &coda_ctrl_ops,
....@@ -1908,12 +2358,15 @@
19082358 if (ctx->dev->devtype->product == CODA_960) {
19092359 v4l2_ctrl_new_std_menu(&ctx->ctrls, &coda_ctrl_ops,
19102360 V4L2_CID_MPEG_VIDEO_H264_LEVEL,
1911
- V4L2_MPEG_VIDEO_H264_LEVEL_4_0,
1912
- ~((1 << V4L2_MPEG_VIDEO_H264_LEVEL_2_0) |
2361
+ V4L2_MPEG_VIDEO_H264_LEVEL_4_2,
2362
+ ~((1 << V4L2_MPEG_VIDEO_H264_LEVEL_1_0) |
2363
+ (1 << V4L2_MPEG_VIDEO_H264_LEVEL_2_0) |
19132364 (1 << V4L2_MPEG_VIDEO_H264_LEVEL_3_0) |
19142365 (1 << V4L2_MPEG_VIDEO_H264_LEVEL_3_1) |
19152366 (1 << V4L2_MPEG_VIDEO_H264_LEVEL_3_2) |
1916
- (1 << V4L2_MPEG_VIDEO_H264_LEVEL_4_0)),
2367
+ (1 << V4L2_MPEG_VIDEO_H264_LEVEL_4_0) |
2368
+ (1 << V4L2_MPEG_VIDEO_H264_LEVEL_4_1) |
2369
+ (1 << V4L2_MPEG_VIDEO_H264_LEVEL_4_2)),
19172370 V4L2_MPEG_VIDEO_H264_LEVEL_4_0);
19182371 }
19192372 v4l2_ctrl_new_std(&ctx->ctrls, &coda_ctrl_ops,
....@@ -1935,7 +2388,7 @@
19352388 }
19362389 v4l2_ctrl_new_std_menu(&ctx->ctrls, &coda_ctrl_ops,
19372390 V4L2_CID_MPEG_VIDEO_MULTI_SLICE_MODE,
1938
- V4L2_MPEG_VIDEO_MULTI_SICE_MODE_MAX_BYTES, 0x0,
2391
+ V4L2_MPEG_VIDEO_MULTI_SLICE_MODE_MAX_BYTES, 0x0,
19392392 V4L2_MPEG_VIDEO_MULTI_SLICE_MODE_SINGLE);
19402393 v4l2_ctrl_new_std(&ctx->ctrls, &coda_ctrl_ops,
19412394 V4L2_CID_MPEG_VIDEO_MULTI_SLICE_MAX_MB, 1, 0x3fffffff, 1, 1);
....@@ -1970,13 +2423,12 @@
19702423
19712424 static void coda_decode_ctrls(struct coda_ctx *ctx)
19722425 {
1973
- u64 mask;
19742426 u8 max;
19752427
19762428 ctx->h264_profile_ctrl = v4l2_ctrl_new_std_menu(&ctx->ctrls,
19772429 &coda_ctrl_ops, V4L2_CID_MPEG_VIDEO_H264_PROFILE,
19782430 V4L2_MPEG_VIDEO_H264_PROFILE_HIGH,
1979
- ~((1 << V4L2_MPEG_VIDEO_H264_PROFILE_BASELINE) |
2431
+ ~((1 << V4L2_MPEG_VIDEO_H264_PROFILE_CONSTRAINED_BASELINE) |
19802432 (1 << V4L2_MPEG_VIDEO_H264_PROFILE_MAIN) |
19812433 (1 << V4L2_MPEG_VIDEO_H264_PROFILE_HIGH)),
19822434 V4L2_MPEG_VIDEO_H264_PROFILE_HIGH);
....@@ -1984,29 +2436,44 @@
19842436 ctx->h264_profile_ctrl->flags |= V4L2_CTRL_FLAG_READ_ONLY;
19852437
19862438 if (ctx->dev->devtype->product == CODA_HX4 ||
1987
- ctx->dev->devtype->product == CODA_7541) {
2439
+ ctx->dev->devtype->product == CODA_7541)
19882440 max = V4L2_MPEG_VIDEO_H264_LEVEL_4_0;
1989
- mask = ~((1 << V4L2_MPEG_VIDEO_H264_LEVEL_2_0) |
1990
- (1 << V4L2_MPEG_VIDEO_H264_LEVEL_3_0) |
1991
- (1 << V4L2_MPEG_VIDEO_H264_LEVEL_3_1) |
1992
- (1 << V4L2_MPEG_VIDEO_H264_LEVEL_3_2) |
1993
- (1 << V4L2_MPEG_VIDEO_H264_LEVEL_4_0));
1994
- } else if (ctx->dev->devtype->product == CODA_960) {
2441
+ else if (ctx->dev->devtype->product == CODA_960)
19952442 max = V4L2_MPEG_VIDEO_H264_LEVEL_4_1;
1996
- mask = ~((1 << V4L2_MPEG_VIDEO_H264_LEVEL_2_0) |
1997
- (1 << V4L2_MPEG_VIDEO_H264_LEVEL_3_0) |
1998
- (1 << V4L2_MPEG_VIDEO_H264_LEVEL_3_1) |
1999
- (1 << V4L2_MPEG_VIDEO_H264_LEVEL_3_2) |
2000
- (1 << V4L2_MPEG_VIDEO_H264_LEVEL_4_0) |
2001
- (1 << V4L2_MPEG_VIDEO_H264_LEVEL_4_1));
2002
- } else {
2443
+ else
20032444 return;
2004
- }
20052445 ctx->h264_level_ctrl = v4l2_ctrl_new_std_menu(&ctx->ctrls,
2006
- &coda_ctrl_ops, V4L2_CID_MPEG_VIDEO_H264_LEVEL, max, mask,
2007
- max);
2446
+ &coda_ctrl_ops, V4L2_CID_MPEG_VIDEO_H264_LEVEL, max, 0, max);
20082447 if (ctx->h264_level_ctrl)
20092448 ctx->h264_level_ctrl->flags |= V4L2_CTRL_FLAG_READ_ONLY;
2449
+
2450
+ ctx->mpeg2_profile_ctrl = v4l2_ctrl_new_std_menu(&ctx->ctrls,
2451
+ &coda_ctrl_ops, V4L2_CID_MPEG_VIDEO_MPEG2_PROFILE,
2452
+ V4L2_MPEG_VIDEO_MPEG2_PROFILE_HIGH, 0,
2453
+ V4L2_MPEG_VIDEO_MPEG2_PROFILE_HIGH);
2454
+ if (ctx->mpeg2_profile_ctrl)
2455
+ ctx->mpeg2_profile_ctrl->flags |= V4L2_CTRL_FLAG_READ_ONLY;
2456
+
2457
+ ctx->mpeg2_level_ctrl = v4l2_ctrl_new_std_menu(&ctx->ctrls,
2458
+ &coda_ctrl_ops, V4L2_CID_MPEG_VIDEO_MPEG2_LEVEL,
2459
+ V4L2_MPEG_VIDEO_MPEG2_LEVEL_HIGH, 0,
2460
+ V4L2_MPEG_VIDEO_MPEG2_LEVEL_HIGH);
2461
+ if (ctx->mpeg2_level_ctrl)
2462
+ ctx->mpeg2_level_ctrl->flags |= V4L2_CTRL_FLAG_READ_ONLY;
2463
+
2464
+ ctx->mpeg4_profile_ctrl = v4l2_ctrl_new_std_menu(&ctx->ctrls,
2465
+ &coda_ctrl_ops, V4L2_CID_MPEG_VIDEO_MPEG4_PROFILE,
2466
+ V4L2_MPEG_VIDEO_MPEG4_PROFILE_ADVANCED_CODING_EFFICIENCY, 0,
2467
+ V4L2_MPEG_VIDEO_MPEG4_PROFILE_ADVANCED_CODING_EFFICIENCY);
2468
+ if (ctx->mpeg4_profile_ctrl)
2469
+ ctx->mpeg4_profile_ctrl->flags |= V4L2_CTRL_FLAG_READ_ONLY;
2470
+
2471
+ ctx->mpeg4_level_ctrl = v4l2_ctrl_new_std_menu(&ctx->ctrls,
2472
+ &coda_ctrl_ops, V4L2_CID_MPEG_VIDEO_MPEG4_LEVEL,
2473
+ V4L2_MPEG_VIDEO_MPEG4_LEVEL_5, 0,
2474
+ V4L2_MPEG_VIDEO_MPEG4_LEVEL_5);
2475
+ if (ctx->mpeg4_level_ctrl)
2476
+ ctx->mpeg4_level_ctrl->flags |= V4L2_CTRL_FLAG_READ_ONLY;
20102477 }
20112478
20122479 static int coda_ctrls_setup(struct coda_ctx *ctx)
....@@ -2018,11 +2485,17 @@
20182485 v4l2_ctrl_new_std(&ctx->ctrls, &coda_ctrl_ops,
20192486 V4L2_CID_VFLIP, 0, 1, 1, 0);
20202487 if (ctx->inst_type == CODA_INST_ENCODER) {
2488
+ v4l2_ctrl_new_std(&ctx->ctrls, &coda_ctrl_ops,
2489
+ V4L2_CID_MIN_BUFFERS_FOR_OUTPUT,
2490
+ 1, 1, 1, 1);
20212491 if (ctx->cvd->dst_formats[0] == V4L2_PIX_FMT_JPEG)
20222492 coda_jpeg_encode_ctrls(ctx);
20232493 else
20242494 coda_encode_ctrls(ctx);
20252495 } else {
2496
+ v4l2_ctrl_new_std(&ctx->ctrls, &coda_ctrl_ops,
2497
+ V4L2_CID_MIN_BUFFERS_FOR_CAPTURE,
2498
+ 1, 1, 1, 1);
20262499 if (ctx->cvd->src_formats[0] == V4L2_PIX_FMT_H264)
20272500 coda_decode_ctrls(ctx);
20282501 }
....@@ -2057,7 +2530,7 @@
20572530 * queues to have at least one buffer queued.
20582531 */
20592532 vq->min_buffers_needed = 1;
2060
- vq->dev = &ctx->dev->plat_dev->dev;
2533
+ vq->dev = ctx->dev->dev;
20612534
20622535 return vb2_queue_init(vq);
20632536 }
....@@ -2097,6 +2570,7 @@
20972570
20982571 dst_vq->type = V4L2_BUF_TYPE_VIDEO_CAPTURE;
20992572 dst_vq->io_modes = VB2_DMABUF | VB2_MMAP;
2573
+ dst_vq->dma_attrs = DMA_ATTR_NO_KERNEL_MAPPING;
21002574 dst_vq->mem_ops = &vb2_dma_contig_memops;
21012575
21022576 return coda_queue_init(priv, dst_vq);
....@@ -2143,6 +2617,8 @@
21432617 ctx->use_bit = !ctx->cvd->direct;
21442618 init_completion(&ctx->completion);
21452619 INIT_WORK(&ctx->pic_run_work, coda_pic_run_work);
2620
+ if (ctx->ops->seq_init_work)
2621
+ INIT_WORK(&ctx->seq_init_work, ctx->ops->seq_init_work);
21462622 if (ctx->ops->seq_end_work)
21472623 INIT_WORK(&ctx->seq_end_work, ctx->ops->seq_end_work);
21482624 v4l2_fh_init(&ctx->fh, video_devdata(file));
....@@ -2150,6 +2626,9 @@
21502626 v4l2_fh_add(&ctx->fh);
21512627 ctx->dev = dev;
21522628 ctx->idx = idx;
2629
+
2630
+ coda_dbg(1, ctx, "open instance (%p)\n", ctx);
2631
+
21532632 switch (dev->devtype->product) {
21542633 case CODA_960:
21552634 /*
....@@ -2160,7 +2639,7 @@
21602639 */
21612640 if (enable_bwb || ctx->inst_type == CODA_INST_ENCODER)
21622641 ctx->frame_mem_ctrl = CODA9_FRAME_ENABLE_BWB;
2163
- /* fallthrough */
2642
+ fallthrough;
21642643 case CODA_HX4:
21652644 case CODA_7541:
21662645 ctx->reg_idx = 0;
....@@ -2177,7 +2656,7 @@
21772656 ctx->use_vdoa = false;
21782657
21792658 /* Power up and upload firmware if necessary */
2180
- ret = pm_runtime_get_sync(&dev->plat_dev->dev);
2659
+ ret = pm_runtime_get_sync(dev->dev);
21812660 if (ret < 0) {
21822661 v4l2_err(&dev->v4l2_dev, "failed to power up: %d\n", ret);
21832662 goto err_pm_get;
....@@ -2185,7 +2664,7 @@
21852664
21862665 ret = clk_prepare_enable(dev->clk_per);
21872666 if (ret)
2188
- goto err_clk_per;
2667
+ goto err_pm_get;
21892668
21902669 ret = clk_prepare_enable(dev->clk_ahb);
21912670 if (ret)
....@@ -2212,15 +2691,9 @@
22122691
22132692 mutex_init(&ctx->bitstream_mutex);
22142693 mutex_init(&ctx->buffer_mutex);
2694
+ mutex_init(&ctx->wakeup_mutex);
22152695 INIT_LIST_HEAD(&ctx->buffer_meta_list);
22162696 spin_lock_init(&ctx->buffer_meta_lock);
2217
-
2218
- mutex_lock(&dev->dev_mutex);
2219
- list_add(&ctx->list, &dev->instances);
2220
- mutex_unlock(&dev->dev_mutex);
2221
-
2222
- v4l2_dbg(1, coda_debug, &dev->v4l2_dev, "Created instance %d (%p)\n",
2223
- ctx->idx, ctx);
22242697
22252698 return 0;
22262699
....@@ -2230,9 +2703,8 @@
22302703 clk_disable_unprepare(dev->clk_ahb);
22312704 err_clk_ahb:
22322705 clk_disable_unprepare(dev->clk_per);
2233
-err_clk_per:
2234
- pm_runtime_put_sync(&dev->plat_dev->dev);
22352706 err_pm_get:
2707
+ pm_runtime_put_sync(dev->dev);
22362708 v4l2_fh_del(&ctx->fh);
22372709 v4l2_fh_exit(&ctx->fh);
22382710 err_coda_name_init:
....@@ -2247,8 +2719,7 @@
22472719 struct coda_dev *dev = video_drvdata(file);
22482720 struct coda_ctx *ctx = fh_to_ctx(file->private_data);
22492721
2250
- v4l2_dbg(1, coda_debug, &dev->v4l2_dev, "Releasing instance %p\n",
2251
- ctx);
2722
+ coda_dbg(1, ctx, "release instance (%p)\n", ctx);
22522723
22532724 if (ctx->inst_type == CODA_INST_DECODER && ctx->use_bit)
22542725 coda_bit_stream_end_flag(ctx);
....@@ -2265,17 +2736,13 @@
22652736 flush_work(&ctx->seq_end_work);
22662737 }
22672738
2268
- mutex_lock(&dev->dev_mutex);
2269
- list_del(&ctx->list);
2270
- mutex_unlock(&dev->dev_mutex);
2271
-
22722739 if (ctx->dev->devtype->product == CODA_DX6)
22732740 coda_free_aux_buf(dev, &ctx->workbuf);
22742741
22752742 v4l2_ctrl_handler_free(&ctx->ctrls);
22762743 clk_disable_unprepare(dev->clk_ahb);
22772744 clk_disable_unprepare(dev->clk_per);
2278
- pm_runtime_put_sync(&dev->plat_dev->dev);
2745
+ pm_runtime_put_sync(dev->dev);
22792746 v4l2_fh_del(&ctx->fh);
22802747 v4l2_fh_exit(&ctx->fh);
22812748 ida_free(&dev->ida, ctx->idx);
....@@ -2398,17 +2865,21 @@
23982865 static int coda_register_device(struct coda_dev *dev, int i)
23992866 {
24002867 struct video_device *vfd = &dev->vfd[i];
2868
+ enum coda_inst_type type;
2869
+ int ret;
24012870
24022871 if (i >= dev->devtype->num_vdevs)
24032872 return -EINVAL;
2873
+ type = dev->devtype->vdevs[i]->type;
24042874
2405
- strlcpy(vfd->name, dev->devtype->vdevs[i]->name, sizeof(vfd->name));
2875
+ strscpy(vfd->name, dev->devtype->vdevs[i]->name, sizeof(vfd->name));
24062876 vfd->fops = &coda_fops;
24072877 vfd->ioctl_ops = &coda_ioctl_ops;
24082878 vfd->release = video_device_release_empty,
24092879 vfd->lock = &dev->dev_mutex;
24102880 vfd->v4l2_dev = &dev->v4l2_dev;
24112881 vfd->vfl_dir = VFL_DIR_M2M;
2882
+ vfd->device_caps = V4L2_CAP_VIDEO_M2M | V4L2_CAP_STREAMING;
24122883 video_set_drvdata(vfd, dev);
24132884
24142885 /* Not applicable, use the selection API instead */
....@@ -2416,7 +2887,12 @@
24162887 v4l2_disable_ioctl(vfd, VIDIOC_G_CROP);
24172888 v4l2_disable_ioctl(vfd, VIDIOC_S_CROP);
24182889
2419
- return video_register_device(vfd, VFL_TYPE_GRABBER, 0);
2890
+ ret = video_register_device(vfd, VFL_TYPE_VIDEO, 0);
2891
+ if (!ret)
2892
+ v4l2_info(&dev->v4l2_dev, "%s registered as %s\n",
2893
+ type == CODA_INST_ENCODER ? "encoder" : "decoder",
2894
+ video_device_node_name(vfd));
2895
+ return ret;
24202896 }
24212897
24222898 static void coda_copy_firmware(struct coda_dev *dev, const u8 * const buf,
....@@ -2462,18 +2938,16 @@
24622938
24632939 fw = dev->devtype->firmware[dev->firmware];
24642940
2465
- dev_dbg(&dev->plat_dev->dev, "requesting firmware '%s' for %s\n", fw,
2941
+ dev_dbg(dev->dev, "requesting firmware '%s' for %s\n", fw,
24662942 coda_product_name(dev->devtype->product));
24672943
2468
- return request_firmware_nowait(THIS_MODULE, true, fw,
2469
- &dev->plat_dev->dev, GFP_KERNEL, dev,
2470
- coda_fw_callback);
2944
+ return request_firmware_nowait(THIS_MODULE, true, fw, dev->dev,
2945
+ GFP_KERNEL, dev, coda_fw_callback);
24712946 }
24722947
24732948 static void coda_fw_callback(const struct firmware *fw, void *context)
24742949 {
24752950 struct coda_dev *dev = context;
2476
- struct platform_device *pdev = dev->plat_dev;
24772951 int i, ret;
24782952
24792953 if (!fw) {
....@@ -2491,7 +2965,7 @@
24912965 * firmware requests, report that the fallback firmware was
24922966 * found.
24932967 */
2494
- dev_info(&pdev->dev, "Using fallback firmware %s\n",
2968
+ dev_info(dev->dev, "Using fallback firmware %s\n",
24952969 dev->devtype->firmware[dev->firmware]);
24962970 }
24972971
....@@ -2530,10 +3004,7 @@
25303004 }
25313005 }
25323006
2533
- v4l2_info(&dev->v4l2_dev, "codec registered as /dev/video[%d-%d]\n",
2534
- dev->vfd[0].num, dev->vfd[i - 1].num);
2535
-
2536
- pm_runtime_put_sync(&pdev->dev);
3007
+ pm_runtime_put_sync(dev->dev);
25373008 return;
25383009
25393010 rel_vfd:
....@@ -2541,7 +3012,7 @@
25413012 video_unregister_device(&dev->vfd[i]);
25423013 v4l2_m2m_release(dev->m2m_dev);
25433014 put_pm:
2544
- pm_runtime_put_sync(&pdev->dev);
3015
+ pm_runtime_put_sync(dev->dev);
25453016 }
25463017
25473018 enum coda_platform {
....@@ -2656,7 +3127,6 @@
26563127 struct device_node *np = pdev->dev.of_node;
26573128 struct gen_pool *pool;
26583129 struct coda_dev *dev;
2659
- struct resource *res;
26603130 int ret, irq;
26613131
26623132 dev = devm_kzalloc(&pdev->dev, sizeof(*dev), GFP_KERNEL);
....@@ -2672,10 +3142,7 @@
26723142 else
26733143 return -EINVAL;
26743144
2675
- spin_lock_init(&dev->irqlock);
2676
- INIT_LIST_HEAD(&dev->instances);
2677
-
2678
- dev->plat_dev = pdev;
3145
+ dev->dev = &pdev->dev;
26793146 dev->clk_per = devm_clk_get(&pdev->dev, "per");
26803147 if (IS_ERR(dev->clk_per)) {
26813148 dev_err(&pdev->dev, "Could not get per clock\n");
....@@ -2689,8 +3156,7 @@
26893156 }
26903157
26913158 /* Get memory for physical registers */
2692
- res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
2693
- dev->regs_base = devm_ioremap_resource(&pdev->dev, res);
3159
+ dev->regs_base = devm_platform_ioremap_resource(pdev, 0);
26943160 if (IS_ERR(dev->regs_base))
26953161 return PTR_ERR(dev->regs_base);
26963162
....@@ -2698,16 +3164,30 @@
26983164 irq = platform_get_irq_byname(pdev, "bit");
26993165 if (irq < 0)
27003166 irq = platform_get_irq(pdev, 0);
2701
- if (irq < 0) {
2702
- dev_err(&pdev->dev, "failed to get irq resource\n");
3167
+ if (irq < 0)
27033168 return irq;
2704
- }
27053169
2706
- ret = devm_request_threaded_irq(&pdev->dev, irq, NULL, coda_irq_handler,
2707
- IRQF_ONESHOT, dev_name(&pdev->dev), dev);
3170
+ ret = devm_request_irq(&pdev->dev, irq, coda_irq_handler, 0,
3171
+ dev_name(&pdev->dev), dev);
27083172 if (ret < 0) {
27093173 dev_err(&pdev->dev, "failed to request irq: %d\n", ret);
27103174 return ret;
3175
+ }
3176
+
3177
+ /* JPEG IRQ */
3178
+ if (dev->devtype->product == CODA_960) {
3179
+ irq = platform_get_irq_byname(pdev, "jpeg");
3180
+ if (irq < 0)
3181
+ return irq;
3182
+
3183
+ ret = devm_request_threaded_irq(&pdev->dev, irq, NULL,
3184
+ coda9_jpeg_irq_handler,
3185
+ IRQF_ONESHOT, CODA_NAME " jpeg",
3186
+ dev);
3187
+ if (ret < 0) {
3188
+ dev_err(&pdev->dev, "failed to request jpeg irq\n");
3189
+ return ret;
3190
+ }
27113191 }
27123192
27133193 dev->rstc = devm_reset_control_get_optional_exclusive(&pdev->dev,
....@@ -2742,8 +3222,6 @@
27423222 ida_init(&dev->ida);
27433223
27443224 dev->debugfs_root = debugfs_create_dir("coda", NULL);
2745
- if (!dev->debugfs_root)
2746
- dev_warn(&pdev->dev, "failed to create debugfs root\n");
27473225
27483226 /* allocate auxiliary per-device buffers for the BIT processor */
27493227 if (dev->devtype->product == CODA_DX6) {
....@@ -2800,6 +3278,8 @@
28003278 return 0;
28013279
28023280 err_alloc_workqueue:
3281
+ pm_runtime_disable(&pdev->dev);
3282
+ pm_runtime_put_noidle(&pdev->dev);
28033283 destroy_workqueue(dev->workqueue);
28043284 err_v4l2_register:
28053285 v4l2_device_unregister(&dev->v4l2_dev);