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