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
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>
36 #include "mt352_priv.h"
38 #include "tuner-xc2028.h"
39 #include "tuner-simple.h"
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 #define deb_info(args...) dprintk(dvb_usb_cxusb_debug, CXUSB_DBG_MISC, args)
58 #define deb_i2c(args...) dprintk(dvb_usb_cxusb_debug, CXUSB_DBG_I2C, args)
60 enum cxusb_table_index {
62 DVICO_BLUEBIRD_LG064F_COLD,
63 DVICO_BLUEBIRD_LG064F_WARM,
64 DVICO_BLUEBIRD_DUAL_1_COLD,
65 DVICO_BLUEBIRD_DUAL_1_WARM,
66 DVICO_BLUEBIRD_LGZ201_COLD,
67 DVICO_BLUEBIRD_LGZ201_WARM,
68 DVICO_BLUEBIRD_TH7579_COLD,
69 DVICO_BLUEBIRD_TH7579_WARM,
70 DIGITALNOW_BLUEBIRD_DUAL_1_COLD,
71 DIGITALNOW_BLUEBIRD_DUAL_1_WARM,
72 DVICO_BLUEBIRD_DUAL_2_COLD,
73 DVICO_BLUEBIRD_DUAL_2_WARM,
74 DVICO_BLUEBIRD_DUAL_4,
75 DVICO_BLUEBIRD_DVB_T_NANO_2,
76 DVICO_BLUEBIRD_DVB_T_NANO_2_NFW_WARM,
77 AVERMEDIA_VOLAR_A868R,
78 DVICO_BLUEBIRD_DUAL_4_REV_2,
84 static struct usb_device_id cxusb_table[];
86 int cxusb_ctrl_msg(struct dvb_usb_device *d,
87 u8 cmd, const u8 *wbuf, int wlen, u8 *rbuf, int rlen)
89 struct cxusb_state *st = d->priv;
92 if (1 + wlen > MAX_XFER_SIZE) {
93 warn("i2c wr: len=%d is too big!\n", wlen);
97 if (rlen > MAX_XFER_SIZE) {
98 warn("i2c rd: len=%d is too big!\n", rlen);
102 mutex_lock(&d->data_mutex);
104 memcpy(&st->data[1], wbuf, wlen);
105 ret = dvb_usb_generic_rw(d, st->data, 1 + wlen, st->data, rlen, 0);
106 if (!ret && rbuf && rlen)
107 memcpy(rbuf, st->data, rlen);
109 mutex_unlock(&d->data_mutex);
114 static void cxusb_gpio_tuner(struct dvb_usb_device *d, int onoff)
116 struct cxusb_state *st = d->priv;
119 if (st->gpio_write_state[GPIO_TUNER] == onoff &&
120 !st->gpio_write_refresh[GPIO_TUNER])
125 cxusb_ctrl_msg(d, CMD_GPIO_WRITE, o, 2, &i, 1);
128 deb_info("gpio_write failed.\n");
130 st->gpio_write_state[GPIO_TUNER] = onoff;
131 st->gpio_write_refresh[GPIO_TUNER] = false;
134 static int cxusb_bluebird_gpio_rw(struct dvb_usb_device *d, u8 changemask,
140 o[0] = 0xff & ~changemask; /* mask of bits to keep */
141 o[1] = newval & changemask; /* new values for bits */
143 rc = cxusb_ctrl_msg(d, CMD_BLUEBIRD_GPIO_RW, o, 2, &gpio_state, 1);
144 if (rc < 0 || (gpio_state & changemask) != (newval & changemask))
145 deb_info("bluebird_gpio_write failed.\n");
147 return rc < 0 ? rc : gpio_state;
150 static void cxusb_bluebird_gpio_pulse(struct dvb_usb_device *d, u8 pin, int low)
152 cxusb_bluebird_gpio_rw(d, pin, low ? 0 : pin);
154 cxusb_bluebird_gpio_rw(d, pin, low ? pin : 0);
157 static void cxusb_nano2_led(struct dvb_usb_device *d, int onoff)
159 cxusb_bluebird_gpio_rw(d, 0x40, onoff ? 0 : 0x40);
162 static int cxusb_d680_dmb_gpio_tuner(struct dvb_usb_device *d,
165 u8 o[2] = {addr, onoff};
169 rc = cxusb_ctrl_msg(d, CMD_GPIO_WRITE, o, 2, &i, 1);
177 deb_info("gpio_write failed.\n");
182 static int cxusb_i2c_xfer(struct i2c_adapter *adap, struct i2c_msg msg[],
185 struct dvb_usb_device *d = i2c_get_adapdata(adap);
189 if (mutex_lock_interruptible(&d->i2c_mutex) < 0)
192 for (i = 0; i < num; i++) {
193 if (le16_to_cpu(d->udev->descriptor.idVendor) == USB_VID_MEDION)
194 switch (msg[i].addr) {
196 cxusb_gpio_tuner(d, 0);
199 cxusb_gpio_tuner(d, 1);
203 if (msg[i].flags & I2C_M_RD) {
205 u8 obuf[3], ibuf[MAX_XFER_SIZE];
207 if (1 + msg[i].len > sizeof(ibuf)) {
208 warn("i2c rd: len=%d is too big!\n",
214 obuf[1] = msg[i].len;
215 obuf[2] = msg[i].addr;
216 if (cxusb_ctrl_msg(d, CMD_I2C_READ,
218 ibuf, 1 + msg[i].len) < 0) {
219 warn("i2c read failed");
222 memcpy(msg[i].buf, &ibuf[1], msg[i].len);
223 } else if (i + 1 < num && (msg[i + 1].flags & I2C_M_RD) &&
224 msg[i].addr == msg[i + 1].addr) {
225 /* write to then read from same address */
226 u8 obuf[MAX_XFER_SIZE], ibuf[MAX_XFER_SIZE];
228 if (3 + msg[i].len > sizeof(obuf)) {
229 warn("i2c wr: len=%d is too big!\n",
234 if (1 + msg[i + 1].len > sizeof(ibuf)) {
235 warn("i2c rd: len=%d is too big!\n",
240 obuf[0] = msg[i].len;
241 obuf[1] = msg[i + 1].len;
242 obuf[2] = msg[i].addr;
243 memcpy(&obuf[3], msg[i].buf, msg[i].len);
245 if (cxusb_ctrl_msg(d, CMD_I2C_READ,
246 obuf, 3 + msg[i].len,
247 ibuf, 1 + msg[i + 1].len) < 0)
251 deb_i2c("i2c read may have failed\n");
253 memcpy(msg[i + 1].buf, &ibuf[1], msg[i + 1].len);
258 u8 obuf[MAX_XFER_SIZE], ibuf;
260 if (2 + msg[i].len > sizeof(obuf)) {
261 warn("i2c wr: len=%d is too big!\n",
266 obuf[0] = msg[i].addr;
267 obuf[1] = msg[i].len;
268 memcpy(&obuf[2], msg[i].buf, msg[i].len);
270 if (cxusb_ctrl_msg(d, CMD_I2C_WRITE, obuf,
271 2 + msg[i].len, &ibuf, 1) < 0)
274 deb_i2c("i2c write may have failed\n");
284 mutex_unlock(&d->i2c_mutex);
288 static u32 cxusb_i2c_func(struct i2c_adapter *adapter)
290 return I2C_FUNC_I2C | I2C_FUNC_SMBUS_EMUL;
293 static struct i2c_algorithm cxusb_i2c_algo = {
294 .master_xfer = cxusb_i2c_xfer,
295 .functionality = cxusb_i2c_func,
298 static int _cxusb_power_ctrl(struct dvb_usb_device *d, int onoff)
302 deb_info("setting power %s\n", onoff ? "ON" : "OFF");
305 return cxusb_ctrl_msg(d, CMD_POWER_ON, &b, 1, NULL, 0);
307 return cxusb_ctrl_msg(d, CMD_POWER_OFF, &b, 1, NULL, 0);
310 static int cxusb_power_ctrl(struct dvb_usb_device *d, int onoff)
312 bool is_medion = d->props.devices[0].warm_ids[0] == &cxusb_table[MEDION_MD95700];
315 if (is_medion && !onoff) {
316 struct cxusb_medion_dev *cxdev = d->priv;
318 mutex_lock(&cxdev->open_lock);
320 if (cxdev->open_type == CXUSB_OPEN_ANALOG) {
321 deb_info("preventing DVB core from setting power OFF while we are in analog mode\n");
327 ret = _cxusb_power_ctrl(d, onoff);
330 if (is_medion && !onoff) {
331 struct cxusb_medion_dev *cxdev = d->priv;
333 mutex_unlock(&cxdev->open_lock);
339 static int cxusb_aver_power_ctrl(struct dvb_usb_device *d, int onoff)
344 return cxusb_ctrl_msg(d, CMD_POWER_OFF, NULL, 0, NULL, 0);
345 if (d->state == DVB_USB_STATE_INIT &&
346 usb_set_interface(d->udev, 0, 0) < 0)
347 err("set interface failed");
350 } while (!(ret = cxusb_ctrl_msg(d, CMD_POWER_ON, NULL, 0, NULL, 0)) &&
351 !(ret = cxusb_ctrl_msg(d, 0x15, NULL, 0, NULL, 0)) &&
352 !(ret = cxusb_ctrl_msg(d, 0x17, NULL, 0, NULL, 0)) && 0);
356 * FIXME: We don't know why, but we need to configure the
357 * lgdt3303 with the register settings below on resume
361 static const u8 bufs[] = {
362 0x0e, 0x2, 0x00, 0x7f,
363 0x0e, 0x2, 0x02, 0xfe,
364 0x0e, 0x2, 0x02, 0x01,
365 0x0e, 0x2, 0x00, 0x03,
366 0x0e, 0x2, 0x0d, 0x40,
367 0x0e, 0x2, 0x0e, 0x87,
368 0x0e, 0x2, 0x0f, 0x8e,
369 0x0e, 0x2, 0x10, 0x01,
370 0x0e, 0x2, 0x14, 0xd7,
371 0x0e, 0x2, 0x47, 0x88,
374 for (i = 0; i < ARRAY_SIZE(bufs); i += 4 / sizeof(u8)) {
375 ret = cxusb_ctrl_msg(d, CMD_I2C_WRITE,
376 bufs + i, 4, &buf, 1);
386 static int cxusb_bluebird_power_ctrl(struct dvb_usb_device *d, int onoff)
391 return cxusb_ctrl_msg(d, CMD_POWER_ON, &b, 1, NULL, 0);
396 static int cxusb_nano2_power_ctrl(struct dvb_usb_device *d, int onoff)
400 rc = cxusb_power_ctrl(d, onoff);
402 cxusb_nano2_led(d, 0);
407 static int cxusb_d680_dmb_power_ctrl(struct dvb_usb_device *d, int onoff)
412 ret = cxusb_power_ctrl(d, onoff);
417 cxusb_ctrl_msg(d, CMD_DIGITAL, NULL, 0, &b, 1);
422 static int cxusb_streaming_ctrl(struct dvb_usb_adapter *adap, int onoff)
424 struct dvb_usb_device *dvbdev = adap->dev;
425 bool is_medion = dvbdev->props.devices[0].warm_ids[0] ==
426 &cxusb_table[MEDION_MD95700];
427 u8 buf[2] = { 0x03, 0x00 };
429 if (is_medion && onoff) {
432 ret = cxusb_medion_get(dvbdev, CXUSB_OPEN_DIGITAL);
438 cxusb_ctrl_msg(dvbdev, CMD_STREAMING_ON, buf, 2, NULL, 0);
440 cxusb_ctrl_msg(dvbdev, CMD_STREAMING_OFF, NULL, 0, NULL, 0);
442 if (is_medion && !onoff)
443 cxusb_medion_put(dvbdev);
448 static int cxusb_aver_streaming_ctrl(struct dvb_usb_adapter *adap, int onoff)
451 cxusb_ctrl_msg(adap->dev, CMD_AVER_STREAM_ON, NULL, 0, NULL, 0);
453 cxusb_ctrl_msg(adap->dev, CMD_AVER_STREAM_OFF,
458 static void cxusb_d680_dmb_drain_message(struct dvb_usb_device *d)
460 int ep = d->props.generic_bulk_ctrl_endpoint;
461 const int timeout = 100;
462 const int junk_len = 32;
466 /* Discard remaining data in video pipe */
467 junk = kmalloc(junk_len, GFP_KERNEL);
471 if (usb_bulk_msg(d->udev,
472 usb_rcvbulkpipe(d->udev, ep),
473 junk, junk_len, &rd_count, timeout) < 0)
481 static void cxusb_d680_dmb_drain_video(struct dvb_usb_device *d)
483 struct usb_data_stream_properties *p = &d->props.adapter[0].fe[0].stream;
484 const int timeout = 100;
485 const int junk_len = p->u.bulk.buffersize;
489 /* Discard remaining data in video pipe */
490 junk = kmalloc(junk_len, GFP_KERNEL);
494 if (usb_bulk_msg(d->udev,
495 usb_rcvbulkpipe(d->udev, p->endpoint),
496 junk, junk_len, &rd_count, timeout) < 0)
504 static int cxusb_d680_dmb_streaming_ctrl(struct dvb_usb_adapter *adap,
508 u8 buf[2] = { 0x03, 0x00 };
510 cxusb_d680_dmb_drain_video(adap->dev);
511 return cxusb_ctrl_msg(adap->dev, CMD_STREAMING_ON,
512 buf, sizeof(buf), NULL, 0);
514 int ret = cxusb_ctrl_msg(adap->dev,
515 CMD_STREAMING_OFF, NULL, 0, NULL, 0);
520 static int cxusb_rc_query(struct dvb_usb_device *d)
524 cxusb_ctrl_msg(d, CMD_GET_IR_CODE, NULL, 0, ircode, 4);
526 if (ircode[2] || ircode[3])
527 rc_keydown(d->rc_dev, RC_PROTO_NEC,
528 RC_SCANCODE_NEC(~ircode[2] & 0xff, ircode[3]), 0);
532 static int cxusb_bluebird2_rc_query(struct dvb_usb_device *d)
535 struct i2c_msg msg = {
542 if (cxusb_i2c_xfer(&d->i2c_adap, &msg, 1) != 1)
545 if (ircode[1] || ircode[2])
546 rc_keydown(d->rc_dev, RC_PROTO_NEC,
547 RC_SCANCODE_NEC(~ircode[1] & 0xff, ircode[2]), 0);
551 static int cxusb_d680_dmb_rc_query(struct dvb_usb_device *d)
555 if (cxusb_ctrl_msg(d, 0x10, NULL, 0, ircode, 2) < 0)
558 if (ircode[0] || ircode[1])
559 rc_keydown(d->rc_dev, RC_PROTO_UNKNOWN,
560 RC_SCANCODE_RC5(ircode[0], ircode[1]), 0);
564 static int cxusb_dee1601_demod_init(struct dvb_frontend *fe)
566 static u8 clock_config[] = { CLOCK_CTL, 0x38, 0x28 };
567 static u8 reset[] = { RESET, 0x80 };
568 static u8 adc_ctl_1_cfg[] = { ADC_CTL_1, 0x40 };
569 static u8 agc_cfg[] = { AGC_TARGET, 0x28, 0x20 };
570 static u8 gpp_ctl_cfg[] = { GPP_CTL, 0x33 };
571 static u8 capt_range_cfg[] = { CAPT_RANGE, 0x32 };
573 mt352_write(fe, clock_config, sizeof(clock_config));
575 mt352_write(fe, reset, sizeof(reset));
576 mt352_write(fe, adc_ctl_1_cfg, sizeof(adc_ctl_1_cfg));
578 mt352_write(fe, agc_cfg, sizeof(agc_cfg));
579 mt352_write(fe, gpp_ctl_cfg, sizeof(gpp_ctl_cfg));
580 mt352_write(fe, capt_range_cfg, sizeof(capt_range_cfg));
585 static int cxusb_mt352_demod_init(struct dvb_frontend *fe)
587 /* used in both lgz201 and th7579 */
588 static u8 clock_config[] = { CLOCK_CTL, 0x38, 0x29 };
589 static u8 reset[] = { RESET, 0x80 };
590 static u8 adc_ctl_1_cfg[] = { ADC_CTL_1, 0x40 };
591 static u8 agc_cfg[] = { AGC_TARGET, 0x24, 0x20 };
592 static u8 gpp_ctl_cfg[] = { GPP_CTL, 0x33 };
593 static u8 capt_range_cfg[] = { CAPT_RANGE, 0x32 };
595 mt352_write(fe, clock_config, sizeof(clock_config));
597 mt352_write(fe, reset, sizeof(reset));
598 mt352_write(fe, adc_ctl_1_cfg, sizeof(adc_ctl_1_cfg));
600 mt352_write(fe, agc_cfg, sizeof(agc_cfg));
601 mt352_write(fe, gpp_ctl_cfg, sizeof(gpp_ctl_cfg));
602 mt352_write(fe, capt_range_cfg, sizeof(capt_range_cfg));
606 static struct cx22702_config cxusb_cx22702_config = {
607 .demod_address = 0x63,
608 .output_mode = CX22702_PARALLEL_OUTPUT,
611 static struct lgdt330x_config cxusb_lgdt3303_config = {
612 .demod_chip = LGDT3303,
615 static struct lgdt330x_config cxusb_aver_lgdt3303_config = {
616 .demod_chip = LGDT3303,
617 .clock_polarity_flip = 2,
620 static struct mt352_config cxusb_dee1601_config = {
621 .demod_address = 0x0f,
622 .demod_init = cxusb_dee1601_demod_init,
625 static struct zl10353_config cxusb_zl10353_dee1601_config = {
626 .demod_address = 0x0f,
630 static struct mt352_config cxusb_mt352_config = {
631 /* used in both lgz201 and th7579 */
632 .demod_address = 0x0f,
633 .demod_init = cxusb_mt352_demod_init,
636 static struct zl10353_config cxusb_zl10353_xc3028_config = {
637 .demod_address = 0x0f,
643 static struct zl10353_config cxusb_zl10353_xc3028_config_no_i2c_gate = {
644 .demod_address = 0x0f,
648 .disable_i2c_gate_ctrl = 1,
651 static struct mt352_config cxusb_mt352_xc3028_config = {
652 .demod_address = 0x0f,
655 .demod_init = cxusb_mt352_demod_init,
658 /* FIXME: needs tweaking */
659 static struct mxl5005s_config aver_a868r_tuner = {
661 .if_freq = 6000000UL,
662 .xtal_freq = CRYSTAL_FREQ_16000000HZ,
663 .agc_mode = MXL_SINGLE_AGC,
664 .tracking_filter = MXL_TF_C,
665 .rssi_enable = MXL_RSSI_ENABLE,
666 .cap_select = MXL_CAP_SEL_ENABLE,
667 .div_out = MXL_DIV_OUT_4,
668 .clock_out = MXL_CLOCK_OUT_DISABLE,
669 .output_load = MXL5005S_IF_OUTPUT_LOAD_200_OHM,
670 .top = MXL5005S_TOP_25P2,
671 .mod_mode = MXL_DIGITAL_MODE,
672 .if_mode = MXL_ZERO_IF,
673 .AgcMasterByte = 0x00,
676 /* FIXME: needs tweaking */
677 static struct mxl5005s_config d680_dmb_tuner = {
679 .if_freq = 36125000UL,
680 .xtal_freq = CRYSTAL_FREQ_16000000HZ,
681 .agc_mode = MXL_SINGLE_AGC,
682 .tracking_filter = MXL_TF_C,
683 .rssi_enable = MXL_RSSI_ENABLE,
684 .cap_select = MXL_CAP_SEL_ENABLE,
685 .div_out = MXL_DIV_OUT_4,
686 .clock_out = MXL_CLOCK_OUT_DISABLE,
687 .output_load = MXL5005S_IF_OUTPUT_LOAD_200_OHM,
688 .top = MXL5005S_TOP_25P2,
689 .mod_mode = MXL_DIGITAL_MODE,
690 .if_mode = MXL_ZERO_IF,
691 .AgcMasterByte = 0x00,
694 static struct max2165_config mygica_d689_max2165_cfg = {
699 /* Callbacks for DVB USB */
700 static int cxusb_fmd1216me_tuner_attach(struct dvb_usb_adapter *adap)
702 struct dvb_usb_device *dvbdev = adap->dev;
703 bool is_medion = dvbdev->props.devices[0].warm_ids[0] ==
704 &cxusb_table[MEDION_MD95700];
706 dvb_attach(simple_tuner_attach, adap->fe_adap[0].fe,
707 &dvbdev->i2c_adap, 0x61,
708 TUNER_PHILIPS_FMD1216ME_MK3);
710 if (is_medion && adap->fe_adap[0].fe)
712 * make sure that DVB core won't put to sleep (reset, really)
713 * tuner when we might be open in analog mode
715 adap->fe_adap[0].fe->ops.tuner_ops.sleep = NULL;
720 static int cxusb_dee1601_tuner_attach(struct dvb_usb_adapter *adap)
722 dvb_attach(dvb_pll_attach, adap->fe_adap[0].fe, 0x61,
723 NULL, DVB_PLL_THOMSON_DTT7579);
727 static int cxusb_lgz201_tuner_attach(struct dvb_usb_adapter *adap)
729 dvb_attach(dvb_pll_attach, adap->fe_adap[0].fe, 0x61,
730 NULL, DVB_PLL_LG_Z201);
734 static int cxusb_dtt7579_tuner_attach(struct dvb_usb_adapter *adap)
736 dvb_attach(dvb_pll_attach, adap->fe_adap[0].fe, 0x60,
737 NULL, DVB_PLL_THOMSON_DTT7579);
741 static int cxusb_lgh064f_tuner_attach(struct dvb_usb_adapter *adap)
743 dvb_attach(simple_tuner_attach, adap->fe_adap[0].fe,
744 &adap->dev->i2c_adap, 0x61, TUNER_LG_TDVS_H06XF);
748 static int dvico_bluebird_xc2028_callback(void *ptr, int component,
749 int command, int arg)
751 struct dvb_usb_adapter *adap = ptr;
752 struct dvb_usb_device *d = adap->dev;
755 case XC2028_TUNER_RESET:
756 deb_info("%s: XC2028_TUNER_RESET %d\n", __func__, arg);
757 cxusb_bluebird_gpio_pulse(d, 0x01, 1);
759 case XC2028_RESET_CLK:
760 deb_info("%s: XC2028_RESET_CLK %d\n", __func__, arg);
762 case XC2028_I2C_FLUSH:
765 deb_info("%s: unknown command %d, arg %d\n", __func__,
773 static int cxusb_dvico_xc3028_tuner_attach(struct dvb_usb_adapter *adap)
775 struct dvb_frontend *fe;
776 struct xc2028_config cfg = {
777 .i2c_adap = &adap->dev->i2c_adap,
780 static struct xc2028_ctrl ctl = {
781 .fname = XC2028_DEFAULT_FIRMWARE,
783 .demod = XC3028_FE_ZARLINK456,
786 /* FIXME: generalize & move to common area */
787 adap->fe_adap[0].fe->callback = dvico_bluebird_xc2028_callback;
789 fe = dvb_attach(xc2028_attach, adap->fe_adap[0].fe, &cfg);
790 if (!fe || !fe->ops.tuner_ops.set_config)
793 fe->ops.tuner_ops.set_config(fe, &ctl);
798 static int cxusb_mxl5003s_tuner_attach(struct dvb_usb_adapter *adap)
800 dvb_attach(mxl5005s_attach, adap->fe_adap[0].fe,
801 &adap->dev->i2c_adap, &aver_a868r_tuner);
805 static int cxusb_d680_dmb_tuner_attach(struct dvb_usb_adapter *adap)
807 struct dvb_frontend *fe;
809 fe = dvb_attach(mxl5005s_attach, adap->fe_adap[0].fe,
810 &adap->dev->i2c_adap, &d680_dmb_tuner);
811 return (!fe) ? -EIO : 0;
814 static int cxusb_mygica_d689_tuner_attach(struct dvb_usb_adapter *adap)
816 struct dvb_frontend *fe;
818 fe = dvb_attach(max2165_attach, adap->fe_adap[0].fe,
819 &adap->dev->i2c_adap, &mygica_d689_max2165_cfg);
820 return (!fe) ? -EIO : 0;
823 static int cxusb_medion_fe_ts_bus_ctrl(struct dvb_frontend *fe, int acquire)
825 struct dvb_usb_adapter *adap = fe->dvb->priv;
826 struct dvb_usb_device *dvbdev = adap->dev;
829 return cxusb_medion_get(dvbdev, CXUSB_OPEN_DIGITAL);
831 cxusb_medion_put(dvbdev);
836 static int cxusb_medion_set_mode(struct dvb_usb_device *dvbdev, bool digital)
838 struct cxusb_state *st = dvbdev->priv;
844 * switching mode while doing an I2C transaction often causes
845 * the device to crash
847 mutex_lock(&dvbdev->i2c_mutex);
850 ret = usb_set_interface(dvbdev->udev, 0, 6);
852 dev_err(&dvbdev->udev->dev,
853 "digital interface selection failed (%d)\n",
858 ret = usb_set_interface(dvbdev->udev, 0, 1);
860 dev_err(&dvbdev->udev->dev,
861 "analog interface selection failed (%d)\n",
867 /* pipes need to be cleared after setting interface */
868 ret = usb_clear_halt(dvbdev->udev, usb_rcvbulkpipe(dvbdev->udev, 1));
870 dev_warn(&dvbdev->udev->dev,
871 "clear halt on IN pipe failed (%d)\n",
874 ret = usb_clear_halt(dvbdev->udev, usb_sndbulkpipe(dvbdev->udev, 1));
876 dev_warn(&dvbdev->udev->dev,
877 "clear halt on OUT pipe failed (%d)\n",
880 ret = cxusb_ctrl_msg(dvbdev, digital ? CMD_DIGITAL : CMD_ANALOG,
883 dev_err(&dvbdev->udev->dev, "mode switch failed (%d)\n",
888 /* mode switch seems to reset GPIO states */
889 for (i = 0; i < ARRAY_SIZE(st->gpio_write_refresh); i++)
890 st->gpio_write_refresh[i] = true;
893 mutex_unlock(&dvbdev->i2c_mutex);
898 static int cxusb_cx22702_frontend_attach(struct dvb_usb_adapter *adap)
900 struct dvb_usb_device *dvbdev = adap->dev;
901 bool is_medion = dvbdev->props.devices[0].warm_ids[0] ==
902 &cxusb_table[MEDION_MD95700];
907 ret = cxusb_medion_set_mode(dvbdev, true);
912 adap->fe_adap[0].fe = dvb_attach(cx22702_attach, &cxusb_cx22702_config,
914 if (!adap->fe_adap[0].fe)
918 adap->fe_adap[0].fe->ops.ts_bus_ctrl =
919 cxusb_medion_fe_ts_bus_ctrl;
924 static int cxusb_lgdt3303_frontend_attach(struct dvb_usb_adapter *adap)
926 if (usb_set_interface(adap->dev->udev, 0, 7) < 0)
927 err("set interface failed");
929 cxusb_ctrl_msg(adap->dev, CMD_DIGITAL, NULL, 0, NULL, 0);
931 adap->fe_adap[0].fe = dvb_attach(lgdt330x_attach,
932 &cxusb_lgdt3303_config,
934 &adap->dev->i2c_adap);
935 if (adap->fe_adap[0].fe)
941 static int cxusb_aver_lgdt3303_frontend_attach(struct dvb_usb_adapter *adap)
943 adap->fe_adap[0].fe = dvb_attach(lgdt330x_attach,
944 &cxusb_aver_lgdt3303_config,
946 &adap->dev->i2c_adap);
947 if (adap->fe_adap[0].fe)
953 static int cxusb_mt352_frontend_attach(struct dvb_usb_adapter *adap)
955 /* used in both lgz201 and th7579 */
956 if (usb_set_interface(adap->dev->udev, 0, 0) < 0)
957 err("set interface failed");
959 cxusb_ctrl_msg(adap->dev, CMD_DIGITAL, NULL, 0, NULL, 0);
961 adap->fe_adap[0].fe = dvb_attach(mt352_attach, &cxusb_mt352_config,
962 &adap->dev->i2c_adap);
963 if (adap->fe_adap[0].fe)
969 static int cxusb_dee1601_frontend_attach(struct dvb_usb_adapter *adap)
971 if (usb_set_interface(adap->dev->udev, 0, 0) < 0)
972 err("set interface failed");
974 cxusb_ctrl_msg(adap->dev, CMD_DIGITAL, NULL, 0, NULL, 0);
976 adap->fe_adap[0].fe = dvb_attach(mt352_attach, &cxusb_dee1601_config,
977 &adap->dev->i2c_adap);
978 if (adap->fe_adap[0].fe)
981 adap->fe_adap[0].fe = dvb_attach(zl10353_attach,
982 &cxusb_zl10353_dee1601_config,
983 &adap->dev->i2c_adap);
984 if (adap->fe_adap[0].fe)
990 static int cxusb_dualdig4_frontend_attach(struct dvb_usb_adapter *adap)
994 struct i2c_msg msg = {
1001 if (usb_set_interface(adap->dev->udev, 0, 1) < 0)
1002 err("set interface failed");
1004 cxusb_ctrl_msg(adap->dev, CMD_DIGITAL, NULL, 0, NULL, 0);
1006 /* reset the tuner and demodulator */
1007 cxusb_bluebird_gpio_rw(adap->dev, 0x04, 0);
1008 cxusb_bluebird_gpio_pulse(adap->dev, 0x01, 1);
1009 cxusb_bluebird_gpio_pulse(adap->dev, 0x02, 1);
1011 adap->fe_adap[0].fe =
1012 dvb_attach(zl10353_attach,
1013 &cxusb_zl10353_xc3028_config_no_i2c_gate,
1014 &adap->dev->i2c_adap);
1015 if (!adap->fe_adap[0].fe)
1018 /* try to determine if there is no IR decoder on the I2C bus */
1019 for (i = 0; adap->dev->props.rc.core.rc_codes && i < 5; i++) {
1021 if (cxusb_i2c_xfer(&adap->dev->i2c_adap, &msg, 1) != 1)
1023 if (ircode[0] == 0 && ircode[1] == 0)
1025 if (ircode[2] + ircode[3] != 0xff) {
1027 adap->dev->props.rc.core.rc_codes = NULL;
1028 info("No IR receiver detected on this device.");
1036 static struct dibx000_agc_config dib7070_agc_config = {
1037 .band_caps = BAND_UHF | BAND_VHF | BAND_LBAND | BAND_SBAND,
1040 * P_agc_use_sd_mod1=0, P_agc_use_sd_mod2=0, P_agc_freq_pwm_div=5,
1041 * P_agc_inv_pwm1=0, P_agc_inv_pwm2=0, P_agc_inh_dc_rv_est=0,
1042 * P_agc_time_est=3, P_agc_freeze=0, P_agc_nb_est=5, P_agc_write=0
1044 .setup = (0 << 15) | (0 << 14) | (5 << 11) | (0 << 10) | (0 << 9) |
1045 (0 << 8) | (3 << 5) | (0 << 4) | (5 << 1) | (0 << 0),
1047 .time_stabiliz = 10,
1071 .perform_agc_softsplit = 0,
1074 static struct dibx000_bandwidth_config dib7070_bw_config_12_mhz = {
1084 .IO_CLK_en_core = 1,
1087 /* refsel, sel, freq_15k */
1088 .sad_cfg = (3 << 14) | (1 << 12) | (524 << 0),
1089 .ifreq = (0 << 25) | 0,
1091 .xtal_hz = 12000000,
1094 static struct dib7000p_config cxusb_dualdig4_rev2_config = {
1095 .output_mode = OUTMODE_MPEG2_PAR_GATED_CLK,
1096 .output_mpeg2_in_188_bytes = 1,
1098 .agc_config_count = 1,
1099 .agc = &dib7070_agc_config,
1100 .bw = &dib7070_bw_config_12_mhz,
1101 .tuner_is_baseband = 1,
1107 .gpio_pwm_pos = DIB7000P_GPIO_DEFAULT_PWM_POS,
1109 .hostbus_diversity = 1,
1112 struct dib0700_adapter_state {
1113 int (*set_param_save)(struct dvb_frontend *fe);
1114 struct dib7000p_ops dib7000p_ops;
1117 static int cxusb_dualdig4_rev2_frontend_attach(struct dvb_usb_adapter *adap)
1119 struct dib0700_adapter_state *state = adap->priv;
1121 if (usb_set_interface(adap->dev->udev, 0, 1) < 0)
1122 err("set interface failed");
1124 cxusb_ctrl_msg(adap->dev, CMD_DIGITAL, NULL, 0, NULL, 0);
1126 cxusb_bluebird_gpio_pulse(adap->dev, 0x02, 1);
1128 if (!dvb_attach(dib7000p_attach, &state->dib7000p_ops))
1131 if (state->dib7000p_ops.i2c_enumeration(&adap->dev->i2c_adap, 1, 18,
1132 &cxusb_dualdig4_rev2_config) < 0) {
1133 pr_warn("Unable to enumerate dib7000p\n");
1137 adap->fe_adap[0].fe = state->dib7000p_ops.init(&adap->dev->i2c_adap,
1139 &cxusb_dualdig4_rev2_config);
1140 if (!adap->fe_adap[0].fe)
1146 static int dib7070_tuner_reset(struct dvb_frontend *fe, int onoff)
1148 struct dvb_usb_adapter *adap = fe->dvb->priv;
1149 struct dib0700_adapter_state *state = adap->priv;
1151 return state->dib7000p_ops.set_gpio(fe, 8, 0, !onoff);
1154 static int dib7070_tuner_sleep(struct dvb_frontend *fe, int onoff)
1159 static struct dib0070_config dib7070p_dib0070_config = {
1160 .i2c_address = DEFAULT_DIB0070_I2C_ADDRESS,
1161 .reset = dib7070_tuner_reset,
1162 .sleep = dib7070_tuner_sleep,
1166 static int dib7070_set_param_override(struct dvb_frontend *fe)
1168 struct dtv_frontend_properties *p = &fe->dtv_property_cache;
1169 struct dvb_usb_adapter *adap = fe->dvb->priv;
1170 struct dib0700_adapter_state *state = adap->priv;
1173 u8 band = BAND_OF_FREQUENCY(p->frequency / 1000);
1185 state->dib7000p_ops.set_wbd_ref(fe, offset + dib0070_wbd_offset(fe));
1187 return state->set_param_save(fe);
1190 static int cxusb_dualdig4_rev2_tuner_attach(struct dvb_usb_adapter *adap)
1192 struct dib0700_adapter_state *st = adap->priv;
1193 struct i2c_adapter *tun_i2c;
1196 * No need to call dvb7000p_attach here, as it was called
1197 * already, as frontend_attach method is called first, and
1198 * tuner_attach is only called on success.
1200 tun_i2c = st->dib7000p_ops.get_i2c_master(adap->fe_adap[0].fe,
1201 DIBX000_I2C_INTERFACE_TUNER, 1);
1203 if (dvb_attach(dib0070_attach, adap->fe_adap[0].fe, tun_i2c,
1204 &dib7070p_dib0070_config) == NULL)
1207 st->set_param_save = adap->fe_adap[0].fe->ops.tuner_ops.set_params;
1208 adap->fe_adap[0].fe->ops.tuner_ops.set_params = dib7070_set_param_override;
1212 static int cxusb_nano2_frontend_attach(struct dvb_usb_adapter *adap)
1214 if (usb_set_interface(adap->dev->udev, 0, 1) < 0)
1215 err("set interface failed");
1217 cxusb_ctrl_msg(adap->dev, CMD_DIGITAL, NULL, 0, NULL, 0);
1219 /* reset the tuner and demodulator */
1220 cxusb_bluebird_gpio_rw(adap->dev, 0x04, 0);
1221 cxusb_bluebird_gpio_pulse(adap->dev, 0x01, 1);
1222 cxusb_bluebird_gpio_pulse(adap->dev, 0x02, 1);
1224 adap->fe_adap[0].fe = dvb_attach(zl10353_attach,
1225 &cxusb_zl10353_xc3028_config,
1226 &adap->dev->i2c_adap);
1227 if (adap->fe_adap[0].fe)
1230 adap->fe_adap[0].fe = dvb_attach(mt352_attach,
1231 &cxusb_mt352_xc3028_config,
1232 &adap->dev->i2c_adap);
1233 if (adap->fe_adap[0].fe)
1239 static struct lgs8gxx_config d680_lgs8gl5_cfg = {
1240 .prod = LGS8GXX_PROD_LGS8GL5,
1241 .demod_address = 0x19,
1245 .if_clk_freq = 30400, /* 30.4 MHz */
1246 .if_freq = 5725, /* 5.725 MHz */
1253 static int cxusb_d680_dmb_frontend_attach(struct dvb_usb_adapter *adap)
1255 struct dvb_usb_device *d = adap->dev;
1258 /* Select required USB configuration */
1259 if (usb_set_interface(d->udev, 0, 0) < 0)
1260 err("set interface failed");
1262 /* Unblock all USB pipes */
1263 usb_clear_halt(d->udev,
1264 usb_sndbulkpipe(d->udev,
1265 d->props.generic_bulk_ctrl_endpoint));
1266 usb_clear_halt(d->udev,
1267 usb_rcvbulkpipe(d->udev,
1268 d->props.generic_bulk_ctrl_endpoint));
1269 usb_clear_halt(d->udev,
1270 usb_rcvbulkpipe(d->udev,
1271 d->props.adapter[0].fe[0].stream.endpoint));
1273 /* Drain USB pipes to avoid hang after reboot */
1274 for (n = 0; n < 5; n++) {
1275 cxusb_d680_dmb_drain_message(d);
1276 cxusb_d680_dmb_drain_video(d);
1280 /* Reset the tuner */
1281 if (cxusb_d680_dmb_gpio_tuner(d, 0x07, 0) < 0) {
1282 err("clear tuner gpio failed");
1286 if (cxusb_d680_dmb_gpio_tuner(d, 0x07, 1) < 0) {
1287 err("set tuner gpio failed");
1292 /* Attach frontend */
1293 adap->fe_adap[0].fe = dvb_attach(lgs8gxx_attach,
1294 &d680_lgs8gl5_cfg, &d->i2c_adap);
1295 if (!adap->fe_adap[0].fe)
1301 static struct atbm8830_config mygica_d689_atbm8830_cfg = {
1302 .prod = ATBM8830_PROD_8830,
1303 .demod_address = 0x40,
1305 .ts_sampling_edge = 1,
1307 .osc_clk_freq = 30400, /* in kHz */
1308 .if_freq = 0, /* zero IF */
1315 static int cxusb_mygica_d689_frontend_attach(struct dvb_usb_adapter *adap)
1317 struct dvb_usb_device *d = adap->dev;
1319 /* Select required USB configuration */
1320 if (usb_set_interface(d->udev, 0, 0) < 0)
1321 err("set interface failed");
1323 /* Unblock all USB pipes */
1324 usb_clear_halt(d->udev,
1325 usb_sndbulkpipe(d->udev,
1326 d->props.generic_bulk_ctrl_endpoint));
1327 usb_clear_halt(d->udev,
1328 usb_rcvbulkpipe(d->udev,
1329 d->props.generic_bulk_ctrl_endpoint));
1330 usb_clear_halt(d->udev,
1331 usb_rcvbulkpipe(d->udev,
1332 d->props.adapter[0].fe[0].stream.endpoint));
1334 /* Reset the tuner */
1335 if (cxusb_d680_dmb_gpio_tuner(d, 0x07, 0) < 0) {
1336 err("clear tuner gpio failed");
1340 if (cxusb_d680_dmb_gpio_tuner(d, 0x07, 1) < 0) {
1341 err("set tuner gpio failed");
1346 /* Attach frontend */
1347 adap->fe_adap[0].fe = dvb_attach(atbm8830_attach,
1348 &mygica_d689_atbm8830_cfg,
1350 if (!adap->fe_adap[0].fe)
1357 * DViCO has shipped two devices with the same USB ID, but only one of them
1358 * needs a firmware download. Check the device class details to see if they
1359 * have non-default values to decide whether the device is actually cold or
1360 * not, and forget a match if it turns out we selected the wrong device.
1362 static int bluebird_fx2_identify_state(struct usb_device *udev,
1363 struct dvb_usb_device_properties *props,
1364 struct dvb_usb_device_description **desc,
1367 int wascold = *cold;
1369 *cold = udev->descriptor.bDeviceClass == 0xff &&
1370 udev->descriptor.bDeviceSubClass == 0xff &&
1371 udev->descriptor.bDeviceProtocol == 0xff;
1373 if (*cold && !wascold)
1380 * DViCO bluebird firmware needs the "warm" product ID to be patched into the
1381 * firmware file before download.
1384 static const int dvico_firmware_id_offsets[] = { 6638, 3204 };
1385 static int bluebird_patch_dvico_firmware_download(struct usb_device *udev,
1386 const struct firmware *fw)
1390 for (pos = 0; pos < ARRAY_SIZE(dvico_firmware_id_offsets); pos++) {
1391 int idoff = dvico_firmware_id_offsets[pos];
1393 if (fw->size < idoff + 4)
1396 if (fw->data[idoff] == (USB_VID_DVICO & 0xff) &&
1397 fw->data[idoff + 1] == USB_VID_DVICO >> 8) {
1398 struct firmware new_fw;
1399 u8 *new_fw_data = vmalloc(fw->size);
1405 memcpy(new_fw_data, fw->data, fw->size);
1406 new_fw.size = fw->size;
1407 new_fw.data = new_fw_data;
1409 new_fw_data[idoff + 2] =
1410 le16_to_cpu(udev->descriptor.idProduct) + 1;
1411 new_fw_data[idoff + 3] =
1412 le16_to_cpu(udev->descriptor.idProduct) >> 8;
1414 ret = usb_cypress_load_firmware(udev, &new_fw,
1424 int cxusb_medion_get(struct dvb_usb_device *dvbdev,
1425 enum cxusb_open_type open_type)
1427 struct cxusb_medion_dev *cxdev = dvbdev->priv;
1430 mutex_lock(&cxdev->open_lock);
1432 if (WARN_ON((cxdev->open_type == CXUSB_OPEN_INIT ||
1433 cxdev->open_type == CXUSB_OPEN_NONE) &&
1434 cxdev->open_ctr != 0)) {
1439 if (cxdev->open_type == CXUSB_OPEN_INIT) {
1444 if (cxdev->open_ctr == 0) {
1445 if (cxdev->open_type != open_type) {
1446 deb_info("will acquire and switch to %s\n",
1447 open_type == CXUSB_OPEN_ANALOG ?
1448 "analog" : "digital");
1450 if (open_type == CXUSB_OPEN_ANALOG) {
1451 ret = _cxusb_power_ctrl(dvbdev, 1);
1453 dev_warn(&dvbdev->udev->dev,
1454 "powerup for analog switch failed (%d)\n",
1457 ret = cxusb_medion_set_mode(dvbdev, false);
1461 ret = cxusb_medion_analog_init(dvbdev);
1464 } else { /* digital */
1465 ret = _cxusb_power_ctrl(dvbdev, 1);
1467 dev_warn(&dvbdev->udev->dev,
1468 "powerup for digital switch failed (%d)\n",
1471 ret = cxusb_medion_set_mode(dvbdev, true);
1476 cxdev->open_type = open_type;
1478 deb_info("reacquired idle %s\n",
1479 open_type == CXUSB_OPEN_ANALOG ?
1480 "analog" : "digital");
1483 cxdev->open_ctr = 1;
1484 } else if (cxdev->open_type == open_type) {
1486 deb_info("acquired %s\n", open_type == CXUSB_OPEN_ANALOG ?
1487 "analog" : "digital");
1493 mutex_unlock(&cxdev->open_lock);
1498 void cxusb_medion_put(struct dvb_usb_device *dvbdev)
1500 struct cxusb_medion_dev *cxdev = dvbdev->priv;
1502 mutex_lock(&cxdev->open_lock);
1504 if (cxdev->open_type == CXUSB_OPEN_INIT) {
1505 WARN_ON(cxdev->open_ctr != 0);
1506 cxdev->open_type = CXUSB_OPEN_NONE;
1510 if (!WARN_ON(cxdev->open_ctr < 1)) {
1513 deb_info("release %s\n",
1514 cxdev->open_type == CXUSB_OPEN_ANALOG ?
1515 "analog" : "digital");
1519 mutex_unlock(&cxdev->open_lock);
1522 /* DVB USB Driver stuff */
1523 static struct dvb_usb_device_properties cxusb_medion_properties;
1524 static struct dvb_usb_device_properties cxusb_bluebird_lgh064f_properties;
1525 static struct dvb_usb_device_properties cxusb_bluebird_dee1601_properties;
1526 static struct dvb_usb_device_properties cxusb_bluebird_lgz201_properties;
1527 static struct dvb_usb_device_properties cxusb_bluebird_dtt7579_properties;
1528 static struct dvb_usb_device_properties cxusb_bluebird_dualdig4_properties;
1529 static struct dvb_usb_device_properties cxusb_bluebird_dualdig4_rev2_properties;
1530 static struct dvb_usb_device_properties cxusb_bluebird_nano2_properties;
1531 static struct dvb_usb_device_properties cxusb_bluebird_nano2_needsfirmware_properties;
1532 static struct dvb_usb_device_properties cxusb_aver_a868r_properties;
1533 static struct dvb_usb_device_properties cxusb_d680_dmb_properties;
1534 static struct dvb_usb_device_properties cxusb_mygica_d689_properties;
1536 static int cxusb_medion_priv_init(struct dvb_usb_device *dvbdev)
1538 struct cxusb_medion_dev *cxdev = dvbdev->priv;
1540 cxdev->dvbdev = dvbdev;
1541 cxdev->open_type = CXUSB_OPEN_INIT;
1542 mutex_init(&cxdev->open_lock);
1547 static void cxusb_medion_priv_destroy(struct dvb_usb_device *dvbdev)
1549 struct cxusb_medion_dev *cxdev = dvbdev->priv;
1551 mutex_destroy(&cxdev->open_lock);
1554 static bool cxusb_medion_check_altsetting(struct usb_host_interface *as)
1558 for (ctr = 0; ctr < as->desc.bNumEndpoints; ctr++) {
1559 if ((as->endpoint[ctr].desc.bEndpointAddress &
1560 USB_ENDPOINT_NUMBER_MASK) != 2)
1563 if (as->endpoint[ctr].desc.bEndpointAddress & USB_DIR_IN &&
1564 ((as->endpoint[ctr].desc.bmAttributes &
1565 USB_ENDPOINT_XFERTYPE_MASK) == USB_ENDPOINT_XFER_ISOC))
1574 static bool cxusb_medion_check_intf(struct usb_interface *intf)
1578 if (intf->num_altsetting < 2) {
1579 dev_err(intf->usb_dev, "no alternate interface");
1584 for (ctr = 0; ctr < intf->num_altsetting; ctr++) {
1585 if (intf->altsetting[ctr].desc.bAlternateSetting != 1)
1588 if (cxusb_medion_check_altsetting(&intf->altsetting[ctr]))
1594 dev_err(intf->usb_dev, "no iso interface");
1599 static int cxusb_probe(struct usb_interface *intf,
1600 const struct usb_device_id *id)
1602 struct dvb_usb_device *dvbdev;
1606 if (!dvb_usb_device_init(intf, &cxusb_medion_properties,
1607 THIS_MODULE, &dvbdev, adapter_nr)) {
1608 if (!cxusb_medion_check_intf(intf)) {
1613 _cxusb_power_ctrl(dvbdev, 1);
1614 ret = cxusb_medion_set_mode(dvbdev, false);
1618 ret = cxusb_medion_register_analog(dvbdev);
1620 cxusb_medion_set_mode(dvbdev, true);
1621 _cxusb_power_ctrl(dvbdev, 0);
1626 /* release device from INIT mode to normal operation */
1627 cxusb_medion_put(dvbdev);
1630 } else if (!dvb_usb_device_init(intf,
1631 &cxusb_bluebird_lgh064f_properties,
1632 THIS_MODULE, NULL, adapter_nr) ||
1633 !dvb_usb_device_init(intf,
1634 &cxusb_bluebird_dee1601_properties,
1635 THIS_MODULE, NULL, adapter_nr) ||
1636 !dvb_usb_device_init(intf,
1637 &cxusb_bluebird_lgz201_properties,
1638 THIS_MODULE, NULL, adapter_nr) ||
1639 !dvb_usb_device_init(intf,
1640 &cxusb_bluebird_dtt7579_properties,
1641 THIS_MODULE, NULL, adapter_nr) ||
1642 !dvb_usb_device_init(intf,
1643 &cxusb_bluebird_dualdig4_properties,
1644 THIS_MODULE, NULL, adapter_nr) ||
1645 !dvb_usb_device_init(intf,
1646 &cxusb_bluebird_nano2_properties,
1647 THIS_MODULE, NULL, adapter_nr) ||
1648 !dvb_usb_device_init(intf,
1649 &cxusb_bluebird_nano2_needsfirmware_properties,
1650 THIS_MODULE, NULL, adapter_nr) ||
1651 !dvb_usb_device_init(intf, &cxusb_aver_a868r_properties,
1652 THIS_MODULE, NULL, adapter_nr) ||
1653 !dvb_usb_device_init(intf,
1654 &cxusb_bluebird_dualdig4_rev2_properties,
1655 THIS_MODULE, NULL, adapter_nr) ||
1656 !dvb_usb_device_init(intf, &cxusb_d680_dmb_properties,
1657 THIS_MODULE, NULL, adapter_nr) ||
1658 !dvb_usb_device_init(intf, &cxusb_mygica_d689_properties,
1659 THIS_MODULE, NULL, adapter_nr) ||
1666 dvb_usb_device_exit(intf);
1671 static void cxusb_disconnect(struct usb_interface *intf)
1673 struct dvb_usb_device *d = usb_get_intfdata(intf);
1674 struct cxusb_state *st = d->priv;
1675 struct i2c_client *client;
1677 if (d->props.devices[0].warm_ids[0] == &cxusb_table[MEDION_MD95700])
1678 cxusb_medion_unregister_analog(d);
1680 /* remove I2C client for tuner */
1681 client = st->i2c_client_tuner;
1683 module_put(client->dev.driver->owner);
1684 i2c_unregister_device(client);
1687 /* remove I2C client for demodulator */
1688 client = st->i2c_client_demod;
1690 module_put(client->dev.driver->owner);
1691 i2c_unregister_device(client);
1694 dvb_usb_device_exit(intf);
1697 static struct usb_device_id cxusb_table[NR__cxusb_table_index + 1] = {
1698 [MEDION_MD95700] = {
1699 USB_DEVICE(USB_VID_MEDION, USB_PID_MEDION_MD95700)
1701 [DVICO_BLUEBIRD_LG064F_COLD] = {
1702 USB_DEVICE(USB_VID_DVICO, USB_PID_DVICO_BLUEBIRD_LG064F_COLD)
1704 [DVICO_BLUEBIRD_LG064F_WARM] = {
1705 USB_DEVICE(USB_VID_DVICO, USB_PID_DVICO_BLUEBIRD_LG064F_WARM)
1707 [DVICO_BLUEBIRD_DUAL_1_COLD] = {
1708 USB_DEVICE(USB_VID_DVICO, USB_PID_DVICO_BLUEBIRD_DUAL_1_COLD)
1710 [DVICO_BLUEBIRD_DUAL_1_WARM] = {
1711 USB_DEVICE(USB_VID_DVICO, USB_PID_DVICO_BLUEBIRD_DUAL_1_WARM)
1713 [DVICO_BLUEBIRD_LGZ201_COLD] = {
1714 USB_DEVICE(USB_VID_DVICO, USB_PID_DVICO_BLUEBIRD_LGZ201_COLD)
1716 [DVICO_BLUEBIRD_LGZ201_WARM] = {
1717 USB_DEVICE(USB_VID_DVICO, USB_PID_DVICO_BLUEBIRD_LGZ201_WARM)
1719 [DVICO_BLUEBIRD_TH7579_COLD] = {
1720 USB_DEVICE(USB_VID_DVICO, USB_PID_DVICO_BLUEBIRD_TH7579_COLD)
1722 [DVICO_BLUEBIRD_TH7579_WARM] = {
1723 USB_DEVICE(USB_VID_DVICO, USB_PID_DVICO_BLUEBIRD_TH7579_WARM)
1725 [DIGITALNOW_BLUEBIRD_DUAL_1_COLD] = {
1726 USB_DEVICE(USB_VID_DVICO,
1727 USB_PID_DIGITALNOW_BLUEBIRD_DUAL_1_COLD)
1729 [DIGITALNOW_BLUEBIRD_DUAL_1_WARM] = {
1730 USB_DEVICE(USB_VID_DVICO,
1731 USB_PID_DIGITALNOW_BLUEBIRD_DUAL_1_WARM)
1733 [DVICO_BLUEBIRD_DUAL_2_COLD] = {
1734 USB_DEVICE(USB_VID_DVICO, USB_PID_DVICO_BLUEBIRD_DUAL_2_COLD)
1736 [DVICO_BLUEBIRD_DUAL_2_WARM] = {
1737 USB_DEVICE(USB_VID_DVICO, USB_PID_DVICO_BLUEBIRD_DUAL_2_WARM)
1739 [DVICO_BLUEBIRD_DUAL_4] = {
1740 USB_DEVICE(USB_VID_DVICO, USB_PID_DVICO_BLUEBIRD_DUAL_4)
1742 [DVICO_BLUEBIRD_DVB_T_NANO_2] = {
1743 USB_DEVICE(USB_VID_DVICO, USB_PID_DVICO_BLUEBIRD_DVB_T_NANO_2)
1745 [DVICO_BLUEBIRD_DVB_T_NANO_2_NFW_WARM] = {
1746 USB_DEVICE(USB_VID_DVICO,
1747 USB_PID_DVICO_BLUEBIRD_DVB_T_NANO_2_NFW_WARM)
1749 [AVERMEDIA_VOLAR_A868R] = {
1750 USB_DEVICE(USB_VID_AVERMEDIA, USB_PID_AVERMEDIA_VOLAR_A868R)
1752 [DVICO_BLUEBIRD_DUAL_4_REV_2] = {
1753 USB_DEVICE(USB_VID_DVICO, USB_PID_DVICO_BLUEBIRD_DUAL_4_REV_2)
1755 [CONEXANT_D680_DMB] = {
1756 USB_DEVICE(USB_VID_CONEXANT, USB_PID_CONEXANT_D680_DMB)
1759 USB_DEVICE(USB_VID_CONEXANT, USB_PID_MYGICA_D689)
1761 {} /* Terminating entry */
1763 MODULE_DEVICE_TABLE(usb, cxusb_table);
1765 static struct dvb_usb_device_properties cxusb_medion_properties = {
1766 .caps = DVB_USB_IS_AN_I2C_ADAPTER,
1768 .usb_ctrl = CYPRESS_FX2,
1770 .size_of_priv = sizeof(struct cxusb_medion_dev),
1771 .priv_init = cxusb_medion_priv_init,
1772 .priv_destroy = cxusb_medion_priv_destroy,
1779 .streaming_ctrl = cxusb_streaming_ctrl,
1780 .frontend_attach = cxusb_cx22702_frontend_attach,
1781 .tuner_attach = cxusb_fmd1216me_tuner_attach,
1782 /* parameter for the MPEG2-data transfer */
1796 .power_ctrl = cxusb_power_ctrl,
1798 .i2c_algo = &cxusb_i2c_algo,
1800 .generic_bulk_ctrl_endpoint = 0x01,
1802 .num_device_descs = 1,
1805 "Medion MD95700 (MDUSBTV-HYBRID)",
1807 { &cxusb_table[MEDION_MD95700], NULL },
1812 static struct dvb_usb_device_properties cxusb_bluebird_lgh064f_properties = {
1813 .caps = DVB_USB_IS_AN_I2C_ADAPTER,
1815 .usb_ctrl = DEVICE_SPECIFIC,
1816 .firmware = "dvb-usb-bluebird-01.fw",
1817 .download_firmware = bluebird_patch_dvico_firmware_download,
1819 * use usb alt setting 0 for EP4 transfer (dvb-t),
1820 * use usb alt setting 7 for EP2 transfer (atsc)
1823 .size_of_priv = sizeof(struct cxusb_state),
1830 .streaming_ctrl = cxusb_streaming_ctrl,
1831 .frontend_attach = cxusb_lgdt3303_frontend_attach,
1832 .tuner_attach = cxusb_lgh064f_tuner_attach,
1834 /* parameter for the MPEG2-data transfer */
1849 .power_ctrl = cxusb_bluebird_power_ctrl,
1851 .i2c_algo = &cxusb_i2c_algo,
1855 .rc_codes = RC_MAP_DVICO_PORTABLE,
1856 .module_name = KBUILD_MODNAME,
1857 .rc_query = cxusb_rc_query,
1858 .allowed_protos = RC_PROTO_BIT_NEC,
1861 .generic_bulk_ctrl_endpoint = 0x01,
1863 .num_device_descs = 1,
1865 { "DViCO FusionHDTV5 USB Gold",
1866 { &cxusb_table[DVICO_BLUEBIRD_LG064F_COLD], NULL },
1867 { &cxusb_table[DVICO_BLUEBIRD_LG064F_WARM], NULL },
1872 static struct dvb_usb_device_properties cxusb_bluebird_dee1601_properties = {
1873 .caps = DVB_USB_IS_AN_I2C_ADAPTER,
1875 .usb_ctrl = DEVICE_SPECIFIC,
1876 .firmware = "dvb-usb-bluebird-01.fw",
1877 .download_firmware = bluebird_patch_dvico_firmware_download,
1879 * use usb alt setting 0 for EP4 transfer (dvb-t),
1880 * use usb alt setting 7 for EP2 transfer (atsc)
1883 .size_of_priv = sizeof(struct cxusb_state),
1890 .streaming_ctrl = cxusb_streaming_ctrl,
1891 .frontend_attach = cxusb_dee1601_frontend_attach,
1892 .tuner_attach = cxusb_dee1601_tuner_attach,
1893 /* parameter for the MPEG2-data transfer */
1908 .power_ctrl = cxusb_bluebird_power_ctrl,
1910 .i2c_algo = &cxusb_i2c_algo,
1914 .rc_codes = RC_MAP_DVICO_MCE,
1915 .module_name = KBUILD_MODNAME,
1916 .rc_query = cxusb_rc_query,
1917 .allowed_protos = RC_PROTO_BIT_NEC,
1920 .generic_bulk_ctrl_endpoint = 0x01,
1922 .num_device_descs = 3,
1924 { "DViCO FusionHDTV DVB-T Dual USB",
1925 { &cxusb_table[DVICO_BLUEBIRD_DUAL_1_COLD], NULL },
1926 { &cxusb_table[DVICO_BLUEBIRD_DUAL_1_WARM], NULL },
1928 { "DigitalNow DVB-T Dual USB",
1929 { &cxusb_table[DIGITALNOW_BLUEBIRD_DUAL_1_COLD], NULL },
1930 { &cxusb_table[DIGITALNOW_BLUEBIRD_DUAL_1_WARM], NULL },
1932 { "DViCO FusionHDTV DVB-T Dual Digital 2",
1933 { &cxusb_table[DVICO_BLUEBIRD_DUAL_2_COLD], NULL },
1934 { &cxusb_table[DVICO_BLUEBIRD_DUAL_2_WARM], NULL },
1939 static struct dvb_usb_device_properties cxusb_bluebird_lgz201_properties = {
1940 .caps = DVB_USB_IS_AN_I2C_ADAPTER,
1942 .usb_ctrl = DEVICE_SPECIFIC,
1943 .firmware = "dvb-usb-bluebird-01.fw",
1944 .download_firmware = bluebird_patch_dvico_firmware_download,
1946 * use usb alt setting 0 for EP4 transfer (dvb-t),
1947 * use usb alt setting 7 for EP2 transfer (atsc)
1950 .size_of_priv = sizeof(struct cxusb_state),
1957 .streaming_ctrl = cxusb_streaming_ctrl,
1958 .frontend_attach = cxusb_mt352_frontend_attach,
1959 .tuner_attach = cxusb_lgz201_tuner_attach,
1961 /* parameter for the MPEG2-data transfer */
1975 .power_ctrl = cxusb_bluebird_power_ctrl,
1977 .i2c_algo = &cxusb_i2c_algo,
1981 .rc_codes = RC_MAP_DVICO_PORTABLE,
1982 .module_name = KBUILD_MODNAME,
1983 .rc_query = cxusb_rc_query,
1984 .allowed_protos = RC_PROTO_BIT_NEC,
1987 .generic_bulk_ctrl_endpoint = 0x01,
1988 .num_device_descs = 1,
1990 { "DViCO FusionHDTV DVB-T USB (LGZ201)",
1991 { &cxusb_table[DVICO_BLUEBIRD_LGZ201_COLD], NULL },
1992 { &cxusb_table[DVICO_BLUEBIRD_LGZ201_WARM], NULL },
1997 static struct dvb_usb_device_properties cxusb_bluebird_dtt7579_properties = {
1998 .caps = DVB_USB_IS_AN_I2C_ADAPTER,
2000 .usb_ctrl = DEVICE_SPECIFIC,
2001 .firmware = "dvb-usb-bluebird-01.fw",
2002 .download_firmware = bluebird_patch_dvico_firmware_download,
2005 * use usb alt setting 0 for EP4 transfer (dvb-t),
2006 * use usb alt setting 7 for EP2 transfer (atsc)
2009 .size_of_priv = sizeof(struct cxusb_state),
2016 .streaming_ctrl = cxusb_streaming_ctrl,
2017 .frontend_attach = cxusb_mt352_frontend_attach,
2018 .tuner_attach = cxusb_dtt7579_tuner_attach,
2020 /* parameter for the MPEG2-data transfer */
2034 .power_ctrl = cxusb_bluebird_power_ctrl,
2036 .i2c_algo = &cxusb_i2c_algo,
2040 .rc_codes = RC_MAP_DVICO_PORTABLE,
2041 .module_name = KBUILD_MODNAME,
2042 .rc_query = cxusb_rc_query,
2043 .allowed_protos = RC_PROTO_BIT_NEC,
2046 .generic_bulk_ctrl_endpoint = 0x01,
2048 .num_device_descs = 1,
2050 { "DViCO FusionHDTV DVB-T USB (TH7579)",
2051 { &cxusb_table[DVICO_BLUEBIRD_TH7579_COLD], NULL },
2052 { &cxusb_table[DVICO_BLUEBIRD_TH7579_WARM], NULL },
2057 static struct dvb_usb_device_properties cxusb_bluebird_dualdig4_properties = {
2058 .caps = DVB_USB_IS_AN_I2C_ADAPTER,
2060 .usb_ctrl = CYPRESS_FX2,
2062 .size_of_priv = sizeof(struct cxusb_state),
2069 .streaming_ctrl = cxusb_streaming_ctrl,
2070 .frontend_attach = cxusb_dualdig4_frontend_attach,
2071 .tuner_attach = cxusb_dvico_xc3028_tuner_attach,
2072 /* parameter for the MPEG2-data transfer */
2087 .power_ctrl = cxusb_power_ctrl,
2089 .i2c_algo = &cxusb_i2c_algo,
2091 .generic_bulk_ctrl_endpoint = 0x01,
2095 .rc_codes = RC_MAP_DVICO_MCE,
2096 .module_name = KBUILD_MODNAME,
2097 .rc_query = cxusb_bluebird2_rc_query,
2098 .allowed_protos = RC_PROTO_BIT_NEC,
2101 .num_device_descs = 1,
2103 { "DViCO FusionHDTV DVB-T Dual Digital 4",
2105 { &cxusb_table[DVICO_BLUEBIRD_DUAL_4], NULL },
2110 static struct dvb_usb_device_properties cxusb_bluebird_nano2_properties = {
2111 .caps = DVB_USB_IS_AN_I2C_ADAPTER,
2113 .usb_ctrl = CYPRESS_FX2,
2114 .identify_state = bluebird_fx2_identify_state,
2116 .size_of_priv = sizeof(struct cxusb_state),
2123 .streaming_ctrl = cxusb_streaming_ctrl,
2124 .frontend_attach = cxusb_nano2_frontend_attach,
2125 .tuner_attach = cxusb_dvico_xc3028_tuner_attach,
2126 /* parameter for the MPEG2-data transfer */
2141 .power_ctrl = cxusb_nano2_power_ctrl,
2143 .i2c_algo = &cxusb_i2c_algo,
2145 .generic_bulk_ctrl_endpoint = 0x01,
2149 .rc_codes = RC_MAP_DVICO_PORTABLE,
2150 .module_name = KBUILD_MODNAME,
2151 .rc_query = cxusb_bluebird2_rc_query,
2152 .allowed_protos = RC_PROTO_BIT_NEC,
2155 .num_device_descs = 1,
2157 { "DViCO FusionHDTV DVB-T NANO2",
2159 { &cxusb_table[DVICO_BLUEBIRD_DVB_T_NANO_2], NULL },
2164 static struct dvb_usb_device_properties
2165 cxusb_bluebird_nano2_needsfirmware_properties = {
2166 .caps = DVB_USB_IS_AN_I2C_ADAPTER,
2168 .usb_ctrl = DEVICE_SPECIFIC,
2169 .firmware = "dvb-usb-bluebird-02.fw",
2170 .download_firmware = bluebird_patch_dvico_firmware_download,
2171 .identify_state = bluebird_fx2_identify_state,
2173 .size_of_priv = sizeof(struct cxusb_state),
2180 .streaming_ctrl = cxusb_streaming_ctrl,
2181 .frontend_attach = cxusb_nano2_frontend_attach,
2182 .tuner_attach = cxusb_dvico_xc3028_tuner_attach,
2183 /* parameter for the MPEG2-data transfer */
2198 .power_ctrl = cxusb_nano2_power_ctrl,
2200 .i2c_algo = &cxusb_i2c_algo,
2202 .generic_bulk_ctrl_endpoint = 0x01,
2206 .rc_codes = RC_MAP_DVICO_PORTABLE,
2207 .module_name = KBUILD_MODNAME,
2208 .rc_query = cxusb_rc_query,
2209 .allowed_protos = RC_PROTO_BIT_NEC,
2212 .num_device_descs = 1,
2214 "DViCO FusionHDTV DVB-T NANO2 w/o firmware",
2215 { &cxusb_table[DVICO_BLUEBIRD_DVB_T_NANO_2], NULL },
2216 { &cxusb_table[DVICO_BLUEBIRD_DVB_T_NANO_2_NFW_WARM],
2222 static struct dvb_usb_device_properties cxusb_aver_a868r_properties = {
2223 .caps = DVB_USB_IS_AN_I2C_ADAPTER,
2225 .usb_ctrl = CYPRESS_FX2,
2227 .size_of_priv = sizeof(struct cxusb_state),
2234 .streaming_ctrl = cxusb_aver_streaming_ctrl,
2235 .frontend_attach = cxusb_aver_lgdt3303_frontend_attach,
2236 .tuner_attach = cxusb_mxl5003s_tuner_attach,
2237 /* parameter for the MPEG2-data transfer */
2251 .power_ctrl = cxusb_aver_power_ctrl,
2253 .i2c_algo = &cxusb_i2c_algo,
2255 .generic_bulk_ctrl_endpoint = 0x01,
2257 .num_device_descs = 1,
2259 { "AVerMedia AVerTVHD Volar (A868R)",
2261 { &cxusb_table[AVERMEDIA_VOLAR_A868R], NULL },
2267 struct dvb_usb_device_properties cxusb_bluebird_dualdig4_rev2_properties = {
2268 .caps = DVB_USB_IS_AN_I2C_ADAPTER,
2270 .usb_ctrl = CYPRESS_FX2,
2272 .size_of_priv = sizeof(struct cxusb_state),
2277 .size_of_priv = sizeof(struct dib0700_adapter_state),
2280 .streaming_ctrl = cxusb_streaming_ctrl,
2281 .frontend_attach = cxusb_dualdig4_rev2_frontend_attach,
2282 .tuner_attach = cxusb_dualdig4_rev2_tuner_attach,
2283 /* parameter for the MPEG2-data transfer */
2298 .power_ctrl = cxusb_bluebird_power_ctrl,
2300 .i2c_algo = &cxusb_i2c_algo,
2302 .generic_bulk_ctrl_endpoint = 0x01,
2306 .rc_codes = RC_MAP_DVICO_MCE,
2307 .module_name = KBUILD_MODNAME,
2308 .rc_query = cxusb_rc_query,
2309 .allowed_protos = RC_PROTO_BIT_NEC,
2312 .num_device_descs = 1,
2314 { "DViCO FusionHDTV DVB-T Dual Digital 4 (rev 2)",
2316 { &cxusb_table[DVICO_BLUEBIRD_DUAL_4_REV_2], NULL },
2321 static struct dvb_usb_device_properties cxusb_d680_dmb_properties = {
2322 .caps = DVB_USB_IS_AN_I2C_ADAPTER,
2324 .usb_ctrl = CYPRESS_FX2,
2326 .size_of_priv = sizeof(struct cxusb_state),
2333 .streaming_ctrl = cxusb_d680_dmb_streaming_ctrl,
2334 .frontend_attach = cxusb_d680_dmb_frontend_attach,
2335 .tuner_attach = cxusb_d680_dmb_tuner_attach,
2337 /* parameter for the MPEG2-data transfer */
2352 .power_ctrl = cxusb_d680_dmb_power_ctrl,
2354 .i2c_algo = &cxusb_i2c_algo,
2356 .generic_bulk_ctrl_endpoint = 0x01,
2360 .rc_codes = RC_MAP_TOTAL_MEDIA_IN_HAND_02,
2361 .module_name = KBUILD_MODNAME,
2362 .rc_query = cxusb_d680_dmb_rc_query,
2363 .allowed_protos = RC_PROTO_BIT_UNKNOWN,
2366 .num_device_descs = 1,
2369 "Conexant DMB-TH Stick",
2371 { &cxusb_table[CONEXANT_D680_DMB], NULL },
2376 static struct dvb_usb_device_properties cxusb_mygica_d689_properties = {
2377 .caps = DVB_USB_IS_AN_I2C_ADAPTER,
2379 .usb_ctrl = CYPRESS_FX2,
2381 .size_of_priv = sizeof(struct cxusb_state),
2388 .streaming_ctrl = cxusb_d680_dmb_streaming_ctrl,
2389 .frontend_attach = cxusb_mygica_d689_frontend_attach,
2390 .tuner_attach = cxusb_mygica_d689_tuner_attach,
2392 /* parameter for the MPEG2-data transfer */
2407 .power_ctrl = cxusb_d680_dmb_power_ctrl,
2409 .i2c_algo = &cxusb_i2c_algo,
2411 .generic_bulk_ctrl_endpoint = 0x01,
2415 .rc_codes = RC_MAP_D680_DMB,
2416 .module_name = KBUILD_MODNAME,
2417 .rc_query = cxusb_d680_dmb_rc_query,
2418 .allowed_protos = RC_PROTO_BIT_UNKNOWN,
2421 .num_device_descs = 1,
2424 "Mygica D689 DMB-TH",
2426 { &cxusb_table[MYGICA_D689], NULL },
2431 static struct usb_driver cxusb_driver = {
2432 .name = "dvb_usb_cxusb",
2433 .probe = cxusb_probe,
2434 .disconnect = cxusb_disconnect,
2435 .id_table = cxusb_table,
2438 module_usb_driver(cxusb_driver);
2440 MODULE_AUTHOR("Patrick Boettcher <patrick.boettcher@posteo.de>");
2441 MODULE_AUTHOR("Michael Krufky <mkrufky@linuxtv.org>");
2442 MODULE_AUTHOR("Chris Pascoe <c.pascoe@itee.uq.edu.au>");
2443 MODULE_AUTHOR("Maciej S. Szmigiero <mail@maciej.szmigiero.name>");
2444 MODULE_DESCRIPTION("Driver for Conexant USB2.0 hybrid reference design");
2445 MODULE_LICENSE("GPL");