diff options
Diffstat (limited to 'drivers/media/usb/usbvision')
-rw-r--r-- | drivers/media/usb/usbvision/Kconfig | 12 | ||||
-rw-r--r-- | drivers/media/usb/usbvision/Makefile | 6 | ||||
-rw-r--r-- | drivers/media/usb/usbvision/usbvision-cards.c | 1133 | ||||
-rw-r--r-- | drivers/media/usb/usbvision/usbvision-cards.h | 69 | ||||
-rw-r--r-- | drivers/media/usb/usbvision/usbvision-core.c | 2518 | ||||
-rw-r--r-- | drivers/media/usb/usbvision/usbvision-i2c.c | 456 | ||||
-rw-r--r-- | drivers/media/usb/usbvision/usbvision-video.c | 1720 | ||||
-rw-r--r-- | drivers/media/usb/usbvision/usbvision.h | 535 |
8 files changed, 6449 insertions, 0 deletions
diff --git a/drivers/media/usb/usbvision/Kconfig b/drivers/media/usb/usbvision/Kconfig new file mode 100644 index 000000000000..fc24ef05b3f3 --- /dev/null +++ b/drivers/media/usb/usbvision/Kconfig | |||
@@ -0,0 +1,12 @@ | |||
1 | config VIDEO_USBVISION | ||
2 | tristate "USB video devices based on Nogatech NT1003/1004/1005" | ||
3 | depends on I2C && VIDEO_V4L2 | ||
4 | select VIDEO_TUNER | ||
5 | select VIDEO_SAA711X if VIDEO_HELPER_CHIPS_AUTO | ||
6 | ---help--- | ||
7 | There are more than 50 different USB video devices based on | ||
8 | NT1003/1004/1005 USB Bridges. This driver enables using those | ||
9 | devices. | ||
10 | |||
11 | To compile this driver as a module, choose M here: the | ||
12 | module will be called usbvision. | ||
diff --git a/drivers/media/usb/usbvision/Makefile b/drivers/media/usb/usbvision/Makefile new file mode 100644 index 000000000000..d55c6bd97a35 --- /dev/null +++ b/drivers/media/usb/usbvision/Makefile | |||
@@ -0,0 +1,6 @@ | |||
1 | usbvision-objs := usbvision-core.o usbvision-video.o usbvision-i2c.o usbvision-cards.o | ||
2 | |||
3 | obj-$(CONFIG_VIDEO_USBVISION) += usbvision.o | ||
4 | |||
5 | ccflags-y += -Idrivers/media/video | ||
6 | ccflags-y += -Idrivers/media/tuners | ||
diff --git a/drivers/media/usb/usbvision/usbvision-cards.c b/drivers/media/usb/usbvision/usbvision-cards.c new file mode 100644 index 000000000000..3103d0d020e8 --- /dev/null +++ b/drivers/media/usb/usbvision/usbvision-cards.c | |||
@@ -0,0 +1,1133 @@ | |||
1 | /* | ||
2 | * usbvision-cards.c | ||
3 | * usbvision cards definition file | ||
4 | * | ||
5 | * Copyright (c) 1999-2005 Joerg Heckenbach <joerg@heckenbach-aw.de> | ||
6 | * | ||
7 | * This module is part of usbvision driver project. | ||
8 | * Updates to driver completed by Dwaine P. Garden | ||
9 | * | ||
10 | * This program is free software; you can redistribute it and/or modify | ||
11 | * it under the terms of the GNU General Public License as published by | ||
12 | * the Free Software Foundation; either version 2 of the License, or | ||
13 | * (at your option) any later version. | ||
14 | * | ||
15 | * This program is distributed in the hope that it will be useful, | ||
16 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
17 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
18 | * GNU General Public License for more details. | ||
19 | * | ||
20 | * You should have received a copy of the GNU General Public License | ||
21 | * along with this program; if not, write to the Free Software | ||
22 | * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. | ||
23 | */ | ||
24 | |||
25 | |||
26 | #include <linux/list.h> | ||
27 | #include <linux/module.h> | ||
28 | #include <media/v4l2-dev.h> | ||
29 | #include <media/tuner.h> | ||
30 | #include "usbvision.h" | ||
31 | #include "usbvision-cards.h" | ||
32 | |||
33 | /* Supported Devices: A table for usbvision.c*/ | ||
34 | struct usbvision_device_data_st usbvision_device_data[] = { | ||
35 | [XANBOO] = { | ||
36 | .interface = -1, | ||
37 | .codec = CODEC_SAA7113, | ||
38 | .video_channels = 4, | ||
39 | .video_norm = V4L2_STD_NTSC, | ||
40 | .audio_channels = 1, | ||
41 | .radio = 0, | ||
42 | .vbi = 1, | ||
43 | .tuner = 0, | ||
44 | .tuner_type = 0, | ||
45 | .x_offset = -1, | ||
46 | .y_offset = -1, | ||
47 | .model_string = "Xanboo", | ||
48 | }, | ||
49 | [BELKIN_VIDEOBUS_II] = { | ||
50 | .interface = -1, | ||
51 | .codec = CODEC_SAA7113, | ||
52 | .video_channels = 2, | ||
53 | .video_norm = V4L2_STD_PAL, | ||
54 | .audio_channels = 1, | ||
55 | .radio = 0, | ||
56 | .vbi = 1, | ||
57 | .tuner = 0, | ||
58 | .tuner_type = 0, | ||
59 | .x_offset = 0, | ||
60 | .y_offset = 3, | ||
61 | .dvi_yuv_override = 1, | ||
62 | .dvi_yuv = 7, | ||
63 | .model_string = "Belkin USB VideoBus II Adapter", | ||
64 | }, | ||
65 | [BELKIN_VIDEOBUS] = { | ||
66 | .interface = -1, | ||
67 | .codec = CODEC_SAA7111, | ||
68 | .video_channels = 2, | ||
69 | .video_norm = V4L2_STD_NTSC, | ||
70 | .audio_channels = 1, | ||
71 | .radio = 0, | ||
72 | .vbi = 1, | ||
73 | .tuner = 0, | ||
74 | .tuner_type = 0, | ||
75 | .x_offset = -1, | ||
76 | .y_offset = -1, | ||
77 | .model_string = "Belkin Components USB VideoBus", | ||
78 | }, | ||
79 | [BELKIN_USB_VIDEOBUS_II] = { | ||
80 | .interface = -1, | ||
81 | .codec = CODEC_SAA7113, | ||
82 | .video_channels = 2, | ||
83 | .video_norm = V4L2_STD_NTSC, | ||
84 | .audio_channels = 1, | ||
85 | .radio = 0, | ||
86 | .vbi = 1, | ||
87 | .tuner = 0, | ||
88 | .tuner_type = 0, | ||
89 | .x_offset = 0, | ||
90 | .y_offset = 3, | ||
91 | .dvi_yuv_override = 1, | ||
92 | .dvi_yuv = 7, | ||
93 | .model_string = "Belkin USB VideoBus II", | ||
94 | }, | ||
95 | [ECHOFX_INTERVIEW_LITE] = { | ||
96 | .interface = 0, | ||
97 | .codec = CODEC_SAA7111, | ||
98 | .video_channels = 2, | ||
99 | .video_norm = V4L2_STD_PAL, | ||
100 | .audio_channels = 0, | ||
101 | .radio = 0, | ||
102 | .vbi = 1, | ||
103 | .tuner = 0, | ||
104 | .tuner_type = 0, | ||
105 | .x_offset = -1, | ||
106 | .y_offset = -1, | ||
107 | .dvi_yuv_override = 1, | ||
108 | .dvi_yuv = 7, | ||
109 | .model_string = "echoFX InterView Lite", | ||
110 | }, | ||
111 | [USBGEAR_USBG_V1] = { | ||
112 | .interface = -1, | ||
113 | .codec = CODEC_SAA7111, | ||
114 | .video_channels = 2, | ||
115 | .video_norm = V4L2_STD_NTSC, | ||
116 | .audio_channels = 1, | ||
117 | .radio = 0, | ||
118 | .vbi = 1, | ||
119 | .tuner = 0, | ||
120 | .tuner_type = 0, | ||
121 | .x_offset = -1, | ||
122 | .y_offset = -1, | ||
123 | .model_string = "USBGear USBG-V1 resp. HAMA USB", | ||
124 | }, | ||
125 | [D_LINK_V100] = { | ||
126 | .interface = -1, | ||
127 | .codec = CODEC_SAA7113, | ||
128 | .video_channels = 4, | ||
129 | .video_norm = V4L2_STD_NTSC, | ||
130 | .audio_channels = 0, | ||
131 | .radio = 0, | ||
132 | .vbi = 1, | ||
133 | .tuner = 0, | ||
134 | .tuner_type = 0, | ||
135 | .x_offset = 0, | ||
136 | .y_offset = 3, | ||
137 | .dvi_yuv_override = 1, | ||
138 | .dvi_yuv = 7, | ||
139 | .model_string = "D-Link V100", | ||
140 | }, | ||
141 | [X10_USB_CAMERA] = { | ||
142 | .interface = -1, | ||
143 | .codec = CODEC_SAA7111, | ||
144 | .video_channels = 2, | ||
145 | .video_norm = V4L2_STD_NTSC, | ||
146 | .audio_channels = 1, | ||
147 | .radio = 0, | ||
148 | .vbi = 1, | ||
149 | .tuner = 0, | ||
150 | .tuner_type = 0, | ||
151 | .x_offset = -1, | ||
152 | .y_offset = -1, | ||
153 | .model_string = "X10 USB Camera", | ||
154 | }, | ||
155 | [HPG_WINTV_LIVE_PAL_BG] = { | ||
156 | .interface = -1, | ||
157 | .codec = CODEC_SAA7111, | ||
158 | .video_channels = 2, | ||
159 | .video_norm = V4L2_STD_PAL, | ||
160 | .audio_channels = 1, | ||
161 | .radio = 0, | ||
162 | .vbi = 1, | ||
163 | .tuner = 0, | ||
164 | .tuner_type = 0, | ||
165 | .x_offset = -1, | ||
166 | .y_offset = 3, | ||
167 | .dvi_yuv_override = 1, | ||
168 | .dvi_yuv = 7, | ||
169 | .model_string = "Hauppauge WinTV USB Live (PAL B/G)", | ||
170 | }, | ||
171 | [HPG_WINTV_LIVE_PRO_NTSC_MN] = { | ||
172 | .interface = -1, | ||
173 | .codec = CODEC_SAA7113, | ||
174 | .video_channels = 2, | ||
175 | .video_norm = V4L2_STD_NTSC, | ||
176 | .audio_channels = 0, | ||
177 | .radio = 0, | ||
178 | .vbi = 1, | ||
179 | .tuner = 0, | ||
180 | .tuner_type = 0, | ||
181 | .x_offset = 0, | ||
182 | .y_offset = 3, | ||
183 | .dvi_yuv_override = 1, | ||
184 | .dvi_yuv = 7, | ||
185 | .model_string = "Hauppauge WinTV USB Live Pro (NTSC M/N)", | ||
186 | }, | ||
187 | [ZORAN_PMD_NOGATECH] = { | ||
188 | .interface = -1, | ||
189 | .codec = CODEC_SAA7113, | ||
190 | .video_channels = 2, | ||
191 | .video_norm = V4L2_STD_PAL, | ||
192 | .audio_channels = 2, | ||
193 | .radio = 0, | ||
194 | .vbi = 1, | ||
195 | .tuner = 0, | ||
196 | .tuner_type = 0, | ||
197 | .x_offset = 0, | ||
198 | .y_offset = 3, | ||
199 | .dvi_yuv_override = 1, | ||
200 | .dvi_yuv = 7, | ||
201 | .model_string = "Zoran Co. PMD (Nogatech) AV-grabber Manhattan", | ||
202 | }, | ||
203 | [NOGATECH_USB_TV_NTSC_FM] = { | ||
204 | .interface = -1, | ||
205 | .codec = CODEC_SAA7111, | ||
206 | .video_channels = 3, | ||
207 | .video_norm = V4L2_STD_NTSC, | ||
208 | .audio_channels = 1, | ||
209 | .radio = 1, | ||
210 | .vbi = 1, | ||
211 | .tuner = 1, | ||
212 | .tuner_type = TUNER_PHILIPS_NTSC_M, | ||
213 | .x_offset = -1, | ||
214 | .y_offset = 20, | ||
215 | .model_string = "Nogatech USB-TV (NTSC) FM", | ||
216 | }, | ||
217 | [PNY_USB_TV_NTSC_FM] = { | ||
218 | .interface = -1, | ||
219 | .codec = CODEC_SAA7111, | ||
220 | .video_channels = 3, | ||
221 | .video_norm = V4L2_STD_NTSC, | ||
222 | .audio_channels = 1, | ||
223 | .radio = 1, | ||
224 | .vbi = 1, | ||
225 | .tuner = 1, | ||
226 | .tuner_type = TUNER_PHILIPS_NTSC_M, | ||
227 | .x_offset = -1, | ||
228 | .y_offset = 20, | ||
229 | .model_string = "PNY USB-TV (NTSC) FM", | ||
230 | }, | ||
231 | [PV_PLAYTV_USB_PRO_PAL_FM] = { | ||
232 | .interface = 0, | ||
233 | .codec = CODEC_SAA7113, | ||
234 | .video_channels = 3, | ||
235 | .video_norm = V4L2_STD_PAL, | ||
236 | .audio_channels = 1, | ||
237 | .radio = 1, | ||
238 | .vbi = 1, | ||
239 | .tuner = 1, | ||
240 | .tuner_type = TUNER_PHILIPS_PAL, | ||
241 | .x_offset = 0, | ||
242 | .y_offset = 3, | ||
243 | .dvi_yuv_override = 1, | ||
244 | .dvi_yuv = 7, | ||
245 | .model_string = "PixelView PlayTv-USB PRO (PAL) FM", | ||
246 | }, | ||
247 | [ZT_721] = { | ||
248 | .interface = 0, | ||
249 | .codec = CODEC_SAA7113, | ||
250 | .video_channels = 3, | ||
251 | .video_norm = V4L2_STD_PAL, | ||
252 | .audio_channels = 1, | ||
253 | .radio = 1, | ||
254 | .vbi = 1, | ||
255 | .tuner = 1, | ||
256 | .tuner_type = TUNER_PHILIPS_PAL, | ||
257 | .x_offset = 0, | ||
258 | .y_offset = 3, | ||
259 | .dvi_yuv_override = 1, | ||
260 | .dvi_yuv = 7, | ||
261 | .model_string = "ZTV ZT-721 2.4GHz USB A/V Receiver", | ||
262 | }, | ||
263 | [HPG_WINTV_NTSC_MN] = { | ||
264 | .interface = -1, | ||
265 | .codec = CODEC_SAA7111, | ||
266 | .video_channels = 3, | ||
267 | .video_norm = V4L2_STD_NTSC, | ||
268 | .audio_channels = 1, | ||
269 | .radio = 0, | ||
270 | .vbi = 1, | ||
271 | .tuner = 1, | ||
272 | .tuner_type = TUNER_PHILIPS_NTSC_M, | ||
273 | .x_offset = -1, | ||
274 | .y_offset = 20, | ||
275 | .model_string = "Hauppauge WinTV USB (NTSC M/N)", | ||
276 | }, | ||
277 | [HPG_WINTV_PAL_BG] = { | ||
278 | .interface = -1, | ||
279 | .codec = CODEC_SAA7111, | ||
280 | .video_channels = 3, | ||
281 | .video_norm = V4L2_STD_PAL, | ||
282 | .audio_channels = 1, | ||
283 | .radio = 0, | ||
284 | .vbi = 1, | ||
285 | .tuner = 1, | ||
286 | .tuner_type = TUNER_PHILIPS_PAL, | ||
287 | .x_offset = -1, | ||
288 | .y_offset = -1, | ||
289 | .model_string = "Hauppauge WinTV USB (PAL B/G)", | ||
290 | }, | ||
291 | [HPG_WINTV_PAL_I] = { | ||
292 | .interface = -1, | ||
293 | .codec = CODEC_SAA7111, | ||
294 | .video_channels = 3, | ||
295 | .video_norm = V4L2_STD_PAL, | ||
296 | .audio_channels = 1, | ||
297 | .radio = 0, | ||
298 | .vbi = 1, | ||
299 | .tuner = 1, | ||
300 | .tuner_type = TUNER_PHILIPS_PAL, | ||
301 | .x_offset = -1, | ||
302 | .y_offset = -1, | ||
303 | .model_string = "Hauppauge WinTV USB (PAL I)", | ||
304 | }, | ||
305 | [HPG_WINTV_PAL_SECAM_L] = { | ||
306 | .interface = -1, | ||
307 | .codec = CODEC_SAA7111, | ||
308 | .video_channels = 3, | ||
309 | .video_norm = V4L2_STD_SECAM, | ||
310 | .audio_channels = 1, | ||
311 | .radio = 0, | ||
312 | .vbi = 1, | ||
313 | .tuner = 1, | ||
314 | .tuner_type = TUNER_PHILIPS_SECAM, | ||
315 | .x_offset = 0x80, | ||
316 | .y_offset = 0x16, | ||
317 | .model_string = "Hauppauge WinTV USB (PAL/SECAM L)", | ||
318 | }, | ||
319 | [HPG_WINTV_PAL_D_K] = { | ||
320 | .interface = -1, | ||
321 | .codec = CODEC_SAA7111, | ||
322 | .video_channels = 3, | ||
323 | .video_norm = V4L2_STD_PAL, | ||
324 | .audio_channels = 1, | ||
325 | .radio = 0, | ||
326 | .vbi = 1, | ||
327 | .tuner = 1, | ||
328 | .tuner_type = TUNER_PHILIPS_PAL, | ||
329 | .x_offset = -1, | ||
330 | .y_offset = -1, | ||
331 | .model_string = "Hauppauge WinTV USB (PAL D/K)", | ||
332 | }, | ||
333 | [HPG_WINTV_NTSC_FM] = { | ||
334 | .interface = -1, | ||
335 | .codec = CODEC_SAA7111, | ||
336 | .video_channels = 3, | ||
337 | .video_norm = V4L2_STD_NTSC, | ||
338 | .audio_channels = 1, | ||
339 | .radio = 1, | ||
340 | .vbi = 1, | ||
341 | .tuner = 1, | ||
342 | .tuner_type = TUNER_PHILIPS_NTSC_M, | ||
343 | .x_offset = -1, | ||
344 | .y_offset = -1, | ||
345 | .model_string = "Hauppauge WinTV USB (NTSC FM)", | ||
346 | }, | ||
347 | [HPG_WINTV_PAL_BG_FM] = { | ||
348 | .interface = -1, | ||
349 | .codec = CODEC_SAA7111, | ||
350 | .video_channels = 3, | ||
351 | .video_norm = V4L2_STD_PAL, | ||
352 | .audio_channels = 1, | ||
353 | .radio = 1, | ||
354 | .vbi = 1, | ||
355 | .tuner = 1, | ||
356 | .tuner_type = TUNER_PHILIPS_PAL, | ||
357 | .x_offset = -1, | ||
358 | .y_offset = -1, | ||
359 | .model_string = "Hauppauge WinTV USB (PAL B/G FM)", | ||
360 | }, | ||
361 | [HPG_WINTV_PAL_I_FM] = { | ||
362 | .interface = -1, | ||
363 | .codec = CODEC_SAA7111, | ||
364 | .video_channels = 3, | ||
365 | .video_norm = V4L2_STD_PAL, | ||
366 | .audio_channels = 1, | ||
367 | .radio = 1, | ||
368 | .vbi = 1, | ||
369 | .tuner = 1, | ||
370 | .tuner_type = TUNER_PHILIPS_PAL, | ||
371 | .x_offset = -1, | ||
372 | .y_offset = -1, | ||
373 | .model_string = "Hauppauge WinTV USB (PAL I FM)", | ||
374 | }, | ||
375 | [HPG_WINTV_PAL_D_K_FM] = { | ||
376 | .interface = -1, | ||
377 | .codec = CODEC_SAA7111, | ||
378 | .video_channels = 3, | ||
379 | .video_norm = V4L2_STD_PAL, | ||
380 | .audio_channels = 1, | ||
381 | .radio = 1, | ||
382 | .vbi = 1, | ||
383 | .tuner = 1, | ||
384 | .tuner_type = TUNER_PHILIPS_PAL, | ||
385 | .x_offset = -1, | ||
386 | .y_offset = -1, | ||
387 | .model_string = "Hauppauge WinTV USB (PAL D/K FM)", | ||
388 | }, | ||
389 | [HPG_WINTV_PRO_NTSC_MN] = { | ||
390 | .interface = 0, | ||
391 | .codec = CODEC_SAA7113, | ||
392 | .video_channels = 3, | ||
393 | .video_norm = V4L2_STD_NTSC, | ||
394 | .audio_channels = 1, | ||
395 | .radio = 1, | ||
396 | .vbi = 1, | ||
397 | .tuner = 1, | ||
398 | .tuner_type = TUNER_MICROTUNE_4049FM5, | ||
399 | .x_offset = 0, | ||
400 | .y_offset = 3, | ||
401 | .dvi_yuv_override = 1, | ||
402 | .dvi_yuv = 7, | ||
403 | .model_string = "Hauppauge WinTV USB Pro (NTSC M/N)", | ||
404 | }, | ||
405 | [HPG_WINTV_PRO_NTSC_MN_V2] = { | ||
406 | .interface = 0, | ||
407 | .codec = CODEC_SAA7113, | ||
408 | .video_channels = 3, | ||
409 | .video_norm = V4L2_STD_NTSC, | ||
410 | .audio_channels = 1, | ||
411 | .radio = 1, | ||
412 | .vbi = 1, | ||
413 | .tuner = 1, | ||
414 | .tuner_type = TUNER_MICROTUNE_4049FM5, | ||
415 | .x_offset = 0, | ||
416 | .y_offset = 3, | ||
417 | .dvi_yuv_override = 1, | ||
418 | .dvi_yuv = 7, | ||
419 | .model_string = "Hauppauge WinTV USB Pro (NTSC M/N) V2", | ||
420 | }, | ||
421 | [HPG_WINTV_PRO_PAL] = { | ||
422 | .interface = 0, | ||
423 | .codec = CODEC_SAA7113, | ||
424 | .video_channels = 3, | ||
425 | .video_norm = V4L2_STD_PAL, | ||
426 | .audio_channels = 1, | ||
427 | .radio = 0, | ||
428 | .vbi = 1, | ||
429 | .tuner = 1, | ||
430 | .tuner_type = TUNER_PHILIPS_FM1216ME_MK3, | ||
431 | .x_offset = 0, | ||
432 | .y_offset = 3, | ||
433 | .dvi_yuv_override = 1, | ||
434 | .dvi_yuv = 7, | ||
435 | .model_string = "Hauppauge WinTV USB Pro (PAL/SECAM B/G/I/D/K/L)", | ||
436 | }, | ||
437 | [HPG_WINTV_PRO_NTSC_MN_V3] = { | ||
438 | .interface = 0, | ||
439 | .codec = CODEC_SAA7113, | ||
440 | .video_channels = 3, | ||
441 | .video_norm = V4L2_STD_NTSC, | ||
442 | .audio_channels = 1, | ||
443 | .radio = 1, | ||
444 | .vbi = 1, | ||
445 | .tuner = 1, | ||
446 | .tuner_type = TUNER_PHILIPS_NTSC_M, | ||
447 | .x_offset = 0, | ||
448 | .y_offset = 3, | ||
449 | .dvi_yuv_override = 1, | ||
450 | .dvi_yuv = 7, | ||
451 | .model_string = "Hauppauge WinTV USB Pro (NTSC M/N) V3", | ||
452 | }, | ||
453 | [HPG_WINTV_PRO_PAL_BG] = { | ||
454 | .interface = 0, | ||
455 | .codec = CODEC_SAA7113, | ||
456 | .video_channels = 3, | ||
457 | .video_norm = V4L2_STD_PAL, | ||
458 | .audio_channels = 1, | ||
459 | .radio = 0, | ||
460 | .vbi = 1, | ||
461 | .tuner = 1, | ||
462 | .tuner_type = TUNER_PHILIPS_PAL, | ||
463 | .x_offset = 0, | ||
464 | .y_offset = 3, | ||
465 | .dvi_yuv_override = 1, | ||
466 | .dvi_yuv = 7, | ||
467 | .model_string = "Hauppauge WinTV USB Pro (PAL B/G)", | ||
468 | }, | ||
469 | [HPG_WINTV_PRO_PAL_I] = { | ||
470 | .interface = 0, | ||
471 | .codec = CODEC_SAA7113, | ||
472 | .video_channels = 3, | ||
473 | .video_norm = V4L2_STD_PAL, | ||
474 | .audio_channels = 1, | ||
475 | .radio = 0, | ||
476 | .vbi = 1, | ||
477 | .tuner = 1, | ||
478 | .tuner_type = TUNER_PHILIPS_PAL, | ||
479 | .x_offset = 0, | ||
480 | .y_offset = 3, | ||
481 | .dvi_yuv_override = 1, | ||
482 | .dvi_yuv = 7, | ||
483 | .model_string = "Hauppauge WinTV USB Pro (PAL I)", | ||
484 | }, | ||
485 | [HPG_WINTV_PRO_PAL_SECAM_L] = { | ||
486 | .interface = -1, | ||
487 | .codec = CODEC_SAA7113, | ||
488 | .video_channels = 3, | ||
489 | .video_norm = V4L2_STD_SECAM, | ||
490 | .audio_channels = 1, | ||
491 | .radio = 0, | ||
492 | .vbi = 1, | ||
493 | .tuner = 1, | ||
494 | .tuner_type = TUNER_PHILIPS_SECAM, | ||
495 | .x_offset = 0, | ||
496 | .y_offset = 3, | ||
497 | .dvi_yuv_override = 1, | ||
498 | .dvi_yuv = 7, | ||
499 | .model_string = "Hauppauge WinTV USB Pro (PAL/SECAM L)", | ||
500 | }, | ||
501 | [HPG_WINTV_PRO_PAL_D_K] = { | ||
502 | .interface = -1, | ||
503 | .codec = CODEC_SAA7113, | ||
504 | .video_channels = 3, | ||
505 | .video_norm = V4L2_STD_PAL, | ||
506 | .audio_channels = 1, | ||
507 | .radio = 0, | ||
508 | .vbi = 1, | ||
509 | .tuner = 1, | ||
510 | .tuner_type = TUNER_PHILIPS_PAL, | ||
511 | .x_offset = 0, | ||
512 | .y_offset = 3, | ||
513 | .dvi_yuv_override = 1, | ||
514 | .dvi_yuv = 7, | ||
515 | .model_string = "Hauppauge WinTV USB Pro (PAL D/K)", | ||
516 | }, | ||
517 | [HPG_WINTV_PRO_PAL_SECAM] = { | ||
518 | .interface = -1, | ||
519 | .codec = CODEC_SAA7113, | ||
520 | .video_channels = 3, | ||
521 | .video_norm = V4L2_STD_SECAM, | ||
522 | .audio_channels = 1, | ||
523 | .radio = 0, | ||
524 | .vbi = 1, | ||
525 | .tuner = 1, | ||
526 | .tuner_type = TUNER_PHILIPS_SECAM, | ||
527 | .x_offset = 0, | ||
528 | .y_offset = 3, | ||
529 | .dvi_yuv_override = 1, | ||
530 | .dvi_yuv = 7, | ||
531 | .model_string = "Hauppauge WinTV USB Pro (PAL/SECAM BGDK/I/L)", | ||
532 | }, | ||
533 | [HPG_WINTV_PRO_PAL_SECAM_V2] = { | ||
534 | .interface = -1, | ||
535 | .codec = CODEC_SAA7113, | ||
536 | .video_channels = 3, | ||
537 | .video_norm = V4L2_STD_SECAM, | ||
538 | .audio_channels = 1, | ||
539 | .radio = 0, | ||
540 | .vbi = 1, | ||
541 | .tuner = 1, | ||
542 | .tuner_type = TUNER_PHILIPS_SECAM, | ||
543 | .x_offset = 0, | ||
544 | .y_offset = 3, | ||
545 | .dvi_yuv_override = 1, | ||
546 | .dvi_yuv = 7, | ||
547 | .model_string = "Hauppauge WinTV USB Pro (PAL/SECAM BGDK/I/L) V2", | ||
548 | }, | ||
549 | [HPG_WINTV_PRO_PAL_BG_V2] = { | ||
550 | .interface = -1, | ||
551 | .codec = CODEC_SAA7113, | ||
552 | .video_channels = 3, | ||
553 | .video_norm = V4L2_STD_PAL, | ||
554 | .audio_channels = 1, | ||
555 | .radio = 0, | ||
556 | .vbi = 1, | ||
557 | .tuner = 1, | ||
558 | .tuner_type = TUNER_ALPS_TSBE1_PAL, | ||
559 | .x_offset = 0, | ||
560 | .y_offset = 3, | ||
561 | .dvi_yuv_override = 1, | ||
562 | .dvi_yuv = 7, | ||
563 | .model_string = "Hauppauge WinTV USB Pro (PAL B/G) V2", | ||
564 | }, | ||
565 | [HPG_WINTV_PRO_PAL_BG_D_K] = { | ||
566 | .interface = -1, | ||
567 | .codec = CODEC_SAA7113, | ||
568 | .video_channels = 3, | ||
569 | .video_norm = V4L2_STD_PAL, | ||
570 | .audio_channels = 1, | ||
571 | .radio = 0, | ||
572 | .vbi = 1, | ||
573 | .tuner = 1, | ||
574 | .tuner_type = TUNER_ALPS_TSBE1_PAL, | ||
575 | .x_offset = 0, | ||
576 | .y_offset = 3, | ||
577 | .dvi_yuv_override = 1, | ||
578 | .dvi_yuv = 7, | ||
579 | .model_string = "Hauppauge WinTV USB Pro (PAL B/G,D/K)", | ||
580 | }, | ||
581 | [HPG_WINTV_PRO_PAL_I_D_K] = { | ||
582 | .interface = -1, | ||
583 | .codec = CODEC_SAA7113, | ||
584 | .video_channels = 3, | ||
585 | .video_norm = V4L2_STD_PAL, | ||
586 | .audio_channels = 1, | ||
587 | .radio = 0, | ||
588 | .vbi = 1, | ||
589 | .tuner = 1, | ||
590 | .tuner_type = TUNER_LG_PAL_NEW_TAPC, | ||
591 | .x_offset = 0, | ||
592 | .y_offset = 3, | ||
593 | .dvi_yuv_override = 1, | ||
594 | .dvi_yuv = 7, | ||
595 | .model_string = "Hauppauge WinTV USB Pro (PAL I,D/K)", | ||
596 | }, | ||
597 | [HPG_WINTV_PRO_NTSC_MN_FM] = { | ||
598 | .interface = -1, | ||
599 | .codec = CODEC_SAA7113, | ||
600 | .video_channels = 3, | ||
601 | .video_norm = V4L2_STD_NTSC, | ||
602 | .audio_channels = 1, | ||
603 | .radio = 1, | ||
604 | .vbi = 1, | ||
605 | .tuner = 1, | ||
606 | .tuner_type = TUNER_PHILIPS_NTSC_M, | ||
607 | .x_offset = 0, | ||
608 | .y_offset = 3, | ||
609 | .dvi_yuv_override = 1, | ||
610 | .dvi_yuv = 7, | ||
611 | .model_string = "Hauppauge WinTV USB Pro (NTSC M/N FM)", | ||
612 | }, | ||
613 | [HPG_WINTV_PRO_PAL_BG_FM] = { | ||
614 | .interface = 0, | ||
615 | .codec = CODEC_SAA7113, | ||
616 | .video_channels = 3, | ||
617 | .video_norm = V4L2_STD_PAL, | ||
618 | .audio_channels = 1, | ||
619 | .radio = 1, | ||
620 | .vbi = 1, | ||
621 | .tuner = 1, | ||
622 | .tuner_type = TUNER_PHILIPS_PAL, | ||
623 | .x_offset = 0, | ||
624 | .y_offset = 3, | ||
625 | .dvi_yuv_override = 1, | ||
626 | .dvi_yuv = 7, | ||
627 | .model_string = "Hauppauge WinTV USB Pro (PAL B/G FM)", | ||
628 | }, | ||
629 | [HPG_WINTV_PRO_PAL_I_FM] = { | ||
630 | .interface = 0, | ||
631 | .codec = CODEC_SAA7113, | ||
632 | .video_channels = 3, | ||
633 | .video_norm = V4L2_STD_PAL, | ||
634 | .audio_channels = 1, | ||
635 | .radio = 1, | ||
636 | .vbi = 1, | ||
637 | .tuner = 1, | ||
638 | .tuner_type = TUNER_PHILIPS_PAL, | ||
639 | .x_offset = 0, | ||
640 | .y_offset = 3, | ||
641 | .dvi_yuv_override = 1, | ||
642 | .dvi_yuv = 7, | ||
643 | .model_string = "Hauppauge WinTV USB Pro (PAL I FM)", | ||
644 | }, | ||
645 | [HPG_WINTV_PRO_PAL_D_K_FM] = { | ||
646 | .interface = 0, | ||
647 | .codec = CODEC_SAA7113, | ||
648 | .video_channels = 3, | ||
649 | .video_norm = V4L2_STD_PAL, | ||
650 | .audio_channels = 1, | ||
651 | .radio = 1, | ||
652 | .vbi = 1, | ||
653 | .tuner = 1, | ||
654 | .tuner_type = TUNER_PHILIPS_PAL, | ||
655 | .x_offset = 0, | ||
656 | .y_offset = 3, | ||
657 | .dvi_yuv_override = 1, | ||
658 | .dvi_yuv = 7, | ||
659 | .model_string = "Hauppauge WinTV USB Pro (PAL D/K FM)", | ||
660 | }, | ||
661 | [HPG_WINTV_PRO_TEMIC_PAL_FM] = { | ||
662 | .interface = 0, | ||
663 | .codec = CODEC_SAA7113, | ||
664 | .video_channels = 3, | ||
665 | .video_norm = V4L2_STD_PAL, | ||
666 | .audio_channels = 1, | ||
667 | .radio = 1, | ||
668 | .vbi = 1, | ||
669 | .tuner = 1, | ||
670 | .tuner_type = TUNER_MICROTUNE_4049FM5, | ||
671 | .x_offset = 0, | ||
672 | .y_offset = 3, | ||
673 | .dvi_yuv_override = 1, | ||
674 | .dvi_yuv = 7, | ||
675 | .model_string = "Hauppauge WinTV USB Pro (Temic PAL/SECAM B/G/I/D/K/L FM)", | ||
676 | }, | ||
677 | [HPG_WINTV_PRO_TEMIC_PAL_BG_FM] = { | ||
678 | .interface = 0, | ||
679 | .codec = CODEC_SAA7113, | ||
680 | .video_channels = 3, | ||
681 | .video_norm = V4L2_STD_PAL, | ||
682 | .audio_channels = 1, | ||
683 | .radio = 1, | ||
684 | .vbi = 1, | ||
685 | .tuner = 1, | ||
686 | .tuner_type = TUNER_MICROTUNE_4049FM5, | ||
687 | .x_offset = 0, | ||
688 | .y_offset = 3, | ||
689 | .dvi_yuv_override = 1, | ||
690 | .dvi_yuv = 7, | ||
691 | .model_string = "Hauppauge WinTV USB Pro (Temic PAL B/G FM)", | ||
692 | }, | ||
693 | [HPG_WINTV_PRO_PAL_FM] = { | ||
694 | .interface = 0, | ||
695 | .codec = CODEC_SAA7113, | ||
696 | .video_channels = 3, | ||
697 | .video_norm = V4L2_STD_PAL, | ||
698 | .audio_channels = 1, | ||
699 | .radio = 1, | ||
700 | .vbi = 1, | ||
701 | .tuner = 1, | ||
702 | .tuner_type = TUNER_PHILIPS_FM1216ME_MK3, | ||
703 | .x_offset = 0, | ||
704 | .y_offset = 3, | ||
705 | .dvi_yuv_override = 1, | ||
706 | .dvi_yuv = 7, | ||
707 | .model_string = "Hauppauge WinTV USB Pro (PAL/SECAM B/G/I/D/K/L FM)", | ||
708 | }, | ||
709 | [HPG_WINTV_PRO_NTSC_MN_FM_V2] = { | ||
710 | .interface = 0, | ||
711 | .codec = CODEC_SAA7113, | ||
712 | .video_channels = 3, | ||
713 | .video_norm = V4L2_STD_NTSC, | ||
714 | .audio_channels = 1, | ||
715 | .radio = 1, | ||
716 | .vbi = 1, | ||
717 | .tuner = 1, | ||
718 | .tuner_type = TUNER_PHILIPS_NTSC_M, | ||
719 | .x_offset = 0, | ||
720 | .y_offset = 3, | ||
721 | .dvi_yuv_override = 1, | ||
722 | .dvi_yuv = 7, | ||
723 | .model_string = "Hauppauge WinTV USB Pro (NTSC M/N FM) V2", | ||
724 | }, | ||
725 | [CAMTEL_TVB330] = { | ||
726 | .interface = -1, | ||
727 | .codec = CODEC_SAA7113, | ||
728 | .video_channels = 3, | ||
729 | .video_norm = V4L2_STD_NTSC, | ||
730 | .audio_channels = 1, | ||
731 | .radio = 1, | ||
732 | .vbi = 1, | ||
733 | .tuner = 1, | ||
734 | .tuner_type = TUNER_PHILIPS_NTSC_M, | ||
735 | .x_offset = 5, | ||
736 | .y_offset = 5, | ||
737 | .model_string = "Camtel Technology USB TV Genie Pro FM Model TVB330", | ||
738 | }, | ||
739 | [DIGITAL_VIDEO_CREATOR_I] = { | ||
740 | .interface = -1, | ||
741 | .codec = CODEC_SAA7113, | ||
742 | .video_channels = 2, | ||
743 | .video_norm = V4L2_STD_PAL, | ||
744 | .audio_channels = 0, | ||
745 | .radio = 0, | ||
746 | .vbi = 1, | ||
747 | .tuner = 0, | ||
748 | .tuner_type = 0, | ||
749 | .x_offset = 0, | ||
750 | .y_offset = 3, | ||
751 | .dvi_yuv_override = 1, | ||
752 | .dvi_yuv = 7, | ||
753 | .model_string = "Digital Video Creator I", | ||
754 | }, | ||
755 | [GLOBAL_VILLAGE_GV_007_NTSC] = { | ||
756 | .interface = -1, | ||
757 | .codec = CODEC_SAA7111, | ||
758 | .video_channels = 2, | ||
759 | .video_norm = V4L2_STD_NTSC, | ||
760 | .audio_channels = 0, | ||
761 | .radio = 0, | ||
762 | .vbi = 1, | ||
763 | .tuner = 0, | ||
764 | .tuner_type = 0, | ||
765 | .x_offset = 82, | ||
766 | .y_offset = 20, | ||
767 | .dvi_yuv_override = 1, | ||
768 | .dvi_yuv = 7, | ||
769 | .model_string = "Global Village GV-007 (NTSC)", | ||
770 | }, | ||
771 | [DAZZLE_DVC_50_REV_1_NTSC] = { | ||
772 | .interface = 0, | ||
773 | .codec = CODEC_SAA7113, | ||
774 | .video_channels = 2, | ||
775 | .video_norm = V4L2_STD_NTSC, | ||
776 | .audio_channels = 0, | ||
777 | .radio = 0, | ||
778 | .vbi = 1, | ||
779 | .tuner = 0, | ||
780 | .tuner_type = 0, | ||
781 | .x_offset = 0, | ||
782 | .y_offset = 3, | ||
783 | .dvi_yuv_override = 1, | ||
784 | .dvi_yuv = 7, | ||
785 | .model_string = "Dazzle Fusion Model DVC-50 Rev 1 (NTSC)", | ||
786 | }, | ||
787 | [DAZZLE_DVC_80_REV_1_PAL] = { | ||
788 | .interface = 0, | ||
789 | .codec = CODEC_SAA7113, | ||
790 | .video_channels = 2, | ||
791 | .video_norm = V4L2_STD_PAL, | ||
792 | .audio_channels = 0, | ||
793 | .radio = 0, | ||
794 | .vbi = 1, | ||
795 | .tuner = 0, | ||
796 | .tuner_type = 0, | ||
797 | .x_offset = 0, | ||
798 | .y_offset = 3, | ||
799 | .dvi_yuv_override = 1, | ||
800 | .dvi_yuv = 7, | ||
801 | .model_string = "Dazzle Fusion Model DVC-80 Rev 1 (PAL)", | ||
802 | }, | ||
803 | [DAZZLE_DVC_90_REV_1_SECAM] = { | ||
804 | .interface = 0, | ||
805 | .codec = CODEC_SAA7113, | ||
806 | .video_channels = 2, | ||
807 | .video_norm = V4L2_STD_SECAM, | ||
808 | .audio_channels = 0, | ||
809 | .radio = 0, | ||
810 | .vbi = 1, | ||
811 | .tuner = 0, | ||
812 | .tuner_type = 0, | ||
813 | .x_offset = 0, | ||
814 | .y_offset = 3, | ||
815 | .dvi_yuv_override = 1, | ||
816 | .dvi_yuv = 7, | ||
817 | .model_string = "Dazzle Fusion Model DVC-90 Rev 1 (SECAM)", | ||
818 | }, | ||
819 | [ESKAPE_LABS_MYTV2GO] = { | ||
820 | .interface = 0, | ||
821 | .codec = CODEC_SAA7113, | ||
822 | .video_channels = 2, | ||
823 | .video_norm = V4L2_STD_PAL, | ||
824 | .audio_channels = 1, | ||
825 | .radio = 1, | ||
826 | .vbi = 1, | ||
827 | .tuner = 1, | ||
828 | .tuner_type = TUNER_PHILIPS_FM1216ME_MK3, | ||
829 | .x_offset = 0, | ||
830 | .y_offset = 3, | ||
831 | .dvi_yuv_override = 1, | ||
832 | .dvi_yuv = 7, | ||
833 | .model_string = "Eskape Labs MyTV2Go", | ||
834 | }, | ||
835 | [PINNA_PCTV_USB_PAL] = { | ||
836 | .interface = -1, | ||
837 | .codec = CODEC_SAA7111, | ||
838 | .video_channels = 3, | ||
839 | .video_norm = V4L2_STD_PAL, | ||
840 | .audio_channels = 1, | ||
841 | .radio = 0, | ||
842 | .vbi = 0, | ||
843 | .tuner = 1, | ||
844 | .tuner_type = TUNER_TEMIC_4066FY5_PAL_I, | ||
845 | .x_offset = -1, | ||
846 | .y_offset = -1, | ||
847 | .model_string = "Pinnacle Studio PCTV USB (PAL)", | ||
848 | }, | ||
849 | [PINNA_PCTV_USB_SECAM] = { | ||
850 | .interface = -1, | ||
851 | .codec = CODEC_SAA7111, | ||
852 | .video_channels = 3, | ||
853 | .video_norm = V4L2_STD_SECAM, | ||
854 | .audio_channels = 1, | ||
855 | .radio = 0, | ||
856 | .vbi = 1, | ||
857 | .tuner = 1, | ||
858 | .tuner_type = TUNER_PHILIPS_SECAM, | ||
859 | .x_offset = -1, | ||
860 | .y_offset = -1, | ||
861 | .model_string = "Pinnacle Studio PCTV USB (SECAM)", | ||
862 | }, | ||
863 | [PINNA_PCTV_USB_PAL_FM] = { | ||
864 | .interface = -1, | ||
865 | .codec = CODEC_SAA7111, | ||
866 | .video_channels = 3, | ||
867 | .video_norm = V4L2_STD_PAL, | ||
868 | .audio_channels = 1, | ||
869 | .radio = 1, | ||
870 | .vbi = 1, | ||
871 | .tuner = 1, | ||
872 | .tuner_type = TUNER_PHILIPS_PAL, | ||
873 | .x_offset = 128, | ||
874 | .y_offset = 23, | ||
875 | .model_string = "Pinnacle Studio PCTV USB (PAL) FM", | ||
876 | }, | ||
877 | [MIRO_PCTV_USB] = { | ||
878 | .interface = -1, | ||
879 | .codec = CODEC_SAA7111, | ||
880 | .video_channels = 3, | ||
881 | .video_norm = V4L2_STD_PAL, | ||
882 | .audio_channels = 1, | ||
883 | .radio = 0, | ||
884 | .vbi = 1, | ||
885 | .tuner = 1, | ||
886 | .tuner_type = TUNER_PHILIPS_PAL, | ||
887 | .x_offset = -1, | ||
888 | .y_offset = -1, | ||
889 | .model_string = "Miro PCTV USB", | ||
890 | }, | ||
891 | [PINNA_PCTV_USB_NTSC_FM] = { | ||
892 | .interface = -1, | ||
893 | .codec = CODEC_SAA7111, | ||
894 | .video_channels = 3, | ||
895 | .video_norm = V4L2_STD_NTSC, | ||
896 | .audio_channels = 1, | ||
897 | .radio = 1, | ||
898 | .vbi = 1, | ||
899 | .tuner = 1, | ||
900 | .tuner_type = TUNER_PHILIPS_NTSC_M, | ||
901 | .x_offset = -1, | ||
902 | .y_offset = -1, | ||
903 | .model_string = "Pinnacle Studio PCTV USB (NTSC) FM", | ||
904 | }, | ||
905 | [PINNA_PCTV_USB_NTSC_FM_V3] = { | ||
906 | .interface = -1, | ||
907 | .codec = CODEC_SAA7111, | ||
908 | .video_channels = 3, | ||
909 | .video_norm = V4L2_STD_NTSC, | ||
910 | .audio_channels = 1, | ||
911 | .radio = 1, | ||
912 | .vbi = 1, | ||
913 | .tuner = 1, | ||
914 | .tuner_type = TUNER_PHILIPS_NTSC_M, | ||
915 | .x_offset = -1, | ||
916 | .y_offset = -1, | ||
917 | .model_string = "Pinnacle Studio PCTV USB (NTSC) FM V3", | ||
918 | }, | ||
919 | [PINNA_PCTV_USB_PAL_FM_V2] = { | ||
920 | .interface = -1, | ||
921 | .codec = CODEC_SAA7113, | ||
922 | .video_channels = 3, | ||
923 | .video_norm = V4L2_STD_PAL, | ||
924 | .audio_channels = 1, | ||
925 | .radio = 1, | ||
926 | .vbi = 1, | ||
927 | .tuner = 1, | ||
928 | .tuner_type = TUNER_TEMIC_4009FR5_PAL, | ||
929 | .x_offset = 0, | ||
930 | .y_offset = 3, | ||
931 | .dvi_yuv_override = 1, | ||
932 | .dvi_yuv = 7, | ||
933 | .model_string = "Pinnacle Studio PCTV USB (PAL) FM V2", | ||
934 | }, | ||
935 | [PINNA_PCTV_USB_NTSC_FM_V2] = { | ||
936 | .interface = -1, | ||
937 | .codec = CODEC_SAA7111, | ||
938 | .video_channels = 3, | ||
939 | .video_norm = V4L2_STD_NTSC, | ||
940 | .audio_channels = 1, | ||
941 | .radio = 1, | ||
942 | .vbi = 1, | ||
943 | .tuner = 1, | ||
944 | .tuner_type = TUNER_TEMIC_4039FR5_NTSC, | ||
945 | .x_offset = 0, | ||
946 | .y_offset = 3, | ||
947 | .dvi_yuv_override = 1, | ||
948 | .dvi_yuv = 7, | ||
949 | .model_string = "Pinnacle Studio PCTV USB (NTSC) FM V2", | ||
950 | }, | ||
951 | [PINNA_PCTV_USB_PAL_FM_V3] = { | ||
952 | .interface = -1, | ||
953 | .codec = CODEC_SAA7113, | ||
954 | .video_channels = 3, | ||
955 | .video_norm = V4L2_STD_PAL, | ||
956 | .audio_channels = 1, | ||
957 | .radio = 1, | ||
958 | .vbi = 1, | ||
959 | .tuner = 1, | ||
960 | .tuner_type = TUNER_TEMIC_4009FR5_PAL, | ||
961 | .x_offset = 0, | ||
962 | .y_offset = 3, | ||
963 | .dvi_yuv_override = 1, | ||
964 | .dvi_yuv = 7, | ||
965 | .model_string = "Pinnacle Studio PCTV USB (PAL) FM V3", | ||
966 | }, | ||
967 | [PINNA_LINX_VD_IN_CAB_NTSC] = { | ||
968 | .interface = -1, | ||
969 | .codec = CODEC_SAA7113, | ||
970 | .video_channels = 2, | ||
971 | .video_norm = V4L2_STD_NTSC, | ||
972 | .audio_channels = 1, | ||
973 | .radio = 0, | ||
974 | .vbi = 1, | ||
975 | .tuner = 0, | ||
976 | .tuner_type = 0, | ||
977 | .x_offset = 0, | ||
978 | .y_offset = 3, | ||
979 | .dvi_yuv_override = 1, | ||
980 | .dvi_yuv = 7, | ||
981 | .model_string = "Pinnacle Studio Linx Video input cable (NTSC)", | ||
982 | }, | ||
983 | [PINNA_LINX_VD_IN_CAB_PAL] = { | ||
984 | .interface = -1, | ||
985 | .codec = CODEC_SAA7113, | ||
986 | .video_channels = 2, | ||
987 | .video_norm = V4L2_STD_PAL, | ||
988 | .audio_channels = 1, | ||
989 | .radio = 0, | ||
990 | .vbi = 1, | ||
991 | .tuner = 0, | ||
992 | .tuner_type = 0, | ||
993 | .x_offset = 0, | ||
994 | .y_offset = 3, | ||
995 | .dvi_yuv_override = 1, | ||
996 | .dvi_yuv = 7, | ||
997 | .model_string = "Pinnacle Studio Linx Video input cable (PAL)", | ||
998 | }, | ||
999 | [PINNA_PCTV_BUNGEE_PAL_FM] = { | ||
1000 | .interface = -1, | ||
1001 | .codec = CODEC_SAA7113, | ||
1002 | .video_channels = 3, | ||
1003 | .video_norm = V4L2_STD_PAL, | ||
1004 | .audio_channels = 1, | ||
1005 | .radio = 1, | ||
1006 | .vbi = 1, | ||
1007 | .tuner = 1, | ||
1008 | .tuner_type = TUNER_TEMIC_4009FR5_PAL, | ||
1009 | .x_offset = 0, | ||
1010 | .y_offset = 3, | ||
1011 | .dvi_yuv_override = 1, | ||
1012 | .dvi_yuv = 7, | ||
1013 | .model_string = "Pinnacle PCTV Bungee USB (PAL) FM", | ||
1014 | }, | ||
1015 | [HPG_WINTV] = { | ||
1016 | .interface = -1, | ||
1017 | .codec = CODEC_SAA7111, | ||
1018 | .video_channels = 3, | ||
1019 | .video_norm = V4L2_STD_NTSC, | ||
1020 | .audio_channels = 1, | ||
1021 | .radio = 0, | ||
1022 | .vbi = 1, | ||
1023 | .tuner = 1, | ||
1024 | .tuner_type = TUNER_PHILIPS_NTSC_M, | ||
1025 | .x_offset = -1, | ||
1026 | .y_offset = -1, | ||
1027 | .model_string = "Hauppauge WinTv-USB", | ||
1028 | }, | ||
1029 | [MICROCAM_NTSC] = { | ||
1030 | .interface = -1, | ||
1031 | .codec = CODEC_WEBCAM, | ||
1032 | .video_channels = 1, | ||
1033 | .video_norm = V4L2_STD_NTSC, | ||
1034 | .audio_channels = 0, | ||
1035 | .radio = 0, | ||
1036 | .vbi = 0, | ||
1037 | .tuner = 0, | ||
1038 | .tuner_type = 0, | ||
1039 | .x_offset = 71, | ||
1040 | .y_offset = 15, | ||
1041 | .model_string = "Nogatech USB MicroCam NTSC (NV3000N)", | ||
1042 | }, | ||
1043 | [MICROCAM_PAL] = { | ||
1044 | .interface = -1, | ||
1045 | .codec = CODEC_WEBCAM, | ||
1046 | .video_channels = 1, | ||
1047 | .video_norm = V4L2_STD_PAL, | ||
1048 | .audio_channels = 0, | ||
1049 | .radio = 0, | ||
1050 | .vbi = 0, | ||
1051 | .tuner = 0, | ||
1052 | .tuner_type = 0, | ||
1053 | .x_offset = 71, | ||
1054 | .y_offset = 18, | ||
1055 | .model_string = "Nogatech USB MicroCam PAL (NV3001P)", | ||
1056 | }, | ||
1057 | }; | ||
1058 | const int usbvision_device_data_size = ARRAY_SIZE(usbvision_device_data); | ||
1059 | |||
1060 | /* Supported Devices */ | ||
1061 | |||
1062 | struct usb_device_id usbvision_table[] = { | ||
1063 | { USB_DEVICE(0x0a6f, 0x0400), .driver_info = XANBOO }, | ||
1064 | { USB_DEVICE(0x050d, 0x0106), .driver_info = BELKIN_VIDEOBUS_II }, | ||
1065 | { USB_DEVICE(0x050d, 0x0207), .driver_info = BELKIN_VIDEOBUS }, | ||
1066 | { USB_DEVICE(0x050d, 0x0208), .driver_info = BELKIN_USB_VIDEOBUS_II }, | ||
1067 | { USB_DEVICE(0x0571, 0x0002), .driver_info = ECHOFX_INTERVIEW_LITE }, | ||
1068 | { USB_DEVICE(0x0573, 0x0003), .driver_info = USBGEAR_USBG_V1 }, | ||
1069 | { USB_DEVICE(0x0573, 0x0400), .driver_info = D_LINK_V100 }, | ||
1070 | { USB_DEVICE(0x0573, 0x2000), .driver_info = X10_USB_CAMERA }, | ||
1071 | { USB_DEVICE(0x0573, 0x2d00), .driver_info = HPG_WINTV_LIVE_PAL_BG }, | ||
1072 | { USB_DEVICE(0x0573, 0x2d01), .driver_info = HPG_WINTV_LIVE_PRO_NTSC_MN }, | ||
1073 | { USB_DEVICE(0x0573, 0x2101), .driver_info = ZORAN_PMD_NOGATECH }, | ||
1074 | { USB_DEVICE(0x0573, 0x3000), .driver_info = MICROCAM_NTSC }, | ||
1075 | { USB_DEVICE(0x0573, 0x3001), .driver_info = MICROCAM_PAL }, | ||
1076 | { USB_DEVICE(0x0573, 0x4100), .driver_info = NOGATECH_USB_TV_NTSC_FM }, | ||
1077 | { USB_DEVICE(0x0573, 0x4110), .driver_info = PNY_USB_TV_NTSC_FM }, | ||
1078 | { USB_DEVICE(0x0573, 0x4450), .driver_info = PV_PLAYTV_USB_PRO_PAL_FM }, | ||
1079 | { USB_DEVICE(0x0573, 0x4550), .driver_info = ZT_721 }, | ||
1080 | { USB_DEVICE(0x0573, 0x4d00), .driver_info = HPG_WINTV_NTSC_MN }, | ||
1081 | { USB_DEVICE(0x0573, 0x4d01), .driver_info = HPG_WINTV_PAL_BG }, | ||
1082 | { USB_DEVICE(0x0573, 0x4d02), .driver_info = HPG_WINTV_PAL_I }, | ||
1083 | { USB_DEVICE(0x0573, 0x4d03), .driver_info = HPG_WINTV_PAL_SECAM_L }, | ||
1084 | { USB_DEVICE(0x0573, 0x4d04), .driver_info = HPG_WINTV_PAL_D_K }, | ||
1085 | { USB_DEVICE(0x0573, 0x4d10), .driver_info = HPG_WINTV_NTSC_FM }, | ||
1086 | { USB_DEVICE(0x0573, 0x4d11), .driver_info = HPG_WINTV_PAL_BG_FM }, | ||
1087 | { USB_DEVICE(0x0573, 0x4d12), .driver_info = HPG_WINTV_PAL_I_FM }, | ||
1088 | { USB_DEVICE(0x0573, 0x4d14), .driver_info = HPG_WINTV_PAL_D_K_FM }, | ||
1089 | { USB_DEVICE(0x0573, 0x4d2a), .driver_info = HPG_WINTV_PRO_NTSC_MN }, | ||
1090 | { USB_DEVICE(0x0573, 0x4d2b), .driver_info = HPG_WINTV_PRO_NTSC_MN_V2 }, | ||
1091 | { USB_DEVICE(0x0573, 0x4d2c), .driver_info = HPG_WINTV_PRO_PAL }, | ||
1092 | { USB_DEVICE(0x0573, 0x4d20), .driver_info = HPG_WINTV_PRO_NTSC_MN_V3 }, | ||
1093 | { USB_DEVICE(0x0573, 0x4d21), .driver_info = HPG_WINTV_PRO_PAL_BG }, | ||
1094 | { USB_DEVICE(0x0573, 0x4d22), .driver_info = HPG_WINTV_PRO_PAL_I }, | ||
1095 | { USB_DEVICE(0x0573, 0x4d23), .driver_info = HPG_WINTV_PRO_PAL_SECAM_L }, | ||
1096 | { USB_DEVICE(0x0573, 0x4d24), .driver_info = HPG_WINTV_PRO_PAL_D_K }, | ||
1097 | { USB_DEVICE(0x0573, 0x4d25), .driver_info = HPG_WINTV_PRO_PAL_SECAM }, | ||
1098 | { USB_DEVICE(0x0573, 0x4d26), .driver_info = HPG_WINTV_PRO_PAL_SECAM_V2 }, | ||
1099 | { USB_DEVICE(0x0573, 0x4d27), .driver_info = HPG_WINTV_PRO_PAL_BG_V2 }, | ||
1100 | { USB_DEVICE(0x0573, 0x4d28), .driver_info = HPG_WINTV_PRO_PAL_BG_D_K }, | ||
1101 | { USB_DEVICE(0x0573, 0x4d29), .driver_info = HPG_WINTV_PRO_PAL_I_D_K }, | ||
1102 | { USB_DEVICE(0x0573, 0x4d30), .driver_info = HPG_WINTV_PRO_NTSC_MN_FM }, | ||
1103 | { USB_DEVICE(0x0573, 0x4d31), .driver_info = HPG_WINTV_PRO_PAL_BG_FM }, | ||
1104 | { USB_DEVICE(0x0573, 0x4d32), .driver_info = HPG_WINTV_PRO_PAL_I_FM }, | ||
1105 | { USB_DEVICE(0x0573, 0x4d34), .driver_info = HPG_WINTV_PRO_PAL_D_K_FM }, | ||
1106 | { USB_DEVICE(0x0573, 0x4d35), .driver_info = HPG_WINTV_PRO_TEMIC_PAL_FM }, | ||
1107 | { USB_DEVICE(0x0573, 0x4d36), .driver_info = HPG_WINTV_PRO_TEMIC_PAL_BG_FM }, | ||
1108 | { USB_DEVICE(0x0573, 0x4d37), .driver_info = HPG_WINTV_PRO_PAL_FM }, | ||
1109 | { USB_DEVICE(0x0573, 0x4d38), .driver_info = HPG_WINTV_PRO_NTSC_MN_FM_V2 }, | ||
1110 | { USB_DEVICE(0x0768, 0x0006), .driver_info = CAMTEL_TVB330 }, | ||
1111 | { USB_DEVICE(0x07d0, 0x0001), .driver_info = DIGITAL_VIDEO_CREATOR_I }, | ||
1112 | { USB_DEVICE(0x07d0, 0x0002), .driver_info = GLOBAL_VILLAGE_GV_007_NTSC }, | ||
1113 | { USB_DEVICE(0x07d0, 0x0003), .driver_info = DAZZLE_DVC_50_REV_1_NTSC }, | ||
1114 | { USB_DEVICE(0x07d0, 0x0004), .driver_info = DAZZLE_DVC_80_REV_1_PAL }, | ||
1115 | { USB_DEVICE(0x07d0, 0x0005), .driver_info = DAZZLE_DVC_90_REV_1_SECAM }, | ||
1116 | { USB_DEVICE(0x07f8, 0x9104), .driver_info = ESKAPE_LABS_MYTV2GO }, | ||
1117 | { USB_DEVICE(0x2304, 0x010d), .driver_info = PINNA_PCTV_USB_PAL }, | ||
1118 | { USB_DEVICE(0x2304, 0x0109), .driver_info = PINNA_PCTV_USB_SECAM }, | ||
1119 | { USB_DEVICE(0x2304, 0x0110), .driver_info = PINNA_PCTV_USB_PAL_FM }, | ||
1120 | { USB_DEVICE(0x2304, 0x0111), .driver_info = MIRO_PCTV_USB }, | ||
1121 | { USB_DEVICE(0x2304, 0x0112), .driver_info = PINNA_PCTV_USB_NTSC_FM }, | ||
1122 | { USB_DEVICE(0x2304, 0x0113), .driver_info = PINNA_PCTV_USB_NTSC_FM_V3 }, | ||
1123 | { USB_DEVICE(0x2304, 0x0210), .driver_info = PINNA_PCTV_USB_PAL_FM_V2 }, | ||
1124 | { USB_DEVICE(0x2304, 0x0212), .driver_info = PINNA_PCTV_USB_NTSC_FM_V2 }, | ||
1125 | { USB_DEVICE(0x2304, 0x0214), .driver_info = PINNA_PCTV_USB_PAL_FM_V3 }, | ||
1126 | { USB_DEVICE(0x2304, 0x0300), .driver_info = PINNA_LINX_VD_IN_CAB_NTSC }, | ||
1127 | { USB_DEVICE(0x2304, 0x0301), .driver_info = PINNA_LINX_VD_IN_CAB_PAL }, | ||
1128 | { USB_DEVICE(0x2304, 0x0419), .driver_info = PINNA_PCTV_BUNGEE_PAL_FM }, | ||
1129 | { USB_DEVICE(0x2400, 0x4200), .driver_info = HPG_WINTV }, | ||
1130 | { }, /* terminate list */ | ||
1131 | }; | ||
1132 | |||
1133 | MODULE_DEVICE_TABLE(usb, usbvision_table); | ||
diff --git a/drivers/media/usb/usbvision/usbvision-cards.h b/drivers/media/usb/usbvision/usbvision-cards.h new file mode 100644 index 000000000000..a51cc1185cce --- /dev/null +++ b/drivers/media/usb/usbvision/usbvision-cards.h | |||
@@ -0,0 +1,69 @@ | |||
1 | #define XANBOO 0 | ||
2 | #define BELKIN_VIDEOBUS_II 1 | ||
3 | #define BELKIN_VIDEOBUS 2 | ||
4 | #define BELKIN_USB_VIDEOBUS_II 3 | ||
5 | #define ECHOFX_INTERVIEW_LITE 4 | ||
6 | #define USBGEAR_USBG_V1 5 | ||
7 | #define D_LINK_V100 6 | ||
8 | #define X10_USB_CAMERA 7 | ||
9 | #define HPG_WINTV_LIVE_PAL_BG 8 | ||
10 | #define HPG_WINTV_LIVE_PRO_NTSC_MN 9 | ||
11 | #define ZORAN_PMD_NOGATECH 10 | ||
12 | #define NOGATECH_USB_TV_NTSC_FM 11 | ||
13 | #define PNY_USB_TV_NTSC_FM 12 | ||
14 | #define PV_PLAYTV_USB_PRO_PAL_FM 13 | ||
15 | #define ZT_721 14 | ||
16 | #define HPG_WINTV_NTSC_MN 15 | ||
17 | #define HPG_WINTV_PAL_BG 16 | ||
18 | #define HPG_WINTV_PAL_I 17 | ||
19 | #define HPG_WINTV_PAL_SECAM_L 18 | ||
20 | #define HPG_WINTV_PAL_D_K 19 | ||
21 | #define HPG_WINTV_NTSC_FM 20 | ||
22 | #define HPG_WINTV_PAL_BG_FM 21 | ||
23 | #define HPG_WINTV_PAL_I_FM 22 | ||
24 | #define HPG_WINTV_PAL_D_K_FM 23 | ||
25 | #define HPG_WINTV_PRO_NTSC_MN 24 | ||
26 | #define HPG_WINTV_PRO_NTSC_MN_V2 25 | ||
27 | #define HPG_WINTV_PRO_PAL 26 | ||
28 | #define HPG_WINTV_PRO_NTSC_MN_V3 27 | ||
29 | #define HPG_WINTV_PRO_PAL_BG 28 | ||
30 | #define HPG_WINTV_PRO_PAL_I 29 | ||
31 | #define HPG_WINTV_PRO_PAL_SECAM_L 30 | ||
32 | #define HPG_WINTV_PRO_PAL_D_K 31 | ||
33 | #define HPG_WINTV_PRO_PAL_SECAM 32 | ||
34 | #define HPG_WINTV_PRO_PAL_SECAM_V2 33 | ||
35 | #define HPG_WINTV_PRO_PAL_BG_V2 34 | ||
36 | #define HPG_WINTV_PRO_PAL_BG_D_K 35 | ||
37 | #define HPG_WINTV_PRO_PAL_I_D_K 36 | ||
38 | #define HPG_WINTV_PRO_NTSC_MN_FM 37 | ||
39 | #define HPG_WINTV_PRO_PAL_BG_FM 38 | ||
40 | #define HPG_WINTV_PRO_PAL_I_FM 39 | ||
41 | #define HPG_WINTV_PRO_PAL_D_K_FM 40 | ||
42 | #define HPG_WINTV_PRO_TEMIC_PAL_FM 41 | ||
43 | #define HPG_WINTV_PRO_TEMIC_PAL_BG_FM 42 | ||
44 | #define HPG_WINTV_PRO_PAL_FM 43 | ||
45 | #define HPG_WINTV_PRO_NTSC_MN_FM_V2 44 | ||
46 | #define CAMTEL_TVB330 45 | ||
47 | #define DIGITAL_VIDEO_CREATOR_I 46 | ||
48 | #define GLOBAL_VILLAGE_GV_007_NTSC 47 | ||
49 | #define DAZZLE_DVC_50_REV_1_NTSC 48 | ||
50 | #define DAZZLE_DVC_80_REV_1_PAL 49 | ||
51 | #define DAZZLE_DVC_90_REV_1_SECAM 50 | ||
52 | #define ESKAPE_LABS_MYTV2GO 51 | ||
53 | #define PINNA_PCTV_USB_PAL 52 | ||
54 | #define PINNA_PCTV_USB_SECAM 53 | ||
55 | #define PINNA_PCTV_USB_PAL_FM 54 | ||
56 | #define MIRO_PCTV_USB 55 | ||
57 | #define PINNA_PCTV_USB_NTSC_FM 56 | ||
58 | #define PINNA_PCTV_USB_PAL_FM_V2 57 | ||
59 | #define PINNA_PCTV_USB_NTSC_FM_V2 58 | ||
60 | #define PINNA_PCTV_USB_PAL_FM_V3 59 | ||
61 | #define PINNA_LINX_VD_IN_CAB_NTSC 60 | ||
62 | #define PINNA_LINX_VD_IN_CAB_PAL 61 | ||
63 | #define PINNA_PCTV_BUNGEE_PAL_FM 62 | ||
64 | #define HPG_WINTV 63 | ||
65 | #define PINNA_PCTV_USB_NTSC_FM_V3 64 | ||
66 | #define MICROCAM_NTSC 65 | ||
67 | #define MICROCAM_PAL 66 | ||
68 | |||
69 | extern const int usbvision_device_data_size; | ||
diff --git a/drivers/media/usb/usbvision/usbvision-core.c b/drivers/media/usb/usbvision/usbvision-core.c new file mode 100644 index 000000000000..c9b2042f8bdf --- /dev/null +++ b/drivers/media/usb/usbvision/usbvision-core.c | |||
@@ -0,0 +1,2518 @@ | |||
1 | /* | ||
2 | * usbvision-core.c - driver for NT100x USB video capture devices | ||
3 | * | ||
4 | * | ||
5 | * Copyright (c) 1999-2005 Joerg Heckenbach <joerg@heckenbach-aw.de> | ||
6 | * Dwaine Garden <dwainegarden@rogers.com> | ||
7 | * | ||
8 | * This module is part of usbvision driver project. | ||
9 | * Updates to driver completed by Dwaine P. Garden | ||
10 | * | ||
11 | * This program is free software; you can redistribute it and/or modify | ||
12 | * it under the terms of the GNU General Public License as published by | ||
13 | * the Free Software Foundation; either version 2 of the License, or | ||
14 | * (at your option) any later version. | ||
15 | * | ||
16 | * This program is distributed in the hope that it will be useful, | ||
17 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
18 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
19 | * GNU General Public License for more details. | ||
20 | * | ||
21 | * You should have received a copy of the GNU General Public License | ||
22 | * along with this program; if not, write to the Free Software | ||
23 | * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. | ||
24 | */ | ||
25 | |||
26 | #include <linux/kernel.h> | ||
27 | #include <linux/list.h> | ||
28 | #include <linux/timer.h> | ||
29 | #include <linux/gfp.h> | ||
30 | #include <linux/mm.h> | ||
31 | #include <linux/highmem.h> | ||
32 | #include <linux/vmalloc.h> | ||
33 | #include <linux/module.h> | ||
34 | #include <linux/init.h> | ||
35 | #include <linux/spinlock.h> | ||
36 | #include <linux/io.h> | ||
37 | #include <linux/videodev2.h> | ||
38 | #include <linux/i2c.h> | ||
39 | |||
40 | #include <media/saa7115.h> | ||
41 | #include <media/v4l2-common.h> | ||
42 | #include <media/tuner.h> | ||
43 | |||
44 | #include <linux/workqueue.h> | ||
45 | |||
46 | #include "usbvision.h" | ||
47 | |||
48 | static unsigned int core_debug; | ||
49 | module_param(core_debug, int, 0644); | ||
50 | MODULE_PARM_DESC(core_debug, "enable debug messages [core]"); | ||
51 | |||
52 | static int adjust_compression = 1; /* Set the compression to be adaptive */ | ||
53 | module_param(adjust_compression, int, 0444); | ||
54 | MODULE_PARM_DESC(adjust_compression, " Set the ADPCM compression for the device. Default: 1 (On)"); | ||
55 | |||
56 | /* To help people with Black and White output with using s-video input. | ||
57 | * Some cables and input device are wired differently. */ | ||
58 | static int switch_svideo_input; | ||
59 | module_param(switch_svideo_input, int, 0444); | ||
60 | MODULE_PARM_DESC(switch_svideo_input, " Set the S-Video input. Some cables and input device are wired differently. Default: 0 (Off)"); | ||
61 | |||
62 | static unsigned int adjust_x_offset = -1; | ||
63 | module_param(adjust_x_offset, int, 0644); | ||
64 | MODULE_PARM_DESC(adjust_x_offset, "adjust X offset display [core]"); | ||
65 | |||
66 | static unsigned int adjust_y_offset = -1; | ||
67 | module_param(adjust_y_offset, int, 0644); | ||
68 | MODULE_PARM_DESC(adjust_y_offset, "adjust Y offset display [core]"); | ||
69 | |||
70 | |||
71 | #define ENABLE_HEXDUMP 0 /* Enable if you need it */ | ||
72 | |||
73 | |||
74 | #ifdef USBVISION_DEBUG | ||
75 | #define PDEBUG(level, fmt, args...) { \ | ||
76 | if (core_debug & (level)) \ | ||
77 | printk(KERN_INFO KBUILD_MODNAME ":[%s:%d] " fmt, \ | ||
78 | __func__, __LINE__ , ## args); \ | ||
79 | } | ||
80 | #else | ||
81 | #define PDEBUG(level, fmt, args...) do {} while (0) | ||
82 | #endif | ||
83 | |||
84 | #define DBG_HEADER (1 << 0) | ||
85 | #define DBG_IRQ (1 << 1) | ||
86 | #define DBG_ISOC (1 << 2) | ||
87 | #define DBG_PARSE (1 << 3) | ||
88 | #define DBG_SCRATCH (1 << 4) | ||
89 | #define DBG_FUNC (1 << 5) | ||
90 | |||
91 | static const int max_imgwidth = MAX_FRAME_WIDTH; | ||
92 | static const int max_imgheight = MAX_FRAME_HEIGHT; | ||
93 | static const int min_imgwidth = MIN_FRAME_WIDTH; | ||
94 | static const int min_imgheight = MIN_FRAME_HEIGHT; | ||
95 | |||
96 | /* The value of 'scratch_buf_size' affects quality of the picture | ||
97 | * in many ways. Shorter buffers may cause loss of data when client | ||
98 | * is too slow. Larger buffers are memory-consuming and take longer | ||
99 | * to work with. This setting can be adjusted, but the default value | ||
100 | * should be OK for most desktop users. | ||
101 | */ | ||
102 | #define DEFAULT_SCRATCH_BUF_SIZE (0x20000) /* 128kB memory scratch buffer */ | ||
103 | static const int scratch_buf_size = DEFAULT_SCRATCH_BUF_SIZE; | ||
104 | |||
105 | /* Function prototypes */ | ||
106 | static int usbvision_request_intra(struct usb_usbvision *usbvision); | ||
107 | static int usbvision_unrequest_intra(struct usb_usbvision *usbvision); | ||
108 | static int usbvision_adjust_compression(struct usb_usbvision *usbvision); | ||
109 | static int usbvision_measure_bandwidth(struct usb_usbvision *usbvision); | ||
110 | |||
111 | /*******************************/ | ||
112 | /* Memory management functions */ | ||
113 | /*******************************/ | ||
114 | |||
115 | /* | ||
116 | * Here we want the physical address of the memory. | ||
117 | * This is used when initializing the contents of the area. | ||
118 | */ | ||
119 | |||
120 | static void *usbvision_rvmalloc(unsigned long size) | ||
121 | { | ||
122 | void *mem; | ||
123 | unsigned long adr; | ||
124 | |||
125 | size = PAGE_ALIGN(size); | ||
126 | mem = vmalloc_32(size); | ||
127 | if (!mem) | ||
128 | return NULL; | ||
129 | |||
130 | memset(mem, 0, size); /* Clear the ram out, no junk to the user */ | ||
131 | adr = (unsigned long) mem; | ||
132 | while (size > 0) { | ||
133 | SetPageReserved(vmalloc_to_page((void *)adr)); | ||
134 | adr += PAGE_SIZE; | ||
135 | size -= PAGE_SIZE; | ||
136 | } | ||
137 | |||
138 | return mem; | ||
139 | } | ||
140 | |||
141 | static void usbvision_rvfree(void *mem, unsigned long size) | ||
142 | { | ||
143 | unsigned long adr; | ||
144 | |||
145 | if (!mem) | ||
146 | return; | ||
147 | |||
148 | size = PAGE_ALIGN(size); | ||
149 | |||
150 | adr = (unsigned long) mem; | ||
151 | while ((long) size > 0) { | ||
152 | ClearPageReserved(vmalloc_to_page((void *)adr)); | ||
153 | adr += PAGE_SIZE; | ||
154 | size -= PAGE_SIZE; | ||
155 | } | ||
156 | |||
157 | vfree(mem); | ||
158 | } | ||
159 | |||
160 | |||
161 | #if ENABLE_HEXDUMP | ||
162 | static void usbvision_hexdump(const unsigned char *data, int len) | ||
163 | { | ||
164 | char tmp[80]; | ||
165 | int i, k; | ||
166 | |||
167 | for (i = k = 0; len > 0; i++, len--) { | ||
168 | if (i > 0 && (i % 16 == 0)) { | ||
169 | printk("%s\n", tmp); | ||
170 | k = 0; | ||
171 | } | ||
172 | k += sprintf(&tmp[k], "%02x ", data[i]); | ||
173 | } | ||
174 | if (k > 0) | ||
175 | printk(KERN_CONT "%s\n", tmp); | ||
176 | } | ||
177 | #endif | ||
178 | |||
179 | /******************************** | ||
180 | * scratch ring buffer handling | ||
181 | ********************************/ | ||
182 | static int scratch_len(struct usb_usbvision *usbvision) /* This returns the amount of data actually in the buffer */ | ||
183 | { | ||
184 | int len = usbvision->scratch_write_ptr - usbvision->scratch_read_ptr; | ||
185 | |||
186 | if (len < 0) | ||
187 | len += scratch_buf_size; | ||
188 | PDEBUG(DBG_SCRATCH, "scratch_len() = %d\n", len); | ||
189 | |||
190 | return len; | ||
191 | } | ||
192 | |||
193 | |||
194 | /* This returns the free space left in the buffer */ | ||
195 | static int scratch_free(struct usb_usbvision *usbvision) | ||
196 | { | ||
197 | int free = usbvision->scratch_read_ptr - usbvision->scratch_write_ptr; | ||
198 | if (free <= 0) | ||
199 | free += scratch_buf_size; | ||
200 | if (free) { | ||
201 | free -= 1; /* at least one byte in the buffer must */ | ||
202 | /* left blank, otherwise there is no chance to differ between full and empty */ | ||
203 | } | ||
204 | PDEBUG(DBG_SCRATCH, "return %d\n", free); | ||
205 | |||
206 | return free; | ||
207 | } | ||
208 | |||
209 | |||
210 | /* This puts data into the buffer */ | ||
211 | static int scratch_put(struct usb_usbvision *usbvision, unsigned char *data, | ||
212 | int len) | ||
213 | { | ||
214 | int len_part; | ||
215 | |||
216 | if (usbvision->scratch_write_ptr + len < scratch_buf_size) { | ||
217 | memcpy(usbvision->scratch + usbvision->scratch_write_ptr, data, len); | ||
218 | usbvision->scratch_write_ptr += len; | ||
219 | } else { | ||
220 | len_part = scratch_buf_size - usbvision->scratch_write_ptr; | ||
221 | memcpy(usbvision->scratch + usbvision->scratch_write_ptr, data, len_part); | ||
222 | if (len == len_part) { | ||
223 | usbvision->scratch_write_ptr = 0; /* just set write_ptr to zero */ | ||
224 | } else { | ||
225 | memcpy(usbvision->scratch, data + len_part, len - len_part); | ||
226 | usbvision->scratch_write_ptr = len - len_part; | ||
227 | } | ||
228 | } | ||
229 | |||
230 | PDEBUG(DBG_SCRATCH, "len=%d, new write_ptr=%d\n", len, usbvision->scratch_write_ptr); | ||
231 | |||
232 | return len; | ||
233 | } | ||
234 | |||
235 | /* This marks the write_ptr as position of new frame header */ | ||
236 | static void scratch_mark_header(struct usb_usbvision *usbvision) | ||
237 | { | ||
238 | PDEBUG(DBG_SCRATCH, "header at write_ptr=%d\n", usbvision->scratch_headermarker_write_ptr); | ||
239 | |||
240 | usbvision->scratch_headermarker[usbvision->scratch_headermarker_write_ptr] = | ||
241 | usbvision->scratch_write_ptr; | ||
242 | usbvision->scratch_headermarker_write_ptr += 1; | ||
243 | usbvision->scratch_headermarker_write_ptr %= USBVISION_NUM_HEADERMARKER; | ||
244 | } | ||
245 | |||
246 | /* This gets data from the buffer at the given "ptr" position */ | ||
247 | static int scratch_get_extra(struct usb_usbvision *usbvision, | ||
248 | unsigned char *data, int *ptr, int len) | ||
249 | { | ||
250 | int len_part; | ||
251 | |||
252 | if (*ptr + len < scratch_buf_size) { | ||
253 | memcpy(data, usbvision->scratch + *ptr, len); | ||
254 | *ptr += len; | ||
255 | } else { | ||
256 | len_part = scratch_buf_size - *ptr; | ||
257 | memcpy(data, usbvision->scratch + *ptr, len_part); | ||
258 | if (len == len_part) { | ||
259 | *ptr = 0; /* just set the y_ptr to zero */ | ||
260 | } else { | ||
261 | memcpy(data + len_part, usbvision->scratch, len - len_part); | ||
262 | *ptr = len - len_part; | ||
263 | } | ||
264 | } | ||
265 | |||
266 | PDEBUG(DBG_SCRATCH, "len=%d, new ptr=%d\n", len, *ptr); | ||
267 | |||
268 | return len; | ||
269 | } | ||
270 | |||
271 | |||
272 | /* This sets the scratch extra read pointer */ | ||
273 | static void scratch_set_extra_ptr(struct usb_usbvision *usbvision, int *ptr, | ||
274 | int len) | ||
275 | { | ||
276 | *ptr = (usbvision->scratch_read_ptr + len) % scratch_buf_size; | ||
277 | |||
278 | PDEBUG(DBG_SCRATCH, "ptr=%d\n", *ptr); | ||
279 | } | ||
280 | |||
281 | |||
282 | /* This increments the scratch extra read pointer */ | ||
283 | static void scratch_inc_extra_ptr(int *ptr, int len) | ||
284 | { | ||
285 | *ptr = (*ptr + len) % scratch_buf_size; | ||
286 | |||
287 | PDEBUG(DBG_SCRATCH, "ptr=%d\n", *ptr); | ||
288 | } | ||
289 | |||
290 | |||
291 | /* This gets data from the buffer */ | ||
292 | static int scratch_get(struct usb_usbvision *usbvision, unsigned char *data, | ||
293 | int len) | ||
294 | { | ||
295 | int len_part; | ||
296 | |||
297 | if (usbvision->scratch_read_ptr + len < scratch_buf_size) { | ||
298 | memcpy(data, usbvision->scratch + usbvision->scratch_read_ptr, len); | ||
299 | usbvision->scratch_read_ptr += len; | ||
300 | } else { | ||
301 | len_part = scratch_buf_size - usbvision->scratch_read_ptr; | ||
302 | memcpy(data, usbvision->scratch + usbvision->scratch_read_ptr, len_part); | ||
303 | if (len == len_part) { | ||
304 | usbvision->scratch_read_ptr = 0; /* just set the read_ptr to zero */ | ||
305 | } else { | ||
306 | memcpy(data + len_part, usbvision->scratch, len - len_part); | ||
307 | usbvision->scratch_read_ptr = len - len_part; | ||
308 | } | ||
309 | } | ||
310 | |||
311 | PDEBUG(DBG_SCRATCH, "len=%d, new read_ptr=%d\n", len, usbvision->scratch_read_ptr); | ||
312 | |||
313 | return len; | ||
314 | } | ||
315 | |||
316 | |||
317 | /* This sets read pointer to next header and returns it */ | ||
318 | static int scratch_get_header(struct usb_usbvision *usbvision, | ||
319 | struct usbvision_frame_header *header) | ||
320 | { | ||
321 | int err_code = 0; | ||
322 | |||
323 | PDEBUG(DBG_SCRATCH, "from read_ptr=%d", usbvision->scratch_headermarker_read_ptr); | ||
324 | |||
325 | while (usbvision->scratch_headermarker_write_ptr - | ||
326 | usbvision->scratch_headermarker_read_ptr != 0) { | ||
327 | usbvision->scratch_read_ptr = | ||
328 | usbvision->scratch_headermarker[usbvision->scratch_headermarker_read_ptr]; | ||
329 | usbvision->scratch_headermarker_read_ptr += 1; | ||
330 | usbvision->scratch_headermarker_read_ptr %= USBVISION_NUM_HEADERMARKER; | ||
331 | scratch_get(usbvision, (unsigned char *)header, USBVISION_HEADER_LENGTH); | ||
332 | if ((header->magic_1 == USBVISION_MAGIC_1) | ||
333 | && (header->magic_2 == USBVISION_MAGIC_2) | ||
334 | && (header->header_length == USBVISION_HEADER_LENGTH)) { | ||
335 | err_code = USBVISION_HEADER_LENGTH; | ||
336 | header->frame_width = header->frame_width_lo + (header->frame_width_hi << 8); | ||
337 | header->frame_height = header->frame_height_lo + (header->frame_height_hi << 8); | ||
338 | break; | ||
339 | } | ||
340 | } | ||
341 | |||
342 | return err_code; | ||
343 | } | ||
344 | |||
345 | |||
346 | /* This removes len bytes of old data from the buffer */ | ||
347 | static void scratch_rm_old(struct usb_usbvision *usbvision, int len) | ||
348 | { | ||
349 | usbvision->scratch_read_ptr += len; | ||
350 | usbvision->scratch_read_ptr %= scratch_buf_size; | ||
351 | PDEBUG(DBG_SCRATCH, "read_ptr is now %d\n", usbvision->scratch_read_ptr); | ||
352 | } | ||
353 | |||
354 | |||
355 | /* This resets the buffer - kills all data in it too */ | ||
356 | static void scratch_reset(struct usb_usbvision *usbvision) | ||
357 | { | ||
358 | PDEBUG(DBG_SCRATCH, "\n"); | ||
359 | |||
360 | usbvision->scratch_read_ptr = 0; | ||
361 | usbvision->scratch_write_ptr = 0; | ||
362 | usbvision->scratch_headermarker_read_ptr = 0; | ||
363 | usbvision->scratch_headermarker_write_ptr = 0; | ||
364 | usbvision->isocstate = isoc_state_no_frame; | ||
365 | } | ||
366 | |||
367 | int usbvision_scratch_alloc(struct usb_usbvision *usbvision) | ||
368 | { | ||
369 | usbvision->scratch = vmalloc_32(scratch_buf_size); | ||
370 | scratch_reset(usbvision); | ||
371 | if (usbvision->scratch == NULL) { | ||
372 | dev_err(&usbvision->dev->dev, | ||
373 | "%s: unable to allocate %d bytes for scratch\n", | ||
374 | __func__, scratch_buf_size); | ||
375 | return -ENOMEM; | ||
376 | } | ||
377 | return 0; | ||
378 | } | ||
379 | |||
380 | void usbvision_scratch_free(struct usb_usbvision *usbvision) | ||
381 | { | ||
382 | vfree(usbvision->scratch); | ||
383 | usbvision->scratch = NULL; | ||
384 | } | ||
385 | |||
386 | /* | ||
387 | * usbvision_decompress_alloc() | ||
388 | * | ||
389 | * allocates intermediate buffer for decompression | ||
390 | */ | ||
391 | int usbvision_decompress_alloc(struct usb_usbvision *usbvision) | ||
392 | { | ||
393 | int IFB_size = MAX_FRAME_WIDTH * MAX_FRAME_HEIGHT * 3 / 2; | ||
394 | |||
395 | usbvision->intra_frame_buffer = vmalloc_32(IFB_size); | ||
396 | if (usbvision->intra_frame_buffer == NULL) { | ||
397 | dev_err(&usbvision->dev->dev, | ||
398 | "%s: unable to allocate %d for compr. frame buffer\n", | ||
399 | __func__, IFB_size); | ||
400 | return -ENOMEM; | ||
401 | } | ||
402 | return 0; | ||
403 | } | ||
404 | |||
405 | /* | ||
406 | * usbvision_decompress_free() | ||
407 | * | ||
408 | * frees intermediate buffer for decompression | ||
409 | */ | ||
410 | void usbvision_decompress_free(struct usb_usbvision *usbvision) | ||
411 | { | ||
412 | vfree(usbvision->intra_frame_buffer); | ||
413 | usbvision->intra_frame_buffer = NULL; | ||
414 | |||
415 | } | ||
416 | |||
417 | /************************************************************ | ||
418 | * Here comes the data parsing stuff that is run as interrupt | ||
419 | ************************************************************/ | ||
420 | /* | ||
421 | * usbvision_find_header() | ||
422 | * | ||
423 | * Locate one of supported header markers in the scratch buffer. | ||
424 | */ | ||
425 | static enum parse_state usbvision_find_header(struct usb_usbvision *usbvision) | ||
426 | { | ||
427 | struct usbvision_frame *frame; | ||
428 | int found_header = 0; | ||
429 | |||
430 | frame = usbvision->cur_frame; | ||
431 | |||
432 | while (scratch_get_header(usbvision, &frame->isoc_header) == USBVISION_HEADER_LENGTH) { | ||
433 | /* found header in scratch */ | ||
434 | PDEBUG(DBG_HEADER, "found header: 0x%02x%02x %d %d %d %d %#x 0x%02x %u %u", | ||
435 | frame->isoc_header.magic_2, | ||
436 | frame->isoc_header.magic_1, | ||
437 | frame->isoc_header.header_length, | ||
438 | frame->isoc_header.frame_num, | ||
439 | frame->isoc_header.frame_phase, | ||
440 | frame->isoc_header.frame_latency, | ||
441 | frame->isoc_header.data_format, | ||
442 | frame->isoc_header.format_param, | ||
443 | frame->isoc_header.frame_width, | ||
444 | frame->isoc_header.frame_height); | ||
445 | |||
446 | if (usbvision->request_intra) { | ||
447 | if (frame->isoc_header.format_param & 0x80) { | ||
448 | found_header = 1; | ||
449 | usbvision->last_isoc_frame_num = -1; /* do not check for lost frames this time */ | ||
450 | usbvision_unrequest_intra(usbvision); | ||
451 | break; | ||
452 | } | ||
453 | } else { | ||
454 | found_header = 1; | ||
455 | break; | ||
456 | } | ||
457 | } | ||
458 | |||
459 | if (found_header) { | ||
460 | frame->frmwidth = frame->isoc_header.frame_width * usbvision->stretch_width; | ||
461 | frame->frmheight = frame->isoc_header.frame_height * usbvision->stretch_height; | ||
462 | frame->v4l2_linesize = (frame->frmwidth * frame->v4l2_format.depth) >> 3; | ||
463 | } else { /* no header found */ | ||
464 | PDEBUG(DBG_HEADER, "skipping scratch data, no header"); | ||
465 | scratch_reset(usbvision); | ||
466 | return parse_state_end_parse; | ||
467 | } | ||
468 | |||
469 | /* found header */ | ||
470 | if (frame->isoc_header.data_format == ISOC_MODE_COMPRESS) { | ||
471 | /* check isoc_header.frame_num for lost frames */ | ||
472 | if (usbvision->last_isoc_frame_num >= 0) { | ||
473 | if (((usbvision->last_isoc_frame_num + 1) % 32) != frame->isoc_header.frame_num) { | ||
474 | /* unexpected frame drop: need to request new intra frame */ | ||
475 | PDEBUG(DBG_HEADER, "Lost frame before %d on USB", frame->isoc_header.frame_num); | ||
476 | usbvision_request_intra(usbvision); | ||
477 | return parse_state_next_frame; | ||
478 | } | ||
479 | } | ||
480 | usbvision->last_isoc_frame_num = frame->isoc_header.frame_num; | ||
481 | } | ||
482 | usbvision->header_count++; | ||
483 | frame->scanstate = scan_state_lines; | ||
484 | frame->curline = 0; | ||
485 | |||
486 | return parse_state_continue; | ||
487 | } | ||
488 | |||
489 | static enum parse_state usbvision_parse_lines_422(struct usb_usbvision *usbvision, | ||
490 | long *pcopylen) | ||
491 | { | ||
492 | volatile struct usbvision_frame *frame; | ||
493 | unsigned char *f; | ||
494 | int len; | ||
495 | int i; | ||
496 | unsigned char yuyv[4] = { 180, 128, 10, 128 }; /* YUV components */ | ||
497 | unsigned char rv, gv, bv; /* RGB components */ | ||
498 | int clipmask_index, bytes_per_pixel; | ||
499 | int stretch_bytes, clipmask_add; | ||
500 | |||
501 | frame = usbvision->cur_frame; | ||
502 | f = frame->data + (frame->v4l2_linesize * frame->curline); | ||
503 | |||
504 | /* Make sure there's enough data for the entire line */ | ||
505 | len = (frame->isoc_header.frame_width * 2) + 5; | ||
506 | if (scratch_len(usbvision) < len) { | ||
507 | PDEBUG(DBG_PARSE, "out of data in line %d, need %u.\n", frame->curline, len); | ||
508 | return parse_state_out; | ||
509 | } | ||
510 | |||
511 | if ((frame->curline + 1) >= frame->frmheight) | ||
512 | return parse_state_next_frame; | ||
513 | |||
514 | bytes_per_pixel = frame->v4l2_format.bytes_per_pixel; | ||
515 | stretch_bytes = (usbvision->stretch_width - 1) * bytes_per_pixel; | ||
516 | clipmask_index = frame->curline * MAX_FRAME_WIDTH; | ||
517 | clipmask_add = usbvision->stretch_width; | ||
518 | |||
519 | for (i = 0; i < frame->frmwidth; i += (2 * usbvision->stretch_width)) { | ||
520 | scratch_get(usbvision, &yuyv[0], 4); | ||
521 | |||
522 | if (frame->v4l2_format.format == V4L2_PIX_FMT_YUYV) { | ||
523 | *f++ = yuyv[0]; /* Y */ | ||
524 | *f++ = yuyv[3]; /* U */ | ||
525 | } else { | ||
526 | YUV_TO_RGB_BY_THE_BOOK(yuyv[0], yuyv[1], yuyv[3], rv, gv, bv); | ||
527 | switch (frame->v4l2_format.format) { | ||
528 | case V4L2_PIX_FMT_RGB565: | ||
529 | *f++ = (0x1F & rv) | | ||
530 | (0xE0 & (gv << 5)); | ||
531 | *f++ = (0x07 & (gv >> 3)) | | ||
532 | (0xF8 & bv); | ||
533 | break; | ||
534 | case V4L2_PIX_FMT_RGB24: | ||
535 | *f++ = rv; | ||
536 | *f++ = gv; | ||
537 | *f++ = bv; | ||
538 | break; | ||
539 | case V4L2_PIX_FMT_RGB32: | ||
540 | *f++ = rv; | ||
541 | *f++ = gv; | ||
542 | *f++ = bv; | ||
543 | f++; | ||
544 | break; | ||
545 | case V4L2_PIX_FMT_RGB555: | ||
546 | *f++ = (0x1F & rv) | | ||
547 | (0xE0 & (gv << 5)); | ||
548 | *f++ = (0x03 & (gv >> 3)) | | ||
549 | (0x7C & (bv << 2)); | ||
550 | break; | ||
551 | } | ||
552 | } | ||
553 | clipmask_index += clipmask_add; | ||
554 | f += stretch_bytes; | ||
555 | |||
556 | if (frame->v4l2_format.format == V4L2_PIX_FMT_YUYV) { | ||
557 | *f++ = yuyv[2]; /* Y */ | ||
558 | *f++ = yuyv[1]; /* V */ | ||
559 | } else { | ||
560 | YUV_TO_RGB_BY_THE_BOOK(yuyv[2], yuyv[1], yuyv[3], rv, gv, bv); | ||
561 | switch (frame->v4l2_format.format) { | ||
562 | case V4L2_PIX_FMT_RGB565: | ||
563 | *f++ = (0x1F & rv) | | ||
564 | (0xE0 & (gv << 5)); | ||
565 | *f++ = (0x07 & (gv >> 3)) | | ||
566 | (0xF8 & bv); | ||
567 | break; | ||
568 | case V4L2_PIX_FMT_RGB24: | ||
569 | *f++ = rv; | ||
570 | *f++ = gv; | ||
571 | *f++ = bv; | ||
572 | break; | ||
573 | case V4L2_PIX_FMT_RGB32: | ||
574 | *f++ = rv; | ||
575 | *f++ = gv; | ||
576 | *f++ = bv; | ||
577 | f++; | ||
578 | break; | ||
579 | case V4L2_PIX_FMT_RGB555: | ||
580 | *f++ = (0x1F & rv) | | ||
581 | (0xE0 & (gv << 5)); | ||
582 | *f++ = (0x03 & (gv >> 3)) | | ||
583 | (0x7C & (bv << 2)); | ||
584 | break; | ||
585 | } | ||
586 | } | ||
587 | clipmask_index += clipmask_add; | ||
588 | f += stretch_bytes; | ||
589 | } | ||
590 | |||
591 | frame->curline += usbvision->stretch_height; | ||
592 | *pcopylen += frame->v4l2_linesize * usbvision->stretch_height; | ||
593 | |||
594 | if (frame->curline >= frame->frmheight) | ||
595 | return parse_state_next_frame; | ||
596 | return parse_state_continue; | ||
597 | } | ||
598 | |||
599 | /* The decompression routine */ | ||
600 | static int usbvision_decompress(struct usb_usbvision *usbvision, unsigned char *compressed, | ||
601 | unsigned char *decompressed, int *start_pos, | ||
602 | int *block_typestart_pos, int len) | ||
603 | { | ||
604 | int rest_pixel, idx, pos, extra_pos, block_len, block_type_pos, block_type_len; | ||
605 | unsigned char block_byte, block_code, block_type, block_type_byte, integrator; | ||
606 | |||
607 | integrator = 0; | ||
608 | pos = *start_pos; | ||
609 | block_type_pos = *block_typestart_pos; | ||
610 | extra_pos = pos; | ||
611 | block_len = 0; | ||
612 | block_byte = 0; | ||
613 | block_code = 0; | ||
614 | block_type = 0; | ||
615 | block_type_byte = 0; | ||
616 | block_type_len = 0; | ||
617 | rest_pixel = len; | ||
618 | |||
619 | for (idx = 0; idx < len; idx++) { | ||
620 | if (block_len == 0) { | ||
621 | if (block_type_len == 0) { | ||
622 | block_type_byte = compressed[block_type_pos]; | ||
623 | block_type_pos++; | ||
624 | block_type_len = 4; | ||
625 | } | ||
626 | block_type = (block_type_byte & 0xC0) >> 6; | ||
627 | |||
628 | /* statistic: */ | ||
629 | usbvision->compr_block_types[block_type]++; | ||
630 | |||
631 | pos = extra_pos; | ||
632 | if (block_type == 0) { | ||
633 | if (rest_pixel >= 24) { | ||
634 | idx += 23; | ||
635 | rest_pixel -= 24; | ||
636 | integrator = decompressed[idx]; | ||
637 | } else { | ||
638 | idx += rest_pixel - 1; | ||
639 | rest_pixel = 0; | ||
640 | } | ||
641 | } else { | ||
642 | block_code = compressed[pos]; | ||
643 | pos++; | ||
644 | if (rest_pixel >= 24) | ||
645 | block_len = 24; | ||
646 | else | ||
647 | block_len = rest_pixel; | ||
648 | rest_pixel -= block_len; | ||
649 | extra_pos = pos + (block_len / 4); | ||
650 | } | ||
651 | block_type_byte <<= 2; | ||
652 | block_type_len -= 1; | ||
653 | } | ||
654 | if (block_len > 0) { | ||
655 | if ((block_len % 4) == 0) { | ||
656 | block_byte = compressed[pos]; | ||
657 | pos++; | ||
658 | } | ||
659 | if (block_type == 1) /* inter Block */ | ||
660 | integrator = decompressed[idx]; | ||
661 | switch (block_byte & 0xC0) { | ||
662 | case 0x03 << 6: | ||
663 | integrator += compressed[extra_pos]; | ||
664 | extra_pos++; | ||
665 | break; | ||
666 | case 0x02 << 6: | ||
667 | integrator += block_code; | ||
668 | break; | ||
669 | case 0x00: | ||
670 | integrator -= block_code; | ||
671 | break; | ||
672 | } | ||
673 | decompressed[idx] = integrator; | ||
674 | block_byte <<= 2; | ||
675 | block_len -= 1; | ||
676 | } | ||
677 | } | ||
678 | *start_pos = extra_pos; | ||
679 | *block_typestart_pos = block_type_pos; | ||
680 | return idx; | ||
681 | } | ||
682 | |||
683 | |||
684 | /* | ||
685 | * usbvision_parse_compress() | ||
686 | * | ||
687 | * Parse compressed frame from the scratch buffer, put | ||
688 | * decoded RGB value into the current frame buffer and add the written | ||
689 | * number of bytes (RGB) to the *pcopylen. | ||
690 | * | ||
691 | */ | ||
692 | static enum parse_state usbvision_parse_compress(struct usb_usbvision *usbvision, | ||
693 | long *pcopylen) | ||
694 | { | ||
695 | #define USBVISION_STRIP_MAGIC 0x5A | ||
696 | #define USBVISION_STRIP_LEN_MAX 400 | ||
697 | #define USBVISION_STRIP_HEADER_LEN 3 | ||
698 | |||
699 | struct usbvision_frame *frame; | ||
700 | unsigned char *f, *u = NULL, *v = NULL; | ||
701 | unsigned char strip_data[USBVISION_STRIP_LEN_MAX]; | ||
702 | unsigned char strip_header[USBVISION_STRIP_HEADER_LEN]; | ||
703 | int idx, idx_end, strip_len, strip_ptr, startblock_pos, block_pos, block_type_pos; | ||
704 | int clipmask_index; | ||
705 | int image_size; | ||
706 | unsigned char rv, gv, bv; | ||
707 | static unsigned char *Y, *U, *V; | ||
708 | |||
709 | frame = usbvision->cur_frame; | ||
710 | image_size = frame->frmwidth * frame->frmheight; | ||
711 | if ((frame->v4l2_format.format == V4L2_PIX_FMT_YUV422P) || | ||
712 | (frame->v4l2_format.format == V4L2_PIX_FMT_YVU420)) { /* this is a planar format */ | ||
713 | /* ... v4l2_linesize not used here. */ | ||
714 | f = frame->data + (frame->width * frame->curline); | ||
715 | } else | ||
716 | f = frame->data + (frame->v4l2_linesize * frame->curline); | ||
717 | |||
718 | if (frame->v4l2_format.format == V4L2_PIX_FMT_YUYV) { /* initialise u and v pointers */ | ||
719 | /* get base of u and b planes add halfoffset */ | ||
720 | u = frame->data | ||
721 | + image_size | ||
722 | + (frame->frmwidth >> 1) * frame->curline; | ||
723 | v = u + (image_size >> 1); | ||
724 | } else if (frame->v4l2_format.format == V4L2_PIX_FMT_YVU420) { | ||
725 | v = frame->data + image_size + ((frame->curline * (frame->width)) >> 2); | ||
726 | u = v + (image_size >> 2); | ||
727 | } | ||
728 | |||
729 | if (frame->curline == 0) | ||
730 | usbvision_adjust_compression(usbvision); | ||
731 | |||
732 | if (scratch_len(usbvision) < USBVISION_STRIP_HEADER_LEN) | ||
733 | return parse_state_out; | ||
734 | |||
735 | /* get strip header without changing the scratch_read_ptr */ | ||
736 | scratch_set_extra_ptr(usbvision, &strip_ptr, 0); | ||
737 | scratch_get_extra(usbvision, &strip_header[0], &strip_ptr, | ||
738 | USBVISION_STRIP_HEADER_LEN); | ||
739 | |||
740 | if (strip_header[0] != USBVISION_STRIP_MAGIC) { | ||
741 | /* wrong strip magic */ | ||
742 | usbvision->strip_magic_errors++; | ||
743 | return parse_state_next_frame; | ||
744 | } | ||
745 | |||
746 | if (frame->curline != (int)strip_header[2]) { | ||
747 | /* line number mismatch error */ | ||
748 | usbvision->strip_line_number_errors++; | ||
749 | } | ||
750 | |||
751 | strip_len = 2 * (unsigned int)strip_header[1]; | ||
752 | if (strip_len > USBVISION_STRIP_LEN_MAX) { | ||
753 | /* strip overrun */ | ||
754 | /* I think this never happens */ | ||
755 | usbvision_request_intra(usbvision); | ||
756 | } | ||
757 | |||
758 | if (scratch_len(usbvision) < strip_len) { | ||
759 | /* there is not enough data for the strip */ | ||
760 | return parse_state_out; | ||
761 | } | ||
762 | |||
763 | if (usbvision->intra_frame_buffer) { | ||
764 | Y = usbvision->intra_frame_buffer + frame->frmwidth * frame->curline; | ||
765 | U = usbvision->intra_frame_buffer + image_size + (frame->frmwidth / 2) * (frame->curline / 2); | ||
766 | V = usbvision->intra_frame_buffer + image_size / 4 * 5 + (frame->frmwidth / 2) * (frame->curline / 2); | ||
767 | } else { | ||
768 | return parse_state_next_frame; | ||
769 | } | ||
770 | |||
771 | clipmask_index = frame->curline * MAX_FRAME_WIDTH; | ||
772 | |||
773 | scratch_get(usbvision, strip_data, strip_len); | ||
774 | |||
775 | idx_end = frame->frmwidth; | ||
776 | block_type_pos = USBVISION_STRIP_HEADER_LEN; | ||
777 | startblock_pos = block_type_pos + (idx_end - 1) / 96 + (idx_end / 2 - 1) / 96 + 2; | ||
778 | block_pos = startblock_pos; | ||
779 | |||
780 | usbvision->block_pos = block_pos; | ||
781 | |||
782 | usbvision_decompress(usbvision, strip_data, Y, &block_pos, &block_type_pos, idx_end); | ||
783 | if (strip_len > usbvision->max_strip_len) | ||
784 | usbvision->max_strip_len = strip_len; | ||
785 | |||
786 | if (frame->curline % 2) | ||
787 | usbvision_decompress(usbvision, strip_data, V, &block_pos, &block_type_pos, idx_end / 2); | ||
788 | else | ||
789 | usbvision_decompress(usbvision, strip_data, U, &block_pos, &block_type_pos, idx_end / 2); | ||
790 | |||
791 | if (block_pos > usbvision->comprblock_pos) | ||
792 | usbvision->comprblock_pos = block_pos; | ||
793 | if (block_pos > strip_len) | ||
794 | usbvision->strip_len_errors++; | ||
795 | |||
796 | for (idx = 0; idx < idx_end; idx++) { | ||
797 | if (frame->v4l2_format.format == V4L2_PIX_FMT_YUYV) { | ||
798 | *f++ = Y[idx]; | ||
799 | *f++ = idx & 0x01 ? U[idx / 2] : V[idx / 2]; | ||
800 | } else if (frame->v4l2_format.format == V4L2_PIX_FMT_YUV422P) { | ||
801 | *f++ = Y[idx]; | ||
802 | if (idx & 0x01) | ||
803 | *u++ = U[idx >> 1]; | ||
804 | else | ||
805 | *v++ = V[idx >> 1]; | ||
806 | } else if (frame->v4l2_format.format == V4L2_PIX_FMT_YVU420) { | ||
807 | *f++ = Y[idx]; | ||
808 | if (!((idx & 0x01) | (frame->curline & 0x01))) { | ||
809 | /* only need do this for 1 in 4 pixels */ | ||
810 | /* intraframe buffer is YUV420 format */ | ||
811 | *u++ = U[idx >> 1]; | ||
812 | *v++ = V[idx >> 1]; | ||
813 | } | ||
814 | } else { | ||
815 | YUV_TO_RGB_BY_THE_BOOK(Y[idx], U[idx / 2], V[idx / 2], rv, gv, bv); | ||
816 | switch (frame->v4l2_format.format) { | ||
817 | case V4L2_PIX_FMT_GREY: | ||
818 | *f++ = Y[idx]; | ||
819 | break; | ||
820 | case V4L2_PIX_FMT_RGB555: | ||
821 | *f++ = (0x1F & rv) | | ||
822 | (0xE0 & (gv << 5)); | ||
823 | *f++ = (0x03 & (gv >> 3)) | | ||
824 | (0x7C & (bv << 2)); | ||
825 | break; | ||
826 | case V4L2_PIX_FMT_RGB565: | ||
827 | *f++ = (0x1F & rv) | | ||
828 | (0xE0 & (gv << 5)); | ||
829 | *f++ = (0x07 & (gv >> 3)) | | ||
830 | (0xF8 & bv); | ||
831 | break; | ||
832 | case V4L2_PIX_FMT_RGB24: | ||
833 | *f++ = rv; | ||
834 | *f++ = gv; | ||
835 | *f++ = bv; | ||
836 | break; | ||
837 | case V4L2_PIX_FMT_RGB32: | ||
838 | *f++ = rv; | ||
839 | *f++ = gv; | ||
840 | *f++ = bv; | ||
841 | f++; | ||
842 | break; | ||
843 | } | ||
844 | } | ||
845 | clipmask_index++; | ||
846 | } | ||
847 | /* Deal with non-integer no. of bytes for YUV420P */ | ||
848 | if (frame->v4l2_format.format != V4L2_PIX_FMT_YVU420) | ||
849 | *pcopylen += frame->v4l2_linesize; | ||
850 | else | ||
851 | *pcopylen += frame->curline & 0x01 ? frame->v4l2_linesize : frame->v4l2_linesize << 1; | ||
852 | |||
853 | frame->curline += 1; | ||
854 | |||
855 | if (frame->curline >= frame->frmheight) | ||
856 | return parse_state_next_frame; | ||
857 | return parse_state_continue; | ||
858 | |||
859 | } | ||
860 | |||
861 | |||
862 | /* | ||
863 | * usbvision_parse_lines_420() | ||
864 | * | ||
865 | * Parse two lines from the scratch buffer, put | ||
866 | * decoded RGB value into the current frame buffer and add the written | ||
867 | * number of bytes (RGB) to the *pcopylen. | ||
868 | * | ||
869 | */ | ||
870 | static enum parse_state usbvision_parse_lines_420(struct usb_usbvision *usbvision, | ||
871 | long *pcopylen) | ||
872 | { | ||
873 | struct usbvision_frame *frame; | ||
874 | unsigned char *f_even = NULL, *f_odd = NULL; | ||
875 | unsigned int pixel_per_line, block; | ||
876 | int pixel, block_split; | ||
877 | int y_ptr, u_ptr, v_ptr, y_odd_offset; | ||
878 | const int y_block_size = 128; | ||
879 | const int uv_block_size = 64; | ||
880 | const int sub_block_size = 32; | ||
881 | const int y_step[] = { 0, 0, 0, 2 }, y_step_size = 4; | ||
882 | const int uv_step[] = { 0, 0, 0, 4 }, uv_step_size = 4; | ||
883 | unsigned char y[2], u, v; /* YUV components */ | ||
884 | int y_, u_, v_, vb, uvg, ur; | ||
885 | int r_, g_, b_; /* RGB components */ | ||
886 | unsigned char g; | ||
887 | int clipmask_even_index, clipmask_odd_index, bytes_per_pixel; | ||
888 | int clipmask_add, stretch_bytes; | ||
889 | |||
890 | frame = usbvision->cur_frame; | ||
891 | f_even = frame->data + (frame->v4l2_linesize * frame->curline); | ||
892 | f_odd = f_even + frame->v4l2_linesize * usbvision->stretch_height; | ||
893 | |||
894 | /* Make sure there's enough data for the entire line */ | ||
895 | /* In this mode usbvision transfer 3 bytes for every 2 pixels */ | ||
896 | /* I need two lines to decode the color */ | ||
897 | bytes_per_pixel = frame->v4l2_format.bytes_per_pixel; | ||
898 | stretch_bytes = (usbvision->stretch_width - 1) * bytes_per_pixel; | ||
899 | clipmask_even_index = frame->curline * MAX_FRAME_WIDTH; | ||
900 | clipmask_odd_index = clipmask_even_index + MAX_FRAME_WIDTH; | ||
901 | clipmask_add = usbvision->stretch_width; | ||
902 | pixel_per_line = frame->isoc_header.frame_width; | ||
903 | |||
904 | if (scratch_len(usbvision) < (int)pixel_per_line * 3) { | ||
905 | /* printk(KERN_DEBUG "out of data, need %d\n", len); */ | ||
906 | return parse_state_out; | ||
907 | } | ||
908 | |||
909 | if ((frame->curline + 1) >= frame->frmheight) | ||
910 | return parse_state_next_frame; | ||
911 | |||
912 | block_split = (pixel_per_line%y_block_size) ? 1 : 0; /* are some blocks splitted into different lines? */ | ||
913 | |||
914 | y_odd_offset = (pixel_per_line / y_block_size) * (y_block_size + uv_block_size) | ||
915 | + block_split * uv_block_size; | ||
916 | |||
917 | scratch_set_extra_ptr(usbvision, &y_ptr, y_odd_offset); | ||
918 | scratch_set_extra_ptr(usbvision, &u_ptr, y_block_size); | ||
919 | scratch_set_extra_ptr(usbvision, &v_ptr, y_odd_offset | ||
920 | + (4 - block_split) * sub_block_size); | ||
921 | |||
922 | for (block = 0; block < (pixel_per_line / sub_block_size); block++) { | ||
923 | for (pixel = 0; pixel < sub_block_size; pixel += 2) { | ||
924 | scratch_get(usbvision, &y[0], 2); | ||
925 | scratch_get_extra(usbvision, &u, &u_ptr, 1); | ||
926 | scratch_get_extra(usbvision, &v, &v_ptr, 1); | ||
927 | |||
928 | /* I don't use the YUV_TO_RGB macro for better performance */ | ||
929 | v_ = v - 128; | ||
930 | u_ = u - 128; | ||
931 | vb = 132252 * v_; | ||
932 | uvg = -53281 * u_ - 25625 * v_; | ||
933 | ur = 104595 * u_; | ||
934 | |||
935 | if (frame->v4l2_format.format == V4L2_PIX_FMT_YUYV) { | ||
936 | *f_even++ = y[0]; | ||
937 | *f_even++ = v; | ||
938 | } else { | ||
939 | y_ = 76284 * (y[0] - 16); | ||
940 | |||
941 | b_ = (y_ + vb) >> 16; | ||
942 | g_ = (y_ + uvg) >> 16; | ||
943 | r_ = (y_ + ur) >> 16; | ||
944 | |||
945 | switch (frame->v4l2_format.format) { | ||
946 | case V4L2_PIX_FMT_RGB565: | ||
947 | g = LIMIT_RGB(g_); | ||
948 | *f_even++ = | ||
949 | (0x1F & LIMIT_RGB(r_)) | | ||
950 | (0xE0 & (g << 5)); | ||
951 | *f_even++ = | ||
952 | (0x07 & (g >> 3)) | | ||
953 | (0xF8 & LIMIT_RGB(b_)); | ||
954 | break; | ||
955 | case V4L2_PIX_FMT_RGB24: | ||
956 | *f_even++ = LIMIT_RGB(r_); | ||
957 | *f_even++ = LIMIT_RGB(g_); | ||
958 | *f_even++ = LIMIT_RGB(b_); | ||
959 | break; | ||
960 | case V4L2_PIX_FMT_RGB32: | ||
961 | *f_even++ = LIMIT_RGB(r_); | ||
962 | *f_even++ = LIMIT_RGB(g_); | ||
963 | *f_even++ = LIMIT_RGB(b_); | ||
964 | f_even++; | ||
965 | break; | ||
966 | case V4L2_PIX_FMT_RGB555: | ||
967 | g = LIMIT_RGB(g_); | ||
968 | *f_even++ = (0x1F & LIMIT_RGB(r_)) | | ||
969 | (0xE0 & (g << 5)); | ||
970 | *f_even++ = (0x03 & (g >> 3)) | | ||
971 | (0x7C & (LIMIT_RGB(b_) << 2)); | ||
972 | break; | ||
973 | } | ||
974 | } | ||
975 | clipmask_even_index += clipmask_add; | ||
976 | f_even += stretch_bytes; | ||
977 | |||
978 | if (frame->v4l2_format.format == V4L2_PIX_FMT_YUYV) { | ||
979 | *f_even++ = y[1]; | ||
980 | *f_even++ = u; | ||
981 | } else { | ||
982 | y_ = 76284 * (y[1] - 16); | ||
983 | |||
984 | b_ = (y_ + vb) >> 16; | ||
985 | g_ = (y_ + uvg) >> 16; | ||
986 | r_ = (y_ + ur) >> 16; | ||
987 | |||
988 | switch (frame->v4l2_format.format) { | ||
989 | case V4L2_PIX_FMT_RGB565: | ||
990 | g = LIMIT_RGB(g_); | ||
991 | *f_even++ = | ||
992 | (0x1F & LIMIT_RGB(r_)) | | ||
993 | (0xE0 & (g << 5)); | ||
994 | *f_even++ = | ||
995 | (0x07 & (g >> 3)) | | ||
996 | (0xF8 & LIMIT_RGB(b_)); | ||
997 | break; | ||
998 | case V4L2_PIX_FMT_RGB24: | ||
999 | *f_even++ = LIMIT_RGB(r_); | ||
1000 | *f_even++ = LIMIT_RGB(g_); | ||
1001 | *f_even++ = LIMIT_RGB(b_); | ||
1002 | break; | ||
1003 | case V4L2_PIX_FMT_RGB32: | ||
1004 | *f_even++ = LIMIT_RGB(r_); | ||
1005 | *f_even++ = LIMIT_RGB(g_); | ||
1006 | *f_even++ = LIMIT_RGB(b_); | ||
1007 | f_even++; | ||
1008 | break; | ||
1009 | case V4L2_PIX_FMT_RGB555: | ||
1010 | g = LIMIT_RGB(g_); | ||
1011 | *f_even++ = (0x1F & LIMIT_RGB(r_)) | | ||
1012 | (0xE0 & (g << 5)); | ||
1013 | *f_even++ = (0x03 & (g >> 3)) | | ||
1014 | (0x7C & (LIMIT_RGB(b_) << 2)); | ||
1015 | break; | ||
1016 | } | ||
1017 | } | ||
1018 | clipmask_even_index += clipmask_add; | ||
1019 | f_even += stretch_bytes; | ||
1020 | |||
1021 | scratch_get_extra(usbvision, &y[0], &y_ptr, 2); | ||
1022 | |||
1023 | if (frame->v4l2_format.format == V4L2_PIX_FMT_YUYV) { | ||
1024 | *f_odd++ = y[0]; | ||
1025 | *f_odd++ = v; | ||
1026 | } else { | ||
1027 | y_ = 76284 * (y[0] - 16); | ||
1028 | |||
1029 | b_ = (y_ + vb) >> 16; | ||
1030 | g_ = (y_ + uvg) >> 16; | ||
1031 | r_ = (y_ + ur) >> 16; | ||
1032 | |||
1033 | switch (frame->v4l2_format.format) { | ||
1034 | case V4L2_PIX_FMT_RGB565: | ||
1035 | g = LIMIT_RGB(g_); | ||
1036 | *f_odd++ = | ||
1037 | (0x1F & LIMIT_RGB(r_)) | | ||
1038 | (0xE0 & (g << 5)); | ||
1039 | *f_odd++ = | ||
1040 | (0x07 & (g >> 3)) | | ||
1041 | (0xF8 & LIMIT_RGB(b_)); | ||
1042 | break; | ||
1043 | case V4L2_PIX_FMT_RGB24: | ||
1044 | *f_odd++ = LIMIT_RGB(r_); | ||
1045 | *f_odd++ = LIMIT_RGB(g_); | ||
1046 | *f_odd++ = LIMIT_RGB(b_); | ||
1047 | break; | ||
1048 | case V4L2_PIX_FMT_RGB32: | ||
1049 | *f_odd++ = LIMIT_RGB(r_); | ||
1050 | *f_odd++ = LIMIT_RGB(g_); | ||
1051 | *f_odd++ = LIMIT_RGB(b_); | ||
1052 | f_odd++; | ||
1053 | break; | ||
1054 | case V4L2_PIX_FMT_RGB555: | ||
1055 | g = LIMIT_RGB(g_); | ||
1056 | *f_odd++ = (0x1F & LIMIT_RGB(r_)) | | ||
1057 | (0xE0 & (g << 5)); | ||
1058 | *f_odd++ = (0x03 & (g >> 3)) | | ||
1059 | (0x7C & (LIMIT_RGB(b_) << 2)); | ||
1060 | break; | ||
1061 | } | ||
1062 | } | ||
1063 | clipmask_odd_index += clipmask_add; | ||
1064 | f_odd += stretch_bytes; | ||
1065 | |||
1066 | if (frame->v4l2_format.format == V4L2_PIX_FMT_YUYV) { | ||
1067 | *f_odd++ = y[1]; | ||
1068 | *f_odd++ = u; | ||
1069 | } else { | ||
1070 | y_ = 76284 * (y[1] - 16); | ||
1071 | |||
1072 | b_ = (y_ + vb) >> 16; | ||
1073 | g_ = (y_ + uvg) >> 16; | ||
1074 | r_ = (y_ + ur) >> 16; | ||
1075 | |||
1076 | switch (frame->v4l2_format.format) { | ||
1077 | case V4L2_PIX_FMT_RGB565: | ||
1078 | g = LIMIT_RGB(g_); | ||
1079 | *f_odd++ = | ||
1080 | (0x1F & LIMIT_RGB(r_)) | | ||
1081 | (0xE0 & (g << 5)); | ||
1082 | *f_odd++ = | ||
1083 | (0x07 & (g >> 3)) | | ||
1084 | (0xF8 & LIMIT_RGB(b_)); | ||
1085 | break; | ||
1086 | case V4L2_PIX_FMT_RGB24: | ||
1087 | *f_odd++ = LIMIT_RGB(r_); | ||
1088 | *f_odd++ = LIMIT_RGB(g_); | ||
1089 | *f_odd++ = LIMIT_RGB(b_); | ||
1090 | break; | ||
1091 | case V4L2_PIX_FMT_RGB32: | ||
1092 | *f_odd++ = LIMIT_RGB(r_); | ||
1093 | *f_odd++ = LIMIT_RGB(g_); | ||
1094 | *f_odd++ = LIMIT_RGB(b_); | ||
1095 | f_odd++; | ||
1096 | break; | ||
1097 | case V4L2_PIX_FMT_RGB555: | ||
1098 | g = LIMIT_RGB(g_); | ||
1099 | *f_odd++ = (0x1F & LIMIT_RGB(r_)) | | ||
1100 | (0xE0 & (g << 5)); | ||
1101 | *f_odd++ = (0x03 & (g >> 3)) | | ||
1102 | (0x7C & (LIMIT_RGB(b_) << 2)); | ||
1103 | break; | ||
1104 | } | ||
1105 | } | ||
1106 | clipmask_odd_index += clipmask_add; | ||
1107 | f_odd += stretch_bytes; | ||
1108 | } | ||
1109 | |||
1110 | scratch_rm_old(usbvision, y_step[block % y_step_size] * sub_block_size); | ||
1111 | scratch_inc_extra_ptr(&y_ptr, y_step[(block + 2 * block_split) % y_step_size] | ||
1112 | * sub_block_size); | ||
1113 | scratch_inc_extra_ptr(&u_ptr, uv_step[block % uv_step_size] | ||
1114 | * sub_block_size); | ||
1115 | scratch_inc_extra_ptr(&v_ptr, uv_step[(block + 2 * block_split) % uv_step_size] | ||
1116 | * sub_block_size); | ||
1117 | } | ||
1118 | |||
1119 | scratch_rm_old(usbvision, pixel_per_line * 3 / 2 | ||
1120 | + block_split * sub_block_size); | ||
1121 | |||
1122 | frame->curline += 2 * usbvision->stretch_height; | ||
1123 | *pcopylen += frame->v4l2_linesize * 2 * usbvision->stretch_height; | ||
1124 | |||
1125 | if (frame->curline >= frame->frmheight) | ||
1126 | return parse_state_next_frame; | ||
1127 | return parse_state_continue; | ||
1128 | } | ||
1129 | |||
1130 | /* | ||
1131 | * usbvision_parse_data() | ||
1132 | * | ||
1133 | * Generic routine to parse the scratch buffer. It employs either | ||
1134 | * usbvision_find_header() or usbvision_parse_lines() to do most | ||
1135 | * of work. | ||
1136 | * | ||
1137 | */ | ||
1138 | static void usbvision_parse_data(struct usb_usbvision *usbvision) | ||
1139 | { | ||
1140 | struct usbvision_frame *frame; | ||
1141 | enum parse_state newstate; | ||
1142 | long copylen = 0; | ||
1143 | unsigned long lock_flags; | ||
1144 | |||
1145 | frame = usbvision->cur_frame; | ||
1146 | |||
1147 | PDEBUG(DBG_PARSE, "parsing len=%d\n", scratch_len(usbvision)); | ||
1148 | |||
1149 | while (1) { | ||
1150 | newstate = parse_state_out; | ||
1151 | if (scratch_len(usbvision)) { | ||
1152 | if (frame->scanstate == scan_state_scanning) { | ||
1153 | newstate = usbvision_find_header(usbvision); | ||
1154 | } else if (frame->scanstate == scan_state_lines) { | ||
1155 | if (usbvision->isoc_mode == ISOC_MODE_YUV420) | ||
1156 | newstate = usbvision_parse_lines_420(usbvision, ©len); | ||
1157 | else if (usbvision->isoc_mode == ISOC_MODE_YUV422) | ||
1158 | newstate = usbvision_parse_lines_422(usbvision, ©len); | ||
1159 | else if (usbvision->isoc_mode == ISOC_MODE_COMPRESS) | ||
1160 | newstate = usbvision_parse_compress(usbvision, ©len); | ||
1161 | } | ||
1162 | } | ||
1163 | if (newstate == parse_state_continue) | ||
1164 | continue; | ||
1165 | if ((newstate == parse_state_next_frame) || (newstate == parse_state_out)) | ||
1166 | break; | ||
1167 | return; /* parse_state_end_parse */ | ||
1168 | } | ||
1169 | |||
1170 | if (newstate == parse_state_next_frame) { | ||
1171 | frame->grabstate = frame_state_done; | ||
1172 | do_gettimeofday(&(frame->timestamp)); | ||
1173 | frame->sequence = usbvision->frame_num; | ||
1174 | |||
1175 | spin_lock_irqsave(&usbvision->queue_lock, lock_flags); | ||
1176 | list_move_tail(&(frame->frame), &usbvision->outqueue); | ||
1177 | usbvision->cur_frame = NULL; | ||
1178 | spin_unlock_irqrestore(&usbvision->queue_lock, lock_flags); | ||
1179 | |||
1180 | usbvision->frame_num++; | ||
1181 | |||
1182 | /* This will cause the process to request another frame. */ | ||
1183 | if (waitqueue_active(&usbvision->wait_frame)) { | ||
1184 | PDEBUG(DBG_PARSE, "Wake up !"); | ||
1185 | wake_up_interruptible(&usbvision->wait_frame); | ||
1186 | } | ||
1187 | } else { | ||
1188 | frame->grabstate = frame_state_grabbing; | ||
1189 | } | ||
1190 | |||
1191 | /* Update the frame's uncompressed length. */ | ||
1192 | frame->scanlength += copylen; | ||
1193 | } | ||
1194 | |||
1195 | |||
1196 | /* | ||
1197 | * Make all of the blocks of data contiguous | ||
1198 | */ | ||
1199 | static int usbvision_compress_isochronous(struct usb_usbvision *usbvision, | ||
1200 | struct urb *urb) | ||
1201 | { | ||
1202 | unsigned char *packet_data; | ||
1203 | int i, totlen = 0; | ||
1204 | |||
1205 | for (i = 0; i < urb->number_of_packets; i++) { | ||
1206 | int packet_len = urb->iso_frame_desc[i].actual_length; | ||
1207 | int packet_stat = urb->iso_frame_desc[i].status; | ||
1208 | |||
1209 | packet_data = urb->transfer_buffer + urb->iso_frame_desc[i].offset; | ||
1210 | |||
1211 | /* Detect and ignore errored packets */ | ||
1212 | if (packet_stat) { /* packet_stat != 0 ????????????? */ | ||
1213 | PDEBUG(DBG_ISOC, "data error: [%d] len=%d, status=%X", i, packet_len, packet_stat); | ||
1214 | usbvision->isoc_err_count++; | ||
1215 | continue; | ||
1216 | } | ||
1217 | |||
1218 | /* Detect and ignore empty packets */ | ||
1219 | if (packet_len < 0) { | ||
1220 | PDEBUG(DBG_ISOC, "error packet [%d]", i); | ||
1221 | usbvision->isoc_skip_count++; | ||
1222 | continue; | ||
1223 | } else if (packet_len == 0) { /* Frame end ????? */ | ||
1224 | PDEBUG(DBG_ISOC, "null packet [%d]", i); | ||
1225 | usbvision->isocstate = isoc_state_no_frame; | ||
1226 | usbvision->isoc_skip_count++; | ||
1227 | continue; | ||
1228 | } else if (packet_len > usbvision->isoc_packet_size) { | ||
1229 | PDEBUG(DBG_ISOC, "packet[%d] > isoc_packet_size", i); | ||
1230 | usbvision->isoc_skip_count++; | ||
1231 | continue; | ||
1232 | } | ||
1233 | |||
1234 | PDEBUG(DBG_ISOC, "packet ok [%d] len=%d", i, packet_len); | ||
1235 | |||
1236 | if (usbvision->isocstate == isoc_state_no_frame) { /* new frame begins */ | ||
1237 | usbvision->isocstate = isoc_state_in_frame; | ||
1238 | scratch_mark_header(usbvision); | ||
1239 | usbvision_measure_bandwidth(usbvision); | ||
1240 | PDEBUG(DBG_ISOC, "packet with header"); | ||
1241 | } | ||
1242 | |||
1243 | /* | ||
1244 | * If usbvision continues to feed us with data but there is no | ||
1245 | * consumption (if, for example, V4L client fell asleep) we | ||
1246 | * may overflow the buffer. We have to move old data over to | ||
1247 | * free room for new data. This is bad for old data. If we | ||
1248 | * just drop new data then it's bad for new data... choose | ||
1249 | * your favorite evil here. | ||
1250 | */ | ||
1251 | if (scratch_free(usbvision) < packet_len) { | ||
1252 | usbvision->scratch_ovf_count++; | ||
1253 | PDEBUG(DBG_ISOC, "scratch buf overflow! scr_len: %d, n: %d", | ||
1254 | scratch_len(usbvision), packet_len); | ||
1255 | scratch_rm_old(usbvision, packet_len - scratch_free(usbvision)); | ||
1256 | } | ||
1257 | |||
1258 | /* Now we know that there is enough room in scratch buffer */ | ||
1259 | scratch_put(usbvision, packet_data, packet_len); | ||
1260 | totlen += packet_len; | ||
1261 | usbvision->isoc_data_count += packet_len; | ||
1262 | usbvision->isoc_packet_count++; | ||
1263 | } | ||
1264 | #if ENABLE_HEXDUMP | ||
1265 | if (totlen > 0) { | ||
1266 | static int foo; | ||
1267 | |||
1268 | if (foo < 1) { | ||
1269 | printk(KERN_DEBUG "+%d.\n", usbvision->scratchlen); | ||
1270 | usbvision_hexdump(data0, (totlen > 64) ? 64 : totlen); | ||
1271 | ++foo; | ||
1272 | } | ||
1273 | } | ||
1274 | #endif | ||
1275 | return totlen; | ||
1276 | } | ||
1277 | |||
1278 | static void usbvision_isoc_irq(struct urb *urb) | ||
1279 | { | ||
1280 | int err_code = 0; | ||
1281 | int len; | ||
1282 | struct usb_usbvision *usbvision = urb->context; | ||
1283 | int i; | ||
1284 | unsigned long start_time = jiffies; | ||
1285 | struct usbvision_frame **f; | ||
1286 | |||
1287 | /* We don't want to do anything if we are about to be removed! */ | ||
1288 | if (!USBVISION_IS_OPERATIONAL(usbvision)) | ||
1289 | return; | ||
1290 | |||
1291 | /* any urb with wrong status is ignored without acknowledgement */ | ||
1292 | if (urb->status == -ENOENT) | ||
1293 | return; | ||
1294 | |||
1295 | f = &usbvision->cur_frame; | ||
1296 | |||
1297 | /* Manage streaming interruption */ | ||
1298 | if (usbvision->streaming == stream_interrupt) { | ||
1299 | usbvision->streaming = stream_idle; | ||
1300 | if ((*f)) { | ||
1301 | (*f)->grabstate = frame_state_ready; | ||
1302 | (*f)->scanstate = scan_state_scanning; | ||
1303 | } | ||
1304 | PDEBUG(DBG_IRQ, "stream interrupted"); | ||
1305 | wake_up_interruptible(&usbvision->wait_stream); | ||
1306 | } | ||
1307 | |||
1308 | /* Copy the data received into our scratch buffer */ | ||
1309 | len = usbvision_compress_isochronous(usbvision, urb); | ||
1310 | |||
1311 | usbvision->isoc_urb_count++; | ||
1312 | usbvision->urb_length = len; | ||
1313 | |||
1314 | if (usbvision->streaming == stream_on) { | ||
1315 | /* If we collected enough data let's parse! */ | ||
1316 | if (scratch_len(usbvision) > USBVISION_HEADER_LENGTH && | ||
1317 | !list_empty(&(usbvision->inqueue))) { | ||
1318 | if (!(*f)) { | ||
1319 | (*f) = list_entry(usbvision->inqueue.next, | ||
1320 | struct usbvision_frame, | ||
1321 | frame); | ||
1322 | } | ||
1323 | usbvision_parse_data(usbvision); | ||
1324 | } else { | ||
1325 | /* If we don't have a frame | ||
1326 | we're current working on, complain */ | ||
1327 | PDEBUG(DBG_IRQ, | ||
1328 | "received data, but no one needs it"); | ||
1329 | scratch_reset(usbvision); | ||
1330 | } | ||
1331 | } else { | ||
1332 | PDEBUG(DBG_IRQ, "received data, but no one needs it"); | ||
1333 | scratch_reset(usbvision); | ||
1334 | } | ||
1335 | |||
1336 | usbvision->time_in_irq += jiffies - start_time; | ||
1337 | |||
1338 | for (i = 0; i < USBVISION_URB_FRAMES; i++) { | ||
1339 | urb->iso_frame_desc[i].status = 0; | ||
1340 | urb->iso_frame_desc[i].actual_length = 0; | ||
1341 | } | ||
1342 | |||
1343 | urb->status = 0; | ||
1344 | urb->dev = usbvision->dev; | ||
1345 | err_code = usb_submit_urb(urb, GFP_ATOMIC); | ||
1346 | |||
1347 | if (err_code) { | ||
1348 | dev_err(&usbvision->dev->dev, | ||
1349 | "%s: usb_submit_urb failed: error %d\n", | ||
1350 | __func__, err_code); | ||
1351 | } | ||
1352 | |||
1353 | return; | ||
1354 | } | ||
1355 | |||
1356 | /*************************************/ | ||
1357 | /* Low level usbvision access functions */ | ||
1358 | /*************************************/ | ||
1359 | |||
1360 | /* | ||
1361 | * usbvision_read_reg() | ||
1362 | * | ||
1363 | * return < 0 -> Error | ||
1364 | * >= 0 -> Data | ||
1365 | */ | ||
1366 | |||
1367 | int usbvision_read_reg(struct usb_usbvision *usbvision, unsigned char reg) | ||
1368 | { | ||
1369 | int err_code = 0; | ||
1370 | unsigned char buffer[1]; | ||
1371 | |||
1372 | if (!USBVISION_IS_OPERATIONAL(usbvision)) | ||
1373 | return -1; | ||
1374 | |||
1375 | err_code = usb_control_msg(usbvision->dev, usb_rcvctrlpipe(usbvision->dev, 1), | ||
1376 | USBVISION_OP_CODE, | ||
1377 | USB_DIR_IN | USB_TYPE_VENDOR | USB_RECIP_ENDPOINT, | ||
1378 | 0, (__u16) reg, buffer, 1, HZ); | ||
1379 | |||
1380 | if (err_code < 0) { | ||
1381 | dev_err(&usbvision->dev->dev, | ||
1382 | "%s: failed: error %d\n", __func__, err_code); | ||
1383 | return err_code; | ||
1384 | } | ||
1385 | return buffer[0]; | ||
1386 | } | ||
1387 | |||
1388 | /* | ||
1389 | * usbvision_write_reg() | ||
1390 | * | ||
1391 | * return 1 -> Reg written | ||
1392 | * 0 -> usbvision is not yet ready | ||
1393 | * -1 -> Something went wrong | ||
1394 | */ | ||
1395 | |||
1396 | int usbvision_write_reg(struct usb_usbvision *usbvision, unsigned char reg, | ||
1397 | unsigned char value) | ||
1398 | { | ||
1399 | int err_code = 0; | ||
1400 | |||
1401 | if (!USBVISION_IS_OPERATIONAL(usbvision)) | ||
1402 | return 0; | ||
1403 | |||
1404 | err_code = usb_control_msg(usbvision->dev, usb_sndctrlpipe(usbvision->dev, 1), | ||
1405 | USBVISION_OP_CODE, | ||
1406 | USB_DIR_OUT | USB_TYPE_VENDOR | | ||
1407 | USB_RECIP_ENDPOINT, 0, (__u16) reg, &value, 1, HZ); | ||
1408 | |||
1409 | if (err_code < 0) { | ||
1410 | dev_err(&usbvision->dev->dev, | ||
1411 | "%s: failed: error %d\n", __func__, err_code); | ||
1412 | } | ||
1413 | return err_code; | ||
1414 | } | ||
1415 | |||
1416 | |||
1417 | static void usbvision_ctrl_urb_complete(struct urb *urb) | ||
1418 | { | ||
1419 | struct usb_usbvision *usbvision = (struct usb_usbvision *)urb->context; | ||
1420 | |||
1421 | PDEBUG(DBG_IRQ, ""); | ||
1422 | usbvision->ctrl_urb_busy = 0; | ||
1423 | if (waitqueue_active(&usbvision->ctrl_urb_wq)) | ||
1424 | wake_up_interruptible(&usbvision->ctrl_urb_wq); | ||
1425 | } | ||
1426 | |||
1427 | |||
1428 | static int usbvision_write_reg_irq(struct usb_usbvision *usbvision, int address, | ||
1429 | unsigned char *data, int len) | ||
1430 | { | ||
1431 | int err_code = 0; | ||
1432 | |||
1433 | PDEBUG(DBG_IRQ, ""); | ||
1434 | if (len > 8) | ||
1435 | return -EFAULT; | ||
1436 | if (usbvision->ctrl_urb_busy) | ||
1437 | return -EBUSY; | ||
1438 | usbvision->ctrl_urb_busy = 1; | ||
1439 | |||
1440 | usbvision->ctrl_urb_setup.bRequestType = USB_DIR_OUT | USB_TYPE_VENDOR | USB_RECIP_ENDPOINT; | ||
1441 | usbvision->ctrl_urb_setup.bRequest = USBVISION_OP_CODE; | ||
1442 | usbvision->ctrl_urb_setup.wValue = 0; | ||
1443 | usbvision->ctrl_urb_setup.wIndex = cpu_to_le16(address); | ||
1444 | usbvision->ctrl_urb_setup.wLength = cpu_to_le16(len); | ||
1445 | usb_fill_control_urb(usbvision->ctrl_urb, usbvision->dev, | ||
1446 | usb_sndctrlpipe(usbvision->dev, 1), | ||
1447 | (unsigned char *)&usbvision->ctrl_urb_setup, | ||
1448 | (void *)usbvision->ctrl_urb_buffer, len, | ||
1449 | usbvision_ctrl_urb_complete, | ||
1450 | (void *)usbvision); | ||
1451 | |||
1452 | memcpy(usbvision->ctrl_urb_buffer, data, len); | ||
1453 | |||
1454 | err_code = usb_submit_urb(usbvision->ctrl_urb, GFP_ATOMIC); | ||
1455 | if (err_code < 0) { | ||
1456 | /* error in usb_submit_urb() */ | ||
1457 | usbvision->ctrl_urb_busy = 0; | ||
1458 | } | ||
1459 | PDEBUG(DBG_IRQ, "submit %d byte: error %d", len, err_code); | ||
1460 | return err_code; | ||
1461 | } | ||
1462 | |||
1463 | |||
1464 | static int usbvision_init_compression(struct usb_usbvision *usbvision) | ||
1465 | { | ||
1466 | int err_code = 0; | ||
1467 | |||
1468 | usbvision->last_isoc_frame_num = -1; | ||
1469 | usbvision->isoc_data_count = 0; | ||
1470 | usbvision->isoc_packet_count = 0; | ||
1471 | usbvision->isoc_skip_count = 0; | ||
1472 | usbvision->compr_level = 50; | ||
1473 | usbvision->last_compr_level = -1; | ||
1474 | usbvision->isoc_urb_count = 0; | ||
1475 | usbvision->request_intra = 1; | ||
1476 | usbvision->isoc_measure_bandwidth_count = 0; | ||
1477 | |||
1478 | return err_code; | ||
1479 | } | ||
1480 | |||
1481 | /* this function measures the used bandwidth since last call | ||
1482 | * return: 0 : no error | ||
1483 | * sets used_bandwidth to 1-100 : 1-100% of full bandwidth resp. to isoc_packet_size | ||
1484 | */ | ||
1485 | static int usbvision_measure_bandwidth(struct usb_usbvision *usbvision) | ||
1486 | { | ||
1487 | int err_code = 0; | ||
1488 | |||
1489 | if (usbvision->isoc_measure_bandwidth_count < 2) { /* this gives an average bandwidth of 3 frames */ | ||
1490 | usbvision->isoc_measure_bandwidth_count++; | ||
1491 | return err_code; | ||
1492 | } | ||
1493 | if ((usbvision->isoc_packet_size > 0) && (usbvision->isoc_packet_count > 0)) { | ||
1494 | usbvision->used_bandwidth = usbvision->isoc_data_count / | ||
1495 | (usbvision->isoc_packet_count + usbvision->isoc_skip_count) * | ||
1496 | 100 / usbvision->isoc_packet_size; | ||
1497 | } | ||
1498 | usbvision->isoc_measure_bandwidth_count = 0; | ||
1499 | usbvision->isoc_data_count = 0; | ||
1500 | usbvision->isoc_packet_count = 0; | ||
1501 | usbvision->isoc_skip_count = 0; | ||
1502 | return err_code; | ||
1503 | } | ||
1504 | |||
1505 | static int usbvision_adjust_compression(struct usb_usbvision *usbvision) | ||
1506 | { | ||
1507 | int err_code = 0; | ||
1508 | unsigned char buffer[6]; | ||
1509 | |||
1510 | PDEBUG(DBG_IRQ, ""); | ||
1511 | if ((adjust_compression) && (usbvision->used_bandwidth > 0)) { | ||
1512 | usbvision->compr_level += (usbvision->used_bandwidth - 90) / 2; | ||
1513 | RESTRICT_TO_RANGE(usbvision->compr_level, 0, 100); | ||
1514 | if (usbvision->compr_level != usbvision->last_compr_level) { | ||
1515 | int distortion; | ||
1516 | |||
1517 | if (usbvision->bridge_type == BRIDGE_NT1004 || usbvision->bridge_type == BRIDGE_NT1005) { | ||
1518 | buffer[0] = (unsigned char)(4 + 16 * usbvision->compr_level / 100); /* PCM Threshold 1 */ | ||
1519 | buffer[1] = (unsigned char)(4 + 8 * usbvision->compr_level / 100); /* PCM Threshold 2 */ | ||
1520 | distortion = 7 + 248 * usbvision->compr_level / 100; | ||
1521 | buffer[2] = (unsigned char)(distortion & 0xFF); /* Average distortion Threshold (inter) */ | ||
1522 | buffer[3] = (unsigned char)(distortion & 0xFF); /* Average distortion Threshold (intra) */ | ||
1523 | distortion = 1 + 42 * usbvision->compr_level / 100; | ||
1524 | buffer[4] = (unsigned char)(distortion & 0xFF); /* Maximum distortion Threshold (inter) */ | ||
1525 | buffer[5] = (unsigned char)(distortion & 0xFF); /* Maximum distortion Threshold (intra) */ | ||
1526 | } else { /* BRIDGE_NT1003 */ | ||
1527 | buffer[0] = (unsigned char)(4 + 16 * usbvision->compr_level / 100); /* PCM threshold 1 */ | ||
1528 | buffer[1] = (unsigned char)(4 + 8 * usbvision->compr_level / 100); /* PCM threshold 2 */ | ||
1529 | distortion = 2 + 253 * usbvision->compr_level / 100; | ||
1530 | buffer[2] = (unsigned char)(distortion & 0xFF); /* distortion threshold bit0-7 */ | ||
1531 | buffer[3] = 0; /* (unsigned char)((distortion >> 8) & 0x0F); distortion threshold bit 8-11 */ | ||
1532 | distortion = 0 + 43 * usbvision->compr_level / 100; | ||
1533 | buffer[4] = (unsigned char)(distortion & 0xFF); /* maximum distortion bit0-7 */ | ||
1534 | buffer[5] = 0; /* (unsigned char)((distortion >> 8) & 0x01); maximum distortion bit 8 */ | ||
1535 | } | ||
1536 | err_code = usbvision_write_reg_irq(usbvision, USBVISION_PCM_THR1, buffer, 6); | ||
1537 | if (err_code == 0) { | ||
1538 | PDEBUG(DBG_IRQ, "new compr params %#02x %#02x %#02x %#02x %#02x %#02x", buffer[0], | ||
1539 | buffer[1], buffer[2], buffer[3], buffer[4], buffer[5]); | ||
1540 | usbvision->last_compr_level = usbvision->compr_level; | ||
1541 | } | ||
1542 | } | ||
1543 | } | ||
1544 | return err_code; | ||
1545 | } | ||
1546 | |||
1547 | static int usbvision_request_intra(struct usb_usbvision *usbvision) | ||
1548 | { | ||
1549 | int err_code = 0; | ||
1550 | unsigned char buffer[1]; | ||
1551 | |||
1552 | PDEBUG(DBG_IRQ, ""); | ||
1553 | usbvision->request_intra = 1; | ||
1554 | buffer[0] = 1; | ||
1555 | usbvision_write_reg_irq(usbvision, USBVISION_FORCE_INTRA, buffer, 1); | ||
1556 | return err_code; | ||
1557 | } | ||
1558 | |||
1559 | static int usbvision_unrequest_intra(struct usb_usbvision *usbvision) | ||
1560 | { | ||
1561 | int err_code = 0; | ||
1562 | unsigned char buffer[1]; | ||
1563 | |||
1564 | PDEBUG(DBG_IRQ, ""); | ||
1565 | usbvision->request_intra = 0; | ||
1566 | buffer[0] = 0; | ||
1567 | usbvision_write_reg_irq(usbvision, USBVISION_FORCE_INTRA, buffer, 1); | ||
1568 | return err_code; | ||
1569 | } | ||
1570 | |||
1571 | /******************************* | ||
1572 | * usbvision utility functions | ||
1573 | *******************************/ | ||
1574 | |||
1575 | int usbvision_power_off(struct usb_usbvision *usbvision) | ||
1576 | { | ||
1577 | int err_code = 0; | ||
1578 | |||
1579 | PDEBUG(DBG_FUNC, ""); | ||
1580 | |||
1581 | err_code = usbvision_write_reg(usbvision, USBVISION_PWR_REG, USBVISION_SSPND_EN); | ||
1582 | if (err_code == 1) | ||
1583 | usbvision->power = 0; | ||
1584 | PDEBUG(DBG_FUNC, "%s: err_code %d", (err_code != 1) ? "ERROR" : "power is off", err_code); | ||
1585 | return err_code; | ||
1586 | } | ||
1587 | |||
1588 | /* configure webcam image sensor using the serial port */ | ||
1589 | static int usbvision_init_webcam(struct usb_usbvision *usbvision) | ||
1590 | { | ||
1591 | int rc; | ||
1592 | int i; | ||
1593 | static char init_values[38][3] = { | ||
1594 | { 0x04, 0x12, 0x08 }, { 0x05, 0xff, 0xc8 }, { 0x06, 0x18, 0x07 }, { 0x07, 0x90, 0x00 }, | ||
1595 | { 0x09, 0x00, 0x00 }, { 0x0a, 0x00, 0x00 }, { 0x0b, 0x08, 0x00 }, { 0x0d, 0xcc, 0xcc }, | ||
1596 | { 0x0e, 0x13, 0x14 }, { 0x10, 0x9b, 0x83 }, { 0x11, 0x5a, 0x3f }, { 0x12, 0xe4, 0x73 }, | ||
1597 | { 0x13, 0x88, 0x84 }, { 0x14, 0x89, 0x80 }, { 0x15, 0x00, 0x20 }, { 0x16, 0x00, 0x00 }, | ||
1598 | { 0x17, 0xff, 0xa0 }, { 0x18, 0x6b, 0x20 }, { 0x19, 0x22, 0x40 }, { 0x1a, 0x10, 0x07 }, | ||
1599 | { 0x1b, 0x00, 0x47 }, { 0x1c, 0x03, 0xe0 }, { 0x1d, 0x00, 0x00 }, { 0x1e, 0x00, 0x00 }, | ||
1600 | { 0x1f, 0x00, 0x00 }, { 0x20, 0x00, 0x00 }, { 0x21, 0x00, 0x00 }, { 0x22, 0x00, 0x00 }, | ||
1601 | { 0x23, 0x00, 0x00 }, { 0x24, 0x00, 0x00 }, { 0x25, 0x00, 0x00 }, { 0x26, 0x00, 0x00 }, | ||
1602 | { 0x27, 0x00, 0x00 }, { 0x28, 0x00, 0x00 }, { 0x29, 0x00, 0x00 }, { 0x08, 0x80, 0x60 }, | ||
1603 | { 0x0f, 0x2d, 0x24 }, { 0x0c, 0x80, 0x80 } | ||
1604 | }; | ||
1605 | char value[3]; | ||
1606 | |||
1607 | /* the only difference between PAL and NTSC init_values */ | ||
1608 | if (usbvision_device_data[usbvision->dev_model].video_norm == V4L2_STD_NTSC) | ||
1609 | init_values[4][1] = 0x34; | ||
1610 | |||
1611 | for (i = 0; i < sizeof(init_values) / 3; i++) { | ||
1612 | usbvision_write_reg(usbvision, USBVISION_SER_MODE, USBVISION_SER_MODE_SOFT); | ||
1613 | memcpy(value, init_values[i], 3); | ||
1614 | rc = usb_control_msg(usbvision->dev, | ||
1615 | usb_sndctrlpipe(usbvision->dev, 1), | ||
1616 | USBVISION_OP_CODE, | ||
1617 | USB_DIR_OUT | USB_TYPE_VENDOR | | ||
1618 | USB_RECIP_ENDPOINT, 0, | ||
1619 | (__u16) USBVISION_SER_DAT1, value, | ||
1620 | 3, HZ); | ||
1621 | if (rc < 0) | ||
1622 | return rc; | ||
1623 | usbvision_write_reg(usbvision, USBVISION_SER_MODE, USBVISION_SER_MODE_SIO); | ||
1624 | /* write 3 bytes to the serial port using SIO mode */ | ||
1625 | usbvision_write_reg(usbvision, USBVISION_SER_CONT, 3 | 0x10); | ||
1626 | usbvision_write_reg(usbvision, USBVISION_IOPIN_REG, 0); | ||
1627 | usbvision_write_reg(usbvision, USBVISION_SER_MODE, USBVISION_SER_MODE_SOFT); | ||
1628 | usbvision_write_reg(usbvision, USBVISION_IOPIN_REG, USBVISION_IO_2); | ||
1629 | usbvision_write_reg(usbvision, USBVISION_SER_MODE, USBVISION_SER_MODE_SOFT | USBVISION_CLK_OUT); | ||
1630 | usbvision_write_reg(usbvision, USBVISION_SER_MODE, USBVISION_SER_MODE_SOFT | USBVISION_DAT_IO); | ||
1631 | usbvision_write_reg(usbvision, USBVISION_SER_MODE, USBVISION_SER_MODE_SOFT | USBVISION_CLK_OUT | USBVISION_DAT_IO); | ||
1632 | } | ||
1633 | |||
1634 | return 0; | ||
1635 | } | ||
1636 | |||
1637 | /* | ||
1638 | * usbvision_set_video_format() | ||
1639 | * | ||
1640 | */ | ||
1641 | static int usbvision_set_video_format(struct usb_usbvision *usbvision, int format) | ||
1642 | { | ||
1643 | static const char proc[] = "usbvision_set_video_format"; | ||
1644 | int rc; | ||
1645 | unsigned char value[2]; | ||
1646 | |||
1647 | if (!USBVISION_IS_OPERATIONAL(usbvision)) | ||
1648 | return 0; | ||
1649 | |||
1650 | PDEBUG(DBG_FUNC, "isoc_mode %#02x", format); | ||
1651 | |||
1652 | if ((format != ISOC_MODE_YUV422) | ||
1653 | && (format != ISOC_MODE_YUV420) | ||
1654 | && (format != ISOC_MODE_COMPRESS)) { | ||
1655 | printk(KERN_ERR "usbvision: unknown video format %02x, using default YUV420", | ||
1656 | format); | ||
1657 | format = ISOC_MODE_YUV420; | ||
1658 | } | ||
1659 | value[0] = 0x0A; /* TODO: See the effect of the filter */ | ||
1660 | value[1] = format; /* Sets the VO_MODE register which follows FILT_CONT */ | ||
1661 | rc = usb_control_msg(usbvision->dev, usb_sndctrlpipe(usbvision->dev, 1), | ||
1662 | USBVISION_OP_CODE, | ||
1663 | USB_DIR_OUT | USB_TYPE_VENDOR | | ||
1664 | USB_RECIP_ENDPOINT, 0, | ||
1665 | (__u16) USBVISION_FILT_CONT, value, 2, HZ); | ||
1666 | |||
1667 | if (rc < 0) { | ||
1668 | printk(KERN_ERR "%s: ERROR=%d. USBVISION stopped - " | ||
1669 | "reconnect or reload driver.\n", proc, rc); | ||
1670 | } | ||
1671 | usbvision->isoc_mode = format; | ||
1672 | return rc; | ||
1673 | } | ||
1674 | |||
1675 | /* | ||
1676 | * usbvision_set_output() | ||
1677 | * | ||
1678 | */ | ||
1679 | |||
1680 | int usbvision_set_output(struct usb_usbvision *usbvision, int width, | ||
1681 | int height) | ||
1682 | { | ||
1683 | int err_code = 0; | ||
1684 | int usb_width, usb_height; | ||
1685 | unsigned int frame_rate = 0, frame_drop = 0; | ||
1686 | unsigned char value[4]; | ||
1687 | |||
1688 | if (!USBVISION_IS_OPERATIONAL(usbvision)) | ||
1689 | return 0; | ||
1690 | |||
1691 | if (width > MAX_USB_WIDTH) { | ||
1692 | usb_width = width / 2; | ||
1693 | usbvision->stretch_width = 2; | ||
1694 | } else { | ||
1695 | usb_width = width; | ||
1696 | usbvision->stretch_width = 1; | ||
1697 | } | ||
1698 | |||
1699 | if (height > MAX_USB_HEIGHT) { | ||
1700 | usb_height = height / 2; | ||
1701 | usbvision->stretch_height = 2; | ||
1702 | } else { | ||
1703 | usb_height = height; | ||
1704 | usbvision->stretch_height = 1; | ||
1705 | } | ||
1706 | |||
1707 | RESTRICT_TO_RANGE(usb_width, MIN_FRAME_WIDTH, MAX_USB_WIDTH); | ||
1708 | usb_width &= ~(MIN_FRAME_WIDTH-1); | ||
1709 | RESTRICT_TO_RANGE(usb_height, MIN_FRAME_HEIGHT, MAX_USB_HEIGHT); | ||
1710 | usb_height &= ~(1); | ||
1711 | |||
1712 | PDEBUG(DBG_FUNC, "usb %dx%d; screen %dx%d; stretch %dx%d", | ||
1713 | usb_width, usb_height, width, height, | ||
1714 | usbvision->stretch_width, usbvision->stretch_height); | ||
1715 | |||
1716 | /* I'll not rewrite the same values */ | ||
1717 | if ((usb_width != usbvision->curwidth) || (usb_height != usbvision->curheight)) { | ||
1718 | value[0] = usb_width & 0xff; /* LSB */ | ||
1719 | value[1] = (usb_width >> 8) & 0x03; /* MSB */ | ||
1720 | value[2] = usb_height & 0xff; /* LSB */ | ||
1721 | value[3] = (usb_height >> 8) & 0x03; /* MSB */ | ||
1722 | |||
1723 | err_code = usb_control_msg(usbvision->dev, usb_sndctrlpipe(usbvision->dev, 1), | ||
1724 | USBVISION_OP_CODE, | ||
1725 | USB_DIR_OUT | USB_TYPE_VENDOR | USB_RECIP_ENDPOINT, | ||
1726 | 0, (__u16) USBVISION_LXSIZE_O, value, 4, HZ); | ||
1727 | |||
1728 | if (err_code < 0) { | ||
1729 | dev_err(&usbvision->dev->dev, | ||
1730 | "%s failed: error %d\n", __func__, err_code); | ||
1731 | return err_code; | ||
1732 | } | ||
1733 | usbvision->curwidth = usbvision->stretch_width * usb_width; | ||
1734 | usbvision->curheight = usbvision->stretch_height * usb_height; | ||
1735 | } | ||
1736 | |||
1737 | if (usbvision->isoc_mode == ISOC_MODE_YUV422) | ||
1738 | frame_rate = (usbvision->isoc_packet_size * 1000) / (usb_width * usb_height * 2); | ||
1739 | else if (usbvision->isoc_mode == ISOC_MODE_YUV420) | ||
1740 | frame_rate = (usbvision->isoc_packet_size * 1000) / ((usb_width * usb_height * 12) / 8); | ||
1741 | else | ||
1742 | frame_rate = FRAMERATE_MAX; | ||
1743 | |||
1744 | if (usbvision->tvnorm_id & V4L2_STD_625_50) | ||
1745 | frame_drop = frame_rate * 32 / 25 - 1; | ||
1746 | else if (usbvision->tvnorm_id & V4L2_STD_525_60) | ||
1747 | frame_drop = frame_rate * 32 / 30 - 1; | ||
1748 | |||
1749 | RESTRICT_TO_RANGE(frame_drop, FRAMERATE_MIN, FRAMERATE_MAX); | ||
1750 | |||
1751 | PDEBUG(DBG_FUNC, "frame_rate %d fps, frame_drop %d", frame_rate, frame_drop); | ||
1752 | |||
1753 | frame_drop = FRAMERATE_MAX; /* We can allow the maximum here, because dropping is controlled */ | ||
1754 | |||
1755 | if (usbvision_device_data[usbvision->dev_model].codec == CODEC_WEBCAM) { | ||
1756 | if (usbvision_device_data[usbvision->dev_model].video_norm == V4L2_STD_PAL) | ||
1757 | frame_drop = 25; | ||
1758 | else | ||
1759 | frame_drop = 30; | ||
1760 | } | ||
1761 | |||
1762 | /* frame_drop = 7; => frame_phase = 1, 5, 9, 13, 17, 21, 25, 0, 4, 8, ... | ||
1763 | => frame_skip = 4; | ||
1764 | => frame_rate = (7 + 1) * 25 / 32 = 200 / 32 = 6.25; | ||
1765 | |||
1766 | frame_drop = 9; => frame_phase = 1, 5, 8, 11, 14, 17, 21, 24, 27, 1, 4, 8, ... | ||
1767 | => frame_skip = 4, 3, 3, 3, 3, 4, 3, 3, 3, 3, 4, ... | ||
1768 | => frame_rate = (9 + 1) * 25 / 32 = 250 / 32 = 7.8125; | ||
1769 | */ | ||
1770 | err_code = usbvision_write_reg(usbvision, USBVISION_FRM_RATE, frame_drop); | ||
1771 | return err_code; | ||
1772 | } | ||
1773 | |||
1774 | |||
1775 | /* | ||
1776 | * usbvision_frames_alloc | ||
1777 | * allocate the required frames | ||
1778 | */ | ||
1779 | int usbvision_frames_alloc(struct usb_usbvision *usbvision, int number_of_frames) | ||
1780 | { | ||
1781 | int i; | ||
1782 | |||
1783 | /* needs to be page aligned cause the buffers can be mapped individually! */ | ||
1784 | usbvision->max_frame_size = PAGE_ALIGN(usbvision->curwidth * | ||
1785 | usbvision->curheight * | ||
1786 | usbvision->palette.bytes_per_pixel); | ||
1787 | |||
1788 | /* Try to do my best to allocate the frames the user want in the remaining memory */ | ||
1789 | usbvision->num_frames = number_of_frames; | ||
1790 | while (usbvision->num_frames > 0) { | ||
1791 | usbvision->fbuf_size = usbvision->num_frames * usbvision->max_frame_size; | ||
1792 | usbvision->fbuf = usbvision_rvmalloc(usbvision->fbuf_size); | ||
1793 | if (usbvision->fbuf) | ||
1794 | break; | ||
1795 | usbvision->num_frames--; | ||
1796 | } | ||
1797 | |||
1798 | spin_lock_init(&usbvision->queue_lock); | ||
1799 | init_waitqueue_head(&usbvision->wait_frame); | ||
1800 | init_waitqueue_head(&usbvision->wait_stream); | ||
1801 | |||
1802 | /* Allocate all buffers */ | ||
1803 | for (i = 0; i < usbvision->num_frames; i++) { | ||
1804 | usbvision->frame[i].index = i; | ||
1805 | usbvision->frame[i].grabstate = frame_state_unused; | ||
1806 | usbvision->frame[i].data = usbvision->fbuf + | ||
1807 | i * usbvision->max_frame_size; | ||
1808 | /* | ||
1809 | * Set default sizes for read operation. | ||
1810 | */ | ||
1811 | usbvision->stretch_width = 1; | ||
1812 | usbvision->stretch_height = 1; | ||
1813 | usbvision->frame[i].width = usbvision->curwidth; | ||
1814 | usbvision->frame[i].height = usbvision->curheight; | ||
1815 | usbvision->frame[i].bytes_read = 0; | ||
1816 | } | ||
1817 | PDEBUG(DBG_FUNC, "allocated %d frames (%d bytes per frame)", | ||
1818 | usbvision->num_frames, usbvision->max_frame_size); | ||
1819 | return usbvision->num_frames; | ||
1820 | } | ||
1821 | |||
1822 | /* | ||
1823 | * usbvision_frames_free | ||
1824 | * frees memory allocated for the frames | ||
1825 | */ | ||
1826 | void usbvision_frames_free(struct usb_usbvision *usbvision) | ||
1827 | { | ||
1828 | /* Have to free all that memory */ | ||
1829 | PDEBUG(DBG_FUNC, "free %d frames", usbvision->num_frames); | ||
1830 | |||
1831 | if (usbvision->fbuf != NULL) { | ||
1832 | usbvision_rvfree(usbvision->fbuf, usbvision->fbuf_size); | ||
1833 | usbvision->fbuf = NULL; | ||
1834 | |||
1835 | usbvision->num_frames = 0; | ||
1836 | } | ||
1837 | } | ||
1838 | /* | ||
1839 | * usbvision_empty_framequeues() | ||
1840 | * prepare queues for incoming and outgoing frames | ||
1841 | */ | ||
1842 | void usbvision_empty_framequeues(struct usb_usbvision *usbvision) | ||
1843 | { | ||
1844 | u32 i; | ||
1845 | |||
1846 | INIT_LIST_HEAD(&(usbvision->inqueue)); | ||
1847 | INIT_LIST_HEAD(&(usbvision->outqueue)); | ||
1848 | |||
1849 | for (i = 0; i < USBVISION_NUMFRAMES; i++) { | ||
1850 | usbvision->frame[i].grabstate = frame_state_unused; | ||
1851 | usbvision->frame[i].bytes_read = 0; | ||
1852 | } | ||
1853 | } | ||
1854 | |||
1855 | /* | ||
1856 | * usbvision_stream_interrupt() | ||
1857 | * stops streaming | ||
1858 | */ | ||
1859 | int usbvision_stream_interrupt(struct usb_usbvision *usbvision) | ||
1860 | { | ||
1861 | int ret = 0; | ||
1862 | |||
1863 | /* stop reading from the device */ | ||
1864 | |||
1865 | usbvision->streaming = stream_interrupt; | ||
1866 | ret = wait_event_timeout(usbvision->wait_stream, | ||
1867 | (usbvision->streaming == stream_idle), | ||
1868 | msecs_to_jiffies(USBVISION_NUMSBUF*USBVISION_URB_FRAMES)); | ||
1869 | return ret; | ||
1870 | } | ||
1871 | |||
1872 | /* | ||
1873 | * usbvision_set_compress_params() | ||
1874 | * | ||
1875 | */ | ||
1876 | |||
1877 | static int usbvision_set_compress_params(struct usb_usbvision *usbvision) | ||
1878 | { | ||
1879 | static const char proc[] = "usbvision_set_compresion_params: "; | ||
1880 | int rc; | ||
1881 | unsigned char value[6]; | ||
1882 | |||
1883 | value[0] = 0x0F; /* Intra-Compression cycle */ | ||
1884 | value[1] = 0x01; /* Reg.45 one line per strip */ | ||
1885 | value[2] = 0x00; /* Reg.46 Force intra mode on all new frames */ | ||
1886 | value[3] = 0x00; /* Reg.47 FORCE_UP <- 0 normal operation (not force) */ | ||
1887 | value[4] = 0xA2; /* Reg.48 BUF_THR I'm not sure if this does something in not compressed mode. */ | ||
1888 | value[5] = 0x00; /* Reg.49 DVI_YUV This has nothing to do with compression */ | ||
1889 | |||
1890 | /* catched values for NT1004 */ | ||
1891 | /* value[0] = 0xFF; Never apply intra mode automatically */ | ||
1892 | /* value[1] = 0xF1; Use full frame height for virtual strip width; One line per strip */ | ||
1893 | /* value[2] = 0x01; Force intra mode on all new frames */ | ||
1894 | /* value[3] = 0x00; Strip size 400 Bytes; do not force up */ | ||
1895 | /* value[4] = 0xA2; */ | ||
1896 | if (!USBVISION_IS_OPERATIONAL(usbvision)) | ||
1897 | return 0; | ||
1898 | |||
1899 | rc = usb_control_msg(usbvision->dev, usb_sndctrlpipe(usbvision->dev, 1), | ||
1900 | USBVISION_OP_CODE, | ||
1901 | USB_DIR_OUT | USB_TYPE_VENDOR | | ||
1902 | USB_RECIP_ENDPOINT, 0, | ||
1903 | (__u16) USBVISION_INTRA_CYC, value, 5, HZ); | ||
1904 | |||
1905 | if (rc < 0) { | ||
1906 | printk(KERN_ERR "%sERROR=%d. USBVISION stopped - " | ||
1907 | "reconnect or reload driver.\n", proc, rc); | ||
1908 | return rc; | ||
1909 | } | ||
1910 | |||
1911 | if (usbvision->bridge_type == BRIDGE_NT1004) { | ||
1912 | value[0] = 20; /* PCM Threshold 1 */ | ||
1913 | value[1] = 12; /* PCM Threshold 2 */ | ||
1914 | value[2] = 255; /* Distortion Threshold inter */ | ||
1915 | value[3] = 255; /* Distortion Threshold intra */ | ||
1916 | value[4] = 43; /* Max Distortion inter */ | ||
1917 | value[5] = 43; /* Max Distortion intra */ | ||
1918 | } else { | ||
1919 | value[0] = 20; /* PCM Threshold 1 */ | ||
1920 | value[1] = 12; /* PCM Threshold 2 */ | ||
1921 | value[2] = 255; /* Distortion Threshold d7-d0 */ | ||
1922 | value[3] = 0; /* Distortion Threshold d11-d8 */ | ||
1923 | value[4] = 43; /* Max Distortion d7-d0 */ | ||
1924 | value[5] = 0; /* Max Distortion d8 */ | ||
1925 | } | ||
1926 | |||
1927 | if (!USBVISION_IS_OPERATIONAL(usbvision)) | ||
1928 | return 0; | ||
1929 | |||
1930 | rc = usb_control_msg(usbvision->dev, usb_sndctrlpipe(usbvision->dev, 1), | ||
1931 | USBVISION_OP_CODE, | ||
1932 | USB_DIR_OUT | USB_TYPE_VENDOR | | ||
1933 | USB_RECIP_ENDPOINT, 0, | ||
1934 | (__u16) USBVISION_PCM_THR1, value, 6, HZ); | ||
1935 | |||
1936 | if (rc < 0) { | ||
1937 | printk(KERN_ERR "%sERROR=%d. USBVISION stopped - " | ||
1938 | "reconnect or reload driver.\n", proc, rc); | ||
1939 | } | ||
1940 | return rc; | ||
1941 | } | ||
1942 | |||
1943 | |||
1944 | /* | ||
1945 | * usbvision_set_input() | ||
1946 | * | ||
1947 | * Set the input (saa711x, ...) size x y and other misc input params | ||
1948 | * I've no idea if this parameters are right | ||
1949 | * | ||
1950 | */ | ||
1951 | int usbvision_set_input(struct usb_usbvision *usbvision) | ||
1952 | { | ||
1953 | static const char proc[] = "usbvision_set_input: "; | ||
1954 | int rc; | ||
1955 | unsigned char value[8]; | ||
1956 | unsigned char dvi_yuv_value; | ||
1957 | |||
1958 | if (!USBVISION_IS_OPERATIONAL(usbvision)) | ||
1959 | return 0; | ||
1960 | |||
1961 | /* Set input format expected from decoder*/ | ||
1962 | if (usbvision_device_data[usbvision->dev_model].vin_reg1_override) { | ||
1963 | value[0] = usbvision_device_data[usbvision->dev_model].vin_reg1; | ||
1964 | } else if (usbvision_device_data[usbvision->dev_model].codec == CODEC_SAA7113) { | ||
1965 | /* SAA7113 uses 8 bit output */ | ||
1966 | value[0] = USBVISION_8_422_SYNC; | ||
1967 | } else { | ||
1968 | /* I'm sure only about d2-d0 [010] 16 bit 4:2:2 usin sync pulses | ||
1969 | * as that is how saa7111 is configured */ | ||
1970 | value[0] = USBVISION_16_422_SYNC; | ||
1971 | /* | USBVISION_VSNC_POL | USBVISION_VCLK_POL);*/ | ||
1972 | } | ||
1973 | |||
1974 | rc = usbvision_write_reg(usbvision, USBVISION_VIN_REG1, value[0]); | ||
1975 | if (rc < 0) { | ||
1976 | printk(KERN_ERR "%sERROR=%d. USBVISION stopped - " | ||
1977 | "reconnect or reload driver.\n", proc, rc); | ||
1978 | return rc; | ||
1979 | } | ||
1980 | |||
1981 | |||
1982 | if (usbvision->tvnorm_id & V4L2_STD_PAL) { | ||
1983 | value[0] = 0xC0; | ||
1984 | value[1] = 0x02; /* 0x02C0 -> 704 Input video line length */ | ||
1985 | value[2] = 0x20; | ||
1986 | value[3] = 0x01; /* 0x0120 -> 288 Input video n. of lines */ | ||
1987 | value[4] = 0x60; | ||
1988 | value[5] = 0x00; /* 0x0060 -> 96 Input video h offset */ | ||
1989 | value[6] = 0x16; | ||
1990 | value[7] = 0x00; /* 0x0016 -> 22 Input video v offset */ | ||
1991 | } else if (usbvision->tvnorm_id & V4L2_STD_SECAM) { | ||
1992 | value[0] = 0xC0; | ||
1993 | value[1] = 0x02; /* 0x02C0 -> 704 Input video line length */ | ||
1994 | value[2] = 0x20; | ||
1995 | value[3] = 0x01; /* 0x0120 -> 288 Input video n. of lines */ | ||
1996 | value[4] = 0x01; | ||
1997 | value[5] = 0x00; /* 0x0001 -> 01 Input video h offset */ | ||
1998 | value[6] = 0x01; | ||
1999 | value[7] = 0x00; /* 0x0001 -> 01 Input video v offset */ | ||
2000 | } else { /* V4L2_STD_NTSC */ | ||
2001 | value[0] = 0xD0; | ||
2002 | value[1] = 0x02; /* 0x02D0 -> 720 Input video line length */ | ||
2003 | value[2] = 0xF0; | ||
2004 | value[3] = 0x00; /* 0x00F0 -> 240 Input video number of lines */ | ||
2005 | value[4] = 0x50; | ||
2006 | value[5] = 0x00; /* 0x0050 -> 80 Input video h offset */ | ||
2007 | value[6] = 0x10; | ||
2008 | value[7] = 0x00; /* 0x0010 -> 16 Input video v offset */ | ||
2009 | } | ||
2010 | |||
2011 | /* webcam is only 480 pixels wide, both PAL and NTSC version */ | ||
2012 | if (usbvision_device_data[usbvision->dev_model].codec == CODEC_WEBCAM) { | ||
2013 | value[0] = 0xe0; | ||
2014 | value[1] = 0x01; /* 0x01E0 -> 480 Input video line length */ | ||
2015 | } | ||
2016 | |||
2017 | if (usbvision_device_data[usbvision->dev_model].x_offset >= 0) { | ||
2018 | value[4] = usbvision_device_data[usbvision->dev_model].x_offset & 0xff; | ||
2019 | value[5] = (usbvision_device_data[usbvision->dev_model].x_offset & 0x0300) >> 8; | ||
2020 | } | ||
2021 | |||
2022 | if (adjust_x_offset != -1) { | ||
2023 | value[4] = adjust_x_offset & 0xff; | ||
2024 | value[5] = (adjust_x_offset & 0x0300) >> 8; | ||
2025 | } | ||
2026 | |||
2027 | if (usbvision_device_data[usbvision->dev_model].y_offset >= 0) { | ||
2028 | value[6] = usbvision_device_data[usbvision->dev_model].y_offset & 0xff; | ||
2029 | value[7] = (usbvision_device_data[usbvision->dev_model].y_offset & 0x0300) >> 8; | ||
2030 | } | ||
2031 | |||
2032 | if (adjust_y_offset != -1) { | ||
2033 | value[6] = adjust_y_offset & 0xff; | ||
2034 | value[7] = (adjust_y_offset & 0x0300) >> 8; | ||
2035 | } | ||
2036 | |||
2037 | rc = usb_control_msg(usbvision->dev, usb_sndctrlpipe(usbvision->dev, 1), | ||
2038 | USBVISION_OP_CODE, /* USBVISION specific code */ | ||
2039 | USB_DIR_OUT | USB_TYPE_VENDOR | USB_RECIP_ENDPOINT, 0, | ||
2040 | (__u16) USBVISION_LXSIZE_I, value, 8, HZ); | ||
2041 | if (rc < 0) { | ||
2042 | printk(KERN_ERR "%sERROR=%d. USBVISION stopped - " | ||
2043 | "reconnect or reload driver.\n", proc, rc); | ||
2044 | return rc; | ||
2045 | } | ||
2046 | |||
2047 | |||
2048 | dvi_yuv_value = 0x00; /* U comes after V, Ya comes after U/V, Yb comes after Yb */ | ||
2049 | |||
2050 | if (usbvision_device_data[usbvision->dev_model].dvi_yuv_override) { | ||
2051 | dvi_yuv_value = usbvision_device_data[usbvision->dev_model].dvi_yuv; | ||
2052 | } else if (usbvision_device_data[usbvision->dev_model].codec == CODEC_SAA7113) { | ||
2053 | /* This changes as the fine sync control changes. Further investigation necessary */ | ||
2054 | dvi_yuv_value = 0x06; | ||
2055 | } | ||
2056 | |||
2057 | return usbvision_write_reg(usbvision, USBVISION_DVI_YUV, dvi_yuv_value); | ||
2058 | } | ||
2059 | |||
2060 | |||
2061 | /* | ||
2062 | * usbvision_set_dram_settings() | ||
2063 | * | ||
2064 | * Set the buffer address needed by the usbvision dram to operate | ||
2065 | * This values has been taken with usbsnoop. | ||
2066 | * | ||
2067 | */ | ||
2068 | |||
2069 | static int usbvision_set_dram_settings(struct usb_usbvision *usbvision) | ||
2070 | { | ||
2071 | int rc; | ||
2072 | unsigned char value[8]; | ||
2073 | |||
2074 | if (usbvision->isoc_mode == ISOC_MODE_COMPRESS) { | ||
2075 | value[0] = 0x42; | ||
2076 | value[1] = 0x71; | ||
2077 | value[2] = 0xff; | ||
2078 | value[3] = 0x00; | ||
2079 | value[4] = 0x98; | ||
2080 | value[5] = 0xe0; | ||
2081 | value[6] = 0x71; | ||
2082 | value[7] = 0xff; | ||
2083 | /* UR: 0x0E200-0x3FFFF = 204288 Words (1 Word = 2 Byte) */ | ||
2084 | /* FDL: 0x00000-0x0E099 = 57498 Words */ | ||
2085 | /* VDW: 0x0E3FF-0x3FFFF */ | ||
2086 | } else { | ||
2087 | value[0] = 0x42; | ||
2088 | value[1] = 0x00; | ||
2089 | value[2] = 0xff; | ||
2090 | value[3] = 0x00; | ||
2091 | value[4] = 0x00; | ||
2092 | value[5] = 0x00; | ||
2093 | value[6] = 0x00; | ||
2094 | value[7] = 0xff; | ||
2095 | } | ||
2096 | /* These are the values of the address of the video buffer, | ||
2097 | * they have to be loaded into the USBVISION_DRM_PRM1-8 | ||
2098 | * | ||
2099 | * Start address of video output buffer for read: drm_prm1-2 -> 0x00000 | ||
2100 | * End address of video output buffer for read: drm_prm1-3 -> 0x1ffff | ||
2101 | * Start address of video frame delay buffer: drm_prm1-4 -> 0x20000 | ||
2102 | * Only used in compressed mode | ||
2103 | * End address of video frame delay buffer: drm_prm1-5-6 -> 0x3ffff | ||
2104 | * Only used in compressed mode | ||
2105 | * Start address of video output buffer for write: drm_prm1-7 -> 0x00000 | ||
2106 | * End address of video output buffer for write: drm_prm1-8 -> 0x1ffff | ||
2107 | */ | ||
2108 | |||
2109 | if (!USBVISION_IS_OPERATIONAL(usbvision)) | ||
2110 | return 0; | ||
2111 | |||
2112 | rc = usb_control_msg(usbvision->dev, usb_sndctrlpipe(usbvision->dev, 1), | ||
2113 | USBVISION_OP_CODE, /* USBVISION specific code */ | ||
2114 | USB_DIR_OUT | USB_TYPE_VENDOR | | ||
2115 | USB_RECIP_ENDPOINT, 0, | ||
2116 | (__u16) USBVISION_DRM_PRM1, value, 8, HZ); | ||
2117 | |||
2118 | if (rc < 0) { | ||
2119 | dev_err(&usbvision->dev->dev, "%s: ERROR=%d\n", __func__, rc); | ||
2120 | return rc; | ||
2121 | } | ||
2122 | |||
2123 | /* Restart the video buffer logic */ | ||
2124 | rc = usbvision_write_reg(usbvision, USBVISION_DRM_CONT, USBVISION_RES_UR | | ||
2125 | USBVISION_RES_FDL | USBVISION_RES_VDW); | ||
2126 | if (rc < 0) | ||
2127 | return rc; | ||
2128 | rc = usbvision_write_reg(usbvision, USBVISION_DRM_CONT, 0x00); | ||
2129 | |||
2130 | return rc; | ||
2131 | } | ||
2132 | |||
2133 | /* | ||
2134 | * () | ||
2135 | * | ||
2136 | * Power on the device, enables suspend-resume logic | ||
2137 | * & reset the isoc End-Point | ||
2138 | * | ||
2139 | */ | ||
2140 | |||
2141 | int usbvision_power_on(struct usb_usbvision *usbvision) | ||
2142 | { | ||
2143 | int err_code = 0; | ||
2144 | |||
2145 | PDEBUG(DBG_FUNC, ""); | ||
2146 | |||
2147 | usbvision_write_reg(usbvision, USBVISION_PWR_REG, USBVISION_SSPND_EN); | ||
2148 | usbvision_write_reg(usbvision, USBVISION_PWR_REG, | ||
2149 | USBVISION_SSPND_EN | USBVISION_RES2); | ||
2150 | |||
2151 | if (usbvision_device_data[usbvision->dev_model].codec == CODEC_WEBCAM) { | ||
2152 | usbvision_write_reg(usbvision, USBVISION_VIN_REG1, | ||
2153 | USBVISION_16_422_SYNC | USBVISION_HVALID_PO); | ||
2154 | usbvision_write_reg(usbvision, USBVISION_VIN_REG2, | ||
2155 | USBVISION_NOHVALID | USBVISION_KEEP_BLANK); | ||
2156 | } | ||
2157 | usbvision_write_reg(usbvision, USBVISION_PWR_REG, | ||
2158 | USBVISION_SSPND_EN | USBVISION_PWR_VID); | ||
2159 | mdelay(10); | ||
2160 | err_code = usbvision_write_reg(usbvision, USBVISION_PWR_REG, | ||
2161 | USBVISION_SSPND_EN | USBVISION_PWR_VID | USBVISION_RES2); | ||
2162 | if (err_code == 1) | ||
2163 | usbvision->power = 1; | ||
2164 | PDEBUG(DBG_FUNC, "%s: err_code %d", (err_code < 0) ? "ERROR" : "power is on", err_code); | ||
2165 | return err_code; | ||
2166 | } | ||
2167 | |||
2168 | |||
2169 | /* | ||
2170 | * usbvision timer stuff | ||
2171 | */ | ||
2172 | |||
2173 | /* to call usbvision_power_off from task queue */ | ||
2174 | static void call_usbvision_power_off(struct work_struct *work) | ||
2175 | { | ||
2176 | struct usb_usbvision *usbvision = container_of(work, struct usb_usbvision, power_off_work); | ||
2177 | |||
2178 | PDEBUG(DBG_FUNC, ""); | ||
2179 | if (mutex_lock_interruptible(&usbvision->v4l2_lock)) | ||
2180 | return; | ||
2181 | |||
2182 | if (usbvision->user == 0) { | ||
2183 | usbvision_i2c_unregister(usbvision); | ||
2184 | |||
2185 | usbvision_power_off(usbvision); | ||
2186 | usbvision->initialized = 0; | ||
2187 | } | ||
2188 | mutex_unlock(&usbvision->v4l2_lock); | ||
2189 | } | ||
2190 | |||
2191 | static void usbvision_power_off_timer(unsigned long data) | ||
2192 | { | ||
2193 | struct usb_usbvision *usbvision = (void *)data; | ||
2194 | |||
2195 | PDEBUG(DBG_FUNC, ""); | ||
2196 | del_timer(&usbvision->power_off_timer); | ||
2197 | INIT_WORK(&usbvision->power_off_work, call_usbvision_power_off); | ||
2198 | (void) schedule_work(&usbvision->power_off_work); | ||
2199 | } | ||
2200 | |||
2201 | void usbvision_init_power_off_timer(struct usb_usbvision *usbvision) | ||
2202 | { | ||
2203 | init_timer(&usbvision->power_off_timer); | ||
2204 | usbvision->power_off_timer.data = (long)usbvision; | ||
2205 | usbvision->power_off_timer.function = usbvision_power_off_timer; | ||
2206 | } | ||
2207 | |||
2208 | void usbvision_set_power_off_timer(struct usb_usbvision *usbvision) | ||
2209 | { | ||
2210 | mod_timer(&usbvision->power_off_timer, jiffies + USBVISION_POWEROFF_TIME); | ||
2211 | } | ||
2212 | |||
2213 | void usbvision_reset_power_off_timer(struct usb_usbvision *usbvision) | ||
2214 | { | ||
2215 | if (timer_pending(&usbvision->power_off_timer)) | ||
2216 | del_timer(&usbvision->power_off_timer); | ||
2217 | } | ||
2218 | |||
2219 | /* | ||
2220 | * usbvision_begin_streaming() | ||
2221 | * Sure you have to put bit 7 to 0, if not incoming frames are droped, but no | ||
2222 | * idea about the rest | ||
2223 | */ | ||
2224 | int usbvision_begin_streaming(struct usb_usbvision *usbvision) | ||
2225 | { | ||
2226 | if (usbvision->isoc_mode == ISOC_MODE_COMPRESS) | ||
2227 | usbvision_init_compression(usbvision); | ||
2228 | return usbvision_write_reg(usbvision, USBVISION_VIN_REG2, | ||
2229 | USBVISION_NOHVALID | usbvision->vin_reg2_preset); | ||
2230 | } | ||
2231 | |||
2232 | /* | ||
2233 | * usbvision_restart_isoc() | ||
2234 | * Not sure yet if touching here PWR_REG make loose the config | ||
2235 | */ | ||
2236 | |||
2237 | int usbvision_restart_isoc(struct usb_usbvision *usbvision) | ||
2238 | { | ||
2239 | int ret; | ||
2240 | |||
2241 | ret = usbvision_write_reg(usbvision, USBVISION_PWR_REG, | ||
2242 | USBVISION_SSPND_EN | USBVISION_PWR_VID); | ||
2243 | if (ret < 0) | ||
2244 | return ret; | ||
2245 | ret = usbvision_write_reg(usbvision, USBVISION_PWR_REG, | ||
2246 | USBVISION_SSPND_EN | USBVISION_PWR_VID | | ||
2247 | USBVISION_RES2); | ||
2248 | if (ret < 0) | ||
2249 | return ret; | ||
2250 | ret = usbvision_write_reg(usbvision, USBVISION_VIN_REG2, | ||
2251 | USBVISION_KEEP_BLANK | USBVISION_NOHVALID | | ||
2252 | usbvision->vin_reg2_preset); | ||
2253 | if (ret < 0) | ||
2254 | return ret; | ||
2255 | |||
2256 | /* TODO: schedule timeout */ | ||
2257 | while ((usbvision_read_reg(usbvision, USBVISION_STATUS_REG) & 0x01) != 1) | ||
2258 | ; | ||
2259 | |||
2260 | return 0; | ||
2261 | } | ||
2262 | |||
2263 | int usbvision_audio_off(struct usb_usbvision *usbvision) | ||
2264 | { | ||
2265 | if (usbvision_write_reg(usbvision, USBVISION_IOPIN_REG, USBVISION_AUDIO_MUTE) < 0) { | ||
2266 | printk(KERN_ERR "usbvision_audio_off: can't write reg\n"); | ||
2267 | return -1; | ||
2268 | } | ||
2269 | usbvision->audio_mute = 0; | ||
2270 | usbvision->audio_channel = USBVISION_AUDIO_MUTE; | ||
2271 | return 0; | ||
2272 | } | ||
2273 | |||
2274 | int usbvision_set_audio(struct usb_usbvision *usbvision, int audio_channel) | ||
2275 | { | ||
2276 | if (!usbvision->audio_mute) { | ||
2277 | if (usbvision_write_reg(usbvision, USBVISION_IOPIN_REG, audio_channel) < 0) { | ||
2278 | printk(KERN_ERR "usbvision_set_audio: can't write iopin register for audio switching\n"); | ||
2279 | return -1; | ||
2280 | } | ||
2281 | } | ||
2282 | usbvision->audio_channel = audio_channel; | ||
2283 | return 0; | ||
2284 | } | ||
2285 | |||
2286 | int usbvision_setup(struct usb_usbvision *usbvision, int format) | ||
2287 | { | ||
2288 | if (usbvision_device_data[usbvision->dev_model].codec == CODEC_WEBCAM) | ||
2289 | usbvision_init_webcam(usbvision); | ||
2290 | usbvision_set_video_format(usbvision, format); | ||
2291 | usbvision_set_dram_settings(usbvision); | ||
2292 | usbvision_set_compress_params(usbvision); | ||
2293 | usbvision_set_input(usbvision); | ||
2294 | usbvision_set_output(usbvision, MAX_USB_WIDTH, MAX_USB_HEIGHT); | ||
2295 | usbvision_restart_isoc(usbvision); | ||
2296 | |||
2297 | /* cosas del PCM */ | ||
2298 | return USBVISION_IS_OPERATIONAL(usbvision); | ||
2299 | } | ||
2300 | |||
2301 | int usbvision_set_alternate(struct usb_usbvision *dev) | ||
2302 | { | ||
2303 | int err_code, prev_alt = dev->iface_alt; | ||
2304 | int i; | ||
2305 | |||
2306 | dev->iface_alt = 0; | ||
2307 | for (i = 0; i < dev->num_alt; i++) | ||
2308 | if (dev->alt_max_pkt_size[i] > dev->alt_max_pkt_size[dev->iface_alt]) | ||
2309 | dev->iface_alt = i; | ||
2310 | |||
2311 | if (dev->iface_alt != prev_alt) { | ||
2312 | dev->isoc_packet_size = dev->alt_max_pkt_size[dev->iface_alt]; | ||
2313 | PDEBUG(DBG_FUNC, "setting alternate %d with max_packet_size=%u", | ||
2314 | dev->iface_alt, dev->isoc_packet_size); | ||
2315 | err_code = usb_set_interface(dev->dev, dev->iface, dev->iface_alt); | ||
2316 | if (err_code < 0) { | ||
2317 | dev_err(&dev->dev->dev, | ||
2318 | "cannot change alternate number to %d (error=%i)\n", | ||
2319 | dev->iface_alt, err_code); | ||
2320 | return err_code; | ||
2321 | } | ||
2322 | } | ||
2323 | |||
2324 | PDEBUG(DBG_ISOC, "ISO Packet Length:%d", dev->isoc_packet_size); | ||
2325 | |||
2326 | return 0; | ||
2327 | } | ||
2328 | |||
2329 | /* | ||
2330 | * usbvision_init_isoc() | ||
2331 | * | ||
2332 | */ | ||
2333 | int usbvision_init_isoc(struct usb_usbvision *usbvision) | ||
2334 | { | ||
2335 | struct usb_device *dev = usbvision->dev; | ||
2336 | int buf_idx, err_code, reg_value; | ||
2337 | int sb_size; | ||
2338 | |||
2339 | if (!USBVISION_IS_OPERATIONAL(usbvision)) | ||
2340 | return -EFAULT; | ||
2341 | |||
2342 | usbvision->cur_frame = NULL; | ||
2343 | scratch_reset(usbvision); | ||
2344 | |||
2345 | /* Alternate interface 1 is is the biggest frame size */ | ||
2346 | err_code = usbvision_set_alternate(usbvision); | ||
2347 | if (err_code < 0) { | ||
2348 | usbvision->last_error = err_code; | ||
2349 | return -EBUSY; | ||
2350 | } | ||
2351 | sb_size = USBVISION_URB_FRAMES * usbvision->isoc_packet_size; | ||
2352 | |||
2353 | reg_value = (16 - usbvision_read_reg(usbvision, | ||
2354 | USBVISION_ALTER_REG)) & 0x0F; | ||
2355 | |||
2356 | usbvision->usb_bandwidth = reg_value >> 1; | ||
2357 | PDEBUG(DBG_ISOC, "USB Bandwidth Usage: %dMbit/Sec", | ||
2358 | usbvision->usb_bandwidth); | ||
2359 | |||
2360 | |||
2361 | |||
2362 | /* We double buffer the Iso lists */ | ||
2363 | |||
2364 | for (buf_idx = 0; buf_idx < USBVISION_NUMSBUF; buf_idx++) { | ||
2365 | int j, k; | ||
2366 | struct urb *urb; | ||
2367 | |||
2368 | urb = usb_alloc_urb(USBVISION_URB_FRAMES, GFP_KERNEL); | ||
2369 | if (urb == NULL) { | ||
2370 | dev_err(&usbvision->dev->dev, | ||
2371 | "%s: usb_alloc_urb() failed\n", __func__); | ||
2372 | return -ENOMEM; | ||
2373 | } | ||
2374 | usbvision->sbuf[buf_idx].urb = urb; | ||
2375 | usbvision->sbuf[buf_idx].data = | ||
2376 | usb_alloc_coherent(usbvision->dev, | ||
2377 | sb_size, | ||
2378 | GFP_KERNEL, | ||
2379 | &urb->transfer_dma); | ||
2380 | urb->dev = dev; | ||
2381 | urb->context = usbvision; | ||
2382 | urb->pipe = usb_rcvisocpipe(dev, usbvision->video_endp); | ||
2383 | urb->transfer_flags = URB_ISO_ASAP | URB_NO_TRANSFER_DMA_MAP; | ||
2384 | urb->interval = 1; | ||
2385 | urb->transfer_buffer = usbvision->sbuf[buf_idx].data; | ||
2386 | urb->complete = usbvision_isoc_irq; | ||
2387 | urb->number_of_packets = USBVISION_URB_FRAMES; | ||
2388 | urb->transfer_buffer_length = | ||
2389 | usbvision->isoc_packet_size * USBVISION_URB_FRAMES; | ||
2390 | for (j = k = 0; j < USBVISION_URB_FRAMES; j++, | ||
2391 | k += usbvision->isoc_packet_size) { | ||
2392 | urb->iso_frame_desc[j].offset = k; | ||
2393 | urb->iso_frame_desc[j].length = | ||
2394 | usbvision->isoc_packet_size; | ||
2395 | } | ||
2396 | } | ||
2397 | |||
2398 | /* Submit all URBs */ | ||
2399 | for (buf_idx = 0; buf_idx < USBVISION_NUMSBUF; buf_idx++) { | ||
2400 | err_code = usb_submit_urb(usbvision->sbuf[buf_idx].urb, | ||
2401 | GFP_KERNEL); | ||
2402 | if (err_code) { | ||
2403 | dev_err(&usbvision->dev->dev, | ||
2404 | "%s: usb_submit_urb(%d) failed: error %d\n", | ||
2405 | __func__, buf_idx, err_code); | ||
2406 | } | ||
2407 | } | ||
2408 | |||
2409 | usbvision->streaming = stream_idle; | ||
2410 | PDEBUG(DBG_ISOC, "%s: streaming=1 usbvision->video_endp=$%02x", | ||
2411 | __func__, | ||
2412 | usbvision->video_endp); | ||
2413 | return 0; | ||
2414 | } | ||
2415 | |||
2416 | /* | ||
2417 | * usbvision_stop_isoc() | ||
2418 | * | ||
2419 | * This procedure stops streaming and deallocates URBs. Then it | ||
2420 | * activates zero-bandwidth alt. setting of the video interface. | ||
2421 | * | ||
2422 | */ | ||
2423 | void usbvision_stop_isoc(struct usb_usbvision *usbvision) | ||
2424 | { | ||
2425 | int buf_idx, err_code, reg_value; | ||
2426 | int sb_size = USBVISION_URB_FRAMES * usbvision->isoc_packet_size; | ||
2427 | |||
2428 | if ((usbvision->streaming == stream_off) || (usbvision->dev == NULL)) | ||
2429 | return; | ||
2430 | |||
2431 | /* Unschedule all of the iso td's */ | ||
2432 | for (buf_idx = 0; buf_idx < USBVISION_NUMSBUF; buf_idx++) { | ||
2433 | usb_kill_urb(usbvision->sbuf[buf_idx].urb); | ||
2434 | if (usbvision->sbuf[buf_idx].data) { | ||
2435 | usb_free_coherent(usbvision->dev, | ||
2436 | sb_size, | ||
2437 | usbvision->sbuf[buf_idx].data, | ||
2438 | usbvision->sbuf[buf_idx].urb->transfer_dma); | ||
2439 | } | ||
2440 | usb_free_urb(usbvision->sbuf[buf_idx].urb); | ||
2441 | usbvision->sbuf[buf_idx].urb = NULL; | ||
2442 | } | ||
2443 | |||
2444 | PDEBUG(DBG_ISOC, "%s: streaming=stream_off\n", __func__); | ||
2445 | usbvision->streaming = stream_off; | ||
2446 | |||
2447 | if (!usbvision->remove_pending) { | ||
2448 | /* Set packet size to 0 */ | ||
2449 | usbvision->iface_alt = 0; | ||
2450 | err_code = usb_set_interface(usbvision->dev, usbvision->iface, | ||
2451 | usbvision->iface_alt); | ||
2452 | if (err_code < 0) { | ||
2453 | dev_err(&usbvision->dev->dev, | ||
2454 | "%s: usb_set_interface() failed: error %d\n", | ||
2455 | __func__, err_code); | ||
2456 | usbvision->last_error = err_code; | ||
2457 | } | ||
2458 | reg_value = (16-usbvision_read_reg(usbvision, USBVISION_ALTER_REG)) & 0x0F; | ||
2459 | usbvision->isoc_packet_size = | ||
2460 | (reg_value == 0) ? 0 : (reg_value * 64) - 1; | ||
2461 | PDEBUG(DBG_ISOC, "ISO Packet Length:%d", | ||
2462 | usbvision->isoc_packet_size); | ||
2463 | |||
2464 | usbvision->usb_bandwidth = reg_value >> 1; | ||
2465 | PDEBUG(DBG_ISOC, "USB Bandwidth Usage: %dMbit/Sec", | ||
2466 | usbvision->usb_bandwidth); | ||
2467 | } | ||
2468 | } | ||
2469 | |||
2470 | int usbvision_muxsel(struct usb_usbvision *usbvision, int channel) | ||
2471 | { | ||
2472 | /* inputs #0 and #3 are constant for every SAA711x. */ | ||
2473 | /* inputs #1 and #2 are variable for SAA7111 and SAA7113 */ | ||
2474 | int mode[4] = { SAA7115_COMPOSITE0, 0, 0, SAA7115_COMPOSITE3 }; | ||
2475 | int audio[] = { 1, 0, 0, 0 }; | ||
2476 | /* channel 0 is TV with audiochannel 1 (tuner mono) */ | ||
2477 | /* channel 1 is Composite with audio channel 0 (line in) */ | ||
2478 | /* channel 2 is S-Video with audio channel 0 (line in) */ | ||
2479 | /* channel 3 is additional video inputs to the device with audio channel 0 (line in) */ | ||
2480 | |||
2481 | RESTRICT_TO_RANGE(channel, 0, usbvision->video_inputs); | ||
2482 | usbvision->ctl_input = channel; | ||
2483 | |||
2484 | /* set the new channel */ | ||
2485 | /* Regular USB TV Tuners -> channel: 0 = Television, 1 = Composite, 2 = S-Video */ | ||
2486 | /* Four video input devices -> channel: 0 = Chan White, 1 = Chan Green, 2 = Chan Yellow, 3 = Chan Red */ | ||
2487 | |||
2488 | switch (usbvision_device_data[usbvision->dev_model].codec) { | ||
2489 | case CODEC_SAA7113: | ||
2490 | mode[1] = SAA7115_COMPOSITE2; | ||
2491 | if (switch_svideo_input) { | ||
2492 | /* To handle problems with S-Video Input for | ||
2493 | * some devices. Use switch_svideo_input | ||
2494 | * parameter when loading the module.*/ | ||
2495 | mode[2] = SAA7115_COMPOSITE1; | ||
2496 | } else { | ||
2497 | mode[2] = SAA7115_SVIDEO1; | ||
2498 | } | ||
2499 | break; | ||
2500 | case CODEC_SAA7111: | ||
2501 | default: | ||
2502 | /* modes for saa7111 */ | ||
2503 | mode[1] = SAA7115_COMPOSITE1; | ||
2504 | mode[2] = SAA7115_SVIDEO1; | ||
2505 | break; | ||
2506 | } | ||
2507 | call_all(usbvision, video, s_routing, mode[channel], 0, 0); | ||
2508 | usbvision_set_audio(usbvision, audio[channel]); | ||
2509 | return 0; | ||
2510 | } | ||
2511 | |||
2512 | /* | ||
2513 | * Overrides for Emacs so that we follow Linus's tabbing style. | ||
2514 | * --------------------------------------------------------------------------- | ||
2515 | * Local variables: | ||
2516 | * c-basic-offset: 8 | ||
2517 | * End: | ||
2518 | */ | ||
diff --git a/drivers/media/usb/usbvision/usbvision-i2c.c b/drivers/media/usb/usbvision/usbvision-i2c.c new file mode 100644 index 000000000000..89fec029e924 --- /dev/null +++ b/drivers/media/usb/usbvision/usbvision-i2c.c | |||
@@ -0,0 +1,456 @@ | |||
1 | /* | ||
2 | * usbvision_i2c.c | ||
3 | * i2c algorithm for USB-I2C Bridges | ||
4 | * | ||
5 | * Copyright (c) 1999-2007 Joerg Heckenbach <joerg@heckenbach-aw.de> | ||
6 | * Dwaine Garden <dwainegarden@rogers.com> | ||
7 | * | ||
8 | * This module is part of usbvision driver project. | ||
9 | * Updates to driver completed by Dwaine P. Garden | ||
10 | * | ||
11 | * This program is free software; you can redistribute it and/or modify | ||
12 | * it under the terms of the GNU General Public License as published by | ||
13 | * the Free Software Foundation; either version 2 of the License, or | ||
14 | * (at your option) any later version. | ||
15 | * | ||
16 | * This program is distributed in the hope that it will be useful, | ||
17 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
18 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
19 | * GNU General Public License for more details. | ||
20 | * | ||
21 | * You should have received a copy of the GNU General Public License | ||
22 | * along with this program; if not, write to the Free Software | ||
23 | * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. | ||
24 | */ | ||
25 | |||
26 | |||
27 | #include <linux/kernel.h> | ||
28 | #include <linux/module.h> | ||
29 | #include <linux/delay.h> | ||
30 | #include <linux/init.h> | ||
31 | #include <linux/uaccess.h> | ||
32 | #include <linux/ioport.h> | ||
33 | #include <linux/errno.h> | ||
34 | #include <linux/usb.h> | ||
35 | #include <linux/i2c.h> | ||
36 | #include "usbvision.h" | ||
37 | |||
38 | #define DBG_I2C (1 << 0) | ||
39 | |||
40 | static int i2c_debug; | ||
41 | |||
42 | module_param(i2c_debug, int, 0644); /* debug_i2c_usb mode of the device driver */ | ||
43 | MODULE_PARM_DESC(i2c_debug, "enable debug messages [i2c]"); | ||
44 | |||
45 | #define PDEBUG(level, fmt, args...) { \ | ||
46 | if (i2c_debug & (level)) \ | ||
47 | printk(KERN_INFO KBUILD_MODNAME ":[%s:%d] " fmt, \ | ||
48 | __func__, __LINE__ , ## args); \ | ||
49 | } | ||
50 | |||
51 | static int usbvision_i2c_write(struct usb_usbvision *usbvision, unsigned char addr, char *buf, | ||
52 | short len); | ||
53 | static int usbvision_i2c_read(struct usb_usbvision *usbvision, unsigned char addr, char *buf, | ||
54 | short len); | ||
55 | |||
56 | static inline int try_write_address(struct i2c_adapter *i2c_adap, | ||
57 | unsigned char addr, int retries) | ||
58 | { | ||
59 | struct usb_usbvision *usbvision; | ||
60 | int i, ret = -1; | ||
61 | char buf[4]; | ||
62 | |||
63 | usbvision = (struct usb_usbvision *)i2c_get_adapdata(i2c_adap); | ||
64 | buf[0] = 0x00; | ||
65 | for (i = 0; i <= retries; i++) { | ||
66 | ret = (usbvision_i2c_write(usbvision, addr, buf, 1)); | ||
67 | if (ret == 1) | ||
68 | break; /* success! */ | ||
69 | udelay(5); | ||
70 | if (i == retries) /* no success */ | ||
71 | break; | ||
72 | udelay(10); | ||
73 | } | ||
74 | if (i) { | ||
75 | PDEBUG(DBG_I2C, "Needed %d retries for address %#2x", i, addr); | ||
76 | PDEBUG(DBG_I2C, "Maybe there's no device at this address"); | ||
77 | } | ||
78 | return ret; | ||
79 | } | ||
80 | |||
81 | static inline int try_read_address(struct i2c_adapter *i2c_adap, | ||
82 | unsigned char addr, int retries) | ||
83 | { | ||
84 | struct usb_usbvision *usbvision; | ||
85 | int i, ret = -1; | ||
86 | char buf[4]; | ||
87 | |||
88 | usbvision = (struct usb_usbvision *)i2c_get_adapdata(i2c_adap); | ||
89 | for (i = 0; i <= retries; i++) { | ||
90 | ret = (usbvision_i2c_read(usbvision, addr, buf, 1)); | ||
91 | if (ret == 1) | ||
92 | break; /* success! */ | ||
93 | udelay(5); | ||
94 | if (i == retries) /* no success */ | ||
95 | break; | ||
96 | udelay(10); | ||
97 | } | ||
98 | if (i) { | ||
99 | PDEBUG(DBG_I2C, "Needed %d retries for address %#2x", i, addr); | ||
100 | PDEBUG(DBG_I2C, "Maybe there's no device at this address"); | ||
101 | } | ||
102 | return ret; | ||
103 | } | ||
104 | |||
105 | static inline int usb_find_address(struct i2c_adapter *i2c_adap, | ||
106 | struct i2c_msg *msg, int retries, | ||
107 | unsigned char *add) | ||
108 | { | ||
109 | unsigned short flags = msg->flags; | ||
110 | |||
111 | unsigned char addr; | ||
112 | int ret; | ||
113 | |||
114 | addr = (msg->addr << 1); | ||
115 | if (flags & I2C_M_RD) | ||
116 | addr |= 1; | ||
117 | |||
118 | add[0] = addr; | ||
119 | if (flags & I2C_M_RD) | ||
120 | ret = try_read_address(i2c_adap, addr, retries); | ||
121 | else | ||
122 | ret = try_write_address(i2c_adap, addr, retries); | ||
123 | |||
124 | if (ret != 1) | ||
125 | return -EREMOTEIO; | ||
126 | |||
127 | return 0; | ||
128 | } | ||
129 | |||
130 | static int | ||
131 | usbvision_i2c_xfer(struct i2c_adapter *i2c_adap, struct i2c_msg msgs[], int num) | ||
132 | { | ||
133 | struct i2c_msg *pmsg; | ||
134 | struct usb_usbvision *usbvision; | ||
135 | int i, ret; | ||
136 | unsigned char addr = 0; | ||
137 | |||
138 | usbvision = (struct usb_usbvision *)i2c_get_adapdata(i2c_adap); | ||
139 | |||
140 | for (i = 0; i < num; i++) { | ||
141 | pmsg = &msgs[i]; | ||
142 | ret = usb_find_address(i2c_adap, pmsg, i2c_adap->retries, &addr); | ||
143 | if (ret != 0) { | ||
144 | PDEBUG(DBG_I2C, "got NAK from device, message #%d", i); | ||
145 | return (ret < 0) ? ret : -EREMOTEIO; | ||
146 | } | ||
147 | |||
148 | if (pmsg->flags & I2C_M_RD) { | ||
149 | /* read bytes into buffer */ | ||
150 | ret = (usbvision_i2c_read(usbvision, addr, pmsg->buf, pmsg->len)); | ||
151 | if (ret < pmsg->len) | ||
152 | return (ret < 0) ? ret : -EREMOTEIO; | ||
153 | } else { | ||
154 | /* write bytes from buffer */ | ||
155 | ret = (usbvision_i2c_write(usbvision, addr, pmsg->buf, pmsg->len)); | ||
156 | if (ret < pmsg->len) | ||
157 | return (ret < 0) ? ret : -EREMOTEIO; | ||
158 | } | ||
159 | } | ||
160 | return num; | ||
161 | } | ||
162 | |||
163 | static u32 functionality(struct i2c_adapter *adap) | ||
164 | { | ||
165 | return I2C_FUNC_I2C | I2C_FUNC_SMBUS_EMUL; | ||
166 | } | ||
167 | |||
168 | /* -----exported algorithm data: ------------------------------------- */ | ||
169 | |||
170 | static struct i2c_algorithm usbvision_algo = { | ||
171 | .master_xfer = usbvision_i2c_xfer, | ||
172 | .smbus_xfer = NULL, | ||
173 | .functionality = functionality, | ||
174 | }; | ||
175 | |||
176 | |||
177 | /* ----------------------------------------------------------------------- */ | ||
178 | /* usbvision specific I2C functions */ | ||
179 | /* ----------------------------------------------------------------------- */ | ||
180 | static struct i2c_adapter i2c_adap_template; | ||
181 | |||
182 | int usbvision_i2c_register(struct usb_usbvision *usbvision) | ||
183 | { | ||
184 | static unsigned short saa711x_addrs[] = { | ||
185 | 0x4a >> 1, 0x48 >> 1, /* SAA7111, SAA7111A and SAA7113 */ | ||
186 | 0x42 >> 1, 0x40 >> 1, /* SAA7114, SAA7115 and SAA7118 */ | ||
187 | I2C_CLIENT_END }; | ||
188 | |||
189 | if (usbvision->registered_i2c) | ||
190 | return 0; | ||
191 | |||
192 | memcpy(&usbvision->i2c_adap, &i2c_adap_template, | ||
193 | sizeof(struct i2c_adapter)); | ||
194 | |||
195 | sprintf(usbvision->i2c_adap.name, "%s-%d-%s", i2c_adap_template.name, | ||
196 | usbvision->dev->bus->busnum, usbvision->dev->devpath); | ||
197 | PDEBUG(DBG_I2C, "Adaptername: %s", usbvision->i2c_adap.name); | ||
198 | usbvision->i2c_adap.dev.parent = &usbvision->dev->dev; | ||
199 | |||
200 | i2c_set_adapdata(&usbvision->i2c_adap, &usbvision->v4l2_dev); | ||
201 | |||
202 | if (usbvision_write_reg(usbvision, USBVISION_SER_MODE, USBVISION_IIC_LRNACK) < 0) { | ||
203 | printk(KERN_ERR "usbvision_i2c_register: can't write reg\n"); | ||
204 | return -EBUSY; | ||
205 | } | ||
206 | |||
207 | PDEBUG(DBG_I2C, "I2C debugging is enabled [i2c]"); | ||
208 | PDEBUG(DBG_I2C, "ALGO debugging is enabled [i2c]"); | ||
209 | |||
210 | /* register new adapter to i2c module... */ | ||
211 | |||
212 | usbvision->i2c_adap.algo = &usbvision_algo; | ||
213 | |||
214 | usbvision->i2c_adap.timeout = 100; /* default values, should */ | ||
215 | usbvision->i2c_adap.retries = 3; /* be replaced by defines */ | ||
216 | |||
217 | i2c_add_adapter(&usbvision->i2c_adap); | ||
218 | |||
219 | PDEBUG(DBG_I2C, "i2c bus for %s registered", usbvision->i2c_adap.name); | ||
220 | |||
221 | /* Request the load of the i2c modules we need */ | ||
222 | switch (usbvision_device_data[usbvision->dev_model].codec) { | ||
223 | case CODEC_SAA7113: | ||
224 | case CODEC_SAA7111: | ||
225 | /* Without this delay the detection of the saa711x is | ||
226 | hit-and-miss. */ | ||
227 | mdelay(10); | ||
228 | v4l2_i2c_new_subdev(&usbvision->v4l2_dev, | ||
229 | &usbvision->i2c_adap, | ||
230 | "saa7115_auto", 0, saa711x_addrs); | ||
231 | break; | ||
232 | } | ||
233 | if (usbvision_device_data[usbvision->dev_model].tuner == 1) { | ||
234 | struct v4l2_subdev *sd; | ||
235 | enum v4l2_i2c_tuner_type type; | ||
236 | struct tuner_setup tun_setup; | ||
237 | |||
238 | sd = v4l2_i2c_new_subdev(&usbvision->v4l2_dev, | ||
239 | &usbvision->i2c_adap, | ||
240 | "tuner", 0, v4l2_i2c_tuner_addrs(ADDRS_DEMOD)); | ||
241 | /* depending on whether we found a demod or not, select | ||
242 | the tuner type. */ | ||
243 | type = sd ? ADDRS_TV_WITH_DEMOD : ADDRS_TV; | ||
244 | |||
245 | sd = v4l2_i2c_new_subdev(&usbvision->v4l2_dev, | ||
246 | &usbvision->i2c_adap, | ||
247 | "tuner", 0, v4l2_i2c_tuner_addrs(type)); | ||
248 | |||
249 | if (sd == NULL) | ||
250 | return -ENODEV; | ||
251 | if (usbvision->tuner_type != -1) { | ||
252 | tun_setup.mode_mask = T_ANALOG_TV | T_RADIO; | ||
253 | tun_setup.type = usbvision->tuner_type; | ||
254 | tun_setup.addr = v4l2_i2c_subdev_addr(sd); | ||
255 | call_all(usbvision, tuner, s_type_addr, &tun_setup); | ||
256 | } | ||
257 | } | ||
258 | usbvision->registered_i2c = 1; | ||
259 | |||
260 | return 0; | ||
261 | } | ||
262 | |||
263 | int usbvision_i2c_unregister(struct usb_usbvision *usbvision) | ||
264 | { | ||
265 | if (!usbvision->registered_i2c) | ||
266 | return 0; | ||
267 | |||
268 | i2c_del_adapter(&(usbvision->i2c_adap)); | ||
269 | usbvision->registered_i2c = 0; | ||
270 | |||
271 | PDEBUG(DBG_I2C, "i2c bus for %s unregistered", usbvision->i2c_adap.name); | ||
272 | |||
273 | return 0; | ||
274 | } | ||
275 | |||
276 | static int | ||
277 | usbvision_i2c_read_max4(struct usb_usbvision *usbvision, unsigned char addr, | ||
278 | char *buf, short len) | ||
279 | { | ||
280 | int rc, retries; | ||
281 | |||
282 | for (retries = 5;;) { | ||
283 | rc = usbvision_write_reg(usbvision, USBVISION_SER_ADRS, addr); | ||
284 | if (rc < 0) | ||
285 | return rc; | ||
286 | |||
287 | /* Initiate byte read cycle */ | ||
288 | /* USBVISION_SER_CONT <- d0-d2 n. of bytes to r/w */ | ||
289 | /* d3 0=Wr 1=Rd */ | ||
290 | rc = usbvision_write_reg(usbvision, USBVISION_SER_CONT, | ||
291 | (len & 0x07) | 0x18); | ||
292 | if (rc < 0) | ||
293 | return rc; | ||
294 | |||
295 | /* Test for Busy and ACK */ | ||
296 | do { | ||
297 | /* USBVISION_SER_CONT -> d4 == 0 busy */ | ||
298 | rc = usbvision_read_reg(usbvision, USBVISION_SER_CONT); | ||
299 | } while (rc > 0 && ((rc & 0x10) != 0)); /* Retry while busy */ | ||
300 | if (rc < 0) | ||
301 | return rc; | ||
302 | |||
303 | /* USBVISION_SER_CONT -> d5 == 1 Not ack */ | ||
304 | if ((rc & 0x20) == 0) /* Ack? */ | ||
305 | break; | ||
306 | |||
307 | /* I2C abort */ | ||
308 | rc = usbvision_write_reg(usbvision, USBVISION_SER_CONT, 0x00); | ||
309 | if (rc < 0) | ||
310 | return rc; | ||
311 | |||
312 | if (--retries < 0) | ||
313 | return -1; | ||
314 | } | ||
315 | |||
316 | switch (len) { | ||
317 | case 4: | ||
318 | buf[3] = usbvision_read_reg(usbvision, USBVISION_SER_DAT4); | ||
319 | case 3: | ||
320 | buf[2] = usbvision_read_reg(usbvision, USBVISION_SER_DAT3); | ||
321 | case 2: | ||
322 | buf[1] = usbvision_read_reg(usbvision, USBVISION_SER_DAT2); | ||
323 | case 1: | ||
324 | buf[0] = usbvision_read_reg(usbvision, USBVISION_SER_DAT1); | ||
325 | break; | ||
326 | default: | ||
327 | printk(KERN_ERR | ||
328 | "usbvision_i2c_read_max4: buffer length > 4\n"); | ||
329 | } | ||
330 | |||
331 | if (i2c_debug & DBG_I2C) { | ||
332 | int idx; | ||
333 | |||
334 | for (idx = 0; idx < len; idx++) | ||
335 | PDEBUG(DBG_I2C, "read %x from address %x", (unsigned char)buf[idx], addr); | ||
336 | } | ||
337 | return len; | ||
338 | } | ||
339 | |||
340 | |||
341 | static int usbvision_i2c_write_max4(struct usb_usbvision *usbvision, | ||
342 | unsigned char addr, const char *buf, | ||
343 | short len) | ||
344 | { | ||
345 | int rc, retries; | ||
346 | int i; | ||
347 | unsigned char value[6]; | ||
348 | unsigned char ser_cont; | ||
349 | |||
350 | ser_cont = (len & 0x07) | 0x10; | ||
351 | |||
352 | value[0] = addr; | ||
353 | value[1] = ser_cont; | ||
354 | for (i = 0; i < len; i++) | ||
355 | value[i + 2] = buf[i]; | ||
356 | |||
357 | for (retries = 5;;) { | ||
358 | rc = usb_control_msg(usbvision->dev, | ||
359 | usb_sndctrlpipe(usbvision->dev, 1), | ||
360 | USBVISION_OP_CODE, | ||
361 | USB_DIR_OUT | USB_TYPE_VENDOR | | ||
362 | USB_RECIP_ENDPOINT, 0, | ||
363 | (__u16) USBVISION_SER_ADRS, value, | ||
364 | len + 2, HZ); | ||
365 | |||
366 | if (rc < 0) | ||
367 | return rc; | ||
368 | |||
369 | rc = usbvision_write_reg(usbvision, USBVISION_SER_CONT, | ||
370 | (len & 0x07) | 0x10); | ||
371 | if (rc < 0) | ||
372 | return rc; | ||
373 | |||
374 | /* Test for Busy and ACK */ | ||
375 | do { | ||
376 | rc = usbvision_read_reg(usbvision, USBVISION_SER_CONT); | ||
377 | } while (rc > 0 && ((rc & 0x10) != 0)); /* Retry while busy */ | ||
378 | if (rc < 0) | ||
379 | return rc; | ||
380 | |||
381 | if ((rc & 0x20) == 0) /* Ack? */ | ||
382 | break; | ||
383 | |||
384 | /* I2C abort */ | ||
385 | usbvision_write_reg(usbvision, USBVISION_SER_CONT, 0x00); | ||
386 | |||
387 | if (--retries < 0) | ||
388 | return -1; | ||
389 | |||
390 | } | ||
391 | |||
392 | if (i2c_debug & DBG_I2C) { | ||
393 | int idx; | ||
394 | |||
395 | for (idx = 0; idx < len; idx++) | ||
396 | PDEBUG(DBG_I2C, "wrote %x at address %x", (unsigned char)buf[idx], addr); | ||
397 | } | ||
398 | return len; | ||
399 | } | ||
400 | |||
401 | static int usbvision_i2c_write(struct usb_usbvision *usbvision, unsigned char addr, char *buf, | ||
402 | short len) | ||
403 | { | ||
404 | char *buf_ptr = buf; | ||
405 | int retval; | ||
406 | int wrcount = 0; | ||
407 | int count; | ||
408 | int max_len = 4; | ||
409 | |||
410 | while (len > 0) { | ||
411 | count = (len > max_len) ? max_len : len; | ||
412 | retval = usbvision_i2c_write_max4(usbvision, addr, buf_ptr, count); | ||
413 | if (retval > 0) { | ||
414 | len -= count; | ||
415 | buf_ptr += count; | ||
416 | wrcount += count; | ||
417 | } else | ||
418 | return (retval < 0) ? retval : -EFAULT; | ||
419 | } | ||
420 | return wrcount; | ||
421 | } | ||
422 | |||
423 | static int usbvision_i2c_read(struct usb_usbvision *usbvision, unsigned char addr, char *buf, | ||
424 | short len) | ||
425 | { | ||
426 | char temp[4]; | ||
427 | int retval, i; | ||
428 | int rdcount = 0; | ||
429 | int count; | ||
430 | |||
431 | while (len > 0) { | ||
432 | count = (len > 3) ? 4 : len; | ||
433 | retval = usbvision_i2c_read_max4(usbvision, addr, temp, count); | ||
434 | if (retval > 0) { | ||
435 | for (i = 0; i < len; i++) | ||
436 | buf[rdcount + i] = temp[i]; | ||
437 | len -= count; | ||
438 | rdcount += count; | ||
439 | } else | ||
440 | return (retval < 0) ? retval : -EFAULT; | ||
441 | } | ||
442 | return rdcount; | ||
443 | } | ||
444 | |||
445 | static struct i2c_adapter i2c_adap_template = { | ||
446 | .owner = THIS_MODULE, | ||
447 | .name = "usbvision", | ||
448 | }; | ||
449 | |||
450 | /* | ||
451 | * Overrides for Emacs so that we follow Linus's tabbing style. | ||
452 | * --------------------------------------------------------------------------- | ||
453 | * Local variables: | ||
454 | * c-basic-offset: 8 | ||
455 | * End: | ||
456 | */ | ||
diff --git a/drivers/media/usb/usbvision/usbvision-video.c b/drivers/media/usb/usbvision/usbvision-video.c new file mode 100644 index 000000000000..8a4317979a43 --- /dev/null +++ b/drivers/media/usb/usbvision/usbvision-video.c | |||
@@ -0,0 +1,1720 @@ | |||
1 | /* | ||
2 | * USB USBVISION Video device driver 0.9.10 | ||
3 | * | ||
4 | * | ||
5 | * | ||
6 | * Copyright (c) 1999-2005 Joerg Heckenbach <joerg@heckenbach-aw.de> | ||
7 | * | ||
8 | * This module is part of usbvision driver project. | ||
9 | * | ||
10 | * This program is free software; you can redistribute it and/or modify | ||
11 | * it under the terms of the GNU General Public License as published by | ||
12 | * the Free Software Foundation; either version 2 of the License, or | ||
13 | * (at your option) any later version. | ||
14 | * | ||
15 | * This program is distributed in the hope that it will be useful, | ||
16 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
17 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
18 | * GNU General Public License for more details. | ||
19 | * | ||
20 | * You should have received a copy of the GNU General Public License | ||
21 | * along with this program; if not, write to the Free Software | ||
22 | * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. | ||
23 | * | ||
24 | * Let's call the version 0.... until compression decoding is completely | ||
25 | * implemented. | ||
26 | * | ||
27 | * This driver is written by Jose Ignacio Gijon and Joerg Heckenbach. | ||
28 | * It was based on USB CPiA driver written by Peter Pregler, | ||
29 | * Scott J. Bertin and Johannes Erdfelt | ||
30 | * Ideas are taken from bttv driver by Ralph Metzler, Marcus Metzler & | ||
31 | * Gerd Knorr and zoran 36120/36125 driver by Pauline Middelink | ||
32 | * Updates to driver completed by Dwaine P. Garden | ||
33 | * | ||
34 | * | ||
35 | * TODO: | ||
36 | * - use submit_urb for all setup packets | ||
37 | * - Fix memory settings for nt1004. It is 4 times as big as the | ||
38 | * nt1003 memory. | ||
39 | * - Add audio on endpoint 3 for nt1004 chip. | ||
40 | * Seems impossible, needs a codec interface. Which one? | ||
41 | * - Clean up the driver. | ||
42 | * - optimization for performance. | ||
43 | * - Add Videotext capability (VBI). Working on it..... | ||
44 | * - Check audio for other devices | ||
45 | * | ||
46 | */ | ||
47 | |||
48 | #include <linux/kernel.h> | ||
49 | #include <linux/list.h> | ||
50 | #include <linux/timer.h> | ||
51 | #include <linux/slab.h> | ||
52 | #include <linux/mm.h> | ||
53 | #include <linux/highmem.h> | ||
54 | #include <linux/vmalloc.h> | ||
55 | #include <linux/module.h> | ||
56 | #include <linux/init.h> | ||
57 | #include <linux/spinlock.h> | ||
58 | #include <linux/io.h> | ||
59 | #include <linux/videodev2.h> | ||
60 | #include <linux/i2c.h> | ||
61 | |||
62 | #include <media/saa7115.h> | ||
63 | #include <media/v4l2-common.h> | ||
64 | #include <media/v4l2-ioctl.h> | ||
65 | #include <media/tuner.h> | ||
66 | |||
67 | #include <linux/workqueue.h> | ||
68 | |||
69 | #include "usbvision.h" | ||
70 | #include "usbvision-cards.h" | ||
71 | |||
72 | #define DRIVER_AUTHOR \ | ||
73 | "Joerg Heckenbach <joerg@heckenbach-aw.de>, " \ | ||
74 | "Dwaine Garden <DwaineGarden@rogers.com>" | ||
75 | #define DRIVER_NAME "usbvision" | ||
76 | #define DRIVER_ALIAS "USBVision" | ||
77 | #define DRIVER_DESC "USBVision USB Video Device Driver for Linux" | ||
78 | #define DRIVER_LICENSE "GPL" | ||
79 | #define USBVISION_VERSION_STRING "0.9.11" | ||
80 | |||
81 | #define ENABLE_HEXDUMP 0 /* Enable if you need it */ | ||
82 | |||
83 | |||
84 | #ifdef USBVISION_DEBUG | ||
85 | #define PDEBUG(level, fmt, args...) { \ | ||
86 | if (video_debug & (level)) \ | ||
87 | printk(KERN_INFO KBUILD_MODNAME ":[%s:%d] " fmt, \ | ||
88 | __func__, __LINE__ , ## args); \ | ||
89 | } | ||
90 | #else | ||
91 | #define PDEBUG(level, fmt, args...) do {} while (0) | ||
92 | #endif | ||
93 | |||
94 | #define DBG_IO (1 << 1) | ||
95 | #define DBG_PROBE (1 << 2) | ||
96 | #define DBG_MMAP (1 << 3) | ||
97 | |||
98 | /* String operations */ | ||
99 | #define rmspace(str) while (*str == ' ') str++; | ||
100 | #define goto2next(str) while (*str != ' ') str++; while (*str == ' ') str++; | ||
101 | |||
102 | |||
103 | /* sequential number of usbvision device */ | ||
104 | static int usbvision_nr; | ||
105 | |||
106 | static struct usbvision_v4l2_format_st usbvision_v4l2_format[] = { | ||
107 | { 1, 1, 8, V4L2_PIX_FMT_GREY , "GREY" }, | ||
108 | { 1, 2, 16, V4L2_PIX_FMT_RGB565 , "RGB565" }, | ||
109 | { 1, 3, 24, V4L2_PIX_FMT_RGB24 , "RGB24" }, | ||
110 | { 1, 4, 32, V4L2_PIX_FMT_RGB32 , "RGB32" }, | ||
111 | { 1, 2, 16, V4L2_PIX_FMT_RGB555 , "RGB555" }, | ||
112 | { 1, 2, 16, V4L2_PIX_FMT_YUYV , "YUV422" }, | ||
113 | { 1, 2, 12, V4L2_PIX_FMT_YVU420 , "YUV420P" }, /* 1.5 ! */ | ||
114 | { 1, 2, 16, V4L2_PIX_FMT_YUV422P , "YUV422P" } | ||
115 | }; | ||
116 | |||
117 | /* Function prototypes */ | ||
118 | static void usbvision_release(struct usb_usbvision *usbvision); | ||
119 | |||
120 | /* Default initialization of device driver parameters */ | ||
121 | /* Set the default format for ISOC endpoint */ | ||
122 | static int isoc_mode = ISOC_MODE_COMPRESS; | ||
123 | /* Set the default Debug Mode of the device driver */ | ||
124 | static int video_debug; | ||
125 | /* Set the default device to power on at startup */ | ||
126 | static int power_on_at_open = 1; | ||
127 | /* Sequential Number of Video Device */ | ||
128 | static int video_nr = -1; | ||
129 | /* Sequential Number of Radio Device */ | ||
130 | static int radio_nr = -1; | ||
131 | |||
132 | /* Grab parameters for the device driver */ | ||
133 | |||
134 | /* Showing parameters under SYSFS */ | ||
135 | module_param(isoc_mode, int, 0444); | ||
136 | module_param(video_debug, int, 0444); | ||
137 | module_param(power_on_at_open, int, 0444); | ||
138 | module_param(video_nr, int, 0444); | ||
139 | module_param(radio_nr, int, 0444); | ||
140 | |||
141 | MODULE_PARM_DESC(isoc_mode, " Set the default format for ISOC endpoint. Default: 0x60 (Compression On)"); | ||
142 | MODULE_PARM_DESC(video_debug, " Set the default Debug Mode of the device driver. Default: 0 (Off)"); | ||
143 | MODULE_PARM_DESC(power_on_at_open, " Set the default device to power on when device is opened. Default: 1 (On)"); | ||
144 | MODULE_PARM_DESC(video_nr, "Set video device number (/dev/videoX). Default: -1 (autodetect)"); | ||
145 | MODULE_PARM_DESC(radio_nr, "Set radio device number (/dev/radioX). Default: -1 (autodetect)"); | ||
146 | |||
147 | |||
148 | /* Misc stuff */ | ||
149 | MODULE_AUTHOR(DRIVER_AUTHOR); | ||
150 | MODULE_DESCRIPTION(DRIVER_DESC); | ||
151 | MODULE_LICENSE(DRIVER_LICENSE); | ||
152 | MODULE_VERSION(USBVISION_VERSION_STRING); | ||
153 | MODULE_ALIAS(DRIVER_ALIAS); | ||
154 | |||
155 | |||
156 | /*****************************************************************************/ | ||
157 | /* SYSFS Code - Copied from the stv680.c usb module. */ | ||
158 | /* Device information is located at /sys/class/video4linux/video0 */ | ||
159 | /* Device parameters information is located at /sys/module/usbvision */ | ||
160 | /* Device USB Information is located at */ | ||
161 | /* /sys/bus/usb/drivers/USBVision Video Grabber */ | ||
162 | /*****************************************************************************/ | ||
163 | |||
164 | #define YES_NO(x) ((x) ? "Yes" : "No") | ||
165 | |||
166 | static inline struct usb_usbvision *cd_to_usbvision(struct device *cd) | ||
167 | { | ||
168 | struct video_device *vdev = | ||
169 | container_of(cd, struct video_device, dev); | ||
170 | return video_get_drvdata(vdev); | ||
171 | } | ||
172 | |||
173 | static ssize_t show_version(struct device *cd, | ||
174 | struct device_attribute *attr, char *buf) | ||
175 | { | ||
176 | return sprintf(buf, "%s\n", USBVISION_VERSION_STRING); | ||
177 | } | ||
178 | static DEVICE_ATTR(version, S_IRUGO, show_version, NULL); | ||
179 | |||
180 | static ssize_t show_model(struct device *cd, | ||
181 | struct device_attribute *attr, char *buf) | ||
182 | { | ||
183 | struct video_device *vdev = | ||
184 | container_of(cd, struct video_device, dev); | ||
185 | struct usb_usbvision *usbvision = video_get_drvdata(vdev); | ||
186 | return sprintf(buf, "%s\n", | ||
187 | usbvision_device_data[usbvision->dev_model].model_string); | ||
188 | } | ||
189 | static DEVICE_ATTR(model, S_IRUGO, show_model, NULL); | ||
190 | |||
191 | static ssize_t show_hue(struct device *cd, | ||
192 | struct device_attribute *attr, char *buf) | ||
193 | { | ||
194 | struct video_device *vdev = | ||
195 | container_of(cd, struct video_device, dev); | ||
196 | struct usb_usbvision *usbvision = video_get_drvdata(vdev); | ||
197 | struct v4l2_control ctrl; | ||
198 | ctrl.id = V4L2_CID_HUE; | ||
199 | ctrl.value = 0; | ||
200 | if (usbvision->user) | ||
201 | call_all(usbvision, core, g_ctrl, &ctrl); | ||
202 | return sprintf(buf, "%d\n", ctrl.value); | ||
203 | } | ||
204 | static DEVICE_ATTR(hue, S_IRUGO, show_hue, NULL); | ||
205 | |||
206 | static ssize_t show_contrast(struct device *cd, | ||
207 | struct device_attribute *attr, char *buf) | ||
208 | { | ||
209 | struct video_device *vdev = | ||
210 | container_of(cd, struct video_device, dev); | ||
211 | struct usb_usbvision *usbvision = video_get_drvdata(vdev); | ||
212 | struct v4l2_control ctrl; | ||
213 | ctrl.id = V4L2_CID_CONTRAST; | ||
214 | ctrl.value = 0; | ||
215 | if (usbvision->user) | ||
216 | call_all(usbvision, core, g_ctrl, &ctrl); | ||
217 | return sprintf(buf, "%d\n", ctrl.value); | ||
218 | } | ||
219 | static DEVICE_ATTR(contrast, S_IRUGO, show_contrast, NULL); | ||
220 | |||
221 | static ssize_t show_brightness(struct device *cd, | ||
222 | struct device_attribute *attr, char *buf) | ||
223 | { | ||
224 | struct video_device *vdev = | ||
225 | container_of(cd, struct video_device, dev); | ||
226 | struct usb_usbvision *usbvision = video_get_drvdata(vdev); | ||
227 | struct v4l2_control ctrl; | ||
228 | ctrl.id = V4L2_CID_BRIGHTNESS; | ||
229 | ctrl.value = 0; | ||
230 | if (usbvision->user) | ||
231 | call_all(usbvision, core, g_ctrl, &ctrl); | ||
232 | return sprintf(buf, "%d\n", ctrl.value); | ||
233 | } | ||
234 | static DEVICE_ATTR(brightness, S_IRUGO, show_brightness, NULL); | ||
235 | |||
236 | static ssize_t show_saturation(struct device *cd, | ||
237 | struct device_attribute *attr, char *buf) | ||
238 | { | ||
239 | struct video_device *vdev = | ||
240 | container_of(cd, struct video_device, dev); | ||
241 | struct usb_usbvision *usbvision = video_get_drvdata(vdev); | ||
242 | struct v4l2_control ctrl; | ||
243 | ctrl.id = V4L2_CID_SATURATION; | ||
244 | ctrl.value = 0; | ||
245 | if (usbvision->user) | ||
246 | call_all(usbvision, core, g_ctrl, &ctrl); | ||
247 | return sprintf(buf, "%d\n", ctrl.value); | ||
248 | } | ||
249 | static DEVICE_ATTR(saturation, S_IRUGO, show_saturation, NULL); | ||
250 | |||
251 | static ssize_t show_streaming(struct device *cd, | ||
252 | struct device_attribute *attr, char *buf) | ||
253 | { | ||
254 | struct video_device *vdev = | ||
255 | container_of(cd, struct video_device, dev); | ||
256 | struct usb_usbvision *usbvision = video_get_drvdata(vdev); | ||
257 | return sprintf(buf, "%s\n", | ||
258 | YES_NO(usbvision->streaming == stream_on ? 1 : 0)); | ||
259 | } | ||
260 | static DEVICE_ATTR(streaming, S_IRUGO, show_streaming, NULL); | ||
261 | |||
262 | static ssize_t show_compression(struct device *cd, | ||
263 | struct device_attribute *attr, char *buf) | ||
264 | { | ||
265 | struct video_device *vdev = | ||
266 | container_of(cd, struct video_device, dev); | ||
267 | struct usb_usbvision *usbvision = video_get_drvdata(vdev); | ||
268 | return sprintf(buf, "%s\n", | ||
269 | YES_NO(usbvision->isoc_mode == ISOC_MODE_COMPRESS)); | ||
270 | } | ||
271 | static DEVICE_ATTR(compression, S_IRUGO, show_compression, NULL); | ||
272 | |||
273 | static ssize_t show_device_bridge(struct device *cd, | ||
274 | struct device_attribute *attr, char *buf) | ||
275 | { | ||
276 | struct video_device *vdev = | ||
277 | container_of(cd, struct video_device, dev); | ||
278 | struct usb_usbvision *usbvision = video_get_drvdata(vdev); | ||
279 | return sprintf(buf, "%d\n", usbvision->bridge_type); | ||
280 | } | ||
281 | static DEVICE_ATTR(bridge, S_IRUGO, show_device_bridge, NULL); | ||
282 | |||
283 | static void usbvision_create_sysfs(struct video_device *vdev) | ||
284 | { | ||
285 | int res; | ||
286 | |||
287 | if (!vdev) | ||
288 | return; | ||
289 | do { | ||
290 | res = device_create_file(&vdev->dev, &dev_attr_version); | ||
291 | if (res < 0) | ||
292 | break; | ||
293 | res = device_create_file(&vdev->dev, &dev_attr_model); | ||
294 | if (res < 0) | ||
295 | break; | ||
296 | res = device_create_file(&vdev->dev, &dev_attr_hue); | ||
297 | if (res < 0) | ||
298 | break; | ||
299 | res = device_create_file(&vdev->dev, &dev_attr_contrast); | ||
300 | if (res < 0) | ||
301 | break; | ||
302 | res = device_create_file(&vdev->dev, &dev_attr_brightness); | ||
303 | if (res < 0) | ||
304 | break; | ||
305 | res = device_create_file(&vdev->dev, &dev_attr_saturation); | ||
306 | if (res < 0) | ||
307 | break; | ||
308 | res = device_create_file(&vdev->dev, &dev_attr_streaming); | ||
309 | if (res < 0) | ||
310 | break; | ||
311 | res = device_create_file(&vdev->dev, &dev_attr_compression); | ||
312 | if (res < 0) | ||
313 | break; | ||
314 | res = device_create_file(&vdev->dev, &dev_attr_bridge); | ||
315 | if (res >= 0) | ||
316 | return; | ||
317 | } while (0); | ||
318 | |||
319 | dev_err(&vdev->dev, "%s error: %d\n", __func__, res); | ||
320 | } | ||
321 | |||
322 | static void usbvision_remove_sysfs(struct video_device *vdev) | ||
323 | { | ||
324 | if (vdev) { | ||
325 | device_remove_file(&vdev->dev, &dev_attr_version); | ||
326 | device_remove_file(&vdev->dev, &dev_attr_model); | ||
327 | device_remove_file(&vdev->dev, &dev_attr_hue); | ||
328 | device_remove_file(&vdev->dev, &dev_attr_contrast); | ||
329 | device_remove_file(&vdev->dev, &dev_attr_brightness); | ||
330 | device_remove_file(&vdev->dev, &dev_attr_saturation); | ||
331 | device_remove_file(&vdev->dev, &dev_attr_streaming); | ||
332 | device_remove_file(&vdev->dev, &dev_attr_compression); | ||
333 | device_remove_file(&vdev->dev, &dev_attr_bridge); | ||
334 | } | ||
335 | } | ||
336 | |||
337 | /* | ||
338 | * usbvision_open() | ||
339 | * | ||
340 | * This is part of Video 4 Linux API. The driver can be opened by one | ||
341 | * client only (checks internal counter 'usbvision->user'). The procedure | ||
342 | * then allocates buffers needed for video processing. | ||
343 | * | ||
344 | */ | ||
345 | static int usbvision_v4l2_open(struct file *file) | ||
346 | { | ||
347 | struct usb_usbvision *usbvision = video_drvdata(file); | ||
348 | int err_code = 0; | ||
349 | |||
350 | PDEBUG(DBG_IO, "open"); | ||
351 | |||
352 | if (mutex_lock_interruptible(&usbvision->v4l2_lock)) | ||
353 | return -ERESTARTSYS; | ||
354 | usbvision_reset_power_off_timer(usbvision); | ||
355 | |||
356 | if (usbvision->user) | ||
357 | err_code = -EBUSY; | ||
358 | else { | ||
359 | /* Allocate memory for the scratch ring buffer */ | ||
360 | err_code = usbvision_scratch_alloc(usbvision); | ||
361 | if (isoc_mode == ISOC_MODE_COMPRESS) { | ||
362 | /* Allocate intermediate decompression buffers | ||
363 | only if needed */ | ||
364 | err_code = usbvision_decompress_alloc(usbvision); | ||
365 | } | ||
366 | if (err_code) { | ||
367 | /* Deallocate all buffers if trouble */ | ||
368 | usbvision_scratch_free(usbvision); | ||
369 | usbvision_decompress_free(usbvision); | ||
370 | } | ||
371 | } | ||
372 | |||
373 | /* If so far no errors then we shall start the camera */ | ||
374 | if (!err_code) { | ||
375 | if (usbvision->power == 0) { | ||
376 | usbvision_power_on(usbvision); | ||
377 | usbvision_i2c_register(usbvision); | ||
378 | } | ||
379 | |||
380 | /* Send init sequence only once, it's large! */ | ||
381 | if (!usbvision->initialized) { | ||
382 | int setup_ok = 0; | ||
383 | setup_ok = usbvision_setup(usbvision, isoc_mode); | ||
384 | if (setup_ok) | ||
385 | usbvision->initialized = 1; | ||
386 | else | ||
387 | err_code = -EBUSY; | ||
388 | } | ||
389 | |||
390 | if (!err_code) { | ||
391 | usbvision_begin_streaming(usbvision); | ||
392 | err_code = usbvision_init_isoc(usbvision); | ||
393 | /* device must be initialized before isoc transfer */ | ||
394 | usbvision_muxsel(usbvision, 0); | ||
395 | usbvision->user++; | ||
396 | } else { | ||
397 | if (power_on_at_open) { | ||
398 | usbvision_i2c_unregister(usbvision); | ||
399 | usbvision_power_off(usbvision); | ||
400 | usbvision->initialized = 0; | ||
401 | } | ||
402 | } | ||
403 | } | ||
404 | |||
405 | /* prepare queues */ | ||
406 | usbvision_empty_framequeues(usbvision); | ||
407 | mutex_unlock(&usbvision->v4l2_lock); | ||
408 | |||
409 | PDEBUG(DBG_IO, "success"); | ||
410 | return err_code; | ||
411 | } | ||
412 | |||
413 | /* | ||
414 | * usbvision_v4l2_close() | ||
415 | * | ||
416 | * This is part of Video 4 Linux API. The procedure | ||
417 | * stops streaming and deallocates all buffers that were earlier | ||
418 | * allocated in usbvision_v4l2_open(). | ||
419 | * | ||
420 | */ | ||
421 | static int usbvision_v4l2_close(struct file *file) | ||
422 | { | ||
423 | struct usb_usbvision *usbvision = video_drvdata(file); | ||
424 | |||
425 | PDEBUG(DBG_IO, "close"); | ||
426 | |||
427 | mutex_lock(&usbvision->v4l2_lock); | ||
428 | usbvision_audio_off(usbvision); | ||
429 | usbvision_restart_isoc(usbvision); | ||
430 | usbvision_stop_isoc(usbvision); | ||
431 | |||
432 | usbvision_decompress_free(usbvision); | ||
433 | usbvision_frames_free(usbvision); | ||
434 | usbvision_empty_framequeues(usbvision); | ||
435 | usbvision_scratch_free(usbvision); | ||
436 | |||
437 | usbvision->user--; | ||
438 | |||
439 | if (power_on_at_open) { | ||
440 | /* power off in a little while | ||
441 | to avoid off/on every close/open short sequences */ | ||
442 | usbvision_set_power_off_timer(usbvision); | ||
443 | usbvision->initialized = 0; | ||
444 | } | ||
445 | |||
446 | if (usbvision->remove_pending) { | ||
447 | printk(KERN_INFO "%s: Final disconnect\n", __func__); | ||
448 | usbvision_release(usbvision); | ||
449 | } | ||
450 | mutex_unlock(&usbvision->v4l2_lock); | ||
451 | |||
452 | PDEBUG(DBG_IO, "success"); | ||
453 | return 0; | ||
454 | } | ||
455 | |||
456 | |||
457 | /* | ||
458 | * usbvision_ioctl() | ||
459 | * | ||
460 | * This is part of Video 4 Linux API. The procedure handles ioctl() calls. | ||
461 | * | ||
462 | */ | ||
463 | #ifdef CONFIG_VIDEO_ADV_DEBUG | ||
464 | static int vidioc_g_register(struct file *file, void *priv, | ||
465 | struct v4l2_dbg_register *reg) | ||
466 | { | ||
467 | struct usb_usbvision *usbvision = video_drvdata(file); | ||
468 | int err_code; | ||
469 | |||
470 | if (!v4l2_chip_match_host(®->match)) | ||
471 | return -EINVAL; | ||
472 | /* NT100x has a 8-bit register space */ | ||
473 | err_code = usbvision_read_reg(usbvision, reg->reg&0xff); | ||
474 | if (err_code < 0) { | ||
475 | dev_err(&usbvision->vdev->dev, | ||
476 | "%s: VIDIOC_DBG_G_REGISTER failed: error %d\n", | ||
477 | __func__, err_code); | ||
478 | return err_code; | ||
479 | } | ||
480 | reg->val = err_code; | ||
481 | reg->size = 1; | ||
482 | return 0; | ||
483 | } | ||
484 | |||
485 | static int vidioc_s_register(struct file *file, void *priv, | ||
486 | struct v4l2_dbg_register *reg) | ||
487 | { | ||
488 | struct usb_usbvision *usbvision = video_drvdata(file); | ||
489 | int err_code; | ||
490 | |||
491 | if (!v4l2_chip_match_host(®->match)) | ||
492 | return -EINVAL; | ||
493 | /* NT100x has a 8-bit register space */ | ||
494 | err_code = usbvision_write_reg(usbvision, reg->reg & 0xff, reg->val); | ||
495 | if (err_code < 0) { | ||
496 | dev_err(&usbvision->vdev->dev, | ||
497 | "%s: VIDIOC_DBG_S_REGISTER failed: error %d\n", | ||
498 | __func__, err_code); | ||
499 | return err_code; | ||
500 | } | ||
501 | return 0; | ||
502 | } | ||
503 | #endif | ||
504 | |||
505 | static int vidioc_querycap(struct file *file, void *priv, | ||
506 | struct v4l2_capability *vc) | ||
507 | { | ||
508 | struct usb_usbvision *usbvision = video_drvdata(file); | ||
509 | |||
510 | strlcpy(vc->driver, "USBVision", sizeof(vc->driver)); | ||
511 | strlcpy(vc->card, | ||
512 | usbvision_device_data[usbvision->dev_model].model_string, | ||
513 | sizeof(vc->card)); | ||
514 | usb_make_path(usbvision->dev, vc->bus_info, sizeof(vc->bus_info)); | ||
515 | vc->capabilities = V4L2_CAP_VIDEO_CAPTURE | | ||
516 | V4L2_CAP_AUDIO | | ||
517 | V4L2_CAP_READWRITE | | ||
518 | V4L2_CAP_STREAMING | | ||
519 | (usbvision->have_tuner ? V4L2_CAP_TUNER : 0); | ||
520 | return 0; | ||
521 | } | ||
522 | |||
523 | static int vidioc_enum_input(struct file *file, void *priv, | ||
524 | struct v4l2_input *vi) | ||
525 | { | ||
526 | struct usb_usbvision *usbvision = video_drvdata(file); | ||
527 | int chan; | ||
528 | |||
529 | if (vi->index >= usbvision->video_inputs) | ||
530 | return -EINVAL; | ||
531 | if (usbvision->have_tuner) | ||
532 | chan = vi->index; | ||
533 | else | ||
534 | chan = vi->index + 1; /* skip Television string*/ | ||
535 | |||
536 | /* Determine the requested input characteristics | ||
537 | specific for each usbvision card model */ | ||
538 | switch (chan) { | ||
539 | case 0: | ||
540 | if (usbvision_device_data[usbvision->dev_model].video_channels == 4) { | ||
541 | strcpy(vi->name, "White Video Input"); | ||
542 | } else { | ||
543 | strcpy(vi->name, "Television"); | ||
544 | vi->type = V4L2_INPUT_TYPE_TUNER; | ||
545 | vi->audioset = 1; | ||
546 | vi->tuner = chan; | ||
547 | vi->std = USBVISION_NORMS; | ||
548 | } | ||
549 | break; | ||
550 | case 1: | ||
551 | vi->type = V4L2_INPUT_TYPE_CAMERA; | ||
552 | if (usbvision_device_data[usbvision->dev_model].video_channels == 4) | ||
553 | strcpy(vi->name, "Green Video Input"); | ||
554 | else | ||
555 | strcpy(vi->name, "Composite Video Input"); | ||
556 | vi->std = V4L2_STD_PAL; | ||
557 | break; | ||
558 | case 2: | ||
559 | vi->type = V4L2_INPUT_TYPE_CAMERA; | ||
560 | if (usbvision_device_data[usbvision->dev_model].video_channels == 4) | ||
561 | strcpy(vi->name, "Yellow Video Input"); | ||
562 | else | ||
563 | strcpy(vi->name, "S-Video Input"); | ||
564 | vi->std = V4L2_STD_PAL; | ||
565 | break; | ||
566 | case 3: | ||
567 | vi->type = V4L2_INPUT_TYPE_CAMERA; | ||
568 | strcpy(vi->name, "Red Video Input"); | ||
569 | vi->std = V4L2_STD_PAL; | ||
570 | break; | ||
571 | } | ||
572 | return 0; | ||
573 | } | ||
574 | |||
575 | static int vidioc_g_input(struct file *file, void *priv, unsigned int *input) | ||
576 | { | ||
577 | struct usb_usbvision *usbvision = video_drvdata(file); | ||
578 | |||
579 | *input = usbvision->ctl_input; | ||
580 | return 0; | ||
581 | } | ||
582 | |||
583 | static int vidioc_s_input(struct file *file, void *priv, unsigned int input) | ||
584 | { | ||
585 | struct usb_usbvision *usbvision = video_drvdata(file); | ||
586 | |||
587 | if (input >= usbvision->video_inputs) | ||
588 | return -EINVAL; | ||
589 | |||
590 | usbvision_muxsel(usbvision, input); | ||
591 | usbvision_set_input(usbvision); | ||
592 | usbvision_set_output(usbvision, | ||
593 | usbvision->curwidth, | ||
594 | usbvision->curheight); | ||
595 | return 0; | ||
596 | } | ||
597 | |||
598 | static int vidioc_s_std(struct file *file, void *priv, v4l2_std_id *id) | ||
599 | { | ||
600 | struct usb_usbvision *usbvision = video_drvdata(file); | ||
601 | |||
602 | usbvision->tvnorm_id = *id; | ||
603 | |||
604 | call_all(usbvision, core, s_std, usbvision->tvnorm_id); | ||
605 | /* propagate the change to the decoder */ | ||
606 | usbvision_muxsel(usbvision, usbvision->ctl_input); | ||
607 | |||
608 | return 0; | ||
609 | } | ||
610 | |||
611 | static int vidioc_g_tuner(struct file *file, void *priv, | ||
612 | struct v4l2_tuner *vt) | ||
613 | { | ||
614 | struct usb_usbvision *usbvision = video_drvdata(file); | ||
615 | |||
616 | if (!usbvision->have_tuner || vt->index) /* Only tuner 0 */ | ||
617 | return -EINVAL; | ||
618 | if (usbvision->radio) { | ||
619 | strcpy(vt->name, "Radio"); | ||
620 | vt->type = V4L2_TUNER_RADIO; | ||
621 | } else { | ||
622 | strcpy(vt->name, "Television"); | ||
623 | } | ||
624 | /* Let clients fill in the remainder of this struct */ | ||
625 | call_all(usbvision, tuner, g_tuner, vt); | ||
626 | |||
627 | return 0; | ||
628 | } | ||
629 | |||
630 | static int vidioc_s_tuner(struct file *file, void *priv, | ||
631 | struct v4l2_tuner *vt) | ||
632 | { | ||
633 | struct usb_usbvision *usbvision = video_drvdata(file); | ||
634 | |||
635 | /* Only no or one tuner for now */ | ||
636 | if (!usbvision->have_tuner || vt->index) | ||
637 | return -EINVAL; | ||
638 | /* let clients handle this */ | ||
639 | call_all(usbvision, tuner, s_tuner, vt); | ||
640 | |||
641 | return 0; | ||
642 | } | ||
643 | |||
644 | static int vidioc_g_frequency(struct file *file, void *priv, | ||
645 | struct v4l2_frequency *freq) | ||
646 | { | ||
647 | struct usb_usbvision *usbvision = video_drvdata(file); | ||
648 | |||
649 | freq->tuner = 0; /* Only one tuner */ | ||
650 | if (usbvision->radio) | ||
651 | freq->type = V4L2_TUNER_RADIO; | ||
652 | else | ||
653 | freq->type = V4L2_TUNER_ANALOG_TV; | ||
654 | freq->frequency = usbvision->freq; | ||
655 | |||
656 | return 0; | ||
657 | } | ||
658 | |||
659 | static int vidioc_s_frequency(struct file *file, void *priv, | ||
660 | struct v4l2_frequency *freq) | ||
661 | { | ||
662 | struct usb_usbvision *usbvision = video_drvdata(file); | ||
663 | |||
664 | /* Only no or one tuner for now */ | ||
665 | if (!usbvision->have_tuner || freq->tuner) | ||
666 | return -EINVAL; | ||
667 | |||
668 | usbvision->freq = freq->frequency; | ||
669 | call_all(usbvision, tuner, s_frequency, freq); | ||
670 | |||
671 | return 0; | ||
672 | } | ||
673 | |||
674 | static int vidioc_g_audio(struct file *file, void *priv, struct v4l2_audio *a) | ||
675 | { | ||
676 | struct usb_usbvision *usbvision = video_drvdata(file); | ||
677 | |||
678 | if (usbvision->radio) | ||
679 | strcpy(a->name, "Radio"); | ||
680 | else | ||
681 | strcpy(a->name, "TV"); | ||
682 | |||
683 | return 0; | ||
684 | } | ||
685 | |||
686 | static int vidioc_s_audio(struct file *file, void *fh, | ||
687 | struct v4l2_audio *a) | ||
688 | { | ||
689 | if (a->index) | ||
690 | return -EINVAL; | ||
691 | return 0; | ||
692 | } | ||
693 | |||
694 | static int vidioc_queryctrl(struct file *file, void *priv, | ||
695 | struct v4l2_queryctrl *ctrl) | ||
696 | { | ||
697 | struct usb_usbvision *usbvision = video_drvdata(file); | ||
698 | |||
699 | call_all(usbvision, core, queryctrl, ctrl); | ||
700 | |||
701 | if (!ctrl->type) | ||
702 | return -EINVAL; | ||
703 | |||
704 | return 0; | ||
705 | } | ||
706 | |||
707 | static int vidioc_g_ctrl(struct file *file, void *priv, | ||
708 | struct v4l2_control *ctrl) | ||
709 | { | ||
710 | struct usb_usbvision *usbvision = video_drvdata(file); | ||
711 | |||
712 | call_all(usbvision, core, g_ctrl, ctrl); | ||
713 | return 0; | ||
714 | } | ||
715 | |||
716 | static int vidioc_s_ctrl(struct file *file, void *priv, | ||
717 | struct v4l2_control *ctrl) | ||
718 | { | ||
719 | struct usb_usbvision *usbvision = video_drvdata(file); | ||
720 | |||
721 | call_all(usbvision, core, s_ctrl, ctrl); | ||
722 | return 0; | ||
723 | } | ||
724 | |||
725 | static int vidioc_reqbufs(struct file *file, | ||
726 | void *priv, struct v4l2_requestbuffers *vr) | ||
727 | { | ||
728 | struct usb_usbvision *usbvision = video_drvdata(file); | ||
729 | int ret; | ||
730 | |||
731 | RESTRICT_TO_RANGE(vr->count, 1, USBVISION_NUMFRAMES); | ||
732 | |||
733 | /* Check input validity: | ||
734 | the user must do a VIDEO CAPTURE and MMAP method. */ | ||
735 | if (vr->memory != V4L2_MEMORY_MMAP) | ||
736 | return -EINVAL; | ||
737 | |||
738 | if (usbvision->streaming == stream_on) { | ||
739 | ret = usbvision_stream_interrupt(usbvision); | ||
740 | if (ret) | ||
741 | return ret; | ||
742 | } | ||
743 | |||
744 | usbvision_frames_free(usbvision); | ||
745 | usbvision_empty_framequeues(usbvision); | ||
746 | vr->count = usbvision_frames_alloc(usbvision, vr->count); | ||
747 | |||
748 | usbvision->cur_frame = NULL; | ||
749 | |||
750 | return 0; | ||
751 | } | ||
752 | |||
753 | static int vidioc_querybuf(struct file *file, | ||
754 | void *priv, struct v4l2_buffer *vb) | ||
755 | { | ||
756 | struct usb_usbvision *usbvision = video_drvdata(file); | ||
757 | struct usbvision_frame *frame; | ||
758 | |||
759 | /* FIXME : must control | ||
760 | that buffers are mapped (VIDIOC_REQBUFS has been called) */ | ||
761 | if (vb->index >= usbvision->num_frames) | ||
762 | return -EINVAL; | ||
763 | /* Updating the corresponding frame state */ | ||
764 | vb->flags = 0; | ||
765 | frame = &usbvision->frame[vb->index]; | ||
766 | if (frame->grabstate >= frame_state_ready) | ||
767 | vb->flags |= V4L2_BUF_FLAG_QUEUED; | ||
768 | if (frame->grabstate >= frame_state_done) | ||
769 | vb->flags |= V4L2_BUF_FLAG_DONE; | ||
770 | if (frame->grabstate == frame_state_unused) | ||
771 | vb->flags |= V4L2_BUF_FLAG_MAPPED; | ||
772 | vb->memory = V4L2_MEMORY_MMAP; | ||
773 | |||
774 | vb->m.offset = vb->index * PAGE_ALIGN(usbvision->max_frame_size); | ||
775 | |||
776 | vb->memory = V4L2_MEMORY_MMAP; | ||
777 | vb->field = V4L2_FIELD_NONE; | ||
778 | vb->length = usbvision->curwidth * | ||
779 | usbvision->curheight * | ||
780 | usbvision->palette.bytes_per_pixel; | ||
781 | vb->timestamp = usbvision->frame[vb->index].timestamp; | ||
782 | vb->sequence = usbvision->frame[vb->index].sequence; | ||
783 | return 0; | ||
784 | } | ||
785 | |||
786 | static int vidioc_qbuf(struct file *file, void *priv, struct v4l2_buffer *vb) | ||
787 | { | ||
788 | struct usb_usbvision *usbvision = video_drvdata(file); | ||
789 | struct usbvision_frame *frame; | ||
790 | unsigned long lock_flags; | ||
791 | |||
792 | /* FIXME : works only on VIDEO_CAPTURE MODE, MMAP. */ | ||
793 | if (vb->index >= usbvision->num_frames) | ||
794 | return -EINVAL; | ||
795 | |||
796 | frame = &usbvision->frame[vb->index]; | ||
797 | |||
798 | if (frame->grabstate != frame_state_unused) | ||
799 | return -EAGAIN; | ||
800 | |||
801 | /* Mark it as ready and enqueue frame */ | ||
802 | frame->grabstate = frame_state_ready; | ||
803 | frame->scanstate = scan_state_scanning; | ||
804 | frame->scanlength = 0; /* Accumulated in usbvision_parse_data() */ | ||
805 | |||
806 | vb->flags &= ~V4L2_BUF_FLAG_DONE; | ||
807 | |||
808 | /* set v4l2_format index */ | ||
809 | frame->v4l2_format = usbvision->palette; | ||
810 | |||
811 | spin_lock_irqsave(&usbvision->queue_lock, lock_flags); | ||
812 | list_add_tail(&usbvision->frame[vb->index].frame, &usbvision->inqueue); | ||
813 | spin_unlock_irqrestore(&usbvision->queue_lock, lock_flags); | ||
814 | |||
815 | return 0; | ||
816 | } | ||
817 | |||
818 | static int vidioc_dqbuf(struct file *file, void *priv, struct v4l2_buffer *vb) | ||
819 | { | ||
820 | struct usb_usbvision *usbvision = video_drvdata(file); | ||
821 | int ret; | ||
822 | struct usbvision_frame *f; | ||
823 | unsigned long lock_flags; | ||
824 | |||
825 | if (list_empty(&(usbvision->outqueue))) { | ||
826 | if (usbvision->streaming == stream_idle) | ||
827 | return -EINVAL; | ||
828 | ret = wait_event_interruptible | ||
829 | (usbvision->wait_frame, | ||
830 | !list_empty(&(usbvision->outqueue))); | ||
831 | if (ret) | ||
832 | return ret; | ||
833 | } | ||
834 | |||
835 | spin_lock_irqsave(&usbvision->queue_lock, lock_flags); | ||
836 | f = list_entry(usbvision->outqueue.next, | ||
837 | struct usbvision_frame, frame); | ||
838 | list_del(usbvision->outqueue.next); | ||
839 | spin_unlock_irqrestore(&usbvision->queue_lock, lock_flags); | ||
840 | |||
841 | f->grabstate = frame_state_unused; | ||
842 | |||
843 | vb->memory = V4L2_MEMORY_MMAP; | ||
844 | vb->flags = V4L2_BUF_FLAG_MAPPED | | ||
845 | V4L2_BUF_FLAG_QUEUED | | ||
846 | V4L2_BUF_FLAG_DONE; | ||
847 | vb->index = f->index; | ||
848 | vb->sequence = f->sequence; | ||
849 | vb->timestamp = f->timestamp; | ||
850 | vb->field = V4L2_FIELD_NONE; | ||
851 | vb->bytesused = f->scanlength; | ||
852 | |||
853 | return 0; | ||
854 | } | ||
855 | |||
856 | static int vidioc_streamon(struct file *file, void *priv, enum v4l2_buf_type i) | ||
857 | { | ||
858 | struct usb_usbvision *usbvision = video_drvdata(file); | ||
859 | |||
860 | usbvision->streaming = stream_on; | ||
861 | call_all(usbvision, video, s_stream, 1); | ||
862 | |||
863 | return 0; | ||
864 | } | ||
865 | |||
866 | static int vidioc_streamoff(struct file *file, | ||
867 | void *priv, enum v4l2_buf_type type) | ||
868 | { | ||
869 | struct usb_usbvision *usbvision = video_drvdata(file); | ||
870 | |||
871 | if (type != V4L2_BUF_TYPE_VIDEO_CAPTURE) | ||
872 | return -EINVAL; | ||
873 | |||
874 | if (usbvision->streaming == stream_on) { | ||
875 | usbvision_stream_interrupt(usbvision); | ||
876 | /* Stop all video streamings */ | ||
877 | call_all(usbvision, video, s_stream, 0); | ||
878 | } | ||
879 | usbvision_empty_framequeues(usbvision); | ||
880 | |||
881 | return 0; | ||
882 | } | ||
883 | |||
884 | static int vidioc_enum_fmt_vid_cap(struct file *file, void *priv, | ||
885 | struct v4l2_fmtdesc *vfd) | ||
886 | { | ||
887 | if (vfd->index >= USBVISION_SUPPORTED_PALETTES - 1) | ||
888 | return -EINVAL; | ||
889 | strcpy(vfd->description, usbvision_v4l2_format[vfd->index].desc); | ||
890 | vfd->pixelformat = usbvision_v4l2_format[vfd->index].format; | ||
891 | return 0; | ||
892 | } | ||
893 | |||
894 | static int vidioc_g_fmt_vid_cap(struct file *file, void *priv, | ||
895 | struct v4l2_format *vf) | ||
896 | { | ||
897 | struct usb_usbvision *usbvision = video_drvdata(file); | ||
898 | vf->fmt.pix.width = usbvision->curwidth; | ||
899 | vf->fmt.pix.height = usbvision->curheight; | ||
900 | vf->fmt.pix.pixelformat = usbvision->palette.format; | ||
901 | vf->fmt.pix.bytesperline = | ||
902 | usbvision->curwidth * usbvision->palette.bytes_per_pixel; | ||
903 | vf->fmt.pix.sizeimage = vf->fmt.pix.bytesperline * usbvision->curheight; | ||
904 | vf->fmt.pix.colorspace = V4L2_COLORSPACE_SMPTE170M; | ||
905 | vf->fmt.pix.field = V4L2_FIELD_NONE; /* Always progressive image */ | ||
906 | |||
907 | return 0; | ||
908 | } | ||
909 | |||
910 | static int vidioc_try_fmt_vid_cap(struct file *file, void *priv, | ||
911 | struct v4l2_format *vf) | ||
912 | { | ||
913 | struct usb_usbvision *usbvision = video_drvdata(file); | ||
914 | int format_idx; | ||
915 | |||
916 | /* Find requested format in available ones */ | ||
917 | for (format_idx = 0; format_idx < USBVISION_SUPPORTED_PALETTES; format_idx++) { | ||
918 | if (vf->fmt.pix.pixelformat == | ||
919 | usbvision_v4l2_format[format_idx].format) { | ||
920 | usbvision->palette = usbvision_v4l2_format[format_idx]; | ||
921 | break; | ||
922 | } | ||
923 | } | ||
924 | /* robustness */ | ||
925 | if (format_idx == USBVISION_SUPPORTED_PALETTES) | ||
926 | return -EINVAL; | ||
927 | RESTRICT_TO_RANGE(vf->fmt.pix.width, MIN_FRAME_WIDTH, MAX_FRAME_WIDTH); | ||
928 | RESTRICT_TO_RANGE(vf->fmt.pix.height, MIN_FRAME_HEIGHT, MAX_FRAME_HEIGHT); | ||
929 | |||
930 | vf->fmt.pix.bytesperline = vf->fmt.pix.width* | ||
931 | usbvision->palette.bytes_per_pixel; | ||
932 | vf->fmt.pix.sizeimage = vf->fmt.pix.bytesperline*vf->fmt.pix.height; | ||
933 | |||
934 | return 0; | ||
935 | } | ||
936 | |||
937 | static int vidioc_s_fmt_vid_cap(struct file *file, void *priv, | ||
938 | struct v4l2_format *vf) | ||
939 | { | ||
940 | struct usb_usbvision *usbvision = video_drvdata(file); | ||
941 | int ret; | ||
942 | |||
943 | ret = vidioc_try_fmt_vid_cap(file, priv, vf); | ||
944 | if (ret) | ||
945 | return ret; | ||
946 | |||
947 | /* stop io in case it is already in progress */ | ||
948 | if (usbvision->streaming == stream_on) { | ||
949 | ret = usbvision_stream_interrupt(usbvision); | ||
950 | if (ret) | ||
951 | return ret; | ||
952 | } | ||
953 | usbvision_frames_free(usbvision); | ||
954 | usbvision_empty_framequeues(usbvision); | ||
955 | |||
956 | usbvision->cur_frame = NULL; | ||
957 | |||
958 | /* by now we are committed to the new data... */ | ||
959 | usbvision_set_output(usbvision, vf->fmt.pix.width, vf->fmt.pix.height); | ||
960 | |||
961 | return 0; | ||
962 | } | ||
963 | |||
964 | static ssize_t usbvision_read(struct file *file, char __user *buf, | ||
965 | size_t count, loff_t *ppos) | ||
966 | { | ||
967 | struct usb_usbvision *usbvision = video_drvdata(file); | ||
968 | int noblock = file->f_flags & O_NONBLOCK; | ||
969 | unsigned long lock_flags; | ||
970 | int ret, i; | ||
971 | struct usbvision_frame *frame; | ||
972 | |||
973 | PDEBUG(DBG_IO, "%s: %ld bytes, noblock=%d", __func__, | ||
974 | (unsigned long)count, noblock); | ||
975 | |||
976 | if (!USBVISION_IS_OPERATIONAL(usbvision) || (buf == NULL)) | ||
977 | return -EFAULT; | ||
978 | |||
979 | /* This entry point is compatible with the mmap routines | ||
980 | so that a user can do either VIDIOC_QBUF/VIDIOC_DQBUF | ||
981 | to get frames or call read on the device. */ | ||
982 | if (!usbvision->num_frames) { | ||
983 | /* First, allocate some frames to work with | ||
984 | if this has not been done with VIDIOC_REQBUF */ | ||
985 | usbvision_frames_free(usbvision); | ||
986 | usbvision_empty_framequeues(usbvision); | ||
987 | usbvision_frames_alloc(usbvision, USBVISION_NUMFRAMES); | ||
988 | } | ||
989 | |||
990 | if (usbvision->streaming != stream_on) { | ||
991 | /* no stream is running, make it running ! */ | ||
992 | usbvision->streaming = stream_on; | ||
993 | call_all(usbvision, video, s_stream, 1); | ||
994 | } | ||
995 | |||
996 | /* Then, enqueue as many frames as possible | ||
997 | (like a user of VIDIOC_QBUF would do) */ | ||
998 | for (i = 0; i < usbvision->num_frames; i++) { | ||
999 | frame = &usbvision->frame[i]; | ||
1000 | if (frame->grabstate == frame_state_unused) { | ||
1001 | /* Mark it as ready and enqueue frame */ | ||
1002 | frame->grabstate = frame_state_ready; | ||
1003 | frame->scanstate = scan_state_scanning; | ||
1004 | /* Accumulated in usbvision_parse_data() */ | ||
1005 | frame->scanlength = 0; | ||
1006 | |||
1007 | /* set v4l2_format index */ | ||
1008 | frame->v4l2_format = usbvision->palette; | ||
1009 | |||
1010 | spin_lock_irqsave(&usbvision->queue_lock, lock_flags); | ||
1011 | list_add_tail(&frame->frame, &usbvision->inqueue); | ||
1012 | spin_unlock_irqrestore(&usbvision->queue_lock, | ||
1013 | lock_flags); | ||
1014 | } | ||
1015 | } | ||
1016 | |||
1017 | /* Then try to steal a frame (like a VIDIOC_DQBUF would do) */ | ||
1018 | if (list_empty(&(usbvision->outqueue))) { | ||
1019 | if (noblock) | ||
1020 | return -EAGAIN; | ||
1021 | |||
1022 | ret = wait_event_interruptible | ||
1023 | (usbvision->wait_frame, | ||
1024 | !list_empty(&(usbvision->outqueue))); | ||
1025 | if (ret) | ||
1026 | return ret; | ||
1027 | } | ||
1028 | |||
1029 | spin_lock_irqsave(&usbvision->queue_lock, lock_flags); | ||
1030 | frame = list_entry(usbvision->outqueue.next, | ||
1031 | struct usbvision_frame, frame); | ||
1032 | list_del(usbvision->outqueue.next); | ||
1033 | spin_unlock_irqrestore(&usbvision->queue_lock, lock_flags); | ||
1034 | |||
1035 | /* An error returns an empty frame */ | ||
1036 | if (frame->grabstate == frame_state_error) { | ||
1037 | frame->bytes_read = 0; | ||
1038 | return 0; | ||
1039 | } | ||
1040 | |||
1041 | PDEBUG(DBG_IO, "%s: frmx=%d, bytes_read=%ld, scanlength=%ld", | ||
1042 | __func__, | ||
1043 | frame->index, frame->bytes_read, frame->scanlength); | ||
1044 | |||
1045 | /* copy bytes to user space; we allow for partials reads */ | ||
1046 | if ((count + frame->bytes_read) > (unsigned long)frame->scanlength) | ||
1047 | count = frame->scanlength - frame->bytes_read; | ||
1048 | |||
1049 | if (copy_to_user(buf, frame->data + frame->bytes_read, count)) | ||
1050 | return -EFAULT; | ||
1051 | |||
1052 | frame->bytes_read += count; | ||
1053 | PDEBUG(DBG_IO, "%s: {copy} count used=%ld, new bytes_read=%ld", | ||
1054 | __func__, | ||
1055 | (unsigned long)count, frame->bytes_read); | ||
1056 | |||
1057 | /* For now, forget the frame if it has not been read in one shot. */ | ||
1058 | /* if (frame->bytes_read >= frame->scanlength) {*/ /* All data has been read */ | ||
1059 | frame->bytes_read = 0; | ||
1060 | |||
1061 | /* Mark it as available to be used again. */ | ||
1062 | frame->grabstate = frame_state_unused; | ||
1063 | /* } */ | ||
1064 | |||
1065 | return count; | ||
1066 | } | ||
1067 | |||
1068 | static ssize_t usbvision_v4l2_read(struct file *file, char __user *buf, | ||
1069 | size_t count, loff_t *ppos) | ||
1070 | { | ||
1071 | struct usb_usbvision *usbvision = video_drvdata(file); | ||
1072 | int res; | ||
1073 | |||
1074 | if (mutex_lock_interruptible(&usbvision->v4l2_lock)) | ||
1075 | return -ERESTARTSYS; | ||
1076 | res = usbvision_read(file, buf, count, ppos); | ||
1077 | mutex_unlock(&usbvision->v4l2_lock); | ||
1078 | return res; | ||
1079 | } | ||
1080 | |||
1081 | static int usbvision_mmap(struct file *file, struct vm_area_struct *vma) | ||
1082 | { | ||
1083 | unsigned long size = vma->vm_end - vma->vm_start, | ||
1084 | start = vma->vm_start; | ||
1085 | void *pos; | ||
1086 | u32 i; | ||
1087 | struct usb_usbvision *usbvision = video_drvdata(file); | ||
1088 | |||
1089 | PDEBUG(DBG_MMAP, "mmap"); | ||
1090 | |||
1091 | if (!USBVISION_IS_OPERATIONAL(usbvision)) | ||
1092 | return -EFAULT; | ||
1093 | |||
1094 | if (!(vma->vm_flags & VM_WRITE) || | ||
1095 | size != PAGE_ALIGN(usbvision->max_frame_size)) { | ||
1096 | return -EINVAL; | ||
1097 | } | ||
1098 | |||
1099 | for (i = 0; i < usbvision->num_frames; i++) { | ||
1100 | if (((PAGE_ALIGN(usbvision->max_frame_size)*i) >> PAGE_SHIFT) == | ||
1101 | vma->vm_pgoff) | ||
1102 | break; | ||
1103 | } | ||
1104 | if (i == usbvision->num_frames) { | ||
1105 | PDEBUG(DBG_MMAP, | ||
1106 | "mmap: user supplied mapping address is out of range"); | ||
1107 | return -EINVAL; | ||
1108 | } | ||
1109 | |||
1110 | /* VM_IO is eventually going to replace PageReserved altogether */ | ||
1111 | vma->vm_flags |= VM_IO; | ||
1112 | vma->vm_flags |= VM_RESERVED; /* avoid to swap out this VMA */ | ||
1113 | |||
1114 | pos = usbvision->frame[i].data; | ||
1115 | while (size > 0) { | ||
1116 | if (vm_insert_page(vma, start, vmalloc_to_page(pos))) { | ||
1117 | PDEBUG(DBG_MMAP, "mmap: vm_insert_page failed"); | ||
1118 | return -EAGAIN; | ||
1119 | } | ||
1120 | start += PAGE_SIZE; | ||
1121 | pos += PAGE_SIZE; | ||
1122 | size -= PAGE_SIZE; | ||
1123 | } | ||
1124 | |||
1125 | return 0; | ||
1126 | } | ||
1127 | |||
1128 | static int usbvision_v4l2_mmap(struct file *file, struct vm_area_struct *vma) | ||
1129 | { | ||
1130 | struct usb_usbvision *usbvision = video_drvdata(file); | ||
1131 | int res; | ||
1132 | |||
1133 | if (mutex_lock_interruptible(&usbvision->v4l2_lock)) | ||
1134 | return -ERESTARTSYS; | ||
1135 | res = usbvision_mmap(file, vma); | ||
1136 | mutex_unlock(&usbvision->v4l2_lock); | ||
1137 | return res; | ||
1138 | } | ||
1139 | |||
1140 | /* | ||
1141 | * Here comes the stuff for radio on usbvision based devices | ||
1142 | * | ||
1143 | */ | ||
1144 | static int usbvision_radio_open(struct file *file) | ||
1145 | { | ||
1146 | struct usb_usbvision *usbvision = video_drvdata(file); | ||
1147 | int err_code = 0; | ||
1148 | |||
1149 | PDEBUG(DBG_IO, "%s:", __func__); | ||
1150 | |||
1151 | if (mutex_lock_interruptible(&usbvision->v4l2_lock)) | ||
1152 | return -ERESTARTSYS; | ||
1153 | if (usbvision->user) { | ||
1154 | dev_err(&usbvision->rdev->dev, | ||
1155 | "%s: Someone tried to open an already opened USBVision Radio!\n", | ||
1156 | __func__); | ||
1157 | err_code = -EBUSY; | ||
1158 | } else { | ||
1159 | if (power_on_at_open) { | ||
1160 | usbvision_reset_power_off_timer(usbvision); | ||
1161 | if (usbvision->power == 0) { | ||
1162 | usbvision_power_on(usbvision); | ||
1163 | usbvision_i2c_register(usbvision); | ||
1164 | } | ||
1165 | } | ||
1166 | |||
1167 | /* Alternate interface 1 is is the biggest frame size */ | ||
1168 | err_code = usbvision_set_alternate(usbvision); | ||
1169 | if (err_code < 0) { | ||
1170 | usbvision->last_error = err_code; | ||
1171 | err_code = -EBUSY; | ||
1172 | goto out; | ||
1173 | } | ||
1174 | |||
1175 | /* If so far no errors then we shall start the radio */ | ||
1176 | usbvision->radio = 1; | ||
1177 | call_all(usbvision, tuner, s_radio); | ||
1178 | usbvision_set_audio(usbvision, USBVISION_AUDIO_RADIO); | ||
1179 | usbvision->user++; | ||
1180 | } | ||
1181 | |||
1182 | if (err_code) { | ||
1183 | if (power_on_at_open) { | ||
1184 | usbvision_i2c_unregister(usbvision); | ||
1185 | usbvision_power_off(usbvision); | ||
1186 | usbvision->initialized = 0; | ||
1187 | } | ||
1188 | } | ||
1189 | out: | ||
1190 | mutex_unlock(&usbvision->v4l2_lock); | ||
1191 | return err_code; | ||
1192 | } | ||
1193 | |||
1194 | |||
1195 | static int usbvision_radio_close(struct file *file) | ||
1196 | { | ||
1197 | struct usb_usbvision *usbvision = video_drvdata(file); | ||
1198 | int err_code = 0; | ||
1199 | |||
1200 | PDEBUG(DBG_IO, ""); | ||
1201 | |||
1202 | mutex_lock(&usbvision->v4l2_lock); | ||
1203 | /* Set packet size to 0 */ | ||
1204 | usbvision->iface_alt = 0; | ||
1205 | err_code = usb_set_interface(usbvision->dev, usbvision->iface, | ||
1206 | usbvision->iface_alt); | ||
1207 | |||
1208 | usbvision_audio_off(usbvision); | ||
1209 | usbvision->radio = 0; | ||
1210 | usbvision->user--; | ||
1211 | |||
1212 | if (power_on_at_open) { | ||
1213 | usbvision_set_power_off_timer(usbvision); | ||
1214 | usbvision->initialized = 0; | ||
1215 | } | ||
1216 | |||
1217 | if (usbvision->remove_pending) { | ||
1218 | printk(KERN_INFO "%s: Final disconnect\n", __func__); | ||
1219 | usbvision_release(usbvision); | ||
1220 | } | ||
1221 | |||
1222 | mutex_unlock(&usbvision->v4l2_lock); | ||
1223 | PDEBUG(DBG_IO, "success"); | ||
1224 | return err_code; | ||
1225 | } | ||
1226 | |||
1227 | /* Video registration stuff */ | ||
1228 | |||
1229 | /* Video template */ | ||
1230 | static const struct v4l2_file_operations usbvision_fops = { | ||
1231 | .owner = THIS_MODULE, | ||
1232 | .open = usbvision_v4l2_open, | ||
1233 | .release = usbvision_v4l2_close, | ||
1234 | .read = usbvision_v4l2_read, | ||
1235 | .mmap = usbvision_v4l2_mmap, | ||
1236 | .unlocked_ioctl = video_ioctl2, | ||
1237 | /* .poll = video_poll, */ | ||
1238 | }; | ||
1239 | |||
1240 | static const struct v4l2_ioctl_ops usbvision_ioctl_ops = { | ||
1241 | .vidioc_querycap = vidioc_querycap, | ||
1242 | .vidioc_enum_fmt_vid_cap = vidioc_enum_fmt_vid_cap, | ||
1243 | .vidioc_g_fmt_vid_cap = vidioc_g_fmt_vid_cap, | ||
1244 | .vidioc_try_fmt_vid_cap = vidioc_try_fmt_vid_cap, | ||
1245 | .vidioc_s_fmt_vid_cap = vidioc_s_fmt_vid_cap, | ||
1246 | .vidioc_reqbufs = vidioc_reqbufs, | ||
1247 | .vidioc_querybuf = vidioc_querybuf, | ||
1248 | .vidioc_qbuf = vidioc_qbuf, | ||
1249 | .vidioc_dqbuf = vidioc_dqbuf, | ||
1250 | .vidioc_s_std = vidioc_s_std, | ||
1251 | .vidioc_enum_input = vidioc_enum_input, | ||
1252 | .vidioc_g_input = vidioc_g_input, | ||
1253 | .vidioc_s_input = vidioc_s_input, | ||
1254 | .vidioc_queryctrl = vidioc_queryctrl, | ||
1255 | .vidioc_g_audio = vidioc_g_audio, | ||
1256 | .vidioc_s_audio = vidioc_s_audio, | ||
1257 | .vidioc_g_ctrl = vidioc_g_ctrl, | ||
1258 | .vidioc_s_ctrl = vidioc_s_ctrl, | ||
1259 | .vidioc_streamon = vidioc_streamon, | ||
1260 | .vidioc_streamoff = vidioc_streamoff, | ||
1261 | .vidioc_g_tuner = vidioc_g_tuner, | ||
1262 | .vidioc_s_tuner = vidioc_s_tuner, | ||
1263 | .vidioc_g_frequency = vidioc_g_frequency, | ||
1264 | .vidioc_s_frequency = vidioc_s_frequency, | ||
1265 | #ifdef CONFIG_VIDEO_ADV_DEBUG | ||
1266 | .vidioc_g_register = vidioc_g_register, | ||
1267 | .vidioc_s_register = vidioc_s_register, | ||
1268 | #endif | ||
1269 | }; | ||
1270 | |||
1271 | static struct video_device usbvision_video_template = { | ||
1272 | .fops = &usbvision_fops, | ||
1273 | .ioctl_ops = &usbvision_ioctl_ops, | ||
1274 | .name = "usbvision-video", | ||
1275 | .release = video_device_release, | ||
1276 | .tvnorms = USBVISION_NORMS, | ||
1277 | .current_norm = V4L2_STD_PAL | ||
1278 | }; | ||
1279 | |||
1280 | |||
1281 | /* Radio template */ | ||
1282 | static const struct v4l2_file_operations usbvision_radio_fops = { | ||
1283 | .owner = THIS_MODULE, | ||
1284 | .open = usbvision_radio_open, | ||
1285 | .release = usbvision_radio_close, | ||
1286 | .unlocked_ioctl = video_ioctl2, | ||
1287 | }; | ||
1288 | |||
1289 | static const struct v4l2_ioctl_ops usbvision_radio_ioctl_ops = { | ||
1290 | .vidioc_querycap = vidioc_querycap, | ||
1291 | .vidioc_enum_input = vidioc_enum_input, | ||
1292 | .vidioc_g_input = vidioc_g_input, | ||
1293 | .vidioc_s_input = vidioc_s_input, | ||
1294 | .vidioc_queryctrl = vidioc_queryctrl, | ||
1295 | .vidioc_g_audio = vidioc_g_audio, | ||
1296 | .vidioc_s_audio = vidioc_s_audio, | ||
1297 | .vidioc_g_ctrl = vidioc_g_ctrl, | ||
1298 | .vidioc_s_ctrl = vidioc_s_ctrl, | ||
1299 | .vidioc_g_tuner = vidioc_g_tuner, | ||
1300 | .vidioc_s_tuner = vidioc_s_tuner, | ||
1301 | .vidioc_g_frequency = vidioc_g_frequency, | ||
1302 | .vidioc_s_frequency = vidioc_s_frequency, | ||
1303 | }; | ||
1304 | |||
1305 | static struct video_device usbvision_radio_template = { | ||
1306 | .fops = &usbvision_radio_fops, | ||
1307 | .name = "usbvision-radio", | ||
1308 | .release = video_device_release, | ||
1309 | .ioctl_ops = &usbvision_radio_ioctl_ops, | ||
1310 | |||
1311 | .tvnorms = USBVISION_NORMS, | ||
1312 | .current_norm = V4L2_STD_PAL | ||
1313 | }; | ||
1314 | |||
1315 | |||
1316 | static struct video_device *usbvision_vdev_init(struct usb_usbvision *usbvision, | ||
1317 | struct video_device *vdev_template, | ||
1318 | char *name) | ||
1319 | { | ||
1320 | struct usb_device *usb_dev = usbvision->dev; | ||
1321 | struct video_device *vdev; | ||
1322 | |||
1323 | if (usb_dev == NULL) { | ||
1324 | dev_err(&usbvision->dev->dev, | ||
1325 | "%s: usbvision->dev is not set\n", __func__); | ||
1326 | return NULL; | ||
1327 | } | ||
1328 | |||
1329 | vdev = video_device_alloc(); | ||
1330 | if (NULL == vdev) | ||
1331 | return NULL; | ||
1332 | *vdev = *vdev_template; | ||
1333 | vdev->lock = &usbvision->v4l2_lock; | ||
1334 | vdev->v4l2_dev = &usbvision->v4l2_dev; | ||
1335 | snprintf(vdev->name, sizeof(vdev->name), "%s", name); | ||
1336 | video_set_drvdata(vdev, usbvision); | ||
1337 | return vdev; | ||
1338 | } | ||
1339 | |||
1340 | /* unregister video4linux devices */ | ||
1341 | static void usbvision_unregister_video(struct usb_usbvision *usbvision) | ||
1342 | { | ||
1343 | /* Radio Device: */ | ||
1344 | if (usbvision->rdev) { | ||
1345 | PDEBUG(DBG_PROBE, "unregister %s [v4l2]", | ||
1346 | video_device_node_name(usbvision->rdev)); | ||
1347 | if (video_is_registered(usbvision->rdev)) | ||
1348 | video_unregister_device(usbvision->rdev); | ||
1349 | else | ||
1350 | video_device_release(usbvision->rdev); | ||
1351 | usbvision->rdev = NULL; | ||
1352 | } | ||
1353 | |||
1354 | /* Video Device: */ | ||
1355 | if (usbvision->vdev) { | ||
1356 | PDEBUG(DBG_PROBE, "unregister %s [v4l2]", | ||
1357 | video_device_node_name(usbvision->vdev)); | ||
1358 | if (video_is_registered(usbvision->vdev)) | ||
1359 | video_unregister_device(usbvision->vdev); | ||
1360 | else | ||
1361 | video_device_release(usbvision->vdev); | ||
1362 | usbvision->vdev = NULL; | ||
1363 | } | ||
1364 | } | ||
1365 | |||
1366 | /* register video4linux devices */ | ||
1367 | static int __devinit usbvision_register_video(struct usb_usbvision *usbvision) | ||
1368 | { | ||
1369 | /* Video Device: */ | ||
1370 | usbvision->vdev = usbvision_vdev_init(usbvision, | ||
1371 | &usbvision_video_template, | ||
1372 | "USBVision Video"); | ||
1373 | if (usbvision->vdev == NULL) | ||
1374 | goto err_exit; | ||
1375 | if (video_register_device(usbvision->vdev, VFL_TYPE_GRABBER, video_nr) < 0) | ||
1376 | goto err_exit; | ||
1377 | printk(KERN_INFO "USBVision[%d]: registered USBVision Video device %s [v4l2]\n", | ||
1378 | usbvision->nr, video_device_node_name(usbvision->vdev)); | ||
1379 | |||
1380 | /* Radio Device: */ | ||
1381 | if (usbvision_device_data[usbvision->dev_model].radio) { | ||
1382 | /* usbvision has radio */ | ||
1383 | usbvision->rdev = usbvision_vdev_init(usbvision, | ||
1384 | &usbvision_radio_template, | ||
1385 | "USBVision Radio"); | ||
1386 | if (usbvision->rdev == NULL) | ||
1387 | goto err_exit; | ||
1388 | if (video_register_device(usbvision->rdev, VFL_TYPE_RADIO, radio_nr) < 0) | ||
1389 | goto err_exit; | ||
1390 | printk(KERN_INFO "USBVision[%d]: registered USBVision Radio device %s [v4l2]\n", | ||
1391 | usbvision->nr, video_device_node_name(usbvision->rdev)); | ||
1392 | } | ||
1393 | /* all done */ | ||
1394 | return 0; | ||
1395 | |||
1396 | err_exit: | ||
1397 | dev_err(&usbvision->dev->dev, | ||
1398 | "USBVision[%d]: video_register_device() failed\n", | ||
1399 | usbvision->nr); | ||
1400 | usbvision_unregister_video(usbvision); | ||
1401 | return -1; | ||
1402 | } | ||
1403 | |||
1404 | /* | ||
1405 | * usbvision_alloc() | ||
1406 | * | ||
1407 | * This code allocates the struct usb_usbvision. | ||
1408 | * It is filled with default values. | ||
1409 | * | ||
1410 | * Returns NULL on error, a pointer to usb_usbvision else. | ||
1411 | * | ||
1412 | */ | ||
1413 | static struct usb_usbvision *usbvision_alloc(struct usb_device *dev, | ||
1414 | struct usb_interface *intf) | ||
1415 | { | ||
1416 | struct usb_usbvision *usbvision; | ||
1417 | |||
1418 | usbvision = kzalloc(sizeof(struct usb_usbvision), GFP_KERNEL); | ||
1419 | if (usbvision == NULL) | ||
1420 | return NULL; | ||
1421 | |||
1422 | usbvision->dev = dev; | ||
1423 | if (v4l2_device_register(&intf->dev, &usbvision->v4l2_dev)) | ||
1424 | goto err_free; | ||
1425 | |||
1426 | mutex_init(&usbvision->v4l2_lock); | ||
1427 | |||
1428 | /* prepare control urb for control messages during interrupts */ | ||
1429 | usbvision->ctrl_urb = usb_alloc_urb(USBVISION_URB_FRAMES, GFP_KERNEL); | ||
1430 | if (usbvision->ctrl_urb == NULL) | ||
1431 | goto err_unreg; | ||
1432 | init_waitqueue_head(&usbvision->ctrl_urb_wq); | ||
1433 | |||
1434 | usbvision_init_power_off_timer(usbvision); | ||
1435 | |||
1436 | return usbvision; | ||
1437 | |||
1438 | err_unreg: | ||
1439 | v4l2_device_unregister(&usbvision->v4l2_dev); | ||
1440 | err_free: | ||
1441 | kfree(usbvision); | ||
1442 | return NULL; | ||
1443 | } | ||
1444 | |||
1445 | /* | ||
1446 | * usbvision_release() | ||
1447 | * | ||
1448 | * This code does final release of struct usb_usbvision. This happens | ||
1449 | * after the device is disconnected -and- all clients closed their files. | ||
1450 | * | ||
1451 | */ | ||
1452 | static void usbvision_release(struct usb_usbvision *usbvision) | ||
1453 | { | ||
1454 | PDEBUG(DBG_PROBE, ""); | ||
1455 | |||
1456 | usbvision_reset_power_off_timer(usbvision); | ||
1457 | |||
1458 | usbvision->initialized = 0; | ||
1459 | |||
1460 | usbvision_remove_sysfs(usbvision->vdev); | ||
1461 | usbvision_unregister_video(usbvision); | ||
1462 | |||
1463 | usb_free_urb(usbvision->ctrl_urb); | ||
1464 | |||
1465 | v4l2_device_unregister(&usbvision->v4l2_dev); | ||
1466 | kfree(usbvision); | ||
1467 | |||
1468 | PDEBUG(DBG_PROBE, "success"); | ||
1469 | } | ||
1470 | |||
1471 | |||
1472 | /*********************** usb interface **********************************/ | ||
1473 | |||
1474 | static void usbvision_configure_video(struct usb_usbvision *usbvision) | ||
1475 | { | ||
1476 | int model; | ||
1477 | |||
1478 | if (usbvision == NULL) | ||
1479 | return; | ||
1480 | |||
1481 | model = usbvision->dev_model; | ||
1482 | usbvision->palette = usbvision_v4l2_format[2]; /* V4L2_PIX_FMT_RGB24; */ | ||
1483 | |||
1484 | if (usbvision_device_data[usbvision->dev_model].vin_reg2_override) { | ||
1485 | usbvision->vin_reg2_preset = | ||
1486 | usbvision_device_data[usbvision->dev_model].vin_reg2; | ||
1487 | } else { | ||
1488 | usbvision->vin_reg2_preset = 0; | ||
1489 | } | ||
1490 | |||
1491 | usbvision->tvnorm_id = usbvision_device_data[model].video_norm; | ||
1492 | |||
1493 | usbvision->video_inputs = usbvision_device_data[model].video_channels; | ||
1494 | usbvision->ctl_input = 0; | ||
1495 | |||
1496 | /* This should be here to make i2c clients to be able to register */ | ||
1497 | /* first switch off audio */ | ||
1498 | if (usbvision_device_data[model].audio_channels > 0) | ||
1499 | usbvision_audio_off(usbvision); | ||
1500 | if (!power_on_at_open) { | ||
1501 | /* and then power up the noisy tuner */ | ||
1502 | usbvision_power_on(usbvision); | ||
1503 | usbvision_i2c_register(usbvision); | ||
1504 | } | ||
1505 | } | ||
1506 | |||
1507 | /* | ||
1508 | * usbvision_probe() | ||
1509 | * | ||
1510 | * This procedure queries device descriptor and accepts the interface | ||
1511 | * if it looks like USBVISION video device | ||
1512 | * | ||
1513 | */ | ||
1514 | static int __devinit usbvision_probe(struct usb_interface *intf, | ||
1515 | const struct usb_device_id *devid) | ||
1516 | { | ||
1517 | struct usb_device *dev = usb_get_dev(interface_to_usbdev(intf)); | ||
1518 | struct usb_interface *uif; | ||
1519 | __u8 ifnum = intf->altsetting->desc.bInterfaceNumber; | ||
1520 | const struct usb_host_interface *interface; | ||
1521 | struct usb_usbvision *usbvision = NULL; | ||
1522 | const struct usb_endpoint_descriptor *endpoint; | ||
1523 | int model, i; | ||
1524 | |||
1525 | PDEBUG(DBG_PROBE, "VID=%#04x, PID=%#04x, ifnum=%u", | ||
1526 | dev->descriptor.idVendor, | ||
1527 | dev->descriptor.idProduct, ifnum); | ||
1528 | |||
1529 | model = devid->driver_info; | ||
1530 | if (model < 0 || model >= usbvision_device_data_size) { | ||
1531 | PDEBUG(DBG_PROBE, "model out of bounds %d", model); | ||
1532 | return -ENODEV; | ||
1533 | } | ||
1534 | printk(KERN_INFO "%s: %s found\n", __func__, | ||
1535 | usbvision_device_data[model].model_string); | ||
1536 | |||
1537 | if (usbvision_device_data[model].interface >= 0) | ||
1538 | interface = &dev->actconfig->interface[usbvision_device_data[model].interface]->altsetting[0]; | ||
1539 | else | ||
1540 | interface = &dev->actconfig->interface[ifnum]->altsetting[0]; | ||
1541 | endpoint = &interface->endpoint[1].desc; | ||
1542 | if (!usb_endpoint_xfer_isoc(endpoint)) { | ||
1543 | dev_err(&intf->dev, "%s: interface %d. has non-ISO endpoint!\n", | ||
1544 | __func__, ifnum); | ||
1545 | dev_err(&intf->dev, "%s: Endpoint attributes %d", | ||
1546 | __func__, endpoint->bmAttributes); | ||
1547 | return -ENODEV; | ||
1548 | } | ||
1549 | if (usb_endpoint_dir_out(endpoint)) { | ||
1550 | dev_err(&intf->dev, "%s: interface %d. has ISO OUT endpoint!\n", | ||
1551 | __func__, ifnum); | ||
1552 | return -ENODEV; | ||
1553 | } | ||
1554 | |||
1555 | usbvision = usbvision_alloc(dev, intf); | ||
1556 | if (usbvision == NULL) { | ||
1557 | dev_err(&intf->dev, "%s: couldn't allocate USBVision struct\n", __func__); | ||
1558 | return -ENOMEM; | ||
1559 | } | ||
1560 | |||
1561 | if (dev->descriptor.bNumConfigurations > 1) | ||
1562 | usbvision->bridge_type = BRIDGE_NT1004; | ||
1563 | else if (model == DAZZLE_DVC_90_REV_1_SECAM) | ||
1564 | usbvision->bridge_type = BRIDGE_NT1005; | ||
1565 | else | ||
1566 | usbvision->bridge_type = BRIDGE_NT1003; | ||
1567 | PDEBUG(DBG_PROBE, "bridge_type %d", usbvision->bridge_type); | ||
1568 | |||
1569 | /* compute alternate max packet sizes */ | ||
1570 | uif = dev->actconfig->interface[0]; | ||
1571 | |||
1572 | usbvision->num_alt = uif->num_altsetting; | ||
1573 | PDEBUG(DBG_PROBE, "Alternate settings: %i", usbvision->num_alt); | ||
1574 | usbvision->alt_max_pkt_size = kmalloc(32 * usbvision->num_alt, GFP_KERNEL); | ||
1575 | if (usbvision->alt_max_pkt_size == NULL) { | ||
1576 | dev_err(&intf->dev, "usbvision: out of memory!\n"); | ||
1577 | return -ENOMEM; | ||
1578 | } | ||
1579 | |||
1580 | for (i = 0; i < usbvision->num_alt; i++) { | ||
1581 | u16 tmp = le16_to_cpu(uif->altsetting[i].endpoint[1].desc. | ||
1582 | wMaxPacketSize); | ||
1583 | usbvision->alt_max_pkt_size[i] = | ||
1584 | (tmp & 0x07ff) * (((tmp & 0x1800) >> 11) + 1); | ||
1585 | PDEBUG(DBG_PROBE, "Alternate setting %i, max size= %i", i, | ||
1586 | usbvision->alt_max_pkt_size[i]); | ||
1587 | } | ||
1588 | |||
1589 | |||
1590 | usbvision->nr = usbvision_nr++; | ||
1591 | |||
1592 | usbvision->have_tuner = usbvision_device_data[model].tuner; | ||
1593 | if (usbvision->have_tuner) | ||
1594 | usbvision->tuner_type = usbvision_device_data[model].tuner_type; | ||
1595 | |||
1596 | usbvision->dev_model = model; | ||
1597 | usbvision->remove_pending = 0; | ||
1598 | usbvision->iface = ifnum; | ||
1599 | usbvision->iface_alt = 0; | ||
1600 | usbvision->video_endp = endpoint->bEndpointAddress; | ||
1601 | usbvision->isoc_packet_size = 0; | ||
1602 | usbvision->usb_bandwidth = 0; | ||
1603 | usbvision->user = 0; | ||
1604 | usbvision->streaming = stream_off; | ||
1605 | usbvision_configure_video(usbvision); | ||
1606 | usbvision_register_video(usbvision); | ||
1607 | |||
1608 | usbvision_create_sysfs(usbvision->vdev); | ||
1609 | |||
1610 | PDEBUG(DBG_PROBE, "success"); | ||
1611 | return 0; | ||
1612 | } | ||
1613 | |||
1614 | |||
1615 | /* | ||
1616 | * usbvision_disconnect() | ||
1617 | * | ||
1618 | * This procedure stops all driver activity, deallocates interface-private | ||
1619 | * structure (pointed by 'ptr') and after that driver should be removable | ||
1620 | * with no ill consequences. | ||
1621 | * | ||
1622 | */ | ||
1623 | static void __devexit usbvision_disconnect(struct usb_interface *intf) | ||
1624 | { | ||
1625 | struct usb_usbvision *usbvision = to_usbvision(usb_get_intfdata(intf)); | ||
1626 | |||
1627 | PDEBUG(DBG_PROBE, ""); | ||
1628 | |||
1629 | if (usbvision == NULL) { | ||
1630 | pr_err("%s: usb_get_intfdata() failed\n", __func__); | ||
1631 | return; | ||
1632 | } | ||
1633 | |||
1634 | mutex_lock(&usbvision->v4l2_lock); | ||
1635 | |||
1636 | /* At this time we ask to cancel outstanding URBs */ | ||
1637 | usbvision_stop_isoc(usbvision); | ||
1638 | |||
1639 | v4l2_device_disconnect(&usbvision->v4l2_dev); | ||
1640 | |||
1641 | if (usbvision->power) { | ||
1642 | usbvision_i2c_unregister(usbvision); | ||
1643 | usbvision_power_off(usbvision); | ||
1644 | } | ||
1645 | usbvision->remove_pending = 1; /* Now all ISO data will be ignored */ | ||
1646 | |||
1647 | usb_put_dev(usbvision->dev); | ||
1648 | usbvision->dev = NULL; /* USB device is no more */ | ||
1649 | |||
1650 | mutex_unlock(&usbvision->v4l2_lock); | ||
1651 | |||
1652 | if (usbvision->user) { | ||
1653 | printk(KERN_INFO "%s: In use, disconnect pending\n", | ||
1654 | __func__); | ||
1655 | wake_up_interruptible(&usbvision->wait_frame); | ||
1656 | wake_up_interruptible(&usbvision->wait_stream); | ||
1657 | } else { | ||
1658 | usbvision_release(usbvision); | ||
1659 | } | ||
1660 | |||
1661 | PDEBUG(DBG_PROBE, "success"); | ||
1662 | } | ||
1663 | |||
1664 | static struct usb_driver usbvision_driver = { | ||
1665 | .name = "usbvision", | ||
1666 | .id_table = usbvision_table, | ||
1667 | .probe = usbvision_probe, | ||
1668 | .disconnect = __devexit_p(usbvision_disconnect), | ||
1669 | }; | ||
1670 | |||
1671 | /* | ||
1672 | * usbvision_init() | ||
1673 | * | ||
1674 | * This code is run to initialize the driver. | ||
1675 | * | ||
1676 | */ | ||
1677 | static int __init usbvision_init(void) | ||
1678 | { | ||
1679 | int err_code; | ||
1680 | |||
1681 | PDEBUG(DBG_PROBE, ""); | ||
1682 | |||
1683 | PDEBUG(DBG_IO, "IO debugging is enabled [video]"); | ||
1684 | PDEBUG(DBG_PROBE, "PROBE debugging is enabled [video]"); | ||
1685 | PDEBUG(DBG_MMAP, "MMAP debugging is enabled [video]"); | ||
1686 | |||
1687 | /* disable planar mode support unless compression enabled */ | ||
1688 | if (isoc_mode != ISOC_MODE_COMPRESS) { | ||
1689 | /* FIXME : not the right way to set supported flag */ | ||
1690 | usbvision_v4l2_format[6].supported = 0; /* V4L2_PIX_FMT_YVU420 */ | ||
1691 | usbvision_v4l2_format[7].supported = 0; /* V4L2_PIX_FMT_YUV422P */ | ||
1692 | } | ||
1693 | |||
1694 | err_code = usb_register(&usbvision_driver); | ||
1695 | |||
1696 | if (err_code == 0) { | ||
1697 | printk(KERN_INFO DRIVER_DESC " : " USBVISION_VERSION_STRING "\n"); | ||
1698 | PDEBUG(DBG_PROBE, "success"); | ||
1699 | } | ||
1700 | return err_code; | ||
1701 | } | ||
1702 | |||
1703 | static void __exit usbvision_exit(void) | ||
1704 | { | ||
1705 | PDEBUG(DBG_PROBE, ""); | ||
1706 | |||
1707 | usb_deregister(&usbvision_driver); | ||
1708 | PDEBUG(DBG_PROBE, "success"); | ||
1709 | } | ||
1710 | |||
1711 | module_init(usbvision_init); | ||
1712 | module_exit(usbvision_exit); | ||
1713 | |||
1714 | /* | ||
1715 | * Overrides for Emacs so that we follow Linus's tabbing style. | ||
1716 | * --------------------------------------------------------------------------- | ||
1717 | * Local variables: | ||
1718 | * c-basic-offset: 8 | ||
1719 | * End: | ||
1720 | */ | ||
diff --git a/drivers/media/usb/usbvision/usbvision.h b/drivers/media/usb/usbvision/usbvision.h new file mode 100644 index 000000000000..43cf61fe4943 --- /dev/null +++ b/drivers/media/usb/usbvision/usbvision.h | |||
@@ -0,0 +1,535 @@ | |||
1 | /* | ||
2 | * USBVISION.H | ||
3 | * usbvision header file | ||
4 | * | ||
5 | * Copyright (c) 1999-2005 Joerg Heckenbach <joerg@heckenbach-aw.de> | ||
6 | * Dwaine Garden <dwainegarden@rogers.com> | ||
7 | * | ||
8 | * | ||
9 | * Report problems to v4l MailingList: linux-media@vger.kernel.org | ||
10 | * | ||
11 | * This module is part of usbvision driver project. | ||
12 | * Updates to driver completed by Dwaine P. Garden | ||
13 | * v4l2 conversion by Thierry Merle <thierry.merle@free.fr> | ||
14 | * | ||
15 | * This program is free software; you can redistribute it and/or modify | ||
16 | * it under the terms of the GNU General Public License as published by | ||
17 | * the Free Software Foundation; either version 2 of the License, or | ||
18 | * (at your option) any later version. | ||
19 | * | ||
20 | * This program is distributed in the hope that it will be useful, | ||
21 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
22 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
23 | * GNU General Public License for more details. | ||
24 | * | ||
25 | * You should have received a copy of the GNU General Public License | ||
26 | * along with this program; if not, write to the Free Software | ||
27 | * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. | ||
28 | */ | ||
29 | |||
30 | |||
31 | #ifndef __LINUX_USBVISION_H | ||
32 | #define __LINUX_USBVISION_H | ||
33 | |||
34 | #include <linux/list.h> | ||
35 | #include <linux/usb.h> | ||
36 | #include <linux/i2c.h> | ||
37 | #include <linux/mutex.h> | ||
38 | #include <media/v4l2-device.h> | ||
39 | #include <media/tuner.h> | ||
40 | #include <linux/videodev2.h> | ||
41 | |||
42 | #define USBVISION_DEBUG /* Turn on debug messages */ | ||
43 | |||
44 | #define USBVISION_PWR_REG 0x00 | ||
45 | #define USBVISION_SSPND_EN (1 << 1) | ||
46 | #define USBVISION_RES2 (1 << 2) | ||
47 | #define USBVISION_PWR_VID (1 << 5) | ||
48 | #define USBVISION_E2_EN (1 << 7) | ||
49 | #define USBVISION_CONFIG_REG 0x01 | ||
50 | #define USBVISION_ADRS_REG 0x02 | ||
51 | #define USBVISION_ALTER_REG 0x03 | ||
52 | #define USBVISION_FORCE_ALTER_REG 0x04 | ||
53 | #define USBVISION_STATUS_REG 0x05 | ||
54 | #define USBVISION_IOPIN_REG 0x06 | ||
55 | #define USBVISION_IO_1 (1 << 0) | ||
56 | #define USBVISION_IO_2 (1 << 1) | ||
57 | #define USBVISION_AUDIO_IN 0 | ||
58 | #define USBVISION_AUDIO_TV 1 | ||
59 | #define USBVISION_AUDIO_RADIO 2 | ||
60 | #define USBVISION_AUDIO_MUTE 3 | ||
61 | #define USBVISION_SER_MODE 0x07 | ||
62 | #define USBVISION_CLK_OUT (1 << 0) | ||
63 | #define USBVISION_DAT_IO (1 << 1) | ||
64 | #define USBVISION_SENS_OUT (1 << 2) | ||
65 | #define USBVISION_SER_MODE_SOFT (0 << 4) | ||
66 | #define USBVISION_SER_MODE_SIO (1 << 4) | ||
67 | #define USBVISION_SER_ADRS 0x08 | ||
68 | #define USBVISION_SER_CONT 0x09 | ||
69 | #define USBVISION_SER_DAT1 0x0A | ||
70 | #define USBVISION_SER_DAT2 0x0B | ||
71 | #define USBVISION_SER_DAT3 0x0C | ||
72 | #define USBVISION_SER_DAT4 0x0D | ||
73 | #define USBVISION_EE_DATA 0x0E | ||
74 | #define USBVISION_EE_LSBAD 0x0F | ||
75 | #define USBVISION_EE_CONT 0x10 | ||
76 | #define USBVISION_DRM_CONT 0x12 | ||
77 | #define USBVISION_REF (1 << 0) | ||
78 | #define USBVISION_RES_UR (1 << 2) | ||
79 | #define USBVISION_RES_FDL (1 << 3) | ||
80 | #define USBVISION_RES_VDW (1 << 4) | ||
81 | #define USBVISION_DRM_PRM1 0x13 | ||
82 | #define USBVISION_DRM_PRM2 0x14 | ||
83 | #define USBVISION_DRM_PRM3 0x15 | ||
84 | #define USBVISION_DRM_PRM4 0x16 | ||
85 | #define USBVISION_DRM_PRM5 0x17 | ||
86 | #define USBVISION_DRM_PRM6 0x18 | ||
87 | #define USBVISION_DRM_PRM7 0x19 | ||
88 | #define USBVISION_DRM_PRM8 0x1A | ||
89 | #define USBVISION_VIN_REG1 0x1B | ||
90 | #define USBVISION_8_422_SYNC 0x01 | ||
91 | #define USBVISION_16_422_SYNC 0x02 | ||
92 | #define USBVISION_VSNC_POL (1 << 3) | ||
93 | #define USBVISION_HSNC_POL (1 << 4) | ||
94 | #define USBVISION_FID_POL (1 << 5) | ||
95 | #define USBVISION_HVALID_PO (1 << 6) | ||
96 | #define USBVISION_VCLK_POL (1 << 7) | ||
97 | #define USBVISION_VIN_REG2 0x1C | ||
98 | #define USBVISION_AUTO_FID (1 << 0) | ||
99 | #define USBVISION_NONE_INTER (1 << 1) | ||
100 | #define USBVISION_NOHVALID (1 << 2) | ||
101 | #define USBVISION_UV_ID (1 << 3) | ||
102 | #define USBVISION_FIX_2C (1 << 4) | ||
103 | #define USBVISION_SEND_FID (1 << 5) | ||
104 | #define USBVISION_KEEP_BLANK (1 << 7) | ||
105 | #define USBVISION_LXSIZE_I 0x1D | ||
106 | #define USBVISION_MXSIZE_I 0x1E | ||
107 | #define USBVISION_LYSIZE_I 0x1F | ||
108 | #define USBVISION_MYSIZE_I 0x20 | ||
109 | #define USBVISION_LX_OFFST 0x21 | ||
110 | #define USBVISION_MX_OFFST 0x22 | ||
111 | #define USBVISION_LY_OFFST 0x23 | ||
112 | #define USBVISION_MY_OFFST 0x24 | ||
113 | #define USBVISION_FRM_RATE 0x25 | ||
114 | #define USBVISION_LXSIZE_O 0x26 | ||
115 | #define USBVISION_MXSIZE_O 0x27 | ||
116 | #define USBVISION_LYSIZE_O 0x28 | ||
117 | #define USBVISION_MYSIZE_O 0x29 | ||
118 | #define USBVISION_FILT_CONT 0x2A | ||
119 | #define USBVISION_VO_MODE 0x2B | ||
120 | #define USBVISION_INTRA_CYC 0x2C | ||
121 | #define USBVISION_STRIP_SZ 0x2D | ||
122 | #define USBVISION_FORCE_INTRA 0x2E | ||
123 | #define USBVISION_FORCE_UP 0x2F | ||
124 | #define USBVISION_BUF_THR 0x30 | ||
125 | #define USBVISION_DVI_YUV 0x31 | ||
126 | #define USBVISION_AUDIO_CONT 0x32 | ||
127 | #define USBVISION_AUD_PK_LEN 0x33 | ||
128 | #define USBVISION_BLK_PK_LEN 0x34 | ||
129 | #define USBVISION_PCM_THR1 0x38 | ||
130 | #define USBVISION_PCM_THR2 0x39 | ||
131 | #define USBVISION_DIST_THR_L 0x3A | ||
132 | #define USBVISION_DIST_THR_H 0x3B | ||
133 | #define USBVISION_MAX_DIST_L 0x3C | ||
134 | #define USBVISION_MAX_DIST_H 0x3D | ||
135 | #define USBVISION_OP_CODE 0x33 | ||
136 | |||
137 | #define MAX_BYTES_PER_PIXEL 4 | ||
138 | |||
139 | #define MIN_FRAME_WIDTH 64 | ||
140 | #define MAX_USB_WIDTH 320 /* 384 */ | ||
141 | #define MAX_FRAME_WIDTH 320 /* 384 */ /* streching sometimes causes crashes*/ | ||
142 | |||
143 | #define MIN_FRAME_HEIGHT 48 | ||
144 | #define MAX_USB_HEIGHT 240 /* 288 */ | ||
145 | #define MAX_FRAME_HEIGHT 240 /* 288 */ /* Streching sometimes causes crashes*/ | ||
146 | |||
147 | #define MAX_FRAME_SIZE (MAX_FRAME_WIDTH * MAX_FRAME_HEIGHT * MAX_BYTES_PER_PIXEL) | ||
148 | #define USBVISION_CLIPMASK_SIZE (MAX_FRAME_WIDTH * MAX_FRAME_HEIGHT / 8) /* bytesize of clipmask */ | ||
149 | |||
150 | #define USBVISION_URB_FRAMES 32 | ||
151 | |||
152 | #define USBVISION_NUM_HEADERMARKER 20 | ||
153 | #define USBVISION_NUMFRAMES 3 /* Maximum number of frames an application can get */ | ||
154 | #define USBVISION_NUMSBUF 2 /* Dimensioning the USB S buffering */ | ||
155 | |||
156 | #define USBVISION_POWEROFF_TIME (3 * HZ) /* 3 seconds */ | ||
157 | |||
158 | |||
159 | #define FRAMERATE_MIN 0 | ||
160 | #define FRAMERATE_MAX 31 | ||
161 | |||
162 | enum { | ||
163 | ISOC_MODE_YUV422 = 0x03, | ||
164 | ISOC_MODE_YUV420 = 0x14, | ||
165 | ISOC_MODE_COMPRESS = 0x60, | ||
166 | }; | ||
167 | |||
168 | /* This macro restricts an int variable to an inclusive range */ | ||
169 | #define RESTRICT_TO_RANGE(v, mi, ma) \ | ||
170 | { if ((v) < (mi)) (v) = (mi); else if ((v) > (ma)) (v) = (ma); } | ||
171 | |||
172 | /* | ||
173 | * We use macros to do YUV -> RGB conversion because this is | ||
174 | * very important for speed and totally unimportant for size. | ||
175 | * | ||
176 | * YUV -> RGB Conversion | ||
177 | * --------------------- | ||
178 | * | ||
179 | * B = 1.164*(Y-16) + 2.018*(V-128) | ||
180 | * G = 1.164*(Y-16) - 0.813*(U-128) - 0.391*(V-128) | ||
181 | * R = 1.164*(Y-16) + 1.596*(U-128) | ||
182 | * | ||
183 | * If you fancy integer arithmetics (as you should), hear this: | ||
184 | * | ||
185 | * 65536*B = 76284*(Y-16) + 132252*(V-128) | ||
186 | * 65536*G = 76284*(Y-16) - 53281*(U-128) - 25625*(V-128) | ||
187 | * 65536*R = 76284*(Y-16) + 104595*(U-128) | ||
188 | * | ||
189 | * Make sure the output values are within [0..255] range. | ||
190 | */ | ||
191 | #define LIMIT_RGB(x) (((x) < 0) ? 0 : (((x) > 255) ? 255 : (x))) | ||
192 | #define YUV_TO_RGB_BY_THE_BOOK(my, mu, mv, mr, mg, mb) { \ | ||
193 | int mm_y, mm_yc, mm_u, mm_v, mm_r, mm_g, mm_b; \ | ||
194 | mm_y = (my) - 16; \ | ||
195 | mm_u = (mu) - 128; \ | ||
196 | mm_v = (mv) - 128; \ | ||
197 | mm_yc = mm_y * 76284; \ | ||
198 | mm_b = (mm_yc + 132252 * mm_v) >> 16; \ | ||
199 | mm_g = (mm_yc - 53281 * mm_u - 25625 * mm_v) >> 16; \ | ||
200 | mm_r = (mm_yc + 104595 * mm_u) >> 16; \ | ||
201 | mb = LIMIT_RGB(mm_b); \ | ||
202 | mg = LIMIT_RGB(mm_g); \ | ||
203 | mr = LIMIT_RGB(mm_r); \ | ||
204 | } | ||
205 | |||
206 | /* Debugging aid */ | ||
207 | #define USBVISION_SAY_AND_WAIT(what) { \ | ||
208 | wait_queue_head_t wq; \ | ||
209 | init_waitqueue_head(&wq); \ | ||
210 | printk(KERN_INFO "Say: %s\n", what); \ | ||
211 | interruptible_sleep_on_timeout(&wq, HZ * 3); \ | ||
212 | } | ||
213 | |||
214 | /* | ||
215 | * This macro checks if usbvision is still operational. The 'usbvision' | ||
216 | * pointer must be valid, usbvision->dev must be valid, we are not | ||
217 | * removing the device and the device has not erred on us. | ||
218 | */ | ||
219 | #define USBVISION_IS_OPERATIONAL(udevice) (\ | ||
220 | (udevice != NULL) && \ | ||
221 | ((udevice)->dev != NULL) && \ | ||
222 | ((udevice)->last_error == 0) && \ | ||
223 | (!(udevice)->remove_pending)) | ||
224 | |||
225 | #define I2C_USB_ADAP_MAX 16 | ||
226 | |||
227 | #define USBVISION_NORMS (V4L2_STD_PAL | V4L2_STD_NTSC | V4L2_STD_SECAM | V4L2_STD_PAL_M) | ||
228 | |||
229 | /* ----------------------------------------------------------------- */ | ||
230 | /* usbvision video structures */ | ||
231 | /* ----------------------------------------------------------------- */ | ||
232 | enum scan_state { | ||
233 | scan_state_scanning, /* Scanning for header */ | ||
234 | scan_state_lines /* Parsing lines */ | ||
235 | }; | ||
236 | |||
237 | /* Completion states of the data parser */ | ||
238 | enum parse_state { | ||
239 | parse_state_continue, /* Just parse next item */ | ||
240 | parse_state_next_frame, /* Frame done, send it to V4L */ | ||
241 | parse_state_out, /* Not enough data for frame */ | ||
242 | parse_state_end_parse /* End parsing */ | ||
243 | }; | ||
244 | |||
245 | enum frame_state { | ||
246 | frame_state_unused, /* Unused (no MCAPTURE) */ | ||
247 | frame_state_ready, /* Ready to start grabbing */ | ||
248 | frame_state_grabbing, /* In the process of being grabbed into */ | ||
249 | frame_state_done, /* Finished grabbing, but not been synced yet */ | ||
250 | frame_state_done_hold, /* Are syncing or reading */ | ||
251 | frame_state_error, /* Something bad happened while processing */ | ||
252 | }; | ||
253 | |||
254 | /* stream states */ | ||
255 | enum stream_state { | ||
256 | stream_off, /* Driver streaming is completely OFF */ | ||
257 | stream_idle, /* Driver streaming is ready to be put ON by the application */ | ||
258 | stream_interrupt, /* Driver streaming must be interrupted */ | ||
259 | stream_on, /* Driver streaming is put ON by the application */ | ||
260 | }; | ||
261 | |||
262 | enum isoc_state { | ||
263 | isoc_state_in_frame, /* Isoc packet is member of frame */ | ||
264 | isoc_state_no_frame, /* Isoc packet is not member of any frame */ | ||
265 | }; | ||
266 | |||
267 | struct usb_device; | ||
268 | |||
269 | struct usbvision_sbuf { | ||
270 | char *data; | ||
271 | struct urb *urb; | ||
272 | }; | ||
273 | |||
274 | #define USBVISION_MAGIC_1 0x55 | ||
275 | #define USBVISION_MAGIC_2 0xAA | ||
276 | #define USBVISION_HEADER_LENGTH 0x0c | ||
277 | #define USBVISION_SAA7111_ADDR 0x48 | ||
278 | #define USBVISION_SAA7113_ADDR 0x4a | ||
279 | #define USBVISION_IIC_LRACK 0x20 | ||
280 | #define USBVISION_IIC_LRNACK 0x30 | ||
281 | #define USBVISION_FRAME_FORMAT_PARAM_INTRA (1<<7) | ||
282 | |||
283 | struct usbvision_v4l2_format_st { | ||
284 | int supported; | ||
285 | int bytes_per_pixel; | ||
286 | int depth; | ||
287 | int format; | ||
288 | char *desc; | ||
289 | }; | ||
290 | #define USBVISION_SUPPORTED_PALETTES ARRAY_SIZE(usbvision_v4l2_format) | ||
291 | |||
292 | struct usbvision_frame_header { | ||
293 | unsigned char magic_1; /* 0 magic */ | ||
294 | unsigned char magic_2; /* 1 magic */ | ||
295 | unsigned char header_length; /* 2 */ | ||
296 | unsigned char frame_num; /* 3 */ | ||
297 | unsigned char frame_phase; /* 4 */ | ||
298 | unsigned char frame_latency; /* 5 */ | ||
299 | unsigned char data_format; /* 6 */ | ||
300 | unsigned char format_param; /* 7 */ | ||
301 | unsigned char frame_width_lo; /* 8 */ | ||
302 | unsigned char frame_width_hi; /* 9 */ | ||
303 | unsigned char frame_height_lo; /* 10 */ | ||
304 | unsigned char frame_height_hi; /* 11 */ | ||
305 | __u16 frame_width; /* 8 - 9 after endian correction*/ | ||
306 | __u16 frame_height; /* 10 - 11 after endian correction*/ | ||
307 | }; | ||
308 | |||
309 | struct usbvision_frame { | ||
310 | char *data; /* Frame buffer */ | ||
311 | struct usbvision_frame_header isoc_header; /* Header from stream */ | ||
312 | |||
313 | int width; /* Width application is expecting */ | ||
314 | int height; /* Height */ | ||
315 | int index; /* Frame index */ | ||
316 | int frmwidth; /* Width the frame actually is */ | ||
317 | int frmheight; /* Height */ | ||
318 | |||
319 | volatile int grabstate; /* State of grabbing */ | ||
320 | int scanstate; /* State of scanning */ | ||
321 | |||
322 | struct list_head frame; | ||
323 | |||
324 | int curline; /* Line of frame we're working on */ | ||
325 | |||
326 | long scanlength; /* uncompressed, raw data length of frame */ | ||
327 | long bytes_read; /* amount of scanlength that has been read from data */ | ||
328 | struct usbvision_v4l2_format_st v4l2_format; /* format the user needs*/ | ||
329 | int v4l2_linesize; /* bytes for one videoline*/ | ||
330 | struct timeval timestamp; | ||
331 | int sequence; /* How many video frames we send to user */ | ||
332 | }; | ||
333 | |||
334 | #define CODEC_SAA7113 7113 | ||
335 | #define CODEC_SAA7111 7111 | ||
336 | #define CODEC_WEBCAM 3000 | ||
337 | #define BRIDGE_NT1003 1003 | ||
338 | #define BRIDGE_NT1004 1004 | ||
339 | #define BRIDGE_NT1005 1005 | ||
340 | |||
341 | struct usbvision_device_data_st { | ||
342 | __u64 video_norm; | ||
343 | const char *model_string; | ||
344 | int interface; /* to handle special interface number like BELKIN and Hauppauge WinTV-USB II */ | ||
345 | __u16 codec; | ||
346 | unsigned video_channels:3; | ||
347 | unsigned audio_channels:2; | ||
348 | unsigned radio:1; | ||
349 | unsigned vbi:1; | ||
350 | unsigned tuner:1; | ||
351 | unsigned vin_reg1_override:1; /* Override default value with */ | ||
352 | unsigned vin_reg2_override:1; /* vin_reg1, vin_reg2, etc. */ | ||
353 | unsigned dvi_yuv_override:1; | ||
354 | __u8 vin_reg1; | ||
355 | __u8 vin_reg2; | ||
356 | __u8 dvi_yuv; | ||
357 | __u8 tuner_type; | ||
358 | __s16 x_offset; | ||
359 | __s16 y_offset; | ||
360 | }; | ||
361 | |||
362 | /* Declared on usbvision-cards.c */ | ||
363 | extern struct usbvision_device_data_st usbvision_device_data[]; | ||
364 | extern struct usb_device_id usbvision_table[]; | ||
365 | |||
366 | struct usb_usbvision { | ||
367 | struct v4l2_device v4l2_dev; | ||
368 | struct video_device *vdev; /* Video Device */ | ||
369 | struct video_device *rdev; /* Radio Device */ | ||
370 | |||
371 | /* i2c Declaration Section*/ | ||
372 | struct i2c_adapter i2c_adap; | ||
373 | int registered_i2c; | ||
374 | |||
375 | struct urb *ctrl_urb; | ||
376 | unsigned char ctrl_urb_buffer[8]; | ||
377 | int ctrl_urb_busy; | ||
378 | struct usb_ctrlrequest ctrl_urb_setup; | ||
379 | wait_queue_head_t ctrl_urb_wq; /* Processes waiting */ | ||
380 | |||
381 | /* configuration part */ | ||
382 | int have_tuner; | ||
383 | int tuner_type; | ||
384 | int bridge_type; /* NT1003, NT1004, NT1005 */ | ||
385 | int radio; | ||
386 | int video_inputs; /* # of inputs */ | ||
387 | unsigned long freq; | ||
388 | int audio_mute; | ||
389 | int audio_channel; | ||
390 | int isoc_mode; /* format of video data for the usb isoc-transfer */ | ||
391 | unsigned int nr; /* Number of the device */ | ||
392 | |||
393 | /* Device structure */ | ||
394 | struct usb_device *dev; | ||
395 | /* usb transfer */ | ||
396 | int num_alt; /* Number of alternative settings */ | ||
397 | unsigned int *alt_max_pkt_size; /* array of max_packet_size */ | ||
398 | unsigned char iface; /* Video interface number */ | ||
399 | unsigned char iface_alt; /* Alt settings */ | ||
400 | unsigned char vin_reg2_preset; | ||
401 | struct mutex v4l2_lock; | ||
402 | struct timer_list power_off_timer; | ||
403 | struct work_struct power_off_work; | ||
404 | int power; /* is the device powered on? */ | ||
405 | int user; /* user count for exclusive use */ | ||
406 | int initialized; /* Had we already sent init sequence? */ | ||
407 | int dev_model; /* What type of USBVISION device we got? */ | ||
408 | enum stream_state streaming; /* Are we streaming Isochronous? */ | ||
409 | int last_error; /* What calamity struck us? */ | ||
410 | int curwidth; /* width of the frame the device is currently set to*/ | ||
411 | int curheight; /* height of the frame the device is currently set to*/ | ||
412 | int stretch_width; /* stretch-factor for frame width (from usb to screen)*/ | ||
413 | int stretch_height; /* stretch-factor for frame height (from usb to screen)*/ | ||
414 | char *fbuf; /* Videodev buffer area for mmap*/ | ||
415 | int max_frame_size; /* Bytes in one video frame */ | ||
416 | int fbuf_size; /* Videodev buffer size */ | ||
417 | spinlock_t queue_lock; /* spinlock for protecting mods on inqueue and outqueue */ | ||
418 | struct list_head inqueue, outqueue; /* queued frame list and ready to dequeue frame list */ | ||
419 | wait_queue_head_t wait_frame; /* Processes waiting */ | ||
420 | wait_queue_head_t wait_stream; /* Processes waiting */ | ||
421 | struct usbvision_frame *cur_frame; /* pointer to current frame, set by usbvision_find_header */ | ||
422 | struct usbvision_frame frame[USBVISION_NUMFRAMES]; /* frame buffer */ | ||
423 | int num_frames; /* number of frames allocated */ | ||
424 | struct usbvision_sbuf sbuf[USBVISION_NUMSBUF]; /* S buffering */ | ||
425 | volatile int remove_pending; /* If set then about to exit */ | ||
426 | |||
427 | /* Scratch space from the Isochronous Pipe.*/ | ||
428 | unsigned char *scratch; | ||
429 | int scratch_read_ptr; | ||
430 | int scratch_write_ptr; | ||
431 | int scratch_headermarker[USBVISION_NUM_HEADERMARKER]; | ||
432 | int scratch_headermarker_read_ptr; | ||
433 | int scratch_headermarker_write_ptr; | ||
434 | enum isoc_state isocstate; | ||
435 | struct usbvision_v4l2_format_st palette; | ||
436 | |||
437 | struct v4l2_capability vcap; /* Video capabilities */ | ||
438 | unsigned int ctl_input; /* selected input */ | ||
439 | v4l2_std_id tvnorm_id; /* selected tv norm */ | ||
440 | unsigned char video_endp; /* 0x82 for USBVISION devices based */ | ||
441 | |||
442 | /* Decompression stuff: */ | ||
443 | unsigned char *intra_frame_buffer; /* Buffer for reference frame */ | ||
444 | int block_pos; /* for test only */ | ||
445 | int request_intra; /* 0 = normal; 1 = intra frame is requested; */ | ||
446 | int last_isoc_frame_num; /* check for lost isoc frames */ | ||
447 | int isoc_packet_size; /* need to calculate used_bandwidth */ | ||
448 | int used_bandwidth; /* used bandwidth 0-100%, need to set compr_level */ | ||
449 | int compr_level; /* How strong (100) or weak (0) is compression */ | ||
450 | int last_compr_level; /* How strong (100) or weak (0) was compression */ | ||
451 | int usb_bandwidth; /* Mbit/s */ | ||
452 | |||
453 | /* Statistics that can be overlayed on the screen */ | ||
454 | unsigned long isoc_urb_count; /* How many URBs we received so far */ | ||
455 | unsigned long urb_length; /* Length of last URB */ | ||
456 | unsigned long isoc_data_count; /* How many bytes we received */ | ||
457 | unsigned long header_count; /* How many frame headers we found */ | ||
458 | unsigned long scratch_ovf_count; /* How many times we overflowed scratch */ | ||
459 | unsigned long isoc_skip_count; /* How many empty ISO packets received */ | ||
460 | unsigned long isoc_err_count; /* How many bad ISO packets received */ | ||
461 | unsigned long isoc_packet_count; /* How many packets we totally got */ | ||
462 | unsigned long time_in_irq; /* How long do we need for interrupt */ | ||
463 | int isoc_measure_bandwidth_count; | ||
464 | int frame_num; /* How many video frames we send to user */ | ||
465 | int max_strip_len; /* How big is the biggest strip */ | ||
466 | int comprblock_pos; | ||
467 | int strip_len_errors; /* How many times was block_pos greater than strip_len */ | ||
468 | int strip_magic_errors; | ||
469 | int strip_line_number_errors; | ||
470 | int compr_block_types[4]; | ||
471 | }; | ||
472 | |||
473 | static inline struct usb_usbvision *to_usbvision(struct v4l2_device *v4l2_dev) | ||
474 | { | ||
475 | return container_of(v4l2_dev, struct usb_usbvision, v4l2_dev); | ||
476 | } | ||
477 | |||
478 | #define call_all(usbvision, o, f, args...) \ | ||
479 | v4l2_device_call_all(&usbvision->v4l2_dev, 0, o, f, ##args) | ||
480 | |||
481 | /* --------------------------------------------------------------- */ | ||
482 | /* defined in usbvision-i2c.c */ | ||
483 | /* i2c-algo-usb declaration */ | ||
484 | /* --------------------------------------------------------------- */ | ||
485 | |||
486 | /* ----------------------------------------------------------------------- */ | ||
487 | /* usbvision specific I2C functions */ | ||
488 | /* ----------------------------------------------------------------------- */ | ||
489 | int usbvision_i2c_register(struct usb_usbvision *usbvision); | ||
490 | int usbvision_i2c_unregister(struct usb_usbvision *usbvision); | ||
491 | |||
492 | /* defined in usbvision-core.c */ | ||
493 | int usbvision_read_reg(struct usb_usbvision *usbvision, unsigned char reg); | ||
494 | int usbvision_write_reg(struct usb_usbvision *usbvision, unsigned char reg, | ||
495 | unsigned char value); | ||
496 | |||
497 | int usbvision_frames_alloc(struct usb_usbvision *usbvision, int number_of_frames); | ||
498 | void usbvision_frames_free(struct usb_usbvision *usbvision); | ||
499 | int usbvision_scratch_alloc(struct usb_usbvision *usbvision); | ||
500 | void usbvision_scratch_free(struct usb_usbvision *usbvision); | ||
501 | int usbvision_decompress_alloc(struct usb_usbvision *usbvision); | ||
502 | void usbvision_decompress_free(struct usb_usbvision *usbvision); | ||
503 | |||
504 | int usbvision_setup(struct usb_usbvision *usbvision, int format); | ||
505 | int usbvision_init_isoc(struct usb_usbvision *usbvision); | ||
506 | int usbvision_restart_isoc(struct usb_usbvision *usbvision); | ||
507 | void usbvision_stop_isoc(struct usb_usbvision *usbvision); | ||
508 | int usbvision_set_alternate(struct usb_usbvision *dev); | ||
509 | |||
510 | int usbvision_set_audio(struct usb_usbvision *usbvision, int audio_channel); | ||
511 | int usbvision_audio_off(struct usb_usbvision *usbvision); | ||
512 | |||
513 | int usbvision_begin_streaming(struct usb_usbvision *usbvision); | ||
514 | void usbvision_empty_framequeues(struct usb_usbvision *dev); | ||
515 | int usbvision_stream_interrupt(struct usb_usbvision *dev); | ||
516 | |||
517 | int usbvision_muxsel(struct usb_usbvision *usbvision, int channel); | ||
518 | int usbvision_set_input(struct usb_usbvision *usbvision); | ||
519 | int usbvision_set_output(struct usb_usbvision *usbvision, int width, int height); | ||
520 | |||
521 | void usbvision_init_power_off_timer(struct usb_usbvision *usbvision); | ||
522 | void usbvision_set_power_off_timer(struct usb_usbvision *usbvision); | ||
523 | void usbvision_reset_power_off_timer(struct usb_usbvision *usbvision); | ||
524 | int usbvision_power_off(struct usb_usbvision *usbvision); | ||
525 | int usbvision_power_on(struct usb_usbvision *usbvision); | ||
526 | |||
527 | #endif /* __LINUX_USBVISION_H */ | ||
528 | |||
529 | /* | ||
530 | * Overrides for Emacs so that we follow Linus's tabbing style. | ||
531 | * --------------------------------------------------------------------------- | ||
532 | * Local variables: | ||
533 | * c-basic-offset: 8 | ||
534 | * End: | ||
535 | */ | ||