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