[media] DiBcom: correct warnings
[pandora-kernel.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 *, struct dvb_frontend_parameters *);
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, struct dvb_frontend_parameters *fep)
808 {
809         struct dvb_usb_adapter *adap = fe->dvb->priv;
810         struct dib0700_adapter_state *state = adap->priv;
811
812         u16 offset;
813         u8 band = BAND_OF_FREQUENCY(fep->frequency/1000);
814         switch (band) {
815                 case BAND_VHF: offset = 950; break;
816                 case BAND_UHF:
817                 default: offset = 550; break;
818         }
819         deb_info("WBD for DiB7000P: %d\n", offset + dib0070_wbd_offset(fe));
820         dib7000p_set_wbd_ref(fe, offset + dib0070_wbd_offset(fe));
821         return state->set_param_save(fe, fep);
822 }
823
824 static int dib7770_set_param_override(struct dvb_frontend *fe,
825                 struct dvb_frontend_parameters *fep)
826 {
827          struct dvb_usb_adapter *adap = fe->dvb->priv;
828          struct dib0700_adapter_state *state = adap->priv;
829
830          u16 offset;
831          u8 band = BAND_OF_FREQUENCY(fep->frequency/1000);
832          switch (band) {
833          case BAND_VHF:
834                   dib7000p_set_gpio(fe, 0, 0, 1);
835                   offset = 850;
836                   break;
837          case BAND_UHF:
838          default:
839                   dib7000p_set_gpio(fe, 0, 0, 0);
840                   offset = 250;
841                   break;
842          }
843          deb_info("WBD for DiB7000P: %d\n", offset + dib0070_wbd_offset(fe));
844          dib7000p_set_wbd_ref(fe, offset + dib0070_wbd_offset(fe));
845          return state->set_param_save(fe, fep);
846 }
847
848 static int dib7770p_tuner_attach(struct dvb_usb_adapter *adap)
849 {
850          struct dib0700_adapter_state *st = adap->priv;
851          struct i2c_adapter *tun_i2c = dib7000p_get_i2c_master(adap->fe_adap[0].fe,
852                          DIBX000_I2C_INTERFACE_TUNER, 1);
853
854          if (dvb_attach(dib0070_attach, adap->fe_adap[0].fe, tun_i2c,
855                         &dib7770p_dib0070_config) == NULL)
856                  return -ENODEV;
857
858          st->set_param_save = adap->fe_adap[0].fe->ops.tuner_ops.set_params;
859          adap->fe_adap[0].fe->ops.tuner_ops.set_params = dib7770_set_param_override;
860          return 0;
861 }
862
863 static int dib7070p_tuner_attach(struct dvb_usb_adapter *adap)
864 {
865         struct dib0700_adapter_state *st = adap->priv;
866         struct i2c_adapter *tun_i2c = dib7000p_get_i2c_master(adap->fe_adap[0].fe, DIBX000_I2C_INTERFACE_TUNER, 1);
867
868         if (adap->id == 0) {
869                 if (dvb_attach(dib0070_attach, adap->fe_adap[0].fe, tun_i2c, &dib7070p_dib0070_config[0]) == NULL)
870                         return -ENODEV;
871         } else {
872                 if (dvb_attach(dib0070_attach, adap->fe_adap[0].fe, tun_i2c, &dib7070p_dib0070_config[1]) == NULL)
873                         return -ENODEV;
874         }
875
876         st->set_param_save = adap->fe_adap[0].fe->ops.tuner_ops.set_params;
877         adap->fe_adap[0].fe->ops.tuner_ops.set_params = dib7070_set_param_override;
878         return 0;
879 }
880
881 static int stk7700p_pid_filter(struct dvb_usb_adapter *adapter, int index,
882                 u16 pid, int onoff)
883 {
884         struct dib0700_state *st = adapter->dev->priv;
885         if (st->is_dib7000pc)
886                 return dib7000p_pid_filter(adapter->fe_adap[0].fe, index, pid, onoff);
887         return dib7000m_pid_filter(adapter->fe_adap[0].fe, index, pid, onoff);
888 }
889
890 static int stk7700p_pid_filter_ctrl(struct dvb_usb_adapter *adapter, int onoff)
891 {
892         struct dib0700_state *st = adapter->dev->priv;
893         if (st->is_dib7000pc)
894                 return dib7000p_pid_filter_ctrl(adapter->fe_adap[0].fe, onoff);
895         return dib7000m_pid_filter_ctrl(adapter->fe_adap[0].fe, onoff);
896 }
897
898 static int stk70x0p_pid_filter(struct dvb_usb_adapter *adapter, int index, u16 pid, int onoff)
899 {
900         return dib7000p_pid_filter(adapter->fe_adap[0].fe, index, pid, onoff);
901 }
902
903 static int stk70x0p_pid_filter_ctrl(struct dvb_usb_adapter *adapter, int onoff)
904 {
905         return dib7000p_pid_filter_ctrl(adapter->fe_adap[0].fe, onoff);
906 }
907
908 static struct dibx000_bandwidth_config dib7070_bw_config_12_mhz = {
909         60000, 15000,
910         1, 20, 3, 1, 0,
911         0, 0, 1, 1, 2,
912         (3 << 14) | (1 << 12) | (524 << 0),
913         (0 << 25) | 0,
914         20452225,
915         12000000,
916 };
917
918 static struct dib7000p_config dib7070p_dib7000p_config = {
919         .output_mpeg2_in_188_bytes = 1,
920
921         .agc_config_count = 1,
922         .agc = &dib7070_agc_config,
923         .bw  = &dib7070_bw_config_12_mhz,
924         .tuner_is_baseband = 1,
925         .spur_protect = 1,
926
927         .gpio_dir = DIB7000P_GPIO_DEFAULT_DIRECTIONS,
928         .gpio_val = DIB7000P_GPIO_DEFAULT_VALUES,
929         .gpio_pwm_pos = DIB7000P_GPIO_DEFAULT_PWM_POS,
930
931         .hostbus_diversity = 1,
932 };
933
934 /* STK7070P */
935 static int stk7070p_frontend_attach(struct dvb_usb_adapter *adap)
936 {
937         struct usb_device_descriptor *p = &adap->dev->udev->descriptor;
938         if (p->idVendor  == cpu_to_le16(USB_VID_PINNACLE) &&
939             p->idProduct == cpu_to_le16(USB_PID_PINNACLE_PCTV72E))
940                 dib0700_set_gpio(adap->dev, GPIO6, GPIO_OUT, 0);
941         else
942                 dib0700_set_gpio(adap->dev, GPIO6, GPIO_OUT, 1);
943         msleep(10);
944         dib0700_set_gpio(adap->dev, GPIO9, GPIO_OUT, 1);
945         dib0700_set_gpio(adap->dev, GPIO4, GPIO_OUT, 1);
946         dib0700_set_gpio(adap->dev, GPIO7, GPIO_OUT, 1);
947         dib0700_set_gpio(adap->dev, GPIO10, GPIO_OUT, 0);
948
949         dib0700_ctrl_clock(adap->dev, 72, 1);
950
951         msleep(10);
952         dib0700_set_gpio(adap->dev, GPIO10, GPIO_OUT, 1);
953         msleep(10);
954         dib0700_set_gpio(adap->dev, GPIO0, GPIO_OUT, 1);
955
956         if (dib7000p_i2c_enumeration(&adap->dev->i2c_adap, 1, 18,
957                                      &dib7070p_dib7000p_config) != 0) {
958                 err("%s: dib7000p_i2c_enumeration failed.  Cannot continue\n",
959                     __func__);
960                 return -ENODEV;
961         }
962
963         adap->fe_adap[0].fe = dvb_attach(dib7000p_attach, &adap->dev->i2c_adap, 0x80,
964                 &dib7070p_dib7000p_config);
965         return adap->fe_adap[0].fe == NULL ? -ENODEV : 0;
966 }
967
968 /* STK7770P */
969 static struct dib7000p_config dib7770p_dib7000p_config = {
970         .output_mpeg2_in_188_bytes = 1,
971
972         .agc_config_count = 1,
973         .agc = &dib7070_agc_config,
974         .bw  = &dib7070_bw_config_12_mhz,
975         .tuner_is_baseband = 1,
976         .spur_protect = 1,
977
978         .gpio_dir = DIB7000P_GPIO_DEFAULT_DIRECTIONS,
979         .gpio_val = DIB7000P_GPIO_DEFAULT_VALUES,
980         .gpio_pwm_pos = DIB7000P_GPIO_DEFAULT_PWM_POS,
981
982         .hostbus_diversity = 1,
983         .enable_current_mirror = 1,
984         .disable_sample_and_hold = 0,
985 };
986
987 static int stk7770p_frontend_attach(struct dvb_usb_adapter *adap)
988 {
989         struct usb_device_descriptor *p = &adap->dev->udev->descriptor;
990         if (p->idVendor  == cpu_to_le16(USB_VID_PINNACLE) &&
991             p->idProduct == cpu_to_le16(USB_PID_PINNACLE_PCTV72E))
992                 dib0700_set_gpio(adap->dev, GPIO6, GPIO_OUT, 0);
993         else
994                 dib0700_set_gpio(adap->dev, GPIO6, GPIO_OUT, 1);
995         msleep(10);
996         dib0700_set_gpio(adap->dev, GPIO9, GPIO_OUT, 1);
997         dib0700_set_gpio(adap->dev, GPIO4, GPIO_OUT, 1);
998         dib0700_set_gpio(adap->dev, GPIO7, GPIO_OUT, 1);
999         dib0700_set_gpio(adap->dev, GPIO10, GPIO_OUT, 0);
1000
1001         dib0700_ctrl_clock(adap->dev, 72, 1);
1002
1003         msleep(10);
1004         dib0700_set_gpio(adap->dev, GPIO10, GPIO_OUT, 1);
1005         msleep(10);
1006         dib0700_set_gpio(adap->dev, GPIO0, GPIO_OUT, 1);
1007
1008         if (dib7000p_i2c_enumeration(&adap->dev->i2c_adap, 1, 18,
1009                                      &dib7770p_dib7000p_config) != 0) {
1010                 err("%s: dib7000p_i2c_enumeration failed.  Cannot continue\n",
1011                     __func__);
1012                 return -ENODEV;
1013         }
1014
1015         adap->fe_adap[0].fe = dvb_attach(dib7000p_attach, &adap->dev->i2c_adap, 0x80,
1016                 &dib7770p_dib7000p_config);
1017         return adap->fe_adap[0].fe == NULL ? -ENODEV : 0;
1018 }
1019
1020 /* DIB807x generic */
1021 static struct dibx000_agc_config dib807x_agc_config[2] = {
1022         {
1023                 BAND_VHF,
1024                 /* P_agc_use_sd_mod1=0, P_agc_use_sd_mod2=0,
1025                  * P_agc_freq_pwm_div=1, P_agc_inv_pwm1=0,
1026                  * P_agc_inv_pwm2=0,P_agc_inh_dc_rv_est=0,
1027                  * P_agc_time_est=3, P_agc_freeze=0, P_agc_nb_est=5,
1028                  * P_agc_write=0 */
1029                 (0 << 15) | (0 << 14) | (7 << 11) | (0 << 10) | (0 << 9) |
1030                         (0 << 8) | (3 << 5) | (0 << 4) | (5 << 1) |
1031                         (0 << 0), /* setup*/
1032
1033                 600, /* inv_gain*/
1034                 10,  /* time_stabiliz*/
1035
1036                 0,  /* alpha_level*/
1037                 118,  /* thlock*/
1038
1039                 0,     /* wbd_inv*/
1040                 3530,  /* wbd_ref*/
1041                 1,     /* wbd_sel*/
1042                 5,     /* wbd_alpha*/
1043
1044                 65535,  /* agc1_max*/
1045                 0,  /* agc1_min*/
1046
1047                 65535,  /* agc2_max*/
1048                 0,      /* agc2_min*/
1049
1050                 0,      /* agc1_pt1*/
1051                 40,     /* agc1_pt2*/
1052                 183,    /* agc1_pt3*/
1053                 206,    /* agc1_slope1*/
1054                 255,    /* agc1_slope2*/
1055                 72,     /* agc2_pt1*/
1056                 152,    /* agc2_pt2*/
1057                 88,     /* agc2_slope1*/
1058                 90,     /* agc2_slope2*/
1059
1060                 17,  /* alpha_mant*/
1061                 27,  /* alpha_exp*/
1062                 23,  /* beta_mant*/
1063                 51,  /* beta_exp*/
1064
1065                 0,  /* perform_agc_softsplit*/
1066         }, {
1067                 BAND_UHF,
1068                 /* P_agc_use_sd_mod1=0, P_agc_use_sd_mod2=0,
1069                  * P_agc_freq_pwm_div=1, P_agc_inv_pwm1=0,
1070                  * P_agc_inv_pwm2=0, P_agc_inh_dc_rv_est=0,
1071                  * P_agc_time_est=3, P_agc_freeze=0, P_agc_nb_est=5,
1072                  * P_agc_write=0 */
1073                 (0 << 15) | (0 << 14) | (1 << 11) | (0 << 10) | (0 << 9) |
1074                         (0 << 8) | (3 << 5) | (0 << 4) | (5 << 1) |
1075                         (0 << 0), /* setup */
1076
1077                 600, /* inv_gain*/
1078                 10,  /* time_stabiliz*/
1079
1080                 0,  /* alpha_level*/
1081                 118,  /* thlock*/
1082
1083                 0,     /* wbd_inv*/
1084                 3530,  /* wbd_ref*/
1085                 1,     /* wbd_sel*/
1086                 5,     /* wbd_alpha*/
1087
1088                 65535,  /* agc1_max*/
1089                 0,  /* agc1_min*/
1090
1091                 65535,  /* agc2_max*/
1092                 0,      /* agc2_min*/
1093
1094                 0,      /* agc1_pt1*/
1095                 40,     /* agc1_pt2*/
1096                 183,    /* agc1_pt3*/
1097                 206,    /* agc1_slope1*/
1098                 255,    /* agc1_slope2*/
1099                 72,     /* agc2_pt1*/
1100                 152,    /* agc2_pt2*/
1101                 88,     /* agc2_slope1*/
1102                 90,     /* agc2_slope2*/
1103
1104                 17,  /* alpha_mant*/
1105                 27,  /* alpha_exp*/
1106                 23,  /* beta_mant*/
1107                 51,  /* beta_exp*/
1108
1109                 0,  /* perform_agc_softsplit*/
1110         }
1111 };
1112
1113 static struct dibx000_bandwidth_config dib807x_bw_config_12_mhz = {
1114         60000, 15000, /* internal, sampling*/
1115         1, 20, 3, 1, 0, /* pll_cfg: prediv, ratio, range, reset, bypass*/
1116         0, 0, 1, 1, 2, /* misc: refdiv, bypclk_div, IO_CLK_en_core,
1117                           ADClkSrc, modulo */
1118         (3 << 14) | (1 << 12) | (599 << 0), /* sad_cfg: refsel, sel, freq_15k*/
1119         (0 << 25) | 0, /* ifreq = 0.000000 MHz*/
1120         18179755, /* timf*/
1121         12000000, /* xtal_hz*/
1122 };
1123
1124 static struct dib8000_config dib807x_dib8000_config[2] = {
1125         {
1126                 .output_mpeg2_in_188_bytes = 1,
1127
1128                 .agc_config_count = 2,
1129                 .agc = dib807x_agc_config,
1130                 .pll = &dib807x_bw_config_12_mhz,
1131                 .tuner_is_baseband = 1,
1132
1133                 .gpio_dir = DIB8000_GPIO_DEFAULT_DIRECTIONS,
1134                 .gpio_val = DIB8000_GPIO_DEFAULT_VALUES,
1135                 .gpio_pwm_pos = DIB8000_GPIO_DEFAULT_PWM_POS,
1136
1137                 .hostbus_diversity = 1,
1138                 .div_cfg = 1,
1139                 .agc_control = &dib0070_ctrl_agc_filter,
1140                 .output_mode = OUTMODE_MPEG2_FIFO,
1141                 .drives = 0x2d98,
1142         }, {
1143                 .output_mpeg2_in_188_bytes = 1,
1144
1145                 .agc_config_count = 2,
1146                 .agc = dib807x_agc_config,
1147                 .pll = &dib807x_bw_config_12_mhz,
1148                 .tuner_is_baseband = 1,
1149
1150                 .gpio_dir = DIB8000_GPIO_DEFAULT_DIRECTIONS,
1151                 .gpio_val = DIB8000_GPIO_DEFAULT_VALUES,
1152                 .gpio_pwm_pos = DIB8000_GPIO_DEFAULT_PWM_POS,
1153
1154                 .hostbus_diversity = 1,
1155                 .agc_control = &dib0070_ctrl_agc_filter,
1156                 .output_mode = OUTMODE_MPEG2_FIFO,
1157                 .drives = 0x2d98,
1158         }
1159 };
1160
1161 static int dib80xx_tuner_reset(struct dvb_frontend *fe, int onoff)
1162 {
1163         return dib8000_set_gpio(fe, 5, 0, !onoff);
1164 }
1165
1166 static int dib80xx_tuner_sleep(struct dvb_frontend *fe, int onoff)
1167 {
1168         return dib8000_set_gpio(fe, 0, 0, onoff);
1169 }
1170
1171 static const struct dib0070_wbd_gain_cfg dib8070_wbd_gain_cfg[] = {
1172     { 240,      7},
1173     { 0xffff,   6},
1174 };
1175
1176 static struct dib0070_config dib807x_dib0070_config[2] = {
1177         {
1178                 .i2c_address = DEFAULT_DIB0070_I2C_ADDRESS,
1179                 .reset = dib80xx_tuner_reset,
1180                 .sleep = dib80xx_tuner_sleep,
1181                 .clock_khz = 12000,
1182                 .clock_pad_drive = 4,
1183                 .vga_filter = 1,
1184                 .force_crystal_mode = 1,
1185                 .enable_third_order_filter = 1,
1186                 .charge_pump = 0,
1187                 .wbd_gain = dib8070_wbd_gain_cfg,
1188                 .osc_buffer_state = 0,
1189                 .freq_offset_khz_uhf = -100,
1190                 .freq_offset_khz_vhf = -100,
1191         }, {
1192                 .i2c_address = DEFAULT_DIB0070_I2C_ADDRESS,
1193                 .reset = dib80xx_tuner_reset,
1194                 .sleep = dib80xx_tuner_sleep,
1195                 .clock_khz = 12000,
1196                 .clock_pad_drive = 2,
1197                 .vga_filter = 1,
1198                 .force_crystal_mode = 1,
1199                 .enable_third_order_filter = 1,
1200                 .charge_pump = 0,
1201                 .wbd_gain = dib8070_wbd_gain_cfg,
1202                 .osc_buffer_state = 0,
1203                 .freq_offset_khz_uhf = -25,
1204                 .freq_offset_khz_vhf = -25,
1205         }
1206 };
1207
1208 static int dib807x_set_param_override(struct dvb_frontend *fe,
1209                 struct dvb_frontend_parameters *fep)
1210 {
1211         struct dvb_usb_adapter *adap = fe->dvb->priv;
1212         struct dib0700_adapter_state *state = adap->priv;
1213
1214         u16 offset = dib0070_wbd_offset(fe);
1215         u8 band = BAND_OF_FREQUENCY(fep->frequency/1000);
1216         switch (band) {
1217         case BAND_VHF:
1218                 offset += 750;
1219                 break;
1220         case BAND_UHF:  /* fall-thru wanted */
1221         default:
1222                 offset += 250; break;
1223         }
1224         deb_info("WBD for DiB8000: %d\n", offset);
1225         dib8000_set_wbd_ref(fe, offset);
1226
1227         return state->set_param_save(fe, fep);
1228 }
1229
1230 static int dib807x_tuner_attach(struct dvb_usb_adapter *adap)
1231 {
1232         struct dib0700_adapter_state *st = adap->priv;
1233         struct i2c_adapter *tun_i2c = dib8000_get_i2c_master(adap->fe_adap[0].fe,
1234                         DIBX000_I2C_INTERFACE_TUNER, 1);
1235
1236         if (adap->id == 0) {
1237                 if (dvb_attach(dib0070_attach, adap->fe_adap[0].fe, tun_i2c,
1238                                 &dib807x_dib0070_config[0]) == NULL)
1239                         return -ENODEV;
1240         } else {
1241                 if (dvb_attach(dib0070_attach, adap->fe_adap[0].fe, tun_i2c,
1242                                 &dib807x_dib0070_config[1]) == NULL)
1243                         return -ENODEV;
1244         }
1245
1246         st->set_param_save = adap->fe_adap[0].fe->ops.tuner_ops.set_params;
1247         adap->fe_adap[0].fe->ops.tuner_ops.set_params = dib807x_set_param_override;
1248         return 0;
1249 }
1250
1251 static int stk80xx_pid_filter(struct dvb_usb_adapter *adapter, int index,
1252         u16 pid, int onoff)
1253 {
1254         return dib8000_pid_filter(adapter->fe_adap[0].fe, index, pid, onoff);
1255 }
1256
1257 static int stk80xx_pid_filter_ctrl(struct dvb_usb_adapter *adapter,
1258                 int onoff)
1259 {
1260         return dib8000_pid_filter_ctrl(adapter->fe_adap[0].fe, onoff);
1261 }
1262
1263 /* STK807x */
1264 static int stk807x_frontend_attach(struct dvb_usb_adapter *adap)
1265 {
1266         dib0700_set_gpio(adap->dev, GPIO6, GPIO_OUT, 1);
1267         msleep(10);
1268         dib0700_set_gpio(adap->dev, GPIO9, GPIO_OUT, 1);
1269         dib0700_set_gpio(adap->dev, GPIO4, GPIO_OUT, 1);
1270         dib0700_set_gpio(adap->dev, GPIO7, GPIO_OUT, 1);
1271
1272         dib0700_set_gpio(adap->dev, GPIO10, GPIO_OUT, 0);
1273
1274         dib0700_ctrl_clock(adap->dev, 72, 1);
1275
1276         msleep(10);
1277         dib0700_set_gpio(adap->dev, GPIO10, GPIO_OUT, 1);
1278         msleep(10);
1279         dib0700_set_gpio(adap->dev, GPIO0, GPIO_OUT, 1);
1280
1281         dib8000_i2c_enumeration(&adap->dev->i2c_adap, 1, 18,
1282                                 0x80);
1283
1284         adap->fe_adap[0].fe = dvb_attach(dib8000_attach, &adap->dev->i2c_adap, 0x80,
1285                               &dib807x_dib8000_config[0]);
1286
1287         return adap->fe_adap[0].fe == NULL ?  -ENODEV : 0;
1288 }
1289
1290 /* STK807xPVR */
1291 static int stk807xpvr_frontend_attach0(struct dvb_usb_adapter *adap)
1292 {
1293         dib0700_set_gpio(adap->dev, GPIO6, GPIO_OUT, 0);
1294         msleep(30);
1295         dib0700_set_gpio(adap->dev, GPIO6, GPIO_OUT, 1);
1296         msleep(500);
1297         dib0700_set_gpio(adap->dev, GPIO9, GPIO_OUT, 1);
1298         dib0700_set_gpio(adap->dev, GPIO4, GPIO_OUT, 1);
1299         dib0700_set_gpio(adap->dev, GPIO7, GPIO_OUT, 1);
1300
1301         dib0700_set_gpio(adap->dev, GPIO10, GPIO_OUT, 0);
1302
1303         dib0700_ctrl_clock(adap->dev, 72, 1);
1304
1305         msleep(10);
1306         dib0700_set_gpio(adap->dev, GPIO10, GPIO_OUT, 1);
1307         msleep(10);
1308         dib0700_set_gpio(adap->dev, GPIO0, GPIO_OUT, 1);
1309
1310         /* initialize IC 0 */
1311         dib8000_i2c_enumeration(&adap->dev->i2c_adap, 1, 0x22, 0x80);
1312
1313         adap->fe_adap[0].fe = dvb_attach(dib8000_attach, &adap->dev->i2c_adap, 0x80,
1314                               &dib807x_dib8000_config[0]);
1315
1316         return adap->fe_adap[0].fe == NULL ? -ENODEV : 0;
1317 }
1318
1319 static int stk807xpvr_frontend_attach1(struct dvb_usb_adapter *adap)
1320 {
1321         /* initialize IC 1 */
1322         dib8000_i2c_enumeration(&adap->dev->i2c_adap, 1, 0x12, 0x82);
1323
1324         adap->fe_adap[0].fe = dvb_attach(dib8000_attach, &adap->dev->i2c_adap, 0x82,
1325                               &dib807x_dib8000_config[1]);
1326
1327         return adap->fe_adap[0].fe == NULL ? -ENODEV : 0;
1328 }
1329
1330 /* STK8096GP */
1331 static struct dibx000_agc_config dib8090_agc_config[2] = {
1332         {
1333         BAND_UHF | BAND_VHF | BAND_LBAND | BAND_SBAND,
1334         /* P_agc_use_sd_mod1=0, P_agc_use_sd_mod2=0, P_agc_freq_pwm_div=1,
1335          * P_agc_inv_pwm1=0, P_agc_inv_pwm2=0, P_agc_inh_dc_rv_est=0,
1336          * P_agc_time_est=3, P_agc_freeze=0, P_agc_nb_est=5, P_agc_write=0 */
1337         (0 << 15) | (0 << 14) | (5 << 11) | (0 << 10) | (0 << 9) | (0 << 8)
1338         | (3 << 5) | (0 << 4) | (5 << 1) | (0 << 0),
1339
1340         787,
1341         10,
1342
1343         0,
1344         118,
1345
1346         0,
1347         3530,
1348         1,
1349         5,
1350
1351         65535,
1352         0,
1353
1354         65535,
1355         0,
1356
1357         0,
1358         32,
1359         114,
1360         143,
1361         144,
1362         114,
1363         227,
1364         116,
1365         117,
1366
1367         28,
1368         26,
1369         31,
1370         51,
1371
1372         0,
1373         },
1374         {
1375         BAND_CBAND,
1376         /* P_agc_use_sd_mod1=0, P_agc_use_sd_mod2=0, P_agc_freq_pwm_div=1,
1377          * P_agc_inv_pwm1=0, P_agc_inv_pwm2=0, P_agc_inh_dc_rv_est=0,
1378          * P_agc_time_est=3, P_agc_freeze=0, P_agc_nb_est=5, P_agc_write=0 */
1379         (0 << 15) | (0 << 14) | (5 << 11) | (0 << 10) | (0 << 9) | (0 << 8)
1380         | (3 << 5) | (0 << 4) | (5 << 1) | (0 << 0),
1381
1382         787,
1383         10,
1384
1385         0,
1386         118,
1387
1388         0,
1389         3530,
1390         1,
1391         5,
1392
1393         0,
1394         0,
1395
1396         65535,
1397         0,
1398
1399         0,
1400         32,
1401         114,
1402         143,
1403         144,
1404         114,
1405         227,
1406         116,
1407         117,
1408
1409         28,
1410         26,
1411         31,
1412         51,
1413
1414         0,
1415         }
1416 };
1417
1418 static struct dibx000_bandwidth_config dib8090_pll_config_12mhz = {
1419         54000, 13500,
1420         1, 18, 3, 1, 0,
1421         0, 0, 1, 1, 2,
1422         (3 << 14) | (1 << 12) | (599 << 0),
1423         (0 << 25) | 0,
1424         20199727,
1425         12000000,
1426 };
1427
1428 static int dib8090_get_adc_power(struct dvb_frontend *fe)
1429 {
1430         return dib8000_get_adc_power(fe, 1);
1431 }
1432
1433 static struct dib8000_config dib809x_dib8000_config[2] = {
1434         {
1435         .output_mpeg2_in_188_bytes = 1,
1436
1437         .agc_config_count = 2,
1438         .agc = dib8090_agc_config,
1439         .agc_control = dib0090_dcc_freq,
1440         .pll = &dib8090_pll_config_12mhz,
1441         .tuner_is_baseband = 1,
1442
1443         .gpio_dir = DIB8000_GPIO_DEFAULT_DIRECTIONS,
1444         .gpio_val = DIB8000_GPIO_DEFAULT_VALUES,
1445         .gpio_pwm_pos = DIB8000_GPIO_DEFAULT_PWM_POS,
1446
1447         .hostbus_diversity = 1,
1448         .div_cfg = 0x31,
1449         .output_mode = OUTMODE_MPEG2_FIFO,
1450         .drives = 0x2d98,
1451         .diversity_delay = 48,
1452         .refclksel = 3,
1453         }, {
1454         .output_mpeg2_in_188_bytes = 1,
1455
1456         .agc_config_count = 2,
1457         .agc = dib8090_agc_config,
1458         .agc_control = dib0090_dcc_freq,
1459         .pll = &dib8090_pll_config_12mhz,
1460         .tuner_is_baseband = 1,
1461
1462         .gpio_dir = DIB8000_GPIO_DEFAULT_DIRECTIONS,
1463         .gpio_val = DIB8000_GPIO_DEFAULT_VALUES,
1464         .gpio_pwm_pos = DIB8000_GPIO_DEFAULT_PWM_POS,
1465
1466         .hostbus_diversity = 1,
1467         .div_cfg = 0x31,
1468         .output_mode = OUTMODE_DIVERSITY,
1469         .drives = 0x2d08,
1470         .diversity_delay = 1,
1471         .refclksel = 3,
1472         }
1473 };
1474
1475 static struct dib0090_wbd_slope dib8090_wbd_table[] = {
1476         /* max freq ; cold slope ; cold offset ; warm slope ; warm offset ; wbd gain */
1477         { 120,     0, 500,  0,   500, 4 }, /* CBAND */
1478         { 170,     0, 450,  0,   450, 4 }, /* CBAND */
1479         { 380,    48, 373, 28,   259, 6 }, /* VHF */
1480         { 860,    34, 700, 36,   616, 6 }, /* high UHF */
1481         { 0xFFFF, 34, 700, 36,   616, 6 }, /* default */
1482 };
1483
1484 static struct dib0090_config dib809x_dib0090_config = {
1485         .io.pll_bypass = 1,
1486         .io.pll_range = 1,
1487         .io.pll_prediv = 1,
1488         .io.pll_loopdiv = 20,
1489         .io.adc_clock_ratio = 8,
1490         .io.pll_int_loop_filt = 0,
1491         .io.clock_khz = 12000,
1492         .reset = dib80xx_tuner_reset,
1493         .sleep = dib80xx_tuner_sleep,
1494         .clkouttobamse = 1,
1495         .analog_output = 1,
1496         .i2c_address = DEFAULT_DIB0090_I2C_ADDRESS,
1497         .use_pwm_agc = 1,
1498         .clkoutdrive = 1,
1499         .get_adc_power = dib8090_get_adc_power,
1500         .freq_offset_khz_uhf = -63,
1501         .freq_offset_khz_vhf = -143,
1502         .wbd = dib8090_wbd_table,
1503         .fref_clock_ratio = 6,
1504 };
1505
1506 static int dib8096_set_param_override(struct dvb_frontend *fe,
1507                 struct dvb_frontend_parameters *fep)
1508 {
1509         struct dvb_usb_adapter *adap = fe->dvb->priv;
1510         struct dib0700_adapter_state *state = adap->priv;
1511         u8 band = BAND_OF_FREQUENCY(fep->frequency/1000);
1512         u16 target;
1513         int ret = 0;
1514         enum frontend_tune_state tune_state = CT_SHUTDOWN;
1515         u16 ltgain, rf_gain_limit;
1516
1517         ret = state->set_param_save(fe, fep);
1518         if (ret < 0)
1519                 return ret;
1520
1521         target = (dib0090_get_wbd_target(fe) * 8 * 18 / 33 + 1) / 2;
1522         dib8000_set_wbd_ref(fe, target);
1523
1524
1525         if (band == BAND_CBAND) {
1526                 deb_info("tuning in CBAND - soft-AGC startup\n");
1527                 dib0090_set_tune_state(fe, CT_AGC_START);
1528                 do {
1529                         ret = dib0090_gain_control(fe);
1530                         msleep(ret);
1531                         tune_state = dib0090_get_tune_state(fe);
1532                         if (tune_state == CT_AGC_STEP_0)
1533                                 dib8000_set_gpio(fe, 6, 0, 1);
1534                         else if (tune_state == CT_AGC_STEP_1) {
1535                                 dib0090_get_current_gain(fe, NULL, NULL, &rf_gain_limit, &ltgain);
1536                                 if (rf_gain_limit == 0)
1537                                         dib8000_set_gpio(fe, 6, 0, 0);
1538                         }
1539                 } while (tune_state < CT_AGC_STOP);
1540                 dib0090_pwm_gain_reset(fe);
1541                 dib8000_pwm_agc_reset(fe);
1542                 dib8000_set_tune_state(fe, CT_DEMOD_START);
1543         } else {
1544                 deb_info("not tuning in CBAND - standard AGC startup\n");
1545                 dib0090_pwm_gain_reset(fe);
1546         }
1547
1548         return 0;
1549 }
1550
1551 static int dib809x_tuner_attach(struct dvb_usb_adapter *adap)
1552 {
1553         struct dib0700_adapter_state *st = adap->priv;
1554         struct i2c_adapter *tun_i2c = dib8000_get_i2c_master(adap->fe_adap[0].fe, DIBX000_I2C_INTERFACE_TUNER, 1);
1555
1556         if (dvb_attach(dib0090_register, adap->fe_adap[0].fe, tun_i2c, &dib809x_dib0090_config) == NULL)
1557                 return -ENODEV;
1558
1559         st->set_param_save = adap->fe_adap[0].fe->ops.tuner_ops.set_params;
1560         adap->fe_adap[0].fe->ops.tuner_ops.set_params = dib8096_set_param_override;
1561         return 0;
1562 }
1563
1564 static int stk809x_frontend_attach(struct dvb_usb_adapter *adap)
1565 {
1566         dib0700_set_gpio(adap->dev, GPIO6, GPIO_OUT, 1);
1567         msleep(10);
1568         dib0700_set_gpio(adap->dev, GPIO9, GPIO_OUT, 1);
1569         dib0700_set_gpio(adap->dev, GPIO4, GPIO_OUT, 1);
1570         dib0700_set_gpio(adap->dev, GPIO7, GPIO_OUT, 1);
1571
1572         dib0700_set_gpio(adap->dev, GPIO10, GPIO_OUT, 0);
1573
1574         dib0700_ctrl_clock(adap->dev, 72, 1);
1575
1576         msleep(10);
1577         dib0700_set_gpio(adap->dev, GPIO10, GPIO_OUT, 1);
1578         msleep(10);
1579         dib0700_set_gpio(adap->dev, GPIO0, GPIO_OUT, 1);
1580
1581         dib8000_i2c_enumeration(&adap->dev->i2c_adap, 1, 18, 0x80);
1582
1583         adap->fe_adap[0].fe = dvb_attach(dib8000_attach, &adap->dev->i2c_adap, 0x80, &dib809x_dib8000_config[0]);
1584
1585         return adap->fe_adap[0].fe == NULL ?  -ENODEV : 0;
1586 }
1587
1588 static int nim8096md_tuner_attach(struct dvb_usb_adapter *adap)
1589 {
1590         struct dib0700_adapter_state *st = adap->priv;
1591         struct i2c_adapter *tun_i2c;
1592         struct dvb_frontend *fe_slave  = dib8000_get_slave_frontend(adap->fe_adap[0].fe, 1);
1593
1594         if (fe_slave) {
1595                 tun_i2c = dib8000_get_i2c_master(fe_slave, DIBX000_I2C_INTERFACE_TUNER, 1);
1596                 if (dvb_attach(dib0090_register, fe_slave, tun_i2c, &dib809x_dib0090_config) == NULL)
1597                         return -ENODEV;
1598                 fe_slave->dvb = adap->fe_adap[0].fe->dvb;
1599                 fe_slave->ops.tuner_ops.set_params = dib8096_set_param_override;
1600         }
1601         tun_i2c = dib8000_get_i2c_master(adap->fe_adap[0].fe, DIBX000_I2C_INTERFACE_TUNER, 1);
1602         if (dvb_attach(dib0090_register, adap->fe_adap[0].fe, tun_i2c, &dib809x_dib0090_config) == NULL)
1603                 return -ENODEV;
1604
1605         st->set_param_save = adap->fe_adap[0].fe->ops.tuner_ops.set_params;
1606         adap->fe_adap[0].fe->ops.tuner_ops.set_params = dib8096_set_param_override;
1607
1608         return 0;
1609 }
1610
1611 static int nim8096md_frontend_attach(struct dvb_usb_adapter *adap)
1612 {
1613         struct dvb_frontend *fe_slave;
1614
1615         dib0700_set_gpio(adap->dev, GPIO6, GPIO_OUT, 0);
1616         msleep(20);
1617         dib0700_set_gpio(adap->dev, GPIO6, GPIO_OUT, 1);
1618         msleep(1000);
1619         dib0700_set_gpio(adap->dev, GPIO9, GPIO_OUT, 1);
1620         dib0700_set_gpio(adap->dev, GPIO4, GPIO_OUT, 1);
1621         dib0700_set_gpio(adap->dev, GPIO7, GPIO_OUT, 1);
1622
1623         dib0700_set_gpio(adap->dev, GPIO10, GPIO_OUT, 0);
1624
1625         dib0700_ctrl_clock(adap->dev, 72, 1);
1626
1627         msleep(20);
1628         dib0700_set_gpio(adap->dev, GPIO10, GPIO_OUT, 1);
1629         msleep(20);
1630         dib0700_set_gpio(adap->dev, GPIO0, GPIO_OUT, 1);
1631
1632         dib8000_i2c_enumeration(&adap->dev->i2c_adap, 2, 18, 0x80);
1633
1634         adap->fe_adap[0].fe = dvb_attach(dib8000_attach, &adap->dev->i2c_adap, 0x80, &dib809x_dib8000_config[0]);
1635         if (adap->fe_adap[0].fe == NULL)
1636                 return -ENODEV;
1637
1638         fe_slave = dvb_attach(dib8000_attach, &adap->dev->i2c_adap, 0x82, &dib809x_dib8000_config[1]);
1639         dib8000_set_slave_frontend(adap->fe_adap[0].fe, fe_slave);
1640
1641         return fe_slave == NULL ?  -ENODEV : 0;
1642 }
1643
1644 /* STK9090M */
1645 static int dib90x0_pid_filter(struct dvb_usb_adapter *adapter, int index, u16 pid, int onoff)
1646 {
1647         return dib9000_fw_pid_filter(adapter->fe_adap[0].fe, index, pid, onoff);
1648 }
1649
1650 static int dib90x0_pid_filter_ctrl(struct dvb_usb_adapter *adapter, int onoff)
1651 {
1652         return dib9000_fw_pid_filter_ctrl(adapter->fe_adap[0].fe, onoff);
1653 }
1654
1655 static int dib90x0_tuner_reset(struct dvb_frontend *fe, int onoff)
1656 {
1657         return dib9000_set_gpio(fe, 5, 0, !onoff);
1658 }
1659
1660 static int dib90x0_tuner_sleep(struct dvb_frontend *fe, int onoff)
1661 {
1662         return dib9000_set_gpio(fe, 0, 0, onoff);
1663 }
1664
1665 static int dib01x0_pmu_update(struct i2c_adapter *i2c, u16 *data, u8 len)
1666 {
1667         u8 wb[4] = { 0xc >> 8, 0xc & 0xff, 0, 0 };
1668         u8 rb[2];
1669         struct i2c_msg msg[2] = {
1670                 {.addr = 0x1e >> 1, .flags = 0, .buf = wb, .len = 2},
1671                 {.addr = 0x1e >> 1, .flags = I2C_M_RD, .buf = rb, .len = 2},
1672         };
1673         u8 index_data;
1674
1675         dibx000_i2c_set_speed(i2c, 250);
1676
1677         if (i2c_transfer(i2c, msg, 2) != 2)
1678                 return -EIO;
1679
1680         switch (rb[0] << 8 | rb[1]) {
1681         case 0:
1682                         deb_info("Found DiB0170 rev1: This version of DiB0170 is not supported any longer.\n");
1683                         return -EIO;
1684         case 1:
1685                         deb_info("Found DiB0170 rev2");
1686                         break;
1687         case 2:
1688                         deb_info("Found DiB0190 rev2");
1689                         break;
1690         default:
1691                         deb_info("DiB01x0 not found");
1692                         return -EIO;
1693         }
1694
1695         for (index_data = 0; index_data < len; index_data += 2) {
1696                 wb[2] = (data[index_data + 1] >> 8) & 0xff;
1697                 wb[3] = (data[index_data + 1]) & 0xff;
1698
1699                 if (data[index_data] == 0) {
1700                         wb[0] = (data[index_data] >> 8) & 0xff;
1701                         wb[1] = (data[index_data]) & 0xff;
1702                         msg[0].len = 2;
1703                         if (i2c_transfer(i2c, msg, 2) != 2)
1704                                 return -EIO;
1705                         wb[2] |= rb[0];
1706                         wb[3] |= rb[1] & ~(3 << 4);
1707                 }
1708
1709                 wb[0] = (data[index_data] >> 8)&0xff;
1710                 wb[1] = (data[index_data])&0xff;
1711                 msg[0].len = 4;
1712                 if (i2c_transfer(i2c, &msg[0], 1) != 1)
1713                         return -EIO;
1714         }
1715         return 0;
1716 }
1717
1718 static struct dib9000_config stk9090m_config = {
1719         .output_mpeg2_in_188_bytes = 1,
1720         .output_mode = OUTMODE_MPEG2_FIFO,
1721         .vcxo_timer = 279620,
1722         .timing_frequency = 20452225,
1723         .demod_clock_khz = 60000,
1724         .xtal_clock_khz = 30000,
1725         .if_drives = (0 << 15) | (1 << 13) | (0 << 12) | (3 << 10) | (0 << 9) | (1 << 7) | (0 << 6) | (0 << 4) | (1 << 3) | (1 << 1) | (0),
1726         .subband = {
1727                 2,
1728                 {
1729                         { 240, { BOARD_GPIO_COMPONENT_DEMOD, BOARD_GPIO_FUNCTION_SUBBAND_GPIO, 0x0008, 0x0000, 0x0008 } }, /* GPIO 3 to 1 for VHF */
1730                         { 890, { BOARD_GPIO_COMPONENT_DEMOD, BOARD_GPIO_FUNCTION_SUBBAND_GPIO, 0x0008, 0x0000, 0x0000 } }, /* GPIO 3 to 0 for UHF */
1731                         { 0 },
1732                 },
1733         },
1734         .gpio_function = {
1735                 { .component = BOARD_GPIO_COMPONENT_DEMOD, .function = BOARD_GPIO_FUNCTION_COMPONENT_ON, .mask = 0x10 | 0x21, .direction = 0 & ~0x21, .value = (0x10 & ~0x1) | 0x20 },
1736                 { .component = BOARD_GPIO_COMPONENT_DEMOD, .function = BOARD_GPIO_FUNCTION_COMPONENT_OFF, .mask = 0x10 | 0x21, .direction = 0 & ~0x21, .value = 0 | 0x21 },
1737         },
1738 };
1739
1740 static struct dib9000_config nim9090md_config[2] = {
1741         {
1742                 .output_mpeg2_in_188_bytes = 1,
1743                 .output_mode = OUTMODE_MPEG2_FIFO,
1744                 .vcxo_timer = 279620,
1745                 .timing_frequency = 20452225,
1746                 .demod_clock_khz = 60000,
1747                 .xtal_clock_khz = 30000,
1748                 .if_drives = (0 << 15) | (1 << 13) | (0 << 12) | (3 << 10) | (0 << 9) | (1 << 7) | (0 << 6) | (0 << 4) | (1 << 3) | (1 << 1) | (0),
1749         }, {
1750                 .output_mpeg2_in_188_bytes = 1,
1751                 .output_mode = OUTMODE_DIVERSITY,
1752                 .vcxo_timer = 279620,
1753                 .timing_frequency = 20452225,
1754                 .demod_clock_khz = 60000,
1755                 .xtal_clock_khz = 30000,
1756                 .if_drives = (0 << 15) | (1 << 13) | (0 << 12) | (3 << 10) | (0 << 9) | (1 << 7) | (0 << 6) | (0 << 4) | (1 << 3) | (1 << 1) | (0),
1757                 .subband = {
1758                         2,
1759                         {
1760                                 { 240, { BOARD_GPIO_COMPONENT_DEMOD, BOARD_GPIO_FUNCTION_SUBBAND_GPIO, 0x0006, 0x0000, 0x0006 } }, /* GPIO 1 and 2 to 1 for VHF */
1761                                 { 890, { BOARD_GPIO_COMPONENT_DEMOD, BOARD_GPIO_FUNCTION_SUBBAND_GPIO, 0x0006, 0x0000, 0x0000 } }, /* GPIO 1 and 2 to 0 for UHF */
1762                                 { 0 },
1763                         },
1764                 },
1765                 .gpio_function = {
1766                         { .component = BOARD_GPIO_COMPONENT_DEMOD, .function = BOARD_GPIO_FUNCTION_COMPONENT_ON, .mask = 0x10 | 0x21, .direction = 0 & ~0x21, .value = (0x10 & ~0x1) | 0x20 },
1767                         { .component = BOARD_GPIO_COMPONENT_DEMOD, .function = BOARD_GPIO_FUNCTION_COMPONENT_OFF, .mask = 0x10 | 0x21, .direction = 0 & ~0x21, .value = 0 | 0x21 },
1768                 },
1769         }
1770 };
1771
1772 static struct dib0090_config dib9090_dib0090_config = {
1773         .io.pll_bypass = 0,
1774         .io.pll_range = 1,
1775         .io.pll_prediv = 1,
1776         .io.pll_loopdiv = 8,
1777         .io.adc_clock_ratio = 8,
1778         .io.pll_int_loop_filt = 0,
1779         .io.clock_khz = 30000,
1780         .reset = dib90x0_tuner_reset,
1781         .sleep = dib90x0_tuner_sleep,
1782         .clkouttobamse = 0,
1783         .analog_output = 0,
1784         .use_pwm_agc = 0,
1785         .clkoutdrive = 0,
1786         .freq_offset_khz_uhf = 0,
1787         .freq_offset_khz_vhf = 0,
1788 };
1789
1790 static struct dib0090_config nim9090md_dib0090_config[2] = {
1791         {
1792                 .io.pll_bypass = 0,
1793                 .io.pll_range = 1,
1794                 .io.pll_prediv = 1,
1795                 .io.pll_loopdiv = 8,
1796                 .io.adc_clock_ratio = 8,
1797                 .io.pll_int_loop_filt = 0,
1798                 .io.clock_khz = 30000,
1799                 .reset = dib90x0_tuner_reset,
1800                 .sleep = dib90x0_tuner_sleep,
1801                 .clkouttobamse = 1,
1802                 .analog_output = 0,
1803                 .use_pwm_agc = 0,
1804                 .clkoutdrive = 0,
1805                 .freq_offset_khz_uhf = 0,
1806                 .freq_offset_khz_vhf = 0,
1807         }, {
1808                 .io.pll_bypass = 0,
1809                 .io.pll_range = 1,
1810                 .io.pll_prediv = 1,
1811                 .io.pll_loopdiv = 8,
1812                 .io.adc_clock_ratio = 8,
1813                 .io.pll_int_loop_filt = 0,
1814                 .io.clock_khz = 30000,
1815                 .reset = dib90x0_tuner_reset,
1816                 .sleep = dib90x0_tuner_sleep,
1817                 .clkouttobamse = 0,
1818                 .analog_output = 0,
1819                 .use_pwm_agc = 0,
1820                 .clkoutdrive = 0,
1821                 .freq_offset_khz_uhf = 0,
1822                 .freq_offset_khz_vhf = 0,
1823         }
1824 };
1825
1826
1827 static int stk9090m_frontend_attach(struct dvb_usb_adapter *adap)
1828 {
1829         struct dib0700_adapter_state *state = adap->priv;
1830         struct dib0700_state *st = adap->dev->priv;
1831         u32 fw_version;
1832
1833         /* Make use of the new i2c functions from FW 1.20 */
1834         dib0700_get_version(adap->dev, NULL, NULL, &fw_version, NULL);
1835         if (fw_version >= 0x10200)
1836                 st->fw_use_new_i2c_api = 1;
1837         dib0700_set_i2c_speed(adap->dev, 340);
1838
1839         dib0700_set_gpio(adap->dev, GPIO6, GPIO_OUT, 1);
1840         msleep(20);
1841         dib0700_set_gpio(adap->dev, GPIO9, GPIO_OUT, 1);
1842         dib0700_set_gpio(adap->dev, GPIO4, GPIO_OUT, 1);
1843         dib0700_set_gpio(adap->dev, GPIO7, GPIO_OUT, 1);
1844         dib0700_set_gpio(adap->dev, GPIO10, GPIO_OUT, 0);
1845
1846         dib0700_ctrl_clock(adap->dev, 72, 1);
1847
1848         msleep(20);
1849         dib0700_set_gpio(adap->dev, GPIO10, GPIO_OUT, 1);
1850         msleep(20);
1851         dib0700_set_gpio(adap->dev, GPIO0, GPIO_OUT, 1);
1852
1853         dib9000_i2c_enumeration(&adap->dev->i2c_adap, 1, 0x10, 0x80);
1854
1855         if (request_firmware(&state->frontend_firmware, "dib9090.fw", &adap->dev->udev->dev)) {
1856                 deb_info("%s: Upload failed. (file not found?)\n", __func__);
1857                 return -ENODEV;
1858         } else {
1859                 deb_info("%s: firmware read %Zu bytes.\n", __func__, state->frontend_firmware->size);
1860         }
1861         stk9090m_config.microcode_B_fe_size = state->frontend_firmware->size;
1862         stk9090m_config.microcode_B_fe_buffer = state->frontend_firmware->data;
1863
1864         adap->fe_adap[0].fe = dvb_attach(dib9000_attach, &adap->dev->i2c_adap, 0x80, &stk9090m_config);
1865
1866         return adap->fe_adap[0].fe == NULL ?  -ENODEV : 0;
1867 }
1868
1869 static int dib9090_tuner_attach(struct dvb_usb_adapter *adap)
1870 {
1871         struct dib0700_adapter_state *state = adap->priv;
1872         struct i2c_adapter *i2c = dib9000_get_tuner_interface(adap->fe_adap[0].fe);
1873         u16 data_dib190[10] = {
1874                 1, 0x1374,
1875                 2, 0x01a2,
1876                 7, 0x0020,
1877                 0, 0x00ef,
1878                 8, 0x0486,
1879         };
1880
1881         if (dvb_attach(dib0090_fw_register, adap->fe_adap[0].fe, i2c, &dib9090_dib0090_config) == NULL)
1882                 return -ENODEV;
1883         i2c = dib9000_get_i2c_master(adap->fe_adap[0].fe, DIBX000_I2C_INTERFACE_GPIO_1_2, 0);
1884         if (dib01x0_pmu_update(i2c, data_dib190, 10) != 0)
1885                 return -ENODEV;
1886         dib0700_set_i2c_speed(adap->dev, 2000);
1887         if (dib9000_firmware_post_pll_init(adap->fe_adap[0].fe) < 0)
1888                 return -ENODEV;
1889         release_firmware(state->frontend_firmware);
1890         return 0;
1891 }
1892
1893 static int nim9090md_frontend_attach(struct dvb_usb_adapter *adap)
1894 {
1895         struct dib0700_adapter_state *state = adap->priv;
1896         struct dib0700_state *st = adap->dev->priv;
1897         struct i2c_adapter *i2c;
1898         struct dvb_frontend *fe_slave;
1899         u32 fw_version;
1900
1901         /* Make use of the new i2c functions from FW 1.20 */
1902         dib0700_get_version(adap->dev, NULL, NULL, &fw_version, NULL);
1903         if (fw_version >= 0x10200)
1904                 st->fw_use_new_i2c_api = 1;
1905         dib0700_set_i2c_speed(adap->dev, 340);
1906
1907         dib0700_set_gpio(adap->dev, GPIO6, GPIO_OUT, 1);
1908         msleep(20);
1909         dib0700_set_gpio(adap->dev, GPIO9, GPIO_OUT, 1);
1910         dib0700_set_gpio(adap->dev, GPIO4, GPIO_OUT, 1);
1911         dib0700_set_gpio(adap->dev, GPIO7, GPIO_OUT, 1);
1912         dib0700_set_gpio(adap->dev, GPIO10, GPIO_OUT, 0);
1913
1914         dib0700_ctrl_clock(adap->dev, 72, 1);
1915
1916         msleep(20);
1917         dib0700_set_gpio(adap->dev, GPIO10, GPIO_OUT, 1);
1918         msleep(20);
1919         dib0700_set_gpio(adap->dev, GPIO0, GPIO_OUT, 1);
1920
1921         if (request_firmware(&state->frontend_firmware, "dib9090.fw", &adap->dev->udev->dev)) {
1922                 deb_info("%s: Upload failed. (file not found?)\n", __func__);
1923                 return -EIO;
1924         } else {
1925                 deb_info("%s: firmware read %Zu bytes.\n", __func__, state->frontend_firmware->size);
1926         }
1927         nim9090md_config[0].microcode_B_fe_size = state->frontend_firmware->size;
1928         nim9090md_config[0].microcode_B_fe_buffer = state->frontend_firmware->data;
1929         nim9090md_config[1].microcode_B_fe_size = state->frontend_firmware->size;
1930         nim9090md_config[1].microcode_B_fe_buffer = state->frontend_firmware->data;
1931
1932         dib9000_i2c_enumeration(&adap->dev->i2c_adap, 1, 0x20, 0x80);
1933         adap->fe_adap[0].fe = dvb_attach(dib9000_attach, &adap->dev->i2c_adap, 0x80, &nim9090md_config[0]);
1934
1935         if (adap->fe_adap[0].fe == NULL)
1936                 return -ENODEV;
1937
1938         i2c = dib9000_get_i2c_master(adap->fe_adap[0].fe, DIBX000_I2C_INTERFACE_GPIO_3_4, 0);
1939         dib9000_i2c_enumeration(i2c, 1, 0x12, 0x82);
1940
1941         fe_slave = dvb_attach(dib9000_attach, i2c, 0x82, &nim9090md_config[1]);
1942         dib9000_set_slave_frontend(adap->fe_adap[0].fe, fe_slave);
1943
1944         return fe_slave == NULL ?  -ENODEV : 0;
1945 }
1946
1947 static int nim9090md_tuner_attach(struct dvb_usb_adapter *adap)
1948 {
1949         struct dib0700_adapter_state *state = adap->priv;
1950         struct i2c_adapter *i2c;
1951         struct dvb_frontend *fe_slave;
1952         u16 data_dib190[10] = {
1953                 1, 0x5374,
1954                 2, 0x01ae,
1955                 7, 0x0020,
1956                 0, 0x00ef,
1957                 8, 0x0406,
1958         };
1959         i2c = dib9000_get_tuner_interface(adap->fe_adap[0].fe);
1960         if (dvb_attach(dib0090_fw_register, adap->fe_adap[0].fe, i2c, &nim9090md_dib0090_config[0]) == NULL)
1961                 return -ENODEV;
1962         i2c = dib9000_get_i2c_master(adap->fe_adap[0].fe, DIBX000_I2C_INTERFACE_GPIO_1_2, 0);
1963         if (dib01x0_pmu_update(i2c, data_dib190, 10) < 0)
1964                 return -ENODEV;
1965         dib0700_set_i2c_speed(adap->dev, 2000);
1966         if (dib9000_firmware_post_pll_init(adap->fe_adap[0].fe) < 0)
1967                 return -ENODEV;
1968
1969         fe_slave = dib9000_get_slave_frontend(adap->fe_adap[0].fe, 1);
1970         if (fe_slave != NULL) {
1971                 i2c = dib9000_get_component_bus_interface(adap->fe_adap[0].fe);
1972                 dib9000_set_i2c_adapter(fe_slave, i2c);
1973
1974                 i2c = dib9000_get_tuner_interface(fe_slave);
1975                 if (dvb_attach(dib0090_fw_register, fe_slave, i2c, &nim9090md_dib0090_config[1]) == NULL)
1976                         return -ENODEV;
1977                 fe_slave->dvb = adap->fe_adap[0].fe->dvb;
1978                 dib9000_fw_set_component_bus_speed(adap->fe_adap[0].fe, 2000);
1979                 if (dib9000_firmware_post_pll_init(fe_slave) < 0)
1980                         return -ENODEV;
1981         }
1982         release_firmware(state->frontend_firmware);
1983
1984         return 0;
1985 }
1986
1987 /* NIM7090 */
1988 struct dib7090p_best_adc {
1989         u32 timf;
1990         u32 pll_loopdiv;
1991         u32 pll_prediv;
1992 };
1993
1994 static int dib7090p_get_best_sampling(struct dvb_frontend *fe , struct dib7090p_best_adc *adc)
1995 {
1996         u8 spur = 0, prediv = 0, loopdiv = 0, min_prediv = 1, max_prediv = 1;
1997
1998         u16 xtal = 12000;
1999         u32 fcp_min = 1900;  /* PLL Minimum Frequency comparator KHz */
2000         u32 fcp_max = 20000; /* PLL Maximum Frequency comparator KHz */
2001         u32 fdem_max = 76000;
2002         u32 fdem_min = 69500;
2003         u32 fcp = 0, fs = 0, fdem = 0;
2004         u32 harmonic_id = 0;
2005
2006         adc->pll_loopdiv = loopdiv;
2007         adc->pll_prediv = prediv;
2008         adc->timf = 0;
2009
2010         deb_info("bandwidth = %d fdem_min =%d", fe->dtv_property_cache.bandwidth_hz, fdem_min);
2011
2012         /* Find Min and Max prediv */
2013         while ((xtal/max_prediv) >= fcp_min)
2014                 max_prediv++;
2015
2016         max_prediv--;
2017         min_prediv = max_prediv;
2018         while ((xtal/min_prediv) <= fcp_max) {
2019                 min_prediv--;
2020                 if (min_prediv == 1)
2021                         break;
2022         }
2023         deb_info("MIN prediv = %d : MAX prediv = %d", min_prediv, max_prediv);
2024
2025         min_prediv = 2;
2026
2027         for (prediv = min_prediv ; prediv < max_prediv; prediv++) {
2028                 fcp = xtal / prediv;
2029                 if (fcp > fcp_min && fcp < fcp_max) {
2030                         for (loopdiv = 1 ; loopdiv < 64 ; loopdiv++) {
2031                                 fdem = ((xtal/prediv) * loopdiv);
2032                                 fs   = fdem / 4;
2033                                 /* test min/max system restrictions */
2034
2035                                 if ((fdem >= fdem_min) && (fdem <= fdem_max) && (fs >= fe->dtv_property_cache.bandwidth_hz/1000)) {
2036                                         spur = 0;
2037                                         /* test fs harmonics positions */
2038                                         for (harmonic_id = (fe->dtv_property_cache.frequency / (1000*fs)) ;  harmonic_id <= ((fe->dtv_property_cache.frequency / (1000*fs))+1) ; harmonic_id++) {
2039                                                 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)))) {
2040                                                         spur = 1;
2041                                                         break;
2042                                                 }
2043                                         }
2044
2045                                         if (!spur) {
2046                                                 adc->pll_loopdiv = loopdiv;
2047                                                 adc->pll_prediv = prediv;
2048                                                 adc->timf = 2396745143UL/fdem*(1 << 9);
2049                                                 adc->timf += ((2396745143UL%fdem) << 9)/fdem;
2050                                                 deb_info("loopdiv=%i prediv=%i timf=%i", loopdiv, prediv, adc->timf);
2051                                                 break;
2052                                         }
2053                                 }
2054                         }
2055                 }
2056                 if (!spur)
2057                         break;
2058         }
2059
2060
2061         if (adc->pll_loopdiv == 0 && adc->pll_prediv == 0)
2062                 return -EINVAL;
2063         else
2064                 return 0;
2065 }
2066
2067 static int dib7090_agc_startup(struct dvb_frontend *fe, struct dvb_frontend_parameters *fep)
2068 {
2069         struct dvb_usb_adapter *adap = fe->dvb->priv;
2070         struct dib0700_adapter_state *state = adap->priv;
2071         struct dibx000_bandwidth_config pll;
2072         u16 target;
2073         struct dib7090p_best_adc adc;
2074         int ret;
2075
2076         ret = state->set_param_save(fe, fep);
2077         if (ret < 0)
2078                 return ret;
2079
2080         memset(&pll, 0, sizeof(struct dibx000_bandwidth_config));
2081         dib0090_pwm_gain_reset(fe);
2082         target = (dib0090_get_wbd_target(fe) * 8 + 1) / 2;
2083         dib7000p_set_wbd_ref(fe, target);
2084
2085         if (dib7090p_get_best_sampling(fe, &adc) == 0) {
2086                 pll.pll_ratio  = adc.pll_loopdiv;
2087                 pll.pll_prediv = adc.pll_prediv;
2088
2089                 dib7000p_update_pll(fe, &pll);
2090                 dib7000p_ctrl_timf(fe, DEMOD_TIMF_SET, adc.timf);
2091         }
2092         return 0;
2093 }
2094
2095 static int dib7090_agc_restart(struct dvb_frontend *fe, u8 restart)
2096 {
2097         deb_info("AGC restart callback: %d", restart);
2098         if (restart == 0) /* before AGC startup */
2099                 dib0090_set_dc_servo(fe, 1);
2100         return 0;
2101 }
2102
2103 static int dib7090e_update_lna(struct dvb_frontend *fe, u16 agc_global)
2104 {
2105         u16 agc1 = 0, agc2, wbd = 0, wbd_target, wbd_offset, threshold_agc1;
2106         s16 wbd_delta;
2107
2108         if ((fe->dtv_property_cache.frequency) < 400000000)
2109                 threshold_agc1 = 25000;
2110         else
2111                 threshold_agc1 = 30000;
2112
2113         wbd_target = (dib0090_get_wbd_target(fe)*8+1)/2;
2114         wbd_offset = dib0090_get_wbd_offset(fe);
2115         dib7000p_get_agc_values(fe, NULL, &agc1, &agc2, &wbd);
2116         wbd_delta = (s16)wbd - (((s16)wbd_offset+10)*4) ;
2117
2118         deb_info("update lna, agc_global=%d agc1=%d agc2=%d",
2119                         agc_global, agc1, agc2);
2120         deb_info("update lna, wbd=%d wbd target=%d wbd offset=%d wbd delta=%d",
2121                         wbd, wbd_target, wbd_offset, wbd_delta);
2122
2123         if ((agc1 < threshold_agc1) && (wbd_delta > 0)) {
2124                 dib0090_set_switch(fe, 1, 1, 1);
2125                 dib0090_set_vga(fe, 0);
2126                 dib0090_update_rframp_7090(fe, 0);
2127                 dib0090_update_tuning_table_7090(fe, 0);
2128         } else {
2129                 dib0090_set_vga(fe, 1);
2130                 dib0090_update_rframp_7090(fe, 1);
2131                 dib0090_update_tuning_table_7090(fe, 1);
2132                 dib0090_set_switch(fe, 0, 0, 0);
2133         }
2134
2135         return 0;
2136 }
2137
2138 static struct dib0090_wbd_slope dib7090_wbd_table[] = {
2139         { 380,   81, 850, 64, 540,  4},
2140         { 860,   51, 866, 21,  375, 4},
2141         {1700,    0, 250, 0,   100, 6},
2142         {2600,    0, 250, 0,   100, 6},
2143         { 0xFFFF, 0,   0, 0,   0,   0},
2144 };
2145
2146 static struct dib0090_wbd_slope dib7090e_wbd_table[] = {
2147         { 380,   81, 850, 64, 540,      4},
2148         { 700,   51, 866, 21,  320,     4},
2149         { 860,   48, 666, 18,  330,     6},
2150         {1700,    0, 250, 0,   100, 6},
2151         {2600,    0, 250, 0,   100, 6},
2152         { 0xFFFF, 0,   0, 0,   0,       0},
2153 };
2154
2155 static struct dibx000_agc_config dib7090_agc_config[2] = {
2156         {
2157                 .band_caps      = BAND_UHF,
2158                 /* 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,
2159                 * 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 */
2160                 .setup          = (0 << 15) | (0 << 14) | (5 << 11) | (0 << 10) | (0 << 9) | (0 << 8) | (3 << 5) | (0 << 4) | (5 << 1) | (0 << 0),
2161
2162                 .inv_gain       = 687,
2163                 .time_stabiliz  = 10,
2164
2165                 .alpha_level    = 0,
2166                 .thlock         = 118,
2167
2168                 .wbd_inv        = 0,
2169                 .wbd_ref        = 1200,
2170                 .wbd_sel        = 3,
2171                 .wbd_alpha      = 5,
2172
2173                 .agc1_max       = 65535,
2174                 .agc1_min       = 0,
2175
2176                 .agc2_max       = 65535,
2177                 .agc2_min       = 0,
2178
2179                 .agc1_pt1       = 0,
2180                 .agc1_pt2       = 32,
2181                 .agc1_pt3       = 114,
2182                 .agc1_slope1    = 143,
2183                 .agc1_slope2    = 144,
2184                 .agc2_pt1       = 114,
2185                 .agc2_pt2       = 227,
2186                 .agc2_slope1    = 116,
2187                 .agc2_slope2    = 117,
2188
2189                 .alpha_mant     = 18,
2190                 .alpha_exp      = 0,
2191                 .beta_mant      = 20,
2192                 .beta_exp       = 59,
2193
2194                 .perform_agc_softsplit = 0,
2195         } , {
2196                 .band_caps      = BAND_FM | BAND_VHF | BAND_CBAND,
2197                 /* 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,
2198                 * 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 */
2199                 .setup          = (0 << 15) | (0 << 14) | (5 << 11) | (0 << 10) | (0 << 9) | (0 << 8) | (3 << 5) | (0 << 4) | (5 << 1) | (0 << 0),
2200
2201                 .inv_gain       = 732,
2202                 .time_stabiliz  = 10,
2203
2204                 .alpha_level    = 0,
2205                 .thlock         = 118,
2206
2207                 .wbd_inv        = 0,
2208                 .wbd_ref        = 1200,
2209                 .wbd_sel        = 3,
2210                 .wbd_alpha      = 5,
2211
2212                 .agc1_max       = 65535,
2213                 .agc1_min       = 0,
2214
2215                 .agc2_max       = 65535,
2216                 .agc2_min       = 0,
2217
2218                 .agc1_pt1       = 0,
2219                 .agc1_pt2       = 0,
2220                 .agc1_pt3       = 98,
2221                 .agc1_slope1    = 0,
2222                 .agc1_slope2    = 167,
2223                 .agc2_pt1       = 98,
2224                 .agc2_pt2       = 255,
2225                 .agc2_slope1    = 104,
2226                 .agc2_slope2    = 0,
2227
2228                 .alpha_mant     = 18,
2229                 .alpha_exp      = 0,
2230                 .beta_mant      = 20,
2231                 .beta_exp       = 59,
2232
2233                 .perform_agc_softsplit = 0,
2234         }
2235 };
2236
2237 static struct dibx000_bandwidth_config dib7090_clock_config_12_mhz = {
2238         60000, 15000,
2239         1, 5, 0, 0, 0,
2240         0, 0, 1, 1, 2,
2241         (3 << 14) | (1 << 12) | (524 << 0),
2242         (0 << 25) | 0,
2243         20452225,
2244         15000000,
2245 };
2246
2247 static struct dib7000p_config nim7090_dib7000p_config = {
2248         .output_mpeg2_in_188_bytes  = 1,
2249         .hostbus_diversity                      = 1,
2250         .tuner_is_baseband                      = 1,
2251         .update_lna                                     = NULL,
2252
2253         .agc_config_count                       = 2,
2254         .agc                                            = dib7090_agc_config,
2255
2256         .bw                                                     = &dib7090_clock_config_12_mhz,
2257
2258         .gpio_dir                                       = DIB7000P_GPIO_DEFAULT_DIRECTIONS,
2259         .gpio_val                                       = DIB7000P_GPIO_DEFAULT_VALUES,
2260         .gpio_pwm_pos                           = DIB7000P_GPIO_DEFAULT_PWM_POS,
2261
2262         .pwm_freq_div                           = 0,
2263
2264         .agc_control                            = dib7090_agc_restart,
2265
2266         .spur_protect                           = 0,
2267         .disable_sample_and_hold        = 0,
2268         .enable_current_mirror          = 0,
2269         .diversity_delay                        = 0,
2270
2271         .output_mode                            = OUTMODE_MPEG2_FIFO,
2272         .enMpegOutput                           = 1,
2273 };
2274
2275 static struct dib7000p_config tfe7090pvr_dib7000p_config[2] = {
2276         {
2277                 .output_mpeg2_in_188_bytes  = 1,
2278                 .hostbus_diversity                      = 1,
2279                 .tuner_is_baseband                      = 1,
2280                 .update_lna                                     = NULL,
2281
2282                 .agc_config_count                       = 2,
2283                 .agc                                            = dib7090_agc_config,
2284
2285                 .bw                                                     = &dib7090_clock_config_12_mhz,
2286
2287                 .gpio_dir                                       = DIB7000P_GPIO_DEFAULT_DIRECTIONS,
2288                 .gpio_val                                       = DIB7000P_GPIO_DEFAULT_VALUES,
2289                 .gpio_pwm_pos                           = DIB7000P_GPIO_DEFAULT_PWM_POS,
2290
2291                 .pwm_freq_div                           = 0,
2292
2293                 .agc_control                            = dib7090_agc_restart,
2294
2295                 .spur_protect                           = 0,
2296                 .disable_sample_and_hold        = 0,
2297                 .enable_current_mirror          = 0,
2298                 .diversity_delay                        = 0,
2299
2300                 .output_mode                            = OUTMODE_MPEG2_PAR_GATED_CLK,
2301                 .default_i2c_addr                       = 0x90,
2302                 .enMpegOutput                           = 1,
2303         }, {
2304                 .output_mpeg2_in_188_bytes  = 1,
2305                 .hostbus_diversity                      = 1,
2306                 .tuner_is_baseband                      = 1,
2307                 .update_lna                                     = NULL,
2308
2309                 .agc_config_count                       = 2,
2310                 .agc                                            = dib7090_agc_config,
2311
2312                 .bw                                                     = &dib7090_clock_config_12_mhz,
2313
2314                 .gpio_dir                                       = DIB7000P_GPIO_DEFAULT_DIRECTIONS,
2315                 .gpio_val                                       = DIB7000P_GPIO_DEFAULT_VALUES,
2316                 .gpio_pwm_pos                           = DIB7000P_GPIO_DEFAULT_PWM_POS,
2317
2318                 .pwm_freq_div                           = 0,
2319
2320                 .agc_control                            = dib7090_agc_restart,
2321
2322                 .spur_protect                           = 0,
2323                 .disable_sample_and_hold        = 0,
2324                 .enable_current_mirror          = 0,
2325                 .diversity_delay                        = 0,
2326
2327                 .output_mode                            = OUTMODE_MPEG2_PAR_GATED_CLK,
2328                 .default_i2c_addr                       = 0x92,
2329                 .enMpegOutput                           = 0,
2330         }
2331 };
2332
2333 static struct dib7000p_config tfe7090e_dib7000p_config = {
2334         .output_mpeg2_in_188_bytes  = 1,
2335         .hostbus_diversity                      = 1,
2336         .tuner_is_baseband                      = 1,
2337         .update_lna                                     = dib7090e_update_lna,
2338
2339         .agc_config_count                       = 2,
2340         .agc                                            = dib7090_agc_config,
2341
2342         .bw                                                     = &dib7090_clock_config_12_mhz,
2343
2344         .gpio_dir                                       = DIB7000P_GPIO_DEFAULT_DIRECTIONS,
2345         .gpio_val                                       = DIB7000P_GPIO_DEFAULT_VALUES,
2346         .gpio_pwm_pos                           = DIB7000P_GPIO_DEFAULT_PWM_POS,
2347
2348         .pwm_freq_div                           = 0,
2349
2350         .agc_control                            = dib7090_agc_restart,
2351
2352         .spur_protect                           = 0,
2353         .disable_sample_and_hold        = 0,
2354         .enable_current_mirror          = 0,
2355         .diversity_delay                        = 0,
2356
2357         .output_mode                            = OUTMODE_MPEG2_FIFO,
2358         .enMpegOutput                           = 1,
2359 };
2360
2361 static const struct dib0090_config nim7090_dib0090_config = {
2362         .io.clock_khz = 12000,
2363         .io.pll_bypass = 0,
2364         .io.pll_range = 0,
2365         .io.pll_prediv = 3,
2366         .io.pll_loopdiv = 6,
2367         .io.adc_clock_ratio = 0,
2368         .io.pll_int_loop_filt = 0,
2369         .reset = dib7090_tuner_sleep,
2370         .sleep = dib7090_tuner_sleep,
2371
2372         .freq_offset_khz_uhf = 0,
2373         .freq_offset_khz_vhf = 0,
2374
2375         .get_adc_power = dib7090_get_adc_power,
2376
2377         .clkouttobamse = 1,
2378         .analog_output = 0,
2379
2380         .wbd_vhf_offset = 0,
2381         .wbd_cband_offset = 0,
2382         .use_pwm_agc = 1,
2383         .clkoutdrive = 0,
2384
2385         .fref_clock_ratio = 0,
2386
2387         .wbd = dib7090_wbd_table,
2388
2389         .ls_cfg_pad_drv = 0,
2390         .data_tx_drv = 0,
2391         .low_if = NULL,
2392         .in_soc = 1,
2393 };
2394
2395 static const struct dib0090_config tfe7090e_dib0090_config = {
2396         .io.clock_khz = 12000,
2397         .io.pll_bypass = 0,
2398         .io.pll_range = 0,
2399         .io.pll_prediv = 3,
2400         .io.pll_loopdiv = 6,
2401         .io.adc_clock_ratio = 0,
2402         .io.pll_int_loop_filt = 0,
2403         .reset = dib7090_tuner_sleep,
2404         .sleep = dib7090_tuner_sleep,
2405
2406         .freq_offset_khz_uhf = 0,
2407         .freq_offset_khz_vhf = 0,
2408
2409         .get_adc_power = dib7090_get_adc_power,
2410
2411         .clkouttobamse = 1,
2412         .analog_output = 0,
2413
2414         .wbd_vhf_offset = 0,
2415         .wbd_cband_offset = 0,
2416         .use_pwm_agc = 1,
2417         .clkoutdrive = 0,
2418
2419         .fref_clock_ratio = 0,
2420
2421         .wbd = dib7090e_wbd_table,
2422
2423         .ls_cfg_pad_drv = 0,
2424         .data_tx_drv = 0,
2425         .low_if = NULL,
2426         .in_soc = 1,
2427         .force_cband_input = 1,
2428         .is_dib7090e = 1,
2429 };
2430
2431 static const struct dib0090_config tfe7090pvr_dib0090_config[2] = {
2432         {
2433                 .io.clock_khz = 12000,
2434                 .io.pll_bypass = 0,
2435                 .io.pll_range = 0,
2436                 .io.pll_prediv = 3,
2437                 .io.pll_loopdiv = 6,
2438                 .io.adc_clock_ratio = 0,
2439                 .io.pll_int_loop_filt = 0,
2440                 .reset = dib7090_tuner_sleep,
2441                 .sleep = dib7090_tuner_sleep,
2442
2443                 .freq_offset_khz_uhf = 50,
2444                 .freq_offset_khz_vhf = 70,
2445
2446                 .get_adc_power = dib7090_get_adc_power,
2447
2448                 .clkouttobamse = 1,
2449                 .analog_output = 0,
2450
2451                 .wbd_vhf_offset = 0,
2452                 .wbd_cband_offset = 0,
2453                 .use_pwm_agc = 1,
2454                 .clkoutdrive = 0,
2455
2456                 .fref_clock_ratio = 0,
2457
2458                 .wbd = dib7090_wbd_table,
2459
2460                 .ls_cfg_pad_drv = 0,
2461                 .data_tx_drv = 0,
2462                 .low_if = NULL,
2463                 .in_soc = 1,
2464         }, {
2465                 .io.clock_khz = 12000,
2466                 .io.pll_bypass = 0,
2467                 .io.pll_range = 0,
2468                 .io.pll_prediv = 3,
2469                 .io.pll_loopdiv = 6,
2470                 .io.adc_clock_ratio = 0,
2471                 .io.pll_int_loop_filt = 0,
2472                 .reset = dib7090_tuner_sleep,
2473                 .sleep = dib7090_tuner_sleep,
2474
2475                 .freq_offset_khz_uhf = -50,
2476                 .freq_offset_khz_vhf = -70,
2477
2478                 .get_adc_power = dib7090_get_adc_power,
2479
2480                 .clkouttobamse = 1,
2481                 .analog_output = 0,
2482
2483                 .wbd_vhf_offset = 0,
2484                 .wbd_cband_offset = 0,
2485                 .use_pwm_agc = 1,
2486                 .clkoutdrive = 0,
2487
2488                 .fref_clock_ratio = 0,
2489
2490                 .wbd = dib7090_wbd_table,
2491
2492                 .ls_cfg_pad_drv = 0,
2493                 .data_tx_drv = 0,
2494                 .low_if = NULL,
2495                 .in_soc = 1,
2496         }
2497 };
2498
2499 static int nim7090_frontend_attach(struct dvb_usb_adapter *adap)
2500 {
2501         dib0700_set_gpio(adap->dev, GPIO6, GPIO_OUT, 1);
2502         msleep(20);
2503         dib0700_set_gpio(adap->dev, GPIO9, GPIO_OUT, 1);
2504         dib0700_set_gpio(adap->dev, GPIO4, GPIO_OUT, 1);
2505         dib0700_set_gpio(adap->dev, GPIO7, GPIO_OUT, 1);
2506         dib0700_set_gpio(adap->dev, GPIO10, GPIO_OUT, 0);
2507
2508         msleep(20);
2509         dib0700_set_gpio(adap->dev, GPIO10, GPIO_OUT, 1);
2510         msleep(20);
2511         dib0700_set_gpio(adap->dev, GPIO0, GPIO_OUT, 1);
2512
2513         if (dib7000p_i2c_enumeration(&adap->dev->i2c_adap, 1, 0x10, &nim7090_dib7000p_config) != 0) {
2514                 err("%s: dib7000p_i2c_enumeration failed.  Cannot continue\n", __func__);
2515                 return -ENODEV;
2516         }
2517         adap->fe_adap[0].fe = dvb_attach(dib7000p_attach, &adap->dev->i2c_adap, 0x80, &nim7090_dib7000p_config);
2518
2519         return adap->fe_adap[0].fe == NULL ?  -ENODEV : 0;
2520 }
2521
2522 static int nim7090_tuner_attach(struct dvb_usb_adapter *adap)
2523 {
2524         struct dib0700_adapter_state *st = adap->priv;
2525         struct i2c_adapter *tun_i2c = dib7090_get_i2c_tuner(adap->fe_adap[0].fe);
2526
2527         if (dvb_attach(dib0090_register, adap->fe_adap[0].fe, tun_i2c, &nim7090_dib0090_config) == NULL)
2528                 return -ENODEV;
2529
2530         dib7000p_set_gpio(adap->fe_adap[0].fe, 8, 0, 1);
2531
2532         st->set_param_save = adap->fe_adap[0].fe->ops.tuner_ops.set_params;
2533         adap->fe_adap[0].fe->ops.tuner_ops.set_params = dib7090_agc_startup;
2534         return 0;
2535 }
2536
2537 static int tfe7090pvr_frontend0_attach(struct dvb_usb_adapter *adap)
2538 {
2539         struct dib0700_state *st = adap->dev->priv;
2540
2541         /* The TFE7090 requires the dib0700 to not be in master mode */
2542         st->disable_streaming_master_mode = 1;
2543
2544         dib0700_set_gpio(adap->dev, GPIO6, GPIO_OUT, 1);
2545         msleep(20);
2546         dib0700_set_gpio(adap->dev, GPIO9, GPIO_OUT, 1);
2547         dib0700_set_gpio(adap->dev, GPIO4, GPIO_OUT, 1);
2548         dib0700_set_gpio(adap->dev, GPIO7, GPIO_OUT, 1);
2549         dib0700_set_gpio(adap->dev, GPIO10, GPIO_OUT, 0);
2550
2551         msleep(20);
2552         dib0700_set_gpio(adap->dev, GPIO10, GPIO_OUT, 1);
2553         msleep(20);
2554         dib0700_set_gpio(adap->dev, GPIO0, GPIO_OUT, 1);
2555
2556         /* initialize IC 0 */
2557         if (dib7000p_i2c_enumeration(&adap->dev->i2c_adap, 1, 0x20, &tfe7090pvr_dib7000p_config[0]) != 0) {
2558                 err("%s: dib7000p_i2c_enumeration failed.  Cannot continue\n", __func__);
2559                 return -ENODEV;
2560         }
2561
2562         dib0700_set_i2c_speed(adap->dev, 340);
2563         adap->fe_adap[0].fe = dvb_attach(dib7000p_attach, &adap->dev->i2c_adap, 0x90, &tfe7090pvr_dib7000p_config[0]);
2564         if (adap->fe_adap[0].fe == NULL)
2565                 return -ENODEV;
2566
2567         dib7090_slave_reset(adap->fe_adap[0].fe);
2568
2569         return 0;
2570 }
2571
2572 static int tfe7090pvr_frontend1_attach(struct dvb_usb_adapter *adap)
2573 {
2574         struct i2c_adapter *i2c;
2575
2576         if (adap->dev->adapter[0].fe_adap[0].fe == NULL) {
2577                 err("the master dib7090 has to be initialized first");
2578                 return -ENODEV; /* the master device has not been initialized */
2579         }
2580
2581         i2c = dib7000p_get_i2c_master(adap->dev->adapter[0].fe_adap[0].fe, DIBX000_I2C_INTERFACE_GPIO_6_7, 1);
2582         if (dib7000p_i2c_enumeration(i2c, 1, 0x10, &tfe7090pvr_dib7000p_config[1]) != 0) {
2583                 err("%s: dib7000p_i2c_enumeration failed.  Cannot continue\n", __func__);
2584                 return -ENODEV;
2585         }
2586
2587         adap->fe_adap[0].fe = dvb_attach(dib7000p_attach, i2c, 0x92, &tfe7090pvr_dib7000p_config[1]);
2588         dib0700_set_i2c_speed(adap->dev, 200);
2589
2590         return adap->fe_adap[0].fe == NULL ? -ENODEV : 0;
2591 }
2592
2593 static int tfe7090pvr_tuner0_attach(struct dvb_usb_adapter *adap)
2594 {
2595         struct dib0700_adapter_state *st = adap->priv;
2596         struct i2c_adapter *tun_i2c = dib7090_get_i2c_tuner(adap->fe_adap[0].fe);
2597
2598         if (dvb_attach(dib0090_register, adap->fe_adap[0].fe, tun_i2c, &tfe7090pvr_dib0090_config[0]) == NULL)
2599                 return -ENODEV;
2600
2601         dib7000p_set_gpio(adap->fe_adap[0].fe, 8, 0, 1);
2602
2603         st->set_param_save = adap->fe_adap[0].fe->ops.tuner_ops.set_params;
2604         adap->fe_adap[0].fe->ops.tuner_ops.set_params = dib7090_agc_startup;
2605         return 0;
2606 }
2607
2608 static int tfe7090pvr_tuner1_attach(struct dvb_usb_adapter *adap)
2609 {
2610         struct dib0700_adapter_state *st = adap->priv;
2611         struct i2c_adapter *tun_i2c = dib7090_get_i2c_tuner(adap->fe_adap[0].fe);
2612
2613         if (dvb_attach(dib0090_register, adap->fe_adap[0].fe, tun_i2c, &tfe7090pvr_dib0090_config[1]) == NULL)
2614                 return -ENODEV;
2615
2616         dib7000p_set_gpio(adap->fe_adap[0].fe, 8, 0, 1);
2617
2618         st->set_param_save = adap->fe_adap[0].fe->ops.tuner_ops.set_params;
2619         adap->fe_adap[0].fe->ops.tuner_ops.set_params = dib7090_agc_startup;
2620         return 0;
2621 }
2622
2623 static int tfe7090e_frontend_attach(struct dvb_usb_adapter *adap)
2624 {
2625         dib0700_set_gpio(adap->dev, GPIO6, GPIO_OUT, 1);
2626         msleep(20);
2627         dib0700_set_gpio(adap->dev, GPIO9, GPIO_OUT, 1);
2628         dib0700_set_gpio(adap->dev, GPIO4, GPIO_OUT, 1);
2629         dib0700_set_gpio(adap->dev, GPIO7, GPIO_OUT, 1);
2630         dib0700_set_gpio(adap->dev, GPIO10, GPIO_OUT, 0);
2631
2632         msleep(20);
2633         dib0700_set_gpio(adap->dev, GPIO10, GPIO_OUT, 1);
2634         msleep(20);
2635         dib0700_set_gpio(adap->dev, GPIO0, GPIO_OUT, 1);
2636
2637         if (dib7000p_i2c_enumeration(&adap->dev->i2c_adap,
2638                                 1, 0x10, &tfe7090e_dib7000p_config) != 0) {
2639                 err("%s: dib7000p_i2c_enumeration failed.  Cannot continue\n",
2640                                 __func__);
2641                 return -ENODEV;
2642         }
2643         adap->fe_adap[0].fe = dvb_attach(dib7000p_attach, &adap->dev->i2c_adap,
2644                         0x80, &tfe7090e_dib7000p_config);
2645
2646         return adap->fe_adap[0].fe == NULL ?  -ENODEV : 0;
2647 }
2648
2649 static int tfe7090e_tuner_attach(struct dvb_usb_adapter *adap)
2650 {
2651         struct dib0700_adapter_state *st = adap->priv;
2652         struct i2c_adapter *tun_i2c =
2653                 dib7090_get_i2c_tuner(adap->fe_adap[0].fe);
2654
2655         if (dvb_attach(dib0090_register, adap->fe_adap[0].fe, tun_i2c,
2656                                 &tfe7090e_dib0090_config) == NULL)
2657                 return -ENODEV;
2658
2659         dib7000p_set_gpio(adap->fe_adap[0].fe, 8, 0, 1);
2660
2661         st->set_param_save = adap->fe_adap[0].fe->ops.tuner_ops.set_params;
2662         adap->fe_adap[0].fe->ops.tuner_ops.set_params = dib7090_agc_startup;
2663         return 0;
2664 }
2665
2666 /* STK7070PD */
2667 static struct dib7000p_config stk7070pd_dib7000p_config[2] = {
2668         {
2669                 .output_mpeg2_in_188_bytes = 1,
2670
2671                 .agc_config_count = 1,
2672                 .agc = &dib7070_agc_config,
2673                 .bw  = &dib7070_bw_config_12_mhz,
2674                 .tuner_is_baseband = 1,
2675                 .spur_protect = 1,
2676
2677                 .gpio_dir = DIB7000P_GPIO_DEFAULT_DIRECTIONS,
2678                 .gpio_val = DIB7000P_GPIO_DEFAULT_VALUES,
2679                 .gpio_pwm_pos = DIB7000P_GPIO_DEFAULT_PWM_POS,
2680
2681                 .hostbus_diversity = 1,
2682         }, {
2683                 .output_mpeg2_in_188_bytes = 1,
2684
2685                 .agc_config_count = 1,
2686                 .agc = &dib7070_agc_config,
2687                 .bw  = &dib7070_bw_config_12_mhz,
2688                 .tuner_is_baseband = 1,
2689                 .spur_protect = 1,
2690
2691                 .gpio_dir = DIB7000P_GPIO_DEFAULT_DIRECTIONS,
2692                 .gpio_val = DIB7000P_GPIO_DEFAULT_VALUES,
2693                 .gpio_pwm_pos = DIB7000P_GPIO_DEFAULT_PWM_POS,
2694
2695                 .hostbus_diversity = 1,
2696         }
2697 };
2698
2699 static int stk7070pd_frontend_attach0(struct dvb_usb_adapter *adap)
2700 {
2701         dib0700_set_gpio(adap->dev, GPIO6, GPIO_OUT, 1);
2702         msleep(10);
2703         dib0700_set_gpio(adap->dev, GPIO9, GPIO_OUT, 1);
2704         dib0700_set_gpio(adap->dev, GPIO4, GPIO_OUT, 1);
2705         dib0700_set_gpio(adap->dev, GPIO7, GPIO_OUT, 1);
2706         dib0700_set_gpio(adap->dev, GPIO10, GPIO_OUT, 0);
2707
2708         dib0700_ctrl_clock(adap->dev, 72, 1);
2709
2710         msleep(10);
2711         dib0700_set_gpio(adap->dev, GPIO10, GPIO_OUT, 1);
2712         msleep(10);
2713         dib0700_set_gpio(adap->dev, GPIO0, GPIO_OUT, 1);
2714
2715         if (dib7000p_i2c_enumeration(&adap->dev->i2c_adap, 2, 18,
2716                                      stk7070pd_dib7000p_config) != 0) {
2717                 err("%s: dib7000p_i2c_enumeration failed.  Cannot continue\n",
2718                     __func__);
2719                 return -ENODEV;
2720         }
2721
2722         adap->fe_adap[0].fe = dvb_attach(dib7000p_attach, &adap->dev->i2c_adap, 0x80, &stk7070pd_dib7000p_config[0]);
2723         return adap->fe_adap[0].fe == NULL ? -ENODEV : 0;
2724 }
2725
2726 static int stk7070pd_frontend_attach1(struct dvb_usb_adapter *adap)
2727 {
2728         adap->fe_adap[0].fe = dvb_attach(dib7000p_attach, &adap->dev->i2c_adap, 0x82, &stk7070pd_dib7000p_config[1]);
2729         return adap->fe_adap[0].fe == NULL ? -ENODEV : 0;
2730 }
2731
2732 /* S5H1411 */
2733 static struct s5h1411_config pinnacle_801e_config = {
2734         .output_mode   = S5H1411_PARALLEL_OUTPUT,
2735         .gpio          = S5H1411_GPIO_OFF,
2736         .mpeg_timing   = S5H1411_MPEGTIMING_NONCONTINOUS_NONINVERTING_CLOCK,
2737         .qam_if        = S5H1411_IF_44000,
2738         .vsb_if        = S5H1411_IF_44000,
2739         .inversion     = S5H1411_INVERSION_OFF,
2740         .status_mode   = S5H1411_DEMODLOCKING
2741 };
2742
2743 /* Pinnacle PCTV HD Pro 801e GPIOs map:
2744    GPIO0  - currently unknown
2745    GPIO1  - xc5000 tuner reset
2746    GPIO2  - CX25843 sleep
2747    GPIO3  - currently unknown
2748    GPIO4  - currently unknown
2749    GPIO6  - currently unknown
2750    GPIO7  - currently unknown
2751    GPIO9  - currently unknown
2752    GPIO10 - CX25843 reset
2753  */
2754 static int s5h1411_frontend_attach(struct dvb_usb_adapter *adap)
2755 {
2756         struct dib0700_state *st = adap->dev->priv;
2757
2758         /* Make use of the new i2c functions from FW 1.20 */
2759         st->fw_use_new_i2c_api = 1;
2760
2761         /* The s5h1411 requires the dib0700 to not be in master mode */
2762         st->disable_streaming_master_mode = 1;
2763
2764         /* All msleep values taken from Windows USB trace */
2765         dib0700_set_gpio(adap->dev, GPIO0, GPIO_OUT, 0);
2766         dib0700_set_gpio(adap->dev, GPIO3, GPIO_OUT, 0);
2767         dib0700_set_gpio(adap->dev, GPIO6, GPIO_OUT, 1);
2768         msleep(400);
2769         dib0700_set_gpio(adap->dev, GPIO10, GPIO_OUT, 0);
2770         msleep(60);
2771         dib0700_set_gpio(adap->dev, GPIO10, GPIO_OUT, 1);
2772         msleep(30);
2773         dib0700_set_gpio(adap->dev, GPIO0, GPIO_OUT, 1);
2774         dib0700_set_gpio(adap->dev, GPIO9, GPIO_OUT, 1);
2775         dib0700_set_gpio(adap->dev, GPIO4, GPIO_OUT, 1);
2776         dib0700_set_gpio(adap->dev, GPIO7, GPIO_OUT, 1);
2777         dib0700_set_gpio(adap->dev, GPIO2, GPIO_OUT, 0);
2778         msleep(30);
2779
2780         /* Put the CX25843 to sleep for now since we're in digital mode */
2781         dib0700_set_gpio(adap->dev, GPIO2, GPIO_OUT, 1);
2782
2783         /* GPIOs are initialized, do the attach */
2784         adap->fe_adap[0].fe = dvb_attach(s5h1411_attach, &pinnacle_801e_config,
2785                               &adap->dev->i2c_adap);
2786         return adap->fe_adap[0].fe == NULL ? -ENODEV : 0;
2787 }
2788
2789 static int dib0700_xc5000_tuner_callback(void *priv, int component,
2790                                          int command, int arg)
2791 {
2792         struct dvb_usb_adapter *adap = priv;
2793
2794         if (command == XC5000_TUNER_RESET) {
2795                 /* Reset the tuner */
2796                 dib0700_set_gpio(adap->dev, GPIO1, GPIO_OUT, 0);
2797                 msleep(10);
2798                 dib0700_set_gpio(adap->dev, GPIO1, GPIO_OUT, 1);
2799                 msleep(10);
2800         } else {
2801                 err("xc5000: unknown tuner callback command: %d\n", command);
2802                 return -EINVAL;
2803         }
2804
2805         return 0;
2806 }
2807
2808 static struct xc5000_config s5h1411_xc5000_tunerconfig = {
2809         .i2c_address      = 0x64,
2810         .if_khz           = 5380,
2811 };
2812
2813 static int xc5000_tuner_attach(struct dvb_usb_adapter *adap)
2814 {
2815         /* FIXME: generalize & move to common area */
2816         adap->fe_adap[0].fe->callback = dib0700_xc5000_tuner_callback;
2817
2818         return dvb_attach(xc5000_attach, adap->fe_adap[0].fe, &adap->dev->i2c_adap,
2819                           &s5h1411_xc5000_tunerconfig)
2820                 == NULL ? -ENODEV : 0;
2821 }
2822
2823 static int dib0700_xc4000_tuner_callback(void *priv, int component,
2824                                          int command, int arg)
2825 {
2826         struct dvb_usb_adapter *adap = priv;
2827
2828         if (command == XC4000_TUNER_RESET) {
2829                 /* Reset the tuner */
2830                 dib7000p_set_gpio(adap->fe_adap[0].fe, 8, 0, 0);
2831                 msleep(10);
2832                 dib7000p_set_gpio(adap->fe_adap[0].fe, 8, 0, 1);
2833         } else {
2834                 err("xc4000: unknown tuner callback command: %d\n", command);
2835                 return -EINVAL;
2836         }
2837
2838         return 0;
2839 }
2840
2841 static struct dibx000_agc_config stk7700p_7000p_xc4000_agc_config = {
2842         .band_caps = BAND_UHF | BAND_VHF,
2843         .setup = 0x64,
2844         .inv_gain = 0x02c8,
2845         .time_stabiliz = 0x15,
2846         .alpha_level = 0x00,
2847         .thlock = 0x76,
2848         .wbd_inv = 0x01,
2849         .wbd_ref = 0x0b33,
2850         .wbd_sel = 0x00,
2851         .wbd_alpha = 0x02,
2852         .agc1_max = 0x00,
2853         .agc1_min = 0x00,
2854         .agc2_max = 0x9b26,
2855         .agc2_min = 0x26ca,
2856         .agc1_pt1 = 0x00,
2857         .agc1_pt2 = 0x00,
2858         .agc1_pt3 = 0x00,
2859         .agc1_slope1 = 0x00,
2860         .agc1_slope2 = 0x00,
2861         .agc2_pt1 = 0x00,
2862         .agc2_pt2 = 0x80,
2863         .agc2_slope1 = 0x1d,
2864         .agc2_slope2 = 0x1d,
2865         .alpha_mant = 0x11,
2866         .alpha_exp = 0x1b,
2867         .beta_mant = 0x17,
2868         .beta_exp = 0x33,
2869         .perform_agc_softsplit = 0x00,
2870 };
2871
2872 static struct dibx000_bandwidth_config stk7700p_xc4000_pll_config = {
2873         60000, 30000,   /* internal, sampling */
2874         1, 8, 3, 1, 0,  /* pll_cfg: prediv, ratio, range, reset, bypass */
2875         0, 0, 1, 1, 0,  /* misc: refdiv, bypclk_div, IO_CLK_en_core, */
2876                         /* ADClkSrc, modulo */
2877         (3 << 14) | (1 << 12) | 524,    /* sad_cfg: refsel, sel, freq_15k */
2878         39370534,       /* ifreq */
2879         20452225,       /* timf */
2880         30000000        /* xtal */
2881 };
2882
2883 /* FIXME: none of these inputs are validated yet */
2884 static struct dib7000p_config pctv_340e_config = {
2885         .output_mpeg2_in_188_bytes = 1,
2886
2887         .agc_config_count = 1,
2888         .agc = &stk7700p_7000p_xc4000_agc_config,
2889         .bw  = &stk7700p_xc4000_pll_config,
2890
2891         .gpio_dir = DIB7000M_GPIO_DEFAULT_DIRECTIONS,
2892         .gpio_val = DIB7000M_GPIO_DEFAULT_VALUES,
2893         .gpio_pwm_pos = DIB7000M_GPIO_DEFAULT_PWM_POS,
2894 };
2895
2896 /* PCTV 340e GPIOs map:
2897    dib0700:
2898    GPIO2  - CX25843 sleep
2899    GPIO3  - CS5340 reset
2900    GPIO5  - IRD
2901    GPIO6  - Power Supply
2902    GPIO8  - LNA (1=off 0=on)
2903    GPIO10 - CX25843 reset
2904    dib7000:
2905    GPIO8  - xc4000 reset
2906  */
2907 static int pctv340e_frontend_attach(struct dvb_usb_adapter *adap)
2908 {
2909         struct dib0700_state *st = adap->dev->priv;
2910
2911         /* Power Supply on */
2912         dib0700_set_gpio(adap->dev, GPIO6,  GPIO_OUT, 0);
2913         msleep(50);
2914         dib0700_set_gpio(adap->dev, GPIO6,  GPIO_OUT, 1);
2915         msleep(100); /* Allow power supply to settle before probing */
2916
2917         /* cx25843 reset */
2918         dib0700_set_gpio(adap->dev, GPIO10,  GPIO_OUT, 0);
2919         msleep(1); /* cx25843 datasheet say 350us required */
2920         dib0700_set_gpio(adap->dev, GPIO10,  GPIO_OUT, 1);
2921
2922         /* LNA off for now */
2923         dib0700_set_gpio(adap->dev, GPIO8,  GPIO_OUT, 1);
2924
2925         /* Put the CX25843 to sleep for now since we're in digital mode */
2926         dib0700_set_gpio(adap->dev, GPIO2, GPIO_OUT, 1);
2927
2928         /* FIXME: not verified yet */
2929         dib0700_ctrl_clock(adap->dev, 72, 1);
2930
2931         msleep(500);
2932
2933         if (dib7000pc_detection(&adap->dev->i2c_adap) == 0) {
2934                 /* Demodulator not found for some reason? */
2935                 return -ENODEV;
2936         }
2937
2938         adap->fe_adap[0].fe = dvb_attach(dib7000p_attach, &adap->dev->i2c_adap, 0x12,
2939                               &pctv_340e_config);
2940         st->is_dib7000pc = 1;
2941
2942         return adap->fe_adap[0].fe == NULL ? -ENODEV : 0;
2943 }
2944
2945 static struct xc4000_config dib7000p_xc4000_tunerconfig = {
2946         .i2c_address      = 0x61,
2947         .default_pm       = 1,
2948         .dvb_amplitude    = 0,
2949         .set_smoothedcvbs = 0,
2950         .if_khz           = 5400
2951 };
2952
2953 static int xc4000_tuner_attach(struct dvb_usb_adapter *adap)
2954 {
2955         struct i2c_adapter *tun_i2c;
2956
2957         /* The xc4000 is not on the main i2c bus */
2958         tun_i2c = dib7000p_get_i2c_master(adap->fe_adap[0].fe,
2959                                           DIBX000_I2C_INTERFACE_TUNER, 1);
2960         if (tun_i2c == NULL) {
2961                 printk(KERN_ERR "Could not reach tuner i2c bus\n");
2962                 return 0;
2963         }
2964
2965         /* Setup the reset callback */
2966         adap->fe_adap[0].fe->callback = dib0700_xc4000_tuner_callback;
2967
2968         return dvb_attach(xc4000_attach, adap->fe_adap[0].fe, tun_i2c,
2969                           &dib7000p_xc4000_tunerconfig)
2970                 == NULL ? -ENODEV : 0;
2971 }
2972
2973 static struct lgdt3305_config hcw_lgdt3305_config = {
2974         .i2c_addr           = 0x0e,
2975         .mpeg_mode          = LGDT3305_MPEG_PARALLEL,
2976         .tpclk_edge         = LGDT3305_TPCLK_FALLING_EDGE,
2977         .tpvalid_polarity   = LGDT3305_TP_VALID_LOW,
2978         .deny_i2c_rptr      = 0,
2979         .spectral_inversion = 1,
2980         .qam_if_khz         = 6000,
2981         .vsb_if_khz         = 6000,
2982         .usref_8vsb         = 0x0500,
2983 };
2984
2985 static struct mxl5007t_config hcw_mxl5007t_config = {
2986         .xtal_freq_hz = MxL_XTAL_25_MHZ,
2987         .if_freq_hz = MxL_IF_6_MHZ,
2988         .invert_if = 1,
2989 };
2990
2991 /* TIGER-ATSC map:
2992    GPIO0  - LNA_CTR  (H: LNA power enabled, L: LNA power disabled)
2993    GPIO1  - ANT_SEL  (H: VPA, L: MCX)
2994    GPIO4  - SCL2
2995    GPIO6  - EN_TUNER
2996    GPIO7  - SDA2
2997    GPIO10 - DEM_RST
2998
2999    MXL is behind LG's i2c repeater.  LG is on SCL2/SDA2 gpios on the DIB
3000  */
3001 static int lgdt3305_frontend_attach(struct dvb_usb_adapter *adap)
3002 {
3003         struct dib0700_state *st = adap->dev->priv;
3004
3005         /* Make use of the new i2c functions from FW 1.20 */
3006         st->fw_use_new_i2c_api = 1;
3007
3008         st->disable_streaming_master_mode = 1;
3009
3010         /* fe power enable */
3011         dib0700_set_gpio(adap->dev, GPIO6, GPIO_OUT, 0);
3012         msleep(30);
3013         dib0700_set_gpio(adap->dev, GPIO6, GPIO_OUT, 1);
3014         msleep(30);
3015
3016         /* demod reset */
3017         dib0700_set_gpio(adap->dev, GPIO10, GPIO_OUT, 1);
3018         msleep(30);
3019         dib0700_set_gpio(adap->dev, GPIO10, GPIO_OUT, 0);
3020         msleep(30);
3021         dib0700_set_gpio(adap->dev, GPIO10, GPIO_OUT, 1);
3022         msleep(30);
3023
3024         adap->fe_adap[0].fe = dvb_attach(lgdt3305_attach,
3025                               &hcw_lgdt3305_config,
3026                               &adap->dev->i2c_adap);
3027
3028         return adap->fe_adap[0].fe == NULL ? -ENODEV : 0;
3029 }
3030
3031 static int mxl5007t_tuner_attach(struct dvb_usb_adapter *adap)
3032 {
3033         return dvb_attach(mxl5007t_attach, adap->fe_adap[0].fe,
3034                           &adap->dev->i2c_adap, 0x60,
3035                           &hcw_mxl5007t_config) == NULL ? -ENODEV : 0;
3036 }
3037
3038
3039 /* DVB-USB and USB stuff follows */
3040 struct usb_device_id dib0700_usb_id_table[] = {
3041 /* 0 */ { USB_DEVICE(USB_VID_DIBCOM,    USB_PID_DIBCOM_STK7700P) },
3042         { USB_DEVICE(USB_VID_DIBCOM,    USB_PID_DIBCOM_STK7700P_PC) },
3043         { USB_DEVICE(USB_VID_HAUPPAUGE, USB_PID_HAUPPAUGE_NOVA_T_500) },
3044         { USB_DEVICE(USB_VID_HAUPPAUGE, USB_PID_HAUPPAUGE_NOVA_T_500_2) },
3045         { USB_DEVICE(USB_VID_HAUPPAUGE, USB_PID_HAUPPAUGE_NOVA_T_STICK) },
3046 /* 5 */ { USB_DEVICE(USB_VID_AVERMEDIA, USB_PID_AVERMEDIA_VOLAR) },
3047         { USB_DEVICE(USB_VID_COMPRO,    USB_PID_COMPRO_VIDEOMATE_U500) },
3048         { USB_DEVICE(USB_VID_UNIWILL,   USB_PID_UNIWILL_STK7700P) },
3049         { USB_DEVICE(USB_VID_LEADTEK,   USB_PID_WINFAST_DTV_DONGLE_STK7700P) },
3050         { USB_DEVICE(USB_VID_HAUPPAUGE, USB_PID_HAUPPAUGE_NOVA_T_STICK_2) },
3051 /* 10 */{ USB_DEVICE(USB_VID_AVERMEDIA, USB_PID_AVERMEDIA_VOLAR_2) },
3052         { USB_DEVICE(USB_VID_PINNACLE,  USB_PID_PINNACLE_PCTV2000E) },
3053         { USB_DEVICE(USB_VID_TERRATEC,
3054                         USB_PID_TERRATEC_CINERGY_DT_XS_DIVERSITY) },
3055         { USB_DEVICE(USB_VID_HAUPPAUGE, USB_PID_HAUPPAUGE_NOVA_TD_STICK) },
3056         { USB_DEVICE(USB_VID_DIBCOM,    USB_PID_DIBCOM_STK7700D) },
3057 /* 15 */{ USB_DEVICE(USB_VID_DIBCOM,    USB_PID_DIBCOM_STK7070P) },
3058         { USB_DEVICE(USB_VID_PINNACLE,  USB_PID_PINNACLE_PCTV_DVB_T_FLASH) },
3059         { USB_DEVICE(USB_VID_DIBCOM,    USB_PID_DIBCOM_STK7070PD) },
3060         { USB_DEVICE(USB_VID_PINNACLE,
3061                         USB_PID_PINNACLE_PCTV_DUAL_DIVERSITY_DVB_T) },
3062         { USB_DEVICE(USB_VID_COMPRO,    USB_PID_COMPRO_VIDEOMATE_U500_PC) },
3063 /* 20 */{ USB_DEVICE(USB_VID_AVERMEDIA, USB_PID_AVERMEDIA_EXPRESS) },
3064         { USB_DEVICE(USB_VID_GIGABYTE,  USB_PID_GIGABYTE_U7000) },
3065         { USB_DEVICE(USB_VID_ULTIMA_ELECTRONIC, USB_PID_ARTEC_T14BR) },
3066         { USB_DEVICE(USB_VID_ASUS,      USB_PID_ASUS_U3000) },
3067         { USB_DEVICE(USB_VID_ASUS,      USB_PID_ASUS_U3100) },
3068 /* 25 */{ USB_DEVICE(USB_VID_HAUPPAUGE, USB_PID_HAUPPAUGE_NOVA_T_STICK_3) },
3069         { USB_DEVICE(USB_VID_HAUPPAUGE, USB_PID_HAUPPAUGE_MYTV_T) },
3070         { USB_DEVICE(USB_VID_TERRATEC,  USB_PID_TERRATEC_CINERGY_HT_USB_XE) },
3071         { USB_DEVICE(USB_VID_PINNACLE,  USB_PID_PINNACLE_EXPRESSCARD_320CX) },
3072         { USB_DEVICE(USB_VID_PINNACLE,  USB_PID_PINNACLE_PCTV72E) },
3073 /* 30 */{ USB_DEVICE(USB_VID_PINNACLE,  USB_PID_PINNACLE_PCTV73E) },
3074         { USB_DEVICE(USB_VID_YUAN,      USB_PID_YUAN_EC372S) },
3075         { USB_DEVICE(USB_VID_TERRATEC,  USB_PID_TERRATEC_CINERGY_HT_EXPRESS) },
3076         { USB_DEVICE(USB_VID_TERRATEC,  USB_PID_TERRATEC_CINERGY_T_XXS) },
3077         { USB_DEVICE(USB_VID_LEADTEK,   USB_PID_WINFAST_DTV_DONGLE_STK7700P_2) },
3078 /* 35 */{ USB_DEVICE(USB_VID_HAUPPAUGE, USB_PID_HAUPPAUGE_NOVA_TD_STICK_52009) },
3079         { USB_DEVICE(USB_VID_HAUPPAUGE, USB_PID_HAUPPAUGE_NOVA_T_500_3) },
3080         { USB_DEVICE(USB_VID_GIGABYTE,  USB_PID_GIGABYTE_U8000) },
3081         { USB_DEVICE(USB_VID_YUAN,      USB_PID_YUAN_STK7700PH) },
3082         { USB_DEVICE(USB_VID_ASUS,      USB_PID_ASUS_U3000H) },
3083 /* 40 */{ USB_DEVICE(USB_VID_PINNACLE,  USB_PID_PINNACLE_PCTV801E) },
3084         { USB_DEVICE(USB_VID_PINNACLE,  USB_PID_PINNACLE_PCTV801E_SE) },
3085         { USB_DEVICE(USB_VID_TERRATEC,  USB_PID_TERRATEC_CINERGY_T_EXPRESS) },
3086         { USB_DEVICE(USB_VID_TERRATEC,
3087                         USB_PID_TERRATEC_CINERGY_DT_XS_DIVERSITY_2) },
3088         { USB_DEVICE(USB_VID_SONY,      USB_PID_SONY_PLAYTV) },
3089 /* 45 */{ USB_DEVICE(USB_VID_YUAN,      USB_PID_YUAN_PD378S) },
3090         { USB_DEVICE(USB_VID_HAUPPAUGE, USB_PID_HAUPPAUGE_TIGER_ATSC) },
3091         { USB_DEVICE(USB_VID_HAUPPAUGE, USB_PID_HAUPPAUGE_TIGER_ATSC_B210) },
3092         { USB_DEVICE(USB_VID_YUAN,      USB_PID_YUAN_MC770) },
3093         { USB_DEVICE(USB_VID_ELGATO,    USB_PID_ELGATO_EYETV_DTT) },
3094 /* 50 */{ USB_DEVICE(USB_VID_ELGATO,    USB_PID_ELGATO_EYETV_DTT_Dlx) },
3095         { USB_DEVICE(USB_VID_LEADTEK,   USB_PID_WINFAST_DTV_DONGLE_H) },
3096         { USB_DEVICE(USB_VID_TERRATEC,  USB_PID_TERRATEC_T3) },
3097         { USB_DEVICE(USB_VID_TERRATEC,  USB_PID_TERRATEC_T5) },
3098         { USB_DEVICE(USB_VID_YUAN,      USB_PID_YUAN_STK7700D) },
3099 /* 55 */{ USB_DEVICE(USB_VID_YUAN,      USB_PID_YUAN_STK7700D_2) },
3100         { USB_DEVICE(USB_VID_PINNACLE,  USB_PID_PINNACLE_PCTV73A) },
3101         { USB_DEVICE(USB_VID_PCTV,      USB_PID_PINNACLE_PCTV73ESE) },
3102         { USB_DEVICE(USB_VID_PCTV,      USB_PID_PINNACLE_PCTV282E) },
3103         { USB_DEVICE(USB_VID_DIBCOM,    USB_PID_DIBCOM_STK7770P) },
3104 /* 60 */{ USB_DEVICE(USB_VID_TERRATEC,  USB_PID_TERRATEC_CINERGY_T_XXS_2) },
3105         { USB_DEVICE(USB_VID_DIBCOM,    USB_PID_DIBCOM_STK807XPVR) },
3106         { USB_DEVICE(USB_VID_DIBCOM,    USB_PID_DIBCOM_STK807XP) },
3107         { USB_DEVICE_VER(USB_VID_PIXELVIEW, USB_PID_PIXELVIEW_SBTVD, 0x000, 0x3f00) },
3108         { USB_DEVICE(USB_VID_EVOLUTEPC, USB_PID_TVWAY_PLUS) },
3109 /* 65 */{ USB_DEVICE(USB_VID_PINNACLE,  USB_PID_PINNACLE_PCTV73ESE) },
3110         { USB_DEVICE(USB_VID_PINNACLE,  USB_PID_PINNACLE_PCTV282E) },
3111         { USB_DEVICE(USB_VID_DIBCOM,    USB_PID_DIBCOM_STK8096GP) },
3112         { USB_DEVICE(USB_VID_ELGATO,    USB_PID_ELGATO_EYETV_DIVERSITY) },
3113         { USB_DEVICE(USB_VID_DIBCOM,    USB_PID_DIBCOM_NIM9090M) },
3114 /* 70 */{ USB_DEVICE(USB_VID_DIBCOM,    USB_PID_DIBCOM_NIM8096MD) },
3115         { USB_DEVICE(USB_VID_DIBCOM,    USB_PID_DIBCOM_NIM9090MD) },
3116         { USB_DEVICE(USB_VID_DIBCOM,    USB_PID_DIBCOM_NIM7090) },
3117         { USB_DEVICE(USB_VID_DIBCOM,    USB_PID_DIBCOM_TFE7090PVR) },
3118         { USB_DEVICE(USB_VID_TECHNISAT, USB_PID_TECHNISAT_AIRSTAR_TELESTICK_2) },
3119 /* 75 */{ USB_DEVICE(USB_VID_MEDION,    USB_PID_CREATIX_CTX1921) },
3120         { USB_DEVICE(USB_VID_PINNACLE,  USB_PID_PINNACLE_PCTV340E) },
3121         { USB_DEVICE(USB_VID_PINNACLE,  USB_PID_PINNACLE_PCTV340E_SE) },
3122         { USB_DEVICE(USB_VID_DIBCOM,    USB_PID_DIBCOM_TFE7090E) },
3123         { 0 }           /* Terminating entry */
3124 };
3125 MODULE_DEVICE_TABLE(usb, dib0700_usb_id_table);
3126
3127 #define DIB0700_DEFAULT_DEVICE_PROPERTIES \
3128         .caps              = DVB_USB_IS_AN_I2C_ADAPTER, \
3129         .usb_ctrl          = DEVICE_SPECIFIC, \
3130         .firmware          = "dvb-usb-dib0700-1.20.fw", \
3131         .download_firmware = dib0700_download_firmware, \
3132         .no_reconnect      = 1, \
3133         .size_of_priv      = sizeof(struct dib0700_state), \
3134         .i2c_algo          = &dib0700_i2c_algo, \
3135         .identify_state    = dib0700_identify_state
3136
3137 #define DIB0700_DEFAULT_STREAMING_CONFIG(ep) \
3138         .streaming_ctrl   = dib0700_streaming_ctrl, \
3139         .stream = { \
3140                 .type = USB_BULK, \
3141                 .count = 4, \
3142                 .endpoint = ep, \
3143                 .u = { \
3144                         .bulk = { \
3145                                 .buffersize = 39480, \
3146                         } \
3147                 } \
3148         }
3149
3150 struct dvb_usb_device_properties dib0700_devices[] = {
3151         {
3152                 DIB0700_DEFAULT_DEVICE_PROPERTIES,
3153
3154                 .num_adapters = 1,
3155                 .adapter = {
3156                         {
3157                         .num_frontends = 1,
3158                         .fe = {{
3159                                 .caps = DVB_USB_ADAP_HAS_PID_FILTER | DVB_USB_ADAP_PID_FILTER_CAN_BE_TURNED_OFF,
3160                                 .pid_filter_count = 32,
3161                                 .pid_filter       = stk7700p_pid_filter,
3162                                 .pid_filter_ctrl  = stk7700p_pid_filter_ctrl,
3163                                 .frontend_attach  = stk7700p_frontend_attach,
3164                                 .tuner_attach     = stk7700p_tuner_attach,
3165
3166                                 DIB0700_DEFAULT_STREAMING_CONFIG(0x02),
3167                         }},
3168                         },
3169                 },
3170
3171                 .num_device_descs = 8,
3172                 .devices = {
3173                         {   "DiBcom STK7700P reference design",
3174                                 { &dib0700_usb_id_table[0], &dib0700_usb_id_table[1] },
3175                                 { NULL },
3176                         },
3177                         {   "Hauppauge Nova-T Stick",
3178                                 { &dib0700_usb_id_table[4], &dib0700_usb_id_table[9], NULL },
3179                                 { NULL },
3180                         },
3181                         {   "AVerMedia AVerTV DVB-T Volar",
3182                                 { &dib0700_usb_id_table[5], &dib0700_usb_id_table[10] },
3183                                 { NULL },
3184                         },
3185                         {   "Compro Videomate U500",
3186                                 { &dib0700_usb_id_table[6], &dib0700_usb_id_table[19] },
3187                                 { NULL },
3188                         },
3189                         {   "Uniwill STK7700P based (Hama and others)",
3190                                 { &dib0700_usb_id_table[7], NULL },
3191                                 { NULL },
3192                         },
3193                         {   "Leadtek Winfast DTV Dongle (STK7700P based)",
3194                                 { &dib0700_usb_id_table[8], &dib0700_usb_id_table[34] },
3195                                 { NULL },
3196                         },
3197                         {   "AVerMedia AVerTV DVB-T Express",
3198                                 { &dib0700_usb_id_table[20] },
3199                                 { NULL },
3200                         },
3201                         {   "Gigabyte U7000",
3202                                 { &dib0700_usb_id_table[21], NULL },
3203                                 { NULL },
3204                         }
3205                 },
3206
3207                 .rc.core = {
3208                         .rc_interval      = DEFAULT_RC_INTERVAL,
3209                         .rc_codes         = RC_MAP_DIB0700_RC5_TABLE,
3210                         .rc_query         = dib0700_rc_query_old_firmware,
3211                         .allowed_protos   = RC_TYPE_RC5 |
3212                                             RC_TYPE_RC6 |
3213                                             RC_TYPE_NEC,
3214                         .change_protocol  = dib0700_change_protocol,
3215                 },
3216         }, { DIB0700_DEFAULT_DEVICE_PROPERTIES,
3217
3218                 .num_adapters = 2,
3219                 .adapter = {
3220                         {
3221                         .num_frontends = 1,
3222                         .fe = {{
3223                                 .frontend_attach  = bristol_frontend_attach,
3224                                 .tuner_attach     = bristol_tuner_attach,
3225
3226                                 DIB0700_DEFAULT_STREAMING_CONFIG(0x02),
3227                         }},
3228                         }, {
3229                         .num_frontends = 1,
3230                         .fe = {{
3231                                 .frontend_attach  = bristol_frontend_attach,
3232                                 .tuner_attach     = bristol_tuner_attach,
3233
3234                                 DIB0700_DEFAULT_STREAMING_CONFIG(0x03),
3235                         }},
3236                         }
3237                 },
3238
3239                 .num_device_descs = 1,
3240                 .devices = {
3241                         {   "Hauppauge Nova-T 500 Dual DVB-T",
3242                                 { &dib0700_usb_id_table[2], &dib0700_usb_id_table[3], NULL },
3243                                 { NULL },
3244                         },
3245                 },
3246
3247                 .rc.core = {
3248                         .rc_interval      = DEFAULT_RC_INTERVAL,
3249                         .rc_codes         = RC_MAP_DIB0700_RC5_TABLE,
3250                         .rc_query         = dib0700_rc_query_old_firmware,
3251                         .allowed_protos   = RC_TYPE_RC5 |
3252                                             RC_TYPE_RC6 |
3253                                             RC_TYPE_NEC,
3254                         .change_protocol = dib0700_change_protocol,
3255                 },
3256         }, { DIB0700_DEFAULT_DEVICE_PROPERTIES,
3257
3258                 .num_adapters = 2,
3259                 .adapter = {
3260                         {
3261                         .num_frontends = 1,
3262                         .fe = {{
3263                                 .caps = DVB_USB_ADAP_HAS_PID_FILTER | DVB_USB_ADAP_PID_FILTER_CAN_BE_TURNED_OFF,
3264                                 .pid_filter_count = 32,
3265                                 .pid_filter       = stk70x0p_pid_filter,
3266                                 .pid_filter_ctrl  = stk70x0p_pid_filter_ctrl,
3267                                 .frontend_attach  = stk7700d_frontend_attach,
3268                                 .tuner_attach     = stk7700d_tuner_attach,
3269
3270                                 DIB0700_DEFAULT_STREAMING_CONFIG(0x02),
3271                         }},
3272                         }, {
3273                         .num_frontends = 1,
3274                         .fe = {{
3275                                 .caps = DVB_USB_ADAP_HAS_PID_FILTER | DVB_USB_ADAP_PID_FILTER_CAN_BE_TURNED_OFF,
3276                                 .pid_filter_count = 32,
3277                                 .pid_filter       = stk70x0p_pid_filter,
3278                                 .pid_filter_ctrl  = stk70x0p_pid_filter_ctrl,
3279                                 .frontend_attach  = stk7700d_frontend_attach,
3280                                 .tuner_attach     = stk7700d_tuner_attach,
3281
3282                                 DIB0700_DEFAULT_STREAMING_CONFIG(0x03),
3283                         }},
3284                         }
3285                 },
3286
3287                 .num_device_descs = 5,
3288                 .devices = {
3289                         {   "Pinnacle PCTV 2000e",
3290                                 { &dib0700_usb_id_table[11], NULL },
3291                                 { NULL },
3292                         },
3293                         {   "Terratec Cinergy DT XS Diversity",
3294                                 { &dib0700_usb_id_table[12], NULL },
3295                                 { NULL },
3296                         },
3297                         {   "Hauppauge Nova-TD Stick/Elgato Eye-TV Diversity",
3298                                 { &dib0700_usb_id_table[13], NULL },
3299                                 { NULL },
3300                         },
3301                         {   "DiBcom STK7700D reference design",
3302                                 { &dib0700_usb_id_table[14], NULL },
3303                                 { NULL },
3304                         },
3305                         {   "YUAN High-Tech DiBcom STK7700D",
3306                                 { &dib0700_usb_id_table[55], NULL },
3307                                 { NULL },
3308                         },
3309
3310                 },
3311
3312                 .rc.core = {
3313                         .rc_interval      = DEFAULT_RC_INTERVAL,
3314                         .rc_codes         = RC_MAP_DIB0700_RC5_TABLE,
3315                         .rc_query         = dib0700_rc_query_old_firmware,
3316                         .allowed_protos   = RC_TYPE_RC5 |
3317                                             RC_TYPE_RC6 |
3318                                             RC_TYPE_NEC,
3319                         .change_protocol = dib0700_change_protocol,
3320                 },
3321         }, { DIB0700_DEFAULT_DEVICE_PROPERTIES,
3322
3323                 .num_adapters = 1,
3324                 .adapter = {
3325                         {
3326                         .num_frontends = 1,
3327                         .fe = {{
3328                                 .caps = DVB_USB_ADAP_HAS_PID_FILTER | DVB_USB_ADAP_PID_FILTER_CAN_BE_TURNED_OFF,
3329                                 .pid_filter_count = 32,
3330                                 .pid_filter       = stk70x0p_pid_filter,
3331                                 .pid_filter_ctrl  = stk70x0p_pid_filter_ctrl,
3332                                 .frontend_attach  = stk7700P2_frontend_attach,
3333                                 .tuner_attach     = stk7700d_tuner_attach,
3334
3335                                 DIB0700_DEFAULT_STREAMING_CONFIG(0x02),
3336                         }},
3337                         },
3338                 },
3339
3340                 .num_device_descs = 3,
3341                 .devices = {
3342                         {   "ASUS My Cinema U3000 Mini DVBT Tuner",
3343                                 { &dib0700_usb_id_table[23], NULL },
3344                                 { NULL },
3345                         },
3346                         {   "Yuan EC372S",
3347                                 { &dib0700_usb_id_table[31], NULL },
3348                                 { NULL },
3349                         },
3350                         {   "Terratec Cinergy T Express",
3351                                 { &dib0700_usb_id_table[42], NULL },
3352                                 { NULL },
3353                         }
3354                 },
3355
3356                 .rc.core = {
3357                         .rc_interval      = DEFAULT_RC_INTERVAL,
3358                         .rc_codes         = RC_MAP_DIB0700_RC5_TABLE,
3359                         .module_name      = "dib0700",
3360                         .rc_query         = dib0700_rc_query_old_firmware,
3361                         .allowed_protos   = RC_TYPE_RC5 |
3362                                             RC_TYPE_RC6 |
3363                                             RC_TYPE_NEC,
3364                         .change_protocol = dib0700_change_protocol,
3365                 },
3366         }, { DIB0700_DEFAULT_DEVICE_PROPERTIES,
3367
3368                 .num_adapters = 1,
3369                 .adapter = {
3370                         {
3371                         .num_frontends = 1,
3372                         .fe = {{
3373                                 .caps = DVB_USB_ADAP_HAS_PID_FILTER | DVB_USB_ADAP_PID_FILTER_CAN_BE_TURNED_OFF,
3374                                 .pid_filter_count = 32,
3375                                 .pid_filter       = stk70x0p_pid_filter,
3376                                 .pid_filter_ctrl  = stk70x0p_pid_filter_ctrl,
3377                                 .frontend_attach  = stk7070p_frontend_attach,
3378                                 .tuner_attach     = dib7070p_tuner_attach,
3379
3380                                 DIB0700_DEFAULT_STREAMING_CONFIG(0x02),
3381                         }},
3382                                 .size_of_priv     = sizeof(struct dib0700_adapter_state),
3383                         },
3384                 },
3385
3386                 .num_device_descs = 11,
3387                 .devices = {
3388                         {   "DiBcom STK7070P reference design",
3389                                 { &dib0700_usb_id_table[15], NULL },
3390                                 { NULL },
3391                         },
3392                         {   "Pinnacle PCTV DVB-T Flash Stick",
3393                                 { &dib0700_usb_id_table[16], NULL },
3394                                 { NULL },
3395                         },
3396                         {   "Artec T14BR DVB-T",
3397                                 { &dib0700_usb_id_table[22], NULL },
3398                                 { NULL },
3399                         },
3400                         {   "ASUS My Cinema U3100 Mini DVBT Tuner",
3401                                 { &dib0700_usb_id_table[24], NULL },
3402                                 { NULL },
3403                         },
3404                         {   "Hauppauge Nova-T Stick",
3405                                 { &dib0700_usb_id_table[25], NULL },
3406                                 { NULL },
3407                         },
3408                         {   "Hauppauge Nova-T MyTV.t",
3409                                 { &dib0700_usb_id_table[26], NULL },
3410                                 { NULL },
3411                         },
3412                         {   "Pinnacle PCTV 72e",
3413                                 { &dib0700_usb_id_table[29], NULL },
3414                                 { NULL },
3415                         },
3416                         {   "Pinnacle PCTV 73e",
3417                                 { &dib0700_usb_id_table[30], NULL },
3418                                 { NULL },
3419                         },
3420                         {   "Elgato EyeTV DTT",
3421                                 { &dib0700_usb_id_table[49], NULL },
3422                                 { NULL },
3423                         },
3424                         {   "Yuan PD378S",
3425                                 { &dib0700_usb_id_table[45], NULL },
3426                                 { NULL },
3427                         },
3428                         {   "Elgato EyeTV Dtt Dlx PD378S",
3429                                 { &dib0700_usb_id_table[50], NULL },
3430                                 { NULL },
3431                         },
3432                 },
3433
3434                 .rc.core = {
3435                         .rc_interval      = DEFAULT_RC_INTERVAL,
3436                         .rc_codes         = RC_MAP_DIB0700_RC5_TABLE,
3437                         .module_name      = "dib0700",
3438                         .rc_query         = dib0700_rc_query_old_firmware,
3439                         .allowed_protos   = RC_TYPE_RC5 |
3440                                             RC_TYPE_RC6 |
3441                                             RC_TYPE_NEC,
3442                         .change_protocol  = dib0700_change_protocol,
3443                 },
3444         }, { DIB0700_DEFAULT_DEVICE_PROPERTIES,
3445
3446                 .num_adapters = 1,
3447                 .adapter = {
3448                         {
3449                         .num_frontends = 1,
3450                         .fe = {{
3451                                 .caps = DVB_USB_ADAP_HAS_PID_FILTER | DVB_USB_ADAP_PID_FILTER_CAN_BE_TURNED_OFF,
3452                                 .pid_filter_count = 32,
3453                                 .pid_filter       = stk70x0p_pid_filter,
3454                                 .pid_filter_ctrl  = stk70x0p_pid_filter_ctrl,
3455                                 .frontend_attach  = stk7070p_frontend_attach,
3456                                 .tuner_attach     = dib7070p_tuner_attach,
3457
3458                                 DIB0700_DEFAULT_STREAMING_CONFIG(0x02),
3459                         }},
3460                                 .size_of_priv     = sizeof(struct dib0700_adapter_state),
3461                         },
3462                 },
3463
3464                 .num_device_descs = 3,
3465                 .devices = {
3466                         {   "Pinnacle PCTV 73A",
3467                                 { &dib0700_usb_id_table[56], NULL },
3468                                 { NULL },
3469                         },
3470                         {   "Pinnacle PCTV 73e SE",
3471                                 { &dib0700_usb_id_table[57], &dib0700_usb_id_table[65], NULL },
3472                                 { NULL },
3473                         },
3474                         {   "Pinnacle PCTV 282e",
3475                                 { &dib0700_usb_id_table[58], &dib0700_usb_id_table[66], NULL },
3476                                 { NULL },
3477                         },
3478                 },
3479
3480                 .rc.core = {
3481                         .rc_interval      = DEFAULT_RC_INTERVAL,
3482                         .rc_codes         = RC_MAP_DIB0700_RC5_TABLE,
3483                         .module_name      = "dib0700",
3484                         .rc_query         = dib0700_rc_query_old_firmware,
3485                         .allowed_protos   = RC_TYPE_RC5 |
3486                                             RC_TYPE_RC6 |
3487                                             RC_TYPE_NEC,
3488                         .change_protocol  = dib0700_change_protocol,
3489                 },
3490         }, { DIB0700_DEFAULT_DEVICE_PROPERTIES,
3491
3492                 .num_adapters = 2,
3493                 .adapter = {
3494                         {
3495                         .num_frontends = 1,
3496                         .fe = {{
3497                                 .caps = DVB_USB_ADAP_HAS_PID_FILTER | DVB_USB_ADAP_PID_FILTER_CAN_BE_TURNED_OFF,
3498                                 .pid_filter_count = 32,
3499                                 .pid_filter       = stk70x0p_pid_filter,
3500                                 .pid_filter_ctrl  = stk70x0p_pid_filter_ctrl,
3501                                 .frontend_attach  = stk7070pd_frontend_attach0,
3502                                 .tuner_attach     = dib7070p_tuner_attach,
3503
3504                                 DIB0700_DEFAULT_STREAMING_CONFIG(0x02),
3505                         }},
3506                                 .size_of_priv     = sizeof(struct dib0700_adapter_state),
3507                         }, {
3508                         .num_frontends = 1,
3509                         .fe = {{
3510                                 .caps = DVB_USB_ADAP_HAS_PID_FILTER | DVB_USB_ADAP_PID_FILTER_CAN_BE_TURNED_OFF,
3511                                 .pid_filter_count = 32,
3512                                 .pid_filter       = stk70x0p_pid_filter,
3513                                 .pid_filter_ctrl  = stk70x0p_pid_filter_ctrl,
3514                                 .frontend_attach  = stk7070pd_frontend_attach1,
3515                                 .tuner_attach     = dib7070p_tuner_attach,
3516
3517                                 DIB0700_DEFAULT_STREAMING_CONFIG(0x03),
3518                         }},
3519                                 .size_of_priv     = sizeof(struct dib0700_adapter_state),
3520                         }
3521                 },
3522
3523                 .num_device_descs = 6,
3524                 .devices = {
3525                         {   "DiBcom STK7070PD reference design",
3526                                 { &dib0700_usb_id_table[17], NULL },
3527                                 { NULL },
3528                         },
3529                         {   "Pinnacle PCTV Dual DVB-T Diversity Stick",
3530                                 { &dib0700_usb_id_table[18], NULL },
3531                                 { NULL },
3532                         },
3533                         {   "Hauppauge Nova-TD Stick (52009)",
3534                                 { &dib0700_usb_id_table[35], NULL },
3535                                 { NULL },
3536                         },
3537                         {   "Hauppauge Nova-TD-500 (84xxx)",
3538                                 { &dib0700_usb_id_table[36], NULL },
3539                                 { NULL },
3540                         },
3541                         {  "Terratec Cinergy DT USB XS Diversity/ T5",
3542                                 { &dib0700_usb_id_table[43],
3543                                         &dib0700_usb_id_table[53], NULL},
3544                                 { NULL },
3545                         },
3546                         {  "Sony PlayTV",
3547                                 { &dib0700_usb_id_table[44], NULL },
3548                                 { NULL },
3549                         },
3550                 },
3551
3552                 .rc.core = {
3553                         .rc_interval      = DEFAULT_RC_INTERVAL,
3554                         .rc_codes         = RC_MAP_DIB0700_RC5_TABLE,
3555                         .module_name      = "dib0700",
3556                         .rc_query         = dib0700_rc_query_old_firmware,
3557                         .allowed_protos   = RC_TYPE_RC5 |
3558                                             RC_TYPE_RC6 |
3559                                             RC_TYPE_NEC,
3560                         .change_protocol = dib0700_change_protocol,
3561                 },
3562         }, { DIB0700_DEFAULT_DEVICE_PROPERTIES,
3563
3564                 .num_adapters = 2,
3565                 .adapter = {
3566                         {
3567                         .num_frontends = 1,
3568                         .fe = {{
3569                                 .caps = DVB_USB_ADAP_HAS_PID_FILTER | DVB_USB_ADAP_PID_FILTER_CAN_BE_TURNED_OFF,
3570                                 .pid_filter_count = 32,
3571                                 .pid_filter       = stk70x0p_pid_filter,
3572                                 .pid_filter_ctrl  = stk70x0p_pid_filter_ctrl,
3573                                 .frontend_attach  = stk7070pd_frontend_attach0,
3574                                 .tuner_attach     = dib7070p_tuner_attach,
3575
3576                                 DIB0700_DEFAULT_STREAMING_CONFIG(0x02),
3577                         }},
3578                                 .size_of_priv     = sizeof(struct dib0700_adapter_state),
3579                         }, {
3580                         .num_frontends = 1,
3581                         .fe = {{
3582                                 .caps = DVB_USB_ADAP_HAS_PID_FILTER | DVB_USB_ADAP_PID_FILTER_CAN_BE_TURNED_OFF,
3583                                 .pid_filter_count = 32,
3584                                 .pid_filter       = stk70x0p_pid_filter,
3585                                 .pid_filter_ctrl  = stk70x0p_pid_filter_ctrl,
3586                                 .frontend_attach  = stk7070pd_frontend_attach1,
3587                                 .tuner_attach     = dib7070p_tuner_attach,
3588
3589                                 DIB0700_DEFAULT_STREAMING_CONFIG(0x03),
3590                         }},
3591                                 .size_of_priv     = sizeof(struct dib0700_adapter_state),
3592                         }
3593                 },
3594
3595                 .num_device_descs = 1,
3596                 .devices = {
3597                         {   "Elgato EyeTV Diversity",
3598                                 { &dib0700_usb_id_table[68], NULL },
3599                                 { NULL },
3600                         },
3601                 },
3602
3603                 .rc.core = {
3604                         .rc_interval      = DEFAULT_RC_INTERVAL,
3605                         .rc_codes         = RC_MAP_DIB0700_NEC_TABLE,
3606                         .module_name      = "dib0700",
3607                         .rc_query         = dib0700_rc_query_old_firmware,
3608                         .allowed_protos   = RC_TYPE_RC5 |
3609                                             RC_TYPE_RC6 |
3610                                             RC_TYPE_NEC,
3611                         .change_protocol  = dib0700_change_protocol,
3612                 },
3613         }, { DIB0700_DEFAULT_DEVICE_PROPERTIES,
3614
3615                 .num_adapters = 1,
3616                 .adapter = {
3617                         {
3618                         .num_frontends = 1,
3619                         .fe = {{
3620                                 .caps = DVB_USB_ADAP_HAS_PID_FILTER | DVB_USB_ADAP_PID_FILTER_CAN_BE_TURNED_OFF,
3621                                 .pid_filter_count = 32,
3622                                 .pid_filter       = stk70x0p_pid_filter,
3623                                 .pid_filter_ctrl  = stk70x0p_pid_filter_ctrl,
3624                                 .frontend_attach  = stk7700ph_frontend_attach,
3625                                 .tuner_attach     = stk7700ph_tuner_attach,
3626
3627                                 DIB0700_DEFAULT_STREAMING_CONFIG(0x02),
3628                         }},
3629                                 .size_of_priv = sizeof(struct
3630                                                 dib0700_adapter_state),
3631                         },
3632                 },
3633
3634                 .num_device_descs = 9,
3635                 .devices = {
3636                         {   "Terratec Cinergy HT USB XE",
3637                                 { &dib0700_usb_id_table[27], NULL },
3638                                 { NULL },
3639                         },
3640                         {   "Pinnacle Expresscard 320cx",
3641                                 { &dib0700_usb_id_table[28], NULL },
3642                                 { NULL },
3643                         },
3644                         {   "Terratec Cinergy HT Express",
3645                                 { &dib0700_usb_id_table[32], NULL },
3646                                 { NULL },
3647                         },
3648                         {   "Gigabyte U8000-RH",
3649                                 { &dib0700_usb_id_table[37], NULL },
3650                                 { NULL },
3651                         },
3652                         {   "YUAN High-Tech STK7700PH",
3653                                 { &dib0700_usb_id_table[38], NULL },
3654                                 { NULL },
3655                         },
3656                         {   "Asus My Cinema-U3000Hybrid",
3657                                 { &dib0700_usb_id_table[39], NULL },
3658                                 { NULL },
3659                         },
3660                         {   "YUAN High-Tech MC770",
3661                                 { &dib0700_usb_id_table[48], NULL },
3662                                 { NULL },
3663                         },
3664                         {   "Leadtek WinFast DTV Dongle H",
3665                                 { &dib0700_usb_id_table[51], NULL },
3666                                 { NULL },
3667                         },
3668                         {   "YUAN High-Tech STK7700D",
3669                                 { &dib0700_usb_id_table[54], NULL },
3670                                 { NULL },
3671                         },
3672                 },
3673
3674                 .rc.core = {
3675                         .rc_interval      = DEFAULT_RC_INTERVAL,
3676                         .rc_codes         = RC_MAP_DIB0700_RC5_TABLE,
3677                         .module_name      = "dib0700",
3678                         .rc_query         = dib0700_rc_query_old_firmware,
3679                         .allowed_protos   = RC_TYPE_RC5 |
3680                                             RC_TYPE_RC6 |
3681                                             RC_TYPE_NEC,
3682                         .change_protocol  = dib0700_change_protocol,
3683                 },
3684         }, { DIB0700_DEFAULT_DEVICE_PROPERTIES,
3685                 .num_adapters = 1,
3686                 .adapter = {
3687                         {
3688                         .num_frontends = 1,
3689                         .fe = {{
3690                                 .frontend_attach  = s5h1411_frontend_attach,
3691                                 .tuner_attach     = xc5000_tuner_attach,
3692
3693                                 DIB0700_DEFAULT_STREAMING_CONFIG(0x02),
3694                         }},
3695                                 .size_of_priv = sizeof(struct
3696                                                 dib0700_adapter_state),
3697                         },
3698                 },
3699
3700                 .num_device_descs = 2,
3701                 .devices = {
3702                         {   "Pinnacle PCTV HD Pro USB Stick",
3703                                 { &dib0700_usb_id_table[40], NULL },
3704                                 { NULL },
3705                         },
3706                         {   "Pinnacle PCTV HD USB Stick",
3707                                 { &dib0700_usb_id_table[41], NULL },
3708                                 { NULL },
3709                         },
3710                 },
3711
3712                 .rc.core = {
3713                         .rc_interval      = DEFAULT_RC_INTERVAL,
3714                         .rc_codes         = RC_MAP_DIB0700_RC5_TABLE,
3715                         .module_name      = "dib0700",
3716                         .rc_query         = dib0700_rc_query_old_firmware,
3717                         .allowed_protos   = RC_TYPE_RC5 |
3718                                             RC_TYPE_RC6 |
3719                                             RC_TYPE_NEC,
3720                         .change_protocol  = dib0700_change_protocol,
3721                 },
3722         }, { DIB0700_DEFAULT_DEVICE_PROPERTIES,
3723                 .num_adapters = 1,
3724                 .adapter = {
3725                         {
3726                         .num_frontends = 1,
3727                         .fe = {{
3728                                 .frontend_attach  = lgdt3305_frontend_attach,
3729                                 .tuner_attach     = mxl5007t_tuner_attach,
3730
3731                                 DIB0700_DEFAULT_STREAMING_CONFIG(0x02),
3732                         }},
3733                                 .size_of_priv = sizeof(struct
3734                                                 dib0700_adapter_state),
3735                         },
3736                 },
3737
3738                 .num_device_descs = 2,
3739                 .devices = {
3740                         {   "Hauppauge ATSC MiniCard (B200)",
3741                                 { &dib0700_usb_id_table[46], NULL },
3742                                 { NULL },
3743                         },
3744                         {   "Hauppauge ATSC MiniCard (B210)",
3745                                 { &dib0700_usb_id_table[47], NULL },
3746                                 { NULL },
3747                         },
3748                 },
3749         }, { DIB0700_DEFAULT_DEVICE_PROPERTIES,
3750
3751                 .num_adapters = 1,
3752                 .adapter = {
3753                         {
3754                         .num_frontends = 1,
3755                         .fe = {{
3756                                 .caps = DVB_USB_ADAP_HAS_PID_FILTER | DVB_USB_ADAP_PID_FILTER_CAN_BE_TURNED_OFF,
3757                                 .pid_filter_count = 32,
3758                                 .pid_filter       = stk70x0p_pid_filter,
3759                                 .pid_filter_ctrl  = stk70x0p_pid_filter_ctrl,
3760                                 .frontend_attach  = stk7770p_frontend_attach,
3761                                 .tuner_attach     = dib7770p_tuner_attach,
3762
3763                                 DIB0700_DEFAULT_STREAMING_CONFIG(0x02),
3764                         }},
3765                                 .size_of_priv =
3766                                         sizeof(struct dib0700_adapter_state),
3767                         },
3768                 },
3769
3770                 .num_device_descs = 4,
3771                 .devices = {
3772                         {   "DiBcom STK7770P reference design",
3773                                 { &dib0700_usb_id_table[59], NULL },
3774                                 { NULL },
3775                         },
3776                         {   "Terratec Cinergy T USB XXS (HD)/ T3",
3777                                 { &dib0700_usb_id_table[33],
3778                                         &dib0700_usb_id_table[52],
3779                                         &dib0700_usb_id_table[60], NULL},
3780                                 { NULL },
3781                         },
3782                         {   "TechniSat AirStar TeleStick 2",
3783                                 { &dib0700_usb_id_table[74], NULL },
3784                                 { NULL },
3785                         },
3786                         {   "Medion CTX1921 DVB-T USB",
3787                                 { &dib0700_usb_id_table[75], NULL },
3788                                 { NULL },
3789                         },
3790                 },
3791
3792                 .rc.core = {
3793                         .rc_interval      = DEFAULT_RC_INTERVAL,
3794                         .rc_codes         = RC_MAP_DIB0700_RC5_TABLE,
3795                         .module_name      = "dib0700",
3796                         .rc_query         = dib0700_rc_query_old_firmware,
3797                         .allowed_protos   = RC_TYPE_RC5 |
3798                                             RC_TYPE_RC6 |
3799                                             RC_TYPE_NEC,
3800                         .change_protocol  = dib0700_change_protocol,
3801                 },
3802         }, { DIB0700_DEFAULT_DEVICE_PROPERTIES,
3803                 .num_adapters = 1,
3804                 .adapter = {
3805                         {
3806                         .num_frontends = 1,
3807                         .fe = {{
3808                                 .caps  = DVB_USB_ADAP_HAS_PID_FILTER | DVB_USB_ADAP_PID_FILTER_CAN_BE_TURNED_OFF,
3809                                 .pid_filter_count = 32,
3810                                 .pid_filter = stk80xx_pid_filter,
3811                                 .pid_filter_ctrl = stk80xx_pid_filter_ctrl,
3812                                 .frontend_attach  = stk807x_frontend_attach,
3813                                 .tuner_attach     = dib807x_tuner_attach,
3814
3815                                 DIB0700_DEFAULT_STREAMING_CONFIG(0x02),
3816                         }},
3817                                 .size_of_priv =
3818                                         sizeof(struct dib0700_adapter_state),
3819                         },
3820                 },
3821
3822                 .num_device_descs = 3,
3823                 .devices = {
3824                         {   "DiBcom STK807xP reference design",
3825                                 { &dib0700_usb_id_table[62], NULL },
3826                                 { NULL },
3827                         },
3828                         {   "Prolink Pixelview SBTVD",
3829                                 { &dib0700_usb_id_table[63], NULL },
3830                                 { NULL },
3831                         },
3832                         {   "EvolutePC TVWay+",
3833                                 { &dib0700_usb_id_table[64], NULL },
3834                                 { NULL },
3835                         },
3836                 },
3837
3838                 .rc.core = {
3839                         .rc_interval      = DEFAULT_RC_INTERVAL,
3840                         .rc_codes         = RC_MAP_DIB0700_NEC_TABLE,
3841                         .module_name      = "dib0700",
3842                         .rc_query         = dib0700_rc_query_old_firmware,
3843                         .allowed_protos   = RC_TYPE_RC5 |
3844                                             RC_TYPE_RC6 |
3845                                             RC_TYPE_NEC,
3846                         .change_protocol  = dib0700_change_protocol,
3847                 },
3848         }, { DIB0700_DEFAULT_DEVICE_PROPERTIES,
3849                 .num_adapters = 2,
3850                 .adapter = {
3851                         {
3852                         .num_frontends = 1,
3853                         .fe = {{
3854                                 .caps  = DVB_USB_ADAP_HAS_PID_FILTER | DVB_USB_ADAP_PID_FILTER_CAN_BE_TURNED_OFF,
3855                                 .pid_filter_count = 32,
3856                                 .pid_filter = stk80xx_pid_filter,
3857                                 .pid_filter_ctrl = stk80xx_pid_filter_ctrl,
3858                                 .frontend_attach  = stk807xpvr_frontend_attach0,
3859                                 .tuner_attach     = dib807x_tuner_attach,
3860
3861                                 DIB0700_DEFAULT_STREAMING_CONFIG(0x02),
3862                         }},
3863                                 .size_of_priv =
3864                                         sizeof(struct dib0700_adapter_state),
3865                         },
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 = stk80xx_pid_filter,
3872                                 .pid_filter_ctrl = stk80xx_pid_filter_ctrl,
3873                                 .frontend_attach  = stk807xpvr_frontend_attach1,
3874                                 .tuner_attach     = dib807x_tuner_attach,
3875
3876                                 DIB0700_DEFAULT_STREAMING_CONFIG(0x03),
3877                         }},
3878                                 .size_of_priv =
3879                                         sizeof(struct dib0700_adapter_state),
3880                         },
3881                 },
3882
3883                 .num_device_descs = 1,
3884                 .devices = {
3885                         {   "DiBcom STK807xPVR reference design",
3886                                 { &dib0700_usb_id_table[61], NULL },
3887                                 { NULL },
3888                         },
3889                 },
3890
3891                 .rc.core = {
3892                         .rc_interval      = DEFAULT_RC_INTERVAL,
3893                         .rc_codes         = RC_MAP_DIB0700_RC5_TABLE,
3894                         .module_name      = "dib0700",
3895                         .rc_query         = dib0700_rc_query_old_firmware,
3896                         .allowed_protos   = RC_TYPE_RC5 |
3897                                             RC_TYPE_RC6 |
3898                                             RC_TYPE_NEC,
3899                         .change_protocol  = dib0700_change_protocol,
3900                 },
3901         }, { DIB0700_DEFAULT_DEVICE_PROPERTIES,
3902                 .num_adapters = 1,
3903                 .adapter = {
3904                         {
3905                         .num_frontends = 1,
3906                         .fe = {{
3907                                 .caps  = DVB_USB_ADAP_HAS_PID_FILTER |
3908                                         DVB_USB_ADAP_PID_FILTER_CAN_BE_TURNED_OFF,
3909                                 .pid_filter_count = 32,
3910                                 .pid_filter = stk80xx_pid_filter,
3911                                 .pid_filter_ctrl = stk80xx_pid_filter_ctrl,
3912                                 .frontend_attach  = stk809x_frontend_attach,
3913                                 .tuner_attach     = dib809x_tuner_attach,
3914
3915                                 DIB0700_DEFAULT_STREAMING_CONFIG(0x02),
3916                         }},
3917                                 .size_of_priv =
3918                                         sizeof(struct dib0700_adapter_state),
3919                         },
3920                 },
3921
3922                 .num_device_descs = 1,
3923                 .devices = {
3924                         {   "DiBcom STK8096GP reference design",
3925                                 { &dib0700_usb_id_table[67], NULL },
3926                                 { NULL },
3927                         },
3928                 },
3929
3930                 .rc.core = {
3931                         .rc_interval      = DEFAULT_RC_INTERVAL,
3932                         .rc_codes         = RC_MAP_DIB0700_RC5_TABLE,
3933                         .module_name      = "dib0700",
3934                         .rc_query         = dib0700_rc_query_old_firmware,
3935                         .allowed_protos   = RC_TYPE_RC5 |
3936                                             RC_TYPE_RC6 |
3937                                             RC_TYPE_NEC,
3938                         .change_protocol  = dib0700_change_protocol,
3939                 },
3940         }, { DIB0700_DEFAULT_DEVICE_PROPERTIES,
3941                 .num_adapters = 1,
3942                 .adapter = {
3943                         {
3944                         .num_frontends = 1,
3945                         .fe = {{
3946                                 .caps  = DVB_USB_ADAP_HAS_PID_FILTER |
3947                                         DVB_USB_ADAP_PID_FILTER_CAN_BE_TURNED_OFF,
3948                                 .pid_filter_count = 32,
3949                                 .pid_filter = dib90x0_pid_filter,
3950                                 .pid_filter_ctrl = dib90x0_pid_filter_ctrl,
3951                                 .frontend_attach  = stk9090m_frontend_attach,
3952                                 .tuner_attach     = dib9090_tuner_attach,
3953
3954                                 DIB0700_DEFAULT_STREAMING_CONFIG(0x02),
3955                         }},
3956                                 .size_of_priv =
3957                                         sizeof(struct dib0700_adapter_state),
3958                         },
3959                 },
3960
3961                 .num_device_descs = 1,
3962                 .devices = {
3963                         {   "DiBcom STK9090M reference design",
3964                                 { &dib0700_usb_id_table[69], NULL },
3965                                 { NULL },
3966                         },
3967                 },
3968
3969                 .rc.core = {
3970                         .rc_interval      = DEFAULT_RC_INTERVAL,
3971                         .rc_codes         = RC_MAP_DIB0700_RC5_TABLE,
3972                         .module_name      = "dib0700",
3973                         .rc_query         = dib0700_rc_query_old_firmware,
3974                         .allowed_protos   = RC_TYPE_RC5 |
3975                                             RC_TYPE_RC6 |
3976                                             RC_TYPE_NEC,
3977                         .change_protocol  = dib0700_change_protocol,
3978                 },
3979         }, { DIB0700_DEFAULT_DEVICE_PROPERTIES,
3980                 .num_adapters = 1,
3981                 .adapter = {
3982                         {
3983                         .num_frontends = 1,
3984                         .fe = {{
3985                                 .caps  = DVB_USB_ADAP_HAS_PID_FILTER |
3986                                         DVB_USB_ADAP_PID_FILTER_CAN_BE_TURNED_OFF,
3987                                 .pid_filter_count = 32,
3988                                 .pid_filter = stk80xx_pid_filter,
3989                                 .pid_filter_ctrl = stk80xx_pid_filter_ctrl,
3990                                 .frontend_attach  = nim8096md_frontend_attach,
3991                                 .tuner_attach     = nim8096md_tuner_attach,
3992
3993                                 DIB0700_DEFAULT_STREAMING_CONFIG(0x02),
3994                         }},
3995                                 .size_of_priv =
3996                                         sizeof(struct dib0700_adapter_state),
3997                         },
3998                 },
3999
4000                 .num_device_descs = 1,
4001                 .devices = {
4002                         {   "DiBcom NIM8096MD reference design",
4003                                 { &dib0700_usb_id_table[70], NULL },
4004                                 { NULL },
4005                         },
4006                 },
4007
4008                 .rc.core = {
4009                         .rc_interval      = DEFAULT_RC_INTERVAL,
4010                         .rc_codes         = RC_MAP_DIB0700_RC5_TABLE,
4011                         .module_name      = "dib0700",
4012                         .rc_query         = dib0700_rc_query_old_firmware,
4013                         .allowed_protos   = RC_TYPE_RC5 |
4014                                             RC_TYPE_RC6 |
4015                                             RC_TYPE_NEC,
4016                         .change_protocol  = dib0700_change_protocol,
4017                 },
4018         }, { DIB0700_DEFAULT_DEVICE_PROPERTIES,
4019                 .num_adapters = 1,
4020                 .adapter = {
4021                         {
4022                         .num_frontends = 1,
4023                         .fe = {{
4024                                 .caps  = DVB_USB_ADAP_HAS_PID_FILTER |
4025                                         DVB_USB_ADAP_PID_FILTER_CAN_BE_TURNED_OFF,
4026                                 .pid_filter_count = 32,
4027                                 .pid_filter = dib90x0_pid_filter,
4028                                 .pid_filter_ctrl = dib90x0_pid_filter_ctrl,
4029                                 .frontend_attach  = nim9090md_frontend_attach,
4030                                 .tuner_attach     = nim9090md_tuner_attach,
4031
4032                                 DIB0700_DEFAULT_STREAMING_CONFIG(0x02),
4033                         }},
4034                                 .size_of_priv =
4035                                         sizeof(struct dib0700_adapter_state),
4036                         },
4037                 },
4038
4039                 .num_device_descs = 1,
4040                 .devices = {
4041                         {   "DiBcom NIM9090MD reference design",
4042                                 { &dib0700_usb_id_table[71], NULL },
4043                                 { NULL },
4044                         },
4045                 },
4046
4047                 .rc.core = {
4048                         .rc_interval      = DEFAULT_RC_INTERVAL,
4049                         .rc_codes         = RC_MAP_DIB0700_RC5_TABLE,
4050                         .module_name      = "dib0700",
4051                         .rc_query         = dib0700_rc_query_old_firmware,
4052                         .allowed_protos   = RC_TYPE_RC5 |
4053                                             RC_TYPE_RC6 |
4054                                             RC_TYPE_NEC,
4055                         .change_protocol  = dib0700_change_protocol,
4056                 },
4057         }, { DIB0700_DEFAULT_DEVICE_PROPERTIES,
4058                 .num_adapters = 1,
4059                 .adapter = {
4060                         {
4061                         .num_frontends = 1,
4062                         .fe = {{
4063                                 .caps  = DVB_USB_ADAP_HAS_PID_FILTER |
4064                                         DVB_USB_ADAP_PID_FILTER_CAN_BE_TURNED_OFF,
4065                                 .pid_filter_count = 32,
4066                                 .pid_filter = stk70x0p_pid_filter,
4067                                 .pid_filter_ctrl = stk70x0p_pid_filter_ctrl,
4068                                 .frontend_attach  = nim7090_frontend_attach,
4069                                 .tuner_attach     = nim7090_tuner_attach,
4070
4071                                 DIB0700_DEFAULT_STREAMING_CONFIG(0x02),
4072                         }},
4073                                 .size_of_priv =
4074                                         sizeof(struct dib0700_adapter_state),
4075                         },
4076                 },
4077
4078                 .num_device_descs = 1,
4079                 .devices = {
4080                         {   "DiBcom NIM7090 reference design",
4081                                 { &dib0700_usb_id_table[72], NULL },
4082                                 { NULL },
4083                         },
4084                 },
4085
4086                 .rc.core = {
4087                         .rc_interval      = DEFAULT_RC_INTERVAL,
4088                         .rc_codes         = RC_MAP_DIB0700_RC5_TABLE,
4089                         .module_name      = "dib0700",
4090                         .rc_query         = dib0700_rc_query_old_firmware,
4091                         .allowed_protos   = RC_TYPE_RC5 |
4092                                             RC_TYPE_RC6 |
4093                                             RC_TYPE_NEC,
4094                         .change_protocol  = dib0700_change_protocol,
4095                 },
4096         }, { DIB0700_DEFAULT_DEVICE_PROPERTIES,
4097                 .num_adapters = 2,
4098                 .adapter = {
4099                         {
4100                         .num_frontends = 1,
4101                         .fe = {{
4102                                 .caps  = DVB_USB_ADAP_HAS_PID_FILTER |
4103                                         DVB_USB_ADAP_PID_FILTER_CAN_BE_TURNED_OFF,
4104                                 .pid_filter_count = 32,
4105                                 .pid_filter = stk70x0p_pid_filter,
4106                                 .pid_filter_ctrl = stk70x0p_pid_filter_ctrl,
4107                                 .frontend_attach  = tfe7090pvr_frontend0_attach,
4108                                 .tuner_attach     = tfe7090pvr_tuner0_attach,
4109
4110                                 DIB0700_DEFAULT_STREAMING_CONFIG(0x03),
4111                         }},
4112                                 .size_of_priv =
4113                                         sizeof(struct dib0700_adapter_state),
4114                         },
4115                         {
4116                         .num_frontends = 1,
4117                         .fe = {{
4118                                 .caps  = DVB_USB_ADAP_HAS_PID_FILTER |
4119                                         DVB_USB_ADAP_PID_FILTER_CAN_BE_TURNED_OFF,
4120                                 .pid_filter_count = 32,
4121                                 .pid_filter = stk70x0p_pid_filter,
4122                                 .pid_filter_ctrl = stk70x0p_pid_filter_ctrl,
4123                                 .frontend_attach  = tfe7090pvr_frontend1_attach,
4124                                 .tuner_attach     = tfe7090pvr_tuner1_attach,
4125
4126                                 DIB0700_DEFAULT_STREAMING_CONFIG(0x02),
4127                         }},
4128                                 .size_of_priv =
4129                                         sizeof(struct dib0700_adapter_state),
4130                         },
4131                 },
4132
4133                 .num_device_descs = 1,
4134                 .devices = {
4135                         {   "DiBcom TFE7090PVR reference design",
4136                                 { &dib0700_usb_id_table[73], NULL },
4137                                 { NULL },
4138                         },
4139                 },
4140
4141                 .rc.core = {
4142                         .rc_interval      = DEFAULT_RC_INTERVAL,
4143                         .rc_codes         = RC_MAP_DIB0700_RC5_TABLE,
4144                         .module_name      = "dib0700",
4145                         .rc_query         = dib0700_rc_query_old_firmware,
4146                         .allowed_protos   = RC_TYPE_RC5 |
4147                                             RC_TYPE_RC6 |
4148                                             RC_TYPE_NEC,
4149                         .change_protocol  = dib0700_change_protocol,
4150                 },
4151         }, { DIB0700_DEFAULT_DEVICE_PROPERTIES,
4152                 .num_adapters = 1,
4153                 .adapter = {
4154                         {
4155                         .num_frontends = 1,
4156                         .fe = {{
4157                                 .frontend_attach  = pctv340e_frontend_attach,
4158                                 .tuner_attach     = xc4000_tuner_attach,
4159
4160                                 DIB0700_DEFAULT_STREAMING_CONFIG(0x02),
4161                         }},
4162                                 .size_of_priv = sizeof(struct
4163                                                 dib0700_adapter_state),
4164                         },
4165                 },
4166
4167                 .num_device_descs = 2,
4168                 .devices = {
4169                         {   "Pinnacle PCTV 340e HD Pro USB Stick",
4170                                 { &dib0700_usb_id_table[76], NULL },
4171                                 { NULL },
4172                         },
4173                         {   "Pinnacle PCTV Hybrid Stick Solo",
4174                                 { &dib0700_usb_id_table[77], NULL },
4175                                 { NULL },
4176                         },
4177                 },
4178                 .rc.core = {
4179                         .rc_interval      = DEFAULT_RC_INTERVAL,
4180                         .rc_codes         = RC_MAP_DIB0700_RC5_TABLE,
4181                         .module_name      = "dib0700",
4182                         .rc_query         = dib0700_rc_query_old_firmware,
4183                         .allowed_protos   = RC_TYPE_RC5 |
4184                                             RC_TYPE_RC6 |
4185                                             RC_TYPE_NEC,
4186                         .change_protocol  = dib0700_change_protocol,
4187                 },
4188         }, { DIB0700_DEFAULT_DEVICE_PROPERTIES,
4189                 .num_adapters = 1,
4190                 .adapter = {
4191                         {
4192                                 .num_frontends = 1,
4193                                 .fe = {{
4194                                         .caps  = DVB_USB_ADAP_HAS_PID_FILTER |
4195                                                 DVB_USB_ADAP_PID_FILTER_CAN_BE_TURNED_OFF,
4196                                         .pid_filter_count = 32,
4197                                         .pid_filter = stk70x0p_pid_filter,
4198                                         .pid_filter_ctrl = stk70x0p_pid_filter_ctrl,
4199                                         .frontend_attach  = tfe7090e_frontend_attach,
4200                                         .tuner_attach     = tfe7090e_tuner_attach,
4201
4202                                         DIB0700_DEFAULT_STREAMING_CONFIG(0x02),
4203                                 } },
4204
4205                                 .size_of_priv =
4206                                         sizeof(struct dib0700_adapter_state),
4207                         },
4208                 },
4209
4210                 .num_device_descs = 1,
4211                 .devices = {
4212                         {   "DiBcom TFE7090E reference design",
4213                                 { &dib0700_usb_id_table[78], NULL },
4214                                 { NULL },
4215                         },
4216                 },
4217
4218                 .rc.core = {
4219                         .rc_interval      = DEFAULT_RC_INTERVAL,
4220                         .rc_codes         = RC_MAP_DIB0700_RC5_TABLE,
4221                         .module_name      = "dib0700",
4222                         .rc_query         = dib0700_rc_query_old_firmware,
4223                         .allowed_protos   = RC_TYPE_RC5 |
4224                                             RC_TYPE_RC6 |
4225                                             RC_TYPE_NEC,
4226                         .change_protocol  = dib0700_change_protocol,
4227                 },
4228         },
4229 };
4230
4231 int dib0700_device_count = ARRAY_SIZE(dib0700_devices);