| .. | .. |
|---|
| 1 | +// SPDX-License-Identifier: GPL-2.0-or-later |
|---|
| 1 | 2 | /* |
|---|
| 2 | 3 | * |
|---|
| 3 | 4 | * device driver for philips saa7134 based TV cards |
|---|
| 4 | 5 | * video4linux video interface |
|---|
| 5 | 6 | * |
|---|
| 6 | 7 | * (c) 2001-03 Gerd Knorr <kraxel@bytesex.org> [SuSE Labs] |
|---|
| 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. |
|---|
| 12 | | - * |
|---|
| 13 | | - * This program is distributed in the hope that it will be useful, |
|---|
| 14 | | - * but WITHOUT ANY WARRANTY; without even the implied warranty of |
|---|
| 15 | | - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|---|
| 16 | | - * GNU General Public License for more details. |
|---|
| 17 | 8 | */ |
|---|
| 18 | 9 | |
|---|
| 19 | 10 | #include "saa7134.h" |
|---|
| .. | .. |
|---|
| 99 | 90 | |
|---|
| 100 | 91 | static struct saa7134_format formats[] = { |
|---|
| 101 | 92 | { |
|---|
| 102 | | - .name = "8 bpp gray", |
|---|
| 103 | 93 | .fourcc = V4L2_PIX_FMT_GREY, |
|---|
| 104 | 94 | .depth = 8, |
|---|
| 105 | 95 | .pm = 0x06, |
|---|
| 106 | 96 | },{ |
|---|
| 107 | | - .name = "15 bpp RGB, le", |
|---|
| 108 | 97 | .fourcc = V4L2_PIX_FMT_RGB555, |
|---|
| 109 | 98 | .depth = 16, |
|---|
| 110 | 99 | .pm = 0x13 | 0x80, |
|---|
| 111 | 100 | },{ |
|---|
| 112 | | - .name = "15 bpp RGB, be", |
|---|
| 113 | 101 | .fourcc = V4L2_PIX_FMT_RGB555X, |
|---|
| 114 | 102 | .depth = 16, |
|---|
| 115 | 103 | .pm = 0x13 | 0x80, |
|---|
| 116 | 104 | .bswap = 1, |
|---|
| 117 | 105 | },{ |
|---|
| 118 | | - .name = "16 bpp RGB, le", |
|---|
| 119 | 106 | .fourcc = V4L2_PIX_FMT_RGB565, |
|---|
| 120 | 107 | .depth = 16, |
|---|
| 121 | 108 | .pm = 0x10 | 0x80, |
|---|
| 122 | 109 | },{ |
|---|
| 123 | | - .name = "16 bpp RGB, be", |
|---|
| 124 | 110 | .fourcc = V4L2_PIX_FMT_RGB565X, |
|---|
| 125 | 111 | .depth = 16, |
|---|
| 126 | 112 | .pm = 0x10 | 0x80, |
|---|
| 127 | 113 | .bswap = 1, |
|---|
| 128 | 114 | },{ |
|---|
| 129 | | - .name = "24 bpp RGB, le", |
|---|
| 130 | 115 | .fourcc = V4L2_PIX_FMT_BGR24, |
|---|
| 131 | 116 | .depth = 24, |
|---|
| 132 | 117 | .pm = 0x11, |
|---|
| 133 | 118 | },{ |
|---|
| 134 | | - .name = "24 bpp RGB, be", |
|---|
| 135 | 119 | .fourcc = V4L2_PIX_FMT_RGB24, |
|---|
| 136 | 120 | .depth = 24, |
|---|
| 137 | 121 | .pm = 0x11, |
|---|
| 138 | 122 | .bswap = 1, |
|---|
| 139 | 123 | },{ |
|---|
| 140 | | - .name = "32 bpp RGB, le", |
|---|
| 141 | 124 | .fourcc = V4L2_PIX_FMT_BGR32, |
|---|
| 142 | 125 | .depth = 32, |
|---|
| 143 | 126 | .pm = 0x12, |
|---|
| 144 | 127 | },{ |
|---|
| 145 | | - .name = "32 bpp RGB, be", |
|---|
| 146 | 128 | .fourcc = V4L2_PIX_FMT_RGB32, |
|---|
| 147 | 129 | .depth = 32, |
|---|
| 148 | 130 | .pm = 0x12, |
|---|
| 149 | 131 | .bswap = 1, |
|---|
| 150 | 132 | .wswap = 1, |
|---|
| 151 | 133 | },{ |
|---|
| 152 | | - .name = "4:2:2 packed, YUYV", |
|---|
| 153 | 134 | .fourcc = V4L2_PIX_FMT_YUYV, |
|---|
| 154 | 135 | .depth = 16, |
|---|
| 155 | 136 | .pm = 0x00, |
|---|
| 156 | 137 | .bswap = 1, |
|---|
| 157 | 138 | .yuv = 1, |
|---|
| 158 | 139 | },{ |
|---|
| 159 | | - .name = "4:2:2 packed, UYVY", |
|---|
| 160 | 140 | .fourcc = V4L2_PIX_FMT_UYVY, |
|---|
| 161 | 141 | .depth = 16, |
|---|
| 162 | 142 | .pm = 0x00, |
|---|
| 163 | 143 | .yuv = 1, |
|---|
| 164 | 144 | },{ |
|---|
| 165 | | - .name = "4:2:2 planar, Y-Cb-Cr", |
|---|
| 166 | 145 | .fourcc = V4L2_PIX_FMT_YUV422P, |
|---|
| 167 | 146 | .depth = 16, |
|---|
| 168 | 147 | .pm = 0x09, |
|---|
| .. | .. |
|---|
| 171 | 150 | .hshift = 1, |
|---|
| 172 | 151 | .vshift = 0, |
|---|
| 173 | 152 | },{ |
|---|
| 174 | | - .name = "4:2:0 planar, Y-Cb-Cr", |
|---|
| 175 | 153 | .fourcc = V4L2_PIX_FMT_YUV420, |
|---|
| 176 | 154 | .depth = 12, |
|---|
| 177 | 155 | .pm = 0x0a, |
|---|
| .. | .. |
|---|
| 180 | 158 | .hshift = 1, |
|---|
| 181 | 159 | .vshift = 1, |
|---|
| 182 | 160 | },{ |
|---|
| 183 | | - .name = "4:2:0 planar, Y-Cb-Cr", |
|---|
| 184 | 161 | .fourcc = V4L2_PIX_FMT_YVU420, |
|---|
| 185 | 162 | .depth = 12, |
|---|
| 186 | 163 | .pm = 0x0a, |
|---|
| .. | .. |
|---|
| 729 | 706 | return err; |
|---|
| 730 | 707 | |
|---|
| 731 | 708 | dev->ovfield = dev->win.field; |
|---|
| 732 | | - video_dbg("start_preview %dx%d+%d+%d %s field=%s\n", |
|---|
| 733 | | - dev->win.w.width, dev->win.w.height, |
|---|
| 734 | | - dev->win.w.left, dev->win.w.top, |
|---|
| 735 | | - dev->ovfmt->name, v4l2_field_names[dev->ovfield]); |
|---|
| 709 | + video_dbg("%s %dx%d+%d+%d 0x%08x field=%s\n", __func__, |
|---|
| 710 | + dev->win.w.width, dev->win.w.height, |
|---|
| 711 | + dev->win.w.left, dev->win.w.top, |
|---|
| 712 | + dev->ovfmt->fourcc, v4l2_field_names[dev->ovfield]); |
|---|
| 736 | 713 | |
|---|
| 737 | 714 | /* setup window + clipping */ |
|---|
| 738 | 715 | set_size(dev, TASK_B, dev->win.w.width, dev->win.w.height, |
|---|
| .. | .. |
|---|
| 1031 | 1008 | */ |
|---|
| 1032 | 1009 | if ((dmaq == &dev->video_q && !vb2_is_streaming(&dev->vbi_vbq)) || |
|---|
| 1033 | 1010 | (dmaq == &dev->vbi_q && !vb2_is_streaming(&dev->video_vbq))) |
|---|
| 1034 | | - pm_qos_add_request(&dev->qos_request, |
|---|
| 1035 | | - PM_QOS_CPU_DMA_LATENCY, 20); |
|---|
| 1011 | + cpu_latency_qos_add_request(&dev->qos_request, 20); |
|---|
| 1036 | 1012 | dmaq->seq_nr = 0; |
|---|
| 1037 | 1013 | |
|---|
| 1038 | 1014 | return 0; |
|---|
| .. | .. |
|---|
| 1047 | 1023 | |
|---|
| 1048 | 1024 | if ((dmaq == &dev->video_q && !vb2_is_streaming(&dev->vbi_vbq)) || |
|---|
| 1049 | 1025 | (dmaq == &dev->vbi_q && !vb2_is_streaming(&dev->video_vbq))) |
|---|
| 1050 | | - pm_qos_remove_request(&dev->qos_request); |
|---|
| 1026 | + cpu_latency_qos_remove_request(&dev->qos_request); |
|---|
| 1051 | 1027 | } |
|---|
| 1052 | 1028 | |
|---|
| 1053 | 1029 | static const struct vb2_ops vb2_qops = { |
|---|
| .. | .. |
|---|
| 1445 | 1421 | if (card_in(dev, i->index).type == SAA7134_NO_INPUT) |
|---|
| 1446 | 1422 | return -EINVAL; |
|---|
| 1447 | 1423 | i->index = n; |
|---|
| 1448 | | - strcpy(i->name, saa7134_input_name[card_in(dev, n).type]); |
|---|
| 1424 | + strscpy(i->name, saa7134_input_name[card_in(dev, n).type], |
|---|
| 1425 | + sizeof(i->name)); |
|---|
| 1449 | 1426 | switch (card_in(dev, n).type) { |
|---|
| 1450 | 1427 | case SAA7134_INPUT_TV: |
|---|
| 1451 | 1428 | case SAA7134_INPUT_TV_MONO: |
|---|
| .. | .. |
|---|
| 1497 | 1474 | struct v4l2_capability *cap) |
|---|
| 1498 | 1475 | { |
|---|
| 1499 | 1476 | struct saa7134_dev *dev = video_drvdata(file); |
|---|
| 1500 | | - struct video_device *vdev = video_devdata(file); |
|---|
| 1501 | | - u32 radio_caps, video_caps, vbi_caps; |
|---|
| 1502 | 1477 | |
|---|
| 1503 | | - unsigned int tuner_type = dev->tuner_type; |
|---|
| 1504 | | - |
|---|
| 1505 | | - strcpy(cap->driver, "saa7134"); |
|---|
| 1506 | | - strlcpy(cap->card, saa7134_boards[dev->board].name, |
|---|
| 1478 | + strscpy(cap->driver, "saa7134", sizeof(cap->driver)); |
|---|
| 1479 | + strscpy(cap->card, saa7134_boards[dev->board].name, |
|---|
| 1507 | 1480 | sizeof(cap->card)); |
|---|
| 1508 | 1481 | sprintf(cap->bus_info, "PCI:%s", pci_name(dev->pci)); |
|---|
| 1509 | | - |
|---|
| 1510 | | - cap->device_caps = V4L2_CAP_READWRITE | V4L2_CAP_STREAMING; |
|---|
| 1511 | | - if ((tuner_type != TUNER_ABSENT) && (tuner_type != UNSET)) |
|---|
| 1512 | | - cap->device_caps |= V4L2_CAP_TUNER; |
|---|
| 1513 | | - |
|---|
| 1514 | | - radio_caps = V4L2_CAP_RADIO; |
|---|
| 1482 | + cap->capabilities = V4L2_CAP_READWRITE | V4L2_CAP_STREAMING | |
|---|
| 1483 | + V4L2_CAP_RADIO | V4L2_CAP_VIDEO_CAPTURE | |
|---|
| 1484 | + V4L2_CAP_VBI_CAPTURE | V4L2_CAP_DEVICE_CAPS; |
|---|
| 1485 | + if (dev->tuner_type != TUNER_ABSENT && dev->tuner_type != UNSET) |
|---|
| 1486 | + cap->capabilities |= V4L2_CAP_TUNER; |
|---|
| 1515 | 1487 | if (dev->has_rds) |
|---|
| 1516 | | - radio_caps |= V4L2_CAP_RDS_CAPTURE; |
|---|
| 1517 | | - |
|---|
| 1518 | | - video_caps = V4L2_CAP_VIDEO_CAPTURE; |
|---|
| 1519 | | - if (saa7134_no_overlay <= 0 && !is_empress(file)) |
|---|
| 1520 | | - video_caps |= V4L2_CAP_VIDEO_OVERLAY; |
|---|
| 1521 | | - |
|---|
| 1522 | | - vbi_caps = V4L2_CAP_VBI_CAPTURE; |
|---|
| 1523 | | - |
|---|
| 1524 | | - switch (vdev->vfl_type) { |
|---|
| 1525 | | - case VFL_TYPE_RADIO: |
|---|
| 1526 | | - cap->device_caps |= radio_caps; |
|---|
| 1527 | | - break; |
|---|
| 1528 | | - case VFL_TYPE_GRABBER: |
|---|
| 1529 | | - cap->device_caps |= video_caps; |
|---|
| 1530 | | - break; |
|---|
| 1531 | | - case VFL_TYPE_VBI: |
|---|
| 1532 | | - cap->device_caps |= vbi_caps; |
|---|
| 1533 | | - break; |
|---|
| 1534 | | - default: |
|---|
| 1535 | | - return -EINVAL; |
|---|
| 1536 | | - } |
|---|
| 1537 | | - cap->capabilities = radio_caps | video_caps | vbi_caps | |
|---|
| 1538 | | - cap->device_caps | V4L2_CAP_DEVICE_CAPS; |
|---|
| 1539 | | - if (vdev->vfl_type == VFL_TYPE_RADIO) { |
|---|
| 1540 | | - cap->device_caps &= ~V4L2_CAP_STREAMING; |
|---|
| 1541 | | - if (!dev->has_rds) |
|---|
| 1542 | | - cap->device_caps &= ~V4L2_CAP_READWRITE; |
|---|
| 1543 | | - } |
|---|
| 1488 | + cap->capabilities |= V4L2_CAP_RDS_CAPTURE; |
|---|
| 1489 | + if (saa7134_no_overlay <= 0) |
|---|
| 1490 | + cap->capabilities |= V4L2_CAP_VIDEO_OVERLAY; |
|---|
| 1544 | 1491 | |
|---|
| 1545 | 1492 | return 0; |
|---|
| 1546 | 1493 | } |
|---|
| .. | .. |
|---|
| 1649 | 1596 | } |
|---|
| 1650 | 1597 | EXPORT_SYMBOL_GPL(saa7134_querystd); |
|---|
| 1651 | 1598 | |
|---|
| 1652 | | -static int saa7134_cropcap(struct file *file, void *priv, |
|---|
| 1653 | | - struct v4l2_cropcap *cap) |
|---|
| 1599 | +static int saa7134_g_pixelaspect(struct file *file, void *priv, |
|---|
| 1600 | + int type, struct v4l2_fract *f) |
|---|
| 1654 | 1601 | { |
|---|
| 1655 | 1602 | struct saa7134_dev *dev = video_drvdata(file); |
|---|
| 1656 | 1603 | |
|---|
| 1657 | | - if (cap->type != V4L2_BUF_TYPE_VIDEO_CAPTURE && |
|---|
| 1658 | | - cap->type != V4L2_BUF_TYPE_VIDEO_OVERLAY) |
|---|
| 1604 | + if (type != V4L2_BUF_TYPE_VIDEO_CAPTURE && |
|---|
| 1605 | + type != V4L2_BUF_TYPE_VIDEO_OVERLAY) |
|---|
| 1659 | 1606 | return -EINVAL; |
|---|
| 1660 | | - cap->pixelaspect.numerator = 1; |
|---|
| 1661 | | - cap->pixelaspect.denominator = 1; |
|---|
| 1607 | + |
|---|
| 1662 | 1608 | if (dev->tvnorm->id & V4L2_STD_525_60) { |
|---|
| 1663 | | - cap->pixelaspect.numerator = 11; |
|---|
| 1664 | | - cap->pixelaspect.denominator = 10; |
|---|
| 1609 | + f->numerator = 11; |
|---|
| 1610 | + f->denominator = 10; |
|---|
| 1665 | 1611 | } |
|---|
| 1666 | 1612 | if (dev->tvnorm->id & V4L2_STD_625_50) { |
|---|
| 1667 | | - cap->pixelaspect.numerator = 54; |
|---|
| 1668 | | - cap->pixelaspect.denominator = 59; |
|---|
| 1613 | + f->numerator = 54; |
|---|
| 1614 | + f->denominator = 59; |
|---|
| 1669 | 1615 | } |
|---|
| 1670 | 1616 | return 0; |
|---|
| 1671 | 1617 | } |
|---|
| .. | .. |
|---|
| 1747 | 1693 | if (n == SAA7134_INPUT_MAX) |
|---|
| 1748 | 1694 | return -EINVAL; |
|---|
| 1749 | 1695 | if (card_in(dev, n).type != SAA7134_NO_INPUT) { |
|---|
| 1750 | | - strcpy(t->name, "Television"); |
|---|
| 1696 | + strscpy(t->name, "Television", sizeof(t->name)); |
|---|
| 1751 | 1697 | t->type = V4L2_TUNER_ANALOG_TV; |
|---|
| 1752 | 1698 | saa_call_all(dev, tuner, g_tuner, t); |
|---|
| 1753 | 1699 | t->capability = V4L2_TUNER_CAP_NORM | |
|---|
| .. | .. |
|---|
| 1819 | 1765 | if (f->index >= FORMATS) |
|---|
| 1820 | 1766 | return -EINVAL; |
|---|
| 1821 | 1767 | |
|---|
| 1822 | | - strlcpy(f->description, formats[f->index].name, |
|---|
| 1823 | | - sizeof(f->description)); |
|---|
| 1824 | | - |
|---|
| 1825 | 1768 | f->pixelformat = formats[f->index].fourcc; |
|---|
| 1826 | 1769 | |
|---|
| 1827 | 1770 | return 0; |
|---|
| .. | .. |
|---|
| 1837 | 1780 | |
|---|
| 1838 | 1781 | if ((f->index >= FORMATS) || formats[f->index].planar) |
|---|
| 1839 | 1782 | return -EINVAL; |
|---|
| 1840 | | - |
|---|
| 1841 | | - strlcpy(f->description, formats[f->index].name, |
|---|
| 1842 | | - sizeof(f->description)); |
|---|
| 1843 | 1783 | |
|---|
| 1844 | 1784 | f->pixelformat = formats[f->index].fourcc; |
|---|
| 1845 | 1785 | |
|---|
| .. | .. |
|---|
| 1939 | 1879 | if (0 != t->index) |
|---|
| 1940 | 1880 | return -EINVAL; |
|---|
| 1941 | 1881 | |
|---|
| 1942 | | - strcpy(t->name, "Radio"); |
|---|
| 1882 | + strscpy(t->name, "Radio", sizeof(t->name)); |
|---|
| 1943 | 1883 | |
|---|
| 1944 | 1884 | saa_call_all(dev, tuner, g_tuner, t); |
|---|
| 1945 | 1885 | t->audmode &= V4L2_TUNER_MODE_MONO | V4L2_TUNER_MODE_STEREO; |
|---|
| .. | .. |
|---|
| 1986 | 1926 | .vidioc_g_fmt_vbi_cap = saa7134_try_get_set_fmt_vbi_cap, |
|---|
| 1987 | 1927 | .vidioc_try_fmt_vbi_cap = saa7134_try_get_set_fmt_vbi_cap, |
|---|
| 1988 | 1928 | .vidioc_s_fmt_vbi_cap = saa7134_try_get_set_fmt_vbi_cap, |
|---|
| 1989 | | - .vidioc_cropcap = saa7134_cropcap, |
|---|
| 1929 | + .vidioc_g_pixelaspect = saa7134_g_pixelaspect, |
|---|
| 1990 | 1930 | .vidioc_reqbufs = vb2_ioctl_reqbufs, |
|---|
| 1991 | 1931 | .vidioc_querybuf = vb2_ioctl_querybuf, |
|---|
| 1992 | 1932 | .vidioc_qbuf = vb2_ioctl_qbuf, |
|---|
| .. | .. |
|---|
| 2136 | 2076 | hdl = &dev->radio_ctrl_handler; |
|---|
| 2137 | 2077 | v4l2_ctrl_handler_init(hdl, 2); |
|---|
| 2138 | 2078 | v4l2_ctrl_add_handler(hdl, &dev->ctrl_handler, |
|---|
| 2139 | | - v4l2_ctrl_radio_filter); |
|---|
| 2079 | + v4l2_ctrl_radio_filter, false); |
|---|
| 2140 | 2080 | if (hdl->error) |
|---|
| 2141 | 2081 | return hdl->error; |
|---|
| 2142 | 2082 | } |
|---|
| .. | .. |
|---|
| 2213 | 2153 | |
|---|
| 2214 | 2154 | void saa7134_video_fini(struct saa7134_dev *dev) |
|---|
| 2215 | 2155 | { |
|---|
| 2156 | + del_timer_sync(&dev->video_q.timeout); |
|---|
| 2216 | 2157 | /* free stuff */ |
|---|
| 2217 | | - vb2_queue_release(&dev->video_vbq); |
|---|
| 2218 | 2158 | saa7134_pgtable_free(dev->pci, &dev->video_q.pt); |
|---|
| 2219 | | - vb2_queue_release(&dev->vbi_vbq); |
|---|
| 2220 | 2159 | saa7134_pgtable_free(dev->pci, &dev->vbi_q.pt); |
|---|
| 2221 | 2160 | v4l2_ctrl_handler_free(&dev->ctrl_handler); |
|---|
| 2222 | 2161 | if (card_has_radio(dev)) |
|---|