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