Thierry MERLE | 483dfdb | 2006-12-04 08:31:45 -0300 | [diff] [blame] | 1 | /* |
Hans Verkuil | 3ff4ad8 | 2009-04-01 03:15:52 -0300 | [diff] [blame] | 2 | * USB USBVISION Video device driver 0.9.10 |
Thierry MERLE | 483dfdb | 2006-12-04 08:31:45 -0300 | [diff] [blame] | 3 | * |
| 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 MERLE | c5f4836 | 2007-05-08 17:22:29 -0300 | [diff] [blame] | 39 | * - Add audio on endpoint 3 for nt1004 chip. |
| 40 | * Seems impossible, needs a codec interface. Which one? |
Thierry MERLE | 483dfdb | 2006-12-04 08:31:45 -0300 | [diff] [blame] | 41 | * - 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 MERLE | 483dfdb | 2006-12-04 08:31:45 -0300 | [diff] [blame] | 49 | #include <linux/list.h> |
| 50 | #include <linux/timer.h> |
| 51 | #include <linux/slab.h> |
| 52 | #include <linux/mm.h> |
Thierry MERLE | 483dfdb | 2006-12-04 08:31:45 -0300 | [diff] [blame] | 53 | #include <linux/highmem.h> |
Thierry MERLE | 483dfdb | 2006-12-04 08:31:45 -0300 | [diff] [blame] | 54 | #include <linux/vmalloc.h> |
| 55 | #include <linux/module.h> |
| 56 | #include <linux/init.h> |
| 57 | #include <linux/spinlock.h> |
Hans Verkuil | 6d6a48e | 2010-12-29 13:53:21 -0300 | [diff] [blame] | 58 | #include <linux/io.h> |
Thierry MERLE | 483dfdb | 2006-12-04 08:31:45 -0300 | [diff] [blame] | 59 | #include <linux/videodev2.h> |
Thierry MERLE | 483dfdb | 2006-12-04 08:31:45 -0300 | [diff] [blame] | 60 | #include <linux/i2c.h> |
| 61 | |
| 62 | #include <media/saa7115.h> |
| 63 | #include <media/v4l2-common.h> |
Hans Verkuil | 35ea11f | 2008-07-20 08:12:02 -0300 | [diff] [blame] | 64 | #include <media/v4l2-ioctl.h> |
Hans Verkuil | fd95870 | 2015-07-20 09:59:29 -0300 | [diff] [blame^] | 65 | #include <media/v4l2-event.h> |
Thierry MERLE | 483dfdb | 2006-12-04 08:31:45 -0300 | [diff] [blame] | 66 | #include <media/tuner.h> |
Thierry MERLE | 483dfdb | 2006-12-04 08:31:45 -0300 | [diff] [blame] | 67 | |
Mauro Carvalho Chehab | a1ed551 | 2006-12-09 11:41:59 -0300 | [diff] [blame] | 68 | #include <linux/workqueue.h> |
Thierry MERLE | 483dfdb | 2006-12-04 08:31:45 -0300 | [diff] [blame] | 69 | |
Thierry MERLE | 483dfdb | 2006-12-04 08:31:45 -0300 | [diff] [blame] | 70 | #include "usbvision.h" |
Mauro Carvalho Chehab | 659ae56 | 2007-04-14 15:09:59 -0300 | [diff] [blame] | 71 | #include "usbvision-cards.h" |
Thierry MERLE | 483dfdb | 2006-12-04 08:31:45 -0300 | [diff] [blame] | 72 | |
Joe Perches | 85ee7a1 | 2011-04-23 20:38:19 -0700 | [diff] [blame] | 73 | #define DRIVER_AUTHOR \ |
| 74 | "Joerg Heckenbach <joerg@heckenbach-aw.de>, " \ |
| 75 | "Dwaine Garden <DwaineGarden@rogers.com>" |
Thierry MERLE | 483dfdb | 2006-12-04 08:31:45 -0300 | [diff] [blame] | 76 | #define DRIVER_NAME "usbvision" |
| 77 | #define DRIVER_ALIAS "USBVision" |
| 78 | #define DRIVER_DESC "USBVision USB Video Device Driver for Linux" |
| 79 | #define DRIVER_LICENSE "GPL" |
Mauro Carvalho Chehab | 1990d50 | 2011-06-24 14:45:49 -0300 | [diff] [blame] | 80 | #define USBVISION_VERSION_STRING "0.9.11" |
Thierry MERLE | 483dfdb | 2006-12-04 08:31:45 -0300 | [diff] [blame] | 81 | |
| 82 | #define ENABLE_HEXDUMP 0 /* Enable if you need it */ |
| 83 | |
| 84 | |
Thierry MERLE | 483dfdb | 2006-12-04 08:31:45 -0300 | [diff] [blame] | 85 | #ifdef USBVISION_DEBUG |
Thierry MERLE | df18c31 | 2008-04-04 21:00:57 -0300 | [diff] [blame] | 86 | #define PDEBUG(level, fmt, args...) { \ |
Thierry MERLE | c5f4836 | 2007-05-08 17:22:29 -0300 | [diff] [blame] | 87 | if (video_debug & (level)) \ |
Greg Kroah-Hartman | a482f32 | 2008-10-10 05:08:23 -0300 | [diff] [blame] | 88 | printk(KERN_INFO KBUILD_MODNAME ":[%s:%d] " fmt, \ |
| 89 | __func__, __LINE__ , ## args); \ |
Thierry MERLE | df18c31 | 2008-04-04 21:00:57 -0300 | [diff] [blame] | 90 | } |
Thierry MERLE | 483dfdb | 2006-12-04 08:31:45 -0300 | [diff] [blame] | 91 | #else |
Hans Verkuil | 6d6a48e | 2010-12-29 13:53:21 -0300 | [diff] [blame] | 92 | #define PDEBUG(level, fmt, args...) do {} while (0) |
Thierry MERLE | 483dfdb | 2006-12-04 08:31:45 -0300 | [diff] [blame] | 93 | #endif |
| 94 | |
Hans Verkuil | 6d6a48e | 2010-12-29 13:53:21 -0300 | [diff] [blame] | 95 | #define DBG_IO (1 << 1) |
| 96 | #define DBG_PROBE (1 << 2) |
| 97 | #define DBG_MMAP (1 << 3) |
Thierry MERLE | 483dfdb | 2006-12-04 08:31:45 -0300 | [diff] [blame] | 98 | |
Hans Verkuil | 52cb0bf | 2010-12-19 20:33:51 -0300 | [diff] [blame] | 99 | /* String operations */ |
Hans Verkuil | 6d6a48e | 2010-12-29 13:53:21 -0300 | [diff] [blame] | 100 | #define rmspace(str) while (*str == ' ') str++; |
| 101 | #define goto2next(str) while (*str != ' ') str++; while (*str == ' ') str++; |
Thierry MERLE | 483dfdb | 2006-12-04 08:31:45 -0300 | [diff] [blame] | 102 | |
| 103 | |
Thierry MERLE | c5f4836 | 2007-05-08 17:22:29 -0300 | [diff] [blame] | 104 | /* sequential number of usbvision device */ |
Douglas Schilling Landgraf | ff699e6 | 2008-04-22 14:41:48 -0300 | [diff] [blame] | 105 | static int usbvision_nr; |
Thierry MERLE | 483dfdb | 2006-12-04 08:31:45 -0300 | [diff] [blame] | 106 | |
| 107 | static struct usbvision_v4l2_format_st usbvision_v4l2_format[] = { |
| 108 | { 1, 1, 8, V4L2_PIX_FMT_GREY , "GREY" }, |
| 109 | { 1, 2, 16, V4L2_PIX_FMT_RGB565 , "RGB565" }, |
| 110 | { 1, 3, 24, V4L2_PIX_FMT_RGB24 , "RGB24" }, |
| 111 | { 1, 4, 32, V4L2_PIX_FMT_RGB32 , "RGB32" }, |
| 112 | { 1, 2, 16, V4L2_PIX_FMT_RGB555 , "RGB555" }, |
| 113 | { 1, 2, 16, V4L2_PIX_FMT_YUYV , "YUV422" }, |
Hans Verkuil | 52cb0bf | 2010-12-19 20:33:51 -0300 | [diff] [blame] | 114 | { 1, 2, 12, V4L2_PIX_FMT_YVU420 , "YUV420P" }, /* 1.5 ! */ |
Thierry MERLE | 483dfdb | 2006-12-04 08:31:45 -0300 | [diff] [blame] | 115 | { 1, 2, 16, V4L2_PIX_FMT_YUV422P , "YUV422P" } |
| 116 | }; |
| 117 | |
Thierry MERLE | c5f4836 | 2007-05-08 17:22:29 -0300 | [diff] [blame] | 118 | /* Function prototypes */ |
Thierry MERLE | 483dfdb | 2006-12-04 08:31:45 -0300 | [diff] [blame] | 119 | static void usbvision_release(struct usb_usbvision *usbvision); |
| 120 | |
Joe Perches | c84e603 | 2008-02-03 17:18:59 +0200 | [diff] [blame] | 121 | /* Default initialization of device driver parameters */ |
Thierry MERLE | c5f4836 | 2007-05-08 17:22:29 -0300 | [diff] [blame] | 122 | /* Set the default format for ISOC endpoint */ |
Hans Verkuil | 5490a7c | 2010-12-19 20:21:36 -0300 | [diff] [blame] | 123 | static int isoc_mode = ISOC_MODE_COMPRESS; |
Thierry MERLE | c5f4836 | 2007-05-08 17:22:29 -0300 | [diff] [blame] | 124 | /* Set the default Debug Mode of the device driver */ |
Douglas Schilling Landgraf | ff699e6 | 2008-04-22 14:41:48 -0300 | [diff] [blame] | 125 | static int video_debug; |
Thierry MERLE | c5f4836 | 2007-05-08 17:22:29 -0300 | [diff] [blame] | 126 | /* Sequential Number of Video Device */ |
| 127 | static int video_nr = -1; |
| 128 | /* Sequential Number of Radio Device */ |
| 129 | static int radio_nr = -1; |
Thierry MERLE | 483dfdb | 2006-12-04 08:31:45 -0300 | [diff] [blame] | 130 | |
Thierry MERLE | c5f4836 | 2007-05-08 17:22:29 -0300 | [diff] [blame] | 131 | /* Grab parameters for the device driver */ |
Thierry MERLE | 483dfdb | 2006-12-04 08:31:45 -0300 | [diff] [blame] | 132 | |
Thierry MERLE | c5f4836 | 2007-05-08 17:22:29 -0300 | [diff] [blame] | 133 | /* Showing parameters under SYSFS */ |
Hans Verkuil | 5490a7c | 2010-12-19 20:21:36 -0300 | [diff] [blame] | 134 | module_param(isoc_mode, int, 0444); |
Thierry MERLE | 483dfdb | 2006-12-04 08:31:45 -0300 | [diff] [blame] | 135 | module_param(video_debug, int, 0444); |
Thierry MERLE | 483dfdb | 2006-12-04 08:31:45 -0300 | [diff] [blame] | 136 | module_param(video_nr, int, 0444); |
| 137 | module_param(radio_nr, int, 0444); |
Thierry MERLE | 483dfdb | 2006-12-04 08:31:45 -0300 | [diff] [blame] | 138 | |
Hans Verkuil | 5490a7c | 2010-12-19 20:21:36 -0300 | [diff] [blame] | 139 | MODULE_PARM_DESC(isoc_mode, " Set the default format for ISOC endpoint. Default: 0x60 (Compression On)"); |
Thierry MERLE | 483dfdb | 2006-12-04 08:31:45 -0300 | [diff] [blame] | 140 | MODULE_PARM_DESC(video_debug, " Set the default Debug Mode of the device driver. Default: 0 (Off)"); |
Thierry MERLE | 483dfdb | 2006-12-04 08:31:45 -0300 | [diff] [blame] | 141 | MODULE_PARM_DESC(video_nr, "Set video device number (/dev/videoX). Default: -1 (autodetect)"); |
| 142 | MODULE_PARM_DESC(radio_nr, "Set radio device number (/dev/radioX). Default: -1 (autodetect)"); |
Thierry MERLE | 483dfdb | 2006-12-04 08:31:45 -0300 | [diff] [blame] | 143 | |
| 144 | |
Hans Verkuil | 52cb0bf | 2010-12-19 20:33:51 -0300 | [diff] [blame] | 145 | /* Misc stuff */ |
Thierry MERLE | 483dfdb | 2006-12-04 08:31:45 -0300 | [diff] [blame] | 146 | MODULE_AUTHOR(DRIVER_AUTHOR); |
| 147 | MODULE_DESCRIPTION(DRIVER_DESC); |
| 148 | MODULE_LICENSE(DRIVER_LICENSE); |
Mauro Carvalho Chehab | a1ed551 | 2006-12-09 11:41:59 -0300 | [diff] [blame] | 149 | MODULE_VERSION(USBVISION_VERSION_STRING); |
| 150 | MODULE_ALIAS(DRIVER_ALIAS); |
Thierry MERLE | 483dfdb | 2006-12-04 08:31:45 -0300 | [diff] [blame] | 151 | |
| 152 | |
Thierry MERLE | c5f4836 | 2007-05-08 17:22:29 -0300 | [diff] [blame] | 153 | /*****************************************************************************/ |
| 154 | /* SYSFS Code - Copied from the stv680.c usb module. */ |
| 155 | /* Device information is located at /sys/class/video4linux/video0 */ |
| 156 | /* Device parameters information is located at /sys/module/usbvision */ |
| 157 | /* Device USB Information is located at */ |
| 158 | /* /sys/bus/usb/drivers/USBVision Video Grabber */ |
| 159 | /*****************************************************************************/ |
Thierry MERLE | 483dfdb | 2006-12-04 08:31:45 -0300 | [diff] [blame] | 160 | |
Thierry MERLE | 483dfdb | 2006-12-04 08:31:45 -0300 | [diff] [blame] | 161 | #define YES_NO(x) ((x) ? "Yes" : "No") |
| 162 | |
Kay Sievers | 54bd5b6 | 2007-10-08 16:26:13 -0300 | [diff] [blame] | 163 | static inline struct usb_usbvision *cd_to_usbvision(struct device *cd) |
Thierry MERLE | 483dfdb | 2006-12-04 08:31:45 -0300 | [diff] [blame] | 164 | { |
Thierry MERLE | c5f4836 | 2007-05-08 17:22:29 -0300 | [diff] [blame] | 165 | struct video_device *vdev = |
Hans Verkuil | 22a04f1 | 2008-07-20 06:35:02 -0300 | [diff] [blame] | 166 | container_of(cd, struct video_device, dev); |
Thierry MERLE | 483dfdb | 2006-12-04 08:31:45 -0300 | [diff] [blame] | 167 | return video_get_drvdata(vdev); |
| 168 | } |
| 169 | |
Kay Sievers | 54bd5b6 | 2007-10-08 16:26:13 -0300 | [diff] [blame] | 170 | static ssize_t show_version(struct device *cd, |
| 171 | struct device_attribute *attr, char *buf) |
Thierry MERLE | 483dfdb | 2006-12-04 08:31:45 -0300 | [diff] [blame] | 172 | { |
| 173 | return sprintf(buf, "%s\n", USBVISION_VERSION_STRING); |
| 174 | } |
Kay Sievers | 54bd5b6 | 2007-10-08 16:26:13 -0300 | [diff] [blame] | 175 | static DEVICE_ATTR(version, S_IRUGO, show_version, NULL); |
Thierry MERLE | 483dfdb | 2006-12-04 08:31:45 -0300 | [diff] [blame] | 176 | |
Kay Sievers | 54bd5b6 | 2007-10-08 16:26:13 -0300 | [diff] [blame] | 177 | static ssize_t show_model(struct device *cd, |
| 178 | struct device_attribute *attr, char *buf) |
Thierry MERLE | 483dfdb | 2006-12-04 08:31:45 -0300 | [diff] [blame] | 179 | { |
Thierry MERLE | c5f4836 | 2007-05-08 17:22:29 -0300 | [diff] [blame] | 180 | struct video_device *vdev = |
Hans Verkuil | 22a04f1 | 2008-07-20 06:35:02 -0300 | [diff] [blame] | 181 | container_of(cd, struct video_device, dev); |
Thierry MERLE | 483dfdb | 2006-12-04 08:31:45 -0300 | [diff] [blame] | 182 | struct usb_usbvision *usbvision = video_get_drvdata(vdev); |
Thierry MERLE | c5f4836 | 2007-05-08 17:22:29 -0300 | [diff] [blame] | 183 | return sprintf(buf, "%s\n", |
Hans Verkuil | 5490a7c | 2010-12-19 20:21:36 -0300 | [diff] [blame] | 184 | usbvision_device_data[usbvision->dev_model].model_string); |
Thierry MERLE | 483dfdb | 2006-12-04 08:31:45 -0300 | [diff] [blame] | 185 | } |
Kay Sievers | 54bd5b6 | 2007-10-08 16:26:13 -0300 | [diff] [blame] | 186 | static DEVICE_ATTR(model, S_IRUGO, show_model, NULL); |
Thierry MERLE | 483dfdb | 2006-12-04 08:31:45 -0300 | [diff] [blame] | 187 | |
Kay Sievers | 54bd5b6 | 2007-10-08 16:26:13 -0300 | [diff] [blame] | 188 | static ssize_t show_hue(struct device *cd, |
| 189 | struct device_attribute *attr, char *buf) |
Thierry MERLE | 483dfdb | 2006-12-04 08:31:45 -0300 | [diff] [blame] | 190 | { |
Thierry MERLE | c5f4836 | 2007-05-08 17:22:29 -0300 | [diff] [blame] | 191 | struct video_device *vdev = |
Hans Verkuil | 22a04f1 | 2008-07-20 06:35:02 -0300 | [diff] [blame] | 192 | container_of(cd, struct video_device, dev); |
Thierry MERLE | 483dfdb | 2006-12-04 08:31:45 -0300 | [diff] [blame] | 193 | struct usb_usbvision *usbvision = video_get_drvdata(vdev); |
| 194 | struct v4l2_control ctrl; |
| 195 | ctrl.id = V4L2_CID_HUE; |
| 196 | ctrl.value = 0; |
Hans Verkuil | 6d6a48e | 2010-12-29 13:53:21 -0300 | [diff] [blame] | 197 | if (usbvision->user) |
Hans Verkuil | 1df7953 | 2009-02-21 18:11:31 -0300 | [diff] [blame] | 198 | call_all(usbvision, core, g_ctrl, &ctrl); |
Thierry MERLE | 2a9f8b5 | 2007-02-07 10:14:38 -0300 | [diff] [blame] | 199 | return sprintf(buf, "%d\n", ctrl.value); |
Thierry MERLE | 483dfdb | 2006-12-04 08:31:45 -0300 | [diff] [blame] | 200 | } |
Kay Sievers | 54bd5b6 | 2007-10-08 16:26:13 -0300 | [diff] [blame] | 201 | static DEVICE_ATTR(hue, S_IRUGO, show_hue, NULL); |
Thierry MERLE | 483dfdb | 2006-12-04 08:31:45 -0300 | [diff] [blame] | 202 | |
Kay Sievers | 54bd5b6 | 2007-10-08 16:26:13 -0300 | [diff] [blame] | 203 | static ssize_t show_contrast(struct device *cd, |
| 204 | struct device_attribute *attr, char *buf) |
Thierry MERLE | 483dfdb | 2006-12-04 08:31:45 -0300 | [diff] [blame] | 205 | { |
Thierry MERLE | c5f4836 | 2007-05-08 17:22:29 -0300 | [diff] [blame] | 206 | struct video_device *vdev = |
Hans Verkuil | 22a04f1 | 2008-07-20 06:35:02 -0300 | [diff] [blame] | 207 | container_of(cd, struct video_device, dev); |
Thierry MERLE | 483dfdb | 2006-12-04 08:31:45 -0300 | [diff] [blame] | 208 | struct usb_usbvision *usbvision = video_get_drvdata(vdev); |
| 209 | struct v4l2_control ctrl; |
| 210 | ctrl.id = V4L2_CID_CONTRAST; |
| 211 | ctrl.value = 0; |
Hans Verkuil | 6d6a48e | 2010-12-29 13:53:21 -0300 | [diff] [blame] | 212 | if (usbvision->user) |
Hans Verkuil | 1df7953 | 2009-02-21 18:11:31 -0300 | [diff] [blame] | 213 | call_all(usbvision, core, g_ctrl, &ctrl); |
Thierry MERLE | 2a9f8b5 | 2007-02-07 10:14:38 -0300 | [diff] [blame] | 214 | return sprintf(buf, "%d\n", ctrl.value); |
Thierry MERLE | 483dfdb | 2006-12-04 08:31:45 -0300 | [diff] [blame] | 215 | } |
Kay Sievers | 54bd5b6 | 2007-10-08 16:26:13 -0300 | [diff] [blame] | 216 | static DEVICE_ATTR(contrast, S_IRUGO, show_contrast, NULL); |
Thierry MERLE | 483dfdb | 2006-12-04 08:31:45 -0300 | [diff] [blame] | 217 | |
Kay Sievers | 54bd5b6 | 2007-10-08 16:26:13 -0300 | [diff] [blame] | 218 | static ssize_t show_brightness(struct device *cd, |
| 219 | struct device_attribute *attr, char *buf) |
Thierry MERLE | 483dfdb | 2006-12-04 08:31:45 -0300 | [diff] [blame] | 220 | { |
Thierry MERLE | c5f4836 | 2007-05-08 17:22:29 -0300 | [diff] [blame] | 221 | struct video_device *vdev = |
Hans Verkuil | 22a04f1 | 2008-07-20 06:35:02 -0300 | [diff] [blame] | 222 | container_of(cd, struct video_device, dev); |
Thierry MERLE | 483dfdb | 2006-12-04 08:31:45 -0300 | [diff] [blame] | 223 | struct usb_usbvision *usbvision = video_get_drvdata(vdev); |
| 224 | struct v4l2_control ctrl; |
| 225 | ctrl.id = V4L2_CID_BRIGHTNESS; |
| 226 | ctrl.value = 0; |
Hans Verkuil | 6d6a48e | 2010-12-29 13:53:21 -0300 | [diff] [blame] | 227 | if (usbvision->user) |
Hans Verkuil | 1df7953 | 2009-02-21 18:11:31 -0300 | [diff] [blame] | 228 | call_all(usbvision, core, g_ctrl, &ctrl); |
Thierry MERLE | 2a9f8b5 | 2007-02-07 10:14:38 -0300 | [diff] [blame] | 229 | return sprintf(buf, "%d\n", ctrl.value); |
Thierry MERLE | 483dfdb | 2006-12-04 08:31:45 -0300 | [diff] [blame] | 230 | } |
Kay Sievers | 54bd5b6 | 2007-10-08 16:26:13 -0300 | [diff] [blame] | 231 | static DEVICE_ATTR(brightness, S_IRUGO, show_brightness, NULL); |
Thierry MERLE | 483dfdb | 2006-12-04 08:31:45 -0300 | [diff] [blame] | 232 | |
Kay Sievers | 54bd5b6 | 2007-10-08 16:26:13 -0300 | [diff] [blame] | 233 | static ssize_t show_saturation(struct device *cd, |
| 234 | struct device_attribute *attr, char *buf) |
Thierry MERLE | 483dfdb | 2006-12-04 08:31:45 -0300 | [diff] [blame] | 235 | { |
Thierry MERLE | c5f4836 | 2007-05-08 17:22:29 -0300 | [diff] [blame] | 236 | struct video_device *vdev = |
Hans Verkuil | 22a04f1 | 2008-07-20 06:35:02 -0300 | [diff] [blame] | 237 | container_of(cd, struct video_device, dev); |
Thierry MERLE | 483dfdb | 2006-12-04 08:31:45 -0300 | [diff] [blame] | 238 | struct usb_usbvision *usbvision = video_get_drvdata(vdev); |
| 239 | struct v4l2_control ctrl; |
| 240 | ctrl.id = V4L2_CID_SATURATION; |
| 241 | ctrl.value = 0; |
Hans Verkuil | 6d6a48e | 2010-12-29 13:53:21 -0300 | [diff] [blame] | 242 | if (usbvision->user) |
Hans Verkuil | 1df7953 | 2009-02-21 18:11:31 -0300 | [diff] [blame] | 243 | call_all(usbvision, core, g_ctrl, &ctrl); |
Thierry MERLE | 2a9f8b5 | 2007-02-07 10:14:38 -0300 | [diff] [blame] | 244 | return sprintf(buf, "%d\n", ctrl.value); |
Thierry MERLE | 483dfdb | 2006-12-04 08:31:45 -0300 | [diff] [blame] | 245 | } |
Kay Sievers | 54bd5b6 | 2007-10-08 16:26:13 -0300 | [diff] [blame] | 246 | static DEVICE_ATTR(saturation, S_IRUGO, show_saturation, NULL); |
Thierry MERLE | 483dfdb | 2006-12-04 08:31:45 -0300 | [diff] [blame] | 247 | |
Kay Sievers | 54bd5b6 | 2007-10-08 16:26:13 -0300 | [diff] [blame] | 248 | static ssize_t show_streaming(struct device *cd, |
| 249 | struct device_attribute *attr, char *buf) |
Thierry MERLE | 483dfdb | 2006-12-04 08:31:45 -0300 | [diff] [blame] | 250 | { |
Thierry MERLE | c5f4836 | 2007-05-08 17:22:29 -0300 | [diff] [blame] | 251 | struct video_device *vdev = |
Hans Verkuil | 22a04f1 | 2008-07-20 06:35:02 -0300 | [diff] [blame] | 252 | container_of(cd, struct video_device, dev); |
Thierry MERLE | 483dfdb | 2006-12-04 08:31:45 -0300 | [diff] [blame] | 253 | struct usb_usbvision *usbvision = video_get_drvdata(vdev); |
Thierry MERLE | c5f4836 | 2007-05-08 17:22:29 -0300 | [diff] [blame] | 254 | return sprintf(buf, "%s\n", |
Hans Verkuil | 6d6a48e | 2010-12-29 13:53:21 -0300 | [diff] [blame] | 255 | YES_NO(usbvision->streaming == stream_on ? 1 : 0)); |
Thierry MERLE | 483dfdb | 2006-12-04 08:31:45 -0300 | [diff] [blame] | 256 | } |
Kay Sievers | 54bd5b6 | 2007-10-08 16:26:13 -0300 | [diff] [blame] | 257 | static DEVICE_ATTR(streaming, S_IRUGO, show_streaming, NULL); |
Thierry MERLE | 483dfdb | 2006-12-04 08:31:45 -0300 | [diff] [blame] | 258 | |
Kay Sievers | 54bd5b6 | 2007-10-08 16:26:13 -0300 | [diff] [blame] | 259 | static ssize_t show_compression(struct device *cd, |
| 260 | struct device_attribute *attr, char *buf) |
Thierry MERLE | 483dfdb | 2006-12-04 08:31:45 -0300 | [diff] [blame] | 261 | { |
Thierry MERLE | c5f4836 | 2007-05-08 17:22:29 -0300 | [diff] [blame] | 262 | struct video_device *vdev = |
Hans Verkuil | 22a04f1 | 2008-07-20 06:35:02 -0300 | [diff] [blame] | 263 | container_of(cd, struct video_device, dev); |
Thierry MERLE | 483dfdb | 2006-12-04 08:31:45 -0300 | [diff] [blame] | 264 | struct usb_usbvision *usbvision = video_get_drvdata(vdev); |
Thierry MERLE | c5f4836 | 2007-05-08 17:22:29 -0300 | [diff] [blame] | 265 | return sprintf(buf, "%s\n", |
Hans Verkuil | 6d6a48e | 2010-12-29 13:53:21 -0300 | [diff] [blame] | 266 | YES_NO(usbvision->isoc_mode == ISOC_MODE_COMPRESS)); |
Thierry MERLE | 483dfdb | 2006-12-04 08:31:45 -0300 | [diff] [blame] | 267 | } |
Kay Sievers | 54bd5b6 | 2007-10-08 16:26:13 -0300 | [diff] [blame] | 268 | static DEVICE_ATTR(compression, S_IRUGO, show_compression, NULL); |
Thierry MERLE | 483dfdb | 2006-12-04 08:31:45 -0300 | [diff] [blame] | 269 | |
Kay Sievers | 54bd5b6 | 2007-10-08 16:26:13 -0300 | [diff] [blame] | 270 | static ssize_t show_device_bridge(struct device *cd, |
| 271 | struct device_attribute *attr, char *buf) |
Thierry MERLE | 483dfdb | 2006-12-04 08:31:45 -0300 | [diff] [blame] | 272 | { |
Thierry MERLE | c5f4836 | 2007-05-08 17:22:29 -0300 | [diff] [blame] | 273 | struct video_device *vdev = |
Hans Verkuil | 22a04f1 | 2008-07-20 06:35:02 -0300 | [diff] [blame] | 274 | container_of(cd, struct video_device, dev); |
Thierry MERLE | 483dfdb | 2006-12-04 08:31:45 -0300 | [diff] [blame] | 275 | struct usb_usbvision *usbvision = video_get_drvdata(vdev); |
Hans Verkuil | 5490a7c | 2010-12-19 20:21:36 -0300 | [diff] [blame] | 276 | return sprintf(buf, "%d\n", usbvision->bridge_type); |
Thierry MERLE | 483dfdb | 2006-12-04 08:31:45 -0300 | [diff] [blame] | 277 | } |
Kay Sievers | 54bd5b6 | 2007-10-08 16:26:13 -0300 | [diff] [blame] | 278 | static DEVICE_ATTR(bridge, S_IRUGO, show_device_bridge, NULL); |
Thierry MERLE | 483dfdb | 2006-12-04 08:31:45 -0300 | [diff] [blame] | 279 | |
| 280 | static void usbvision_create_sysfs(struct video_device *vdev) |
| 281 | { |
| 282 | int res; |
Hans Verkuil | 6d6a48e | 2010-12-29 13:53:21 -0300 | [diff] [blame] | 283 | |
Dwaine Garden | ed00b41 | 2006-12-27 10:23:28 -0200 | [diff] [blame] | 284 | if (!vdev) |
| 285 | return; |
| 286 | do { |
Hans Verkuil | 22a04f1 | 2008-07-20 06:35:02 -0300 | [diff] [blame] | 287 | res = device_create_file(&vdev->dev, &dev_attr_version); |
Hans Verkuil | 6d6a48e | 2010-12-29 13:53:21 -0300 | [diff] [blame] | 288 | if (res < 0) |
Dwaine Garden | ed00b41 | 2006-12-27 10:23:28 -0200 | [diff] [blame] | 289 | break; |
Hans Verkuil | 22a04f1 | 2008-07-20 06:35:02 -0300 | [diff] [blame] | 290 | res = device_create_file(&vdev->dev, &dev_attr_model); |
Hans Verkuil | 6d6a48e | 2010-12-29 13:53:21 -0300 | [diff] [blame] | 291 | if (res < 0) |
Dwaine Garden | ed00b41 | 2006-12-27 10:23:28 -0200 | [diff] [blame] | 292 | break; |
Hans Verkuil | 22a04f1 | 2008-07-20 06:35:02 -0300 | [diff] [blame] | 293 | res = device_create_file(&vdev->dev, &dev_attr_hue); |
Hans Verkuil | 6d6a48e | 2010-12-29 13:53:21 -0300 | [diff] [blame] | 294 | if (res < 0) |
Dwaine Garden | ed00b41 | 2006-12-27 10:23:28 -0200 | [diff] [blame] | 295 | break; |
Hans Verkuil | 22a04f1 | 2008-07-20 06:35:02 -0300 | [diff] [blame] | 296 | res = device_create_file(&vdev->dev, &dev_attr_contrast); |
Hans Verkuil | 6d6a48e | 2010-12-29 13:53:21 -0300 | [diff] [blame] | 297 | if (res < 0) |
Dwaine Garden | ed00b41 | 2006-12-27 10:23:28 -0200 | [diff] [blame] | 298 | break; |
Hans Verkuil | 22a04f1 | 2008-07-20 06:35:02 -0300 | [diff] [blame] | 299 | res = device_create_file(&vdev->dev, &dev_attr_brightness); |
Hans Verkuil | 6d6a48e | 2010-12-29 13:53:21 -0300 | [diff] [blame] | 300 | if (res < 0) |
Dwaine Garden | ed00b41 | 2006-12-27 10:23:28 -0200 | [diff] [blame] | 301 | break; |
Hans Verkuil | 22a04f1 | 2008-07-20 06:35:02 -0300 | [diff] [blame] | 302 | res = device_create_file(&vdev->dev, &dev_attr_saturation); |
Hans Verkuil | 6d6a48e | 2010-12-29 13:53:21 -0300 | [diff] [blame] | 303 | if (res < 0) |
Dwaine Garden | ed00b41 | 2006-12-27 10:23:28 -0200 | [diff] [blame] | 304 | break; |
Hans Verkuil | 22a04f1 | 2008-07-20 06:35:02 -0300 | [diff] [blame] | 305 | res = device_create_file(&vdev->dev, &dev_attr_streaming); |
Hans Verkuil | 6d6a48e | 2010-12-29 13:53:21 -0300 | [diff] [blame] | 306 | if (res < 0) |
Dwaine Garden | ed00b41 | 2006-12-27 10:23:28 -0200 | [diff] [blame] | 307 | break; |
Hans Verkuil | 22a04f1 | 2008-07-20 06:35:02 -0300 | [diff] [blame] | 308 | res = device_create_file(&vdev->dev, &dev_attr_compression); |
Hans Verkuil | 6d6a48e | 2010-12-29 13:53:21 -0300 | [diff] [blame] | 309 | if (res < 0) |
Dwaine Garden | ed00b41 | 2006-12-27 10:23:28 -0200 | [diff] [blame] | 310 | break; |
Hans Verkuil | 22a04f1 | 2008-07-20 06:35:02 -0300 | [diff] [blame] | 311 | res = device_create_file(&vdev->dev, &dev_attr_bridge); |
Hans Verkuil | 6d6a48e | 2010-12-29 13:53:21 -0300 | [diff] [blame] | 312 | if (res >= 0) |
Dwaine Garden | ed00b41 | 2006-12-27 10:23:28 -0200 | [diff] [blame] | 313 | return; |
| 314 | } while (0); |
| 315 | |
Mauro Carvalho Chehab | be9ed51 | 2009-01-08 09:13:42 -0300 | [diff] [blame] | 316 | dev_err(&vdev->dev, "%s error: %d\n", __func__, res); |
Thierry MERLE | 483dfdb | 2006-12-04 08:31:45 -0300 | [diff] [blame] | 317 | } |
| 318 | |
| 319 | static void usbvision_remove_sysfs(struct video_device *vdev) |
| 320 | { |
| 321 | if (vdev) { |
Hans Verkuil | 22a04f1 | 2008-07-20 06:35:02 -0300 | [diff] [blame] | 322 | device_remove_file(&vdev->dev, &dev_attr_version); |
| 323 | device_remove_file(&vdev->dev, &dev_attr_model); |
| 324 | device_remove_file(&vdev->dev, &dev_attr_hue); |
| 325 | device_remove_file(&vdev->dev, &dev_attr_contrast); |
| 326 | device_remove_file(&vdev->dev, &dev_attr_brightness); |
| 327 | device_remove_file(&vdev->dev, &dev_attr_saturation); |
| 328 | device_remove_file(&vdev->dev, &dev_attr_streaming); |
| 329 | device_remove_file(&vdev->dev, &dev_attr_compression); |
| 330 | device_remove_file(&vdev->dev, &dev_attr_bridge); |
Thierry MERLE | 483dfdb | 2006-12-04 08:31:45 -0300 | [diff] [blame] | 331 | } |
| 332 | } |
| 333 | |
Thierry MERLE | 483dfdb | 2006-12-04 08:31:45 -0300 | [diff] [blame] | 334 | /* |
| 335 | * usbvision_open() |
| 336 | * |
| 337 | * This is part of Video 4 Linux API. The driver can be opened by one |
| 338 | * client only (checks internal counter 'usbvision->user'). The procedure |
| 339 | * then allocates buffers needed for video processing. |
| 340 | * |
| 341 | */ |
Hans Verkuil | bec4366 | 2008-12-30 06:58:20 -0300 | [diff] [blame] | 342 | static int usbvision_v4l2_open(struct file *file) |
Thierry MERLE | 483dfdb | 2006-12-04 08:31:45 -0300 | [diff] [blame] | 343 | { |
Hans Verkuil | c170ecf | 2008-08-23 08:32:09 -0300 | [diff] [blame] | 344 | struct usb_usbvision *usbvision = video_drvdata(file); |
Hans Verkuil | 5490a7c | 2010-12-19 20:21:36 -0300 | [diff] [blame] | 345 | int err_code = 0; |
Thierry MERLE | 483dfdb | 2006-12-04 08:31:45 -0300 | [diff] [blame] | 346 | |
| 347 | PDEBUG(DBG_IO, "open"); |
| 348 | |
Hans Verkuil | 4d34570 | 2012-06-23 08:03:50 -0300 | [diff] [blame] | 349 | if (mutex_lock_interruptible(&usbvision->v4l2_lock)) |
| 350 | return -ERESTARTSYS; |
Thierry MERLE | 483dfdb | 2006-12-04 08:31:45 -0300 | [diff] [blame] | 351 | |
Hans Verkuil | 62e2594 | 2015-07-20 09:59:28 -0300 | [diff] [blame] | 352 | if (usbvision->user) { |
Hans Verkuil | 5490a7c | 2010-12-19 20:21:36 -0300 | [diff] [blame] | 353 | err_code = -EBUSY; |
Hans Verkuil | 62e2594 | 2015-07-20 09:59:28 -0300 | [diff] [blame] | 354 | } else { |
Hans Verkuil | fd95870 | 2015-07-20 09:59:29 -0300 | [diff] [blame^] | 355 | err_code = v4l2_fh_open(file); |
| 356 | if (err_code) |
| 357 | goto unlock; |
| 358 | |
Thierry MERLE | 6f78e18 | 2007-02-07 10:13:11 -0300 | [diff] [blame] | 359 | /* Allocate memory for the scratch ring buffer */ |
Hans Verkuil | 5490a7c | 2010-12-19 20:21:36 -0300 | [diff] [blame] | 360 | err_code = usbvision_scratch_alloc(usbvision); |
Hans Verkuil | 6d6a48e | 2010-12-29 13:53:21 -0300 | [diff] [blame] | 361 | if (isoc_mode == ISOC_MODE_COMPRESS) { |
Thierry MERLE | c5f4836 | 2007-05-08 17:22:29 -0300 | [diff] [blame] | 362 | /* Allocate intermediate decompression buffers |
| 363 | only if needed */ |
Hans Verkuil | 5490a7c | 2010-12-19 20:21:36 -0300 | [diff] [blame] | 364 | err_code = usbvision_decompress_alloc(usbvision); |
Thierry MERLE | 483dfdb | 2006-12-04 08:31:45 -0300 | [diff] [blame] | 365 | } |
Hans Verkuil | 5490a7c | 2010-12-19 20:21:36 -0300 | [diff] [blame] | 366 | if (err_code) { |
Thierry MERLE | 483dfdb | 2006-12-04 08:31:45 -0300 | [diff] [blame] | 367 | /* Deallocate all buffers if trouble */ |
Thierry MERLE | 483dfdb | 2006-12-04 08:31:45 -0300 | [diff] [blame] | 368 | usbvision_scratch_free(usbvision); |
Thierry MERLE | 483dfdb | 2006-12-04 08:31:45 -0300 | [diff] [blame] | 369 | usbvision_decompress_free(usbvision); |
| 370 | } |
| 371 | } |
| 372 | |
| 373 | /* If so far no errors then we shall start the camera */ |
Hans Verkuil | 5490a7c | 2010-12-19 20:21:36 -0300 | [diff] [blame] | 374 | if (!err_code) { |
Thierry MERLE | 483dfdb | 2006-12-04 08:31:45 -0300 | [diff] [blame] | 375 | /* Send init sequence only once, it's large! */ |
| 376 | if (!usbvision->initialized) { |
| 377 | int setup_ok = 0; |
Hans Verkuil | 6d6a48e | 2010-12-29 13:53:21 -0300 | [diff] [blame] | 378 | setup_ok = usbvision_setup(usbvision, isoc_mode); |
Thierry MERLE | 483dfdb | 2006-12-04 08:31:45 -0300 | [diff] [blame] | 379 | if (setup_ok) |
| 380 | usbvision->initialized = 1; |
| 381 | else |
Hans Verkuil | 5490a7c | 2010-12-19 20:21:36 -0300 | [diff] [blame] | 382 | err_code = -EBUSY; |
Thierry MERLE | 483dfdb | 2006-12-04 08:31:45 -0300 | [diff] [blame] | 383 | } |
| 384 | |
Hans Verkuil | 5490a7c | 2010-12-19 20:21:36 -0300 | [diff] [blame] | 385 | if (!err_code) { |
Thierry MERLE | 483dfdb | 2006-12-04 08:31:45 -0300 | [diff] [blame] | 386 | usbvision_begin_streaming(usbvision); |
Hans Verkuil | 5490a7c | 2010-12-19 20:21:36 -0300 | [diff] [blame] | 387 | err_code = usbvision_init_isoc(usbvision); |
Thierry MERLE | c5f4836 | 2007-05-08 17:22:29 -0300 | [diff] [blame] | 388 | /* device must be initialized before isoc transfer */ |
Hans Verkuil | 6d6a48e | 2010-12-29 13:53:21 -0300 | [diff] [blame] | 389 | usbvision_muxsel(usbvision, 0); |
Hans Verkuil | 62e2594 | 2015-07-20 09:59:28 -0300 | [diff] [blame] | 390 | |
| 391 | /* prepare queues */ |
| 392 | usbvision_empty_framequeues(usbvision); |
Thierry MERLE | 483dfdb | 2006-12-04 08:31:45 -0300 | [diff] [blame] | 393 | usbvision->user++; |
Thierry MERLE | 483dfdb | 2006-12-04 08:31:45 -0300 | [diff] [blame] | 394 | } |
Thierry MERLE | 483dfdb | 2006-12-04 08:31:45 -0300 | [diff] [blame] | 395 | } |
| 396 | |
Hans Verkuil | fd95870 | 2015-07-20 09:59:29 -0300 | [diff] [blame^] | 397 | unlock: |
Hans Verkuil | 4d34570 | 2012-06-23 08:03:50 -0300 | [diff] [blame] | 398 | mutex_unlock(&usbvision->v4l2_lock); |
Thierry MERLE | 483dfdb | 2006-12-04 08:31:45 -0300 | [diff] [blame] | 399 | |
| 400 | PDEBUG(DBG_IO, "success"); |
Hans Verkuil | 5490a7c | 2010-12-19 20:21:36 -0300 | [diff] [blame] | 401 | return err_code; |
Thierry MERLE | 483dfdb | 2006-12-04 08:31:45 -0300 | [diff] [blame] | 402 | } |
| 403 | |
| 404 | /* |
| 405 | * usbvision_v4l2_close() |
| 406 | * |
| 407 | * This is part of Video 4 Linux API. The procedure |
| 408 | * stops streaming and deallocates all buffers that were earlier |
| 409 | * allocated in usbvision_v4l2_open(). |
| 410 | * |
| 411 | */ |
Hans Verkuil | bec4366 | 2008-12-30 06:58:20 -0300 | [diff] [blame] | 412 | static int usbvision_v4l2_close(struct file *file) |
Thierry MERLE | 483dfdb | 2006-12-04 08:31:45 -0300 | [diff] [blame] | 413 | { |
Hans Verkuil | c170ecf | 2008-08-23 08:32:09 -0300 | [diff] [blame] | 414 | struct usb_usbvision *usbvision = video_drvdata(file); |
Thierry MERLE | 483dfdb | 2006-12-04 08:31:45 -0300 | [diff] [blame] | 415 | |
| 416 | PDEBUG(DBG_IO, "close"); |
Thierry MERLE | 483dfdb | 2006-12-04 08:31:45 -0300 | [diff] [blame] | 417 | |
Hans Verkuil | 4d34570 | 2012-06-23 08:03:50 -0300 | [diff] [blame] | 418 | mutex_lock(&usbvision->v4l2_lock); |
Thierry MERLE | 483dfdb | 2006-12-04 08:31:45 -0300 | [diff] [blame] | 419 | usbvision_audio_off(usbvision); |
| 420 | usbvision_restart_isoc(usbvision); |
| 421 | usbvision_stop_isoc(usbvision); |
| 422 | |
| 423 | usbvision_decompress_free(usbvision); |
Thierry MERLE | 38284ba | 2006-12-15 16:46:53 -0300 | [diff] [blame] | 424 | usbvision_frames_free(usbvision); |
Thierry MERLE | 6f78e18 | 2007-02-07 10:13:11 -0300 | [diff] [blame] | 425 | usbvision_empty_framequeues(usbvision); |
Thierry MERLE | 483dfdb | 2006-12-04 08:31:45 -0300 | [diff] [blame] | 426 | usbvision_scratch_free(usbvision); |
Thierry MERLE | 483dfdb | 2006-12-04 08:31:45 -0300 | [diff] [blame] | 427 | |
| 428 | usbvision->user--; |
| 429 | |
Thierry MERLE | 483dfdb | 2006-12-04 08:31:45 -0300 | [diff] [blame] | 430 | if (usbvision->remove_pending) { |
Harvey Harrison | d2db42d | 2008-04-04 20:50:07 -0300 | [diff] [blame] | 431 | printk(KERN_INFO "%s: Final disconnect\n", __func__); |
Thierry MERLE | 483dfdb | 2006-12-04 08:31:45 -0300 | [diff] [blame] | 432 | usbvision_release(usbvision); |
Dan Carpenter | 470a914 | 2014-10-16 04:57:21 -0300 | [diff] [blame] | 433 | return 0; |
Thierry MERLE | 483dfdb | 2006-12-04 08:31:45 -0300 | [diff] [blame] | 434 | } |
Hans Verkuil | 4d34570 | 2012-06-23 08:03:50 -0300 | [diff] [blame] | 435 | mutex_unlock(&usbvision->v4l2_lock); |
Thierry MERLE | 483dfdb | 2006-12-04 08:31:45 -0300 | [diff] [blame] | 436 | |
| 437 | PDEBUG(DBG_IO, "success"); |
Hans Verkuil | fd95870 | 2015-07-20 09:59:29 -0300 | [diff] [blame^] | 438 | return v4l2_fh_release(file); |
Thierry MERLE | 483dfdb | 2006-12-04 08:31:45 -0300 | [diff] [blame] | 439 | } |
| 440 | |
| 441 | |
| 442 | /* |
| 443 | * usbvision_ioctl() |
| 444 | * |
| 445 | * This is part of Video 4 Linux API. The procedure handles ioctl() calls. |
| 446 | * |
| 447 | */ |
Thierry MERLE | c5f4836 | 2007-05-08 17:22:29 -0300 | [diff] [blame] | 448 | #ifdef CONFIG_VIDEO_ADV_DEBUG |
Hans Verkuil | 6d6a48e | 2010-12-29 13:53:21 -0300 | [diff] [blame] | 449 | static int vidioc_g_register(struct file *file, void *priv, |
Hans Verkuil | aecde8b5 | 2008-12-30 07:14:19 -0300 | [diff] [blame] | 450 | struct v4l2_dbg_register *reg) |
Thierry MERLE | 483dfdb | 2006-12-04 08:31:45 -0300 | [diff] [blame] | 451 | { |
Hans Verkuil | c170ecf | 2008-08-23 08:32:09 -0300 | [diff] [blame] | 452 | struct usb_usbvision *usbvision = video_drvdata(file); |
Hans Verkuil | 5490a7c | 2010-12-19 20:21:36 -0300 | [diff] [blame] | 453 | int err_code; |
Thierry MERLE | 483dfdb | 2006-12-04 08:31:45 -0300 | [diff] [blame] | 454 | |
Thierry MERLE | c5f4836 | 2007-05-08 17:22:29 -0300 | [diff] [blame] | 455 | /* NT100x has a 8-bit register space */ |
Hans Verkuil | 5490a7c | 2010-12-19 20:21:36 -0300 | [diff] [blame] | 456 | err_code = usbvision_read_reg(usbvision, reg->reg&0xff); |
| 457 | if (err_code < 0) { |
Hans Verkuil | 2aa689d | 2015-03-09 13:34:12 -0300 | [diff] [blame] | 458 | dev_err(&usbvision->vdev.dev, |
Mauro Carvalho Chehab | be9ed51 | 2009-01-08 09:13:42 -0300 | [diff] [blame] | 459 | "%s: VIDIOC_DBG_G_REGISTER failed: error %d\n", |
Hans Verkuil | 5490a7c | 2010-12-19 20:21:36 -0300 | [diff] [blame] | 460 | __func__, err_code); |
| 461 | return err_code; |
Thierry MERLE | 483dfdb | 2006-12-04 08:31:45 -0300 | [diff] [blame] | 462 | } |
Hans Verkuil | 5490a7c | 2010-12-19 20:21:36 -0300 | [diff] [blame] | 463 | reg->val = err_code; |
Hans Verkuil | aecde8b5 | 2008-12-30 07:14:19 -0300 | [diff] [blame] | 464 | reg->size = 1; |
Thierry MERLE | 483dfdb | 2006-12-04 08:31:45 -0300 | [diff] [blame] | 465 | return 0; |
| 466 | } |
| 467 | |
Hans Verkuil | 6d6a48e | 2010-12-29 13:53:21 -0300 | [diff] [blame] | 468 | static int vidioc_s_register(struct file *file, void *priv, |
Hans Verkuil | 977ba3b | 2013-03-24 08:28:46 -0300 | [diff] [blame] | 469 | const struct v4l2_dbg_register *reg) |
Thierry MERLE | 483dfdb | 2006-12-04 08:31:45 -0300 | [diff] [blame] | 470 | { |
Hans Verkuil | c170ecf | 2008-08-23 08:32:09 -0300 | [diff] [blame] | 471 | struct usb_usbvision *usbvision = video_drvdata(file); |
Hans Verkuil | 5490a7c | 2010-12-19 20:21:36 -0300 | [diff] [blame] | 472 | int err_code; |
Thierry MERLE | c5f4836 | 2007-05-08 17:22:29 -0300 | [diff] [blame] | 473 | |
Thierry MERLE | c5f4836 | 2007-05-08 17:22:29 -0300 | [diff] [blame] | 474 | /* NT100x has a 8-bit register space */ |
Hans Verkuil | 6d6a48e | 2010-12-29 13:53:21 -0300 | [diff] [blame] | 475 | err_code = usbvision_write_reg(usbvision, reg->reg & 0xff, reg->val); |
Hans Verkuil | 5490a7c | 2010-12-19 20:21:36 -0300 | [diff] [blame] | 476 | if (err_code < 0) { |
Hans Verkuil | 2aa689d | 2015-03-09 13:34:12 -0300 | [diff] [blame] | 477 | dev_err(&usbvision->vdev.dev, |
Mauro Carvalho Chehab | be9ed51 | 2009-01-08 09:13:42 -0300 | [diff] [blame] | 478 | "%s: VIDIOC_DBG_S_REGISTER failed: error %d\n", |
Hans Verkuil | 5490a7c | 2010-12-19 20:21:36 -0300 | [diff] [blame] | 479 | __func__, err_code); |
| 480 | return err_code; |
Thierry MERLE | c5f4836 | 2007-05-08 17:22:29 -0300 | [diff] [blame] | 481 | } |
| 482 | return 0; |
| 483 | } |
| 484 | #endif |
| 485 | |
Hans Verkuil | 6d6a48e | 2010-12-29 13:53:21 -0300 | [diff] [blame] | 486 | static int vidioc_querycap(struct file *file, void *priv, |
Thierry MERLE | c5f4836 | 2007-05-08 17:22:29 -0300 | [diff] [blame] | 487 | struct v4l2_capability *vc) |
| 488 | { |
Hans Verkuil | c170ecf | 2008-08-23 08:32:09 -0300 | [diff] [blame] | 489 | struct usb_usbvision *usbvision = video_drvdata(file); |
Thierry MERLE | c5f4836 | 2007-05-08 17:22:29 -0300 | [diff] [blame] | 490 | |
| 491 | strlcpy(vc->driver, "USBVision", sizeof(vc->driver)); |
| 492 | strlcpy(vc->card, |
Hans Verkuil | 5490a7c | 2010-12-19 20:21:36 -0300 | [diff] [blame] | 493 | usbvision_device_data[usbvision->dev_model].model_string, |
Thierry MERLE | c5f4836 | 2007-05-08 17:22:29 -0300 | [diff] [blame] | 494 | sizeof(vc->card)); |
Thierry MERLE | 6f2a278 | 2009-01-20 17:40:44 -0300 | [diff] [blame] | 495 | usb_make_path(usbvision->dev, vc->bus_info, sizeof(vc->bus_info)); |
Hans Verkuil | 2eb3b1a | 2014-11-24 06:37:23 -0300 | [diff] [blame] | 496 | vc->device_caps = V4L2_CAP_VIDEO_CAPTURE | |
Thierry MERLE | c5f4836 | 2007-05-08 17:22:29 -0300 | [diff] [blame] | 497 | V4L2_CAP_AUDIO | |
| 498 | V4L2_CAP_READWRITE | |
| 499 | V4L2_CAP_STREAMING | |
| 500 | (usbvision->have_tuner ? V4L2_CAP_TUNER : 0); |
Hans Verkuil | 2eb3b1a | 2014-11-24 06:37:23 -0300 | [diff] [blame] | 501 | vc->capabilities = vc->device_caps | V4L2_CAP_DEVICE_CAPS; |
Thierry MERLE | c5f4836 | 2007-05-08 17:22:29 -0300 | [diff] [blame] | 502 | return 0; |
Thierry MERLE | 483dfdb | 2006-12-04 08:31:45 -0300 | [diff] [blame] | 503 | } |
| 504 | |
Hans Verkuil | 6d6a48e | 2010-12-29 13:53:21 -0300 | [diff] [blame] | 505 | static int vidioc_enum_input(struct file *file, void *priv, |
Thierry MERLE | c5f4836 | 2007-05-08 17:22:29 -0300 | [diff] [blame] | 506 | struct v4l2_input *vi) |
| 507 | { |
Hans Verkuil | c170ecf | 2008-08-23 08:32:09 -0300 | [diff] [blame] | 508 | struct usb_usbvision *usbvision = video_drvdata(file); |
Thierry MERLE | c5f4836 | 2007-05-08 17:22:29 -0300 | [diff] [blame] | 509 | int chan; |
| 510 | |
Roel Kluin | 223ffe5 | 2009-05-02 16:38:47 -0300 | [diff] [blame] | 511 | if (vi->index >= usbvision->video_inputs) |
Thierry MERLE | c5f4836 | 2007-05-08 17:22:29 -0300 | [diff] [blame] | 512 | return -EINVAL; |
Hans Verkuil | 6d6a48e | 2010-12-29 13:53:21 -0300 | [diff] [blame] | 513 | if (usbvision->have_tuner) |
Thierry MERLE | c5f4836 | 2007-05-08 17:22:29 -0300 | [diff] [blame] | 514 | chan = vi->index; |
Hans Verkuil | 6d6a48e | 2010-12-29 13:53:21 -0300 | [diff] [blame] | 515 | else |
Hans Verkuil | 52cb0bf | 2010-12-19 20:33:51 -0300 | [diff] [blame] | 516 | chan = vi->index + 1; /* skip Television string*/ |
Hans Verkuil | 6d6a48e | 2010-12-29 13:53:21 -0300 | [diff] [blame] | 517 | |
Thierry MERLE | c5f4836 | 2007-05-08 17:22:29 -0300 | [diff] [blame] | 518 | /* Determine the requested input characteristics |
| 519 | specific for each usbvision card model */ |
Hans Verkuil | 6d6a48e | 2010-12-29 13:53:21 -0300 | [diff] [blame] | 520 | switch (chan) { |
Thierry MERLE | c5f4836 | 2007-05-08 17:22:29 -0300 | [diff] [blame] | 521 | case 0: |
Hans Verkuil | 5490a7c | 2010-12-19 20:21:36 -0300 | [diff] [blame] | 522 | if (usbvision_device_data[usbvision->dev_model].video_channels == 4) { |
Thierry MERLE | c5f4836 | 2007-05-08 17:22:29 -0300 | [diff] [blame] | 523 | strcpy(vi->name, "White Video Input"); |
| 524 | } else { |
| 525 | strcpy(vi->name, "Television"); |
| 526 | vi->type = V4L2_INPUT_TYPE_TUNER; |
| 527 | vi->audioset = 1; |
| 528 | vi->tuner = chan; |
| 529 | vi->std = USBVISION_NORMS; |
| 530 | } |
| 531 | break; |
| 532 | case 1: |
| 533 | vi->type = V4L2_INPUT_TYPE_CAMERA; |
Hans Verkuil | 6d6a48e | 2010-12-29 13:53:21 -0300 | [diff] [blame] | 534 | if (usbvision_device_data[usbvision->dev_model].video_channels == 4) |
Thierry MERLE | c5f4836 | 2007-05-08 17:22:29 -0300 | [diff] [blame] | 535 | strcpy(vi->name, "Green Video Input"); |
Hans Verkuil | 6d6a48e | 2010-12-29 13:53:21 -0300 | [diff] [blame] | 536 | else |
Thierry MERLE | c5f4836 | 2007-05-08 17:22:29 -0300 | [diff] [blame] | 537 | strcpy(vi->name, "Composite Video Input"); |
Thierry MERLE | c5f4836 | 2007-05-08 17:22:29 -0300 | [diff] [blame] | 538 | vi->std = V4L2_STD_PAL; |
| 539 | break; |
| 540 | case 2: |
| 541 | vi->type = V4L2_INPUT_TYPE_CAMERA; |
Hans Verkuil | 6d6a48e | 2010-12-29 13:53:21 -0300 | [diff] [blame] | 542 | if (usbvision_device_data[usbvision->dev_model].video_channels == 4) |
Thierry MERLE | c5f4836 | 2007-05-08 17:22:29 -0300 | [diff] [blame] | 543 | strcpy(vi->name, "Yellow Video Input"); |
Hans Verkuil | 6d6a48e | 2010-12-29 13:53:21 -0300 | [diff] [blame] | 544 | else |
Thierry MERLE | c5f4836 | 2007-05-08 17:22:29 -0300 | [diff] [blame] | 545 | strcpy(vi->name, "S-Video Input"); |
Thierry MERLE | c5f4836 | 2007-05-08 17:22:29 -0300 | [diff] [blame] | 546 | vi->std = V4L2_STD_PAL; |
| 547 | break; |
| 548 | case 3: |
| 549 | vi->type = V4L2_INPUT_TYPE_CAMERA; |
| 550 | strcpy(vi->name, "Red Video Input"); |
| 551 | vi->std = V4L2_STD_PAL; |
| 552 | break; |
| 553 | } |
| 554 | return 0; |
| 555 | } |
| 556 | |
Hans Verkuil | 6d6a48e | 2010-12-29 13:53:21 -0300 | [diff] [blame] | 557 | static int vidioc_g_input(struct file *file, void *priv, unsigned int *input) |
Thierry MERLE | c5f4836 | 2007-05-08 17:22:29 -0300 | [diff] [blame] | 558 | { |
Hans Verkuil | c170ecf | 2008-08-23 08:32:09 -0300 | [diff] [blame] | 559 | struct usb_usbvision *usbvision = video_drvdata(file); |
Thierry MERLE | c5f4836 | 2007-05-08 17:22:29 -0300 | [diff] [blame] | 560 | |
| 561 | *input = usbvision->ctl_input; |
| 562 | return 0; |
| 563 | } |
| 564 | |
Hans Verkuil | 6d6a48e | 2010-12-29 13:53:21 -0300 | [diff] [blame] | 565 | static int vidioc_s_input(struct file *file, void *priv, unsigned int input) |
Thierry MERLE | c5f4836 | 2007-05-08 17:22:29 -0300 | [diff] [blame] | 566 | { |
Hans Verkuil | c170ecf | 2008-08-23 08:32:09 -0300 | [diff] [blame] | 567 | struct usb_usbvision *usbvision = video_drvdata(file); |
Thierry MERLE | c5f4836 | 2007-05-08 17:22:29 -0300 | [diff] [blame] | 568 | |
Roel Kluin | f14a297 | 2009-10-23 07:59:42 -0300 | [diff] [blame] | 569 | if (input >= usbvision->video_inputs) |
Thierry MERLE | c5f4836 | 2007-05-08 17:22:29 -0300 | [diff] [blame] | 570 | return -EINVAL; |
Thierry MERLE | c5f4836 | 2007-05-08 17:22:29 -0300 | [diff] [blame] | 571 | |
Thierry MERLE | 66a1787 | 2007-06-26 16:35:30 -0300 | [diff] [blame] | 572 | usbvision_muxsel(usbvision, input); |
Thierry MERLE | c5f4836 | 2007-05-08 17:22:29 -0300 | [diff] [blame] | 573 | usbvision_set_input(usbvision); |
| 574 | usbvision_set_output(usbvision, |
| 575 | usbvision->curwidth, |
| 576 | usbvision->curheight); |
Thierry MERLE | c5f4836 | 2007-05-08 17:22:29 -0300 | [diff] [blame] | 577 | return 0; |
| 578 | } |
| 579 | |
Hans Verkuil | 314527a | 2013-03-15 06:10:40 -0300 | [diff] [blame] | 580 | static int vidioc_s_std(struct file *file, void *priv, v4l2_std_id id) |
Thierry MERLE | c5f4836 | 2007-05-08 17:22:29 -0300 | [diff] [blame] | 581 | { |
Hans Verkuil | c170ecf | 2008-08-23 08:32:09 -0300 | [diff] [blame] | 582 | struct usb_usbvision *usbvision = video_drvdata(file); |
| 583 | |
Hans Verkuil | 314527a | 2013-03-15 06:10:40 -0300 | [diff] [blame] | 584 | usbvision->tvnorm_id = id; |
Thierry MERLE | c5f4836 | 2007-05-08 17:22:29 -0300 | [diff] [blame] | 585 | |
Laurent Pinchart | 8774bed | 2014-04-28 16:53:01 -0300 | [diff] [blame] | 586 | call_all(usbvision, video, s_std, usbvision->tvnorm_id); |
Thierry MERLE | 66a1787 | 2007-06-26 16:35:30 -0300 | [diff] [blame] | 587 | /* propagate the change to the decoder */ |
| 588 | usbvision_muxsel(usbvision, usbvision->ctl_input); |
Thierry MERLE | c5f4836 | 2007-05-08 17:22:29 -0300 | [diff] [blame] | 589 | |
| 590 | return 0; |
| 591 | } |
| 592 | |
Hans Verkuil | 3b8436d | 2013-06-03 05:36:47 -0300 | [diff] [blame] | 593 | static int vidioc_g_std(struct file *file, void *priv, v4l2_std_id *id) |
| 594 | { |
| 595 | struct usb_usbvision *usbvision = video_drvdata(file); |
| 596 | |
| 597 | *id = usbvision->tvnorm_id; |
| 598 | return 0; |
| 599 | } |
| 600 | |
Hans Verkuil | 6d6a48e | 2010-12-29 13:53:21 -0300 | [diff] [blame] | 601 | static int vidioc_g_tuner(struct file *file, void *priv, |
Thierry MERLE | c5f4836 | 2007-05-08 17:22:29 -0300 | [diff] [blame] | 602 | struct v4l2_tuner *vt) |
| 603 | { |
Hans Verkuil | c170ecf | 2008-08-23 08:32:09 -0300 | [diff] [blame] | 604 | struct usb_usbvision *usbvision = video_drvdata(file); |
Thierry MERLE | c5f4836 | 2007-05-08 17:22:29 -0300 | [diff] [blame] | 605 | |
Hans Verkuil | 52cb0bf | 2010-12-19 20:33:51 -0300 | [diff] [blame] | 606 | if (!usbvision->have_tuner || vt->index) /* Only tuner 0 */ |
Thierry MERLE | c5f4836 | 2007-05-08 17:22:29 -0300 | [diff] [blame] | 607 | return -EINVAL; |
Hans Verkuil | 6d6a48e | 2010-12-29 13:53:21 -0300 | [diff] [blame] | 608 | if (usbvision->radio) { |
Thierry MERLE | c5f4836 | 2007-05-08 17:22:29 -0300 | [diff] [blame] | 609 | strcpy(vt->name, "Radio"); |
| 610 | vt->type = V4L2_TUNER_RADIO; |
| 611 | } else { |
| 612 | strcpy(vt->name, "Television"); |
| 613 | } |
| 614 | /* Let clients fill in the remainder of this struct */ |
Hans Verkuil | 1df7953 | 2009-02-21 18:11:31 -0300 | [diff] [blame] | 615 | call_all(usbvision, tuner, g_tuner, vt); |
Thierry MERLE | c5f4836 | 2007-05-08 17:22:29 -0300 | [diff] [blame] | 616 | |
| 617 | return 0; |
| 618 | } |
| 619 | |
Hans Verkuil | 6d6a48e | 2010-12-29 13:53:21 -0300 | [diff] [blame] | 620 | static int vidioc_s_tuner(struct file *file, void *priv, |
Hans Verkuil | 2f73c7c | 2013-03-15 06:10:06 -0300 | [diff] [blame] | 621 | const struct v4l2_tuner *vt) |
Thierry MERLE | c5f4836 | 2007-05-08 17:22:29 -0300 | [diff] [blame] | 622 | { |
Hans Verkuil | c170ecf | 2008-08-23 08:32:09 -0300 | [diff] [blame] | 623 | struct usb_usbvision *usbvision = video_drvdata(file); |
Thierry MERLE | c5f4836 | 2007-05-08 17:22:29 -0300 | [diff] [blame] | 624 | |
Hans Verkuil | 52cb0bf | 2010-12-19 20:33:51 -0300 | [diff] [blame] | 625 | /* Only no or one tuner for now */ |
Thierry MERLE | c5f4836 | 2007-05-08 17:22:29 -0300 | [diff] [blame] | 626 | if (!usbvision->have_tuner || vt->index) |
| 627 | return -EINVAL; |
| 628 | /* let clients handle this */ |
Hans Verkuil | 1df7953 | 2009-02-21 18:11:31 -0300 | [diff] [blame] | 629 | call_all(usbvision, tuner, s_tuner, vt); |
Thierry MERLE | c5f4836 | 2007-05-08 17:22:29 -0300 | [diff] [blame] | 630 | |
| 631 | return 0; |
| 632 | } |
| 633 | |
Hans Verkuil | 6d6a48e | 2010-12-29 13:53:21 -0300 | [diff] [blame] | 634 | static int vidioc_g_frequency(struct file *file, void *priv, |
Thierry MERLE | c5f4836 | 2007-05-08 17:22:29 -0300 | [diff] [blame] | 635 | struct v4l2_frequency *freq) |
| 636 | { |
Hans Verkuil | c170ecf | 2008-08-23 08:32:09 -0300 | [diff] [blame] | 637 | struct usb_usbvision *usbvision = video_drvdata(file); |
Thierry MERLE | c5f4836 | 2007-05-08 17:22:29 -0300 | [diff] [blame] | 638 | |
Hans Verkuil | 52cb0bf | 2010-12-19 20:33:51 -0300 | [diff] [blame] | 639 | freq->tuner = 0; /* Only one tuner */ |
Hans Verkuil | 6d6a48e | 2010-12-29 13:53:21 -0300 | [diff] [blame] | 640 | if (usbvision->radio) |
Thierry MERLE | c5f4836 | 2007-05-08 17:22:29 -0300 | [diff] [blame] | 641 | freq->type = V4L2_TUNER_RADIO; |
Hans Verkuil | 6d6a48e | 2010-12-29 13:53:21 -0300 | [diff] [blame] | 642 | else |
Thierry MERLE | c5f4836 | 2007-05-08 17:22:29 -0300 | [diff] [blame] | 643 | freq->type = V4L2_TUNER_ANALOG_TV; |
Thierry MERLE | c5f4836 | 2007-05-08 17:22:29 -0300 | [diff] [blame] | 644 | freq->frequency = usbvision->freq; |
| 645 | |
| 646 | return 0; |
| 647 | } |
| 648 | |
Hans Verkuil | 6d6a48e | 2010-12-29 13:53:21 -0300 | [diff] [blame] | 649 | static int vidioc_s_frequency(struct file *file, void *priv, |
Hans Verkuil | b530a44 | 2013-03-19 04:09:26 -0300 | [diff] [blame] | 650 | const struct v4l2_frequency *freq) |
Thierry MERLE | c5f4836 | 2007-05-08 17:22:29 -0300 | [diff] [blame] | 651 | { |
Hans Verkuil | c170ecf | 2008-08-23 08:32:09 -0300 | [diff] [blame] | 652 | struct usb_usbvision *usbvision = video_drvdata(file); |
Thierry MERLE | c5f4836 | 2007-05-08 17:22:29 -0300 | [diff] [blame] | 653 | |
Hans Verkuil | 52cb0bf | 2010-12-19 20:33:51 -0300 | [diff] [blame] | 654 | /* Only no or one tuner for now */ |
Thierry MERLE | c5f4836 | 2007-05-08 17:22:29 -0300 | [diff] [blame] | 655 | if (!usbvision->have_tuner || freq->tuner) |
| 656 | return -EINVAL; |
| 657 | |
| 658 | usbvision->freq = freq->frequency; |
Hans Verkuil | 1df7953 | 2009-02-21 18:11:31 -0300 | [diff] [blame] | 659 | call_all(usbvision, tuner, s_frequency, freq); |
Thierry MERLE | c5f4836 | 2007-05-08 17:22:29 -0300 | [diff] [blame] | 660 | |
| 661 | return 0; |
| 662 | } |
| 663 | |
Hans Verkuil | 6d6a48e | 2010-12-29 13:53:21 -0300 | [diff] [blame] | 664 | static int vidioc_g_audio(struct file *file, void *priv, struct v4l2_audio *a) |
Thierry MERLE | c5f4836 | 2007-05-08 17:22:29 -0300 | [diff] [blame] | 665 | { |
Hans Verkuil | c170ecf | 2008-08-23 08:32:09 -0300 | [diff] [blame] | 666 | struct usb_usbvision *usbvision = video_drvdata(file); |
Thierry MERLE | c5f4836 | 2007-05-08 17:22:29 -0300 | [diff] [blame] | 667 | |
Hans Verkuil | 6d6a48e | 2010-12-29 13:53:21 -0300 | [diff] [blame] | 668 | if (usbvision->radio) |
| 669 | strcpy(a->name, "Radio"); |
| 670 | else |
Thierry MERLE | c5f4836 | 2007-05-08 17:22:29 -0300 | [diff] [blame] | 671 | strcpy(a->name, "TV"); |
Thierry MERLE | c5f4836 | 2007-05-08 17:22:29 -0300 | [diff] [blame] | 672 | |
| 673 | return 0; |
| 674 | } |
| 675 | |
Hans Verkuil | 6d6a48e | 2010-12-29 13:53:21 -0300 | [diff] [blame] | 676 | static int vidioc_s_audio(struct file *file, void *fh, |
Hans Verkuil | 0e8025b9 | 2012-09-04 11:59:31 -0300 | [diff] [blame] | 677 | const struct v4l2_audio *a) |
Thierry MERLE | c5f4836 | 2007-05-08 17:22:29 -0300 | [diff] [blame] | 678 | { |
Hans Verkuil | 6d6a48e | 2010-12-29 13:53:21 -0300 | [diff] [blame] | 679 | if (a->index) |
Thierry MERLE | c5f4836 | 2007-05-08 17:22:29 -0300 | [diff] [blame] | 680 | return -EINVAL; |
Thierry MERLE | c5f4836 | 2007-05-08 17:22:29 -0300 | [diff] [blame] | 681 | return 0; |
| 682 | } |
| 683 | |
Hans Verkuil | 6d6a48e | 2010-12-29 13:53:21 -0300 | [diff] [blame] | 684 | static int vidioc_reqbufs(struct file *file, |
Thierry MERLE | c5f4836 | 2007-05-08 17:22:29 -0300 | [diff] [blame] | 685 | void *priv, struct v4l2_requestbuffers *vr) |
| 686 | { |
Hans Verkuil | c170ecf | 2008-08-23 08:32:09 -0300 | [diff] [blame] | 687 | struct usb_usbvision *usbvision = video_drvdata(file); |
Thierry MERLE | c5f4836 | 2007-05-08 17:22:29 -0300 | [diff] [blame] | 688 | int ret; |
| 689 | |
Hans Verkuil | 6d6a48e | 2010-12-29 13:53:21 -0300 | [diff] [blame] | 690 | RESTRICT_TO_RANGE(vr->count, 1, USBVISION_NUMFRAMES); |
Thierry MERLE | c5f4836 | 2007-05-08 17:22:29 -0300 | [diff] [blame] | 691 | |
| 692 | /* Check input validity: |
| 693 | the user must do a VIDEO CAPTURE and MMAP method. */ |
Trent Piepho | 975f576 | 2009-03-28 22:25:36 -0300 | [diff] [blame] | 694 | if (vr->memory != V4L2_MEMORY_MMAP) |
Thierry MERLE | c5f4836 | 2007-05-08 17:22:29 -0300 | [diff] [blame] | 695 | return -EINVAL; |
| 696 | |
Hans Verkuil | 6d6a48e | 2010-12-29 13:53:21 -0300 | [diff] [blame] | 697 | if (usbvision->streaming == stream_on) { |
| 698 | ret = usbvision_stream_interrupt(usbvision); |
| 699 | if (ret) |
Thierry MERLE | c5f4836 | 2007-05-08 17:22:29 -0300 | [diff] [blame] | 700 | return ret; |
| 701 | } |
| 702 | |
| 703 | usbvision_frames_free(usbvision); |
| 704 | usbvision_empty_framequeues(usbvision); |
Hans Verkuil | 6d6a48e | 2010-12-29 13:53:21 -0300 | [diff] [blame] | 705 | vr->count = usbvision_frames_alloc(usbvision, vr->count); |
Thierry MERLE | c5f4836 | 2007-05-08 17:22:29 -0300 | [diff] [blame] | 706 | |
Hans Verkuil | 5490a7c | 2010-12-19 20:21:36 -0300 | [diff] [blame] | 707 | usbvision->cur_frame = NULL; |
Thierry MERLE | c5f4836 | 2007-05-08 17:22:29 -0300 | [diff] [blame] | 708 | |
| 709 | return 0; |
| 710 | } |
| 711 | |
Hans Verkuil | 6d6a48e | 2010-12-29 13:53:21 -0300 | [diff] [blame] | 712 | static int vidioc_querybuf(struct file *file, |
Thierry MERLE | c5f4836 | 2007-05-08 17:22:29 -0300 | [diff] [blame] | 713 | void *priv, struct v4l2_buffer *vb) |
| 714 | { |
Hans Verkuil | c170ecf | 2008-08-23 08:32:09 -0300 | [diff] [blame] | 715 | struct usb_usbvision *usbvision = video_drvdata(file); |
Thierry MERLE | c5f4836 | 2007-05-08 17:22:29 -0300 | [diff] [blame] | 716 | struct usbvision_frame *frame; |
| 717 | |
| 718 | /* FIXME : must control |
| 719 | that buffers are mapped (VIDIOC_REQBUFS has been called) */ |
Hans Verkuil | 6d6a48e | 2010-12-29 13:53:21 -0300 | [diff] [blame] | 720 | if (vb->index >= usbvision->num_frames) |
Thierry MERLE | c5f4836 | 2007-05-08 17:22:29 -0300 | [diff] [blame] | 721 | return -EINVAL; |
Thierry MERLE | c5f4836 | 2007-05-08 17:22:29 -0300 | [diff] [blame] | 722 | /* Updating the corresponding frame state */ |
Sakari Ailus | 1b18e7a | 2012-10-22 17:10:16 -0300 | [diff] [blame] | 723 | vb->flags = V4L2_BUF_FLAG_TIMESTAMP_MONOTONIC; |
Thierry MERLE | c5f4836 | 2007-05-08 17:22:29 -0300 | [diff] [blame] | 724 | frame = &usbvision->frame[vb->index]; |
Hans Verkuil | 6d6a48e | 2010-12-29 13:53:21 -0300 | [diff] [blame] | 725 | if (frame->grabstate >= frame_state_ready) |
Thierry MERLE | c5f4836 | 2007-05-08 17:22:29 -0300 | [diff] [blame] | 726 | vb->flags |= V4L2_BUF_FLAG_QUEUED; |
Hans Verkuil | 6d6a48e | 2010-12-29 13:53:21 -0300 | [diff] [blame] | 727 | if (frame->grabstate >= frame_state_done) |
Thierry MERLE | c5f4836 | 2007-05-08 17:22:29 -0300 | [diff] [blame] | 728 | vb->flags |= V4L2_BUF_FLAG_DONE; |
Hans Verkuil | 6d6a48e | 2010-12-29 13:53:21 -0300 | [diff] [blame] | 729 | if (frame->grabstate == frame_state_unused) |
Thierry MERLE | c5f4836 | 2007-05-08 17:22:29 -0300 | [diff] [blame] | 730 | vb->flags |= V4L2_BUF_FLAG_MAPPED; |
| 731 | vb->memory = V4L2_MEMORY_MMAP; |
| 732 | |
Hans Verkuil | 6d6a48e | 2010-12-29 13:53:21 -0300 | [diff] [blame] | 733 | vb->m.offset = vb->index * PAGE_ALIGN(usbvision->max_frame_size); |
Thierry MERLE | c5f4836 | 2007-05-08 17:22:29 -0300 | [diff] [blame] | 734 | |
| 735 | vb->memory = V4L2_MEMORY_MMAP; |
| 736 | vb->field = V4L2_FIELD_NONE; |
Hans Verkuil | 6d6a48e | 2010-12-29 13:53:21 -0300 | [diff] [blame] | 737 | vb->length = usbvision->curwidth * |
| 738 | usbvision->curheight * |
Thierry MERLE | c5f4836 | 2007-05-08 17:22:29 -0300 | [diff] [blame] | 739 | usbvision->palette.bytes_per_pixel; |
| 740 | vb->timestamp = usbvision->frame[vb->index].timestamp; |
| 741 | vb->sequence = usbvision->frame[vb->index].sequence; |
| 742 | return 0; |
| 743 | } |
| 744 | |
Hans Verkuil | 6d6a48e | 2010-12-29 13:53:21 -0300 | [diff] [blame] | 745 | static int vidioc_qbuf(struct file *file, void *priv, struct v4l2_buffer *vb) |
Thierry MERLE | c5f4836 | 2007-05-08 17:22:29 -0300 | [diff] [blame] | 746 | { |
Hans Verkuil | c170ecf | 2008-08-23 08:32:09 -0300 | [diff] [blame] | 747 | struct usb_usbvision *usbvision = video_drvdata(file); |
Thierry MERLE | c5f4836 | 2007-05-08 17:22:29 -0300 | [diff] [blame] | 748 | struct usbvision_frame *frame; |
| 749 | unsigned long lock_flags; |
| 750 | |
| 751 | /* FIXME : works only on VIDEO_CAPTURE MODE, MMAP. */ |
Hans Verkuil | 6d6a48e | 2010-12-29 13:53:21 -0300 | [diff] [blame] | 752 | if (vb->index >= usbvision->num_frames) |
Thierry MERLE | c5f4836 | 2007-05-08 17:22:29 -0300 | [diff] [blame] | 753 | return -EINVAL; |
Thierry MERLE | c5f4836 | 2007-05-08 17:22:29 -0300 | [diff] [blame] | 754 | |
| 755 | frame = &usbvision->frame[vb->index]; |
| 756 | |
Hans Verkuil | 6d6a48e | 2010-12-29 13:53:21 -0300 | [diff] [blame] | 757 | if (frame->grabstate != frame_state_unused) |
Thierry MERLE | c5f4836 | 2007-05-08 17:22:29 -0300 | [diff] [blame] | 758 | return -EAGAIN; |
Thierry MERLE | c5f4836 | 2007-05-08 17:22:29 -0300 | [diff] [blame] | 759 | |
| 760 | /* Mark it as ready and enqueue frame */ |
Hans Verkuil | 5490a7c | 2010-12-19 20:21:36 -0300 | [diff] [blame] | 761 | frame->grabstate = frame_state_ready; |
| 762 | frame->scanstate = scan_state_scanning; |
Thierry MERLE | c5f4836 | 2007-05-08 17:22:29 -0300 | [diff] [blame] | 763 | frame->scanlength = 0; /* Accumulated in usbvision_parse_data() */ |
| 764 | |
| 765 | vb->flags &= ~V4L2_BUF_FLAG_DONE; |
| 766 | |
| 767 | /* set v4l2_format index */ |
| 768 | frame->v4l2_format = usbvision->palette; |
| 769 | |
| 770 | spin_lock_irqsave(&usbvision->queue_lock, lock_flags); |
| 771 | list_add_tail(&usbvision->frame[vb->index].frame, &usbvision->inqueue); |
| 772 | spin_unlock_irqrestore(&usbvision->queue_lock, lock_flags); |
| 773 | |
| 774 | return 0; |
| 775 | } |
| 776 | |
Hans Verkuil | 6d6a48e | 2010-12-29 13:53:21 -0300 | [diff] [blame] | 777 | static int vidioc_dqbuf(struct file *file, void *priv, struct v4l2_buffer *vb) |
Thierry MERLE | c5f4836 | 2007-05-08 17:22:29 -0300 | [diff] [blame] | 778 | { |
Hans Verkuil | c170ecf | 2008-08-23 08:32:09 -0300 | [diff] [blame] | 779 | struct usb_usbvision *usbvision = video_drvdata(file); |
Thierry MERLE | c5f4836 | 2007-05-08 17:22:29 -0300 | [diff] [blame] | 780 | int ret; |
| 781 | struct usbvision_frame *f; |
| 782 | unsigned long lock_flags; |
| 783 | |
Thierry MERLE | c5f4836 | 2007-05-08 17:22:29 -0300 | [diff] [blame] | 784 | if (list_empty(&(usbvision->outqueue))) { |
Hans Verkuil | 5490a7c | 2010-12-19 20:21:36 -0300 | [diff] [blame] | 785 | if (usbvision->streaming == stream_idle) |
Thierry MERLE | c5f4836 | 2007-05-08 17:22:29 -0300 | [diff] [blame] | 786 | return -EINVAL; |
| 787 | ret = wait_event_interruptible |
| 788 | (usbvision->wait_frame, |
| 789 | !list_empty(&(usbvision->outqueue))); |
| 790 | if (ret) |
| 791 | return ret; |
| 792 | } |
| 793 | |
| 794 | spin_lock_irqsave(&usbvision->queue_lock, lock_flags); |
| 795 | f = list_entry(usbvision->outqueue.next, |
| 796 | struct usbvision_frame, frame); |
| 797 | list_del(usbvision->outqueue.next); |
| 798 | spin_unlock_irqrestore(&usbvision->queue_lock, lock_flags); |
| 799 | |
Hans Verkuil | 5490a7c | 2010-12-19 20:21:36 -0300 | [diff] [blame] | 800 | f->grabstate = frame_state_unused; |
Thierry MERLE | c5f4836 | 2007-05-08 17:22:29 -0300 | [diff] [blame] | 801 | |
| 802 | vb->memory = V4L2_MEMORY_MMAP; |
| 803 | vb->flags = V4L2_BUF_FLAG_MAPPED | |
| 804 | V4L2_BUF_FLAG_QUEUED | |
Sakari Ailus | 1b18e7a | 2012-10-22 17:10:16 -0300 | [diff] [blame] | 805 | V4L2_BUF_FLAG_DONE | |
| 806 | V4L2_BUF_FLAG_TIMESTAMP_MONOTONIC; |
Thierry MERLE | c5f4836 | 2007-05-08 17:22:29 -0300 | [diff] [blame] | 807 | vb->index = f->index; |
| 808 | vb->sequence = f->sequence; |
| 809 | vb->timestamp = f->timestamp; |
| 810 | vb->field = V4L2_FIELD_NONE; |
| 811 | vb->bytesused = f->scanlength; |
| 812 | |
| 813 | return 0; |
| 814 | } |
| 815 | |
| 816 | static int vidioc_streamon(struct file *file, void *priv, enum v4l2_buf_type i) |
| 817 | { |
Hans Verkuil | c170ecf | 2008-08-23 08:32:09 -0300 | [diff] [blame] | 818 | struct usb_usbvision *usbvision = video_drvdata(file); |
Thierry MERLE | c5f4836 | 2007-05-08 17:22:29 -0300 | [diff] [blame] | 819 | |
Hans Verkuil | 5490a7c | 2010-12-19 20:21:36 -0300 | [diff] [blame] | 820 | usbvision->streaming = stream_on; |
Hans Verkuil | 1df7953 | 2009-02-21 18:11:31 -0300 | [diff] [blame] | 821 | call_all(usbvision, video, s_stream, 1); |
Thierry MERLE | c5f4836 | 2007-05-08 17:22:29 -0300 | [diff] [blame] | 822 | |
| 823 | return 0; |
| 824 | } |
| 825 | |
| 826 | static int vidioc_streamoff(struct file *file, |
| 827 | void *priv, enum v4l2_buf_type type) |
| 828 | { |
Hans Verkuil | c170ecf | 2008-08-23 08:32:09 -0300 | [diff] [blame] | 829 | struct usb_usbvision *usbvision = video_drvdata(file); |
Thierry MERLE | c5f4836 | 2007-05-08 17:22:29 -0300 | [diff] [blame] | 830 | |
| 831 | if (type != V4L2_BUF_TYPE_VIDEO_CAPTURE) |
| 832 | return -EINVAL; |
| 833 | |
Hans Verkuil | 6d6a48e | 2010-12-29 13:53:21 -0300 | [diff] [blame] | 834 | if (usbvision->streaming == stream_on) { |
Thierry MERLE | c5f4836 | 2007-05-08 17:22:29 -0300 | [diff] [blame] | 835 | usbvision_stream_interrupt(usbvision); |
| 836 | /* Stop all video streamings */ |
Hans Verkuil | 1df7953 | 2009-02-21 18:11:31 -0300 | [diff] [blame] | 837 | call_all(usbvision, video, s_stream, 0); |
Thierry MERLE | c5f4836 | 2007-05-08 17:22:29 -0300 | [diff] [blame] | 838 | } |
| 839 | usbvision_empty_framequeues(usbvision); |
| 840 | |
| 841 | return 0; |
| 842 | } |
| 843 | |
Hans Verkuil | 6d6a48e | 2010-12-29 13:53:21 -0300 | [diff] [blame] | 844 | static int vidioc_enum_fmt_vid_cap(struct file *file, void *priv, |
Thierry MERLE | c5f4836 | 2007-05-08 17:22:29 -0300 | [diff] [blame] | 845 | struct v4l2_fmtdesc *vfd) |
| 846 | { |
Hans Verkuil | 6d6a48e | 2010-12-29 13:53:21 -0300 | [diff] [blame] | 847 | if (vfd->index >= USBVISION_SUPPORTED_PALETTES - 1) |
Thierry MERLE | c5f4836 | 2007-05-08 17:22:29 -0300 | [diff] [blame] | 848 | return -EINVAL; |
Hans Verkuil | 6d6a48e | 2010-12-29 13:53:21 -0300 | [diff] [blame] | 849 | strcpy(vfd->description, usbvision_v4l2_format[vfd->index].desc); |
Thierry MERLE | c5f4836 | 2007-05-08 17:22:29 -0300 | [diff] [blame] | 850 | vfd->pixelformat = usbvision_v4l2_format[vfd->index].format; |
Thierry MERLE | c5f4836 | 2007-05-08 17:22:29 -0300 | [diff] [blame] | 851 | return 0; |
| 852 | } |
| 853 | |
Hans Verkuil | 6d6a48e | 2010-12-29 13:53:21 -0300 | [diff] [blame] | 854 | static int vidioc_g_fmt_vid_cap(struct file *file, void *priv, |
Thierry MERLE | c5f4836 | 2007-05-08 17:22:29 -0300 | [diff] [blame] | 855 | struct v4l2_format *vf) |
| 856 | { |
Hans Verkuil | c170ecf | 2008-08-23 08:32:09 -0300 | [diff] [blame] | 857 | struct usb_usbvision *usbvision = video_drvdata(file); |
Thierry MERLE | c5f4836 | 2007-05-08 17:22:29 -0300 | [diff] [blame] | 858 | vf->fmt.pix.width = usbvision->curwidth; |
| 859 | vf->fmt.pix.height = usbvision->curheight; |
| 860 | vf->fmt.pix.pixelformat = usbvision->palette.format; |
| 861 | vf->fmt.pix.bytesperline = |
Hans Verkuil | 6d6a48e | 2010-12-29 13:53:21 -0300 | [diff] [blame] | 862 | usbvision->curwidth * usbvision->palette.bytes_per_pixel; |
| 863 | vf->fmt.pix.sizeimage = vf->fmt.pix.bytesperline * usbvision->curheight; |
Thierry MERLE | c5f4836 | 2007-05-08 17:22:29 -0300 | [diff] [blame] | 864 | vf->fmt.pix.colorspace = V4L2_COLORSPACE_SMPTE170M; |
| 865 | vf->fmt.pix.field = V4L2_FIELD_NONE; /* Always progressive image */ |
| 866 | |
| 867 | return 0; |
| 868 | } |
| 869 | |
Hans Verkuil | 6d6a48e | 2010-12-29 13:53:21 -0300 | [diff] [blame] | 870 | static int vidioc_try_fmt_vid_cap(struct file *file, void *priv, |
Thierry MERLE | c5f4836 | 2007-05-08 17:22:29 -0300 | [diff] [blame] | 871 | struct v4l2_format *vf) |
| 872 | { |
Hans Verkuil | c170ecf | 2008-08-23 08:32:09 -0300 | [diff] [blame] | 873 | struct usb_usbvision *usbvision = video_drvdata(file); |
Hans Verkuil | 5490a7c | 2010-12-19 20:21:36 -0300 | [diff] [blame] | 874 | int format_idx; |
Thierry MERLE | c5f4836 | 2007-05-08 17:22:29 -0300 | [diff] [blame] | 875 | |
| 876 | /* Find requested format in available ones */ |
Hans Verkuil | 6d6a48e | 2010-12-29 13:53:21 -0300 | [diff] [blame] | 877 | for (format_idx = 0; format_idx < USBVISION_SUPPORTED_PALETTES; format_idx++) { |
| 878 | if (vf->fmt.pix.pixelformat == |
Hans Verkuil | 5490a7c | 2010-12-19 20:21:36 -0300 | [diff] [blame] | 879 | usbvision_v4l2_format[format_idx].format) { |
| 880 | usbvision->palette = usbvision_v4l2_format[format_idx]; |
Thierry MERLE | c5f4836 | 2007-05-08 17:22:29 -0300 | [diff] [blame] | 881 | break; |
| 882 | } |
| 883 | } |
| 884 | /* robustness */ |
Hans Verkuil | 6d6a48e | 2010-12-29 13:53:21 -0300 | [diff] [blame] | 885 | if (format_idx == USBVISION_SUPPORTED_PALETTES) |
Thierry MERLE | c5f4836 | 2007-05-08 17:22:29 -0300 | [diff] [blame] | 886 | return -EINVAL; |
Thierry MERLE | c5f4836 | 2007-05-08 17:22:29 -0300 | [diff] [blame] | 887 | RESTRICT_TO_RANGE(vf->fmt.pix.width, MIN_FRAME_WIDTH, MAX_FRAME_WIDTH); |
| 888 | RESTRICT_TO_RANGE(vf->fmt.pix.height, MIN_FRAME_HEIGHT, MAX_FRAME_HEIGHT); |
| 889 | |
| 890 | vf->fmt.pix.bytesperline = vf->fmt.pix.width* |
| 891 | usbvision->palette.bytes_per_pixel; |
| 892 | vf->fmt.pix.sizeimage = vf->fmt.pix.bytesperline*vf->fmt.pix.height; |
| 893 | |
| 894 | return 0; |
| 895 | } |
| 896 | |
Hans Verkuil | 78b526a | 2008-05-28 12:16:41 -0300 | [diff] [blame] | 897 | static int vidioc_s_fmt_vid_cap(struct file *file, void *priv, |
Thierry MERLE | c5f4836 | 2007-05-08 17:22:29 -0300 | [diff] [blame] | 898 | struct v4l2_format *vf) |
| 899 | { |
Hans Verkuil | c170ecf | 2008-08-23 08:32:09 -0300 | [diff] [blame] | 900 | struct usb_usbvision *usbvision = video_drvdata(file); |
Thierry MERLE | c5f4836 | 2007-05-08 17:22:29 -0300 | [diff] [blame] | 901 | int ret; |
| 902 | |
Hans Verkuil | 6d6a48e | 2010-12-29 13:53:21 -0300 | [diff] [blame] | 903 | ret = vidioc_try_fmt_vid_cap(file, priv, vf); |
| 904 | if (ret) |
Thierry MERLE | c5f4836 | 2007-05-08 17:22:29 -0300 | [diff] [blame] | 905 | return ret; |
Thierry MERLE | c5f4836 | 2007-05-08 17:22:29 -0300 | [diff] [blame] | 906 | |
| 907 | /* stop io in case it is already in progress */ |
Hans Verkuil | 6d6a48e | 2010-12-29 13:53:21 -0300 | [diff] [blame] | 908 | if (usbvision->streaming == stream_on) { |
| 909 | ret = usbvision_stream_interrupt(usbvision); |
| 910 | if (ret) |
Thierry MERLE | c5f4836 | 2007-05-08 17:22:29 -0300 | [diff] [blame] | 911 | return ret; |
| 912 | } |
| 913 | usbvision_frames_free(usbvision); |
| 914 | usbvision_empty_framequeues(usbvision); |
| 915 | |
Hans Verkuil | 5490a7c | 2010-12-19 20:21:36 -0300 | [diff] [blame] | 916 | usbvision->cur_frame = NULL; |
Thierry MERLE | c5f4836 | 2007-05-08 17:22:29 -0300 | [diff] [blame] | 917 | |
| 918 | /* by now we are committed to the new data... */ |
Thierry MERLE | c5f4836 | 2007-05-08 17:22:29 -0300 | [diff] [blame] | 919 | usbvision_set_output(usbvision, vf->fmt.pix.width, vf->fmt.pix.height); |
Thierry MERLE | c5f4836 | 2007-05-08 17:22:29 -0300 | [diff] [blame] | 920 | |
| 921 | return 0; |
| 922 | } |
Thierry MERLE | 483dfdb | 2006-12-04 08:31:45 -0300 | [diff] [blame] | 923 | |
Hans Verkuil | 4d34570 | 2012-06-23 08:03:50 -0300 | [diff] [blame] | 924 | static ssize_t usbvision_read(struct file *file, char __user *buf, |
Thierry MERLE | 483dfdb | 2006-12-04 08:31:45 -0300 | [diff] [blame] | 925 | size_t count, loff_t *ppos) |
| 926 | { |
Hans Verkuil | c170ecf | 2008-08-23 08:32:09 -0300 | [diff] [blame] | 927 | struct usb_usbvision *usbvision = video_drvdata(file); |
Thierry MERLE | 483dfdb | 2006-12-04 08:31:45 -0300 | [diff] [blame] | 928 | int noblock = file->f_flags & O_NONBLOCK; |
| 929 | unsigned long lock_flags; |
Hans Verkuil | 6d6a48e | 2010-12-29 13:53:21 -0300 | [diff] [blame] | 930 | int ret, i; |
Thierry MERLE | 483dfdb | 2006-12-04 08:31:45 -0300 | [diff] [blame] | 931 | struct usbvision_frame *frame; |
| 932 | |
Harvey Harrison | d2db42d | 2008-04-04 20:50:07 -0300 | [diff] [blame] | 933 | PDEBUG(DBG_IO, "%s: %ld bytes, noblock=%d", __func__, |
Thierry MERLE | c5f4836 | 2007-05-08 17:22:29 -0300 | [diff] [blame] | 934 | (unsigned long)count, noblock); |
Thierry MERLE | 483dfdb | 2006-12-04 08:31:45 -0300 | [diff] [blame] | 935 | |
| 936 | if (!USBVISION_IS_OPERATIONAL(usbvision) || (buf == NULL)) |
| 937 | return -EFAULT; |
| 938 | |
Thierry MERLE | c5f4836 | 2007-05-08 17:22:29 -0300 | [diff] [blame] | 939 | /* This entry point is compatible with the mmap routines |
| 940 | so that a user can do either VIDIOC_QBUF/VIDIOC_DQBUF |
| 941 | to get frames or call read on the device. */ |
Hans Verkuil | 6d6a48e | 2010-12-29 13:53:21 -0300 | [diff] [blame] | 942 | if (!usbvision->num_frames) { |
Thierry MERLE | c5f4836 | 2007-05-08 17:22:29 -0300 | [diff] [blame] | 943 | /* First, allocate some frames to work with |
| 944 | if this has not been done with VIDIOC_REQBUF */ |
Thierry MERLE | 6f78e18 | 2007-02-07 10:13:11 -0300 | [diff] [blame] | 945 | usbvision_frames_free(usbvision); |
| 946 | usbvision_empty_framequeues(usbvision); |
Hans Verkuil | 6d6a48e | 2010-12-29 13:53:21 -0300 | [diff] [blame] | 947 | usbvision_frames_alloc(usbvision, USBVISION_NUMFRAMES); |
Thierry MERLE | 6f78e18 | 2007-02-07 10:13:11 -0300 | [diff] [blame] | 948 | } |
Thierry MERLE | 483dfdb | 2006-12-04 08:31:45 -0300 | [diff] [blame] | 949 | |
Hans Verkuil | 6d6a48e | 2010-12-29 13:53:21 -0300 | [diff] [blame] | 950 | if (usbvision->streaming != stream_on) { |
Thierry MERLE | 6f78e18 | 2007-02-07 10:13:11 -0300 | [diff] [blame] | 951 | /* no stream is running, make it running ! */ |
Hans Verkuil | 5490a7c | 2010-12-19 20:21:36 -0300 | [diff] [blame] | 952 | usbvision->streaming = stream_on; |
Hans Verkuil | 1df7953 | 2009-02-21 18:11:31 -0300 | [diff] [blame] | 953 | call_all(usbvision, video, s_stream, 1); |
Thierry MERLE | 6f78e18 | 2007-02-07 10:13:11 -0300 | [diff] [blame] | 954 | } |
| 955 | |
Thierry MERLE | c5f4836 | 2007-05-08 17:22:29 -0300 | [diff] [blame] | 956 | /* Then, enqueue as many frames as possible |
| 957 | (like a user of VIDIOC_QBUF would do) */ |
Hans Verkuil | 6d6a48e | 2010-12-29 13:53:21 -0300 | [diff] [blame] | 958 | for (i = 0; i < usbvision->num_frames; i++) { |
Thierry MERLE | 483dfdb | 2006-12-04 08:31:45 -0300 | [diff] [blame] | 959 | frame = &usbvision->frame[i]; |
Hans Verkuil | 6d6a48e | 2010-12-29 13:53:21 -0300 | [diff] [blame] | 960 | if (frame->grabstate == frame_state_unused) { |
Thierry MERLE | 483dfdb | 2006-12-04 08:31:45 -0300 | [diff] [blame] | 961 | /* Mark it as ready and enqueue frame */ |
Hans Verkuil | 5490a7c | 2010-12-19 20:21:36 -0300 | [diff] [blame] | 962 | frame->grabstate = frame_state_ready; |
| 963 | frame->scanstate = scan_state_scanning; |
Thierry MERLE | c5f4836 | 2007-05-08 17:22:29 -0300 | [diff] [blame] | 964 | /* Accumulated in usbvision_parse_data() */ |
| 965 | frame->scanlength = 0; |
Thierry MERLE | 483dfdb | 2006-12-04 08:31:45 -0300 | [diff] [blame] | 966 | |
| 967 | /* set v4l2_format index */ |
| 968 | frame->v4l2_format = usbvision->palette; |
| 969 | |
| 970 | spin_lock_irqsave(&usbvision->queue_lock, lock_flags); |
| 971 | list_add_tail(&frame->frame, &usbvision->inqueue); |
Thierry MERLE | c5f4836 | 2007-05-08 17:22:29 -0300 | [diff] [blame] | 972 | spin_unlock_irqrestore(&usbvision->queue_lock, |
| 973 | lock_flags); |
Thierry MERLE | 483dfdb | 2006-12-04 08:31:45 -0300 | [diff] [blame] | 974 | } |
| 975 | } |
| 976 | |
| 977 | /* Then try to steal a frame (like a VIDIOC_DQBUF would do) */ |
| 978 | if (list_empty(&(usbvision->outqueue))) { |
Hans Verkuil | 6d6a48e | 2010-12-29 13:53:21 -0300 | [diff] [blame] | 979 | if (noblock) |
Thierry MERLE | 483dfdb | 2006-12-04 08:31:45 -0300 | [diff] [blame] | 980 | return -EAGAIN; |
| 981 | |
| 982 | ret = wait_event_interruptible |
| 983 | (usbvision->wait_frame, |
| 984 | !list_empty(&(usbvision->outqueue))); |
| 985 | if (ret) |
| 986 | return ret; |
| 987 | } |
| 988 | |
| 989 | spin_lock_irqsave(&usbvision->queue_lock, lock_flags); |
| 990 | frame = list_entry(usbvision->outqueue.next, |
| 991 | struct usbvision_frame, frame); |
| 992 | list_del(usbvision->outqueue.next); |
| 993 | spin_unlock_irqrestore(&usbvision->queue_lock, lock_flags); |
| 994 | |
| 995 | /* An error returns an empty frame */ |
Hans Verkuil | 5490a7c | 2010-12-19 20:21:36 -0300 | [diff] [blame] | 996 | if (frame->grabstate == frame_state_error) { |
Thierry MERLE | 483dfdb | 2006-12-04 08:31:45 -0300 | [diff] [blame] | 997 | frame->bytes_read = 0; |
| 998 | return 0; |
| 999 | } |
| 1000 | |
Thierry MERLE | c5f4836 | 2007-05-08 17:22:29 -0300 | [diff] [blame] | 1001 | PDEBUG(DBG_IO, "%s: frmx=%d, bytes_read=%ld, scanlength=%ld", |
Harvey Harrison | d2db42d | 2008-04-04 20:50:07 -0300 | [diff] [blame] | 1002 | __func__, |
Thierry MERLE | c5f4836 | 2007-05-08 17:22:29 -0300 | [diff] [blame] | 1003 | frame->index, frame->bytes_read, frame->scanlength); |
Thierry MERLE | 483dfdb | 2006-12-04 08:31:45 -0300 | [diff] [blame] | 1004 | |
| 1005 | /* copy bytes to user space; we allow for partials reads */ |
| 1006 | if ((count + frame->bytes_read) > (unsigned long)frame->scanlength) |
| 1007 | count = frame->scanlength - frame->bytes_read; |
| 1008 | |
Hans Verkuil | 6d6a48e | 2010-12-29 13:53:21 -0300 | [diff] [blame] | 1009 | if (copy_to_user(buf, frame->data + frame->bytes_read, count)) |
Thierry MERLE | 483dfdb | 2006-12-04 08:31:45 -0300 | [diff] [blame] | 1010 | return -EFAULT; |
Thierry MERLE | 483dfdb | 2006-12-04 08:31:45 -0300 | [diff] [blame] | 1011 | |
| 1012 | frame->bytes_read += count; |
Thierry MERLE | c5f4836 | 2007-05-08 17:22:29 -0300 | [diff] [blame] | 1013 | PDEBUG(DBG_IO, "%s: {copy} count used=%ld, new bytes_read=%ld", |
Harvey Harrison | d2db42d | 2008-04-04 20:50:07 -0300 | [diff] [blame] | 1014 | __func__, |
Thierry MERLE | c5f4836 | 2007-05-08 17:22:29 -0300 | [diff] [blame] | 1015 | (unsigned long)count, frame->bytes_read); |
Thierry MERLE | 483dfdb | 2006-12-04 08:31:45 -0300 | [diff] [blame] | 1016 | |
Mauro Carvalho Chehab | b295e5c | 2015-06-05 10:47:36 -0300 | [diff] [blame] | 1017 | #if 1 |
| 1018 | /* |
| 1019 | * FIXME: |
| 1020 | * For now, forget the frame if it has not been read in one shot. |
| 1021 | */ |
| 1022 | frame->bytes_read = 0; |
| 1023 | |
| 1024 | /* Mark it as available to be used again. */ |
| 1025 | frame->grabstate = frame_state_unused; |
| 1026 | #else |
| 1027 | if (frame->bytes_read >= frame->scanlength) { |
| 1028 | /* All data has been read */ |
Thierry MERLE | 483dfdb | 2006-12-04 08:31:45 -0300 | [diff] [blame] | 1029 | frame->bytes_read = 0; |
| 1030 | |
| 1031 | /* Mark it as available to be used again. */ |
Hans Verkuil | 5490a7c | 2010-12-19 20:21:36 -0300 | [diff] [blame] | 1032 | frame->grabstate = frame_state_unused; |
Mauro Carvalho Chehab | b295e5c | 2015-06-05 10:47:36 -0300 | [diff] [blame] | 1033 | } |
| 1034 | #endif |
Thierry MERLE | 483dfdb | 2006-12-04 08:31:45 -0300 | [diff] [blame] | 1035 | |
| 1036 | return count; |
| 1037 | } |
| 1038 | |
Hans Verkuil | 4d34570 | 2012-06-23 08:03:50 -0300 | [diff] [blame] | 1039 | static ssize_t usbvision_v4l2_read(struct file *file, char __user *buf, |
| 1040 | size_t count, loff_t *ppos) |
| 1041 | { |
| 1042 | struct usb_usbvision *usbvision = video_drvdata(file); |
| 1043 | int res; |
| 1044 | |
| 1045 | if (mutex_lock_interruptible(&usbvision->v4l2_lock)) |
| 1046 | return -ERESTARTSYS; |
| 1047 | res = usbvision_read(file, buf, count, ppos); |
| 1048 | mutex_unlock(&usbvision->v4l2_lock); |
| 1049 | return res; |
| 1050 | } |
| 1051 | |
| 1052 | static int usbvision_mmap(struct file *file, struct vm_area_struct *vma) |
Thierry MERLE | 483dfdb | 2006-12-04 08:31:45 -0300 | [diff] [blame] | 1053 | { |
| 1054 | unsigned long size = vma->vm_end - vma->vm_start, |
| 1055 | start = vma->vm_start; |
| 1056 | void *pos; |
| 1057 | u32 i; |
Hans Verkuil | c170ecf | 2008-08-23 08:32:09 -0300 | [diff] [blame] | 1058 | struct usb_usbvision *usbvision = video_drvdata(file); |
Thierry MERLE | 483dfdb | 2006-12-04 08:31:45 -0300 | [diff] [blame] | 1059 | |
Thierry MERLE | 6f78e18 | 2007-02-07 10:13:11 -0300 | [diff] [blame] | 1060 | PDEBUG(DBG_MMAP, "mmap"); |
| 1061 | |
Hans Verkuil | 6d6a48e | 2010-12-29 13:53:21 -0300 | [diff] [blame] | 1062 | if (!USBVISION_IS_OPERATIONAL(usbvision)) |
Thierry MERLE | 483dfdb | 2006-12-04 08:31:45 -0300 | [diff] [blame] | 1063 | return -EFAULT; |
Thierry MERLE | 483dfdb | 2006-12-04 08:31:45 -0300 | [diff] [blame] | 1064 | |
| 1065 | if (!(vma->vm_flags & VM_WRITE) || |
Thierry MERLE | 6f78e18 | 2007-02-07 10:13:11 -0300 | [diff] [blame] | 1066 | size != PAGE_ALIGN(usbvision->max_frame_size)) { |
Thierry MERLE | 483dfdb | 2006-12-04 08:31:45 -0300 | [diff] [blame] | 1067 | return -EINVAL; |
| 1068 | } |
| 1069 | |
Thierry MERLE | 6f78e18 | 2007-02-07 10:13:11 -0300 | [diff] [blame] | 1070 | for (i = 0; i < usbvision->num_frames; i++) { |
Thierry MERLE | c5f4836 | 2007-05-08 17:22:29 -0300 | [diff] [blame] | 1071 | if (((PAGE_ALIGN(usbvision->max_frame_size)*i) >> PAGE_SHIFT) == |
| 1072 | vma->vm_pgoff) |
Thierry MERLE | 483dfdb | 2006-12-04 08:31:45 -0300 | [diff] [blame] | 1073 | break; |
| 1074 | } |
Thierry MERLE | 6f78e18 | 2007-02-07 10:13:11 -0300 | [diff] [blame] | 1075 | if (i == usbvision->num_frames) { |
Thierry MERLE | c5f4836 | 2007-05-08 17:22:29 -0300 | [diff] [blame] | 1076 | PDEBUG(DBG_MMAP, |
| 1077 | "mmap: user supplied mapping address is out of range"); |
Thierry MERLE | 483dfdb | 2006-12-04 08:31:45 -0300 | [diff] [blame] | 1078 | return -EINVAL; |
| 1079 | } |
| 1080 | |
| 1081 | /* VM_IO is eventually going to replace PageReserved altogether */ |
Konstantin Khlebnikov | 314e51b | 2012-10-08 16:29:02 -0700 | [diff] [blame] | 1082 | vma->vm_flags |= VM_IO | VM_DONTEXPAND | VM_DONTDUMP; |
Thierry MERLE | 483dfdb | 2006-12-04 08:31:45 -0300 | [diff] [blame] | 1083 | |
| 1084 | pos = usbvision->frame[i].data; |
| 1085 | while (size > 0) { |
Thierry MERLE | 483dfdb | 2006-12-04 08:31:45 -0300 | [diff] [blame] | 1086 | if (vm_insert_page(vma, start, vmalloc_to_page(pos))) { |
Thierry MERLE | c876a34 | 2006-12-09 16:42:54 -0300 | [diff] [blame] | 1087 | PDEBUG(DBG_MMAP, "mmap: vm_insert_page failed"); |
Thierry MERLE | 483dfdb | 2006-12-04 08:31:45 -0300 | [diff] [blame] | 1088 | return -EAGAIN; |
| 1089 | } |
| 1090 | start += PAGE_SIZE; |
| 1091 | pos += PAGE_SIZE; |
| 1092 | size -= PAGE_SIZE; |
| 1093 | } |
| 1094 | |
Thierry MERLE | 483dfdb | 2006-12-04 08:31:45 -0300 | [diff] [blame] | 1095 | return 0; |
| 1096 | } |
| 1097 | |
Hans Verkuil | 4d34570 | 2012-06-23 08:03:50 -0300 | [diff] [blame] | 1098 | static int usbvision_v4l2_mmap(struct file *file, struct vm_area_struct *vma) |
| 1099 | { |
| 1100 | struct usb_usbvision *usbvision = video_drvdata(file); |
| 1101 | int res; |
| 1102 | |
| 1103 | if (mutex_lock_interruptible(&usbvision->v4l2_lock)) |
| 1104 | return -ERESTARTSYS; |
| 1105 | res = usbvision_mmap(file, vma); |
| 1106 | mutex_unlock(&usbvision->v4l2_lock); |
| 1107 | return res; |
| 1108 | } |
Thierry MERLE | 483dfdb | 2006-12-04 08:31:45 -0300 | [diff] [blame] | 1109 | |
| 1110 | /* |
| 1111 | * Here comes the stuff for radio on usbvision based devices |
| 1112 | * |
| 1113 | */ |
Hans Verkuil | bec4366 | 2008-12-30 06:58:20 -0300 | [diff] [blame] | 1114 | static int usbvision_radio_open(struct file *file) |
Thierry MERLE | 483dfdb | 2006-12-04 08:31:45 -0300 | [diff] [blame] | 1115 | { |
Hans Verkuil | c170ecf | 2008-08-23 08:32:09 -0300 | [diff] [blame] | 1116 | struct usb_usbvision *usbvision = video_drvdata(file); |
Hans Verkuil | 5490a7c | 2010-12-19 20:21:36 -0300 | [diff] [blame] | 1117 | int err_code = 0; |
Thierry MERLE | 483dfdb | 2006-12-04 08:31:45 -0300 | [diff] [blame] | 1118 | |
Harvey Harrison | d2db42d | 2008-04-04 20:50:07 -0300 | [diff] [blame] | 1119 | PDEBUG(DBG_IO, "%s:", __func__); |
Thierry MERLE | 483dfdb | 2006-12-04 08:31:45 -0300 | [diff] [blame] | 1120 | |
Hans Verkuil | 4d34570 | 2012-06-23 08:03:50 -0300 | [diff] [blame] | 1121 | if (mutex_lock_interruptible(&usbvision->v4l2_lock)) |
| 1122 | return -ERESTARTSYS; |
Hans Verkuil | fd95870 | 2015-07-20 09:59:29 -0300 | [diff] [blame^] | 1123 | err_code = v4l2_fh_open(file); |
| 1124 | if (err_code) |
| 1125 | goto out; |
Thierry MERLE | 483dfdb | 2006-12-04 08:31:45 -0300 | [diff] [blame] | 1126 | if (usbvision->user) { |
Hans Verkuil | 2aa689d | 2015-03-09 13:34:12 -0300 | [diff] [blame] | 1127 | dev_err(&usbvision->rdev.dev, |
Mauro Carvalho Chehab | be9ed51 | 2009-01-08 09:13:42 -0300 | [diff] [blame] | 1128 | "%s: Someone tried to open an already opened USBVision Radio!\n", |
| 1129 | __func__); |
Hans Verkuil | 5490a7c | 2010-12-19 20:21:36 -0300 | [diff] [blame] | 1130 | err_code = -EBUSY; |
Hans Verkuil | 6d6a48e | 2010-12-29 13:53:21 -0300 | [diff] [blame] | 1131 | } else { |
Thierry MERLE | 2a9f8b5 | 2007-02-07 10:14:38 -0300 | [diff] [blame] | 1132 | /* Alternate interface 1 is is the biggest frame size */ |
Hans Verkuil | 5490a7c | 2010-12-19 20:21:36 -0300 | [diff] [blame] | 1133 | err_code = usbvision_set_alternate(usbvision); |
| 1134 | if (err_code < 0) { |
| 1135 | usbvision->last_error = err_code; |
| 1136 | err_code = -EBUSY; |
Andrew Morton | 544e617 | 2007-12-12 18:25:23 -0300 | [diff] [blame] | 1137 | goto out; |
Thierry MERLE | 2a9f8b5 | 2007-02-07 10:14:38 -0300 | [diff] [blame] | 1138 | } |
| 1139 | |
Hans Verkuil | 52cb0bf | 2010-12-19 20:33:51 -0300 | [diff] [blame] | 1140 | /* If so far no errors then we shall start the radio */ |
Thierry MERLE | 483dfdb | 2006-12-04 08:31:45 -0300 | [diff] [blame] | 1141 | usbvision->radio = 1; |
Hans Verkuil | 1df7953 | 2009-02-21 18:11:31 -0300 | [diff] [blame] | 1142 | call_all(usbvision, tuner, s_radio); |
Thierry MERLE | 483dfdb | 2006-12-04 08:31:45 -0300 | [diff] [blame] | 1143 | usbvision_set_audio(usbvision, USBVISION_AUDIO_RADIO); |
| 1144 | usbvision->user++; |
| 1145 | } |
Andrew Morton | 544e617 | 2007-12-12 18:25:23 -0300 | [diff] [blame] | 1146 | out: |
Hans Verkuil | 4d34570 | 2012-06-23 08:03:50 -0300 | [diff] [blame] | 1147 | mutex_unlock(&usbvision->v4l2_lock); |
Hans Verkuil | 5490a7c | 2010-12-19 20:21:36 -0300 | [diff] [blame] | 1148 | return err_code; |
Thierry MERLE | 483dfdb | 2006-12-04 08:31:45 -0300 | [diff] [blame] | 1149 | } |
| 1150 | |
| 1151 | |
Hans Verkuil | bec4366 | 2008-12-30 06:58:20 -0300 | [diff] [blame] | 1152 | static int usbvision_radio_close(struct file *file) |
Thierry MERLE | 483dfdb | 2006-12-04 08:31:45 -0300 | [diff] [blame] | 1153 | { |
Hans Verkuil | c170ecf | 2008-08-23 08:32:09 -0300 | [diff] [blame] | 1154 | struct usb_usbvision *usbvision = video_drvdata(file); |
Thierry MERLE | 483dfdb | 2006-12-04 08:31:45 -0300 | [diff] [blame] | 1155 | |
| 1156 | PDEBUG(DBG_IO, ""); |
| 1157 | |
Hans Verkuil | 4d34570 | 2012-06-23 08:03:50 -0300 | [diff] [blame] | 1158 | mutex_lock(&usbvision->v4l2_lock); |
Thierry MERLE | 2a9f8b5 | 2007-02-07 10:14:38 -0300 | [diff] [blame] | 1159 | /* Set packet size to 0 */ |
Hans Verkuil | 6d6a48e | 2010-12-29 13:53:21 -0300 | [diff] [blame] | 1160 | usbvision->iface_alt = 0; |
Hans Verkuil | fd95870 | 2015-07-20 09:59:29 -0300 | [diff] [blame^] | 1161 | usb_set_interface(usbvision->dev, usbvision->iface, |
Hans Verkuil | 5490a7c | 2010-12-19 20:21:36 -0300 | [diff] [blame] | 1162 | usbvision->iface_alt); |
Thierry MERLE | 2a9f8b5 | 2007-02-07 10:14:38 -0300 | [diff] [blame] | 1163 | |
Thierry MERLE | 483dfdb | 2006-12-04 08:31:45 -0300 | [diff] [blame] | 1164 | usbvision_audio_off(usbvision); |
Hans Verkuil | 6d6a48e | 2010-12-29 13:53:21 -0300 | [diff] [blame] | 1165 | usbvision->radio = 0; |
Thierry MERLE | 483dfdb | 2006-12-04 08:31:45 -0300 | [diff] [blame] | 1166 | usbvision->user--; |
| 1167 | |
Thierry MERLE | 483dfdb | 2006-12-04 08:31:45 -0300 | [diff] [blame] | 1168 | if (usbvision->remove_pending) { |
Harvey Harrison | d2db42d | 2008-04-04 20:50:07 -0300 | [diff] [blame] | 1169 | printk(KERN_INFO "%s: Final disconnect\n", __func__); |
Hans Verkuil | fd95870 | 2015-07-20 09:59:29 -0300 | [diff] [blame^] | 1170 | v4l2_fh_release(file); |
Thierry MERLE | 483dfdb | 2006-12-04 08:31:45 -0300 | [diff] [blame] | 1171 | usbvision_release(usbvision); |
Hans Verkuil | fd95870 | 2015-07-20 09:59:29 -0300 | [diff] [blame^] | 1172 | return 0; |
Thierry MERLE | 483dfdb | 2006-12-04 08:31:45 -0300 | [diff] [blame] | 1173 | } |
| 1174 | |
Hans Verkuil | 4d34570 | 2012-06-23 08:03:50 -0300 | [diff] [blame] | 1175 | mutex_unlock(&usbvision->v4l2_lock); |
Thierry MERLE | 483dfdb | 2006-12-04 08:31:45 -0300 | [diff] [blame] | 1176 | PDEBUG(DBG_IO, "success"); |
Hans Verkuil | fd95870 | 2015-07-20 09:59:29 -0300 | [diff] [blame^] | 1177 | return v4l2_fh_release(file); |
Thierry MERLE | 483dfdb | 2006-12-04 08:31:45 -0300 | [diff] [blame] | 1178 | } |
| 1179 | |
Hans Verkuil | 52cb0bf | 2010-12-19 20:33:51 -0300 | [diff] [blame] | 1180 | /* Video registration stuff */ |
Thierry MERLE | 483dfdb | 2006-12-04 08:31:45 -0300 | [diff] [blame] | 1181 | |
Hans Verkuil | 52cb0bf | 2010-12-19 20:33:51 -0300 | [diff] [blame] | 1182 | /* Video template */ |
Hans Verkuil | bec4366 | 2008-12-30 06:58:20 -0300 | [diff] [blame] | 1183 | static const struct v4l2_file_operations usbvision_fops = { |
Thierry MERLE | 483dfdb | 2006-12-04 08:31:45 -0300 | [diff] [blame] | 1184 | .owner = THIS_MODULE, |
Thierry MERLE | 483dfdb | 2006-12-04 08:31:45 -0300 | [diff] [blame] | 1185 | .open = usbvision_v4l2_open, |
| 1186 | .release = usbvision_v4l2_close, |
| 1187 | .read = usbvision_v4l2_read, |
| 1188 | .mmap = usbvision_v4l2_mmap, |
Hans Verkuil | c627b9d | 2010-12-18 11:06:09 -0300 | [diff] [blame] | 1189 | .unlocked_ioctl = video_ioctl2, |
Thierry MERLE | 483dfdb | 2006-12-04 08:31:45 -0300 | [diff] [blame] | 1190 | }; |
Hans Verkuil | a399810 | 2008-07-21 02:57:38 -0300 | [diff] [blame] | 1191 | |
| 1192 | static const struct v4l2_ioctl_ops usbvision_ioctl_ops = { |
Thierry MERLE | c5f4836 | 2007-05-08 17:22:29 -0300 | [diff] [blame] | 1193 | .vidioc_querycap = vidioc_querycap, |
Hans Verkuil | 78b526a | 2008-05-28 12:16:41 -0300 | [diff] [blame] | 1194 | .vidioc_enum_fmt_vid_cap = vidioc_enum_fmt_vid_cap, |
| 1195 | .vidioc_g_fmt_vid_cap = vidioc_g_fmt_vid_cap, |
| 1196 | .vidioc_try_fmt_vid_cap = vidioc_try_fmt_vid_cap, |
| 1197 | .vidioc_s_fmt_vid_cap = vidioc_s_fmt_vid_cap, |
Thierry MERLE | c5f4836 | 2007-05-08 17:22:29 -0300 | [diff] [blame] | 1198 | .vidioc_reqbufs = vidioc_reqbufs, |
| 1199 | .vidioc_querybuf = vidioc_querybuf, |
| 1200 | .vidioc_qbuf = vidioc_qbuf, |
| 1201 | .vidioc_dqbuf = vidioc_dqbuf, |
| 1202 | .vidioc_s_std = vidioc_s_std, |
Hans Verkuil | 3b8436d | 2013-06-03 05:36:47 -0300 | [diff] [blame] | 1203 | .vidioc_g_std = vidioc_g_std, |
Thierry MERLE | c5f4836 | 2007-05-08 17:22:29 -0300 | [diff] [blame] | 1204 | .vidioc_enum_input = vidioc_enum_input, |
| 1205 | .vidioc_g_input = vidioc_g_input, |
| 1206 | .vidioc_s_input = vidioc_s_input, |
Thierry MERLE | c5f4836 | 2007-05-08 17:22:29 -0300 | [diff] [blame] | 1207 | .vidioc_g_audio = vidioc_g_audio, |
Al Viro | ed4d637 | 2007-09-26 01:53:42 +0100 | [diff] [blame] | 1208 | .vidioc_s_audio = vidioc_s_audio, |
Thierry MERLE | c5f4836 | 2007-05-08 17:22:29 -0300 | [diff] [blame] | 1209 | .vidioc_streamon = vidioc_streamon, |
| 1210 | .vidioc_streamoff = vidioc_streamoff, |
Thierry MERLE | c5f4836 | 2007-05-08 17:22:29 -0300 | [diff] [blame] | 1211 | .vidioc_g_tuner = vidioc_g_tuner, |
| 1212 | .vidioc_s_tuner = vidioc_s_tuner, |
| 1213 | .vidioc_g_frequency = vidioc_g_frequency, |
| 1214 | .vidioc_s_frequency = vidioc_s_frequency, |
Hans Verkuil | fd95870 | 2015-07-20 09:59:29 -0300 | [diff] [blame^] | 1215 | .vidioc_log_status = v4l2_ctrl_log_status, |
| 1216 | .vidioc_subscribe_event = v4l2_ctrl_subscribe_event, |
| 1217 | .vidioc_unsubscribe_event = v4l2_event_unsubscribe, |
Thierry MERLE | c5f4836 | 2007-05-08 17:22:29 -0300 | [diff] [blame] | 1218 | #ifdef CONFIG_VIDEO_ADV_DEBUG |
| 1219 | .vidioc_g_register = vidioc_g_register, |
| 1220 | .vidioc_s_register = vidioc_s_register, |
| 1221 | #endif |
Hans Verkuil | a399810 | 2008-07-21 02:57:38 -0300 | [diff] [blame] | 1222 | }; |
| 1223 | |
| 1224 | static struct video_device usbvision_video_template = { |
Hans Verkuil | a399810 | 2008-07-21 02:57:38 -0300 | [diff] [blame] | 1225 | .fops = &usbvision_fops, |
Hans Verkuil | 6d6a48e | 2010-12-29 13:53:21 -0300 | [diff] [blame] | 1226 | .ioctl_ops = &usbvision_ioctl_ops, |
Hans Verkuil | a399810 | 2008-07-21 02:57:38 -0300 | [diff] [blame] | 1227 | .name = "usbvision-video", |
Hans Verkuil | 2aa689d | 2015-03-09 13:34:12 -0300 | [diff] [blame] | 1228 | .release = video_device_release_empty, |
Hans Verkuil | 6d6a48e | 2010-12-29 13:53:21 -0300 | [diff] [blame] | 1229 | .tvnorms = USBVISION_NORMS, |
Thierry MERLE | 483dfdb | 2006-12-04 08:31:45 -0300 | [diff] [blame] | 1230 | }; |
| 1231 | |
| 1232 | |
Hans Verkuil | 52cb0bf | 2010-12-19 20:33:51 -0300 | [diff] [blame] | 1233 | /* Radio template */ |
Hans Verkuil | bec4366 | 2008-12-30 06:58:20 -0300 | [diff] [blame] | 1234 | static const struct v4l2_file_operations usbvision_radio_fops = { |
Thierry MERLE | 483dfdb | 2006-12-04 08:31:45 -0300 | [diff] [blame] | 1235 | .owner = THIS_MODULE, |
Thierry MERLE | 483dfdb | 2006-12-04 08:31:45 -0300 | [diff] [blame] | 1236 | .open = usbvision_radio_open, |
| 1237 | .release = usbvision_radio_close, |
Hans Verkuil | fd95870 | 2015-07-20 09:59:29 -0300 | [diff] [blame^] | 1238 | .poll = v4l2_ctrl_poll, |
Hans Verkuil | c627b9d | 2010-12-18 11:06:09 -0300 | [diff] [blame] | 1239 | .unlocked_ioctl = video_ioctl2, |
Thierry MERLE | 483dfdb | 2006-12-04 08:31:45 -0300 | [diff] [blame] | 1240 | }; |
| 1241 | |
Hans Verkuil | a399810 | 2008-07-21 02:57:38 -0300 | [diff] [blame] | 1242 | static const struct v4l2_ioctl_ops usbvision_radio_ioctl_ops = { |
Thierry MERLE | c5f4836 | 2007-05-08 17:22:29 -0300 | [diff] [blame] | 1243 | .vidioc_querycap = vidioc_querycap, |
| 1244 | .vidioc_enum_input = vidioc_enum_input, |
| 1245 | .vidioc_g_input = vidioc_g_input, |
| 1246 | .vidioc_s_input = vidioc_s_input, |
Thierry MERLE | c5f4836 | 2007-05-08 17:22:29 -0300 | [diff] [blame] | 1247 | .vidioc_g_audio = vidioc_g_audio, |
Al Viro | ed4d637 | 2007-09-26 01:53:42 +0100 | [diff] [blame] | 1248 | .vidioc_s_audio = vidioc_s_audio, |
Thierry MERLE | c5f4836 | 2007-05-08 17:22:29 -0300 | [diff] [blame] | 1249 | .vidioc_g_tuner = vidioc_g_tuner, |
| 1250 | .vidioc_s_tuner = vidioc_s_tuner, |
| 1251 | .vidioc_g_frequency = vidioc_g_frequency, |
| 1252 | .vidioc_s_frequency = vidioc_s_frequency, |
Hans Verkuil | fd95870 | 2015-07-20 09:59:29 -0300 | [diff] [blame^] | 1253 | .vidioc_log_status = v4l2_ctrl_log_status, |
| 1254 | .vidioc_subscribe_event = v4l2_ctrl_subscribe_event, |
| 1255 | .vidioc_unsubscribe_event = v4l2_event_unsubscribe, |
Hans Verkuil | a399810 | 2008-07-21 02:57:38 -0300 | [diff] [blame] | 1256 | }; |
| 1257 | |
| 1258 | static struct video_device usbvision_radio_template = { |
Hans Verkuil | a399810 | 2008-07-21 02:57:38 -0300 | [diff] [blame] | 1259 | .fops = &usbvision_radio_fops, |
Hans Verkuil | 6d6a48e | 2010-12-29 13:53:21 -0300 | [diff] [blame] | 1260 | .name = "usbvision-radio", |
Hans Verkuil | 2aa689d | 2015-03-09 13:34:12 -0300 | [diff] [blame] | 1261 | .release = video_device_release_empty, |
Hans Verkuil | 6d6a48e | 2010-12-29 13:53:21 -0300 | [diff] [blame] | 1262 | .ioctl_ops = &usbvision_radio_ioctl_ops, |
Thierry MERLE | c5f4836 | 2007-05-08 17:22:29 -0300 | [diff] [blame] | 1263 | }; |
Thierry MERLE | 483dfdb | 2006-12-04 08:31:45 -0300 | [diff] [blame] | 1264 | |
Thierry MERLE | 483dfdb | 2006-12-04 08:31:45 -0300 | [diff] [blame] | 1265 | |
Hans Verkuil | 2aa689d | 2015-03-09 13:34:12 -0300 | [diff] [blame] | 1266 | static void usbvision_vdev_init(struct usb_usbvision *usbvision, |
| 1267 | struct video_device *vdev, |
| 1268 | const struct video_device *vdev_template, |
| 1269 | const char *name) |
Thierry MERLE | 483dfdb | 2006-12-04 08:31:45 -0300 | [diff] [blame] | 1270 | { |
| 1271 | struct usb_device *usb_dev = usbvision->dev; |
Thierry MERLE | 483dfdb | 2006-12-04 08:31:45 -0300 | [diff] [blame] | 1272 | |
| 1273 | if (usb_dev == NULL) { |
Mauro Carvalho Chehab | be9ed51 | 2009-01-08 09:13:42 -0300 | [diff] [blame] | 1274 | dev_err(&usbvision->dev->dev, |
| 1275 | "%s: usbvision->dev is not set\n", __func__); |
Hans Verkuil | 2aa689d | 2015-03-09 13:34:12 -0300 | [diff] [blame] | 1276 | return; |
Thierry MERLE | 483dfdb | 2006-12-04 08:31:45 -0300 | [diff] [blame] | 1277 | } |
| 1278 | |
Thierry MERLE | 483dfdb | 2006-12-04 08:31:45 -0300 | [diff] [blame] | 1279 | *vdev = *vdev_template; |
Hans Verkuil | c627b9d | 2010-12-18 11:06:09 -0300 | [diff] [blame] | 1280 | vdev->lock = &usbvision->v4l2_lock; |
Hans Verkuil | 1df7953 | 2009-02-21 18:11:31 -0300 | [diff] [blame] | 1281 | vdev->v4l2_dev = &usbvision->v4l2_dev; |
Thierry MERLE | 483dfdb | 2006-12-04 08:31:45 -0300 | [diff] [blame] | 1282 | snprintf(vdev->name, sizeof(vdev->name), "%s", name); |
| 1283 | video_set_drvdata(vdev, usbvision); |
Thierry MERLE | 483dfdb | 2006-12-04 08:31:45 -0300 | [diff] [blame] | 1284 | } |
| 1285 | |
Hans Verkuil | 52cb0bf | 2010-12-19 20:33:51 -0300 | [diff] [blame] | 1286 | /* unregister video4linux devices */ |
Thierry MERLE | 483dfdb | 2006-12-04 08:31:45 -0300 | [diff] [blame] | 1287 | static void usbvision_unregister_video(struct usb_usbvision *usbvision) |
| 1288 | { |
Hans Verkuil | 52cb0bf | 2010-12-19 20:33:51 -0300 | [diff] [blame] | 1289 | /* Radio Device: */ |
Hans Verkuil | 2aa689d | 2015-03-09 13:34:12 -0300 | [diff] [blame] | 1290 | if (video_is_registered(&usbvision->rdev)) { |
Laurent Pinchart | 38c7c03 | 2009-11-27 13:57:15 -0300 | [diff] [blame] | 1291 | PDEBUG(DBG_PROBE, "unregister %s [v4l2]", |
Hans Verkuil | 2aa689d | 2015-03-09 13:34:12 -0300 | [diff] [blame] | 1292 | video_device_node_name(&usbvision->rdev)); |
| 1293 | video_unregister_device(&usbvision->rdev); |
Thierry MERLE | 483dfdb | 2006-12-04 08:31:45 -0300 | [diff] [blame] | 1294 | } |
| 1295 | |
Hans Verkuil | 52cb0bf | 2010-12-19 20:33:51 -0300 | [diff] [blame] | 1296 | /* Video Device: */ |
Hans Verkuil | 2aa689d | 2015-03-09 13:34:12 -0300 | [diff] [blame] | 1297 | if (video_is_registered(&usbvision->vdev)) { |
Laurent Pinchart | 38c7c03 | 2009-11-27 13:57:15 -0300 | [diff] [blame] | 1298 | PDEBUG(DBG_PROBE, "unregister %s [v4l2]", |
Hans Verkuil | 2aa689d | 2015-03-09 13:34:12 -0300 | [diff] [blame] | 1299 | video_device_node_name(&usbvision->vdev)); |
| 1300 | video_unregister_device(&usbvision->vdev); |
Thierry MERLE | 483dfdb | 2006-12-04 08:31:45 -0300 | [diff] [blame] | 1301 | } |
| 1302 | } |
| 1303 | |
Hans Verkuil | 52cb0bf | 2010-12-19 20:33:51 -0300 | [diff] [blame] | 1304 | /* register video4linux devices */ |
Greg Kroah-Hartman | 4c62e97 | 2012-12-21 13:17:53 -0800 | [diff] [blame] | 1305 | static int usbvision_register_video(struct usb_usbvision *usbvision) |
Thierry MERLE | 483dfdb | 2006-12-04 08:31:45 -0300 | [diff] [blame] | 1306 | { |
Hans Verkuil | 52cb0bf | 2010-12-19 20:33:51 -0300 | [diff] [blame] | 1307 | /* Video Device: */ |
Hans Verkuil | 2aa689d | 2015-03-09 13:34:12 -0300 | [diff] [blame] | 1308 | usbvision_vdev_init(usbvision, &usbvision->vdev, |
| 1309 | &usbvision_video_template, "USBVision Video"); |
| 1310 | if (video_register_device(&usbvision->vdev, VFL_TYPE_GRABBER, video_nr) < 0) |
Thierry MERLE | 483dfdb | 2006-12-04 08:31:45 -0300 | [diff] [blame] | 1311 | goto err_exit; |
Laurent Pinchart | 38c7c03 | 2009-11-27 13:57:15 -0300 | [diff] [blame] | 1312 | printk(KERN_INFO "USBVision[%d]: registered USBVision Video device %s [v4l2]\n", |
Hans Verkuil | 2aa689d | 2015-03-09 13:34:12 -0300 | [diff] [blame] | 1313 | usbvision->nr, video_device_node_name(&usbvision->vdev)); |
Thierry MERLE | 483dfdb | 2006-12-04 08:31:45 -0300 | [diff] [blame] | 1314 | |
Hans Verkuil | 52cb0bf | 2010-12-19 20:33:51 -0300 | [diff] [blame] | 1315 | /* Radio Device: */ |
Hans Verkuil | 5490a7c | 2010-12-19 20:21:36 -0300 | [diff] [blame] | 1316 | if (usbvision_device_data[usbvision->dev_model].radio) { |
Hans Verkuil | 52cb0bf | 2010-12-19 20:33:51 -0300 | [diff] [blame] | 1317 | /* usbvision has radio */ |
Hans Verkuil | 2aa689d | 2015-03-09 13:34:12 -0300 | [diff] [blame] | 1318 | usbvision_vdev_init(usbvision, &usbvision->rdev, |
| 1319 | &usbvision_radio_template, "USBVision Radio"); |
| 1320 | if (video_register_device(&usbvision->rdev, VFL_TYPE_RADIO, radio_nr) < 0) |
Thierry MERLE | 483dfdb | 2006-12-04 08:31:45 -0300 | [diff] [blame] | 1321 | goto err_exit; |
Laurent Pinchart | 38c7c03 | 2009-11-27 13:57:15 -0300 | [diff] [blame] | 1322 | printk(KERN_INFO "USBVision[%d]: registered USBVision Radio device %s [v4l2]\n", |
Hans Verkuil | 2aa689d | 2015-03-09 13:34:12 -0300 | [diff] [blame] | 1323 | usbvision->nr, video_device_node_name(&usbvision->rdev)); |
Thierry MERLE | 483dfdb | 2006-12-04 08:31:45 -0300 | [diff] [blame] | 1324 | } |
Hans Verkuil | 52cb0bf | 2010-12-19 20:33:51 -0300 | [diff] [blame] | 1325 | /* all done */ |
Thierry MERLE | 483dfdb | 2006-12-04 08:31:45 -0300 | [diff] [blame] | 1326 | return 0; |
| 1327 | |
| 1328 | err_exit: |
Mauro Carvalho Chehab | be9ed51 | 2009-01-08 09:13:42 -0300 | [diff] [blame] | 1329 | dev_err(&usbvision->dev->dev, |
| 1330 | "USBVision[%d]: video_register_device() failed\n", |
| 1331 | usbvision->nr); |
Thierry MERLE | 483dfdb | 2006-12-04 08:31:45 -0300 | [diff] [blame] | 1332 | usbvision_unregister_video(usbvision); |
| 1333 | return -1; |
| 1334 | } |
| 1335 | |
| 1336 | /* |
| 1337 | * usbvision_alloc() |
| 1338 | * |
Thierry MERLE | c5f4836 | 2007-05-08 17:22:29 -0300 | [diff] [blame] | 1339 | * This code allocates the struct usb_usbvision. |
| 1340 | * It is filled with default values. |
Thierry MERLE | 483dfdb | 2006-12-04 08:31:45 -0300 | [diff] [blame] | 1341 | * |
| 1342 | * Returns NULL on error, a pointer to usb_usbvision else. |
| 1343 | * |
| 1344 | */ |
Janne Grunau | a878440 | 2009-04-01 08:46:00 -0300 | [diff] [blame] | 1345 | static struct usb_usbvision *usbvision_alloc(struct usb_device *dev, |
| 1346 | struct usb_interface *intf) |
Thierry MERLE | 483dfdb | 2006-12-04 08:31:45 -0300 | [diff] [blame] | 1347 | { |
| 1348 | struct usb_usbvision *usbvision; |
| 1349 | |
Hans Verkuil | 1df7953 | 2009-02-21 18:11:31 -0300 | [diff] [blame] | 1350 | usbvision = kzalloc(sizeof(struct usb_usbvision), GFP_KERNEL); |
| 1351 | if (usbvision == NULL) |
| 1352 | return NULL; |
Thierry MERLE | 483dfdb | 2006-12-04 08:31:45 -0300 | [diff] [blame] | 1353 | |
| 1354 | usbvision->dev = dev; |
Janne Grunau | a878440 | 2009-04-01 08:46:00 -0300 | [diff] [blame] | 1355 | if (v4l2_device_register(&intf->dev, &usbvision->v4l2_dev)) |
Hans Verkuil | 1df7953 | 2009-02-21 18:11:31 -0300 | [diff] [blame] | 1356 | goto err_free; |
Thierry MERLE | 483dfdb | 2006-12-04 08:31:45 -0300 | [diff] [blame] | 1357 | |
Hans Verkuil | fd95870 | 2015-07-20 09:59:29 -0300 | [diff] [blame^] | 1358 | if (v4l2_ctrl_handler_init(&usbvision->hdl, 4)) |
| 1359 | goto err_unreg; |
| 1360 | usbvision->v4l2_dev.ctrl_handler = &usbvision->hdl; |
Hans Verkuil | c627b9d | 2010-12-18 11:06:09 -0300 | [diff] [blame] | 1361 | mutex_init(&usbvision->v4l2_lock); |
Thierry MERLE | 483dfdb | 2006-12-04 08:31:45 -0300 | [diff] [blame] | 1362 | |
Hans Verkuil | 52cb0bf | 2010-12-19 20:33:51 -0300 | [diff] [blame] | 1363 | /* prepare control urb for control messages during interrupts */ |
Hans Verkuil | 5490a7c | 2010-12-19 20:21:36 -0300 | [diff] [blame] | 1364 | usbvision->ctrl_urb = usb_alloc_urb(USBVISION_URB_FRAMES, GFP_KERNEL); |
| 1365 | if (usbvision->ctrl_urb == NULL) |
Hans Verkuil | 1df7953 | 2009-02-21 18:11:31 -0300 | [diff] [blame] | 1366 | goto err_unreg; |
Hans Verkuil | 5490a7c | 2010-12-19 20:21:36 -0300 | [diff] [blame] | 1367 | init_waitqueue_head(&usbvision->ctrl_urb_wq); |
Thierry MERLE | 483dfdb | 2006-12-04 08:31:45 -0300 | [diff] [blame] | 1368 | |
Thierry MERLE | 483dfdb | 2006-12-04 08:31:45 -0300 | [diff] [blame] | 1369 | return usbvision; |
| 1370 | |
Hans Verkuil | 1df7953 | 2009-02-21 18:11:31 -0300 | [diff] [blame] | 1371 | err_unreg: |
Hans Verkuil | fd95870 | 2015-07-20 09:59:29 -0300 | [diff] [blame^] | 1372 | v4l2_ctrl_handler_free(&usbvision->hdl); |
Hans Verkuil | 1df7953 | 2009-02-21 18:11:31 -0300 | [diff] [blame] | 1373 | v4l2_device_unregister(&usbvision->v4l2_dev); |
| 1374 | err_free: |
| 1375 | kfree(usbvision); |
Thierry MERLE | 483dfdb | 2006-12-04 08:31:45 -0300 | [diff] [blame] | 1376 | return NULL; |
| 1377 | } |
| 1378 | |
| 1379 | /* |
| 1380 | * usbvision_release() |
| 1381 | * |
| 1382 | * This code does final release of struct usb_usbvision. This happens |
| 1383 | * after the device is disconnected -and- all clients closed their files. |
| 1384 | * |
| 1385 | */ |
| 1386 | static void usbvision_release(struct usb_usbvision *usbvision) |
| 1387 | { |
| 1388 | PDEBUG(DBG_PROBE, ""); |
| 1389 | |
Thierry MERLE | 483dfdb | 2006-12-04 08:31:45 -0300 | [diff] [blame] | 1390 | usbvision->initialized = 0; |
| 1391 | |
Hans Verkuil | 2aa689d | 2015-03-09 13:34:12 -0300 | [diff] [blame] | 1392 | usbvision_remove_sysfs(&usbvision->vdev); |
Thierry MERLE | 483dfdb | 2006-12-04 08:31:45 -0300 | [diff] [blame] | 1393 | usbvision_unregister_video(usbvision); |
Alexey Khoroshilov | 090c65b | 2013-06-10 17:32:29 -0300 | [diff] [blame] | 1394 | kfree(usbvision->alt_max_pkt_size); |
Thierry MERLE | 483dfdb | 2006-12-04 08:31:45 -0300 | [diff] [blame] | 1395 | |
Hans Verkuil | 6d6a48e | 2010-12-29 13:53:21 -0300 | [diff] [blame] | 1396 | usb_free_urb(usbvision->ctrl_urb); |
Thierry MERLE | 483dfdb | 2006-12-04 08:31:45 -0300 | [diff] [blame] | 1397 | |
Hans Verkuil | fd95870 | 2015-07-20 09:59:29 -0300 | [diff] [blame^] | 1398 | v4l2_ctrl_handler_free(&usbvision->hdl); |
Hans Verkuil | 1df7953 | 2009-02-21 18:11:31 -0300 | [diff] [blame] | 1399 | v4l2_device_unregister(&usbvision->v4l2_dev); |
Thierry MERLE | 483dfdb | 2006-12-04 08:31:45 -0300 | [diff] [blame] | 1400 | kfree(usbvision); |
| 1401 | |
| 1402 | PDEBUG(DBG_PROBE, "success"); |
| 1403 | } |
| 1404 | |
| 1405 | |
Thierry MERLE | c5f4836 | 2007-05-08 17:22:29 -0300 | [diff] [blame] | 1406 | /*********************** usb interface **********************************/ |
Thierry MERLE | 483dfdb | 2006-12-04 08:31:45 -0300 | [diff] [blame] | 1407 | |
| 1408 | static void usbvision_configure_video(struct usb_usbvision *usbvision) |
| 1409 | { |
Thierry MERLE | c5f4836 | 2007-05-08 17:22:29 -0300 | [diff] [blame] | 1410 | int model; |
Thierry MERLE | 483dfdb | 2006-12-04 08:31:45 -0300 | [diff] [blame] | 1411 | |
| 1412 | if (usbvision == NULL) |
| 1413 | return; |
| 1414 | |
Hans Verkuil | 5490a7c | 2010-12-19 20:21:36 -0300 | [diff] [blame] | 1415 | model = usbvision->dev_model; |
Hans Verkuil | 52cb0bf | 2010-12-19 20:33:51 -0300 | [diff] [blame] | 1416 | usbvision->palette = usbvision_v4l2_format[2]; /* V4L2_PIX_FMT_RGB24; */ |
Thierry MERLE | 483dfdb | 2006-12-04 08:31:45 -0300 | [diff] [blame] | 1417 | |
Hans Verkuil | 5490a7c | 2010-12-19 20:21:36 -0300 | [diff] [blame] | 1418 | if (usbvision_device_data[usbvision->dev_model].vin_reg2_override) { |
| 1419 | usbvision->vin_reg2_preset = |
| 1420 | usbvision_device_data[usbvision->dev_model].vin_reg2; |
Thierry MERLE | 483dfdb | 2006-12-04 08:31:45 -0300 | [diff] [blame] | 1421 | } else { |
Hans Verkuil | 5490a7c | 2010-12-19 20:21:36 -0300 | [diff] [blame] | 1422 | usbvision->vin_reg2_preset = 0; |
Thierry MERLE | 483dfdb | 2006-12-04 08:31:45 -0300 | [diff] [blame] | 1423 | } |
| 1424 | |
Hans Verkuil | 5490a7c | 2010-12-19 20:21:36 -0300 | [diff] [blame] | 1425 | usbvision->tvnorm_id = usbvision_device_data[model].video_norm; |
Thierry MERLE | 483dfdb | 2006-12-04 08:31:45 -0300 | [diff] [blame] | 1426 | |
Hans Verkuil | 5490a7c | 2010-12-19 20:21:36 -0300 | [diff] [blame] | 1427 | usbvision->video_inputs = usbvision_device_data[model].video_channels; |
Thierry MERLE | 483dfdb | 2006-12-04 08:31:45 -0300 | [diff] [blame] | 1428 | usbvision->ctl_input = 0; |
| 1429 | |
| 1430 | /* This should be here to make i2c clients to be able to register */ |
Thierry MERLE | c5f4836 | 2007-05-08 17:22:29 -0300 | [diff] [blame] | 1431 | /* first switch off audio */ |
Ondrej Zary | 240d57b | 2011-04-27 17:36:05 -0300 | [diff] [blame] | 1432 | if (usbvision_device_data[model].audio_channels > 0) |
| 1433 | usbvision_audio_off(usbvision); |
Hans Verkuil | 62e2594 | 2015-07-20 09:59:28 -0300 | [diff] [blame] | 1434 | /* and then power up the tuner */ |
| 1435 | usbvision_power_on(usbvision); |
| 1436 | usbvision_i2c_register(usbvision); |
Thierry MERLE | 483dfdb | 2006-12-04 08:31:45 -0300 | [diff] [blame] | 1437 | } |
| 1438 | |
| 1439 | /* |
| 1440 | * usbvision_probe() |
| 1441 | * |
| 1442 | * This procedure queries device descriptor and accepts the interface |
| 1443 | * if it looks like USBVISION video device |
| 1444 | * |
| 1445 | */ |
Greg Kroah-Hartman | 4c62e97 | 2012-12-21 13:17:53 -0800 | [diff] [blame] | 1446 | static int usbvision_probe(struct usb_interface *intf, |
| 1447 | const struct usb_device_id *devid) |
Thierry MERLE | 483dfdb | 2006-12-04 08:31:45 -0300 | [diff] [blame] | 1448 | { |
Thierry MERLE | 2a9f8b5 | 2007-02-07 10:14:38 -0300 | [diff] [blame] | 1449 | struct usb_device *dev = usb_get_dev(interface_to_usbdev(intf)); |
| 1450 | struct usb_interface *uif; |
Thierry MERLE | 483dfdb | 2006-12-04 08:31:45 -0300 | [diff] [blame] | 1451 | __u8 ifnum = intf->altsetting->desc.bInterfaceNumber; |
| 1452 | const struct usb_host_interface *interface; |
| 1453 | struct usb_usbvision *usbvision = NULL; |
| 1454 | const struct usb_endpoint_descriptor *endpoint; |
Alexey Khoroshilov | afd270d | 2015-03-27 19:39:09 -0300 | [diff] [blame] | 1455 | int model, i, ret; |
Thierry MERLE | 483dfdb | 2006-12-04 08:31:45 -0300 | [diff] [blame] | 1456 | |
| 1457 | PDEBUG(DBG_PROBE, "VID=%#04x, PID=%#04x, ifnum=%u", |
Mauro Carvalho Chehab | 659ae56 | 2007-04-14 15:09:59 -0300 | [diff] [blame] | 1458 | dev->descriptor.idVendor, |
| 1459 | dev->descriptor.idProduct, ifnum); |
Thierry MERLE | 2a9f8b5 | 2007-02-07 10:14:38 -0300 | [diff] [blame] | 1460 | |
Mauro Carvalho Chehab | 659ae56 | 2007-04-14 15:09:59 -0300 | [diff] [blame] | 1461 | model = devid->driver_info; |
Hans Verkuil | 6d6a48e | 2010-12-29 13:53:21 -0300 | [diff] [blame] | 1462 | if (model < 0 || model >= usbvision_device_data_size) { |
| 1463 | PDEBUG(DBG_PROBE, "model out of bounds %d", model); |
Alexey Khoroshilov | afd270d | 2015-03-27 19:39:09 -0300 | [diff] [blame] | 1464 | ret = -ENODEV; |
| 1465 | goto err_usb; |
Mauro Carvalho Chehab | f8a389d | 2007-04-14 15:17:35 -0300 | [diff] [blame] | 1466 | } |
Harvey Harrison | d2db42d | 2008-04-04 20:50:07 -0300 | [diff] [blame] | 1467 | printk(KERN_INFO "%s: %s found\n", __func__, |
Hans Verkuil | 5490a7c | 2010-12-19 20:21:36 -0300 | [diff] [blame] | 1468 | usbvision_device_data[model].model_string); |
Thierry MERLE | 483dfdb | 2006-12-04 08:31:45 -0300 | [diff] [blame] | 1469 | |
Hans Verkuil | 6d6a48e | 2010-12-29 13:53:21 -0300 | [diff] [blame] | 1470 | if (usbvision_device_data[model].interface >= 0) |
Hans Verkuil | 5490a7c | 2010-12-19 20:21:36 -0300 | [diff] [blame] | 1471 | interface = &dev->actconfig->interface[usbvision_device_data[model].interface]->altsetting[0]; |
Hans Verkuil | 6d6a48e | 2010-12-29 13:53:21 -0300 | [diff] [blame] | 1472 | else |
Thierry MERLE | 483dfdb | 2006-12-04 08:31:45 -0300 | [diff] [blame] | 1473 | interface = &dev->actconfig->interface[ifnum]->altsetting[0]; |
Thierry MERLE | 483dfdb | 2006-12-04 08:31:45 -0300 | [diff] [blame] | 1474 | endpoint = &interface->endpoint[1].desc; |
Julia Lawall | 2230c3c | 2009-01-03 16:53:10 -0300 | [diff] [blame] | 1475 | if (!usb_endpoint_xfer_isoc(endpoint)) { |
Mauro Carvalho Chehab | be9ed51 | 2009-01-08 09:13:42 -0300 | [diff] [blame] | 1476 | dev_err(&intf->dev, "%s: interface %d. has non-ISO endpoint!\n", |
Harvey Harrison | d2db42d | 2008-04-04 20:50:07 -0300 | [diff] [blame] | 1477 | __func__, ifnum); |
Mauro Carvalho Chehab | be9ed51 | 2009-01-08 09:13:42 -0300 | [diff] [blame] | 1478 | dev_err(&intf->dev, "%s: Endpoint attributes %d", |
Harvey Harrison | d2db42d | 2008-04-04 20:50:07 -0300 | [diff] [blame] | 1479 | __func__, endpoint->bmAttributes); |
Alexey Khoroshilov | afd270d | 2015-03-27 19:39:09 -0300 | [diff] [blame] | 1480 | ret = -ENODEV; |
| 1481 | goto err_usb; |
Thierry MERLE | 483dfdb | 2006-12-04 08:31:45 -0300 | [diff] [blame] | 1482 | } |
Julia Lawall | 1341798 | 2008-12-29 21:49:22 -0300 | [diff] [blame] | 1483 | if (usb_endpoint_dir_out(endpoint)) { |
Mauro Carvalho Chehab | be9ed51 | 2009-01-08 09:13:42 -0300 | [diff] [blame] | 1484 | dev_err(&intf->dev, "%s: interface %d. has ISO OUT endpoint!\n", |
Harvey Harrison | d2db42d | 2008-04-04 20:50:07 -0300 | [diff] [blame] | 1485 | __func__, ifnum); |
Alexey Khoroshilov | afd270d | 2015-03-27 19:39:09 -0300 | [diff] [blame] | 1486 | ret = -ENODEV; |
| 1487 | goto err_usb; |
Thierry MERLE | 483dfdb | 2006-12-04 08:31:45 -0300 | [diff] [blame] | 1488 | } |
| 1489 | |
Janne Grunau | a878440 | 2009-04-01 08:46:00 -0300 | [diff] [blame] | 1490 | usbvision = usbvision_alloc(dev, intf); |
| 1491 | if (usbvision == NULL) { |
Mauro Carvalho Chehab | be9ed51 | 2009-01-08 09:13:42 -0300 | [diff] [blame] | 1492 | dev_err(&intf->dev, "%s: couldn't allocate USBVision struct\n", __func__); |
Alexey Khoroshilov | afd270d | 2015-03-27 19:39:09 -0300 | [diff] [blame] | 1493 | ret = -ENOMEM; |
| 1494 | goto err_usb; |
Thierry MERLE | 483dfdb | 2006-12-04 08:31:45 -0300 | [diff] [blame] | 1495 | } |
Mauro Carvalho Chehab | 659ae56 | 2007-04-14 15:09:59 -0300 | [diff] [blame] | 1496 | |
Hans Verkuil | 6d6a48e | 2010-12-29 13:53:21 -0300 | [diff] [blame] | 1497 | if (dev->descriptor.bNumConfigurations > 1) |
Hans Verkuil | 5490a7c | 2010-12-19 20:21:36 -0300 | [diff] [blame] | 1498 | usbvision->bridge_type = BRIDGE_NT1004; |
Hans Verkuil | 6d6a48e | 2010-12-29 13:53:21 -0300 | [diff] [blame] | 1499 | else if (model == DAZZLE_DVC_90_REV_1_SECAM) |
Hans Verkuil | 5490a7c | 2010-12-19 20:21:36 -0300 | [diff] [blame] | 1500 | usbvision->bridge_type = BRIDGE_NT1005; |
Hans Verkuil | 6d6a48e | 2010-12-29 13:53:21 -0300 | [diff] [blame] | 1501 | else |
Hans Verkuil | 5490a7c | 2010-12-19 20:21:36 -0300 | [diff] [blame] | 1502 | usbvision->bridge_type = BRIDGE_NT1003; |
Hans Verkuil | 5490a7c | 2010-12-19 20:21:36 -0300 | [diff] [blame] | 1503 | PDEBUG(DBG_PROBE, "bridge_type %d", usbvision->bridge_type); |
Thierry MERLE | 483dfdb | 2006-12-04 08:31:45 -0300 | [diff] [blame] | 1504 | |
Thierry MERLE | 2a9f8b5 | 2007-02-07 10:14:38 -0300 | [diff] [blame] | 1505 | /* compute alternate max packet sizes */ |
| 1506 | uif = dev->actconfig->interface[0]; |
| 1507 | |
Hans Verkuil | 6d6a48e | 2010-12-29 13:53:21 -0300 | [diff] [blame] | 1508 | usbvision->num_alt = uif->num_altsetting; |
| 1509 | PDEBUG(DBG_PROBE, "Alternate settings: %i", usbvision->num_alt); |
| 1510 | usbvision->alt_max_pkt_size = kmalloc(32 * usbvision->num_alt, GFP_KERNEL); |
Thierry MERLE | 2a9f8b5 | 2007-02-07 10:14:38 -0300 | [diff] [blame] | 1511 | if (usbvision->alt_max_pkt_size == NULL) { |
Mauro Carvalho Chehab | be9ed51 | 2009-01-08 09:13:42 -0300 | [diff] [blame] | 1512 | dev_err(&intf->dev, "usbvision: out of memory!\n"); |
Alexey Khoroshilov | afd270d | 2015-03-27 19:39:09 -0300 | [diff] [blame] | 1513 | ret = -ENOMEM; |
| 1514 | goto err_pkt; |
Thierry MERLE | 2a9f8b5 | 2007-02-07 10:14:38 -0300 | [diff] [blame] | 1515 | } |
| 1516 | |
Hans Verkuil | 6d6a48e | 2010-12-29 13:53:21 -0300 | [diff] [blame] | 1517 | for (i = 0; i < usbvision->num_alt; i++) { |
Thierry MERLE | 2a9f8b5 | 2007-02-07 10:14:38 -0300 | [diff] [blame] | 1518 | u16 tmp = le16_to_cpu(uif->altsetting[i].endpoint[1].desc. |
| 1519 | wMaxPacketSize); |
| 1520 | usbvision->alt_max_pkt_size[i] = |
| 1521 | (tmp & 0x07ff) * (((tmp & 0x1800) >> 11) + 1); |
Hans Verkuil | 6d6a48e | 2010-12-29 13:53:21 -0300 | [diff] [blame] | 1522 | PDEBUG(DBG_PROBE, "Alternate setting %i, max size= %i", i, |
Thierry MERLE | 2a9f8b5 | 2007-02-07 10:14:38 -0300 | [diff] [blame] | 1523 | usbvision->alt_max_pkt_size[i]); |
| 1524 | } |
| 1525 | |
| 1526 | |
Thierry MERLE | 483dfdb | 2006-12-04 08:31:45 -0300 | [diff] [blame] | 1527 | usbvision->nr = usbvision_nr++; |
| 1528 | |
Hans Verkuil | 5490a7c | 2010-12-19 20:21:36 -0300 | [diff] [blame] | 1529 | usbvision->have_tuner = usbvision_device_data[model].tuner; |
Hans Verkuil | 6d6a48e | 2010-12-29 13:53:21 -0300 | [diff] [blame] | 1530 | if (usbvision->have_tuner) |
Hans Verkuil | 5490a7c | 2010-12-19 20:21:36 -0300 | [diff] [blame] | 1531 | usbvision->tuner_type = usbvision_device_data[model].tuner_type; |
Thierry MERLE | 483dfdb | 2006-12-04 08:31:45 -0300 | [diff] [blame] | 1532 | |
Hans Verkuil | 5490a7c | 2010-12-19 20:21:36 -0300 | [diff] [blame] | 1533 | usbvision->dev_model = model; |
Thierry MERLE | 483dfdb | 2006-12-04 08:31:45 -0300 | [diff] [blame] | 1534 | usbvision->remove_pending = 0; |
| 1535 | usbvision->iface = ifnum; |
Hans Verkuil | 5490a7c | 2010-12-19 20:21:36 -0300 | [diff] [blame] | 1536 | usbvision->iface_alt = 0; |
Thierry MERLE | 483dfdb | 2006-12-04 08:31:45 -0300 | [diff] [blame] | 1537 | usbvision->video_endp = endpoint->bEndpointAddress; |
Hans Verkuil | 5490a7c | 2010-12-19 20:21:36 -0300 | [diff] [blame] | 1538 | usbvision->isoc_packet_size = 0; |
Thierry MERLE | 483dfdb | 2006-12-04 08:31:45 -0300 | [diff] [blame] | 1539 | usbvision->usb_bandwidth = 0; |
| 1540 | usbvision->user = 0; |
Hans Verkuil | 5490a7c | 2010-12-19 20:21:36 -0300 | [diff] [blame] | 1541 | usbvision->streaming = stream_off; |
Thierry MERLE | 483dfdb | 2006-12-04 08:31:45 -0300 | [diff] [blame] | 1542 | usbvision_configure_video(usbvision); |
Hans Verkuil | 8403472 | 2010-09-17 15:07:28 -0300 | [diff] [blame] | 1543 | usbvision_register_video(usbvision); |
Thierry MERLE | 483dfdb | 2006-12-04 08:31:45 -0300 | [diff] [blame] | 1544 | |
Hans Verkuil | 2aa689d | 2015-03-09 13:34:12 -0300 | [diff] [blame] | 1545 | usbvision_create_sysfs(&usbvision->vdev); |
Thierry MERLE | 483dfdb | 2006-12-04 08:31:45 -0300 | [diff] [blame] | 1546 | |
| 1547 | PDEBUG(DBG_PROBE, "success"); |
| 1548 | return 0; |
Alexey Khoroshilov | afd270d | 2015-03-27 19:39:09 -0300 | [diff] [blame] | 1549 | |
| 1550 | err_pkt: |
| 1551 | usbvision_release(usbvision); |
| 1552 | err_usb: |
| 1553 | usb_put_dev(dev); |
| 1554 | return ret; |
Thierry MERLE | 483dfdb | 2006-12-04 08:31:45 -0300 | [diff] [blame] | 1555 | } |
| 1556 | |
| 1557 | |
| 1558 | /* |
| 1559 | * usbvision_disconnect() |
| 1560 | * |
| 1561 | * This procedure stops all driver activity, deallocates interface-private |
| 1562 | * structure (pointed by 'ptr') and after that driver should be removable |
| 1563 | * with no ill consequences. |
| 1564 | * |
| 1565 | */ |
Greg Kroah-Hartman | 4c62e97 | 2012-12-21 13:17:53 -0800 | [diff] [blame] | 1566 | static void usbvision_disconnect(struct usb_interface *intf) |
Thierry MERLE | 483dfdb | 2006-12-04 08:31:45 -0300 | [diff] [blame] | 1567 | { |
Hans Verkuil | aeb506a | 2010-05-02 09:00:13 -0300 | [diff] [blame] | 1568 | struct usb_usbvision *usbvision = to_usbvision(usb_get_intfdata(intf)); |
Thierry MERLE | 483dfdb | 2006-12-04 08:31:45 -0300 | [diff] [blame] | 1569 | |
| 1570 | PDEBUG(DBG_PROBE, ""); |
| 1571 | |
| 1572 | if (usbvision == NULL) { |
Julia Lawall | 4202066 | 2010-05-27 09:36:45 -0300 | [diff] [blame] | 1573 | pr_err("%s: usb_get_intfdata() failed\n", __func__); |
Thierry MERLE | 483dfdb | 2006-12-04 08:31:45 -0300 | [diff] [blame] | 1574 | return; |
| 1575 | } |
Thierry MERLE | 483dfdb | 2006-12-04 08:31:45 -0300 | [diff] [blame] | 1576 | |
Hans Verkuil | c627b9d | 2010-12-18 11:06:09 -0300 | [diff] [blame] | 1577 | mutex_lock(&usbvision->v4l2_lock); |
Thierry MERLE | 483dfdb | 2006-12-04 08:31:45 -0300 | [diff] [blame] | 1578 | |
Hans Verkuil | 52cb0bf | 2010-12-19 20:33:51 -0300 | [diff] [blame] | 1579 | /* At this time we ask to cancel outstanding URBs */ |
Thierry MERLE | 483dfdb | 2006-12-04 08:31:45 -0300 | [diff] [blame] | 1580 | usbvision_stop_isoc(usbvision); |
| 1581 | |
Hans Verkuil | f1ba28c | 2009-03-14 12:27:01 -0300 | [diff] [blame] | 1582 | v4l2_device_disconnect(&usbvision->v4l2_dev); |
Hans Verkuil | 62e2594 | 2015-07-20 09:59:28 -0300 | [diff] [blame] | 1583 | usbvision_i2c_unregister(usbvision); |
Hans Verkuil | 52cb0bf | 2010-12-19 20:33:51 -0300 | [diff] [blame] | 1584 | usbvision->remove_pending = 1; /* Now all ISO data will be ignored */ |
Thierry MERLE | 483dfdb | 2006-12-04 08:31:45 -0300 | [diff] [blame] | 1585 | |
| 1586 | usb_put_dev(usbvision->dev); |
Hans Verkuil | 52cb0bf | 2010-12-19 20:33:51 -0300 | [diff] [blame] | 1587 | usbvision->dev = NULL; /* USB device is no more */ |
Thierry MERLE | 483dfdb | 2006-12-04 08:31:45 -0300 | [diff] [blame] | 1588 | |
Hans Verkuil | c627b9d | 2010-12-18 11:06:09 -0300 | [diff] [blame] | 1589 | mutex_unlock(&usbvision->v4l2_lock); |
Thierry MERLE | 483dfdb | 2006-12-04 08:31:45 -0300 | [diff] [blame] | 1590 | |
| 1591 | if (usbvision->user) { |
Thierry MERLE | c5f4836 | 2007-05-08 17:22:29 -0300 | [diff] [blame] | 1592 | printk(KERN_INFO "%s: In use, disconnect pending\n", |
Harvey Harrison | d2db42d | 2008-04-04 20:50:07 -0300 | [diff] [blame] | 1593 | __func__); |
Thierry MERLE | 483dfdb | 2006-12-04 08:31:45 -0300 | [diff] [blame] | 1594 | wake_up_interruptible(&usbvision->wait_frame); |
| 1595 | wake_up_interruptible(&usbvision->wait_stream); |
Thierry MERLE | c5f4836 | 2007-05-08 17:22:29 -0300 | [diff] [blame] | 1596 | } else { |
Thierry MERLE | 483dfdb | 2006-12-04 08:31:45 -0300 | [diff] [blame] | 1597 | usbvision_release(usbvision); |
| 1598 | } |
| 1599 | |
| 1600 | PDEBUG(DBG_PROBE, "success"); |
Thierry MERLE | 483dfdb | 2006-12-04 08:31:45 -0300 | [diff] [blame] | 1601 | } |
| 1602 | |
| 1603 | static struct usb_driver usbvision_driver = { |
| 1604 | .name = "usbvision", |
| 1605 | .id_table = usbvision_table, |
| 1606 | .probe = usbvision_probe, |
Greg Kroah-Hartman | 4c62e97 | 2012-12-21 13:17:53 -0800 | [diff] [blame] | 1607 | .disconnect = usbvision_disconnect, |
Thierry MERLE | 483dfdb | 2006-12-04 08:31:45 -0300 | [diff] [blame] | 1608 | }; |
| 1609 | |
| 1610 | /* |
Thierry MERLE | 483dfdb | 2006-12-04 08:31:45 -0300 | [diff] [blame] | 1611 | * usbvision_init() |
| 1612 | * |
| 1613 | * This code is run to initialize the driver. |
| 1614 | * |
| 1615 | */ |
| 1616 | static int __init usbvision_init(void) |
| 1617 | { |
Hans Verkuil | 5490a7c | 2010-12-19 20:21:36 -0300 | [diff] [blame] | 1618 | int err_code; |
Thierry MERLE | 483dfdb | 2006-12-04 08:31:45 -0300 | [diff] [blame] | 1619 | |
| 1620 | PDEBUG(DBG_PROBE, ""); |
| 1621 | |
Thierry MERLE | 483dfdb | 2006-12-04 08:31:45 -0300 | [diff] [blame] | 1622 | PDEBUG(DBG_IO, "IO debugging is enabled [video]"); |
| 1623 | PDEBUG(DBG_PROBE, "PROBE debugging is enabled [video]"); |
Thierry MERLE | c876a34 | 2006-12-09 16:42:54 -0300 | [diff] [blame] | 1624 | PDEBUG(DBG_MMAP, "MMAP debugging is enabled [video]"); |
Thierry MERLE | 483dfdb | 2006-12-04 08:31:45 -0300 | [diff] [blame] | 1625 | |
| 1626 | /* disable planar mode support unless compression enabled */ |
Hans Verkuil | 6d6a48e | 2010-12-29 13:53:21 -0300 | [diff] [blame] | 1627 | if (isoc_mode != ISOC_MODE_COMPRESS) { |
Hans Verkuil | 52cb0bf | 2010-12-19 20:33:51 -0300 | [diff] [blame] | 1628 | /* FIXME : not the right way to set supported flag */ |
| 1629 | usbvision_v4l2_format[6].supported = 0; /* V4L2_PIX_FMT_YVU420 */ |
| 1630 | usbvision_v4l2_format[7].supported = 0; /* V4L2_PIX_FMT_YUV422P */ |
Thierry MERLE | 483dfdb | 2006-12-04 08:31:45 -0300 | [diff] [blame] | 1631 | } |
| 1632 | |
Hans Verkuil | 5490a7c | 2010-12-19 20:21:36 -0300 | [diff] [blame] | 1633 | err_code = usb_register(&usbvision_driver); |
Thierry MERLE | 483dfdb | 2006-12-04 08:31:45 -0300 | [diff] [blame] | 1634 | |
Hans Verkuil | 5490a7c | 2010-12-19 20:21:36 -0300 | [diff] [blame] | 1635 | if (err_code == 0) { |
Dwaine Garden | de6a1b8 | 2007-01-07 21:13:55 -0300 | [diff] [blame] | 1636 | printk(KERN_INFO DRIVER_DESC " : " USBVISION_VERSION_STRING "\n"); |
Thierry MERLE | 483dfdb | 2006-12-04 08:31:45 -0300 | [diff] [blame] | 1637 | PDEBUG(DBG_PROBE, "success"); |
| 1638 | } |
Hans Verkuil | 5490a7c | 2010-12-19 20:21:36 -0300 | [diff] [blame] | 1639 | return err_code; |
Thierry MERLE | 483dfdb | 2006-12-04 08:31:45 -0300 | [diff] [blame] | 1640 | } |
| 1641 | |
| 1642 | static void __exit usbvision_exit(void) |
| 1643 | { |
Hans Verkuil | 6d6a48e | 2010-12-29 13:53:21 -0300 | [diff] [blame] | 1644 | PDEBUG(DBG_PROBE, ""); |
Thierry MERLE | 483dfdb | 2006-12-04 08:31:45 -0300 | [diff] [blame] | 1645 | |
Hans Verkuil | 6d6a48e | 2010-12-29 13:53:21 -0300 | [diff] [blame] | 1646 | usb_deregister(&usbvision_driver); |
| 1647 | PDEBUG(DBG_PROBE, "success"); |
Thierry MERLE | 483dfdb | 2006-12-04 08:31:45 -0300 | [diff] [blame] | 1648 | } |
| 1649 | |
| 1650 | module_init(usbvision_init); |
| 1651 | module_exit(usbvision_exit); |