dib0700_devices.c 134.8 KB
Newer Older
1 2 3 4 5 6
/* Linux driver for devices based on the DiBcom DiB0700 USB bridge
 *
 *	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, version 2.
 *
7
 *  Copyright (C) 2005-9 DiBcom, SA et al
8 9 10 11
 */
#include "dib0700.h"

#include "dib3000mc.h"
12
#include "dib7000m.h"
13
#include "dib7000p.h"
14
#include "dib8000.h"
15
#include "dib9000.h"
16
#include "mt2060.h"
17
#include "mt2266.h"
18
#include "tuner-xc2028.h"
19
#include "xc5000.h"
20
#include "xc4000.h"
21
#include "s5h1411.h"
22
#include "dib0070.h"
23
#include "dib0090.h"
24 25
#include "lgdt3305.h"
#include "mxl5007t.h"
26

27 28 29 30 31
static int force_lna_activation;
module_param(force_lna_activation, int, 0644);
MODULE_PARM_DESC(force_lna_activation, "force the activation of Low-Noise-Amplifyer(s) (LNA), "
		"if applicable for the device (default: 0=automatic/off).");

32
struct dib0700_adapter_state {
33
	int (*set_param_save) (struct dvb_frontend *);
34
	const struct firmware *frontend_firmware;
35
	struct dib7000p_ops dib7000p_ops;
36
	struct dib8000_ops dib8000_ops;
37 38 39
};

/* Hauppauge Nova-T 500 (aka Bristol)
40 41 42 43
 *  has a LNA on GPIO0 which is enabled by setting 1 */
static struct mt2060_config bristol_mt2060_config[2] = {
	{
		.i2c_address = 0x60,
44
		.clock_out   = 3,
45 46 47 48 49
	}, {
		.i2c_address = 0x61,
	}
};

50

51 52
static struct dibx000_agc_config bristol_dib3000p_mt2060_agc_config = {
	.band_caps = BAND_VHF | BAND_UHF,
53
	.setup     = (1 << 8) | (5 << 5) | (0 << 4) | (0 << 3) | (0 << 2) | (2 << 0),
54

55 56 57 58
	.agc1_max = 42598,
	.agc1_min = 17694,
	.agc2_max = 45875,
	.agc2_min = 0,
59

60 61
	.agc1_pt1 = 0,
	.agc1_pt2 = 59,
62

63 64
	.agc1_slope1 = 0,
	.agc1_slope2 = 69,
65 66

	.agc2_pt1 = 0,
67
	.agc2_pt2 = 59,
68

69 70
	.agc2_slope1 = 111,
	.agc2_slope2 = 28,
71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87
};

static struct dib3000mc_config bristol_dib3000mc_config[2] = {
	{	.agc          = &bristol_dib3000p_mt2060_agc_config,
		.max_time     = 0x196,
		.ln_adc_level = 0x1cc7,
		.output_mpeg2_in_188_bytes = 1,
	},
	{	.agc          = &bristol_dib3000p_mt2060_agc_config,
		.max_time     = 0x196,
		.ln_adc_level = 0x1cc7,
		.output_mpeg2_in_188_bytes = 1,
	}
};

static int bristol_frontend_attach(struct dvb_usb_adapter *adap)
{
88
	struct dib0700_state *st = adap->dev->priv;
89 90 91 92 93 94
	if (adap->id == 0) {
		dib0700_set_gpio(adap->dev, GPIO6,  GPIO_OUT, 0); msleep(10);
		dib0700_set_gpio(adap->dev, GPIO6,  GPIO_OUT, 1); msleep(10);
		dib0700_set_gpio(adap->dev, GPIO10, GPIO_OUT, 0); msleep(10);
		dib0700_set_gpio(adap->dev, GPIO10, GPIO_OUT, 1); msleep(10);

95 96 97 98
		if (force_lna_activation)
			dib0700_set_gpio(adap->dev, GPIO0, GPIO_OUT, 1);
		else
			dib0700_set_gpio(adap->dev, GPIO0, GPIO_OUT, 0);
99

100 101 102 103 104
		if (dib3000mc_i2c_enumeration(&adap->dev->i2c_adap, 2, DEFAULT_DIB3000P_I2C_ADDRESS, bristol_dib3000mc_config) != 0) {
			dib0700_set_gpio(adap->dev, GPIO6, GPIO_OUT, 0); msleep(10);
			return -ENODEV;
		}
	}
105
	st->mt2060_if1[adap->id] = 1220;
106
	return (adap->fe_adap[0].fe = dvb_attach(dib3000mc_attach, &adap->dev->i2c_adap,
107
		(10 + adap->id) << 1, &bristol_dib3000mc_config[adap->id])) == NULL ? -ENODEV : 0;
108 109
}

110
static int eeprom_read(struct i2c_adapter *adap,u8 adrs,u8 *pval)
111 112 113 114 115 116 117 118 119
{
	struct i2c_msg msg[2] = {
		{ .addr = 0x50, .flags = 0,        .buf = &adrs, .len = 1 },
		{ .addr = 0x50, .flags = I2C_M_RD, .buf = pval,  .len = 1 },
	};
	if (i2c_transfer(adap, msg, 2) != 2) return -EREMOTEIO;
	return 0;
}

120 121
static int bristol_tuner_attach(struct dvb_usb_adapter *adap)
{
122
	struct i2c_adapter *prim_i2c = &adap->dev->i2c_adap;
123
	struct i2c_adapter *tun_i2c = dib3000mc_get_tuner_i2c_master(adap->fe_adap[0].fe, 1);
124 125
	s8 a;
	int if1=1220;
126 127
	if (adap->dev->udev->descriptor.idVendor  == cpu_to_le16(USB_VID_HAUPPAUGE) &&
		adap->dev->udev->descriptor.idProduct == cpu_to_le16(USB_PID_HAUPPAUGE_NOVA_T_500_2)) {
128 129
		if (!eeprom_read(prim_i2c,0x59 + adap->id,&a)) if1=1220+a;
	}
130 131 132
	return dvb_attach(mt2060_attach, adap->fe_adap[0].fe, tun_i2c,
			  &bristol_mt2060_config[adap->id], if1) == NULL ?
			  -ENODEV : 0;
133 134
}

135
/* STK7700D: Pinnacle/Terratec/Hauppauge Dual DVB-T Diversity */
136

137 138 139
/* MT226x */
static struct dibx000_agc_config stk7700d_7000p_mt2266_agc_config[2] = {
	{
140
		BAND_UHF,
141 142 143

		/* P_agc_use_sd_mod1=0, P_agc_use_sd_mod2=0, P_agc_freq_pwm_div=1, P_agc_inv_pwm1=1, P_agc_inv_pwm2=1,
		* P_agc_inh_dc_rv_est=0, P_agc_time_est=3, P_agc_freeze=0, P_agc_nb_est=2, P_agc_write=0 */
144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178
		(0 << 15) | (0 << 14) | (1 << 11) | (1 << 10) | (1 << 9) | (0 << 8)
	    | (3 << 5) | (0 << 4) | (5 << 1) | (0 << 0),

		1130,
		21,

		0,
		118,

		0,
		3530,
		1,
		0,

		65535,
		33770,
		65535,
		23592,

		0,
		62,
		255,
		64,
		64,
		132,
		192,
		80,
		80,

		17,
		27,
		23,
		51,

		1,
179
	}, {
180
		BAND_VHF | BAND_LBAND,
181 182 183

		/* P_agc_use_sd_mod1=0, P_agc_use_sd_mod2=0, P_agc_freq_pwm_div=1, P_agc_inv_pwm1=1, P_agc_inv_pwm2=1,
		* P_agc_inh_dc_rv_est=0, P_agc_time_est=3, P_agc_freeze=0, P_agc_nb_est=2, P_agc_write=0 */
184 185 186 187 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
		(0 << 15) | (0 << 14) | (1 << 11) | (1 << 10) | (1 << 9) | (0 << 8)
	    | (3 << 5) | (0 << 4) | (2 << 1) | (0 << 0),

		2372,
		21,

		0,
		118,

		0,
		3530,
		1,
		0,

		65535,
		0,
		65535,
		23592,

		0,
		128,
		128,
		128,
		0,
		128,
		253,
		81,
		0,

		17,
		27,
		23,
		51,

		1,
219
	}
220 221 222
};

static struct dibx000_bandwidth_config stk7700d_mt2266_pll_config = {
223 224 225 226 227 228
	60000, 30000,
	1, 8, 3, 1, 0,
	0, 0, 1, 1, 2,
	(3 << 14) | (1 << 12) | (524 << 0),
	0,
	20452225,
229 230 231 232 233 234 235
};

static struct dib7000p_config stk7700d_dib7000p_mt2266_config[] = {
	{	.output_mpeg2_in_188_bytes = 1,
		.hostbus_diversity = 1,
		.tuner_is_baseband = 1,

236 237
		.agc_config_count = 2,
		.agc = stk7700d_7000p_mt2266_agc_config,
238 239
		.bw  = &stk7700d_mt2266_pll_config,

240 241 242
		.gpio_dir = DIB7000P_GPIO_DEFAULT_DIRECTIONS,
		.gpio_val = DIB7000P_GPIO_DEFAULT_VALUES,
		.gpio_pwm_pos = DIB7000P_GPIO_DEFAULT_PWM_POS,
243 244 245 246 247
	},
	{	.output_mpeg2_in_188_bytes = 1,
		.hostbus_diversity = 1,
		.tuner_is_baseband = 1,

248 249
		.agc_config_count = 2,
		.agc = stk7700d_7000p_mt2266_agc_config,
250 251
		.bw  = &stk7700d_mt2266_pll_config,

252 253 254
		.gpio_dir = DIB7000P_GPIO_DEFAULT_DIRECTIONS,
		.gpio_val = DIB7000P_GPIO_DEFAULT_VALUES,
		.gpio_pwm_pos = DIB7000P_GPIO_DEFAULT_PWM_POS,
255 256 257 258 259 260 261 262 263 264
	}
};

static struct mt2266_config stk7700d_mt2266_config[2] = {
	{	.i2c_address = 0x60
	},
	{	.i2c_address = 0x60
	}
};

265 266
static int stk7700P2_frontend_attach(struct dvb_usb_adapter *adap)
{
267 268 269 270 271
	struct dib0700_adapter_state *state = adap->priv;

	if (!dvb_attach(dib7000p_attach, &state->dib7000p_ops))
		return -ENODEV;

272 273 274 275 276 277 278 279 280 281
	if (adap->id == 0) {
		dib0700_set_gpio(adap->dev, GPIO6, GPIO_OUT, 1);
		msleep(10);
		dib0700_set_gpio(adap->dev, GPIO9, GPIO_OUT, 1);
		dib0700_set_gpio(adap->dev, GPIO4, GPIO_OUT, 1);
		dib0700_set_gpio(adap->dev, GPIO7, GPIO_OUT, 1);
		dib0700_set_gpio(adap->dev, GPIO10, GPIO_OUT, 0);
		msleep(10);
		dib0700_set_gpio(adap->dev, GPIO10, GPIO_OUT, 1);
		msleep(10);
282
		if (state->dib7000p_ops.i2c_enumeration(&adap->dev->i2c_adap, 1, 18,
283 284
					     stk7700d_dib7000p_mt2266_config)
		    != 0) {
285 286
			err("%s: state->dib7000p_ops.i2c_enumeration failed.  Cannot continue\n", __func__);
			dvb_detach(&state->dib7000p_ops);
287 288
			return -ENODEV;
		}
289 290
	}

291
	adap->fe_adap[0].fe = state->dib7000p_ops.init(&adap->dev->i2c_adap,
292 293
			   0x80 + (adap->id << 1),
			   &stk7700d_dib7000p_mt2266_config[adap->id]);
294

295
	return adap->fe_adap[0].fe == NULL ? -ENODEV : 0;
296 297
}

298 299
static int stk7700d_frontend_attach(struct dvb_usb_adapter *adap)
{
300 301 302 303 304
	struct dib0700_adapter_state *state = adap->priv;

	if (!dvb_attach(dib7000p_attach, &state->dib7000p_ops))
		return -ENODEV;

305 306 307 308 309 310 311 312 313 314 315
	if (adap->id == 0) {
		dib0700_set_gpio(adap->dev, GPIO6, GPIO_OUT, 1);
		msleep(10);
		dib0700_set_gpio(adap->dev, GPIO9, GPIO_OUT, 1);
		dib0700_set_gpio(adap->dev, GPIO4, GPIO_OUT, 1);
		dib0700_set_gpio(adap->dev, GPIO7, GPIO_OUT, 1);
		dib0700_set_gpio(adap->dev, GPIO10, GPIO_OUT, 0);
		msleep(10);
		dib0700_set_gpio(adap->dev, GPIO10, GPIO_OUT, 1);
		msleep(10);
		dib0700_set_gpio(adap->dev, GPIO0, GPIO_OUT, 1);
316
		if (state->dib7000p_ops.i2c_enumeration(&adap->dev->i2c_adap, 2, 18,
317 318
					     stk7700d_dib7000p_mt2266_config)
		    != 0) {
319 320
			err("%s: state->dib7000p_ops.i2c_enumeration failed.  Cannot continue\n", __func__);
			dvb_detach(&state->dib7000p_ops);
321 322
			return -ENODEV;
		}
323 324
	}

325
	adap->fe_adap[0].fe = state->dib7000p_ops.init(&adap->dev->i2c_adap,
326 327
			   0x80 + (adap->id << 1),
			   &stk7700d_dib7000p_mt2266_config[adap->id]);
328

329
	return adap->fe_adap[0].fe == NULL ? -ENODEV : 0;
330 331 332 333 334
}

static int stk7700d_tuner_attach(struct dvb_usb_adapter *adap)
{
	struct i2c_adapter *tun_i2c;
335 336 337 338
	struct dib0700_adapter_state *state = adap->priv;

	tun_i2c = state->dib7000p_ops.get_i2c_master(adap->fe_adap[0].fe,
					    DIBX000_I2C_INTERFACE_TUNER, 1);
339
	return dvb_attach(mt2266_attach, adap->fe_adap[0].fe, tun_i2c,
340
		&stk7700d_mt2266_config[adap->id]) == NULL ? -ENODEV : 0;
341 342
}

343
/* STK7700-PH: Digital/Analog Hybrid Tuner, e.h. Cinergy HT USB HE */
344
static struct dibx000_agc_config xc3028_agc_config = {
345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386
	BAND_VHF | BAND_UHF,       /* band_caps */

	/* P_agc_use_sd_mod1=0, P_agc_use_sd_mod2=0, P_agc_freq_pwm_div=0,
	 * P_agc_inv_pwm1=0, P_agc_inv_pwm2=0, P_agc_inh_dc_rv_est=0,
	 * P_agc_time_est=3, P_agc_freeze=0, P_agc_nb_est=2, P_agc_write=0 */
	(0 << 15) | (0 << 14) | (0 << 11) | (0 << 10) | (0 << 9) | (0 << 8) |
	(3 << 5) | (0 << 4) | (2 << 1) | (0 << 0), /* setup */

	712,	/* inv_gain */
	21,	/* time_stabiliz */

	0,	/* alpha_level */
	118,	/* thlock */

	0,	/* wbd_inv */
	2867,	/* wbd_ref */
	0,	/* wbd_sel */
	2,	/* wbd_alpha */

	0,	/* agc1_max */
	0,	/* agc1_min */
	39718,	/* agc2_max */
	9930,	/* agc2_min */
	0,	/* agc1_pt1 */
	0,	/* agc1_pt2 */
	0,	/* agc1_pt3 */
	0,	/* agc1_slope1 */
	0,	/* agc1_slope2 */
	0,	/* agc2_pt1 */
	128,	/* agc2_pt2 */
	29,	/* agc2_slope1 */
	29,	/* agc2_slope2 */

	17,	/* alpha_mant */
	27,	/* alpha_exp */
	23,	/* beta_mant */
	51,	/* beta_exp */

	1,	/* perform_agc_softsplit */
};

/* PLL Configuration for COFDM BW_MHz = 8.00 with external clock = 30.00 */
387
static struct dibx000_bandwidth_config xc3028_bw_config = {
388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410
	60000, 30000, /* internal, sampling */
	1, 8, 3, 1, 0, /* pll_cfg: prediv, ratio, range, reset, bypass */
	0, 0, 1, 1, 0, /* misc: refdiv, bypclk_div, IO_CLK_en_core, ADClkSrc,
			  modulo */
	(3 << 14) | (1 << 12) | (524 << 0), /* sad_cfg: refsel, sel, freq_15k */
	(1 << 25) | 5816102, /* ifreq = 5.200000 MHz */
	20452225, /* timf */
	30000000, /* xtal_hz */
};

static struct dib7000p_config stk7700ph_dib7700_xc3028_config = {
	.output_mpeg2_in_188_bytes = 1,
	.tuner_is_baseband = 1,

	.agc_config_count = 1,
	.agc = &xc3028_agc_config,
	.bw  = &xc3028_bw_config,

	.gpio_dir = DIB7000P_GPIO_DEFAULT_DIRECTIONS,
	.gpio_val = DIB7000P_GPIO_DEFAULT_VALUES,
	.gpio_pwm_pos = DIB7000P_GPIO_DEFAULT_PWM_POS,
};

411 412
static int stk7700ph_xc3028_callback(void *ptr, int component,
				     int command, int arg)
413 414
{
	struct dvb_usb_adapter *adap = ptr;
415
	struct dib0700_adapter_state *state = adap->priv;
416 417 418 419

	switch (command) {
	case XC2028_TUNER_RESET:
		/* Send the tuner in then out of reset */
420 421 422
		state->dib7000p_ops.set_gpio(adap->fe_adap[0].fe, 8, 0, 0);
		msleep(10);
		state->dib7000p_ops.set_gpio(adap->fe_adap[0].fe, 8, 0, 1);
423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447
		break;
	case XC2028_RESET_CLK:
		break;
	default:
		err("%s: unknown command %d, arg %d\n", __func__,
			command, arg);
		return -EINVAL;
	}
	return 0;
}

static struct xc2028_ctrl stk7700ph_xc3028_ctrl = {
	.fname = XC2028_DEFAULT_FIRMWARE,
	.max_len = 64,
	.demod = XC3028_FE_DIBCOM52,
};

static struct xc2028_config stk7700ph_xc3028_config = {
	.i2c_addr = 0x61,
	.ctrl = &stk7700ph_xc3028_ctrl,
};

static int stk7700ph_frontend_attach(struct dvb_usb_adapter *adap)
{
	struct usb_device_descriptor *desc = &adap->dev->udev->descriptor;
448 449 450 451
	struct dib0700_adapter_state *state = adap->priv;

	if (!dvb_attach(dib7000p_attach, &state->dib7000p_ops))
		return -ENODEV;
452

453 454
	if (desc->idVendor  == cpu_to_le16(USB_VID_PINNACLE) &&
	    desc->idProduct == cpu_to_le16(USB_PID_PINNACLE_EXPRESSCARD_320CX))
455
		dib0700_set_gpio(adap->dev, GPIO6, GPIO_OUT, 0);
456
	else
457
		dib0700_set_gpio(adap->dev, GPIO6, GPIO_OUT, 1);
458 459 460 461 462 463 464 465 466 467 468
	msleep(20);
	dib0700_set_gpio(adap->dev, GPIO9, GPIO_OUT, 1);
	dib0700_set_gpio(adap->dev, GPIO4, GPIO_OUT, 1);
	dib0700_set_gpio(adap->dev, GPIO7, GPIO_OUT, 1);
	dib0700_set_gpio(adap->dev, GPIO10, GPIO_OUT, 0);
	msleep(10);
	dib0700_set_gpio(adap->dev, GPIO10, GPIO_OUT, 1);
	msleep(20);
	dib0700_set_gpio(adap->dev, GPIO0, GPIO_OUT, 1);
	msleep(10);

469
	if (state->dib7000p_ops.i2c_enumeration(&adap->dev->i2c_adap, 1, 18,
470
				     &stk7700ph_dib7700_xc3028_config) != 0) {
471
		err("%s: state->dib7000p_ops.i2c_enumeration failed.  Cannot continue\n",
472
		    __func__);
473
		dvb_detach(&state->dib7000p_ops);
474 475
		return -ENODEV;
	}
476

477
	adap->fe_adap[0].fe = state->dib7000p_ops.init(&adap->dev->i2c_adap, 0x80,
478 479
		&stk7700ph_dib7700_xc3028_config);

480
	return adap->fe_adap[0].fe == NULL ? -ENODEV : 0;
481 482 483 484 485
}

static int stk7700ph_tuner_attach(struct dvb_usb_adapter *adap)
{
	struct i2c_adapter *tun_i2c;
486
	struct dib0700_adapter_state *state = adap->priv;
487

488
	tun_i2c = state->dib7000p_ops.get_i2c_master(adap->fe_adap[0].fe,
489 490 491
		DIBX000_I2C_INTERFACE_TUNER, 1);

	stk7700ph_xc3028_config.i2c_adap = tun_i2c;
492 493

	/* FIXME: generalize & move to common area */
494
	adap->fe_adap[0].fe->callback = stk7700ph_xc3028_callback;
495

496
	return dvb_attach(xc2028_attach, adap->fe_adap[0].fe, &stk7700ph_xc3028_config)
497 498 499
		== NULL ? -ENODEV : 0;
}

500
#define DEFAULT_RC_INTERVAL 50
501 502 503

static u8 rc_request[] = { REQUEST_POLL_RC, 0 };

504
/* Number of keypresses to ignore before start repeating */
505
#define RC_REPEAT_DELAY 6
506

507 508 509 510 511 512
/*
 * This function is used only when firmware is < 1.20 version. Newer
 * firmwares use bulk mode, with functions implemented at dib0700_core,
 * at dib0700_rc_urb_completion()
 */
static int dib0700_rc_query_old_firmware(struct dvb_usb_device *d)
513 514
{
	u8 key[4];
515 516
	u32 keycode;
	u8 toggle;
517 518
	int i;
	struct dib0700_state *st = d->priv;
519 520 521 522 523 524 525 526 527

	if (st->fw_version >= 0x10200) {
		/* For 1.20 firmware , We need to keep the RC polling
		   callback so we can reuse the input device setup in
		   dvb-usb-remote.c.  However, the actual work is being done
		   in the bulk URB completion handler. */
		return 0;
	}

528 529
	i = dib0700_ctrl_rd(d, rc_request, 2, key, 4);
	if (i <= 0) {
530
		err("RC Query Failed");
531
		return -1;
532
	}
533 534

	/* losing half of KEY_0 events from Philipps rc5 remotes.. */
535 536
	if (key[0] == 0 && key[1] == 0 && key[2] == 0 && key[3] == 0)
		return 0;
537 538 539

	/* info("%d: %2X %2X %2X %2X",dvb_usb_dib0700_ir_proto,(int)key[3-2],(int)key[3-3],(int)key[3-1],(int)key[3]);  */

540
	dib0700_rc_setup(d, NULL); /* reset ir sensor data to prevent false events */
541

542
	d->last_event = 0;
543
	switch (d->props.rc.core.protocol) {
544
	case RC_BIT_NEC:
545 546
		/* NEC protocol sends repeat code as 0 0 0 FF */
		if ((key[3-2] == 0x00) && (key[3-3] == 0x00) &&
547 548 549 550 551
		    (key[3] == 0xff))
			keycode = d->last_event;
		else {
			keycode = key[3-2] << 8 | key[3-3];
			d->last_event = keycode;
552
		}
553

554
		rc_keydown(d->rc_dev, keycode, 0);
555
		break;
556
	default:
557
		/* RC-5 protocol changes toggle bit on new keypress */
558 559
		keycode = key[3-2] << 8 | key[3-3];
		toggle = key[3-1];
560
		rc_keydown(d->rc_dev, keycode, toggle);
561

562 563
		break;
	}
564 565 566
	return 0;
}

567
/* STK7700P: Hauppauge Nova-T Stick, AVerMedia Volar */
568
static struct dibx000_agc_config stk7700p_7000m_mt2060_agc_config = {
569
	BAND_UHF | BAND_VHF,
570 571 572

	/* P_agc_use_sd_mod1=0, P_agc_use_sd_mod2=0, P_agc_freq_pwm_div=5, P_agc_inv_pwm1=0, P_agc_inv_pwm2=0,
	 * P_agc_inh_dc_rv_est=0, P_agc_time_est=3, P_agc_freeze=0, P_agc_nb_est=2, P_agc_write=0 */
573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610
	(0 << 15) | (0 << 14) | (5 << 11) | (0 << 10) | (0 << 9) | (0 << 8)
	| (3 << 5) | (0 << 4) | (2 << 1) | (0 << 0),

	712,
	41,

	0,
	118,

	0,
	4095,
	0,
	0,

	42598,
	17694,
	45875,
	2621,
	0,
	76,
	139,
	52,
	59,
	107,
	172,
	57,
	70,

	21,
	25,
	28,
	48,

	1,
	{  0,
	   107,
	   51800,
	   24700
611 612 613
	},
};

614 615 616 617 618
static struct dibx000_agc_config stk7700p_7000p_mt2060_agc_config = {
	BAND_UHF | BAND_VHF,

	/* P_agc_use_sd_mod1=0, P_agc_use_sd_mod2=0, P_agc_freq_pwm_div=5, P_agc_inv_pwm1=0, P_agc_inv_pwm2=0,
	 * P_agc_inh_dc_rv_est=0, P_agc_time_est=3, P_agc_freeze=0, P_agc_nb_est=2, P_agc_write=0 */
619 620
	(0 << 15) | (0 << 14) | (5 << 11) | (0 << 10) | (0 << 9) | (0 << 8)
	| (3 << 5) | (0 << 4) | (2 << 1) | (0 << 0),
621

622 623
	712,
	41,
624

625 626
	0,
	118,
627

628 629 630 631
	0,
	4095,
	0,
	0,
632

633 634 635 636
	42598,
	16384,
	42598,
	    0,
637

638 639 640
	  0,
	137,
	255,
641

642 643
	  0,
	255,
644

645 646
	0,
	0,
647

648 649
	 0,
	41,
650

651 652
	15,
	25,
653

654 655
	28,
	48,
656

657
	0,
658 659 660
};

static struct dibx000_bandwidth_config stk7700p_pll_config = {
661 662 663 664 665 666 667
	60000, 30000,
	1, 8, 3, 1, 0,
	0, 0, 1, 1, 0,
	(3 << 14) | (1 << 12) | (524 << 0),
	60258167,
	20452225,
	30000000,
668 669 670 671 672 673 674 675
};

static struct dib7000m_config stk7700p_dib7000m_config = {
	.dvbt_mode = 1,
	.output_mpeg2_in_188_bytes = 1,
	.quartz_direct = 1,

	.agc_config_count = 1,
676 677 678 679 680 681 682 683 684 685 686
	.agc = &stk7700p_7000m_mt2060_agc_config,
	.bw  = &stk7700p_pll_config,

	.gpio_dir = DIB7000M_GPIO_DEFAULT_DIRECTIONS,
	.gpio_val = DIB7000M_GPIO_DEFAULT_VALUES,
	.gpio_pwm_pos = DIB7000M_GPIO_DEFAULT_PWM_POS,
};

static struct dib7000p_config stk7700p_dib7000p_config = {
	.output_mpeg2_in_188_bytes = 1,

687
	.agc_config_count = 1,
688 689
	.agc = &stk7700p_7000p_mt2060_agc_config,
	.bw  = &stk7700p_pll_config,
690 691 692 693

	.gpio_dir = DIB7000M_GPIO_DEFAULT_DIRECTIONS,
	.gpio_val = DIB7000M_GPIO_DEFAULT_VALUES,
	.gpio_pwm_pos = DIB7000M_GPIO_DEFAULT_PWM_POS,
694 695 696 697
};

static int stk7700p_frontend_attach(struct dvb_usb_adapter *adap)
{
698
	struct dib0700_state *st = adap->dev->priv;
699 700 701 702 703
	struct dib0700_adapter_state *state = adap->priv;

	if (!dvb_attach(dib7000p_attach, &state->dib7000p_ops))
		return -ENODEV;

704
	/* unless there is no real power management in DVB - we leave the device on GPIO6 */
705 706 707 708

	dib0700_set_gpio(adap->dev, GPIO10, GPIO_OUT, 0);
	dib0700_set_gpio(adap->dev, GPIO6,  GPIO_OUT, 0); msleep(50);

709
	dib0700_set_gpio(adap->dev, GPIO6,  GPIO_OUT, 1); msleep(10);
710 711
	dib0700_set_gpio(adap->dev, GPIO9,  GPIO_OUT, 1);

712
	dib0700_set_gpio(adap->dev, GPIO10, GPIO_OUT, 0); msleep(10);
713 714 715 716
	dib0700_ctrl_clock(adap->dev, 72, 1);
	dib0700_set_gpio(adap->dev, GPIO10, GPIO_OUT, 1); msleep(100);

	dib0700_set_gpio(adap->dev,  GPIO0, GPIO_OUT, 1);
717

718
	st->mt2060_if1[0] = 1220;
719

720 721
	if (state->dib7000p_ops.dib7000pc_detection(&adap->dev->i2c_adap)) {
		adap->fe_adap[0].fe = state->dib7000p_ops.init(&adap->dev->i2c_adap, 18, &stk7700p_dib7000p_config);
722
		st->is_dib7000pc = 1;
723 724 725
	} else {
		dvb_detach(&state->dib7000p_ops);
		memset(&state->dib7000p_ops, 0, sizeof(state->dib7000p_ops));
726
		adap->fe_adap[0].fe = dvb_attach(dib7000m_attach, &adap->dev->i2c_adap, 18, &stk7700p_dib7000m_config);
727
	}
728

729
	return adap->fe_adap[0].fe == NULL ? -ENODEV : 0;
730 731
}

732 733 734 735
static struct mt2060_config stk7700p_mt2060_config = {
	0x60
};

736 737
static int stk7700p_tuner_attach(struct dvb_usb_adapter *adap)
{
738
	struct i2c_adapter *prim_i2c = &adap->dev->i2c_adap;
739
	struct dib0700_state *st = adap->dev->priv;
740
	struct i2c_adapter *tun_i2c;
741
	struct dib0700_adapter_state *state = adap->priv;
742 743
	s8 a;
	int if1=1220;
744

745 746
	if (adap->dev->udev->descriptor.idVendor  == cpu_to_le16(USB_VID_HAUPPAUGE) &&
		adap->dev->udev->descriptor.idProduct == cpu_to_le16(USB_PID_HAUPPAUGE_NOVA_T_STICK)) {
747 748
		if (!eeprom_read(prim_i2c,0x58,&a)) if1=1220+a;
	}
749
	if (st->is_dib7000pc)
750
		tun_i2c = state->dib7000p_ops.get_i2c_master(adap->fe_adap[0].fe, DIBX000_I2C_INTERFACE_TUNER, 1);
751
	else
752
		tun_i2c = dib7000m_get_i2c_master(adap->fe_adap[0].fe, DIBX000_I2C_INTERFACE_TUNER, 1);
753

754
	return dvb_attach(mt2060_attach, adap->fe_adap[0].fe, tun_i2c, &stk7700p_mt2060_config,
755
		if1) == NULL ? -ENODEV : 0;
756 757
}

758 759 760 761 762
/* DIB7070 generic */
static struct dibx000_agc_config dib7070_agc_config = {
	BAND_UHF | BAND_VHF | BAND_LBAND | BAND_SBAND,
	/* P_agc_use_sd_mod1=0, P_agc_use_sd_mod2=0, P_agc_freq_pwm_div=5, P_agc_inv_pwm1=0, P_agc_inv_pwm2=0,
	 * P_agc_inh_dc_rv_est=0, P_agc_time_est=3, P_agc_freeze=0, P_agc_nb_est=5, P_agc_write=0 */
763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798
	(0 << 15) | (0 << 14) | (5 << 11) | (0 << 10) | (0 << 9) | (0 << 8)
	| (3 << 5) | (0 << 4) | (5 << 1) | (0 << 0),

	600,
	10,

	0,
	118,

	0,
	3530,
	1,
	5,

	65535,
		0,

	65535,
	0,

	0,
	40,
	183,
	206,
	255,
	72,
	152,
	88,
	90,

	17,
	27,
	23,
	51,

	0,
799 800 801 802
};

static int dib7070_tuner_reset(struct dvb_frontend *fe, int onoff)
{
803 804 805
	struct dvb_usb_adapter *adap = fe->dvb->priv;
	struct dib0700_adapter_state *state = adap->priv;

806
	deb_info("reset: %d", onoff);
807
	return state->dib7000p_ops.set_gpio(fe, 8, 0, !onoff);
808 809 810 811
}

static int dib7070_tuner_sleep(struct dvb_frontend *fe, int onoff)
{
812 813 814
	struct dvb_usb_adapter *adap = fe->dvb->priv;
	struct dib0700_adapter_state *state = adap->priv;

815
	deb_info("sleep: %d", onoff);
816
	return state->dib7000p_ops.set_gpio(fe, 9, 0, onoff);
817 818 819 820 821 822 823 824
}

static struct dib0070_config dib7070p_dib0070_config[2] = {
	{
		.i2c_address = DEFAULT_DIB0070_I2C_ADDRESS,
		.reset = dib7070_tuner_reset,
		.sleep = dib7070_tuner_sleep,
		.clock_khz = 12000,
825 826
		.clock_pad_drive = 4,
		.charge_pump = 2,
827 828 829 830 831
	}, {
		.i2c_address = DEFAULT_DIB0070_I2C_ADDRESS,
		.reset = dib7070_tuner_reset,
		.sleep = dib7070_tuner_sleep,
		.clock_khz = 12000,
832
		.charge_pump = 2,
833 834 835
	}
};

836 837 838 839 840 841 842
static struct dib0070_config dib7770p_dib0070_config = {
	 .i2c_address = DEFAULT_DIB0070_I2C_ADDRESS,
	 .reset = dib7070_tuner_reset,
	 .sleep = dib7070_tuner_sleep,
	 .clock_khz = 12000,
	 .clock_pad_drive = 0,
	 .flip_chip = 1,
843
	 .charge_pump = 2,
844 845
};

846
static int dib7070_set_param_override(struct dvb_frontend *fe)
847
{
848
	struct dtv_frontend_properties *p = &fe->dtv_property_cache;
849 850 851 852
	struct dvb_usb_adapter *adap = fe->dvb->priv;
	struct dib0700_adapter_state *state = adap->priv;

	u16 offset;
853
	u8 band = BAND_OF_FREQUENCY(p->frequency/1000);
854 855 856 857 858 859
	switch (band) {
		case BAND_VHF: offset = 950; break;
		case BAND_UHF:
		default: offset = 550; break;
	}
	deb_info("WBD for DiB7000P: %d\n", offset + dib0070_wbd_offset(fe));
860
	state->dib7000p_ops.set_wbd_ref(fe, offset + dib0070_wbd_offset(fe));
861
	return state->set_param_save(fe);
862 863
}

864
static int dib7770_set_param_override(struct dvb_frontend *fe)
865
{
866 867 868
	struct dtv_frontend_properties *p = &fe->dtv_property_cache;
	struct dvb_usb_adapter *adap = fe->dvb->priv;
	struct dib0700_adapter_state *state = adap->priv;
869 870

	 u16 offset;
871
	 u8 band = BAND_OF_FREQUENCY(p->frequency/1000);
872 873
	 switch (band) {
	 case BAND_VHF:
874
		  state->dib7000p_ops.set_gpio(fe, 0, 0, 1);
875 876 877 878
		  offset = 850;
		  break;
	 case BAND_UHF:
	 default:
879
		  state->dib7000p_ops.set_gpio(fe, 0, 0, 0);
880 881 882 883
		  offset = 250;
		  break;
	 }
	 deb_info("WBD for DiB7000P: %d\n", offset + dib0070_wbd_offset(fe));
884
	 state->dib7000p_ops.set_wbd_ref(fe, offset + dib0070_wbd_offset(fe));
885
	 return state->set_param_save(fe);
886 887 888 889
}

static int dib7770p_tuner_attach(struct dvb_usb_adapter *adap)
{
890 891
	struct dib0700_adapter_state *st = adap->priv;
	struct i2c_adapter *tun_i2c = st->dib7000p_ops.get_i2c_master(adap->fe_adap[0].fe,
892 893
			 DIBX000_I2C_INTERFACE_TUNER, 1);

894 895 896
	if (dvb_attach(dib0070_attach, adap->fe_adap[0].fe, tun_i2c,
		       &dib7770p_dib0070_config) == NULL)
		return -ENODEV;
897

898 899 900
	st->set_param_save = adap->fe_adap[0].fe->ops.tuner_ops.set_params;
	adap->fe_adap[0].fe->ops.tuner_ops.set_params = dib7770_set_param_override;
	return 0;
901 902
}

903 904 905
static int dib7070p_tuner_attach(struct dvb_usb_adapter *adap)
{
	struct dib0700_adapter_state *st = adap->priv;
906
	struct i2c_adapter *tun_i2c = st->dib7000p_ops.get_i2c_master(adap->fe_adap[0].fe, DIBX000_I2C_INTERFACE_TUNER, 1);
907 908

	if (adap->id == 0) {
909
		if (dvb_attach(dib0070_attach, adap->fe_adap[0].fe, tun_i2c, &dib7070p_dib0070_config[0]) == NULL)
910 911
			return -ENODEV;
	} else {
912
		if (dvb_attach(dib0070_attach, adap->fe_adap[0].fe, tun_i2c, &dib7070p_dib0070_config[1]) == NULL)
913 914 915
			return -ENODEV;
	}

916 917
	st->set_param_save = adap->fe_adap[0].fe->ops.tuner_ops.set_params;
	adap->fe_adap[0].fe->ops.tuner_ops.set_params = dib7070_set_param_override;
918 919 920
	return 0;
}

921 922 923
static int stk7700p_pid_filter(struct dvb_usb_adapter *adapter, int index,
		u16 pid, int onoff)
{
924
	struct dib0700_adapter_state *state = adapter->priv;
925
	struct dib0700_state *st = adapter->dev->priv;
926

927
	if (st->is_dib7000pc)
928
		return state->dib7000p_ops.pid_filter(adapter->fe_adap[0].fe, index, pid, onoff);
929
	return dib7000m_pid_filter(adapter->fe_adap[0].fe, index, pid, onoff);
930 931 932 933 934
}

static int stk7700p_pid_filter_ctrl(struct dvb_usb_adapter *adapter, int onoff)
{
	struct dib0700_state *st = adapter->dev->priv;
935
	struct dib0700_adapter_state *state = adapter->priv;
936
	if (st->is_dib7000pc)
937
		return state->dib7000p_ops.pid_filter_ctrl(adapter->fe_adap[0].fe, onoff);
938
	return dib7000m_pid_filter_ctrl(adapter->fe_adap[0].fe, onoff);
939 940
}

941 942
static int stk70x0p_pid_filter(struct dvb_usb_adapter *adapter, int index, u16 pid, int onoff)
{
943 944
	struct dib0700_adapter_state *state = adapter->priv;
	return state->dib7000p_ops.pid_filter(adapter->fe_adap[0].fe, index, pid, onoff);
945 946 947 948
}

static int stk70x0p_pid_filter_ctrl(struct dvb_usb_adapter *adapter, int onoff)
{
949 950
	struct dib0700_adapter_state *state = adapter->priv;
	return state->dib7000p_ops.pid_filter_ctrl(adapter->fe_adap[0].fe, onoff);
951 952
}

953
static struct dibx000_bandwidth_config dib7070_bw_config_12_mhz = {
954 955 956 957 958 959 960
	60000, 15000,
	1, 20, 3, 1, 0,
	0, 0, 1, 1, 2,
	(3 << 14) | (1 << 12) | (524 << 0),
	(0 << 25) | 0,
	20452225,
	12000000,
961 962 963 964 965 966 967 968
};

static struct dib7000p_config dib7070p_dib7000p_config = {
	.output_mpeg2_in_188_bytes = 1,

	.agc_config_count = 1,
	.agc = &dib7070_agc_config,
	.bw  = &dib7070_bw_config_12_mhz,
969 970
	.tuner_is_baseband = 1,
	.spur_protect = 1,
971 972 973 974 975 976 977 978 979 980 981

	.gpio_dir = DIB7000P_GPIO_DEFAULT_DIRECTIONS,
	.gpio_val = DIB7000P_GPIO_DEFAULT_VALUES,
	.gpio_pwm_pos = DIB7000P_GPIO_DEFAULT_PWM_POS,

	.hostbus_diversity = 1,
};

/* STK7070P */
static int stk7070p_frontend_attach(struct dvb_usb_adapter *adap)
{
982
	struct usb_device_descriptor *p = &adap->dev->udev->descriptor;
983 984 985 986 987
	struct dib0700_adapter_state *state = adap->priv;

	if (!dvb_attach(dib7000p_attach, &state->dib7000p_ops))
		return -ENODEV;

988 989 990
	if (p->idVendor  == cpu_to_le16(USB_VID_PINNACLE) &&
	    p->idProduct == cpu_to_le16(USB_PID_PINNACLE_PCTV72E))
		dib0700_set_gpio(adap->dev, GPIO6, GPIO_OUT, 0);
991
	else
992
		dib0700_set_gpio(adap->dev, GPIO6, GPIO_OUT, 1);
993 994 995 996 997 998 999 1000 1001 1002 1003 1004 1005
	msleep(10);
	dib0700_set_gpio(adap->dev, GPIO9, GPIO_OUT, 1);
	dib0700_set_gpio(adap->dev, GPIO4, GPIO_OUT, 1);
	dib0700_set_gpio(adap->dev, GPIO7, GPIO_OUT, 1);
	dib0700_set_gpio(adap->dev, GPIO10, GPIO_OUT, 0);

	dib0700_ctrl_clock(adap->dev, 72, 1);

	msleep(10);
	dib0700_set_gpio(adap->dev, GPIO10, GPIO_OUT, 1);
	msleep(10);
	dib0700_set_gpio(adap->dev, GPIO0, GPIO_OUT, 1);

1006
	if (state->dib7000p_ops.i2c_enumeration(&adap->dev->i2c_adap, 1, 18,
1007
				     &dib7070p_dib7000p_config) != 0) {
1008
		err("%s: state->dib7000p_ops.i2c_enumeration failed.  Cannot continue\n",
1009
		    __func__);
1010
		dvb_detach(&state->dib7000p_ops);
1011 1012
		return -ENODEV;
	}
1013

1014
	adap->fe_adap[0].fe = state->dib7000p_ops.init(&adap->dev->i2c_adap, 0x80,
1015
		&dib7070p_dib7000p_config);
1016
	return adap->fe_adap[0].fe == NULL ? -ENODEV : 0;
1017 1018
}

1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 1032 1033 1034
/* STK7770P */
static struct dib7000p_config dib7770p_dib7000p_config = {
	.output_mpeg2_in_188_bytes = 1,

	.agc_config_count = 1,
	.agc = &dib7070_agc_config,
	.bw  = &dib7070_bw_config_12_mhz,
	.tuner_is_baseband = 1,
	.spur_protect = 1,

	.gpio_dir = DIB7000P_GPIO_DEFAULT_DIRECTIONS,
	.gpio_val = DIB7000P_GPIO_DEFAULT_VALUES,
	.gpio_pwm_pos = DIB7000P_GPIO_DEFAULT_PWM_POS,

	.hostbus_diversity = 1,
	.enable_current_mirror = 1,
1035
	.disable_sample_and_hold = 0,
1036 1037 1038 1039 1040
};

static int stk7770p_frontend_attach(struct dvb_usb_adapter *adap)
{
	struct usb_device_descriptor *p = &adap->dev->udev->descriptor;
1041 1042 1043 1044 1045
	struct dib0700_adapter_state *state = adap->priv;

	if (!dvb_attach(dib7000p_attach, &state->dib7000p_ops))
		return -ENODEV;

1046 1047 1048 1049 1050 1051 1052 1053 1054 1055 1056 1057 1058 1059 1060 1061 1062 1063
	if (p->idVendor  == cpu_to_le16(USB_VID_PINNACLE) &&
	    p->idProduct == cpu_to_le16(USB_PID_PINNACLE_PCTV72E))
		dib0700_set_gpio(adap->dev, GPIO6, GPIO_OUT, 0);
	else
		dib0700_set_gpio(adap->dev, GPIO6, GPIO_OUT, 1);
	msleep(10);
	dib0700_set_gpio(adap->dev, GPIO9, GPIO_OUT, 1);
	dib0700_set_gpio(adap->dev, GPIO4, GPIO_OUT, 1);
	dib0700_set_gpio(adap->dev, GPIO7, GPIO_OUT, 1);
	dib0700_set_gpio(adap->dev, GPIO10, GPIO_OUT, 0);

	dib0700_ctrl_clock(adap->dev, 72, 1);

	msleep(10);
	dib0700_set_gpio(adap->dev, GPIO10, GPIO_OUT, 1);
	msleep(10);
	dib0700_set_gpio(adap->dev, GPIO0, GPIO_OUT, 1);

1064
	if (state->dib7000p_ops.i2c_enumeration(&adap->dev->i2c_adap, 1, 18,
1065
				     &dib7770p_dib7000p_config) != 0) {
1066
		err("%s: state->dib7000p_ops.i2c_enumeration failed.  Cannot continue\n",
1067
		    __func__);
1068
		dvb_detach(&state->dib7000p_ops);
1069 1070 1071
		return -ENODEV;
	}

1072
	adap->fe_adap[0].fe = state->dib7000p_ops.init(&adap->dev->i2c_adap, 0x80,
1073
		&dib7770p_dib7000p_config);
1074
	return adap->fe_adap[0].fe == NULL ? -ENODEV : 0;
1075 1076
}

1077 1078 1079 1080 1081 1082 1083 1084 1085 1086 1087 1088 1089 1090 1091 1092 1093 1094 1095 1096 1097 1098 1099 1100 1101 1102 1103 1104 1105 1106 1107 1108 1109 1110 1111 1112 1113 1114 1115 1116 1117 1118 1119 1120 1121 1122 1123 1124 1125 1126 1127 1128 1129 1130 1131 1132 1133 1134 1135 1136 1137 1138 1139 1140 1141 1142 1143 1144 1145 1146 1147 1148 1149 1150 1151 1152 1153 1154 1155 1156 1157 1158 1159 1160 1161 1162 1163 1164 1165 1166 1167 1168 1169 1170 1171 1172 1173 1174 1175 1176 1177 1178 1179 1180 1181 1182 1183 1184 1185 1186 1187 1188 1189 1190 1191 1192 1193 1194 1195 1196 1197 1198 1199 1200 1201 1202 1203 1204 1205 1206 1207 1208 1209 1210 1211 1212 1213 1214 1215 1216 1217
/* DIB807x generic */
static struct dibx000_agc_config dib807x_agc_config[2] = {
	{
		BAND_VHF,
		/* P_agc_use_sd_mod1=0, P_agc_use_sd_mod2=0,
		 * P_agc_freq_pwm_div=1, P_agc_inv_pwm1=0,
		 * P_agc_inv_pwm2=0,P_agc_inh_dc_rv_est=0,
		 * P_agc_time_est=3, P_agc_freeze=0, P_agc_nb_est=5,
		 * P_agc_write=0 */
		(0 << 15) | (0 << 14) | (7 << 11) | (0 << 10) | (0 << 9) |
			(0 << 8) | (3 << 5) | (0 << 4) | (5 << 1) |
			(0 << 0), /* setup*/

		600, /* inv_gain*/
		10,  /* time_stabiliz*/

		0,  /* alpha_level*/
		118,  /* thlock*/

		0,     /* wbd_inv*/
		3530,  /* wbd_ref*/
		1,     /* wbd_sel*/
		5,     /* wbd_alpha*/

		65535,  /* agc1_max*/
		0,  /* agc1_min*/

		65535,  /* agc2_max*/
		0,      /* agc2_min*/

		0,      /* agc1_pt1*/
		40,     /* agc1_pt2*/
		183,    /* agc1_pt3*/
		206,    /* agc1_slope1*/
		255,    /* agc1_slope2*/
		72,     /* agc2_pt1*/
		152,    /* agc2_pt2*/
		88,     /* agc2_slope1*/
		90,     /* agc2_slope2*/

		17,  /* alpha_mant*/
		27,  /* alpha_exp*/
		23,  /* beta_mant*/
		51,  /* beta_exp*/

		0,  /* perform_agc_softsplit*/
	}, {
		BAND_UHF,
		/* P_agc_use_sd_mod1=0, P_agc_use_sd_mod2=0,
		 * P_agc_freq_pwm_div=1, P_agc_inv_pwm1=0,
		 * P_agc_inv_pwm2=0, P_agc_inh_dc_rv_est=0,
		 * P_agc_time_est=3, P_agc_freeze=0, P_agc_nb_est=5,
		 * P_agc_write=0 */
		(0 << 15) | (0 << 14) | (1 << 11) | (0 << 10) | (0 << 9) |
			(0 << 8) | (3 << 5) | (0 << 4) | (5 << 1) |
			(0 << 0), /* setup */

		600, /* inv_gain*/
		10,  /* time_stabiliz*/

		0,  /* alpha_level*/
		118,  /* thlock*/

		0,     /* wbd_inv*/
		3530,  /* wbd_ref*/
		1,     /* wbd_sel*/
		5,     /* wbd_alpha*/

		65535,  /* agc1_max*/
		0,  /* agc1_min*/

		65535,  /* agc2_max*/
		0,      /* agc2_min*/

		0,      /* agc1_pt1*/
		40,     /* agc1_pt2*/
		183,    /* agc1_pt3*/
		206,    /* agc1_slope1*/
		255,    /* agc1_slope2*/
		72,     /* agc2_pt1*/
		152,    /* agc2_pt2*/
		88,     /* agc2_slope1*/
		90,     /* agc2_slope2*/

		17,  /* alpha_mant*/
		27,  /* alpha_exp*/
		23,  /* beta_mant*/
		51,  /* beta_exp*/

		0,  /* perform_agc_softsplit*/
	}
};

static struct dibx000_bandwidth_config dib807x_bw_config_12_mhz = {
	60000, 15000, /* internal, sampling*/
	1, 20, 3, 1, 0, /* pll_cfg: prediv, ratio, range, reset, bypass*/
	0, 0, 1, 1, 2, /* misc: refdiv, bypclk_div, IO_CLK_en_core,
			  ADClkSrc, modulo */
	(3 << 14) | (1 << 12) | (599 << 0), /* sad_cfg: refsel, sel, freq_15k*/
	(0 << 25) | 0, /* ifreq = 0.000000 MHz*/
	18179755, /* timf*/
	12000000, /* xtal_hz*/
};

static struct dib8000_config dib807x_dib8000_config[2] = {
	{
		.output_mpeg2_in_188_bytes = 1,

		.agc_config_count = 2,
		.agc = dib807x_agc_config,
		.pll = &dib807x_bw_config_12_mhz,
		.tuner_is_baseband = 1,

		.gpio_dir = DIB8000_GPIO_DEFAULT_DIRECTIONS,
		.gpio_val = DIB8000_GPIO_DEFAULT_VALUES,
		.gpio_pwm_pos = DIB8000_GPIO_DEFAULT_PWM_POS,

		.hostbus_diversity = 1,
		.div_cfg = 1,
		.agc_control = &dib0070_ctrl_agc_filter,
		.output_mode = OUTMODE_MPEG2_FIFO,
		.drives = 0x2d98,
	}, {
		.output_mpeg2_in_188_bytes = 1,

		.agc_config_count = 2,
		.agc = dib807x_agc_config,
		.pll = &dib807x_bw_config_12_mhz,
		.tuner_is_baseband = 1,

		.gpio_dir = DIB8000_GPIO_DEFAULT_DIRECTIONS,
		.gpio_val = DIB8000_GPIO_DEFAULT_VALUES,
		.gpio_pwm_pos = DIB8000_GPIO_DEFAULT_PWM_POS,

		.hostbus_diversity = 1,
		.agc_control = &dib0070_ctrl_agc_filter,
		.output_mode = OUTMODE_MPEG2_FIFO,
		.drives = 0x2d98,
	}
};

1218
static int dib80xx_tuner_reset(struct dvb_frontend *fe, int onoff)
1219
{
1220 1221 1222 1223
	struct dvb_usb_adapter *adap = fe->dvb->priv;
	struct dib0700_adapter_state *state = adap->priv;

	return state->dib8000_ops.set_gpio(fe, 5, 0, !onoff);
1224 1225
}

1226
static int dib80xx_tuner_sleep(struct dvb_frontend *fe, int onoff)
1227
{
1228 1229 1230 1231
	struct dvb_usb_adapter *adap = fe->dvb->priv;
	struct dib0700_adapter_state *state = adap->priv;

	return state->dib8000_ops.set_gpio(fe, 0, 0, onoff);
1232 1233 1234 1235 1236 1237 1238 1239 1240 1241
}

static const struct dib0070_wbd_gain_cfg dib8070_wbd_gain_cfg[] = {
    { 240,      7},
    { 0xffff,   6},
};

static struct dib0070_config dib807x_dib0070_config[2] = {
	{
		.i2c_address = DEFAULT_DIB0070_I2C_ADDRESS,
1242 1243
		.reset = dib80xx_tuner_reset,
		.sleep = dib80xx_tuner_sleep,
1244 1245 1246 1247 1248 1249 1250 1251 1252 1253 1254 1255
		.clock_khz = 12000,
		.clock_pad_drive = 4,
		.vga_filter = 1,
		.force_crystal_mode = 1,
		.enable_third_order_filter = 1,
		.charge_pump = 0,
		.wbd_gain = dib8070_wbd_gain_cfg,
		.osc_buffer_state = 0,
		.freq_offset_khz_uhf = -100,
		.freq_offset_khz_vhf = -100,
	}, {
		.i2c_address = DEFAULT_DIB0070_I2C_ADDRESS,
1256 1257
		.reset = dib80xx_tuner_reset,
		.sleep = dib80xx_tuner_sleep,
1258 1259 1260 1261 1262 1263 1264 1265 1266 1267 1268 1269 1270
		.clock_khz = 12000,
		.clock_pad_drive = 2,
		.vga_filter = 1,
		.force_crystal_mode = 1,
		.enable_third_order_filter = 1,
		.charge_pump = 0,
		.wbd_gain = dib8070_wbd_gain_cfg,
		.osc_buffer_state = 0,
		.freq_offset_khz_uhf = -25,
		.freq_offset_khz_vhf = -25,
	}
};

1271
static int dib807x_set_param_override(struct dvb_frontend *fe)
1272
{
1273
	struct dtv_frontend_properties *p = &fe->dtv_property_cache;
1274 1275 1276 1277
	struct dvb_usb_adapter *adap = fe->dvb->priv;
	struct dib0700_adapter_state *state = adap->priv;

	u16 offset = dib0070_wbd_offset(fe);
1278
	u8 band = BAND_OF_FREQUENCY(p->frequency/1000);
1279 1280 1281 1282 1283 1284 1285 1286 1287
	switch (band) {
	case BAND_VHF:
		offset += 750;
		break;
	case BAND_UHF:  /* fall-thru wanted */
	default:
		offset += 250; break;
	}
	deb_info("WBD for DiB8000: %d\n", offset);
1288
	state->dib8000_ops.set_wbd_ref(fe, offset);
1289

1290
	return state->set_param_save(fe);
1291 1292 1293 1294 1295
}

static int dib807x_tuner_attach(struct dvb_usb_adapter *adap)
{
	struct dib0700_adapter_state *st = adap->priv;
1296
	struct i2c_adapter *tun_i2c = st->dib8000_ops.get_i2c_master(adap->fe_adap[0].fe,
1297 1298 1299
			DIBX000_I2C_INTERFACE_TUNER, 1);

	if (adap->id == 0) {
1300
		if (dvb_attach(dib0070_attach, adap->fe_adap[0].fe, tun_i2c,
1301 1302 1303
				&dib807x_dib0070_config[0]) == NULL)
			return -ENODEV;
	} else {
1304
		if (dvb_attach(dib0070_attach, adap->fe_adap[0].fe, tun_i2c,
1305 1306 1307 1308
				&dib807x_dib0070_config[1]) == NULL)
			return -ENODEV;
	}

1309 1310
	st->set_param_save = adap->fe_adap[0].fe->ops.tuner_ops.set_params;
	adap->fe_adap[0].fe->ops.tuner_ops.set_params = dib807x_set_param_override;
1311 1312 1313
	return 0;
}

1314 1315
static int stk80xx_pid_filter(struct dvb_usb_adapter *adapter, int index,
	u16 pid, int onoff)
1316
{
1317 1318 1319
	struct dib0700_adapter_state *state = adapter->priv;

	return state->dib8000_ops.pid_filter(adapter->fe_adap[0].fe, index, pid, onoff);
1320 1321
}

1322
static int stk80xx_pid_filter_ctrl(struct dvb_usb_adapter *adapter,
1323
		int onoff)
1324
{
1325 1326 1327
	struct dib0700_adapter_state *state = adapter->priv;

	return state->dib8000_ops.pid_filter_ctrl(adapter->fe_adap[0].fe, onoff);
1328
}
1329 1330 1331 1332

/* STK807x */
static int stk807x_frontend_attach(struct dvb_usb_adapter *adap)
{
1333 1334 1335 1336 1337
	struct dib0700_adapter_state *state = adap->priv;

	if (!dvb_attach(dib8000_attach, &state->dib8000_ops))
		return -ENODEV;

1338 1339 1340 1341 1342 1343 1344 1345 1346 1347 1348 1349 1350 1351 1352
	dib0700_set_gpio(adap->dev, GPIO6, GPIO_OUT, 1);
	msleep(10);
	dib0700_set_gpio(adap->dev, GPIO9, GPIO_OUT, 1);
	dib0700_set_gpio(adap->dev, GPIO4, GPIO_OUT, 1);
	dib0700_set_gpio(adap->dev, GPIO7, GPIO_OUT, 1);

	dib0700_set_gpio(adap->dev, GPIO10, GPIO_OUT, 0);

	dib0700_ctrl_clock(adap->dev, 72, 1);

	msleep(10);
	dib0700_set_gpio(adap->dev, GPIO10, GPIO_OUT, 1);
	msleep(10);
	dib0700_set_gpio(adap->dev, GPIO0, GPIO_OUT, 1);

1353
	state->dib8000_ops.i2c_enumeration(&adap->dev->i2c_adap, 1, 18,
1354
				0x80, 0);
1355

1356
	adap->fe_adap[0].fe = state->dib8000_ops.init(&adap->dev->i2c_adap, 0x80,
1357 1358
			      &dib807x_dib8000_config[0]);

1359
	return adap->fe_adap[0].fe == NULL ?  -ENODEV : 0;
1360 1361 1362 1363 1364
}

/* STK807xPVR */
static int stk807xpvr_frontend_attach0(struct dvb_usb_adapter *adap)
{
1365 1366 1367 1368 1369
	struct dib0700_adapter_state *state = adap->priv;

	if (!dvb_attach(dib8000_attach, &state->dib8000_ops))
		return -ENODEV;

1370 1371 1372 1373 1374 1375 1376 1377 1378 1379 1380 1381 1382 1383 1384 1385 1386 1387
	dib0700_set_gpio(adap->dev, GPIO6, GPIO_OUT, 0);
	msleep(30);
	dib0700_set_gpio(adap->dev, GPIO6, GPIO_OUT, 1);
	msleep(500);
	dib0700_set_gpio(adap->dev, GPIO9, GPIO_OUT, 1);
	dib0700_set_gpio(adap->dev, GPIO4, GPIO_OUT, 1);
	dib0700_set_gpio(adap->dev, GPIO7, GPIO_OUT, 1);

	dib0700_set_gpio(adap->dev, GPIO10, GPIO_OUT, 0);

	dib0700_ctrl_clock(adap->dev, 72, 1);

	msleep(10);
	dib0700_set_gpio(adap->dev, GPIO10, GPIO_OUT, 1);
	msleep(10);
	dib0700_set_gpio(adap->dev, GPIO0, GPIO_OUT, 1);

	/* initialize IC 0 */
1388
	state->dib8000_ops.i2c_enumeration(&adap->dev->i2c_adap, 1, 0x22, 0x80, 0);
1389

1390
	adap->fe_adap[0].fe = state->dib8000_ops.init(&adap->dev->i2c_adap, 0x80,
1391 1392
			      &dib807x_dib8000_config[0]);

1393
	return adap->fe_adap[0].fe == NULL ? -ENODEV : 0;
1394 1395 1396 1397
}

static int stk807xpvr_frontend_attach1(struct dvb_usb_adapter *adap)
{
1398 1399 1400 1401 1402
	struct dib0700_adapter_state *state = adap->priv;

	if (!dvb_attach(dib8000_attach, &state->dib8000_ops))
		return -ENODEV;

1403
	/* initialize IC 1 */
1404
	state->dib8000_ops.i2c_enumeration(&adap->dev->i2c_adap, 1, 0x12, 0x82, 0);
1405

1406
	adap->fe_adap[0].fe = state->dib8000_ops.init(&adap->dev->i2c_adap, 0x82,
1407 1408
			      &dib807x_dib8000_config[1]);

1409
	return adap->fe_adap[0].fe == NULL ? -ENODEV : 0;
1410 1411
}

1412
/* STK8096GP */
O
Olivier Grenie 已提交
1413
static struct dibx000_agc_config dib8090_agc_config[2] = {
1414
	{
1415
	.band_caps = BAND_UHF | BAND_VHF | BAND_LBAND | BAND_SBAND,
1416
	/* P_agc_use_sd_mod1=0, P_agc_use_sd_mod2=0, P_agc_freq_pwm_div=1,
1417 1418
	 * P_agc_inv_pwm1=0, P_agc_inv_pwm2=0, P_agc_inh_dc_rv_est=0,
	 * P_agc_time_est=3, P_agc_freeze=0, P_agc_nb_est=5, P_agc_write=0 */
1419
	.setup = (0 << 15) | (0 << 14) | (5 << 11) | (0 << 10) | (0 << 9) | (0 << 8)
1420 1421
	| (3 << 5) | (0 << 4) | (5 << 1) | (0 << 0),

1422 1423
	.inv_gain = 787,
	.time_stabiliz = 10,
1424

1425 1426
	.alpha_level = 0,
	.thlock = 118,
1427

1428 1429 1430 1431
	.wbd_inv = 0,
	.wbd_ref = 3530,
	.wbd_sel = 1,
	.wbd_alpha = 5,
1432

1433 1434
	.agc1_max = 65535,
	.agc1_min = 0,
1435

1436 1437
	.agc2_max = 65535,
	.agc2_min = 0,
1438

1439 1440 1441 1442 1443 1444 1445 1446 1447 1448 1449 1450 1451 1452 1453 1454
	.agc1_pt1 = 0,
	.agc1_pt2 = 32,
	.agc1_pt3 = 114,
	.agc1_slope1 = 143,
	.agc1_slope2 = 144,
	.agc2_pt1 = 114,
	.agc2_pt2 = 227,
	.agc2_slope1 = 116,
	.agc2_slope2 = 117,

	.alpha_mant = 28,
	.alpha_exp = 26,
	.beta_mant = 31,
	.beta_exp = 51,

	.perform_agc_softsplit = 0,
1455 1456
	},
	{
1457
	.band_caps = BAND_CBAND,
1458
	/* P_agc_use_sd_mod1=0, P_agc_use_sd_mod2=0, P_agc_freq_pwm_div=1,
1459 1460
	 * P_agc_inv_pwm1=0, P_agc_inv_pwm2=0, P_agc_inh_dc_rv_est=0,
	 * P_agc_time_est=3, P_agc_freeze=0, P_agc_nb_est=5, P_agc_write=0 */
1461
	.setup = (0 << 15) | (0 << 14) | (5 << 11) | (0 << 10) | (0 << 9) | (0 << 8)
1462 1463
	| (3 << 5) | (0 << 4) | (5 << 1) | (0 << 0),

1464 1465
	.inv_gain = 787,
	.time_stabiliz = 10,
1466

1467 1468
	.alpha_level = 0,
	.thlock = 118,
1469

1470 1471 1472 1473
	.wbd_inv = 0,
	.wbd_ref = 3530,
	.wbd_sel = 1,
	.wbd_alpha = 5,
1474

1475 1476
	.agc1_max = 0,
	.agc1_min = 0,
1477

1478 1479
	.agc2_max = 65535,
	.agc2_min = 0,
1480

1481 1482 1483 1484 1485 1486 1487 1488 1489 1490 1491 1492 1493 1494 1495 1496
	.agc1_pt1 = 0,
	.agc1_pt2 = 32,
	.agc1_pt3 = 114,
	.agc1_slope1 = 143,
	.agc1_slope2 = 144,
	.agc2_pt1 = 114,
	.agc2_pt2 = 227,
	.agc2_slope1 = 116,
	.agc2_slope2 = 117,

	.alpha_mant = 28,
	.alpha_exp = 26,
	.beta_mant = 31,
	.beta_exp = 51,

	.perform_agc_softsplit = 0,
1497
	}
1498 1499 1500
};

static struct dibx000_bandwidth_config dib8090_pll_config_12mhz = {
1501 1502 1503 1504 1505 1506 1507 1508 1509 1510 1511 1512 1513 1514 1515 1516 1517 1518 1519 1520 1521
	.internal = 54000,
	.sampling = 13500,

	.pll_prediv = 1,
	.pll_ratio = 18,
	.pll_range = 3,
	.pll_reset = 1,
	.pll_bypass = 0,

	.enable_refdiv = 0,
	.bypclk_div = 0,
	.IO_CLK_en_core = 1,
	.ADClkSrc = 1,
	.modulo = 2,

	.sad_cfg = (3 << 14) | (1 << 12) | (599 << 0),

	.ifreq = (0 << 25) | 0,
	.timf = 20199727,

	.xtal_hz = 12000000,
1522 1523 1524 1525
};

static int dib8090_get_adc_power(struct dvb_frontend *fe)
{
1526 1527 1528 1529
	struct dvb_usb_adapter *adap = fe->dvb->priv;
	struct dib0700_adapter_state *state = adap->priv;

	return state->dib8000_ops.get_adc_power(fe, 1);
1530 1531
}

O
Olivier Grenie 已提交
1532 1533 1534 1535 1536 1537 1538 1539 1540
static void dib8090_agc_control(struct dvb_frontend *fe, u8 restart)
{
	deb_info("AGC control callback: %i\n", restart);
	dib0090_dcc_freq(fe, restart);

	if (restart == 0) /* before AGC startup */
		dib0090_set_dc_servo(fe, 1);
}

1541 1542 1543 1544 1545 1546
static struct dib8000_config dib809x_dib8000_config[2] = {
	{
	.output_mpeg2_in_188_bytes = 1,

	.agc_config_count = 2,
	.agc = dib8090_agc_config,
O
Olivier Grenie 已提交
1547
	.agc_control = dib8090_agc_control,
1548 1549 1550 1551 1552 1553 1554 1555 1556 1557 1558 1559 1560
	.pll = &dib8090_pll_config_12mhz,
	.tuner_is_baseband = 1,

	.gpio_dir = DIB8000_GPIO_DEFAULT_DIRECTIONS,
	.gpio_val = DIB8000_GPIO_DEFAULT_VALUES,
	.gpio_pwm_pos = DIB8000_GPIO_DEFAULT_PWM_POS,

	.hostbus_diversity = 1,
	.div_cfg = 0x31,
	.output_mode = OUTMODE_MPEG2_FIFO,
	.drives = 0x2d98,
	.diversity_delay = 48,
	.refclksel = 3,
1561
	}, {
1562 1563 1564 1565
	.output_mpeg2_in_188_bytes = 1,

	.agc_config_count = 2,
	.agc = dib8090_agc_config,
O
Olivier Grenie 已提交
1566
	.agc_control = dib8090_agc_control,
1567 1568 1569 1570 1571 1572 1573 1574 1575 1576 1577 1578 1579 1580 1581 1582 1583 1584 1585 1586 1587 1588 1589 1590 1591 1592 1593 1594 1595 1596 1597 1598 1599 1600 1601 1602 1603 1604 1605 1606 1607 1608 1609 1610 1611 1612 1613
	.pll = &dib8090_pll_config_12mhz,
	.tuner_is_baseband = 1,

	.gpio_dir = DIB8000_GPIO_DEFAULT_DIRECTIONS,
	.gpio_val = DIB8000_GPIO_DEFAULT_VALUES,
	.gpio_pwm_pos = DIB8000_GPIO_DEFAULT_PWM_POS,

	.hostbus_diversity = 1,
	.div_cfg = 0x31,
	.output_mode = OUTMODE_DIVERSITY,
	.drives = 0x2d08,
	.diversity_delay = 1,
	.refclksel = 3,
	}
};

static struct dib0090_wbd_slope dib8090_wbd_table[] = {
	/* max freq ; cold slope ; cold offset ; warm slope ; warm offset ; wbd gain */
	{ 120,     0, 500,  0,   500, 4 }, /* CBAND */
	{ 170,     0, 450,  0,   450, 4 }, /* CBAND */
	{ 380,    48, 373, 28,   259, 6 }, /* VHF */
	{ 860,    34, 700, 36,   616, 6 }, /* high UHF */
	{ 0xFFFF, 34, 700, 36,   616, 6 }, /* default */
};

static struct dib0090_config dib809x_dib0090_config = {
	.io.pll_bypass = 1,
	.io.pll_range = 1,
	.io.pll_prediv = 1,
	.io.pll_loopdiv = 20,
	.io.adc_clock_ratio = 8,
	.io.pll_int_loop_filt = 0,
	.io.clock_khz = 12000,
	.reset = dib80xx_tuner_reset,
	.sleep = dib80xx_tuner_sleep,
	.clkouttobamse = 1,
	.analog_output = 1,
	.i2c_address = DEFAULT_DIB0090_I2C_ADDRESS,
	.use_pwm_agc = 1,
	.clkoutdrive = 1,
	.get_adc_power = dib8090_get_adc_power,
	.freq_offset_khz_uhf = -63,
	.freq_offset_khz_vhf = -143,
	.wbd = dib8090_wbd_table,
	.fref_clock_ratio = 6,
};

O
Olivier Grenie 已提交
1614 1615 1616 1617 1618 1619 1620 1621 1622 1623 1624 1625 1626 1627 1628 1629 1630 1631 1632 1633 1634 1635 1636 1637
static u8 dib8090_compute_pll_parameters(struct dvb_frontend *fe)
{
	u8 optimal_pll_ratio = 20;
	u32 freq_adc, ratio, rest, max = 0;
	u8 pll_ratio;

	for (pll_ratio = 17; pll_ratio <= 20; pll_ratio++) {
		freq_adc = 12 * pll_ratio * (1 << 8) / 16;
		ratio = ((fe->dtv_property_cache.frequency / 1000) * (1 << 8) / 1000) / freq_adc;
		rest = ((fe->dtv_property_cache.frequency / 1000) * (1 << 8) / 1000) - ratio * freq_adc;

		if (rest > freq_adc / 2)
			rest = freq_adc - rest;
		deb_info("PLL ratio=%i rest=%i\n", pll_ratio, rest);
		if ((rest > max) && (rest > 717)) {
			optimal_pll_ratio = pll_ratio;
			max = rest;
		}
	}
	deb_info("optimal PLL ratio=%i\n", optimal_pll_ratio);

	return optimal_pll_ratio;
}

1638
static int dib8096_set_param_override(struct dvb_frontend *fe)
1639 1640 1641
{
	struct dvb_usb_adapter *adap = fe->dvb->priv;
	struct dib0700_adapter_state *state = adap->priv;
O
Olivier Grenie 已提交
1642 1643 1644
	u8 pll_ratio, band = BAND_OF_FREQUENCY(fe->dtv_property_cache.frequency / 1000);
	u16 target, ltgain, rf_gain_limit;
	u32 timf;
1645 1646
	int ret = 0;
	enum frontend_tune_state tune_state = CT_SHUTDOWN;
O
Olivier Grenie 已提交
1647 1648 1649 1650 1651

	switch (band) {
	default:
			deb_info("Warning : Rf frequency  (%iHz) is not in the supported range, using VHF switch ", fe->dtv_property_cache.frequency);
	case BAND_VHF:
1652
			state->dib8000_ops.set_gpio(fe, 3, 0, 1);
O
Olivier Grenie 已提交
1653 1654
			break;
	case BAND_UHF:
1655
			state->dib8000_ops.set_gpio(fe, 3, 0, 0);
O
Olivier Grenie 已提交
1656 1657
			break;
	}
1658

1659
	ret = state->set_param_save(fe);
1660 1661 1662
	if (ret < 0)
		return ret;

O
Olivier Grenie 已提交
1663 1664 1665 1666 1667 1668
	if (fe->dtv_property_cache.bandwidth_hz != 6000000) {
		deb_info("only 6MHz bandwidth is supported\n");
		return -EINVAL;
	}

	/** Update PLL if needed ratio **/
1669
	state->dib8000_ops.update_pll(fe, &dib8090_pll_config_12mhz, fe->dtv_property_cache.bandwidth_hz / 1000, 0);
O
Olivier Grenie 已提交
1670 1671 1672 1673 1674 1675 1676 1677 1678 1679 1680

	/** Get optimize PLL ratio to remove spurious **/
	pll_ratio = dib8090_compute_pll_parameters(fe);
	if (pll_ratio == 17)
		timf = 21387946;
	else if (pll_ratio == 18)
		timf = 20199727;
	else if (pll_ratio == 19)
		timf = 19136583;
	else
		timf = 18179756;
1681

O
Olivier Grenie 已提交
1682
	/** Update ratio **/
1683
	state->dib8000_ops.update_pll(fe, &dib8090_pll_config_12mhz, fe->dtv_property_cache.bandwidth_hz / 1000, pll_ratio);
O
Olivier Grenie 已提交
1684

1685
	state->dib8000_ops.ctrl_timf(fe, DEMOD_TIMF_SET, timf);
O
Olivier Grenie 已提交
1686 1687 1688 1689

	if (band != BAND_CBAND) {
		/* dib0090_get_wbd_target is returning any possible temperature compensated wbd-target */
		target = (dib0090_get_wbd_target(fe) * 8 * 18 / 33 + 1) / 2;
1690
		state->dib8000_ops.set_wbd_ref(fe, target);
O
Olivier Grenie 已提交
1691
	}
1692 1693

	if (band == BAND_CBAND) {
1694 1695
		deb_info("tuning in CBAND - soft-AGC startup\n");
		dib0090_set_tune_state(fe, CT_AGC_START);
O
Olivier Grenie 已提交
1696

1697 1698 1699 1700 1701
		do {
			ret = dib0090_gain_control(fe);
			msleep(ret);
			tune_state = dib0090_get_tune_state(fe);
			if (tune_state == CT_AGC_STEP_0)
1702
				state->dib8000_ops.set_gpio(fe, 6, 0, 1);
1703 1704
			else if (tune_state == CT_AGC_STEP_1) {
				dib0090_get_current_gain(fe, NULL, NULL, &rf_gain_limit, &ltgain);
O
Olivier Grenie 已提交
1705
				if (rf_gain_limit < 2000) /* activate the external attenuator in case of very high input power */
1706
					state->dib8000_ops.set_gpio(fe, 6, 0, 0);
1707 1708
			}
		} while (tune_state < CT_AGC_STOP);
O
Olivier Grenie 已提交
1709 1710

		deb_info("switching to PWM AGC\n");
1711
		dib0090_pwm_gain_reset(fe);
1712 1713
		state->dib8000_ops.pwm_agc_reset(fe);
		state->dib8000_ops.set_tune_state(fe, CT_DEMOD_START);
1714
	} else {
O
Olivier Grenie 已提交
1715
		/* for everything else than CBAND we are using standard AGC */
1716 1717
		deb_info("not tuning in CBAND - standard AGC startup\n");
		dib0090_pwm_gain_reset(fe);
1718 1719 1720 1721 1722 1723 1724 1725
	}

	return 0;
}

static int dib809x_tuner_attach(struct dvb_usb_adapter *adap)
{
	struct dib0700_adapter_state *st = adap->priv;
1726
	struct i2c_adapter *tun_i2c = st->dib8000_ops.get_i2c_master(adap->fe_adap[0].fe, DIBX000_I2C_INTERFACE_TUNER, 1);
1727

1728
	if (dvb_attach(dib0090_register, adap->fe_adap[0].fe, tun_i2c, &dib809x_dib0090_config) == NULL)
1729 1730
		return -ENODEV;

1731 1732
	st->set_param_save = adap->fe_adap[0].fe->ops.tuner_ops.set_params;
	adap->fe_adap[0].fe->ops.tuner_ops.set_params = dib8096_set_param_override;
1733 1734 1735 1736 1737
	return 0;
}

static int stk809x_frontend_attach(struct dvb_usb_adapter *adap)
{
1738 1739 1740 1741 1742
	struct dib0700_adapter_state *state = adap->priv;

	if (!dvb_attach(dib8000_attach, &state->dib8000_ops))
		return -ENODEV;

1743 1744 1745 1746 1747 1748 1749 1750 1751 1752 1753 1754 1755 1756 1757
	dib0700_set_gpio(adap->dev, GPIO6, GPIO_OUT, 1);
	msleep(10);
	dib0700_set_gpio(adap->dev, GPIO9, GPIO_OUT, 1);
	dib0700_set_gpio(adap->dev, GPIO4, GPIO_OUT, 1);
	dib0700_set_gpio(adap->dev, GPIO7, GPIO_OUT, 1);

	dib0700_set_gpio(adap->dev, GPIO10, GPIO_OUT, 0);

	dib0700_ctrl_clock(adap->dev, 72, 1);

	msleep(10);
	dib0700_set_gpio(adap->dev, GPIO10, GPIO_OUT, 1);
	msleep(10);
	dib0700_set_gpio(adap->dev, GPIO0, GPIO_OUT, 1);

1758
	state->dib8000_ops.i2c_enumeration(&adap->dev->i2c_adap, 1, 18, 0x80, 0);
1759

1760
	adap->fe_adap[0].fe = state->dib8000_ops.init(&adap->dev->i2c_adap, 0x80, &dib809x_dib8000_config[0]);
1761

1762
	return adap->fe_adap[0].fe == NULL ?  -ENODEV : 0;
1763 1764 1765 1766 1767 1768
}

static int nim8096md_tuner_attach(struct dvb_usb_adapter *adap)
{
	struct dib0700_adapter_state *st = adap->priv;
	struct i2c_adapter *tun_i2c;
1769
	struct dvb_frontend *fe_slave  = st->dib8000_ops.get_slave_frontend(adap->fe_adap[0].fe, 1);
1770 1771

	if (fe_slave) {
1772
		tun_i2c = st->dib8000_ops.get_i2c_master(fe_slave, DIBX000_I2C_INTERFACE_TUNER, 1);
1773 1774
		if (dvb_attach(dib0090_register, fe_slave, tun_i2c, &dib809x_dib0090_config) == NULL)
			return -ENODEV;
1775
		fe_slave->dvb = adap->fe_adap[0].fe->dvb;
1776 1777
		fe_slave->ops.tuner_ops.set_params = dib8096_set_param_override;
	}
1778
	tun_i2c = st->dib8000_ops.get_i2c_master(adap->fe_adap[0].fe, DIBX000_I2C_INTERFACE_TUNER, 1);
1779
	if (dvb_attach(dib0090_register, adap->fe_adap[0].fe, tun_i2c, &dib809x_dib0090_config) == NULL)
1780 1781
		return -ENODEV;

1782 1783
	st->set_param_save = adap->fe_adap[0].fe->ops.tuner_ops.set_params;
	adap->fe_adap[0].fe->ops.tuner_ops.set_params = dib8096_set_param_override;
1784 1785 1786 1787 1788 1789 1790

	return 0;
}

static int nim8096md_frontend_attach(struct dvb_usb_adapter *adap)
{
	struct dvb_frontend *fe_slave;
1791 1792 1793 1794
	struct dib0700_adapter_state *state = adap->priv;

	if (!dvb_attach(dib8000_attach, &state->dib8000_ops))
		return -ENODEV;
1795 1796

	dib0700_set_gpio(adap->dev, GPIO6, GPIO_OUT, 0);
1797
	msleep(20);
1798 1799 1800 1801 1802 1803 1804 1805 1806 1807
	dib0700_set_gpio(adap->dev, GPIO6, GPIO_OUT, 1);
	msleep(1000);
	dib0700_set_gpio(adap->dev, GPIO9, GPIO_OUT, 1);
	dib0700_set_gpio(adap->dev, GPIO4, GPIO_OUT, 1);
	dib0700_set_gpio(adap->dev, GPIO7, GPIO_OUT, 1);

	dib0700_set_gpio(adap->dev, GPIO10, GPIO_OUT, 0);

	dib0700_ctrl_clock(adap->dev, 72, 1);

1808
	msleep(20);
1809
	dib0700_set_gpio(adap->dev, GPIO10, GPIO_OUT, 1);
1810
	msleep(20);
1811 1812
	dib0700_set_gpio(adap->dev, GPIO0, GPIO_OUT, 1);

1813
	state->dib8000_ops.i2c_enumeration(&adap->dev->i2c_adap, 2, 18, 0x80, 0);
1814

1815
	adap->fe_adap[0].fe = state->dib8000_ops.init(&adap->dev->i2c_adap, 0x80, &dib809x_dib8000_config[0]);
1816
	if (adap->fe_adap[0].fe == NULL)
1817 1818
		return -ENODEV;

1819 1820 1821 1822 1823 1824
	/* Needed to increment refcount */
	if (!dvb_attach(dib8000_attach, &state->dib8000_ops))
		return -ENODEV;

	fe_slave = state->dib8000_ops.init(&adap->dev->i2c_adap, 0x82, &dib809x_dib8000_config[1]);
	state->dib8000_ops.set_slave_frontend(adap->fe_adap[0].fe, fe_slave);
1825 1826 1827 1828

	return fe_slave == NULL ?  -ENODEV : 0;
}

1829 1830 1831 1832 1833 1834 1835 1836 1837 1838 1839 1840 1841 1842 1843 1844 1845 1846 1847 1848 1849 1850 1851 1852 1853 1854 1855 1856 1857 1858 1859 1860 1861 1862 1863 1864 1865 1866 1867 1868 1869 1870 1871 1872 1873 1874 1875 1876 1877 1878 1879 1880 1881 1882 1883 1884 1885 1886 1887 1888 1889 1890 1891 1892 1893 1894 1895 1896 1897 1898 1899 1900 1901 1902 1903 1904 1905 1906 1907 1908 1909 1910 1911 1912 1913 1914 1915 1916 1917 1918 1919 1920 1921 1922 1923 1924 1925 1926 1927 1928 1929 1930 1931 1932 1933 1934 1935 1936 1937 1938 1939 1940 1941 1942 1943 1944 1945 1946 1947 1948 1949 1950 1951 1952 1953 1954 1955 1956 1957 1958
/* TFE8096P */
static struct dibx000_agc_config dib8096p_agc_config[2] = {
	{
		.band_caps		= BAND_UHF,
		/* P_agc_use_sd_mod1=0, P_agc_use_sd_mod2=0,
		   P_agc_freq_pwm_div=1, P_agc_inv_pwm1=0,
		   P_agc_inv_pwm2=0, P_agc_inh_dc_rv_est=0,
		   P_agc_time_est=3, P_agc_freeze=0, P_agc_nb_est=5,
		   P_agc_write=0 */
		.setup			= (0 << 15) | (0 << 14) | (5 << 11)
			| (0 << 10) | (0 << 9) | (0 << 8) | (3 << 5)
			| (0 << 4) | (5 << 1) | (0 << 0),

		.inv_gain		= 684,
		.time_stabiliz	= 10,

		.alpha_level	= 0,
		.thlock			= 118,

		.wbd_inv		= 0,
		.wbd_ref		= 1200,
		.wbd_sel		= 3,
		.wbd_alpha		= 5,

		.agc1_max		= 65535,
		.agc1_min		= 0,

		.agc2_max		= 32767,
		.agc2_min		= 0,

		.agc1_pt1		= 0,
		.agc1_pt2		= 0,
		.agc1_pt3		= 105,
		.agc1_slope1	= 0,
		.agc1_slope2	= 156,
		.agc2_pt1		= 105,
		.agc2_pt2		= 255,
		.agc2_slope1	= 54,
		.agc2_slope2	= 0,

		.alpha_mant		= 28,
		.alpha_exp		= 26,
		.beta_mant		= 31,
		.beta_exp		= 51,

		.perform_agc_softsplit = 0,
	} , {
		.band_caps		= BAND_FM | BAND_VHF | BAND_CBAND,
		/* P_agc_use_sd_mod1=0, P_agc_use_sd_mod2=0,
		   P_agc_freq_pwm_div=1, P_agc_inv_pwm1=0,
		   P_agc_inv_pwm2=0, P_agc_inh_dc_rv_est=0,
		   P_agc_time_est=3, P_agc_freeze=0, P_agc_nb_est=5,
		   P_agc_write=0 */
		.setup			= (0 << 15) | (0 << 14) | (5 << 11)
			| (0 << 10) | (0 << 9) | (0 << 8) | (3 << 5)
			| (0 << 4) | (5 << 1) | (0 << 0),

		.inv_gain		= 732,
		.time_stabiliz  = 10,

		.alpha_level	= 0,
		.thlock			= 118,

		.wbd_inv		= 0,
		.wbd_ref		= 1200,
		.wbd_sel		= 3,
		.wbd_alpha		= 5,

		.agc1_max		= 65535,
		.agc1_min		= 0,

		.agc2_max		= 32767,
		.agc2_min		= 0,

		.agc1_pt1		= 0,
		.agc1_pt2		= 0,
		.agc1_pt3		= 98,
		.agc1_slope1	= 0,
		.agc1_slope2	= 167,
		.agc2_pt1		= 98,
		.agc2_pt2		= 255,
		.agc2_slope1	= 52,
		.agc2_slope2	= 0,

		.alpha_mant		= 28,
		.alpha_exp		= 26,
		.beta_mant		= 31,
		.beta_exp		= 51,

		.perform_agc_softsplit = 0,
	}
};

static struct dibx000_bandwidth_config dib8096p_clock_config_12_mhz = {
	108000, 13500,
	1, 9, 1, 0, 0,
	0, 0, 0, 0, 2,
	(3 << 14) | (1 << 12) | (524 << 0),
	(0 << 25) | 0,
	20199729,
	12000000,
};

static struct dib8000_config tfe8096p_dib8000_config = {
	.output_mpeg2_in_188_bytes	= 1,
	.hostbus_diversity			= 1,
	.update_lna					= NULL,

	.agc_config_count			= 2,
	.agc						= dib8096p_agc_config,
	.pll						= &dib8096p_clock_config_12_mhz,

	.gpio_dir					= DIB8000_GPIO_DEFAULT_DIRECTIONS,
	.gpio_val					= DIB8000_GPIO_DEFAULT_VALUES,
	.gpio_pwm_pos				= DIB8000_GPIO_DEFAULT_PWM_POS,

	.agc_control				= NULL,
	.diversity_delay			= 48,
	.output_mode				= OUTMODE_MPEG2_FIFO,
	.enMpegOutput				= 1,
};

static struct dib0090_wbd_slope dib8096p_wbd_table[] = {
	{ 380, 81, 850, 64, 540, 4},
	{ 860, 51, 866, 21, 375, 4},
	{1700, 0, 250, 0, 100, 6},
	{2600, 0, 250, 0, 100, 6},
	{ 0xFFFF, 0, 0, 0, 0, 0},
};

1959
static struct dib0090_config tfe8096p_dib0090_config = {
1960 1961 1962 1963 1964 1965 1966 1967 1968 1969 1970 1971 1972 1973 1974 1975 1976 1977 1978 1979 1980 1981 1982 1983 1984 1985 1986 1987 1988 1989 1990 1991 1992 1993 1994 1995 1996
	.io.clock_khz			= 12000,
	.io.pll_bypass			= 0,
	.io.pll_range			= 0,
	.io.pll_prediv			= 3,
	.io.pll_loopdiv			= 6,
	.io.adc_clock_ratio		= 0,
	.io.pll_int_loop_filt	= 0,

	.freq_offset_khz_uhf	= -143,
	.freq_offset_khz_vhf	= -143,

	.get_adc_power			= dib8090_get_adc_power,

	.clkouttobamse			= 1,
	.analog_output			= 0,

	.wbd_vhf_offset			= 0,
	.wbd_cband_offset		= 0,
	.use_pwm_agc			= 1,
	.clkoutdrive			= 0,

	.fref_clock_ratio		= 1,

	.ls_cfg_pad_drv			= 0,
	.data_tx_drv			= 0,
	.low_if					= NULL,
	.in_soc					= 1,
	.force_cband_input		= 0,
};

struct dibx090p_adc {
	u32 freq;			/* RF freq MHz */
	u32 timf;			/* New Timf */
	u32 pll_loopdiv;	/* New prediv */
	u32 pll_prediv;		/* New loopdiv */
};

O
Olivier Grenie 已提交
1997 1998 1999 2000
struct dibx090p_best_adc {
	u32 timf;
	u32 pll_loopdiv;
	u32 pll_prediv;
2001 2002
};

O
Olivier Grenie 已提交
2003 2004 2005 2006 2007 2008 2009 2010 2011 2012 2013 2014 2015 2016 2017 2018 2019 2020 2021 2022 2023 2024 2025 2026 2027 2028 2029 2030 2031 2032 2033 2034 2035 2036 2037 2038 2039 2040 2041 2042 2043 2044 2045 2046 2047 2048 2049 2050 2051 2052 2053 2054 2055 2056 2057 2058 2059 2060 2061 2062 2063 2064 2065 2066 2067 2068 2069 2070 2071 2072 2073 2074
static int dib8096p_get_best_sampling(struct dvb_frontend *fe, struct dibx090p_best_adc *adc)
{
	u8 spur = 0, prediv = 0, loopdiv = 0, min_prediv = 1, max_prediv = 1;
	u16 xtal = 12000;
	u16 fcp_min = 1900;  /* PLL, Minimum Frequency of phase comparator (KHz) */
	u16 fcp_max = 20000; /* PLL, Maximum Frequency of phase comparator (KHz) */
	u32 fmem_max = 140000; /* 140MHz max SDRAM freq */
	u32 fdem_min = 66000;
	u32 fcp = 0, fs = 0, fdem = 0, fmem = 0;
	u32 harmonic_id = 0;

	adc->timf = 0;
	adc->pll_loopdiv = loopdiv;
	adc->pll_prediv = prediv;

	deb_info("bandwidth = %d", fe->dtv_property_cache.bandwidth_hz);

	/* Find Min and Max prediv */
	while ((xtal / max_prediv) >= fcp_min)
		max_prediv++;

	max_prediv--;
	min_prediv = max_prediv;
	while ((xtal / min_prediv) <= fcp_max) {
		min_prediv--;
		if (min_prediv == 1)
			break;
	}
	deb_info("MIN prediv = %d : MAX prediv = %d", min_prediv, max_prediv);

	min_prediv = 1;

	for (prediv = min_prediv; prediv < max_prediv; prediv++) {
		fcp = xtal / prediv;
		if (fcp > fcp_min && fcp < fcp_max) {
			for (loopdiv = 1; loopdiv < 64; loopdiv++) {
				fmem = ((xtal/prediv) * loopdiv);
				fdem = fmem / 2;
				fs   = fdem / 4;

				/* test min/max system restrictions */
				if ((fdem >= fdem_min) && (fmem <= fmem_max) && (fs >= fe->dtv_property_cache.bandwidth_hz / 1000)) {
					spur = 0;
					/* test fs harmonics positions */
					for (harmonic_id = (fe->dtv_property_cache.frequency / (1000 * fs));  harmonic_id <= ((fe->dtv_property_cache.frequency / (1000 * fs)) + 1); harmonic_id++) {
						if (((fs * harmonic_id) >= (fe->dtv_property_cache.frequency / 1000 - (fe->dtv_property_cache.bandwidth_hz / 2000))) &&  ((fs * harmonic_id) <= (fe->dtv_property_cache.frequency / 1000 + (fe->dtv_property_cache.bandwidth_hz / 2000)))) {
							spur = 1;
							break;
						}
					}

					if (!spur) {
						adc->pll_loopdiv = loopdiv;
						adc->pll_prediv = prediv;
						adc->timf = (4260880253U / fdem) * (1 << 8);
						adc->timf += ((4260880253U % fdem) << 8) / fdem;

						deb_info("RF %6d; BW %6d; Xtal %6d; Fmem %6d; Fdem %6d; Fs %6d; Prediv %2d; Loopdiv %2d; Timf %8d;", fe->dtv_property_cache.frequency, fe->dtv_property_cache.bandwidth_hz, xtal, fmem, fdem, fs, prediv, loopdiv, adc->timf);
						break;
					}
				}
			}
		}
		if (!spur)
			break;
	}

	if (adc->pll_loopdiv == 0 && adc->pll_prediv == 0)
		return -EINVAL;
	return 0;
}

2075
static int dib8096p_agc_startup(struct dvb_frontend *fe)
2076 2077 2078 2079
{
	struct dvb_usb_adapter *adap = fe->dvb->priv;
	struct dib0700_adapter_state *state = adap->priv;
	struct dibx000_bandwidth_config pll;
O
Olivier Grenie 已提交
2080
	struct dibx090p_best_adc adc;
2081
	u16 target;
O
Olivier Grenie 已提交
2082
	int ret;
2083

2084
	ret = state->set_param_save(fe);
2085 2086 2087 2088 2089 2090 2091 2092
	if (ret < 0)
		return ret;
	memset(&pll, 0, sizeof(struct dibx000_bandwidth_config));

	dib0090_pwm_gain_reset(fe);
	/* dib0090_get_wbd_target is returning any possible
	   temperature compensated wbd-target */
	target = (dib0090_get_wbd_target(fe) * 8  + 1) / 2;
2093
	state->dib8000_ops.set_wbd_ref(fe, target);
2094

O
Olivier Grenie 已提交
2095 2096 2097
	if (dib8096p_get_best_sampling(fe, &adc) == 0) {
		pll.pll_ratio  = adc.pll_loopdiv;
		pll.pll_prediv = adc.pll_prediv;
2098

O
Olivier Grenie 已提交
2099
		dib0700_set_i2c_speed(adap->dev, 200);
2100 2101
		state->dib8000_ops.update_pll(fe, &pll, fe->dtv_property_cache.bandwidth_hz / 1000, 0);
		state->dib8000_ops.ctrl_timf(fe, DEMOD_TIMF_SET, adc.timf);
O
Olivier Grenie 已提交
2102
		dib0700_set_i2c_speed(adap->dev, 1000);
2103 2104 2105 2106 2107 2108
	}
	return 0;
}

static int tfe8096p_frontend_attach(struct dvb_usb_adapter *adap)
{
O
Olivier Grenie 已提交
2109 2110
	struct dib0700_state *st = adap->dev->priv;
	u32 fw_version;
2111 2112 2113 2114
	struct dib0700_adapter_state *state = adap->priv;

	if (!dvb_attach(dib8000_attach, &state->dib8000_ops))
		return -ENODEV;
O
Olivier Grenie 已提交
2115 2116 2117 2118 2119

	dib0700_get_version(adap->dev, NULL, NULL, &fw_version, NULL);
	if (fw_version >= 0x10200)
		st->fw_use_new_i2c_api = 1;

2120 2121 2122 2123 2124 2125 2126 2127 2128 2129 2130 2131 2132 2133 2134
	dib0700_set_gpio(adap->dev, GPIO6, GPIO_OUT, 1);
	msleep(20);
	dib0700_set_gpio(adap->dev, GPIO9, GPIO_OUT, 1);
	dib0700_set_gpio(adap->dev, GPIO4, GPIO_OUT, 1);
	dib0700_set_gpio(adap->dev, GPIO7, GPIO_OUT, 1);

	dib0700_set_gpio(adap->dev, GPIO10, GPIO_OUT, 0);

	dib0700_ctrl_clock(adap->dev, 72, 1);

	msleep(20);
	dib0700_set_gpio(adap->dev, GPIO10, GPIO_OUT, 1);
	msleep(20);
	dib0700_set_gpio(adap->dev, GPIO0, GPIO_OUT, 1);

2135
	state->dib8000_ops.i2c_enumeration(&adap->dev->i2c_adap, 1, 0x10, 0x80, 1);
2136

2137 2138
	adap->fe_adap[0].fe = state->dib8000_ops.init(&adap->dev->i2c_adap,
					     0x80, &tfe8096p_dib8000_config);
2139 2140 2141 2142 2143 2144 2145

	return adap->fe_adap[0].fe == NULL ?  -ENODEV : 0;
}

static int tfe8096p_tuner_attach(struct dvb_usb_adapter *adap)
{
	struct dib0700_adapter_state *st = adap->priv;
2146 2147 2148 2149 2150
	struct i2c_adapter *tun_i2c = st->dib8000_ops.get_i2c_tuner(adap->fe_adap[0].fe);

	tfe8096p_dib0090_config.reset = st->dib8000_ops.tuner_sleep;
	tfe8096p_dib0090_config.sleep = st->dib8000_ops.tuner_sleep;
	tfe8096p_dib0090_config.wbd = dib8096p_wbd_table;
2151 2152 2153 2154 2155

	if (dvb_attach(dib0090_register, adap->fe_adap[0].fe, tun_i2c,
				&tfe8096p_dib0090_config) == NULL)
		return -ENODEV;

2156
	st->dib8000_ops.set_gpio(adap->fe_adap[0].fe, 8, 0, 1);
2157 2158 2159 2160 2161 2162

	st->set_param_save = adap->fe_adap[0].fe->ops.tuner_ops.set_params;
	adap->fe_adap[0].fe->ops.tuner_ops.set_params = dib8096p_agc_startup;
	return 0;
}

2163 2164 2165
/* STK9090M */
static int dib90x0_pid_filter(struct dvb_usb_adapter *adapter, int index, u16 pid, int onoff)
{
2166
	return dib9000_fw_pid_filter(adapter->fe_adap[0].fe, index, pid, onoff);
2167 2168 2169 2170
}

static int dib90x0_pid_filter_ctrl(struct dvb_usb_adapter *adapter, int onoff)
{
2171
	return dib9000_fw_pid_filter_ctrl(adapter->fe_adap[0].fe, onoff);
2172 2173 2174 2175 2176 2177 2178 2179 2180 2181 2182 2183 2184 2185 2186 2187 2188
}

static int dib90x0_tuner_reset(struct dvb_frontend *fe, int onoff)
{
	return dib9000_set_gpio(fe, 5, 0, !onoff);
}

static int dib90x0_tuner_sleep(struct dvb_frontend *fe, int onoff)
{
	return dib9000_set_gpio(fe, 0, 0, onoff);
}

static int dib01x0_pmu_update(struct i2c_adapter *i2c, u16 *data, u8 len)
{
	u8 wb[4] = { 0xc >> 8, 0xc & 0xff, 0, 0 };
	u8 rb[2];
	struct i2c_msg msg[2] = {
2189 2190
		{.addr = 0x1e >> 1, .flags = 0, .buf = wb, .len = 2},
		{.addr = 0x1e >> 1, .flags = I2C_M_RD, .buf = rb, .len = 2},
2191 2192 2193 2194 2195 2196 2197 2198 2199
	};
	u8 index_data;

	dibx000_i2c_set_speed(i2c, 250);

	if (i2c_transfer(i2c, msg, 2) != 2)
		return -EIO;

	switch (rb[0] << 8 | rb[1]) {
2200
	case 0:
2201 2202
			deb_info("Found DiB0170 rev1: This version of DiB0170 is not supported any longer.\n");
			return -EIO;
2203
	case 1:
2204 2205
			deb_info("Found DiB0170 rev2");
			break;
2206
	case 2:
2207 2208
			deb_info("Found DiB0190 rev2");
			break;
2209
	default:
2210 2211
			deb_info("DiB01x0 not found");
			return -EIO;
2212
	}
2213 2214 2215 2216 2217 2218 2219 2220 2221 2222 2223 2224 2225 2226 2227

	for (index_data = 0; index_data < len; index_data += 2) {
		wb[2] = (data[index_data + 1] >> 8) & 0xff;
		wb[3] = (data[index_data + 1]) & 0xff;

		if (data[index_data] == 0) {
			wb[0] = (data[index_data] >> 8) & 0xff;
			wb[1] = (data[index_data]) & 0xff;
			msg[0].len = 2;
			if (i2c_transfer(i2c, msg, 2) != 2)
				return -EIO;
			wb[2] |= rb[0];
			wb[3] |= rb[1] & ~(3 << 4);
		}

2228 2229
		wb[0] = (data[index_data] >> 8)&0xff;
		wb[1] = (data[index_data])&0xff;
2230 2231 2232 2233 2234 2235 2236 2237 2238 2239 2240 2241 2242 2243 2244 2245 2246 2247 2248 2249 2250 2251 2252 2253 2254 2255 2256 2257 2258 2259 2260 2261 2262 2263 2264 2265 2266 2267 2268 2269 2270 2271 2272 2273 2274 2275 2276 2277 2278 2279 2280 2281 2282 2283 2284 2285 2286 2287 2288 2289 2290 2291 2292 2293 2294 2295 2296 2297 2298 2299 2300 2301 2302 2303 2304 2305 2306 2307 2308 2309 2310 2311 2312 2313 2314 2315 2316 2317 2318 2319 2320 2321 2322 2323 2324 2325
		msg[0].len = 4;
		if (i2c_transfer(i2c, &msg[0], 1) != 1)
			return -EIO;
	}
	return 0;
}

static struct dib9000_config stk9090m_config = {
	.output_mpeg2_in_188_bytes = 1,
	.output_mode = OUTMODE_MPEG2_FIFO,
	.vcxo_timer = 279620,
	.timing_frequency = 20452225,
	.demod_clock_khz = 60000,
	.xtal_clock_khz = 30000,
	.if_drives = (0 << 15) | (1 << 13) | (0 << 12) | (3 << 10) | (0 << 9) | (1 << 7) | (0 << 6) | (0 << 4) | (1 << 3) | (1 << 1) | (0),
	.subband = {
		2,
		{
			{ 240, { BOARD_GPIO_COMPONENT_DEMOD, BOARD_GPIO_FUNCTION_SUBBAND_GPIO, 0x0008, 0x0000, 0x0008 } }, /* GPIO 3 to 1 for VHF */
			{ 890, { BOARD_GPIO_COMPONENT_DEMOD, BOARD_GPIO_FUNCTION_SUBBAND_GPIO, 0x0008, 0x0000, 0x0000 } }, /* GPIO 3 to 0 for UHF */
			{ 0 },
		},
	},
	.gpio_function = {
		{ .component = BOARD_GPIO_COMPONENT_DEMOD, .function = BOARD_GPIO_FUNCTION_COMPONENT_ON, .mask = 0x10 | 0x21, .direction = 0 & ~0x21, .value = (0x10 & ~0x1) | 0x20 },
		{ .component = BOARD_GPIO_COMPONENT_DEMOD, .function = BOARD_GPIO_FUNCTION_COMPONENT_OFF, .mask = 0x10 | 0x21, .direction = 0 & ~0x21, .value = 0 | 0x21 },
	},
};

static struct dib9000_config nim9090md_config[2] = {
	{
		.output_mpeg2_in_188_bytes = 1,
		.output_mode = OUTMODE_MPEG2_FIFO,
		.vcxo_timer = 279620,
		.timing_frequency = 20452225,
		.demod_clock_khz = 60000,
		.xtal_clock_khz = 30000,
		.if_drives = (0 << 15) | (1 << 13) | (0 << 12) | (3 << 10) | (0 << 9) | (1 << 7) | (0 << 6) | (0 << 4) | (1 << 3) | (1 << 1) | (0),
	}, {
		.output_mpeg2_in_188_bytes = 1,
		.output_mode = OUTMODE_DIVERSITY,
		.vcxo_timer = 279620,
		.timing_frequency = 20452225,
		.demod_clock_khz = 60000,
		.xtal_clock_khz = 30000,
		.if_drives = (0 << 15) | (1 << 13) | (0 << 12) | (3 << 10) | (0 << 9) | (1 << 7) | (0 << 6) | (0 << 4) | (1 << 3) | (1 << 1) | (0),
		.subband = {
			2,
			{
				{ 240, { BOARD_GPIO_COMPONENT_DEMOD, BOARD_GPIO_FUNCTION_SUBBAND_GPIO, 0x0006, 0x0000, 0x0006 } }, /* GPIO 1 and 2 to 1 for VHF */
				{ 890, { BOARD_GPIO_COMPONENT_DEMOD, BOARD_GPIO_FUNCTION_SUBBAND_GPIO, 0x0006, 0x0000, 0x0000 } }, /* GPIO 1 and 2 to 0 for UHF */
				{ 0 },
			},
		},
		.gpio_function = {
			{ .component = BOARD_GPIO_COMPONENT_DEMOD, .function = BOARD_GPIO_FUNCTION_COMPONENT_ON, .mask = 0x10 | 0x21, .direction = 0 & ~0x21, .value = (0x10 & ~0x1) | 0x20 },
			{ .component = BOARD_GPIO_COMPONENT_DEMOD, .function = BOARD_GPIO_FUNCTION_COMPONENT_OFF, .mask = 0x10 | 0x21, .direction = 0 & ~0x21, .value = 0 | 0x21 },
		},
	}
};

static struct dib0090_config dib9090_dib0090_config = {
	.io.pll_bypass = 0,
	.io.pll_range = 1,
	.io.pll_prediv = 1,
	.io.pll_loopdiv = 8,
	.io.adc_clock_ratio = 8,
	.io.pll_int_loop_filt = 0,
	.io.clock_khz = 30000,
	.reset = dib90x0_tuner_reset,
	.sleep = dib90x0_tuner_sleep,
	.clkouttobamse = 0,
	.analog_output = 0,
	.use_pwm_agc = 0,
	.clkoutdrive = 0,
	.freq_offset_khz_uhf = 0,
	.freq_offset_khz_vhf = 0,
};

static struct dib0090_config nim9090md_dib0090_config[2] = {
	{
		.io.pll_bypass = 0,
		.io.pll_range = 1,
		.io.pll_prediv = 1,
		.io.pll_loopdiv = 8,
		.io.adc_clock_ratio = 8,
		.io.pll_int_loop_filt = 0,
		.io.clock_khz = 30000,
		.reset = dib90x0_tuner_reset,
		.sleep = dib90x0_tuner_sleep,
		.clkouttobamse = 1,
		.analog_output = 0,
		.use_pwm_agc = 0,
		.clkoutdrive = 0,
		.freq_offset_khz_uhf = 0,
		.freq_offset_khz_vhf = 0,
2326
	}, {
2327 2328 2329 2330 2331 2332 2333 2334 2335 2336 2337 2338 2339 2340 2341 2342 2343 2344 2345 2346 2347 2348 2349 2350 2351 2352 2353 2354 2355 2356 2357 2358
		.io.pll_bypass = 0,
		.io.pll_range = 1,
		.io.pll_prediv = 1,
		.io.pll_loopdiv = 8,
		.io.adc_clock_ratio = 8,
		.io.pll_int_loop_filt = 0,
		.io.clock_khz = 30000,
		.reset = dib90x0_tuner_reset,
		.sleep = dib90x0_tuner_sleep,
		.clkouttobamse = 0,
		.analog_output = 0,
		.use_pwm_agc = 0,
		.clkoutdrive = 0,
		.freq_offset_khz_uhf = 0,
		.freq_offset_khz_vhf = 0,
	}
};


static int stk9090m_frontend_attach(struct dvb_usb_adapter *adap)
{
	struct dib0700_adapter_state *state = adap->priv;
	struct dib0700_state *st = adap->dev->priv;
	u32 fw_version;

	/* Make use of the new i2c functions from FW 1.20 */
	dib0700_get_version(adap->dev, NULL, NULL, &fw_version, NULL);
	if (fw_version >= 0x10200)
		st->fw_use_new_i2c_api = 1;
	dib0700_set_i2c_speed(adap->dev, 340);

	dib0700_set_gpio(adap->dev, GPIO6, GPIO_OUT, 1);
2359
	msleep(20);
2360 2361 2362 2363 2364 2365 2366
	dib0700_set_gpio(adap->dev, GPIO9, GPIO_OUT, 1);
	dib0700_set_gpio(adap->dev, GPIO4, GPIO_OUT, 1);
	dib0700_set_gpio(adap->dev, GPIO7, GPIO_OUT, 1);
	dib0700_set_gpio(adap->dev, GPIO10, GPIO_OUT, 0);

	dib0700_ctrl_clock(adap->dev, 72, 1);

2367
	msleep(20);
2368
	dib0700_set_gpio(adap->dev, GPIO10, GPIO_OUT, 1);
2369
	msleep(20);
2370 2371 2372 2373 2374 2375 2376 2377 2378 2379 2380 2381 2382
	dib0700_set_gpio(adap->dev, GPIO0, GPIO_OUT, 1);

	dib9000_i2c_enumeration(&adap->dev->i2c_adap, 1, 0x10, 0x80);

	if (request_firmware(&state->frontend_firmware, "dib9090.fw", &adap->dev->udev->dev)) {
		deb_info("%s: Upload failed. (file not found?)\n", __func__);
		return -ENODEV;
	} else {
		deb_info("%s: firmware read %Zu bytes.\n", __func__, state->frontend_firmware->size);
	}
	stk9090m_config.microcode_B_fe_size = state->frontend_firmware->size;
	stk9090m_config.microcode_B_fe_buffer = state->frontend_firmware->data;

2383
	adap->fe_adap[0].fe = dvb_attach(dib9000_attach, &adap->dev->i2c_adap, 0x80, &stk9090m_config);
2384

2385
	return adap->fe_adap[0].fe == NULL ?  -ENODEV : 0;
2386 2387 2388 2389 2390
}

static int dib9090_tuner_attach(struct dvb_usb_adapter *adap)
{
	struct dib0700_adapter_state *state = adap->priv;
2391
	struct i2c_adapter *i2c = dib9000_get_tuner_interface(adap->fe_adap[0].fe);
2392 2393 2394 2395 2396 2397 2398 2399
	u16 data_dib190[10] = {
		1, 0x1374,
		2, 0x01a2,
		7, 0x0020,
		0, 0x00ef,
		8, 0x0486,
	};

2400
	if (dvb_attach(dib0090_fw_register, adap->fe_adap[0].fe, i2c, &dib9090_dib0090_config) == NULL)
2401
		return -ENODEV;
2402
	i2c = dib9000_get_i2c_master(adap->fe_adap[0].fe, DIBX000_I2C_INTERFACE_GPIO_1_2, 0);
2403 2404
	if (dib01x0_pmu_update(i2c, data_dib190, 10) != 0)
		return -ENODEV;
2405
	dib0700_set_i2c_speed(adap->dev, 1500);
2406
	if (dib9000_firmware_post_pll_init(adap->fe_adap[0].fe) < 0)
2407
		return -ENODEV;
2408
	release_firmware(state->frontend_firmware);
2409 2410 2411 2412 2413 2414 2415 2416 2417 2418 2419 2420 2421 2422 2423 2424 2425 2426
	return 0;
}

static int nim9090md_frontend_attach(struct dvb_usb_adapter *adap)
{
	struct dib0700_adapter_state *state = adap->priv;
	struct dib0700_state *st = adap->dev->priv;
	struct i2c_adapter *i2c;
	struct dvb_frontend *fe_slave;
	u32 fw_version;

	/* Make use of the new i2c functions from FW 1.20 */
	dib0700_get_version(adap->dev, NULL, NULL, &fw_version, NULL);
	if (fw_version >= 0x10200)
		st->fw_use_new_i2c_api = 1;
	dib0700_set_i2c_speed(adap->dev, 340);

	dib0700_set_gpio(adap->dev, GPIO6, GPIO_OUT, 1);
2427
	msleep(20);
2428 2429 2430 2431 2432 2433 2434
	dib0700_set_gpio(adap->dev, GPIO9, GPIO_OUT, 1);
	dib0700_set_gpio(adap->dev, GPIO4, GPIO_OUT, 1);
	dib0700_set_gpio(adap->dev, GPIO7, GPIO_OUT, 1);
	dib0700_set_gpio(adap->dev, GPIO10, GPIO_OUT, 0);

	dib0700_ctrl_clock(adap->dev, 72, 1);

2435
	msleep(20);
2436
	dib0700_set_gpio(adap->dev, GPIO10, GPIO_OUT, 1);
2437
	msleep(20);
2438 2439 2440 2441 2442 2443 2444 2445 2446 2447 2448 2449 2450 2451
	dib0700_set_gpio(adap->dev, GPIO0, GPIO_OUT, 1);

	if (request_firmware(&state->frontend_firmware, "dib9090.fw", &adap->dev->udev->dev)) {
		deb_info("%s: Upload failed. (file not found?)\n", __func__);
		return -EIO;
	} else {
		deb_info("%s: firmware read %Zu bytes.\n", __func__, state->frontend_firmware->size);
	}
	nim9090md_config[0].microcode_B_fe_size = state->frontend_firmware->size;
	nim9090md_config[0].microcode_B_fe_buffer = state->frontend_firmware->data;
	nim9090md_config[1].microcode_B_fe_size = state->frontend_firmware->size;
	nim9090md_config[1].microcode_B_fe_buffer = state->frontend_firmware->data;

	dib9000_i2c_enumeration(&adap->dev->i2c_adap, 1, 0x20, 0x80);
2452
	adap->fe_adap[0].fe = dvb_attach(dib9000_attach, &adap->dev->i2c_adap, 0x80, &nim9090md_config[0]);
2453

2454
	if (adap->fe_adap[0].fe == NULL)
2455 2456
		return -ENODEV;

2457
	i2c = dib9000_get_i2c_master(adap->fe_adap[0].fe, DIBX000_I2C_INTERFACE_GPIO_3_4, 0);
2458 2459 2460
	dib9000_i2c_enumeration(i2c, 1, 0x12, 0x82);

	fe_slave = dvb_attach(dib9000_attach, i2c, 0x82, &nim9090md_config[1]);
2461
	dib9000_set_slave_frontend(adap->fe_adap[0].fe, fe_slave);
2462 2463

	return fe_slave == NULL ?  -ENODEV : 0;
2464 2465
}

2466 2467 2468 2469 2470 2471 2472 2473 2474 2475 2476 2477
static int nim9090md_tuner_attach(struct dvb_usb_adapter *adap)
{
	struct dib0700_adapter_state *state = adap->priv;
	struct i2c_adapter *i2c;
	struct dvb_frontend *fe_slave;
	u16 data_dib190[10] = {
		1, 0x5374,
		2, 0x01ae,
		7, 0x0020,
		0, 0x00ef,
		8, 0x0406,
	};
2478 2479
	i2c = dib9000_get_tuner_interface(adap->fe_adap[0].fe);
	if (dvb_attach(dib0090_fw_register, adap->fe_adap[0].fe, i2c, &nim9090md_dib0090_config[0]) == NULL)
2480
		return -ENODEV;
2481
	i2c = dib9000_get_i2c_master(adap->fe_adap[0].fe, DIBX000_I2C_INTERFACE_GPIO_1_2, 0);
2482 2483
	if (dib01x0_pmu_update(i2c, data_dib190, 10) < 0)
		return -ENODEV;
2484 2485

	dib0700_set_i2c_speed(adap->dev, 1500);
2486
	if (dib9000_firmware_post_pll_init(adap->fe_adap[0].fe) < 0)
2487 2488
		return -ENODEV;

2489
	fe_slave = dib9000_get_slave_frontend(adap->fe_adap[0].fe, 1);
2490
	if (fe_slave != NULL) {
2491
		i2c = dib9000_get_component_bus_interface(adap->fe_adap[0].fe);
2492 2493 2494 2495 2496
		dib9000_set_i2c_adapter(fe_slave, i2c);

		i2c = dib9000_get_tuner_interface(fe_slave);
		if (dvb_attach(dib0090_fw_register, fe_slave, i2c, &nim9090md_dib0090_config[1]) == NULL)
			return -ENODEV;
2497
		fe_slave->dvb = adap->fe_adap[0].fe->dvb;
2498
		dib9000_fw_set_component_bus_speed(adap->fe_adap[0].fe, 1500);
2499 2500 2501
		if (dib9000_firmware_post_pll_init(fe_slave) < 0)
			return -ENODEV;
	}
2502
	release_firmware(state->frontend_firmware);
2503 2504 2505 2506 2507

	return 0;
}

/* NIM7090 */
O
Olivier Grenie 已提交
2508
static int dib7090p_get_best_sampling(struct dvb_frontend *fe , struct dibx090p_best_adc *adc)
2509 2510 2511 2512 2513 2514 2515 2516 2517 2518 2519 2520 2521 2522 2523 2524 2525 2526
{
	u8 spur = 0, prediv = 0, loopdiv = 0, min_prediv = 1, max_prediv = 1;

	u16 xtal = 12000;
	u32 fcp_min = 1900;  /* PLL Minimum Frequency comparator KHz */
	u32 fcp_max = 20000; /* PLL Maximum Frequency comparator KHz */
	u32 fdem_max = 76000;
	u32 fdem_min = 69500;
	u32 fcp = 0, fs = 0, fdem = 0;
	u32 harmonic_id = 0;

	adc->pll_loopdiv = loopdiv;
	adc->pll_prediv = prediv;
	adc->timf = 0;

	deb_info("bandwidth = %d fdem_min =%d", fe->dtv_property_cache.bandwidth_hz, fdem_min);

	/* Find Min and Max prediv */
2527
	while ((xtal/max_prediv) >= fcp_min)
2528 2529 2530 2531
		max_prediv++;

	max_prediv--;
	min_prediv = max_prediv;
2532
	while ((xtal/min_prediv) <= fcp_max) {
2533
		min_prediv--;
2534
		if (min_prediv == 1)
2535 2536 2537 2538 2539 2540
			break;
	}
	deb_info("MIN prediv = %d : MAX prediv = %d", min_prediv, max_prediv);

	min_prediv = 2;

2541
	for (prediv = min_prediv ; prediv < max_prediv; prediv++) {
2542
		fcp = xtal / prediv;
2543 2544
		if (fcp > fcp_min && fcp < fcp_max) {
			for (loopdiv = 1 ; loopdiv < 64 ; loopdiv++) {
2545 2546 2547 2548
				fdem = ((xtal/prediv) * loopdiv);
				fs   = fdem / 4;
				/* test min/max system restrictions */

2549
				if ((fdem >= fdem_min) && (fdem <= fdem_max) && (fs >= fe->dtv_property_cache.bandwidth_hz/1000)) {
2550 2551
					spur = 0;
					/* test fs harmonics positions */
2552 2553
					for (harmonic_id = (fe->dtv_property_cache.frequency / (1000*fs)) ;  harmonic_id <= ((fe->dtv_property_cache.frequency / (1000*fs))+1) ; harmonic_id++) {
						if (((fs*harmonic_id) >= ((fe->dtv_property_cache.frequency/1000) - (fe->dtv_property_cache.bandwidth_hz/2000))) &&  ((fs*harmonic_id) <= ((fe->dtv_property_cache.frequency/1000) + (fe->dtv_property_cache.bandwidth_hz/2000)))) {
2554 2555 2556 2557 2558
							spur = 1;
							break;
						}
					}

2559
					if (!spur) {
2560 2561
						adc->pll_loopdiv = loopdiv;
						adc->pll_prediv = prediv;
2562 2563
						adc->timf = 2396745143UL/fdem*(1 << 9);
						adc->timf += ((2396745143UL%fdem) << 9)/fdem;
2564 2565 2566 2567 2568 2569 2570 2571 2572 2573 2574
						deb_info("loopdiv=%i prediv=%i timf=%i", loopdiv, prediv, adc->timf);
						break;
					}
				}
			}
		}
		if (!spur)
			break;
	}


2575
	if (adc->pll_loopdiv == 0 && adc->pll_prediv == 0)
2576
		return -EINVAL;
2577
	else
2578 2579 2580
		return 0;
}

2581
static int dib7090_agc_startup(struct dvb_frontend *fe)
2582 2583 2584 2585 2586
{
	struct dvb_usb_adapter *adap = fe->dvb->priv;
	struct dib0700_adapter_state *state = adap->priv;
	struct dibx000_bandwidth_config pll;
	u16 target;
O
Olivier Grenie 已提交
2587
	struct dibx090p_best_adc adc;
2588 2589
	int ret;

2590
	ret = state->set_param_save(fe);
2591 2592 2593 2594 2595
	if (ret < 0)
		return ret;

	memset(&pll, 0, sizeof(struct dibx000_bandwidth_config));
	dib0090_pwm_gain_reset(fe);
2596
	target = (dib0090_get_wbd_target(fe) * 8 + 1) / 2;
2597
	state->dib7000p_ops.set_wbd_ref(fe, target);
2598

2599
	if (dib7090p_get_best_sampling(fe, &adc) == 0) {
2600 2601 2602
		pll.pll_ratio  = adc.pll_loopdiv;
		pll.pll_prediv = adc.pll_prediv;

2603 2604
		state->dib7000p_ops.update_pll(fe, &pll);
		state->dib7000p_ops.ctrl_timf(fe, DEMOD_TIMF_SET, adc.timf);
2605 2606 2607 2608
	}
	return 0;
}

2609 2610 2611 2612 2613 2614 2615 2616
static int dib7090_agc_restart(struct dvb_frontend *fe, u8 restart)
{
	deb_info("AGC restart callback: %d", restart);
	if (restart == 0) /* before AGC startup */
		dib0090_set_dc_servo(fe, 1);
	return 0;
}

2617
static int tfe7790p_update_lna(struct dvb_frontend *fe, u16 agc_global)
2618
{
2619 2620 2621
	struct dvb_usb_adapter *adap = fe->dvb->priv;
	struct dib0700_adapter_state *state = adap->priv;

2622
	deb_info("update LNA: agc global=%i", agc_global);
2623

2624
	if (agc_global < 25000) {
2625 2626
		state->dib7000p_ops.set_gpio(fe, 8, 0, 0);
		state->dib7000p_ops.set_agc1_min(fe, 0);
2627
	} else {
2628 2629
		state->dib7000p_ops.set_gpio(fe, 8, 0, 1);
		state->dib7000p_ops.set_agc1_min(fe, 32768);
2630 2631 2632 2633 2634
	}

	return 0;
}

2635
static struct dib0090_wbd_slope dib7090_wbd_table[] = {
2636 2637 2638 2639 2640
	{ 380,   81, 850, 64, 540,  4},
	{ 860,   51, 866, 21,  375, 4},
	{1700,    0, 250, 0,   100, 6},
	{2600,    0, 250, 0,   100, 6},
	{ 0xFFFF, 0,   0, 0,   0,   0},
2641 2642
};

O
Olivier Grenie 已提交
2643
static struct dibx000_agc_config dib7090_agc_config[2] = {
2644 2645 2646 2647
	{
		.band_caps      = BAND_UHF,
		/* P_agc_use_sd_mod1=0, P_agc_use_sd_mod2=0, P_agc_freq_pwm_div=1, P_agc_inv_pwm1=0, P_agc_inv_pwm2=0,
		* P_agc_inh_dc_rv_est=0, P_agc_time_est=3, P_agc_freeze=0, P_agc_nb_est=5, P_agc_write=0 */
2648
		.setup          = (0 << 15) | (0 << 14) | (5 << 11) | (0 << 10) | (0 << 9) | (0 << 8) | (3 << 5) | (0 << 4) | (5 << 1) | (0 << 0),
2649

2650 2651
		.inv_gain       = 687,
		.time_stabiliz  = 10,
2652

2653 2654
		.alpha_level    = 0,
		.thlock         = 118,
2655

2656 2657 2658 2659
		.wbd_inv        = 0,
		.wbd_ref        = 1200,
		.wbd_sel        = 3,
		.wbd_alpha      = 5,
2660

2661
		.agc1_max       = 65535,
2662
		.agc1_min       = 32768,
2663

2664 2665
		.agc2_max       = 65535,
		.agc2_min       = 0,
2666

2667 2668 2669 2670 2671 2672 2673 2674 2675
		.agc1_pt1       = 0,
		.agc1_pt2       = 32,
		.agc1_pt3       = 114,
		.agc1_slope1    = 143,
		.agc1_slope2    = 144,
		.agc2_pt1       = 114,
		.agc2_pt2       = 227,
		.agc2_slope1    = 116,
		.agc2_slope2    = 117,
2676

2677 2678 2679 2680
		.alpha_mant     = 18,
		.alpha_exp      = 0,
		.beta_mant      = 20,
		.beta_exp       = 59,
2681

2682
		.perform_agc_softsplit = 0,
2683 2684 2685 2686
	} , {
		.band_caps      = BAND_FM | BAND_VHF | BAND_CBAND,
		/* P_agc_use_sd_mod1=0, P_agc_use_sd_mod2=0, P_agc_freq_pwm_div=1, P_agc_inv_pwm1=0, P_agc_inv_pwm2=0,
		* P_agc_inh_dc_rv_est=0, P_agc_time_est=3, P_agc_freeze=0, P_agc_nb_est=5, P_agc_write=0 */
2687
		.setup          = (0 << 15) | (0 << 14) | (5 << 11) | (0 << 10) | (0 << 9) | (0 << 8) | (3 << 5) | (0 << 4) | (5 << 1) | (0 << 0),
2688

2689 2690
		.inv_gain       = 732,
		.time_stabiliz  = 10,
2691

2692 2693
		.alpha_level    = 0,
		.thlock         = 118,
2694

2695 2696 2697 2698
		.wbd_inv        = 0,
		.wbd_ref        = 1200,
		.wbd_sel        = 3,
		.wbd_alpha      = 5,
2699

2700 2701
		.agc1_max       = 65535,
		.agc1_min       = 0,
2702

2703 2704
		.agc2_max       = 65535,
		.agc2_min       = 0,
2705

2706 2707 2708 2709 2710
		.agc1_pt1       = 0,
		.agc1_pt2       = 0,
		.agc1_pt3       = 98,
		.agc1_slope1    = 0,
		.agc1_slope2    = 167,
2711
		.agc2_pt1       = 98,
2712 2713 2714
		.agc2_pt2       = 255,
		.agc2_slope1    = 104,
		.agc2_slope2    = 0,
2715

2716 2717 2718 2719
		.alpha_mant     = 18,
		.alpha_exp      = 0,
		.beta_mant      = 20,
		.beta_exp       = 59,
2720

2721
		.perform_agc_softsplit = 0,
2722 2723 2724 2725
	}
};

static struct dibx000_bandwidth_config dib7090_clock_config_12_mhz = {
2726 2727 2728 2729 2730 2731 2732
	60000, 15000,
	1, 5, 0, 0, 0,
	0, 0, 1, 1, 2,
	(3 << 14) | (1 << 12) | (524 << 0),
	(0 << 25) | 0,
	20452225,
	15000000,
2733 2734 2735 2736 2737 2738
};

static struct dib7000p_config nim7090_dib7000p_config = {
	.output_mpeg2_in_188_bytes  = 1,
	.hostbus_diversity			= 1,
	.tuner_is_baseband			= 1,
2739
	.update_lna					= tfe7790p_update_lna, /* GPIO used is the same as TFE7790 */
2740 2741 2742 2743 2744 2745 2746 2747 2748 2749 2750 2751 2752 2753 2754 2755 2756 2757 2758 2759 2760 2761 2762

	.agc_config_count			= 2,
	.agc						= dib7090_agc_config,

	.bw							= &dib7090_clock_config_12_mhz,

	.gpio_dir					= DIB7000P_GPIO_DEFAULT_DIRECTIONS,
	.gpio_val					= DIB7000P_GPIO_DEFAULT_VALUES,
	.gpio_pwm_pos				= DIB7000P_GPIO_DEFAULT_PWM_POS,

	.pwm_freq_div				= 0,

	.agc_control				= dib7090_agc_restart,

	.spur_protect				= 0,
	.disable_sample_and_hold	= 0,
	.enable_current_mirror		= 0,
	.diversity_delay			= 0,

	.output_mode				= OUTMODE_MPEG2_FIFO,
	.enMpegOutput				= 1,
};

2763 2764
static int tfe7090p_pvr_update_lna(struct dvb_frontend *fe, u16 agc_global)
{
2765 2766 2767
	struct dvb_usb_adapter *adap = fe->dvb->priv;
	struct dib0700_adapter_state *state = adap->priv;

2768 2769
	deb_info("TFE7090P-PVR update LNA: agc global=%i", agc_global);
	if (agc_global < 25000) {
2770 2771
		state->dib7000p_ops.set_gpio(fe, 5, 0, 0);
		state->dib7000p_ops.set_agc1_min(fe, 0);
2772
	} else {
2773 2774
		state->dib7000p_ops.set_gpio(fe, 5, 0, 1);
		state->dib7000p_ops.set_agc1_min(fe, 32768);
2775 2776 2777 2778 2779
	}

	return 0;
}

2780 2781 2782 2783 2784
static struct dib7000p_config tfe7090pvr_dib7000p_config[2] = {
	{
		.output_mpeg2_in_188_bytes  = 1,
		.hostbus_diversity			= 1,
		.tuner_is_baseband			= 1,
2785
		.update_lna					= tfe7090p_pvr_update_lna,
2786 2787 2788 2789 2790 2791 2792 2793 2794 2795 2796 2797 2798 2799 2800 2801 2802 2803 2804 2805 2806 2807

		.agc_config_count			= 2,
		.agc						= dib7090_agc_config,

		.bw							= &dib7090_clock_config_12_mhz,

		.gpio_dir					= DIB7000P_GPIO_DEFAULT_DIRECTIONS,
		.gpio_val					= DIB7000P_GPIO_DEFAULT_VALUES,
		.gpio_pwm_pos				= DIB7000P_GPIO_DEFAULT_PWM_POS,

		.pwm_freq_div				= 0,

		.agc_control				= dib7090_agc_restart,

		.spur_protect				= 0,
		.disable_sample_and_hold	= 0,
		.enable_current_mirror		= 0,
		.diversity_delay			= 0,

		.output_mode				= OUTMODE_MPEG2_PAR_GATED_CLK,
		.default_i2c_addr			= 0x90,
		.enMpegOutput				= 1,
2808
	}, {
2809 2810 2811
		.output_mpeg2_in_188_bytes  = 1,
		.hostbus_diversity			= 1,
		.tuner_is_baseband			= 1,
2812
		.update_lna					= tfe7090p_pvr_update_lna,
2813 2814 2815 2816 2817 2818 2819 2820 2821 2822 2823 2824 2825 2826 2827 2828 2829 2830 2831 2832 2833 2834 2835 2836 2837

		.agc_config_count			= 2,
		.agc						= dib7090_agc_config,

		.bw							= &dib7090_clock_config_12_mhz,

		.gpio_dir					= DIB7000P_GPIO_DEFAULT_DIRECTIONS,
		.gpio_val					= DIB7000P_GPIO_DEFAULT_VALUES,
		.gpio_pwm_pos				= DIB7000P_GPIO_DEFAULT_PWM_POS,

		.pwm_freq_div				= 0,

		.agc_control				= dib7090_agc_restart,

		.spur_protect				= 0,
		.disable_sample_and_hold	= 0,
		.enable_current_mirror		= 0,
		.diversity_delay			= 0,

		.output_mode				= OUTMODE_MPEG2_PAR_GATED_CLK,
		.default_i2c_addr			= 0x92,
		.enMpegOutput				= 0,
	}
};

2838
static struct dib0090_config nim7090_dib0090_config = {
2839 2840 2841 2842 2843 2844 2845 2846 2847 2848 2849 2850 2851 2852 2853 2854 2855 2856 2857 2858 2859 2860 2861 2862 2863 2864 2865 2866 2867
	.io.clock_khz = 12000,
	.io.pll_bypass = 0,
	.io.pll_range = 0,
	.io.pll_prediv = 3,
	.io.pll_loopdiv = 6,
	.io.adc_clock_ratio = 0,
	.io.pll_int_loop_filt = 0,

	.freq_offset_khz_uhf = 0,
	.freq_offset_khz_vhf = 0,

	.clkouttobamse = 1,
	.analog_output = 0,

	.wbd_vhf_offset = 0,
	.wbd_cband_offset = 0,
	.use_pwm_agc = 1,
	.clkoutdrive = 0,

	.fref_clock_ratio = 0,

	.wbd = dib7090_wbd_table,

	.ls_cfg_pad_drv = 0,
	.data_tx_drv = 0,
	.low_if = NULL,
	.in_soc = 1,
};

2868
static struct dib7000p_config tfe7790p_dib7000p_config = {
2869 2870 2871
	.output_mpeg2_in_188_bytes  = 1,
	.hostbus_diversity			= 1,
	.tuner_is_baseband			= 1,
2872
	.update_lna					= tfe7790p_update_lna,
2873 2874 2875 2876 2877 2878 2879 2880 2881 2882 2883 2884 2885 2886 2887 2888 2889 2890 2891 2892 2893 2894 2895

	.agc_config_count			= 2,
	.agc						= dib7090_agc_config,

	.bw							= &dib7090_clock_config_12_mhz,

	.gpio_dir					= DIB7000P_GPIO_DEFAULT_DIRECTIONS,
	.gpio_val					= DIB7000P_GPIO_DEFAULT_VALUES,
	.gpio_pwm_pos				= DIB7000P_GPIO_DEFAULT_PWM_POS,

	.pwm_freq_div				= 0,

	.agc_control				= dib7090_agc_restart,

	.spur_protect				= 0,
	.disable_sample_and_hold	= 0,
	.enable_current_mirror		= 0,
	.diversity_delay			= 0,

	.output_mode				= OUTMODE_MPEG2_PAR_GATED_CLK,
	.enMpegOutput				= 1,
};

2896
static struct dib0090_config tfe7790p_dib0090_config = {
2897 2898 2899 2900 2901 2902 2903 2904 2905 2906 2907 2908 2909 2910 2911 2912 2913 2914 2915 2916 2917
	.io.clock_khz = 12000,
	.io.pll_bypass = 0,
	.io.pll_range = 0,
	.io.pll_prediv = 3,
	.io.pll_loopdiv = 6,
	.io.adc_clock_ratio = 0,
	.io.pll_int_loop_filt = 0,

	.freq_offset_khz_uhf = 0,
	.freq_offset_khz_vhf = 0,

	.clkouttobamse = 1,
	.analog_output = 0,

	.wbd_vhf_offset = 0,
	.wbd_cband_offset = 0,
	.use_pwm_agc = 1,
	.clkoutdrive = 0,

	.fref_clock_ratio = 0,

2918
	.wbd = dib7090_wbd_table,
2919 2920 2921 2922 2923

	.ls_cfg_pad_drv = 0,
	.data_tx_drv = 0,
	.low_if = NULL,
	.in_soc = 1,
2924 2925
	.force_cband_input = 0,
	.is_dib7090e = 0,
2926 2927 2928
	.force_crystal_mode = 1,
};

2929
static struct dib0090_config tfe7090pvr_dib0090_config[2] = {
2930 2931 2932 2933 2934 2935 2936 2937 2938 2939 2940 2941 2942 2943 2944 2945 2946 2947 2948 2949 2950 2951 2952 2953 2954 2955 2956 2957
	{
		.io.clock_khz = 12000,
		.io.pll_bypass = 0,
		.io.pll_range = 0,
		.io.pll_prediv = 3,
		.io.pll_loopdiv = 6,
		.io.adc_clock_ratio = 0,
		.io.pll_int_loop_filt = 0,

		.freq_offset_khz_uhf = 50,
		.freq_offset_khz_vhf = 70,

		.clkouttobamse = 1,
		.analog_output = 0,

		.wbd_vhf_offset = 0,
		.wbd_cband_offset = 0,
		.use_pwm_agc = 1,
		.clkoutdrive = 0,

		.fref_clock_ratio = 0,

		.wbd = dib7090_wbd_table,

		.ls_cfg_pad_drv = 0,
		.data_tx_drv = 0,
		.low_if = NULL,
		.in_soc = 1,
2958
	}, {
2959 2960 2961 2962 2963 2964 2965 2966 2967 2968 2969 2970 2971 2972 2973 2974 2975 2976 2977 2978 2979 2980 2981 2982 2983 2984 2985 2986 2987 2988 2989 2990
		.io.clock_khz = 12000,
		.io.pll_bypass = 0,
		.io.pll_range = 0,
		.io.pll_prediv = 3,
		.io.pll_loopdiv = 6,
		.io.adc_clock_ratio = 0,
		.io.pll_int_loop_filt = 0,

		.freq_offset_khz_uhf = -50,
		.freq_offset_khz_vhf = -70,

		.clkouttobamse = 1,
		.analog_output = 0,

		.wbd_vhf_offset = 0,
		.wbd_cband_offset = 0,
		.use_pwm_agc = 1,
		.clkoutdrive = 0,

		.fref_clock_ratio = 0,

		.wbd = dib7090_wbd_table,

		.ls_cfg_pad_drv = 0,
		.data_tx_drv = 0,
		.low_if = NULL,
		.in_soc = 1,
	}
};

static int nim7090_frontend_attach(struct dvb_usb_adapter *adap)
{
2991 2992 2993 2994 2995
	struct dib0700_adapter_state *state = adap->priv;

	if (!dvb_attach(dib7000p_attach, &state->dib7000p_ops))
		return -ENODEV;

2996
	dib0700_set_gpio(adap->dev, GPIO6, GPIO_OUT, 1);
2997
	msleep(20);
2998 2999 3000 3001 3002
	dib0700_set_gpio(adap->dev, GPIO9, GPIO_OUT, 1);
	dib0700_set_gpio(adap->dev, GPIO4, GPIO_OUT, 1);
	dib0700_set_gpio(adap->dev, GPIO7, GPIO_OUT, 1);
	dib0700_set_gpio(adap->dev, GPIO10, GPIO_OUT, 0);

3003
	msleep(20);
3004
	dib0700_set_gpio(adap->dev, GPIO10, GPIO_OUT, 1);
3005
	msleep(20);
3006
	dib0700_set_gpio(adap->dev, GPIO0, GPIO_OUT, 1);
3007

3008 3009 3010
	if (state->dib7000p_ops.i2c_enumeration(&adap->dev->i2c_adap, 1, 0x10, &nim7090_dib7000p_config) != 0) {
		err("%s: state->dib7000p_ops.i2c_enumeration failed.  Cannot continue\n", __func__);
		dvb_detach(&state->dib7000p_ops);
3011 3012
		return -ENODEV;
	}
3013
	adap->fe_adap[0].fe = state->dib7000p_ops.init(&adap->dev->i2c_adap, 0x80, &nim7090_dib7000p_config);
3014

3015
	return adap->fe_adap[0].fe == NULL ?  -ENODEV : 0;
3016 3017
}

3018
static int nim7090_tuner_attach(struct dvb_usb_adapter *adap)
3019
{
3020
	struct dib0700_adapter_state *st = adap->priv;
3021 3022 3023 3024 3025
	struct i2c_adapter *tun_i2c = st->dib7000p_ops.get_i2c_tuner(adap->fe_adap[0].fe);

	nim7090_dib0090_config.reset = st->dib7000p_ops.tuner_sleep,
	nim7090_dib0090_config.sleep = st->dib7000p_ops.tuner_sleep,
	nim7090_dib0090_config.get_adc_power = st->dib7000p_ops.get_adc_power;
3026

3027
	if (dvb_attach(dib0090_register, adap->fe_adap[0].fe, tun_i2c, &nim7090_dib0090_config) == NULL)
3028
		return -ENODEV;
3029

3030
	st->dib7000p_ops.set_gpio(adap->fe_adap[0].fe, 8, 0, 1);
3031

3032 3033
	st->set_param_save = adap->fe_adap[0].fe->ops.tuner_ops.set_params;
	adap->fe_adap[0].fe->ops.tuner_ops.set_params = dib7090_agc_startup;
3034
	return 0;
3035 3036
}

3037
static int tfe7090pvr_frontend0_attach(struct dvb_usb_adapter *adap)
3038
{
3039
	struct dib0700_state *st = adap->dev->priv;
3040 3041 3042 3043
	struct dib0700_adapter_state *state = adap->priv;

	if (!dvb_attach(dib7000p_attach, &state->dib7000p_ops))
		return -ENODEV;
3044 3045 3046 3047

	/* The TFE7090 requires the dib0700 to not be in master mode */
	st->disable_streaming_master_mode = 1;

3048
	dib0700_set_gpio(adap->dev, GPIO6, GPIO_OUT, 1);
3049
	msleep(20);
3050 3051 3052 3053 3054
	dib0700_set_gpio(adap->dev, GPIO9, GPIO_OUT, 1);
	dib0700_set_gpio(adap->dev, GPIO4, GPIO_OUT, 1);
	dib0700_set_gpio(adap->dev, GPIO7, GPIO_OUT, 1);
	dib0700_set_gpio(adap->dev, GPIO10, GPIO_OUT, 0);

3055
	msleep(20);
3056
	dib0700_set_gpio(adap->dev, GPIO10, GPIO_OUT, 1);
3057
	msleep(20);
3058 3059
	dib0700_set_gpio(adap->dev, GPIO0, GPIO_OUT, 1);

3060
	/* initialize IC 0 */
3061 3062 3063
	if (state->dib7000p_ops.i2c_enumeration(&adap->dev->i2c_adap, 1, 0x20, &tfe7090pvr_dib7000p_config[0]) != 0) {
		err("%s: state->dib7000p_ops.i2c_enumeration failed.  Cannot continue\n", __func__);
		dvb_detach(&state->dib7000p_ops);
3064 3065
		return -ENODEV;
	}
3066

3067
	dib0700_set_i2c_speed(adap->dev, 340);
3068
	adap->fe_adap[0].fe = state->dib7000p_ops.init(&adap->dev->i2c_adap, 0x90, &tfe7090pvr_dib7000p_config[0]);
3069
	if (adap->fe_adap[0].fe == NULL)
3070 3071
		return -ENODEV;

3072
	state->dib7000p_ops.slave_reset(adap->fe_adap[0].fe);
3073

3074 3075 3076 3077 3078 3079
	return 0;
}

static int tfe7090pvr_frontend1_attach(struct dvb_usb_adapter *adap)
{
	struct i2c_adapter *i2c;
3080
	struct dib0700_adapter_state *state = adap->priv;
3081

3082
	if (adap->dev->adapter[0].fe_adap[0].fe == NULL) {
3083 3084 3085 3086
		err("the master dib7090 has to be initialized first");
		return -ENODEV; /* the master device has not been initialized */
	}

3087 3088 3089 3090 3091 3092 3093
	if (!dvb_attach(dib7000p_attach, &state->dib7000p_ops))
		return -ENODEV;

	i2c = state->dib7000p_ops.get_i2c_master(adap->dev->adapter[0].fe_adap[0].fe, DIBX000_I2C_INTERFACE_GPIO_6_7, 1);
	if (state->dib7000p_ops.i2c_enumeration(i2c, 1, 0x10, &tfe7090pvr_dib7000p_config[1]) != 0) {
		err("%s: state->dib7000p_ops.i2c_enumeration failed.  Cannot continue\n", __func__);
		dvb_detach(&state->dib7000p_ops);
3094 3095 3096
		return -ENODEV;
	}

3097
	adap->fe_adap[0].fe = state->dib7000p_ops.init(i2c, 0x92, &tfe7090pvr_dib7000p_config[1]);
3098 3099
	dib0700_set_i2c_speed(adap->dev, 200);

3100
	return adap->fe_adap[0].fe == NULL ? -ENODEV : 0;
3101 3102 3103 3104 3105
}

static int tfe7090pvr_tuner0_attach(struct dvb_usb_adapter *adap)
{
	struct dib0700_adapter_state *st = adap->priv;
3106 3107 3108 3109 3110
	struct i2c_adapter *tun_i2c = st->dib7000p_ops.get_i2c_tuner(adap->fe_adap[0].fe);

	tfe7090pvr_dib0090_config[0].reset = st->dib7000p_ops.tuner_sleep;
	tfe7090pvr_dib0090_config[0].sleep = st->dib7000p_ops.tuner_sleep;
	tfe7090pvr_dib0090_config[0].get_adc_power = st->dib7000p_ops.get_adc_power;
3111

3112
	if (dvb_attach(dib0090_register, adap->fe_adap[0].fe, tun_i2c, &tfe7090pvr_dib0090_config[0]) == NULL)
3113 3114
		return -ENODEV;

3115
	st->dib7000p_ops.set_gpio(adap->fe_adap[0].fe, 8, 0, 1);
3116

3117 3118
	st->set_param_save = adap->fe_adap[0].fe->ops.tuner_ops.set_params;
	adap->fe_adap[0].fe->ops.tuner_ops.set_params = dib7090_agc_startup;
3119 3120 3121 3122 3123 3124
	return 0;
}

static int tfe7090pvr_tuner1_attach(struct dvb_usb_adapter *adap)
{
	struct dib0700_adapter_state *st = adap->priv;
3125 3126 3127 3128 3129
	struct i2c_adapter *tun_i2c = st->dib7000p_ops.get_i2c_tuner(adap->fe_adap[0].fe);

	tfe7090pvr_dib0090_config[1].reset = st->dib7000p_ops.tuner_sleep;
	tfe7090pvr_dib0090_config[1].sleep = st->dib7000p_ops.tuner_sleep;
	tfe7090pvr_dib0090_config[1].get_adc_power = st->dib7000p_ops.get_adc_power;
3130

3131
	if (dvb_attach(dib0090_register, adap->fe_adap[0].fe, tun_i2c, &tfe7090pvr_dib0090_config[1]) == NULL)
3132 3133
		return -ENODEV;

3134
	st->dib7000p_ops.set_gpio(adap->fe_adap[0].fe, 8, 0, 1);
3135

3136 3137
	st->set_param_save = adap->fe_adap[0].fe->ops.tuner_ops.set_params;
	adap->fe_adap[0].fe->ops.tuner_ops.set_params = dib7090_agc_startup;
3138
	return 0;
3139
}
3140

3141
static int tfe7790p_frontend_attach(struct dvb_usb_adapter *adap)
3142 3143
{
	struct dib0700_state *st = adap->dev->priv;
3144 3145 3146 3147
	struct dib0700_adapter_state *state = adap->priv;

	if (!dvb_attach(dib7000p_attach, &state->dib7000p_ops))
		return -ENODEV;
3148

3149
	/* The TFE7790P requires the dib0700 to not be in master mode */
3150 3151 3152 3153 3154 3155 3156 3157 3158 3159 3160 3161 3162 3163
	st->disable_streaming_master_mode = 1;

	dib0700_set_gpio(adap->dev, GPIO6, GPIO_OUT, 1);
	msleep(20);
	dib0700_set_gpio(adap->dev, GPIO9, GPIO_OUT, 1);
	dib0700_set_gpio(adap->dev, GPIO4, GPIO_OUT, 1);
	dib0700_set_gpio(adap->dev, GPIO7, GPIO_OUT, 1);
	dib0700_set_gpio(adap->dev, GPIO10, GPIO_OUT, 0);
	msleep(20);
	dib0700_ctrl_clock(adap->dev, 72, 1);
	dib0700_set_gpio(adap->dev, GPIO10, GPIO_OUT, 1);
	msleep(20);
	dib0700_set_gpio(adap->dev, GPIO0, GPIO_OUT, 1);

3164
	if (state->dib7000p_ops.i2c_enumeration(&adap->dev->i2c_adap,
3165
				1, 0x10, &tfe7790p_dib7000p_config) != 0) {
3166
		err("%s: state->dib7000p_ops.i2c_enumeration failed.  Cannot continue\n",
3167
				__func__);
3168
		dvb_detach(&state->dib7000p_ops);
3169 3170
		return -ENODEV;
	}
3171
	adap->fe_adap[0].fe = state->dib7000p_ops.init(&adap->dev->i2c_adap,
3172
			0x80, &tfe7790p_dib7000p_config);
3173 3174 3175 3176

	return adap->fe_adap[0].fe == NULL ?  -ENODEV : 0;
}

3177
static int tfe7790p_tuner_attach(struct dvb_usb_adapter *adap)
3178 3179 3180
{
	struct dib0700_adapter_state *st = adap->priv;
	struct i2c_adapter *tun_i2c =
3181 3182 3183 3184 3185 3186
		st->dib7000p_ops.get_i2c_tuner(adap->fe_adap[0].fe);


	tfe7790p_dib0090_config.reset = st->dib7000p_ops.tuner_sleep;
	tfe7790p_dib0090_config.sleep = st->dib7000p_ops.tuner_sleep;
	tfe7790p_dib0090_config.get_adc_power = st->dib7000p_ops.get_adc_power;
3187 3188

	if (dvb_attach(dib0090_register, adap->fe_adap[0].fe, tun_i2c,
3189
				&tfe7790p_dib0090_config) == NULL)
3190 3191
		return -ENODEV;

3192
	st->dib7000p_ops.set_gpio(adap->fe_adap[0].fe, 8, 0, 1);
3193 3194 3195 3196 3197 3198

	st->set_param_save = adap->fe_adap[0].fe->ops.tuner_ops.set_params;
	adap->fe_adap[0].fe->ops.tuner_ops.set_params = dib7090_agc_startup;
	return 0;
}

3199 3200 3201 3202 3203 3204 3205 3206
/* STK7070PD */
static struct dib7000p_config stk7070pd_dib7000p_config[2] = {
	{
		.output_mpeg2_in_188_bytes = 1,

		.agc_config_count = 1,
		.agc = &dib7070_agc_config,
		.bw  = &dib7070_bw_config_12_mhz,
3207 3208
		.tuner_is_baseband = 1,
		.spur_protect = 1,
3209 3210 3211 3212 3213 3214 3215 3216 3217 3218 3219 3220

		.gpio_dir = DIB7000P_GPIO_DEFAULT_DIRECTIONS,
		.gpio_val = DIB7000P_GPIO_DEFAULT_VALUES,
		.gpio_pwm_pos = DIB7000P_GPIO_DEFAULT_PWM_POS,

		.hostbus_diversity = 1,
	}, {
		.output_mpeg2_in_188_bytes = 1,

		.agc_config_count = 1,
		.agc = &dib7070_agc_config,
		.bw  = &dib7070_bw_config_12_mhz,
3221 3222
		.tuner_is_baseband = 1,
		.spur_protect = 1,
3223 3224 3225 3226 3227 3228 3229 3230 3231

		.gpio_dir = DIB7000P_GPIO_DEFAULT_DIRECTIONS,
		.gpio_val = DIB7000P_GPIO_DEFAULT_VALUES,
		.gpio_pwm_pos = DIB7000P_GPIO_DEFAULT_PWM_POS,

		.hostbus_diversity = 1,
	}
};

3232
static void stk7070pd_init(struct dvb_usb_device *dev)
3233
{
3234
	dib0700_set_gpio(dev, GPIO6, GPIO_OUT, 1);
3235
	msleep(10);
3236 3237 3238 3239
	dib0700_set_gpio(dev, GPIO9, GPIO_OUT, 1);
	dib0700_set_gpio(dev, GPIO4, GPIO_OUT, 1);
	dib0700_set_gpio(dev, GPIO7, GPIO_OUT, 1);
	dib0700_set_gpio(dev, GPIO10, GPIO_OUT, 0);
3240

3241
	dib0700_ctrl_clock(dev, 72, 1);
3242 3243

	msleep(10);
3244 3245 3246 3247 3248
	dib0700_set_gpio(dev, GPIO10, GPIO_OUT, 1);
}

static int stk7070pd_frontend_attach0(struct dvb_usb_adapter *adap)
{
3249 3250 3251 3252 3253
	struct dib0700_adapter_state *state = adap->priv;

	if (!dvb_attach(dib7000p_attach, &state->dib7000p_ops))
		return -ENODEV;

3254 3255
	stk7070pd_init(adap->dev);

3256 3257 3258
	msleep(10);
	dib0700_set_gpio(adap->dev, GPIO0, GPIO_OUT, 1);

3259
	if (state->dib7000p_ops.i2c_enumeration(&adap->dev->i2c_adap, 2, 18,
3260
				     stk7070pd_dib7000p_config) != 0) {
3261
		err("%s: state->dib7000p_ops.i2c_enumeration failed.  Cannot continue\n",
3262
		    __func__);
3263
		dvb_detach(&state->dib7000p_ops);
3264 3265
		return -ENODEV;
	}
3266

3267
	adap->fe_adap[0].fe = state->dib7000p_ops.init(&adap->dev->i2c_adap, 0x80, &stk7070pd_dib7000p_config[0]);
3268
	return adap->fe_adap[0].fe == NULL ? -ENODEV : 0;
3269 3270 3271 3272
}

static int stk7070pd_frontend_attach1(struct dvb_usb_adapter *adap)
{
3273 3274 3275 3276 3277 3278
	struct dib0700_adapter_state *state = adap->priv;

	if (!dvb_attach(dib7000p_attach, &state->dib7000p_ops))
		return -ENODEV;

	adap->fe_adap[0].fe = state->dib7000p_ops.init(&adap->dev->i2c_adap, 0x82, &stk7070pd_dib7000p_config[1]);
3279
	return adap->fe_adap[0].fe == NULL ? -ENODEV : 0;
3280 3281
}

3282 3283 3284 3285 3286 3287 3288 3289 3290 3291 3292 3293 3294 3295 3296 3297 3298 3299 3300 3301 3302 3303 3304 3305 3306 3307 3308 3309 3310
static int novatd_read_status_override(struct dvb_frontend *fe,
		fe_status_t *stat)
{
	struct dvb_usb_adapter *adap = fe->dvb->priv;
	struct dvb_usb_device *dev = adap->dev;
	struct dib0700_state *state = dev->priv;
	int ret;

	ret = state->read_status(fe, stat);

	if (!ret)
		dib0700_set_gpio(dev, adap->id == 0 ? GPIO1 : GPIO0, GPIO_OUT,
				!!(*stat & FE_HAS_LOCK));

	return ret;
}

static int novatd_sleep_override(struct dvb_frontend* fe)
{
	struct dvb_usb_adapter *adap = fe->dvb->priv;
	struct dvb_usb_device *dev = adap->dev;
	struct dib0700_state *state = dev->priv;

	/* turn off LED */
	dib0700_set_gpio(dev, adap->id == 0 ? GPIO1 : GPIO0, GPIO_OUT, 0);

	return state->sleep(fe);
}

3311 3312 3313 3314 3315 3316 3317 3318 3319
/**
 * novatd_frontend_attach - Nova-TD specific attach
 *
 * Nova-TD has GPIO0, 1 and 2 for LEDs. So do not fiddle with them except for
 * information purposes.
 */
static int novatd_frontend_attach(struct dvb_usb_adapter *adap)
{
	struct dvb_usb_device *dev = adap->dev;
3320
	struct dib0700_state *st = dev->priv;
3321 3322 3323 3324
	struct dib0700_adapter_state *state = adap->priv;

	if (!dvb_attach(dib7000p_attach, &state->dib7000p_ops))
		return -ENODEV;
3325 3326 3327 3328 3329 3330 3331 3332 3333

	if (adap->id == 0) {
		stk7070pd_init(dev);

		/* turn the power LED on, the other two off (just in case) */
		dib0700_set_gpio(dev, GPIO0, GPIO_OUT, 0);
		dib0700_set_gpio(dev, GPIO1, GPIO_OUT, 0);
		dib0700_set_gpio(dev, GPIO2, GPIO_OUT, 1);

3334
		if (state->dib7000p_ops.i2c_enumeration(&dev->i2c_adap, 2, 18,
3335
					     stk7070pd_dib7000p_config) != 0) {
3336
			err("%s: state->dib7000p_ops.i2c_enumeration failed.  Cannot continue\n",
3337
			    __func__);
3338
			dvb_detach(&state->dib7000p_ops);
3339 3340 3341 3342
			return -ENODEV;
		}
	}

3343
	adap->fe_adap[0].fe = state->dib7000p_ops.init(&dev->i2c_adap,
3344 3345
			adap->id == 0 ? 0x80 : 0x82,
			&stk7070pd_dib7000p_config[adap->id]);
3346 3347 3348 3349 3350 3351 3352 3353 3354 3355

	if (adap->fe_adap[0].fe == NULL)
		return -ENODEV;

	st->read_status = adap->fe_adap[0].fe->ops.read_status;
	adap->fe_adap[0].fe->ops.read_status = novatd_read_status_override;
	st->sleep = adap->fe_adap[0].fe->ops.sleep;
	adap->fe_adap[0].fe->ops.sleep = novatd_sleep_override;

	return 0;
3356 3357
}

3358 3359 3360 3361 3362 3363 3364 3365 3366 3367 3368 3369 3370 3371 3372 3373 3374 3375 3376 3377 3378 3379 3380 3381 3382 3383 3384 3385 3386 3387 3388 3389 3390 3391 3392 3393 3394 3395 3396 3397 3398 3399 3400 3401 3402 3403 3404 3405 3406 3407 3408 3409
/* S5H1411 */
static struct s5h1411_config pinnacle_801e_config = {
	.output_mode   = S5H1411_PARALLEL_OUTPUT,
	.gpio          = S5H1411_GPIO_OFF,
	.mpeg_timing   = S5H1411_MPEGTIMING_NONCONTINOUS_NONINVERTING_CLOCK,
	.qam_if        = S5H1411_IF_44000,
	.vsb_if        = S5H1411_IF_44000,
	.inversion     = S5H1411_INVERSION_OFF,
	.status_mode   = S5H1411_DEMODLOCKING
};

/* Pinnacle PCTV HD Pro 801e GPIOs map:
   GPIO0  - currently unknown
   GPIO1  - xc5000 tuner reset
   GPIO2  - CX25843 sleep
   GPIO3  - currently unknown
   GPIO4  - currently unknown
   GPIO6  - currently unknown
   GPIO7  - currently unknown
   GPIO9  - currently unknown
   GPIO10 - CX25843 reset
 */
static int s5h1411_frontend_attach(struct dvb_usb_adapter *adap)
{
	struct dib0700_state *st = adap->dev->priv;

	/* Make use of the new i2c functions from FW 1.20 */
	st->fw_use_new_i2c_api = 1;

	/* The s5h1411 requires the dib0700 to not be in master mode */
	st->disable_streaming_master_mode = 1;

	/* All msleep values taken from Windows USB trace */
	dib0700_set_gpio(adap->dev, GPIO0, GPIO_OUT, 0);
	dib0700_set_gpio(adap->dev, GPIO3, GPIO_OUT, 0);
	dib0700_set_gpio(adap->dev, GPIO6, GPIO_OUT, 1);
	msleep(400);
	dib0700_set_gpio(adap->dev, GPIO10, GPIO_OUT, 0);
	msleep(60);
	dib0700_set_gpio(adap->dev, GPIO10, GPIO_OUT, 1);
	msleep(30);
	dib0700_set_gpio(adap->dev, GPIO0, GPIO_OUT, 1);
	dib0700_set_gpio(adap->dev, GPIO9, GPIO_OUT, 1);
	dib0700_set_gpio(adap->dev, GPIO4, GPIO_OUT, 1);
	dib0700_set_gpio(adap->dev, GPIO7, GPIO_OUT, 1);
	dib0700_set_gpio(adap->dev, GPIO2, GPIO_OUT, 0);
	msleep(30);

	/* Put the CX25843 to sleep for now since we're in digital mode */
	dib0700_set_gpio(adap->dev, GPIO2, GPIO_OUT, 1);

	/* GPIOs are initialized, do the attach */
3410
	adap->fe_adap[0].fe = dvb_attach(s5h1411_attach, &pinnacle_801e_config,
3411
			      &adap->dev->i2c_adap);
3412
	return adap->fe_adap[0].fe == NULL ? -ENODEV : 0;
3413 3414
}

3415 3416
static int dib0700_xc5000_tuner_callback(void *priv, int component,
					 int command, int arg)
3417 3418 3419
{
	struct dvb_usb_adapter *adap = priv;

3420 3421 3422
	if (command == XC5000_TUNER_RESET) {
		/* Reset the tuner */
		dib0700_set_gpio(adap->dev, GPIO1, GPIO_OUT, 0);
3423
		msleep(10);
3424
		dib0700_set_gpio(adap->dev, GPIO1, GPIO_OUT, 1);
3425
		msleep(10);
3426 3427 3428 3429
	} else {
		err("xc5000: unknown tuner callback command: %d\n", command);
		return -EINVAL;
	}
3430 3431 3432 3433 3434 3435 3436 3437 3438 3439 3440

	return 0;
}

static struct xc5000_config s5h1411_xc5000_tunerconfig = {
	.i2c_address      = 0x64,
	.if_khz           = 5380,
};

static int xc5000_tuner_attach(struct dvb_usb_adapter *adap)
{
3441
	/* FIXME: generalize & move to common area */
3442
	adap->fe_adap[0].fe->callback = dib0700_xc5000_tuner_callback;
3443

3444
	return dvb_attach(xc5000_attach, adap->fe_adap[0].fe, &adap->dev->i2c_adap,
3445
			  &s5h1411_xc5000_tunerconfig)
3446 3447 3448
		== NULL ? -ENODEV : 0;
}

3449 3450 3451 3452
static int dib0700_xc4000_tuner_callback(void *priv, int component,
					 int command, int arg)
{
	struct dvb_usb_adapter *adap = priv;
3453
	struct dib0700_adapter_state *state = adap->priv;
3454 3455 3456

	if (command == XC4000_TUNER_RESET) {
		/* Reset the tuner */
3457
		state->dib7000p_ops.set_gpio(adap->fe_adap[0].fe, 8, 0, 0);
3458
		msleep(10);
3459
		state->dib7000p_ops.set_gpio(adap->fe_adap[0].fe, 8, 0, 1);
3460 3461 3462 3463 3464 3465 3466 3467
	} else {
		err("xc4000: unknown tuner callback command: %d\n", command);
		return -EINVAL;
	}

	return 0;
}

3468 3469 3470 3471 3472 3473 3474 3475 3476 3477 3478 3479 3480 3481 3482 3483 3484 3485 3486 3487 3488 3489 3490 3491
static struct dibx000_agc_config stk7700p_7000p_xc4000_agc_config = {
	.band_caps = BAND_UHF | BAND_VHF,
	.setup = 0x64,
	.inv_gain = 0x02c8,
	.time_stabiliz = 0x15,
	.alpha_level = 0x00,
	.thlock = 0x76,
	.wbd_inv = 0x01,
	.wbd_ref = 0x0b33,
	.wbd_sel = 0x00,
	.wbd_alpha = 0x02,
	.agc1_max = 0x00,
	.agc1_min = 0x00,
	.agc2_max = 0x9b26,
	.agc2_min = 0x26ca,
	.agc1_pt1 = 0x00,
	.agc1_pt2 = 0x00,
	.agc1_pt3 = 0x00,
	.agc1_slope1 = 0x00,
	.agc1_slope2 = 0x00,
	.agc2_pt1 = 0x00,
	.agc2_pt2 = 0x80,
	.agc2_slope1 = 0x1d,
	.agc2_slope2 = 0x1d,
3492
	.alpha_mant = 0x11,
3493 3494 3495 3496 3497 3498
	.alpha_exp = 0x1b,
	.beta_mant = 0x17,
	.beta_exp = 0x33,
	.perform_agc_softsplit = 0x00,
};

3499
static struct dibx000_bandwidth_config stk7700p_xc4000_pll_config = {
3500 3501 3502 3503 3504 3505 3506 3507
	60000, 30000,	/* internal, sampling */
	1, 8, 3, 1, 0,	/* pll_cfg: prediv, ratio, range, reset, bypass */
	0, 0, 1, 1, 0,	/* misc: refdiv, bypclk_div, IO_CLK_en_core, */
			/* ADClkSrc, modulo */
	(3 << 14) | (1 << 12) | 524,	/* sad_cfg: refsel, sel, freq_15k */
	39370534,	/* ifreq */
	20452225,	/* timf */
	30000000	/* xtal */
3508 3509
};

3510 3511
/* FIXME: none of these inputs are validated yet */
static struct dib7000p_config pctv_340e_config = {
3512
	.output_mpeg2_in_188_bytes = 1,
3513 3514

	.agc_config_count = 1,
3515
	.agc = &stk7700p_7000p_xc4000_agc_config,
3516
	.bw  = &stk7700p_xc4000_pll_config,
3517 3518 3519 3520 3521 3522 3523 3524 3525 3526 3527 3528 3529 3530 3531 3532 3533 3534 3535 3536

	.gpio_dir = DIB7000M_GPIO_DEFAULT_DIRECTIONS,
	.gpio_val = DIB7000M_GPIO_DEFAULT_VALUES,
	.gpio_pwm_pos = DIB7000M_GPIO_DEFAULT_PWM_POS,
};

/* PCTV 340e GPIOs map:
   dib0700:
   GPIO2  - CX25843 sleep
   GPIO3  - CS5340 reset
   GPIO5  - IRD
   GPIO6  - Power Supply
   GPIO8  - LNA (1=off 0=on)
   GPIO10 - CX25843 reset
   dib7000:
   GPIO8  - xc4000 reset
 */
static int pctv340e_frontend_attach(struct dvb_usb_adapter *adap)
{
	struct dib0700_state *st = adap->dev->priv;
3537 3538 3539 3540
	struct dib0700_adapter_state *state = adap->priv;

	if (!dvb_attach(dib7000p_attach, &state->dib7000p_ops))
		return -ENODEV;
3541 3542 3543 3544 3545 3546 3547 3548 3549 3550 3551 3552 3553 3554 3555 3556 3557 3558 3559 3560 3561

	/* Power Supply on */
	dib0700_set_gpio(adap->dev, GPIO6,  GPIO_OUT, 0);
	msleep(50);
	dib0700_set_gpio(adap->dev, GPIO6,  GPIO_OUT, 1);
	msleep(100); /* Allow power supply to settle before probing */

	/* cx25843 reset */
	dib0700_set_gpio(adap->dev, GPIO10,  GPIO_OUT, 0);
	msleep(1); /* cx25843 datasheet say 350us required */
	dib0700_set_gpio(adap->dev, GPIO10,  GPIO_OUT, 1);

	/* LNA off for now */
	dib0700_set_gpio(adap->dev, GPIO8,  GPIO_OUT, 1);

	/* Put the CX25843 to sleep for now since we're in digital mode */
	dib0700_set_gpio(adap->dev, GPIO2, GPIO_OUT, 1);

	/* FIXME: not verified yet */
	dib0700_ctrl_clock(adap->dev, 72, 1);

3562 3563
	msleep(500);

3564
	if (state->dib7000p_ops.dib7000pc_detection(&adap->dev->i2c_adap) == 0) {
3565
		/* Demodulator not found for some reason? */
3566
		dvb_detach(&state->dib7000p_ops);
3567 3568 3569
		return -ENODEV;
	}

3570
	adap->fe_adap[0].fe = state->dib7000p_ops.init(&adap->dev->i2c_adap, 0x12,
3571 3572 3573
			      &pctv_340e_config);
	st->is_dib7000pc = 1;

3574
	return adap->fe_adap[0].fe == NULL ? -ENODEV : 0;
3575 3576
}

3577
static struct xc4000_config dib7000p_xc4000_tunerconfig = {
3578 3579 3580 3581 3582
	.i2c_address	  = 0x61,
	.default_pm	  = 1,
	.dvb_amplitude	  = 0,
	.set_smoothedcvbs = 0,
	.if_khz		  = 5400
3583 3584 3585 3586
};

static int xc4000_tuner_attach(struct dvb_usb_adapter *adap)
{
3587
	struct i2c_adapter *tun_i2c;
3588
	struct dib0700_adapter_state *state = adap->priv;
3589 3590

	/* The xc4000 is not on the main i2c bus */
3591
	tun_i2c = state->dib7000p_ops.get_i2c_master(adap->fe_adap[0].fe,
3592 3593
					  DIBX000_I2C_INTERFACE_TUNER, 1);
	if (tun_i2c == NULL) {
3594
		printk(KERN_ERR "Could not reach tuner i2c bus\n");
3595 3596 3597 3598
		return 0;
	}

	/* Setup the reset callback */
3599
	adap->fe_adap[0].fe->callback = dib0700_xc4000_tuner_callback;
3600

3601
	return dvb_attach(xc4000_attach, adap->fe_adap[0].fe, tun_i2c,
3602
			  &dib7000p_xc4000_tunerconfig)
3603 3604 3605
		== NULL ? -ENODEV : 0;
}

3606 3607 3608 3609 3610 3611 3612 3613 3614 3615 3616 3617 3618 3619 3620 3621 3622 3623 3624 3625 3626 3627 3628 3629 3630 3631 3632 3633 3634 3635 3636 3637 3638 3639 3640 3641 3642 3643 3644 3645 3646 3647 3648 3649 3650 3651 3652 3653 3654 3655 3656
static struct lgdt3305_config hcw_lgdt3305_config = {
	.i2c_addr           = 0x0e,
	.mpeg_mode          = LGDT3305_MPEG_PARALLEL,
	.tpclk_edge         = LGDT3305_TPCLK_FALLING_EDGE,
	.tpvalid_polarity   = LGDT3305_TP_VALID_LOW,
	.deny_i2c_rptr      = 0,
	.spectral_inversion = 1,
	.qam_if_khz         = 6000,
	.vsb_if_khz         = 6000,
	.usref_8vsb         = 0x0500,
};

static struct mxl5007t_config hcw_mxl5007t_config = {
	.xtal_freq_hz = MxL_XTAL_25_MHZ,
	.if_freq_hz = MxL_IF_6_MHZ,
	.invert_if = 1,
};

/* TIGER-ATSC map:
   GPIO0  - LNA_CTR  (H: LNA power enabled, L: LNA power disabled)
   GPIO1  - ANT_SEL  (H: VPA, L: MCX)
   GPIO4  - SCL2
   GPIO6  - EN_TUNER
   GPIO7  - SDA2
   GPIO10 - DEM_RST

   MXL is behind LG's i2c repeater.  LG is on SCL2/SDA2 gpios on the DIB
 */
static int lgdt3305_frontend_attach(struct dvb_usb_adapter *adap)
{
	struct dib0700_state *st = adap->dev->priv;

	/* Make use of the new i2c functions from FW 1.20 */
	st->fw_use_new_i2c_api = 1;

	st->disable_streaming_master_mode = 1;

	/* fe power enable */
	dib0700_set_gpio(adap->dev, GPIO6, GPIO_OUT, 0);
	msleep(30);
	dib0700_set_gpio(adap->dev, GPIO6, GPIO_OUT, 1);
	msleep(30);

	/* demod reset */
	dib0700_set_gpio(adap->dev, GPIO10, GPIO_OUT, 1);
	msleep(30);
	dib0700_set_gpio(adap->dev, GPIO10, GPIO_OUT, 0);
	msleep(30);
	dib0700_set_gpio(adap->dev, GPIO10, GPIO_OUT, 1);
	msleep(30);

3657
	adap->fe_adap[0].fe = dvb_attach(lgdt3305_attach,
3658 3659 3660
			      &hcw_lgdt3305_config,
			      &adap->dev->i2c_adap);

3661
	return adap->fe_adap[0].fe == NULL ? -ENODEV : 0;
3662 3663 3664 3665
}

static int mxl5007t_tuner_attach(struct dvb_usb_adapter *adap)
{
3666
	return dvb_attach(mxl5007t_attach, adap->fe_adap[0].fe,
3667 3668 3669 3670 3671
			  &adap->dev->i2c_adap, 0x60,
			  &hcw_mxl5007t_config) == NULL ? -ENODEV : 0;
}


3672
/* DVB-USB and USB stuff follows */
3673
struct usb_device_id dib0700_usb_id_table[] = {
3674
/* 0 */	{ USB_DEVICE(USB_VID_DIBCOM,    USB_PID_DIBCOM_STK7700P) },
3675 3676 3677 3678
	{ USB_DEVICE(USB_VID_DIBCOM,    USB_PID_DIBCOM_STK7700P_PC) },
	{ USB_DEVICE(USB_VID_HAUPPAUGE, USB_PID_HAUPPAUGE_NOVA_T_500) },
	{ USB_DEVICE(USB_VID_HAUPPAUGE, USB_PID_HAUPPAUGE_NOVA_T_500_2) },
	{ USB_DEVICE(USB_VID_HAUPPAUGE, USB_PID_HAUPPAUGE_NOVA_T_STICK) },
3679
/* 5 */	{ USB_DEVICE(USB_VID_AVERMEDIA, USB_PID_AVERMEDIA_VOLAR) },
3680 3681 3682 3683
	{ USB_DEVICE(USB_VID_COMPRO,    USB_PID_COMPRO_VIDEOMATE_U500) },
	{ USB_DEVICE(USB_VID_UNIWILL,   USB_PID_UNIWILL_STK7700P) },
	{ USB_DEVICE(USB_VID_LEADTEK,   USB_PID_WINFAST_DTV_DONGLE_STK7700P) },
	{ USB_DEVICE(USB_VID_HAUPPAUGE, USB_PID_HAUPPAUGE_NOVA_T_STICK_2) },
3684
/* 10 */{ USB_DEVICE(USB_VID_AVERMEDIA, USB_PID_AVERMEDIA_VOLAR_2) },
3685 3686 3687 3688 3689
	{ USB_DEVICE(USB_VID_PINNACLE,  USB_PID_PINNACLE_PCTV2000E) },
	{ USB_DEVICE(USB_VID_TERRATEC,
			USB_PID_TERRATEC_CINERGY_DT_XS_DIVERSITY) },
	{ USB_DEVICE(USB_VID_HAUPPAUGE, USB_PID_HAUPPAUGE_NOVA_TD_STICK) },
	{ USB_DEVICE(USB_VID_DIBCOM,    USB_PID_DIBCOM_STK7700D) },
3690
/* 15 */{ USB_DEVICE(USB_VID_DIBCOM,    USB_PID_DIBCOM_STK7070P) },
3691 3692 3693 3694 3695
	{ USB_DEVICE(USB_VID_PINNACLE,  USB_PID_PINNACLE_PCTV_DVB_T_FLASH) },
	{ USB_DEVICE(USB_VID_DIBCOM,    USB_PID_DIBCOM_STK7070PD) },
	{ USB_DEVICE(USB_VID_PINNACLE,
			USB_PID_PINNACLE_PCTV_DUAL_DIVERSITY_DVB_T) },
	{ USB_DEVICE(USB_VID_COMPRO,    USB_PID_COMPRO_VIDEOMATE_U500_PC) },
3696
/* 20 */{ USB_DEVICE(USB_VID_AVERMEDIA, USB_PID_AVERMEDIA_EXPRESS) },
3697 3698 3699 3700 3701 3702 3703 3704 3705 3706 3707 3708
	{ USB_DEVICE(USB_VID_GIGABYTE,  USB_PID_GIGABYTE_U7000) },
	{ USB_DEVICE(USB_VID_ULTIMA_ELECTRONIC, USB_PID_ARTEC_T14BR) },
	{ USB_DEVICE(USB_VID_ASUS,      USB_PID_ASUS_U3000) },
	{ USB_DEVICE(USB_VID_ASUS,      USB_PID_ASUS_U3100) },
/* 25 */{ USB_DEVICE(USB_VID_HAUPPAUGE, USB_PID_HAUPPAUGE_NOVA_T_STICK_3) },
	{ USB_DEVICE(USB_VID_HAUPPAUGE, USB_PID_HAUPPAUGE_MYTV_T) },
	{ USB_DEVICE(USB_VID_TERRATEC,  USB_PID_TERRATEC_CINERGY_HT_USB_XE) },
	{ USB_DEVICE(USB_VID_PINNACLE,	USB_PID_PINNACLE_EXPRESSCARD_320CX) },
	{ USB_DEVICE(USB_VID_PINNACLE,	USB_PID_PINNACLE_PCTV72E) },
/* 30 */{ USB_DEVICE(USB_VID_PINNACLE,	USB_PID_PINNACLE_PCTV73E) },
	{ USB_DEVICE(USB_VID_YUAN,	USB_PID_YUAN_EC372S) },
	{ USB_DEVICE(USB_VID_TERRATEC,	USB_PID_TERRATEC_CINERGY_HT_EXPRESS) },
3709
	{ USB_DEVICE(USB_VID_TERRATEC,	USB_PID_TERRATEC_CINERGY_T_XXS) },
3710
	{ USB_DEVICE(USB_VID_LEADTEK,   USB_PID_WINFAST_DTV_DONGLE_STK7700P_2) },
3711
/* 35 */{ USB_DEVICE(USB_VID_HAUPPAUGE, USB_PID_HAUPPAUGE_NOVA_TD_STICK_52009) },
3712
	{ USB_DEVICE(USB_VID_HAUPPAUGE, USB_PID_HAUPPAUGE_NOVA_T_500_3) },
3713
	{ USB_DEVICE(USB_VID_GIGABYTE,  USB_PID_GIGABYTE_U8000) },
3714
	{ USB_DEVICE(USB_VID_YUAN,      USB_PID_YUAN_STK7700PH) },
3715
	{ USB_DEVICE(USB_VID_ASUS,	USB_PID_ASUS_U3000H) },
3716
/* 40 */{ USB_DEVICE(USB_VID_PINNACLE,  USB_PID_PINNACLE_PCTV801E) },
3717
	{ USB_DEVICE(USB_VID_PINNACLE,  USB_PID_PINNACLE_PCTV801E_SE) },
3718
	{ USB_DEVICE(USB_VID_TERRATEC,	USB_PID_TERRATEC_CINERGY_T_EXPRESS) },
3719 3720
	{ USB_DEVICE(USB_VID_TERRATEC,
			USB_PID_TERRATEC_CINERGY_DT_XS_DIVERSITY_2) },
3721
	{ USB_DEVICE(USB_VID_SONY,	USB_PID_SONY_PLAYTV) },
3722
/* 45 */{ USB_DEVICE(USB_VID_YUAN,      USB_PID_YUAN_PD378S) },
3723 3724
	{ USB_DEVICE(USB_VID_HAUPPAUGE, USB_PID_HAUPPAUGE_TIGER_ATSC) },
	{ USB_DEVICE(USB_VID_HAUPPAUGE, USB_PID_HAUPPAUGE_TIGER_ATSC_B210) },
3725
	{ USB_DEVICE(USB_VID_YUAN,	USB_PID_YUAN_MC770) },
3726
	{ USB_DEVICE(USB_VID_ELGATO,	USB_PID_ELGATO_EYETV_DTT) },
3727
/* 50 */{ USB_DEVICE(USB_VID_ELGATO,	USB_PID_ELGATO_EYETV_DTT_Dlx) },
3728
	{ USB_DEVICE(USB_VID_LEADTEK,   USB_PID_WINFAST_DTV_DONGLE_H) },
3729 3730
	{ USB_DEVICE(USB_VID_TERRATEC,	USB_PID_TERRATEC_T3) },
	{ USB_DEVICE(USB_VID_TERRATEC,	USB_PID_TERRATEC_T5) },
3731
	{ USB_DEVICE(USB_VID_YUAN,      USB_PID_YUAN_STK7700D) },
3732 3733
/* 55 */{ USB_DEVICE(USB_VID_YUAN,	USB_PID_YUAN_STK7700D_2) },
	{ USB_DEVICE(USB_VID_PINNACLE,	USB_PID_PINNACLE_PCTV73A) },
3734 3735
	{ USB_DEVICE(USB_VID_PCTV,	USB_PID_PINNACLE_PCTV73ESE) },
	{ USB_DEVICE(USB_VID_PCTV,	USB_PID_PINNACLE_PCTV282E) },
3736
	{ USB_DEVICE(USB_VID_DIBCOM,	USB_PID_DIBCOM_STK7770P) },
3737
/* 60 */{ USB_DEVICE(USB_VID_TERRATEC,	USB_PID_TERRATEC_CINERGY_T_XXS_2) },
3738 3739
	{ USB_DEVICE(USB_VID_DIBCOM,    USB_PID_DIBCOM_STK807XPVR) },
	{ USB_DEVICE(USB_VID_DIBCOM,    USB_PID_DIBCOM_STK807XP) },
3740
	{ USB_DEVICE_VER(USB_VID_PIXELVIEW, USB_PID_PIXELVIEW_SBTVD, 0x000, 0x3f00) },
3741
	{ USB_DEVICE(USB_VID_EVOLUTEPC, USB_PID_TVWAY_PLUS) },
3742
/* 65 */{ USB_DEVICE(USB_VID_PINNACLE,	USB_PID_PINNACLE_PCTV73ESE) },
3743
	{ USB_DEVICE(USB_VID_PINNACLE,	USB_PID_PINNACLE_PCTV282E) },
3744
	{ USB_DEVICE(USB_VID_DIBCOM,    USB_PID_DIBCOM_STK8096GP) },
3745
	{ USB_DEVICE(USB_VID_ELGATO,    USB_PID_ELGATO_EYETV_DIVERSITY) },
3746 3747 3748 3749 3750
	{ USB_DEVICE(USB_VID_DIBCOM,    USB_PID_DIBCOM_NIM9090M) },
/* 70 */{ USB_DEVICE(USB_VID_DIBCOM,    USB_PID_DIBCOM_NIM8096MD) },
	{ USB_DEVICE(USB_VID_DIBCOM,    USB_PID_DIBCOM_NIM9090MD) },
	{ USB_DEVICE(USB_VID_DIBCOM,    USB_PID_DIBCOM_NIM7090) },
	{ USB_DEVICE(USB_VID_DIBCOM,    USB_PID_DIBCOM_TFE7090PVR) },
3751
	{ USB_DEVICE(USB_VID_TECHNISAT, USB_PID_TECHNISAT_AIRSTAR_TELESTICK_2) },
3752
/* 75 */{ USB_DEVICE(USB_VID_MEDION,    USB_PID_CREATIX_CTX1921) },
3753
	{ USB_DEVICE(USB_VID_PINNACLE,  USB_PID_PINNACLE_PCTV340E) },
3754
	{ USB_DEVICE(USB_VID_PINNACLE,  USB_PID_PINNACLE_PCTV340E_SE) },
3755 3756 3757
	{ USB_DEVICE(USB_VID_DIBCOM,    USB_PID_DIBCOM_TFE7790P) },
	{ USB_DEVICE(USB_VID_DIBCOM,    USB_PID_DIBCOM_TFE8096P) },
/* 80 */{ USB_DEVICE(USB_VID_ELGATO,	USB_PID_ELGATO_EYETV_DTT_2) },
3758 3759
	{ USB_DEVICE(USB_VID_PCTV,      USB_PID_PCTV_2002E) },
	{ USB_DEVICE(USB_VID_PCTV,      USB_PID_PCTV_2002E_SE) },
3760
	{ 0 }		/* Terminating entry */
3761 3762 3763 3764 3765 3766
};
MODULE_DEVICE_TABLE(usb, dib0700_usb_id_table);

#define DIB0700_DEFAULT_DEVICE_PROPERTIES \
	.caps              = DVB_USB_IS_AN_I2C_ADAPTER, \
	.usb_ctrl          = DEVICE_SPECIFIC, \
3767
	.firmware          = "dvb-usb-dib0700-1.20.fw", \
3768
	.download_firmware = dib0700_download_firmware, \
3769
	.no_reconnect      = 1, \
3770
	.size_of_priv      = sizeof(struct dib0700_state), \
3771 3772
	.i2c_algo          = &dib0700_i2c_algo, \
	.identify_state    = dib0700_identify_state
3773 3774 3775 3776 3777 3778 3779 3780 3781 3782 3783 3784 3785 3786 3787 3788 3789 3790 3791 3792 3793

#define DIB0700_DEFAULT_STREAMING_CONFIG(ep) \
	.streaming_ctrl   = dib0700_streaming_ctrl, \
	.stream = { \
		.type = USB_BULK, \
		.count = 4, \
		.endpoint = ep, \
		.u = { \
			.bulk = { \
				.buffersize = 39480, \
			} \
		} \
	}

struct dvb_usb_device_properties dib0700_devices[] = {
	{
		DIB0700_DEFAULT_DEVICE_PROPERTIES,

		.num_adapters = 1,
		.adapter = {
			{
3794 3795
			.num_frontends = 1,
			.fe = {{
3796 3797
				.caps = DVB_USB_ADAP_HAS_PID_FILTER | DVB_USB_ADAP_PID_FILTER_CAN_BE_TURNED_OFF,
				.pid_filter_count = 32,
3798 3799
				.pid_filter       = stk7700p_pid_filter,
				.pid_filter_ctrl  = stk7700p_pid_filter_ctrl,
3800 3801 3802 3803
				.frontend_attach  = stk7700p_frontend_attach,
				.tuner_attach     = stk7700p_tuner_attach,

				DIB0700_DEFAULT_STREAMING_CONFIG(0x02),
3804
			}},
3805 3806 3807
			},
		},

3808
		.num_device_descs = 8,
3809 3810
		.devices = {
			{   "DiBcom STK7700P reference design",
3811
				{ &dib0700_usb_id_table[0], &dib0700_usb_id_table[1] },
3812 3813 3814
				{ NULL },
			},
			{   "Hauppauge Nova-T Stick",
3815
				{ &dib0700_usb_id_table[4], &dib0700_usb_id_table[9], NULL },
3816 3817 3818
				{ NULL },
			},
			{   "AVerMedia AVerTV DVB-T Volar",
3819
				{ &dib0700_usb_id_table[5], &dib0700_usb_id_table[10] },
3820 3821
				{ NULL },
			},
3822
			{   "Compro Videomate U500",
3823
				{ &dib0700_usb_id_table[6], &dib0700_usb_id_table[19] },
3824
				{ NULL },
3825 3826 3827 3828
			},
			{   "Uniwill STK7700P based (Hama and others)",
				{ &dib0700_usb_id_table[7], NULL },
				{ NULL },
3829 3830
			},
			{   "Leadtek Winfast DTV Dongle (STK7700P based)",
3831
				{ &dib0700_usb_id_table[8], &dib0700_usb_id_table[34] },
3832
				{ NULL },
3833 3834 3835 3836
			},
			{   "AVerMedia AVerTV DVB-T Express",
				{ &dib0700_usb_id_table[20] },
				{ NULL },
3837 3838 3839 3840
			},
			{   "Gigabyte U7000",
				{ &dib0700_usb_id_table[21], NULL },
				{ NULL },
3841
			}
3842 3843
		},

3844
		.rc.core = {
3845
			.rc_interval      = DEFAULT_RC_INTERVAL,
3846
			.rc_codes         = RC_MAP_DIB0700_RC5_TABLE,
3847
			.rc_query         = dib0700_rc_query_old_firmware,
3848 3849 3850
			.allowed_protos   = RC_BIT_RC5 |
					    RC_BIT_RC6_MCE |
					    RC_BIT_NEC,
3851
			.change_protocol  = dib0700_change_protocol,
3852
		},
3853 3854 3855 3856 3857
	}, { DIB0700_DEFAULT_DEVICE_PROPERTIES,

		.num_adapters = 2,
		.adapter = {
			{
3858 3859
			.num_frontends = 1,
			.fe = {{
3860 3861 3862 3863
				.frontend_attach  = bristol_frontend_attach,
				.tuner_attach     = bristol_tuner_attach,

				DIB0700_DEFAULT_STREAMING_CONFIG(0x02),
3864
			}},
3865
			}, {
3866 3867
			.num_frontends = 1,
			.fe = {{
3868 3869 3870 3871
				.frontend_attach  = bristol_frontend_attach,
				.tuner_attach     = bristol_tuner_attach,

				DIB0700_DEFAULT_STREAMING_CONFIG(0x03),
3872
			}},
3873 3874 3875 3876 3877 3878
			}
		},

		.num_device_descs = 1,
		.devices = {
			{   "Hauppauge Nova-T 500 Dual DVB-T",
3879
				{ &dib0700_usb_id_table[2], &dib0700_usb_id_table[3], NULL },
3880 3881
				{ NULL },
			},
3882 3883
		},

3884
		.rc.core = {
3885
			.rc_interval      = DEFAULT_RC_INTERVAL,
3886
			.rc_codes         = RC_MAP_DIB0700_RC5_TABLE,
3887
			.rc_query         = dib0700_rc_query_old_firmware,
3888 3889 3890
			.allowed_protos   = RC_BIT_RC5 |
					    RC_BIT_RC6_MCE |
					    RC_BIT_NEC,
3891
			.change_protocol = dib0700_change_protocol,
3892
		},
3893 3894 3895 3896 3897
	}, { DIB0700_DEFAULT_DEVICE_PROPERTIES,

		.num_adapters = 2,
		.adapter = {
			{
3898 3899
			.num_frontends = 1,
			.fe = {{
3900 3901 3902 3903
				.caps = DVB_USB_ADAP_HAS_PID_FILTER | DVB_USB_ADAP_PID_FILTER_CAN_BE_TURNED_OFF,
				.pid_filter_count = 32,
				.pid_filter       = stk70x0p_pid_filter,
				.pid_filter_ctrl  = stk70x0p_pid_filter_ctrl,
3904 3905 3906 3907
				.frontend_attach  = stk7700d_frontend_attach,
				.tuner_attach     = stk7700d_tuner_attach,

				DIB0700_DEFAULT_STREAMING_CONFIG(0x02),
3908
			}},
3909
			}, {
3910 3911
			.num_frontends = 1,
			.fe = {{
3912 3913 3914 3915
				.caps = DVB_USB_ADAP_HAS_PID_FILTER | DVB_USB_ADAP_PID_FILTER_CAN_BE_TURNED_OFF,
				.pid_filter_count = 32,
				.pid_filter       = stk70x0p_pid_filter,
				.pid_filter_ctrl  = stk70x0p_pid_filter_ctrl,
3916 3917 3918 3919
				.frontend_attach  = stk7700d_frontend_attach,
				.tuner_attach     = stk7700d_tuner_attach,

				DIB0700_DEFAULT_STREAMING_CONFIG(0x03),
3920
			}},
3921 3922 3923
			}
		},

3924
		.num_device_descs = 5,
3925 3926 3927 3928 3929 3930 3931 3932 3933
		.devices = {
			{   "Pinnacle PCTV 2000e",
				{ &dib0700_usb_id_table[11], NULL },
				{ NULL },
			},
			{   "Terratec Cinergy DT XS Diversity",
				{ &dib0700_usb_id_table[12], NULL },
				{ NULL },
			},
3934
			{   "Hauppauge Nova-TD Stick/Elgato Eye-TV Diversity",
3935 3936 3937
				{ &dib0700_usb_id_table[13], NULL },
				{ NULL },
			},
3938
			{   "DiBcom STK7700D reference design",
3939 3940
				{ &dib0700_usb_id_table[14], NULL },
				{ NULL },
3941
			},
3942 3943 3944 3945
			{   "YUAN High-Tech DiBcom STK7700D",
				{ &dib0700_usb_id_table[55], NULL },
				{ NULL },
			},
3946

3947
		},
3948

3949
		.rc.core = {
3950
			.rc_interval      = DEFAULT_RC_INTERVAL,
3951
			.rc_codes         = RC_MAP_DIB0700_RC5_TABLE,
3952
			.rc_query         = dib0700_rc_query_old_firmware,
3953 3954 3955
			.allowed_protos   = RC_BIT_RC5 |
					    RC_BIT_RC6_MCE |
					    RC_BIT_NEC,
3956
			.change_protocol = dib0700_change_protocol,
3957
		},
3958 3959 3960 3961 3962
	}, { DIB0700_DEFAULT_DEVICE_PROPERTIES,

		.num_adapters = 1,
		.adapter = {
			{
3963 3964
			.num_frontends = 1,
			.fe = {{
3965 3966 3967 3968
				.caps = DVB_USB_ADAP_HAS_PID_FILTER | DVB_USB_ADAP_PID_FILTER_CAN_BE_TURNED_OFF,
				.pid_filter_count = 32,
				.pid_filter       = stk70x0p_pid_filter,
				.pid_filter_ctrl  = stk70x0p_pid_filter_ctrl,
3969 3970 3971 3972
				.frontend_attach  = stk7700P2_frontend_attach,
				.tuner_attach     = stk7700d_tuner_attach,

				DIB0700_DEFAULT_STREAMING_CONFIG(0x02),
3973
			}},
3974 3975 3976
			},
		},

3977
		.num_device_descs = 3,
3978 3979 3980 3981 3982
		.devices = {
			{   "ASUS My Cinema U3000 Mini DVBT Tuner",
				{ &dib0700_usb_id_table[23], NULL },
				{ NULL },
			},
3983 3984 3985
			{   "Yuan EC372S",
				{ &dib0700_usb_id_table[31], NULL },
				{ NULL },
3986 3987 3988 3989
			},
			{   "Terratec Cinergy T Express",
				{ &dib0700_usb_id_table[42], NULL },
				{ NULL },
3990
			}
3991 3992
		},

3993
		.rc.core = {
3994
			.rc_interval      = DEFAULT_RC_INTERVAL,
3995
			.rc_codes         = RC_MAP_DIB0700_RC5_TABLE,
3996
			.module_name	  = "dib0700",
3997
			.rc_query         = dib0700_rc_query_old_firmware,
3998 3999 4000
			.allowed_protos   = RC_BIT_RC5 |
					    RC_BIT_RC6_MCE |
					    RC_BIT_NEC,
4001
			.change_protocol = dib0700_change_protocol,
4002
		},
4003 4004 4005 4006 4007
	}, { DIB0700_DEFAULT_DEVICE_PROPERTIES,

		.num_adapters = 1,
		.adapter = {
			{
4008 4009
			.num_frontends = 1,
			.fe = {{
4010 4011 4012 4013
				.caps = DVB_USB_ADAP_HAS_PID_FILTER | DVB_USB_ADAP_PID_FILTER_CAN_BE_TURNED_OFF,
				.pid_filter_count = 32,
				.pid_filter       = stk70x0p_pid_filter,
				.pid_filter_ctrl  = stk70x0p_pid_filter_ctrl,
4014 4015 4016 4017
				.frontend_attach  = stk7070p_frontend_attach,
				.tuner_attach     = dib7070p_tuner_attach,

				DIB0700_DEFAULT_STREAMING_CONFIG(0x02),
4018
			}},
4019 4020 4021 4022
				.size_of_priv     = sizeof(struct dib0700_adapter_state),
			},
		},

4023
		.num_device_descs = 12,
4024 4025 4026 4027 4028 4029 4030 4031 4032
		.devices = {
			{   "DiBcom STK7070P reference design",
				{ &dib0700_usb_id_table[15], NULL },
				{ NULL },
			},
			{   "Pinnacle PCTV DVB-T Flash Stick",
				{ &dib0700_usb_id_table[16], NULL },
				{ NULL },
			},
4033 4034 4035
			{   "Artec T14BR DVB-T",
				{ &dib0700_usb_id_table[22], NULL },
				{ NULL },
4036 4037 4038 4039 4040
			},
			{   "ASUS My Cinema U3100 Mini DVBT Tuner",
				{ &dib0700_usb_id_table[24], NULL },
				{ NULL },
			},
4041 4042 4043 4044
			{   "Hauppauge Nova-T Stick",
				{ &dib0700_usb_id_table[25], NULL },
				{ NULL },
			},
D
Darren Salt 已提交
4045 4046 4047 4048
			{   "Hauppauge Nova-T MyTV.t",
				{ &dib0700_usb_id_table[26], NULL },
				{ NULL },
			},
4049 4050 4051 4052 4053 4054 4055 4056
			{   "Pinnacle PCTV 72e",
				{ &dib0700_usb_id_table[29], NULL },
				{ NULL },
			},
			{   "Pinnacle PCTV 73e",
				{ &dib0700_usb_id_table[30], NULL },
				{ NULL },
			},
4057 4058 4059 4060
			{   "Elgato EyeTV DTT",
				{ &dib0700_usb_id_table[49], NULL },
				{ NULL },
			},
4061 4062 4063 4064
			{   "Yuan PD378S",
				{ &dib0700_usb_id_table[45], NULL },
				{ NULL },
			},
4065 4066 4067 4068
			{   "Elgato EyeTV Dtt Dlx PD378S",
				{ &dib0700_usb_id_table[50], NULL },
				{ NULL },
			},
4069
			{   "Elgato EyeTV DTT rev. 2",
4070
				{ &dib0700_usb_id_table[80], NULL },
4071 4072
				{ NULL },
			},
4073 4074
		},

4075
		.rc.core = {
4076
			.rc_interval      = DEFAULT_RC_INTERVAL,
4077
			.rc_codes         = RC_MAP_DIB0700_RC5_TABLE,
4078
			.module_name	  = "dib0700",
4079
			.rc_query         = dib0700_rc_query_old_firmware,
4080 4081 4082
			.allowed_protos   = RC_BIT_RC5 |
					    RC_BIT_RC6_MCE |
					    RC_BIT_NEC,
4083
			.change_protocol  = dib0700_change_protocol,
4084
		},
4085 4086 4087 4088 4089
	}, { DIB0700_DEFAULT_DEVICE_PROPERTIES,

		.num_adapters = 1,
		.adapter = {
			{
4090 4091
			.num_frontends = 1,
			.fe = {{
4092 4093 4094 4095
				.caps = DVB_USB_ADAP_HAS_PID_FILTER | DVB_USB_ADAP_PID_FILTER_CAN_BE_TURNED_OFF,
				.pid_filter_count = 32,
				.pid_filter       = stk70x0p_pid_filter,
				.pid_filter_ctrl  = stk70x0p_pid_filter_ctrl,
4096 4097 4098 4099
				.frontend_attach  = stk7070p_frontend_attach,
				.tuner_attach     = dib7070p_tuner_attach,

				DIB0700_DEFAULT_STREAMING_CONFIG(0x02),
4100
			}},
4101 4102 4103 4104
				.size_of_priv     = sizeof(struct dib0700_adapter_state),
			},
		},

4105
		.num_device_descs = 3,
4106 4107 4108 4109 4110 4111
		.devices = {
			{   "Pinnacle PCTV 73A",
				{ &dib0700_usb_id_table[56], NULL },
				{ NULL },
			},
			{   "Pinnacle PCTV 73e SE",
4112
				{ &dib0700_usb_id_table[57], &dib0700_usb_id_table[65], NULL },
4113 4114 4115
				{ NULL },
			},
			{   "Pinnacle PCTV 282e",
4116
				{ &dib0700_usb_id_table[58], &dib0700_usb_id_table[66], NULL },
4117 4118 4119 4120
				{ NULL },
			},
		},

4121
		.rc.core = {
4122
			.rc_interval      = DEFAULT_RC_INTERVAL,
4123
			.rc_codes         = RC_MAP_DIB0700_RC5_TABLE,
4124
			.module_name	  = "dib0700",
4125
			.rc_query         = dib0700_rc_query_old_firmware,
4126 4127 4128
			.allowed_protos   = RC_BIT_RC5 |
					    RC_BIT_RC6_MCE |
					    RC_BIT_NEC,
4129
			.change_protocol  = dib0700_change_protocol,
4130
		},
4131 4132 4133 4134 4135
	}, { DIB0700_DEFAULT_DEVICE_PROPERTIES,

		.num_adapters = 2,
		.adapter = {
			{
4136 4137
			.num_frontends = 1,
			.fe = {{
4138 4139 4140 4141
				.caps = DVB_USB_ADAP_HAS_PID_FILTER | DVB_USB_ADAP_PID_FILTER_CAN_BE_TURNED_OFF,
				.pid_filter_count = 32,
				.pid_filter       = stk70x0p_pid_filter,
				.pid_filter_ctrl  = stk70x0p_pid_filter_ctrl,
4142
				.frontend_attach  = novatd_frontend_attach,
4143 4144 4145
				.tuner_attach     = dib7070p_tuner_attach,

				DIB0700_DEFAULT_STREAMING_CONFIG(0x02),
4146
			}},
4147 4148
				.size_of_priv     = sizeof(struct dib0700_adapter_state),
			}, {
4149 4150
			.num_frontends = 1,
			.fe = {{
4151 4152 4153 4154
				.caps = DVB_USB_ADAP_HAS_PID_FILTER | DVB_USB_ADAP_PID_FILTER_CAN_BE_TURNED_OFF,
				.pid_filter_count = 32,
				.pid_filter       = stk70x0p_pid_filter,
				.pid_filter_ctrl  = stk70x0p_pid_filter_ctrl,
4155
				.frontend_attach  = novatd_frontend_attach,
4156 4157 4158
				.tuner_attach     = dib7070p_tuner_attach,

				DIB0700_DEFAULT_STREAMING_CONFIG(0x03),
4159
			}},
4160 4161 4162 4163
				.size_of_priv     = sizeof(struct dib0700_adapter_state),
			}
		},

4164
		.num_device_descs = 3,
4165 4166 4167 4168 4169
		.devices = {
			{   "Hauppauge Nova-TD Stick (52009)",
				{ &dib0700_usb_id_table[35], NULL },
				{ NULL },
			},
4170 4171 4172 4173 4174 4175 4176 4177
			{   "PCTV 2002e",
				{ &dib0700_usb_id_table[81], NULL },
				{ NULL },
			},
			{   "PCTV 2002e SE",
				{ &dib0700_usb_id_table[82], NULL },
				{ NULL },
			},
4178 4179 4180 4181 4182 4183 4184
		},

		.rc.core = {
			.rc_interval      = DEFAULT_RC_INTERVAL,
			.rc_codes         = RC_MAP_DIB0700_RC5_TABLE,
			.module_name	  = "dib0700",
			.rc_query         = dib0700_rc_query_old_firmware,
4185 4186 4187
			.allowed_protos   = RC_BIT_RC5 |
					    RC_BIT_RC6_MCE |
					    RC_BIT_NEC,
4188 4189 4190 4191 4192 4193 4194 4195 4196 4197 4198 4199 4200 4201 4202 4203 4204 4205 4206 4207 4208 4209 4210 4211 4212 4213 4214 4215 4216 4217 4218 4219 4220 4221 4222 4223
			.change_protocol = dib0700_change_protocol,
		},
	}, { DIB0700_DEFAULT_DEVICE_PROPERTIES,

		.num_adapters = 2,
		.adapter = {
			{
			.num_frontends = 1,
			.fe = {{
				.caps = DVB_USB_ADAP_HAS_PID_FILTER | DVB_USB_ADAP_PID_FILTER_CAN_BE_TURNED_OFF,
				.pid_filter_count = 32,
				.pid_filter       = stk70x0p_pid_filter,
				.pid_filter_ctrl  = stk70x0p_pid_filter_ctrl,
				.frontend_attach  = stk7070pd_frontend_attach0,
				.tuner_attach     = dib7070p_tuner_attach,

				DIB0700_DEFAULT_STREAMING_CONFIG(0x02),
			}},
				.size_of_priv     = sizeof(struct dib0700_adapter_state),
			}, {
			.num_frontends = 1,
			.fe = {{
				.caps = DVB_USB_ADAP_HAS_PID_FILTER | DVB_USB_ADAP_PID_FILTER_CAN_BE_TURNED_OFF,
				.pid_filter_count = 32,
				.pid_filter       = stk70x0p_pid_filter,
				.pid_filter_ctrl  = stk70x0p_pid_filter_ctrl,
				.frontend_attach  = stk7070pd_frontend_attach1,
				.tuner_attach     = dib7070p_tuner_attach,

				DIB0700_DEFAULT_STREAMING_CONFIG(0x03),
			}},
				.size_of_priv     = sizeof(struct dib0700_adapter_state),
			}
		},

		.num_device_descs = 5,
4224 4225 4226 4227 4228 4229 4230 4231
		.devices = {
			{   "DiBcom STK7070PD reference design",
				{ &dib0700_usb_id_table[17], NULL },
				{ NULL },
			},
			{   "Pinnacle PCTV Dual DVB-T Diversity Stick",
				{ &dib0700_usb_id_table[18], NULL },
				{ NULL },
4232
			},
4233 4234 4235
			{   "Hauppauge Nova-TD-500 (84xxx)",
				{ &dib0700_usb_id_table[36], NULL },
				{ NULL },
4236
			},
4237 4238 4239
			{  "Terratec Cinergy DT USB XS Diversity/ T5",
				{ &dib0700_usb_id_table[43],
					&dib0700_usb_id_table[53], NULL},
4240
				{ NULL },
4241 4242 4243 4244
			},
			{  "Sony PlayTV",
				{ &dib0700_usb_id_table[44], NULL },
				{ NULL },
4245
			},
4246 4247 4248 4249 4250 4251
		},

		.rc.core = {
			.rc_interval      = DEFAULT_RC_INTERVAL,
			.rc_codes         = RC_MAP_DIB0700_RC5_TABLE,
			.module_name	  = "dib0700",
4252
			.rc_query         = dib0700_rc_query_old_firmware,
4253 4254 4255
			.allowed_protos   = RC_BIT_RC5 |
					    RC_BIT_RC6_MCE |
					    RC_BIT_NEC,
4256
			.change_protocol = dib0700_change_protocol,
4257 4258 4259 4260 4261 4262
		},
	}, { DIB0700_DEFAULT_DEVICE_PROPERTIES,

		.num_adapters = 2,
		.adapter = {
			{
4263 4264
			.num_frontends = 1,
			.fe = {{
4265 4266 4267 4268 4269 4270 4271 4272
				.caps = DVB_USB_ADAP_HAS_PID_FILTER | DVB_USB_ADAP_PID_FILTER_CAN_BE_TURNED_OFF,
				.pid_filter_count = 32,
				.pid_filter       = stk70x0p_pid_filter,
				.pid_filter_ctrl  = stk70x0p_pid_filter_ctrl,
				.frontend_attach  = stk7070pd_frontend_attach0,
				.tuner_attach     = dib7070p_tuner_attach,

				DIB0700_DEFAULT_STREAMING_CONFIG(0x02),
4273
			}},
4274 4275
				.size_of_priv     = sizeof(struct dib0700_adapter_state),
			}, {
4276 4277
			.num_frontends = 1,
			.fe = {{
4278 4279 4280 4281 4282 4283 4284 4285
				.caps = DVB_USB_ADAP_HAS_PID_FILTER | DVB_USB_ADAP_PID_FILTER_CAN_BE_TURNED_OFF,
				.pid_filter_count = 32,
				.pid_filter       = stk70x0p_pid_filter,
				.pid_filter_ctrl  = stk70x0p_pid_filter_ctrl,
				.frontend_attach  = stk7070pd_frontend_attach1,
				.tuner_attach     = dib7070p_tuner_attach,

				DIB0700_DEFAULT_STREAMING_CONFIG(0x03),
4286
			}},
4287 4288 4289 4290 4291 4292
				.size_of_priv     = sizeof(struct dib0700_adapter_state),
			}
		},

		.num_device_descs = 1,
		.devices = {
4293 4294 4295 4296
			{   "Elgato EyeTV Diversity",
				{ &dib0700_usb_id_table[68], NULL },
				{ NULL },
			},
4297
		},
4298

4299
		.rc.core = {
4300
			.rc_interval      = DEFAULT_RC_INTERVAL,
4301
			.rc_codes         = RC_MAP_DIB0700_NEC_TABLE,
4302
			.module_name	  = "dib0700",
4303
			.rc_query         = dib0700_rc_query_old_firmware,
4304 4305 4306
			.allowed_protos   = RC_BIT_RC5 |
					    RC_BIT_RC6_MCE |
					    RC_BIT_NEC,
4307
			.change_protocol  = dib0700_change_protocol,
4308
		},
4309 4310 4311 4312 4313
	}, { DIB0700_DEFAULT_DEVICE_PROPERTIES,

		.num_adapters = 1,
		.adapter = {
			{
4314 4315
			.num_frontends = 1,
			.fe = {{
4316 4317 4318 4319
				.caps = DVB_USB_ADAP_HAS_PID_FILTER | DVB_USB_ADAP_PID_FILTER_CAN_BE_TURNED_OFF,
				.pid_filter_count = 32,
				.pid_filter       = stk70x0p_pid_filter,
				.pid_filter_ctrl  = stk70x0p_pid_filter_ctrl,
4320 4321 4322 4323
				.frontend_attach  = stk7700ph_frontend_attach,
				.tuner_attach     = stk7700ph_tuner_attach,

				DIB0700_DEFAULT_STREAMING_CONFIG(0x02),
4324
			}},
4325 4326 4327 4328 4329
				.size_of_priv = sizeof(struct
						dib0700_adapter_state),
			},
		},

4330
		.num_device_descs = 9,
4331 4332 4333 4334 4335 4336 4337 4338 4339 4340 4341 4342 4343
		.devices = {
			{   "Terratec Cinergy HT USB XE",
				{ &dib0700_usb_id_table[27], NULL },
				{ NULL },
			},
			{   "Pinnacle Expresscard 320cx",
				{ &dib0700_usb_id_table[28], NULL },
				{ NULL },
			},
			{   "Terratec Cinergy HT Express",
				{ &dib0700_usb_id_table[32], NULL },
				{ NULL },
			},
4344 4345 4346 4347
			{   "Gigabyte U8000-RH",
				{ &dib0700_usb_id_table[37], NULL },
				{ NULL },
			},
4348 4349 4350 4351
			{   "YUAN High-Tech STK7700PH",
				{ &dib0700_usb_id_table[38], NULL },
				{ NULL },
			},
4352 4353 4354 4355
			{   "Asus My Cinema-U3000Hybrid",
				{ &dib0700_usb_id_table[39], NULL },
				{ NULL },
			},
4356 4357 4358 4359
			{   "YUAN High-Tech MC770",
				{ &dib0700_usb_id_table[48], NULL },
				{ NULL },
			},
4360 4361 4362 4363
			{   "Leadtek WinFast DTV Dongle H",
				{ &dib0700_usb_id_table[51], NULL },
				{ NULL },
			},
4364 4365 4366 4367
			{   "YUAN High-Tech STK7700D",
				{ &dib0700_usb_id_table[54], NULL },
				{ NULL },
			},
4368
		},
4369

4370
		.rc.core = {
4371
			.rc_interval      = DEFAULT_RC_INTERVAL,
4372
			.rc_codes         = RC_MAP_DIB0700_RC5_TABLE,
4373
			.module_name	  = "dib0700",
4374
			.rc_query         = dib0700_rc_query_old_firmware,
4375 4376 4377
			.allowed_protos   = RC_BIT_RC5 |
					    RC_BIT_RC6_MCE |
					    RC_BIT_NEC,
4378
			.change_protocol  = dib0700_change_protocol,
4379
		},
4380 4381 4382 4383
	}, { DIB0700_DEFAULT_DEVICE_PROPERTIES,
		.num_adapters = 1,
		.adapter = {
			{
4384 4385
			.num_frontends = 1,
			.fe = {{
4386 4387 4388 4389
				.frontend_attach  = s5h1411_frontend_attach,
				.tuner_attach     = xc5000_tuner_attach,

				DIB0700_DEFAULT_STREAMING_CONFIG(0x02),
4390
			}},
4391 4392 4393 4394 4395
				.size_of_priv = sizeof(struct
						dib0700_adapter_state),
			},
		},

4396
		.num_device_descs = 2,
4397 4398 4399 4400 4401
		.devices = {
			{   "Pinnacle PCTV HD Pro USB Stick",
				{ &dib0700_usb_id_table[40], NULL },
				{ NULL },
			},
4402 4403 4404 4405
			{   "Pinnacle PCTV HD USB Stick",
				{ &dib0700_usb_id_table[41], NULL },
				{ NULL },
			},
4406
		},
4407 4408

		.rc.core = {
4409
			.rc_interval      = DEFAULT_RC_INTERVAL,
4410
			.rc_codes         = RC_MAP_DIB0700_RC5_TABLE,
4411
			.module_name	  = "dib0700",
4412
			.rc_query         = dib0700_rc_query_old_firmware,
4413 4414 4415
			.allowed_protos   = RC_BIT_RC5 |
					    RC_BIT_RC6_MCE |
					    RC_BIT_NEC,
4416
			.change_protocol  = dib0700_change_protocol,
4417
		},
4418 4419 4420 4421
	}, { DIB0700_DEFAULT_DEVICE_PROPERTIES,
		.num_adapters = 1,
		.adapter = {
			{
4422 4423
			.num_frontends = 1,
			.fe = {{
4424 4425 4426 4427
				.frontend_attach  = lgdt3305_frontend_attach,
				.tuner_attach     = mxl5007t_tuner_attach,

				DIB0700_DEFAULT_STREAMING_CONFIG(0x02),
4428
			}},
4429 4430 4431 4432 4433 4434 4435 4436 4437 4438 4439 4440 4441 4442 4443 4444
				.size_of_priv = sizeof(struct
						dib0700_adapter_state),
			},
		},

		.num_device_descs = 2,
		.devices = {
			{   "Hauppauge ATSC MiniCard (B200)",
				{ &dib0700_usb_id_table[46], NULL },
				{ NULL },
			},
			{   "Hauppauge ATSC MiniCard (B210)",
				{ &dib0700_usb_id_table[47], NULL },
				{ NULL },
			},
		},
4445 4446 4447 4448 4449
	}, { DIB0700_DEFAULT_DEVICE_PROPERTIES,

		.num_adapters = 1,
		.adapter = {
			{
4450 4451
			.num_frontends = 1,
			.fe = {{
4452 4453 4454 4455
				.caps = DVB_USB_ADAP_HAS_PID_FILTER | DVB_USB_ADAP_PID_FILTER_CAN_BE_TURNED_OFF,
				.pid_filter_count = 32,
				.pid_filter       = stk70x0p_pid_filter,
				.pid_filter_ctrl  = stk70x0p_pid_filter_ctrl,
4456
				.frontend_attach  = stk7770p_frontend_attach,
4457 4458 4459
				.tuner_attach     = dib7770p_tuner_attach,

				DIB0700_DEFAULT_STREAMING_CONFIG(0x02),
4460
			}},
4461
				.size_of_priv =
4462
					sizeof(struct dib0700_adapter_state),
4463 4464 4465
			},
		},

4466
		.num_device_descs = 4,
4467 4468 4469 4470 4471
		.devices = {
			{   "DiBcom STK7770P reference design",
				{ &dib0700_usb_id_table[59], NULL },
				{ NULL },
			},
4472 4473 4474 4475
			{   "Terratec Cinergy T USB XXS (HD)/ T3",
				{ &dib0700_usb_id_table[33],
					&dib0700_usb_id_table[52],
					&dib0700_usb_id_table[60], NULL},
4476 4477
				{ NULL },
			},
4478 4479 4480 4481
			{   "TechniSat AirStar TeleStick 2",
				{ &dib0700_usb_id_table[74], NULL },
				{ NULL },
			},
4482 4483 4484 4485
			{   "Medion CTX1921 DVB-T USB",
				{ &dib0700_usb_id_table[75], NULL },
				{ NULL },
			},
4486
		},
4487 4488

		.rc.core = {
4489
			.rc_interval      = DEFAULT_RC_INTERVAL,
4490
			.rc_codes         = RC_MAP_DIB0700_RC5_TABLE,
4491
			.module_name	  = "dib0700",
4492
			.rc_query         = dib0700_rc_query_old_firmware,
4493 4494 4495
			.allowed_protos   = RC_BIT_RC5 |
					    RC_BIT_RC6_MCE |
					    RC_BIT_NEC,
4496
			.change_protocol  = dib0700_change_protocol,
4497
		},
4498 4499 4500 4501
	}, { DIB0700_DEFAULT_DEVICE_PROPERTIES,
		.num_adapters = 1,
		.adapter = {
			{
4502 4503
			.num_frontends = 1,
			.fe = {{
4504 4505
				.caps  = DVB_USB_ADAP_HAS_PID_FILTER | DVB_USB_ADAP_PID_FILTER_CAN_BE_TURNED_OFF,
				.pid_filter_count = 32,
4506 4507
				.pid_filter = stk80xx_pid_filter,
				.pid_filter_ctrl = stk80xx_pid_filter_ctrl,
4508 4509 4510 4511
				.frontend_attach  = stk807x_frontend_attach,
				.tuner_attach     = dib807x_tuner_attach,

				DIB0700_DEFAULT_STREAMING_CONFIG(0x02),
4512
			}},
4513 4514 4515 4516 4517
				.size_of_priv =
					sizeof(struct dib0700_adapter_state),
			},
		},

4518
		.num_device_descs = 3,
4519 4520 4521 4522 4523
		.devices = {
			{   "DiBcom STK807xP reference design",
				{ &dib0700_usb_id_table[62], NULL },
				{ NULL },
			},
4524 4525 4526 4527
			{   "Prolink Pixelview SBTVD",
				{ &dib0700_usb_id_table[63], NULL },
				{ NULL },
			},
4528 4529 4530 4531
			{   "EvolutePC TVWay+",
				{ &dib0700_usb_id_table[64], NULL },
				{ NULL },
			},
4532 4533
		},

4534
		.rc.core = {
4535
			.rc_interval      = DEFAULT_RC_INTERVAL,
4536
			.rc_codes         = RC_MAP_DIB0700_NEC_TABLE,
4537
			.module_name	  = "dib0700",
4538
			.rc_query         = dib0700_rc_query_old_firmware,
4539 4540 4541
			.allowed_protos   = RC_BIT_RC5 |
					    RC_BIT_RC6_MCE |
					    RC_BIT_NEC,
4542
			.change_protocol  = dib0700_change_protocol,
4543
		},
4544 4545 4546 4547
	}, { DIB0700_DEFAULT_DEVICE_PROPERTIES,
		.num_adapters = 2,
		.adapter = {
			{
4548 4549
			.num_frontends = 1,
			.fe = {{
4550 4551
				.caps  = DVB_USB_ADAP_HAS_PID_FILTER | DVB_USB_ADAP_PID_FILTER_CAN_BE_TURNED_OFF,
				.pid_filter_count = 32,
4552 4553
				.pid_filter = stk80xx_pid_filter,
				.pid_filter_ctrl = stk80xx_pid_filter_ctrl,
4554 4555 4556 4557
				.frontend_attach  = stk807xpvr_frontend_attach0,
				.tuner_attach     = dib807x_tuner_attach,

				DIB0700_DEFAULT_STREAMING_CONFIG(0x02),
4558
			}},
4559 4560 4561 4562
				.size_of_priv =
					sizeof(struct dib0700_adapter_state),
			},
			{
4563 4564
			.num_frontends = 1,
			.fe = {{
4565 4566
				.caps  = DVB_USB_ADAP_HAS_PID_FILTER | DVB_USB_ADAP_PID_FILTER_CAN_BE_TURNED_OFF,
				.pid_filter_count = 32,
4567 4568
				.pid_filter = stk80xx_pid_filter,
				.pid_filter_ctrl = stk80xx_pid_filter_ctrl,
4569 4570 4571 4572
				.frontend_attach  = stk807xpvr_frontend_attach1,
				.tuner_attach     = dib807x_tuner_attach,

				DIB0700_DEFAULT_STREAMING_CONFIG(0x03),
4573
			}},
4574 4575 4576 4577 4578 4579 4580 4581 4582 4583 4584 4585 4586
				.size_of_priv =
					sizeof(struct dib0700_adapter_state),
			},
		},

		.num_device_descs = 1,
		.devices = {
			{   "DiBcom STK807xPVR reference design",
				{ &dib0700_usb_id_table[61], NULL },
				{ NULL },
			},
		},

4587
		.rc.core = {
4588
			.rc_interval      = DEFAULT_RC_INTERVAL,
4589
			.rc_codes         = RC_MAP_DIB0700_RC5_TABLE,
4590
			.module_name	  = "dib0700",
4591
			.rc_query         = dib0700_rc_query_old_firmware,
4592 4593 4594
			.allowed_protos   = RC_BIT_RC5 |
					    RC_BIT_RC6_MCE |
					    RC_BIT_NEC,
4595
			.change_protocol  = dib0700_change_protocol,
4596
		},
4597 4598 4599 4600
	}, { DIB0700_DEFAULT_DEVICE_PROPERTIES,
		.num_adapters = 1,
		.adapter = {
			{
4601 4602
			.num_frontends = 1,
			.fe = {{
4603 4604 4605 4606 4607 4608 4609 4610 4611
				.caps  = DVB_USB_ADAP_HAS_PID_FILTER |
					DVB_USB_ADAP_PID_FILTER_CAN_BE_TURNED_OFF,
				.pid_filter_count = 32,
				.pid_filter = stk80xx_pid_filter,
				.pid_filter_ctrl = stk80xx_pid_filter_ctrl,
				.frontend_attach  = stk809x_frontend_attach,
				.tuner_attach     = dib809x_tuner_attach,

				DIB0700_DEFAULT_STREAMING_CONFIG(0x02),
4612
			}},
4613 4614 4615 4616 4617 4618 4619 4620 4621 4622 4623 4624 4625
				.size_of_priv =
					sizeof(struct dib0700_adapter_state),
			},
		},

		.num_device_descs = 1,
		.devices = {
			{   "DiBcom STK8096GP reference design",
				{ &dib0700_usb_id_table[67], NULL },
				{ NULL },
			},
		},

4626 4627 4628 4629 4630
		.rc.core = {
			.rc_interval      = DEFAULT_RC_INTERVAL,
			.rc_codes         = RC_MAP_DIB0700_RC5_TABLE,
			.module_name	  = "dib0700",
			.rc_query         = dib0700_rc_query_old_firmware,
4631 4632 4633
			.allowed_protos   = RC_BIT_RC5 |
					    RC_BIT_RC6_MCE |
					    RC_BIT_NEC,
4634 4635 4636 4637 4638 4639
			.change_protocol  = dib0700_change_protocol,
		},
	}, { DIB0700_DEFAULT_DEVICE_PROPERTIES,
		.num_adapters = 1,
		.adapter = {
			{
4640 4641
			.num_frontends = 1,
			.fe = {{
4642 4643 4644 4645 4646 4647 4648 4649 4650
				.caps  = DVB_USB_ADAP_HAS_PID_FILTER |
					DVB_USB_ADAP_PID_FILTER_CAN_BE_TURNED_OFF,
				.pid_filter_count = 32,
				.pid_filter = dib90x0_pid_filter,
				.pid_filter_ctrl = dib90x0_pid_filter_ctrl,
				.frontend_attach  = stk9090m_frontend_attach,
				.tuner_attach     = dib9090_tuner_attach,

				DIB0700_DEFAULT_STREAMING_CONFIG(0x02),
4651
			}},
4652 4653 4654 4655 4656 4657 4658 4659 4660 4661 4662 4663 4664 4665 4666 4667 4668 4669
				.size_of_priv =
					sizeof(struct dib0700_adapter_state),
			},
		},

		.num_device_descs = 1,
		.devices = {
			{   "DiBcom STK9090M reference design",
				{ &dib0700_usb_id_table[69], NULL },
				{ NULL },
			},
		},

		.rc.core = {
			.rc_interval      = DEFAULT_RC_INTERVAL,
			.rc_codes         = RC_MAP_DIB0700_RC5_TABLE,
			.module_name	  = "dib0700",
			.rc_query         = dib0700_rc_query_old_firmware,
4670 4671 4672
			.allowed_protos   = RC_BIT_RC5 |
					    RC_BIT_RC6_MCE |
					    RC_BIT_NEC,
4673 4674 4675 4676 4677 4678
			.change_protocol  = dib0700_change_protocol,
		},
	}, { DIB0700_DEFAULT_DEVICE_PROPERTIES,
		.num_adapters = 1,
		.adapter = {
			{
4679 4680
			.num_frontends = 1,
			.fe = {{
4681 4682 4683 4684 4685 4686 4687 4688 4689
				.caps  = DVB_USB_ADAP_HAS_PID_FILTER |
					DVB_USB_ADAP_PID_FILTER_CAN_BE_TURNED_OFF,
				.pid_filter_count = 32,
				.pid_filter = stk80xx_pid_filter,
				.pid_filter_ctrl = stk80xx_pid_filter_ctrl,
				.frontend_attach  = nim8096md_frontend_attach,
				.tuner_attach     = nim8096md_tuner_attach,

				DIB0700_DEFAULT_STREAMING_CONFIG(0x02),
4690
			}},
4691 4692 4693 4694 4695 4696 4697 4698 4699 4700 4701 4702 4703 4704 4705 4706 4707 4708
				.size_of_priv =
					sizeof(struct dib0700_adapter_state),
			},
		},

		.num_device_descs = 1,
		.devices = {
			{   "DiBcom NIM8096MD reference design",
				{ &dib0700_usb_id_table[70], NULL },
				{ NULL },
			},
		},

		.rc.core = {
			.rc_interval      = DEFAULT_RC_INTERVAL,
			.rc_codes         = RC_MAP_DIB0700_RC5_TABLE,
			.module_name	  = "dib0700",
			.rc_query         = dib0700_rc_query_old_firmware,
4709 4710 4711
			.allowed_protos   = RC_BIT_RC5 |
					    RC_BIT_RC6_MCE |
					    RC_BIT_NEC,
4712 4713 4714 4715 4716 4717
			.change_protocol  = dib0700_change_protocol,
		},
	}, { DIB0700_DEFAULT_DEVICE_PROPERTIES,
		.num_adapters = 1,
		.adapter = {
			{
4718 4719
			.num_frontends = 1,
			.fe = {{
4720 4721 4722 4723 4724 4725 4726 4727 4728
				.caps  = DVB_USB_ADAP_HAS_PID_FILTER |
					DVB_USB_ADAP_PID_FILTER_CAN_BE_TURNED_OFF,
				.pid_filter_count = 32,
				.pid_filter = dib90x0_pid_filter,
				.pid_filter_ctrl = dib90x0_pid_filter_ctrl,
				.frontend_attach  = nim9090md_frontend_attach,
				.tuner_attach     = nim9090md_tuner_attach,

				DIB0700_DEFAULT_STREAMING_CONFIG(0x02),
4729
			}},
4730 4731 4732 4733 4734 4735 4736 4737 4738 4739 4740 4741 4742 4743 4744 4745 4746 4747
				.size_of_priv =
					sizeof(struct dib0700_adapter_state),
			},
		},

		.num_device_descs = 1,
		.devices = {
			{   "DiBcom NIM9090MD reference design",
				{ &dib0700_usb_id_table[71], NULL },
				{ NULL },
			},
		},

		.rc.core = {
			.rc_interval      = DEFAULT_RC_INTERVAL,
			.rc_codes         = RC_MAP_DIB0700_RC5_TABLE,
			.module_name	  = "dib0700",
			.rc_query         = dib0700_rc_query_old_firmware,
4748 4749 4750
			.allowed_protos   = RC_BIT_RC5 |
					    RC_BIT_RC6_MCE |
					    RC_BIT_NEC,
4751 4752 4753 4754 4755 4756
			.change_protocol  = dib0700_change_protocol,
		},
	}, { DIB0700_DEFAULT_DEVICE_PROPERTIES,
		.num_adapters = 1,
		.adapter = {
			{
4757 4758
			.num_frontends = 1,
			.fe = {{
4759 4760 4761 4762 4763 4764 4765 4766 4767
				.caps  = DVB_USB_ADAP_HAS_PID_FILTER |
					DVB_USB_ADAP_PID_FILTER_CAN_BE_TURNED_OFF,
				.pid_filter_count = 32,
				.pid_filter = stk70x0p_pid_filter,
				.pid_filter_ctrl = stk70x0p_pid_filter_ctrl,
				.frontend_attach  = nim7090_frontend_attach,
				.tuner_attach     = nim7090_tuner_attach,

				DIB0700_DEFAULT_STREAMING_CONFIG(0x02),
4768
			}},
4769 4770 4771 4772 4773 4774 4775 4776 4777 4778 4779 4780 4781 4782 4783 4784 4785 4786
				.size_of_priv =
					sizeof(struct dib0700_adapter_state),
			},
		},

		.num_device_descs = 1,
		.devices = {
			{   "DiBcom NIM7090 reference design",
				{ &dib0700_usb_id_table[72], NULL },
				{ NULL },
			},
		},

		.rc.core = {
			.rc_interval      = DEFAULT_RC_INTERVAL,
			.rc_codes         = RC_MAP_DIB0700_RC5_TABLE,
			.module_name	  = "dib0700",
			.rc_query         = dib0700_rc_query_old_firmware,
4787 4788 4789
			.allowed_protos   = RC_BIT_RC5 |
					    RC_BIT_RC6_MCE |
					    RC_BIT_NEC,
4790 4791 4792 4793 4794 4795
			.change_protocol  = dib0700_change_protocol,
		},
	}, { DIB0700_DEFAULT_DEVICE_PROPERTIES,
		.num_adapters = 2,
		.adapter = {
			{
4796 4797
			.num_frontends = 1,
			.fe = {{
4798 4799 4800 4801 4802 4803 4804 4805 4806
				.caps  = DVB_USB_ADAP_HAS_PID_FILTER |
					DVB_USB_ADAP_PID_FILTER_CAN_BE_TURNED_OFF,
				.pid_filter_count = 32,
				.pid_filter = stk70x0p_pid_filter,
				.pid_filter_ctrl = stk70x0p_pid_filter_ctrl,
				.frontend_attach  = tfe7090pvr_frontend0_attach,
				.tuner_attach     = tfe7090pvr_tuner0_attach,

				DIB0700_DEFAULT_STREAMING_CONFIG(0x03),
4807
			}},
4808 4809 4810 4811
				.size_of_priv =
					sizeof(struct dib0700_adapter_state),
			},
			{
4812 4813
			.num_frontends = 1,
			.fe = {{
4814 4815 4816 4817 4818 4819 4820 4821 4822
				.caps  = DVB_USB_ADAP_HAS_PID_FILTER |
					DVB_USB_ADAP_PID_FILTER_CAN_BE_TURNED_OFF,
				.pid_filter_count = 32,
				.pid_filter = stk70x0p_pid_filter,
				.pid_filter_ctrl = stk70x0p_pid_filter_ctrl,
				.frontend_attach  = tfe7090pvr_frontend1_attach,
				.tuner_attach     = tfe7090pvr_tuner1_attach,

				DIB0700_DEFAULT_STREAMING_CONFIG(0x02),
4823
			}},
4824 4825 4826 4827 4828 4829 4830 4831 4832 4833 4834 4835 4836
				.size_of_priv =
					sizeof(struct dib0700_adapter_state),
			},
		},

		.num_device_descs = 1,
		.devices = {
			{   "DiBcom TFE7090PVR reference design",
				{ &dib0700_usb_id_table[73], NULL },
				{ NULL },
			},
		},

4837 4838 4839 4840 4841
		.rc.core = {
			.rc_interval      = DEFAULT_RC_INTERVAL,
			.rc_codes         = RC_MAP_DIB0700_RC5_TABLE,
			.module_name	  = "dib0700",
			.rc_query         = dib0700_rc_query_old_firmware,
4842 4843 4844
			.allowed_protos   = RC_BIT_RC5 |
					    RC_BIT_RC6_MCE |
					    RC_BIT_NEC,
4845 4846 4847 4848 4849 4850
			.change_protocol  = dib0700_change_protocol,
		},
	}, { DIB0700_DEFAULT_DEVICE_PROPERTIES,
		.num_adapters = 1,
		.adapter = {
			{
4851 4852
			.num_frontends = 1,
			.fe = {{
4853
				.frontend_attach  = pctv340e_frontend_attach,
4854 4855 4856
				.tuner_attach     = xc4000_tuner_attach,

				DIB0700_DEFAULT_STREAMING_CONFIG(0x02),
4857
			}},
4858 4859 4860 4861 4862
				.size_of_priv = sizeof(struct
						dib0700_adapter_state),
			},
		},

4863
		.num_device_descs = 2,
4864 4865 4866 4867 4868
		.devices = {
			{   "Pinnacle PCTV 340e HD Pro USB Stick",
				{ &dib0700_usb_id_table[76], NULL },
				{ NULL },
			},
4869 4870 4871 4872
			{   "Pinnacle PCTV Hybrid Stick Solo",
				{ &dib0700_usb_id_table[77], NULL },
				{ NULL },
			},
4873
		},
4874 4875 4876 4877 4878
		.rc.core = {
			.rc_interval      = DEFAULT_RC_INTERVAL,
			.rc_codes         = RC_MAP_DIB0700_RC5_TABLE,
			.module_name	  = "dib0700",
			.rc_query         = dib0700_rc_query_old_firmware,
4879 4880 4881
			.allowed_protos   = RC_BIT_RC5 |
					    RC_BIT_RC6_MCE |
					    RC_BIT_NEC,
4882 4883 4884 4885 4886 4887 4888 4889 4890 4891 4892 4893 4894
			.change_protocol  = dib0700_change_protocol,
		},
	}, { DIB0700_DEFAULT_DEVICE_PROPERTIES,
		.num_adapters = 1,
		.adapter = {
			{
				.num_frontends = 1,
				.fe = {{
					.caps  = DVB_USB_ADAP_HAS_PID_FILTER |
						DVB_USB_ADAP_PID_FILTER_CAN_BE_TURNED_OFF,
					.pid_filter_count = 32,
					.pid_filter = stk70x0p_pid_filter,
					.pid_filter_ctrl = stk70x0p_pid_filter_ctrl,
4895 4896
					.frontend_attach  = tfe7790p_frontend_attach,
					.tuner_attach     = tfe7790p_tuner_attach,
4897 4898 4899 4900 4901 4902 4903 4904 4905 4906 4907

					DIB0700_DEFAULT_STREAMING_CONFIG(0x03),
				} },

				.size_of_priv =
					sizeof(struct dib0700_adapter_state),
			},
		},

		.num_device_descs = 1,
		.devices = {
4908 4909
			{   "DiBcom TFE7790P reference design",
				{ &dib0700_usb_id_table[78], NULL },
4910 4911 4912 4913
				{ NULL },
			},
		},

4914 4915 4916 4917 4918
		.rc.core = {
			.rc_interval      = DEFAULT_RC_INTERVAL,
			.rc_codes         = RC_MAP_DIB0700_RC5_TABLE,
			.module_name	  = "dib0700",
			.rc_query         = dib0700_rc_query_old_firmware,
4919 4920 4921
			.allowed_protos   = RC_BIT_RC5 |
					    RC_BIT_RC6_MCE |
					    RC_BIT_NEC,
4922 4923 4924 4925 4926 4927 4928 4929 4930 4931 4932 4933 4934 4935 4936 4937 4938 4939 4940 4941 4942 4943 4944 4945 4946 4947 4948 4949
			.change_protocol  = dib0700_change_protocol,
		},
	}, { DIB0700_DEFAULT_DEVICE_PROPERTIES,
		.num_adapters = 1,
		.adapter = {
			{
				.num_frontends = 1,
				.fe = {{
					.caps  = DVB_USB_ADAP_HAS_PID_FILTER |
						DVB_USB_ADAP_PID_FILTER_CAN_BE_TURNED_OFF,
					.pid_filter_count = 32,
					.pid_filter = stk80xx_pid_filter,
					.pid_filter_ctrl = stk80xx_pid_filter_ctrl,
					.frontend_attach  = tfe8096p_frontend_attach,
					.tuner_attach     = tfe8096p_tuner_attach,

					DIB0700_DEFAULT_STREAMING_CONFIG(0x02),

				} },

				.size_of_priv =
					sizeof(struct dib0700_adapter_state),
			},
		},

		.num_device_descs = 1,
		.devices = {
			{   "DiBcom TFE8096P reference design",
4950
				{ &dib0700_usb_id_table[79], NULL },
4951 4952 4953 4954
				{ NULL },
			},
		},

4955
		.rc.core = {
4956
			.rc_interval      = DEFAULT_RC_INTERVAL,
4957
			.rc_codes         = RC_MAP_DIB0700_RC5_TABLE,
4958
			.module_name	  = "dib0700",
4959
			.rc_query         = dib0700_rc_query_old_firmware,
4960 4961 4962
			.allowed_protos   = RC_BIT_RC5 |
					    RC_BIT_RC6_MCE |
					    RC_BIT_NEC,
4963
			.change_protocol  = dib0700_change_protocol,
4964
		},
4965
	},
4966 4967 4968
};

int dib0700_device_count = ARRAY_SIZE(dib0700_devices);