forked from ~ljy/RK356X_SDK_RELEASE

hc
2024-12-19 9370bb92b2d16684ee45cf24e879c93c509162da
kernel/drivers/media/pci/cobalt/cobalt-v4l2.c
....@@ -375,7 +375,7 @@
375375 }
376376 spin_unlock_irqrestore(&s->irqlock, flags);
377377
378
- /* Wait 100 milisecond for DMA to finish, abort on timeout. */
378
+ /* Wait 100 millisecond for DMA to finish, abort on timeout. */
379379 if (!wait_event_timeout(s->q.done_wq, is_dma_done(s),
380380 msecs_to_jiffies(timeout_msec))) {
381381 omni_sg_dma_abort_channel(s);
....@@ -479,17 +479,12 @@
479479 struct cobalt_stream *s = video_drvdata(file);
480480 struct cobalt *cobalt = s->cobalt;
481481
482
- strlcpy(vcap->driver, "cobalt", sizeof(vcap->driver));
483
- strlcpy(vcap->card, "cobalt", sizeof(vcap->card));
482
+ strscpy(vcap->driver, "cobalt", sizeof(vcap->driver));
483
+ strscpy(vcap->card, "cobalt", sizeof(vcap->card));
484484 snprintf(vcap->bus_info, sizeof(vcap->bus_info),
485485 "PCIe:%s", pci_name(cobalt->pci_dev));
486
- vcap->device_caps = V4L2_CAP_STREAMING | V4L2_CAP_READWRITE;
487
- if (s->is_output)
488
- vcap->device_caps |= V4L2_CAP_VIDEO_OUTPUT;
489
- else
490
- vcap->device_caps |= V4L2_CAP_VIDEO_CAPTURE;
491
- vcap->capabilities = vcap->device_caps | V4L2_CAP_DEVICE_CAPS |
492
- V4L2_CAP_VIDEO_CAPTURE;
486
+ vcap->capabilities = V4L2_CAP_STREAMING | V4L2_CAP_READWRITE |
487
+ V4L2_CAP_VIDEO_CAPTURE | V4L2_CAP_DEVICE_CAPS;
493488 if (cobalt->have_hsma_tx)
494489 vcap->capabilities |= V4L2_CAP_VIDEO_OUTPUT;
495490 return 0;
....@@ -693,15 +688,12 @@
693688 {
694689 switch (f->index) {
695690 case 0:
696
- strlcpy(f->description, "YUV 4:2:2", sizeof(f->description));
697691 f->pixelformat = V4L2_PIX_FMT_YUYV;
698692 break;
699693 case 1:
700
- strlcpy(f->description, "RGB24", sizeof(f->description));
701694 f->pixelformat = V4L2_PIX_FMT_RGB24;
702695 break;
703696 case 2:
704
- strlcpy(f->description, "RGB32", sizeof(f->description));
705697 f->pixelformat = V4L2_PIX_FMT_BGR32;
706698 break;
707699 default:
....@@ -793,7 +785,6 @@
793785
794786 pix->sizeimage = pix->bytesperline * pix->height;
795787 pix->field = V4L2_FIELD_NONE;
796
- pix->priv = 0;
797788
798789 return 0;
799790 }
....@@ -898,11 +889,9 @@
898889 {
899890 switch (f->index) {
900891 case 0:
901
- strlcpy(f->description, "YUV 4:2:2", sizeof(f->description));
902892 f->pixelformat = V4L2_PIX_FMT_YUYV;
903893 break;
904894 case 1:
905
- strlcpy(f->description, "RGB32", sizeof(f->description));
906895 f->pixelformat = V4L2_PIX_FMT_BGR32;
907896 break;
908897 default:
....@@ -1064,32 +1053,68 @@
10641053
10651054 static int cobalt_g_parm(struct file *file, void *fh, struct v4l2_streamparm *a)
10661055 {
1056
+ struct cobalt_stream *s = video_drvdata(file);
1057
+ struct v4l2_fract fps;
1058
+
10671059 if (a->type != V4L2_BUF_TYPE_VIDEO_CAPTURE)
10681060 return -EINVAL;
1069
- a->parm.capture.timeperframe.numerator = 1;
1070
- a->parm.capture.timeperframe.denominator = 60;
1061
+
1062
+ fps = v4l2_calc_timeperframe(&s->timings);
1063
+ a->parm.capture.timeperframe.numerator = fps.numerator;
1064
+ a->parm.capture.timeperframe.denominator = fps.denominator;
10711065 a->parm.capture.readbuffers = 3;
10721066 return 0;
10731067 }
10741068
1075
-static int cobalt_cropcap(struct file *file, void *fh, struct v4l2_cropcap *cc)
1069
+static int cobalt_g_pixelaspect(struct file *file, void *fh,
1070
+ int type, struct v4l2_fract *f)
10761071 {
10771072 struct cobalt_stream *s = video_drvdata(file);
10781073 struct v4l2_dv_timings timings;
10791074 int err = 0;
10801075
1081
- if (cc->type != V4L2_BUF_TYPE_VIDEO_CAPTURE)
1076
+ if (type != V4L2_BUF_TYPE_VIDEO_CAPTURE)
10821077 return -EINVAL;
1078
+
10831079 if (s->input == 1)
10841080 timings = cea1080p60;
10851081 else
10861082 err = v4l2_subdev_call(s->sd, video, g_dv_timings, &timings);
1087
- if (!err) {
1088
- cc->bounds.width = cc->defrect.width = timings.bt.width;
1089
- cc->bounds.height = cc->defrect.height = timings.bt.height;
1090
- cc->pixelaspect = v4l2_dv_timings_aspect_ratio(&timings);
1091
- }
1083
+ if (!err)
1084
+ *f = v4l2_dv_timings_aspect_ratio(&timings);
10921085 return err;
1086
+}
1087
+
1088
+static int cobalt_g_selection(struct file *file, void *fh,
1089
+ struct v4l2_selection *sel)
1090
+{
1091
+ struct cobalt_stream *s = video_drvdata(file);
1092
+ struct v4l2_dv_timings timings;
1093
+ int err = 0;
1094
+
1095
+ if (sel->type != V4L2_BUF_TYPE_VIDEO_CAPTURE)
1096
+ return -EINVAL;
1097
+
1098
+ if (s->input == 1)
1099
+ timings = cea1080p60;
1100
+ else
1101
+ err = v4l2_subdev_call(s->sd, video, g_dv_timings, &timings);
1102
+
1103
+ if (err)
1104
+ return err;
1105
+
1106
+ switch (sel->target) {
1107
+ case V4L2_SEL_TGT_CROP_BOUNDS:
1108
+ case V4L2_SEL_TGT_CROP_DEFAULT:
1109
+ sel->r.top = 0;
1110
+ sel->r.left = 0;
1111
+ sel->r.width = timings.bt.width;
1112
+ sel->r.height = timings.bt.height;
1113
+ break;
1114
+ default:
1115
+ return -EINVAL;
1116
+ }
1117
+ return 0;
10931118 }
10941119
10951120 static const struct v4l2_ioctl_ops cobalt_ioctl_ops = {
....@@ -1098,7 +1123,8 @@
10981123 .vidioc_log_status = cobalt_log_status,
10991124 .vidioc_streamon = vb2_ioctl_streamon,
11001125 .vidioc_streamoff = vb2_ioctl_streamoff,
1101
- .vidioc_cropcap = cobalt_cropcap,
1126
+ .vidioc_g_pixelaspect = cobalt_g_pixelaspect,
1127
+ .vidioc_g_selection = cobalt_g_selection,
11021128 .vidioc_enum_input = cobalt_enum_input,
11031129 .vidioc_g_input = cobalt_g_input,
11041130 .vidioc_s_input = cobalt_s_input,
....@@ -1237,11 +1263,16 @@
12371263 q->lock = &s->lock;
12381264 q->dev = &cobalt->pci_dev->dev;
12391265 vdev->queue = q;
1266
+ vdev->device_caps = V4L2_CAP_STREAMING | V4L2_CAP_READWRITE;
1267
+ if (s->is_output)
1268
+ vdev->device_caps |= V4L2_CAP_VIDEO_OUTPUT;
1269
+ else
1270
+ vdev->device_caps |= V4L2_CAP_VIDEO_CAPTURE;
12401271
12411272 video_set_drvdata(vdev, s);
12421273 ret = vb2_queue_init(q);
12431274 if (!s->is_audio && ret == 0)
1244
- ret = video_register_device(vdev, VFL_TYPE_GRABBER, -1);
1275
+ ret = video_register_device(vdev, VFL_TYPE_VIDEO, -1);
12451276 else if (!s->is_dummy)
12461277 ret = cobalt_alsa_init(s);
12471278