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