]> git.openfabrics.org - ~shefty/rdma-dev.git/blob - drivers/media/video/em28xx/em28xx-cards.c
ed281f5659459c20bc571fbfb3ed61e3348590bc
[~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 /* FIXME: Should be replaced by a proper mt9m001 driver */
1734 static int em28xx_initialize_mt9m001(struct em28xx *dev)
1735 {
1736         int i;
1737         unsigned char regs[][3] = {
1738                 { 0x0d, 0x00, 0x01, },
1739                 { 0x0d, 0x00, 0x00, },
1740                 { 0x04, 0x05, 0x00, },  /* hres = 1280 */
1741                 { 0x03, 0x04, 0x00, },  /* vres = 1024 */
1742                 { 0x20, 0x11, 0x00, },
1743                 { 0x06, 0x00, 0x10, },
1744                 { 0x2b, 0x00, 0x24, },
1745                 { 0x2e, 0x00, 0x24, },
1746                 { 0x35, 0x00, 0x24, },
1747                 { 0x2d, 0x00, 0x20, },
1748                 { 0x2c, 0x00, 0x20, },
1749                 { 0x09, 0x0a, 0xd4, },
1750                 { 0x35, 0x00, 0x57, },
1751         };
1752
1753         for (i = 0; i < ARRAY_SIZE(regs); i++)
1754                 i2c_master_send(&dev->i2c_client, &regs[i][0], 3);
1755
1756         return 0;
1757 }
1758
1759 /* HINT method: webcam I2C chips
1760  *
1761  * This method work for webcams with Micron sensors
1762  */
1763 static int em28xx_hint_sensor(struct em28xx *dev)
1764 {
1765         int rc;
1766         char *sensor_name;
1767         unsigned char cmd;
1768         __be16 version_be;
1769         u16 version;
1770
1771         /* Micron sensor detection */
1772         dev->i2c_client.addr = 0xba >> 1;
1773         cmd = 0;
1774         i2c_master_send(&dev->i2c_client, &cmd, 1);
1775         rc = i2c_master_recv(&dev->i2c_client, (char *)&version_be, 2);
1776         if (rc != 2)
1777                 return -EINVAL;
1778
1779         version = be16_to_cpu(version_be);
1780         switch (version) {
1781         case 0x8232:            /* mt9v011 640x480 1.3 Mpix sensor */
1782         case 0x8243:            /* mt9v011 rev B 640x480 1.3 Mpix sensor */
1783                 dev->model = EM2820_BOARD_SILVERCREST_WEBCAM;
1784                 em28xx_set_model(dev);
1785
1786                 sensor_name = "mt9v011";
1787                 dev->em28xx_sensor = EM28XX_MT9V011;
1788                 dev->sensor_xres = 640;
1789                 dev->sensor_yres = 480;
1790                 /*
1791                  * FIXME: mt9v011 uses I2S speed as xtal clk - at least with
1792                  * the Silvercrest cam I have here for testing - for higher
1793                  * resolutions, a high clock cause horizontal artifacts, so we
1794                  * need to use a lower xclk frequency.
1795                  * Yet, it would be possible to adjust xclk depending on the
1796                  * desired resolution, since this affects directly the
1797                  * frame rate.
1798                  */
1799                 dev->board.xclk = EM28XX_XCLK_FREQUENCY_4_3MHZ;
1800                 dev->sensor_xtal = 4300000;
1801
1802                 /* probably means GRGB 16 bit bayer */
1803                 dev->vinmode = 0x0d;
1804                 dev->vinctl = 0x00;
1805
1806                 break;
1807         case 0x8431:
1808                 dev->model = EM2750_BOARD_UNKNOWN;
1809                 em28xx_set_model(dev);
1810
1811                 sensor_name = "mt9m001";
1812                 dev->em28xx_sensor = EM28XX_MT9M001;
1813                 em28xx_initialize_mt9m001(dev);
1814                 dev->sensor_xres = 1280;
1815                 dev->sensor_yres = 1024;
1816
1817                 /* probably means BGGR 16 bit bayer */
1818                 dev->vinmode = 0x0c;
1819                 dev->vinctl = 0x00;
1820
1821                 break;
1822         default:
1823                 printk("Unknown Micron Sensor 0x%04x\n", be16_to_cpu(version));
1824                 return -EINVAL;
1825         }
1826
1827         /* Setup webcam defaults */
1828         em28xx_pre_card_setup(dev);
1829
1830         em28xx_errdev("Sensor is %s, using model %s entry.\n",
1831                       sensor_name, em28xx_boards[dev->model].name);
1832
1833         return 0;
1834 }
1835
1836 /* Since em28xx_pre_card_setup() requires a proper dev->model,
1837  * this won't work for boards with generic PCI IDs
1838  */
1839 void em28xx_pre_card_setup(struct em28xx *dev)
1840 {
1841         /* Set the initial XCLK and I2C clock values based on the board
1842            definition */
1843         em28xx_write_reg(dev, EM28XX_R0F_XCLK, dev->board.xclk & 0x7f);
1844         em28xx_write_reg(dev, EM28XX_R06_I2C_CLK, dev->board.i2c_speed);
1845         msleep(50);
1846
1847         /* request some modules */
1848         switch (dev->model) {
1849         case EM2861_BOARD_PLEXTOR_PX_TV100U:
1850                 /* Sets the msp34xx I2S speed */
1851                 dev->i2s_speed = 2048000;
1852                 break;
1853         case EM2861_BOARD_KWORLD_PVRTV_300U:
1854         case EM2880_BOARD_KWORLD_DVB_305U:
1855                 em28xx_write_reg(dev, EM28XX_R08_GPIO, 0x6d);
1856                 msleep(10);
1857                 em28xx_write_reg(dev, EM28XX_R08_GPIO, 0x7d);
1858                 msleep(10);
1859                 break;
1860         case EM2870_BOARD_COMPRO_VIDEOMATE:
1861                 /* TODO: someone can do some cleanup here...
1862                          not everything's needed */
1863                 em28xx_write_reg(dev, EM2880_R04_GPO, 0x00);
1864                 msleep(10);
1865                 em28xx_write_reg(dev, EM2880_R04_GPO, 0x01);
1866                 msleep(10);
1867                 em28xx_write_reg(dev, EM28XX_R08_GPIO, 0xfd);
1868                 mdelay(70);
1869                 em28xx_write_reg(dev, EM28XX_R08_GPIO, 0xfc);
1870                 mdelay(70);
1871                 em28xx_write_reg(dev, EM28XX_R08_GPIO, 0xdc);
1872                 mdelay(70);
1873                 em28xx_write_reg(dev, EM28XX_R08_GPIO, 0xfc);
1874                 mdelay(70);
1875                 break;
1876         case EM2870_BOARD_TERRATEC_XS_MT2060:
1877                 /* this device needs some gpio writes to get the DVB-T
1878                    demod work */
1879                 em28xx_write_reg(dev, EM28XX_R08_GPIO, 0xfe);
1880                 mdelay(70);
1881                 em28xx_write_reg(dev, EM28XX_R08_GPIO, 0xde);
1882                 mdelay(70);
1883                 em28xx_write_reg(dev, EM28XX_R08_GPIO, 0xfe);
1884                 mdelay(70);
1885                 break;
1886         case EM2870_BOARD_PINNACLE_PCTV_DVB:
1887                 /* this device needs some gpio writes to get the
1888                    DVB-T demod work */
1889                 em28xx_write_reg(dev, EM28XX_R08_GPIO, 0xfe);
1890                 mdelay(70);
1891                 em28xx_write_reg(dev, EM28XX_R08_GPIO, 0xde);
1892                 mdelay(70);
1893                 em28xx_write_reg(dev, EM28XX_R08_GPIO, 0xfe);
1894                 mdelay(70);
1895                 break;
1896         case EM2820_BOARD_GADMEI_UTV310:
1897         case EM2820_BOARD_MSI_VOX_USB_2:
1898                 /* enables audio for that devices */
1899                 em28xx_write_reg(dev, EM28XX_R08_GPIO, 0xfd);
1900                 break;
1901
1902         case EM2882_BOARD_KWORLD_ATSC_315U:
1903                 em28xx_write_reg(dev, EM28XX_R08_GPIO, 0xff);
1904                 msleep(10);
1905                 em28xx_write_reg(dev, EM28XX_R08_GPIO, 0xfe);
1906                 msleep(10);
1907                 em28xx_write_reg(dev, EM2880_R04_GPO, 0x00);
1908                 msleep(10);
1909                 em28xx_write_reg(dev, EM2880_R04_GPO, 0x08);
1910                 msleep(10);
1911                 break;
1912
1913         case EM2860_BOARD_KAIOMY_TVNPC_U2:
1914                 em28xx_write_regs(dev, EM28XX_R0F_XCLK, "\x07", 1);
1915                 em28xx_write_regs(dev, EM28XX_R06_I2C_CLK, "\x40", 1);
1916                 em28xx_write_regs(dev, 0x0d, "\x42", 1);
1917                 em28xx_write_regs(dev, 0x08, "\xfd", 1);
1918                 msleep(10);
1919                 em28xx_write_regs(dev, 0x08, "\xff", 1);
1920                 msleep(10);
1921                 em28xx_write_regs(dev, 0x08, "\x7f", 1);
1922                 msleep(10);
1923                 em28xx_write_regs(dev, 0x08, "\x6b", 1);
1924
1925                 break;
1926         case EM2860_BOARD_EASYCAP:
1927                 em28xx_write_regs(dev, 0x08, "\xf8", 1);
1928                 break;
1929
1930         case EM2820_BOARD_IODATA_GVMVP_SZ:
1931                 em28xx_write_reg(dev, EM28XX_R08_GPIO, 0xff);
1932                 msleep(70);
1933                 em28xx_write_reg(dev, EM28XX_R08_GPIO, 0xf7);
1934                 msleep(10);
1935                 em28xx_write_reg(dev, EM28XX_R08_GPIO, 0xfe);
1936                 msleep(70);
1937                 em28xx_write_reg(dev, EM28XX_R08_GPIO, 0xfd);
1938                 msleep(70);
1939                 break;
1940         }
1941
1942         em28xx_gpio_set(dev, dev->board.tuner_gpio);
1943         em28xx_set_mode(dev, EM28XX_ANALOG_MODE);
1944
1945         /* Unlock device */
1946         em28xx_set_mode(dev, EM28XX_SUSPEND);
1947 }
1948
1949 static void em28xx_setup_xc3028(struct em28xx *dev, struct xc2028_ctrl *ctl)
1950 {
1951         memset(ctl, 0, sizeof(*ctl));
1952
1953         ctl->fname   = XC2028_DEFAULT_FIRMWARE;
1954         ctl->max_len = 64;
1955         ctl->mts = em28xx_boards[dev->model].mts_firmware;
1956
1957         switch (dev->model) {
1958         case EM2880_BOARD_EMPIRE_DUAL_TV:
1959         case EM2880_BOARD_HAUPPAUGE_WINTV_HVR_900:
1960                 ctl->demod = XC3028_FE_ZARLINK456;
1961                 break;
1962         case EM2880_BOARD_TERRATEC_HYBRID_XS:
1963         case EM2881_BOARD_PINNACLE_HYBRID_PRO:
1964                 ctl->demod = XC3028_FE_ZARLINK456;
1965                 break;
1966         case EM2880_BOARD_HAUPPAUGE_WINTV_HVR_900_R2:
1967                 /* djh - Not sure which demod we need here */
1968                 ctl->demod = XC3028_FE_DEFAULT;
1969                 break;
1970         case EM2880_BOARD_AMD_ATI_TV_WONDER_HD_600:
1971                 ctl->demod = XC3028_FE_DEFAULT;
1972                 ctl->fname = XC3028L_DEFAULT_FIRMWARE;
1973                 break;
1974         case EM2883_BOARD_HAUPPAUGE_WINTV_HVR_850:
1975         case EM2883_BOARD_HAUPPAUGE_WINTV_HVR_950:
1976         case EM2880_BOARD_PINNACLE_PCTV_HD_PRO:
1977                 /* FIXME: Better to specify the needed IF */
1978                 ctl->demod = XC3028_FE_DEFAULT;
1979                 break;
1980         case EM2883_BOARD_KWORLD_HYBRID_330U:
1981                 ctl->demod = XC3028_FE_CHINA;
1982                 ctl->fname = XC2028_DEFAULT_FIRMWARE;
1983                 break;
1984         case EM2882_BOARD_EVGA_INDTUBE:
1985                 ctl->demod = XC3028_FE_CHINA;
1986                 ctl->fname = XC3028L_DEFAULT_FIRMWARE;
1987                 break;
1988         default:
1989                 ctl->demod = XC3028_FE_OREN538;
1990         }
1991 }
1992
1993 static void em28xx_tuner_setup(struct em28xx *dev)
1994 {
1995         struct tuner_setup           tun_setup;
1996         struct v4l2_frequency        f;
1997
1998         if (dev->tuner_type == TUNER_ABSENT)
1999                 return;
2000
2001         memset(&tun_setup, 0, sizeof(tun_setup));
2002
2003         tun_setup.mode_mask = T_ANALOG_TV | T_RADIO;
2004         tun_setup.tuner_callback = em28xx_tuner_callback;
2005
2006         if (dev->board.radio.type) {
2007                 tun_setup.type = dev->board.radio.type;
2008                 tun_setup.addr = dev->board.radio_addr;
2009
2010                 v4l2_device_call_all(&dev->v4l2_dev, 0, tuner, s_type_addr, &tun_setup);
2011         }
2012
2013         if ((dev->tuner_type != TUNER_ABSENT) && (dev->tuner_type)) {
2014                 tun_setup.type   = dev->tuner_type;
2015                 tun_setup.addr   = dev->tuner_addr;
2016
2017                 v4l2_device_call_all(&dev->v4l2_dev, 0, tuner, s_type_addr, &tun_setup);
2018         }
2019
2020         if (dev->tda9887_conf) {
2021                 struct v4l2_priv_tun_config tda9887_cfg;
2022
2023                 tda9887_cfg.tuner = TUNER_TDA9887;
2024                 tda9887_cfg.priv = &dev->tda9887_conf;
2025
2026                 v4l2_device_call_all(&dev->v4l2_dev, 0, tuner, s_config, &tda9887_cfg);
2027         }
2028
2029         if (dev->tuner_type == TUNER_XC2028) {
2030                 struct v4l2_priv_tun_config  xc2028_cfg;
2031                 struct xc2028_ctrl           ctl;
2032
2033                 memset(&xc2028_cfg, 0, sizeof(xc2028_cfg));
2034                 memset(&ctl, 0, sizeof(ctl));
2035
2036                 em28xx_setup_xc3028(dev, &ctl);
2037
2038                 xc2028_cfg.tuner = TUNER_XC2028;
2039                 xc2028_cfg.priv  = &ctl;
2040
2041                 v4l2_device_call_all(&dev->v4l2_dev, 0, tuner, s_config, &xc2028_cfg);
2042         }
2043
2044         /* configure tuner */
2045         f.tuner = 0;
2046         f.type = V4L2_TUNER_ANALOG_TV;
2047         f.frequency = 9076;     /* just a magic number */
2048         dev->ctl_freq = f.frequency;
2049         v4l2_device_call_all(&dev->v4l2_dev, 0, tuner, s_frequency, &f);
2050 }
2051
2052 static int em28xx_hint_board(struct em28xx *dev)
2053 {
2054         int i;
2055
2056         /* HINT method: EEPROM
2057          *
2058          * This method works only for boards with eeprom.
2059          * Uses a hash of all eeprom bytes. The hash should be
2060          * unique for a vendor/tuner pair.
2061          * There are a high chance that tuners for different
2062          * video standards produce different hashes.
2063          */
2064         for (i = 0; i < ARRAY_SIZE(em28xx_eeprom_hash); i++) {
2065                 if (dev->hash == em28xx_eeprom_hash[i].hash) {
2066                         dev->model = em28xx_eeprom_hash[i].model;
2067                         dev->tuner_type = em28xx_eeprom_hash[i].tuner;
2068
2069                         em28xx_errdev("Your board has no unique USB ID.\n");
2070                         em28xx_errdev("A hint were successfully done, "
2071                                       "based on eeprom hash.\n");
2072                         em28xx_errdev("This method is not 100%% failproof.\n");
2073                         em28xx_errdev("If the board were missdetected, "
2074                                       "please email this log to:\n");
2075                         em28xx_errdev("\tV4L Mailing List "
2076                                       " <linux-media@vger.kernel.org>\n");
2077                         em28xx_errdev("Board detected as %s\n",
2078                                       em28xx_boards[dev->model].name);
2079
2080                         return 0;
2081                 }
2082         }
2083
2084         /* HINT method: I2C attached devices
2085          *
2086          * This method works for all boards.
2087          * Uses a hash of i2c scanned devices.
2088          * Devices with the same i2c attached chips will
2089          * be considered equal.
2090          * This method is less precise than the eeprom one.
2091          */
2092
2093         /* user did not request i2c scanning => do it now */
2094         if (!dev->i2c_hash)
2095                 em28xx_do_i2c_scan(dev);
2096
2097         for (i = 0; i < ARRAY_SIZE(em28xx_i2c_hash); i++) {
2098                 if (dev->i2c_hash == em28xx_i2c_hash[i].hash) {
2099                         dev->model = em28xx_i2c_hash[i].model;
2100                         dev->tuner_type = em28xx_i2c_hash[i].tuner;
2101                         em28xx_errdev("Your board has no unique USB ID.\n");
2102                         em28xx_errdev("A hint were successfully done, "
2103                                       "based on i2c devicelist hash.\n");
2104                         em28xx_errdev("This method is not 100%% failproof.\n");
2105                         em28xx_errdev("If the board were missdetected, "
2106                                       "please email this log to:\n");
2107                         em28xx_errdev("\tV4L Mailing List "
2108                                       " <linux-media@vger.kernel.org>\n");
2109                         em28xx_errdev("Board detected as %s\n",
2110                                       em28xx_boards[dev->model].name);
2111
2112                         return 0;
2113                 }
2114         }
2115
2116         em28xx_errdev("Your board has no unique USB ID and thus need a "
2117                       "hint to be detected.\n");
2118         em28xx_errdev("You may try to use card=<n> insmod option to "
2119                       "workaround that.\n");
2120         em28xx_errdev("Please send an email with this log to:\n");
2121         em28xx_errdev("\tV4L Mailing List <linux-media@vger.kernel.org>\n");
2122         em28xx_errdev("Board eeprom hash is 0x%08lx\n", dev->hash);
2123         em28xx_errdev("Board i2c devicelist hash is 0x%08lx\n", dev->i2c_hash);
2124
2125         em28xx_errdev("Here is a list of valid choices for the card=<n>"
2126                       " insmod option:\n");
2127         for (i = 0; i < em28xx_bcount; i++) {
2128                 em28xx_errdev("    card=%d -> %s\n",
2129                                 i, em28xx_boards[i].name);
2130         }
2131         return -1;
2132 }
2133
2134 /* ----------------------------------------------------------------------- */
2135 void em28xx_register_i2c_ir(struct em28xx *dev)
2136 {
2137         struct i2c_board_info info;
2138         struct IR_i2c_init_data init_data;
2139         const unsigned short addr_list[] = {
2140                  0x30, 0x47, I2C_CLIENT_END
2141         };
2142
2143         if (disable_ir)
2144                 return;
2145
2146         memset(&info, 0, sizeof(struct i2c_board_info));
2147         memset(&init_data, 0, sizeof(struct IR_i2c_init_data));
2148         strlcpy(info.type, "ir_video", I2C_NAME_SIZE);
2149
2150         /* detect & configure */
2151         switch (dev->model) {
2152         case (EM2800_BOARD_UNKNOWN):
2153                 break;
2154         case (EM2820_BOARD_UNKNOWN):
2155                 break;
2156         case (EM2800_BOARD_TERRATEC_CINERGY_200):
2157         case (EM2820_BOARD_TERRATEC_CINERGY_250):
2158                 init_data.ir_codes = ir_codes_em_terratec;
2159                 init_data.get_key = em28xx_get_key_terratec;
2160                 init_data.name = "i2c IR (EM28XX Terratec)";
2161                 break;
2162         case (EM2820_BOARD_PINNACLE_USB_2):
2163                 init_data.ir_codes = ir_codes_pinnacle_grey;
2164                 init_data.get_key = em28xx_get_key_pinnacle_usb_grey;
2165                 init_data.name = "i2c IR (EM28XX Pinnacle PCTV)";
2166                 break;
2167         case (EM2820_BOARD_HAUPPAUGE_WINTV_USB_2):
2168                 init_data.ir_codes = ir_codes_hauppauge_new;
2169                 init_data.get_key = em28xx_get_key_em_haup;
2170                 init_data.name = "i2c IR (EM2840 Hauppauge)";
2171                 break;
2172         case (EM2820_BOARD_MSI_VOX_USB_2):
2173                 break;
2174         case (EM2800_BOARD_LEADTEK_WINFAST_USBII):
2175                 break;
2176         case (EM2800_BOARD_KWORLD_USB2800):
2177                 break;
2178         case (EM2800_BOARD_GRABBEEX_USB2800):
2179                 break;
2180         }
2181
2182         if (init_data.name)
2183                 info.platform_data = &init_data;
2184         i2c_new_probed_device(&dev->i2c_adap, &info, addr_list);
2185 }
2186
2187 void em28xx_card_setup(struct em28xx *dev)
2188 {
2189         /*
2190          * If the device can be a webcam, seek for a sensor.
2191          * If sensor is not found, then it isn't a webcam.
2192          */
2193         if (dev->board.is_webcam) {
2194                 if (em28xx_hint_sensor(dev) < 0)
2195                         dev->board.is_webcam = 0;
2196                 else
2197                         dev->progressive = 1;
2198         } else
2199                 em28xx_set_model(dev);
2200
2201         em28xx_info("Identified as %s (card=%d)\n",
2202                     dev->board.name, dev->model);
2203
2204         dev->tuner_type = em28xx_boards[dev->model].tuner_type;
2205         if (em28xx_boards[dev->model].tuner_addr)
2206                 dev->tuner_addr = em28xx_boards[dev->model].tuner_addr;
2207
2208         if (em28xx_boards[dev->model].tda9887_conf)
2209                 dev->tda9887_conf = em28xx_boards[dev->model].tda9887_conf;
2210
2211         /* request some modules */
2212         switch (dev->model) {
2213         case EM2820_BOARD_HAUPPAUGE_WINTV_USB_2:
2214         case EM2880_BOARD_HAUPPAUGE_WINTV_HVR_900:
2215         case EM2880_BOARD_HAUPPAUGE_WINTV_HVR_900_R2:
2216         case EM2883_BOARD_HAUPPAUGE_WINTV_HVR_850:
2217         case EM2883_BOARD_HAUPPAUGE_WINTV_HVR_950:
2218         {
2219                 struct tveeprom tv;
2220 #ifdef CONFIG_MODULES
2221                 request_module("tveeprom");
2222 #endif
2223                 /* Call first TVeeprom */
2224
2225                 dev->i2c_client.addr = 0xa0 >> 1;
2226                 tveeprom_hauppauge_analog(&dev->i2c_client, &tv, dev->eedata);
2227
2228                 dev->tuner_type = tv.tuner_type;
2229
2230                 if (tv.audio_processor == V4L2_IDENT_MSPX4XX) {
2231                         dev->i2s_speed = 2048000;
2232                         dev->board.has_msp34xx = 1;
2233                 }
2234 #ifdef CONFIG_MODULES
2235                 if (tv.has_ir)
2236                         request_module("ir-kbd-i2c");
2237 #endif
2238                 break;
2239         }
2240         case EM2882_BOARD_KWORLD_ATSC_315U:
2241                 em28xx_write_reg(dev, 0x0d, 0x42);
2242                 msleep(10);
2243                 em28xx_write_reg(dev, EM28XX_R08_GPIO, 0xfd);
2244                 msleep(10);
2245                 break;
2246         case EM2820_BOARD_KWORLD_PVRTV2800RF:
2247                 /* GPIO enables sound on KWORLD PVR TV 2800RF */
2248                 em28xx_write_reg(dev, EM28XX_R08_GPIO, 0xf9);
2249                 break;
2250         case EM2820_BOARD_UNKNOWN:
2251         case EM2800_BOARD_UNKNOWN:
2252                 /*
2253                  * The K-WORLD DVB-T 310U is detected as an MSI Digivox AD.
2254                  *
2255                  * This occurs because they share identical USB vendor and
2256                  * product IDs.
2257                  *
2258                  * What we do here is look up the EEPROM hash of the K-WORLD
2259                  * and if it is found then we decide that we do not have
2260                  * a DIGIVOX and reset the device to the K-WORLD instead.
2261                  *
2262                  * This solution is only valid if they do not share eeprom
2263                  * hash identities which has not been determined as yet.
2264                  */
2265         case EM2880_BOARD_MSI_DIGIVOX_AD:
2266                 if (!em28xx_hint_board(dev))
2267                         em28xx_set_model(dev);
2268
2269                 /* In cases where we had to use a board hint, the call to
2270                    em28xx_set_mode() in em28xx_pre_card_setup() was a no-op,
2271                    so make the call now so the analog GPIOs are set properly
2272                    before probing the i2c bus. */
2273                 em28xx_gpio_set(dev, dev->board.tuner_gpio);
2274                 em28xx_set_mode(dev, EM28XX_ANALOG_MODE);
2275                 break;
2276         }
2277
2278         if (dev->board.has_snapshot_button)
2279                 em28xx_register_snapshot_button(dev);
2280
2281         if (dev->board.valid == EM28XX_BOARD_NOT_VALIDATED) {
2282                 em28xx_errdev("\n\n");
2283                 em28xx_errdev("The support for this board weren't "
2284                               "valid yet.\n");
2285                 em28xx_errdev("Please send a report of having this working\n");
2286                 em28xx_errdev("not to V4L mailing list (and/or to other "
2287                                 "addresses)\n\n");
2288         }
2289
2290         /* Allow override tuner type by a module parameter */
2291         if (tuner >= 0)
2292                 dev->tuner_type = tuner;
2293
2294         /* request some modules */
2295         if (dev->board.has_msp34xx)
2296                 v4l2_i2c_new_probed_subdev(&dev->v4l2_dev, &dev->i2c_adap,
2297                         "msp3400", "msp3400", msp3400_addrs);
2298
2299         if (dev->board.decoder == EM28XX_SAA711X)
2300                 v4l2_i2c_new_probed_subdev(&dev->v4l2_dev, &dev->i2c_adap,
2301                         "saa7115", "saa7115_auto", saa711x_addrs);
2302
2303         if (dev->board.decoder == EM28XX_TVP5150)
2304                 v4l2_i2c_new_probed_subdev(&dev->v4l2_dev, &dev->i2c_adap,
2305                         "tvp5150", "tvp5150", tvp5150_addrs);
2306
2307         if (dev->em28xx_sensor == EM28XX_MT9V011) {
2308                 struct v4l2_subdev *sd;
2309
2310                 sd = v4l2_i2c_new_probed_subdev(&dev->v4l2_dev,
2311                          &dev->i2c_adap, "mt9v011", "mt9v011", mt9v011_addrs);
2312                 v4l2_subdev_call(sd, core, s_config, 0, &dev->sensor_xtal);
2313         }
2314
2315
2316         if (dev->board.adecoder == EM28XX_TVAUDIO)
2317                 v4l2_i2c_new_subdev(&dev->v4l2_dev, &dev->i2c_adap,
2318                         "tvaudio", "tvaudio", dev->board.tvaudio_addr);
2319
2320         if (dev->board.tuner_type != TUNER_ABSENT) {
2321                 int has_demod = (dev->tda9887_conf & TDA9887_PRESENT);
2322
2323                 if (dev->board.radio.type)
2324                         v4l2_i2c_new_subdev(&dev->v4l2_dev, &dev->i2c_adap,
2325                                 "tuner", "tuner", dev->board.radio_addr);
2326
2327                 if (has_demod)
2328                         v4l2_i2c_new_probed_subdev(&dev->v4l2_dev,
2329                                 &dev->i2c_adap, "tuner", "tuner",
2330                                 v4l2_i2c_tuner_addrs(ADDRS_DEMOD));
2331                 if (dev->tuner_addr == 0) {
2332                         enum v4l2_i2c_tuner_type type =
2333                                 has_demod ? ADDRS_TV_WITH_DEMOD : ADDRS_TV;
2334                         struct v4l2_subdev *sd;
2335
2336                         sd = v4l2_i2c_new_probed_subdev(&dev->v4l2_dev,
2337                                 &dev->i2c_adap, "tuner", "tuner",
2338                                 v4l2_i2c_tuner_addrs(type));
2339
2340                         if (sd)
2341                                 dev->tuner_addr = v4l2_i2c_subdev_addr(sd);
2342                 } else {
2343                         v4l2_i2c_new_subdev(&dev->v4l2_dev, &dev->i2c_adap,
2344                                 "tuner", "tuner", dev->tuner_addr);
2345                 }
2346         }
2347
2348         em28xx_tuner_setup(dev);
2349         em28xx_ir_init(dev);
2350 }
2351
2352
2353 #if defined(CONFIG_MODULES) && defined(MODULE)
2354 static void request_module_async(struct work_struct *work)
2355 {
2356         struct em28xx *dev = container_of(work,
2357                              struct em28xx, request_module_wk);
2358
2359         if (dev->has_audio_class)
2360                 request_module("snd-usb-audio");
2361         else if (dev->has_alsa_audio)
2362                 request_module("em28xx-alsa");
2363
2364         if (dev->board.has_dvb)
2365                 request_module("em28xx-dvb");
2366 }
2367
2368 static void request_modules(struct em28xx *dev)
2369 {
2370         INIT_WORK(&dev->request_module_wk, request_module_async);
2371         schedule_work(&dev->request_module_wk);
2372 }
2373 #else
2374 #define request_modules(dev)
2375 #endif /* CONFIG_MODULES */
2376
2377 /*
2378  * em28xx_realease_resources()
2379  * unregisters the v4l2,i2c and usb devices
2380  * called when the device gets disconected or at module unload
2381 */
2382 void em28xx_release_resources(struct em28xx *dev)
2383 {
2384         if (dev->sbutton_input_dev)
2385                 em28xx_deregister_snapshot_button(dev);
2386
2387         if (dev->ir)
2388                 em28xx_ir_fini(dev);
2389
2390         /*FIXME: I2C IR should be disconnected */
2391
2392         em28xx_release_analog_resources(dev);
2393
2394         em28xx_remove_from_devlist(dev);
2395
2396         em28xx_i2c_unregister(dev);
2397
2398         v4l2_device_unregister(&dev->v4l2_dev);
2399
2400         usb_put_dev(dev->udev);
2401
2402         /* Mark device as unused */
2403         em28xx_devused &= ~(1 << dev->devno);
2404 };
2405
2406 /*
2407  * em28xx_init_dev()
2408  * allocates and inits the device structs, registers i2c bus and v4l device
2409  */
2410 static int em28xx_init_dev(struct em28xx **devhandle, struct usb_device *udev,
2411                            struct usb_interface *interface,
2412                            int minor)
2413 {
2414         struct em28xx *dev = *devhandle;
2415         int retval;
2416         int errCode;
2417
2418         dev->udev = udev;
2419         mutex_init(&dev->ctrl_urb_lock);
2420         spin_lock_init(&dev->slock);
2421         init_waitqueue_head(&dev->open);
2422         init_waitqueue_head(&dev->wait_frame);
2423         init_waitqueue_head(&dev->wait_stream);
2424
2425         dev->em28xx_write_regs = em28xx_write_regs;
2426         dev->em28xx_read_reg = em28xx_read_reg;
2427         dev->em28xx_read_reg_req_len = em28xx_read_reg_req_len;
2428         dev->em28xx_write_regs_req = em28xx_write_regs_req;
2429         dev->em28xx_read_reg_req = em28xx_read_reg_req;
2430         dev->board.is_em2800 = em28xx_boards[dev->model].is_em2800;
2431
2432         em28xx_set_model(dev);
2433
2434         /* Set the default GPO/GPIO for legacy devices */
2435         dev->reg_gpo_num = EM2880_R04_GPO;
2436         dev->reg_gpio_num = EM28XX_R08_GPIO;
2437
2438         dev->wait_after_write = 5;
2439
2440         /* Based on the Chip ID, set the device configuration */
2441         retval = em28xx_read_reg(dev, EM28XX_R0A_CHIPID);
2442         if (retval > 0) {
2443                 dev->chip_id = retval;
2444
2445                 switch (dev->chip_id) {
2446                 case CHIP_ID_EM2710:
2447                         em28xx_info("chip ID is em2710\n");
2448                         break;
2449                 case CHIP_ID_EM2750:
2450                         em28xx_info("chip ID is em2750\n");
2451                         break;
2452                 case CHIP_ID_EM2820:
2453                         em28xx_info("chip ID is em2820 (or em2710)\n");
2454                         break;
2455                 case CHIP_ID_EM2840:
2456                         em28xx_info("chip ID is em2840\n");
2457                         break;
2458                 case CHIP_ID_EM2860:
2459                         em28xx_info("chip ID is em2860\n");
2460                         break;
2461                 case CHIP_ID_EM2870:
2462                         em28xx_info("chip ID is em2870\n");
2463                         dev->wait_after_write = 0;
2464                         break;
2465                 case CHIP_ID_EM2874:
2466                         em28xx_info("chip ID is em2874\n");
2467                         dev->reg_gpio_num = EM2874_R80_GPIO;
2468                         dev->wait_after_write = 0;
2469                         break;
2470                 case CHIP_ID_EM2883:
2471                         em28xx_info("chip ID is em2882/em2883\n");
2472                         dev->wait_after_write = 0;
2473                         break;
2474                 default:
2475                         em28xx_info("em28xx chip ID = %d\n", dev->chip_id);
2476                 }
2477         }
2478
2479         /* Prepopulate cached GPO register content */
2480         retval = em28xx_read_reg(dev, dev->reg_gpo_num);
2481         if (retval >= 0)
2482                 dev->reg_gpo = retval;
2483
2484         em28xx_pre_card_setup(dev);
2485
2486         if (!dev->board.is_em2800) {
2487                 /* Sets I2C speed to 100 KHz */
2488                 retval = em28xx_write_reg(dev, EM28XX_R06_I2C_CLK, 0x40);
2489                 if (retval < 0) {
2490                         em28xx_errdev("%s: em28xx_write_regs_req failed!"
2491                                       " retval [%d]\n",
2492                                       __func__, retval);
2493                         return retval;
2494                 }
2495         }
2496
2497         retval = v4l2_device_register(&interface->dev, &dev->v4l2_dev);
2498         if (retval < 0) {
2499                 em28xx_errdev("Call to v4l2_device_register() failed!\n");
2500                 return retval;
2501         }
2502
2503         /* register i2c bus */
2504         errCode = em28xx_i2c_register(dev);
2505         if (errCode < 0) {
2506                 v4l2_device_unregister(&dev->v4l2_dev);
2507                 em28xx_errdev("%s: em28xx_i2c_register - errCode [%d]!\n",
2508                         __func__, errCode);
2509                 return errCode;
2510         }
2511
2512         /*
2513          * Default format, used for tvp5150 or saa711x output formats
2514          */
2515         dev->vinmode = 0x10;
2516         dev->vinctl  = 0x11;
2517
2518         /* Do board specific init and eeprom reading */
2519         em28xx_card_setup(dev);
2520
2521         /* Configure audio */
2522         errCode = em28xx_audio_setup(dev);
2523         if (errCode < 0) {
2524                 v4l2_device_unregister(&dev->v4l2_dev);
2525                 em28xx_errdev("%s: Error while setting audio - errCode [%d]!\n",
2526                         __func__, errCode);
2527         }
2528
2529         /* wake i2c devices */
2530         em28xx_wake_i2c(dev);
2531
2532         /* init video dma queues */
2533         INIT_LIST_HEAD(&dev->vidq.active);
2534         INIT_LIST_HEAD(&dev->vidq.queued);
2535
2536
2537         if (dev->board.has_msp34xx) {
2538                 /* Send a reset to other chips via gpio */
2539                 errCode = em28xx_write_reg(dev, EM28XX_R08_GPIO, 0xf7);
2540                 if (errCode < 0) {
2541                         em28xx_errdev("%s: em28xx_write_regs_req - "
2542                                       "msp34xx(1) failed! errCode [%d]\n",
2543                                       __func__, errCode);
2544                         return errCode;
2545                 }
2546                 msleep(3);
2547
2548                 errCode = em28xx_write_reg(dev, EM28XX_R08_GPIO, 0xff);
2549                 if (errCode < 0) {
2550                         em28xx_errdev("%s: em28xx_write_regs_req - "
2551                                       "msp34xx(2) failed! errCode [%d]\n",
2552                                       __func__, errCode);
2553                         return errCode;
2554                 }
2555                 msleep(3);
2556         }
2557
2558         em28xx_add_into_devlist(dev);
2559
2560         retval = em28xx_register_analog_devices(dev);
2561         if (retval < 0) {
2562                 em28xx_release_resources(dev);
2563                 goto fail_reg_devices;
2564         }
2565
2566         em28xx_init_extension(dev);
2567
2568         /* Save some power by putting tuner to sleep */
2569         v4l2_device_call_all(&dev->v4l2_dev, 0, tuner, s_standby);
2570
2571         return 0;
2572
2573 fail_reg_devices:
2574         return retval;
2575 }
2576
2577 /*
2578  * em28xx_usb_probe()
2579  * checks for supported devices
2580  */
2581 static int em28xx_usb_probe(struct usb_interface *interface,
2582                             const struct usb_device_id *id)
2583 {
2584         const struct usb_endpoint_descriptor *endpoint;
2585         struct usb_device *udev;
2586         struct usb_interface *uif;
2587         struct em28xx *dev = NULL;
2588         int retval;
2589         int i, nr, ifnum, isoc_pipe;
2590         char *speed;
2591         char descr[255] = "";
2592
2593         udev = usb_get_dev(interface_to_usbdev(interface));
2594         ifnum = interface->altsetting[0].desc.bInterfaceNumber;
2595
2596         /* Check to see next free device and mark as used */
2597         nr = find_first_zero_bit(&em28xx_devused, EM28XX_MAXBOARDS);
2598         em28xx_devused |= 1<<nr;
2599
2600         /* Don't register audio interfaces */
2601         if (interface->altsetting[0].desc.bInterfaceClass == USB_CLASS_AUDIO) {
2602                 em28xx_err(DRIVER_NAME " audio device (%04x:%04x): "
2603                         "interface %i, class %i\n",
2604                         le16_to_cpu(udev->descriptor.idVendor),
2605                         le16_to_cpu(udev->descriptor.idProduct),
2606                         ifnum,
2607                         interface->altsetting[0].desc.bInterfaceClass);
2608
2609                 em28xx_devused &= ~(1<<nr);
2610                 retval = -ENODEV;
2611                 goto err;
2612         }
2613
2614         endpoint = &interface->cur_altsetting->endpoint[0].desc;
2615
2616         /* check if the device has the iso in endpoint at the correct place */
2617         if (usb_endpoint_xfer_isoc(endpoint)
2618             &&
2619             (interface->altsetting[1].endpoint[0].desc.wMaxPacketSize == 940)) {
2620                 /* It's a newer em2874/em2875 device */
2621                 isoc_pipe = 0;
2622         } else {
2623                 int check_interface = 1;
2624                 isoc_pipe = 1;
2625                 endpoint = &interface->cur_altsetting->endpoint[1].desc;
2626                 if (!usb_endpoint_xfer_isoc(endpoint))
2627                         check_interface = 0;
2628
2629                 if (usb_endpoint_dir_out(endpoint))
2630                         check_interface = 0;
2631
2632                 if (!check_interface) {
2633                         em28xx_err(DRIVER_NAME " video device (%04x:%04x): "
2634                                 "interface %i, class %i found.\n",
2635                                 le16_to_cpu(udev->descriptor.idVendor),
2636                                 le16_to_cpu(udev->descriptor.idProduct),
2637                                 ifnum,
2638                                 interface->altsetting[0].desc.bInterfaceClass);
2639
2640                         em28xx_err(DRIVER_NAME " This is an anciliary "
2641                                 "interface not used by the driver\n");
2642
2643                         em28xx_devused &= ~(1<<nr);
2644                         retval = -ENODEV;
2645                         goto err;
2646                 }
2647         }
2648
2649         switch (udev->speed) {
2650         case USB_SPEED_LOW:
2651                 speed = "1.5";
2652                 break;
2653         case USB_SPEED_UNKNOWN:
2654         case USB_SPEED_FULL:
2655                 speed = "12";
2656                 break;
2657         case USB_SPEED_HIGH:
2658                 speed = "480";
2659                 break;
2660         default:
2661                 speed = "unknown";
2662         }
2663
2664         if (udev->manufacturer)
2665                 strlcpy(descr, udev->manufacturer, sizeof(descr));
2666
2667         if (udev->product) {
2668                 if (*descr)
2669                         strlcat(descr, " ", sizeof(descr));
2670                 strlcat(descr, udev->product, sizeof(descr));
2671         }
2672         if (*descr)
2673                 strlcat(descr, " ", sizeof(descr));
2674
2675         printk(DRIVER_NAME ": New device %s@ %s Mbps "
2676                 "(%04x:%04x, interface %d, class %d)\n",
2677                 descr,
2678                 speed,
2679                 le16_to_cpu(udev->descriptor.idVendor),
2680                 le16_to_cpu(udev->descriptor.idProduct),
2681                 ifnum,
2682                 interface->altsetting->desc.bInterfaceNumber);
2683
2684         /*
2685          * Make sure we have 480 Mbps of bandwidth, otherwise things like
2686          * video stream wouldn't likely work, since 12 Mbps is generally
2687          * not enough even for most Digital TV streams.
2688          */
2689         if (udev->speed != USB_SPEED_HIGH && disable_usb_speed_check == 0) {
2690                 printk(DRIVER_NAME ": Device initialization failed.\n");
2691                 printk(DRIVER_NAME ": Device must be connected to a high-speed"
2692                        " USB 2.0 port.\n");
2693                 em28xx_devused &= ~(1<<nr);
2694                 retval = -ENODEV;
2695                 goto err;
2696         }
2697
2698         if (nr >= EM28XX_MAXBOARDS) {
2699                 printk(DRIVER_NAME ": Supports only %i em28xx boards.\n",
2700                                 EM28XX_MAXBOARDS);
2701                 em28xx_devused &= ~(1<<nr);
2702                 retval = -ENOMEM;
2703                 goto err;
2704         }
2705
2706         /* allocate memory for our device state and initialize it */
2707         dev = kzalloc(sizeof(*dev), GFP_KERNEL);
2708         if (dev == NULL) {
2709                 em28xx_err(DRIVER_NAME ": out of memory!\n");
2710                 em28xx_devused &= ~(1<<nr);
2711                 retval = -ENOMEM;
2712                 goto err;
2713         }
2714
2715         snprintf(dev->name, 29, "em28xx #%d", nr);
2716         dev->devno = nr;
2717         dev->model = id->driver_info;
2718         dev->alt   = -1;
2719
2720         /* Checks if audio is provided by some interface */
2721         for (i = 0; i < udev->config->desc.bNumInterfaces; i++) {
2722                 uif = udev->config->interface[i];
2723                 if (uif->altsetting[0].desc.bInterfaceClass == USB_CLASS_AUDIO) {
2724                         dev->has_audio_class = 1;
2725                         break;
2726                 }
2727         }
2728
2729         /* compute alternate max packet sizes */
2730         uif = udev->actconfig->interface[0];
2731
2732         dev->num_alt = uif->num_altsetting;
2733         dev->alt_max_pkt_size = kmalloc(32 * dev->num_alt, GFP_KERNEL);
2734
2735         if (dev->alt_max_pkt_size == NULL) {
2736                 em28xx_errdev("out of memory!\n");
2737                 em28xx_devused &= ~(1<<nr);
2738                 kfree(dev);
2739                 retval = -ENOMEM;
2740                 goto err;
2741         }
2742
2743         for (i = 0; i < dev->num_alt ; i++) {
2744                 u16 tmp = le16_to_cpu(uif->altsetting[i].endpoint[isoc_pipe].desc.wMaxPacketSize);
2745                 dev->alt_max_pkt_size[i] =
2746                     (tmp & 0x07ff) * (((tmp & 0x1800) >> 11) + 1);
2747         }
2748
2749         if ((card[nr] >= 0) && (card[nr] < em28xx_bcount))
2750                 dev->model = card[nr];
2751
2752         /* allocate device struct */
2753         mutex_init(&dev->lock);
2754         mutex_lock(&dev->lock);
2755         retval = em28xx_init_dev(&dev, udev, interface, nr);
2756         if (retval) {
2757                 em28xx_devused &= ~(1<<dev->devno);
2758                 mutex_unlock(&dev->lock);
2759                 kfree(dev);
2760                 goto err;
2761         }
2762
2763         /* save our data pointer in this interface device */
2764         usb_set_intfdata(interface, dev);
2765
2766         request_modules(dev);
2767
2768         /* Should be the last thing to do, to avoid newer udev's to
2769            open the device before fully initializing it
2770          */
2771         mutex_unlock(&dev->lock);
2772
2773         return 0;
2774
2775 err:
2776         return retval;
2777 }
2778
2779 /*
2780  * em28xx_usb_disconnect()
2781  * called when the device gets diconencted
2782  * video device will be unregistered on v4l2_close in case it is still open
2783  */
2784 static void em28xx_usb_disconnect(struct usb_interface *interface)
2785 {
2786         struct em28xx *dev;
2787
2788         dev = usb_get_intfdata(interface);
2789         usb_set_intfdata(interface, NULL);
2790
2791         if (!dev)
2792                 return;
2793
2794         em28xx_info("disconnecting %s\n", dev->vdev->name);
2795
2796         /* wait until all current v4l2 io is finished then deallocate
2797            resources */
2798         mutex_lock(&dev->lock);
2799
2800         wake_up_interruptible_all(&dev->open);
2801
2802         v4l2_device_disconnect(&dev->v4l2_dev);
2803
2804         if (dev->users) {
2805                 em28xx_warn
2806                     ("device /dev/video%d is open! Deregistration and memory "
2807                      "deallocation are deferred on close.\n",
2808                                 dev->vdev->num);
2809
2810                 dev->state |= DEV_MISCONFIGURED;
2811                 em28xx_uninit_isoc(dev);
2812                 dev->state |= DEV_DISCONNECTED;
2813                 wake_up_interruptible(&dev->wait_frame);
2814                 wake_up_interruptible(&dev->wait_stream);
2815         } else {
2816                 dev->state |= DEV_DISCONNECTED;
2817                 em28xx_release_resources(dev);
2818         }
2819
2820         em28xx_close_extension(dev);
2821
2822         mutex_unlock(&dev->lock);
2823
2824         if (!dev->users) {
2825                 kfree(dev->alt_max_pkt_size);
2826                 kfree(dev);
2827         }
2828 }
2829
2830 static struct usb_driver em28xx_usb_driver = {
2831         .name = "em28xx",
2832         .probe = em28xx_usb_probe,
2833         .disconnect = em28xx_usb_disconnect,
2834         .id_table = em28xx_id_table,
2835 };
2836
2837 static int __init em28xx_module_init(void)
2838 {
2839         int result;
2840
2841         /* register this driver with the USB subsystem */
2842         result = usb_register(&em28xx_usb_driver);
2843         if (result)
2844                 em28xx_err(DRIVER_NAME
2845                            " usb_register failed. Error number %d.\n", result);
2846
2847         printk(KERN_INFO DRIVER_NAME " driver loaded\n");
2848
2849         return result;
2850 }
2851
2852 static void __exit em28xx_module_exit(void)
2853 {
2854         /* deregister this driver with the USB subsystem */
2855         usb_deregister(&em28xx_usb_driver);
2856 }
2857
2858 module_init(em28xx_module_init);
2859 module_exit(em28xx_module_exit);