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