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,
5 * Geniatech SU3000, T220,
7 * Terratec Cinergy S2 cards
8 * Copyright (C) 2008-2012 Igor M. Liplianin (liplianin@me.by)
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.
14 * see Documentation/dvb/README.dvb-usb for more information
16 #include "dvb-usb-ids.h"
33 #include "stb6100_proc.h"
34 #include "m88rs2000.h"
37 #include "m88ds3103.h"
39 /* Max transfer size done by I2C transfer functions */
40 #define MAX_XFER_SIZE 64
43 #define DW210X_READ_MSG 0
44 #define DW210X_WRITE_MSG 1
46 #define REG_1F_SYMBOLRATE_BYTE0 0x1f
47 #define REG_20_SYMBOLRATE_BYTE1 0x20
48 #define REG_21_SYMBOLRATE_BYTE2 0x21
50 #define DW2102_VOLTAGE_CTRL (0x1800)
51 #define SU3000_STREAM_CTRL (0x1900)
52 #define DW2102_RC_QUERY (0x1a00)
53 #define DW2102_LED_CTRL (0x1b00)
55 #define DW2101_FIRMWARE "/*(DEBLOBBED)*/"
56 #define DW2102_FIRMWARE "/*(DEBLOBBED)*/"
57 #define DW2104_FIRMWARE "/*(DEBLOBBED)*/"
58 #define DW3101_FIRMWARE "/*(DEBLOBBED)*/"
59 #define S630_FIRMWARE "/*(DEBLOBBED)*/"
60 #define S660_FIRMWARE "/*(DEBLOBBED)*/"
61 #define P1100_FIRMWARE "/*(DEBLOBBED)*/"
62 #define P7500_FIRMWARE "/*(DEBLOBBED)*/"
64 #define err_str "did not find the firmware file. (%s) " \
65 "Please see linux/Documentation/dvb/ for more details " \
66 "on firmware-problems."
71 u8 data[MAX_XFER_SIZE + 4];
72 struct i2c_client *i2c_client_demod;
73 struct i2c_client *i2c_client_tuner;
75 /* fe hook functions*/
76 int (*old_set_voltage)(struct dvb_frontend *f, enum fe_sec_voltage v);
77 int (*fe_read_status)(struct dvb_frontend *fe,
78 enum fe_status *status);
82 static int dvb_usb_dw2102_debug;
83 module_param_named(debug, dvb_usb_dw2102_debug, int, 0644);
84 MODULE_PARM_DESC(debug, "set debugging level (1=info 2=xfer 4=rc(or-able))."
85 DVB_USB_DEBUG_STATUS);
88 static int demod_probe = 1;
89 module_param_named(demod, demod_probe, int, 0644);
90 MODULE_PARM_DESC(demod, "demod to probe (1=cx24116 2=stv0903+stv6110 "
91 "4=stv0903+stb6100(or-able)).");
93 DVB_DEFINE_MOD_OPT_ADAPTER_NR(adapter_nr);
95 static int dw210x_op_rw(struct usb_device *dev, u8 request, u16 value,
96 u16 index, u8 * data, u16 len, int flags)
100 unsigned int pipe = (flags == DW210X_READ_MSG) ?
101 usb_rcvctrlpipe(dev, 0) : usb_sndctrlpipe(dev, 0);
102 u8 request_type = (flags == DW210X_READ_MSG) ? USB_DIR_IN : USB_DIR_OUT;
104 u8buf = kmalloc(len, GFP_KERNEL);
109 if (flags == DW210X_WRITE_MSG)
110 memcpy(u8buf, data, len);
111 ret = usb_control_msg(dev, pipe, request, request_type | USB_TYPE_VENDOR,
112 value, index , u8buf, len, 2000);
114 if (flags == DW210X_READ_MSG)
115 memcpy(data, u8buf, len);
122 static int dw2102_i2c_transfer(struct i2c_adapter *adap, struct i2c_msg msg[],
125 struct dvb_usb_device *d = i2c_get_adapdata(adap);
127 u8 buf6[] = {0x2c, 0x05, 0xc0, 0, 0, 0, 0};
132 if (mutex_lock_interruptible(&d->i2c_mutex) < 0)
137 /* read stv0299 register */
138 value = msg[0].buf[0];/* register */
139 for (i = 0; i < msg[1].len; i++) {
140 dw210x_op_rw(d->udev, 0xb5, value + i, 0,
141 buf6, 2, DW210X_READ_MSG);
142 msg[1].buf[i] = buf6[0];
146 switch (msg[0].addr) {
148 /* write to stv0299 register */
150 buf6[1] = msg[0].buf[0];
151 buf6[2] = msg[0].buf[1];
152 dw210x_op_rw(d->udev, 0xb2, 0, 0,
153 buf6, 3, DW210X_WRITE_MSG);
156 if (msg[0].flags == 0) {
157 /* write to tuner pll */
161 buf6[3] = msg[0].buf[0];
162 buf6[4] = msg[0].buf[1];
163 buf6[5] = msg[0].buf[2];
164 buf6[6] = msg[0].buf[3];
165 dw210x_op_rw(d->udev, 0xb2, 0, 0,
166 buf6, 7, DW210X_WRITE_MSG);
168 /* read from tuner */
169 dw210x_op_rw(d->udev, 0xb5, 0, 0,
170 buf6, 1, DW210X_READ_MSG);
171 msg[0].buf[0] = buf6[0];
174 case (DW2102_RC_QUERY):
175 dw210x_op_rw(d->udev, 0xb8, 0, 0,
176 buf6, 2, DW210X_READ_MSG);
177 msg[0].buf[0] = buf6[0];
178 msg[0].buf[1] = buf6[1];
180 case (DW2102_VOLTAGE_CTRL):
182 buf6[1] = msg[0].buf[0];
183 dw210x_op_rw(d->udev, 0xb2, 0, 0,
184 buf6, 2, DW210X_WRITE_MSG);
191 mutex_unlock(&d->i2c_mutex);
195 static int dw2102_serit_i2c_transfer(struct i2c_adapter *adap,
196 struct i2c_msg msg[], int num)
198 struct dvb_usb_device *d = i2c_get_adapdata(adap);
199 u8 buf6[] = {0, 0, 0, 0, 0, 0, 0};
203 if (mutex_lock_interruptible(&d->i2c_mutex) < 0)
208 if (msg[0].len != 1) {
209 warn("i2c rd: len=%d is not 1!\n",
215 if (2 + msg[1].len > sizeof(buf6)) {
216 warn("i2c rd: len=%d is too big!\n",
222 /* read si2109 register by number */
223 buf6[0] = msg[0].addr << 1;
224 buf6[1] = msg[0].len;
225 buf6[2] = msg[0].buf[0];
226 dw210x_op_rw(d->udev, 0xc2, 0, 0,
227 buf6, msg[0].len + 2, DW210X_WRITE_MSG);
228 /* read si2109 register */
229 dw210x_op_rw(d->udev, 0xc3, 0xd0, 0,
230 buf6, msg[1].len + 2, DW210X_READ_MSG);
231 memcpy(msg[1].buf, buf6 + 2, msg[1].len);
235 switch (msg[0].addr) {
237 if (2 + msg[0].len > sizeof(buf6)) {
238 warn("i2c wr: len=%d is too big!\n",
244 /* write to si2109 register */
245 buf6[0] = msg[0].addr << 1;
246 buf6[1] = msg[0].len;
247 memcpy(buf6 + 2, msg[0].buf, msg[0].len);
248 dw210x_op_rw(d->udev, 0xc2, 0, 0, buf6,
249 msg[0].len + 2, DW210X_WRITE_MSG);
251 case(DW2102_RC_QUERY):
252 dw210x_op_rw(d->udev, 0xb8, 0, 0,
253 buf6, 2, DW210X_READ_MSG);
254 msg[0].buf[0] = buf6[0];
255 msg[0].buf[1] = buf6[1];
257 case(DW2102_VOLTAGE_CTRL):
259 buf6[1] = msg[0].buf[0];
260 dw210x_op_rw(d->udev, 0xb2, 0, 0,
261 buf6, 2, DW210X_WRITE_MSG);
267 mutex_unlock(&d->i2c_mutex);
271 static int dw2102_earda_i2c_transfer(struct i2c_adapter *adap, struct i2c_msg msg[], int num)
273 struct dvb_usb_device *d = i2c_get_adapdata(adap);
278 if (mutex_lock_interruptible(&d->i2c_mutex) < 0)
284 /* first write first register number */
285 u8 ibuf[MAX_XFER_SIZE], obuf[3];
287 if (2 + msg[0].len != sizeof(obuf)) {
288 warn("i2c rd: len=%d is not 1!\n",
294 if (2 + msg[1].len > sizeof(ibuf)) {
295 warn("i2c rd: len=%d is too big!\n",
301 obuf[0] = msg[0].addr << 1;
302 obuf[1] = msg[0].len;
303 obuf[2] = msg[0].buf[0];
304 dw210x_op_rw(d->udev, 0xc2, 0, 0,
305 obuf, msg[0].len + 2, DW210X_WRITE_MSG);
306 /* second read registers */
307 dw210x_op_rw(d->udev, 0xc3, 0xd1 , 0,
308 ibuf, msg[1].len + 2, DW210X_READ_MSG);
309 memcpy(msg[1].buf, ibuf + 2, msg[1].len);
314 switch (msg[0].addr) {
316 /* write to register */
317 u8 obuf[MAX_XFER_SIZE];
319 if (2 + msg[0].len > sizeof(obuf)) {
320 warn("i2c wr: len=%d is too big!\n",
326 obuf[0] = msg[0].addr << 1;
327 obuf[1] = msg[0].len;
328 memcpy(obuf + 2, msg[0].buf, msg[0].len);
329 dw210x_op_rw(d->udev, 0xc2, 0, 0,
330 obuf, msg[0].len + 2, DW210X_WRITE_MSG);
335 u8 obuf[MAX_XFER_SIZE];
337 if (2 + msg[0].len > sizeof(obuf)) {
338 warn("i2c wr: len=%d is too big!\n",
344 obuf[0] = msg[0].addr << 1;
345 obuf[1] = msg[0].len;
346 memcpy(obuf + 2, msg[0].buf, msg[0].len);
347 dw210x_op_rw(d->udev, 0xc2, 0, 0,
348 obuf, msg[0].len + 2, DW210X_WRITE_MSG);
351 case(DW2102_RC_QUERY): {
353 dw210x_op_rw(d->udev, 0xb8, 0, 0,
354 ibuf, 2, DW210X_READ_MSG);
355 memcpy(msg[0].buf, ibuf , 2);
358 case(DW2102_VOLTAGE_CTRL): {
361 obuf[1] = msg[0].buf[0];
362 dw210x_op_rw(d->udev, 0xb2, 0, 0,
363 obuf, 2, DW210X_WRITE_MSG);
373 mutex_unlock(&d->i2c_mutex);
377 static int dw2104_i2c_transfer(struct i2c_adapter *adap, struct i2c_msg msg[], int num)
379 struct dvb_usb_device *d = i2c_get_adapdata(adap);
384 if (mutex_lock_interruptible(&d->i2c_mutex) < 0)
387 for (j = 0; j < num; j++) {
388 switch (msg[j].addr) {
389 case(DW2102_RC_QUERY): {
391 dw210x_op_rw(d->udev, 0xb8, 0, 0,
392 ibuf, 2, DW210X_READ_MSG);
393 memcpy(msg[j].buf, ibuf , 2);
396 case(DW2102_VOLTAGE_CTRL): {
399 obuf[1] = msg[j].buf[0];
400 dw210x_op_rw(d->udev, 0xb2, 0, 0,
401 obuf, 2, DW210X_WRITE_MSG);
406 case 0x68: ds3000, stv0903
407 case 0x60: ts2020, stv6110, stb6100 */
409 if (msg[j].flags == I2C_M_RD) {
411 u8 ibuf[MAX_XFER_SIZE];
413 if (2 + msg[j].len > sizeof(ibuf)) {
414 warn("i2c rd: len=%d is too big!\n",
420 dw210x_op_rw(d->udev, 0xc3,
421 (msg[j].addr << 1) + 1, 0,
422 ibuf, msg[j].len + 2,
424 memcpy(msg[j].buf, ibuf + 2, msg[j].len);
426 } else if (((msg[j].buf[0] == 0xb0) &&
427 (msg[j].addr == 0x68)) ||
428 ((msg[j].buf[0] == 0xf7) &&
429 (msg[j].addr == 0x55))) {
432 obuf[0] = msg[j].addr << 1;
433 obuf[1] = (msg[j].len > 15 ? 17 : msg[j].len);
434 obuf[2] = msg[j].buf[0];
435 len = msg[j].len - 1;
438 memcpy(obuf + 3, msg[j].buf + i,
439 (len > 16 ? 16 : len));
440 dw210x_op_rw(d->udev, 0xc2, 0, 0,
441 obuf, (len > 16 ? 16 : len) + 3,
447 /* write registers */
448 u8 obuf[MAX_XFER_SIZE];
450 if (2 + msg[j].len > sizeof(obuf)) {
451 warn("i2c wr: len=%d is too big!\n",
457 obuf[0] = msg[j].addr << 1;
458 obuf[1] = msg[j].len;
459 memcpy(obuf + 2, msg[j].buf, msg[j].len);
460 dw210x_op_rw(d->udev, 0xc2, 0, 0,
461 obuf, msg[j].len + 2,
472 mutex_unlock(&d->i2c_mutex);
476 static int dw3101_i2c_transfer(struct i2c_adapter *adap, struct i2c_msg msg[],
479 struct dvb_usb_device *d = i2c_get_adapdata(adap);
485 if (mutex_lock_interruptible(&d->i2c_mutex) < 0)
491 /* first write first register number */
492 u8 ibuf[MAX_XFER_SIZE], obuf[3];
494 if (2 + msg[0].len != sizeof(obuf)) {
495 warn("i2c rd: len=%d is not 1!\n",
500 if (2 + msg[1].len > sizeof(ibuf)) {
501 warn("i2c rd: len=%d is too big!\n",
506 obuf[0] = msg[0].addr << 1;
507 obuf[1] = msg[0].len;
508 obuf[2] = msg[0].buf[0];
509 dw210x_op_rw(d->udev, 0xc2, 0, 0,
510 obuf, msg[0].len + 2, DW210X_WRITE_MSG);
511 /* second read registers */
512 dw210x_op_rw(d->udev, 0xc3, 0x19 , 0,
513 ibuf, msg[1].len + 2, DW210X_READ_MSG);
514 memcpy(msg[1].buf, ibuf + 2, msg[1].len);
519 switch (msg[0].addr) {
522 /* write to register */
523 u8 obuf[MAX_XFER_SIZE];
525 if (2 + msg[0].len > sizeof(obuf)) {
526 warn("i2c wr: len=%d is too big!\n",
531 obuf[0] = msg[0].addr << 1;
532 obuf[1] = msg[0].len;
533 memcpy(obuf + 2, msg[0].buf, msg[0].len);
534 dw210x_op_rw(d->udev, 0xc2, 0, 0,
535 obuf, msg[0].len + 2, DW210X_WRITE_MSG);
538 case(DW2102_RC_QUERY): {
540 dw210x_op_rw(d->udev, 0xb8, 0, 0,
541 ibuf, 2, DW210X_READ_MSG);
542 memcpy(msg[0].buf, ibuf , 2);
550 for (i = 0; i < num; i++) {
551 deb_xfer("%02x:%02x: %s ", i, msg[i].addr,
552 msg[i].flags == 0 ? ">>>" : "<<<");
553 debug_dump(msg[i].buf, msg[i].len, deb_xfer);
558 mutex_unlock(&d->i2c_mutex);
562 static int s6x0_i2c_transfer(struct i2c_adapter *adap, struct i2c_msg msg[],
565 struct dvb_usb_device *d = i2c_get_adapdata(adap);
566 struct usb_device *udev;
572 if (mutex_lock_interruptible(&d->i2c_mutex) < 0)
575 for (j = 0; j < num; j++) {
576 switch (msg[j].addr) {
577 case (DW2102_RC_QUERY): {
579 dw210x_op_rw(d->udev, 0xb8, 0, 0,
580 ibuf, 5, DW210X_READ_MSG);
581 memcpy(msg[j].buf, ibuf + 3, 2);
584 case (DW2102_VOLTAGE_CTRL): {
588 obuf[1] = msg[j].buf[1];/* off-on */
589 dw210x_op_rw(d->udev, 0x8a, 0, 0,
590 obuf, 2, DW210X_WRITE_MSG);
592 obuf[1] = msg[j].buf[0];/* 13v-18v */
593 dw210x_op_rw(d->udev, 0x8a, 0, 0,
594 obuf, 2, DW210X_WRITE_MSG);
597 case (DW2102_LED_CTRL): {
601 obuf[1] = msg[j].buf[0];
602 dw210x_op_rw(d->udev, 0x8a, 0, 0,
603 obuf, 2, DW210X_WRITE_MSG);
608 case 0x68: ds3000, stv0903, rs2000
609 case 0x60: ts2020, stv6110, stb6100
612 if (msg[j].flags == I2C_M_RD) {
614 u8 ibuf[MAX_XFER_SIZE];
616 if (msg[j].len > sizeof(ibuf)) {
617 warn("i2c rd: len=%d is too big!\n",
623 dw210x_op_rw(d->udev, 0x91, 0, 0,
626 memcpy(msg[j].buf, ibuf, msg[j].len);
628 } else if ((msg[j].buf[0] == 0xb0) &&
629 (msg[j].addr == 0x68)) {
632 obuf[0] = (msg[j].len > 16 ?
633 18 : msg[j].len + 1);
634 obuf[1] = msg[j].addr << 1;
635 obuf[2] = msg[j].buf[0];
636 len = msg[j].len - 1;
639 memcpy(obuf + 3, msg[j].buf + i,
640 (len > 16 ? 16 : len));
641 dw210x_op_rw(d->udev, 0x80, 0, 0,
642 obuf, (len > 16 ? 16 : len) + 3,
647 } else if (j < (num - 1)) {
648 /* write register addr before read */
649 u8 obuf[MAX_XFER_SIZE];
651 if (2 + msg[j].len > sizeof(obuf)) {
652 warn("i2c wr: len=%d is too big!\n",
658 obuf[0] = msg[j + 1].len;
659 obuf[1] = (msg[j].addr << 1);
660 memcpy(obuf + 2, msg[j].buf, msg[j].len);
661 dw210x_op_rw(d->udev,
662 le16_to_cpu(udev->descriptor.idProduct) ==
663 0x7500 ? 0x92 : 0x90, 0, 0,
664 obuf, msg[j].len + 2,
668 /* write registers */
669 u8 obuf[MAX_XFER_SIZE];
671 if (2 + msg[j].len > sizeof(obuf)) {
672 warn("i2c wr: len=%d is too big!\n",
677 obuf[0] = msg[j].len + 1;
678 obuf[1] = (msg[j].addr << 1);
679 memcpy(obuf + 2, msg[j].buf, msg[j].len);
680 dw210x_op_rw(d->udev, 0x80, 0, 0,
681 obuf, msg[j].len + 2,
692 mutex_unlock(&d->i2c_mutex);
696 static int su3000_i2c_transfer(struct i2c_adapter *adap, struct i2c_msg msg[],
699 struct dvb_usb_device *d = i2c_get_adapdata(adap);
700 struct dw2102_state *state;
707 if (mutex_lock_interruptible(&d->i2c_mutex) < 0)
709 if (mutex_lock_interruptible(&d->data_mutex) < 0) {
710 mutex_unlock(&d->i2c_mutex);
716 switch (msg[0].addr) {
717 case SU3000_STREAM_CTRL:
718 state->data[0] = msg[0].buf[0] + 0x36;
721 if (dvb_usb_generic_rw(d, state->data, 3,
722 state->data, 0, 0) < 0)
723 err("i2c transfer failed.");
725 case DW2102_RC_QUERY:
726 state->data[0] = 0x10;
727 if (dvb_usb_generic_rw(d, state->data, 1,
728 state->data, 2, 0) < 0)
729 err("i2c transfer failed.");
730 msg[0].buf[1] = state->data[0];
731 msg[0].buf[0] = state->data[1];
734 if (3 + msg[0].len > sizeof(state->data)) {
735 warn("i2c wr: len=%d is too big!\n",
741 /* always i2c write*/
742 state->data[0] = 0x08;
743 state->data[1] = msg[0].addr;
744 state->data[2] = msg[0].len;
746 memcpy(&state->data[3], msg[0].buf, msg[0].len);
748 if (dvb_usb_generic_rw(d, state->data, msg[0].len + 3,
749 state->data, 1, 0) < 0)
750 err("i2c transfer failed.");
755 /* always i2c read */
756 if (4 + msg[0].len > sizeof(state->data)) {
757 warn("i2c rd: len=%d is too big!\n",
762 if (1 + msg[1].len > sizeof(state->data)) {
763 warn("i2c rd: len=%d is too big!\n",
769 state->data[0] = 0x09;
770 state->data[1] = msg[0].len;
771 state->data[2] = msg[1].len;
772 state->data[3] = msg[0].addr;
773 memcpy(&state->data[4], msg[0].buf, msg[0].len);
775 if (dvb_usb_generic_rw(d, state->data, msg[0].len + 4,
776 state->data, msg[1].len + 1, 0) < 0)
777 err("i2c transfer failed.");
779 memcpy(msg[1].buf, &state->data[1], msg[1].len);
782 warn("more than 2 i2c messages at a time is not handled yet.");
785 mutex_unlock(&d->data_mutex);
786 mutex_unlock(&d->i2c_mutex);
790 static u32 dw210x_i2c_func(struct i2c_adapter *adapter)
795 static struct i2c_algorithm dw2102_i2c_algo = {
796 .master_xfer = dw2102_i2c_transfer,
797 .functionality = dw210x_i2c_func,
800 static struct i2c_algorithm dw2102_serit_i2c_algo = {
801 .master_xfer = dw2102_serit_i2c_transfer,
802 .functionality = dw210x_i2c_func,
805 static struct i2c_algorithm dw2102_earda_i2c_algo = {
806 .master_xfer = dw2102_earda_i2c_transfer,
807 .functionality = dw210x_i2c_func,
810 static struct i2c_algorithm dw2104_i2c_algo = {
811 .master_xfer = dw2104_i2c_transfer,
812 .functionality = dw210x_i2c_func,
815 static struct i2c_algorithm dw3101_i2c_algo = {
816 .master_xfer = dw3101_i2c_transfer,
817 .functionality = dw210x_i2c_func,
820 static struct i2c_algorithm s6x0_i2c_algo = {
821 .master_xfer = s6x0_i2c_transfer,
822 .functionality = dw210x_i2c_func,
825 static struct i2c_algorithm su3000_i2c_algo = {
826 .master_xfer = su3000_i2c_transfer,
827 .functionality = dw210x_i2c_func,
830 static int dw210x_read_mac_address(struct dvb_usb_device *d, u8 mac[6])
834 u8 eeprom[256], eepromline[16];
836 for (i = 0; i < 256; i++) {
837 if (dw210x_op_rw(d->udev, 0xb6, 0xa0 , i, ibuf, 2, DW210X_READ_MSG) < 0) {
838 err("read eeprom failed.");
841 eepromline[i%16] = ibuf[0];
844 if ((i % 16) == 15) {
845 deb_xfer("%02x: ", i - 15);
846 debug_dump(eepromline, 16, deb_xfer);
850 memcpy(mac, eeprom + 8, 6);
854 static int s6x0_read_mac_address(struct dvb_usb_device *d, u8 mac[6])
857 u8 ibuf[] = { 0 }, obuf[] = { 0 };
858 u8 eeprom[256], eepromline[16];
859 struct i2c_msg msg[] = {
873 for (i = 0; i < 256; i++) {
875 ret = s6x0_i2c_transfer(&d->i2c_adap, msg, 2);
877 err("read eeprom failed.");
880 eepromline[i % 16] = ibuf[0];
884 if ((i % 16) == 15) {
885 deb_xfer("%02x: ", i - 15);
886 debug_dump(eepromline, 16, deb_xfer);
890 memcpy(mac, eeprom + 16, 6);
894 static int su3000_streaming_ctrl(struct dvb_usb_adapter *adap, int onoff)
896 static u8 command_start[] = {0x00};
897 static u8 command_stop[] = {0x01};
898 struct i2c_msg msg = {
899 .addr = SU3000_STREAM_CTRL,
901 .buf = onoff ? command_start : command_stop,
905 i2c_transfer(&adap->dev->i2c_adap, &msg, 1);
910 static int su3000_power_ctrl(struct dvb_usb_device *d, int i)
912 struct dw2102_state *state = (struct dw2102_state *)d->priv;
915 info("%s: %d, initialized %d", __func__, i, state->initialized);
917 if (i && !state->initialized) {
918 mutex_lock(&d->data_mutex);
920 state->data[0] = 0xde;
923 state->initialized = 1;
925 ret = dvb_usb_generic_rw(d, state->data, 2, NULL, 0, 0);
926 mutex_unlock(&d->data_mutex);
932 static int su3000_read_mac_address(struct dvb_usb_device *d, u8 mac[6])
935 u8 obuf[] = { 0x1f, 0xf0 };
937 struct i2c_msg msg[] = {
952 for (i = 0; i < 6; i++) {
954 if (i2c_transfer(&d->i2c_adap, msg, 2) != 2)
963 static int su3000_identify_state(struct usb_device *udev,
964 struct dvb_usb_device_properties *props,
965 struct dvb_usb_device_description **desc,
968 info("%s", __func__);
974 static int dw210x_set_voltage(struct dvb_frontend *fe,
975 enum fe_sec_voltage voltage)
977 static u8 command_13v[] = {0x00, 0x01};
978 static u8 command_18v[] = {0x01, 0x01};
979 static u8 command_off[] = {0x00, 0x00};
980 struct i2c_msg msg = {
981 .addr = DW2102_VOLTAGE_CTRL,
987 struct dvb_usb_adapter *udev_adap =
988 (struct dvb_usb_adapter *)(fe->dvb->priv);
989 if (voltage == SEC_VOLTAGE_18)
990 msg.buf = command_18v;
991 else if (voltage == SEC_VOLTAGE_13)
992 msg.buf = command_13v;
994 i2c_transfer(&udev_adap->dev->i2c_adap, &msg, 1);
999 static int s660_set_voltage(struct dvb_frontend *fe,
1000 enum fe_sec_voltage voltage)
1002 struct dvb_usb_adapter *d =
1003 (struct dvb_usb_adapter *)(fe->dvb->priv);
1004 struct dw2102_state *st = (struct dw2102_state *)d->dev->priv;
1006 dw210x_set_voltage(fe, voltage);
1007 if (st->old_set_voltage)
1008 st->old_set_voltage(fe, voltage);
1013 static void dw210x_led_ctrl(struct dvb_frontend *fe, int offon)
1015 static u8 led_off[] = { 0 };
1016 static u8 led_on[] = { 1 };
1017 struct i2c_msg msg = {
1018 .addr = DW2102_LED_CTRL,
1023 struct dvb_usb_adapter *udev_adap =
1024 (struct dvb_usb_adapter *)(fe->dvb->priv);
1028 i2c_transfer(&udev_adap->dev->i2c_adap, &msg, 1);
1031 static int tt_s2_4600_read_status(struct dvb_frontend *fe,
1032 enum fe_status *status)
1034 struct dvb_usb_adapter *d =
1035 (struct dvb_usb_adapter *)(fe->dvb->priv);
1036 struct dw2102_state *st = (struct dw2102_state *)d->dev->priv;
1039 ret = st->fe_read_status(fe, status);
1041 /* resync slave fifo when signal change from unlock to lock */
1042 if ((*status & FE_HAS_LOCK) && (!st->last_lock))
1043 su3000_streaming_ctrl(d, 1);
1045 st->last_lock = (*status & FE_HAS_LOCK) ? 1 : 0;
1049 static struct stv0299_config sharp_z0194a_config = {
1050 .demod_address = 0x68,
1051 .inittab = sharp_z0194a_inittab,
1055 .lock_output = STV0299_LOCKOUTPUT_1,
1056 .volt13_op0_op1 = STV0299_VOLT13_OP1,
1057 .min_delay_ms = 100,
1058 .set_symbol_rate = sharp_z0194a_set_symbol_rate,
1061 static struct cx24116_config dw2104_config = {
1062 .demod_address = 0x55,
1063 .mpg_clk_pos_pol = 0x01,
1066 static struct si21xx_config serit_sp1511lhb_config = {
1067 .demod_address = 0x68,
1068 .min_delay_ms = 100,
1072 static struct tda10023_config dw3101_tda10023_config = {
1073 .demod_address = 0x0c,
1077 static struct mt312_config zl313_config = {
1078 .demod_address = 0x0e,
1081 static struct ds3000_config dw2104_ds3000_config = {
1082 .demod_address = 0x68,
1085 static struct ts2020_config dw2104_ts2020_config = {
1086 .tuner_address = 0x60,
1088 .frequency_div = 1060000,
1091 static struct ds3000_config s660_ds3000_config = {
1092 .demod_address = 0x68,
1094 .set_lock_led = dw210x_led_ctrl,
1097 static struct ts2020_config s660_ts2020_config = {
1098 .tuner_address = 0x60,
1100 .frequency_div = 1146000,
1103 static struct stv0900_config dw2104a_stv0900_config = {
1104 .demod_address = 0x6a,
1107 .clkmode = 3,/* 0-CLKI, 2-XTALI, else AUTO */
1108 .diseqc_mode = 2,/* 2/3 PWM */
1109 .tun1_maddress = 0,/* 0x60 */
1110 .tun1_adc = 0,/* 2 Vpp */
1114 static struct stb6100_config dw2104a_stb6100_config = {
1115 .tuner_address = 0x60,
1116 .refclock = 27000000,
1119 static struct stv0900_config dw2104_stv0900_config = {
1120 .demod_address = 0x68,
1126 .tun1_adc = 1,/* 1 Vpp */
1130 static struct stv6110_config dw2104_stv6110_config = {
1131 .i2c_address = 0x60,
1136 static struct stv0900_config prof_7500_stv0900_config = {
1137 .demod_address = 0x6a,
1140 .clkmode = 3,/* 0-CLKI, 2-XTALI, else AUTO */
1141 .diseqc_mode = 2,/* 2/3 PWM */
1142 .tun1_maddress = 0,/* 0x60 */
1143 .tun1_adc = 0,/* 2 Vpp */
1146 .set_lock_led = dw210x_led_ctrl,
1149 static struct ds3000_config su3000_ds3000_config = {
1150 .demod_address = 0x68,
1152 .set_lock_led = dw210x_led_ctrl,
1155 static struct cxd2820r_config cxd2820r_config = {
1156 .i2c_address = 0x6c, /* (0xd8 >> 1) */
1161 static struct tda18271_config tda18271_config = {
1162 .output_opt = TDA18271_OUTPUT_LT_OFF,
1163 .gate = TDA18271_GATE_DIGITAL,
1166 static u8 m88rs2000_inittab[] = {
1167 DEMOD_WRITE, 0x9a, 0x30,
1168 DEMOD_WRITE, 0x00, 0x01,
1169 WRITE_DELAY, 0x19, 0x00,
1170 DEMOD_WRITE, 0x00, 0x00,
1171 DEMOD_WRITE, 0x9a, 0xb0,
1172 DEMOD_WRITE, 0x81, 0xc1,
1173 DEMOD_WRITE, 0x81, 0x81,
1174 DEMOD_WRITE, 0x86, 0xc6,
1175 DEMOD_WRITE, 0x9a, 0x30,
1176 DEMOD_WRITE, 0xf0, 0x80,
1177 DEMOD_WRITE, 0xf1, 0xbf,
1178 DEMOD_WRITE, 0xb0, 0x45,
1179 DEMOD_WRITE, 0xb2, 0x01,
1180 DEMOD_WRITE, 0x9a, 0xb0,
1184 static struct m88rs2000_config s421_m88rs2000_config = {
1186 .inittab = m88rs2000_inittab,
1189 static int dw2104_frontend_attach(struct dvb_usb_adapter *d)
1191 struct dvb_tuner_ops *tuner_ops = NULL;
1193 if (demod_probe & 4) {
1194 d->fe_adap[0].fe = dvb_attach(stv0900_attach, &dw2104a_stv0900_config,
1195 &d->dev->i2c_adap, 0);
1196 if (d->fe_adap[0].fe != NULL) {
1197 if (dvb_attach(stb6100_attach, d->fe_adap[0].fe,
1198 &dw2104a_stb6100_config,
1199 &d->dev->i2c_adap)) {
1200 tuner_ops = &d->fe_adap[0].fe->ops.tuner_ops;
1201 tuner_ops->set_frequency = stb6100_set_freq;
1202 tuner_ops->get_frequency = stb6100_get_freq;
1203 tuner_ops->set_bandwidth = stb6100_set_bandw;
1204 tuner_ops->get_bandwidth = stb6100_get_bandw;
1205 d->fe_adap[0].fe->ops.set_voltage = dw210x_set_voltage;
1206 info("Attached STV0900+STB6100!");
1212 if (demod_probe & 2) {
1213 d->fe_adap[0].fe = dvb_attach(stv0900_attach, &dw2104_stv0900_config,
1214 &d->dev->i2c_adap, 0);
1215 if (d->fe_adap[0].fe != NULL) {
1216 if (dvb_attach(stv6110_attach, d->fe_adap[0].fe,
1217 &dw2104_stv6110_config,
1218 &d->dev->i2c_adap)) {
1219 d->fe_adap[0].fe->ops.set_voltage = dw210x_set_voltage;
1220 info("Attached STV0900+STV6110A!");
1226 if (demod_probe & 1) {
1227 d->fe_adap[0].fe = dvb_attach(cx24116_attach, &dw2104_config,
1229 if (d->fe_adap[0].fe != NULL) {
1230 d->fe_adap[0].fe->ops.set_voltage = dw210x_set_voltage;
1231 info("Attached cx24116!");
1236 d->fe_adap[0].fe = dvb_attach(ds3000_attach, &dw2104_ds3000_config,
1238 if (d->fe_adap[0].fe != NULL) {
1239 dvb_attach(ts2020_attach, d->fe_adap[0].fe,
1240 &dw2104_ts2020_config, &d->dev->i2c_adap);
1241 d->fe_adap[0].fe->ops.set_voltage = dw210x_set_voltage;
1242 info("Attached DS3000!");
1249 static struct dvb_usb_device_properties dw2102_properties;
1250 static struct dvb_usb_device_properties dw2104_properties;
1251 static struct dvb_usb_device_properties s6x0_properties;
1253 static int dw2102_frontend_attach(struct dvb_usb_adapter *d)
1255 if (dw2102_properties.i2c_algo == &dw2102_serit_i2c_algo) {
1256 /*dw2102_properties.adapter->tuner_attach = NULL;*/
1257 d->fe_adap[0].fe = dvb_attach(si21xx_attach, &serit_sp1511lhb_config,
1259 if (d->fe_adap[0].fe != NULL) {
1260 d->fe_adap[0].fe->ops.set_voltage = dw210x_set_voltage;
1261 info("Attached si21xx!");
1266 if (dw2102_properties.i2c_algo == &dw2102_earda_i2c_algo) {
1267 d->fe_adap[0].fe = dvb_attach(stv0288_attach, &earda_config,
1269 if (d->fe_adap[0].fe != NULL) {
1270 if (dvb_attach(stb6000_attach, d->fe_adap[0].fe, 0x61,
1271 &d->dev->i2c_adap)) {
1272 d->fe_adap[0].fe->ops.set_voltage = dw210x_set_voltage;
1273 info("Attached stv0288!");
1279 if (dw2102_properties.i2c_algo == &dw2102_i2c_algo) {
1280 /*dw2102_properties.adapter->tuner_attach = dw2102_tuner_attach;*/
1281 d->fe_adap[0].fe = dvb_attach(stv0299_attach, &sharp_z0194a_config,
1283 if (d->fe_adap[0].fe != NULL) {
1284 d->fe_adap[0].fe->ops.set_voltage = dw210x_set_voltage;
1285 info("Attached stv0299!");
1292 static int dw3101_frontend_attach(struct dvb_usb_adapter *d)
1294 d->fe_adap[0].fe = dvb_attach(tda10023_attach, &dw3101_tda10023_config,
1295 &d->dev->i2c_adap, 0x48);
1296 if (d->fe_adap[0].fe != NULL) {
1297 info("Attached tda10023!");
1303 static int zl100313_frontend_attach(struct dvb_usb_adapter *d)
1305 d->fe_adap[0].fe = dvb_attach(mt312_attach, &zl313_config,
1307 if (d->fe_adap[0].fe != NULL) {
1308 if (dvb_attach(zl10039_attach, d->fe_adap[0].fe, 0x60,
1309 &d->dev->i2c_adap)) {
1310 d->fe_adap[0].fe->ops.set_voltage = dw210x_set_voltage;
1311 info("Attached zl100313+zl10039!");
1319 static int stv0288_frontend_attach(struct dvb_usb_adapter *d)
1323 d->fe_adap[0].fe = dvb_attach(stv0288_attach, &earda_config,
1326 if (d->fe_adap[0].fe == NULL)
1329 if (NULL == dvb_attach(stb6000_attach, d->fe_adap[0].fe, 0x61, &d->dev->i2c_adap))
1332 d->fe_adap[0].fe->ops.set_voltage = dw210x_set_voltage;
1334 dw210x_op_rw(d->dev->udev, 0x8a, 0, 0, obuf, 2, DW210X_WRITE_MSG);
1336 info("Attached stv0288+stb6000!");
1342 static int ds3000_frontend_attach(struct dvb_usb_adapter *d)
1344 struct dw2102_state *st = d->dev->priv;
1347 d->fe_adap[0].fe = dvb_attach(ds3000_attach, &s660_ds3000_config,
1350 if (d->fe_adap[0].fe == NULL)
1353 dvb_attach(ts2020_attach, d->fe_adap[0].fe, &s660_ts2020_config,
1356 st->old_set_voltage = d->fe_adap[0].fe->ops.set_voltage;
1357 d->fe_adap[0].fe->ops.set_voltage = s660_set_voltage;
1359 dw210x_op_rw(d->dev->udev, 0x8a, 0, 0, obuf, 2, DW210X_WRITE_MSG);
1361 info("Attached ds3000+ts2020!");
1366 static int prof_7500_frontend_attach(struct dvb_usb_adapter *d)
1370 d->fe_adap[0].fe = dvb_attach(stv0900_attach, &prof_7500_stv0900_config,
1371 &d->dev->i2c_adap, 0);
1372 if (d->fe_adap[0].fe == NULL)
1375 d->fe_adap[0].fe->ops.set_voltage = dw210x_set_voltage;
1377 dw210x_op_rw(d->dev->udev, 0x8a, 0, 0, obuf, 2, DW210X_WRITE_MSG);
1379 info("Attached STV0900+STB6100A!");
1384 static int su3000_frontend_attach(struct dvb_usb_adapter *adap)
1386 struct dvb_usb_device *d = adap->dev;
1387 struct dw2102_state *state = d->priv;
1389 mutex_lock(&d->data_mutex);
1391 state->data[0] = 0xe;
1392 state->data[1] = 0x80;
1395 if (dvb_usb_generic_rw(d, state->data, 3, state->data, 1, 0) < 0)
1396 err("command 0x0e transfer failed.");
1398 state->data[0] = 0xe;
1399 state->data[1] = 0x02;
1402 if (dvb_usb_generic_rw(d, state->data, 3, state->data, 1, 0) < 0)
1403 err("command 0x0e transfer failed.");
1406 state->data[0] = 0xe;
1407 state->data[1] = 0x83;
1410 if (dvb_usb_generic_rw(d, state->data, 3, state->data, 1, 0) < 0)
1411 err("command 0x0e transfer failed.");
1413 state->data[0] = 0xe;
1414 state->data[1] = 0x83;
1417 if (dvb_usb_generic_rw(d, state->data, 3, state->data, 1, 0) < 0)
1418 err("command 0x0e transfer failed.");
1420 state->data[0] = 0x51;
1422 if (dvb_usb_generic_rw(d, state->data, 1, state->data, 1, 0) < 0)
1423 err("command 0x51 transfer failed.");
1425 mutex_unlock(&d->data_mutex);
1427 adap->fe_adap[0].fe = dvb_attach(ds3000_attach, &su3000_ds3000_config,
1429 if (adap->fe_adap[0].fe == NULL)
1432 if (dvb_attach(ts2020_attach, adap->fe_adap[0].fe,
1433 &dw2104_ts2020_config,
1435 info("Attached DS3000/TS2020!");
1439 info("Failed to attach DS3000/TS2020!");
1443 static int t220_frontend_attach(struct dvb_usb_adapter *adap)
1445 struct dvb_usb_device *d = adap->dev;
1446 struct dw2102_state *state = d->priv;
1448 mutex_lock(&d->data_mutex);
1450 state->data[0] = 0xe;
1451 state->data[1] = 0x87;
1452 state->data[2] = 0x0;
1454 if (dvb_usb_generic_rw(d, state->data, 3, state->data, 1, 0) < 0)
1455 err("command 0x0e transfer failed.");
1457 state->data[0] = 0xe;
1458 state->data[1] = 0x86;
1461 if (dvb_usb_generic_rw(d, state->data, 3, state->data, 1, 0) < 0)
1462 err("command 0x0e transfer failed.");
1464 state->data[0] = 0xe;
1465 state->data[1] = 0x80;
1468 if (dvb_usb_generic_rw(d, state->data, 3, state->data, 1, 0) < 0)
1469 err("command 0x0e transfer failed.");
1473 state->data[0] = 0xe;
1474 state->data[1] = 0x80;
1477 if (dvb_usb_generic_rw(d, state->data, 3, state->data, 1, 0) < 0)
1478 err("command 0x0e transfer failed.");
1480 state->data[0] = 0x51;
1482 if (dvb_usb_generic_rw(d, state->data, 1, state->data, 1, 0) < 0)
1483 err("command 0x51 transfer failed.");
1485 mutex_unlock(&d->data_mutex);
1487 adap->fe_adap[0].fe = dvb_attach(cxd2820r_attach, &cxd2820r_config,
1488 &d->i2c_adap, NULL);
1489 if (adap->fe_adap[0].fe != NULL) {
1490 if (dvb_attach(tda18271_attach, adap->fe_adap[0].fe, 0x60,
1491 &d->i2c_adap, &tda18271_config)) {
1492 info("Attached TDA18271HD/CXD2820R!");
1497 info("Failed to attach TDA18271HD/CXD2820R!");
1501 static int m88rs2000_frontend_attach(struct dvb_usb_adapter *adap)
1503 struct dvb_usb_device *d = adap->dev;
1504 struct dw2102_state *state = d->priv;
1506 mutex_lock(&d->data_mutex);
1508 state->data[0] = 0x51;
1510 if (dvb_usb_generic_rw(d, state->data, 1, state->data, 1, 0) < 0)
1511 err("command 0x51 transfer failed.");
1513 mutex_unlock(&d->data_mutex);
1515 adap->fe_adap[0].fe = dvb_attach(m88rs2000_attach,
1516 &s421_m88rs2000_config,
1519 if (adap->fe_adap[0].fe == NULL)
1522 if (dvb_attach(ts2020_attach, adap->fe_adap[0].fe,
1523 &dw2104_ts2020_config,
1525 info("Attached RS2000/TS2020!");
1529 info("Failed to attach RS2000/TS2020!");
1533 static int tt_s2_4600_frontend_attach(struct dvb_usb_adapter *adap)
1535 struct dvb_usb_device *d = adap->dev;
1536 struct dw2102_state *state = d->priv;
1537 struct i2c_adapter *i2c_adapter;
1538 struct i2c_client *client;
1539 struct i2c_board_info board_info;
1540 struct m88ds3103_platform_data m88ds3103_pdata = {};
1541 struct ts2020_config ts2020_config = {};
1543 mutex_lock(&d->data_mutex);
1545 state->data[0] = 0xe;
1546 state->data[1] = 0x80;
1547 state->data[2] = 0x0;
1549 if (dvb_usb_generic_rw(d, state->data, 3, state->data, 1, 0) < 0)
1550 err("command 0x0e transfer failed.");
1552 state->data[0] = 0xe;
1553 state->data[1] = 0x02;
1556 if (dvb_usb_generic_rw(d, state->data, 3, state->data, 1, 0) < 0)
1557 err("command 0x0e transfer failed.");
1560 state->data[0] = 0xe;
1561 state->data[1] = 0x83;
1564 if (dvb_usb_generic_rw(d, state->data, 3, state->data, 1, 0) < 0)
1565 err("command 0x0e transfer failed.");
1567 state->data[0] = 0xe;
1568 state->data[1] = 0x83;
1571 if (dvb_usb_generic_rw(d, state->data, 3, state->data, 1, 0) < 0)
1572 err("command 0x0e transfer failed.");
1574 state->data[0] = 0x51;
1576 if (dvb_usb_generic_rw(d, state->data, 1, state->data, 1, 0) < 0)
1577 err("command 0x51 transfer failed.");
1579 mutex_unlock(&d->data_mutex);
1582 m88ds3103_pdata.clk = 27000000;
1583 m88ds3103_pdata.i2c_wr_max = 33;
1584 m88ds3103_pdata.ts_mode = M88DS3103_TS_CI;
1585 m88ds3103_pdata.ts_clk = 16000;
1586 m88ds3103_pdata.ts_clk_pol = 0;
1587 m88ds3103_pdata.spec_inv = 0;
1588 m88ds3103_pdata.agc = 0x99;
1589 m88ds3103_pdata.agc_inv = 0;
1590 m88ds3103_pdata.clk_out = M88DS3103_CLOCK_OUT_ENABLED;
1591 m88ds3103_pdata.envelope_mode = 0;
1592 m88ds3103_pdata.lnb_hv_pol = 1;
1593 m88ds3103_pdata.lnb_en_pol = 0;
1594 memset(&board_info, 0, sizeof(board_info));
1595 strlcpy(board_info.type, "m88ds3103", I2C_NAME_SIZE);
1596 board_info.addr = 0x68;
1597 board_info.platform_data = &m88ds3103_pdata;
1598 request_module("m88ds3103");
1599 client = i2c_new_device(&d->i2c_adap, &board_info);
1600 if (client == NULL || client->dev.driver == NULL)
1602 if (!try_module_get(client->dev.driver->owner)) {
1603 i2c_unregister_device(client);
1606 adap->fe_adap[0].fe = m88ds3103_pdata.get_dvb_frontend(client);
1607 i2c_adapter = m88ds3103_pdata.get_i2c_adapter(client);
1609 state->i2c_client_demod = client;
1612 ts2020_config.fe = adap->fe_adap[0].fe;
1613 memset(&board_info, 0, sizeof(board_info));
1614 strlcpy(board_info.type, "ts2022", I2C_NAME_SIZE);
1615 board_info.addr = 0x60;
1616 board_info.platform_data = &ts2020_config;
1617 request_module("ts2020");
1618 client = i2c_new_device(i2c_adapter, &board_info);
1620 if (client == NULL || client->dev.driver == NULL) {
1621 dvb_frontend_detach(adap->fe_adap[0].fe);
1625 if (!try_module_get(client->dev.driver->owner)) {
1626 i2c_unregister_device(client);
1627 dvb_frontend_detach(adap->fe_adap[0].fe);
1631 /* delegate signal strength measurement to tuner */
1632 adap->fe_adap[0].fe->ops.read_signal_strength =
1633 adap->fe_adap[0].fe->ops.tuner_ops.get_rf_strength;
1635 state->i2c_client_tuner = client;
1637 /* hook fe: need to resync the slave fifo when signal locks */
1638 state->fe_read_status = adap->fe_adap[0].fe->ops.read_status;
1639 adap->fe_adap[0].fe->ops.read_status = tt_s2_4600_read_status;
1641 state->last_lock = 0;
1646 static int dw2102_tuner_attach(struct dvb_usb_adapter *adap)
1648 dvb_attach(dvb_pll_attach, adap->fe_adap[0].fe, 0x60,
1649 &adap->dev->i2c_adap, DVB_PLL_OPERA1);
1653 static int dw3101_tuner_attach(struct dvb_usb_adapter *adap)
1655 dvb_attach(dvb_pll_attach, adap->fe_adap[0].fe, 0x60,
1656 &adap->dev->i2c_adap, DVB_PLL_TUA6034);
1661 static int dw2102_rc_query(struct dvb_usb_device *d)
1664 struct i2c_msg msg = {
1665 .addr = DW2102_RC_QUERY,
1671 if (d->props.i2c_algo->master_xfer(&d->i2c_adap, &msg, 1) == 1) {
1672 if (msg.buf[0] != 0xff) {
1673 deb_rc("%s: rc code: %x, %x\n",
1674 __func__, key[0], key[1]);
1675 rc_keydown(d->rc_dev, RC_TYPE_UNKNOWN, key[0], 0);
1682 static int prof_rc_query(struct dvb_usb_device *d)
1685 struct i2c_msg msg = {
1686 .addr = DW2102_RC_QUERY,
1692 if (d->props.i2c_algo->master_xfer(&d->i2c_adap, &msg, 1) == 1) {
1693 if (msg.buf[0] != 0xff) {
1694 deb_rc("%s: rc code: %x, %x\n",
1695 __func__, key[0], key[1]);
1696 rc_keydown(d->rc_dev, RC_TYPE_UNKNOWN, key[0]^0xff, 0);
1703 static int su3000_rc_query(struct dvb_usb_device *d)
1706 struct i2c_msg msg = {
1707 .addr = DW2102_RC_QUERY,
1713 if (d->props.i2c_algo->master_xfer(&d->i2c_adap, &msg, 1) == 1) {
1714 if (msg.buf[0] != 0xff) {
1715 deb_rc("%s: rc code: %x, %x\n",
1716 __func__, key[0], key[1]);
1717 rc_keydown(d->rc_dev, RC_TYPE_RC5,
1718 RC_SCANCODE_RC5(key[1], key[0]), 0);
1725 enum dw2102_table_entry {
1737 TERRATEC_CINERGY_S2,
1743 TERRATEC_CINERGY_S2_R2,
1744 TERRATEC_CINERGY_S2_R3,
1747 TECHNOTREND_S2_4600,
1750 TERRATEC_CINERGY_S2_BOX,
1754 static struct usb_device_id dw2102_table[] = {
1755 [CYPRESS_DW2102] = {USB_DEVICE(USB_VID_CYPRESS, USB_PID_DW2102)},
1756 [CYPRESS_DW2101] = {USB_DEVICE(USB_VID_CYPRESS, 0x2101)},
1757 [CYPRESS_DW2104] = {USB_DEVICE(USB_VID_CYPRESS, USB_PID_DW2104)},
1758 [TEVII_S650] = {USB_DEVICE(0x9022, USB_PID_TEVII_S650)},
1759 [TERRATEC_CINERGY_S] = {USB_DEVICE(USB_VID_TERRATEC, USB_PID_TERRATEC_CINERGY_S)},
1760 [CYPRESS_DW3101] = {USB_DEVICE(USB_VID_CYPRESS, USB_PID_DW3101)},
1761 [TEVII_S630] = {USB_DEVICE(0x9022, USB_PID_TEVII_S630)},
1762 [PROF_1100] = {USB_DEVICE(0x3011, USB_PID_PROF_1100)},
1763 [TEVII_S660] = {USB_DEVICE(0x9022, USB_PID_TEVII_S660)},
1764 [PROF_7500] = {USB_DEVICE(0x3034, 0x7500)},
1765 [GENIATECH_SU3000] = {USB_DEVICE(0x1f4d, 0x3000)},
1766 [TERRATEC_CINERGY_S2] = {USB_DEVICE(USB_VID_TERRATEC, USB_PID_TERRATEC_CINERGY_S2_R1)},
1767 [TEVII_S480_1] = {USB_DEVICE(0x9022, USB_PID_TEVII_S480_1)},
1768 [TEVII_S480_2] = {USB_DEVICE(0x9022, USB_PID_TEVII_S480_2)},
1769 [X3M_SPC1400HD] = {USB_DEVICE(0x1f4d, 0x3100)},
1770 [TEVII_S421] = {USB_DEVICE(0x9022, USB_PID_TEVII_S421)},
1771 [TEVII_S632] = {USB_DEVICE(0x9022, USB_PID_TEVII_S632)},
1772 [TERRATEC_CINERGY_S2_R2] = {USB_DEVICE(USB_VID_TERRATEC, USB_PID_TERRATEC_CINERGY_S2_R2)},
1773 [TERRATEC_CINERGY_S2_R3] = {USB_DEVICE(USB_VID_TERRATEC, USB_PID_TERRATEC_CINERGY_S2_R3)},
1774 [GOTVIEW_SAT_HD] = {USB_DEVICE(0x1FE1, USB_PID_GOTVIEW_SAT_HD)},
1775 [GENIATECH_T220] = {USB_DEVICE(0x1f4d, 0xD220)},
1776 [TECHNOTREND_S2_4600] = {USB_DEVICE(USB_VID_TECHNOTREND,
1777 USB_PID_TECHNOTREND_CONNECT_S2_4600)},
1778 [TEVII_S482_1] = {USB_DEVICE(0x9022, 0xd483)},
1779 [TEVII_S482_2] = {USB_DEVICE(0x9022, 0xd484)},
1780 [TERRATEC_CINERGY_S2_BOX] = {USB_DEVICE(USB_VID_TERRATEC, 0x0105)},
1781 [TEVII_S662] = {USB_DEVICE(0x9022, USB_PID_TEVII_S662)},
1785 MODULE_DEVICE_TABLE(usb, dw2102_table);
1787 static int dw2102_load_firmware(struct usb_device *dev,
1788 const struct firmware *frmwr)
1793 u8 reset16[] = {0, 0, 0, 0, 0, 0, 0};
1794 const struct firmware *fw;
1796 switch (le16_to_cpu(dev->descriptor.idProduct)) {
1798 ret = reject_firmware(&fw, DW2101_FIRMWARE, &dev->dev);
1800 err(err_str, DW2101_FIRMWARE);
1808 info("start downloading DW210X firmware");
1809 p = kmalloc(fw->size, GFP_KERNEL);
1812 dw210x_op_rw(dev, 0xa0, 0x7f92, 0, &reset, 1, DW210X_WRITE_MSG);
1813 dw210x_op_rw(dev, 0xa0, 0xe600, 0, &reset, 1, DW210X_WRITE_MSG);
1816 memcpy(p, fw->data, fw->size);
1817 for (i = 0; i < fw->size; i += 0x40) {
1819 if (dw210x_op_rw(dev, 0xa0, i, 0, b , 0x40,
1820 DW210X_WRITE_MSG) != 0x40) {
1821 err("error while transferring firmware");
1826 /* restart the CPU */
1828 if (ret || dw210x_op_rw(dev, 0xa0, 0x7f92, 0, &reset, 1,
1829 DW210X_WRITE_MSG) != 1) {
1830 err("could not restart the USB controller CPU.");
1833 if (ret || dw210x_op_rw(dev, 0xa0, 0xe600, 0, &reset, 1,
1834 DW210X_WRITE_MSG) != 1) {
1835 err("could not restart the USB controller CPU.");
1838 /* init registers */
1839 switch (le16_to_cpu(dev->descriptor.idProduct)) {
1840 case USB_PID_TEVII_S650:
1841 dw2104_properties.rc.core.rc_codes = RC_MAP_TEVII_NEC;
1842 case USB_PID_DW2104:
1844 dw210x_op_rw(dev, 0xc4, 0x0000, 0, &reset, 1,
1846 /* break omitted intentionally */
1847 case USB_PID_DW3101:
1849 dw210x_op_rw(dev, 0xbf, 0x0040, 0, &reset, 0,
1852 case USB_PID_TERRATEC_CINERGY_S:
1853 case USB_PID_DW2102:
1854 dw210x_op_rw(dev, 0xbf, 0x0040, 0, &reset, 0,
1856 dw210x_op_rw(dev, 0xb9, 0x0000, 0, &reset16[0], 2,
1858 /* check STV0299 frontend */
1859 dw210x_op_rw(dev, 0xb5, 0, 0, &reset16[0], 2,
1861 if ((reset16[0] == 0xa1) || (reset16[0] == 0x80)) {
1862 dw2102_properties.i2c_algo = &dw2102_i2c_algo;
1863 dw2102_properties.adapter->fe[0].tuner_attach = &dw2102_tuner_attach;
1866 /* check STV0288 frontend */
1870 dw210x_op_rw(dev, 0xc2, 0, 0, &reset16[0], 3,
1872 dw210x_op_rw(dev, 0xc3, 0xd1, 0, &reset16[0], 3,
1874 if (reset16[2] == 0x11) {
1875 dw2102_properties.i2c_algo = &dw2102_earda_i2c_algo;
1880 dw210x_op_rw(dev, 0xbc, 0x0030, 0, &reset16[0], 2,
1882 dw210x_op_rw(dev, 0xba, 0x0000, 0, &reset16[0], 7,
1884 dw210x_op_rw(dev, 0xba, 0x0000, 0, &reset16[0], 7,
1886 dw210x_op_rw(dev, 0xb9, 0x0000, 0, &reset16[0], 2,
1895 if (le16_to_cpu(dev->descriptor.idProduct) == 0x2101)
1896 release_firmware(fw);
1900 static struct dvb_usb_device_properties dw2102_properties = {
1901 .caps = DVB_USB_IS_AN_I2C_ADAPTER,
1902 .usb_ctrl = DEVICE_SPECIFIC,
1903 .firmware = DW2102_FIRMWARE,
1906 .i2c_algo = &dw2102_serit_i2c_algo,
1910 .rc_codes = RC_MAP_DM1105_NEC,
1911 .module_name = "dw2102",
1912 .allowed_protos = RC_BIT_NEC,
1913 .rc_query = dw2102_rc_query,
1916 .generic_bulk_ctrl_endpoint = 0x81,
1917 /* parameter for the MPEG2-data transfer */
1919 .download_firmware = dw2102_load_firmware,
1920 .read_mac_address = dw210x_read_mac_address,
1925 .frontend_attach = dw2102_frontend_attach,
1939 .num_device_descs = 3,
1941 {"DVBWorld DVB-S 2102 USB2.0",
1942 {&dw2102_table[CYPRESS_DW2102], NULL},
1945 {"DVBWorld DVB-S 2101 USB2.0",
1946 {&dw2102_table[CYPRESS_DW2101], NULL},
1949 {"TerraTec Cinergy S USB",
1950 {&dw2102_table[TERRATEC_CINERGY_S], NULL},
1956 static struct dvb_usb_device_properties dw2104_properties = {
1957 .caps = DVB_USB_IS_AN_I2C_ADAPTER,
1958 .usb_ctrl = DEVICE_SPECIFIC,
1959 .firmware = DW2104_FIRMWARE,
1962 .i2c_algo = &dw2104_i2c_algo,
1965 .rc_codes = RC_MAP_DM1105_NEC,
1966 .module_name = "dw2102",
1967 .allowed_protos = RC_BIT_NEC,
1968 .rc_query = dw2102_rc_query,
1971 .generic_bulk_ctrl_endpoint = 0x81,
1972 /* parameter for the MPEG2-data transfer */
1974 .download_firmware = dw2102_load_firmware,
1975 .read_mac_address = dw210x_read_mac_address,
1980 .frontend_attach = dw2104_frontend_attach,
1994 .num_device_descs = 2,
1996 { "DVBWorld DW2104 USB2.0",
1997 {&dw2102_table[CYPRESS_DW2104], NULL},
2000 { "TeVii S650 USB2.0",
2001 {&dw2102_table[TEVII_S650], NULL},
2007 static struct dvb_usb_device_properties dw3101_properties = {
2008 .caps = DVB_USB_IS_AN_I2C_ADAPTER,
2009 .usb_ctrl = DEVICE_SPECIFIC,
2010 .firmware = DW3101_FIRMWARE,
2013 .i2c_algo = &dw3101_i2c_algo,
2016 .rc_codes = RC_MAP_DM1105_NEC,
2017 .module_name = "dw2102",
2018 .allowed_protos = RC_BIT_NEC,
2019 .rc_query = dw2102_rc_query,
2022 .generic_bulk_ctrl_endpoint = 0x81,
2023 /* parameter for the MPEG2-data transfer */
2025 .download_firmware = dw2102_load_firmware,
2026 .read_mac_address = dw210x_read_mac_address,
2031 .frontend_attach = dw3101_frontend_attach,
2032 .tuner_attach = dw3101_tuner_attach,
2046 .num_device_descs = 1,
2048 { "DVBWorld DVB-C 3101 USB2.0",
2049 {&dw2102_table[CYPRESS_DW3101], NULL},
2055 static struct dvb_usb_device_properties s6x0_properties = {
2056 .caps = DVB_USB_IS_AN_I2C_ADAPTER,
2057 .usb_ctrl = DEVICE_SPECIFIC,
2058 .size_of_priv = sizeof(struct dw2102_state),
2059 .firmware = S630_FIRMWARE,
2062 .i2c_algo = &s6x0_i2c_algo,
2065 .rc_codes = RC_MAP_TEVII_NEC,
2066 .module_name = "dw2102",
2067 .allowed_protos = RC_BIT_NEC,
2068 .rc_query = dw2102_rc_query,
2071 .generic_bulk_ctrl_endpoint = 0x81,
2073 .download_firmware = dw2102_load_firmware,
2074 .read_mac_address = s6x0_read_mac_address,
2079 .frontend_attach = zl100313_frontend_attach,
2093 .num_device_descs = 1,
2096 {&dw2102_table[TEVII_S630], NULL},
2102 static struct dvb_usb_device_properties *p1100;
2103 static struct dvb_usb_device_description d1100 = {
2105 {&dw2102_table[PROF_1100], NULL},
2109 static struct dvb_usb_device_properties *s660;
2110 static struct dvb_usb_device_description d660 = {
2112 {&dw2102_table[TEVII_S660], NULL},
2116 static struct dvb_usb_device_description d480_1 = {
2118 {&dw2102_table[TEVII_S480_1], NULL},
2122 static struct dvb_usb_device_description d480_2 = {
2124 {&dw2102_table[TEVII_S480_2], NULL},
2128 static struct dvb_usb_device_properties *p7500;
2129 static struct dvb_usb_device_description d7500 = {
2130 "Prof 7500 USB DVB-S2",
2131 {&dw2102_table[PROF_7500], NULL},
2135 static struct dvb_usb_device_properties *s421;
2136 static struct dvb_usb_device_description d421 = {
2138 {&dw2102_table[TEVII_S421], NULL},
2142 static struct dvb_usb_device_description d632 = {
2144 {&dw2102_table[TEVII_S632], NULL},
2148 static struct dvb_usb_device_properties su3000_properties = {
2149 .caps = DVB_USB_IS_AN_I2C_ADAPTER,
2150 .usb_ctrl = DEVICE_SPECIFIC,
2151 .size_of_priv = sizeof(struct dw2102_state),
2152 .power_ctrl = su3000_power_ctrl,
2154 .identify_state = su3000_identify_state,
2155 .i2c_algo = &su3000_i2c_algo,
2159 .rc_codes = RC_MAP_SU3000,
2160 .module_name = "dw2102",
2161 .allowed_protos = RC_BIT_RC5,
2162 .rc_query = su3000_rc_query,
2165 .read_mac_address = su3000_read_mac_address,
2167 .generic_bulk_ctrl_endpoint = 0x01,
2173 .streaming_ctrl = su3000_streaming_ctrl,
2174 .frontend_attach = su3000_frontend_attach,
2188 .num_device_descs = 6,
2190 { "SU3000HD DVB-S USB2.0",
2191 { &dw2102_table[GENIATECH_SU3000], NULL },
2194 { "Terratec Cinergy S2 USB HD",
2195 { &dw2102_table[TERRATEC_CINERGY_S2], NULL },
2198 { "X3M TV SPC1400HD PCI",
2199 { &dw2102_table[X3M_SPC1400HD], NULL },
2202 { "Terratec Cinergy S2 USB HD Rev.2",
2203 { &dw2102_table[TERRATEC_CINERGY_S2_R2], NULL },
2206 { "Terratec Cinergy S2 USB HD Rev.3",
2207 { &dw2102_table[TERRATEC_CINERGY_S2_R3], NULL },
2210 { "GOTVIEW Satellite HD",
2211 { &dw2102_table[GOTVIEW_SAT_HD], NULL },
2217 static struct dvb_usb_device_properties t220_properties = {
2218 .caps = DVB_USB_IS_AN_I2C_ADAPTER,
2219 .usb_ctrl = DEVICE_SPECIFIC,
2220 .size_of_priv = sizeof(struct dw2102_state),
2221 .power_ctrl = su3000_power_ctrl,
2223 .identify_state = su3000_identify_state,
2224 .i2c_algo = &su3000_i2c_algo,
2228 .rc_codes = RC_MAP_SU3000,
2229 .module_name = "dw2102",
2230 .allowed_protos = RC_BIT_RC5,
2231 .rc_query = su3000_rc_query,
2234 .read_mac_address = su3000_read_mac_address,
2236 .generic_bulk_ctrl_endpoint = 0x01,
2242 .streaming_ctrl = su3000_streaming_ctrl,
2243 .frontend_attach = t220_frontend_attach,
2257 .num_device_descs = 1,
2259 { "Geniatech T220 DVB-T/T2 USB2.0",
2260 { &dw2102_table[GENIATECH_T220], NULL },
2266 static struct dvb_usb_device_properties tt_s2_4600_properties = {
2267 .caps = DVB_USB_IS_AN_I2C_ADAPTER,
2268 .usb_ctrl = DEVICE_SPECIFIC,
2269 .size_of_priv = sizeof(struct dw2102_state),
2270 .power_ctrl = su3000_power_ctrl,
2272 .identify_state = su3000_identify_state,
2273 .i2c_algo = &su3000_i2c_algo,
2277 .rc_codes = RC_MAP_TT_1500,
2278 .module_name = "dw2102",
2279 .allowed_protos = RC_BIT_RC5,
2280 .rc_query = su3000_rc_query,
2283 .read_mac_address = su3000_read_mac_address,
2285 .generic_bulk_ctrl_endpoint = 0x01,
2291 .streaming_ctrl = su3000_streaming_ctrl,
2292 .frontend_attach = tt_s2_4600_frontend_attach,
2306 .num_device_descs = 5,
2308 { "TechnoTrend TT-connect S2-4600",
2309 { &dw2102_table[TECHNOTREND_S2_4600], NULL },
2312 { "TeVii S482 (tuner 1)",
2313 { &dw2102_table[TEVII_S482_1], NULL },
2316 { "TeVii S482 (tuner 2)",
2317 { &dw2102_table[TEVII_S482_2], NULL },
2320 { "Terratec Cinergy S2 USB BOX",
2321 { &dw2102_table[TERRATEC_CINERGY_S2_BOX], NULL },
2325 { &dw2102_table[TEVII_S662], NULL },
2331 static int dw2102_probe(struct usb_interface *intf,
2332 const struct usb_device_id *id)
2334 p1100 = kmemdup(&s6x0_properties,
2335 sizeof(struct dvb_usb_device_properties), GFP_KERNEL);
2338 /* copy default structure */
2339 /* fill only different fields */
2340 p1100->firmware = P1100_FIRMWARE;
2341 p1100->devices[0] = d1100;
2342 p1100->rc.core.rc_query = prof_rc_query;
2343 p1100->rc.core.rc_codes = RC_MAP_TBS_NEC;
2344 p1100->adapter->fe[0].frontend_attach = stv0288_frontend_attach;
2346 s660 = kmemdup(&s6x0_properties,
2347 sizeof(struct dvb_usb_device_properties), GFP_KERNEL);
2352 s660->firmware = S660_FIRMWARE;
2353 s660->num_device_descs = 3;
2354 s660->devices[0] = d660;
2355 s660->devices[1] = d480_1;
2356 s660->devices[2] = d480_2;
2357 s660->adapter->fe[0].frontend_attach = ds3000_frontend_attach;
2359 p7500 = kmemdup(&s6x0_properties,
2360 sizeof(struct dvb_usb_device_properties), GFP_KERNEL);
2366 p7500->firmware = P7500_FIRMWARE;
2367 p7500->devices[0] = d7500;
2368 p7500->rc.core.rc_query = prof_rc_query;
2369 p7500->rc.core.rc_codes = RC_MAP_TBS_NEC;
2370 p7500->adapter->fe[0].frontend_attach = prof_7500_frontend_attach;
2373 s421 = kmemdup(&su3000_properties,
2374 sizeof(struct dvb_usb_device_properties), GFP_KERNEL);
2381 s421->num_device_descs = 2;
2382 s421->devices[0] = d421;
2383 s421->devices[1] = d632;
2384 s421->adapter->fe[0].frontend_attach = m88rs2000_frontend_attach;
2386 if (0 == dvb_usb_device_init(intf, &dw2102_properties,
2387 THIS_MODULE, NULL, adapter_nr) ||
2388 0 == dvb_usb_device_init(intf, &dw2104_properties,
2389 THIS_MODULE, NULL, adapter_nr) ||
2390 0 == dvb_usb_device_init(intf, &dw3101_properties,
2391 THIS_MODULE, NULL, adapter_nr) ||
2392 0 == dvb_usb_device_init(intf, &s6x0_properties,
2393 THIS_MODULE, NULL, adapter_nr) ||
2394 0 == dvb_usb_device_init(intf, p1100,
2395 THIS_MODULE, NULL, adapter_nr) ||
2396 0 == dvb_usb_device_init(intf, s660,
2397 THIS_MODULE, NULL, adapter_nr) ||
2398 0 == dvb_usb_device_init(intf, p7500,
2399 THIS_MODULE, NULL, adapter_nr) ||
2400 0 == dvb_usb_device_init(intf, s421,
2401 THIS_MODULE, NULL, adapter_nr) ||
2402 0 == dvb_usb_device_init(intf, &su3000_properties,
2403 THIS_MODULE, NULL, adapter_nr) ||
2404 0 == dvb_usb_device_init(intf, &t220_properties,
2405 THIS_MODULE, NULL, adapter_nr) ||
2406 0 == dvb_usb_device_init(intf, &tt_s2_4600_properties,
2407 THIS_MODULE, NULL, adapter_nr))
2413 static void dw2102_disconnect(struct usb_interface *intf)
2415 struct dvb_usb_device *d = usb_get_intfdata(intf);
2416 struct dw2102_state *st = (struct dw2102_state *)d->priv;
2417 struct i2c_client *client;
2419 /* remove I2C client for tuner */
2420 client = st->i2c_client_tuner;
2422 module_put(client->dev.driver->owner);
2423 i2c_unregister_device(client);
2426 /* remove I2C client for demodulator */
2427 client = st->i2c_client_demod;
2429 module_put(client->dev.driver->owner);
2430 i2c_unregister_device(client);
2433 dvb_usb_device_exit(intf);
2436 static struct usb_driver dw2102_driver = {
2438 .probe = dw2102_probe,
2439 .disconnect = dw2102_disconnect,
2440 .id_table = dw2102_table,
2443 module_usb_driver(dw2102_driver);
2445 MODULE_AUTHOR("Igor M. Liplianin (c) liplianin@me.by");
2446 MODULE_DESCRIPTION("Driver for DVBWorld DVB-S 2101, 2102, DVB-S2 2104,"
2447 " DVB-C 3101 USB2.0,"
2448 " TeVii S421, S480, S482, S600, S630, S632, S650,"
2449 " TeVii S660, S662, Prof 1100, 7500 USB2.0,"
2450 " Geniatech SU3000, T220,"
2451 " TechnoTrend S2-4600, Terratec Cinergy S2 devices");
2452 MODULE_VERSION("0.1");
2453 MODULE_LICENSE("GPL");