treewide: remove redundant IS_ERR() before error code check
[linux/fpc-iii.git] / drivers / media / usb / dvb-usb / cxusb.c
blobc421b603be44685ac2738e29cd0eea4d0436a94b
1 // SPDX-License-Identifier: GPL-2.0-only
2 /* DVB USB compliant linux driver for Conexant USB reference design.
4 * The Conexant reference design I saw on their website was only for analogue
5 * capturing (using the cx25842). The box I took to write this driver (reverse
6 * engineered) is the one labeled Medion MD95700. In addition to the cx25842
7 * for analogue capturing it also has a cx22702 DVB-T demodulator on the main
8 * board. Besides it has a atiremote (X10) and a USB2.0 hub onboard.
10 * Maybe it is a little bit premature to call this driver cxusb, but I assume
11 * the USB protocol is identical or at least inherited from the reference
12 * design, so it can be reused for the "analogue-only" device (if it will
13 * appear at all).
16 * Copyright (C) 2005 Patrick Boettcher (patrick.boettcher@posteo.de)
17 * Copyright (C) 2006 Michael Krufky (mkrufky@linuxtv.org)
18 * Copyright (C) 2006, 2007 Chris Pascoe (c.pascoe@itee.uq.edu.au)
19 * Copyright (C) 2011, 2017 Maciej S. Szmigiero (mail@maciej.szmigiero.name)
21 * see Documentation/media/dvb-drivers/dvb-usb.rst for more information
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>
31 #include "cxusb.h"
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"
49 /* debug */
50 int dvb_usb_cxusb_debug;
51 module_param_named(debug, dvb_usb_cxusb_debug, int, 0644);
52 MODULE_PARM_DESC(debug, "set debugging level (see cxusb.h)."
53 DVB_USB_DEBUG_STATUS);
55 DVB_DEFINE_MOD_OPT_ADAPTER_NR(adapter_nr);
57 enum 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
81 static struct usb_device_id cxusb_table[];
83 int cxusb_ctrl_msg(struct dvb_usb_device *d,
84 u8 cmd, const u8 *wbuf, int wlen, u8 *rbuf, int rlen)
86 struct cxusb_state *st = d->priv;
87 int ret;
89 if (1 + wlen > MAX_XFER_SIZE) {
90 warn("i2c wr: len=%d is too big!\n", wlen);
91 return -EOPNOTSUPP;
94 if (rlen > MAX_XFER_SIZE) {
95 warn("i2c rd: len=%d is too big!\n", rlen);
96 return -EOPNOTSUPP;
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);
106 mutex_unlock(&d->data_mutex);
107 return ret;
110 /* GPIO */
111 static void cxusb_gpio_tuner(struct dvb_usb_device *d, int onoff)
113 struct cxusb_state *st = d->priv;
114 u8 o[2], i;
116 if (st->gpio_write_state[GPIO_TUNER] == onoff &&
117 !st->gpio_write_refresh[GPIO_TUNER])
118 return;
120 o[0] = GPIO_TUNER;
121 o[1] = onoff;
122 cxusb_ctrl_msg(d, CMD_GPIO_WRITE, o, 2, &i, 1);
124 if (i != 0x01)
125 dev_info(&d->udev->dev, "gpio_write failed.\n");
127 st->gpio_write_state[GPIO_TUNER] = onoff;
128 st->gpio_write_refresh[GPIO_TUNER] = false;
131 static int cxusb_bluebird_gpio_rw(struct dvb_usb_device *d, u8 changemask,
132 u8 newval)
134 u8 o[2], gpio_state;
135 int rc;
137 o[0] = 0xff & ~changemask; /* mask of bits to keep */
138 o[1] = newval & changemask; /* new values for bits */
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");
144 return rc < 0 ? rc : gpio_state;
147 static void cxusb_bluebird_gpio_pulse(struct dvb_usb_device *d, u8 pin, int low)
149 cxusb_bluebird_gpio_rw(d, pin, low ? 0 : pin);
150 msleep(5);
151 cxusb_bluebird_gpio_rw(d, pin, low ? pin : 0);
154 static void cxusb_nano2_led(struct dvb_usb_device *d, int onoff)
156 cxusb_bluebird_gpio_rw(d, 0x40, onoff ? 0 : 0x40);
159 static int cxusb_d680_dmb_gpio_tuner(struct dvb_usb_device *d,
160 u8 addr, int onoff)
162 u8 o[2] = {addr, onoff};
163 u8 i;
164 int rc;
166 rc = cxusb_ctrl_msg(d, CMD_GPIO_WRITE, o, 2, &i, 1);
168 if (rc < 0)
169 return rc;
171 if (i == 0x01)
172 return 0;
174 dev_info(&d->udev->dev, "gpio_write failed.\n");
175 return -EIO;
178 /* I2C */
179 static int cxusb_i2c_xfer(struct i2c_adapter *adap, struct i2c_msg msg[],
180 int num)
182 struct dvb_usb_device *d = i2c_get_adapdata(adap);
183 int ret;
184 int i;
186 if (mutex_lock_interruptible(&d->i2c_mutex) < 0)
187 return -EAGAIN;
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;
200 if (msg[i].flags & I2C_M_RD) {
201 /* read only */
202 u8 obuf[3], ibuf[MAX_XFER_SIZE];
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;
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;
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 /* write to then read from same address */
223 u8 obuf[MAX_XFER_SIZE], ibuf[MAX_XFER_SIZE];
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;
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;
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);
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;
247 if (ibuf[0] != 0x08)
248 dev_info(&d->udev->dev, "i2c read may have failed\n");
250 memcpy(msg[i + 1].buf, &ibuf[1], msg[i + 1].len);
252 i++;
253 } else {
254 /* write only */
255 u8 obuf[MAX_XFER_SIZE], ibuf;
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;
263 obuf[0] = msg[i].addr;
264 obuf[1] = msg[i].len;
265 memcpy(&obuf[2], msg[i].buf, msg[i].len);
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");
275 if (i == num)
276 ret = num;
277 else
278 ret = -EREMOTEIO;
280 unlock:
281 mutex_unlock(&d->i2c_mutex);
282 return ret;
285 static u32 cxusb_i2c_func(struct i2c_adapter *adapter)
287 return I2C_FUNC_I2C | I2C_FUNC_SMBUS_EMUL;
290 static struct i2c_algorithm cxusb_i2c_algo = {
291 .master_xfer = cxusb_i2c_xfer,
292 .functionality = cxusb_i2c_func,
295 static int _cxusb_power_ctrl(struct dvb_usb_device *d, int onoff)
297 u8 b = 0;
299 dev_info(&d->udev->dev, "setting power %s\n", onoff ? "ON" : "OFF");
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);
307 static int cxusb_power_ctrl(struct dvb_usb_device *d, int onoff)
309 bool is_medion = d->props.devices[0].warm_ids[0] == &cxusb_table[MEDION_MD95700];
310 int ret;
312 if (is_medion && !onoff) {
313 struct cxusb_medion_dev *cxdev = d->priv;
315 mutex_lock(&cxdev->open_lock);
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;
324 ret = _cxusb_power_ctrl(d, onoff);
326 ret_unlock:
327 if (is_medion && !onoff) {
328 struct cxusb_medion_dev *cxdev = d->priv;
330 mutex_unlock(&cxdev->open_lock);
333 return ret;
336 static int cxusb_aver_power_ctrl(struct dvb_usb_device *d, int onoff)
338 int ret;
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 /* Nothing */
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);
351 if (!ret) {
353 * FIXME: We don't know why, but we need to configure the
354 * lgdt3303 with the register settings below on resume
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,
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;
380 return ret;
383 static int cxusb_bluebird_power_ctrl(struct dvb_usb_device *d, int onoff)
385 u8 b = 0;
387 if (onoff)
388 return cxusb_ctrl_msg(d, CMD_POWER_ON, &b, 1, NULL, 0);
389 else
390 return 0;
393 static int cxusb_nano2_power_ctrl(struct dvb_usb_device *d, int onoff)
395 int rc = 0;
397 rc = cxusb_power_ctrl(d, onoff);
398 if (!onoff)
399 cxusb_nano2_led(d, 0);
401 return rc;
404 static int cxusb_d680_dmb_power_ctrl(struct dvb_usb_device *d, int onoff)
406 int ret;
407 u8 b;
409 ret = cxusb_power_ctrl(d, onoff);
410 if (!onoff)
411 return ret;
413 msleep(128);
414 cxusb_ctrl_msg(d, CMD_DIGITAL, NULL, 0, &b, 1);
415 msleep(100);
416 return ret;
419 static int cxusb_streaming_ctrl(struct dvb_usb_adapter *adap, int onoff)
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 };
426 if (is_medion && onoff) {
427 int ret;
429 ret = cxusb_medion_get(dvbdev, CXUSB_OPEN_DIGITAL);
430 if (ret != 0)
431 return ret;
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);
439 if (is_medion && !onoff)
440 cxusb_medion_put(dvbdev);
442 return 0;
445 static int cxusb_aver_streaming_ctrl(struct dvb_usb_adapter *adap, int onoff)
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;
455 static void cxusb_d680_dmb_drain_message(struct dvb_usb_device *d)
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;
463 /* Discard remaining data in video pipe */
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;
475 kfree(junk);
478 static void cxusb_d680_dmb_drain_video(struct dvb_usb_device *d)
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;
486 /* Discard remaining data in video pipe */
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;
498 kfree(junk);
501 static int cxusb_d680_dmb_streaming_ctrl(struct dvb_usb_adapter *adap,
502 int onoff)
504 if (onoff) {
505 u8 buf[2] = { 0x03, 0x00 };
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;
517 static int cxusb_rc_query(struct dvb_usb_device *d)
519 u8 ircode[4];
521 if (cxusb_ctrl_msg(d, CMD_GET_IR_CODE, NULL, 0, ircode, 4) < 0)
522 return 0;
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;
530 static int cxusb_bluebird2_rc_query(struct dvb_usb_device *d)
532 u8 ircode[4];
533 struct i2c_msg msg = {
534 .addr = 0x6b,
535 .flags = I2C_M_RD,
536 .buf = ircode,
537 .len = 4
540 if (cxusb_i2c_xfer(&d->i2c_adap, &msg, 1) != 1)
541 return 0;
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;
549 static int cxusb_d680_dmb_rc_query(struct dvb_usb_device *d)
551 u8 ircode[2];
553 if (cxusb_ctrl_msg(d, 0x10, NULL, 0, ircode, 2) < 0)
554 return 0;
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;
562 static int cxusb_dee1601_demod_init(struct dvb_frontend *fe)
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 };
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));
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));
580 return 0;
583 static int cxusb_mt352_demod_init(struct dvb_frontend *fe)
585 /* used in both lgz201 and th7579 */
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 };
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));
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;
604 static struct cx22702_config cxusb_cx22702_config = {
605 .demod_address = 0x63,
606 .output_mode = CX22702_PARALLEL_OUTPUT,
609 static struct lgdt330x_config cxusb_lgdt3303_config = {
610 .demod_chip = LGDT3303,
613 static struct lgdt330x_config cxusb_aver_lgdt3303_config = {
614 .demod_chip = LGDT3303,
615 .clock_polarity_flip = 2,
618 static struct mt352_config cxusb_dee1601_config = {
619 .demod_address = 0x0f,
620 .demod_init = cxusb_dee1601_demod_init,
623 static struct zl10353_config cxusb_zl10353_dee1601_config = {
624 .demod_address = 0x0f,
625 .parallel_ts = 1,
628 static struct mt352_config cxusb_mt352_config = {
629 /* used in both lgz201 and th7579 */
630 .demod_address = 0x0f,
631 .demod_init = cxusb_mt352_demod_init,
634 static struct zl10353_config cxusb_zl10353_xc3028_config = {
635 .demod_address = 0x0f,
636 .if2 = 45600,
637 .no_tuner = 1,
638 .parallel_ts = 1,
641 static 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,
649 static 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,
656 /* FIXME: needs tweaking */
657 static 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,
674 /* FIXME: needs tweaking */
675 static 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,
692 static struct max2165_config mygica_d689_max2165_cfg = {
693 .i2c_address = 0x60,
694 .osc_clk = 20
697 /* Callbacks for DVB USB */
698 static int cxusb_fmd1216me_tuner_attach(struct dvb_usb_adapter *adap)
700 struct dvb_usb_device *dvbdev = adap->dev;
701 bool is_medion = dvbdev->props.devices[0].warm_ids[0] ==
702 &cxusb_table[MEDION_MD95700];
704 dvb_attach(simple_tuner_attach, adap->fe_adap[0].fe,
705 &dvbdev->i2c_adap, 0x61,
706 TUNER_PHILIPS_FMD1216ME_MK3);
708 if (is_medion && adap->fe_adap[0].fe)
710 * make sure that DVB core won't put to sleep (reset, really)
711 * tuner when we might be open in analog mode
713 adap->fe_adap[0].fe->ops.tuner_ops.sleep = NULL;
715 return 0;
718 static int cxusb_dee1601_tuner_attach(struct dvb_usb_adapter *adap)
720 dvb_attach(dvb_pll_attach, adap->fe_adap[0].fe, 0x61,
721 NULL, DVB_PLL_THOMSON_DTT7579);
722 return 0;
725 static int cxusb_lgz201_tuner_attach(struct dvb_usb_adapter *adap)
727 dvb_attach(dvb_pll_attach, adap->fe_adap[0].fe, 0x61,
728 NULL, DVB_PLL_LG_Z201);
729 return 0;
732 static int cxusb_dtt7579_tuner_attach(struct dvb_usb_adapter *adap)
734 dvb_attach(dvb_pll_attach, adap->fe_adap[0].fe, 0x60,
735 NULL, DVB_PLL_THOMSON_DTT7579);
736 return 0;
739 static int cxusb_lgh064f_tuner_attach(struct dvb_usb_adapter *adap)
741 dvb_attach(simple_tuner_attach, adap->fe_adap[0].fe,
742 &adap->dev->i2c_adap, 0x61, TUNER_LG_TDVS_H06XF);
743 return 0;
746 static int dvico_bluebird_xc2028_callback(void *ptr, int component,
747 int command, int arg)
749 struct dvb_usb_adapter *adap = ptr;
750 struct dvb_usb_device *d = adap->dev;
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;
768 return 0;
771 static int cxusb_dvico_xc3028_tuner_attach(struct dvb_usb_adapter *adap)
773 struct dvb_frontend *fe;
774 struct xc2028_config cfg = {
775 .i2c_adap = &adap->dev->i2c_adap,
776 .i2c_addr = 0x61,
778 static struct xc2028_ctrl ctl = {
779 .fname = XC2028_DEFAULT_FIRMWARE,
780 .max_len = 64,
781 .demod = XC3028_FE_ZARLINK456,
784 /* FIXME: generalize & move to common area */
785 adap->fe_adap[0].fe->callback = dvico_bluebird_xc2028_callback;
787 fe = dvb_attach(xc2028_attach, adap->fe_adap[0].fe, &cfg);
788 if (!fe || !fe->ops.tuner_ops.set_config)
789 return -EIO;
791 fe->ops.tuner_ops.set_config(fe, &ctl);
793 return 0;
796 static int cxusb_mxl5003s_tuner_attach(struct dvb_usb_adapter *adap)
798 dvb_attach(mxl5005s_attach, adap->fe_adap[0].fe,
799 &adap->dev->i2c_adap, &aver_a868r_tuner);
800 return 0;
803 static int cxusb_d680_dmb_tuner_attach(struct dvb_usb_adapter *adap)
805 struct dvb_frontend *fe;
807 fe = dvb_attach(mxl5005s_attach, adap->fe_adap[0].fe,
808 &adap->dev->i2c_adap, &d680_dmb_tuner);
809 return (!fe) ? -EIO : 0;
812 static int cxusb_mygica_d689_tuner_attach(struct dvb_usb_adapter *adap)
814 struct dvb_frontend *fe;
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;
821 static int cxusb_medion_fe_ts_bus_ctrl(struct dvb_frontend *fe, int acquire)
823 struct dvb_usb_adapter *adap = fe->dvb->priv;
824 struct dvb_usb_device *dvbdev = adap->dev;
826 if (acquire)
827 return cxusb_medion_get(dvbdev, CXUSB_OPEN_DIGITAL);
829 cxusb_medion_put(dvbdev);
831 return 0;
834 static int cxusb_medion_set_mode(struct dvb_usb_device *dvbdev, bool digital)
836 struct cxusb_state *st = dvbdev->priv;
837 int ret;
838 u8 b;
839 unsigned int i;
842 * switching mode while doing an I2C transaction often causes
843 * the device to crash
845 mutex_lock(&dvbdev->i2c_mutex);
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;
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;
865 /* pipes need to be cleared after setting interface */
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);
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);
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;
886 /* mode switch seems to reset GPIO states */
887 for (i = 0; i < ARRAY_SIZE(st->gpio_write_refresh); i++)
888 st->gpio_write_refresh[i] = true;
890 ret_unlock:
891 mutex_unlock(&dvbdev->i2c_mutex);
893 return ret;
896 static int cxusb_cx22702_frontend_attach(struct dvb_usb_adapter *adap)
898 struct dvb_usb_device *dvbdev = adap->dev;
899 bool is_medion = dvbdev->props.devices[0].warm_ids[0] ==
900 &cxusb_table[MEDION_MD95700];
902 if (is_medion) {
903 int ret;
905 ret = cxusb_medion_set_mode(dvbdev, true);
906 if (ret)
907 return ret;
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;
915 if (is_medion)
916 adap->fe_adap[0].fe->ops.ts_bus_ctrl =
917 cxusb_medion_fe_ts_bus_ctrl;
919 return 0;
922 static int cxusb_lgdt3303_frontend_attach(struct dvb_usb_adapter *adap)
924 if (usb_set_interface(adap->dev->udev, 0, 7) < 0)
925 err("set interface failed");
927 cxusb_ctrl_msg(adap->dev, CMD_DIGITAL, NULL, 0, NULL, 0);
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;
936 return -EIO;
939 static int cxusb_aver_lgdt3303_frontend_attach(struct dvb_usb_adapter *adap)
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;
948 return -EIO;
951 static int cxusb_mt352_frontend_attach(struct dvb_usb_adapter *adap)
953 /* used in both lgz201 and th7579 */
954 if (usb_set_interface(adap->dev->udev, 0, 0) < 0)
955 err("set interface failed");
957 cxusb_ctrl_msg(adap->dev, CMD_DIGITAL, NULL, 0, NULL, 0);
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;
964 return -EIO;
967 static int cxusb_dee1601_frontend_attach(struct dvb_usb_adapter *adap)
969 if (usb_set_interface(adap->dev->udev, 0, 0) < 0)
970 err("set interface failed");
972 cxusb_ctrl_msg(adap->dev, CMD_DIGITAL, NULL, 0, NULL, 0);
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;
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;
985 return -EIO;
988 static int cxusb_dualdig4_frontend_attach(struct dvb_usb_adapter *adap)
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
999 if (usb_set_interface(adap->dev->udev, 0, 1) < 0)
1000 err("set interface failed");
1002 cxusb_ctrl_msg(adap->dev, CMD_DIGITAL, NULL, 0, NULL, 0);
1004 /* reset the tuner and demodulator */
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);
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;
1016 /* try to determine if there is no IR decoder on the I2C bus */
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) {
1024 no_IR:
1025 adap->dev->props.rc.core.rc_codes = NULL;
1026 info("No IR receiver detected on this device.");
1027 break;
1031 return 0;
1034 static struct dibx000_agc_config dib7070_agc_config = {
1035 .band_caps = BAND_UHF | BAND_VHF | BAND_LBAND | BAND_SBAND,
1038 * P_agc_use_sd_mod1=0, P_agc_use_sd_mod2=0, P_agc_freq_pwm_div=5,
1039 * P_agc_inv_pwm1=0, P_agc_inv_pwm2=0, P_agc_inh_dc_rv_est=0,
1040 * P_agc_time_est=3, P_agc_freeze=0, P_agc_nb_est=5, P_agc_write=0
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,
1072 static 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 /* refsel, sel, freq_15k */
1086 .sad_cfg = (3 << 14) | (1 << 12) | (524 << 0),
1087 .ifreq = (0 << 25) | 0,
1088 .timf = 20452225,
1089 .xtal_hz = 12000000,
1092 static struct dib7000p_config cxusb_dualdig4_rev2_config = {
1093 .output_mode = OUTMODE_MPEG2_PAR_GATED_CLK,
1094 .output_mpeg2_in_188_bytes = 1,
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,
1102 .gpio_dir = 0xfcef,
1103 .gpio_val = 0x0110,
1105 .gpio_pwm_pos = DIB7000P_GPIO_DEFAULT_PWM_POS,
1107 .hostbus_diversity = 1,
1110 struct dib0700_adapter_state {
1111 int (*set_param_save)(struct dvb_frontend *fe);
1112 struct dib7000p_ops dib7000p_ops;
1115 static int cxusb_dualdig4_rev2_frontend_attach(struct dvb_usb_adapter *adap)
1117 struct dib0700_adapter_state *state = adap->priv;
1119 if (usb_set_interface(adap->dev->udev, 0, 1) < 0)
1120 err("set interface failed");
1122 cxusb_ctrl_msg(adap->dev, CMD_DIGITAL, NULL, 0, NULL, 0);
1124 cxusb_bluebird_gpio_pulse(adap->dev, 0x02, 1);
1126 if (!dvb_attach(dib7000p_attach, &state->dib7000p_ops))
1127 return -ENODEV;
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;
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;
1141 return 0;
1144 static int dib7070_tuner_reset(struct dvb_frontend *fe, int onoff)
1146 struct dvb_usb_adapter *adap = fe->dvb->priv;
1147 struct dib0700_adapter_state *state = adap->priv;
1149 return state->dib7000p_ops.set_gpio(fe, 8, 0, !onoff);
1152 static int dib7070_tuner_sleep(struct dvb_frontend *fe, int onoff)
1154 return 0;
1157 static 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,
1164 static int dib7070_set_param_override(struct dvb_frontend *fe)
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;
1170 u16 offset;
1171 u8 band = BAND_OF_FREQUENCY(p->frequency / 1000);
1173 switch (band) {
1174 case BAND_VHF:
1175 offset = 950;
1176 break;
1177 default:
1178 case BAND_UHF:
1179 offset = 550;
1180 break;
1183 state->dib7000p_ops.set_wbd_ref(fe, offset + dib0070_wbd_offset(fe));
1185 return state->set_param_save(fe);
1188 static int cxusb_dualdig4_rev2_tuner_attach(struct dvb_usb_adapter *adap)
1190 struct dib0700_adapter_state *st = adap->priv;
1191 struct i2c_adapter *tun_i2c;
1194 * No need to call dvb7000p_attach here, as it was called
1195 * already, as frontend_attach method is called first, and
1196 * tuner_attach is only called on success.
1198 tun_i2c = st->dib7000p_ops.get_i2c_master(adap->fe_adap[0].fe,
1199 DIBX000_I2C_INTERFACE_TUNER, 1);
1201 if (dvb_attach(dib0070_attach, adap->fe_adap[0].fe, tun_i2c,
1202 &dib7070p_dib0070_config) == NULL)
1203 return -ENODEV;
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;
1210 static int cxusb_nano2_frontend_attach(struct dvb_usb_adapter *adap)
1212 if (usb_set_interface(adap->dev->udev, 0, 1) < 0)
1213 err("set interface failed");
1215 cxusb_ctrl_msg(adap->dev, CMD_DIGITAL, NULL, 0, NULL, 0);
1217 /* reset the tuner and demodulator */
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);
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;
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;
1234 return -EIO;
1237 static 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, /* 30.4 MHz */
1244 .if_freq = 5725, /* 5.725 MHz */
1245 .if_neg_center = 0,
1246 .ext_adc = 0,
1247 .adc_signed = 0,
1248 .if_neg_edge = 0,
1251 static int cxusb_d680_dmb_frontend_attach(struct dvb_usb_adapter *adap)
1253 struct dvb_usb_device *d = adap->dev;
1254 int n;
1256 /* Select required USB configuration */
1257 if (usb_set_interface(d->udev, 0, 0) < 0)
1258 err("set interface failed");
1260 /* Unblock all USB pipes */
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));
1271 /* Drain USB pipes to avoid hang after reboot */
1272 for (n = 0; n < 5; n++) {
1273 cxusb_d680_dmb_drain_message(d);
1274 cxusb_d680_dmb_drain_video(d);
1275 msleep(200);
1278 /* Reset the tuner */
1279 if (cxusb_d680_dmb_gpio_tuner(d, 0x07, 0) < 0) {
1280 err("clear tuner gpio failed");
1281 return -EIO;
1283 msleep(100);
1284 if (cxusb_d680_dmb_gpio_tuner(d, 0x07, 1) < 0) {
1285 err("set tuner gpio failed");
1286 return -EIO;
1288 msleep(100);
1290 /* Attach frontend */
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;
1296 return 0;
1299 static 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, /* in kHz */
1306 .if_freq = 0, /* zero IF */
1307 .zif_swap_iq = 1,
1308 .agc_min = 0x2E,
1309 .agc_max = 0x90,
1310 .agc_hold_loop = 0,
1313 static int cxusb_mygica_d689_frontend_attach(struct dvb_usb_adapter *adap)
1315 struct dvb_usb_device *d = adap->dev;
1317 /* Select required USB configuration */
1318 if (usb_set_interface(d->udev, 0, 0) < 0)
1319 err("set interface failed");
1321 /* Unblock all USB pipes */
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));
1332 /* Reset the tuner */
1333 if (cxusb_d680_dmb_gpio_tuner(d, 0x07, 0) < 0) {
1334 err("clear tuner gpio failed");
1335 return -EIO;
1337 msleep(100);
1338 if (cxusb_d680_dmb_gpio_tuner(d, 0x07, 1) < 0) {
1339 err("set tuner gpio failed");
1340 return -EIO;
1342 msleep(100);
1344 /* Attach frontend */
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;
1351 return 0;
1355 * DViCO has shipped two devices with the same USB ID, but only one of them
1356 * needs a firmware download. Check the device class details to see if they
1357 * have non-default values to decide whether the device is actually cold or
1358 * not, and forget a match if it turns out we selected the wrong device.
1360 static int bluebird_fx2_identify_state(struct usb_device *udev,
1361 struct dvb_usb_device_properties *props,
1362 struct dvb_usb_device_description **desc,
1363 int *cold)
1365 int wascold = *cold;
1367 *cold = udev->descriptor.bDeviceClass == 0xff &&
1368 udev->descriptor.bDeviceSubClass == 0xff &&
1369 udev->descriptor.bDeviceProtocol == 0xff;
1371 if (*cold && !wascold)
1372 *desc = NULL;
1374 return 0;
1378 * DViCO bluebird firmware needs the "warm" product ID to be patched into the
1379 * firmware file before download.
1382 static const int dvico_firmware_id_offsets[] = { 6638, 3204 };
1383 static int bluebird_patch_dvico_firmware_download(struct usb_device *udev,
1384 const struct firmware *fw)
1386 int pos;
1388 for (pos = 0; pos < ARRAY_SIZE(dvico_firmware_id_offsets); pos++) {
1389 int idoff = dvico_firmware_id_offsets[pos];
1391 if (fw->size < idoff + 4)
1392 continue;
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;
1400 if (!new_fw_data)
1401 return -ENOMEM;
1403 memcpy(new_fw_data, fw->data, fw->size);
1404 new_fw.size = fw->size;
1405 new_fw.data = new_fw_data;
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;
1412 ret = usb_cypress_load_firmware(udev, &new_fw,
1413 CYPRESS_FX2);
1414 vfree(new_fw_data);
1415 return ret;
1419 return -EINVAL;
1422 int cxusb_medion_get(struct dvb_usb_device *dvbdev,
1423 enum cxusb_open_type open_type)
1425 struct cxusb_medion_dev *cxdev = dvbdev->priv;
1426 int ret = 0;
1428 mutex_lock(&cxdev->open_lock);
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;
1437 if (cxdev->open_type == CXUSB_OPEN_INIT) {
1438 ret = -EAGAIN;
1439 goto ret_unlock;
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");
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);
1455 ret = cxusb_medion_set_mode(dvbdev, false);
1456 if (ret != 0)
1457 goto ret_unlock;
1459 ret = cxusb_medion_analog_init(dvbdev);
1460 if (ret != 0)
1461 goto ret_unlock;
1462 } else { /* digital */
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);
1469 ret = cxusb_medion_set_mode(dvbdev, true);
1470 if (ret != 0)
1471 goto ret_unlock;
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");
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;
1490 ret_unlock:
1491 mutex_unlock(&cxdev->open_lock);
1493 return ret;
1496 void cxusb_medion_put(struct dvb_usb_device *dvbdev)
1498 struct cxusb_medion_dev *cxdev = dvbdev->priv;
1500 mutex_lock(&cxdev->open_lock);
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;
1508 if (!WARN_ON(cxdev->open_ctr < 1)) {
1509 cxdev->open_ctr--;
1511 dev_info(&dvbdev->udev->dev, "release %s\n",
1512 cxdev->open_type == CXUSB_OPEN_ANALOG ?
1513 "analog" : "digital");
1516 unlock:
1517 mutex_unlock(&cxdev->open_lock);
1520 /* DVB USB Driver stuff */
1521 static struct dvb_usb_device_properties cxusb_medion_properties;
1522 static struct dvb_usb_device_properties cxusb_bluebird_lgh064f_properties;
1523 static struct dvb_usb_device_properties cxusb_bluebird_dee1601_properties;
1524 static struct dvb_usb_device_properties cxusb_bluebird_lgz201_properties;
1525 static struct dvb_usb_device_properties cxusb_bluebird_dtt7579_properties;
1526 static struct dvb_usb_device_properties cxusb_bluebird_dualdig4_properties;
1527 static struct dvb_usb_device_properties cxusb_bluebird_dualdig4_rev2_properties;
1528 static struct dvb_usb_device_properties cxusb_bluebird_nano2_properties;
1529 static struct dvb_usb_device_properties cxusb_bluebird_nano2_needsfirmware_properties;
1530 static struct dvb_usb_device_properties cxusb_aver_a868r_properties;
1531 static struct dvb_usb_device_properties cxusb_d680_dmb_properties;
1532 static struct dvb_usb_device_properties cxusb_mygica_d689_properties;
1534 static int cxusb_medion_priv_init(struct dvb_usb_device *dvbdev)
1536 struct cxusb_medion_dev *cxdev = dvbdev->priv;
1538 cxdev->dvbdev = dvbdev;
1539 cxdev->open_type = CXUSB_OPEN_INIT;
1540 mutex_init(&cxdev->open_lock);
1542 return 0;
1545 static void cxusb_medion_priv_destroy(struct dvb_usb_device *dvbdev)
1547 struct cxusb_medion_dev *cxdev = dvbdev->priv;
1549 mutex_destroy(&cxdev->open_lock);
1552 static bool cxusb_medion_check_altsetting(struct usb_host_interface *as)
1554 unsigned int ctr;
1556 for (ctr = 0; ctr < as->desc.bNumEndpoints; ctr++) {
1557 if ((as->endpoint[ctr].desc.bEndpointAddress &
1558 USB_ENDPOINT_NUMBER_MASK) != 2)
1559 continue;
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;
1566 break;
1569 return false;
1572 static bool cxusb_medion_check_intf(struct usb_interface *intf)
1574 unsigned int ctr;
1576 if (intf->num_altsetting < 2) {
1577 dev_err(intf->usb_dev, "no alternate interface");
1579 return false;
1582 for (ctr = 0; ctr < intf->num_altsetting; ctr++) {
1583 if (intf->altsetting[ctr].desc.bAlternateSetting != 1)
1584 continue;
1586 if (cxusb_medion_check_altsetting(&intf->altsetting[ctr]))
1587 return true;
1589 break;
1592 dev_err(intf->usb_dev, "no iso interface");
1594 return false;
1597 static int cxusb_probe(struct usb_interface *intf,
1598 const struct usb_device_id *id)
1600 struct dvb_usb_device *dvbdev;
1601 int ret;
1603 /* Medion 95700 */
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;
1611 _cxusb_power_ctrl(dvbdev, 1);
1612 ret = cxusb_medion_set_mode(dvbdev, false);
1613 if (ret)
1614 goto ret_uninit;
1616 ret = cxusb_medion_register_analog(dvbdev);
1618 cxusb_medion_set_mode(dvbdev, true);
1619 _cxusb_power_ctrl(dvbdev, 0);
1621 if (ret != 0)
1622 goto ret_uninit;
1624 /* release device from INIT mode to normal operation */
1625 cxusb_medion_put(dvbdev);
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) ||
1659 return 0;
1661 return -EINVAL;
1663 ret_uninit:
1664 dvb_usb_device_exit(intf);
1666 return ret;
1669 static void cxusb_disconnect(struct usb_interface *intf)
1671 struct dvb_usb_device *d = usb_get_intfdata(intf);
1672 struct cxusb_state *st = d->priv;
1673 struct i2c_client *client;
1675 if (d->props.devices[0].warm_ids[0] == &cxusb_table[MEDION_MD95700])
1676 cxusb_medion_unregister_analog(d);
1678 /* remove I2C client for tuner */
1679 client = st->i2c_client_tuner;
1680 if (client) {
1681 module_put(client->dev.driver->owner);
1682 i2c_unregister_device(client);
1685 /* remove I2C client for demodulator */
1686 client = st->i2c_client_demod;
1687 if (client) {
1688 module_put(client->dev.driver->owner);
1689 i2c_unregister_device(client);
1692 dvb_usb_device_exit(intf);
1695 static struct usb_device_id cxusb_table[NR__cxusb_table_index + 1] = {
1696 [MEDION_MD95700] = {
1697 USB_DEVICE(USB_VID_MEDION, USB_PID_MEDION_MD95700)
1699 [DVICO_BLUEBIRD_LG064F_COLD] = {
1700 USB_DEVICE(USB_VID_DVICO, USB_PID_DVICO_BLUEBIRD_LG064F_COLD)
1702 [DVICO_BLUEBIRD_LG064F_WARM] = {
1703 USB_DEVICE(USB_VID_DVICO, USB_PID_DVICO_BLUEBIRD_LG064F_WARM)
1705 [DVICO_BLUEBIRD_DUAL_1_COLD] = {
1706 USB_DEVICE(USB_VID_DVICO, USB_PID_DVICO_BLUEBIRD_DUAL_1_COLD)
1708 [DVICO_BLUEBIRD_DUAL_1_WARM] = {
1709 USB_DEVICE(USB_VID_DVICO, USB_PID_DVICO_BLUEBIRD_DUAL_1_WARM)
1711 [DVICO_BLUEBIRD_LGZ201_COLD] = {
1712 USB_DEVICE(USB_VID_DVICO, USB_PID_DVICO_BLUEBIRD_LGZ201_COLD)
1714 [DVICO_BLUEBIRD_LGZ201_WARM] = {
1715 USB_DEVICE(USB_VID_DVICO, USB_PID_DVICO_BLUEBIRD_LGZ201_WARM)
1717 [DVICO_BLUEBIRD_TH7579_COLD] = {
1718 USB_DEVICE(USB_VID_DVICO, USB_PID_DVICO_BLUEBIRD_TH7579_COLD)
1720 [DVICO_BLUEBIRD_TH7579_WARM] = {
1721 USB_DEVICE(USB_VID_DVICO, USB_PID_DVICO_BLUEBIRD_TH7579_WARM)
1723 [DIGITALNOW_BLUEBIRD_DUAL_1_COLD] = {
1724 USB_DEVICE(USB_VID_DVICO,
1725 USB_PID_DIGITALNOW_BLUEBIRD_DUAL_1_COLD)
1727 [DIGITALNOW_BLUEBIRD_DUAL_1_WARM] = {
1728 USB_DEVICE(USB_VID_DVICO,
1729 USB_PID_DIGITALNOW_BLUEBIRD_DUAL_1_WARM)
1731 [DVICO_BLUEBIRD_DUAL_2_COLD] = {
1732 USB_DEVICE(USB_VID_DVICO, USB_PID_DVICO_BLUEBIRD_DUAL_2_COLD)
1734 [DVICO_BLUEBIRD_DUAL_2_WARM] = {
1735 USB_DEVICE(USB_VID_DVICO, USB_PID_DVICO_BLUEBIRD_DUAL_2_WARM)
1737 [DVICO_BLUEBIRD_DUAL_4] = {
1738 USB_DEVICE(USB_VID_DVICO, USB_PID_DVICO_BLUEBIRD_DUAL_4)
1740 [DVICO_BLUEBIRD_DVB_T_NANO_2] = {
1741 USB_DEVICE(USB_VID_DVICO, USB_PID_DVICO_BLUEBIRD_DVB_T_NANO_2)
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)
1747 [AVERMEDIA_VOLAR_A868R] = {
1748 USB_DEVICE(USB_VID_AVERMEDIA, USB_PID_AVERMEDIA_VOLAR_A868R)
1750 [DVICO_BLUEBIRD_DUAL_4_REV_2] = {
1751 USB_DEVICE(USB_VID_DVICO, USB_PID_DVICO_BLUEBIRD_DUAL_4_REV_2)
1753 [CONEXANT_D680_DMB] = {
1754 USB_DEVICE(USB_VID_CONEXANT, USB_PID_CONEXANT_D680_DMB)
1756 [MYGICA_D689] = {
1757 USB_DEVICE(USB_VID_CONEXANT, USB_PID_MYGICA_D689)
1759 {} /* Terminating entry */
1761 MODULE_DEVICE_TABLE(usb, cxusb_table);
1763 static struct dvb_usb_device_properties cxusb_medion_properties = {
1764 .caps = DVB_USB_IS_AN_I2C_ADAPTER,
1766 .usb_ctrl = CYPRESS_FX2,
1768 .size_of_priv = sizeof(struct cxusb_medion_dev),
1769 .priv_init = cxusb_medion_priv_init,
1770 .priv_destroy = cxusb_medion_priv_destroy,
1772 .num_adapters = 1,
1773 .adapter = {
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 /* parameter for the MPEG2-data transfer */
1781 .stream = {
1782 .type = USB_BULK,
1783 .count = 5,
1784 .endpoint = 0x02,
1785 .u = {
1786 .bulk = {
1787 .buffersize = 8192,
1791 } },
1794 .power_ctrl = cxusb_power_ctrl,
1796 .i2c_algo = &cxusb_i2c_algo,
1798 .generic_bulk_ctrl_endpoint = 0x01,
1800 .num_device_descs = 1,
1801 .devices = {
1803 "Medion MD95700 (MDUSBTV-HYBRID)",
1804 { NULL },
1805 { &cxusb_table[MEDION_MD95700], NULL },
1810 static struct dvb_usb_device_properties cxusb_bluebird_lgh064f_properties = {
1811 .caps = DVB_USB_IS_AN_I2C_ADAPTER,
1813 .usb_ctrl = DEVICE_SPECIFIC,
1814 .firmware = "dvb-usb-bluebird-01.fw",
1815 .download_firmware = bluebird_patch_dvico_firmware_download,
1817 * use usb alt setting 0 for EP4 transfer (dvb-t),
1818 * use usb alt setting 7 for EP2 transfer (atsc)
1821 .size_of_priv = sizeof(struct cxusb_state),
1823 .num_adapters = 1,
1824 .adapter = {
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,
1832 /* parameter for the MPEG2-data transfer */
1833 .stream = {
1834 .type = USB_BULK,
1835 .count = 5,
1836 .endpoint = 0x02,
1837 .u = {
1838 .bulk = {
1839 .buffersize = 8192,
1843 } },
1847 .power_ctrl = cxusb_bluebird_power_ctrl,
1849 .i2c_algo = &cxusb_i2c_algo,
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,
1859 .generic_bulk_ctrl_endpoint = 0x01,
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 },
1870 static struct dvb_usb_device_properties cxusb_bluebird_dee1601_properties = {
1871 .caps = DVB_USB_IS_AN_I2C_ADAPTER,
1873 .usb_ctrl = DEVICE_SPECIFIC,
1874 .firmware = "dvb-usb-bluebird-01.fw",
1875 .download_firmware = bluebird_patch_dvico_firmware_download,
1877 * use usb alt setting 0 for EP4 transfer (dvb-t),
1878 * use usb alt setting 7 for EP2 transfer (atsc)
1881 .size_of_priv = sizeof(struct cxusb_state),
1883 .num_adapters = 1,
1884 .adapter = {
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 /* parameter for the MPEG2-data transfer */
1892 .stream = {
1893 .type = USB_BULK,
1894 .count = 5,
1895 .endpoint = 0x04,
1896 .u = {
1897 .bulk = {
1898 .buffersize = 8192,
1902 } },
1906 .power_ctrl = cxusb_bluebird_power_ctrl,
1908 .i2c_algo = &cxusb_i2c_algo,
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,
1918 .generic_bulk_ctrl_endpoint = 0x01,
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 },
1926 { "DigitalNow DVB-T Dual USB",
1927 { &cxusb_table[DIGITALNOW_BLUEBIRD_DUAL_1_COLD], NULL },
1928 { &cxusb_table[DIGITALNOW_BLUEBIRD_DUAL_1_WARM], NULL },
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 },
1937 static struct dvb_usb_device_properties cxusb_bluebird_lgz201_properties = {
1938 .caps = DVB_USB_IS_AN_I2C_ADAPTER,
1940 .usb_ctrl = DEVICE_SPECIFIC,
1941 .firmware = "dvb-usb-bluebird-01.fw",
1942 .download_firmware = bluebird_patch_dvico_firmware_download,
1944 * use usb alt setting 0 for EP4 transfer (dvb-t),
1945 * use usb alt setting 7 for EP2 transfer (atsc)
1948 .size_of_priv = sizeof(struct cxusb_state),
1950 .num_adapters = 2,
1951 .adapter = {
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,
1959 /* parameter for the MPEG2-data transfer */
1960 .stream = {
1961 .type = USB_BULK,
1962 .count = 5,
1963 .endpoint = 0x04,
1964 .u = {
1965 .bulk = {
1966 .buffersize = 8192,
1970 } },
1973 .power_ctrl = cxusb_bluebird_power_ctrl,
1975 .i2c_algo = &cxusb_i2c_algo,
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,
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 },
1995 static struct dvb_usb_device_properties cxusb_bluebird_dtt7579_properties = {
1996 .caps = DVB_USB_IS_AN_I2C_ADAPTER,
1998 .usb_ctrl = DEVICE_SPECIFIC,
1999 .firmware = "dvb-usb-bluebird-01.fw",
2000 .download_firmware = bluebird_patch_dvico_firmware_download,
2003 * use usb alt setting 0 for EP4 transfer (dvb-t),
2004 * use usb alt setting 7 for EP2 transfer (atsc)
2007 .size_of_priv = sizeof(struct cxusb_state),
2009 .num_adapters = 1,
2010 .adapter = {
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,
2018 /* parameter for the MPEG2-data transfer */
2019 .stream = {
2020 .type = USB_BULK,
2021 .count = 5,
2022 .endpoint = 0x04,
2023 .u = {
2024 .bulk = {
2025 .buffersize = 8192,
2029 } },
2032 .power_ctrl = cxusb_bluebird_power_ctrl,
2034 .i2c_algo = &cxusb_i2c_algo,
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,
2044 .generic_bulk_ctrl_endpoint = 0x01,
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 },
2055 static struct dvb_usb_device_properties cxusb_bluebird_dualdig4_properties = {
2056 .caps = DVB_USB_IS_AN_I2C_ADAPTER,
2058 .usb_ctrl = CYPRESS_FX2,
2060 .size_of_priv = sizeof(struct cxusb_state),
2062 .num_adapters = 1,
2063 .adapter = {
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 /* parameter for the MPEG2-data transfer */
2071 .stream = {
2072 .type = USB_BULK,
2073 .count = 5,
2074 .endpoint = 0x02,
2075 .u = {
2076 .bulk = {
2077 .buffersize = 8192,
2081 } },
2085 .power_ctrl = cxusb_power_ctrl,
2087 .i2c_algo = &cxusb_i2c_algo,
2089 .generic_bulk_ctrl_endpoint = 0x01,
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,
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 },
2108 static struct dvb_usb_device_properties cxusb_bluebird_nano2_properties = {
2109 .caps = DVB_USB_IS_AN_I2C_ADAPTER,
2111 .usb_ctrl = CYPRESS_FX2,
2112 .identify_state = bluebird_fx2_identify_state,
2114 .size_of_priv = sizeof(struct cxusb_state),
2116 .num_adapters = 1,
2117 .adapter = {
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 /* parameter for the MPEG2-data transfer */
2125 .stream = {
2126 .type = USB_BULK,
2127 .count = 5,
2128 .endpoint = 0x02,
2129 .u = {
2130 .bulk = {
2131 .buffersize = 8192,
2135 } },
2139 .power_ctrl = cxusb_nano2_power_ctrl,
2141 .i2c_algo = &cxusb_i2c_algo,
2143 .generic_bulk_ctrl_endpoint = 0x01,
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,
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 },
2162 static struct dvb_usb_device_properties
2163 cxusb_bluebird_nano2_needsfirmware_properties = {
2164 .caps = DVB_USB_IS_AN_I2C_ADAPTER,
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,
2171 .size_of_priv = sizeof(struct cxusb_state),
2173 .num_adapters = 1,
2174 .adapter = {
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 /* parameter for the MPEG2-data transfer */
2182 .stream = {
2183 .type = USB_BULK,
2184 .count = 5,
2185 .endpoint = 0x02,
2186 .u = {
2187 .bulk = {
2188 .buffersize = 8192,
2192 } },
2196 .power_ctrl = cxusb_nano2_power_ctrl,
2198 .i2c_algo = &cxusb_i2c_algo,
2200 .generic_bulk_ctrl_endpoint = 0x01,
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,
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 },
2220 static struct dvb_usb_device_properties cxusb_aver_a868r_properties = {
2221 .caps = DVB_USB_IS_AN_I2C_ADAPTER,
2223 .usb_ctrl = CYPRESS_FX2,
2225 .size_of_priv = sizeof(struct cxusb_state),
2227 .num_adapters = 1,
2228 .adapter = {
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 /* parameter for the MPEG2-data transfer */
2236 .stream = {
2237 .type = USB_BULK,
2238 .count = 5,
2239 .endpoint = 0x04,
2240 .u = {
2241 .bulk = {
2242 .buffersize = 8192,
2246 } },
2249 .power_ctrl = cxusb_aver_power_ctrl,
2251 .i2c_algo = &cxusb_i2c_algo,
2253 .generic_bulk_ctrl_endpoint = 0x01,
2255 .num_device_descs = 1,
2256 .devices = {
2257 { "AVerMedia AVerTVHD Volar (A868R)",
2258 { NULL },
2259 { &cxusb_table[AVERMEDIA_VOLAR_A868R], NULL },
2264 static
2265 struct dvb_usb_device_properties cxusb_bluebird_dualdig4_rev2_properties = {
2266 .caps = DVB_USB_IS_AN_I2C_ADAPTER,
2268 .usb_ctrl = CYPRESS_FX2,
2270 .size_of_priv = sizeof(struct cxusb_state),
2272 .num_adapters = 1,
2273 .adapter = {
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 /* parameter for the MPEG2-data transfer */
2282 .stream = {
2283 .type = USB_BULK,
2284 .count = 7,
2285 .endpoint = 0x02,
2286 .u = {
2287 .bulk = {
2288 .buffersize = 4096,
2292 } },
2296 .power_ctrl = cxusb_bluebird_power_ctrl,
2298 .i2c_algo = &cxusb_i2c_algo,
2300 .generic_bulk_ctrl_endpoint = 0x01,
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,
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 },
2319 static struct dvb_usb_device_properties cxusb_d680_dmb_properties = {
2320 .caps = DVB_USB_IS_AN_I2C_ADAPTER,
2322 .usb_ctrl = CYPRESS_FX2,
2324 .size_of_priv = sizeof(struct cxusb_state),
2326 .num_adapters = 1,
2327 .adapter = {
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,
2335 /* parameter for the MPEG2-data transfer */
2336 .stream = {
2337 .type = USB_BULK,
2338 .count = 5,
2339 .endpoint = 0x02,
2340 .u = {
2341 .bulk = {
2342 .buffersize = 8192,
2346 } },
2350 .power_ctrl = cxusb_d680_dmb_power_ctrl,
2352 .i2c_algo = &cxusb_i2c_algo,
2354 .generic_bulk_ctrl_endpoint = 0x01,
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,
2364 .num_device_descs = 1,
2365 .devices = {
2367 "Conexant DMB-TH Stick",
2368 { NULL },
2369 { &cxusb_table[CONEXANT_D680_DMB], NULL },
2374 static struct dvb_usb_device_properties cxusb_mygica_d689_properties = {
2375 .caps = DVB_USB_IS_AN_I2C_ADAPTER,
2377 .usb_ctrl = CYPRESS_FX2,
2379 .size_of_priv = sizeof(struct cxusb_state),
2381 .num_adapters = 1,
2382 .adapter = {
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,
2390 /* parameter for the MPEG2-data transfer */
2391 .stream = {
2392 .type = USB_BULK,
2393 .count = 5,
2394 .endpoint = 0x02,
2395 .u = {
2396 .bulk = {
2397 .buffersize = 8192,
2401 } },
2405 .power_ctrl = cxusb_d680_dmb_power_ctrl,
2407 .i2c_algo = &cxusb_i2c_algo,
2409 .generic_bulk_ctrl_endpoint = 0x01,
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,
2419 .num_device_descs = 1,
2420 .devices = {
2422 "Mygica D689 DMB-TH",
2423 { NULL },
2424 { &cxusb_table[MYGICA_D689], NULL },
2429 static struct usb_driver cxusb_driver = {
2430 .name = "dvb_usb_cxusb",
2431 .probe = cxusb_probe,
2432 .disconnect = cxusb_disconnect,
2433 .id_table = cxusb_table,
2436 module_usb_driver(cxusb_driver);
2438 MODULE_AUTHOR("Patrick Boettcher <patrick.boettcher@posteo.de>");
2439 MODULE_AUTHOR("Michael Krufky <mkrufky@linuxtv.org>");
2440 MODULE_AUTHOR("Chris Pascoe <c.pascoe@itee.uq.edu.au>");
2441 MODULE_AUTHOR("Maciej S. Szmigiero <mail@maciej.szmigiero.name>");
2442 MODULE_DESCRIPTION("Driver for Conexant USB2.0 hybrid reference design");
2443 MODULE_LICENSE("GPL");