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
5 * Geniatech SU3000, T220,
6 * TechnoTrend S2-4600 Cards
7 * Copyright (C) 2008-2012 Igor M. Liplianin (liplianin@me.by)
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.
13 * see Documentation/dvb/README.dvb-usb for more information
31 #include "stb6100_proc.h"
32 #include "m88rs2000.h"
35 #include "m88ds3103.h"
38 /* Max transfer size done by I2C transfer functions */
39 #define MAX_XFER_SIZE 64
41 #ifndef USB_PID_DW2102
42 #define USB_PID_DW2102 0x2102
45 #ifndef USB_PID_DW2104
46 #define USB_PID_DW2104 0x2104
49 #ifndef USB_PID_DW3101
50 #define USB_PID_DW3101 0x3101
53 #ifndef USB_PID_CINERGY_S
54 #define USB_PID_CINERGY_S 0x0064
57 #ifndef USB_PID_TEVII_S630
58 #define USB_PID_TEVII_S630 0xd630
61 #ifndef USB_PID_TEVII_S650
62 #define USB_PID_TEVII_S650 0xd650
65 #ifndef USB_PID_TEVII_S660
66 #define USB_PID_TEVII_S660 0xd660
69 #ifndef USB_PID_TEVII_S480_1
70 #define USB_PID_TEVII_S480_1 0xd481
73 #ifndef USB_PID_TEVII_S480_2
74 #define USB_PID_TEVII_S480_2 0xd482
77 #ifndef USB_PID_PROF_1100
78 #define USB_PID_PROF_1100 0xb012
81 #ifndef USB_PID_TEVII_S421
82 #define USB_PID_TEVII_S421 0xd421
85 #ifndef USB_PID_TEVII_S632
86 #define USB_PID_TEVII_S632 0xd632
89 #ifndef USB_PID_GOTVIEW_SAT_HD
90 #define USB_PID_GOTVIEW_SAT_HD 0x5456
93 #define DW210X_READ_MSG 0
94 #define DW210X_WRITE_MSG 1
96 #define REG_1F_SYMBOLRATE_BYTE0 0x1f
97 #define REG_20_SYMBOLRATE_BYTE1 0x20
98 #define REG_21_SYMBOLRATE_BYTE2 0x21
100 #define DW2102_VOLTAGE_CTRL (0x1800)
101 #define SU3000_STREAM_CTRL (0x1900)
102 #define DW2102_RC_QUERY (0x1a00)
103 #define DW2102_LED_CTRL (0x1b00)
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"
114 #define err_str "did not find the firmware file. (%s) " \
115 "Please see linux/Documentation/dvb/ for more details " \
116 "on firmware-problems."
118 struct dw2102_state {
120 struct i2c_client *i2c_client_tuner;
121 int (*old_set_voltage)(struct dvb_frontend *f, fe_sec_voltage_t v);
125 static int dvb_usb_dw2102_debug;
126 module_param_named(debug, dvb_usb_dw2102_debug, int, 0644);
127 MODULE_PARM_DESC(debug, "set debugging level (1=info 2=xfer 4=rc(or-able))."
128 DVB_USB_DEBUG_STATUS);
131 static int demod_probe = 1;
132 module_param_named(demod, demod_probe, int, 0644);
133 MODULE_PARM_DESC(demod, "demod to probe (1=cx24116 2=stv0903+stv6110 "
134 "4=stv0903+stb6100(or-able)).");
136 DVB_DEFINE_MOD_OPT_ADAPTER_NR(adapter_nr);
138 static int dw210x_op_rw(struct usb_device *dev, u8 request, u16 value,
139 u16 index, u8 * data, u16 len, int flags)
143 unsigned int pipe = (flags == DW210X_READ_MSG) ?
144 usb_rcvctrlpipe(dev, 0) : usb_sndctrlpipe(dev, 0);
145 u8 request_type = (flags == DW210X_READ_MSG) ? USB_DIR_IN : USB_DIR_OUT;
147 u8buf = kmalloc(len, GFP_KERNEL);
152 if (flags == DW210X_WRITE_MSG)
153 memcpy(u8buf, data, len);
154 ret = usb_control_msg(dev, pipe, request, request_type | USB_TYPE_VENDOR,
155 value, index , u8buf, len, 2000);
157 if (flags == DW210X_READ_MSG)
158 memcpy(data, u8buf, len);
165 static int dw2102_i2c_transfer(struct i2c_adapter *adap, struct i2c_msg msg[],
168 struct dvb_usb_device *d = i2c_get_adapdata(adap);
170 u8 buf6[] = {0x2c, 0x05, 0xc0, 0, 0, 0, 0};
175 if (mutex_lock_interruptible(&d->i2c_mutex) < 0)
180 /* read stv0299 register */
181 value = msg[0].buf[0];/* register */
182 for (i = 0; i < msg[1].len; i++) {
183 dw210x_op_rw(d->udev, 0xb5, value + i, 0,
184 buf6, 2, DW210X_READ_MSG);
185 msg[1].buf[i] = buf6[0];
189 switch (msg[0].addr) {
191 /* write to stv0299 register */
193 buf6[1] = msg[0].buf[0];
194 buf6[2] = msg[0].buf[1];
195 dw210x_op_rw(d->udev, 0xb2, 0, 0,
196 buf6, 3, DW210X_WRITE_MSG);
199 if (msg[0].flags == 0) {
200 /* write to tuner pll */
204 buf6[3] = msg[0].buf[0];
205 buf6[4] = msg[0].buf[1];
206 buf6[5] = msg[0].buf[2];
207 buf6[6] = msg[0].buf[3];
208 dw210x_op_rw(d->udev, 0xb2, 0, 0,
209 buf6, 7, DW210X_WRITE_MSG);
211 /* read from tuner */
212 dw210x_op_rw(d->udev, 0xb5, 0, 0,
213 buf6, 1, DW210X_READ_MSG);
214 msg[0].buf[0] = buf6[0];
217 case (DW2102_RC_QUERY):
218 dw210x_op_rw(d->udev, 0xb8, 0, 0,
219 buf6, 2, DW210X_READ_MSG);
220 msg[0].buf[0] = buf6[0];
221 msg[0].buf[1] = buf6[1];
223 case (DW2102_VOLTAGE_CTRL):
225 buf6[1] = msg[0].buf[0];
226 dw210x_op_rw(d->udev, 0xb2, 0, 0,
227 buf6, 2, DW210X_WRITE_MSG);
234 mutex_unlock(&d->i2c_mutex);
238 static int dw2102_serit_i2c_transfer(struct i2c_adapter *adap,
239 struct i2c_msg msg[], int num)
241 struct dvb_usb_device *d = i2c_get_adapdata(adap);
242 u8 buf6[] = {0, 0, 0, 0, 0, 0, 0};
246 if (mutex_lock_interruptible(&d->i2c_mutex) < 0)
251 /* read si2109 register by number */
252 buf6[0] = msg[0].addr << 1;
253 buf6[1] = msg[0].len;
254 buf6[2] = msg[0].buf[0];
255 dw210x_op_rw(d->udev, 0xc2, 0, 0,
256 buf6, msg[0].len + 2, DW210X_WRITE_MSG);
257 /* read si2109 register */
258 dw210x_op_rw(d->udev, 0xc3, 0xd0, 0,
259 buf6, msg[1].len + 2, DW210X_READ_MSG);
260 memcpy(msg[1].buf, buf6 + 2, msg[1].len);
264 switch (msg[0].addr) {
266 /* write to si2109 register */
267 buf6[0] = msg[0].addr << 1;
268 buf6[1] = msg[0].len;
269 memcpy(buf6 + 2, msg[0].buf, msg[0].len);
270 dw210x_op_rw(d->udev, 0xc2, 0, 0, buf6,
271 msg[0].len + 2, DW210X_WRITE_MSG);
273 case(DW2102_RC_QUERY):
274 dw210x_op_rw(d->udev, 0xb8, 0, 0,
275 buf6, 2, DW210X_READ_MSG);
276 msg[0].buf[0] = buf6[0];
277 msg[0].buf[1] = buf6[1];
279 case(DW2102_VOLTAGE_CTRL):
281 buf6[1] = msg[0].buf[0];
282 dw210x_op_rw(d->udev, 0xb2, 0, 0,
283 buf6, 2, DW210X_WRITE_MSG);
289 mutex_unlock(&d->i2c_mutex);
293 static int dw2102_earda_i2c_transfer(struct i2c_adapter *adap, struct i2c_msg msg[], int num)
295 struct dvb_usb_device *d = i2c_get_adapdata(adap);
300 if (mutex_lock_interruptible(&d->i2c_mutex) < 0)
306 /* first write first register number */
307 u8 ibuf[MAX_XFER_SIZE], obuf[3];
309 if (2 + msg[1].len > sizeof(ibuf)) {
310 warn("i2c rd: len=%d is too big!\n",
316 obuf[0] = msg[0].addr << 1;
317 obuf[1] = msg[0].len;
318 obuf[2] = msg[0].buf[0];
319 dw210x_op_rw(d->udev, 0xc2, 0, 0,
320 obuf, msg[0].len + 2, DW210X_WRITE_MSG);
321 /* second read registers */
322 dw210x_op_rw(d->udev, 0xc3, 0xd1 , 0,
323 ibuf, msg[1].len + 2, DW210X_READ_MSG);
324 memcpy(msg[1].buf, ibuf + 2, msg[1].len);
329 switch (msg[0].addr) {
331 /* write to register */
332 u8 obuf[MAX_XFER_SIZE];
334 if (2 + msg[0].len > sizeof(obuf)) {
335 warn("i2c wr: len=%d is too big!\n",
341 obuf[0] = msg[0].addr << 1;
342 obuf[1] = msg[0].len;
343 memcpy(obuf + 2, msg[0].buf, msg[0].len);
344 dw210x_op_rw(d->udev, 0xc2, 0, 0,
345 obuf, msg[0].len + 2, DW210X_WRITE_MSG);
350 u8 obuf[MAX_XFER_SIZE];
352 if (2 + msg[0].len > sizeof(obuf)) {
353 warn("i2c wr: len=%d is too big!\n",
359 obuf[0] = msg[0].addr << 1;
360 obuf[1] = msg[0].len;
361 memcpy(obuf + 2, msg[0].buf, msg[0].len);
362 dw210x_op_rw(d->udev, 0xc2, 0, 0,
363 obuf, msg[0].len + 2, DW210X_WRITE_MSG);
366 case(DW2102_RC_QUERY): {
368 dw210x_op_rw(d->udev, 0xb8, 0, 0,
369 ibuf, 2, DW210X_READ_MSG);
370 memcpy(msg[0].buf, ibuf , 2);
373 case(DW2102_VOLTAGE_CTRL): {
376 obuf[1] = msg[0].buf[0];
377 dw210x_op_rw(d->udev, 0xb2, 0, 0,
378 obuf, 2, DW210X_WRITE_MSG);
388 mutex_unlock(&d->i2c_mutex);
392 static int dw2104_i2c_transfer(struct i2c_adapter *adap, struct i2c_msg msg[], int num)
394 struct dvb_usb_device *d = i2c_get_adapdata(adap);
399 if (mutex_lock_interruptible(&d->i2c_mutex) < 0)
402 for (j = 0; j < num; j++) {
403 switch (msg[j].addr) {
404 case(DW2102_RC_QUERY): {
406 dw210x_op_rw(d->udev, 0xb8, 0, 0,
407 ibuf, 2, DW210X_READ_MSG);
408 memcpy(msg[j].buf, ibuf , 2);
411 case(DW2102_VOLTAGE_CTRL): {
414 obuf[1] = msg[j].buf[0];
415 dw210x_op_rw(d->udev, 0xb2, 0, 0,
416 obuf, 2, DW210X_WRITE_MSG);
421 case 0x68: ds3000, stv0903
422 case 0x60: ts2020, stv6110, stb6100 */
424 if (msg[j].flags == I2C_M_RD) {
426 u8 ibuf[MAX_XFER_SIZE];
428 if (2 + msg[j].len > sizeof(ibuf)) {
429 warn("i2c rd: len=%d is too big!\n",
435 dw210x_op_rw(d->udev, 0xc3,
436 (msg[j].addr << 1) + 1, 0,
437 ibuf, msg[j].len + 2,
439 memcpy(msg[j].buf, ibuf + 2, msg[j].len);
441 } else if (((msg[j].buf[0] == 0xb0) &&
442 (msg[j].addr == 0x68)) ||
443 ((msg[j].buf[0] == 0xf7) &&
444 (msg[j].addr == 0x55))) {
447 obuf[0] = msg[j].addr << 1;
448 obuf[1] = (msg[j].len > 15 ? 17 : msg[j].len);
449 obuf[2] = msg[j].buf[0];
450 len = msg[j].len - 1;
453 memcpy(obuf + 3, msg[j].buf + i,
454 (len > 16 ? 16 : len));
455 dw210x_op_rw(d->udev, 0xc2, 0, 0,
456 obuf, (len > 16 ? 16 : len) + 3,
462 /* write registers */
463 u8 obuf[MAX_XFER_SIZE];
465 if (2 + msg[j].len > sizeof(obuf)) {
466 warn("i2c wr: len=%d is too big!\n",
472 obuf[0] = msg[j].addr << 1;
473 obuf[1] = msg[j].len;
474 memcpy(obuf + 2, msg[j].buf, msg[j].len);
475 dw210x_op_rw(d->udev, 0xc2, 0, 0,
476 obuf, msg[j].len + 2,
487 mutex_unlock(&d->i2c_mutex);
491 static int dw3101_i2c_transfer(struct i2c_adapter *adap, struct i2c_msg msg[],
494 struct dvb_usb_device *d = i2c_get_adapdata(adap);
500 if (mutex_lock_interruptible(&d->i2c_mutex) < 0)
506 /* first write first register number */
507 u8 ibuf[MAX_XFER_SIZE], obuf[3];
509 if (2 + msg[1].len > sizeof(ibuf)) {
510 warn("i2c rd: len=%d is too big!\n",
515 obuf[0] = msg[0].addr << 1;
516 obuf[1] = msg[0].len;
517 obuf[2] = msg[0].buf[0];
518 dw210x_op_rw(d->udev, 0xc2, 0, 0,
519 obuf, msg[0].len + 2, DW210X_WRITE_MSG);
520 /* second read registers */
521 dw210x_op_rw(d->udev, 0xc3, 0x19 , 0,
522 ibuf, msg[1].len + 2, DW210X_READ_MSG);
523 memcpy(msg[1].buf, ibuf + 2, msg[1].len);
528 switch (msg[0].addr) {
531 /* write to register */
532 u8 obuf[MAX_XFER_SIZE];
534 if (2 + msg[0].len > sizeof(obuf)) {
535 warn("i2c wr: len=%d is too big!\n",
540 obuf[0] = msg[0].addr << 1;
541 obuf[1] = msg[0].len;
542 memcpy(obuf + 2, msg[0].buf, msg[0].len);
543 dw210x_op_rw(d->udev, 0xc2, 0, 0,
544 obuf, msg[0].len + 2, DW210X_WRITE_MSG);
547 case(DW2102_RC_QUERY): {
549 dw210x_op_rw(d->udev, 0xb8, 0, 0,
550 ibuf, 2, DW210X_READ_MSG);
551 memcpy(msg[0].buf, ibuf , 2);
559 for (i = 0; i < num; i++) {
560 deb_xfer("%02x:%02x: %s ", i, msg[i].addr,
561 msg[i].flags == 0 ? ">>>" : "<<<");
562 debug_dump(msg[i].buf, msg[i].len, deb_xfer);
567 mutex_unlock(&d->i2c_mutex);
571 static int s6x0_i2c_transfer(struct i2c_adapter *adap, struct i2c_msg msg[],
574 struct dvb_usb_device *d = i2c_get_adapdata(adap);
575 struct usb_device *udev;
581 if (mutex_lock_interruptible(&d->i2c_mutex) < 0)
584 for (j = 0; j < num; j++) {
585 switch (msg[j].addr) {
586 case (DW2102_RC_QUERY): {
588 dw210x_op_rw(d->udev, 0xb8, 0, 0,
589 ibuf, 5, DW210X_READ_MSG);
590 memcpy(msg[j].buf, ibuf + 3, 2);
593 case (DW2102_VOLTAGE_CTRL): {
597 obuf[1] = msg[j].buf[1];/* off-on */
598 dw210x_op_rw(d->udev, 0x8a, 0, 0,
599 obuf, 2, DW210X_WRITE_MSG);
601 obuf[1] = msg[j].buf[0];/* 13v-18v */
602 dw210x_op_rw(d->udev, 0x8a, 0, 0,
603 obuf, 2, DW210X_WRITE_MSG);
606 case (DW2102_LED_CTRL): {
610 obuf[1] = msg[j].buf[0];
611 dw210x_op_rw(d->udev, 0x8a, 0, 0,
612 obuf, 2, DW210X_WRITE_MSG);
617 case 0x68: ds3000, stv0903, rs2000
618 case 0x60: ts2020, stv6110, stb6100
621 if (msg[j].flags == I2C_M_RD) {
623 u8 ibuf[MAX_XFER_SIZE];
625 if (msg[j].len > sizeof(ibuf)) {
626 warn("i2c rd: len=%d is too big!\n",
632 dw210x_op_rw(d->udev, 0x91, 0, 0,
635 memcpy(msg[j].buf, ibuf, msg[j].len);
637 } else if ((msg[j].buf[0] == 0xb0) &&
638 (msg[j].addr == 0x68)) {
641 obuf[0] = (msg[j].len > 16 ?
642 18 : msg[j].len + 1);
643 obuf[1] = msg[j].addr << 1;
644 obuf[2] = msg[j].buf[0];
645 len = msg[j].len - 1;
648 memcpy(obuf + 3, msg[j].buf + i,
649 (len > 16 ? 16 : len));
650 dw210x_op_rw(d->udev, 0x80, 0, 0,
651 obuf, (len > 16 ? 16 : len) + 3,
656 } else if (j < (num - 1)) {
657 /* write register addr before read */
658 u8 obuf[MAX_XFER_SIZE];
660 if (2 + msg[j].len > sizeof(obuf)) {
661 warn("i2c wr: len=%d is too big!\n",
667 obuf[0] = msg[j + 1].len;
668 obuf[1] = (msg[j].addr << 1);
669 memcpy(obuf + 2, msg[j].buf, msg[j].len);
670 dw210x_op_rw(d->udev,
671 le16_to_cpu(udev->descriptor.idProduct) ==
672 0x7500 ? 0x92 : 0x90, 0, 0,
673 obuf, msg[j].len + 2,
677 /* write registers */
678 u8 obuf[MAX_XFER_SIZE];
680 if (2 + msg[j].len > sizeof(obuf)) {
681 warn("i2c wr: len=%d is too big!\n",
686 obuf[0] = msg[j].len + 1;
687 obuf[1] = (msg[j].addr << 1);
688 memcpy(obuf + 2, msg[j].buf, msg[j].len);
689 dw210x_op_rw(d->udev, 0x80, 0, 0,
690 obuf, msg[j].len + 2,
701 mutex_unlock(&d->i2c_mutex);
705 static int su3000_i2c_transfer(struct i2c_adapter *adap, struct i2c_msg msg[],
708 struct dvb_usb_device *d = i2c_get_adapdata(adap);
709 u8 obuf[0x40], ibuf[0x40];
713 if (mutex_lock_interruptible(&d->i2c_mutex) < 0)
718 switch (msg[0].addr) {
719 case SU3000_STREAM_CTRL:
720 obuf[0] = msg[0].buf[0] + 0x36;
723 if (dvb_usb_generic_rw(d, obuf, 3, ibuf, 0, 0) < 0)
724 err("i2c transfer failed.");
726 case DW2102_RC_QUERY:
728 if (dvb_usb_generic_rw(d, obuf, 1, ibuf, 2, 0) < 0)
729 err("i2c transfer failed.");
730 msg[0].buf[1] = ibuf[0];
731 msg[0].buf[0] = ibuf[1];
734 /* always i2c write*/
736 obuf[1] = msg[0].addr;
737 obuf[2] = msg[0].len;
739 memcpy(&obuf[3], msg[0].buf, msg[0].len);
741 if (dvb_usb_generic_rw(d, obuf, msg[0].len + 3,
743 err("i2c transfer failed.");
748 /* always i2c read */
750 obuf[1] = msg[0].len;
751 obuf[2] = msg[1].len;
752 obuf[3] = msg[0].addr;
753 memcpy(&obuf[4], msg[0].buf, msg[0].len);
755 if (dvb_usb_generic_rw(d, obuf, msg[0].len + 4,
756 ibuf, msg[1].len + 1, 0) < 0)
757 err("i2c transfer failed.");
759 memcpy(msg[1].buf, &ibuf[1], msg[1].len);
762 warn("more than 2 i2c messages at a time is not handled yet.");
765 mutex_unlock(&d->i2c_mutex);
769 static u32 dw210x_i2c_func(struct i2c_adapter *adapter)
774 static struct i2c_algorithm dw2102_i2c_algo = {
775 .master_xfer = dw2102_i2c_transfer,
776 .functionality = dw210x_i2c_func,
779 static struct i2c_algorithm dw2102_serit_i2c_algo = {
780 .master_xfer = dw2102_serit_i2c_transfer,
781 .functionality = dw210x_i2c_func,
784 static struct i2c_algorithm dw2102_earda_i2c_algo = {
785 .master_xfer = dw2102_earda_i2c_transfer,
786 .functionality = dw210x_i2c_func,
789 static struct i2c_algorithm dw2104_i2c_algo = {
790 .master_xfer = dw2104_i2c_transfer,
791 .functionality = dw210x_i2c_func,
794 static struct i2c_algorithm dw3101_i2c_algo = {
795 .master_xfer = dw3101_i2c_transfer,
796 .functionality = dw210x_i2c_func,
799 static struct i2c_algorithm s6x0_i2c_algo = {
800 .master_xfer = s6x0_i2c_transfer,
801 .functionality = dw210x_i2c_func,
804 static struct i2c_algorithm su3000_i2c_algo = {
805 .master_xfer = su3000_i2c_transfer,
806 .functionality = dw210x_i2c_func,
809 static int dw210x_read_mac_address(struct dvb_usb_device *d, u8 mac[6])
813 u8 eeprom[256], eepromline[16];
815 for (i = 0; i < 256; i++) {
816 if (dw210x_op_rw(d->udev, 0xb6, 0xa0 , i, ibuf, 2, DW210X_READ_MSG) < 0) {
817 err("read eeprom failed.");
820 eepromline[i%16] = ibuf[0];
823 if ((i % 16) == 15) {
824 deb_xfer("%02x: ", i - 15);
825 debug_dump(eepromline, 16, deb_xfer);
829 memcpy(mac, eeprom + 8, 6);
833 static int s6x0_read_mac_address(struct dvb_usb_device *d, u8 mac[6])
836 u8 ibuf[] = { 0 }, obuf[] = { 0 };
837 u8 eeprom[256], eepromline[16];
838 struct i2c_msg msg[] = {
852 for (i = 0; i < 256; i++) {
854 ret = s6x0_i2c_transfer(&d->i2c_adap, msg, 2);
856 err("read eeprom failed.");
859 eepromline[i % 16] = ibuf[0];
863 if ((i % 16) == 15) {
864 deb_xfer("%02x: ", i - 15);
865 debug_dump(eepromline, 16, deb_xfer);
869 memcpy(mac, eeprom + 16, 6);
873 static int su3000_streaming_ctrl(struct dvb_usb_adapter *adap, int onoff)
875 static u8 command_start[] = {0x00};
876 static u8 command_stop[] = {0x01};
877 struct i2c_msg msg = {
878 .addr = SU3000_STREAM_CTRL,
880 .buf = onoff ? command_start : command_stop,
884 i2c_transfer(&adap->dev->i2c_adap, &msg, 1);
889 static int su3000_power_ctrl(struct dvb_usb_device *d, int i)
891 struct dw2102_state *state = (struct dw2102_state *)d->priv;
892 u8 obuf[] = {0xde, 0};
894 info("%s: %d, initialized %d\n", __func__, i, state->initialized);
896 if (i && !state->initialized) {
897 state->initialized = 1;
899 dvb_usb_generic_rw(d, obuf, 2, NULL, 0, 0);
905 static int su3000_read_mac_address(struct dvb_usb_device *d, u8 mac[6])
908 u8 obuf[] = { 0x1f, 0xf0 };
910 struct i2c_msg msg[] = {
925 for (i = 0; i < 6; i++) {
927 if (i2c_transfer(&d->i2c_adap, msg, 2) != 2)
932 debug_dump(mac, 6, printk);
938 static int su3000_identify_state(struct usb_device *udev,
939 struct dvb_usb_device_properties *props,
940 struct dvb_usb_device_description **desc,
943 info("%s\n", __func__);
949 static int dw210x_set_voltage(struct dvb_frontend *fe, fe_sec_voltage_t voltage)
951 static u8 command_13v[] = {0x00, 0x01};
952 static u8 command_18v[] = {0x01, 0x01};
953 static u8 command_off[] = {0x00, 0x00};
954 struct i2c_msg msg = {
955 .addr = DW2102_VOLTAGE_CTRL,
961 struct dvb_usb_adapter *udev_adap =
962 (struct dvb_usb_adapter *)(fe->dvb->priv);
963 if (voltage == SEC_VOLTAGE_18)
964 msg.buf = command_18v;
965 else if (voltage == SEC_VOLTAGE_13)
966 msg.buf = command_13v;
968 i2c_transfer(&udev_adap->dev->i2c_adap, &msg, 1);
973 static int s660_set_voltage(struct dvb_frontend *fe, fe_sec_voltage_t voltage)
975 struct dvb_usb_adapter *d =
976 (struct dvb_usb_adapter *)(fe->dvb->priv);
977 struct dw2102_state *st = (struct dw2102_state *)d->dev->priv;
979 dw210x_set_voltage(fe, voltage);
980 if (st->old_set_voltage)
981 st->old_set_voltage(fe, voltage);
986 static void dw210x_led_ctrl(struct dvb_frontend *fe, int offon)
988 static u8 led_off[] = { 0 };
989 static u8 led_on[] = { 1 };
990 struct i2c_msg msg = {
991 .addr = DW2102_LED_CTRL,
996 struct dvb_usb_adapter *udev_adap =
997 (struct dvb_usb_adapter *)(fe->dvb->priv);
1001 i2c_transfer(&udev_adap->dev->i2c_adap, &msg, 1);
1004 static struct stv0299_config sharp_z0194a_config = {
1005 .demod_address = 0x68,
1006 .inittab = sharp_z0194a_inittab,
1010 .lock_output = STV0299_LOCKOUTPUT_1,
1011 .volt13_op0_op1 = STV0299_VOLT13_OP1,
1012 .min_delay_ms = 100,
1013 .set_symbol_rate = sharp_z0194a_set_symbol_rate,
1016 static struct cx24116_config dw2104_config = {
1017 .demod_address = 0x55,
1018 .mpg_clk_pos_pol = 0x01,
1021 static struct si21xx_config serit_sp1511lhb_config = {
1022 .demod_address = 0x68,
1023 .min_delay_ms = 100,
1027 static struct tda10023_config dw3101_tda10023_config = {
1028 .demod_address = 0x0c,
1032 static struct mt312_config zl313_config = {
1033 .demod_address = 0x0e,
1036 static struct ds3000_config dw2104_ds3000_config = {
1037 .demod_address = 0x68,
1040 static struct ts2020_config dw2104_ts2020_config = {
1041 .tuner_address = 0x60,
1043 .frequency_div = 1060000,
1046 static struct ds3000_config s660_ds3000_config = {
1047 .demod_address = 0x68,
1049 .set_lock_led = dw210x_led_ctrl,
1052 static struct ts2020_config s660_ts2020_config = {
1053 .tuner_address = 0x60,
1055 .frequency_div = 1146000,
1058 static struct stv0900_config dw2104a_stv0900_config = {
1059 .demod_address = 0x6a,
1062 .clkmode = 3,/* 0-CLKI, 2-XTALI, else AUTO */
1063 .diseqc_mode = 2,/* 2/3 PWM */
1064 .tun1_maddress = 0,/* 0x60 */
1065 .tun1_adc = 0,/* 2 Vpp */
1069 static struct stb6100_config dw2104a_stb6100_config = {
1070 .tuner_address = 0x60,
1071 .refclock = 27000000,
1074 static struct stv0900_config dw2104_stv0900_config = {
1075 .demod_address = 0x68,
1081 .tun1_adc = 1,/* 1 Vpp */
1085 static struct stv6110_config dw2104_stv6110_config = {
1086 .i2c_address = 0x60,
1091 static struct stv0900_config prof_7500_stv0900_config = {
1092 .demod_address = 0x6a,
1095 .clkmode = 3,/* 0-CLKI, 2-XTALI, else AUTO */
1096 .diseqc_mode = 2,/* 2/3 PWM */
1097 .tun1_maddress = 0,/* 0x60 */
1098 .tun1_adc = 0,/* 2 Vpp */
1101 .set_lock_led = dw210x_led_ctrl,
1104 static struct ds3000_config su3000_ds3000_config = {
1105 .demod_address = 0x68,
1107 .set_lock_led = dw210x_led_ctrl,
1110 static struct cxd2820r_config cxd2820r_config = {
1111 .i2c_address = 0x6c, /* (0xd8 >> 1) */
1116 static struct tda18271_config tda18271_config = {
1117 .output_opt = TDA18271_OUTPUT_LT_OFF,
1118 .gate = TDA18271_GATE_DIGITAL,
1121 static const struct m88ds3103_config tt_s2_4600_m88ds3103_config = {
1125 .ts_mode = M88DS3103_TS_CI,
1130 .clock_out = M88DS3103_CLOCK_OUT_ENABLED,
1137 static u8 m88rs2000_inittab[] = {
1138 DEMOD_WRITE, 0x9a, 0x30,
1139 DEMOD_WRITE, 0x00, 0x01,
1140 WRITE_DELAY, 0x19, 0x00,
1141 DEMOD_WRITE, 0x00, 0x00,
1142 DEMOD_WRITE, 0x9a, 0xb0,
1143 DEMOD_WRITE, 0x81, 0xc1,
1144 DEMOD_WRITE, 0x81, 0x81,
1145 DEMOD_WRITE, 0x86, 0xc6,
1146 DEMOD_WRITE, 0x9a, 0x30,
1147 DEMOD_WRITE, 0xf0, 0x80,
1148 DEMOD_WRITE, 0xf1, 0xbf,
1149 DEMOD_WRITE, 0xb0, 0x45,
1150 DEMOD_WRITE, 0xb2, 0x01,
1151 DEMOD_WRITE, 0x9a, 0xb0,
1155 static struct m88rs2000_config s421_m88rs2000_config = {
1157 .inittab = m88rs2000_inittab,
1160 static int dw2104_frontend_attach(struct dvb_usb_adapter *d)
1162 struct dvb_tuner_ops *tuner_ops = NULL;
1164 if (demod_probe & 4) {
1165 d->fe_adap[0].fe = dvb_attach(stv0900_attach, &dw2104a_stv0900_config,
1166 &d->dev->i2c_adap, 0);
1167 if (d->fe_adap[0].fe != NULL) {
1168 if (dvb_attach(stb6100_attach, d->fe_adap[0].fe,
1169 &dw2104a_stb6100_config,
1170 &d->dev->i2c_adap)) {
1171 tuner_ops = &d->fe_adap[0].fe->ops.tuner_ops;
1172 tuner_ops->set_frequency = stb6100_set_freq;
1173 tuner_ops->get_frequency = stb6100_get_freq;
1174 tuner_ops->set_bandwidth = stb6100_set_bandw;
1175 tuner_ops->get_bandwidth = stb6100_get_bandw;
1176 d->fe_adap[0].fe->ops.set_voltage = dw210x_set_voltage;
1177 info("Attached STV0900+STB6100!\n");
1183 if (demod_probe & 2) {
1184 d->fe_adap[0].fe = dvb_attach(stv0900_attach, &dw2104_stv0900_config,
1185 &d->dev->i2c_adap, 0);
1186 if (d->fe_adap[0].fe != NULL) {
1187 if (dvb_attach(stv6110_attach, d->fe_adap[0].fe,
1188 &dw2104_stv6110_config,
1189 &d->dev->i2c_adap)) {
1190 d->fe_adap[0].fe->ops.set_voltage = dw210x_set_voltage;
1191 info("Attached STV0900+STV6110A!\n");
1197 if (demod_probe & 1) {
1198 d->fe_adap[0].fe = dvb_attach(cx24116_attach, &dw2104_config,
1200 if (d->fe_adap[0].fe != NULL) {
1201 d->fe_adap[0].fe->ops.set_voltage = dw210x_set_voltage;
1202 info("Attached cx24116!\n");
1207 d->fe_adap[0].fe = dvb_attach(ds3000_attach, &dw2104_ds3000_config,
1209 if (d->fe_adap[0].fe != NULL) {
1210 dvb_attach(ts2020_attach, d->fe_adap[0].fe,
1211 &dw2104_ts2020_config, &d->dev->i2c_adap);
1212 d->fe_adap[0].fe->ops.set_voltage = dw210x_set_voltage;
1213 info("Attached DS3000!\n");
1220 static struct dvb_usb_device_properties dw2102_properties;
1221 static struct dvb_usb_device_properties dw2104_properties;
1222 static struct dvb_usb_device_properties s6x0_properties;
1224 static int dw2102_frontend_attach(struct dvb_usb_adapter *d)
1226 if (dw2102_properties.i2c_algo == &dw2102_serit_i2c_algo) {
1227 /*dw2102_properties.adapter->tuner_attach = NULL;*/
1228 d->fe_adap[0].fe = dvb_attach(si21xx_attach, &serit_sp1511lhb_config,
1230 if (d->fe_adap[0].fe != NULL) {
1231 d->fe_adap[0].fe->ops.set_voltage = dw210x_set_voltage;
1232 info("Attached si21xx!\n");
1237 if (dw2102_properties.i2c_algo == &dw2102_earda_i2c_algo) {
1238 d->fe_adap[0].fe = dvb_attach(stv0288_attach, &earda_config,
1240 if (d->fe_adap[0].fe != NULL) {
1241 if (dvb_attach(stb6000_attach, d->fe_adap[0].fe, 0x61,
1242 &d->dev->i2c_adap)) {
1243 d->fe_adap[0].fe->ops.set_voltage = dw210x_set_voltage;
1244 info("Attached stv0288!\n");
1250 if (dw2102_properties.i2c_algo == &dw2102_i2c_algo) {
1251 /*dw2102_properties.adapter->tuner_attach = dw2102_tuner_attach;*/
1252 d->fe_adap[0].fe = dvb_attach(stv0299_attach, &sharp_z0194a_config,
1254 if (d->fe_adap[0].fe != NULL) {
1255 d->fe_adap[0].fe->ops.set_voltage = dw210x_set_voltage;
1256 info("Attached stv0299!\n");
1263 static int dw3101_frontend_attach(struct dvb_usb_adapter *d)
1265 d->fe_adap[0].fe = dvb_attach(tda10023_attach, &dw3101_tda10023_config,
1266 &d->dev->i2c_adap, 0x48);
1267 if (d->fe_adap[0].fe != NULL) {
1268 info("Attached tda10023!\n");
1274 static int zl100313_frontend_attach(struct dvb_usb_adapter *d)
1276 d->fe_adap[0].fe = dvb_attach(mt312_attach, &zl313_config,
1278 if (d->fe_adap[0].fe != NULL) {
1279 if (dvb_attach(zl10039_attach, d->fe_adap[0].fe, 0x60,
1280 &d->dev->i2c_adap)) {
1281 d->fe_adap[0].fe->ops.set_voltage = dw210x_set_voltage;
1282 info("Attached zl100313+zl10039!\n");
1290 static int stv0288_frontend_attach(struct dvb_usb_adapter *d)
1294 d->fe_adap[0].fe = dvb_attach(stv0288_attach, &earda_config,
1297 if (d->fe_adap[0].fe == NULL)
1300 if (NULL == dvb_attach(stb6000_attach, d->fe_adap[0].fe, 0x61, &d->dev->i2c_adap))
1303 d->fe_adap[0].fe->ops.set_voltage = dw210x_set_voltage;
1305 dw210x_op_rw(d->dev->udev, 0x8a, 0, 0, obuf, 2, DW210X_WRITE_MSG);
1307 info("Attached stv0288+stb6000!\n");
1313 static int ds3000_frontend_attach(struct dvb_usb_adapter *d)
1315 struct dw2102_state *st = d->dev->priv;
1318 d->fe_adap[0].fe = dvb_attach(ds3000_attach, &s660_ds3000_config,
1321 if (d->fe_adap[0].fe == NULL)
1324 dvb_attach(ts2020_attach, d->fe_adap[0].fe, &s660_ts2020_config,
1327 st->old_set_voltage = d->fe_adap[0].fe->ops.set_voltage;
1328 d->fe_adap[0].fe->ops.set_voltage = s660_set_voltage;
1330 dw210x_op_rw(d->dev->udev, 0x8a, 0, 0, obuf, 2, DW210X_WRITE_MSG);
1332 info("Attached ds3000+ts2020!\n");
1337 static int prof_7500_frontend_attach(struct dvb_usb_adapter *d)
1341 d->fe_adap[0].fe = dvb_attach(stv0900_attach, &prof_7500_stv0900_config,
1342 &d->dev->i2c_adap, 0);
1343 if (d->fe_adap[0].fe == NULL)
1346 d->fe_adap[0].fe->ops.set_voltage = dw210x_set_voltage;
1348 dw210x_op_rw(d->dev->udev, 0x8a, 0, 0, obuf, 2, DW210X_WRITE_MSG);
1350 info("Attached STV0900+STB6100A!\n");
1355 static int su3000_frontend_attach(struct dvb_usb_adapter *d)
1357 u8 obuf[3] = { 0xe, 0x80, 0 };
1360 if (dvb_usb_generic_rw(d->dev, obuf, 3, ibuf, 1, 0) < 0)
1361 err("command 0x0e transfer failed.");
1367 if (dvb_usb_generic_rw(d->dev, obuf, 3, ibuf, 1, 0) < 0)
1368 err("command 0x0e transfer failed.");
1375 if (dvb_usb_generic_rw(d->dev, obuf, 3, ibuf, 1, 0) < 0)
1376 err("command 0x0e transfer failed.");
1382 if (dvb_usb_generic_rw(d->dev, obuf, 3, ibuf, 1, 0) < 0)
1383 err("command 0x0e transfer failed.");
1387 if (dvb_usb_generic_rw(d->dev, obuf, 1, ibuf, 1, 0) < 0)
1388 err("command 0x51 transfer failed.");
1390 d->fe_adap[0].fe = dvb_attach(ds3000_attach, &su3000_ds3000_config,
1392 if (d->fe_adap[0].fe == NULL)
1395 if (dvb_attach(ts2020_attach, d->fe_adap[0].fe,
1396 &dw2104_ts2020_config,
1397 &d->dev->i2c_adap)) {
1398 info("Attached DS3000/TS2020!\n");
1402 info("Failed to attach DS3000/TS2020!\n");
1406 static int t220_frontend_attach(struct dvb_usb_adapter *d)
1408 u8 obuf[3] = { 0xe, 0x87, 0 };
1411 if (dvb_usb_generic_rw(d->dev, obuf, 3, ibuf, 1, 0) < 0)
1412 err("command 0x0e transfer failed.");
1418 if (dvb_usb_generic_rw(d->dev, obuf, 3, ibuf, 1, 0) < 0)
1419 err("command 0x0e transfer failed.");
1425 if (dvb_usb_generic_rw(d->dev, obuf, 3, ibuf, 1, 0) < 0)
1426 err("command 0x0e transfer failed.");
1434 if (dvb_usb_generic_rw(d->dev, obuf, 3, ibuf, 1, 0) < 0)
1435 err("command 0x0e transfer failed.");
1439 if (dvb_usb_generic_rw(d->dev, obuf, 1, ibuf, 1, 0) < 0)
1440 err("command 0x51 transfer failed.");
1442 d->fe_adap[0].fe = dvb_attach(cxd2820r_attach, &cxd2820r_config,
1443 &d->dev->i2c_adap, NULL);
1444 if (d->fe_adap[0].fe != NULL) {
1445 if (dvb_attach(tda18271_attach, d->fe_adap[0].fe, 0x60,
1446 &d->dev->i2c_adap, &tda18271_config)) {
1447 info("Attached TDA18271HD/CXD2820R!\n");
1452 info("Failed to attach TDA18271HD/CXD2820R!\n");
1456 static int m88rs2000_frontend_attach(struct dvb_usb_adapter *d)
1458 u8 obuf[] = { 0x51 };
1461 if (dvb_usb_generic_rw(d->dev, obuf, 1, ibuf, 1, 0) < 0)
1462 err("command 0x51 transfer failed.");
1464 d->fe_adap[0].fe = dvb_attach(m88rs2000_attach, &s421_m88rs2000_config,
1467 if (d->fe_adap[0].fe == NULL)
1470 if (dvb_attach(ts2020_attach, d->fe_adap[0].fe,
1471 &dw2104_ts2020_config,
1472 &d->dev->i2c_adap)) {
1473 info("Attached RS2000/TS2020!\n");
1477 info("Failed to attach RS2000/TS2020!\n");
1481 static int tt_s2_4600_frontend_attach(struct dvb_usb_adapter *adap)
1483 struct dvb_usb_device *d = adap->dev;
1484 struct dw2102_state *state = d->priv;
1485 u8 obuf[3] = { 0xe, 0x80, 0 };
1487 struct i2c_adapter *i2c_adapter;
1488 struct i2c_client *client;
1489 struct i2c_board_info info;
1490 struct ts2020_config ts2020_config = {};
1492 if (dvb_usb_generic_rw(d, obuf, 3, ibuf, 1, 0) < 0)
1493 err("command 0x0e transfer failed.");
1499 if (dvb_usb_generic_rw(d, obuf, 3, ibuf, 1, 0) < 0)
1500 err("command 0x0e transfer failed.");
1507 if (dvb_usb_generic_rw(d, obuf, 3, ibuf, 1, 0) < 0)
1508 err("command 0x0e transfer failed.");
1514 if (dvb_usb_generic_rw(d, obuf, 3, ibuf, 1, 0) < 0)
1515 err("command 0x0e transfer failed.");
1519 if (dvb_usb_generic_rw(d, obuf, 1, ibuf, 1, 0) < 0)
1520 err("command 0x51 transfer failed.");
1522 memset(&info, 0, sizeof(struct i2c_board_info));
1524 adap->fe_adap[0].fe = dvb_attach(m88ds3103_attach,
1525 &tt_s2_4600_m88ds3103_config,
1528 if (adap->fe_adap[0].fe == NULL)
1532 ts2020_config.fe = adap->fe_adap[0].fe;
1533 strlcpy(info.type, "ts2022", I2C_NAME_SIZE);
1535 info.platform_data = &ts2020_config;
1536 request_module("ts2020");
1537 client = i2c_new_device(i2c_adapter, &info);
1539 if (client == NULL || client->dev.driver == NULL) {
1540 dvb_frontend_detach(adap->fe_adap[0].fe);
1544 if (!try_module_get(client->dev.driver->owner)) {
1545 i2c_unregister_device(client);
1546 dvb_frontend_detach(adap->fe_adap[0].fe);
1550 /* delegate signal strength measurement to tuner */
1551 adap->fe_adap[0].fe->ops.read_signal_strength =
1552 adap->fe_adap[0].fe->ops.tuner_ops.get_rf_strength;
1554 state->i2c_client_tuner = client;
1559 static int dw2102_tuner_attach(struct dvb_usb_adapter *adap)
1561 dvb_attach(dvb_pll_attach, adap->fe_adap[0].fe, 0x60,
1562 &adap->dev->i2c_adap, DVB_PLL_OPERA1);
1566 static int dw3101_tuner_attach(struct dvb_usb_adapter *adap)
1568 dvb_attach(dvb_pll_attach, adap->fe_adap[0].fe, 0x60,
1569 &adap->dev->i2c_adap, DVB_PLL_TUA6034);
1574 static int dw2102_rc_query(struct dvb_usb_device *d)
1577 struct i2c_msg msg = {
1578 .addr = DW2102_RC_QUERY,
1584 if (d->props.i2c_algo->master_xfer(&d->i2c_adap, &msg, 1) == 1) {
1585 if (msg.buf[0] != 0xff) {
1586 deb_rc("%s: rc code: %x, %x\n",
1587 __func__, key[0], key[1]);
1588 rc_keydown(d->rc_dev, RC_TYPE_UNKNOWN, key[0], 0);
1595 static int prof_rc_query(struct dvb_usb_device *d)
1598 struct i2c_msg msg = {
1599 .addr = DW2102_RC_QUERY,
1605 if (d->props.i2c_algo->master_xfer(&d->i2c_adap, &msg, 1) == 1) {
1606 if (msg.buf[0] != 0xff) {
1607 deb_rc("%s: rc code: %x, %x\n",
1608 __func__, key[0], key[1]);
1609 rc_keydown(d->rc_dev, RC_TYPE_UNKNOWN, key[0]^0xff, 0);
1616 static int su3000_rc_query(struct dvb_usb_device *d)
1619 struct i2c_msg msg = {
1620 .addr = DW2102_RC_QUERY,
1626 if (d->props.i2c_algo->master_xfer(&d->i2c_adap, &msg, 1) == 1) {
1627 if (msg.buf[0] != 0xff) {
1628 deb_rc("%s: rc code: %x, %x\n",
1629 __func__, key[0], key[1]);
1630 rc_keydown(d->rc_dev, RC_TYPE_RC5,
1631 RC_SCANCODE_RC5(key[1], key[0]), 0);
1638 enum dw2102_table_entry {
1650 TERRATEC_CINERGY_S2,
1656 TERRATEC_CINERGY_S2_R2,
1659 TECHNOTREND_S2_4600,
1662 static struct usb_device_id dw2102_table[] = {
1663 [CYPRESS_DW2102] = {USB_DEVICE(USB_VID_CYPRESS, USB_PID_DW2102)},
1664 [CYPRESS_DW2101] = {USB_DEVICE(USB_VID_CYPRESS, 0x2101)},
1665 [CYPRESS_DW2104] = {USB_DEVICE(USB_VID_CYPRESS, USB_PID_DW2104)},
1666 [TEVII_S650] = {USB_DEVICE(0x9022, USB_PID_TEVII_S650)},
1667 [TERRATEC_CINERGY_S] = {USB_DEVICE(USB_VID_TERRATEC, USB_PID_CINERGY_S)},
1668 [CYPRESS_DW3101] = {USB_DEVICE(USB_VID_CYPRESS, USB_PID_DW3101)},
1669 [TEVII_S630] = {USB_DEVICE(0x9022, USB_PID_TEVII_S630)},
1670 [PROF_1100] = {USB_DEVICE(0x3011, USB_PID_PROF_1100)},
1671 [TEVII_S660] = {USB_DEVICE(0x9022, USB_PID_TEVII_S660)},
1672 [PROF_7500] = {USB_DEVICE(0x3034, 0x7500)},
1673 [GENIATECH_SU3000] = {USB_DEVICE(0x1f4d, 0x3000)},
1674 [TERRATEC_CINERGY_S2] = {USB_DEVICE(USB_VID_TERRATEC, 0x00a8)},
1675 [TEVII_S480_1] = {USB_DEVICE(0x9022, USB_PID_TEVII_S480_1)},
1676 [TEVII_S480_2] = {USB_DEVICE(0x9022, USB_PID_TEVII_S480_2)},
1677 [X3M_SPC1400HD] = {USB_DEVICE(0x1f4d, 0x3100)},
1678 [TEVII_S421] = {USB_DEVICE(0x9022, USB_PID_TEVII_S421)},
1679 [TEVII_S632] = {USB_DEVICE(0x9022, USB_PID_TEVII_S632)},
1680 [TERRATEC_CINERGY_S2_R2] = {USB_DEVICE(USB_VID_TERRATEC, 0x00b0)},
1681 [GOTVIEW_SAT_HD] = {USB_DEVICE(0x1FE1, USB_PID_GOTVIEW_SAT_HD)},
1682 [GENIATECH_T220] = {USB_DEVICE(0x1f4d, 0xD220)},
1683 [TECHNOTREND_S2_4600] = {USB_DEVICE(USB_VID_TECHNOTREND,
1684 USB_PID_TECHNOTREND_CONNECT_S2_4600)},
1688 MODULE_DEVICE_TABLE(usb, dw2102_table);
1690 static int dw2102_load_firmware(struct usb_device *dev,
1691 const struct firmware *frmwr)
1696 u8 reset16[] = {0, 0, 0, 0, 0, 0, 0};
1697 const struct firmware *fw;
1699 switch (le16_to_cpu(dev->descriptor.idProduct)) {
1701 ret = request_firmware(&fw, DW2101_FIRMWARE, &dev->dev);
1703 err(err_str, DW2101_FIRMWARE);
1711 info("start downloading DW210X firmware");
1712 p = kmalloc(fw->size, GFP_KERNEL);
1715 dw210x_op_rw(dev, 0xa0, 0x7f92, 0, &reset, 1, DW210X_WRITE_MSG);
1716 dw210x_op_rw(dev, 0xa0, 0xe600, 0, &reset, 1, DW210X_WRITE_MSG);
1719 memcpy(p, fw->data, fw->size);
1720 for (i = 0; i < fw->size; i += 0x40) {
1722 if (dw210x_op_rw(dev, 0xa0, i, 0, b , 0x40,
1723 DW210X_WRITE_MSG) != 0x40) {
1724 err("error while transferring firmware");
1729 /* restart the CPU */
1731 if (ret || dw210x_op_rw(dev, 0xa0, 0x7f92, 0, &reset, 1,
1732 DW210X_WRITE_MSG) != 1) {
1733 err("could not restart the USB controller CPU.");
1736 if (ret || dw210x_op_rw(dev, 0xa0, 0xe600, 0, &reset, 1,
1737 DW210X_WRITE_MSG) != 1) {
1738 err("could not restart the USB controller CPU.");
1741 /* init registers */
1742 switch (le16_to_cpu(dev->descriptor.idProduct)) {
1743 case USB_PID_TEVII_S650:
1744 dw2104_properties.rc.core.rc_codes = RC_MAP_TEVII_NEC;
1745 case USB_PID_DW2104:
1747 dw210x_op_rw(dev, 0xc4, 0x0000, 0, &reset, 1,
1749 /* break omitted intentionally */
1750 case USB_PID_DW3101:
1752 dw210x_op_rw(dev, 0xbf, 0x0040, 0, &reset, 0,
1755 case USB_PID_CINERGY_S:
1756 case USB_PID_DW2102:
1757 dw210x_op_rw(dev, 0xbf, 0x0040, 0, &reset, 0,
1759 dw210x_op_rw(dev, 0xb9, 0x0000, 0, &reset16[0], 2,
1761 /* check STV0299 frontend */
1762 dw210x_op_rw(dev, 0xb5, 0, 0, &reset16[0], 2,
1764 if ((reset16[0] == 0xa1) || (reset16[0] == 0x80)) {
1765 dw2102_properties.i2c_algo = &dw2102_i2c_algo;
1766 dw2102_properties.adapter->fe[0].tuner_attach = &dw2102_tuner_attach;
1769 /* check STV0288 frontend */
1773 dw210x_op_rw(dev, 0xc2, 0, 0, &reset16[0], 3,
1775 dw210x_op_rw(dev, 0xc3, 0xd1, 0, &reset16[0], 3,
1777 if (reset16[2] == 0x11) {
1778 dw2102_properties.i2c_algo = &dw2102_earda_i2c_algo;
1783 dw210x_op_rw(dev, 0xbc, 0x0030, 0, &reset16[0], 2,
1785 dw210x_op_rw(dev, 0xba, 0x0000, 0, &reset16[0], 7,
1787 dw210x_op_rw(dev, 0xba, 0x0000, 0, &reset16[0], 7,
1789 dw210x_op_rw(dev, 0xb9, 0x0000, 0, &reset16[0], 2,
1800 static struct dvb_usb_device_properties dw2102_properties = {
1801 .caps = DVB_USB_IS_AN_I2C_ADAPTER,
1802 .usb_ctrl = DEVICE_SPECIFIC,
1803 .firmware = DW2102_FIRMWARE,
1806 .i2c_algo = &dw2102_serit_i2c_algo,
1810 .rc_codes = RC_MAP_DM1105_NEC,
1811 .module_name = "dw2102",
1812 .allowed_protos = RC_BIT_NEC,
1813 .rc_query = dw2102_rc_query,
1816 .generic_bulk_ctrl_endpoint = 0x81,
1817 /* parameter for the MPEG2-data transfer */
1819 .download_firmware = dw2102_load_firmware,
1820 .read_mac_address = dw210x_read_mac_address,
1825 .frontend_attach = dw2102_frontend_attach,
1839 .num_device_descs = 3,
1841 {"DVBWorld DVB-S 2102 USB2.0",
1842 {&dw2102_table[CYPRESS_DW2102], NULL},
1845 {"DVBWorld DVB-S 2101 USB2.0",
1846 {&dw2102_table[CYPRESS_DW2101], NULL},
1849 {"TerraTec Cinergy S USB",
1850 {&dw2102_table[TERRATEC_CINERGY_S], NULL},
1856 static struct dvb_usb_device_properties dw2104_properties = {
1857 .caps = DVB_USB_IS_AN_I2C_ADAPTER,
1858 .usb_ctrl = DEVICE_SPECIFIC,
1859 .firmware = DW2104_FIRMWARE,
1862 .i2c_algo = &dw2104_i2c_algo,
1865 .rc_codes = RC_MAP_DM1105_NEC,
1866 .module_name = "dw2102",
1867 .allowed_protos = RC_BIT_NEC,
1868 .rc_query = dw2102_rc_query,
1871 .generic_bulk_ctrl_endpoint = 0x81,
1872 /* parameter for the MPEG2-data transfer */
1874 .download_firmware = dw2102_load_firmware,
1875 .read_mac_address = dw210x_read_mac_address,
1880 .frontend_attach = dw2104_frontend_attach,
1894 .num_device_descs = 2,
1896 { "DVBWorld DW2104 USB2.0",
1897 {&dw2102_table[CYPRESS_DW2104], NULL},
1900 { "TeVii S650 USB2.0",
1901 {&dw2102_table[TEVII_S650], NULL},
1907 static struct dvb_usb_device_properties dw3101_properties = {
1908 .caps = DVB_USB_IS_AN_I2C_ADAPTER,
1909 .usb_ctrl = DEVICE_SPECIFIC,
1910 .firmware = DW3101_FIRMWARE,
1913 .i2c_algo = &dw3101_i2c_algo,
1916 .rc_codes = RC_MAP_DM1105_NEC,
1917 .module_name = "dw2102",
1918 .allowed_protos = RC_BIT_NEC,
1919 .rc_query = dw2102_rc_query,
1922 .generic_bulk_ctrl_endpoint = 0x81,
1923 /* parameter for the MPEG2-data transfer */
1925 .download_firmware = dw2102_load_firmware,
1926 .read_mac_address = dw210x_read_mac_address,
1931 .frontend_attach = dw3101_frontend_attach,
1932 .tuner_attach = dw3101_tuner_attach,
1946 .num_device_descs = 1,
1948 { "DVBWorld DVB-C 3101 USB2.0",
1949 {&dw2102_table[CYPRESS_DW3101], NULL},
1955 static struct dvb_usb_device_properties s6x0_properties = {
1956 .caps = DVB_USB_IS_AN_I2C_ADAPTER,
1957 .usb_ctrl = DEVICE_SPECIFIC,
1958 .size_of_priv = sizeof(struct dw2102_state),
1959 .firmware = S630_FIRMWARE,
1962 .i2c_algo = &s6x0_i2c_algo,
1965 .rc_codes = RC_MAP_TEVII_NEC,
1966 .module_name = "dw2102",
1967 .allowed_protos = RC_BIT_NEC,
1968 .rc_query = dw2102_rc_query,
1971 .generic_bulk_ctrl_endpoint = 0x81,
1973 .download_firmware = dw2102_load_firmware,
1974 .read_mac_address = s6x0_read_mac_address,
1979 .frontend_attach = zl100313_frontend_attach,
1993 .num_device_descs = 1,
1996 {&dw2102_table[TEVII_S630], NULL},
2002 static struct dvb_usb_device_properties *p1100;
2003 static struct dvb_usb_device_description d1100 = {
2005 {&dw2102_table[PROF_1100], NULL},
2009 static struct dvb_usb_device_properties *s660;
2010 static struct dvb_usb_device_description d660 = {
2012 {&dw2102_table[TEVII_S660], NULL},
2016 static struct dvb_usb_device_description d480_1 = {
2018 {&dw2102_table[TEVII_S480_1], NULL},
2022 static struct dvb_usb_device_description d480_2 = {
2024 {&dw2102_table[TEVII_S480_2], NULL},
2028 static struct dvb_usb_device_properties *p7500;
2029 static struct dvb_usb_device_description d7500 = {
2030 "Prof 7500 USB DVB-S2",
2031 {&dw2102_table[PROF_7500], NULL},
2035 static struct dvb_usb_device_properties *s421;
2036 static struct dvb_usb_device_description d421 = {
2038 {&dw2102_table[TEVII_S421], NULL},
2042 static struct dvb_usb_device_description d632 = {
2044 {&dw2102_table[TEVII_S632], NULL},
2048 static struct dvb_usb_device_properties su3000_properties = {
2049 .caps = DVB_USB_IS_AN_I2C_ADAPTER,
2050 .usb_ctrl = DEVICE_SPECIFIC,
2051 .size_of_priv = sizeof(struct dw2102_state),
2052 .power_ctrl = su3000_power_ctrl,
2054 .identify_state = su3000_identify_state,
2055 .i2c_algo = &su3000_i2c_algo,
2059 .rc_codes = RC_MAP_SU3000,
2060 .module_name = "dw2102",
2061 .allowed_protos = RC_BIT_RC5,
2062 .rc_query = su3000_rc_query,
2065 .read_mac_address = su3000_read_mac_address,
2067 .generic_bulk_ctrl_endpoint = 0x01,
2073 .streaming_ctrl = su3000_streaming_ctrl,
2074 .frontend_attach = su3000_frontend_attach,
2088 .num_device_descs = 5,
2090 { "SU3000HD DVB-S USB2.0",
2091 { &dw2102_table[GENIATECH_SU3000], NULL },
2094 { "Terratec Cinergy S2 USB HD",
2095 { &dw2102_table[TERRATEC_CINERGY_S2], NULL },
2098 { "X3M TV SPC1400HD PCI",
2099 { &dw2102_table[X3M_SPC1400HD], NULL },
2102 { "Terratec Cinergy S2 USB HD Rev.2",
2103 { &dw2102_table[TERRATEC_CINERGY_S2_R2], NULL },
2106 { "GOTVIEW Satellite HD",
2107 { &dw2102_table[GOTVIEW_SAT_HD], NULL },
2113 static struct dvb_usb_device_properties t220_properties = {
2114 .caps = DVB_USB_IS_AN_I2C_ADAPTER,
2115 .usb_ctrl = DEVICE_SPECIFIC,
2116 .size_of_priv = sizeof(struct dw2102_state),
2117 .power_ctrl = su3000_power_ctrl,
2119 .identify_state = su3000_identify_state,
2120 .i2c_algo = &su3000_i2c_algo,
2124 .rc_codes = RC_MAP_SU3000,
2125 .module_name = "dw2102",
2126 .allowed_protos = RC_BIT_RC5,
2127 .rc_query = su3000_rc_query,
2130 .read_mac_address = su3000_read_mac_address,
2132 .generic_bulk_ctrl_endpoint = 0x01,
2138 .streaming_ctrl = su3000_streaming_ctrl,
2139 .frontend_attach = t220_frontend_attach,
2153 .num_device_descs = 1,
2155 { "Geniatech T220 DVB-T/T2 USB2.0",
2156 { &dw2102_table[GENIATECH_T220], NULL },
2162 static struct dvb_usb_device_properties tt_s2_4600_properties = {
2163 .caps = DVB_USB_IS_AN_I2C_ADAPTER,
2164 .usb_ctrl = DEVICE_SPECIFIC,
2165 .size_of_priv = sizeof(struct dw2102_state),
2166 .power_ctrl = su3000_power_ctrl,
2168 .identify_state = su3000_identify_state,
2169 .i2c_algo = &su3000_i2c_algo,
2173 .rc_codes = RC_MAP_TT_1500,
2174 .module_name = "dw2102",
2175 .allowed_protos = RC_BIT_RC5,
2176 .rc_query = su3000_rc_query,
2179 .read_mac_address = su3000_read_mac_address,
2181 .generic_bulk_ctrl_endpoint = 0x01,
2187 .streaming_ctrl = su3000_streaming_ctrl,
2188 .frontend_attach = tt_s2_4600_frontend_attach,
2202 .num_device_descs = 1,
2204 { "TechnoTrend TT-connect S2-4600",
2205 { &dw2102_table[TECHNOTREND_S2_4600], NULL },
2211 static int dw2102_probe(struct usb_interface *intf,
2212 const struct usb_device_id *id)
2214 p1100 = kmemdup(&s6x0_properties,
2215 sizeof(struct dvb_usb_device_properties), GFP_KERNEL);
2218 /* copy default structure */
2219 /* fill only different fields */
2220 p1100->firmware = P1100_FIRMWARE;
2221 p1100->devices[0] = d1100;
2222 p1100->rc.core.rc_query = prof_rc_query;
2223 p1100->rc.core.rc_codes = RC_MAP_TBS_NEC;
2224 p1100->adapter->fe[0].frontend_attach = stv0288_frontend_attach;
2226 s660 = kmemdup(&s6x0_properties,
2227 sizeof(struct dvb_usb_device_properties), GFP_KERNEL);
2232 s660->firmware = S660_FIRMWARE;
2233 s660->num_device_descs = 3;
2234 s660->devices[0] = d660;
2235 s660->devices[1] = d480_1;
2236 s660->devices[2] = d480_2;
2237 s660->adapter->fe[0].frontend_attach = ds3000_frontend_attach;
2239 p7500 = kmemdup(&s6x0_properties,
2240 sizeof(struct dvb_usb_device_properties), GFP_KERNEL);
2246 p7500->firmware = P7500_FIRMWARE;
2247 p7500->devices[0] = d7500;
2248 p7500->rc.core.rc_query = prof_rc_query;
2249 p7500->rc.core.rc_codes = RC_MAP_TBS_NEC;
2250 p7500->adapter->fe[0].frontend_attach = prof_7500_frontend_attach;
2253 s421 = kmemdup(&su3000_properties,
2254 sizeof(struct dvb_usb_device_properties), GFP_KERNEL);
2261 s421->num_device_descs = 2;
2262 s421->devices[0] = d421;
2263 s421->devices[1] = d632;
2264 s421->adapter->fe[0].frontend_attach = m88rs2000_frontend_attach;
2266 if (0 == dvb_usb_device_init(intf, &dw2102_properties,
2267 THIS_MODULE, NULL, adapter_nr) ||
2268 0 == dvb_usb_device_init(intf, &dw2104_properties,
2269 THIS_MODULE, NULL, adapter_nr) ||
2270 0 == dvb_usb_device_init(intf, &dw3101_properties,
2271 THIS_MODULE, NULL, adapter_nr) ||
2272 0 == dvb_usb_device_init(intf, &s6x0_properties,
2273 THIS_MODULE, NULL, adapter_nr) ||
2274 0 == dvb_usb_device_init(intf, p1100,
2275 THIS_MODULE, NULL, adapter_nr) ||
2276 0 == dvb_usb_device_init(intf, s660,
2277 THIS_MODULE, NULL, adapter_nr) ||
2278 0 == dvb_usb_device_init(intf, p7500,
2279 THIS_MODULE, NULL, adapter_nr) ||
2280 0 == dvb_usb_device_init(intf, s421,
2281 THIS_MODULE, NULL, adapter_nr) ||
2282 0 == dvb_usb_device_init(intf, &su3000_properties,
2283 THIS_MODULE, NULL, adapter_nr) ||
2284 0 == dvb_usb_device_init(intf, &t220_properties,
2285 THIS_MODULE, NULL, adapter_nr) ||
2286 0 == dvb_usb_device_init(intf, &tt_s2_4600_properties,
2287 THIS_MODULE, NULL, adapter_nr))
2293 static void dw2102_disconnect(struct usb_interface *intf)
2295 struct dvb_usb_device *d = usb_get_intfdata(intf);
2296 struct dw2102_state *st = (struct dw2102_state *)d->priv;
2297 struct i2c_client *client;
2299 /* remove I2C client for tuner */
2300 client = st->i2c_client_tuner;
2302 module_put(client->dev.driver->owner);
2303 i2c_unregister_device(client);
2306 dvb_usb_device_exit(intf);
2309 static struct usb_driver dw2102_driver = {
2311 .probe = dw2102_probe,
2312 .disconnect = dw2102_disconnect,
2313 .id_table = dw2102_table,
2316 module_usb_driver(dw2102_driver);
2318 MODULE_AUTHOR("Igor M. Liplianin (c) liplianin@me.by");
2319 MODULE_DESCRIPTION("Driver for DVBWorld DVB-S 2101, 2102, DVB-S2 2104,"
2320 " DVB-C 3101 USB2.0,"
2321 " TeVii S600, S630, S650, S660, S480, S421, S632"
2322 " Prof 1100, 7500 USB2.0,"
2323 " Geniatech SU3000, T220,"
2324 " TechnoTrend S2-4600 devices");
2325 MODULE_VERSION("0.1");
2326 MODULE_LICENSE("GPL");
2327 MODULE_FIRMWARE(DW2101_FIRMWARE);
2328 MODULE_FIRMWARE(DW2102_FIRMWARE);
2329 MODULE_FIRMWARE(DW2104_FIRMWARE);
2330 MODULE_FIRMWARE(DW3101_FIRMWARE);
2331 MODULE_FIRMWARE(S630_FIRMWARE);
2332 MODULE_FIRMWARE(S660_FIRMWARE);
2333 MODULE_FIRMWARE(P1100_FIRMWARE);
2334 MODULE_FIRMWARE(P7500_FIRMWARE);