hc
2023-12-11 d2ccde1c8e90d38cee87a1b0309ad2827f3fd30d
kernel/drivers/media/platform/m2m-deinterlace.c
....@@ -1,13 +1,9 @@
1
+// SPDX-License-Identifier: GPL-2.0-or-later
12 /*
23 * V4L2 deinterlacing support.
34 *
45 * Copyright (c) 2012 Vista Silicon S.L.
56 * Javier Martin <javier.martin@vista-silicon.com>
6
- *
7
- * This program is free software; you can redistribute it and/or modify
8
- * it under the terms of the GNU General Public License as published by the
9
- * Free Software Foundation; either version 2 of the
10
- * License, or (at your option) any later version
117 */
128
139 #include <linux/module.h>
....@@ -41,7 +37,6 @@
4137 v4l2_dbg(1, debug, &dev->v4l2_dev, "%s: " fmt, __func__, ## arg)
4238
4339 struct deinterlace_fmt {
44
- char *name;
4540 u32 fourcc;
4641 /* Types the format can be used for */
4742 u32 types;
....@@ -49,12 +44,10 @@
4944
5045 static struct deinterlace_fmt formats[] = {
5146 {
52
- .name = "YUV 4:2:0 Planar",
5347 .fourcc = V4L2_PIX_FMT_YUV420,
5448 .types = MEM2MEM_CAPTURE | MEM2MEM_OUTPUT,
5549 },
5650 {
57
- .name = "YUYV 4:2:2",
5851 .fourcc = V4L2_PIX_FMT_YUYV,
5952 .types = MEM2MEM_CAPTURE | MEM2MEM_OUTPUT,
6053 },
....@@ -139,13 +132,13 @@
139132 };
140133
141134 struct deinterlace_ctx {
135
+ struct v4l2_fh fh;
142136 struct deinterlace_dev *dev;
143137
144138 /* Abort requested by m2m */
145139 int aborting;
146140 enum v4l2_colorspace colorspace;
147141 dma_cookie_t cookie;
148
- struct v4l2_m2m_ctx *m2m_ctx;
149142 struct dma_interleaved_template *xt;
150143 };
151144
....@@ -157,9 +150,9 @@
157150 struct deinterlace_ctx *ctx = priv;
158151 struct deinterlace_dev *pcdev = ctx->dev;
159152
160
- if ((v4l2_m2m_num_src_bufs_ready(ctx->m2m_ctx) > 0)
161
- && (v4l2_m2m_num_dst_bufs_ready(ctx->m2m_ctx) > 0)
162
- && (atomic_read(&ctx->dev->busy) == 0)) {
153
+ if (v4l2_m2m_num_src_bufs_ready(ctx->fh.m2m_ctx) > 0 &&
154
+ v4l2_m2m_num_dst_bufs_ready(ctx->fh.m2m_ctx) > 0 &&
155
+ !atomic_read(&ctx->dev->busy)) {
163156 dprintk(pcdev, "Task ready\n");
164157 return 1;
165158 }
....@@ -178,7 +171,7 @@
178171
179172 dprintk(pcdev, "Aborting task\n");
180173
181
- v4l2_m2m_job_finish(pcdev->m2m_dev, ctx->m2m_ctx);
174
+ v4l2_m2m_job_finish(pcdev->m2m_dev, ctx->fh.m2m_ctx);
182175 }
183176
184177 static void dma_callback(void *data)
....@@ -189,8 +182,8 @@
189182
190183 atomic_set(&pcdev->busy, 0);
191184
192
- src_vb = v4l2_m2m_src_buf_remove(curr_ctx->m2m_ctx);
193
- dst_vb = v4l2_m2m_dst_buf_remove(curr_ctx->m2m_ctx);
185
+ src_vb = v4l2_m2m_src_buf_remove(curr_ctx->fh.m2m_ctx);
186
+ dst_vb = v4l2_m2m_dst_buf_remove(curr_ctx->fh.m2m_ctx);
194187
195188 dst_vb->vb2_buf.timestamp = src_vb->vb2_buf.timestamp;
196189 dst_vb->flags &= ~V4L2_BUF_FLAG_TSTAMP_SRC_MASK;
....@@ -201,7 +194,7 @@
201194 v4l2_m2m_buf_done(src_vb, VB2_BUF_STATE_DONE);
202195 v4l2_m2m_buf_done(dst_vb, VB2_BUF_STATE_DONE);
203196
204
- v4l2_m2m_job_finish(pcdev->m2m_dev, curr_ctx->m2m_ctx);
197
+ v4l2_m2m_job_finish(pcdev->m2m_dev, curr_ctx->fh.m2m_ctx);
205198
206199 dprintk(pcdev, "dma transfers completed.\n");
207200 }
....@@ -220,8 +213,8 @@
220213 dma_addr_t p_in, p_out;
221214 enum dma_ctrl_flags flags;
222215
223
- src_buf = v4l2_m2m_next_src_buf(ctx->m2m_ctx);
224
- dst_buf = v4l2_m2m_next_dst_buf(ctx->m2m_ctx);
216
+ src_buf = v4l2_m2m_next_src_buf(ctx->fh.m2m_ctx);
217
+ dst_buf = v4l2_m2m_next_dst_buf(ctx->fh.m2m_ctx);
225218
226219 s_q_data = get_q_data(V4L2_BUF_TYPE_VIDEO_OUTPUT);
227220 s_width = s_q_data->width;
....@@ -438,18 +431,9 @@
438431 static int vidioc_querycap(struct file *file, void *priv,
439432 struct v4l2_capability *cap)
440433 {
441
- strlcpy(cap->driver, MEM2MEM_NAME, sizeof(cap->driver));
442
- strlcpy(cap->card, MEM2MEM_NAME, sizeof(cap->card));
443
- strlcpy(cap->bus_info, MEM2MEM_NAME, sizeof(cap->card));
444
- /*
445
- * This is only a mem-to-mem video device. The capture and output
446
- * device capability flags are left only for backward compatibility
447
- * and are scheduled for removal.
448
- */
449
- cap->device_caps = V4L2_CAP_VIDEO_CAPTURE | V4L2_CAP_VIDEO_OUTPUT |
450
- V4L2_CAP_VIDEO_M2M | V4L2_CAP_STREAMING;
451
- cap->capabilities = cap->device_caps | V4L2_CAP_DEVICE_CAPS;
452
-
434
+ strscpy(cap->driver, MEM2MEM_NAME, sizeof(cap->driver));
435
+ strscpy(cap->card, MEM2MEM_NAME, sizeof(cap->card));
436
+ strscpy(cap->bus_info, MEM2MEM_NAME, sizeof(cap->bus_info));
453437 return 0;
454438 }
455439
....@@ -474,7 +458,6 @@
474458 if (i < NUM_FORMATS) {
475459 /* Format found */
476460 fmt = &formats[i];
477
- strlcpy(f->description, fmt->name, sizeof(f->description));
478461 f->pixelformat = fmt->fourcc;
479462 return 0;
480463 }
....@@ -500,7 +483,7 @@
500483 struct vb2_queue *vq;
501484 struct deinterlace_q_data *q_data;
502485
503
- vq = v4l2_m2m_get_vq(ctx->m2m_ctx, f->type);
486
+ vq = v4l2_m2m_get_vq(ctx->fh.m2m_ctx, f->type);
504487 if (!vq)
505488 return -EINVAL;
506489
....@@ -597,7 +580,7 @@
597580 struct deinterlace_q_data *q_data;
598581 struct vb2_queue *vq;
599582
600
- vq = v4l2_m2m_get_vq(ctx->m2m_ctx, f->type);
583
+ vq = v4l2_m2m_get_vq(ctx->fh.m2m_ctx, f->type);
601584 if (!vq)
602585 return -EINVAL;
603586
....@@ -670,36 +653,6 @@
670653 return ret;
671654 }
672655
673
-static int vidioc_reqbufs(struct file *file, void *priv,
674
- struct v4l2_requestbuffers *reqbufs)
675
-{
676
- struct deinterlace_ctx *ctx = priv;
677
-
678
- return v4l2_m2m_reqbufs(file, ctx->m2m_ctx, reqbufs);
679
-}
680
-
681
-static int vidioc_querybuf(struct file *file, void *priv,
682
- struct v4l2_buffer *buf)
683
-{
684
- struct deinterlace_ctx *ctx = priv;
685
-
686
- return v4l2_m2m_querybuf(file, ctx->m2m_ctx, buf);
687
-}
688
-
689
-static int vidioc_qbuf(struct file *file, void *priv, struct v4l2_buffer *buf)
690
-{
691
- struct deinterlace_ctx *ctx = priv;
692
-
693
- return v4l2_m2m_qbuf(file, ctx->m2m_ctx, buf);
694
-}
695
-
696
-static int vidioc_dqbuf(struct file *file, void *priv, struct v4l2_buffer *buf)
697
-{
698
- struct deinterlace_ctx *ctx = priv;
699
-
700
- return v4l2_m2m_dqbuf(file, ctx->m2m_ctx, buf);
701
-}
702
-
703656 static int vidioc_streamon(struct file *file, void *priv,
704657 enum v4l2_buf_type type)
705658 {
....@@ -740,15 +693,7 @@
740693 return -EINVAL;
741694 }
742695
743
- return v4l2_m2m_streamon(file, ctx->m2m_ctx, type);
744
-}
745
-
746
-static int vidioc_streamoff(struct file *file, void *priv,
747
- enum v4l2_buf_type type)
748
-{
749
- struct deinterlace_ctx *ctx = priv;
750
-
751
- return v4l2_m2m_streamoff(file, ctx->m2m_ctx, type);
696
+ return v4l2_m2m_streamon(file, ctx->fh.m2m_ctx, type);
752697 }
753698
754699 static const struct v4l2_ioctl_ops deinterlace_ioctl_ops = {
....@@ -764,14 +709,15 @@
764709 .vidioc_try_fmt_vid_out = vidioc_try_fmt_vid_out,
765710 .vidioc_s_fmt_vid_out = vidioc_s_fmt_vid_out,
766711
767
- .vidioc_reqbufs = vidioc_reqbufs,
768
- .vidioc_querybuf = vidioc_querybuf,
769
-
770
- .vidioc_qbuf = vidioc_qbuf,
771
- .vidioc_dqbuf = vidioc_dqbuf,
712
+ .vidioc_reqbufs = v4l2_m2m_ioctl_reqbufs,
713
+ .vidioc_querybuf = v4l2_m2m_ioctl_querybuf,
714
+ .vidioc_qbuf = v4l2_m2m_ioctl_qbuf,
715
+ .vidioc_dqbuf = v4l2_m2m_ioctl_dqbuf,
716
+ .vidioc_prepare_buf = v4l2_m2m_ioctl_prepare_buf,
717
+ .vidioc_expbuf = v4l2_m2m_ioctl_expbuf,
772718
773719 .vidioc_streamon = vidioc_streamon,
774
- .vidioc_streamoff = vidioc_streamoff,
720
+ .vidioc_streamoff = v4l2_m2m_ioctl_streamoff,
775721 };
776722
777723
....@@ -835,7 +781,7 @@
835781 struct vb2_v4l2_buffer *vbuf = to_vb2_v4l2_buffer(vb);
836782 struct deinterlace_ctx *ctx = vb2_get_drv_priv(vb->vb2_queue);
837783
838
- v4l2_m2m_buf_queue(ctx->m2m_ctx, vbuf);
784
+ v4l2_m2m_buf_queue(ctx->fh.m2m_ctx, vbuf);
839785 }
840786
841787 static const struct vb2_ops deinterlace_qops = {
....@@ -853,7 +799,7 @@
853799 int ret;
854800
855801 src_vq->type = V4L2_BUF_TYPE_VIDEO_OUTPUT;
856
- src_vq->io_modes = VB2_MMAP | VB2_USERPTR;
802
+ src_vq->io_modes = VB2_MMAP | VB2_USERPTR | VB2_DMABUF;
857803 src_vq->drv_priv = ctx;
858804 src_vq->buf_struct_size = sizeof(struct v4l2_m2m_buffer);
859805 src_vq->ops = &deinterlace_qops;
....@@ -872,7 +818,7 @@
872818 return ret;
873819
874820 dst_vq->type = V4L2_BUF_TYPE_VIDEO_CAPTURE;
875
- dst_vq->io_modes = VB2_MMAP | VB2_USERPTR;
821
+ dst_vq->io_modes = VB2_MMAP | VB2_USERPTR | VB2_DMABUF;
876822 dst_vq->drv_priv = ctx;
877823 dst_vq->buf_struct_size = sizeof(struct v4l2_m2m_buffer);
878824 dst_vq->ops = &deinterlace_qops;
....@@ -901,12 +847,13 @@
901847 if (!ctx)
902848 return -ENOMEM;
903849
904
- file->private_data = ctx;
850
+ v4l2_fh_init(&ctx->fh, video_devdata(file));
851
+ file->private_data = &ctx->fh;
905852 ctx->dev = pcdev;
906853
907
- ctx->m2m_ctx = v4l2_m2m_ctx_init(pcdev->m2m_dev, ctx, &queue_init);
908
- if (IS_ERR(ctx->m2m_ctx)) {
909
- int ret = PTR_ERR(ctx->m2m_ctx);
854
+ ctx->fh.m2m_ctx = v4l2_m2m_ctx_init(pcdev->m2m_dev, ctx, &queue_init);
855
+ if (IS_ERR(ctx->fh.m2m_ctx)) {
856
+ int ret = PTR_ERR(ctx->fh.m2m_ctx);
910857
911858 kfree(ctx);
912859 return ret;
....@@ -920,8 +867,10 @@
920867 }
921868
922869 ctx->colorspace = V4L2_COLORSPACE_REC709;
870
+ v4l2_fh_add(&ctx->fh);
923871
924
- dprintk(pcdev, "Created instance %p, m2m_ctx: %p\n", ctx, ctx->m2m_ctx);
872
+ dprintk(pcdev, "Created instance %p, m2m_ctx: %p\n",
873
+ ctx, ctx->fh.m2m_ctx);
925874
926875 return 0;
927876 }
....@@ -933,40 +882,22 @@
933882
934883 dprintk(pcdev, "Releasing instance %p\n", ctx);
935884
936
- v4l2_m2m_ctx_release(ctx->m2m_ctx);
885
+ v4l2_fh_del(&ctx->fh);
886
+ v4l2_fh_exit(&ctx->fh);
887
+ v4l2_m2m_ctx_release(ctx->fh.m2m_ctx);
937888 kfree(ctx->xt);
938889 kfree(ctx);
939890
940891 return 0;
941892 }
942893
943
-static __poll_t deinterlace_poll(struct file *file,
944
- struct poll_table_struct *wait)
945
-{
946
- struct deinterlace_ctx *ctx = file->private_data;
947
- __poll_t ret;
948
-
949
- mutex_lock(&ctx->dev->dev_mutex);
950
- ret = v4l2_m2m_poll(file, ctx->m2m_ctx, wait);
951
- mutex_unlock(&ctx->dev->dev_mutex);
952
-
953
- return ret;
954
-}
955
-
956
-static int deinterlace_mmap(struct file *file, struct vm_area_struct *vma)
957
-{
958
- struct deinterlace_ctx *ctx = file->private_data;
959
-
960
- return v4l2_m2m_mmap(file, ctx->m2m_ctx, vma);
961
-}
962
-
963894 static const struct v4l2_file_operations deinterlace_fops = {
964895 .owner = THIS_MODULE,
965896 .open = deinterlace_open,
966897 .release = deinterlace_release,
967
- .poll = deinterlace_poll,
898
+ .poll = v4l2_m2m_fop_poll,
968899 .unlocked_ioctl = video_ioctl2,
969
- .mmap = deinterlace_mmap,
900
+ .mmap = v4l2_m2m_fop_mmap,
970901 };
971902
972903 static const struct video_device deinterlace_videodev = {
....@@ -976,6 +907,7 @@
976907 .minor = -1,
977908 .release = video_device_release_empty,
978909 .vfl_dir = VFL_DIR_M2M,
910
+ .device_caps = V4L2_CAP_VIDEO_M2M | V4L2_CAP_STREAMING,
979911 };
980912
981913 static const struct v4l2_m2m_ops m2m_ops = {
....@@ -1021,7 +953,7 @@
1021953 vfd->lock = &pcdev->dev_mutex;
1022954 vfd->v4l2_dev = &pcdev->v4l2_dev;
1023955
1024
- ret = video_register_device(vfd, VFL_TYPE_GRABBER, 0);
956
+ ret = video_register_device(vfd, VFL_TYPE_VIDEO, 0);
1025957 if (ret) {
1026958 v4l2_err(&pcdev->v4l2_dev, "Failed to register video device\n");
1027959 goto unreg_dev;