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