1 /* DVB USB framework compliant Linux driver for the 2 * DVBWorld DVB-S 2101, 2102, DVB-S2 2104, DVB-C 3101, 3 * TeVii S600, S630, S650, S660, S480, S421, S632 4 * Prof 1100, 7500, 5 * Geniatech SU3000, T220 Cards 6 * Copyright (C) 2008-2012 Igor M. Liplianin (liplianin@me.by) 7 * 8 * This program is free software; you can redistribute it and/or modify it 9 * under the terms of the GNU General Public License as published by the 10 * Free Software Foundation, version 2. 11 * 12 * see Documentation/dvb/README.dvb-usb for more information 13 */ 14 #include "dw2102.h" 15 #include "si21xx.h" 16 #include "stv0299.h" 17 #include "z0194a.h" 18 #include "stv0288.h" 19 #include "stb6000.h" 20 #include "eds1547.h" 21 #include "cx24116.h" 22 #include "tda1002x.h" 23 #include "mt312.h" 24 #include "zl10039.h" 25 #include "ts2020.h" 26 #include "ds3000.h" 27 #include "stv0900.h" 28 #include "stv6110.h" 29 #include "stb6100.h" 30 #include "stb6100_proc.h" 31 #include "m88rs2000.h" 32 #include "tda18271.h" 33 #include "cxd2820r.h" 34 35 /* Max transfer size done by I2C transfer functions */ 36 #define MAX_XFER_SIZE 64 37 38 #ifndef USB_PID_DW2102 39 #define USB_PID_DW2102 0x2102 40 #endif 41 42 #ifndef USB_PID_DW2104 43 #define USB_PID_DW2104 0x2104 44 #endif 45 46 #ifndef USB_PID_DW3101 47 #define USB_PID_DW3101 0x3101 48 #endif 49 50 #ifndef USB_PID_CINERGY_S 51 #define USB_PID_CINERGY_S 0x0064 52 #endif 53 54 #ifndef USB_PID_TEVII_S630 55 #define USB_PID_TEVII_S630 0xd630 56 #endif 57 58 #ifndef USB_PID_TEVII_S650 59 #define USB_PID_TEVII_S650 0xd650 60 #endif 61 62 #ifndef USB_PID_TEVII_S660 63 #define USB_PID_TEVII_S660 0xd660 64 #endif 65 66 #ifndef USB_PID_TEVII_S480_1 67 #define USB_PID_TEVII_S480_1 0xd481 68 #endif 69 70 #ifndef USB_PID_TEVII_S480_2 71 #define USB_PID_TEVII_S480_2 0xd482 72 #endif 73 74 #ifndef USB_PID_PROF_1100 75 #define USB_PID_PROF_1100 0xb012 76 #endif 77 78 #ifndef USB_PID_TEVII_S421 79 #define USB_PID_TEVII_S421 0xd421 80 #endif 81 82 #ifndef USB_PID_TEVII_S632 83 #define USB_PID_TEVII_S632 0xd632 84 #endif 85 86 #ifndef USB_PID_GOTVIEW_SAT_HD 87 #define USB_PID_GOTVIEW_SAT_HD 0x5456 88 #endif 89 90 #define DW210X_READ_MSG 0 91 #define DW210X_WRITE_MSG 1 92 93 #define REG_1F_SYMBOLRATE_BYTE0 0x1f 94 #define REG_20_SYMBOLRATE_BYTE1 0x20 95 #define REG_21_SYMBOLRATE_BYTE2 0x21 96 /* on my own*/ 97 #define DW2102_VOLTAGE_CTRL (0x1800) 98 #define SU3000_STREAM_CTRL (0x1900) 99 #define DW2102_RC_QUERY (0x1a00) 100 #define DW2102_LED_CTRL (0x1b00) 101 102 #define DW2101_FIRMWARE "dvb-usb-dw2101.fw" 103 #define DW2102_FIRMWARE "dvb-usb-dw2102.fw" 104 #define DW2104_FIRMWARE "dvb-usb-dw2104.fw" 105 #define DW3101_FIRMWARE "dvb-usb-dw3101.fw" 106 #define S630_FIRMWARE "dvb-usb-s630.fw" 107 #define S660_FIRMWARE "dvb-usb-s660.fw" 108 #define P1100_FIRMWARE "dvb-usb-p1100.fw" 109 #define P7500_FIRMWARE "dvb-usb-p7500.fw" 110 111 #define err_str "did not find the firmware file. (%s) " \ 112 "Please see linux/Documentation/dvb/ for more details " \ 113 "on firmware-problems." 114 115 struct dw2102_state { 116 u8 initialized; 117 struct i2c_client *i2c_client_tuner; 118 int (*old_set_voltage)(struct dvb_frontend *f, fe_sec_voltage_t v); 119 }; 120 121 /* debug */ 122 static int dvb_usb_dw2102_debug; 123 module_param_named(debug, dvb_usb_dw2102_debug, int, 0644); 124 MODULE_PARM_DESC(debug, "set debugging level (1=info 2=xfer 4=rc(or-able))." 125 DVB_USB_DEBUG_STATUS); 126 127 /* demod probe */ 128 static int demod_probe = 1; 129 module_param_named(demod, demod_probe, int, 0644); 130 MODULE_PARM_DESC(demod, "demod to probe (1=cx24116 2=stv0903+stv6110 " 131 "4=stv0903+stb6100(or-able))."); 132 133 DVB_DEFINE_MOD_OPT_ADAPTER_NR(adapter_nr); 134 135 static int dw210x_op_rw(struct usb_device *dev, u8 request, u16 value, 136 u16 index, u8 * data, u16 len, int flags) 137 { 138 int ret; 139 u8 *u8buf; 140 unsigned int pipe = (flags == DW210X_READ_MSG) ? 141 usb_rcvctrlpipe(dev, 0) : usb_sndctrlpipe(dev, 0); 142 u8 request_type = (flags == DW210X_READ_MSG) ? USB_DIR_IN : USB_DIR_OUT; 143 144 u8buf = kmalloc(len, GFP_KERNEL); 145 if (!u8buf) 146 return -ENOMEM; 147 148 149 if (flags == DW210X_WRITE_MSG) 150 memcpy(u8buf, data, len); 151 ret = usb_control_msg(dev, pipe, request, request_type | USB_TYPE_VENDOR, 152 value, index , u8buf, len, 2000); 153 154 if (flags == DW210X_READ_MSG) 155 memcpy(data, u8buf, len); 156 157 kfree(u8buf); 158 return ret; 159 } 160 161 /* I2C */ 162 static int dw2102_i2c_transfer(struct i2c_adapter *adap, struct i2c_msg msg[], 163 int num) 164 { 165 struct dvb_usb_device *d = i2c_get_adapdata(adap); 166 int i = 0; 167 u8 buf6[] = {0x2c, 0x05, 0xc0, 0, 0, 0, 0}; 168 u16 value; 169 170 if (!d) 171 return -ENODEV; 172 if (mutex_lock_interruptible(&d->i2c_mutex) < 0) 173 return -EAGAIN; 174 175 switch (num) { 176 case 2: 177 /* read stv0299 register */ 178 value = msg[0].buf[0];/* register */ 179 for (i = 0; i < msg[1].len; i++) { 180 dw210x_op_rw(d->udev, 0xb5, value + i, 0, 181 buf6, 2, DW210X_READ_MSG); 182 msg[1].buf[i] = buf6[0]; 183 } 184 break; 185 case 1: 186 switch (msg[0].addr) { 187 case 0x68: 188 /* write to stv0299 register */ 189 buf6[0] = 0x2a; 190 buf6[1] = msg[0].buf[0]; 191 buf6[2] = msg[0].buf[1]; 192 dw210x_op_rw(d->udev, 0xb2, 0, 0, 193 buf6, 3, DW210X_WRITE_MSG); 194 break; 195 case 0x60: 196 if (msg[0].flags == 0) { 197 /* write to tuner pll */ 198 buf6[0] = 0x2c; 199 buf6[1] = 5; 200 buf6[2] = 0xc0; 201 buf6[3] = msg[0].buf[0]; 202 buf6[4] = msg[0].buf[1]; 203 buf6[5] = msg[0].buf[2]; 204 buf6[6] = msg[0].buf[3]; 205 dw210x_op_rw(d->udev, 0xb2, 0, 0, 206 buf6, 7, DW210X_WRITE_MSG); 207 } else { 208 /* read from tuner */ 209 dw210x_op_rw(d->udev, 0xb5, 0, 0, 210 buf6, 1, DW210X_READ_MSG); 211 msg[0].buf[0] = buf6[0]; 212 } 213 break; 214 case (DW2102_RC_QUERY): 215 dw210x_op_rw(d->udev, 0xb8, 0, 0, 216 buf6, 2, DW210X_READ_MSG); 217 msg[0].buf[0] = buf6[0]; 218 msg[0].buf[1] = buf6[1]; 219 break; 220 case (DW2102_VOLTAGE_CTRL): 221 buf6[0] = 0x30; 222 buf6[1] = msg[0].buf[0]; 223 dw210x_op_rw(d->udev, 0xb2, 0, 0, 224 buf6, 2, DW210X_WRITE_MSG); 225 break; 226 } 227 228 break; 229 } 230 231 mutex_unlock(&d->i2c_mutex); 232 return num; 233 } 234 235 static int dw2102_serit_i2c_transfer(struct i2c_adapter *adap, 236 struct i2c_msg msg[], int num) 237 { 238 struct dvb_usb_device *d = i2c_get_adapdata(adap); 239 u8 buf6[] = {0, 0, 0, 0, 0, 0, 0}; 240 241 if (!d) 242 return -ENODEV; 243 if (mutex_lock_interruptible(&d->i2c_mutex) < 0) 244 return -EAGAIN; 245 246 switch (num) { 247 case 2: 248 /* read si2109 register by number */ 249 buf6[0] = msg[0].addr << 1; 250 buf6[1] = msg[0].len; 251 buf6[2] = msg[0].buf[0]; 252 dw210x_op_rw(d->udev, 0xc2, 0, 0, 253 buf6, msg[0].len + 2, DW210X_WRITE_MSG); 254 /* read si2109 register */ 255 dw210x_op_rw(d->udev, 0xc3, 0xd0, 0, 256 buf6, msg[1].len + 2, DW210X_READ_MSG); 257 memcpy(msg[1].buf, buf6 + 2, msg[1].len); 258 259 break; 260 case 1: 261 switch (msg[0].addr) { 262 case 0x68: 263 /* write to si2109 register */ 264 buf6[0] = msg[0].addr << 1; 265 buf6[1] = msg[0].len; 266 memcpy(buf6 + 2, msg[0].buf, msg[0].len); 267 dw210x_op_rw(d->udev, 0xc2, 0, 0, buf6, 268 msg[0].len + 2, DW210X_WRITE_MSG); 269 break; 270 case(DW2102_RC_QUERY): 271 dw210x_op_rw(d->udev, 0xb8, 0, 0, 272 buf6, 2, DW210X_READ_MSG); 273 msg[0].buf[0] = buf6[0]; 274 msg[0].buf[1] = buf6[1]; 275 break; 276 case(DW2102_VOLTAGE_CTRL): 277 buf6[0] = 0x30; 278 buf6[1] = msg[0].buf[0]; 279 dw210x_op_rw(d->udev, 0xb2, 0, 0, 280 buf6, 2, DW210X_WRITE_MSG); 281 break; 282 } 283 break; 284 } 285 286 mutex_unlock(&d->i2c_mutex); 287 return num; 288 } 289 290 static int dw2102_earda_i2c_transfer(struct i2c_adapter *adap, struct i2c_msg msg[], int num) 291 { 292 struct dvb_usb_device *d = i2c_get_adapdata(adap); 293 int ret; 294 295 if (!d) 296 return -ENODEV; 297 if (mutex_lock_interruptible(&d->i2c_mutex) < 0) 298 return -EAGAIN; 299 300 switch (num) { 301 case 2: { 302 /* read */ 303 /* first write first register number */ 304 u8 ibuf[MAX_XFER_SIZE], obuf[3]; 305 306 if (2 + msg[1].len > sizeof(ibuf)) { 307 warn("i2c rd: len=%d is too big!\n", 308 msg[1].len); 309 ret = -EOPNOTSUPP; 310 goto unlock; 311 } 312 313 obuf[0] = msg[0].addr << 1; 314 obuf[1] = msg[0].len; 315 obuf[2] = msg[0].buf[0]; 316 dw210x_op_rw(d->udev, 0xc2, 0, 0, 317 obuf, msg[0].len + 2, DW210X_WRITE_MSG); 318 /* second read registers */ 319 dw210x_op_rw(d->udev, 0xc3, 0xd1 , 0, 320 ibuf, msg[1].len + 2, DW210X_READ_MSG); 321 memcpy(msg[1].buf, ibuf + 2, msg[1].len); 322 323 break; 324 } 325 case 1: 326 switch (msg[0].addr) { 327 case 0x68: { 328 /* write to register */ 329 u8 obuf[MAX_XFER_SIZE]; 330 331 if (2 + msg[0].len > sizeof(obuf)) { 332 warn("i2c wr: len=%d is too big!\n", 333 msg[1].len); 334 ret = -EOPNOTSUPP; 335 goto unlock; 336 } 337 338 obuf[0] = msg[0].addr << 1; 339 obuf[1] = msg[0].len; 340 memcpy(obuf + 2, msg[0].buf, msg[0].len); 341 dw210x_op_rw(d->udev, 0xc2, 0, 0, 342 obuf, msg[0].len + 2, DW210X_WRITE_MSG); 343 break; 344 } 345 case 0x61: { 346 /* write to tuner */ 347 u8 obuf[MAX_XFER_SIZE]; 348 349 if (2 + msg[0].len > sizeof(obuf)) { 350 warn("i2c wr: len=%d is too big!\n", 351 msg[1].len); 352 ret = -EOPNOTSUPP; 353 goto unlock; 354 } 355 356 obuf[0] = msg[0].addr << 1; 357 obuf[1] = msg[0].len; 358 memcpy(obuf + 2, msg[0].buf, msg[0].len); 359 dw210x_op_rw(d->udev, 0xc2, 0, 0, 360 obuf, msg[0].len + 2, DW210X_WRITE_MSG); 361 break; 362 } 363 case(DW2102_RC_QUERY): { 364 u8 ibuf[2]; 365 dw210x_op_rw(d->udev, 0xb8, 0, 0, 366 ibuf, 2, DW210X_READ_MSG); 367 memcpy(msg[0].buf, ibuf , 2); 368 break; 369 } 370 case(DW2102_VOLTAGE_CTRL): { 371 u8 obuf[2]; 372 obuf[0] = 0x30; 373 obuf[1] = msg[0].buf[0]; 374 dw210x_op_rw(d->udev, 0xb2, 0, 0, 375 obuf, 2, DW210X_WRITE_MSG); 376 break; 377 } 378 } 379 380 break; 381 } 382 ret = num; 383 384 unlock: 385 mutex_unlock(&d->i2c_mutex); 386 return ret; 387 } 388 389 static int dw2104_i2c_transfer(struct i2c_adapter *adap, struct i2c_msg msg[], int num) 390 { 391 struct dvb_usb_device *d = i2c_get_adapdata(adap); 392 int len, i, j, ret; 393 394 if (!d) 395 return -ENODEV; 396 if (mutex_lock_interruptible(&d->i2c_mutex) < 0) 397 return -EAGAIN; 398 399 for (j = 0; j < num; j++) { 400 switch (msg[j].addr) { 401 case(DW2102_RC_QUERY): { 402 u8 ibuf[2]; 403 dw210x_op_rw(d->udev, 0xb8, 0, 0, 404 ibuf, 2, DW210X_READ_MSG); 405 memcpy(msg[j].buf, ibuf , 2); 406 break; 407 } 408 case(DW2102_VOLTAGE_CTRL): { 409 u8 obuf[2]; 410 obuf[0] = 0x30; 411 obuf[1] = msg[j].buf[0]; 412 dw210x_op_rw(d->udev, 0xb2, 0, 0, 413 obuf, 2, DW210X_WRITE_MSG); 414 break; 415 } 416 /*case 0x55: cx24116 417 case 0x6a: stv0903 418 case 0x68: ds3000, stv0903 419 case 0x60: ts2020, stv6110, stb6100 */ 420 default: { 421 if (msg[j].flags == I2C_M_RD) { 422 /* read registers */ 423 u8 ibuf[MAX_XFER_SIZE]; 424 425 if (2 + msg[j].len > sizeof(ibuf)) { 426 warn("i2c rd: len=%d is too big!\n", 427 msg[j].len); 428 ret = -EOPNOTSUPP; 429 goto unlock; 430 } 431 432 dw210x_op_rw(d->udev, 0xc3, 433 (msg[j].addr << 1) + 1, 0, 434 ibuf, msg[j].len + 2, 435 DW210X_READ_MSG); 436 memcpy(msg[j].buf, ibuf + 2, msg[j].len); 437 mdelay(10); 438 } else if (((msg[j].buf[0] == 0xb0) && 439 (msg[j].addr == 0x68)) || 440 ((msg[j].buf[0] == 0xf7) && 441 (msg[j].addr == 0x55))) { 442 /* write firmware */ 443 u8 obuf[19]; 444 obuf[0] = msg[j].addr << 1; 445 obuf[1] = (msg[j].len > 15 ? 17 : msg[j].len); 446 obuf[2] = msg[j].buf[0]; 447 len = msg[j].len - 1; 448 i = 1; 449 do { 450 memcpy(obuf + 3, msg[j].buf + i, 451 (len > 16 ? 16 : len)); 452 dw210x_op_rw(d->udev, 0xc2, 0, 0, 453 obuf, (len > 16 ? 16 : len) + 3, 454 DW210X_WRITE_MSG); 455 i += 16; 456 len -= 16; 457 } while (len > 0); 458 } else { 459 /* write registers */ 460 u8 obuf[MAX_XFER_SIZE]; 461 462 if (2 + msg[j].len > sizeof(obuf)) { 463 warn("i2c wr: len=%d is too big!\n", 464 msg[j].len); 465 ret = -EOPNOTSUPP; 466 goto unlock; 467 } 468 469 obuf[0] = msg[j].addr << 1; 470 obuf[1] = msg[j].len; 471 memcpy(obuf + 2, msg[j].buf, msg[j].len); 472 dw210x_op_rw(d->udev, 0xc2, 0, 0, 473 obuf, msg[j].len + 2, 474 DW210X_WRITE_MSG); 475 } 476 break; 477 } 478 } 479 480 } 481 ret = num; 482 483 unlock: 484 mutex_unlock(&d->i2c_mutex); 485 return ret; 486 } 487 488 static int dw3101_i2c_transfer(struct i2c_adapter *adap, struct i2c_msg msg[], 489 int num) 490 { 491 struct dvb_usb_device *d = i2c_get_adapdata(adap); 492 int ret; 493 int i; 494 495 if (!d) 496 return -ENODEV; 497 if (mutex_lock_interruptible(&d->i2c_mutex) < 0) 498 return -EAGAIN; 499 500 switch (num) { 501 case 2: { 502 /* read */ 503 /* first write first register number */ 504 u8 ibuf[MAX_XFER_SIZE], obuf[3]; 505 506 if (2 + msg[1].len > sizeof(ibuf)) { 507 warn("i2c rd: len=%d is too big!\n", 508 msg[1].len); 509 ret = -EOPNOTSUPP; 510 goto unlock; 511 } 512 obuf[0] = msg[0].addr << 1; 513 obuf[1] = msg[0].len; 514 obuf[2] = msg[0].buf[0]; 515 dw210x_op_rw(d->udev, 0xc2, 0, 0, 516 obuf, msg[0].len + 2, DW210X_WRITE_MSG); 517 /* second read registers */ 518 dw210x_op_rw(d->udev, 0xc3, 0x19 , 0, 519 ibuf, msg[1].len + 2, DW210X_READ_MSG); 520 memcpy(msg[1].buf, ibuf + 2, msg[1].len); 521 522 break; 523 } 524 case 1: 525 switch (msg[0].addr) { 526 case 0x60: 527 case 0x0c: { 528 /* write to register */ 529 u8 obuf[MAX_XFER_SIZE]; 530 531 if (2 + msg[0].len > sizeof(obuf)) { 532 warn("i2c wr: len=%d is too big!\n", 533 msg[0].len); 534 ret = -EOPNOTSUPP; 535 goto unlock; 536 } 537 obuf[0] = msg[0].addr << 1; 538 obuf[1] = msg[0].len; 539 memcpy(obuf + 2, msg[0].buf, msg[0].len); 540 dw210x_op_rw(d->udev, 0xc2, 0, 0, 541 obuf, msg[0].len + 2, DW210X_WRITE_MSG); 542 break; 543 } 544 case(DW2102_RC_QUERY): { 545 u8 ibuf[2]; 546 dw210x_op_rw(d->udev, 0xb8, 0, 0, 547 ibuf, 2, DW210X_READ_MSG); 548 memcpy(msg[0].buf, ibuf , 2); 549 break; 550 } 551 } 552 553 break; 554 } 555 556 for (i = 0; i < num; i++) { 557 deb_xfer("%02x:%02x: %s ", i, msg[i].addr, 558 msg[i].flags == 0 ? ">>>" : "<<<"); 559 debug_dump(msg[i].buf, msg[i].len, deb_xfer); 560 } 561 ret = num; 562 563 unlock: 564 mutex_unlock(&d->i2c_mutex); 565 return ret; 566 } 567 568 static int s6x0_i2c_transfer(struct i2c_adapter *adap, struct i2c_msg msg[], 569 int num) 570 { 571 struct dvb_usb_device *d = i2c_get_adapdata(adap); 572 struct usb_device *udev; 573 int len, i, j, ret; 574 575 if (!d) 576 return -ENODEV; 577 udev = d->udev; 578 if (mutex_lock_interruptible(&d->i2c_mutex) < 0) 579 return -EAGAIN; 580 581 for (j = 0; j < num; j++) { 582 switch (msg[j].addr) { 583 case (DW2102_RC_QUERY): { 584 u8 ibuf[5]; 585 dw210x_op_rw(d->udev, 0xb8, 0, 0, 586 ibuf, 5, DW210X_READ_MSG); 587 memcpy(msg[j].buf, ibuf + 3, 2); 588 break; 589 } 590 case (DW2102_VOLTAGE_CTRL): { 591 u8 obuf[2]; 592 593 obuf[0] = 1; 594 obuf[1] = msg[j].buf[1];/* off-on */ 595 dw210x_op_rw(d->udev, 0x8a, 0, 0, 596 obuf, 2, DW210X_WRITE_MSG); 597 obuf[0] = 3; 598 obuf[1] = msg[j].buf[0];/* 13v-18v */ 599 dw210x_op_rw(d->udev, 0x8a, 0, 0, 600 obuf, 2, DW210X_WRITE_MSG); 601 break; 602 } 603 case (DW2102_LED_CTRL): { 604 u8 obuf[2]; 605 606 obuf[0] = 5; 607 obuf[1] = msg[j].buf[0]; 608 dw210x_op_rw(d->udev, 0x8a, 0, 0, 609 obuf, 2, DW210X_WRITE_MSG); 610 break; 611 } 612 /*case 0x55: cx24116 613 case 0x6a: stv0903 614 case 0x68: ds3000, stv0903, rs2000 615 case 0x60: ts2020, stv6110, stb6100 616 case 0xa0: eeprom */ 617 default: { 618 if (msg[j].flags == I2C_M_RD) { 619 /* read registers */ 620 u8 ibuf[MAX_XFER_SIZE]; 621 622 if (msg[j].len > sizeof(ibuf)) { 623 warn("i2c rd: len=%d is too big!\n", 624 msg[j].len); 625 ret = -EOPNOTSUPP; 626 goto unlock; 627 } 628 629 dw210x_op_rw(d->udev, 0x91, 0, 0, 630 ibuf, msg[j].len, 631 DW210X_READ_MSG); 632 memcpy(msg[j].buf, ibuf, msg[j].len); 633 break; 634 } else if ((msg[j].buf[0] == 0xb0) && 635 (msg[j].addr == 0x68)) { 636 /* write firmware */ 637 u8 obuf[19]; 638 obuf[0] = (msg[j].len > 16 ? 639 18 : msg[j].len + 1); 640 obuf[1] = msg[j].addr << 1; 641 obuf[2] = msg[j].buf[0]; 642 len = msg[j].len - 1; 643 i = 1; 644 do { 645 memcpy(obuf + 3, msg[j].buf + i, 646 (len > 16 ? 16 : len)); 647 dw210x_op_rw(d->udev, 0x80, 0, 0, 648 obuf, (len > 16 ? 16 : len) + 3, 649 DW210X_WRITE_MSG); 650 i += 16; 651 len -= 16; 652 } while (len > 0); 653 } else if (j < (num - 1)) { 654 /* write register addr before read */ 655 u8 obuf[MAX_XFER_SIZE]; 656 657 if (2 + msg[j].len > sizeof(obuf)) { 658 warn("i2c wr: len=%d is too big!\n", 659 msg[j].len); 660 ret = -EOPNOTSUPP; 661 goto unlock; 662 } 663 664 obuf[0] = msg[j + 1].len; 665 obuf[1] = (msg[j].addr << 1); 666 memcpy(obuf + 2, msg[j].buf, msg[j].len); 667 dw210x_op_rw(d->udev, 668 le16_to_cpu(udev->descriptor.idProduct) == 669 0x7500 ? 0x92 : 0x90, 0, 0, 670 obuf, msg[j].len + 2, 671 DW210X_WRITE_MSG); 672 break; 673 } else { 674 /* write registers */ 675 u8 obuf[MAX_XFER_SIZE]; 676 677 if (2 + msg[j].len > sizeof(obuf)) { 678 warn("i2c wr: len=%d is too big!\n", 679 msg[j].len); 680 ret = -EOPNOTSUPP; 681 goto unlock; 682 } 683 obuf[0] = msg[j].len + 1; 684 obuf[1] = (msg[j].addr << 1); 685 memcpy(obuf + 2, msg[j].buf, msg[j].len); 686 dw210x_op_rw(d->udev, 0x80, 0, 0, 687 obuf, msg[j].len + 2, 688 DW210X_WRITE_MSG); 689 break; 690 } 691 break; 692 } 693 } 694 } 695 ret = num; 696 697 unlock: 698 mutex_unlock(&d->i2c_mutex); 699 return ret; 700 } 701 702 static int su3000_i2c_transfer(struct i2c_adapter *adap, struct i2c_msg msg[], 703 int num) 704 { 705 struct dvb_usb_device *d = i2c_get_adapdata(adap); 706 u8 obuf[0x40], ibuf[0x40]; 707 708 if (!d) 709 return -ENODEV; 710 if (mutex_lock_interruptible(&d->i2c_mutex) < 0) 711 return -EAGAIN; 712 713 switch (num) { 714 case 1: 715 switch (msg[0].addr) { 716 case SU3000_STREAM_CTRL: 717 obuf[0] = msg[0].buf[0] + 0x36; 718 obuf[1] = 3; 719 obuf[2] = 0; 720 if (dvb_usb_generic_rw(d, obuf, 3, ibuf, 0, 0) < 0) 721 err("i2c transfer failed."); 722 break; 723 case DW2102_RC_QUERY: 724 obuf[0] = 0x10; 725 if (dvb_usb_generic_rw(d, obuf, 1, ibuf, 2, 0) < 0) 726 err("i2c transfer failed."); 727 msg[0].buf[1] = ibuf[0]; 728 msg[0].buf[0] = ibuf[1]; 729 break; 730 default: 731 /* always i2c write*/ 732 obuf[0] = 0x08; 733 obuf[1] = msg[0].addr; 734 obuf[2] = msg[0].len; 735 736 memcpy(&obuf[3], msg[0].buf, msg[0].len); 737 738 if (dvb_usb_generic_rw(d, obuf, msg[0].len + 3, 739 ibuf, 1, 0) < 0) 740 err("i2c transfer failed."); 741 742 } 743 break; 744 case 2: 745 /* always i2c read */ 746 obuf[0] = 0x09; 747 obuf[1] = msg[0].len; 748 obuf[2] = msg[1].len; 749 obuf[3] = msg[0].addr; 750 memcpy(&obuf[4], msg[0].buf, msg[0].len); 751 752 if (dvb_usb_generic_rw(d, obuf, msg[0].len + 4, 753 ibuf, msg[1].len + 1, 0) < 0) 754 err("i2c transfer failed."); 755 756 memcpy(msg[1].buf, &ibuf[1], msg[1].len); 757 break; 758 default: 759 warn("more than 2 i2c messages at a time is not handled yet."); 760 break; 761 } 762 mutex_unlock(&d->i2c_mutex); 763 return num; 764 } 765 766 static u32 dw210x_i2c_func(struct i2c_adapter *adapter) 767 { 768 return I2C_FUNC_I2C; 769 } 770 771 static struct i2c_algorithm dw2102_i2c_algo = { 772 .master_xfer = dw2102_i2c_transfer, 773 .functionality = dw210x_i2c_func, 774 }; 775 776 static struct i2c_algorithm dw2102_serit_i2c_algo = { 777 .master_xfer = dw2102_serit_i2c_transfer, 778 .functionality = dw210x_i2c_func, 779 }; 780 781 static struct i2c_algorithm dw2102_earda_i2c_algo = { 782 .master_xfer = dw2102_earda_i2c_transfer, 783 .functionality = dw210x_i2c_func, 784 }; 785 786 static struct i2c_algorithm dw2104_i2c_algo = { 787 .master_xfer = dw2104_i2c_transfer, 788 .functionality = dw210x_i2c_func, 789 }; 790 791 static struct i2c_algorithm dw3101_i2c_algo = { 792 .master_xfer = dw3101_i2c_transfer, 793 .functionality = dw210x_i2c_func, 794 }; 795 796 static struct i2c_algorithm s6x0_i2c_algo = { 797 .master_xfer = s6x0_i2c_transfer, 798 .functionality = dw210x_i2c_func, 799 }; 800 801 static struct i2c_algorithm su3000_i2c_algo = { 802 .master_xfer = su3000_i2c_transfer, 803 .functionality = dw210x_i2c_func, 804 }; 805 806 static int dw210x_read_mac_address(struct dvb_usb_device *d, u8 mac[6]) 807 { 808 int i; 809 u8 ibuf[] = {0, 0}; 810 u8 eeprom[256], eepromline[16]; 811 812 for (i = 0; i < 256; i++) { 813 if (dw210x_op_rw(d->udev, 0xb6, 0xa0 , i, ibuf, 2, DW210X_READ_MSG) < 0) { 814 err("read eeprom failed."); 815 return -1; 816 } else { 817 eepromline[i%16] = ibuf[0]; 818 eeprom[i] = ibuf[0]; 819 } 820 if ((i % 16) == 15) { 821 deb_xfer("%02x: ", i - 15); 822 debug_dump(eepromline, 16, deb_xfer); 823 } 824 } 825 826 memcpy(mac, eeprom + 8, 6); 827 return 0; 828 }; 829 830 static int s6x0_read_mac_address(struct dvb_usb_device *d, u8 mac[6]) 831 { 832 int i, ret; 833 u8 ibuf[] = { 0 }, obuf[] = { 0 }; 834 u8 eeprom[256], eepromline[16]; 835 struct i2c_msg msg[] = { 836 { 837 .addr = 0xa0 >> 1, 838 .flags = 0, 839 .buf = obuf, 840 .len = 1, 841 }, { 842 .addr = 0xa0 >> 1, 843 .flags = I2C_M_RD, 844 .buf = ibuf, 845 .len = 1, 846 } 847 }; 848 849 for (i = 0; i < 256; i++) { 850 obuf[0] = i; 851 ret = s6x0_i2c_transfer(&d->i2c_adap, msg, 2); 852 if (ret != 2) { 853 err("read eeprom failed."); 854 return -1; 855 } else { 856 eepromline[i % 16] = ibuf[0]; 857 eeprom[i] = ibuf[0]; 858 } 859 860 if ((i % 16) == 15) { 861 deb_xfer("%02x: ", i - 15); 862 debug_dump(eepromline, 16, deb_xfer); 863 } 864 } 865 866 memcpy(mac, eeprom + 16, 6); 867 return 0; 868 }; 869 870 static int su3000_streaming_ctrl(struct dvb_usb_adapter *adap, int onoff) 871 { 872 static u8 command_start[] = {0x00}; 873 static u8 command_stop[] = {0x01}; 874 struct i2c_msg msg = { 875 .addr = SU3000_STREAM_CTRL, 876 .flags = 0, 877 .buf = onoff ? command_start : command_stop, 878 .len = 1 879 }; 880 881 i2c_transfer(&adap->dev->i2c_adap, &msg, 1); 882 883 return 0; 884 } 885 886 static int su3000_power_ctrl(struct dvb_usb_device *d, int i) 887 { 888 struct dw2102_state *state = (struct dw2102_state *)d->priv; 889 u8 obuf[] = {0xde, 0}; 890 891 info("%s: %d, initialized %d\n", __func__, i, state->initialized); 892 893 if (i && !state->initialized) { 894 state->initialized = 1; 895 /* reset board */ 896 dvb_usb_generic_rw(d, obuf, 2, NULL, 0, 0); 897 } 898 899 return 0; 900 } 901 902 static int su3000_read_mac_address(struct dvb_usb_device *d, u8 mac[6]) 903 { 904 int i; 905 u8 obuf[] = { 0x1f, 0xf0 }; 906 u8 ibuf[] = { 0 }; 907 struct i2c_msg msg[] = { 908 { 909 .addr = 0x51, 910 .flags = 0, 911 .buf = obuf, 912 .len = 2, 913 }, { 914 .addr = 0x51, 915 .flags = I2C_M_RD, 916 .buf = ibuf, 917 .len = 1, 918 919 } 920 }; 921 922 for (i = 0; i < 6; i++) { 923 obuf[1] = 0xf0 + i; 924 if (i2c_transfer(&d->i2c_adap, msg, 2) != 2) 925 break; 926 else 927 mac[i] = ibuf[0]; 928 929 debug_dump(mac, 6, printk); 930 } 931 932 return 0; 933 } 934 935 static int su3000_identify_state(struct usb_device *udev, 936 struct dvb_usb_device_properties *props, 937 struct dvb_usb_device_description **desc, 938 int *cold) 939 { 940 info("%s\n", __func__); 941 942 *cold = 0; 943 return 0; 944 } 945 946 static int dw210x_set_voltage(struct dvb_frontend *fe, fe_sec_voltage_t voltage) 947 { 948 static u8 command_13v[] = {0x00, 0x01}; 949 static u8 command_18v[] = {0x01, 0x01}; 950 static u8 command_off[] = {0x00, 0x00}; 951 struct i2c_msg msg = { 952 .addr = DW2102_VOLTAGE_CTRL, 953 .flags = 0, 954 .buf = command_off, 955 .len = 2, 956 }; 957 958 struct dvb_usb_adapter *udev_adap = 959 (struct dvb_usb_adapter *)(fe->dvb->priv); 960 if (voltage == SEC_VOLTAGE_18) 961 msg.buf = command_18v; 962 else if (voltage == SEC_VOLTAGE_13) 963 msg.buf = command_13v; 964 965 i2c_transfer(&udev_adap->dev->i2c_adap, &msg, 1); 966 967 return 0; 968 } 969 970 static int s660_set_voltage(struct dvb_frontend *fe, fe_sec_voltage_t voltage) 971 { 972 struct dvb_usb_adapter *d = 973 (struct dvb_usb_adapter *)(fe->dvb->priv); 974 struct dw2102_state *st = (struct dw2102_state *)d->dev->priv; 975 976 dw210x_set_voltage(fe, voltage); 977 if (st->old_set_voltage) 978 st->old_set_voltage(fe, voltage); 979 980 return 0; 981 } 982 983 static void dw210x_led_ctrl(struct dvb_frontend *fe, int offon) 984 { 985 static u8 led_off[] = { 0 }; 986 static u8 led_on[] = { 1 }; 987 struct i2c_msg msg = { 988 .addr = DW2102_LED_CTRL, 989 .flags = 0, 990 .buf = led_off, 991 .len = 1 992 }; 993 struct dvb_usb_adapter *udev_adap = 994 (struct dvb_usb_adapter *)(fe->dvb->priv); 995 996 if (offon) 997 msg.buf = led_on; 998 i2c_transfer(&udev_adap->dev->i2c_adap, &msg, 1); 999 } 1000 1001 static struct stv0299_config sharp_z0194a_config = { 1002 .demod_address = 0x68, 1003 .inittab = sharp_z0194a_inittab, 1004 .mclk = 88000000UL, 1005 .invert = 1, 1006 .skip_reinit = 0, 1007 .lock_output = STV0299_LOCKOUTPUT_1, 1008 .volt13_op0_op1 = STV0299_VOLT13_OP1, 1009 .min_delay_ms = 100, 1010 .set_symbol_rate = sharp_z0194a_set_symbol_rate, 1011 }; 1012 1013 static struct cx24116_config dw2104_config = { 1014 .demod_address = 0x55, 1015 .mpg_clk_pos_pol = 0x01, 1016 }; 1017 1018 static struct si21xx_config serit_sp1511lhb_config = { 1019 .demod_address = 0x68, 1020 .min_delay_ms = 100, 1021 1022 }; 1023 1024 static struct tda10023_config dw3101_tda10023_config = { 1025 .demod_address = 0x0c, 1026 .invert = 1, 1027 }; 1028 1029 static struct mt312_config zl313_config = { 1030 .demod_address = 0x0e, 1031 }; 1032 1033 static struct ds3000_config dw2104_ds3000_config = { 1034 .demod_address = 0x68, 1035 }; 1036 1037 static struct ts2020_config dw2104_ts2020_config = { 1038 .tuner_address = 0x60, 1039 .clk_out_div = 1, 1040 .frequency_div = 1060000, 1041 }; 1042 1043 static struct ds3000_config s660_ds3000_config = { 1044 .demod_address = 0x68, 1045 .ci_mode = 1, 1046 .set_lock_led = dw210x_led_ctrl, 1047 }; 1048 1049 static struct ts2020_config s660_ts2020_config = { 1050 .tuner_address = 0x60, 1051 .clk_out_div = 1, 1052 .frequency_div = 1146000, 1053 }; 1054 1055 static struct stv0900_config dw2104a_stv0900_config = { 1056 .demod_address = 0x6a, 1057 .demod_mode = 0, 1058 .xtal = 27000000, 1059 .clkmode = 3,/* 0-CLKI, 2-XTALI, else AUTO */ 1060 .diseqc_mode = 2,/* 2/3 PWM */ 1061 .tun1_maddress = 0,/* 0x60 */ 1062 .tun1_adc = 0,/* 2 Vpp */ 1063 .path1_mode = 3, 1064 }; 1065 1066 static struct stb6100_config dw2104a_stb6100_config = { 1067 .tuner_address = 0x60, 1068 .refclock = 27000000, 1069 }; 1070 1071 static struct stv0900_config dw2104_stv0900_config = { 1072 .demod_address = 0x68, 1073 .demod_mode = 0, 1074 .xtal = 8000000, 1075 .clkmode = 3, 1076 .diseqc_mode = 2, 1077 .tun1_maddress = 0, 1078 .tun1_adc = 1,/* 1 Vpp */ 1079 .path1_mode = 3, 1080 }; 1081 1082 static struct stv6110_config dw2104_stv6110_config = { 1083 .i2c_address = 0x60, 1084 .mclk = 16000000, 1085 .clk_div = 1, 1086 }; 1087 1088 static struct stv0900_config prof_7500_stv0900_config = { 1089 .demod_address = 0x6a, 1090 .demod_mode = 0, 1091 .xtal = 27000000, 1092 .clkmode = 3,/* 0-CLKI, 2-XTALI, else AUTO */ 1093 .diseqc_mode = 2,/* 2/3 PWM */ 1094 .tun1_maddress = 0,/* 0x60 */ 1095 .tun1_adc = 0,/* 2 Vpp */ 1096 .path1_mode = 3, 1097 .tun1_type = 3, 1098 .set_lock_led = dw210x_led_ctrl, 1099 }; 1100 1101 static struct ds3000_config su3000_ds3000_config = { 1102 .demod_address = 0x68, 1103 .ci_mode = 1, 1104 .set_lock_led = dw210x_led_ctrl, 1105 }; 1106 1107 static struct cxd2820r_config cxd2820r_config = { 1108 .i2c_address = 0x6c, /* (0xd8 >> 1) */ 1109 .ts_mode = 0x38, 1110 .ts_clock_inv = 1, 1111 }; 1112 1113 static struct tda18271_config tda18271_config = { 1114 .output_opt = TDA18271_OUTPUT_LT_OFF, 1115 .gate = TDA18271_GATE_DIGITAL, 1116 }; 1117 1118 static u8 m88rs2000_inittab[] = { 1119 DEMOD_WRITE, 0x9a, 0x30, 1120 DEMOD_WRITE, 0x00, 0x01, 1121 WRITE_DELAY, 0x19, 0x00, 1122 DEMOD_WRITE, 0x00, 0x00, 1123 DEMOD_WRITE, 0x9a, 0xb0, 1124 DEMOD_WRITE, 0x81, 0xc1, 1125 DEMOD_WRITE, 0x81, 0x81, 1126 DEMOD_WRITE, 0x86, 0xc6, 1127 DEMOD_WRITE, 0x9a, 0x30, 1128 DEMOD_WRITE, 0xf0, 0x80, 1129 DEMOD_WRITE, 0xf1, 0xbf, 1130 DEMOD_WRITE, 0xb0, 0x45, 1131 DEMOD_WRITE, 0xb2, 0x01, 1132 DEMOD_WRITE, 0x9a, 0xb0, 1133 0xff, 0xaa, 0xff 1134 }; 1135 1136 static struct m88rs2000_config s421_m88rs2000_config = { 1137 .demod_addr = 0x68, 1138 .inittab = m88rs2000_inittab, 1139 }; 1140 1141 static int dw2104_frontend_attach(struct dvb_usb_adapter *d) 1142 { 1143 struct dvb_tuner_ops *tuner_ops = NULL; 1144 1145 if (demod_probe & 4) { 1146 d->fe_adap[0].fe = dvb_attach(stv0900_attach, &dw2104a_stv0900_config, 1147 &d->dev->i2c_adap, 0); 1148 if (d->fe_adap[0].fe != NULL) { 1149 if (dvb_attach(stb6100_attach, d->fe_adap[0].fe, 1150 &dw2104a_stb6100_config, 1151 &d->dev->i2c_adap)) { 1152 tuner_ops = &d->fe_adap[0].fe->ops.tuner_ops; 1153 tuner_ops->set_frequency = stb6100_set_freq; 1154 tuner_ops->get_frequency = stb6100_get_freq; 1155 tuner_ops->set_bandwidth = stb6100_set_bandw; 1156 tuner_ops->get_bandwidth = stb6100_get_bandw; 1157 d->fe_adap[0].fe->ops.set_voltage = dw210x_set_voltage; 1158 info("Attached STV0900+STB6100!\n"); 1159 return 0; 1160 } 1161 } 1162 } 1163 1164 if (demod_probe & 2) { 1165 d->fe_adap[0].fe = dvb_attach(stv0900_attach, &dw2104_stv0900_config, 1166 &d->dev->i2c_adap, 0); 1167 if (d->fe_adap[0].fe != NULL) { 1168 if (dvb_attach(stv6110_attach, d->fe_adap[0].fe, 1169 &dw2104_stv6110_config, 1170 &d->dev->i2c_adap)) { 1171 d->fe_adap[0].fe->ops.set_voltage = dw210x_set_voltage; 1172 info("Attached STV0900+STV6110A!\n"); 1173 return 0; 1174 } 1175 } 1176 } 1177 1178 if (demod_probe & 1) { 1179 d->fe_adap[0].fe = dvb_attach(cx24116_attach, &dw2104_config, 1180 &d->dev->i2c_adap); 1181 if (d->fe_adap[0].fe != NULL) { 1182 d->fe_adap[0].fe->ops.set_voltage = dw210x_set_voltage; 1183 info("Attached cx24116!\n"); 1184 return 0; 1185 } 1186 } 1187 1188 d->fe_adap[0].fe = dvb_attach(ds3000_attach, &dw2104_ds3000_config, 1189 &d->dev->i2c_adap); 1190 if (d->fe_adap[0].fe != NULL) { 1191 dvb_attach(ts2020_attach, d->fe_adap[0].fe, 1192 &dw2104_ts2020_config, &d->dev->i2c_adap); 1193 d->fe_adap[0].fe->ops.set_voltage = dw210x_set_voltage; 1194 info("Attached DS3000!\n"); 1195 return 0; 1196 } 1197 1198 return -EIO; 1199 } 1200 1201 static struct dvb_usb_device_properties dw2102_properties; 1202 static struct dvb_usb_device_properties dw2104_properties; 1203 static struct dvb_usb_device_properties s6x0_properties; 1204 1205 static int dw2102_frontend_attach(struct dvb_usb_adapter *d) 1206 { 1207 if (dw2102_properties.i2c_algo == &dw2102_serit_i2c_algo) { 1208 /*dw2102_properties.adapter->tuner_attach = NULL;*/ 1209 d->fe_adap[0].fe = dvb_attach(si21xx_attach, &serit_sp1511lhb_config, 1210 &d->dev->i2c_adap); 1211 if (d->fe_adap[0].fe != NULL) { 1212 d->fe_adap[0].fe->ops.set_voltage = dw210x_set_voltage; 1213 info("Attached si21xx!\n"); 1214 return 0; 1215 } 1216 } 1217 1218 if (dw2102_properties.i2c_algo == &dw2102_earda_i2c_algo) { 1219 d->fe_adap[0].fe = dvb_attach(stv0288_attach, &earda_config, 1220 &d->dev->i2c_adap); 1221 if (d->fe_adap[0].fe != NULL) { 1222 if (dvb_attach(stb6000_attach, d->fe_adap[0].fe, 0x61, 1223 &d->dev->i2c_adap)) { 1224 d->fe_adap[0].fe->ops.set_voltage = dw210x_set_voltage; 1225 info("Attached stv0288!\n"); 1226 return 0; 1227 } 1228 } 1229 } 1230 1231 if (dw2102_properties.i2c_algo == &dw2102_i2c_algo) { 1232 /*dw2102_properties.adapter->tuner_attach = dw2102_tuner_attach;*/ 1233 d->fe_adap[0].fe = dvb_attach(stv0299_attach, &sharp_z0194a_config, 1234 &d->dev->i2c_adap); 1235 if (d->fe_adap[0].fe != NULL) { 1236 d->fe_adap[0].fe->ops.set_voltage = dw210x_set_voltage; 1237 info("Attached stv0299!\n"); 1238 return 0; 1239 } 1240 } 1241 return -EIO; 1242 } 1243 1244 static int dw3101_frontend_attach(struct dvb_usb_adapter *d) 1245 { 1246 d->fe_adap[0].fe = dvb_attach(tda10023_attach, &dw3101_tda10023_config, 1247 &d->dev->i2c_adap, 0x48); 1248 if (d->fe_adap[0].fe != NULL) { 1249 info("Attached tda10023!\n"); 1250 return 0; 1251 } 1252 return -EIO; 1253 } 1254 1255 static int zl100313_frontend_attach(struct dvb_usb_adapter *d) 1256 { 1257 d->fe_adap[0].fe = dvb_attach(mt312_attach, &zl313_config, 1258 &d->dev->i2c_adap); 1259 if (d->fe_adap[0].fe != NULL) { 1260 if (dvb_attach(zl10039_attach, d->fe_adap[0].fe, 0x60, 1261 &d->dev->i2c_adap)) { 1262 d->fe_adap[0].fe->ops.set_voltage = dw210x_set_voltage; 1263 info("Attached zl100313+zl10039!\n"); 1264 return 0; 1265 } 1266 } 1267 1268 return -EIO; 1269 } 1270 1271 static int stv0288_frontend_attach(struct dvb_usb_adapter *d) 1272 { 1273 u8 obuf[] = {7, 1}; 1274 1275 d->fe_adap[0].fe = dvb_attach(stv0288_attach, &earda_config, 1276 &d->dev->i2c_adap); 1277 1278 if (d->fe_adap[0].fe == NULL) 1279 return -EIO; 1280 1281 if (NULL == dvb_attach(stb6000_attach, d->fe_adap[0].fe, 0x61, &d->dev->i2c_adap)) 1282 return -EIO; 1283 1284 d->fe_adap[0].fe->ops.set_voltage = dw210x_set_voltage; 1285 1286 dw210x_op_rw(d->dev->udev, 0x8a, 0, 0, obuf, 2, DW210X_WRITE_MSG); 1287 1288 info("Attached stv0288+stb6000!\n"); 1289 1290 return 0; 1291 1292 } 1293 1294 static int ds3000_frontend_attach(struct dvb_usb_adapter *d) 1295 { 1296 struct dw2102_state *st = d->dev->priv; 1297 u8 obuf[] = {7, 1}; 1298 1299 d->fe_adap[0].fe = dvb_attach(ds3000_attach, &s660_ds3000_config, 1300 &d->dev->i2c_adap); 1301 1302 if (d->fe_adap[0].fe == NULL) 1303 return -EIO; 1304 1305 dvb_attach(ts2020_attach, d->fe_adap[0].fe, &s660_ts2020_config, 1306 &d->dev->i2c_adap); 1307 1308 st->old_set_voltage = d->fe_adap[0].fe->ops.set_voltage; 1309 d->fe_adap[0].fe->ops.set_voltage = s660_set_voltage; 1310 1311 dw210x_op_rw(d->dev->udev, 0x8a, 0, 0, obuf, 2, DW210X_WRITE_MSG); 1312 1313 info("Attached ds3000+ts2020!\n"); 1314 1315 return 0; 1316 } 1317 1318 static int prof_7500_frontend_attach(struct dvb_usb_adapter *d) 1319 { 1320 u8 obuf[] = {7, 1}; 1321 1322 d->fe_adap[0].fe = dvb_attach(stv0900_attach, &prof_7500_stv0900_config, 1323 &d->dev->i2c_adap, 0); 1324 if (d->fe_adap[0].fe == NULL) 1325 return -EIO; 1326 1327 d->fe_adap[0].fe->ops.set_voltage = dw210x_set_voltage; 1328 1329 dw210x_op_rw(d->dev->udev, 0x8a, 0, 0, obuf, 2, DW210X_WRITE_MSG); 1330 1331 info("Attached STV0900+STB6100A!\n"); 1332 1333 return 0; 1334 } 1335 1336 static int su3000_frontend_attach(struct dvb_usb_adapter *d) 1337 { 1338 u8 obuf[3] = { 0xe, 0x80, 0 }; 1339 u8 ibuf[] = { 0 }; 1340 1341 if (dvb_usb_generic_rw(d->dev, obuf, 3, ibuf, 1, 0) < 0) 1342 err("command 0x0e transfer failed."); 1343 1344 obuf[0] = 0xe; 1345 obuf[1] = 0x02; 1346 obuf[2] = 1; 1347 1348 if (dvb_usb_generic_rw(d->dev, obuf, 3, ibuf, 1, 0) < 0) 1349 err("command 0x0e transfer failed."); 1350 msleep(300); 1351 1352 obuf[0] = 0xe; 1353 obuf[1] = 0x83; 1354 obuf[2] = 0; 1355 1356 if (dvb_usb_generic_rw(d->dev, obuf, 3, ibuf, 1, 0) < 0) 1357 err("command 0x0e transfer failed."); 1358 1359 obuf[0] = 0xe; 1360 obuf[1] = 0x83; 1361 obuf[2] = 1; 1362 1363 if (dvb_usb_generic_rw(d->dev, obuf, 3, ibuf, 1, 0) < 0) 1364 err("command 0x0e transfer failed."); 1365 1366 obuf[0] = 0x51; 1367 1368 if (dvb_usb_generic_rw(d->dev, obuf, 1, ibuf, 1, 0) < 0) 1369 err("command 0x51 transfer failed."); 1370 1371 d->fe_adap[0].fe = dvb_attach(ds3000_attach, &su3000_ds3000_config, 1372 &d->dev->i2c_adap); 1373 if (d->fe_adap[0].fe == NULL) 1374 return -EIO; 1375 1376 if (dvb_attach(ts2020_attach, d->fe_adap[0].fe, 1377 &dw2104_ts2020_config, 1378 &d->dev->i2c_adap)) { 1379 info("Attached DS3000/TS2020!\n"); 1380 return 0; 1381 } 1382 1383 info("Failed to attach DS3000/TS2020!\n"); 1384 return -EIO; 1385 } 1386 1387 static int t220_frontend_attach(struct dvb_usb_adapter *d) 1388 { 1389 u8 obuf[3] = { 0xe, 0x87, 0 }; 1390 u8 ibuf[] = { 0 }; 1391 1392 if (dvb_usb_generic_rw(d->dev, obuf, 3, ibuf, 1, 0) < 0) 1393 err("command 0x0e transfer failed."); 1394 1395 obuf[0] = 0xe; 1396 obuf[1] = 0x86; 1397 obuf[2] = 1; 1398 1399 if (dvb_usb_generic_rw(d->dev, obuf, 3, ibuf, 1, 0) < 0) 1400 err("command 0x0e transfer failed."); 1401 1402 obuf[0] = 0xe; 1403 obuf[1] = 0x80; 1404 obuf[2] = 0; 1405 1406 if (dvb_usb_generic_rw(d->dev, obuf, 3, ibuf, 1, 0) < 0) 1407 err("command 0x0e transfer failed."); 1408 1409 msleep(50); 1410 1411 obuf[0] = 0xe; 1412 obuf[1] = 0x80; 1413 obuf[2] = 1; 1414 1415 if (dvb_usb_generic_rw(d->dev, obuf, 3, ibuf, 1, 0) < 0) 1416 err("command 0x0e transfer failed."); 1417 1418 obuf[0] = 0x51; 1419 1420 if (dvb_usb_generic_rw(d->dev, obuf, 1, ibuf, 1, 0) < 0) 1421 err("command 0x51 transfer failed."); 1422 1423 d->fe_adap[0].fe = dvb_attach(cxd2820r_attach, &cxd2820r_config, 1424 &d->dev->i2c_adap, NULL); 1425 if (d->fe_adap[0].fe != NULL) { 1426 if (dvb_attach(tda18271_attach, d->fe_adap[0].fe, 0x60, 1427 &d->dev->i2c_adap, &tda18271_config)) { 1428 info("Attached TDA18271HD/CXD2820R!\n"); 1429 return 0; 1430 } 1431 } 1432 1433 info("Failed to attach TDA18271HD/CXD2820R!\n"); 1434 return -EIO; 1435 } 1436 1437 static int m88rs2000_frontend_attach(struct dvb_usb_adapter *d) 1438 { 1439 u8 obuf[] = { 0x51 }; 1440 u8 ibuf[] = { 0 }; 1441 1442 if (dvb_usb_generic_rw(d->dev, obuf, 1, ibuf, 1, 0) < 0) 1443 err("command 0x51 transfer failed."); 1444 1445 d->fe_adap[0].fe = dvb_attach(m88rs2000_attach, &s421_m88rs2000_config, 1446 &d->dev->i2c_adap); 1447 1448 if (d->fe_adap[0].fe == NULL) 1449 return -EIO; 1450 1451 if (dvb_attach(ts2020_attach, d->fe_adap[0].fe, 1452 &dw2104_ts2020_config, 1453 &d->dev->i2c_adap)) { 1454 info("Attached RS2000/TS2020!\n"); 1455 return 0; 1456 } 1457 1458 info("Failed to attach RS2000/TS2020!\n"); 1459 return -EIO; 1460 } 1461 1462 static int dw2102_tuner_attach(struct dvb_usb_adapter *adap) 1463 { 1464 dvb_attach(dvb_pll_attach, adap->fe_adap[0].fe, 0x60, 1465 &adap->dev->i2c_adap, DVB_PLL_OPERA1); 1466 return 0; 1467 } 1468 1469 static int dw3101_tuner_attach(struct dvb_usb_adapter *adap) 1470 { 1471 dvb_attach(dvb_pll_attach, adap->fe_adap[0].fe, 0x60, 1472 &adap->dev->i2c_adap, DVB_PLL_TUA6034); 1473 1474 return 0; 1475 } 1476 1477 static int dw2102_rc_query(struct dvb_usb_device *d) 1478 { 1479 u8 key[2]; 1480 struct i2c_msg msg = { 1481 .addr = DW2102_RC_QUERY, 1482 .flags = I2C_M_RD, 1483 .buf = key, 1484 .len = 2 1485 }; 1486 1487 if (d->props.i2c_algo->master_xfer(&d->i2c_adap, &msg, 1) == 1) { 1488 if (msg.buf[0] != 0xff) { 1489 deb_rc("%s: rc code: %x, %x\n", 1490 __func__, key[0], key[1]); 1491 rc_keydown(d->rc_dev, RC_TYPE_UNKNOWN, key[0], 0); 1492 } 1493 } 1494 1495 return 0; 1496 } 1497 1498 static int prof_rc_query(struct dvb_usb_device *d) 1499 { 1500 u8 key[2]; 1501 struct i2c_msg msg = { 1502 .addr = DW2102_RC_QUERY, 1503 .flags = I2C_M_RD, 1504 .buf = key, 1505 .len = 2 1506 }; 1507 1508 if (d->props.i2c_algo->master_xfer(&d->i2c_adap, &msg, 1) == 1) { 1509 if (msg.buf[0] != 0xff) { 1510 deb_rc("%s: rc code: %x, %x\n", 1511 __func__, key[0], key[1]); 1512 rc_keydown(d->rc_dev, RC_TYPE_UNKNOWN, key[0]^0xff, 0); 1513 } 1514 } 1515 1516 return 0; 1517 } 1518 1519 static int su3000_rc_query(struct dvb_usb_device *d) 1520 { 1521 u8 key[2]; 1522 struct i2c_msg msg = { 1523 .addr = DW2102_RC_QUERY, 1524 .flags = I2C_M_RD, 1525 .buf = key, 1526 .len = 2 1527 }; 1528 1529 if (d->props.i2c_algo->master_xfer(&d->i2c_adap, &msg, 1) == 1) { 1530 if (msg.buf[0] != 0xff) { 1531 deb_rc("%s: rc code: %x, %x\n", 1532 __func__, key[0], key[1]); 1533 rc_keydown(d->rc_dev, RC_TYPE_RC5, 1534 RC_SCANCODE_RC5(key[1], key[0]), 0); 1535 } 1536 } 1537 1538 return 0; 1539 } 1540 1541 enum dw2102_table_entry { 1542 CYPRESS_DW2102, 1543 CYPRESS_DW2101, 1544 CYPRESS_DW2104, 1545 TEVII_S650, 1546 TERRATEC_CINERGY_S, 1547 CYPRESS_DW3101, 1548 TEVII_S630, 1549 PROF_1100, 1550 TEVII_S660, 1551 PROF_7500, 1552 GENIATECH_SU3000, 1553 TERRATEC_CINERGY_S2, 1554 TEVII_S480_1, 1555 TEVII_S480_2, 1556 X3M_SPC1400HD, 1557 TEVII_S421, 1558 TEVII_S632, 1559 TERRATEC_CINERGY_S2_R2, 1560 GOTVIEW_SAT_HD, 1561 GENIATECH_T220, 1562 }; 1563 1564 static struct usb_device_id dw2102_table[] = { 1565 [CYPRESS_DW2102] = {USB_DEVICE(USB_VID_CYPRESS, USB_PID_DW2102)}, 1566 [CYPRESS_DW2101] = {USB_DEVICE(USB_VID_CYPRESS, 0x2101)}, 1567 [CYPRESS_DW2104] = {USB_DEVICE(USB_VID_CYPRESS, USB_PID_DW2104)}, 1568 [TEVII_S650] = {USB_DEVICE(0x9022, USB_PID_TEVII_S650)}, 1569 [TERRATEC_CINERGY_S] = {USB_DEVICE(USB_VID_TERRATEC, USB_PID_CINERGY_S)}, 1570 [CYPRESS_DW3101] = {USB_DEVICE(USB_VID_CYPRESS, USB_PID_DW3101)}, 1571 [TEVII_S630] = {USB_DEVICE(0x9022, USB_PID_TEVII_S630)}, 1572 [PROF_1100] = {USB_DEVICE(0x3011, USB_PID_PROF_1100)}, 1573 [TEVII_S660] = {USB_DEVICE(0x9022, USB_PID_TEVII_S660)}, 1574 [PROF_7500] = {USB_DEVICE(0x3034, 0x7500)}, 1575 [GENIATECH_SU3000] = {USB_DEVICE(0x1f4d, 0x3000)}, 1576 [TERRATEC_CINERGY_S2] = {USB_DEVICE(USB_VID_TERRATEC, 0x00a8)}, 1577 [TEVII_S480_1] = {USB_DEVICE(0x9022, USB_PID_TEVII_S480_1)}, 1578 [TEVII_S480_2] = {USB_DEVICE(0x9022, USB_PID_TEVII_S480_2)}, 1579 [X3M_SPC1400HD] = {USB_DEVICE(0x1f4d, 0x3100)}, 1580 [TEVII_S421] = {USB_DEVICE(0x9022, USB_PID_TEVII_S421)}, 1581 [TEVII_S632] = {USB_DEVICE(0x9022, USB_PID_TEVII_S632)}, 1582 [TERRATEC_CINERGY_S2_R2] = {USB_DEVICE(USB_VID_TERRATEC, 0x00b0)}, 1583 [GOTVIEW_SAT_HD] = {USB_DEVICE(0x1FE1, USB_PID_GOTVIEW_SAT_HD)}, 1584 [GENIATECH_T220] = {USB_DEVICE(0x1f4d, 0xD220)}, 1585 { } 1586 }; 1587 1588 MODULE_DEVICE_TABLE(usb, dw2102_table); 1589 1590 static int dw2102_load_firmware(struct usb_device *dev, 1591 const struct firmware *frmwr) 1592 { 1593 u8 *b, *p; 1594 int ret = 0, i; 1595 u8 reset; 1596 u8 reset16[] = {0, 0, 0, 0, 0, 0, 0}; 1597 const struct firmware *fw; 1598 1599 switch (le16_to_cpu(dev->descriptor.idProduct)) { 1600 case 0x2101: 1601 ret = request_firmware(&fw, DW2101_FIRMWARE, &dev->dev); 1602 if (ret != 0) { 1603 err(err_str, DW2101_FIRMWARE); 1604 return ret; 1605 } 1606 break; 1607 default: 1608 fw = frmwr; 1609 break; 1610 } 1611 info("start downloading DW210X firmware"); 1612 p = kmalloc(fw->size, GFP_KERNEL); 1613 reset = 1; 1614 /*stop the CPU*/ 1615 dw210x_op_rw(dev, 0xa0, 0x7f92, 0, &reset, 1, DW210X_WRITE_MSG); 1616 dw210x_op_rw(dev, 0xa0, 0xe600, 0, &reset, 1, DW210X_WRITE_MSG); 1617 1618 if (p != NULL) { 1619 memcpy(p, fw->data, fw->size); 1620 for (i = 0; i < fw->size; i += 0x40) { 1621 b = (u8 *) p + i; 1622 if (dw210x_op_rw(dev, 0xa0, i, 0, b , 0x40, 1623 DW210X_WRITE_MSG) != 0x40) { 1624 err("error while transferring firmware"); 1625 ret = -EINVAL; 1626 break; 1627 } 1628 } 1629 /* restart the CPU */ 1630 reset = 0; 1631 if (ret || dw210x_op_rw(dev, 0xa0, 0x7f92, 0, &reset, 1, 1632 DW210X_WRITE_MSG) != 1) { 1633 err("could not restart the USB controller CPU."); 1634 ret = -EINVAL; 1635 } 1636 if (ret || dw210x_op_rw(dev, 0xa0, 0xe600, 0, &reset, 1, 1637 DW210X_WRITE_MSG) != 1) { 1638 err("could not restart the USB controller CPU."); 1639 ret = -EINVAL; 1640 } 1641 /* init registers */ 1642 switch (le16_to_cpu(dev->descriptor.idProduct)) { 1643 case USB_PID_TEVII_S650: 1644 dw2104_properties.rc.core.rc_codes = RC_MAP_TEVII_NEC; 1645 case USB_PID_DW2104: 1646 reset = 1; 1647 dw210x_op_rw(dev, 0xc4, 0x0000, 0, &reset, 1, 1648 DW210X_WRITE_MSG); 1649 /* break omitted intentionally */ 1650 case USB_PID_DW3101: 1651 reset = 0; 1652 dw210x_op_rw(dev, 0xbf, 0x0040, 0, &reset, 0, 1653 DW210X_WRITE_MSG); 1654 break; 1655 case USB_PID_CINERGY_S: 1656 case USB_PID_DW2102: 1657 dw210x_op_rw(dev, 0xbf, 0x0040, 0, &reset, 0, 1658 DW210X_WRITE_MSG); 1659 dw210x_op_rw(dev, 0xb9, 0x0000, 0, &reset16[0], 2, 1660 DW210X_READ_MSG); 1661 /* check STV0299 frontend */ 1662 dw210x_op_rw(dev, 0xb5, 0, 0, &reset16[0], 2, 1663 DW210X_READ_MSG); 1664 if ((reset16[0] == 0xa1) || (reset16[0] == 0x80)) { 1665 dw2102_properties.i2c_algo = &dw2102_i2c_algo; 1666 dw2102_properties.adapter->fe[0].tuner_attach = &dw2102_tuner_attach; 1667 break; 1668 } else { 1669 /* check STV0288 frontend */ 1670 reset16[0] = 0xd0; 1671 reset16[1] = 1; 1672 reset16[2] = 0; 1673 dw210x_op_rw(dev, 0xc2, 0, 0, &reset16[0], 3, 1674 DW210X_WRITE_MSG); 1675 dw210x_op_rw(dev, 0xc3, 0xd1, 0, &reset16[0], 3, 1676 DW210X_READ_MSG); 1677 if (reset16[2] == 0x11) { 1678 dw2102_properties.i2c_algo = &dw2102_earda_i2c_algo; 1679 break; 1680 } 1681 } 1682 case 0x2101: 1683 dw210x_op_rw(dev, 0xbc, 0x0030, 0, &reset16[0], 2, 1684 DW210X_READ_MSG); 1685 dw210x_op_rw(dev, 0xba, 0x0000, 0, &reset16[0], 7, 1686 DW210X_READ_MSG); 1687 dw210x_op_rw(dev, 0xba, 0x0000, 0, &reset16[0], 7, 1688 DW210X_READ_MSG); 1689 dw210x_op_rw(dev, 0xb9, 0x0000, 0, &reset16[0], 2, 1690 DW210X_READ_MSG); 1691 break; 1692 } 1693 1694 msleep(100); 1695 kfree(p); 1696 } 1697 return ret; 1698 } 1699 1700 static struct dvb_usb_device_properties dw2102_properties = { 1701 .caps = DVB_USB_IS_AN_I2C_ADAPTER, 1702 .usb_ctrl = DEVICE_SPECIFIC, 1703 .firmware = DW2102_FIRMWARE, 1704 .no_reconnect = 1, 1705 1706 .i2c_algo = &dw2102_serit_i2c_algo, 1707 1708 .rc.core = { 1709 .rc_interval = 150, 1710 .rc_codes = RC_MAP_DM1105_NEC, 1711 .module_name = "dw2102", 1712 .allowed_protos = RC_BIT_NEC, 1713 .rc_query = dw2102_rc_query, 1714 }, 1715 1716 .generic_bulk_ctrl_endpoint = 0x81, 1717 /* parameter for the MPEG2-data transfer */ 1718 .num_adapters = 1, 1719 .download_firmware = dw2102_load_firmware, 1720 .read_mac_address = dw210x_read_mac_address, 1721 .adapter = { 1722 { 1723 .num_frontends = 1, 1724 .fe = {{ 1725 .frontend_attach = dw2102_frontend_attach, 1726 .stream = { 1727 .type = USB_BULK, 1728 .count = 8, 1729 .endpoint = 0x82, 1730 .u = { 1731 .bulk = { 1732 .buffersize = 4096, 1733 } 1734 } 1735 }, 1736 }}, 1737 } 1738 }, 1739 .num_device_descs = 3, 1740 .devices = { 1741 {"DVBWorld DVB-S 2102 USB2.0", 1742 {&dw2102_table[CYPRESS_DW2102], NULL}, 1743 {NULL}, 1744 }, 1745 {"DVBWorld DVB-S 2101 USB2.0", 1746 {&dw2102_table[CYPRESS_DW2101], NULL}, 1747 {NULL}, 1748 }, 1749 {"TerraTec Cinergy S USB", 1750 {&dw2102_table[TERRATEC_CINERGY_S], NULL}, 1751 {NULL}, 1752 }, 1753 } 1754 }; 1755 1756 static struct dvb_usb_device_properties dw2104_properties = { 1757 .caps = DVB_USB_IS_AN_I2C_ADAPTER, 1758 .usb_ctrl = DEVICE_SPECIFIC, 1759 .firmware = DW2104_FIRMWARE, 1760 .no_reconnect = 1, 1761 1762 .i2c_algo = &dw2104_i2c_algo, 1763 .rc.core = { 1764 .rc_interval = 150, 1765 .rc_codes = RC_MAP_DM1105_NEC, 1766 .module_name = "dw2102", 1767 .allowed_protos = RC_BIT_NEC, 1768 .rc_query = dw2102_rc_query, 1769 }, 1770 1771 .generic_bulk_ctrl_endpoint = 0x81, 1772 /* parameter for the MPEG2-data transfer */ 1773 .num_adapters = 1, 1774 .download_firmware = dw2102_load_firmware, 1775 .read_mac_address = dw210x_read_mac_address, 1776 .adapter = { 1777 { 1778 .num_frontends = 1, 1779 .fe = {{ 1780 .frontend_attach = dw2104_frontend_attach, 1781 .stream = { 1782 .type = USB_BULK, 1783 .count = 8, 1784 .endpoint = 0x82, 1785 .u = { 1786 .bulk = { 1787 .buffersize = 4096, 1788 } 1789 } 1790 }, 1791 }}, 1792 } 1793 }, 1794 .num_device_descs = 2, 1795 .devices = { 1796 { "DVBWorld DW2104 USB2.0", 1797 {&dw2102_table[CYPRESS_DW2104], NULL}, 1798 {NULL}, 1799 }, 1800 { "TeVii S650 USB2.0", 1801 {&dw2102_table[TEVII_S650], NULL}, 1802 {NULL}, 1803 }, 1804 } 1805 }; 1806 1807 static struct dvb_usb_device_properties dw3101_properties = { 1808 .caps = DVB_USB_IS_AN_I2C_ADAPTER, 1809 .usb_ctrl = DEVICE_SPECIFIC, 1810 .firmware = DW3101_FIRMWARE, 1811 .no_reconnect = 1, 1812 1813 .i2c_algo = &dw3101_i2c_algo, 1814 .rc.core = { 1815 .rc_interval = 150, 1816 .rc_codes = RC_MAP_DM1105_NEC, 1817 .module_name = "dw2102", 1818 .allowed_protos = RC_BIT_NEC, 1819 .rc_query = dw2102_rc_query, 1820 }, 1821 1822 .generic_bulk_ctrl_endpoint = 0x81, 1823 /* parameter for the MPEG2-data transfer */ 1824 .num_adapters = 1, 1825 .download_firmware = dw2102_load_firmware, 1826 .read_mac_address = dw210x_read_mac_address, 1827 .adapter = { 1828 { 1829 .num_frontends = 1, 1830 .fe = {{ 1831 .frontend_attach = dw3101_frontend_attach, 1832 .tuner_attach = dw3101_tuner_attach, 1833 .stream = { 1834 .type = USB_BULK, 1835 .count = 8, 1836 .endpoint = 0x82, 1837 .u = { 1838 .bulk = { 1839 .buffersize = 4096, 1840 } 1841 } 1842 }, 1843 }}, 1844 } 1845 }, 1846 .num_device_descs = 1, 1847 .devices = { 1848 { "DVBWorld DVB-C 3101 USB2.0", 1849 {&dw2102_table[CYPRESS_DW3101], NULL}, 1850 {NULL}, 1851 }, 1852 } 1853 }; 1854 1855 static struct dvb_usb_device_properties s6x0_properties = { 1856 .caps = DVB_USB_IS_AN_I2C_ADAPTER, 1857 .usb_ctrl = DEVICE_SPECIFIC, 1858 .size_of_priv = sizeof(struct dw2102_state), 1859 .firmware = S630_FIRMWARE, 1860 .no_reconnect = 1, 1861 1862 .i2c_algo = &s6x0_i2c_algo, 1863 .rc.core = { 1864 .rc_interval = 150, 1865 .rc_codes = RC_MAP_TEVII_NEC, 1866 .module_name = "dw2102", 1867 .allowed_protos = RC_BIT_NEC, 1868 .rc_query = dw2102_rc_query, 1869 }, 1870 1871 .generic_bulk_ctrl_endpoint = 0x81, 1872 .num_adapters = 1, 1873 .download_firmware = dw2102_load_firmware, 1874 .read_mac_address = s6x0_read_mac_address, 1875 .adapter = { 1876 { 1877 .num_frontends = 1, 1878 .fe = {{ 1879 .frontend_attach = zl100313_frontend_attach, 1880 .stream = { 1881 .type = USB_BULK, 1882 .count = 8, 1883 .endpoint = 0x82, 1884 .u = { 1885 .bulk = { 1886 .buffersize = 4096, 1887 } 1888 } 1889 }, 1890 }}, 1891 } 1892 }, 1893 .num_device_descs = 1, 1894 .devices = { 1895 {"TeVii S630 USB", 1896 {&dw2102_table[TEVII_S630], NULL}, 1897 {NULL}, 1898 }, 1899 } 1900 }; 1901 1902 static struct dvb_usb_device_properties *p1100; 1903 static struct dvb_usb_device_description d1100 = { 1904 "Prof 1100 USB ", 1905 {&dw2102_table[PROF_1100], NULL}, 1906 {NULL}, 1907 }; 1908 1909 static struct dvb_usb_device_properties *s660; 1910 static struct dvb_usb_device_description d660 = { 1911 "TeVii S660 USB", 1912 {&dw2102_table[TEVII_S660], NULL}, 1913 {NULL}, 1914 }; 1915 1916 static struct dvb_usb_device_description d480_1 = { 1917 "TeVii S480.1 USB", 1918 {&dw2102_table[TEVII_S480_1], NULL}, 1919 {NULL}, 1920 }; 1921 1922 static struct dvb_usb_device_description d480_2 = { 1923 "TeVii S480.2 USB", 1924 {&dw2102_table[TEVII_S480_2], NULL}, 1925 {NULL}, 1926 }; 1927 1928 static struct dvb_usb_device_properties *p7500; 1929 static struct dvb_usb_device_description d7500 = { 1930 "Prof 7500 USB DVB-S2", 1931 {&dw2102_table[PROF_7500], NULL}, 1932 {NULL}, 1933 }; 1934 1935 static struct dvb_usb_device_properties *s421; 1936 static struct dvb_usb_device_description d421 = { 1937 "TeVii S421 PCI", 1938 {&dw2102_table[TEVII_S421], NULL}, 1939 {NULL}, 1940 }; 1941 1942 static struct dvb_usb_device_description d632 = { 1943 "TeVii S632 USB", 1944 {&dw2102_table[TEVII_S632], NULL}, 1945 {NULL}, 1946 }; 1947 1948 static struct dvb_usb_device_properties su3000_properties = { 1949 .caps = DVB_USB_IS_AN_I2C_ADAPTER, 1950 .usb_ctrl = DEVICE_SPECIFIC, 1951 .size_of_priv = sizeof(struct dw2102_state), 1952 .power_ctrl = su3000_power_ctrl, 1953 .num_adapters = 1, 1954 .identify_state = su3000_identify_state, 1955 .i2c_algo = &su3000_i2c_algo, 1956 1957 .rc.core = { 1958 .rc_interval = 150, 1959 .rc_codes = RC_MAP_SU3000, 1960 .module_name = "dw2102", 1961 .allowed_protos = RC_BIT_RC5, 1962 .rc_query = su3000_rc_query, 1963 }, 1964 1965 .read_mac_address = su3000_read_mac_address, 1966 1967 .generic_bulk_ctrl_endpoint = 0x01, 1968 1969 .adapter = { 1970 { 1971 .num_frontends = 1, 1972 .fe = {{ 1973 .streaming_ctrl = su3000_streaming_ctrl, 1974 .frontend_attach = su3000_frontend_attach, 1975 .stream = { 1976 .type = USB_BULK, 1977 .count = 8, 1978 .endpoint = 0x82, 1979 .u = { 1980 .bulk = { 1981 .buffersize = 4096, 1982 } 1983 } 1984 } 1985 }}, 1986 } 1987 }, 1988 .num_device_descs = 5, 1989 .devices = { 1990 { "SU3000HD DVB-S USB2.0", 1991 { &dw2102_table[GENIATECH_SU3000], NULL }, 1992 { NULL }, 1993 }, 1994 { "Terratec Cinergy S2 USB HD", 1995 { &dw2102_table[TERRATEC_CINERGY_S2], NULL }, 1996 { NULL }, 1997 }, 1998 { "X3M TV SPC1400HD PCI", 1999 { &dw2102_table[X3M_SPC1400HD], NULL }, 2000 { NULL }, 2001 }, 2002 { "Terratec Cinergy S2 USB HD Rev.2", 2003 { &dw2102_table[TERRATEC_CINERGY_S2_R2], NULL }, 2004 { NULL }, 2005 }, 2006 { "GOTVIEW Satellite HD", 2007 { &dw2102_table[GOTVIEW_SAT_HD], NULL }, 2008 { NULL }, 2009 }, 2010 } 2011 }; 2012 2013 static struct dvb_usb_device_properties t220_properties = { 2014 .caps = DVB_USB_IS_AN_I2C_ADAPTER, 2015 .usb_ctrl = DEVICE_SPECIFIC, 2016 .size_of_priv = sizeof(struct dw2102_state), 2017 .power_ctrl = su3000_power_ctrl, 2018 .num_adapters = 1, 2019 .identify_state = su3000_identify_state, 2020 .i2c_algo = &su3000_i2c_algo, 2021 2022 .rc.core = { 2023 .rc_interval = 150, 2024 .rc_codes = RC_MAP_SU3000, 2025 .module_name = "dw2102", 2026 .allowed_protos = RC_BIT_RC5, 2027 .rc_query = su3000_rc_query, 2028 }, 2029 2030 .read_mac_address = su3000_read_mac_address, 2031 2032 .generic_bulk_ctrl_endpoint = 0x01, 2033 2034 .adapter = { 2035 { 2036 .num_frontends = 1, 2037 .fe = { { 2038 .streaming_ctrl = su3000_streaming_ctrl, 2039 .frontend_attach = t220_frontend_attach, 2040 .stream = { 2041 .type = USB_BULK, 2042 .count = 8, 2043 .endpoint = 0x82, 2044 .u = { 2045 .bulk = { 2046 .buffersize = 4096, 2047 } 2048 } 2049 } 2050 } }, 2051 } 2052 }, 2053 .num_device_descs = 1, 2054 .devices = { 2055 { "Geniatech T220 DVB-T/T2 USB2.0", 2056 { &dw2102_table[GENIATECH_T220], NULL }, 2057 { NULL }, 2058 }, 2059 } 2060 }; 2061 2062 static int dw2102_probe(struct usb_interface *intf, 2063 const struct usb_device_id *id) 2064 { 2065 p1100 = kmemdup(&s6x0_properties, 2066 sizeof(struct dvb_usb_device_properties), GFP_KERNEL); 2067 if (!p1100) 2068 return -ENOMEM; 2069 /* copy default structure */ 2070 /* fill only different fields */ 2071 p1100->firmware = P1100_FIRMWARE; 2072 p1100->devices[0] = d1100; 2073 p1100->rc.core.rc_query = prof_rc_query; 2074 p1100->rc.core.rc_codes = RC_MAP_TBS_NEC; 2075 p1100->adapter->fe[0].frontend_attach = stv0288_frontend_attach; 2076 2077 s660 = kmemdup(&s6x0_properties, 2078 sizeof(struct dvb_usb_device_properties), GFP_KERNEL); 2079 if (!s660) { 2080 kfree(p1100); 2081 return -ENOMEM; 2082 } 2083 s660->firmware = S660_FIRMWARE; 2084 s660->num_device_descs = 3; 2085 s660->devices[0] = d660; 2086 s660->devices[1] = d480_1; 2087 s660->devices[2] = d480_2; 2088 s660->adapter->fe[0].frontend_attach = ds3000_frontend_attach; 2089 2090 p7500 = kmemdup(&s6x0_properties, 2091 sizeof(struct dvb_usb_device_properties), GFP_KERNEL); 2092 if (!p7500) { 2093 kfree(p1100); 2094 kfree(s660); 2095 return -ENOMEM; 2096 } 2097 p7500->firmware = P7500_FIRMWARE; 2098 p7500->devices[0] = d7500; 2099 p7500->rc.core.rc_query = prof_rc_query; 2100 p7500->rc.core.rc_codes = RC_MAP_TBS_NEC; 2101 p7500->adapter->fe[0].frontend_attach = prof_7500_frontend_attach; 2102 2103 2104 s421 = kmemdup(&su3000_properties, 2105 sizeof(struct dvb_usb_device_properties), GFP_KERNEL); 2106 if (!s421) { 2107 kfree(p1100); 2108 kfree(s660); 2109 kfree(p7500); 2110 return -ENOMEM; 2111 } 2112 s421->num_device_descs = 2; 2113 s421->devices[0] = d421; 2114 s421->devices[1] = d632; 2115 s421->adapter->fe[0].frontend_attach = m88rs2000_frontend_attach; 2116 2117 if (0 == dvb_usb_device_init(intf, &dw2102_properties, 2118 THIS_MODULE, NULL, adapter_nr) || 2119 0 == dvb_usb_device_init(intf, &dw2104_properties, 2120 THIS_MODULE, NULL, adapter_nr) || 2121 0 == dvb_usb_device_init(intf, &dw3101_properties, 2122 THIS_MODULE, NULL, adapter_nr) || 2123 0 == dvb_usb_device_init(intf, &s6x0_properties, 2124 THIS_MODULE, NULL, adapter_nr) || 2125 0 == dvb_usb_device_init(intf, p1100, 2126 THIS_MODULE, NULL, adapter_nr) || 2127 0 == dvb_usb_device_init(intf, s660, 2128 THIS_MODULE, NULL, adapter_nr) || 2129 0 == dvb_usb_device_init(intf, p7500, 2130 THIS_MODULE, NULL, adapter_nr) || 2131 0 == dvb_usb_device_init(intf, s421, 2132 THIS_MODULE, NULL, adapter_nr) || 2133 0 == dvb_usb_device_init(intf, &su3000_properties, 2134 THIS_MODULE, NULL, adapter_nr) || 2135 0 == dvb_usb_device_init(intf, &t220_properties, 2136 THIS_MODULE, NULL, adapter_nr)) 2137 return 0; 2138 2139 return -ENODEV; 2140 } 2141 2142 static void dw2102_disconnect(struct usb_interface *intf) 2143 { 2144 struct dvb_usb_device *d = usb_get_intfdata(intf); 2145 struct dw2102_state *st = (struct dw2102_state *)d->priv; 2146 struct i2c_client *client; 2147 2148 /* remove I2C client for tuner */ 2149 client = st->i2c_client_tuner; 2150 if (client) { 2151 module_put(client->dev.driver->owner); 2152 i2c_unregister_device(client); 2153 } 2154 2155 dvb_usb_device_exit(intf); 2156 } 2157 2158 static struct usb_driver dw2102_driver = { 2159 .name = "dw2102", 2160 .probe = dw2102_probe, 2161 .disconnect = dw2102_disconnect, 2162 .id_table = dw2102_table, 2163 }; 2164 2165 module_usb_driver(dw2102_driver); 2166 2167 MODULE_AUTHOR("Igor M. Liplianin (c) liplianin@me.by"); 2168 MODULE_DESCRIPTION("Driver for DVBWorld DVB-S 2101, 2102, DVB-S2 2104," 2169 " DVB-C 3101 USB2.0," 2170 " TeVii S600, S630, S650, S660, S480, S421, S632" 2171 " Prof 1100, 7500 USB2.0," 2172 " Geniatech SU3000, T220 devices"); 2173 MODULE_VERSION("0.1"); 2174 MODULE_LICENSE("GPL"); 2175 MODULE_FIRMWARE(DW2101_FIRMWARE); 2176 MODULE_FIRMWARE(DW2102_FIRMWARE); 2177 MODULE_FIRMWARE(DW2104_FIRMWARE); 2178 MODULE_FIRMWARE(DW3101_FIRMWARE); 2179 MODULE_FIRMWARE(S630_FIRMWARE); 2180 MODULE_FIRMWARE(S660_FIRMWARE); 2181 MODULE_FIRMWARE(P1100_FIRMWARE); 2182 MODULE_FIRMWARE(P7500_FIRMWARE); 2183