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