1 // SPDX-License-Identifier: GPL-2.0-only 2 /* DVB USB compliant linux driver for MSI Mega Sky 580 DVB-T USB2.0 receiver 3 * 4 * Copyright (C) 2006 Aapo Tahkola (aet@rasterburn.org) 5 * 6 * see Documentation/driver-api/media/drivers/dvb-usb.rst for more information 7 */ 8 9 #include "m920x.h" 10 11 #include "mt352.h" 12 #include "mt352_priv.h" 13 #include "qt1010.h" 14 #include "tda1004x.h" 15 #include "tda827x.h" 16 #include "mt2060.h" 17 18 #include <media/tuner.h> 19 #include "tuner-simple.h" 20 #include <asm/unaligned.h> 21 22 /* debug */ 23 static int dvb_usb_m920x_debug; 24 module_param_named(debug,dvb_usb_m920x_debug, int, 0644); 25 MODULE_PARM_DESC(debug, "set debugging level (1=rc (or-able))." DVB_USB_DEBUG_STATUS); 26 27 DVB_DEFINE_MOD_OPT_ADAPTER_NR(adapter_nr); 28 29 static int m920x_set_filter(struct dvb_usb_device *d, int type, int idx, int pid); 30 31 static inline int m920x_read(struct usb_device *udev, u8 request, u16 value, 32 u16 index, void *data, int size) 33 { 34 int ret; 35 36 ret = usb_control_msg(udev, usb_rcvctrlpipe(udev, 0), 37 request, USB_TYPE_VENDOR | USB_DIR_IN, 38 value, index, data, size, 2000); 39 if (ret < 0) { 40 printk(KERN_INFO "m920x_read = error: %d\n", ret); 41 return ret; 42 } 43 44 if (ret != size) { 45 deb("m920x_read = no data\n"); 46 return -EIO; 47 } 48 49 return 0; 50 } 51 52 static inline int m920x_write(struct usb_device *udev, u8 request, 53 u16 value, u16 index) 54 { 55 return usb_control_msg(udev, usb_sndctrlpipe(udev, 0), request, 56 USB_TYPE_VENDOR | USB_DIR_OUT, value, index, 57 NULL, 0, 2000); 58 } 59 60 static inline int m920x_write_seq(struct usb_device *udev, u8 request, 61 struct m920x_inits *seq) 62 { 63 int ret; 64 do { 65 ret = m920x_write(udev, request, seq->data, seq->address); 66 if (ret != 0) 67 return ret; 68 69 seq++; 70 } while (seq->address); 71 72 return 0; 73 } 74 75 static int m920x_init(struct dvb_usb_device *d, struct m920x_inits *rc_seq) 76 { 77 int ret, i, epi, flags = 0; 78 int adap_enabled[M9206_MAX_ADAPTERS] = { 0 }; 79 80 /* Remote controller init. */ 81 if (d->props.rc.legacy.rc_query || d->props.rc.core.rc_query) { 82 deb("Initialising remote control\n"); 83 ret = m920x_write_seq(d->udev, M9206_CORE, rc_seq); 84 if (ret != 0) { 85 deb("Initialising remote control failed\n"); 86 return ret; 87 } 88 89 deb("Initialising remote control success\n"); 90 } 91 92 for (i = 0; i < d->props.num_adapters; i++) 93 flags |= d->adapter[i].props.fe[0].caps; 94 95 /* Some devices(Dposh) might crash if we attempt touch at all. */ 96 if (flags & DVB_USB_ADAP_HAS_PID_FILTER) { 97 for (i = 0; i < d->props.num_adapters; i++) { 98 epi = d->adapter[i].props.fe[0].stream.endpoint - 0x81; 99 100 if (epi < 0 || epi >= M9206_MAX_ADAPTERS) { 101 printk(KERN_INFO "m920x: Unexpected adapter endpoint!\n"); 102 return -EINVAL; 103 } 104 105 adap_enabled[epi] = 1; 106 } 107 108 for (i = 0; i < M9206_MAX_ADAPTERS; i++) { 109 if (adap_enabled[i]) 110 continue; 111 112 if ((ret = m920x_set_filter(d, 0x81 + i, 0, 0x0)) != 0) 113 return ret; 114 115 if ((ret = m920x_set_filter(d, 0x81 + i, 0, 0x02f5)) != 0) 116 return ret; 117 } 118 } 119 120 return 0; 121 } 122 123 static int m920x_init_ep(struct usb_interface *intf) 124 { 125 struct usb_device *udev = interface_to_usbdev(intf); 126 struct usb_host_interface *alt; 127 128 if ((alt = usb_altnum_to_altsetting(intf, 1)) == NULL) { 129 deb("No alt found!\n"); 130 return -ENODEV; 131 } 132 133 return usb_set_interface(udev, alt->desc.bInterfaceNumber, 134 alt->desc.bAlternateSetting); 135 } 136 137 static inline void m920x_parse_rc_state(struct dvb_usb_device *d, u8 rc_state, 138 int *state) 139 { 140 struct m920x_state *m = d->priv; 141 142 switch (rc_state) { 143 case 0x80: 144 *state = REMOTE_NO_KEY_PRESSED; 145 break; 146 147 case 0x88: /* framing error or "invalid code" */ 148 case 0x99: 149 case 0xc0: 150 case 0xd8: 151 *state = REMOTE_NO_KEY_PRESSED; 152 m->rep_count = 0; 153 break; 154 155 case 0x93: 156 case 0x92: 157 case 0x83: /* pinnacle PCTV310e */ 158 case 0x82: 159 m->rep_count = 0; 160 *state = REMOTE_KEY_PRESSED; 161 break; 162 163 case 0x91: 164 case 0x81: /* pinnacle PCTV310e */ 165 /* prevent immediate auto-repeat */ 166 if (++m->rep_count > 2) 167 *state = REMOTE_KEY_REPEAT; 168 else 169 *state = REMOTE_NO_KEY_PRESSED; 170 break; 171 172 default: 173 deb("Unexpected rc state %02x\n", rc_state); 174 *state = REMOTE_NO_KEY_PRESSED; 175 break; 176 } 177 } 178 179 static int m920x_rc_query(struct dvb_usb_device *d, u32 *event, int *state) 180 { 181 int i, ret = 0; 182 u8 *rc_state; 183 184 rc_state = kmalloc(2, GFP_KERNEL); 185 if (!rc_state) 186 return -ENOMEM; 187 188 ret = m920x_read(d->udev, M9206_CORE, 0x0, M9206_RC_STATE, 189 rc_state, 1); 190 if (ret != 0) 191 goto out; 192 193 ret = m920x_read(d->udev, M9206_CORE, 0x0, M9206_RC_KEY, 194 rc_state + 1, 1); 195 if (ret != 0) 196 goto out; 197 198 m920x_parse_rc_state(d, rc_state[0], state); 199 200 for (i = 0; i < d->props.rc.legacy.rc_map_size; i++) 201 if (rc5_data(&d->props.rc.legacy.rc_map_table[i]) == rc_state[1]) { 202 *event = d->props.rc.legacy.rc_map_table[i].keycode; 203 goto out; 204 } 205 206 if (rc_state[1] != 0) 207 deb("Unknown rc key %02x\n", rc_state[1]); 208 209 *state = REMOTE_NO_KEY_PRESSED; 210 211 out: 212 kfree(rc_state); 213 return ret; 214 } 215 216 static int m920x_rc_core_query(struct dvb_usb_device *d) 217 { 218 int ret = 0; 219 u8 *rc_state; 220 int state; 221 222 rc_state = kmalloc(2, GFP_KERNEL); 223 if (!rc_state) 224 return -ENOMEM; 225 226 if ((ret = m920x_read(d->udev, M9206_CORE, 0x0, M9206_RC_STATE, &rc_state[0], 1)) != 0) 227 goto out; 228 229 if ((ret = m920x_read(d->udev, M9206_CORE, 0x0, M9206_RC_KEY, &rc_state[1], 1)) != 0) 230 goto out; 231 232 deb("state=0x%02x keycode=0x%02x\n", rc_state[0], rc_state[1]); 233 234 m920x_parse_rc_state(d, rc_state[0], &state); 235 236 if (state == REMOTE_NO_KEY_PRESSED) 237 rc_keyup(d->rc_dev); 238 else if (state == REMOTE_KEY_REPEAT) 239 rc_repeat(d->rc_dev); 240 else 241 rc_keydown(d->rc_dev, RC_PROTO_UNKNOWN, rc_state[1], 0); 242 243 out: 244 kfree(rc_state); 245 return ret; 246 } 247 248 /* I2C */ 249 static int m920x_i2c_xfer(struct i2c_adapter *adap, struct i2c_msg msg[], int num) 250 { 251 struct dvb_usb_device *d = i2c_get_adapdata(adap); 252 int i, j; 253 int ret = 0; 254 255 if (mutex_lock_interruptible(&d->i2c_mutex) < 0) 256 return -EAGAIN; 257 258 for (i = 0; i < num; i++) { 259 if (msg[i].flags & (I2C_M_NO_RD_ACK | I2C_M_IGNORE_NAK | I2C_M_TEN) || msg[i].len == 0) { 260 /* For a 0 byte message, I think sending the address 261 * to index 0x80|0x40 would be the correct thing to 262 * do. However, zero byte messages are only used for 263 * probing, and since we don't know how to get the 264 * slave's ack, we can't probe. */ 265 ret = -ENOTSUPP; 266 goto unlock; 267 } 268 /* Send START & address/RW bit */ 269 if (!(msg[i].flags & I2C_M_NOSTART)) { 270 if ((ret = m920x_write(d->udev, M9206_I2C, 271 (msg[i].addr << 1) | 272 (msg[i].flags & I2C_M_RD ? 0x01 : 0), 0x80)) != 0) 273 goto unlock; 274 /* Should check for ack here, if we knew how. */ 275 } 276 if (msg[i].flags & I2C_M_RD) { 277 char *read = kmalloc(1, GFP_KERNEL); 278 if (!read) { 279 ret = -ENOMEM; 280 kfree(read); 281 goto unlock; 282 } 283 284 for (j = 0; j < msg[i].len; j++) { 285 /* Last byte of transaction? 286 * Send STOP, otherwise send ACK. */ 287 int stop = (i+1 == num && j+1 == msg[i].len) ? 0x40 : 0x01; 288 289 if ((ret = m920x_read(d->udev, M9206_I2C, 0x0, 290 0x20 | stop, 291 read, 1)) != 0) 292 goto unlock; 293 msg[i].buf[j] = read[0]; 294 } 295 296 kfree(read); 297 } else { 298 for (j = 0; j < msg[i].len; j++) { 299 /* Last byte of transaction? Then send STOP. */ 300 int stop = (i+1 == num && j+1 == msg[i].len) ? 0x40 : 0x00; 301 302 if ((ret = m920x_write(d->udev, M9206_I2C, msg[i].buf[j], stop)) != 0) 303 goto unlock; 304 /* Should check for ack here too. */ 305 } 306 } 307 } 308 ret = num; 309 310 unlock: 311 mutex_unlock(&d->i2c_mutex); 312 313 return ret; 314 } 315 316 static u32 m920x_i2c_func(struct i2c_adapter *adapter) 317 { 318 return I2C_FUNC_I2C; 319 } 320 321 static struct i2c_algorithm m920x_i2c_algo = { 322 .master_xfer = m920x_i2c_xfer, 323 .functionality = m920x_i2c_func, 324 }; 325 326 /* pid filter */ 327 static int m920x_set_filter(struct dvb_usb_device *d, int type, int idx, int pid) 328 { 329 int ret = 0; 330 331 if (pid >= 0x8000) 332 return -EINVAL; 333 334 pid |= 0x8000; 335 336 if ((ret = m920x_write(d->udev, M9206_FILTER, pid, (type << 8) | (idx * 4) )) != 0) 337 return ret; 338 339 if ((ret = m920x_write(d->udev, M9206_FILTER, 0, (type << 8) | (idx * 4) )) != 0) 340 return ret; 341 342 return ret; 343 } 344 345 static int m920x_update_filters(struct dvb_usb_adapter *adap) 346 { 347 struct m920x_state *m = adap->dev->priv; 348 int enabled = m->filtering_enabled[adap->id]; 349 int i, ret = 0, filter = 0; 350 int ep = adap->props.fe[0].stream.endpoint; 351 352 for (i = 0; i < M9206_MAX_FILTERS; i++) 353 if (m->filters[adap->id][i] == 8192) 354 enabled = 0; 355 356 /* Disable all filters */ 357 if ((ret = m920x_set_filter(adap->dev, ep, 1, enabled)) != 0) 358 return ret; 359 360 for (i = 0; i < M9206_MAX_FILTERS; i++) 361 if ((ret = m920x_set_filter(adap->dev, ep, i + 2, 0)) != 0) 362 return ret; 363 364 /* Set */ 365 if (enabled) { 366 for (i = 0; i < M9206_MAX_FILTERS; i++) { 367 if (m->filters[adap->id][i] == 0) 368 continue; 369 370 if ((ret = m920x_set_filter(adap->dev, ep, filter + 2, m->filters[adap->id][i])) != 0) 371 return ret; 372 373 filter++; 374 } 375 } 376 377 return ret; 378 } 379 380 static int m920x_pid_filter_ctrl(struct dvb_usb_adapter *adap, int onoff) 381 { 382 struct m920x_state *m = adap->dev->priv; 383 384 m->filtering_enabled[adap->id] = onoff ? 1 : 0; 385 386 return m920x_update_filters(adap); 387 } 388 389 static int m920x_pid_filter(struct dvb_usb_adapter *adap, int index, u16 pid, int onoff) 390 { 391 struct m920x_state *m = adap->dev->priv; 392 393 m->filters[adap->id][index] = onoff ? pid : 0; 394 395 return m920x_update_filters(adap); 396 } 397 398 static int m920x_firmware_download(struct usb_device *udev, const struct firmware *fw) 399 { 400 u16 value, index, size; 401 u8 *read, *buff; 402 int i, pass, ret = 0; 403 404 buff = kmalloc(65536, GFP_KERNEL); 405 if (buff == NULL) 406 return -ENOMEM; 407 408 read = kmalloc(4, GFP_KERNEL); 409 if (!read) { 410 kfree(buff); 411 return -ENOMEM; 412 } 413 414 if ((ret = m920x_read(udev, M9206_FILTER, 0x0, 0x8000, read, 4)) != 0) 415 goto done; 416 deb("%*ph\n", 4, read); 417 418 if ((ret = m920x_read(udev, M9206_FW, 0x0, 0x0, read, 1)) != 0) 419 goto done; 420 deb("%x\n", read[0]); 421 422 for (pass = 0; pass < 2; pass++) { 423 for (i = 0; i + (sizeof(u16) * 3) < fw->size;) { 424 value = get_unaligned_le16(fw->data + i); 425 i += sizeof(u16); 426 427 index = get_unaligned_le16(fw->data + i); 428 i += sizeof(u16); 429 430 size = get_unaligned_le16(fw->data + i); 431 i += sizeof(u16); 432 433 if (pass == 1) { 434 /* Will stall if using fw->data ... */ 435 memcpy(buff, fw->data + i, size); 436 437 ret = usb_control_msg(udev, usb_sndctrlpipe(udev,0), 438 M9206_FW, 439 USB_TYPE_VENDOR | USB_DIR_OUT, 440 value, index, buff, size, 20); 441 if (ret != size) { 442 deb("error while uploading fw!\n"); 443 ret = -EIO; 444 goto done; 445 } 446 msleep(3); 447 } 448 i += size; 449 } 450 if (i != fw->size) { 451 deb("bad firmware file!\n"); 452 ret = -EINVAL; 453 goto done; 454 } 455 } 456 457 msleep(36); 458 459 /* m920x will disconnect itself from the bus after this. */ 460 (void) m920x_write(udev, M9206_CORE, 0x01, M9206_FW_GO); 461 deb("firmware uploaded!\n"); 462 463 done: 464 kfree(read); 465 kfree(buff); 466 467 return ret; 468 } 469 470 /* Callbacks for DVB USB */ 471 static int m920x_identify_state(struct usb_device *udev, 472 const struct dvb_usb_device_properties *props, 473 const struct dvb_usb_device_description **desc, 474 int *cold) 475 { 476 struct usb_host_interface *alt; 477 478 alt = usb_altnum_to_altsetting(usb_ifnum_to_if(udev, 0), 1); 479 *cold = (alt == NULL) ? 1 : 0; 480 481 return 0; 482 } 483 484 /* demod configurations */ 485 static int m920x_mt352_demod_init(struct dvb_frontend *fe) 486 { 487 int ret; 488 static const u8 config[] = { CONFIG, 0x3d }; 489 static const u8 clock[] = { CLOCK_CTL, 0x30 }; 490 static const u8 reset[] = { RESET, 0x80 }; 491 static const u8 adc_ctl[] = { ADC_CTL_1, 0x40 }; 492 static const u8 agc[] = { AGC_TARGET, 0x1c, 0x20 }; 493 static const u8 sec_agc[] = { 0x69, 0x00, 0xff, 0xff, 0x40, 0xff, 0x00, 0x40, 0x40 }; 494 static const u8 unk1[] = { 0x93, 0x1a }; 495 static const u8 unk2[] = { 0xb5, 0x7a }; 496 497 deb("Demod init!\n"); 498 499 if ((ret = mt352_write(fe, config, ARRAY_SIZE(config))) != 0) 500 return ret; 501 if ((ret = mt352_write(fe, clock, ARRAY_SIZE(clock))) != 0) 502 return ret; 503 if ((ret = mt352_write(fe, reset, ARRAY_SIZE(reset))) != 0) 504 return ret; 505 if ((ret = mt352_write(fe, adc_ctl, ARRAY_SIZE(adc_ctl))) != 0) 506 return ret; 507 if ((ret = mt352_write(fe, agc, ARRAY_SIZE(agc))) != 0) 508 return ret; 509 if ((ret = mt352_write(fe, sec_agc, ARRAY_SIZE(sec_agc))) != 0) 510 return ret; 511 if ((ret = mt352_write(fe, unk1, ARRAY_SIZE(unk1))) != 0) 512 return ret; 513 if ((ret = mt352_write(fe, unk2, ARRAY_SIZE(unk2))) != 0) 514 return ret; 515 516 return 0; 517 } 518 519 static struct mt352_config m920x_mt352_config = { 520 .demod_address = 0x0f, 521 .no_tuner = 1, 522 .demod_init = m920x_mt352_demod_init, 523 }; 524 525 static struct tda1004x_config m920x_tda10046_08_config = { 526 .demod_address = 0x08, 527 .invert = 0, 528 .invert_oclk = 0, 529 .ts_mode = TDA10046_TS_SERIAL, 530 .xtal_freq = TDA10046_XTAL_16M, 531 .if_freq = TDA10046_FREQ_045, 532 .agc_config = TDA10046_AGC_TDA827X, 533 .gpio_config = TDA10046_GPTRI, 534 .request_firmware = NULL, 535 }; 536 537 static struct tda1004x_config m920x_tda10046_0b_config = { 538 .demod_address = 0x0b, 539 .invert = 0, 540 .invert_oclk = 0, 541 .ts_mode = TDA10046_TS_SERIAL, 542 .xtal_freq = TDA10046_XTAL_16M, 543 .if_freq = TDA10046_FREQ_045, 544 .agc_config = TDA10046_AGC_TDA827X, 545 .gpio_config = TDA10046_GPTRI, 546 .request_firmware = NULL, /* uses firmware EEPROM */ 547 }; 548 549 /* tuner configurations */ 550 static struct qt1010_config m920x_qt1010_config = { 551 .i2c_address = 0x62 552 }; 553 554 static struct mt2060_config m920x_mt2060_config = { 555 .i2c_address = 0x60, /* 0xc0 */ 556 .clock_out = 0, 557 }; 558 559 560 /* Callbacks for DVB USB */ 561 static int m920x_mt352_frontend_attach(struct dvb_usb_adapter *adap) 562 { 563 deb("%s\n",__func__); 564 565 adap->fe_adap[0].fe = dvb_attach(mt352_attach, 566 &m920x_mt352_config, 567 &adap->dev->i2c_adap); 568 if ((adap->fe_adap[0].fe) == NULL) 569 return -EIO; 570 571 return 0; 572 } 573 574 static int m920x_mt352_frontend_attach_vp7049(struct dvb_usb_adapter *adap) 575 { 576 struct m920x_inits vp7049_fe_init_seq[] = { 577 /* XXX without these commands the frontend cannot be detected, 578 * they must be sent BEFORE the frontend is attached */ 579 { 0xff28, 0x00 }, 580 { 0xff23, 0x00 }, 581 { 0xff28, 0x00 }, 582 { 0xff23, 0x00 }, 583 { 0xff21, 0x20 }, 584 { 0xff21, 0x60 }, 585 { 0xff28, 0x00 }, 586 { 0xff22, 0x00 }, 587 { 0xff20, 0x30 }, 588 { 0xff20, 0x20 }, 589 { 0xff20, 0x30 }, 590 { } /* terminating entry */ 591 }; 592 int ret; 593 594 deb("%s\n", __func__); 595 596 ret = m920x_write_seq(adap->dev->udev, M9206_CORE, vp7049_fe_init_seq); 597 if (ret != 0) { 598 deb("Initialization of vp7049 frontend failed."); 599 return ret; 600 } 601 602 return m920x_mt352_frontend_attach(adap); 603 } 604 605 static int m920x_tda10046_08_frontend_attach(struct dvb_usb_adapter *adap) 606 { 607 deb("%s\n",__func__); 608 609 adap->fe_adap[0].fe = dvb_attach(tda10046_attach, 610 &m920x_tda10046_08_config, 611 &adap->dev->i2c_adap); 612 if ((adap->fe_adap[0].fe) == NULL) 613 return -EIO; 614 615 return 0; 616 } 617 618 static int m920x_tda10046_0b_frontend_attach(struct dvb_usb_adapter *adap) 619 { 620 deb("%s\n",__func__); 621 622 adap->fe_adap[0].fe = dvb_attach(tda10046_attach, 623 &m920x_tda10046_0b_config, 624 &adap->dev->i2c_adap); 625 if ((adap->fe_adap[0].fe) == NULL) 626 return -EIO; 627 628 return 0; 629 } 630 631 static int m920x_qt1010_tuner_attach(struct dvb_usb_adapter *adap) 632 { 633 deb("%s\n",__func__); 634 635 if (dvb_attach(qt1010_attach, adap->fe_adap[0].fe, &adap->dev->i2c_adap, &m920x_qt1010_config) == NULL) 636 return -ENODEV; 637 638 return 0; 639 } 640 641 static int m920x_tda8275_60_tuner_attach(struct dvb_usb_adapter *adap) 642 { 643 deb("%s\n",__func__); 644 645 if (dvb_attach(tda827x_attach, adap->fe_adap[0].fe, 0x60, &adap->dev->i2c_adap, NULL) == NULL) 646 return -ENODEV; 647 648 return 0; 649 } 650 651 static int m920x_tda8275_61_tuner_attach(struct dvb_usb_adapter *adap) 652 { 653 deb("%s\n",__func__); 654 655 if (dvb_attach(tda827x_attach, adap->fe_adap[0].fe, 0x61, &adap->dev->i2c_adap, NULL) == NULL) 656 return -ENODEV; 657 658 return 0; 659 } 660 661 static int m920x_fmd1216me_tuner_attach(struct dvb_usb_adapter *adap) 662 { 663 dvb_attach(simple_tuner_attach, adap->fe_adap[0].fe, 664 &adap->dev->i2c_adap, 0x61, 665 TUNER_PHILIPS_FMD1216ME_MK3); 666 return 0; 667 } 668 669 static int m920x_mt2060_tuner_attach(struct dvb_usb_adapter *adap) 670 { 671 deb("%s\n", __func__); 672 673 if (dvb_attach(mt2060_attach, adap->fe_adap[0].fe, &adap->dev->i2c_adap, 674 &m920x_mt2060_config, 1220) == NULL) 675 return -ENODEV; 676 677 return 0; 678 } 679 680 681 /* device-specific initialization */ 682 static struct m920x_inits megasky_rc_init [] = { 683 { M9206_RC_INIT2, 0xa8 }, 684 { M9206_RC_INIT1, 0x51 }, 685 { } /* terminating entry */ 686 }; 687 688 static struct m920x_inits tvwalkertwin_rc_init [] = { 689 { M9206_RC_INIT2, 0x00 }, 690 { M9206_RC_INIT1, 0xef }, 691 { 0xff28, 0x00 }, 692 { 0xff23, 0x00 }, 693 { 0xff21, 0x30 }, 694 { } /* terminating entry */ 695 }; 696 697 static struct m920x_inits pinnacle310e_init[] = { 698 /* without these the tuner doesn't work */ 699 { 0xff20, 0x9b }, 700 { 0xff22, 0x70 }, 701 702 /* rc settings */ 703 { 0xff50, 0x80 }, 704 { M9206_RC_INIT1, 0x00 }, 705 { M9206_RC_INIT2, 0xff }, 706 { } /* terminating entry */ 707 }; 708 709 static struct m920x_inits vp7049_rc_init[] = { 710 { 0xff28, 0x00 }, 711 { 0xff23, 0x00 }, 712 { 0xff21, 0x70 }, 713 { M9206_RC_INIT2, 0x00 }, 714 { M9206_RC_INIT1, 0xff }, 715 { } /* terminating entry */ 716 }; 717 718 /* ir keymaps */ 719 static struct rc_map_table rc_map_megasky_table[] = { 720 { 0x0012, KEY_POWER }, 721 { 0x001e, KEY_CYCLEWINDOWS }, /* min/max */ 722 { 0x0002, KEY_CHANNELUP }, 723 { 0x0005, KEY_CHANNELDOWN }, 724 { 0x0003, KEY_VOLUMEUP }, 725 { 0x0006, KEY_VOLUMEDOWN }, 726 { 0x0004, KEY_MUTE }, 727 { 0x0007, KEY_OK }, /* TS */ 728 { 0x0008, KEY_STOP }, 729 { 0x0009, KEY_MENU }, /* swap */ 730 { 0x000a, KEY_REWIND }, 731 { 0x001b, KEY_PAUSE }, 732 { 0x001f, KEY_FASTFORWARD }, 733 { 0x000c, KEY_RECORD }, 734 { 0x000d, KEY_CAMERA }, /* screenshot */ 735 { 0x000e, KEY_COFFEE }, /* "MTS" */ 736 }; 737 738 static struct rc_map_table rc_map_tvwalkertwin_table[] = { 739 { 0x0001, KEY_ZOOM }, /* Full Screen */ 740 { 0x0002, KEY_CAMERA }, /* snapshot */ 741 { 0x0003, KEY_MUTE }, 742 { 0x0004, KEY_REWIND }, 743 { 0x0005, KEY_PLAYPAUSE }, /* Play/Pause */ 744 { 0x0006, KEY_FASTFORWARD }, 745 { 0x0007, KEY_RECORD }, 746 { 0x0008, KEY_STOP }, 747 { 0x0009, KEY_TIME }, /* Timeshift */ 748 { 0x000c, KEY_COFFEE }, /* Recall */ 749 { 0x000e, KEY_CHANNELUP }, 750 { 0x0012, KEY_POWER }, 751 { 0x0015, KEY_MENU }, /* source */ 752 { 0x0018, KEY_CYCLEWINDOWS }, /* TWIN PIP */ 753 { 0x001a, KEY_CHANNELDOWN }, 754 { 0x001b, KEY_VOLUMEDOWN }, 755 { 0x001e, KEY_VOLUMEUP }, 756 }; 757 758 static struct rc_map_table rc_map_pinnacle310e_table[] = { 759 { 0x16, KEY_POWER }, 760 { 0x17, KEY_FAVORITES }, 761 { 0x0f, KEY_TEXT }, 762 { 0x48, KEY_PROGRAM }, /* preview */ 763 { 0x1c, KEY_EPG }, 764 { 0x04, KEY_LIST }, /* record list */ 765 { 0x03, KEY_1 }, 766 { 0x01, KEY_2 }, 767 { 0x06, KEY_3 }, 768 { 0x09, KEY_4 }, 769 { 0x1d, KEY_5 }, 770 { 0x1f, KEY_6 }, 771 { 0x0d, KEY_7 }, 772 { 0x19, KEY_8 }, 773 { 0x1b, KEY_9 }, 774 { 0x15, KEY_0 }, 775 { 0x0c, KEY_CANCEL }, 776 { 0x4a, KEY_CLEAR }, 777 { 0x13, KEY_BACK }, 778 { 0x00, KEY_TAB }, 779 { 0x4b, KEY_UP }, 780 { 0x4e, KEY_LEFT }, 781 { 0x52, KEY_RIGHT }, 782 { 0x51, KEY_DOWN }, 783 { 0x4f, KEY_ENTER }, /* could also be KEY_OK */ 784 { 0x1e, KEY_VOLUMEUP }, 785 { 0x0a, KEY_VOLUMEDOWN }, 786 { 0x05, KEY_CHANNELUP }, 787 { 0x02, KEY_CHANNELDOWN }, 788 { 0x11, KEY_RECORD }, 789 { 0x14, KEY_PLAY }, 790 { 0x4c, KEY_PAUSE }, 791 { 0x1a, KEY_STOP }, 792 { 0x40, KEY_REWIND }, 793 { 0x12, KEY_FASTFORWARD }, 794 { 0x41, KEY_PREVIOUSSONG }, /* Replay */ 795 { 0x42, KEY_NEXTSONG }, /* Skip */ 796 { 0x54, KEY_CAMERA }, /* Capture */ 797 /* { 0x50, KEY_SAP }, */ /* Sap */ 798 { 0x47, KEY_CYCLEWINDOWS }, /* Pip */ 799 { 0x4d, KEY_SCREEN }, /* FullScreen */ 800 { 0x08, KEY_SUBTITLE }, 801 { 0x0e, KEY_MUTE }, 802 /* { 0x49, KEY_LR }, */ /* L/R */ 803 { 0x07, KEY_SLEEP }, /* Hibernate */ 804 { 0x08, KEY_VIDEO }, /* A/V */ 805 { 0x0e, KEY_MENU }, /* Recall */ 806 { 0x45, KEY_ZOOMIN }, 807 { 0x46, KEY_ZOOMOUT }, 808 { 0x18, KEY_RED }, /* Red */ 809 { 0x53, KEY_GREEN }, /* Green */ 810 { 0x5e, KEY_YELLOW }, /* Yellow */ 811 { 0x5f, KEY_BLUE }, /* Blue */ 812 }; 813 814 /* DVB USB Driver stuff */ 815 static struct dvb_usb_device_properties megasky_properties; 816 static struct dvb_usb_device_properties digivox_mini_ii_properties; 817 static struct dvb_usb_device_properties tvwalkertwin_properties; 818 static struct dvb_usb_device_properties dposh_properties; 819 static struct dvb_usb_device_properties pinnacle_pctv310e_properties; 820 static struct dvb_usb_device_properties vp7049_properties; 821 822 static int m920x_probe(struct usb_interface *intf, 823 const struct usb_device_id *id) 824 { 825 struct dvb_usb_device *d = NULL; 826 int ret; 827 struct m920x_inits *rc_init_seq = NULL; 828 int bInterfaceNumber = intf->cur_altsetting->desc.bInterfaceNumber; 829 830 deb("Probing for m920x device at interface %d\n", bInterfaceNumber); 831 832 if (bInterfaceNumber == 0) { 833 /* Single-tuner device, or first interface on 834 * multi-tuner device 835 */ 836 837 ret = dvb_usb_device_init(intf, &megasky_properties, 838 THIS_MODULE, &d, adapter_nr); 839 if (ret == 0) { 840 rc_init_seq = megasky_rc_init; 841 goto found; 842 } 843 844 ret = dvb_usb_device_init(intf, &digivox_mini_ii_properties, 845 THIS_MODULE, &d, adapter_nr); 846 if (ret == 0) { 847 /* No remote control, so no rc_init_seq */ 848 goto found; 849 } 850 851 /* This configures both tuners on the TV Walker Twin */ 852 ret = dvb_usb_device_init(intf, &tvwalkertwin_properties, 853 THIS_MODULE, &d, adapter_nr); 854 if (ret == 0) { 855 rc_init_seq = tvwalkertwin_rc_init; 856 goto found; 857 } 858 859 ret = dvb_usb_device_init(intf, &dposh_properties, 860 THIS_MODULE, &d, adapter_nr); 861 if (ret == 0) { 862 /* Remote controller not supported yet. */ 863 goto found; 864 } 865 866 ret = dvb_usb_device_init(intf, &pinnacle_pctv310e_properties, 867 THIS_MODULE, &d, adapter_nr); 868 if (ret == 0) { 869 rc_init_seq = pinnacle310e_init; 870 goto found; 871 } 872 873 ret = dvb_usb_device_init(intf, &vp7049_properties, 874 THIS_MODULE, &d, adapter_nr); 875 if (ret == 0) { 876 rc_init_seq = vp7049_rc_init; 877 goto found; 878 } 879 880 return ret; 881 } else { 882 /* Another interface on a multi-tuner device */ 883 884 /* The LifeView TV Walker Twin gets here, but struct 885 * tvwalkertwin_properties already configured both 886 * tuners, so there is nothing for us to do here 887 */ 888 } 889 890 found: 891 if ((ret = m920x_init_ep(intf)) < 0) 892 return ret; 893 894 if (d && (ret = m920x_init(d, rc_init_seq)) != 0) 895 return ret; 896 897 return ret; 898 } 899 900 enum { 901 MSI_MEGASKY580, 902 ANUBIS_MSI_DIGI_VOX_MINI_II, 903 ANUBIS_LIFEVIEW_TV_WALKER_TWIN_COLD, 904 ANUBIS_LIFEVIEW_TV_WALKER_TWIN_WARM, 905 DPOSH_M9206_COLD, 906 DPOSH_M9206_WARM, 907 VISIONPLUS_PINNACLE_PCTV310E, 908 AZUREWAVE_TWINHAN_VP7049, 909 }; 910 911 static struct usb_device_id m920x_table[] = { 912 DVB_USB_DEV(MSI, MSI_MEGASKY580), 913 DVB_USB_DEV(ANUBIS_ELECTRONIC, ANUBIS_MSI_DIGI_VOX_MINI_II), 914 DVB_USB_DEV(ANUBIS_ELECTRONIC, ANUBIS_LIFEVIEW_TV_WALKER_TWIN_COLD), 915 DVB_USB_DEV(ANUBIS_ELECTRONIC, ANUBIS_LIFEVIEW_TV_WALKER_TWIN_WARM), 916 DVB_USB_DEV(DPOSH, DPOSH_M9206_COLD), 917 DVB_USB_DEV(DPOSH, DPOSH_M9206_WARM), 918 DVB_USB_DEV(VISIONPLUS, VISIONPLUS_PINNACLE_PCTV310E), 919 DVB_USB_DEV(AZUREWAVE, AZUREWAVE_TWINHAN_VP7049), 920 { } 921 }; 922 923 MODULE_DEVICE_TABLE (usb, m920x_table); 924 925 static struct dvb_usb_device_properties megasky_properties = { 926 .caps = DVB_USB_IS_AN_I2C_ADAPTER, 927 928 .usb_ctrl = DEVICE_SPECIFIC, 929 .firmware = "dvb-usb-megasky-02.fw", 930 .download_firmware = m920x_firmware_download, 931 932 .rc.legacy = { 933 .rc_interval = 100, 934 .rc_map_table = rc_map_megasky_table, 935 .rc_map_size = ARRAY_SIZE(rc_map_megasky_table), 936 .rc_query = m920x_rc_query, 937 }, 938 939 .size_of_priv = sizeof(struct m920x_state), 940 941 .identify_state = m920x_identify_state, 942 .num_adapters = 1, 943 .adapter = {{ 944 .num_frontends = 1, 945 .fe = {{ 946 947 .caps = DVB_USB_ADAP_HAS_PID_FILTER | 948 DVB_USB_ADAP_PID_FILTER_CAN_BE_TURNED_OFF, 949 950 .pid_filter_count = 8, 951 .pid_filter = m920x_pid_filter, 952 .pid_filter_ctrl = m920x_pid_filter_ctrl, 953 954 .frontend_attach = m920x_mt352_frontend_attach, 955 .tuner_attach = m920x_qt1010_tuner_attach, 956 957 .stream = { 958 .type = USB_BULK, 959 .count = 8, 960 .endpoint = 0x81, 961 .u = { 962 .bulk = { 963 .buffersize = 512, 964 } 965 } 966 }, 967 }}, 968 }}, 969 .i2c_algo = &m920x_i2c_algo, 970 971 .num_device_descs = 1, 972 .devices = { 973 { "MSI Mega Sky 580 DVB-T USB2.0", 974 { &m920x_table[MSI_MEGASKY580], NULL }, 975 { NULL }, 976 } 977 } 978 }; 979 980 static struct dvb_usb_device_properties digivox_mini_ii_properties = { 981 .caps = DVB_USB_IS_AN_I2C_ADAPTER, 982 983 .usb_ctrl = DEVICE_SPECIFIC, 984 .firmware = "dvb-usb-digivox-02.fw", 985 .download_firmware = m920x_firmware_download, 986 987 .size_of_priv = sizeof(struct m920x_state), 988 989 .identify_state = m920x_identify_state, 990 .num_adapters = 1, 991 .adapter = {{ 992 .num_frontends = 1, 993 .fe = {{ 994 995 .caps = DVB_USB_ADAP_HAS_PID_FILTER | 996 DVB_USB_ADAP_PID_FILTER_CAN_BE_TURNED_OFF, 997 998 .pid_filter_count = 8, 999 .pid_filter = m920x_pid_filter, 1000 .pid_filter_ctrl = m920x_pid_filter_ctrl, 1001 1002 .frontend_attach = m920x_tda10046_08_frontend_attach, 1003 .tuner_attach = m920x_tda8275_60_tuner_attach, 1004 1005 .stream = { 1006 .type = USB_BULK, 1007 .count = 8, 1008 .endpoint = 0x81, 1009 .u = { 1010 .bulk = { 1011 .buffersize = 0x4000, 1012 } 1013 } 1014 }, 1015 }}, 1016 }}, 1017 .i2c_algo = &m920x_i2c_algo, 1018 1019 .num_device_descs = 1, 1020 .devices = { 1021 { "MSI DIGI VOX mini II DVB-T USB2.0", 1022 { &m920x_table[ANUBIS_MSI_DIGI_VOX_MINI_II], NULL }, 1023 { NULL }, 1024 }, 1025 } 1026 }; 1027 1028 /* LifeView TV Walker Twin support by Nick Andrew <nick@nick-andrew.net> 1029 * 1030 * LifeView TV Walker Twin has 1 x M9206, 2 x TDA10046, 2 x TDA8275A 1031 * TDA10046 #0 is located at i2c address 0x08 1032 * TDA10046 #1 is located at i2c address 0x0b 1033 * TDA8275A #0 is located at i2c address 0x60 1034 * TDA8275A #1 is located at i2c address 0x61 1035 */ 1036 static struct dvb_usb_device_properties tvwalkertwin_properties = { 1037 .caps = DVB_USB_IS_AN_I2C_ADAPTER, 1038 1039 .usb_ctrl = DEVICE_SPECIFIC, 1040 .firmware = "dvb-usb-tvwalkert.fw", 1041 .download_firmware = m920x_firmware_download, 1042 1043 .rc.legacy = { 1044 .rc_interval = 100, 1045 .rc_map_table = rc_map_tvwalkertwin_table, 1046 .rc_map_size = ARRAY_SIZE(rc_map_tvwalkertwin_table), 1047 .rc_query = m920x_rc_query, 1048 }, 1049 1050 .size_of_priv = sizeof(struct m920x_state), 1051 1052 .identify_state = m920x_identify_state, 1053 .num_adapters = 2, 1054 .adapter = {{ 1055 .num_frontends = 1, 1056 .fe = {{ 1057 1058 .caps = DVB_USB_ADAP_HAS_PID_FILTER | 1059 DVB_USB_ADAP_PID_FILTER_CAN_BE_TURNED_OFF, 1060 1061 .pid_filter_count = 8, 1062 .pid_filter = m920x_pid_filter, 1063 .pid_filter_ctrl = m920x_pid_filter_ctrl, 1064 1065 .frontend_attach = m920x_tda10046_08_frontend_attach, 1066 .tuner_attach = m920x_tda8275_60_tuner_attach, 1067 1068 .stream = { 1069 .type = USB_BULK, 1070 .count = 8, 1071 .endpoint = 0x81, 1072 .u = { 1073 .bulk = { 1074 .buffersize = 512, 1075 } 1076 } 1077 }}, 1078 }},{ 1079 .num_frontends = 1, 1080 .fe = {{ 1081 1082 .caps = DVB_USB_ADAP_HAS_PID_FILTER | 1083 DVB_USB_ADAP_PID_FILTER_CAN_BE_TURNED_OFF, 1084 1085 .pid_filter_count = 8, 1086 .pid_filter = m920x_pid_filter, 1087 .pid_filter_ctrl = m920x_pid_filter_ctrl, 1088 1089 .frontend_attach = m920x_tda10046_0b_frontend_attach, 1090 .tuner_attach = m920x_tda8275_61_tuner_attach, 1091 1092 .stream = { 1093 .type = USB_BULK, 1094 .count = 8, 1095 .endpoint = 0x82, 1096 .u = { 1097 .bulk = { 1098 .buffersize = 512, 1099 } 1100 } 1101 }}, 1102 }, 1103 }}, 1104 .i2c_algo = &m920x_i2c_algo, 1105 1106 .num_device_descs = 1, 1107 .devices = { 1108 { .name = "LifeView TV Walker Twin DVB-T USB2.0", 1109 .cold_ids = { &m920x_table[ANUBIS_LIFEVIEW_TV_WALKER_TWIN_COLD], NULL }, 1110 .warm_ids = { &m920x_table[ANUBIS_LIFEVIEW_TV_WALKER_TWIN_WARM], NULL }, 1111 }, 1112 } 1113 }; 1114 1115 static struct dvb_usb_device_properties dposh_properties = { 1116 .caps = DVB_USB_IS_AN_I2C_ADAPTER, 1117 1118 .usb_ctrl = DEVICE_SPECIFIC, 1119 .firmware = "dvb-usb-dposh-01.fw", 1120 .download_firmware = m920x_firmware_download, 1121 1122 .size_of_priv = sizeof(struct m920x_state), 1123 1124 .identify_state = m920x_identify_state, 1125 .num_adapters = 1, 1126 .adapter = {{ 1127 .num_frontends = 1, 1128 .fe = {{ 1129 /* Hardware pid filters don't work with this device/firmware */ 1130 1131 .frontend_attach = m920x_mt352_frontend_attach, 1132 .tuner_attach = m920x_qt1010_tuner_attach, 1133 1134 .stream = { 1135 .type = USB_BULK, 1136 .count = 8, 1137 .endpoint = 0x81, 1138 .u = { 1139 .bulk = { 1140 .buffersize = 512, 1141 } 1142 } 1143 }, 1144 }}, 1145 }}, 1146 .i2c_algo = &m920x_i2c_algo, 1147 1148 .num_device_descs = 1, 1149 .devices = { 1150 { .name = "Dposh DVB-T USB2.0", 1151 .cold_ids = { &m920x_table[DPOSH_M9206_COLD], NULL }, 1152 .warm_ids = { &m920x_table[DPOSH_M9206_WARM], NULL }, 1153 }, 1154 } 1155 }; 1156 1157 static struct dvb_usb_device_properties pinnacle_pctv310e_properties = { 1158 .caps = DVB_USB_IS_AN_I2C_ADAPTER, 1159 1160 .usb_ctrl = DEVICE_SPECIFIC, 1161 .download_firmware = NULL, 1162 1163 .rc.legacy = { 1164 .rc_interval = 100, 1165 .rc_map_table = rc_map_pinnacle310e_table, 1166 .rc_map_size = ARRAY_SIZE(rc_map_pinnacle310e_table), 1167 .rc_query = m920x_rc_query, 1168 }, 1169 1170 .size_of_priv = sizeof(struct m920x_state), 1171 1172 .identify_state = m920x_identify_state, 1173 .num_adapters = 1, 1174 .adapter = {{ 1175 .num_frontends = 1, 1176 .fe = {{ 1177 1178 .caps = DVB_USB_ADAP_HAS_PID_FILTER | 1179 DVB_USB_ADAP_PID_FILTER_CAN_BE_TURNED_OFF, 1180 1181 .pid_filter_count = 8, 1182 .pid_filter = m920x_pid_filter, 1183 .pid_filter_ctrl = m920x_pid_filter_ctrl, 1184 1185 .frontend_attach = m920x_mt352_frontend_attach, 1186 .tuner_attach = m920x_fmd1216me_tuner_attach, 1187 1188 .stream = { 1189 .type = USB_ISOC, 1190 .count = 5, 1191 .endpoint = 0x84, 1192 .u = { 1193 .isoc = { 1194 .framesperurb = 128, 1195 .framesize = 564, 1196 .interval = 1, 1197 } 1198 } 1199 }, 1200 }}, 1201 } }, 1202 .i2c_algo = &m920x_i2c_algo, 1203 1204 .num_device_descs = 1, 1205 .devices = { 1206 { "Pinnacle PCTV 310e", 1207 { &m920x_table[VISIONPLUS_PINNACLE_PCTV310E], NULL }, 1208 { NULL }, 1209 } 1210 } 1211 }; 1212 1213 static struct dvb_usb_device_properties vp7049_properties = { 1214 .caps = DVB_USB_IS_AN_I2C_ADAPTER, 1215 1216 .usb_ctrl = DEVICE_SPECIFIC, 1217 .firmware = "dvb-usb-vp7049-0.95.fw", 1218 .download_firmware = m920x_firmware_download, 1219 1220 .rc.core = { 1221 .rc_interval = 150, 1222 .rc_codes = RC_MAP_TWINHAN_VP1027_DVBS, 1223 .rc_query = m920x_rc_core_query, 1224 .allowed_protos = RC_PROTO_BIT_UNKNOWN, 1225 }, 1226 1227 .size_of_priv = sizeof(struct m920x_state), 1228 1229 .identify_state = m920x_identify_state, 1230 .num_adapters = 1, 1231 .adapter = {{ 1232 .num_frontends = 1, 1233 .fe = {{ 1234 1235 .caps = DVB_USB_ADAP_HAS_PID_FILTER | 1236 DVB_USB_ADAP_PID_FILTER_CAN_BE_TURNED_OFF, 1237 1238 .pid_filter_count = 8, 1239 .pid_filter = m920x_pid_filter, 1240 .pid_filter_ctrl = m920x_pid_filter_ctrl, 1241 1242 .frontend_attach = m920x_mt352_frontend_attach_vp7049, 1243 .tuner_attach = m920x_mt2060_tuner_attach, 1244 1245 .stream = { 1246 .type = USB_BULK, 1247 .count = 8, 1248 .endpoint = 0x81, 1249 .u = { 1250 .bulk = { 1251 .buffersize = 512, 1252 } 1253 } 1254 }, 1255 } }, 1256 } }, 1257 .i2c_algo = &m920x_i2c_algo, 1258 1259 .num_device_descs = 1, 1260 .devices = { 1261 { "DTV-DVB UDTT7049", 1262 { &m920x_table[AZUREWAVE_TWINHAN_VP7049], NULL }, 1263 { NULL }, 1264 } 1265 } 1266 }; 1267 1268 static struct usb_driver m920x_driver = { 1269 .name = "dvb_usb_m920x", 1270 .probe = m920x_probe, 1271 .disconnect = dvb_usb_device_exit, 1272 .id_table = m920x_table, 1273 }; 1274 1275 module_usb_driver(m920x_driver); 1276 1277 MODULE_AUTHOR("Aapo Tahkola <aet@rasterburn.org>"); 1278 MODULE_DESCRIPTION("DVB Driver for ULI M920x"); 1279 MODULE_VERSION("0.1"); 1280 MODULE_LICENSE("GPL"); 1281