aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/media/video/usbvision/usbvision-video.c
diff options
context:
space:
mode:
authorThierry MERLE <thierry.merle@free.fr>2007-05-08 16:22:29 -0400
committerMauro Carvalho Chehab <mchehab@infradead.org>2007-07-18 13:23:20 -0400
commitc5f48367fe54c46805774eeea8e828de54a5ad7b (patch)
tree5a78194b89745dc55054e6f656cacec20ca1a79b /drivers/media/video/usbvision/usbvision-video.c
parentea1f83cee96badc28d3f67ef29ac29c9d0eb0a1b (diff)
V4L/DVB (5644): Usbvision: video_ioctl2 conversion
The ioctl entry point, a big switch/case, is splitted in little functions. These functions are set as callbacks for the video_ioctl2 video4linux facility. This improves the driver memory consumption and enables the v4l1 compatibility as a side effect. Signed-off-by: Thierry MERLE <thierry.merle@free.fr> Acked-by: Dwaine P. Garden <dwainegarden@rogers.com> Signed-off-by: Mauro Carvalho Chehab <mchehab@infradead.org>
Diffstat (limited to 'drivers/media/video/usbvision/usbvision-video.c')
-rw-r--r--drivers/media/video/usbvision/usbvision-video.c1453
1 files changed, 780 insertions, 673 deletions
diff --git a/drivers/media/video/usbvision/usbvision-video.c b/drivers/media/video/usbvision/usbvision-video.c
index dab8bc968dfb..6b185a9a37e8 100644
--- a/drivers/media/video/usbvision/usbvision-video.c
+++ b/drivers/media/video/usbvision/usbvision-video.c
@@ -36,7 +36,8 @@
36 * - use submit_urb for all setup packets 36 * - use submit_urb for all setup packets
37 * - Fix memory settings for nt1004. It is 4 times as big as the 37 * - Fix memory settings for nt1004. It is 4 times as big as the
38 * nt1003 memory. 38 * nt1003 memory.
39 * - Add audio on endpoint 3 for nt1004 chip. Seems impossible, needs a codec interface. Which one? 39 * - Add audio on endpoint 3 for nt1004 chip.
40 * Seems impossible, needs a codec interface. Which one?
40 * - Clean up the driver. 41 * - Clean up the driver.
41 * - optimization for performance. 42 * - optimization for performance.
42 * - Add Videotext capability (VBI). Working on it..... 43 * - Add Videotext capability (VBI). Working on it.....
@@ -77,7 +78,8 @@
77#include "usbvision.h" 78#include "usbvision.h"
78#include "usbvision-cards.h" 79#include "usbvision-cards.h"
79 80
80#define DRIVER_AUTHOR "Joerg Heckenbach <joerg@heckenbach-aw.de>, Dwaine Garden <DwaineGarden@rogers.com>" 81#define DRIVER_AUTHOR "Joerg Heckenbach <joerg@heckenbach-aw.de>,\
82 Dwaine Garden <DwaineGarden@rogers.com>"
81#define DRIVER_NAME "usbvision" 83#define DRIVER_NAME "usbvision"
82#define DRIVER_ALIAS "USBVision" 84#define DRIVER_ALIAS "USBVision"
83#define DRIVER_DESC "USBVision USB Video Device Driver for Linux" 85#define DRIVER_DESC "USBVision USB Video Device Driver for Linux"
@@ -85,20 +87,25 @@
85#define USBVISION_DRIVER_VERSION_MAJOR 0 87#define USBVISION_DRIVER_VERSION_MAJOR 0
86#define USBVISION_DRIVER_VERSION_MINOR 9 88#define USBVISION_DRIVER_VERSION_MINOR 9
87#define USBVISION_DRIVER_VERSION_PATCHLEVEL 9 89#define USBVISION_DRIVER_VERSION_PATCHLEVEL 9
88#define USBVISION_DRIVER_VERSION KERNEL_VERSION(USBVISION_DRIVER_VERSION_MAJOR,USBVISION_DRIVER_VERSION_MINOR,USBVISION_DRIVER_VERSION_PATCHLEVEL) 90#define USBVISION_DRIVER_VERSION KERNEL_VERSION(USBVISION_DRIVER_VERSION_MAJOR,\
89#define USBVISION_VERSION_STRING __stringify(USBVISION_DRIVER_VERSION_MAJOR) "." __stringify(USBVISION_DRIVER_VERSION_MINOR) "." __stringify(USBVISION_DRIVER_VERSION_PATCHLEVEL) 91USBVISION_DRIVER_VERSION_MINOR,\
92USBVISION_DRIVER_VERSION_PATCHLEVEL)
93#define USBVISION_VERSION_STRING __stringify(USBVISION_DRIVER_VERSION_MAJOR)\
94 "." __stringify(USBVISION_DRIVER_VERSION_MINOR)\
95 "." __stringify(USBVISION_DRIVER_VERSION_PATCHLEVEL)
90 96
91#define ENABLE_HEXDUMP 0 /* Enable if you need it */ 97#define ENABLE_HEXDUMP 0 /* Enable if you need it */
92 98
93 99
94#ifdef USBVISION_DEBUG 100#ifdef USBVISION_DEBUG
95 #define PDEBUG(level, fmt, args...) \ 101 #define PDEBUG(level, fmt, args...) \
96 if (video_debug & (level)) info("[%s:%d] " fmt, __PRETTY_FUNCTION__, __LINE__ , ## args) 102 if (video_debug & (level)) \
103 info("[%s:%d] " fmt, __PRETTY_FUNCTION__, __LINE__ ,\
104 ## args)
97#else 105#else
98 #define PDEBUG(level, fmt, args...) do {} while(0) 106 #define PDEBUG(level, fmt, args...) do {} while(0)
99#endif 107#endif
100 108
101#define DBG_IOCTL 1<<0
102#define DBG_IO 1<<1 109#define DBG_IO 1<<1
103#define DBG_PROBE 1<<2 110#define DBG_PROBE 1<<2
104#define DBG_MMAP 1<<3 111#define DBG_MMAP 1<<3
@@ -108,7 +115,8 @@
108#define goto2next(str) while(*str!=' ') str++; while(*str==' ') str++; 115#define goto2next(str) while(*str!=' ') str++; while(*str==' ') str++;
109 116
110 117
111static int usbvision_nr = 0; // sequential number of usbvision device 118/* sequential number of usbvision device */
119static int usbvision_nr = 0;
112 120
113static struct usbvision_v4l2_format_st usbvision_v4l2_format[] = { 121static struct usbvision_v4l2_format_st usbvision_v4l2_format[] = {
114 { 1, 1, 8, V4L2_PIX_FMT_GREY , "GREY" }, 122 { 1, 1, 8, V4L2_PIX_FMT_GREY , "GREY" },
@@ -121,54 +129,54 @@ static struct usbvision_v4l2_format_st usbvision_v4l2_format[] = {
121 { 1, 2, 16, V4L2_PIX_FMT_YUV422P , "YUV422P" } 129 { 1, 2, 16, V4L2_PIX_FMT_YUV422P , "YUV422P" }
122}; 130};
123 131
124/* supported tv norms */ 132/* Function prototypes */
125static struct usbvision_tvnorm tvnorms[] = {
126 {
127 .name = "PAL",
128 .id = V4L2_STD_PAL,
129 }, {
130 .name = "NTSC",
131 .id = V4L2_STD_NTSC,
132 }, {
133 .name = "SECAM",
134 .id = V4L2_STD_SECAM,
135 }, {
136 .name = "PAL-M",
137 .id = V4L2_STD_PAL_M,
138 }
139};
140
141#define TVNORMS ARRAY_SIZE(tvnorms)
142
143// Function prototypes
144static void usbvision_release(struct usb_usbvision *usbvision); 133static void usbvision_release(struct usb_usbvision *usbvision);
145 134
146// Default initalization of device driver parameters 135/* Default initalization of device driver parameters */
147static int isocMode = ISOC_MODE_COMPRESS; // Set the default format for ISOC endpoint 136/* Set the default format for ISOC endpoint */
148static int video_debug = 0; // Set the default Debug Mode of the device driver 137static int isocMode = ISOC_MODE_COMPRESS;
149static int PowerOnAtOpen = 1; // Set the default device to power on at startup 138/* Set the default Debug Mode of the device driver */
150static int video_nr = -1; // Sequential Number of Video Device 139static int video_debug = 0;
151static int radio_nr = -1; // Sequential Number of Radio Device 140/* Set the default device to power on at startup */
152static int vbi_nr = -1; // Sequential Number of VBI Device 141static int PowerOnAtOpen = 1;
153 142/* Sequential Number of Video Device */
154// Grab parameters for the device driver 143static int video_nr = -1;
155 144/* Sequential Number of Radio Device */
156#if defined(module_param) // Showing parameters under SYSFS 145static int radio_nr = -1;
146/* Sequential Number of VBI Device */
147static int vbi_nr = -1;
148
149/* Grab parameters for the device driver */
150
151/* Showing parameters under SYSFS */
152#if defined(module_param)
157module_param(isocMode, int, 0444); 153module_param(isocMode, int, 0444);
158module_param(video_debug, int, 0444); 154module_param(video_debug, int, 0444);
159module_param(PowerOnAtOpen, int, 0444); 155module_param(PowerOnAtOpen, int, 0444);
160module_param(video_nr, int, 0444); 156module_param(video_nr, int, 0444);
161module_param(radio_nr, int, 0444); 157module_param(radio_nr, int, 0444);
162module_param(vbi_nr, int, 0444); 158module_param(vbi_nr, int, 0444);
163#else // Old Style 159#else
160/* Old Style */
164MODULE_PARAM(isocMode, "i"); 161MODULE_PARAM(isocMode, "i");
165MODULE_PARM(video_debug, "i"); // Grab the Debug Mode of the device driver 162/* Grab the Debug Mode of the device driver */
166MODULE_PARM(adjustCompression, "i"); // Grab the compression to be adaptive 163MODULE_PARM(video_debug, "i");
167MODULE_PARM(PowerOnAtOpen, "i"); // Grab the device to power on at startup 164/* Grab the compression to be adaptive */
168MODULE_PARM(SwitchSVideoInput, "i"); // To help people with Black and White output with using s-video input. Some cables and input device are wired differently. 165MODULE_PARM(adjustCompression, "i");
169MODULE_PARM(video_nr, "i"); // video_nr option allows to specify a certain /dev/videoX device (like /dev/video0 or /dev/video1 ...) 166/* Grab the device to power on at startup */
170MODULE_PARM(radio_nr, "i"); // radio_nr option allows to specify a certain /dev/radioX device (like /dev/radio0 or /dev/radio1 ...) 167MODULE_PARM(PowerOnAtOpen, "i");
171MODULE_PARM(vbi_nr, "i"); // vbi_nr option allows to specify a certain /dev/vbiX device (like /dev/vbi0 or /dev/vbi1 ...) 168/* To help people with Black and White output with using s-video input.
169 Some cables and input device are wired differently. */
170MODULE_PARM(SwitchSVideoInput, "i");
171/* video_nr option allows to specify a certain /dev/videoX device
172 (like /dev/video0 or /dev/video1 ...) */
173MODULE_PARM(video_nr, "i");
174/* radio_nr option allows to specify a certain /dev/radioX device
175 (like /dev/radio0 or /dev/radio1 ...) */
176MODULE_PARM(radio_nr, "i");
177/* vbi_nr option allows to specify a certain /dev/vbiX device
178 (like /dev/vbi0 or /dev/vbi1 ...) */
179MODULE_PARM(vbi_nr, "i");
172#endif 180#endif
173 181
174MODULE_PARM_DESC(isocMode, " Set the default format for ISOC endpoint. Default: 0x60 (Compression On)"); 182MODULE_PARM_DESC(isocMode, " Set the default format for ISOC endpoint. Default: 0x60 (Compression On)");
@@ -187,19 +195,21 @@ MODULE_VERSION(USBVISION_VERSION_STRING);
187MODULE_ALIAS(DRIVER_ALIAS); 195MODULE_ALIAS(DRIVER_ALIAS);
188 196
189 197
190/****************************************************************************************/ 198/*****************************************************************************/
191/* SYSFS Code - Copied from the stv680.c usb module. */ 199/* SYSFS Code - Copied from the stv680.c usb module. */
192/* Device information is located at /sys/class/video4linux/video0 */ 200/* Device information is located at /sys/class/video4linux/video0 */
193/* Device parameters information is located at /sys/module/usbvision */ 201/* Device parameters information is located at /sys/module/usbvision */
194/* Device USB Information is located at /sys/bus/usb/drivers/USBVision Video Grabber */ 202/* Device USB Information is located at */
195/****************************************************************************************/ 203/* /sys/bus/usb/drivers/USBVision Video Grabber */
204/*****************************************************************************/
196 205
197 206
198#define YES_NO(x) ((x) ? "Yes" : "No") 207#define YES_NO(x) ((x) ? "Yes" : "No")
199 208
200static inline struct usb_usbvision *cd_to_usbvision(struct class_device *cd) 209static inline struct usb_usbvision *cd_to_usbvision(struct class_device *cd)
201{ 210{
202 struct video_device *vdev = container_of(cd, struct video_device, class_dev); 211 struct video_device *vdev =
212 container_of(cd, struct video_device, class_dev);
203 return video_get_drvdata(vdev); 213 return video_get_drvdata(vdev);
204} 214}
205 215
@@ -211,15 +221,18 @@ static CLASS_DEVICE_ATTR(version, S_IRUGO, show_version, NULL);
211 221
212static ssize_t show_model(struct class_device *cd, char *buf) 222static ssize_t show_model(struct class_device *cd, char *buf)
213{ 223{
214 struct video_device *vdev = container_of(cd, struct video_device, class_dev); 224 struct video_device *vdev =
225 container_of(cd, struct video_device, class_dev);
215 struct usb_usbvision *usbvision = video_get_drvdata(vdev); 226 struct usb_usbvision *usbvision = video_get_drvdata(vdev);
216 return sprintf(buf, "%s\n", usbvision_device_data[usbvision->DevModel].ModelString); 227 return sprintf(buf, "%s\n",
228 usbvision_device_data[usbvision->DevModel].ModelString);
217} 229}
218static CLASS_DEVICE_ATTR(model, S_IRUGO, show_model, NULL); 230static CLASS_DEVICE_ATTR(model, S_IRUGO, show_model, NULL);
219 231
220static ssize_t show_hue(struct class_device *cd, char *buf) 232static ssize_t show_hue(struct class_device *cd, char *buf)
221{ 233{
222 struct video_device *vdev = container_of(cd, struct video_device, class_dev); 234 struct video_device *vdev =
235 container_of(cd, struct video_device, class_dev);
223 struct usb_usbvision *usbvision = video_get_drvdata(vdev); 236 struct usb_usbvision *usbvision = video_get_drvdata(vdev);
224 struct v4l2_control ctrl; 237 struct v4l2_control ctrl;
225 ctrl.id = V4L2_CID_HUE; 238 ctrl.id = V4L2_CID_HUE;
@@ -232,7 +245,8 @@ static CLASS_DEVICE_ATTR(hue, S_IRUGO, show_hue, NULL);
232 245
233static ssize_t show_contrast(struct class_device *cd, char *buf) 246static ssize_t show_contrast(struct class_device *cd, char *buf)
234{ 247{
235 struct video_device *vdev = container_of(cd, struct video_device, class_dev); 248 struct video_device *vdev =
249 container_of(cd, struct video_device, class_dev);
236 struct usb_usbvision *usbvision = video_get_drvdata(vdev); 250 struct usb_usbvision *usbvision = video_get_drvdata(vdev);
237 struct v4l2_control ctrl; 251 struct v4l2_control ctrl;
238 ctrl.id = V4L2_CID_CONTRAST; 252 ctrl.id = V4L2_CID_CONTRAST;
@@ -245,7 +259,8 @@ static CLASS_DEVICE_ATTR(contrast, S_IRUGO, show_contrast, NULL);
245 259
246static ssize_t show_brightness(struct class_device *cd, char *buf) 260static ssize_t show_brightness(struct class_device *cd, char *buf)
247{ 261{
248 struct video_device *vdev = container_of(cd, struct video_device, class_dev); 262 struct video_device *vdev =
263 container_of(cd, struct video_device, class_dev);
249 struct usb_usbvision *usbvision = video_get_drvdata(vdev); 264 struct usb_usbvision *usbvision = video_get_drvdata(vdev);
250 struct v4l2_control ctrl; 265 struct v4l2_control ctrl;
251 ctrl.id = V4L2_CID_BRIGHTNESS; 266 ctrl.id = V4L2_CID_BRIGHTNESS;
@@ -258,7 +273,8 @@ static CLASS_DEVICE_ATTR(brightness, S_IRUGO, show_brightness, NULL);
258 273
259static ssize_t show_saturation(struct class_device *cd, char *buf) 274static ssize_t show_saturation(struct class_device *cd, char *buf)
260{ 275{
261 struct video_device *vdev = container_of(cd, struct video_device, class_dev); 276 struct video_device *vdev =
277 container_of(cd, struct video_device, class_dev);
262 struct usb_usbvision *usbvision = video_get_drvdata(vdev); 278 struct usb_usbvision *usbvision = video_get_drvdata(vdev);
263 struct v4l2_control ctrl; 279 struct v4l2_control ctrl;
264 ctrl.id = V4L2_CID_SATURATION; 280 ctrl.id = V4L2_CID_SATURATION;
@@ -271,23 +287,28 @@ static CLASS_DEVICE_ATTR(saturation, S_IRUGO, show_saturation, NULL);
271 287
272static ssize_t show_streaming(struct class_device *cd, char *buf) 288static ssize_t show_streaming(struct class_device *cd, char *buf)
273{ 289{
274 struct video_device *vdev = container_of(cd, struct video_device, class_dev); 290 struct video_device *vdev =
291 container_of(cd, struct video_device, class_dev);
275 struct usb_usbvision *usbvision = video_get_drvdata(vdev); 292 struct usb_usbvision *usbvision = video_get_drvdata(vdev);
276 return sprintf(buf, "%s\n", YES_NO(usbvision->streaming==Stream_On?1:0)); 293 return sprintf(buf, "%s\n",
294 YES_NO(usbvision->streaming==Stream_On?1:0));
277} 295}
278static CLASS_DEVICE_ATTR(streaming, S_IRUGO, show_streaming, NULL); 296static CLASS_DEVICE_ATTR(streaming, S_IRUGO, show_streaming, NULL);
279 297
280static ssize_t show_compression(struct class_device *cd, char *buf) 298static ssize_t show_compression(struct class_device *cd, char *buf)
281{ 299{
282 struct video_device *vdev = container_of(cd, struct video_device, class_dev); 300 struct video_device *vdev =
301 container_of(cd, struct video_device, class_dev);
283 struct usb_usbvision *usbvision = video_get_drvdata(vdev); 302 struct usb_usbvision *usbvision = video_get_drvdata(vdev);
284 return sprintf(buf, "%s\n", YES_NO(usbvision->isocMode==ISOC_MODE_COMPRESS)); 303 return sprintf(buf, "%s\n",
304 YES_NO(usbvision->isocMode==ISOC_MODE_COMPRESS));
285} 305}
286static CLASS_DEVICE_ATTR(compression, S_IRUGO, show_compression, NULL); 306static CLASS_DEVICE_ATTR(compression, S_IRUGO, show_compression, NULL);
287 307
288static ssize_t show_device_bridge(struct class_device *cd, char *buf) 308static ssize_t show_device_bridge(struct class_device *cd, char *buf)
289{ 309{
290 struct video_device *vdev = container_of(cd, struct video_device, class_dev); 310 struct video_device *vdev =
311 container_of(cd, struct video_device, class_dev);
291 struct usb_usbvision *usbvision = video_get_drvdata(vdev); 312 struct usb_usbvision *usbvision = video_get_drvdata(vdev);
292 return sprintf(buf, "%d\n", usbvision->bridgeType); 313 return sprintf(buf, "%d\n", usbvision->bridgeType);
293} 314}
@@ -376,7 +397,8 @@ static void usbvision_remove_sysfs(struct video_device *vdev)
376static int usbvision_v4l2_open(struct inode *inode, struct file *file) 397static int usbvision_v4l2_open(struct inode *inode, struct file *file)
377{ 398{
378 struct video_device *dev = video_devdata(file); 399 struct video_device *dev = video_devdata(file);
379 struct usb_usbvision *usbvision = (struct usb_usbvision *) video_get_drvdata(dev); 400 struct usb_usbvision *usbvision =
401 (struct usb_usbvision *) video_get_drvdata(dev);
380 int errCode = 0; 402 int errCode = 0;
381 403
382 PDEBUG(DBG_IO, "open"); 404 PDEBUG(DBG_IO, "open");
@@ -390,7 +412,8 @@ static int usbvision_v4l2_open(struct inode *inode, struct file *file)
390 /* Allocate memory for the scratch ring buffer */ 412 /* Allocate memory for the scratch ring buffer */
391 errCode = usbvision_scratch_alloc(usbvision); 413 errCode = usbvision_scratch_alloc(usbvision);
392 if (isocMode==ISOC_MODE_COMPRESS) { 414 if (isocMode==ISOC_MODE_COMPRESS) {
393 /* Allocate intermediate decompression buffers only if needed */ 415 /* Allocate intermediate decompression buffers
416 only if needed */
394 errCode = usbvision_decompress_alloc(usbvision); 417 errCode = usbvision_decompress_alloc(usbvision);
395 } 418 }
396 if (errCode) { 419 if (errCode) {
@@ -421,11 +444,10 @@ static int usbvision_v4l2_open(struct inode *inode, struct file *file)
421 if (!errCode) { 444 if (!errCode) {
422 usbvision_begin_streaming(usbvision); 445 usbvision_begin_streaming(usbvision);
423 errCode = usbvision_init_isoc(usbvision); 446 errCode = usbvision_init_isoc(usbvision);
424 /* device needs to be initialized before isoc transfer */ 447 /* device must be initialized before isoc transfer */
425 usbvision_muxsel(usbvision,0); 448 usbvision_muxsel(usbvision,0);
426 usbvision->user++; 449 usbvision->user++;
427 } 450 } else {
428 else {
429 if (PowerOnAtOpen) { 451 if (PowerOnAtOpen) {
430 usbvision_i2c_unregister(usbvision); 452 usbvision_i2c_unregister(usbvision);
431 usbvision_power_off(usbvision); 453 usbvision_power_off(usbvision);
@@ -456,7 +478,8 @@ static int usbvision_v4l2_open(struct inode *inode, struct file *file)
456static int usbvision_v4l2_close(struct inode *inode, struct file *file) 478static int usbvision_v4l2_close(struct inode *inode, struct file *file)
457{ 479{
458 struct video_device *dev = video_devdata(file); 480 struct video_device *dev = video_devdata(file);
459 struct usb_usbvision *usbvision = (struct usb_usbvision *) video_get_drvdata(dev); 481 struct usb_usbvision *usbvision =
482 (struct usb_usbvision *) video_get_drvdata(dev);
460 483
461 PDEBUG(DBG_IO, "close"); 484 PDEBUG(DBG_IO, "close");
462 down(&usbvision->lock); 485 down(&usbvision->lock);
@@ -473,7 +496,8 @@ static int usbvision_v4l2_close(struct inode *inode, struct file *file)
473 usbvision->user--; 496 usbvision->user--;
474 497
475 if (PowerOnAtOpen) { 498 if (PowerOnAtOpen) {
476 /* power off in a little while to avoid off/on every close/open short sequences */ 499 /* power off in a little while
500 to avoid off/on every close/open short sequences */
477 usbvision_set_powerOffTimer(usbvision); 501 usbvision_set_powerOffTimer(usbvision);
478 usbvision->initialized = 0; 502 usbvision->initialized = 0;
479 } 503 }
@@ -498,600 +522,611 @@ static int usbvision_v4l2_close(struct inode *inode, struct file *file)
498 * This is part of Video 4 Linux API. The procedure handles ioctl() calls. 522 * This is part of Video 4 Linux API. The procedure handles ioctl() calls.
499 * 523 *
500 */ 524 */
501static int usbvision_v4l2_do_ioctl(struct inode *inode, struct file *file, 525#ifdef CONFIG_VIDEO_ADV_DEBUG
502 unsigned int cmd, void *arg) 526static int vidioc_g_register (struct file *file, void *priv,
527 struct v4l2_register *reg)
503{ 528{
504 struct video_device *dev = video_devdata(file); 529 struct video_device *dev = video_devdata(file);
505 struct usb_usbvision *usbvision = (struct usb_usbvision *) video_get_drvdata(dev); 530 struct usb_usbvision *usbvision =
506 531 (struct usb_usbvision *) video_get_drvdata(dev);
507 if (!USBVISION_IS_OPERATIONAL(usbvision)) 532 int errCode;
508 return -EFAULT;
509 533
510 switch (cmd) { 534 if (!v4l2_chip_match_host(reg->match_type, reg->match_chip))
535 return -EINVAL;
536 /* NT100x has a 8-bit register space */
537 errCode = usbvision_read_reg(usbvision, reg->reg&0xff);
538 if (errCode < 0) {
539 err("%s: VIDIOC_DBG_G_REGISTER failed: error %d",
540 __FUNCTION__, errCode);
541 return errCode;
542 }
543 return 0;
544}
511 545
512#ifdef CONFIG_VIDEO_ADV_DEBUG 546static int vidioc_s_register (struct file *file, void *priv,
513 /* ioctls to allow direct acces to the NT100x registers */ 547 struct v4l2_register *reg)
514 case VIDIOC_DBG_G_REGISTER: 548{
515 case VIDIOC_DBG_S_REGISTER: 549 struct video_device *dev = video_devdata(file);
516 { 550 struct usb_usbvision *usbvision =
517 struct v4l2_register *reg = arg; 551 (struct usb_usbvision *) video_get_drvdata(dev);
518 int errCode; 552 int errCode;
519
520 if (!v4l2_chip_match_host(reg->match_type, reg->match_chip))
521 return -EINVAL;
522 if (!capable(CAP_SYS_ADMIN))
523 return -EPERM;
524 /* NT100x has a 8-bit register space */
525 if (cmd == VIDIOC_DBG_G_REGISTER)
526 errCode = usbvision_read_reg(usbvision, reg->reg&0xff);
527 else
528 errCode = usbvision_write_reg(usbvision, reg->reg&0xff, reg->val);
529 if (errCode < 0) {
530 err("%s: VIDIOC_DBG_%c_REGISTER failed: error %d", __FUNCTION__,
531 cmd == VIDIOC_DBG_G_REGISTER ? 'G' : 'S', errCode);
532 return errCode;
533 }
534 if (cmd == VIDIOC_DBG_S_REGISTER)
535 reg->val = (u8)errCode;
536 553
537 PDEBUG(DBG_IOCTL, "VIDIOC_DBG_%c_REGISTER reg=0x%02X, value=0x%02X", 554 if (!v4l2_chip_match_host(reg->match_type, reg->match_chip))
538 cmd == VIDIOC_DBG_G_REGISTER ? 'G' : 'S', 555 return -EINVAL;
539 (unsigned int)reg->reg, (unsigned int)reg->val); 556 /* NT100x has a 8-bit register space */
540 return 0; 557 reg->val = (u8)usbvision_write_reg(usbvision, reg->reg&0xff, reg->val);
541 } 558 if (reg->val < 0) {
559 err("%s: VIDIOC_DBG_S_REGISTER failed: error %d",
560 __FUNCTION__, errCode);
561 return errCode;
562 }
563 return 0;
564}
542#endif 565#endif
543 case VIDIOC_QUERYCAP: 566
544 { 567static int vidioc_querycap (struct file *file, void *priv,
545 struct v4l2_capability *vc=arg; 568 struct v4l2_capability *vc)
546 569{
547 memset(vc, 0, sizeof(*vc)); 570 struct video_device *dev = video_devdata(file);
548 strlcpy(vc->driver, "USBVision", sizeof(vc->driver)); 571 struct usb_usbvision *usbvision =
549 strlcpy(vc->card, usbvision_device_data[usbvision->DevModel].ModelString, 572 (struct usb_usbvision *) video_get_drvdata(dev);
550 sizeof(vc->card)); 573
551 strlcpy(vc->bus_info, usbvision->dev->dev.bus_id, 574 strlcpy(vc->driver, "USBVision", sizeof(vc->driver));
552 sizeof(vc->bus_info)); 575 strlcpy(vc->card,
553 vc->version = USBVISION_DRIVER_VERSION; 576 usbvision_device_data[usbvision->DevModel].ModelString,
554 vc->capabilities = V4L2_CAP_VIDEO_CAPTURE | 577 sizeof(vc->card));
555 V4L2_CAP_AUDIO | 578 strlcpy(vc->bus_info, usbvision->dev->dev.bus_id,
556 V4L2_CAP_READWRITE | 579 sizeof(vc->bus_info));
557 V4L2_CAP_STREAMING | 580 vc->version = USBVISION_DRIVER_VERSION;
558 (usbvision->have_tuner ? V4L2_CAP_TUNER : 0); 581 vc->capabilities = V4L2_CAP_VIDEO_CAPTURE |
559 PDEBUG(DBG_IOCTL, "VIDIOC_QUERYCAP"); 582 V4L2_CAP_AUDIO |
560 return 0; 583 V4L2_CAP_READWRITE |
561 } 584 V4L2_CAP_STREAMING |
562 case VIDIOC_ENUMINPUT: 585 (usbvision->have_tuner ? V4L2_CAP_TUNER : 0);
563 { 586 return 0;
564 struct v4l2_input *vi = arg; 587}
565 int chan; 588
566 589static int vidioc_enum_input (struct file *file, void *priv,
567 if ((vi->index >= usbvision->video_inputs) || (vi->index < 0) ) 590 struct v4l2_input *vi)
568 return -EINVAL; 591{
569 if (usbvision->have_tuner) { 592 struct video_device *dev = video_devdata(file);
570 chan = vi->index; 593 struct usb_usbvision *usbvision =
571 } 594 (struct usb_usbvision *) video_get_drvdata(dev);
572 else { 595 int chan;
573 chan = vi->index + 1; //skip Television string 596
574 } 597 if ((vi->index >= usbvision->video_inputs) || (vi->index < 0) )
575 switch(chan) { 598 return -EINVAL;
576 case 0: 599 if (usbvision->have_tuner) {
577 if (usbvision_device_data[usbvision->DevModel].VideoChannels == 4) { 600 chan = vi->index;
578 strcpy(vi->name, "White Video Input"); 601 } else {
579 } 602 chan = vi->index + 1; /*skip Television string*/
580 else { 603 }
581 strcpy(vi->name, "Television"); 604 /* Determine the requested input characteristics
582 vi->type = V4L2_INPUT_TYPE_TUNER; 605 specific for each usbvision card model */
583 vi->audioset = 1; 606 switch(chan) {
584 vi->tuner = chan; 607 case 0:
585 vi->std = V4L2_STD_PAL | V4L2_STD_NTSC | V4L2_STD_SECAM; 608 if (usbvision_device_data[usbvision->DevModel].VideoChannels == 4) {
586 } 609 strcpy(vi->name, "White Video Input");
587 break; 610 } else {
588 case 1: 611 strcpy(vi->name, "Television");
589 vi->type = V4L2_INPUT_TYPE_CAMERA; 612 vi->type = V4L2_INPUT_TYPE_TUNER;
590 if (usbvision_device_data[usbvision->DevModel].VideoChannels == 4) { 613 vi->audioset = 1;
591 strcpy(vi->name, "Green Video Input"); 614 vi->tuner = chan;
592 } 615 vi->std = USBVISION_NORMS;
593 else {
594 strcpy(vi->name, "Composite Video Input");
595 }
596 vi->std = V4L2_STD_PAL;
597 break;
598 case 2:
599 vi->type = V4L2_INPUT_TYPE_CAMERA;
600 if (usbvision_device_data[usbvision->DevModel].VideoChannels == 4) {
601 strcpy(vi->name, "Yellow Video Input");
602 }
603 else {
604 strcpy(vi->name, "S-Video Input");
605 }
606 vi->std = V4L2_STD_PAL;
607 break;
608 case 3:
609 vi->type = V4L2_INPUT_TYPE_CAMERA;
610 strcpy(vi->name, "Red Video Input");
611 vi->std = V4L2_STD_PAL;
612 break;
613 }
614 PDEBUG(DBG_IOCTL, "VIDIOC_ENUMINPUT name=%s:%d tuners=%d type=%d norm=%x",
615 vi->name, vi->index, vi->tuner,vi->type,(int)vi->std);
616 return 0;
617 }
618 case VIDIOC_ENUMSTD:
619 {
620 struct v4l2_standard *e = arg;
621 unsigned int i;
622 int ret;
623
624 i = e->index;
625 if (i >= TVNORMS)
626 return -EINVAL;
627 ret = v4l2_video_std_construct(e, tvnorms[e->index].id,
628 tvnorms[e->index].name);
629 e->index = i;
630 if (ret < 0)
631 return ret;
632 return 0;
633 } 616 }
634 case VIDIOC_G_INPUT: 617 break;
635 { 618 case 1:
636 int *input = arg; 619 vi->type = V4L2_INPUT_TYPE_CAMERA;
637 *input = usbvision->ctl_input; 620 if (usbvision_device_data[usbvision->DevModel].VideoChannels == 4) {
638 return 0; 621 strcpy(vi->name, "Green Video Input");
622 } else {
623 strcpy(vi->name, "Composite Video Input");
639 } 624 }
640 case VIDIOC_S_INPUT: 625 vi->std = V4L2_STD_PAL;
641 { 626 break;
642 int *input = arg; 627 case 2:
643 if ((*input >= usbvision->video_inputs) || (*input < 0) ) 628 vi->type = V4L2_INPUT_TYPE_CAMERA;
644 return -EINVAL; 629 if (usbvision_device_data[usbvision->DevModel].VideoChannels == 4) {
645 usbvision->ctl_input = *input; 630 strcpy(vi->name, "Yellow Video Input");
646 631 } else {
647 down(&usbvision->lock); 632 strcpy(vi->name, "S-Video Input");
648 usbvision_muxsel(usbvision, usbvision->ctl_input);
649 usbvision_set_input(usbvision);
650 usbvision_set_output(usbvision, usbvision->curwidth, usbvision->curheight);
651 up(&usbvision->lock);
652 return 0;
653 } 633 }
654 case VIDIOC_G_STD: 634 vi->std = V4L2_STD_PAL;
655 { 635 break;
656 v4l2_std_id *id = arg; 636 case 3:
637 vi->type = V4L2_INPUT_TYPE_CAMERA;
638 strcpy(vi->name, "Red Video Input");
639 vi->std = V4L2_STD_PAL;
640 break;
641 }
642 return 0;
643}
657 644
658 *id = usbvision->tvnorm->id; 645static int vidioc_g_input (struct file *file, void *priv, unsigned int *input)
646{
647 struct video_device *dev = video_devdata(file);
648 struct usb_usbvision *usbvision =
649 (struct usb_usbvision *) video_get_drvdata(dev);
659 650
660 PDEBUG(DBG_IOCTL, "VIDIOC_G_STD std_id=%s", usbvision->tvnorm->name); 651 *input = usbvision->ctl_input;
661 return 0; 652 return 0;
662 } 653}
663 case VIDIOC_S_STD:
664 {
665 v4l2_std_id *id = arg;
666 unsigned int i;
667
668 for (i = 0; i < TVNORMS; i++)
669 if (*id == tvnorms[i].id)
670 break;
671 if (i == TVNORMS)
672 for (i = 0; i < TVNORMS; i++)
673 if (*id & tvnorms[i].id)
674 break;
675 if (i == TVNORMS)
676 return -EINVAL;
677
678 down(&usbvision->lock);
679 usbvision->tvnorm = &tvnorms[i];
680
681 call_i2c_clients(usbvision, VIDIOC_S_STD,
682 &usbvision->tvnorm->id);
683 654
684 up(&usbvision->lock); 655static int vidioc_s_input (struct file *file, void *priv, unsigned int input)
656{
657 struct video_device *dev = video_devdata(file);
658 struct usb_usbvision *usbvision =
659 (struct usb_usbvision *) video_get_drvdata(dev);
685 660
686 PDEBUG(DBG_IOCTL, "VIDIOC_S_STD std_id=%s", usbvision->tvnorm->name); 661 if ((input >= usbvision->video_inputs) || (input < 0) )
687 return 0; 662 return -EINVAL;
688 } 663 usbvision->ctl_input = input;
689 case VIDIOC_G_TUNER:
690 {
691 struct v4l2_tuner *vt = arg;
692
693 if (!usbvision->have_tuner || vt->index) // Only tuner 0
694 return -EINVAL;
695 if(usbvision->radio) {
696 strcpy(vt->name, "Radio");
697 vt->type = V4L2_TUNER_RADIO;
698 }
699 else {
700 strcpy(vt->name, "Television");
701 }
702 /* Let clients fill in the remainder of this struct */
703 call_i2c_clients(usbvision,VIDIOC_G_TUNER,vt);
704 664
705 PDEBUG(DBG_IOCTL, "VIDIOC_G_TUNER for %s signal=%x, afc=%x", 665 down(&usbvision->lock);
706 vt->name, vt->signal,vt->afc); 666 usbvision_muxsel(usbvision, usbvision->ctl_input);
707 return 0; 667 usbvision_set_input(usbvision);
708 } 668 usbvision_set_output(usbvision,
709 case VIDIOC_S_TUNER: 669 usbvision->curwidth,
710 { 670 usbvision->curheight);
711 struct v4l2_tuner *vt = arg; 671 up(&usbvision->lock);
712 672 return 0;
713 // Only no or one tuner for now 673}
714 if (!usbvision->have_tuner || vt->index)
715 return -EINVAL;
716 /* let clients handle this */
717 call_i2c_clients(usbvision,VIDIOC_S_TUNER,vt);
718
719 PDEBUG(DBG_IOCTL, "VIDIOC_S_TUNER");
720 return 0;
721 }
722 case VIDIOC_G_FREQUENCY:
723 {
724 struct v4l2_frequency *freq = arg;
725 674
726 freq->tuner = 0; // Only one tuner 675static int vidioc_s_std (struct file *file, void *priv, v4l2_std_id *id)
727 if(usbvision->radio) { 676{
728 freq->type = V4L2_TUNER_RADIO; 677 struct video_device *dev = video_devdata(file);
729 } 678 struct usb_usbvision *usbvision =
730 else { 679 (struct usb_usbvision *) video_get_drvdata(dev);
731 freq->type = V4L2_TUNER_ANALOG_TV; 680 usbvision->tvnormId=*id;
732 }
733 freq->frequency = usbvision->freq;
734 PDEBUG(DBG_IOCTL, "VIDIOC_G_FREQUENCY freq=0x%X", (unsigned)freq->frequency);
735 return 0;
736 }
737 case VIDIOC_S_FREQUENCY:
738 {
739 struct v4l2_frequency *freq = arg;
740
741 // Only no or one tuner for now
742 if (!usbvision->have_tuner || freq->tuner)
743 return -EINVAL;
744
745 usbvision->freq = freq->frequency;
746 call_i2c_clients(usbvision, cmd, freq);
747 PDEBUG(DBG_IOCTL, "VIDIOC_S_FREQUENCY freq=0x%X", (unsigned)freq->frequency);
748 return 0;
749 }
750 case VIDIOC_G_AUDIO:
751 {
752 struct v4l2_audio *v = arg;
753 memset(v,0, sizeof(v));
754 if(usbvision->radio) {
755 strcpy(v->name,"Radio");
756 }
757 else {
758 strcpy(v->name, "TV");
759 }
760 PDEBUG(DBG_IOCTL, "VIDIOC_G_AUDIO");
761 return 0;
762 }
763 case VIDIOC_S_AUDIO:
764 {
765 struct v4l2_audio *v = arg;
766 if(v->index) {
767 return -EINVAL;
768 }
769 PDEBUG(DBG_IOCTL, "VIDIOC_S_AUDIO");
770 return 0;
771 }
772 case VIDIOC_QUERYCTRL:
773 {
774 struct v4l2_queryctrl *ctrl = arg;
775 int id=ctrl->id;
776 681
777 memset(ctrl,0,sizeof(*ctrl)); 682 down(&usbvision->lock);
778 ctrl->id=id; 683 call_i2c_clients(usbvision, VIDIOC_S_STD,
684 &usbvision->tvnormId);
685 up(&usbvision->lock);
779 686
780 call_i2c_clients(usbvision, cmd, arg); 687 return 0;
688}
781 689
782 if (ctrl->type) 690static int vidioc_g_tuner (struct file *file, void *priv,
783 return 0; 691 struct v4l2_tuner *vt)
784 else 692{
785 return -EINVAL; 693 struct video_device *dev = video_devdata(file);
694 struct usb_usbvision *usbvision =
695 (struct usb_usbvision *) video_get_drvdata(dev);
786 696
787 PDEBUG(DBG_IOCTL,"VIDIOC_QUERYCTRL id=%x value=%x",ctrl->id,ctrl->type); 697 if (!usbvision->have_tuner || vt->index) // Only tuner 0
788 } 698 return -EINVAL;
789 case VIDIOC_G_CTRL: 699 if(usbvision->radio) {
790 { 700 strcpy(vt->name, "Radio");
791 struct v4l2_control *ctrl = arg; 701 vt->type = V4L2_TUNER_RADIO;
792 call_i2c_clients(usbvision, VIDIOC_G_CTRL, ctrl); 702 } else {
793 PDEBUG(DBG_IOCTL,"VIDIOC_G_CTRL id=%x value=%x",ctrl->id,ctrl->value); 703 strcpy(vt->name, "Television");
794 return 0; 704 }
795 } 705 /* Let clients fill in the remainder of this struct */
796 case VIDIOC_S_CTRL: 706 call_i2c_clients(usbvision,VIDIOC_G_TUNER,vt);
797 {
798 struct v4l2_control *ctrl = arg;
799 707
800 PDEBUG(DBG_IOCTL, "VIDIOC_S_CTRL id=%x value=%x",ctrl->id,ctrl->value); 708 return 0;
801 call_i2c_clients(usbvision, VIDIOC_S_CTRL, ctrl); 709}
802 return 0;
803 }
804 case VIDIOC_REQBUFS:
805 {
806 struct v4l2_requestbuffers *vr = arg;
807 int ret;
808 710
809 RESTRICT_TO_RANGE(vr->count,1,USBVISION_NUMFRAMES); 711static int vidioc_s_tuner (struct file *file, void *priv,
712 struct v4l2_tuner *vt)
713{
714 struct video_device *dev = video_devdata(file);
715 struct usb_usbvision *usbvision =
716 (struct usb_usbvision *) video_get_drvdata(dev);
810 717
811 // Check input validity : the user must do a VIDEO CAPTURE and MMAP method. 718 // Only no or one tuner for now
812 if((vr->type != V4L2_BUF_TYPE_VIDEO_CAPTURE) || 719 if (!usbvision->have_tuner || vt->index)
813 (vr->memory != V4L2_MEMORY_MMAP)) 720 return -EINVAL;
814 return -EINVAL; 721 /* let clients handle this */
722 call_i2c_clients(usbvision,VIDIOC_S_TUNER,vt);
815 723
816 if(usbvision->streaming == Stream_On) { 724 return 0;
817 if ((ret = usbvision_stream_interrupt(usbvision))) 725}
818 return ret;
819 }
820 726
821 usbvision_frames_free(usbvision); 727static int vidioc_g_frequency (struct file *file, void *priv,
822 usbvision_empty_framequeues(usbvision); 728 struct v4l2_frequency *freq)
823 vr->count = usbvision_frames_alloc(usbvision,vr->count); 729{
730 struct video_device *dev = video_devdata(file);
731 struct usb_usbvision *usbvision =
732 (struct usb_usbvision *) video_get_drvdata(dev);
824 733
825 usbvision->curFrame = NULL; 734 freq->tuner = 0; // Only one tuner
735 if(usbvision->radio) {
736 freq->type = V4L2_TUNER_RADIO;
737 } else {
738 freq->type = V4L2_TUNER_ANALOG_TV;
739 }
740 freq->frequency = usbvision->freq;
826 741
827 PDEBUG(DBG_IOCTL, "VIDIOC_REQBUFS count=%d",vr->count); 742 return 0;
828 return 0; 743}
829 }
830 case VIDIOC_QUERYBUF:
831 {
832 struct v4l2_buffer *vb = arg;
833 struct usbvision_frame *frame;
834 744
835 // FIXME : must control that buffers are mapped (VIDIOC_REQBUFS has been called) 745static int vidioc_s_frequency (struct file *file, void *priv,
746 struct v4l2_frequency *freq)
747{
748 struct video_device *dev = video_devdata(file);
749 struct usb_usbvision *usbvision =
750 (struct usb_usbvision *) video_get_drvdata(dev);
836 751
837 if(vb->type != V4L2_CAP_VIDEO_CAPTURE) { 752 // Only no or one tuner for now
838 return -EINVAL; 753 if (!usbvision->have_tuner || freq->tuner)
839 } 754 return -EINVAL;
840 if(vb->index>=usbvision->num_frames) {
841 return -EINVAL;
842 }
843 // Updating the corresponding frame state
844 vb->flags = 0;
845 frame = &usbvision->frame[vb->index];
846 if(frame->grabstate >= FrameState_Ready)
847 vb->flags |= V4L2_BUF_FLAG_QUEUED;
848 if(frame->grabstate >= FrameState_Done)
849 vb->flags |= V4L2_BUF_FLAG_DONE;
850 if(frame->grabstate == FrameState_Unused)
851 vb->flags |= V4L2_BUF_FLAG_MAPPED;
852 vb->memory = V4L2_MEMORY_MMAP;
853
854 vb->m.offset = vb->index*PAGE_ALIGN(usbvision->max_frame_size);
855
856 vb->memory = V4L2_MEMORY_MMAP;
857 vb->field = V4L2_FIELD_NONE;
858 vb->length = usbvision->curwidth*usbvision->curheight*usbvision->palette.bytes_per_pixel;
859 vb->timestamp = usbvision->frame[vb->index].timestamp;
860 vb->sequence = usbvision->frame[vb->index].sequence;
861 return 0;
862 }
863 case VIDIOC_QBUF:
864 {
865 struct v4l2_buffer *vb = arg;
866 struct usbvision_frame *frame;
867 unsigned long lock_flags;
868
869 // FIXME : works only on VIDEO_CAPTURE MODE, MMAP.
870 if(vb->type != V4L2_CAP_VIDEO_CAPTURE) {
871 return -EINVAL;
872 }
873 if(vb->index>=usbvision->num_frames) {
874 return -EINVAL;
875 }
876 755
877 frame = &usbvision->frame[vb->index]; 756 usbvision->freq = freq->frequency;
757 call_i2c_clients(usbvision, VIDIOC_S_FREQUENCY, freq);
878 758
879 if (frame->grabstate != FrameState_Unused) { 759 return 0;
880 return -EAGAIN; 760}
881 }
882 761
883 /* Mark it as ready and enqueue frame */ 762static int vidioc_g_audio (struct file *file, void *priv, struct v4l2_audio *a)
884 frame->grabstate = FrameState_Ready; 763{
885 frame->scanstate = ScanState_Scanning; 764 struct video_device *dev = video_devdata(file);
886 frame->scanlength = 0; /* Accumulated in usbvision_parse_data() */ 765 struct usb_usbvision *usbvision =
766 (struct usb_usbvision *) video_get_drvdata(dev);
887 767
888 vb->flags &= ~V4L2_BUF_FLAG_DONE; 768 memset(a,0,sizeof(*a));
769 if(usbvision->radio) {
770 strcpy(a->name,"Radio");
771 } else {
772 strcpy(a->name, "TV");
773 }
889 774
890 /* set v4l2_format index */ 775 return 0;
891 frame->v4l2_format = usbvision->palette; 776}
892 777
893 spin_lock_irqsave(&usbvision->queue_lock, lock_flags); 778static int vidioc_s_audio (struct file *file, void *fh,
894 list_add_tail(&usbvision->frame[vb->index].frame, &usbvision->inqueue); 779 struct v4l2_audio *a)
895 spin_unlock_irqrestore(&usbvision->queue_lock, lock_flags); 780{
781 if(a->index) {
782 return -EINVAL;
783 }
896 784
897 PDEBUG(DBG_IOCTL, "VIDIOC_QBUF frame #%d",vb->index); 785 return 0;
898 return 0; 786}
899 }
900 case VIDIOC_DQBUF:
901 {
902 struct v4l2_buffer *vb = arg;
903 int ret;
904 struct usbvision_frame *f;
905 unsigned long lock_flags;
906
907 if (vb->type != V4L2_BUF_TYPE_VIDEO_CAPTURE)
908 return -EINVAL;
909
910 if (list_empty(&(usbvision->outqueue))) {
911 if (usbvision->streaming == Stream_Idle)
912 return -EINVAL;
913 ret = wait_event_interruptible
914 (usbvision->wait_frame,
915 !list_empty(&(usbvision->outqueue)));
916 if (ret)
917 return ret;
918 }
919 787
920 spin_lock_irqsave(&usbvision->queue_lock, lock_flags); 788static int vidioc_queryctrl (struct file *file, void *priv,
921 f = list_entry(usbvision->outqueue.next, 789 struct v4l2_queryctrl *ctrl)
922 struct usbvision_frame, frame); 790{
923 list_del(usbvision->outqueue.next); 791 struct video_device *dev = video_devdata(file);
924 spin_unlock_irqrestore(&usbvision->queue_lock, lock_flags); 792 struct usb_usbvision *usbvision =
925 793 (struct usb_usbvision *) video_get_drvdata(dev);
926 f->grabstate = FrameState_Unused; 794 int id=ctrl->id;
927
928 vb->memory = V4L2_MEMORY_MMAP;
929 vb->flags = V4L2_BUF_FLAG_MAPPED | V4L2_BUF_FLAG_QUEUED | V4L2_BUF_FLAG_DONE;
930 vb->index = f->index;
931 vb->sequence = f->sequence;
932 vb->timestamp = f->timestamp;
933 vb->field = V4L2_FIELD_NONE;
934 vb->bytesused = f->scanlength;
935
936 return 0;
937 }
938 case VIDIOC_STREAMON:
939 {
940 int b=V4L2_BUF_TYPE_VIDEO_CAPTURE;
941 795
942 usbvision->streaming = Stream_On; 796 memset(ctrl,0,sizeof(*ctrl));
797 ctrl->id=id;
943 798
944 call_i2c_clients(usbvision,VIDIOC_STREAMON , &b); 799 call_i2c_clients(usbvision, VIDIOC_QUERYCTRL, ctrl);
945 800
946 PDEBUG(DBG_IOCTL, "VIDIOC_STREAMON"); 801 if (!ctrl->type)
802 return -EINVAL;
947 803
948 return 0; 804 return 0;
949 } 805}
950 case VIDIOC_STREAMOFF:
951 {
952 int *type = arg;
953 int b=V4L2_BUF_TYPE_VIDEO_CAPTURE;
954
955 if (*type != V4L2_BUF_TYPE_VIDEO_CAPTURE)
956 return -EINVAL;
957
958 if(usbvision->streaming == Stream_On) {
959 usbvision_stream_interrupt(usbvision);
960 // Stop all video streamings
961 call_i2c_clients(usbvision,VIDIOC_STREAMOFF , &b);
962 }
963 usbvision_empty_framequeues(usbvision);
964 806
965 PDEBUG(DBG_IOCTL, "VIDIOC_STREAMOFF"); 807static int vidioc_g_ctrl (struct file *file, void *priv,
966 return 0; 808 struct v4l2_control *ctrl)
967 } 809{
968 case VIDIOC_ENUM_FMT: 810 struct video_device *dev = video_devdata(file);
969 { 811 struct usb_usbvision *usbvision =
970 struct v4l2_fmtdesc *vfd = arg; 812 (struct usb_usbvision *) video_get_drvdata(dev);
813 call_i2c_clients(usbvision, VIDIOC_G_CTRL, ctrl);
971 814
972 if(vfd->index>=USBVISION_SUPPORTED_PALETTES-1) { 815 return 0;
973 return -EINVAL; 816}
974 } 817
975 vfd->flags = 0; 818static int vidioc_s_ctrl (struct file *file, void *priv,
976 vfd->type = V4L2_BUF_TYPE_VIDEO_CAPTURE; 819 struct v4l2_control *ctrl)
977 strcpy(vfd->description,usbvision_v4l2_format[vfd->index].desc); 820{
978 vfd->pixelformat = usbvision_v4l2_format[vfd->index].format; 821 struct video_device *dev = video_devdata(file);
979 memset(vfd->reserved, 0, sizeof(vfd->reserved)); 822 struct usb_usbvision *usbvision =
980 return 0; 823 (struct usb_usbvision *) video_get_drvdata(dev);
981 } 824 call_i2c_clients(usbvision, VIDIOC_S_CTRL, ctrl);
982 case VIDIOC_G_FMT: 825
983 { 826 return 0;
984 struct v4l2_format *vf = arg; 827}
985 828
986 switch (vf->type) { 829static int vidioc_reqbufs (struct file *file,
987 case V4L2_BUF_TYPE_VIDEO_CAPTURE: 830 void *priv, struct v4l2_requestbuffers *vr)
988 { 831{
989 vf->fmt.pix.width = usbvision->curwidth; 832 struct video_device *dev = video_devdata(file);
990 vf->fmt.pix.height = usbvision->curheight; 833 struct usb_usbvision *usbvision =
991 vf->fmt.pix.pixelformat = usbvision->palette.format; 834 (struct usb_usbvision *) video_get_drvdata(dev);
992 vf->fmt.pix.bytesperline = usbvision->curwidth*usbvision->palette.bytes_per_pixel; 835 int ret;
993 vf->fmt.pix.sizeimage = vf->fmt.pix.bytesperline*usbvision->curheight; 836
994 vf->fmt.pix.colorspace = V4L2_COLORSPACE_SMPTE170M; 837 RESTRICT_TO_RANGE(vr->count,1,USBVISION_NUMFRAMES);
995 vf->fmt.pix.field = V4L2_FIELD_NONE; /* Always progressive image */ 838
996 PDEBUG(DBG_IOCTL, "VIDIOC_G_FMT w=%d, h=%d, format=%s", 839 /* Check input validity:
997 vf->fmt.pix.width, vf->fmt.pix.height,usbvision->palette.desc); 840 the user must do a VIDEO CAPTURE and MMAP method. */
998 return 0; 841 if((vr->type != V4L2_BUF_TYPE_VIDEO_CAPTURE) ||
999 } 842 (vr->memory != V4L2_MEMORY_MMAP))
1000 default: 843 return -EINVAL;
1001 PDEBUG(DBG_IOCTL, "VIDIOC_G_FMT invalid type %d",vf->type); 844
1002 return -EINVAL; 845 if(usbvision->streaming == Stream_On) {
1003 } 846 if ((ret = usbvision_stream_interrupt(usbvision)))
1004 return 0; 847 return ret;
1005 }
1006 case VIDIOC_TRY_FMT:
1007 case VIDIOC_S_FMT:
1008 {
1009 struct v4l2_format *vf = arg;
1010 int formatIdx,ret;
1011
1012 switch(vf->type) {
1013 case V4L2_BUF_TYPE_VIDEO_CAPTURE:
1014 {
1015 /* Find requested format in available ones */
1016 for(formatIdx=0;formatIdx<USBVISION_SUPPORTED_PALETTES;formatIdx++) {
1017 if(vf->fmt.pix.pixelformat == usbvision_v4l2_format[formatIdx].format) {
1018 usbvision->palette = usbvision_v4l2_format[formatIdx];
1019 break;
1020 }
1021 }
1022 /* robustness */
1023 if(formatIdx == USBVISION_SUPPORTED_PALETTES) {
1024 return -EINVAL;
1025 }
1026 RESTRICT_TO_RANGE(vf->fmt.pix.width, MIN_FRAME_WIDTH, MAX_FRAME_WIDTH);
1027 RESTRICT_TO_RANGE(vf->fmt.pix.height, MIN_FRAME_HEIGHT, MAX_FRAME_HEIGHT);
1028
1029 vf->fmt.pix.bytesperline = vf->fmt.pix.width*usbvision->palette.bytes_per_pixel;
1030 vf->fmt.pix.sizeimage = vf->fmt.pix.bytesperline*vf->fmt.pix.height;
1031
1032 if(cmd == VIDIOC_TRY_FMT) {
1033 PDEBUG(DBG_IOCTL, "VIDIOC_TRY_FMT grabdisplay w=%d, h=%d, format=%s",
1034 vf->fmt.pix.width, vf->fmt.pix.height,usbvision->palette.desc);
1035 return 0;
1036 }
1037
1038 /* stop io in case it is already in progress */
1039 if(usbvision->streaming == Stream_On) {
1040 if ((ret = usbvision_stream_interrupt(usbvision)))
1041 return ret;
1042 }
1043 usbvision_frames_free(usbvision);
1044 usbvision_empty_framequeues(usbvision);
1045
1046 usbvision->curFrame = NULL;
1047
1048 // by now we are committed to the new data...
1049 down(&usbvision->lock);
1050 usbvision_set_output(usbvision, vf->fmt.pix.width, vf->fmt.pix.height);
1051 up(&usbvision->lock);
1052
1053 PDEBUG(DBG_IOCTL, "VIDIOC_S_FMT grabdisplay w=%d, h=%d, format=%s",
1054 vf->fmt.pix.width, vf->fmt.pix.height,usbvision->palette.desc);
1055 return 0;
1056 }
1057 default:
1058 return -EINVAL;
1059 }
1060 }
1061 default:
1062 return -ENOIOCTLCMD;
1063 } 848 }
849
850 usbvision_frames_free(usbvision);
851 usbvision_empty_framequeues(usbvision);
852 vr->count = usbvision_frames_alloc(usbvision,vr->count);
853
854 usbvision->curFrame = NULL;
855
1064 return 0; 856 return 0;
1065} 857}
1066 858
1067static int usbvision_v4l2_ioctl(struct inode *inode, struct file *file, 859static int vidioc_querybuf (struct file *file,
1068 unsigned int cmd, unsigned long arg) 860 void *priv, struct v4l2_buffer *vb)
1069{ 861{
1070 return video_usercopy(inode, file, cmd, arg, usbvision_v4l2_do_ioctl); 862 struct video_device *dev = video_devdata(file);
863 struct usb_usbvision *usbvision =
864 (struct usb_usbvision *) video_get_drvdata(dev);
865 struct usbvision_frame *frame;
866
867 /* FIXME : must control
868 that buffers are mapped (VIDIOC_REQBUFS has been called) */
869 if(vb->type != V4L2_CAP_VIDEO_CAPTURE) {
870 return -EINVAL;
871 }
872 if(vb->index>=usbvision->num_frames) {
873 return -EINVAL;
874 }
875 /* Updating the corresponding frame state */
876 vb->flags = 0;
877 frame = &usbvision->frame[vb->index];
878 if(frame->grabstate >= FrameState_Ready)
879 vb->flags |= V4L2_BUF_FLAG_QUEUED;
880 if(frame->grabstate >= FrameState_Done)
881 vb->flags |= V4L2_BUF_FLAG_DONE;
882 if(frame->grabstate == FrameState_Unused)
883 vb->flags |= V4L2_BUF_FLAG_MAPPED;
884 vb->memory = V4L2_MEMORY_MMAP;
885
886 vb->m.offset = vb->index*PAGE_ALIGN(usbvision->max_frame_size);
887
888 vb->memory = V4L2_MEMORY_MMAP;
889 vb->field = V4L2_FIELD_NONE;
890 vb->length = usbvision->curwidth*
891 usbvision->curheight*
892 usbvision->palette.bytes_per_pixel;
893 vb->timestamp = usbvision->frame[vb->index].timestamp;
894 vb->sequence = usbvision->frame[vb->index].sequence;
895 return 0;
1071} 896}
1072 897
898static int vidioc_qbuf (struct file *file, void *priv, struct v4l2_buffer *vb)
899{
900 struct video_device *dev = video_devdata(file);
901 struct usb_usbvision *usbvision =
902 (struct usb_usbvision *) video_get_drvdata(dev);
903 struct usbvision_frame *frame;
904 unsigned long lock_flags;
905
906 /* FIXME : works only on VIDEO_CAPTURE MODE, MMAP. */
907 if(vb->type != V4L2_CAP_VIDEO_CAPTURE) {
908 return -EINVAL;
909 }
910 if(vb->index>=usbvision->num_frames) {
911 return -EINVAL;
912 }
913
914 frame = &usbvision->frame[vb->index];
915
916 if (frame->grabstate != FrameState_Unused) {
917 return -EAGAIN;
918 }
919
920 /* Mark it as ready and enqueue frame */
921 frame->grabstate = FrameState_Ready;
922 frame->scanstate = ScanState_Scanning;
923 frame->scanlength = 0; /* Accumulated in usbvision_parse_data() */
924
925 vb->flags &= ~V4L2_BUF_FLAG_DONE;
926
927 /* set v4l2_format index */
928 frame->v4l2_format = usbvision->palette;
929
930 spin_lock_irqsave(&usbvision->queue_lock, lock_flags);
931 list_add_tail(&usbvision->frame[vb->index].frame, &usbvision->inqueue);
932 spin_unlock_irqrestore(&usbvision->queue_lock, lock_flags);
933
934 return 0;
935}
936
937static int vidioc_dqbuf (struct file *file, void *priv, struct v4l2_buffer *vb)
938{
939 struct video_device *dev = video_devdata(file);
940 struct usb_usbvision *usbvision =
941 (struct usb_usbvision *) video_get_drvdata(dev);
942 int ret;
943 struct usbvision_frame *f;
944 unsigned long lock_flags;
945
946 if (vb->type != V4L2_BUF_TYPE_VIDEO_CAPTURE)
947 return -EINVAL;
948
949 if (list_empty(&(usbvision->outqueue))) {
950 if (usbvision->streaming == Stream_Idle)
951 return -EINVAL;
952 ret = wait_event_interruptible
953 (usbvision->wait_frame,
954 !list_empty(&(usbvision->outqueue)));
955 if (ret)
956 return ret;
957 }
958
959 spin_lock_irqsave(&usbvision->queue_lock, lock_flags);
960 f = list_entry(usbvision->outqueue.next,
961 struct usbvision_frame, frame);
962 list_del(usbvision->outqueue.next);
963 spin_unlock_irqrestore(&usbvision->queue_lock, lock_flags);
964
965 f->grabstate = FrameState_Unused;
966
967 vb->memory = V4L2_MEMORY_MMAP;
968 vb->flags = V4L2_BUF_FLAG_MAPPED |
969 V4L2_BUF_FLAG_QUEUED |
970 V4L2_BUF_FLAG_DONE;
971 vb->index = f->index;
972 vb->sequence = f->sequence;
973 vb->timestamp = f->timestamp;
974 vb->field = V4L2_FIELD_NONE;
975 vb->bytesused = f->scanlength;
976
977 return 0;
978}
979
980static int vidioc_streamon(struct file *file, void *priv, enum v4l2_buf_type i)
981{
982 struct video_device *dev = video_devdata(file);
983 struct usb_usbvision *usbvision =
984 (struct usb_usbvision *) video_get_drvdata(dev);
985 int b=V4L2_BUF_TYPE_VIDEO_CAPTURE;
986
987 usbvision->streaming = Stream_On;
988 call_i2c_clients(usbvision,VIDIOC_STREAMON , &b);
989
990 return 0;
991}
992
993static int vidioc_streamoff(struct file *file,
994 void *priv, enum v4l2_buf_type type)
995{
996 struct video_device *dev = video_devdata(file);
997 struct usb_usbvision *usbvision =
998 (struct usb_usbvision *) video_get_drvdata(dev);
999 int b=V4L2_BUF_TYPE_VIDEO_CAPTURE;
1000
1001 if (type != V4L2_BUF_TYPE_VIDEO_CAPTURE)
1002 return -EINVAL;
1003
1004 if(usbvision->streaming == Stream_On) {
1005 usbvision_stream_interrupt(usbvision);
1006 /* Stop all video streamings */
1007 call_i2c_clients(usbvision,VIDIOC_STREAMOFF , &b);
1008 }
1009 usbvision_empty_framequeues(usbvision);
1010
1011 return 0;
1012}
1013
1014static int vidioc_enum_fmt_cap (struct file *file, void *priv,
1015 struct v4l2_fmtdesc *vfd)
1016{
1017 if(vfd->index>=USBVISION_SUPPORTED_PALETTES-1) {
1018 return -EINVAL;
1019 }
1020 vfd->flags = 0;
1021 vfd->type = V4L2_BUF_TYPE_VIDEO_CAPTURE;
1022 strcpy(vfd->description,usbvision_v4l2_format[vfd->index].desc);
1023 vfd->pixelformat = usbvision_v4l2_format[vfd->index].format;
1024 memset(vfd->reserved, 0, sizeof(vfd->reserved));
1025 return 0;
1026}
1027
1028static int vidioc_g_fmt_cap (struct file *file, void *priv,
1029 struct v4l2_format *vf)
1030{
1031 struct video_device *dev = video_devdata(file);
1032 struct usb_usbvision *usbvision =
1033 (struct usb_usbvision *) video_get_drvdata(dev);
1034 vf->fmt.pix.width = usbvision->curwidth;
1035 vf->fmt.pix.height = usbvision->curheight;
1036 vf->fmt.pix.pixelformat = usbvision->palette.format;
1037 vf->fmt.pix.bytesperline =
1038 usbvision->curwidth*usbvision->palette.bytes_per_pixel;
1039 vf->fmt.pix.sizeimage = vf->fmt.pix.bytesperline*usbvision->curheight;
1040 vf->fmt.pix.colorspace = V4L2_COLORSPACE_SMPTE170M;
1041 vf->fmt.pix.field = V4L2_FIELD_NONE; /* Always progressive image */
1042
1043 return 0;
1044}
1045
1046static int vidioc_try_fmt_cap (struct file *file, void *priv,
1047 struct v4l2_format *vf)
1048{
1049 struct video_device *dev = video_devdata(file);
1050 struct usb_usbvision *usbvision =
1051 (struct usb_usbvision *) video_get_drvdata(dev);
1052 int formatIdx;
1053
1054 /* Find requested format in available ones */
1055 for(formatIdx=0;formatIdx<USBVISION_SUPPORTED_PALETTES;formatIdx++) {
1056 if(vf->fmt.pix.pixelformat ==
1057 usbvision_v4l2_format[formatIdx].format) {
1058 usbvision->palette = usbvision_v4l2_format[formatIdx];
1059 break;
1060 }
1061 }
1062 /* robustness */
1063 if(formatIdx == USBVISION_SUPPORTED_PALETTES) {
1064 return -EINVAL;
1065 }
1066 RESTRICT_TO_RANGE(vf->fmt.pix.width, MIN_FRAME_WIDTH, MAX_FRAME_WIDTH);
1067 RESTRICT_TO_RANGE(vf->fmt.pix.height, MIN_FRAME_HEIGHT, MAX_FRAME_HEIGHT);
1068
1069 vf->fmt.pix.bytesperline = vf->fmt.pix.width*
1070 usbvision->palette.bytes_per_pixel;
1071 vf->fmt.pix.sizeimage = vf->fmt.pix.bytesperline*vf->fmt.pix.height;
1072
1073 return 0;
1074}
1075
1076static int vidioc_s_fmt_cap(struct file *file, void *priv,
1077 struct v4l2_format *vf)
1078{
1079 struct video_device *dev = video_devdata(file);
1080 struct usb_usbvision *usbvision =
1081 (struct usb_usbvision *) video_get_drvdata(dev);
1082 int ret;
1083
1084 if( 0 != (ret=vidioc_try_fmt_cap (file, priv, vf)) ) {
1085 return ret;
1086 }
1087
1088 /* stop io in case it is already in progress */
1089 if(usbvision->streaming == Stream_On) {
1090 if ((ret = usbvision_stream_interrupt(usbvision)))
1091 return ret;
1092 }
1093 usbvision_frames_free(usbvision);
1094 usbvision_empty_framequeues(usbvision);
1095
1096 usbvision->curFrame = NULL;
1097
1098 /* by now we are committed to the new data... */
1099 down(&usbvision->lock);
1100 usbvision_set_output(usbvision, vf->fmt.pix.width, vf->fmt.pix.height);
1101 up(&usbvision->lock);
1102
1103 return 0;
1104}
1073 1105
1074static ssize_t usbvision_v4l2_read(struct file *file, char __user *buf, 1106static ssize_t usbvision_v4l2_read(struct file *file, char __user *buf,
1075 size_t count, loff_t *ppos) 1107 size_t count, loff_t *ppos)
1076{ 1108{
1077 struct video_device *dev = video_devdata(file); 1109 struct video_device *dev = video_devdata(file);
1078 struct usb_usbvision *usbvision = (struct usb_usbvision *) video_get_drvdata(dev); 1110 struct usb_usbvision *usbvision =
1111 (struct usb_usbvision *) video_get_drvdata(dev);
1079 int noblock = file->f_flags & O_NONBLOCK; 1112 int noblock = file->f_flags & O_NONBLOCK;
1080 unsigned long lock_flags; 1113 unsigned long lock_flags;
1081 1114
1082 int ret,i; 1115 int ret,i;
1083 struct usbvision_frame *frame; 1116 struct usbvision_frame *frame;
1084 1117
1085 PDEBUG(DBG_IO, "%s: %ld bytes, noblock=%d", __FUNCTION__, (unsigned long)count, noblock); 1118 PDEBUG(DBG_IO, "%s: %ld bytes, noblock=%d", __FUNCTION__,
1119 (unsigned long)count, noblock);
1086 1120
1087 if (!USBVISION_IS_OPERATIONAL(usbvision) || (buf == NULL)) 1121 if (!USBVISION_IS_OPERATIONAL(usbvision) || (buf == NULL))
1088 return -EFAULT; 1122 return -EFAULT;
1089 1123
1090 /* This entry point is compatible with the mmap routines so that a user can do either 1124 /* This entry point is compatible with the mmap routines
1091 VIDIOC_QBUF/VIDIOC_DQBUF to get frames or call read on the device. */ 1125 so that a user can do either VIDIOC_QBUF/VIDIOC_DQBUF
1126 to get frames or call read on the device. */
1092 if(!usbvision->num_frames) { 1127 if(!usbvision->num_frames) {
1093 /* First, allocate some frames to work with if this has not been done with 1128 /* First, allocate some frames to work with
1094 VIDIOC_REQBUF */ 1129 if this has not been done with VIDIOC_REQBUF */
1095 usbvision_frames_free(usbvision); 1130 usbvision_frames_free(usbvision);
1096 usbvision_empty_framequeues(usbvision); 1131 usbvision_empty_framequeues(usbvision);
1097 usbvision_frames_alloc(usbvision,USBVISION_NUMFRAMES); 1132 usbvision_frames_alloc(usbvision,USBVISION_NUMFRAMES);
@@ -1103,21 +1138,24 @@ static ssize_t usbvision_v4l2_read(struct file *file, char __user *buf,
1103 call_i2c_clients(usbvision,VIDIOC_STREAMON , NULL); 1138 call_i2c_clients(usbvision,VIDIOC_STREAMON , NULL);
1104 } 1139 }
1105 1140
1106 /* Then, enqueue as many frames as possible (like a user of VIDIOC_QBUF would do) */ 1141 /* Then, enqueue as many frames as possible
1142 (like a user of VIDIOC_QBUF would do) */
1107 for(i=0;i<usbvision->num_frames;i++) { 1143 for(i=0;i<usbvision->num_frames;i++) {
1108 frame = &usbvision->frame[i]; 1144 frame = &usbvision->frame[i];
1109 if(frame->grabstate == FrameState_Unused) { 1145 if(frame->grabstate == FrameState_Unused) {
1110 /* Mark it as ready and enqueue frame */ 1146 /* Mark it as ready and enqueue frame */
1111 frame->grabstate = FrameState_Ready; 1147 frame->grabstate = FrameState_Ready;
1112 frame->scanstate = ScanState_Scanning; 1148 frame->scanstate = ScanState_Scanning;
1113 frame->scanlength = 0; /* Accumulated in usbvision_parse_data() */ 1149 /* Accumulated in usbvision_parse_data() */
1150 frame->scanlength = 0;
1114 1151
1115 /* set v4l2_format index */ 1152 /* set v4l2_format index */
1116 frame->v4l2_format = usbvision->palette; 1153 frame->v4l2_format = usbvision->palette;
1117 1154
1118 spin_lock_irqsave(&usbvision->queue_lock, lock_flags); 1155 spin_lock_irqsave(&usbvision->queue_lock, lock_flags);
1119 list_add_tail(&frame->frame, &usbvision->inqueue); 1156 list_add_tail(&frame->frame, &usbvision->inqueue);
1120 spin_unlock_irqrestore(&usbvision->queue_lock, lock_flags); 1157 spin_unlock_irqrestore(&usbvision->queue_lock,
1158 lock_flags);
1121 } 1159 }
1122 } 1160 }
1123 1161
@@ -1145,8 +1183,9 @@ static ssize_t usbvision_v4l2_read(struct file *file, char __user *buf,
1145 return 0; 1183 return 0;
1146 } 1184 }
1147 1185
1148 PDEBUG(DBG_IO, "%s: frmx=%d, bytes_read=%ld, scanlength=%ld", __FUNCTION__, 1186 PDEBUG(DBG_IO, "%s: frmx=%d, bytes_read=%ld, scanlength=%ld",
1149 frame->index, frame->bytes_read, frame->scanlength); 1187 __FUNCTION__,
1188 frame->index, frame->bytes_read, frame->scanlength);
1150 1189
1151 /* copy bytes to user space; we allow for partials reads */ 1190 /* copy bytes to user space; we allow for partials reads */
1152 if ((count + frame->bytes_read) > (unsigned long)frame->scanlength) 1191 if ((count + frame->bytes_read) > (unsigned long)frame->scanlength)
@@ -1157,10 +1196,11 @@ static ssize_t usbvision_v4l2_read(struct file *file, char __user *buf,
1157 } 1196 }
1158 1197
1159 frame->bytes_read += count; 1198 frame->bytes_read += count;
1160 PDEBUG(DBG_IO, "%s: {copy} count used=%ld, new bytes_read=%ld", __FUNCTION__, 1199 PDEBUG(DBG_IO, "%s: {copy} count used=%ld, new bytes_read=%ld",
1161 (unsigned long)count, frame->bytes_read); 1200 __FUNCTION__,
1201 (unsigned long)count, frame->bytes_read);
1162 1202
1163 // For now, forget the frame if it has not been read in one shot. 1203 /* For now, forget the frame if it has not been read in one shot. */
1164/* if (frame->bytes_read >= frame->scanlength) {// All data has been read */ 1204/* if (frame->bytes_read >= frame->scanlength) {// All data has been read */
1165 frame->bytes_read = 0; 1205 frame->bytes_read = 0;
1166 1206
@@ -1179,7 +1219,8 @@ static int usbvision_v4l2_mmap(struct file *file, struct vm_area_struct *vma)
1179 u32 i; 1219 u32 i;
1180 1220
1181 struct video_device *dev = video_devdata(file); 1221 struct video_device *dev = video_devdata(file);
1182 struct usb_usbvision *usbvision = (struct usb_usbvision *) video_get_drvdata(dev); 1222 struct usb_usbvision *usbvision =
1223 (struct usb_usbvision *) video_get_drvdata(dev);
1183 1224
1184 PDEBUG(DBG_MMAP, "mmap"); 1225 PDEBUG(DBG_MMAP, "mmap");
1185 1226
@@ -1197,11 +1238,13 @@ static int usbvision_v4l2_mmap(struct file *file, struct vm_area_struct *vma)
1197 } 1238 }
1198 1239
1199 for (i = 0; i < usbvision->num_frames; i++) { 1240 for (i = 0; i < usbvision->num_frames; i++) {
1200 if (((PAGE_ALIGN(usbvision->max_frame_size)*i) >> PAGE_SHIFT) == vma->vm_pgoff) 1241 if (((PAGE_ALIGN(usbvision->max_frame_size)*i) >> PAGE_SHIFT) ==
1242 vma->vm_pgoff)
1201 break; 1243 break;
1202 } 1244 }
1203 if (i == usbvision->num_frames) { 1245 if (i == usbvision->num_frames) {
1204 PDEBUG(DBG_MMAP, "mmap: user supplied mapping address is out of range"); 1246 PDEBUG(DBG_MMAP,
1247 "mmap: user supplied mapping address is out of range");
1205 up(&usbvision->lock); 1248 up(&usbvision->lock);
1206 return -EINVAL; 1249 return -EINVAL;
1207 } 1250 }
@@ -1235,7 +1278,8 @@ static int usbvision_v4l2_mmap(struct file *file, struct vm_area_struct *vma)
1235static int usbvision_radio_open(struct inode *inode, struct file *file) 1278static int usbvision_radio_open(struct inode *inode, struct file *file)
1236{ 1279{
1237 struct video_device *dev = video_devdata(file); 1280 struct video_device *dev = video_devdata(file);
1238 struct usb_usbvision *usbvision = (struct usb_usbvision *) video_get_drvdata(dev); 1281 struct usb_usbvision *usbvision =
1282 (struct usb_usbvision *) video_get_drvdata(dev);
1239 int errCode = 0; 1283 int errCode = 0;
1240 1284
1241 PDEBUG(DBG_IO, "%s:", __FUNCTION__); 1285 PDEBUG(DBG_IO, "%s:", __FUNCTION__);
@@ -1284,7 +1328,8 @@ static int usbvision_radio_open(struct inode *inode, struct file *file)
1284static int usbvision_radio_close(struct inode *inode, struct file *file) 1328static int usbvision_radio_close(struct inode *inode, struct file *file)
1285{ 1329{
1286 struct video_device *dev = video_devdata(file); 1330 struct video_device *dev = video_devdata(file);
1287 struct usb_usbvision *usbvision = (struct usb_usbvision *) video_get_drvdata(dev); 1331 struct usb_usbvision *usbvision =
1332 (struct usb_usbvision *) video_get_drvdata(dev);
1288 int errCode = 0; 1333 int errCode = 0;
1289 1334
1290 PDEBUG(DBG_IO, ""); 1335 PDEBUG(DBG_IO, "");
@@ -1318,13 +1363,6 @@ static int usbvision_radio_close(struct inode *inode, struct file *file)
1318 return errCode; 1363 return errCode;
1319} 1364}
1320 1365
1321static int usbvision_radio_ioctl(struct inode *inode, struct file *file,
1322 unsigned int cmd, unsigned long arg)
1323{
1324 return video_usercopy(inode, file, cmd, arg, usbvision_v4l2_do_ioctl);
1325}
1326
1327
1328/* 1366/*
1329 * Here comes the stuff for vbi on usbvision based devices 1367 * Here comes the stuff for vbi on usbvision based devices
1330 * 1368 *
@@ -1332,21 +1370,21 @@ static int usbvision_radio_ioctl(struct inode *inode, struct file *file,
1332static int usbvision_vbi_open(struct inode *inode, struct file *file) 1370static int usbvision_vbi_open(struct inode *inode, struct file *file)
1333{ 1371{
1334 /* TODO */ 1372 /* TODO */
1335 return -EINVAL; 1373 return -ENODEV;
1336 1374
1337} 1375}
1338 1376
1339static int usbvision_vbi_close(struct inode *inode, struct file *file) 1377static int usbvision_vbi_close(struct inode *inode, struct file *file)
1340{ 1378{
1341 /* TODO */ 1379 /* TODO */
1342 return -EINVAL; 1380 return -ENODEV;
1343} 1381}
1344 1382
1345static int usbvision_do_vbi_ioctl(struct inode *inode, struct file *file, 1383static int usbvision_do_vbi_ioctl(struct inode *inode, struct file *file,
1346 unsigned int cmd, void *arg) 1384 unsigned int cmd, void *arg)
1347{ 1385{
1348 /* TODO */ 1386 /* TODO */
1349 return -EINVAL; 1387 return -ENOIOCTLCMD;
1350} 1388}
1351 1389
1352static int usbvision_vbi_ioctl(struct inode *inode, struct file *file, 1390static int usbvision_vbi_ioctl(struct inode *inode, struct file *file,
@@ -1367,8 +1405,11 @@ static const struct file_operations usbvision_fops = {
1367 .release = usbvision_v4l2_close, 1405 .release = usbvision_v4l2_close,
1368 .read = usbvision_v4l2_read, 1406 .read = usbvision_v4l2_read,
1369 .mmap = usbvision_v4l2_mmap, 1407 .mmap = usbvision_v4l2_mmap,
1370 .ioctl = usbvision_v4l2_ioctl, 1408 .ioctl = video_ioctl2,
1371 .llseek = no_llseek, 1409 .llseek = no_llseek,
1410/* .poll = video_poll, */
1411 .mmap = usbvision_v4l2_mmap,
1412 .compat_ioctl = v4l_compat_ioctl32,
1372}; 1413};
1373static struct video_device usbvision_video_template = { 1414static struct video_device usbvision_video_template = {
1374 .owner = THIS_MODULE, 1415 .owner = THIS_MODULE,
@@ -1378,6 +1419,39 @@ static struct video_device usbvision_video_template = {
1378 .name = "usbvision-video", 1419 .name = "usbvision-video",
1379 .release = video_device_release, 1420 .release = video_device_release,
1380 .minor = -1, 1421 .minor = -1,
1422 .vidioc_querycap = vidioc_querycap,
1423 .vidioc_enum_fmt_cap = vidioc_enum_fmt_cap,
1424 .vidioc_g_fmt_cap = vidioc_g_fmt_cap,
1425 .vidioc_try_fmt_cap = vidioc_try_fmt_cap,
1426 .vidioc_s_fmt_cap = vidioc_s_fmt_cap,
1427 .vidioc_reqbufs = vidioc_reqbufs,
1428 .vidioc_querybuf = vidioc_querybuf,
1429 .vidioc_qbuf = vidioc_qbuf,
1430 .vidioc_dqbuf = vidioc_dqbuf,
1431 .vidioc_s_std = vidioc_s_std,
1432 .vidioc_enum_input = vidioc_enum_input,
1433 .vidioc_g_input = vidioc_g_input,
1434 .vidioc_s_input = vidioc_s_input,
1435 .vidioc_queryctrl = vidioc_queryctrl,
1436 .vidioc_g_audio = vidioc_g_audio,
1437 .vidioc_g_audio = vidioc_s_audio,
1438 .vidioc_g_ctrl = vidioc_g_ctrl,
1439 .vidioc_s_ctrl = vidioc_s_ctrl,
1440 .vidioc_streamon = vidioc_streamon,
1441 .vidioc_streamoff = vidioc_streamoff,
1442#ifdef CONFIG_VIDEO_V4L1_COMPAT
1443/* .vidiocgmbuf = vidiocgmbuf, */
1444#endif
1445 .vidioc_g_tuner = vidioc_g_tuner,
1446 .vidioc_s_tuner = vidioc_s_tuner,
1447 .vidioc_g_frequency = vidioc_g_frequency,
1448 .vidioc_s_frequency = vidioc_s_frequency,
1449#ifdef CONFIG_VIDEO_ADV_DEBUG
1450 .vidioc_g_register = vidioc_g_register,
1451 .vidioc_s_register = vidioc_s_register,
1452#endif
1453 .tvnorms = USBVISION_NORMS,
1454 .current_norm = V4L2_STD_PAL
1381}; 1455};
1382 1456
1383 1457
@@ -1386,8 +1460,9 @@ static const struct file_operations usbvision_radio_fops = {
1386 .owner = THIS_MODULE, 1460 .owner = THIS_MODULE,
1387 .open = usbvision_radio_open, 1461 .open = usbvision_radio_open,
1388 .release = usbvision_radio_close, 1462 .release = usbvision_radio_close,
1389 .ioctl = usbvision_radio_ioctl, 1463 .ioctl = video_ioctl2,
1390 .llseek = no_llseek, 1464 .llseek = no_llseek,
1465 .compat_ioctl = v4l_compat_ioctl32,
1391}; 1466};
1392 1467
1393static struct video_device usbvision_radio_template= 1468static struct video_device usbvision_radio_template=
@@ -1396,12 +1471,27 @@ static struct video_device usbvision_radio_template=
1396 .type = VID_TYPE_TUNER, 1471 .type = VID_TYPE_TUNER,
1397 .hardware = VID_HARDWARE_USBVISION, 1472 .hardware = VID_HARDWARE_USBVISION,
1398 .fops = &usbvision_radio_fops, 1473 .fops = &usbvision_radio_fops,
1399 .release = video_device_release,
1400 .name = "usbvision-radio", 1474 .name = "usbvision-radio",
1475 .release = video_device_release,
1401 .minor = -1, 1476 .minor = -1,
1477 .vidioc_querycap = vidioc_querycap,
1478 .vidioc_enum_input = vidioc_enum_input,
1479 .vidioc_g_input = vidioc_g_input,
1480 .vidioc_s_input = vidioc_s_input,
1481 .vidioc_queryctrl = vidioc_queryctrl,
1482 .vidioc_g_audio = vidioc_g_audio,
1483 .vidioc_g_audio = vidioc_s_audio,
1484 .vidioc_g_ctrl = vidioc_g_ctrl,
1485 .vidioc_s_ctrl = vidioc_s_ctrl,
1486 .vidioc_g_tuner = vidioc_g_tuner,
1487 .vidioc_s_tuner = vidioc_s_tuner,
1488 .vidioc_g_frequency = vidioc_g_frequency,
1489 .vidioc_s_frequency = vidioc_s_frequency,
1490
1491 .tvnorms = USBVISION_NORMS,
1492 .current_norm = V4L2_STD_PAL
1402}; 1493};
1403 1494
1404
1405// vbi template 1495// vbi template
1406static const struct file_operations usbvision_vbi_fops = { 1496static const struct file_operations usbvision_vbi_fops = {
1407 .owner = THIS_MODULE, 1497 .owner = THIS_MODULE,
@@ -1409,6 +1499,7 @@ static const struct file_operations usbvision_vbi_fops = {
1409 .release = usbvision_vbi_close, 1499 .release = usbvision_vbi_close,
1410 .ioctl = usbvision_vbi_ioctl, 1500 .ioctl = usbvision_vbi_ioctl,
1411 .llseek = no_llseek, 1501 .llseek = no_llseek,
1502 .compat_ioctl = v4l_compat_ioctl32,
1412}; 1503};
1413 1504
1414static struct video_device usbvision_vbi_template= 1505static struct video_device usbvision_vbi_template=
@@ -1452,11 +1543,11 @@ static void usbvision_unregister_video(struct usb_usbvision *usbvision)
1452{ 1543{
1453 // vbi Device: 1544 // vbi Device:
1454 if (usbvision->vbi) { 1545 if (usbvision->vbi) {
1455 PDEBUG(DBG_PROBE, "unregister /dev/vbi%d [v4l2]", usbvision->vbi->minor & 0x1f); 1546 PDEBUG(DBG_PROBE, "unregister /dev/vbi%d [v4l2]",
1547 usbvision->vbi->minor & 0x1f);
1456 if (usbvision->vbi->minor != -1) { 1548 if (usbvision->vbi->minor != -1) {
1457 video_unregister_device(usbvision->vbi); 1549 video_unregister_device(usbvision->vbi);
1458 } 1550 } else {
1459 else {
1460 video_device_release(usbvision->vbi); 1551 video_device_release(usbvision->vbi);
1461 } 1552 }
1462 usbvision->vbi = NULL; 1553 usbvision->vbi = NULL;
@@ -1464,11 +1555,11 @@ static void usbvision_unregister_video(struct usb_usbvision *usbvision)
1464 1555
1465 // Radio Device: 1556 // Radio Device:
1466 if (usbvision->rdev) { 1557 if (usbvision->rdev) {
1467 PDEBUG(DBG_PROBE, "unregister /dev/radio%d [v4l2]", usbvision->rdev->minor & 0x1f); 1558 PDEBUG(DBG_PROBE, "unregister /dev/radio%d [v4l2]",
1559 usbvision->rdev->minor & 0x1f);
1468 if (usbvision->rdev->minor != -1) { 1560 if (usbvision->rdev->minor != -1) {
1469 video_unregister_device(usbvision->rdev); 1561 video_unregister_device(usbvision->rdev);
1470 } 1562 } else {
1471 else {
1472 video_device_release(usbvision->rdev); 1563 video_device_release(usbvision->rdev);
1473 } 1564 }
1474 usbvision->rdev = NULL; 1565 usbvision->rdev = NULL;
@@ -1476,11 +1567,11 @@ static void usbvision_unregister_video(struct usb_usbvision *usbvision)
1476 1567
1477 // Video Device: 1568 // Video Device:
1478 if (usbvision->vdev) { 1569 if (usbvision->vdev) {
1479 PDEBUG(DBG_PROBE, "unregister /dev/video%d [v4l2]", usbvision->vdev->minor & 0x1f); 1570 PDEBUG(DBG_PROBE, "unregister /dev/video%d [v4l2]",
1571 usbvision->vdev->minor & 0x1f);
1480 if (usbvision->vdev->minor != -1) { 1572 if (usbvision->vdev->minor != -1) {
1481 video_unregister_device(usbvision->vdev); 1573 video_unregister_device(usbvision->vdev);
1482 } 1574 } else {
1483 else {
1484 video_device_release(usbvision->vdev); 1575 video_device_release(usbvision->vdev);
1485 } 1576 }
1486 usbvision->vdev = NULL; 1577 usbvision->vdev = NULL;
@@ -1491,37 +1582,52 @@ static void usbvision_unregister_video(struct usb_usbvision *usbvision)
1491static int __devinit usbvision_register_video(struct usb_usbvision *usbvision) 1582static int __devinit usbvision_register_video(struct usb_usbvision *usbvision)
1492{ 1583{
1493 // Video Device: 1584 // Video Device:
1494 usbvision->vdev = usbvision_vdev_init(usbvision, &usbvision_video_template, "USBVision Video"); 1585 usbvision->vdev = usbvision_vdev_init(usbvision,
1586 &usbvision_video_template,
1587 "USBVision Video");
1495 if (usbvision->vdev == NULL) { 1588 if (usbvision->vdev == NULL) {
1496 goto err_exit; 1589 goto err_exit;
1497 } 1590 }
1498 if (video_register_device(usbvision->vdev, VFL_TYPE_GRABBER, video_nr)<0) { 1591 if (video_register_device(usbvision->vdev,
1592 VFL_TYPE_GRABBER,
1593 video_nr)<0) {
1499 goto err_exit; 1594 goto err_exit;
1500 } 1595 }
1501 printk(KERN_INFO "USBVision[%d]: registered USBVision Video device /dev/video%d [v4l2]\n", usbvision->nr,usbvision->vdev->minor & 0x1f); 1596 printk(KERN_INFO "USBVision[%d]: registered USBVision Video device /dev/video%d [v4l2]\n",
1597 usbvision->nr,usbvision->vdev->minor & 0x1f);
1502 1598
1503 // Radio Device: 1599 // Radio Device:
1504 if (usbvision_device_data[usbvision->DevModel].Radio) { 1600 if (usbvision_device_data[usbvision->DevModel].Radio) {
1505 // usbvision has radio 1601 // usbvision has radio
1506 usbvision->rdev = usbvision_vdev_init(usbvision, &usbvision_radio_template, "USBVision Radio"); 1602 usbvision->rdev = usbvision_vdev_init(usbvision,
1603 &usbvision_radio_template,
1604 "USBVision Radio");
1507 if (usbvision->rdev == NULL) { 1605 if (usbvision->rdev == NULL) {
1508 goto err_exit; 1606 goto err_exit;
1509 } 1607 }
1510 if (video_register_device(usbvision->rdev, VFL_TYPE_RADIO, radio_nr)<0) { 1608 if (video_register_device(usbvision->rdev,
1609 VFL_TYPE_RADIO,
1610 radio_nr)<0) {
1511 goto err_exit; 1611 goto err_exit;
1512 } 1612 }
1513 printk(KERN_INFO "USBVision[%d]: registered USBVision Radio device /dev/radio%d [v4l2]\n", usbvision->nr, usbvision->rdev->minor & 0x1f); 1613 printk(KERN_INFO "USBVision[%d]: registered USBVision Radio device /dev/radio%d [v4l2]\n",
1614 usbvision->nr, usbvision->rdev->minor & 0x1f);
1514 } 1615 }
1515 // vbi Device: 1616 // vbi Device:
1516 if (usbvision_device_data[usbvision->DevModel].vbi) { 1617 if (usbvision_device_data[usbvision->DevModel].vbi) {
1517 usbvision->vbi = usbvision_vdev_init(usbvision, &usbvision_vbi_template, "USBVision VBI"); 1618 usbvision->vbi = usbvision_vdev_init(usbvision,
1619 &usbvision_vbi_template,
1620 "USBVision VBI");
1518 if (usbvision->vdev == NULL) { 1621 if (usbvision->vdev == NULL) {
1519 goto err_exit; 1622 goto err_exit;
1520 } 1623 }
1521 if (video_register_device(usbvision->vbi, VFL_TYPE_VBI, vbi_nr)<0) { 1624 if (video_register_device(usbvision->vbi,
1625 VFL_TYPE_VBI,
1626 vbi_nr)<0) {
1522 goto err_exit; 1627 goto err_exit;
1523 } 1628 }
1524 printk(KERN_INFO "USBVision[%d]: registered USBVision VBI device /dev/vbi%d [v4l2] (Not Working Yet!)\n", usbvision->nr,usbvision->vbi->minor & 0x1f); 1629 printk(KERN_INFO "USBVision[%d]: registered USBVision VBI device /dev/vbi%d [v4l2] (Not Working Yet!)\n",
1630 usbvision->nr,usbvision->vbi->minor & 0x1f);
1525 } 1631 }
1526 // all done 1632 // all done
1527 return 0; 1633 return 0;
@@ -1535,7 +1641,8 @@ static int __devinit usbvision_register_video(struct usb_usbvision *usbvision)
1535/* 1641/*
1536 * usbvision_alloc() 1642 * usbvision_alloc()
1537 * 1643 *
1538 * This code allocates the struct usb_usbvision. It is filled with default values. 1644 * This code allocates the struct usb_usbvision.
1645 * It is filled with default values.
1539 * 1646 *
1540 * Returns NULL on error, a pointer to usb_usbvision else. 1647 * Returns NULL on error, a pointer to usb_usbvision else.
1541 * 1648 *
@@ -1544,7 +1651,8 @@ static struct usb_usbvision *usbvision_alloc(struct usb_device *dev)
1544{ 1651{
1545 struct usb_usbvision *usbvision; 1652 struct usb_usbvision *usbvision;
1546 1653
1547 if ((usbvision = kzalloc(sizeof(struct usb_usbvision), GFP_KERNEL)) == NULL) { 1654 if ((usbvision = kzalloc(sizeof(struct usb_usbvision), GFP_KERNEL)) ==
1655 NULL) {
1548 goto err_exit; 1656 goto err_exit;
1549 } 1657 }
1550 1658
@@ -1606,11 +1714,11 @@ static void usbvision_release(struct usb_usbvision *usbvision)
1606} 1714}
1607 1715
1608 1716
1609/******************************** usb interface *****************************************/ 1717/*********************** usb interface **********************************/
1610 1718
1611static void usbvision_configure_video(struct usb_usbvision *usbvision) 1719static void usbvision_configure_video(struct usb_usbvision *usbvision)
1612{ 1720{
1613 int model,i; 1721 int model;
1614 1722
1615 if (usbvision == NULL) 1723 if (usbvision == NULL)
1616 return; 1724 return;
@@ -1619,25 +1727,23 @@ static void usbvision_configure_video(struct usb_usbvision *usbvision)
1619 usbvision->palette = usbvision_v4l2_format[2]; // V4L2_PIX_FMT_RGB24; 1727 usbvision->palette = usbvision_v4l2_format[2]; // V4L2_PIX_FMT_RGB24;
1620 1728
1621 if (usbvision_device_data[usbvision->DevModel].Vin_Reg2_override) { 1729 if (usbvision_device_data[usbvision->DevModel].Vin_Reg2_override) {
1622 usbvision->Vin_Reg2_Preset = usbvision_device_data[usbvision->DevModel].Vin_Reg2; 1730 usbvision->Vin_Reg2_Preset =
1731 usbvision_device_data[usbvision->DevModel].Vin_Reg2;
1623 } else { 1732 } else {
1624 usbvision->Vin_Reg2_Preset = 0; 1733 usbvision->Vin_Reg2_Preset = 0;
1625 } 1734 }
1626 1735
1627 for (i = 0; i < TVNORMS; i++) 1736 usbvision->tvnormId = usbvision_device_data[model].VideoNorm;
1628 if (usbvision_device_data[model].VideoNorm == tvnorms[i].mode)
1629 break;
1630 if (i == TVNORMS)
1631 i = 0;
1632 usbvision->tvnorm = &tvnorms[i]; /* set default norm */
1633 1737
1634 usbvision->video_inputs = usbvision_device_data[model].VideoChannels; 1738 usbvision->video_inputs = usbvision_device_data[model].VideoChannels;
1635 usbvision->ctl_input = 0; 1739 usbvision->ctl_input = 0;
1636 1740
1637 /* This should be here to make i2c clients to be able to register */ 1741 /* This should be here to make i2c clients to be able to register */
1638 usbvision_audio_off(usbvision); //first switch off audio 1742 /* first switch off audio */
1743 usbvision_audio_off(usbvision);
1639 if (!PowerOnAtOpen) { 1744 if (!PowerOnAtOpen) {
1640 usbvision_power_on(usbvision); //and then power up the noisy tuner 1745 /* and then power up the noisy tuner */
1746 usbvision_power_on(usbvision);
1641 usbvision_i2c_register(usbvision); 1747 usbvision_i2c_register(usbvision);
1642 } 1748 }
1643} 1749}
@@ -1674,18 +1780,22 @@ static int __devinit usbvision_probe(struct usb_interface *intf,
1674 1780
1675 if (usbvision_device_data[model].Interface >= 0) { 1781 if (usbvision_device_data[model].Interface >= 0) {
1676 interface = &dev->actconfig->interface[usbvision_device_data[model].Interface]->altsetting[0]; 1782 interface = &dev->actconfig->interface[usbvision_device_data[model].Interface]->altsetting[0];
1677 } 1783 } else {
1678 else {
1679 interface = &dev->actconfig->interface[ifnum]->altsetting[0]; 1784 interface = &dev->actconfig->interface[ifnum]->altsetting[0];
1680 } 1785 }
1681 endpoint = &interface->endpoint[1].desc; 1786 endpoint = &interface->endpoint[1].desc;
1682 if ((endpoint->bmAttributes & USB_ENDPOINT_XFERTYPE_MASK) != USB_ENDPOINT_XFER_ISOC) { 1787 if ((endpoint->bmAttributes & USB_ENDPOINT_XFERTYPE_MASK) !=
1683 err("%s: interface %d. has non-ISO endpoint!", __FUNCTION__, ifnum); 1788 USB_ENDPOINT_XFER_ISOC) {
1684 err("%s: Endpoint attributes %d", __FUNCTION__, endpoint->bmAttributes); 1789 err("%s: interface %d. has non-ISO endpoint!",
1790 __FUNCTION__, ifnum);
1791 err("%s: Endpoint attributes %d",
1792 __FUNCTION__, endpoint->bmAttributes);
1685 return -ENODEV; 1793 return -ENODEV;
1686 } 1794 }
1687 if ((endpoint->bEndpointAddress & USB_ENDPOINT_DIR_MASK) == USB_DIR_OUT) { 1795 if ((endpoint->bEndpointAddress & USB_ENDPOINT_DIR_MASK) ==
1688 err("%s: interface %d. has ISO OUT endpoint!", __FUNCTION__, ifnum); 1796 USB_DIR_OUT) {
1797 err("%s: interface %d. has ISO OUT endpoint!",
1798 __FUNCTION__, ifnum);
1689 return -ENODEV; 1799 return -ENODEV;
1690 } 1800 }
1691 1801
@@ -1696,11 +1806,9 @@ static int __devinit usbvision_probe(struct usb_interface *intf,
1696 1806
1697 if (dev->descriptor.bNumConfigurations > 1) { 1807 if (dev->descriptor.bNumConfigurations > 1) {
1698 usbvision->bridgeType = BRIDGE_NT1004; 1808 usbvision->bridgeType = BRIDGE_NT1004;
1699 } 1809 } else if (model == DAZZLE_DVC_90_REV_1_SECAM) {
1700 else if (model == DAZZLE_DVC_90_REV_1_SECAM) {
1701 usbvision->bridgeType = BRIDGE_NT1005; 1810 usbvision->bridgeType = BRIDGE_NT1005;
1702 } 1811 } else {
1703 else {
1704 usbvision->bridgeType = BRIDGE_NT1003; 1812 usbvision->bridgeType = BRIDGE_NT1003;
1705 } 1813 }
1706 PDEBUG(DBG_PROBE, "bridgeType %d", usbvision->bridgeType); 1814 PDEBUG(DBG_PROBE, "bridgeType %d", usbvision->bridgeType);
@@ -1797,11 +1905,11 @@ static void __devexit usbvision_disconnect(struct usb_interface *intf)
1797 up(&usbvision->lock); 1905 up(&usbvision->lock);
1798 1906
1799 if (usbvision->user) { 1907 if (usbvision->user) {
1800 printk(KERN_INFO "%s: In use, disconnect pending\n", __FUNCTION__); 1908 printk(KERN_INFO "%s: In use, disconnect pending\n",
1909 __FUNCTION__);
1801 wake_up_interruptible(&usbvision->wait_frame); 1910 wake_up_interruptible(&usbvision->wait_frame);
1802 wake_up_interruptible(&usbvision->wait_stream); 1911 wake_up_interruptible(&usbvision->wait_stream);
1803 } 1912 } else {
1804 else {
1805 usbvision_release(usbvision); 1913 usbvision_release(usbvision);
1806 } 1914 }
1807 1915
@@ -1828,7 +1936,6 @@ static int __init usbvision_init(void)
1828 1936
1829 PDEBUG(DBG_PROBE, ""); 1937 PDEBUG(DBG_PROBE, "");
1830 1938
1831 PDEBUG(DBG_IOCTL, "IOCTL debugging is enabled [video]");
1832 PDEBUG(DBG_IO, "IO debugging is enabled [video]"); 1939 PDEBUG(DBG_IO, "IO debugging is enabled [video]");
1833 PDEBUG(DBG_PROBE, "PROBE debugging is enabled [video]"); 1940 PDEBUG(DBG_PROBE, "PROBE debugging is enabled [video]");
1834 PDEBUG(DBG_MMAP, "MMAP debugging is enabled [video]"); 1941 PDEBUG(DBG_MMAP, "MMAP debugging is enabled [video]");