1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23#include <media/tuner.h>
24#include <linux/delay.h>
25#include <linux/device.h>
26#include <linux/kernel.h>
27#include <linux/slab.h>
28#include <linux/string.h>
29#include <linux/vmalloc.h>
30
31#include "cxusb.h"
32
33#include "cx22702.h"
34#include "lgdt330x.h"
35#include "mt352.h"
36#include "mt352_priv.h"
37#include "zl10353.h"
38#include "tuner-xc2028.h"
39#include "tuner-simple.h"
40#include "mxl5005s.h"
41#include "max2165.h"
42#include "dib7000p.h"
43#include "dib0070.h"
44#include "lgs8gxx.h"
45#include "atbm8830.h"
46#include "si2168.h"
47#include "si2157.h"
48
49
50int dvb_usb_cxusb_debug;
51module_param_named(debug, dvb_usb_cxusb_debug, int, 0644);
52MODULE_PARM_DESC(debug, "set debugging level (see cxusb.h)."
53 DVB_USB_DEBUG_STATUS);
54
55DVB_DEFINE_MOD_OPT_ADAPTER_NR(adapter_nr);
56
57enum cxusb_table_index {
58 MEDION_MD95700,
59 DVICO_BLUEBIRD_LG064F_COLD,
60 DVICO_BLUEBIRD_LG064F_WARM,
61 DVICO_BLUEBIRD_DUAL_1_COLD,
62 DVICO_BLUEBIRD_DUAL_1_WARM,
63 DVICO_BLUEBIRD_LGZ201_COLD,
64 DVICO_BLUEBIRD_LGZ201_WARM,
65 DVICO_BLUEBIRD_TH7579_COLD,
66 DVICO_BLUEBIRD_TH7579_WARM,
67 DIGITALNOW_BLUEBIRD_DUAL_1_COLD,
68 DIGITALNOW_BLUEBIRD_DUAL_1_WARM,
69 DVICO_BLUEBIRD_DUAL_2_COLD,
70 DVICO_BLUEBIRD_DUAL_2_WARM,
71 DVICO_BLUEBIRD_DUAL_4,
72 DVICO_BLUEBIRD_DVB_T_NANO_2,
73 DVICO_BLUEBIRD_DVB_T_NANO_2_NFW_WARM,
74 AVERMEDIA_VOLAR_A868R,
75 DVICO_BLUEBIRD_DUAL_4_REV_2,
76 CONEXANT_D680_DMB,
77 MYGICA_D689,
78 NR__cxusb_table_index
79};
80
81static struct usb_device_id cxusb_table[];
82
83int cxusb_ctrl_msg(struct dvb_usb_device *d,
84 u8 cmd, const u8 *wbuf, int wlen, u8 *rbuf, int rlen)
85{
86 struct cxusb_state *st = d->priv;
87 int ret;
88
89 if (1 + wlen > MAX_XFER_SIZE) {
90 warn("i2c wr: len=%d is too big!\n", wlen);
91 return -EOPNOTSUPP;
92 }
93
94 if (rlen > MAX_XFER_SIZE) {
95 warn("i2c rd: len=%d is too big!\n", rlen);
96 return -EOPNOTSUPP;
97 }
98
99 mutex_lock(&d->data_mutex);
100 st->data[0] = cmd;
101 memcpy(&st->data[1], wbuf, wlen);
102 ret = dvb_usb_generic_rw(d, st->data, 1 + wlen, st->data, rlen, 0);
103 if (!ret && rbuf && rlen)
104 memcpy(rbuf, st->data, rlen);
105
106 mutex_unlock(&d->data_mutex);
107 return ret;
108}
109
110
111static void cxusb_gpio_tuner(struct dvb_usb_device *d, int onoff)
112{
113 struct cxusb_state *st = d->priv;
114 u8 o[2], i;
115
116 if (st->gpio_write_state[GPIO_TUNER] == onoff &&
117 !st->gpio_write_refresh[GPIO_TUNER])
118 return;
119
120 o[0] = GPIO_TUNER;
121 o[1] = onoff;
122 cxusb_ctrl_msg(d, CMD_GPIO_WRITE, o, 2, &i, 1);
123
124 if (i != 0x01)
125 dev_info(&d->udev->dev, "gpio_write failed.\n");
126
127 st->gpio_write_state[GPIO_TUNER] = onoff;
128 st->gpio_write_refresh[GPIO_TUNER] = false;
129}
130
131static int cxusb_bluebird_gpio_rw(struct dvb_usb_device *d, u8 changemask,
132 u8 newval)
133{
134 u8 o[2], gpio_state;
135 int rc;
136
137 o[0] = 0xff & ~changemask;
138 o[1] = newval & changemask;
139
140 rc = cxusb_ctrl_msg(d, CMD_BLUEBIRD_GPIO_RW, o, 2, &gpio_state, 1);
141 if (rc < 0 || (gpio_state & changemask) != (newval & changemask))
142 dev_info(&d->udev->dev, "bluebird_gpio_write failed.\n");
143
144 return rc < 0 ? rc : gpio_state;
145}
146
147static void cxusb_bluebird_gpio_pulse(struct dvb_usb_device *d, u8 pin, int low)
148{
149 cxusb_bluebird_gpio_rw(d, pin, low ? 0 : pin);
150 msleep(5);
151 cxusb_bluebird_gpio_rw(d, pin, low ? pin : 0);
152}
153
154static void cxusb_nano2_led(struct dvb_usb_device *d, int onoff)
155{
156 cxusb_bluebird_gpio_rw(d, 0x40, onoff ? 0 : 0x40);
157}
158
159static int cxusb_d680_dmb_gpio_tuner(struct dvb_usb_device *d,
160 u8 addr, int onoff)
161{
162 u8 o[2] = {addr, onoff};
163 u8 i;
164 int rc;
165
166 rc = cxusb_ctrl_msg(d, CMD_GPIO_WRITE, o, 2, &i, 1);
167
168 if (rc < 0)
169 return rc;
170
171 if (i == 0x01)
172 return 0;
173
174 dev_info(&d->udev->dev, "gpio_write failed.\n");
175 return -EIO;
176}
177
178
179static int cxusb_i2c_xfer(struct i2c_adapter *adap, struct i2c_msg msg[],
180 int num)
181{
182 struct dvb_usb_device *d = i2c_get_adapdata(adap);
183 int ret;
184 int i;
185
186 if (mutex_lock_interruptible(&d->i2c_mutex) < 0)
187 return -EAGAIN;
188
189 for (i = 0; i < num; i++) {
190 if (le16_to_cpu(d->udev->descriptor.idVendor) == USB_VID_MEDION)
191 switch (msg[i].addr) {
192 case 0x63:
193 cxusb_gpio_tuner(d, 0);
194 break;
195 default:
196 cxusb_gpio_tuner(d, 1);
197 break;
198 }
199
200 if (msg[i].flags & I2C_M_RD) {
201
202 u8 obuf[3], ibuf[MAX_XFER_SIZE];
203
204 if (1 + msg[i].len > sizeof(ibuf)) {
205 warn("i2c rd: len=%d is too big!\n",
206 msg[i].len);
207 ret = -EOPNOTSUPP;
208 goto unlock;
209 }
210 obuf[0] = 0;
211 obuf[1] = msg[i].len;
212 obuf[2] = msg[i].addr;
213 if (cxusb_ctrl_msg(d, CMD_I2C_READ,
214 obuf, 3,
215 ibuf, 1 + msg[i].len) < 0) {
216 warn("i2c read failed");
217 break;
218 }
219 memcpy(msg[i].buf, &ibuf[1], msg[i].len);
220 } else if (i + 1 < num && (msg[i + 1].flags & I2C_M_RD) &&
221 msg[i].addr == msg[i + 1].addr) {
222
223 u8 obuf[MAX_XFER_SIZE], ibuf[MAX_XFER_SIZE];
224
225 if (3 + msg[i].len > sizeof(obuf)) {
226 warn("i2c wr: len=%d is too big!\n",
227 msg[i].len);
228 ret = -EOPNOTSUPP;
229 goto unlock;
230 }
231 if (1 + msg[i + 1].len > sizeof(ibuf)) {
232 warn("i2c rd: len=%d is too big!\n",
233 msg[i + 1].len);
234 ret = -EOPNOTSUPP;
235 goto unlock;
236 }
237 obuf[0] = msg[i].len;
238 obuf[1] = msg[i + 1].len;
239 obuf[2] = msg[i].addr;
240 memcpy(&obuf[3], msg[i].buf, msg[i].len);
241
242 if (cxusb_ctrl_msg(d, CMD_I2C_READ,
243 obuf, 3 + msg[i].len,
244 ibuf, 1 + msg[i + 1].len) < 0)
245 break;
246
247 if (ibuf[0] != 0x08)
248 dev_info(&d->udev->dev, "i2c read may have failed\n");
249
250 memcpy(msg[i + 1].buf, &ibuf[1], msg[i + 1].len);
251
252 i++;
253 } else {
254
255 u8 obuf[MAX_XFER_SIZE], ibuf;
256
257 if (2 + msg[i].len > sizeof(obuf)) {
258 warn("i2c wr: len=%d is too big!\n",
259 msg[i].len);
260 ret = -EOPNOTSUPP;
261 goto unlock;
262 }
263 obuf[0] = msg[i].addr;
264 obuf[1] = msg[i].len;
265 memcpy(&obuf[2], msg[i].buf, msg[i].len);
266
267 if (cxusb_ctrl_msg(d, CMD_I2C_WRITE, obuf,
268 2 + msg[i].len, &ibuf, 1) < 0)
269 break;
270 if (ibuf != 0x08)
271 dev_info(&d->udev->dev, "i2c write may have failed\n");
272 }
273 }
274
275 if (i == num)
276 ret = num;
277 else
278 ret = -EREMOTEIO;
279
280unlock:
281 mutex_unlock(&d->i2c_mutex);
282 return ret;
283}
284
285static u32 cxusb_i2c_func(struct i2c_adapter *adapter)
286{
287 return I2C_FUNC_I2C | I2C_FUNC_SMBUS_EMUL;
288}
289
290static struct i2c_algorithm cxusb_i2c_algo = {
291 .master_xfer = cxusb_i2c_xfer,
292 .functionality = cxusb_i2c_func,
293};
294
295static int _cxusb_power_ctrl(struct dvb_usb_device *d, int onoff)
296{
297 u8 b = 0;
298
299 dev_info(&d->udev->dev, "setting power %s\n", onoff ? "ON" : "OFF");
300
301 if (onoff)
302 return cxusb_ctrl_msg(d, CMD_POWER_ON, &b, 1, NULL, 0);
303 else
304 return cxusb_ctrl_msg(d, CMD_POWER_OFF, &b, 1, NULL, 0);
305}
306
307static int cxusb_power_ctrl(struct dvb_usb_device *d, int onoff)
308{
309 bool is_medion = d->props.devices[0].warm_ids[0] == &cxusb_table[MEDION_MD95700];
310 int ret;
311
312 if (is_medion && !onoff) {
313 struct cxusb_medion_dev *cxdev = d->priv;
314
315 mutex_lock(&cxdev->open_lock);
316
317 if (cxdev->open_type == CXUSB_OPEN_ANALOG) {
318 dev_info(&d->udev->dev, "preventing DVB core from setting power OFF while we are in analog mode\n");
319 ret = -EBUSY;
320 goto ret_unlock;
321 }
322 }
323
324 ret = _cxusb_power_ctrl(d, onoff);
325
326ret_unlock:
327 if (is_medion && !onoff) {
328 struct cxusb_medion_dev *cxdev = d->priv;
329
330 mutex_unlock(&cxdev->open_lock);
331 }
332
333 return ret;
334}
335
336static int cxusb_aver_power_ctrl(struct dvb_usb_device *d, int onoff)
337{
338 int ret;
339
340 if (!onoff)
341 return cxusb_ctrl_msg(d, CMD_POWER_OFF, NULL, 0, NULL, 0);
342 if (d->state == DVB_USB_STATE_INIT &&
343 usb_set_interface(d->udev, 0, 0) < 0)
344 err("set interface failed");
345 do {
346
347 } while (!(ret = cxusb_ctrl_msg(d, CMD_POWER_ON, NULL, 0, NULL, 0)) &&
348 !(ret = cxusb_ctrl_msg(d, 0x15, NULL, 0, NULL, 0)) &&
349 !(ret = cxusb_ctrl_msg(d, 0x17, NULL, 0, NULL, 0)) && 0);
350
351 if (!ret) {
352
353
354
355
356 int i;
357 u8 buf;
358 static const u8 bufs[] = {
359 0x0e, 0x2, 0x00, 0x7f,
360 0x0e, 0x2, 0x02, 0xfe,
361 0x0e, 0x2, 0x02, 0x01,
362 0x0e, 0x2, 0x00, 0x03,
363 0x0e, 0x2, 0x0d, 0x40,
364 0x0e, 0x2, 0x0e, 0x87,
365 0x0e, 0x2, 0x0f, 0x8e,
366 0x0e, 0x2, 0x10, 0x01,
367 0x0e, 0x2, 0x14, 0xd7,
368 0x0e, 0x2, 0x47, 0x88,
369 };
370 msleep(20);
371 for (i = 0; i < ARRAY_SIZE(bufs); i += 4 / sizeof(u8)) {
372 ret = cxusb_ctrl_msg(d, CMD_I2C_WRITE,
373 bufs + i, 4, &buf, 1);
374 if (ret)
375 break;
376 if (buf != 0x8)
377 return -EREMOTEIO;
378 }
379 }
380 return ret;
381}
382
383static int cxusb_bluebird_power_ctrl(struct dvb_usb_device *d, int onoff)
384{
385 u8 b = 0;
386
387 if (onoff)
388 return cxusb_ctrl_msg(d, CMD_POWER_ON, &b, 1, NULL, 0);
389 else
390 return 0;
391}
392
393static int cxusb_nano2_power_ctrl(struct dvb_usb_device *d, int onoff)
394{
395 int rc = 0;
396
397 rc = cxusb_power_ctrl(d, onoff);
398 if (!onoff)
399 cxusb_nano2_led(d, 0);
400
401 return rc;
402}
403
404static int cxusb_d680_dmb_power_ctrl(struct dvb_usb_device *d, int onoff)
405{
406 int ret;
407 u8 b;
408
409 ret = cxusb_power_ctrl(d, onoff);
410 if (!onoff)
411 return ret;
412
413 msleep(128);
414 cxusb_ctrl_msg(d, CMD_DIGITAL, NULL, 0, &b, 1);
415 msleep(100);
416 return ret;
417}
418
419static int cxusb_streaming_ctrl(struct dvb_usb_adapter *adap, int onoff)
420{
421 struct dvb_usb_device *dvbdev = adap->dev;
422 bool is_medion = dvbdev->props.devices[0].warm_ids[0] ==
423 &cxusb_table[MEDION_MD95700];
424 u8 buf[2] = { 0x03, 0x00 };
425
426 if (is_medion && onoff) {
427 int ret;
428
429 ret = cxusb_medion_get(dvbdev, CXUSB_OPEN_DIGITAL);
430 if (ret != 0)
431 return ret;
432 }
433
434 if (onoff)
435 cxusb_ctrl_msg(dvbdev, CMD_STREAMING_ON, buf, 2, NULL, 0);
436 else
437 cxusb_ctrl_msg(dvbdev, CMD_STREAMING_OFF, NULL, 0, NULL, 0);
438
439 if (is_medion && !onoff)
440 cxusb_medion_put(dvbdev);
441
442 return 0;
443}
444
445static int cxusb_aver_streaming_ctrl(struct dvb_usb_adapter *adap, int onoff)
446{
447 if (onoff)
448 cxusb_ctrl_msg(adap->dev, CMD_AVER_STREAM_ON, NULL, 0, NULL, 0);
449 else
450 cxusb_ctrl_msg(adap->dev, CMD_AVER_STREAM_OFF,
451 NULL, 0, NULL, 0);
452 return 0;
453}
454
455static void cxusb_d680_dmb_drain_message(struct dvb_usb_device *d)
456{
457 int ep = d->props.generic_bulk_ctrl_endpoint;
458 const int timeout = 100;
459 const int junk_len = 32;
460 u8 *junk;
461 int rd_count;
462
463
464 junk = kmalloc(junk_len, GFP_KERNEL);
465 if (!junk)
466 return;
467 while (1) {
468 if (usb_bulk_msg(d->udev,
469 usb_rcvbulkpipe(d->udev, ep),
470 junk, junk_len, &rd_count, timeout) < 0)
471 break;
472 if (!rd_count)
473 break;
474 }
475 kfree(junk);
476}
477
478static void cxusb_d680_dmb_drain_video(struct dvb_usb_device *d)
479{
480 struct usb_data_stream_properties *p = &d->props.adapter[0].fe[0].stream;
481 const int timeout = 100;
482 const int junk_len = p->u.bulk.buffersize;
483 u8 *junk;
484 int rd_count;
485
486
487 junk = kmalloc(junk_len, GFP_KERNEL);
488 if (!junk)
489 return;
490 while (1) {
491 if (usb_bulk_msg(d->udev,
492 usb_rcvbulkpipe(d->udev, p->endpoint),
493 junk, junk_len, &rd_count, timeout) < 0)
494 break;
495 if (!rd_count)
496 break;
497 }
498 kfree(junk);
499}
500
501static int cxusb_d680_dmb_streaming_ctrl(struct dvb_usb_adapter *adap,
502 int onoff)
503{
504 if (onoff) {
505 u8 buf[2] = { 0x03, 0x00 };
506
507 cxusb_d680_dmb_drain_video(adap->dev);
508 return cxusb_ctrl_msg(adap->dev, CMD_STREAMING_ON,
509 buf, sizeof(buf), NULL, 0);
510 } else {
511 int ret = cxusb_ctrl_msg(adap->dev,
512 CMD_STREAMING_OFF, NULL, 0, NULL, 0);
513 return ret;
514 }
515}
516
517static int cxusb_rc_query(struct dvb_usb_device *d)
518{
519 u8 ircode[4];
520
521 if (cxusb_ctrl_msg(d, CMD_GET_IR_CODE, NULL, 0, ircode, 4) < 0)
522 return 0;
523
524 if (ircode[2] || ircode[3])
525 rc_keydown(d->rc_dev, RC_PROTO_NEC,
526 RC_SCANCODE_NEC(~ircode[2] & 0xff, ircode[3]), 0);
527 return 0;
528}
529
530static int cxusb_bluebird2_rc_query(struct dvb_usb_device *d)
531{
532 u8 ircode[4];
533 struct i2c_msg msg = {
534 .addr = 0x6b,
535 .flags = I2C_M_RD,
536 .buf = ircode,
537 .len = 4
538 };
539
540 if (cxusb_i2c_xfer(&d->i2c_adap, &msg, 1) != 1)
541 return 0;
542
543 if (ircode[1] || ircode[2])
544 rc_keydown(d->rc_dev, RC_PROTO_NEC,
545 RC_SCANCODE_NEC(~ircode[1] & 0xff, ircode[2]), 0);
546 return 0;
547}
548
549static int cxusb_d680_dmb_rc_query(struct dvb_usb_device *d)
550{
551 u8 ircode[2];
552
553 if (cxusb_ctrl_msg(d, 0x10, NULL, 0, ircode, 2) < 0)
554 return 0;
555
556 if (ircode[0] || ircode[1])
557 rc_keydown(d->rc_dev, RC_PROTO_UNKNOWN,
558 RC_SCANCODE_RC5(ircode[0], ircode[1]), 0);
559 return 0;
560}
561
562static int cxusb_dee1601_demod_init(struct dvb_frontend *fe)
563{
564 static u8 clock_config[] = { CLOCK_CTL, 0x38, 0x28 };
565 static u8 reset[] = { RESET, 0x80 };
566 static u8 adc_ctl_1_cfg[] = { ADC_CTL_1, 0x40 };
567 static u8 agc_cfg[] = { AGC_TARGET, 0x28, 0x20 };
568 static u8 gpp_ctl_cfg[] = { GPP_CTL, 0x33 };
569 static u8 capt_range_cfg[] = { CAPT_RANGE, 0x32 };
570
571 mt352_write(fe, clock_config, sizeof(clock_config));
572 udelay(200);
573 mt352_write(fe, reset, sizeof(reset));
574 mt352_write(fe, adc_ctl_1_cfg, sizeof(adc_ctl_1_cfg));
575
576 mt352_write(fe, agc_cfg, sizeof(agc_cfg));
577 mt352_write(fe, gpp_ctl_cfg, sizeof(gpp_ctl_cfg));
578 mt352_write(fe, capt_range_cfg, sizeof(capt_range_cfg));
579
580 return 0;
581}
582
583static int cxusb_mt352_demod_init(struct dvb_frontend *fe)
584{
585
586 static u8 clock_config[] = { CLOCK_CTL, 0x38, 0x29 };
587 static u8 reset[] = { RESET, 0x80 };
588 static u8 adc_ctl_1_cfg[] = { ADC_CTL_1, 0x40 };
589 static u8 agc_cfg[] = { AGC_TARGET, 0x24, 0x20 };
590 static u8 gpp_ctl_cfg[] = { GPP_CTL, 0x33 };
591 static u8 capt_range_cfg[] = { CAPT_RANGE, 0x32 };
592
593 mt352_write(fe, clock_config, sizeof(clock_config));
594 udelay(200);
595 mt352_write(fe, reset, sizeof(reset));
596 mt352_write(fe, adc_ctl_1_cfg, sizeof(adc_ctl_1_cfg));
597
598 mt352_write(fe, agc_cfg, sizeof(agc_cfg));
599 mt352_write(fe, gpp_ctl_cfg, sizeof(gpp_ctl_cfg));
600 mt352_write(fe, capt_range_cfg, sizeof(capt_range_cfg));
601 return 0;
602}
603
604static struct cx22702_config cxusb_cx22702_config = {
605 .demod_address = 0x63,
606 .output_mode = CX22702_PARALLEL_OUTPUT,
607};
608
609static struct lgdt330x_config cxusb_lgdt3303_config = {
610 .demod_chip = LGDT3303,
611};
612
613static struct lgdt330x_config cxusb_aver_lgdt3303_config = {
614 .demod_chip = LGDT3303,
615 .clock_polarity_flip = 2,
616};
617
618static struct mt352_config cxusb_dee1601_config = {
619 .demod_address = 0x0f,
620 .demod_init = cxusb_dee1601_demod_init,
621};
622
623static struct zl10353_config cxusb_zl10353_dee1601_config = {
624 .demod_address = 0x0f,
625 .parallel_ts = 1,
626};
627
628static struct mt352_config cxusb_mt352_config = {
629
630 .demod_address = 0x0f,
631 .demod_init = cxusb_mt352_demod_init,
632};
633
634static struct zl10353_config cxusb_zl10353_xc3028_config = {
635 .demod_address = 0x0f,
636 .if2 = 45600,
637 .no_tuner = 1,
638 .parallel_ts = 1,
639};
640
641static struct zl10353_config cxusb_zl10353_xc3028_config_no_i2c_gate = {
642 .demod_address = 0x0f,
643 .if2 = 45600,
644 .no_tuner = 1,
645 .parallel_ts = 1,
646 .disable_i2c_gate_ctrl = 1,
647};
648
649static struct mt352_config cxusb_mt352_xc3028_config = {
650 .demod_address = 0x0f,
651 .if2 = 4560,
652 .no_tuner = 1,
653 .demod_init = cxusb_mt352_demod_init,
654};
655
656
657static struct mxl5005s_config aver_a868r_tuner = {
658 .i2c_address = 0x63,
659 .if_freq = 6000000UL,
660 .xtal_freq = CRYSTAL_FREQ_16000000HZ,
661 .agc_mode = MXL_SINGLE_AGC,
662 .tracking_filter = MXL_TF_C,
663 .rssi_enable = MXL_RSSI_ENABLE,
664 .cap_select = MXL_CAP_SEL_ENABLE,
665 .div_out = MXL_DIV_OUT_4,
666 .clock_out = MXL_CLOCK_OUT_DISABLE,
667 .output_load = MXL5005S_IF_OUTPUT_LOAD_200_OHM,
668 .top = MXL5005S_TOP_25P2,
669 .mod_mode = MXL_DIGITAL_MODE,
670 .if_mode = MXL_ZERO_IF,
671 .AgcMasterByte = 0x00,
672};
673
674
675static struct mxl5005s_config d680_dmb_tuner = {
676 .i2c_address = 0x63,
677 .if_freq = 36125000UL,
678 .xtal_freq = CRYSTAL_FREQ_16000000HZ,
679 .agc_mode = MXL_SINGLE_AGC,
680 .tracking_filter = MXL_TF_C,
681 .rssi_enable = MXL_RSSI_ENABLE,
682 .cap_select = MXL_CAP_SEL_ENABLE,
683 .div_out = MXL_DIV_OUT_4,
684 .clock_out = MXL_CLOCK_OUT_DISABLE,
685 .output_load = MXL5005S_IF_OUTPUT_LOAD_200_OHM,
686 .top = MXL5005S_TOP_25P2,
687 .mod_mode = MXL_DIGITAL_MODE,
688 .if_mode = MXL_ZERO_IF,
689 .AgcMasterByte = 0x00,
690};
691
692static struct max2165_config mygica_d689_max2165_cfg = {
693 .i2c_address = 0x60,
694 .osc_clk = 20
695};
696
697
698static int cxusb_fmd1216me_tuner_attach(struct dvb_usb_adapter *adap)
699{
700 struct dvb_usb_device *dvbdev = adap->dev;
701 bool is_medion = dvbdev->props.devices[0].warm_ids[0] ==
702 &cxusb_table[MEDION_MD95700];
703
704 dvb_attach(simple_tuner_attach, adap->fe_adap[0].fe,
705 &dvbdev->i2c_adap, 0x61,
706 TUNER_PHILIPS_FMD1216ME_MK3);
707
708 if (is_medion && adap->fe_adap[0].fe)
709
710
711
712
713 adap->fe_adap[0].fe->ops.tuner_ops.sleep = NULL;
714
715 return 0;
716}
717
718static int cxusb_dee1601_tuner_attach(struct dvb_usb_adapter *adap)
719{
720 dvb_attach(dvb_pll_attach, adap->fe_adap[0].fe, 0x61,
721 NULL, DVB_PLL_THOMSON_DTT7579);
722 return 0;
723}
724
725static int cxusb_lgz201_tuner_attach(struct dvb_usb_adapter *adap)
726{
727 dvb_attach(dvb_pll_attach, adap->fe_adap[0].fe, 0x61,
728 NULL, DVB_PLL_LG_Z201);
729 return 0;
730}
731
732static int cxusb_dtt7579_tuner_attach(struct dvb_usb_adapter *adap)
733{
734 dvb_attach(dvb_pll_attach, adap->fe_adap[0].fe, 0x60,
735 NULL, DVB_PLL_THOMSON_DTT7579);
736 return 0;
737}
738
739static int cxusb_lgh064f_tuner_attach(struct dvb_usb_adapter *adap)
740{
741 dvb_attach(simple_tuner_attach, adap->fe_adap[0].fe,
742 &adap->dev->i2c_adap, 0x61, TUNER_LG_TDVS_H06XF);
743 return 0;
744}
745
746static int dvico_bluebird_xc2028_callback(void *ptr, int component,
747 int command, int arg)
748{
749 struct dvb_usb_adapter *adap = ptr;
750 struct dvb_usb_device *d = adap->dev;
751
752 switch (command) {
753 case XC2028_TUNER_RESET:
754 dev_info(&d->udev->dev, "XC2028_TUNER_RESET %d\n", arg);
755 cxusb_bluebird_gpio_pulse(d, 0x01, 1);
756 break;
757 case XC2028_RESET_CLK:
758 dev_info(&d->udev->dev, "XC2028_RESET_CLK %d\n", arg);
759 break;
760 case XC2028_I2C_FLUSH:
761 break;
762 default:
763 dev_info(&d->udev->dev, "unknown command %d, arg %d\n",
764 command, arg);
765 return -EINVAL;
766 }
767
768 return 0;
769}
770
771static int cxusb_dvico_xc3028_tuner_attach(struct dvb_usb_adapter *adap)
772{
773 struct dvb_frontend *fe;
774 struct xc2028_config cfg = {
775 .i2c_adap = &adap->dev->i2c_adap,
776 .i2c_addr = 0x61,
777 };
778 static struct xc2028_ctrl ctl = {
779 .fname = XC2028_DEFAULT_FIRMWARE,
780 .max_len = 64,
781 .demod = XC3028_FE_ZARLINK456,
782 };
783
784
785 adap->fe_adap[0].fe->callback = dvico_bluebird_xc2028_callback;
786
787 fe = dvb_attach(xc2028_attach, adap->fe_adap[0].fe, &cfg);
788 if (!fe || !fe->ops.tuner_ops.set_config)
789 return -EIO;
790
791 fe->ops.tuner_ops.set_config(fe, &ctl);
792
793 return 0;
794}
795
796static int cxusb_mxl5003s_tuner_attach(struct dvb_usb_adapter *adap)
797{
798 dvb_attach(mxl5005s_attach, adap->fe_adap[0].fe,
799 &adap->dev->i2c_adap, &aver_a868r_tuner);
800 return 0;
801}
802
803static int cxusb_d680_dmb_tuner_attach(struct dvb_usb_adapter *adap)
804{
805 struct dvb_frontend *fe;
806
807 fe = dvb_attach(mxl5005s_attach, adap->fe_adap[0].fe,
808 &adap->dev->i2c_adap, &d680_dmb_tuner);
809 return (!fe) ? -EIO : 0;
810}
811
812static int cxusb_mygica_d689_tuner_attach(struct dvb_usb_adapter *adap)
813{
814 struct dvb_frontend *fe;
815
816 fe = dvb_attach(max2165_attach, adap->fe_adap[0].fe,
817 &adap->dev->i2c_adap, &mygica_d689_max2165_cfg);
818 return (!fe) ? -EIO : 0;
819}
820
821static int cxusb_medion_fe_ts_bus_ctrl(struct dvb_frontend *fe, int acquire)
822{
823 struct dvb_usb_adapter *adap = fe->dvb->priv;
824 struct dvb_usb_device *dvbdev = adap->dev;
825
826 if (acquire)
827 return cxusb_medion_get(dvbdev, CXUSB_OPEN_DIGITAL);
828
829 cxusb_medion_put(dvbdev);
830
831 return 0;
832}
833
834static int cxusb_medion_set_mode(struct dvb_usb_device *dvbdev, bool digital)
835{
836 struct cxusb_state *st = dvbdev->priv;
837 int ret;
838 u8 b;
839 unsigned int i;
840
841
842
843
844
845 mutex_lock(&dvbdev->i2c_mutex);
846
847 if (digital) {
848 ret = usb_set_interface(dvbdev->udev, 0, 6);
849 if (ret != 0) {
850 dev_err(&dvbdev->udev->dev,
851 "digital interface selection failed (%d)\n",
852 ret);
853 goto ret_unlock;
854 }
855 } else {
856 ret = usb_set_interface(dvbdev->udev, 0, 1);
857 if (ret != 0) {
858 dev_err(&dvbdev->udev->dev,
859 "analog interface selection failed (%d)\n",
860 ret);
861 goto ret_unlock;
862 }
863 }
864
865
866 ret = usb_clear_halt(dvbdev->udev, usb_rcvbulkpipe(dvbdev->udev, 1));
867 if (ret != 0)
868 dev_warn(&dvbdev->udev->dev,
869 "clear halt on IN pipe failed (%d)\n",
870 ret);
871
872 ret = usb_clear_halt(dvbdev->udev, usb_sndbulkpipe(dvbdev->udev, 1));
873 if (ret != 0)
874 dev_warn(&dvbdev->udev->dev,
875 "clear halt on OUT pipe failed (%d)\n",
876 ret);
877
878 ret = cxusb_ctrl_msg(dvbdev, digital ? CMD_DIGITAL : CMD_ANALOG,
879 NULL, 0, &b, 1);
880 if (ret != 0) {
881 dev_err(&dvbdev->udev->dev, "mode switch failed (%d)\n",
882 ret);
883 goto ret_unlock;
884 }
885
886
887 for (i = 0; i < ARRAY_SIZE(st->gpio_write_refresh); i++)
888 st->gpio_write_refresh[i] = true;
889
890ret_unlock:
891 mutex_unlock(&dvbdev->i2c_mutex);
892
893 return ret;
894}
895
896static int cxusb_cx22702_frontend_attach(struct dvb_usb_adapter *adap)
897{
898 struct dvb_usb_device *dvbdev = adap->dev;
899 bool is_medion = dvbdev->props.devices[0].warm_ids[0] ==
900 &cxusb_table[MEDION_MD95700];
901
902 if (is_medion) {
903 int ret;
904
905 ret = cxusb_medion_set_mode(dvbdev, true);
906 if (ret)
907 return ret;
908 }
909
910 adap->fe_adap[0].fe = dvb_attach(cx22702_attach, &cxusb_cx22702_config,
911 &dvbdev->i2c_adap);
912 if (!adap->fe_adap[0].fe)
913 return -EIO;
914
915 if (is_medion)
916 adap->fe_adap[0].fe->ops.ts_bus_ctrl =
917 cxusb_medion_fe_ts_bus_ctrl;
918
919 return 0;
920}
921
922static int cxusb_lgdt3303_frontend_attach(struct dvb_usb_adapter *adap)
923{
924 if (usb_set_interface(adap->dev->udev, 0, 7) < 0)
925 err("set interface failed");
926
927 cxusb_ctrl_msg(adap->dev, CMD_DIGITAL, NULL, 0, NULL, 0);
928
929 adap->fe_adap[0].fe = dvb_attach(lgdt330x_attach,
930 &cxusb_lgdt3303_config,
931 0x0e,
932 &adap->dev->i2c_adap);
933 if (adap->fe_adap[0].fe)
934 return 0;
935
936 return -EIO;
937}
938
939static int cxusb_aver_lgdt3303_frontend_attach(struct dvb_usb_adapter *adap)
940{
941 adap->fe_adap[0].fe = dvb_attach(lgdt330x_attach,
942 &cxusb_aver_lgdt3303_config,
943 0x0e,
944 &adap->dev->i2c_adap);
945 if (adap->fe_adap[0].fe)
946 return 0;
947
948 return -EIO;
949}
950
951static int cxusb_mt352_frontend_attach(struct dvb_usb_adapter *adap)
952{
953
954 if (usb_set_interface(adap->dev->udev, 0, 0) < 0)
955 err("set interface failed");
956
957 cxusb_ctrl_msg(adap->dev, CMD_DIGITAL, NULL, 0, NULL, 0);
958
959 adap->fe_adap[0].fe = dvb_attach(mt352_attach, &cxusb_mt352_config,
960 &adap->dev->i2c_adap);
961 if (adap->fe_adap[0].fe)
962 return 0;
963
964 return -EIO;
965}
966
967static int cxusb_dee1601_frontend_attach(struct dvb_usb_adapter *adap)
968{
969 if (usb_set_interface(adap->dev->udev, 0, 0) < 0)
970 err("set interface failed");
971
972 cxusb_ctrl_msg(adap->dev, CMD_DIGITAL, NULL, 0, NULL, 0);
973
974 adap->fe_adap[0].fe = dvb_attach(mt352_attach, &cxusb_dee1601_config,
975 &adap->dev->i2c_adap);
976 if (adap->fe_adap[0].fe)
977 return 0;
978
979 adap->fe_adap[0].fe = dvb_attach(zl10353_attach,
980 &cxusb_zl10353_dee1601_config,
981 &adap->dev->i2c_adap);
982 if (adap->fe_adap[0].fe)
983 return 0;
984
985 return -EIO;
986}
987
988static int cxusb_dualdig4_frontend_attach(struct dvb_usb_adapter *adap)
989{
990 u8 ircode[4];
991 int i;
992 struct i2c_msg msg = {
993 .addr = 0x6b,
994 .flags = I2C_M_RD,
995 .buf = ircode,
996 .len = 4
997 };
998
999 if (usb_set_interface(adap->dev->udev, 0, 1) < 0)
1000 err("set interface failed");
1001
1002 cxusb_ctrl_msg(adap->dev, CMD_DIGITAL, NULL, 0, NULL, 0);
1003
1004
1005 cxusb_bluebird_gpio_rw(adap->dev, 0x04, 0);
1006 cxusb_bluebird_gpio_pulse(adap->dev, 0x01, 1);
1007 cxusb_bluebird_gpio_pulse(adap->dev, 0x02, 1);
1008
1009 adap->fe_adap[0].fe =
1010 dvb_attach(zl10353_attach,
1011 &cxusb_zl10353_xc3028_config_no_i2c_gate,
1012 &adap->dev->i2c_adap);
1013 if (!adap->fe_adap[0].fe)
1014 return -EIO;
1015
1016
1017 for (i = 0; adap->dev->props.rc.core.rc_codes && i < 5; i++) {
1018 msleep(20);
1019 if (cxusb_i2c_xfer(&adap->dev->i2c_adap, &msg, 1) != 1)
1020 goto no_IR;
1021 if (ircode[0] == 0 && ircode[1] == 0)
1022 continue;
1023 if (ircode[2] + ircode[3] != 0xff) {
1024no_IR:
1025 adap->dev->props.rc.core.rc_codes = NULL;
1026 info("No IR receiver detected on this device.");
1027 break;
1028 }
1029 }
1030
1031 return 0;
1032}
1033
1034static struct dibx000_agc_config dib7070_agc_config = {
1035 .band_caps = BAND_UHF | BAND_VHF | BAND_LBAND | BAND_SBAND,
1036
1037
1038
1039
1040
1041
1042 .setup = (0 << 15) | (0 << 14) | (5 << 11) | (0 << 10) | (0 << 9) |
1043 (0 << 8) | (3 << 5) | (0 << 4) | (5 << 1) | (0 << 0),
1044 .inv_gain = 600,
1045 .time_stabiliz = 10,
1046 .alpha_level = 0,
1047 .thlock = 118,
1048 .wbd_inv = 0,
1049 .wbd_ref = 3530,
1050 .wbd_sel = 1,
1051 .wbd_alpha = 5,
1052 .agc1_max = 65535,
1053 .agc1_min = 0,
1054 .agc2_max = 65535,
1055 .agc2_min = 0,
1056 .agc1_pt1 = 0,
1057 .agc1_pt2 = 40,
1058 .agc1_pt3 = 183,
1059 .agc1_slope1 = 206,
1060 .agc1_slope2 = 255,
1061 .agc2_pt1 = 72,
1062 .agc2_pt2 = 152,
1063 .agc2_slope1 = 88,
1064 .agc2_slope2 = 90,
1065 .alpha_mant = 17,
1066 .alpha_exp = 27,
1067 .beta_mant = 23,
1068 .beta_exp = 51,
1069 .perform_agc_softsplit = 0,
1070};
1071
1072static struct dibx000_bandwidth_config dib7070_bw_config_12_mhz = {
1073 .internal = 60000,
1074 .sampling = 15000,
1075 .pll_prediv = 1,
1076 .pll_ratio = 20,
1077 .pll_range = 3,
1078 .pll_reset = 1,
1079 .pll_bypass = 0,
1080 .enable_refdiv = 0,
1081 .bypclk_div = 0,
1082 .IO_CLK_en_core = 1,
1083 .ADClkSrc = 1,
1084 .modulo = 2,
1085
1086 .sad_cfg = (3 << 14) | (1 << 12) | (524 << 0),
1087 .ifreq = (0 << 25) | 0,
1088 .timf = 20452225,
1089 .xtal_hz = 12000000,
1090};
1091
1092static struct dib7000p_config cxusb_dualdig4_rev2_config = {
1093 .output_mode = OUTMODE_MPEG2_PAR_GATED_CLK,
1094 .output_mpeg2_in_188_bytes = 1,
1095
1096 .agc_config_count = 1,
1097 .agc = &dib7070_agc_config,
1098 .bw = &dib7070_bw_config_12_mhz,
1099 .tuner_is_baseband = 1,
1100 .spur_protect = 1,
1101
1102 .gpio_dir = 0xfcef,
1103 .gpio_val = 0x0110,
1104
1105 .gpio_pwm_pos = DIB7000P_GPIO_DEFAULT_PWM_POS,
1106
1107 .hostbus_diversity = 1,
1108};
1109
1110struct dib0700_adapter_state {
1111 int (*set_param_save)(struct dvb_frontend *fe);
1112 struct dib7000p_ops dib7000p_ops;
1113};
1114
1115static int cxusb_dualdig4_rev2_frontend_attach(struct dvb_usb_adapter *adap)
1116{
1117 struct dib0700_adapter_state *state = adap->priv;
1118
1119 if (usb_set_interface(adap->dev->udev, 0, 1) < 0)
1120 err("set interface failed");
1121
1122 cxusb_ctrl_msg(adap->dev, CMD_DIGITAL, NULL, 0, NULL, 0);
1123
1124 cxusb_bluebird_gpio_pulse(adap->dev, 0x02, 1);
1125
1126 if (!dvb_attach(dib7000p_attach, &state->dib7000p_ops))
1127 return -ENODEV;
1128
1129 if (state->dib7000p_ops.i2c_enumeration(&adap->dev->i2c_adap, 1, 18,
1130 &cxusb_dualdig4_rev2_config) < 0) {
1131 pr_warn("Unable to enumerate dib7000p\n");
1132 return -ENODEV;
1133 }
1134
1135 adap->fe_adap[0].fe = state->dib7000p_ops.init(&adap->dev->i2c_adap,
1136 0x80,
1137 &cxusb_dualdig4_rev2_config);
1138 if (!adap->fe_adap[0].fe)
1139 return -EIO;
1140
1141 return 0;
1142}
1143
1144static int dib7070_tuner_reset(struct dvb_frontend *fe, int onoff)
1145{
1146 struct dvb_usb_adapter *adap = fe->dvb->priv;
1147 struct dib0700_adapter_state *state = adap->priv;
1148
1149 return state->dib7000p_ops.set_gpio(fe, 8, 0, !onoff);
1150}
1151
1152static int dib7070_tuner_sleep(struct dvb_frontend *fe, int onoff)
1153{
1154 return 0;
1155}
1156
1157static struct dib0070_config dib7070p_dib0070_config = {
1158 .i2c_address = DEFAULT_DIB0070_I2C_ADDRESS,
1159 .reset = dib7070_tuner_reset,
1160 .sleep = dib7070_tuner_sleep,
1161 .clock_khz = 12000,
1162};
1163
1164static int dib7070_set_param_override(struct dvb_frontend *fe)
1165{
1166 struct dtv_frontend_properties *p = &fe->dtv_property_cache;
1167 struct dvb_usb_adapter *adap = fe->dvb->priv;
1168 struct dib0700_adapter_state *state = adap->priv;
1169
1170 u16 offset;
1171 u8 band = BAND_OF_FREQUENCY(p->frequency / 1000);
1172
1173 switch (band) {
1174 case BAND_VHF:
1175 offset = 950;
1176 break;
1177 default:
1178 case BAND_UHF:
1179 offset = 550;
1180 break;
1181 }
1182
1183 state->dib7000p_ops.set_wbd_ref(fe, offset + dib0070_wbd_offset(fe));
1184
1185 return state->set_param_save(fe);
1186}
1187
1188static int cxusb_dualdig4_rev2_tuner_attach(struct dvb_usb_adapter *adap)
1189{
1190 struct dib0700_adapter_state *st = adap->priv;
1191 struct i2c_adapter *tun_i2c;
1192
1193
1194
1195
1196
1197
1198 tun_i2c = st->dib7000p_ops.get_i2c_master(adap->fe_adap[0].fe,
1199 DIBX000_I2C_INTERFACE_TUNER, 1);
1200
1201 if (dvb_attach(dib0070_attach, adap->fe_adap[0].fe, tun_i2c,
1202 &dib7070p_dib0070_config) == NULL)
1203 return -ENODEV;
1204
1205 st->set_param_save = adap->fe_adap[0].fe->ops.tuner_ops.set_params;
1206 adap->fe_adap[0].fe->ops.tuner_ops.set_params = dib7070_set_param_override;
1207 return 0;
1208}
1209
1210static int cxusb_nano2_frontend_attach(struct dvb_usb_adapter *adap)
1211{
1212 if (usb_set_interface(adap->dev->udev, 0, 1) < 0)
1213 err("set interface failed");
1214
1215 cxusb_ctrl_msg(adap->dev, CMD_DIGITAL, NULL, 0, NULL, 0);
1216
1217
1218 cxusb_bluebird_gpio_rw(adap->dev, 0x04, 0);
1219 cxusb_bluebird_gpio_pulse(adap->dev, 0x01, 1);
1220 cxusb_bluebird_gpio_pulse(adap->dev, 0x02, 1);
1221
1222 adap->fe_adap[0].fe = dvb_attach(zl10353_attach,
1223 &cxusb_zl10353_xc3028_config,
1224 &adap->dev->i2c_adap);
1225 if (adap->fe_adap[0].fe)
1226 return 0;
1227
1228 adap->fe_adap[0].fe = dvb_attach(mt352_attach,
1229 &cxusb_mt352_xc3028_config,
1230 &adap->dev->i2c_adap);
1231 if (adap->fe_adap[0].fe)
1232 return 0;
1233
1234 return -EIO;
1235}
1236
1237static struct lgs8gxx_config d680_lgs8gl5_cfg = {
1238 .prod = LGS8GXX_PROD_LGS8GL5,
1239 .demod_address = 0x19,
1240 .serial_ts = 0,
1241 .ts_clk_pol = 0,
1242 .ts_clk_gated = 1,
1243 .if_clk_freq = 30400,
1244 .if_freq = 5725,
1245 .if_neg_center = 0,
1246 .ext_adc = 0,
1247 .adc_signed = 0,
1248 .if_neg_edge = 0,
1249};
1250
1251static int cxusb_d680_dmb_frontend_attach(struct dvb_usb_adapter *adap)
1252{
1253 struct dvb_usb_device *d = adap->dev;
1254 int n;
1255
1256
1257 if (usb_set_interface(d->udev, 0, 0) < 0)
1258 err("set interface failed");
1259
1260
1261 usb_clear_halt(d->udev,
1262 usb_sndbulkpipe(d->udev,
1263 d->props.generic_bulk_ctrl_endpoint));
1264 usb_clear_halt(d->udev,
1265 usb_rcvbulkpipe(d->udev,
1266 d->props.generic_bulk_ctrl_endpoint));
1267 usb_clear_halt(d->udev,
1268 usb_rcvbulkpipe(d->udev,
1269 d->props.adapter[0].fe[0].stream.endpoint));
1270
1271
1272 for (n = 0; n < 5; n++) {
1273 cxusb_d680_dmb_drain_message(d);
1274 cxusb_d680_dmb_drain_video(d);
1275 msleep(200);
1276 }
1277
1278
1279 if (cxusb_d680_dmb_gpio_tuner(d, 0x07, 0) < 0) {
1280 err("clear tuner gpio failed");
1281 return -EIO;
1282 }
1283 msleep(100);
1284 if (cxusb_d680_dmb_gpio_tuner(d, 0x07, 1) < 0) {
1285 err("set tuner gpio failed");
1286 return -EIO;
1287 }
1288 msleep(100);
1289
1290
1291 adap->fe_adap[0].fe = dvb_attach(lgs8gxx_attach,
1292 &d680_lgs8gl5_cfg, &d->i2c_adap);
1293 if (!adap->fe_adap[0].fe)
1294 return -EIO;
1295
1296 return 0;
1297}
1298
1299static struct atbm8830_config mygica_d689_atbm8830_cfg = {
1300 .prod = ATBM8830_PROD_8830,
1301 .demod_address = 0x40,
1302 .serial_ts = 0,
1303 .ts_sampling_edge = 1,
1304 .ts_clk_gated = 0,
1305 .osc_clk_freq = 30400,
1306 .if_freq = 0,
1307 .zif_swap_iq = 1,
1308 .agc_min = 0x2E,
1309 .agc_max = 0x90,
1310 .agc_hold_loop = 0,
1311};
1312
1313static int cxusb_mygica_d689_frontend_attach(struct dvb_usb_adapter *adap)
1314{
1315 struct dvb_usb_device *d = adap->dev;
1316
1317
1318 if (usb_set_interface(d->udev, 0, 0) < 0)
1319 err("set interface failed");
1320
1321
1322 usb_clear_halt(d->udev,
1323 usb_sndbulkpipe(d->udev,
1324 d->props.generic_bulk_ctrl_endpoint));
1325 usb_clear_halt(d->udev,
1326 usb_rcvbulkpipe(d->udev,
1327 d->props.generic_bulk_ctrl_endpoint));
1328 usb_clear_halt(d->udev,
1329 usb_rcvbulkpipe(d->udev,
1330 d->props.adapter[0].fe[0].stream.endpoint));
1331
1332
1333 if (cxusb_d680_dmb_gpio_tuner(d, 0x07, 0) < 0) {
1334 err("clear tuner gpio failed");
1335 return -EIO;
1336 }
1337 msleep(100);
1338 if (cxusb_d680_dmb_gpio_tuner(d, 0x07, 1) < 0) {
1339 err("set tuner gpio failed");
1340 return -EIO;
1341 }
1342 msleep(100);
1343
1344
1345 adap->fe_adap[0].fe = dvb_attach(atbm8830_attach,
1346 &mygica_d689_atbm8830_cfg,
1347 &d->i2c_adap);
1348 if (!adap->fe_adap[0].fe)
1349 return -EIO;
1350
1351 return 0;
1352}
1353
1354
1355
1356
1357
1358
1359
1360static int bluebird_fx2_identify_state(struct usb_device *udev,
1361 const struct dvb_usb_device_properties *props,
1362 const struct dvb_usb_device_description **desc,
1363 int *cold)
1364{
1365 int wascold = *cold;
1366
1367 *cold = udev->descriptor.bDeviceClass == 0xff &&
1368 udev->descriptor.bDeviceSubClass == 0xff &&
1369 udev->descriptor.bDeviceProtocol == 0xff;
1370
1371 if (*cold && !wascold)
1372 *desc = NULL;
1373
1374 return 0;
1375}
1376
1377
1378
1379
1380
1381
1382static const int dvico_firmware_id_offsets[] = { 6638, 3204 };
1383static int bluebird_patch_dvico_firmware_download(struct usb_device *udev,
1384 const struct firmware *fw)
1385{
1386 int pos;
1387
1388 for (pos = 0; pos < ARRAY_SIZE(dvico_firmware_id_offsets); pos++) {
1389 int idoff = dvico_firmware_id_offsets[pos];
1390
1391 if (fw->size < idoff + 4)
1392 continue;
1393
1394 if (fw->data[idoff] == (USB_VID_DVICO & 0xff) &&
1395 fw->data[idoff + 1] == USB_VID_DVICO >> 8) {
1396 struct firmware new_fw;
1397 u8 *new_fw_data = vmalloc(fw->size);
1398 int ret;
1399
1400 if (!new_fw_data)
1401 return -ENOMEM;
1402
1403 memcpy(new_fw_data, fw->data, fw->size);
1404 new_fw.size = fw->size;
1405 new_fw.data = new_fw_data;
1406
1407 new_fw_data[idoff + 2] =
1408 le16_to_cpu(udev->descriptor.idProduct) + 1;
1409 new_fw_data[idoff + 3] =
1410 le16_to_cpu(udev->descriptor.idProduct) >> 8;
1411
1412 ret = usb_cypress_load_firmware(udev, &new_fw,
1413 CYPRESS_FX2);
1414 vfree(new_fw_data);
1415 return ret;
1416 }
1417 }
1418
1419 return -EINVAL;
1420}
1421
1422int cxusb_medion_get(struct dvb_usb_device *dvbdev,
1423 enum cxusb_open_type open_type)
1424{
1425 struct cxusb_medion_dev *cxdev = dvbdev->priv;
1426 int ret = 0;
1427
1428 mutex_lock(&cxdev->open_lock);
1429
1430 if (WARN_ON((cxdev->open_type == CXUSB_OPEN_INIT ||
1431 cxdev->open_type == CXUSB_OPEN_NONE) &&
1432 cxdev->open_ctr != 0)) {
1433 ret = -EINVAL;
1434 goto ret_unlock;
1435 }
1436
1437 if (cxdev->open_type == CXUSB_OPEN_INIT) {
1438 ret = -EAGAIN;
1439 goto ret_unlock;
1440 }
1441
1442 if (cxdev->open_ctr == 0) {
1443 if (cxdev->open_type != open_type) {
1444 dev_info(&dvbdev->udev->dev, "will acquire and switch to %s\n",
1445 open_type == CXUSB_OPEN_ANALOG ?
1446 "analog" : "digital");
1447
1448 if (open_type == CXUSB_OPEN_ANALOG) {
1449 ret = _cxusb_power_ctrl(dvbdev, 1);
1450 if (ret != 0)
1451 dev_warn(&dvbdev->udev->dev,
1452 "powerup for analog switch failed (%d)\n",
1453 ret);
1454
1455 ret = cxusb_medion_set_mode(dvbdev, false);
1456 if (ret != 0)
1457 goto ret_unlock;
1458
1459 ret = cxusb_medion_analog_init(dvbdev);
1460 if (ret != 0)
1461 goto ret_unlock;
1462 } else {
1463 ret = _cxusb_power_ctrl(dvbdev, 1);
1464 if (ret != 0)
1465 dev_warn(&dvbdev->udev->dev,
1466 "powerup for digital switch failed (%d)\n",
1467 ret);
1468
1469 ret = cxusb_medion_set_mode(dvbdev, true);
1470 if (ret != 0)
1471 goto ret_unlock;
1472 }
1473
1474 cxdev->open_type = open_type;
1475 } else {
1476 dev_info(&dvbdev->udev->dev, "reacquired idle %s\n",
1477 open_type == CXUSB_OPEN_ANALOG ?
1478 "analog" : "digital");
1479 }
1480
1481 cxdev->open_ctr = 1;
1482 } else if (cxdev->open_type == open_type) {
1483 cxdev->open_ctr++;
1484 dev_info(&dvbdev->udev->dev, "acquired %s\n",
1485 open_type == CXUSB_OPEN_ANALOG ? "analog" : "digital");
1486 } else {
1487 ret = -EBUSY;
1488 }
1489
1490ret_unlock:
1491 mutex_unlock(&cxdev->open_lock);
1492
1493 return ret;
1494}
1495
1496void cxusb_medion_put(struct dvb_usb_device *dvbdev)
1497{
1498 struct cxusb_medion_dev *cxdev = dvbdev->priv;
1499
1500 mutex_lock(&cxdev->open_lock);
1501
1502 if (cxdev->open_type == CXUSB_OPEN_INIT) {
1503 WARN_ON(cxdev->open_ctr != 0);
1504 cxdev->open_type = CXUSB_OPEN_NONE;
1505 goto unlock;
1506 }
1507
1508 if (!WARN_ON(cxdev->open_ctr < 1)) {
1509 cxdev->open_ctr--;
1510
1511 dev_info(&dvbdev->udev->dev, "release %s\n",
1512 cxdev->open_type == CXUSB_OPEN_ANALOG ?
1513 "analog" : "digital");
1514 }
1515
1516unlock:
1517 mutex_unlock(&cxdev->open_lock);
1518}
1519
1520
1521static struct dvb_usb_device_properties cxusb_medion_properties;
1522static struct dvb_usb_device_properties cxusb_bluebird_lgh064f_properties;
1523static struct dvb_usb_device_properties cxusb_bluebird_dee1601_properties;
1524static struct dvb_usb_device_properties cxusb_bluebird_lgz201_properties;
1525static struct dvb_usb_device_properties cxusb_bluebird_dtt7579_properties;
1526static struct dvb_usb_device_properties cxusb_bluebird_dualdig4_properties;
1527static struct dvb_usb_device_properties cxusb_bluebird_dualdig4_rev2_properties;
1528static struct dvb_usb_device_properties cxusb_bluebird_nano2_properties;
1529static struct dvb_usb_device_properties cxusb_bluebird_nano2_needsfirmware_properties;
1530static struct dvb_usb_device_properties cxusb_aver_a868r_properties;
1531static struct dvb_usb_device_properties cxusb_d680_dmb_properties;
1532static struct dvb_usb_device_properties cxusb_mygica_d689_properties;
1533
1534static int cxusb_medion_priv_init(struct dvb_usb_device *dvbdev)
1535{
1536 struct cxusb_medion_dev *cxdev = dvbdev->priv;
1537
1538 cxdev->dvbdev = dvbdev;
1539 cxdev->open_type = CXUSB_OPEN_INIT;
1540 mutex_init(&cxdev->open_lock);
1541
1542 return 0;
1543}
1544
1545static void cxusb_medion_priv_destroy(struct dvb_usb_device *dvbdev)
1546{
1547 struct cxusb_medion_dev *cxdev = dvbdev->priv;
1548
1549 mutex_destroy(&cxdev->open_lock);
1550}
1551
1552static bool cxusb_medion_check_altsetting(struct usb_host_interface *as)
1553{
1554 unsigned int ctr;
1555
1556 for (ctr = 0; ctr < as->desc.bNumEndpoints; ctr++) {
1557 if ((as->endpoint[ctr].desc.bEndpointAddress &
1558 USB_ENDPOINT_NUMBER_MASK) != 2)
1559 continue;
1560
1561 if (as->endpoint[ctr].desc.bEndpointAddress & USB_DIR_IN &&
1562 ((as->endpoint[ctr].desc.bmAttributes &
1563 USB_ENDPOINT_XFERTYPE_MASK) == USB_ENDPOINT_XFER_ISOC))
1564 return true;
1565
1566 break;
1567 }
1568
1569 return false;
1570}
1571
1572static bool cxusb_medion_check_intf(struct usb_interface *intf)
1573{
1574 unsigned int ctr;
1575
1576 if (intf->num_altsetting < 2) {
1577 dev_err(intf->usb_dev, "no alternate interface");
1578
1579 return false;
1580 }
1581
1582 for (ctr = 0; ctr < intf->num_altsetting; ctr++) {
1583 if (intf->altsetting[ctr].desc.bAlternateSetting != 1)
1584 continue;
1585
1586 if (cxusb_medion_check_altsetting(&intf->altsetting[ctr]))
1587 return true;
1588
1589 break;
1590 }
1591
1592 dev_err(intf->usb_dev, "no iso interface");
1593
1594 return false;
1595}
1596
1597static int cxusb_probe(struct usb_interface *intf,
1598 const struct usb_device_id *id)
1599{
1600 struct dvb_usb_device *dvbdev;
1601 int ret;
1602
1603
1604 if (!dvb_usb_device_init(intf, &cxusb_medion_properties,
1605 THIS_MODULE, &dvbdev, adapter_nr)) {
1606 if (!cxusb_medion_check_intf(intf)) {
1607 ret = -ENODEV;
1608 goto ret_uninit;
1609 }
1610
1611 _cxusb_power_ctrl(dvbdev, 1);
1612 ret = cxusb_medion_set_mode(dvbdev, false);
1613 if (ret)
1614 goto ret_uninit;
1615
1616 ret = cxusb_medion_register_analog(dvbdev);
1617
1618 cxusb_medion_set_mode(dvbdev, true);
1619 _cxusb_power_ctrl(dvbdev, 0);
1620
1621 if (ret != 0)
1622 goto ret_uninit;
1623
1624
1625 cxusb_medion_put(dvbdev);
1626
1627 return 0;
1628 } else if (!dvb_usb_device_init(intf,
1629 &cxusb_bluebird_lgh064f_properties,
1630 THIS_MODULE, NULL, adapter_nr) ||
1631 !dvb_usb_device_init(intf,
1632 &cxusb_bluebird_dee1601_properties,
1633 THIS_MODULE, NULL, adapter_nr) ||
1634 !dvb_usb_device_init(intf,
1635 &cxusb_bluebird_lgz201_properties,
1636 THIS_MODULE, NULL, adapter_nr) ||
1637 !dvb_usb_device_init(intf,
1638 &cxusb_bluebird_dtt7579_properties,
1639 THIS_MODULE, NULL, adapter_nr) ||
1640 !dvb_usb_device_init(intf,
1641 &cxusb_bluebird_dualdig4_properties,
1642 THIS_MODULE, NULL, adapter_nr) ||
1643 !dvb_usb_device_init(intf,
1644 &cxusb_bluebird_nano2_properties,
1645 THIS_MODULE, NULL, adapter_nr) ||
1646 !dvb_usb_device_init(intf,
1647 &cxusb_bluebird_nano2_needsfirmware_properties,
1648 THIS_MODULE, NULL, adapter_nr) ||
1649 !dvb_usb_device_init(intf, &cxusb_aver_a868r_properties,
1650 THIS_MODULE, NULL, adapter_nr) ||
1651 !dvb_usb_device_init(intf,
1652 &cxusb_bluebird_dualdig4_rev2_properties,
1653 THIS_MODULE, NULL, adapter_nr) ||
1654 !dvb_usb_device_init(intf, &cxusb_d680_dmb_properties,
1655 THIS_MODULE, NULL, adapter_nr) ||
1656 !dvb_usb_device_init(intf, &cxusb_mygica_d689_properties,
1657 THIS_MODULE, NULL, adapter_nr) ||
1658 0)
1659 return 0;
1660
1661 return -EINVAL;
1662
1663ret_uninit:
1664 dvb_usb_device_exit(intf);
1665
1666 return ret;
1667}
1668
1669static void cxusb_disconnect(struct usb_interface *intf)
1670{
1671 struct dvb_usb_device *d = usb_get_intfdata(intf);
1672 struct cxusb_state *st = d->priv;
1673 struct i2c_client *client;
1674
1675 if (d->props.devices[0].warm_ids[0] == &cxusb_table[MEDION_MD95700])
1676 cxusb_medion_unregister_analog(d);
1677
1678
1679 client = st->i2c_client_tuner;
1680 if (client) {
1681 module_put(client->dev.driver->owner);
1682 i2c_unregister_device(client);
1683 }
1684
1685
1686 client = st->i2c_client_demod;
1687 if (client) {
1688 module_put(client->dev.driver->owner);
1689 i2c_unregister_device(client);
1690 }
1691
1692 dvb_usb_device_exit(intf);
1693}
1694
1695static struct usb_device_id cxusb_table[NR__cxusb_table_index + 1] = {
1696 [MEDION_MD95700] = {
1697 USB_DEVICE(USB_VID_MEDION, USB_PID_MEDION_MD95700)
1698 },
1699 [DVICO_BLUEBIRD_LG064F_COLD] = {
1700 USB_DEVICE(USB_VID_DVICO, USB_PID_DVICO_BLUEBIRD_LG064F_COLD)
1701 },
1702 [DVICO_BLUEBIRD_LG064F_WARM] = {
1703 USB_DEVICE(USB_VID_DVICO, USB_PID_DVICO_BLUEBIRD_LG064F_WARM)
1704 },
1705 [DVICO_BLUEBIRD_DUAL_1_COLD] = {
1706 USB_DEVICE(USB_VID_DVICO, USB_PID_DVICO_BLUEBIRD_DUAL_1_COLD)
1707 },
1708 [DVICO_BLUEBIRD_DUAL_1_WARM] = {
1709 USB_DEVICE(USB_VID_DVICO, USB_PID_DVICO_BLUEBIRD_DUAL_1_WARM)
1710 },
1711 [DVICO_BLUEBIRD_LGZ201_COLD] = {
1712 USB_DEVICE(USB_VID_DVICO, USB_PID_DVICO_BLUEBIRD_LGZ201_COLD)
1713 },
1714 [DVICO_BLUEBIRD_LGZ201_WARM] = {
1715 USB_DEVICE(USB_VID_DVICO, USB_PID_DVICO_BLUEBIRD_LGZ201_WARM)
1716 },
1717 [DVICO_BLUEBIRD_TH7579_COLD] = {
1718 USB_DEVICE(USB_VID_DVICO, USB_PID_DVICO_BLUEBIRD_TH7579_COLD)
1719 },
1720 [DVICO_BLUEBIRD_TH7579_WARM] = {
1721 USB_DEVICE(USB_VID_DVICO, USB_PID_DVICO_BLUEBIRD_TH7579_WARM)
1722 },
1723 [DIGITALNOW_BLUEBIRD_DUAL_1_COLD] = {
1724 USB_DEVICE(USB_VID_DVICO,
1725 USB_PID_DIGITALNOW_BLUEBIRD_DUAL_1_COLD)
1726 },
1727 [DIGITALNOW_BLUEBIRD_DUAL_1_WARM] = {
1728 USB_DEVICE(USB_VID_DVICO,
1729 USB_PID_DIGITALNOW_BLUEBIRD_DUAL_1_WARM)
1730 },
1731 [DVICO_BLUEBIRD_DUAL_2_COLD] = {
1732 USB_DEVICE(USB_VID_DVICO, USB_PID_DVICO_BLUEBIRD_DUAL_2_COLD)
1733 },
1734 [DVICO_BLUEBIRD_DUAL_2_WARM] = {
1735 USB_DEVICE(USB_VID_DVICO, USB_PID_DVICO_BLUEBIRD_DUAL_2_WARM)
1736 },
1737 [DVICO_BLUEBIRD_DUAL_4] = {
1738 USB_DEVICE(USB_VID_DVICO, USB_PID_DVICO_BLUEBIRD_DUAL_4)
1739 },
1740 [DVICO_BLUEBIRD_DVB_T_NANO_2] = {
1741 USB_DEVICE(USB_VID_DVICO, USB_PID_DVICO_BLUEBIRD_DVB_T_NANO_2)
1742 },
1743 [DVICO_BLUEBIRD_DVB_T_NANO_2_NFW_WARM] = {
1744 USB_DEVICE(USB_VID_DVICO,
1745 USB_PID_DVICO_BLUEBIRD_DVB_T_NANO_2_NFW_WARM)
1746 },
1747 [AVERMEDIA_VOLAR_A868R] = {
1748 USB_DEVICE(USB_VID_AVERMEDIA, USB_PID_AVERMEDIA_VOLAR_A868R)
1749 },
1750 [DVICO_BLUEBIRD_DUAL_4_REV_2] = {
1751 USB_DEVICE(USB_VID_DVICO, USB_PID_DVICO_BLUEBIRD_DUAL_4_REV_2)
1752 },
1753 [CONEXANT_D680_DMB] = {
1754 USB_DEVICE(USB_VID_CONEXANT, USB_PID_CONEXANT_D680_DMB)
1755 },
1756 [MYGICA_D689] = {
1757 USB_DEVICE(USB_VID_CONEXANT, USB_PID_MYGICA_D689)
1758 },
1759 {}
1760};
1761MODULE_DEVICE_TABLE(usb, cxusb_table);
1762
1763static struct dvb_usb_device_properties cxusb_medion_properties = {
1764 .caps = DVB_USB_IS_AN_I2C_ADAPTER,
1765
1766 .usb_ctrl = CYPRESS_FX2,
1767
1768 .size_of_priv = sizeof(struct cxusb_medion_dev),
1769 .priv_init = cxusb_medion_priv_init,
1770 .priv_destroy = cxusb_medion_priv_destroy,
1771
1772 .num_adapters = 1,
1773 .adapter = {
1774 {
1775 .num_frontends = 1,
1776 .fe = {{
1777 .streaming_ctrl = cxusb_streaming_ctrl,
1778 .frontend_attach = cxusb_cx22702_frontend_attach,
1779 .tuner_attach = cxusb_fmd1216me_tuner_attach,
1780
1781 .stream = {
1782 .type = USB_BULK,
1783 .count = 5,
1784 .endpoint = 0x02,
1785 .u = {
1786 .bulk = {
1787 .buffersize = 8192,
1788 }
1789 }
1790 },
1791 } },
1792 },
1793 },
1794 .power_ctrl = cxusb_power_ctrl,
1795
1796 .i2c_algo = &cxusb_i2c_algo,
1797
1798 .generic_bulk_ctrl_endpoint = 0x01,
1799
1800 .num_device_descs = 1,
1801 .devices = {
1802 {
1803 "Medion MD95700 (MDUSBTV-HYBRID)",
1804 { NULL },
1805 { &cxusb_table[MEDION_MD95700], NULL },
1806 },
1807 }
1808};
1809
1810static struct dvb_usb_device_properties cxusb_bluebird_lgh064f_properties = {
1811 .caps = DVB_USB_IS_AN_I2C_ADAPTER,
1812
1813 .usb_ctrl = DEVICE_SPECIFIC,
1814 .firmware = "dvb-usb-bluebird-01.fw",
1815 .download_firmware = bluebird_patch_dvico_firmware_download,
1816
1817
1818
1819
1820
1821 .size_of_priv = sizeof(struct cxusb_state),
1822
1823 .num_adapters = 1,
1824 .adapter = {
1825 {
1826 .num_frontends = 1,
1827 .fe = {{
1828 .streaming_ctrl = cxusb_streaming_ctrl,
1829 .frontend_attach = cxusb_lgdt3303_frontend_attach,
1830 .tuner_attach = cxusb_lgh064f_tuner_attach,
1831
1832
1833 .stream = {
1834 .type = USB_BULK,
1835 .count = 5,
1836 .endpoint = 0x02,
1837 .u = {
1838 .bulk = {
1839 .buffersize = 8192,
1840 }
1841 }
1842 },
1843 } },
1844 },
1845 },
1846
1847 .power_ctrl = cxusb_bluebird_power_ctrl,
1848
1849 .i2c_algo = &cxusb_i2c_algo,
1850
1851 .rc.core = {
1852 .rc_interval = 100,
1853 .rc_codes = RC_MAP_DVICO_PORTABLE,
1854 .module_name = KBUILD_MODNAME,
1855 .rc_query = cxusb_rc_query,
1856 .allowed_protos = RC_PROTO_BIT_NEC,
1857 },
1858
1859 .generic_bulk_ctrl_endpoint = 0x01,
1860
1861 .num_device_descs = 1,
1862 .devices = {
1863 { "DViCO FusionHDTV5 USB Gold",
1864 { &cxusb_table[DVICO_BLUEBIRD_LG064F_COLD], NULL },
1865 { &cxusb_table[DVICO_BLUEBIRD_LG064F_WARM], NULL },
1866 },
1867 }
1868};
1869
1870static struct dvb_usb_device_properties cxusb_bluebird_dee1601_properties = {
1871 .caps = DVB_USB_IS_AN_I2C_ADAPTER,
1872
1873 .usb_ctrl = DEVICE_SPECIFIC,
1874 .firmware = "dvb-usb-bluebird-01.fw",
1875 .download_firmware = bluebird_patch_dvico_firmware_download,
1876
1877
1878
1879
1880
1881 .size_of_priv = sizeof(struct cxusb_state),
1882
1883 .num_adapters = 1,
1884 .adapter = {
1885 {
1886 .num_frontends = 1,
1887 .fe = {{
1888 .streaming_ctrl = cxusb_streaming_ctrl,
1889 .frontend_attach = cxusb_dee1601_frontend_attach,
1890 .tuner_attach = cxusb_dee1601_tuner_attach,
1891
1892 .stream = {
1893 .type = USB_BULK,
1894 .count = 5,
1895 .endpoint = 0x04,
1896 .u = {
1897 .bulk = {
1898 .buffersize = 8192,
1899 }
1900 }
1901 },
1902 } },
1903 },
1904 },
1905
1906 .power_ctrl = cxusb_bluebird_power_ctrl,
1907
1908 .i2c_algo = &cxusb_i2c_algo,
1909
1910 .rc.core = {
1911 .rc_interval = 100,
1912 .rc_codes = RC_MAP_DVICO_MCE,
1913 .module_name = KBUILD_MODNAME,
1914 .rc_query = cxusb_rc_query,
1915 .allowed_protos = RC_PROTO_BIT_NEC,
1916 },
1917
1918 .generic_bulk_ctrl_endpoint = 0x01,
1919
1920 .num_device_descs = 3,
1921 .devices = {
1922 { "DViCO FusionHDTV DVB-T Dual USB",
1923 { &cxusb_table[DVICO_BLUEBIRD_DUAL_1_COLD], NULL },
1924 { &cxusb_table[DVICO_BLUEBIRD_DUAL_1_WARM], NULL },
1925 },
1926 { "DigitalNow DVB-T Dual USB",
1927 { &cxusb_table[DIGITALNOW_BLUEBIRD_DUAL_1_COLD], NULL },
1928 { &cxusb_table[DIGITALNOW_BLUEBIRD_DUAL_1_WARM], NULL },
1929 },
1930 { "DViCO FusionHDTV DVB-T Dual Digital 2",
1931 { &cxusb_table[DVICO_BLUEBIRD_DUAL_2_COLD], NULL },
1932 { &cxusb_table[DVICO_BLUEBIRD_DUAL_2_WARM], NULL },
1933 },
1934 }
1935};
1936
1937static struct dvb_usb_device_properties cxusb_bluebird_lgz201_properties = {
1938 .caps = DVB_USB_IS_AN_I2C_ADAPTER,
1939
1940 .usb_ctrl = DEVICE_SPECIFIC,
1941 .firmware = "dvb-usb-bluebird-01.fw",
1942 .download_firmware = bluebird_patch_dvico_firmware_download,
1943
1944
1945
1946
1947
1948 .size_of_priv = sizeof(struct cxusb_state),
1949
1950 .num_adapters = 2,
1951 .adapter = {
1952 {
1953 .num_frontends = 1,
1954 .fe = {{
1955 .streaming_ctrl = cxusb_streaming_ctrl,
1956 .frontend_attach = cxusb_mt352_frontend_attach,
1957 .tuner_attach = cxusb_lgz201_tuner_attach,
1958
1959
1960 .stream = {
1961 .type = USB_BULK,
1962 .count = 5,
1963 .endpoint = 0x04,
1964 .u = {
1965 .bulk = {
1966 .buffersize = 8192,
1967 }
1968 }
1969 },
1970 } },
1971 },
1972 },
1973 .power_ctrl = cxusb_bluebird_power_ctrl,
1974
1975 .i2c_algo = &cxusb_i2c_algo,
1976
1977 .rc.core = {
1978 .rc_interval = 100,
1979 .rc_codes = RC_MAP_DVICO_PORTABLE,
1980 .module_name = KBUILD_MODNAME,
1981 .rc_query = cxusb_rc_query,
1982 .allowed_protos = RC_PROTO_BIT_NEC,
1983 },
1984
1985 .generic_bulk_ctrl_endpoint = 0x01,
1986 .num_device_descs = 1,
1987 .devices = {
1988 { "DViCO FusionHDTV DVB-T USB (LGZ201)",
1989 { &cxusb_table[DVICO_BLUEBIRD_LGZ201_COLD], NULL },
1990 { &cxusb_table[DVICO_BLUEBIRD_LGZ201_WARM], NULL },
1991 },
1992 }
1993};
1994
1995static struct dvb_usb_device_properties cxusb_bluebird_dtt7579_properties = {
1996 .caps = DVB_USB_IS_AN_I2C_ADAPTER,
1997
1998 .usb_ctrl = DEVICE_SPECIFIC,
1999 .firmware = "dvb-usb-bluebird-01.fw",
2000 .download_firmware = bluebird_patch_dvico_firmware_download,
2001
2002
2003
2004
2005
2006
2007 .size_of_priv = sizeof(struct cxusb_state),
2008
2009 .num_adapters = 1,
2010 .adapter = {
2011 {
2012 .num_frontends = 1,
2013 .fe = {{
2014 .streaming_ctrl = cxusb_streaming_ctrl,
2015 .frontend_attach = cxusb_mt352_frontend_attach,
2016 .tuner_attach = cxusb_dtt7579_tuner_attach,
2017
2018
2019 .stream = {
2020 .type = USB_BULK,
2021 .count = 5,
2022 .endpoint = 0x04,
2023 .u = {
2024 .bulk = {
2025 .buffersize = 8192,
2026 }
2027 }
2028 },
2029 } },
2030 },
2031 },
2032 .power_ctrl = cxusb_bluebird_power_ctrl,
2033
2034 .i2c_algo = &cxusb_i2c_algo,
2035
2036 .rc.core = {
2037 .rc_interval = 100,
2038 .rc_codes = RC_MAP_DVICO_PORTABLE,
2039 .module_name = KBUILD_MODNAME,
2040 .rc_query = cxusb_rc_query,
2041 .allowed_protos = RC_PROTO_BIT_NEC,
2042 },
2043
2044 .generic_bulk_ctrl_endpoint = 0x01,
2045
2046 .num_device_descs = 1,
2047 .devices = {
2048 { "DViCO FusionHDTV DVB-T USB (TH7579)",
2049 { &cxusb_table[DVICO_BLUEBIRD_TH7579_COLD], NULL },
2050 { &cxusb_table[DVICO_BLUEBIRD_TH7579_WARM], NULL },
2051 },
2052 }
2053};
2054
2055static struct dvb_usb_device_properties cxusb_bluebird_dualdig4_properties = {
2056 .caps = DVB_USB_IS_AN_I2C_ADAPTER,
2057
2058 .usb_ctrl = CYPRESS_FX2,
2059
2060 .size_of_priv = sizeof(struct cxusb_state),
2061
2062 .num_adapters = 1,
2063 .adapter = {
2064 {
2065 .num_frontends = 1,
2066 .fe = {{
2067 .streaming_ctrl = cxusb_streaming_ctrl,
2068 .frontend_attach = cxusb_dualdig4_frontend_attach,
2069 .tuner_attach = cxusb_dvico_xc3028_tuner_attach,
2070
2071 .stream = {
2072 .type = USB_BULK,
2073 .count = 5,
2074 .endpoint = 0x02,
2075 .u = {
2076 .bulk = {
2077 .buffersize = 8192,
2078 }
2079 }
2080 },
2081 } },
2082 },
2083 },
2084
2085 .power_ctrl = cxusb_power_ctrl,
2086
2087 .i2c_algo = &cxusb_i2c_algo,
2088
2089 .generic_bulk_ctrl_endpoint = 0x01,
2090
2091 .rc.core = {
2092 .rc_interval = 100,
2093 .rc_codes = RC_MAP_DVICO_MCE,
2094 .module_name = KBUILD_MODNAME,
2095 .rc_query = cxusb_bluebird2_rc_query,
2096 .allowed_protos = RC_PROTO_BIT_NEC,
2097 },
2098
2099 .num_device_descs = 1,
2100 .devices = {
2101 { "DViCO FusionHDTV DVB-T Dual Digital 4",
2102 { NULL },
2103 { &cxusb_table[DVICO_BLUEBIRD_DUAL_4], NULL },
2104 },
2105 }
2106};
2107
2108static struct dvb_usb_device_properties cxusb_bluebird_nano2_properties = {
2109 .caps = DVB_USB_IS_AN_I2C_ADAPTER,
2110
2111 .usb_ctrl = CYPRESS_FX2,
2112 .identify_state = bluebird_fx2_identify_state,
2113
2114 .size_of_priv = sizeof(struct cxusb_state),
2115
2116 .num_adapters = 1,
2117 .adapter = {
2118 {
2119 .num_frontends = 1,
2120 .fe = {{
2121 .streaming_ctrl = cxusb_streaming_ctrl,
2122 .frontend_attach = cxusb_nano2_frontend_attach,
2123 .tuner_attach = cxusb_dvico_xc3028_tuner_attach,
2124
2125 .stream = {
2126 .type = USB_BULK,
2127 .count = 5,
2128 .endpoint = 0x02,
2129 .u = {
2130 .bulk = {
2131 .buffersize = 8192,
2132 }
2133 }
2134 },
2135 } },
2136 },
2137 },
2138
2139 .power_ctrl = cxusb_nano2_power_ctrl,
2140
2141 .i2c_algo = &cxusb_i2c_algo,
2142
2143 .generic_bulk_ctrl_endpoint = 0x01,
2144
2145 .rc.core = {
2146 .rc_interval = 100,
2147 .rc_codes = RC_MAP_DVICO_PORTABLE,
2148 .module_name = KBUILD_MODNAME,
2149 .rc_query = cxusb_bluebird2_rc_query,
2150 .allowed_protos = RC_PROTO_BIT_NEC,
2151 },
2152
2153 .num_device_descs = 1,
2154 .devices = {
2155 { "DViCO FusionHDTV DVB-T NANO2",
2156 { NULL },
2157 { &cxusb_table[DVICO_BLUEBIRD_DVB_T_NANO_2], NULL },
2158 },
2159 }
2160};
2161
2162static struct dvb_usb_device_properties
2163cxusb_bluebird_nano2_needsfirmware_properties = {
2164 .caps = DVB_USB_IS_AN_I2C_ADAPTER,
2165
2166 .usb_ctrl = DEVICE_SPECIFIC,
2167 .firmware = "dvb-usb-bluebird-02.fw",
2168 .download_firmware = bluebird_patch_dvico_firmware_download,
2169 .identify_state = bluebird_fx2_identify_state,
2170
2171 .size_of_priv = sizeof(struct cxusb_state),
2172
2173 .num_adapters = 1,
2174 .adapter = {
2175 {
2176 .num_frontends = 1,
2177 .fe = {{
2178 .streaming_ctrl = cxusb_streaming_ctrl,
2179 .frontend_attach = cxusb_nano2_frontend_attach,
2180 .tuner_attach = cxusb_dvico_xc3028_tuner_attach,
2181
2182 .stream = {
2183 .type = USB_BULK,
2184 .count = 5,
2185 .endpoint = 0x02,
2186 .u = {
2187 .bulk = {
2188 .buffersize = 8192,
2189 }
2190 }
2191 },
2192 } },
2193 },
2194 },
2195
2196 .power_ctrl = cxusb_nano2_power_ctrl,
2197
2198 .i2c_algo = &cxusb_i2c_algo,
2199
2200 .generic_bulk_ctrl_endpoint = 0x01,
2201
2202 .rc.core = {
2203 .rc_interval = 100,
2204 .rc_codes = RC_MAP_DVICO_PORTABLE,
2205 .module_name = KBUILD_MODNAME,
2206 .rc_query = cxusb_rc_query,
2207 .allowed_protos = RC_PROTO_BIT_NEC,
2208 },
2209
2210 .num_device_descs = 1,
2211 .devices = { {
2212 "DViCO FusionHDTV DVB-T NANO2 w/o firmware",
2213 { &cxusb_table[DVICO_BLUEBIRD_DVB_T_NANO_2], NULL },
2214 { &cxusb_table[DVICO_BLUEBIRD_DVB_T_NANO_2_NFW_WARM],
2215 NULL },
2216 },
2217 }
2218};
2219
2220static struct dvb_usb_device_properties cxusb_aver_a868r_properties = {
2221 .caps = DVB_USB_IS_AN_I2C_ADAPTER,
2222
2223 .usb_ctrl = CYPRESS_FX2,
2224
2225 .size_of_priv = sizeof(struct cxusb_state),
2226
2227 .num_adapters = 1,
2228 .adapter = {
2229 {
2230 .num_frontends = 1,
2231 .fe = {{
2232 .streaming_ctrl = cxusb_aver_streaming_ctrl,
2233 .frontend_attach = cxusb_aver_lgdt3303_frontend_attach,
2234 .tuner_attach = cxusb_mxl5003s_tuner_attach,
2235
2236 .stream = {
2237 .type = USB_BULK,
2238 .count = 5,
2239 .endpoint = 0x04,
2240 .u = {
2241 .bulk = {
2242 .buffersize = 8192,
2243 }
2244 }
2245 },
2246 } },
2247 },
2248 },
2249 .power_ctrl = cxusb_aver_power_ctrl,
2250
2251 .i2c_algo = &cxusb_i2c_algo,
2252
2253 .generic_bulk_ctrl_endpoint = 0x01,
2254
2255 .num_device_descs = 1,
2256 .devices = {
2257 { "AVerMedia AVerTVHD Volar (A868R)",
2258 { NULL },
2259 { &cxusb_table[AVERMEDIA_VOLAR_A868R], NULL },
2260 },
2261 }
2262};
2263
2264static
2265struct dvb_usb_device_properties cxusb_bluebird_dualdig4_rev2_properties = {
2266 .caps = DVB_USB_IS_AN_I2C_ADAPTER,
2267
2268 .usb_ctrl = CYPRESS_FX2,
2269
2270 .size_of_priv = sizeof(struct cxusb_state),
2271
2272 .num_adapters = 1,
2273 .adapter = {
2274 {
2275 .size_of_priv = sizeof(struct dib0700_adapter_state),
2276 .num_frontends = 1,
2277 .fe = {{
2278 .streaming_ctrl = cxusb_streaming_ctrl,
2279 .frontend_attach = cxusb_dualdig4_rev2_frontend_attach,
2280 .tuner_attach = cxusb_dualdig4_rev2_tuner_attach,
2281
2282 .stream = {
2283 .type = USB_BULK,
2284 .count = 7,
2285 .endpoint = 0x02,
2286 .u = {
2287 .bulk = {
2288 .buffersize = 4096,
2289 }
2290 }
2291 },
2292 } },
2293 },
2294 },
2295
2296 .power_ctrl = cxusb_bluebird_power_ctrl,
2297
2298 .i2c_algo = &cxusb_i2c_algo,
2299
2300 .generic_bulk_ctrl_endpoint = 0x01,
2301
2302 .rc.core = {
2303 .rc_interval = 100,
2304 .rc_codes = RC_MAP_DVICO_MCE,
2305 .module_name = KBUILD_MODNAME,
2306 .rc_query = cxusb_rc_query,
2307 .allowed_protos = RC_PROTO_BIT_NEC,
2308 },
2309
2310 .num_device_descs = 1,
2311 .devices = {
2312 { "DViCO FusionHDTV DVB-T Dual Digital 4 (rev 2)",
2313 { NULL },
2314 { &cxusb_table[DVICO_BLUEBIRD_DUAL_4_REV_2], NULL },
2315 },
2316 }
2317};
2318
2319static struct dvb_usb_device_properties cxusb_d680_dmb_properties = {
2320 .caps = DVB_USB_IS_AN_I2C_ADAPTER,
2321
2322 .usb_ctrl = CYPRESS_FX2,
2323
2324 .size_of_priv = sizeof(struct cxusb_state),
2325
2326 .num_adapters = 1,
2327 .adapter = {
2328 {
2329 .num_frontends = 1,
2330 .fe = {{
2331 .streaming_ctrl = cxusb_d680_dmb_streaming_ctrl,
2332 .frontend_attach = cxusb_d680_dmb_frontend_attach,
2333 .tuner_attach = cxusb_d680_dmb_tuner_attach,
2334
2335
2336 .stream = {
2337 .type = USB_BULK,
2338 .count = 5,
2339 .endpoint = 0x02,
2340 .u = {
2341 .bulk = {
2342 .buffersize = 8192,
2343 }
2344 }
2345 },
2346 } },
2347 },
2348 },
2349
2350 .power_ctrl = cxusb_d680_dmb_power_ctrl,
2351
2352 .i2c_algo = &cxusb_i2c_algo,
2353
2354 .generic_bulk_ctrl_endpoint = 0x01,
2355
2356 .rc.core = {
2357 .rc_interval = 100,
2358 .rc_codes = RC_MAP_TOTAL_MEDIA_IN_HAND_02,
2359 .module_name = KBUILD_MODNAME,
2360 .rc_query = cxusb_d680_dmb_rc_query,
2361 .allowed_protos = RC_PROTO_BIT_UNKNOWN,
2362 },
2363
2364 .num_device_descs = 1,
2365 .devices = {
2366 {
2367 "Conexant DMB-TH Stick",
2368 { NULL },
2369 { &cxusb_table[CONEXANT_D680_DMB], NULL },
2370 },
2371 }
2372};
2373
2374static struct dvb_usb_device_properties cxusb_mygica_d689_properties = {
2375 .caps = DVB_USB_IS_AN_I2C_ADAPTER,
2376
2377 .usb_ctrl = CYPRESS_FX2,
2378
2379 .size_of_priv = sizeof(struct cxusb_state),
2380
2381 .num_adapters = 1,
2382 .adapter = {
2383 {
2384 .num_frontends = 1,
2385 .fe = {{
2386 .streaming_ctrl = cxusb_d680_dmb_streaming_ctrl,
2387 .frontend_attach = cxusb_mygica_d689_frontend_attach,
2388 .tuner_attach = cxusb_mygica_d689_tuner_attach,
2389
2390
2391 .stream = {
2392 .type = USB_BULK,
2393 .count = 5,
2394 .endpoint = 0x02,
2395 .u = {
2396 .bulk = {
2397 .buffersize = 8192,
2398 }
2399 }
2400 },
2401 } },
2402 },
2403 },
2404
2405 .power_ctrl = cxusb_d680_dmb_power_ctrl,
2406
2407 .i2c_algo = &cxusb_i2c_algo,
2408
2409 .generic_bulk_ctrl_endpoint = 0x01,
2410
2411 .rc.core = {
2412 .rc_interval = 100,
2413 .rc_codes = RC_MAP_D680_DMB,
2414 .module_name = KBUILD_MODNAME,
2415 .rc_query = cxusb_d680_dmb_rc_query,
2416 .allowed_protos = RC_PROTO_BIT_UNKNOWN,
2417 },
2418
2419 .num_device_descs = 1,
2420 .devices = {
2421 {
2422 "Mygica D689 DMB-TH",
2423 { NULL },
2424 { &cxusb_table[MYGICA_D689], NULL },
2425 },
2426 }
2427};
2428
2429static struct usb_driver cxusb_driver = {
2430 .name = "dvb_usb_cxusb",
2431 .probe = cxusb_probe,
2432 .disconnect = cxusb_disconnect,
2433 .id_table = cxusb_table,
2434};
2435
2436module_usb_driver(cxusb_driver);
2437
2438MODULE_AUTHOR("Patrick Boettcher <patrick.boettcher@posteo.de>");
2439MODULE_AUTHOR("Michael Krufky <mkrufky@linuxtv.org>");
2440MODULE_AUTHOR("Chris Pascoe <c.pascoe@itee.uq.edu.au>");
2441MODULE_AUTHOR("Maciej S. Szmigiero <mail@maciej.szmigiero.name>");
2442MODULE_DESCRIPTION("Driver for Conexant USB2.0 hybrid reference design");
2443MODULE_LICENSE("GPL");
2444