s2255drv.c (7ae9fb1b7ecbb5d85d07857943f677fd1a559b18) s2255drv.c (29ce81f9799166563c9548b4ab1614a7db3d9b89)
1// SPDX-License-Identifier: GPL-2.0-or-later
2/*
3 * s2255drv.c - a driver for the Sensoray 2255 USB video capture device
4 *
5 * Copyright (C) 2007-2014 by Sensoray Company Inc.
6 * Dean Anderson
7 *
8 * Some video buffer code based on vivi driver:

--- 233 unchanged lines hidden (view full) ---

242 struct mutex vb_lock; /* streaming lock */
243 spinlock_t qlock;
244};
245
246
247struct s2255_dev {
248 struct s2255_vc vc[MAX_CHANNELS];
249 struct v4l2_device v4l2_dev;
1// SPDX-License-Identifier: GPL-2.0-or-later
2/*
3 * s2255drv.c - a driver for the Sensoray 2255 USB video capture device
4 *
5 * Copyright (C) 2007-2014 by Sensoray Company Inc.
6 * Dean Anderson
7 *
8 * Some video buffer code based on vivi driver:

--- 233 unchanged lines hidden (view full) ---

242 struct mutex vb_lock; /* streaming lock */
243 spinlock_t qlock;
244};
245
246
247struct s2255_dev {
248 struct s2255_vc vc[MAX_CHANNELS];
249 struct v4l2_device v4l2_dev;
250 atomic_t num_channels;
250 refcount_t num_channels;
251 int frames;
252 struct mutex lock; /* channels[].vdev.lock */
253 struct mutex cmdlock; /* protects cmdbuf */
254 struct usb_device *udev;
255 struct usb_interface *interface;
256 u8 read_endpoint;
257 struct timer_list timer;
258 struct s2255_fw *fw_data;

--- 1286 unchanged lines hidden (view full) ---

1545
1546static void s2255_video_device_release(struct video_device *vdev)
1547{
1548 struct s2255_dev *dev = to_s2255_dev(vdev->v4l2_dev);
1549 struct s2255_vc *vc =
1550 container_of(vdev, struct s2255_vc, vdev);
1551
1552 dprintk(dev, 4, "%s, chnls: %d\n", __func__,
251 int frames;
252 struct mutex lock; /* channels[].vdev.lock */
253 struct mutex cmdlock; /* protects cmdbuf */
254 struct usb_device *udev;
255 struct usb_interface *interface;
256 u8 read_endpoint;
257 struct timer_list timer;
258 struct s2255_fw *fw_data;

--- 1286 unchanged lines hidden (view full) ---

1545
1546static void s2255_video_device_release(struct video_device *vdev)
1547{
1548 struct s2255_dev *dev = to_s2255_dev(vdev->v4l2_dev);
1549 struct s2255_vc *vc =
1550 container_of(vdev, struct s2255_vc, vdev);
1551
1552 dprintk(dev, 4, "%s, chnls: %d\n", __func__,
1553 atomic_read(&dev->num_channels));
1553 refcount_read(&dev->num_channels));
1554
1555 v4l2_ctrl_handler_free(&vc->hdl);
1556
1554
1555 v4l2_ctrl_handler_free(&vc->hdl);
1556
1557 if (atomic_dec_and_test(&dev->num_channels))
1557 if (refcount_dec_and_test(&dev->num_channels))
1558 s2255_destroy(dev);
1559 return;
1560}
1561
1562static const struct video_device template = {
1563 .name = "s2255v",
1564 .fops = &s2255_fops_v4l,
1565 .ioctl_ops = &s2255_ioctl_ops,

--- 88 unchanged lines hidden (view full) ---

1654 VFL_TYPE_VIDEO,
1655 cur_nr + i);
1656
1657 if (ret) {
1658 dev_err(&dev->udev->dev,
1659 "failed to register video device!\n");
1660 break;
1661 }
1558 s2255_destroy(dev);
1559 return;
1560}
1561
1562static const struct video_device template = {
1563 .name = "s2255v",
1564 .fops = &s2255_fops_v4l,
1565 .ioctl_ops = &s2255_ioctl_ops,

--- 88 unchanged lines hidden (view full) ---

1654 VFL_TYPE_VIDEO,
1655 cur_nr + i);
1656
1657 if (ret) {
1658 dev_err(&dev->udev->dev,
1659 "failed to register video device!\n");
1660 break;
1661 }
1662 atomic_inc(&dev->num_channels);
1662 refcount_inc(&dev->num_channels);
1663 v4l2_info(&dev->v4l2_dev, "V4L2 device registered as %s\n",
1664 video_device_node_name(&vc->vdev));
1665
1666 }
1667 pr_info("Sensoray 2255 V4L driver Revision: %s\n",
1668 S2255_VERSION);
1669 /* if no channels registered, return error and probe will fail*/
1663 v4l2_info(&dev->v4l2_dev, "V4L2 device registered as %s\n",
1664 video_device_node_name(&vc->vdev));
1665
1666 }
1667 pr_info("Sensoray 2255 V4L driver Revision: %s\n",
1668 S2255_VERSION);
1669 /* if no channels registered, return error and probe will fail*/
1670 if (atomic_read(&dev->num_channels) == 0) {
1670 if (refcount_read(&dev->num_channels) == 0) {
1671 v4l2_device_unregister(&dev->v4l2_dev);
1672 return ret;
1673 }
1671 v4l2_device_unregister(&dev->v4l2_dev);
1672 return ret;
1673 }
1674 if (atomic_read(&dev->num_channels) != MAX_CHANNELS)
1674 if (refcount_read(&dev->num_channels) != MAX_CHANNELS)
1675 pr_warn("s2255: Not all channels available.\n");
1676 return 0;
1677}
1678
1679/* this function moves the usb stream read pipe data
1680 * into the system buffers.
1681 * returns 0 on success, EAGAIN if more data to process( call this
1682 * function again).

--- 532 unchanged lines hidden (view full) ---

2215 }
2216
2217 dev->cmdbuf = kzalloc(S2255_CMDBUF_SIZE, GFP_KERNEL);
2218 if (dev->cmdbuf == NULL) {
2219 s2255_dev_err(&interface->dev, "out of memory\n");
2220 goto errorFWDATA1;
2221 }
2222
1675 pr_warn("s2255: Not all channels available.\n");
1676 return 0;
1677}
1678
1679/* this function moves the usb stream read pipe data
1680 * into the system buffers.
1681 * returns 0 on success, EAGAIN if more data to process( call this
1682 * function again).

--- 532 unchanged lines hidden (view full) ---

2215 }
2216
2217 dev->cmdbuf = kzalloc(S2255_CMDBUF_SIZE, GFP_KERNEL);
2218 if (dev->cmdbuf == NULL) {
2219 s2255_dev_err(&interface->dev, "out of memory\n");
2220 goto errorFWDATA1;
2221 }
2222
2223 atomic_set(&dev->num_channels, 0);
2223 refcount_set(&dev->num_channels, 0);
2224 dev->pid = id->idProduct;
2225 dev->fw_data = kzalloc(sizeof(struct s2255_fw), GFP_KERNEL);
2226 if (!dev->fw_data)
2227 goto errorFWDATA1;
2228 mutex_init(&dev->lock);
2229 mutex_init(&dev->cmdlock);
2230 /* grab usb_device and save it */
2231 dev->udev = usb_get_dev(interface_to_usbdev(interface));

--- 103 unchanged lines hidden (view full) ---

2335 return retval;
2336}
2337
2338/* disconnect routine. when board is removed physically or with rmmod */
2339static void s2255_disconnect(struct usb_interface *interface)
2340{
2341 struct s2255_dev *dev = to_s2255_dev(usb_get_intfdata(interface));
2342 int i;
2224 dev->pid = id->idProduct;
2225 dev->fw_data = kzalloc(sizeof(struct s2255_fw), GFP_KERNEL);
2226 if (!dev->fw_data)
2227 goto errorFWDATA1;
2228 mutex_init(&dev->lock);
2229 mutex_init(&dev->cmdlock);
2230 /* grab usb_device and save it */
2231 dev->udev = usb_get_dev(interface_to_usbdev(interface));

--- 103 unchanged lines hidden (view full) ---

2335 return retval;
2336}
2337
2338/* disconnect routine. when board is removed physically or with rmmod */
2339static void s2255_disconnect(struct usb_interface *interface)
2340{
2341 struct s2255_dev *dev = to_s2255_dev(usb_get_intfdata(interface));
2342 int i;
2343 int channels = atomic_read(&dev->num_channels);
2343 int channels = refcount_read(&dev->num_channels);
2344 mutex_lock(&dev->lock);
2345 v4l2_device_disconnect(&dev->v4l2_dev);
2346 mutex_unlock(&dev->lock);
2347 /*see comments in the uvc_driver.c usb disconnect function */
2344 mutex_lock(&dev->lock);
2345 v4l2_device_disconnect(&dev->v4l2_dev);
2346 mutex_unlock(&dev->lock);
2347 /*see comments in the uvc_driver.c usb disconnect function */
2348 atomic_inc(&dev->num_channels);
2348 refcount_inc(&dev->num_channels);
2349 /* unregister each video device. */
2350 for (i = 0; i < channels; i++)
2351 video_unregister_device(&dev->vc[i].vdev);
2352 /* wake up any of our timers */
2353 atomic_set(&dev->fw_data->fw_state, S2255_FW_DISCONNECTING);
2354 wake_up(&dev->fw_data->wait_fw);
2355 for (i = 0; i < MAX_CHANNELS; i++) {
2356 dev->vc[i].setmode_ready = 1;
2357 wake_up(&dev->vc[i].wait_setmode);
2358 dev->vc[i].vidstatus_ready = 1;
2359 wake_up(&dev->vc[i].wait_vidstatus);
2360 }
2349 /* unregister each video device. */
2350 for (i = 0; i < channels; i++)
2351 video_unregister_device(&dev->vc[i].vdev);
2352 /* wake up any of our timers */
2353 atomic_set(&dev->fw_data->fw_state, S2255_FW_DISCONNECTING);
2354 wake_up(&dev->fw_data->wait_fw);
2355 for (i = 0; i < MAX_CHANNELS; i++) {
2356 dev->vc[i].setmode_ready = 1;
2357 wake_up(&dev->vc[i].wait_setmode);
2358 dev->vc[i].vidstatus_ready = 1;
2359 wake_up(&dev->vc[i].wait_vidstatus);
2360 }
2361 if (atomic_dec_and_test(&dev->num_channels))
2361 if (refcount_dec_and_test(&dev->num_channels))
2362 s2255_destroy(dev);
2363 dev_info(&interface->dev, "%s\n", __func__);
2364}
2365
2366static struct usb_driver s2255_driver = {
2367 .name = S2255_DRIVER_NAME,
2368 .probe = s2255_probe,
2369 .disconnect = s2255_disconnect,
2370 .id_table = s2255_table,
2371};
2372
2373module_usb_driver(s2255_driver);
2374
2375MODULE_DESCRIPTION("Sensoray 2255 Video for Linux driver");
2376MODULE_AUTHOR("Dean Anderson (Sensoray Company Inc.)");
2377MODULE_LICENSE("GPL");
2378MODULE_VERSION(S2255_VERSION);
2379MODULE_FIRMWARE(FIRMWARE_FILE_NAME);
2362 s2255_destroy(dev);
2363 dev_info(&interface->dev, "%s\n", __func__);
2364}
2365
2366static struct usb_driver s2255_driver = {
2367 .name = S2255_DRIVER_NAME,
2368 .probe = s2255_probe,
2369 .disconnect = s2255_disconnect,
2370 .id_table = s2255_table,
2371};
2372
2373module_usb_driver(s2255_driver);
2374
2375MODULE_DESCRIPTION("Sensoray 2255 Video for Linux driver");
2376MODULE_AUTHOR("Dean Anderson (Sensoray Company Inc.)");
2377MODULE_LICENSE("GPL");
2378MODULE_VERSION(S2255_VERSION);
2379MODULE_FIRMWARE(FIRMWARE_FILE_NAME);