blob: 5a74f5e07d7dd6bf1caf42d310ca01294f5db9ee [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
62#include <media/saa7115.h>
63#include <media/v4l2-common.h>
Hans Verkuil35ea11f2008-07-20 08:12:02 -030064#include <media/v4l2-ioctl.h>
Thierry MERLE483dfdb2006-12-04 08:31:45 -030065#include <media/tuner.h>
Thierry MERLE483dfdb2006-12-04 08:31:45 -030066
Mauro Carvalho Chehaba1ed5512006-12-09 11:41:59 -030067#include <linux/workqueue.h>
Thierry MERLE483dfdb2006-12-04 08:31:45 -030068
Thierry MERLE483dfdb2006-12-04 08:31:45 -030069#include "usbvision.h"
Mauro Carvalho Chehab659ae562007-04-14 15:09:59 -030070#include "usbvision-cards.h"
Thierry MERLE483dfdb2006-12-04 08:31:45 -030071
Joe Perches85ee7a12011-04-23 20:38:19 -070072#define DRIVER_AUTHOR \
73 "Joerg Heckenbach <joerg@heckenbach-aw.de>, " \
74 "Dwaine Garden <DwaineGarden@rogers.com>"
Thierry MERLE483dfdb2006-12-04 08:31:45 -030075#define DRIVER_NAME "usbvision"
76#define DRIVER_ALIAS "USBVision"
77#define DRIVER_DESC "USBVision USB Video Device Driver for Linux"
78#define DRIVER_LICENSE "GPL"
Mauro Carvalho Chehab1990d502011-06-24 14:45:49 -030079#define USBVISION_VERSION_STRING "0.9.11"
Thierry MERLE483dfdb2006-12-04 08:31:45 -030080
81#define ENABLE_HEXDUMP 0 /* Enable if you need it */
82
83
Thierry MERLE483dfdb2006-12-04 08:31:45 -030084#ifdef USBVISION_DEBUG
Thierry MERLEdf18c312008-04-04 21:00:57 -030085 #define PDEBUG(level, fmt, args...) { \
Thierry MERLEc5f48362007-05-08 17:22:29 -030086 if (video_debug & (level)) \
Greg Kroah-Hartmana482f322008-10-10 05:08:23 -030087 printk(KERN_INFO KBUILD_MODNAME ":[%s:%d] " fmt, \
88 __func__, __LINE__ , ## args); \
Thierry MERLEdf18c312008-04-04 21:00:57 -030089 }
Thierry MERLE483dfdb2006-12-04 08:31:45 -030090#else
Hans Verkuil6d6a48e2010-12-29 13:53:21 -030091 #define PDEBUG(level, fmt, args...) do {} while (0)
Thierry MERLE483dfdb2006-12-04 08:31:45 -030092#endif
93
Hans Verkuil6d6a48e2010-12-29 13:53:21 -030094#define DBG_IO (1 << 1)
95#define DBG_PROBE (1 << 2)
96#define DBG_MMAP (1 << 3)
Thierry MERLE483dfdb2006-12-04 08:31:45 -030097
Hans Verkuil52cb0bf2010-12-19 20:33:51 -030098/* String operations */
Hans Verkuil6d6a48e2010-12-29 13:53:21 -030099#define rmspace(str) while (*str == ' ') str++;
100#define goto2next(str) while (*str != ' ') str++; while (*str == ' ') str++;
Thierry MERLE483dfdb2006-12-04 08:31:45 -0300101
102
Thierry MERLEc5f48362007-05-08 17:22:29 -0300103/* sequential number of usbvision device */
Douglas Schilling Landgrafff699e62008-04-22 14:41:48 -0300104static int usbvision_nr;
Thierry MERLE483dfdb2006-12-04 08:31:45 -0300105
106static struct usbvision_v4l2_format_st usbvision_v4l2_format[] = {
107 { 1, 1, 8, V4L2_PIX_FMT_GREY , "GREY" },
108 { 1, 2, 16, V4L2_PIX_FMT_RGB565 , "RGB565" },
109 { 1, 3, 24, V4L2_PIX_FMT_RGB24 , "RGB24" },
110 { 1, 4, 32, V4L2_PIX_FMT_RGB32 , "RGB32" },
111 { 1, 2, 16, V4L2_PIX_FMT_RGB555 , "RGB555" },
112 { 1, 2, 16, V4L2_PIX_FMT_YUYV , "YUV422" },
Hans Verkuil52cb0bf2010-12-19 20:33:51 -0300113 { 1, 2, 12, V4L2_PIX_FMT_YVU420 , "YUV420P" }, /* 1.5 ! */
Thierry MERLE483dfdb2006-12-04 08:31:45 -0300114 { 1, 2, 16, V4L2_PIX_FMT_YUV422P , "YUV422P" }
115};
116
Thierry MERLEc5f48362007-05-08 17:22:29 -0300117/* Function prototypes */
Thierry MERLE483dfdb2006-12-04 08:31:45 -0300118static void usbvision_release(struct usb_usbvision *usbvision);
119
Joe Perchesc84e6032008-02-03 17:18:59 +0200120/* Default initialization of device driver parameters */
Thierry MERLEc5f48362007-05-08 17:22:29 -0300121/* Set the default format for ISOC endpoint */
Hans Verkuil5490a7c2010-12-19 20:21:36 -0300122static int isoc_mode = ISOC_MODE_COMPRESS;
Thierry MERLEc5f48362007-05-08 17:22:29 -0300123/* Set the default Debug Mode of the device driver */
Douglas Schilling Landgrafff699e62008-04-22 14:41:48 -0300124static int video_debug;
Thierry MERLEc5f48362007-05-08 17:22:29 -0300125/* Set the default device to power on at startup */
Hans Verkuil5490a7c2010-12-19 20:21:36 -0300126static int power_on_at_open = 1;
Thierry MERLEc5f48362007-05-08 17:22:29 -0300127/* Sequential Number of Video Device */
128static int video_nr = -1;
129/* Sequential Number of Radio Device */
130static int radio_nr = -1;
Thierry MERLE483dfdb2006-12-04 08:31:45 -0300131
Thierry MERLEc5f48362007-05-08 17:22:29 -0300132/* Grab parameters for the device driver */
Thierry MERLE483dfdb2006-12-04 08:31:45 -0300133
Thierry MERLEc5f48362007-05-08 17:22:29 -0300134/* Showing parameters under SYSFS */
Hans Verkuil5490a7c2010-12-19 20:21:36 -0300135module_param(isoc_mode, int, 0444);
Thierry MERLE483dfdb2006-12-04 08:31:45 -0300136module_param(video_debug, int, 0444);
Hans Verkuil5490a7c2010-12-19 20:21:36 -0300137module_param(power_on_at_open, int, 0444);
Thierry MERLE483dfdb2006-12-04 08:31:45 -0300138module_param(video_nr, int, 0444);
139module_param(radio_nr, int, 0444);
Thierry MERLE483dfdb2006-12-04 08:31:45 -0300140
Hans Verkuil5490a7c2010-12-19 20:21:36 -0300141MODULE_PARM_DESC(isoc_mode, " Set the default format for ISOC endpoint. Default: 0x60 (Compression On)");
Thierry MERLE483dfdb2006-12-04 08:31:45 -0300142MODULE_PARM_DESC(video_debug, " Set the default Debug Mode of the device driver. Default: 0 (Off)");
Hans Verkuil5490a7c2010-12-19 20:21:36 -0300143MODULE_PARM_DESC(power_on_at_open, " Set the default device to power on when device is opened. Default: 1 (On)");
Thierry MERLE483dfdb2006-12-04 08:31:45 -0300144MODULE_PARM_DESC(video_nr, "Set video device number (/dev/videoX). Default: -1 (autodetect)");
145MODULE_PARM_DESC(radio_nr, "Set radio device number (/dev/radioX). Default: -1 (autodetect)");
Thierry MERLE483dfdb2006-12-04 08:31:45 -0300146
147
Hans Verkuil52cb0bf2010-12-19 20:33:51 -0300148/* Misc stuff */
Thierry MERLE483dfdb2006-12-04 08:31:45 -0300149MODULE_AUTHOR(DRIVER_AUTHOR);
150MODULE_DESCRIPTION(DRIVER_DESC);
151MODULE_LICENSE(DRIVER_LICENSE);
Mauro Carvalho Chehaba1ed5512006-12-09 11:41:59 -0300152MODULE_VERSION(USBVISION_VERSION_STRING);
153MODULE_ALIAS(DRIVER_ALIAS);
Thierry MERLE483dfdb2006-12-04 08:31:45 -0300154
155
Thierry MERLEc5f48362007-05-08 17:22:29 -0300156/*****************************************************************************/
157/* SYSFS Code - Copied from the stv680.c usb module. */
158/* Device information is located at /sys/class/video4linux/video0 */
159/* Device parameters information is located at /sys/module/usbvision */
160/* Device USB Information is located at */
161/* /sys/bus/usb/drivers/USBVision Video Grabber */
162/*****************************************************************************/
Thierry MERLE483dfdb2006-12-04 08:31:45 -0300163
Thierry MERLE483dfdb2006-12-04 08:31:45 -0300164#define YES_NO(x) ((x) ? "Yes" : "No")
165
Kay Sievers54bd5b62007-10-08 16:26:13 -0300166static inline struct usb_usbvision *cd_to_usbvision(struct device *cd)
Thierry MERLE483dfdb2006-12-04 08:31:45 -0300167{
Thierry MERLEc5f48362007-05-08 17:22:29 -0300168 struct video_device *vdev =
Hans Verkuil22a04f12008-07-20 06:35:02 -0300169 container_of(cd, struct video_device, dev);
Thierry MERLE483dfdb2006-12-04 08:31:45 -0300170 return video_get_drvdata(vdev);
171}
172
Kay Sievers54bd5b62007-10-08 16:26:13 -0300173static ssize_t show_version(struct device *cd,
174 struct device_attribute *attr, char *buf)
Thierry MERLE483dfdb2006-12-04 08:31:45 -0300175{
176 return sprintf(buf, "%s\n", USBVISION_VERSION_STRING);
177}
Kay Sievers54bd5b62007-10-08 16:26:13 -0300178static DEVICE_ATTR(version, S_IRUGO, show_version, NULL);
Thierry MERLE483dfdb2006-12-04 08:31:45 -0300179
Kay Sievers54bd5b62007-10-08 16:26:13 -0300180static ssize_t show_model(struct device *cd,
181 struct device_attribute *attr, char *buf)
Thierry MERLE483dfdb2006-12-04 08:31:45 -0300182{
Thierry MERLEc5f48362007-05-08 17:22:29 -0300183 struct video_device *vdev =
Hans Verkuil22a04f12008-07-20 06:35:02 -0300184 container_of(cd, struct video_device, dev);
Thierry MERLE483dfdb2006-12-04 08:31:45 -0300185 struct usb_usbvision *usbvision = video_get_drvdata(vdev);
Thierry MERLEc5f48362007-05-08 17:22:29 -0300186 return sprintf(buf, "%s\n",
Hans Verkuil5490a7c2010-12-19 20:21:36 -0300187 usbvision_device_data[usbvision->dev_model].model_string);
Thierry MERLE483dfdb2006-12-04 08:31:45 -0300188}
Kay Sievers54bd5b62007-10-08 16:26:13 -0300189static DEVICE_ATTR(model, S_IRUGO, show_model, NULL);
Thierry MERLE483dfdb2006-12-04 08:31:45 -0300190
Kay Sievers54bd5b62007-10-08 16:26:13 -0300191static ssize_t show_hue(struct device *cd,
192 struct device_attribute *attr, char *buf)
Thierry MERLE483dfdb2006-12-04 08:31:45 -0300193{
Thierry MERLEc5f48362007-05-08 17:22:29 -0300194 struct video_device *vdev =
Hans Verkuil22a04f12008-07-20 06:35:02 -0300195 container_of(cd, struct video_device, dev);
Thierry MERLE483dfdb2006-12-04 08:31:45 -0300196 struct usb_usbvision *usbvision = video_get_drvdata(vdev);
197 struct v4l2_control ctrl;
198 ctrl.id = V4L2_CID_HUE;
199 ctrl.value = 0;
Hans Verkuil6d6a48e2010-12-29 13:53:21 -0300200 if (usbvision->user)
Hans Verkuil1df79532009-02-21 18:11:31 -0300201 call_all(usbvision, core, g_ctrl, &ctrl);
Thierry MERLE2a9f8b52007-02-07 10:14:38 -0300202 return sprintf(buf, "%d\n", ctrl.value);
Thierry MERLE483dfdb2006-12-04 08:31:45 -0300203}
Kay Sievers54bd5b62007-10-08 16:26:13 -0300204static DEVICE_ATTR(hue, S_IRUGO, show_hue, NULL);
Thierry MERLE483dfdb2006-12-04 08:31:45 -0300205
Kay Sievers54bd5b62007-10-08 16:26:13 -0300206static ssize_t show_contrast(struct device *cd,
207 struct device_attribute *attr, char *buf)
Thierry MERLE483dfdb2006-12-04 08:31:45 -0300208{
Thierry MERLEc5f48362007-05-08 17:22:29 -0300209 struct video_device *vdev =
Hans Verkuil22a04f12008-07-20 06:35:02 -0300210 container_of(cd, struct video_device, dev);
Thierry MERLE483dfdb2006-12-04 08:31:45 -0300211 struct usb_usbvision *usbvision = video_get_drvdata(vdev);
212 struct v4l2_control ctrl;
213 ctrl.id = V4L2_CID_CONTRAST;
214 ctrl.value = 0;
Hans Verkuil6d6a48e2010-12-29 13:53:21 -0300215 if (usbvision->user)
Hans Verkuil1df79532009-02-21 18:11:31 -0300216 call_all(usbvision, core, g_ctrl, &ctrl);
Thierry MERLE2a9f8b52007-02-07 10:14:38 -0300217 return sprintf(buf, "%d\n", ctrl.value);
Thierry MERLE483dfdb2006-12-04 08:31:45 -0300218}
Kay Sievers54bd5b62007-10-08 16:26:13 -0300219static DEVICE_ATTR(contrast, S_IRUGO, show_contrast, NULL);
Thierry MERLE483dfdb2006-12-04 08:31:45 -0300220
Kay Sievers54bd5b62007-10-08 16:26:13 -0300221static ssize_t show_brightness(struct device *cd,
222 struct device_attribute *attr, char *buf)
Thierry MERLE483dfdb2006-12-04 08:31:45 -0300223{
Thierry MERLEc5f48362007-05-08 17:22:29 -0300224 struct video_device *vdev =
Hans Verkuil22a04f12008-07-20 06:35:02 -0300225 container_of(cd, struct video_device, dev);
Thierry MERLE483dfdb2006-12-04 08:31:45 -0300226 struct usb_usbvision *usbvision = video_get_drvdata(vdev);
227 struct v4l2_control ctrl;
228 ctrl.id = V4L2_CID_BRIGHTNESS;
229 ctrl.value = 0;
Hans Verkuil6d6a48e2010-12-29 13:53:21 -0300230 if (usbvision->user)
Hans Verkuil1df79532009-02-21 18:11:31 -0300231 call_all(usbvision, core, g_ctrl, &ctrl);
Thierry MERLE2a9f8b52007-02-07 10:14:38 -0300232 return sprintf(buf, "%d\n", ctrl.value);
Thierry MERLE483dfdb2006-12-04 08:31:45 -0300233}
Kay Sievers54bd5b62007-10-08 16:26:13 -0300234static DEVICE_ATTR(brightness, S_IRUGO, show_brightness, NULL);
Thierry MERLE483dfdb2006-12-04 08:31:45 -0300235
Kay Sievers54bd5b62007-10-08 16:26:13 -0300236static ssize_t show_saturation(struct device *cd,
237 struct device_attribute *attr, char *buf)
Thierry MERLE483dfdb2006-12-04 08:31:45 -0300238{
Thierry MERLEc5f48362007-05-08 17:22:29 -0300239 struct video_device *vdev =
Hans Verkuil22a04f12008-07-20 06:35:02 -0300240 container_of(cd, struct video_device, dev);
Thierry MERLE483dfdb2006-12-04 08:31:45 -0300241 struct usb_usbvision *usbvision = video_get_drvdata(vdev);
242 struct v4l2_control ctrl;
243 ctrl.id = V4L2_CID_SATURATION;
244 ctrl.value = 0;
Hans Verkuil6d6a48e2010-12-29 13:53:21 -0300245 if (usbvision->user)
Hans Verkuil1df79532009-02-21 18:11:31 -0300246 call_all(usbvision, core, g_ctrl, &ctrl);
Thierry MERLE2a9f8b52007-02-07 10:14:38 -0300247 return sprintf(buf, "%d\n", ctrl.value);
Thierry MERLE483dfdb2006-12-04 08:31:45 -0300248}
Kay Sievers54bd5b62007-10-08 16:26:13 -0300249static DEVICE_ATTR(saturation, S_IRUGO, show_saturation, NULL);
Thierry MERLE483dfdb2006-12-04 08:31:45 -0300250
Kay Sievers54bd5b62007-10-08 16:26:13 -0300251static ssize_t show_streaming(struct device *cd,
252 struct device_attribute *attr, char *buf)
Thierry MERLE483dfdb2006-12-04 08:31:45 -0300253{
Thierry MERLEc5f48362007-05-08 17:22:29 -0300254 struct video_device *vdev =
Hans Verkuil22a04f12008-07-20 06:35:02 -0300255 container_of(cd, struct video_device, dev);
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->streaming == stream_on ? 1 : 0));
Thierry MERLE483dfdb2006-12-04 08:31:45 -0300259}
Kay Sievers54bd5b62007-10-08 16:26:13 -0300260static DEVICE_ATTR(streaming, S_IRUGO, show_streaming, NULL);
Thierry MERLE483dfdb2006-12-04 08:31:45 -0300261
Kay Sievers54bd5b62007-10-08 16:26:13 -0300262static ssize_t show_compression(struct device *cd,
263 struct device_attribute *attr, char *buf)
Thierry MERLE483dfdb2006-12-04 08:31:45 -0300264{
Thierry MERLEc5f48362007-05-08 17:22:29 -0300265 struct video_device *vdev =
Hans Verkuil22a04f12008-07-20 06:35:02 -0300266 container_of(cd, struct video_device, dev);
Thierry MERLE483dfdb2006-12-04 08:31:45 -0300267 struct usb_usbvision *usbvision = video_get_drvdata(vdev);
Thierry MERLEc5f48362007-05-08 17:22:29 -0300268 return sprintf(buf, "%s\n",
Hans Verkuil6d6a48e2010-12-29 13:53:21 -0300269 YES_NO(usbvision->isoc_mode == ISOC_MODE_COMPRESS));
Thierry MERLE483dfdb2006-12-04 08:31:45 -0300270}
Kay Sievers54bd5b62007-10-08 16:26:13 -0300271static DEVICE_ATTR(compression, S_IRUGO, show_compression, NULL);
Thierry MERLE483dfdb2006-12-04 08:31:45 -0300272
Kay Sievers54bd5b62007-10-08 16:26:13 -0300273static ssize_t show_device_bridge(struct device *cd,
274 struct device_attribute *attr, char *buf)
Thierry MERLE483dfdb2006-12-04 08:31:45 -0300275{
Thierry MERLEc5f48362007-05-08 17:22:29 -0300276 struct video_device *vdev =
Hans Verkuil22a04f12008-07-20 06:35:02 -0300277 container_of(cd, struct video_device, dev);
Thierry MERLE483dfdb2006-12-04 08:31:45 -0300278 struct usb_usbvision *usbvision = video_get_drvdata(vdev);
Hans Verkuil5490a7c2010-12-19 20:21:36 -0300279 return sprintf(buf, "%d\n", usbvision->bridge_type);
Thierry MERLE483dfdb2006-12-04 08:31:45 -0300280}
Kay Sievers54bd5b62007-10-08 16:26:13 -0300281static DEVICE_ATTR(bridge, S_IRUGO, show_device_bridge, NULL);
Thierry MERLE483dfdb2006-12-04 08:31:45 -0300282
283static void usbvision_create_sysfs(struct video_device *vdev)
284{
285 int res;
Hans Verkuil6d6a48e2010-12-29 13:53:21 -0300286
Dwaine Gardened00b412006-12-27 10:23:28 -0200287 if (!vdev)
288 return;
289 do {
Hans Verkuil22a04f12008-07-20 06:35:02 -0300290 res = device_create_file(&vdev->dev, &dev_attr_version);
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_model);
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_hue);
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_contrast);
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_brightness);
Hans Verkuil6d6a48e2010-12-29 13:53:21 -0300303 if (res < 0)
Dwaine Gardened00b412006-12-27 10:23:28 -0200304 break;
Hans Verkuil22a04f12008-07-20 06:35:02 -0300305 res = device_create_file(&vdev->dev, &dev_attr_saturation);
Hans Verkuil6d6a48e2010-12-29 13:53:21 -0300306 if (res < 0)
Dwaine Gardened00b412006-12-27 10:23:28 -0200307 break;
Hans Verkuil22a04f12008-07-20 06:35:02 -0300308 res = device_create_file(&vdev->dev, &dev_attr_streaming);
Hans Verkuil6d6a48e2010-12-29 13:53:21 -0300309 if (res < 0)
Dwaine Gardened00b412006-12-27 10:23:28 -0200310 break;
Hans Verkuil22a04f12008-07-20 06:35:02 -0300311 res = device_create_file(&vdev->dev, &dev_attr_compression);
Hans Verkuil6d6a48e2010-12-29 13:53:21 -0300312 if (res < 0)
Dwaine Gardened00b412006-12-27 10:23:28 -0200313 break;
Hans Verkuil22a04f12008-07-20 06:35:02 -0300314 res = device_create_file(&vdev->dev, &dev_attr_bridge);
Hans Verkuil6d6a48e2010-12-29 13:53:21 -0300315 if (res >= 0)
Dwaine Gardened00b412006-12-27 10:23:28 -0200316 return;
317 } while (0);
318
Mauro Carvalho Chehabbe9ed512009-01-08 09:13:42 -0300319 dev_err(&vdev->dev, "%s error: %d\n", __func__, res);
Thierry MERLE483dfdb2006-12-04 08:31:45 -0300320}
321
322static void usbvision_remove_sysfs(struct video_device *vdev)
323{
324 if (vdev) {
Hans Verkuil22a04f12008-07-20 06:35:02 -0300325 device_remove_file(&vdev->dev, &dev_attr_version);
326 device_remove_file(&vdev->dev, &dev_attr_model);
327 device_remove_file(&vdev->dev, &dev_attr_hue);
328 device_remove_file(&vdev->dev, &dev_attr_contrast);
329 device_remove_file(&vdev->dev, &dev_attr_brightness);
330 device_remove_file(&vdev->dev, &dev_attr_saturation);
331 device_remove_file(&vdev->dev, &dev_attr_streaming);
332 device_remove_file(&vdev->dev, &dev_attr_compression);
333 device_remove_file(&vdev->dev, &dev_attr_bridge);
Thierry MERLE483dfdb2006-12-04 08:31:45 -0300334 }
335}
336
Thierry MERLE483dfdb2006-12-04 08:31:45 -0300337/*
338 * usbvision_open()
339 *
340 * This is part of Video 4 Linux API. The driver can be opened by one
341 * client only (checks internal counter 'usbvision->user'). The procedure
342 * then allocates buffers needed for video processing.
343 *
344 */
Hans Verkuilbec43662008-12-30 06:58:20 -0300345static int usbvision_v4l2_open(struct file *file)
Thierry MERLE483dfdb2006-12-04 08:31:45 -0300346{
Hans Verkuilc170ecf2008-08-23 08:32:09 -0300347 struct usb_usbvision *usbvision = video_drvdata(file);
Hans Verkuil5490a7c2010-12-19 20:21:36 -0300348 int err_code = 0;
Thierry MERLE483dfdb2006-12-04 08:31:45 -0300349
350 PDEBUG(DBG_IO, "open");
351
Hans Verkuil5490a7c2010-12-19 20:21:36 -0300352 usbvision_reset_power_off_timer(usbvision);
Thierry MERLE483dfdb2006-12-04 08:31:45 -0300353
354 if (usbvision->user)
Hans Verkuil5490a7c2010-12-19 20:21:36 -0300355 err_code = -EBUSY;
Thierry MERLE483dfdb2006-12-04 08:31:45 -0300356 else {
Thierry MERLE6f78e182007-02-07 10:13:11 -0300357 /* Allocate memory for the scratch ring buffer */
Hans Verkuil5490a7c2010-12-19 20:21:36 -0300358 err_code = usbvision_scratch_alloc(usbvision);
Hans Verkuil6d6a48e2010-12-29 13:53:21 -0300359 if (isoc_mode == ISOC_MODE_COMPRESS) {
Thierry MERLEc5f48362007-05-08 17:22:29 -0300360 /* Allocate intermediate decompression buffers
361 only if needed */
Hans Verkuil5490a7c2010-12-19 20:21:36 -0300362 err_code = usbvision_decompress_alloc(usbvision);
Thierry MERLE483dfdb2006-12-04 08:31:45 -0300363 }
Hans Verkuil5490a7c2010-12-19 20:21:36 -0300364 if (err_code) {
Thierry MERLE483dfdb2006-12-04 08:31:45 -0300365 /* Deallocate all buffers if trouble */
Thierry MERLE483dfdb2006-12-04 08:31:45 -0300366 usbvision_scratch_free(usbvision);
Thierry MERLE483dfdb2006-12-04 08:31:45 -0300367 usbvision_decompress_free(usbvision);
368 }
369 }
370
371 /* If so far no errors then we shall start the camera */
Hans Verkuil5490a7c2010-12-19 20:21:36 -0300372 if (!err_code) {
Thierry MERLE483dfdb2006-12-04 08:31:45 -0300373 if (usbvision->power == 0) {
374 usbvision_power_on(usbvision);
Thierry MERLE1ff16c22007-04-14 16:23:49 -0300375 usbvision_i2c_register(usbvision);
Thierry MERLE483dfdb2006-12-04 08:31:45 -0300376 }
377
378 /* Send init sequence only once, it's large! */
379 if (!usbvision->initialized) {
380 int setup_ok = 0;
Hans Verkuil6d6a48e2010-12-29 13:53:21 -0300381 setup_ok = usbvision_setup(usbvision, isoc_mode);
Thierry MERLE483dfdb2006-12-04 08:31:45 -0300382 if (setup_ok)
383 usbvision->initialized = 1;
384 else
Hans Verkuil5490a7c2010-12-19 20:21:36 -0300385 err_code = -EBUSY;
Thierry MERLE483dfdb2006-12-04 08:31:45 -0300386 }
387
Hans Verkuil5490a7c2010-12-19 20:21:36 -0300388 if (!err_code) {
Thierry MERLE483dfdb2006-12-04 08:31:45 -0300389 usbvision_begin_streaming(usbvision);
Hans Verkuil5490a7c2010-12-19 20:21:36 -0300390 err_code = usbvision_init_isoc(usbvision);
Thierry MERLEc5f48362007-05-08 17:22:29 -0300391 /* device must be initialized before isoc transfer */
Hans Verkuil6d6a48e2010-12-29 13:53:21 -0300392 usbvision_muxsel(usbvision, 0);
Thierry MERLE483dfdb2006-12-04 08:31:45 -0300393 usbvision->user++;
Thierry MERLEc5f48362007-05-08 17:22:29 -0300394 } else {
Hans Verkuil5490a7c2010-12-19 20:21:36 -0300395 if (power_on_at_open) {
Thierry MERLE1ff16c22007-04-14 16:23:49 -0300396 usbvision_i2c_unregister(usbvision);
Thierry MERLE483dfdb2006-12-04 08:31:45 -0300397 usbvision_power_off(usbvision);
398 usbvision->initialized = 0;
399 }
400 }
Thierry MERLE483dfdb2006-12-04 08:31:45 -0300401 }
402
Thierry MERLE483dfdb2006-12-04 08:31:45 -0300403 /* prepare queues */
404 usbvision_empty_framequeues(usbvision);
405
406 PDEBUG(DBG_IO, "success");
Hans Verkuil5490a7c2010-12-19 20:21:36 -0300407 return err_code;
Thierry MERLE483dfdb2006-12-04 08:31:45 -0300408}
409
410/*
411 * usbvision_v4l2_close()
412 *
413 * This is part of Video 4 Linux API. The procedure
414 * stops streaming and deallocates all buffers that were earlier
415 * allocated in usbvision_v4l2_open().
416 *
417 */
Hans Verkuilbec43662008-12-30 06:58:20 -0300418static int usbvision_v4l2_close(struct file *file)
Thierry MERLE483dfdb2006-12-04 08:31:45 -0300419{
Hans Verkuilc170ecf2008-08-23 08:32:09 -0300420 struct usb_usbvision *usbvision = video_drvdata(file);
Thierry MERLE483dfdb2006-12-04 08:31:45 -0300421
422 PDEBUG(DBG_IO, "close");
Thierry MERLE483dfdb2006-12-04 08:31:45 -0300423
424 usbvision_audio_off(usbvision);
425 usbvision_restart_isoc(usbvision);
426 usbvision_stop_isoc(usbvision);
427
428 usbvision_decompress_free(usbvision);
Thierry MERLE38284ba2006-12-15 16:46:53 -0300429 usbvision_frames_free(usbvision);
Thierry MERLE6f78e182007-02-07 10:13:11 -0300430 usbvision_empty_framequeues(usbvision);
Thierry MERLE483dfdb2006-12-04 08:31:45 -0300431 usbvision_scratch_free(usbvision);
Thierry MERLE483dfdb2006-12-04 08:31:45 -0300432
433 usbvision->user--;
434
Hans Verkuil5490a7c2010-12-19 20:21:36 -0300435 if (power_on_at_open) {
Thierry MERLEc5f48362007-05-08 17:22:29 -0300436 /* power off in a little while
437 to avoid off/on every close/open short sequences */
Hans Verkuil5490a7c2010-12-19 20:21:36 -0300438 usbvision_set_power_off_timer(usbvision);
Thierry MERLE483dfdb2006-12-04 08:31:45 -0300439 usbvision->initialized = 0;
440 }
441
Thierry MERLE483dfdb2006-12-04 08:31:45 -0300442 if (usbvision->remove_pending) {
Harvey Harrisond2db42d2008-04-04 20:50:07 -0300443 printk(KERN_INFO "%s: Final disconnect\n", __func__);
Thierry MERLE483dfdb2006-12-04 08:31:45 -0300444 usbvision_release(usbvision);
445 }
446
447 PDEBUG(DBG_IO, "success");
Thierry MERLE483dfdb2006-12-04 08:31:45 -0300448 return 0;
449}
450
451
452/*
453 * usbvision_ioctl()
454 *
455 * This is part of Video 4 Linux API. The procedure handles ioctl() calls.
456 *
457 */
Thierry MERLEc5f48362007-05-08 17:22:29 -0300458#ifdef CONFIG_VIDEO_ADV_DEBUG
Hans Verkuil6d6a48e2010-12-29 13:53:21 -0300459static int vidioc_g_register(struct file *file, void *priv,
Hans Verkuilaecde8b2008-12-30 07:14:19 -0300460 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 MERLE483dfdb2006-12-04 08:31:45 -0300464
Hans Verkuilaecde8b2008-12-30 07:14:19 -0300465 if (!v4l2_chip_match_host(&reg->match))
Thierry MERLEc5f48362007-05-08 17:22:29 -0300466 return -EINVAL;
467 /* NT100x has a 8-bit register space */
Hans Verkuil5490a7c2010-12-19 20:21:36 -0300468 err_code = usbvision_read_reg(usbvision, reg->reg&0xff);
469 if (err_code < 0) {
Mauro Carvalho Chehabbe9ed512009-01-08 09:13:42 -0300470 dev_err(&usbvision->vdev->dev,
471 "%s: VIDIOC_DBG_G_REGISTER failed: error %d\n",
Hans Verkuil5490a7c2010-12-19 20:21:36 -0300472 __func__, err_code);
473 return err_code;
Thierry MERLE483dfdb2006-12-04 08:31:45 -0300474 }
Hans Verkuil5490a7c2010-12-19 20:21:36 -0300475 reg->val = err_code;
Hans Verkuilaecde8b2008-12-30 07:14:19 -0300476 reg->size = 1;
Thierry MERLE483dfdb2006-12-04 08:31:45 -0300477 return 0;
478}
479
Hans Verkuil6d6a48e2010-12-29 13:53:21 -0300480static int vidioc_s_register(struct file *file, void *priv,
Hans Verkuilaecde8b2008-12-30 07:14:19 -0300481 struct v4l2_dbg_register *reg)
Thierry MERLE483dfdb2006-12-04 08:31:45 -0300482{
Hans Verkuilc170ecf2008-08-23 08:32:09 -0300483 struct usb_usbvision *usbvision = video_drvdata(file);
Hans Verkuil5490a7c2010-12-19 20:21:36 -0300484 int err_code;
Thierry MERLEc5f48362007-05-08 17:22:29 -0300485
Hans Verkuilaecde8b2008-12-30 07:14:19 -0300486 if (!v4l2_chip_match_host(&reg->match))
Thierry MERLEc5f48362007-05-08 17:22:29 -0300487 return -EINVAL;
488 /* NT100x has a 8-bit register space */
Hans Verkuil6d6a48e2010-12-29 13:53:21 -0300489 err_code = usbvision_write_reg(usbvision, reg->reg & 0xff, reg->val);
Hans Verkuil5490a7c2010-12-19 20:21:36 -0300490 if (err_code < 0) {
Mauro Carvalho Chehabbe9ed512009-01-08 09:13:42 -0300491 dev_err(&usbvision->vdev->dev,
492 "%s: VIDIOC_DBG_S_REGISTER failed: error %d\n",
Hans Verkuil5490a7c2010-12-19 20:21:36 -0300493 __func__, err_code);
494 return err_code;
Thierry MERLEc5f48362007-05-08 17:22:29 -0300495 }
496 return 0;
497}
498#endif
499
Hans Verkuil6d6a48e2010-12-29 13:53:21 -0300500static int vidioc_querycap(struct file *file, void *priv,
Thierry MERLEc5f48362007-05-08 17:22:29 -0300501 struct v4l2_capability *vc)
502{
Hans Verkuilc170ecf2008-08-23 08:32:09 -0300503 struct usb_usbvision *usbvision = video_drvdata(file);
Thierry MERLEc5f48362007-05-08 17:22:29 -0300504
505 strlcpy(vc->driver, "USBVision", sizeof(vc->driver));
506 strlcpy(vc->card,
Hans Verkuil5490a7c2010-12-19 20:21:36 -0300507 usbvision_device_data[usbvision->dev_model].model_string,
Thierry MERLEc5f48362007-05-08 17:22:29 -0300508 sizeof(vc->card));
Thierry MERLE6f2a2782009-01-20 17:40:44 -0300509 usb_make_path(usbvision->dev, vc->bus_info, sizeof(vc->bus_info));
Thierry MERLEc5f48362007-05-08 17:22:29 -0300510 vc->capabilities = V4L2_CAP_VIDEO_CAPTURE |
511 V4L2_CAP_AUDIO |
512 V4L2_CAP_READWRITE |
513 V4L2_CAP_STREAMING |
514 (usbvision->have_tuner ? V4L2_CAP_TUNER : 0);
515 return 0;
Thierry MERLE483dfdb2006-12-04 08:31:45 -0300516}
517
Hans Verkuil6d6a48e2010-12-29 13:53:21 -0300518static int vidioc_enum_input(struct file *file, void *priv,
Thierry MERLEc5f48362007-05-08 17:22:29 -0300519 struct v4l2_input *vi)
520{
Hans Verkuilc170ecf2008-08-23 08:32:09 -0300521 struct usb_usbvision *usbvision = video_drvdata(file);
Thierry MERLEc5f48362007-05-08 17:22:29 -0300522 int chan;
523
Roel Kluin223ffe52009-05-02 16:38:47 -0300524 if (vi->index >= usbvision->video_inputs)
Thierry MERLEc5f48362007-05-08 17:22:29 -0300525 return -EINVAL;
Hans Verkuil6d6a48e2010-12-29 13:53:21 -0300526 if (usbvision->have_tuner)
Thierry MERLEc5f48362007-05-08 17:22:29 -0300527 chan = vi->index;
Hans Verkuil6d6a48e2010-12-29 13:53:21 -0300528 else
Hans Verkuil52cb0bf2010-12-19 20:33:51 -0300529 chan = vi->index + 1; /* skip Television string*/
Hans Verkuil6d6a48e2010-12-29 13:53:21 -0300530
Thierry MERLEc5f48362007-05-08 17:22:29 -0300531 /* Determine the requested input characteristics
532 specific for each usbvision card model */
Hans Verkuil6d6a48e2010-12-29 13:53:21 -0300533 switch (chan) {
Thierry MERLEc5f48362007-05-08 17:22:29 -0300534 case 0:
Hans Verkuil5490a7c2010-12-19 20:21:36 -0300535 if (usbvision_device_data[usbvision->dev_model].video_channels == 4) {
Thierry MERLEc5f48362007-05-08 17:22:29 -0300536 strcpy(vi->name, "White Video Input");
537 } else {
538 strcpy(vi->name, "Television");
539 vi->type = V4L2_INPUT_TYPE_TUNER;
540 vi->audioset = 1;
541 vi->tuner = chan;
542 vi->std = USBVISION_NORMS;
543 }
544 break;
545 case 1:
546 vi->type = V4L2_INPUT_TYPE_CAMERA;
Hans Verkuil6d6a48e2010-12-29 13:53:21 -0300547 if (usbvision_device_data[usbvision->dev_model].video_channels == 4)
Thierry MERLEc5f48362007-05-08 17:22:29 -0300548 strcpy(vi->name, "Green Video Input");
Hans Verkuil6d6a48e2010-12-29 13:53:21 -0300549 else
Thierry MERLEc5f48362007-05-08 17:22:29 -0300550 strcpy(vi->name, "Composite Video Input");
Thierry MERLEc5f48362007-05-08 17:22:29 -0300551 vi->std = V4L2_STD_PAL;
552 break;
553 case 2:
554 vi->type = V4L2_INPUT_TYPE_CAMERA;
Hans Verkuil6d6a48e2010-12-29 13:53:21 -0300555 if (usbvision_device_data[usbvision->dev_model].video_channels == 4)
Thierry MERLEc5f48362007-05-08 17:22:29 -0300556 strcpy(vi->name, "Yellow Video Input");
Hans Verkuil6d6a48e2010-12-29 13:53:21 -0300557 else
Thierry MERLEc5f48362007-05-08 17:22:29 -0300558 strcpy(vi->name, "S-Video Input");
Thierry MERLEc5f48362007-05-08 17:22:29 -0300559 vi->std = V4L2_STD_PAL;
560 break;
561 case 3:
562 vi->type = V4L2_INPUT_TYPE_CAMERA;
563 strcpy(vi->name, "Red Video Input");
564 vi->std = V4L2_STD_PAL;
565 break;
566 }
567 return 0;
568}
569
Hans Verkuil6d6a48e2010-12-29 13:53:21 -0300570static int vidioc_g_input(struct file *file, void *priv, unsigned int *input)
Thierry MERLEc5f48362007-05-08 17:22:29 -0300571{
Hans Verkuilc170ecf2008-08-23 08:32:09 -0300572 struct usb_usbvision *usbvision = video_drvdata(file);
Thierry MERLEc5f48362007-05-08 17:22:29 -0300573
574 *input = usbvision->ctl_input;
575 return 0;
576}
577
Hans Verkuil6d6a48e2010-12-29 13:53:21 -0300578static int vidioc_s_input(struct file *file, void *priv, unsigned int input)
Thierry MERLEc5f48362007-05-08 17:22:29 -0300579{
Hans Verkuilc170ecf2008-08-23 08:32:09 -0300580 struct usb_usbvision *usbvision = video_drvdata(file);
Thierry MERLEc5f48362007-05-08 17:22:29 -0300581
Roel Kluinf14a2972009-10-23 07:59:42 -0300582 if (input >= usbvision->video_inputs)
Thierry MERLEc5f48362007-05-08 17:22:29 -0300583 return -EINVAL;
Thierry MERLEc5f48362007-05-08 17:22:29 -0300584
Thierry MERLE66a17872007-06-26 16:35:30 -0300585 usbvision_muxsel(usbvision, input);
Thierry MERLEc5f48362007-05-08 17:22:29 -0300586 usbvision_set_input(usbvision);
587 usbvision_set_output(usbvision,
588 usbvision->curwidth,
589 usbvision->curheight);
Thierry MERLEc5f48362007-05-08 17:22:29 -0300590 return 0;
591}
592
Hans Verkuil6d6a48e2010-12-29 13:53:21 -0300593static int vidioc_s_std(struct file *file, void *priv, v4l2_std_id *id)
Thierry MERLEc5f48362007-05-08 17:22:29 -0300594{
Hans Verkuilc170ecf2008-08-23 08:32:09 -0300595 struct usb_usbvision *usbvision = video_drvdata(file);
596
Hans Verkuil6d6a48e2010-12-29 13:53:21 -0300597 usbvision->tvnorm_id = *id;
Thierry MERLEc5f48362007-05-08 17:22:29 -0300598
Hans Verkuil5490a7c2010-12-19 20:21:36 -0300599 call_all(usbvision, core, s_std, usbvision->tvnorm_id);
Thierry MERLE66a17872007-06-26 16:35:30 -0300600 /* propagate the change to the decoder */
601 usbvision_muxsel(usbvision, usbvision->ctl_input);
Thierry MERLEc5f48362007-05-08 17:22:29 -0300602
603 return 0;
604}
605
Hans Verkuil6d6a48e2010-12-29 13:53:21 -0300606static int vidioc_g_tuner(struct file *file, void *priv,
Thierry MERLEc5f48362007-05-08 17:22:29 -0300607 struct v4l2_tuner *vt)
608{
Hans Verkuilc170ecf2008-08-23 08:32:09 -0300609 struct usb_usbvision *usbvision = video_drvdata(file);
Thierry MERLEc5f48362007-05-08 17:22:29 -0300610
Hans Verkuil52cb0bf2010-12-19 20:33:51 -0300611 if (!usbvision->have_tuner || vt->index) /* Only tuner 0 */
Thierry MERLEc5f48362007-05-08 17:22:29 -0300612 return -EINVAL;
Hans Verkuil6d6a48e2010-12-29 13:53:21 -0300613 if (usbvision->radio) {
Thierry MERLEc5f48362007-05-08 17:22:29 -0300614 strcpy(vt->name, "Radio");
615 vt->type = V4L2_TUNER_RADIO;
616 } else {
617 strcpy(vt->name, "Television");
618 }
619 /* Let clients fill in the remainder of this struct */
Hans Verkuil1df79532009-02-21 18:11:31 -0300620 call_all(usbvision, tuner, g_tuner, vt);
Thierry MERLEc5f48362007-05-08 17:22:29 -0300621
622 return 0;
623}
624
Hans Verkuil6d6a48e2010-12-29 13:53:21 -0300625static int vidioc_s_tuner(struct file *file, void *priv,
Thierry MERLEc5f48362007-05-08 17:22:29 -0300626 struct v4l2_tuner *vt)
627{
Hans Verkuilc170ecf2008-08-23 08:32:09 -0300628 struct usb_usbvision *usbvision = video_drvdata(file);
Thierry MERLEc5f48362007-05-08 17:22:29 -0300629
Hans Verkuil52cb0bf2010-12-19 20:33:51 -0300630 /* Only no or one tuner for now */
Thierry MERLEc5f48362007-05-08 17:22:29 -0300631 if (!usbvision->have_tuner || vt->index)
632 return -EINVAL;
633 /* let clients handle this */
Hans Verkuil1df79532009-02-21 18:11:31 -0300634 call_all(usbvision, tuner, s_tuner, vt);
Thierry MERLEc5f48362007-05-08 17:22:29 -0300635
636 return 0;
637}
638
Hans Verkuil6d6a48e2010-12-29 13:53:21 -0300639static int vidioc_g_frequency(struct file *file, void *priv,
Thierry MERLEc5f48362007-05-08 17:22:29 -0300640 struct v4l2_frequency *freq)
641{
Hans Verkuilc170ecf2008-08-23 08:32:09 -0300642 struct usb_usbvision *usbvision = video_drvdata(file);
Thierry MERLEc5f48362007-05-08 17:22:29 -0300643
Hans Verkuil52cb0bf2010-12-19 20:33:51 -0300644 freq->tuner = 0; /* Only one tuner */
Hans Verkuil6d6a48e2010-12-29 13:53:21 -0300645 if (usbvision->radio)
Thierry MERLEc5f48362007-05-08 17:22:29 -0300646 freq->type = V4L2_TUNER_RADIO;
Hans Verkuil6d6a48e2010-12-29 13:53:21 -0300647 else
Thierry MERLEc5f48362007-05-08 17:22:29 -0300648 freq->type = V4L2_TUNER_ANALOG_TV;
Thierry MERLEc5f48362007-05-08 17:22:29 -0300649 freq->frequency = usbvision->freq;
650
651 return 0;
652}
653
Hans Verkuil6d6a48e2010-12-29 13:53:21 -0300654static int vidioc_s_frequency(struct file *file, void *priv,
Thierry MERLEc5f48362007-05-08 17:22:29 -0300655 struct v4l2_frequency *freq)
656{
Hans Verkuilc170ecf2008-08-23 08:32:09 -0300657 struct usb_usbvision *usbvision = video_drvdata(file);
Thierry MERLEc5f48362007-05-08 17:22:29 -0300658
Hans Verkuil52cb0bf2010-12-19 20:33:51 -0300659 /* Only no or one tuner for now */
Thierry MERLEc5f48362007-05-08 17:22:29 -0300660 if (!usbvision->have_tuner || freq->tuner)
661 return -EINVAL;
662
663 usbvision->freq = freq->frequency;
Hans Verkuil1df79532009-02-21 18:11:31 -0300664 call_all(usbvision, tuner, s_frequency, freq);
Thierry MERLEc5f48362007-05-08 17:22:29 -0300665
666 return 0;
667}
668
Hans Verkuil6d6a48e2010-12-29 13:53:21 -0300669static int vidioc_g_audio(struct file *file, void *priv, struct v4l2_audio *a)
Thierry MERLEc5f48362007-05-08 17:22:29 -0300670{
Hans Verkuilc170ecf2008-08-23 08:32:09 -0300671 struct usb_usbvision *usbvision = video_drvdata(file);
Thierry MERLEc5f48362007-05-08 17:22:29 -0300672
Hans Verkuil6d6a48e2010-12-29 13:53:21 -0300673 if (usbvision->radio)
674 strcpy(a->name, "Radio");
675 else
Thierry MERLEc5f48362007-05-08 17:22:29 -0300676 strcpy(a->name, "TV");
Thierry MERLEc5f48362007-05-08 17:22:29 -0300677
678 return 0;
679}
680
Hans Verkuil6d6a48e2010-12-29 13:53:21 -0300681static int vidioc_s_audio(struct file *file, void *fh,
Thierry MERLEc5f48362007-05-08 17:22:29 -0300682 struct v4l2_audio *a)
683{
Hans Verkuil6d6a48e2010-12-29 13:53:21 -0300684 if (a->index)
Thierry MERLEc5f48362007-05-08 17:22:29 -0300685 return -EINVAL;
Thierry MERLEc5f48362007-05-08 17:22:29 -0300686 return 0;
687}
688
Hans Verkuil6d6a48e2010-12-29 13:53:21 -0300689static int vidioc_queryctrl(struct file *file, void *priv,
Thierry MERLEc5f48362007-05-08 17:22:29 -0300690 struct v4l2_queryctrl *ctrl)
691{
Hans Verkuilc170ecf2008-08-23 08:32:09 -0300692 struct usb_usbvision *usbvision = video_drvdata(file);
Thierry MERLEc5f48362007-05-08 17:22:29 -0300693
Hans Verkuil1df79532009-02-21 18:11:31 -0300694 call_all(usbvision, core, queryctrl, ctrl);
Thierry MERLEc5f48362007-05-08 17:22:29 -0300695
696 if (!ctrl->type)
697 return -EINVAL;
698
699 return 0;
700}
701
Hans Verkuil6d6a48e2010-12-29 13:53:21 -0300702static int vidioc_g_ctrl(struct file *file, void *priv,
Thierry MERLEc5f48362007-05-08 17:22:29 -0300703 struct v4l2_control *ctrl)
704{
Hans Verkuilc170ecf2008-08-23 08:32:09 -0300705 struct usb_usbvision *usbvision = video_drvdata(file);
Hans Verkuil6d6a48e2010-12-29 13:53:21 -0300706
Hans Verkuil1df79532009-02-21 18:11:31 -0300707 call_all(usbvision, core, g_ctrl, ctrl);
Thierry MERLEc5f48362007-05-08 17:22:29 -0300708 return 0;
709}
710
Hans Verkuil6d6a48e2010-12-29 13:53:21 -0300711static int vidioc_s_ctrl(struct file *file, void *priv,
Thierry MERLEc5f48362007-05-08 17:22:29 -0300712 struct v4l2_control *ctrl)
713{
Hans Verkuilc170ecf2008-08-23 08:32:09 -0300714 struct usb_usbvision *usbvision = video_drvdata(file);
Thierry MERLEc5f48362007-05-08 17:22:29 -0300715
Hans Verkuil6d6a48e2010-12-29 13:53:21 -0300716 call_all(usbvision, core, s_ctrl, ctrl);
Thierry MERLEc5f48362007-05-08 17:22:29 -0300717 return 0;
718}
719
Hans Verkuil6d6a48e2010-12-29 13:53:21 -0300720static int vidioc_reqbufs(struct file *file,
Thierry MERLEc5f48362007-05-08 17:22:29 -0300721 void *priv, struct v4l2_requestbuffers *vr)
722{
Hans Verkuilc170ecf2008-08-23 08:32:09 -0300723 struct usb_usbvision *usbvision = video_drvdata(file);
Thierry MERLEc5f48362007-05-08 17:22:29 -0300724 int ret;
725
Hans Verkuil6d6a48e2010-12-29 13:53:21 -0300726 RESTRICT_TO_RANGE(vr->count, 1, USBVISION_NUMFRAMES);
Thierry MERLEc5f48362007-05-08 17:22:29 -0300727
728 /* Check input validity:
729 the user must do a VIDEO CAPTURE and MMAP method. */
Trent Piepho975f5762009-03-28 22:25:36 -0300730 if (vr->memory != V4L2_MEMORY_MMAP)
Thierry MERLEc5f48362007-05-08 17:22:29 -0300731 return -EINVAL;
732
Hans Verkuil6d6a48e2010-12-29 13:53:21 -0300733 if (usbvision->streaming == stream_on) {
734 ret = usbvision_stream_interrupt(usbvision);
735 if (ret)
Thierry MERLEc5f48362007-05-08 17:22:29 -0300736 return ret;
737 }
738
739 usbvision_frames_free(usbvision);
740 usbvision_empty_framequeues(usbvision);
Hans Verkuil6d6a48e2010-12-29 13:53:21 -0300741 vr->count = usbvision_frames_alloc(usbvision, vr->count);
Thierry MERLEc5f48362007-05-08 17:22:29 -0300742
Hans Verkuil5490a7c2010-12-19 20:21:36 -0300743 usbvision->cur_frame = NULL;
Thierry MERLEc5f48362007-05-08 17:22:29 -0300744
745 return 0;
746}
747
Hans Verkuil6d6a48e2010-12-29 13:53:21 -0300748static int vidioc_querybuf(struct file *file,
Thierry MERLEc5f48362007-05-08 17:22:29 -0300749 void *priv, struct v4l2_buffer *vb)
750{
Hans Verkuilc170ecf2008-08-23 08:32:09 -0300751 struct usb_usbvision *usbvision = video_drvdata(file);
Thierry MERLEc5f48362007-05-08 17:22:29 -0300752 struct usbvision_frame *frame;
753
754 /* FIXME : must control
755 that buffers are mapped (VIDIOC_REQBUFS has been called) */
Hans Verkuil6d6a48e2010-12-29 13:53:21 -0300756 if (vb->index >= usbvision->num_frames)
Thierry MERLEc5f48362007-05-08 17:22:29 -0300757 return -EINVAL;
Thierry MERLEc5f48362007-05-08 17:22:29 -0300758 /* Updating the corresponding frame state */
759 vb->flags = 0;
760 frame = &usbvision->frame[vb->index];
Hans Verkuil6d6a48e2010-12-29 13:53:21 -0300761 if (frame->grabstate >= frame_state_ready)
Thierry MERLEc5f48362007-05-08 17:22:29 -0300762 vb->flags |= V4L2_BUF_FLAG_QUEUED;
Hans Verkuil6d6a48e2010-12-29 13:53:21 -0300763 if (frame->grabstate >= frame_state_done)
Thierry MERLEc5f48362007-05-08 17:22:29 -0300764 vb->flags |= V4L2_BUF_FLAG_DONE;
Hans Verkuil6d6a48e2010-12-29 13:53:21 -0300765 if (frame->grabstate == frame_state_unused)
Thierry MERLEc5f48362007-05-08 17:22:29 -0300766 vb->flags |= V4L2_BUF_FLAG_MAPPED;
767 vb->memory = V4L2_MEMORY_MMAP;
768
Hans Verkuil6d6a48e2010-12-29 13:53:21 -0300769 vb->m.offset = vb->index * PAGE_ALIGN(usbvision->max_frame_size);
Thierry MERLEc5f48362007-05-08 17:22:29 -0300770
771 vb->memory = V4L2_MEMORY_MMAP;
772 vb->field = V4L2_FIELD_NONE;
Hans Verkuil6d6a48e2010-12-29 13:53:21 -0300773 vb->length = usbvision->curwidth *
774 usbvision->curheight *
Thierry MERLEc5f48362007-05-08 17:22:29 -0300775 usbvision->palette.bytes_per_pixel;
776 vb->timestamp = usbvision->frame[vb->index].timestamp;
777 vb->sequence = usbvision->frame[vb->index].sequence;
778 return 0;
779}
780
Hans Verkuil6d6a48e2010-12-29 13:53:21 -0300781static int vidioc_qbuf(struct file *file, void *priv, struct v4l2_buffer *vb)
Thierry MERLEc5f48362007-05-08 17:22:29 -0300782{
Hans Verkuilc170ecf2008-08-23 08:32:09 -0300783 struct usb_usbvision *usbvision = video_drvdata(file);
Thierry MERLEc5f48362007-05-08 17:22:29 -0300784 struct usbvision_frame *frame;
785 unsigned long lock_flags;
786
787 /* FIXME : works only on VIDEO_CAPTURE MODE, MMAP. */
Hans Verkuil6d6a48e2010-12-29 13:53:21 -0300788 if (vb->index >= usbvision->num_frames)
Thierry MERLEc5f48362007-05-08 17:22:29 -0300789 return -EINVAL;
Thierry MERLEc5f48362007-05-08 17:22:29 -0300790
791 frame = &usbvision->frame[vb->index];
792
Hans Verkuil6d6a48e2010-12-29 13:53:21 -0300793 if (frame->grabstate != frame_state_unused)
Thierry MERLEc5f48362007-05-08 17:22:29 -0300794 return -EAGAIN;
Thierry MERLEc5f48362007-05-08 17:22:29 -0300795
796 /* Mark it as ready and enqueue frame */
Hans Verkuil5490a7c2010-12-19 20:21:36 -0300797 frame->grabstate = frame_state_ready;
798 frame->scanstate = scan_state_scanning;
Thierry MERLEc5f48362007-05-08 17:22:29 -0300799 frame->scanlength = 0; /* Accumulated in usbvision_parse_data() */
800
801 vb->flags &= ~V4L2_BUF_FLAG_DONE;
802
803 /* set v4l2_format index */
804 frame->v4l2_format = usbvision->palette;
805
806 spin_lock_irqsave(&usbvision->queue_lock, lock_flags);
807 list_add_tail(&usbvision->frame[vb->index].frame, &usbvision->inqueue);
808 spin_unlock_irqrestore(&usbvision->queue_lock, lock_flags);
809
810 return 0;
811}
812
Hans Verkuil6d6a48e2010-12-29 13:53:21 -0300813static int vidioc_dqbuf(struct file *file, void *priv, struct v4l2_buffer *vb)
Thierry MERLEc5f48362007-05-08 17:22:29 -0300814{
Hans Verkuilc170ecf2008-08-23 08:32:09 -0300815 struct usb_usbvision *usbvision = video_drvdata(file);
Thierry MERLEc5f48362007-05-08 17:22:29 -0300816 int ret;
817 struct usbvision_frame *f;
818 unsigned long lock_flags;
819
Thierry MERLEc5f48362007-05-08 17:22:29 -0300820 if (list_empty(&(usbvision->outqueue))) {
Hans Verkuil5490a7c2010-12-19 20:21:36 -0300821 if (usbvision->streaming == stream_idle)
Thierry MERLEc5f48362007-05-08 17:22:29 -0300822 return -EINVAL;
823 ret = wait_event_interruptible
824 (usbvision->wait_frame,
825 !list_empty(&(usbvision->outqueue)));
826 if (ret)
827 return ret;
828 }
829
830 spin_lock_irqsave(&usbvision->queue_lock, lock_flags);
831 f = list_entry(usbvision->outqueue.next,
832 struct usbvision_frame, frame);
833 list_del(usbvision->outqueue.next);
834 spin_unlock_irqrestore(&usbvision->queue_lock, lock_flags);
835
Hans Verkuil5490a7c2010-12-19 20:21:36 -0300836 f->grabstate = frame_state_unused;
Thierry MERLEc5f48362007-05-08 17:22:29 -0300837
838 vb->memory = V4L2_MEMORY_MMAP;
839 vb->flags = V4L2_BUF_FLAG_MAPPED |
840 V4L2_BUF_FLAG_QUEUED |
841 V4L2_BUF_FLAG_DONE;
842 vb->index = f->index;
843 vb->sequence = f->sequence;
844 vb->timestamp = f->timestamp;
845 vb->field = V4L2_FIELD_NONE;
846 vb->bytesused = f->scanlength;
847
848 return 0;
849}
850
851static int vidioc_streamon(struct file *file, void *priv, enum v4l2_buf_type i)
852{
Hans Verkuilc170ecf2008-08-23 08:32:09 -0300853 struct usb_usbvision *usbvision = video_drvdata(file);
Thierry MERLEc5f48362007-05-08 17:22:29 -0300854
Hans Verkuil5490a7c2010-12-19 20:21:36 -0300855 usbvision->streaming = stream_on;
Hans Verkuil1df79532009-02-21 18:11:31 -0300856 call_all(usbvision, video, s_stream, 1);
Thierry MERLEc5f48362007-05-08 17:22:29 -0300857
858 return 0;
859}
860
861static int vidioc_streamoff(struct file *file,
862 void *priv, enum v4l2_buf_type type)
863{
Hans Verkuilc170ecf2008-08-23 08:32:09 -0300864 struct usb_usbvision *usbvision = video_drvdata(file);
Thierry MERLEc5f48362007-05-08 17:22:29 -0300865
866 if (type != V4L2_BUF_TYPE_VIDEO_CAPTURE)
867 return -EINVAL;
868
Hans Verkuil6d6a48e2010-12-29 13:53:21 -0300869 if (usbvision->streaming == stream_on) {
Thierry MERLEc5f48362007-05-08 17:22:29 -0300870 usbvision_stream_interrupt(usbvision);
871 /* Stop all video streamings */
Hans Verkuil1df79532009-02-21 18:11:31 -0300872 call_all(usbvision, video, s_stream, 0);
Thierry MERLEc5f48362007-05-08 17:22:29 -0300873 }
874 usbvision_empty_framequeues(usbvision);
875
876 return 0;
877}
878
Hans Verkuil6d6a48e2010-12-29 13:53:21 -0300879static int vidioc_enum_fmt_vid_cap(struct file *file, void *priv,
Thierry MERLEc5f48362007-05-08 17:22:29 -0300880 struct v4l2_fmtdesc *vfd)
881{
Hans Verkuil6d6a48e2010-12-29 13:53:21 -0300882 if (vfd->index >= USBVISION_SUPPORTED_PALETTES - 1)
Thierry MERLEc5f48362007-05-08 17:22:29 -0300883 return -EINVAL;
Hans Verkuil6d6a48e2010-12-29 13:53:21 -0300884 strcpy(vfd->description, usbvision_v4l2_format[vfd->index].desc);
Thierry MERLEc5f48362007-05-08 17:22:29 -0300885 vfd->pixelformat = usbvision_v4l2_format[vfd->index].format;
Thierry MERLEc5f48362007-05-08 17:22:29 -0300886 return 0;
887}
888
Hans Verkuil6d6a48e2010-12-29 13:53:21 -0300889static int vidioc_g_fmt_vid_cap(struct file *file, void *priv,
Thierry MERLEc5f48362007-05-08 17:22:29 -0300890 struct v4l2_format *vf)
891{
Hans Verkuilc170ecf2008-08-23 08:32:09 -0300892 struct usb_usbvision *usbvision = video_drvdata(file);
Thierry MERLEc5f48362007-05-08 17:22:29 -0300893 vf->fmt.pix.width = usbvision->curwidth;
894 vf->fmt.pix.height = usbvision->curheight;
895 vf->fmt.pix.pixelformat = usbvision->palette.format;
896 vf->fmt.pix.bytesperline =
Hans Verkuil6d6a48e2010-12-29 13:53:21 -0300897 usbvision->curwidth * usbvision->palette.bytes_per_pixel;
898 vf->fmt.pix.sizeimage = vf->fmt.pix.bytesperline * usbvision->curheight;
Thierry MERLEc5f48362007-05-08 17:22:29 -0300899 vf->fmt.pix.colorspace = V4L2_COLORSPACE_SMPTE170M;
900 vf->fmt.pix.field = V4L2_FIELD_NONE; /* Always progressive image */
901
902 return 0;
903}
904
Hans Verkuil6d6a48e2010-12-29 13:53:21 -0300905static int vidioc_try_fmt_vid_cap(struct file *file, void *priv,
Thierry MERLEc5f48362007-05-08 17:22:29 -0300906 struct v4l2_format *vf)
907{
Hans Verkuilc170ecf2008-08-23 08:32:09 -0300908 struct usb_usbvision *usbvision = video_drvdata(file);
Hans Verkuil5490a7c2010-12-19 20:21:36 -0300909 int format_idx;
Thierry MERLEc5f48362007-05-08 17:22:29 -0300910
911 /* Find requested format in available ones */
Hans Verkuil6d6a48e2010-12-29 13:53:21 -0300912 for (format_idx = 0; format_idx < USBVISION_SUPPORTED_PALETTES; format_idx++) {
913 if (vf->fmt.pix.pixelformat ==
Hans Verkuil5490a7c2010-12-19 20:21:36 -0300914 usbvision_v4l2_format[format_idx].format) {
915 usbvision->palette = usbvision_v4l2_format[format_idx];
Thierry MERLEc5f48362007-05-08 17:22:29 -0300916 break;
917 }
918 }
919 /* robustness */
Hans Verkuil6d6a48e2010-12-29 13:53:21 -0300920 if (format_idx == USBVISION_SUPPORTED_PALETTES)
Thierry MERLEc5f48362007-05-08 17:22:29 -0300921 return -EINVAL;
Thierry MERLEc5f48362007-05-08 17:22:29 -0300922 RESTRICT_TO_RANGE(vf->fmt.pix.width, MIN_FRAME_WIDTH, MAX_FRAME_WIDTH);
923 RESTRICT_TO_RANGE(vf->fmt.pix.height, MIN_FRAME_HEIGHT, MAX_FRAME_HEIGHT);
924
925 vf->fmt.pix.bytesperline = vf->fmt.pix.width*
926 usbvision->palette.bytes_per_pixel;
927 vf->fmt.pix.sizeimage = vf->fmt.pix.bytesperline*vf->fmt.pix.height;
928
929 return 0;
930}
931
Hans Verkuil78b526a2008-05-28 12:16:41 -0300932static int vidioc_s_fmt_vid_cap(struct file *file, void *priv,
Thierry MERLEc5f48362007-05-08 17:22:29 -0300933 struct v4l2_format *vf)
934{
Hans Verkuilc170ecf2008-08-23 08:32:09 -0300935 struct usb_usbvision *usbvision = video_drvdata(file);
Thierry MERLEc5f48362007-05-08 17:22:29 -0300936 int ret;
937
Hans Verkuil6d6a48e2010-12-29 13:53:21 -0300938 ret = vidioc_try_fmt_vid_cap(file, priv, vf);
939 if (ret)
Thierry MERLEc5f48362007-05-08 17:22:29 -0300940 return ret;
Thierry MERLEc5f48362007-05-08 17:22:29 -0300941
942 /* stop io in case it is already in progress */
Hans Verkuil6d6a48e2010-12-29 13:53:21 -0300943 if (usbvision->streaming == stream_on) {
944 ret = usbvision_stream_interrupt(usbvision);
945 if (ret)
Thierry MERLEc5f48362007-05-08 17:22:29 -0300946 return ret;
947 }
948 usbvision_frames_free(usbvision);
949 usbvision_empty_framequeues(usbvision);
950
Hans Verkuil5490a7c2010-12-19 20:21:36 -0300951 usbvision->cur_frame = NULL;
Thierry MERLEc5f48362007-05-08 17:22:29 -0300952
953 /* by now we are committed to the new data... */
Thierry MERLEc5f48362007-05-08 17:22:29 -0300954 usbvision_set_output(usbvision, vf->fmt.pix.width, vf->fmt.pix.height);
Thierry MERLEc5f48362007-05-08 17:22:29 -0300955
956 return 0;
957}
Thierry MERLE483dfdb2006-12-04 08:31:45 -0300958
Al Viro8a5ab412007-02-09 16:38:20 +0000959static ssize_t usbvision_v4l2_read(struct file *file, char __user *buf,
Thierry MERLE483dfdb2006-12-04 08:31:45 -0300960 size_t count, loff_t *ppos)
961{
Hans Verkuilc170ecf2008-08-23 08:32:09 -0300962 struct usb_usbvision *usbvision = video_drvdata(file);
Thierry MERLE483dfdb2006-12-04 08:31:45 -0300963 int noblock = file->f_flags & O_NONBLOCK;
964 unsigned long lock_flags;
Hans Verkuil6d6a48e2010-12-29 13:53:21 -0300965 int ret, i;
Thierry MERLE483dfdb2006-12-04 08:31:45 -0300966 struct usbvision_frame *frame;
967
Harvey Harrisond2db42d2008-04-04 20:50:07 -0300968 PDEBUG(DBG_IO, "%s: %ld bytes, noblock=%d", __func__,
Thierry MERLEc5f48362007-05-08 17:22:29 -0300969 (unsigned long)count, noblock);
Thierry MERLE483dfdb2006-12-04 08:31:45 -0300970
971 if (!USBVISION_IS_OPERATIONAL(usbvision) || (buf == NULL))
972 return -EFAULT;
973
Thierry MERLEc5f48362007-05-08 17:22:29 -0300974 /* This entry point is compatible with the mmap routines
975 so that a user can do either VIDIOC_QBUF/VIDIOC_DQBUF
976 to get frames or call read on the device. */
Hans Verkuil6d6a48e2010-12-29 13:53:21 -0300977 if (!usbvision->num_frames) {
Thierry MERLEc5f48362007-05-08 17:22:29 -0300978 /* First, allocate some frames to work with
979 if this has not been done with VIDIOC_REQBUF */
Thierry MERLE6f78e182007-02-07 10:13:11 -0300980 usbvision_frames_free(usbvision);
981 usbvision_empty_framequeues(usbvision);
Hans Verkuil6d6a48e2010-12-29 13:53:21 -0300982 usbvision_frames_alloc(usbvision, USBVISION_NUMFRAMES);
Thierry MERLE6f78e182007-02-07 10:13:11 -0300983 }
Thierry MERLE483dfdb2006-12-04 08:31:45 -0300984
Hans Verkuil6d6a48e2010-12-29 13:53:21 -0300985 if (usbvision->streaming != stream_on) {
Thierry MERLE6f78e182007-02-07 10:13:11 -0300986 /* no stream is running, make it running ! */
Hans Verkuil5490a7c2010-12-19 20:21:36 -0300987 usbvision->streaming = stream_on;
Hans Verkuil1df79532009-02-21 18:11:31 -0300988 call_all(usbvision, video, s_stream, 1);
Thierry MERLE6f78e182007-02-07 10:13:11 -0300989 }
990
Thierry MERLEc5f48362007-05-08 17:22:29 -0300991 /* Then, enqueue as many frames as possible
992 (like a user of VIDIOC_QBUF would do) */
Hans Verkuil6d6a48e2010-12-29 13:53:21 -0300993 for (i = 0; i < usbvision->num_frames; i++) {
Thierry MERLE483dfdb2006-12-04 08:31:45 -0300994 frame = &usbvision->frame[i];
Hans Verkuil6d6a48e2010-12-29 13:53:21 -0300995 if (frame->grabstate == frame_state_unused) {
Thierry MERLE483dfdb2006-12-04 08:31:45 -0300996 /* Mark it as ready and enqueue frame */
Hans Verkuil5490a7c2010-12-19 20:21:36 -0300997 frame->grabstate = frame_state_ready;
998 frame->scanstate = scan_state_scanning;
Thierry MERLEc5f48362007-05-08 17:22:29 -0300999 /* Accumulated in usbvision_parse_data() */
1000 frame->scanlength = 0;
Thierry MERLE483dfdb2006-12-04 08:31:45 -03001001
1002 /* set v4l2_format index */
1003 frame->v4l2_format = usbvision->palette;
1004
1005 spin_lock_irqsave(&usbvision->queue_lock, lock_flags);
1006 list_add_tail(&frame->frame, &usbvision->inqueue);
Thierry MERLEc5f48362007-05-08 17:22:29 -03001007 spin_unlock_irqrestore(&usbvision->queue_lock,
1008 lock_flags);
Thierry MERLE483dfdb2006-12-04 08:31:45 -03001009 }
1010 }
1011
1012 /* Then try to steal a frame (like a VIDIOC_DQBUF would do) */
1013 if (list_empty(&(usbvision->outqueue))) {
Hans Verkuil6d6a48e2010-12-29 13:53:21 -03001014 if (noblock)
Thierry MERLE483dfdb2006-12-04 08:31:45 -03001015 return -EAGAIN;
1016
1017 ret = wait_event_interruptible
1018 (usbvision->wait_frame,
1019 !list_empty(&(usbvision->outqueue)));
1020 if (ret)
1021 return ret;
1022 }
1023
1024 spin_lock_irqsave(&usbvision->queue_lock, lock_flags);
1025 frame = list_entry(usbvision->outqueue.next,
1026 struct usbvision_frame, frame);
1027 list_del(usbvision->outqueue.next);
1028 spin_unlock_irqrestore(&usbvision->queue_lock, lock_flags);
1029
1030 /* An error returns an empty frame */
Hans Verkuil5490a7c2010-12-19 20:21:36 -03001031 if (frame->grabstate == frame_state_error) {
Thierry MERLE483dfdb2006-12-04 08:31:45 -03001032 frame->bytes_read = 0;
1033 return 0;
1034 }
1035
Thierry MERLEc5f48362007-05-08 17:22:29 -03001036 PDEBUG(DBG_IO, "%s: frmx=%d, bytes_read=%ld, scanlength=%ld",
Harvey Harrisond2db42d2008-04-04 20:50:07 -03001037 __func__,
Thierry MERLEc5f48362007-05-08 17:22:29 -03001038 frame->index, frame->bytes_read, frame->scanlength);
Thierry MERLE483dfdb2006-12-04 08:31:45 -03001039
1040 /* copy bytes to user space; we allow for partials reads */
1041 if ((count + frame->bytes_read) > (unsigned long)frame->scanlength)
1042 count = frame->scanlength - frame->bytes_read;
1043
Hans Verkuil6d6a48e2010-12-29 13:53:21 -03001044 if (copy_to_user(buf, frame->data + frame->bytes_read, count))
Thierry MERLE483dfdb2006-12-04 08:31:45 -03001045 return -EFAULT;
Thierry MERLE483dfdb2006-12-04 08:31:45 -03001046
1047 frame->bytes_read += count;
Thierry MERLEc5f48362007-05-08 17:22:29 -03001048 PDEBUG(DBG_IO, "%s: {copy} count used=%ld, new bytes_read=%ld",
Harvey Harrisond2db42d2008-04-04 20:50:07 -03001049 __func__,
Thierry MERLEc5f48362007-05-08 17:22:29 -03001050 (unsigned long)count, frame->bytes_read);
Thierry MERLE483dfdb2006-12-04 08:31:45 -03001051
Thierry MERLEc5f48362007-05-08 17:22:29 -03001052 /* For now, forget the frame if it has not been read in one shot. */
Hans Verkuil6d6a48e2010-12-29 13:53:21 -03001053/* if (frame->bytes_read >= frame->scanlength) {*/ /* All data has been read */
Thierry MERLE483dfdb2006-12-04 08:31:45 -03001054 frame->bytes_read = 0;
1055
1056 /* Mark it as available to be used again. */
Hans Verkuil5490a7c2010-12-19 20:21:36 -03001057 frame->grabstate = frame_state_unused;
Hans Verkuil6d6a48e2010-12-29 13:53:21 -03001058/* } */
Thierry MERLE483dfdb2006-12-04 08:31:45 -03001059
1060 return count;
1061}
1062
1063static int usbvision_v4l2_mmap(struct file *file, struct vm_area_struct *vma)
1064{
1065 unsigned long size = vma->vm_end - vma->vm_start,
1066 start = vma->vm_start;
1067 void *pos;
1068 u32 i;
Hans Verkuilc170ecf2008-08-23 08:32:09 -03001069 struct usb_usbvision *usbvision = video_drvdata(file);
Thierry MERLE483dfdb2006-12-04 08:31:45 -03001070
Thierry MERLE6f78e182007-02-07 10:13:11 -03001071 PDEBUG(DBG_MMAP, "mmap");
1072
Hans Verkuil6d6a48e2010-12-29 13:53:21 -03001073 if (!USBVISION_IS_OPERATIONAL(usbvision))
Thierry MERLE483dfdb2006-12-04 08:31:45 -03001074 return -EFAULT;
Thierry MERLE483dfdb2006-12-04 08:31:45 -03001075
1076 if (!(vma->vm_flags & VM_WRITE) ||
Thierry MERLE6f78e182007-02-07 10:13:11 -03001077 size != PAGE_ALIGN(usbvision->max_frame_size)) {
Thierry MERLE483dfdb2006-12-04 08:31:45 -03001078 return -EINVAL;
1079 }
1080
Thierry MERLE6f78e182007-02-07 10:13:11 -03001081 for (i = 0; i < usbvision->num_frames; i++) {
Thierry MERLEc5f48362007-05-08 17:22:29 -03001082 if (((PAGE_ALIGN(usbvision->max_frame_size)*i) >> PAGE_SHIFT) ==
1083 vma->vm_pgoff)
Thierry MERLE483dfdb2006-12-04 08:31:45 -03001084 break;
1085 }
Thierry MERLE6f78e182007-02-07 10:13:11 -03001086 if (i == usbvision->num_frames) {
Thierry MERLEc5f48362007-05-08 17:22:29 -03001087 PDEBUG(DBG_MMAP,
1088 "mmap: user supplied mapping address is out of range");
Thierry MERLE483dfdb2006-12-04 08:31:45 -03001089 return -EINVAL;
1090 }
1091
1092 /* VM_IO is eventually going to replace PageReserved altogether */
1093 vma->vm_flags |= VM_IO;
1094 vma->vm_flags |= VM_RESERVED; /* avoid to swap out this VMA */
1095
1096 pos = usbvision->frame[i].data;
1097 while (size > 0) {
Thierry MERLE483dfdb2006-12-04 08:31:45 -03001098 if (vm_insert_page(vma, start, vmalloc_to_page(pos))) {
Thierry MERLEc876a342006-12-09 16:42:54 -03001099 PDEBUG(DBG_MMAP, "mmap: vm_insert_page failed");
Thierry MERLE483dfdb2006-12-04 08:31:45 -03001100 return -EAGAIN;
1101 }
1102 start += PAGE_SIZE;
1103 pos += PAGE_SIZE;
1104 size -= PAGE_SIZE;
1105 }
1106
Thierry MERLE483dfdb2006-12-04 08:31:45 -03001107 return 0;
1108}
1109
1110
1111/*
1112 * Here comes the stuff for radio on usbvision based devices
1113 *
1114 */
Hans Verkuilbec43662008-12-30 06:58:20 -03001115static int usbvision_radio_open(struct file *file)
Thierry MERLE483dfdb2006-12-04 08:31:45 -03001116{
Hans Verkuilc170ecf2008-08-23 08:32:09 -03001117 struct usb_usbvision *usbvision = video_drvdata(file);
Hans Verkuil5490a7c2010-12-19 20:21:36 -03001118 int err_code = 0;
Thierry MERLE483dfdb2006-12-04 08:31:45 -03001119
Harvey Harrisond2db42d2008-04-04 20:50:07 -03001120 PDEBUG(DBG_IO, "%s:", __func__);
Thierry MERLE483dfdb2006-12-04 08:31:45 -03001121
Thierry MERLE483dfdb2006-12-04 08:31:45 -03001122 if (usbvision->user) {
Mauro Carvalho Chehabbe9ed512009-01-08 09:13:42 -03001123 dev_err(&usbvision->rdev->dev,
1124 "%s: Someone tried to open an already opened USBVision Radio!\n",
1125 __func__);
Hans Verkuil5490a7c2010-12-19 20:21:36 -03001126 err_code = -EBUSY;
Hans Verkuil6d6a48e2010-12-29 13:53:21 -03001127 } else {
1128 if (power_on_at_open) {
Hans Verkuil5490a7c2010-12-19 20:21:36 -03001129 usbvision_reset_power_off_timer(usbvision);
Thierry MERLE483dfdb2006-12-04 08:31:45 -03001130 if (usbvision->power == 0) {
1131 usbvision_power_on(usbvision);
Thierry MERLE1ff16c22007-04-14 16:23:49 -03001132 usbvision_i2c_register(usbvision);
Thierry MERLE483dfdb2006-12-04 08:31:45 -03001133 }
1134 }
1135
Thierry MERLE2a9f8b52007-02-07 10:14:38 -03001136 /* Alternate interface 1 is is the biggest frame size */
Hans Verkuil5490a7c2010-12-19 20:21:36 -03001137 err_code = usbvision_set_alternate(usbvision);
1138 if (err_code < 0) {
1139 usbvision->last_error = err_code;
1140 err_code = -EBUSY;
Andrew Morton544e6172007-12-12 18:25:23 -03001141 goto out;
Thierry MERLE2a9f8b52007-02-07 10:14:38 -03001142 }
1143
Hans Verkuil52cb0bf2010-12-19 20:33:51 -03001144 /* If so far no errors then we shall start the radio */
Thierry MERLE483dfdb2006-12-04 08:31:45 -03001145 usbvision->radio = 1;
Hans Verkuil1df79532009-02-21 18:11:31 -03001146 call_all(usbvision, tuner, s_radio);
Thierry MERLE483dfdb2006-12-04 08:31:45 -03001147 usbvision_set_audio(usbvision, USBVISION_AUDIO_RADIO);
1148 usbvision->user++;
1149 }
1150
Hans Verkuil5490a7c2010-12-19 20:21:36 -03001151 if (err_code) {
1152 if (power_on_at_open) {
Thierry MERLE1ff16c22007-04-14 16:23:49 -03001153 usbvision_i2c_unregister(usbvision);
Thierry MERLE483dfdb2006-12-04 08:31:45 -03001154 usbvision_power_off(usbvision);
1155 usbvision->initialized = 0;
1156 }
1157 }
Andrew Morton544e6172007-12-12 18:25:23 -03001158out:
Hans Verkuil5490a7c2010-12-19 20:21:36 -03001159 return err_code;
Thierry MERLE483dfdb2006-12-04 08:31:45 -03001160}
1161
1162
Hans Verkuilbec43662008-12-30 06:58:20 -03001163static int usbvision_radio_close(struct file *file)
Thierry MERLE483dfdb2006-12-04 08:31:45 -03001164{
Hans Verkuilc170ecf2008-08-23 08:32:09 -03001165 struct usb_usbvision *usbvision = video_drvdata(file);
Hans Verkuil5490a7c2010-12-19 20:21:36 -03001166 int err_code = 0;
Thierry MERLE483dfdb2006-12-04 08:31:45 -03001167
1168 PDEBUG(DBG_IO, "");
1169
Thierry MERLE2a9f8b52007-02-07 10:14:38 -03001170 /* Set packet size to 0 */
Hans Verkuil6d6a48e2010-12-29 13:53:21 -03001171 usbvision->iface_alt = 0;
Hans Verkuil5490a7c2010-12-19 20:21:36 -03001172 err_code = usb_set_interface(usbvision->dev, usbvision->iface,
1173 usbvision->iface_alt);
Thierry MERLE2a9f8b52007-02-07 10:14:38 -03001174
Thierry MERLE483dfdb2006-12-04 08:31:45 -03001175 usbvision_audio_off(usbvision);
Hans Verkuil6d6a48e2010-12-29 13:53:21 -03001176 usbvision->radio = 0;
Thierry MERLE483dfdb2006-12-04 08:31:45 -03001177 usbvision->user--;
1178
Hans Verkuil5490a7c2010-12-19 20:21:36 -03001179 if (power_on_at_open) {
1180 usbvision_set_power_off_timer(usbvision);
Thierry MERLE483dfdb2006-12-04 08:31:45 -03001181 usbvision->initialized = 0;
1182 }
1183
Thierry MERLE483dfdb2006-12-04 08:31:45 -03001184 if (usbvision->remove_pending) {
Harvey Harrisond2db42d2008-04-04 20:50:07 -03001185 printk(KERN_INFO "%s: Final disconnect\n", __func__);
Thierry MERLE483dfdb2006-12-04 08:31:45 -03001186 usbvision_release(usbvision);
1187 }
1188
Thierry MERLE483dfdb2006-12-04 08:31:45 -03001189 PDEBUG(DBG_IO, "success");
Hans Verkuil5490a7c2010-12-19 20:21:36 -03001190 return err_code;
Thierry MERLE483dfdb2006-12-04 08:31:45 -03001191}
1192
Hans Verkuil52cb0bf2010-12-19 20:33:51 -03001193/* Video registration stuff */
Thierry MERLE483dfdb2006-12-04 08:31:45 -03001194
Hans Verkuil52cb0bf2010-12-19 20:33:51 -03001195/* Video template */
Hans Verkuilbec43662008-12-30 06:58:20 -03001196static const struct v4l2_file_operations usbvision_fops = {
Thierry MERLE483dfdb2006-12-04 08:31:45 -03001197 .owner = THIS_MODULE,
Thierry MERLE483dfdb2006-12-04 08:31:45 -03001198 .open = usbvision_v4l2_open,
1199 .release = usbvision_v4l2_close,
1200 .read = usbvision_v4l2_read,
1201 .mmap = usbvision_v4l2_mmap,
Hans Verkuilc627b9d2010-12-18 11:06:09 -03001202 .unlocked_ioctl = video_ioctl2,
Hans Verkuil6d6a48e2010-12-29 13:53:21 -03001203/* .poll = video_poll, */
Thierry MERLE483dfdb2006-12-04 08:31:45 -03001204};
Hans Verkuila3998102008-07-21 02:57:38 -03001205
1206static const struct v4l2_ioctl_ops usbvision_ioctl_ops = {
Thierry MERLEc5f48362007-05-08 17:22:29 -03001207 .vidioc_querycap = vidioc_querycap,
Hans Verkuil78b526a2008-05-28 12:16:41 -03001208 .vidioc_enum_fmt_vid_cap = vidioc_enum_fmt_vid_cap,
1209 .vidioc_g_fmt_vid_cap = vidioc_g_fmt_vid_cap,
1210 .vidioc_try_fmt_vid_cap = vidioc_try_fmt_vid_cap,
1211 .vidioc_s_fmt_vid_cap = vidioc_s_fmt_vid_cap,
Thierry MERLEc5f48362007-05-08 17:22:29 -03001212 .vidioc_reqbufs = vidioc_reqbufs,
1213 .vidioc_querybuf = vidioc_querybuf,
1214 .vidioc_qbuf = vidioc_qbuf,
1215 .vidioc_dqbuf = vidioc_dqbuf,
1216 .vidioc_s_std = vidioc_s_std,
1217 .vidioc_enum_input = vidioc_enum_input,
1218 .vidioc_g_input = vidioc_g_input,
1219 .vidioc_s_input = vidioc_s_input,
1220 .vidioc_queryctrl = vidioc_queryctrl,
1221 .vidioc_g_audio = vidioc_g_audio,
Al Viroed4d6372007-09-26 01:53:42 +01001222 .vidioc_s_audio = vidioc_s_audio,
Thierry MERLEc5f48362007-05-08 17:22:29 -03001223 .vidioc_g_ctrl = vidioc_g_ctrl,
1224 .vidioc_s_ctrl = vidioc_s_ctrl,
1225 .vidioc_streamon = vidioc_streamon,
1226 .vidioc_streamoff = vidioc_streamoff,
Thierry MERLEc5f48362007-05-08 17:22:29 -03001227 .vidioc_g_tuner = vidioc_g_tuner,
1228 .vidioc_s_tuner = vidioc_s_tuner,
1229 .vidioc_g_frequency = vidioc_g_frequency,
1230 .vidioc_s_frequency = vidioc_s_frequency,
1231#ifdef CONFIG_VIDEO_ADV_DEBUG
1232 .vidioc_g_register = vidioc_g_register,
1233 .vidioc_s_register = vidioc_s_register,
1234#endif
Hans Verkuila3998102008-07-21 02:57:38 -03001235};
1236
1237static struct video_device usbvision_video_template = {
Hans Verkuila3998102008-07-21 02:57:38 -03001238 .fops = &usbvision_fops,
Hans Verkuil6d6a48e2010-12-29 13:53:21 -03001239 .ioctl_ops = &usbvision_ioctl_ops,
Hans Verkuila3998102008-07-21 02:57:38 -03001240 .name = "usbvision-video",
1241 .release = video_device_release,
Hans Verkuil6d6a48e2010-12-29 13:53:21 -03001242 .tvnorms = USBVISION_NORMS,
1243 .current_norm = V4L2_STD_PAL
Thierry MERLE483dfdb2006-12-04 08:31:45 -03001244};
1245
1246
Hans Verkuil52cb0bf2010-12-19 20:33:51 -03001247/* Radio template */
Hans Verkuilbec43662008-12-30 06:58:20 -03001248static const struct v4l2_file_operations usbvision_radio_fops = {
Thierry MERLE483dfdb2006-12-04 08:31:45 -03001249 .owner = THIS_MODULE,
Thierry MERLE483dfdb2006-12-04 08:31:45 -03001250 .open = usbvision_radio_open,
1251 .release = usbvision_radio_close,
Hans Verkuilc627b9d2010-12-18 11:06:09 -03001252 .unlocked_ioctl = video_ioctl2,
Thierry MERLE483dfdb2006-12-04 08:31:45 -03001253};
1254
Hans Verkuila3998102008-07-21 02:57:38 -03001255static const struct v4l2_ioctl_ops usbvision_radio_ioctl_ops = {
Thierry MERLEc5f48362007-05-08 17:22:29 -03001256 .vidioc_querycap = vidioc_querycap,
1257 .vidioc_enum_input = vidioc_enum_input,
1258 .vidioc_g_input = vidioc_g_input,
1259 .vidioc_s_input = vidioc_s_input,
1260 .vidioc_queryctrl = vidioc_queryctrl,
1261 .vidioc_g_audio = vidioc_g_audio,
Al Viroed4d6372007-09-26 01:53:42 +01001262 .vidioc_s_audio = vidioc_s_audio,
Thierry MERLEc5f48362007-05-08 17:22:29 -03001263 .vidioc_g_ctrl = vidioc_g_ctrl,
1264 .vidioc_s_ctrl = vidioc_s_ctrl,
1265 .vidioc_g_tuner = vidioc_g_tuner,
1266 .vidioc_s_tuner = vidioc_s_tuner,
1267 .vidioc_g_frequency = vidioc_g_frequency,
1268 .vidioc_s_frequency = vidioc_s_frequency,
Hans Verkuila3998102008-07-21 02:57:38 -03001269};
1270
1271static struct video_device usbvision_radio_template = {
Hans Verkuila3998102008-07-21 02:57:38 -03001272 .fops = &usbvision_radio_fops,
Hans Verkuil6d6a48e2010-12-29 13:53:21 -03001273 .name = "usbvision-radio",
Hans Verkuila3998102008-07-21 02:57:38 -03001274 .release = video_device_release,
Hans Verkuil6d6a48e2010-12-29 13:53:21 -03001275 .ioctl_ops = &usbvision_radio_ioctl_ops,
Thierry MERLE483dfdb2006-12-04 08:31:45 -03001276
Thierry MERLEc5f48362007-05-08 17:22:29 -03001277 .tvnorms = USBVISION_NORMS,
1278 .current_norm = V4L2_STD_PAL
1279};
Thierry MERLE483dfdb2006-12-04 08:31:45 -03001280
Thierry MERLE483dfdb2006-12-04 08:31:45 -03001281
1282static struct video_device *usbvision_vdev_init(struct usb_usbvision *usbvision,
1283 struct video_device *vdev_template,
1284 char *name)
1285{
1286 struct usb_device *usb_dev = usbvision->dev;
1287 struct video_device *vdev;
1288
1289 if (usb_dev == NULL) {
Mauro Carvalho Chehabbe9ed512009-01-08 09:13:42 -03001290 dev_err(&usbvision->dev->dev,
1291 "%s: usbvision->dev is not set\n", __func__);
Thierry MERLE483dfdb2006-12-04 08:31:45 -03001292 return NULL;
1293 }
1294
1295 vdev = video_device_alloc();
Hans Verkuil6d6a48e2010-12-29 13:53:21 -03001296 if (NULL == vdev)
Thierry MERLE483dfdb2006-12-04 08:31:45 -03001297 return NULL;
Thierry MERLE483dfdb2006-12-04 08:31:45 -03001298 *vdev = *vdev_template;
Hans Verkuilc627b9d2010-12-18 11:06:09 -03001299 vdev->lock = &usbvision->v4l2_lock;
Hans Verkuil1df79532009-02-21 18:11:31 -03001300 vdev->v4l2_dev = &usbvision->v4l2_dev;
Thierry MERLE483dfdb2006-12-04 08:31:45 -03001301 snprintf(vdev->name, sizeof(vdev->name), "%s", name);
1302 video_set_drvdata(vdev, usbvision);
1303 return vdev;
1304}
1305
Hans Verkuil52cb0bf2010-12-19 20:33:51 -03001306/* unregister video4linux devices */
Thierry MERLE483dfdb2006-12-04 08:31:45 -03001307static void usbvision_unregister_video(struct usb_usbvision *usbvision)
1308{
Hans Verkuil52cb0bf2010-12-19 20:33:51 -03001309 /* Radio Device: */
Thierry MERLE483dfdb2006-12-04 08:31:45 -03001310 if (usbvision->rdev) {
Laurent Pinchart38c7c032009-11-27 13:57:15 -03001311 PDEBUG(DBG_PROBE, "unregister %s [v4l2]",
1312 video_device_node_name(usbvision->rdev));
Hans Verkuil6d6a48e2010-12-29 13:53:21 -03001313 if (video_is_registered(usbvision->rdev))
Thierry MERLE483dfdb2006-12-04 08:31:45 -03001314 video_unregister_device(usbvision->rdev);
Hans Verkuil6d6a48e2010-12-29 13:53:21 -03001315 else
Thierry MERLE483dfdb2006-12-04 08:31:45 -03001316 video_device_release(usbvision->rdev);
Thierry MERLE483dfdb2006-12-04 08:31:45 -03001317 usbvision->rdev = NULL;
1318 }
1319
Hans Verkuil52cb0bf2010-12-19 20:33:51 -03001320 /* Video Device: */
Thierry MERLE483dfdb2006-12-04 08:31:45 -03001321 if (usbvision->vdev) {
Laurent Pinchart38c7c032009-11-27 13:57:15 -03001322 PDEBUG(DBG_PROBE, "unregister %s [v4l2]",
1323 video_device_node_name(usbvision->vdev));
Hans Verkuil6d6a48e2010-12-29 13:53:21 -03001324 if (video_is_registered(usbvision->vdev))
Thierry MERLE483dfdb2006-12-04 08:31:45 -03001325 video_unregister_device(usbvision->vdev);
Hans Verkuil6d6a48e2010-12-29 13:53:21 -03001326 else
Thierry MERLE483dfdb2006-12-04 08:31:45 -03001327 video_device_release(usbvision->vdev);
Thierry MERLE483dfdb2006-12-04 08:31:45 -03001328 usbvision->vdev = NULL;
1329 }
1330}
1331
Hans Verkuil52cb0bf2010-12-19 20:33:51 -03001332/* register video4linux devices */
Thierry MERLE483dfdb2006-12-04 08:31:45 -03001333static int __devinit usbvision_register_video(struct usb_usbvision *usbvision)
1334{
Hans Verkuil52cb0bf2010-12-19 20:33:51 -03001335 /* Video Device: */
Thierry MERLEc5f48362007-05-08 17:22:29 -03001336 usbvision->vdev = usbvision_vdev_init(usbvision,
1337 &usbvision_video_template,
1338 "USBVision Video");
Hans Verkuil6d6a48e2010-12-29 13:53:21 -03001339 if (usbvision->vdev == NULL)
Thierry MERLE483dfdb2006-12-04 08:31:45 -03001340 goto err_exit;
Hans Verkuil6d6a48e2010-12-29 13:53:21 -03001341 if (video_register_device(usbvision->vdev, VFL_TYPE_GRABBER, video_nr) < 0)
Thierry MERLE483dfdb2006-12-04 08:31:45 -03001342 goto err_exit;
Laurent Pinchart38c7c032009-11-27 13:57:15 -03001343 printk(KERN_INFO "USBVision[%d]: registered USBVision Video device %s [v4l2]\n",
1344 usbvision->nr, video_device_node_name(usbvision->vdev));
Thierry MERLE483dfdb2006-12-04 08:31:45 -03001345
Hans Verkuil52cb0bf2010-12-19 20:33:51 -03001346 /* Radio Device: */
Hans Verkuil5490a7c2010-12-19 20:21:36 -03001347 if (usbvision_device_data[usbvision->dev_model].radio) {
Hans Verkuil52cb0bf2010-12-19 20:33:51 -03001348 /* usbvision has radio */
Thierry MERLEc5f48362007-05-08 17:22:29 -03001349 usbvision->rdev = usbvision_vdev_init(usbvision,
1350 &usbvision_radio_template,
1351 "USBVision Radio");
Hans Verkuil6d6a48e2010-12-29 13:53:21 -03001352 if (usbvision->rdev == NULL)
Thierry MERLE483dfdb2006-12-04 08:31:45 -03001353 goto err_exit;
Hans Verkuil6d6a48e2010-12-29 13:53:21 -03001354 if (video_register_device(usbvision->rdev, VFL_TYPE_RADIO, radio_nr) < 0)
Thierry MERLE483dfdb2006-12-04 08:31:45 -03001355 goto err_exit;
Laurent Pinchart38c7c032009-11-27 13:57:15 -03001356 printk(KERN_INFO "USBVision[%d]: registered USBVision Radio device %s [v4l2]\n",
1357 usbvision->nr, video_device_node_name(usbvision->rdev));
Thierry MERLE483dfdb2006-12-04 08:31:45 -03001358 }
Hans Verkuil52cb0bf2010-12-19 20:33:51 -03001359 /* all done */
Thierry MERLE483dfdb2006-12-04 08:31:45 -03001360 return 0;
1361
1362 err_exit:
Mauro Carvalho Chehabbe9ed512009-01-08 09:13:42 -03001363 dev_err(&usbvision->dev->dev,
1364 "USBVision[%d]: video_register_device() failed\n",
1365 usbvision->nr);
Thierry MERLE483dfdb2006-12-04 08:31:45 -03001366 usbvision_unregister_video(usbvision);
1367 return -1;
1368}
1369
1370/*
1371 * usbvision_alloc()
1372 *
Thierry MERLEc5f48362007-05-08 17:22:29 -03001373 * This code allocates the struct usb_usbvision.
1374 * It is filled with default values.
Thierry MERLE483dfdb2006-12-04 08:31:45 -03001375 *
1376 * Returns NULL on error, a pointer to usb_usbvision else.
1377 *
1378 */
Janne Grunaua8784402009-04-01 08:46:00 -03001379static struct usb_usbvision *usbvision_alloc(struct usb_device *dev,
1380 struct usb_interface *intf)
Thierry MERLE483dfdb2006-12-04 08:31:45 -03001381{
1382 struct usb_usbvision *usbvision;
1383
Hans Verkuil1df79532009-02-21 18:11:31 -03001384 usbvision = kzalloc(sizeof(struct usb_usbvision), GFP_KERNEL);
1385 if (usbvision == NULL)
1386 return NULL;
Thierry MERLE483dfdb2006-12-04 08:31:45 -03001387
1388 usbvision->dev = dev;
Janne Grunaua8784402009-04-01 08:46:00 -03001389 if (v4l2_device_register(&intf->dev, &usbvision->v4l2_dev))
Hans Verkuil1df79532009-02-21 18:11:31 -03001390 goto err_free;
Thierry MERLE483dfdb2006-12-04 08:31:45 -03001391
Hans Verkuilc627b9d2010-12-18 11:06:09 -03001392 mutex_init(&usbvision->v4l2_lock);
Thierry MERLE483dfdb2006-12-04 08:31:45 -03001393
Hans Verkuil52cb0bf2010-12-19 20:33:51 -03001394 /* prepare control urb for control messages during interrupts */
Hans Verkuil5490a7c2010-12-19 20:21:36 -03001395 usbvision->ctrl_urb = usb_alloc_urb(USBVISION_URB_FRAMES, GFP_KERNEL);
1396 if (usbvision->ctrl_urb == NULL)
Hans Verkuil1df79532009-02-21 18:11:31 -03001397 goto err_unreg;
Hans Verkuil5490a7c2010-12-19 20:21:36 -03001398 init_waitqueue_head(&usbvision->ctrl_urb_wq);
Thierry MERLE483dfdb2006-12-04 08:31:45 -03001399
Hans Verkuil5490a7c2010-12-19 20:21:36 -03001400 usbvision_init_power_off_timer(usbvision);
Thierry MERLE483dfdb2006-12-04 08:31:45 -03001401
1402 return usbvision;
1403
Hans Verkuil1df79532009-02-21 18:11:31 -03001404err_unreg:
1405 v4l2_device_unregister(&usbvision->v4l2_dev);
1406err_free:
1407 kfree(usbvision);
Thierry MERLE483dfdb2006-12-04 08:31:45 -03001408 return NULL;
1409}
1410
1411/*
1412 * usbvision_release()
1413 *
1414 * This code does final release of struct usb_usbvision. This happens
1415 * after the device is disconnected -and- all clients closed their files.
1416 *
1417 */
1418static void usbvision_release(struct usb_usbvision *usbvision)
1419{
1420 PDEBUG(DBG_PROBE, "");
1421
Hans Verkuil5490a7c2010-12-19 20:21:36 -03001422 usbvision_reset_power_off_timer(usbvision);
Thierry MERLE483dfdb2006-12-04 08:31:45 -03001423
1424 usbvision->initialized = 0;
1425
Thierry MERLE483dfdb2006-12-04 08:31:45 -03001426 usbvision_remove_sysfs(usbvision->vdev);
1427 usbvision_unregister_video(usbvision);
1428
Hans Verkuil6d6a48e2010-12-29 13:53:21 -03001429 usb_free_urb(usbvision->ctrl_urb);
Thierry MERLE483dfdb2006-12-04 08:31:45 -03001430
Hans Verkuil1df79532009-02-21 18:11:31 -03001431 v4l2_device_unregister(&usbvision->v4l2_dev);
Thierry MERLE483dfdb2006-12-04 08:31:45 -03001432 kfree(usbvision);
1433
1434 PDEBUG(DBG_PROBE, "success");
1435}
1436
1437
Thierry MERLEc5f48362007-05-08 17:22:29 -03001438/*********************** usb interface **********************************/
Thierry MERLE483dfdb2006-12-04 08:31:45 -03001439
1440static void usbvision_configure_video(struct usb_usbvision *usbvision)
1441{
Thierry MERLEc5f48362007-05-08 17:22:29 -03001442 int model;
Thierry MERLE483dfdb2006-12-04 08:31:45 -03001443
1444 if (usbvision == NULL)
1445 return;
1446
Hans Verkuil5490a7c2010-12-19 20:21:36 -03001447 model = usbvision->dev_model;
Hans Verkuil52cb0bf2010-12-19 20:33:51 -03001448 usbvision->palette = usbvision_v4l2_format[2]; /* V4L2_PIX_FMT_RGB24; */
Thierry MERLE483dfdb2006-12-04 08:31:45 -03001449
Hans Verkuil5490a7c2010-12-19 20:21:36 -03001450 if (usbvision_device_data[usbvision->dev_model].vin_reg2_override) {
1451 usbvision->vin_reg2_preset =
1452 usbvision_device_data[usbvision->dev_model].vin_reg2;
Thierry MERLE483dfdb2006-12-04 08:31:45 -03001453 } else {
Hans Verkuil5490a7c2010-12-19 20:21:36 -03001454 usbvision->vin_reg2_preset = 0;
Thierry MERLE483dfdb2006-12-04 08:31:45 -03001455 }
1456
Hans Verkuil5490a7c2010-12-19 20:21:36 -03001457 usbvision->tvnorm_id = usbvision_device_data[model].video_norm;
Thierry MERLE483dfdb2006-12-04 08:31:45 -03001458
Hans Verkuil5490a7c2010-12-19 20:21:36 -03001459 usbvision->video_inputs = usbvision_device_data[model].video_channels;
Thierry MERLE483dfdb2006-12-04 08:31:45 -03001460 usbvision->ctl_input = 0;
1461
1462 /* This should be here to make i2c clients to be able to register */
Thierry MERLEc5f48362007-05-08 17:22:29 -03001463 /* first switch off audio */
Ondrej Zary240d57b2011-04-27 17:36:05 -03001464 if (usbvision_device_data[model].audio_channels > 0)
1465 usbvision_audio_off(usbvision);
Hans Verkuil5490a7c2010-12-19 20:21:36 -03001466 if (!power_on_at_open) {
Thierry MERLEc5f48362007-05-08 17:22:29 -03001467 /* and then power up the noisy tuner */
1468 usbvision_power_on(usbvision);
Thierry MERLE1ff16c22007-04-14 16:23:49 -03001469 usbvision_i2c_register(usbvision);
Thierry MERLE483dfdb2006-12-04 08:31:45 -03001470 }
1471}
1472
1473/*
1474 * usbvision_probe()
1475 *
1476 * This procedure queries device descriptor and accepts the interface
1477 * if it looks like USBVISION video device
1478 *
1479 */
Mauro Carvalho Chehab659ae562007-04-14 15:09:59 -03001480static int __devinit usbvision_probe(struct usb_interface *intf,
1481 const struct usb_device_id *devid)
Thierry MERLE483dfdb2006-12-04 08:31:45 -03001482{
Thierry MERLE2a9f8b52007-02-07 10:14:38 -03001483 struct usb_device *dev = usb_get_dev(interface_to_usbdev(intf));
1484 struct usb_interface *uif;
Thierry MERLE483dfdb2006-12-04 08:31:45 -03001485 __u8 ifnum = intf->altsetting->desc.bInterfaceNumber;
1486 const struct usb_host_interface *interface;
1487 struct usb_usbvision *usbvision = NULL;
1488 const struct usb_endpoint_descriptor *endpoint;
Hans Verkuil6d6a48e2010-12-29 13:53:21 -03001489 int model, i;
Thierry MERLE483dfdb2006-12-04 08:31:45 -03001490
1491 PDEBUG(DBG_PROBE, "VID=%#04x, PID=%#04x, ifnum=%u",
Mauro Carvalho Chehab659ae562007-04-14 15:09:59 -03001492 dev->descriptor.idVendor,
1493 dev->descriptor.idProduct, ifnum);
Thierry MERLE2a9f8b52007-02-07 10:14:38 -03001494
Mauro Carvalho Chehab659ae562007-04-14 15:09:59 -03001495 model = devid->driver_info;
Hans Verkuil6d6a48e2010-12-29 13:53:21 -03001496 if (model < 0 || model >= usbvision_device_data_size) {
1497 PDEBUG(DBG_PROBE, "model out of bounds %d", model);
Mauro Carvalho Chehabf8a389d2007-04-14 15:17:35 -03001498 return -ENODEV;
1499 }
Harvey Harrisond2db42d2008-04-04 20:50:07 -03001500 printk(KERN_INFO "%s: %s found\n", __func__,
Hans Verkuil5490a7c2010-12-19 20:21:36 -03001501 usbvision_device_data[model].model_string);
Thierry MERLE483dfdb2006-12-04 08:31:45 -03001502
Hans Verkuil6d6a48e2010-12-29 13:53:21 -03001503 if (usbvision_device_data[model].interface >= 0)
Hans Verkuil5490a7c2010-12-19 20:21:36 -03001504 interface = &dev->actconfig->interface[usbvision_device_data[model].interface]->altsetting[0];
Hans Verkuil6d6a48e2010-12-29 13:53:21 -03001505 else
Thierry MERLE483dfdb2006-12-04 08:31:45 -03001506 interface = &dev->actconfig->interface[ifnum]->altsetting[0];
Thierry MERLE483dfdb2006-12-04 08:31:45 -03001507 endpoint = &interface->endpoint[1].desc;
Julia Lawall2230c3c2009-01-03 16:53:10 -03001508 if (!usb_endpoint_xfer_isoc(endpoint)) {
Mauro Carvalho Chehabbe9ed512009-01-08 09:13:42 -03001509 dev_err(&intf->dev, "%s: interface %d. has non-ISO endpoint!\n",
Harvey Harrisond2db42d2008-04-04 20:50:07 -03001510 __func__, ifnum);
Mauro Carvalho Chehabbe9ed512009-01-08 09:13:42 -03001511 dev_err(&intf->dev, "%s: Endpoint attributes %d",
Harvey Harrisond2db42d2008-04-04 20:50:07 -03001512 __func__, endpoint->bmAttributes);
Thierry MERLE483dfdb2006-12-04 08:31:45 -03001513 return -ENODEV;
1514 }
Julia Lawall13417982008-12-29 21:49:22 -03001515 if (usb_endpoint_dir_out(endpoint)) {
Mauro Carvalho Chehabbe9ed512009-01-08 09:13:42 -03001516 dev_err(&intf->dev, "%s: interface %d. has ISO OUT endpoint!\n",
Harvey Harrisond2db42d2008-04-04 20:50:07 -03001517 __func__, ifnum);
Thierry MERLE483dfdb2006-12-04 08:31:45 -03001518 return -ENODEV;
1519 }
1520
Janne Grunaua8784402009-04-01 08:46:00 -03001521 usbvision = usbvision_alloc(dev, intf);
1522 if (usbvision == NULL) {
Mauro Carvalho Chehabbe9ed512009-01-08 09:13:42 -03001523 dev_err(&intf->dev, "%s: couldn't allocate USBVision struct\n", __func__);
Thierry MERLE483dfdb2006-12-04 08:31:45 -03001524 return -ENOMEM;
1525 }
Mauro Carvalho Chehab659ae562007-04-14 15:09:59 -03001526
Hans Verkuil6d6a48e2010-12-29 13:53:21 -03001527 if (dev->descriptor.bNumConfigurations > 1)
Hans Verkuil5490a7c2010-12-19 20:21:36 -03001528 usbvision->bridge_type = BRIDGE_NT1004;
Hans Verkuil6d6a48e2010-12-29 13:53:21 -03001529 else if (model == DAZZLE_DVC_90_REV_1_SECAM)
Hans Verkuil5490a7c2010-12-19 20:21:36 -03001530 usbvision->bridge_type = BRIDGE_NT1005;
Hans Verkuil6d6a48e2010-12-29 13:53:21 -03001531 else
Hans Verkuil5490a7c2010-12-19 20:21:36 -03001532 usbvision->bridge_type = BRIDGE_NT1003;
Hans Verkuil5490a7c2010-12-19 20:21:36 -03001533 PDEBUG(DBG_PROBE, "bridge_type %d", usbvision->bridge_type);
Thierry MERLE483dfdb2006-12-04 08:31:45 -03001534
Thierry MERLE2a9f8b52007-02-07 10:14:38 -03001535 /* compute alternate max packet sizes */
1536 uif = dev->actconfig->interface[0];
1537
Hans Verkuil6d6a48e2010-12-29 13:53:21 -03001538 usbvision->num_alt = uif->num_altsetting;
1539 PDEBUG(DBG_PROBE, "Alternate settings: %i", usbvision->num_alt);
1540 usbvision->alt_max_pkt_size = kmalloc(32 * usbvision->num_alt, GFP_KERNEL);
Thierry MERLE2a9f8b52007-02-07 10:14:38 -03001541 if (usbvision->alt_max_pkt_size == NULL) {
Mauro Carvalho Chehabbe9ed512009-01-08 09:13:42 -03001542 dev_err(&intf->dev, "usbvision: out of memory!\n");
Thierry MERLE2a9f8b52007-02-07 10:14:38 -03001543 return -ENOMEM;
1544 }
1545
Hans Verkuil6d6a48e2010-12-29 13:53:21 -03001546 for (i = 0; i < usbvision->num_alt; i++) {
Thierry MERLE2a9f8b52007-02-07 10:14:38 -03001547 u16 tmp = le16_to_cpu(uif->altsetting[i].endpoint[1].desc.
1548 wMaxPacketSize);
1549 usbvision->alt_max_pkt_size[i] =
1550 (tmp & 0x07ff) * (((tmp & 0x1800) >> 11) + 1);
Hans Verkuil6d6a48e2010-12-29 13:53:21 -03001551 PDEBUG(DBG_PROBE, "Alternate setting %i, max size= %i", i,
Thierry MERLE2a9f8b52007-02-07 10:14:38 -03001552 usbvision->alt_max_pkt_size[i]);
1553 }
1554
1555
Thierry MERLE483dfdb2006-12-04 08:31:45 -03001556 usbvision->nr = usbvision_nr++;
1557
Hans Verkuil5490a7c2010-12-19 20:21:36 -03001558 usbvision->have_tuner = usbvision_device_data[model].tuner;
Hans Verkuil6d6a48e2010-12-29 13:53:21 -03001559 if (usbvision->have_tuner)
Hans Verkuil5490a7c2010-12-19 20:21:36 -03001560 usbvision->tuner_type = usbvision_device_data[model].tuner_type;
Thierry MERLE483dfdb2006-12-04 08:31:45 -03001561
Hans Verkuil5490a7c2010-12-19 20:21:36 -03001562 usbvision->dev_model = model;
Thierry MERLE483dfdb2006-12-04 08:31:45 -03001563 usbvision->remove_pending = 0;
1564 usbvision->iface = ifnum;
Hans Verkuil5490a7c2010-12-19 20:21:36 -03001565 usbvision->iface_alt = 0;
Thierry MERLE483dfdb2006-12-04 08:31:45 -03001566 usbvision->video_endp = endpoint->bEndpointAddress;
Hans Verkuil5490a7c2010-12-19 20:21:36 -03001567 usbvision->isoc_packet_size = 0;
Thierry MERLE483dfdb2006-12-04 08:31:45 -03001568 usbvision->usb_bandwidth = 0;
1569 usbvision->user = 0;
Hans Verkuil5490a7c2010-12-19 20:21:36 -03001570 usbvision->streaming = stream_off;
Thierry MERLE483dfdb2006-12-04 08:31:45 -03001571 usbvision_configure_video(usbvision);
Hans Verkuil84034722010-09-17 15:07:28 -03001572 usbvision_register_video(usbvision);
Thierry MERLE483dfdb2006-12-04 08:31:45 -03001573
Thierry MERLE483dfdb2006-12-04 08:31:45 -03001574 usbvision_create_sysfs(usbvision->vdev);
1575
1576 PDEBUG(DBG_PROBE, "success");
1577 return 0;
1578}
1579
1580
1581/*
1582 * usbvision_disconnect()
1583 *
1584 * This procedure stops all driver activity, deallocates interface-private
1585 * structure (pointed by 'ptr') and after that driver should be removable
1586 * with no ill consequences.
1587 *
1588 */
1589static void __devexit usbvision_disconnect(struct usb_interface *intf)
1590{
Hans Verkuilaeb506a2010-05-02 09:00:13 -03001591 struct usb_usbvision *usbvision = to_usbvision(usb_get_intfdata(intf));
Thierry MERLE483dfdb2006-12-04 08:31:45 -03001592
1593 PDEBUG(DBG_PROBE, "");
1594
1595 if (usbvision == NULL) {
Julia Lawall42020662010-05-27 09:36:45 -03001596 pr_err("%s: usb_get_intfdata() failed\n", __func__);
Thierry MERLE483dfdb2006-12-04 08:31:45 -03001597 return;
1598 }
Thierry MERLE483dfdb2006-12-04 08:31:45 -03001599
Hans Verkuilc627b9d2010-12-18 11:06:09 -03001600 mutex_lock(&usbvision->v4l2_lock);
Thierry MERLE483dfdb2006-12-04 08:31:45 -03001601
Hans Verkuil52cb0bf2010-12-19 20:33:51 -03001602 /* At this time we ask to cancel outstanding URBs */
Thierry MERLE483dfdb2006-12-04 08:31:45 -03001603 usbvision_stop_isoc(usbvision);
1604
Hans Verkuilf1ba28c2009-03-14 12:27:01 -03001605 v4l2_device_disconnect(&usbvision->v4l2_dev);
1606
Thierry MERLE483dfdb2006-12-04 08:31:45 -03001607 if (usbvision->power) {
Thierry MERLE1ff16c22007-04-14 16:23:49 -03001608 usbvision_i2c_unregister(usbvision);
Thierry MERLE483dfdb2006-12-04 08:31:45 -03001609 usbvision_power_off(usbvision);
1610 }
Hans Verkuil52cb0bf2010-12-19 20:33:51 -03001611 usbvision->remove_pending = 1; /* Now all ISO data will be ignored */
Thierry MERLE483dfdb2006-12-04 08:31:45 -03001612
1613 usb_put_dev(usbvision->dev);
Hans Verkuil52cb0bf2010-12-19 20:33:51 -03001614 usbvision->dev = NULL; /* USB device is no more */
Thierry MERLE483dfdb2006-12-04 08:31:45 -03001615
Hans Verkuilc627b9d2010-12-18 11:06:09 -03001616 mutex_unlock(&usbvision->v4l2_lock);
Thierry MERLE483dfdb2006-12-04 08:31:45 -03001617
1618 if (usbvision->user) {
Thierry MERLEc5f48362007-05-08 17:22:29 -03001619 printk(KERN_INFO "%s: In use, disconnect pending\n",
Harvey Harrisond2db42d2008-04-04 20:50:07 -03001620 __func__);
Thierry MERLE483dfdb2006-12-04 08:31:45 -03001621 wake_up_interruptible(&usbvision->wait_frame);
1622 wake_up_interruptible(&usbvision->wait_stream);
Thierry MERLEc5f48362007-05-08 17:22:29 -03001623 } else {
Thierry MERLE483dfdb2006-12-04 08:31:45 -03001624 usbvision_release(usbvision);
1625 }
1626
1627 PDEBUG(DBG_PROBE, "success");
Thierry MERLE483dfdb2006-12-04 08:31:45 -03001628}
1629
1630static struct usb_driver usbvision_driver = {
1631 .name = "usbvision",
1632 .id_table = usbvision_table,
1633 .probe = usbvision_probe,
Jean Delvaree36bc312009-06-04 11:07:16 -03001634 .disconnect = __devexit_p(usbvision_disconnect),
Thierry MERLE483dfdb2006-12-04 08:31:45 -03001635};
1636
1637/*
Thierry MERLE483dfdb2006-12-04 08:31:45 -03001638 * usbvision_init()
1639 *
1640 * This code is run to initialize the driver.
1641 *
1642 */
1643static int __init usbvision_init(void)
1644{
Hans Verkuil5490a7c2010-12-19 20:21:36 -03001645 int err_code;
Thierry MERLE483dfdb2006-12-04 08:31:45 -03001646
1647 PDEBUG(DBG_PROBE, "");
1648
Thierry MERLE483dfdb2006-12-04 08:31:45 -03001649 PDEBUG(DBG_IO, "IO debugging is enabled [video]");
1650 PDEBUG(DBG_PROBE, "PROBE debugging is enabled [video]");
Thierry MERLEc876a342006-12-09 16:42:54 -03001651 PDEBUG(DBG_MMAP, "MMAP debugging is enabled [video]");
Thierry MERLE483dfdb2006-12-04 08:31:45 -03001652
1653 /* disable planar mode support unless compression enabled */
Hans Verkuil6d6a48e2010-12-29 13:53:21 -03001654 if (isoc_mode != ISOC_MODE_COMPRESS) {
Hans Verkuil52cb0bf2010-12-19 20:33:51 -03001655 /* FIXME : not the right way to set supported flag */
1656 usbvision_v4l2_format[6].supported = 0; /* V4L2_PIX_FMT_YVU420 */
1657 usbvision_v4l2_format[7].supported = 0; /* V4L2_PIX_FMT_YUV422P */
Thierry MERLE483dfdb2006-12-04 08:31:45 -03001658 }
1659
Hans Verkuil5490a7c2010-12-19 20:21:36 -03001660 err_code = usb_register(&usbvision_driver);
Thierry MERLE483dfdb2006-12-04 08:31:45 -03001661
Hans Verkuil5490a7c2010-12-19 20:21:36 -03001662 if (err_code == 0) {
Dwaine Gardende6a1b82007-01-07 21:13:55 -03001663 printk(KERN_INFO DRIVER_DESC " : " USBVISION_VERSION_STRING "\n");
Thierry MERLE483dfdb2006-12-04 08:31:45 -03001664 PDEBUG(DBG_PROBE, "success");
1665 }
Hans Verkuil5490a7c2010-12-19 20:21:36 -03001666 return err_code;
Thierry MERLE483dfdb2006-12-04 08:31:45 -03001667}
1668
1669static void __exit usbvision_exit(void)
1670{
Hans Verkuil6d6a48e2010-12-29 13:53:21 -03001671 PDEBUG(DBG_PROBE, "");
Thierry MERLE483dfdb2006-12-04 08:31:45 -03001672
Hans Verkuil6d6a48e2010-12-29 13:53:21 -03001673 usb_deregister(&usbvision_driver);
1674 PDEBUG(DBG_PROBE, "success");
Thierry MERLE483dfdb2006-12-04 08:31:45 -03001675}
1676
1677module_init(usbvision_init);
1678module_exit(usbvision_exit);
1679
1680/*
1681 * Overrides for Emacs so that we follow Linus's tabbing style.
1682 * ---------------------------------------------------------------------------
1683 * Local variables:
1684 * c-basic-offset: 8
1685 * End:
1686 */