Merge branch 'master' of git://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux...
[linux-2.6] / drivers / media / video / em28xx / em28xx-cards.c
1 /*
2    em28xx-cards.c - driver for Empia EM2800/EM2820/2840 USB
3                     video capture devices
4
5    Copyright (C) 2005 Ludovico Cavedon <cavedon@sssup.it>
6                       Markus Rechberger <mrechberger@gmail.com>
7                       Mauro Carvalho Chehab <mchehab@infradead.org>
8                       Sascha Sommer <saschasommer@freenet.de>
9
10    This program is free software; you can redistribute it and/or modify
11    it under the terms of the GNU General Public License as published by
12    the Free Software Foundation; either version 2 of the License, or
13    (at your option) any later version.
14
15    This program is distributed in the hope that it will be useful,
16    but WITHOUT ANY WARRANTY; without even the implied warranty of
17    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18    GNU General Public License for more details.
19
20    You should have received a copy of the GNU General Public License
21    along with this program; if not, write to the Free Software
22    Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
23  */
24
25 #include <linux/init.h>
26 #include <linux/module.h>
27 #include <linux/delay.h>
28 #include <linux/i2c.h>
29 #include <linux/usb.h>
30 #include <media/tuner.h>
31 #include <media/msp3400.h>
32 #include <media/saa7115.h>
33 #include <media/tvp5150.h>
34 #include <media/tveeprom.h>
35 #include <media/v4l2-common.h>
36 #include <media/v4l2-chip-ident.h>
37
38 #include "em28xx.h"
39
40 #define DRIVER_NAME         "em28xx"
41
42 static int tuner = -1;
43 module_param(tuner, int, 0444);
44 MODULE_PARM_DESC(tuner, "tuner type");
45
46 static unsigned int disable_ir;
47 module_param(disable_ir, int, 0444);
48 MODULE_PARM_DESC(disable_ir, "disable infrared remote support");
49
50 static unsigned int card[]     = {[0 ... (EM28XX_MAXBOARDS - 1)] = UNSET };
51 module_param_array(card,  int, NULL, 0444);
52 MODULE_PARM_DESC(card,     "card type");
53
54 /* Bitmask marking allocated devices from 0 to EM28XX_MAXBOARDS */
55 static unsigned long em28xx_devused;
56
57 struct em28xx_hash_table {
58         unsigned long hash;
59         unsigned int  model;
60         unsigned int  tuner;
61 };
62
63 /*
64  *  Reset sequences for analog/digital modes
65  */
66
67 /* Reset for the most [analog] boards */
68 static struct em28xx_reg_seq default_analog[] = {
69         {EM28XX_R08_GPIO,       0x6d,   ~EM_GPIO_4,     10},
70         {       -1,             -1,     -1,             -1},
71 };
72
73 /* Reset for the most [digital] boards */
74 static struct em28xx_reg_seq default_digital[] = {
75         {EM28XX_R08_GPIO,       0x6e,   ~EM_GPIO_4,     10},
76         {       -1,             -1,     -1,             -1},
77 };
78
79 /* Board Hauppauge WinTV HVR 900 analog */
80 static struct em28xx_reg_seq hauppauge_wintv_hvr_900_analog[] = {
81         {EM28XX_R08_GPIO,       0x2d,   ~EM_GPIO_4,     10},
82         {0x05,                  0xff,   0x10,           10},
83         {  -1,                  -1,     -1,             -1},
84 };
85
86 /* Board Hauppauge WinTV HVR 900 digital */
87 static struct em28xx_reg_seq hauppauge_wintv_hvr_900_digital[] = {
88         {EM28XX_R08_GPIO,       0x2e,   ~EM_GPIO_4,     10},
89         {EM2880_R04_GPO,        0x04,   0x0f,           10},
90         {EM2880_R04_GPO,        0x0c,   0x0f,           10},
91         { -1,                   -1,     -1,             -1},
92 };
93
94 /* Boards - EM2880 MSI DIGIVOX AD and EM2880_BOARD_MSI_DIGIVOX_AD_II */
95 static struct em28xx_reg_seq em2880_msi_digivox_ad_analog[] = {
96         {EM28XX_R08_GPIO,       0x69,   ~EM_GPIO_4,      10},
97         {       -1,             -1,     -1,              -1},
98 };
99
100 /* Boards - EM2880 MSI DIGIVOX AD and EM2880_BOARD_MSI_DIGIVOX_AD_II */
101
102 /* Board  - EM2870 Kworld 355u
103    Analog - No input analog */
104
105 /* Callback for the most boards */
106 static struct em28xx_reg_seq default_tuner_gpio[] = {
107         {EM28XX_R08_GPIO,       EM_GPIO_4,      EM_GPIO_4,      10},
108         {EM28XX_R08_GPIO,       0,              EM_GPIO_4,      10},
109         {EM28XX_R08_GPIO,       EM_GPIO_4,      EM_GPIO_4,      10},
110         {  -1,                  -1,             -1,             -1},
111 };
112
113 /*
114  *  Board definitions
115  */
116 struct em28xx_board em28xx_boards[] = {
117         [EM2750_BOARD_UNKNOWN] = {
118                 .name          = "Unknown EM2750/EM2751 webcam grabber",
119                 .xclk          = EM28XX_XCLK_FREQUENCY_48MHZ,
120                 .tuner_type    = TUNER_ABSENT,  /* This is a webcam */
121                 .input         = { {
122                         .type     = EM28XX_VMUX_COMPOSITE1,
123                         .vmux     = 0,
124                         .amux     = EM28XX_AMUX_VIDEO,
125                 } },
126         },
127         [EM2800_BOARD_UNKNOWN] = {
128                 .name         = "Unknown EM2800 video grabber",
129                 .is_em2800    = 1,
130                 .tda9887_conf = TDA9887_PRESENT,
131                 .decoder      = EM28XX_SAA711X,
132                 .tuner_type   = TUNER_ABSENT,
133                 .input        = { {
134                         .type     = EM28XX_VMUX_COMPOSITE1,
135                         .vmux     = SAA7115_COMPOSITE0,
136                         .amux     = EM28XX_AMUX_LINE_IN,
137                 }, {
138                         .type     = EM28XX_VMUX_SVIDEO,
139                         .vmux     = SAA7115_SVIDEO3,
140                         .amux     = EM28XX_AMUX_LINE_IN,
141                 } },
142         },
143         [EM2820_BOARD_UNKNOWN] = {
144                 .name          = "Unknown EM2750/28xx video grabber",
145                 .tuner_type    = TUNER_ABSENT,
146         },
147         [EM2750_BOARD_DLCW_130] = {
148                 /* Beijing Huaqi Information Digital Technology Co., Ltd */
149                 .name          = "Huaqi DLCW-130",
150                 .valid         = EM28XX_BOARD_NOT_VALIDATED,
151                 .xclk          = EM28XX_XCLK_FREQUENCY_48MHZ,
152                 .tuner_type    = TUNER_ABSENT,  /* This is a webcam */
153                 .input         = { {
154                         .type     = EM28XX_VMUX_COMPOSITE1,
155                         .vmux     = 0,
156                         .amux     = EM28XX_AMUX_VIDEO,
157                 } },
158         },
159         [EM2820_BOARD_KWORLD_PVRTV2800RF] = {
160                 .name         = "Kworld PVR TV 2800 RF",
161                 .tuner_type   = TUNER_TEMIC_PAL,
162                 .tda9887_conf = TDA9887_PRESENT,
163                 .decoder      = EM28XX_SAA711X,
164                 .input        = { {
165                         .type     = EM28XX_VMUX_COMPOSITE1,
166                         .vmux     = SAA7115_COMPOSITE0,
167                         .amux     = EM28XX_AMUX_LINE_IN,
168                 }, {
169                         .type     = EM28XX_VMUX_SVIDEO,
170                         .vmux     = SAA7115_SVIDEO3,
171                         .amux     = EM28XX_AMUX_LINE_IN,
172                 } },
173         },
174         [EM2820_BOARD_TERRATEC_CINERGY_250] = {
175                 .name         = "Terratec Cinergy 250 USB",
176                 .tuner_type   = TUNER_LG_PAL_NEW_TAPC,
177                 .tda9887_conf = TDA9887_PRESENT,
178                 .decoder      = EM28XX_SAA711X,
179                 .input        = { {
180                         .type     = EM28XX_VMUX_TELEVISION,
181                         .vmux     = SAA7115_COMPOSITE2,
182                         .amux     = EM28XX_AMUX_LINE_IN,
183                 }, {
184                         .type     = EM28XX_VMUX_COMPOSITE1,
185                         .vmux     = SAA7115_COMPOSITE0,
186                         .amux     = EM28XX_AMUX_LINE_IN,
187                 }, {
188                         .type     = EM28XX_VMUX_SVIDEO,
189                         .vmux     = SAA7115_SVIDEO3,
190                         .amux     = EM28XX_AMUX_LINE_IN,
191                 } },
192         },
193         [EM2820_BOARD_PINNACLE_USB_2] = {
194                 .name         = "Pinnacle PCTV USB 2",
195                 .tuner_type   = TUNER_LG_PAL_NEW_TAPC,
196                 .tda9887_conf = TDA9887_PRESENT,
197                 .decoder      = EM28XX_SAA711X,
198                 .input        = { {
199                         .type     = EM28XX_VMUX_TELEVISION,
200                         .vmux     = SAA7115_COMPOSITE2,
201                         .amux     = EM28XX_AMUX_VIDEO,
202                 }, {
203                         .type     = EM28XX_VMUX_COMPOSITE1,
204                         .vmux     = SAA7115_COMPOSITE0,
205                         .amux     = EM28XX_AMUX_LINE_IN,
206                 }, {
207                         .type     = EM28XX_VMUX_SVIDEO,
208                         .vmux     = SAA7115_SVIDEO3,
209                         .amux     = EM28XX_AMUX_LINE_IN,
210                 } },
211         },
212         [EM2820_BOARD_HAUPPAUGE_WINTV_USB_2] = {
213                 .name         = "Hauppauge WinTV USB 2",
214                 .tuner_type   = TUNER_PHILIPS_FM1236_MK3,
215                 .tda9887_conf = TDA9887_PRESENT |
216                                 TDA9887_PORT1_ACTIVE|
217                                 TDA9887_PORT2_ACTIVE,
218                 .decoder      = EM28XX_TVP5150,
219                 .has_msp34xx  = 1,
220                 .input        = { {
221                         .type     = EM28XX_VMUX_TELEVISION,
222                         .vmux     = TVP5150_COMPOSITE0,
223                         .amux     = MSP_INPUT_DEFAULT,
224                 }, {
225                         .type     = EM28XX_VMUX_SVIDEO,
226                         .vmux     = TVP5150_SVIDEO,
227                         .amux     = MSP_INPUT(MSP_IN_SCART1, MSP_IN_TUNER1,
228                                         MSP_DSP_IN_SCART, MSP_DSP_IN_SCART),
229                 } },
230         },
231         [EM2820_BOARD_DLINK_USB_TV] = {
232                 .name         = "D-Link DUB-T210 TV Tuner",
233                 .valid        = EM28XX_BOARD_NOT_VALIDATED,
234                 .tuner_type   = TUNER_LG_PAL_NEW_TAPC,
235                 .tda9887_conf = TDA9887_PRESENT,
236                 .decoder      = EM28XX_SAA711X,
237                 .input        = { {
238                         .type     = EM28XX_VMUX_TELEVISION,
239                         .vmux     = SAA7115_COMPOSITE2,
240                         .amux     = EM28XX_AMUX_LINE_IN,
241                 }, {
242                         .type     = EM28XX_VMUX_COMPOSITE1,
243                         .vmux     = SAA7115_COMPOSITE0,
244                         .amux     = EM28XX_AMUX_LINE_IN,
245                 }, {
246                         .type     = EM28XX_VMUX_SVIDEO,
247                         .vmux     = SAA7115_SVIDEO3,
248                         .amux     = EM28XX_AMUX_LINE_IN,
249                 } },
250         },
251         [EM2820_BOARD_HERCULES_SMART_TV_USB2] = {
252                 .name         = "Hercules Smart TV USB 2.0",
253                 .valid        = EM28XX_BOARD_NOT_VALIDATED,
254                 .tuner_type   = TUNER_LG_PAL_NEW_TAPC,
255                 .tda9887_conf = TDA9887_PRESENT,
256                 .decoder      = EM28XX_SAA711X,
257                 .input        = { {
258                         .type     = EM28XX_VMUX_TELEVISION,
259                         .vmux     = SAA7115_COMPOSITE2,
260                         .amux     = EM28XX_AMUX_LINE_IN,
261                 }, {
262                         .type     = EM28XX_VMUX_COMPOSITE1,
263                         .vmux     = SAA7115_COMPOSITE0,
264                         .amux     = EM28XX_AMUX_LINE_IN,
265                 }, {
266                         .type     = EM28XX_VMUX_SVIDEO,
267                         .vmux     = SAA7115_SVIDEO3,
268                         .amux     = EM28XX_AMUX_LINE_IN,
269                 } },
270         },
271         [EM2820_BOARD_PINNACLE_USB_2_FM1216ME] = {
272                 .name         = "Pinnacle PCTV USB 2 (Philips FM1216ME)",
273                 .valid        = EM28XX_BOARD_NOT_VALIDATED,
274                 .tuner_type   = TUNER_PHILIPS_FM1216ME_MK3,
275                 .tda9887_conf = TDA9887_PRESENT,
276                 .decoder      = EM28XX_SAA711X,
277                 .input        = { {
278                         .type     = EM28XX_VMUX_TELEVISION,
279                         .vmux     = SAA7115_COMPOSITE2,
280                         .amux     = EM28XX_AMUX_VIDEO,
281                 }, {
282                         .type     = EM28XX_VMUX_COMPOSITE1,
283                         .vmux     = SAA7115_COMPOSITE0,
284                         .amux     = EM28XX_AMUX_LINE_IN,
285                 }, {
286                         .type     = EM28XX_VMUX_SVIDEO,
287                         .vmux     = SAA7115_SVIDEO3,
288                         .amux     = EM28XX_AMUX_LINE_IN,
289                 } },
290         },
291         [EM2820_BOARD_GADMEI_UTV310] = {
292                 .name         = "Gadmei UTV310",
293                 .valid        = EM28XX_BOARD_NOT_VALIDATED,
294                 .tuner_type   = TUNER_TNF_5335MF,
295                 .tda9887_conf = TDA9887_PRESENT,
296                 .decoder      = EM28XX_SAA711X,
297                 .input        = { {
298                         .type     = EM28XX_VMUX_TELEVISION,
299                         .vmux     = SAA7115_COMPOSITE1,
300                         .amux     = EM28XX_AMUX_LINE_IN,
301                 }, {
302                         .type     = EM28XX_VMUX_COMPOSITE1,
303                         .vmux     = SAA7115_COMPOSITE0,
304                         .amux     = EM28XX_AMUX_LINE_IN,
305                 }, {
306                         .type     = EM28XX_VMUX_SVIDEO,
307                         .vmux     = SAA7115_SVIDEO3,
308                         .amux     = EM28XX_AMUX_LINE_IN,
309                 } },
310         },
311         [EM2820_BOARD_LEADTEK_WINFAST_USBII_DELUXE] = {
312                 .name         = "Leadtek Winfast USB II Deluxe",
313                 .valid        = EM28XX_BOARD_NOT_VALIDATED,
314                 .tuner_type   = TUNER_PHILIPS_FM1216ME_MK3,
315                 .tda9887_conf = TDA9887_PRESENT,
316                 .decoder      = EM28XX_SAA711X,
317                 .input        = { {
318                         .type     = EM28XX_VMUX_TELEVISION,
319                         .vmux     = SAA7115_COMPOSITE2,
320                         .amux     = EM28XX_AMUX_VIDEO,
321                 }, {
322                         .type     = EM28XX_VMUX_COMPOSITE1,
323                         .vmux     = SAA7115_COMPOSITE0,
324                         .amux     = EM28XX_AMUX_LINE_IN,
325                 }, {
326                         .type     = EM28XX_VMUX_SVIDEO,
327                         .vmux     = SAA7115_COMPOSITE0,
328                         .amux     = EM28XX_AMUX_LINE_IN,
329                 } },
330         },
331         [EM2820_BOARD_VIDEOLOGY_20K14XUSB] = {
332                 .name         = "Videology 20K14XUSB USB2.0",
333                 .valid        = EM28XX_BOARD_NOT_VALIDATED,
334                 .tuner_type   = TUNER_ABSENT,   /* This is a webcam */
335                 .input        = { {
336                         .type     = EM28XX_VMUX_COMPOSITE1,
337                         .vmux     = 0,
338                         .amux     = EM28XX_AMUX_VIDEO,
339                 } },
340         },
341         [EM2821_BOARD_PROLINK_PLAYTV_USB2] = {
342                 .name         = "SIIG AVTuner-PVR/Prolink PlayTV USB 2.0",
343                 .valid        = EM28XX_BOARD_NOT_VALIDATED,
344                 .tuner_type   = TUNER_LG_PAL_NEW_TAPC,  /* unknown? */
345                 .tda9887_conf = TDA9887_PRESENT,        /* unknown? */
346                 .decoder      = EM28XX_SAA711X,
347                 .input        = { {
348                         .type     = EM28XX_VMUX_TELEVISION,
349                         .vmux     = SAA7115_COMPOSITE2,
350                         .amux     = EM28XX_AMUX_LINE_IN,
351                 }, {
352                         .type     = EM28XX_VMUX_COMPOSITE1,
353                         .vmux     = SAA7115_COMPOSITE0,
354                         .amux     = EM28XX_AMUX_LINE_IN,
355                 }, {
356                         .type     = EM28XX_VMUX_SVIDEO,
357                         .vmux     = SAA7115_SVIDEO3,
358                         .amux     = EM28XX_AMUX_LINE_IN,
359                 } },
360         },
361         [EM2821_BOARD_SUPERCOMP_USB_2] = {
362                 .name         = "Supercomp USB 2.0 TV",
363                 .valid        = EM28XX_BOARD_NOT_VALIDATED,
364                 .tuner_type   = TUNER_PHILIPS_FM1236_MK3,
365                 .tda9887_conf = TDA9887_PRESENT |
366                                 TDA9887_PORT1_ACTIVE |
367                                 TDA9887_PORT2_ACTIVE,
368                 .decoder      = EM28XX_SAA711X,
369                 .input        = { {
370                         .type     = EM28XX_VMUX_TELEVISION,
371                         .vmux     = SAA7115_COMPOSITE2,
372                         .amux     = EM28XX_AMUX_LINE_IN,
373                 }, {
374                         .type     = EM28XX_VMUX_COMPOSITE1,
375                         .vmux     = SAA7115_COMPOSITE0,
376                         .amux     = EM28XX_AMUX_VIDEO,
377                 }, {
378                         .type     = EM28XX_VMUX_SVIDEO,
379                         .vmux     = SAA7115_SVIDEO3,
380                         .amux     = EM28XX_AMUX_LINE_IN,
381                 } },
382         },
383         [EM2821_BOARD_USBGEAR_VD204] = {
384                 .name         = "Usbgear VD204v9",
385                 .valid        = EM28XX_BOARD_NOT_VALIDATED,
386                 .tuner_type   = TUNER_ABSENT,   /* Capture only device */
387                 .decoder      = EM28XX_SAA711X,
388                 .input        = { {
389                         .type  = EM28XX_VMUX_COMPOSITE1,
390                         .vmux  = SAA7115_COMPOSITE0,
391                         .amux  = EM28XX_AMUX_LINE_IN,
392                 }, {
393                         .type  = EM28XX_VMUX_SVIDEO,
394                         .vmux  = SAA7115_SVIDEO3,
395                         .amux  = EM28XX_AMUX_LINE_IN,
396                 } },
397         },
398         [EM2860_BOARD_NETGMBH_CAM] = {
399                 /* Beijing Huaqi Information Digital Technology Co., Ltd */
400                 .name         = "NetGMBH Cam",
401                 .valid        = EM28XX_BOARD_NOT_VALIDATED,
402                 .tuner_type   = TUNER_ABSENT,   /* This is a webcam */
403                 .input        = { {
404                         .type     = EM28XX_VMUX_COMPOSITE1,
405                         .vmux     = 0,
406                         .amux     = EM28XX_AMUX_VIDEO,
407                 } },
408         },
409         [EM2860_BOARD_TYPHOON_DVD_MAKER] = {
410                 .name         = "Typhoon DVD Maker",
411                 .decoder      = EM28XX_SAA711X,
412                 .tuner_type   = TUNER_ABSENT,   /* Capture only device */
413                 .input        = { {
414                         .type  = EM28XX_VMUX_COMPOSITE1,
415                         .vmux  = SAA7115_COMPOSITE0,
416                         .amux  = EM28XX_AMUX_LINE_IN,
417                 }, {
418                         .type  = EM28XX_VMUX_SVIDEO,
419                         .vmux  = SAA7115_SVIDEO3,
420                         .amux  = EM28XX_AMUX_LINE_IN,
421                 } },
422         },
423         [EM2860_BOARD_GADMEI_UTV330] = {
424                 .name         = "Gadmei UTV330",
425                 .valid        = EM28XX_BOARD_NOT_VALIDATED,
426                 .tuner_type   = TUNER_TNF_5335MF,
427                 .tda9887_conf = TDA9887_PRESENT,
428                 .decoder      = EM28XX_SAA711X,
429                 .input        = { {
430                         .type     = EM28XX_VMUX_TELEVISION,
431                         .vmux     = SAA7115_COMPOSITE2,
432                         .amux     = EM28XX_AMUX_VIDEO,
433                 }, {
434                         .type     = EM28XX_VMUX_COMPOSITE1,
435                         .vmux     = SAA7115_COMPOSITE0,
436                         .amux     = EM28XX_AMUX_LINE_IN,
437                 }, {
438                         .type     = EM28XX_VMUX_SVIDEO,
439                         .vmux     = SAA7115_SVIDEO3,
440                         .amux     = EM28XX_AMUX_LINE_IN,
441                 } },
442         },
443         [EM2860_BOARD_TERRATEC_HYBRID_XS] = {
444                 .name         = "Terratec Cinergy A Hybrid XS",
445                 .valid        = EM28XX_BOARD_NOT_VALIDATED,
446                 .tuner_type   = TUNER_XC2028,
447                 .tuner_gpio   = default_tuner_gpio,
448                 .decoder      = EM28XX_TVP5150,
449
450                 .input        = { {
451                         .type     = EM28XX_VMUX_TELEVISION,
452                         .vmux     = TVP5150_COMPOSITE0,
453                         .amux     = EM28XX_AMUX_VIDEO,
454                         .gpio     = hauppauge_wintv_hvr_900_analog,
455                 }, {
456                         .type     = EM28XX_VMUX_COMPOSITE1,
457                         .vmux     = TVP5150_COMPOSITE1,
458                         .amux     = EM28XX_AMUX_LINE_IN,
459                         .gpio     = hauppauge_wintv_hvr_900_analog,
460                 }, {
461                         .type     = EM28XX_VMUX_SVIDEO,
462                         .vmux     = TVP5150_SVIDEO,
463                         .amux     = EM28XX_AMUX_LINE_IN,
464                         .gpio     = hauppauge_wintv_hvr_900_analog,
465                 } },
466         },
467         [EM2861_BOARD_KWORLD_PVRTV_300U] = {
468                 .name         = "KWorld PVRTV 300U",
469                 .valid        = EM28XX_BOARD_NOT_VALIDATED,
470                 .tuner_type   = TUNER_XC2028,
471                 .tuner_gpio   = default_tuner_gpio,
472                 .decoder      = EM28XX_TVP5150,
473                 .input        = { {
474                         .type     = EM28XX_VMUX_TELEVISION,
475                         .vmux     = TVP5150_COMPOSITE0,
476                         .amux     = EM28XX_AMUX_VIDEO,
477                 }, {
478                         .type     = EM28XX_VMUX_COMPOSITE1,
479                         .vmux     = TVP5150_COMPOSITE1,
480                         .amux     = EM28XX_AMUX_LINE_IN,
481                 }, {
482                         .type     = EM28XX_VMUX_SVIDEO,
483                         .vmux     = TVP5150_SVIDEO,
484                         .amux     = EM28XX_AMUX_LINE_IN,
485                 } },
486         },
487         [EM2861_BOARD_YAKUMO_MOVIE_MIXER] = {
488                 .name          = "Yakumo MovieMixer",
489                 .tuner_type   = TUNER_ABSENT,   /* Capture only device */
490                 .decoder       = EM28XX_TVP5150,
491                 .input         = { {
492                         .type     = EM28XX_VMUX_TELEVISION,
493                         .vmux     = TVP5150_COMPOSITE0,
494                         .amux     = EM28XX_AMUX_VIDEO,
495                 }, {
496                         .type     = EM28XX_VMUX_COMPOSITE1,
497                         .vmux     = TVP5150_COMPOSITE1,
498                         .amux     = EM28XX_AMUX_LINE_IN,
499                 }, {
500                         .type     = EM28XX_VMUX_SVIDEO,
501                         .vmux     = TVP5150_SVIDEO,
502                         .amux     = EM28XX_AMUX_LINE_IN,
503                 } },
504         },
505         [EM2861_BOARD_PLEXTOR_PX_TV100U] = {
506                 .name         = "Plextor ConvertX PX-TV100U",
507                 .valid        = EM28XX_BOARD_NOT_VALIDATED,
508                 .tuner_type   = TUNER_TNF_5335MF,
509                 .tda9887_conf = TDA9887_PRESENT,
510                 .decoder      = EM28XX_TVP5150,
511                 .input        = { {
512                         .type     = EM28XX_VMUX_TELEVISION,
513                         .vmux     = TVP5150_COMPOSITE0,
514                         .amux     = EM28XX_AMUX_LINE_IN,
515                 }, {
516                         .type     = EM28XX_VMUX_COMPOSITE1,
517                         .vmux     = TVP5150_COMPOSITE1,
518                         .amux     = EM28XX_AMUX_LINE_IN,
519                 }, {
520                         .type     = EM28XX_VMUX_SVIDEO,
521                         .vmux     = TVP5150_SVIDEO,
522                         .amux     = EM28XX_AMUX_LINE_IN,
523                 } },
524         },
525
526         /* Those boards with em2870 are DVB Only*/
527
528         [EM2870_BOARD_TERRATEC_XS] = {
529                 .name         = "Terratec Cinergy T XS",
530                 .valid        = EM28XX_BOARD_NOT_VALIDATED,
531                 .tuner_type   = TUNER_XC2028,
532                 .tuner_gpio   = default_tuner_gpio,
533         },
534         [EM2870_BOARD_TERRATEC_XS_MT2060] = {
535                 .name         = "Terratec Cinergy T XS (MT2060)",
536                 .valid        = EM28XX_BOARD_NOT_VALIDATED,
537                 .tuner_type   = TUNER_ABSENT, /* MT2060 */
538         },
539         [EM2870_BOARD_KWORLD_350U] = {
540                 .name         = "Kworld 350 U DVB-T",
541                 .valid        = EM28XX_BOARD_NOT_VALIDATED,
542                 .tuner_type   = TUNER_XC2028,
543                 .tuner_gpio   = default_tuner_gpio,
544         },
545         [EM2870_BOARD_KWORLD_355U] = {
546                 .name         = "Kworld 355 U DVB-T",
547                 .valid        = EM28XX_BOARD_NOT_VALIDATED,
548         },
549         [EM2870_BOARD_PINNACLE_PCTV_DVB] = {
550                 .name         = "Pinnacle PCTV DVB-T",
551                 .valid        = EM28XX_BOARD_NOT_VALIDATED,
552                 .tuner_type   = TUNER_ABSENT, /* MT2060 */
553                 /* djh - I have serious doubts this is right... */
554                 .xclk         = EM28XX_XCLK_IR_RC5_MODE |
555                                 EM28XX_XCLK_FREQUENCY_10MHZ,
556         },
557         [EM2870_BOARD_COMPRO_VIDEOMATE] = {
558                 .name         = "Compro, VideoMate U3",
559                 .valid        = EM28XX_BOARD_NOT_VALIDATED,
560                 .tuner_type   = TUNER_ABSENT, /* MT2060 */
561         },
562
563         [EM2880_BOARD_TERRATEC_HYBRID_XS_FR] = {
564                 .name         = "Terratec Hybrid XS Secam",
565                 .valid        = EM28XX_BOARD_NOT_VALIDATED,
566                 .has_msp34xx  = 1,
567                 .tuner_type   = TUNER_XC2028,
568                 .tuner_gpio   = default_tuner_gpio,
569                 .decoder      = EM28XX_TVP5150,
570                 .input        = { {
571                         .type     = EM28XX_VMUX_TELEVISION,
572                         .vmux     = TVP5150_COMPOSITE0,
573                         .amux     = EM28XX_AMUX_VIDEO,
574                         .gpio     = default_analog,
575                 }, {
576                         .type     = EM28XX_VMUX_COMPOSITE1,
577                         .vmux     = TVP5150_COMPOSITE1,
578                         .amux     = EM28XX_AMUX_LINE_IN,
579                         .gpio     = default_analog,
580                 }, {
581                         .type     = EM28XX_VMUX_SVIDEO,
582                         .vmux     = TVP5150_SVIDEO,
583                         .amux     = EM28XX_AMUX_LINE_IN,
584                         .gpio     = default_analog,
585                 } },
586         },
587         [EM2880_BOARD_HAUPPAUGE_WINTV_HVR_900] = {
588                 .name         = "Hauppauge WinTV HVR 900",
589                 .tda9887_conf = TDA9887_PRESENT,
590                 .tuner_type   = TUNER_XC2028,
591                 .tuner_gpio   = default_tuner_gpio,
592                 .mts_firmware = 1,
593                 .has_dvb      = 1,
594                 .dvb_gpio     = hauppauge_wintv_hvr_900_digital,
595                 .decoder      = EM28XX_TVP5150,
596                 .input        = { {
597                         .type     = EM28XX_VMUX_TELEVISION,
598                         .vmux     = TVP5150_COMPOSITE0,
599                         .amux     = EM28XX_AMUX_VIDEO,
600                         .gpio     = hauppauge_wintv_hvr_900_analog,
601                 }, {
602                         .type     = EM28XX_VMUX_COMPOSITE1,
603                         .vmux     = TVP5150_COMPOSITE1,
604                         .amux     = EM28XX_AMUX_LINE_IN,
605                         .gpio     = hauppauge_wintv_hvr_900_analog,
606                 }, {
607                         .type     = EM28XX_VMUX_SVIDEO,
608                         .vmux     = TVP5150_SVIDEO,
609                         .amux     = EM28XX_AMUX_LINE_IN,
610                         .gpio     = hauppauge_wintv_hvr_900_analog,
611                 } },
612         },
613         [EM2880_BOARD_HAUPPAUGE_WINTV_HVR_900_R2] = {
614                 .name         = "Hauppauge WinTV HVR 900 (R2)",
615                 .tda9887_conf = TDA9887_PRESENT,
616                 .tuner_type   = TUNER_XC2028,
617                 .tuner_gpio   = default_tuner_gpio,
618                 .mts_firmware = 1,
619                 .decoder      = EM28XX_TVP5150,
620                 .input        = { {
621                         .type     = EM28XX_VMUX_TELEVISION,
622                         .vmux     = TVP5150_COMPOSITE0,
623                         .amux     = EM28XX_AMUX_VIDEO,
624                         .gpio     = hauppauge_wintv_hvr_900_analog,
625                 }, {
626                         .type     = EM28XX_VMUX_COMPOSITE1,
627                         .vmux     = TVP5150_COMPOSITE1,
628                         .amux     = EM28XX_AMUX_LINE_IN,
629                         .gpio     = hauppauge_wintv_hvr_900_analog,
630                 }, {
631                         .type     = EM28XX_VMUX_SVIDEO,
632                         .vmux     = TVP5150_SVIDEO,
633                         .amux     = EM28XX_AMUX_LINE_IN,
634                         .gpio     = hauppauge_wintv_hvr_900_analog,
635                 } },
636         },
637         [EM2883_BOARD_HAUPPAUGE_WINTV_HVR_850] = {
638                 .name           = "Hauppauge WinTV HVR 850",
639                 .tuner_type     = TUNER_XC2028,
640                 .tuner_gpio     = default_tuner_gpio,
641                 .mts_firmware   = 1,
642                 .has_dvb        = 1,
643                 .dvb_gpio       = hauppauge_wintv_hvr_900_digital,
644                 .ir_codes       = ir_codes_hauppauge_new,
645                 .decoder        = EM28XX_TVP5150,
646                 .input          = { {
647                         .type     = EM28XX_VMUX_TELEVISION,
648                         .vmux     = TVP5150_COMPOSITE0,
649                         .amux     = EM28XX_AMUX_VIDEO,
650                         .gpio     = hauppauge_wintv_hvr_900_analog,
651                 }, {
652                         .type     = EM28XX_VMUX_COMPOSITE1,
653                         .vmux     = TVP5150_COMPOSITE1,
654                         .amux     = EM28XX_AMUX_LINE_IN,
655                         .gpio     = hauppauge_wintv_hvr_900_analog,
656                 }, {
657                         .type     = EM28XX_VMUX_SVIDEO,
658                         .vmux     = TVP5150_SVIDEO,
659                         .amux     = EM28XX_AMUX_LINE_IN,
660                         .gpio     = hauppauge_wintv_hvr_900_analog,
661                 } },
662         },
663         [EM2883_BOARD_HAUPPAUGE_WINTV_HVR_950] = {
664                 .name           = "Hauppauge WinTV HVR 950",
665                 .tuner_type     = TUNER_XC2028,
666                 .tuner_gpio     = default_tuner_gpio,
667                 .mts_firmware   = 1,
668                 .has_dvb        = 1,
669                 .dvb_gpio       = hauppauge_wintv_hvr_900_digital,
670                 .ir_codes       = ir_codes_hauppauge_new,
671                 .decoder        = EM28XX_TVP5150,
672                 .input          = { {
673                         .type     = EM28XX_VMUX_TELEVISION,
674                         .vmux     = TVP5150_COMPOSITE0,
675                         .amux     = EM28XX_AMUX_VIDEO,
676                         .gpio     = hauppauge_wintv_hvr_900_analog,
677                 }, {
678                         .type     = EM28XX_VMUX_COMPOSITE1,
679                         .vmux     = TVP5150_COMPOSITE1,
680                         .amux     = EM28XX_AMUX_LINE_IN,
681                         .gpio     = hauppauge_wintv_hvr_900_analog,
682                 }, {
683                         .type     = EM28XX_VMUX_SVIDEO,
684                         .vmux     = TVP5150_SVIDEO,
685                         .amux     = EM28XX_AMUX_LINE_IN,
686                         .gpio     = hauppauge_wintv_hvr_900_analog,
687                 } },
688         },
689         [EM2880_BOARD_PINNACLE_PCTV_HD_PRO] = {
690                 .name           = "Pinnacle PCTV HD Pro Stick",
691                 .tuner_type     = TUNER_XC2028,
692                 .tuner_gpio   = default_tuner_gpio,
693                 .mts_firmware   = 1,
694                 .has_dvb        = 1,
695                 .dvb_gpio       = hauppauge_wintv_hvr_900_digital,
696                 .ir_codes       = ir_codes_pinnacle_pctv_hd,
697                 .decoder        = EM28XX_TVP5150,
698                 .input          = { {
699                         .type     = EM28XX_VMUX_TELEVISION,
700                         .vmux     = TVP5150_COMPOSITE0,
701                         .amux     = EM28XX_AMUX_VIDEO,
702                         .gpio     = hauppauge_wintv_hvr_900_analog,
703                 }, {
704                         .type     = EM28XX_VMUX_COMPOSITE1,
705                         .vmux     = TVP5150_COMPOSITE1,
706                         .amux     = EM28XX_AMUX_LINE_IN,
707                         .gpio     = hauppauge_wintv_hvr_900_analog,
708                 }, {
709                         .type     = EM28XX_VMUX_SVIDEO,
710                         .vmux     = TVP5150_SVIDEO,
711                         .amux     = EM28XX_AMUX_LINE_IN,
712                         .gpio     = hauppauge_wintv_hvr_900_analog,
713                 } },
714         },
715         [EM2880_BOARD_AMD_ATI_TV_WONDER_HD_600] = {
716                 .name           = "AMD ATI TV Wonder HD 600",
717                 .tuner_type     = TUNER_XC2028,
718                 .tuner_gpio     = default_tuner_gpio,
719                 .mts_firmware   = 1,
720                 .has_dvb        = 1,
721                 .dvb_gpio       = hauppauge_wintv_hvr_900_digital,
722                 .ir_codes       = ir_codes_ati_tv_wonder_hd_600,
723                 .decoder        = EM28XX_TVP5150,
724                 .input          = { {
725                         .type     = EM28XX_VMUX_TELEVISION,
726                         .vmux     = TVP5150_COMPOSITE0,
727                         .amux     = EM28XX_AMUX_VIDEO,
728                         .gpio     = hauppauge_wintv_hvr_900_analog,
729                 }, {
730                         .type     = EM28XX_VMUX_COMPOSITE1,
731                         .vmux     = TVP5150_COMPOSITE1,
732                         .amux     = EM28XX_AMUX_LINE_IN,
733                         .gpio     = hauppauge_wintv_hvr_900_analog,
734                 }, {
735                         .type     = EM28XX_VMUX_SVIDEO,
736                         .vmux     = TVP5150_SVIDEO,
737                         .amux     = EM28XX_AMUX_LINE_IN,
738                         .gpio     = hauppauge_wintv_hvr_900_analog,
739                 } },
740         },
741         [EM2880_BOARD_TERRATEC_HYBRID_XS] = {
742                 .name           = "Terratec Hybrid XS",
743                 .tuner_type     = TUNER_XC2028,
744                 .tuner_gpio     = default_tuner_gpio,
745                 .decoder        = EM28XX_TVP5150,
746                 .has_dvb        = 1,
747                 .dvb_gpio       = default_analog,
748                 .input          = { {
749                         .type     = EM28XX_VMUX_TELEVISION,
750                         .vmux     = TVP5150_COMPOSITE0,
751                         .amux     = EM28XX_AMUX_VIDEO,
752                         .gpio     = default_analog,
753                 }, {
754                         .type     = EM28XX_VMUX_COMPOSITE1,
755                         .vmux     = TVP5150_COMPOSITE1,
756                         .amux     = EM28XX_AMUX_LINE_IN,
757                         .gpio     = default_analog,
758                 }, {
759                         .type     = EM28XX_VMUX_SVIDEO,
760                         .vmux     = TVP5150_SVIDEO,
761                         .amux     = EM28XX_AMUX_LINE_IN,
762                         .gpio     = default_analog,
763                 } },
764         },
765         /* maybe there's a reason behind it why Terratec sells the Hybrid XS
766            as Prodigy XS with a different PID, let's keep it separated for now
767            maybe we'll need it lateron */
768         [EM2880_BOARD_TERRATEC_PRODIGY_XS] = {
769                 .name         = "Terratec Prodigy XS",
770                 .tuner_type   = TUNER_XC2028,
771                 .tuner_gpio   = default_tuner_gpio,
772                 .decoder      = EM28XX_TVP5150,
773                 .input        = { {
774                         .type     = EM28XX_VMUX_TELEVISION,
775                         .vmux     = TVP5150_COMPOSITE0,
776                         .amux     = EM28XX_AMUX_VIDEO,
777                         .gpio     = hauppauge_wintv_hvr_900_analog,
778                 }, {
779                         .type     = EM28XX_VMUX_COMPOSITE1,
780                         .vmux     = TVP5150_COMPOSITE1,
781                         .amux     = EM28XX_AMUX_LINE_IN,
782                         .gpio     = hauppauge_wintv_hvr_900_analog,
783                 }, {
784                         .type     = EM28XX_VMUX_SVIDEO,
785                         .vmux     = TVP5150_SVIDEO,
786                         .amux     = EM28XX_AMUX_LINE_IN,
787                         .gpio     = hauppauge_wintv_hvr_900_analog,
788                 } },
789         },
790         [EM2820_BOARD_MSI_VOX_USB_2] = {
791                 .name              = "MSI VOX USB 2.0",
792                 .tuner_type        = TUNER_LG_PAL_NEW_TAPC,
793                 .tda9887_conf      = TDA9887_PRESENT      |
794                                      TDA9887_PORT1_ACTIVE |
795                                      TDA9887_PORT2_ACTIVE,
796                 .max_range_640_480 = 1,
797                 .decoder           = EM28XX_SAA711X,
798                 .input             = { {
799                         .type      = EM28XX_VMUX_TELEVISION,
800                         .vmux      = SAA7115_COMPOSITE4,
801                         .amux      = EM28XX_AMUX_VIDEO,
802                 }, {
803                         .type      = EM28XX_VMUX_COMPOSITE1,
804                         .vmux      = SAA7115_COMPOSITE0,
805                         .amux      = EM28XX_AMUX_LINE_IN,
806                 }, {
807                         .type      = EM28XX_VMUX_SVIDEO,
808                         .vmux      = SAA7115_SVIDEO3,
809                         .amux      = EM28XX_AMUX_LINE_IN,
810                 } },
811         },
812         [EM2800_BOARD_TERRATEC_CINERGY_200] = {
813                 .name         = "Terratec Cinergy 200 USB",
814                 .is_em2800    = 1,
815                 .tuner_type   = TUNER_LG_PAL_NEW_TAPC,
816                 .tda9887_conf = TDA9887_PRESENT,
817                 .decoder      = EM28XX_SAA711X,
818                 .input        = { {
819                         .type     = EM28XX_VMUX_TELEVISION,
820                         .vmux     = SAA7115_COMPOSITE2,
821                         .amux     = EM28XX_AMUX_VIDEO,
822                 }, {
823                         .type     = EM28XX_VMUX_COMPOSITE1,
824                         .vmux     = SAA7115_COMPOSITE0,
825                         .amux     = EM28XX_AMUX_LINE_IN,
826                 }, {
827                         .type     = EM28XX_VMUX_SVIDEO,
828                         .vmux     = SAA7115_SVIDEO3,
829                         .amux     = EM28XX_AMUX_LINE_IN,
830                 } },
831         },
832         [EM2800_BOARD_GRABBEEX_USB2800] = {
833                 .name         = "eMPIA Technology, Inc. GrabBeeX+ Video Encoder",
834                 .is_em2800    = 1,
835                 .decoder      = EM28XX_SAA711X,
836                 .tuner_type   = TUNER_ABSENT, /* capture only board */
837                 .input        = { {
838                         .type     = EM28XX_VMUX_COMPOSITE1,
839                         .vmux     = SAA7115_COMPOSITE0,
840                         .amux     = EM28XX_AMUX_LINE_IN,
841                 }, {
842                         .type     = EM28XX_VMUX_SVIDEO,
843                         .vmux     = SAA7115_SVIDEO3,
844                         .amux     = EM28XX_AMUX_LINE_IN,
845                 } },
846         },
847         [EM2800_BOARD_LEADTEK_WINFAST_USBII] = {
848                 .name         = "Leadtek Winfast USB II",
849                 .is_em2800    = 1,
850                 .tuner_type   = TUNER_LG_PAL_NEW_TAPC,
851                 .tda9887_conf = TDA9887_PRESENT,
852                 .decoder      = EM28XX_SAA711X,
853                 .input        = { {
854                         .type     = EM28XX_VMUX_TELEVISION,
855                         .vmux     = SAA7115_COMPOSITE2,
856                         .amux     = EM28XX_AMUX_VIDEO,
857                 }, {
858                         .type     = EM28XX_VMUX_COMPOSITE1,
859                         .vmux     = SAA7115_COMPOSITE0,
860                         .amux     = EM28XX_AMUX_LINE_IN,
861                 }, {
862                         .type     = EM28XX_VMUX_SVIDEO,
863                         .vmux     = SAA7115_SVIDEO3,
864                         .amux     = EM28XX_AMUX_LINE_IN,
865                 } },
866         },
867         [EM2800_BOARD_KWORLD_USB2800] = {
868                 .name         = "Kworld USB2800",
869                 .is_em2800    = 1,
870                 .tuner_type   = TUNER_PHILIPS_FCV1236D,
871                 .tda9887_conf = TDA9887_PRESENT,
872                 .decoder      = EM28XX_SAA711X,
873                 .input        = { {
874                         .type     = EM28XX_VMUX_TELEVISION,
875                         .vmux     = SAA7115_COMPOSITE2,
876                         .amux     = EM28XX_AMUX_VIDEO,
877                 }, {
878                         .type     = EM28XX_VMUX_COMPOSITE1,
879                         .vmux     = SAA7115_COMPOSITE0,
880                         .amux     = EM28XX_AMUX_LINE_IN,
881                 }, {
882                         .type     = EM28XX_VMUX_SVIDEO,
883                         .vmux     = SAA7115_SVIDEO3,
884                         .amux     = EM28XX_AMUX_LINE_IN,
885                 } },
886         },
887         [EM2820_BOARD_PINNACLE_DVC_90] = {
888                 .name         = "Pinnacle Dazzle DVC 90/DVC 100",
889                 .tuner_type   = TUNER_ABSENT, /* capture only board */
890                 .decoder      = EM28XX_SAA711X,
891                 .input        = { {
892                         .type     = EM28XX_VMUX_COMPOSITE1,
893                         .vmux     = SAA7115_COMPOSITE0,
894                         .amux     = EM28XX_AMUX_LINE_IN,
895                 }, {
896                         .type     = EM28XX_VMUX_SVIDEO,
897                         .vmux     = SAA7115_SVIDEO3,
898                         .amux     = EM28XX_AMUX_LINE_IN,
899                 } },
900         },
901         [EM2800_BOARD_VGEAR_POCKETTV] = {
902                 .name         = "V-Gear PocketTV",
903                 .is_em2800    = 1,
904                 .tuner_type   = TUNER_LG_PAL_NEW_TAPC,
905                 .tda9887_conf = TDA9887_PRESENT,
906                 .decoder      = EM28XX_SAA711X,
907                 .input        = { {
908                         .type     = EM28XX_VMUX_TELEVISION,
909                         .vmux     = SAA7115_COMPOSITE2,
910                         .amux     = EM28XX_AMUX_VIDEO,
911                 }, {
912                         .type     = EM28XX_VMUX_COMPOSITE1,
913                         .vmux     = SAA7115_COMPOSITE0,
914                         .amux     = EM28XX_AMUX_LINE_IN,
915                 }, {
916                         .type     = EM28XX_VMUX_SVIDEO,
917                         .vmux     = SAA7115_SVIDEO3,
918                         .amux     = EM28XX_AMUX_LINE_IN,
919                 } },
920         },
921         [EM2820_BOARD_PROLINK_PLAYTV_BOX4_USB2] = {
922                 .name         = "Pixelview PlayTV Box 4 USB 2.0",
923                 .tda9887_conf = TDA9887_PRESENT,
924                 .tuner_type   = TUNER_YMEC_TVF_5533MF,
925                 .decoder      = EM28XX_SAA711X,
926                 .input        = { {
927                         .type     = EM28XX_VMUX_TELEVISION,
928                         .vmux     = SAA7115_COMPOSITE2,
929                         .amux     = EM28XX_AMUX_VIDEO,
930                         .aout     = EM28XX_AOUT_MONO |  /* I2S */
931                                     EM28XX_AOUT_MASTER, /* Line out pin */
932                 }, {
933                         .type     = EM28XX_VMUX_COMPOSITE1,
934                         .vmux     = SAA7115_COMPOSITE0,
935                         .amux     = EM28XX_AMUX_LINE_IN,
936                 }, {
937                         .type     = EM28XX_VMUX_SVIDEO,
938                         .vmux     = SAA7115_SVIDEO3,
939                         .amux     = EM28XX_AMUX_LINE_IN,
940                 } },
941         },
942         [EM2820_BOARD_PROLINK_PLAYTV_USB2] = {
943                 .name         = "Pixelview Prolink PlayTV USB 2.0",
944                 .has_snapshot_button = 1,
945                 .tda9887_conf = TDA9887_PRESENT,
946                 .tuner_type   = TUNER_YMEC_TVF_5533MF,
947                 .decoder      = EM28XX_SAA711X,
948                 .input        = { {
949                         .type     = EM28XX_VMUX_TELEVISION,
950                         .vmux     = SAA7115_COMPOSITE2,
951                         .amux     = EM28XX_AMUX_VIDEO,
952                         .aout     = EM28XX_AOUT_MONO |  /* I2S */
953                                     EM28XX_AOUT_MASTER, /* Line out pin */
954                 }, {
955                         .type     = EM28XX_VMUX_COMPOSITE1,
956                         .vmux     = SAA7115_COMPOSITE0,
957                         .amux     = EM28XX_AMUX_LINE_IN,
958                 }, {
959                         .type     = EM28XX_VMUX_SVIDEO,
960                         .vmux     = SAA7115_SVIDEO3,
961                         .amux     = EM28XX_AMUX_LINE_IN,
962                 } },
963         },
964         [EM2860_BOARD_POINTNIX_INTRAORAL_CAMERA] = {
965                 .name                = "PointNix Intra-Oral Camera",
966                 .has_snapshot_button = 1,
967                 .tda9887_conf        = TDA9887_PRESENT,
968                 .tuner_type          = TUNER_ABSENT,
969                 .decoder             = EM28XX_SAA711X,
970                 .input               = { {
971                         .type     = EM28XX_VMUX_SVIDEO,
972                         .vmux     = SAA7115_SVIDEO3,
973                         .amux     = EM28XX_AMUX_VIDEO,
974                 } },
975         },
976         [EM2880_BOARD_MSI_DIGIVOX_AD] = {
977                 .name         = "MSI DigiVox A/D",
978                 .valid        = EM28XX_BOARD_NOT_VALIDATED,
979                 .tuner_type   = TUNER_XC2028,
980                 .tuner_gpio   = default_tuner_gpio,
981                 .decoder      = EM28XX_TVP5150,
982                 .input        = { {
983                         .type     = EM28XX_VMUX_TELEVISION,
984                         .vmux     = TVP5150_COMPOSITE0,
985                         .amux     = EM28XX_AMUX_VIDEO,
986                         .gpio     = em2880_msi_digivox_ad_analog,
987                 }, {
988                         .type     = EM28XX_VMUX_COMPOSITE1,
989                         .vmux     = TVP5150_COMPOSITE1,
990                         .amux     = EM28XX_AMUX_LINE_IN,
991                         .gpio     = em2880_msi_digivox_ad_analog,
992                 }, {
993                         .type     = EM28XX_VMUX_SVIDEO,
994                         .vmux     = TVP5150_SVIDEO,
995                         .amux     = EM28XX_AMUX_LINE_IN,
996                         .gpio     = em2880_msi_digivox_ad_analog,
997                 } },
998         },
999         [EM2880_BOARD_MSI_DIGIVOX_AD_II] = {
1000                 .name         = "MSI DigiVox A/D II",
1001                 .valid        = EM28XX_BOARD_NOT_VALIDATED,
1002                 .tuner_type   = TUNER_XC2028,
1003                 .tuner_gpio   = default_tuner_gpio,
1004                 .decoder      = EM28XX_TVP5150,
1005                 .input        = { {
1006                         .type     = EM28XX_VMUX_TELEVISION,
1007                         .vmux     = TVP5150_COMPOSITE0,
1008                         .amux     = EM28XX_AMUX_VIDEO,
1009                         .gpio     = em2880_msi_digivox_ad_analog,
1010                 }, {
1011                         .type     = EM28XX_VMUX_COMPOSITE1,
1012                         .vmux     = TVP5150_COMPOSITE1,
1013                         .amux     = EM28XX_AMUX_LINE_IN,
1014                         .gpio     = em2880_msi_digivox_ad_analog,
1015                 }, {
1016                         .type     = EM28XX_VMUX_SVIDEO,
1017                         .vmux     = TVP5150_SVIDEO,
1018                         .amux     = EM28XX_AMUX_LINE_IN,
1019                         .gpio     = em2880_msi_digivox_ad_analog,
1020                 } },
1021         },
1022         [EM2880_BOARD_KWORLD_DVB_305U] = {
1023                 .name         = "KWorld DVB-T 305U",
1024                 .valid        = EM28XX_BOARD_NOT_VALIDATED,
1025                 .tuner_type   = TUNER_XC2028,
1026                 .tuner_gpio   = default_tuner_gpio,
1027                 .decoder      = EM28XX_TVP5150,
1028                 .input        = { {
1029                         .type     = EM28XX_VMUX_TELEVISION,
1030                         .vmux     = TVP5150_COMPOSITE0,
1031                         .amux     = EM28XX_AMUX_VIDEO,
1032                 }, {
1033                         .type     = EM28XX_VMUX_COMPOSITE1,
1034                         .vmux     = TVP5150_COMPOSITE1,
1035                         .amux     = EM28XX_AMUX_LINE_IN,
1036                 }, {
1037                         .type     = EM28XX_VMUX_SVIDEO,
1038                         .vmux     = TVP5150_SVIDEO,
1039                         .amux     = EM28XX_AMUX_LINE_IN,
1040                 } },
1041         },
1042         [EM2880_BOARD_KWORLD_DVB_310U] = {
1043                 .name         = "KWorld DVB-T 310U",
1044                 .tuner_type   = TUNER_XC2028,
1045                 .tuner_gpio   = default_tuner_gpio,
1046                 .has_dvb      = 1,
1047                 .dvb_gpio     = default_digital,
1048                 .mts_firmware = 1,
1049                 .decoder      = EM28XX_TVP5150,
1050                 .input        = { {
1051                         .type     = EM28XX_VMUX_TELEVISION,
1052                         .vmux     = TVP5150_COMPOSITE0,
1053                         .amux     = EM28XX_AMUX_VIDEO,
1054                         .gpio     = default_analog,
1055                 }, {
1056                         .type     = EM28XX_VMUX_COMPOSITE1,
1057                         .vmux     = TVP5150_COMPOSITE1,
1058                         .amux     = EM28XX_AMUX_LINE_IN,
1059                         .gpio     = default_analog,
1060                 }, {    /* S-video has not been tested yet */
1061                         .type     = EM28XX_VMUX_SVIDEO,
1062                         .vmux     = TVP5150_SVIDEO,
1063                         .amux     = EM28XX_AMUX_LINE_IN,
1064                         .gpio     = default_analog,
1065                 } },
1066         },
1067         [EM2881_BOARD_DNT_DA2_HYBRID] = {
1068                 .name         = "DNT DA2 Hybrid",
1069                 .valid        = EM28XX_BOARD_NOT_VALIDATED,
1070                 .tuner_type   = TUNER_XC2028,
1071                 .tuner_gpio   = default_tuner_gpio,
1072                 .decoder      = EM28XX_TVP5150,
1073                 .input        = { {
1074                         .type     = EM28XX_VMUX_TELEVISION,
1075                         .vmux     = TVP5150_COMPOSITE0,
1076                         .amux     = EM28XX_AMUX_VIDEO,
1077                         .gpio     = default_analog,
1078                 }, {
1079                         .type     = EM28XX_VMUX_COMPOSITE1,
1080                         .vmux     = TVP5150_COMPOSITE1,
1081                         .amux     = EM28XX_AMUX_LINE_IN,
1082                         .gpio     = default_analog,
1083                 }, {
1084                         .type     = EM28XX_VMUX_SVIDEO,
1085                         .vmux     = TVP5150_SVIDEO,
1086                         .amux     = EM28XX_AMUX_LINE_IN,
1087                         .gpio     = default_analog,
1088                 } },
1089         },
1090         [EM2881_BOARD_PINNACLE_HYBRID_PRO] = {
1091                 .name         = "Pinnacle Hybrid Pro",
1092                 .valid        = EM28XX_BOARD_NOT_VALIDATED,
1093                 .tuner_type   = TUNER_XC2028,
1094                 .tuner_gpio   = default_tuner_gpio,
1095                 .decoder      = EM28XX_TVP5150,
1096                 .input        = { {
1097                         .type     = EM28XX_VMUX_TELEVISION,
1098                         .vmux     = TVP5150_COMPOSITE0,
1099                         .amux     = EM28XX_AMUX_VIDEO,
1100                         .gpio     = default_analog,
1101                 }, {
1102                         .type     = EM28XX_VMUX_COMPOSITE1,
1103                         .vmux     = TVP5150_COMPOSITE1,
1104                         .amux     = EM28XX_AMUX_LINE_IN,
1105                         .gpio     = default_analog,
1106                 }, {
1107                         .type     = EM28XX_VMUX_SVIDEO,
1108                         .vmux     = TVP5150_SVIDEO,
1109                         .amux     = EM28XX_AMUX_LINE_IN,
1110                         .gpio     = default_analog,
1111                 } },
1112         },
1113         [EM2882_BOARD_PINNACLE_HYBRID_PRO] = {
1114                 .name         = "Pinnacle Hybrid Pro (2)",
1115                 .valid        = EM28XX_BOARD_NOT_VALIDATED,
1116                 .tuner_type   = TUNER_XC2028,
1117                 .tuner_gpio   = default_tuner_gpio,
1118                 .mts_firmware = 1,
1119                 .decoder      = EM28XX_TVP5150,
1120                 .input        = { {
1121                         .type     = EM28XX_VMUX_TELEVISION,
1122                         .vmux     = TVP5150_COMPOSITE0,
1123                         .amux     = EM28XX_AMUX_VIDEO,
1124                         .gpio     = hauppauge_wintv_hvr_900_analog,
1125                 }, {
1126                         .type     = EM28XX_VMUX_COMPOSITE1,
1127                         .vmux     = TVP5150_COMPOSITE1,
1128                         .amux     = EM28XX_AMUX_LINE_IN,
1129                         .gpio     = hauppauge_wintv_hvr_900_analog,
1130                 }, {
1131                         .type     = EM28XX_VMUX_SVIDEO,
1132                         .vmux     = TVP5150_SVIDEO,
1133                         .amux     = EM28XX_AMUX_LINE_IN,
1134                         .gpio     = hauppauge_wintv_hvr_900_analog,
1135                 } },
1136         },
1137         [EM2882_BOARD_KWORLD_VS_DVBT] = {
1138                 .name         = "Kworld VS-DVB-T 323UR",
1139                 .valid        = EM28XX_BOARD_NOT_VALIDATED,
1140                 .tuner_type   = TUNER_XC2028,
1141                 .tuner_gpio   = default_tuner_gpio,
1142                 .decoder      = EM28XX_TVP5150,
1143                 .input        = { {
1144                         .type     = EM28XX_VMUX_TELEVISION,
1145                         .vmux     = TVP5150_COMPOSITE0,
1146                         .amux     = EM28XX_AMUX_VIDEO,
1147                 }, {
1148                         .type     = EM28XX_VMUX_COMPOSITE1,
1149                         .vmux     = TVP5150_COMPOSITE1,
1150                         .amux     = EM28XX_AMUX_LINE_IN,
1151                 }, {
1152                         .type     = EM28XX_VMUX_SVIDEO,
1153                         .vmux     = TVP5150_SVIDEO,
1154                         .amux     = EM28XX_AMUX_LINE_IN,
1155                 } },
1156         },
1157         [EM2882_BOARD_TERRATEC_HYBRID_XS] = {
1158                 .name         = "Terratec Hybrid XS (em2882)",
1159                 .valid        = EM28XX_BOARD_NOT_VALIDATED,
1160                 .tuner_type   = TUNER_XC2028,
1161                 .tuner_gpio   = default_tuner_gpio,
1162                 .decoder      = EM28XX_TVP5150,
1163                 .input        = { {
1164                         .type     = EM28XX_VMUX_TELEVISION,
1165                         .vmux     = TVP5150_COMPOSITE0,
1166                         .amux     = EM28XX_AMUX_VIDEO,
1167                         .gpio     = hauppauge_wintv_hvr_900_analog,
1168                 }, {
1169                         .type     = EM28XX_VMUX_COMPOSITE1,
1170                         .vmux     = TVP5150_COMPOSITE1,
1171                         .amux     = EM28XX_AMUX_LINE_IN,
1172                         .gpio     = hauppauge_wintv_hvr_900_analog,
1173                 }, {
1174                         .type     = EM28XX_VMUX_SVIDEO,
1175                         .vmux     = TVP5150_SVIDEO,
1176                         .amux     = EM28XX_AMUX_LINE_IN,
1177                         .gpio     = hauppauge_wintv_hvr_900_analog,
1178                 } },
1179         },
1180         [EM2883_BOARD_KWORLD_HYBRID_A316] = {
1181                 .name         = "Kworld PlusTV HD Hybrid 330",
1182                 .tuner_type   = TUNER_XC2028,
1183                 .tuner_gpio   = default_tuner_gpio,
1184                 .decoder      = EM28XX_TVP5150,
1185                 .mts_firmware = 1,
1186                 .has_dvb      = 1,
1187                 .dvb_gpio     = default_digital,
1188                 .input        = { {
1189                         .type     = EM28XX_VMUX_TELEVISION,
1190                         .vmux     = TVP5150_COMPOSITE0,
1191                         .amux     = EM28XX_AMUX_VIDEO,
1192                         .gpio     = default_analog,
1193                 }, {
1194                         .type     = EM28XX_VMUX_COMPOSITE1,
1195                         .vmux     = TVP5150_COMPOSITE1,
1196                         .amux     = EM28XX_AMUX_LINE_IN,
1197                         .gpio     = hauppauge_wintv_hvr_900_analog,
1198                 }, {
1199                         .type     = EM28XX_VMUX_SVIDEO,
1200                         .vmux     = TVP5150_SVIDEO,
1201                         .amux     = EM28XX_AMUX_LINE_IN,
1202                         .gpio     = hauppauge_wintv_hvr_900_analog,
1203                 } },
1204         },
1205         [EM2820_BOARD_COMPRO_VIDEOMATE_FORYOU] = {
1206                 .name         = "Compro VideoMate ForYou/Stereo",
1207                 .tuner_type   = TUNER_LG_PAL_NEW_TAPC,
1208                 .tda9887_conf = TDA9887_PRESENT,
1209                 .decoder      = EM28XX_TVP5150,
1210                 .input        = { {
1211                         .type     = EM28XX_VMUX_TELEVISION,
1212                         .vmux     = TVP5150_COMPOSITE0,
1213                         .amux     = EM28XX_AMUX_LINE_IN,
1214                 }, {
1215                         .type     = EM28XX_VMUX_SVIDEO,
1216                         .vmux     = TVP5150_SVIDEO,
1217                         .amux     = EM28XX_AMUX_LINE_IN,
1218                 } },
1219         },
1220 };
1221 const unsigned int em28xx_bcount = ARRAY_SIZE(em28xx_boards);
1222
1223 /* table of devices that work with this driver */
1224 struct usb_device_id em28xx_id_table [] = {
1225         { USB_DEVICE(0xeb1a, 0x2750),
1226                         .driver_info = EM2750_BOARD_UNKNOWN },
1227         { USB_DEVICE(0xeb1a, 0x2751),
1228                         .driver_info = EM2750_BOARD_UNKNOWN },
1229         { USB_DEVICE(0xeb1a, 0x2800),
1230                         .driver_info = EM2800_BOARD_UNKNOWN },
1231         { USB_DEVICE(0xeb1a, 0x2820),
1232                         .driver_info = EM2820_BOARD_UNKNOWN },
1233         { USB_DEVICE(0xeb1a, 0x2821),
1234                         .driver_info = EM2820_BOARD_UNKNOWN },
1235         { USB_DEVICE(0xeb1a, 0x2860),
1236                         .driver_info = EM2820_BOARD_UNKNOWN },
1237         { USB_DEVICE(0xeb1a, 0x2861),
1238                         .driver_info = EM2820_BOARD_UNKNOWN },
1239         { USB_DEVICE(0xeb1a, 0x2870),
1240                         .driver_info = EM2820_BOARD_UNKNOWN },
1241         { USB_DEVICE(0xeb1a, 0x2881),
1242                         .driver_info = EM2820_BOARD_UNKNOWN },
1243         { USB_DEVICE(0xeb1a, 0x2883),
1244                         .driver_info = EM2820_BOARD_UNKNOWN },
1245         { USB_DEVICE(0xeb1a, 0xe300),
1246                         .driver_info = EM2861_BOARD_KWORLD_PVRTV_300U },
1247         { USB_DEVICE(0xeb1a, 0xe305),
1248                         .driver_info = EM2880_BOARD_KWORLD_DVB_305U },
1249         { USB_DEVICE(0xeb1a, 0xe310),
1250                         .driver_info = EM2880_BOARD_MSI_DIGIVOX_AD },
1251         { USB_DEVICE(0xeb1a, 0xa316),
1252                         .driver_info = EM2883_BOARD_KWORLD_HYBRID_A316 },
1253         { USB_DEVICE(0xeb1a, 0xe320),
1254                         .driver_info = EM2880_BOARD_MSI_DIGIVOX_AD_II },
1255         { USB_DEVICE(0xeb1a, 0xe323),
1256                         .driver_info = EM2882_BOARD_KWORLD_VS_DVBT },
1257         { USB_DEVICE(0xeb1a, 0xe350),
1258                         .driver_info = EM2870_BOARD_KWORLD_350U },
1259         { USB_DEVICE(0xeb1a, 0xe355),
1260                         .driver_info = EM2870_BOARD_KWORLD_355U },
1261         { USB_DEVICE(0xeb1a, 0x2801),
1262                         .driver_info = EM2800_BOARD_GRABBEEX_USB2800 },
1263         { USB_DEVICE(0xeb1a, 0xe357),
1264                         .driver_info = EM2870_BOARD_KWORLD_355U },
1265         { USB_DEVICE(0x0ccd, 0x0036),
1266                         .driver_info = EM2820_BOARD_TERRATEC_CINERGY_250 },
1267         { USB_DEVICE(0x0ccd, 0x004c),
1268                         .driver_info = EM2880_BOARD_TERRATEC_HYBRID_XS_FR },
1269         { USB_DEVICE(0x0ccd, 0x004f),
1270                         .driver_info = EM2860_BOARD_TERRATEC_HYBRID_XS },
1271         { USB_DEVICE(0x0ccd, 0x005e),
1272                         .driver_info = EM2882_BOARD_TERRATEC_HYBRID_XS },
1273         { USB_DEVICE(0x0ccd, 0x0042),
1274                         .driver_info = EM2880_BOARD_TERRATEC_HYBRID_XS },
1275         { USB_DEVICE(0x0ccd, 0x0043),
1276                         .driver_info = EM2870_BOARD_TERRATEC_XS },
1277         { USB_DEVICE(0x0ccd, 0x0047),
1278                         .driver_info = EM2880_BOARD_TERRATEC_PRODIGY_XS },
1279         { USB_DEVICE(0x185b, 0x2870),
1280                         .driver_info = EM2870_BOARD_COMPRO_VIDEOMATE },
1281         { USB_DEVICE(0x185b, 0x2041),
1282                         .driver_info = EM2820_BOARD_COMPRO_VIDEOMATE_FORYOU },
1283         { USB_DEVICE(0x2040, 0x4200),
1284                         .driver_info = EM2820_BOARD_HAUPPAUGE_WINTV_USB_2 },
1285         { USB_DEVICE(0x2040, 0x4201),
1286                         .driver_info = EM2820_BOARD_HAUPPAUGE_WINTV_USB_2 },
1287         { USB_DEVICE(0x2040, 0x6500),
1288                         .driver_info = EM2880_BOARD_HAUPPAUGE_WINTV_HVR_900 },
1289         { USB_DEVICE(0x2040, 0x6502),
1290                         .driver_info = EM2880_BOARD_HAUPPAUGE_WINTV_HVR_900_R2 },
1291         { USB_DEVICE(0x2040, 0x6513), /* HCW HVR-980 */
1292                         .driver_info = EM2883_BOARD_HAUPPAUGE_WINTV_HVR_950 },
1293         { USB_DEVICE(0x2040, 0x6517), /* HP  HVR-950 */
1294                         .driver_info = EM2883_BOARD_HAUPPAUGE_WINTV_HVR_950 },
1295         { USB_DEVICE(0x2040, 0x651b), /* RP  HVR-950 */
1296                         .driver_info = EM2883_BOARD_HAUPPAUGE_WINTV_HVR_950 },
1297         { USB_DEVICE(0x2040, 0x651f),
1298                         .driver_info = EM2883_BOARD_HAUPPAUGE_WINTV_HVR_850 },
1299         { USB_DEVICE(0x0438, 0xb002),
1300                         .driver_info = EM2880_BOARD_AMD_ATI_TV_WONDER_HD_600 },
1301         { USB_DEVICE(0x2001, 0xf112),
1302                         .driver_info = EM2820_BOARD_DLINK_USB_TV },
1303         { USB_DEVICE(0x2304, 0x0207),
1304                         .driver_info = EM2820_BOARD_PINNACLE_DVC_90 },
1305         { USB_DEVICE(0x2304, 0x0208),
1306                         .driver_info = EM2820_BOARD_PINNACLE_USB_2 },
1307         { USB_DEVICE(0x2304, 0x021a),
1308                         .driver_info = EM2820_BOARD_PINNACLE_DVC_90 },
1309         { USB_DEVICE(0x2304, 0x0226),
1310                         .driver_info = EM2882_BOARD_PINNACLE_HYBRID_PRO },
1311         { USB_DEVICE(0x2304, 0x0227),
1312                         .driver_info = EM2880_BOARD_PINNACLE_PCTV_HD_PRO },
1313         { USB_DEVICE(0x0413, 0x6023),
1314                         .driver_info = EM2800_BOARD_LEADTEK_WINFAST_USBII },
1315         { USB_DEVICE(0x093b, 0xa005),
1316                         .driver_info = EM2861_BOARD_PLEXTOR_PX_TV100U },
1317         { },
1318 };
1319 MODULE_DEVICE_TABLE(usb, em28xx_id_table);
1320
1321 /*
1322  * EEPROM hash table for devices with generic USB IDs
1323  */
1324 static struct em28xx_hash_table em28xx_eeprom_hash [] = {
1325         /* P/N: SA 60002070465 Tuner: TVF7533-MF */
1326         {0x6ce05a8f, EM2820_BOARD_PROLINK_PLAYTV_USB2, TUNER_YMEC_TVF_5533MF},
1327         {0x72cc5a8b, EM2820_BOARD_PROLINK_PLAYTV_BOX4_USB2, TUNER_YMEC_TVF_5533MF},
1328         {0x966a0441, EM2880_BOARD_KWORLD_DVB_310U, TUNER_XC2028},
1329 };
1330
1331 /* I2C devicelist hash table for devices with generic USB IDs */
1332 static struct em28xx_hash_table em28xx_i2c_hash[] = {
1333         {0xb06a32c3, EM2800_BOARD_TERRATEC_CINERGY_200, TUNER_LG_PAL_NEW_TAPC},
1334         {0xf51200e3, EM2800_BOARD_VGEAR_POCKETTV, TUNER_LG_PAL_NEW_TAPC},
1335         {0x1ba50080, EM2860_BOARD_POINTNIX_INTRAORAL_CAMERA, TUNER_ABSENT},
1336 };
1337
1338 int em28xx_tuner_callback(void *ptr, int component, int command, int arg)
1339 {
1340         int rc = 0;
1341         struct em28xx *dev = ptr;
1342
1343         if (dev->tuner_type != TUNER_XC2028)
1344                 return 0;
1345
1346         if (command != XC2028_TUNER_RESET)
1347                 return 0;
1348
1349         rc = em28xx_gpio_set(dev, dev->board.tuner_gpio);
1350
1351         return rc;
1352 }
1353 EXPORT_SYMBOL_GPL(em28xx_tuner_callback);
1354
1355 static void inline em28xx_set_model(struct em28xx *dev)
1356 {
1357         memcpy(&dev->board, &em28xx_boards[dev->model], sizeof(dev->board));
1358
1359         /* Those are the default values for the majority of boards
1360            Use those values if not specified otherwise at boards entry
1361          */
1362         if (!dev->board.xclk)
1363                 dev->board.xclk = EM28XX_XCLK_IR_RC5_MODE |
1364                                   EM28XX_XCLK_FREQUENCY_12MHZ;
1365
1366         if (!dev->board.i2c_speed)
1367                 dev->board.i2c_speed = EM28XX_I2C_CLK_WAIT_ENABLE |
1368                                        EM28XX_I2C_FREQ_100_KHZ;
1369 }
1370
1371 /* Since em28xx_pre_card_setup() requires a proper dev->model,
1372  * this won't work for boards with generic PCI IDs
1373  */
1374 void em28xx_pre_card_setup(struct em28xx *dev)
1375 {
1376         int rc;
1377
1378         em28xx_set_model(dev);
1379
1380         em28xx_info("Identified as %s (card=%d)\n",
1381                     dev->board.name, dev->model);
1382
1383         /* Set the default GPO/GPIO for legacy devices */
1384         dev->reg_gpo_num = EM2880_R04_GPO;
1385         dev->reg_gpio_num = EM28XX_R08_GPIO;
1386
1387         dev->wait_after_write = 5;
1388
1389         /* Based on the Chip ID, set the device configuration */
1390         rc = em28xx_read_reg(dev, EM28XX_R0A_CHIPID);
1391         if (rc > 0) {
1392                 dev->chip_id = rc;
1393
1394                 switch (dev->chip_id) {
1395                 case CHIP_ID_EM2750:
1396                         em28xx_info("chip ID is em2750\n");
1397                         break;
1398                 case CHIP_ID_EM2820:
1399                         em28xx_info("chip ID is em2820\n");
1400                         break;
1401                 case CHIP_ID_EM2840:
1402                         em28xx_info("chip ID is em2840\n");
1403                         break;
1404                 case CHIP_ID_EM2860:
1405                         em28xx_info("chip ID is em2860\n");
1406                         break;
1407                 case CHIP_ID_EM2870:
1408                         em28xx_info("chip ID is em2870\n");
1409                         dev->wait_after_write = 0;
1410                         break;
1411                 case CHIP_ID_EM2874:
1412                         em28xx_info("chip ID is em2874\n");
1413                         dev->reg_gpio_num = EM2874_R80_GPIO;
1414                         dev->wait_after_write = 0;
1415                         break;
1416                 case CHIP_ID_EM2883:
1417                         em28xx_info("chip ID is em2882/em2883\n");
1418                         dev->wait_after_write = 0;
1419                         break;
1420                 default:
1421                         em28xx_info("em28xx chip ID = %d\n", dev->chip_id);
1422                 }
1423         }
1424
1425         /* Prepopulate cached GPO register content */
1426         rc = em28xx_read_reg(dev, dev->reg_gpo_num);
1427         if (rc >= 0)
1428                 dev->reg_gpo = rc;
1429
1430         /* Set the initial XCLK and I2C clock values based on the board
1431            definition */
1432         em28xx_write_reg(dev, EM28XX_R0F_XCLK, dev->board.xclk & 0x7f);
1433         em28xx_write_reg(dev, EM28XX_R06_I2C_CLK, dev->board.i2c_speed);
1434         msleep(50);
1435
1436         /* request some modules */
1437         switch (dev->model) {
1438         case EM2861_BOARD_PLEXTOR_PX_TV100U:
1439                 /* FIXME guess */
1440                 /* Turn on analog audio output */
1441                 em28xx_write_reg(dev, EM28XX_R08_GPIO, 0xfd);
1442                 break;
1443         case EM2861_BOARD_KWORLD_PVRTV_300U:
1444         case EM2880_BOARD_KWORLD_DVB_305U:
1445                 em28xx_write_reg(dev, EM28XX_R08_GPIO, 0x6d);
1446                 msleep(10);
1447                 em28xx_write_reg(dev, EM28XX_R08_GPIO, 0x7d);
1448                 msleep(10);
1449                 break;
1450         case EM2870_BOARD_COMPRO_VIDEOMATE:
1451                 /* TODO: someone can do some cleanup here...
1452                          not everything's needed */
1453                 em28xx_write_reg(dev, EM2880_R04_GPO, 0x00);
1454                 msleep(10);
1455                 em28xx_write_reg(dev, EM2880_R04_GPO, 0x01);
1456                 msleep(10);
1457                 em28xx_write_reg(dev, EM28XX_R08_GPIO, 0xfd);
1458                 mdelay(70);
1459                 em28xx_write_reg(dev, EM28XX_R08_GPIO, 0xfc);
1460                 mdelay(70);
1461                 em28xx_write_reg(dev, EM28XX_R08_GPIO, 0xdc);
1462                 mdelay(70);
1463                 em28xx_write_reg(dev, EM28XX_R08_GPIO, 0xfc);
1464                 mdelay(70);
1465                 break;
1466         case EM2870_BOARD_TERRATEC_XS_MT2060:
1467                 /* this device needs some gpio writes to get the DVB-T
1468                    demod work */
1469                 em28xx_write_reg(dev, EM28XX_R08_GPIO, 0xfe);
1470                 mdelay(70);
1471                 em28xx_write_reg(dev, EM28XX_R08_GPIO, 0xde);
1472                 mdelay(70);
1473                 em28xx_write_reg(dev, EM28XX_R08_GPIO, 0xfe);
1474                 mdelay(70);
1475                 break;
1476         case EM2870_BOARD_PINNACLE_PCTV_DVB:
1477                 /* this device needs some gpio writes to get the
1478                    DVB-T demod work */
1479                 em28xx_write_reg(dev, EM28XX_R08_GPIO, 0xfe);
1480                 mdelay(70);
1481                 em28xx_write_reg(dev, EM28XX_R08_GPIO, 0xde);
1482                 mdelay(70);
1483                 em28xx_write_reg(dev, EM28XX_R08_GPIO, 0xfe);
1484                 mdelay(70);
1485                 break;
1486         case EM2820_BOARD_GADMEI_UTV310:
1487         case EM2820_BOARD_MSI_VOX_USB_2:
1488                 /* enables audio for that devices */
1489                 em28xx_write_reg(dev, EM28XX_R08_GPIO, 0xfd);
1490                 break;
1491         }
1492
1493         em28xx_gpio_set(dev, dev->board.tuner_gpio);
1494         em28xx_set_mode(dev, EM28XX_ANALOG_MODE);
1495
1496         /* Unlock device */
1497         em28xx_set_mode(dev, EM28XX_SUSPEND);
1498 }
1499
1500 static void em28xx_setup_xc3028(struct em28xx *dev, struct xc2028_ctrl *ctl)
1501 {
1502         memset(ctl, 0, sizeof(*ctl));
1503
1504         ctl->fname   = XC2028_DEFAULT_FIRMWARE;
1505         ctl->max_len = 64;
1506         ctl->mts = em28xx_boards[dev->model].mts_firmware;
1507
1508         switch (dev->model) {
1509         case EM2880_BOARD_HAUPPAUGE_WINTV_HVR_900:
1510                 ctl->demod = XC3028_FE_ZARLINK456;
1511                 break;
1512         case EM2880_BOARD_TERRATEC_HYBRID_XS:
1513                 ctl->demod = XC3028_FE_ZARLINK456;
1514                 break;
1515         case EM2880_BOARD_HAUPPAUGE_WINTV_HVR_900_R2:
1516                 /* djh - Not sure which demod we need here */
1517                 ctl->demod = XC3028_FE_DEFAULT;
1518                 break;
1519         case EM2880_BOARD_AMD_ATI_TV_WONDER_HD_600:
1520                 ctl->demod = XC3028_FE_DEFAULT;
1521                 ctl->fname = XC3028L_DEFAULT_FIRMWARE;
1522                 break;
1523         case EM2883_BOARD_HAUPPAUGE_WINTV_HVR_850:
1524         case EM2883_BOARD_HAUPPAUGE_WINTV_HVR_950:
1525         case EM2880_BOARD_PINNACLE_PCTV_HD_PRO:
1526                 /* FIXME: Better to specify the needed IF */
1527                 ctl->demod = XC3028_FE_DEFAULT;
1528                 break;
1529         default:
1530                 ctl->demod = XC3028_FE_OREN538;
1531         }
1532 }
1533
1534 static void em28xx_config_tuner(struct em28xx *dev)
1535 {
1536         struct v4l2_priv_tun_config  xc2028_cfg;
1537         struct tuner_setup           tun_setup;
1538         struct v4l2_frequency        f;
1539
1540         if (dev->tuner_type == TUNER_ABSENT)
1541                 return;
1542
1543         tun_setup.mode_mask = T_ANALOG_TV | T_RADIO;
1544         tun_setup.type = dev->tuner_type;
1545         tun_setup.addr = dev->tuner_addr;
1546         tun_setup.tuner_callback = em28xx_tuner_callback;
1547
1548         em28xx_i2c_call_clients(dev, TUNER_SET_TYPE_ADDR, &tun_setup);
1549
1550         if (dev->tuner_type == TUNER_XC2028) {
1551                 struct xc2028_ctrl           ctl;
1552
1553                 em28xx_setup_xc3028(dev, &ctl);
1554
1555                 xc2028_cfg.tuner = TUNER_XC2028;
1556                 xc2028_cfg.priv  = &ctl;
1557
1558                 em28xx_i2c_call_clients(dev, TUNER_SET_CONFIG, &xc2028_cfg);
1559         }
1560
1561         /* configure tuner */
1562         f.tuner = 0;
1563         f.type = V4L2_TUNER_ANALOG_TV;
1564         f.frequency = 9076;     /* just a magic number */
1565         dev->ctl_freq = f.frequency;
1566         em28xx_i2c_call_clients(dev, VIDIOC_S_FREQUENCY, &f);
1567 }
1568
1569 static int em28xx_hint_board(struct em28xx *dev)
1570 {
1571         int i;
1572
1573         /* HINT method: EEPROM
1574          *
1575          * This method works only for boards with eeprom.
1576          * Uses a hash of all eeprom bytes. The hash should be
1577          * unique for a vendor/tuner pair.
1578          * There are a high chance that tuners for different
1579          * video standards produce different hashes.
1580          */
1581         for (i = 0; i < ARRAY_SIZE(em28xx_eeprom_hash); i++) {
1582                 if (dev->hash == em28xx_eeprom_hash[i].hash) {
1583                         dev->model = em28xx_eeprom_hash[i].model;
1584                         dev->tuner_type = em28xx_eeprom_hash[i].tuner;
1585
1586                         em28xx_errdev("Your board has no unique USB ID.\n");
1587                         em28xx_errdev("A hint were successfully done, "
1588                                       "based on eeprom hash.\n");
1589                         em28xx_errdev("This method is not 100%% failproof.\n");
1590                         em28xx_errdev("If the board were missdetected, "
1591                                       "please email this log to:\n");
1592                         em28xx_errdev("\tV4L Mailing List "
1593                                       " <video4linux-list@redhat.com>\n");
1594                         em28xx_errdev("Board detected as %s\n",
1595                                       em28xx_boards[dev->model].name);
1596
1597                         return 0;
1598                 }
1599         }
1600
1601         /* HINT method: I2C attached devices
1602          *
1603          * This method works for all boards.
1604          * Uses a hash of i2c scanned devices.
1605          * Devices with the same i2c attached chips will
1606          * be considered equal.
1607          * This method is less precise than the eeprom one.
1608          */
1609
1610         /* user did not request i2c scanning => do it now */
1611         if (!dev->i2c_hash)
1612                 em28xx_do_i2c_scan(dev);
1613
1614         for (i = 0; i < ARRAY_SIZE(em28xx_i2c_hash); i++) {
1615                 if (dev->i2c_hash == em28xx_i2c_hash[i].hash) {
1616                         dev->model = em28xx_i2c_hash[i].model;
1617                         dev->tuner_type = em28xx_i2c_hash[i].tuner;
1618                         em28xx_errdev("Your board has no unique USB ID.\n");
1619                         em28xx_errdev("A hint were successfully done, "
1620                                       "based on i2c devicelist hash.\n");
1621                         em28xx_errdev("This method is not 100%% failproof.\n");
1622                         em28xx_errdev("If the board were missdetected, "
1623                                       "please email this log to:\n");
1624                         em28xx_errdev("\tV4L Mailing List "
1625                                       " <video4linux-list@redhat.com>\n");
1626                         em28xx_errdev("Board detected as %s\n",
1627                                       em28xx_boards[dev->model].name);
1628
1629                         return 0;
1630                 }
1631         }
1632
1633         em28xx_errdev("Your board has no unique USB ID and thus need a "
1634                       "hint to be detected.\n");
1635         em28xx_errdev("You may try to use card=<n> insmod option to "
1636                       "workaround that.\n");
1637         em28xx_errdev("Please send an email with this log to:\n");
1638         em28xx_errdev("\tV4L Mailing List <video4linux-list@redhat.com>\n");
1639         em28xx_errdev("Board eeprom hash is 0x%08lx\n", dev->hash);
1640         em28xx_errdev("Board i2c devicelist hash is 0x%08lx\n", dev->i2c_hash);
1641
1642         em28xx_errdev("Here is a list of valid choices for the card=<n>"
1643                       " insmod option:\n");
1644         for (i = 0; i < em28xx_bcount; i++) {
1645                 em28xx_errdev("    card=%d -> %s\n",
1646                                 i, em28xx_boards[i].name);
1647         }
1648         return -1;
1649 }
1650
1651 /* ----------------------------------------------------------------------- */
1652 void em28xx_set_ir(struct em28xx *dev, struct IR_i2c *ir)
1653 {
1654         if (disable_ir) {
1655                 ir->get_key = NULL;
1656                 return ;
1657         }
1658
1659         /* detect & configure */
1660         switch (dev->model) {
1661         case (EM2800_BOARD_UNKNOWN):
1662                 break;
1663         case (EM2820_BOARD_UNKNOWN):
1664                 break;
1665         case (EM2800_BOARD_TERRATEC_CINERGY_200):
1666         case (EM2820_BOARD_TERRATEC_CINERGY_250):
1667                 ir->ir_codes = ir_codes_em_terratec;
1668                 ir->get_key = em28xx_get_key_terratec;
1669                 snprintf(ir->c.name, sizeof(ir->c.name),
1670                          "i2c IR (EM28XX Terratec)");
1671                 break;
1672         case (EM2820_BOARD_PINNACLE_USB_2):
1673                 ir->ir_codes = ir_codes_pinnacle_grey;
1674                 ir->get_key = em28xx_get_key_pinnacle_usb_grey;
1675                 snprintf(ir->c.name, sizeof(ir->c.name),
1676                          "i2c IR (EM28XX Pinnacle PCTV)");
1677                 break;
1678         case (EM2820_BOARD_HAUPPAUGE_WINTV_USB_2):
1679                 ir->ir_codes = ir_codes_hauppauge_new;
1680                 ir->get_key = em28xx_get_key_em_haup;
1681                 snprintf(ir->c.name, sizeof(ir->c.name),
1682                          "i2c IR (EM2840 Hauppauge)");
1683                 break;
1684         case (EM2820_BOARD_MSI_VOX_USB_2):
1685                 break;
1686         case (EM2800_BOARD_LEADTEK_WINFAST_USBII):
1687                 break;
1688         case (EM2800_BOARD_KWORLD_USB2800):
1689                 break;
1690         case (EM2800_BOARD_GRABBEEX_USB2800):
1691                 break;
1692         }
1693 }
1694
1695 void em28xx_card_setup(struct em28xx *dev)
1696 {
1697         em28xx_set_model(dev);
1698
1699         dev->tuner_type = em28xx_boards[dev->model].tuner_type;
1700         if (em28xx_boards[dev->model].tuner_addr)
1701                 dev->tuner_addr = em28xx_boards[dev->model].tuner_addr;
1702
1703         /* request some modules */
1704         switch (dev->model) {
1705         case EM2820_BOARD_HAUPPAUGE_WINTV_USB_2:
1706         case EM2880_BOARD_HAUPPAUGE_WINTV_HVR_900:
1707         case EM2880_BOARD_HAUPPAUGE_WINTV_HVR_900_R2:
1708         case EM2883_BOARD_HAUPPAUGE_WINTV_HVR_850:
1709         case EM2883_BOARD_HAUPPAUGE_WINTV_HVR_950:
1710         {
1711                 struct tveeprom tv;
1712 #ifdef CONFIG_MODULES
1713                 request_module("tveeprom");
1714 #endif
1715                 /* Call first TVeeprom */
1716
1717                 dev->i2c_client.addr = 0xa0 >> 1;
1718                 tveeprom_hauppauge_analog(&dev->i2c_client, &tv, dev->eedata);
1719
1720                 dev->tuner_type = tv.tuner_type;
1721
1722                 if (tv.audio_processor == V4L2_IDENT_MSPX4XX) {
1723                         dev->i2s_speed = 2048000;
1724                         dev->board.has_msp34xx = 1;
1725                 }
1726 #ifdef CONFIG_MODULES
1727                 if (tv.has_ir)
1728                         request_module("ir-kbd-i2c");
1729 #endif
1730                 break;
1731         }
1732         case EM2820_BOARD_KWORLD_PVRTV2800RF:
1733                 /* GPIO enables sound on KWORLD PVR TV 2800RF */
1734                 em28xx_write_reg(dev, EM28XX_R08_GPIO, 0xf9);
1735                 break;
1736         case EM2820_BOARD_UNKNOWN:
1737         case EM2800_BOARD_UNKNOWN:
1738                 /*
1739                  * The K-WORLD DVB-T 310U is detected as an MSI Digivox AD.
1740                  *
1741                  * This occurs because they share identical USB vendor and
1742                  * product IDs.
1743                  *
1744                  * What we do here is look up the EEPROM hash of the K-WORLD
1745                  * and if it is found then we decide that we do not have
1746                  * a DIGIVOX and reset the device to the K-WORLD instead.
1747                  *
1748                  * This solution is only valid if they do not share eeprom
1749                  * hash identities which has not been determined as yet.
1750                  */
1751         case EM2880_BOARD_MSI_DIGIVOX_AD:
1752                 if (!em28xx_hint_board(dev))
1753                         em28xx_set_model(dev);
1754                 break;
1755         }
1756
1757         if (dev->board.has_snapshot_button)
1758                 em28xx_register_snapshot_button(dev);
1759
1760         if (dev->board.valid == EM28XX_BOARD_NOT_VALIDATED) {
1761                 em28xx_errdev("\n\n");
1762                 em28xx_errdev("The support for this board weren't "
1763                               "valid yet.\n");
1764                 em28xx_errdev("Please send a report of having this working\n");
1765                 em28xx_errdev("not to V4L mailing list (and/or to other "
1766                                 "addresses)\n\n");
1767         }
1768
1769         /* Allow override tuner type by a module parameter */
1770         if (tuner >= 0)
1771                 dev->tuner_type = tuner;
1772
1773 #ifdef CONFIG_MODULES
1774         /* request some modules */
1775         if (dev->board.has_msp34xx)
1776                 request_module("msp3400");
1777         if (dev->board.decoder == EM28XX_SAA711X)
1778                 request_module("saa7115");
1779         if (dev->board.decoder == EM28XX_TVP5150)
1780                 request_module("tvp5150");
1781         if (dev->board.tuner_type != TUNER_ABSENT)
1782                 request_module("tuner");
1783 #endif
1784
1785         em28xx_config_tuner(dev);
1786
1787         em28xx_ir_init(dev);
1788 }
1789
1790
1791 #if defined(CONFIG_MODULES) && defined(MODULE)
1792 static void request_module_async(struct work_struct *work)
1793 {
1794         struct em28xx *dev = container_of(work,
1795                              struct em28xx, request_module_wk);
1796
1797         if (dev->has_audio_class)
1798                 request_module("snd-usb-audio");
1799         else if (dev->has_alsa_audio)
1800                 request_module("em28xx-alsa");
1801
1802         if (dev->board.has_dvb)
1803                 request_module("em28xx-dvb");
1804 }
1805
1806 static void request_modules(struct em28xx *dev)
1807 {
1808         INIT_WORK(&dev->request_module_wk, request_module_async);
1809         schedule_work(&dev->request_module_wk);
1810 }
1811 #else
1812 #define request_modules(dev)
1813 #endif /* CONFIG_MODULES */
1814
1815 /*
1816  * em28xx_realease_resources()
1817  * unregisters the v4l2,i2c and usb devices
1818  * called when the device gets disconected or at module unload
1819 */
1820 void em28xx_release_resources(struct em28xx *dev)
1821 {
1822         if (dev->sbutton_input_dev)
1823                 em28xx_deregister_snapshot_button(dev);
1824
1825         if (dev->ir)
1826                 em28xx_ir_fini(dev);
1827
1828         /*FIXME: I2C IR should be disconnected */
1829
1830         em28xx_release_analog_resources(dev);
1831
1832         em28xx_remove_from_devlist(dev);
1833
1834         em28xx_i2c_unregister(dev);
1835         usb_put_dev(dev->udev);
1836
1837         /* Mark device as unused */
1838         em28xx_devused &= ~(1 << dev->devno);
1839 };
1840
1841 /*
1842  * em28xx_init_dev()
1843  * allocates and inits the device structs, registers i2c bus and v4l device
1844  */
1845 static int em28xx_init_dev(struct em28xx **devhandle, struct usb_device *udev,
1846                            int minor)
1847 {
1848         struct em28xx *dev = *devhandle;
1849         int retval = -ENOMEM;
1850         int errCode;
1851
1852         dev->udev = udev;
1853         mutex_init(&dev->ctrl_urb_lock);
1854         spin_lock_init(&dev->slock);
1855         init_waitqueue_head(&dev->open);
1856         init_waitqueue_head(&dev->wait_frame);
1857         init_waitqueue_head(&dev->wait_stream);
1858
1859         dev->em28xx_write_regs = em28xx_write_regs;
1860         dev->em28xx_read_reg = em28xx_read_reg;
1861         dev->em28xx_read_reg_req_len = em28xx_read_reg_req_len;
1862         dev->em28xx_write_regs_req = em28xx_write_regs_req;
1863         dev->em28xx_read_reg_req = em28xx_read_reg_req;
1864         dev->board.is_em2800 = em28xx_boards[dev->model].is_em2800;
1865
1866         em28xx_pre_card_setup(dev);
1867
1868         if (!dev->board.is_em2800) {
1869                 /* Sets I2C speed to 100 KHz */
1870                 retval = em28xx_write_reg(dev, EM28XX_R06_I2C_CLK, 0x40);
1871                 if (retval < 0) {
1872                         em28xx_errdev("%s: em28xx_write_regs_req failed!"
1873                                       " retval [%d]\n",
1874                                       __func__, retval);
1875                         return retval;
1876                 }
1877         }
1878
1879         /* register i2c bus */
1880         errCode = em28xx_i2c_register(dev);
1881         if (errCode < 0) {
1882                 em28xx_errdev("%s: em28xx_i2c_register - errCode [%d]!\n",
1883                         __func__, errCode);
1884                 return errCode;
1885         }
1886
1887         /* Do board specific init and eeprom reading */
1888         em28xx_card_setup(dev);
1889
1890         /* Configure audio */
1891         errCode = em28xx_audio_setup(dev);
1892         if (errCode < 0) {
1893                 em28xx_errdev("%s: Error while setting audio - errCode [%d]!\n",
1894                         __func__, errCode);
1895         }
1896
1897         /* wake i2c devices */
1898         em28xx_wake_i2c(dev);
1899
1900         /* init video dma queues */
1901         INIT_LIST_HEAD(&dev->vidq.active);
1902         INIT_LIST_HEAD(&dev->vidq.queued);
1903
1904
1905         if (dev->board.has_msp34xx) {
1906                 /* Send a reset to other chips via gpio */
1907                 errCode = em28xx_write_reg(dev, EM28XX_R08_GPIO, 0xf7);
1908                 if (errCode < 0) {
1909                         em28xx_errdev("%s: em28xx_write_regs_req - "
1910                                       "msp34xx(1) failed! errCode [%d]\n",
1911                                       __func__, errCode);
1912                         return errCode;
1913                 }
1914                 msleep(3);
1915
1916                 errCode = em28xx_write_reg(dev, EM28XX_R08_GPIO, 0xff);
1917                 if (errCode < 0) {
1918                         em28xx_errdev("%s: em28xx_write_regs_req - "
1919                                       "msp34xx(2) failed! errCode [%d]\n",
1920                                       __func__, errCode);
1921                         return errCode;
1922                 }
1923                 msleep(3);
1924         }
1925
1926         em28xx_add_into_devlist(dev);
1927
1928         retval = em28xx_register_analog_devices(dev);
1929         if (retval < 0) {
1930                 em28xx_release_resources(dev);
1931                 goto fail_reg_devices;
1932         }
1933
1934         em28xx_init_extension(dev);
1935
1936         /* Save some power by putting tuner to sleep */
1937         em28xx_i2c_call_clients(dev, TUNER_SET_STANDBY, NULL);
1938
1939         return 0;
1940
1941 fail_reg_devices:
1942         return retval;
1943 }
1944
1945 /*
1946  * em28xx_usb_probe()
1947  * checks for supported devices
1948  */
1949 static int em28xx_usb_probe(struct usb_interface *interface,
1950                             const struct usb_device_id *id)
1951 {
1952         const struct usb_endpoint_descriptor *endpoint;
1953         struct usb_device *udev;
1954         struct usb_interface *uif;
1955         struct em28xx *dev = NULL;
1956         int retval = -ENODEV;
1957         int i, nr, ifnum, isoc_pipe;
1958         char *speed;
1959         char descr[255] = "";
1960
1961         udev = usb_get_dev(interface_to_usbdev(interface));
1962         ifnum = interface->altsetting[0].desc.bInterfaceNumber;
1963
1964         /* Check to see next free device and mark as used */
1965         nr = find_first_zero_bit(&em28xx_devused, EM28XX_MAXBOARDS);
1966         em28xx_devused |= 1<<nr;
1967
1968         /* Don't register audio interfaces */
1969         if (interface->altsetting[0].desc.bInterfaceClass == USB_CLASS_AUDIO) {
1970                 em28xx_err(DRIVER_NAME " audio device (%04x:%04x): "
1971                         "interface %i, class %i\n",
1972                         le16_to_cpu(udev->descriptor.idVendor),
1973                         le16_to_cpu(udev->descriptor.idProduct),
1974                         ifnum,
1975                         interface->altsetting[0].desc.bInterfaceClass);
1976
1977                 em28xx_devused &= ~(1<<nr);
1978                 return -ENODEV;
1979         }
1980
1981         endpoint = &interface->cur_altsetting->endpoint[0].desc;
1982
1983         /* check if the device has the iso in endpoint at the correct place */
1984         if (usb_endpoint_xfer_isoc(endpoint)
1985             &&
1986             (interface->altsetting[1].endpoint[0].desc.wMaxPacketSize == 940)) {
1987                 /* It's a newer em2874/em2875 device */
1988                 isoc_pipe = 0;
1989         } else {
1990                 int check_interface = 1;
1991                 isoc_pipe = 1;
1992                 endpoint = &interface->cur_altsetting->endpoint[1].desc;
1993                 if (!usb_endpoint_xfer_isoc(endpoint))
1994                         check_interface = 0;
1995
1996                 if (usb_endpoint_dir_out(endpoint))
1997                         check_interface = 0;
1998
1999                 if (!check_interface) {
2000                         em28xx_err(DRIVER_NAME " video device (%04x:%04x): "
2001                                 "interface %i, class %i found.\n",
2002                                 le16_to_cpu(udev->descriptor.idVendor),
2003                                 le16_to_cpu(udev->descriptor.idProduct),
2004                                 ifnum,
2005                                 interface->altsetting[0].desc.bInterfaceClass);
2006
2007                         em28xx_err(DRIVER_NAME " This is an anciliary "
2008                                 "interface not used by the driver\n");
2009
2010                         em28xx_devused &= ~(1<<nr);
2011                         return -ENODEV;
2012                 }
2013         }
2014
2015         switch (udev->speed) {
2016         case USB_SPEED_LOW:
2017                 speed = "1.5";
2018                 break;
2019         case USB_SPEED_UNKNOWN:
2020         case USB_SPEED_FULL:
2021                 speed = "12";
2022                 break;
2023         case USB_SPEED_HIGH:
2024                 speed = "480";
2025                 break;
2026         default:
2027                 speed = "unknown";
2028         }
2029
2030         if (udev->manufacturer)
2031                 strlcpy(descr, udev->manufacturer, sizeof(descr));
2032
2033         if (udev->product) {
2034                 if (*descr)
2035                         strlcat(descr, " ", sizeof(descr));
2036                 strlcat(descr, udev->product, sizeof(descr));
2037         }
2038         if (*descr)
2039                 strlcat(descr, " ", sizeof(descr));
2040
2041         printk(DRIVER_NAME ": New device %s@ %s Mbps "
2042                 "(%04x:%04x, interface %d, class %d)\n",
2043                 descr,
2044                 speed,
2045                 le16_to_cpu(udev->descriptor.idVendor),
2046                 le16_to_cpu(udev->descriptor.idProduct),
2047                 ifnum,
2048                 interface->altsetting->desc.bInterfaceNumber);
2049
2050         if (nr >= EM28XX_MAXBOARDS) {
2051                 printk(DRIVER_NAME ": Supports only %i em28xx boards.\n",
2052                                 EM28XX_MAXBOARDS);
2053                 em28xx_devused &= ~(1<<nr);
2054                 return -ENOMEM;
2055         }
2056
2057         /* allocate memory for our device state and initialize it */
2058         dev = kzalloc(sizeof(*dev), GFP_KERNEL);
2059         if (dev == NULL) {
2060                 em28xx_err(DRIVER_NAME ": out of memory!\n");
2061                 em28xx_devused &= ~(1<<nr);
2062                 return -ENOMEM;
2063         }
2064
2065         snprintf(dev->name, 29, "em28xx #%d", nr);
2066         dev->devno = nr;
2067         dev->model = id->driver_info;
2068         dev->alt   = -1;
2069
2070         /* Checks if audio is provided by some interface */
2071         for (i = 0; i < udev->config->desc.bNumInterfaces; i++) {
2072                 uif = udev->config->interface[i];
2073                 if (uif->altsetting[0].desc.bInterfaceClass == USB_CLASS_AUDIO) {
2074                         dev->has_audio_class = 1;
2075                         break;
2076                 }
2077         }
2078
2079         /* compute alternate max packet sizes */
2080         uif = udev->actconfig->interface[0];
2081
2082         dev->num_alt = uif->num_altsetting;
2083         dev->alt_max_pkt_size = kmalloc(32 * dev->num_alt, GFP_KERNEL);
2084
2085         if (dev->alt_max_pkt_size == NULL) {
2086                 em28xx_errdev("out of memory!\n");
2087                 em28xx_devused &= ~(1<<nr);
2088                 kfree(dev);
2089                 return -ENOMEM;
2090         }
2091
2092         for (i = 0; i < dev->num_alt ; i++) {
2093                 u16 tmp = le16_to_cpu(uif->altsetting[i].endpoint[isoc_pipe].desc.wMaxPacketSize);
2094                 dev->alt_max_pkt_size[i] =
2095                     (tmp & 0x07ff) * (((tmp & 0x1800) >> 11) + 1);
2096         }
2097
2098         if ((card[nr] >= 0) && (card[nr] < em28xx_bcount))
2099                 dev->model = card[nr];
2100
2101         /* allocate device struct */
2102         mutex_init(&dev->lock);
2103         mutex_lock(&dev->lock);
2104         retval = em28xx_init_dev(&dev, udev, nr);
2105         if (retval) {
2106                 em28xx_devused &= ~(1<<dev->devno);
2107                 kfree(dev);
2108
2109                 return retval;
2110         }
2111
2112         /* save our data pointer in this interface device */
2113         usb_set_intfdata(interface, dev);
2114
2115         request_modules(dev);
2116
2117         /* Should be the last thing to do, to avoid newer udev's to
2118            open the device before fully initializing it
2119          */
2120         mutex_unlock(&dev->lock);
2121
2122         return 0;
2123 }
2124
2125 /*
2126  * em28xx_usb_disconnect()
2127  * called when the device gets diconencted
2128  * video device will be unregistered on v4l2_close in case it is still open
2129  */
2130 static void em28xx_usb_disconnect(struct usb_interface *interface)
2131 {
2132         struct em28xx *dev;
2133
2134         dev = usb_get_intfdata(interface);
2135         usb_set_intfdata(interface, NULL);
2136
2137         if (!dev)
2138                 return;
2139
2140         em28xx_info("disconnecting %s\n", dev->vdev->name);
2141
2142         /* wait until all current v4l2 io is finished then deallocate
2143            resources */
2144         mutex_lock(&dev->lock);
2145
2146         wake_up_interruptible_all(&dev->open);
2147
2148         if (dev->users) {
2149                 em28xx_warn
2150                     ("device /dev/video%d is open! Deregistration and memory "
2151                      "deallocation are deferred on close.\n",
2152                                 dev->vdev->num);
2153
2154                 dev->state |= DEV_MISCONFIGURED;
2155                 em28xx_uninit_isoc(dev);
2156                 dev->state |= DEV_DISCONNECTED;
2157                 wake_up_interruptible(&dev->wait_frame);
2158                 wake_up_interruptible(&dev->wait_stream);
2159         } else {
2160                 dev->state |= DEV_DISCONNECTED;
2161                 em28xx_release_resources(dev);
2162         }
2163
2164         em28xx_close_extension(dev);
2165
2166         mutex_unlock(&dev->lock);
2167
2168         if (!dev->users) {
2169                 kfree(dev->alt_max_pkt_size);
2170                 kfree(dev);
2171         }
2172 }
2173
2174 static struct usb_driver em28xx_usb_driver = {
2175         .name = "em28xx",
2176         .probe = em28xx_usb_probe,
2177         .disconnect = em28xx_usb_disconnect,
2178         .id_table = em28xx_id_table,
2179 };
2180
2181 static int __init em28xx_module_init(void)
2182 {
2183         int result;
2184
2185         /* register this driver with the USB subsystem */
2186         result = usb_register(&em28xx_usb_driver);
2187         if (result)
2188                 em28xx_err(DRIVER_NAME
2189                            " usb_register failed. Error number %d.\n", result);
2190
2191         printk(KERN_INFO DRIVER_NAME " driver loaded\n");
2192
2193         return result;
2194 }
2195
2196 static void __exit em28xx_module_exit(void)
2197 {
2198         /* deregister this driver with the USB subsystem */
2199         usb_deregister(&em28xx_usb_driver);
2200 }
2201
2202 module_init(em28xx_module_init);
2203 module_exit(em28xx_module_exit);