em28xx-cards.c 18.6 KB
Newer Older
1
/*
2
   em28xx-cards.c - driver for Empia EM2800/EM2820/2840 USB video capture devices
3

4 5
   Copyright (C) 2005 Ludovico Cavedon <cavedon@sssup.it>
		      Markus Rechberger <mrechberger@gmail.com>
6
		      Mauro Carvalho Chehab <mchehab@infradead.org>
7
		      Sascha Sommer <saschasommer@freenet.de>
8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29

   This program is free software; you can redistribute it and/or modify
   it under the terms of the GNU General Public License as published by
   the Free Software Foundation; either version 2 of the License, or
   (at your option) any later version.

   This program is distributed in the hope that it will be useful,
   but WITHOUT ANY WARRANTY; without even the implied warranty of
   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
   GNU General Public License for more details.

   You should have received a copy of the GNU General Public License
   along with this program; if not, write to the Free Software
   Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
 */

#include <linux/init.h>
#include <linux/module.h>
#include <linux/delay.h>
#include <linux/i2c.h>
#include <linux/usb.h>
#include <media/tuner.h>
30
#include <media/msp3400.h>
31 32
#include <media/saa7115.h>
#include <media/tvp5150.h>
33
#include <media/tveeprom.h>
34
#include <media/audiochip.h>
35
#include <media/v4l2-common.h>
36

37
#include "em28xx.h"
38
#include "tuner-xc2028.h"
39

40 41 42 43 44 45 46 47 48 49
static int tuner = -1;
module_param(tuner, int, 0444);
MODULE_PARM_DESC(tuner, "tuner type");

struct em28xx_hash_table {
	unsigned long hash;
	unsigned int  model;
	unsigned int  tuner;
};

50
struct em28xx_board em28xx_boards[] = {
51 52 53 54 55 56
	[EM2800_BOARD_UNKNOWN] = {
		.name         = "Unknown EM2800 video grabber",
		.is_em2800    = 1,
		.vchannels    = 2,
		.tda9887_conf = TDA9887_PRESENT,
		.has_tuner    = 1,
57
		.decoder      = EM28XX_SAA7113,
58
		.input           = {{
59
			.type     = EM28XX_VMUX_COMPOSITE1,
60
			.vmux     = SAA7115_COMPOSITE0,
61 62
			.amux     = 1,
		},{
63
			.type     = EM28XX_VMUX_SVIDEO,
64
			.vmux     = SAA7115_SVIDEO3,
65 66 67 68
			.amux     = 1,
		}},
	},
	[EM2820_BOARD_UNKNOWN] = {
69
		.name         = "Unknown EM2750/28xx video grabber",
70 71
		.is_em2800    = 0,
	},
72
	[EM2820_BOARD_KWORLD_PVRTV2800RF] = {
73
		.name         = "Kworld PVR TV 2800 RF",
74 75 76 77 78 79 80
		.is_em2800    = 0,
		.vchannels    = 2,
		.tda9887_conf = TDA9887_PRESENT,
		.has_tuner    = 1,
		.decoder      = EM28XX_SAA7113,
		.input           = {{
			.type     = EM28XX_VMUX_COMPOSITE1,
81
			.vmux     = SAA7115_COMPOSITE0,
82 83 84
			.amux     = 1,
		},{
			.type     = EM28XX_VMUX_SVIDEO,
85
			.vmux     = SAA7115_SVIDEO3,
86 87 88
			.amux     = 1,
		}},
	},
89 90 91 92 93 94
	[EM2820_BOARD_TERRATEC_CINERGY_250] = {
		.name         = "Terratec Cinergy 250 USB",
		.vchannels    = 3,
		.tuner_type   = TUNER_LG_PAL_NEW_TAPC,
		.tda9887_conf = TDA9887_PRESENT,
		.has_tuner    = 1,
95
		.decoder      = EM28XX_SAA7113,
96
		.input          = {{
97
			.type     = EM28XX_VMUX_TELEVISION,
98
			.vmux     = SAA7115_COMPOSITE2,
99
			.amux     = 1,
100
		},{
101
			.type     = EM28XX_VMUX_COMPOSITE1,
102
			.vmux     = SAA7115_COMPOSITE0,
103 104
			.amux     = 1,
		},{
105
			.type     = EM28XX_VMUX_SVIDEO,
106
			.vmux     = SAA7115_SVIDEO3,
107 108 109 110 111 112 113 114 115
			.amux     = 1,
		}},
	},
	[EM2820_BOARD_PINNACLE_USB_2] = {
		.name         = "Pinnacle PCTV USB 2",
		.vchannels    = 3,
		.tuner_type   = TUNER_LG_PAL_NEW_TAPC,
		.tda9887_conf = TDA9887_PRESENT,
		.has_tuner    = 1,
116
		.decoder      = EM28XX_SAA7113,
117
		.input          = {{
118
			.type     = EM28XX_VMUX_TELEVISION,
119
			.vmux     = SAA7115_COMPOSITE2,
120 121
			.amux     = 0,
		},{
122
			.type     = EM28XX_VMUX_COMPOSITE1,
123
			.vmux     = SAA7115_COMPOSITE0,
124 125
			.amux     = 1,
		},{
126
			.type     = EM28XX_VMUX_SVIDEO,
127
			.vmux     = SAA7115_SVIDEO3,
128 129 130 131 132 133 134 135 136
			.amux     = 1,
		}},
	},
	[EM2820_BOARD_HAUPPAUGE_WINTV_USB_2] = {
		.name         = "Hauppauge WinTV USB 2",
		.vchannels    = 3,
		.tuner_type   = TUNER_PHILIPS_FM1236_MK3,
		.tda9887_conf = TDA9887_PRESENT|TDA9887_PORT1_ACTIVE|TDA9887_PORT2_ACTIVE,
		.has_tuner    = 1,
137
		.decoder      = EM28XX_TVP5150,
138 139 140
		.has_msp34xx  = 1,
		/*FIXME: S-Video not tested */
		.input          = {{
141
			.type     = EM28XX_VMUX_TELEVISION,
142
			.vmux     = TVP5150_COMPOSITE0,
143
			.amux     = MSP_INPUT_DEFAULT,
144
		},{
145
			.type     = EM28XX_VMUX_SVIDEO,
146
			.vmux     = TVP5150_SVIDEO,
147 148
			.amux     = MSP_INPUT(MSP_IN_SCART1, MSP_IN_TUNER1,
					MSP_DSP_IN_SCART, MSP_DSP_IN_SCART),
149 150
		}},
	},
151
	[EM2880_BOARD_HAUPPAUGE_WINTV_HVR_900] = {
152 153 154 155 156
		.name         = "Hauppauge WinTV HVR 900",
		.vchannels    = 3,
		.tda9887_conf = TDA9887_PRESENT,
		.tuner_type   = TUNER_XC2028,
		.has_tuner    = 1,
157
		.mts_firmware = 1,
158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174
		.decoder      = EM28XX_TVP5150,
		.input          = {{
			.type     = EM28XX_VMUX_TELEVISION,
			.vmux     = TVP5150_COMPOSITE0,
			.amux     = 0,
		},{
			.type     = EM28XX_VMUX_COMPOSITE1,
			.vmux     = TVP5150_COMPOSITE1,
			.amux     = 1,
		},{
			.type     = EM28XX_VMUX_SVIDEO,
			.vmux     = TVP5150_SVIDEO,
			.amux     = 1,
		}},
	},
	[EM2880_BOARD_HAUPPAUGE_WINTV_HVR_950] = {
		.name         = "Hauppauge WinTV HVR 950",
175 176 177 178 179 180 181 182 183
		.vchannels    = 3,
		.tda9887_conf = TDA9887_PRESENT,
		.tuner_type   = TUNER_XC2028,
		.has_tuner    = 1,
		.decoder      = EM28XX_TVP5150,
		.input          = {{
			.type     = EM28XX_VMUX_TELEVISION,
			.vmux     = TVP5150_COMPOSITE0,
			.amux     = 0,
184 185 186 187
		},{
			.type     = EM28XX_VMUX_COMPOSITE1,
			.vmux     = TVP5150_COMPOSITE1,
			.amux     = 1,
188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237
		},{
			.type     = EM28XX_VMUX_SVIDEO,
			.vmux     = TVP5150_SVIDEO,
			.amux     = 1,
		}},
	},
	[EM2880_BOARD_TERRATEC_HYBRID_XS] = {
		.name         = "Terratec Hybrid XS",
		.vchannels    = 3,
		.tda9887_conf = TDA9887_PRESENT,
		.has_tuner    = 1,
		.tuner_type   = TUNER_XC2028,
		.decoder      = EM28XX_TVP5150,
		.input          = {{
			.type     = EM28XX_VMUX_TELEVISION,
			.vmux     = TVP5150_COMPOSITE0,
			.amux     = 0,
		},{
			.type     = EM28XX_VMUX_COMPOSITE1,
			.vmux     = TVP5150_COMPOSITE1,
			.amux     = 1,
		},{
			.type     = EM28XX_VMUX_SVIDEO,
			.vmux     = TVP5150_SVIDEO,
			.amux     = 1,
		}},
	},
	/* maybe there's a reason behind it why Terratec sells the Hybrid XS as Prodigy XS with a
	 * different PID, let's keep it separated for now maybe we'll need it lateron */
	[EM2880_BOARD_TERRATEC_PRODIGY_XS] = {
		.name         = "Terratec Prodigy XS",
		.vchannels    = 3,
		.tda9887_conf = TDA9887_PRESENT,
		.has_tuner    = 1,
		.tuner_type   = TUNER_XC2028,
		.decoder      = EM28XX_TVP5150,
		.input          = {{
			.type     = EM28XX_VMUX_TELEVISION,
			.vmux     = TVP5150_COMPOSITE0,
			.amux     = 0,
		},{
			.type     = EM28XX_VMUX_COMPOSITE1,
			.vmux     = TVP5150_COMPOSITE1,
			.amux     = 1,
		},{
			.type     = EM28XX_VMUX_SVIDEO,
			.vmux     = TVP5150_SVIDEO,
			.amux     = 1,
		}},
	},
238 239 240
	[EM2820_BOARD_MSI_VOX_USB_2] = {
		.name		= "MSI VOX USB 2.0",
		.vchannels	= 3,
241
		.tuner_type	= TUNER_LG_PAL_NEW_TAPC,
242 243
		.tda9887_conf	= TDA9887_PRESENT|TDA9887_PORT1_ACTIVE|TDA9887_PORT2_ACTIVE,
		.has_tuner	= 1,
244
		.decoder        = EM28XX_SAA7114,
245
		.input          = {{
246
			.type     = EM28XX_VMUX_TELEVISION,
247
			.vmux     = SAA7115_COMPOSITE4,
248 249
			.amux     = 0,
		},{
250
			.type     = EM28XX_VMUX_COMPOSITE1,
251
			.vmux     = SAA7115_COMPOSITE0,
252 253
			.amux     = 1,
		},{
254
			.type     = EM28XX_VMUX_SVIDEO,
255
			.vmux     = SAA7115_SVIDEO3,
256 257 258
			.amux     = 1,
		}},
	},
259 260 261 262 263 264 265
	[EM2800_BOARD_TERRATEC_CINERGY_200] = {
		.name         = "Terratec Cinergy 200 USB",
		.is_em2800    = 1,
		.vchannels    = 3,
		.tuner_type   = TUNER_LG_PAL_NEW_TAPC,
		.tda9887_conf = TDA9887_PRESENT,
		.has_tuner    = 1,
266
		.decoder      = EM28XX_SAA7113,
267
		.input          = {{
268
			.type     = EM28XX_VMUX_TELEVISION,
269
			.vmux     = SAA7115_COMPOSITE2,
270 271
			.amux     = 0,
		},{
272
			.type     = EM28XX_VMUX_COMPOSITE1,
273
			.vmux     = SAA7115_COMPOSITE0,
274 275
			.amux     = 1,
		},{
276
			.type     = EM28XX_VMUX_SVIDEO,
277
			.vmux     = SAA7115_SVIDEO3,
278 279 280 281 282 283 284 285 286 287
			.amux     = 1,
		}},
	},
	[EM2800_BOARD_LEADTEK_WINFAST_USBII] = {
		.name         = "Leadtek Winfast USB II",
		.is_em2800    = 1,
		.vchannels    = 3,
		.tuner_type   = TUNER_LG_PAL_NEW_TAPC,
		.tda9887_conf = TDA9887_PRESENT,
		.has_tuner    = 1,
288
		.decoder      = EM28XX_SAA7113,
289
		.input          = {{
290
			.type     = EM28XX_VMUX_TELEVISION,
291
			.vmux     = SAA7115_COMPOSITE2,
292 293
			.amux     = 0,
		},{
294
			.type     = EM28XX_VMUX_COMPOSITE1,
295
			.vmux     = SAA7115_COMPOSITE0,
296 297
			.amux     = 1,
		},{
298
			.type     = EM28XX_VMUX_SVIDEO,
299
			.vmux     = SAA7115_SVIDEO3,
300 301 302 303 304 305 306 307 308 309
			.amux     = 1,
		}},
	},
	[EM2800_BOARD_KWORLD_USB2800] = {
		.name         = "Kworld USB2800",
		.is_em2800    = 1,
		.vchannels    = 3,
		.tuner_type   = TUNER_PHILIPS_ATSC,
		.tda9887_conf = TDA9887_PRESENT,
		.has_tuner    = 1,
310
		.decoder      = EM28XX_SAA7113,
311
		.input          = {{
312
			.type     = EM28XX_VMUX_TELEVISION,
313
			.vmux     = SAA7115_COMPOSITE2,
314 315
			.amux     = 0,
		},{
316
			.type     = EM28XX_VMUX_COMPOSITE1,
317
			.vmux     = SAA7115_COMPOSITE0,
318 319
			.amux     = 1,
		},{
320
			.type     = EM28XX_VMUX_SVIDEO,
321
			.vmux     = SAA7115_SVIDEO3,
322 323 324
			.amux     = 1,
		}},
	},
325 326 327 328
	[EM2820_BOARD_PINNACLE_DVC_90] = {
		.name         = "Pinnacle Dazzle DVC 90",
		.vchannels    = 3,
		.has_tuner    = 0,
329
		.decoder      = EM28XX_SAA7113,
330
		.input          = {{
331
			.type     = EM28XX_VMUX_COMPOSITE1,
332
			.vmux     = SAA7115_COMPOSITE0,
333 334
			.amux     = 1,
		},{
335
			.type     = EM28XX_VMUX_SVIDEO,
336
			.vmux     = SAA7115_SVIDEO3,
337 338 339
			.amux     = 1,
		}},
	},
340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361
	[EM2800_BOARD_VGEAR_POCKETTV] = {
		.name         = "V-Gear PocketTV",
		.is_em2800    = 1,
		.vchannels    = 3,
		.tuner_type   = TUNER_LG_PAL_NEW_TAPC,
		.tda9887_conf = TDA9887_PRESENT,
		.has_tuner    = 1,
		.decoder      = EM28XX_SAA7113,
		.input          = {{
			.type     = EM28XX_VMUX_TELEVISION,
			.vmux     = SAA7115_COMPOSITE2,
			.amux     = 0,
		},{
			.type     = EM28XX_VMUX_COMPOSITE1,
			.vmux     = SAA7115_COMPOSITE0,
			.amux     = 1,
		},{
			.type     = EM28XX_VMUX_SVIDEO,
			.vmux     = SAA7115_SVIDEO3,
			.amux     = 1,
		}},
	},
362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381
	[EM2820_BOARD_PROLINK_PLAYTV_USB2] = {
		.name         = "Pixelview Prolink PlayTV USB 2.0",
		.vchannels    = 3,
		.tda9887_conf = TDA9887_PRESENT,
		.has_tuner    = 1,
		.decoder      = EM28XX_SAA7113,
		.input          = {{
			.type     = EM28XX_VMUX_TELEVISION,
			.vmux     = SAA7115_COMPOSITE2,
			.amux     = 1,
		},{
			.type     = EM28XX_VMUX_COMPOSITE1,
			.vmux     = SAA7115_COMPOSITE0,
			.amux     = 1,
		},{
			.type     = EM28XX_VMUX_SVIDEO,
			.vmux     = SAA7115_SVIDEO3,
			.amux     = 1,
		}},
	},
382
};
383
const unsigned int em28xx_bcount = ARRAY_SIZE(em28xx_boards);
384 385

/* table of devices that work with this driver */
386
struct usb_device_id em28xx_id_table [] = {
387
	{ USB_DEVICE(0xeb1a, 0x2750), .driver_info = EM2820_BOARD_UNKNOWN },
388
	{ USB_DEVICE(0xeb1a, 0x2800), .driver_info = EM2800_BOARD_UNKNOWN },
389 390 391 392 393 394 395
	{ USB_DEVICE(0xeb1a, 0x2820), .driver_info = EM2820_BOARD_UNKNOWN },
	{ USB_DEVICE(0xeb1a, 0x2821), .driver_info = EM2820_BOARD_UNKNOWN },
	{ USB_DEVICE(0xeb1a, 0x2860), .driver_info = EM2820_BOARD_UNKNOWN },
	{ USB_DEVICE(0xeb1a, 0x2861), .driver_info = EM2820_BOARD_UNKNOWN },
	{ USB_DEVICE(0xeb1a, 0x2870), .driver_info = EM2820_BOARD_UNKNOWN },
	{ USB_DEVICE(0xeb1a, 0x2881), .driver_info = EM2820_BOARD_UNKNOWN },
	{ USB_DEVICE(0xeb1a, 0x2883), .driver_info = EM2820_BOARD_UNKNOWN },
396 397 398
	{ USB_DEVICE(0x0ccd, 0x0036), .driver_info = EM2820_BOARD_TERRATEC_CINERGY_250 },
	{ USB_DEVICE(0x2304, 0x0208), .driver_info = EM2820_BOARD_PINNACLE_USB_2 },
	{ USB_DEVICE(0x2040, 0x4200), .driver_info = EM2820_BOARD_HAUPPAUGE_WINTV_USB_2 },
399
	{ USB_DEVICE(0x2304, 0x0207), .driver_info = EM2820_BOARD_PINNACLE_DVC_90 },
400
	{ USB_DEVICE(0x2040, 0x6500), .driver_info = EM2880_BOARD_HAUPPAUGE_WINTV_HVR_900 },
401
	{ USB_DEVICE(0x2040, 0x6513), .driver_info = EM2880_BOARD_HAUPPAUGE_WINTV_HVR_950 },
402 403
	{ USB_DEVICE(0x0ccd, 0x0042), .driver_info = EM2880_BOARD_TERRATEC_HYBRID_XS },
	{ USB_DEVICE(0x0ccd, 0x0047), .driver_info = EM2880_BOARD_TERRATEC_PRODIGY_XS },
404 405
	{ },
};
406 407
MODULE_DEVICE_TABLE (usb, em28xx_id_table);

408 409
/* EEPROM hash table for devices with generic USB IDs */
static struct em28xx_hash_table em28xx_eeprom_hash [] = {
410 411
	/* P/N: SA 60002070465 Tuner: TVF7533-MF */
	{ 0x6ce05a8f, EM2820_BOARD_PROLINK_PLAYTV_USB2, TUNER_YMEC_TVF_5533MF },
412
};
413

414
/* I2C devicelist hash table for devices with generic USB IDs */
415 416 417 418 419
static struct em28xx_hash_table em28xx_i2c_hash[] = {
	{ 0xb06a32c3, EM2800_BOARD_TERRATEC_CINERGY_200, TUNER_LG_PAL_NEW_TAPC },
	{ 0xf51200e3, EM2800_BOARD_VGEAR_POCKETTV, TUNER_LG_PAL_NEW_TAPC },
};

420 421 422
/* Since em28xx_pre_card_setup() requires a proper dev->model,
 * this won't work for boards with generic PCI IDs
 */
423 424 425 426
void em28xx_pre_card_setup(struct em28xx *dev)
{
	/* request some modules */
	switch(dev->model){
427 428
	case EM2880_BOARD_TERRATEC_PRODIGY_XS:
	case EM2880_BOARD_HAUPPAUGE_WINTV_HVR_900:
429
	case EM2880_BOARD_HAUPPAUGE_WINTV_HVR_950:
430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452
	case EM2880_BOARD_TERRATEC_HYBRID_XS:
		/* reset through GPIO? */
		em28xx_write_regs_req(dev, 0x00, 0x08, "\x7d", 1);
		break;
	}
}

static int em28xx_tuner_callback(void *ptr, int command, int arg)
{
	int rc = 0;
	struct em28xx *dev = ptr;

	if (dev->tuner_type != TUNER_XC2028)
		return 0;

	switch (command) {
	case XC2028_TUNER_RESET:
		/* FIXME: This is device-dependent */
		dev->em28xx_write_regs_req(dev, 0x00, 0x48, "\x00", 1);
		dev->em28xx_write_regs_req(dev, 0x00, 0x12, "\x67", 1);

		msleep(140);
		break;
453
	}
454
	return rc;
455 456
}

457 458 459 460
static void em28xx_config_tuner (struct em28xx *dev)
{
	struct v4l2_priv_tun_config  xc2028_cfg;
	struct xc2028_ctrl           ctl;
461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478
	struct tuner_setup           tun_setup;
	struct v4l2_frequency        f;

	if (!dev->has_tuner)
		return;

	tun_setup.mode_mask = T_ANALOG_TV | T_RADIO;
	tun_setup.type = dev->tuner_type;
	tun_setup.addr = dev->tuner_addr;
	tun_setup.tuner_callback = em28xx_tuner_callback;

	em28xx_i2c_call_clients(dev, TUNER_SET_TYPE_ADDR, &tun_setup);

	if (dev->tuner_type == TUNER_XC2028) {
		memset (&ctl, 0, sizeof(ctl));

		ctl.fname   = XC2028_DEFAULT_FIRMWARE;
		ctl.max_len = 64;
479
		ctl.mts = em28xx_boards[dev->model].mts_firmware;
480 481 482

		xc2028_cfg.tuner = TUNER_XC2028;
		xc2028_cfg.priv  = &ctl;
483

484 485 486 487 488 489 490 491 492 493 494 495 496 497
		em28xx_i2c_call_clients(dev, TUNER_SET_CONFIG, &xc2028_cfg);
	}

	/* configure tuner */
	f.tuner = 0;
	f.type = V4L2_TUNER_ANALOG_TV;
	f.frequency = 9076;     /* just a magic number */
	dev->ctl_freq = f.frequency;
	em28xx_i2c_call_clients(dev, VIDIOC_S_FREQUENCY, &f);
}

static int em28xx_hint_board(struct em28xx *dev)
{
	int i;
498

499 500 501 502 503 504 505 506 507 508 509 510
	/* HINT method: EEPROM
	 *
	 * This method works only for boards with eeprom.
	 * Uses a hash of all eeprom bytes. The hash should be
	 * unique for a vendor/tuner pair.
	 * There are a high chance that tuners for different
	 * video standards produce different hashes.
	 */
	for (i = 0; i < ARRAY_SIZE(em28xx_eeprom_hash); i++) {
		if (dev->hash == em28xx_eeprom_hash[i].hash) {
			dev->model = em28xx_eeprom_hash[i].model;
			dev->tuner_type = em28xx_eeprom_hash[i].tuner;
511

512 513 514 515 516 517 518 519 520 521
			em28xx_errdev("Your board has no unique USB ID.\n");
			em28xx_errdev("A hint were successfully done, "
				      "based on eeprom hash.\n");
			em28xx_errdev("This method is not 100%% failproof.\n");
			em28xx_errdev("If the board were missdetected, "
				      "please email this log to:\n");
			em28xx_errdev("\tV4L Mailing List "
				      " <video4linux-list@redhat.com>\n");
			em28xx_errdev("Board detected as %s\n",
				      em28xx_boards[dev->model].name);
522

523 524 525
			return 0;
		}
	}
526

527 528 529 530 531 532 533 534 535
	/* HINT method: I2C attached devices
	 *
	 * This method works for all boards.
	 * Uses a hash of i2c scanned devices.
	 * Devices with the same i2c attached chips will
	 * be considered equal.
	 * This method is less precise than the eeprom one.
	 */

536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558
	/* user did not request i2c scanning => do it now */
	if (!dev->i2c_hash)
		em28xx_do_i2c_scan(dev);

	for (i = 0; i < ARRAY_SIZE(em28xx_i2c_hash); i++) {
		if (dev->i2c_hash == em28xx_i2c_hash[i].hash) {
			dev->model = em28xx_i2c_hash[i].model;
			dev->tuner_type = em28xx_i2c_hash[i].tuner;
			em28xx_errdev("Your board has no unique USB ID.\n");
			em28xx_errdev("A hint were successfully done, "
				      "based on i2c devicelist hash.\n");
			em28xx_errdev("This method is not 100%% failproof.\n");
			em28xx_errdev("If the board were missdetected, "
				      "please email this log to:\n");
			em28xx_errdev("\tV4L Mailing List "
				      " <video4linux-list@redhat.com>\n");
			em28xx_errdev("Board detected as %s\n",
				      em28xx_boards[dev->model].name);

			return 0;
		}
	}

559 560 561 562 563 564 565
	em28xx_errdev("Your board has no unique USB ID and thus need a "
		      "hint to be detected.\n");
	em28xx_errdev("You may try to use card=<n> insmod option to "
		      "workaround that.\n");
	em28xx_errdev("Please send an email with this log to:\n");
	em28xx_errdev("\tV4L Mailing List <video4linux-list@redhat.com>\n");
	em28xx_errdev("Board eeprom hash is 0x%08lx\n", dev->hash);
566
	em28xx_errdev("Board i2c devicelist hash is 0x%08lx\n", dev->i2c_hash);
567 568 569 570 571 572 573 574

	em28xx_errdev("Here is a list of valid choices for the card=<n>"
		      " insmod option:\n");
	for (i = 0; i < em28xx_bcount; i++) {
		em28xx_errdev("    card=%d -> %s\n",
				i, em28xx_boards[i].name);
	}
	return -1;
575 576
}

577 578 579 580 581 582 583 584 585 586 587 588 589 590

static void em28xx_set_model(struct em28xx *dev)
{
	dev->is_em2800 = em28xx_boards[dev->model].is_em2800;
	dev->has_tuner = em28xx_boards[dev->model].has_tuner;
	dev->has_msp34xx = em28xx_boards[dev->model].has_msp34xx;
	dev->tda9887_conf = em28xx_boards[dev->model].tda9887_conf;
	dev->decoder = em28xx_boards[dev->model].decoder;
	dev->video_inputs = em28xx_boards[dev->model].vchannels;

	if (!em28xx_boards[dev->model].has_tuner)
		dev->tuner_type = UNSET;
}

591
void em28xx_card_setup(struct em28xx *dev)
592
{
593 594 595 596
	em28xx_set_model(dev);

	dev->tuner_type = em28xx_boards[dev->model].tuner_type;

597
	/* request some modules */
598 599
	switch (dev->model) {
	case EM2820_BOARD_HAUPPAUGE_WINTV_USB_2:
600
	case EM2880_BOARD_HAUPPAUGE_WINTV_HVR_900:
601
	case EM2880_BOARD_HAUPPAUGE_WINTV_HVR_950:
602 603
	{
		struct tveeprom tv;
604
#ifdef CONFIG_MODULES
605
		request_module("tveeprom");
606
#endif
607 608 609 610
		/* Call first TVeeprom */

		dev->i2c_client.addr = 0xa0 >> 1;
		tveeprom_hauppauge_analog(&dev->i2c_client, &tv, dev->eedata);
611

612 613 614 615 616
		dev->tuner_type = tv.tuner_type;
		if (tv.audio_processor == AUDIO_CHIP_MSP34XX) {
			dev->i2s_speed = 2048000;
			dev->has_msp34xx = 1;
		}
617 618 619 620 621 622
#ifdef CONFIG_MODULES
		if (tv.has_ir)
			request_module("ir-kbd-i2c");
#endif
		/* FIXME: Should also retrieve decoder processor type */

623
		break;
624
	}
625 626 627 628 629 630
	case EM2820_BOARD_KWORLD_PVRTV2800RF:
		/* GPIO enables sound on KWORLD PVR TV 2800RF */
		em28xx_write_regs_req(dev, 0x00, 0x08, "\xf9", 1);
		break;
	case EM2820_BOARD_UNKNOWN:
	case EM2800_BOARD_UNKNOWN:
631 632
		if (!em28xx_hint_board(dev))
			em28xx_set_model(dev);
633 634
	}

635
	/* Allow override tuner type by a module parameter */
636 637 638 639 640 641 642 643 644 645 646 647 648 649 650
	if (tuner >= 0)
		dev->tuner_type = tuner;

#ifdef CONFIG_MODULES
	/* request some modules */
	if (dev->has_msp34xx)
		request_module("msp3400");
	if (dev->decoder == EM28XX_SAA7113 || dev->decoder == EM28XX_SAA7114)
		request_module("saa7115");
	if (dev->decoder == EM28XX_TVP5150)
		request_module("tvp5150");
	if (dev->has_tuner)
		request_module("tuner");
#endif

651
	em28xx_config_tuner (dev);
652
}