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 <media/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 "dvb-usb-dw2101.fw"
56 #define DW2102_FIRMWARE "dvb-usb-dw2102.fw"
57 #define DW2104_FIRMWARE "dvb-usb-dw2104.fw"
58 #define DW3101_FIRMWARE "dvb-usb-dw3101.fw"
59 #define S630_FIRMWARE "dvb-usb-s630.fw"
60 #define S660_FIRMWARE "dvb-usb-s660.fw"
61 #define P1100_FIRMWARE "dvb-usb-p1100.fw"
62 #define P7500_FIRMWARE "dvb-usb-p7500.fw"
64 #define err_str "did not find the firmware file '%s'. You can use <kernel_dir>/scripts/get_dvb_firmware to get the firmware"
69 u8 data[MAX_XFER_SIZE + 4];
70 struct i2c_client *i2c_client_demod;
71 struct i2c_client *i2c_client_tuner;
73 /* fe hook functions*/
74 int (*old_set_voltage)(struct dvb_frontend *f, enum fe_sec_voltage v);
75 int (*fe_read_status)(struct dvb_frontend *fe,
76 enum fe_status *status);
80 static int dvb_usb_dw2102_debug;
81 module_param_named(debug, dvb_usb_dw2102_debug, int, 0644);
82 MODULE_PARM_DESC(debug, "set debugging level (1=info 2=xfer 4=rc(or-able))."
83 DVB_USB_DEBUG_STATUS);
86 static int demod_probe = 1;
87 module_param_named(demod, demod_probe, int, 0644);
88 MODULE_PARM_DESC(demod, "demod to probe (1=cx24116 2=stv0903+stv6110 4=stv0903+stb6100(or-able)).");
90 DVB_DEFINE_MOD_OPT_ADAPTER_NR(adapter_nr);
92 static int dw210x_op_rw(struct usb_device *dev, u8 request, u16 value,
93 u16 index, u8 * data, u16 len, int flags)
97 unsigned int pipe = (flags == DW210X_READ_MSG) ?
98 usb_rcvctrlpipe(dev, 0) : usb_sndctrlpipe(dev, 0);
99 u8 request_type = (flags == DW210X_READ_MSG) ? USB_DIR_IN : USB_DIR_OUT;
101 u8buf = kmalloc(len, GFP_KERNEL);
106 if (flags == DW210X_WRITE_MSG)
107 memcpy(u8buf, data, len);
108 ret = usb_control_msg(dev, pipe, request, request_type | USB_TYPE_VENDOR,
109 value, index , u8buf, len, 2000);
111 if (flags == DW210X_READ_MSG)
112 memcpy(data, u8buf, len);
119 static int dw2102_i2c_transfer(struct i2c_adapter *adap, struct i2c_msg msg[],
122 struct dvb_usb_device *d = i2c_get_adapdata(adap);
124 u8 buf6[] = {0x2c, 0x05, 0xc0, 0, 0, 0, 0};
129 if (mutex_lock_interruptible(&d->i2c_mutex) < 0)
134 /* read stv0299 register */
135 value = msg[0].buf[0];/* register */
136 for (i = 0; i < msg[1].len; i++) {
137 dw210x_op_rw(d->udev, 0xb5, value + i, 0,
138 buf6, 2, DW210X_READ_MSG);
139 msg[1].buf[i] = buf6[0];
143 switch (msg[0].addr) {
145 /* write to stv0299 register */
147 buf6[1] = msg[0].buf[0];
148 buf6[2] = msg[0].buf[1];
149 dw210x_op_rw(d->udev, 0xb2, 0, 0,
150 buf6, 3, DW210X_WRITE_MSG);
153 if (msg[0].flags == 0) {
154 /* write to tuner pll */
158 buf6[3] = msg[0].buf[0];
159 buf6[4] = msg[0].buf[1];
160 buf6[5] = msg[0].buf[2];
161 buf6[6] = msg[0].buf[3];
162 dw210x_op_rw(d->udev, 0xb2, 0, 0,
163 buf6, 7, DW210X_WRITE_MSG);
165 /* read from tuner */
166 dw210x_op_rw(d->udev, 0xb5, 0, 0,
167 buf6, 1, DW210X_READ_MSG);
168 msg[0].buf[0] = buf6[0];
171 case (DW2102_RC_QUERY):
172 dw210x_op_rw(d->udev, 0xb8, 0, 0,
173 buf6, 2, DW210X_READ_MSG);
174 msg[0].buf[0] = buf6[0];
175 msg[0].buf[1] = buf6[1];
177 case (DW2102_VOLTAGE_CTRL):
179 buf6[1] = msg[0].buf[0];
180 dw210x_op_rw(d->udev, 0xb2, 0, 0,
181 buf6, 2, DW210X_WRITE_MSG);
188 mutex_unlock(&d->i2c_mutex);
192 static int dw2102_serit_i2c_transfer(struct i2c_adapter *adap,
193 struct i2c_msg msg[], int num)
195 struct dvb_usb_device *d = i2c_get_adapdata(adap);
196 u8 buf6[] = {0, 0, 0, 0, 0, 0, 0};
200 if (mutex_lock_interruptible(&d->i2c_mutex) < 0)
205 if (msg[0].len != 1) {
206 warn("i2c rd: len=%d is not 1!\n",
212 if (2 + msg[1].len > sizeof(buf6)) {
213 warn("i2c rd: len=%d is too big!\n",
219 /* read si2109 register by number */
220 buf6[0] = msg[0].addr << 1;
221 buf6[1] = msg[0].len;
222 buf6[2] = msg[0].buf[0];
223 dw210x_op_rw(d->udev, 0xc2, 0, 0,
224 buf6, msg[0].len + 2, DW210X_WRITE_MSG);
225 /* read si2109 register */
226 dw210x_op_rw(d->udev, 0xc3, 0xd0, 0,
227 buf6, msg[1].len + 2, DW210X_READ_MSG);
228 memcpy(msg[1].buf, buf6 + 2, msg[1].len);
232 switch (msg[0].addr) {
234 if (2 + msg[0].len > sizeof(buf6)) {
235 warn("i2c wr: len=%d is too big!\n",
241 /* write to si2109 register */
242 buf6[0] = msg[0].addr << 1;
243 buf6[1] = msg[0].len;
244 memcpy(buf6 + 2, msg[0].buf, msg[0].len);
245 dw210x_op_rw(d->udev, 0xc2, 0, 0, buf6,
246 msg[0].len + 2, DW210X_WRITE_MSG);
248 case(DW2102_RC_QUERY):
249 dw210x_op_rw(d->udev, 0xb8, 0, 0,
250 buf6, 2, DW210X_READ_MSG);
251 msg[0].buf[0] = buf6[0];
252 msg[0].buf[1] = buf6[1];
254 case(DW2102_VOLTAGE_CTRL):
256 buf6[1] = msg[0].buf[0];
257 dw210x_op_rw(d->udev, 0xb2, 0, 0,
258 buf6, 2, DW210X_WRITE_MSG);
264 mutex_unlock(&d->i2c_mutex);
268 static int dw2102_earda_i2c_transfer(struct i2c_adapter *adap, struct i2c_msg msg[], int num)
270 struct dvb_usb_device *d = i2c_get_adapdata(adap);
275 if (mutex_lock_interruptible(&d->i2c_mutex) < 0)
281 /* first write first register number */
282 u8 ibuf[MAX_XFER_SIZE], obuf[3];
284 if (2 + msg[0].len != sizeof(obuf)) {
285 warn("i2c rd: len=%d is not 1!\n",
291 if (2 + msg[1].len > sizeof(ibuf)) {
292 warn("i2c rd: len=%d is too big!\n",
298 obuf[0] = msg[0].addr << 1;
299 obuf[1] = msg[0].len;
300 obuf[2] = msg[0].buf[0];
301 dw210x_op_rw(d->udev, 0xc2, 0, 0,
302 obuf, msg[0].len + 2, DW210X_WRITE_MSG);
303 /* second read registers */
304 dw210x_op_rw(d->udev, 0xc3, 0xd1 , 0,
305 ibuf, msg[1].len + 2, DW210X_READ_MSG);
306 memcpy(msg[1].buf, ibuf + 2, msg[1].len);
311 switch (msg[0].addr) {
313 /* write to register */
314 u8 obuf[MAX_XFER_SIZE];
316 if (2 + msg[0].len > sizeof(obuf)) {
317 warn("i2c wr: len=%d is too big!\n",
323 obuf[0] = msg[0].addr << 1;
324 obuf[1] = msg[0].len;
325 memcpy(obuf + 2, msg[0].buf, msg[0].len);
326 dw210x_op_rw(d->udev, 0xc2, 0, 0,
327 obuf, msg[0].len + 2, DW210X_WRITE_MSG);
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);
348 case(DW2102_RC_QUERY): {
350 dw210x_op_rw(d->udev, 0xb8, 0, 0,
351 ibuf, 2, DW210X_READ_MSG);
352 memcpy(msg[0].buf, ibuf , 2);
355 case(DW2102_VOLTAGE_CTRL): {
358 obuf[1] = msg[0].buf[0];
359 dw210x_op_rw(d->udev, 0xb2, 0, 0,
360 obuf, 2, DW210X_WRITE_MSG);
370 mutex_unlock(&d->i2c_mutex);
374 static int dw2104_i2c_transfer(struct i2c_adapter *adap, struct i2c_msg msg[], int num)
376 struct dvb_usb_device *d = i2c_get_adapdata(adap);
381 if (mutex_lock_interruptible(&d->i2c_mutex) < 0)
384 for (j = 0; j < num; j++) {
385 switch (msg[j].addr) {
386 case(DW2102_RC_QUERY): {
388 dw210x_op_rw(d->udev, 0xb8, 0, 0,
389 ibuf, 2, DW210X_READ_MSG);
390 memcpy(msg[j].buf, ibuf , 2);
393 case(DW2102_VOLTAGE_CTRL): {
396 obuf[1] = msg[j].buf[0];
397 dw210x_op_rw(d->udev, 0xb2, 0, 0,
398 obuf, 2, DW210X_WRITE_MSG);
403 case 0x68: ds3000, stv0903
404 case 0x60: ts2020, stv6110, stb6100 */
406 if (msg[j].flags == I2C_M_RD) {
408 u8 ibuf[MAX_XFER_SIZE];
410 if (2 + msg[j].len > sizeof(ibuf)) {
411 warn("i2c rd: len=%d is too big!\n",
417 dw210x_op_rw(d->udev, 0xc3,
418 (msg[j].addr << 1) + 1, 0,
419 ibuf, msg[j].len + 2,
421 memcpy(msg[j].buf, ibuf + 2, msg[j].len);
423 } else if (((msg[j].buf[0] == 0xb0) &&
424 (msg[j].addr == 0x68)) ||
425 ((msg[j].buf[0] == 0xf7) &&
426 (msg[j].addr == 0x55))) {
429 obuf[0] = msg[j].addr << 1;
430 obuf[1] = (msg[j].len > 15 ? 17 : msg[j].len);
431 obuf[2] = msg[j].buf[0];
432 len = msg[j].len - 1;
435 memcpy(obuf + 3, msg[j].buf + i,
436 (len > 16 ? 16 : len));
437 dw210x_op_rw(d->udev, 0xc2, 0, 0,
438 obuf, (len > 16 ? 16 : len) + 3,
444 /* write registers */
445 u8 obuf[MAX_XFER_SIZE];
447 if (2 + msg[j].len > sizeof(obuf)) {
448 warn("i2c wr: len=%d is too big!\n",
454 obuf[0] = msg[j].addr << 1;
455 obuf[1] = msg[j].len;
456 memcpy(obuf + 2, msg[j].buf, msg[j].len);
457 dw210x_op_rw(d->udev, 0xc2, 0, 0,
458 obuf, msg[j].len + 2,
469 mutex_unlock(&d->i2c_mutex);
473 static int dw3101_i2c_transfer(struct i2c_adapter *adap, struct i2c_msg msg[],
476 struct dvb_usb_device *d = i2c_get_adapdata(adap);
482 if (mutex_lock_interruptible(&d->i2c_mutex) < 0)
488 /* first write first register number */
489 u8 ibuf[MAX_XFER_SIZE], obuf[3];
491 if (2 + msg[0].len != sizeof(obuf)) {
492 warn("i2c rd: len=%d is not 1!\n",
497 if (2 + msg[1].len > sizeof(ibuf)) {
498 warn("i2c rd: len=%d is too big!\n",
503 obuf[0] = msg[0].addr << 1;
504 obuf[1] = msg[0].len;
505 obuf[2] = msg[0].buf[0];
506 dw210x_op_rw(d->udev, 0xc2, 0, 0,
507 obuf, msg[0].len + 2, DW210X_WRITE_MSG);
508 /* second read registers */
509 dw210x_op_rw(d->udev, 0xc3, 0x19 , 0,
510 ibuf, msg[1].len + 2, DW210X_READ_MSG);
511 memcpy(msg[1].buf, ibuf + 2, msg[1].len);
516 switch (msg[0].addr) {
519 /* write to register */
520 u8 obuf[MAX_XFER_SIZE];
522 if (2 + msg[0].len > sizeof(obuf)) {
523 warn("i2c wr: len=%d is too big!\n",
528 obuf[0] = msg[0].addr << 1;
529 obuf[1] = msg[0].len;
530 memcpy(obuf + 2, msg[0].buf, msg[0].len);
531 dw210x_op_rw(d->udev, 0xc2, 0, 0,
532 obuf, msg[0].len + 2, DW210X_WRITE_MSG);
535 case(DW2102_RC_QUERY): {
537 dw210x_op_rw(d->udev, 0xb8, 0, 0,
538 ibuf, 2, DW210X_READ_MSG);
539 memcpy(msg[0].buf, ibuf , 2);
547 for (i = 0; i < num; i++) {
548 deb_xfer("%02x:%02x: %s ", i, msg[i].addr,
549 msg[i].flags == 0 ? ">>>" : "<<<");
550 debug_dump(msg[i].buf, msg[i].len, deb_xfer);
555 mutex_unlock(&d->i2c_mutex);
559 static int s6x0_i2c_transfer(struct i2c_adapter *adap, struct i2c_msg msg[],
562 struct dvb_usb_device *d = i2c_get_adapdata(adap);
563 struct usb_device *udev;
569 if (mutex_lock_interruptible(&d->i2c_mutex) < 0)
572 for (j = 0; j < num; j++) {
573 switch (msg[j].addr) {
574 case (DW2102_RC_QUERY): {
576 dw210x_op_rw(d->udev, 0xb8, 0, 0,
577 ibuf, 5, DW210X_READ_MSG);
578 memcpy(msg[j].buf, ibuf + 3, 2);
581 case (DW2102_VOLTAGE_CTRL): {
585 obuf[1] = msg[j].buf[1];/* off-on */
586 dw210x_op_rw(d->udev, 0x8a, 0, 0,
587 obuf, 2, DW210X_WRITE_MSG);
589 obuf[1] = msg[j].buf[0];/* 13v-18v */
590 dw210x_op_rw(d->udev, 0x8a, 0, 0,
591 obuf, 2, DW210X_WRITE_MSG);
594 case (DW2102_LED_CTRL): {
598 obuf[1] = msg[j].buf[0];
599 dw210x_op_rw(d->udev, 0x8a, 0, 0,
600 obuf, 2, DW210X_WRITE_MSG);
605 case 0x68: ds3000, stv0903, rs2000
606 case 0x60: ts2020, stv6110, stb6100
609 if (msg[j].flags == I2C_M_RD) {
611 u8 ibuf[MAX_XFER_SIZE];
613 if (msg[j].len > sizeof(ibuf)) {
614 warn("i2c rd: len=%d is too big!\n",
620 dw210x_op_rw(d->udev, 0x91, 0, 0,
623 memcpy(msg[j].buf, ibuf, msg[j].len);
625 } else if ((msg[j].buf[0] == 0xb0) &&
626 (msg[j].addr == 0x68)) {
629 obuf[0] = (msg[j].len > 16 ?
630 18 : msg[j].len + 1);
631 obuf[1] = msg[j].addr << 1;
632 obuf[2] = msg[j].buf[0];
633 len = msg[j].len - 1;
636 memcpy(obuf + 3, msg[j].buf + i,
637 (len > 16 ? 16 : len));
638 dw210x_op_rw(d->udev, 0x80, 0, 0,
639 obuf, (len > 16 ? 16 : len) + 3,
644 } else if (j < (num - 1)) {
645 /* write register addr before read */
646 u8 obuf[MAX_XFER_SIZE];
648 if (2 + msg[j].len > sizeof(obuf)) {
649 warn("i2c wr: len=%d is too big!\n",
655 obuf[0] = msg[j + 1].len;
656 obuf[1] = (msg[j].addr << 1);
657 memcpy(obuf + 2, msg[j].buf, msg[j].len);
658 dw210x_op_rw(d->udev,
659 le16_to_cpu(udev->descriptor.idProduct) ==
660 0x7500 ? 0x92 : 0x90, 0, 0,
661 obuf, msg[j].len + 2,
665 /* write registers */
666 u8 obuf[MAX_XFER_SIZE];
668 if (2 + msg[j].len > sizeof(obuf)) {
669 warn("i2c wr: len=%d is too big!\n",
674 obuf[0] = msg[j].len + 1;
675 obuf[1] = (msg[j].addr << 1);
676 memcpy(obuf + 2, msg[j].buf, msg[j].len);
677 dw210x_op_rw(d->udev, 0x80, 0, 0,
678 obuf, msg[j].len + 2,
689 mutex_unlock(&d->i2c_mutex);
693 static int su3000_i2c_transfer(struct i2c_adapter *adap, struct i2c_msg msg[],
696 struct dvb_usb_device *d = i2c_get_adapdata(adap);
697 struct dw2102_state *state;
704 if (mutex_lock_interruptible(&d->i2c_mutex) < 0)
706 if (mutex_lock_interruptible(&d->data_mutex) < 0) {
707 mutex_unlock(&d->i2c_mutex);
713 switch (msg[0].addr) {
714 case SU3000_STREAM_CTRL:
715 state->data[0] = msg[0].buf[0] + 0x36;
718 if (dvb_usb_generic_rw(d, state->data, 3,
719 state->data, 0, 0) < 0)
720 err("i2c transfer failed.");
722 case DW2102_RC_QUERY:
723 state->data[0] = 0x10;
724 if (dvb_usb_generic_rw(d, state->data, 1,
725 state->data, 2, 0) < 0)
726 err("i2c transfer failed.");
727 msg[0].buf[1] = state->data[0];
728 msg[0].buf[0] = state->data[1];
731 if (3 + msg[0].len > sizeof(state->data)) {
732 warn("i2c wr: len=%d is too big!\n",
738 /* always i2c write*/
739 state->data[0] = 0x08;
740 state->data[1] = msg[0].addr;
741 state->data[2] = msg[0].len;
743 memcpy(&state->data[3], msg[0].buf, msg[0].len);
745 if (dvb_usb_generic_rw(d, state->data, msg[0].len + 3,
746 state->data, 1, 0) < 0)
747 err("i2c transfer failed.");
752 /* always i2c read */
753 if (4 + msg[0].len > sizeof(state->data)) {
754 warn("i2c rd: len=%d is too big!\n",
759 if (1 + msg[1].len > sizeof(state->data)) {
760 warn("i2c rd: len=%d is too big!\n",
766 state->data[0] = 0x09;
767 state->data[1] = msg[0].len;
768 state->data[2] = msg[1].len;
769 state->data[3] = msg[0].addr;
770 memcpy(&state->data[4], msg[0].buf, msg[0].len);
772 if (dvb_usb_generic_rw(d, state->data, msg[0].len + 4,
773 state->data, msg[1].len + 1, 0) < 0)
774 err("i2c transfer failed.");
776 memcpy(msg[1].buf, &state->data[1], msg[1].len);
779 warn("more than 2 i2c messages at a time is not handled yet.");
782 mutex_unlock(&d->data_mutex);
783 mutex_unlock(&d->i2c_mutex);
787 static u32 dw210x_i2c_func(struct i2c_adapter *adapter)
792 static struct i2c_algorithm dw2102_i2c_algo = {
793 .master_xfer = dw2102_i2c_transfer,
794 .functionality = dw210x_i2c_func,
797 static struct i2c_algorithm dw2102_serit_i2c_algo = {
798 .master_xfer = dw2102_serit_i2c_transfer,
799 .functionality = dw210x_i2c_func,
802 static struct i2c_algorithm dw2102_earda_i2c_algo = {
803 .master_xfer = dw2102_earda_i2c_transfer,
804 .functionality = dw210x_i2c_func,
807 static struct i2c_algorithm dw2104_i2c_algo = {
808 .master_xfer = dw2104_i2c_transfer,
809 .functionality = dw210x_i2c_func,
812 static struct i2c_algorithm dw3101_i2c_algo = {
813 .master_xfer = dw3101_i2c_transfer,
814 .functionality = dw210x_i2c_func,
817 static struct i2c_algorithm s6x0_i2c_algo = {
818 .master_xfer = s6x0_i2c_transfer,
819 .functionality = dw210x_i2c_func,
822 static struct i2c_algorithm su3000_i2c_algo = {
823 .master_xfer = su3000_i2c_transfer,
824 .functionality = dw210x_i2c_func,
827 static int dw210x_read_mac_address(struct dvb_usb_device *d, u8 mac[6])
831 u8 eeprom[256], eepromline[16];
833 for (i = 0; i < 256; i++) {
834 if (dw210x_op_rw(d->udev, 0xb6, 0xa0 , i, ibuf, 2, DW210X_READ_MSG) < 0) {
835 err("read eeprom failed.");
838 eepromline[i%16] = ibuf[0];
841 if ((i % 16) == 15) {
842 deb_xfer("%02x: ", i - 15);
843 debug_dump(eepromline, 16, deb_xfer);
847 memcpy(mac, eeprom + 8, 6);
851 static int s6x0_read_mac_address(struct dvb_usb_device *d, u8 mac[6])
854 u8 ibuf[] = { 0 }, obuf[] = { 0 };
855 u8 eeprom[256], eepromline[16];
856 struct i2c_msg msg[] = {
870 for (i = 0; i < 256; i++) {
872 ret = s6x0_i2c_transfer(&d->i2c_adap, msg, 2);
874 err("read eeprom failed.");
877 eepromline[i % 16] = ibuf[0];
881 if ((i % 16) == 15) {
882 deb_xfer("%02x: ", i - 15);
883 debug_dump(eepromline, 16, deb_xfer);
887 memcpy(mac, eeprom + 16, 6);
891 static int su3000_streaming_ctrl(struct dvb_usb_adapter *adap, int onoff)
893 static u8 command_start[] = {0x00};
894 static u8 command_stop[] = {0x01};
895 struct i2c_msg msg = {
896 .addr = SU3000_STREAM_CTRL,
898 .buf = onoff ? command_start : command_stop,
902 i2c_transfer(&adap->dev->i2c_adap, &msg, 1);
907 static int su3000_power_ctrl(struct dvb_usb_device *d, int i)
909 struct dw2102_state *state = (struct dw2102_state *)d->priv;
912 info("%s: %d, initialized %d", __func__, i, state->initialized);
914 if (i && !state->initialized) {
915 mutex_lock(&d->data_mutex);
917 state->data[0] = 0xde;
920 state->initialized = 1;
922 ret = dvb_usb_generic_rw(d, state->data, 2, NULL, 0, 0);
923 mutex_unlock(&d->data_mutex);
929 static int su3000_read_mac_address(struct dvb_usb_device *d, u8 mac[6])
932 u8 obuf[] = { 0x1f, 0xf0 };
934 struct i2c_msg msg[] = {
949 for (i = 0; i < 6; i++) {
951 if (i2c_transfer(&d->i2c_adap, msg, 2) != 2)
960 static int su3000_identify_state(struct usb_device *udev,
961 struct dvb_usb_device_properties *props,
962 struct dvb_usb_device_description **desc,
965 info("%s", __func__);
971 static int dw210x_set_voltage(struct dvb_frontend *fe,
972 enum fe_sec_voltage voltage)
974 static u8 command_13v[] = {0x00, 0x01};
975 static u8 command_18v[] = {0x01, 0x01};
976 static u8 command_off[] = {0x00, 0x00};
977 struct i2c_msg msg = {
978 .addr = DW2102_VOLTAGE_CTRL,
984 struct dvb_usb_adapter *udev_adap =
985 (struct dvb_usb_adapter *)(fe->dvb->priv);
986 if (voltage == SEC_VOLTAGE_18)
987 msg.buf = command_18v;
988 else if (voltage == SEC_VOLTAGE_13)
989 msg.buf = command_13v;
991 i2c_transfer(&udev_adap->dev->i2c_adap, &msg, 1);
996 static int s660_set_voltage(struct dvb_frontend *fe,
997 enum fe_sec_voltage voltage)
999 struct dvb_usb_adapter *d =
1000 (struct dvb_usb_adapter *)(fe->dvb->priv);
1001 struct dw2102_state *st = (struct dw2102_state *)d->dev->priv;
1003 dw210x_set_voltage(fe, voltage);
1004 if (st->old_set_voltage)
1005 st->old_set_voltage(fe, voltage);
1010 static void dw210x_led_ctrl(struct dvb_frontend *fe, int offon)
1012 static u8 led_off[] = { 0 };
1013 static u8 led_on[] = { 1 };
1014 struct i2c_msg msg = {
1015 .addr = DW2102_LED_CTRL,
1020 struct dvb_usb_adapter *udev_adap =
1021 (struct dvb_usb_adapter *)(fe->dvb->priv);
1025 i2c_transfer(&udev_adap->dev->i2c_adap, &msg, 1);
1028 static int tt_s2_4600_read_status(struct dvb_frontend *fe,
1029 enum fe_status *status)
1031 struct dvb_usb_adapter *d =
1032 (struct dvb_usb_adapter *)(fe->dvb->priv);
1033 struct dw2102_state *st = (struct dw2102_state *)d->dev->priv;
1036 ret = st->fe_read_status(fe, status);
1038 /* resync slave fifo when signal change from unlock to lock */
1039 if ((*status & FE_HAS_LOCK) && (!st->last_lock))
1040 su3000_streaming_ctrl(d, 1);
1042 st->last_lock = (*status & FE_HAS_LOCK) ? 1 : 0;
1046 static struct stv0299_config sharp_z0194a_config = {
1047 .demod_address = 0x68,
1048 .inittab = sharp_z0194a_inittab,
1052 .lock_output = STV0299_LOCKOUTPUT_1,
1053 .volt13_op0_op1 = STV0299_VOLT13_OP1,
1054 .min_delay_ms = 100,
1055 .set_symbol_rate = sharp_z0194a_set_symbol_rate,
1058 static struct cx24116_config dw2104_config = {
1059 .demod_address = 0x55,
1060 .mpg_clk_pos_pol = 0x01,
1063 static struct si21xx_config serit_sp1511lhb_config = {
1064 .demod_address = 0x68,
1065 .min_delay_ms = 100,
1069 static struct tda10023_config dw3101_tda10023_config = {
1070 .demod_address = 0x0c,
1074 static struct mt312_config zl313_config = {
1075 .demod_address = 0x0e,
1078 static struct ds3000_config dw2104_ds3000_config = {
1079 .demod_address = 0x68,
1082 static struct ts2020_config dw2104_ts2020_config = {
1083 .tuner_address = 0x60,
1085 .frequency_div = 1060000,
1088 static struct ds3000_config s660_ds3000_config = {
1089 .demod_address = 0x68,
1091 .set_lock_led = dw210x_led_ctrl,
1094 static struct ts2020_config s660_ts2020_config = {
1095 .tuner_address = 0x60,
1097 .frequency_div = 1146000,
1100 static struct stv0900_config dw2104a_stv0900_config = {
1101 .demod_address = 0x6a,
1104 .clkmode = 3,/* 0-CLKI, 2-XTALI, else AUTO */
1105 .diseqc_mode = 2,/* 2/3 PWM */
1106 .tun1_maddress = 0,/* 0x60 */
1107 .tun1_adc = 0,/* 2 Vpp */
1111 static struct stb6100_config dw2104a_stb6100_config = {
1112 .tuner_address = 0x60,
1113 .refclock = 27000000,
1116 static struct stv0900_config dw2104_stv0900_config = {
1117 .demod_address = 0x68,
1123 .tun1_adc = 1,/* 1 Vpp */
1127 static struct stv6110_config dw2104_stv6110_config = {
1128 .i2c_address = 0x60,
1133 static struct stv0900_config prof_7500_stv0900_config = {
1134 .demod_address = 0x6a,
1137 .clkmode = 3,/* 0-CLKI, 2-XTALI, else AUTO */
1138 .diseqc_mode = 2,/* 2/3 PWM */
1139 .tun1_maddress = 0,/* 0x60 */
1140 .tun1_adc = 0,/* 2 Vpp */
1143 .set_lock_led = dw210x_led_ctrl,
1146 static struct ds3000_config su3000_ds3000_config = {
1147 .demod_address = 0x68,
1149 .set_lock_led = dw210x_led_ctrl,
1152 static struct cxd2820r_config cxd2820r_config = {
1153 .i2c_address = 0x6c, /* (0xd8 >> 1) */
1158 static struct tda18271_config tda18271_config = {
1159 .output_opt = TDA18271_OUTPUT_LT_OFF,
1160 .gate = TDA18271_GATE_DIGITAL,
1163 static u8 m88rs2000_inittab[] = {
1164 DEMOD_WRITE, 0x9a, 0x30,
1165 DEMOD_WRITE, 0x00, 0x01,
1166 WRITE_DELAY, 0x19, 0x00,
1167 DEMOD_WRITE, 0x00, 0x00,
1168 DEMOD_WRITE, 0x9a, 0xb0,
1169 DEMOD_WRITE, 0x81, 0xc1,
1170 DEMOD_WRITE, 0x81, 0x81,
1171 DEMOD_WRITE, 0x86, 0xc6,
1172 DEMOD_WRITE, 0x9a, 0x30,
1173 DEMOD_WRITE, 0xf0, 0x80,
1174 DEMOD_WRITE, 0xf1, 0xbf,
1175 DEMOD_WRITE, 0xb0, 0x45,
1176 DEMOD_WRITE, 0xb2, 0x01,
1177 DEMOD_WRITE, 0x9a, 0xb0,
1181 static struct m88rs2000_config s421_m88rs2000_config = {
1183 .inittab = m88rs2000_inittab,
1186 static int dw2104_frontend_attach(struct dvb_usb_adapter *d)
1188 struct dvb_tuner_ops *tuner_ops = NULL;
1190 if (demod_probe & 4) {
1191 d->fe_adap[0].fe = dvb_attach(stv0900_attach, &dw2104a_stv0900_config,
1192 &d->dev->i2c_adap, 0);
1193 if (d->fe_adap[0].fe != NULL) {
1194 if (dvb_attach(stb6100_attach, d->fe_adap[0].fe,
1195 &dw2104a_stb6100_config,
1196 &d->dev->i2c_adap)) {
1197 tuner_ops = &d->fe_adap[0].fe->ops.tuner_ops;
1198 tuner_ops->set_frequency = stb6100_set_freq;
1199 tuner_ops->get_frequency = stb6100_get_freq;
1200 tuner_ops->set_bandwidth = stb6100_set_bandw;
1201 tuner_ops->get_bandwidth = stb6100_get_bandw;
1202 d->fe_adap[0].fe->ops.set_voltage = dw210x_set_voltage;
1203 info("Attached STV0900+STB6100!");
1209 if (demod_probe & 2) {
1210 d->fe_adap[0].fe = dvb_attach(stv0900_attach, &dw2104_stv0900_config,
1211 &d->dev->i2c_adap, 0);
1212 if (d->fe_adap[0].fe != NULL) {
1213 if (dvb_attach(stv6110_attach, d->fe_adap[0].fe,
1214 &dw2104_stv6110_config,
1215 &d->dev->i2c_adap)) {
1216 d->fe_adap[0].fe->ops.set_voltage = dw210x_set_voltage;
1217 info("Attached STV0900+STV6110A!");
1223 if (demod_probe & 1) {
1224 d->fe_adap[0].fe = dvb_attach(cx24116_attach, &dw2104_config,
1226 if (d->fe_adap[0].fe != NULL) {
1227 d->fe_adap[0].fe->ops.set_voltage = dw210x_set_voltage;
1228 info("Attached cx24116!");
1233 d->fe_adap[0].fe = dvb_attach(ds3000_attach, &dw2104_ds3000_config,
1235 if (d->fe_adap[0].fe != NULL) {
1236 dvb_attach(ts2020_attach, d->fe_adap[0].fe,
1237 &dw2104_ts2020_config, &d->dev->i2c_adap);
1238 d->fe_adap[0].fe->ops.set_voltage = dw210x_set_voltage;
1239 info("Attached DS3000!");
1246 static struct dvb_usb_device_properties dw2102_properties;
1247 static struct dvb_usb_device_properties dw2104_properties;
1248 static struct dvb_usb_device_properties s6x0_properties;
1250 static int dw2102_frontend_attach(struct dvb_usb_adapter *d)
1252 if (dw2102_properties.i2c_algo == &dw2102_serit_i2c_algo) {
1253 /*dw2102_properties.adapter->tuner_attach = NULL;*/
1254 d->fe_adap[0].fe = dvb_attach(si21xx_attach, &serit_sp1511lhb_config,
1256 if (d->fe_adap[0].fe != NULL) {
1257 d->fe_adap[0].fe->ops.set_voltage = dw210x_set_voltage;
1258 info("Attached si21xx!");
1263 if (dw2102_properties.i2c_algo == &dw2102_earda_i2c_algo) {
1264 d->fe_adap[0].fe = dvb_attach(stv0288_attach, &earda_config,
1266 if (d->fe_adap[0].fe != NULL) {
1267 if (dvb_attach(stb6000_attach, d->fe_adap[0].fe, 0x61,
1268 &d->dev->i2c_adap)) {
1269 d->fe_adap[0].fe->ops.set_voltage = dw210x_set_voltage;
1270 info("Attached stv0288!");
1276 if (dw2102_properties.i2c_algo == &dw2102_i2c_algo) {
1277 /*dw2102_properties.adapter->tuner_attach = dw2102_tuner_attach;*/
1278 d->fe_adap[0].fe = dvb_attach(stv0299_attach, &sharp_z0194a_config,
1280 if (d->fe_adap[0].fe != NULL) {
1281 d->fe_adap[0].fe->ops.set_voltage = dw210x_set_voltage;
1282 info("Attached stv0299!");
1289 static int dw3101_frontend_attach(struct dvb_usb_adapter *d)
1291 d->fe_adap[0].fe = dvb_attach(tda10023_attach, &dw3101_tda10023_config,
1292 &d->dev->i2c_adap, 0x48);
1293 if (d->fe_adap[0].fe != NULL) {
1294 info("Attached tda10023!");
1300 static int zl100313_frontend_attach(struct dvb_usb_adapter *d)
1302 d->fe_adap[0].fe = dvb_attach(mt312_attach, &zl313_config,
1304 if (d->fe_adap[0].fe != NULL) {
1305 if (dvb_attach(zl10039_attach, d->fe_adap[0].fe, 0x60,
1306 &d->dev->i2c_adap)) {
1307 d->fe_adap[0].fe->ops.set_voltage = dw210x_set_voltage;
1308 info("Attached zl100313+zl10039!");
1316 static int stv0288_frontend_attach(struct dvb_usb_adapter *d)
1320 d->fe_adap[0].fe = dvb_attach(stv0288_attach, &earda_config,
1323 if (d->fe_adap[0].fe == NULL)
1326 if (NULL == dvb_attach(stb6000_attach, d->fe_adap[0].fe, 0x61, &d->dev->i2c_adap))
1329 d->fe_adap[0].fe->ops.set_voltage = dw210x_set_voltage;
1331 dw210x_op_rw(d->dev->udev, 0x8a, 0, 0, obuf, 2, DW210X_WRITE_MSG);
1333 info("Attached stv0288+stb6000!");
1339 static int ds3000_frontend_attach(struct dvb_usb_adapter *d)
1341 struct dw2102_state *st = d->dev->priv;
1344 d->fe_adap[0].fe = dvb_attach(ds3000_attach, &s660_ds3000_config,
1347 if (d->fe_adap[0].fe == NULL)
1350 dvb_attach(ts2020_attach, d->fe_adap[0].fe, &s660_ts2020_config,
1353 st->old_set_voltage = d->fe_adap[0].fe->ops.set_voltage;
1354 d->fe_adap[0].fe->ops.set_voltage = s660_set_voltage;
1356 dw210x_op_rw(d->dev->udev, 0x8a, 0, 0, obuf, 2, DW210X_WRITE_MSG);
1358 info("Attached ds3000+ts2020!");
1363 static int prof_7500_frontend_attach(struct dvb_usb_adapter *d)
1367 d->fe_adap[0].fe = dvb_attach(stv0900_attach, &prof_7500_stv0900_config,
1368 &d->dev->i2c_adap, 0);
1369 if (d->fe_adap[0].fe == NULL)
1372 d->fe_adap[0].fe->ops.set_voltage = dw210x_set_voltage;
1374 dw210x_op_rw(d->dev->udev, 0x8a, 0, 0, obuf, 2, DW210X_WRITE_MSG);
1376 info("Attached STV0900+STB6100A!");
1381 static int su3000_frontend_attach(struct dvb_usb_adapter *adap)
1383 struct dvb_usb_device *d = adap->dev;
1384 struct dw2102_state *state = d->priv;
1386 mutex_lock(&d->data_mutex);
1388 state->data[0] = 0xe;
1389 state->data[1] = 0x80;
1392 if (dvb_usb_generic_rw(d, state->data, 3, state->data, 1, 0) < 0)
1393 err("command 0x0e transfer failed.");
1395 state->data[0] = 0xe;
1396 state->data[1] = 0x02;
1399 if (dvb_usb_generic_rw(d, state->data, 3, state->data, 1, 0) < 0)
1400 err("command 0x0e transfer failed.");
1403 state->data[0] = 0xe;
1404 state->data[1] = 0x83;
1407 if (dvb_usb_generic_rw(d, state->data, 3, state->data, 1, 0) < 0)
1408 err("command 0x0e transfer failed.");
1410 state->data[0] = 0xe;
1411 state->data[1] = 0x83;
1414 if (dvb_usb_generic_rw(d, state->data, 3, state->data, 1, 0) < 0)
1415 err("command 0x0e transfer failed.");
1417 state->data[0] = 0x51;
1419 if (dvb_usb_generic_rw(d, state->data, 1, state->data, 1, 0) < 0)
1420 err("command 0x51 transfer failed.");
1422 mutex_unlock(&d->data_mutex);
1424 adap->fe_adap[0].fe = dvb_attach(ds3000_attach, &su3000_ds3000_config,
1426 if (adap->fe_adap[0].fe == NULL)
1429 if (dvb_attach(ts2020_attach, adap->fe_adap[0].fe,
1430 &dw2104_ts2020_config,
1432 info("Attached DS3000/TS2020!");
1436 info("Failed to attach DS3000/TS2020!");
1440 static int t220_frontend_attach(struct dvb_usb_adapter *adap)
1442 struct dvb_usb_device *d = adap->dev;
1443 struct dw2102_state *state = d->priv;
1445 mutex_lock(&d->data_mutex);
1447 state->data[0] = 0xe;
1448 state->data[1] = 0x87;
1449 state->data[2] = 0x0;
1451 if (dvb_usb_generic_rw(d, state->data, 3, state->data, 1, 0) < 0)
1452 err("command 0x0e transfer failed.");
1454 state->data[0] = 0xe;
1455 state->data[1] = 0x86;
1458 if (dvb_usb_generic_rw(d, state->data, 3, state->data, 1, 0) < 0)
1459 err("command 0x0e transfer failed.");
1461 state->data[0] = 0xe;
1462 state->data[1] = 0x80;
1465 if (dvb_usb_generic_rw(d, state->data, 3, state->data, 1, 0) < 0)
1466 err("command 0x0e transfer failed.");
1470 state->data[0] = 0xe;
1471 state->data[1] = 0x80;
1474 if (dvb_usb_generic_rw(d, state->data, 3, state->data, 1, 0) < 0)
1475 err("command 0x0e transfer failed.");
1477 state->data[0] = 0x51;
1479 if (dvb_usb_generic_rw(d, state->data, 1, state->data, 1, 0) < 0)
1480 err("command 0x51 transfer failed.");
1482 mutex_unlock(&d->data_mutex);
1484 adap->fe_adap[0].fe = dvb_attach(cxd2820r_attach, &cxd2820r_config,
1485 &d->i2c_adap, NULL);
1486 if (adap->fe_adap[0].fe != NULL) {
1487 if (dvb_attach(tda18271_attach, adap->fe_adap[0].fe, 0x60,
1488 &d->i2c_adap, &tda18271_config)) {
1489 info("Attached TDA18271HD/CXD2820R!");
1494 info("Failed to attach TDA18271HD/CXD2820R!");
1498 static int m88rs2000_frontend_attach(struct dvb_usb_adapter *adap)
1500 struct dvb_usb_device *d = adap->dev;
1501 struct dw2102_state *state = d->priv;
1503 mutex_lock(&d->data_mutex);
1505 state->data[0] = 0x51;
1507 if (dvb_usb_generic_rw(d, state->data, 1, state->data, 1, 0) < 0)
1508 err("command 0x51 transfer failed.");
1510 mutex_unlock(&d->data_mutex);
1512 adap->fe_adap[0].fe = dvb_attach(m88rs2000_attach,
1513 &s421_m88rs2000_config,
1516 if (adap->fe_adap[0].fe == NULL)
1519 if (dvb_attach(ts2020_attach, adap->fe_adap[0].fe,
1520 &dw2104_ts2020_config,
1522 info("Attached RS2000/TS2020!");
1526 info("Failed to attach RS2000/TS2020!");
1530 static int tt_s2_4600_frontend_attach(struct dvb_usb_adapter *adap)
1532 struct dvb_usb_device *d = adap->dev;
1533 struct dw2102_state *state = d->priv;
1534 struct i2c_adapter *i2c_adapter;
1535 struct i2c_client *client;
1536 struct i2c_board_info board_info;
1537 struct m88ds3103_platform_data m88ds3103_pdata = {};
1538 struct ts2020_config ts2020_config = {};
1540 mutex_lock(&d->data_mutex);
1542 state->data[0] = 0xe;
1543 state->data[1] = 0x80;
1544 state->data[2] = 0x0;
1546 if (dvb_usb_generic_rw(d, state->data, 3, state->data, 1, 0) < 0)
1547 err("command 0x0e transfer failed.");
1549 state->data[0] = 0xe;
1550 state->data[1] = 0x02;
1553 if (dvb_usb_generic_rw(d, state->data, 3, state->data, 1, 0) < 0)
1554 err("command 0x0e transfer failed.");
1557 state->data[0] = 0xe;
1558 state->data[1] = 0x83;
1561 if (dvb_usb_generic_rw(d, state->data, 3, state->data, 1, 0) < 0)
1562 err("command 0x0e transfer failed.");
1564 state->data[0] = 0xe;
1565 state->data[1] = 0x83;
1568 if (dvb_usb_generic_rw(d, state->data, 3, state->data, 1, 0) < 0)
1569 err("command 0x0e transfer failed.");
1571 state->data[0] = 0x51;
1573 if (dvb_usb_generic_rw(d, state->data, 1, state->data, 1, 0) < 0)
1574 err("command 0x51 transfer failed.");
1576 mutex_unlock(&d->data_mutex);
1579 m88ds3103_pdata.clk = 27000000;
1580 m88ds3103_pdata.i2c_wr_max = 33;
1581 m88ds3103_pdata.ts_mode = M88DS3103_TS_CI;
1582 m88ds3103_pdata.ts_clk = 16000;
1583 m88ds3103_pdata.ts_clk_pol = 0;
1584 m88ds3103_pdata.spec_inv = 0;
1585 m88ds3103_pdata.agc = 0x99;
1586 m88ds3103_pdata.agc_inv = 0;
1587 m88ds3103_pdata.clk_out = M88DS3103_CLOCK_OUT_ENABLED;
1588 m88ds3103_pdata.envelope_mode = 0;
1589 m88ds3103_pdata.lnb_hv_pol = 1;
1590 m88ds3103_pdata.lnb_en_pol = 0;
1591 memset(&board_info, 0, sizeof(board_info));
1592 strlcpy(board_info.type, "m88ds3103", I2C_NAME_SIZE);
1593 board_info.addr = 0x68;
1594 board_info.platform_data = &m88ds3103_pdata;
1595 request_module("m88ds3103");
1596 client = i2c_new_device(&d->i2c_adap, &board_info);
1597 if (client == NULL || client->dev.driver == NULL)
1599 if (!try_module_get(client->dev.driver->owner)) {
1600 i2c_unregister_device(client);
1603 adap->fe_adap[0].fe = m88ds3103_pdata.get_dvb_frontend(client);
1604 i2c_adapter = m88ds3103_pdata.get_i2c_adapter(client);
1606 state->i2c_client_demod = client;
1609 ts2020_config.fe = adap->fe_adap[0].fe;
1610 memset(&board_info, 0, sizeof(board_info));
1611 strlcpy(board_info.type, "ts2022", I2C_NAME_SIZE);
1612 board_info.addr = 0x60;
1613 board_info.platform_data = &ts2020_config;
1614 request_module("ts2020");
1615 client = i2c_new_device(i2c_adapter, &board_info);
1617 if (client == NULL || client->dev.driver == NULL) {
1618 dvb_frontend_detach(adap->fe_adap[0].fe);
1622 if (!try_module_get(client->dev.driver->owner)) {
1623 i2c_unregister_device(client);
1624 dvb_frontend_detach(adap->fe_adap[0].fe);
1628 /* delegate signal strength measurement to tuner */
1629 adap->fe_adap[0].fe->ops.read_signal_strength =
1630 adap->fe_adap[0].fe->ops.tuner_ops.get_rf_strength;
1632 state->i2c_client_tuner = client;
1634 /* hook fe: need to resync the slave fifo when signal locks */
1635 state->fe_read_status = adap->fe_adap[0].fe->ops.read_status;
1636 adap->fe_adap[0].fe->ops.read_status = tt_s2_4600_read_status;
1638 state->last_lock = 0;
1643 static int dw2102_tuner_attach(struct dvb_usb_adapter *adap)
1645 dvb_attach(dvb_pll_attach, adap->fe_adap[0].fe, 0x60,
1646 &adap->dev->i2c_adap, DVB_PLL_OPERA1);
1650 static int dw3101_tuner_attach(struct dvb_usb_adapter *adap)
1652 dvb_attach(dvb_pll_attach, adap->fe_adap[0].fe, 0x60,
1653 &adap->dev->i2c_adap, DVB_PLL_TUA6034);
1658 static int dw2102_rc_query(struct dvb_usb_device *d)
1661 struct i2c_msg msg = {
1662 .addr = DW2102_RC_QUERY,
1668 if (d->props.i2c_algo->master_xfer(&d->i2c_adap, &msg, 1) == 1) {
1669 if (msg.buf[0] != 0xff) {
1670 deb_rc("%s: rc code: %x, %x\n",
1671 __func__, key[0], key[1]);
1672 rc_keydown(d->rc_dev, RC_PROTO_UNKNOWN, key[0], 0);
1679 static int prof_rc_query(struct dvb_usb_device *d)
1682 struct i2c_msg msg = {
1683 .addr = DW2102_RC_QUERY,
1689 if (d->props.i2c_algo->master_xfer(&d->i2c_adap, &msg, 1) == 1) {
1690 if (msg.buf[0] != 0xff) {
1691 deb_rc("%s: rc code: %x, %x\n",
1692 __func__, key[0], key[1]);
1693 rc_keydown(d->rc_dev, RC_PROTO_UNKNOWN, key[0] ^ 0xff,
1701 static int su3000_rc_query(struct dvb_usb_device *d)
1704 struct i2c_msg msg = {
1705 .addr = DW2102_RC_QUERY,
1711 if (d->props.i2c_algo->master_xfer(&d->i2c_adap, &msg, 1) == 1) {
1712 if (msg.buf[0] != 0xff) {
1713 deb_rc("%s: rc code: %x, %x\n",
1714 __func__, key[0], key[1]);
1715 rc_keydown(d->rc_dev, RC_PROTO_RC5,
1716 RC_SCANCODE_RC5(key[1], key[0]), 0);
1723 enum dw2102_table_entry {
1735 TERRATEC_CINERGY_S2,
1741 TERRATEC_CINERGY_S2_R2,
1742 TERRATEC_CINERGY_S2_R3,
1743 TERRATEC_CINERGY_S2_R4,
1746 TECHNOTREND_S2_4600,
1749 TERRATEC_CINERGY_S2_BOX,
1753 static struct usb_device_id dw2102_table[] = {
1754 [CYPRESS_DW2102] = {USB_DEVICE(USB_VID_CYPRESS, USB_PID_DW2102)},
1755 [CYPRESS_DW2101] = {USB_DEVICE(USB_VID_CYPRESS, 0x2101)},
1756 [CYPRESS_DW2104] = {USB_DEVICE(USB_VID_CYPRESS, USB_PID_DW2104)},
1757 [TEVII_S650] = {USB_DEVICE(0x9022, USB_PID_TEVII_S650)},
1758 [TERRATEC_CINERGY_S] = {USB_DEVICE(USB_VID_TERRATEC, USB_PID_TERRATEC_CINERGY_S)},
1759 [CYPRESS_DW3101] = {USB_DEVICE(USB_VID_CYPRESS, USB_PID_DW3101)},
1760 [TEVII_S630] = {USB_DEVICE(0x9022, USB_PID_TEVII_S630)},
1761 [PROF_1100] = {USB_DEVICE(0x3011, USB_PID_PROF_1100)},
1762 [TEVII_S660] = {USB_DEVICE(0x9022, USB_PID_TEVII_S660)},
1763 [PROF_7500] = {USB_DEVICE(0x3034, 0x7500)},
1764 [GENIATECH_SU3000] = {USB_DEVICE(0x1f4d, 0x3000)},
1765 [TERRATEC_CINERGY_S2] = {USB_DEVICE(USB_VID_TERRATEC, USB_PID_TERRATEC_CINERGY_S2_R1)},
1766 [TEVII_S480_1] = {USB_DEVICE(0x9022, USB_PID_TEVII_S480_1)},
1767 [TEVII_S480_2] = {USB_DEVICE(0x9022, USB_PID_TEVII_S480_2)},
1768 [X3M_SPC1400HD] = {USB_DEVICE(0x1f4d, 0x3100)},
1769 [TEVII_S421] = {USB_DEVICE(0x9022, USB_PID_TEVII_S421)},
1770 [TEVII_S632] = {USB_DEVICE(0x9022, USB_PID_TEVII_S632)},
1771 [TERRATEC_CINERGY_S2_R2] = {USB_DEVICE(USB_VID_TERRATEC, USB_PID_TERRATEC_CINERGY_S2_R2)},
1772 [TERRATEC_CINERGY_S2_R3] = {USB_DEVICE(USB_VID_TERRATEC, USB_PID_TERRATEC_CINERGY_S2_R3)},
1773 [TERRATEC_CINERGY_S2_R4] = {USB_DEVICE(USB_VID_TERRATEC, USB_PID_TERRATEC_CINERGY_S2_R4)},
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 = request_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;
1843 case USB_PID_DW2104:
1845 dw210x_op_rw(dev, 0xc4, 0x0000, 0, &reset, 1,
1848 case USB_PID_DW3101:
1850 dw210x_op_rw(dev, 0xbf, 0x0040, 0, &reset, 0,
1853 case USB_PID_TERRATEC_CINERGY_S:
1854 case USB_PID_DW2102:
1855 dw210x_op_rw(dev, 0xbf, 0x0040, 0, &reset, 0,
1857 dw210x_op_rw(dev, 0xb9, 0x0000, 0, &reset16[0], 2,
1859 /* check STV0299 frontend */
1860 dw210x_op_rw(dev, 0xb5, 0, 0, &reset16[0], 2,
1862 if ((reset16[0] == 0xa1) || (reset16[0] == 0x80)) {
1863 dw2102_properties.i2c_algo = &dw2102_i2c_algo;
1864 dw2102_properties.adapter->fe[0].tuner_attach = &dw2102_tuner_attach;
1867 /* check STV0288 frontend */
1871 dw210x_op_rw(dev, 0xc2, 0, 0, &reset16[0], 3,
1873 dw210x_op_rw(dev, 0xc3, 0xd1, 0, &reset16[0], 3,
1875 if (reset16[2] == 0x11) {
1876 dw2102_properties.i2c_algo = &dw2102_earda_i2c_algo;
1882 dw210x_op_rw(dev, 0xbc, 0x0030, 0, &reset16[0], 2,
1884 dw210x_op_rw(dev, 0xba, 0x0000, 0, &reset16[0], 7,
1886 dw210x_op_rw(dev, 0xba, 0x0000, 0, &reset16[0], 7,
1888 dw210x_op_rw(dev, 0xb9, 0x0000, 0, &reset16[0], 2,
1897 if (le16_to_cpu(dev->descriptor.idProduct) == 0x2101)
1898 release_firmware(fw);
1902 static struct dvb_usb_device_properties dw2102_properties = {
1903 .caps = DVB_USB_IS_AN_I2C_ADAPTER,
1904 .usb_ctrl = DEVICE_SPECIFIC,
1905 .firmware = DW2102_FIRMWARE,
1908 .i2c_algo = &dw2102_serit_i2c_algo,
1912 .rc_codes = RC_MAP_DM1105_NEC,
1913 .module_name = "dw2102",
1914 .allowed_protos = RC_PROTO_BIT_NEC,
1915 .rc_query = dw2102_rc_query,
1918 .generic_bulk_ctrl_endpoint = 0x81,
1919 /* parameter for the MPEG2-data transfer */
1921 .download_firmware = dw2102_load_firmware,
1922 .read_mac_address = dw210x_read_mac_address,
1927 .frontend_attach = dw2102_frontend_attach,
1941 .num_device_descs = 3,
1943 {"DVBWorld DVB-S 2102 USB2.0",
1944 {&dw2102_table[CYPRESS_DW2102], NULL},
1947 {"DVBWorld DVB-S 2101 USB2.0",
1948 {&dw2102_table[CYPRESS_DW2101], NULL},
1951 {"TerraTec Cinergy S USB",
1952 {&dw2102_table[TERRATEC_CINERGY_S], NULL},
1958 static struct dvb_usb_device_properties dw2104_properties = {
1959 .caps = DVB_USB_IS_AN_I2C_ADAPTER,
1960 .usb_ctrl = DEVICE_SPECIFIC,
1961 .firmware = DW2104_FIRMWARE,
1964 .i2c_algo = &dw2104_i2c_algo,
1967 .rc_codes = RC_MAP_DM1105_NEC,
1968 .module_name = "dw2102",
1969 .allowed_protos = RC_PROTO_BIT_NEC,
1970 .rc_query = dw2102_rc_query,
1973 .generic_bulk_ctrl_endpoint = 0x81,
1974 /* parameter for the MPEG2-data transfer */
1976 .download_firmware = dw2102_load_firmware,
1977 .read_mac_address = dw210x_read_mac_address,
1982 .frontend_attach = dw2104_frontend_attach,
1996 .num_device_descs = 2,
1998 { "DVBWorld DW2104 USB2.0",
1999 {&dw2102_table[CYPRESS_DW2104], NULL},
2002 { "TeVii S650 USB2.0",
2003 {&dw2102_table[TEVII_S650], NULL},
2009 static struct dvb_usb_device_properties dw3101_properties = {
2010 .caps = DVB_USB_IS_AN_I2C_ADAPTER,
2011 .usb_ctrl = DEVICE_SPECIFIC,
2012 .firmware = DW3101_FIRMWARE,
2015 .i2c_algo = &dw3101_i2c_algo,
2018 .rc_codes = RC_MAP_DM1105_NEC,
2019 .module_name = "dw2102",
2020 .allowed_protos = RC_PROTO_BIT_NEC,
2021 .rc_query = dw2102_rc_query,
2024 .generic_bulk_ctrl_endpoint = 0x81,
2025 /* parameter for the MPEG2-data transfer */
2027 .download_firmware = dw2102_load_firmware,
2028 .read_mac_address = dw210x_read_mac_address,
2033 .frontend_attach = dw3101_frontend_attach,
2034 .tuner_attach = dw3101_tuner_attach,
2048 .num_device_descs = 1,
2050 { "DVBWorld DVB-C 3101 USB2.0",
2051 {&dw2102_table[CYPRESS_DW3101], NULL},
2057 static struct dvb_usb_device_properties s6x0_properties = {
2058 .caps = DVB_USB_IS_AN_I2C_ADAPTER,
2059 .usb_ctrl = DEVICE_SPECIFIC,
2060 .size_of_priv = sizeof(struct dw2102_state),
2061 .firmware = S630_FIRMWARE,
2064 .i2c_algo = &s6x0_i2c_algo,
2067 .rc_codes = RC_MAP_TEVII_NEC,
2068 .module_name = "dw2102",
2069 .allowed_protos = RC_PROTO_BIT_NEC,
2070 .rc_query = dw2102_rc_query,
2073 .generic_bulk_ctrl_endpoint = 0x81,
2075 .download_firmware = dw2102_load_firmware,
2076 .read_mac_address = s6x0_read_mac_address,
2081 .frontend_attach = zl100313_frontend_attach,
2095 .num_device_descs = 1,
2098 {&dw2102_table[TEVII_S630], NULL},
2104 static struct dvb_usb_device_properties *p1100;
2105 static const struct dvb_usb_device_description d1100 = {
2107 {&dw2102_table[PROF_1100], NULL},
2111 static struct dvb_usb_device_properties *s660;
2112 static const struct dvb_usb_device_description d660 = {
2114 {&dw2102_table[TEVII_S660], NULL},
2118 static const struct dvb_usb_device_description d480_1 = {
2120 {&dw2102_table[TEVII_S480_1], NULL},
2124 static const struct dvb_usb_device_description d480_2 = {
2126 {&dw2102_table[TEVII_S480_2], NULL},
2130 static struct dvb_usb_device_properties *p7500;
2131 static const struct dvb_usb_device_description d7500 = {
2132 "Prof 7500 USB DVB-S2",
2133 {&dw2102_table[PROF_7500], NULL},
2137 static struct dvb_usb_device_properties *s421;
2138 static const struct dvb_usb_device_description d421 = {
2140 {&dw2102_table[TEVII_S421], NULL},
2144 static const struct dvb_usb_device_description d632 = {
2146 {&dw2102_table[TEVII_S632], NULL},
2150 static struct dvb_usb_device_properties su3000_properties = {
2151 .caps = DVB_USB_IS_AN_I2C_ADAPTER,
2152 .usb_ctrl = DEVICE_SPECIFIC,
2153 .size_of_priv = sizeof(struct dw2102_state),
2154 .power_ctrl = su3000_power_ctrl,
2156 .identify_state = su3000_identify_state,
2157 .i2c_algo = &su3000_i2c_algo,
2161 .rc_codes = RC_MAP_SU3000,
2162 .module_name = "dw2102",
2163 .allowed_protos = RC_PROTO_BIT_RC5,
2164 .rc_query = su3000_rc_query,
2167 .read_mac_address = su3000_read_mac_address,
2169 .generic_bulk_ctrl_endpoint = 0x01,
2175 .streaming_ctrl = su3000_streaming_ctrl,
2176 .frontend_attach = su3000_frontend_attach,
2190 .num_device_descs = 6,
2192 { "SU3000HD DVB-S USB2.0",
2193 { &dw2102_table[GENIATECH_SU3000], NULL },
2196 { "Terratec Cinergy S2 USB HD",
2197 { &dw2102_table[TERRATEC_CINERGY_S2], NULL },
2200 { "X3M TV SPC1400HD PCI",
2201 { &dw2102_table[X3M_SPC1400HD], NULL },
2204 { "Terratec Cinergy S2 USB HD Rev.2",
2205 { &dw2102_table[TERRATEC_CINERGY_S2_R2], NULL },
2208 { "Terratec Cinergy S2 USB HD Rev.3",
2209 { &dw2102_table[TERRATEC_CINERGY_S2_R3], NULL },
2212 { "GOTVIEW Satellite HD",
2213 { &dw2102_table[GOTVIEW_SAT_HD], NULL },
2219 static struct dvb_usb_device_properties t220_properties = {
2220 .caps = DVB_USB_IS_AN_I2C_ADAPTER,
2221 .usb_ctrl = DEVICE_SPECIFIC,
2222 .size_of_priv = sizeof(struct dw2102_state),
2223 .power_ctrl = su3000_power_ctrl,
2225 .identify_state = su3000_identify_state,
2226 .i2c_algo = &su3000_i2c_algo,
2230 .rc_codes = RC_MAP_SU3000,
2231 .module_name = "dw2102",
2232 .allowed_protos = RC_PROTO_BIT_RC5,
2233 .rc_query = su3000_rc_query,
2236 .read_mac_address = su3000_read_mac_address,
2238 .generic_bulk_ctrl_endpoint = 0x01,
2244 .streaming_ctrl = su3000_streaming_ctrl,
2245 .frontend_attach = t220_frontend_attach,
2259 .num_device_descs = 1,
2261 { "Geniatech T220 DVB-T/T2 USB2.0",
2262 { &dw2102_table[GENIATECH_T220], NULL },
2268 static struct dvb_usb_device_properties tt_s2_4600_properties = {
2269 .caps = DVB_USB_IS_AN_I2C_ADAPTER,
2270 .usb_ctrl = DEVICE_SPECIFIC,
2271 .size_of_priv = sizeof(struct dw2102_state),
2272 .power_ctrl = su3000_power_ctrl,
2274 .identify_state = su3000_identify_state,
2275 .i2c_algo = &su3000_i2c_algo,
2279 .rc_codes = RC_MAP_TT_1500,
2280 .module_name = "dw2102",
2281 .allowed_protos = RC_PROTO_BIT_RC5,
2282 .rc_query = su3000_rc_query,
2285 .read_mac_address = su3000_read_mac_address,
2287 .generic_bulk_ctrl_endpoint = 0x01,
2293 .streaming_ctrl = su3000_streaming_ctrl,
2294 .frontend_attach = tt_s2_4600_frontend_attach,
2308 .num_device_descs = 5,
2310 { "TechnoTrend TT-connect S2-4600",
2311 { &dw2102_table[TECHNOTREND_S2_4600], NULL },
2314 { "TeVii S482 (tuner 1)",
2315 { &dw2102_table[TEVII_S482_1], NULL },
2318 { "TeVii S482 (tuner 2)",
2319 { &dw2102_table[TEVII_S482_2], NULL },
2322 { "Terratec Cinergy S2 USB BOX",
2323 { &dw2102_table[TERRATEC_CINERGY_S2_BOX], NULL },
2327 { &dw2102_table[TEVII_S662], NULL },
2333 static int dw2102_probe(struct usb_interface *intf,
2334 const struct usb_device_id *id)
2336 int retval = -ENOMEM;
2337 p1100 = kmemdup(&s6x0_properties,
2338 sizeof(struct dvb_usb_device_properties), GFP_KERNEL);
2342 /* copy default structure */
2343 /* fill only different fields */
2344 p1100->firmware = P1100_FIRMWARE;
2345 p1100->devices[0] = d1100;
2346 p1100->rc.core.rc_query = prof_rc_query;
2347 p1100->rc.core.rc_codes = RC_MAP_TBS_NEC;
2348 p1100->adapter->fe[0].frontend_attach = stv0288_frontend_attach;
2350 s660 = kmemdup(&s6x0_properties,
2351 sizeof(struct dvb_usb_device_properties), GFP_KERNEL);
2355 s660->firmware = S660_FIRMWARE;
2356 s660->num_device_descs = 3;
2357 s660->devices[0] = d660;
2358 s660->devices[1] = d480_1;
2359 s660->devices[2] = d480_2;
2360 s660->adapter->fe[0].frontend_attach = ds3000_frontend_attach;
2362 p7500 = kmemdup(&s6x0_properties,
2363 sizeof(struct dvb_usb_device_properties), GFP_KERNEL);
2367 p7500->firmware = P7500_FIRMWARE;
2368 p7500->devices[0] = d7500;
2369 p7500->rc.core.rc_query = prof_rc_query;
2370 p7500->rc.core.rc_codes = RC_MAP_TBS_NEC;
2371 p7500->adapter->fe[0].frontend_attach = prof_7500_frontend_attach;
2374 s421 = kmemdup(&su3000_properties,
2375 sizeof(struct dvb_usb_device_properties), GFP_KERNEL);
2379 s421->num_device_descs = 2;
2380 s421->devices[0] = d421;
2381 s421->devices[1] = d632;
2382 s421->adapter->fe[0].frontend_attach = m88rs2000_frontend_attach;
2384 if (0 == dvb_usb_device_init(intf, &dw2102_properties,
2385 THIS_MODULE, NULL, adapter_nr) ||
2386 0 == dvb_usb_device_init(intf, &dw2104_properties,
2387 THIS_MODULE, NULL, adapter_nr) ||
2388 0 == dvb_usb_device_init(intf, &dw3101_properties,
2389 THIS_MODULE, NULL, adapter_nr) ||
2390 0 == dvb_usb_device_init(intf, &s6x0_properties,
2391 THIS_MODULE, NULL, adapter_nr) ||
2392 0 == dvb_usb_device_init(intf, p1100,
2393 THIS_MODULE, NULL, adapter_nr) ||
2394 0 == dvb_usb_device_init(intf, s660,
2395 THIS_MODULE, NULL, adapter_nr) ||
2396 0 == dvb_usb_device_init(intf, p7500,
2397 THIS_MODULE, NULL, adapter_nr) ||
2398 0 == dvb_usb_device_init(intf, s421,
2399 THIS_MODULE, NULL, adapter_nr) ||
2400 0 == dvb_usb_device_init(intf, &su3000_properties,
2401 THIS_MODULE, NULL, adapter_nr) ||
2402 0 == dvb_usb_device_init(intf, &t220_properties,
2403 THIS_MODULE, NULL, adapter_nr) ||
2404 0 == dvb_usb_device_init(intf, &tt_s2_4600_properties,
2405 THIS_MODULE, NULL, adapter_nr))
2420 static void dw2102_disconnect(struct usb_interface *intf)
2422 struct dvb_usb_device *d = usb_get_intfdata(intf);
2423 struct dw2102_state *st = (struct dw2102_state *)d->priv;
2424 struct i2c_client *client;
2426 /* remove I2C client for tuner */
2427 client = st->i2c_client_tuner;
2429 module_put(client->dev.driver->owner);
2430 i2c_unregister_device(client);
2433 /* remove I2C client for demodulator */
2434 client = st->i2c_client_demod;
2436 module_put(client->dev.driver->owner);
2437 i2c_unregister_device(client);
2440 dvb_usb_device_exit(intf);
2443 static struct usb_driver dw2102_driver = {
2445 .probe = dw2102_probe,
2446 .disconnect = dw2102_disconnect,
2447 .id_table = dw2102_table,
2450 module_usb_driver(dw2102_driver);
2452 MODULE_AUTHOR("Igor M. Liplianin (c) liplianin@me.by");
2453 MODULE_DESCRIPTION("Driver for DVBWorld DVB-S 2101, 2102, DVB-S2 2104, DVB-C 3101 USB2.0, TeVii S421, S480, S482, S600, S630, S632, S650, TeVii S660, S662, Prof 1100, 7500 USB2.0, Geniatech SU3000, T220, TechnoTrend S2-4600, Terratec Cinergy S2 devices");
2454 MODULE_VERSION("0.1");
2455 MODULE_LICENSE("GPL");
2456 MODULE_FIRMWARE(DW2101_FIRMWARE);
2457 MODULE_FIRMWARE(DW2102_FIRMWARE);
2458 MODULE_FIRMWARE(DW2104_FIRMWARE);
2459 MODULE_FIRMWARE(DW3101_FIRMWARE);
2460 MODULE_FIRMWARE(S630_FIRMWARE);
2461 MODULE_FIRMWARE(S660_FIRMWARE);
2462 MODULE_FIRMWARE(P1100_FIRMWARE);
2463 MODULE_FIRMWARE(P7500_FIRMWARE);