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