Merge branch 'nfsd-next' of git://linux-nfs.org/~bfields/linux
[deliverable/linux.git] / drivers / staging / media / go7007 / go7007-usb.c
1 /*
2 * Copyright (C) 2005-2006 Micronas USA Inc.
3 *
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License (Version 2) as
6 * published by the Free Software Foundation.
7 *
8 * This program is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 * GNU General Public License for more details.
12 *
13 * You should have received a copy of the GNU General Public License
14 * along with this program; if not, write to the Free Software Foundation,
15 * Inc., 59 Temple Place - Suite 330, Boston MA 02111-1307, USA.
16 */
17
18 #include <linux/module.h>
19 #include <linux/kernel.h>
20 #include <linux/init.h>
21 #include <linux/wait.h>
22 #include <linux/list.h>
23 #include <linux/slab.h>
24 #include <linux/time.h>
25 #include <linux/mm.h>
26 #include <linux/usb.h>
27 #include <linux/i2c.h>
28 #include <asm/byteorder.h>
29 #include <media/saa7115.h>
30 #include <media/tuner.h>
31 #include <media/uda1342.h>
32
33 #include "go7007-priv.h"
34
35 static unsigned int assume_endura;
36 module_param(assume_endura, int, 0644);
37 MODULE_PARM_DESC(assume_endura,
38 "when probing fails, hardware is a Pelco Endura");
39
40 /* #define GO7007_I2C_DEBUG */ /* for debugging the EZ-USB I2C adapter */
41
42 #define HPI_STATUS_ADDR 0xFFF4
43 #define INT_PARAM_ADDR 0xFFF6
44 #define INT_INDEX_ADDR 0xFFF8
45
46 /*
47 * Pipes on EZ-USB interface:
48 * 0 snd - Control
49 * 0 rcv - Control
50 * 2 snd - Download firmware (control)
51 * 4 rcv - Read Interrupt (interrupt)
52 * 6 rcv - Read Video (bulk)
53 * 8 rcv - Read Audio (bulk)
54 */
55
56 #define GO7007_USB_EZUSB (1<<0)
57 #define GO7007_USB_EZUSB_I2C (1<<1)
58
59 struct go7007_usb_board {
60 unsigned int flags;
61 struct go7007_board_info main_info;
62 };
63
64 struct go7007_usb {
65 const struct go7007_usb_board *board;
66 struct mutex i2c_lock;
67 struct usb_device *usbdev;
68 struct urb *video_urbs[8];
69 struct urb *audio_urbs[8];
70 struct urb *intr_urb;
71 };
72
73 /*********************** Product specification data ***********************/
74
75 static const struct go7007_usb_board board_matrix_ii = {
76 .flags = GO7007_USB_EZUSB,
77 .main_info = {
78 .flags = GO7007_BOARD_HAS_AUDIO |
79 GO7007_BOARD_USE_ONBOARD_I2C,
80 .audio_flags = GO7007_AUDIO_I2S_MODE_1 |
81 GO7007_AUDIO_WORD_16,
82 .audio_rate = 48000,
83 .audio_bclk_div = 8,
84 .audio_main_div = 2,
85 .hpi_buffer_cap = 7,
86 .sensor_flags = GO7007_SENSOR_656 |
87 GO7007_SENSOR_VALID_ENABLE |
88 GO7007_SENSOR_TV |
89 GO7007_SENSOR_SAA7115 |
90 GO7007_SENSOR_VBI |
91 GO7007_SENSOR_SCALING,
92 .num_i2c_devs = 1,
93 .i2c_devs = {
94 {
95 .type = "saa7115",
96 .addr = 0x20,
97 .is_video = 1,
98 },
99 },
100 .num_inputs = 2,
101 .inputs = {
102 {
103 .video_input = 0,
104 .name = "Composite",
105 },
106 {
107 .video_input = 9,
108 .name = "S-Video",
109 },
110 },
111 .video_config = SAA7115_IDQ_IS_DEFAULT,
112 },
113 };
114
115 static const struct go7007_usb_board board_matrix_reload = {
116 .flags = GO7007_USB_EZUSB,
117 .main_info = {
118 .flags = GO7007_BOARD_HAS_AUDIO |
119 GO7007_BOARD_USE_ONBOARD_I2C,
120 .audio_flags = GO7007_AUDIO_I2S_MODE_1 |
121 GO7007_AUDIO_I2S_MASTER |
122 GO7007_AUDIO_WORD_16,
123 .audio_rate = 48000,
124 .audio_bclk_div = 8,
125 .audio_main_div = 2,
126 .hpi_buffer_cap = 7,
127 .sensor_flags = GO7007_SENSOR_656 |
128 GO7007_SENSOR_TV,
129 .num_i2c_devs = 1,
130 .i2c_devs = {
131 {
132 .type = "saa7113",
133 .addr = 0x25,
134 .is_video = 1,
135 },
136 },
137 .num_inputs = 2,
138 .inputs = {
139 {
140 .video_input = 0,
141 .name = "Composite",
142 },
143 {
144 .video_input = 9,
145 .name = "S-Video",
146 },
147 },
148 .video_config = SAA7115_IDQ_IS_DEFAULT,
149 },
150 };
151
152 static const struct go7007_usb_board board_star_trek = {
153 .flags = GO7007_USB_EZUSB | GO7007_USB_EZUSB_I2C,
154 .main_info = {
155 .flags = GO7007_BOARD_HAS_AUDIO, /* |
156 GO7007_BOARD_HAS_TUNER, */
157 .sensor_flags = GO7007_SENSOR_656 |
158 GO7007_SENSOR_VALID_ENABLE |
159 GO7007_SENSOR_TV |
160 GO7007_SENSOR_SAA7115 |
161 GO7007_SENSOR_VBI |
162 GO7007_SENSOR_SCALING,
163 .audio_flags = GO7007_AUDIO_I2S_MODE_1 |
164 GO7007_AUDIO_WORD_16,
165 .audio_bclk_div = 8,
166 .audio_main_div = 2,
167 .hpi_buffer_cap = 7,
168 .num_i2c_devs = 1,
169 .i2c_devs = {
170 {
171 .type = "saa7115",
172 .addr = 0x20,
173 .is_video = 1,
174 },
175 },
176 .num_inputs = 2,
177 .inputs = {
178 /* {
179 * .video_input = 3,
180 * .audio_index = AUDIO_TUNER,
181 * .name = "Tuner",
182 * },
183 */
184 {
185 .video_input = 1,
186 /* .audio_index = AUDIO_EXTERN, */
187 .name = "Composite",
188 },
189 {
190 .video_input = 8,
191 /* .audio_index = AUDIO_EXTERN, */
192 .name = "S-Video",
193 },
194 },
195 .video_config = SAA7115_IDQ_IS_DEFAULT,
196 },
197 };
198
199 static const struct go7007_usb_board board_px_tv402u = {
200 .flags = GO7007_USB_EZUSB | GO7007_USB_EZUSB_I2C,
201 .main_info = {
202 .flags = GO7007_BOARD_HAS_AUDIO |
203 GO7007_BOARD_HAS_TUNER,
204 .sensor_flags = GO7007_SENSOR_656 |
205 GO7007_SENSOR_VALID_ENABLE |
206 GO7007_SENSOR_TV |
207 GO7007_SENSOR_SAA7115 |
208 GO7007_SENSOR_VBI |
209 GO7007_SENSOR_SCALING,
210 .audio_flags = GO7007_AUDIO_I2S_MODE_1 |
211 GO7007_AUDIO_WORD_16,
212 .audio_bclk_div = 8,
213 .audio_main_div = 2,
214 .hpi_buffer_cap = 7,
215 .num_i2c_devs = 5,
216 .i2c_devs = {
217 {
218 .type = "saa7115",
219 .addr = 0x20,
220 .is_video = 1,
221 },
222 {
223 .type = "uda1342",
224 .addr = 0x1a,
225 .is_audio = 1,
226 },
227 {
228 .type = "tuner",
229 .addr = 0x60,
230 },
231 {
232 .type = "tuner",
233 .addr = 0x43,
234 },
235 {
236 .type = "sony-btf-mpx",
237 .addr = 0x44,
238 },
239 },
240 .num_inputs = 3,
241 .inputs = {
242 {
243 .video_input = 3,
244 .audio_index = 0,
245 .name = "Tuner",
246 },
247 {
248 .video_input = 1,
249 .audio_index = 1,
250 .name = "Composite",
251 },
252 {
253 .video_input = 8,
254 .audio_index = 1,
255 .name = "S-Video",
256 },
257 },
258 .video_config = SAA7115_IDQ_IS_DEFAULT,
259 .num_aud_inputs = 2,
260 .aud_inputs = {
261 {
262 .audio_input = UDA1342_IN2,
263 .name = "Tuner",
264 },
265 {
266 .audio_input = UDA1342_IN1,
267 .name = "Line In",
268 },
269 },
270 },
271 };
272
273 static const struct go7007_usb_board board_xmen = {
274 .flags = 0,
275 .main_info = {
276 .flags = GO7007_BOARD_USE_ONBOARD_I2C,
277 .hpi_buffer_cap = 0,
278 .sensor_flags = GO7007_SENSOR_VREF_POLAR,
279 .sensor_width = 320,
280 .sensor_height = 240,
281 .sensor_framerate = 30030,
282 .audio_flags = GO7007_AUDIO_ONE_CHANNEL |
283 GO7007_AUDIO_I2S_MODE_3 |
284 GO7007_AUDIO_WORD_14 |
285 GO7007_AUDIO_I2S_MASTER |
286 GO7007_AUDIO_BCLK_POLAR |
287 GO7007_AUDIO_OKI_MODE,
288 .audio_rate = 8000,
289 .audio_bclk_div = 48,
290 .audio_main_div = 1,
291 .num_i2c_devs = 1,
292 .i2c_devs = {
293 {
294 .type = "ov7640",
295 .addr = 0x21,
296 },
297 },
298 .num_inputs = 1,
299 .inputs = {
300 {
301 .name = "Camera",
302 },
303 },
304 },
305 };
306
307 static const struct go7007_usb_board board_matrix_revolution = {
308 .flags = GO7007_USB_EZUSB,
309 .main_info = {
310 .flags = GO7007_BOARD_HAS_AUDIO |
311 GO7007_BOARD_USE_ONBOARD_I2C,
312 .audio_flags = GO7007_AUDIO_I2S_MODE_1 |
313 GO7007_AUDIO_I2S_MASTER |
314 GO7007_AUDIO_WORD_16,
315 .audio_rate = 48000,
316 .audio_bclk_div = 8,
317 .audio_main_div = 2,
318 .hpi_buffer_cap = 7,
319 .sensor_flags = GO7007_SENSOR_656 |
320 GO7007_SENSOR_TV |
321 GO7007_SENSOR_VBI,
322 .num_i2c_devs = 1,
323 .i2c_devs = {
324 {
325 .type = "tw9903",
326 .is_video = 1,
327 .addr = 0x44,
328 },
329 },
330 .num_inputs = 2,
331 .inputs = {
332 {
333 .video_input = 2,
334 .name = "Composite",
335 },
336 {
337 .video_input = 8,
338 .name = "S-Video",
339 },
340 },
341 },
342 };
343
344 static const struct go7007_usb_board board_lifeview_lr192 = {
345 .flags = GO7007_USB_EZUSB,
346 .main_info = {
347 .flags = GO7007_BOARD_HAS_AUDIO |
348 GO7007_BOARD_USE_ONBOARD_I2C,
349 .audio_flags = GO7007_AUDIO_I2S_MODE_1 |
350 GO7007_AUDIO_WORD_16,
351 .audio_rate = 48000,
352 .audio_bclk_div = 8,
353 .audio_main_div = 2,
354 .hpi_buffer_cap = 7,
355 .sensor_flags = GO7007_SENSOR_656 |
356 GO7007_SENSOR_VALID_ENABLE |
357 GO7007_SENSOR_TV |
358 GO7007_SENSOR_VBI |
359 GO7007_SENSOR_SCALING,
360 .num_i2c_devs = 0,
361 .num_inputs = 1,
362 .inputs = {
363 {
364 .video_input = 0,
365 .name = "Composite",
366 },
367 },
368 },
369 };
370
371 static const struct go7007_usb_board board_endura = {
372 .flags = 0,
373 .main_info = {
374 .flags = 0,
375 .audio_flags = GO7007_AUDIO_I2S_MODE_1 |
376 GO7007_AUDIO_I2S_MASTER |
377 GO7007_AUDIO_WORD_16,
378 .audio_rate = 8000,
379 .audio_bclk_div = 48,
380 .audio_main_div = 8,
381 .hpi_buffer_cap = 0,
382 .sensor_flags = GO7007_SENSOR_656 |
383 GO7007_SENSOR_TV,
384 .sensor_h_offset = 8,
385 .num_i2c_devs = 0,
386 .num_inputs = 1,
387 .inputs = {
388 {
389 .name = "Camera",
390 },
391 },
392 },
393 };
394
395 static const struct go7007_usb_board board_adlink_mpg24 = {
396 .flags = 0,
397 .main_info = {
398 .flags = GO7007_BOARD_USE_ONBOARD_I2C,
399 .audio_flags = GO7007_AUDIO_I2S_MODE_1 |
400 GO7007_AUDIO_I2S_MASTER |
401 GO7007_AUDIO_WORD_16,
402 .audio_rate = 48000,
403 .audio_bclk_div = 8,
404 .audio_main_div = 2,
405 .hpi_buffer_cap = 0,
406 .sensor_flags = GO7007_SENSOR_656 |
407 GO7007_SENSOR_TV |
408 GO7007_SENSOR_VBI,
409 .num_i2c_devs = 1,
410 .i2c_devs = {
411 {
412 .type = "tw2804",
413 .addr = 0x00, /* yes, really */
414 .flags = I2C_CLIENT_TEN,
415 .is_video = 1,
416 },
417 },
418 .num_inputs = 1,
419 .inputs = {
420 {
421 .name = "Composite",
422 },
423 },
424 },
425 };
426
427 static const struct go7007_usb_board board_sensoray_2250 = {
428 .flags = GO7007_USB_EZUSB | GO7007_USB_EZUSB_I2C,
429 .main_info = {
430 .audio_flags = GO7007_AUDIO_I2S_MODE_1 |
431 GO7007_AUDIO_I2S_MASTER |
432 GO7007_AUDIO_WORD_16,
433 .flags = GO7007_BOARD_HAS_AUDIO,
434 .audio_rate = 48000,
435 .audio_bclk_div = 8,
436 .audio_main_div = 2,
437 .hpi_buffer_cap = 7,
438 .sensor_flags = GO7007_SENSOR_656 |
439 GO7007_SENSOR_TV,
440 .num_i2c_devs = 1,
441 .i2c_devs = {
442 {
443 .type = "s2250",
444 .addr = 0x43,
445 .is_video = 1,
446 .is_audio = 1,
447 },
448 },
449 .num_inputs = 2,
450 .inputs = {
451 {
452 .video_input = 0,
453 .name = "Composite",
454 },
455 {
456 .video_input = 1,
457 .name = "S-Video",
458 },
459 },
460 .num_aud_inputs = 3,
461 .aud_inputs = {
462 {
463 .audio_input = 0,
464 .name = "Line In",
465 },
466 {
467 .audio_input = 1,
468 .name = "Mic",
469 },
470 {
471 .audio_input = 2,
472 .name = "Mic Boost",
473 },
474 },
475 },
476 };
477
478 static const struct go7007_usb_board board_ads_usbav_709 = {
479 .flags = GO7007_USB_EZUSB,
480 .main_info = {
481 .flags = GO7007_BOARD_HAS_AUDIO |
482 GO7007_BOARD_USE_ONBOARD_I2C,
483 .audio_flags = GO7007_AUDIO_I2S_MODE_1 |
484 GO7007_AUDIO_I2S_MASTER |
485 GO7007_AUDIO_WORD_16,
486 .audio_rate = 48000,
487 .audio_bclk_div = 8,
488 .audio_main_div = 2,
489 .hpi_buffer_cap = 7,
490 .sensor_flags = GO7007_SENSOR_656 |
491 GO7007_SENSOR_TV |
492 GO7007_SENSOR_VBI,
493 .num_i2c_devs = 1,
494 .i2c_devs = {
495 {
496 .type = "tw9906",
497 .is_video = 1,
498 .addr = 0x44,
499 },
500 },
501 .num_inputs = 2,
502 .inputs = {
503 {
504 .video_input = 0,
505 .name = "Composite",
506 },
507 {
508 .video_input = 10,
509 .name = "S-Video",
510 },
511 },
512 },
513 };
514
515 static const struct usb_device_id go7007_usb_id_table[] = {
516 {
517 .match_flags = USB_DEVICE_ID_MATCH_DEVICE_AND_VERSION |
518 USB_DEVICE_ID_MATCH_INT_INFO,
519 .idVendor = 0x0eb1, /* Vendor ID of WIS Technologies */
520 .idProduct = 0x7007, /* Product ID of GO7007SB chip */
521 .bcdDevice_lo = 0x200, /* Revision number of XMen */
522 .bcdDevice_hi = 0x200,
523 .bInterfaceClass = 255,
524 .bInterfaceSubClass = 0,
525 .bInterfaceProtocol = 255,
526 .driver_info = (kernel_ulong_t)GO7007_BOARDID_XMEN,
527 },
528 {
529 .match_flags = USB_DEVICE_ID_MATCH_DEVICE_AND_VERSION,
530 .idVendor = 0x0eb1, /* Vendor ID of WIS Technologies */
531 .idProduct = 0x7007, /* Product ID of GO7007SB chip */
532 .bcdDevice_lo = 0x202, /* Revision number of Matrix II */
533 .bcdDevice_hi = 0x202,
534 .driver_info = (kernel_ulong_t)GO7007_BOARDID_MATRIX_II,
535 },
536 {
537 .match_flags = USB_DEVICE_ID_MATCH_DEVICE_AND_VERSION,
538 .idVendor = 0x0eb1, /* Vendor ID of WIS Technologies */
539 .idProduct = 0x7007, /* Product ID of GO7007SB chip */
540 .bcdDevice_lo = 0x204, /* Revision number of Matrix */
541 .bcdDevice_hi = 0x204, /* Reloaded */
542 .driver_info = (kernel_ulong_t)GO7007_BOARDID_MATRIX_RELOAD,
543 },
544 {
545 .match_flags = USB_DEVICE_ID_MATCH_DEVICE_AND_VERSION |
546 USB_DEVICE_ID_MATCH_INT_INFO,
547 .idVendor = 0x0eb1, /* Vendor ID of WIS Technologies */
548 .idProduct = 0x7007, /* Product ID of GO7007SB chip */
549 .bcdDevice_lo = 0x205, /* Revision number of XMen-II */
550 .bcdDevice_hi = 0x205,
551 .bInterfaceClass = 255,
552 .bInterfaceSubClass = 0,
553 .bInterfaceProtocol = 255,
554 .driver_info = (kernel_ulong_t)GO7007_BOARDID_XMEN_II,
555 },
556 {
557 .match_flags = USB_DEVICE_ID_MATCH_DEVICE_AND_VERSION,
558 .idVendor = 0x0eb1, /* Vendor ID of WIS Technologies */
559 .idProduct = 0x7007, /* Product ID of GO7007SB chip */
560 .bcdDevice_lo = 0x208, /* Revision number of Star Trek */
561 .bcdDevice_hi = 0x208,
562 .driver_info = (kernel_ulong_t)GO7007_BOARDID_STAR_TREK,
563 },
564 {
565 .match_flags = USB_DEVICE_ID_MATCH_DEVICE_AND_VERSION |
566 USB_DEVICE_ID_MATCH_INT_INFO,
567 .idVendor = 0x0eb1, /* Vendor ID of WIS Technologies */
568 .idProduct = 0x7007, /* Product ID of GO7007SB chip */
569 .bcdDevice_lo = 0x209, /* Revision number of XMen-III */
570 .bcdDevice_hi = 0x209,
571 .bInterfaceClass = 255,
572 .bInterfaceSubClass = 0,
573 .bInterfaceProtocol = 255,
574 .driver_info = (kernel_ulong_t)GO7007_BOARDID_XMEN_III,
575 },
576 {
577 .match_flags = USB_DEVICE_ID_MATCH_DEVICE_AND_VERSION,
578 .idVendor = 0x0eb1, /* Vendor ID of WIS Technologies */
579 .idProduct = 0x7007, /* Product ID of GO7007SB chip */
580 .bcdDevice_lo = 0x210, /* Revision number of Matrix */
581 .bcdDevice_hi = 0x210, /* Revolution */
582 .driver_info = (kernel_ulong_t)GO7007_BOARDID_MATRIX_REV,
583 },
584 {
585 .match_flags = USB_DEVICE_ID_MATCH_DEVICE_AND_VERSION,
586 .idVendor = 0x093b, /* Vendor ID of Plextor */
587 .idProduct = 0xa102, /* Product ID of M402U */
588 .bcdDevice_lo = 0x1, /* revision number of Blueberry */
589 .bcdDevice_hi = 0x1,
590 .driver_info = (kernel_ulong_t)GO7007_BOARDID_PX_M402U,
591 },
592 {
593 .match_flags = USB_DEVICE_ID_MATCH_DEVICE_AND_VERSION,
594 .idVendor = 0x093b, /* Vendor ID of Plextor */
595 .idProduct = 0xa104, /* Product ID of TV402U */
596 .bcdDevice_lo = 0x1,
597 .bcdDevice_hi = 0x1,
598 .driver_info = (kernel_ulong_t)GO7007_BOARDID_PX_TV402U,
599 },
600 {
601 .match_flags = USB_DEVICE_ID_MATCH_DEVICE_AND_VERSION,
602 .idVendor = 0x10fd, /* Vendor ID of Anubis Electronics */
603 .idProduct = 0xde00, /* Product ID of Lifeview LR192 */
604 .bcdDevice_lo = 0x1,
605 .bcdDevice_hi = 0x1,
606 .driver_info = (kernel_ulong_t)GO7007_BOARDID_LIFEVIEW_LR192,
607 },
608 {
609 .match_flags = USB_DEVICE_ID_MATCH_DEVICE_AND_VERSION,
610 .idVendor = 0x1943, /* Vendor ID Sensoray */
611 .idProduct = 0x2250, /* Product ID of 2250/2251 */
612 .bcdDevice_lo = 0x1,
613 .bcdDevice_hi = 0x1,
614 .driver_info = (kernel_ulong_t)GO7007_BOARDID_SENSORAY_2250,
615 },
616 {
617 .match_flags = USB_DEVICE_ID_MATCH_DEVICE_AND_VERSION,
618 .idVendor = 0x06e1, /* Vendor ID of ADS Technologies */
619 .idProduct = 0x0709, /* Product ID of DVD Xpress DX2 */
620 .bcdDevice_lo = 0x204,
621 .bcdDevice_hi = 0x204,
622 .driver_info = (kernel_ulong_t)GO7007_BOARDID_ADS_USBAV_709,
623 },
624 { } /* Terminating entry */
625 };
626
627 MODULE_DEVICE_TABLE(usb, go7007_usb_id_table);
628
629 /********************* Driver for EZ-USB HPI interface *********************/
630
631 static int go7007_usb_vendor_request(struct go7007 *go, int request,
632 int value, int index, void *transfer_buffer, int length, int in)
633 {
634 struct go7007_usb *usb = go->hpi_context;
635 int timeout = 5000;
636
637 if (in) {
638 return usb_control_msg(usb->usbdev,
639 usb_rcvctrlpipe(usb->usbdev, 0), request,
640 USB_TYPE_VENDOR | USB_RECIP_DEVICE | USB_DIR_IN,
641 value, index, transfer_buffer, length, timeout);
642 } else {
643 return usb_control_msg(usb->usbdev,
644 usb_sndctrlpipe(usb->usbdev, 0), request,
645 USB_TYPE_VENDOR | USB_RECIP_DEVICE,
646 value, index, transfer_buffer, length, timeout);
647 }
648 }
649
650 static int go7007_usb_interface_reset(struct go7007 *go)
651 {
652 struct go7007_usb *usb = go->hpi_context;
653 u16 intr_val, intr_data;
654
655 if (go->status == STATUS_SHUTDOWN)
656 return -1;
657 /* Reset encoder */
658 if (go7007_write_interrupt(go, 0x0001, 0x0001) < 0)
659 return -1;
660 msleep(100);
661
662 if (usb->board->flags & GO7007_USB_EZUSB) {
663 /* Reset buffer in EZ-USB */
664 dev_dbg(go->dev, "resetting EZ-USB buffers\n");
665 if (go7007_usb_vendor_request(go, 0x10, 0, 0, NULL, 0, 0) < 0 ||
666 go7007_usb_vendor_request(go, 0x10, 0, 0, NULL, 0, 0) < 0)
667 return -1;
668
669 /* Reset encoder again */
670 if (go7007_write_interrupt(go, 0x0001, 0x0001) < 0)
671 return -1;
672 msleep(100);
673 }
674
675 /* Wait for an interrupt to indicate successful hardware reset */
676 if (go7007_read_interrupt(go, &intr_val, &intr_data) < 0 ||
677 (intr_val & ~0x1) != 0x55aa) {
678 dev_err(go->dev, "unable to reset the USB interface\n");
679 return -1;
680 }
681 return 0;
682 }
683
684 static int go7007_usb_ezusb_write_interrupt(struct go7007 *go,
685 int addr, int data)
686 {
687 struct go7007_usb *usb = go->hpi_context;
688 int i, r;
689 u16 status_reg = 0;
690 int timeout = 500;
691
692 dev_dbg(go->dev, "WriteInterrupt: %04x %04x\n", addr, data);
693
694 for (i = 0; i < 100; ++i) {
695 r = usb_control_msg(usb->usbdev,
696 usb_rcvctrlpipe(usb->usbdev, 0), 0x14,
697 USB_TYPE_VENDOR | USB_RECIP_DEVICE | USB_DIR_IN,
698 0, HPI_STATUS_ADDR, go->usb_buf,
699 sizeof(status_reg), timeout);
700 if (r < 0)
701 break;
702 status_reg = le16_to_cpu(*((u16 *)go->usb_buf));
703 if (!(status_reg & 0x0010))
704 break;
705 msleep(10);
706 }
707 if (r < 0)
708 goto write_int_error;
709 if (i == 100) {
710 dev_err(go->dev, "device is hung, status reg = 0x%04x\n", status_reg);
711 return -1;
712 }
713 r = usb_control_msg(usb->usbdev, usb_sndctrlpipe(usb->usbdev, 0), 0x12,
714 USB_TYPE_VENDOR | USB_RECIP_DEVICE, data,
715 INT_PARAM_ADDR, NULL, 0, timeout);
716 if (r < 0)
717 goto write_int_error;
718 r = usb_control_msg(usb->usbdev, usb_sndctrlpipe(usb->usbdev, 0),
719 0x12, USB_TYPE_VENDOR | USB_RECIP_DEVICE, addr,
720 INT_INDEX_ADDR, NULL, 0, timeout);
721 if (r < 0)
722 goto write_int_error;
723 return 0;
724
725 write_int_error:
726 dev_err(go->dev, "error in WriteInterrupt: %d\n", r);
727 return r;
728 }
729
730 static int go7007_usb_onboard_write_interrupt(struct go7007 *go,
731 int addr, int data)
732 {
733 struct go7007_usb *usb = go->hpi_context;
734 int r;
735 int timeout = 500;
736
737 dev_dbg(go->dev, "WriteInterrupt: %04x %04x\n", addr, data);
738
739 go->usb_buf[0] = data & 0xff;
740 go->usb_buf[1] = data >> 8;
741 go->usb_buf[2] = addr & 0xff;
742 go->usb_buf[3] = addr >> 8;
743 go->usb_buf[4] = go->usb_buf[5] = go->usb_buf[6] = go->usb_buf[7] = 0;
744 r = usb_control_msg(usb->usbdev, usb_sndctrlpipe(usb->usbdev, 2), 0x00,
745 USB_TYPE_VENDOR | USB_RECIP_ENDPOINT, 0x55aa,
746 0xf0f0, go->usb_buf, 8, timeout);
747 if (r < 0) {
748 dev_err(go->dev, "error in WriteInterrupt: %d\n", r);
749 return r;
750 }
751 return 0;
752 }
753
754 static void go7007_usb_readinterrupt_complete(struct urb *urb)
755 {
756 struct go7007 *go = (struct go7007 *)urb->context;
757 u16 *regs = (u16 *)urb->transfer_buffer;
758 int status = urb->status;
759
760 if (status) {
761 if (status != -ESHUTDOWN &&
762 go->status != STATUS_SHUTDOWN) {
763 dev_err(go->dev, "error in read interrupt: %d\n", urb->status);
764 } else {
765 wake_up(&go->interrupt_waitq);
766 return;
767 }
768 } else if (urb->actual_length != urb->transfer_buffer_length) {
769 dev_err(go->dev, "short read in interrupt pipe!\n");
770 } else {
771 go->interrupt_available = 1;
772 go->interrupt_data = __le16_to_cpu(regs[0]);
773 go->interrupt_value = __le16_to_cpu(regs[1]);
774 dev_dbg(go->dev, "ReadInterrupt: %04x %04x\n",
775 go->interrupt_value, go->interrupt_data);
776 }
777
778 wake_up(&go->interrupt_waitq);
779 }
780
781 static int go7007_usb_read_interrupt(struct go7007 *go)
782 {
783 struct go7007_usb *usb = go->hpi_context;
784 int r;
785
786 r = usb_submit_urb(usb->intr_urb, GFP_KERNEL);
787 if (r < 0) {
788 dev_err(go->dev, "unable to submit interrupt urb: %d\n", r);
789 return r;
790 }
791 return 0;
792 }
793
794 static void go7007_usb_read_video_pipe_complete(struct urb *urb)
795 {
796 struct go7007 *go = (struct go7007 *)urb->context;
797 int r, status = urb->status;
798
799 if (!vb2_is_streaming(&go->vidq)) {
800 wake_up_interruptible(&go->frame_waitq);
801 return;
802 }
803 if (status) {
804 dev_err(go->dev, "error in video pipe: %d\n", status);
805 return;
806 }
807 if (urb->actual_length != urb->transfer_buffer_length) {
808 dev_err(go->dev, "short read in video pipe!\n");
809 return;
810 }
811 go7007_parse_video_stream(go, urb->transfer_buffer, urb->actual_length);
812 r = usb_submit_urb(urb, GFP_ATOMIC);
813 if (r < 0)
814 dev_err(go->dev, "error in video pipe: %d\n", r);
815 }
816
817 static void go7007_usb_read_audio_pipe_complete(struct urb *urb)
818 {
819 struct go7007 *go = (struct go7007 *)urb->context;
820 int r, status = urb->status;
821
822 if (!vb2_is_streaming(&go->vidq))
823 return;
824 if (status) {
825 dev_err(go->dev, "error in audio pipe: %d\n",
826 status);
827 return;
828 }
829 if (urb->actual_length != urb->transfer_buffer_length) {
830 dev_err(go->dev, "short read in audio pipe!\n");
831 return;
832 }
833 if (go->audio_deliver != NULL)
834 go->audio_deliver(go, urb->transfer_buffer, urb->actual_length);
835 r = usb_submit_urb(urb, GFP_ATOMIC);
836 if (r < 0)
837 dev_err(go->dev, "error in audio pipe: %d\n", r);
838 }
839
840 static int go7007_usb_stream_start(struct go7007 *go)
841 {
842 struct go7007_usb *usb = go->hpi_context;
843 int i, r;
844
845 for (i = 0; i < 8; ++i) {
846 r = usb_submit_urb(usb->video_urbs[i], GFP_KERNEL);
847 if (r < 0) {
848 dev_err(go->dev, "error submitting video urb %d: %d\n", i, r);
849 goto video_submit_failed;
850 }
851 }
852 if (!go->audio_enabled)
853 return 0;
854
855 for (i = 0; i < 8; ++i) {
856 r = usb_submit_urb(usb->audio_urbs[i], GFP_KERNEL);
857 if (r < 0) {
858 dev_err(go->dev, "error submitting audio urb %d: %d\n", i, r);
859 goto audio_submit_failed;
860 }
861 }
862 return 0;
863
864 audio_submit_failed:
865 for (i = 0; i < 7; ++i)
866 usb_kill_urb(usb->audio_urbs[i]);
867 video_submit_failed:
868 for (i = 0; i < 8; ++i)
869 usb_kill_urb(usb->video_urbs[i]);
870 return -1;
871 }
872
873 static int go7007_usb_stream_stop(struct go7007 *go)
874 {
875 struct go7007_usb *usb = go->hpi_context;
876 int i;
877
878 if (go->status == STATUS_SHUTDOWN)
879 return 0;
880 for (i = 0; i < 8; ++i)
881 usb_kill_urb(usb->video_urbs[i]);
882 if (go->audio_enabled)
883 for (i = 0; i < 8; ++i)
884 usb_kill_urb(usb->audio_urbs[i]);
885 return 0;
886 }
887
888 static int go7007_usb_send_firmware(struct go7007 *go, u8 *data, int len)
889 {
890 struct go7007_usb *usb = go->hpi_context;
891 int transferred, pipe;
892 int timeout = 500;
893
894 dev_dbg(go->dev, "DownloadBuffer sending %d bytes\n", len);
895
896 if (usb->board->flags & GO7007_USB_EZUSB)
897 pipe = usb_sndbulkpipe(usb->usbdev, 2);
898 else
899 pipe = usb_sndbulkpipe(usb->usbdev, 3);
900
901 return usb_bulk_msg(usb->usbdev, pipe, data, len,
902 &transferred, timeout);
903 }
904
905 static void go7007_usb_release(struct go7007 *go)
906 {
907 struct go7007_usb *usb = go->hpi_context;
908 struct urb *vurb, *aurb;
909 int i;
910
911 if (usb->intr_urb) {
912 usb_kill_urb(usb->intr_urb);
913 kfree(usb->intr_urb->transfer_buffer);
914 usb_free_urb(usb->intr_urb);
915 }
916
917 /* Free USB-related structs */
918 for (i = 0; i < 8; ++i) {
919 vurb = usb->video_urbs[i];
920 if (vurb) {
921 usb_kill_urb(vurb);
922 kfree(vurb->transfer_buffer);
923 usb_free_urb(vurb);
924 }
925 aurb = usb->audio_urbs[i];
926 if (aurb) {
927 usb_kill_urb(aurb);
928 kfree(aurb->transfer_buffer);
929 usb_free_urb(aurb);
930 }
931 }
932
933 kfree(go->hpi_context);
934 }
935
936 static struct go7007_hpi_ops go7007_usb_ezusb_hpi_ops = {
937 .interface_reset = go7007_usb_interface_reset,
938 .write_interrupt = go7007_usb_ezusb_write_interrupt,
939 .read_interrupt = go7007_usb_read_interrupt,
940 .stream_start = go7007_usb_stream_start,
941 .stream_stop = go7007_usb_stream_stop,
942 .send_firmware = go7007_usb_send_firmware,
943 .release = go7007_usb_release,
944 };
945
946 static struct go7007_hpi_ops go7007_usb_onboard_hpi_ops = {
947 .interface_reset = go7007_usb_interface_reset,
948 .write_interrupt = go7007_usb_onboard_write_interrupt,
949 .read_interrupt = go7007_usb_read_interrupt,
950 .stream_start = go7007_usb_stream_start,
951 .stream_stop = go7007_usb_stream_stop,
952 .send_firmware = go7007_usb_send_firmware,
953 .release = go7007_usb_release,
954 };
955
956 /********************* Driver for EZ-USB I2C adapter *********************/
957
958 static int go7007_usb_i2c_master_xfer(struct i2c_adapter *adapter,
959 struct i2c_msg msgs[], int num)
960 {
961 struct go7007 *go = i2c_get_adapdata(adapter);
962 struct go7007_usb *usb = go->hpi_context;
963 u8 *buf = go->usb_buf;
964 int buf_len, i;
965 int ret = -EIO;
966
967 if (go->status == STATUS_SHUTDOWN)
968 return -ENODEV;
969
970 mutex_lock(&usb->i2c_lock);
971
972 for (i = 0; i < num; ++i) {
973 /* The hardware command is "write some bytes then read some
974 * bytes", so we try to coalesce a write followed by a read
975 * into a single USB transaction */
976 if (i + 1 < num && msgs[i].addr == msgs[i + 1].addr &&
977 !(msgs[i].flags & I2C_M_RD) &&
978 (msgs[i + 1].flags & I2C_M_RD)) {
979 #ifdef GO7007_I2C_DEBUG
980 dev_dbg(go->dev, "i2c write/read %d/%d bytes on %02x\n",
981 msgs[i].len, msgs[i + 1].len, msgs[i].addr);
982 #endif
983 buf[0] = 0x01;
984 buf[1] = msgs[i].len + 1;
985 buf[2] = msgs[i].addr << 1;
986 memcpy(&buf[3], msgs[i].buf, msgs[i].len);
987 buf_len = msgs[i].len + 3;
988 buf[buf_len++] = msgs[++i].len;
989 } else if (msgs[i].flags & I2C_M_RD) {
990 #ifdef GO7007_I2C_DEBUG
991 dev_dbg(go->dev, "i2c read %d bytes on %02x\n",
992 msgs[i].len, msgs[i].addr);
993 #endif
994 buf[0] = 0x01;
995 buf[1] = 1;
996 buf[2] = msgs[i].addr << 1;
997 buf[3] = msgs[i].len;
998 buf_len = 4;
999 } else {
1000 #ifdef GO7007_I2C_DEBUG
1001 dev_dbg(go->dev, "i2c write %d bytes on %02x\n",
1002 msgs[i].len, msgs[i].addr);
1003 #endif
1004 buf[0] = 0x00;
1005 buf[1] = msgs[i].len + 1;
1006 buf[2] = msgs[i].addr << 1;
1007 memcpy(&buf[3], msgs[i].buf, msgs[i].len);
1008 buf_len = msgs[i].len + 3;
1009 buf[buf_len++] = 0;
1010 }
1011 if (go7007_usb_vendor_request(go, 0x24, 0, 0,
1012 buf, buf_len, 0) < 0)
1013 goto i2c_done;
1014 if (msgs[i].flags & I2C_M_RD) {
1015 memset(buf, 0, msgs[i].len + 1);
1016 if (go7007_usb_vendor_request(go, 0x25, 0, 0, buf,
1017 msgs[i].len + 1, 1) < 0)
1018 goto i2c_done;
1019 memcpy(msgs[i].buf, buf + 1, msgs[i].len);
1020 }
1021 }
1022 ret = num;
1023
1024 i2c_done:
1025 mutex_unlock(&usb->i2c_lock);
1026 return ret;
1027 }
1028
1029 static u32 go7007_usb_functionality(struct i2c_adapter *adapter)
1030 {
1031 /* No errors are reported by the hardware, so we don't bother
1032 * supporting quick writes to avoid confusing probing */
1033 return (I2C_FUNC_SMBUS_EMUL) & ~I2C_FUNC_SMBUS_QUICK;
1034 }
1035
1036 static struct i2c_algorithm go7007_usb_algo = {
1037 .master_xfer = go7007_usb_i2c_master_xfer,
1038 .functionality = go7007_usb_functionality,
1039 };
1040
1041 static struct i2c_adapter go7007_usb_adap_templ = {
1042 .owner = THIS_MODULE,
1043 .name = "WIS GO7007SB EZ-USB",
1044 .algo = &go7007_usb_algo,
1045 };
1046
1047 /********************* USB add/remove functions *********************/
1048
1049 static int go7007_usb_probe(struct usb_interface *intf,
1050 const struct usb_device_id *id)
1051 {
1052 struct go7007 *go;
1053 struct go7007_usb *usb;
1054 const struct go7007_usb_board *board;
1055 struct usb_device *usbdev = interface_to_usbdev(intf);
1056 unsigned num_i2c_devs;
1057 char *name;
1058 int video_pipe, i, v_urb_len;
1059
1060 dev_dbg(go->dev, "probing new GO7007 USB board\n");
1061
1062 switch (id->driver_info) {
1063 case GO7007_BOARDID_MATRIX_II:
1064 name = "WIS Matrix II or compatible";
1065 board = &board_matrix_ii;
1066 break;
1067 case GO7007_BOARDID_MATRIX_RELOAD:
1068 name = "WIS Matrix Reloaded or compatible";
1069 board = &board_matrix_reload;
1070 break;
1071 case GO7007_BOARDID_MATRIX_REV:
1072 name = "WIS Matrix Revolution or compatible";
1073 board = &board_matrix_revolution;
1074 break;
1075 case GO7007_BOARDID_STAR_TREK:
1076 name = "WIS Star Trek or compatible";
1077 board = &board_star_trek;
1078 break;
1079 case GO7007_BOARDID_XMEN:
1080 name = "WIS XMen or compatible";
1081 board = &board_xmen;
1082 break;
1083 case GO7007_BOARDID_XMEN_II:
1084 name = "WIS XMen II or compatible";
1085 board = &board_xmen;
1086 break;
1087 case GO7007_BOARDID_XMEN_III:
1088 name = "WIS XMen III or compatible";
1089 board = &board_xmen;
1090 break;
1091 case GO7007_BOARDID_PX_M402U:
1092 name = "Plextor PX-M402U";
1093 board = &board_matrix_ii;
1094 break;
1095 case GO7007_BOARDID_PX_TV402U:
1096 name = "Plextor PX-TV402U (unknown tuner)";
1097 board = &board_px_tv402u;
1098 break;
1099 case GO7007_BOARDID_LIFEVIEW_LR192:
1100 dev_err(go->dev, "The Lifeview TV Walker Ultra is not supported. Sorry!\n");
1101 return -ENODEV;
1102 name = "Lifeview TV Walker Ultra";
1103 board = &board_lifeview_lr192;
1104 break;
1105 case GO7007_BOARDID_SENSORAY_2250:
1106 dev_info(go->dev, "Sensoray 2250 found\n");
1107 name = "Sensoray 2250/2251";
1108 board = &board_sensoray_2250;
1109 break;
1110 case GO7007_BOARDID_ADS_USBAV_709:
1111 name = "ADS Tech DVD Xpress DX2";
1112 board = &board_ads_usbav_709;
1113 break;
1114 default:
1115 dev_err(go->dev, "unknown board ID %d!\n",
1116 (unsigned int)id->driver_info);
1117 return -ENODEV;
1118 }
1119
1120 go = go7007_alloc(&board->main_info, &intf->dev);
1121 if (go == NULL)
1122 return -ENOMEM;
1123
1124 usb = kzalloc(sizeof(struct go7007_usb), GFP_KERNEL);
1125 if (usb == NULL) {
1126 kfree(go);
1127 return -ENOMEM;
1128 }
1129
1130 usb->board = board;
1131 usb->usbdev = usbdev;
1132 usb_make_path(usbdev, go->bus_info, sizeof(go->bus_info));
1133 go->board_id = id->driver_info;
1134 strncpy(go->name, name, sizeof(go->name));
1135 if (board->flags & GO7007_USB_EZUSB)
1136 go->hpi_ops = &go7007_usb_ezusb_hpi_ops;
1137 else
1138 go->hpi_ops = &go7007_usb_onboard_hpi_ops;
1139 go->hpi_context = usb;
1140
1141 /* Allocate the URB and buffer for receiving incoming interrupts */
1142 usb->intr_urb = usb_alloc_urb(0, GFP_KERNEL);
1143 if (usb->intr_urb == NULL)
1144 goto allocfail;
1145 usb->intr_urb->transfer_buffer = kmalloc(2*sizeof(u16), GFP_KERNEL);
1146 if (usb->intr_urb->transfer_buffer == NULL)
1147 goto allocfail;
1148
1149 if (go->board_id == GO7007_BOARDID_SENSORAY_2250)
1150 usb_fill_bulk_urb(usb->intr_urb, usb->usbdev,
1151 usb_rcvbulkpipe(usb->usbdev, 4),
1152 usb->intr_urb->transfer_buffer, 2*sizeof(u16),
1153 go7007_usb_readinterrupt_complete, go);
1154 else
1155 usb_fill_int_urb(usb->intr_urb, usb->usbdev,
1156 usb_rcvintpipe(usb->usbdev, 4),
1157 usb->intr_urb->transfer_buffer, 2*sizeof(u16),
1158 go7007_usb_readinterrupt_complete, go, 8);
1159 usb_set_intfdata(intf, &go->v4l2_dev);
1160
1161 /* Boot the GO7007 */
1162 if (go7007_boot_encoder(go, go->board_info->flags &
1163 GO7007_BOARD_USE_ONBOARD_I2C) < 0)
1164 goto allocfail;
1165
1166 /* Register the EZ-USB I2C adapter, if we're using it */
1167 if (board->flags & GO7007_USB_EZUSB_I2C) {
1168 memcpy(&go->i2c_adapter, &go7007_usb_adap_templ,
1169 sizeof(go7007_usb_adap_templ));
1170 mutex_init(&usb->i2c_lock);
1171 go->i2c_adapter.dev.parent = go->dev;
1172 i2c_set_adapdata(&go->i2c_adapter, go);
1173 if (i2c_add_adapter(&go->i2c_adapter) < 0) {
1174 dev_err(go->dev, "error: i2c_add_adapter failed\n");
1175 goto allocfail;
1176 }
1177 go->i2c_adapter_online = 1;
1178 }
1179
1180 /* Pelco and Adlink reused the XMen and XMen-III vendor and product
1181 * IDs for their own incompatible designs. We can detect XMen boards
1182 * by probing the sensor, but there is no way to probe the sensors on
1183 * the Pelco and Adlink designs so we default to the Adlink. If it
1184 * is actually a Pelco, the user must set the assume_endura module
1185 * parameter. */
1186 if ((go->board_id == GO7007_BOARDID_XMEN ||
1187 go->board_id == GO7007_BOARDID_XMEN_III) &&
1188 go->i2c_adapter_online) {
1189 union i2c_smbus_data data;
1190
1191 /* Check to see if register 0x0A is 0x76 */
1192 i2c_smbus_xfer(&go->i2c_adapter, 0x21, I2C_CLIENT_SCCB,
1193 I2C_SMBUS_READ, 0x0A, I2C_SMBUS_BYTE_DATA, &data);
1194 if (data.byte != 0x76) {
1195 if (assume_endura) {
1196 go->board_id = GO7007_BOARDID_ENDURA;
1197 usb->board = board = &board_endura;
1198 go->board_info = &board->main_info;
1199 strncpy(go->name, "Pelco Endura",
1200 sizeof(go->name));
1201 } else {
1202 u16 channel;
1203
1204 /* read channel number from GPIO[1:0] */
1205 go7007_read_addr(go, 0x3c81, &channel);
1206 channel &= 0x3;
1207 go->board_id = GO7007_BOARDID_ADLINK_MPG24;
1208 usb->board = board = &board_adlink_mpg24;
1209 go->board_info = &board->main_info;
1210 go->channel_number = channel;
1211 snprintf(go->name, sizeof(go->name),
1212 "Adlink PCI-MPG24, channel #%d",
1213 channel);
1214 }
1215 go7007_update_board(go);
1216 }
1217 }
1218
1219 num_i2c_devs = go->board_info->num_i2c_devs;
1220
1221 /* Probe the tuner model on the TV402U */
1222 if (go->board_id == GO7007_BOARDID_PX_TV402U) {
1223 /* Board strapping indicates tuner model */
1224 if (go7007_usb_vendor_request(go, 0x41, 0, 0, go->usb_buf, 3,
1225 1) < 0) {
1226 dev_err(go->dev, "GPIO read failed!\n");
1227 goto allocfail;
1228 }
1229 switch (go->usb_buf[0] >> 6) {
1230 case 1:
1231 go->tuner_type = TUNER_SONY_BTF_PG472Z;
1232 go->std = V4L2_STD_PAL;
1233 strncpy(go->name, "Plextor PX-TV402U-EU",
1234 sizeof(go->name));
1235 break;
1236 case 2:
1237 go->tuner_type = TUNER_SONY_BTF_PK467Z;
1238 go->std = V4L2_STD_NTSC_M_JP;
1239 num_i2c_devs -= 2;
1240 strncpy(go->name, "Plextor PX-TV402U-JP",
1241 sizeof(go->name));
1242 break;
1243 case 3:
1244 go->tuner_type = TUNER_SONY_BTF_PB463Z;
1245 num_i2c_devs -= 2;
1246 strncpy(go->name, "Plextor PX-TV402U-NA",
1247 sizeof(go->name));
1248 break;
1249 default:
1250 dev_dbg(go->dev, "unable to detect tuner type!\n");
1251 break;
1252 }
1253 /* Configure tuner mode selection inputs connected
1254 * to the EZ-USB GPIO output pins */
1255 if (go7007_usb_vendor_request(go, 0x40, 0x7f02, 0,
1256 NULL, 0, 0) < 0) {
1257 dev_err(go->dev, "GPIO write failed!\n");
1258 goto allocfail;
1259 }
1260 }
1261
1262 /* Print a nasty message if the user attempts to use a USB2.0 device in
1263 * a USB1.1 port. There will be silent corruption of the stream. */
1264 if ((board->flags & GO7007_USB_EZUSB) &&
1265 usbdev->speed != USB_SPEED_HIGH)
1266 dev_err(go->dev, "*** WARNING *** This device must be connected to a USB 2.0 port! Attempting to capture video through a USB 1.1 port will result in stream corruption, even at low bitrates!\n");
1267
1268 /* Allocate the URBs and buffers for receiving the video stream */
1269 if (board->flags & GO7007_USB_EZUSB) {
1270 v_urb_len = 1024;
1271 video_pipe = usb_rcvbulkpipe(usb->usbdev, 6);
1272 } else {
1273 v_urb_len = 512;
1274 video_pipe = usb_rcvbulkpipe(usb->usbdev, 1);
1275 }
1276 for (i = 0; i < 8; ++i) {
1277 usb->video_urbs[i] = usb_alloc_urb(0, GFP_KERNEL);
1278 if (usb->video_urbs[i] == NULL)
1279 goto allocfail;
1280 usb->video_urbs[i]->transfer_buffer =
1281 kmalloc(v_urb_len, GFP_KERNEL);
1282 if (usb->video_urbs[i]->transfer_buffer == NULL)
1283 goto allocfail;
1284 usb_fill_bulk_urb(usb->video_urbs[i], usb->usbdev, video_pipe,
1285 usb->video_urbs[i]->transfer_buffer, v_urb_len,
1286 go7007_usb_read_video_pipe_complete, go);
1287 }
1288
1289 /* Allocate the URBs and buffers for receiving the audio stream */
1290 if ((board->flags & GO7007_USB_EZUSB) &&
1291 (board->flags & GO7007_BOARD_HAS_AUDIO)) {
1292 for (i = 0; i < 8; ++i) {
1293 usb->audio_urbs[i] = usb_alloc_urb(0, GFP_KERNEL);
1294 if (usb->audio_urbs[i] == NULL)
1295 goto allocfail;
1296 usb->audio_urbs[i]->transfer_buffer = kmalloc(4096,
1297 GFP_KERNEL);
1298 if (usb->audio_urbs[i]->transfer_buffer == NULL)
1299 goto allocfail;
1300 usb_fill_bulk_urb(usb->audio_urbs[i], usb->usbdev,
1301 usb_rcvbulkpipe(usb->usbdev, 8),
1302 usb->audio_urbs[i]->transfer_buffer, 4096,
1303 go7007_usb_read_audio_pipe_complete, go);
1304 }
1305 }
1306
1307 /* Do any final GO7007 initialization, then register the
1308 * V4L2 and ALSA interfaces */
1309 if (go7007_register_encoder(go, num_i2c_devs) < 0)
1310 goto allocfail;
1311
1312 go->status = STATUS_ONLINE;
1313 return 0;
1314
1315 allocfail:
1316 go7007_usb_release(go);
1317 kfree(go);
1318 return -ENOMEM;
1319 }
1320
1321 static void go7007_usb_disconnect(struct usb_interface *intf)
1322 {
1323 struct go7007 *go = to_go7007(usb_get_intfdata(intf));
1324
1325 mutex_lock(&go->queue_lock);
1326 mutex_lock(&go->serialize_lock);
1327
1328 if (go->audio_enabled)
1329 go7007_snd_remove(go);
1330
1331 go->status = STATUS_SHUTDOWN;
1332 v4l2_device_disconnect(&go->v4l2_dev);
1333 video_unregister_device(&go->vdev);
1334 mutex_unlock(&go->serialize_lock);
1335 mutex_unlock(&go->queue_lock);
1336
1337 v4l2_device_put(&go->v4l2_dev);
1338 }
1339
1340 static struct usb_driver go7007_usb_driver = {
1341 .name = "go7007",
1342 .probe = go7007_usb_probe,
1343 .disconnect = go7007_usb_disconnect,
1344 .id_table = go7007_usb_id_table,
1345 };
1346
1347 module_usb_driver(go7007_usb_driver);
1348 MODULE_LICENSE("GPL v2");
This page took 0.061549 seconds and 6 git commands to generate.