forked from ~ljy/RK356X_SDK_RELEASE

hc
2024-10-22 8ac6c7a54ed1b98d142dce24b11c6de6a1e239a5
kernel/drivers/media/usb/au0828/au0828-video.c
....@@ -1,18 +1,9 @@
1
+// SPDX-License-Identifier: GPL-2.0-or-later
12 /*
23 * Auvitek AU0828 USB Bridge (Analog video support)
34 *
45 * Copyright (C) 2009 Devin Heitmueller <dheitmueller@linuxtv.org>
56 * Copyright (C) 2005-2008 Auvitek International, Ltd.
6
- *
7
- * This program is free software; you can redistribute it and/or
8
- * modify it under the terms of the GNU General Public License
9
- * As published by the Free Software Foundation; either version 2
10
- * of the License, or (at your option) any later version.
11
- *
12
- * This program is distributed in the hope that it will be useful,
13
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
14
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15
- * GNU General Public License for more details.
167 */
178
189 /* Developer Notes:
....@@ -947,8 +938,8 @@
947938 return 0;
948939
949940 mutex_lock(&au0828_sysfs_lock);
950
- video_unregister_device(&dev->vdev);
951
- video_unregister_device(&dev->vbi_dev);
941
+ vb2_video_unregister_device(&dev->vdev);
942
+ vb2_video_unregister_device(&dev->vbi_dev);
952943 mutex_unlock(&au0828_sysfs_lock);
953944
954945 v4l2_device_disconnect(&dev->v4l2_dev);
....@@ -1051,7 +1042,7 @@
10511042 dev->streaming_users, dev->users);
10521043
10531044 mutex_lock(&dev->lock);
1054
- if (vdev->vfl_type == VFL_TYPE_GRABBER && dev->vid_timeout_running) {
1045
+ if (vdev->vfl_type == VFL_TYPE_VIDEO && dev->vid_timeout_running) {
10551046 /* Cancel timeout thread in case they didn't call streamoff */
10561047 dev->vid_timeout_running = 0;
10571048 del_timer_sync(&dev->vid_timeout);
....@@ -1071,7 +1062,7 @@
10711062 * streaming.
10721063 *
10731064 * On most USB devices like au0828 the tuner can
1074
- * be safely put in sleep stare here if ALSA isn't
1065
+ * be safely put in sleep state here if ALSA isn't
10751066 * streaming. Exceptions are some very old USB tuner
10761067 * models such as em28xx-based WinTV USB2 which have
10771068 * a separate audio output jack. The devices that have
....@@ -1080,7 +1071,7 @@
10801071 * so the s_power callback are silently ignored.
10811072 * So, the current logic here does the following:
10821073 * Disable (put tuner to sleep) when
1083
- * - ALSA and DVB aren't not streaming;
1074
+ * - ALSA and DVB aren't streaming.
10841075 * - the last V4L2 file handler is closed.
10851076 *
10861077 * FIXME:
....@@ -1162,7 +1153,6 @@
11621153 format->fmt.pix.sizeimage = width * height * 2;
11631154 format->fmt.pix.colorspace = V4L2_COLORSPACE_SMPTE170M;
11641155 format->fmt.pix.field = V4L2_FIELD_INTERLACED;
1165
- format->fmt.pix.priv = 0;
11661156
11671157 if (cmd == VIDIOC_TRY_FMT)
11681158 return 0;
....@@ -1191,27 +1181,20 @@
11911181 static int vidioc_querycap(struct file *file, void *priv,
11921182 struct v4l2_capability *cap)
11931183 {
1194
- struct video_device *vdev = video_devdata(file);
11951184 struct au0828_dev *dev = video_drvdata(file);
11961185
11971186 dprintk(1, "%s called std_set %d dev_state %ld\n", __func__,
11981187 dev->std_set_in_tuner_core, dev->dev_state);
11991188
1200
- strlcpy(cap->driver, "au0828", sizeof(cap->driver));
1201
- strlcpy(cap->card, dev->board.name, sizeof(cap->card));
1189
+ strscpy(cap->driver, "au0828", sizeof(cap->driver));
1190
+ strscpy(cap->card, dev->board.name, sizeof(cap->card));
12021191 usb_make_path(dev->usbdev, cap->bus_info, sizeof(cap->bus_info));
12031192
12041193 /* set the device capabilities */
1205
- cap->device_caps = V4L2_CAP_AUDIO |
1206
- V4L2_CAP_READWRITE |
1207
- V4L2_CAP_STREAMING |
1208
- V4L2_CAP_TUNER;
1209
- if (vdev->vfl_type == VFL_TYPE_GRABBER)
1210
- cap->device_caps |= V4L2_CAP_VIDEO_CAPTURE;
1211
- else
1212
- cap->device_caps |= V4L2_CAP_VBI_CAPTURE;
1213
- cap->capabilities = cap->device_caps | V4L2_CAP_DEVICE_CAPS |
1214
- V4L2_CAP_VBI_CAPTURE | V4L2_CAP_VIDEO_CAPTURE;
1194
+ cap->capabilities =
1195
+ V4L2_CAP_AUDIO | V4L2_CAP_READWRITE | V4L2_CAP_STREAMING |
1196
+ V4L2_CAP_TUNER | V4L2_CAP_VBI_CAPTURE | V4L2_CAP_VIDEO_CAPTURE |
1197
+ V4L2_CAP_DEVICE_CAPS;
12151198 return 0;
12161199 }
12171200
....@@ -1223,10 +1206,6 @@
12231206
12241207 dprintk(1, "%s called\n", __func__);
12251208
1226
- f->type = V4L2_BUF_TYPE_VIDEO_CAPTURE;
1227
- strcpy(f->description, "Packed YUV2");
1228
-
1229
- f->flags = 0;
12301209 f->pixelformat = V4L2_PIX_FMT_UYVY;
12311210
12321211 return 0;
....@@ -1247,7 +1226,6 @@
12471226 f->fmt.pix.sizeimage = dev->frame_size;
12481227 f->fmt.pix.colorspace = V4L2_COLORSPACE_SMPTE170M; /* NTSC/PAL */
12491228 f->fmt.pix.field = V4L2_FIELD_INTERLACED;
1250
- f->fmt.pix.priv = 0;
12511229 return 0;
12521230 }
12531231
....@@ -1355,7 +1333,7 @@
13551333 return -EINVAL;
13561334
13571335 input->index = tmp;
1358
- strcpy(input->name, inames[AUVI_INPUT(tmp).type]);
1336
+ strscpy(input->name, inames[AUVI_INPUT(tmp).type], sizeof(input->name));
13591337 if ((AUVI_INPUT(tmp).type == AU0828_VMUX_TELEVISION) ||
13601338 (AUVI_INPUT(tmp).type == AU0828_VMUX_CABLE)) {
13611339 input->type |= V4L2_INPUT_TYPE_TUNER;
....@@ -1471,9 +1449,9 @@
14711449 dprintk(1, "%s called\n", __func__);
14721450
14731451 if (a->index == 0)
1474
- strcpy(a->name, "Television");
1452
+ strscpy(a->name, "Television", sizeof(a->name));
14751453 else
1476
- strcpy(a->name, "Line in");
1454
+ strscpy(a->name, "Line in", sizeof(a->name));
14771455
14781456 a->capability = V4L2_AUDCAP_STEREO;
14791457 return 0;
....@@ -1488,9 +1466,9 @@
14881466
14891467 a->index = dev->ctrl_ainput;
14901468 if (a->index == 0)
1491
- strcpy(a->name, "Television");
1469
+ strscpy(a->name, "Television", sizeof(a->name));
14921470 else
1493
- strcpy(a->name, "Line in");
1471
+ strscpy(a->name, "Line in", sizeof(a->name));
14941472
14951473 a->capability = V4L2_AUDCAP_STEREO;
14961474 return 0;
....@@ -1524,7 +1502,7 @@
15241502 dprintk(1, "%s called std_set %d dev_state %ld\n", __func__,
15251503 dev->std_set_in_tuner_core, dev->dev_state);
15261504
1527
- strcpy(t->name, "Auvitek tuner");
1505
+ strscpy(t->name, "Auvitek tuner", sizeof(t->name));
15281506
15291507 au0828_init_tuner(dev);
15301508 i2c_gate_ctrl(dev, 1);
....@@ -1622,27 +1600,42 @@
16221600 return 0;
16231601 }
16241602
1625
-static int vidioc_cropcap(struct file *file, void *priv,
1626
- struct v4l2_cropcap *cc)
1603
+static int vidioc_g_pixelaspect(struct file *file, void *priv,
1604
+ int type, struct v4l2_fract *f)
16271605 {
16281606 struct au0828_dev *dev = video_drvdata(file);
16291607
1630
- if (cc->type != V4L2_BUF_TYPE_VIDEO_CAPTURE)
1608
+ if (type != V4L2_BUF_TYPE_VIDEO_CAPTURE)
16311609 return -EINVAL;
16321610
16331611 dprintk(1, "%s called std_set %d dev_state %ld\n", __func__,
16341612 dev->std_set_in_tuner_core, dev->dev_state);
16351613
1636
- cc->bounds.left = 0;
1637
- cc->bounds.top = 0;
1638
- cc->bounds.width = dev->width;
1639
- cc->bounds.height = dev->height;
1614
+ f->numerator = 54;
1615
+ f->denominator = 59;
16401616
1641
- cc->defrect = cc->bounds;
1617
+ return 0;
1618
+}
16421619
1643
- cc->pixelaspect.numerator = 54;
1644
- cc->pixelaspect.denominator = 59;
1620
+static int vidioc_g_selection(struct file *file, void *priv,
1621
+ struct v4l2_selection *s)
1622
+{
1623
+ struct au0828_dev *dev = video_drvdata(file);
16451624
1625
+ if (s->type != V4L2_BUF_TYPE_VIDEO_CAPTURE)
1626
+ return -EINVAL;
1627
+
1628
+ switch (s->target) {
1629
+ case V4L2_SEL_TGT_CROP_BOUNDS:
1630
+ case V4L2_SEL_TGT_CROP_DEFAULT:
1631
+ s->r.left = 0;
1632
+ s->r.top = 0;
1633
+ s->r.width = dev->width;
1634
+ s->r.height = dev->height;
1635
+ break;
1636
+ default:
1637
+ return -EINVAL;
1638
+ }
16461639 return 0;
16471640 }
16481641
....@@ -1768,7 +1761,8 @@
17681761 .vidioc_enumaudio = vidioc_enumaudio,
17691762 .vidioc_g_audio = vidioc_g_audio,
17701763 .vidioc_s_audio = vidioc_s_audio,
1771
- .vidioc_cropcap = vidioc_cropcap,
1764
+ .vidioc_g_pixelaspect = vidioc_g_pixelaspect,
1765
+ .vidioc_g_selection = vidioc_g_selection,
17721766
17731767 .vidioc_reqbufs = vb2_ioctl_reqbufs,
17741768 .vidioc_create_bufs = vb2_ioctl_create_bufs,
....@@ -1984,7 +1978,10 @@
19841978 dev->vdev.lock = &dev->lock;
19851979 dev->vdev.queue = &dev->vb_vidq;
19861980 dev->vdev.queue->lock = &dev->vb_queue_lock;
1987
- strcpy(dev->vdev.name, "au0828a video");
1981
+ dev->vdev.device_caps =
1982
+ V4L2_CAP_AUDIO | V4L2_CAP_READWRITE | V4L2_CAP_STREAMING |
1983
+ V4L2_CAP_TUNER | V4L2_CAP_VIDEO_CAPTURE;
1984
+ strscpy(dev->vdev.name, "au0828a video", sizeof(dev->vdev.name));
19881985
19891986 /* Setup the VBI device */
19901987 dev->vbi_dev = au0828_video_template;
....@@ -1992,7 +1989,10 @@
19921989 dev->vbi_dev.lock = &dev->lock;
19931990 dev->vbi_dev.queue = &dev->vb_vbiq;
19941991 dev->vbi_dev.queue->lock = &dev->vb_vbi_queue_lock;
1995
- strcpy(dev->vbi_dev.name, "au0828a vbi");
1992
+ dev->vbi_dev.device_caps =
1993
+ V4L2_CAP_AUDIO | V4L2_CAP_READWRITE | V4L2_CAP_STREAMING |
1994
+ V4L2_CAP_TUNER | V4L2_CAP_VBI_CAPTURE;
1995
+ strscpy(dev->vbi_dev.name, "au0828a vbi", sizeof(dev->vbi_dev.name));
19961996
19971997 /* Init entities at the Media Controller */
19981998 au0828_analog_create_entities(dev);
....@@ -2007,12 +2007,11 @@
20072007
20082008 /* Register the v4l2 device */
20092009 video_set_drvdata(&dev->vdev, dev);
2010
- retval = video_register_device(&dev->vdev, VFL_TYPE_GRABBER, -1);
2010
+ retval = video_register_device(&dev->vdev, VFL_TYPE_VIDEO, -1);
20112011 if (retval != 0) {
20122012 dprintk(1, "unable to register video device (error = %d).\n",
20132013 retval);
2014
- ret = -ENODEV;
2015
- goto err_reg_vdev;
2014
+ return -ENODEV;
20162015 }
20172016
20182017 /* Register the vbi device */
....@@ -2040,10 +2039,7 @@
20402039 return 0;
20412040
20422041 err_reg_vbi_dev:
2043
- video_unregister_device(&dev->vdev);
2044
-err_reg_vdev:
2045
- vb2_queue_release(&dev->vb_vidq);
2046
- vb2_queue_release(&dev->vb_vbiq);
2042
+ vb2_video_unregister_device(&dev->vdev);
20472043 return ret;
20482044 }
20492045