1/* Linux driver for devices based on the DiBcom DiB0700 USB bridge
2 *
3 *	This program is free software; you can redistribute it and/or modify it
4 *	under the terms of the GNU General Public License as published by the Free
5 *	Software Foundation, version 2.
6 *
7 *  Copyright (C) 2005-9 DiBcom, SA et al
8 */
9#include "dib0700.h"
10
11#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#include "lgdt3305.h"
25#include "mxl5007t.h"
26
27static int force_lna_activation;
28module_param(force_lna_activation, int, 0644);
29MODULE_PARM_DESC(force_lna_activation, "force the activation of Low-Noise-Amplifyer(s) (LNA), "
30		"if applicable for the device (default: 0=automatic/off).");
31
32struct 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 *  has a LNA on GPIO0 which is enabled by setting 1 */
41static struct mt2060_config bristol_mt2060_config[2] = {
42	{
43		.i2c_address = 0x60,
44		.clock_out   = 3,
45	}, {
46		.i2c_address = 0x61,
47	}
48};
49
50
51static struct dibx000_agc_config bristol_dib3000p_mt2060_agc_config = {
52	.band_caps = BAND_VHF | BAND_UHF,
53	.setup     = (1 << 8) | (5 << 5) | (0 << 4) | (0 << 3) | (0 << 2) | (2 << 0),
54
55	.agc1_max = 42598,
56	.agc1_min = 17694,
57	.agc2_max = 45875,
58	.agc2_min = 0,
59
60	.agc1_pt1 = 0,
61	.agc1_pt2 = 59,
62
63	.agc1_slope1 = 0,
64	.agc1_slope2 = 69,
65
66	.agc2_pt1 = 0,
67	.agc2_pt2 = 59,
68
69	.agc2_slope1 = 111,
70	.agc2_slope2 = 28,
71};
72
73static struct dib3000mc_config bristol_dib3000mc_config[2] = {
74	{	.agc          = &bristol_dib3000p_mt2060_agc_config,
75		.max_time     = 0x196,
76		.ln_adc_level = 0x1cc7,
77		.output_mpeg2_in_188_bytes = 1,
78	},
79	{	.agc          = &bristol_dib3000p_mt2060_agc_config,
80		.max_time     = 0x196,
81		.ln_adc_level = 0x1cc7,
82		.output_mpeg2_in_188_bytes = 1,
83	}
84};
85
86static int bristol_frontend_attach(struct dvb_usb_adapter *adap)
87{
88	struct dib0700_state *st = adap->dev->priv;
89	if (adap->id == 0) {
90		dib0700_set_gpio(adap->dev, GPIO6,  GPIO_OUT, 0); msleep(10);
91		dib0700_set_gpio(adap->dev, GPIO6,  GPIO_OUT, 1); msleep(10);
92		dib0700_set_gpio(adap->dev, GPIO10, GPIO_OUT, 0); msleep(10);
93		dib0700_set_gpio(adap->dev, GPIO10, GPIO_OUT, 1); msleep(10);
94
95		if (force_lna_activation)
96			dib0700_set_gpio(adap->dev, GPIO0, GPIO_OUT, 1);
97		else
98			dib0700_set_gpio(adap->dev, GPIO0, GPIO_OUT, 0);
99
100		if (dib3000mc_i2c_enumeration(&adap->dev->i2c_adap, 2, DEFAULT_DIB3000P_I2C_ADDRESS, bristol_dib3000mc_config) != 0) {
101			dib0700_set_gpio(adap->dev, GPIO6, GPIO_OUT, 0); msleep(10);
102			return -ENODEV;
103		}
104	}
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
110static int eeprom_read(struct i2c_adapter *adap,u8 adrs,u8 *pval)
111{
112	struct i2c_msg msg[2] = {
113		{ .addr = 0x50, .flags = 0,        .buf = &adrs, .len = 1 },
114		{ .addr = 0x50, .flags = I2C_M_RD, .buf = pval,  .len = 1 },
115	};
116	if (i2c_transfer(adap, msg, 2) != 2) return -EREMOTEIO;
117	return 0;
118}
119
120static int bristol_tuner_attach(struct dvb_usb_adapter *adap)
121{
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	s8 a;
125	int if1=1220;
126	if (adap->dev->udev->descriptor.idVendor  == cpu_to_le16(USB_VID_HAUPPAUGE) &&
127		adap->dev->udev->descriptor.idProduct == cpu_to_le16(USB_PID_HAUPPAUGE_NOVA_T_500_2)) {
128		if (!eeprom_read(prim_i2c,0x59 + adap->id,&a)) if1=1220+a;
129	}
130	return dvb_attach(mt2060_attach, adap->fe_adap[0].fe, tun_i2c,
131			  &bristol_mt2060_config[adap->id], if1) == NULL ?
132			  -ENODEV : 0;
133}
134
135/* STK7700D: Pinnacle/Terratec/Hauppauge Dual DVB-T Diversity */
136
137/* MT226x */
138static struct dibx000_agc_config stk7700d_7000p_mt2266_agc_config[2] = {
139	{
140		BAND_UHF,
141
142		/* 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,
143		* 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		(0 << 15) | (0 << 14) | (1 << 11) | (1 << 10) | (1 << 9) | (0 << 8)
145	    | (3 << 5) | (0 << 4) | (5 << 1) | (0 << 0),
146
147		1130,
148		21,
149
150		0,
151		118,
152
153		0,
154		3530,
155		1,
156		0,
157
158		65535,
159		33770,
160		65535,
161		23592,
162
163		0,
164		62,
165		255,
166		64,
167		64,
168		132,
169		192,
170		80,
171		80,
172
173		17,
174		27,
175		23,
176		51,
177
178		1,
179	}, {
180		BAND_VHF | BAND_LBAND,
181
182		/* 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,
183		* 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		(0 << 15) | (0 << 14) | (1 << 11) | (1 << 10) | (1 << 9) | (0 << 8)
185	    | (3 << 5) | (0 << 4) | (2 << 1) | (0 << 0),
186
187		2372,
188		21,
189
190		0,
191		118,
192
193		0,
194		3530,
195		1,
196		0,
197
198		65535,
199		0,
200		65535,
201		23592,
202
203		0,
204		128,
205		128,
206		128,
207		0,
208		128,
209		253,
210		81,
211		0,
212
213		17,
214		27,
215		23,
216		51,
217
218		1,
219	}
220};
221
222static struct dibx000_bandwidth_config stk7700d_mt2266_pll_config = {
223	.internal = 60000,
224	.sampling = 30000,
225	.pll_prediv = 1,
226	.pll_ratio = 8,
227	.pll_range = 3,
228	.pll_reset = 1,
229	.pll_bypass = 0,
230	.enable_refdiv = 0,
231	.bypclk_div = 0,
232	.IO_CLK_en_core = 1,
233	.ADClkSrc = 1,
234	.modulo = 2,
235	.sad_cfg = (3 << 14) | (1 << 12) | (524 << 0),
236	.ifreq = 0,
237	.timf = 20452225,
238};
239
240static struct dib7000p_config stk7700d_dib7000p_mt2266_config[] = {
241	{	.output_mpeg2_in_188_bytes = 1,
242		.hostbus_diversity = 1,
243		.tuner_is_baseband = 1,
244
245		.agc_config_count = 2,
246		.agc = stk7700d_7000p_mt2266_agc_config,
247		.bw  = &stk7700d_mt2266_pll_config,
248
249		.gpio_dir = DIB7000P_GPIO_DEFAULT_DIRECTIONS,
250		.gpio_val = DIB7000P_GPIO_DEFAULT_VALUES,
251		.gpio_pwm_pos = DIB7000P_GPIO_DEFAULT_PWM_POS,
252	},
253	{	.output_mpeg2_in_188_bytes = 1,
254		.hostbus_diversity = 1,
255		.tuner_is_baseband = 1,
256
257		.agc_config_count = 2,
258		.agc = stk7700d_7000p_mt2266_agc_config,
259		.bw  = &stk7700d_mt2266_pll_config,
260
261		.gpio_dir = DIB7000P_GPIO_DEFAULT_DIRECTIONS,
262		.gpio_val = DIB7000P_GPIO_DEFAULT_VALUES,
263		.gpio_pwm_pos = DIB7000P_GPIO_DEFAULT_PWM_POS,
264	}
265};
266
267static struct mt2266_config stk7700d_mt2266_config[2] = {
268	{	.i2c_address = 0x60
269	},
270	{	.i2c_address = 0x60
271	}
272};
273
274static int stk7700P2_frontend_attach(struct dvb_usb_adapter *adap)
275{
276	struct dib0700_adapter_state *state = adap->priv;
277
278	if (!dvb_attach(dib7000p_attach, &state->dib7000p_ops))
279		return -ENODEV;
280
281	if (adap->id == 0) {
282		dib0700_set_gpio(adap->dev, GPIO6, GPIO_OUT, 1);
283		msleep(10);
284		dib0700_set_gpio(adap->dev, GPIO9, GPIO_OUT, 1);
285		dib0700_set_gpio(adap->dev, GPIO4, GPIO_OUT, 1);
286		dib0700_set_gpio(adap->dev, GPIO7, GPIO_OUT, 1);
287		dib0700_set_gpio(adap->dev, GPIO10, GPIO_OUT, 0);
288		msleep(10);
289		dib0700_set_gpio(adap->dev, GPIO10, GPIO_OUT, 1);
290		msleep(10);
291		if (state->dib7000p_ops.i2c_enumeration(&adap->dev->i2c_adap, 1, 18,
292					     stk7700d_dib7000p_mt2266_config)
293		    != 0) {
294			err("%s: state->dib7000p_ops.i2c_enumeration failed.  Cannot continue\n", __func__);
295			dvb_detach(&state->dib7000p_ops);
296			return -ENODEV;
297		}
298	}
299
300	adap->fe_adap[0].fe = state->dib7000p_ops.init(&adap->dev->i2c_adap,
301			   0x80 + (adap->id << 1),
302			   &stk7700d_dib7000p_mt2266_config[adap->id]);
303
304	return adap->fe_adap[0].fe == NULL ? -ENODEV : 0;
305}
306
307static int stk7700d_frontend_attach(struct dvb_usb_adapter *adap)
308{
309	struct dib0700_adapter_state *state = adap->priv;
310
311	if (!dvb_attach(dib7000p_attach, &state->dib7000p_ops))
312		return -ENODEV;
313
314	if (adap->id == 0) {
315		dib0700_set_gpio(adap->dev, GPIO6, GPIO_OUT, 1);
316		msleep(10);
317		dib0700_set_gpio(adap->dev, GPIO9, GPIO_OUT, 1);
318		dib0700_set_gpio(adap->dev, GPIO4, GPIO_OUT, 1);
319		dib0700_set_gpio(adap->dev, GPIO7, GPIO_OUT, 1);
320		dib0700_set_gpio(adap->dev, GPIO10, GPIO_OUT, 0);
321		msleep(10);
322		dib0700_set_gpio(adap->dev, GPIO10, GPIO_OUT, 1);
323		msleep(10);
324		dib0700_set_gpio(adap->dev, GPIO0, GPIO_OUT, 1);
325		if (state->dib7000p_ops.i2c_enumeration(&adap->dev->i2c_adap, 2, 18,
326					     stk7700d_dib7000p_mt2266_config)
327		    != 0) {
328			err("%s: state->dib7000p_ops.i2c_enumeration failed.  Cannot continue\n", __func__);
329			dvb_detach(&state->dib7000p_ops);
330			return -ENODEV;
331		}
332	}
333
334	adap->fe_adap[0].fe = state->dib7000p_ops.init(&adap->dev->i2c_adap,
335			   0x80 + (adap->id << 1),
336			   &stk7700d_dib7000p_mt2266_config[adap->id]);
337
338	return adap->fe_adap[0].fe == NULL ? -ENODEV : 0;
339}
340
341static int stk7700d_tuner_attach(struct dvb_usb_adapter *adap)
342{
343	struct i2c_adapter *tun_i2c;
344	struct dib0700_adapter_state *state = adap->priv;
345
346	tun_i2c = state->dib7000p_ops.get_i2c_master(adap->fe_adap[0].fe,
347					    DIBX000_I2C_INTERFACE_TUNER, 1);
348	return dvb_attach(mt2266_attach, adap->fe_adap[0].fe, tun_i2c,
349		&stk7700d_mt2266_config[adap->id]) == NULL ? -ENODEV : 0;
350}
351
352/* STK7700-PH: Digital/Analog Hybrid Tuner, e.h. Cinergy HT USB HE */
353static struct dibx000_agc_config xc3028_agc_config = {
354	.band_caps = BAND_VHF | BAND_UHF,
355	/* P_agc_use_sd_mod1=0, P_agc_use_sd_mod2=0, P_agc_freq_pwm_div=0,
356	 * P_agc_inv_pwm1=0, P_agc_inv_pwm2=0, P_agc_inh_dc_rv_est=0,
357	 * P_agc_time_est=3, P_agc_freeze=0, P_agc_nb_est=2, P_agc_write=0 */
358	.setup = (0 << 15) | (0 << 14) | (0 << 11) | (0 << 10) | (0 << 9) | (0 << 8) | (3 << 5) | (0 << 4) | (2 << 1) | (0 << 0),
359	.inv_gain = 712,
360	.time_stabiliz = 21,
361	.alpha_level = 0,
362	.thlock = 118,
363	.wbd_inv = 0,
364	.wbd_ref = 2867,
365	.wbd_sel = 0,
366	.wbd_alpha = 2,
367	.agc1_max = 0,
368	.agc1_min = 0,
369	.agc2_max = 39718,
370	.agc2_min = 9930,
371	.agc1_pt1 = 0,
372	.agc1_pt2 = 0,
373	.agc1_pt3 = 0,
374	.agc1_slope1 = 0,
375	.agc1_slope2 = 0,
376	.agc2_pt1 = 0,
377	.agc2_pt2 = 128,
378	.agc2_slope1 = 29,
379	.agc2_slope2 = 29,
380	.alpha_mant = 17,
381	.alpha_exp = 27,
382	.beta_mant = 23,
383	.beta_exp = 51,
384	.perform_agc_softsplit = 1,
385};
386
387/* PLL Configuration for COFDM BW_MHz = 8.00 with external clock = 30.00 */
388static struct dibx000_bandwidth_config xc3028_bw_config = {
389	.internal = 60000,
390	.sampling = 30000,
391	.pll_prediv = 1,
392	.pll_ratio = 8,
393	.pll_range = 3,
394	.pll_reset = 1,
395	.pll_bypass = 0,
396	.enable_refdiv = 0,
397	.bypclk_div = 0,
398	.IO_CLK_en_core = 1,
399	.ADClkSrc = 1,
400	.modulo = 0,
401	.sad_cfg = (3 << 14) | (1 << 12) | (524 << 0), /* sad_cfg: refsel, sel, freq_15k */
402	.ifreq = (1 << 25) | 5816102,  /* ifreq = 5.200000 MHz */
403	.timf = 20452225,
404	.xtal_hz = 30000000,
405};
406
407static struct dib7000p_config stk7700ph_dib7700_xc3028_config = {
408	.output_mpeg2_in_188_bytes = 1,
409	.tuner_is_baseband = 1,
410
411	.agc_config_count = 1,
412	.agc = &xc3028_agc_config,
413	.bw  = &xc3028_bw_config,
414
415	.gpio_dir = DIB7000P_GPIO_DEFAULT_DIRECTIONS,
416	.gpio_val = DIB7000P_GPIO_DEFAULT_VALUES,
417	.gpio_pwm_pos = DIB7000P_GPIO_DEFAULT_PWM_POS,
418};
419
420static int stk7700ph_xc3028_callback(void *ptr, int component,
421				     int command, int arg)
422{
423	struct dvb_usb_adapter *adap = ptr;
424	struct dib0700_adapter_state *state = adap->priv;
425
426	switch (command) {
427	case XC2028_TUNER_RESET:
428		/* Send the tuner in then out of reset */
429		state->dib7000p_ops.set_gpio(adap->fe_adap[0].fe, 8, 0, 0);
430		msleep(10);
431		state->dib7000p_ops.set_gpio(adap->fe_adap[0].fe, 8, 0, 1);
432		break;
433	case XC2028_RESET_CLK:
434		break;
435	default:
436		err("%s: unknown command %d, arg %d\n", __func__,
437			command, arg);
438		return -EINVAL;
439	}
440	return 0;
441}
442
443static struct xc2028_ctrl stk7700ph_xc3028_ctrl = {
444	.fname = XC2028_DEFAULT_FIRMWARE,
445	.max_len = 64,
446	.demod = XC3028_FE_DIBCOM52,
447};
448
449static struct xc2028_config stk7700ph_xc3028_config = {
450	.i2c_addr = 0x61,
451	.ctrl = &stk7700ph_xc3028_ctrl,
452};
453
454static int stk7700ph_frontend_attach(struct dvb_usb_adapter *adap)
455{
456	struct usb_device_descriptor *desc = &adap->dev->udev->descriptor;
457	struct dib0700_adapter_state *state = adap->priv;
458
459	if (!dvb_attach(dib7000p_attach, &state->dib7000p_ops))
460		return -ENODEV;
461
462	if (desc->idVendor  == cpu_to_le16(USB_VID_PINNACLE) &&
463	    desc->idProduct == cpu_to_le16(USB_PID_PINNACLE_EXPRESSCARD_320CX))
464		dib0700_set_gpio(adap->dev, GPIO6, GPIO_OUT, 0);
465	else
466		dib0700_set_gpio(adap->dev, GPIO6, GPIO_OUT, 1);
467	msleep(20);
468	dib0700_set_gpio(adap->dev, GPIO9, GPIO_OUT, 1);
469	dib0700_set_gpio(adap->dev, GPIO4, GPIO_OUT, 1);
470	dib0700_set_gpio(adap->dev, GPIO7, GPIO_OUT, 1);
471	dib0700_set_gpio(adap->dev, GPIO10, GPIO_OUT, 0);
472	msleep(10);
473	dib0700_set_gpio(adap->dev, GPIO10, GPIO_OUT, 1);
474	msleep(20);
475	dib0700_set_gpio(adap->dev, GPIO0, GPIO_OUT, 1);
476	msleep(10);
477
478	if (state->dib7000p_ops.i2c_enumeration(&adap->dev->i2c_adap, 1, 18,
479				     &stk7700ph_dib7700_xc3028_config) != 0) {
480		err("%s: state->dib7000p_ops.i2c_enumeration failed.  Cannot continue\n",
481		    __func__);
482		dvb_detach(&state->dib7000p_ops);
483		return -ENODEV;
484	}
485
486	adap->fe_adap[0].fe = state->dib7000p_ops.init(&adap->dev->i2c_adap, 0x80,
487		&stk7700ph_dib7700_xc3028_config);
488
489	return adap->fe_adap[0].fe == NULL ? -ENODEV : 0;
490}
491
492static int stk7700ph_tuner_attach(struct dvb_usb_adapter *adap)
493{
494	struct i2c_adapter *tun_i2c;
495	struct dib0700_adapter_state *state = adap->priv;
496
497	tun_i2c = state->dib7000p_ops.get_i2c_master(adap->fe_adap[0].fe,
498		DIBX000_I2C_INTERFACE_TUNER, 1);
499
500	stk7700ph_xc3028_config.i2c_adap = tun_i2c;
501
502	/* FIXME: generalize & move to common area */
503	adap->fe_adap[0].fe->callback = stk7700ph_xc3028_callback;
504
505	return dvb_attach(xc2028_attach, adap->fe_adap[0].fe, &stk7700ph_xc3028_config)
506		== NULL ? -ENODEV : 0;
507}
508
509#define DEFAULT_RC_INTERVAL 50
510
511static u8 rc_request[] = { REQUEST_POLL_RC, 0 };
512
513/*
514 * This function is used only when firmware is < 1.20 version. Newer
515 * firmwares use bulk mode, with functions implemented at dib0700_core,
516 * at dib0700_rc_urb_completion()
517 */
518static int dib0700_rc_query_old_firmware(struct dvb_usb_device *d)
519{
520	u8 key[4];
521	enum rc_type protocol;
522	u32 scancode;
523	u8 toggle;
524	int i;
525	struct dib0700_state *st = d->priv;
526
527	if (st->fw_version >= 0x10200) {
528		/* For 1.20 firmware , We need to keep the RC polling
529		   callback so we can reuse the input device setup in
530		   dvb-usb-remote.c.  However, the actual work is being done
531		   in the bulk URB completion handler. */
532		return 0;
533	}
534
535	i = dib0700_ctrl_rd(d, rc_request, 2, key, 4);
536	if (i <= 0) {
537		err("RC Query Failed");
538		return -1;
539	}
540
541	/* losing half of KEY_0 events from Philipps rc5 remotes.. */
542	if (key[0] == 0 && key[1] == 0 && key[2] == 0 && key[3] == 0)
543		return 0;
544
545	/* 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]);  */
546
547	dib0700_rc_setup(d, NULL); /* reset ir sensor data to prevent false events */
548
549	switch (d->props.rc.core.protocol) {
550	case RC_BIT_NEC:
551		/* NEC protocol sends repeat code as 0 0 0 FF */
552		if ((key[3-2] == 0x00) && (key[3-3] == 0x00) &&
553		    (key[3] == 0xff)) {
554			rc_repeat(d->rc_dev);
555			return 0;
556		}
557
558		protocol = RC_TYPE_NEC;
559		scancode = RC_SCANCODE_NEC(key[3-2], key[3-3]);
560		toggle = 0;
561		break;
562
563	default:
564		/* RC-5 protocol changes toggle bit on new keypress */
565		protocol = RC_TYPE_RC5;
566		scancode = RC_SCANCODE_RC5(key[3-2], key[3-3]);
567		toggle = key[3-1];
568		break;
569	}
570
571	rc_keydown(d->rc_dev, protocol, scancode, toggle);
572	return 0;
573}
574
575/* STK7700P: Hauppauge Nova-T Stick, AVerMedia Volar */
576static struct dibx000_agc_config stk7700p_7000m_mt2060_agc_config = {
577	BAND_UHF | BAND_VHF,
578
579	/* 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,
580	 * 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 */
581	(0 << 15) | (0 << 14) | (5 << 11) | (0 << 10) | (0 << 9) | (0 << 8)
582	| (3 << 5) | (0 << 4) | (2 << 1) | (0 << 0),
583
584	712,
585	41,
586
587	0,
588	118,
589
590	0,
591	4095,
592	0,
593	0,
594
595	42598,
596	17694,
597	45875,
598	2621,
599	0,
600	76,
601	139,
602	52,
603	59,
604	107,
605	172,
606	57,
607	70,
608
609	21,
610	25,
611	28,
612	48,
613
614	1,
615	{  0,
616	   107,
617	   51800,
618	   24700
619	},
620};
621
622static struct dibx000_agc_config stk7700p_7000p_mt2060_agc_config = {
623	.band_caps = BAND_UHF | BAND_VHF,
624	/* 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,
625	 * 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 */
626	.setup = (0 << 15) | (0 << 14) | (5 << 11) | (0 << 10) | (0 << 9) | (0 << 8) | (3 << 5) | (0 << 4) | (2 << 1) | (0 << 0),
627	.inv_gain = 712,
628	.time_stabiliz = 41,
629	.alpha_level = 0,
630	.thlock = 118,
631	.wbd_inv = 0,
632	.wbd_ref = 4095,
633	.wbd_sel = 0,
634	.wbd_alpha = 0,
635	.agc1_max = 42598,
636	.agc1_min = 16384,
637	.agc2_max = 42598,
638	.agc2_min = 0,
639	.agc1_pt1 = 0,
640	.agc1_pt2 = 137,
641	.agc1_pt3 = 255,
642	.agc1_slope1 = 0,
643	.agc1_slope2 = 255,
644	.agc2_pt1 = 0,
645	.agc2_pt2 = 0,
646	.agc2_slope1 = 0,
647	.agc2_slope2 = 41,
648	.alpha_mant = 15,
649	.alpha_exp = 25,
650	.beta_mant = 28,
651	.beta_exp = 48,
652	.perform_agc_softsplit = 0,
653};
654
655static struct dibx000_bandwidth_config stk7700p_pll_config = {
656	.internal = 60000,
657	.sampling = 30000,
658	.pll_prediv = 1,
659	.pll_ratio = 8,
660	.pll_range = 3,
661	.pll_reset = 1,
662	.pll_bypass = 0,
663	.enable_refdiv = 0,
664	.bypclk_div = 0,
665	.IO_CLK_en_core = 1,
666	.ADClkSrc = 1,
667	.modulo = 0,
668	.sad_cfg = (3 << 14) | (1 << 12) | (524 << 0),
669	.ifreq = 60258167,
670	.timf = 20452225,
671	.xtal_hz = 30000000,
672};
673
674static struct dib7000m_config stk7700p_dib7000m_config = {
675	.dvbt_mode = 1,
676	.output_mpeg2_in_188_bytes = 1,
677	.quartz_direct = 1,
678
679	.agc_config_count = 1,
680	.agc = &stk7700p_7000m_mt2060_agc_config,
681	.bw  = &stk7700p_pll_config,
682
683	.gpio_dir = DIB7000M_GPIO_DEFAULT_DIRECTIONS,
684	.gpio_val = DIB7000M_GPIO_DEFAULT_VALUES,
685	.gpio_pwm_pos = DIB7000M_GPIO_DEFAULT_PWM_POS,
686};
687
688static struct dib7000p_config stk7700p_dib7000p_config = {
689	.output_mpeg2_in_188_bytes = 1,
690
691	.agc_config_count = 1,
692	.agc = &stk7700p_7000p_mt2060_agc_config,
693	.bw  = &stk7700p_pll_config,
694
695	.gpio_dir = DIB7000M_GPIO_DEFAULT_DIRECTIONS,
696	.gpio_val = DIB7000M_GPIO_DEFAULT_VALUES,
697	.gpio_pwm_pos = DIB7000M_GPIO_DEFAULT_PWM_POS,
698};
699
700static int stk7700p_frontend_attach(struct dvb_usb_adapter *adap)
701{
702	struct dib0700_state *st = adap->dev->priv;
703	struct dib0700_adapter_state *state = adap->priv;
704
705	if (!dvb_attach(dib7000p_attach, &state->dib7000p_ops))
706		return -ENODEV;
707
708	/* unless there is no real power management in DVB - we leave the device on GPIO6 */
709
710	dib0700_set_gpio(adap->dev, GPIO10, GPIO_OUT, 0);
711	dib0700_set_gpio(adap->dev, GPIO6,  GPIO_OUT, 0); msleep(50);
712
713	dib0700_set_gpio(adap->dev, GPIO6,  GPIO_OUT, 1); msleep(10);
714	dib0700_set_gpio(adap->dev, GPIO9,  GPIO_OUT, 1);
715
716	dib0700_set_gpio(adap->dev, GPIO10, GPIO_OUT, 0); msleep(10);
717	dib0700_ctrl_clock(adap->dev, 72, 1);
718	dib0700_set_gpio(adap->dev, GPIO10, GPIO_OUT, 1); msleep(100);
719
720	dib0700_set_gpio(adap->dev,  GPIO0, GPIO_OUT, 1);
721
722	st->mt2060_if1[0] = 1220;
723
724	if (state->dib7000p_ops.dib7000pc_detection(&adap->dev->i2c_adap)) {
725		adap->fe_adap[0].fe = state->dib7000p_ops.init(&adap->dev->i2c_adap, 18, &stk7700p_dib7000p_config);
726		st->is_dib7000pc = 1;
727	} else {
728		memset(&state->dib7000p_ops, 0, sizeof(state->dib7000p_ops));
729		adap->fe_adap[0].fe = dvb_attach(dib7000m_attach, &adap->dev->i2c_adap, 18, &stk7700p_dib7000m_config);
730	}
731
732	return adap->fe_adap[0].fe == NULL ? -ENODEV : 0;
733}
734
735static struct mt2060_config stk7700p_mt2060_config = {
736	0x60
737};
738
739static int stk7700p_tuner_attach(struct dvb_usb_adapter *adap)
740{
741	struct i2c_adapter *prim_i2c = &adap->dev->i2c_adap;
742	struct dib0700_state *st = adap->dev->priv;
743	struct i2c_adapter *tun_i2c;
744	struct dib0700_adapter_state *state = adap->priv;
745	s8 a;
746	int if1=1220;
747
748	if (adap->dev->udev->descriptor.idVendor  == cpu_to_le16(USB_VID_HAUPPAUGE) &&
749		adap->dev->udev->descriptor.idProduct == cpu_to_le16(USB_PID_HAUPPAUGE_NOVA_T_STICK)) {
750		if (!eeprom_read(prim_i2c,0x58,&a)) if1=1220+a;
751	}
752	if (st->is_dib7000pc)
753		tun_i2c = state->dib7000p_ops.get_i2c_master(adap->fe_adap[0].fe, DIBX000_I2C_INTERFACE_TUNER, 1);
754	else
755		tun_i2c = dib7000m_get_i2c_master(adap->fe_adap[0].fe, DIBX000_I2C_INTERFACE_TUNER, 1);
756
757	return dvb_attach(mt2060_attach, adap->fe_adap[0].fe, tun_i2c, &stk7700p_mt2060_config,
758		if1) == NULL ? -ENODEV : 0;
759}
760
761/* DIB7070 generic */
762static struct dibx000_agc_config dib7070_agc_config = {
763	.band_caps = BAND_UHF | BAND_VHF | BAND_LBAND | BAND_SBAND,
764	/* 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,
765	 * 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 */
766	.setup = (0 << 15) | (0 << 14) | (5 << 11) | (0 << 10) | (0 << 9) | (0 << 8) | (3 << 5) | (0 << 4) | (5 << 1) | (0 << 0),
767	.inv_gain = 600,
768	.time_stabiliz = 10,
769	.alpha_level = 0,
770	.thlock = 118,
771	.wbd_inv = 0,
772	.wbd_ref = 3530,
773	.wbd_sel = 1,
774	.wbd_alpha = 5,
775	.agc1_max = 65535,
776	.agc1_min = 0,
777	.agc2_max = 65535,
778	.agc2_min = 0,
779	.agc1_pt1 = 0,
780	.agc1_pt2 = 40,
781	.agc1_pt3 = 183,
782	.agc1_slope1 = 206,
783	.agc1_slope2 = 255,
784	.agc2_pt1 = 72,
785	.agc2_pt2 = 152,
786	.agc2_slope1 = 88,
787	.agc2_slope2 = 90,
788	.alpha_mant = 17,
789	.alpha_exp = 27,
790	.beta_mant = 23,
791	.beta_exp = 51,
792	.perform_agc_softsplit = 0,
793};
794
795static int dib7070_tuner_reset(struct dvb_frontend *fe, int onoff)
796{
797	struct dvb_usb_adapter *adap = fe->dvb->priv;
798	struct dib0700_adapter_state *state = adap->priv;
799
800	deb_info("reset: %d", onoff);
801	return state->dib7000p_ops.set_gpio(fe, 8, 0, !onoff);
802}
803
804static int dib7070_tuner_sleep(struct dvb_frontend *fe, int onoff)
805{
806	struct dvb_usb_adapter *adap = fe->dvb->priv;
807	struct dib0700_adapter_state *state = adap->priv;
808
809	deb_info("sleep: %d", onoff);
810	return state->dib7000p_ops.set_gpio(fe, 9, 0, onoff);
811}
812
813static struct dib0070_config dib7070p_dib0070_config[2] = {
814	{
815		.i2c_address = DEFAULT_DIB0070_I2C_ADDRESS,
816		.reset = dib7070_tuner_reset,
817		.sleep = dib7070_tuner_sleep,
818		.clock_khz = 12000,
819		.clock_pad_drive = 4,
820		.charge_pump = 2,
821	}, {
822		.i2c_address = DEFAULT_DIB0070_I2C_ADDRESS,
823		.reset = dib7070_tuner_reset,
824		.sleep = dib7070_tuner_sleep,
825		.clock_khz = 12000,
826		.charge_pump = 2,
827	}
828};
829
830static struct dib0070_config dib7770p_dib0070_config = {
831	 .i2c_address = DEFAULT_DIB0070_I2C_ADDRESS,
832	 .reset = dib7070_tuner_reset,
833	 .sleep = dib7070_tuner_sleep,
834	 .clock_khz = 12000,
835	 .clock_pad_drive = 0,
836	 .flip_chip = 1,
837	 .charge_pump = 2,
838};
839
840static int dib7070_set_param_override(struct dvb_frontend *fe)
841{
842	struct dtv_frontend_properties *p = &fe->dtv_property_cache;
843	struct dvb_usb_adapter *adap = fe->dvb->priv;
844	struct dib0700_adapter_state *state = adap->priv;
845
846	u16 offset;
847	u8 band = BAND_OF_FREQUENCY(p->frequency/1000);
848	switch (band) {
849		case BAND_VHF: offset = 950; break;
850		case BAND_UHF:
851		default: offset = 550; break;
852	}
853	deb_info("WBD for DiB7000P: %d\n", offset + dib0070_wbd_offset(fe));
854	state->dib7000p_ops.set_wbd_ref(fe, offset + dib0070_wbd_offset(fe));
855	return state->set_param_save(fe);
856}
857
858static int dib7770_set_param_override(struct dvb_frontend *fe)
859{
860	struct dtv_frontend_properties *p = &fe->dtv_property_cache;
861	struct dvb_usb_adapter *adap = fe->dvb->priv;
862	struct dib0700_adapter_state *state = adap->priv;
863
864	 u16 offset;
865	 u8 band = BAND_OF_FREQUENCY(p->frequency/1000);
866	 switch (band) {
867	 case BAND_VHF:
868		  state->dib7000p_ops.set_gpio(fe, 0, 0, 1);
869		  offset = 850;
870		  break;
871	 case BAND_UHF:
872	 default:
873		  state->dib7000p_ops.set_gpio(fe, 0, 0, 0);
874		  offset = 250;
875		  break;
876	 }
877	 deb_info("WBD for DiB7000P: %d\n", offset + dib0070_wbd_offset(fe));
878	 state->dib7000p_ops.set_wbd_ref(fe, offset + dib0070_wbd_offset(fe));
879	 return state->set_param_save(fe);
880}
881
882static int dib7770p_tuner_attach(struct dvb_usb_adapter *adap)
883{
884	struct dib0700_adapter_state *st = adap->priv;
885	struct i2c_adapter *tun_i2c = st->dib7000p_ops.get_i2c_master(adap->fe_adap[0].fe,
886			 DIBX000_I2C_INTERFACE_TUNER, 1);
887
888	if (dvb_attach(dib0070_attach, adap->fe_adap[0].fe, tun_i2c,
889		       &dib7770p_dib0070_config) == NULL)
890		return -ENODEV;
891
892	st->set_param_save = adap->fe_adap[0].fe->ops.tuner_ops.set_params;
893	adap->fe_adap[0].fe->ops.tuner_ops.set_params = dib7770_set_param_override;
894	return 0;
895}
896
897static int dib7070p_tuner_attach(struct dvb_usb_adapter *adap)
898{
899	struct dib0700_adapter_state *st = adap->priv;
900	struct i2c_adapter *tun_i2c = st->dib7000p_ops.get_i2c_master(adap->fe_adap[0].fe, DIBX000_I2C_INTERFACE_TUNER, 1);
901
902	if (adap->id == 0) {
903		if (dvb_attach(dib0070_attach, adap->fe_adap[0].fe, tun_i2c, &dib7070p_dib0070_config[0]) == NULL)
904			return -ENODEV;
905	} else {
906		if (dvb_attach(dib0070_attach, adap->fe_adap[0].fe, tun_i2c, &dib7070p_dib0070_config[1]) == NULL)
907			return -ENODEV;
908	}
909
910	st->set_param_save = adap->fe_adap[0].fe->ops.tuner_ops.set_params;
911	adap->fe_adap[0].fe->ops.tuner_ops.set_params = dib7070_set_param_override;
912	return 0;
913}
914
915static int stk7700p_pid_filter(struct dvb_usb_adapter *adapter, int index,
916		u16 pid, int onoff)
917{
918	struct dib0700_adapter_state *state = adapter->priv;
919	struct dib0700_state *st = adapter->dev->priv;
920
921	if (st->is_dib7000pc)
922		return state->dib7000p_ops.pid_filter(adapter->fe_adap[0].fe, index, pid, onoff);
923	return dib7000m_pid_filter(adapter->fe_adap[0].fe, index, pid, onoff);
924}
925
926static int stk7700p_pid_filter_ctrl(struct dvb_usb_adapter *adapter, int onoff)
927{
928	struct dib0700_state *st = adapter->dev->priv;
929	struct dib0700_adapter_state *state = adapter->priv;
930	if (st->is_dib7000pc)
931		return state->dib7000p_ops.pid_filter_ctrl(adapter->fe_adap[0].fe, onoff);
932	return dib7000m_pid_filter_ctrl(adapter->fe_adap[0].fe, onoff);
933}
934
935static int stk70x0p_pid_filter(struct dvb_usb_adapter *adapter, int index, u16 pid, int onoff)
936{
937	struct dib0700_adapter_state *state = adapter->priv;
938	return state->dib7000p_ops.pid_filter(adapter->fe_adap[0].fe, index, pid, onoff);
939}
940
941static int stk70x0p_pid_filter_ctrl(struct dvb_usb_adapter *adapter, int onoff)
942{
943	struct dib0700_adapter_state *state = adapter->priv;
944	return state->dib7000p_ops.pid_filter_ctrl(adapter->fe_adap[0].fe, onoff);
945}
946
947static struct dibx000_bandwidth_config dib7070_bw_config_12_mhz = {
948	.internal = 60000,
949	.sampling = 15000,
950	.pll_prediv = 1,
951	.pll_ratio = 20,
952	.pll_range = 3,
953	.pll_reset = 1,
954	.pll_bypass = 0,
955	.enable_refdiv = 0,
956	.bypclk_div = 0,
957	.IO_CLK_en_core = 1,
958	.ADClkSrc = 1,
959	.modulo = 2,
960	.sad_cfg = (3 << 14) | (1 << 12) | (524 << 0),
961	.ifreq = (0 << 25) | 0,
962	.timf = 20452225,
963	.xtal_hz = 12000000,
964};
965
966static struct dib7000p_config dib7070p_dib7000p_config = {
967	.output_mpeg2_in_188_bytes = 1,
968
969	.agc_config_count = 1,
970	.agc = &dib7070_agc_config,
971	.bw  = &dib7070_bw_config_12_mhz,
972	.tuner_is_baseband = 1,
973	.spur_protect = 1,
974
975	.gpio_dir = DIB7000P_GPIO_DEFAULT_DIRECTIONS,
976	.gpio_val = DIB7000P_GPIO_DEFAULT_VALUES,
977	.gpio_pwm_pos = DIB7000P_GPIO_DEFAULT_PWM_POS,
978
979	.hostbus_diversity = 1,
980};
981
982/* STK7070P */
983static int stk7070p_frontend_attach(struct dvb_usb_adapter *adap)
984{
985	struct usb_device_descriptor *p = &adap->dev->udev->descriptor;
986	struct dib0700_adapter_state *state = adap->priv;
987
988	if (!dvb_attach(dib7000p_attach, &state->dib7000p_ops))
989		return -ENODEV;
990
991	if (p->idVendor  == cpu_to_le16(USB_VID_PINNACLE) &&
992	    p->idProduct == cpu_to_le16(USB_PID_PINNACLE_PCTV72E))
993		dib0700_set_gpio(adap->dev, GPIO6, GPIO_OUT, 0);
994	else
995		dib0700_set_gpio(adap->dev, GPIO6, GPIO_OUT, 1);
996	msleep(10);
997	dib0700_set_gpio(adap->dev, GPIO9, GPIO_OUT, 1);
998	dib0700_set_gpio(adap->dev, GPIO4, GPIO_OUT, 1);
999	dib0700_set_gpio(adap->dev, GPIO7, GPIO_OUT, 1);
1000	dib0700_set_gpio(adap->dev, GPIO10, GPIO_OUT, 0);
1001
1002	dib0700_ctrl_clock(adap->dev, 72, 1);
1003
1004	msleep(10);
1005	dib0700_set_gpio(adap->dev, GPIO10, GPIO_OUT, 1);
1006	msleep(10);
1007	dib0700_set_gpio(adap->dev, GPIO0, GPIO_OUT, 1);
1008
1009	if (state->dib7000p_ops.i2c_enumeration(&adap->dev->i2c_adap, 1, 18,
1010				     &dib7070p_dib7000p_config) != 0) {
1011		err("%s: state->dib7000p_ops.i2c_enumeration failed.  Cannot continue\n",
1012		    __func__);
1013		dvb_detach(&state->dib7000p_ops);
1014		return -ENODEV;
1015	}
1016
1017	adap->fe_adap[0].fe = state->dib7000p_ops.init(&adap->dev->i2c_adap, 0x80,
1018		&dib7070p_dib7000p_config);
1019	return adap->fe_adap[0].fe == NULL ? -ENODEV : 0;
1020}
1021
1022/* STK7770P */
1023static struct dib7000p_config dib7770p_dib7000p_config = {
1024	.output_mpeg2_in_188_bytes = 1,
1025
1026	.agc_config_count = 1,
1027	.agc = &dib7070_agc_config,
1028	.bw  = &dib7070_bw_config_12_mhz,
1029	.tuner_is_baseband = 1,
1030	.spur_protect = 1,
1031
1032	.gpio_dir = DIB7000P_GPIO_DEFAULT_DIRECTIONS,
1033	.gpio_val = DIB7000P_GPIO_DEFAULT_VALUES,
1034	.gpio_pwm_pos = DIB7000P_GPIO_DEFAULT_PWM_POS,
1035
1036	.hostbus_diversity = 1,
1037	.enable_current_mirror = 1,
1038	.disable_sample_and_hold = 0,
1039};
1040
1041static int stk7770p_frontend_attach(struct dvb_usb_adapter *adap)
1042{
1043	struct usb_device_descriptor *p = &adap->dev->udev->descriptor;
1044	struct dib0700_adapter_state *state = adap->priv;
1045
1046	if (!dvb_attach(dib7000p_attach, &state->dib7000p_ops))
1047		return -ENODEV;
1048
1049	if (p->idVendor  == cpu_to_le16(USB_VID_PINNACLE) &&
1050	    p->idProduct == cpu_to_le16(USB_PID_PINNACLE_PCTV72E))
1051		dib0700_set_gpio(adap->dev, GPIO6, GPIO_OUT, 0);
1052	else
1053		dib0700_set_gpio(adap->dev, GPIO6, GPIO_OUT, 1);
1054	msleep(10);
1055	dib0700_set_gpio(adap->dev, GPIO9, GPIO_OUT, 1);
1056	dib0700_set_gpio(adap->dev, GPIO4, GPIO_OUT, 1);
1057	dib0700_set_gpio(adap->dev, GPIO7, GPIO_OUT, 1);
1058	dib0700_set_gpio(adap->dev, GPIO10, GPIO_OUT, 0);
1059
1060	dib0700_ctrl_clock(adap->dev, 72, 1);
1061
1062	msleep(10);
1063	dib0700_set_gpio(adap->dev, GPIO10, GPIO_OUT, 1);
1064	msleep(10);
1065	dib0700_set_gpio(adap->dev, GPIO0, GPIO_OUT, 1);
1066
1067	if (state->dib7000p_ops.i2c_enumeration(&adap->dev->i2c_adap, 1, 18,
1068				     &dib7770p_dib7000p_config) != 0) {
1069		err("%s: state->dib7000p_ops.i2c_enumeration failed.  Cannot continue\n",
1070		    __func__);
1071		dvb_detach(&state->dib7000p_ops);
1072		return -ENODEV;
1073	}
1074
1075	adap->fe_adap[0].fe = state->dib7000p_ops.init(&adap->dev->i2c_adap, 0x80,
1076		&dib7770p_dib7000p_config);
1077	return adap->fe_adap[0].fe == NULL ? -ENODEV : 0;
1078}
1079
1080/* DIB807x generic */
1081static struct dibx000_agc_config dib807x_agc_config[2] = {
1082	{
1083		BAND_VHF,
1084		/* P_agc_use_sd_mod1=0, P_agc_use_sd_mod2=0,
1085		 * P_agc_freq_pwm_div=1, P_agc_inv_pwm1=0,
1086		 * P_agc_inv_pwm2=0,P_agc_inh_dc_rv_est=0,
1087		 * P_agc_time_est=3, P_agc_freeze=0, P_agc_nb_est=5,
1088		 * P_agc_write=0 */
1089		(0 << 15) | (0 << 14) | (7 << 11) | (0 << 10) | (0 << 9) |
1090			(0 << 8) | (3 << 5) | (0 << 4) | (5 << 1) |
1091			(0 << 0), /* setup*/
1092
1093		600, /* inv_gain*/
1094		10,  /* time_stabiliz*/
1095
1096		0,  /* alpha_level*/
1097		118,  /* thlock*/
1098
1099		0,     /* wbd_inv*/
1100		3530,  /* wbd_ref*/
1101		1,     /* wbd_sel*/
1102		5,     /* wbd_alpha*/
1103
1104		65535,  /* agc1_max*/
1105		0,  /* agc1_min*/
1106
1107		65535,  /* agc2_max*/
1108		0,      /* agc2_min*/
1109
1110		0,      /* agc1_pt1*/
1111		40,     /* agc1_pt2*/
1112		183,    /* agc1_pt3*/
1113		206,    /* agc1_slope1*/
1114		255,    /* agc1_slope2*/
1115		72,     /* agc2_pt1*/
1116		152,    /* agc2_pt2*/
1117		88,     /* agc2_slope1*/
1118		90,     /* agc2_slope2*/
1119
1120		17,  /* alpha_mant*/
1121		27,  /* alpha_exp*/
1122		23,  /* beta_mant*/
1123		51,  /* beta_exp*/
1124
1125		0,  /* perform_agc_softsplit*/
1126	}, {
1127		BAND_UHF,
1128		/* P_agc_use_sd_mod1=0, P_agc_use_sd_mod2=0,
1129		 * P_agc_freq_pwm_div=1, P_agc_inv_pwm1=0,
1130		 * P_agc_inv_pwm2=0, P_agc_inh_dc_rv_est=0,
1131		 * P_agc_time_est=3, P_agc_freeze=0, P_agc_nb_est=5,
1132		 * P_agc_write=0 */
1133		(0 << 15) | (0 << 14) | (1 << 11) | (0 << 10) | (0 << 9) |
1134			(0 << 8) | (3 << 5) | (0 << 4) | (5 << 1) |
1135			(0 << 0), /* setup */
1136
1137		600, /* inv_gain*/
1138		10,  /* time_stabiliz*/
1139
1140		0,  /* alpha_level*/
1141		118,  /* thlock*/
1142
1143		0,     /* wbd_inv*/
1144		3530,  /* wbd_ref*/
1145		1,     /* wbd_sel*/
1146		5,     /* wbd_alpha*/
1147
1148		65535,  /* agc1_max*/
1149		0,  /* agc1_min*/
1150
1151		65535,  /* agc2_max*/
1152		0,      /* agc2_min*/
1153
1154		0,      /* agc1_pt1*/
1155		40,     /* agc1_pt2*/
1156		183,    /* agc1_pt3*/
1157		206,    /* agc1_slope1*/
1158		255,    /* agc1_slope2*/
1159		72,     /* agc2_pt1*/
1160		152,    /* agc2_pt2*/
1161		88,     /* agc2_slope1*/
1162		90,     /* agc2_slope2*/
1163
1164		17,  /* alpha_mant*/
1165		27,  /* alpha_exp*/
1166		23,  /* beta_mant*/
1167		51,  /* beta_exp*/
1168
1169		0,  /* perform_agc_softsplit*/
1170	}
1171};
1172
1173static struct dibx000_bandwidth_config dib807x_bw_config_12_mhz = {
1174	.internal = 60000,
1175	.sampling = 15000,
1176	.pll_prediv = 1,
1177	.pll_ratio = 20,
1178	.pll_range = 3,
1179	.pll_reset = 1,
1180	.pll_bypass = 0,
1181	.enable_refdiv = 0,
1182	.bypclk_div = 0,
1183	.IO_CLK_en_core = 1,
1184	.ADClkSrc = 1,
1185	.modulo = 2,
1186	.sad_cfg = (3 << 14) | (1 << 12) | (599 << 0),	/* sad_cfg: refsel, sel, freq_15k*/
1187	.ifreq = (0 << 25) | 0,				/* ifreq = 0.000000 MHz*/
1188	.timf = 18179755,
1189	.xtal_hz = 12000000,
1190};
1191
1192static struct dib8000_config dib807x_dib8000_config[2] = {
1193	{
1194		.output_mpeg2_in_188_bytes = 1,
1195
1196		.agc_config_count = 2,
1197		.agc = dib807x_agc_config,
1198		.pll = &dib807x_bw_config_12_mhz,
1199		.tuner_is_baseband = 1,
1200
1201		.gpio_dir = DIB8000_GPIO_DEFAULT_DIRECTIONS,
1202		.gpio_val = DIB8000_GPIO_DEFAULT_VALUES,
1203		.gpio_pwm_pos = DIB8000_GPIO_DEFAULT_PWM_POS,
1204
1205		.hostbus_diversity = 1,
1206		.div_cfg = 1,
1207		.agc_control = &dib0070_ctrl_agc_filter,
1208		.output_mode = OUTMODE_MPEG2_FIFO,
1209		.drives = 0x2d98,
1210	}, {
1211		.output_mpeg2_in_188_bytes = 1,
1212
1213		.agc_config_count = 2,
1214		.agc = dib807x_agc_config,
1215		.pll = &dib807x_bw_config_12_mhz,
1216		.tuner_is_baseband = 1,
1217
1218		.gpio_dir = DIB8000_GPIO_DEFAULT_DIRECTIONS,
1219		.gpio_val = DIB8000_GPIO_DEFAULT_VALUES,
1220		.gpio_pwm_pos = DIB8000_GPIO_DEFAULT_PWM_POS,
1221
1222		.hostbus_diversity = 1,
1223		.agc_control = &dib0070_ctrl_agc_filter,
1224		.output_mode = OUTMODE_MPEG2_FIFO,
1225		.drives = 0x2d98,
1226	}
1227};
1228
1229static int dib80xx_tuner_reset(struct dvb_frontend *fe, int onoff)
1230{
1231	struct dvb_usb_adapter *adap = fe->dvb->priv;
1232	struct dib0700_adapter_state *state = adap->priv;
1233
1234	return state->dib8000_ops.set_gpio(fe, 5, 0, !onoff);
1235}
1236
1237static int dib80xx_tuner_sleep(struct dvb_frontend *fe, int onoff)
1238{
1239	struct dvb_usb_adapter *adap = fe->dvb->priv;
1240	struct dib0700_adapter_state *state = adap->priv;
1241
1242	return state->dib8000_ops.set_gpio(fe, 0, 0, onoff);
1243}
1244
1245static const struct dib0070_wbd_gain_cfg dib8070_wbd_gain_cfg[] = {
1246    { 240,      7},
1247    { 0xffff,   6},
1248};
1249
1250static struct dib0070_config dib807x_dib0070_config[2] = {
1251	{
1252		.i2c_address = DEFAULT_DIB0070_I2C_ADDRESS,
1253		.reset = dib80xx_tuner_reset,
1254		.sleep = dib80xx_tuner_sleep,
1255		.clock_khz = 12000,
1256		.clock_pad_drive = 4,
1257		.vga_filter = 1,
1258		.force_crystal_mode = 1,
1259		.enable_third_order_filter = 1,
1260		.charge_pump = 0,
1261		.wbd_gain = dib8070_wbd_gain_cfg,
1262		.osc_buffer_state = 0,
1263		.freq_offset_khz_uhf = -100,
1264		.freq_offset_khz_vhf = -100,
1265	}, {
1266		.i2c_address = DEFAULT_DIB0070_I2C_ADDRESS,
1267		.reset = dib80xx_tuner_reset,
1268		.sleep = dib80xx_tuner_sleep,
1269		.clock_khz = 12000,
1270		.clock_pad_drive = 2,
1271		.vga_filter = 1,
1272		.force_crystal_mode = 1,
1273		.enable_third_order_filter = 1,
1274		.charge_pump = 0,
1275		.wbd_gain = dib8070_wbd_gain_cfg,
1276		.osc_buffer_state = 0,
1277		.freq_offset_khz_uhf = -25,
1278		.freq_offset_khz_vhf = -25,
1279	}
1280};
1281
1282static int dib807x_set_param_override(struct dvb_frontend *fe)
1283{
1284	struct dtv_frontend_properties *p = &fe->dtv_property_cache;
1285	struct dvb_usb_adapter *adap = fe->dvb->priv;
1286	struct dib0700_adapter_state *state = adap->priv;
1287
1288	u16 offset = dib0070_wbd_offset(fe);
1289	u8 band = BAND_OF_FREQUENCY(p->frequency/1000);
1290	switch (band) {
1291	case BAND_VHF:
1292		offset += 750;
1293		break;
1294	case BAND_UHF:  /* fall-thru wanted */
1295	default:
1296		offset += 250; break;
1297	}
1298	deb_info("WBD for DiB8000: %d\n", offset);
1299	state->dib8000_ops.set_wbd_ref(fe, offset);
1300
1301	return state->set_param_save(fe);
1302}
1303
1304static int dib807x_tuner_attach(struct dvb_usb_adapter *adap)
1305{
1306	struct dib0700_adapter_state *st = adap->priv;
1307	struct i2c_adapter *tun_i2c = st->dib8000_ops.get_i2c_master(adap->fe_adap[0].fe,
1308			DIBX000_I2C_INTERFACE_TUNER, 1);
1309
1310	if (adap->id == 0) {
1311		if (dvb_attach(dib0070_attach, adap->fe_adap[0].fe, tun_i2c,
1312				&dib807x_dib0070_config[0]) == NULL)
1313			return -ENODEV;
1314	} else {
1315		if (dvb_attach(dib0070_attach, adap->fe_adap[0].fe, tun_i2c,
1316				&dib807x_dib0070_config[1]) == NULL)
1317			return -ENODEV;
1318	}
1319
1320	st->set_param_save = adap->fe_adap[0].fe->ops.tuner_ops.set_params;
1321	adap->fe_adap[0].fe->ops.tuner_ops.set_params = dib807x_set_param_override;
1322	return 0;
1323}
1324
1325static int stk80xx_pid_filter(struct dvb_usb_adapter *adapter, int index,
1326	u16 pid, int onoff)
1327{
1328	struct dib0700_adapter_state *state = adapter->priv;
1329
1330	return state->dib8000_ops.pid_filter(adapter->fe_adap[0].fe, index, pid, onoff);
1331}
1332
1333static int stk80xx_pid_filter_ctrl(struct dvb_usb_adapter *adapter,
1334		int onoff)
1335{
1336	struct dib0700_adapter_state *state = adapter->priv;
1337
1338	return state->dib8000_ops.pid_filter_ctrl(adapter->fe_adap[0].fe, onoff);
1339}
1340
1341/* STK807x */
1342static int stk807x_frontend_attach(struct dvb_usb_adapter *adap)
1343{
1344	struct dib0700_adapter_state *state = adap->priv;
1345
1346	if (!dvb_attach(dib8000_attach, &state->dib8000_ops))
1347		return -ENODEV;
1348
1349	dib0700_set_gpio(adap->dev, GPIO6, GPIO_OUT, 1);
1350	msleep(10);
1351	dib0700_set_gpio(adap->dev, GPIO9, GPIO_OUT, 1);
1352	dib0700_set_gpio(adap->dev, GPIO4, GPIO_OUT, 1);
1353	dib0700_set_gpio(adap->dev, GPIO7, GPIO_OUT, 1);
1354
1355	dib0700_set_gpio(adap->dev, GPIO10, GPIO_OUT, 0);
1356
1357	dib0700_ctrl_clock(adap->dev, 72, 1);
1358
1359	msleep(10);
1360	dib0700_set_gpio(adap->dev, GPIO10, GPIO_OUT, 1);
1361	msleep(10);
1362	dib0700_set_gpio(adap->dev, GPIO0, GPIO_OUT, 1);
1363
1364	state->dib8000_ops.i2c_enumeration(&adap->dev->i2c_adap, 1, 18,
1365				0x80, 0);
1366
1367	adap->fe_adap[0].fe = state->dib8000_ops.init(&adap->dev->i2c_adap, 0x80,
1368			      &dib807x_dib8000_config[0]);
1369
1370	return adap->fe_adap[0].fe == NULL ?  -ENODEV : 0;
1371}
1372
1373/* STK807xPVR */
1374static int stk807xpvr_frontend_attach0(struct dvb_usb_adapter *adap)
1375{
1376	struct dib0700_adapter_state *state = adap->priv;
1377
1378	if (!dvb_attach(dib8000_attach, &state->dib8000_ops))
1379		return -ENODEV;
1380
1381	dib0700_set_gpio(adap->dev, GPIO6, GPIO_OUT, 0);
1382	msleep(30);
1383	dib0700_set_gpio(adap->dev, GPIO6, GPIO_OUT, 1);
1384	msleep(500);
1385	dib0700_set_gpio(adap->dev, GPIO9, GPIO_OUT, 1);
1386	dib0700_set_gpio(adap->dev, GPIO4, GPIO_OUT, 1);
1387	dib0700_set_gpio(adap->dev, GPIO7, GPIO_OUT, 1);
1388
1389	dib0700_set_gpio(adap->dev, GPIO10, GPIO_OUT, 0);
1390
1391	dib0700_ctrl_clock(adap->dev, 72, 1);
1392
1393	msleep(10);
1394	dib0700_set_gpio(adap->dev, GPIO10, GPIO_OUT, 1);
1395	msleep(10);
1396	dib0700_set_gpio(adap->dev, GPIO0, GPIO_OUT, 1);
1397
1398	/* initialize IC 0 */
1399	state->dib8000_ops.i2c_enumeration(&adap->dev->i2c_adap, 1, 0x22, 0x80, 0);
1400
1401	adap->fe_adap[0].fe = state->dib8000_ops.init(&adap->dev->i2c_adap, 0x80,
1402			      &dib807x_dib8000_config[0]);
1403
1404	return adap->fe_adap[0].fe == NULL ? -ENODEV : 0;
1405}
1406
1407static int stk807xpvr_frontend_attach1(struct dvb_usb_adapter *adap)
1408{
1409	struct dib0700_adapter_state *state = adap->priv;
1410
1411	if (!dvb_attach(dib8000_attach, &state->dib8000_ops))
1412		return -ENODEV;
1413
1414	/* initialize IC 1 */
1415	state->dib8000_ops.i2c_enumeration(&adap->dev->i2c_adap, 1, 0x12, 0x82, 0);
1416
1417	adap->fe_adap[0].fe = state->dib8000_ops.init(&adap->dev->i2c_adap, 0x82,
1418			      &dib807x_dib8000_config[1]);
1419
1420	return adap->fe_adap[0].fe == NULL ? -ENODEV : 0;
1421}
1422
1423/* STK8096GP */
1424static struct dibx000_agc_config dib8090_agc_config[2] = {
1425	{
1426	.band_caps = BAND_UHF | BAND_VHF | BAND_LBAND | BAND_SBAND,
1427	/* P_agc_use_sd_mod1=0, P_agc_use_sd_mod2=0, P_agc_freq_pwm_div=1,
1428	 * P_agc_inv_pwm1=0, P_agc_inv_pwm2=0, P_agc_inh_dc_rv_est=0,
1429	 * P_agc_time_est=3, P_agc_freeze=0, P_agc_nb_est=5, P_agc_write=0 */
1430	.setup = (0 << 15) | (0 << 14) | (5 << 11) | (0 << 10) | (0 << 9) | (0 << 8)
1431	| (3 << 5) | (0 << 4) | (5 << 1) | (0 << 0),
1432
1433	.inv_gain = 787,
1434	.time_stabiliz = 10,
1435
1436	.alpha_level = 0,
1437	.thlock = 118,
1438
1439	.wbd_inv = 0,
1440	.wbd_ref = 3530,
1441	.wbd_sel = 1,
1442	.wbd_alpha = 5,
1443
1444	.agc1_max = 65535,
1445	.agc1_min = 0,
1446
1447	.agc2_max = 65535,
1448	.agc2_min = 0,
1449
1450	.agc1_pt1 = 0,
1451	.agc1_pt2 = 32,
1452	.agc1_pt3 = 114,
1453	.agc1_slope1 = 143,
1454	.agc1_slope2 = 144,
1455	.agc2_pt1 = 114,
1456	.agc2_pt2 = 227,
1457	.agc2_slope1 = 116,
1458	.agc2_slope2 = 117,
1459
1460	.alpha_mant = 28,
1461	.alpha_exp = 26,
1462	.beta_mant = 31,
1463	.beta_exp = 51,
1464
1465	.perform_agc_softsplit = 0,
1466	},
1467	{
1468	.band_caps = BAND_CBAND,
1469	/* P_agc_use_sd_mod1=0, P_agc_use_sd_mod2=0, P_agc_freq_pwm_div=1,
1470	 * P_agc_inv_pwm1=0, P_agc_inv_pwm2=0, P_agc_inh_dc_rv_est=0,
1471	 * P_agc_time_est=3, P_agc_freeze=0, P_agc_nb_est=5, P_agc_write=0 */
1472	.setup = (0 << 15) | (0 << 14) | (5 << 11) | (0 << 10) | (0 << 9) | (0 << 8)
1473	| (3 << 5) | (0 << 4) | (5 << 1) | (0 << 0),
1474
1475	.inv_gain = 787,
1476	.time_stabiliz = 10,
1477
1478	.alpha_level = 0,
1479	.thlock = 118,
1480
1481	.wbd_inv = 0,
1482	.wbd_ref = 3530,
1483	.wbd_sel = 1,
1484	.wbd_alpha = 5,
1485
1486	.agc1_max = 0,
1487	.agc1_min = 0,
1488
1489	.agc2_max = 65535,
1490	.agc2_min = 0,
1491
1492	.agc1_pt1 = 0,
1493	.agc1_pt2 = 32,
1494	.agc1_pt3 = 114,
1495	.agc1_slope1 = 143,
1496	.agc1_slope2 = 144,
1497	.agc2_pt1 = 114,
1498	.agc2_pt2 = 227,
1499	.agc2_slope1 = 116,
1500	.agc2_slope2 = 117,
1501
1502	.alpha_mant = 28,
1503	.alpha_exp = 26,
1504	.beta_mant = 31,
1505	.beta_exp = 51,
1506
1507	.perform_agc_softsplit = 0,
1508	}
1509};
1510
1511static struct dibx000_bandwidth_config dib8090_pll_config_12mhz = {
1512	.internal = 54000,
1513	.sampling = 13500,
1514
1515	.pll_prediv = 1,
1516	.pll_ratio = 18,
1517	.pll_range = 3,
1518	.pll_reset = 1,
1519	.pll_bypass = 0,
1520
1521	.enable_refdiv = 0,
1522	.bypclk_div = 0,
1523	.IO_CLK_en_core = 1,
1524	.ADClkSrc = 1,
1525	.modulo = 2,
1526
1527	.sad_cfg = (3 << 14) | (1 << 12) | (599 << 0),
1528
1529	.ifreq = (0 << 25) | 0,
1530	.timf = 20199727,
1531
1532	.xtal_hz = 12000000,
1533};
1534
1535static int dib8090_get_adc_power(struct dvb_frontend *fe)
1536{
1537	struct dvb_usb_adapter *adap = fe->dvb->priv;
1538	struct dib0700_adapter_state *state = adap->priv;
1539
1540	return state->dib8000_ops.get_adc_power(fe, 1);
1541}
1542
1543static void dib8090_agc_control(struct dvb_frontend *fe, u8 restart)
1544{
1545	deb_info("AGC control callback: %i\n", restart);
1546	dib0090_dcc_freq(fe, restart);
1547
1548	if (restart == 0) /* before AGC startup */
1549		dib0090_set_dc_servo(fe, 1);
1550}
1551
1552static struct dib8000_config dib809x_dib8000_config[2] = {
1553	{
1554	.output_mpeg2_in_188_bytes = 1,
1555
1556	.agc_config_count = 2,
1557	.agc = dib8090_agc_config,
1558	.agc_control = dib8090_agc_control,
1559	.pll = &dib8090_pll_config_12mhz,
1560	.tuner_is_baseband = 1,
1561
1562	.gpio_dir = DIB8000_GPIO_DEFAULT_DIRECTIONS,
1563	.gpio_val = DIB8000_GPIO_DEFAULT_VALUES,
1564	.gpio_pwm_pos = DIB8000_GPIO_DEFAULT_PWM_POS,
1565
1566	.hostbus_diversity = 1,
1567	.div_cfg = 0x31,
1568	.output_mode = OUTMODE_MPEG2_FIFO,
1569	.drives = 0x2d98,
1570	.diversity_delay = 48,
1571	.refclksel = 3,
1572	}, {
1573	.output_mpeg2_in_188_bytes = 1,
1574
1575	.agc_config_count = 2,
1576	.agc = dib8090_agc_config,
1577	.agc_control = dib8090_agc_control,
1578	.pll = &dib8090_pll_config_12mhz,
1579	.tuner_is_baseband = 1,
1580
1581	.gpio_dir = DIB8000_GPIO_DEFAULT_DIRECTIONS,
1582	.gpio_val = DIB8000_GPIO_DEFAULT_VALUES,
1583	.gpio_pwm_pos = DIB8000_GPIO_DEFAULT_PWM_POS,
1584
1585	.hostbus_diversity = 1,
1586	.div_cfg = 0x31,
1587	.output_mode = OUTMODE_DIVERSITY,
1588	.drives = 0x2d08,
1589	.diversity_delay = 1,
1590	.refclksel = 3,
1591	}
1592};
1593
1594static struct dib0090_wbd_slope dib8090_wbd_table[] = {
1595	/* max freq ; cold slope ; cold offset ; warm slope ; warm offset ; wbd gain */
1596	{ 120,     0, 500,  0,   500, 4 }, /* CBAND */
1597	{ 170,     0, 450,  0,   450, 4 }, /* CBAND */
1598	{ 380,    48, 373, 28,   259, 6 }, /* VHF */
1599	{ 860,    34, 700, 36,   616, 6 }, /* high UHF */
1600	{ 0xFFFF, 34, 700, 36,   616, 6 }, /* default */
1601};
1602
1603static struct dib0090_config dib809x_dib0090_config = {
1604	.io.pll_bypass = 1,
1605	.io.pll_range = 1,
1606	.io.pll_prediv = 1,
1607	.io.pll_loopdiv = 20,
1608	.io.adc_clock_ratio = 8,
1609	.io.pll_int_loop_filt = 0,
1610	.io.clock_khz = 12000,
1611	.reset = dib80xx_tuner_reset,
1612	.sleep = dib80xx_tuner_sleep,
1613	.clkouttobamse = 1,
1614	.analog_output = 1,
1615	.i2c_address = DEFAULT_DIB0090_I2C_ADDRESS,
1616	.use_pwm_agc = 1,
1617	.clkoutdrive = 1,
1618	.get_adc_power = dib8090_get_adc_power,
1619	.freq_offset_khz_uhf = -63,
1620	.freq_offset_khz_vhf = -143,
1621	.wbd = dib8090_wbd_table,
1622	.fref_clock_ratio = 6,
1623};
1624
1625static u8 dib8090_compute_pll_parameters(struct dvb_frontend *fe)
1626{
1627	u8 optimal_pll_ratio = 20;
1628	u32 freq_adc, ratio, rest, max = 0;
1629	u8 pll_ratio;
1630
1631	for (pll_ratio = 17; pll_ratio <= 20; pll_ratio++) {
1632		freq_adc = 12 * pll_ratio * (1 << 8) / 16;
1633		ratio = ((fe->dtv_property_cache.frequency / 1000) * (1 << 8) / 1000) / freq_adc;
1634		rest = ((fe->dtv_property_cache.frequency / 1000) * (1 << 8) / 1000) - ratio * freq_adc;
1635
1636		if (rest > freq_adc / 2)
1637			rest = freq_adc - rest;
1638		deb_info("PLL ratio=%i rest=%i\n", pll_ratio, rest);
1639		if ((rest > max) && (rest > 717)) {
1640			optimal_pll_ratio = pll_ratio;
1641			max = rest;
1642		}
1643	}
1644	deb_info("optimal PLL ratio=%i\n", optimal_pll_ratio);
1645
1646	return optimal_pll_ratio;
1647}
1648
1649static int dib8096_set_param_override(struct dvb_frontend *fe)
1650{
1651	struct dvb_usb_adapter *adap = fe->dvb->priv;
1652	struct dib0700_adapter_state *state = adap->priv;
1653	u8 pll_ratio, band = BAND_OF_FREQUENCY(fe->dtv_property_cache.frequency / 1000);
1654	u16 target, ltgain, rf_gain_limit;
1655	u32 timf;
1656	int ret = 0;
1657	enum frontend_tune_state tune_state = CT_SHUTDOWN;
1658
1659	switch (band) {
1660	default:
1661			deb_info("Warning : Rf frequency  (%iHz) is not in the supported range, using VHF switch ", fe->dtv_property_cache.frequency);
1662	case BAND_VHF:
1663			state->dib8000_ops.set_gpio(fe, 3, 0, 1);
1664			break;
1665	case BAND_UHF:
1666			state->dib8000_ops.set_gpio(fe, 3, 0, 0);
1667			break;
1668	}
1669
1670	ret = state->set_param_save(fe);
1671	if (ret < 0)
1672		return ret;
1673
1674	if (fe->dtv_property_cache.bandwidth_hz != 6000000) {
1675		deb_info("only 6MHz bandwidth is supported\n");
1676		return -EINVAL;
1677	}
1678
1679	/** Update PLL if needed ratio **/
1680	state->dib8000_ops.update_pll(fe, &dib8090_pll_config_12mhz, fe->dtv_property_cache.bandwidth_hz / 1000, 0);
1681
1682	/** Get optimize PLL ratio to remove spurious **/
1683	pll_ratio = dib8090_compute_pll_parameters(fe);
1684	if (pll_ratio == 17)
1685		timf = 21387946;
1686	else if (pll_ratio == 18)
1687		timf = 20199727;
1688	else if (pll_ratio == 19)
1689		timf = 19136583;
1690	else
1691		timf = 18179756;
1692
1693	/** Update ratio **/
1694	state->dib8000_ops.update_pll(fe, &dib8090_pll_config_12mhz, fe->dtv_property_cache.bandwidth_hz / 1000, pll_ratio);
1695
1696	state->dib8000_ops.ctrl_timf(fe, DEMOD_TIMF_SET, timf);
1697
1698	if (band != BAND_CBAND) {
1699		/* dib0090_get_wbd_target is returning any possible temperature compensated wbd-target */
1700		target = (dib0090_get_wbd_target(fe) * 8 * 18 / 33 + 1) / 2;
1701		state->dib8000_ops.set_wbd_ref(fe, target);
1702	}
1703
1704	if (band == BAND_CBAND) {
1705		deb_info("tuning in CBAND - soft-AGC startup\n");
1706		dib0090_set_tune_state(fe, CT_AGC_START);
1707
1708		do {
1709			ret = dib0090_gain_control(fe);
1710			msleep(ret);
1711			tune_state = dib0090_get_tune_state(fe);
1712			if (tune_state == CT_AGC_STEP_0)
1713				state->dib8000_ops.set_gpio(fe, 6, 0, 1);
1714			else if (tune_state == CT_AGC_STEP_1) {
1715				dib0090_get_current_gain(fe, NULL, NULL, &rf_gain_limit, &ltgain);
1716				if (rf_gain_limit < 2000) /* activate the external attenuator in case of very high input power */
1717					state->dib8000_ops.set_gpio(fe, 6, 0, 0);
1718			}
1719		} while (tune_state < CT_AGC_STOP);
1720
1721		deb_info("switching to PWM AGC\n");
1722		dib0090_pwm_gain_reset(fe);
1723		state->dib8000_ops.pwm_agc_reset(fe);
1724		state->dib8000_ops.set_tune_state(fe, CT_DEMOD_START);
1725	} else {
1726		/* for everything else than CBAND we are using standard AGC */
1727		deb_info("not tuning in CBAND - standard AGC startup\n");
1728		dib0090_pwm_gain_reset(fe);
1729	}
1730
1731	return 0;
1732}
1733
1734static int dib809x_tuner_attach(struct dvb_usb_adapter *adap)
1735{
1736	struct dib0700_adapter_state *st = adap->priv;
1737	struct i2c_adapter *tun_i2c = st->dib8000_ops.get_i2c_master(adap->fe_adap[0].fe, DIBX000_I2C_INTERFACE_TUNER, 1);
1738
1739	if (dvb_attach(dib0090_register, adap->fe_adap[0].fe, tun_i2c, &dib809x_dib0090_config) == NULL)
1740		return -ENODEV;
1741
1742	st->set_param_save = adap->fe_adap[0].fe->ops.tuner_ops.set_params;
1743	adap->fe_adap[0].fe->ops.tuner_ops.set_params = dib8096_set_param_override;
1744	return 0;
1745}
1746
1747static int stk809x_frontend_attach(struct dvb_usb_adapter *adap)
1748{
1749	struct dib0700_adapter_state *state = adap->priv;
1750
1751	if (!dvb_attach(dib8000_attach, &state->dib8000_ops))
1752		return -ENODEV;
1753
1754	dib0700_set_gpio(adap->dev, GPIO6, GPIO_OUT, 1);
1755	msleep(10);
1756	dib0700_set_gpio(adap->dev, GPIO9, GPIO_OUT, 1);
1757	dib0700_set_gpio(adap->dev, GPIO4, GPIO_OUT, 1);
1758	dib0700_set_gpio(adap->dev, GPIO7, GPIO_OUT, 1);
1759
1760	dib0700_set_gpio(adap->dev, GPIO10, GPIO_OUT, 0);
1761
1762	dib0700_ctrl_clock(adap->dev, 72, 1);
1763
1764	msleep(10);
1765	dib0700_set_gpio(adap->dev, GPIO10, GPIO_OUT, 1);
1766	msleep(10);
1767	dib0700_set_gpio(adap->dev, GPIO0, GPIO_OUT, 1);
1768
1769	state->dib8000_ops.i2c_enumeration(&adap->dev->i2c_adap, 1, 18, 0x80, 0);
1770
1771	adap->fe_adap[0].fe = state->dib8000_ops.init(&adap->dev->i2c_adap, 0x80, &dib809x_dib8000_config[0]);
1772
1773	return adap->fe_adap[0].fe == NULL ?  -ENODEV : 0;
1774}
1775
1776static int nim8096md_tuner_attach(struct dvb_usb_adapter *adap)
1777{
1778	struct dib0700_adapter_state *st = adap->priv;
1779	struct i2c_adapter *tun_i2c;
1780	struct dvb_frontend *fe_slave  = st->dib8000_ops.get_slave_frontend(adap->fe_adap[0].fe, 1);
1781
1782	if (fe_slave) {
1783		tun_i2c = st->dib8000_ops.get_i2c_master(fe_slave, DIBX000_I2C_INTERFACE_TUNER, 1);
1784		if (dvb_attach(dib0090_register, fe_slave, tun_i2c, &dib809x_dib0090_config) == NULL)
1785			return -ENODEV;
1786		fe_slave->dvb = adap->fe_adap[0].fe->dvb;
1787		fe_slave->ops.tuner_ops.set_params = dib8096_set_param_override;
1788	}
1789	tun_i2c = st->dib8000_ops.get_i2c_master(adap->fe_adap[0].fe, DIBX000_I2C_INTERFACE_TUNER, 1);
1790	if (dvb_attach(dib0090_register, adap->fe_adap[0].fe, tun_i2c, &dib809x_dib0090_config) == NULL)
1791		return -ENODEV;
1792
1793	st->set_param_save = adap->fe_adap[0].fe->ops.tuner_ops.set_params;
1794	adap->fe_adap[0].fe->ops.tuner_ops.set_params = dib8096_set_param_override;
1795
1796	return 0;
1797}
1798
1799static int nim8096md_frontend_attach(struct dvb_usb_adapter *adap)
1800{
1801	struct dvb_frontend *fe_slave;
1802	struct dib0700_adapter_state *state = adap->priv;
1803
1804	if (!dvb_attach(dib8000_attach, &state->dib8000_ops))
1805		return -ENODEV;
1806
1807	dib0700_set_gpio(adap->dev, GPIO6, GPIO_OUT, 0);
1808	msleep(20);
1809	dib0700_set_gpio(adap->dev, GPIO6, GPIO_OUT, 1);
1810	msleep(1000);
1811	dib0700_set_gpio(adap->dev, GPIO9, GPIO_OUT, 1);
1812	dib0700_set_gpio(adap->dev, GPIO4, GPIO_OUT, 1);
1813	dib0700_set_gpio(adap->dev, GPIO7, GPIO_OUT, 1);
1814
1815	dib0700_set_gpio(adap->dev, GPIO10, GPIO_OUT, 0);
1816
1817	dib0700_ctrl_clock(adap->dev, 72, 1);
1818
1819	msleep(20);
1820	dib0700_set_gpio(adap->dev, GPIO10, GPIO_OUT, 1);
1821	msleep(20);
1822	dib0700_set_gpio(adap->dev, GPIO0, GPIO_OUT, 1);
1823
1824	state->dib8000_ops.i2c_enumeration(&adap->dev->i2c_adap, 2, 18, 0x80, 0);
1825
1826	adap->fe_adap[0].fe = state->dib8000_ops.init(&adap->dev->i2c_adap, 0x80, &dib809x_dib8000_config[0]);
1827	if (adap->fe_adap[0].fe == NULL)
1828		return -ENODEV;
1829
1830	/* Needed to increment refcount */
1831	if (!dvb_attach(dib8000_attach, &state->dib8000_ops))
1832		return -ENODEV;
1833
1834	fe_slave = state->dib8000_ops.init(&adap->dev->i2c_adap, 0x82, &dib809x_dib8000_config[1]);
1835	state->dib8000_ops.set_slave_frontend(adap->fe_adap[0].fe, fe_slave);
1836
1837	return fe_slave == NULL ?  -ENODEV : 0;
1838}
1839
1840/* TFE8096P */
1841static struct dibx000_agc_config dib8096p_agc_config[2] = {
1842	{
1843		.band_caps		= BAND_UHF,
1844		/* P_agc_use_sd_mod1=0, P_agc_use_sd_mod2=0,
1845		   P_agc_freq_pwm_div=1, P_agc_inv_pwm1=0,
1846		   P_agc_inv_pwm2=0, P_agc_inh_dc_rv_est=0,
1847		   P_agc_time_est=3, P_agc_freeze=0, P_agc_nb_est=5,
1848		   P_agc_write=0 */
1849		.setup			= (0 << 15) | (0 << 14) | (5 << 11)
1850			| (0 << 10) | (0 << 9) | (0 << 8) | (3 << 5)
1851			| (0 << 4) | (5 << 1) | (0 << 0),
1852
1853		.inv_gain		= 684,
1854		.time_stabiliz	= 10,
1855
1856		.alpha_level	= 0,
1857		.thlock			= 118,
1858
1859		.wbd_inv		= 0,
1860		.wbd_ref		= 1200,
1861		.wbd_sel		= 3,
1862		.wbd_alpha		= 5,
1863
1864		.agc1_max		= 65535,
1865		.agc1_min		= 0,
1866
1867		.agc2_max		= 32767,
1868		.agc2_min		= 0,
1869
1870		.agc1_pt1		= 0,
1871		.agc1_pt2		= 0,
1872		.agc1_pt3		= 105,
1873		.agc1_slope1	= 0,
1874		.agc1_slope2	= 156,
1875		.agc2_pt1		= 105,
1876		.agc2_pt2		= 255,
1877		.agc2_slope1	= 54,
1878		.agc2_slope2	= 0,
1879
1880		.alpha_mant		= 28,
1881		.alpha_exp		= 26,
1882		.beta_mant		= 31,
1883		.beta_exp		= 51,
1884
1885		.perform_agc_softsplit = 0,
1886	} , {
1887		.band_caps		= BAND_FM | BAND_VHF | BAND_CBAND,
1888		/* P_agc_use_sd_mod1=0, P_agc_use_sd_mod2=0,
1889		   P_agc_freq_pwm_div=1, P_agc_inv_pwm1=0,
1890		   P_agc_inv_pwm2=0, P_agc_inh_dc_rv_est=0,
1891		   P_agc_time_est=3, P_agc_freeze=0, P_agc_nb_est=5,
1892		   P_agc_write=0 */
1893		.setup			= (0 << 15) | (0 << 14) | (5 << 11)
1894			| (0 << 10) | (0 << 9) | (0 << 8) | (3 << 5)
1895			| (0 << 4) | (5 << 1) | (0 << 0),
1896
1897		.inv_gain		= 732,
1898		.time_stabiliz  = 10,
1899
1900		.alpha_level	= 0,
1901		.thlock			= 118,
1902
1903		.wbd_inv		= 0,
1904		.wbd_ref		= 1200,
1905		.wbd_sel		= 3,
1906		.wbd_alpha		= 5,
1907
1908		.agc1_max		= 65535,
1909		.agc1_min		= 0,
1910
1911		.agc2_max		= 32767,
1912		.agc2_min		= 0,
1913
1914		.agc1_pt1		= 0,
1915		.agc1_pt2		= 0,
1916		.agc1_pt3		= 98,
1917		.agc1_slope1	= 0,
1918		.agc1_slope2	= 167,
1919		.agc2_pt1		= 98,
1920		.agc2_pt2		= 255,
1921		.agc2_slope1	= 52,
1922		.agc2_slope2	= 0,
1923
1924		.alpha_mant		= 28,
1925		.alpha_exp		= 26,
1926		.beta_mant		= 31,
1927		.beta_exp		= 51,
1928
1929		.perform_agc_softsplit = 0,
1930	}
1931};
1932
1933static struct dibx000_bandwidth_config dib8096p_clock_config_12_mhz = {
1934	.internal = 108000,
1935	.sampling = 13500,
1936	.pll_prediv = 1,
1937	.pll_ratio = 9,
1938	.pll_range = 1,
1939	.pll_reset = 0,
1940	.pll_bypass = 0,
1941	.enable_refdiv = 0,
1942	.bypclk_div = 0,
1943	.IO_CLK_en_core = 0,
1944	.ADClkSrc = 0,
1945	.modulo = 2,
1946	.sad_cfg = (3 << 14) | (1 << 12) | (524 << 0),
1947	.ifreq = (0 << 25) | 0,
1948	.timf = 20199729,
1949	.xtal_hz = 12000000,
1950};
1951
1952static struct dib8000_config tfe8096p_dib8000_config = {
1953	.output_mpeg2_in_188_bytes	= 1,
1954	.hostbus_diversity			= 1,
1955	.update_lna					= NULL,
1956
1957	.agc_config_count			= 2,
1958	.agc						= dib8096p_agc_config,
1959	.pll						= &dib8096p_clock_config_12_mhz,
1960
1961	.gpio_dir					= DIB8000_GPIO_DEFAULT_DIRECTIONS,
1962	.gpio_val					= DIB8000_GPIO_DEFAULT_VALUES,
1963	.gpio_pwm_pos				= DIB8000_GPIO_DEFAULT_PWM_POS,
1964
1965	.agc_control				= NULL,
1966	.diversity_delay			= 48,
1967	.output_mode				= OUTMODE_MPEG2_FIFO,
1968	.enMpegOutput				= 1,
1969};
1970
1971static struct dib0090_wbd_slope dib8096p_wbd_table[] = {
1972	{ 380, 81, 850, 64, 540, 4},
1973	{ 860, 51, 866, 21, 375, 4},
1974	{1700, 0, 250, 0, 100, 6},
1975	{2600, 0, 250, 0, 100, 6},
1976	{ 0xFFFF, 0, 0, 0, 0, 0},
1977};
1978
1979static struct dib0090_config tfe8096p_dib0090_config = {
1980	.io.clock_khz			= 12000,
1981	.io.pll_bypass			= 0,
1982	.io.pll_range			= 0,
1983	.io.pll_prediv			= 3,
1984	.io.pll_loopdiv			= 6,
1985	.io.adc_clock_ratio		= 0,
1986	.io.pll_int_loop_filt	= 0,
1987
1988	.freq_offset_khz_uhf	= -143,
1989	.freq_offset_khz_vhf	= -143,
1990
1991	.get_adc_power			= dib8090_get_adc_power,
1992
1993	.clkouttobamse			= 1,
1994	.analog_output			= 0,
1995
1996	.wbd_vhf_offset			= 0,
1997	.wbd_cband_offset		= 0,
1998	.use_pwm_agc			= 1,
1999	.clkoutdrive			= 0,
2000
2001	.fref_clock_ratio		= 1,
2002
2003	.ls_cfg_pad_drv			= 0,
2004	.data_tx_drv			= 0,
2005	.low_if					= NULL,
2006	.in_soc					= 1,
2007	.force_cband_input		= 0,
2008};
2009
2010struct dibx090p_adc {
2011	u32 freq;			/* RF freq MHz */
2012	u32 timf;			/* New Timf */
2013	u32 pll_loopdiv;	/* New prediv */
2014	u32 pll_prediv;		/* New loopdiv */
2015};
2016
2017struct dibx090p_best_adc {
2018	u32 timf;
2019	u32 pll_loopdiv;
2020	u32 pll_prediv;
2021};
2022
2023static int dib8096p_get_best_sampling(struct dvb_frontend *fe, struct dibx090p_best_adc *adc)
2024{
2025	u8 spur = 0, prediv = 0, loopdiv = 0, min_prediv = 1, max_prediv = 1;
2026	u16 xtal = 12000;
2027	u16 fcp_min = 1900;  /* PLL, Minimum Frequency of phase comparator (KHz) */
2028	u16 fcp_max = 20000; /* PLL, Maximum Frequency of phase comparator (KHz) */
2029	u32 fmem_max = 140000; /* 140MHz max SDRAM freq */
2030	u32 fdem_min = 66000;
2031	u32 fcp = 0, fs = 0, fdem = 0, fmem = 0;
2032	u32 harmonic_id = 0;
2033
2034	adc->timf = 0;
2035	adc->pll_loopdiv = loopdiv;
2036	adc->pll_prediv = prediv;
2037
2038	deb_info("bandwidth = %d", fe->dtv_property_cache.bandwidth_hz);
2039
2040	/* Find Min and Max prediv */
2041	while ((xtal / max_prediv) >= fcp_min)
2042		max_prediv++;
2043
2044	max_prediv--;
2045	min_prediv = max_prediv;
2046	while ((xtal / min_prediv) <= fcp_max) {
2047		min_prediv--;
2048		if (min_prediv == 1)
2049			break;
2050	}
2051	deb_info("MIN prediv = %d : MAX prediv = %d", min_prediv, max_prediv);
2052
2053	min_prediv = 1;
2054
2055	for (prediv = min_prediv; prediv < max_prediv; prediv++) {
2056		fcp = xtal / prediv;
2057		if (fcp > fcp_min && fcp < fcp_max) {
2058			for (loopdiv = 1; loopdiv < 64; loopdiv++) {
2059				fmem = ((xtal/prediv) * loopdiv);
2060				fdem = fmem / 2;
2061				fs   = fdem / 4;
2062
2063				/* test min/max system restrictions */
2064				if ((fdem >= fdem_min) && (fmem <= fmem_max) && (fs >= fe->dtv_property_cache.bandwidth_hz / 1000)) {
2065					spur = 0;
2066					/* test fs harmonics positions */
2067					for (harmonic_id = (fe->dtv_property_cache.frequency / (1000 * fs));  harmonic_id <= ((fe->dtv_property_cache.frequency / (1000 * fs)) + 1); harmonic_id++) {
2068						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)))) {
2069							spur = 1;
2070							break;
2071						}
2072					}
2073
2074					if (!spur) {
2075						adc->pll_loopdiv = loopdiv;
2076						adc->pll_prediv = prediv;
2077						adc->timf = (4260880253U / fdem) * (1 << 8);
2078						adc->timf += ((4260880253U % fdem) << 8) / fdem;
2079
2080						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);
2081						break;
2082					}
2083				}
2084			}
2085		}
2086		if (!spur)
2087			break;
2088	}
2089
2090	if (adc->pll_loopdiv == 0 && adc->pll_prediv == 0)
2091		return -EINVAL;
2092	return 0;
2093}
2094
2095static int dib8096p_agc_startup(struct dvb_frontend *fe)
2096{
2097	struct dvb_usb_adapter *adap = fe->dvb->priv;
2098	struct dib0700_adapter_state *state = adap->priv;
2099	struct dibx000_bandwidth_config pll;
2100	struct dibx090p_best_adc adc;
2101	u16 target;
2102	int ret;
2103
2104	ret = state->set_param_save(fe);
2105	if (ret < 0)
2106		return ret;
2107	memset(&pll, 0, sizeof(struct dibx000_bandwidth_config));
2108
2109	dib0090_pwm_gain_reset(fe);
2110	/* dib0090_get_wbd_target is returning any possible
2111	   temperature compensated wbd-target */
2112	target = (dib0090_get_wbd_target(fe) * 8  + 1) / 2;
2113	state->dib8000_ops.set_wbd_ref(fe, target);
2114
2115	if (dib8096p_get_best_sampling(fe, &adc) == 0) {
2116		pll.pll_ratio  = adc.pll_loopdiv;
2117		pll.pll_prediv = adc.pll_prediv;
2118
2119		dib0700_set_i2c_speed(adap->dev, 200);
2120		state->dib8000_ops.update_pll(fe, &pll, fe->dtv_property_cache.bandwidth_hz / 1000, 0);
2121		state->dib8000_ops.ctrl_timf(fe, DEMOD_TIMF_SET, adc.timf);
2122		dib0700_set_i2c_speed(adap->dev, 1000);
2123	}
2124	return 0;
2125}
2126
2127static int tfe8096p_frontend_attach(struct dvb_usb_adapter *adap)
2128{
2129	struct dib0700_state *st = adap->dev->priv;
2130	u32 fw_version;
2131	struct dib0700_adapter_state *state = adap->priv;
2132
2133	if (!dvb_attach(dib8000_attach, &state->dib8000_ops))
2134		return -ENODEV;
2135
2136	dib0700_get_version(adap->dev, NULL, NULL, &fw_version, NULL);
2137	if (fw_version >= 0x10200)
2138		st->fw_use_new_i2c_api = 1;
2139
2140	dib0700_set_gpio(adap->dev, GPIO6, GPIO_OUT, 1);
2141	msleep(20);
2142	dib0700_set_gpio(adap->dev, GPIO9, GPIO_OUT, 1);
2143	dib0700_set_gpio(adap->dev, GPIO4, GPIO_OUT, 1);
2144	dib0700_set_gpio(adap->dev, GPIO7, GPIO_OUT, 1);
2145
2146	dib0700_set_gpio(adap->dev, GPIO10, GPIO_OUT, 0);
2147
2148	dib0700_ctrl_clock(adap->dev, 72, 1);
2149
2150	msleep(20);
2151	dib0700_set_gpio(adap->dev, GPIO10, GPIO_OUT, 1);
2152	msleep(20);
2153	dib0700_set_gpio(adap->dev, GPIO0, GPIO_OUT, 1);
2154
2155	state->dib8000_ops.i2c_enumeration(&adap->dev->i2c_adap, 1, 0x10, 0x80, 1);
2156
2157	adap->fe_adap[0].fe = state->dib8000_ops.init(&adap->dev->i2c_adap,
2158					     0x80, &tfe8096p_dib8000_config);
2159
2160	return adap->fe_adap[0].fe == NULL ?  -ENODEV : 0;
2161}
2162
2163static int tfe8096p_tuner_attach(struct dvb_usb_adapter *adap)
2164{
2165	struct dib0700_adapter_state *st = adap->priv;
2166	struct i2c_adapter *tun_i2c = st->dib8000_ops.get_i2c_tuner(adap->fe_adap[0].fe);
2167
2168	tfe8096p_dib0090_config.reset = st->dib8000_ops.tuner_sleep;
2169	tfe8096p_dib0090_config.sleep = st->dib8000_ops.tuner_sleep;
2170	tfe8096p_dib0090_config.wbd = dib8096p_wbd_table;
2171
2172	if (dvb_attach(dib0090_register, adap->fe_adap[0].fe, tun_i2c,
2173				&tfe8096p_dib0090_config) == NULL)
2174		return -ENODEV;
2175
2176	st->dib8000_ops.set_gpio(adap->fe_adap[0].fe, 8, 0, 1);
2177
2178	st->set_param_save = adap->fe_adap[0].fe->ops.tuner_ops.set_params;
2179	adap->fe_adap[0].fe->ops.tuner_ops.set_params = dib8096p_agc_startup;
2180	return 0;
2181}
2182
2183/* STK9090M */
2184static int dib90x0_pid_filter(struct dvb_usb_adapter *adapter, int index, u16 pid, int onoff)
2185{
2186	return dib9000_fw_pid_filter(adapter->fe_adap[0].fe, index, pid, onoff);
2187}
2188
2189static int dib90x0_pid_filter_ctrl(struct dvb_usb_adapter *adapter, int onoff)
2190{
2191	return dib9000_fw_pid_filter_ctrl(adapter->fe_adap[0].fe, onoff);
2192}
2193
2194static int dib90x0_tuner_reset(struct dvb_frontend *fe, int onoff)
2195{
2196	return dib9000_set_gpio(fe, 5, 0, !onoff);
2197}
2198
2199static int dib90x0_tuner_sleep(struct dvb_frontend *fe, int onoff)
2200{
2201	return dib9000_set_gpio(fe, 0, 0, onoff);
2202}
2203
2204static int dib01x0_pmu_update(struct i2c_adapter *i2c, u16 *data, u8 len)
2205{
2206	u8 wb[4] = { 0xc >> 8, 0xc & 0xff, 0, 0 };
2207	u8 rb[2];
2208	struct i2c_msg msg[2] = {
2209		{.addr = 0x1e >> 1, .flags = 0, .buf = wb, .len = 2},
2210		{.addr = 0x1e >> 1, .flags = I2C_M_RD, .buf = rb, .len = 2},
2211	};
2212	u8 index_data;
2213
2214	dibx000_i2c_set_speed(i2c, 250);
2215
2216	if (i2c_transfer(i2c, msg, 2) != 2)
2217		return -EIO;
2218
2219	switch (rb[0] << 8 | rb[1]) {
2220	case 0:
2221			deb_info("Found DiB0170 rev1: This version of DiB0170 is not supported any longer.\n");
2222			return -EIO;
2223	case 1:
2224			deb_info("Found DiB0170 rev2");
2225			break;
2226	case 2:
2227			deb_info("Found DiB0190 rev2");
2228			break;
2229	default:
2230			deb_info("DiB01x0 not found");
2231			return -EIO;
2232	}
2233
2234	for (index_data = 0; index_data < len; index_data += 2) {
2235		wb[2] = (data[index_data + 1] >> 8) & 0xff;
2236		wb[3] = (data[index_data + 1]) & 0xff;
2237
2238		if (data[index_data] == 0) {
2239			wb[0] = (data[index_data] >> 8) & 0xff;
2240			wb[1] = (data[index_data]) & 0xff;
2241			msg[0].len = 2;
2242			if (i2c_transfer(i2c, msg, 2) != 2)
2243				return -EIO;
2244			wb[2] |= rb[0];
2245			wb[3] |= rb[1] & ~(3 << 4);
2246		}
2247
2248		wb[0] = (data[index_data] >> 8)&0xff;
2249		wb[1] = (data[index_data])&0xff;
2250		msg[0].len = 4;
2251		if (i2c_transfer(i2c, &msg[0], 1) != 1)
2252			return -EIO;
2253	}
2254	return 0;
2255}
2256
2257static struct dib9000_config stk9090m_config = {
2258	.output_mpeg2_in_188_bytes = 1,
2259	.output_mode = OUTMODE_MPEG2_FIFO,
2260	.vcxo_timer = 279620,
2261	.timing_frequency = 20452225,
2262	.demod_clock_khz = 60000,
2263	.xtal_clock_khz = 30000,
2264	.if_drives = (0 << 15) | (1 << 13) | (0 << 12) | (3 << 10) | (0 << 9) | (1 << 7) | (0 << 6) | (0 << 4) | (1 << 3) | (1 << 1) | (0),
2265	.subband = {
2266		2,
2267		{
2268			{ 240, { BOARD_GPIO_COMPONENT_DEMOD, BOARD_GPIO_FUNCTION_SUBBAND_GPIO, 0x0008, 0x0000, 0x0008 } }, /* GPIO 3 to 1 for VHF */
2269			{ 890, { BOARD_GPIO_COMPONENT_DEMOD, BOARD_GPIO_FUNCTION_SUBBAND_GPIO, 0x0008, 0x0000, 0x0000 } }, /* GPIO 3 to 0 for UHF */
2270			{ 0 },
2271		},
2272	},
2273	.gpio_function = {
2274		{ .component = BOARD_GPIO_COMPONENT_DEMOD, .function = BOARD_GPIO_FUNCTION_COMPONENT_ON, .mask = 0x10 | 0x21, .direction = 0 & ~0x21, .value = (0x10 & ~0x1) | 0x20 },
2275		{ .component = BOARD_GPIO_COMPONENT_DEMOD, .function = BOARD_GPIO_FUNCTION_COMPONENT_OFF, .mask = 0x10 | 0x21, .direction = 0 & ~0x21, .value = 0 | 0x21 },
2276	},
2277};
2278
2279static struct dib9000_config nim9090md_config[2] = {
2280	{
2281		.output_mpeg2_in_188_bytes = 1,
2282		.output_mode = OUTMODE_MPEG2_FIFO,
2283		.vcxo_timer = 279620,
2284		.timing_frequency = 20452225,
2285		.demod_clock_khz = 60000,
2286		.xtal_clock_khz = 30000,
2287		.if_drives = (0 << 15) | (1 << 13) | (0 << 12) | (3 << 10) | (0 << 9) | (1 << 7) | (0 << 6) | (0 << 4) | (1 << 3) | (1 << 1) | (0),
2288	}, {
2289		.output_mpeg2_in_188_bytes = 1,
2290		.output_mode = OUTMODE_DIVERSITY,
2291		.vcxo_timer = 279620,
2292		.timing_frequency = 20452225,
2293		.demod_clock_khz = 60000,
2294		.xtal_clock_khz = 30000,
2295		.if_drives = (0 << 15) | (1 << 13) | (0 << 12) | (3 << 10) | (0 << 9) | (1 << 7) | (0 << 6) | (0 << 4) | (1 << 3) | (1 << 1) | (0),
2296		.subband = {
2297			2,
2298			{
2299				{ 240, { BOARD_GPIO_COMPONENT_DEMOD, BOARD_GPIO_FUNCTION_SUBBAND_GPIO, 0x0006, 0x0000, 0x0006 } }, /* GPIO 1 and 2 to 1 for VHF */
2300				{ 890, { BOARD_GPIO_COMPONENT_DEMOD, BOARD_GPIO_FUNCTION_SUBBAND_GPIO, 0x0006, 0x0000, 0x0000 } }, /* GPIO 1 and 2 to 0 for UHF */
2301				{ 0 },
2302			},
2303		},
2304		.gpio_function = {
2305			{ .component = BOARD_GPIO_COMPONENT_DEMOD, .function = BOARD_GPIO_FUNCTION_COMPONENT_ON, .mask = 0x10 | 0x21, .direction = 0 & ~0x21, .value = (0x10 & ~0x1) | 0x20 },
2306			{ .component = BOARD_GPIO_COMPONENT_DEMOD, .function = BOARD_GPIO_FUNCTION_COMPONENT_OFF, .mask = 0x10 | 0x21, .direction = 0 & ~0x21, .value = 0 | 0x21 },
2307		},
2308	}
2309};
2310
2311static struct dib0090_config dib9090_dib0090_config = {
2312	.io.pll_bypass = 0,
2313	.io.pll_range = 1,
2314	.io.pll_prediv = 1,
2315	.io.pll_loopdiv = 8,
2316	.io.adc_clock_ratio = 8,
2317	.io.pll_int_loop_filt = 0,
2318	.io.clock_khz = 30000,
2319	.reset = dib90x0_tuner_reset,
2320	.sleep = dib90x0_tuner_sleep,
2321	.clkouttobamse = 0,
2322	.analog_output = 0,
2323	.use_pwm_agc = 0,
2324	.clkoutdrive = 0,
2325	.freq_offset_khz_uhf = 0,
2326	.freq_offset_khz_vhf = 0,
2327};
2328
2329static struct dib0090_config nim9090md_dib0090_config[2] = {
2330	{
2331		.io.pll_bypass = 0,
2332		.io.pll_range = 1,
2333		.io.pll_prediv = 1,
2334		.io.pll_loopdiv = 8,
2335		.io.adc_clock_ratio = 8,
2336		.io.pll_int_loop_filt = 0,
2337		.io.clock_khz = 30000,
2338		.reset = dib90x0_tuner_reset,
2339		.sleep = dib90x0_tuner_sleep,
2340		.clkouttobamse = 1,
2341		.analog_output = 0,
2342		.use_pwm_agc = 0,
2343		.clkoutdrive = 0,
2344		.freq_offset_khz_uhf = 0,
2345		.freq_offset_khz_vhf = 0,
2346	}, {
2347		.io.pll_bypass = 0,
2348		.io.pll_range = 1,
2349		.io.pll_prediv = 1,
2350		.io.pll_loopdiv = 8,
2351		.io.adc_clock_ratio = 8,
2352		.io.pll_int_loop_filt = 0,
2353		.io.clock_khz = 30000,
2354		.reset = dib90x0_tuner_reset,
2355		.sleep = dib90x0_tuner_sleep,
2356		.clkouttobamse = 0,
2357		.analog_output = 0,
2358		.use_pwm_agc = 0,
2359		.clkoutdrive = 0,
2360		.freq_offset_khz_uhf = 0,
2361		.freq_offset_khz_vhf = 0,
2362	}
2363};
2364
2365
2366static int stk9090m_frontend_attach(struct dvb_usb_adapter *adap)
2367{
2368	struct dib0700_adapter_state *state = adap->priv;
2369	struct dib0700_state *st = adap->dev->priv;
2370	u32 fw_version;
2371
2372	/* Make use of the new i2c functions from FW 1.20 */
2373	dib0700_get_version(adap->dev, NULL, NULL, &fw_version, NULL);
2374	if (fw_version >= 0x10200)
2375		st->fw_use_new_i2c_api = 1;
2376	dib0700_set_i2c_speed(adap->dev, 340);
2377
2378	dib0700_set_gpio(adap->dev, GPIO6, GPIO_OUT, 1);
2379	msleep(20);
2380	dib0700_set_gpio(adap->dev, GPIO9, GPIO_OUT, 1);
2381	dib0700_set_gpio(adap->dev, GPIO4, GPIO_OUT, 1);
2382	dib0700_set_gpio(adap->dev, GPIO7, GPIO_OUT, 1);
2383	dib0700_set_gpio(adap->dev, GPIO10, GPIO_OUT, 0);
2384
2385	dib0700_ctrl_clock(adap->dev, 72, 1);
2386
2387	msleep(20);
2388	dib0700_set_gpio(adap->dev, GPIO10, GPIO_OUT, 1);
2389	msleep(20);
2390	dib0700_set_gpio(adap->dev, GPIO0, GPIO_OUT, 1);
2391
2392	dib9000_i2c_enumeration(&adap->dev->i2c_adap, 1, 0x10, 0x80);
2393
2394	if (request_firmware(&state->frontend_firmware, "dib9090.fw", &adap->dev->udev->dev)) {
2395		deb_info("%s: Upload failed. (file not found?)\n", __func__);
2396		return -ENODEV;
2397	} else {
2398		deb_info("%s: firmware read %Zu bytes.\n", __func__, state->frontend_firmware->size);
2399	}
2400	stk9090m_config.microcode_B_fe_size = state->frontend_firmware->size;
2401	stk9090m_config.microcode_B_fe_buffer = state->frontend_firmware->data;
2402
2403	adap->fe_adap[0].fe = dvb_attach(dib9000_attach, &adap->dev->i2c_adap, 0x80, &stk9090m_config);
2404
2405	return adap->fe_adap[0].fe == NULL ?  -ENODEV : 0;
2406}
2407
2408static int dib9090_tuner_attach(struct dvb_usb_adapter *adap)
2409{
2410	struct dib0700_adapter_state *state = adap->priv;
2411	struct i2c_adapter *i2c = dib9000_get_tuner_interface(adap->fe_adap[0].fe);
2412	u16 data_dib190[10] = {
2413		1, 0x1374,
2414		2, 0x01a2,
2415		7, 0x0020,
2416		0, 0x00ef,
2417		8, 0x0486,
2418	};
2419
2420	if (dvb_attach(dib0090_fw_register, adap->fe_adap[0].fe, i2c, &dib9090_dib0090_config) == NULL)
2421		return -ENODEV;
2422	i2c = dib9000_get_i2c_master(adap->fe_adap[0].fe, DIBX000_I2C_INTERFACE_GPIO_1_2, 0);
2423	if (dib01x0_pmu_update(i2c, data_dib190, 10) != 0)
2424		return -ENODEV;
2425	dib0700_set_i2c_speed(adap->dev, 1500);
2426	if (dib9000_firmware_post_pll_init(adap->fe_adap[0].fe) < 0)
2427		return -ENODEV;
2428	release_firmware(state->frontend_firmware);
2429	return 0;
2430}
2431
2432static int nim9090md_frontend_attach(struct dvb_usb_adapter *adap)
2433{
2434	struct dib0700_adapter_state *state = adap->priv;
2435	struct dib0700_state *st = adap->dev->priv;
2436	struct i2c_adapter *i2c;
2437	struct dvb_frontend *fe_slave;
2438	u32 fw_version;
2439
2440	/* Make use of the new i2c functions from FW 1.20 */
2441	dib0700_get_version(adap->dev, NULL, NULL, &fw_version, NULL);
2442	if (fw_version >= 0x10200)
2443		st->fw_use_new_i2c_api = 1;
2444	dib0700_set_i2c_speed(adap->dev, 340);
2445
2446	dib0700_set_gpio(adap->dev, GPIO6, GPIO_OUT, 1);
2447	msleep(20);
2448	dib0700_set_gpio(adap->dev, GPIO9, GPIO_OUT, 1);
2449	dib0700_set_gpio(adap->dev, GPIO4, GPIO_OUT, 1);
2450	dib0700_set_gpio(adap->dev, GPIO7, GPIO_OUT, 1);
2451	dib0700_set_gpio(adap->dev, GPIO10, GPIO_OUT, 0);
2452
2453	dib0700_ctrl_clock(adap->dev, 72, 1);
2454
2455	msleep(20);
2456	dib0700_set_gpio(adap->dev, GPIO10, GPIO_OUT, 1);
2457	msleep(20);
2458	dib0700_set_gpio(adap->dev, GPIO0, GPIO_OUT, 1);
2459
2460	if (request_firmware(&state->frontend_firmware, "dib9090.fw", &adap->dev->udev->dev)) {
2461		deb_info("%s: Upload failed. (file not found?)\n", __func__);
2462		return -EIO;
2463	} else {
2464		deb_info("%s: firmware read %Zu bytes.\n", __func__, state->frontend_firmware->size);
2465	}
2466	nim9090md_config[0].microcode_B_fe_size = state->frontend_firmware->size;
2467	nim9090md_config[0].microcode_B_fe_buffer = state->frontend_firmware->data;
2468	nim9090md_config[1].microcode_B_fe_size = state->frontend_firmware->size;
2469	nim9090md_config[1].microcode_B_fe_buffer = state->frontend_firmware->data;
2470
2471	dib9000_i2c_enumeration(&adap->dev->i2c_adap, 1, 0x20, 0x80);
2472	adap->fe_adap[0].fe = dvb_attach(dib9000_attach, &adap->dev->i2c_adap, 0x80, &nim9090md_config[0]);
2473
2474	if (adap->fe_adap[0].fe == NULL)
2475		return -ENODEV;
2476
2477	i2c = dib9000_get_i2c_master(adap->fe_adap[0].fe, DIBX000_I2C_INTERFACE_GPIO_3_4, 0);
2478	dib9000_i2c_enumeration(i2c, 1, 0x12, 0x82);
2479
2480	fe_slave = dvb_attach(dib9000_attach, i2c, 0x82, &nim9090md_config[1]);
2481	dib9000_set_slave_frontend(adap->fe_adap[0].fe, fe_slave);
2482
2483	return fe_slave == NULL ?  -ENODEV : 0;
2484}
2485
2486static int nim9090md_tuner_attach(struct dvb_usb_adapter *adap)
2487{
2488	struct dib0700_adapter_state *state = adap->priv;
2489	struct i2c_adapter *i2c;
2490	struct dvb_frontend *fe_slave;
2491	u16 data_dib190[10] = {
2492		1, 0x5374,
2493		2, 0x01ae,
2494		7, 0x0020,
2495		0, 0x00ef,
2496		8, 0x0406,
2497	};
2498	i2c = dib9000_get_tuner_interface(adap->fe_adap[0].fe);
2499	if (dvb_attach(dib0090_fw_register, adap->fe_adap[0].fe, i2c, &nim9090md_dib0090_config[0]) == NULL)
2500		return -ENODEV;
2501	i2c = dib9000_get_i2c_master(adap->fe_adap[0].fe, DIBX000_I2C_INTERFACE_GPIO_1_2, 0);
2502	if (dib01x0_pmu_update(i2c, data_dib190, 10) < 0)
2503		return -ENODEV;
2504
2505	dib0700_set_i2c_speed(adap->dev, 1500);
2506	if (dib9000_firmware_post_pll_init(adap->fe_adap[0].fe) < 0)
2507		return -ENODEV;
2508
2509	fe_slave = dib9000_get_slave_frontend(adap->fe_adap[0].fe, 1);
2510	if (fe_slave != NULL) {
2511		i2c = dib9000_get_component_bus_interface(adap->fe_adap[0].fe);
2512		dib9000_set_i2c_adapter(fe_slave, i2c);
2513
2514		i2c = dib9000_get_tuner_interface(fe_slave);
2515		if (dvb_attach(dib0090_fw_register, fe_slave, i2c, &nim9090md_dib0090_config[1]) == NULL)
2516			return -ENODEV;
2517		fe_slave->dvb = adap->fe_adap[0].fe->dvb;
2518		dib9000_fw_set_component_bus_speed(adap->fe_adap[0].fe, 1500);
2519		if (dib9000_firmware_post_pll_init(fe_slave) < 0)
2520			return -ENODEV;
2521	}
2522	release_firmware(state->frontend_firmware);
2523
2524	return 0;
2525}
2526
2527/* NIM7090 */
2528static int dib7090p_get_best_sampling(struct dvb_frontend *fe , struct dibx090p_best_adc *adc)
2529{
2530	u8 spur = 0, prediv = 0, loopdiv = 0, min_prediv = 1, max_prediv = 1;
2531
2532	u16 xtal = 12000;
2533	u32 fcp_min = 1900;  /* PLL Minimum Frequency comparator KHz */
2534	u32 fcp_max = 20000; /* PLL Maximum Frequency comparator KHz */
2535	u32 fdem_max = 76000;
2536	u32 fdem_min = 69500;
2537	u32 fcp = 0, fs = 0, fdem = 0;
2538	u32 harmonic_id = 0;
2539
2540	adc->pll_loopdiv = loopdiv;
2541	adc->pll_prediv = prediv;
2542	adc->timf = 0;
2543
2544	deb_info("bandwidth = %d fdem_min =%d", fe->dtv_property_cache.bandwidth_hz, fdem_min);
2545
2546	/* Find Min and Max prediv */
2547	while ((xtal/max_prediv) >= fcp_min)
2548		max_prediv++;
2549
2550	max_prediv--;
2551	min_prediv = max_prediv;
2552	while ((xtal/min_prediv) <= fcp_max) {
2553		min_prediv--;
2554		if (min_prediv == 1)
2555			break;
2556	}
2557	deb_info("MIN prediv = %d : MAX prediv = %d", min_prediv, max_prediv);
2558
2559	min_prediv = 2;
2560
2561	for (prediv = min_prediv ; prediv < max_prediv; prediv++) {
2562		fcp = xtal / prediv;
2563		if (fcp > fcp_min && fcp < fcp_max) {
2564			for (loopdiv = 1 ; loopdiv < 64 ; loopdiv++) {
2565				fdem = ((xtal/prediv) * loopdiv);
2566				fs   = fdem / 4;
2567				/* test min/max system restrictions */
2568
2569				if ((fdem >= fdem_min) && (fdem <= fdem_max) && (fs >= fe->dtv_property_cache.bandwidth_hz/1000)) {
2570					spur = 0;
2571					/* test fs harmonics positions */
2572					for (harmonic_id = (fe->dtv_property_cache.frequency / (1000*fs)) ;  harmonic_id <= ((fe->dtv_property_cache.frequency / (1000*fs))+1) ; harmonic_id++) {
2573						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)))) {
2574							spur = 1;
2575							break;
2576						}
2577					}
2578
2579					if (!spur) {
2580						adc->pll_loopdiv = loopdiv;
2581						adc->pll_prediv = prediv;
2582						adc->timf = 2396745143UL/fdem*(1 << 9);
2583						adc->timf += ((2396745143UL%fdem) << 9)/fdem;
2584						deb_info("loopdiv=%i prediv=%i timf=%i", loopdiv, prediv, adc->timf);
2585						break;
2586					}
2587				}
2588			}
2589		}
2590		if (!spur)
2591			break;
2592	}
2593
2594
2595	if (adc->pll_loopdiv == 0 && adc->pll_prediv == 0)
2596		return -EINVAL;
2597	else
2598		return 0;
2599}
2600
2601static int dib7090_agc_startup(struct dvb_frontend *fe)
2602{
2603	struct dvb_usb_adapter *adap = fe->dvb->priv;
2604	struct dib0700_adapter_state *state = adap->priv;
2605	struct dibx000_bandwidth_config pll;
2606	u16 target;
2607	struct dibx090p_best_adc adc;
2608	int ret;
2609
2610	ret = state->set_param_save(fe);
2611	if (ret < 0)
2612		return ret;
2613
2614	memset(&pll, 0, sizeof(struct dibx000_bandwidth_config));
2615	dib0090_pwm_gain_reset(fe);
2616	target = (dib0090_get_wbd_target(fe) * 8 + 1) / 2;
2617	state->dib7000p_ops.set_wbd_ref(fe, target);
2618
2619	if (dib7090p_get_best_sampling(fe, &adc) == 0) {
2620		pll.pll_ratio  = adc.pll_loopdiv;
2621		pll.pll_prediv = adc.pll_prediv;
2622
2623		state->dib7000p_ops.update_pll(fe, &pll);
2624		state->dib7000p_ops.ctrl_timf(fe, DEMOD_TIMF_SET, adc.timf);
2625	}
2626	return 0;
2627}
2628
2629static int dib7090_agc_restart(struct dvb_frontend *fe, u8 restart)
2630{
2631	deb_info("AGC restart callback: %d", restart);
2632	if (restart == 0) /* before AGC startup */
2633		dib0090_set_dc_servo(fe, 1);
2634	return 0;
2635}
2636
2637static int tfe7790p_update_lna(struct dvb_frontend *fe, u16 agc_global)
2638{
2639	struct dvb_usb_adapter *adap = fe->dvb->priv;
2640	struct dib0700_adapter_state *state = adap->priv;
2641
2642	deb_info("update LNA: agc global=%i", agc_global);
2643
2644	if (agc_global < 25000) {
2645		state->dib7000p_ops.set_gpio(fe, 8, 0, 0);
2646		state->dib7000p_ops.set_agc1_min(fe, 0);
2647	} else {
2648		state->dib7000p_ops.set_gpio(fe, 8, 0, 1);
2649		state->dib7000p_ops.set_agc1_min(fe, 32768);
2650	}
2651
2652	return 0;
2653}
2654
2655static struct dib0090_wbd_slope dib7090_wbd_table[] = {
2656	{ 380,   81, 850, 64, 540,  4},
2657	{ 860,   51, 866, 21,  375, 4},
2658	{1700,    0, 250, 0,   100, 6},
2659	{2600,    0, 250, 0,   100, 6},
2660	{ 0xFFFF, 0,   0, 0,   0,   0},
2661};
2662
2663static struct dibx000_agc_config dib7090_agc_config[2] = {
2664	{
2665		.band_caps      = BAND_UHF,
2666		/* 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,
2667		* 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 */
2668		.setup          = (0 << 15) | (0 << 14) | (5 << 11) | (0 << 10) | (0 << 9) | (0 << 8) | (3 << 5) | (0 << 4) | (5 << 1) | (0 << 0),
2669
2670		.inv_gain       = 687,
2671		.time_stabiliz  = 10,
2672
2673		.alpha_level    = 0,
2674		.thlock         = 118,
2675
2676		.wbd_inv        = 0,
2677		.wbd_ref        = 1200,
2678		.wbd_sel        = 3,
2679		.wbd_alpha      = 5,
2680
2681		.agc1_max       = 65535,
2682		.agc1_min       = 32768,
2683
2684		.agc2_max       = 65535,
2685		.agc2_min       = 0,
2686
2687		.agc1_pt1       = 0,
2688		.agc1_pt2       = 32,
2689		.agc1_pt3       = 114,
2690		.agc1_slope1    = 143,
2691		.agc1_slope2    = 144,
2692		.agc2_pt1       = 114,
2693		.agc2_pt2       = 227,
2694		.agc2_slope1    = 116,
2695		.agc2_slope2    = 117,
2696
2697		.alpha_mant     = 18,
2698		.alpha_exp      = 0,
2699		.beta_mant      = 20,
2700		.beta_exp       = 59,
2701
2702		.perform_agc_softsplit = 0,
2703	} , {
2704		.band_caps      = BAND_FM | BAND_VHF | BAND_CBAND,
2705		/* 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,
2706		* 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 */
2707		.setup          = (0 << 15) | (0 << 14) | (5 << 11) | (0 << 10) | (0 << 9) | (0 << 8) | (3 << 5) | (0 << 4) | (5 << 1) | (0 << 0),
2708
2709		.inv_gain       = 732,
2710		.time_stabiliz  = 10,
2711
2712		.alpha_level    = 0,
2713		.thlock         = 118,
2714
2715		.wbd_inv        = 0,
2716		.wbd_ref        = 1200,
2717		.wbd_sel        = 3,
2718		.wbd_alpha      = 5,
2719
2720		.agc1_max       = 65535,
2721		.agc1_min       = 0,
2722
2723		.agc2_max       = 65535,
2724		.agc2_min       = 0,
2725
2726		.agc1_pt1       = 0,
2727		.agc1_pt2       = 0,
2728		.agc1_pt3       = 98,
2729		.agc1_slope1    = 0,
2730		.agc1_slope2    = 167,
2731		.agc2_pt1       = 98,
2732		.agc2_pt2       = 255,
2733		.agc2_slope1    = 104,
2734		.agc2_slope2    = 0,
2735
2736		.alpha_mant     = 18,
2737		.alpha_exp      = 0,
2738		.beta_mant      = 20,
2739		.beta_exp       = 59,
2740
2741		.perform_agc_softsplit = 0,
2742	}
2743};
2744
2745static struct dibx000_bandwidth_config dib7090_clock_config_12_mhz = {
2746	.internal = 60000,
2747	.sampling = 15000,
2748	.pll_prediv = 1,
2749	.pll_ratio = 5,
2750	.pll_range = 0,
2751	.pll_reset = 0,
2752	.pll_bypass = 0,
2753	.enable_refdiv = 0,
2754	.bypclk_div = 0,
2755	.IO_CLK_en_core = 1,
2756	.ADClkSrc = 1,
2757	.modulo = 2,
2758	.sad_cfg = (3 << 14) | (1 << 12) | (524 << 0),
2759	.ifreq = (0 << 25) | 0,
2760	.timf = 20452225,
2761	.xtal_hz = 15000000,
2762};
2763
2764static struct dib7000p_config nim7090_dib7000p_config = {
2765	.output_mpeg2_in_188_bytes  = 1,
2766	.hostbus_diversity			= 1,
2767	.tuner_is_baseband			= 1,
2768	.update_lna					= tfe7790p_update_lna, /* GPIO used is the same as TFE7790 */
2769
2770	.agc_config_count			= 2,
2771	.agc						= dib7090_agc_config,
2772
2773	.bw							= &dib7090_clock_config_12_mhz,
2774
2775	.gpio_dir					= DIB7000P_GPIO_DEFAULT_DIRECTIONS,
2776	.gpio_val					= DIB7000P_GPIO_DEFAULT_VALUES,
2777	.gpio_pwm_pos				= DIB7000P_GPIO_DEFAULT_PWM_POS,
2778
2779	.pwm_freq_div				= 0,
2780
2781	.agc_control				= dib7090_agc_restart,
2782
2783	.spur_protect				= 0,
2784	.disable_sample_and_hold	= 0,
2785	.enable_current_mirror		= 0,
2786	.diversity_delay			= 0,
2787
2788	.output_mode				= OUTMODE_MPEG2_FIFO,
2789	.enMpegOutput				= 1,
2790};
2791
2792static int tfe7090p_pvr_update_lna(struct dvb_frontend *fe, u16 agc_global)
2793{
2794	struct dvb_usb_adapter *adap = fe->dvb->priv;
2795	struct dib0700_adapter_state *state = adap->priv;
2796
2797	deb_info("TFE7090P-PVR update LNA: agc global=%i", agc_global);
2798	if (agc_global < 25000) {
2799		state->dib7000p_ops.set_gpio(fe, 5, 0, 0);
2800		state->dib7000p_ops.set_agc1_min(fe, 0);
2801	} else {
2802		state->dib7000p_ops.set_gpio(fe, 5, 0, 1);
2803		state->dib7000p_ops.set_agc1_min(fe, 32768);
2804	}
2805
2806	return 0;
2807}
2808
2809static struct dib7000p_config tfe7090pvr_dib7000p_config[2] = {
2810	{
2811		.output_mpeg2_in_188_bytes  = 1,
2812		.hostbus_diversity			= 1,
2813		.tuner_is_baseband			= 1,
2814		.update_lna					= tfe7090p_pvr_update_lna,
2815
2816		.agc_config_count			= 2,
2817		.agc						= dib7090_agc_config,
2818
2819		.bw							= &dib7090_clock_config_12_mhz,
2820
2821		.gpio_dir					= DIB7000P_GPIO_DEFAULT_DIRECTIONS,
2822		.gpio_val					= DIB7000P_GPIO_DEFAULT_VALUES,
2823		.gpio_pwm_pos				= DIB7000P_GPIO_DEFAULT_PWM_POS,
2824
2825		.pwm_freq_div				= 0,
2826
2827		.agc_control				= dib7090_agc_restart,
2828
2829		.spur_protect				= 0,
2830		.disable_sample_and_hold	= 0,
2831		.enable_current_mirror		= 0,
2832		.diversity_delay			= 0,
2833
2834		.output_mode				= OUTMODE_MPEG2_PAR_GATED_CLK,
2835		.default_i2c_addr			= 0x90,
2836		.enMpegOutput				= 1,
2837	}, {
2838		.output_mpeg2_in_188_bytes  = 1,
2839		.hostbus_diversity			= 1,
2840		.tuner_is_baseband			= 1,
2841		.update_lna					= tfe7090p_pvr_update_lna,
2842
2843		.agc_config_count			= 2,
2844		.agc						= dib7090_agc_config,
2845
2846		.bw							= &dib7090_clock_config_12_mhz,
2847
2848		.gpio_dir					= DIB7000P_GPIO_DEFAULT_DIRECTIONS,
2849		.gpio_val					= DIB7000P_GPIO_DEFAULT_VALUES,
2850		.gpio_pwm_pos				= DIB7000P_GPIO_DEFAULT_PWM_POS,
2851
2852		.pwm_freq_div				= 0,
2853
2854		.agc_control				= dib7090_agc_restart,
2855
2856		.spur_protect				= 0,
2857		.disable_sample_and_hold	= 0,
2858		.enable_current_mirror		= 0,
2859		.diversity_delay			= 0,
2860
2861		.output_mode				= OUTMODE_MPEG2_PAR_GATED_CLK,
2862		.default_i2c_addr			= 0x92,
2863		.enMpegOutput				= 0,
2864	}
2865};
2866
2867static struct dib0090_config nim7090_dib0090_config = {
2868	.io.clock_khz = 12000,
2869	.io.pll_bypass = 0,
2870	.io.pll_range = 0,
2871	.io.pll_prediv = 3,
2872	.io.pll_loopdiv = 6,
2873	.io.adc_clock_ratio = 0,
2874	.io.pll_int_loop_filt = 0,
2875
2876	.freq_offset_khz_uhf = 0,
2877	.freq_offset_khz_vhf = 0,
2878
2879	.clkouttobamse = 1,
2880	.analog_output = 0,
2881
2882	.wbd_vhf_offset = 0,
2883	.wbd_cband_offset = 0,
2884	.use_pwm_agc = 1,
2885	.clkoutdrive = 0,
2886
2887	.fref_clock_ratio = 0,
2888
2889	.wbd = dib7090_wbd_table,
2890
2891	.ls_cfg_pad_drv = 0,
2892	.data_tx_drv = 0,
2893	.low_if = NULL,
2894	.in_soc = 1,
2895};
2896
2897static struct dib7000p_config tfe7790p_dib7000p_config = {
2898	.output_mpeg2_in_188_bytes  = 1,
2899	.hostbus_diversity			= 1,
2900	.tuner_is_baseband			= 1,
2901	.update_lna					= tfe7790p_update_lna,
2902
2903	.agc_config_count			= 2,
2904	.agc						= dib7090_agc_config,
2905
2906	.bw							= &dib7090_clock_config_12_mhz,
2907
2908	.gpio_dir					= DIB7000P_GPIO_DEFAULT_DIRECTIONS,
2909	.gpio_val					= DIB7000P_GPIO_DEFAULT_VALUES,
2910	.gpio_pwm_pos				= DIB7000P_GPIO_DEFAULT_PWM_POS,
2911
2912	.pwm_freq_div				= 0,
2913
2914	.agc_control				= dib7090_agc_restart,
2915
2916	.spur_protect				= 0,
2917	.disable_sample_and_hold	= 0,
2918	.enable_current_mirror		= 0,
2919	.diversity_delay			= 0,
2920
2921	.output_mode				= OUTMODE_MPEG2_PAR_GATED_CLK,
2922	.enMpegOutput				= 1,
2923};
2924
2925static struct dib0090_config tfe7790p_dib0090_config = {
2926	.io.clock_khz = 12000,
2927	.io.pll_bypass = 0,
2928	.io.pll_range = 0,
2929	.io.pll_prediv = 3,
2930	.io.pll_loopdiv = 6,
2931	.io.adc_clock_ratio = 0,
2932	.io.pll_int_loop_filt = 0,
2933
2934	.freq_offset_khz_uhf = 0,
2935	.freq_offset_khz_vhf = 0,
2936
2937	.clkouttobamse = 1,
2938	.analog_output = 0,
2939
2940	.wbd_vhf_offset = 0,
2941	.wbd_cband_offset = 0,
2942	.use_pwm_agc = 1,
2943	.clkoutdrive = 0,
2944
2945	.fref_clock_ratio = 0,
2946
2947	.wbd = dib7090_wbd_table,
2948
2949	.ls_cfg_pad_drv = 0,
2950	.data_tx_drv = 0,
2951	.low_if = NULL,
2952	.in_soc = 1,
2953	.force_cband_input = 0,
2954	.is_dib7090e = 0,
2955	.force_crystal_mode = 1,
2956};
2957
2958static struct dib0090_config tfe7090pvr_dib0090_config[2] = {
2959	{
2960		.io.clock_khz = 12000,
2961		.io.pll_bypass = 0,
2962		.io.pll_range = 0,
2963		.io.pll_prediv = 3,
2964		.io.pll_loopdiv = 6,
2965		.io.adc_clock_ratio = 0,
2966		.io.pll_int_loop_filt = 0,
2967
2968		.freq_offset_khz_uhf = 50,
2969		.freq_offset_khz_vhf = 70,
2970
2971		.clkouttobamse = 1,
2972		.analog_output = 0,
2973
2974		.wbd_vhf_offset = 0,
2975		.wbd_cband_offset = 0,
2976		.use_pwm_agc = 1,
2977		.clkoutdrive = 0,
2978
2979		.fref_clock_ratio = 0,
2980
2981		.wbd = dib7090_wbd_table,
2982
2983		.ls_cfg_pad_drv = 0,
2984		.data_tx_drv = 0,
2985		.low_if = NULL,
2986		.in_soc = 1,
2987	}, {
2988		.io.clock_khz = 12000,
2989		.io.pll_bypass = 0,
2990		.io.pll_range = 0,
2991		.io.pll_prediv = 3,
2992		.io.pll_loopdiv = 6,
2993		.io.adc_clock_ratio = 0,
2994		.io.pll_int_loop_filt = 0,
2995
2996		.freq_offset_khz_uhf = -50,
2997		.freq_offset_khz_vhf = -70,
2998
2999		.clkouttobamse = 1,
3000		.analog_output = 0,
3001
3002		.wbd_vhf_offset = 0,
3003		.wbd_cband_offset = 0,
3004		.use_pwm_agc = 1,
3005		.clkoutdrive = 0,
3006
3007		.fref_clock_ratio = 0,
3008
3009		.wbd = dib7090_wbd_table,
3010
3011		.ls_cfg_pad_drv = 0,
3012		.data_tx_drv = 0,
3013		.low_if = NULL,
3014		.in_soc = 1,
3015	}
3016};
3017
3018static int nim7090_frontend_attach(struct dvb_usb_adapter *adap)
3019{
3020	struct dib0700_adapter_state *state = adap->priv;
3021
3022	if (!dvb_attach(dib7000p_attach, &state->dib7000p_ops))
3023		return -ENODEV;
3024
3025	dib0700_set_gpio(adap->dev, GPIO6, GPIO_OUT, 1);
3026	msleep(20);
3027	dib0700_set_gpio(adap->dev, GPIO9, GPIO_OUT, 1);
3028	dib0700_set_gpio(adap->dev, GPIO4, GPIO_OUT, 1);
3029	dib0700_set_gpio(adap->dev, GPIO7, GPIO_OUT, 1);
3030	dib0700_set_gpio(adap->dev, GPIO10, GPIO_OUT, 0);
3031
3032	msleep(20);
3033	dib0700_set_gpio(adap->dev, GPIO10, GPIO_OUT, 1);
3034	msleep(20);
3035	dib0700_set_gpio(adap->dev, GPIO0, GPIO_OUT, 1);
3036
3037	if (state->dib7000p_ops.i2c_enumeration(&adap->dev->i2c_adap, 1, 0x10, &nim7090_dib7000p_config) != 0) {
3038		err("%s: state->dib7000p_ops.i2c_enumeration failed.  Cannot continue\n", __func__);
3039		dvb_detach(&state->dib7000p_ops);
3040		return -ENODEV;
3041	}
3042	adap->fe_adap[0].fe = state->dib7000p_ops.init(&adap->dev->i2c_adap, 0x80, &nim7090_dib7000p_config);
3043
3044	return adap->fe_adap[0].fe == NULL ?  -ENODEV : 0;
3045}
3046
3047static int nim7090_tuner_attach(struct dvb_usb_adapter *adap)
3048{
3049	struct dib0700_adapter_state *st = adap->priv;
3050	struct i2c_adapter *tun_i2c = st->dib7000p_ops.get_i2c_tuner(adap->fe_adap[0].fe);
3051
3052	nim7090_dib0090_config.reset = st->dib7000p_ops.tuner_sleep,
3053	nim7090_dib0090_config.sleep = st->dib7000p_ops.tuner_sleep,
3054	nim7090_dib0090_config.get_adc_power = st->dib7000p_ops.get_adc_power;
3055
3056	if (dvb_attach(dib0090_register, adap->fe_adap[0].fe, tun_i2c, &nim7090_dib0090_config) == NULL)
3057		return -ENODEV;
3058
3059	st->dib7000p_ops.set_gpio(adap->fe_adap[0].fe, 8, 0, 1);
3060
3061	st->set_param_save = adap->fe_adap[0].fe->ops.tuner_ops.set_params;
3062	adap->fe_adap[0].fe->ops.tuner_ops.set_params = dib7090_agc_startup;
3063	return 0;
3064}
3065
3066static int tfe7090pvr_frontend0_attach(struct dvb_usb_adapter *adap)
3067{
3068	struct dib0700_state *st = adap->dev->priv;
3069	struct dib0700_adapter_state *state = adap->priv;
3070
3071	if (!dvb_attach(dib7000p_attach, &state->dib7000p_ops))
3072		return -ENODEV;
3073
3074	/* The TFE7090 requires the dib0700 to not be in master mode */
3075	st->disable_streaming_master_mode = 1;
3076
3077	dib0700_set_gpio(adap->dev, GPIO6, GPIO_OUT, 1);
3078	msleep(20);
3079	dib0700_set_gpio(adap->dev, GPIO9, GPIO_OUT, 1);
3080	dib0700_set_gpio(adap->dev, GPIO4, GPIO_OUT, 1);
3081	dib0700_set_gpio(adap->dev, GPIO7, GPIO_OUT, 1);
3082	dib0700_set_gpio(adap->dev, GPIO10, GPIO_OUT, 0);
3083
3084	msleep(20);
3085	dib0700_set_gpio(adap->dev, GPIO10, GPIO_OUT, 1);
3086	msleep(20);
3087	dib0700_set_gpio(adap->dev, GPIO0, GPIO_OUT, 1);
3088
3089	/* initialize IC 0 */
3090	if (state->dib7000p_ops.i2c_enumeration(&adap->dev->i2c_adap, 1, 0x20, &tfe7090pvr_dib7000p_config[0]) != 0) {
3091		err("%s: state->dib7000p_ops.i2c_enumeration failed.  Cannot continue\n", __func__);
3092		dvb_detach(&state->dib7000p_ops);
3093		return -ENODEV;
3094	}
3095
3096	dib0700_set_i2c_speed(adap->dev, 340);
3097	adap->fe_adap[0].fe = state->dib7000p_ops.init(&adap->dev->i2c_adap, 0x90, &tfe7090pvr_dib7000p_config[0]);
3098	if (adap->fe_adap[0].fe == NULL)
3099		return -ENODEV;
3100
3101	state->dib7000p_ops.slave_reset(adap->fe_adap[0].fe);
3102
3103	return 0;
3104}
3105
3106static int tfe7090pvr_frontend1_attach(struct dvb_usb_adapter *adap)
3107{
3108	struct i2c_adapter *i2c;
3109	struct dib0700_adapter_state *state = adap->priv;
3110
3111	if (adap->dev->adapter[0].fe_adap[0].fe == NULL) {
3112		err("the master dib7090 has to be initialized first");
3113		return -ENODEV; /* the master device has not been initialized */
3114	}
3115
3116	if (!dvb_attach(dib7000p_attach, &state->dib7000p_ops))
3117		return -ENODEV;
3118
3119	i2c = state->dib7000p_ops.get_i2c_master(adap->dev->adapter[0].fe_adap[0].fe, DIBX000_I2C_INTERFACE_GPIO_6_7, 1);
3120	if (state->dib7000p_ops.i2c_enumeration(i2c, 1, 0x10, &tfe7090pvr_dib7000p_config[1]) != 0) {
3121		err("%s: state->dib7000p_ops.i2c_enumeration failed.  Cannot continue\n", __func__);
3122		dvb_detach(&state->dib7000p_ops);
3123		return -ENODEV;
3124	}
3125
3126	adap->fe_adap[0].fe = state->dib7000p_ops.init(i2c, 0x92, &tfe7090pvr_dib7000p_config[1]);
3127	dib0700_set_i2c_speed(adap->dev, 200);
3128
3129	return adap->fe_adap[0].fe == NULL ? -ENODEV : 0;
3130}
3131
3132static int tfe7090pvr_tuner0_attach(struct dvb_usb_adapter *adap)
3133{
3134	struct dib0700_adapter_state *st = adap->priv;
3135	struct i2c_adapter *tun_i2c = st->dib7000p_ops.get_i2c_tuner(adap->fe_adap[0].fe);
3136
3137	tfe7090pvr_dib0090_config[0].reset = st->dib7000p_ops.tuner_sleep;
3138	tfe7090pvr_dib0090_config[0].sleep = st->dib7000p_ops.tuner_sleep;
3139	tfe7090pvr_dib0090_config[0].get_adc_power = st->dib7000p_ops.get_adc_power;
3140
3141	if (dvb_attach(dib0090_register, adap->fe_adap[0].fe, tun_i2c, &tfe7090pvr_dib0090_config[0]) == NULL)
3142		return -ENODEV;
3143
3144	st->dib7000p_ops.set_gpio(adap->fe_adap[0].fe, 8, 0, 1);
3145
3146	st->set_param_save = adap->fe_adap[0].fe->ops.tuner_ops.set_params;
3147	adap->fe_adap[0].fe->ops.tuner_ops.set_params = dib7090_agc_startup;
3148	return 0;
3149}
3150
3151static int tfe7090pvr_tuner1_attach(struct dvb_usb_adapter *adap)
3152{
3153	struct dib0700_adapter_state *st = adap->priv;
3154	struct i2c_adapter *tun_i2c = st->dib7000p_ops.get_i2c_tuner(adap->fe_adap[0].fe);
3155
3156	tfe7090pvr_dib0090_config[1].reset = st->dib7000p_ops.tuner_sleep;
3157	tfe7090pvr_dib0090_config[1].sleep = st->dib7000p_ops.tuner_sleep;
3158	tfe7090pvr_dib0090_config[1].get_adc_power = st->dib7000p_ops.get_adc_power;
3159
3160	if (dvb_attach(dib0090_register, adap->fe_adap[0].fe, tun_i2c, &tfe7090pvr_dib0090_config[1]) == NULL)
3161		return -ENODEV;
3162
3163	st->dib7000p_ops.set_gpio(adap->fe_adap[0].fe, 8, 0, 1);
3164
3165	st->set_param_save = adap->fe_adap[0].fe->ops.tuner_ops.set_params;
3166	adap->fe_adap[0].fe->ops.tuner_ops.set_params = dib7090_agc_startup;
3167	return 0;
3168}
3169
3170static int tfe7790p_frontend_attach(struct dvb_usb_adapter *adap)
3171{
3172	struct dib0700_state *st = adap->dev->priv;
3173	struct dib0700_adapter_state *state = adap->priv;
3174
3175	if (!dvb_attach(dib7000p_attach, &state->dib7000p_ops))
3176		return -ENODEV;
3177
3178	/* The TFE7790P requires the dib0700 to not be in master mode */
3179	st->disable_streaming_master_mode = 1;
3180
3181	dib0700_set_gpio(adap->dev, GPIO6, GPIO_OUT, 1);
3182	msleep(20);
3183	dib0700_set_gpio(adap->dev, GPIO9, GPIO_OUT, 1);
3184	dib0700_set_gpio(adap->dev, GPIO4, GPIO_OUT, 1);
3185	dib0700_set_gpio(adap->dev, GPIO7, GPIO_OUT, 1);
3186	dib0700_set_gpio(adap->dev, GPIO10, GPIO_OUT, 0);
3187	msleep(20);
3188	dib0700_ctrl_clock(adap->dev, 72, 1);
3189	dib0700_set_gpio(adap->dev, GPIO10, GPIO_OUT, 1);
3190	msleep(20);
3191	dib0700_set_gpio(adap->dev, GPIO0, GPIO_OUT, 1);
3192
3193	if (state->dib7000p_ops.i2c_enumeration(&adap->dev->i2c_adap,
3194				1, 0x10, &tfe7790p_dib7000p_config) != 0) {
3195		err("%s: state->dib7000p_ops.i2c_enumeration failed.  Cannot continue\n",
3196				__func__);
3197		dvb_detach(&state->dib7000p_ops);
3198		return -ENODEV;
3199	}
3200	adap->fe_adap[0].fe = state->dib7000p_ops.init(&adap->dev->i2c_adap,
3201			0x80, &tfe7790p_dib7000p_config);
3202
3203	return adap->fe_adap[0].fe == NULL ?  -ENODEV : 0;
3204}
3205
3206static int tfe7790p_tuner_attach(struct dvb_usb_adapter *adap)
3207{
3208	struct dib0700_adapter_state *st = adap->priv;
3209	struct i2c_adapter *tun_i2c =
3210		st->dib7000p_ops.get_i2c_tuner(adap->fe_adap[0].fe);
3211
3212
3213	tfe7790p_dib0090_config.reset = st->dib7000p_ops.tuner_sleep;
3214	tfe7790p_dib0090_config.sleep = st->dib7000p_ops.tuner_sleep;
3215	tfe7790p_dib0090_config.get_adc_power = st->dib7000p_ops.get_adc_power;
3216
3217	if (dvb_attach(dib0090_register, adap->fe_adap[0].fe, tun_i2c,
3218				&tfe7790p_dib0090_config) == NULL)
3219		return -ENODEV;
3220
3221	st->dib7000p_ops.set_gpio(adap->fe_adap[0].fe, 8, 0, 1);
3222
3223	st->set_param_save = adap->fe_adap[0].fe->ops.tuner_ops.set_params;
3224	adap->fe_adap[0].fe->ops.tuner_ops.set_params = dib7090_agc_startup;
3225	return 0;
3226}
3227
3228/* STK7070PD */
3229static struct dib7000p_config stk7070pd_dib7000p_config[2] = {
3230	{
3231		.output_mpeg2_in_188_bytes = 1,
3232
3233		.agc_config_count = 1,
3234		.agc = &dib7070_agc_config,
3235		.bw  = &dib7070_bw_config_12_mhz,
3236		.tuner_is_baseband = 1,
3237		.spur_protect = 1,
3238
3239		.gpio_dir = DIB7000P_GPIO_DEFAULT_DIRECTIONS,
3240		.gpio_val = DIB7000P_GPIO_DEFAULT_VALUES,
3241		.gpio_pwm_pos = DIB7000P_GPIO_DEFAULT_PWM_POS,
3242
3243		.hostbus_diversity = 1,
3244	}, {
3245		.output_mpeg2_in_188_bytes = 1,
3246
3247		.agc_config_count = 1,
3248		.agc = &dib7070_agc_config,
3249		.bw  = &dib7070_bw_config_12_mhz,
3250		.tuner_is_baseband = 1,
3251		.spur_protect = 1,
3252
3253		.gpio_dir = DIB7000P_GPIO_DEFAULT_DIRECTIONS,
3254		.gpio_val = DIB7000P_GPIO_DEFAULT_VALUES,
3255		.gpio_pwm_pos = DIB7000P_GPIO_DEFAULT_PWM_POS,
3256
3257		.hostbus_diversity = 1,
3258	}
3259};
3260
3261static void stk7070pd_init(struct dvb_usb_device *dev)
3262{
3263	dib0700_set_gpio(dev, GPIO6, GPIO_OUT, 1);
3264	msleep(10);
3265	dib0700_set_gpio(dev, GPIO9, GPIO_OUT, 1);
3266	dib0700_set_gpio(dev, GPIO4, GPIO_OUT, 1);
3267	dib0700_set_gpio(dev, GPIO7, GPIO_OUT, 1);
3268	dib0700_set_gpio(dev, GPIO10, GPIO_OUT, 0);
3269
3270	dib0700_ctrl_clock(dev, 72, 1);
3271
3272	msleep(10);
3273	dib0700_set_gpio(dev, GPIO10, GPIO_OUT, 1);
3274}
3275
3276static int stk7070pd_frontend_attach0(struct dvb_usb_adapter *adap)
3277{
3278	struct dib0700_adapter_state *state = adap->priv;
3279
3280	if (!dvb_attach(dib7000p_attach, &state->dib7000p_ops))
3281		return -ENODEV;
3282
3283	stk7070pd_init(adap->dev);
3284
3285	msleep(10);
3286	dib0700_set_gpio(adap->dev, GPIO0, GPIO_OUT, 1);
3287
3288	if (state->dib7000p_ops.i2c_enumeration(&adap->dev->i2c_adap, 2, 18,
3289				     stk7070pd_dib7000p_config) != 0) {
3290		err("%s: state->dib7000p_ops.i2c_enumeration failed.  Cannot continue\n",
3291		    __func__);
3292		dvb_detach(&state->dib7000p_ops);
3293		return -ENODEV;
3294	}
3295
3296	adap->fe_adap[0].fe = state->dib7000p_ops.init(&adap->dev->i2c_adap, 0x80, &stk7070pd_dib7000p_config[0]);
3297	return adap->fe_adap[0].fe == NULL ? -ENODEV : 0;
3298}
3299
3300static int stk7070pd_frontend_attach1(struct dvb_usb_adapter *adap)
3301{
3302	struct dib0700_adapter_state *state = adap->priv;
3303
3304	if (!dvb_attach(dib7000p_attach, &state->dib7000p_ops))
3305		return -ENODEV;
3306
3307	adap->fe_adap[0].fe = state->dib7000p_ops.init(&adap->dev->i2c_adap, 0x82, &stk7070pd_dib7000p_config[1]);
3308	return adap->fe_adap[0].fe == NULL ? -ENODEV : 0;
3309}
3310
3311static int novatd_read_status_override(struct dvb_frontend *fe,
3312		fe_status_t *stat)
3313{
3314	struct dvb_usb_adapter *adap = fe->dvb->priv;
3315	struct dvb_usb_device *dev = adap->dev;
3316	struct dib0700_state *state = dev->priv;
3317	int ret;
3318
3319	ret = state->read_status(fe, stat);
3320
3321	if (!ret)
3322		dib0700_set_gpio(dev, adap->id == 0 ? GPIO1 : GPIO0, GPIO_OUT,
3323				!!(*stat & FE_HAS_LOCK));
3324
3325	return ret;
3326}
3327
3328static int novatd_sleep_override(struct dvb_frontend* fe)
3329{
3330	struct dvb_usb_adapter *adap = fe->dvb->priv;
3331	struct dvb_usb_device *dev = adap->dev;
3332	struct dib0700_state *state = dev->priv;
3333
3334	/* turn off LED */
3335	dib0700_set_gpio(dev, adap->id == 0 ? GPIO1 : GPIO0, GPIO_OUT, 0);
3336
3337	return state->sleep(fe);
3338}
3339
3340/**
3341 * novatd_frontend_attach - Nova-TD specific attach
3342 *
3343 * Nova-TD has GPIO0, 1 and 2 for LEDs. So do not fiddle with them except for
3344 * information purposes.
3345 */
3346static int novatd_frontend_attach(struct dvb_usb_adapter *adap)
3347{
3348	struct dvb_usb_device *dev = adap->dev;
3349	struct dib0700_state *st = dev->priv;
3350	struct dib0700_adapter_state *state = adap->priv;
3351
3352	if (!dvb_attach(dib7000p_attach, &state->dib7000p_ops))
3353		return -ENODEV;
3354
3355	if (adap->id == 0) {
3356		stk7070pd_init(dev);
3357
3358		/* turn the power LED on, the other two off (just in case) */
3359		dib0700_set_gpio(dev, GPIO0, GPIO_OUT, 0);
3360		dib0700_set_gpio(dev, GPIO1, GPIO_OUT, 0);
3361		dib0700_set_gpio(dev, GPIO2, GPIO_OUT, 1);
3362
3363		if (state->dib7000p_ops.i2c_enumeration(&dev->i2c_adap, 2, 18,
3364					     stk7070pd_dib7000p_config) != 0) {
3365			err("%s: state->dib7000p_ops.i2c_enumeration failed.  Cannot continue\n",
3366			    __func__);
3367			dvb_detach(&state->dib7000p_ops);
3368			return -ENODEV;
3369		}
3370	}
3371
3372	adap->fe_adap[0].fe = state->dib7000p_ops.init(&dev->i2c_adap,
3373			adap->id == 0 ? 0x80 : 0x82,
3374			&stk7070pd_dib7000p_config[adap->id]);
3375
3376	if (adap->fe_adap[0].fe == NULL)
3377		return -ENODEV;
3378
3379	st->read_status = adap->fe_adap[0].fe->ops.read_status;
3380	adap->fe_adap[0].fe->ops.read_status = novatd_read_status_override;
3381	st->sleep = adap->fe_adap[0].fe->ops.sleep;
3382	adap->fe_adap[0].fe->ops.sleep = novatd_sleep_override;
3383
3384	return 0;
3385}
3386
3387/* S5H1411 */
3388static struct s5h1411_config pinnacle_801e_config = {
3389	.output_mode   = S5H1411_PARALLEL_OUTPUT,
3390	.gpio          = S5H1411_GPIO_OFF,
3391	.mpeg_timing   = S5H1411_MPEGTIMING_NONCONTINOUS_NONINVERTING_CLOCK,
3392	.qam_if        = S5H1411_IF_44000,
3393	.vsb_if        = S5H1411_IF_44000,
3394	.inversion     = S5H1411_INVERSION_OFF,
3395	.status_mode   = S5H1411_DEMODLOCKING
3396};
3397
3398/* Pinnacle PCTV HD Pro 801e GPIOs map:
3399   GPIO0  - currently unknown
3400   GPIO1  - xc5000 tuner reset
3401   GPIO2  - CX25843 sleep
3402   GPIO3  - currently unknown
3403   GPIO4  - currently unknown
3404   GPIO6  - currently unknown
3405   GPIO7  - currently unknown
3406   GPIO9  - currently unknown
3407   GPIO10 - CX25843 reset
3408 */
3409static int s5h1411_frontend_attach(struct dvb_usb_adapter *adap)
3410{
3411	struct dib0700_state *st = adap->dev->priv;
3412
3413	/* Make use of the new i2c functions from FW 1.20 */
3414	st->fw_use_new_i2c_api = 1;
3415
3416	/* The s5h1411 requires the dib0700 to not be in master mode */
3417	st->disable_streaming_master_mode = 1;
3418
3419	/* All msleep values taken from Windows USB trace */
3420	dib0700_set_gpio(adap->dev, GPIO0, GPIO_OUT, 0);
3421	dib0700_set_gpio(adap->dev, GPIO3, GPIO_OUT, 0);
3422	dib0700_set_gpio(adap->dev, GPIO6, GPIO_OUT, 1);
3423	msleep(400);
3424	dib0700_set_gpio(adap->dev, GPIO10, GPIO_OUT, 0);
3425	msleep(60);
3426	dib0700_set_gpio(adap->dev, GPIO10, GPIO_OUT, 1);
3427	msleep(30);
3428	dib0700_set_gpio(adap->dev, GPIO0, GPIO_OUT, 1);
3429	dib0700_set_gpio(adap->dev, GPIO9, GPIO_OUT, 1);
3430	dib0700_set_gpio(adap->dev, GPIO4, GPIO_OUT, 1);
3431	dib0700_set_gpio(adap->dev, GPIO7, GPIO_OUT, 1);
3432	dib0700_set_gpio(adap->dev, GPIO2, GPIO_OUT, 0);
3433	msleep(30);
3434
3435	/* Put the CX25843 to sleep for now since we're in digital mode */
3436	dib0700_set_gpio(adap->dev, GPIO2, GPIO_OUT, 1);
3437
3438	/* GPIOs are initialized, do the attach */
3439	adap->fe_adap[0].fe = dvb_attach(s5h1411_attach, &pinnacle_801e_config,
3440			      &adap->dev->i2c_adap);
3441	return adap->fe_adap[0].fe == NULL ? -ENODEV : 0;
3442}
3443
3444static int dib0700_xc5000_tuner_callback(void *priv, int component,
3445					 int command, int arg)
3446{
3447	struct dvb_usb_adapter *adap = priv;
3448
3449	if (command == XC5000_TUNER_RESET) {
3450		/* Reset the tuner */
3451		dib0700_set_gpio(adap->dev, GPIO1, GPIO_OUT, 0);
3452		msleep(10);
3453		dib0700_set_gpio(adap->dev, GPIO1, GPIO_OUT, 1);
3454		msleep(10);
3455	} else {
3456		err("xc5000: unknown tuner callback command: %d\n", command);
3457		return -EINVAL;
3458	}
3459
3460	return 0;
3461}
3462
3463static struct xc5000_config s5h1411_xc5000_tunerconfig = {
3464	.i2c_address      = 0x64,
3465	.if_khz           = 5380,
3466};
3467
3468static int xc5000_tuner_attach(struct dvb_usb_adapter *adap)
3469{
3470	/* FIXME: generalize & move to common area */
3471	adap->fe_adap[0].fe->callback = dib0700_xc5000_tuner_callback;
3472
3473	return dvb_attach(xc5000_attach, adap->fe_adap[0].fe, &adap->dev->i2c_adap,
3474			  &s5h1411_xc5000_tunerconfig)
3475		== NULL ? -ENODEV : 0;
3476}
3477
3478static int dib0700_xc4000_tuner_callback(void *priv, int component,
3479					 int command, int arg)
3480{
3481	struct dvb_usb_adapter *adap = priv;
3482	struct dib0700_adapter_state *state = adap->priv;
3483
3484	if (command == XC4000_TUNER_RESET) {
3485		/* Reset the tuner */
3486		state->dib7000p_ops.set_gpio(adap->fe_adap[0].fe, 8, 0, 0);
3487		msleep(10);
3488		state->dib7000p_ops.set_gpio(adap->fe_adap[0].fe, 8, 0, 1);
3489	} else {
3490		err("xc4000: unknown tuner callback command: %d\n", command);
3491		return -EINVAL;
3492	}
3493
3494	return 0;
3495}
3496
3497static struct dibx000_agc_config stk7700p_7000p_xc4000_agc_config = {
3498	.band_caps = BAND_UHF | BAND_VHF,
3499	.setup = 0x64,
3500	.inv_gain = 0x02c8,
3501	.time_stabiliz = 0x15,
3502	.alpha_level = 0x00,
3503	.thlock = 0x76,
3504	.wbd_inv = 0x01,
3505	.wbd_ref = 0x0b33,
3506	.wbd_sel = 0x00,
3507	.wbd_alpha = 0x02,
3508	.agc1_max = 0x00,
3509	.agc1_min = 0x00,
3510	.agc2_max = 0x9b26,
3511	.agc2_min = 0x26ca,
3512	.agc1_pt1 = 0x00,
3513	.agc1_pt2 = 0x00,
3514	.agc1_pt3 = 0x00,
3515	.agc1_slope1 = 0x00,
3516	.agc1_slope2 = 0x00,
3517	.agc2_pt1 = 0x00,
3518	.agc2_pt2 = 0x80,
3519	.agc2_slope1 = 0x1d,
3520	.agc2_slope2 = 0x1d,
3521	.alpha_mant = 0x11,
3522	.alpha_exp = 0x1b,
3523	.beta_mant = 0x17,
3524	.beta_exp = 0x33,
3525	.perform_agc_softsplit = 0x00,
3526};
3527
3528static struct dibx000_bandwidth_config stk7700p_xc4000_pll_config = {
3529	.internal = 60000,
3530	.sampling = 30000,
3531	.pll_prediv = 1,
3532	.pll_ratio = 8,
3533	.pll_range = 3,
3534	.pll_reset = 1,
3535	.pll_bypass = 0,
3536	.enable_refdiv = 0,
3537	.bypclk_div = 0,
3538	.IO_CLK_en_core = 1,
3539	.ADClkSrc = 1,
3540	.modulo = 0,
3541	.sad_cfg = (3 << 14) | (1 << 12) | 524, /* sad_cfg: refsel, sel, freq_15k */
3542	.ifreq = 39370534,
3543	.timf = 20452225,
3544	.xtal_hz = 30000000
3545};
3546
3547/* FIXME: none of these inputs are validated yet */
3548static struct dib7000p_config pctv_340e_config = {
3549	.output_mpeg2_in_188_bytes = 1,
3550
3551	.agc_config_count = 1,
3552	.agc = &stk7700p_7000p_xc4000_agc_config,
3553	.bw  = &stk7700p_xc4000_pll_config,
3554
3555	.gpio_dir = DIB7000M_GPIO_DEFAULT_DIRECTIONS,
3556	.gpio_val = DIB7000M_GPIO_DEFAULT_VALUES,
3557	.gpio_pwm_pos = DIB7000M_GPIO_DEFAULT_PWM_POS,
3558};
3559
3560/* PCTV 340e GPIOs map:
3561   dib0700:
3562   GPIO2  - CX25843 sleep
3563   GPIO3  - CS5340 reset
3564   GPIO5  - IRD
3565   GPIO6  - Power Supply
3566   GPIO8  - LNA (1=off 0=on)
3567   GPIO10 - CX25843 reset
3568   dib7000:
3569   GPIO8  - xc4000 reset
3570 */
3571static int pctv340e_frontend_attach(struct dvb_usb_adapter *adap)
3572{
3573	struct dib0700_state *st = adap->dev->priv;
3574	struct dib0700_adapter_state *state = adap->priv;
3575
3576	if (!dvb_attach(dib7000p_attach, &state->dib7000p_ops))
3577		return -ENODEV;
3578
3579	/* Power Supply on */
3580	dib0700_set_gpio(adap->dev, GPIO6,  GPIO_OUT, 0);
3581	msleep(50);
3582	dib0700_set_gpio(adap->dev, GPIO6,  GPIO_OUT, 1);
3583	msleep(100); /* Allow power supply to settle before probing */
3584
3585	/* cx25843 reset */
3586	dib0700_set_gpio(adap->dev, GPIO10,  GPIO_OUT, 0);
3587	msleep(1); /* cx25843 datasheet say 350us required */
3588	dib0700_set_gpio(adap->dev, GPIO10,  GPIO_OUT, 1);
3589
3590	/* LNA off for now */
3591	dib0700_set_gpio(adap->dev, GPIO8,  GPIO_OUT, 1);
3592
3593	/* Put the CX25843 to sleep for now since we're in digital mode */
3594	dib0700_set_gpio(adap->dev, GPIO2, GPIO_OUT, 1);
3595
3596	/* FIXME: not verified yet */
3597	dib0700_ctrl_clock(adap->dev, 72, 1);
3598
3599	msleep(500);
3600
3601	if (state->dib7000p_ops.dib7000pc_detection(&adap->dev->i2c_adap) == 0) {
3602		/* Demodulator not found for some reason? */
3603		dvb_detach(&state->dib7000p_ops);
3604		return -ENODEV;
3605	}
3606
3607	adap->fe_adap[0].fe = state->dib7000p_ops.init(&adap->dev->i2c_adap, 0x12,
3608			      &pctv_340e_config);
3609	st->is_dib7000pc = 1;
3610
3611	return adap->fe_adap[0].fe == NULL ? -ENODEV : 0;
3612}
3613
3614static struct xc4000_config dib7000p_xc4000_tunerconfig = {
3615	.i2c_address	  = 0x61,
3616	.default_pm	  = 1,
3617	.dvb_amplitude	  = 0,
3618	.set_smoothedcvbs = 0,
3619	.if_khz		  = 5400
3620};
3621
3622static int xc4000_tuner_attach(struct dvb_usb_adapter *adap)
3623{
3624	struct i2c_adapter *tun_i2c;
3625	struct dib0700_adapter_state *state = adap->priv;
3626
3627	/* The xc4000 is not on the main i2c bus */
3628	tun_i2c = state->dib7000p_ops.get_i2c_master(adap->fe_adap[0].fe,
3629					  DIBX000_I2C_INTERFACE_TUNER, 1);
3630	if (tun_i2c == NULL) {
3631		printk(KERN_ERR "Could not reach tuner i2c bus\n");
3632		return 0;
3633	}
3634
3635	/* Setup the reset callback */
3636	adap->fe_adap[0].fe->callback = dib0700_xc4000_tuner_callback;
3637
3638	return dvb_attach(xc4000_attach, adap->fe_adap[0].fe, tun_i2c,
3639			  &dib7000p_xc4000_tunerconfig)
3640		== NULL ? -ENODEV : 0;
3641}
3642
3643static struct lgdt3305_config hcw_lgdt3305_config = {
3644	.i2c_addr           = 0x0e,
3645	.mpeg_mode          = LGDT3305_MPEG_PARALLEL,
3646	.tpclk_edge         = LGDT3305_TPCLK_FALLING_EDGE,
3647	.tpvalid_polarity   = LGDT3305_TP_VALID_LOW,
3648	.deny_i2c_rptr      = 0,
3649	.spectral_inversion = 1,
3650	.qam_if_khz         = 6000,
3651	.vsb_if_khz         = 6000,
3652	.usref_8vsb         = 0x0500,
3653};
3654
3655static struct mxl5007t_config hcw_mxl5007t_config = {
3656	.xtal_freq_hz = MxL_XTAL_25_MHZ,
3657	.if_freq_hz = MxL_IF_6_MHZ,
3658	.invert_if = 1,
3659};
3660
3661/* TIGER-ATSC map:
3662   GPIO0  - LNA_CTR  (H: LNA power enabled, L: LNA power disabled)
3663   GPIO1  - ANT_SEL  (H: VPA, L: MCX)
3664   GPIO4  - SCL2
3665   GPIO6  - EN_TUNER
3666   GPIO7  - SDA2
3667   GPIO10 - DEM_RST
3668
3669   MXL is behind LG's i2c repeater.  LG is on SCL2/SDA2 gpios on the DIB
3670 */
3671static int lgdt3305_frontend_attach(struct dvb_usb_adapter *adap)
3672{
3673	struct dib0700_state *st = adap->dev->priv;
3674
3675	/* Make use of the new i2c functions from FW 1.20 */
3676	st->fw_use_new_i2c_api = 1;
3677
3678	st->disable_streaming_master_mode = 1;
3679
3680	/* fe power enable */
3681	dib0700_set_gpio(adap->dev, GPIO6, GPIO_OUT, 0);
3682	msleep(30);
3683	dib0700_set_gpio(adap->dev, GPIO6, GPIO_OUT, 1);
3684	msleep(30);
3685
3686	/* demod reset */
3687	dib0700_set_gpio(adap->dev, GPIO10, GPIO_OUT, 1);
3688	msleep(30);
3689	dib0700_set_gpio(adap->dev, GPIO10, GPIO_OUT, 0);
3690	msleep(30);
3691	dib0700_set_gpio(adap->dev, GPIO10, GPIO_OUT, 1);
3692	msleep(30);
3693
3694	adap->fe_adap[0].fe = dvb_attach(lgdt3305_attach,
3695			      &hcw_lgdt3305_config,
3696			      &adap->dev->i2c_adap);
3697
3698	return adap->fe_adap[0].fe == NULL ? -ENODEV : 0;
3699}
3700
3701static int mxl5007t_tuner_attach(struct dvb_usb_adapter *adap)
3702{
3703	return dvb_attach(mxl5007t_attach, adap->fe_adap[0].fe,
3704			  &adap->dev->i2c_adap, 0x60,
3705			  &hcw_mxl5007t_config) == NULL ? -ENODEV : 0;
3706}
3707
3708
3709/* DVB-USB and USB stuff follows */
3710struct usb_device_id dib0700_usb_id_table[] = {
3711/* 0 */	{ USB_DEVICE(USB_VID_DIBCOM,    USB_PID_DIBCOM_STK7700P) },
3712	{ USB_DEVICE(USB_VID_DIBCOM,    USB_PID_DIBCOM_STK7700P_PC) },
3713	{ USB_DEVICE(USB_VID_HAUPPAUGE, USB_PID_HAUPPAUGE_NOVA_T_500) },
3714	{ USB_DEVICE(USB_VID_HAUPPAUGE, USB_PID_HAUPPAUGE_NOVA_T_500_2) },
3715	{ USB_DEVICE(USB_VID_HAUPPAUGE, USB_PID_HAUPPAUGE_NOVA_T_STICK) },
3716/* 5 */	{ USB_DEVICE(USB_VID_AVERMEDIA, USB_PID_AVERMEDIA_VOLAR) },
3717	{ USB_DEVICE(USB_VID_COMPRO,    USB_PID_COMPRO_VIDEOMATE_U500) },
3718	{ USB_DEVICE(USB_VID_UNIWILL,   USB_PID_UNIWILL_STK7700P) },
3719	{ USB_DEVICE(USB_VID_LEADTEK,   USB_PID_WINFAST_DTV_DONGLE_STK7700P) },
3720	{ USB_DEVICE(USB_VID_HAUPPAUGE, USB_PID_HAUPPAUGE_NOVA_T_STICK_2) },
3721/* 10 */{ USB_DEVICE(USB_VID_AVERMEDIA, USB_PID_AVERMEDIA_VOLAR_2) },
3722	{ USB_DEVICE(USB_VID_PINNACLE,  USB_PID_PINNACLE_PCTV2000E) },
3723	{ USB_DEVICE(USB_VID_TERRATEC,
3724			USB_PID_TERRATEC_CINERGY_DT_XS_DIVERSITY) },
3725	{ USB_DEVICE(USB_VID_HAUPPAUGE, USB_PID_HAUPPAUGE_NOVA_TD_STICK) },
3726	{ USB_DEVICE(USB_VID_DIBCOM,    USB_PID_DIBCOM_STK7700D) },
3727/* 15 */{ USB_DEVICE(USB_VID_DIBCOM,    USB_PID_DIBCOM_STK7070P) },
3728	{ USB_DEVICE(USB_VID_PINNACLE,  USB_PID_PINNACLE_PCTV_DVB_T_FLASH) },
3729	{ USB_DEVICE(USB_VID_DIBCOM,    USB_PID_DIBCOM_STK7070PD) },
3730	{ USB_DEVICE(USB_VID_PINNACLE,
3731			USB_PID_PINNACLE_PCTV_DUAL_DIVERSITY_DVB_T) },
3732	{ USB_DEVICE(USB_VID_COMPRO,    USB_PID_COMPRO_VIDEOMATE_U500_PC) },
3733/* 20 */{ USB_DEVICE(USB_VID_AVERMEDIA, USB_PID_AVERMEDIA_EXPRESS) },
3734	{ USB_DEVICE(USB_VID_GIGABYTE,  USB_PID_GIGABYTE_U7000) },
3735	{ USB_DEVICE(USB_VID_ULTIMA_ELECTRONIC, USB_PID_ARTEC_T14BR) },
3736	{ USB_DEVICE(USB_VID_ASUS,      USB_PID_ASUS_U3000) },
3737	{ USB_DEVICE(USB_VID_ASUS,      USB_PID_ASUS_U3100) },
3738/* 25 */{ USB_DEVICE(USB_VID_HAUPPAUGE, USB_PID_HAUPPAUGE_NOVA_T_STICK_3) },
3739	{ USB_DEVICE(USB_VID_HAUPPAUGE, USB_PID_HAUPPAUGE_MYTV_T) },
3740	{ USB_DEVICE(USB_VID_TERRATEC,  USB_PID_TERRATEC_CINERGY_HT_USB_XE) },
3741	{ USB_DEVICE(USB_VID_PINNACLE,	USB_PID_PINNACLE_EXPRESSCARD_320CX) },
3742	{ USB_DEVICE(USB_VID_PINNACLE,	USB_PID_PINNACLE_PCTV72E) },
3743/* 30 */{ USB_DEVICE(USB_VID_PINNACLE,	USB_PID_PINNACLE_PCTV73E) },
3744	{ USB_DEVICE(USB_VID_YUAN,	USB_PID_YUAN_EC372S) },
3745	{ USB_DEVICE(USB_VID_TERRATEC,	USB_PID_TERRATEC_CINERGY_HT_EXPRESS) },
3746	{ USB_DEVICE(USB_VID_TERRATEC,	USB_PID_TERRATEC_CINERGY_T_XXS) },
3747	{ USB_DEVICE(USB_VID_LEADTEK,   USB_PID_WINFAST_DTV_DONGLE_STK7700P_2) },
3748/* 35 */{ USB_DEVICE(USB_VID_HAUPPAUGE, USB_PID_HAUPPAUGE_NOVA_TD_STICK_52009) },
3749	{ USB_DEVICE(USB_VID_HAUPPAUGE, USB_PID_HAUPPAUGE_NOVA_T_500_3) },
3750	{ USB_DEVICE(USB_VID_GIGABYTE,  USB_PID_GIGABYTE_U8000) },
3751	{ USB_DEVICE(USB_VID_YUAN,      USB_PID_YUAN_STK7700PH) },
3752	{ USB_DEVICE(USB_VID_ASUS,	USB_PID_ASUS_U3000H) },
3753/* 40 */{ USB_DEVICE(USB_VID_PINNACLE,  USB_PID_PINNACLE_PCTV801E) },
3754	{ USB_DEVICE(USB_VID_PINNACLE,  USB_PID_PINNACLE_PCTV801E_SE) },
3755	{ USB_DEVICE(USB_VID_TERRATEC,	USB_PID_TERRATEC_CINERGY_T_EXPRESS) },
3756	{ USB_DEVICE(USB_VID_TERRATEC,
3757			USB_PID_TERRATEC_CINERGY_DT_XS_DIVERSITY_2) },
3758	{ USB_DEVICE(USB_VID_SONY,	USB_PID_SONY_PLAYTV) },
3759/* 45 */{ USB_DEVICE(USB_VID_YUAN,      USB_PID_YUAN_PD378S) },
3760	{ USB_DEVICE(USB_VID_HAUPPAUGE, USB_PID_HAUPPAUGE_TIGER_ATSC) },
3761	{ USB_DEVICE(USB_VID_HAUPPAUGE, USB_PID_HAUPPAUGE_TIGER_ATSC_B210) },
3762	{ USB_DEVICE(USB_VID_YUAN,	USB_PID_YUAN_MC770) },
3763	{ USB_DEVICE(USB_VID_ELGATO,	USB_PID_ELGATO_EYETV_DTT) },
3764/* 50 */{ USB_DEVICE(USB_VID_ELGATO,	USB_PID_ELGATO_EYETV_DTT_Dlx) },
3765	{ USB_DEVICE(USB_VID_LEADTEK,   USB_PID_WINFAST_DTV_DONGLE_H) },
3766	{ USB_DEVICE(USB_VID_TERRATEC,	USB_PID_TERRATEC_T3) },
3767	{ USB_DEVICE(USB_VID_TERRATEC,	USB_PID_TERRATEC_T5) },
3768	{ USB_DEVICE(USB_VID_YUAN,      USB_PID_YUAN_STK7700D) },
3769/* 55 */{ USB_DEVICE(USB_VID_YUAN,	USB_PID_YUAN_STK7700D_2) },
3770	{ USB_DEVICE(USB_VID_PINNACLE,	USB_PID_PINNACLE_PCTV73A) },
3771	{ USB_DEVICE(USB_VID_PCTV,	USB_PID_PINNACLE_PCTV73ESE) },
3772	{ USB_DEVICE(USB_VID_PCTV,	USB_PID_PINNACLE_PCTV282E) },
3773	{ USB_DEVICE(USB_VID_DIBCOM,	USB_PID_DIBCOM_STK7770P) },
3774/* 60 */{ USB_DEVICE(USB_VID_TERRATEC,	USB_PID_TERRATEC_CINERGY_T_XXS_2) },
3775	{ USB_DEVICE(USB_VID_DIBCOM,    USB_PID_DIBCOM_STK807XPVR) },
3776	{ USB_DEVICE(USB_VID_DIBCOM,    USB_PID_DIBCOM_STK807XP) },
3777	{ USB_DEVICE_VER(USB_VID_PIXELVIEW, USB_PID_PIXELVIEW_SBTVD, 0x000, 0x3f00) },
3778	{ USB_DEVICE(USB_VID_EVOLUTEPC, USB_PID_TVWAY_PLUS) },
3779/* 65 */{ USB_DEVICE(USB_VID_PINNACLE,	USB_PID_PINNACLE_PCTV73ESE) },
3780	{ USB_DEVICE(USB_VID_PINNACLE,	USB_PID_PINNACLE_PCTV282E) },
3781	{ USB_DEVICE(USB_VID_DIBCOM,    USB_PID_DIBCOM_STK8096GP) },
3782	{ USB_DEVICE(USB_VID_ELGATO,    USB_PID_ELGATO_EYETV_DIVERSITY) },
3783	{ USB_DEVICE(USB_VID_DIBCOM,    USB_PID_DIBCOM_NIM9090M) },
3784/* 70 */{ USB_DEVICE(USB_VID_DIBCOM,    USB_PID_DIBCOM_NIM8096MD) },
3785	{ USB_DEVICE(USB_VID_DIBCOM,    USB_PID_DIBCOM_NIM9090MD) },
3786	{ USB_DEVICE(USB_VID_DIBCOM,    USB_PID_DIBCOM_NIM7090) },
3787	{ USB_DEVICE(USB_VID_DIBCOM,    USB_PID_DIBCOM_TFE7090PVR) },
3788	{ USB_DEVICE(USB_VID_TECHNISAT, USB_PID_TECHNISAT_AIRSTAR_TELESTICK_2) },
3789/* 75 */{ USB_DEVICE(USB_VID_MEDION,    USB_PID_CREATIX_CTX1921) },
3790	{ USB_DEVICE(USB_VID_PINNACLE,  USB_PID_PINNACLE_PCTV340E) },
3791	{ USB_DEVICE(USB_VID_PINNACLE,  USB_PID_PINNACLE_PCTV340E_SE) },
3792	{ USB_DEVICE(USB_VID_DIBCOM,    USB_PID_DIBCOM_TFE7790P) },
3793	{ USB_DEVICE(USB_VID_DIBCOM,    USB_PID_DIBCOM_TFE8096P) },
3794/* 80 */{ USB_DEVICE(USB_VID_ELGATO,	USB_PID_ELGATO_EYETV_DTT_2) },
3795	{ USB_DEVICE(USB_VID_PCTV,      USB_PID_PCTV_2002E) },
3796	{ USB_DEVICE(USB_VID_PCTV,      USB_PID_PCTV_2002E_SE) },
3797	{ 0 }		/* Terminating entry */
3798};
3799MODULE_DEVICE_TABLE(usb, dib0700_usb_id_table);
3800
3801#define DIB0700_DEFAULT_DEVICE_PROPERTIES \
3802	.caps              = DVB_USB_IS_AN_I2C_ADAPTER, \
3803	.usb_ctrl          = DEVICE_SPECIFIC, \
3804	.firmware          = "dvb-usb-dib0700-1.20.fw", \
3805	.download_firmware = dib0700_download_firmware, \
3806	.no_reconnect      = 1, \
3807	.size_of_priv      = sizeof(struct dib0700_state), \
3808	.i2c_algo          = &dib0700_i2c_algo, \
3809	.identify_state    = dib0700_identify_state
3810
3811#define DIB0700_DEFAULT_STREAMING_CONFIG(ep) \
3812	.streaming_ctrl   = dib0700_streaming_ctrl, \
3813	.stream = { \
3814		.type = USB_BULK, \
3815		.count = 4, \
3816		.endpoint = ep, \
3817		.u = { \
3818			.bulk = { \
3819				.buffersize = 39480, \
3820			} \
3821		} \
3822	}
3823
3824struct dvb_usb_device_properties dib0700_devices[] = {
3825	{
3826		DIB0700_DEFAULT_DEVICE_PROPERTIES,
3827
3828		.num_adapters = 1,
3829		.adapter = {
3830			{
3831			.num_frontends = 1,
3832			.fe = {{
3833				.caps = DVB_USB_ADAP_HAS_PID_FILTER | DVB_USB_ADAP_PID_FILTER_CAN_BE_TURNED_OFF,
3834				.pid_filter_count = 32,
3835				.pid_filter       = stk7700p_pid_filter,
3836				.pid_filter_ctrl  = stk7700p_pid_filter_ctrl,
3837				.frontend_attach  = stk7700p_frontend_attach,
3838				.tuner_attach     = stk7700p_tuner_attach,
3839
3840				DIB0700_DEFAULT_STREAMING_CONFIG(0x02),
3841			}},
3842				.size_of_priv     = sizeof(struct dib0700_adapter_state),
3843			},
3844		},
3845
3846		.num_device_descs = 8,
3847		.devices = {
3848			{   "DiBcom STK7700P reference design",
3849				{ &dib0700_usb_id_table[0], &dib0700_usb_id_table[1] },
3850				{ NULL },
3851			},
3852			{   "Hauppauge Nova-T Stick",
3853				{ &dib0700_usb_id_table[4], &dib0700_usb_id_table[9], NULL },
3854				{ NULL },
3855			},
3856			{   "AVerMedia AVerTV DVB-T Volar",
3857				{ &dib0700_usb_id_table[5], &dib0700_usb_id_table[10] },
3858				{ NULL },
3859			},
3860			{   "Compro Videomate U500",
3861				{ &dib0700_usb_id_table[6], &dib0700_usb_id_table[19] },
3862				{ NULL },
3863			},
3864			{   "Uniwill STK7700P based (Hama and others)",
3865				{ &dib0700_usb_id_table[7], NULL },
3866				{ NULL },
3867			},
3868			{   "Leadtek Winfast DTV Dongle (STK7700P based)",
3869				{ &dib0700_usb_id_table[8], &dib0700_usb_id_table[34] },
3870				{ NULL },
3871			},
3872			{   "AVerMedia AVerTV DVB-T Express",
3873				{ &dib0700_usb_id_table[20] },
3874				{ NULL },
3875			},
3876			{   "Gigabyte U7000",
3877				{ &dib0700_usb_id_table[21], NULL },
3878				{ NULL },
3879			}
3880		},
3881
3882		.rc.core = {
3883			.rc_interval      = DEFAULT_RC_INTERVAL,
3884			.rc_codes         = RC_MAP_DIB0700_RC5_TABLE,
3885			.rc_query         = dib0700_rc_query_old_firmware,
3886			.allowed_protos   = RC_BIT_RC5 |
3887					    RC_BIT_RC6_MCE |
3888					    RC_BIT_NEC,
3889			.change_protocol  = dib0700_change_protocol,
3890		},
3891	}, { DIB0700_DEFAULT_DEVICE_PROPERTIES,
3892
3893		.num_adapters = 2,
3894		.adapter = {
3895			{
3896			.num_frontends = 1,
3897			.fe = {{
3898				.frontend_attach  = bristol_frontend_attach,
3899				.tuner_attach     = bristol_tuner_attach,
3900
3901				DIB0700_DEFAULT_STREAMING_CONFIG(0x02),
3902			}},
3903			}, {
3904			.num_frontends = 1,
3905			.fe = {{
3906				.frontend_attach  = bristol_frontend_attach,
3907				.tuner_attach     = bristol_tuner_attach,
3908
3909				DIB0700_DEFAULT_STREAMING_CONFIG(0x03),
3910			}},
3911			}
3912		},
3913
3914		.num_device_descs = 1,
3915		.devices = {
3916			{   "Hauppauge Nova-T 500 Dual DVB-T",
3917				{ &dib0700_usb_id_table[2], &dib0700_usb_id_table[3], NULL },
3918				{ NULL },
3919			},
3920		},
3921
3922		.rc.core = {
3923			.rc_interval      = DEFAULT_RC_INTERVAL,
3924			.rc_codes         = RC_MAP_DIB0700_RC5_TABLE,
3925			.rc_query         = dib0700_rc_query_old_firmware,
3926			.allowed_protos   = RC_BIT_RC5 |
3927					    RC_BIT_RC6_MCE |
3928					    RC_BIT_NEC,
3929			.change_protocol = dib0700_change_protocol,
3930		},
3931	}, { DIB0700_DEFAULT_DEVICE_PROPERTIES,
3932
3933		.num_adapters = 2,
3934		.adapter = {
3935			{
3936			.num_frontends = 1,
3937			.fe = {{
3938				.caps = DVB_USB_ADAP_HAS_PID_FILTER | DVB_USB_ADAP_PID_FILTER_CAN_BE_TURNED_OFF,
3939				.pid_filter_count = 32,
3940				.pid_filter       = stk70x0p_pid_filter,
3941				.pid_filter_ctrl  = stk70x0p_pid_filter_ctrl,
3942				.frontend_attach  = stk7700d_frontend_attach,
3943				.tuner_attach     = stk7700d_tuner_attach,
3944
3945				DIB0700_DEFAULT_STREAMING_CONFIG(0x02),
3946			}},
3947				.size_of_priv = sizeof(struct
3948						dib0700_adapter_state),
3949			}, {
3950			.num_frontends = 1,
3951			.fe = {{
3952				.caps = DVB_USB_ADAP_HAS_PID_FILTER | DVB_USB_ADAP_PID_FILTER_CAN_BE_TURNED_OFF,
3953				.pid_filter_count = 32,
3954				.pid_filter       = stk70x0p_pid_filter,
3955				.pid_filter_ctrl  = stk70x0p_pid_filter_ctrl,
3956				.frontend_attach  = stk7700d_frontend_attach,
3957				.tuner_attach     = stk7700d_tuner_attach,
3958
3959				DIB0700_DEFAULT_STREAMING_CONFIG(0x03),
3960			}},
3961				.size_of_priv = sizeof(struct
3962						dib0700_adapter_state),
3963			}
3964		},
3965
3966		.num_device_descs = 5,
3967		.devices = {
3968			{   "Pinnacle PCTV 2000e",
3969				{ &dib0700_usb_id_table[11], NULL },
3970				{ NULL },
3971			},
3972			{   "Terratec Cinergy DT XS Diversity",
3973				{ &dib0700_usb_id_table[12], NULL },
3974				{ NULL },
3975			},
3976			{   "Hauppauge Nova-TD Stick/Elgato Eye-TV Diversity",
3977				{ &dib0700_usb_id_table[13], NULL },
3978				{ NULL },
3979			},
3980			{   "DiBcom STK7700D reference design",
3981				{ &dib0700_usb_id_table[14], NULL },
3982				{ NULL },
3983			},
3984			{   "YUAN High-Tech DiBcom STK7700D",
3985				{ &dib0700_usb_id_table[55], NULL },
3986				{ NULL },
3987			},
3988
3989		},
3990
3991		.rc.core = {
3992			.rc_interval      = DEFAULT_RC_INTERVAL,
3993			.rc_codes         = RC_MAP_DIB0700_RC5_TABLE,
3994			.rc_query         = dib0700_rc_query_old_firmware,
3995			.allowed_protos   = RC_BIT_RC5 |
3996					    RC_BIT_RC6_MCE |
3997					    RC_BIT_NEC,
3998			.change_protocol = dib0700_change_protocol,
3999		},
4000	}, { DIB0700_DEFAULT_DEVICE_PROPERTIES,
4001
4002		.num_adapters = 1,
4003		.adapter = {
4004			{
4005			.num_frontends = 1,
4006			.fe = {{
4007				.caps = DVB_USB_ADAP_HAS_PID_FILTER | DVB_USB_ADAP_PID_FILTER_CAN_BE_TURNED_OFF,
4008				.pid_filter_count = 32,
4009				.pid_filter       = stk70x0p_pid_filter,
4010				.pid_filter_ctrl  = stk70x0p_pid_filter_ctrl,
4011				.frontend_attach  = stk7700P2_frontend_attach,
4012				.tuner_attach     = stk7700d_tuner_attach,
4013
4014				DIB0700_DEFAULT_STREAMING_CONFIG(0x02),
4015			}},
4016				.size_of_priv = sizeof(struct
4017						dib0700_adapter_state),
4018			},
4019		},
4020
4021		.num_device_descs = 3,
4022		.devices = {
4023			{   "ASUS My Cinema U3000 Mini DVBT Tuner",
4024				{ &dib0700_usb_id_table[23], NULL },
4025				{ NULL },
4026			},
4027			{   "Yuan EC372S",
4028				{ &dib0700_usb_id_table[31], NULL },
4029				{ NULL },
4030			},
4031			{   "Terratec Cinergy T Express",
4032				{ &dib0700_usb_id_table[42], NULL },
4033				{ NULL },
4034			}
4035		},
4036
4037		.rc.core = {
4038			.rc_interval      = DEFAULT_RC_INTERVAL,
4039			.rc_codes         = RC_MAP_DIB0700_RC5_TABLE,
4040			.module_name	  = "dib0700",
4041			.rc_query         = dib0700_rc_query_old_firmware,
4042			.allowed_protos   = RC_BIT_RC5 |
4043					    RC_BIT_RC6_MCE |
4044					    RC_BIT_NEC,
4045			.change_protocol = dib0700_change_protocol,
4046		},
4047	}, { DIB0700_DEFAULT_DEVICE_PROPERTIES,
4048
4049		.num_adapters = 1,
4050		.adapter = {
4051			{
4052			.num_frontends = 1,
4053			.fe = {{
4054				.caps = DVB_USB_ADAP_HAS_PID_FILTER | DVB_USB_ADAP_PID_FILTER_CAN_BE_TURNED_OFF,
4055				.pid_filter_count = 32,
4056				.pid_filter       = stk70x0p_pid_filter,
4057				.pid_filter_ctrl  = stk70x0p_pid_filter_ctrl,
4058				.frontend_attach  = stk7070p_frontend_attach,
4059				.tuner_attach     = dib7070p_tuner_attach,
4060
4061				DIB0700_DEFAULT_STREAMING_CONFIG(0x02),
4062			}},
4063				.size_of_priv     = sizeof(struct dib0700_adapter_state),
4064			},
4065		},
4066
4067		.num_device_descs = 12,
4068		.devices = {
4069			{   "DiBcom STK7070P reference design",
4070				{ &dib0700_usb_id_table[15], NULL },
4071				{ NULL },
4072			},
4073			{   "Pinnacle PCTV DVB-T Flash Stick",
4074				{ &dib0700_usb_id_table[16], NULL },
4075				{ NULL },
4076			},
4077			{   "Artec T14BR DVB-T",
4078				{ &dib0700_usb_id_table[22], NULL },
4079				{ NULL },
4080			},
4081			{   "ASUS My Cinema U3100 Mini DVBT Tuner",
4082				{ &dib0700_usb_id_table[24], NULL },
4083				{ NULL },
4084			},
4085			{   "Hauppauge Nova-T Stick",
4086				{ &dib0700_usb_id_table[25], NULL },
4087				{ NULL },
4088			},
4089			{   "Hauppauge Nova-T MyTV.t",
4090				{ &dib0700_usb_id_table[26], NULL },
4091				{ NULL },
4092			},
4093			{   "Pinnacle PCTV 72e",
4094				{ &dib0700_usb_id_table[29], NULL },
4095				{ NULL },
4096			},
4097			{   "Pinnacle PCTV 73e",
4098				{ &dib0700_usb_id_table[30], NULL },
4099				{ NULL },
4100			},
4101			{   "Elgato EyeTV DTT",
4102				{ &dib0700_usb_id_table[49], NULL },
4103				{ NULL },
4104			},
4105			{   "Yuan PD378S",
4106				{ &dib0700_usb_id_table[45], NULL },
4107				{ NULL },
4108			},
4109			{   "Elgato EyeTV Dtt Dlx PD378S",
4110				{ &dib0700_usb_id_table[50], NULL },
4111				{ NULL },
4112			},
4113			{   "Elgato EyeTV DTT rev. 2",
4114				{ &dib0700_usb_id_table[80], NULL },
4115				{ NULL },
4116			},
4117		},
4118
4119		.rc.core = {
4120			.rc_interval      = DEFAULT_RC_INTERVAL,
4121			.rc_codes         = RC_MAP_DIB0700_RC5_TABLE,
4122			.module_name	  = "dib0700",
4123			.rc_query         = dib0700_rc_query_old_firmware,
4124			.allowed_protos   = RC_BIT_RC5 |
4125					    RC_BIT_RC6_MCE |
4126					    RC_BIT_NEC,
4127			.change_protocol  = dib0700_change_protocol,
4128		},
4129	}, { DIB0700_DEFAULT_DEVICE_PROPERTIES,
4130
4131		.num_adapters = 1,
4132		.adapter = {
4133			{
4134			.num_frontends = 1,
4135			.fe = {{
4136				.caps = DVB_USB_ADAP_HAS_PID_FILTER | DVB_USB_ADAP_PID_FILTER_CAN_BE_TURNED_OFF,
4137				.pid_filter_count = 32,
4138				.pid_filter       = stk70x0p_pid_filter,
4139				.pid_filter_ctrl  = stk70x0p_pid_filter_ctrl,
4140				.frontend_attach  = stk7070p_frontend_attach,
4141				.tuner_attach     = dib7070p_tuner_attach,
4142
4143				DIB0700_DEFAULT_STREAMING_CONFIG(0x02),
4144			}},
4145				.size_of_priv     = sizeof(struct dib0700_adapter_state),
4146			},
4147		},
4148
4149		.num_device_descs = 3,
4150		.devices = {
4151			{   "Pinnacle PCTV 73A",
4152				{ &dib0700_usb_id_table[56], NULL },
4153				{ NULL },
4154			},
4155			{   "Pinnacle PCTV 73e SE",
4156				{ &dib0700_usb_id_table[57], &dib0700_usb_id_table[65], NULL },
4157				{ NULL },
4158			},
4159			{   "Pinnacle PCTV 282e",
4160				{ &dib0700_usb_id_table[58], &dib0700_usb_id_table[66], NULL },
4161				{ NULL },
4162			},
4163		},
4164
4165		.rc.core = {
4166			.rc_interval      = DEFAULT_RC_INTERVAL,
4167			.rc_codes         = RC_MAP_DIB0700_RC5_TABLE,
4168			.module_name	  = "dib0700",
4169			.rc_query         = dib0700_rc_query_old_firmware,
4170			.allowed_protos   = RC_BIT_RC5 |
4171					    RC_BIT_RC6_MCE |
4172					    RC_BIT_NEC,
4173			.change_protocol  = dib0700_change_protocol,
4174		},
4175	}, { DIB0700_DEFAULT_DEVICE_PROPERTIES,
4176
4177		.num_adapters = 2,
4178		.adapter = {
4179			{
4180			.num_frontends = 1,
4181			.fe = {{
4182				.caps = DVB_USB_ADAP_HAS_PID_FILTER | DVB_USB_ADAP_PID_FILTER_CAN_BE_TURNED_OFF,
4183				.pid_filter_count = 32,
4184				.pid_filter       = stk70x0p_pid_filter,
4185				.pid_filter_ctrl  = stk70x0p_pid_filter_ctrl,
4186				.frontend_attach  = novatd_frontend_attach,
4187				.tuner_attach     = dib7070p_tuner_attach,
4188
4189				DIB0700_DEFAULT_STREAMING_CONFIG(0x02),
4190			}},
4191				.size_of_priv     = sizeof(struct dib0700_adapter_state),
4192			}, {
4193			.num_frontends = 1,
4194			.fe = {{
4195				.caps = DVB_USB_ADAP_HAS_PID_FILTER | DVB_USB_ADAP_PID_FILTER_CAN_BE_TURNED_OFF,
4196				.pid_filter_count = 32,
4197				.pid_filter       = stk70x0p_pid_filter,
4198				.pid_filter_ctrl  = stk70x0p_pid_filter_ctrl,
4199				.frontend_attach  = novatd_frontend_attach,
4200				.tuner_attach     = dib7070p_tuner_attach,
4201
4202				DIB0700_DEFAULT_STREAMING_CONFIG(0x03),
4203			}},
4204				.size_of_priv     = sizeof(struct dib0700_adapter_state),
4205			}
4206		},
4207
4208		.num_device_descs = 3,
4209		.devices = {
4210			{   "Hauppauge Nova-TD Stick (52009)",
4211				{ &dib0700_usb_id_table[35], NULL },
4212				{ NULL },
4213			},
4214			{   "PCTV 2002e",
4215				{ &dib0700_usb_id_table[81], NULL },
4216				{ NULL },
4217			},
4218			{   "PCTV 2002e SE",
4219				{ &dib0700_usb_id_table[82], NULL },
4220				{ NULL },
4221			},
4222		},
4223
4224		.rc.core = {
4225			.rc_interval      = DEFAULT_RC_INTERVAL,
4226			.rc_codes         = RC_MAP_DIB0700_RC5_TABLE,
4227			.module_name	  = "dib0700",
4228			.rc_query         = dib0700_rc_query_old_firmware,
4229			.allowed_protos   = RC_BIT_RC5 |
4230					    RC_BIT_RC6_MCE |
4231					    RC_BIT_NEC,
4232			.change_protocol = dib0700_change_protocol,
4233		},
4234	}, { DIB0700_DEFAULT_DEVICE_PROPERTIES,
4235
4236		.num_adapters = 2,
4237		.adapter = {
4238			{
4239			.num_frontends = 1,
4240			.fe = {{
4241				.caps = DVB_USB_ADAP_HAS_PID_FILTER | DVB_USB_ADAP_PID_FILTER_CAN_BE_TURNED_OFF,
4242				.pid_filter_count = 32,
4243				.pid_filter       = stk70x0p_pid_filter,
4244				.pid_filter_ctrl  = stk70x0p_pid_filter_ctrl,
4245				.frontend_attach  = stk7070pd_frontend_attach0,
4246				.tuner_attach     = dib7070p_tuner_attach,
4247
4248				DIB0700_DEFAULT_STREAMING_CONFIG(0x02),
4249			}},
4250				.size_of_priv     = sizeof(struct dib0700_adapter_state),
4251			}, {
4252			.num_frontends = 1,
4253			.fe = {{
4254				.caps = DVB_USB_ADAP_HAS_PID_FILTER | DVB_USB_ADAP_PID_FILTER_CAN_BE_TURNED_OFF,
4255				.pid_filter_count = 32,
4256				.pid_filter       = stk70x0p_pid_filter,
4257				.pid_filter_ctrl  = stk70x0p_pid_filter_ctrl,
4258				.frontend_attach  = stk7070pd_frontend_attach1,
4259				.tuner_attach     = dib7070p_tuner_attach,
4260
4261				DIB0700_DEFAULT_STREAMING_CONFIG(0x03),
4262			}},
4263				.size_of_priv     = sizeof(struct dib0700_adapter_state),
4264			}
4265		},
4266
4267		.num_device_descs = 5,
4268		.devices = {
4269			{   "DiBcom STK7070PD reference design",
4270				{ &dib0700_usb_id_table[17], NULL },
4271				{ NULL },
4272			},
4273			{   "Pinnacle PCTV Dual DVB-T Diversity Stick",
4274				{ &dib0700_usb_id_table[18], NULL },
4275				{ NULL },
4276			},
4277			{   "Hauppauge Nova-TD-500 (84xxx)",
4278				{ &dib0700_usb_id_table[36], NULL },
4279				{ NULL },
4280			},
4281			{  "Terratec Cinergy DT USB XS Diversity/ T5",
4282				{ &dib0700_usb_id_table[43],
4283					&dib0700_usb_id_table[53], NULL},
4284				{ NULL },
4285			},
4286			{  "Sony PlayTV",
4287				{ &dib0700_usb_id_table[44], NULL },
4288				{ NULL },
4289			},
4290		},
4291
4292		.rc.core = {
4293			.rc_interval      = DEFAULT_RC_INTERVAL,
4294			.rc_codes         = RC_MAP_DIB0700_RC5_TABLE,
4295			.module_name	  = "dib0700",
4296			.rc_query         = dib0700_rc_query_old_firmware,
4297			.allowed_protos   = RC_BIT_RC5 |
4298					    RC_BIT_RC6_MCE |
4299					    RC_BIT_NEC,
4300			.change_protocol = dib0700_change_protocol,
4301		},
4302	}, { DIB0700_DEFAULT_DEVICE_PROPERTIES,
4303
4304		.num_adapters = 2,
4305		.adapter = {
4306			{
4307			.num_frontends = 1,
4308			.fe = {{
4309				.caps = DVB_USB_ADAP_HAS_PID_FILTER | DVB_USB_ADAP_PID_FILTER_CAN_BE_TURNED_OFF,
4310				.pid_filter_count = 32,
4311				.pid_filter       = stk70x0p_pid_filter,
4312				.pid_filter_ctrl  = stk70x0p_pid_filter_ctrl,
4313				.frontend_attach  = stk7070pd_frontend_attach0,
4314				.tuner_attach     = dib7070p_tuner_attach,
4315
4316				DIB0700_DEFAULT_STREAMING_CONFIG(0x02),
4317			}},
4318				.size_of_priv     = sizeof(struct dib0700_adapter_state),
4319			}, {
4320			.num_frontends = 1,
4321			.fe = {{
4322				.caps = DVB_USB_ADAP_HAS_PID_FILTER | DVB_USB_ADAP_PID_FILTER_CAN_BE_TURNED_OFF,
4323				.pid_filter_count = 32,
4324				.pid_filter       = stk70x0p_pid_filter,
4325				.pid_filter_ctrl  = stk70x0p_pid_filter_ctrl,
4326				.frontend_attach  = stk7070pd_frontend_attach1,
4327				.tuner_attach     = dib7070p_tuner_attach,
4328
4329				DIB0700_DEFAULT_STREAMING_CONFIG(0x03),
4330			}},
4331				.size_of_priv     = sizeof(struct dib0700_adapter_state),
4332			}
4333		},
4334
4335		.num_device_descs = 1,
4336		.devices = {
4337			{   "Elgato EyeTV Diversity",
4338				{ &dib0700_usb_id_table[68], NULL },
4339				{ NULL },
4340			},
4341		},
4342
4343		.rc.core = {
4344			.rc_interval      = DEFAULT_RC_INTERVAL,
4345			.rc_codes         = RC_MAP_DIB0700_NEC_TABLE,
4346			.module_name	  = "dib0700",
4347			.rc_query         = dib0700_rc_query_old_firmware,
4348			.allowed_protos   = RC_BIT_RC5 |
4349					    RC_BIT_RC6_MCE |
4350					    RC_BIT_NEC,
4351			.change_protocol  = dib0700_change_protocol,
4352		},
4353	}, { DIB0700_DEFAULT_DEVICE_PROPERTIES,
4354
4355		.num_adapters = 1,
4356		.adapter = {
4357			{
4358			.num_frontends = 1,
4359			.fe = {{
4360				.caps = DVB_USB_ADAP_HAS_PID_FILTER | DVB_USB_ADAP_PID_FILTER_CAN_BE_TURNED_OFF,
4361				.pid_filter_count = 32,
4362				.pid_filter       = stk70x0p_pid_filter,
4363				.pid_filter_ctrl  = stk70x0p_pid_filter_ctrl,
4364				.frontend_attach  = stk7700ph_frontend_attach,
4365				.tuner_attach     = stk7700ph_tuner_attach,
4366
4367				DIB0700_DEFAULT_STREAMING_CONFIG(0x02),
4368			}},
4369				.size_of_priv = sizeof(struct
4370						dib0700_adapter_state),
4371			},
4372		},
4373
4374		.num_device_descs = 9,
4375		.devices = {
4376			{   "Terratec Cinergy HT USB XE",
4377				{ &dib0700_usb_id_table[27], NULL },
4378				{ NULL },
4379			},
4380			{   "Pinnacle Expresscard 320cx",
4381				{ &dib0700_usb_id_table[28], NULL },
4382				{ NULL },
4383			},
4384			{   "Terratec Cinergy HT Express",
4385				{ &dib0700_usb_id_table[32], NULL },
4386				{ NULL },
4387			},
4388			{   "Gigabyte U8000-RH",
4389				{ &dib0700_usb_id_table[37], NULL },
4390				{ NULL },
4391			},
4392			{   "YUAN High-Tech STK7700PH",
4393				{ &dib0700_usb_id_table[38], NULL },
4394				{ NULL },
4395			},
4396			{   "Asus My Cinema-U3000Hybrid",
4397				{ &dib0700_usb_id_table[39], NULL },
4398				{ NULL },
4399			},
4400			{   "YUAN High-Tech MC770",
4401				{ &dib0700_usb_id_table[48], NULL },
4402				{ NULL },
4403			},
4404			{   "Leadtek WinFast DTV Dongle H",
4405				{ &dib0700_usb_id_table[51], NULL },
4406				{ NULL },
4407			},
4408			{   "YUAN High-Tech STK7700D",
4409				{ &dib0700_usb_id_table[54], NULL },
4410				{ NULL },
4411			},
4412		},
4413
4414		.rc.core = {
4415			.rc_interval      = DEFAULT_RC_INTERVAL,
4416			.rc_codes         = RC_MAP_DIB0700_RC5_TABLE,
4417			.module_name	  = "dib0700",
4418			.rc_query         = dib0700_rc_query_old_firmware,
4419			.allowed_protos   = RC_BIT_RC5 |
4420					    RC_BIT_RC6_MCE |
4421					    RC_BIT_NEC,
4422			.change_protocol  = dib0700_change_protocol,
4423		},
4424	}, { DIB0700_DEFAULT_DEVICE_PROPERTIES,
4425		.num_adapters = 1,
4426		.adapter = {
4427			{
4428			.num_frontends = 1,
4429			.fe = {{
4430				.frontend_attach  = s5h1411_frontend_attach,
4431				.tuner_attach     = xc5000_tuner_attach,
4432
4433				DIB0700_DEFAULT_STREAMING_CONFIG(0x02),
4434			}},
4435				.size_of_priv = sizeof(struct
4436						dib0700_adapter_state),
4437			},
4438		},
4439
4440		.num_device_descs = 2,
4441		.devices = {
4442			{   "Pinnacle PCTV HD Pro USB Stick",
4443				{ &dib0700_usb_id_table[40], NULL },
4444				{ NULL },
4445			},
4446			{   "Pinnacle PCTV HD USB Stick",
4447				{ &dib0700_usb_id_table[41], NULL },
4448				{ NULL },
4449			},
4450		},
4451
4452		.rc.core = {
4453			.rc_interval      = DEFAULT_RC_INTERVAL,
4454			.rc_codes         = RC_MAP_DIB0700_RC5_TABLE,
4455			.module_name	  = "dib0700",
4456			.rc_query         = dib0700_rc_query_old_firmware,
4457			.allowed_protos   = RC_BIT_RC5 |
4458					    RC_BIT_RC6_MCE |
4459					    RC_BIT_NEC,
4460			.change_protocol  = dib0700_change_protocol,
4461		},
4462	}, { DIB0700_DEFAULT_DEVICE_PROPERTIES,
4463		.num_adapters = 1,
4464		.adapter = {
4465			{
4466			.num_frontends = 1,
4467			.fe = {{
4468				.frontend_attach  = lgdt3305_frontend_attach,
4469				.tuner_attach     = mxl5007t_tuner_attach,
4470
4471				DIB0700_DEFAULT_STREAMING_CONFIG(0x02),
4472			}},
4473				.size_of_priv = sizeof(struct
4474						dib0700_adapter_state),
4475			},
4476		},
4477
4478		.num_device_descs = 2,
4479		.devices = {
4480			{   "Hauppauge ATSC MiniCard (B200)",
4481				{ &dib0700_usb_id_table[46], NULL },
4482				{ NULL },
4483			},
4484			{   "Hauppauge ATSC MiniCard (B210)",
4485				{ &dib0700_usb_id_table[47], NULL },
4486				{ NULL },
4487			},
4488		},
4489	}, { DIB0700_DEFAULT_DEVICE_PROPERTIES,
4490
4491		.num_adapters = 1,
4492		.adapter = {
4493			{
4494			.num_frontends = 1,
4495			.fe = {{
4496				.caps = DVB_USB_ADAP_HAS_PID_FILTER | DVB_USB_ADAP_PID_FILTER_CAN_BE_TURNED_OFF,
4497				.pid_filter_count = 32,
4498				.pid_filter       = stk70x0p_pid_filter,
4499				.pid_filter_ctrl  = stk70x0p_pid_filter_ctrl,
4500				.frontend_attach  = stk7770p_frontend_attach,
4501				.tuner_attach     = dib7770p_tuner_attach,
4502
4503				DIB0700_DEFAULT_STREAMING_CONFIG(0x02),
4504			}},
4505				.size_of_priv =
4506					sizeof(struct dib0700_adapter_state),
4507			},
4508		},
4509
4510		.num_device_descs = 4,
4511		.devices = {
4512			{   "DiBcom STK7770P reference design",
4513				{ &dib0700_usb_id_table[59], NULL },
4514				{ NULL },
4515			},
4516			{   "Terratec Cinergy T USB XXS (HD)/ T3",
4517				{ &dib0700_usb_id_table[33],
4518					&dib0700_usb_id_table[52],
4519					&dib0700_usb_id_table[60], NULL},
4520				{ NULL },
4521			},
4522			{   "TechniSat AirStar TeleStick 2",
4523				{ &dib0700_usb_id_table[74], NULL },
4524				{ NULL },
4525			},
4526			{   "Medion CTX1921 DVB-T USB",
4527				{ &dib0700_usb_id_table[75], NULL },
4528				{ NULL },
4529			},
4530		},
4531
4532		.rc.core = {
4533			.rc_interval      = DEFAULT_RC_INTERVAL,
4534			.rc_codes         = RC_MAP_DIB0700_RC5_TABLE,
4535			.module_name	  = "dib0700",
4536			.rc_query         = dib0700_rc_query_old_firmware,
4537			.allowed_protos   = RC_BIT_RC5 |
4538					    RC_BIT_RC6_MCE |
4539					    RC_BIT_NEC,
4540			.change_protocol  = dib0700_change_protocol,
4541		},
4542	}, { DIB0700_DEFAULT_DEVICE_PROPERTIES,
4543		.num_adapters = 1,
4544		.adapter = {
4545			{
4546			.num_frontends = 1,
4547			.fe = {{
4548				.caps  = DVB_USB_ADAP_HAS_PID_FILTER | DVB_USB_ADAP_PID_FILTER_CAN_BE_TURNED_OFF,
4549				.pid_filter_count = 32,
4550				.pid_filter = stk80xx_pid_filter,
4551				.pid_filter_ctrl = stk80xx_pid_filter_ctrl,
4552				.frontend_attach  = stk807x_frontend_attach,
4553				.tuner_attach     = dib807x_tuner_attach,
4554
4555				DIB0700_DEFAULT_STREAMING_CONFIG(0x02),
4556			}},
4557				.size_of_priv =
4558					sizeof(struct dib0700_adapter_state),
4559			},
4560		},
4561
4562		.num_device_descs = 3,
4563		.devices = {
4564			{   "DiBcom STK807xP reference design",
4565				{ &dib0700_usb_id_table[62], NULL },
4566				{ NULL },
4567			},
4568			{   "Prolink Pixelview SBTVD",
4569				{ &dib0700_usb_id_table[63], NULL },
4570				{ NULL },
4571			},
4572			{   "EvolutePC TVWay+",
4573				{ &dib0700_usb_id_table[64], NULL },
4574				{ NULL },
4575			},
4576		},
4577
4578		.rc.core = {
4579			.rc_interval      = DEFAULT_RC_INTERVAL,
4580			.rc_codes         = RC_MAP_DIB0700_NEC_TABLE,
4581			.module_name	  = "dib0700",
4582			.rc_query         = dib0700_rc_query_old_firmware,
4583			.allowed_protos   = RC_BIT_RC5 |
4584					    RC_BIT_RC6_MCE |
4585					    RC_BIT_NEC,
4586			.change_protocol  = dib0700_change_protocol,
4587		},
4588	}, { DIB0700_DEFAULT_DEVICE_PROPERTIES,
4589		.num_adapters = 2,
4590		.adapter = {
4591			{
4592			.num_frontends = 1,
4593			.fe = {{
4594				.caps  = DVB_USB_ADAP_HAS_PID_FILTER | DVB_USB_ADAP_PID_FILTER_CAN_BE_TURNED_OFF,
4595				.pid_filter_count = 32,
4596				.pid_filter = stk80xx_pid_filter,
4597				.pid_filter_ctrl = stk80xx_pid_filter_ctrl,
4598				.frontend_attach  = stk807xpvr_frontend_attach0,
4599				.tuner_attach     = dib807x_tuner_attach,
4600
4601				DIB0700_DEFAULT_STREAMING_CONFIG(0x02),
4602			}},
4603				.size_of_priv =
4604					sizeof(struct dib0700_adapter_state),
4605			},
4606			{
4607			.num_frontends = 1,
4608			.fe = {{
4609				.caps  = DVB_USB_ADAP_HAS_PID_FILTER | DVB_USB_ADAP_PID_FILTER_CAN_BE_TURNED_OFF,
4610				.pid_filter_count = 32,
4611				.pid_filter = stk80xx_pid_filter,
4612				.pid_filter_ctrl = stk80xx_pid_filter_ctrl,
4613				.frontend_attach  = stk807xpvr_frontend_attach1,
4614				.tuner_attach     = dib807x_tuner_attach,
4615
4616				DIB0700_DEFAULT_STREAMING_CONFIG(0x03),
4617			}},
4618				.size_of_priv =
4619					sizeof(struct dib0700_adapter_state),
4620			},
4621		},
4622
4623		.num_device_descs = 1,
4624		.devices = {
4625			{   "DiBcom STK807xPVR reference design",
4626				{ &dib0700_usb_id_table[61], NULL },
4627				{ NULL },
4628			},
4629		},
4630
4631		.rc.core = {
4632			.rc_interval      = DEFAULT_RC_INTERVAL,
4633			.rc_codes         = RC_MAP_DIB0700_RC5_TABLE,
4634			.module_name	  = "dib0700",
4635			.rc_query         = dib0700_rc_query_old_firmware,
4636			.allowed_protos   = RC_BIT_RC5 |
4637					    RC_BIT_RC6_MCE |
4638					    RC_BIT_NEC,
4639			.change_protocol  = dib0700_change_protocol,
4640		},
4641	}, { DIB0700_DEFAULT_DEVICE_PROPERTIES,
4642		.num_adapters = 1,
4643		.adapter = {
4644			{
4645			.num_frontends = 1,
4646			.fe = {{
4647				.caps  = DVB_USB_ADAP_HAS_PID_FILTER |
4648					DVB_USB_ADAP_PID_FILTER_CAN_BE_TURNED_OFF,
4649				.pid_filter_count = 32,
4650				.pid_filter = stk80xx_pid_filter,
4651				.pid_filter_ctrl = stk80xx_pid_filter_ctrl,
4652				.frontend_attach  = stk809x_frontend_attach,
4653				.tuner_attach     = dib809x_tuner_attach,
4654
4655				DIB0700_DEFAULT_STREAMING_CONFIG(0x02),
4656			}},
4657				.size_of_priv =
4658					sizeof(struct dib0700_adapter_state),
4659			},
4660		},
4661
4662		.num_device_descs = 1,
4663		.devices = {
4664			{   "DiBcom STK8096GP reference design",
4665				{ &dib0700_usb_id_table[67], NULL },
4666				{ NULL },
4667			},
4668		},
4669
4670		.rc.core = {
4671			.rc_interval      = DEFAULT_RC_INTERVAL,
4672			.rc_codes         = RC_MAP_DIB0700_RC5_TABLE,
4673			.module_name	  = "dib0700",
4674			.rc_query         = dib0700_rc_query_old_firmware,
4675			.allowed_protos   = RC_BIT_RC5 |
4676					    RC_BIT_RC6_MCE |
4677					    RC_BIT_NEC,
4678			.change_protocol  = dib0700_change_protocol,
4679		},
4680	}, { DIB0700_DEFAULT_DEVICE_PROPERTIES,
4681		.num_adapters = 1,
4682		.adapter = {
4683			{
4684			.num_frontends = 1,
4685			.fe = {{
4686				.caps  = DVB_USB_ADAP_HAS_PID_FILTER |
4687					DVB_USB_ADAP_PID_FILTER_CAN_BE_TURNED_OFF,
4688				.pid_filter_count = 32,
4689				.pid_filter = dib90x0_pid_filter,
4690				.pid_filter_ctrl = dib90x0_pid_filter_ctrl,
4691				.frontend_attach  = stk9090m_frontend_attach,
4692				.tuner_attach     = dib9090_tuner_attach,
4693
4694				DIB0700_DEFAULT_STREAMING_CONFIG(0x02),
4695			}},
4696				.size_of_priv =
4697					sizeof(struct dib0700_adapter_state),
4698			},
4699		},
4700
4701		.num_device_descs = 1,
4702		.devices = {
4703			{   "DiBcom STK9090M reference design",
4704				{ &dib0700_usb_id_table[69], NULL },
4705				{ NULL },
4706			},
4707		},
4708
4709		.rc.core = {
4710			.rc_interval      = DEFAULT_RC_INTERVAL,
4711			.rc_codes         = RC_MAP_DIB0700_RC5_TABLE,
4712			.module_name	  = "dib0700",
4713			.rc_query         = dib0700_rc_query_old_firmware,
4714			.allowed_protos   = RC_BIT_RC5 |
4715					    RC_BIT_RC6_MCE |
4716					    RC_BIT_NEC,
4717			.change_protocol  = dib0700_change_protocol,
4718		},
4719	}, { DIB0700_DEFAULT_DEVICE_PROPERTIES,
4720		.num_adapters = 1,
4721		.adapter = {
4722			{
4723			.num_frontends = 1,
4724			.fe = {{
4725				.caps  = DVB_USB_ADAP_HAS_PID_FILTER |
4726					DVB_USB_ADAP_PID_FILTER_CAN_BE_TURNED_OFF,
4727				.pid_filter_count = 32,
4728				.pid_filter = stk80xx_pid_filter,
4729				.pid_filter_ctrl = stk80xx_pid_filter_ctrl,
4730				.frontend_attach  = nim8096md_frontend_attach,
4731				.tuner_attach     = nim8096md_tuner_attach,
4732
4733				DIB0700_DEFAULT_STREAMING_CONFIG(0x02),
4734			}},
4735				.size_of_priv =
4736					sizeof(struct dib0700_adapter_state),
4737			},
4738		},
4739
4740		.num_device_descs = 1,
4741		.devices = {
4742			{   "DiBcom NIM8096MD reference design",
4743				{ &dib0700_usb_id_table[70], NULL },
4744				{ NULL },
4745			},
4746		},
4747
4748		.rc.core = {
4749			.rc_interval      = DEFAULT_RC_INTERVAL,
4750			.rc_codes         = RC_MAP_DIB0700_RC5_TABLE,
4751			.module_name	  = "dib0700",
4752			.rc_query         = dib0700_rc_query_old_firmware,
4753			.allowed_protos   = RC_BIT_RC5 |
4754					    RC_BIT_RC6_MCE |
4755					    RC_BIT_NEC,
4756			.change_protocol  = dib0700_change_protocol,
4757		},
4758	}, { DIB0700_DEFAULT_DEVICE_PROPERTIES,
4759		.num_adapters = 1,
4760		.adapter = {
4761			{
4762			.num_frontends = 1,
4763			.fe = {{
4764				.caps  = DVB_USB_ADAP_HAS_PID_FILTER |
4765					DVB_USB_ADAP_PID_FILTER_CAN_BE_TURNED_OFF,
4766				.pid_filter_count = 32,
4767				.pid_filter = dib90x0_pid_filter,
4768				.pid_filter_ctrl = dib90x0_pid_filter_ctrl,
4769				.frontend_attach  = nim9090md_frontend_attach,
4770				.tuner_attach     = nim9090md_tuner_attach,
4771
4772				DIB0700_DEFAULT_STREAMING_CONFIG(0x02),
4773			}},
4774				.size_of_priv =
4775					sizeof(struct dib0700_adapter_state),
4776			},
4777		},
4778
4779		.num_device_descs = 1,
4780		.devices = {
4781			{   "DiBcom NIM9090MD reference design",
4782				{ &dib0700_usb_id_table[71], NULL },
4783				{ NULL },
4784			},
4785		},
4786
4787		.rc.core = {
4788			.rc_interval      = DEFAULT_RC_INTERVAL,
4789			.rc_codes         = RC_MAP_DIB0700_RC5_TABLE,
4790			.module_name	  = "dib0700",
4791			.rc_query         = dib0700_rc_query_old_firmware,
4792			.allowed_protos   = RC_BIT_RC5 |
4793					    RC_BIT_RC6_MCE |
4794					    RC_BIT_NEC,
4795			.change_protocol  = dib0700_change_protocol,
4796		},
4797	}, { DIB0700_DEFAULT_DEVICE_PROPERTIES,
4798		.num_adapters = 1,
4799		.adapter = {
4800			{
4801			.num_frontends = 1,
4802			.fe = {{
4803				.caps  = DVB_USB_ADAP_HAS_PID_FILTER |
4804					DVB_USB_ADAP_PID_FILTER_CAN_BE_TURNED_OFF,
4805				.pid_filter_count = 32,
4806				.pid_filter = stk70x0p_pid_filter,
4807				.pid_filter_ctrl = stk70x0p_pid_filter_ctrl,
4808				.frontend_attach  = nim7090_frontend_attach,
4809				.tuner_attach     = nim7090_tuner_attach,
4810
4811				DIB0700_DEFAULT_STREAMING_CONFIG(0x02),
4812			}},
4813				.size_of_priv =
4814					sizeof(struct dib0700_adapter_state),
4815			},
4816		},
4817
4818		.num_device_descs = 1,
4819		.devices = {
4820			{   "DiBcom NIM7090 reference design",
4821				{ &dib0700_usb_id_table[72], NULL },
4822				{ NULL },
4823			},
4824		},
4825
4826		.rc.core = {
4827			.rc_interval      = DEFAULT_RC_INTERVAL,
4828			.rc_codes         = RC_MAP_DIB0700_RC5_TABLE,
4829			.module_name	  = "dib0700",
4830			.rc_query         = dib0700_rc_query_old_firmware,
4831			.allowed_protos   = RC_BIT_RC5 |
4832					    RC_BIT_RC6_MCE |
4833					    RC_BIT_NEC,
4834			.change_protocol  = dib0700_change_protocol,
4835		},
4836	}, { DIB0700_DEFAULT_DEVICE_PROPERTIES,
4837		.num_adapters = 2,
4838		.adapter = {
4839			{
4840			.num_frontends = 1,
4841			.fe = {{
4842				.caps  = DVB_USB_ADAP_HAS_PID_FILTER |
4843					DVB_USB_ADAP_PID_FILTER_CAN_BE_TURNED_OFF,
4844				.pid_filter_count = 32,
4845				.pid_filter = stk70x0p_pid_filter,
4846				.pid_filter_ctrl = stk70x0p_pid_filter_ctrl,
4847				.frontend_attach  = tfe7090pvr_frontend0_attach,
4848				.tuner_attach     = tfe7090pvr_tuner0_attach,
4849
4850				DIB0700_DEFAULT_STREAMING_CONFIG(0x03),
4851			}},
4852				.size_of_priv =
4853					sizeof(struct dib0700_adapter_state),
4854			},
4855			{
4856			.num_frontends = 1,
4857			.fe = {{
4858				.caps  = DVB_USB_ADAP_HAS_PID_FILTER |
4859					DVB_USB_ADAP_PID_FILTER_CAN_BE_TURNED_OFF,
4860				.pid_filter_count = 32,
4861				.pid_filter = stk70x0p_pid_filter,
4862				.pid_filter_ctrl = stk70x0p_pid_filter_ctrl,
4863				.frontend_attach  = tfe7090pvr_frontend1_attach,
4864				.tuner_attach     = tfe7090pvr_tuner1_attach,
4865
4866				DIB0700_DEFAULT_STREAMING_CONFIG(0x02),
4867			}},
4868				.size_of_priv =
4869					sizeof(struct dib0700_adapter_state),
4870			},
4871		},
4872
4873		.num_device_descs = 1,
4874		.devices = {
4875			{   "DiBcom TFE7090PVR reference design",
4876				{ &dib0700_usb_id_table[73], NULL },
4877				{ NULL },
4878			},
4879		},
4880
4881		.rc.core = {
4882			.rc_interval      = DEFAULT_RC_INTERVAL,
4883			.rc_codes         = RC_MAP_DIB0700_RC5_TABLE,
4884			.module_name	  = "dib0700",
4885			.rc_query         = dib0700_rc_query_old_firmware,
4886			.allowed_protos   = RC_BIT_RC5 |
4887					    RC_BIT_RC6_MCE |
4888					    RC_BIT_NEC,
4889			.change_protocol  = dib0700_change_protocol,
4890		},
4891	}, { DIB0700_DEFAULT_DEVICE_PROPERTIES,
4892		.num_adapters = 1,
4893		.adapter = {
4894			{
4895			.num_frontends = 1,
4896			.fe = {{
4897				.frontend_attach  = pctv340e_frontend_attach,
4898				.tuner_attach     = xc4000_tuner_attach,
4899
4900				DIB0700_DEFAULT_STREAMING_CONFIG(0x02),
4901			}},
4902				.size_of_priv = sizeof(struct
4903						dib0700_adapter_state),
4904			},
4905		},
4906
4907		.num_device_descs = 2,
4908		.devices = {
4909			{   "Pinnacle PCTV 340e HD Pro USB Stick",
4910				{ &dib0700_usb_id_table[76], NULL },
4911				{ NULL },
4912			},
4913			{   "Pinnacle PCTV Hybrid Stick Solo",
4914				{ &dib0700_usb_id_table[77], NULL },
4915				{ NULL },
4916			},
4917		},
4918		.rc.core = {
4919			.rc_interval      = DEFAULT_RC_INTERVAL,
4920			.rc_codes         = RC_MAP_DIB0700_RC5_TABLE,
4921			.module_name	  = "dib0700",
4922			.rc_query         = dib0700_rc_query_old_firmware,
4923			.allowed_protos   = RC_BIT_RC5 |
4924					    RC_BIT_RC6_MCE |
4925					    RC_BIT_NEC,
4926			.change_protocol  = dib0700_change_protocol,
4927		},
4928	}, { DIB0700_DEFAULT_DEVICE_PROPERTIES,
4929		.num_adapters = 1,
4930		.adapter = {
4931			{
4932				.num_frontends = 1,
4933				.fe = {{
4934					.caps  = DVB_USB_ADAP_HAS_PID_FILTER |
4935						DVB_USB_ADAP_PID_FILTER_CAN_BE_TURNED_OFF,
4936					.pid_filter_count = 32,
4937					.pid_filter = stk70x0p_pid_filter,
4938					.pid_filter_ctrl = stk70x0p_pid_filter_ctrl,
4939					.frontend_attach  = tfe7790p_frontend_attach,
4940					.tuner_attach     = tfe7790p_tuner_attach,
4941
4942					DIB0700_DEFAULT_STREAMING_CONFIG(0x03),
4943				} },
4944
4945				.size_of_priv =
4946					sizeof(struct dib0700_adapter_state),
4947			},
4948		},
4949
4950		.num_device_descs = 1,
4951		.devices = {
4952			{   "DiBcom TFE7790P reference design",
4953				{ &dib0700_usb_id_table[78], NULL },
4954				{ NULL },
4955			},
4956		},
4957
4958		.rc.core = {
4959			.rc_interval      = DEFAULT_RC_INTERVAL,
4960			.rc_codes         = RC_MAP_DIB0700_RC5_TABLE,
4961			.module_name	  = "dib0700",
4962			.rc_query         = dib0700_rc_query_old_firmware,
4963			.allowed_protos   = RC_BIT_RC5 |
4964					    RC_BIT_RC6_MCE |
4965					    RC_BIT_NEC,
4966			.change_protocol  = dib0700_change_protocol,
4967		},
4968	}, { DIB0700_DEFAULT_DEVICE_PROPERTIES,
4969		.num_adapters = 1,
4970		.adapter = {
4971			{
4972				.num_frontends = 1,
4973				.fe = {{
4974					.caps  = DVB_USB_ADAP_HAS_PID_FILTER |
4975						DVB_USB_ADAP_PID_FILTER_CAN_BE_TURNED_OFF,
4976					.pid_filter_count = 32,
4977					.pid_filter = stk80xx_pid_filter,
4978					.pid_filter_ctrl = stk80xx_pid_filter_ctrl,
4979					.frontend_attach  = tfe8096p_frontend_attach,
4980					.tuner_attach     = tfe8096p_tuner_attach,
4981
4982					DIB0700_DEFAULT_STREAMING_CONFIG(0x02),
4983
4984				} },
4985
4986				.size_of_priv =
4987					sizeof(struct dib0700_adapter_state),
4988			},
4989		},
4990
4991		.num_device_descs = 1,
4992		.devices = {
4993			{   "DiBcom TFE8096P reference design",
4994				{ &dib0700_usb_id_table[79], NULL },
4995				{ NULL },
4996			},
4997		},
4998
4999		.rc.core = {
5000			.rc_interval      = DEFAULT_RC_INTERVAL,
5001			.rc_codes         = RC_MAP_DIB0700_RC5_TABLE,
5002			.module_name	  = "dib0700",
5003			.rc_query         = dib0700_rc_query_old_firmware,
5004			.allowed_protos   = RC_BIT_RC5 |
5005					    RC_BIT_RC6_MCE |
5006					    RC_BIT_NEC,
5007			.change_protocol  = dib0700_change_protocol,
5008		},
5009	},
5010};
5011
5012int dib0700_device_count = ARRAY_SIZE(dib0700_devices);
5013