Version:  2.0.40 2.2.26 2.4.37 3.0 3.1 3.2 3.3 3.4 3.5 3.6 3.7 3.8 3.9 3.10 3.11 3.12 3.13 3.14 3.15 3.16

Linux/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 #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
 19 
 20 #include <linux/module.h>
 21 #include <linux/kernel.h>
 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>
 30 #include <media/saa7115.h>
 31 #include <media/tuner.h>
 32 #include <media/uda1342.h>
 33 
 34 #include "go7007-priv.h"
 35 
 36 static unsigned int assume_endura;
 37 module_param(assume_endura, int, 0644);
 38 MODULE_PARM_DESC(assume_endura,
 39                         "when probing fails, hardware is a Pelco Endura");
 40 
 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:
 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)
 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         const struct go7007_usb_board *board;
 67         struct mutex i2c_lock;
 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 const struct go7007_usb_board board_matrix_ii = {
 77         .flags          = GO7007_USB_EZUSB,
 78         .main_info      = {
 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 |
 90                                         GO7007_SENSOR_SAA7115 |
 91                                         GO7007_SENSOR_VBI |
 92                                         GO7007_SENSOR_SCALING,
 93                 .num_i2c_devs    = 1,
 94                 .i2c_devs        = {
 95                         {
 96                                 .type   = "saa7115",
 97                                 .addr   = 0x20,
 98                                 .is_video = 1,
 99                         },
100                 },
101                 .num_inputs      = 2,
102                 .inputs          = {
103                         {
104                                 .video_input    = 0,
105                                 .name           = "Composite",
106                         },
107                         {
108                                 .video_input    = 9,
109                                 .name           = "S-Video",
110                         },
111                 },
112                 .video_config   = SAA7115_IDQ_IS_DEFAULT,
113         },
114 };
115 
116 static const struct go7007_usb_board board_matrix_reload = {
117         .flags          = GO7007_USB_EZUSB,
118         .main_info      = {
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                         {
133                                 .type   = "saa7113",
134                                 .addr   = 0x25,
135                                 .is_video = 1,
136                         },
137                 },
138                 .num_inputs      = 2,
139                 .inputs          = {
140                         {
141                                 .video_input    = 0,
142                                 .name           = "Composite",
143                         },
144                         {
145                                 .video_input    = 9,
146                                 .name           = "S-Video",
147                         },
148                 },
149                 .video_config   = SAA7115_IDQ_IS_DEFAULT,
150         },
151 };
152 
153 static const struct go7007_usb_board board_star_trek = {
154         .flags          = GO7007_USB_EZUSB | GO7007_USB_EZUSB_I2C,
155         .main_info      = {
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_SAA7115 |
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                         {
172                                 .type   = "saa7115",
173                                 .addr   = 0x20,
174                                 .is_video = 1,
175                         },
176                 },
177                 .num_inputs      = 2,
178                 .inputs          = {
179                 /*      {
180                  *              .video_input    = 3,
181                  *              .audio_index    = AUDIO_TUNER,
182                  *              .name           = "Tuner",
183                  *      },
184                  */
185                         {
186                                 .video_input    = 1,
187                         /*      .audio_index    = AUDIO_EXTERN, */
188                                 .name           = "Composite",
189                         },
190                         {
191                                 .video_input    = 8,
192                         /*      .audio_index    = AUDIO_EXTERN, */
193                                 .name           = "S-Video",
194                         },
195                 },
196                 .video_config   = SAA7115_IDQ_IS_DEFAULT,
197         },
198 };
199 
200 static const struct go7007_usb_board board_px_tv402u = {
201         .flags          = GO7007_USB_EZUSB | GO7007_USB_EZUSB_I2C,
202         .main_info      = {
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 |
208                                         GO7007_SENSOR_SAA7115 |
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,
216                 .num_i2c_devs    = 5,
217                 .i2c_devs        = {
218                         {
219                                 .type   = "saa7115",
220                                 .addr   = 0x20,
221                                 .is_video = 1,
222                         },
223                         {
224                                 .type   = "uda1342",
225                                 .addr   = 0x1a,
226                                 .is_audio = 1,
227                         },
228                         {
229                                 .type   = "tuner",
230                                 .addr   = 0x60,
231                         },
232                         {
233                                 .type   = "tuner",
234                                 .addr   = 0x43,
235                         },
236                         {
237                                 .type   = "sony-btf-mpx",
238                                 .addr   = 0x44,
239                         },
240                 },
241                 .num_inputs      = 3,
242                 .inputs          = {
243                         {
244                                 .video_input    = 3,
245                                 .audio_index    = 0,
246                                 .name           = "Tuner",
247                         },
248                         {
249                                 .video_input    = 1,
250                                 .audio_index    = 1,
251                                 .name           = "Composite",
252                         },
253                         {
254                                 .video_input    = 8,
255                                 .audio_index    = 1,
256                                 .name           = "S-Video",
257                         },
258                 },
259                 .video_config   = SAA7115_IDQ_IS_DEFAULT,
260                 .num_aud_inputs  = 2,
261                 .aud_inputs      = {
262                         {
263                                 .audio_input    = UDA1342_IN2,
264                                 .name           = "Tuner",
265                         },
266                         {
267                                 .audio_input    = UDA1342_IN1,
268                                 .name           = "Line In",
269                         },
270                 },
271         },
272 };
273 
274 static const struct go7007_usb_board board_xmen = {
275         .flags          = 0,
276         .main_info      = {
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                         {
295                                 .type   = "ov7640",
296                                 .addr   = 0x21,
297                         },
298                 },
299                 .num_inputs       = 1,
300                 .inputs           = {
301                         {
302                                 .name           = "Camera",
303                         },
304                 },
305         },
306 };
307 
308 static const struct go7007_usb_board board_matrix_revolution = {
309         .flags          = GO7007_USB_EZUSB,
310         .main_info      = {
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                         {
326                                 .type   = "tw9903",
327                                 .is_video = 1,
328                                 .addr   = 0x44,
329                         },
330                 },
331                 .num_inputs      = 2,
332                 .inputs          = {
333                         {
334                                 .video_input    = 2,
335                                 .name           = "Composite",
336                         },
337                         {
338                                 .video_input    = 8,
339                                 .name           = "S-Video",
340                         },
341                 },
342         },
343 };
344 
345 static const struct go7007_usb_board board_lifeview_lr192 = {
346         .flags          = GO7007_USB_EZUSB,
347         .main_info      = {
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,
363                 .inputs          = {
364                         {
365                                 .video_input    = 0,
366                                 .name           = "Composite",
367                         },
368                 },
369         },
370 };
371 
372 static const struct go7007_usb_board board_endura = {
373         .flags          = 0,
374         .main_info      = {
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,
388                 .inputs          = {
389                         {
390                                 .name           = "Camera",
391                         },
392                 },
393         },
394 };
395 
396 static const struct go7007_usb_board board_adlink_mpg24 = {
397         .flags          = 0,
398         .main_info      = {
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                         {
413                                 .type   = "tw2804",
414                                 .addr   = 0x00, /* yes, really */
415                                 .flags  = I2C_CLIENT_TEN,
416                                 .is_video = 1,
417                         },
418                 },
419                 .num_inputs      = 1,
420                 .inputs          = {
421                         {
422                                 .name           = "Composite",
423                         },
424                 },
425         },
426 };
427 
428 static const struct go7007_usb_board board_sensoray_2250 = {
429         .flags          = GO7007_USB_EZUSB | GO7007_USB_EZUSB_I2C,
430         .main_info      = {
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                         {
444                                 .type   = "s2250",
445                                 .addr   = 0x43,
446                                 .is_video = 1,
447                                 .is_audio = 1,
448                         },
449                 },
450                 .num_inputs      = 2,
451                 .inputs          = {
452                         {
453                                 .video_input    = 0,
454                                 .name           = "Composite",
455                         },
456                         {
457                                 .video_input    = 1,
458                                 .name           = "S-Video",
459                         },
460                 },
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                 },
476         },
477 };
478 
479 static 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 
516 static const struct usb_device_id go7007_usb_id_table[] = {
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,
599                 .driver_info    = (kernel_ulong_t)GO7007_BOARDID_PX_TV402U,
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         },
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         },
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         },
625         { }                                     /* Terminating entry */
626 };
627 
628 MODULE_DEVICE_TABLE(usb, go7007_usb_id_table);
629 
630 /********************* Driver for EZ-USB HPI interface *********************/
631 
632 static 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 
651 static int go7007_usb_interface_reset(struct go7007 *go)
652 {
653         struct go7007_usb *usb = go->hpi_context;
654         u16 intr_val, intr_data;
655 
656         if (go->status == STATUS_SHUTDOWN)
657                 return -1;
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 */
665                 pr_debug("resetting EZ-USB buffers\n");
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) {
679                 dev_err(go->dev, "unable to reset the USB interface\n");
680                 return -1;
681         }
682         return 0;
683 }
684 
685 static 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;
690         u16 status_reg = 0;
691         int timeout = 500;
692 
693         pr_debug("WriteInterrupt: %04x %04x\n", addr, data);
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,
699                                 0, HPI_STATUS_ADDR, go->usb_buf,
700                                 sizeof(status_reg), timeout);
701                 if (r < 0)
702                         break;
703                 status_reg = le16_to_cpu(*((u16 *)go->usb_buf));
704                 if (!(status_reg & 0x0010))
705                         break;
706                 msleep(10);
707         }
708         if (r < 0)
709                 goto write_int_error;
710         if (i == 100) {
711                 dev_err(go->dev, "device is hung, status reg = 0x%04x\n", status_reg);
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 
726 write_int_error:
727         dev_err(go->dev, "error in WriteInterrupt: %d\n", r);
728         return r;
729 }
730 
731 static int go7007_usb_onboard_write_interrupt(struct go7007 *go,
732                                                 int addr, int data)
733 {
734         struct go7007_usb *usb = go->hpi_context;
735         int r;
736         int timeout = 500;
737 
738         pr_debug("WriteInterrupt: %04x %04x\n", addr, data);
739 
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;
745         r = usb_control_msg(usb->usbdev, usb_sndctrlpipe(usb->usbdev, 2), 0x00,
746                         USB_TYPE_VENDOR | USB_RECIP_ENDPOINT, 0x55aa,
747                         0xf0f0, go->usb_buf, 8, timeout);
748         if (r < 0) {
749                 dev_err(go->dev, "error in WriteInterrupt: %d\n", r);
750                 return r;
751         }
752         return 0;
753 }
754 
755 static void go7007_usb_readinterrupt_complete(struct urb *urb)
756 {
757         struct go7007 *go = (struct go7007 *)urb->context;
758         u16 *regs = (u16 *)urb->transfer_buffer;
759         int status = urb->status;
760 
761         if (status) {
762                 if (status != -ESHUTDOWN &&
763                                 go->status != STATUS_SHUTDOWN) {
764                         dev_err(go->dev, "error in read interrupt: %d\n", urb->status);
765                 } else {
766                         wake_up(&go->interrupt_waitq);
767                         return;
768                 }
769         } else if (urb->actual_length != urb->transfer_buffer_length) {
770                 dev_err(go->dev, "short read in interrupt pipe!\n");
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]);
775                 pr_debug("ReadInterrupt: %04x %04x\n",
776                                 go->interrupt_value, go->interrupt_data);
777         }
778 
779         wake_up(&go->interrupt_waitq);
780 }
781 
782 static 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) {
789                 dev_err(go->dev, "unable to submit interrupt urb: %d\n", r);
790                 return r;
791         }
792         return 0;
793 }
794 
795 static void go7007_usb_read_video_pipe_complete(struct urb *urb)
796 {
797         struct go7007 *go = (struct go7007 *)urb->context;
798         int r, status = urb->status;
799 
800         if (!vb2_is_streaming(&go->vidq)) {
801                 wake_up_interruptible(&go->frame_waitq);
802                 return;
803         }
804         if (status) {
805                 dev_err(go->dev, "error in video pipe: %d\n", status);
806                 return;
807         }
808         if (urb->actual_length != urb->transfer_buffer_length) {
809                 dev_err(go->dev, "short read in video pipe!\n");
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)
815                 dev_err(go->dev, "error in video pipe: %d\n", r);
816 }
817 
818 static void go7007_usb_read_audio_pipe_complete(struct urb *urb)
819 {
820         struct go7007 *go = (struct go7007 *)urb->context;
821         int r, status = urb->status;
822 
823         if (!vb2_is_streaming(&go->vidq))
824                 return;
825         if (status) {
826                 dev_err(go->dev, "error in audio pipe: %d\n",
827                         status);
828                 return;
829         }
830         if (urb->actual_length != urb->transfer_buffer_length) {
831                 dev_err(go->dev, "short read in audio pipe!\n");
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)
838                 dev_err(go->dev, "error in audio pipe: %d\n", r);
839 }
840 
841 static 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) {
849                         dev_err(go->dev, "error submitting video urb %d: %d\n", i, r);
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) {
859                         dev_err(go->dev, "error submitting audio urb %d: %d\n", i, r);
860                         goto audio_submit_failed;
861                 }
862         }
863         return 0;
864 
865 audio_submit_failed:
866         for (i = 0; i < 7; ++i)
867                 usb_kill_urb(usb->audio_urbs[i]);
868 video_submit_failed:
869         for (i = 0; i < 8; ++i)
870                 usb_kill_urb(usb->video_urbs[i]);
871         return -1;
872 }
873 
874 static 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 
889 static 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 
895         pr_debug("DownloadBuffer sending %d bytes\n", len);
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 
906 static 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 
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         }
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         }
933 
934         kfree(go->hpi_context);
935 }
936 
937 static 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,
944         .release                = go7007_usb_release,
945 };
946 
947 static 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,
954         .release                = go7007_usb_release,
955 };
956 
957 /********************* Driver for EZ-USB I2C adapter *********************/
958 
959 static 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;
964         u8 *buf = go->usb_buf;
965         int buf_len, i;
966         int ret = -EIO;
967 
968         if (go->status == STATUS_SHUTDOWN)
969                 return -ENODEV;
970 
971         mutex_lock(&usb->i2c_lock);
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
981                         pr_debug("i2c write/read %d/%d bytes on %02x\n",
982                                 msgs[i].len, msgs[i + 1].len, msgs[i].addr);
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
992                         pr_debug("i2c read %d bytes on %02x\n",
993                                         msgs[i].len, msgs[i].addr);
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
1002                         pr_debug("i2c write %d bytes on %02x\n",
1003                                         msgs[i].len, msgs[i].addr);
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) {
1016                         memset(buf, 0, msgs[i].len + 1);
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         }
1023         ret = num;
1024 
1025 i2c_done:
1026         mutex_unlock(&usb->i2c_lock);
1027         return ret;
1028 }
1029 
1030 static 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 
1037 static struct i2c_algorithm go7007_usb_algo = {
1038         .master_xfer    = go7007_usb_i2c_master_xfer,
1039         .functionality  = go7007_usb_functionality,
1040 };
1041 
1042 static struct i2c_adapter go7007_usb_adap_templ = {
1043         .owner                  = THIS_MODULE,
1044         .name                   = "WIS GO7007SB EZ-USB",
1045         .algo                   = &go7007_usb_algo,
1046 };
1047 
1048 /********************* USB add/remove functions *********************/
1049 
1050 static 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;
1055         const struct go7007_usb_board *board;
1056         struct usb_device *usbdev = interface_to_usbdev(intf);
1057         unsigned num_i2c_devs;
1058         char *name;
1059         int video_pipe, i, v_urb_len;
1060 
1061         pr_debug("probing new GO7007 USB board\n");
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;
1096         case GO7007_BOARDID_PX_TV402U:
1097                 name = "Plextor PX-TV402U (unknown tuner)";
1098                 board = &board_px_tv402u;
1099                 break;
1100         case GO7007_BOARDID_LIFEVIEW_LR192:
1101                 dev_err(&intf->dev, "The Lifeview TV Walker Ultra is not supported. Sorry!\n");
1102                 return -ENODEV;
1103                 name = "Lifeview TV Walker Ultra";
1104                 board = &board_lifeview_lr192;
1105                 break;
1106         case GO7007_BOARDID_SENSORAY_2250:
1107                 dev_info(&intf->dev, "Sensoray 2250 found\n");
1108                 name = "Sensoray 2250/2251";
1109                 board = &board_sensoray_2250;
1110                 break;
1111         case GO7007_BOARDID_ADS_USBAV_709:
1112                 name = "ADS Tech DVD Xpress DX2";
1113                 board = &board_ads_usbav_709;
1114                 break;
1115         default:
1116                 dev_err(&intf->dev, "unknown board ID %d!\n",
1117                                 (unsigned int)id->driver_info);
1118                 return -ENODEV;
1119         }
1120 
1121         go = go7007_alloc(&board->main_info, &intf->dev);
1122         if (go == NULL)
1123                 return -ENOMEM;
1124 
1125         usb = kzalloc(sizeof(struct go7007_usb), GFP_KERNEL);
1126         if (usb == NULL) {
1127                 kfree(go);
1128                 return -ENOMEM;
1129         }
1130 
1131         usb->board = board;
1132         usb->usbdev = usbdev;
1133         usb_make_path(usbdev, go->bus_info, sizeof(go->bus_info));
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;
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 
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,
1157                         usb_rcvintpipe(usb->usbdev, 4),
1158                         usb->intr_urb->transfer_buffer, 2*sizeof(u16),
1159                         go7007_usb_readinterrupt_complete, go, 8);
1160         usb_set_intfdata(intf, &go->v4l2_dev);
1161 
1162         /* Boot the GO7007 */
1163         if (go7007_boot_encoder(go, go->board_info->flags &
1164                                         GO7007_BOARD_USE_ONBOARD_I2C) < 0)
1165                 goto allocfail;
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));
1171                 mutex_init(&usb->i2c_lock);
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) {
1175                         dev_err(go->dev, "error: i2c_add_adapter failed\n");
1176                         goto allocfail;
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",
1201                                         sizeof(go->name));
1202                         } else {
1203                                 u16 channel;
1204 
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                         }
1216                         go7007_update_board(go);
1217                 }
1218         }
1219 
1220         num_i2c_devs = go->board_info->num_i2c_devs;
1221 
1222         /* Probe the tuner model on the TV402U */
1223         if (go->board_id == GO7007_BOARDID_PX_TV402U) {
1224                 /* Board strapping indicates tuner model */
1225                 if (go7007_usb_vendor_request(go, 0x41, 0, 0, go->usb_buf, 3,
1226                                         1) < 0) {
1227                         dev_err(go->dev, "GPIO read failed!\n");
1228                         goto allocfail;
1229                 }
1230                 switch (go->usb_buf[0] >> 6) {
1231                 case 1:
1232                         go->tuner_type = TUNER_SONY_BTF_PG472Z;
1233                         go->std = V4L2_STD_PAL;
1234                         strncpy(go->name, "Plextor PX-TV402U-EU",
1235                                         sizeof(go->name));
1236                         break;
1237                 case 2:
1238                         go->tuner_type = TUNER_SONY_BTF_PK467Z;
1239                         go->std = V4L2_STD_NTSC_M_JP;
1240                         num_i2c_devs -= 2;
1241                         strncpy(go->name, "Plextor PX-TV402U-JP",
1242                                         sizeof(go->name));
1243                         break;
1244                 case 3:
1245                         go->tuner_type = TUNER_SONY_BTF_PB463Z;
1246                         num_i2c_devs -= 2;
1247                         strncpy(go->name, "Plextor PX-TV402U-NA",
1248                                         sizeof(go->name));
1249                         break;
1250                 default:
1251                         pr_debug("unable to detect tuner type!\n");
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) {
1258                         dev_err(go->dev, "GPIO write failed!\n");
1259                         goto allocfail;
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)
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");
1268 
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)
1280                         goto allocfail;
1281                 usb->video_urbs[i]->transfer_buffer =
1282                                                 kmalloc(v_urb_len, GFP_KERNEL);
1283                 if (usb->video_urbs[i]->transfer_buffer == NULL)
1284                         goto allocfail;
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 */
1291         if ((board->flags & GO7007_USB_EZUSB) &&
1292             (board->flags & GO7007_BOARD_HAS_AUDIO)) {
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)
1296                                 goto allocfail;
1297                         usb->audio_urbs[i]->transfer_buffer = kmalloc(4096,
1298                                                                 GFP_KERNEL);
1299                         if (usb->audio_urbs[i]->transfer_buffer == NULL)
1300                                 goto allocfail;
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                 }
1306         }
1307 
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;
1312 
1313         go->status = STATUS_ONLINE;
1314         return 0;
1315 
1316 allocfail:
1317         go7007_usb_release(go);
1318         kfree(go);
1319         return -ENOMEM;
1320 }
1321 
1322 static void go7007_usb_disconnect(struct usb_interface *intf)
1323 {
1324         struct go7007 *go = to_go7007(usb_get_intfdata(intf));
1325 
1326         mutex_lock(&go->queue_lock);
1327         mutex_lock(&go->serialize_lock);
1328 
1329         if (go->audio_enabled)
1330                 go7007_snd_remove(go);
1331 
1332         go->status = STATUS_SHUTDOWN;
1333         v4l2_device_disconnect(&go->v4l2_dev);
1334         video_unregister_device(&go->vdev);
1335         mutex_unlock(&go->serialize_lock);
1336         mutex_unlock(&go->queue_lock);
1337 
1338         v4l2_device_put(&go->v4l2_dev);
1339 }
1340 
1341 static 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 
1348 module_usb_driver(go7007_usb_driver);
1349 MODULE_LICENSE("GPL v2");
1350 

This page was automatically generated by LXR 0.3.1 (source).  •  Linux is a registered trademark of Linus Torvalds  •  Contact us