blob: ad2f3d27b2662092e0d3fa7f894b8486eb1920ba [file] [log] [blame]
Thierry MERLE483dfdb2006-12-04 08:31:45 -03001/*
Hans Verkuil3ff4ad82009-04-01 03:15:52 -03002 * USB USBVISION Video device driver 0.9.10
Thierry MERLE483dfdb2006-12-04 08:31:45 -03003 *
4 *
5 *
6 * Copyright (c) 1999-2005 Joerg Heckenbach <joerg@heckenbach-aw.de>
7 *
8 * This module is part of usbvision driver project.
9 *
10 * This program is free software; you can redistribute it and/or modify
11 * it under the terms of the GNU General Public License as published by
12 * the Free Software Foundation; either version 2 of the License, or
13 * (at your option) any later version.
14 *
15 * This program is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 * GNU General Public License for more details.
19 *
20 * You should have received a copy of the GNU General Public License
21 * along with this program; if not, write to the Free Software
22 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
23 *
24 * Let's call the version 0.... until compression decoding is completely
25 * implemented.
26 *
27 * This driver is written by Jose Ignacio Gijon and Joerg Heckenbach.
28 * It was based on USB CPiA driver written by Peter Pregler,
29 * Scott J. Bertin and Johannes Erdfelt
30 * Ideas are taken from bttv driver by Ralph Metzler, Marcus Metzler &
31 * Gerd Knorr and zoran 36120/36125 driver by Pauline Middelink
32 * Updates to driver completed by Dwaine P. Garden
33 *
34 *
35 * TODO:
36 * - use submit_urb for all setup packets
37 * - Fix memory settings for nt1004. It is 4 times as big as the
38 * nt1003 memory.
Thierry MERLEc5f48362007-05-08 17:22:29 -030039 * - Add audio on endpoint 3 for nt1004 chip.
40 * Seems impossible, needs a codec interface. Which one?
Thierry MERLE483dfdb2006-12-04 08:31:45 -030041 * - Clean up the driver.
42 * - optimization for performance.
43 * - Add Videotext capability (VBI). Working on it.....
44 * - Check audio for other devices
45 *
46 */
47
48#include <linux/kernel.h>
Thierry MERLE483dfdb2006-12-04 08:31:45 -030049#include <linux/list.h>
50#include <linux/timer.h>
51#include <linux/slab.h>
52#include <linux/mm.h>
Thierry MERLE483dfdb2006-12-04 08:31:45 -030053#include <linux/highmem.h>
Thierry MERLE483dfdb2006-12-04 08:31:45 -030054#include <linux/vmalloc.h>
55#include <linux/module.h>
56#include <linux/init.h>
57#include <linux/spinlock.h>
Hans Verkuil6d6a48e2010-12-29 13:53:21 -030058#include <linux/io.h>
Thierry MERLE483dfdb2006-12-04 08:31:45 -030059#include <linux/videodev2.h>
Thierry MERLE483dfdb2006-12-04 08:31:45 -030060#include <linux/i2c.h>
61
Mauro Carvalho Chehabb5dcee22015-11-10 12:01:44 -020062#include <media/i2c/saa7115.h>
Thierry MERLE483dfdb2006-12-04 08:31:45 -030063#include <media/v4l2-common.h>
Hans Verkuil35ea11f2008-07-20 08:12:02 -030064#include <media/v4l2-ioctl.h>
Hans Verkuilfd958702015-07-20 09:59:29 -030065#include <media/v4l2-event.h>
Thierry MERLE483dfdb2006-12-04 08:31:45 -030066#include <media/tuner.h>
Thierry MERLE483dfdb2006-12-04 08:31:45 -030067
Mauro Carvalho Chehaba1ed5512006-12-09 11:41:59 -030068#include <linux/workqueue.h>
Thierry MERLE483dfdb2006-12-04 08:31:45 -030069
Thierry MERLE483dfdb2006-12-04 08:31:45 -030070#include "usbvision.h"
Mauro Carvalho Chehab659ae562007-04-14 15:09:59 -030071#include "usbvision-cards.h"
Thierry MERLE483dfdb2006-12-04 08:31:45 -030072
Joe Perches85ee7a12011-04-23 20:38:19 -070073#define DRIVER_AUTHOR \
74 "Joerg Heckenbach <joerg@heckenbach-aw.de>, " \
75 "Dwaine Garden <DwaineGarden@rogers.com>"
Thierry MERLE483dfdb2006-12-04 08:31:45 -030076#define DRIVER_NAME "usbvision"
77#define DRIVER_ALIAS "USBVision"
78#define DRIVER_DESC "USBVision USB Video Device Driver for Linux"
79#define DRIVER_LICENSE "GPL"
Mauro Carvalho Chehab1990d502011-06-24 14:45:49 -030080#define USBVISION_VERSION_STRING "0.9.11"
Thierry MERLE483dfdb2006-12-04 08:31:45 -030081
82#define ENABLE_HEXDUMP 0 /* Enable if you need it */
83
84
Thierry MERLE483dfdb2006-12-04 08:31:45 -030085#ifdef USBVISION_DEBUG
Thierry MERLEdf18c312008-04-04 21:00:57 -030086 #define PDEBUG(level, fmt, args...) { \
Thierry MERLEc5f48362007-05-08 17:22:29 -030087 if (video_debug & (level)) \
Greg Kroah-Hartmana482f322008-10-10 05:08:23 -030088 printk(KERN_INFO KBUILD_MODNAME ":[%s:%d] " fmt, \
89 __func__, __LINE__ , ## args); \
Thierry MERLEdf18c312008-04-04 21:00:57 -030090 }
Thierry MERLE483dfdb2006-12-04 08:31:45 -030091#else
Hans Verkuil6d6a48e2010-12-29 13:53:21 -030092 #define PDEBUG(level, fmt, args...) do {} while (0)
Thierry MERLE483dfdb2006-12-04 08:31:45 -030093#endif
94
Hans Verkuil6d6a48e2010-12-29 13:53:21 -030095#define DBG_IO (1 << 1)
96#define DBG_PROBE (1 << 2)
97#define DBG_MMAP (1 << 3)
Thierry MERLE483dfdb2006-12-04 08:31:45 -030098
Hans Verkuil52cb0bf2010-12-19 20:33:51 -030099/* String operations */
Hans Verkuil6d6a48e2010-12-29 13:53:21 -0300100#define rmspace(str) while (*str == ' ') str++;
101#define goto2next(str) while (*str != ' ') str++; while (*str == ' ') str++;
Thierry MERLE483dfdb2006-12-04 08:31:45 -0300102
103
Thierry MERLEc5f48362007-05-08 17:22:29 -0300104/* sequential number of usbvision device */
Douglas Schilling Landgrafff699e62008-04-22 14:41:48 -0300105static int usbvision_nr;
Thierry MERLE483dfdb2006-12-04 08:31:45 -0300106
107static struct usbvision_v4l2_format_st usbvision_v4l2_format[] = {
108 { 1, 1, 8, V4L2_PIX_FMT_GREY , "GREY" },
109 { 1, 2, 16, V4L2_PIX_FMT_RGB565 , "RGB565" },
110 { 1, 3, 24, V4L2_PIX_FMT_RGB24 , "RGB24" },
111 { 1, 4, 32, V4L2_PIX_FMT_RGB32 , "RGB32" },
112 { 1, 2, 16, V4L2_PIX_FMT_RGB555 , "RGB555" },
113 { 1, 2, 16, V4L2_PIX_FMT_YUYV , "YUV422" },
Hans Verkuil52cb0bf2010-12-19 20:33:51 -0300114 { 1, 2, 12, V4L2_PIX_FMT_YVU420 , "YUV420P" }, /* 1.5 ! */
Thierry MERLE483dfdb2006-12-04 08:31:45 -0300115 { 1, 2, 16, V4L2_PIX_FMT_YUV422P , "YUV422P" }
116};
117
Thierry MERLEc5f48362007-05-08 17:22:29 -0300118/* Function prototypes */
Thierry MERLE483dfdb2006-12-04 08:31:45 -0300119static void usbvision_release(struct usb_usbvision *usbvision);
120
Joe Perchesc84e6032008-02-03 17:18:59 +0200121/* Default initialization of device driver parameters */
Thierry MERLEc5f48362007-05-08 17:22:29 -0300122/* Set the default format for ISOC endpoint */
Hans Verkuil5490a7c2010-12-19 20:21:36 -0300123static int isoc_mode = ISOC_MODE_COMPRESS;
Thierry MERLEc5f48362007-05-08 17:22:29 -0300124/* Set the default Debug Mode of the device driver */
Douglas Schilling Landgrafff699e62008-04-22 14:41:48 -0300125static int video_debug;
Thierry MERLEc5f48362007-05-08 17:22:29 -0300126/* Sequential Number of Video Device */
127static int video_nr = -1;
128/* Sequential Number of Radio Device */
129static int radio_nr = -1;
Thierry MERLE483dfdb2006-12-04 08:31:45 -0300130
Thierry MERLEc5f48362007-05-08 17:22:29 -0300131/* Grab parameters for the device driver */
Thierry MERLE483dfdb2006-12-04 08:31:45 -0300132
Thierry MERLEc5f48362007-05-08 17:22:29 -0300133/* Showing parameters under SYSFS */
Hans Verkuil5490a7c2010-12-19 20:21:36 -0300134module_param(isoc_mode, int, 0444);
Thierry MERLE483dfdb2006-12-04 08:31:45 -0300135module_param(video_debug, int, 0444);
Thierry MERLE483dfdb2006-12-04 08:31:45 -0300136module_param(video_nr, int, 0444);
137module_param(radio_nr, int, 0444);
Thierry MERLE483dfdb2006-12-04 08:31:45 -0300138
Hans Verkuil5490a7c2010-12-19 20:21:36 -0300139MODULE_PARM_DESC(isoc_mode, " Set the default format for ISOC endpoint. Default: 0x60 (Compression On)");
Thierry MERLE483dfdb2006-12-04 08:31:45 -0300140MODULE_PARM_DESC(video_debug, " Set the default Debug Mode of the device driver. Default: 0 (Off)");
Thierry MERLE483dfdb2006-12-04 08:31:45 -0300141MODULE_PARM_DESC(video_nr, "Set video device number (/dev/videoX). Default: -1 (autodetect)");
142MODULE_PARM_DESC(radio_nr, "Set radio device number (/dev/radioX). Default: -1 (autodetect)");
Thierry MERLE483dfdb2006-12-04 08:31:45 -0300143
144
Hans Verkuil52cb0bf2010-12-19 20:33:51 -0300145/* Misc stuff */
Thierry MERLE483dfdb2006-12-04 08:31:45 -0300146MODULE_AUTHOR(DRIVER_AUTHOR);
147MODULE_DESCRIPTION(DRIVER_DESC);
148MODULE_LICENSE(DRIVER_LICENSE);
Mauro Carvalho Chehaba1ed5512006-12-09 11:41:59 -0300149MODULE_VERSION(USBVISION_VERSION_STRING);
150MODULE_ALIAS(DRIVER_ALIAS);
Thierry MERLE483dfdb2006-12-04 08:31:45 -0300151
152
Thierry MERLEc5f48362007-05-08 17:22:29 -0300153/*****************************************************************************/
154/* SYSFS Code - Copied from the stv680.c usb module. */
155/* Device information is located at /sys/class/video4linux/video0 */
156/* Device parameters information is located at /sys/module/usbvision */
157/* Device USB Information is located at */
158/* /sys/bus/usb/drivers/USBVision Video Grabber */
159/*****************************************************************************/
Thierry MERLE483dfdb2006-12-04 08:31:45 -0300160
Thierry MERLE483dfdb2006-12-04 08:31:45 -0300161#define YES_NO(x) ((x) ? "Yes" : "No")
162
Kay Sievers54bd5b62007-10-08 16:26:13 -0300163static inline struct usb_usbvision *cd_to_usbvision(struct device *cd)
Thierry MERLE483dfdb2006-12-04 08:31:45 -0300164{
Geliang Tang03c6bdf2015-12-22 13:38:04 -0200165 struct video_device *vdev = to_video_device(cd);
Thierry MERLE483dfdb2006-12-04 08:31:45 -0300166 return video_get_drvdata(vdev);
167}
168
Kay Sievers54bd5b62007-10-08 16:26:13 -0300169static ssize_t show_version(struct device *cd,
170 struct device_attribute *attr, char *buf)
Thierry MERLE483dfdb2006-12-04 08:31:45 -0300171{
172 return sprintf(buf, "%s\n", USBVISION_VERSION_STRING);
173}
Kay Sievers54bd5b62007-10-08 16:26:13 -0300174static DEVICE_ATTR(version, S_IRUGO, show_version, NULL);
Thierry MERLE483dfdb2006-12-04 08:31:45 -0300175
Kay Sievers54bd5b62007-10-08 16:26:13 -0300176static ssize_t show_model(struct device *cd,
177 struct device_attribute *attr, char *buf)
Thierry MERLE483dfdb2006-12-04 08:31:45 -0300178{
Geliang Tang03c6bdf2015-12-22 13:38:04 -0200179 struct video_device *vdev = to_video_device(cd);
Thierry MERLE483dfdb2006-12-04 08:31:45 -0300180 struct usb_usbvision *usbvision = video_get_drvdata(vdev);
Thierry MERLEc5f48362007-05-08 17:22:29 -0300181 return sprintf(buf, "%s\n",
Hans Verkuil5490a7c2010-12-19 20:21:36 -0300182 usbvision_device_data[usbvision->dev_model].model_string);
Thierry MERLE483dfdb2006-12-04 08:31:45 -0300183}
Kay Sievers54bd5b62007-10-08 16:26:13 -0300184static DEVICE_ATTR(model, S_IRUGO, show_model, NULL);
Thierry MERLE483dfdb2006-12-04 08:31:45 -0300185
Kay Sievers54bd5b62007-10-08 16:26:13 -0300186static ssize_t show_hue(struct device *cd,
187 struct device_attribute *attr, char *buf)
Thierry MERLE483dfdb2006-12-04 08:31:45 -0300188{
Geliang Tang03c6bdf2015-12-22 13:38:04 -0200189 struct video_device *vdev = to_video_device(cd);
Thierry MERLE483dfdb2006-12-04 08:31:45 -0300190 struct usb_usbvision *usbvision = video_get_drvdata(vdev);
191 struct v4l2_control ctrl;
192 ctrl.id = V4L2_CID_HUE;
193 ctrl.value = 0;
Hans Verkuil6d6a48e2010-12-29 13:53:21 -0300194 if (usbvision->user)
Hans Verkuil1df79532009-02-21 18:11:31 -0300195 call_all(usbvision, core, g_ctrl, &ctrl);
Thierry MERLE2a9f8b52007-02-07 10:14:38 -0300196 return sprintf(buf, "%d\n", ctrl.value);
Thierry MERLE483dfdb2006-12-04 08:31:45 -0300197}
Kay Sievers54bd5b62007-10-08 16:26:13 -0300198static DEVICE_ATTR(hue, S_IRUGO, show_hue, NULL);
Thierry MERLE483dfdb2006-12-04 08:31:45 -0300199
Kay Sievers54bd5b62007-10-08 16:26:13 -0300200static ssize_t show_contrast(struct device *cd,
201 struct device_attribute *attr, char *buf)
Thierry MERLE483dfdb2006-12-04 08:31:45 -0300202{
Geliang Tang03c6bdf2015-12-22 13:38:04 -0200203 struct video_device *vdev = to_video_device(cd);
Thierry MERLE483dfdb2006-12-04 08:31:45 -0300204 struct usb_usbvision *usbvision = video_get_drvdata(vdev);
205 struct v4l2_control ctrl;
206 ctrl.id = V4L2_CID_CONTRAST;
207 ctrl.value = 0;
Hans Verkuil6d6a48e2010-12-29 13:53:21 -0300208 if (usbvision->user)
Hans Verkuil1df79532009-02-21 18:11:31 -0300209 call_all(usbvision, core, g_ctrl, &ctrl);
Thierry MERLE2a9f8b52007-02-07 10:14:38 -0300210 return sprintf(buf, "%d\n", ctrl.value);
Thierry MERLE483dfdb2006-12-04 08:31:45 -0300211}
Kay Sievers54bd5b62007-10-08 16:26:13 -0300212static DEVICE_ATTR(contrast, S_IRUGO, show_contrast, NULL);
Thierry MERLE483dfdb2006-12-04 08:31:45 -0300213
Kay Sievers54bd5b62007-10-08 16:26:13 -0300214static ssize_t show_brightness(struct device *cd,
215 struct device_attribute *attr, char *buf)
Thierry MERLE483dfdb2006-12-04 08:31:45 -0300216{
Geliang Tang03c6bdf2015-12-22 13:38:04 -0200217 struct video_device *vdev = to_video_device(cd);
Thierry MERLE483dfdb2006-12-04 08:31:45 -0300218 struct usb_usbvision *usbvision = video_get_drvdata(vdev);
219 struct v4l2_control ctrl;
220 ctrl.id = V4L2_CID_BRIGHTNESS;
221 ctrl.value = 0;
Hans Verkuil6d6a48e2010-12-29 13:53:21 -0300222 if (usbvision->user)
Hans Verkuil1df79532009-02-21 18:11:31 -0300223 call_all(usbvision, core, g_ctrl, &ctrl);
Thierry MERLE2a9f8b52007-02-07 10:14:38 -0300224 return sprintf(buf, "%d\n", ctrl.value);
Thierry MERLE483dfdb2006-12-04 08:31:45 -0300225}
Kay Sievers54bd5b62007-10-08 16:26:13 -0300226static DEVICE_ATTR(brightness, S_IRUGO, show_brightness, NULL);
Thierry MERLE483dfdb2006-12-04 08:31:45 -0300227
Kay Sievers54bd5b62007-10-08 16:26:13 -0300228static ssize_t show_saturation(struct device *cd,
229 struct device_attribute *attr, char *buf)
Thierry MERLE483dfdb2006-12-04 08:31:45 -0300230{
Geliang Tang03c6bdf2015-12-22 13:38:04 -0200231 struct video_device *vdev = to_video_device(cd);
Thierry MERLE483dfdb2006-12-04 08:31:45 -0300232 struct usb_usbvision *usbvision = video_get_drvdata(vdev);
233 struct v4l2_control ctrl;
234 ctrl.id = V4L2_CID_SATURATION;
235 ctrl.value = 0;
Hans Verkuil6d6a48e2010-12-29 13:53:21 -0300236 if (usbvision->user)
Hans Verkuil1df79532009-02-21 18:11:31 -0300237 call_all(usbvision, core, g_ctrl, &ctrl);
Thierry MERLE2a9f8b52007-02-07 10:14:38 -0300238 return sprintf(buf, "%d\n", ctrl.value);
Thierry MERLE483dfdb2006-12-04 08:31:45 -0300239}
Kay Sievers54bd5b62007-10-08 16:26:13 -0300240static DEVICE_ATTR(saturation, S_IRUGO, show_saturation, NULL);
Thierry MERLE483dfdb2006-12-04 08:31:45 -0300241
Kay Sievers54bd5b62007-10-08 16:26:13 -0300242static ssize_t show_streaming(struct device *cd,
243 struct device_attribute *attr, char *buf)
Thierry MERLE483dfdb2006-12-04 08:31:45 -0300244{
Geliang Tang03c6bdf2015-12-22 13:38:04 -0200245 struct video_device *vdev = to_video_device(cd);
Thierry MERLE483dfdb2006-12-04 08:31:45 -0300246 struct usb_usbvision *usbvision = video_get_drvdata(vdev);
Thierry MERLEc5f48362007-05-08 17:22:29 -0300247 return sprintf(buf, "%s\n",
Hans Verkuil6d6a48e2010-12-29 13:53:21 -0300248 YES_NO(usbvision->streaming == stream_on ? 1 : 0));
Thierry MERLE483dfdb2006-12-04 08:31:45 -0300249}
Kay Sievers54bd5b62007-10-08 16:26:13 -0300250static DEVICE_ATTR(streaming, S_IRUGO, show_streaming, NULL);
Thierry MERLE483dfdb2006-12-04 08:31:45 -0300251
Kay Sievers54bd5b62007-10-08 16:26:13 -0300252static ssize_t show_compression(struct device *cd,
253 struct device_attribute *attr, char *buf)
Thierry MERLE483dfdb2006-12-04 08:31:45 -0300254{
Geliang Tang03c6bdf2015-12-22 13:38:04 -0200255 struct video_device *vdev = to_video_device(cd);
Thierry MERLE483dfdb2006-12-04 08:31:45 -0300256 struct usb_usbvision *usbvision = video_get_drvdata(vdev);
Thierry MERLEc5f48362007-05-08 17:22:29 -0300257 return sprintf(buf, "%s\n",
Hans Verkuil6d6a48e2010-12-29 13:53:21 -0300258 YES_NO(usbvision->isoc_mode == ISOC_MODE_COMPRESS));
Thierry MERLE483dfdb2006-12-04 08:31:45 -0300259}
Kay Sievers54bd5b62007-10-08 16:26:13 -0300260static DEVICE_ATTR(compression, S_IRUGO, show_compression, NULL);
Thierry MERLE483dfdb2006-12-04 08:31:45 -0300261
Kay Sievers54bd5b62007-10-08 16:26:13 -0300262static ssize_t show_device_bridge(struct device *cd,
263 struct device_attribute *attr, char *buf)
Thierry MERLE483dfdb2006-12-04 08:31:45 -0300264{
Geliang Tang03c6bdf2015-12-22 13:38:04 -0200265 struct video_device *vdev = to_video_device(cd);
Thierry MERLE483dfdb2006-12-04 08:31:45 -0300266 struct usb_usbvision *usbvision = video_get_drvdata(vdev);
Hans Verkuil5490a7c2010-12-19 20:21:36 -0300267 return sprintf(buf, "%d\n", usbvision->bridge_type);
Thierry MERLE483dfdb2006-12-04 08:31:45 -0300268}
Kay Sievers54bd5b62007-10-08 16:26:13 -0300269static DEVICE_ATTR(bridge, S_IRUGO, show_device_bridge, NULL);
Thierry MERLE483dfdb2006-12-04 08:31:45 -0300270
271static void usbvision_create_sysfs(struct video_device *vdev)
272{
273 int res;
Hans Verkuil6d6a48e2010-12-29 13:53:21 -0300274
Dwaine Gardened00b412006-12-27 10:23:28 -0200275 if (!vdev)
276 return;
277 do {
Hans Verkuil22a04f12008-07-20 06:35:02 -0300278 res = device_create_file(&vdev->dev, &dev_attr_version);
Hans Verkuil6d6a48e2010-12-29 13:53:21 -0300279 if (res < 0)
Dwaine Gardened00b412006-12-27 10:23:28 -0200280 break;
Hans Verkuil22a04f12008-07-20 06:35:02 -0300281 res = device_create_file(&vdev->dev, &dev_attr_model);
Hans Verkuil6d6a48e2010-12-29 13:53:21 -0300282 if (res < 0)
Dwaine Gardened00b412006-12-27 10:23:28 -0200283 break;
Hans Verkuil22a04f12008-07-20 06:35:02 -0300284 res = device_create_file(&vdev->dev, &dev_attr_hue);
Hans Verkuil6d6a48e2010-12-29 13:53:21 -0300285 if (res < 0)
Dwaine Gardened00b412006-12-27 10:23:28 -0200286 break;
Hans Verkuil22a04f12008-07-20 06:35:02 -0300287 res = device_create_file(&vdev->dev, &dev_attr_contrast);
Hans Verkuil6d6a48e2010-12-29 13:53:21 -0300288 if (res < 0)
Dwaine Gardened00b412006-12-27 10:23:28 -0200289 break;
Hans Verkuil22a04f12008-07-20 06:35:02 -0300290 res = device_create_file(&vdev->dev, &dev_attr_brightness);
Hans Verkuil6d6a48e2010-12-29 13:53:21 -0300291 if (res < 0)
Dwaine Gardened00b412006-12-27 10:23:28 -0200292 break;
Hans Verkuil22a04f12008-07-20 06:35:02 -0300293 res = device_create_file(&vdev->dev, &dev_attr_saturation);
Hans Verkuil6d6a48e2010-12-29 13:53:21 -0300294 if (res < 0)
Dwaine Gardened00b412006-12-27 10:23:28 -0200295 break;
Hans Verkuil22a04f12008-07-20 06:35:02 -0300296 res = device_create_file(&vdev->dev, &dev_attr_streaming);
Hans Verkuil6d6a48e2010-12-29 13:53:21 -0300297 if (res < 0)
Dwaine Gardened00b412006-12-27 10:23:28 -0200298 break;
Hans Verkuil22a04f12008-07-20 06:35:02 -0300299 res = device_create_file(&vdev->dev, &dev_attr_compression);
Hans Verkuil6d6a48e2010-12-29 13:53:21 -0300300 if (res < 0)
Dwaine Gardened00b412006-12-27 10:23:28 -0200301 break;
Hans Verkuil22a04f12008-07-20 06:35:02 -0300302 res = device_create_file(&vdev->dev, &dev_attr_bridge);
Hans Verkuil6d6a48e2010-12-29 13:53:21 -0300303 if (res >= 0)
Dwaine Gardened00b412006-12-27 10:23:28 -0200304 return;
305 } while (0);
306
Mauro Carvalho Chehabbe9ed512009-01-08 09:13:42 -0300307 dev_err(&vdev->dev, "%s error: %d\n", __func__, res);
Thierry MERLE483dfdb2006-12-04 08:31:45 -0300308}
309
310static void usbvision_remove_sysfs(struct video_device *vdev)
311{
312 if (vdev) {
Hans Verkuil22a04f12008-07-20 06:35:02 -0300313 device_remove_file(&vdev->dev, &dev_attr_version);
314 device_remove_file(&vdev->dev, &dev_attr_model);
315 device_remove_file(&vdev->dev, &dev_attr_hue);
316 device_remove_file(&vdev->dev, &dev_attr_contrast);
317 device_remove_file(&vdev->dev, &dev_attr_brightness);
318 device_remove_file(&vdev->dev, &dev_attr_saturation);
319 device_remove_file(&vdev->dev, &dev_attr_streaming);
320 device_remove_file(&vdev->dev, &dev_attr_compression);
321 device_remove_file(&vdev->dev, &dev_attr_bridge);
Thierry MERLE483dfdb2006-12-04 08:31:45 -0300322 }
323}
324
Thierry MERLE483dfdb2006-12-04 08:31:45 -0300325/*
326 * usbvision_open()
327 *
328 * This is part of Video 4 Linux API. The driver can be opened by one
329 * client only (checks internal counter 'usbvision->user'). The procedure
330 * then allocates buffers needed for video processing.
331 *
332 */
Hans Verkuilbec43662008-12-30 06:58:20 -0300333static int usbvision_v4l2_open(struct file *file)
Thierry MERLE483dfdb2006-12-04 08:31:45 -0300334{
Hans Verkuilc170ecf2008-08-23 08:32:09 -0300335 struct usb_usbvision *usbvision = video_drvdata(file);
Hans Verkuil5490a7c2010-12-19 20:21:36 -0300336 int err_code = 0;
Thierry MERLE483dfdb2006-12-04 08:31:45 -0300337
338 PDEBUG(DBG_IO, "open");
339
Hans Verkuil4d345702012-06-23 08:03:50 -0300340 if (mutex_lock_interruptible(&usbvision->v4l2_lock))
341 return -ERESTARTSYS;
Thierry MERLE483dfdb2006-12-04 08:31:45 -0300342
Hans Verkuil62e25942015-07-20 09:59:28 -0300343 if (usbvision->user) {
Hans Verkuil5490a7c2010-12-19 20:21:36 -0300344 err_code = -EBUSY;
Hans Verkuil62e25942015-07-20 09:59:28 -0300345 } else {
Hans Verkuilfd958702015-07-20 09:59:29 -0300346 err_code = v4l2_fh_open(file);
347 if (err_code)
348 goto unlock;
349
Thierry MERLE6f78e182007-02-07 10:13:11 -0300350 /* Allocate memory for the scratch ring buffer */
Hans Verkuil5490a7c2010-12-19 20:21:36 -0300351 err_code = usbvision_scratch_alloc(usbvision);
Hans Verkuil6d6a48e2010-12-29 13:53:21 -0300352 if (isoc_mode == ISOC_MODE_COMPRESS) {
Thierry MERLEc5f48362007-05-08 17:22:29 -0300353 /* Allocate intermediate decompression buffers
354 only if needed */
Hans Verkuil5490a7c2010-12-19 20:21:36 -0300355 err_code = usbvision_decompress_alloc(usbvision);
Thierry MERLE483dfdb2006-12-04 08:31:45 -0300356 }
Hans Verkuil5490a7c2010-12-19 20:21:36 -0300357 if (err_code) {
Thierry MERLE483dfdb2006-12-04 08:31:45 -0300358 /* Deallocate all buffers if trouble */
Thierry MERLE483dfdb2006-12-04 08:31:45 -0300359 usbvision_scratch_free(usbvision);
Thierry MERLE483dfdb2006-12-04 08:31:45 -0300360 usbvision_decompress_free(usbvision);
361 }
362 }
363
364 /* If so far no errors then we shall start the camera */
Hans Verkuil5490a7c2010-12-19 20:21:36 -0300365 if (!err_code) {
Thierry MERLE483dfdb2006-12-04 08:31:45 -0300366 /* Send init sequence only once, it's large! */
367 if (!usbvision->initialized) {
368 int setup_ok = 0;
Hans Verkuil6d6a48e2010-12-29 13:53:21 -0300369 setup_ok = usbvision_setup(usbvision, isoc_mode);
Thierry MERLE483dfdb2006-12-04 08:31:45 -0300370 if (setup_ok)
371 usbvision->initialized = 1;
372 else
Hans Verkuil5490a7c2010-12-19 20:21:36 -0300373 err_code = -EBUSY;
Thierry MERLE483dfdb2006-12-04 08:31:45 -0300374 }
375
Hans Verkuil5490a7c2010-12-19 20:21:36 -0300376 if (!err_code) {
Thierry MERLE483dfdb2006-12-04 08:31:45 -0300377 usbvision_begin_streaming(usbvision);
Hans Verkuil5490a7c2010-12-19 20:21:36 -0300378 err_code = usbvision_init_isoc(usbvision);
Thierry MERLEc5f48362007-05-08 17:22:29 -0300379 /* device must be initialized before isoc transfer */
Hans Verkuil6d6a48e2010-12-29 13:53:21 -0300380 usbvision_muxsel(usbvision, 0);
Hans Verkuil62e25942015-07-20 09:59:28 -0300381
382 /* prepare queues */
383 usbvision_empty_framequeues(usbvision);
Thierry MERLE483dfdb2006-12-04 08:31:45 -0300384 usbvision->user++;
Thierry MERLE483dfdb2006-12-04 08:31:45 -0300385 }
Thierry MERLE483dfdb2006-12-04 08:31:45 -0300386 }
387
Hans Verkuilfd958702015-07-20 09:59:29 -0300388unlock:
Hans Verkuil4d345702012-06-23 08:03:50 -0300389 mutex_unlock(&usbvision->v4l2_lock);
Thierry MERLE483dfdb2006-12-04 08:31:45 -0300390
391 PDEBUG(DBG_IO, "success");
Hans Verkuil5490a7c2010-12-19 20:21:36 -0300392 return err_code;
Thierry MERLE483dfdb2006-12-04 08:31:45 -0300393}
394
395/*
396 * usbvision_v4l2_close()
397 *
398 * This is part of Video 4 Linux API. The procedure
399 * stops streaming and deallocates all buffers that were earlier
400 * allocated in usbvision_v4l2_open().
401 *
402 */
Hans Verkuilbec43662008-12-30 06:58:20 -0300403static int usbvision_v4l2_close(struct file *file)
Thierry MERLE483dfdb2006-12-04 08:31:45 -0300404{
Hans Verkuilc170ecf2008-08-23 08:32:09 -0300405 struct usb_usbvision *usbvision = video_drvdata(file);
Thierry MERLE483dfdb2006-12-04 08:31:45 -0300406
407 PDEBUG(DBG_IO, "close");
Thierry MERLE483dfdb2006-12-04 08:31:45 -0300408
Hans Verkuil4d345702012-06-23 08:03:50 -0300409 mutex_lock(&usbvision->v4l2_lock);
Thierry MERLE483dfdb2006-12-04 08:31:45 -0300410 usbvision_audio_off(usbvision);
411 usbvision_restart_isoc(usbvision);
412 usbvision_stop_isoc(usbvision);
413
414 usbvision_decompress_free(usbvision);
Thierry MERLE38284ba2006-12-15 16:46:53 -0300415 usbvision_frames_free(usbvision);
Thierry MERLE6f78e182007-02-07 10:13:11 -0300416 usbvision_empty_framequeues(usbvision);
Thierry MERLE483dfdb2006-12-04 08:31:45 -0300417 usbvision_scratch_free(usbvision);
Thierry MERLE483dfdb2006-12-04 08:31:45 -0300418
419 usbvision->user--;
Hans Verkuile2c84cc2015-07-20 09:59:35 -0300420 mutex_unlock(&usbvision->v4l2_lock);
Thierry MERLE483dfdb2006-12-04 08:31:45 -0300421
Thierry MERLE483dfdb2006-12-04 08:31:45 -0300422 if (usbvision->remove_pending) {
Harvey Harrisond2db42d2008-04-04 20:50:07 -0300423 printk(KERN_INFO "%s: Final disconnect\n", __func__);
Thierry MERLE483dfdb2006-12-04 08:31:45 -0300424 usbvision_release(usbvision);
Dan Carpenter470a9142014-10-16 04:57:21 -0300425 return 0;
Thierry MERLE483dfdb2006-12-04 08:31:45 -0300426 }
427
428 PDEBUG(DBG_IO, "success");
Hans Verkuilfd958702015-07-20 09:59:29 -0300429 return v4l2_fh_release(file);
Thierry MERLE483dfdb2006-12-04 08:31:45 -0300430}
431
432
433/*
434 * usbvision_ioctl()
435 *
436 * This is part of Video 4 Linux API. The procedure handles ioctl() calls.
437 *
438 */
Thierry MERLEc5f48362007-05-08 17:22:29 -0300439#ifdef CONFIG_VIDEO_ADV_DEBUG
Hans Verkuil6d6a48e2010-12-29 13:53:21 -0300440static int vidioc_g_register(struct file *file, void *priv,
Hans Verkuilaecde8b52008-12-30 07:14:19 -0300441 struct v4l2_dbg_register *reg)
Thierry MERLE483dfdb2006-12-04 08:31:45 -0300442{
Hans Verkuilc170ecf2008-08-23 08:32:09 -0300443 struct usb_usbvision *usbvision = video_drvdata(file);
Hans Verkuil5490a7c2010-12-19 20:21:36 -0300444 int err_code;
Thierry MERLE483dfdb2006-12-04 08:31:45 -0300445
Thierry MERLEc5f48362007-05-08 17:22:29 -0300446 /* NT100x has a 8-bit register space */
Hans Verkuil5490a7c2010-12-19 20:21:36 -0300447 err_code = usbvision_read_reg(usbvision, reg->reg&0xff);
448 if (err_code < 0) {
Hans Verkuil2aa689d2015-03-09 13:34:12 -0300449 dev_err(&usbvision->vdev.dev,
Mauro Carvalho Chehabbe9ed512009-01-08 09:13:42 -0300450 "%s: VIDIOC_DBG_G_REGISTER failed: error %d\n",
Hans Verkuil5490a7c2010-12-19 20:21:36 -0300451 __func__, err_code);
452 return err_code;
Thierry MERLE483dfdb2006-12-04 08:31:45 -0300453 }
Hans Verkuil5490a7c2010-12-19 20:21:36 -0300454 reg->val = err_code;
Hans Verkuilaecde8b52008-12-30 07:14:19 -0300455 reg->size = 1;
Thierry MERLE483dfdb2006-12-04 08:31:45 -0300456 return 0;
457}
458
Hans Verkuil6d6a48e2010-12-29 13:53:21 -0300459static int vidioc_s_register(struct file *file, void *priv,
Hans Verkuil977ba3b2013-03-24 08:28:46 -0300460 const struct v4l2_dbg_register *reg)
Thierry MERLE483dfdb2006-12-04 08:31:45 -0300461{
Hans Verkuilc170ecf2008-08-23 08:32:09 -0300462 struct usb_usbvision *usbvision = video_drvdata(file);
Hans Verkuil5490a7c2010-12-19 20:21:36 -0300463 int err_code;
Thierry MERLEc5f48362007-05-08 17:22:29 -0300464
Thierry MERLEc5f48362007-05-08 17:22:29 -0300465 /* NT100x has a 8-bit register space */
Hans Verkuil6d6a48e2010-12-29 13:53:21 -0300466 err_code = usbvision_write_reg(usbvision, reg->reg & 0xff, reg->val);
Hans Verkuil5490a7c2010-12-19 20:21:36 -0300467 if (err_code < 0) {
Hans Verkuil2aa689d2015-03-09 13:34:12 -0300468 dev_err(&usbvision->vdev.dev,
Mauro Carvalho Chehabbe9ed512009-01-08 09:13:42 -0300469 "%s: VIDIOC_DBG_S_REGISTER failed: error %d\n",
Hans Verkuil5490a7c2010-12-19 20:21:36 -0300470 __func__, err_code);
471 return err_code;
Thierry MERLEc5f48362007-05-08 17:22:29 -0300472 }
473 return 0;
474}
475#endif
476
Hans Verkuil6d6a48e2010-12-29 13:53:21 -0300477static int vidioc_querycap(struct file *file, void *priv,
Thierry MERLEc5f48362007-05-08 17:22:29 -0300478 struct v4l2_capability *vc)
479{
Hans Verkuilc170ecf2008-08-23 08:32:09 -0300480 struct usb_usbvision *usbvision = video_drvdata(file);
Hans Verkuilcbe12cc2015-07-20 09:59:32 -0300481 struct video_device *vdev = video_devdata(file);
Thierry MERLEc5f48362007-05-08 17:22:29 -0300482
483 strlcpy(vc->driver, "USBVision", sizeof(vc->driver));
484 strlcpy(vc->card,
Hans Verkuil5490a7c2010-12-19 20:21:36 -0300485 usbvision_device_data[usbvision->dev_model].model_string,
Thierry MERLEc5f48362007-05-08 17:22:29 -0300486 sizeof(vc->card));
Thierry MERLE6f2a2782009-01-20 17:40:44 -0300487 usb_make_path(usbvision->dev, vc->bus_info, sizeof(vc->bus_info));
Hans Verkuilcbe12cc2015-07-20 09:59:32 -0300488 vc->device_caps = usbvision->have_tuner ? V4L2_CAP_TUNER : 0;
489 if (vdev->vfl_type == VFL_TYPE_GRABBER)
490 vc->device_caps |= V4L2_CAP_VIDEO_CAPTURE |
491 V4L2_CAP_READWRITE | V4L2_CAP_STREAMING;
492 else
493 vc->device_caps |= V4L2_CAP_RADIO;
494
495 vc->capabilities = vc->device_caps | V4L2_CAP_VIDEO_CAPTURE |
496 V4L2_CAP_READWRITE | V4L2_CAP_STREAMING | V4L2_CAP_DEVICE_CAPS;
497 if (usbvision_device_data[usbvision->dev_model].radio)
498 vc->capabilities |= V4L2_CAP_RADIO;
Thierry MERLEc5f48362007-05-08 17:22:29 -0300499 return 0;
Thierry MERLE483dfdb2006-12-04 08:31:45 -0300500}
501
Hans Verkuil6d6a48e2010-12-29 13:53:21 -0300502static int vidioc_enum_input(struct file *file, void *priv,
Thierry MERLEc5f48362007-05-08 17:22:29 -0300503 struct v4l2_input *vi)
504{
Hans Verkuilc170ecf2008-08-23 08:32:09 -0300505 struct usb_usbvision *usbvision = video_drvdata(file);
Thierry MERLEc5f48362007-05-08 17:22:29 -0300506 int chan;
507
Roel Kluin223ffe52009-05-02 16:38:47 -0300508 if (vi->index >= usbvision->video_inputs)
Thierry MERLEc5f48362007-05-08 17:22:29 -0300509 return -EINVAL;
Hans Verkuil6d6a48e2010-12-29 13:53:21 -0300510 if (usbvision->have_tuner)
Thierry MERLEc5f48362007-05-08 17:22:29 -0300511 chan = vi->index;
Hans Verkuil6d6a48e2010-12-29 13:53:21 -0300512 else
Hans Verkuil52cb0bf2010-12-19 20:33:51 -0300513 chan = vi->index + 1; /* skip Television string*/
Hans Verkuil6d6a48e2010-12-29 13:53:21 -0300514
Thierry MERLEc5f48362007-05-08 17:22:29 -0300515 /* Determine the requested input characteristics
516 specific for each usbvision card model */
Hans Verkuil6d6a48e2010-12-29 13:53:21 -0300517 switch (chan) {
Thierry MERLEc5f48362007-05-08 17:22:29 -0300518 case 0:
Hans Verkuil5490a7c2010-12-19 20:21:36 -0300519 if (usbvision_device_data[usbvision->dev_model].video_channels == 4) {
Thierry MERLEc5f48362007-05-08 17:22:29 -0300520 strcpy(vi->name, "White Video Input");
521 } else {
522 strcpy(vi->name, "Television");
523 vi->type = V4L2_INPUT_TYPE_TUNER;
Thierry MERLEc5f48362007-05-08 17:22:29 -0300524 vi->tuner = chan;
525 vi->std = USBVISION_NORMS;
526 }
527 break;
528 case 1:
529 vi->type = V4L2_INPUT_TYPE_CAMERA;
Hans Verkuil6d6a48e2010-12-29 13:53:21 -0300530 if (usbvision_device_data[usbvision->dev_model].video_channels == 4)
Thierry MERLEc5f48362007-05-08 17:22:29 -0300531 strcpy(vi->name, "Green Video Input");
Hans Verkuil6d6a48e2010-12-29 13:53:21 -0300532 else
Thierry MERLEc5f48362007-05-08 17:22:29 -0300533 strcpy(vi->name, "Composite Video Input");
Hans Verkuil94384012015-07-20 09:59:37 -0300534 vi->std = USBVISION_NORMS;
Thierry MERLEc5f48362007-05-08 17:22:29 -0300535 break;
536 case 2:
537 vi->type = V4L2_INPUT_TYPE_CAMERA;
Hans Verkuil6d6a48e2010-12-29 13:53:21 -0300538 if (usbvision_device_data[usbvision->dev_model].video_channels == 4)
Thierry MERLEc5f48362007-05-08 17:22:29 -0300539 strcpy(vi->name, "Yellow Video Input");
Hans Verkuil6d6a48e2010-12-29 13:53:21 -0300540 else
Thierry MERLEc5f48362007-05-08 17:22:29 -0300541 strcpy(vi->name, "S-Video Input");
Hans Verkuil94384012015-07-20 09:59:37 -0300542 vi->std = USBVISION_NORMS;
Thierry MERLEc5f48362007-05-08 17:22:29 -0300543 break;
544 case 3:
545 vi->type = V4L2_INPUT_TYPE_CAMERA;
546 strcpy(vi->name, "Red Video Input");
Hans Verkuil94384012015-07-20 09:59:37 -0300547 vi->std = USBVISION_NORMS;
Thierry MERLEc5f48362007-05-08 17:22:29 -0300548 break;
549 }
550 return 0;
551}
552
Hans Verkuil6d6a48e2010-12-29 13:53:21 -0300553static int vidioc_g_input(struct file *file, void *priv, unsigned int *input)
Thierry MERLEc5f48362007-05-08 17:22:29 -0300554{
Hans Verkuilc170ecf2008-08-23 08:32:09 -0300555 struct usb_usbvision *usbvision = video_drvdata(file);
Thierry MERLEc5f48362007-05-08 17:22:29 -0300556
557 *input = usbvision->ctl_input;
558 return 0;
559}
560
Hans Verkuil6d6a48e2010-12-29 13:53:21 -0300561static int vidioc_s_input(struct file *file, void *priv, unsigned int input)
Thierry MERLEc5f48362007-05-08 17:22:29 -0300562{
Hans Verkuilc170ecf2008-08-23 08:32:09 -0300563 struct usb_usbvision *usbvision = video_drvdata(file);
Thierry MERLEc5f48362007-05-08 17:22:29 -0300564
Roel Kluinf14a2972009-10-23 07:59:42 -0300565 if (input >= usbvision->video_inputs)
Thierry MERLEc5f48362007-05-08 17:22:29 -0300566 return -EINVAL;
Thierry MERLEc5f48362007-05-08 17:22:29 -0300567
Thierry MERLE66a17872007-06-26 16:35:30 -0300568 usbvision_muxsel(usbvision, input);
Thierry MERLEc5f48362007-05-08 17:22:29 -0300569 usbvision_set_input(usbvision);
570 usbvision_set_output(usbvision,
571 usbvision->curwidth,
572 usbvision->curheight);
Thierry MERLEc5f48362007-05-08 17:22:29 -0300573 return 0;
574}
575
Hans Verkuil314527a2013-03-15 06:10:40 -0300576static int vidioc_s_std(struct file *file, void *priv, v4l2_std_id id)
Thierry MERLEc5f48362007-05-08 17:22:29 -0300577{
Hans Verkuilc170ecf2008-08-23 08:32:09 -0300578 struct usb_usbvision *usbvision = video_drvdata(file);
579
Hans Verkuil314527a2013-03-15 06:10:40 -0300580 usbvision->tvnorm_id = id;
Thierry MERLEc5f48362007-05-08 17:22:29 -0300581
Laurent Pinchart8774bed2014-04-28 16:53:01 -0300582 call_all(usbvision, video, s_std, usbvision->tvnorm_id);
Thierry MERLE66a17872007-06-26 16:35:30 -0300583 /* propagate the change to the decoder */
584 usbvision_muxsel(usbvision, usbvision->ctl_input);
Thierry MERLEc5f48362007-05-08 17:22:29 -0300585
586 return 0;
587}
588
Hans Verkuil3b8436d2013-06-03 05:36:47 -0300589static int vidioc_g_std(struct file *file, void *priv, v4l2_std_id *id)
590{
591 struct usb_usbvision *usbvision = video_drvdata(file);
592
593 *id = usbvision->tvnorm_id;
594 return 0;
595}
596
Hans Verkuil6d6a48e2010-12-29 13:53:21 -0300597static int vidioc_g_tuner(struct file *file, void *priv,
Thierry MERLEc5f48362007-05-08 17:22:29 -0300598 struct v4l2_tuner *vt)
599{
Hans Verkuilc170ecf2008-08-23 08:32:09 -0300600 struct usb_usbvision *usbvision = video_drvdata(file);
Thierry MERLEc5f48362007-05-08 17:22:29 -0300601
Hans Verkuil64d416e2015-07-20 09:59:33 -0300602 if (vt->index) /* Only tuner 0 */
Thierry MERLEc5f48362007-05-08 17:22:29 -0300603 return -EINVAL;
Hans Verkuil64d416e2015-07-20 09:59:33 -0300604 if (vt->type == V4L2_TUNER_RADIO)
Thierry MERLEc5f48362007-05-08 17:22:29 -0300605 strcpy(vt->name, "Radio");
Hans Verkuil64d416e2015-07-20 09:59:33 -0300606 else
Thierry MERLEc5f48362007-05-08 17:22:29 -0300607 strcpy(vt->name, "Television");
Hans Verkuil64d416e2015-07-20 09:59:33 -0300608
Thierry MERLEc5f48362007-05-08 17:22:29 -0300609 /* Let clients fill in the remainder of this struct */
Hans Verkuil1df79532009-02-21 18:11:31 -0300610 call_all(usbvision, tuner, g_tuner, vt);
Thierry MERLEc5f48362007-05-08 17:22:29 -0300611
612 return 0;
613}
614
Hans Verkuil6d6a48e2010-12-29 13:53:21 -0300615static int vidioc_s_tuner(struct file *file, void *priv,
Hans Verkuil2f73c7c2013-03-15 06:10:06 -0300616 const struct v4l2_tuner *vt)
Thierry MERLEc5f48362007-05-08 17:22:29 -0300617{
Hans Verkuilc170ecf2008-08-23 08:32:09 -0300618 struct usb_usbvision *usbvision = video_drvdata(file);
Thierry MERLEc5f48362007-05-08 17:22:29 -0300619
Hans Verkuil64d416e2015-07-20 09:59:33 -0300620 /* Only one tuner for now */
621 if (vt->index)
Thierry MERLEc5f48362007-05-08 17:22:29 -0300622 return -EINVAL;
623 /* let clients handle this */
Hans Verkuil1df79532009-02-21 18:11:31 -0300624 call_all(usbvision, tuner, s_tuner, vt);
Thierry MERLEc5f48362007-05-08 17:22:29 -0300625
626 return 0;
627}
628
Hans Verkuil6d6a48e2010-12-29 13:53:21 -0300629static int vidioc_g_frequency(struct file *file, void *priv,
Thierry MERLEc5f48362007-05-08 17:22:29 -0300630 struct v4l2_frequency *freq)
631{
Hans Verkuilc170ecf2008-08-23 08:32:09 -0300632 struct usb_usbvision *usbvision = video_drvdata(file);
Thierry MERLEc5f48362007-05-08 17:22:29 -0300633
Hans Verkuil64d416e2015-07-20 09:59:33 -0300634 /* Only one tuner */
635 if (freq->tuner)
636 return -EINVAL;
637 if (freq->type == V4L2_TUNER_RADIO)
638 freq->frequency = usbvision->radio_freq;
Hans Verkuil6d6a48e2010-12-29 13:53:21 -0300639 else
Hans Verkuil64d416e2015-07-20 09:59:33 -0300640 freq->frequency = usbvision->tv_freq;
Thierry MERLEc5f48362007-05-08 17:22:29 -0300641
642 return 0;
643}
644
Hans Verkuil6d6a48e2010-12-29 13:53:21 -0300645static int vidioc_s_frequency(struct file *file, void *priv,
Hans Verkuilb530a442013-03-19 04:09:26 -0300646 const struct v4l2_frequency *freq)
Thierry MERLEc5f48362007-05-08 17:22:29 -0300647{
Hans Verkuilc170ecf2008-08-23 08:32:09 -0300648 struct usb_usbvision *usbvision = video_drvdata(file);
Hans Verkuil64d416e2015-07-20 09:59:33 -0300649 struct v4l2_frequency new_freq = *freq;
Thierry MERLEc5f48362007-05-08 17:22:29 -0300650
Hans Verkuil64d416e2015-07-20 09:59:33 -0300651 /* Only one tuner for now */
652 if (freq->tuner)
Thierry MERLEc5f48362007-05-08 17:22:29 -0300653 return -EINVAL;
654
Hans Verkuil1df79532009-02-21 18:11:31 -0300655 call_all(usbvision, tuner, s_frequency, freq);
Hans Verkuil64d416e2015-07-20 09:59:33 -0300656 call_all(usbvision, tuner, g_frequency, &new_freq);
657 if (freq->type == V4L2_TUNER_RADIO)
658 usbvision->radio_freq = new_freq.frequency;
659 else
660 usbvision->tv_freq = new_freq.frequency;
Thierry MERLEc5f48362007-05-08 17:22:29 -0300661
662 return 0;
663}
664
Hans Verkuil6d6a48e2010-12-29 13:53:21 -0300665static int vidioc_reqbufs(struct file *file,
Thierry MERLEc5f48362007-05-08 17:22:29 -0300666 void *priv, struct v4l2_requestbuffers *vr)
667{
Hans Verkuilc170ecf2008-08-23 08:32:09 -0300668 struct usb_usbvision *usbvision = video_drvdata(file);
Thierry MERLEc5f48362007-05-08 17:22:29 -0300669 int ret;
670
Hans Verkuil6d6a48e2010-12-29 13:53:21 -0300671 RESTRICT_TO_RANGE(vr->count, 1, USBVISION_NUMFRAMES);
Thierry MERLEc5f48362007-05-08 17:22:29 -0300672
673 /* Check input validity:
674 the user must do a VIDEO CAPTURE and MMAP method. */
Trent Piepho975f5762009-03-28 22:25:36 -0300675 if (vr->memory != V4L2_MEMORY_MMAP)
Thierry MERLEc5f48362007-05-08 17:22:29 -0300676 return -EINVAL;
677
Hans Verkuil6d6a48e2010-12-29 13:53:21 -0300678 if (usbvision->streaming == stream_on) {
679 ret = usbvision_stream_interrupt(usbvision);
680 if (ret)
Thierry MERLEc5f48362007-05-08 17:22:29 -0300681 return ret;
682 }
683
684 usbvision_frames_free(usbvision);
685 usbvision_empty_framequeues(usbvision);
Hans Verkuil6d6a48e2010-12-29 13:53:21 -0300686 vr->count = usbvision_frames_alloc(usbvision, vr->count);
Thierry MERLEc5f48362007-05-08 17:22:29 -0300687
Hans Verkuil5490a7c2010-12-19 20:21:36 -0300688 usbvision->cur_frame = NULL;
Thierry MERLEc5f48362007-05-08 17:22:29 -0300689
690 return 0;
691}
692
Hans Verkuil6d6a48e2010-12-29 13:53:21 -0300693static int vidioc_querybuf(struct file *file,
Thierry MERLEc5f48362007-05-08 17:22:29 -0300694 void *priv, struct v4l2_buffer *vb)
695{
Hans Verkuilc170ecf2008-08-23 08:32:09 -0300696 struct usb_usbvision *usbvision = video_drvdata(file);
Thierry MERLEc5f48362007-05-08 17:22:29 -0300697 struct usbvision_frame *frame;
698
699 /* FIXME : must control
700 that buffers are mapped (VIDIOC_REQBUFS has been called) */
Hans Verkuil6d6a48e2010-12-29 13:53:21 -0300701 if (vb->index >= usbvision->num_frames)
Thierry MERLEc5f48362007-05-08 17:22:29 -0300702 return -EINVAL;
Thierry MERLEc5f48362007-05-08 17:22:29 -0300703 /* Updating the corresponding frame state */
Sakari Ailus1b18e7a2012-10-22 17:10:16 -0300704 vb->flags = V4L2_BUF_FLAG_TIMESTAMP_MONOTONIC;
Thierry MERLEc5f48362007-05-08 17:22:29 -0300705 frame = &usbvision->frame[vb->index];
Hans Verkuil6d6a48e2010-12-29 13:53:21 -0300706 if (frame->grabstate >= frame_state_ready)
Thierry MERLEc5f48362007-05-08 17:22:29 -0300707 vb->flags |= V4L2_BUF_FLAG_QUEUED;
Hans Verkuil6d6a48e2010-12-29 13:53:21 -0300708 if (frame->grabstate >= frame_state_done)
Thierry MERLEc5f48362007-05-08 17:22:29 -0300709 vb->flags |= V4L2_BUF_FLAG_DONE;
Hans Verkuil6d6a48e2010-12-29 13:53:21 -0300710 if (frame->grabstate == frame_state_unused)
Thierry MERLEc5f48362007-05-08 17:22:29 -0300711 vb->flags |= V4L2_BUF_FLAG_MAPPED;
712 vb->memory = V4L2_MEMORY_MMAP;
713
Hans Verkuil6d6a48e2010-12-29 13:53:21 -0300714 vb->m.offset = vb->index * PAGE_ALIGN(usbvision->max_frame_size);
Thierry MERLEc5f48362007-05-08 17:22:29 -0300715
716 vb->memory = V4L2_MEMORY_MMAP;
717 vb->field = V4L2_FIELD_NONE;
Hans Verkuil6d6a48e2010-12-29 13:53:21 -0300718 vb->length = usbvision->curwidth *
719 usbvision->curheight *
Thierry MERLEc5f48362007-05-08 17:22:29 -0300720 usbvision->palette.bytes_per_pixel;
721 vb->timestamp = usbvision->frame[vb->index].timestamp;
722 vb->sequence = usbvision->frame[vb->index].sequence;
723 return 0;
724}
725
Hans Verkuil6d6a48e2010-12-29 13:53:21 -0300726static int vidioc_qbuf(struct file *file, void *priv, struct v4l2_buffer *vb)
Thierry MERLEc5f48362007-05-08 17:22:29 -0300727{
Hans Verkuilc170ecf2008-08-23 08:32:09 -0300728 struct usb_usbvision *usbvision = video_drvdata(file);
Thierry MERLEc5f48362007-05-08 17:22:29 -0300729 struct usbvision_frame *frame;
730 unsigned long lock_flags;
731
732 /* FIXME : works only on VIDEO_CAPTURE MODE, MMAP. */
Hans Verkuil6d6a48e2010-12-29 13:53:21 -0300733 if (vb->index >= usbvision->num_frames)
Thierry MERLEc5f48362007-05-08 17:22:29 -0300734 return -EINVAL;
Thierry MERLEc5f48362007-05-08 17:22:29 -0300735
736 frame = &usbvision->frame[vb->index];
737
Hans Verkuil6d6a48e2010-12-29 13:53:21 -0300738 if (frame->grabstate != frame_state_unused)
Thierry MERLEc5f48362007-05-08 17:22:29 -0300739 return -EAGAIN;
Thierry MERLEc5f48362007-05-08 17:22:29 -0300740
741 /* Mark it as ready and enqueue frame */
Hans Verkuil5490a7c2010-12-19 20:21:36 -0300742 frame->grabstate = frame_state_ready;
743 frame->scanstate = scan_state_scanning;
Thierry MERLEc5f48362007-05-08 17:22:29 -0300744 frame->scanlength = 0; /* Accumulated in usbvision_parse_data() */
745
746 vb->flags &= ~V4L2_BUF_FLAG_DONE;
747
748 /* set v4l2_format index */
749 frame->v4l2_format = usbvision->palette;
750
751 spin_lock_irqsave(&usbvision->queue_lock, lock_flags);
752 list_add_tail(&usbvision->frame[vb->index].frame, &usbvision->inqueue);
753 spin_unlock_irqrestore(&usbvision->queue_lock, lock_flags);
754
755 return 0;
756}
757
Hans Verkuil6d6a48e2010-12-29 13:53:21 -0300758static int vidioc_dqbuf(struct file *file, void *priv, struct v4l2_buffer *vb)
Thierry MERLEc5f48362007-05-08 17:22:29 -0300759{
Hans Verkuilc170ecf2008-08-23 08:32:09 -0300760 struct usb_usbvision *usbvision = video_drvdata(file);
Thierry MERLEc5f48362007-05-08 17:22:29 -0300761 int ret;
762 struct usbvision_frame *f;
763 unsigned long lock_flags;
764
Thierry MERLEc5f48362007-05-08 17:22:29 -0300765 if (list_empty(&(usbvision->outqueue))) {
Hans Verkuil5490a7c2010-12-19 20:21:36 -0300766 if (usbvision->streaming == stream_idle)
Thierry MERLEc5f48362007-05-08 17:22:29 -0300767 return -EINVAL;
768 ret = wait_event_interruptible
769 (usbvision->wait_frame,
770 !list_empty(&(usbvision->outqueue)));
771 if (ret)
772 return ret;
773 }
774
775 spin_lock_irqsave(&usbvision->queue_lock, lock_flags);
776 f = list_entry(usbvision->outqueue.next,
777 struct usbvision_frame, frame);
778 list_del(usbvision->outqueue.next);
779 spin_unlock_irqrestore(&usbvision->queue_lock, lock_flags);
780
Hans Verkuil5490a7c2010-12-19 20:21:36 -0300781 f->grabstate = frame_state_unused;
Thierry MERLEc5f48362007-05-08 17:22:29 -0300782
783 vb->memory = V4L2_MEMORY_MMAP;
784 vb->flags = V4L2_BUF_FLAG_MAPPED |
785 V4L2_BUF_FLAG_QUEUED |
Sakari Ailus1b18e7a2012-10-22 17:10:16 -0300786 V4L2_BUF_FLAG_DONE |
787 V4L2_BUF_FLAG_TIMESTAMP_MONOTONIC;
Thierry MERLEc5f48362007-05-08 17:22:29 -0300788 vb->index = f->index;
789 vb->sequence = f->sequence;
790 vb->timestamp = f->timestamp;
791 vb->field = V4L2_FIELD_NONE;
792 vb->bytesused = f->scanlength;
793
794 return 0;
795}
796
797static int vidioc_streamon(struct file *file, void *priv, enum v4l2_buf_type i)
798{
Hans Verkuilc170ecf2008-08-23 08:32:09 -0300799 struct usb_usbvision *usbvision = video_drvdata(file);
Thierry MERLEc5f48362007-05-08 17:22:29 -0300800
Hans Verkuil5490a7c2010-12-19 20:21:36 -0300801 usbvision->streaming = stream_on;
Hans Verkuil1df79532009-02-21 18:11:31 -0300802 call_all(usbvision, video, s_stream, 1);
Thierry MERLEc5f48362007-05-08 17:22:29 -0300803
804 return 0;
805}
806
807static int vidioc_streamoff(struct file *file,
808 void *priv, enum v4l2_buf_type type)
809{
Hans Verkuilc170ecf2008-08-23 08:32:09 -0300810 struct usb_usbvision *usbvision = video_drvdata(file);
Thierry MERLEc5f48362007-05-08 17:22:29 -0300811
812 if (type != V4L2_BUF_TYPE_VIDEO_CAPTURE)
813 return -EINVAL;
814
Hans Verkuil6d6a48e2010-12-29 13:53:21 -0300815 if (usbvision->streaming == stream_on) {
Thierry MERLEc5f48362007-05-08 17:22:29 -0300816 usbvision_stream_interrupt(usbvision);
817 /* Stop all video streamings */
Hans Verkuil1df79532009-02-21 18:11:31 -0300818 call_all(usbvision, video, s_stream, 0);
Thierry MERLEc5f48362007-05-08 17:22:29 -0300819 }
820 usbvision_empty_framequeues(usbvision);
821
822 return 0;
823}
824
Hans Verkuil6d6a48e2010-12-29 13:53:21 -0300825static int vidioc_enum_fmt_vid_cap(struct file *file, void *priv,
Thierry MERLEc5f48362007-05-08 17:22:29 -0300826 struct v4l2_fmtdesc *vfd)
827{
Hans Verkuil6d6a48e2010-12-29 13:53:21 -0300828 if (vfd->index >= USBVISION_SUPPORTED_PALETTES - 1)
Thierry MERLEc5f48362007-05-08 17:22:29 -0300829 return -EINVAL;
Hans Verkuil6d6a48e2010-12-29 13:53:21 -0300830 strcpy(vfd->description, usbvision_v4l2_format[vfd->index].desc);
Thierry MERLEc5f48362007-05-08 17:22:29 -0300831 vfd->pixelformat = usbvision_v4l2_format[vfd->index].format;
Thierry MERLEc5f48362007-05-08 17:22:29 -0300832 return 0;
833}
834
Hans Verkuil6d6a48e2010-12-29 13:53:21 -0300835static int vidioc_g_fmt_vid_cap(struct file *file, void *priv,
Thierry MERLEc5f48362007-05-08 17:22:29 -0300836 struct v4l2_format *vf)
837{
Hans Verkuilc170ecf2008-08-23 08:32:09 -0300838 struct usb_usbvision *usbvision = video_drvdata(file);
Thierry MERLEc5f48362007-05-08 17:22:29 -0300839 vf->fmt.pix.width = usbvision->curwidth;
840 vf->fmt.pix.height = usbvision->curheight;
841 vf->fmt.pix.pixelformat = usbvision->palette.format;
842 vf->fmt.pix.bytesperline =
Hans Verkuil6d6a48e2010-12-29 13:53:21 -0300843 usbvision->curwidth * usbvision->palette.bytes_per_pixel;
844 vf->fmt.pix.sizeimage = vf->fmt.pix.bytesperline * usbvision->curheight;
Thierry MERLEc5f48362007-05-08 17:22:29 -0300845 vf->fmt.pix.colorspace = V4L2_COLORSPACE_SMPTE170M;
846 vf->fmt.pix.field = V4L2_FIELD_NONE; /* Always progressive image */
847
848 return 0;
849}
850
Hans Verkuil6d6a48e2010-12-29 13:53:21 -0300851static int vidioc_try_fmt_vid_cap(struct file *file, void *priv,
Thierry MERLEc5f48362007-05-08 17:22:29 -0300852 struct v4l2_format *vf)
853{
Hans Verkuilc170ecf2008-08-23 08:32:09 -0300854 struct usb_usbvision *usbvision = video_drvdata(file);
Hans Verkuil5490a7c2010-12-19 20:21:36 -0300855 int format_idx;
Thierry MERLEc5f48362007-05-08 17:22:29 -0300856
857 /* Find requested format in available ones */
Hans Verkuil6d6a48e2010-12-29 13:53:21 -0300858 for (format_idx = 0; format_idx < USBVISION_SUPPORTED_PALETTES; format_idx++) {
859 if (vf->fmt.pix.pixelformat ==
Hans Verkuil5490a7c2010-12-19 20:21:36 -0300860 usbvision_v4l2_format[format_idx].format) {
861 usbvision->palette = usbvision_v4l2_format[format_idx];
Thierry MERLEc5f48362007-05-08 17:22:29 -0300862 break;
863 }
864 }
865 /* robustness */
Hans Verkuil6d6a48e2010-12-29 13:53:21 -0300866 if (format_idx == USBVISION_SUPPORTED_PALETTES)
Thierry MERLEc5f48362007-05-08 17:22:29 -0300867 return -EINVAL;
Thierry MERLEc5f48362007-05-08 17:22:29 -0300868 RESTRICT_TO_RANGE(vf->fmt.pix.width, MIN_FRAME_WIDTH, MAX_FRAME_WIDTH);
869 RESTRICT_TO_RANGE(vf->fmt.pix.height, MIN_FRAME_HEIGHT, MAX_FRAME_HEIGHT);
870
871 vf->fmt.pix.bytesperline = vf->fmt.pix.width*
872 usbvision->palette.bytes_per_pixel;
873 vf->fmt.pix.sizeimage = vf->fmt.pix.bytesperline*vf->fmt.pix.height;
Hans Verkuil4eeda6f2015-07-20 09:59:34 -0300874 vf->fmt.pix.colorspace = V4L2_COLORSPACE_SMPTE170M;
875 vf->fmt.pix.field = V4L2_FIELD_NONE; /* Always progressive image */
Thierry MERLEc5f48362007-05-08 17:22:29 -0300876
877 return 0;
878}
879
Hans Verkuil78b526a2008-05-28 12:16:41 -0300880static int vidioc_s_fmt_vid_cap(struct file *file, void *priv,
Thierry MERLEc5f48362007-05-08 17:22:29 -0300881 struct v4l2_format *vf)
882{
Hans Verkuilc170ecf2008-08-23 08:32:09 -0300883 struct usb_usbvision *usbvision = video_drvdata(file);
Thierry MERLEc5f48362007-05-08 17:22:29 -0300884 int ret;
885
Hans Verkuil6d6a48e2010-12-29 13:53:21 -0300886 ret = vidioc_try_fmt_vid_cap(file, priv, vf);
887 if (ret)
Thierry MERLEc5f48362007-05-08 17:22:29 -0300888 return ret;
Thierry MERLEc5f48362007-05-08 17:22:29 -0300889
890 /* stop io in case it is already in progress */
Hans Verkuil6d6a48e2010-12-29 13:53:21 -0300891 if (usbvision->streaming == stream_on) {
892 ret = usbvision_stream_interrupt(usbvision);
893 if (ret)
Thierry MERLEc5f48362007-05-08 17:22:29 -0300894 return ret;
895 }
896 usbvision_frames_free(usbvision);
897 usbvision_empty_framequeues(usbvision);
898
Hans Verkuil5490a7c2010-12-19 20:21:36 -0300899 usbvision->cur_frame = NULL;
Thierry MERLEc5f48362007-05-08 17:22:29 -0300900
901 /* by now we are committed to the new data... */
Thierry MERLEc5f48362007-05-08 17:22:29 -0300902 usbvision_set_output(usbvision, vf->fmt.pix.width, vf->fmt.pix.height);
Thierry MERLEc5f48362007-05-08 17:22:29 -0300903
904 return 0;
905}
Thierry MERLE483dfdb2006-12-04 08:31:45 -0300906
Hans Verkuil4d345702012-06-23 08:03:50 -0300907static ssize_t usbvision_read(struct file *file, char __user *buf,
Thierry MERLE483dfdb2006-12-04 08:31:45 -0300908 size_t count, loff_t *ppos)
909{
Hans Verkuilc170ecf2008-08-23 08:32:09 -0300910 struct usb_usbvision *usbvision = video_drvdata(file);
Thierry MERLE483dfdb2006-12-04 08:31:45 -0300911 int noblock = file->f_flags & O_NONBLOCK;
912 unsigned long lock_flags;
Hans Verkuil6d6a48e2010-12-29 13:53:21 -0300913 int ret, i;
Thierry MERLE483dfdb2006-12-04 08:31:45 -0300914 struct usbvision_frame *frame;
915
Harvey Harrisond2db42d2008-04-04 20:50:07 -0300916 PDEBUG(DBG_IO, "%s: %ld bytes, noblock=%d", __func__,
Thierry MERLEc5f48362007-05-08 17:22:29 -0300917 (unsigned long)count, noblock);
Thierry MERLE483dfdb2006-12-04 08:31:45 -0300918
919 if (!USBVISION_IS_OPERATIONAL(usbvision) || (buf == NULL))
920 return -EFAULT;
921
Thierry MERLEc5f48362007-05-08 17:22:29 -0300922 /* This entry point is compatible with the mmap routines
923 so that a user can do either VIDIOC_QBUF/VIDIOC_DQBUF
924 to get frames or call read on the device. */
Hans Verkuil6d6a48e2010-12-29 13:53:21 -0300925 if (!usbvision->num_frames) {
Thierry MERLEc5f48362007-05-08 17:22:29 -0300926 /* First, allocate some frames to work with
927 if this has not been done with VIDIOC_REQBUF */
Thierry MERLE6f78e182007-02-07 10:13:11 -0300928 usbvision_frames_free(usbvision);
929 usbvision_empty_framequeues(usbvision);
Hans Verkuil6d6a48e2010-12-29 13:53:21 -0300930 usbvision_frames_alloc(usbvision, USBVISION_NUMFRAMES);
Thierry MERLE6f78e182007-02-07 10:13:11 -0300931 }
Thierry MERLE483dfdb2006-12-04 08:31:45 -0300932
Hans Verkuil6d6a48e2010-12-29 13:53:21 -0300933 if (usbvision->streaming != stream_on) {
Thierry MERLE6f78e182007-02-07 10:13:11 -0300934 /* no stream is running, make it running ! */
Hans Verkuil5490a7c2010-12-19 20:21:36 -0300935 usbvision->streaming = stream_on;
Hans Verkuil1df79532009-02-21 18:11:31 -0300936 call_all(usbvision, video, s_stream, 1);
Thierry MERLE6f78e182007-02-07 10:13:11 -0300937 }
938
Thierry MERLEc5f48362007-05-08 17:22:29 -0300939 /* Then, enqueue as many frames as possible
940 (like a user of VIDIOC_QBUF would do) */
Hans Verkuil6d6a48e2010-12-29 13:53:21 -0300941 for (i = 0; i < usbvision->num_frames; i++) {
Thierry MERLE483dfdb2006-12-04 08:31:45 -0300942 frame = &usbvision->frame[i];
Hans Verkuil6d6a48e2010-12-29 13:53:21 -0300943 if (frame->grabstate == frame_state_unused) {
Thierry MERLE483dfdb2006-12-04 08:31:45 -0300944 /* Mark it as ready and enqueue frame */
Hans Verkuil5490a7c2010-12-19 20:21:36 -0300945 frame->grabstate = frame_state_ready;
946 frame->scanstate = scan_state_scanning;
Thierry MERLEc5f48362007-05-08 17:22:29 -0300947 /* Accumulated in usbvision_parse_data() */
948 frame->scanlength = 0;
Thierry MERLE483dfdb2006-12-04 08:31:45 -0300949
950 /* set v4l2_format index */
951 frame->v4l2_format = usbvision->palette;
952
953 spin_lock_irqsave(&usbvision->queue_lock, lock_flags);
954 list_add_tail(&frame->frame, &usbvision->inqueue);
Thierry MERLEc5f48362007-05-08 17:22:29 -0300955 spin_unlock_irqrestore(&usbvision->queue_lock,
956 lock_flags);
Thierry MERLE483dfdb2006-12-04 08:31:45 -0300957 }
958 }
959
960 /* Then try to steal a frame (like a VIDIOC_DQBUF would do) */
961 if (list_empty(&(usbvision->outqueue))) {
Hans Verkuil6d6a48e2010-12-29 13:53:21 -0300962 if (noblock)
Thierry MERLE483dfdb2006-12-04 08:31:45 -0300963 return -EAGAIN;
964
965 ret = wait_event_interruptible
966 (usbvision->wait_frame,
967 !list_empty(&(usbvision->outqueue)));
968 if (ret)
969 return ret;
970 }
971
972 spin_lock_irqsave(&usbvision->queue_lock, lock_flags);
973 frame = list_entry(usbvision->outqueue.next,
974 struct usbvision_frame, frame);
975 list_del(usbvision->outqueue.next);
976 spin_unlock_irqrestore(&usbvision->queue_lock, lock_flags);
977
978 /* An error returns an empty frame */
Hans Verkuil5490a7c2010-12-19 20:21:36 -0300979 if (frame->grabstate == frame_state_error) {
Thierry MERLE483dfdb2006-12-04 08:31:45 -0300980 frame->bytes_read = 0;
981 return 0;
982 }
983
Thierry MERLEc5f48362007-05-08 17:22:29 -0300984 PDEBUG(DBG_IO, "%s: frmx=%d, bytes_read=%ld, scanlength=%ld",
Harvey Harrisond2db42d2008-04-04 20:50:07 -0300985 __func__,
Thierry MERLEc5f48362007-05-08 17:22:29 -0300986 frame->index, frame->bytes_read, frame->scanlength);
Thierry MERLE483dfdb2006-12-04 08:31:45 -0300987
988 /* copy bytes to user space; we allow for partials reads */
989 if ((count + frame->bytes_read) > (unsigned long)frame->scanlength)
990 count = frame->scanlength - frame->bytes_read;
991
Hans Verkuil6d6a48e2010-12-29 13:53:21 -0300992 if (copy_to_user(buf, frame->data + frame->bytes_read, count))
Thierry MERLE483dfdb2006-12-04 08:31:45 -0300993 return -EFAULT;
Thierry MERLE483dfdb2006-12-04 08:31:45 -0300994
995 frame->bytes_read += count;
Thierry MERLEc5f48362007-05-08 17:22:29 -0300996 PDEBUG(DBG_IO, "%s: {copy} count used=%ld, new bytes_read=%ld",
Harvey Harrisond2db42d2008-04-04 20:50:07 -0300997 __func__,
Thierry MERLEc5f48362007-05-08 17:22:29 -0300998 (unsigned long)count, frame->bytes_read);
Thierry MERLE483dfdb2006-12-04 08:31:45 -0300999
Mauro Carvalho Chehabb295e5c2015-06-05 10:47:36 -03001000#if 1
1001 /*
1002 * FIXME:
1003 * For now, forget the frame if it has not been read in one shot.
1004 */
1005 frame->bytes_read = 0;
1006
1007 /* Mark it as available to be used again. */
1008 frame->grabstate = frame_state_unused;
1009#else
1010 if (frame->bytes_read >= frame->scanlength) {
1011 /* All data has been read */
Thierry MERLE483dfdb2006-12-04 08:31:45 -03001012 frame->bytes_read = 0;
1013
1014 /* Mark it as available to be used again. */
Hans Verkuil5490a7c2010-12-19 20:21:36 -03001015 frame->grabstate = frame_state_unused;
Mauro Carvalho Chehabb295e5c2015-06-05 10:47:36 -03001016 }
1017#endif
Thierry MERLE483dfdb2006-12-04 08:31:45 -03001018
1019 return count;
1020}
1021
Hans Verkuil4d345702012-06-23 08:03:50 -03001022static ssize_t usbvision_v4l2_read(struct file *file, char __user *buf,
1023 size_t count, loff_t *ppos)
1024{
1025 struct usb_usbvision *usbvision = video_drvdata(file);
1026 int res;
1027
1028 if (mutex_lock_interruptible(&usbvision->v4l2_lock))
1029 return -ERESTARTSYS;
1030 res = usbvision_read(file, buf, count, ppos);
1031 mutex_unlock(&usbvision->v4l2_lock);
1032 return res;
1033}
1034
1035static int usbvision_mmap(struct file *file, struct vm_area_struct *vma)
Thierry MERLE483dfdb2006-12-04 08:31:45 -03001036{
1037 unsigned long size = vma->vm_end - vma->vm_start,
1038 start = vma->vm_start;
1039 void *pos;
1040 u32 i;
Hans Verkuilc170ecf2008-08-23 08:32:09 -03001041 struct usb_usbvision *usbvision = video_drvdata(file);
Thierry MERLE483dfdb2006-12-04 08:31:45 -03001042
Thierry MERLE6f78e182007-02-07 10:13:11 -03001043 PDEBUG(DBG_MMAP, "mmap");
1044
Hans Verkuil6d6a48e2010-12-29 13:53:21 -03001045 if (!USBVISION_IS_OPERATIONAL(usbvision))
Thierry MERLE483dfdb2006-12-04 08:31:45 -03001046 return -EFAULT;
Thierry MERLE483dfdb2006-12-04 08:31:45 -03001047
1048 if (!(vma->vm_flags & VM_WRITE) ||
Thierry MERLE6f78e182007-02-07 10:13:11 -03001049 size != PAGE_ALIGN(usbvision->max_frame_size)) {
Thierry MERLE483dfdb2006-12-04 08:31:45 -03001050 return -EINVAL;
1051 }
1052
Thierry MERLE6f78e182007-02-07 10:13:11 -03001053 for (i = 0; i < usbvision->num_frames; i++) {
Thierry MERLEc5f48362007-05-08 17:22:29 -03001054 if (((PAGE_ALIGN(usbvision->max_frame_size)*i) >> PAGE_SHIFT) ==
1055 vma->vm_pgoff)
Thierry MERLE483dfdb2006-12-04 08:31:45 -03001056 break;
1057 }
Thierry MERLE6f78e182007-02-07 10:13:11 -03001058 if (i == usbvision->num_frames) {
Thierry MERLEc5f48362007-05-08 17:22:29 -03001059 PDEBUG(DBG_MMAP,
1060 "mmap: user supplied mapping address is out of range");
Thierry MERLE483dfdb2006-12-04 08:31:45 -03001061 return -EINVAL;
1062 }
1063
1064 /* VM_IO is eventually going to replace PageReserved altogether */
Konstantin Khlebnikov314e51b2012-10-08 16:29:02 -07001065 vma->vm_flags |= VM_IO | VM_DONTEXPAND | VM_DONTDUMP;
Thierry MERLE483dfdb2006-12-04 08:31:45 -03001066
1067 pos = usbvision->frame[i].data;
1068 while (size > 0) {
Thierry MERLE483dfdb2006-12-04 08:31:45 -03001069 if (vm_insert_page(vma, start, vmalloc_to_page(pos))) {
Thierry MERLEc876a342006-12-09 16:42:54 -03001070 PDEBUG(DBG_MMAP, "mmap: vm_insert_page failed");
Thierry MERLE483dfdb2006-12-04 08:31:45 -03001071 return -EAGAIN;
1072 }
1073 start += PAGE_SIZE;
1074 pos += PAGE_SIZE;
1075 size -= PAGE_SIZE;
1076 }
1077
Thierry MERLE483dfdb2006-12-04 08:31:45 -03001078 return 0;
1079}
1080
Hans Verkuil4d345702012-06-23 08:03:50 -03001081static int usbvision_v4l2_mmap(struct file *file, struct vm_area_struct *vma)
1082{
1083 struct usb_usbvision *usbvision = video_drvdata(file);
1084 int res;
1085
1086 if (mutex_lock_interruptible(&usbvision->v4l2_lock))
1087 return -ERESTARTSYS;
1088 res = usbvision_mmap(file, vma);
1089 mutex_unlock(&usbvision->v4l2_lock);
1090 return res;
1091}
Thierry MERLE483dfdb2006-12-04 08:31:45 -03001092
1093/*
1094 * Here comes the stuff for radio on usbvision based devices
1095 *
1096 */
Hans Verkuilbec43662008-12-30 06:58:20 -03001097static int usbvision_radio_open(struct file *file)
Thierry MERLE483dfdb2006-12-04 08:31:45 -03001098{
Hans Verkuilc170ecf2008-08-23 08:32:09 -03001099 struct usb_usbvision *usbvision = video_drvdata(file);
Hans Verkuil5490a7c2010-12-19 20:21:36 -03001100 int err_code = 0;
Thierry MERLE483dfdb2006-12-04 08:31:45 -03001101
Harvey Harrisond2db42d2008-04-04 20:50:07 -03001102 PDEBUG(DBG_IO, "%s:", __func__);
Thierry MERLE483dfdb2006-12-04 08:31:45 -03001103
Hans Verkuil4d345702012-06-23 08:03:50 -03001104 if (mutex_lock_interruptible(&usbvision->v4l2_lock))
1105 return -ERESTARTSYS;
Hans Verkuilfd958702015-07-20 09:59:29 -03001106 err_code = v4l2_fh_open(file);
1107 if (err_code)
1108 goto out;
Thierry MERLE483dfdb2006-12-04 08:31:45 -03001109 if (usbvision->user) {
Hans Verkuil2aa689d2015-03-09 13:34:12 -03001110 dev_err(&usbvision->rdev.dev,
Mauro Carvalho Chehabbe9ed512009-01-08 09:13:42 -03001111 "%s: Someone tried to open an already opened USBVision Radio!\n",
1112 __func__);
Hans Verkuil5490a7c2010-12-19 20:21:36 -03001113 err_code = -EBUSY;
Hans Verkuil6d6a48e2010-12-29 13:53:21 -03001114 } else {
Thierry MERLE2a9f8b52007-02-07 10:14:38 -03001115 /* Alternate interface 1 is is the biggest frame size */
Hans Verkuil5490a7c2010-12-19 20:21:36 -03001116 err_code = usbvision_set_alternate(usbvision);
1117 if (err_code < 0) {
1118 usbvision->last_error = err_code;
1119 err_code = -EBUSY;
Andrew Morton544e6172007-12-12 18:25:23 -03001120 goto out;
Thierry MERLE2a9f8b52007-02-07 10:14:38 -03001121 }
1122
Hans Verkuil52cb0bf2010-12-19 20:33:51 -03001123 /* If so far no errors then we shall start the radio */
Thierry MERLE483dfdb2006-12-04 08:31:45 -03001124 usbvision->radio = 1;
Hans Verkuil1df79532009-02-21 18:11:31 -03001125 call_all(usbvision, tuner, s_radio);
Thierry MERLE483dfdb2006-12-04 08:31:45 -03001126 usbvision_set_audio(usbvision, USBVISION_AUDIO_RADIO);
1127 usbvision->user++;
1128 }
Andrew Morton544e6172007-12-12 18:25:23 -03001129out:
Hans Verkuil4d345702012-06-23 08:03:50 -03001130 mutex_unlock(&usbvision->v4l2_lock);
Hans Verkuil5490a7c2010-12-19 20:21:36 -03001131 return err_code;
Thierry MERLE483dfdb2006-12-04 08:31:45 -03001132}
1133
1134
Hans Verkuilbec43662008-12-30 06:58:20 -03001135static int usbvision_radio_close(struct file *file)
Thierry MERLE483dfdb2006-12-04 08:31:45 -03001136{
Hans Verkuilc170ecf2008-08-23 08:32:09 -03001137 struct usb_usbvision *usbvision = video_drvdata(file);
Thierry MERLE483dfdb2006-12-04 08:31:45 -03001138
1139 PDEBUG(DBG_IO, "");
1140
Hans Verkuil4d345702012-06-23 08:03:50 -03001141 mutex_lock(&usbvision->v4l2_lock);
Thierry MERLE2a9f8b52007-02-07 10:14:38 -03001142 /* Set packet size to 0 */
Hans Verkuil6d6a48e2010-12-29 13:53:21 -03001143 usbvision->iface_alt = 0;
Hans Verkuilfd958702015-07-20 09:59:29 -03001144 usb_set_interface(usbvision->dev, usbvision->iface,
Hans Verkuil5490a7c2010-12-19 20:21:36 -03001145 usbvision->iface_alt);
Thierry MERLE2a9f8b52007-02-07 10:14:38 -03001146
Thierry MERLE483dfdb2006-12-04 08:31:45 -03001147 usbvision_audio_off(usbvision);
Hans Verkuil6d6a48e2010-12-29 13:53:21 -03001148 usbvision->radio = 0;
Thierry MERLE483dfdb2006-12-04 08:31:45 -03001149 usbvision->user--;
Insu Yun5ce625a2016-02-01 13:59:30 -02001150 mutex_unlock(&usbvision->v4l2_lock);
Thierry MERLE483dfdb2006-12-04 08:31:45 -03001151
Thierry MERLE483dfdb2006-12-04 08:31:45 -03001152 if (usbvision->remove_pending) {
Harvey Harrisond2db42d2008-04-04 20:50:07 -03001153 printk(KERN_INFO "%s: Final disconnect\n", __func__);
Hans Verkuilfd958702015-07-20 09:59:29 -03001154 v4l2_fh_release(file);
Thierry MERLE483dfdb2006-12-04 08:31:45 -03001155 usbvision_release(usbvision);
Hans Verkuilfd958702015-07-20 09:59:29 -03001156 return 0;
Thierry MERLE483dfdb2006-12-04 08:31:45 -03001157 }
1158
Thierry MERLE483dfdb2006-12-04 08:31:45 -03001159 PDEBUG(DBG_IO, "success");
Hans Verkuilfd958702015-07-20 09:59:29 -03001160 return v4l2_fh_release(file);
Thierry MERLE483dfdb2006-12-04 08:31:45 -03001161}
1162
Hans Verkuil52cb0bf2010-12-19 20:33:51 -03001163/* Video registration stuff */
Thierry MERLE483dfdb2006-12-04 08:31:45 -03001164
Hans Verkuil52cb0bf2010-12-19 20:33:51 -03001165/* Video template */
Hans Verkuilbec43662008-12-30 06:58:20 -03001166static const struct v4l2_file_operations usbvision_fops = {
Thierry MERLE483dfdb2006-12-04 08:31:45 -03001167 .owner = THIS_MODULE,
Thierry MERLE483dfdb2006-12-04 08:31:45 -03001168 .open = usbvision_v4l2_open,
1169 .release = usbvision_v4l2_close,
1170 .read = usbvision_v4l2_read,
1171 .mmap = usbvision_v4l2_mmap,
Hans Verkuilc627b9d2010-12-18 11:06:09 -03001172 .unlocked_ioctl = video_ioctl2,
Thierry MERLE483dfdb2006-12-04 08:31:45 -03001173};
Hans Verkuila3998102008-07-21 02:57:38 -03001174
1175static const struct v4l2_ioctl_ops usbvision_ioctl_ops = {
Thierry MERLEc5f48362007-05-08 17:22:29 -03001176 .vidioc_querycap = vidioc_querycap,
Hans Verkuil78b526a2008-05-28 12:16:41 -03001177 .vidioc_enum_fmt_vid_cap = vidioc_enum_fmt_vid_cap,
1178 .vidioc_g_fmt_vid_cap = vidioc_g_fmt_vid_cap,
1179 .vidioc_try_fmt_vid_cap = vidioc_try_fmt_vid_cap,
1180 .vidioc_s_fmt_vid_cap = vidioc_s_fmt_vid_cap,
Thierry MERLEc5f48362007-05-08 17:22:29 -03001181 .vidioc_reqbufs = vidioc_reqbufs,
1182 .vidioc_querybuf = vidioc_querybuf,
1183 .vidioc_qbuf = vidioc_qbuf,
1184 .vidioc_dqbuf = vidioc_dqbuf,
1185 .vidioc_s_std = vidioc_s_std,
Hans Verkuil3b8436d2013-06-03 05:36:47 -03001186 .vidioc_g_std = vidioc_g_std,
Thierry MERLEc5f48362007-05-08 17:22:29 -03001187 .vidioc_enum_input = vidioc_enum_input,
1188 .vidioc_g_input = vidioc_g_input,
1189 .vidioc_s_input = vidioc_s_input,
Thierry MERLEc5f48362007-05-08 17:22:29 -03001190 .vidioc_streamon = vidioc_streamon,
1191 .vidioc_streamoff = vidioc_streamoff,
Thierry MERLEc5f48362007-05-08 17:22:29 -03001192 .vidioc_g_tuner = vidioc_g_tuner,
1193 .vidioc_s_tuner = vidioc_s_tuner,
1194 .vidioc_g_frequency = vidioc_g_frequency,
1195 .vidioc_s_frequency = vidioc_s_frequency,
Hans Verkuilfd958702015-07-20 09:59:29 -03001196 .vidioc_log_status = v4l2_ctrl_log_status,
1197 .vidioc_subscribe_event = v4l2_ctrl_subscribe_event,
1198 .vidioc_unsubscribe_event = v4l2_event_unsubscribe,
Thierry MERLEc5f48362007-05-08 17:22:29 -03001199#ifdef CONFIG_VIDEO_ADV_DEBUG
1200 .vidioc_g_register = vidioc_g_register,
1201 .vidioc_s_register = vidioc_s_register,
1202#endif
Hans Verkuila3998102008-07-21 02:57:38 -03001203};
1204
1205static struct video_device usbvision_video_template = {
Hans Verkuila3998102008-07-21 02:57:38 -03001206 .fops = &usbvision_fops,
Hans Verkuil6d6a48e2010-12-29 13:53:21 -03001207 .ioctl_ops = &usbvision_ioctl_ops,
Hans Verkuila3998102008-07-21 02:57:38 -03001208 .name = "usbvision-video",
Hans Verkuil2aa689d2015-03-09 13:34:12 -03001209 .release = video_device_release_empty,
Hans Verkuil6d6a48e2010-12-29 13:53:21 -03001210 .tvnorms = USBVISION_NORMS,
Thierry MERLE483dfdb2006-12-04 08:31:45 -03001211};
1212
1213
Hans Verkuil52cb0bf2010-12-19 20:33:51 -03001214/* Radio template */
Hans Verkuilbec43662008-12-30 06:58:20 -03001215static const struct v4l2_file_operations usbvision_radio_fops = {
Thierry MERLE483dfdb2006-12-04 08:31:45 -03001216 .owner = THIS_MODULE,
Thierry MERLE483dfdb2006-12-04 08:31:45 -03001217 .open = usbvision_radio_open,
1218 .release = usbvision_radio_close,
Hans Verkuilfd958702015-07-20 09:59:29 -03001219 .poll = v4l2_ctrl_poll,
Hans Verkuilc627b9d2010-12-18 11:06:09 -03001220 .unlocked_ioctl = video_ioctl2,
Thierry MERLE483dfdb2006-12-04 08:31:45 -03001221};
1222
Hans Verkuila3998102008-07-21 02:57:38 -03001223static const struct v4l2_ioctl_ops usbvision_radio_ioctl_ops = {
Thierry MERLEc5f48362007-05-08 17:22:29 -03001224 .vidioc_querycap = vidioc_querycap,
Thierry MERLEc5f48362007-05-08 17:22:29 -03001225 .vidioc_g_tuner = vidioc_g_tuner,
1226 .vidioc_s_tuner = vidioc_s_tuner,
1227 .vidioc_g_frequency = vidioc_g_frequency,
1228 .vidioc_s_frequency = vidioc_s_frequency,
Hans Verkuilfd958702015-07-20 09:59:29 -03001229 .vidioc_log_status = v4l2_ctrl_log_status,
1230 .vidioc_subscribe_event = v4l2_ctrl_subscribe_event,
1231 .vidioc_unsubscribe_event = v4l2_event_unsubscribe,
Hans Verkuila3998102008-07-21 02:57:38 -03001232};
1233
1234static struct video_device usbvision_radio_template = {
Hans Verkuila3998102008-07-21 02:57:38 -03001235 .fops = &usbvision_radio_fops,
Hans Verkuil6d6a48e2010-12-29 13:53:21 -03001236 .name = "usbvision-radio",
Hans Verkuil2aa689d2015-03-09 13:34:12 -03001237 .release = video_device_release_empty,
Hans Verkuil6d6a48e2010-12-29 13:53:21 -03001238 .ioctl_ops = &usbvision_radio_ioctl_ops,
Thierry MERLEc5f48362007-05-08 17:22:29 -03001239};
Thierry MERLE483dfdb2006-12-04 08:31:45 -03001240
Thierry MERLE483dfdb2006-12-04 08:31:45 -03001241
Hans Verkuil2aa689d2015-03-09 13:34:12 -03001242static void usbvision_vdev_init(struct usb_usbvision *usbvision,
1243 struct video_device *vdev,
1244 const struct video_device *vdev_template,
1245 const char *name)
Thierry MERLE483dfdb2006-12-04 08:31:45 -03001246{
1247 struct usb_device *usb_dev = usbvision->dev;
Thierry MERLE483dfdb2006-12-04 08:31:45 -03001248
1249 if (usb_dev == NULL) {
Mauro Carvalho Chehabbe9ed512009-01-08 09:13:42 -03001250 dev_err(&usbvision->dev->dev,
1251 "%s: usbvision->dev is not set\n", __func__);
Hans Verkuil2aa689d2015-03-09 13:34:12 -03001252 return;
Thierry MERLE483dfdb2006-12-04 08:31:45 -03001253 }
1254
Thierry MERLE483dfdb2006-12-04 08:31:45 -03001255 *vdev = *vdev_template;
Hans Verkuilc627b9d2010-12-18 11:06:09 -03001256 vdev->lock = &usbvision->v4l2_lock;
Hans Verkuil1df79532009-02-21 18:11:31 -03001257 vdev->v4l2_dev = &usbvision->v4l2_dev;
Thierry MERLE483dfdb2006-12-04 08:31:45 -03001258 snprintf(vdev->name, sizeof(vdev->name), "%s", name);
1259 video_set_drvdata(vdev, usbvision);
Thierry MERLE483dfdb2006-12-04 08:31:45 -03001260}
1261
Hans Verkuil52cb0bf2010-12-19 20:33:51 -03001262/* unregister video4linux devices */
Thierry MERLE483dfdb2006-12-04 08:31:45 -03001263static void usbvision_unregister_video(struct usb_usbvision *usbvision)
1264{
Hans Verkuil52cb0bf2010-12-19 20:33:51 -03001265 /* Radio Device: */
Hans Verkuil2aa689d2015-03-09 13:34:12 -03001266 if (video_is_registered(&usbvision->rdev)) {
Laurent Pinchart38c7c032009-11-27 13:57:15 -03001267 PDEBUG(DBG_PROBE, "unregister %s [v4l2]",
Hans Verkuil2aa689d2015-03-09 13:34:12 -03001268 video_device_node_name(&usbvision->rdev));
1269 video_unregister_device(&usbvision->rdev);
Thierry MERLE483dfdb2006-12-04 08:31:45 -03001270 }
1271
Hans Verkuil52cb0bf2010-12-19 20:33:51 -03001272 /* Video Device: */
Hans Verkuil2aa689d2015-03-09 13:34:12 -03001273 if (video_is_registered(&usbvision->vdev)) {
Laurent Pinchart38c7c032009-11-27 13:57:15 -03001274 PDEBUG(DBG_PROBE, "unregister %s [v4l2]",
Hans Verkuil2aa689d2015-03-09 13:34:12 -03001275 video_device_node_name(&usbvision->vdev));
1276 video_unregister_device(&usbvision->vdev);
Thierry MERLE483dfdb2006-12-04 08:31:45 -03001277 }
1278}
1279
Hans Verkuil52cb0bf2010-12-19 20:33:51 -03001280/* register video4linux devices */
Greg Kroah-Hartman4c62e972012-12-21 13:17:53 -08001281static int usbvision_register_video(struct usb_usbvision *usbvision)
Thierry MERLE483dfdb2006-12-04 08:31:45 -03001282{
Hans Verkuil2b436652015-07-20 09:59:30 -03001283 int res = -ENOMEM;
1284
Hans Verkuil52cb0bf2010-12-19 20:33:51 -03001285 /* Video Device: */
Hans Verkuil2aa689d2015-03-09 13:34:12 -03001286 usbvision_vdev_init(usbvision, &usbvision->vdev,
1287 &usbvision_video_template, "USBVision Video");
Hans Verkuil64d416e2015-07-20 09:59:33 -03001288 if (!usbvision->have_tuner) {
1289 v4l2_disable_ioctl(&usbvision->vdev, VIDIOC_G_FREQUENCY);
1290 v4l2_disable_ioctl(&usbvision->vdev, VIDIOC_S_TUNER);
1291 v4l2_disable_ioctl(&usbvision->vdev, VIDIOC_G_FREQUENCY);
1292 v4l2_disable_ioctl(&usbvision->vdev, VIDIOC_S_TUNER);
1293 }
Hans Verkuil2aa689d2015-03-09 13:34:12 -03001294 if (video_register_device(&usbvision->vdev, VFL_TYPE_GRABBER, video_nr) < 0)
Thierry MERLE483dfdb2006-12-04 08:31:45 -03001295 goto err_exit;
Laurent Pinchart38c7c032009-11-27 13:57:15 -03001296 printk(KERN_INFO "USBVision[%d]: registered USBVision Video device %s [v4l2]\n",
Hans Verkuil2aa689d2015-03-09 13:34:12 -03001297 usbvision->nr, video_device_node_name(&usbvision->vdev));
Thierry MERLE483dfdb2006-12-04 08:31:45 -03001298
Hans Verkuil52cb0bf2010-12-19 20:33:51 -03001299 /* Radio Device: */
Hans Verkuil5490a7c2010-12-19 20:21:36 -03001300 if (usbvision_device_data[usbvision->dev_model].radio) {
Hans Verkuil52cb0bf2010-12-19 20:33:51 -03001301 /* usbvision has radio */
Hans Verkuil2aa689d2015-03-09 13:34:12 -03001302 usbvision_vdev_init(usbvision, &usbvision->rdev,
1303 &usbvision_radio_template, "USBVision Radio");
1304 if (video_register_device(&usbvision->rdev, VFL_TYPE_RADIO, radio_nr) < 0)
Thierry MERLE483dfdb2006-12-04 08:31:45 -03001305 goto err_exit;
Laurent Pinchart38c7c032009-11-27 13:57:15 -03001306 printk(KERN_INFO "USBVision[%d]: registered USBVision Radio device %s [v4l2]\n",
Hans Verkuil2aa689d2015-03-09 13:34:12 -03001307 usbvision->nr, video_device_node_name(&usbvision->rdev));
Thierry MERLE483dfdb2006-12-04 08:31:45 -03001308 }
Hans Verkuil52cb0bf2010-12-19 20:33:51 -03001309 /* all done */
Thierry MERLE483dfdb2006-12-04 08:31:45 -03001310 return 0;
1311
1312 err_exit:
Mauro Carvalho Chehabbe9ed512009-01-08 09:13:42 -03001313 dev_err(&usbvision->dev->dev,
1314 "USBVision[%d]: video_register_device() failed\n",
1315 usbvision->nr);
Thierry MERLE483dfdb2006-12-04 08:31:45 -03001316 usbvision_unregister_video(usbvision);
Hans Verkuil2b436652015-07-20 09:59:30 -03001317 return res;
Thierry MERLE483dfdb2006-12-04 08:31:45 -03001318}
1319
1320/*
1321 * usbvision_alloc()
1322 *
Thierry MERLEc5f48362007-05-08 17:22:29 -03001323 * This code allocates the struct usb_usbvision.
1324 * It is filled with default values.
Thierry MERLE483dfdb2006-12-04 08:31:45 -03001325 *
1326 * Returns NULL on error, a pointer to usb_usbvision else.
1327 *
1328 */
Janne Grunaua8784402009-04-01 08:46:00 -03001329static struct usb_usbvision *usbvision_alloc(struct usb_device *dev,
1330 struct usb_interface *intf)
Thierry MERLE483dfdb2006-12-04 08:31:45 -03001331{
1332 struct usb_usbvision *usbvision;
1333
Hans Verkuil1df79532009-02-21 18:11:31 -03001334 usbvision = kzalloc(sizeof(struct usb_usbvision), GFP_KERNEL);
1335 if (usbvision == NULL)
1336 return NULL;
Thierry MERLE483dfdb2006-12-04 08:31:45 -03001337
1338 usbvision->dev = dev;
Janne Grunaua8784402009-04-01 08:46:00 -03001339 if (v4l2_device_register(&intf->dev, &usbvision->v4l2_dev))
Hans Verkuil1df79532009-02-21 18:11:31 -03001340 goto err_free;
Thierry MERLE483dfdb2006-12-04 08:31:45 -03001341
Hans Verkuilfd958702015-07-20 09:59:29 -03001342 if (v4l2_ctrl_handler_init(&usbvision->hdl, 4))
1343 goto err_unreg;
1344 usbvision->v4l2_dev.ctrl_handler = &usbvision->hdl;
Hans Verkuilc627b9d2010-12-18 11:06:09 -03001345 mutex_init(&usbvision->v4l2_lock);
Thierry MERLE483dfdb2006-12-04 08:31:45 -03001346
Hans Verkuil52cb0bf2010-12-19 20:33:51 -03001347 /* prepare control urb for control messages during interrupts */
Hans Verkuil5490a7c2010-12-19 20:21:36 -03001348 usbvision->ctrl_urb = usb_alloc_urb(USBVISION_URB_FRAMES, GFP_KERNEL);
1349 if (usbvision->ctrl_urb == NULL)
Hans Verkuil1df79532009-02-21 18:11:31 -03001350 goto err_unreg;
Hans Verkuil5490a7c2010-12-19 20:21:36 -03001351 init_waitqueue_head(&usbvision->ctrl_urb_wq);
Thierry MERLE483dfdb2006-12-04 08:31:45 -03001352
Thierry MERLE483dfdb2006-12-04 08:31:45 -03001353 return usbvision;
1354
Hans Verkuil1df79532009-02-21 18:11:31 -03001355err_unreg:
Hans Verkuilfd958702015-07-20 09:59:29 -03001356 v4l2_ctrl_handler_free(&usbvision->hdl);
Hans Verkuil1df79532009-02-21 18:11:31 -03001357 v4l2_device_unregister(&usbvision->v4l2_dev);
1358err_free:
1359 kfree(usbvision);
Thierry MERLE483dfdb2006-12-04 08:31:45 -03001360 return NULL;
1361}
1362
1363/*
1364 * usbvision_release()
1365 *
1366 * This code does final release of struct usb_usbvision. This happens
1367 * after the device is disconnected -and- all clients closed their files.
1368 *
1369 */
1370static void usbvision_release(struct usb_usbvision *usbvision)
1371{
1372 PDEBUG(DBG_PROBE, "");
1373
Thierry MERLE483dfdb2006-12-04 08:31:45 -03001374 usbvision->initialized = 0;
1375
Hans Verkuil2aa689d2015-03-09 13:34:12 -03001376 usbvision_remove_sysfs(&usbvision->vdev);
Thierry MERLE483dfdb2006-12-04 08:31:45 -03001377 usbvision_unregister_video(usbvision);
Alexey Khoroshilov090c65b2013-06-10 17:32:29 -03001378 kfree(usbvision->alt_max_pkt_size);
Thierry MERLE483dfdb2006-12-04 08:31:45 -03001379
Hans Verkuil6d6a48e2010-12-29 13:53:21 -03001380 usb_free_urb(usbvision->ctrl_urb);
Thierry MERLE483dfdb2006-12-04 08:31:45 -03001381
Hans Verkuilfd958702015-07-20 09:59:29 -03001382 v4l2_ctrl_handler_free(&usbvision->hdl);
Hans Verkuil1df79532009-02-21 18:11:31 -03001383 v4l2_device_unregister(&usbvision->v4l2_dev);
Thierry MERLE483dfdb2006-12-04 08:31:45 -03001384 kfree(usbvision);
1385
1386 PDEBUG(DBG_PROBE, "success");
1387}
1388
1389
Thierry MERLEc5f48362007-05-08 17:22:29 -03001390/*********************** usb interface **********************************/
Thierry MERLE483dfdb2006-12-04 08:31:45 -03001391
1392static void usbvision_configure_video(struct usb_usbvision *usbvision)
1393{
Thierry MERLEc5f48362007-05-08 17:22:29 -03001394 int model;
Thierry MERLE483dfdb2006-12-04 08:31:45 -03001395
1396 if (usbvision == NULL)
1397 return;
1398
Hans Verkuil5490a7c2010-12-19 20:21:36 -03001399 model = usbvision->dev_model;
Hans Verkuil52cb0bf2010-12-19 20:33:51 -03001400 usbvision->palette = usbvision_v4l2_format[2]; /* V4L2_PIX_FMT_RGB24; */
Thierry MERLE483dfdb2006-12-04 08:31:45 -03001401
Hans Verkuil5490a7c2010-12-19 20:21:36 -03001402 if (usbvision_device_data[usbvision->dev_model].vin_reg2_override) {
1403 usbvision->vin_reg2_preset =
1404 usbvision_device_data[usbvision->dev_model].vin_reg2;
Thierry MERLE483dfdb2006-12-04 08:31:45 -03001405 } else {
Hans Verkuil5490a7c2010-12-19 20:21:36 -03001406 usbvision->vin_reg2_preset = 0;
Thierry MERLE483dfdb2006-12-04 08:31:45 -03001407 }
1408
Hans Verkuil5490a7c2010-12-19 20:21:36 -03001409 usbvision->tvnorm_id = usbvision_device_data[model].video_norm;
Hans Verkuil5490a7c2010-12-19 20:21:36 -03001410 usbvision->video_inputs = usbvision_device_data[model].video_channels;
Thierry MERLE483dfdb2006-12-04 08:31:45 -03001411 usbvision->ctl_input = 0;
Hans Verkuil64d416e2015-07-20 09:59:33 -03001412 usbvision->radio_freq = 87.5 * 16000;
1413 usbvision->tv_freq = 400 * 16;
Thierry MERLE483dfdb2006-12-04 08:31:45 -03001414
1415 /* This should be here to make i2c clients to be able to register */
Thierry MERLEc5f48362007-05-08 17:22:29 -03001416 /* first switch off audio */
Ondrej Zary240d57b2011-04-27 17:36:05 -03001417 if (usbvision_device_data[model].audio_channels > 0)
1418 usbvision_audio_off(usbvision);
Hans Verkuil62e25942015-07-20 09:59:28 -03001419 /* and then power up the tuner */
1420 usbvision_power_on(usbvision);
1421 usbvision_i2c_register(usbvision);
Thierry MERLE483dfdb2006-12-04 08:31:45 -03001422}
1423
1424/*
1425 * usbvision_probe()
1426 *
1427 * This procedure queries device descriptor and accepts the interface
1428 * if it looks like USBVISION video device
1429 *
1430 */
Greg Kroah-Hartman4c62e972012-12-21 13:17:53 -08001431static int usbvision_probe(struct usb_interface *intf,
1432 const struct usb_device_id *devid)
Thierry MERLE483dfdb2006-12-04 08:31:45 -03001433{
Thierry MERLE2a9f8b52007-02-07 10:14:38 -03001434 struct usb_device *dev = usb_get_dev(interface_to_usbdev(intf));
1435 struct usb_interface *uif;
Thierry MERLE483dfdb2006-12-04 08:31:45 -03001436 __u8 ifnum = intf->altsetting->desc.bInterfaceNumber;
1437 const struct usb_host_interface *interface;
1438 struct usb_usbvision *usbvision = NULL;
1439 const struct usb_endpoint_descriptor *endpoint;
Alexey Khoroshilovafd270d2015-03-27 19:39:09 -03001440 int model, i, ret;
Thierry MERLE483dfdb2006-12-04 08:31:45 -03001441
1442 PDEBUG(DBG_PROBE, "VID=%#04x, PID=%#04x, ifnum=%u",
Mauro Carvalho Chehab659ae562007-04-14 15:09:59 -03001443 dev->descriptor.idVendor,
1444 dev->descriptor.idProduct, ifnum);
Thierry MERLE2a9f8b52007-02-07 10:14:38 -03001445
Mauro Carvalho Chehab659ae562007-04-14 15:09:59 -03001446 model = devid->driver_info;
Hans Verkuil6d6a48e2010-12-29 13:53:21 -03001447 if (model < 0 || model >= usbvision_device_data_size) {
1448 PDEBUG(DBG_PROBE, "model out of bounds %d", model);
Alexey Khoroshilovafd270d2015-03-27 19:39:09 -03001449 ret = -ENODEV;
1450 goto err_usb;
Mauro Carvalho Chehabf8a389d2007-04-14 15:17:35 -03001451 }
Harvey Harrisond2db42d2008-04-04 20:50:07 -03001452 printk(KERN_INFO "%s: %s found\n", __func__,
Hans Verkuil5490a7c2010-12-19 20:21:36 -03001453 usbvision_device_data[model].model_string);
Thierry MERLE483dfdb2006-12-04 08:31:45 -03001454
Hans Verkuil6d6a48e2010-12-29 13:53:21 -03001455 if (usbvision_device_data[model].interface >= 0)
Hans Verkuil5490a7c2010-12-19 20:21:36 -03001456 interface = &dev->actconfig->interface[usbvision_device_data[model].interface]->altsetting[0];
Vladis Dronovfa52bd502015-11-16 15:55:11 -02001457 else if (ifnum < dev->actconfig->desc.bNumInterfaces)
Thierry MERLE483dfdb2006-12-04 08:31:45 -03001458 interface = &dev->actconfig->interface[ifnum]->altsetting[0];
Vladis Dronovfa52bd502015-11-16 15:55:11 -02001459 else {
1460 dev_err(&intf->dev, "interface %d is invalid, max is %d\n",
1461 ifnum, dev->actconfig->desc.bNumInterfaces - 1);
1462 ret = -ENODEV;
1463 goto err_usb;
1464 }
1465
1466 if (interface->desc.bNumEndpoints < 2) {
1467 dev_err(&intf->dev, "interface %d has %d endpoints, but must"
1468 " have minimum 2\n", ifnum, interface->desc.bNumEndpoints);
1469 ret = -ENODEV;
1470 goto err_usb;
1471 }
Thierry MERLE483dfdb2006-12-04 08:31:45 -03001472 endpoint = &interface->endpoint[1].desc;
Vladis Dronovfa52bd502015-11-16 15:55:11 -02001473
Julia Lawall2230c3c2009-01-03 16:53:10 -03001474 if (!usb_endpoint_xfer_isoc(endpoint)) {
Mauro Carvalho Chehabbe9ed512009-01-08 09:13:42 -03001475 dev_err(&intf->dev, "%s: interface %d. has non-ISO endpoint!\n",
Harvey Harrisond2db42d2008-04-04 20:50:07 -03001476 __func__, ifnum);
Mauro Carvalho Chehabbe9ed512009-01-08 09:13:42 -03001477 dev_err(&intf->dev, "%s: Endpoint attributes %d",
Harvey Harrisond2db42d2008-04-04 20:50:07 -03001478 __func__, endpoint->bmAttributes);
Alexey Khoroshilovafd270d2015-03-27 19:39:09 -03001479 ret = -ENODEV;
1480 goto err_usb;
Thierry MERLE483dfdb2006-12-04 08:31:45 -03001481 }
Julia Lawall13417982008-12-29 21:49:22 -03001482 if (usb_endpoint_dir_out(endpoint)) {
Mauro Carvalho Chehabbe9ed512009-01-08 09:13:42 -03001483 dev_err(&intf->dev, "%s: interface %d. has ISO OUT endpoint!\n",
Harvey Harrisond2db42d2008-04-04 20:50:07 -03001484 __func__, ifnum);
Alexey Khoroshilovafd270d2015-03-27 19:39:09 -03001485 ret = -ENODEV;
1486 goto err_usb;
Thierry MERLE483dfdb2006-12-04 08:31:45 -03001487 }
1488
Janne Grunaua8784402009-04-01 08:46:00 -03001489 usbvision = usbvision_alloc(dev, intf);
1490 if (usbvision == NULL) {
Mauro Carvalho Chehabbe9ed512009-01-08 09:13:42 -03001491 dev_err(&intf->dev, "%s: couldn't allocate USBVision struct\n", __func__);
Alexey Khoroshilovafd270d2015-03-27 19:39:09 -03001492 ret = -ENOMEM;
1493 goto err_usb;
Thierry MERLE483dfdb2006-12-04 08:31:45 -03001494 }
Mauro Carvalho Chehab659ae562007-04-14 15:09:59 -03001495
Hans Verkuil6d6a48e2010-12-29 13:53:21 -03001496 if (dev->descriptor.bNumConfigurations > 1)
Hans Verkuil5490a7c2010-12-19 20:21:36 -03001497 usbvision->bridge_type = BRIDGE_NT1004;
Hans Verkuil6d6a48e2010-12-29 13:53:21 -03001498 else if (model == DAZZLE_DVC_90_REV_1_SECAM)
Hans Verkuil5490a7c2010-12-19 20:21:36 -03001499 usbvision->bridge_type = BRIDGE_NT1005;
Hans Verkuil6d6a48e2010-12-29 13:53:21 -03001500 else
Hans Verkuil5490a7c2010-12-19 20:21:36 -03001501 usbvision->bridge_type = BRIDGE_NT1003;
Hans Verkuil5490a7c2010-12-19 20:21:36 -03001502 PDEBUG(DBG_PROBE, "bridge_type %d", usbvision->bridge_type);
Thierry MERLE483dfdb2006-12-04 08:31:45 -03001503
Thierry MERLE2a9f8b52007-02-07 10:14:38 -03001504 /* compute alternate max packet sizes */
1505 uif = dev->actconfig->interface[0];
1506
Hans Verkuil6d6a48e2010-12-29 13:53:21 -03001507 usbvision->num_alt = uif->num_altsetting;
1508 PDEBUG(DBG_PROBE, "Alternate settings: %i", usbvision->num_alt);
1509 usbvision->alt_max_pkt_size = kmalloc(32 * usbvision->num_alt, GFP_KERNEL);
Thierry MERLE2a9f8b52007-02-07 10:14:38 -03001510 if (usbvision->alt_max_pkt_size == NULL) {
Mauro Carvalho Chehabbe9ed512009-01-08 09:13:42 -03001511 dev_err(&intf->dev, "usbvision: out of memory!\n");
Alexey Khoroshilovafd270d2015-03-27 19:39:09 -03001512 ret = -ENOMEM;
1513 goto err_pkt;
Thierry MERLE2a9f8b52007-02-07 10:14:38 -03001514 }
1515
Hans Verkuil6d6a48e2010-12-29 13:53:21 -03001516 for (i = 0; i < usbvision->num_alt; i++) {
Thierry MERLE2a9f8b52007-02-07 10:14:38 -03001517 u16 tmp = le16_to_cpu(uif->altsetting[i].endpoint[1].desc.
1518 wMaxPacketSize);
1519 usbvision->alt_max_pkt_size[i] =
1520 (tmp & 0x07ff) * (((tmp & 0x1800) >> 11) + 1);
Hans Verkuil6d6a48e2010-12-29 13:53:21 -03001521 PDEBUG(DBG_PROBE, "Alternate setting %i, max size= %i", i,
Thierry MERLE2a9f8b52007-02-07 10:14:38 -03001522 usbvision->alt_max_pkt_size[i]);
1523 }
1524
1525
Thierry MERLE483dfdb2006-12-04 08:31:45 -03001526 usbvision->nr = usbvision_nr++;
1527
Hans Verkuildf3cfa62015-07-20 09:59:38 -03001528 spin_lock_init(&usbvision->queue_lock);
1529 init_waitqueue_head(&usbvision->wait_frame);
1530 init_waitqueue_head(&usbvision->wait_stream);
1531
Hans Verkuil5490a7c2010-12-19 20:21:36 -03001532 usbvision->have_tuner = usbvision_device_data[model].tuner;
Hans Verkuil6d6a48e2010-12-29 13:53:21 -03001533 if (usbvision->have_tuner)
Hans Verkuil5490a7c2010-12-19 20:21:36 -03001534 usbvision->tuner_type = usbvision_device_data[model].tuner_type;
Thierry MERLE483dfdb2006-12-04 08:31:45 -03001535
Hans Verkuil5490a7c2010-12-19 20:21:36 -03001536 usbvision->dev_model = model;
Thierry MERLE483dfdb2006-12-04 08:31:45 -03001537 usbvision->remove_pending = 0;
1538 usbvision->iface = ifnum;
Hans Verkuil5490a7c2010-12-19 20:21:36 -03001539 usbvision->iface_alt = 0;
Thierry MERLE483dfdb2006-12-04 08:31:45 -03001540 usbvision->video_endp = endpoint->bEndpointAddress;
Hans Verkuil5490a7c2010-12-19 20:21:36 -03001541 usbvision->isoc_packet_size = 0;
Thierry MERLE483dfdb2006-12-04 08:31:45 -03001542 usbvision->usb_bandwidth = 0;
1543 usbvision->user = 0;
Hans Verkuil5490a7c2010-12-19 20:21:36 -03001544 usbvision->streaming = stream_off;
Thierry MERLE483dfdb2006-12-04 08:31:45 -03001545 usbvision_configure_video(usbvision);
Hans Verkuil84034722010-09-17 15:07:28 -03001546 usbvision_register_video(usbvision);
Thierry MERLE483dfdb2006-12-04 08:31:45 -03001547
Hans Verkuil2aa689d2015-03-09 13:34:12 -03001548 usbvision_create_sysfs(&usbvision->vdev);
Thierry MERLE483dfdb2006-12-04 08:31:45 -03001549
1550 PDEBUG(DBG_PROBE, "success");
1551 return 0;
Alexey Khoroshilovafd270d2015-03-27 19:39:09 -03001552
1553err_pkt:
1554 usbvision_release(usbvision);
1555err_usb:
1556 usb_put_dev(dev);
1557 return ret;
Thierry MERLE483dfdb2006-12-04 08:31:45 -03001558}
1559
1560
1561/*
1562 * usbvision_disconnect()
1563 *
1564 * This procedure stops all driver activity, deallocates interface-private
1565 * structure (pointed by 'ptr') and after that driver should be removable
1566 * with no ill consequences.
1567 *
1568 */
Greg Kroah-Hartman4c62e972012-12-21 13:17:53 -08001569static void usbvision_disconnect(struct usb_interface *intf)
Thierry MERLE483dfdb2006-12-04 08:31:45 -03001570{
Hans Verkuilaeb506a2010-05-02 09:00:13 -03001571 struct usb_usbvision *usbvision = to_usbvision(usb_get_intfdata(intf));
Thierry MERLE483dfdb2006-12-04 08:31:45 -03001572
1573 PDEBUG(DBG_PROBE, "");
1574
1575 if (usbvision == NULL) {
Julia Lawall42020662010-05-27 09:36:45 -03001576 pr_err("%s: usb_get_intfdata() failed\n", __func__);
Thierry MERLE483dfdb2006-12-04 08:31:45 -03001577 return;
1578 }
Thierry MERLE483dfdb2006-12-04 08:31:45 -03001579
Hans Verkuilc627b9d2010-12-18 11:06:09 -03001580 mutex_lock(&usbvision->v4l2_lock);
Thierry MERLE483dfdb2006-12-04 08:31:45 -03001581
Hans Verkuil52cb0bf2010-12-19 20:33:51 -03001582 /* At this time we ask to cancel outstanding URBs */
Thierry MERLE483dfdb2006-12-04 08:31:45 -03001583 usbvision_stop_isoc(usbvision);
1584
Hans Verkuilf1ba28c2009-03-14 12:27:01 -03001585 v4l2_device_disconnect(&usbvision->v4l2_dev);
Hans Verkuil62e25942015-07-20 09:59:28 -03001586 usbvision_i2c_unregister(usbvision);
Hans Verkuil52cb0bf2010-12-19 20:33:51 -03001587 usbvision->remove_pending = 1; /* Now all ISO data will be ignored */
Thierry MERLE483dfdb2006-12-04 08:31:45 -03001588
1589 usb_put_dev(usbvision->dev);
Hans Verkuil52cb0bf2010-12-19 20:33:51 -03001590 usbvision->dev = NULL; /* USB device is no more */
Thierry MERLE483dfdb2006-12-04 08:31:45 -03001591
Hans Verkuilc627b9d2010-12-18 11:06:09 -03001592 mutex_unlock(&usbvision->v4l2_lock);
Thierry MERLE483dfdb2006-12-04 08:31:45 -03001593
1594 if (usbvision->user) {
Thierry MERLEc5f48362007-05-08 17:22:29 -03001595 printk(KERN_INFO "%s: In use, disconnect pending\n",
Harvey Harrisond2db42d2008-04-04 20:50:07 -03001596 __func__);
Thierry MERLE483dfdb2006-12-04 08:31:45 -03001597 wake_up_interruptible(&usbvision->wait_frame);
1598 wake_up_interruptible(&usbvision->wait_stream);
Thierry MERLEc5f48362007-05-08 17:22:29 -03001599 } else {
Thierry MERLE483dfdb2006-12-04 08:31:45 -03001600 usbvision_release(usbvision);
1601 }
1602
1603 PDEBUG(DBG_PROBE, "success");
Thierry MERLE483dfdb2006-12-04 08:31:45 -03001604}
1605
1606static struct usb_driver usbvision_driver = {
1607 .name = "usbvision",
1608 .id_table = usbvision_table,
1609 .probe = usbvision_probe,
Greg Kroah-Hartman4c62e972012-12-21 13:17:53 -08001610 .disconnect = usbvision_disconnect,
Thierry MERLE483dfdb2006-12-04 08:31:45 -03001611};
1612
1613/*
Thierry MERLE483dfdb2006-12-04 08:31:45 -03001614 * usbvision_init()
1615 *
1616 * This code is run to initialize the driver.
1617 *
1618 */
1619static int __init usbvision_init(void)
1620{
Hans Verkuil5490a7c2010-12-19 20:21:36 -03001621 int err_code;
Thierry MERLE483dfdb2006-12-04 08:31:45 -03001622
1623 PDEBUG(DBG_PROBE, "");
1624
Thierry MERLE483dfdb2006-12-04 08:31:45 -03001625 PDEBUG(DBG_IO, "IO debugging is enabled [video]");
1626 PDEBUG(DBG_PROBE, "PROBE debugging is enabled [video]");
Thierry MERLEc876a342006-12-09 16:42:54 -03001627 PDEBUG(DBG_MMAP, "MMAP debugging is enabled [video]");
Thierry MERLE483dfdb2006-12-04 08:31:45 -03001628
1629 /* disable planar mode support unless compression enabled */
Hans Verkuil6d6a48e2010-12-29 13:53:21 -03001630 if (isoc_mode != ISOC_MODE_COMPRESS) {
Hans Verkuil52cb0bf2010-12-19 20:33:51 -03001631 /* FIXME : not the right way to set supported flag */
1632 usbvision_v4l2_format[6].supported = 0; /* V4L2_PIX_FMT_YVU420 */
1633 usbvision_v4l2_format[7].supported = 0; /* V4L2_PIX_FMT_YUV422P */
Thierry MERLE483dfdb2006-12-04 08:31:45 -03001634 }
1635
Hans Verkuil5490a7c2010-12-19 20:21:36 -03001636 err_code = usb_register(&usbvision_driver);
Thierry MERLE483dfdb2006-12-04 08:31:45 -03001637
Hans Verkuil5490a7c2010-12-19 20:21:36 -03001638 if (err_code == 0) {
Dwaine Gardende6a1b82007-01-07 21:13:55 -03001639 printk(KERN_INFO DRIVER_DESC " : " USBVISION_VERSION_STRING "\n");
Thierry MERLE483dfdb2006-12-04 08:31:45 -03001640 PDEBUG(DBG_PROBE, "success");
1641 }
Hans Verkuil5490a7c2010-12-19 20:21:36 -03001642 return err_code;
Thierry MERLE483dfdb2006-12-04 08:31:45 -03001643}
1644
1645static void __exit usbvision_exit(void)
1646{
Hans Verkuil6d6a48e2010-12-29 13:53:21 -03001647 PDEBUG(DBG_PROBE, "");
Thierry MERLE483dfdb2006-12-04 08:31:45 -03001648
Hans Verkuil6d6a48e2010-12-29 13:53:21 -03001649 usb_deregister(&usbvision_driver);
1650 PDEBUG(DBG_PROBE, "success");
Thierry MERLE483dfdb2006-12-04 08:31:45 -03001651}
1652
1653module_init(usbvision_init);
1654module_exit(usbvision_exit);