blob: 6d42154e3d0a2d04a91db4bb2fa542acb552d83f [file] [log] [blame]
Thomas Gleixnerc942fdd2019-05-27 08:55:06 +02001// SPDX-License-Identifier: GPL-2.0-or-later
Thierry MERLE483dfdb2006-12-04 08:31:45 -03002/*
Hans Verkuil3ff4ad82009-04-01 03:15:52 -03003 * USB USBVISION Video device driver 0.9.10
Thierry MERLE483dfdb2006-12-04 08:31:45 -03004 *
Thierry MERLE483dfdb2006-12-04 08:31:45 -03005 * Copyright (c) 1999-2005 Joerg Heckenbach <joerg@heckenbach-aw.de>
6 *
7 * This module is part of usbvision driver project.
8 *
Thierry MERLE483dfdb2006-12-04 08:31:45 -03009 * Let's call the version 0.... until compression decoding is completely
10 * implemented.
11 *
12 * This driver is written by Jose Ignacio Gijon and Joerg Heckenbach.
13 * It was based on USB CPiA driver written by Peter Pregler,
14 * Scott J. Bertin and Johannes Erdfelt
15 * Ideas are taken from bttv driver by Ralph Metzler, Marcus Metzler &
16 * Gerd Knorr and zoran 36120/36125 driver by Pauline Middelink
17 * Updates to driver completed by Dwaine P. Garden
18 *
Thierry MERLE483dfdb2006-12-04 08:31:45 -030019 * TODO:
20 * - use submit_urb for all setup packets
21 * - Fix memory settings for nt1004. It is 4 times as big as the
22 * nt1003 memory.
Thierry MERLEc5f48362007-05-08 17:22:29 -030023 * - Add audio on endpoint 3 for nt1004 chip.
24 * Seems impossible, needs a codec interface. Which one?
Thierry MERLE483dfdb2006-12-04 08:31:45 -030025 * - Clean up the driver.
26 * - optimization for performance.
27 * - Add Videotext capability (VBI). Working on it.....
28 * - Check audio for other devices
Thierry MERLE483dfdb2006-12-04 08:31:45 -030029 */
30
31#include <linux/kernel.h>
Thierry MERLE483dfdb2006-12-04 08:31:45 -030032#include <linux/list.h>
33#include <linux/timer.h>
34#include <linux/slab.h>
35#include <linux/mm.h>
Thierry MERLE483dfdb2006-12-04 08:31:45 -030036#include <linux/highmem.h>
Thierry MERLE483dfdb2006-12-04 08:31:45 -030037#include <linux/vmalloc.h>
38#include <linux/module.h>
39#include <linux/init.h>
40#include <linux/spinlock.h>
Hans Verkuil6d6a48e2010-12-29 13:53:21 -030041#include <linux/io.h>
Thierry MERLE483dfdb2006-12-04 08:31:45 -030042#include <linux/videodev2.h>
Thierry MERLE483dfdb2006-12-04 08:31:45 -030043#include <linux/i2c.h>
44
Mauro Carvalho Chehabb5dcee22015-11-10 12:01:44 -020045#include <media/i2c/saa7115.h>
Thierry MERLE483dfdb2006-12-04 08:31:45 -030046#include <media/v4l2-common.h>
Hans Verkuil35ea11f2008-07-20 08:12:02 -030047#include <media/v4l2-ioctl.h>
Hans Verkuilfd958702015-07-20 09:59:29 -030048#include <media/v4l2-event.h>
Thierry MERLE483dfdb2006-12-04 08:31:45 -030049#include <media/tuner.h>
Thierry MERLE483dfdb2006-12-04 08:31:45 -030050
Mauro Carvalho Chehaba1ed5512006-12-09 11:41:59 -030051#include <linux/workqueue.h>
Thierry MERLE483dfdb2006-12-04 08:31:45 -030052
Thierry MERLE483dfdb2006-12-04 08:31:45 -030053#include "usbvision.h"
Mauro Carvalho Chehab659ae562007-04-14 15:09:59 -030054#include "usbvision-cards.h"
Thierry MERLE483dfdb2006-12-04 08:31:45 -030055
Joe Perches85ee7a12011-04-23 20:38:19 -070056#define DRIVER_AUTHOR \
57 "Joerg Heckenbach <joerg@heckenbach-aw.de>, " \
58 "Dwaine Garden <DwaineGarden@rogers.com>"
Thierry MERLE483dfdb2006-12-04 08:31:45 -030059#define DRIVER_NAME "usbvision"
60#define DRIVER_ALIAS "USBVision"
61#define DRIVER_DESC "USBVision USB Video Device Driver for Linux"
Mauro Carvalho Chehab1990d502011-06-24 14:45:49 -030062#define USBVISION_VERSION_STRING "0.9.11"
Thierry MERLE483dfdb2006-12-04 08:31:45 -030063
64#define ENABLE_HEXDUMP 0 /* Enable if you need it */
65
66
Thierry MERLE483dfdb2006-12-04 08:31:45 -030067#ifdef USBVISION_DEBUG
Thierry MERLEdf18c312008-04-04 21:00:57 -030068 #define PDEBUG(level, fmt, args...) { \
Thierry MERLEc5f48362007-05-08 17:22:29 -030069 if (video_debug & (level)) \
Greg Kroah-Hartmana482f322008-10-10 05:08:23 -030070 printk(KERN_INFO KBUILD_MODNAME ":[%s:%d] " fmt, \
71 __func__, __LINE__ , ## args); \
Thierry MERLEdf18c312008-04-04 21:00:57 -030072 }
Thierry MERLE483dfdb2006-12-04 08:31:45 -030073#else
Hans Verkuil6d6a48e2010-12-29 13:53:21 -030074 #define PDEBUG(level, fmt, args...) do {} while (0)
Thierry MERLE483dfdb2006-12-04 08:31:45 -030075#endif
76
Hans Verkuil6d6a48e2010-12-29 13:53:21 -030077#define DBG_IO (1 << 1)
78#define DBG_PROBE (1 << 2)
79#define DBG_MMAP (1 << 3)
Thierry MERLE483dfdb2006-12-04 08:31:45 -030080
Hans Verkuil52cb0bf22010-12-19 20:33:51 -030081/* String operations */
Hans Verkuil6d6a48e2010-12-29 13:53:21 -030082#define rmspace(str) while (*str == ' ') str++;
83#define goto2next(str) while (*str != ' ') str++; while (*str == ' ') str++;
Thierry MERLE483dfdb2006-12-04 08:31:45 -030084
85
Thierry MERLEc5f48362007-05-08 17:22:29 -030086/* sequential number of usbvision device */
Douglas Schilling Landgrafff699e62008-04-22 14:41:48 -030087static int usbvision_nr;
Thierry MERLE483dfdb2006-12-04 08:31:45 -030088
89static struct usbvision_v4l2_format_st usbvision_v4l2_format[] = {
90 { 1, 1, 8, V4L2_PIX_FMT_GREY , "GREY" },
91 { 1, 2, 16, V4L2_PIX_FMT_RGB565 , "RGB565" },
92 { 1, 3, 24, V4L2_PIX_FMT_RGB24 , "RGB24" },
93 { 1, 4, 32, V4L2_PIX_FMT_RGB32 , "RGB32" },
94 { 1, 2, 16, V4L2_PIX_FMT_RGB555 , "RGB555" },
95 { 1, 2, 16, V4L2_PIX_FMT_YUYV , "YUV422" },
Hans Verkuil52cb0bf22010-12-19 20:33:51 -030096 { 1, 2, 12, V4L2_PIX_FMT_YVU420 , "YUV420P" }, /* 1.5 ! */
Thierry MERLE483dfdb2006-12-04 08:31:45 -030097 { 1, 2, 16, V4L2_PIX_FMT_YUV422P , "YUV422P" }
98};
99
Thierry MERLEc5f48362007-05-08 17:22:29 -0300100/* Function prototypes */
Thierry MERLE483dfdb2006-12-04 08:31:45 -0300101static void usbvision_release(struct usb_usbvision *usbvision);
102
Joe Perchesc84e6032008-02-03 17:18:59 +0200103/* Default initialization of device driver parameters */
Thierry MERLEc5f48362007-05-08 17:22:29 -0300104/* Set the default format for ISOC endpoint */
Hans Verkuil5490a7c2010-12-19 20:21:36 -0300105static int isoc_mode = ISOC_MODE_COMPRESS;
Thierry MERLEc5f48362007-05-08 17:22:29 -0300106/* Set the default Debug Mode of the device driver */
Douglas Schilling Landgrafff699e62008-04-22 14:41:48 -0300107static int video_debug;
Thierry MERLEc5f48362007-05-08 17:22:29 -0300108/* Sequential Number of Video Device */
109static int video_nr = -1;
110/* Sequential Number of Radio Device */
111static int radio_nr = -1;
Thierry MERLE483dfdb2006-12-04 08:31:45 -0300112
Thierry MERLEc5f48362007-05-08 17:22:29 -0300113/* Grab parameters for the device driver */
Thierry MERLE483dfdb2006-12-04 08:31:45 -0300114
Thierry MERLEc5f48362007-05-08 17:22:29 -0300115/* Showing parameters under SYSFS */
Hans Verkuil5490a7c2010-12-19 20:21:36 -0300116module_param(isoc_mode, int, 0444);
Thierry MERLE483dfdb2006-12-04 08:31:45 -0300117module_param(video_debug, int, 0444);
Thierry MERLE483dfdb2006-12-04 08:31:45 -0300118module_param(video_nr, int, 0444);
119module_param(radio_nr, int, 0444);
Thierry MERLE483dfdb2006-12-04 08:31:45 -0300120
Hans Verkuil5490a7c2010-12-19 20:21:36 -0300121MODULE_PARM_DESC(isoc_mode, " Set the default format for ISOC endpoint. Default: 0x60 (Compression On)");
Thierry MERLE483dfdb2006-12-04 08:31:45 -0300122MODULE_PARM_DESC(video_debug, " Set the default Debug Mode of the device driver. Default: 0 (Off)");
Thierry MERLE483dfdb2006-12-04 08:31:45 -0300123MODULE_PARM_DESC(video_nr, "Set video device number (/dev/videoX). Default: -1 (autodetect)");
124MODULE_PARM_DESC(radio_nr, "Set radio device number (/dev/radioX). Default: -1 (autodetect)");
Thierry MERLE483dfdb2006-12-04 08:31:45 -0300125
126
Hans Verkuil52cb0bf22010-12-19 20:33:51 -0300127/* Misc stuff */
Thierry MERLE483dfdb2006-12-04 08:31:45 -0300128MODULE_AUTHOR(DRIVER_AUTHOR);
129MODULE_DESCRIPTION(DRIVER_DESC);
Greg Kroah-Hartmanb6277582017-11-17 09:18:26 -0500130MODULE_LICENSE("GPL");
Mauro Carvalho Chehaba1ed5512006-12-09 11:41:59 -0300131MODULE_VERSION(USBVISION_VERSION_STRING);
132MODULE_ALIAS(DRIVER_ALIAS);
Thierry MERLE483dfdb2006-12-04 08:31:45 -0300133
134
Thierry MERLEc5f48362007-05-08 17:22:29 -0300135/*****************************************************************************/
136/* SYSFS Code - Copied from the stv680.c usb module. */
137/* Device information is located at /sys/class/video4linux/video0 */
138/* Device parameters information is located at /sys/module/usbvision */
139/* Device USB Information is located at */
140/* /sys/bus/usb/drivers/USBVision Video Grabber */
141/*****************************************************************************/
Thierry MERLE483dfdb2006-12-04 08:31:45 -0300142
Thierry MERLE483dfdb2006-12-04 08:31:45 -0300143#define YES_NO(x) ((x) ? "Yes" : "No")
144
Kay Sievers54bd5b62007-10-08 16:26:13 -0300145static inline struct usb_usbvision *cd_to_usbvision(struct device *cd)
Thierry MERLE483dfdb2006-12-04 08:31:45 -0300146{
Geliang Tang03c6bdf2015-12-22 13:38:04 -0200147 struct video_device *vdev = to_video_device(cd);
Thierry MERLE483dfdb2006-12-04 08:31:45 -0300148 return video_get_drvdata(vdev);
149}
150
Kay Sievers54bd5b62007-10-08 16:26:13 -0300151static ssize_t show_version(struct device *cd,
152 struct device_attribute *attr, char *buf)
Thierry MERLE483dfdb2006-12-04 08:31:45 -0300153{
154 return sprintf(buf, "%s\n", USBVISION_VERSION_STRING);
155}
Kay Sievers54bd5b62007-10-08 16:26:13 -0300156static DEVICE_ATTR(version, S_IRUGO, show_version, NULL);
Thierry MERLE483dfdb2006-12-04 08:31:45 -0300157
Kay Sievers54bd5b62007-10-08 16:26:13 -0300158static ssize_t show_model(struct device *cd,
159 struct device_attribute *attr, char *buf)
Thierry MERLE483dfdb2006-12-04 08:31:45 -0300160{
Geliang Tang03c6bdf2015-12-22 13:38:04 -0200161 struct video_device *vdev = to_video_device(cd);
Thierry MERLE483dfdb2006-12-04 08:31:45 -0300162 struct usb_usbvision *usbvision = video_get_drvdata(vdev);
Thierry MERLEc5f48362007-05-08 17:22:29 -0300163 return sprintf(buf, "%s\n",
Hans Verkuil5490a7c2010-12-19 20:21:36 -0300164 usbvision_device_data[usbvision->dev_model].model_string);
Thierry MERLE483dfdb2006-12-04 08:31:45 -0300165}
Kay Sievers54bd5b62007-10-08 16:26:13 -0300166static DEVICE_ATTR(model, S_IRUGO, show_model, NULL);
Thierry MERLE483dfdb2006-12-04 08:31:45 -0300167
Kay Sievers54bd5b62007-10-08 16:26:13 -0300168static ssize_t show_hue(struct device *cd,
169 struct device_attribute *attr, char *buf)
Thierry MERLE483dfdb2006-12-04 08:31:45 -0300170{
Geliang Tang03c6bdf2015-12-22 13:38:04 -0200171 struct video_device *vdev = to_video_device(cd);
Thierry MERLE483dfdb2006-12-04 08:31:45 -0300172 struct usb_usbvision *usbvision = video_get_drvdata(vdev);
Hans Verkuil25bba362016-07-03 08:58:07 -0300173 s32 val = v4l2_ctrl_g_ctrl(v4l2_ctrl_find(&usbvision->hdl,
174 V4L2_CID_HUE));
175
176 return sprintf(buf, "%d\n", val);
Thierry MERLE483dfdb2006-12-04 08:31:45 -0300177}
Kay Sievers54bd5b62007-10-08 16:26:13 -0300178static DEVICE_ATTR(hue, S_IRUGO, show_hue, NULL);
Thierry MERLE483dfdb2006-12-04 08:31:45 -0300179
Kay Sievers54bd5b62007-10-08 16:26:13 -0300180static ssize_t show_contrast(struct device *cd,
181 struct device_attribute *attr, char *buf)
Thierry MERLE483dfdb2006-12-04 08:31:45 -0300182{
Geliang Tang03c6bdf2015-12-22 13:38:04 -0200183 struct video_device *vdev = to_video_device(cd);
Thierry MERLE483dfdb2006-12-04 08:31:45 -0300184 struct usb_usbvision *usbvision = video_get_drvdata(vdev);
Hans Verkuil25bba362016-07-03 08:58:07 -0300185 s32 val = v4l2_ctrl_g_ctrl(v4l2_ctrl_find(&usbvision->hdl,
186 V4L2_CID_CONTRAST));
187
188 return sprintf(buf, "%d\n", val);
Thierry MERLE483dfdb2006-12-04 08:31:45 -0300189}
Kay Sievers54bd5b62007-10-08 16:26:13 -0300190static DEVICE_ATTR(contrast, S_IRUGO, show_contrast, NULL);
Thierry MERLE483dfdb2006-12-04 08:31:45 -0300191
Kay Sievers54bd5b62007-10-08 16:26:13 -0300192static ssize_t show_brightness(struct device *cd,
193 struct device_attribute *attr, char *buf)
Thierry MERLE483dfdb2006-12-04 08:31:45 -0300194{
Geliang Tang03c6bdf2015-12-22 13:38:04 -0200195 struct video_device *vdev = to_video_device(cd);
Thierry MERLE483dfdb2006-12-04 08:31:45 -0300196 struct usb_usbvision *usbvision = video_get_drvdata(vdev);
Hans Verkuil25bba362016-07-03 08:58:07 -0300197 s32 val = v4l2_ctrl_g_ctrl(v4l2_ctrl_find(&usbvision->hdl,
198 V4L2_CID_BRIGHTNESS));
199
200 return sprintf(buf, "%d\n", val);
Thierry MERLE483dfdb2006-12-04 08:31:45 -0300201}
Kay Sievers54bd5b62007-10-08 16:26:13 -0300202static DEVICE_ATTR(brightness, S_IRUGO, show_brightness, NULL);
Thierry MERLE483dfdb2006-12-04 08:31:45 -0300203
Kay Sievers54bd5b62007-10-08 16:26:13 -0300204static ssize_t show_saturation(struct device *cd,
205 struct device_attribute *attr, char *buf)
Thierry MERLE483dfdb2006-12-04 08:31:45 -0300206{
Geliang Tang03c6bdf2015-12-22 13:38:04 -0200207 struct video_device *vdev = to_video_device(cd);
Thierry MERLE483dfdb2006-12-04 08:31:45 -0300208 struct usb_usbvision *usbvision = video_get_drvdata(vdev);
Hans Verkuil25bba362016-07-03 08:58:07 -0300209 s32 val = v4l2_ctrl_g_ctrl(v4l2_ctrl_find(&usbvision->hdl,
210 V4L2_CID_SATURATION));
211
212 return sprintf(buf, "%d\n", val);
Thierry MERLE483dfdb2006-12-04 08:31:45 -0300213}
Kay Sievers54bd5b62007-10-08 16:26:13 -0300214static DEVICE_ATTR(saturation, S_IRUGO, show_saturation, NULL);
Thierry MERLE483dfdb2006-12-04 08:31:45 -0300215
Kay Sievers54bd5b62007-10-08 16:26:13 -0300216static ssize_t show_streaming(struct device *cd,
217 struct device_attribute *attr, char *buf)
Thierry MERLE483dfdb2006-12-04 08:31:45 -0300218{
Geliang Tang03c6bdf2015-12-22 13:38:04 -0200219 struct video_device *vdev = to_video_device(cd);
Thierry MERLE483dfdb2006-12-04 08:31:45 -0300220 struct usb_usbvision *usbvision = video_get_drvdata(vdev);
Thierry MERLEc5f48362007-05-08 17:22:29 -0300221 return sprintf(buf, "%s\n",
Hans Verkuil6d6a48e2010-12-29 13:53:21 -0300222 YES_NO(usbvision->streaming == stream_on ? 1 : 0));
Thierry MERLE483dfdb2006-12-04 08:31:45 -0300223}
Kay Sievers54bd5b62007-10-08 16:26:13 -0300224static DEVICE_ATTR(streaming, S_IRUGO, show_streaming, NULL);
Thierry MERLE483dfdb2006-12-04 08:31:45 -0300225
Kay Sievers54bd5b62007-10-08 16:26:13 -0300226static ssize_t show_compression(struct device *cd,
227 struct device_attribute *attr, char *buf)
Thierry MERLE483dfdb2006-12-04 08:31:45 -0300228{
Geliang Tang03c6bdf2015-12-22 13:38:04 -0200229 struct video_device *vdev = to_video_device(cd);
Thierry MERLE483dfdb2006-12-04 08:31:45 -0300230 struct usb_usbvision *usbvision = video_get_drvdata(vdev);
Thierry MERLEc5f48362007-05-08 17:22:29 -0300231 return sprintf(buf, "%s\n",
Hans Verkuil6d6a48e2010-12-29 13:53:21 -0300232 YES_NO(usbvision->isoc_mode == ISOC_MODE_COMPRESS));
Thierry MERLE483dfdb2006-12-04 08:31:45 -0300233}
Kay Sievers54bd5b62007-10-08 16:26:13 -0300234static DEVICE_ATTR(compression, S_IRUGO, show_compression, NULL);
Thierry MERLE483dfdb2006-12-04 08:31:45 -0300235
Kay Sievers54bd5b62007-10-08 16:26:13 -0300236static ssize_t show_device_bridge(struct device *cd,
237 struct device_attribute *attr, char *buf)
Thierry MERLE483dfdb2006-12-04 08:31:45 -0300238{
Geliang Tang03c6bdf2015-12-22 13:38:04 -0200239 struct video_device *vdev = to_video_device(cd);
Thierry MERLE483dfdb2006-12-04 08:31:45 -0300240 struct usb_usbvision *usbvision = video_get_drvdata(vdev);
Hans Verkuil5490a7c2010-12-19 20:21:36 -0300241 return sprintf(buf, "%d\n", usbvision->bridge_type);
Thierry MERLE483dfdb2006-12-04 08:31:45 -0300242}
Kay Sievers54bd5b62007-10-08 16:26:13 -0300243static DEVICE_ATTR(bridge, S_IRUGO, show_device_bridge, NULL);
Thierry MERLE483dfdb2006-12-04 08:31:45 -0300244
245static void usbvision_create_sysfs(struct video_device *vdev)
246{
247 int res;
Hans Verkuil6d6a48e2010-12-29 13:53:21 -0300248
Dwaine Gardened00b412006-12-27 10:23:28 -0200249 if (!vdev)
250 return;
251 do {
Hans Verkuil22a04f12008-07-20 06:35:02 -0300252 res = device_create_file(&vdev->dev, &dev_attr_version);
Hans Verkuil6d6a48e2010-12-29 13:53:21 -0300253 if (res < 0)
Dwaine Gardened00b412006-12-27 10:23:28 -0200254 break;
Hans Verkuil22a04f12008-07-20 06:35:02 -0300255 res = device_create_file(&vdev->dev, &dev_attr_model);
Hans Verkuil6d6a48e2010-12-29 13:53:21 -0300256 if (res < 0)
Dwaine Gardened00b412006-12-27 10:23:28 -0200257 break;
Hans Verkuil22a04f12008-07-20 06:35:02 -0300258 res = device_create_file(&vdev->dev, &dev_attr_hue);
Hans Verkuil6d6a48e2010-12-29 13:53:21 -0300259 if (res < 0)
Dwaine Gardened00b412006-12-27 10:23:28 -0200260 break;
Hans Verkuil22a04f12008-07-20 06:35:02 -0300261 res = device_create_file(&vdev->dev, &dev_attr_contrast);
Hans Verkuil6d6a48e2010-12-29 13:53:21 -0300262 if (res < 0)
Dwaine Gardened00b412006-12-27 10:23:28 -0200263 break;
Hans Verkuil22a04f12008-07-20 06:35:02 -0300264 res = device_create_file(&vdev->dev, &dev_attr_brightness);
Hans Verkuil6d6a48e2010-12-29 13:53:21 -0300265 if (res < 0)
Dwaine Gardened00b412006-12-27 10:23:28 -0200266 break;
Hans Verkuil22a04f12008-07-20 06:35:02 -0300267 res = device_create_file(&vdev->dev, &dev_attr_saturation);
Hans Verkuil6d6a48e2010-12-29 13:53:21 -0300268 if (res < 0)
Dwaine Gardened00b412006-12-27 10:23:28 -0200269 break;
Hans Verkuil22a04f12008-07-20 06:35:02 -0300270 res = device_create_file(&vdev->dev, &dev_attr_streaming);
Hans Verkuil6d6a48e2010-12-29 13:53:21 -0300271 if (res < 0)
Dwaine Gardened00b412006-12-27 10:23:28 -0200272 break;
Hans Verkuil22a04f12008-07-20 06:35:02 -0300273 res = device_create_file(&vdev->dev, &dev_attr_compression);
Hans Verkuil6d6a48e2010-12-29 13:53:21 -0300274 if (res < 0)
Dwaine Gardened00b412006-12-27 10:23:28 -0200275 break;
Hans Verkuil22a04f12008-07-20 06:35:02 -0300276 res = device_create_file(&vdev->dev, &dev_attr_bridge);
Hans Verkuil6d6a48e2010-12-29 13:53:21 -0300277 if (res >= 0)
Dwaine Gardened00b412006-12-27 10:23:28 -0200278 return;
279 } while (0);
280
Mauro Carvalho Chehabbe9ed512009-01-08 09:13:42 -0300281 dev_err(&vdev->dev, "%s error: %d\n", __func__, res);
Thierry MERLE483dfdb2006-12-04 08:31:45 -0300282}
283
284static void usbvision_remove_sysfs(struct video_device *vdev)
285{
286 if (vdev) {
Hans Verkuil22a04f12008-07-20 06:35:02 -0300287 device_remove_file(&vdev->dev, &dev_attr_version);
288 device_remove_file(&vdev->dev, &dev_attr_model);
289 device_remove_file(&vdev->dev, &dev_attr_hue);
290 device_remove_file(&vdev->dev, &dev_attr_contrast);
291 device_remove_file(&vdev->dev, &dev_attr_brightness);
292 device_remove_file(&vdev->dev, &dev_attr_saturation);
293 device_remove_file(&vdev->dev, &dev_attr_streaming);
294 device_remove_file(&vdev->dev, &dev_attr_compression);
295 device_remove_file(&vdev->dev, &dev_attr_bridge);
Thierry MERLE483dfdb2006-12-04 08:31:45 -0300296 }
297}
298
Thierry MERLE483dfdb2006-12-04 08:31:45 -0300299/*
300 * usbvision_open()
301 *
302 * This is part of Video 4 Linux API. The driver can be opened by one
303 * client only (checks internal counter 'usbvision->user'). The procedure
304 * then allocates buffers needed for video processing.
305 *
306 */
Hans Verkuilbec43662008-12-30 06:58:20 -0300307static int usbvision_v4l2_open(struct file *file)
Thierry MERLE483dfdb2006-12-04 08:31:45 -0300308{
Hans Verkuilc170ecf2008-08-23 08:32:09 -0300309 struct usb_usbvision *usbvision = video_drvdata(file);
Hans Verkuil5490a7c2010-12-19 20:21:36 -0300310 int err_code = 0;
Thierry MERLE483dfdb2006-12-04 08:31:45 -0300311
312 PDEBUG(DBG_IO, "open");
313
Hans Verkuil4d345702012-06-23 08:03:50 -0300314 if (mutex_lock_interruptible(&usbvision->v4l2_lock))
315 return -ERESTARTSYS;
Thierry MERLE483dfdb2006-12-04 08:31:45 -0300316
Hans Verkuil62e25942015-07-20 09:59:28 -0300317 if (usbvision->user) {
Hans Verkuil5490a7c2010-12-19 20:21:36 -0300318 err_code = -EBUSY;
Hans Verkuil62e25942015-07-20 09:59:28 -0300319 } else {
Hans Verkuilfd958702015-07-20 09:59:29 -0300320 err_code = v4l2_fh_open(file);
321 if (err_code)
322 goto unlock;
323
Thierry MERLE6f78e182007-02-07 10:13:11 -0300324 /* Allocate memory for the scratch ring buffer */
Hans Verkuil5490a7c2010-12-19 20:21:36 -0300325 err_code = usbvision_scratch_alloc(usbvision);
Hans Verkuil6d6a48e2010-12-29 13:53:21 -0300326 if (isoc_mode == ISOC_MODE_COMPRESS) {
Thierry MERLEc5f48362007-05-08 17:22:29 -0300327 /* Allocate intermediate decompression buffers
328 only if needed */
Hans Verkuil5490a7c2010-12-19 20:21:36 -0300329 err_code = usbvision_decompress_alloc(usbvision);
Thierry MERLE483dfdb2006-12-04 08:31:45 -0300330 }
Hans Verkuil5490a7c2010-12-19 20:21:36 -0300331 if (err_code) {
Thierry MERLE483dfdb2006-12-04 08:31:45 -0300332 /* Deallocate all buffers if trouble */
Thierry MERLE483dfdb2006-12-04 08:31:45 -0300333 usbvision_scratch_free(usbvision);
Thierry MERLE483dfdb2006-12-04 08:31:45 -0300334 usbvision_decompress_free(usbvision);
335 }
336 }
337
338 /* If so far no errors then we shall start the camera */
Hans Verkuil5490a7c2010-12-19 20:21:36 -0300339 if (!err_code) {
Thierry MERLE483dfdb2006-12-04 08:31:45 -0300340 /* Send init sequence only once, it's large! */
341 if (!usbvision->initialized) {
342 int setup_ok = 0;
Hans Verkuil6d6a48e2010-12-29 13:53:21 -0300343 setup_ok = usbvision_setup(usbvision, isoc_mode);
Thierry MERLE483dfdb2006-12-04 08:31:45 -0300344 if (setup_ok)
345 usbvision->initialized = 1;
346 else
Hans Verkuil5490a7c2010-12-19 20:21:36 -0300347 err_code = -EBUSY;
Thierry MERLE483dfdb2006-12-04 08:31:45 -0300348 }
349
Hans Verkuil5490a7c2010-12-19 20:21:36 -0300350 if (!err_code) {
Thierry MERLE483dfdb2006-12-04 08:31:45 -0300351 usbvision_begin_streaming(usbvision);
Hans Verkuil5490a7c2010-12-19 20:21:36 -0300352 err_code = usbvision_init_isoc(usbvision);
Thierry MERLEc5f48362007-05-08 17:22:29 -0300353 /* device must be initialized before isoc transfer */
Hans Verkuil6d6a48e2010-12-29 13:53:21 -0300354 usbvision_muxsel(usbvision, 0);
Hans Verkuil62e25942015-07-20 09:59:28 -0300355
356 /* prepare queues */
357 usbvision_empty_framequeues(usbvision);
Thierry MERLE483dfdb2006-12-04 08:31:45 -0300358 usbvision->user++;
Thierry MERLE483dfdb2006-12-04 08:31:45 -0300359 }
Thierry MERLE483dfdb2006-12-04 08:31:45 -0300360 }
361
Hans Verkuilfd958702015-07-20 09:59:29 -0300362unlock:
Hans Verkuil4d345702012-06-23 08:03:50 -0300363 mutex_unlock(&usbvision->v4l2_lock);
Thierry MERLE483dfdb2006-12-04 08:31:45 -0300364
365 PDEBUG(DBG_IO, "success");
Hans Verkuil5490a7c2010-12-19 20:21:36 -0300366 return err_code;
Thierry MERLE483dfdb2006-12-04 08:31:45 -0300367}
368
369/*
370 * usbvision_v4l2_close()
371 *
372 * This is part of Video 4 Linux API. The procedure
373 * stops streaming and deallocates all buffers that were earlier
374 * allocated in usbvision_v4l2_open().
375 *
376 */
Hans Verkuilbec43662008-12-30 06:58:20 -0300377static int usbvision_v4l2_close(struct file *file)
Thierry MERLE483dfdb2006-12-04 08:31:45 -0300378{
Hans Verkuilc170ecf2008-08-23 08:32:09 -0300379 struct usb_usbvision *usbvision = video_drvdata(file);
Thierry MERLE483dfdb2006-12-04 08:31:45 -0300380
381 PDEBUG(DBG_IO, "close");
Thierry MERLE483dfdb2006-12-04 08:31:45 -0300382
Hans Verkuil4d345702012-06-23 08:03:50 -0300383 mutex_lock(&usbvision->v4l2_lock);
Thierry MERLE483dfdb2006-12-04 08:31:45 -0300384 usbvision_audio_off(usbvision);
385 usbvision_restart_isoc(usbvision);
386 usbvision_stop_isoc(usbvision);
387
388 usbvision_decompress_free(usbvision);
Thierry MERLE38284ba2006-12-15 16:46:53 -0300389 usbvision_frames_free(usbvision);
Thierry MERLE6f78e182007-02-07 10:13:11 -0300390 usbvision_empty_framequeues(usbvision);
Thierry MERLE483dfdb2006-12-04 08:31:45 -0300391 usbvision_scratch_free(usbvision);
Thierry MERLE483dfdb2006-12-04 08:31:45 -0300392
393 usbvision->user--;
Hans Verkuile2c84cc2015-07-20 09:59:35 -0300394 mutex_unlock(&usbvision->v4l2_lock);
Thierry MERLE483dfdb2006-12-04 08:31:45 -0300395
Thierry MERLE483dfdb2006-12-04 08:31:45 -0300396 if (usbvision->remove_pending) {
Harvey Harrisond2db42d2008-04-04 20:50:07 -0300397 printk(KERN_INFO "%s: Final disconnect\n", __func__);
Thierry MERLE483dfdb2006-12-04 08:31:45 -0300398 usbvision_release(usbvision);
Dan Carpenter470a9142014-10-16 04:57:21 -0300399 return 0;
Thierry MERLE483dfdb2006-12-04 08:31:45 -0300400 }
401
402 PDEBUG(DBG_IO, "success");
Hans Verkuilfd958702015-07-20 09:59:29 -0300403 return v4l2_fh_release(file);
Thierry MERLE483dfdb2006-12-04 08:31:45 -0300404}
405
406
407/*
408 * usbvision_ioctl()
409 *
410 * This is part of Video 4 Linux API. The procedure handles ioctl() calls.
411 *
412 */
Thierry MERLEc5f48362007-05-08 17:22:29 -0300413#ifdef CONFIG_VIDEO_ADV_DEBUG
Hans Verkuil6d6a48e2010-12-29 13:53:21 -0300414static int vidioc_g_register(struct file *file, void *priv,
Hans Verkuilaecde8b52008-12-30 07:14:19 -0300415 struct v4l2_dbg_register *reg)
Thierry MERLE483dfdb2006-12-04 08:31:45 -0300416{
Hans Verkuilc170ecf2008-08-23 08:32:09 -0300417 struct usb_usbvision *usbvision = video_drvdata(file);
Hans Verkuil5490a7c2010-12-19 20:21:36 -0300418 int err_code;
Thierry MERLE483dfdb2006-12-04 08:31:45 -0300419
Thierry MERLEc5f48362007-05-08 17:22:29 -0300420 /* NT100x has a 8-bit register space */
Hans Verkuil5490a7c2010-12-19 20:21:36 -0300421 err_code = usbvision_read_reg(usbvision, reg->reg&0xff);
422 if (err_code < 0) {
Hans Verkuil2aa689d2015-03-09 13:34:12 -0300423 dev_err(&usbvision->vdev.dev,
Mauro Carvalho Chehabbe9ed512009-01-08 09:13:42 -0300424 "%s: VIDIOC_DBG_G_REGISTER failed: error %d\n",
Hans Verkuil5490a7c2010-12-19 20:21:36 -0300425 __func__, err_code);
426 return err_code;
Thierry MERLE483dfdb2006-12-04 08:31:45 -0300427 }
Hans Verkuil5490a7c2010-12-19 20:21:36 -0300428 reg->val = err_code;
Hans Verkuilaecde8b52008-12-30 07:14:19 -0300429 reg->size = 1;
Thierry MERLE483dfdb2006-12-04 08:31:45 -0300430 return 0;
431}
432
Hans Verkuil6d6a48e2010-12-29 13:53:21 -0300433static int vidioc_s_register(struct file *file, void *priv,
Hans Verkuil977ba3b12013-03-24 08:28:46 -0300434 const struct v4l2_dbg_register *reg)
Thierry MERLE483dfdb2006-12-04 08:31:45 -0300435{
Hans Verkuilc170ecf2008-08-23 08:32:09 -0300436 struct usb_usbvision *usbvision = video_drvdata(file);
Hans Verkuil5490a7c2010-12-19 20:21:36 -0300437 int err_code;
Thierry MERLEc5f48362007-05-08 17:22:29 -0300438
Thierry MERLEc5f48362007-05-08 17:22:29 -0300439 /* NT100x has a 8-bit register space */
Hans Verkuil6d6a48e2010-12-29 13:53:21 -0300440 err_code = usbvision_write_reg(usbvision, reg->reg & 0xff, reg->val);
Hans Verkuil5490a7c2010-12-19 20:21:36 -0300441 if (err_code < 0) {
Hans Verkuil2aa689d2015-03-09 13:34:12 -0300442 dev_err(&usbvision->vdev.dev,
Mauro Carvalho Chehabbe9ed512009-01-08 09:13:42 -0300443 "%s: VIDIOC_DBG_S_REGISTER failed: error %d\n",
Hans Verkuil5490a7c2010-12-19 20:21:36 -0300444 __func__, err_code);
445 return err_code;
Thierry MERLEc5f48362007-05-08 17:22:29 -0300446 }
447 return 0;
448}
449#endif
450
Hans Verkuil6d6a48e2010-12-29 13:53:21 -0300451static int vidioc_querycap(struct file *file, void *priv,
Thierry MERLEc5f48362007-05-08 17:22:29 -0300452 struct v4l2_capability *vc)
453{
Hans Verkuilc170ecf2008-08-23 08:32:09 -0300454 struct usb_usbvision *usbvision = video_drvdata(file);
Hans Verkuilcbe12cc2015-07-20 09:59:32 -0300455 struct video_device *vdev = video_devdata(file);
Thierry MERLEc5f48362007-05-08 17:22:29 -0300456
Mauro Carvalho Chehabc0decac2018-09-10 08:19:14 -0400457 strscpy(vc->driver, "USBVision", sizeof(vc->driver));
458 strscpy(vc->card,
Hans Verkuil5490a7c2010-12-19 20:21:36 -0300459 usbvision_device_data[usbvision->dev_model].model_string,
Thierry MERLEc5f48362007-05-08 17:22:29 -0300460 sizeof(vc->card));
Thierry MERLE6f2a2782009-01-20 17:40:44 -0300461 usb_make_path(usbvision->dev, vc->bus_info, sizeof(vc->bus_info));
Hans Verkuilcbe12cc2015-07-20 09:59:32 -0300462 vc->device_caps = usbvision->have_tuner ? V4L2_CAP_TUNER : 0;
463 if (vdev->vfl_type == VFL_TYPE_GRABBER)
464 vc->device_caps |= V4L2_CAP_VIDEO_CAPTURE |
465 V4L2_CAP_READWRITE | V4L2_CAP_STREAMING;
466 else
467 vc->device_caps |= V4L2_CAP_RADIO;
468
469 vc->capabilities = vc->device_caps | V4L2_CAP_VIDEO_CAPTURE |
470 V4L2_CAP_READWRITE | V4L2_CAP_STREAMING | V4L2_CAP_DEVICE_CAPS;
471 if (usbvision_device_data[usbvision->dev_model].radio)
472 vc->capabilities |= V4L2_CAP_RADIO;
Thierry MERLEc5f48362007-05-08 17:22:29 -0300473 return 0;
Thierry MERLE483dfdb2006-12-04 08:31:45 -0300474}
475
Hans Verkuil6d6a48e2010-12-29 13:53:21 -0300476static int vidioc_enum_input(struct file *file, void *priv,
Thierry MERLEc5f48362007-05-08 17:22:29 -0300477 struct v4l2_input *vi)
478{
Hans Verkuilc170ecf2008-08-23 08:32:09 -0300479 struct usb_usbvision *usbvision = video_drvdata(file);
Thierry MERLEc5f48362007-05-08 17:22:29 -0300480 int chan;
481
Roel Kluin223ffe52009-05-02 16:38:47 -0300482 if (vi->index >= usbvision->video_inputs)
Thierry MERLEc5f48362007-05-08 17:22:29 -0300483 return -EINVAL;
Hans Verkuil6d6a48e2010-12-29 13:53:21 -0300484 if (usbvision->have_tuner)
Thierry MERLEc5f48362007-05-08 17:22:29 -0300485 chan = vi->index;
Hans Verkuil6d6a48e2010-12-29 13:53:21 -0300486 else
Hans Verkuil52cb0bf22010-12-19 20:33:51 -0300487 chan = vi->index + 1; /* skip Television string*/
Hans Verkuil6d6a48e2010-12-29 13:53:21 -0300488
Thierry MERLEc5f48362007-05-08 17:22:29 -0300489 /* Determine the requested input characteristics
490 specific for each usbvision card model */
Hans Verkuil6d6a48e2010-12-29 13:53:21 -0300491 switch (chan) {
Thierry MERLEc5f48362007-05-08 17:22:29 -0300492 case 0:
Hans Verkuil5490a7c2010-12-19 20:21:36 -0300493 if (usbvision_device_data[usbvision->dev_model].video_channels == 4) {
Mauro Carvalho Chehabcc1e6312018-09-10 16:20:42 -0400494 strscpy(vi->name, "White Video Input", sizeof(vi->name));
Thierry MERLEc5f48362007-05-08 17:22:29 -0300495 } else {
Mauro Carvalho Chehabcc1e6312018-09-10 16:20:42 -0400496 strscpy(vi->name, "Television", sizeof(vi->name));
Thierry MERLEc5f48362007-05-08 17:22:29 -0300497 vi->type = V4L2_INPUT_TYPE_TUNER;
Thierry MERLEc5f48362007-05-08 17:22:29 -0300498 vi->tuner = chan;
499 vi->std = USBVISION_NORMS;
500 }
501 break;
502 case 1:
503 vi->type = V4L2_INPUT_TYPE_CAMERA;
Hans Verkuil6d6a48e2010-12-29 13:53:21 -0300504 if (usbvision_device_data[usbvision->dev_model].video_channels == 4)
Mauro Carvalho Chehabcc1e6312018-09-10 16:20:42 -0400505 strscpy(vi->name, "Green Video Input", sizeof(vi->name));
Hans Verkuil6d6a48e2010-12-29 13:53:21 -0300506 else
Mauro Carvalho Chehabcc1e6312018-09-10 16:20:42 -0400507 strscpy(vi->name, "Composite Video Input",
508 sizeof(vi->name));
Hans Verkuil94384012015-07-20 09:59:37 -0300509 vi->std = USBVISION_NORMS;
Thierry MERLEc5f48362007-05-08 17:22:29 -0300510 break;
511 case 2:
512 vi->type = V4L2_INPUT_TYPE_CAMERA;
Hans Verkuil6d6a48e2010-12-29 13:53:21 -0300513 if (usbvision_device_data[usbvision->dev_model].video_channels == 4)
Mauro Carvalho Chehabcc1e6312018-09-10 16:20:42 -0400514 strscpy(vi->name, "Yellow Video Input", sizeof(vi->name));
Hans Verkuil6d6a48e2010-12-29 13:53:21 -0300515 else
Mauro Carvalho Chehabcc1e6312018-09-10 16:20:42 -0400516 strscpy(vi->name, "S-Video Input", sizeof(vi->name));
Hans Verkuil94384012015-07-20 09:59:37 -0300517 vi->std = USBVISION_NORMS;
Thierry MERLEc5f48362007-05-08 17:22:29 -0300518 break;
519 case 3:
520 vi->type = V4L2_INPUT_TYPE_CAMERA;
Mauro Carvalho Chehabcc1e6312018-09-10 16:20:42 -0400521 strscpy(vi->name, "Red Video Input", sizeof(vi->name));
Hans Verkuil94384012015-07-20 09:59:37 -0300522 vi->std = USBVISION_NORMS;
Thierry MERLEc5f48362007-05-08 17:22:29 -0300523 break;
524 }
525 return 0;
526}
527
Hans Verkuil6d6a48e2010-12-29 13:53:21 -0300528static int vidioc_g_input(struct file *file, void *priv, unsigned int *input)
Thierry MERLEc5f48362007-05-08 17:22:29 -0300529{
Hans Verkuilc170ecf2008-08-23 08:32:09 -0300530 struct usb_usbvision *usbvision = video_drvdata(file);
Thierry MERLEc5f48362007-05-08 17:22:29 -0300531
532 *input = usbvision->ctl_input;
533 return 0;
534}
535
Hans Verkuil6d6a48e2010-12-29 13:53:21 -0300536static int vidioc_s_input(struct file *file, void *priv, unsigned int input)
Thierry MERLEc5f48362007-05-08 17:22:29 -0300537{
Hans Verkuilc170ecf2008-08-23 08:32:09 -0300538 struct usb_usbvision *usbvision = video_drvdata(file);
Thierry MERLEc5f48362007-05-08 17:22:29 -0300539
Roel Kluinf14a2972009-10-23 07:59:42 -0300540 if (input >= usbvision->video_inputs)
Thierry MERLEc5f48362007-05-08 17:22:29 -0300541 return -EINVAL;
Thierry MERLEc5f48362007-05-08 17:22:29 -0300542
Thierry MERLE66a17872007-06-26 16:35:30 -0300543 usbvision_muxsel(usbvision, input);
Thierry MERLEc5f48362007-05-08 17:22:29 -0300544 usbvision_set_input(usbvision);
545 usbvision_set_output(usbvision,
546 usbvision->curwidth,
547 usbvision->curheight);
Thierry MERLEc5f48362007-05-08 17:22:29 -0300548 return 0;
549}
550
Hans Verkuil314527acb2013-03-15 06:10:40 -0300551static int vidioc_s_std(struct file *file, void *priv, v4l2_std_id id)
Thierry MERLEc5f48362007-05-08 17:22:29 -0300552{
Hans Verkuilc170ecf2008-08-23 08:32:09 -0300553 struct usb_usbvision *usbvision = video_drvdata(file);
554
Hans Verkuil314527acb2013-03-15 06:10:40 -0300555 usbvision->tvnorm_id = id;
Thierry MERLEc5f48362007-05-08 17:22:29 -0300556
Laurent Pinchart8774bed2014-04-28 16:53:01 -0300557 call_all(usbvision, video, s_std, usbvision->tvnorm_id);
Thierry MERLE66a17872007-06-26 16:35:30 -0300558 /* propagate the change to the decoder */
559 usbvision_muxsel(usbvision, usbvision->ctl_input);
Thierry MERLEc5f48362007-05-08 17:22:29 -0300560
561 return 0;
562}
563
Hans Verkuil3b8436d2013-06-03 05:36:47 -0300564static int vidioc_g_std(struct file *file, void *priv, v4l2_std_id *id)
565{
566 struct usb_usbvision *usbvision = video_drvdata(file);
567
568 *id = usbvision->tvnorm_id;
569 return 0;
570}
571
Hans Verkuil6d6a48e2010-12-29 13:53:21 -0300572static int vidioc_g_tuner(struct file *file, void *priv,
Thierry MERLEc5f48362007-05-08 17:22:29 -0300573 struct v4l2_tuner *vt)
574{
Hans Verkuilc170ecf2008-08-23 08:32:09 -0300575 struct usb_usbvision *usbvision = video_drvdata(file);
Thierry MERLEc5f48362007-05-08 17:22:29 -0300576
Hans Verkuil64d416e2015-07-20 09:59:33 -0300577 if (vt->index) /* Only tuner 0 */
Thierry MERLEc5f48362007-05-08 17:22:29 -0300578 return -EINVAL;
Hans Verkuil64d416e2015-07-20 09:59:33 -0300579 if (vt->type == V4L2_TUNER_RADIO)
Mauro Carvalho Chehabcc1e6312018-09-10 16:20:42 -0400580 strscpy(vt->name, "Radio", sizeof(vt->name));
Hans Verkuil64d416e2015-07-20 09:59:33 -0300581 else
Mauro Carvalho Chehabcc1e6312018-09-10 16:20:42 -0400582 strscpy(vt->name, "Television", sizeof(vt->name));
Hans Verkuil64d416e2015-07-20 09:59:33 -0300583
Thierry MERLEc5f48362007-05-08 17:22:29 -0300584 /* Let clients fill in the remainder of this struct */
Hans Verkuil1df79532009-02-21 18:11:31 -0300585 call_all(usbvision, tuner, g_tuner, vt);
Thierry MERLEc5f48362007-05-08 17:22:29 -0300586
587 return 0;
588}
589
Hans Verkuil6d6a48e2010-12-29 13:53:21 -0300590static int vidioc_s_tuner(struct file *file, void *priv,
Hans Verkuil2f73c7c2013-03-15 06:10:06 -0300591 const struct v4l2_tuner *vt)
Thierry MERLEc5f48362007-05-08 17:22:29 -0300592{
Hans Verkuilc170ecf2008-08-23 08:32:09 -0300593 struct usb_usbvision *usbvision = video_drvdata(file);
Thierry MERLEc5f48362007-05-08 17:22:29 -0300594
Hans Verkuil64d416e2015-07-20 09:59:33 -0300595 /* Only one tuner for now */
596 if (vt->index)
Thierry MERLEc5f48362007-05-08 17:22:29 -0300597 return -EINVAL;
598 /* let clients handle this */
Hans Verkuil1df79532009-02-21 18:11:31 -0300599 call_all(usbvision, tuner, s_tuner, vt);
Thierry MERLEc5f48362007-05-08 17:22:29 -0300600
601 return 0;
602}
603
Hans Verkuil6d6a48e2010-12-29 13:53:21 -0300604static int vidioc_g_frequency(struct file *file, void *priv,
Thierry MERLEc5f48362007-05-08 17:22:29 -0300605 struct v4l2_frequency *freq)
606{
Hans Verkuilc170ecf2008-08-23 08:32:09 -0300607 struct usb_usbvision *usbvision = video_drvdata(file);
Thierry MERLEc5f48362007-05-08 17:22:29 -0300608
Hans Verkuil64d416e2015-07-20 09:59:33 -0300609 /* Only one tuner */
610 if (freq->tuner)
611 return -EINVAL;
612 if (freq->type == V4L2_TUNER_RADIO)
613 freq->frequency = usbvision->radio_freq;
Hans Verkuil6d6a48e2010-12-29 13:53:21 -0300614 else
Hans Verkuil64d416e2015-07-20 09:59:33 -0300615 freq->frequency = usbvision->tv_freq;
Thierry MERLEc5f48362007-05-08 17:22:29 -0300616
617 return 0;
618}
619
Hans Verkuil6d6a48e2010-12-29 13:53:21 -0300620static int vidioc_s_frequency(struct file *file, void *priv,
Hans Verkuilb530a442013-03-19 04:09:26 -0300621 const struct v4l2_frequency *freq)
Thierry MERLEc5f48362007-05-08 17:22:29 -0300622{
Hans Verkuilc170ecf2008-08-23 08:32:09 -0300623 struct usb_usbvision *usbvision = video_drvdata(file);
Hans Verkuil64d416e2015-07-20 09:59:33 -0300624 struct v4l2_frequency new_freq = *freq;
Thierry MERLEc5f48362007-05-08 17:22:29 -0300625
Hans Verkuil64d416e2015-07-20 09:59:33 -0300626 /* Only one tuner for now */
627 if (freq->tuner)
Thierry MERLEc5f48362007-05-08 17:22:29 -0300628 return -EINVAL;
629
Hans Verkuil1df79532009-02-21 18:11:31 -0300630 call_all(usbvision, tuner, s_frequency, freq);
Hans Verkuil64d416e2015-07-20 09:59:33 -0300631 call_all(usbvision, tuner, g_frequency, &new_freq);
632 if (freq->type == V4L2_TUNER_RADIO)
633 usbvision->radio_freq = new_freq.frequency;
634 else
635 usbvision->tv_freq = new_freq.frequency;
Thierry MERLEc5f48362007-05-08 17:22:29 -0300636
637 return 0;
638}
639
Hans Verkuil6d6a48e2010-12-29 13:53:21 -0300640static int vidioc_reqbufs(struct file *file,
Thierry MERLEc5f48362007-05-08 17:22:29 -0300641 void *priv, struct v4l2_requestbuffers *vr)
642{
Hans Verkuilc170ecf2008-08-23 08:32:09 -0300643 struct usb_usbvision *usbvision = video_drvdata(file);
Thierry MERLEc5f48362007-05-08 17:22:29 -0300644 int ret;
645
Hans Verkuil6d6a48e2010-12-29 13:53:21 -0300646 RESTRICT_TO_RANGE(vr->count, 1, USBVISION_NUMFRAMES);
Thierry MERLEc5f48362007-05-08 17:22:29 -0300647
648 /* Check input validity:
649 the user must do a VIDEO CAPTURE and MMAP method. */
Trent Piepho975f5762009-03-28 22:25:36 -0300650 if (vr->memory != V4L2_MEMORY_MMAP)
Thierry MERLEc5f48362007-05-08 17:22:29 -0300651 return -EINVAL;
652
Hans Verkuil6d6a48e2010-12-29 13:53:21 -0300653 if (usbvision->streaming == stream_on) {
654 ret = usbvision_stream_interrupt(usbvision);
655 if (ret)
Thierry MERLEc5f48362007-05-08 17:22:29 -0300656 return ret;
657 }
658
659 usbvision_frames_free(usbvision);
660 usbvision_empty_framequeues(usbvision);
Hans Verkuil6d6a48e2010-12-29 13:53:21 -0300661 vr->count = usbvision_frames_alloc(usbvision, vr->count);
Thierry MERLEc5f48362007-05-08 17:22:29 -0300662
Hans Verkuil5490a7c2010-12-19 20:21:36 -0300663 usbvision->cur_frame = NULL;
Thierry MERLEc5f48362007-05-08 17:22:29 -0300664
665 return 0;
666}
667
Hans Verkuil6d6a48e2010-12-29 13:53:21 -0300668static int vidioc_querybuf(struct file *file,
Thierry MERLEc5f48362007-05-08 17:22:29 -0300669 void *priv, struct v4l2_buffer *vb)
670{
Hans Verkuilc170ecf2008-08-23 08:32:09 -0300671 struct usb_usbvision *usbvision = video_drvdata(file);
Thierry MERLEc5f48362007-05-08 17:22:29 -0300672 struct usbvision_frame *frame;
673
674 /* FIXME : must control
675 that buffers are mapped (VIDIOC_REQBUFS has been called) */
Hans Verkuil6d6a48e2010-12-29 13:53:21 -0300676 if (vb->index >= usbvision->num_frames)
Thierry MERLEc5f48362007-05-08 17:22:29 -0300677 return -EINVAL;
Thierry MERLEc5f48362007-05-08 17:22:29 -0300678 /* Updating the corresponding frame state */
Sakari Ailus1b18e7a2012-10-22 17:10:16 -0300679 vb->flags = V4L2_BUF_FLAG_TIMESTAMP_MONOTONIC;
Thierry MERLEc5f48362007-05-08 17:22:29 -0300680 frame = &usbvision->frame[vb->index];
Hans Verkuil6d6a48e2010-12-29 13:53:21 -0300681 if (frame->grabstate >= frame_state_ready)
Thierry MERLEc5f48362007-05-08 17:22:29 -0300682 vb->flags |= V4L2_BUF_FLAG_QUEUED;
Hans Verkuil6d6a48e2010-12-29 13:53:21 -0300683 if (frame->grabstate >= frame_state_done)
Thierry MERLEc5f48362007-05-08 17:22:29 -0300684 vb->flags |= V4L2_BUF_FLAG_DONE;
Hans Verkuil6d6a48e2010-12-29 13:53:21 -0300685 if (frame->grabstate == frame_state_unused)
Thierry MERLEc5f48362007-05-08 17:22:29 -0300686 vb->flags |= V4L2_BUF_FLAG_MAPPED;
687 vb->memory = V4L2_MEMORY_MMAP;
688
Hans Verkuil6d6a48e2010-12-29 13:53:21 -0300689 vb->m.offset = vb->index * PAGE_ALIGN(usbvision->max_frame_size);
Thierry MERLEc5f48362007-05-08 17:22:29 -0300690
691 vb->memory = V4L2_MEMORY_MMAP;
692 vb->field = V4L2_FIELD_NONE;
Hans Verkuil6d6a48e2010-12-29 13:53:21 -0300693 vb->length = usbvision->curwidth *
694 usbvision->curheight *
Thierry MERLEc5f48362007-05-08 17:22:29 -0300695 usbvision->palette.bytes_per_pixel;
Hans Verkuil459d2a5d2019-01-21 08:32:27 -0500696 vb->timestamp = ns_to_timeval(usbvision->frame[vb->index].ts);
Thierry MERLEc5f48362007-05-08 17:22:29 -0300697 vb->sequence = usbvision->frame[vb->index].sequence;
698 return 0;
699}
700
Hans Verkuil6d6a48e2010-12-29 13:53:21 -0300701static int vidioc_qbuf(struct file *file, void *priv, struct v4l2_buffer *vb)
Thierry MERLEc5f48362007-05-08 17:22:29 -0300702{
Hans Verkuilc170ecf2008-08-23 08:32:09 -0300703 struct usb_usbvision *usbvision = video_drvdata(file);
Thierry MERLEc5f48362007-05-08 17:22:29 -0300704 struct usbvision_frame *frame;
705 unsigned long lock_flags;
706
707 /* FIXME : works only on VIDEO_CAPTURE MODE, MMAP. */
Hans Verkuil6d6a48e2010-12-29 13:53:21 -0300708 if (vb->index >= usbvision->num_frames)
Thierry MERLEc5f48362007-05-08 17:22:29 -0300709 return -EINVAL;
Thierry MERLEc5f48362007-05-08 17:22:29 -0300710
711 frame = &usbvision->frame[vb->index];
712
Hans Verkuil6d6a48e2010-12-29 13:53:21 -0300713 if (frame->grabstate != frame_state_unused)
Thierry MERLEc5f48362007-05-08 17:22:29 -0300714 return -EAGAIN;
Thierry MERLEc5f48362007-05-08 17:22:29 -0300715
716 /* Mark it as ready and enqueue frame */
Hans Verkuil5490a7c2010-12-19 20:21:36 -0300717 frame->grabstate = frame_state_ready;
718 frame->scanstate = scan_state_scanning;
Thierry MERLEc5f48362007-05-08 17:22:29 -0300719 frame->scanlength = 0; /* Accumulated in usbvision_parse_data() */
720
721 vb->flags &= ~V4L2_BUF_FLAG_DONE;
722
723 /* set v4l2_format index */
724 frame->v4l2_format = usbvision->palette;
725
726 spin_lock_irqsave(&usbvision->queue_lock, lock_flags);
727 list_add_tail(&usbvision->frame[vb->index].frame, &usbvision->inqueue);
728 spin_unlock_irqrestore(&usbvision->queue_lock, lock_flags);
729
730 return 0;
731}
732
Hans Verkuil6d6a48e2010-12-29 13:53:21 -0300733static int vidioc_dqbuf(struct file *file, void *priv, struct v4l2_buffer *vb)
Thierry MERLEc5f48362007-05-08 17:22:29 -0300734{
Hans Verkuilc170ecf2008-08-23 08:32:09 -0300735 struct usb_usbvision *usbvision = video_drvdata(file);
Thierry MERLEc5f48362007-05-08 17:22:29 -0300736 int ret;
737 struct usbvision_frame *f;
738 unsigned long lock_flags;
739
Thierry MERLEc5f48362007-05-08 17:22:29 -0300740 if (list_empty(&(usbvision->outqueue))) {
Hans Verkuil5490a7c2010-12-19 20:21:36 -0300741 if (usbvision->streaming == stream_idle)
Thierry MERLEc5f48362007-05-08 17:22:29 -0300742 return -EINVAL;
743 ret = wait_event_interruptible
744 (usbvision->wait_frame,
745 !list_empty(&(usbvision->outqueue)));
746 if (ret)
747 return ret;
748 }
749
750 spin_lock_irqsave(&usbvision->queue_lock, lock_flags);
751 f = list_entry(usbvision->outqueue.next,
752 struct usbvision_frame, frame);
753 list_del(usbvision->outqueue.next);
754 spin_unlock_irqrestore(&usbvision->queue_lock, lock_flags);
755
Hans Verkuil5490a7c2010-12-19 20:21:36 -0300756 f->grabstate = frame_state_unused;
Thierry MERLEc5f48362007-05-08 17:22:29 -0300757
758 vb->memory = V4L2_MEMORY_MMAP;
759 vb->flags = V4L2_BUF_FLAG_MAPPED |
760 V4L2_BUF_FLAG_QUEUED |
Sakari Ailus1b18e7a2012-10-22 17:10:16 -0300761 V4L2_BUF_FLAG_DONE |
762 V4L2_BUF_FLAG_TIMESTAMP_MONOTONIC;
Thierry MERLEc5f48362007-05-08 17:22:29 -0300763 vb->index = f->index;
764 vb->sequence = f->sequence;
Hans Verkuil459d2a5d2019-01-21 08:32:27 -0500765 vb->timestamp = ns_to_timeval(f->ts);
Thierry MERLEc5f48362007-05-08 17:22:29 -0300766 vb->field = V4L2_FIELD_NONE;
767 vb->bytesused = f->scanlength;
768
769 return 0;
770}
771
772static int vidioc_streamon(struct file *file, void *priv, enum v4l2_buf_type i)
773{
Hans Verkuilc170ecf2008-08-23 08:32:09 -0300774 struct usb_usbvision *usbvision = video_drvdata(file);
Thierry MERLEc5f48362007-05-08 17:22:29 -0300775
Hans Verkuil5490a7c2010-12-19 20:21:36 -0300776 usbvision->streaming = stream_on;
Hans Verkuil1df79532009-02-21 18:11:31 -0300777 call_all(usbvision, video, s_stream, 1);
Thierry MERLEc5f48362007-05-08 17:22:29 -0300778
779 return 0;
780}
781
782static int vidioc_streamoff(struct file *file,
783 void *priv, enum v4l2_buf_type type)
784{
Hans Verkuilc170ecf2008-08-23 08:32:09 -0300785 struct usb_usbvision *usbvision = video_drvdata(file);
Thierry MERLEc5f48362007-05-08 17:22:29 -0300786
787 if (type != V4L2_BUF_TYPE_VIDEO_CAPTURE)
788 return -EINVAL;
789
Hans Verkuil6d6a48e2010-12-29 13:53:21 -0300790 if (usbvision->streaming == stream_on) {
Thierry MERLEc5f48362007-05-08 17:22:29 -0300791 usbvision_stream_interrupt(usbvision);
792 /* Stop all video streamings */
Hans Verkuil1df79532009-02-21 18:11:31 -0300793 call_all(usbvision, video, s_stream, 0);
Thierry MERLEc5f48362007-05-08 17:22:29 -0300794 }
795 usbvision_empty_framequeues(usbvision);
796
797 return 0;
798}
799
Hans Verkuil6d6a48e2010-12-29 13:53:21 -0300800static int vidioc_enum_fmt_vid_cap(struct file *file, void *priv,
Thierry MERLEc5f48362007-05-08 17:22:29 -0300801 struct v4l2_fmtdesc *vfd)
802{
Hans Verkuil6d6a48e2010-12-29 13:53:21 -0300803 if (vfd->index >= USBVISION_SUPPORTED_PALETTES - 1)
Thierry MERLEc5f48362007-05-08 17:22:29 -0300804 return -EINVAL;
Mauro Carvalho Chehabcc1e6312018-09-10 16:20:42 -0400805 strscpy(vfd->description, usbvision_v4l2_format[vfd->index].desc,
806 sizeof(vfd->description));
Thierry MERLEc5f48362007-05-08 17:22:29 -0300807 vfd->pixelformat = usbvision_v4l2_format[vfd->index].format;
Thierry MERLEc5f48362007-05-08 17:22:29 -0300808 return 0;
809}
810
Hans Verkuil6d6a48e2010-12-29 13:53:21 -0300811static int vidioc_g_fmt_vid_cap(struct file *file, void *priv,
Thierry MERLEc5f48362007-05-08 17:22:29 -0300812 struct v4l2_format *vf)
813{
Hans Verkuilc170ecf2008-08-23 08:32:09 -0300814 struct usb_usbvision *usbvision = video_drvdata(file);
Thierry MERLEc5f48362007-05-08 17:22:29 -0300815 vf->fmt.pix.width = usbvision->curwidth;
816 vf->fmt.pix.height = usbvision->curheight;
817 vf->fmt.pix.pixelformat = usbvision->palette.format;
818 vf->fmt.pix.bytesperline =
Hans Verkuil6d6a48e2010-12-29 13:53:21 -0300819 usbvision->curwidth * usbvision->palette.bytes_per_pixel;
820 vf->fmt.pix.sizeimage = vf->fmt.pix.bytesperline * usbvision->curheight;
Thierry MERLEc5f48362007-05-08 17:22:29 -0300821 vf->fmt.pix.colorspace = V4L2_COLORSPACE_SMPTE170M;
822 vf->fmt.pix.field = V4L2_FIELD_NONE; /* Always progressive image */
823
824 return 0;
825}
826
Hans Verkuil6d6a48e2010-12-29 13:53:21 -0300827static int vidioc_try_fmt_vid_cap(struct file *file, void *priv,
Thierry MERLEc5f48362007-05-08 17:22:29 -0300828 struct v4l2_format *vf)
829{
Hans Verkuilc170ecf2008-08-23 08:32:09 -0300830 struct usb_usbvision *usbvision = video_drvdata(file);
Hans Verkuil5490a7c2010-12-19 20:21:36 -0300831 int format_idx;
Thierry MERLEc5f48362007-05-08 17:22:29 -0300832
833 /* Find requested format in available ones */
Hans Verkuil6d6a48e2010-12-29 13:53:21 -0300834 for (format_idx = 0; format_idx < USBVISION_SUPPORTED_PALETTES; format_idx++) {
835 if (vf->fmt.pix.pixelformat ==
Hans Verkuil5490a7c2010-12-19 20:21:36 -0300836 usbvision_v4l2_format[format_idx].format) {
837 usbvision->palette = usbvision_v4l2_format[format_idx];
Thierry MERLEc5f48362007-05-08 17:22:29 -0300838 break;
839 }
840 }
841 /* robustness */
Hans Verkuil6d6a48e2010-12-29 13:53:21 -0300842 if (format_idx == USBVISION_SUPPORTED_PALETTES)
Thierry MERLEc5f48362007-05-08 17:22:29 -0300843 return -EINVAL;
Thierry MERLEc5f48362007-05-08 17:22:29 -0300844 RESTRICT_TO_RANGE(vf->fmt.pix.width, MIN_FRAME_WIDTH, MAX_FRAME_WIDTH);
845 RESTRICT_TO_RANGE(vf->fmt.pix.height, MIN_FRAME_HEIGHT, MAX_FRAME_HEIGHT);
846
847 vf->fmt.pix.bytesperline = vf->fmt.pix.width*
848 usbvision->palette.bytes_per_pixel;
849 vf->fmt.pix.sizeimage = vf->fmt.pix.bytesperline*vf->fmt.pix.height;
Hans Verkuil4eeda6f2015-07-20 09:59:34 -0300850 vf->fmt.pix.colorspace = V4L2_COLORSPACE_SMPTE170M;
851 vf->fmt.pix.field = V4L2_FIELD_NONE; /* Always progressive image */
Thierry MERLEc5f48362007-05-08 17:22:29 -0300852
853 return 0;
854}
855
Hans Verkuil78b526a2008-05-28 12:16:41 -0300856static int vidioc_s_fmt_vid_cap(struct file *file, void *priv,
Thierry MERLEc5f48362007-05-08 17:22:29 -0300857 struct v4l2_format *vf)
858{
Hans Verkuilc170ecf2008-08-23 08:32:09 -0300859 struct usb_usbvision *usbvision = video_drvdata(file);
Thierry MERLEc5f48362007-05-08 17:22:29 -0300860 int ret;
861
Hans Verkuil6d6a48e2010-12-29 13:53:21 -0300862 ret = vidioc_try_fmt_vid_cap(file, priv, vf);
863 if (ret)
Thierry MERLEc5f48362007-05-08 17:22:29 -0300864 return ret;
Thierry MERLEc5f48362007-05-08 17:22:29 -0300865
866 /* stop io in case it is already in progress */
Hans Verkuil6d6a48e2010-12-29 13:53:21 -0300867 if (usbvision->streaming == stream_on) {
868 ret = usbvision_stream_interrupt(usbvision);
869 if (ret)
Thierry MERLEc5f48362007-05-08 17:22:29 -0300870 return ret;
871 }
872 usbvision_frames_free(usbvision);
873 usbvision_empty_framequeues(usbvision);
874
Hans Verkuil5490a7c2010-12-19 20:21:36 -0300875 usbvision->cur_frame = NULL;
Thierry MERLEc5f48362007-05-08 17:22:29 -0300876
877 /* by now we are committed to the new data... */
Thierry MERLEc5f48362007-05-08 17:22:29 -0300878 usbvision_set_output(usbvision, vf->fmt.pix.width, vf->fmt.pix.height);
Thierry MERLEc5f48362007-05-08 17:22:29 -0300879
880 return 0;
881}
Thierry MERLE483dfdb2006-12-04 08:31:45 -0300882
Hans Verkuil4d345702012-06-23 08:03:50 -0300883static ssize_t usbvision_read(struct file *file, char __user *buf,
Thierry MERLE483dfdb2006-12-04 08:31:45 -0300884 size_t count, loff_t *ppos)
885{
Hans Verkuilc170ecf2008-08-23 08:32:09 -0300886 struct usb_usbvision *usbvision = video_drvdata(file);
Thierry MERLE483dfdb2006-12-04 08:31:45 -0300887 int noblock = file->f_flags & O_NONBLOCK;
888 unsigned long lock_flags;
Hans Verkuil6d6a48e2010-12-29 13:53:21 -0300889 int ret, i;
Thierry MERLE483dfdb2006-12-04 08:31:45 -0300890 struct usbvision_frame *frame;
891
Harvey Harrisond2db42d2008-04-04 20:50:07 -0300892 PDEBUG(DBG_IO, "%s: %ld bytes, noblock=%d", __func__,
Thierry MERLEc5f48362007-05-08 17:22:29 -0300893 (unsigned long)count, noblock);
Thierry MERLE483dfdb2006-12-04 08:31:45 -0300894
Markus Elfringc4cdcf92017-08-26 16:16:52 -0400895 if (!USBVISION_IS_OPERATIONAL(usbvision) || !buf)
Thierry MERLE483dfdb2006-12-04 08:31:45 -0300896 return -EFAULT;
897
Thierry MERLEc5f48362007-05-08 17:22:29 -0300898 /* This entry point is compatible with the mmap routines
899 so that a user can do either VIDIOC_QBUF/VIDIOC_DQBUF
900 to get frames or call read on the device. */
Hans Verkuil6d6a48e2010-12-29 13:53:21 -0300901 if (!usbvision->num_frames) {
Thierry MERLEc5f48362007-05-08 17:22:29 -0300902 /* First, allocate some frames to work with
903 if this has not been done with VIDIOC_REQBUF */
Thierry MERLE6f78e182007-02-07 10:13:11 -0300904 usbvision_frames_free(usbvision);
905 usbvision_empty_framequeues(usbvision);
Hans Verkuil6d6a48e2010-12-29 13:53:21 -0300906 usbvision_frames_alloc(usbvision, USBVISION_NUMFRAMES);
Thierry MERLE6f78e182007-02-07 10:13:11 -0300907 }
Thierry MERLE483dfdb2006-12-04 08:31:45 -0300908
Hans Verkuil6d6a48e2010-12-29 13:53:21 -0300909 if (usbvision->streaming != stream_on) {
Thierry MERLE6f78e182007-02-07 10:13:11 -0300910 /* no stream is running, make it running ! */
Hans Verkuil5490a7c2010-12-19 20:21:36 -0300911 usbvision->streaming = stream_on;
Hans Verkuil1df79532009-02-21 18:11:31 -0300912 call_all(usbvision, video, s_stream, 1);
Thierry MERLE6f78e182007-02-07 10:13:11 -0300913 }
914
Thierry MERLEc5f48362007-05-08 17:22:29 -0300915 /* Then, enqueue as many frames as possible
916 (like a user of VIDIOC_QBUF would do) */
Hans Verkuil6d6a48e2010-12-29 13:53:21 -0300917 for (i = 0; i < usbvision->num_frames; i++) {
Thierry MERLE483dfdb2006-12-04 08:31:45 -0300918 frame = &usbvision->frame[i];
Hans Verkuil6d6a48e2010-12-29 13:53:21 -0300919 if (frame->grabstate == frame_state_unused) {
Thierry MERLE483dfdb2006-12-04 08:31:45 -0300920 /* Mark it as ready and enqueue frame */
Hans Verkuil5490a7c2010-12-19 20:21:36 -0300921 frame->grabstate = frame_state_ready;
922 frame->scanstate = scan_state_scanning;
Thierry MERLEc5f48362007-05-08 17:22:29 -0300923 /* Accumulated in usbvision_parse_data() */
924 frame->scanlength = 0;
Thierry MERLE483dfdb2006-12-04 08:31:45 -0300925
926 /* set v4l2_format index */
927 frame->v4l2_format = usbvision->palette;
928
929 spin_lock_irqsave(&usbvision->queue_lock, lock_flags);
930 list_add_tail(&frame->frame, &usbvision->inqueue);
Thierry MERLEc5f48362007-05-08 17:22:29 -0300931 spin_unlock_irqrestore(&usbvision->queue_lock,
932 lock_flags);
Thierry MERLE483dfdb2006-12-04 08:31:45 -0300933 }
934 }
935
936 /* Then try to steal a frame (like a VIDIOC_DQBUF would do) */
937 if (list_empty(&(usbvision->outqueue))) {
Hans Verkuil6d6a48e2010-12-29 13:53:21 -0300938 if (noblock)
Thierry MERLE483dfdb2006-12-04 08:31:45 -0300939 return -EAGAIN;
940
941 ret = wait_event_interruptible
942 (usbvision->wait_frame,
943 !list_empty(&(usbvision->outqueue)));
944 if (ret)
945 return ret;
946 }
947
948 spin_lock_irqsave(&usbvision->queue_lock, lock_flags);
949 frame = list_entry(usbvision->outqueue.next,
950 struct usbvision_frame, frame);
951 list_del(usbvision->outqueue.next);
952 spin_unlock_irqrestore(&usbvision->queue_lock, lock_flags);
953
954 /* An error returns an empty frame */
Hans Verkuil5490a7c2010-12-19 20:21:36 -0300955 if (frame->grabstate == frame_state_error) {
Thierry MERLE483dfdb2006-12-04 08:31:45 -0300956 frame->bytes_read = 0;
957 return 0;
958 }
959
Thierry MERLEc5f48362007-05-08 17:22:29 -0300960 PDEBUG(DBG_IO, "%s: frmx=%d, bytes_read=%ld, scanlength=%ld",
Harvey Harrisond2db42d2008-04-04 20:50:07 -0300961 __func__,
Thierry MERLEc5f48362007-05-08 17:22:29 -0300962 frame->index, frame->bytes_read, frame->scanlength);
Thierry MERLE483dfdb2006-12-04 08:31:45 -0300963
964 /* copy bytes to user space; we allow for partials reads */
965 if ((count + frame->bytes_read) > (unsigned long)frame->scanlength)
966 count = frame->scanlength - frame->bytes_read;
967
Hans Verkuil6d6a48e2010-12-29 13:53:21 -0300968 if (copy_to_user(buf, frame->data + frame->bytes_read, count))
Thierry MERLE483dfdb2006-12-04 08:31:45 -0300969 return -EFAULT;
Thierry MERLE483dfdb2006-12-04 08:31:45 -0300970
971 frame->bytes_read += count;
Thierry MERLEc5f48362007-05-08 17:22:29 -0300972 PDEBUG(DBG_IO, "%s: {copy} count used=%ld, new bytes_read=%ld",
Harvey Harrisond2db42d2008-04-04 20:50:07 -0300973 __func__,
Thierry MERLEc5f48362007-05-08 17:22:29 -0300974 (unsigned long)count, frame->bytes_read);
Thierry MERLE483dfdb2006-12-04 08:31:45 -0300975
Mauro Carvalho Chehabb295e5c2015-06-05 10:47:36 -0300976#if 1
977 /*
978 * FIXME:
979 * For now, forget the frame if it has not been read in one shot.
980 */
981 frame->bytes_read = 0;
982
983 /* Mark it as available to be used again. */
984 frame->grabstate = frame_state_unused;
985#else
986 if (frame->bytes_read >= frame->scanlength) {
987 /* All data has been read */
Thierry MERLE483dfdb2006-12-04 08:31:45 -0300988 frame->bytes_read = 0;
989
990 /* Mark it as available to be used again. */
Hans Verkuil5490a7c2010-12-19 20:21:36 -0300991 frame->grabstate = frame_state_unused;
Mauro Carvalho Chehabb295e5c2015-06-05 10:47:36 -0300992 }
993#endif
Thierry MERLE483dfdb2006-12-04 08:31:45 -0300994
995 return count;
996}
997
Hans Verkuil4d345702012-06-23 08:03:50 -0300998static ssize_t usbvision_v4l2_read(struct file *file, char __user *buf,
999 size_t count, loff_t *ppos)
1000{
1001 struct usb_usbvision *usbvision = video_drvdata(file);
1002 int res;
1003
1004 if (mutex_lock_interruptible(&usbvision->v4l2_lock))
1005 return -ERESTARTSYS;
1006 res = usbvision_read(file, buf, count, ppos);
1007 mutex_unlock(&usbvision->v4l2_lock);
1008 return res;
1009}
1010
1011static int usbvision_mmap(struct file *file, struct vm_area_struct *vma)
Thierry MERLE483dfdb2006-12-04 08:31:45 -03001012{
1013 unsigned long size = vma->vm_end - vma->vm_start,
1014 start = vma->vm_start;
1015 void *pos;
1016 u32 i;
Hans Verkuilc170ecf2008-08-23 08:32:09 -03001017 struct usb_usbvision *usbvision = video_drvdata(file);
Thierry MERLE483dfdb2006-12-04 08:31:45 -03001018
Thierry MERLE6f78e182007-02-07 10:13:11 -03001019 PDEBUG(DBG_MMAP, "mmap");
1020
Hans Verkuil6d6a48e2010-12-29 13:53:21 -03001021 if (!USBVISION_IS_OPERATIONAL(usbvision))
Thierry MERLE483dfdb2006-12-04 08:31:45 -03001022 return -EFAULT;
Thierry MERLE483dfdb2006-12-04 08:31:45 -03001023
1024 if (!(vma->vm_flags & VM_WRITE) ||
Thierry MERLE6f78e182007-02-07 10:13:11 -03001025 size != PAGE_ALIGN(usbvision->max_frame_size)) {
Thierry MERLE483dfdb2006-12-04 08:31:45 -03001026 return -EINVAL;
1027 }
1028
Thierry MERLE6f78e182007-02-07 10:13:11 -03001029 for (i = 0; i < usbvision->num_frames; i++) {
Thierry MERLEc5f48362007-05-08 17:22:29 -03001030 if (((PAGE_ALIGN(usbvision->max_frame_size)*i) >> PAGE_SHIFT) ==
1031 vma->vm_pgoff)
Thierry MERLE483dfdb2006-12-04 08:31:45 -03001032 break;
1033 }
Thierry MERLE6f78e182007-02-07 10:13:11 -03001034 if (i == usbvision->num_frames) {
Thierry MERLEc5f48362007-05-08 17:22:29 -03001035 PDEBUG(DBG_MMAP,
1036 "mmap: user supplied mapping address is out of range");
Thierry MERLE483dfdb2006-12-04 08:31:45 -03001037 return -EINVAL;
1038 }
1039
1040 /* VM_IO is eventually going to replace PageReserved altogether */
Konstantin Khlebnikov314e51b2012-10-08 16:29:02 -07001041 vma->vm_flags |= VM_IO | VM_DONTEXPAND | VM_DONTDUMP;
Thierry MERLE483dfdb2006-12-04 08:31:45 -03001042
1043 pos = usbvision->frame[i].data;
1044 while (size > 0) {
Thierry MERLE483dfdb2006-12-04 08:31:45 -03001045 if (vm_insert_page(vma, start, vmalloc_to_page(pos))) {
Thierry MERLEc876a342006-12-09 16:42:54 -03001046 PDEBUG(DBG_MMAP, "mmap: vm_insert_page failed");
Thierry MERLE483dfdb2006-12-04 08:31:45 -03001047 return -EAGAIN;
1048 }
1049 start += PAGE_SIZE;
1050 pos += PAGE_SIZE;
1051 size -= PAGE_SIZE;
1052 }
1053
Thierry MERLE483dfdb2006-12-04 08:31:45 -03001054 return 0;
1055}
1056
Hans Verkuil4d345702012-06-23 08:03:50 -03001057static int usbvision_v4l2_mmap(struct file *file, struct vm_area_struct *vma)
1058{
1059 struct usb_usbvision *usbvision = video_drvdata(file);
1060 int res;
1061
1062 if (mutex_lock_interruptible(&usbvision->v4l2_lock))
1063 return -ERESTARTSYS;
1064 res = usbvision_mmap(file, vma);
1065 mutex_unlock(&usbvision->v4l2_lock);
1066 return res;
1067}
Thierry MERLE483dfdb2006-12-04 08:31:45 -03001068
1069/*
1070 * Here comes the stuff for radio on usbvision based devices
1071 *
1072 */
Hans Verkuilbec43662008-12-30 06:58:20 -03001073static int usbvision_radio_open(struct file *file)
Thierry MERLE483dfdb2006-12-04 08:31:45 -03001074{
Hans Verkuilc170ecf2008-08-23 08:32:09 -03001075 struct usb_usbvision *usbvision = video_drvdata(file);
Hans Verkuil5490a7c2010-12-19 20:21:36 -03001076 int err_code = 0;
Thierry MERLE483dfdb2006-12-04 08:31:45 -03001077
Harvey Harrisond2db42d2008-04-04 20:50:07 -03001078 PDEBUG(DBG_IO, "%s:", __func__);
Thierry MERLE483dfdb2006-12-04 08:31:45 -03001079
Hans Verkuil4d345702012-06-23 08:03:50 -03001080 if (mutex_lock_interruptible(&usbvision->v4l2_lock))
1081 return -ERESTARTSYS;
Hans Verkuilfd958702015-07-20 09:59:29 -03001082 err_code = v4l2_fh_open(file);
1083 if (err_code)
1084 goto out;
Thierry MERLE483dfdb2006-12-04 08:31:45 -03001085 if (usbvision->user) {
Hans Verkuil2aa689d2015-03-09 13:34:12 -03001086 dev_err(&usbvision->rdev.dev,
Mauro Carvalho Chehabbe9ed512009-01-08 09:13:42 -03001087 "%s: Someone tried to open an already opened USBVision Radio!\n",
1088 __func__);
Hans Verkuil5490a7c2010-12-19 20:21:36 -03001089 err_code = -EBUSY;
Hans Verkuil6d6a48e2010-12-29 13:53:21 -03001090 } else {
Thierry MERLE2a9f8b52007-02-07 10:14:38 -03001091 /* Alternate interface 1 is is the biggest frame size */
Hans Verkuil5490a7c2010-12-19 20:21:36 -03001092 err_code = usbvision_set_alternate(usbvision);
1093 if (err_code < 0) {
1094 usbvision->last_error = err_code;
1095 err_code = -EBUSY;
Andrew Morton544e6172007-12-12 18:25:23 -03001096 goto out;
Thierry MERLE2a9f8b52007-02-07 10:14:38 -03001097 }
1098
Hans Verkuil52cb0bf22010-12-19 20:33:51 -03001099 /* If so far no errors then we shall start the radio */
Thierry MERLE483dfdb2006-12-04 08:31:45 -03001100 usbvision->radio = 1;
Hans Verkuil1df79532009-02-21 18:11:31 -03001101 call_all(usbvision, tuner, s_radio);
Thierry MERLE483dfdb2006-12-04 08:31:45 -03001102 usbvision_set_audio(usbvision, USBVISION_AUDIO_RADIO);
1103 usbvision->user++;
1104 }
Andrew Morton544e6172007-12-12 18:25:23 -03001105out:
Hans Verkuil4d345702012-06-23 08:03:50 -03001106 mutex_unlock(&usbvision->v4l2_lock);
Hans Verkuil5490a7c2010-12-19 20:21:36 -03001107 return err_code;
Thierry MERLE483dfdb2006-12-04 08:31:45 -03001108}
1109
1110
Hans Verkuilbec43662008-12-30 06:58:20 -03001111static int usbvision_radio_close(struct file *file)
Thierry MERLE483dfdb2006-12-04 08:31:45 -03001112{
Hans Verkuilc170ecf2008-08-23 08:32:09 -03001113 struct usb_usbvision *usbvision = video_drvdata(file);
Thierry MERLE483dfdb2006-12-04 08:31:45 -03001114
1115 PDEBUG(DBG_IO, "");
1116
Hans Verkuil4d345702012-06-23 08:03:50 -03001117 mutex_lock(&usbvision->v4l2_lock);
Thierry MERLE2a9f8b52007-02-07 10:14:38 -03001118 /* Set packet size to 0 */
Hans Verkuil6d6a48e2010-12-29 13:53:21 -03001119 usbvision->iface_alt = 0;
Hans Verkuilfd958702015-07-20 09:59:29 -03001120 usb_set_interface(usbvision->dev, usbvision->iface,
Hans Verkuil5490a7c2010-12-19 20:21:36 -03001121 usbvision->iface_alt);
Thierry MERLE2a9f8b52007-02-07 10:14:38 -03001122
Thierry MERLE483dfdb2006-12-04 08:31:45 -03001123 usbvision_audio_off(usbvision);
Hans Verkuil6d6a48e2010-12-29 13:53:21 -03001124 usbvision->radio = 0;
Thierry MERLE483dfdb2006-12-04 08:31:45 -03001125 usbvision->user--;
Insu Yun5ce625a2016-02-01 13:59:30 -02001126 mutex_unlock(&usbvision->v4l2_lock);
Thierry MERLE483dfdb2006-12-04 08:31:45 -03001127
Thierry MERLE483dfdb2006-12-04 08:31:45 -03001128 if (usbvision->remove_pending) {
Harvey Harrisond2db42d2008-04-04 20:50:07 -03001129 printk(KERN_INFO "%s: Final disconnect\n", __func__);
Hans Verkuilfd958702015-07-20 09:59:29 -03001130 v4l2_fh_release(file);
Thierry MERLE483dfdb2006-12-04 08:31:45 -03001131 usbvision_release(usbvision);
Hans Verkuilfd958702015-07-20 09:59:29 -03001132 return 0;
Thierry MERLE483dfdb2006-12-04 08:31:45 -03001133 }
1134
Thierry MERLE483dfdb2006-12-04 08:31:45 -03001135 PDEBUG(DBG_IO, "success");
Hans Verkuilfd958702015-07-20 09:59:29 -03001136 return v4l2_fh_release(file);
Thierry MERLE483dfdb2006-12-04 08:31:45 -03001137}
1138
Hans Verkuil52cb0bf22010-12-19 20:33:51 -03001139/* Video registration stuff */
Thierry MERLE483dfdb2006-12-04 08:31:45 -03001140
Hans Verkuil52cb0bf22010-12-19 20:33:51 -03001141/* Video template */
Hans Verkuilbec43662008-12-30 06:58:20 -03001142static const struct v4l2_file_operations usbvision_fops = {
Thierry MERLE483dfdb2006-12-04 08:31:45 -03001143 .owner = THIS_MODULE,
Thierry MERLE483dfdb2006-12-04 08:31:45 -03001144 .open = usbvision_v4l2_open,
1145 .release = usbvision_v4l2_close,
1146 .read = usbvision_v4l2_read,
1147 .mmap = usbvision_v4l2_mmap,
Hans Verkuilc627b9d2010-12-18 11:06:09 -03001148 .unlocked_ioctl = video_ioctl2,
Thierry MERLE483dfdb2006-12-04 08:31:45 -03001149};
Hans Verkuila3998102008-07-21 02:57:38 -03001150
1151static const struct v4l2_ioctl_ops usbvision_ioctl_ops = {
Thierry MERLEc5f48362007-05-08 17:22:29 -03001152 .vidioc_querycap = vidioc_querycap,
Hans Verkuil78b526a2008-05-28 12:16:41 -03001153 .vidioc_enum_fmt_vid_cap = vidioc_enum_fmt_vid_cap,
1154 .vidioc_g_fmt_vid_cap = vidioc_g_fmt_vid_cap,
1155 .vidioc_try_fmt_vid_cap = vidioc_try_fmt_vid_cap,
1156 .vidioc_s_fmt_vid_cap = vidioc_s_fmt_vid_cap,
Thierry MERLEc5f48362007-05-08 17:22:29 -03001157 .vidioc_reqbufs = vidioc_reqbufs,
1158 .vidioc_querybuf = vidioc_querybuf,
1159 .vidioc_qbuf = vidioc_qbuf,
1160 .vidioc_dqbuf = vidioc_dqbuf,
1161 .vidioc_s_std = vidioc_s_std,
Hans Verkuil3b8436d2013-06-03 05:36:47 -03001162 .vidioc_g_std = vidioc_g_std,
Thierry MERLEc5f48362007-05-08 17:22:29 -03001163 .vidioc_enum_input = vidioc_enum_input,
1164 .vidioc_g_input = vidioc_g_input,
1165 .vidioc_s_input = vidioc_s_input,
Thierry MERLEc5f48362007-05-08 17:22:29 -03001166 .vidioc_streamon = vidioc_streamon,
1167 .vidioc_streamoff = vidioc_streamoff,
Thierry MERLEc5f48362007-05-08 17:22:29 -03001168 .vidioc_g_tuner = vidioc_g_tuner,
1169 .vidioc_s_tuner = vidioc_s_tuner,
1170 .vidioc_g_frequency = vidioc_g_frequency,
1171 .vidioc_s_frequency = vidioc_s_frequency,
Hans Verkuilfd958702015-07-20 09:59:29 -03001172 .vidioc_log_status = v4l2_ctrl_log_status,
1173 .vidioc_subscribe_event = v4l2_ctrl_subscribe_event,
1174 .vidioc_unsubscribe_event = v4l2_event_unsubscribe,
Thierry MERLEc5f48362007-05-08 17:22:29 -03001175#ifdef CONFIG_VIDEO_ADV_DEBUG
1176 .vidioc_g_register = vidioc_g_register,
1177 .vidioc_s_register = vidioc_s_register,
1178#endif
Hans Verkuila3998102008-07-21 02:57:38 -03001179};
1180
1181static struct video_device usbvision_video_template = {
Hans Verkuila3998102008-07-21 02:57:38 -03001182 .fops = &usbvision_fops,
Hans Verkuil6d6a48e2010-12-29 13:53:21 -03001183 .ioctl_ops = &usbvision_ioctl_ops,
Hans Verkuila3998102008-07-21 02:57:38 -03001184 .name = "usbvision-video",
Hans Verkuil2aa689d2015-03-09 13:34:12 -03001185 .release = video_device_release_empty,
Hans Verkuil6d6a48e2010-12-29 13:53:21 -03001186 .tvnorms = USBVISION_NORMS,
Thierry MERLE483dfdb2006-12-04 08:31:45 -03001187};
1188
1189
Hans Verkuil52cb0bf22010-12-19 20:33:51 -03001190/* Radio template */
Hans Verkuilbec43662008-12-30 06:58:20 -03001191static const struct v4l2_file_operations usbvision_radio_fops = {
Thierry MERLE483dfdb2006-12-04 08:31:45 -03001192 .owner = THIS_MODULE,
Thierry MERLE483dfdb2006-12-04 08:31:45 -03001193 .open = usbvision_radio_open,
1194 .release = usbvision_radio_close,
Hans Verkuilfd958702015-07-20 09:59:29 -03001195 .poll = v4l2_ctrl_poll,
Hans Verkuilc627b9d2010-12-18 11:06:09 -03001196 .unlocked_ioctl = video_ioctl2,
Thierry MERLE483dfdb2006-12-04 08:31:45 -03001197};
1198
Hans Verkuila3998102008-07-21 02:57:38 -03001199static const struct v4l2_ioctl_ops usbvision_radio_ioctl_ops = {
Thierry MERLEc5f48362007-05-08 17:22:29 -03001200 .vidioc_querycap = vidioc_querycap,
Thierry MERLEc5f48362007-05-08 17:22:29 -03001201 .vidioc_g_tuner = vidioc_g_tuner,
1202 .vidioc_s_tuner = vidioc_s_tuner,
1203 .vidioc_g_frequency = vidioc_g_frequency,
1204 .vidioc_s_frequency = vidioc_s_frequency,
Hans Verkuilfd958702015-07-20 09:59:29 -03001205 .vidioc_log_status = v4l2_ctrl_log_status,
1206 .vidioc_subscribe_event = v4l2_ctrl_subscribe_event,
1207 .vidioc_unsubscribe_event = v4l2_event_unsubscribe,
Hans Verkuila3998102008-07-21 02:57:38 -03001208};
1209
1210static struct video_device usbvision_radio_template = {
Hans Verkuila3998102008-07-21 02:57:38 -03001211 .fops = &usbvision_radio_fops,
Hans Verkuil6d6a48e2010-12-29 13:53:21 -03001212 .name = "usbvision-radio",
Hans Verkuil2aa689d2015-03-09 13:34:12 -03001213 .release = video_device_release_empty,
Hans Verkuil6d6a48e2010-12-29 13:53:21 -03001214 .ioctl_ops = &usbvision_radio_ioctl_ops,
Thierry MERLEc5f48362007-05-08 17:22:29 -03001215};
Thierry MERLE483dfdb2006-12-04 08:31:45 -03001216
Thierry MERLE483dfdb2006-12-04 08:31:45 -03001217
Hans Verkuil2aa689d2015-03-09 13:34:12 -03001218static void usbvision_vdev_init(struct usb_usbvision *usbvision,
1219 struct video_device *vdev,
1220 const struct video_device *vdev_template,
1221 const char *name)
Thierry MERLE483dfdb2006-12-04 08:31:45 -03001222{
1223 struct usb_device *usb_dev = usbvision->dev;
Thierry MERLE483dfdb2006-12-04 08:31:45 -03001224
Markus Elfringc4cdcf92017-08-26 16:16:52 -04001225 if (!usb_dev) {
Mauro Carvalho Chehabbe9ed512009-01-08 09:13:42 -03001226 dev_err(&usbvision->dev->dev,
1227 "%s: usbvision->dev is not set\n", __func__);
Hans Verkuil2aa689d2015-03-09 13:34:12 -03001228 return;
Thierry MERLE483dfdb2006-12-04 08:31:45 -03001229 }
1230
Thierry MERLE483dfdb2006-12-04 08:31:45 -03001231 *vdev = *vdev_template;
Hans Verkuilc627b9d2010-12-18 11:06:09 -03001232 vdev->lock = &usbvision->v4l2_lock;
Hans Verkuil1df79532009-02-21 18:11:31 -03001233 vdev->v4l2_dev = &usbvision->v4l2_dev;
Thierry MERLE483dfdb2006-12-04 08:31:45 -03001234 snprintf(vdev->name, sizeof(vdev->name), "%s", name);
1235 video_set_drvdata(vdev, usbvision);
Thierry MERLE483dfdb2006-12-04 08:31:45 -03001236}
1237
Hans Verkuil52cb0bf22010-12-19 20:33:51 -03001238/* unregister video4linux devices */
Thierry MERLE483dfdb2006-12-04 08:31:45 -03001239static void usbvision_unregister_video(struct usb_usbvision *usbvision)
1240{
Hans Verkuil52cb0bf22010-12-19 20:33:51 -03001241 /* Radio Device: */
Hans Verkuil2aa689d2015-03-09 13:34:12 -03001242 if (video_is_registered(&usbvision->rdev)) {
Laurent Pinchart38c7c032009-11-27 13:57:15 -03001243 PDEBUG(DBG_PROBE, "unregister %s [v4l2]",
Hans Verkuil2aa689d2015-03-09 13:34:12 -03001244 video_device_node_name(&usbvision->rdev));
1245 video_unregister_device(&usbvision->rdev);
Thierry MERLE483dfdb2006-12-04 08:31:45 -03001246 }
1247
Hans Verkuil52cb0bf22010-12-19 20:33:51 -03001248 /* Video Device: */
Hans Verkuil2aa689d2015-03-09 13:34:12 -03001249 if (video_is_registered(&usbvision->vdev)) {
Laurent Pinchart38c7c032009-11-27 13:57:15 -03001250 PDEBUG(DBG_PROBE, "unregister %s [v4l2]",
Hans Verkuil2aa689d2015-03-09 13:34:12 -03001251 video_device_node_name(&usbvision->vdev));
1252 video_unregister_device(&usbvision->vdev);
Thierry MERLE483dfdb2006-12-04 08:31:45 -03001253 }
1254}
1255
Hans Verkuil52cb0bf22010-12-19 20:33:51 -03001256/* register video4linux devices */
Greg Kroah-Hartman4c62e972012-12-21 13:17:53 -08001257static int usbvision_register_video(struct usb_usbvision *usbvision)
Thierry MERLE483dfdb2006-12-04 08:31:45 -03001258{
Hans Verkuil2b436652015-07-20 09:59:30 -03001259 int res = -ENOMEM;
1260
Hans Verkuil52cb0bf22010-12-19 20:33:51 -03001261 /* Video Device: */
Hans Verkuil2aa689d2015-03-09 13:34:12 -03001262 usbvision_vdev_init(usbvision, &usbvision->vdev,
1263 &usbvision_video_template, "USBVision Video");
Hans Verkuil64d416e2015-07-20 09:59:33 -03001264 if (!usbvision->have_tuner) {
1265 v4l2_disable_ioctl(&usbvision->vdev, VIDIOC_G_FREQUENCY);
1266 v4l2_disable_ioctl(&usbvision->vdev, VIDIOC_S_TUNER);
1267 v4l2_disable_ioctl(&usbvision->vdev, VIDIOC_G_FREQUENCY);
1268 v4l2_disable_ioctl(&usbvision->vdev, VIDIOC_S_TUNER);
1269 }
Hans Verkuil2aa689d2015-03-09 13:34:12 -03001270 if (video_register_device(&usbvision->vdev, VFL_TYPE_GRABBER, video_nr) < 0)
Thierry MERLE483dfdb2006-12-04 08:31:45 -03001271 goto err_exit;
Laurent Pinchart38c7c032009-11-27 13:57:15 -03001272 printk(KERN_INFO "USBVision[%d]: registered USBVision Video device %s [v4l2]\n",
Hans Verkuil2aa689d2015-03-09 13:34:12 -03001273 usbvision->nr, video_device_node_name(&usbvision->vdev));
Thierry MERLE483dfdb2006-12-04 08:31:45 -03001274
Hans Verkuil52cb0bf22010-12-19 20:33:51 -03001275 /* Radio Device: */
Hans Verkuil5490a7c2010-12-19 20:21:36 -03001276 if (usbvision_device_data[usbvision->dev_model].radio) {
Hans Verkuil52cb0bf22010-12-19 20:33:51 -03001277 /* usbvision has radio */
Hans Verkuil2aa689d2015-03-09 13:34:12 -03001278 usbvision_vdev_init(usbvision, &usbvision->rdev,
1279 &usbvision_radio_template, "USBVision Radio");
1280 if (video_register_device(&usbvision->rdev, VFL_TYPE_RADIO, radio_nr) < 0)
Thierry MERLE483dfdb2006-12-04 08:31:45 -03001281 goto err_exit;
Laurent Pinchart38c7c032009-11-27 13:57:15 -03001282 printk(KERN_INFO "USBVision[%d]: registered USBVision Radio device %s [v4l2]\n",
Hans Verkuil2aa689d2015-03-09 13:34:12 -03001283 usbvision->nr, video_device_node_name(&usbvision->rdev));
Thierry MERLE483dfdb2006-12-04 08:31:45 -03001284 }
Hans Verkuil52cb0bf22010-12-19 20:33:51 -03001285 /* all done */
Thierry MERLE483dfdb2006-12-04 08:31:45 -03001286 return 0;
1287
1288 err_exit:
Mauro Carvalho Chehabbe9ed512009-01-08 09:13:42 -03001289 dev_err(&usbvision->dev->dev,
1290 "USBVision[%d]: video_register_device() failed\n",
1291 usbvision->nr);
Thierry MERLE483dfdb2006-12-04 08:31:45 -03001292 usbvision_unregister_video(usbvision);
Hans Verkuil2b436652015-07-20 09:59:30 -03001293 return res;
Thierry MERLE483dfdb2006-12-04 08:31:45 -03001294}
1295
1296/*
1297 * usbvision_alloc()
1298 *
Thierry MERLEc5f48362007-05-08 17:22:29 -03001299 * This code allocates the struct usb_usbvision.
1300 * It is filled with default values.
Thierry MERLE483dfdb2006-12-04 08:31:45 -03001301 *
1302 * Returns NULL on error, a pointer to usb_usbvision else.
1303 *
1304 */
Janne Grunaua8784402009-04-01 08:46:00 -03001305static struct usb_usbvision *usbvision_alloc(struct usb_device *dev,
1306 struct usb_interface *intf)
Thierry MERLE483dfdb2006-12-04 08:31:45 -03001307{
1308 struct usb_usbvision *usbvision;
1309
Markus Elfring1fbfd8c2017-08-26 16:22:13 -04001310 usbvision = kzalloc(sizeof(*usbvision), GFP_KERNEL);
Markus Elfringc4cdcf92017-08-26 16:16:52 -04001311 if (!usbvision)
Hans Verkuil1df79532009-02-21 18:11:31 -03001312 return NULL;
Thierry MERLE483dfdb2006-12-04 08:31:45 -03001313
1314 usbvision->dev = dev;
Janne Grunaua8784402009-04-01 08:46:00 -03001315 if (v4l2_device_register(&intf->dev, &usbvision->v4l2_dev))
Hans Verkuil1df79532009-02-21 18:11:31 -03001316 goto err_free;
Thierry MERLE483dfdb2006-12-04 08:31:45 -03001317
Hans Verkuilfd958702015-07-20 09:59:29 -03001318 if (v4l2_ctrl_handler_init(&usbvision->hdl, 4))
1319 goto err_unreg;
1320 usbvision->v4l2_dev.ctrl_handler = &usbvision->hdl;
Hans Verkuilc627b9d2010-12-18 11:06:09 -03001321 mutex_init(&usbvision->v4l2_lock);
Thierry MERLE483dfdb2006-12-04 08:31:45 -03001322
Hans Verkuil52cb0bf22010-12-19 20:33:51 -03001323 /* prepare control urb for control messages during interrupts */
Hans Verkuil5490a7c2010-12-19 20:21:36 -03001324 usbvision->ctrl_urb = usb_alloc_urb(USBVISION_URB_FRAMES, GFP_KERNEL);
Markus Elfringc4cdcf92017-08-26 16:16:52 -04001325 if (!usbvision->ctrl_urb)
Hans Verkuil1df79532009-02-21 18:11:31 -03001326 goto err_unreg;
Thierry MERLE483dfdb2006-12-04 08:31:45 -03001327
Thierry MERLE483dfdb2006-12-04 08:31:45 -03001328 return usbvision;
1329
Hans Verkuil1df79532009-02-21 18:11:31 -03001330err_unreg:
Hans Verkuilfd958702015-07-20 09:59:29 -03001331 v4l2_ctrl_handler_free(&usbvision->hdl);
Hans Verkuil1df79532009-02-21 18:11:31 -03001332 v4l2_device_unregister(&usbvision->v4l2_dev);
1333err_free:
1334 kfree(usbvision);
Thierry MERLE483dfdb2006-12-04 08:31:45 -03001335 return NULL;
1336}
1337
1338/*
1339 * usbvision_release()
1340 *
1341 * This code does final release of struct usb_usbvision. This happens
1342 * after the device is disconnected -and- all clients closed their files.
1343 *
1344 */
1345static void usbvision_release(struct usb_usbvision *usbvision)
1346{
1347 PDEBUG(DBG_PROBE, "");
1348
Thierry MERLE483dfdb2006-12-04 08:31:45 -03001349 usbvision->initialized = 0;
1350
Hans Verkuil2aa689d2015-03-09 13:34:12 -03001351 usbvision_remove_sysfs(&usbvision->vdev);
Thierry MERLE483dfdb2006-12-04 08:31:45 -03001352 usbvision_unregister_video(usbvision);
Alexey Khoroshilov090c65b2013-06-10 17:32:29 -03001353 kfree(usbvision->alt_max_pkt_size);
Thierry MERLE483dfdb2006-12-04 08:31:45 -03001354
Hans Verkuil6d6a48e2010-12-29 13:53:21 -03001355 usb_free_urb(usbvision->ctrl_urb);
Thierry MERLE483dfdb2006-12-04 08:31:45 -03001356
Hans Verkuilfd958702015-07-20 09:59:29 -03001357 v4l2_ctrl_handler_free(&usbvision->hdl);
Hans Verkuil1df79532009-02-21 18:11:31 -03001358 v4l2_device_unregister(&usbvision->v4l2_dev);
Thierry MERLE483dfdb2006-12-04 08:31:45 -03001359 kfree(usbvision);
1360
1361 PDEBUG(DBG_PROBE, "success");
1362}
1363
1364
Thierry MERLEc5f48362007-05-08 17:22:29 -03001365/*********************** usb interface **********************************/
Thierry MERLE483dfdb2006-12-04 08:31:45 -03001366
1367static void usbvision_configure_video(struct usb_usbvision *usbvision)
1368{
Thierry MERLEc5f48362007-05-08 17:22:29 -03001369 int model;
Thierry MERLE483dfdb2006-12-04 08:31:45 -03001370
Markus Elfringc4cdcf92017-08-26 16:16:52 -04001371 if (!usbvision)
Thierry MERLE483dfdb2006-12-04 08:31:45 -03001372 return;
1373
Hans Verkuil5490a7c2010-12-19 20:21:36 -03001374 model = usbvision->dev_model;
Hans Verkuil52cb0bf22010-12-19 20:33:51 -03001375 usbvision->palette = usbvision_v4l2_format[2]; /* V4L2_PIX_FMT_RGB24; */
Thierry MERLE483dfdb2006-12-04 08:31:45 -03001376
Hans Verkuil5490a7c2010-12-19 20:21:36 -03001377 if (usbvision_device_data[usbvision->dev_model].vin_reg2_override) {
1378 usbvision->vin_reg2_preset =
1379 usbvision_device_data[usbvision->dev_model].vin_reg2;
Thierry MERLE483dfdb2006-12-04 08:31:45 -03001380 } else {
Hans Verkuil5490a7c2010-12-19 20:21:36 -03001381 usbvision->vin_reg2_preset = 0;
Thierry MERLE483dfdb2006-12-04 08:31:45 -03001382 }
1383
Hans Verkuil5490a7c2010-12-19 20:21:36 -03001384 usbvision->tvnorm_id = usbvision_device_data[model].video_norm;
Hans Verkuil5490a7c2010-12-19 20:21:36 -03001385 usbvision->video_inputs = usbvision_device_data[model].video_channels;
Thierry MERLE483dfdb2006-12-04 08:31:45 -03001386 usbvision->ctl_input = 0;
Hans Verkuil64d416e2015-07-20 09:59:33 -03001387 usbvision->radio_freq = 87.5 * 16000;
1388 usbvision->tv_freq = 400 * 16;
Thierry MERLE483dfdb2006-12-04 08:31:45 -03001389
1390 /* This should be here to make i2c clients to be able to register */
Thierry MERLEc5f48362007-05-08 17:22:29 -03001391 /* first switch off audio */
Ondrej Zary240d57b2011-04-27 17:36:05 -03001392 if (usbvision_device_data[model].audio_channels > 0)
1393 usbvision_audio_off(usbvision);
Hans Verkuil62e25942015-07-20 09:59:28 -03001394 /* and then power up the tuner */
1395 usbvision_power_on(usbvision);
1396 usbvision_i2c_register(usbvision);
Thierry MERLE483dfdb2006-12-04 08:31:45 -03001397}
1398
1399/*
1400 * usbvision_probe()
1401 *
1402 * This procedure queries device descriptor and accepts the interface
1403 * if it looks like USBVISION video device
1404 *
1405 */
Greg Kroah-Hartman4c62e972012-12-21 13:17:53 -08001406static int usbvision_probe(struct usb_interface *intf,
1407 const struct usb_device_id *devid)
Thierry MERLE483dfdb2006-12-04 08:31:45 -03001408{
Thierry MERLE2a9f8b52007-02-07 10:14:38 -03001409 struct usb_device *dev = usb_get_dev(interface_to_usbdev(intf));
1410 struct usb_interface *uif;
Thierry MERLE483dfdb2006-12-04 08:31:45 -03001411 __u8 ifnum = intf->altsetting->desc.bInterfaceNumber;
1412 const struct usb_host_interface *interface;
1413 struct usb_usbvision *usbvision = NULL;
1414 const struct usb_endpoint_descriptor *endpoint;
Alexey Khoroshilovafd270d2015-03-27 19:39:09 -03001415 int model, i, ret;
Thierry MERLE483dfdb2006-12-04 08:31:45 -03001416
1417 PDEBUG(DBG_PROBE, "VID=%#04x, PID=%#04x, ifnum=%u",
Johan Hovoldab64a582017-05-12 07:01:30 -03001418 le16_to_cpu(dev->descriptor.idVendor),
1419 le16_to_cpu(dev->descriptor.idProduct), ifnum);
Thierry MERLE2a9f8b52007-02-07 10:14:38 -03001420
Mauro Carvalho Chehab659ae562007-04-14 15:09:59 -03001421 model = devid->driver_info;
Hans Verkuil6d6a48e2010-12-29 13:53:21 -03001422 if (model < 0 || model >= usbvision_device_data_size) {
1423 PDEBUG(DBG_PROBE, "model out of bounds %d", model);
Alexey Khoroshilovafd270d2015-03-27 19:39:09 -03001424 ret = -ENODEV;
1425 goto err_usb;
Mauro Carvalho Chehabf8a389d2007-04-14 15:17:35 -03001426 }
Harvey Harrisond2db42d2008-04-04 20:50:07 -03001427 printk(KERN_INFO "%s: %s found\n", __func__,
Hans Verkuil5490a7c2010-12-19 20:21:36 -03001428 usbvision_device_data[model].model_string);
Thierry MERLE483dfdb2006-12-04 08:31:45 -03001429
Hans Verkuil6d6a48e2010-12-29 13:53:21 -03001430 if (usbvision_device_data[model].interface >= 0)
Hans Verkuil5490a7c2010-12-19 20:21:36 -03001431 interface = &dev->actconfig->interface[usbvision_device_data[model].interface]->altsetting[0];
Vladis Dronovfa52bd502015-11-16 15:55:11 -02001432 else if (ifnum < dev->actconfig->desc.bNumInterfaces)
Thierry MERLE483dfdb2006-12-04 08:31:45 -03001433 interface = &dev->actconfig->interface[ifnum]->altsetting[0];
Vladis Dronovfa52bd502015-11-16 15:55:11 -02001434 else {
1435 dev_err(&intf->dev, "interface %d is invalid, max is %d\n",
1436 ifnum, dev->actconfig->desc.bNumInterfaces - 1);
1437 ret = -ENODEV;
1438 goto err_usb;
1439 }
1440
1441 if (interface->desc.bNumEndpoints < 2) {
Mauro Carvalho Chehab02c539d2016-10-18 17:44:21 -02001442 dev_err(&intf->dev, "interface %d has %d endpoints, but must have minimum 2\n",
1443 ifnum, interface->desc.bNumEndpoints);
Vladis Dronovfa52bd502015-11-16 15:55:11 -02001444 ret = -ENODEV;
1445 goto err_usb;
1446 }
Thierry MERLE483dfdb2006-12-04 08:31:45 -03001447 endpoint = &interface->endpoint[1].desc;
Vladis Dronovfa52bd502015-11-16 15:55:11 -02001448
Julia Lawall2230c3c2009-01-03 16:53:10 -03001449 if (!usb_endpoint_xfer_isoc(endpoint)) {
Mauro Carvalho Chehabbe9ed512009-01-08 09:13:42 -03001450 dev_err(&intf->dev, "%s: interface %d. has non-ISO endpoint!\n",
Harvey Harrisond2db42d2008-04-04 20:50:07 -03001451 __func__, ifnum);
Mauro Carvalho Chehabbe9ed512009-01-08 09:13:42 -03001452 dev_err(&intf->dev, "%s: Endpoint attributes %d",
Harvey Harrisond2db42d2008-04-04 20:50:07 -03001453 __func__, endpoint->bmAttributes);
Alexey Khoroshilovafd270d2015-03-27 19:39:09 -03001454 ret = -ENODEV;
1455 goto err_usb;
Thierry MERLE483dfdb2006-12-04 08:31:45 -03001456 }
Julia Lawall13417982008-12-29 21:49:22 -03001457 if (usb_endpoint_dir_out(endpoint)) {
Mauro Carvalho Chehabbe9ed512009-01-08 09:13:42 -03001458 dev_err(&intf->dev, "%s: interface %d. has ISO OUT endpoint!\n",
Harvey Harrisond2db42d2008-04-04 20:50:07 -03001459 __func__, ifnum);
Alexey Khoroshilovafd270d2015-03-27 19:39:09 -03001460 ret = -ENODEV;
1461 goto err_usb;
Thierry MERLE483dfdb2006-12-04 08:31:45 -03001462 }
1463
Janne Grunaua8784402009-04-01 08:46:00 -03001464 usbvision = usbvision_alloc(dev, intf);
Markus Elfringc4cdcf92017-08-26 16:16:52 -04001465 if (!usbvision) {
Mauro Carvalho Chehabbe9ed512009-01-08 09:13:42 -03001466 dev_err(&intf->dev, "%s: couldn't allocate USBVision struct\n", __func__);
Alexey Khoroshilovafd270d2015-03-27 19:39:09 -03001467 ret = -ENOMEM;
1468 goto err_usb;
Thierry MERLE483dfdb2006-12-04 08:31:45 -03001469 }
Mauro Carvalho Chehab659ae562007-04-14 15:09:59 -03001470
Hans Verkuil6d6a48e2010-12-29 13:53:21 -03001471 if (dev->descriptor.bNumConfigurations > 1)
Hans Verkuil5490a7c2010-12-19 20:21:36 -03001472 usbvision->bridge_type = BRIDGE_NT1004;
Hans Verkuil6d6a48e2010-12-29 13:53:21 -03001473 else if (model == DAZZLE_DVC_90_REV_1_SECAM)
Hans Verkuil5490a7c2010-12-19 20:21:36 -03001474 usbvision->bridge_type = BRIDGE_NT1005;
Hans Verkuil6d6a48e2010-12-29 13:53:21 -03001475 else
Hans Verkuil5490a7c2010-12-19 20:21:36 -03001476 usbvision->bridge_type = BRIDGE_NT1003;
Hans Verkuil5490a7c2010-12-19 20:21:36 -03001477 PDEBUG(DBG_PROBE, "bridge_type %d", usbvision->bridge_type);
Thierry MERLE483dfdb2006-12-04 08:31:45 -03001478
Thierry MERLE2a9f8b52007-02-07 10:14:38 -03001479 /* compute alternate max packet sizes */
1480 uif = dev->actconfig->interface[0];
1481
Hans Verkuil6d6a48e2010-12-29 13:53:21 -03001482 usbvision->num_alt = uif->num_altsetting;
1483 PDEBUG(DBG_PROBE, "Alternate settings: %i", usbvision->num_alt);
Kees Cook6da2ec52018-06-12 13:55:00 -07001484 usbvision->alt_max_pkt_size = kmalloc_array(32, usbvision->num_alt,
1485 GFP_KERNEL);
Markus Elfringc4cdcf92017-08-26 16:16:52 -04001486 if (!usbvision->alt_max_pkt_size) {
Alexey Khoroshilovafd270d2015-03-27 19:39:09 -03001487 ret = -ENOMEM;
1488 goto err_pkt;
Thierry MERLE2a9f8b52007-02-07 10:14:38 -03001489 }
1490
Hans Verkuil6d6a48e2010-12-29 13:53:21 -03001491 for (i = 0; i < usbvision->num_alt; i++) {
Johan Hovoldeacb9752017-03-13 09:53:55 -03001492 u16 tmp;
1493
1494 if (uif->altsetting[i].desc.bNumEndpoints < 2) {
1495 ret = -ENODEV;
1496 goto err_pkt;
1497 }
1498
1499 tmp = le16_to_cpu(uif->altsetting[i].endpoint[1].desc.
Thierry MERLE2a9f8b52007-02-07 10:14:38 -03001500 wMaxPacketSize);
1501 usbvision->alt_max_pkt_size[i] =
1502 (tmp & 0x07ff) * (((tmp & 0x1800) >> 11) + 1);
Hans Verkuil6d6a48e2010-12-29 13:53:21 -03001503 PDEBUG(DBG_PROBE, "Alternate setting %i, max size= %i", i,
Thierry MERLE2a9f8b52007-02-07 10:14:38 -03001504 usbvision->alt_max_pkt_size[i]);
1505 }
1506
1507
Thierry MERLE483dfdb2006-12-04 08:31:45 -03001508 usbvision->nr = usbvision_nr++;
1509
Hans Verkuildf3cfa62015-07-20 09:59:38 -03001510 spin_lock_init(&usbvision->queue_lock);
1511 init_waitqueue_head(&usbvision->wait_frame);
1512 init_waitqueue_head(&usbvision->wait_stream);
1513
Hans Verkuil5490a7c2010-12-19 20:21:36 -03001514 usbvision->have_tuner = usbvision_device_data[model].tuner;
Hans Verkuil6d6a48e2010-12-29 13:53:21 -03001515 if (usbvision->have_tuner)
Hans Verkuil5490a7c2010-12-19 20:21:36 -03001516 usbvision->tuner_type = usbvision_device_data[model].tuner_type;
Thierry MERLE483dfdb2006-12-04 08:31:45 -03001517
Hans Verkuil5490a7c2010-12-19 20:21:36 -03001518 usbvision->dev_model = model;
Thierry MERLE483dfdb2006-12-04 08:31:45 -03001519 usbvision->remove_pending = 0;
1520 usbvision->iface = ifnum;
Hans Verkuil5490a7c2010-12-19 20:21:36 -03001521 usbvision->iface_alt = 0;
Thierry MERLE483dfdb2006-12-04 08:31:45 -03001522 usbvision->video_endp = endpoint->bEndpointAddress;
Hans Verkuil5490a7c2010-12-19 20:21:36 -03001523 usbvision->isoc_packet_size = 0;
Thierry MERLE483dfdb2006-12-04 08:31:45 -03001524 usbvision->usb_bandwidth = 0;
1525 usbvision->user = 0;
Hans Verkuil5490a7c2010-12-19 20:21:36 -03001526 usbvision->streaming = stream_off;
Thierry MERLE483dfdb2006-12-04 08:31:45 -03001527 usbvision_configure_video(usbvision);
Hans Verkuil84034722010-09-17 15:07:28 -03001528 usbvision_register_video(usbvision);
Thierry MERLE483dfdb2006-12-04 08:31:45 -03001529
Hans Verkuil2aa689d2015-03-09 13:34:12 -03001530 usbvision_create_sysfs(&usbvision->vdev);
Thierry MERLE483dfdb2006-12-04 08:31:45 -03001531
1532 PDEBUG(DBG_PROBE, "success");
1533 return 0;
Alexey Khoroshilovafd270d2015-03-27 19:39:09 -03001534
1535err_pkt:
1536 usbvision_release(usbvision);
1537err_usb:
1538 usb_put_dev(dev);
1539 return ret;
Thierry MERLE483dfdb2006-12-04 08:31:45 -03001540}
1541
1542
1543/*
1544 * usbvision_disconnect()
1545 *
1546 * This procedure stops all driver activity, deallocates interface-private
1547 * structure (pointed by 'ptr') and after that driver should be removable
1548 * with no ill consequences.
1549 *
1550 */
Greg Kroah-Hartman4c62e972012-12-21 13:17:53 -08001551static void usbvision_disconnect(struct usb_interface *intf)
Thierry MERLE483dfdb2006-12-04 08:31:45 -03001552{
Hans Verkuilaeb506a2010-05-02 09:00:13 -03001553 struct usb_usbvision *usbvision = to_usbvision(usb_get_intfdata(intf));
Thierry MERLE483dfdb2006-12-04 08:31:45 -03001554
1555 PDEBUG(DBG_PROBE, "");
1556
Markus Elfringc4cdcf92017-08-26 16:16:52 -04001557 if (!usbvision) {
Julia Lawall42020662010-05-27 09:36:45 -03001558 pr_err("%s: usb_get_intfdata() failed\n", __func__);
Thierry MERLE483dfdb2006-12-04 08:31:45 -03001559 return;
1560 }
Thierry MERLE483dfdb2006-12-04 08:31:45 -03001561
Hans Verkuilc627b9d2010-12-18 11:06:09 -03001562 mutex_lock(&usbvision->v4l2_lock);
Thierry MERLE483dfdb2006-12-04 08:31:45 -03001563
Hans Verkuil52cb0bf22010-12-19 20:33:51 -03001564 /* At this time we ask to cancel outstanding URBs */
Thierry MERLE483dfdb2006-12-04 08:31:45 -03001565 usbvision_stop_isoc(usbvision);
1566
Hans Verkuilf1ba28c2009-03-14 12:27:01 -03001567 v4l2_device_disconnect(&usbvision->v4l2_dev);
Hans Verkuil62e25942015-07-20 09:59:28 -03001568 usbvision_i2c_unregister(usbvision);
Hans Verkuil52cb0bf22010-12-19 20:33:51 -03001569 usbvision->remove_pending = 1; /* Now all ISO data will be ignored */
Thierry MERLE483dfdb2006-12-04 08:31:45 -03001570
1571 usb_put_dev(usbvision->dev);
Hans Verkuil52cb0bf22010-12-19 20:33:51 -03001572 usbvision->dev = NULL; /* USB device is no more */
Thierry MERLE483dfdb2006-12-04 08:31:45 -03001573
Hans Verkuilc627b9d2010-12-18 11:06:09 -03001574 mutex_unlock(&usbvision->v4l2_lock);
Thierry MERLE483dfdb2006-12-04 08:31:45 -03001575
1576 if (usbvision->user) {
Thierry MERLEc5f48362007-05-08 17:22:29 -03001577 printk(KERN_INFO "%s: In use, disconnect pending\n",
Harvey Harrisond2db42d2008-04-04 20:50:07 -03001578 __func__);
Thierry MERLE483dfdb2006-12-04 08:31:45 -03001579 wake_up_interruptible(&usbvision->wait_frame);
1580 wake_up_interruptible(&usbvision->wait_stream);
Thierry MERLEc5f48362007-05-08 17:22:29 -03001581 } else {
Thierry MERLE483dfdb2006-12-04 08:31:45 -03001582 usbvision_release(usbvision);
1583 }
1584
1585 PDEBUG(DBG_PROBE, "success");
Thierry MERLE483dfdb2006-12-04 08:31:45 -03001586}
1587
1588static struct usb_driver usbvision_driver = {
1589 .name = "usbvision",
1590 .id_table = usbvision_table,
1591 .probe = usbvision_probe,
Greg Kroah-Hartman4c62e972012-12-21 13:17:53 -08001592 .disconnect = usbvision_disconnect,
Thierry MERLE483dfdb2006-12-04 08:31:45 -03001593};
1594
1595/*
Thierry MERLE483dfdb2006-12-04 08:31:45 -03001596 * usbvision_init()
1597 *
1598 * This code is run to initialize the driver.
1599 *
1600 */
1601static int __init usbvision_init(void)
1602{
Hans Verkuil5490a7c2010-12-19 20:21:36 -03001603 int err_code;
Thierry MERLE483dfdb2006-12-04 08:31:45 -03001604
1605 PDEBUG(DBG_PROBE, "");
1606
Thierry MERLE483dfdb2006-12-04 08:31:45 -03001607 PDEBUG(DBG_IO, "IO debugging is enabled [video]");
1608 PDEBUG(DBG_PROBE, "PROBE debugging is enabled [video]");
Thierry MERLEc876a342006-12-09 16:42:54 -03001609 PDEBUG(DBG_MMAP, "MMAP debugging is enabled [video]");
Thierry MERLE483dfdb2006-12-04 08:31:45 -03001610
1611 /* disable planar mode support unless compression enabled */
Hans Verkuil6d6a48e2010-12-29 13:53:21 -03001612 if (isoc_mode != ISOC_MODE_COMPRESS) {
Hans Verkuil52cb0bf22010-12-19 20:33:51 -03001613 /* FIXME : not the right way to set supported flag */
1614 usbvision_v4l2_format[6].supported = 0; /* V4L2_PIX_FMT_YVU420 */
1615 usbvision_v4l2_format[7].supported = 0; /* V4L2_PIX_FMT_YUV422P */
Thierry MERLE483dfdb2006-12-04 08:31:45 -03001616 }
1617
Hans Verkuil5490a7c2010-12-19 20:21:36 -03001618 err_code = usb_register(&usbvision_driver);
Thierry MERLE483dfdb2006-12-04 08:31:45 -03001619
Hans Verkuil5490a7c2010-12-19 20:21:36 -03001620 if (err_code == 0) {
Dwaine Gardende6a1b82007-01-07 21:13:55 -03001621 printk(KERN_INFO DRIVER_DESC " : " USBVISION_VERSION_STRING "\n");
Thierry MERLE483dfdb2006-12-04 08:31:45 -03001622 PDEBUG(DBG_PROBE, "success");
1623 }
Hans Verkuil5490a7c2010-12-19 20:21:36 -03001624 return err_code;
Thierry MERLE483dfdb2006-12-04 08:31:45 -03001625}
1626
1627static void __exit usbvision_exit(void)
1628{
Hans Verkuil6d6a48e2010-12-29 13:53:21 -03001629 PDEBUG(DBG_PROBE, "");
Thierry MERLE483dfdb2006-12-04 08:31:45 -03001630
Hans Verkuil6d6a48e2010-12-29 13:53:21 -03001631 usb_deregister(&usbvision_driver);
1632 PDEBUG(DBG_PROBE, "success");
Thierry MERLE483dfdb2006-12-04 08:31:45 -03001633}
1634
1635module_init(usbvision_init);
1636module_exit(usbvision_exit);