| .. | .. |
|---|
| 1 | +// SPDX-License-Identifier: GPL-2.0-only |
|---|
| 1 | 2 | /* |
|---|
| 2 | 3 | * This is the driver for the STA2x11 Video Input Port. |
|---|
| 3 | 4 | * |
|---|
| .. | .. |
|---|
| 6 | 7 | * Copyright (C) 2010 WindRiver Systems, Inc. |
|---|
| 7 | 8 | * authors: Andreas Kies <andreas.kies@windriver.com> |
|---|
| 8 | 9 | * 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 | | - * |
|---|
| 26 | 10 | */ |
|---|
| 27 | 11 | |
|---|
| 28 | 12 | #include <linux/types.h> |
|---|
| .. | .. |
|---|
| 110 | 94 | * @std: video standard (e.g. PAL/NTSC) |
|---|
| 111 | 95 | * @input: input line for video signal ( 0 or 1 ) |
|---|
| 112 | 96 | * @disabled: Device is in power down state |
|---|
| 113 | | - * @slock: for excluse acces of registers |
|---|
| 97 | + * @slock: for excluse access of registers |
|---|
| 114 | 98 | * @vb_vidq: queue maintained by videobuf2 layer |
|---|
| 115 | 99 | * @buffer_list: list of buffer in use |
|---|
| 116 | 100 | * @sequence: sequence number of acquired buffer |
|---|
| .. | .. |
|---|
| 419 | 403 | { |
|---|
| 420 | 404 | struct sta2x11_vip *vip = video_drvdata(file); |
|---|
| 421 | 405 | |
|---|
| 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)); |
|---|
| 424 | 408 | snprintf(cap->bus_info, sizeof(cap->bus_info), "PCI:%s", |
|---|
| 425 | 409 | 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 | | - |
|---|
| 430 | 410 | return 0; |
|---|
| 431 | 411 | } |
|---|
| 432 | 412 | |
|---|
| .. | .. |
|---|
| 580 | 560 | if (f->index != 0) |
|---|
| 581 | 561 | return -EINVAL; |
|---|
| 582 | 562 | |
|---|
| 583 | | - strcpy(f->description, "4:2:2, packed, UYVY"); |
|---|
| 584 | 563 | f->pixelformat = V4L2_PIX_FMT_UYVY; |
|---|
| 585 | | - f->flags = 0; |
|---|
| 586 | 564 | return 0; |
|---|
| 587 | 565 | } |
|---|
| 588 | 566 | |
|---|
| .. | .. |
|---|
| 775 | 753 | .fops = &vip_fops, |
|---|
| 776 | 754 | .ioctl_ops = &vip_ioctl_ops, |
|---|
| 777 | 755 | .tvnorms = V4L2_STD_ALL, |
|---|
| 756 | + .device_caps = V4L2_CAP_VIDEO_CAPTURE | V4L2_CAP_READWRITE | |
|---|
| 757 | + V4L2_CAP_STREAMING, |
|---|
| 778 | 758 | }; |
|---|
| 779 | 759 | |
|---|
| 780 | 760 | /** |
|---|
| .. | .. |
|---|
| 1089 | 1069 | vip->video_dev.lock = &vip->v4l_lock; |
|---|
| 1090 | 1070 | video_set_drvdata(&vip->video_dev, vip); |
|---|
| 1091 | 1071 | |
|---|
| 1092 | | - ret = video_register_device(&vip->video_dev, VFL_TYPE_GRABBER, -1); |
|---|
| 1072 | + ret = video_register_device(&vip->video_dev, VFL_TYPE_VIDEO, -1); |
|---|
| 1093 | 1073 | if (ret) |
|---|
| 1094 | 1074 | goto vrelease; |
|---|
| 1095 | 1075 | |
|---|
| .. | .. |
|---|
| 1121 | 1101 | vunreg: |
|---|
| 1122 | 1102 | video_set_drvdata(&vip->video_dev, NULL); |
|---|
| 1123 | 1103 | vrelease: |
|---|
| 1124 | | - video_unregister_device(&vip->video_dev); |
|---|
| 1104 | + vb2_video_unregister_device(&vip->video_dev); |
|---|
| 1125 | 1105 | free_irq(pdev->irq, vip); |
|---|
| 1126 | 1106 | release_buf: |
|---|
| 1127 | 1107 | pci_disable_msi(pdev); |
|---|
| 1128 | 1108 | unmap: |
|---|
| 1129 | | - vb2_queue_release(&vip->vb_vidq); |
|---|
| 1130 | 1109 | pci_iounmap(pdev, vip->iomem); |
|---|
| 1131 | 1110 | release: |
|---|
| 1132 | 1111 | pci_release_regions(pdev); |
|---|
| .. | .. |
|---|
| 1166 | 1145 | sta2x11_vip_clear_register(vip); |
|---|
| 1167 | 1146 | |
|---|
| 1168 | 1147 | video_set_drvdata(&vip->video_dev, NULL); |
|---|
| 1169 | | - video_unregister_device(&vip->video_dev); |
|---|
| 1148 | + vb2_video_unregister_device(&vip->video_dev); |
|---|
| 1170 | 1149 | free_irq(pdev->irq, vip); |
|---|
| 1171 | 1150 | pci_disable_msi(pdev); |
|---|
| 1172 | | - vb2_queue_release(&vip->vb_vidq); |
|---|
| 1173 | 1151 | pci_iounmap(pdev, vip->iomem); |
|---|
| 1174 | 1152 | pci_release_regions(pdev); |
|---|
| 1175 | 1153 | |
|---|
| .. | .. |
|---|
| 1187 | 1165 | */ |
|---|
| 1188 | 1166 | } |
|---|
| 1189 | 1167 | |
|---|
| 1190 | | -#ifdef CONFIG_PM |
|---|
| 1191 | | - |
|---|
| 1192 | 1168 | /** |
|---|
| 1193 | 1169 | * sta2x11_vip_suspend - set device into power save mode |
|---|
| 1194 | | - * @pdev: PCI device |
|---|
| 1195 | | - * @state: new state of device |
|---|
| 1170 | + * @dev_d: PCI device |
|---|
| 1196 | 1171 | * |
|---|
| 1197 | 1172 | * all relevant registers are saved and an attempt to set a new state is made. |
|---|
| 1198 | 1173 | * |
|---|
| 1199 | 1174 | * return value: 0 always indicate success, |
|---|
| 1200 | 1175 | * even if device could not be disabled. (workaround for hardware problem) |
|---|
| 1201 | 1176 | */ |
|---|
| 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) |
|---|
| 1203 | 1178 | { |
|---|
| 1204 | | - struct v4l2_device *v4l2_dev = pci_get_drvdata(pdev); |
|---|
| 1179 | + struct v4l2_device *v4l2_dev = dev_get_drvdata(dev_d); |
|---|
| 1205 | 1180 | struct sta2x11_vip *vip = |
|---|
| 1206 | 1181 | container_of(v4l2_dev, struct sta2x11_vip, v4l2_dev); |
|---|
| 1207 | 1182 | unsigned long flags; |
|---|
| .. | .. |
|---|
| 1218 | 1193 | vip->register_save_area[SAVE_COUNT + IRQ_COUNT + i] = |
|---|
| 1219 | 1194 | reg_read(vip, registers_to_save[i]); |
|---|
| 1220 | 1195 | 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; |
|---|
| 1230 | 1198 | |
|---|
| 1231 | 1199 | pr_info("VIP: suspend\n"); |
|---|
| 1232 | 1200 | return 0; |
|---|
| .. | .. |
|---|
| 1234 | 1202 | |
|---|
| 1235 | 1203 | /** |
|---|
| 1236 | 1204 | * 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 |
|---|
| 1241 | 1206 | * |
|---|
| 1242 | 1207 | * return value: 0, no error. |
|---|
| 1243 | 1208 | * |
|---|
| 1244 | 1209 | * other, could not set device to power on state. |
|---|
| 1245 | 1210 | */ |
|---|
| 1246 | | -static int sta2x11_vip_resume(struct pci_dev *pdev) |
|---|
| 1211 | +static int __maybe_unused sta2x11_vip_resume(struct device *dev_d) |
|---|
| 1247 | 1212 | { |
|---|
| 1248 | | - struct v4l2_device *v4l2_dev = pci_get_drvdata(pdev); |
|---|
| 1213 | + struct v4l2_device *v4l2_dev = dev_get_drvdata(dev_d); |
|---|
| 1249 | 1214 | struct sta2x11_vip *vip = |
|---|
| 1250 | 1215 | container_of(v4l2_dev, struct sta2x11_vip, v4l2_dev); |
|---|
| 1251 | 1216 | unsigned long flags; |
|---|
| 1252 | | - int ret, i; |
|---|
| 1217 | + int i; |
|---|
| 1253 | 1218 | |
|---|
| 1254 | 1219 | 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 | | - } |
|---|
| 1274 | 1220 | |
|---|
| 1275 | | - pci_restore_state(pdev); |
|---|
| 1221 | + vip->disabled = 0; |
|---|
| 1276 | 1222 | |
|---|
| 1277 | 1223 | spin_lock_irqsave(&vip->slock, flags); |
|---|
| 1278 | 1224 | for (i = 1; i < SAVE_COUNT; i++) |
|---|
| .. | .. |
|---|
| 1286 | 1232 | return 0; |
|---|
| 1287 | 1233 | } |
|---|
| 1288 | 1234 | |
|---|
| 1289 | | -#endif |
|---|
| 1290 | | - |
|---|
| 1291 | 1235 | static const struct pci_device_id sta2x11_vip_pci_tbl[] = { |
|---|
| 1292 | 1236 | {PCI_DEVICE(PCI_VENDOR_ID_STMICRO, PCI_DEVICE_ID_STMICRO_VIP)}, |
|---|
| 1293 | 1237 | {0,} |
|---|
| 1294 | 1238 | }; |
|---|
| 1239 | + |
|---|
| 1240 | +static SIMPLE_DEV_PM_OPS(sta2x11_vip_pm_ops, |
|---|
| 1241 | + sta2x11_vip_suspend, |
|---|
| 1242 | + sta2x11_vip_resume); |
|---|
| 1295 | 1243 | |
|---|
| 1296 | 1244 | static struct pci_driver sta2x11_vip_driver = { |
|---|
| 1297 | 1245 | .name = KBUILD_MODNAME, |
|---|
| 1298 | 1246 | .probe = sta2x11_vip_init_one, |
|---|
| 1299 | 1247 | .remove = sta2x11_vip_remove_one, |
|---|
| 1300 | 1248 | .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, |
|---|
| 1305 | 1250 | }; |
|---|
| 1306 | 1251 | |
|---|
| 1307 | 1252 | static int __init sta2x11_vip_init_module(void) |
|---|