forked from ~ljy/RK356X_SDK_RELEASE

hc
2024-12-19 9370bb92b2d16684ee45cf24e879c93c509162da
kernel/drivers/media/pci/cx88/cx88-video.c
....@@ -1,3 +1,4 @@
1
+// SPDX-License-Identifier: GPL-2.0-or-later
12 /*
23 *
34 * device driver for Conexant 2388x based TV cards
....@@ -9,16 +10,6 @@
910 * - Multituner support
1011 * - video_ioctl2 conversion
1112 * - PAL/M fixes
12
- *
13
- * This program is free software; you can redistribute it and/or modify
14
- * it under the terms of the GNU General Public License as published by
15
- * the Free Software Foundation; either version 2 of the License, or
16
- * (at your option) any later version.
17
- *
18
- * This program is distributed in the hope that it will be useful,
19
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
20
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21
- * GNU General Public License for more details.
2213 */
2314
2415 #include "cx88.h"
....@@ -42,7 +33,7 @@
4233
4334 MODULE_DESCRIPTION("v4l2 driver module for cx2388x based TV cards");
4435 MODULE_AUTHOR("Gerd Knorr <kraxel@bytesex.org> [SuSE Labs]");
45
-MODULE_LICENSE("GPL");
36
+MODULE_LICENSE("GPL v2");
4637 MODULE_VERSION(CX88_VERSION);
4738
4839 /* ------------------------------------------------------------------ */
....@@ -78,62 +69,52 @@
7869
7970 static const struct cx8800_fmt formats[] = {
8071 {
81
- .name = "8 bpp, gray",
8272 .fourcc = V4L2_PIX_FMT_GREY,
8373 .cxformat = ColorFormatY8,
8474 .depth = 8,
8575 .flags = FORMAT_FLAGS_PACKED,
8676 }, {
87
- .name = "15 bpp RGB, le",
8877 .fourcc = V4L2_PIX_FMT_RGB555,
8978 .cxformat = ColorFormatRGB15,
9079 .depth = 16,
9180 .flags = FORMAT_FLAGS_PACKED,
9281 }, {
93
- .name = "15 bpp RGB, be",
9482 .fourcc = V4L2_PIX_FMT_RGB555X,
9583 .cxformat = ColorFormatRGB15 | ColorFormatBSWAP,
9684 .depth = 16,
9785 .flags = FORMAT_FLAGS_PACKED,
9886 }, {
99
- .name = "16 bpp RGB, le",
10087 .fourcc = V4L2_PIX_FMT_RGB565,
10188 .cxformat = ColorFormatRGB16,
10289 .depth = 16,
10390 .flags = FORMAT_FLAGS_PACKED,
10491 }, {
105
- .name = "16 bpp RGB, be",
10692 .fourcc = V4L2_PIX_FMT_RGB565X,
10793 .cxformat = ColorFormatRGB16 | ColorFormatBSWAP,
10894 .depth = 16,
10995 .flags = FORMAT_FLAGS_PACKED,
11096 }, {
111
- .name = "24 bpp RGB, le",
11297 .fourcc = V4L2_PIX_FMT_BGR24,
11398 .cxformat = ColorFormatRGB24,
11499 .depth = 24,
115100 .flags = FORMAT_FLAGS_PACKED,
116101 }, {
117
- .name = "32 bpp RGB, le",
118102 .fourcc = V4L2_PIX_FMT_BGR32,
119103 .cxformat = ColorFormatRGB32,
120104 .depth = 32,
121105 .flags = FORMAT_FLAGS_PACKED,
122106 }, {
123
- .name = "32 bpp RGB, be",
124107 .fourcc = V4L2_PIX_FMT_RGB32,
125108 .cxformat = ColorFormatRGB32 | ColorFormatBSWAP |
126109 ColorFormatWSWAP,
127110 .depth = 32,
128111 .flags = FORMAT_FLAGS_PACKED,
129112 }, {
130
- .name = "4:2:2, packed, YUYV",
131113 .fourcc = V4L2_PIX_FMT_YUYV,
132114 .cxformat = ColorFormatYUY2,
133115 .depth = 16,
134116 .flags = FORMAT_FLAGS_PACKED,
135117 }, {
136
- .name = "4:2:2, packed, UYVY",
137118 .fourcc = V4L2_PIX_FMT_UYVY,
138119 .cxformat = ColorFormatYUY2 | ColorFormatBSWAP,
139120 .depth = 16,
....@@ -404,8 +385,7 @@
404385 return 0;
405386 }
406387
407
-#ifdef CONFIG_PM
408
-static int stop_video_dma(struct cx8800_dev *dev)
388
+static int __maybe_unused stop_video_dma(struct cx8800_dev *dev)
409389 {
410390 struct cx88_core *core = dev->core;
411391
....@@ -421,8 +401,8 @@
421401 return 0;
422402 }
423403
424
-static int restart_video_queue(struct cx8800_dev *dev,
425
- struct cx88_dmaqueue *q)
404
+static int __maybe_unused restart_video_queue(struct cx8800_dev *dev,
405
+ struct cx88_dmaqueue *q)
426406 {
427407 struct cx88_buffer *buf;
428408
....@@ -434,7 +414,6 @@
434414 }
435415 return 0;
436416 }
437
-#endif
438417
439418 /* ------------------------------------------------------------------ */
440419
....@@ -452,6 +431,7 @@
452431
453432 static int buffer_prepare(struct vb2_buffer *vb)
454433 {
434
+ int ret;
455435 struct vb2_v4l2_buffer *vbuf = to_vb2_v4l2_buffer(vb);
456436 struct cx8800_dev *dev = vb->vb2_queue->drv_priv;
457437 struct cx88_core *core = dev->core;
....@@ -466,43 +446,43 @@
466446
467447 switch (core->field) {
468448 case V4L2_FIELD_TOP:
469
- cx88_risc_buffer(dev->pci, &buf->risc,
470
- sgt->sgl, 0, UNSET,
471
- buf->bpl, 0, core->height);
449
+ ret = cx88_risc_buffer(dev->pci, &buf->risc,
450
+ sgt->sgl, 0, UNSET,
451
+ buf->bpl, 0, core->height);
472452 break;
473453 case V4L2_FIELD_BOTTOM:
474
- cx88_risc_buffer(dev->pci, &buf->risc,
475
- sgt->sgl, UNSET, 0,
476
- buf->bpl, 0, core->height);
454
+ ret = cx88_risc_buffer(dev->pci, &buf->risc,
455
+ sgt->sgl, UNSET, 0,
456
+ buf->bpl, 0, core->height);
477457 break;
478458 case V4L2_FIELD_SEQ_TB:
479
- cx88_risc_buffer(dev->pci, &buf->risc,
480
- sgt->sgl,
481
- 0, buf->bpl * (core->height >> 1),
482
- buf->bpl, 0,
483
- core->height >> 1);
459
+ ret = cx88_risc_buffer(dev->pci, &buf->risc,
460
+ sgt->sgl,
461
+ 0, buf->bpl * (core->height >> 1),
462
+ buf->bpl, 0,
463
+ core->height >> 1);
484464 break;
485465 case V4L2_FIELD_SEQ_BT:
486
- cx88_risc_buffer(dev->pci, &buf->risc,
487
- sgt->sgl,
488
- buf->bpl * (core->height >> 1), 0,
489
- buf->bpl, 0,
490
- core->height >> 1);
466
+ ret = cx88_risc_buffer(dev->pci, &buf->risc,
467
+ sgt->sgl,
468
+ buf->bpl * (core->height >> 1), 0,
469
+ buf->bpl, 0,
470
+ core->height >> 1);
491471 break;
492472 case V4L2_FIELD_INTERLACED:
493473 default:
494
- cx88_risc_buffer(dev->pci, &buf->risc,
495
- sgt->sgl, 0, buf->bpl,
496
- buf->bpl, buf->bpl,
497
- core->height >> 1);
474
+ ret = cx88_risc_buffer(dev->pci, &buf->risc,
475
+ sgt->sgl, 0, buf->bpl,
476
+ buf->bpl, buf->bpl,
477
+ core->height >> 1);
498478 break;
499479 }
500480 dprintk(2,
501
- "[%p/%d] buffer_prepare - %dx%d %dbpp \"%s\" - dma=0x%08lx\n",
502
- buf, buf->vb.vb2_buf.index,
503
- core->width, core->height, dev->fmt->depth, dev->fmt->name,
481
+ "[%p/%d] %s - %dx%d %dbpp 0x%08x - dma=0x%08lx\n",
482
+ buf, buf->vb.vb2_buf.index, __func__,
483
+ core->width, core->height, dev->fmt->depth, dev->fmt->fourcc,
504484 (unsigned long)buf->risc.dma);
505
- return 0;
485
+ return ret;
506486 }
507487
508488 static void buffer_finish(struct vb2_buffer *vb)
....@@ -809,27 +789,12 @@
809789 int cx88_querycap(struct file *file, struct cx88_core *core,
810790 struct v4l2_capability *cap)
811791 {
812
- struct video_device *vdev = video_devdata(file);
813
-
814
- strlcpy(cap->card, core->board.name, sizeof(cap->card));
815
- cap->device_caps = V4L2_CAP_READWRITE | V4L2_CAP_STREAMING;
792
+ strscpy(cap->card, core->board.name, sizeof(cap->card));
793
+ cap->capabilities = V4L2_CAP_READWRITE | V4L2_CAP_STREAMING |
794
+ V4L2_CAP_VIDEO_CAPTURE | V4L2_CAP_VBI_CAPTURE |
795
+ V4L2_CAP_DEVICE_CAPS;
816796 if (core->board.tuner_type != UNSET)
817
- cap->device_caps |= V4L2_CAP_TUNER;
818
- switch (vdev->vfl_type) {
819
- case VFL_TYPE_RADIO:
820
- cap->device_caps = V4L2_CAP_RADIO | V4L2_CAP_TUNER;
821
- break;
822
- case VFL_TYPE_GRABBER:
823
- cap->device_caps |= V4L2_CAP_VIDEO_CAPTURE;
824
- break;
825
- case VFL_TYPE_VBI:
826
- cap->device_caps |= V4L2_CAP_VBI_CAPTURE;
827
- break;
828
- default:
829
- return -EINVAL;
830
- }
831
- cap->capabilities = cap->device_caps | V4L2_CAP_VIDEO_CAPTURE |
832
- V4L2_CAP_VBI_CAPTURE | V4L2_CAP_DEVICE_CAPS;
797
+ cap->capabilities |= V4L2_CAP_TUNER;
833798 if (core->board.radio.type == CX88_RADIO)
834799 cap->capabilities |= V4L2_CAP_RADIO;
835800 return 0;
....@@ -842,7 +807,7 @@
842807 struct cx8800_dev *dev = video_drvdata(file);
843808 struct cx88_core *core = dev->core;
844809
845
- strcpy(cap->driver, "cx8800");
810
+ strscpy(cap->driver, "cx8800", sizeof(cap->driver));
846811 sprintf(cap->bus_info, "PCI:%s", pci_name(dev->pci));
847812 return cx88_querycap(file, core, cap);
848813 }
....@@ -853,7 +818,6 @@
853818 if (unlikely(f->index >= ARRAY_SIZE(formats)))
854819 return -EINVAL;
855820
856
- strlcpy(f->description, formats[f->index].name, sizeof(f->description));
857821 f->pixelformat = formats[f->index].fourcc;
858822
859823 return 0;
....@@ -897,7 +861,7 @@
897861 if (!INPUT(n).type)
898862 return -EINVAL;
899863 i->type = V4L2_INPUT_TYPE_CAMERA;
900
- strcpy(i->name, iname[INPUT(n).type]);
864
+ strscpy(i->name, iname[INPUT(n).type], sizeof(i->name));
901865 if ((INPUT(n).type == CX88_VMUX_TELEVISION) ||
902866 (INPUT(n).type == CX88_VMUX_CABLE))
903867 i->type = V4L2_INPUT_TYPE_TUNER;
....@@ -952,7 +916,7 @@
952916 if (t->index != 0)
953917 return -EINVAL;
954918
955
- strcpy(t->name, "Television");
919
+ strscpy(t->name, "Television", sizeof(t->name));
956920 t->capability = V4L2_TUNER_CAP_NORM;
957921 t->rangehigh = 0xffffffffUL;
958922 call_all(core, tuner, g_tuner, t);
....@@ -1065,7 +1029,7 @@
10651029 if (unlikely(t->index > 0))
10661030 return -EINVAL;
10671031
1068
- strcpy(t->name, "Radio");
1032
+ strscpy(t->name, "Radio", sizeof(t->name));
10691033
10701034 call_all(core, tuner, g_tuner, t);
10711035 return 0;
....@@ -1378,7 +1342,7 @@
13781342 if (vc->id == V4L2_CID_CHROMA_AGC)
13791343 core->chroma_agc = vc;
13801344 }
1381
- v4l2_ctrl_add_handler(&core->video_hdl, &core->audio_hdl, NULL);
1345
+ v4l2_ctrl_add_handler(&core->video_hdl, &core->audio_hdl, NULL, false);
13821346
13831347 /* load and configure helper modules */
13841348
....@@ -1420,9 +1384,9 @@
14201384 };
14211385
14221386 request_module("rtc-isl1208");
1423
- core->i2c_rtc = i2c_new_device(&core->i2c_adap, &rtc_info);
1387
+ core->i2c_rtc = i2c_new_client_device(&core->i2c_adap, &rtc_info);
14241388 }
1425
- /* fall-through */
1389
+ fallthrough;
14261390 case CX88_BOARD_DVICO_FUSIONHDTV_5_PCI_NANO:
14271391 request_module("ir-kbd-i2c");
14281392 }
....@@ -1482,7 +1446,11 @@
14821446 video_set_drvdata(&dev->video_dev, dev);
14831447 dev->video_dev.ctrl_handler = &core->video_hdl;
14841448 dev->video_dev.queue = &dev->vb2_vidq;
1485
- err = video_register_device(&dev->video_dev, VFL_TYPE_GRABBER,
1449
+ dev->video_dev.device_caps = V4L2_CAP_READWRITE | V4L2_CAP_STREAMING |
1450
+ V4L2_CAP_VIDEO_CAPTURE;
1451
+ if (core->board.tuner_type != UNSET)
1452
+ dev->video_dev.device_caps |= V4L2_CAP_TUNER;
1453
+ err = video_register_device(&dev->video_dev, VFL_TYPE_VIDEO,
14861454 video_nr[core->nr]);
14871455 if (err < 0) {
14881456 pr_err("can't register video device\n");
....@@ -1495,6 +1463,10 @@
14951463 &cx8800_vbi_template, "vbi");
14961464 video_set_drvdata(&dev->vbi_dev, dev);
14971465 dev->vbi_dev.queue = &dev->vb2_vbiq;
1466
+ dev->vbi_dev.device_caps = V4L2_CAP_READWRITE | V4L2_CAP_STREAMING |
1467
+ V4L2_CAP_VBI_CAPTURE;
1468
+ if (core->board.tuner_type != UNSET)
1469
+ dev->vbi_dev.device_caps |= V4L2_CAP_TUNER;
14981470 err = video_register_device(&dev->vbi_dev, VFL_TYPE_VBI,
14991471 vbi_nr[core->nr]);
15001472 if (err < 0) {
....@@ -1509,6 +1481,7 @@
15091481 &cx8800_radio_template, "radio");
15101482 video_set_drvdata(&dev->radio_dev, dev);
15111483 dev->radio_dev.ctrl_handler = &core->audio_hdl;
1484
+ dev->radio_dev.device_caps = V4L2_CAP_RADIO | V4L2_CAP_TUNER;
15121485 err = video_register_device(&dev->radio_dev, VFL_TYPE_RADIO,
15131486 radio_nr[core->nr]);
15141487 if (err < 0) {
....@@ -1577,10 +1550,9 @@
15771550 kfree(dev);
15781551 }
15791552
1580
-#ifdef CONFIG_PM
1581
-static int cx8800_suspend(struct pci_dev *pci_dev, pm_message_t state)
1553
+static int __maybe_unused cx8800_suspend(struct device *dev_d)
15821554 {
1583
- struct cx8800_dev *dev = pci_get_drvdata(pci_dev);
1555
+ struct cx8800_dev *dev = dev_get_drvdata(dev_d);
15841556 struct cx88_core *core = dev->core;
15851557 unsigned long flags;
15861558
....@@ -1601,40 +1573,17 @@
16011573 /* FIXME -- shutdown device */
16021574 cx88_shutdown(core);
16031575
1604
- pci_save_state(pci_dev);
1605
- if (pci_set_power_state(pci_dev,
1606
- pci_choose_state(pci_dev, state)) != 0) {
1607
- pci_disable_device(pci_dev);
1608
- dev->state.disabled = 1;
1609
- }
1576
+ dev->state.disabled = 1;
16101577 return 0;
16111578 }
16121579
1613
-static int cx8800_resume(struct pci_dev *pci_dev)
1580
+static int __maybe_unused cx8800_resume(struct device *dev_d)
16141581 {
1615
- struct cx8800_dev *dev = pci_get_drvdata(pci_dev);
1582
+ struct cx8800_dev *dev = dev_get_drvdata(dev_d);
16161583 struct cx88_core *core = dev->core;
16171584 unsigned long flags;
1618
- int err;
16191585
1620
- if (dev->state.disabled) {
1621
- err = pci_enable_device(pci_dev);
1622
- if (err) {
1623
- pr_err("can't enable device\n");
1624
- return err;
1625
- }
1626
-
1627
- dev->state.disabled = 0;
1628
- }
1629
- err = pci_set_power_state(pci_dev, PCI_D0);
1630
- if (err) {
1631
- pr_err("can't set power state\n");
1632
- pci_disable_device(pci_dev);
1633
- dev->state.disabled = 1;
1634
-
1635
- return err;
1636
- }
1637
- pci_restore_state(pci_dev);
1586
+ dev->state.disabled = 0;
16381587
16391588 /* FIXME: re-initialize hardware */
16401589 cx88_reset(core);
....@@ -1657,7 +1606,6 @@
16571606
16581607 return 0;
16591608 }
1660
-#endif
16611609
16621610 /* ----------------------------------------------------------- */
16631611
....@@ -1673,15 +1621,14 @@
16731621 };
16741622 MODULE_DEVICE_TABLE(pci, cx8800_pci_tbl);
16751623
1624
+static SIMPLE_DEV_PM_OPS(cx8800_pm_ops, cx8800_suspend, cx8800_resume);
1625
+
16761626 static struct pci_driver cx8800_pci_driver = {
1677
- .name = "cx8800",
1678
- .id_table = cx8800_pci_tbl,
1679
- .probe = cx8800_initdev,
1680
- .remove = cx8800_finidev,
1681
-#ifdef CONFIG_PM
1682
- .suspend = cx8800_suspend,
1683
- .resume = cx8800_resume,
1684
-#endif
1627
+ .name = "cx8800",
1628
+ .id_table = cx8800_pci_tbl,
1629
+ .probe = cx8800_initdev,
1630
+ .remove = cx8800_finidev,
1631
+ .driver.pm = &cx8800_pm_ops,
16851632 };
16861633
16871634 module_pci_driver(cx8800_pci_driver);