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