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