2 * USB USBVISION Video device driver 0.9.9
6 * Copyright (c) 1999-2005 Joerg Heckenbach <joerg@heckenbach-aw.de>
8 * This module is part of usbvision driver project.
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.
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.
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.
24 * Let's call the version 0.... until compression decoding is completely
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
36 * - use submit_urb for all setup packets
37 * - Fix memory settings for nt1004. It is 4 times as big as the
39 * - Add audio on endpoint 3 for nt1004 chip. Seems impossible, needs a codec interface. Which one?
40 * - Clean up the driver.
41 * - optimization for performance.
42 * - Add Videotext capability (VBI). Working on it.....
43 * - Check audio for other devices
47 #include <linux/version.h>
48 #include <linux/kernel.h>
49 #include <linux/list.h>
50 #include <linux/timer.h>
51 #include <linux/slab.h>
53 #include <linux/utsname.h>
54 #include <linux/highmem.h>
55 #include <linux/smp_lock.h>
56 #include <linux/videodev.h>
57 #include <linux/vmalloc.h>
58 #include <linux/module.h>
59 #include <linux/init.h>
60 #include <linux/spinlock.h>
62 #include <linux/videodev2.h>
63 #include <linux/video_decoder.h>
64 #include <linux/i2c.h>
66 #include <media/saa7115.h>
67 #include <media/v4l2-common.h>
68 #include <media/tuner.h>
69 #include <media/audiochip.h>
71 #include <linux/moduleparam.h>
72 #include <linux/workqueue.h>
75 #include <linux/kmod.h>
78 #include "usbvision.h"
79 #include "usbvision-cards.h"
81 #define DRIVER_AUTHOR "Joerg Heckenbach <joerg@heckenbach-aw.de>, Dwaine Garden <DwaineGarden@rogers.com>"
82 #define DRIVER_NAME "usbvision"
83 #define DRIVER_ALIAS "USBVision"
84 #define DRIVER_DESC "USBVision USB Video Device Driver for Linux"
85 #define DRIVER_LICENSE "GPL"
86 #define USBVISION_DRIVER_VERSION_MAJOR 0
87 #define USBVISION_DRIVER_VERSION_MINOR 9
88 #define USBVISION_DRIVER_VERSION_PATCHLEVEL 9
89 #define USBVISION_DRIVER_VERSION KERNEL_VERSION(USBVISION_DRIVER_VERSION_MAJOR,USBVISION_DRIVER_VERSION_MINOR,USBVISION_DRIVER_VERSION_PATCHLEVEL)
90 #define USBVISION_VERSION_STRING __stringify(USBVISION_DRIVER_VERSION_MAJOR) "." __stringify(USBVISION_DRIVER_VERSION_MINOR) "." __stringify(USBVISION_DRIVER_VERSION_PATCHLEVEL)
92 #define ENABLE_HEXDUMP 0 /* Enable if you need it */
95 #ifdef USBVISION_DEBUG
96 #define PDEBUG(level, fmt, args...) \
97 if (video_debug & (level)) info("[%s:%d] " fmt, __PRETTY_FUNCTION__, __LINE__ , ## args)
99 #define PDEBUG(level, fmt, args...) do {} while(0)
102 #define DBG_IOCTL 1<<0
104 #define DBG_PROBE 1<<2
105 #define DBG_MMAP 1<<3
108 #define rmspace(str) while(*str==' ') str++;
109 #define goto2next(str) while(*str!=' ') str++; while(*str==' ') str++;
112 static int usbvision_nr
= 0; // sequential number of usbvision device
114 static struct usbvision_v4l2_format_st usbvision_v4l2_format
[] = {
115 { 1, 1, 8, V4L2_PIX_FMT_GREY
, "GREY" },
116 { 1, 2, 16, V4L2_PIX_FMT_RGB565
, "RGB565" },
117 { 1, 3, 24, V4L2_PIX_FMT_RGB24
, "RGB24" },
118 { 1, 4, 32, V4L2_PIX_FMT_RGB32
, "RGB32" },
119 { 1, 2, 16, V4L2_PIX_FMT_RGB555
, "RGB555" },
120 { 1, 2, 16, V4L2_PIX_FMT_YUYV
, "YUV422" },
121 { 1, 2, 12, V4L2_PIX_FMT_YVU420
, "YUV420P" }, // 1.5 !
122 { 1, 2, 16, V4L2_PIX_FMT_YUV422P
, "YUV422P" }
125 /* supported tv norms */
126 static struct usbvision_tvnorm tvnorms
[] = {
135 .id
= V4L2_STD_SECAM
,
138 .id
= V4L2_STD_PAL_M
,
142 #define TVNORMS ARRAY_SIZE(tvnorms)
144 // Function prototypes
145 static void usbvision_release(struct usb_usbvision
*usbvision
);
147 // Default initalization of device driver parameters
148 static int isocMode
= ISOC_MODE_COMPRESS
; // Set the default format for ISOC endpoint
149 static int video_debug
= 0; // Set the default Debug Mode of the device driver
150 static int PowerOnAtOpen
= 1; // Set the default device to power on at startup
151 static int video_nr
= -1; // Sequential Number of Video Device
152 static int radio_nr
= -1; // Sequential Number of Radio Device
153 static int vbi_nr
= -1; // Sequential Number of VBI Device
154 static char *CustomDevice
=NULL
; // Set as nothing....
156 // Grab parameters for the device driver
158 #if defined(module_param) // Showing parameters under SYSFS
159 module_param(isocMode
, int, 0444);
160 module_param(video_debug
, int, 0444);
161 module_param(PowerOnAtOpen
, int, 0444);
162 module_param(video_nr
, int, 0444);
163 module_param(radio_nr
, int, 0444);
164 module_param(vbi_nr
, int, 0444);
165 module_param(CustomDevice
, charp
, 0444);
167 MODULE_PARAM(isocMode
, "i");
168 MODULE_PARM(video_debug
, "i"); // Grab the Debug Mode of the device driver
169 MODULE_PARM(adjustCompression
, "i"); // Grab the compression to be adaptive
170 MODULE_PARM(PowerOnAtOpen
, "i"); // Grab the device to power on at startup
171 MODULE_PARM(SwitchSVideoInput
, "i"); // To help people with Black and White output with using s-video input. Some cables and input device are wired differently.
172 MODULE_PARM(video_nr
, "i"); // video_nr option allows to specify a certain /dev/videoX device (like /dev/video0 or /dev/video1 ...)
173 MODULE_PARM(radio_nr
, "i"); // radio_nr option allows to specify a certain /dev/radioX device (like /dev/radio0 or /dev/radio1 ...)
174 MODULE_PARM(vbi_nr
, "i"); // vbi_nr option allows to specify a certain /dev/vbiX device (like /dev/vbi0 or /dev/vbi1 ...)
175 MODULE_PARM(CustomDevice
, "s"); // .... CustomDevice
178 MODULE_PARM_DESC(isocMode
, " Set the default format for ISOC endpoint. Default: 0x60 (Compression On)");
179 MODULE_PARM_DESC(video_debug
, " Set the default Debug Mode of the device driver. Default: 0 (Off)");
180 MODULE_PARM_DESC(PowerOnAtOpen
, " Set the default device to power on when device is opened. Default: 1 (On)");
181 MODULE_PARM_DESC(video_nr
, "Set video device number (/dev/videoX). Default: -1 (autodetect)");
182 MODULE_PARM_DESC(radio_nr
, "Set radio device number (/dev/radioX). Default: -1 (autodetect)");
183 MODULE_PARM_DESC(vbi_nr
, "Set vbi device number (/dev/vbiX). Default: -1 (autodetect)");
184 MODULE_PARM_DESC(CustomDevice
, " Define the fine tuning parameters for the device. Default: null");
188 MODULE_AUTHOR(DRIVER_AUTHOR
);
189 MODULE_DESCRIPTION(DRIVER_DESC
);
190 MODULE_LICENSE(DRIVER_LICENSE
);
191 MODULE_VERSION(USBVISION_VERSION_STRING
);
192 MODULE_ALIAS(DRIVER_ALIAS
);
195 /****************************************************************************************/
196 /* SYSFS Code - Copied from the stv680.c usb module. */
197 /* Device information is located at /sys/class/video4linux/video0 */
198 /* Device parameters information is located at /sys/module/usbvision */
199 /* Device USB Information is located at /sys/bus/usb/drivers/USBVision Video Grabber */
200 /****************************************************************************************/
203 #define YES_NO(x) ((x) ? "Yes" : "No")
205 static inline struct usb_usbvision
*cd_to_usbvision(struct class_device
*cd
)
207 struct video_device
*vdev
= container_of(cd
, struct video_device
, class_dev
);
208 return video_get_drvdata(vdev
);
211 static ssize_t
show_version(struct class_device
*cd
, char *buf
)
213 return sprintf(buf
, "%s\n", USBVISION_VERSION_STRING
);
215 static CLASS_DEVICE_ATTR(version
, S_IRUGO
, show_version
, NULL
);
217 static ssize_t
show_model(struct class_device
*cd
, char *buf
)
219 struct video_device
*vdev
= container_of(cd
, struct video_device
, class_dev
);
220 struct usb_usbvision
*usbvision
= video_get_drvdata(vdev
);
221 return sprintf(buf
, "%s\n", usbvision_device_data
[usbvision
->DevModel
].ModelString
);
223 static CLASS_DEVICE_ATTR(model
, S_IRUGO
, show_model
, NULL
);
225 static ssize_t
show_hue(struct class_device
*cd
, char *buf
)
227 struct video_device
*vdev
= container_of(cd
, struct video_device
, class_dev
);
228 struct usb_usbvision
*usbvision
= video_get_drvdata(vdev
);
229 struct v4l2_control ctrl
;
230 ctrl
.id
= V4L2_CID_HUE
;
233 call_i2c_clients(usbvision
, VIDIOC_G_CTRL
, &ctrl
);
234 return sprintf(buf
, "%d\n", ctrl
.value
);
236 static CLASS_DEVICE_ATTR(hue
, S_IRUGO
, show_hue
, NULL
);
238 static ssize_t
show_contrast(struct class_device
*cd
, char *buf
)
240 struct video_device
*vdev
= container_of(cd
, struct video_device
, class_dev
);
241 struct usb_usbvision
*usbvision
= video_get_drvdata(vdev
);
242 struct v4l2_control ctrl
;
243 ctrl
.id
= V4L2_CID_CONTRAST
;
246 call_i2c_clients(usbvision
, VIDIOC_G_CTRL
, &ctrl
);
247 return sprintf(buf
, "%d\n", ctrl
.value
);
249 static CLASS_DEVICE_ATTR(contrast
, S_IRUGO
, show_contrast
, NULL
);
251 static ssize_t
show_brightness(struct class_device
*cd
, char *buf
)
253 struct video_device
*vdev
= container_of(cd
, struct video_device
, class_dev
);
254 struct usb_usbvision
*usbvision
= video_get_drvdata(vdev
);
255 struct v4l2_control ctrl
;
256 ctrl
.id
= V4L2_CID_BRIGHTNESS
;
259 call_i2c_clients(usbvision
, VIDIOC_G_CTRL
, &ctrl
);
260 return sprintf(buf
, "%d\n", ctrl
.value
);
262 static CLASS_DEVICE_ATTR(brightness
, S_IRUGO
, show_brightness
, NULL
);
264 static ssize_t
show_saturation(struct class_device
*cd
, char *buf
)
266 struct video_device
*vdev
= container_of(cd
, struct video_device
, class_dev
);
267 struct usb_usbvision
*usbvision
= video_get_drvdata(vdev
);
268 struct v4l2_control ctrl
;
269 ctrl
.id
= V4L2_CID_SATURATION
;
272 call_i2c_clients(usbvision
, VIDIOC_G_CTRL
, &ctrl
);
273 return sprintf(buf
, "%d\n", ctrl
.value
);
275 static CLASS_DEVICE_ATTR(saturation
, S_IRUGO
, show_saturation
, NULL
);
277 static ssize_t
show_streaming(struct class_device
*cd
, char *buf
)
279 struct video_device
*vdev
= container_of(cd
, struct video_device
, class_dev
);
280 struct usb_usbvision
*usbvision
= video_get_drvdata(vdev
);
281 return sprintf(buf
, "%s\n", YES_NO(usbvision
->streaming
==Stream_On
?1:0));
283 static CLASS_DEVICE_ATTR(streaming
, S_IRUGO
, show_streaming
, NULL
);
285 static ssize_t
show_compression(struct class_device
*cd
, char *buf
)
287 struct video_device
*vdev
= container_of(cd
, struct video_device
, class_dev
);
288 struct usb_usbvision
*usbvision
= video_get_drvdata(vdev
);
289 return sprintf(buf
, "%s\n", YES_NO(usbvision
->isocMode
==ISOC_MODE_COMPRESS
));
291 static CLASS_DEVICE_ATTR(compression
, S_IRUGO
, show_compression
, NULL
);
293 static ssize_t
show_device_bridge(struct class_device
*cd
, char *buf
)
295 struct video_device
*vdev
= container_of(cd
, struct video_device
, class_dev
);
296 struct usb_usbvision
*usbvision
= video_get_drvdata(vdev
);
297 return sprintf(buf
, "%d\n", usbvision
->bridgeType
);
299 static CLASS_DEVICE_ATTR(bridge
, S_IRUGO
, show_device_bridge
, NULL
);
301 static void usbvision_create_sysfs(struct video_device
*vdev
)
307 res
=class_device_create_file(&vdev
->class_dev
,
308 &class_device_attr_version
);
311 res
=class_device_create_file(&vdev
->class_dev
,
312 &class_device_attr_model
);
315 res
=class_device_create_file(&vdev
->class_dev
,
316 &class_device_attr_hue
);
319 res
=class_device_create_file(&vdev
->class_dev
,
320 &class_device_attr_contrast
);
323 res
=class_device_create_file(&vdev
->class_dev
,
324 &class_device_attr_brightness
);
327 res
=class_device_create_file(&vdev
->class_dev
,
328 &class_device_attr_saturation
);
331 res
=class_device_create_file(&vdev
->class_dev
,
332 &class_device_attr_streaming
);
335 res
=class_device_create_file(&vdev
->class_dev
,
336 &class_device_attr_compression
);
339 res
=class_device_create_file(&vdev
->class_dev
,
340 &class_device_attr_bridge
);
345 err("%s error: %d\n", __FUNCTION__
, res
);
348 static void usbvision_remove_sysfs(struct video_device
*vdev
)
351 class_device_remove_file(&vdev
->class_dev
,
352 &class_device_attr_version
);
353 class_device_remove_file(&vdev
->class_dev
,
354 &class_device_attr_model
);
355 class_device_remove_file(&vdev
->class_dev
,
356 &class_device_attr_hue
);
357 class_device_remove_file(&vdev
->class_dev
,
358 &class_device_attr_contrast
);
359 class_device_remove_file(&vdev
->class_dev
,
360 &class_device_attr_brightness
);
361 class_device_remove_file(&vdev
->class_dev
,
362 &class_device_attr_saturation
);
363 class_device_remove_file(&vdev
->class_dev
,
364 &class_device_attr_streaming
);
365 class_device_remove_file(&vdev
->class_dev
,
366 &class_device_attr_compression
);
367 class_device_remove_file(&vdev
->class_dev
,
368 &class_device_attr_bridge
);
376 * This is part of Video 4 Linux API. The driver can be opened by one
377 * client only (checks internal counter 'usbvision->user'). The procedure
378 * then allocates buffers needed for video processing.
381 static int usbvision_v4l2_open(struct inode
*inode
, struct file
*file
)
383 struct video_device
*dev
= video_devdata(file
);
384 struct usb_usbvision
*usbvision
= (struct usb_usbvision
*) video_get_drvdata(dev
);
387 PDEBUG(DBG_IO
, "open");
390 usbvision_reset_powerOffTimer(usbvision
);
395 /* Allocate memory for the scratch ring buffer */
396 errCode
= usbvision_scratch_alloc(usbvision
);
397 if (isocMode
==ISOC_MODE_COMPRESS
) {
398 /* Allocate intermediate decompression buffers only if needed */
399 errCode
= usbvision_decompress_alloc(usbvision
);
402 /* Deallocate all buffers if trouble */
403 usbvision_scratch_free(usbvision
);
404 usbvision_decompress_free(usbvision
);
408 /* If so far no errors then we shall start the camera */
410 down(&usbvision
->lock
);
411 if (usbvision
->power
== 0) {
412 usbvision_power_on(usbvision
);
413 usbvision_init_i2c(usbvision
);
416 /* Send init sequence only once, it's large! */
417 if (!usbvision
->initialized
) {
419 setup_ok
= usbvision_setup(usbvision
,isocMode
);
421 usbvision
->initialized
= 1;
427 usbvision_begin_streaming(usbvision
);
428 errCode
= usbvision_init_isoc(usbvision
);
429 /* device needs to be initialized before isoc transfer */
430 usbvision_muxsel(usbvision
,0);
435 usbvision_i2c_usb_del_bus(&usbvision
->i2c_adap
);
436 usbvision_power_off(usbvision
);
437 usbvision
->initialized
= 0;
440 up(&usbvision
->lock
);
447 usbvision_empty_framequeues(usbvision
);
449 PDEBUG(DBG_IO
, "success");
454 * usbvision_v4l2_close()
456 * This is part of Video 4 Linux API. The procedure
457 * stops streaming and deallocates all buffers that were earlier
458 * allocated in usbvision_v4l2_open().
461 static int usbvision_v4l2_close(struct inode
*inode
, struct file
*file
)
463 struct video_device
*dev
= video_devdata(file
);
464 struct usb_usbvision
*usbvision
= (struct usb_usbvision
*) video_get_drvdata(dev
);
466 PDEBUG(DBG_IO
, "close");
467 down(&usbvision
->lock
);
469 usbvision_audio_off(usbvision
);
470 usbvision_restart_isoc(usbvision
);
471 usbvision_stop_isoc(usbvision
);
473 usbvision_decompress_free(usbvision
);
474 usbvision_frames_free(usbvision
);
475 usbvision_empty_framequeues(usbvision
);
476 usbvision_scratch_free(usbvision
);
481 /* power off in a little while to avoid off/on every close/open short sequences */
482 usbvision_set_powerOffTimer(usbvision
);
483 usbvision
->initialized
= 0;
486 up(&usbvision
->lock
);
488 if (usbvision
->remove_pending
) {
489 printk(KERN_INFO
"%s: Final disconnect\n", __FUNCTION__
);
490 usbvision_release(usbvision
);
493 PDEBUG(DBG_IO
, "success");
503 * This is part of Video 4 Linux API. The procedure handles ioctl() calls.
506 static int usbvision_v4l2_do_ioctl(struct inode
*inode
, struct file
*file
,
507 unsigned int cmd
, void *arg
)
509 struct video_device
*dev
= video_devdata(file
);
510 struct usb_usbvision
*usbvision
= (struct usb_usbvision
*) video_get_drvdata(dev
);
512 if (!USBVISION_IS_OPERATIONAL(usbvision
))
517 #ifdef CONFIG_VIDEO_ADV_DEBUG
518 /* ioctls to allow direct acces to the NT100x registers */
519 case VIDIOC_DBG_G_REGISTER
:
520 case VIDIOC_DBG_S_REGISTER
:
522 struct v4l2_register
*reg
= arg
;
525 if (!v4l2_chip_match_host(reg
->match_type
, reg
->match_chip
))
527 if (!capable(CAP_SYS_ADMIN
))
529 /* NT100x has a 8-bit register space */
530 if (cmd
== VIDIOC_DBG_G_REGISTER
)
531 errCode
= usbvision_read_reg(usbvision
, reg
->reg
&0xff);
533 errCode
= usbvision_write_reg(usbvision
, reg
->reg
&0xff, reg
->val
);
535 err("%s: VIDIOC_DBG_%c_REGISTER failed: error %d", __FUNCTION__
,
536 cmd
== VIDIOC_DBG_G_REGISTER
? 'G' : 'S', errCode
);
539 if (cmd
== VIDIOC_DBG_S_REGISTER
)
540 reg
->val
= (u8
)errCode
;
542 PDEBUG(DBG_IOCTL
, "VIDIOC_DBG_%c_REGISTER reg=0x%02X, value=0x%02X",
543 cmd
== VIDIOC_DBG_G_REGISTER
? 'G' : 'S',
544 (unsigned int)reg
->reg
, (unsigned int)reg
->val
);
548 case VIDIOC_QUERYCAP
:
550 struct v4l2_capability
*vc
=arg
;
552 memset(vc
, 0, sizeof(*vc
));
553 strlcpy(vc
->driver
, "USBVision", sizeof(vc
->driver
));
554 strlcpy(vc
->card
, usbvision_device_data
[usbvision
->DevModel
].ModelString
,
556 strlcpy(vc
->bus_info
, usbvision
->dev
->dev
.bus_id
,
557 sizeof(vc
->bus_info
));
558 vc
->version
= USBVISION_DRIVER_VERSION
;
559 vc
->capabilities
= V4L2_CAP_VIDEO_CAPTURE
|
563 (usbvision
->have_tuner
? V4L2_CAP_TUNER
: 0);
564 PDEBUG(DBG_IOCTL
, "VIDIOC_QUERYCAP");
567 case VIDIOC_ENUMINPUT
:
569 struct v4l2_input
*vi
= arg
;
572 if ((vi
->index
>= usbvision
->video_inputs
) || (vi
->index
< 0) )
574 if (usbvision
->have_tuner
) {
578 chan
= vi
->index
+ 1; //skip Television string
582 if (usbvision_device_data
[usbvision
->DevModel
].VideoChannels
== 4) {
583 strcpy(vi
->name
, "White Video Input");
586 strcpy(vi
->name
, "Television");
587 vi
->type
= V4L2_INPUT_TYPE_TUNER
;
590 vi
->std
= V4L2_STD_PAL
| V4L2_STD_NTSC
| V4L2_STD_SECAM
;
594 vi
->type
= V4L2_INPUT_TYPE_CAMERA
;
595 if (usbvision_device_data
[usbvision
->DevModel
].VideoChannels
== 4) {
596 strcpy(vi
->name
, "Green Video Input");
599 strcpy(vi
->name
, "Composite Video Input");
601 vi
->std
= V4L2_STD_PAL
;
604 vi
->type
= V4L2_INPUT_TYPE_CAMERA
;
605 if (usbvision_device_data
[usbvision
->DevModel
].VideoChannels
== 4) {
606 strcpy(vi
->name
, "Yellow Video Input");
609 strcpy(vi
->name
, "S-Video Input");
611 vi
->std
= V4L2_STD_PAL
;
614 vi
->type
= V4L2_INPUT_TYPE_CAMERA
;
615 strcpy(vi
->name
, "Red Video Input");
616 vi
->std
= V4L2_STD_PAL
;
619 PDEBUG(DBG_IOCTL
, "VIDIOC_ENUMINPUT name=%s:%d tuners=%d type=%d norm=%x",
620 vi
->name
, vi
->index
, vi
->tuner
,vi
->type
,(int)vi
->std
);
625 struct v4l2_standard
*e
= arg
;
632 ret
= v4l2_video_std_construct(e
, tvnorms
[e
->index
].id
,
633 tvnorms
[e
->index
].name
);
642 *input
= usbvision
->ctl_input
;
648 if ((*input
>= usbvision
->video_inputs
) || (*input
< 0) )
650 usbvision
->ctl_input
= *input
;
652 down(&usbvision
->lock
);
653 usbvision_muxsel(usbvision
, usbvision
->ctl_input
);
654 usbvision_set_input(usbvision
);
655 usbvision_set_output(usbvision
, usbvision
->curwidth
, usbvision
->curheight
);
656 up(&usbvision
->lock
);
661 v4l2_std_id
*id
= arg
;
663 *id
= usbvision
->tvnorm
->id
;
665 PDEBUG(DBG_IOCTL
, "VIDIOC_G_STD std_id=%s", usbvision
->tvnorm
->name
);
670 v4l2_std_id
*id
= arg
;
673 for (i
= 0; i
< TVNORMS
; i
++)
674 if (*id
== tvnorms
[i
].id
)
677 for (i
= 0; i
< TVNORMS
; i
++)
678 if (*id
& tvnorms
[i
].id
)
683 down(&usbvision
->lock
);
684 usbvision
->tvnorm
= &tvnorms
[i
];
686 call_i2c_clients(usbvision
, VIDIOC_S_STD
,
687 &usbvision
->tvnorm
->id
);
689 up(&usbvision
->lock
);
691 PDEBUG(DBG_IOCTL
, "VIDIOC_S_STD std_id=%s", usbvision
->tvnorm
->name
);
696 struct v4l2_tuner
*vt
= arg
;
698 if (!usbvision
->have_tuner
|| vt
->index
) // Only tuner 0
700 strcpy(vt
->name
, "Television");
701 /* Let clients fill in the remainder of this struct */
702 call_i2c_clients(usbvision
,VIDIOC_G_TUNER
,vt
);
704 PDEBUG(DBG_IOCTL
, "VIDIOC_G_TUNER signal=%x, afc=%x",vt
->signal
,vt
->afc
);
709 struct v4l2_tuner
*vt
= arg
;
711 // Only no or one tuner for now
712 if (!usbvision
->have_tuner
|| vt
->index
)
714 /* let clients handle this */
715 call_i2c_clients(usbvision
,VIDIOC_S_TUNER
,vt
);
717 PDEBUG(DBG_IOCTL
, "VIDIOC_S_TUNER");
720 case VIDIOC_G_FREQUENCY
:
722 struct v4l2_frequency
*freq
= arg
;
724 freq
->tuner
= 0; // Only one tuner
725 freq
->type
= V4L2_TUNER_ANALOG_TV
;
726 freq
->frequency
= usbvision
->freq
;
727 PDEBUG(DBG_IOCTL
, "VIDIOC_G_FREQUENCY freq=0x%X", (unsigned)freq
->frequency
);
730 case VIDIOC_S_FREQUENCY
:
732 struct v4l2_frequency
*freq
= arg
;
734 // Only no or one tuner for now
735 if (!usbvision
->have_tuner
|| freq
->tuner
)
738 usbvision
->freq
= freq
->frequency
;
739 call_i2c_clients(usbvision
, cmd
, freq
);
740 PDEBUG(DBG_IOCTL
, "VIDIOC_S_FREQUENCY freq=0x%X", (unsigned)freq
->frequency
);
745 struct v4l2_audio
*v
= arg
;
746 memset(v
,0, sizeof(v
));
747 strcpy(v
->name
, "TV");
748 PDEBUG(DBG_IOCTL
, "VIDIOC_G_AUDIO");
753 struct v4l2_audio
*v
= arg
;
757 PDEBUG(DBG_IOCTL
, "VIDIOC_S_AUDIO");
760 case VIDIOC_QUERYCTRL
:
762 struct v4l2_queryctrl
*ctrl
= arg
;
765 memset(ctrl
,0,sizeof(*ctrl
));
768 call_i2c_clients(usbvision
, cmd
, arg
);
775 PDEBUG(DBG_IOCTL
,"VIDIOC_QUERYCTRL id=%x value=%x",ctrl
->id
,ctrl
->type
);
779 struct v4l2_control
*ctrl
= arg
;
780 call_i2c_clients(usbvision
, VIDIOC_G_CTRL
, ctrl
);
781 PDEBUG(DBG_IOCTL
,"VIDIOC_G_CTRL id=%x value=%x",ctrl
->id
,ctrl
->value
);
786 struct v4l2_control
*ctrl
= arg
;
788 PDEBUG(DBG_IOCTL
, "VIDIOC_S_CTRL id=%x value=%x",ctrl
->id
,ctrl
->value
);
789 call_i2c_clients(usbvision
, VIDIOC_S_CTRL
, ctrl
);
794 struct v4l2_requestbuffers
*vr
= arg
;
797 RESTRICT_TO_RANGE(vr
->count
,1,USBVISION_NUMFRAMES
);
799 // Check input validity : the user must do a VIDEO CAPTURE and MMAP method.
800 if((vr
->type
!= V4L2_BUF_TYPE_VIDEO_CAPTURE
) ||
801 (vr
->memory
!= V4L2_MEMORY_MMAP
))
804 if(usbvision
->streaming
== Stream_On
) {
805 if ((ret
= usbvision_stream_interrupt(usbvision
)))
809 usbvision_frames_free(usbvision
);
810 usbvision_empty_framequeues(usbvision
);
811 vr
->count
= usbvision_frames_alloc(usbvision
,vr
->count
);
813 usbvision
->curFrame
= NULL
;
815 PDEBUG(DBG_IOCTL
, "VIDIOC_REQBUFS count=%d",vr
->count
);
818 case VIDIOC_QUERYBUF
:
820 struct v4l2_buffer
*vb
= arg
;
821 struct usbvision_frame
*frame
;
823 // FIXME : must control that buffers are mapped (VIDIOC_REQBUFS has been called)
825 if(vb
->type
!= V4L2_CAP_VIDEO_CAPTURE
) {
828 if(vb
->index
>=usbvision
->num_frames
) {
831 // Updating the corresponding frame state
833 frame
= &usbvision
->frame
[vb
->index
];
834 if(frame
->grabstate
>= FrameState_Ready
)
835 vb
->flags
|= V4L2_BUF_FLAG_QUEUED
;
836 if(frame
->grabstate
>= FrameState_Done
)
837 vb
->flags
|= V4L2_BUF_FLAG_DONE
;
838 if(frame
->grabstate
== FrameState_Unused
)
839 vb
->flags
|= V4L2_BUF_FLAG_MAPPED
;
840 vb
->memory
= V4L2_MEMORY_MMAP
;
842 vb
->m
.offset
= vb
->index
*PAGE_ALIGN(usbvision
->max_frame_size
);
844 vb
->memory
= V4L2_MEMORY_MMAP
;
845 vb
->field
= V4L2_FIELD_NONE
;
846 vb
->length
= usbvision
->curwidth
*usbvision
->curheight
*usbvision
->palette
.bytes_per_pixel
;
847 vb
->timestamp
= usbvision
->frame
[vb
->index
].timestamp
;
848 vb
->sequence
= usbvision
->frame
[vb
->index
].sequence
;
853 struct v4l2_buffer
*vb
= arg
;
854 struct usbvision_frame
*frame
;
855 unsigned long lock_flags
;
857 // FIXME : works only on VIDEO_CAPTURE MODE, MMAP.
858 if(vb
->type
!= V4L2_CAP_VIDEO_CAPTURE
) {
861 if(vb
->index
>=usbvision
->num_frames
) {
865 frame
= &usbvision
->frame
[vb
->index
];
867 if (frame
->grabstate
!= FrameState_Unused
) {
871 /* Mark it as ready and enqueue frame */
872 frame
->grabstate
= FrameState_Ready
;
873 frame
->scanstate
= ScanState_Scanning
;
874 frame
->scanlength
= 0; /* Accumulated in usbvision_parse_data() */
876 vb
->flags
&= ~V4L2_BUF_FLAG_DONE
;
878 /* set v4l2_format index */
879 frame
->v4l2_format
= usbvision
->palette
;
881 spin_lock_irqsave(&usbvision
->queue_lock
, lock_flags
);
882 list_add_tail(&usbvision
->frame
[vb
->index
].frame
, &usbvision
->inqueue
);
883 spin_unlock_irqrestore(&usbvision
->queue_lock
, lock_flags
);
885 PDEBUG(DBG_IOCTL
, "VIDIOC_QBUF frame #%d",vb
->index
);
890 struct v4l2_buffer
*vb
= arg
;
892 struct usbvision_frame
*f
;
893 unsigned long lock_flags
;
895 if (vb
->type
!= V4L2_BUF_TYPE_VIDEO_CAPTURE
)
898 if (list_empty(&(usbvision
->outqueue
))) {
899 if (usbvision
->streaming
== Stream_Idle
)
901 ret
= wait_event_interruptible
902 (usbvision
->wait_frame
,
903 !list_empty(&(usbvision
->outqueue
)));
908 spin_lock_irqsave(&usbvision
->queue_lock
, lock_flags
);
909 f
= list_entry(usbvision
->outqueue
.next
,
910 struct usbvision_frame
, frame
);
911 list_del(usbvision
->outqueue
.next
);
912 spin_unlock_irqrestore(&usbvision
->queue_lock
, lock_flags
);
914 f
->grabstate
= FrameState_Unused
;
916 vb
->memory
= V4L2_MEMORY_MMAP
;
917 vb
->flags
= V4L2_BUF_FLAG_MAPPED
| V4L2_BUF_FLAG_QUEUED
| V4L2_BUF_FLAG_DONE
;
918 vb
->index
= f
->index
;
919 vb
->sequence
= f
->sequence
;
920 vb
->timestamp
= f
->timestamp
;
921 vb
->field
= V4L2_FIELD_NONE
;
922 vb
->bytesused
= f
->scanlength
;
926 case VIDIOC_STREAMON
:
928 int b
=V4L2_BUF_TYPE_VIDEO_CAPTURE
;
930 usbvision
->streaming
= Stream_On
;
932 call_i2c_clients(usbvision
,VIDIOC_STREAMON
, &b
);
934 PDEBUG(DBG_IOCTL
, "VIDIOC_STREAMON");
938 case VIDIOC_STREAMOFF
:
941 int b
=V4L2_BUF_TYPE_VIDEO_CAPTURE
;
943 if (*type
!= V4L2_BUF_TYPE_VIDEO_CAPTURE
)
946 if(usbvision
->streaming
== Stream_On
) {
947 usbvision_stream_interrupt(usbvision
);
948 // Stop all video streamings
949 call_i2c_clients(usbvision
,VIDIOC_STREAMOFF
, &b
);
951 usbvision_empty_framequeues(usbvision
);
953 PDEBUG(DBG_IOCTL
, "VIDIOC_STREAMOFF");
956 case VIDIOC_ENUM_FMT
:
958 struct v4l2_fmtdesc
*vfd
= arg
;
960 if(vfd
->index
>=USBVISION_SUPPORTED_PALETTES
-1) {
964 vfd
->type
= V4L2_BUF_TYPE_VIDEO_CAPTURE
;
965 strcpy(vfd
->description
,usbvision_v4l2_format
[vfd
->index
].desc
);
966 vfd
->pixelformat
= usbvision_v4l2_format
[vfd
->index
].format
;
967 memset(vfd
->reserved
, 0, sizeof(vfd
->reserved
));
972 struct v4l2_format
*vf
= arg
;
975 case V4L2_BUF_TYPE_VIDEO_CAPTURE
:
977 vf
->fmt
.pix
.width
= usbvision
->curwidth
;
978 vf
->fmt
.pix
.height
= usbvision
->curheight
;
979 vf
->fmt
.pix
.pixelformat
= usbvision
->palette
.format
;
980 vf
->fmt
.pix
.bytesperline
= usbvision
->curwidth
*usbvision
->palette
.bytes_per_pixel
;
981 vf
->fmt
.pix
.sizeimage
= vf
->fmt
.pix
.bytesperline
*usbvision
->curheight
;
982 vf
->fmt
.pix
.colorspace
= V4L2_COLORSPACE_SMPTE170M
;
983 vf
->fmt
.pix
.field
= V4L2_FIELD_NONE
; /* Always progressive image */
984 PDEBUG(DBG_IOCTL
, "VIDIOC_G_FMT w=%d, h=%d, format=%s",
985 vf
->fmt
.pix
.width
, vf
->fmt
.pix
.height
,usbvision
->palette
.desc
);
989 PDEBUG(DBG_IOCTL
, "VIDIOC_G_FMT invalid type %d",vf
->type
);
997 struct v4l2_format
*vf
= arg
;
1001 case V4L2_BUF_TYPE_VIDEO_CAPTURE
:
1003 /* Find requested format in available ones */
1004 for(formatIdx
=0;formatIdx
<USBVISION_SUPPORTED_PALETTES
;formatIdx
++) {
1005 if(vf
->fmt
.pix
.pixelformat
== usbvision_v4l2_format
[formatIdx
].format
) {
1006 usbvision
->palette
= usbvision_v4l2_format
[formatIdx
];
1011 if(formatIdx
== USBVISION_SUPPORTED_PALETTES
) {
1014 RESTRICT_TO_RANGE(vf
->fmt
.pix
.width
, MIN_FRAME_WIDTH
, MAX_FRAME_WIDTH
);
1015 RESTRICT_TO_RANGE(vf
->fmt
.pix
.height
, MIN_FRAME_HEIGHT
, MAX_FRAME_HEIGHT
);
1017 vf
->fmt
.pix
.bytesperline
= vf
->fmt
.pix
.width
*usbvision
->palette
.bytes_per_pixel
;
1018 vf
->fmt
.pix
.sizeimage
= vf
->fmt
.pix
.bytesperline
*vf
->fmt
.pix
.height
;
1020 if(cmd
== VIDIOC_TRY_FMT
) {
1021 PDEBUG(DBG_IOCTL
, "VIDIOC_TRY_FMT grabdisplay w=%d, h=%d, format=%s",
1022 vf
->fmt
.pix
.width
, vf
->fmt
.pix
.height
,usbvision
->palette
.desc
);
1026 /* stop io in case it is already in progress */
1027 if(usbvision
->streaming
== Stream_On
) {
1028 if ((ret
= usbvision_stream_interrupt(usbvision
)))
1031 usbvision_frames_free(usbvision
);
1032 usbvision_empty_framequeues(usbvision
);
1034 usbvision
->curFrame
= NULL
;
1036 // by now we are committed to the new data...
1037 down(&usbvision
->lock
);
1038 usbvision_set_output(usbvision
, vf
->fmt
.pix
.width
, vf
->fmt
.pix
.height
);
1039 up(&usbvision
->lock
);
1041 PDEBUG(DBG_IOCTL
, "VIDIOC_S_FMT grabdisplay w=%d, h=%d, format=%s",
1042 vf
->fmt
.pix
.width
, vf
->fmt
.pix
.height
,usbvision
->palette
.desc
);
1050 return -ENOIOCTLCMD
;
1055 static int usbvision_v4l2_ioctl(struct inode
*inode
, struct file
*file
,
1056 unsigned int cmd
, unsigned long arg
)
1058 return video_usercopy(inode
, file
, cmd
, arg
, usbvision_v4l2_do_ioctl
);
1062 static ssize_t
usbvision_v4l2_read(struct file
*file
, char __user
*buf
,
1063 size_t count
, loff_t
*ppos
)
1065 struct video_device
*dev
= video_devdata(file
);
1066 struct usb_usbvision
*usbvision
= (struct usb_usbvision
*) video_get_drvdata(dev
);
1067 int noblock
= file
->f_flags
& O_NONBLOCK
;
1068 unsigned long lock_flags
;
1071 struct usbvision_frame
*frame
;
1073 PDEBUG(DBG_IO
, "%s: %ld bytes, noblock=%d", __FUNCTION__
, (unsigned long)count
, noblock
);
1075 if (!USBVISION_IS_OPERATIONAL(usbvision
) || (buf
== NULL
))
1078 /* This entry point is compatible with the mmap routines so that a user can do either
1079 VIDIOC_QBUF/VIDIOC_DQBUF to get frames or call read on the device. */
1080 if(!usbvision
->num_frames
) {
1081 /* First, allocate some frames to work with if this has not been done with
1083 usbvision_frames_free(usbvision
);
1084 usbvision_empty_framequeues(usbvision
);
1085 usbvision_frames_alloc(usbvision
,USBVISION_NUMFRAMES
);
1088 if(usbvision
->streaming
!= Stream_On
) {
1089 /* no stream is running, make it running ! */
1090 usbvision
->streaming
= Stream_On
;
1091 call_i2c_clients(usbvision
,VIDIOC_STREAMON
, NULL
);
1094 /* Then, enqueue as many frames as possible (like a user of VIDIOC_QBUF would do) */
1095 for(i
=0;i
<usbvision
->num_frames
;i
++) {
1096 frame
= &usbvision
->frame
[i
];
1097 if(frame
->grabstate
== FrameState_Unused
) {
1098 /* Mark it as ready and enqueue frame */
1099 frame
->grabstate
= FrameState_Ready
;
1100 frame
->scanstate
= ScanState_Scanning
;
1101 frame
->scanlength
= 0; /* Accumulated in usbvision_parse_data() */
1103 /* set v4l2_format index */
1104 frame
->v4l2_format
= usbvision
->palette
;
1106 spin_lock_irqsave(&usbvision
->queue_lock
, lock_flags
);
1107 list_add_tail(&frame
->frame
, &usbvision
->inqueue
);
1108 spin_unlock_irqrestore(&usbvision
->queue_lock
, lock_flags
);
1112 /* Then try to steal a frame (like a VIDIOC_DQBUF would do) */
1113 if (list_empty(&(usbvision
->outqueue
))) {
1117 ret
= wait_event_interruptible
1118 (usbvision
->wait_frame
,
1119 !list_empty(&(usbvision
->outqueue
)));
1124 spin_lock_irqsave(&usbvision
->queue_lock
, lock_flags
);
1125 frame
= list_entry(usbvision
->outqueue
.next
,
1126 struct usbvision_frame
, frame
);
1127 list_del(usbvision
->outqueue
.next
);
1128 spin_unlock_irqrestore(&usbvision
->queue_lock
, lock_flags
);
1130 /* An error returns an empty frame */
1131 if (frame
->grabstate
== FrameState_Error
) {
1132 frame
->bytes_read
= 0;
1136 PDEBUG(DBG_IO
, "%s: frmx=%d, bytes_read=%ld, scanlength=%ld", __FUNCTION__
,
1137 frame
->index
, frame
->bytes_read
, frame
->scanlength
);
1139 /* copy bytes to user space; we allow for partials reads */
1140 if ((count
+ frame
->bytes_read
) > (unsigned long)frame
->scanlength
)
1141 count
= frame
->scanlength
- frame
->bytes_read
;
1143 if (copy_to_user(buf
, frame
->data
+ frame
->bytes_read
, count
)) {
1147 frame
->bytes_read
+= count
;
1148 PDEBUG(DBG_IO
, "%s: {copy} count used=%ld, new bytes_read=%ld", __FUNCTION__
,
1149 (unsigned long)count
, frame
->bytes_read
);
1151 // For now, forget the frame if it has not been read in one shot.
1152 /* if (frame->bytes_read >= frame->scanlength) {// All data has been read */
1153 frame
->bytes_read
= 0;
1155 /* Mark it as available to be used again. */
1156 frame
->grabstate
= FrameState_Unused
;
1162 static int usbvision_v4l2_mmap(struct file
*file
, struct vm_area_struct
*vma
)
1164 unsigned long size
= vma
->vm_end
- vma
->vm_start
,
1165 start
= vma
->vm_start
;
1169 struct video_device
*dev
= video_devdata(file
);
1170 struct usb_usbvision
*usbvision
= (struct usb_usbvision
*) video_get_drvdata(dev
);
1172 PDEBUG(DBG_MMAP
, "mmap");
1174 down(&usbvision
->lock
);
1176 if (!USBVISION_IS_OPERATIONAL(usbvision
)) {
1177 up(&usbvision
->lock
);
1181 if (!(vma
->vm_flags
& VM_WRITE
) ||
1182 size
!= PAGE_ALIGN(usbvision
->max_frame_size
)) {
1183 up(&usbvision
->lock
);
1187 for (i
= 0; i
< usbvision
->num_frames
; i
++) {
1188 if (((PAGE_ALIGN(usbvision
->max_frame_size
)*i
) >> PAGE_SHIFT
) == vma
->vm_pgoff
)
1191 if (i
== usbvision
->num_frames
) {
1192 PDEBUG(DBG_MMAP
, "mmap: user supplied mapping address is out of range");
1193 up(&usbvision
->lock
);
1197 /* VM_IO is eventually going to replace PageReserved altogether */
1198 vma
->vm_flags
|= VM_IO
;
1199 vma
->vm_flags
|= VM_RESERVED
; /* avoid to swap out this VMA */
1201 pos
= usbvision
->frame
[i
].data
;
1204 if (vm_insert_page(vma
, start
, vmalloc_to_page(pos
))) {
1205 PDEBUG(DBG_MMAP
, "mmap: vm_insert_page failed");
1206 up(&usbvision
->lock
);
1214 up(&usbvision
->lock
);
1220 * Here comes the stuff for radio on usbvision based devices
1223 static int usbvision_radio_open(struct inode
*inode
, struct file
*file
)
1225 struct video_device
*dev
= video_devdata(file
);
1226 struct usb_usbvision
*usbvision
= (struct usb_usbvision
*) video_get_drvdata(dev
);
1227 struct v4l2_frequency freq
;
1230 PDEBUG(DBG_IO
, "%s:", __FUNCTION__
);
1232 down(&usbvision
->lock
);
1234 if (usbvision
->user
) {
1235 err("%s: Someone tried to open an already opened USBVision Radio!", __FUNCTION__
);
1240 usbvision_reset_powerOffTimer(usbvision
);
1241 if (usbvision
->power
== 0) {
1242 usbvision_power_on(usbvision
);
1243 usbvision_init_i2c(usbvision
);
1247 /* Alternate interface 1 is is the biggest frame size */
1248 errCode
= usbvision_set_alternate(usbvision
);
1250 usbvision
->last_error
= errCode
;
1254 // If so far no errors then we shall start the radio
1255 usbvision
->radio
= 1;
1256 call_i2c_clients(usbvision
,AUDC_SET_RADIO
,&usbvision
->tuner_type
);
1257 freq
.frequency
= 1517; //SWR3 @ 94.8MHz
1258 call_i2c_clients(usbvision
, VIDIOC_S_FREQUENCY
, &freq
);
1259 usbvision_set_audio(usbvision
, USBVISION_AUDIO_RADIO
);
1264 if (PowerOnAtOpen
) {
1265 usbvision_i2c_usb_del_bus(&usbvision
->i2c_adap
);
1266 usbvision_power_off(usbvision
);
1267 usbvision
->initialized
= 0;
1270 up(&usbvision
->lock
);
1275 static int usbvision_radio_close(struct inode
*inode
, struct file
*file
)
1277 struct video_device
*dev
= video_devdata(file
);
1278 struct usb_usbvision
*usbvision
= (struct usb_usbvision
*) video_get_drvdata(dev
);
1283 down(&usbvision
->lock
);
1285 /* Set packet size to 0 */
1286 usbvision
->ifaceAlt
=0;
1287 errCode
= usb_set_interface(usbvision
->dev
, usbvision
->iface
,
1288 usbvision
->ifaceAlt
);
1290 usbvision_audio_off(usbvision
);
1294 if (PowerOnAtOpen
) {
1295 usbvision_set_powerOffTimer(usbvision
);
1296 usbvision
->initialized
= 0;
1299 up(&usbvision
->lock
);
1301 if (usbvision
->remove_pending
) {
1302 printk(KERN_INFO
"%s: Final disconnect\n", __FUNCTION__
);
1303 usbvision_release(usbvision
);
1307 PDEBUG(DBG_IO
, "success");
1312 static int usbvision_do_radio_ioctl(struct inode
*inode
, struct file
*file
,
1313 unsigned int cmd
, void *arg
)
1315 struct video_device
*dev
= video_devdata(file
);
1316 struct usb_usbvision
*usbvision
= (struct usb_usbvision
*) video_get_drvdata(dev
);
1318 if (!USBVISION_IS_OPERATIONAL(usbvision
))
1322 case VIDIOC_QUERYCAP
:
1324 struct v4l2_capability
*vc
=arg
;
1326 memset(vc
, 0, sizeof(*vc
));
1327 strlcpy(vc
->driver
, "USBVision", sizeof(vc
->driver
));
1328 strlcpy(vc
->card
, usbvision_device_data
[usbvision
->DevModel
].ModelString
,
1330 strlcpy(vc
->bus_info
, usbvision
->dev
->dev
.bus_id
,
1331 sizeof(vc
->bus_info
));
1332 vc
->version
= USBVISION_DRIVER_VERSION
;
1333 vc
->capabilities
= (usbvision
->have_tuner
? V4L2_CAP_TUNER
: 0);
1334 PDEBUG(DBG_IO
, "VIDIOC_QUERYCAP");
1337 case VIDIOC_QUERYCTRL
:
1339 struct v4l2_queryctrl
*ctrl
= arg
;
1342 memset(ctrl
,0,sizeof(*ctrl
));
1345 call_i2c_clients(usbvision
, cmd
, arg
);
1346 PDEBUG(DBG_IO
,"VIDIOC_QUERYCTRL id=%x value=%x",ctrl
->id
,ctrl
->type
);
1356 struct v4l2_control
*ctrl
= arg
;
1358 call_i2c_clients(usbvision
, VIDIOC_G_CTRL
, ctrl
);
1359 PDEBUG(DBG_IO
,"VIDIOC_G_CTRL id=%x value=%x",ctrl
->id
,ctrl
->value
);
1364 struct v4l2_control
*ctrl
= arg
;
1366 call_i2c_clients(usbvision
, VIDIOC_S_CTRL
, ctrl
);
1367 PDEBUG(DBG_IO
, "VIDIOC_S_CTRL id=%x value=%x",ctrl
->id
,ctrl
->value
);
1370 case VIDIOC_G_TUNER
:
1372 struct v4l2_tuner
*t
= arg
;
1377 memset(t
,0,sizeof(*t
));
1378 strcpy(t
->name
, "Radio");
1379 t
->type
= V4L2_TUNER_RADIO
;
1381 /* Let clients fill in the remainder of this struct */
1382 call_i2c_clients(usbvision
,VIDIOC_G_TUNER
,t
);
1383 PDEBUG(DBG_IO
, "VIDIOC_G_TUNER signal=%x, afc=%x",t
->signal
,t
->afc
);
1386 case VIDIOC_S_TUNER
:
1388 struct v4l2_tuner
*vt
= arg
;
1390 // Only no or one tuner for now
1391 if (!usbvision
->have_tuner
|| vt
->index
)
1393 /* let clients handle this */
1394 call_i2c_clients(usbvision
,VIDIOC_S_TUNER
,vt
);
1396 PDEBUG(DBG_IO
, "VIDIOC_S_TUNER");
1399 case VIDIOC_G_AUDIO
:
1401 struct v4l2_audio
*a
= arg
;
1403 memset(a
,0,sizeof(*a
));
1404 strcpy(a
->name
,"Radio");
1405 PDEBUG(DBG_IO
, "VIDIOC_G_AUDIO");
1408 case VIDIOC_S_AUDIO
:
1409 case VIDIOC_S_INPUT
:
1413 case VIDIOC_G_FREQUENCY
:
1415 struct v4l2_frequency
*f
= arg
;
1417 memset(f
,0,sizeof(*f
));
1419 f
->type
= V4L2_TUNER_RADIO
;
1420 f
->frequency
= usbvision
->freq
;
1421 call_i2c_clients(usbvision
, cmd
, f
);
1422 PDEBUG(DBG_IO
, "VIDIOC_G_FREQUENCY freq=0x%X", (unsigned)f
->frequency
);
1426 case VIDIOC_S_FREQUENCY
:
1428 struct v4l2_frequency
*f
= arg
;
1432 usbvision
->freq
= f
->frequency
;
1433 call_i2c_clients(usbvision
, cmd
, f
);
1434 PDEBUG(DBG_IO
, "VIDIOC_S_FREQUENCY freq=0x%X", (unsigned)f
->frequency
);
1440 PDEBUG(DBG_IO
, "%s: Unknown command %x", __FUNCTION__
, cmd
);
1441 return -ENOIOCTLCMD
;
1448 static int usbvision_radio_ioctl(struct inode
*inode
, struct file
*file
,
1449 unsigned int cmd
, unsigned long arg
)
1451 return video_usercopy(inode
, file
, cmd
, arg
, usbvision_do_radio_ioctl
);
1456 * Here comes the stuff for vbi on usbvision based devices
1459 static int usbvision_vbi_open(struct inode
*inode
, struct file
*file
)
1466 static int usbvision_vbi_close(struct inode
*inode
, struct file
*file
)
1472 static int usbvision_do_vbi_ioctl(struct inode
*inode
, struct file
*file
,
1473 unsigned int cmd
, void *arg
)
1479 static int usbvision_vbi_ioctl(struct inode
*inode
, struct file
*file
,
1480 unsigned int cmd
, unsigned long arg
)
1482 return video_usercopy(inode
, file
, cmd
, arg
, usbvision_do_vbi_ioctl
);
1487 // Video registration stuff
1491 static const struct file_operations usbvision_fops
= {
1492 .owner
= THIS_MODULE
,
1493 .open
= usbvision_v4l2_open
,
1494 .release
= usbvision_v4l2_close
,
1495 .read
= usbvision_v4l2_read
,
1496 .mmap
= usbvision_v4l2_mmap
,
1497 .ioctl
= usbvision_v4l2_ioctl
,
1498 .llseek
= no_llseek
,
1500 static struct video_device usbvision_video_template
= {
1501 .owner
= THIS_MODULE
,
1502 .type
= VID_TYPE_TUNER
| VID_TYPE_CAPTURE
,
1503 .hardware
= VID_HARDWARE_USBVISION
,
1504 .fops
= &usbvision_fops
,
1505 .name
= "usbvision-video",
1506 .release
= video_device_release
,
1512 static const struct file_operations usbvision_radio_fops
= {
1513 .owner
= THIS_MODULE
,
1514 .open
= usbvision_radio_open
,
1515 .release
= usbvision_radio_close
,
1516 .ioctl
= usbvision_radio_ioctl
,
1517 .llseek
= no_llseek
,
1520 static struct video_device usbvision_radio_template
=
1522 .owner
= THIS_MODULE
,
1523 .type
= VID_TYPE_TUNER
,
1524 .hardware
= VID_HARDWARE_USBVISION
,
1525 .fops
= &usbvision_radio_fops
,
1526 .release
= video_device_release
,
1527 .name
= "usbvision-radio",
1533 static const struct file_operations usbvision_vbi_fops
= {
1534 .owner
= THIS_MODULE
,
1535 .open
= usbvision_vbi_open
,
1536 .release
= usbvision_vbi_close
,
1537 .ioctl
= usbvision_vbi_ioctl
,
1538 .llseek
= no_llseek
,
1541 static struct video_device usbvision_vbi_template
=
1543 .owner
= THIS_MODULE
,
1544 .type
= VID_TYPE_TUNER
,
1545 .hardware
= VID_HARDWARE_USBVISION
,
1546 .fops
= &usbvision_vbi_fops
,
1547 .release
= video_device_release
,
1548 .name
= "usbvision-vbi",
1553 static struct video_device
*usbvision_vdev_init(struct usb_usbvision
*usbvision
,
1554 struct video_device
*vdev_template
,
1557 struct usb_device
*usb_dev
= usbvision
->dev
;
1558 struct video_device
*vdev
;
1560 if (usb_dev
== NULL
) {
1561 err("%s: usbvision->dev is not set", __FUNCTION__
);
1565 vdev
= video_device_alloc();
1569 *vdev
= *vdev_template
;
1570 // vdev->minor = -1;
1571 vdev
->dev
= &usb_dev
->dev
;
1572 snprintf(vdev
->name
, sizeof(vdev
->name
), "%s", name
);
1573 video_set_drvdata(vdev
, usbvision
);
1577 // unregister video4linux devices
1578 static void usbvision_unregister_video(struct usb_usbvision
*usbvision
)
1581 if (usbvision
->vbi
) {
1582 PDEBUG(DBG_PROBE
, "unregister /dev/vbi%d [v4l2]", usbvision
->vbi
->minor
& 0x1f);
1583 if (usbvision
->vbi
->minor
!= -1) {
1584 video_unregister_device(usbvision
->vbi
);
1587 video_device_release(usbvision
->vbi
);
1589 usbvision
->vbi
= NULL
;
1593 if (usbvision
->rdev
) {
1594 PDEBUG(DBG_PROBE
, "unregister /dev/radio%d [v4l2]", usbvision
->rdev
->minor
& 0x1f);
1595 if (usbvision
->rdev
->minor
!= -1) {
1596 video_unregister_device(usbvision
->rdev
);
1599 video_device_release(usbvision
->rdev
);
1601 usbvision
->rdev
= NULL
;
1605 if (usbvision
->vdev
) {
1606 PDEBUG(DBG_PROBE
, "unregister /dev/video%d [v4l2]", usbvision
->vdev
->minor
& 0x1f);
1607 if (usbvision
->vdev
->minor
!= -1) {
1608 video_unregister_device(usbvision
->vdev
);
1611 video_device_release(usbvision
->vdev
);
1613 usbvision
->vdev
= NULL
;
1617 // register video4linux devices
1618 static int __devinit
usbvision_register_video(struct usb_usbvision
*usbvision
)
1621 usbvision
->vdev
= usbvision_vdev_init(usbvision
, &usbvision_video_template
, "USBVision Video");
1622 if (usbvision
->vdev
== NULL
) {
1625 if (video_register_device(usbvision
->vdev
, VFL_TYPE_GRABBER
, video_nr
)<0) {
1628 printk(KERN_INFO
"USBVision[%d]: registered USBVision Video device /dev/video%d [v4l2]\n", usbvision
->nr
,usbvision
->vdev
->minor
& 0x1f);
1631 if (usbvision_device_data
[usbvision
->DevModel
].Radio
) {
1632 // usbvision has radio
1633 usbvision
->rdev
= usbvision_vdev_init(usbvision
, &usbvision_radio_template
, "USBVision Radio");
1634 if (usbvision
->rdev
== NULL
) {
1637 if (video_register_device(usbvision
->rdev
, VFL_TYPE_RADIO
, radio_nr
)<0) {
1640 printk(KERN_INFO
"USBVision[%d]: registered USBVision Radio device /dev/radio%d [v4l2]\n", usbvision
->nr
, usbvision
->rdev
->minor
& 0x1f);
1643 if (usbvision_device_data
[usbvision
->DevModel
].vbi
) {
1644 usbvision
->vbi
= usbvision_vdev_init(usbvision
, &usbvision_vbi_template
, "USBVision VBI");
1645 if (usbvision
->vdev
== NULL
) {
1648 if (video_register_device(usbvision
->vbi
, VFL_TYPE_VBI
, vbi_nr
)<0) {
1651 printk(KERN_INFO
"USBVision[%d]: registered USBVision VBI device /dev/vbi%d [v4l2] (Not Working Yet!)\n", usbvision
->nr
,usbvision
->vbi
->minor
& 0x1f);
1657 err("USBVision[%d]: video_register_device() failed", usbvision
->nr
);
1658 usbvision_unregister_video(usbvision
);
1665 * This code allocates the struct usb_usbvision. It is filled with default values.
1667 * Returns NULL on error, a pointer to usb_usbvision else.
1670 static struct usb_usbvision
*usbvision_alloc(struct usb_device
*dev
)
1672 struct usb_usbvision
*usbvision
;
1674 if ((usbvision
= kzalloc(sizeof(struct usb_usbvision
), GFP_KERNEL
)) == NULL
) {
1678 usbvision
->dev
= dev
;
1680 init_MUTEX(&usbvision
->lock
); /* to 1 == available */
1682 // prepare control urb for control messages during interrupts
1683 usbvision
->ctrlUrb
= usb_alloc_urb(USBVISION_URB_FRAMES
, GFP_KERNEL
);
1684 if (usbvision
->ctrlUrb
== NULL
) {
1687 init_waitqueue_head(&usbvision
->ctrlUrb_wq
);
1688 init_MUTEX(&usbvision
->ctrlUrbLock
); /* to 1 == available */
1690 usbvision_init_powerOffTimer(usbvision
);
1695 if (usbvision
&& usbvision
->ctrlUrb
) {
1696 usb_free_urb(usbvision
->ctrlUrb
);
1705 * usbvision_release()
1707 * This code does final release of struct usb_usbvision. This happens
1708 * after the device is disconnected -and- all clients closed their files.
1711 static void usbvision_release(struct usb_usbvision
*usbvision
)
1713 PDEBUG(DBG_PROBE
, "");
1715 down(&usbvision
->lock
);
1717 usbvision_reset_powerOffTimer(usbvision
);
1719 usbvision
->initialized
= 0;
1721 up(&usbvision
->lock
);
1723 usbvision_remove_sysfs(usbvision
->vdev
);
1724 usbvision_unregister_video(usbvision
);
1726 if (usbvision
->ctrlUrb
) {
1727 usb_free_urb(usbvision
->ctrlUrb
);
1732 PDEBUG(DBG_PROBE
, "success");
1736 /******************************** usb interface *****************************************/
1738 static void usbvision_configure_video(struct usb_usbvision
*usbvision
)
1742 if (usbvision
== NULL
)
1745 model
= usbvision
->DevModel
;
1746 usbvision
->palette
= usbvision_v4l2_format
[2]; // V4L2_PIX_FMT_RGB24;
1748 if (usbvision_device_data
[usbvision
->DevModel
].Vin_Reg2_override
) {
1749 usbvision
->Vin_Reg2_Preset
= usbvision_device_data
[usbvision
->DevModel
].Vin_Reg2
;
1751 usbvision
->Vin_Reg2_Preset
= 0;
1754 for (i
= 0; i
< TVNORMS
; i
++)
1755 if (usbvision_device_data
[model
].VideoNorm
== tvnorms
[i
].mode
)
1759 usbvision
->tvnorm
= &tvnorms
[i
]; /* set default norm */
1761 usbvision
->video_inputs
= usbvision_device_data
[model
].VideoChannels
;
1762 usbvision
->ctl_input
= 0;
1764 /* This should be here to make i2c clients to be able to register */
1765 usbvision_audio_off(usbvision
); //first switch off audio
1766 if (!PowerOnAtOpen
) {
1767 usbvision_power_on(usbvision
); //and then power up the noisy tuner
1768 usbvision_init_i2c(usbvision
);
1775 * This procedure queries device descriptor and accepts the interface
1776 * if it looks like USBVISION video device
1779 static int __devinit
usbvision_probe(struct usb_interface
*intf
,
1780 const struct usb_device_id
*devid
)
1782 struct usb_device
*dev
= usb_get_dev(interface_to_usbdev(intf
));
1783 struct usb_interface
*uif
;
1784 __u8 ifnum
= intf
->altsetting
->desc
.bInterfaceNumber
;
1785 const struct usb_host_interface
*interface
;
1786 struct usb_usbvision
*usbvision
= NULL
;
1787 const struct usb_endpoint_descriptor
*endpoint
;
1790 PDEBUG(DBG_PROBE
, "VID=%#04x, PID=%#04x, ifnum=%u",
1791 dev
->descriptor
.idVendor
,
1792 dev
->descriptor
.idProduct
, ifnum
);
1794 model
= devid
->driver_info
;
1795 printk(KERN_INFO
"%s: %s found\n", __FUNCTION__
,
1796 usbvision_device_data
[model
].ModelString
);
1798 if (usbvision_device_data
[model
].Interface
>= 0) {
1799 interface
= &dev
->actconfig
->interface
[usbvision_device_data
[model
].Interface
]->altsetting
[0];
1802 interface
= &dev
->actconfig
->interface
[ifnum
]->altsetting
[0];
1804 endpoint
= &interface
->endpoint
[1].desc
;
1805 if ((endpoint
->bmAttributes
& USB_ENDPOINT_XFERTYPE_MASK
) != USB_ENDPOINT_XFER_ISOC
) {
1806 err("%s: interface %d. has non-ISO endpoint!", __FUNCTION__
, ifnum
);
1807 err("%s: Endpoint attributes %d", __FUNCTION__
, endpoint
->bmAttributes
);
1810 if ((endpoint
->bEndpointAddress
& USB_ENDPOINT_DIR_MASK
) == USB_DIR_OUT
) {
1811 err("%s: interface %d. has ISO OUT endpoint!", __FUNCTION__
, ifnum
);
1817 if ((usbvision
= usbvision_alloc(dev
)) == NULL
) {
1818 err("%s: couldn't allocate USBVision struct", __FUNCTION__
);
1822 if (dev
->descriptor
.bNumConfigurations
> 1) {
1823 usbvision
->bridgeType
= BRIDGE_NT1004
;
1825 else if (model
== DAZZLE_DVC_90_REV_1_SECAM
) {
1826 usbvision
->bridgeType
= BRIDGE_NT1005
;
1829 usbvision
->bridgeType
= BRIDGE_NT1003
;
1831 PDEBUG(DBG_PROBE
, "bridgeType %d", usbvision
->bridgeType
);
1833 down(&usbvision
->lock
);
1835 /* compute alternate max packet sizes */
1836 uif
= dev
->actconfig
->interface
[0];
1838 usbvision
->num_alt
=uif
->num_altsetting
;
1839 PDEBUG(DBG_PROBE
, "Alternate settings: %i",usbvision
->num_alt
);
1840 usbvision
->alt_max_pkt_size
= kmalloc(32*
1841 usbvision
->num_alt
,GFP_KERNEL
);
1842 if (usbvision
->alt_max_pkt_size
== NULL
) {
1843 err("usbvision: out of memory!\n");
1847 for (i
= 0; i
< usbvision
->num_alt
; i
++) {
1848 u16 tmp
= le16_to_cpu(uif
->altsetting
[i
].endpoint
[1].desc
.
1850 usbvision
->alt_max_pkt_size
[i
] =
1851 (tmp
& 0x07ff) * (((tmp
& 0x1800) >> 11) + 1);
1852 PDEBUG(DBG_PROBE
, "Alternate setting %i, max size= %i",i
,
1853 usbvision
->alt_max_pkt_size
[i
]);
1857 usbvision
->nr
= usbvision_nr
++;
1859 usbvision
->have_tuner
= usbvision_device_data
[model
].Tuner
;
1860 if (usbvision
->have_tuner
) {
1861 usbvision
->tuner_type
= usbvision_device_data
[model
].TunerType
;
1864 usbvision
->tuner_addr
= ADDR_UNSET
;
1866 usbvision
->DevModel
= model
;
1867 usbvision
->remove_pending
= 0;
1868 usbvision
->iface
= ifnum
;
1869 usbvision
->ifaceAlt
= 0;
1870 usbvision
->video_endp
= endpoint
->bEndpointAddress
;
1871 usbvision
->isocPacketSize
= 0;
1872 usbvision
->usb_bandwidth
= 0;
1873 usbvision
->user
= 0;
1874 usbvision
->streaming
= Stream_Off
;
1875 usbvision_register_video(usbvision
);
1876 usbvision_configure_video(usbvision
);
1877 up(&usbvision
->lock
);
1880 usb_set_intfdata (intf
, usbvision
);
1881 usbvision_create_sysfs(usbvision
->vdev
);
1883 PDEBUG(DBG_PROBE
, "success");
1889 * usbvision_disconnect()
1891 * This procedure stops all driver activity, deallocates interface-private
1892 * structure (pointed by 'ptr') and after that driver should be removable
1893 * with no ill consequences.
1896 static void __devexit
usbvision_disconnect(struct usb_interface
*intf
)
1898 struct usb_usbvision
*usbvision
= usb_get_intfdata(intf
);
1900 PDEBUG(DBG_PROBE
, "");
1902 if (usbvision
== NULL
) {
1903 err("%s: usb_get_intfdata() failed", __FUNCTION__
);
1906 usb_set_intfdata (intf
, NULL
);
1908 down(&usbvision
->lock
);
1910 // At this time we ask to cancel outstanding URBs
1911 usbvision_stop_isoc(usbvision
);
1913 if (usbvision
->power
) {
1914 usbvision_i2c_usb_del_bus(&usbvision
->i2c_adap
);
1915 usbvision_power_off(usbvision
);
1917 usbvision
->remove_pending
= 1; // Now all ISO data will be ignored
1919 usb_put_dev(usbvision
->dev
);
1920 usbvision
->dev
= NULL
; // USB device is no more
1922 up(&usbvision
->lock
);
1924 if (usbvision
->user
) {
1925 printk(KERN_INFO
"%s: In use, disconnect pending\n", __FUNCTION__
);
1926 wake_up_interruptible(&usbvision
->wait_frame
);
1927 wake_up_interruptible(&usbvision
->wait_stream
);
1930 usbvision_release(usbvision
);
1933 PDEBUG(DBG_PROBE
, "success");
1937 static struct usb_driver usbvision_driver
= {
1938 .name
= "usbvision",
1939 .id_table
= usbvision_table
,
1940 .probe
= usbvision_probe
,
1941 .disconnect
= usbvision_disconnect
1945 * customdevice_process()
1947 * This procedure preprocesses CustomDevice parameter if any
1950 static void customdevice_process(void)
1952 unsigned int id_vend
,id_prod
,radio
,tuner
;
1954 usbvision_device_data
[0]=usbvision_device_data
[1];
1955 usbvision_table
[0]=usbvision_table
[1];
1959 char *parse
=CustomDevice
;
1962 PDEBUG(DBG_PROBE
, "CustomDevice=%s", CustomDevice
);
1964 /*format is CustomDevice="0x0573 0x4D31 0 7113 3 PAL 1 1 1 5 -1 -1 -1 -1 -1"
1965 usbvision_device_data[0].idVendor;
1966 usbvision_device_data[0].idProduct;
1967 usbvision_device_data[0].Interface;
1968 usbvision_device_data[0].Codec;
1969 usbvision_device_data[0].VideoChannels;
1970 usbvision_device_data[0].VideoNorm;
1971 usbvision_device_data[0].AudioChannels;
1972 usbvision_device_data[0].Radio;
1973 usbvision_device_data[0].Tuner;
1974 usbvision_device_data[0].TunerType;
1975 usbvision_device_data[0].Vin_Reg1;
1976 usbvision_device_data[0].Vin_Reg2;
1977 usbvision_device_data[0].X_Offset;
1978 usbvision_device_data[0].Y_Offset;
1979 usbvision_device_data[0].Dvi_yuv;
1980 usbvision_device_data[0].ModelString;
1984 usbvision_device_data
[0].ModelString
="USBVISION Custom Device";
1987 sscanf(parse
,"%u",&id_vend
);
1988 usbvision_table
[0].idVendor
=id_vend
;
1991 PDEBUG(DBG_PROBE
, "idVendor=0x%.4X", usbvision_table
[0].idVendor
);
1993 sscanf(parse
,"%u",&id_prod
);
1994 usbvision_table
[0].idProduct
=id_prod
;
1996 PDEBUG(DBG_PROBE
, "idProduct=0x%.4X", usbvision_table
[0].idProduct
);
1997 sscanf(parse
,"%d",&usbvision_device_data
[0].Interface
);
1999 PDEBUG(DBG_PROBE
, "Interface=%d", usbvision_device_data
[0].Interface
);
2000 sscanf(parse
,"%hd",&usbvision_device_data
[0].Codec
);
2002 PDEBUG(DBG_PROBE
, "Codec=%d", usbvision_device_data
[0].Codec
);
2003 sscanf(parse
,"%d",&tmp
);
2004 usbvision_device_data
[0].VideoChannels
= tmp
;
2006 PDEBUG(DBG_PROBE
, "VideoChannels=%d", usbvision_device_data
[0].VideoChannels
);
2011 PDEBUG(DBG_PROBE
, "VideoNorm=PAL");
2012 usbvision_device_data
[0].VideoNorm
=V4L2_STD_PAL
;
2016 PDEBUG(DBG_PROBE
, "VideoNorm=SECAM");
2017 usbvision_device_data
[0].VideoNorm
=V4L2_STD_SECAM
;
2021 PDEBUG(DBG_PROBE
, "VideoNorm=NTSC");
2022 usbvision_device_data
[0].VideoNorm
=V4L2_STD_NTSC
;
2026 PDEBUG(DBG_PROBE
, "VideoNorm=PAL (by default)");
2027 usbvision_device_data
[0].VideoNorm
=V4L2_STD_PAL
;
2032 sscanf(parse
,"%d",&tmp
);
2033 usbvision_device_data
[0].AudioChannels
= tmp
;
2035 PDEBUG(DBG_PROBE
, "AudioChannels=%d", usbvision_device_data
[0].AudioChannels
);
2036 sscanf(parse
,"%d",&radio
);
2037 usbvision_device_data
[0].Radio
=(radio
?1:0);
2039 PDEBUG(DBG_PROBE
, "Radio=%d", usbvision_device_data
[0].Radio
);
2040 sscanf(parse
,"%d",&tuner
);
2041 usbvision_device_data
[0].Tuner
=(tuner
?1:0);
2043 PDEBUG(DBG_PROBE
, "Tuner=%d", usbvision_device_data
[0].Tuner
);
2044 sscanf(parse
,"%hhu",&usbvision_device_data
[0].TunerType
);
2046 PDEBUG(DBG_PROBE
, "TunerType=%d", usbvision_device_data
[0].TunerType
);
2047 sscanf(parse
,"%d",&tmp
);
2049 usbvision_device_data
[0].Vin_Reg1_override
= 1;
2050 usbvision_device_data
[0].Vin_Reg1
= tmp
&0xff;
2053 PDEBUG(DBG_PROBE
, "Vin_Reg1=%d", usbvision_device_data
[0].Vin_Reg1
);
2054 sscanf(parse
,"%d",&tmp
);
2056 usbvision_device_data
[0].Vin_Reg2_override
= 1;
2057 usbvision_device_data
[0].Vin_Reg2
= tmp
&0xff;
2060 PDEBUG(DBG_PROBE
, "Vin_Reg2=%d", usbvision_device_data
[0].Vin_Reg2
);
2061 sscanf(parse
,"%hd",&usbvision_device_data
[0].X_Offset
);
2063 PDEBUG(DBG_PROBE
, "X_Offset=%d", usbvision_device_data
[0].X_Offset
);
2064 sscanf(parse
,"%hd",&usbvision_device_data
[0].Y_Offset
);
2066 PDEBUG(DBG_PROBE
, "Y_Offset=%d", usbvision_device_data
[0].Y_Offset
);
2067 sscanf(parse
,"%d",&tmp
);
2069 usbvision_device_data
[0].Dvi_yuv_override
= 1;
2070 usbvision_device_data
[0].Dvi_yuv
= tmp
&0xff;
2072 PDEBUG(DBG_PROBE
, "Dvi_yuv=%d", usbvision_device_data
[0].Dvi_yuv
);
2074 //add to usbvision_table also
2075 usbvision_table
[0].match_flags
=USB_DEVICE_ID_MATCH_DEVICE
;
2084 * This code is run to initialize the driver.
2087 static int __init
usbvision_init(void)
2091 PDEBUG(DBG_PROBE
, "");
2093 PDEBUG(DBG_IOCTL
, "IOCTL debugging is enabled [video]");
2094 PDEBUG(DBG_IO
, "IO debugging is enabled [video]");
2095 PDEBUG(DBG_PROBE
, "PROBE debugging is enabled [video]");
2096 PDEBUG(DBG_MMAP
, "MMAP debugging is enabled [video]");
2098 /* disable planar mode support unless compression enabled */
2099 if (isocMode
!= ISOC_MODE_COMPRESS
) {
2100 // FIXME : not the right way to set supported flag
2101 usbvision_v4l2_format
[6].supported
= 0; // V4L2_PIX_FMT_YVU420
2102 usbvision_v4l2_format
[7].supported
= 0; // V4L2_PIX_FMT_YUV422P
2105 customdevice_process();
2107 errCode
= usb_register(&usbvision_driver
);
2110 printk(KERN_INFO DRIVER_DESC
" : " USBVISION_VERSION_STRING
"\n");
2111 PDEBUG(DBG_PROBE
, "success");
2116 static void __exit
usbvision_exit(void)
2118 PDEBUG(DBG_PROBE
, "");
2120 usb_deregister(&usbvision_driver
);
2121 PDEBUG(DBG_PROBE
, "success");
2124 module_init(usbvision_init
);
2125 module_exit(usbvision_exit
);
2128 * Overrides for Emacs so that we follow Linus's tabbing style.
2129 * ---------------------------------------------------------------------------