hc
2024-05-10 9999e48639b3cecb08ffb37358bcba3b48161b29
kernel/drivers/media/pci/sta2x11/sta2x11_vip.c
....@@ -1,3 +1,4 @@
1
+// SPDX-License-Identifier: GPL-2.0-only
12 /*
23 * This is the driver for the STA2x11 Video Input Port.
34 *
....@@ -6,23 +7,6 @@
67 * Copyright (C) 2010 WindRiver Systems, Inc.
78 * authors: Andreas Kies <andreas.kies@windriver.com>
89 * Vlad Lungu <vlad.lungu@windriver.com>
9
- *
10
- * This program is free software; you can redistribute it and/or modify it
11
- * under the terms and conditions of the GNU General Public License,
12
- * version 2, as published by the Free Software Foundation.
13
- *
14
- * This program is distributed in the hope it will be useful, but WITHOUT
15
- * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
16
- * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
17
- * more details.
18
- *
19
- * You should have received a copy of the GNU General Public License along with
20
- * this program; if not, write to the Free Software Foundation, Inc.,
21
- * 51 Franklin St - Fifth Floor, Boston, MA 02110-1301 USA.
22
- *
23
- * The full GNU General Public License is included in this distribution in
24
- * the file called "COPYING".
25
- *
2610 */
2711
2812 #include <linux/types.h>
....@@ -110,7 +94,7 @@
11094 * @std: video standard (e.g. PAL/NTSC)
11195 * @input: input line for video signal ( 0 or 1 )
11296 * @disabled: Device is in power down state
113
- * @slock: for excluse acces of registers
97
+ * @slock: for excluse access of registers
11498 * @vb_vidq: queue maintained by videobuf2 layer
11599 * @buffer_list: list of buffer in use
116100 * @sequence: sequence number of acquired buffer
....@@ -419,14 +403,10 @@
419403 {
420404 struct sta2x11_vip *vip = video_drvdata(file);
421405
422
- strcpy(cap->driver, KBUILD_MODNAME);
423
- strcpy(cap->card, KBUILD_MODNAME);
406
+ strscpy(cap->driver, KBUILD_MODNAME, sizeof(cap->driver));
407
+ strscpy(cap->card, KBUILD_MODNAME, sizeof(cap->card));
424408 snprintf(cap->bus_info, sizeof(cap->bus_info), "PCI:%s",
425409 pci_name(vip->pdev));
426
- cap->device_caps = V4L2_CAP_VIDEO_CAPTURE | V4L2_CAP_READWRITE |
427
- V4L2_CAP_STREAMING;
428
- cap->capabilities = cap->device_caps | V4L2_CAP_DEVICE_CAPS;
429
-
430410 return 0;
431411 }
432412
....@@ -580,9 +560,7 @@
580560 if (f->index != 0)
581561 return -EINVAL;
582562
583
- strcpy(f->description, "4:2:2, packed, UYVY");
584563 f->pixelformat = V4L2_PIX_FMT_UYVY;
585
- f->flags = 0;
586564 return 0;
587565 }
588566
....@@ -775,6 +753,8 @@
775753 .fops = &vip_fops,
776754 .ioctl_ops = &vip_ioctl_ops,
777755 .tvnorms = V4L2_STD_ALL,
756
+ .device_caps = V4L2_CAP_VIDEO_CAPTURE | V4L2_CAP_READWRITE |
757
+ V4L2_CAP_STREAMING,
778758 };
779759
780760 /**
....@@ -1089,7 +1069,7 @@
10891069 vip->video_dev.lock = &vip->v4l_lock;
10901070 video_set_drvdata(&vip->video_dev, vip);
10911071
1092
- ret = video_register_device(&vip->video_dev, VFL_TYPE_GRABBER, -1);
1072
+ ret = video_register_device(&vip->video_dev, VFL_TYPE_VIDEO, -1);
10931073 if (ret)
10941074 goto vrelease;
10951075
....@@ -1121,12 +1101,11 @@
11211101 vunreg:
11221102 video_set_drvdata(&vip->video_dev, NULL);
11231103 vrelease:
1124
- video_unregister_device(&vip->video_dev);
1104
+ vb2_video_unregister_device(&vip->video_dev);
11251105 free_irq(pdev->irq, vip);
11261106 release_buf:
11271107 pci_disable_msi(pdev);
11281108 unmap:
1129
- vb2_queue_release(&vip->vb_vidq);
11301109 pci_iounmap(pdev, vip->iomem);
11311110 release:
11321111 pci_release_regions(pdev);
....@@ -1166,10 +1145,9 @@
11661145 sta2x11_vip_clear_register(vip);
11671146
11681147 video_set_drvdata(&vip->video_dev, NULL);
1169
- video_unregister_device(&vip->video_dev);
1148
+ vb2_video_unregister_device(&vip->video_dev);
11701149 free_irq(pdev->irq, vip);
11711150 pci_disable_msi(pdev);
1172
- vb2_queue_release(&vip->vb_vidq);
11731151 pci_iounmap(pdev, vip->iomem);
11741152 pci_release_regions(pdev);
11751153
....@@ -1187,21 +1165,18 @@
11871165 */
11881166 }
11891167
1190
-#ifdef CONFIG_PM
1191
-
11921168 /**
11931169 * sta2x11_vip_suspend - set device into power save mode
1194
- * @pdev: PCI device
1195
- * @state: new state of device
1170
+ * @dev_d: PCI device
11961171 *
11971172 * all relevant registers are saved and an attempt to set a new state is made.
11981173 *
11991174 * return value: 0 always indicate success,
12001175 * even if device could not be disabled. (workaround for hardware problem)
12011176 */
1202
-static int sta2x11_vip_suspend(struct pci_dev *pdev, pm_message_t state)
1177
+static int __maybe_unused sta2x11_vip_suspend(struct device *dev_d)
12031178 {
1204
- struct v4l2_device *v4l2_dev = pci_get_drvdata(pdev);
1179
+ struct v4l2_device *v4l2_dev = dev_get_drvdata(dev_d);
12051180 struct sta2x11_vip *vip =
12061181 container_of(v4l2_dev, struct sta2x11_vip, v4l2_dev);
12071182 unsigned long flags;
....@@ -1218,15 +1193,8 @@
12181193 vip->register_save_area[SAVE_COUNT + IRQ_COUNT + i] =
12191194 reg_read(vip, registers_to_save[i]);
12201195 spin_unlock_irqrestore(&vip->slock, flags);
1221
- /* save pci state */
1222
- pci_save_state(pdev);
1223
- if (pci_set_power_state(pdev, pci_choose_state(pdev, state))) {
1224
- /*
1225
- * do not call pci_disable_device on sta2x11 because it
1226
- * break all other Bus masters on this EP
1227
- */
1228
- vip->disabled = 1;
1229
- }
1196
+
1197
+ vip->disabled = 1;
12301198
12311199 pr_info("VIP: suspend\n");
12321200 return 0;
....@@ -1234,45 +1202,23 @@
12341202
12351203 /**
12361204 * sta2x11_vip_resume - resume device operation
1237
- * @pdev : PCI device
1238
- *
1239
- * re-enable device, set PCI state to powered and restore registers.
1240
- * resume normal device operation afterwards.
1205
+ * @dev_d : PCI device
12411206 *
12421207 * return value: 0, no error.
12431208 *
12441209 * other, could not set device to power on state.
12451210 */
1246
-static int sta2x11_vip_resume(struct pci_dev *pdev)
1211
+static int __maybe_unused sta2x11_vip_resume(struct device *dev_d)
12471212 {
1248
- struct v4l2_device *v4l2_dev = pci_get_drvdata(pdev);
1213
+ struct v4l2_device *v4l2_dev = dev_get_drvdata(dev_d);
12491214 struct sta2x11_vip *vip =
12501215 container_of(v4l2_dev, struct sta2x11_vip, v4l2_dev);
12511216 unsigned long flags;
1252
- int ret, i;
1217
+ int i;
12531218
12541219 pr_info("VIP: resume\n");
1255
- /* restore pci state */
1256
- if (vip->disabled) {
1257
- ret = pci_enable_device(pdev);
1258
- if (ret) {
1259
- pr_warn("VIP: Can't enable device.\n");
1260
- return ret;
1261
- }
1262
- vip->disabled = 0;
1263
- }
1264
- ret = pci_set_power_state(pdev, PCI_D0);
1265
- if (ret) {
1266
- /*
1267
- * do not call pci_disable_device on sta2x11 because it
1268
- * break all other Bus masters on this EP
1269
- */
1270
- pr_warn("VIP: Can't enable device.\n");
1271
- vip->disabled = 1;
1272
- return ret;
1273
- }
12741220
1275
- pci_restore_state(pdev);
1221
+ vip->disabled = 0;
12761222
12771223 spin_lock_irqsave(&vip->slock, flags);
12781224 for (i = 1; i < SAVE_COUNT; i++)
....@@ -1286,22 +1232,21 @@
12861232 return 0;
12871233 }
12881234
1289
-#endif
1290
-
12911235 static const struct pci_device_id sta2x11_vip_pci_tbl[] = {
12921236 {PCI_DEVICE(PCI_VENDOR_ID_STMICRO, PCI_DEVICE_ID_STMICRO_VIP)},
12931237 {0,}
12941238 };
1239
+
1240
+static SIMPLE_DEV_PM_OPS(sta2x11_vip_pm_ops,
1241
+ sta2x11_vip_suspend,
1242
+ sta2x11_vip_resume);
12951243
12961244 static struct pci_driver sta2x11_vip_driver = {
12971245 .name = KBUILD_MODNAME,
12981246 .probe = sta2x11_vip_init_one,
12991247 .remove = sta2x11_vip_remove_one,
13001248 .id_table = sta2x11_vip_pci_tbl,
1301
-#ifdef CONFIG_PM
1302
- .suspend = sta2x11_vip_suspend,
1303
- .resume = sta2x11_vip_resume,
1304
-#endif
1249
+ .driver.pm = &sta2x11_vip_pm_ops,
13051250 };
13061251
13071252 static int __init sta2x11_vip_init_module(void)