| .. | .. |
|---|
| 1 | +// SPDX-License-Identifier: GPL-2.0-or-later |
|---|
| 1 | 2 | /* |
|---|
| 2 | 3 | * Auvitek AU0828 USB Bridge (Analog video support) |
|---|
| 3 | 4 | * |
|---|
| 4 | 5 | * Copyright (C) 2009 Devin Heitmueller <dheitmueller@linuxtv.org> |
|---|
| 5 | 6 | * 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. |
|---|
| 16 | 7 | */ |
|---|
| 17 | 8 | |
|---|
| 18 | 9 | /* Developer Notes: |
|---|
| .. | .. |
|---|
| 947 | 938 | return 0; |
|---|
| 948 | 939 | |
|---|
| 949 | 940 | 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); |
|---|
| 952 | 943 | mutex_unlock(&au0828_sysfs_lock); |
|---|
| 953 | 944 | |
|---|
| 954 | 945 | v4l2_device_disconnect(&dev->v4l2_dev); |
|---|
| .. | .. |
|---|
| 1051 | 1042 | dev->streaming_users, dev->users); |
|---|
| 1052 | 1043 | |
|---|
| 1053 | 1044 | 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) { |
|---|
| 1055 | 1046 | /* Cancel timeout thread in case they didn't call streamoff */ |
|---|
| 1056 | 1047 | dev->vid_timeout_running = 0; |
|---|
| 1057 | 1048 | del_timer_sync(&dev->vid_timeout); |
|---|
| .. | .. |
|---|
| 1071 | 1062 | * streaming. |
|---|
| 1072 | 1063 | * |
|---|
| 1073 | 1064 | * 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 |
|---|
| 1075 | 1066 | * streaming. Exceptions are some very old USB tuner |
|---|
| 1076 | 1067 | * models such as em28xx-based WinTV USB2 which have |
|---|
| 1077 | 1068 | * a separate audio output jack. The devices that have |
|---|
| .. | .. |
|---|
| 1080 | 1071 | * so the s_power callback are silently ignored. |
|---|
| 1081 | 1072 | * So, the current logic here does the following: |
|---|
| 1082 | 1073 | * Disable (put tuner to sleep) when |
|---|
| 1083 | | - * - ALSA and DVB aren't not streaming; |
|---|
| 1074 | + * - ALSA and DVB aren't streaming. |
|---|
| 1084 | 1075 | * - the last V4L2 file handler is closed. |
|---|
| 1085 | 1076 | * |
|---|
| 1086 | 1077 | * FIXME: |
|---|
| .. | .. |
|---|
| 1162 | 1153 | format->fmt.pix.sizeimage = width * height * 2; |
|---|
| 1163 | 1154 | format->fmt.pix.colorspace = V4L2_COLORSPACE_SMPTE170M; |
|---|
| 1164 | 1155 | format->fmt.pix.field = V4L2_FIELD_INTERLACED; |
|---|
| 1165 | | - format->fmt.pix.priv = 0; |
|---|
| 1166 | 1156 | |
|---|
| 1167 | 1157 | if (cmd == VIDIOC_TRY_FMT) |
|---|
| 1168 | 1158 | return 0; |
|---|
| .. | .. |
|---|
| 1191 | 1181 | static int vidioc_querycap(struct file *file, void *priv, |
|---|
| 1192 | 1182 | struct v4l2_capability *cap) |
|---|
| 1193 | 1183 | { |
|---|
| 1194 | | - struct video_device *vdev = video_devdata(file); |
|---|
| 1195 | 1184 | struct au0828_dev *dev = video_drvdata(file); |
|---|
| 1196 | 1185 | |
|---|
| 1197 | 1186 | dprintk(1, "%s called std_set %d dev_state %ld\n", __func__, |
|---|
| 1198 | 1187 | dev->std_set_in_tuner_core, dev->dev_state); |
|---|
| 1199 | 1188 | |
|---|
| 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)); |
|---|
| 1202 | 1191 | usb_make_path(dev->usbdev, cap->bus_info, sizeof(cap->bus_info)); |
|---|
| 1203 | 1192 | |
|---|
| 1204 | 1193 | /* 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; |
|---|
| 1215 | 1198 | return 0; |
|---|
| 1216 | 1199 | } |
|---|
| 1217 | 1200 | |
|---|
| .. | .. |
|---|
| 1223 | 1206 | |
|---|
| 1224 | 1207 | dprintk(1, "%s called\n", __func__); |
|---|
| 1225 | 1208 | |
|---|
| 1226 | | - f->type = V4L2_BUF_TYPE_VIDEO_CAPTURE; |
|---|
| 1227 | | - strcpy(f->description, "Packed YUV2"); |
|---|
| 1228 | | - |
|---|
| 1229 | | - f->flags = 0; |
|---|
| 1230 | 1209 | f->pixelformat = V4L2_PIX_FMT_UYVY; |
|---|
| 1231 | 1210 | |
|---|
| 1232 | 1211 | return 0; |
|---|
| .. | .. |
|---|
| 1247 | 1226 | f->fmt.pix.sizeimage = dev->frame_size; |
|---|
| 1248 | 1227 | f->fmt.pix.colorspace = V4L2_COLORSPACE_SMPTE170M; /* NTSC/PAL */ |
|---|
| 1249 | 1228 | f->fmt.pix.field = V4L2_FIELD_INTERLACED; |
|---|
| 1250 | | - f->fmt.pix.priv = 0; |
|---|
| 1251 | 1229 | return 0; |
|---|
| 1252 | 1230 | } |
|---|
| 1253 | 1231 | |
|---|
| .. | .. |
|---|
| 1355 | 1333 | return -EINVAL; |
|---|
| 1356 | 1334 | |
|---|
| 1357 | 1335 | input->index = tmp; |
|---|
| 1358 | | - strcpy(input->name, inames[AUVI_INPUT(tmp).type]); |
|---|
| 1336 | + strscpy(input->name, inames[AUVI_INPUT(tmp).type], sizeof(input->name)); |
|---|
| 1359 | 1337 | if ((AUVI_INPUT(tmp).type == AU0828_VMUX_TELEVISION) || |
|---|
| 1360 | 1338 | (AUVI_INPUT(tmp).type == AU0828_VMUX_CABLE)) { |
|---|
| 1361 | 1339 | input->type |= V4L2_INPUT_TYPE_TUNER; |
|---|
| .. | .. |
|---|
| 1471 | 1449 | dprintk(1, "%s called\n", __func__); |
|---|
| 1472 | 1450 | |
|---|
| 1473 | 1451 | if (a->index == 0) |
|---|
| 1474 | | - strcpy(a->name, "Television"); |
|---|
| 1452 | + strscpy(a->name, "Television", sizeof(a->name)); |
|---|
| 1475 | 1453 | else |
|---|
| 1476 | | - strcpy(a->name, "Line in"); |
|---|
| 1454 | + strscpy(a->name, "Line in", sizeof(a->name)); |
|---|
| 1477 | 1455 | |
|---|
| 1478 | 1456 | a->capability = V4L2_AUDCAP_STEREO; |
|---|
| 1479 | 1457 | return 0; |
|---|
| .. | .. |
|---|
| 1488 | 1466 | |
|---|
| 1489 | 1467 | a->index = dev->ctrl_ainput; |
|---|
| 1490 | 1468 | if (a->index == 0) |
|---|
| 1491 | | - strcpy(a->name, "Television"); |
|---|
| 1469 | + strscpy(a->name, "Television", sizeof(a->name)); |
|---|
| 1492 | 1470 | else |
|---|
| 1493 | | - strcpy(a->name, "Line in"); |
|---|
| 1471 | + strscpy(a->name, "Line in", sizeof(a->name)); |
|---|
| 1494 | 1472 | |
|---|
| 1495 | 1473 | a->capability = V4L2_AUDCAP_STEREO; |
|---|
| 1496 | 1474 | return 0; |
|---|
| .. | .. |
|---|
| 1524 | 1502 | dprintk(1, "%s called std_set %d dev_state %ld\n", __func__, |
|---|
| 1525 | 1503 | dev->std_set_in_tuner_core, dev->dev_state); |
|---|
| 1526 | 1504 | |
|---|
| 1527 | | - strcpy(t->name, "Auvitek tuner"); |
|---|
| 1505 | + strscpy(t->name, "Auvitek tuner", sizeof(t->name)); |
|---|
| 1528 | 1506 | |
|---|
| 1529 | 1507 | au0828_init_tuner(dev); |
|---|
| 1530 | 1508 | i2c_gate_ctrl(dev, 1); |
|---|
| .. | .. |
|---|
| 1622 | 1600 | return 0; |
|---|
| 1623 | 1601 | } |
|---|
| 1624 | 1602 | |
|---|
| 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) |
|---|
| 1627 | 1605 | { |
|---|
| 1628 | 1606 | struct au0828_dev *dev = video_drvdata(file); |
|---|
| 1629 | 1607 | |
|---|
| 1630 | | - if (cc->type != V4L2_BUF_TYPE_VIDEO_CAPTURE) |
|---|
| 1608 | + if (type != V4L2_BUF_TYPE_VIDEO_CAPTURE) |
|---|
| 1631 | 1609 | return -EINVAL; |
|---|
| 1632 | 1610 | |
|---|
| 1633 | 1611 | dprintk(1, "%s called std_set %d dev_state %ld\n", __func__, |
|---|
| 1634 | 1612 | dev->std_set_in_tuner_core, dev->dev_state); |
|---|
| 1635 | 1613 | |
|---|
| 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; |
|---|
| 1640 | 1616 | |
|---|
| 1641 | | - cc->defrect = cc->bounds; |
|---|
| 1617 | + return 0; |
|---|
| 1618 | +} |
|---|
| 1642 | 1619 | |
|---|
| 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); |
|---|
| 1645 | 1624 | |
|---|
| 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 | + } |
|---|
| 1646 | 1639 | return 0; |
|---|
| 1647 | 1640 | } |
|---|
| 1648 | 1641 | |
|---|
| .. | .. |
|---|
| 1768 | 1761 | .vidioc_enumaudio = vidioc_enumaudio, |
|---|
| 1769 | 1762 | .vidioc_g_audio = vidioc_g_audio, |
|---|
| 1770 | 1763 | .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, |
|---|
| 1772 | 1766 | |
|---|
| 1773 | 1767 | .vidioc_reqbufs = vb2_ioctl_reqbufs, |
|---|
| 1774 | 1768 | .vidioc_create_bufs = vb2_ioctl_create_bufs, |
|---|
| .. | .. |
|---|
| 1984 | 1978 | dev->vdev.lock = &dev->lock; |
|---|
| 1985 | 1979 | dev->vdev.queue = &dev->vb_vidq; |
|---|
| 1986 | 1980 | 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)); |
|---|
| 1988 | 1985 | |
|---|
| 1989 | 1986 | /* Setup the VBI device */ |
|---|
| 1990 | 1987 | dev->vbi_dev = au0828_video_template; |
|---|
| .. | .. |
|---|
| 1992 | 1989 | dev->vbi_dev.lock = &dev->lock; |
|---|
| 1993 | 1990 | dev->vbi_dev.queue = &dev->vb_vbiq; |
|---|
| 1994 | 1991 | 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)); |
|---|
| 1996 | 1996 | |
|---|
| 1997 | 1997 | /* Init entities at the Media Controller */ |
|---|
| 1998 | 1998 | au0828_analog_create_entities(dev); |
|---|
| .. | .. |
|---|
| 2007 | 2007 | |
|---|
| 2008 | 2008 | /* Register the v4l2 device */ |
|---|
| 2009 | 2009 | 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); |
|---|
| 2011 | 2011 | if (retval != 0) { |
|---|
| 2012 | 2012 | dprintk(1, "unable to register video device (error = %d).\n", |
|---|
| 2013 | 2013 | retval); |
|---|
| 2014 | | - ret = -ENODEV; |
|---|
| 2015 | | - goto err_reg_vdev; |
|---|
| 2014 | + return -ENODEV; |
|---|
| 2016 | 2015 | } |
|---|
| 2017 | 2016 | |
|---|
| 2018 | 2017 | /* Register the vbi device */ |
|---|
| .. | .. |
|---|
| 2040 | 2039 | return 0; |
|---|
| 2041 | 2040 | |
|---|
| 2042 | 2041 | 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); |
|---|
| 2047 | 2043 | return ret; |
|---|
| 2048 | 2044 | } |
|---|
| 2049 | 2045 | |
|---|