include cleanup: Update gfp.h and slab.h includes to prepare for breaking implicit...
[safe/jmp/linux-2.6] / drivers / media / dvb / dvb-usb / cxusb.c
1 /* DVB USB compliant linux driver for Conexant USB reference design.
2  *
3  * The Conexant reference design I saw on their website was only for analogue
4  * capturing (using the cx25842). The box I took to write this driver (reverse
5  * engineered) is the one labeled Medion MD95700. In addition to the cx25842
6  * for analogue capturing it also has a cx22702 DVB-T demodulator on the main
7  * board. Besides it has a atiremote (X10) and a USB2.0 hub onboard.
8  *
9  * Maybe it is a little bit premature to call this driver cxusb, but I assume
10  * the USB protocol is identical or at least inherited from the reference
11  * design, so it can be reused for the "analogue-only" device (if it will
12  * appear at all).
13  *
14  * TODO: Use the cx25840-driver for the analogue part
15  *
16  * Copyright (C) 2005 Patrick Boettcher (patrick.boettcher@desy.de)
17  * Copyright (C) 2006 Michael Krufky (mkrufky@linuxtv.org)
18  * Copyright (C) 2006, 2007 Chris Pascoe (c.pascoe@itee.uq.edu.au)
19  *
20  *   This program is free software; you can redistribute it and/or modify it
21  *   under the terms of the GNU General Public License as published by the Free
22  *   Software Foundation, version 2.
23  *
24  * see Documentation/dvb/README.dvb-usb for more information
25  */
26 #include <media/tuner.h>
27 #include <linux/vmalloc.h>
28 #include <linux/slab.h>
29
30 #include "cxusb.h"
31
32 #include "cx22702.h"
33 #include "lgdt330x.h"
34 #include "mt352.h"
35 #include "mt352_priv.h"
36 #include "zl10353.h"
37 #include "tuner-xc2028.h"
38 #include "tuner-simple.h"
39 #include "mxl5005s.h"
40 #include "max2165.h"
41 #include "dib7000p.h"
42 #include "dib0070.h"
43 #include "lgs8gxx.h"
44 #include "atbm8830.h"
45
46 /* debug */
47 static int dvb_usb_cxusb_debug;
48 module_param_named(debug, dvb_usb_cxusb_debug, int, 0644);
49 MODULE_PARM_DESC(debug, "set debugging level (1=rc (or-able))." DVB_USB_DEBUG_STATUS);
50
51 DVB_DEFINE_MOD_OPT_ADAPTER_NR(adapter_nr);
52
53 #define deb_info(args...)   dprintk(dvb_usb_cxusb_debug, 0x03, args)
54 #define deb_i2c(args...)    dprintk(dvb_usb_cxusb_debug, 0x02, args)
55
56 static int cxusb_ctrl_msg(struct dvb_usb_device *d,
57                           u8 cmd, u8 *wbuf, int wlen, u8 *rbuf, int rlen)
58 {
59         int wo = (rbuf == NULL || rlen == 0); /* write-only */
60         u8 sndbuf[1+wlen];
61         memset(sndbuf, 0, 1+wlen);
62
63         sndbuf[0] = cmd;
64         memcpy(&sndbuf[1], wbuf, wlen);
65         if (wo)
66                 return dvb_usb_generic_write(d, sndbuf, 1+wlen);
67         else
68                 return dvb_usb_generic_rw(d, sndbuf, 1+wlen, rbuf, rlen, 0);
69 }
70
71 /* GPIO */
72 static void cxusb_gpio_tuner(struct dvb_usb_device *d, int onoff)
73 {
74         struct cxusb_state *st = d->priv;
75         u8 o[2], i;
76
77         if (st->gpio_write_state[GPIO_TUNER] == onoff)
78                 return;
79
80         o[0] = GPIO_TUNER;
81         o[1] = onoff;
82         cxusb_ctrl_msg(d, CMD_GPIO_WRITE, o, 2, &i, 1);
83
84         if (i != 0x01)
85                 deb_info("gpio_write failed.\n");
86
87         st->gpio_write_state[GPIO_TUNER] = onoff;
88 }
89
90 static int cxusb_bluebird_gpio_rw(struct dvb_usb_device *d, u8 changemask,
91                                  u8 newval)
92 {
93         u8 o[2], gpio_state;
94         int rc;
95
96         o[0] = 0xff & ~changemask;      /* mask of bits to keep */
97         o[1] = newval & changemask;     /* new values for bits  */
98
99         rc = cxusb_ctrl_msg(d, CMD_BLUEBIRD_GPIO_RW, o, 2, &gpio_state, 1);
100         if (rc < 0 || (gpio_state & changemask) != (newval & changemask))
101                 deb_info("bluebird_gpio_write failed.\n");
102
103         return rc < 0 ? rc : gpio_state;
104 }
105
106 static void cxusb_bluebird_gpio_pulse(struct dvb_usb_device *d, u8 pin, int low)
107 {
108         cxusb_bluebird_gpio_rw(d, pin, low ? 0 : pin);
109         msleep(5);
110         cxusb_bluebird_gpio_rw(d, pin, low ? pin : 0);
111 }
112
113 static void cxusb_nano2_led(struct dvb_usb_device *d, int onoff)
114 {
115         cxusb_bluebird_gpio_rw(d, 0x40, onoff ? 0 : 0x40);
116 }
117
118 static int cxusb_d680_dmb_gpio_tuner(struct dvb_usb_device *d,
119                 u8 addr, int onoff)
120 {
121         u8  o[2] = {addr, onoff};
122         u8  i;
123         int rc;
124
125         rc = cxusb_ctrl_msg(d, CMD_GPIO_WRITE, o, 2, &i, 1);
126
127         if (rc < 0)
128                 return rc;
129         if (i == 0x01)
130                 return 0;
131         else {
132                 deb_info("gpio_write failed.\n");
133                 return -EIO;
134         }
135 }
136
137 /* I2C */
138 static int cxusb_i2c_xfer(struct i2c_adapter *adap, struct i2c_msg msg[],
139                           int num)
140 {
141         struct dvb_usb_device *d = i2c_get_adapdata(adap);
142         int i;
143
144         if (mutex_lock_interruptible(&d->i2c_mutex) < 0)
145                 return -EAGAIN;
146
147         for (i = 0; i < num; i++) {
148
149                 if (d->udev->descriptor.idVendor == USB_VID_MEDION)
150                         switch (msg[i].addr) {
151                         case 0x63:
152                                 cxusb_gpio_tuner(d, 0);
153                                 break;
154                         default:
155                                 cxusb_gpio_tuner(d, 1);
156                                 break;
157                         }
158
159                 if (msg[i].flags & I2C_M_RD) {
160                         /* read only */
161                         u8 obuf[3], ibuf[1+msg[i].len];
162                         obuf[0] = 0;
163                         obuf[1] = msg[i].len;
164                         obuf[2] = msg[i].addr;
165                         if (cxusb_ctrl_msg(d, CMD_I2C_READ,
166                                            obuf, 3,
167                                            ibuf, 1+msg[i].len) < 0) {
168                                 warn("i2c read failed");
169                                 break;
170                         }
171                         memcpy(msg[i].buf, &ibuf[1], msg[i].len);
172                 } else if (i+1 < num && (msg[i+1].flags & I2C_M_RD) &&
173                            msg[i].addr == msg[i+1].addr) {
174                         /* write to then read from same address */
175                         u8 obuf[3+msg[i].len], ibuf[1+msg[i+1].len];
176                         obuf[0] = msg[i].len;
177                         obuf[1] = msg[i+1].len;
178                         obuf[2] = msg[i].addr;
179                         memcpy(&obuf[3], msg[i].buf, msg[i].len);
180
181                         if (cxusb_ctrl_msg(d, CMD_I2C_READ,
182                                            obuf, 3+msg[i].len,
183                                            ibuf, 1+msg[i+1].len) < 0)
184                                 break;
185
186                         if (ibuf[0] != 0x08)
187                                 deb_i2c("i2c read may have failed\n");
188
189                         memcpy(msg[i+1].buf, &ibuf[1], msg[i+1].len);
190
191                         i++;
192                 } else {
193                         /* write only */
194                         u8 obuf[2+msg[i].len], ibuf;
195                         obuf[0] = msg[i].addr;
196                         obuf[1] = msg[i].len;
197                         memcpy(&obuf[2], msg[i].buf, msg[i].len);
198
199                         if (cxusb_ctrl_msg(d, CMD_I2C_WRITE, obuf,
200                                            2+msg[i].len, &ibuf,1) < 0)
201                                 break;
202                         if (ibuf != 0x08)
203                                 deb_i2c("i2c write may have failed\n");
204                 }
205         }
206
207         mutex_unlock(&d->i2c_mutex);
208         return i == num ? num : -EREMOTEIO;
209 }
210
211 static u32 cxusb_i2c_func(struct i2c_adapter *adapter)
212 {
213         return I2C_FUNC_I2C;
214 }
215
216 static struct i2c_algorithm cxusb_i2c_algo = {
217         .master_xfer   = cxusb_i2c_xfer,
218         .functionality = cxusb_i2c_func,
219 };
220
221 static int cxusb_power_ctrl(struct dvb_usb_device *d, int onoff)
222 {
223         u8 b = 0;
224         if (onoff)
225                 return cxusb_ctrl_msg(d, CMD_POWER_ON, &b, 1, NULL, 0);
226         else
227                 return cxusb_ctrl_msg(d, CMD_POWER_OFF, &b, 1, NULL, 0);
228 }
229
230 static int cxusb_aver_power_ctrl(struct dvb_usb_device *d, int onoff)
231 {
232         int ret;
233         if (!onoff)
234                 return cxusb_ctrl_msg(d, CMD_POWER_OFF, NULL, 0, NULL, 0);
235         if (d->state == DVB_USB_STATE_INIT &&
236             usb_set_interface(d->udev, 0, 0) < 0)
237                 err("set interface failed");
238         do {} while (!(ret = cxusb_ctrl_msg(d, CMD_POWER_ON, NULL, 0, NULL, 0)) &&
239                    !(ret = cxusb_ctrl_msg(d, 0x15, NULL, 0, NULL, 0)) &&
240                    !(ret = cxusb_ctrl_msg(d, 0x17, NULL, 0, NULL, 0)) && 0);
241         if (!ret) {
242                 /* FIXME: We don't know why, but we need to configure the
243                  * lgdt3303 with the register settings below on resume */
244                 int i;
245                 u8 buf, bufs[] = {
246                         0x0e, 0x2, 0x00, 0x7f,
247                         0x0e, 0x2, 0x02, 0xfe,
248                         0x0e, 0x2, 0x02, 0x01,
249                         0x0e, 0x2, 0x00, 0x03,
250                         0x0e, 0x2, 0x0d, 0x40,
251                         0x0e, 0x2, 0x0e, 0x87,
252                         0x0e, 0x2, 0x0f, 0x8e,
253                         0x0e, 0x2, 0x10, 0x01,
254                         0x0e, 0x2, 0x14, 0xd7,
255                         0x0e, 0x2, 0x47, 0x88,
256                 };
257                 msleep(20);
258                 for (i = 0; i < sizeof(bufs)/sizeof(u8); i += 4/sizeof(u8)) {
259                         ret = cxusb_ctrl_msg(d, CMD_I2C_WRITE,
260                                              bufs+i, 4, &buf, 1);
261                         if (ret)
262                                 break;
263                         if (buf != 0x8)
264                                 return -EREMOTEIO;
265                 }
266         }
267         return ret;
268 }
269
270 static int cxusb_bluebird_power_ctrl(struct dvb_usb_device *d, int onoff)
271 {
272         u8 b = 0;
273         if (onoff)
274                 return cxusb_ctrl_msg(d, CMD_POWER_ON, &b, 1, NULL, 0);
275         else
276                 return 0;
277 }
278
279 static int cxusb_nano2_power_ctrl(struct dvb_usb_device *d, int onoff)
280 {
281         int rc = 0;
282
283         rc = cxusb_power_ctrl(d, onoff);
284         if (!onoff)
285                 cxusb_nano2_led(d, 0);
286
287         return rc;
288 }
289
290 static int cxusb_d680_dmb_power_ctrl(struct dvb_usb_device *d, int onoff)
291 {
292         int ret;
293         u8  b;
294         ret = cxusb_power_ctrl(d, onoff);
295         if (!onoff)
296                 return ret;
297
298         msleep(128);
299         cxusb_ctrl_msg(d, CMD_DIGITAL, NULL, 0, &b, 1);
300         msleep(100);
301         return ret;
302 }
303
304 static int cxusb_streaming_ctrl(struct dvb_usb_adapter *adap, int onoff)
305 {
306         u8 buf[2] = { 0x03, 0x00 };
307         if (onoff)
308                 cxusb_ctrl_msg(adap->dev, CMD_STREAMING_ON, buf, 2, NULL, 0);
309         else
310                 cxusb_ctrl_msg(adap->dev, CMD_STREAMING_OFF, NULL, 0, NULL, 0);
311
312         return 0;
313 }
314
315 static int cxusb_aver_streaming_ctrl(struct dvb_usb_adapter *adap, int onoff)
316 {
317         if (onoff)
318                 cxusb_ctrl_msg(adap->dev, CMD_AVER_STREAM_ON, NULL, 0, NULL, 0);
319         else
320                 cxusb_ctrl_msg(adap->dev, CMD_AVER_STREAM_OFF,
321                                NULL, 0, NULL, 0);
322         return 0;
323 }
324
325 static void cxusb_d680_dmb_drain_message(struct dvb_usb_device *d)
326 {
327         int       ep = d->props.generic_bulk_ctrl_endpoint;
328         const int timeout = 100;
329         const int junk_len = 32;
330         u8        *junk;
331         int       rd_count;
332
333         /* Discard remaining data in video pipe */
334         junk = kmalloc(junk_len, GFP_KERNEL);
335         if (!junk)
336                 return;
337         while (1) {
338                 if (usb_bulk_msg(d->udev,
339                         usb_rcvbulkpipe(d->udev, ep),
340                         junk, junk_len, &rd_count, timeout) < 0)
341                         break;
342                 if (!rd_count)
343                         break;
344         }
345         kfree(junk);
346 }
347
348 static void cxusb_d680_dmb_drain_video(struct dvb_usb_device *d)
349 {
350         struct usb_data_stream_properties *p = &d->props.adapter[0].stream;
351         const int timeout = 100;
352         const int junk_len = p->u.bulk.buffersize;
353         u8        *junk;
354         int       rd_count;
355
356         /* Discard remaining data in video pipe */
357         junk = kmalloc(junk_len, GFP_KERNEL);
358         if (!junk)
359                 return;
360         while (1) {
361                 if (usb_bulk_msg(d->udev,
362                         usb_rcvbulkpipe(d->udev, p->endpoint),
363                         junk, junk_len, &rd_count, timeout) < 0)
364                         break;
365                 if (!rd_count)
366                         break;
367         }
368         kfree(junk);
369 }
370
371 static int cxusb_d680_dmb_streaming_ctrl(
372                 struct dvb_usb_adapter *adap, int onoff)
373 {
374         if (onoff) {
375                 u8 buf[2] = { 0x03, 0x00 };
376                 cxusb_d680_dmb_drain_video(adap->dev);
377                 return cxusb_ctrl_msg(adap->dev, CMD_STREAMING_ON,
378                         buf, sizeof(buf), NULL, 0);
379         } else {
380                 int ret = cxusb_ctrl_msg(adap->dev,
381                         CMD_STREAMING_OFF, NULL, 0, NULL, 0);
382                 return ret;
383         }
384 }
385
386 static int cxusb_rc_query(struct dvb_usb_device *d, u32 *event, int *state)
387 {
388         struct dvb_usb_rc_key *keymap = d->props.rc_key_map;
389         u8 ircode[4];
390         int i;
391
392         cxusb_ctrl_msg(d, CMD_GET_IR_CODE, NULL, 0, ircode, 4);
393
394         *event = 0;
395         *state = REMOTE_NO_KEY_PRESSED;
396
397         for (i = 0; i < d->props.rc_key_map_size; i++) {
398                 if (rc5_custom(&keymap[i]) == ircode[2] &&
399                     rc5_data(&keymap[i]) == ircode[3]) {
400                         *event = keymap[i].event;
401                         *state = REMOTE_KEY_PRESSED;
402
403                         return 0;
404                 }
405         }
406
407         return 0;
408 }
409
410 static int cxusb_bluebird2_rc_query(struct dvb_usb_device *d, u32 *event,
411                                     int *state)
412 {
413         struct dvb_usb_rc_key *keymap = d->props.rc_key_map;
414         u8 ircode[4];
415         int i;
416         struct i2c_msg msg = { .addr = 0x6b, .flags = I2C_M_RD,
417                                .buf = ircode, .len = 4 };
418
419         *event = 0;
420         *state = REMOTE_NO_KEY_PRESSED;
421
422         if (cxusb_i2c_xfer(&d->i2c_adap, &msg, 1) != 1)
423                 return 0;
424
425         for (i = 0; i < d->props.rc_key_map_size; i++) {
426                 if (rc5_custom(&keymap[i]) == ircode[1] &&
427                     rc5_data(&keymap[i]) == ircode[2]) {
428                         *event = keymap[i].event;
429                         *state = REMOTE_KEY_PRESSED;
430
431                         return 0;
432                 }
433         }
434
435         return 0;
436 }
437
438 static int cxusb_d680_dmb_rc_query(struct dvb_usb_device *d, u32 *event,
439                 int *state)
440 {
441         struct dvb_usb_rc_key *keymap = d->props.rc_key_map;
442         u8 ircode[2];
443         int i;
444
445         *event = 0;
446         *state = REMOTE_NO_KEY_PRESSED;
447
448         if (cxusb_ctrl_msg(d, 0x10, NULL, 0, ircode, 2) < 0)
449                 return 0;
450
451         for (i = 0; i < d->props.rc_key_map_size; i++) {
452                 if (rc5_custom(&keymap[i]) == ircode[0] &&
453                     rc5_data(&keymap[i]) == ircode[1]) {
454                         *event = keymap[i].event;
455                         *state = REMOTE_KEY_PRESSED;
456
457                         return 0;
458                 }
459         }
460
461         return 0;
462 }
463
464 static struct dvb_usb_rc_key dvico_mce_rc_keys[] = {
465         { 0xfe02, KEY_TV },
466         { 0xfe0e, KEY_MP3 },
467         { 0xfe1a, KEY_DVD },
468         { 0xfe1e, KEY_FAVORITES },
469         { 0xfe16, KEY_SETUP },
470         { 0xfe46, KEY_POWER2 },
471         { 0xfe0a, KEY_EPG },
472         { 0xfe49, KEY_BACK },
473         { 0xfe4d, KEY_MENU },
474         { 0xfe51, KEY_UP },
475         { 0xfe5b, KEY_LEFT },
476         { 0xfe5f, KEY_RIGHT },
477         { 0xfe53, KEY_DOWN },
478         { 0xfe5e, KEY_OK },
479         { 0xfe59, KEY_INFO },
480         { 0xfe55, KEY_TAB },
481         { 0xfe0f, KEY_PREVIOUSSONG },/* Replay */
482         { 0xfe12, KEY_NEXTSONG },       /* Skip */
483         { 0xfe42, KEY_ENTER      },     /* Windows/Start */
484         { 0xfe15, KEY_VOLUMEUP },
485         { 0xfe05, KEY_VOLUMEDOWN },
486         { 0xfe11, KEY_CHANNELUP },
487         { 0xfe09, KEY_CHANNELDOWN },
488         { 0xfe52, KEY_CAMERA },
489         { 0xfe5a, KEY_TUNER },  /* Live */
490         { 0xfe19, KEY_OPEN },
491         { 0xfe0b, KEY_1 },
492         { 0xfe17, KEY_2 },
493         { 0xfe1b, KEY_3 },
494         { 0xfe07, KEY_4 },
495         { 0xfe50, KEY_5 },
496         { 0xfe54, KEY_6 },
497         { 0xfe48, KEY_7 },
498         { 0xfe4c, KEY_8 },
499         { 0xfe58, KEY_9 },
500         { 0xfe13, KEY_ANGLE },  /* Aspect */
501         { 0xfe03, KEY_0 },
502         { 0xfe1f, KEY_ZOOM },
503         { 0xfe43, KEY_REWIND },
504         { 0xfe47, KEY_PLAYPAUSE },
505         { 0xfe4f, KEY_FASTFORWARD },
506         { 0xfe57, KEY_MUTE },
507         { 0xfe0d, KEY_STOP },
508         { 0xfe01, KEY_RECORD },
509         { 0xfe4e, KEY_POWER },
510 };
511
512 static struct dvb_usb_rc_key dvico_portable_rc_keys[] = {
513         { 0xfc02, KEY_SETUP },       /* Profile */
514         { 0xfc43, KEY_POWER2 },
515         { 0xfc06, KEY_EPG },
516         { 0xfc5a, KEY_BACK },
517         { 0xfc05, KEY_MENU },
518         { 0xfc47, KEY_INFO },
519         { 0xfc01, KEY_TAB },
520         { 0xfc42, KEY_PREVIOUSSONG },/* Replay */
521         { 0xfc49, KEY_VOLUMEUP },
522         { 0xfc09, KEY_VOLUMEDOWN },
523         { 0xfc54, KEY_CHANNELUP },
524         { 0xfc0b, KEY_CHANNELDOWN },
525         { 0xfc16, KEY_CAMERA },
526         { 0xfc40, KEY_TUNER },  /* ATV/DTV */
527         { 0xfc45, KEY_OPEN },
528         { 0xfc19, KEY_1 },
529         { 0xfc18, KEY_2 },
530         { 0xfc1b, KEY_3 },
531         { 0xfc1a, KEY_4 },
532         { 0xfc58, KEY_5 },
533         { 0xfc59, KEY_6 },
534         { 0xfc15, KEY_7 },
535         { 0xfc14, KEY_8 },
536         { 0xfc17, KEY_9 },
537         { 0xfc44, KEY_ANGLE },  /* Aspect */
538         { 0xfc55, KEY_0 },
539         { 0xfc07, KEY_ZOOM },
540         { 0xfc0a, KEY_REWIND },
541         { 0xfc08, KEY_PLAYPAUSE },
542         { 0xfc4b, KEY_FASTFORWARD },
543         { 0xfc5b, KEY_MUTE },
544         { 0xfc04, KEY_STOP },
545         { 0xfc56, KEY_RECORD },
546         { 0xfc57, KEY_POWER },
547         { 0xfc41, KEY_UNKNOWN },    /* INPUT */
548         { 0xfc00, KEY_UNKNOWN },    /* HD */
549 };
550
551 static struct dvb_usb_rc_key d680_dmb_rc_keys[] = {
552         { 0x0038, KEY_UNKNOWN },        /* TV/AV */
553         { 0x080c, KEY_ZOOM },
554         { 0x0800, KEY_0 },
555         { 0x0001, KEY_1 },
556         { 0x0802, KEY_2 },
557         { 0x0003, KEY_3 },
558         { 0x0804, KEY_4 },
559         { 0x0005, KEY_5 },
560         { 0x0806, KEY_6 },
561         { 0x0007, KEY_7 },
562         { 0x0808, KEY_8 },
563         { 0x0009, KEY_9 },
564         { 0x000a, KEY_MUTE },
565         { 0x0829, KEY_BACK },
566         { 0x0012, KEY_CHANNELUP },
567         { 0x0813, KEY_CHANNELDOWN },
568         { 0x002b, KEY_VOLUMEUP },
569         { 0x082c, KEY_VOLUMEDOWN },
570         { 0x0020, KEY_UP },
571         { 0x0821, KEY_DOWN },
572         { 0x0011, KEY_LEFT },
573         { 0x0810, KEY_RIGHT },
574         { 0x000d, KEY_OK },
575         { 0x081f, KEY_RECORD },
576         { 0x0017, KEY_PLAYPAUSE },
577         { 0x0816, KEY_PLAYPAUSE },
578         { 0x000b, KEY_STOP },
579         { 0x0827, KEY_FASTFORWARD },
580         { 0x0026, KEY_REWIND },
581         { 0x081e, KEY_UNKNOWN },    /* Time Shift */
582         { 0x000e, KEY_UNKNOWN },    /* Snapshot */
583         { 0x082d, KEY_UNKNOWN },    /* Mouse Cursor */
584         { 0x000f, KEY_UNKNOWN },    /* Minimize/Maximize */
585         { 0x0814, KEY_UNKNOWN },    /* Shuffle */
586         { 0x0025, KEY_POWER },
587 };
588
589 static int cxusb_dee1601_demod_init(struct dvb_frontend* fe)
590 {
591         static u8 clock_config []  = { CLOCK_CTL,  0x38, 0x28 };
592         static u8 reset []         = { RESET,      0x80 };
593         static u8 adc_ctl_1_cfg [] = { ADC_CTL_1,  0x40 };
594         static u8 agc_cfg []       = { AGC_TARGET, 0x28, 0x20 };
595         static u8 gpp_ctl_cfg []   = { GPP_CTL,    0x33 };
596         static u8 capt_range_cfg[] = { CAPT_RANGE, 0x32 };
597
598         mt352_write(fe, clock_config,   sizeof(clock_config));
599         udelay(200);
600         mt352_write(fe, reset,          sizeof(reset));
601         mt352_write(fe, adc_ctl_1_cfg,  sizeof(adc_ctl_1_cfg));
602
603         mt352_write(fe, agc_cfg,        sizeof(agc_cfg));
604         mt352_write(fe, gpp_ctl_cfg,    sizeof(gpp_ctl_cfg));
605         mt352_write(fe, capt_range_cfg, sizeof(capt_range_cfg));
606
607         return 0;
608 }
609
610 static int cxusb_mt352_demod_init(struct dvb_frontend* fe)
611 {       /* used in both lgz201 and th7579 */
612         static u8 clock_config []  = { CLOCK_CTL,  0x38, 0x29 };
613         static u8 reset []         = { RESET,      0x80 };
614         static u8 adc_ctl_1_cfg [] = { ADC_CTL_1,  0x40 };
615         static u8 agc_cfg []       = { AGC_TARGET, 0x24, 0x20 };
616         static u8 gpp_ctl_cfg []   = { GPP_CTL,    0x33 };
617         static u8 capt_range_cfg[] = { CAPT_RANGE, 0x32 };
618
619         mt352_write(fe, clock_config,   sizeof(clock_config));
620         udelay(200);
621         mt352_write(fe, reset,          sizeof(reset));
622         mt352_write(fe, adc_ctl_1_cfg,  sizeof(adc_ctl_1_cfg));
623
624         mt352_write(fe, agc_cfg,        sizeof(agc_cfg));
625         mt352_write(fe, gpp_ctl_cfg,    sizeof(gpp_ctl_cfg));
626         mt352_write(fe, capt_range_cfg, sizeof(capt_range_cfg));
627         return 0;
628 }
629
630 static struct cx22702_config cxusb_cx22702_config = {
631         .demod_address = 0x63,
632         .output_mode = CX22702_PARALLEL_OUTPUT,
633 };
634
635 static struct lgdt330x_config cxusb_lgdt3303_config = {
636         .demod_address = 0x0e,
637         .demod_chip    = LGDT3303,
638 };
639
640 static struct lgdt330x_config cxusb_aver_lgdt3303_config = {
641         .demod_address       = 0x0e,
642         .demod_chip          = LGDT3303,
643         .clock_polarity_flip = 2,
644 };
645
646 static struct mt352_config cxusb_dee1601_config = {
647         .demod_address = 0x0f,
648         .demod_init    = cxusb_dee1601_demod_init,
649 };
650
651 static struct zl10353_config cxusb_zl10353_dee1601_config = {
652         .demod_address = 0x0f,
653         .parallel_ts = 1,
654 };
655
656 static struct mt352_config cxusb_mt352_config = {
657         /* used in both lgz201 and th7579 */
658         .demod_address = 0x0f,
659         .demod_init    = cxusb_mt352_demod_init,
660 };
661
662 static struct zl10353_config cxusb_zl10353_xc3028_config = {
663         .demod_address = 0x0f,
664         .if2 = 45600,
665         .no_tuner = 1,
666         .parallel_ts = 1,
667 };
668
669 static struct zl10353_config cxusb_zl10353_xc3028_config_no_i2c_gate = {
670         .demod_address = 0x0f,
671         .if2 = 45600,
672         .no_tuner = 1,
673         .parallel_ts = 1,
674         .disable_i2c_gate_ctrl = 1,
675 };
676
677 static struct mt352_config cxusb_mt352_xc3028_config = {
678         .demod_address = 0x0f,
679         .if2 = 4560,
680         .no_tuner = 1,
681         .demod_init = cxusb_mt352_demod_init,
682 };
683
684 /* FIXME: needs tweaking */
685 static struct mxl5005s_config aver_a868r_tuner = {
686         .i2c_address     = 0x63,
687         .if_freq         = 6000000UL,
688         .xtal_freq       = CRYSTAL_FREQ_16000000HZ,
689         .agc_mode        = MXL_SINGLE_AGC,
690         .tracking_filter = MXL_TF_C,
691         .rssi_enable     = MXL_RSSI_ENABLE,
692         .cap_select      = MXL_CAP_SEL_ENABLE,
693         .div_out         = MXL_DIV_OUT_4,
694         .clock_out       = MXL_CLOCK_OUT_DISABLE,
695         .output_load     = MXL5005S_IF_OUTPUT_LOAD_200_OHM,
696         .top             = MXL5005S_TOP_25P2,
697         .mod_mode        = MXL_DIGITAL_MODE,
698         .if_mode         = MXL_ZERO_IF,
699         .AgcMasterByte   = 0x00,
700 };
701
702 /* FIXME: needs tweaking */
703 static struct mxl5005s_config d680_dmb_tuner = {
704         .i2c_address     = 0x63,
705         .if_freq         = 36125000UL,
706         .xtal_freq       = CRYSTAL_FREQ_16000000HZ,
707         .agc_mode        = MXL_SINGLE_AGC,
708         .tracking_filter = MXL_TF_C,
709         .rssi_enable     = MXL_RSSI_ENABLE,
710         .cap_select      = MXL_CAP_SEL_ENABLE,
711         .div_out         = MXL_DIV_OUT_4,
712         .clock_out       = MXL_CLOCK_OUT_DISABLE,
713         .output_load     = MXL5005S_IF_OUTPUT_LOAD_200_OHM,
714         .top             = MXL5005S_TOP_25P2,
715         .mod_mode        = MXL_DIGITAL_MODE,
716         .if_mode         = MXL_ZERO_IF,
717         .AgcMasterByte   = 0x00,
718 };
719
720 static struct max2165_config mygica_d689_max2165_cfg = {
721         .i2c_address = 0x60,
722         .osc_clk = 20
723 };
724
725 /* Callbacks for DVB USB */
726 static int cxusb_fmd1216me_tuner_attach(struct dvb_usb_adapter *adap)
727 {
728         dvb_attach(simple_tuner_attach, adap->fe,
729                    &adap->dev->i2c_adap, 0x61,
730                    TUNER_PHILIPS_FMD1216ME_MK3);
731         return 0;
732 }
733
734 static int cxusb_dee1601_tuner_attach(struct dvb_usb_adapter *adap)
735 {
736         dvb_attach(dvb_pll_attach, adap->fe, 0x61,
737                    NULL, DVB_PLL_THOMSON_DTT7579);
738         return 0;
739 }
740
741 static int cxusb_lgz201_tuner_attach(struct dvb_usb_adapter *adap)
742 {
743         dvb_attach(dvb_pll_attach, adap->fe, 0x61, NULL, DVB_PLL_LG_Z201);
744         return 0;
745 }
746
747 static int cxusb_dtt7579_tuner_attach(struct dvb_usb_adapter *adap)
748 {
749         dvb_attach(dvb_pll_attach, adap->fe, 0x60,
750                    NULL, DVB_PLL_THOMSON_DTT7579);
751         return 0;
752 }
753
754 static int cxusb_lgh064f_tuner_attach(struct dvb_usb_adapter *adap)
755 {
756         dvb_attach(simple_tuner_attach, adap->fe,
757                    &adap->dev->i2c_adap, 0x61, TUNER_LG_TDVS_H06XF);
758         return 0;
759 }
760
761 static int dvico_bluebird_xc2028_callback(void *ptr, int component,
762                                           int command, int arg)
763 {
764         struct dvb_usb_adapter *adap = ptr;
765         struct dvb_usb_device *d = adap->dev;
766
767         switch (command) {
768         case XC2028_TUNER_RESET:
769                 deb_info("%s: XC2028_TUNER_RESET %d\n", __func__, arg);
770                 cxusb_bluebird_gpio_pulse(d, 0x01, 1);
771                 break;
772         case XC2028_RESET_CLK:
773                 deb_info("%s: XC2028_RESET_CLK %d\n", __func__, arg);
774                 break;
775         default:
776                 deb_info("%s: unknown command %d, arg %d\n", __func__,
777                          command, arg);
778                 return -EINVAL;
779         }
780
781         return 0;
782 }
783
784 static int cxusb_dvico_xc3028_tuner_attach(struct dvb_usb_adapter *adap)
785 {
786         struct dvb_frontend      *fe;
787         struct xc2028_config      cfg = {
788                 .i2c_adap  = &adap->dev->i2c_adap,
789                 .i2c_addr  = 0x61,
790         };
791         static struct xc2028_ctrl ctl = {
792                 .fname       = XC2028_DEFAULT_FIRMWARE,
793                 .max_len     = 64,
794                 .demod       = XC3028_FE_ZARLINK456,
795         };
796
797         /* FIXME: generalize & move to common area */
798         adap->fe->callback = dvico_bluebird_xc2028_callback;
799
800         fe = dvb_attach(xc2028_attach, adap->fe, &cfg);
801         if (fe == NULL || fe->ops.tuner_ops.set_config == NULL)
802                 return -EIO;
803
804         fe->ops.tuner_ops.set_config(fe, &ctl);
805
806         return 0;
807 }
808
809 static int cxusb_mxl5003s_tuner_attach(struct dvb_usb_adapter *adap)
810 {
811         dvb_attach(mxl5005s_attach, adap->fe,
812                    &adap->dev->i2c_adap, &aver_a868r_tuner);
813         return 0;
814 }
815
816 static int cxusb_d680_dmb_tuner_attach(struct dvb_usb_adapter *adap)
817 {
818         struct dvb_frontend *fe;
819         fe = dvb_attach(mxl5005s_attach, adap->fe,
820                         &adap->dev->i2c_adap, &d680_dmb_tuner);
821         return (fe == NULL) ? -EIO : 0;
822 }
823
824 static int cxusb_mygica_d689_tuner_attach(struct dvb_usb_adapter *adap)
825 {
826         struct dvb_frontend *fe;
827         fe = dvb_attach(max2165_attach, adap->fe,
828                         &adap->dev->i2c_adap, &mygica_d689_max2165_cfg);
829         return (fe == NULL) ? -EIO : 0;
830 }
831
832 static int cxusb_cx22702_frontend_attach(struct dvb_usb_adapter *adap)
833 {
834         u8 b;
835         if (usb_set_interface(adap->dev->udev, 0, 6) < 0)
836                 err("set interface failed");
837
838         cxusb_ctrl_msg(adap->dev, CMD_DIGITAL, NULL, 0, &b, 1);
839
840         if ((adap->fe = dvb_attach(cx22702_attach, &cxusb_cx22702_config,
841                                    &adap->dev->i2c_adap)) != NULL)
842                 return 0;
843
844         return -EIO;
845 }
846
847 static int cxusb_lgdt3303_frontend_attach(struct dvb_usb_adapter *adap)
848 {
849         if (usb_set_interface(adap->dev->udev, 0, 7) < 0)
850                 err("set interface failed");
851
852         cxusb_ctrl_msg(adap->dev, CMD_DIGITAL, NULL, 0, NULL, 0);
853
854         if ((adap->fe = dvb_attach(lgdt330x_attach, &cxusb_lgdt3303_config,
855                                    &adap->dev->i2c_adap)) != NULL)
856                 return 0;
857
858         return -EIO;
859 }
860
861 static int cxusb_aver_lgdt3303_frontend_attach(struct dvb_usb_adapter *adap)
862 {
863         adap->fe = dvb_attach(lgdt330x_attach, &cxusb_aver_lgdt3303_config,
864                               &adap->dev->i2c_adap);
865         if (adap->fe != NULL)
866                 return 0;
867
868         return -EIO;
869 }
870
871 static int cxusb_mt352_frontend_attach(struct dvb_usb_adapter *adap)
872 {
873         /* used in both lgz201 and th7579 */
874         if (usb_set_interface(adap->dev->udev, 0, 0) < 0)
875                 err("set interface failed");
876
877         cxusb_ctrl_msg(adap->dev, CMD_DIGITAL, NULL, 0, NULL, 0);
878
879         if ((adap->fe = dvb_attach(mt352_attach, &cxusb_mt352_config,
880                                    &adap->dev->i2c_adap)) != NULL)
881                 return 0;
882
883         return -EIO;
884 }
885
886 static int cxusb_dee1601_frontend_attach(struct dvb_usb_adapter *adap)
887 {
888         if (usb_set_interface(adap->dev->udev, 0, 0) < 0)
889                 err("set interface failed");
890
891         cxusb_ctrl_msg(adap->dev, CMD_DIGITAL, NULL, 0, NULL, 0);
892
893         if (((adap->fe = dvb_attach(mt352_attach, &cxusb_dee1601_config,
894                                     &adap->dev->i2c_adap)) != NULL) ||
895                 ((adap->fe = dvb_attach(zl10353_attach,
896                                         &cxusb_zl10353_dee1601_config,
897                                         &adap->dev->i2c_adap)) != NULL))
898                 return 0;
899
900         return -EIO;
901 }
902
903 static int cxusb_dualdig4_frontend_attach(struct dvb_usb_adapter *adap)
904 {
905         u8 ircode[4];
906         int i;
907         struct i2c_msg msg = { .addr = 0x6b, .flags = I2C_M_RD,
908                                .buf = ircode, .len = 4 };
909
910         if (usb_set_interface(adap->dev->udev, 0, 1) < 0)
911                 err("set interface failed");
912
913         cxusb_ctrl_msg(adap->dev, CMD_DIGITAL, NULL, 0, NULL, 0);
914
915         /* reset the tuner and demodulator */
916         cxusb_bluebird_gpio_rw(adap->dev, 0x04, 0);
917         cxusb_bluebird_gpio_pulse(adap->dev, 0x01, 1);
918         cxusb_bluebird_gpio_pulse(adap->dev, 0x02, 1);
919
920         if ((adap->fe = dvb_attach(zl10353_attach,
921                                    &cxusb_zl10353_xc3028_config_no_i2c_gate,
922                                    &adap->dev->i2c_adap)) == NULL)
923                 return -EIO;
924
925         /* try to determine if there is no IR decoder on the I2C bus */
926         for (i = 0; adap->dev->props.rc_key_map != NULL && i < 5; i++) {
927                 msleep(20);
928                 if (cxusb_i2c_xfer(&adap->dev->i2c_adap, &msg, 1) != 1)
929                         goto no_IR;
930                 if (ircode[0] == 0 && ircode[1] == 0)
931                         continue;
932                 if (ircode[2] + ircode[3] != 0xff) {
933 no_IR:
934                         adap->dev->props.rc_key_map = NULL;
935                         info("No IR receiver detected on this device.");
936                         break;
937                 }
938         }
939
940         return 0;
941 }
942
943 static struct dibx000_agc_config dib7070_agc_config = {
944         .band_caps = BAND_UHF | BAND_VHF | BAND_LBAND | BAND_SBAND,
945
946         /*
947          * P_agc_use_sd_mod1=0, P_agc_use_sd_mod2=0, P_agc_freq_pwm_div=5,
948          * P_agc_inv_pwm1=0, P_agc_inv_pwm2=0, P_agc_inh_dc_rv_est=0,
949          * P_agc_time_est=3, P_agc_freeze=0, P_agc_nb_est=5, P_agc_write=0
950          */
951         .setup = (0 << 15) | (0 << 14) | (5 << 11) | (0 << 10) | (0 << 9) |
952                  (0 << 8) | (3 << 5) | (0 << 4) | (5 << 1) | (0 << 0),
953         .inv_gain = 600,
954         .time_stabiliz = 10,
955         .alpha_level = 0,
956         .thlock = 118,
957         .wbd_inv = 0,
958         .wbd_ref = 3530,
959         .wbd_sel = 1,
960         .wbd_alpha = 5,
961         .agc1_max = 65535,
962         .agc1_min = 0,
963         .agc2_max = 65535,
964         .agc2_min = 0,
965         .agc1_pt1 = 0,
966         .agc1_pt2 = 40,
967         .agc1_pt3 = 183,
968         .agc1_slope1 = 206,
969         .agc1_slope2 = 255,
970         .agc2_pt1 = 72,
971         .agc2_pt2 = 152,
972         .agc2_slope1 = 88,
973         .agc2_slope2 = 90,
974         .alpha_mant = 17,
975         .alpha_exp = 27,
976         .beta_mant = 23,
977         .beta_exp = 51,
978         .perform_agc_softsplit = 0,
979 };
980
981 static struct dibx000_bandwidth_config dib7070_bw_config_12_mhz = {
982         .internal = 60000,
983         .sampling = 15000,
984         .pll_prediv = 1,
985         .pll_ratio = 20,
986         .pll_range = 3,
987         .pll_reset = 1,
988         .pll_bypass = 0,
989         .enable_refdiv = 0,
990         .bypclk_div = 0,
991         .IO_CLK_en_core = 1,
992         .ADClkSrc = 1,
993         .modulo = 2,
994         /* refsel, sel, freq_15k */
995         .sad_cfg = (3 << 14) | (1 << 12) | (524 << 0),
996         .ifreq = (0 << 25) | 0,
997         .timf = 20452225,
998         .xtal_hz = 12000000,
999 };
1000
1001 static struct dib7000p_config cxusb_dualdig4_rev2_config = {
1002         .output_mode = OUTMODE_MPEG2_PAR_GATED_CLK,
1003         .output_mpeg2_in_188_bytes = 1,
1004
1005         .agc_config_count = 1,
1006         .agc = &dib7070_agc_config,
1007         .bw  = &dib7070_bw_config_12_mhz,
1008         .tuner_is_baseband = 1,
1009         .spur_protect = 1,
1010
1011         .gpio_dir = 0xfcef,
1012         .gpio_val = 0x0110,
1013
1014         .gpio_pwm_pos = DIB7000P_GPIO_DEFAULT_PWM_POS,
1015
1016         .hostbus_diversity = 1,
1017 };
1018
1019 static int cxusb_dualdig4_rev2_frontend_attach(struct dvb_usb_adapter *adap)
1020 {
1021         if (usb_set_interface(adap->dev->udev, 0, 1) < 0)
1022                 err("set interface failed");
1023
1024         cxusb_ctrl_msg(adap->dev, CMD_DIGITAL, NULL, 0, NULL, 0);
1025
1026         cxusb_bluebird_gpio_pulse(adap->dev, 0x02, 1);
1027
1028         dib7000p_i2c_enumeration(&adap->dev->i2c_adap, 1, 18,
1029                                  &cxusb_dualdig4_rev2_config);
1030
1031         adap->fe = dvb_attach(dib7000p_attach, &adap->dev->i2c_adap, 0x80,
1032                               &cxusb_dualdig4_rev2_config);
1033         if (adap->fe == NULL)
1034                 return -EIO;
1035
1036         return 0;
1037 }
1038
1039 static int dib7070_tuner_reset(struct dvb_frontend *fe, int onoff)
1040 {
1041         return dib7000p_set_gpio(fe, 8, 0, !onoff);
1042 }
1043
1044 static int dib7070_tuner_sleep(struct dvb_frontend *fe, int onoff)
1045 {
1046         return 0;
1047 }
1048
1049 static struct dib0070_config dib7070p_dib0070_config = {
1050         .i2c_address = DEFAULT_DIB0070_I2C_ADDRESS,
1051         .reset = dib7070_tuner_reset,
1052         .sleep = dib7070_tuner_sleep,
1053         .clock_khz = 12000,
1054 };
1055
1056 struct dib0700_adapter_state {
1057         int (*set_param_save) (struct dvb_frontend *,
1058                                struct dvb_frontend_parameters *);
1059 };
1060
1061 static int dib7070_set_param_override(struct dvb_frontend *fe,
1062                                       struct dvb_frontend_parameters *fep)
1063 {
1064         struct dvb_usb_adapter *adap = fe->dvb->priv;
1065         struct dib0700_adapter_state *state = adap->priv;
1066
1067         u16 offset;
1068         u8 band = BAND_OF_FREQUENCY(fep->frequency/1000);
1069         switch (band) {
1070         case BAND_VHF: offset = 950; break;
1071         default:
1072         case BAND_UHF: offset = 550; break;
1073         }
1074
1075         dib7000p_set_wbd_ref(fe, offset + dib0070_wbd_offset(fe));
1076
1077         return state->set_param_save(fe, fep);
1078 }
1079
1080 static int cxusb_dualdig4_rev2_tuner_attach(struct dvb_usb_adapter *adap)
1081 {
1082         struct dib0700_adapter_state *st = adap->priv;
1083         struct i2c_adapter *tun_i2c =
1084                 dib7000p_get_i2c_master(adap->fe,
1085                                         DIBX000_I2C_INTERFACE_TUNER, 1);
1086
1087         if (dvb_attach(dib0070_attach, adap->fe, tun_i2c,
1088             &dib7070p_dib0070_config) == NULL)
1089                 return -ENODEV;
1090
1091         st->set_param_save = adap->fe->ops.tuner_ops.set_params;
1092         adap->fe->ops.tuner_ops.set_params = dib7070_set_param_override;
1093         return 0;
1094 }
1095
1096 static int cxusb_nano2_frontend_attach(struct dvb_usb_adapter *adap)
1097 {
1098         if (usb_set_interface(adap->dev->udev, 0, 1) < 0)
1099                 err("set interface failed");
1100
1101         cxusb_ctrl_msg(adap->dev, CMD_DIGITAL, NULL, 0, NULL, 0);
1102
1103         /* reset the tuner and demodulator */
1104         cxusb_bluebird_gpio_rw(adap->dev, 0x04, 0);
1105         cxusb_bluebird_gpio_pulse(adap->dev, 0x01, 1);
1106         cxusb_bluebird_gpio_pulse(adap->dev, 0x02, 1);
1107
1108         if ((adap->fe = dvb_attach(zl10353_attach,
1109                                    &cxusb_zl10353_xc3028_config,
1110                                    &adap->dev->i2c_adap)) != NULL)
1111                 return 0;
1112
1113         if ((adap->fe = dvb_attach(mt352_attach,
1114                                    &cxusb_mt352_xc3028_config,
1115                                    &adap->dev->i2c_adap)) != NULL)
1116                 return 0;
1117
1118         return -EIO;
1119 }
1120
1121 static struct lgs8gxx_config d680_lgs8gl5_cfg = {
1122         .prod = LGS8GXX_PROD_LGS8GL5,
1123         .demod_address = 0x19,
1124         .serial_ts = 0,
1125         .ts_clk_pol = 0,
1126         .ts_clk_gated = 1,
1127         .if_clk_freq = 30400, /* 30.4 MHz */
1128         .if_freq = 5725, /* 5.725 MHz */
1129         .if_neg_center = 0,
1130         .ext_adc = 0,
1131         .adc_signed = 0,
1132         .if_neg_edge = 0,
1133 };
1134
1135 static int cxusb_d680_dmb_frontend_attach(struct dvb_usb_adapter *adap)
1136 {
1137         struct dvb_usb_device *d = adap->dev;
1138         int n;
1139
1140         /* Select required USB configuration */
1141         if (usb_set_interface(d->udev, 0, 0) < 0)
1142                 err("set interface failed");
1143
1144         /* Unblock all USB pipes */
1145         usb_clear_halt(d->udev,
1146                 usb_sndbulkpipe(d->udev, d->props.generic_bulk_ctrl_endpoint));
1147         usb_clear_halt(d->udev,
1148                 usb_rcvbulkpipe(d->udev, d->props.generic_bulk_ctrl_endpoint));
1149         usb_clear_halt(d->udev,
1150                 usb_rcvbulkpipe(d->udev, d->props.adapter[0].stream.endpoint));
1151
1152         /* Drain USB pipes to avoid hang after reboot */
1153         for (n = 0;  n < 5;  n++) {
1154                 cxusb_d680_dmb_drain_message(d);
1155                 cxusb_d680_dmb_drain_video(d);
1156                 msleep(200);
1157         }
1158
1159         /* Reset the tuner */
1160         if (cxusb_d680_dmb_gpio_tuner(d, 0x07, 0) < 0) {
1161                 err("clear tuner gpio failed");
1162                 return -EIO;
1163         }
1164         msleep(100);
1165         if (cxusb_d680_dmb_gpio_tuner(d, 0x07, 1) < 0) {
1166                 err("set tuner gpio failed");
1167                 return -EIO;
1168         }
1169         msleep(100);
1170
1171         /* Attach frontend */
1172         adap->fe = dvb_attach(lgs8gxx_attach, &d680_lgs8gl5_cfg, &d->i2c_adap);
1173         if (adap->fe == NULL)
1174                 return -EIO;
1175
1176         return 0;
1177 }
1178
1179 static struct atbm8830_config mygica_d689_atbm8830_cfg = {
1180         .prod = ATBM8830_PROD_8830,
1181         .demod_address = 0x40,
1182         .serial_ts = 0,
1183         .ts_sampling_edge = 1,
1184         .ts_clk_gated = 0,
1185         .osc_clk_freq = 30400, /* in kHz */
1186         .if_freq = 0, /* zero IF */
1187         .zif_swap_iq = 1,
1188         .agc_min = 0x2E,
1189         .agc_max = 0x90,
1190         .agc_hold_loop = 0,
1191 };
1192
1193 static int cxusb_mygica_d689_frontend_attach(struct dvb_usb_adapter *adap)
1194 {
1195         struct dvb_usb_device *d = adap->dev;
1196
1197         /* Select required USB configuration */
1198         if (usb_set_interface(d->udev, 0, 0) < 0)
1199                 err("set interface failed");
1200
1201         /* Unblock all USB pipes */
1202         usb_clear_halt(d->udev,
1203                 usb_sndbulkpipe(d->udev, d->props.generic_bulk_ctrl_endpoint));
1204         usb_clear_halt(d->udev,
1205                 usb_rcvbulkpipe(d->udev, d->props.generic_bulk_ctrl_endpoint));
1206         usb_clear_halt(d->udev,
1207                 usb_rcvbulkpipe(d->udev, d->props.adapter[0].stream.endpoint));
1208
1209
1210         /* Reset the tuner */
1211         if (cxusb_d680_dmb_gpio_tuner(d, 0x07, 0) < 0) {
1212                 err("clear tuner gpio failed");
1213                 return -EIO;
1214         }
1215         msleep(100);
1216         if (cxusb_d680_dmb_gpio_tuner(d, 0x07, 1) < 0) {
1217                 err("set tuner gpio failed");
1218                 return -EIO;
1219         }
1220         msleep(100);
1221
1222         /* Attach frontend */
1223         adap->fe = dvb_attach(atbm8830_attach, &mygica_d689_atbm8830_cfg,
1224                 &d->i2c_adap);
1225         if (adap->fe == NULL)
1226                 return -EIO;
1227
1228         return 0;
1229 }
1230
1231 /*
1232  * DViCO has shipped two devices with the same USB ID, but only one of them
1233  * needs a firmware download.  Check the device class details to see if they
1234  * have non-default values to decide whether the device is actually cold or
1235  * not, and forget a match if it turns out we selected the wrong device.
1236  */
1237 static int bluebird_fx2_identify_state(struct usb_device *udev,
1238                                        struct dvb_usb_device_properties *props,
1239                                        struct dvb_usb_device_description **desc,
1240                                        int *cold)
1241 {
1242         int wascold = *cold;
1243
1244         *cold = udev->descriptor.bDeviceClass == 0xff &&
1245                 udev->descriptor.bDeviceSubClass == 0xff &&
1246                 udev->descriptor.bDeviceProtocol == 0xff;
1247
1248         if (*cold && !wascold)
1249                 *desc = NULL;
1250
1251         return 0;
1252 }
1253
1254 /*
1255  * DViCO bluebird firmware needs the "warm" product ID to be patched into the
1256  * firmware file before download.
1257  */
1258
1259 static const int dvico_firmware_id_offsets[] = { 6638, 3204 };
1260 static int bluebird_patch_dvico_firmware_download(struct usb_device *udev,
1261                                                   const struct firmware *fw)
1262 {
1263         int pos;
1264
1265         for (pos = 0; pos < ARRAY_SIZE(dvico_firmware_id_offsets); pos++) {
1266                 int idoff = dvico_firmware_id_offsets[pos];
1267
1268                 if (fw->size < idoff + 4)
1269                         continue;
1270
1271                 if (fw->data[idoff] == (USB_VID_DVICO & 0xff) &&
1272                     fw->data[idoff + 1] == USB_VID_DVICO >> 8) {
1273                         struct firmware new_fw;
1274                         u8 *new_fw_data = vmalloc(fw->size);
1275                         int ret;
1276
1277                         if (!new_fw_data)
1278                                 return -ENOMEM;
1279
1280                         memcpy(new_fw_data, fw->data, fw->size);
1281                         new_fw.size = fw->size;
1282                         new_fw.data = new_fw_data;
1283
1284                         new_fw_data[idoff + 2] =
1285                                 le16_to_cpu(udev->descriptor.idProduct) + 1;
1286                         new_fw_data[idoff + 3] =
1287                                 le16_to_cpu(udev->descriptor.idProduct) >> 8;
1288
1289                         ret = usb_cypress_load_firmware(udev, &new_fw,
1290                                                         CYPRESS_FX2);
1291                         vfree(new_fw_data);
1292                         return ret;
1293                 }
1294         }
1295
1296         return -EINVAL;
1297 }
1298
1299 /* DVB USB Driver stuff */
1300 static struct dvb_usb_device_properties cxusb_medion_properties;
1301 static struct dvb_usb_device_properties cxusb_bluebird_lgh064f_properties;
1302 static struct dvb_usb_device_properties cxusb_bluebird_dee1601_properties;
1303 static struct dvb_usb_device_properties cxusb_bluebird_lgz201_properties;
1304 static struct dvb_usb_device_properties cxusb_bluebird_dtt7579_properties;
1305 static struct dvb_usb_device_properties cxusb_bluebird_dualdig4_properties;
1306 static struct dvb_usb_device_properties cxusb_bluebird_dualdig4_rev2_properties;
1307 static struct dvb_usb_device_properties cxusb_bluebird_nano2_properties;
1308 static struct dvb_usb_device_properties cxusb_bluebird_nano2_needsfirmware_properties;
1309 static struct dvb_usb_device_properties cxusb_aver_a868r_properties;
1310 static struct dvb_usb_device_properties cxusb_d680_dmb_properties;
1311 static struct dvb_usb_device_properties cxusb_mygica_d689_properties;
1312
1313 static int cxusb_probe(struct usb_interface *intf,
1314                        const struct usb_device_id *id)
1315 {
1316         if (0 == dvb_usb_device_init(intf, &cxusb_medion_properties,
1317                                      THIS_MODULE, NULL, adapter_nr) ||
1318             0 == dvb_usb_device_init(intf, &cxusb_bluebird_lgh064f_properties,
1319                                      THIS_MODULE, NULL, adapter_nr) ||
1320             0 == dvb_usb_device_init(intf, &cxusb_bluebird_dee1601_properties,
1321                                      THIS_MODULE, NULL, adapter_nr) ||
1322             0 == dvb_usb_device_init(intf, &cxusb_bluebird_lgz201_properties,
1323                                      THIS_MODULE, NULL, adapter_nr) ||
1324             0 == dvb_usb_device_init(intf, &cxusb_bluebird_dtt7579_properties,
1325                                      THIS_MODULE, NULL, adapter_nr) ||
1326             0 == dvb_usb_device_init(intf, &cxusb_bluebird_dualdig4_properties,
1327                                      THIS_MODULE, NULL, adapter_nr) ||
1328             0 == dvb_usb_device_init(intf, &cxusb_bluebird_nano2_properties,
1329                                      THIS_MODULE, NULL, adapter_nr) ||
1330             0 == dvb_usb_device_init(intf,
1331                                 &cxusb_bluebird_nano2_needsfirmware_properties,
1332                                      THIS_MODULE, NULL, adapter_nr) ||
1333             0 == dvb_usb_device_init(intf, &cxusb_aver_a868r_properties,
1334                                      THIS_MODULE, NULL, adapter_nr) ||
1335             0 == dvb_usb_device_init(intf,
1336                                      &cxusb_bluebird_dualdig4_rev2_properties,
1337                                      THIS_MODULE, NULL, adapter_nr) ||
1338             0 == dvb_usb_device_init(intf, &cxusb_d680_dmb_properties,
1339                                      THIS_MODULE, NULL, adapter_nr) ||
1340             0 == dvb_usb_device_init(intf, &cxusb_mygica_d689_properties,
1341                                      THIS_MODULE, NULL, adapter_nr) ||
1342             0)
1343                 return 0;
1344
1345         return -EINVAL;
1346 }
1347
1348 static struct usb_device_id cxusb_table [] = {
1349         { USB_DEVICE(USB_VID_MEDION, USB_PID_MEDION_MD95700) },
1350         { USB_DEVICE(USB_VID_DVICO, USB_PID_DVICO_BLUEBIRD_LG064F_COLD) },
1351         { USB_DEVICE(USB_VID_DVICO, USB_PID_DVICO_BLUEBIRD_LG064F_WARM) },
1352         { USB_DEVICE(USB_VID_DVICO, USB_PID_DVICO_BLUEBIRD_DUAL_1_COLD) },
1353         { USB_DEVICE(USB_VID_DVICO, USB_PID_DVICO_BLUEBIRD_DUAL_1_WARM) },
1354         { USB_DEVICE(USB_VID_DVICO, USB_PID_DVICO_BLUEBIRD_LGZ201_COLD) },
1355         { USB_DEVICE(USB_VID_DVICO, USB_PID_DVICO_BLUEBIRD_LGZ201_WARM) },
1356         { USB_DEVICE(USB_VID_DVICO, USB_PID_DVICO_BLUEBIRD_TH7579_COLD) },
1357         { USB_DEVICE(USB_VID_DVICO, USB_PID_DVICO_BLUEBIRD_TH7579_WARM) },
1358         { USB_DEVICE(USB_VID_DVICO, USB_PID_DIGITALNOW_BLUEBIRD_DUAL_1_COLD) },
1359         { USB_DEVICE(USB_VID_DVICO, USB_PID_DIGITALNOW_BLUEBIRD_DUAL_1_WARM) },
1360         { USB_DEVICE(USB_VID_DVICO, USB_PID_DVICO_BLUEBIRD_DUAL_2_COLD) },
1361         { USB_DEVICE(USB_VID_DVICO, USB_PID_DVICO_BLUEBIRD_DUAL_2_WARM) },
1362         { USB_DEVICE(USB_VID_DVICO, USB_PID_DVICO_BLUEBIRD_DUAL_4) },
1363         { USB_DEVICE(USB_VID_DVICO, USB_PID_DVICO_BLUEBIRD_DVB_T_NANO_2) },
1364         { USB_DEVICE(USB_VID_DVICO, USB_PID_DVICO_BLUEBIRD_DVB_T_NANO_2_NFW_WARM) },
1365         { USB_DEVICE(USB_VID_AVERMEDIA, USB_PID_AVERMEDIA_VOLAR_A868R) },
1366         { USB_DEVICE(USB_VID_DVICO, USB_PID_DVICO_BLUEBIRD_DUAL_4_REV_2) },
1367         { USB_DEVICE(USB_VID_CONEXANT, USB_PID_CONEXANT_D680_DMB) },
1368         { USB_DEVICE(USB_VID_CONEXANT, USB_PID_MYGICA_D689) },
1369         {}              /* Terminating entry */
1370 };
1371 MODULE_DEVICE_TABLE (usb, cxusb_table);
1372
1373 static struct dvb_usb_device_properties cxusb_medion_properties = {
1374         .caps = DVB_USB_IS_AN_I2C_ADAPTER,
1375
1376         .usb_ctrl = CYPRESS_FX2,
1377
1378         .size_of_priv     = sizeof(struct cxusb_state),
1379
1380         .num_adapters = 1,
1381         .adapter = {
1382                 {
1383                         .streaming_ctrl   = cxusb_streaming_ctrl,
1384                         .frontend_attach  = cxusb_cx22702_frontend_attach,
1385                         .tuner_attach     = cxusb_fmd1216me_tuner_attach,
1386                         /* parameter for the MPEG2-data transfer */
1387                                         .stream = {
1388                                                 .type = USB_BULK,
1389                                 .count = 5,
1390                                 .endpoint = 0x02,
1391                                 .u = {
1392                                         .bulk = {
1393                                                 .buffersize = 8192,
1394                                         }
1395                                 }
1396                         },
1397
1398                 },
1399         },
1400         .power_ctrl       = cxusb_power_ctrl,
1401
1402         .i2c_algo         = &cxusb_i2c_algo,
1403
1404         .generic_bulk_ctrl_endpoint = 0x01,
1405
1406         .num_device_descs = 1,
1407         .devices = {
1408                 {   "Medion MD95700 (MDUSBTV-HYBRID)",
1409                         { NULL },
1410                         { &cxusb_table[0], NULL },
1411                 },
1412         }
1413 };
1414
1415 static struct dvb_usb_device_properties cxusb_bluebird_lgh064f_properties = {
1416         .caps = DVB_USB_IS_AN_I2C_ADAPTER,
1417
1418         .usb_ctrl          = DEVICE_SPECIFIC,
1419         .firmware          = "dvb-usb-bluebird-01.fw",
1420         .download_firmware = bluebird_patch_dvico_firmware_download,
1421         /* use usb alt setting 0 for EP4 transfer (dvb-t),
1422            use usb alt setting 7 for EP2 transfer (atsc) */
1423
1424         .size_of_priv     = sizeof(struct cxusb_state),
1425
1426         .num_adapters = 1,
1427         .adapter = {
1428                 {
1429                         .streaming_ctrl   = cxusb_streaming_ctrl,
1430                         .frontend_attach  = cxusb_lgdt3303_frontend_attach,
1431                         .tuner_attach     = cxusb_lgh064f_tuner_attach,
1432
1433                         /* parameter for the MPEG2-data transfer */
1434                                         .stream = {
1435                                                 .type = USB_BULK,
1436                                 .count = 5,
1437                                 .endpoint = 0x02,
1438                                 .u = {
1439                                         .bulk = {
1440                                                 .buffersize = 8192,
1441                                         }
1442                                 }
1443                         },
1444                 },
1445         },
1446
1447         .power_ctrl       = cxusb_bluebird_power_ctrl,
1448
1449         .i2c_algo         = &cxusb_i2c_algo,
1450
1451         .rc_interval      = 100,
1452         .rc_key_map       = dvico_portable_rc_keys,
1453         .rc_key_map_size  = ARRAY_SIZE(dvico_portable_rc_keys),
1454         .rc_query         = cxusb_rc_query,
1455
1456         .generic_bulk_ctrl_endpoint = 0x01,
1457
1458         .num_device_descs = 1,
1459         .devices = {
1460                 {   "DViCO FusionHDTV5 USB Gold",
1461                         { &cxusb_table[1], NULL },
1462                         { &cxusb_table[2], NULL },
1463                 },
1464         }
1465 };
1466
1467 static struct dvb_usb_device_properties cxusb_bluebird_dee1601_properties = {
1468         .caps = DVB_USB_IS_AN_I2C_ADAPTER,
1469
1470         .usb_ctrl          = DEVICE_SPECIFIC,
1471         .firmware          = "dvb-usb-bluebird-01.fw",
1472         .download_firmware = bluebird_patch_dvico_firmware_download,
1473         /* use usb alt setting 0 for EP4 transfer (dvb-t),
1474            use usb alt setting 7 for EP2 transfer (atsc) */
1475
1476         .size_of_priv     = sizeof(struct cxusb_state),
1477
1478         .num_adapters = 1,
1479         .adapter = {
1480                 {
1481                         .streaming_ctrl   = cxusb_streaming_ctrl,
1482                         .frontend_attach  = cxusb_dee1601_frontend_attach,
1483                         .tuner_attach     = cxusb_dee1601_tuner_attach,
1484                         /* parameter for the MPEG2-data transfer */
1485                         .stream = {
1486                                 .type = USB_BULK,
1487                                 .count = 5,
1488                                 .endpoint = 0x04,
1489                                 .u = {
1490                                         .bulk = {
1491                                                 .buffersize = 8192,
1492                                         }
1493                                 }
1494                         },
1495                 },
1496         },
1497
1498         .power_ctrl       = cxusb_bluebird_power_ctrl,
1499
1500         .i2c_algo         = &cxusb_i2c_algo,
1501
1502         .rc_interval      = 150,
1503         .rc_key_map       = dvico_mce_rc_keys,
1504         .rc_key_map_size  = ARRAY_SIZE(dvico_mce_rc_keys),
1505         .rc_query         = cxusb_rc_query,
1506
1507         .generic_bulk_ctrl_endpoint = 0x01,
1508
1509         .num_device_descs = 3,
1510         .devices = {
1511                 {   "DViCO FusionHDTV DVB-T Dual USB",
1512                         { &cxusb_table[3], NULL },
1513                         { &cxusb_table[4], NULL },
1514                 },
1515                 {   "DigitalNow DVB-T Dual USB",
1516                         { &cxusb_table[9],  NULL },
1517                         { &cxusb_table[10], NULL },
1518                 },
1519                 {   "DViCO FusionHDTV DVB-T Dual Digital 2",
1520                         { &cxusb_table[11], NULL },
1521                         { &cxusb_table[12], NULL },
1522                 },
1523         }
1524 };
1525
1526 static struct dvb_usb_device_properties cxusb_bluebird_lgz201_properties = {
1527         .caps = DVB_USB_IS_AN_I2C_ADAPTER,
1528
1529         .usb_ctrl          = DEVICE_SPECIFIC,
1530         .firmware          = "dvb-usb-bluebird-01.fw",
1531         .download_firmware = bluebird_patch_dvico_firmware_download,
1532         /* use usb alt setting 0 for EP4 transfer (dvb-t),
1533            use usb alt setting 7 for EP2 transfer (atsc) */
1534
1535         .size_of_priv     = sizeof(struct cxusb_state),
1536
1537         .num_adapters = 2,
1538         .adapter = {
1539                 {
1540                         .streaming_ctrl   = cxusb_streaming_ctrl,
1541                         .frontend_attach  = cxusb_mt352_frontend_attach,
1542                         .tuner_attach     = cxusb_lgz201_tuner_attach,
1543
1544                         /* parameter for the MPEG2-data transfer */
1545                         .stream = {
1546                                 .type = USB_BULK,
1547                                 .count = 5,
1548                                 .endpoint = 0x04,
1549                                 .u = {
1550                                         .bulk = {
1551                                                 .buffersize = 8192,
1552                                         }
1553                                 }
1554                         },
1555                 },
1556         },
1557         .power_ctrl       = cxusb_bluebird_power_ctrl,
1558
1559         .i2c_algo         = &cxusb_i2c_algo,
1560
1561         .rc_interval      = 100,
1562         .rc_key_map       = dvico_portable_rc_keys,
1563         .rc_key_map_size  = ARRAY_SIZE(dvico_portable_rc_keys),
1564         .rc_query         = cxusb_rc_query,
1565
1566         .generic_bulk_ctrl_endpoint = 0x01,
1567         .num_device_descs = 1,
1568         .devices = {
1569                 {   "DViCO FusionHDTV DVB-T USB (LGZ201)",
1570                         { &cxusb_table[5], NULL },
1571                         { &cxusb_table[6], NULL },
1572                 },
1573         }
1574 };
1575
1576 static struct dvb_usb_device_properties cxusb_bluebird_dtt7579_properties = {
1577         .caps = DVB_USB_IS_AN_I2C_ADAPTER,
1578
1579         .usb_ctrl          = DEVICE_SPECIFIC,
1580         .firmware          = "dvb-usb-bluebird-01.fw",
1581         .download_firmware = bluebird_patch_dvico_firmware_download,
1582         /* use usb alt setting 0 for EP4 transfer (dvb-t),
1583            use usb alt setting 7 for EP2 transfer (atsc) */
1584
1585         .size_of_priv     = sizeof(struct cxusb_state),
1586
1587         .num_adapters = 1,
1588         .adapter = {
1589                 {
1590                         .streaming_ctrl   = cxusb_streaming_ctrl,
1591                         .frontend_attach  = cxusb_mt352_frontend_attach,
1592                         .tuner_attach     = cxusb_dtt7579_tuner_attach,
1593
1594                         /* parameter for the MPEG2-data transfer */
1595                         .stream = {
1596                                 .type = USB_BULK,
1597                                 .count = 5,
1598                                 .endpoint = 0x04,
1599                                 .u = {
1600                                         .bulk = {
1601                                                 .buffersize = 8192,
1602                                         }
1603                                 }
1604                         },
1605                 },
1606         },
1607         .power_ctrl       = cxusb_bluebird_power_ctrl,
1608
1609         .i2c_algo         = &cxusb_i2c_algo,
1610
1611         .rc_interval      = 100,
1612         .rc_key_map       = dvico_portable_rc_keys,
1613         .rc_key_map_size  = ARRAY_SIZE(dvico_portable_rc_keys),
1614         .rc_query         = cxusb_rc_query,
1615
1616         .generic_bulk_ctrl_endpoint = 0x01,
1617
1618         .num_device_descs = 1,
1619         .devices = {
1620                 {   "DViCO FusionHDTV DVB-T USB (TH7579)",
1621                         { &cxusb_table[7], NULL },
1622                         { &cxusb_table[8], NULL },
1623                 },
1624         }
1625 };
1626
1627 static struct dvb_usb_device_properties cxusb_bluebird_dualdig4_properties = {
1628         .caps = DVB_USB_IS_AN_I2C_ADAPTER,
1629
1630         .usb_ctrl         = CYPRESS_FX2,
1631
1632         .size_of_priv     = sizeof(struct cxusb_state),
1633
1634         .num_adapters = 1,
1635         .adapter = {
1636                 {
1637                         .streaming_ctrl   = cxusb_streaming_ctrl,
1638                         .frontend_attach  = cxusb_dualdig4_frontend_attach,
1639                         .tuner_attach     = cxusb_dvico_xc3028_tuner_attach,
1640                         /* parameter for the MPEG2-data transfer */
1641                         .stream = {
1642                                 .type = USB_BULK,
1643                                 .count = 5,
1644                                 .endpoint = 0x02,
1645                                 .u = {
1646                                         .bulk = {
1647                                                 .buffersize = 8192,
1648                                         }
1649                                 }
1650                         },
1651                 },
1652         },
1653
1654         .power_ctrl       = cxusb_power_ctrl,
1655
1656         .i2c_algo         = &cxusb_i2c_algo,
1657
1658         .generic_bulk_ctrl_endpoint = 0x01,
1659
1660         .rc_interval      = 100,
1661         .rc_key_map       = dvico_mce_rc_keys,
1662         .rc_key_map_size  = ARRAY_SIZE(dvico_mce_rc_keys),
1663         .rc_query         = cxusb_bluebird2_rc_query,
1664
1665         .num_device_descs = 1,
1666         .devices = {
1667                 {   "DViCO FusionHDTV DVB-T Dual Digital 4",
1668                         { NULL },
1669                         { &cxusb_table[13], NULL },
1670                 },
1671         }
1672 };
1673
1674 static struct dvb_usb_device_properties cxusb_bluebird_nano2_properties = {
1675         .caps = DVB_USB_IS_AN_I2C_ADAPTER,
1676
1677         .usb_ctrl         = CYPRESS_FX2,
1678         .identify_state   = bluebird_fx2_identify_state,
1679
1680         .size_of_priv     = sizeof(struct cxusb_state),
1681
1682         .num_adapters = 1,
1683         .adapter = {
1684                 {
1685                         .streaming_ctrl   = cxusb_streaming_ctrl,
1686                         .frontend_attach  = cxusb_nano2_frontend_attach,
1687                         .tuner_attach     = cxusb_dvico_xc3028_tuner_attach,
1688                         /* parameter for the MPEG2-data transfer */
1689                         .stream = {
1690                                 .type = USB_BULK,
1691                                 .count = 5,
1692                                 .endpoint = 0x02,
1693                                 .u = {
1694                                         .bulk = {
1695                                                 .buffersize = 8192,
1696                                         }
1697                                 }
1698                         },
1699                 },
1700         },
1701
1702         .power_ctrl       = cxusb_nano2_power_ctrl,
1703
1704         .i2c_algo         = &cxusb_i2c_algo,
1705
1706         .generic_bulk_ctrl_endpoint = 0x01,
1707
1708         .rc_interval      = 100,
1709         .rc_key_map       = dvico_portable_rc_keys,
1710         .rc_key_map_size  = ARRAY_SIZE(dvico_portable_rc_keys),
1711         .rc_query         = cxusb_bluebird2_rc_query,
1712
1713         .num_device_descs = 1,
1714         .devices = {
1715                 {   "DViCO FusionHDTV DVB-T NANO2",
1716                         { NULL },
1717                         { &cxusb_table[14], NULL },
1718                 },
1719         }
1720 };
1721
1722 static struct dvb_usb_device_properties cxusb_bluebird_nano2_needsfirmware_properties = {
1723         .caps = DVB_USB_IS_AN_I2C_ADAPTER,
1724
1725         .usb_ctrl          = DEVICE_SPECIFIC,
1726         .firmware          = "dvb-usb-bluebird-02.fw",
1727         .download_firmware = bluebird_patch_dvico_firmware_download,
1728         .identify_state    = bluebird_fx2_identify_state,
1729
1730         .size_of_priv      = sizeof(struct cxusb_state),
1731
1732         .num_adapters = 1,
1733         .adapter = {
1734                 {
1735                         .streaming_ctrl   = cxusb_streaming_ctrl,
1736                         .frontend_attach  = cxusb_nano2_frontend_attach,
1737                         .tuner_attach     = cxusb_dvico_xc3028_tuner_attach,
1738                         /* parameter for the MPEG2-data transfer */
1739                         .stream = {
1740                                 .type = USB_BULK,
1741                                 .count = 5,
1742                                 .endpoint = 0x02,
1743                                 .u = {
1744                                         .bulk = {
1745                                                 .buffersize = 8192,
1746                                         }
1747                                 }
1748                         },
1749                 },
1750         },
1751
1752         .power_ctrl       = cxusb_nano2_power_ctrl,
1753
1754         .i2c_algo         = &cxusb_i2c_algo,
1755
1756         .generic_bulk_ctrl_endpoint = 0x01,
1757
1758         .rc_interval      = 100,
1759         .rc_key_map       = dvico_portable_rc_keys,
1760         .rc_key_map_size  = ARRAY_SIZE(dvico_portable_rc_keys),
1761         .rc_query         = cxusb_rc_query,
1762
1763         .num_device_descs = 1,
1764         .devices = {
1765                 {   "DViCO FusionHDTV DVB-T NANO2 w/o firmware",
1766                         { &cxusb_table[14], NULL },
1767                         { &cxusb_table[15], NULL },
1768                 },
1769         }
1770 };
1771
1772 static struct dvb_usb_device_properties cxusb_aver_a868r_properties = {
1773         .caps = DVB_USB_IS_AN_I2C_ADAPTER,
1774
1775         .usb_ctrl         = CYPRESS_FX2,
1776
1777         .size_of_priv     = sizeof(struct cxusb_state),
1778
1779         .num_adapters = 1,
1780         .adapter = {
1781                 {
1782                         .streaming_ctrl   = cxusb_aver_streaming_ctrl,
1783                         .frontend_attach  = cxusb_aver_lgdt3303_frontend_attach,
1784                         .tuner_attach     = cxusb_mxl5003s_tuner_attach,
1785                         /* parameter for the MPEG2-data transfer */
1786                         .stream = {
1787                                 .type = USB_BULK,
1788                                 .count = 5,
1789                                 .endpoint = 0x04,
1790                                 .u = {
1791                                         .bulk = {
1792                                                 .buffersize = 8192,
1793                                         }
1794                                 }
1795                         },
1796
1797                 },
1798         },
1799         .power_ctrl       = cxusb_aver_power_ctrl,
1800
1801         .i2c_algo         = &cxusb_i2c_algo,
1802
1803         .generic_bulk_ctrl_endpoint = 0x01,
1804
1805         .num_device_descs = 1,
1806         .devices = {
1807                 {   "AVerMedia AVerTVHD Volar (A868R)",
1808                         { NULL },
1809                         { &cxusb_table[16], NULL },
1810                 },
1811         }
1812 };
1813
1814 static
1815 struct dvb_usb_device_properties cxusb_bluebird_dualdig4_rev2_properties = {
1816         .caps = DVB_USB_IS_AN_I2C_ADAPTER,
1817
1818         .usb_ctrl         = CYPRESS_FX2,
1819
1820         .size_of_priv     = sizeof(struct cxusb_state),
1821
1822         .num_adapters = 1,
1823         .adapter = {
1824                 {
1825                         .streaming_ctrl  = cxusb_streaming_ctrl,
1826                         .frontend_attach = cxusb_dualdig4_rev2_frontend_attach,
1827                         .tuner_attach    = cxusb_dualdig4_rev2_tuner_attach,
1828                         .size_of_priv    = sizeof(struct dib0700_adapter_state),
1829                         /* parameter for the MPEG2-data transfer */
1830                         .stream = {
1831                                 .type = USB_BULK,
1832                                 .count = 7,
1833                                 .endpoint = 0x02,
1834                                 .u = {
1835                                         .bulk = {
1836                                                 .buffersize = 4096,
1837                                         }
1838                                 }
1839                         },
1840                 },
1841         },
1842
1843         .power_ctrl       = cxusb_bluebird_power_ctrl,
1844
1845         .i2c_algo         = &cxusb_i2c_algo,
1846
1847         .generic_bulk_ctrl_endpoint = 0x01,
1848
1849         .rc_interval      = 100,
1850         .rc_key_map       = dvico_mce_rc_keys,
1851         .rc_key_map_size  = ARRAY_SIZE(dvico_mce_rc_keys),
1852         .rc_query         = cxusb_rc_query,
1853
1854         .num_device_descs = 1,
1855         .devices = {
1856                 {   "DViCO FusionHDTV DVB-T Dual Digital 4 (rev 2)",
1857                         { NULL },
1858                         { &cxusb_table[17], NULL },
1859                 },
1860         }
1861 };
1862
1863 static struct dvb_usb_device_properties cxusb_d680_dmb_properties = {
1864         .caps = DVB_USB_IS_AN_I2C_ADAPTER,
1865
1866         .usb_ctrl         = CYPRESS_FX2,
1867
1868         .size_of_priv     = sizeof(struct cxusb_state),
1869
1870         .num_adapters = 1,
1871         .adapter = {
1872                 {
1873                         .streaming_ctrl   = cxusb_d680_dmb_streaming_ctrl,
1874                         .frontend_attach  = cxusb_d680_dmb_frontend_attach,
1875                         .tuner_attach     = cxusb_d680_dmb_tuner_attach,
1876
1877                         /* parameter for the MPEG2-data transfer */
1878                         .stream = {
1879                                 .type = USB_BULK,
1880                                 .count = 5,
1881                                 .endpoint = 0x02,
1882                                 .u = {
1883                                         .bulk = {
1884                                                 .buffersize = 8192,
1885                                         }
1886                                 }
1887                         },
1888                 },
1889         },
1890
1891         .power_ctrl       = cxusb_d680_dmb_power_ctrl,
1892
1893         .i2c_algo         = &cxusb_i2c_algo,
1894
1895         .generic_bulk_ctrl_endpoint = 0x01,
1896
1897         .rc_interval      = 100,
1898         .rc_key_map       = d680_dmb_rc_keys,
1899         .rc_key_map_size  = ARRAY_SIZE(d680_dmb_rc_keys),
1900         .rc_query         = cxusb_d680_dmb_rc_query,
1901
1902         .num_device_descs = 1,
1903         .devices = {
1904                 {
1905                         "Conexant DMB-TH Stick",
1906                         { NULL },
1907                         { &cxusb_table[18], NULL },
1908                 },
1909         }
1910 };
1911
1912 static struct dvb_usb_device_properties cxusb_mygica_d689_properties = {
1913         .caps = DVB_USB_IS_AN_I2C_ADAPTER,
1914
1915         .usb_ctrl         = CYPRESS_FX2,
1916
1917         .size_of_priv     = sizeof(struct cxusb_state),
1918
1919         .num_adapters = 1,
1920         .adapter = {
1921                 {
1922                         .streaming_ctrl   = cxusb_d680_dmb_streaming_ctrl,
1923                         .frontend_attach  = cxusb_mygica_d689_frontend_attach,
1924                         .tuner_attach     = cxusb_mygica_d689_tuner_attach,
1925
1926                         /* parameter for the MPEG2-data transfer */
1927                         .stream = {
1928                                 .type = USB_BULK,
1929                                 .count = 5,
1930                                 .endpoint = 0x02,
1931                                 .u = {
1932                                         .bulk = {
1933                                                 .buffersize = 8192,
1934                                         }
1935                                 }
1936                         },
1937                 },
1938         },
1939
1940         .power_ctrl       = cxusb_d680_dmb_power_ctrl,
1941
1942         .i2c_algo         = &cxusb_i2c_algo,
1943
1944         .generic_bulk_ctrl_endpoint = 0x01,
1945
1946         .rc_interval      = 100,
1947         .rc_key_map       = d680_dmb_rc_keys,
1948         .rc_key_map_size  = ARRAY_SIZE(d680_dmb_rc_keys),
1949         .rc_query         = cxusb_d680_dmb_rc_query,
1950
1951         .num_device_descs = 1,
1952         .devices = {
1953                 {
1954                         "Mygica D689 DMB-TH",
1955                         { NULL },
1956                         { &cxusb_table[19], NULL },
1957                 },
1958         }
1959 };
1960
1961 static struct usb_driver cxusb_driver = {
1962         .name           = "dvb_usb_cxusb",
1963         .probe          = cxusb_probe,
1964         .disconnect     = dvb_usb_device_exit,
1965         .id_table       = cxusb_table,
1966 };
1967
1968 /* module stuff */
1969 static int __init cxusb_module_init(void)
1970 {
1971         int result;
1972         if ((result = usb_register(&cxusb_driver))) {
1973                 err("usb_register failed. Error number %d",result);
1974                 return result;
1975         }
1976
1977         return 0;
1978 }
1979
1980 static void __exit cxusb_module_exit(void)
1981 {
1982         /* deregister this driver from the USB subsystem */
1983         usb_deregister(&cxusb_driver);
1984 }
1985
1986 module_init (cxusb_module_init);
1987 module_exit (cxusb_module_exit);
1988
1989 MODULE_AUTHOR("Patrick Boettcher <patrick.boettcher@desy.de>");
1990 MODULE_AUTHOR("Michael Krufky <mkrufky@linuxtv.org>");
1991 MODULE_AUTHOR("Chris Pascoe <c.pascoe@itee.uq.edu.au>");
1992 MODULE_DESCRIPTION("Driver for Conexant USB2.0 hybrid reference design");
1993 MODULE_VERSION("1.0-alpha");
1994 MODULE_LICENSE("GPL");