[media] v4l: Remove hardcoded module names passed to v4l2_i2c_new_subdev*
[linux-2.6.git] / 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/slab.h>
28 #include <linux/delay.h>
29 #include <linux/i2c.h>
30 #include <linux/usb.h>
31 #include <media/tuner.h>
32 #include <media/msp3400.h>
33 #include <media/saa7115.h>
34 #include <media/tvp5150.h>
35 #include <media/tvaudio.h>
36 #include <media/i2c-addr.h>
37 #include <media/tveeprom.h>
38 #include <media/v4l2-common.h>
39 #include <media/v4l2-chip-ident.h>
40
41 #include "em28xx.h"
42
43 #define DRIVER_NAME         "em28xx"
44
45 static int tuner = -1;
46 module_param(tuner, int, 0444);
47 MODULE_PARM_DESC(tuner, "tuner type");
48
49 static unsigned int disable_ir;
50 module_param(disable_ir, int, 0444);
51 MODULE_PARM_DESC(disable_ir, "disable infrared remote support");
52
53 static unsigned int disable_usb_speed_check;
54 module_param(disable_usb_speed_check, int, 0444);
55 MODULE_PARM_DESC(disable_usb_speed_check,
56                  "override min bandwidth requirement of 480M bps");
57
58 static unsigned int card[]     = {[0 ... (EM28XX_MAXBOARDS - 1)] = UNSET };
59 module_param_array(card,  int, NULL, 0444);
60 MODULE_PARM_DESC(card,     "card type");
61
62 /* Bitmask marking allocated devices from 0 to EM28XX_MAXBOARDS */
63 static unsigned long em28xx_devused;
64
65 struct em28xx_hash_table {
66         unsigned long hash;
67         unsigned int  model;
68         unsigned int  tuner;
69 };
70
71 /*
72  *  Reset sequences for analog/digital modes
73  */
74
75 /* Reset for the most [analog] boards */
76 static struct em28xx_reg_seq default_analog[] = {
77         {EM28XX_R08_GPIO,       0x6d,   ~EM_GPIO_4,     10},
78         {       -1,             -1,     -1,             -1},
79 };
80
81 /* Reset for the most [digital] boards */
82 static struct em28xx_reg_seq default_digital[] = {
83         {EM28XX_R08_GPIO,       0x6e,   ~EM_GPIO_4,     10},
84         {       -1,             -1,     -1,             -1},
85 };
86
87 /* Board Hauppauge WinTV HVR 900 analog */
88 static struct em28xx_reg_seq hauppauge_wintv_hvr_900_analog[] = {
89         {EM28XX_R08_GPIO,       0x2d,   ~EM_GPIO_4,     10},
90         {0x05,                  0xff,   0x10,           10},
91         {  -1,                  -1,     -1,             -1},
92 };
93
94 /* Board Hauppauge WinTV HVR 900 digital */
95 static struct em28xx_reg_seq hauppauge_wintv_hvr_900_digital[] = {
96         {EM28XX_R08_GPIO,       0x2e,   ~EM_GPIO_4,     10},
97         {EM2880_R04_GPO,        0x04,   0x0f,           10},
98         {EM2880_R04_GPO,        0x0c,   0x0f,           10},
99         { -1,                   -1,     -1,             -1},
100 };
101
102 /* Boards - EM2880 MSI DIGIVOX AD and EM2880_BOARD_MSI_DIGIVOX_AD_II */
103 static struct em28xx_reg_seq em2880_msi_digivox_ad_analog[] = {
104         {EM28XX_R08_GPIO,       0x69,   ~EM_GPIO_4,      10},
105         {       -1,             -1,     -1,              -1},
106 };
107
108 /* Boards - EM2880 MSI DIGIVOX AD and EM2880_BOARD_MSI_DIGIVOX_AD_II */
109
110 /* Board  - EM2870 Kworld 355u
111    Analog - No input analog */
112
113 /* Board - EM2882 Kworld 315U digital */
114 static struct em28xx_reg_seq em2882_kworld_315u_digital[] = {
115         {EM28XX_R08_GPIO,       0xff,   0xff,           10},
116         {EM28XX_R08_GPIO,       0xfe,   0xff,           10},
117         {EM2880_R04_GPO,        0x04,   0xff,           10},
118         {EM2880_R04_GPO,        0x0c,   0xff,           10},
119         {EM28XX_R08_GPIO,       0x7e,   0xff,           10},
120         {  -1,                  -1,     -1,             -1},
121 };
122
123 static struct em28xx_reg_seq em2882_kworld_315u_tuner_gpio[] = {
124         {EM2880_R04_GPO,        0x08,   0xff,           10},
125         {EM2880_R04_GPO,        0x0c,   0xff,           10},
126         {EM2880_R04_GPO,        0x08,   0xff,           10},
127         {EM2880_R04_GPO,        0x0c,   0xff,           10},
128         {  -1,                  -1,     -1,             -1},
129 };
130
131 static struct em28xx_reg_seq kworld_330u_analog[] = {
132         {EM28XX_R08_GPIO,       0x6d,   ~EM_GPIO_4,     10},
133         {EM2880_R04_GPO,        0x00,   0xff,           10},
134         { -1,                   -1,     -1,             -1},
135 };
136
137 static struct em28xx_reg_seq kworld_330u_digital[] = {
138         {EM28XX_R08_GPIO,       0x6e,   ~EM_GPIO_4,     10},
139         {EM2880_R04_GPO,        0x08,   0xff,           10},
140         { -1,                   -1,     -1,             -1},
141 };
142
143 /* Evga inDtube
144    GPIO0 - Enable digital power (s5h1409) - low to enable
145    GPIO1 - Enable analog power (tvp5150/emp202) - low to enable
146    GPIO4 - xc3028 reset
147    GOP3  - s5h1409 reset
148  */
149 static struct em28xx_reg_seq evga_indtube_analog[] = {
150         {EM28XX_R08_GPIO,       0x79,   0xff,           60},
151         {       -1,             -1,     -1,             -1},
152 };
153
154 static struct em28xx_reg_seq evga_indtube_digital[] = {
155         {EM28XX_R08_GPIO,       0x7a,   0xff,            1},
156         {EM2880_R04_GPO,        0x04,   0xff,           10},
157         {EM2880_R04_GPO,        0x0c,   0xff,            1},
158         { -1,                   -1,     -1,             -1},
159 };
160
161 /*
162  * KWorld PlusTV 340U and UB435-Q (ATSC) GPIOs map:
163  * EM_GPIO_0 - currently unknown
164  * EM_GPIO_1 - LED disable/enable (1 = off, 0 = on)
165  * EM_GPIO_2 - currently unknown
166  * EM_GPIO_3 - currently unknown
167  * EM_GPIO_4 - TDA18271HD/C1 tuner (1 = active, 0 = in reset)
168  * EM_GPIO_5 - LGDT3304 ATSC/QAM demod (1 = active, 0 = in reset)
169  * EM_GPIO_6 - currently unknown
170  * EM_GPIO_7 - currently unknown
171  */
172 static struct em28xx_reg_seq kworld_a340_digital[] = {
173         {EM28XX_R08_GPIO,       0x6d,           ~EM_GPIO_4,     10},
174         { -1,                   -1,             -1,             -1},
175 };
176
177 /* Pinnacle Hybrid Pro eb1a:2881 */
178 static struct em28xx_reg_seq pinnacle_hybrid_pro_analog[] = {
179         {EM28XX_R08_GPIO,       0xfd,   ~EM_GPIO_4,     10},
180         {       -1,             -1,     -1,             -1},
181 };
182
183 static struct em28xx_reg_seq pinnacle_hybrid_pro_digital[] = {
184         {EM28XX_R08_GPIO,       0x6e,   ~EM_GPIO_4,     10},
185         {EM2880_R04_GPO,        0x04,   0xff,          100},/* zl10353 reset */
186         {EM2880_R04_GPO,        0x0c,   0xff,            1},
187         {       -1,             -1,     -1,             -1},
188 };
189
190 static struct em28xx_reg_seq terratec_cinergy_USB_XS_FR_analog[] = {
191         {EM28XX_R08_GPIO,       0x6d,   ~EM_GPIO_4,     10},
192         {EM2880_R04_GPO,        0x00,   0xff,           10},
193         { -1,                   -1,     -1,             -1},
194 };
195
196 static struct em28xx_reg_seq terratec_cinergy_USB_XS_FR_digital[] = {
197         {EM28XX_R08_GPIO,       0x6e,   ~EM_GPIO_4,     10},
198         {EM2880_R04_GPO,        0x08,   0xff,           10},
199         { -1,                   -1,     -1,             -1},
200 };
201
202 /* eb1a:2868 Reddo DVB-C USB TV Box
203    GPIO4 - CU1216L NIM
204    Other GPIOs seems to be don't care. */
205 static struct em28xx_reg_seq reddo_dvb_c_usb_box[] = {
206         {EM28XX_R08_GPIO,       0xfe,   0xff,           10},
207         {EM28XX_R08_GPIO,       0xde,   0xff,           10},
208         {EM28XX_R08_GPIO,       0xfe,   0xff,           10},
209         {EM28XX_R08_GPIO,       0xff,   0xff,           10},
210         {EM28XX_R08_GPIO,       0x7f,   0xff,           10},
211         {EM28XX_R08_GPIO,       0x6f,   0xff,           10},
212         {EM28XX_R08_GPIO,       0xff,   0xff,           10},
213         {-1,                    -1,     -1,             -1},
214 };
215
216 /* Callback for the most boards */
217 static struct em28xx_reg_seq default_tuner_gpio[] = {
218         {EM28XX_R08_GPIO,       EM_GPIO_4,      EM_GPIO_4,      10},
219         {EM28XX_R08_GPIO,       0,              EM_GPIO_4,      10},
220         {EM28XX_R08_GPIO,       EM_GPIO_4,      EM_GPIO_4,      10},
221         {  -1,                  -1,             -1,             -1},
222 };
223
224 /* Mute/unmute */
225 static struct em28xx_reg_seq compro_unmute_tv_gpio[] = {
226         {EM28XX_R08_GPIO,       5,              7,              10},
227         {  -1,                  -1,             -1,             -1},
228 };
229
230 static struct em28xx_reg_seq compro_unmute_svid_gpio[] = {
231         {EM28XX_R08_GPIO,       4,              7,              10},
232         {  -1,                  -1,             -1,             -1},
233 };
234
235 static struct em28xx_reg_seq compro_mute_gpio[] = {
236         {EM28XX_R08_GPIO,       6,              7,              10},
237         {  -1,                  -1,             -1,             -1},
238 };
239
240 /* Terratec AV350 */
241 static struct em28xx_reg_seq terratec_av350_mute_gpio[] = {
242         {EM28XX_R08_GPIO,       0xff,   0x7f,           10},
243         {       -1,             -1,     -1,             -1},
244 };
245
246 static struct em28xx_reg_seq terratec_av350_unmute_gpio[] = {
247         {EM28XX_R08_GPIO,       0xff,   0xff,           10},
248         {       -1,             -1,     -1,             -1},
249 };
250
251 static struct em28xx_reg_seq silvercrest_reg_seq[] = {
252         {EM28XX_R08_GPIO,       0xff,   0xff,           10},
253         {EM28XX_R08_GPIO,       0x01,   0xf7,           10},
254         {       -1,             -1,     -1,             -1},
255 };
256
257 static struct em28xx_reg_seq vc211a_enable[] = {
258         {EM28XX_R08_GPIO,       0xff,   0x07,           10},
259         {EM28XX_R08_GPIO,       0xff,   0x0f,           10},
260         {EM28XX_R08_GPIO,       0xff,   0x0b,           10},
261         {       -1,             -1,     -1,             -1},
262 };
263
264 static struct em28xx_reg_seq dikom_dk300_digital[] = {
265         {EM28XX_R08_GPIO,       0x6e,   ~EM_GPIO_4,     10},
266         {EM2880_R04_GPO,        0x08,   0xff,           10},
267         { -1,                   -1,     -1,             -1},
268 };
269
270
271 /*
272  *  Board definitions
273  */
274 struct em28xx_board em28xx_boards[] = {
275         [EM2750_BOARD_UNKNOWN] = {
276                 .name          = "EM2710/EM2750/EM2751 webcam grabber",
277                 .xclk          = EM28XX_XCLK_FREQUENCY_20MHZ,
278                 .tuner_type    = TUNER_ABSENT,
279                 .is_webcam     = 1,
280                 .input         = { {
281                         .type     = EM28XX_VMUX_COMPOSITE1,
282                         .vmux     = 0,
283                         .amux     = EM28XX_AMUX_VIDEO,
284                         .gpio     = silvercrest_reg_seq,
285                 } },
286         },
287         [EM2800_BOARD_UNKNOWN] = {
288                 .name         = "Unknown EM2800 video grabber",
289                 .is_em2800    = 1,
290                 .tda9887_conf = TDA9887_PRESENT,
291                 .decoder      = EM28XX_SAA711X,
292                 .tuner_type   = TUNER_ABSENT,
293                 .input        = { {
294                         .type     = EM28XX_VMUX_COMPOSITE1,
295                         .vmux     = SAA7115_COMPOSITE0,
296                         .amux     = EM28XX_AMUX_LINE_IN,
297                 }, {
298                         .type     = EM28XX_VMUX_SVIDEO,
299                         .vmux     = SAA7115_SVIDEO3,
300                         .amux     = EM28XX_AMUX_LINE_IN,
301                 } },
302         },
303         [EM2820_BOARD_UNKNOWN] = {
304                 .name          = "Unknown EM2750/28xx video grabber",
305                 .tuner_type    = TUNER_ABSENT,
306                 .is_webcam     = 1,     /* To enable sensor probe */
307         },
308         [EM2750_BOARD_DLCW_130] = {
309                 /* Beijing Huaqi Information Digital Technology Co., Ltd */
310                 .name          = "Huaqi DLCW-130",
311                 .valid         = EM28XX_BOARD_NOT_VALIDATED,
312                 .xclk          = EM28XX_XCLK_FREQUENCY_48MHZ,
313                 .tuner_type    = TUNER_ABSENT,
314                 .is_webcam     = 1,
315                 .input         = { {
316                         .type     = EM28XX_VMUX_COMPOSITE1,
317                         .vmux     = 0,
318                         .amux     = EM28XX_AMUX_VIDEO,
319                 } },
320         },
321         [EM2820_BOARD_KWORLD_PVRTV2800RF] = {
322                 .name         = "Kworld PVR TV 2800 RF",
323                 .tuner_type   = TUNER_TEMIC_PAL,
324                 .tda9887_conf = TDA9887_PRESENT,
325                 .decoder      = EM28XX_SAA711X,
326                 .input        = { {
327                         .type     = EM28XX_VMUX_COMPOSITE1,
328                         .vmux     = SAA7115_COMPOSITE0,
329                         .amux     = EM28XX_AMUX_LINE_IN,
330                 }, {
331                         .type     = EM28XX_VMUX_SVIDEO,
332                         .vmux     = SAA7115_SVIDEO3,
333                         .amux     = EM28XX_AMUX_LINE_IN,
334                 } },
335         },
336         [EM2820_BOARD_GADMEI_TVR200] = {
337                 .name         = "Gadmei TVR200",
338                 .tuner_type   = TUNER_LG_PAL_NEW_TAPC,
339                 .tda9887_conf = TDA9887_PRESENT,
340                 .decoder      = EM28XX_SAA711X,
341                 .input        = { {
342                         .type     = EM28XX_VMUX_TELEVISION,
343                         .vmux     = SAA7115_COMPOSITE2,
344                         .amux     = EM28XX_AMUX_LINE_IN,
345                 }, {
346                         .type     = EM28XX_VMUX_COMPOSITE1,
347                         .vmux     = SAA7115_COMPOSITE0,
348                         .amux     = EM28XX_AMUX_LINE_IN,
349                 }, {
350                         .type     = EM28XX_VMUX_SVIDEO,
351                         .vmux     = SAA7115_SVIDEO3,
352                         .amux     = EM28XX_AMUX_LINE_IN,
353                 } },
354         },
355         [EM2820_BOARD_TERRATEC_CINERGY_250] = {
356                 .name         = "Terratec Cinergy 250 USB",
357                 .tuner_type   = TUNER_LG_PAL_NEW_TAPC,
358                 .has_ir_i2c   = 1,
359                 .tda9887_conf = TDA9887_PRESENT,
360                 .decoder      = EM28XX_SAA711X,
361                 .input        = { {
362                         .type     = EM28XX_VMUX_TELEVISION,
363                         .vmux     = SAA7115_COMPOSITE2,
364                         .amux     = EM28XX_AMUX_LINE_IN,
365                 }, {
366                         .type     = EM28XX_VMUX_COMPOSITE1,
367                         .vmux     = SAA7115_COMPOSITE0,
368                         .amux     = EM28XX_AMUX_LINE_IN,
369                 }, {
370                         .type     = EM28XX_VMUX_SVIDEO,
371                         .vmux     = SAA7115_SVIDEO3,
372                         .amux     = EM28XX_AMUX_LINE_IN,
373                 } },
374         },
375         [EM2820_BOARD_PINNACLE_USB_2] = {
376                 .name         = "Pinnacle PCTV USB 2",
377                 .tuner_type   = TUNER_LG_PAL_NEW_TAPC,
378                 .has_ir_i2c   = 1,
379                 .tda9887_conf = TDA9887_PRESENT,
380                 .decoder      = EM28XX_SAA711X,
381                 .input        = { {
382                         .type     = EM28XX_VMUX_TELEVISION,
383                         .vmux     = SAA7115_COMPOSITE2,
384                         .amux     = EM28XX_AMUX_VIDEO,
385                 }, {
386                         .type     = EM28XX_VMUX_COMPOSITE1,
387                         .vmux     = SAA7115_COMPOSITE0,
388                         .amux     = EM28XX_AMUX_LINE_IN,
389                 }, {
390                         .type     = EM28XX_VMUX_SVIDEO,
391                         .vmux     = SAA7115_SVIDEO3,
392                         .amux     = EM28XX_AMUX_LINE_IN,
393                 } },
394         },
395         [EM2820_BOARD_HAUPPAUGE_WINTV_USB_2] = {
396                 .name         = "Hauppauge WinTV USB 2",
397                 .tuner_type   = TUNER_PHILIPS_FM1236_MK3,
398                 .tda9887_conf = TDA9887_PRESENT |
399                                 TDA9887_PORT1_ACTIVE |
400                                 TDA9887_PORT2_ACTIVE,
401                 .decoder      = EM28XX_TVP5150,
402                 .has_msp34xx  = 1,
403                 .has_ir_i2c   = 1,
404                 .input        = { {
405                         .type     = EM28XX_VMUX_TELEVISION,
406                         .vmux     = TVP5150_COMPOSITE0,
407                         .amux     = MSP_INPUT_DEFAULT,
408                 }, {
409                         .type     = EM28XX_VMUX_SVIDEO,
410                         .vmux     = TVP5150_SVIDEO,
411                         .amux     = MSP_INPUT(MSP_IN_SCART1, MSP_IN_TUNER1,
412                                         MSP_DSP_IN_SCART, MSP_DSP_IN_SCART),
413                 } },
414         },
415         [EM2820_BOARD_DLINK_USB_TV] = {
416                 .name         = "D-Link DUB-T210 TV Tuner",
417                 .valid        = EM28XX_BOARD_NOT_VALIDATED,
418                 .tuner_type   = TUNER_LG_PAL_NEW_TAPC,
419                 .tda9887_conf = TDA9887_PRESENT,
420                 .decoder      = EM28XX_SAA711X,
421                 .input        = { {
422                         .type     = EM28XX_VMUX_TELEVISION,
423                         .vmux     = SAA7115_COMPOSITE2,
424                         .amux     = EM28XX_AMUX_LINE_IN,
425                 }, {
426                         .type     = EM28XX_VMUX_COMPOSITE1,
427                         .vmux     = SAA7115_COMPOSITE0,
428                         .amux     = EM28XX_AMUX_LINE_IN,
429                 }, {
430                         .type     = EM28XX_VMUX_SVIDEO,
431                         .vmux     = SAA7115_SVIDEO3,
432                         .amux     = EM28XX_AMUX_LINE_IN,
433                 } },
434         },
435         [EM2820_BOARD_HERCULES_SMART_TV_USB2] = {
436                 .name         = "Hercules Smart TV USB 2.0",
437                 .valid        = EM28XX_BOARD_NOT_VALIDATED,
438                 .tuner_type   = TUNER_LG_PAL_NEW_TAPC,
439                 .tda9887_conf = TDA9887_PRESENT,
440                 .decoder      = EM28XX_SAA711X,
441                 .input        = { {
442                         .type     = EM28XX_VMUX_TELEVISION,
443                         .vmux     = SAA7115_COMPOSITE2,
444                         .amux     = EM28XX_AMUX_LINE_IN,
445                 }, {
446                         .type     = EM28XX_VMUX_COMPOSITE1,
447                         .vmux     = SAA7115_COMPOSITE0,
448                         .amux     = EM28XX_AMUX_LINE_IN,
449                 }, {
450                         .type     = EM28XX_VMUX_SVIDEO,
451                         .vmux     = SAA7115_SVIDEO3,
452                         .amux     = EM28XX_AMUX_LINE_IN,
453                 } },
454         },
455         [EM2820_BOARD_PINNACLE_USB_2_FM1216ME] = {
456                 .name         = "Pinnacle PCTV USB 2 (Philips FM1216ME)",
457                 .valid        = EM28XX_BOARD_NOT_VALIDATED,
458                 .tuner_type   = TUNER_PHILIPS_FM1216ME_MK3,
459                 .tda9887_conf = TDA9887_PRESENT,
460                 .decoder      = EM28XX_SAA711X,
461                 .input        = { {
462                         .type     = EM28XX_VMUX_TELEVISION,
463                         .vmux     = SAA7115_COMPOSITE2,
464                         .amux     = EM28XX_AMUX_VIDEO,
465                 }, {
466                         .type     = EM28XX_VMUX_COMPOSITE1,
467                         .vmux     = SAA7115_COMPOSITE0,
468                         .amux     = EM28XX_AMUX_LINE_IN,
469                 }, {
470                         .type     = EM28XX_VMUX_SVIDEO,
471                         .vmux     = SAA7115_SVIDEO3,
472                         .amux     = EM28XX_AMUX_LINE_IN,
473                 } },
474         },
475         [EM2820_BOARD_GADMEI_UTV310] = {
476                 .name         = "Gadmei UTV310",
477                 .valid        = EM28XX_BOARD_NOT_VALIDATED,
478                 .tuner_type   = TUNER_TNF_5335MF,
479                 .tda9887_conf = TDA9887_PRESENT,
480                 .decoder      = EM28XX_SAA711X,
481                 .input        = { {
482                         .type     = EM28XX_VMUX_TELEVISION,
483                         .vmux     = SAA7115_COMPOSITE1,
484                         .amux     = EM28XX_AMUX_LINE_IN,
485                 }, {
486                         .type     = EM28XX_VMUX_COMPOSITE1,
487                         .vmux     = SAA7115_COMPOSITE0,
488                         .amux     = EM28XX_AMUX_LINE_IN,
489                 }, {
490                         .type     = EM28XX_VMUX_SVIDEO,
491                         .vmux     = SAA7115_SVIDEO3,
492                         .amux     = EM28XX_AMUX_LINE_IN,
493                 } },
494         },
495         [EM2820_BOARD_LEADTEK_WINFAST_USBII_DELUXE] = {
496                 .name         = "Leadtek Winfast USB II Deluxe",
497                 .valid        = EM28XX_BOARD_NOT_VALIDATED,
498                 .tuner_type   = TUNER_PHILIPS_FM1216ME_MK3,
499                 .has_ir_i2c   = 1,
500                 .tvaudio_addr = 0x58,
501                 .tda9887_conf = TDA9887_PRESENT |
502                                 TDA9887_PORT2_ACTIVE |
503                                 TDA9887_QSS,
504                 .decoder      = EM28XX_SAA711X,
505                 .adecoder     = EM28XX_TVAUDIO,
506                 .input        = { {
507                         .type     = EM28XX_VMUX_TELEVISION,
508                         .vmux     = SAA7115_COMPOSITE4,
509                         .amux     = EM28XX_AMUX_AUX,
510                 }, {
511                         .type     = EM28XX_VMUX_COMPOSITE1,
512                         .vmux     = SAA7115_COMPOSITE5,
513                         .amux     = EM28XX_AMUX_LINE_IN,
514                 }, {
515                         .type     = EM28XX_VMUX_SVIDEO,
516                         .vmux     = SAA7115_SVIDEO3,
517                         .amux     = EM28XX_AMUX_LINE_IN,
518                 } },
519                         .radio    = {
520                         .type     = EM28XX_RADIO,
521                         .amux     = EM28XX_AMUX_AUX,
522                         }
523         },
524         [EM2820_BOARD_VIDEOLOGY_20K14XUSB] = {
525                 .name         = "Videology 20K14XUSB USB2.0",
526                 .valid        = EM28XX_BOARD_NOT_VALIDATED,
527                 .tuner_type   = TUNER_ABSENT,
528                 .is_webcam    = 1,
529                 .input        = { {
530                         .type     = EM28XX_VMUX_COMPOSITE1,
531                         .vmux     = 0,
532                         .amux     = EM28XX_AMUX_VIDEO,
533                 } },
534         },
535         [EM2820_BOARD_SILVERCREST_WEBCAM] = {
536                 .name         = "Silvercrest Webcam 1.3mpix",
537                 .tuner_type   = TUNER_ABSENT,
538                 .is_webcam    = 1,
539                 .input        = { {
540                         .type     = EM28XX_VMUX_COMPOSITE1,
541                         .vmux     = 0,
542                         .amux     = EM28XX_AMUX_VIDEO,
543                         .gpio     = silvercrest_reg_seq,
544                 } },
545         },
546         [EM2821_BOARD_SUPERCOMP_USB_2] = {
547                 .name         = "Supercomp USB 2.0 TV",
548                 .valid        = EM28XX_BOARD_NOT_VALIDATED,
549                 .tuner_type   = TUNER_PHILIPS_FM1236_MK3,
550                 .tda9887_conf = TDA9887_PRESENT |
551                                 TDA9887_PORT1_ACTIVE |
552                                 TDA9887_PORT2_ACTIVE,
553                 .decoder      = EM28XX_SAA711X,
554                 .input        = { {
555                         .type     = EM28XX_VMUX_TELEVISION,
556                         .vmux     = SAA7115_COMPOSITE2,
557                         .amux     = EM28XX_AMUX_LINE_IN,
558                 }, {
559                         .type     = EM28XX_VMUX_COMPOSITE1,
560                         .vmux     = SAA7115_COMPOSITE0,
561                         .amux     = EM28XX_AMUX_VIDEO,
562                 }, {
563                         .type     = EM28XX_VMUX_SVIDEO,
564                         .vmux     = SAA7115_SVIDEO3,
565                         .amux     = EM28XX_AMUX_LINE_IN,
566                 } },
567         },
568         [EM2821_BOARD_USBGEAR_VD204] = {
569                 .name         = "Usbgear VD204v9",
570                 .valid        = EM28XX_BOARD_NOT_VALIDATED,
571                 .tuner_type   = TUNER_ABSENT,   /* Capture only device */
572                 .decoder      = EM28XX_SAA711X,
573                 .input        = { {
574                         .type  = EM28XX_VMUX_COMPOSITE1,
575                         .vmux  = SAA7115_COMPOSITE0,
576                         .amux  = EM28XX_AMUX_LINE_IN,
577                 }, {
578                         .type  = EM28XX_VMUX_SVIDEO,
579                         .vmux  = SAA7115_SVIDEO3,
580                         .amux  = EM28XX_AMUX_LINE_IN,
581                 } },
582         },
583         [EM2860_BOARD_NETGMBH_CAM] = {
584                 /* Beijing Huaqi Information Digital Technology Co., Ltd */
585                 .name         = "NetGMBH Cam",
586                 .valid        = EM28XX_BOARD_NOT_VALIDATED,
587                 .tuner_type   = TUNER_ABSENT,
588                 .is_webcam    = 1,
589                 .input        = { {
590                         .type     = EM28XX_VMUX_COMPOSITE1,
591                         .vmux     = 0,
592                         .amux     = EM28XX_AMUX_VIDEO,
593                 } },
594         },
595         [EM2860_BOARD_TYPHOON_DVD_MAKER] = {
596                 .name         = "Typhoon DVD Maker",
597                 .decoder      = EM28XX_SAA711X,
598                 .tuner_type   = TUNER_ABSENT,   /* Capture only device */
599                 .input        = { {
600                         .type  = EM28XX_VMUX_COMPOSITE1,
601                         .vmux  = SAA7115_COMPOSITE0,
602                         .amux  = EM28XX_AMUX_LINE_IN,
603                 }, {
604                         .type  = EM28XX_VMUX_SVIDEO,
605                         .vmux  = SAA7115_SVIDEO3,
606                         .amux  = EM28XX_AMUX_LINE_IN,
607                 } },
608         },
609         [EM2860_BOARD_GADMEI_UTV330] = {
610                 .name         = "Gadmei UTV330",
611                 .valid        = EM28XX_BOARD_NOT_VALIDATED,
612                 .tuner_type   = TUNER_TNF_5335MF,
613                 .tda9887_conf = TDA9887_PRESENT,
614                 .decoder      = EM28XX_SAA711X,
615                 .input        = { {
616                         .type     = EM28XX_VMUX_TELEVISION,
617                         .vmux     = SAA7115_COMPOSITE2,
618                         .amux     = EM28XX_AMUX_VIDEO,
619                 }, {
620                         .type     = EM28XX_VMUX_COMPOSITE1,
621                         .vmux     = SAA7115_COMPOSITE0,
622                         .amux     = EM28XX_AMUX_LINE_IN,
623                 }, {
624                         .type     = EM28XX_VMUX_SVIDEO,
625                         .vmux     = SAA7115_SVIDEO3,
626                         .amux     = EM28XX_AMUX_LINE_IN,
627                 } },
628         },
629         [EM2861_BOARD_GADMEI_UTV330PLUS] = {
630                 .name         = "Gadmei UTV330+",
631                 .tuner_type   = TUNER_TNF_5335MF,
632                 .tda9887_conf = TDA9887_PRESENT,
633                 .ir_codes     = RC_MAP_GADMEI_RM008Z,
634                 .decoder      = EM28XX_SAA711X,
635                 .xclk         = EM28XX_XCLK_FREQUENCY_12MHZ,
636                 .input        = { {
637                         .type     = EM28XX_VMUX_TELEVISION,
638                         .vmux     = SAA7115_COMPOSITE2,
639                         .amux     = EM28XX_AMUX_VIDEO,
640                 }, {
641                         .type     = EM28XX_VMUX_COMPOSITE1,
642                         .vmux     = SAA7115_COMPOSITE0,
643                         .amux     = EM28XX_AMUX_LINE_IN,
644                 }, {
645                         .type     = EM28XX_VMUX_SVIDEO,
646                         .vmux     = SAA7115_SVIDEO3,
647                         .amux     = EM28XX_AMUX_LINE_IN,
648                 } },
649         },
650         [EM2860_BOARD_TERRATEC_HYBRID_XS] = {
651                 .name         = "Terratec Cinergy A Hybrid XS",
652                 .valid        = EM28XX_BOARD_NOT_VALIDATED,
653                 .tuner_type   = TUNER_XC2028,
654                 .tuner_gpio   = default_tuner_gpio,
655                 .decoder      = EM28XX_TVP5150,
656
657                 .input        = { {
658                         .type     = EM28XX_VMUX_TELEVISION,
659                         .vmux     = TVP5150_COMPOSITE0,
660                         .amux     = EM28XX_AMUX_VIDEO,
661                         .gpio     = hauppauge_wintv_hvr_900_analog,
662                 }, {
663                         .type     = EM28XX_VMUX_COMPOSITE1,
664                         .vmux     = TVP5150_COMPOSITE1,
665                         .amux     = EM28XX_AMUX_LINE_IN,
666                         .gpio     = hauppauge_wintv_hvr_900_analog,
667                 }, {
668                         .type     = EM28XX_VMUX_SVIDEO,
669                         .vmux     = TVP5150_SVIDEO,
670                         .amux     = EM28XX_AMUX_LINE_IN,
671                         .gpio     = hauppauge_wintv_hvr_900_analog,
672                 } },
673         },
674         [EM2861_BOARD_KWORLD_PVRTV_300U] = {
675                 .name         = "KWorld PVRTV 300U",
676                 .valid        = EM28XX_BOARD_NOT_VALIDATED,
677                 .tuner_type   = TUNER_XC2028,
678                 .tuner_gpio   = default_tuner_gpio,
679                 .decoder      = EM28XX_TVP5150,
680                 .input        = { {
681                         .type     = EM28XX_VMUX_TELEVISION,
682                         .vmux     = TVP5150_COMPOSITE0,
683                         .amux     = EM28XX_AMUX_VIDEO,
684                 }, {
685                         .type     = EM28XX_VMUX_COMPOSITE1,
686                         .vmux     = TVP5150_COMPOSITE1,
687                         .amux     = EM28XX_AMUX_LINE_IN,
688                 }, {
689                         .type     = EM28XX_VMUX_SVIDEO,
690                         .vmux     = TVP5150_SVIDEO,
691                         .amux     = EM28XX_AMUX_LINE_IN,
692                 } },
693         },
694         [EM2861_BOARD_YAKUMO_MOVIE_MIXER] = {
695                 .name          = "Yakumo MovieMixer",
696                 .tuner_type    = TUNER_ABSENT,  /* Capture only device */
697                 .decoder       = EM28XX_TVP5150,
698                 .input         = { {
699                         .type     = EM28XX_VMUX_TELEVISION,
700                         .vmux     = TVP5150_COMPOSITE0,
701                         .amux     = EM28XX_AMUX_VIDEO,
702                 }, {
703                         .type     = EM28XX_VMUX_COMPOSITE1,
704                         .vmux     = TVP5150_COMPOSITE1,
705                         .amux     = EM28XX_AMUX_LINE_IN,
706                 }, {
707                         .type     = EM28XX_VMUX_SVIDEO,
708                         .vmux     = TVP5150_SVIDEO,
709                         .amux     = EM28XX_AMUX_LINE_IN,
710                 } },
711         },
712         [EM2860_BOARD_TVP5150_REFERENCE_DESIGN] = {
713                 .name          = "EM2860/TVP5150 Reference Design",
714                 .tuner_type    = TUNER_ABSENT,  /* Capture only device */
715                 .decoder       = EM28XX_TVP5150,
716                 .input         = { {
717                         .type     = EM28XX_VMUX_COMPOSITE1,
718                         .vmux     = TVP5150_COMPOSITE1,
719                         .amux     = EM28XX_AMUX_LINE_IN,
720                 }, {
721                         .type     = EM28XX_VMUX_SVIDEO,
722                         .vmux     = TVP5150_SVIDEO,
723                         .amux     = EM28XX_AMUX_LINE_IN,
724                 } },
725         },
726         [EM2861_BOARD_PLEXTOR_PX_TV100U] = {
727                 .name         = "Plextor ConvertX PX-TV100U",
728                 .tuner_type   = TUNER_TNF_5335MF,
729                 .xclk         = EM28XX_XCLK_I2S_MSB_TIMING |
730                                 EM28XX_XCLK_FREQUENCY_12MHZ,
731                 .tda9887_conf = TDA9887_PRESENT,
732                 .decoder      = EM28XX_TVP5150,
733                 .has_msp34xx  = 1,
734                 .input        = { {
735                         .type     = EM28XX_VMUX_TELEVISION,
736                         .vmux     = TVP5150_COMPOSITE0,
737                         .amux     = EM28XX_AMUX_LINE_IN,
738                         .gpio     = pinnacle_hybrid_pro_analog,
739                 }, {
740                         .type     = EM28XX_VMUX_COMPOSITE1,
741                         .vmux     = TVP5150_COMPOSITE1,
742                         .amux     = EM28XX_AMUX_LINE_IN,
743                         .gpio     = pinnacle_hybrid_pro_analog,
744                 }, {
745                         .type     = EM28XX_VMUX_SVIDEO,
746                         .vmux     = TVP5150_SVIDEO,
747                         .amux     = EM28XX_AMUX_LINE_IN,
748                         .gpio     = pinnacle_hybrid_pro_analog,
749                 } },
750         },
751
752         /* Those boards with em2870 are DVB Only*/
753
754         [EM2870_BOARD_TERRATEC_XS] = {
755                 .name         = "Terratec Cinergy T XS",
756                 .valid        = EM28XX_BOARD_NOT_VALIDATED,
757                 .tuner_type   = TUNER_XC2028,
758                 .tuner_gpio   = default_tuner_gpio,
759         },
760         [EM2870_BOARD_TERRATEC_XS_MT2060] = {
761                 .name         = "Terratec Cinergy T XS (MT2060)",
762                 .valid        = EM28XX_BOARD_NOT_VALIDATED,
763                 .tuner_type   = TUNER_ABSENT, /* MT2060 */
764         },
765         [EM2870_BOARD_KWORLD_350U] = {
766                 .name         = "Kworld 350 U DVB-T",
767                 .valid        = EM28XX_BOARD_NOT_VALIDATED,
768                 .tuner_type   = TUNER_XC2028,
769                 .tuner_gpio   = default_tuner_gpio,
770         },
771         [EM2870_BOARD_KWORLD_355U] = {
772                 .name         = "Kworld 355 U DVB-T",
773                 .valid        = EM28XX_BOARD_NOT_VALIDATED,
774         },
775         [EM2870_BOARD_PINNACLE_PCTV_DVB] = {
776                 .name         = "Pinnacle PCTV DVB-T",
777                 .valid        = EM28XX_BOARD_NOT_VALIDATED,
778                 .tuner_type   = TUNER_ABSENT, /* MT2060 */
779                 /* djh - I have serious doubts this is right... */
780                 .xclk         = EM28XX_XCLK_IR_RC5_MODE |
781                                 EM28XX_XCLK_FREQUENCY_10MHZ,
782         },
783         [EM2870_BOARD_COMPRO_VIDEOMATE] = {
784                 .name         = "Compro, VideoMate U3",
785                 .valid        = EM28XX_BOARD_NOT_VALIDATED,
786                 .tuner_type   = TUNER_ABSENT, /* MT2060 */
787         },
788
789         [EM2880_BOARD_TERRATEC_HYBRID_XS_FR] = {
790                 .name         = "Terratec Hybrid XS Secam",
791                 .has_msp34xx  = 1,
792                 .tuner_type   = TUNER_XC2028,
793                 .tuner_gpio   = default_tuner_gpio,
794                 .decoder      = EM28XX_TVP5150,
795                 .has_dvb      = 1,
796                 .dvb_gpio     = terratec_cinergy_USB_XS_FR_digital,
797                 .input        = { {
798                         .type     = EM28XX_VMUX_TELEVISION,
799                         .vmux     = TVP5150_COMPOSITE0,
800                         .amux     = EM28XX_AMUX_VIDEO,
801                         .gpio     = terratec_cinergy_USB_XS_FR_analog,
802                 }, {
803                         .type     = EM28XX_VMUX_COMPOSITE1,
804                         .vmux     = TVP5150_COMPOSITE1,
805                         .amux     = EM28XX_AMUX_LINE_IN,
806                         .gpio     = terratec_cinergy_USB_XS_FR_analog,
807                 }, {
808                         .type     = EM28XX_VMUX_SVIDEO,
809                         .vmux     = TVP5150_SVIDEO,
810                         .amux     = EM28XX_AMUX_LINE_IN,
811                         .gpio     = terratec_cinergy_USB_XS_FR_analog,
812                 } },
813         },
814         [EM2880_BOARD_HAUPPAUGE_WINTV_HVR_900] = {
815                 .name         = "Hauppauge WinTV HVR 900",
816                 .tda9887_conf = TDA9887_PRESENT,
817                 .tuner_type   = TUNER_XC2028,
818                 .tuner_gpio   = default_tuner_gpio,
819                 .mts_firmware = 1,
820                 .has_dvb      = 1,
821                 .dvb_gpio     = hauppauge_wintv_hvr_900_digital,
822                 .ir_codes     = RC_MAP_HAUPPAUGE_NEW,
823                 .decoder      = EM28XX_TVP5150,
824                 .input        = { {
825                         .type     = EM28XX_VMUX_TELEVISION,
826                         .vmux     = TVP5150_COMPOSITE0,
827                         .amux     = EM28XX_AMUX_VIDEO,
828                         .gpio     = hauppauge_wintv_hvr_900_analog,
829                 }, {
830                         .type     = EM28XX_VMUX_COMPOSITE1,
831                         .vmux     = TVP5150_COMPOSITE1,
832                         .amux     = EM28XX_AMUX_LINE_IN,
833                         .gpio     = hauppauge_wintv_hvr_900_analog,
834                 }, {
835                         .type     = EM28XX_VMUX_SVIDEO,
836                         .vmux     = TVP5150_SVIDEO,
837                         .amux     = EM28XX_AMUX_LINE_IN,
838                         .gpio     = hauppauge_wintv_hvr_900_analog,
839                 } },
840         },
841         [EM2880_BOARD_HAUPPAUGE_WINTV_HVR_900_R2] = {
842                 .name         = "Hauppauge WinTV HVR 900 (R2)",
843                 .tda9887_conf = TDA9887_PRESENT,
844                 .tuner_type   = TUNER_XC2028,
845                 .tuner_gpio   = default_tuner_gpio,
846                 .mts_firmware = 1,
847                 .ir_codes     = RC_MAP_HAUPPAUGE_NEW,
848                 .decoder      = EM28XX_TVP5150,
849                 .input        = { {
850                         .type     = EM28XX_VMUX_TELEVISION,
851                         .vmux     = TVP5150_COMPOSITE0,
852                         .amux     = EM28XX_AMUX_VIDEO,
853                         .gpio     = hauppauge_wintv_hvr_900_analog,
854                 }, {
855                         .type     = EM28XX_VMUX_COMPOSITE1,
856                         .vmux     = TVP5150_COMPOSITE1,
857                         .amux     = EM28XX_AMUX_LINE_IN,
858                         .gpio     = hauppauge_wintv_hvr_900_analog,
859                 }, {
860                         .type     = EM28XX_VMUX_SVIDEO,
861                         .vmux     = TVP5150_SVIDEO,
862                         .amux     = EM28XX_AMUX_LINE_IN,
863                         .gpio     = hauppauge_wintv_hvr_900_analog,
864                 } },
865         },
866         [EM2883_BOARD_HAUPPAUGE_WINTV_HVR_850] = {
867                 .name           = "Hauppauge WinTV HVR 850",
868                 .tuner_type     = TUNER_XC2028,
869                 .tuner_gpio     = default_tuner_gpio,
870                 .mts_firmware   = 1,
871                 .has_dvb        = 1,
872                 .dvb_gpio       = hauppauge_wintv_hvr_900_digital,
873                 .ir_codes       = RC_MAP_HAUPPAUGE_NEW,
874                 .decoder        = EM28XX_TVP5150,
875                 .input          = { {
876                         .type     = EM28XX_VMUX_TELEVISION,
877                         .vmux     = TVP5150_COMPOSITE0,
878                         .amux     = EM28XX_AMUX_VIDEO,
879                         .gpio     = hauppauge_wintv_hvr_900_analog,
880                 }, {
881                         .type     = EM28XX_VMUX_COMPOSITE1,
882                         .vmux     = TVP5150_COMPOSITE1,
883                         .amux     = EM28XX_AMUX_LINE_IN,
884                         .gpio     = hauppauge_wintv_hvr_900_analog,
885                 }, {
886                         .type     = EM28XX_VMUX_SVIDEO,
887                         .vmux     = TVP5150_SVIDEO,
888                         .amux     = EM28XX_AMUX_LINE_IN,
889                         .gpio     = hauppauge_wintv_hvr_900_analog,
890                 } },
891         },
892         [EM2883_BOARD_HAUPPAUGE_WINTV_HVR_950] = {
893                 .name           = "Hauppauge WinTV HVR 950",
894                 .tuner_type     = TUNER_XC2028,
895                 .tuner_gpio     = default_tuner_gpio,
896                 .mts_firmware   = 1,
897                 .has_dvb        = 1,
898                 .dvb_gpio       = hauppauge_wintv_hvr_900_digital,
899                 .ir_codes       = RC_MAP_RC5_HAUPPAUGE_NEW,
900                 .decoder        = EM28XX_TVP5150,
901                 .input          = { {
902                         .type     = EM28XX_VMUX_TELEVISION,
903                         .vmux     = TVP5150_COMPOSITE0,
904                         .amux     = EM28XX_AMUX_VIDEO,
905                         .gpio     = hauppauge_wintv_hvr_900_analog,
906                 }, {
907                         .type     = EM28XX_VMUX_COMPOSITE1,
908                         .vmux     = TVP5150_COMPOSITE1,
909                         .amux     = EM28XX_AMUX_LINE_IN,
910                         .gpio     = hauppauge_wintv_hvr_900_analog,
911                 }, {
912                         .type     = EM28XX_VMUX_SVIDEO,
913                         .vmux     = TVP5150_SVIDEO,
914                         .amux     = EM28XX_AMUX_LINE_IN,
915                         .gpio     = hauppauge_wintv_hvr_900_analog,
916                 } },
917         },
918         [EM2880_BOARD_PINNACLE_PCTV_HD_PRO] = {
919                 .name           = "Pinnacle PCTV HD Pro Stick",
920                 .tuner_type     = TUNER_XC2028,
921                 .tuner_gpio   = default_tuner_gpio,
922                 .mts_firmware   = 1,
923                 .has_dvb        = 1,
924                 .dvb_gpio       = hauppauge_wintv_hvr_900_digital,
925                 .ir_codes       = RC_MAP_PINNACLE_PCTV_HD,
926                 .decoder        = EM28XX_TVP5150,
927                 .input          = { {
928                         .type     = EM28XX_VMUX_TELEVISION,
929                         .vmux     = TVP5150_COMPOSITE0,
930                         .amux     = EM28XX_AMUX_VIDEO,
931                         .gpio     = hauppauge_wintv_hvr_900_analog,
932                 }, {
933                         .type     = EM28XX_VMUX_COMPOSITE1,
934                         .vmux     = TVP5150_COMPOSITE1,
935                         .amux     = EM28XX_AMUX_LINE_IN,
936                         .gpio     = hauppauge_wintv_hvr_900_analog,
937                 }, {
938                         .type     = EM28XX_VMUX_SVIDEO,
939                         .vmux     = TVP5150_SVIDEO,
940                         .amux     = EM28XX_AMUX_LINE_IN,
941                         .gpio     = hauppauge_wintv_hvr_900_analog,
942                 } },
943         },
944         [EM2880_BOARD_AMD_ATI_TV_WONDER_HD_600] = {
945                 .name           = "AMD ATI TV Wonder HD 600",
946                 .tuner_type     = TUNER_XC2028,
947                 .tuner_gpio     = default_tuner_gpio,
948                 .mts_firmware   = 1,
949                 .has_dvb        = 1,
950                 .dvb_gpio       = hauppauge_wintv_hvr_900_digital,
951                 .ir_codes       = RC_MAP_ATI_TV_WONDER_HD_600,
952                 .decoder        = EM28XX_TVP5150,
953                 .input          = { {
954                         .type     = EM28XX_VMUX_TELEVISION,
955                         .vmux     = TVP5150_COMPOSITE0,
956                         .amux     = EM28XX_AMUX_VIDEO,
957                         .gpio     = hauppauge_wintv_hvr_900_analog,
958                 }, {
959                         .type     = EM28XX_VMUX_COMPOSITE1,
960                         .vmux     = TVP5150_COMPOSITE1,
961                         .amux     = EM28XX_AMUX_LINE_IN,
962                         .gpio     = hauppauge_wintv_hvr_900_analog,
963                 }, {
964                         .type     = EM28XX_VMUX_SVIDEO,
965                         .vmux     = TVP5150_SVIDEO,
966                         .amux     = EM28XX_AMUX_LINE_IN,
967                         .gpio     = hauppauge_wintv_hvr_900_analog,
968                 } },
969         },
970         [EM2880_BOARD_TERRATEC_HYBRID_XS] = {
971                 .name           = "Terratec Hybrid XS",
972                 .tuner_type     = TUNER_XC2028,
973                 .tuner_gpio     = default_tuner_gpio,
974                 .decoder        = EM28XX_TVP5150,
975                 .has_dvb        = 1,
976                 .dvb_gpio       = default_digital,
977                 .ir_codes       = RC_MAP_TERRATEC_CINERGY_XS,
978                 .xclk           = EM28XX_XCLK_FREQUENCY_12MHZ, /* NEC IR */
979                 .input          = { {
980                         .type     = EM28XX_VMUX_TELEVISION,
981                         .vmux     = TVP5150_COMPOSITE0,
982                         .amux     = EM28XX_AMUX_VIDEO,
983                         .gpio     = default_analog,
984                 }, {
985                         .type     = EM28XX_VMUX_COMPOSITE1,
986                         .vmux     = TVP5150_COMPOSITE1,
987                         .amux     = EM28XX_AMUX_LINE_IN,
988                         .gpio     = default_analog,
989                 }, {
990                         .type     = EM28XX_VMUX_SVIDEO,
991                         .vmux     = TVP5150_SVIDEO,
992                         .amux     = EM28XX_AMUX_LINE_IN,
993                         .gpio     = default_analog,
994                 } },
995         },
996         /* maybe there's a reason behind it why Terratec sells the Hybrid XS
997            as Prodigy XS with a different PID, let's keep it separated for now
998            maybe we'll need it lateron */
999         [EM2880_BOARD_TERRATEC_PRODIGY_XS] = {
1000                 .name         = "Terratec Prodigy XS",
1001                 .tuner_type   = TUNER_XC2028,
1002                 .tuner_gpio   = default_tuner_gpio,
1003                 .decoder      = EM28XX_TVP5150,
1004                 .input        = { {
1005                         .type     = EM28XX_VMUX_TELEVISION,
1006                         .vmux     = TVP5150_COMPOSITE0,
1007                         .amux     = EM28XX_AMUX_VIDEO,
1008                         .gpio     = hauppauge_wintv_hvr_900_analog,
1009                 }, {
1010                         .type     = EM28XX_VMUX_COMPOSITE1,
1011                         .vmux     = TVP5150_COMPOSITE1,
1012                         .amux     = EM28XX_AMUX_LINE_IN,
1013                         .gpio     = hauppauge_wintv_hvr_900_analog,
1014                 }, {
1015                         .type     = EM28XX_VMUX_SVIDEO,
1016                         .vmux     = TVP5150_SVIDEO,
1017                         .amux     = EM28XX_AMUX_LINE_IN,
1018                         .gpio     = hauppauge_wintv_hvr_900_analog,
1019                 } },
1020         },
1021         [EM2820_BOARD_MSI_VOX_USB_2] = {
1022                 .name              = "MSI VOX USB 2.0",
1023                 .tuner_type        = TUNER_LG_PAL_NEW_TAPC,
1024                 .tda9887_conf      = TDA9887_PRESENT      |
1025                                      TDA9887_PORT1_ACTIVE |
1026                                      TDA9887_PORT2_ACTIVE,
1027                 .max_range_640_480 = 1,
1028                 .decoder           = EM28XX_SAA711X,
1029                 .input             = { {
1030                         .type      = EM28XX_VMUX_TELEVISION,
1031                         .vmux      = SAA7115_COMPOSITE4,
1032                         .amux      = EM28XX_AMUX_VIDEO,
1033                 }, {
1034                         .type      = EM28XX_VMUX_COMPOSITE1,
1035                         .vmux      = SAA7115_COMPOSITE0,
1036                         .amux      = EM28XX_AMUX_LINE_IN,
1037                 }, {
1038                         .type      = EM28XX_VMUX_SVIDEO,
1039                         .vmux      = SAA7115_SVIDEO3,
1040                         .amux      = EM28XX_AMUX_LINE_IN,
1041                 } },
1042         },
1043         [EM2800_BOARD_TERRATEC_CINERGY_200] = {
1044                 .name         = "Terratec Cinergy 200 USB",
1045                 .is_em2800    = 1,
1046                 .has_ir_i2c   = 1,
1047                 .tuner_type   = TUNER_LG_PAL_NEW_TAPC,
1048                 .tda9887_conf = TDA9887_PRESENT,
1049                 .decoder      = EM28XX_SAA711X,
1050                 .input        = { {
1051                         .type     = EM28XX_VMUX_TELEVISION,
1052                         .vmux     = SAA7115_COMPOSITE2,
1053                         .amux     = EM28XX_AMUX_VIDEO,
1054                 }, {
1055                         .type     = EM28XX_VMUX_COMPOSITE1,
1056                         .vmux     = SAA7115_COMPOSITE0,
1057                         .amux     = EM28XX_AMUX_LINE_IN,
1058                 }, {
1059                         .type     = EM28XX_VMUX_SVIDEO,
1060                         .vmux     = SAA7115_SVIDEO3,
1061                         .amux     = EM28XX_AMUX_LINE_IN,
1062                 } },
1063         },
1064         [EM2800_BOARD_GRABBEEX_USB2800] = {
1065                 .name       = "eMPIA Technology, Inc. GrabBeeX+ Video Encoder",
1066                 .is_em2800  = 1,
1067                 .decoder    = EM28XX_SAA711X,
1068                 .tuner_type = TUNER_ABSENT, /* capture only board */
1069                 .input      = { {
1070                         .type     = EM28XX_VMUX_COMPOSITE1,
1071                         .vmux     = SAA7115_COMPOSITE0,
1072                         .amux     = EM28XX_AMUX_LINE_IN,
1073                 }, {
1074                         .type     = EM28XX_VMUX_SVIDEO,
1075                         .vmux     = SAA7115_SVIDEO3,
1076                         .amux     = EM28XX_AMUX_LINE_IN,
1077                 } },
1078         },
1079         [EM2800_BOARD_VC211A] = {
1080                 .name         = "Actionmaster/LinXcel/Digitus VC211A",
1081                 .is_em2800    = 1,
1082                 .tuner_type   = TUNER_ABSENT,   /* Capture-only board */
1083                 .decoder      = EM28XX_SAA711X,
1084                 .input        = { {
1085                         .type     = EM28XX_VMUX_COMPOSITE1,
1086                         .vmux     = SAA7115_COMPOSITE0,
1087                         .amux     = EM28XX_AMUX_LINE_IN,
1088                         .gpio     = vc211a_enable,
1089                 }, {
1090                         .type     = EM28XX_VMUX_SVIDEO,
1091                         .vmux     = SAA7115_SVIDEO3,
1092                         .amux     = EM28XX_AMUX_LINE_IN,
1093                         .gpio     = vc211a_enable,
1094                 } },
1095         },
1096         [EM2800_BOARD_LEADTEK_WINFAST_USBII] = {
1097                 .name         = "Leadtek Winfast USB II",
1098                 .is_em2800    = 1,
1099                 .tuner_type   = TUNER_LG_PAL_NEW_TAPC,
1100                 .tda9887_conf = TDA9887_PRESENT,
1101                 .decoder      = EM28XX_SAA711X,
1102                 .input        = { {
1103                         .type     = EM28XX_VMUX_TELEVISION,
1104                         .vmux     = SAA7115_COMPOSITE2,
1105                         .amux     = EM28XX_AMUX_VIDEO,
1106                 }, {
1107                         .type     = EM28XX_VMUX_COMPOSITE1,
1108                         .vmux     = SAA7115_COMPOSITE0,
1109                         .amux     = EM28XX_AMUX_LINE_IN,
1110                 }, {
1111                         .type     = EM28XX_VMUX_SVIDEO,
1112                         .vmux     = SAA7115_SVIDEO3,
1113                         .amux     = EM28XX_AMUX_LINE_IN,
1114                 } },
1115         },
1116         [EM2800_BOARD_KWORLD_USB2800] = {
1117                 .name         = "Kworld USB2800",
1118                 .is_em2800    = 1,
1119                 .tuner_type   = TUNER_PHILIPS_FCV1236D,
1120                 .tda9887_conf = TDA9887_PRESENT,
1121                 .decoder      = EM28XX_SAA711X,
1122                 .input        = { {
1123                         .type     = EM28XX_VMUX_TELEVISION,
1124                         .vmux     = SAA7115_COMPOSITE2,
1125                         .amux     = EM28XX_AMUX_VIDEO,
1126                 }, {
1127                         .type     = EM28XX_VMUX_COMPOSITE1,
1128                         .vmux     = SAA7115_COMPOSITE0,
1129                         .amux     = EM28XX_AMUX_LINE_IN,
1130                 }, {
1131                         .type     = EM28XX_VMUX_SVIDEO,
1132                         .vmux     = SAA7115_SVIDEO3,
1133                         .amux     = EM28XX_AMUX_LINE_IN,
1134                 } },
1135         },
1136         [EM2820_BOARD_PINNACLE_DVC_90] = {
1137                 .name         = "Pinnacle Dazzle DVC 90/100/101/107 / Kaiser Baas Video to DVD maker "
1138                                 "/ Kworld DVD Maker 2",
1139                 .tuner_type   = TUNER_ABSENT, /* capture only board */
1140                 .decoder      = EM28XX_SAA711X,
1141                 .input        = { {
1142                         .type     = EM28XX_VMUX_COMPOSITE1,
1143                         .vmux     = SAA7115_COMPOSITE0,
1144                         .amux     = EM28XX_AMUX_LINE_IN,
1145                 }, {
1146                         .type     = EM28XX_VMUX_SVIDEO,
1147                         .vmux     = SAA7115_SVIDEO3,
1148                         .amux     = EM28XX_AMUX_LINE_IN,
1149                 } },
1150         },
1151         [EM2800_BOARD_VGEAR_POCKETTV] = {
1152                 .name         = "V-Gear PocketTV",
1153                 .is_em2800    = 1,
1154                 .tuner_type   = TUNER_LG_PAL_NEW_TAPC,
1155                 .tda9887_conf = TDA9887_PRESENT,
1156                 .decoder      = EM28XX_SAA711X,
1157                 .input        = { {
1158                         .type     = EM28XX_VMUX_TELEVISION,
1159                         .vmux     = SAA7115_COMPOSITE2,
1160                         .amux     = EM28XX_AMUX_VIDEO,
1161                 }, {
1162                         .type     = EM28XX_VMUX_COMPOSITE1,
1163                         .vmux     = SAA7115_COMPOSITE0,
1164                         .amux     = EM28XX_AMUX_LINE_IN,
1165                 }, {
1166                         .type     = EM28XX_VMUX_SVIDEO,
1167                         .vmux     = SAA7115_SVIDEO3,
1168                         .amux     = EM28XX_AMUX_LINE_IN,
1169                 } },
1170         },
1171         [EM2820_BOARD_PROLINK_PLAYTV_BOX4_USB2] = {
1172                 .name         = "Pixelview PlayTV Box 4 USB 2.0",
1173                 .tda9887_conf = TDA9887_PRESENT,
1174                 .tuner_type   = TUNER_YMEC_TVF_5533MF,
1175                 .decoder      = EM28XX_SAA711X,
1176                 .input        = { {
1177                         .type     = EM28XX_VMUX_TELEVISION,
1178                         .vmux     = SAA7115_COMPOSITE2,
1179                         .amux     = EM28XX_AMUX_VIDEO,
1180                         .aout     = EM28XX_AOUT_MONO |  /* I2S */
1181                                     EM28XX_AOUT_MASTER, /* Line out pin */
1182                 }, {
1183                         .type     = EM28XX_VMUX_COMPOSITE1,
1184                         .vmux     = SAA7115_COMPOSITE0,
1185                         .amux     = EM28XX_AMUX_LINE_IN,
1186                 }, {
1187                         .type     = EM28XX_VMUX_SVIDEO,
1188                         .vmux     = SAA7115_SVIDEO3,
1189                         .amux     = EM28XX_AMUX_LINE_IN,
1190                 } },
1191         },
1192         [EM2820_BOARD_PROLINK_PLAYTV_USB2] = {
1193                 .name         = "SIIG AVTuner-PVR / Pixelview Prolink PlayTV USB 2.0",
1194                 .has_snapshot_button = 1,
1195                 .tda9887_conf = TDA9887_PRESENT,
1196                 .tuner_type   = TUNER_YMEC_TVF_5533MF,
1197                 .decoder      = EM28XX_SAA711X,
1198                 .input        = { {
1199                         .type     = EM28XX_VMUX_TELEVISION,
1200                         .vmux     = SAA7115_COMPOSITE2,
1201                         .amux     = EM28XX_AMUX_VIDEO,
1202                         .aout     = EM28XX_AOUT_MONO |  /* I2S */
1203                                     EM28XX_AOUT_MASTER, /* Line out pin */
1204                 }, {
1205                         .type     = EM28XX_VMUX_COMPOSITE1,
1206                         .vmux     = SAA7115_COMPOSITE0,
1207                         .amux     = EM28XX_AMUX_LINE_IN,
1208                 }, {
1209                         .type     = EM28XX_VMUX_SVIDEO,
1210                         .vmux     = SAA7115_SVIDEO3,
1211                         .amux     = EM28XX_AMUX_LINE_IN,
1212                 } },
1213         },
1214         [EM2860_BOARD_SAA711X_REFERENCE_DESIGN] = {
1215                 .name                = "EM2860/SAA711X Reference Design",
1216                 .has_snapshot_button = 1,
1217                 .tuner_type          = TUNER_ABSENT,
1218                 .decoder             = EM28XX_SAA711X,
1219                 .input               = { {
1220                         .type     = EM28XX_VMUX_SVIDEO,
1221                         .vmux     = SAA7115_SVIDEO3,
1222                 }, {
1223                         .type     = EM28XX_VMUX_COMPOSITE1,
1224                         .vmux     = SAA7115_COMPOSITE0,
1225                 } },
1226         },
1227         [EM2880_BOARD_MSI_DIGIVOX_AD] = {
1228                 .name         = "MSI DigiVox A/D",
1229                 .valid        = EM28XX_BOARD_NOT_VALIDATED,
1230                 .tuner_type   = TUNER_XC2028,
1231                 .tuner_gpio   = default_tuner_gpio,
1232                 .decoder      = EM28XX_TVP5150,
1233                 .input        = { {
1234                         .type     = EM28XX_VMUX_TELEVISION,
1235                         .vmux     = TVP5150_COMPOSITE0,
1236                         .amux     = EM28XX_AMUX_VIDEO,
1237                         .gpio     = em2880_msi_digivox_ad_analog,
1238                 }, {
1239                         .type     = EM28XX_VMUX_COMPOSITE1,
1240                         .vmux     = TVP5150_COMPOSITE1,
1241                         .amux     = EM28XX_AMUX_LINE_IN,
1242                         .gpio     = em2880_msi_digivox_ad_analog,
1243                 }, {
1244                         .type     = EM28XX_VMUX_SVIDEO,
1245                         .vmux     = TVP5150_SVIDEO,
1246                         .amux     = EM28XX_AMUX_LINE_IN,
1247                         .gpio     = em2880_msi_digivox_ad_analog,
1248                 } },
1249         },
1250         [EM2880_BOARD_MSI_DIGIVOX_AD_II] = {
1251                 .name         = "MSI DigiVox A/D II",
1252                 .valid        = EM28XX_BOARD_NOT_VALIDATED,
1253                 .tuner_type   = TUNER_XC2028,
1254                 .tuner_gpio   = default_tuner_gpio,
1255                 .decoder      = EM28XX_TVP5150,
1256                 .input        = { {
1257                         .type     = EM28XX_VMUX_TELEVISION,
1258                         .vmux     = TVP5150_COMPOSITE0,
1259                         .amux     = EM28XX_AMUX_VIDEO,
1260                         .gpio     = em2880_msi_digivox_ad_analog,
1261                 }, {
1262                         .type     = EM28XX_VMUX_COMPOSITE1,
1263                         .vmux     = TVP5150_COMPOSITE1,
1264                         .amux     = EM28XX_AMUX_LINE_IN,
1265                         .gpio     = em2880_msi_digivox_ad_analog,
1266                 }, {
1267                         .type     = EM28XX_VMUX_SVIDEO,
1268                         .vmux     = TVP5150_SVIDEO,
1269                         .amux     = EM28XX_AMUX_LINE_IN,
1270                         .gpio     = em2880_msi_digivox_ad_analog,
1271                 } },
1272         },
1273         [EM2880_BOARD_KWORLD_DVB_305U] = {
1274                 .name         = "KWorld DVB-T 305U",
1275                 .valid        = EM28XX_BOARD_NOT_VALIDATED,
1276                 .tuner_type   = TUNER_XC2028,
1277                 .tuner_gpio   = default_tuner_gpio,
1278                 .decoder      = EM28XX_TVP5150,
1279                 .input        = { {
1280                         .type     = EM28XX_VMUX_TELEVISION,
1281                         .vmux     = TVP5150_COMPOSITE0,
1282                         .amux     = EM28XX_AMUX_VIDEO,
1283                 }, {
1284                         .type     = EM28XX_VMUX_COMPOSITE1,
1285                         .vmux     = TVP5150_COMPOSITE1,
1286                         .amux     = EM28XX_AMUX_LINE_IN,
1287                 }, {
1288                         .type     = EM28XX_VMUX_SVIDEO,
1289                         .vmux     = TVP5150_SVIDEO,
1290                         .amux     = EM28XX_AMUX_LINE_IN,
1291                 } },
1292         },
1293         [EM2880_BOARD_KWORLD_DVB_310U] = {
1294                 .name         = "KWorld DVB-T 310U",
1295                 .tuner_type   = TUNER_XC2028,
1296                 .tuner_gpio   = default_tuner_gpio,
1297                 .has_dvb      = 1,
1298                 .dvb_gpio     = default_digital,
1299                 .mts_firmware = 1,
1300                 .decoder      = EM28XX_TVP5150,
1301                 .input        = { {
1302                         .type     = EM28XX_VMUX_TELEVISION,
1303                         .vmux     = TVP5150_COMPOSITE0,
1304                         .amux     = EM28XX_AMUX_VIDEO,
1305                         .gpio     = default_analog,
1306                 }, {
1307                         .type     = EM28XX_VMUX_COMPOSITE1,
1308                         .vmux     = TVP5150_COMPOSITE1,
1309                         .amux     = EM28XX_AMUX_LINE_IN,
1310                         .gpio     = default_analog,
1311                 }, {    /* S-video has not been tested yet */
1312                         .type     = EM28XX_VMUX_SVIDEO,
1313                         .vmux     = TVP5150_SVIDEO,
1314                         .amux     = EM28XX_AMUX_LINE_IN,
1315                         .gpio     = default_analog,
1316                 } },
1317         },
1318         [EM2882_BOARD_KWORLD_ATSC_315U] = {
1319                 .name           = "KWorld ATSC 315U HDTV TV Box",
1320                 .valid          = EM28XX_BOARD_NOT_VALIDATED,
1321                 .tuner_type     = TUNER_THOMSON_DTT761X,
1322                 .tuner_gpio     = em2882_kworld_315u_tuner_gpio,
1323                 .tda9887_conf   = TDA9887_PRESENT,
1324                 .decoder        = EM28XX_SAA711X,
1325                 .has_dvb        = 1,
1326                 .dvb_gpio       = em2882_kworld_315u_digital,
1327                 .ir_codes       = RC_MAP_KWORLD_315U,
1328                 .xclk           = EM28XX_XCLK_FREQUENCY_12MHZ,
1329                 .i2c_speed      = EM28XX_I2C_CLK_WAIT_ENABLE,
1330                 /* Analog mode - still not ready */
1331                 /*.input        = { {
1332                         .type = EM28XX_VMUX_TELEVISION,
1333                         .vmux = SAA7115_COMPOSITE2,
1334                         .amux = EM28XX_AMUX_VIDEO,
1335                         .gpio = em2882_kworld_315u_analog,
1336                         .aout = EM28XX_AOUT_PCM_IN | EM28XX_AOUT_PCM_STEREO,
1337                 }, {
1338                         .type = EM28XX_VMUX_COMPOSITE1,
1339                         .vmux = SAA7115_COMPOSITE0,
1340                         .amux = EM28XX_AMUX_LINE_IN,
1341                         .gpio = em2882_kworld_315u_analog1,
1342                         .aout = EM28XX_AOUT_PCM_IN | EM28XX_AOUT_PCM_STEREO,
1343                 }, {
1344                         .type = EM28XX_VMUX_SVIDEO,
1345                         .vmux = SAA7115_SVIDEO3,
1346                         .amux = EM28XX_AMUX_LINE_IN,
1347                         .gpio = em2882_kworld_315u_analog1,
1348                         .aout = EM28XX_AOUT_PCM_IN | EM28XX_AOUT_PCM_STEREO,
1349                 } }, */
1350         },
1351         [EM2880_BOARD_EMPIRE_DUAL_TV] = {
1352                 .name = "Empire dual TV",
1353                 .tuner_type = TUNER_XC2028,
1354                 .tuner_gpio = default_tuner_gpio,
1355                 .has_dvb = 1,
1356                 .dvb_gpio = default_digital,
1357                 .mts_firmware = 1,
1358                 .decoder = EM28XX_TVP5150,
1359                 .input = { {
1360                         .type = EM28XX_VMUX_TELEVISION,
1361                         .vmux = TVP5150_COMPOSITE0,
1362                         .amux = EM28XX_AMUX_VIDEO,
1363                         .gpio = default_analog,
1364                 }, {
1365                         .type = EM28XX_VMUX_COMPOSITE1,
1366                         .vmux = TVP5150_COMPOSITE1,
1367                         .amux = EM28XX_AMUX_LINE_IN,
1368                         .gpio = default_analog,
1369                 }, {
1370                         .type = EM28XX_VMUX_SVIDEO,
1371                         .vmux = TVP5150_SVIDEO,
1372                         .amux = EM28XX_AMUX_LINE_IN,
1373                         .gpio = default_analog,
1374                 } },
1375         },
1376         [EM2881_BOARD_DNT_DA2_HYBRID] = {
1377                 .name         = "DNT DA2 Hybrid",
1378                 .valid        = EM28XX_BOARD_NOT_VALIDATED,
1379                 .tuner_type   = TUNER_XC2028,
1380                 .tuner_gpio   = default_tuner_gpio,
1381                 .decoder      = EM28XX_TVP5150,
1382                 .input        = { {
1383                         .type     = EM28XX_VMUX_TELEVISION,
1384                         .vmux     = TVP5150_COMPOSITE0,
1385                         .amux     = EM28XX_AMUX_VIDEO,
1386                         .gpio     = default_analog,
1387                 }, {
1388                         .type     = EM28XX_VMUX_COMPOSITE1,
1389                         .vmux     = TVP5150_COMPOSITE1,
1390                         .amux     = EM28XX_AMUX_LINE_IN,
1391                         .gpio     = default_analog,
1392                 }, {
1393                         .type     = EM28XX_VMUX_SVIDEO,
1394                         .vmux     = TVP5150_SVIDEO,
1395                         .amux     = EM28XX_AMUX_LINE_IN,
1396                         .gpio     = default_analog,
1397                 } },
1398         },
1399         [EM2881_BOARD_PINNACLE_HYBRID_PRO] = {
1400                 .name         = "Pinnacle Hybrid Pro",
1401                 .tuner_type   = TUNER_XC2028,
1402                 .tuner_gpio   = default_tuner_gpio,
1403                 .decoder      = EM28XX_TVP5150,
1404                 .has_dvb      = 1,
1405                 .dvb_gpio     = pinnacle_hybrid_pro_digital,
1406                 .input        = { {
1407                         .type     = EM28XX_VMUX_TELEVISION,
1408                         .vmux     = TVP5150_COMPOSITE0,
1409                         .amux     = EM28XX_AMUX_VIDEO,
1410                         .gpio     = pinnacle_hybrid_pro_analog,
1411                 }, {
1412                         .type     = EM28XX_VMUX_COMPOSITE1,
1413                         .vmux     = TVP5150_COMPOSITE1,
1414                         .amux     = EM28XX_AMUX_LINE_IN,
1415                         .gpio     = pinnacle_hybrid_pro_analog,
1416                 }, {
1417                         .type     = EM28XX_VMUX_SVIDEO,
1418                         .vmux     = TVP5150_SVIDEO,
1419                         .amux     = EM28XX_AMUX_LINE_IN,
1420                         .gpio     = pinnacle_hybrid_pro_analog,
1421                 } },
1422         },
1423         [EM2882_BOARD_PINNACLE_HYBRID_PRO] = {
1424                 .name         = "Pinnacle Hybrid Pro (2)",
1425                 .valid        = EM28XX_BOARD_NOT_VALIDATED,
1426                 .tuner_type   = TUNER_XC2028,
1427                 .tuner_gpio   = default_tuner_gpio,
1428                 .mts_firmware = 1,
1429                 .decoder      = EM28XX_TVP5150,
1430                 .input        = { {
1431                         .type     = EM28XX_VMUX_TELEVISION,
1432                         .vmux     = TVP5150_COMPOSITE0,
1433                         .amux     = EM28XX_AMUX_VIDEO,
1434                         .gpio     = hauppauge_wintv_hvr_900_analog,
1435                 }, {
1436                         .type     = EM28XX_VMUX_COMPOSITE1,
1437                         .vmux     = TVP5150_COMPOSITE1,
1438                         .amux     = EM28XX_AMUX_LINE_IN,
1439                         .gpio     = hauppauge_wintv_hvr_900_analog,
1440                 }, {
1441                         .type     = EM28XX_VMUX_SVIDEO,
1442                         .vmux     = TVP5150_SVIDEO,
1443                         .amux     = EM28XX_AMUX_LINE_IN,
1444                         .gpio     = hauppauge_wintv_hvr_900_analog,
1445                 } },
1446         },
1447         [EM2882_BOARD_KWORLD_VS_DVBT] = {
1448                 .name         = "Kworld VS-DVB-T 323UR",
1449                 .tuner_type   = TUNER_XC2028,
1450                 .tuner_gpio   = default_tuner_gpio,
1451                 .decoder      = EM28XX_TVP5150,
1452                 .mts_firmware = 1,
1453                 .has_dvb      = 1,
1454                 .dvb_gpio     = kworld_330u_digital,
1455                 .xclk         = EM28XX_XCLK_FREQUENCY_12MHZ, /* NEC IR */
1456                 .ir_codes     = RC_MAP_KWORLD_315U,
1457                 .input        = { {
1458                         .type     = EM28XX_VMUX_TELEVISION,
1459                         .vmux     = TVP5150_COMPOSITE0,
1460                         .amux     = EM28XX_AMUX_VIDEO,
1461                 }, {
1462                         .type     = EM28XX_VMUX_COMPOSITE1,
1463                         .vmux     = TVP5150_COMPOSITE1,
1464                         .amux     = EM28XX_AMUX_LINE_IN,
1465                 }, {
1466                         .type     = EM28XX_VMUX_SVIDEO,
1467                         .vmux     = TVP5150_SVIDEO,
1468                         .amux     = EM28XX_AMUX_LINE_IN,
1469                 } },
1470         },
1471         [EM2882_BOARD_TERRATEC_HYBRID_XS] = {
1472                 .name         = "Terratec Hybrid XS (em2882)",
1473                 .tuner_type   = TUNER_XC2028,
1474                 .tuner_gpio   = default_tuner_gpio,
1475                 .mts_firmware = 1,
1476                 .decoder      = EM28XX_TVP5150,
1477                 .has_dvb      = 1,
1478                 .dvb_gpio     = hauppauge_wintv_hvr_900_digital,
1479                 .ir_codes     = RC_MAP_TERRATEC_CINERGY_XS,
1480                 .xclk         = EM28XX_XCLK_FREQUENCY_12MHZ,
1481                 .input        = { {
1482                         .type     = EM28XX_VMUX_TELEVISION,
1483                         .vmux     = TVP5150_COMPOSITE0,
1484                         .amux     = EM28XX_AMUX_VIDEO,
1485                         .gpio     = hauppauge_wintv_hvr_900_analog,
1486                 }, {
1487                         .type     = EM28XX_VMUX_COMPOSITE1,
1488                         .vmux     = TVP5150_COMPOSITE1,
1489                         .amux     = EM28XX_AMUX_LINE_IN,
1490                         .gpio     = hauppauge_wintv_hvr_900_analog,
1491                 }, {
1492                         .type     = EM28XX_VMUX_SVIDEO,
1493                         .vmux     = TVP5150_SVIDEO,
1494                         .amux     = EM28XX_AMUX_LINE_IN,
1495                         .gpio     = hauppauge_wintv_hvr_900_analog,
1496                 } },
1497         },
1498         [EM2882_BOARD_DIKOM_DK300] = {
1499                 .name         = "Dikom DK300",
1500                 .tuner_type   = TUNER_XC2028,
1501                 .tuner_gpio   = default_tuner_gpio,
1502                 .decoder      = EM28XX_TVP5150,
1503                 .mts_firmware = 1,
1504                 .has_dvb      = 1,
1505                 .dvb_gpio     = dikom_dk300_digital,
1506                 .input        = { {
1507                         .type     = EM28XX_VMUX_TELEVISION,
1508                         .vmux     = TVP5150_COMPOSITE0,
1509                         .amux     = EM28XX_AMUX_VIDEO,
1510                         .gpio     = default_analog,
1511                 } },
1512         },
1513         [EM2883_BOARD_KWORLD_HYBRID_330U] = {
1514                 .name         = "Kworld PlusTV HD Hybrid 330",
1515                 .tuner_type   = TUNER_XC2028,
1516                 .tuner_gpio   = default_tuner_gpio,
1517                 .decoder      = EM28XX_TVP5150,
1518                 .mts_firmware = 1,
1519                 .has_dvb      = 1,
1520                 .dvb_gpio     = kworld_330u_digital,
1521                 .xclk             = EM28XX_XCLK_FREQUENCY_12MHZ,
1522                 .i2c_speed        = EM28XX_I2C_CLK_WAIT_ENABLE |
1523                                     EM28XX_I2C_EEPROM_ON_BOARD |
1524                                     EM28XX_I2C_EEPROM_KEY_VALID,
1525                 .input        = { {
1526                         .type     = EM28XX_VMUX_TELEVISION,
1527                         .vmux     = TVP5150_COMPOSITE0,
1528                         .amux     = EM28XX_AMUX_VIDEO,
1529                         .gpio     = kworld_330u_analog,
1530                         .aout     = EM28XX_AOUT_PCM_IN | EM28XX_AOUT_PCM_STEREO,
1531                 }, {
1532                         .type     = EM28XX_VMUX_COMPOSITE1,
1533                         .vmux     = TVP5150_COMPOSITE1,
1534                         .amux     = EM28XX_AMUX_LINE_IN,
1535                         .gpio     = kworld_330u_analog,
1536                         .aout     = EM28XX_AOUT_PCM_IN | EM28XX_AOUT_PCM_STEREO,
1537                 }, {
1538                         .type     = EM28XX_VMUX_SVIDEO,
1539                         .vmux     = TVP5150_SVIDEO,
1540                         .amux     = EM28XX_AMUX_LINE_IN,
1541                         .gpio     = kworld_330u_analog,
1542                 } },
1543         },
1544         [EM2820_BOARD_COMPRO_VIDEOMATE_FORYOU] = {
1545                 .name         = "Compro VideoMate ForYou/Stereo",
1546                 .tuner_type   = TUNER_LG_PAL_NEW_TAPC,
1547                 .tvaudio_addr = 0xb0,
1548                 .tda9887_conf = TDA9887_PRESENT,
1549                 .decoder      = EM28XX_TVP5150,
1550                 .adecoder     = EM28XX_TVAUDIO,
1551                 .mute_gpio    = compro_mute_gpio,
1552                 .input        = { {
1553                         .type     = EM28XX_VMUX_TELEVISION,
1554                         .vmux     = TVP5150_COMPOSITE0,
1555                         .amux     = EM28XX_AMUX_VIDEO,
1556                         .gpio     = compro_unmute_tv_gpio,
1557                 }, {
1558                         .type     = EM28XX_VMUX_SVIDEO,
1559                         .vmux     = TVP5150_SVIDEO,
1560                         .amux     = EM28XX_AMUX_LINE_IN,
1561                         .gpio     = compro_unmute_svid_gpio,
1562                 } },
1563         },
1564         [EM2860_BOARD_KAIOMY_TVNPC_U2] = {
1565                 .name         = "Kaiomy TVnPC U2",
1566                 .vchannels    = 3,
1567                 .tuner_type   = TUNER_XC2028,
1568                 .tuner_addr   = 0x61,
1569                 .mts_firmware = 1,
1570                 .decoder      = EM28XX_TVP5150,
1571                 .tuner_gpio   = default_tuner_gpio,
1572                 .ir_codes     = RC_MAP_KAIOMY,
1573                 .input          = { {
1574                         .type     = EM28XX_VMUX_TELEVISION,
1575                         .vmux     = TVP5150_COMPOSITE0,
1576                         .amux     = EM28XX_AMUX_VIDEO,
1577
1578                 }, {
1579                         .type     = EM28XX_VMUX_COMPOSITE1,
1580                         .vmux     = TVP5150_COMPOSITE1,
1581                         .amux     = EM28XX_AMUX_LINE_IN,
1582                 }, {
1583                         .type     = EM28XX_VMUX_SVIDEO,
1584                         .vmux     = TVP5150_SVIDEO,
1585                         .amux     = EM28XX_AMUX_LINE_IN,
1586                 } },
1587                 .radio          = {
1588                         .type     = EM28XX_RADIO,
1589                         .amux     = EM28XX_AMUX_LINE_IN,
1590                 }
1591         },
1592         [EM2860_BOARD_EASYCAP] = {
1593                 .name         = "Easy Cap Capture DC-60",
1594                 .vchannels    = 2,
1595                 .tuner_type   = TUNER_ABSENT,
1596                 .decoder      = EM28XX_SAA711X,
1597                 .input           = { {
1598                         .type     = EM28XX_VMUX_COMPOSITE1,
1599                         .vmux     = SAA7115_COMPOSITE0,
1600                         .amux     = EM28XX_AMUX_LINE_IN,
1601                 }, {
1602                         .type     = EM28XX_VMUX_SVIDEO,
1603                         .vmux     = SAA7115_SVIDEO3,
1604                         .amux     = EM28XX_AMUX_LINE_IN,
1605                 } },
1606         },
1607         [EM2820_BOARD_IODATA_GVMVP_SZ] = {
1608                 .name       = "IO-DATA GV-MVP/SZ",
1609                 .tuner_type   = TUNER_PHILIPS_FM1236_MK3,
1610                 .tuner_gpio   = default_tuner_gpio,
1611                 .tda9887_conf = TDA9887_PRESENT,
1612                 .decoder      = EM28XX_TVP5150,
1613                 .input        = { {
1614                         .type     = EM28XX_VMUX_TELEVISION,
1615                         .vmux     = TVP5150_COMPOSITE0,
1616                         .amux     = EM28XX_AMUX_VIDEO,
1617                 }, { /* Composite has not been tested yet */
1618                         .type     = EM28XX_VMUX_COMPOSITE1,
1619                         .vmux     = TVP5150_COMPOSITE1,
1620                         .amux     = EM28XX_AMUX_VIDEO,
1621                 }, { /* S-video has not been tested yet */
1622                         .type     = EM28XX_VMUX_SVIDEO,
1623                         .vmux     = TVP5150_SVIDEO,
1624                         .amux     = EM28XX_AMUX_VIDEO,
1625                 } },
1626         },
1627         [EM2860_BOARD_TERRATEC_GRABBY] = {
1628                 .name            = "Terratec Grabby",
1629                 .vchannels       = 2,
1630                 .tuner_type      = TUNER_ABSENT,
1631                 .decoder         = EM28XX_SAA711X,
1632                 .xclk            = EM28XX_XCLK_FREQUENCY_12MHZ,
1633                 .input           = { {
1634                         .type     = EM28XX_VMUX_COMPOSITE1,
1635                         .vmux     = SAA7115_COMPOSITE0,
1636                         .amux     = EM28XX_AMUX_VIDEO2,
1637                 }, {
1638                         .type     = EM28XX_VMUX_SVIDEO,
1639                         .vmux     = SAA7115_SVIDEO3,
1640                         .amux     = EM28XX_AMUX_VIDEO2,
1641                 } },
1642         },
1643         [EM2860_BOARD_TERRATEC_AV350] = {
1644                 .name            = "Terratec AV350",
1645                 .vchannels       = 2,
1646                 .tuner_type      = TUNER_ABSENT,
1647                 .decoder         = EM28XX_TVP5150,
1648                 .xclk            = EM28XX_XCLK_FREQUENCY_12MHZ,
1649                 .mute_gpio       = terratec_av350_mute_gpio,
1650                 .input           = { {
1651                         .type     = EM28XX_VMUX_COMPOSITE1,
1652                         .vmux     = TVP5150_COMPOSITE1,
1653                         .amux     = EM28XX_AUDIO_SRC_LINE,
1654                         .gpio     = terratec_av350_unmute_gpio,
1655
1656                 }, {
1657                         .type     = EM28XX_VMUX_SVIDEO,
1658                         .vmux     = TVP5150_SVIDEO,
1659                         .amux     = EM28XX_AUDIO_SRC_LINE,
1660                         .gpio     = terratec_av350_unmute_gpio,
1661                 } },
1662         },
1663
1664         [EM2860_BOARD_ELGATO_VIDEO_CAPTURE] = {
1665                 .name         = "Elgato Video Capture",
1666                 .decoder      = EM28XX_SAA711X,
1667                 .tuner_type   = TUNER_ABSENT,   /* Capture only device */
1668                 .input        = { {
1669                         .type  = EM28XX_VMUX_COMPOSITE1,
1670                         .vmux  = SAA7115_COMPOSITE0,
1671                         .amux  = EM28XX_AMUX_LINE_IN,
1672                 }, {
1673                         .type  = EM28XX_VMUX_SVIDEO,
1674                         .vmux  = SAA7115_SVIDEO3,
1675                         .amux  = EM28XX_AMUX_LINE_IN,
1676                 } },
1677         },
1678
1679         [EM2882_BOARD_EVGA_INDTUBE] = {
1680                 .name         = "Evga inDtube",
1681                 .tuner_type   = TUNER_XC2028,
1682                 .tuner_gpio   = default_tuner_gpio,
1683                 .decoder      = EM28XX_TVP5150,
1684                 .xclk         = EM28XX_XCLK_FREQUENCY_12MHZ, /* NEC IR */
1685                 .mts_firmware = 1,
1686                 .has_dvb      = 1,
1687                 .dvb_gpio     = evga_indtube_digital,
1688                 .ir_codes     = RC_MAP_EVGA_INDTUBE,
1689                 .input        = { {
1690                         .type     = EM28XX_VMUX_TELEVISION,
1691                         .vmux     = TVP5150_COMPOSITE0,
1692                         .amux     = EM28XX_AMUX_VIDEO,
1693                         .gpio     = evga_indtube_analog,
1694                 }, {
1695                         .type     = EM28XX_VMUX_COMPOSITE1,
1696                         .vmux     = TVP5150_COMPOSITE1,
1697                         .amux     = EM28XX_AMUX_LINE_IN,
1698                         .gpio     = evga_indtube_analog,
1699                 }, {
1700                         .type     = EM28XX_VMUX_SVIDEO,
1701                         .vmux     = TVP5150_SVIDEO,
1702                         .amux     = EM28XX_AMUX_LINE_IN,
1703                         .gpio     = evga_indtube_analog,
1704                 } },
1705         },
1706         /* eb1a:2868 Empia EM2870 + Philips CU1216L NIM (Philips TDA10023 +
1707            Infineon TUA6034) */
1708         [EM2870_BOARD_REDDO_DVB_C_USB_BOX] = {
1709                 .name          = "Reddo DVB-C USB TV Box",
1710                 .tuner_type    = TUNER_ABSENT,
1711                 .tuner_gpio    = reddo_dvb_c_usb_box,
1712                 .has_dvb       = 1,
1713         },
1714         /* 1b80:a340 - Empia EM2870, NXP TDA18271HD and LG DT3304, sold
1715          * initially as the KWorld PlusTV 340U, then as the UB435-Q.
1716          * Early variants have a TDA18271HD/C1, later ones a TDA18271HD/C2 */
1717         [EM2870_BOARD_KWORLD_A340] = {
1718                 .name       = "KWorld PlusTV 340U or UB435-Q (ATSC)",
1719                 .tuner_type = TUNER_ABSENT,     /* Digital-only TDA18271HD */
1720                 .has_dvb    = 1,
1721                 .dvb_gpio   = kworld_a340_digital,
1722                 .tuner_gpio = default_tuner_gpio,
1723         },
1724 };
1725 const unsigned int em28xx_bcount = ARRAY_SIZE(em28xx_boards);
1726
1727 /* table of devices that work with this driver */
1728 struct usb_device_id em28xx_id_table[] = {
1729         { USB_DEVICE(0xeb1a, 0x2750),
1730                         .driver_info = EM2750_BOARD_UNKNOWN },
1731         { USB_DEVICE(0xeb1a, 0x2751),
1732                         .driver_info = EM2750_BOARD_UNKNOWN },
1733         { USB_DEVICE(0xeb1a, 0x2800),
1734                         .driver_info = EM2800_BOARD_UNKNOWN },
1735         { USB_DEVICE(0xeb1a, 0x2710),
1736                         .driver_info = EM2820_BOARD_UNKNOWN },
1737         { USB_DEVICE(0xeb1a, 0x2820),
1738                         .driver_info = EM2820_BOARD_UNKNOWN },
1739         { USB_DEVICE(0xeb1a, 0x2821),
1740                         .driver_info = EM2820_BOARD_UNKNOWN },
1741         { USB_DEVICE(0xeb1a, 0x2860),
1742                         .driver_info = EM2820_BOARD_UNKNOWN },
1743         { USB_DEVICE(0xeb1a, 0x2861),
1744                         .driver_info = EM2820_BOARD_UNKNOWN },
1745         { USB_DEVICE(0xeb1a, 0x2862),
1746                         .driver_info = EM2820_BOARD_UNKNOWN },
1747         { USB_DEVICE(0xeb1a, 0x2863),
1748                         .driver_info = EM2820_BOARD_UNKNOWN },
1749         { USB_DEVICE(0xeb1a, 0x2870),
1750                         .driver_info = EM2820_BOARD_UNKNOWN },
1751         { USB_DEVICE(0xeb1a, 0x2881),
1752                         .driver_info = EM2820_BOARD_UNKNOWN },
1753         { USB_DEVICE(0xeb1a, 0x2883),
1754                         .driver_info = EM2820_BOARD_UNKNOWN },
1755         { USB_DEVICE(0xeb1a, 0x2868),
1756                         .driver_info = EM2820_BOARD_UNKNOWN },
1757         { USB_DEVICE(0xeb1a, 0xe300),
1758                         .driver_info = EM2861_BOARD_KWORLD_PVRTV_300U },
1759         { USB_DEVICE(0xeb1a, 0xe303),
1760                         .driver_info = EM2860_BOARD_KAIOMY_TVNPC_U2 },
1761         { USB_DEVICE(0xeb1a, 0xe305),
1762                         .driver_info = EM2880_BOARD_KWORLD_DVB_305U },
1763         { USB_DEVICE(0xeb1a, 0xe310),
1764                         .driver_info = EM2880_BOARD_MSI_DIGIVOX_AD },
1765         { USB_DEVICE(0xeb1a, 0xa313),
1766                 .driver_info = EM2882_BOARD_KWORLD_ATSC_315U },
1767         { USB_DEVICE(0xeb1a, 0xa316),
1768                         .driver_info = EM2883_BOARD_KWORLD_HYBRID_330U },
1769         { USB_DEVICE(0xeb1a, 0xe320),
1770                         .driver_info = EM2880_BOARD_MSI_DIGIVOX_AD_II },
1771         { USB_DEVICE(0xeb1a, 0xe323),
1772                         .driver_info = EM2882_BOARD_KWORLD_VS_DVBT },
1773         { USB_DEVICE(0xeb1a, 0xe350),
1774                         .driver_info = EM2870_BOARD_KWORLD_350U },
1775         { USB_DEVICE(0xeb1a, 0xe355),
1776                         .driver_info = EM2870_BOARD_KWORLD_355U },
1777         { USB_DEVICE(0xeb1a, 0x2801),
1778                         .driver_info = EM2800_BOARD_GRABBEEX_USB2800 },
1779         { USB_DEVICE(0xeb1a, 0xe357),
1780                         .driver_info = EM2870_BOARD_KWORLD_355U },
1781         { USB_DEVICE(0x1b80, 0xe302),
1782                         .driver_info = EM2820_BOARD_PINNACLE_DVC_90 }, /* Kaiser Baas Video to DVD maker */
1783         { USB_DEVICE(0x1b80, 0xe304),
1784                         .driver_info = EM2820_BOARD_PINNACLE_DVC_90 }, /* Kworld DVD Maker 2 */
1785         { USB_DEVICE(0x0ccd, 0x0036),
1786                         .driver_info = EM2820_BOARD_TERRATEC_CINERGY_250 },
1787         { USB_DEVICE(0x0ccd, 0x004c),
1788                         .driver_info = EM2880_BOARD_TERRATEC_HYBRID_XS_FR },
1789         { USB_DEVICE(0x0ccd, 0x004f),
1790                         .driver_info = EM2860_BOARD_TERRATEC_HYBRID_XS },
1791         { USB_DEVICE(0x0ccd, 0x005e),
1792                         .driver_info = EM2882_BOARD_TERRATEC_HYBRID_XS },
1793         { USB_DEVICE(0x0ccd, 0x0042),
1794                         .driver_info = EM2880_BOARD_TERRATEC_HYBRID_XS },
1795         { USB_DEVICE(0x0ccd, 0x0043),
1796                         .driver_info = EM2870_BOARD_TERRATEC_XS },
1797         { USB_DEVICE(0x0ccd, 0x0047),
1798                         .driver_info = EM2880_BOARD_TERRATEC_PRODIGY_XS },
1799         { USB_DEVICE(0x0ccd, 0x0084),
1800                         .driver_info = EM2860_BOARD_TERRATEC_AV350 },
1801         { USB_DEVICE(0x0ccd, 0x0096),
1802                         .driver_info = EM2860_BOARD_TERRATEC_GRABBY },
1803         { USB_DEVICE(0x0fd9, 0x0033),
1804                         .driver_info = EM2860_BOARD_ELGATO_VIDEO_CAPTURE},
1805         { USB_DEVICE(0x185b, 0x2870),
1806                         .driver_info = EM2870_BOARD_COMPRO_VIDEOMATE },
1807         { USB_DEVICE(0x185b, 0x2041),
1808                         .driver_info = EM2820_BOARD_COMPRO_VIDEOMATE_FORYOU },
1809         { USB_DEVICE(0x2040, 0x4200),
1810                         .driver_info = EM2820_BOARD_HAUPPAUGE_WINTV_USB_2 },
1811         { USB_DEVICE(0x2040, 0x4201),
1812                         .driver_info = EM2820_BOARD_HAUPPAUGE_WINTV_USB_2 },
1813         { USB_DEVICE(0x2040, 0x6500),
1814                         .driver_info = EM2880_BOARD_HAUPPAUGE_WINTV_HVR_900 },
1815         { USB_DEVICE(0x2040, 0x6502),
1816                         .driver_info = EM2880_BOARD_HAUPPAUGE_WINTV_HVR_900_R2 },
1817         { USB_DEVICE(0x2040, 0x6513), /* HCW HVR-980 */
1818                         .driver_info = EM2883_BOARD_HAUPPAUGE_WINTV_HVR_950 },
1819         { USB_DEVICE(0x2040, 0x6517), /* HP  HVR-950 */
1820                         .driver_info = EM2883_BOARD_HAUPPAUGE_WINTV_HVR_950 },
1821         { USB_DEVICE(0x2040, 0x651b), /* RP  HVR-950 */
1822                         .driver_info = EM2883_BOARD_HAUPPAUGE_WINTV_HVR_950 },
1823         { USB_DEVICE(0x2040, 0x651f),
1824                         .driver_info = EM2883_BOARD_HAUPPAUGE_WINTV_HVR_850 },
1825         { USB_DEVICE(0x0438, 0xb002),
1826                         .driver_info = EM2880_BOARD_AMD_ATI_TV_WONDER_HD_600 },
1827         { USB_DEVICE(0x2001, 0xf112),
1828                         .driver_info = EM2820_BOARD_DLINK_USB_TV },
1829         { USB_DEVICE(0x2304, 0x0207),
1830                         .driver_info = EM2820_BOARD_PINNACLE_DVC_90 },
1831         { USB_DEVICE(0x2304, 0x0208),
1832                         .driver_info = EM2820_BOARD_PINNACLE_USB_2 },
1833         { USB_DEVICE(0x2304, 0x021a),
1834                         .driver_info = EM2820_BOARD_PINNACLE_DVC_90 },
1835         { USB_DEVICE(0x2304, 0x0226),
1836                         .driver_info = EM2882_BOARD_PINNACLE_HYBRID_PRO },
1837         { USB_DEVICE(0x2304, 0x0227),
1838                         .driver_info = EM2880_BOARD_PINNACLE_PCTV_HD_PRO },
1839         { USB_DEVICE(0x0413, 0x6023),
1840                         .driver_info = EM2800_BOARD_LEADTEK_WINFAST_USBII },
1841         { USB_DEVICE(0x093b, 0xa005),
1842                         .driver_info = EM2861_BOARD_PLEXTOR_PX_TV100U },
1843         { USB_DEVICE(0x04bb, 0x0515),
1844                         .driver_info = EM2820_BOARD_IODATA_GVMVP_SZ },
1845         { USB_DEVICE(0xeb1a, 0x50a6),
1846                         .driver_info = EM2860_BOARD_GADMEI_UTV330 },
1847         { USB_DEVICE(0x1b80, 0xa340),
1848                         .driver_info = EM2870_BOARD_KWORLD_A340 },
1849         { },
1850 };
1851 MODULE_DEVICE_TABLE(usb, em28xx_id_table);
1852
1853 /*
1854  * EEPROM hash table for devices with generic USB IDs
1855  */
1856 static struct em28xx_hash_table em28xx_eeprom_hash[] = {
1857         /* P/N: SA 60002070465 Tuner: TVF7533-MF */
1858         {0x6ce05a8f, EM2820_BOARD_PROLINK_PLAYTV_USB2, TUNER_YMEC_TVF_5533MF},
1859         {0x72cc5a8b, EM2820_BOARD_PROLINK_PLAYTV_BOX4_USB2, TUNER_YMEC_TVF_5533MF},
1860         {0x966a0441, EM2880_BOARD_KWORLD_DVB_310U, TUNER_XC2028},
1861         {0x166a0441, EM2880_BOARD_EMPIRE_DUAL_TV, TUNER_XC2028},
1862         {0xcee44a99, EM2882_BOARD_EVGA_INDTUBE, TUNER_XC2028},
1863         {0xb8846b20, EM2881_BOARD_PINNACLE_HYBRID_PRO, TUNER_XC2028},
1864         {0x63f653bd, EM2870_BOARD_REDDO_DVB_C_USB_BOX, TUNER_ABSENT},
1865         {0x4e913442, EM2882_BOARD_DIKOM_DK300, TUNER_XC2028},
1866 };
1867
1868 /* I2C devicelist hash table for devices with generic USB IDs */
1869 static struct em28xx_hash_table em28xx_i2c_hash[] = {
1870         {0xb06a32c3, EM2800_BOARD_TERRATEC_CINERGY_200, TUNER_LG_PAL_NEW_TAPC},
1871         {0xf51200e3, EM2800_BOARD_VGEAR_POCKETTV, TUNER_LG_PAL_NEW_TAPC},
1872         {0x1ba50080, EM2860_BOARD_SAA711X_REFERENCE_DESIGN, TUNER_ABSENT},
1873         {0x77800080, EM2860_BOARD_TVP5150_REFERENCE_DESIGN, TUNER_ABSENT},
1874         {0xc51200e3, EM2820_BOARD_GADMEI_TVR200, TUNER_LG_PAL_NEW_TAPC},
1875         {0x4ba50080, EM2861_BOARD_GADMEI_UTV330PLUS, TUNER_TNF_5335MF},
1876 };
1877
1878 /* I2C possible address to saa7115, tvp5150, msp3400, tvaudio */
1879 static unsigned short saa711x_addrs[] = {
1880         0x4a >> 1, 0x48 >> 1,   /* SAA7111, SAA7111A and SAA7113 */
1881         0x42 >> 1, 0x40 >> 1,   /* SAA7114, SAA7115 and SAA7118 */
1882         I2C_CLIENT_END };
1883
1884 static unsigned short tvp5150_addrs[] = {
1885         0xb8 >> 1,
1886         0xba >> 1,
1887         I2C_CLIENT_END
1888 };
1889
1890 static unsigned short mt9v011_addrs[] = {
1891         0xba >> 1,
1892         I2C_CLIENT_END
1893 };
1894
1895 static unsigned short msp3400_addrs[] = {
1896         0x80 >> 1,
1897         0x88 >> 1,
1898         I2C_CLIENT_END
1899 };
1900
1901 int em28xx_tuner_callback(void *ptr, int component, int command, int arg)
1902 {
1903         int rc = 0;
1904         struct em28xx *dev = ptr;
1905
1906         if (dev->tuner_type != TUNER_XC2028)
1907                 return 0;
1908
1909         if (command != XC2028_TUNER_RESET)
1910                 return 0;
1911
1912         rc = em28xx_gpio_set(dev, dev->board.tuner_gpio);
1913
1914         return rc;
1915 }
1916 EXPORT_SYMBOL_GPL(em28xx_tuner_callback);
1917
1918 static inline void em28xx_set_model(struct em28xx *dev)
1919 {
1920         memcpy(&dev->board, &em28xx_boards[dev->model], sizeof(dev->board));
1921
1922         /* Those are the default values for the majority of boards
1923            Use those values if not specified otherwise at boards entry
1924          */
1925         if (!dev->board.xclk)
1926                 dev->board.xclk = EM28XX_XCLK_IR_RC5_MODE |
1927                                   EM28XX_XCLK_FREQUENCY_12MHZ;
1928
1929         if (!dev->board.i2c_speed)
1930                 dev->board.i2c_speed = EM28XX_I2C_CLK_WAIT_ENABLE |
1931                                        EM28XX_I2C_FREQ_100_KHZ;
1932 }
1933
1934
1935 /* FIXME: Should be replaced by a proper mt9m111 driver */
1936 static int em28xx_initialize_mt9m111(struct em28xx *dev)
1937 {
1938         int i;
1939         unsigned char regs[][3] = {
1940                 { 0x0d, 0x00, 0x01, },  /* reset and use defaults */
1941                 { 0x0d, 0x00, 0x00, },
1942                 { 0x0a, 0x00, 0x21, },
1943                 { 0x21, 0x04, 0x00, },  /* full readout speed, no row/col skipping */
1944         };
1945
1946         for (i = 0; i < ARRAY_SIZE(regs); i++)
1947                 i2c_master_send(&dev->i2c_client, &regs[i][0], 3);
1948
1949         return 0;
1950 }
1951
1952
1953 /* FIXME: Should be replaced by a proper mt9m001 driver */
1954 static int em28xx_initialize_mt9m001(struct em28xx *dev)
1955 {
1956         int i;
1957         unsigned char regs[][3] = {
1958                 { 0x0d, 0x00, 0x01, },
1959                 { 0x0d, 0x00, 0x00, },
1960                 { 0x04, 0x05, 0x00, },  /* hres = 1280 */
1961                 { 0x03, 0x04, 0x00, },  /* vres = 1024 */
1962                 { 0x20, 0x11, 0x00, },
1963                 { 0x06, 0x00, 0x10, },
1964                 { 0x2b, 0x00, 0x24, },
1965                 { 0x2e, 0x00, 0x24, },
1966                 { 0x35, 0x00, 0x24, },
1967                 { 0x2d, 0x00, 0x20, },
1968                 { 0x2c, 0x00, 0x20, },
1969                 { 0x09, 0x0a, 0xd4, },
1970                 { 0x35, 0x00, 0x57, },
1971         };
1972
1973         for (i = 0; i < ARRAY_SIZE(regs); i++)
1974                 i2c_master_send(&dev->i2c_client, &regs[i][0], 3);
1975
1976         return 0;
1977 }
1978
1979 /* HINT method: webcam I2C chips
1980  *
1981  * This method works for webcams with Micron sensors
1982  */
1983 static int em28xx_hint_sensor(struct em28xx *dev)
1984 {
1985         int rc;
1986         char *sensor_name;
1987         unsigned char cmd;
1988         __be16 version_be;
1989         u16 version;
1990
1991         /* Micron sensor detection */
1992         dev->i2c_client.addr = 0xba >> 1;
1993         cmd = 0;
1994         i2c_master_send(&dev->i2c_client, &cmd, 1);
1995         rc = i2c_master_recv(&dev->i2c_client, (char *)&version_be, 2);
1996         if (rc != 2)
1997                 return -EINVAL;
1998
1999         version = be16_to_cpu(version_be);
2000         switch (version) {
2001         case 0x8232:            /* mt9v011 640x480 1.3 Mpix sensor */
2002         case 0x8243:            /* mt9v011 rev B 640x480 1.3 Mpix sensor */
2003                 dev->model = EM2820_BOARD_SILVERCREST_WEBCAM;
2004                 em28xx_set_model(dev);
2005
2006                 sensor_name = "mt9v011";
2007                 dev->em28xx_sensor = EM28XX_MT9V011;
2008                 dev->sensor_xres = 640;
2009                 dev->sensor_yres = 480;
2010                 /*
2011                  * FIXME: mt9v011 uses I2S speed as xtal clk - at least with
2012                  * the Silvercrest cam I have here for testing - for higher
2013                  * resolutions, a high clock cause horizontal artifacts, so we
2014                  * need to use a lower xclk frequency.
2015                  * Yet, it would be possible to adjust xclk depending on the
2016                  * desired resolution, since this affects directly the
2017                  * frame rate.
2018                  */
2019                 dev->board.xclk = EM28XX_XCLK_FREQUENCY_4_3MHZ;
2020                 dev->sensor_xtal = 4300000;
2021
2022                 /* probably means GRGB 16 bit bayer */
2023                 dev->vinmode = 0x0d;
2024                 dev->vinctl = 0x00;
2025
2026                 break;
2027
2028         case 0x143a:    /* MT9M111 as found in the ECS G200 */
2029                 dev->model = EM2750_BOARD_UNKNOWN;
2030                 em28xx_set_model(dev);
2031
2032                 sensor_name = "mt9m111";
2033                 dev->board.xclk = EM28XX_XCLK_FREQUENCY_48MHZ;
2034                 dev->em28xx_sensor = EM28XX_MT9M111;
2035                 em28xx_initialize_mt9m111(dev);
2036                 dev->sensor_xres = 640;
2037                 dev->sensor_yres = 512;
2038
2039                 dev->vinmode = 0x0a;
2040                 dev->vinctl = 0x00;
2041
2042                 break;
2043
2044         case 0x8431:
2045                 dev->model = EM2750_BOARD_UNKNOWN;
2046                 em28xx_set_model(dev);
2047
2048                 sensor_name = "mt9m001";
2049                 dev->em28xx_sensor = EM28XX_MT9M001;
2050                 em28xx_initialize_mt9m001(dev);
2051                 dev->sensor_xres = 1280;
2052                 dev->sensor_yres = 1024;
2053
2054                 /* probably means BGGR 16 bit bayer */
2055                 dev->vinmode = 0x0c;
2056                 dev->vinctl = 0x00;
2057
2058                 break;
2059         default:
2060                 printk("Unknown Micron Sensor 0x%04x\n", version);
2061                 return -EINVAL;
2062         }
2063
2064         /* Setup webcam defaults */
2065         em28xx_pre_card_setup(dev);
2066
2067         em28xx_errdev("Sensor is %s, using model %s entry.\n",
2068                       sensor_name, em28xx_boards[dev->model].name);
2069
2070         return 0;
2071 }
2072
2073 /* Since em28xx_pre_card_setup() requires a proper dev->model,
2074  * this won't work for boards with generic PCI IDs
2075  */
2076 void em28xx_pre_card_setup(struct em28xx *dev)
2077 {
2078         /* Set the initial XCLK and I2C clock values based on the board
2079            definition */
2080         em28xx_write_reg(dev, EM28XX_R0F_XCLK, dev->board.xclk & 0x7f);
2081         em28xx_write_reg(dev, EM28XX_R06_I2C_CLK, dev->board.i2c_speed);
2082         msleep(50);
2083
2084         /* request some modules */
2085         switch (dev->model) {
2086         case EM2861_BOARD_PLEXTOR_PX_TV100U:
2087                 /* Sets the msp34xx I2S speed */
2088                 dev->i2s_speed = 2048000;
2089                 break;
2090         case EM2861_BOARD_KWORLD_PVRTV_300U:
2091         case EM2880_BOARD_KWORLD_DVB_305U:
2092                 em28xx_write_reg(dev, EM28XX_R08_GPIO, 0x6d);
2093                 msleep(10);
2094                 em28xx_write_reg(dev, EM28XX_R08_GPIO, 0x7d);
2095                 msleep(10);
2096                 break;
2097         case EM2870_BOARD_COMPRO_VIDEOMATE:
2098                 /* TODO: someone can do some cleanup here...
2099                          not everything's needed */
2100                 em28xx_write_reg(dev, EM2880_R04_GPO, 0x00);
2101                 msleep(10);
2102                 em28xx_write_reg(dev, EM2880_R04_GPO, 0x01);
2103                 msleep(10);
2104                 em28xx_write_reg(dev, EM28XX_R08_GPIO, 0xfd);
2105                 mdelay(70);
2106                 em28xx_write_reg(dev, EM28XX_R08_GPIO, 0xfc);
2107                 mdelay(70);
2108                 em28xx_write_reg(dev, EM28XX_R08_GPIO, 0xdc);
2109                 mdelay(70);
2110                 em28xx_write_reg(dev, EM28XX_R08_GPIO, 0xfc);
2111                 mdelay(70);
2112                 break;
2113         case EM2870_BOARD_TERRATEC_XS_MT2060:
2114                 /* this device needs some gpio writes to get the DVB-T
2115                    demod work */
2116                 em28xx_write_reg(dev, EM28XX_R08_GPIO, 0xfe);
2117                 mdelay(70);
2118                 em28xx_write_reg(dev, EM28XX_R08_GPIO, 0xde);
2119                 mdelay(70);
2120                 em28xx_write_reg(dev, EM28XX_R08_GPIO, 0xfe);
2121                 mdelay(70);
2122                 break;
2123         case EM2870_BOARD_PINNACLE_PCTV_DVB:
2124                 /* this device needs some gpio writes to get the
2125                    DVB-T demod work */
2126                 em28xx_write_reg(dev, EM28XX_R08_GPIO, 0xfe);
2127                 mdelay(70);
2128                 em28xx_write_reg(dev, EM28XX_R08_GPIO, 0xde);
2129                 mdelay(70);
2130                 em28xx_write_reg(dev, EM28XX_R08_GPIO, 0xfe);
2131                 mdelay(70);
2132                 break;
2133         case EM2820_BOARD_GADMEI_UTV310:
2134         case EM2820_BOARD_MSI_VOX_USB_2:
2135                 /* enables audio for that devices */
2136                 em28xx_write_reg(dev, EM28XX_R08_GPIO, 0xfd);
2137                 break;
2138
2139         case EM2882_BOARD_KWORLD_ATSC_315U:
2140                 em28xx_write_reg(dev, EM28XX_R08_GPIO, 0xff);
2141                 msleep(10);
2142                 em28xx_write_reg(dev, EM28XX_R08_GPIO, 0xfe);
2143                 msleep(10);
2144                 em28xx_write_reg(dev, EM2880_R04_GPO, 0x00);
2145                 msleep(10);
2146                 em28xx_write_reg(dev, EM2880_R04_GPO, 0x08);
2147                 msleep(10);
2148                 break;
2149
2150         case EM2860_BOARD_KAIOMY_TVNPC_U2:
2151                 em28xx_write_regs(dev, EM28XX_R0F_XCLK, "\x07", 1);
2152                 em28xx_write_regs(dev, EM28XX_R06_I2C_CLK, "\x40", 1);
2153                 em28xx_write_regs(dev, 0x0d, "\x42", 1);
2154                 em28xx_write_regs(dev, 0x08, "\xfd", 1);
2155                 msleep(10);
2156                 em28xx_write_regs(dev, 0x08, "\xff", 1);
2157                 msleep(10);
2158                 em28xx_write_regs(dev, 0x08, "\x7f", 1);
2159                 msleep(10);
2160                 em28xx_write_regs(dev, 0x08, "\x6b", 1);
2161
2162                 break;
2163         case EM2860_BOARD_EASYCAP:
2164                 em28xx_write_regs(dev, 0x08, "\xf8", 1);
2165                 break;
2166
2167         case EM2820_BOARD_IODATA_GVMVP_SZ:
2168                 em28xx_write_reg(dev, EM28XX_R08_GPIO, 0xff);
2169                 msleep(70);
2170                 em28xx_write_reg(dev, EM28XX_R08_GPIO, 0xf7);
2171                 msleep(10);
2172                 em28xx_write_reg(dev, EM28XX_R08_GPIO, 0xfe);
2173                 msleep(70);
2174                 em28xx_write_reg(dev, EM28XX_R08_GPIO, 0xfd);
2175                 msleep(70);
2176                 break;
2177         }
2178
2179         em28xx_gpio_set(dev, dev->board.tuner_gpio);
2180         em28xx_set_mode(dev, EM28XX_ANALOG_MODE);
2181
2182         /* Unlock device */
2183         em28xx_set_mode(dev, EM28XX_SUSPEND);
2184 }
2185
2186 static void em28xx_setup_xc3028(struct em28xx *dev, struct xc2028_ctrl *ctl)
2187 {
2188         memset(ctl, 0, sizeof(*ctl));
2189
2190         ctl->fname   = XC2028_DEFAULT_FIRMWARE;
2191         ctl->max_len = 64;
2192         ctl->mts = em28xx_boards[dev->model].mts_firmware;
2193
2194         switch (dev->model) {
2195         case EM2880_BOARD_EMPIRE_DUAL_TV:
2196         case EM2880_BOARD_HAUPPAUGE_WINTV_HVR_900:
2197         case EM2882_BOARD_TERRATEC_HYBRID_XS:
2198                 ctl->demod = XC3028_FE_ZARLINK456;
2199                 break;
2200         case EM2880_BOARD_TERRATEC_HYBRID_XS:
2201         case EM2880_BOARD_TERRATEC_HYBRID_XS_FR:
2202         case EM2881_BOARD_PINNACLE_HYBRID_PRO:
2203                 ctl->demod = XC3028_FE_ZARLINK456;
2204                 break;
2205         case EM2880_BOARD_HAUPPAUGE_WINTV_HVR_900_R2:
2206                 /* djh - Not sure which demod we need here */
2207                 ctl->demod = XC3028_FE_DEFAULT;
2208                 break;
2209         case EM2880_BOARD_AMD_ATI_TV_WONDER_HD_600:
2210                 ctl->demod = XC3028_FE_DEFAULT;
2211                 ctl->fname = XC3028L_DEFAULT_FIRMWARE;
2212                 break;
2213         case EM2883_BOARD_HAUPPAUGE_WINTV_HVR_850:
2214         case EM2883_BOARD_HAUPPAUGE_WINTV_HVR_950:
2215         case EM2880_BOARD_PINNACLE_PCTV_HD_PRO:
2216                 /* FIXME: Better to specify the needed IF */
2217                 ctl->demod = XC3028_FE_DEFAULT;
2218                 break;
2219         case EM2883_BOARD_KWORLD_HYBRID_330U:
2220         case EM2882_BOARD_DIKOM_DK300:
2221         case EM2882_BOARD_KWORLD_VS_DVBT:
2222                 ctl->demod = XC3028_FE_CHINA;
2223                 ctl->fname = XC2028_DEFAULT_FIRMWARE;
2224                 break;
2225         case EM2882_BOARD_EVGA_INDTUBE:
2226                 ctl->demod = XC3028_FE_CHINA;
2227                 ctl->fname = XC3028L_DEFAULT_FIRMWARE;
2228                 break;
2229         default:
2230                 ctl->demod = XC3028_FE_OREN538;
2231         }
2232 }
2233
2234 static void em28xx_tuner_setup(struct em28xx *dev)
2235 {
2236         struct tuner_setup           tun_setup;
2237         struct v4l2_frequency        f;
2238
2239         if (dev->tuner_type == TUNER_ABSENT)
2240                 return;
2241
2242         memset(&tun_setup, 0, sizeof(tun_setup));
2243
2244         tun_setup.mode_mask = T_ANALOG_TV | T_RADIO;
2245         tun_setup.tuner_callback = em28xx_tuner_callback;
2246
2247         if (dev->board.radio.type) {
2248                 tun_setup.type = dev->board.radio.type;
2249                 tun_setup.addr = dev->board.radio_addr;
2250
2251                 v4l2_device_call_all(&dev->v4l2_dev, 0, tuner, s_type_addr, &tun_setup);
2252         }
2253
2254         if ((dev->tuner_type != TUNER_ABSENT) && (dev->tuner_type)) {
2255                 tun_setup.type   = dev->tuner_type;
2256                 tun_setup.addr   = dev->tuner_addr;
2257
2258                 v4l2_device_call_all(&dev->v4l2_dev, 0, tuner, s_type_addr, &tun_setup);
2259         }
2260
2261         if (dev->tda9887_conf) {
2262                 struct v4l2_priv_tun_config tda9887_cfg;
2263
2264                 tda9887_cfg.tuner = TUNER_TDA9887;
2265                 tda9887_cfg.priv = &dev->tda9887_conf;
2266
2267                 v4l2_device_call_all(&dev->v4l2_dev, 0, tuner, s_config, &tda9887_cfg);
2268         }
2269
2270         if (dev->tuner_type == TUNER_XC2028) {
2271                 struct v4l2_priv_tun_config  xc2028_cfg;
2272                 struct xc2028_ctrl           ctl;
2273
2274                 memset(&xc2028_cfg, 0, sizeof(xc2028_cfg));
2275                 memset(&ctl, 0, sizeof(ctl));
2276
2277                 em28xx_setup_xc3028(dev, &ctl);
2278
2279                 xc2028_cfg.tuner = TUNER_XC2028;
2280                 xc2028_cfg.priv  = &ctl;
2281
2282                 v4l2_device_call_all(&dev->v4l2_dev, 0, tuner, s_config, &xc2028_cfg);
2283         }
2284
2285         /* configure tuner */
2286         f.tuner = 0;
2287         f.type = V4L2_TUNER_ANALOG_TV;
2288         f.frequency = 9076;     /* just a magic number */
2289         dev->ctl_freq = f.frequency;
2290         v4l2_device_call_all(&dev->v4l2_dev, 0, tuner, s_frequency, &f);
2291 }
2292
2293 static int em28xx_hint_board(struct em28xx *dev)
2294 {
2295         int i;
2296
2297         /* HINT method: EEPROM
2298          *
2299          * This method works only for boards with eeprom.
2300          * Uses a hash of all eeprom bytes. The hash should be
2301          * unique for a vendor/tuner pair.
2302          * There are a high chance that tuners for different
2303          * video standards produce different hashes.
2304          */
2305         for (i = 0; i < ARRAY_SIZE(em28xx_eeprom_hash); i++) {
2306                 if (dev->hash == em28xx_eeprom_hash[i].hash) {
2307                         dev->model = em28xx_eeprom_hash[i].model;
2308                         dev->tuner_type = em28xx_eeprom_hash[i].tuner;
2309
2310                         em28xx_errdev("Your board has no unique USB ID.\n");
2311                         em28xx_errdev("A hint were successfully done, "
2312                                       "based on eeprom hash.\n");
2313                         em28xx_errdev("This method is not 100%% failproof.\n");
2314                         em28xx_errdev("If the board were missdetected, "
2315                                       "please email this log to:\n");
2316                         em28xx_errdev("\tV4L Mailing List "
2317                                       " <linux-media@vger.kernel.org>\n");
2318                         em28xx_errdev("Board detected as %s\n",
2319                                       em28xx_boards[dev->model].name);
2320
2321                         return 0;
2322                 }
2323         }
2324
2325         /* HINT method: I2C attached devices
2326          *
2327          * This method works for all boards.
2328          * Uses a hash of i2c scanned devices.
2329          * Devices with the same i2c attached chips will
2330          * be considered equal.
2331          * This method is less precise than the eeprom one.
2332          */
2333
2334         /* user did not request i2c scanning => do it now */
2335         if (!dev->i2c_hash)
2336                 em28xx_do_i2c_scan(dev);
2337
2338         for (i = 0; i < ARRAY_SIZE(em28xx_i2c_hash); i++) {
2339                 if (dev->i2c_hash == em28xx_i2c_hash[i].hash) {
2340                         dev->model = em28xx_i2c_hash[i].model;
2341                         dev->tuner_type = em28xx_i2c_hash[i].tuner;
2342                         em28xx_errdev("Your board has no unique USB ID.\n");
2343                         em28xx_errdev("A hint were successfully done, "
2344                                       "based on i2c devicelist hash.\n");
2345                         em28xx_errdev("This method is not 100%% failproof.\n");
2346                         em28xx_errdev("If the board were missdetected, "
2347                                       "please email this log to:\n");
2348                         em28xx_errdev("\tV4L Mailing List "
2349                                       " <linux-media@vger.kernel.org>\n");
2350                         em28xx_errdev("Board detected as %s\n",
2351                                       em28xx_boards[dev->model].name);
2352
2353                         return 0;
2354                 }
2355         }
2356
2357         em28xx_errdev("Your board has no unique USB ID and thus need a "
2358                       "hint to be detected.\n");
2359         em28xx_errdev("You may try to use card=<n> insmod option to "
2360                       "workaround that.\n");
2361         em28xx_errdev("Please send an email with this log to:\n");
2362         em28xx_errdev("\tV4L Mailing List <linux-media@vger.kernel.org>\n");
2363         em28xx_errdev("Board eeprom hash is 0x%08lx\n", dev->hash);
2364         em28xx_errdev("Board i2c devicelist hash is 0x%08lx\n", dev->i2c_hash);
2365
2366         em28xx_errdev("Here is a list of valid choices for the card=<n>"
2367                       " insmod option:\n");
2368         for (i = 0; i < em28xx_bcount; i++) {
2369                 em28xx_errdev("    card=%d -> %s\n",
2370                                 i, em28xx_boards[i].name);
2371         }
2372         return -1;
2373 }
2374
2375 /* ----------------------------------------------------------------------- */
2376 void em28xx_register_i2c_ir(struct em28xx *dev)
2377 {
2378         /* Leadtek winfast tv USBII deluxe can find a non working IR-device */
2379         /* at address 0x18, so if that address is needed for another board in */
2380         /* the future, please put it after 0x1f. */
2381         struct i2c_board_info info;
2382         const unsigned short addr_list[] = {
2383                  0x1f, 0x30, 0x47, I2C_CLIENT_END
2384         };
2385
2386         if (disable_ir)
2387                 return;
2388
2389         memset(&info, 0, sizeof(struct i2c_board_info));
2390         memset(&dev->init_data, 0, sizeof(dev->init_data));
2391         strlcpy(info.type, "ir_video", I2C_NAME_SIZE);
2392
2393         /* detect & configure */
2394         switch (dev->model) {
2395         case EM2800_BOARD_TERRATEC_CINERGY_200:
2396         case EM2820_BOARD_TERRATEC_CINERGY_250:
2397                 dev->init_data.ir_codes = RC_MAP_EM_TERRATEC;
2398                 dev->init_data.get_key = em28xx_get_key_terratec;
2399                 dev->init_data.name = "i2c IR (EM28XX Terratec)";
2400                 break;
2401         case EM2820_BOARD_PINNACLE_USB_2:
2402                 dev->init_data.ir_codes = RC_MAP_PINNACLE_GREY;
2403                 dev->init_data.get_key = em28xx_get_key_pinnacle_usb_grey;
2404                 dev->init_data.name = "i2c IR (EM28XX Pinnacle PCTV)";
2405                 break;
2406         case EM2820_BOARD_HAUPPAUGE_WINTV_USB_2:
2407                 dev->init_data.ir_codes = RC_MAP_RC5_HAUPPAUGE_NEW;
2408                 dev->init_data.get_key = em28xx_get_key_em_haup;
2409                 dev->init_data.name = "i2c IR (EM2840 Hauppauge)";
2410         case EM2820_BOARD_LEADTEK_WINFAST_USBII_DELUXE:
2411                 dev->init_data.ir_codes = RC_MAP_WINFAST_USBII_DELUXE;;
2412                 dev->init_data.get_key = em28xx_get_key_winfast_usbii_deluxe;
2413                 dev->init_data.name = "i2c IR (EM2820 Winfast TV USBII Deluxe)";
2414                 break;
2415         }
2416
2417         if (dev->init_data.name)
2418                 info.platform_data = &dev->init_data;
2419         i2c_new_probed_device(&dev->i2c_adap, &info, addr_list, NULL);
2420 }
2421
2422 void em28xx_card_setup(struct em28xx *dev)
2423 {
2424         /*
2425          * If the device can be a webcam, seek for a sensor.
2426          * If sensor is not found, then it isn't a webcam.
2427          */
2428         if (dev->board.is_webcam) {
2429                 if (em28xx_hint_sensor(dev) < 0)
2430                         dev->board.is_webcam = 0;
2431                 else
2432                         dev->progressive = 1;
2433         } else
2434                 em28xx_set_model(dev);
2435
2436         em28xx_info("Identified as %s (card=%d)\n",
2437                     dev->board.name, dev->model);
2438
2439         dev->tuner_type = em28xx_boards[dev->model].tuner_type;
2440         if (em28xx_boards[dev->model].tuner_addr)
2441                 dev->tuner_addr = em28xx_boards[dev->model].tuner_addr;
2442
2443         if (em28xx_boards[dev->model].tda9887_conf)
2444                 dev->tda9887_conf = em28xx_boards[dev->model].tda9887_conf;
2445
2446         /* request some modules */
2447         switch (dev->model) {
2448         case EM2820_BOARD_HAUPPAUGE_WINTV_USB_2:
2449         case EM2880_BOARD_HAUPPAUGE_WINTV_HVR_900:
2450         case EM2880_BOARD_HAUPPAUGE_WINTV_HVR_900_R2:
2451         case EM2883_BOARD_HAUPPAUGE_WINTV_HVR_850:
2452         case EM2883_BOARD_HAUPPAUGE_WINTV_HVR_950:
2453         {
2454                 struct tveeprom tv;
2455 #if defined(CONFIG_MODULES) && defined(MODULE)
2456                 request_module("tveeprom");
2457 #endif
2458                 /* Call first TVeeprom */
2459
2460                 dev->i2c_client.addr = 0xa0 >> 1;
2461                 tveeprom_hauppauge_analog(&dev->i2c_client, &tv, dev->eedata);
2462
2463                 dev->tuner_type = tv.tuner_type;
2464
2465                 if (tv.audio_processor == V4L2_IDENT_MSPX4XX) {
2466                         dev->i2s_speed = 2048000;
2467                         dev->board.has_msp34xx = 1;
2468                 }
2469                 break;
2470         }
2471         case EM2882_BOARD_KWORLD_ATSC_315U:
2472                 em28xx_write_reg(dev, 0x0d, 0x42);
2473                 msleep(10);
2474                 em28xx_write_reg(dev, EM28XX_R08_GPIO, 0xfd);
2475                 msleep(10);
2476                 break;
2477         case EM2820_BOARD_KWORLD_PVRTV2800RF:
2478                 /* GPIO enables sound on KWORLD PVR TV 2800RF */
2479                 em28xx_write_reg(dev, EM28XX_R08_GPIO, 0xf9);
2480                 break;
2481         case EM2820_BOARD_UNKNOWN:
2482         case EM2800_BOARD_UNKNOWN:
2483                 /*
2484                  * The K-WORLD DVB-T 310U is detected as an MSI Digivox AD.
2485                  *
2486                  * This occurs because they share identical USB vendor and
2487                  * product IDs.
2488                  *
2489                  * What we do here is look up the EEPROM hash of the K-WORLD
2490                  * and if it is found then we decide that we do not have
2491                  * a DIGIVOX and reset the device to the K-WORLD instead.
2492                  *
2493                  * This solution is only valid if they do not share eeprom
2494                  * hash identities which has not been determined as yet.
2495                  */
2496         case EM2880_BOARD_MSI_DIGIVOX_AD:
2497                 if (!em28xx_hint_board(dev))
2498                         em28xx_set_model(dev);
2499
2500                 /* In cases where we had to use a board hint, the call to
2501                    em28xx_set_mode() in em28xx_pre_card_setup() was a no-op,
2502                    so make the call now so the analog GPIOs are set properly
2503                    before probing the i2c bus. */
2504                 em28xx_gpio_set(dev, dev->board.tuner_gpio);
2505                 em28xx_set_mode(dev, EM28XX_ANALOG_MODE);
2506                 break;
2507
2508 /*
2509                  * The Dikom DK300 is detected as an Kworld VS-DVB-T 323UR.
2510                  *
2511                  * This occurs because they share identical USB vendor and
2512                  * product IDs.
2513                  *
2514                  * What we do here is look up the EEPROM hash of the Dikom
2515                  * and if it is found then we decide that we do not have
2516                  * a Kworld and reset the device to the Dikom instead.
2517                  *
2518                  * This solution is only valid if they do not share eeprom
2519                  * hash identities which has not been determined as yet.
2520                  */
2521         case EM2882_BOARD_KWORLD_VS_DVBT:
2522                 if (!em28xx_hint_board(dev))
2523                         em28xx_set_model(dev);
2524
2525                 /* In cases where we had to use a board hint, the call to
2526                    em28xx_set_mode() in em28xx_pre_card_setup() was a no-op,
2527                    so make the call now so the analog GPIOs are set properly
2528                    before probing the i2c bus. */
2529                 em28xx_gpio_set(dev, dev->board.tuner_gpio);
2530                 em28xx_set_mode(dev, EM28XX_ANALOG_MODE);
2531                 break;
2532         }
2533
2534 #if defined(CONFIG_MODULES) && defined(MODULE)
2535         if (dev->board.has_ir_i2c && !disable_ir)
2536                 request_module("ir-kbd-i2c");
2537 #endif
2538         if (dev->board.has_snapshot_button)
2539                 em28xx_register_snapshot_button(dev);
2540
2541         if (dev->board.valid == EM28XX_BOARD_NOT_VALIDATED) {
2542                 em28xx_errdev("\n\n");
2543                 em28xx_errdev("The support for this board weren't "
2544                               "valid yet.\n");
2545                 em28xx_errdev("Please send a report of having this working\n");
2546                 em28xx_errdev("not to V4L mailing list (and/or to other "
2547                                 "addresses)\n\n");
2548         }
2549
2550         /* Allow override tuner type by a module parameter */
2551         if (tuner >= 0)
2552                 dev->tuner_type = tuner;
2553
2554         /* request some modules */
2555         if (dev->board.has_msp34xx)
2556                 v4l2_i2c_new_subdev(&dev->v4l2_dev, &dev->i2c_adap,
2557                         NULL, "msp3400", 0, msp3400_addrs);
2558
2559         if (dev->board.decoder == EM28XX_SAA711X)
2560                 v4l2_i2c_new_subdev(&dev->v4l2_dev, &dev->i2c_adap,
2561                         NULL, "saa7115_auto", 0, saa711x_addrs);
2562
2563         if (dev->board.decoder == EM28XX_TVP5150)
2564                 v4l2_i2c_new_subdev(&dev->v4l2_dev, &dev->i2c_adap,
2565                         NULL, "tvp5150", 0, tvp5150_addrs);
2566
2567         if (dev->em28xx_sensor == EM28XX_MT9V011) {
2568                 struct v4l2_subdev *sd;
2569
2570                 sd = v4l2_i2c_new_subdev(&dev->v4l2_dev,
2571                          &dev->i2c_adap, NULL, "mt9v011", 0, mt9v011_addrs);
2572                 v4l2_subdev_call(sd, core, s_config, 0, &dev->sensor_xtal);
2573         }
2574
2575
2576         if (dev->board.adecoder == EM28XX_TVAUDIO)
2577                 v4l2_i2c_new_subdev(&dev->v4l2_dev, &dev->i2c_adap,
2578                         NULL, "tvaudio", dev->board.tvaudio_addr, NULL);
2579
2580         if (dev->board.tuner_type != TUNER_ABSENT) {
2581                 int has_demod = (dev->tda9887_conf & TDA9887_PRESENT);
2582
2583                 if (dev->board.radio.type)
2584                         v4l2_i2c_new_subdev(&dev->v4l2_dev, &dev->i2c_adap,
2585                                 NULL, "tuner", dev->board.radio_addr, NULL);
2586
2587                 if (has_demod)
2588                         v4l2_i2c_new_subdev(&dev->v4l2_dev,
2589                                 &dev->i2c_adap, NULL, "tuner",
2590                                 0, v4l2_i2c_tuner_addrs(ADDRS_DEMOD));
2591                 if (dev->tuner_addr == 0) {
2592                         enum v4l2_i2c_tuner_type type =
2593                                 has_demod ? ADDRS_TV_WITH_DEMOD : ADDRS_TV;
2594                         struct v4l2_subdev *sd;
2595
2596                         sd = v4l2_i2c_new_subdev(&dev->v4l2_dev,
2597                                 &dev->i2c_adap, NULL, "tuner",
2598                                 0, v4l2_i2c_tuner_addrs(type));
2599
2600                         if (sd)
2601                                 dev->tuner_addr = v4l2_i2c_subdev_addr(sd);
2602                 } else {
2603                         v4l2_i2c_new_subdev(&dev->v4l2_dev, &dev->i2c_adap,
2604                                 NULL, "tuner", dev->tuner_addr, NULL);
2605                 }
2606         }
2607
2608         em28xx_tuner_setup(dev);
2609
2610         if(!disable_ir)
2611                 em28xx_ir_init(dev);
2612 }
2613
2614
2615 #if defined(CONFIG_MODULES) && defined(MODULE)
2616 static void request_module_async(struct work_struct *work)
2617 {
2618         struct em28xx *dev = container_of(work,
2619                              struct em28xx, request_module_wk);
2620
2621         if (dev->has_audio_class)
2622                 request_module("snd-usb-audio");
2623         else if (dev->has_alsa_audio)
2624                 request_module("em28xx-alsa");
2625
2626         if (dev->board.has_dvb)
2627                 request_module("em28xx-dvb");
2628 }
2629
2630 static void request_modules(struct em28xx *dev)
2631 {
2632         INIT_WORK(&dev->request_module_wk, request_module_async);
2633         schedule_work(&dev->request_module_wk);
2634 }
2635 #else
2636 #define request_modules(dev)
2637 #endif /* CONFIG_MODULES */
2638
2639 /*
2640  * em28xx_realease_resources()
2641  * unregisters the v4l2,i2c and usb devices
2642  * called when the device gets disconected or at module unload
2643 */
2644 void em28xx_release_resources(struct em28xx *dev)
2645 {
2646         if (dev->sbutton_input_dev)
2647                 em28xx_deregister_snapshot_button(dev);
2648
2649         if (dev->ir)
2650                 em28xx_ir_fini(dev);
2651
2652         /*FIXME: I2C IR should be disconnected */
2653
2654         em28xx_release_analog_resources(dev);
2655
2656         em28xx_remove_from_devlist(dev);
2657
2658         em28xx_i2c_unregister(dev);
2659
2660         v4l2_device_unregister(&dev->v4l2_dev);
2661
2662         usb_put_dev(dev->udev);
2663
2664         /* Mark device as unused */
2665         em28xx_devused &= ~(1 << dev->devno);
2666 };
2667
2668 /*
2669  * em28xx_init_dev()
2670  * allocates and inits the device structs, registers i2c bus and v4l device
2671  */
2672 static int em28xx_init_dev(struct em28xx **devhandle, struct usb_device *udev,
2673                            struct usb_interface *interface,
2674                            int minor)
2675 {
2676         struct em28xx *dev = *devhandle;
2677         int retval;
2678         int errCode;
2679
2680         dev->udev = udev;
2681         mutex_init(&dev->ctrl_urb_lock);
2682         spin_lock_init(&dev->slock);
2683         init_waitqueue_head(&dev->open);
2684         init_waitqueue_head(&dev->wait_frame);
2685         init_waitqueue_head(&dev->wait_stream);
2686
2687         dev->em28xx_write_regs = em28xx_write_regs;
2688         dev->em28xx_read_reg = em28xx_read_reg;
2689         dev->em28xx_read_reg_req_len = em28xx_read_reg_req_len;
2690         dev->em28xx_write_regs_req = em28xx_write_regs_req;
2691         dev->em28xx_read_reg_req = em28xx_read_reg_req;
2692         dev->board.is_em2800 = em28xx_boards[dev->model].is_em2800;
2693
2694         em28xx_set_model(dev);
2695
2696         /* Set the default GPO/GPIO for legacy devices */
2697         dev->reg_gpo_num = EM2880_R04_GPO;
2698         dev->reg_gpio_num = EM28XX_R08_GPIO;
2699
2700         dev->wait_after_write = 5;
2701
2702         /* Based on the Chip ID, set the device configuration */
2703         retval = em28xx_read_reg(dev, EM28XX_R0A_CHIPID);
2704         if (retval > 0) {
2705                 dev->chip_id = retval;
2706
2707                 switch (dev->chip_id) {
2708                 case CHIP_ID_EM2800:
2709                         em28xx_info("chip ID is em2800\n");
2710                         break;
2711                 case CHIP_ID_EM2710:
2712                         em28xx_info("chip ID is em2710\n");
2713                         break;
2714                 case CHIP_ID_EM2750:
2715                         em28xx_info("chip ID is em2750\n");
2716                         break;
2717                 case CHIP_ID_EM2820:
2718                         em28xx_info("chip ID is em2820 (or em2710)\n");
2719                         break;
2720                 case CHIP_ID_EM2840:
2721                         em28xx_info("chip ID is em2840\n");
2722                         break;
2723                 case CHIP_ID_EM2860:
2724                         em28xx_info("chip ID is em2860\n");
2725                         break;
2726                 case CHIP_ID_EM2870:
2727                         em28xx_info("chip ID is em2870\n");
2728                         dev->wait_after_write = 0;
2729                         break;
2730                 case CHIP_ID_EM2874:
2731                         em28xx_info("chip ID is em2874\n");
2732                         dev->reg_gpio_num = EM2874_R80_GPIO;
2733                         dev->wait_after_write = 0;
2734                         break;
2735                 case CHIP_ID_EM2883:
2736                         em28xx_info("chip ID is em2882/em2883\n");
2737                         dev->wait_after_write = 0;
2738                         break;
2739                 default:
2740                         em28xx_info("em28xx chip ID = %d\n", dev->chip_id);
2741                 }
2742         }
2743
2744         /* Prepopulate cached GPO register content */
2745         retval = em28xx_read_reg(dev, dev->reg_gpo_num);
2746         if (retval >= 0)
2747                 dev->reg_gpo = retval;
2748
2749         em28xx_pre_card_setup(dev);
2750
2751         if (!dev->board.is_em2800) {
2752                 /* Sets I2C speed to 100 KHz */
2753                 retval = em28xx_write_reg(dev, EM28XX_R06_I2C_CLK, 0x40);
2754                 if (retval < 0) {
2755                         em28xx_errdev("%s: em28xx_write_regs_req failed!"
2756                                       " retval [%d]\n",
2757                                       __func__, retval);
2758                         return retval;
2759                 }
2760         }
2761
2762         retval = v4l2_device_register(&interface->dev, &dev->v4l2_dev);
2763         if (retval < 0) {
2764                 em28xx_errdev("Call to v4l2_device_register() failed!\n");
2765                 return retval;
2766         }
2767
2768         /* register i2c bus */
2769         errCode = em28xx_i2c_register(dev);
2770         if (errCode < 0) {
2771                 v4l2_device_unregister(&dev->v4l2_dev);
2772                 em28xx_errdev("%s: em28xx_i2c_register - errCode [%d]!\n",
2773                         __func__, errCode);
2774                 return errCode;
2775         }
2776
2777         /*
2778          * Default format, used for tvp5150 or saa711x output formats
2779          */
2780         dev->vinmode = 0x10;
2781         dev->vinctl  = EM28XX_VINCTRL_INTERLACED |
2782                        EM28XX_VINCTRL_CCIR656_ENABLE;
2783
2784         /* Do board specific init and eeprom reading */
2785         em28xx_card_setup(dev);
2786
2787         /* Configure audio */
2788         errCode = em28xx_audio_setup(dev);
2789         if (errCode < 0) {
2790                 v4l2_device_unregister(&dev->v4l2_dev);
2791                 em28xx_errdev("%s: Error while setting audio - errCode [%d]!\n",
2792                         __func__, errCode);
2793         }
2794
2795         /* wake i2c devices */
2796         em28xx_wake_i2c(dev);
2797
2798         /* init video dma queues */
2799         INIT_LIST_HEAD(&dev->vidq.active);
2800         INIT_LIST_HEAD(&dev->vidq.queued);
2801         INIT_LIST_HEAD(&dev->vbiq.active);
2802         INIT_LIST_HEAD(&dev->vbiq.queued);
2803
2804         if (dev->board.has_msp34xx) {
2805                 /* Send a reset to other chips via gpio */
2806                 errCode = em28xx_write_reg(dev, EM28XX_R08_GPIO, 0xf7);
2807                 if (errCode < 0) {
2808                         em28xx_errdev("%s: em28xx_write_regs_req - "
2809                                       "msp34xx(1) failed! errCode [%d]\n",
2810                                       __func__, errCode);
2811                         return errCode;
2812                 }
2813                 msleep(3);
2814
2815                 errCode = em28xx_write_reg(dev, EM28XX_R08_GPIO, 0xff);
2816                 if (errCode < 0) {
2817                         em28xx_errdev("%s: em28xx_write_regs_req - "
2818                                       "msp34xx(2) failed! errCode [%d]\n",
2819                                       __func__, errCode);
2820                         return errCode;
2821                 }
2822                 msleep(3);
2823         }
2824
2825         em28xx_add_into_devlist(dev);
2826
2827         retval = em28xx_register_analog_devices(dev);
2828         if (retval < 0) {
2829                 em28xx_release_resources(dev);
2830                 goto fail_reg_devices;
2831         }
2832
2833         em28xx_init_extension(dev);
2834
2835         /* Save some power by putting tuner to sleep */
2836         v4l2_device_call_all(&dev->v4l2_dev, 0, core, s_power, 0);
2837
2838         return 0;
2839
2840 fail_reg_devices:
2841         return retval;
2842 }
2843
2844 /*
2845  * em28xx_usb_probe()
2846  * checks for supported devices
2847  */
2848 static int em28xx_usb_probe(struct usb_interface *interface,
2849                             const struct usb_device_id *id)
2850 {
2851         const struct usb_endpoint_descriptor *endpoint;
2852         struct usb_device *udev;
2853         struct usb_interface *uif;
2854         struct em28xx *dev = NULL;
2855         int retval;
2856         int i, nr, ifnum, isoc_pipe;
2857         char *speed;
2858         char descr[255] = "";
2859
2860         udev = usb_get_dev(interface_to_usbdev(interface));
2861         ifnum = interface->altsetting[0].desc.bInterfaceNumber;
2862
2863         /* Check to see next free device and mark as used */
2864         nr = find_first_zero_bit(&em28xx_devused, EM28XX_MAXBOARDS);
2865         em28xx_devused |= 1<<nr;
2866
2867         /* Don't register audio interfaces */
2868         if (interface->altsetting[0].desc.bInterfaceClass == USB_CLASS_AUDIO) {
2869                 em28xx_err(DRIVER_NAME " audio device (%04x:%04x): "
2870                         "interface %i, class %i\n",
2871                         le16_to_cpu(udev->descriptor.idVendor),
2872                         le16_to_cpu(udev->descriptor.idProduct),
2873                         ifnum,
2874                         interface->altsetting[0].desc.bInterfaceClass);
2875
2876                 em28xx_devused &= ~(1<<nr);
2877                 retval = -ENODEV;
2878                 goto err;
2879         }
2880
2881         endpoint = &interface->cur_altsetting->endpoint[0].desc;
2882
2883         /* check if the device has the iso in endpoint at the correct place */
2884         if (usb_endpoint_xfer_isoc(endpoint)
2885             &&
2886             (interface->altsetting[1].endpoint[0].desc.wMaxPacketSize == 940)) {
2887                 /* It's a newer em2874/em2875 device */
2888                 isoc_pipe = 0;
2889         } else {
2890                 int check_interface = 1;
2891                 isoc_pipe = 1;
2892                 endpoint = &interface->cur_altsetting->endpoint[1].desc;
2893                 if (!usb_endpoint_xfer_isoc(endpoint))
2894                         check_interface = 0;
2895
2896                 if (usb_endpoint_dir_out(endpoint))
2897                         check_interface = 0;
2898
2899                 if (!check_interface) {
2900                         em28xx_err(DRIVER_NAME " video device (%04x:%04x): "
2901                                 "interface %i, class %i found.\n",
2902                                 le16_to_cpu(udev->descriptor.idVendor),
2903                                 le16_to_cpu(udev->descriptor.idProduct),
2904                                 ifnum,
2905                                 interface->altsetting[0].desc.bInterfaceClass);
2906
2907                         em28xx_err(DRIVER_NAME " This is an anciliary "
2908                                 "interface not used by the driver\n");
2909
2910                         em28xx_devused &= ~(1<<nr);
2911                         retval = -ENODEV;
2912                         goto err;
2913                 }
2914         }
2915
2916         switch (udev->speed) {
2917         case USB_SPEED_LOW:
2918                 speed = "1.5";
2919                 break;
2920         case USB_SPEED_UNKNOWN:
2921         case USB_SPEED_FULL:
2922                 speed = "12";
2923                 break;
2924         case USB_SPEED_HIGH:
2925                 speed = "480";
2926                 break;
2927         default:
2928                 speed = "unknown";
2929         }
2930
2931         if (udev->manufacturer)
2932                 strlcpy(descr, udev->manufacturer, sizeof(descr));
2933
2934         if (udev->product) {
2935                 if (*descr)
2936                         strlcat(descr, " ", sizeof(descr));
2937                 strlcat(descr, udev->product, sizeof(descr));
2938         }
2939         if (*descr)
2940                 strlcat(descr, " ", sizeof(descr));
2941
2942         printk(DRIVER_NAME ": New device %s@ %s Mbps "
2943                 "(%04x:%04x, interface %d, class %d)\n",
2944                 descr,
2945                 speed,
2946                 le16_to_cpu(udev->descriptor.idVendor),
2947                 le16_to_cpu(udev->descriptor.idProduct),
2948                 ifnum,
2949                 interface->altsetting->desc.bInterfaceNumber);
2950
2951         /*
2952          * Make sure we have 480 Mbps of bandwidth, otherwise things like
2953          * video stream wouldn't likely work, since 12 Mbps is generally
2954          * not enough even for most Digital TV streams.
2955          */
2956         if (udev->speed != USB_SPEED_HIGH && disable_usb_speed_check == 0) {
2957                 printk(DRIVER_NAME ": Device initialization failed.\n");
2958                 printk(DRIVER_NAME ": Device must be connected to a high-speed"
2959                        " USB 2.0 port.\n");
2960                 em28xx_devused &= ~(1<<nr);
2961                 retval = -ENODEV;
2962                 goto err;
2963         }
2964
2965         if (nr >= EM28XX_MAXBOARDS) {
2966                 printk(DRIVER_NAME ": Supports only %i em28xx boards.\n",
2967                                 EM28XX_MAXBOARDS);
2968                 em28xx_devused &= ~(1<<nr);
2969                 retval = -ENOMEM;
2970                 goto err;
2971         }
2972
2973         /* allocate memory for our device state and initialize it */
2974         dev = kzalloc(sizeof(*dev), GFP_KERNEL);
2975         if (dev == NULL) {
2976                 em28xx_err(DRIVER_NAME ": out of memory!\n");
2977                 em28xx_devused &= ~(1<<nr);
2978                 retval = -ENOMEM;
2979                 goto err;
2980         }
2981
2982         snprintf(dev->name, 29, "em28xx #%d", nr);
2983         dev->devno = nr;
2984         dev->model = id->driver_info;
2985         dev->alt   = -1;
2986
2987         /* Checks if audio is provided by some interface */
2988         for (i = 0; i < udev->config->desc.bNumInterfaces; i++) {
2989                 uif = udev->config->interface[i];
2990                 if (uif->altsetting[0].desc.bInterfaceClass == USB_CLASS_AUDIO) {
2991                         dev->has_audio_class = 1;
2992                         break;
2993                 }
2994         }
2995
2996         /* compute alternate max packet sizes */
2997         uif = udev->actconfig->interface[0];
2998
2999         dev->num_alt = uif->num_altsetting;
3000         dev->alt_max_pkt_size = kmalloc(32 * dev->num_alt, GFP_KERNEL);
3001
3002         if (dev->alt_max_pkt_size == NULL) {
3003                 em28xx_errdev("out of memory!\n");
3004                 em28xx_devused &= ~(1<<nr);
3005                 kfree(dev);
3006                 retval = -ENOMEM;
3007                 goto err;
3008         }
3009
3010         for (i = 0; i < dev->num_alt ; i++) {
3011                 u16 tmp = le16_to_cpu(uif->altsetting[i].endpoint[isoc_pipe].desc.wMaxPacketSize);
3012                 dev->alt_max_pkt_size[i] =
3013                     (tmp & 0x07ff) * (((tmp & 0x1800) >> 11) + 1);
3014         }
3015
3016         if ((card[nr] >= 0) && (card[nr] < em28xx_bcount))
3017                 dev->model = card[nr];
3018
3019         /* allocate device struct */
3020         mutex_init(&dev->lock);
3021         mutex_lock(&dev->lock);
3022         retval = em28xx_init_dev(&dev, udev, interface, nr);
3023         if (retval) {
3024                 em28xx_devused &= ~(1<<dev->devno);
3025                 mutex_unlock(&dev->lock);
3026                 kfree(dev);
3027                 goto err;
3028         }
3029
3030         /* save our data pointer in this interface device */
3031         usb_set_intfdata(interface, dev);
3032
3033         request_modules(dev);
3034
3035         /* Should be the last thing to do, to avoid newer udev's to
3036            open the device before fully initializing it
3037          */
3038         mutex_unlock(&dev->lock);
3039
3040         return 0;
3041
3042 err:
3043         return retval;
3044 }
3045
3046 /*
3047  * em28xx_usb_disconnect()
3048  * called when the device gets diconencted
3049  * video device will be unregistered on v4l2_close in case it is still open
3050  */
3051 static void em28xx_usb_disconnect(struct usb_interface *interface)
3052 {
3053         struct em28xx *dev;
3054
3055         dev = usb_get_intfdata(interface);
3056         usb_set_intfdata(interface, NULL);
3057
3058         if (!dev)
3059                 return;
3060
3061         em28xx_info("disconnecting %s\n", dev->vdev->name);
3062
3063         /* wait until all current v4l2 io is finished then deallocate
3064            resources */
3065         mutex_lock(&dev->lock);
3066
3067         wake_up_interruptible_all(&dev->open);
3068
3069         v4l2_device_disconnect(&dev->v4l2_dev);
3070
3071         if (dev->users) {
3072                 em28xx_warn
3073                     ("device %s is open! Deregistration and memory "
3074                      "deallocation are deferred on close.\n",
3075                      video_device_node_name(dev->vdev));
3076
3077                 dev->state |= DEV_MISCONFIGURED;
3078                 em28xx_uninit_isoc(dev);
3079                 dev->state |= DEV_DISCONNECTED;
3080                 wake_up_interruptible(&dev->wait_frame);
3081                 wake_up_interruptible(&dev->wait_stream);
3082         } else {
3083                 dev->state |= DEV_DISCONNECTED;
3084                 em28xx_release_resources(dev);
3085         }
3086
3087         em28xx_close_extension(dev);
3088
3089         mutex_unlock(&dev->lock);
3090
3091         if (!dev->users) {
3092                 kfree(dev->alt_max_pkt_size);
3093                 kfree(dev);
3094         }
3095 }
3096
3097 static struct usb_driver em28xx_usb_driver = {
3098         .name = "em28xx",
3099         .probe = em28xx_usb_probe,
3100         .disconnect = em28xx_usb_disconnect,
3101         .id_table = em28xx_id_table,
3102 };
3103
3104 static int __init em28xx_module_init(void)
3105 {
3106         int result;
3107
3108         /* register this driver with the USB subsystem */
3109         result = usb_register(&em28xx_usb_driver);
3110         if (result)
3111                 em28xx_err(DRIVER_NAME
3112                            " usb_register failed. Error number %d.\n", result);
3113
3114         printk(KERN_INFO DRIVER_NAME " driver loaded\n");
3115
3116         return result;
3117 }
3118
3119 static void __exit em28xx_module_exit(void)
3120 {
3121         /* deregister this driver with the USB subsystem */
3122         usb_deregister(&em28xx_usb_driver);
3123 }
3124
3125 module_init(em28xx_module_init);
3126 module_exit(em28xx_module_exit);