Linux kernel & device driver programming

Cross-Referenced Linux and Device Driver Code

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