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 if (cxusb_ctrl_msg(d, CMD_GET_IR_CODE, NULL, 0, ircode, 4) < 0)
527 if (ircode[2] || ircode[3])
528 rc_keydown(d->rc_dev, RC_PROTO_NEC,
529 RC_SCANCODE_NEC(~ircode[2] & 0xff, ircode[3]), 0);
533 static int cxusb_bluebird2_rc_query(struct dvb_usb_device *d)
536 struct i2c_msg msg = {
543 if (cxusb_i2c_xfer(&d->i2c_adap, &msg, 1) != 1)
546 if (ircode[1] || ircode[2])
547 rc_keydown(d->rc_dev, RC_PROTO_NEC,
548 RC_SCANCODE_NEC(~ircode[1] & 0xff, ircode[2]), 0);
552 static int cxusb_d680_dmb_rc_query(struct dvb_usb_device *d)
556 if (cxusb_ctrl_msg(d, 0x10, NULL, 0, ircode, 2) < 0)
559 if (ircode[0] || ircode[1])
560 rc_keydown(d->rc_dev, RC_PROTO_UNKNOWN,
561 RC_SCANCODE_RC5(ircode[0], ircode[1]), 0);
565 static int cxusb_dee1601_demod_init(struct dvb_frontend *fe)
567 static u8 clock_config[] = { CLOCK_CTL, 0x38, 0x28 };
568 static u8 reset[] = { RESET, 0x80 };
569 static u8 adc_ctl_1_cfg[] = { ADC_CTL_1, 0x40 };
570 static u8 agc_cfg[] = { AGC_TARGET, 0x28, 0x20 };
571 static u8 gpp_ctl_cfg[] = { GPP_CTL, 0x33 };
572 static u8 capt_range_cfg[] = { CAPT_RANGE, 0x32 };
574 mt352_write(fe, clock_config, sizeof(clock_config));
576 mt352_write(fe, reset, sizeof(reset));
577 mt352_write(fe, adc_ctl_1_cfg, sizeof(adc_ctl_1_cfg));
579 mt352_write(fe, agc_cfg, sizeof(agc_cfg));
580 mt352_write(fe, gpp_ctl_cfg, sizeof(gpp_ctl_cfg));
581 mt352_write(fe, capt_range_cfg, sizeof(capt_range_cfg));
586 static int cxusb_mt352_demod_init(struct dvb_frontend *fe)
588 /* used in both lgz201 and th7579 */
589 static u8 clock_config[] = { CLOCK_CTL, 0x38, 0x29 };
590 static u8 reset[] = { RESET, 0x80 };
591 static u8 adc_ctl_1_cfg[] = { ADC_CTL_1, 0x40 };
592 static u8 agc_cfg[] = { AGC_TARGET, 0x24, 0x20 };
593 static u8 gpp_ctl_cfg[] = { GPP_CTL, 0x33 };
594 static u8 capt_range_cfg[] = { CAPT_RANGE, 0x32 };
596 mt352_write(fe, clock_config, sizeof(clock_config));
598 mt352_write(fe, reset, sizeof(reset));
599 mt352_write(fe, adc_ctl_1_cfg, sizeof(adc_ctl_1_cfg));
601 mt352_write(fe, agc_cfg, sizeof(agc_cfg));
602 mt352_write(fe, gpp_ctl_cfg, sizeof(gpp_ctl_cfg));
603 mt352_write(fe, capt_range_cfg, sizeof(capt_range_cfg));
607 static struct cx22702_config cxusb_cx22702_config = {
608 .demod_address = 0x63,
609 .output_mode = CX22702_PARALLEL_OUTPUT,
612 static struct lgdt330x_config cxusb_lgdt3303_config = {
613 .demod_chip = LGDT3303,
616 static struct lgdt330x_config cxusb_aver_lgdt3303_config = {
617 .demod_chip = LGDT3303,
618 .clock_polarity_flip = 2,
621 static struct mt352_config cxusb_dee1601_config = {
622 .demod_address = 0x0f,
623 .demod_init = cxusb_dee1601_demod_init,
626 static struct zl10353_config cxusb_zl10353_dee1601_config = {
627 .demod_address = 0x0f,
631 static struct mt352_config cxusb_mt352_config = {
632 /* used in both lgz201 and th7579 */
633 .demod_address = 0x0f,
634 .demod_init = cxusb_mt352_demod_init,
637 static struct zl10353_config cxusb_zl10353_xc3028_config = {
638 .demod_address = 0x0f,
644 static struct zl10353_config cxusb_zl10353_xc3028_config_no_i2c_gate = {
645 .demod_address = 0x0f,
649 .disable_i2c_gate_ctrl = 1,
652 static struct mt352_config cxusb_mt352_xc3028_config = {
653 .demod_address = 0x0f,
656 .demod_init = cxusb_mt352_demod_init,
659 /* FIXME: needs tweaking */
660 static struct mxl5005s_config aver_a868r_tuner = {
662 .if_freq = 6000000UL,
663 .xtal_freq = CRYSTAL_FREQ_16000000HZ,
664 .agc_mode = MXL_SINGLE_AGC,
665 .tracking_filter = MXL_TF_C,
666 .rssi_enable = MXL_RSSI_ENABLE,
667 .cap_select = MXL_CAP_SEL_ENABLE,
668 .div_out = MXL_DIV_OUT_4,
669 .clock_out = MXL_CLOCK_OUT_DISABLE,
670 .output_load = MXL5005S_IF_OUTPUT_LOAD_200_OHM,
671 .top = MXL5005S_TOP_25P2,
672 .mod_mode = MXL_DIGITAL_MODE,
673 .if_mode = MXL_ZERO_IF,
674 .AgcMasterByte = 0x00,
677 /* FIXME: needs tweaking */
678 static struct mxl5005s_config d680_dmb_tuner = {
680 .if_freq = 36125000UL,
681 .xtal_freq = CRYSTAL_FREQ_16000000HZ,
682 .agc_mode = MXL_SINGLE_AGC,
683 .tracking_filter = MXL_TF_C,
684 .rssi_enable = MXL_RSSI_ENABLE,
685 .cap_select = MXL_CAP_SEL_ENABLE,
686 .div_out = MXL_DIV_OUT_4,
687 .clock_out = MXL_CLOCK_OUT_DISABLE,
688 .output_load = MXL5005S_IF_OUTPUT_LOAD_200_OHM,
689 .top = MXL5005S_TOP_25P2,
690 .mod_mode = MXL_DIGITAL_MODE,
691 .if_mode = MXL_ZERO_IF,
692 .AgcMasterByte = 0x00,
695 static struct max2165_config mygica_d689_max2165_cfg = {
700 /* Callbacks for DVB USB */
701 static int cxusb_fmd1216me_tuner_attach(struct dvb_usb_adapter *adap)
703 struct dvb_usb_device *dvbdev = adap->dev;
704 bool is_medion = dvbdev->props.devices[0].warm_ids[0] ==
705 &cxusb_table[MEDION_MD95700];
707 dvb_attach(simple_tuner_attach, adap->fe_adap[0].fe,
708 &dvbdev->i2c_adap, 0x61,
709 TUNER_PHILIPS_FMD1216ME_MK3);
711 if (is_medion && adap->fe_adap[0].fe)
713 * make sure that DVB core won't put to sleep (reset, really)
714 * tuner when we might be open in analog mode
716 adap->fe_adap[0].fe->ops.tuner_ops.sleep = NULL;
721 static int cxusb_dee1601_tuner_attach(struct dvb_usb_adapter *adap)
723 dvb_attach(dvb_pll_attach, adap->fe_adap[0].fe, 0x61,
724 NULL, DVB_PLL_THOMSON_DTT7579);
728 static int cxusb_lgz201_tuner_attach(struct dvb_usb_adapter *adap)
730 dvb_attach(dvb_pll_attach, adap->fe_adap[0].fe, 0x61,
731 NULL, DVB_PLL_LG_Z201);
735 static int cxusb_dtt7579_tuner_attach(struct dvb_usb_adapter *adap)
737 dvb_attach(dvb_pll_attach, adap->fe_adap[0].fe, 0x60,
738 NULL, DVB_PLL_THOMSON_DTT7579);
742 static int cxusb_lgh064f_tuner_attach(struct dvb_usb_adapter *adap)
744 dvb_attach(simple_tuner_attach, adap->fe_adap[0].fe,
745 &adap->dev->i2c_adap, 0x61, TUNER_LG_TDVS_H06XF);
749 static int dvico_bluebird_xc2028_callback(void *ptr, int component,
750 int command, int arg)
752 struct dvb_usb_adapter *adap = ptr;
753 struct dvb_usb_device *d = adap->dev;
756 case XC2028_TUNER_RESET:
757 deb_info("%s: XC2028_TUNER_RESET %d\n", __func__, arg);
758 cxusb_bluebird_gpio_pulse(d, 0x01, 1);
760 case XC2028_RESET_CLK:
761 deb_info("%s: XC2028_RESET_CLK %d\n", __func__, arg);
763 case XC2028_I2C_FLUSH:
766 deb_info("%s: unknown command %d, arg %d\n", __func__,
774 static int cxusb_dvico_xc3028_tuner_attach(struct dvb_usb_adapter *adap)
776 struct dvb_frontend *fe;
777 struct xc2028_config cfg = {
778 .i2c_adap = &adap->dev->i2c_adap,
781 static struct xc2028_ctrl ctl = {
782 .fname = XC2028_DEFAULT_FIRMWARE,
784 .demod = XC3028_FE_ZARLINK456,
787 /* FIXME: generalize & move to common area */
788 adap->fe_adap[0].fe->callback = dvico_bluebird_xc2028_callback;
790 fe = dvb_attach(xc2028_attach, adap->fe_adap[0].fe, &cfg);
791 if (!fe || !fe->ops.tuner_ops.set_config)
794 fe->ops.tuner_ops.set_config(fe, &ctl);
799 static int cxusb_mxl5003s_tuner_attach(struct dvb_usb_adapter *adap)
801 dvb_attach(mxl5005s_attach, adap->fe_adap[0].fe,
802 &adap->dev->i2c_adap, &aver_a868r_tuner);
806 static int cxusb_d680_dmb_tuner_attach(struct dvb_usb_adapter *adap)
808 struct dvb_frontend *fe;
810 fe = dvb_attach(mxl5005s_attach, adap->fe_adap[0].fe,
811 &adap->dev->i2c_adap, &d680_dmb_tuner);
812 return (!fe) ? -EIO : 0;
815 static int cxusb_mygica_d689_tuner_attach(struct dvb_usb_adapter *adap)
817 struct dvb_frontend *fe;
819 fe = dvb_attach(max2165_attach, adap->fe_adap[0].fe,
820 &adap->dev->i2c_adap, &mygica_d689_max2165_cfg);
821 return (!fe) ? -EIO : 0;
824 static int cxusb_medion_fe_ts_bus_ctrl(struct dvb_frontend *fe, int acquire)
826 struct dvb_usb_adapter *adap = fe->dvb->priv;
827 struct dvb_usb_device *dvbdev = adap->dev;
830 return cxusb_medion_get(dvbdev, CXUSB_OPEN_DIGITAL);
832 cxusb_medion_put(dvbdev);
837 static int cxusb_medion_set_mode(struct dvb_usb_device *dvbdev, bool digital)
839 struct cxusb_state *st = dvbdev->priv;
845 * switching mode while doing an I2C transaction often causes
846 * the device to crash
848 mutex_lock(&dvbdev->i2c_mutex);
851 ret = usb_set_interface(dvbdev->udev, 0, 6);
853 dev_err(&dvbdev->udev->dev,
854 "digital interface selection failed (%d)\n",
859 ret = usb_set_interface(dvbdev->udev, 0, 1);
861 dev_err(&dvbdev->udev->dev,
862 "analog interface selection failed (%d)\n",
868 /* pipes need to be cleared after setting interface */
869 ret = usb_clear_halt(dvbdev->udev, usb_rcvbulkpipe(dvbdev->udev, 1));
871 dev_warn(&dvbdev->udev->dev,
872 "clear halt on IN pipe failed (%d)\n",
875 ret = usb_clear_halt(dvbdev->udev, usb_sndbulkpipe(dvbdev->udev, 1));
877 dev_warn(&dvbdev->udev->dev,
878 "clear halt on OUT pipe failed (%d)\n",
881 ret = cxusb_ctrl_msg(dvbdev, digital ? CMD_DIGITAL : CMD_ANALOG,
884 dev_err(&dvbdev->udev->dev, "mode switch failed (%d)\n",
889 /* mode switch seems to reset GPIO states */
890 for (i = 0; i < ARRAY_SIZE(st->gpio_write_refresh); i++)
891 st->gpio_write_refresh[i] = true;
894 mutex_unlock(&dvbdev->i2c_mutex);
899 static int cxusb_cx22702_frontend_attach(struct dvb_usb_adapter *adap)
901 struct dvb_usb_device *dvbdev = adap->dev;
902 bool is_medion = dvbdev->props.devices[0].warm_ids[0] ==
903 &cxusb_table[MEDION_MD95700];
908 ret = cxusb_medion_set_mode(dvbdev, true);
913 adap->fe_adap[0].fe = dvb_attach(cx22702_attach, &cxusb_cx22702_config,
915 if (!adap->fe_adap[0].fe)
919 adap->fe_adap[0].fe->ops.ts_bus_ctrl =
920 cxusb_medion_fe_ts_bus_ctrl;
925 static int cxusb_lgdt3303_frontend_attach(struct dvb_usb_adapter *adap)
927 if (usb_set_interface(adap->dev->udev, 0, 7) < 0)
928 err("set interface failed");
930 cxusb_ctrl_msg(adap->dev, CMD_DIGITAL, NULL, 0, NULL, 0);
932 adap->fe_adap[0].fe = dvb_attach(lgdt330x_attach,
933 &cxusb_lgdt3303_config,
935 &adap->dev->i2c_adap);
936 if (adap->fe_adap[0].fe)
942 static int cxusb_aver_lgdt3303_frontend_attach(struct dvb_usb_adapter *adap)
944 adap->fe_adap[0].fe = dvb_attach(lgdt330x_attach,
945 &cxusb_aver_lgdt3303_config,
947 &adap->dev->i2c_adap);
948 if (adap->fe_adap[0].fe)
954 static int cxusb_mt352_frontend_attach(struct dvb_usb_adapter *adap)
956 /* used in both lgz201 and th7579 */
957 if (usb_set_interface(adap->dev->udev, 0, 0) < 0)
958 err("set interface failed");
960 cxusb_ctrl_msg(adap->dev, CMD_DIGITAL, NULL, 0, NULL, 0);
962 adap->fe_adap[0].fe = dvb_attach(mt352_attach, &cxusb_mt352_config,
963 &adap->dev->i2c_adap);
964 if (adap->fe_adap[0].fe)
970 static int cxusb_dee1601_frontend_attach(struct dvb_usb_adapter *adap)
972 if (usb_set_interface(adap->dev->udev, 0, 0) < 0)
973 err("set interface failed");
975 cxusb_ctrl_msg(adap->dev, CMD_DIGITAL, NULL, 0, NULL, 0);
977 adap->fe_adap[0].fe = dvb_attach(mt352_attach, &cxusb_dee1601_config,
978 &adap->dev->i2c_adap);
979 if (adap->fe_adap[0].fe)
982 adap->fe_adap[0].fe = dvb_attach(zl10353_attach,
983 &cxusb_zl10353_dee1601_config,
984 &adap->dev->i2c_adap);
985 if (adap->fe_adap[0].fe)
991 static int cxusb_dualdig4_frontend_attach(struct dvb_usb_adapter *adap)
995 struct i2c_msg msg = {
1002 if (usb_set_interface(adap->dev->udev, 0, 1) < 0)
1003 err("set interface failed");
1005 cxusb_ctrl_msg(adap->dev, CMD_DIGITAL, NULL, 0, NULL, 0);
1007 /* reset the tuner and demodulator */
1008 cxusb_bluebird_gpio_rw(adap->dev, 0x04, 0);
1009 cxusb_bluebird_gpio_pulse(adap->dev, 0x01, 1);
1010 cxusb_bluebird_gpio_pulse(adap->dev, 0x02, 1);
1012 adap->fe_adap[0].fe =
1013 dvb_attach(zl10353_attach,
1014 &cxusb_zl10353_xc3028_config_no_i2c_gate,
1015 &adap->dev->i2c_adap);
1016 if (!adap->fe_adap[0].fe)
1019 /* try to determine if there is no IR decoder on the I2C bus */
1020 for (i = 0; adap->dev->props.rc.core.rc_codes && i < 5; i++) {
1022 if (cxusb_i2c_xfer(&adap->dev->i2c_adap, &msg, 1) != 1)
1024 if (ircode[0] == 0 && ircode[1] == 0)
1026 if (ircode[2] + ircode[3] != 0xff) {
1028 adap->dev->props.rc.core.rc_codes = NULL;
1029 info("No IR receiver detected on this device.");
1037 static struct dibx000_agc_config dib7070_agc_config = {
1038 .band_caps = BAND_UHF | BAND_VHF | BAND_LBAND | BAND_SBAND,
1041 * P_agc_use_sd_mod1=0, P_agc_use_sd_mod2=0, P_agc_freq_pwm_div=5,
1042 * P_agc_inv_pwm1=0, P_agc_inv_pwm2=0, P_agc_inh_dc_rv_est=0,
1043 * P_agc_time_est=3, P_agc_freeze=0, P_agc_nb_est=5, P_agc_write=0
1045 .setup = (0 << 15) | (0 << 14) | (5 << 11) | (0 << 10) | (0 << 9) |
1046 (0 << 8) | (3 << 5) | (0 << 4) | (5 << 1) | (0 << 0),
1048 .time_stabiliz = 10,
1072 .perform_agc_softsplit = 0,
1075 static struct dibx000_bandwidth_config dib7070_bw_config_12_mhz = {
1085 .IO_CLK_en_core = 1,
1088 /* refsel, sel, freq_15k */
1089 .sad_cfg = (3 << 14) | (1 << 12) | (524 << 0),
1090 .ifreq = (0 << 25) | 0,
1092 .xtal_hz = 12000000,
1095 static struct dib7000p_config cxusb_dualdig4_rev2_config = {
1096 .output_mode = OUTMODE_MPEG2_PAR_GATED_CLK,
1097 .output_mpeg2_in_188_bytes = 1,
1099 .agc_config_count = 1,
1100 .agc = &dib7070_agc_config,
1101 .bw = &dib7070_bw_config_12_mhz,
1102 .tuner_is_baseband = 1,
1108 .gpio_pwm_pos = DIB7000P_GPIO_DEFAULT_PWM_POS,
1110 .hostbus_diversity = 1,
1113 struct dib0700_adapter_state {
1114 int (*set_param_save)(struct dvb_frontend *fe);
1115 struct dib7000p_ops dib7000p_ops;
1118 static int cxusb_dualdig4_rev2_frontend_attach(struct dvb_usb_adapter *adap)
1120 struct dib0700_adapter_state *state = adap->priv;
1122 if (usb_set_interface(adap->dev->udev, 0, 1) < 0)
1123 err("set interface failed");
1125 cxusb_ctrl_msg(adap->dev, CMD_DIGITAL, NULL, 0, NULL, 0);
1127 cxusb_bluebird_gpio_pulse(adap->dev, 0x02, 1);
1129 if (!dvb_attach(dib7000p_attach, &state->dib7000p_ops))
1132 if (state->dib7000p_ops.i2c_enumeration(&adap->dev->i2c_adap, 1, 18,
1133 &cxusb_dualdig4_rev2_config) < 0) {
1134 pr_warn("Unable to enumerate dib7000p\n");
1138 adap->fe_adap[0].fe = state->dib7000p_ops.init(&adap->dev->i2c_adap,
1140 &cxusb_dualdig4_rev2_config);
1141 if (!adap->fe_adap[0].fe)
1147 static int dib7070_tuner_reset(struct dvb_frontend *fe, int onoff)
1149 struct dvb_usb_adapter *adap = fe->dvb->priv;
1150 struct dib0700_adapter_state *state = adap->priv;
1152 return state->dib7000p_ops.set_gpio(fe, 8, 0, !onoff);
1155 static int dib7070_tuner_sleep(struct dvb_frontend *fe, int onoff)
1160 static struct dib0070_config dib7070p_dib0070_config = {
1161 .i2c_address = DEFAULT_DIB0070_I2C_ADDRESS,
1162 .reset = dib7070_tuner_reset,
1163 .sleep = dib7070_tuner_sleep,
1167 static int dib7070_set_param_override(struct dvb_frontend *fe)
1169 struct dtv_frontend_properties *p = &fe->dtv_property_cache;
1170 struct dvb_usb_adapter *adap = fe->dvb->priv;
1171 struct dib0700_adapter_state *state = adap->priv;
1174 u8 band = BAND_OF_FREQUENCY(p->frequency / 1000);
1186 state->dib7000p_ops.set_wbd_ref(fe, offset + dib0070_wbd_offset(fe));
1188 return state->set_param_save(fe);
1191 static int cxusb_dualdig4_rev2_tuner_attach(struct dvb_usb_adapter *adap)
1193 struct dib0700_adapter_state *st = adap->priv;
1194 struct i2c_adapter *tun_i2c;
1197 * No need to call dvb7000p_attach here, as it was called
1198 * already, as frontend_attach method is called first, and
1199 * tuner_attach is only called on success.
1201 tun_i2c = st->dib7000p_ops.get_i2c_master(adap->fe_adap[0].fe,
1202 DIBX000_I2C_INTERFACE_TUNER, 1);
1204 if (dvb_attach(dib0070_attach, adap->fe_adap[0].fe, tun_i2c,
1205 &dib7070p_dib0070_config) == NULL)
1208 st->set_param_save = adap->fe_adap[0].fe->ops.tuner_ops.set_params;
1209 adap->fe_adap[0].fe->ops.tuner_ops.set_params = dib7070_set_param_override;
1213 static int cxusb_nano2_frontend_attach(struct dvb_usb_adapter *adap)
1215 if (usb_set_interface(adap->dev->udev, 0, 1) < 0)
1216 err("set interface failed");
1218 cxusb_ctrl_msg(adap->dev, CMD_DIGITAL, NULL, 0, NULL, 0);
1220 /* reset the tuner and demodulator */
1221 cxusb_bluebird_gpio_rw(adap->dev, 0x04, 0);
1222 cxusb_bluebird_gpio_pulse(adap->dev, 0x01, 1);
1223 cxusb_bluebird_gpio_pulse(adap->dev, 0x02, 1);
1225 adap->fe_adap[0].fe = dvb_attach(zl10353_attach,
1226 &cxusb_zl10353_xc3028_config,
1227 &adap->dev->i2c_adap);
1228 if (adap->fe_adap[0].fe)
1231 adap->fe_adap[0].fe = dvb_attach(mt352_attach,
1232 &cxusb_mt352_xc3028_config,
1233 &adap->dev->i2c_adap);
1234 if (adap->fe_adap[0].fe)
1240 static struct lgs8gxx_config d680_lgs8gl5_cfg = {
1241 .prod = LGS8GXX_PROD_LGS8GL5,
1242 .demod_address = 0x19,
1246 .if_clk_freq = 30400, /* 30.4 MHz */
1247 .if_freq = 5725, /* 5.725 MHz */
1254 static int cxusb_d680_dmb_frontend_attach(struct dvb_usb_adapter *adap)
1256 struct dvb_usb_device *d = adap->dev;
1259 /* Select required USB configuration */
1260 if (usb_set_interface(d->udev, 0, 0) < 0)
1261 err("set interface failed");
1263 /* Unblock all USB pipes */
1264 usb_clear_halt(d->udev,
1265 usb_sndbulkpipe(d->udev,
1266 d->props.generic_bulk_ctrl_endpoint));
1267 usb_clear_halt(d->udev,
1268 usb_rcvbulkpipe(d->udev,
1269 d->props.generic_bulk_ctrl_endpoint));
1270 usb_clear_halt(d->udev,
1271 usb_rcvbulkpipe(d->udev,
1272 d->props.adapter[0].fe[0].stream.endpoint));
1274 /* Drain USB pipes to avoid hang after reboot */
1275 for (n = 0; n < 5; n++) {
1276 cxusb_d680_dmb_drain_message(d);
1277 cxusb_d680_dmb_drain_video(d);
1281 /* Reset the tuner */
1282 if (cxusb_d680_dmb_gpio_tuner(d, 0x07, 0) < 0) {
1283 err("clear tuner gpio failed");
1287 if (cxusb_d680_dmb_gpio_tuner(d, 0x07, 1) < 0) {
1288 err("set tuner gpio failed");
1293 /* Attach frontend */
1294 adap->fe_adap[0].fe = dvb_attach(lgs8gxx_attach,
1295 &d680_lgs8gl5_cfg, &d->i2c_adap);
1296 if (!adap->fe_adap[0].fe)
1302 static struct atbm8830_config mygica_d689_atbm8830_cfg = {
1303 .prod = ATBM8830_PROD_8830,
1304 .demod_address = 0x40,
1306 .ts_sampling_edge = 1,
1308 .osc_clk_freq = 30400, /* in kHz */
1309 .if_freq = 0, /* zero IF */
1316 static int cxusb_mygica_d689_frontend_attach(struct dvb_usb_adapter *adap)
1318 struct dvb_usb_device *d = adap->dev;
1320 /* Select required USB configuration */
1321 if (usb_set_interface(d->udev, 0, 0) < 0)
1322 err("set interface failed");
1324 /* Unblock all USB pipes */
1325 usb_clear_halt(d->udev,
1326 usb_sndbulkpipe(d->udev,
1327 d->props.generic_bulk_ctrl_endpoint));
1328 usb_clear_halt(d->udev,
1329 usb_rcvbulkpipe(d->udev,
1330 d->props.generic_bulk_ctrl_endpoint));
1331 usb_clear_halt(d->udev,
1332 usb_rcvbulkpipe(d->udev,
1333 d->props.adapter[0].fe[0].stream.endpoint));
1335 /* Reset the tuner */
1336 if (cxusb_d680_dmb_gpio_tuner(d, 0x07, 0) < 0) {
1337 err("clear tuner gpio failed");
1341 if (cxusb_d680_dmb_gpio_tuner(d, 0x07, 1) < 0) {
1342 err("set tuner gpio failed");
1347 /* Attach frontend */
1348 adap->fe_adap[0].fe = dvb_attach(atbm8830_attach,
1349 &mygica_d689_atbm8830_cfg,
1351 if (!adap->fe_adap[0].fe)
1358 * DViCO has shipped two devices with the same USB ID, but only one of them
1359 * needs a firmware download. Check the device class details to see if they
1360 * have non-default values to decide whether the device is actually cold or
1361 * not, and forget a match if it turns out we selected the wrong device.
1363 static int bluebird_fx2_identify_state(struct usb_device *udev,
1364 struct dvb_usb_device_properties *props,
1365 struct dvb_usb_device_description **desc,
1368 int wascold = *cold;
1370 *cold = udev->descriptor.bDeviceClass == 0xff &&
1371 udev->descriptor.bDeviceSubClass == 0xff &&
1372 udev->descriptor.bDeviceProtocol == 0xff;
1374 if (*cold && !wascold)
1381 * DViCO bluebird firmware needs the "warm" product ID to be patched into the
1382 * firmware file before download.
1385 static const int dvico_firmware_id_offsets[] = { 6638, 3204 };
1386 static int bluebird_patch_dvico_firmware_download(struct usb_device *udev,
1387 const struct firmware *fw)
1391 for (pos = 0; pos < ARRAY_SIZE(dvico_firmware_id_offsets); pos++) {
1392 int idoff = dvico_firmware_id_offsets[pos];
1394 if (fw->size < idoff + 4)
1397 if (fw->data[idoff] == (USB_VID_DVICO & 0xff) &&
1398 fw->data[idoff + 1] == USB_VID_DVICO >> 8) {
1399 struct firmware new_fw;
1400 u8 *new_fw_data = vmalloc(fw->size);
1406 memcpy(new_fw_data, fw->data, fw->size);
1407 new_fw.size = fw->size;
1408 new_fw.data = new_fw_data;
1410 new_fw_data[idoff + 2] =
1411 le16_to_cpu(udev->descriptor.idProduct) + 1;
1412 new_fw_data[idoff + 3] =
1413 le16_to_cpu(udev->descriptor.idProduct) >> 8;
1415 ret = usb_cypress_load_firmware(udev, &new_fw,
1425 int cxusb_medion_get(struct dvb_usb_device *dvbdev,
1426 enum cxusb_open_type open_type)
1428 struct cxusb_medion_dev *cxdev = dvbdev->priv;
1431 mutex_lock(&cxdev->open_lock);
1433 if (WARN_ON((cxdev->open_type == CXUSB_OPEN_INIT ||
1434 cxdev->open_type == CXUSB_OPEN_NONE) &&
1435 cxdev->open_ctr != 0)) {
1440 if (cxdev->open_type == CXUSB_OPEN_INIT) {
1445 if (cxdev->open_ctr == 0) {
1446 if (cxdev->open_type != open_type) {
1447 deb_info("will acquire and switch to %s\n",
1448 open_type == CXUSB_OPEN_ANALOG ?
1449 "analog" : "digital");
1451 if (open_type == CXUSB_OPEN_ANALOG) {
1452 ret = _cxusb_power_ctrl(dvbdev, 1);
1454 dev_warn(&dvbdev->udev->dev,
1455 "powerup for analog switch failed (%d)\n",
1458 ret = cxusb_medion_set_mode(dvbdev, false);
1462 ret = cxusb_medion_analog_init(dvbdev);
1465 } else { /* digital */
1466 ret = _cxusb_power_ctrl(dvbdev, 1);
1468 dev_warn(&dvbdev->udev->dev,
1469 "powerup for digital switch failed (%d)\n",
1472 ret = cxusb_medion_set_mode(dvbdev, true);
1477 cxdev->open_type = open_type;
1479 deb_info("reacquired idle %s\n",
1480 open_type == CXUSB_OPEN_ANALOG ?
1481 "analog" : "digital");
1484 cxdev->open_ctr = 1;
1485 } else if (cxdev->open_type == open_type) {
1487 deb_info("acquired %s\n", open_type == CXUSB_OPEN_ANALOG ?
1488 "analog" : "digital");
1494 mutex_unlock(&cxdev->open_lock);
1499 void cxusb_medion_put(struct dvb_usb_device *dvbdev)
1501 struct cxusb_medion_dev *cxdev = dvbdev->priv;
1503 mutex_lock(&cxdev->open_lock);
1505 if (cxdev->open_type == CXUSB_OPEN_INIT) {
1506 WARN_ON(cxdev->open_ctr != 0);
1507 cxdev->open_type = CXUSB_OPEN_NONE;
1511 if (!WARN_ON(cxdev->open_ctr < 1)) {
1514 deb_info("release %s\n",
1515 cxdev->open_type == CXUSB_OPEN_ANALOG ?
1516 "analog" : "digital");
1520 mutex_unlock(&cxdev->open_lock);
1523 /* DVB USB Driver stuff */
1524 static struct dvb_usb_device_properties cxusb_medion_properties;
1525 static struct dvb_usb_device_properties cxusb_bluebird_lgh064f_properties;
1526 static struct dvb_usb_device_properties cxusb_bluebird_dee1601_properties;
1527 static struct dvb_usb_device_properties cxusb_bluebird_lgz201_properties;
1528 static struct dvb_usb_device_properties cxusb_bluebird_dtt7579_properties;
1529 static struct dvb_usb_device_properties cxusb_bluebird_dualdig4_properties;
1530 static struct dvb_usb_device_properties cxusb_bluebird_dualdig4_rev2_properties;
1531 static struct dvb_usb_device_properties cxusb_bluebird_nano2_properties;
1532 static struct dvb_usb_device_properties cxusb_bluebird_nano2_needsfirmware_properties;
1533 static struct dvb_usb_device_properties cxusb_aver_a868r_properties;
1534 static struct dvb_usb_device_properties cxusb_d680_dmb_properties;
1535 static struct dvb_usb_device_properties cxusb_mygica_d689_properties;
1537 static int cxusb_medion_priv_init(struct dvb_usb_device *dvbdev)
1539 struct cxusb_medion_dev *cxdev = dvbdev->priv;
1541 cxdev->dvbdev = dvbdev;
1542 cxdev->open_type = CXUSB_OPEN_INIT;
1543 mutex_init(&cxdev->open_lock);
1548 static void cxusb_medion_priv_destroy(struct dvb_usb_device *dvbdev)
1550 struct cxusb_medion_dev *cxdev = dvbdev->priv;
1552 mutex_destroy(&cxdev->open_lock);
1555 static bool cxusb_medion_check_altsetting(struct usb_host_interface *as)
1559 for (ctr = 0; ctr < as->desc.bNumEndpoints; ctr++) {
1560 if ((as->endpoint[ctr].desc.bEndpointAddress &
1561 USB_ENDPOINT_NUMBER_MASK) != 2)
1564 if (as->endpoint[ctr].desc.bEndpointAddress & USB_DIR_IN &&
1565 ((as->endpoint[ctr].desc.bmAttributes &
1566 USB_ENDPOINT_XFERTYPE_MASK) == USB_ENDPOINT_XFER_ISOC))
1575 static bool cxusb_medion_check_intf(struct usb_interface *intf)
1579 if (intf->num_altsetting < 2) {
1580 dev_err(intf->usb_dev, "no alternate interface");
1585 for (ctr = 0; ctr < intf->num_altsetting; ctr++) {
1586 if (intf->altsetting[ctr].desc.bAlternateSetting != 1)
1589 if (cxusb_medion_check_altsetting(&intf->altsetting[ctr]))
1595 dev_err(intf->usb_dev, "no iso interface");
1600 static int cxusb_probe(struct usb_interface *intf,
1601 const struct usb_device_id *id)
1603 struct dvb_usb_device *dvbdev;
1607 if (!dvb_usb_device_init(intf, &cxusb_medion_properties,
1608 THIS_MODULE, &dvbdev, adapter_nr)) {
1609 if (!cxusb_medion_check_intf(intf)) {
1614 _cxusb_power_ctrl(dvbdev, 1);
1615 ret = cxusb_medion_set_mode(dvbdev, false);
1619 ret = cxusb_medion_register_analog(dvbdev);
1621 cxusb_medion_set_mode(dvbdev, true);
1622 _cxusb_power_ctrl(dvbdev, 0);
1627 /* release device from INIT mode to normal operation */
1628 cxusb_medion_put(dvbdev);
1631 } else if (!dvb_usb_device_init(intf,
1632 &cxusb_bluebird_lgh064f_properties,
1633 THIS_MODULE, NULL, adapter_nr) ||
1634 !dvb_usb_device_init(intf,
1635 &cxusb_bluebird_dee1601_properties,
1636 THIS_MODULE, NULL, adapter_nr) ||
1637 !dvb_usb_device_init(intf,
1638 &cxusb_bluebird_lgz201_properties,
1639 THIS_MODULE, NULL, adapter_nr) ||
1640 !dvb_usb_device_init(intf,
1641 &cxusb_bluebird_dtt7579_properties,
1642 THIS_MODULE, NULL, adapter_nr) ||
1643 !dvb_usb_device_init(intf,
1644 &cxusb_bluebird_dualdig4_properties,
1645 THIS_MODULE, NULL, adapter_nr) ||
1646 !dvb_usb_device_init(intf,
1647 &cxusb_bluebird_nano2_properties,
1648 THIS_MODULE, NULL, adapter_nr) ||
1649 !dvb_usb_device_init(intf,
1650 &cxusb_bluebird_nano2_needsfirmware_properties,
1651 THIS_MODULE, NULL, adapter_nr) ||
1652 !dvb_usb_device_init(intf, &cxusb_aver_a868r_properties,
1653 THIS_MODULE, NULL, adapter_nr) ||
1654 !dvb_usb_device_init(intf,
1655 &cxusb_bluebird_dualdig4_rev2_properties,
1656 THIS_MODULE, NULL, adapter_nr) ||
1657 !dvb_usb_device_init(intf, &cxusb_d680_dmb_properties,
1658 THIS_MODULE, NULL, adapter_nr) ||
1659 !dvb_usb_device_init(intf, &cxusb_mygica_d689_properties,
1660 THIS_MODULE, NULL, adapter_nr) ||
1667 dvb_usb_device_exit(intf);
1672 static void cxusb_disconnect(struct usb_interface *intf)
1674 struct dvb_usb_device *d = usb_get_intfdata(intf);
1675 struct cxusb_state *st = d->priv;
1676 struct i2c_client *client;
1678 if (d->props.devices[0].warm_ids[0] == &cxusb_table[MEDION_MD95700])
1679 cxusb_medion_unregister_analog(d);
1681 /* remove I2C client for tuner */
1682 client = st->i2c_client_tuner;
1684 module_put(client->dev.driver->owner);
1685 i2c_unregister_device(client);
1688 /* remove I2C client for demodulator */
1689 client = st->i2c_client_demod;
1691 module_put(client->dev.driver->owner);
1692 i2c_unregister_device(client);
1695 dvb_usb_device_exit(intf);
1698 static struct usb_device_id cxusb_table[NR__cxusb_table_index + 1] = {
1699 [MEDION_MD95700] = {
1700 USB_DEVICE(USB_VID_MEDION, USB_PID_MEDION_MD95700)
1702 [DVICO_BLUEBIRD_LG064F_COLD] = {
1703 USB_DEVICE(USB_VID_DVICO, USB_PID_DVICO_BLUEBIRD_LG064F_COLD)
1705 [DVICO_BLUEBIRD_LG064F_WARM] = {
1706 USB_DEVICE(USB_VID_DVICO, USB_PID_DVICO_BLUEBIRD_LG064F_WARM)
1708 [DVICO_BLUEBIRD_DUAL_1_COLD] = {
1709 USB_DEVICE(USB_VID_DVICO, USB_PID_DVICO_BLUEBIRD_DUAL_1_COLD)
1711 [DVICO_BLUEBIRD_DUAL_1_WARM] = {
1712 USB_DEVICE(USB_VID_DVICO, USB_PID_DVICO_BLUEBIRD_DUAL_1_WARM)
1714 [DVICO_BLUEBIRD_LGZ201_COLD] = {
1715 USB_DEVICE(USB_VID_DVICO, USB_PID_DVICO_BLUEBIRD_LGZ201_COLD)
1717 [DVICO_BLUEBIRD_LGZ201_WARM] = {
1718 USB_DEVICE(USB_VID_DVICO, USB_PID_DVICO_BLUEBIRD_LGZ201_WARM)
1720 [DVICO_BLUEBIRD_TH7579_COLD] = {
1721 USB_DEVICE(USB_VID_DVICO, USB_PID_DVICO_BLUEBIRD_TH7579_COLD)
1723 [DVICO_BLUEBIRD_TH7579_WARM] = {
1724 USB_DEVICE(USB_VID_DVICO, USB_PID_DVICO_BLUEBIRD_TH7579_WARM)
1726 [DIGITALNOW_BLUEBIRD_DUAL_1_COLD] = {
1727 USB_DEVICE(USB_VID_DVICO,
1728 USB_PID_DIGITALNOW_BLUEBIRD_DUAL_1_COLD)
1730 [DIGITALNOW_BLUEBIRD_DUAL_1_WARM] = {
1731 USB_DEVICE(USB_VID_DVICO,
1732 USB_PID_DIGITALNOW_BLUEBIRD_DUAL_1_WARM)
1734 [DVICO_BLUEBIRD_DUAL_2_COLD] = {
1735 USB_DEVICE(USB_VID_DVICO, USB_PID_DVICO_BLUEBIRD_DUAL_2_COLD)
1737 [DVICO_BLUEBIRD_DUAL_2_WARM] = {
1738 USB_DEVICE(USB_VID_DVICO, USB_PID_DVICO_BLUEBIRD_DUAL_2_WARM)
1740 [DVICO_BLUEBIRD_DUAL_4] = {
1741 USB_DEVICE(USB_VID_DVICO, USB_PID_DVICO_BLUEBIRD_DUAL_4)
1743 [DVICO_BLUEBIRD_DVB_T_NANO_2] = {
1744 USB_DEVICE(USB_VID_DVICO, USB_PID_DVICO_BLUEBIRD_DVB_T_NANO_2)
1746 [DVICO_BLUEBIRD_DVB_T_NANO_2_NFW_WARM] = {
1747 USB_DEVICE(USB_VID_DVICO,
1748 USB_PID_DVICO_BLUEBIRD_DVB_T_NANO_2_NFW_WARM)
1750 [AVERMEDIA_VOLAR_A868R] = {
1751 USB_DEVICE(USB_VID_AVERMEDIA, USB_PID_AVERMEDIA_VOLAR_A868R)
1753 [DVICO_BLUEBIRD_DUAL_4_REV_2] = {
1754 USB_DEVICE(USB_VID_DVICO, USB_PID_DVICO_BLUEBIRD_DUAL_4_REV_2)
1756 [CONEXANT_D680_DMB] = {
1757 USB_DEVICE(USB_VID_CONEXANT, USB_PID_CONEXANT_D680_DMB)
1760 USB_DEVICE(USB_VID_CONEXANT, USB_PID_MYGICA_D689)
1762 {} /* Terminating entry */
1764 MODULE_DEVICE_TABLE(usb, cxusb_table);
1766 static struct dvb_usb_device_properties cxusb_medion_properties = {
1767 .caps = DVB_USB_IS_AN_I2C_ADAPTER,
1769 .usb_ctrl = CYPRESS_FX2,
1771 .size_of_priv = sizeof(struct cxusb_medion_dev),
1772 .priv_init = cxusb_medion_priv_init,
1773 .priv_destroy = cxusb_medion_priv_destroy,
1780 .streaming_ctrl = cxusb_streaming_ctrl,
1781 .frontend_attach = cxusb_cx22702_frontend_attach,
1782 .tuner_attach = cxusb_fmd1216me_tuner_attach,
1783 /* parameter for the MPEG2-data transfer */
1797 .power_ctrl = cxusb_power_ctrl,
1799 .i2c_algo = &cxusb_i2c_algo,
1801 .generic_bulk_ctrl_endpoint = 0x01,
1803 .num_device_descs = 1,
1806 "Medion MD95700 (MDUSBTV-HYBRID)",
1808 { &cxusb_table[MEDION_MD95700], NULL },
1813 static struct dvb_usb_device_properties cxusb_bluebird_lgh064f_properties = {
1814 .caps = DVB_USB_IS_AN_I2C_ADAPTER,
1816 .usb_ctrl = DEVICE_SPECIFIC,
1817 .firmware = "dvb-usb-bluebird-01.fw",
1818 .download_firmware = bluebird_patch_dvico_firmware_download,
1820 * use usb alt setting 0 for EP4 transfer (dvb-t),
1821 * use usb alt setting 7 for EP2 transfer (atsc)
1824 .size_of_priv = sizeof(struct cxusb_state),
1831 .streaming_ctrl = cxusb_streaming_ctrl,
1832 .frontend_attach = cxusb_lgdt3303_frontend_attach,
1833 .tuner_attach = cxusb_lgh064f_tuner_attach,
1835 /* parameter for the MPEG2-data transfer */
1850 .power_ctrl = cxusb_bluebird_power_ctrl,
1852 .i2c_algo = &cxusb_i2c_algo,
1856 .rc_codes = RC_MAP_DVICO_PORTABLE,
1857 .module_name = KBUILD_MODNAME,
1858 .rc_query = cxusb_rc_query,
1859 .allowed_protos = RC_PROTO_BIT_NEC,
1862 .generic_bulk_ctrl_endpoint = 0x01,
1864 .num_device_descs = 1,
1866 { "DViCO FusionHDTV5 USB Gold",
1867 { &cxusb_table[DVICO_BLUEBIRD_LG064F_COLD], NULL },
1868 { &cxusb_table[DVICO_BLUEBIRD_LG064F_WARM], NULL },
1873 static struct dvb_usb_device_properties cxusb_bluebird_dee1601_properties = {
1874 .caps = DVB_USB_IS_AN_I2C_ADAPTER,
1876 .usb_ctrl = DEVICE_SPECIFIC,
1877 .firmware = "dvb-usb-bluebird-01.fw",
1878 .download_firmware = bluebird_patch_dvico_firmware_download,
1880 * use usb alt setting 0 for EP4 transfer (dvb-t),
1881 * use usb alt setting 7 for EP2 transfer (atsc)
1884 .size_of_priv = sizeof(struct cxusb_state),
1891 .streaming_ctrl = cxusb_streaming_ctrl,
1892 .frontend_attach = cxusb_dee1601_frontend_attach,
1893 .tuner_attach = cxusb_dee1601_tuner_attach,
1894 /* parameter for the MPEG2-data transfer */
1909 .power_ctrl = cxusb_bluebird_power_ctrl,
1911 .i2c_algo = &cxusb_i2c_algo,
1915 .rc_codes = RC_MAP_DVICO_MCE,
1916 .module_name = KBUILD_MODNAME,
1917 .rc_query = cxusb_rc_query,
1918 .allowed_protos = RC_PROTO_BIT_NEC,
1921 .generic_bulk_ctrl_endpoint = 0x01,
1923 .num_device_descs = 3,
1925 { "DViCO FusionHDTV DVB-T Dual USB",
1926 { &cxusb_table[DVICO_BLUEBIRD_DUAL_1_COLD], NULL },
1927 { &cxusb_table[DVICO_BLUEBIRD_DUAL_1_WARM], NULL },
1929 { "DigitalNow DVB-T Dual USB",
1930 { &cxusb_table[DIGITALNOW_BLUEBIRD_DUAL_1_COLD], NULL },
1931 { &cxusb_table[DIGITALNOW_BLUEBIRD_DUAL_1_WARM], NULL },
1933 { "DViCO FusionHDTV DVB-T Dual Digital 2",
1934 { &cxusb_table[DVICO_BLUEBIRD_DUAL_2_COLD], NULL },
1935 { &cxusb_table[DVICO_BLUEBIRD_DUAL_2_WARM], NULL },
1940 static struct dvb_usb_device_properties cxusb_bluebird_lgz201_properties = {
1941 .caps = DVB_USB_IS_AN_I2C_ADAPTER,
1943 .usb_ctrl = DEVICE_SPECIFIC,
1944 .firmware = "dvb-usb-bluebird-01.fw",
1945 .download_firmware = bluebird_patch_dvico_firmware_download,
1947 * use usb alt setting 0 for EP4 transfer (dvb-t),
1948 * use usb alt setting 7 for EP2 transfer (atsc)
1951 .size_of_priv = sizeof(struct cxusb_state),
1958 .streaming_ctrl = cxusb_streaming_ctrl,
1959 .frontend_attach = cxusb_mt352_frontend_attach,
1960 .tuner_attach = cxusb_lgz201_tuner_attach,
1962 /* parameter for the MPEG2-data transfer */
1976 .power_ctrl = cxusb_bluebird_power_ctrl,
1978 .i2c_algo = &cxusb_i2c_algo,
1982 .rc_codes = RC_MAP_DVICO_PORTABLE,
1983 .module_name = KBUILD_MODNAME,
1984 .rc_query = cxusb_rc_query,
1985 .allowed_protos = RC_PROTO_BIT_NEC,
1988 .generic_bulk_ctrl_endpoint = 0x01,
1989 .num_device_descs = 1,
1991 { "DViCO FusionHDTV DVB-T USB (LGZ201)",
1992 { &cxusb_table[DVICO_BLUEBIRD_LGZ201_COLD], NULL },
1993 { &cxusb_table[DVICO_BLUEBIRD_LGZ201_WARM], NULL },
1998 static struct dvb_usb_device_properties cxusb_bluebird_dtt7579_properties = {
1999 .caps = DVB_USB_IS_AN_I2C_ADAPTER,
2001 .usb_ctrl = DEVICE_SPECIFIC,
2002 .firmware = "dvb-usb-bluebird-01.fw",
2003 .download_firmware = bluebird_patch_dvico_firmware_download,
2006 * use usb alt setting 0 for EP4 transfer (dvb-t),
2007 * use usb alt setting 7 for EP2 transfer (atsc)
2010 .size_of_priv = sizeof(struct cxusb_state),
2017 .streaming_ctrl = cxusb_streaming_ctrl,
2018 .frontend_attach = cxusb_mt352_frontend_attach,
2019 .tuner_attach = cxusb_dtt7579_tuner_attach,
2021 /* parameter for the MPEG2-data transfer */
2035 .power_ctrl = cxusb_bluebird_power_ctrl,
2037 .i2c_algo = &cxusb_i2c_algo,
2041 .rc_codes = RC_MAP_DVICO_PORTABLE,
2042 .module_name = KBUILD_MODNAME,
2043 .rc_query = cxusb_rc_query,
2044 .allowed_protos = RC_PROTO_BIT_NEC,
2047 .generic_bulk_ctrl_endpoint = 0x01,
2049 .num_device_descs = 1,
2051 { "DViCO FusionHDTV DVB-T USB (TH7579)",
2052 { &cxusb_table[DVICO_BLUEBIRD_TH7579_COLD], NULL },
2053 { &cxusb_table[DVICO_BLUEBIRD_TH7579_WARM], NULL },
2058 static struct dvb_usb_device_properties cxusb_bluebird_dualdig4_properties = {
2059 .caps = DVB_USB_IS_AN_I2C_ADAPTER,
2061 .usb_ctrl = CYPRESS_FX2,
2063 .size_of_priv = sizeof(struct cxusb_state),
2070 .streaming_ctrl = cxusb_streaming_ctrl,
2071 .frontend_attach = cxusb_dualdig4_frontend_attach,
2072 .tuner_attach = cxusb_dvico_xc3028_tuner_attach,
2073 /* parameter for the MPEG2-data transfer */
2088 .power_ctrl = cxusb_power_ctrl,
2090 .i2c_algo = &cxusb_i2c_algo,
2092 .generic_bulk_ctrl_endpoint = 0x01,
2096 .rc_codes = RC_MAP_DVICO_MCE,
2097 .module_name = KBUILD_MODNAME,
2098 .rc_query = cxusb_bluebird2_rc_query,
2099 .allowed_protos = RC_PROTO_BIT_NEC,
2102 .num_device_descs = 1,
2104 { "DViCO FusionHDTV DVB-T Dual Digital 4",
2106 { &cxusb_table[DVICO_BLUEBIRD_DUAL_4], NULL },
2111 static struct dvb_usb_device_properties cxusb_bluebird_nano2_properties = {
2112 .caps = DVB_USB_IS_AN_I2C_ADAPTER,
2114 .usb_ctrl = CYPRESS_FX2,
2115 .identify_state = bluebird_fx2_identify_state,
2117 .size_of_priv = sizeof(struct cxusb_state),
2124 .streaming_ctrl = cxusb_streaming_ctrl,
2125 .frontend_attach = cxusb_nano2_frontend_attach,
2126 .tuner_attach = cxusb_dvico_xc3028_tuner_attach,
2127 /* parameter for the MPEG2-data transfer */
2142 .power_ctrl = cxusb_nano2_power_ctrl,
2144 .i2c_algo = &cxusb_i2c_algo,
2146 .generic_bulk_ctrl_endpoint = 0x01,
2150 .rc_codes = RC_MAP_DVICO_PORTABLE,
2151 .module_name = KBUILD_MODNAME,
2152 .rc_query = cxusb_bluebird2_rc_query,
2153 .allowed_protos = RC_PROTO_BIT_NEC,
2156 .num_device_descs = 1,
2158 { "DViCO FusionHDTV DVB-T NANO2",
2160 { &cxusb_table[DVICO_BLUEBIRD_DVB_T_NANO_2], NULL },
2165 static struct dvb_usb_device_properties
2166 cxusb_bluebird_nano2_needsfirmware_properties = {
2167 .caps = DVB_USB_IS_AN_I2C_ADAPTER,
2169 .usb_ctrl = DEVICE_SPECIFIC,
2170 .firmware = "dvb-usb-bluebird-02.fw",
2171 .download_firmware = bluebird_patch_dvico_firmware_download,
2172 .identify_state = bluebird_fx2_identify_state,
2174 .size_of_priv = sizeof(struct cxusb_state),
2181 .streaming_ctrl = cxusb_streaming_ctrl,
2182 .frontend_attach = cxusb_nano2_frontend_attach,
2183 .tuner_attach = cxusb_dvico_xc3028_tuner_attach,
2184 /* parameter for the MPEG2-data transfer */
2199 .power_ctrl = cxusb_nano2_power_ctrl,
2201 .i2c_algo = &cxusb_i2c_algo,
2203 .generic_bulk_ctrl_endpoint = 0x01,
2207 .rc_codes = RC_MAP_DVICO_PORTABLE,
2208 .module_name = KBUILD_MODNAME,
2209 .rc_query = cxusb_rc_query,
2210 .allowed_protos = RC_PROTO_BIT_NEC,
2213 .num_device_descs = 1,
2215 "DViCO FusionHDTV DVB-T NANO2 w/o firmware",
2216 { &cxusb_table[DVICO_BLUEBIRD_DVB_T_NANO_2], NULL },
2217 { &cxusb_table[DVICO_BLUEBIRD_DVB_T_NANO_2_NFW_WARM],
2223 static struct dvb_usb_device_properties cxusb_aver_a868r_properties = {
2224 .caps = DVB_USB_IS_AN_I2C_ADAPTER,
2226 .usb_ctrl = CYPRESS_FX2,
2228 .size_of_priv = sizeof(struct cxusb_state),
2235 .streaming_ctrl = cxusb_aver_streaming_ctrl,
2236 .frontend_attach = cxusb_aver_lgdt3303_frontend_attach,
2237 .tuner_attach = cxusb_mxl5003s_tuner_attach,
2238 /* parameter for the MPEG2-data transfer */
2252 .power_ctrl = cxusb_aver_power_ctrl,
2254 .i2c_algo = &cxusb_i2c_algo,
2256 .generic_bulk_ctrl_endpoint = 0x01,
2258 .num_device_descs = 1,
2260 { "AVerMedia AVerTVHD Volar (A868R)",
2262 { &cxusb_table[AVERMEDIA_VOLAR_A868R], NULL },
2268 struct dvb_usb_device_properties cxusb_bluebird_dualdig4_rev2_properties = {
2269 .caps = DVB_USB_IS_AN_I2C_ADAPTER,
2271 .usb_ctrl = CYPRESS_FX2,
2273 .size_of_priv = sizeof(struct cxusb_state),
2278 .size_of_priv = sizeof(struct dib0700_adapter_state),
2281 .streaming_ctrl = cxusb_streaming_ctrl,
2282 .frontend_attach = cxusb_dualdig4_rev2_frontend_attach,
2283 .tuner_attach = cxusb_dualdig4_rev2_tuner_attach,
2284 /* parameter for the MPEG2-data transfer */
2299 .power_ctrl = cxusb_bluebird_power_ctrl,
2301 .i2c_algo = &cxusb_i2c_algo,
2303 .generic_bulk_ctrl_endpoint = 0x01,
2307 .rc_codes = RC_MAP_DVICO_MCE,
2308 .module_name = KBUILD_MODNAME,
2309 .rc_query = cxusb_rc_query,
2310 .allowed_protos = RC_PROTO_BIT_NEC,
2313 .num_device_descs = 1,
2315 { "DViCO FusionHDTV DVB-T Dual Digital 4 (rev 2)",
2317 { &cxusb_table[DVICO_BLUEBIRD_DUAL_4_REV_2], NULL },
2322 static struct dvb_usb_device_properties cxusb_d680_dmb_properties = {
2323 .caps = DVB_USB_IS_AN_I2C_ADAPTER,
2325 .usb_ctrl = CYPRESS_FX2,
2327 .size_of_priv = sizeof(struct cxusb_state),
2334 .streaming_ctrl = cxusb_d680_dmb_streaming_ctrl,
2335 .frontend_attach = cxusb_d680_dmb_frontend_attach,
2336 .tuner_attach = cxusb_d680_dmb_tuner_attach,
2338 /* parameter for the MPEG2-data transfer */
2353 .power_ctrl = cxusb_d680_dmb_power_ctrl,
2355 .i2c_algo = &cxusb_i2c_algo,
2357 .generic_bulk_ctrl_endpoint = 0x01,
2361 .rc_codes = RC_MAP_TOTAL_MEDIA_IN_HAND_02,
2362 .module_name = KBUILD_MODNAME,
2363 .rc_query = cxusb_d680_dmb_rc_query,
2364 .allowed_protos = RC_PROTO_BIT_UNKNOWN,
2367 .num_device_descs = 1,
2370 "Conexant DMB-TH Stick",
2372 { &cxusb_table[CONEXANT_D680_DMB], NULL },
2377 static struct dvb_usb_device_properties cxusb_mygica_d689_properties = {
2378 .caps = DVB_USB_IS_AN_I2C_ADAPTER,
2380 .usb_ctrl = CYPRESS_FX2,
2382 .size_of_priv = sizeof(struct cxusb_state),
2389 .streaming_ctrl = cxusb_d680_dmb_streaming_ctrl,
2390 .frontend_attach = cxusb_mygica_d689_frontend_attach,
2391 .tuner_attach = cxusb_mygica_d689_tuner_attach,
2393 /* parameter for the MPEG2-data transfer */
2408 .power_ctrl = cxusb_d680_dmb_power_ctrl,
2410 .i2c_algo = &cxusb_i2c_algo,
2412 .generic_bulk_ctrl_endpoint = 0x01,
2416 .rc_codes = RC_MAP_D680_DMB,
2417 .module_name = KBUILD_MODNAME,
2418 .rc_query = cxusb_d680_dmb_rc_query,
2419 .allowed_protos = RC_PROTO_BIT_UNKNOWN,
2422 .num_device_descs = 1,
2425 "Mygica D689 DMB-TH",
2427 { &cxusb_table[MYGICA_D689], NULL },
2432 static struct usb_driver cxusb_driver = {
2433 .name = "dvb_usb_cxusb",
2434 .probe = cxusb_probe,
2435 .disconnect = cxusb_disconnect,
2436 .id_table = cxusb_table,
2439 module_usb_driver(cxusb_driver);
2441 MODULE_AUTHOR("Patrick Boettcher <patrick.boettcher@posteo.de>");
2442 MODULE_AUTHOR("Michael Krufky <mkrufky@linuxtv.org>");
2443 MODULE_AUTHOR("Chris Pascoe <c.pascoe@itee.uq.edu.au>");
2444 MODULE_AUTHOR("Maciej S. Szmigiero <mail@maciej.szmigiero.name>");
2445 MODULE_DESCRIPTION("Driver for Conexant USB2.0 hybrid reference design");
2446 MODULE_LICENSE("GPL");