| .. | .. |
|---|
| 1 | +// SPDX-License-Identifier: GPL-2.0-or-later |
|---|
| 1 | 2 | /* |
|---|
| 2 | 3 | * Motion Eye video4linux driver for Sony Vaio PictureBook |
|---|
| 3 | 4 | * |
|---|
| .. | .. |
|---|
| 11 | 12 | * |
|---|
| 12 | 13 | * Some parts borrowed from various video4linux drivers, especially |
|---|
| 13 | 14 | * bttv-driver.c and zoran.c, see original files for credits. |
|---|
| 14 | | - * |
|---|
| 15 | | - * This program is free software; you can redistribute it and/or modify |
|---|
| 16 | | - * it under the terms of the GNU General Public License as published by |
|---|
| 17 | | - * the Free Software Foundation; either version 2 of the License, or |
|---|
| 18 | | - * (at your option) any later version. |
|---|
| 19 | | - * |
|---|
| 20 | | - * This program is distributed in the hope that it will be useful, |
|---|
| 21 | | - * but WITHOUT ANY WARRANTY; without even the implied warranty of |
|---|
| 22 | | - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|---|
| 23 | | - * GNU General Public License for more details. |
|---|
| 24 | 15 | */ |
|---|
| 25 | 16 | #include <linux/module.h> |
|---|
| 26 | 17 | #include <linux/pci.h> |
|---|
| .. | .. |
|---|
| 805 | 796 | mchip_hsize() * mchip_vsize() * 2); |
|---|
| 806 | 797 | meye.grab_buffer[reqnr].size = mchip_hsize() * mchip_vsize() * 2; |
|---|
| 807 | 798 | meye.grab_buffer[reqnr].state = MEYE_BUF_DONE; |
|---|
| 808 | | - v4l2_get_timestamp(&meye.grab_buffer[reqnr].timestamp); |
|---|
| 799 | + meye.grab_buffer[reqnr].ts = ktime_get_ns(); |
|---|
| 809 | 800 | meye.grab_buffer[reqnr].sequence = sequence++; |
|---|
| 810 | 801 | kfifo_in_locked(&meye.doneq, (unsigned char *)&reqnr, |
|---|
| 811 | 802 | sizeof(int), &meye.doneq_lock); |
|---|
| .. | .. |
|---|
| 826 | 817 | size); |
|---|
| 827 | 818 | meye.grab_buffer[reqnr].size = size; |
|---|
| 828 | 819 | meye.grab_buffer[reqnr].state = MEYE_BUF_DONE; |
|---|
| 829 | | - v4l2_get_timestamp(&meye.grab_buffer[reqnr].timestamp); |
|---|
| 820 | + meye.grab_buffer[reqnr].ts = ktime_get_ns(); |
|---|
| 830 | 821 | meye.grab_buffer[reqnr].sequence = sequence++; |
|---|
| 831 | 822 | kfifo_in_locked(&meye.doneq, (unsigned char *)&reqnr, |
|---|
| 832 | 823 | sizeof(int), &meye.doneq_lock); |
|---|
| .. | .. |
|---|
| 961 | 952 | mutex_unlock(&meye.lock); |
|---|
| 962 | 953 | return -EINTR; |
|---|
| 963 | 954 | } |
|---|
| 964 | | - /* fall through */ |
|---|
| 955 | + fallthrough; |
|---|
| 965 | 956 | case MEYE_BUF_DONE: |
|---|
| 966 | 957 | meye.grab_buffer[*i].state = MEYE_BUF_UNUSED; |
|---|
| 967 | 958 | if (kfifo_out_locked(&meye.doneq, (unsigned char *)&unused, |
|---|
| .. | .. |
|---|
| 1019 | 1010 | static int vidioc_querycap(struct file *file, void *fh, |
|---|
| 1020 | 1011 | struct v4l2_capability *cap) |
|---|
| 1021 | 1012 | { |
|---|
| 1022 | | - strcpy(cap->driver, "meye"); |
|---|
| 1023 | | - strcpy(cap->card, "meye"); |
|---|
| 1013 | + strscpy(cap->driver, "meye", sizeof(cap->driver)); |
|---|
| 1014 | + strscpy(cap->card, "meye", sizeof(cap->card)); |
|---|
| 1024 | 1015 | sprintf(cap->bus_info, "PCI:%s", pci_name(meye.mchip_dev)); |
|---|
| 1025 | | - |
|---|
| 1026 | | - cap->device_caps = V4L2_CAP_VIDEO_CAPTURE | |
|---|
| 1027 | | - V4L2_CAP_STREAMING; |
|---|
| 1028 | | - cap->capabilities = cap->device_caps | V4L2_CAP_DEVICE_CAPS; |
|---|
| 1029 | | - |
|---|
| 1030 | 1016 | return 0; |
|---|
| 1031 | 1017 | } |
|---|
| 1032 | 1018 | |
|---|
| .. | .. |
|---|
| 1035 | 1021 | if (i->index != 0) |
|---|
| 1036 | 1022 | return -EINVAL; |
|---|
| 1037 | 1023 | |
|---|
| 1038 | | - strcpy(i->name, "Camera"); |
|---|
| 1024 | + strscpy(i->name, "Camera", sizeof(i->name)); |
|---|
| 1039 | 1025 | i->type = V4L2_INPUT_TYPE_CAMERA; |
|---|
| 1040 | 1026 | |
|---|
| 1041 | 1027 | return 0; |
|---|
| .. | .. |
|---|
| 1118 | 1104 | if (f->index == 0) { |
|---|
| 1119 | 1105 | /* standard YUV 422 capture */ |
|---|
| 1120 | 1106 | f->flags = 0; |
|---|
| 1121 | | - strcpy(f->description, "YUV422"); |
|---|
| 1122 | 1107 | f->pixelformat = V4L2_PIX_FMT_YUYV; |
|---|
| 1123 | 1108 | } else { |
|---|
| 1124 | 1109 | /* compressed MJPEG capture */ |
|---|
| 1125 | | - f->flags = V4L2_FMT_FLAG_COMPRESSED; |
|---|
| 1126 | | - strcpy(f->description, "MJPEG"); |
|---|
| 1127 | 1110 | f->pixelformat = V4L2_PIX_FMT_MJPEG; |
|---|
| 1128 | 1111 | } |
|---|
| 1129 | 1112 | |
|---|
| .. | .. |
|---|
| 1283 | 1266 | buf->flags |= V4L2_BUF_FLAG_DONE; |
|---|
| 1284 | 1267 | |
|---|
| 1285 | 1268 | buf->field = V4L2_FIELD_NONE; |
|---|
| 1286 | | - buf->timestamp = meye.grab_buffer[index].timestamp; |
|---|
| 1269 | + v4l2_buffer_set_timestamp(buf, meye.grab_buffer[index].ts); |
|---|
| 1287 | 1270 | buf->sequence = meye.grab_buffer[index].sequence; |
|---|
| 1288 | 1271 | buf->memory = V4L2_MEMORY_MMAP; |
|---|
| 1289 | 1272 | buf->m.offset = index * gbufsize; |
|---|
| .. | .. |
|---|
| 1349 | 1332 | buf->bytesused = meye.grab_buffer[reqnr].size; |
|---|
| 1350 | 1333 | buf->flags = V4L2_BUF_FLAG_MAPPED | V4L2_BUF_FLAG_TIMESTAMP_MONOTONIC; |
|---|
| 1351 | 1334 | buf->field = V4L2_FIELD_NONE; |
|---|
| 1352 | | - buf->timestamp = meye.grab_buffer[reqnr].timestamp; |
|---|
| 1335 | + v4l2_buffer_set_timestamp(buf, meye.grab_buffer[reqnr].ts); |
|---|
| 1353 | 1336 | buf->sequence = meye.grab_buffer[reqnr].sequence; |
|---|
| 1354 | 1337 | buf->memory = V4L2_MEMORY_MMAP; |
|---|
| 1355 | 1338 | buf->m.offset = reqnr * gbufsize; |
|---|
| .. | .. |
|---|
| 1538 | 1521 | .fops = &meye_fops, |
|---|
| 1539 | 1522 | .ioctl_ops = &meye_ioctl_ops, |
|---|
| 1540 | 1523 | .release = video_device_release_empty, |
|---|
| 1524 | + .device_caps = V4L2_CAP_VIDEO_CAPTURE | V4L2_CAP_STREAMING, |
|---|
| 1541 | 1525 | }; |
|---|
| 1542 | 1526 | |
|---|
| 1543 | 1527 | static const struct v4l2_ctrl_ops meye_ctrl_ops = { |
|---|
| 1544 | 1528 | .s_ctrl = meye_s_ctrl, |
|---|
| 1545 | 1529 | }; |
|---|
| 1546 | 1530 | |
|---|
| 1547 | | -#ifdef CONFIG_PM |
|---|
| 1548 | | -static int meye_suspend(struct pci_dev *pdev, pm_message_t state) |
|---|
| 1531 | +static int __maybe_unused meye_suspend(struct device *dev) |
|---|
| 1549 | 1532 | { |
|---|
| 1550 | | - pci_save_state(pdev); |
|---|
| 1551 | 1533 | meye.pm_mchip_mode = meye.mchip_mode; |
|---|
| 1552 | 1534 | mchip_hic_stop(); |
|---|
| 1553 | 1535 | mchip_set(MCHIP_MM_INTA, 0x0); |
|---|
| 1554 | 1536 | return 0; |
|---|
| 1555 | 1537 | } |
|---|
| 1556 | 1538 | |
|---|
| 1557 | | -static int meye_resume(struct pci_dev *pdev) |
|---|
| 1539 | +static int __maybe_unused meye_resume(struct device *dev) |
|---|
| 1558 | 1540 | { |
|---|
| 1559 | | - pci_restore_state(pdev); |
|---|
| 1560 | 1541 | pci_write_config_word(meye.mchip_dev, MCHIP_PCI_SOFTRESET_SET, 1); |
|---|
| 1561 | 1542 | |
|---|
| 1562 | 1543 | mchip_delay(MCHIP_HIC_CMD, 0); |
|---|
| .. | .. |
|---|
| 1578 | 1559 | } |
|---|
| 1579 | 1560 | return 0; |
|---|
| 1580 | 1561 | } |
|---|
| 1581 | | -#endif |
|---|
| 1582 | 1562 | |
|---|
| 1583 | 1563 | static int meye_probe(struct pci_dev *pcidev, const struct pci_device_id *ent) |
|---|
| 1584 | 1564 | { |
|---|
| .. | .. |
|---|
| 1727 | 1707 | v4l2_ctrl_handler_setup(&meye.hdl); |
|---|
| 1728 | 1708 | meye.vdev.ctrl_handler = &meye.hdl; |
|---|
| 1729 | 1709 | |
|---|
| 1730 | | - if (video_register_device(&meye.vdev, VFL_TYPE_GRABBER, |
|---|
| 1710 | + if (video_register_device(&meye.vdev, VFL_TYPE_VIDEO, |
|---|
| 1731 | 1711 | video_nr) < 0) { |
|---|
| 1732 | 1712 | v4l2_err(v4l2_dev, "video_register_device failed\n"); |
|---|
| 1733 | 1713 | goto outvideoreg; |
|---|
| .. | .. |
|---|
| 1804 | 1784 | |
|---|
| 1805 | 1785 | MODULE_DEVICE_TABLE(pci, meye_pci_tbl); |
|---|
| 1806 | 1786 | |
|---|
| 1787 | +static SIMPLE_DEV_PM_OPS(meye_pm_ops, meye_suspend, meye_resume); |
|---|
| 1788 | + |
|---|
| 1807 | 1789 | static struct pci_driver meye_driver = { |
|---|
| 1808 | 1790 | .name = "meye", |
|---|
| 1809 | 1791 | .id_table = meye_pci_tbl, |
|---|
| 1810 | 1792 | .probe = meye_probe, |
|---|
| 1811 | 1793 | .remove = meye_remove, |
|---|
| 1812 | | -#ifdef CONFIG_PM |
|---|
| 1813 | | - .suspend = meye_suspend, |
|---|
| 1814 | | - .resume = meye_resume, |
|---|
| 1815 | | -#endif |
|---|
| 1794 | + .driver.pm = &meye_pm_ops, |
|---|
| 1816 | 1795 | }; |
|---|
| 1817 | 1796 | |
|---|
| 1818 | 1797 | static int __init meye_init(void) |
|---|