forked from ~ljy/RK356X_SDK_RELEASE

hc
2024-12-19 9370bb92b2d16684ee45cf24e879c93c509162da
kernel/drivers/media/pci/bt8xx/bttv-driver.c
....@@ -1,3 +1,4 @@
1
+// SPDX-License-Identifier: GPL-2.0-or-later
12 /*
23
34 bttv - Bt848 frame grabber driver
....@@ -19,19 +20,6 @@
1920 Copyright (C) 2005, 2006 Michael H. Schimek <mschimek@gmx.at>
2021 Sponsored by OPQ Systems AB
2122
22
- This program is free software; you can redistribute it and/or modify
23
- it under the terms of the GNU General Public License as published by
24
- the Free Software Foundation; either version 2 of the License, or
25
- (at your option) any later version.
26
-
27
- This program is distributed in the hope that it will be useful,
28
- but WITHOUT ANY WARRANTY; without even the implied warranty of
29
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
30
- GNU General Public License for more details.
31
-
32
- You should have received a copy of the GNU General Public License
33
- along with this program; if not, write to the Free Software
34
- Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
3523 */
3624
3725 #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
....@@ -515,77 +503,65 @@
515503 packed pixel formats must come first */
516504 static const struct bttv_format formats[] = {
517505 {
518
- .name = "8 bpp, gray",
519506 .fourcc = V4L2_PIX_FMT_GREY,
520507 .btformat = BT848_COLOR_FMT_Y8,
521508 .depth = 8,
522509 .flags = FORMAT_FLAGS_PACKED,
523510 },{
524
- .name = "8 bpp, dithered color",
525511 .fourcc = V4L2_PIX_FMT_HI240,
526512 .btformat = BT848_COLOR_FMT_RGB8,
527513 .depth = 8,
528514 .flags = FORMAT_FLAGS_PACKED | FORMAT_FLAGS_DITHER,
529515 },{
530
- .name = "15 bpp RGB, le",
531516 .fourcc = V4L2_PIX_FMT_RGB555,
532517 .btformat = BT848_COLOR_FMT_RGB15,
533518 .depth = 16,
534519 .flags = FORMAT_FLAGS_PACKED,
535520 },{
536
- .name = "15 bpp RGB, be",
537521 .fourcc = V4L2_PIX_FMT_RGB555X,
538522 .btformat = BT848_COLOR_FMT_RGB15,
539523 .btswap = 0x03, /* byteswap */
540524 .depth = 16,
541525 .flags = FORMAT_FLAGS_PACKED,
542526 },{
543
- .name = "16 bpp RGB, le",
544527 .fourcc = V4L2_PIX_FMT_RGB565,
545528 .btformat = BT848_COLOR_FMT_RGB16,
546529 .depth = 16,
547530 .flags = FORMAT_FLAGS_PACKED,
548531 },{
549
- .name = "16 bpp RGB, be",
550532 .fourcc = V4L2_PIX_FMT_RGB565X,
551533 .btformat = BT848_COLOR_FMT_RGB16,
552534 .btswap = 0x03, /* byteswap */
553535 .depth = 16,
554536 .flags = FORMAT_FLAGS_PACKED,
555537 },{
556
- .name = "24 bpp RGB, le",
557538 .fourcc = V4L2_PIX_FMT_BGR24,
558539 .btformat = BT848_COLOR_FMT_RGB24,
559540 .depth = 24,
560541 .flags = FORMAT_FLAGS_PACKED,
561542 },{
562
- .name = "32 bpp RGB, le",
563543 .fourcc = V4L2_PIX_FMT_BGR32,
564544 .btformat = BT848_COLOR_FMT_RGB32,
565545 .depth = 32,
566546 .flags = FORMAT_FLAGS_PACKED,
567547 },{
568
- .name = "32 bpp RGB, be",
569548 .fourcc = V4L2_PIX_FMT_RGB32,
570549 .btformat = BT848_COLOR_FMT_RGB32,
571550 .btswap = 0x0f, /* byte+word swap */
572551 .depth = 32,
573552 .flags = FORMAT_FLAGS_PACKED,
574553 },{
575
- .name = "4:2:2, packed, YUYV",
576554 .fourcc = V4L2_PIX_FMT_YUYV,
577555 .btformat = BT848_COLOR_FMT_YUY2,
578556 .depth = 16,
579557 .flags = FORMAT_FLAGS_PACKED,
580558 },{
581
- .name = "4:2:2, packed, UYVY",
582559 .fourcc = V4L2_PIX_FMT_UYVY,
583560 .btformat = BT848_COLOR_FMT_YUY2,
584561 .btswap = 0x03, /* byteswap */
585562 .depth = 16,
586563 .flags = FORMAT_FLAGS_PACKED,
587564 },{
588
- .name = "4:2:2, planar, Y-Cb-Cr",
589565 .fourcc = V4L2_PIX_FMT_YUV422P,
590566 .btformat = BT848_COLOR_FMT_YCrCb422,
591567 .depth = 16,
....@@ -593,7 +569,6 @@
593569 .hshift = 1,
594570 .vshift = 0,
595571 },{
596
- .name = "4:2:0, planar, Y-Cb-Cr",
597572 .fourcc = V4L2_PIX_FMT_YUV420,
598573 .btformat = BT848_COLOR_FMT_YCrCb422,
599574 .depth = 12,
....@@ -601,7 +576,6 @@
601576 .hshift = 1,
602577 .vshift = 1,
603578 },{
604
- .name = "4:2:0, planar, Y-Cr-Cb",
605579 .fourcc = V4L2_PIX_FMT_YVU420,
606580 .btformat = BT848_COLOR_FMT_YCrCb422,
607581 .depth = 12,
....@@ -609,7 +583,6 @@
609583 .hshift = 1,
610584 .vshift = 1,
611585 },{
612
- .name = "4:1:1, planar, Y-Cb-Cr",
613586 .fourcc = V4L2_PIX_FMT_YUV411P,
614587 .btformat = BT848_COLOR_FMT_YCrCb411,
615588 .depth = 12,
....@@ -617,7 +590,6 @@
617590 .hshift = 2,
618591 .vshift = 0,
619592 },{
620
- .name = "4:1:0, planar, Y-Cb-Cr",
621593 .fourcc = V4L2_PIX_FMT_YUV410,
622594 .btformat = BT848_COLOR_FMT_YCrCb411,
623595 .depth = 9,
....@@ -625,7 +597,6 @@
625597 .hshift = 2,
626598 .vshift = 2,
627599 },{
628
- .name = "4:1:0, planar, Y-Cr-Cb",
629600 .fourcc = V4L2_PIX_FMT_YVU410,
630601 .btformat = BT848_COLOR_FMT_YCrCb411,
631602 .depth = 9,
....@@ -633,7 +604,6 @@
633604 .hshift = 2,
634605 .vshift = 2,
635606 },{
636
- .name = "raw scanlines",
637607 .fourcc = -1,
638608 .btformat = BT848_COLOR_FMT_RAW,
639609 .depth = 8,
....@@ -2040,7 +2010,6 @@
20402010 max_width = max_width & width_mask;
20412011
20422012 /* Max. scale factor is 16:1 for frames, 8:1 for fields. */
2043
- min_height = min_height;
20442013 /* Min. scale factor is 1:1. */
20452014 max_height >>= !V4L2_FIELD_HAS_BOTH(field);
20462015
....@@ -2363,7 +2332,7 @@
23632332 field = V4L2_FIELD_SEQ_TB;
23642333 break;
23652334 }
2366
- /* fall through */
2335
+ fallthrough;
23672336 default: /* FIELD_ANY case */
23682337 height2 = btv->crop[!!fh->do_crop].rect.height >> 1;
23692338 field = (f->fmt.pix.height > height2)
....@@ -2436,7 +2405,7 @@
24362405
24372406 f->fmt.pix.field = field;
24382407
2439
- /* update our state informations */
2408
+ /* update our state information */
24402409 fh->fmt = fmt;
24412410 fh->cap.field = f->fmt.pix.field;
24422411 fh->cap.last = V4L2_FIELD_NONE;
....@@ -2466,28 +2435,27 @@
24662435 static int bttv_querycap(struct file *file, void *priv,
24672436 struct v4l2_capability *cap)
24682437 {
2469
- struct video_device *vdev = video_devdata(file);
24702438 struct bttv_fh *fh = priv;
24712439 struct bttv *btv = fh->btv;
24722440
24732441 if (0 == v4l2)
24742442 return -EINVAL;
24752443
2476
- strlcpy(cap->driver, "bttv", sizeof(cap->driver));
2477
- strlcpy(cap->card, btv->video_dev.name, sizeof(cap->card));
2444
+ strscpy(cap->driver, "bttv", sizeof(cap->driver));
2445
+ strscpy(cap->card, btv->video_dev.name, sizeof(cap->card));
24782446 snprintf(cap->bus_info, sizeof(cap->bus_info),
24792447 "PCI:%s", pci_name(btv->c.pci));
2480
- cap->capabilities =
2481
- V4L2_CAP_VIDEO_CAPTURE |
2482
- V4L2_CAP_READWRITE |
2483
- V4L2_CAP_STREAMING |
2484
- V4L2_CAP_DEVICE_CAPS;
2448
+ cap->capabilities = V4L2_CAP_VIDEO_CAPTURE | V4L2_CAP_READWRITE |
2449
+ V4L2_CAP_STREAMING | V4L2_CAP_DEVICE_CAPS;
24852450 if (no_overlay <= 0)
24862451 cap->capabilities |= V4L2_CAP_VIDEO_OVERLAY;
24872452 if (video_is_registered(&btv->vbi_dev))
24882453 cap->capabilities |= V4L2_CAP_VBI_CAPTURE;
2489
- if (video_is_registered(&btv->radio_dev))
2454
+ if (video_is_registered(&btv->radio_dev)) {
24902455 cap->capabilities |= V4L2_CAP_RADIO;
2456
+ if (btv->has_tea575x)
2457
+ cap->capabilities |= V4L2_CAP_HW_FREQ_SEEK;
2458
+ }
24912459
24922460 /*
24932461 * No need to lock here: those vars are initialized during board
....@@ -2497,27 +2465,6 @@
24972465 cap->capabilities |= V4L2_CAP_RDS_CAPTURE;
24982466 if (btv->tuner_type != TUNER_ABSENT)
24992467 cap->capabilities |= V4L2_CAP_TUNER;
2500
- if (vdev->vfl_type == VFL_TYPE_GRABBER)
2501
- cap->device_caps = cap->capabilities &
2502
- (V4L2_CAP_VIDEO_CAPTURE |
2503
- V4L2_CAP_READWRITE |
2504
- V4L2_CAP_STREAMING |
2505
- V4L2_CAP_VIDEO_OVERLAY |
2506
- V4L2_CAP_TUNER);
2507
- else if (vdev->vfl_type == VFL_TYPE_VBI)
2508
- cap->device_caps = cap->capabilities &
2509
- (V4L2_CAP_VBI_CAPTURE |
2510
- V4L2_CAP_READWRITE |
2511
- V4L2_CAP_STREAMING |
2512
- V4L2_CAP_TUNER);
2513
- else {
2514
- cap->device_caps = V4L2_CAP_RADIO | V4L2_CAP_TUNER;
2515
- if (btv->has_saa6588)
2516
- cap->device_caps |= V4L2_CAP_READWRITE |
2517
- V4L2_CAP_RDS_CAPTURE;
2518
- if (btv->has_tea575x)
2519
- cap->device_caps |= V4L2_CAP_HW_FREQ_SEEK;
2520
- }
25212468 return 0;
25222469 }
25232470
....@@ -2535,7 +2482,6 @@
25352482 return -EINVAL;
25362483
25372484 f->pixelformat = formats[i].fourcc;
2538
- strlcpy(f->description, formats[i].name, sizeof(f->description));
25392485
25402486 return i;
25412487 }
....@@ -2782,7 +2728,7 @@
27822728 t->rxsubchans = V4L2_TUNER_SUB_MONO;
27832729 t->capability = V4L2_TUNER_CAP_NORM;
27842730 bttv_call_all(btv, tuner, g_tuner, t);
2785
- strcpy(t->name, "Television");
2731
+ strscpy(t->name, "Television", sizeof(t->name));
27862732 t->type = V4L2_TUNER_ANALOG_TV;
27872733 if (btread(BT848_DSTATUS)&BT848_DSTATUS_HLOC)
27882734 t->signal = 0xffff;
....@@ -2793,19 +2739,17 @@
27932739 return 0;
27942740 }
27952741
2796
-static int bttv_cropcap(struct file *file, void *priv,
2797
- struct v4l2_cropcap *cap)
2742
+static int bttv_g_pixelaspect(struct file *file, void *priv,
2743
+ int type, struct v4l2_fract *f)
27982744 {
27992745 struct bttv_fh *fh = priv;
28002746 struct bttv *btv = fh->btv;
28012747
2802
- if (cap->type != V4L2_BUF_TYPE_VIDEO_CAPTURE &&
2803
- cap->type != V4L2_BUF_TYPE_VIDEO_OVERLAY)
2748
+ if (type != V4L2_BUF_TYPE_VIDEO_CAPTURE)
28042749 return -EINVAL;
28052750
28062751 /* defrect and bounds are set via g_selection */
2807
- cap->pixelaspect = bttv_tvnorms[btv->tvnorm].cropcap.pixelaspect;
2808
-
2752
+ *f = bttv_tvnorms[btv->tvnorm].cropcap.pixelaspect;
28092753 return 0;
28102754 }
28112755
....@@ -3020,7 +2964,7 @@
30202964
30212965 dprintk("open dev=%s\n", video_device_node_name(vdev));
30222966
3023
- if (vdev->vfl_type == VFL_TYPE_GRABBER) {
2967
+ if (vdev->vfl_type == VFL_TYPE_VIDEO) {
30242968 type = V4L2_BUF_TYPE_VIDEO_CAPTURE;
30252969 } else if (vdev->vfl_type == VFL_TYPE_VBI) {
30262970 type = V4L2_BUF_TYPE_VBI_CAPTURE;
....@@ -3067,7 +3011,7 @@
30673011 V4L2 apps we now reset the cropping parameters as seen through
30683012 this fh, which is to say VIDIOC_G_SELECTION and scaling limit checks
30693013 will use btv->crop[0], the default cropping parameters for the
3070
- current video standard, and VIDIOC_S_FMT will not implicitely
3014
+ current video standard, and VIDIOC_S_FMT will not implicitly
30713015 change the cropping parameters until VIDIOC_S_SELECTION has been
30723016 called. */
30733017 fh->do_crop = !reset_crop; /* module parameter */
....@@ -3163,7 +3107,7 @@
31633107 .vidioc_g_fmt_vbi_cap = bttv_g_fmt_vbi_cap,
31643108 .vidioc_try_fmt_vbi_cap = bttv_try_fmt_vbi_cap,
31653109 .vidioc_s_fmt_vbi_cap = bttv_s_fmt_vbi_cap,
3166
- .vidioc_cropcap = bttv_cropcap,
3110
+ .vidioc_g_pixelaspect = bttv_g_pixelaspect,
31673111 .vidioc_reqbufs = bttv_reqbufs,
31683112 .vidioc_querybuf = bttv_querybuf,
31693113 .vidioc_qbuf = bttv_qbuf,
....@@ -3257,7 +3201,7 @@
32573201
32583202 if (0 != t->index)
32593203 return -EINVAL;
3260
- strcpy(t->name, "Radio");
3204
+ strscpy(t->name, "Radio", sizeof(t->name));
32613205 t->type = V4L2_TUNER_RADIO;
32623206 radio_enable(btv);
32633207
....@@ -3603,9 +3547,7 @@
36033547 bttv_irq_wakeup_video(struct bttv *btv, struct bttv_buffer_set *wakeup,
36043548 struct bttv_buffer_set *curr, unsigned int state)
36053549 {
3606
- struct timeval ts;
3607
-
3608
- v4l2_get_timestamp(&ts);
3550
+ u64 ts = ktime_get_ns();
36093551
36103552 if (wakeup->top == wakeup->bottom) {
36113553 if (NULL != wakeup->top && curr->top != wakeup->top) {
....@@ -3646,7 +3588,7 @@
36463588 if (NULL == wakeup)
36473589 return;
36483590
3649
- v4l2_get_timestamp(&wakeup->vb.ts);
3591
+ wakeup->vb.ts = ktime_get_ns();
36503592 wakeup->vb.field_count = btv->field_count;
36513593 wakeup->vb.state = state;
36523594 wake_up(&wakeup->vb.done);
....@@ -3716,7 +3658,7 @@
37163658 btv->curr.top = NULL;
37173659 bttv_risc_hook(btv, RISC_SLOT_O_FIELD, NULL, 0);
37183660
3719
- v4l2_get_timestamp(&wakeup->vb.ts);
3661
+ wakeup->vb.ts = ktime_get_ns();
37203662 wakeup->vb.field_count = btv->field_count;
37213663 wakeup->vb.state = VIDEOBUF_DONE;
37223664 wake_up(&wakeup->vb.done);
....@@ -3956,8 +3898,14 @@
39563898
39573899 /* video */
39583900 vdev_init(btv, &btv->video_dev, &bttv_video_template, "video");
3901
+ btv->video_dev.device_caps = V4L2_CAP_VIDEO_CAPTURE |
3902
+ V4L2_CAP_READWRITE | V4L2_CAP_STREAMING;
3903
+ if (btv->tuner_type != TUNER_ABSENT)
3904
+ btv->video_dev.device_caps |= V4L2_CAP_TUNER;
3905
+ if (no_overlay <= 0)
3906
+ btv->video_dev.device_caps |= V4L2_CAP_VIDEO_OVERLAY;
39593907
3960
- if (video_register_device(&btv->video_dev, VFL_TYPE_GRABBER,
3908
+ if (video_register_device(&btv->video_dev, VFL_TYPE_VIDEO,
39613909 video_nr[btv->c.nr]) < 0)
39623910 goto err;
39633911 pr_info("%d: registered device %s\n",
....@@ -3970,6 +3918,10 @@
39703918
39713919 /* vbi */
39723920 vdev_init(btv, &btv->vbi_dev, &bttv_video_template, "vbi");
3921
+ btv->vbi_dev.device_caps = V4L2_CAP_VBI_CAPTURE | V4L2_CAP_READWRITE |
3922
+ V4L2_CAP_STREAMING;
3923
+ if (btv->tuner_type != TUNER_ABSENT)
3924
+ btv->vbi_dev.device_caps |= V4L2_CAP_TUNER;
39733925
39743926 if (video_register_device(&btv->vbi_dev, VFL_TYPE_VBI,
39753927 vbi_nr[btv->c.nr]) < 0)
....@@ -3981,6 +3933,12 @@
39813933 return 0;
39823934 /* radio */
39833935 vdev_init(btv, &btv->radio_dev, &radio_template, "radio");
3936
+ btv->radio_dev.device_caps = V4L2_CAP_RADIO | V4L2_CAP_TUNER;
3937
+ if (btv->has_saa6588)
3938
+ btv->radio_dev.device_caps |= V4L2_CAP_READWRITE |
3939
+ V4L2_CAP_RDS_CAPTURE;
3940
+ if (btv->has_tea575x)
3941
+ btv->radio_dev.device_caps |= V4L2_CAP_HW_FREQ_SEEK;
39843942 btv->radio_dev.ctrl_handler = &btv->radio_ctrl_handler;
39853943 if (video_register_device(&btv->radio_dev, VFL_TYPE_RADIO,
39863944 radio_nr[btv->c.nr]) < 0)
....@@ -4214,7 +4172,7 @@
42144172 /* register video4linux + input */
42154173 if (!bttv_tvcards[btv->c.type].no_video) {
42164174 v4l2_ctrl_add_handler(&btv->radio_ctrl_handler, hdl,
4217
- v4l2_ctrl_radio_filter);
4175
+ v4l2_ctrl_radio_filter, false);
42184176 if (btv->radio_ctrl_handler.error) {
42194177 result = btv->radio_ctrl_handler.error;
42204178 goto fail2;