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