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 4=stv0903+stb6100(or-able)).");
92 DVB_DEFINE_MOD_OPT_ADAPTER_NR(adapter_nr);
94 static int dw210x_op_rw(struct usb_device *dev, u8 request, u16 value,
95 u16 index, u8 * data, u16 len, int flags)
99 unsigned int pipe = (flags == DW210X_READ_MSG) ?
100 usb_rcvctrlpipe(dev, 0) : usb_sndctrlpipe(dev, 0);
101 u8 request_type = (flags == DW210X_READ_MSG) ? USB_DIR_IN : USB_DIR_OUT;
103 u8buf = kmalloc(len, GFP_KERNEL);
108 if (flags == DW210X_WRITE_MSG)
109 memcpy(u8buf, data, len);
110 ret = usb_control_msg(dev, pipe, request, request_type | USB_TYPE_VENDOR,
111 value, index , u8buf, len, 2000);
113 if (flags == DW210X_READ_MSG)
114 memcpy(data, u8buf, len);
121 static int dw2102_i2c_transfer(struct i2c_adapter *adap, struct i2c_msg msg[],
124 struct dvb_usb_device *d = i2c_get_adapdata(adap);
126 u8 buf6[] = {0x2c, 0x05, 0xc0, 0, 0, 0, 0};
131 if (mutex_lock_interruptible(&d->i2c_mutex) < 0)
136 if (msg[0].len < 1) {
140 /* read stv0299 register */
141 value = msg[0].buf[0];/* register */
142 for (i = 0; i < msg[1].len; i++) {
143 dw210x_op_rw(d->udev, 0xb5, value + i, 0,
144 buf6, 2, DW210X_READ_MSG);
145 msg[1].buf[i] = buf6[0];
149 switch (msg[0].addr) {
151 if (msg[0].len < 2) {
155 /* write to stv0299 register */
157 buf6[1] = msg[0].buf[0];
158 buf6[2] = msg[0].buf[1];
159 dw210x_op_rw(d->udev, 0xb2, 0, 0,
160 buf6, 3, DW210X_WRITE_MSG);
163 if (msg[0].flags == 0) {
164 if (msg[0].len < 4) {
168 /* write to tuner pll */
172 buf6[3] = msg[0].buf[0];
173 buf6[4] = msg[0].buf[1];
174 buf6[5] = msg[0].buf[2];
175 buf6[6] = msg[0].buf[3];
176 dw210x_op_rw(d->udev, 0xb2, 0, 0,
177 buf6, 7, DW210X_WRITE_MSG);
179 if (msg[0].len < 1) {
183 /* read from tuner */
184 dw210x_op_rw(d->udev, 0xb5, 0, 0,
185 buf6, 1, DW210X_READ_MSG);
186 msg[0].buf[0] = buf6[0];
189 case (DW2102_RC_QUERY):
190 if (msg[0].len < 2) {
194 dw210x_op_rw(d->udev, 0xb8, 0, 0,
195 buf6, 2, DW210X_READ_MSG);
196 msg[0].buf[0] = buf6[0];
197 msg[0].buf[1] = buf6[1];
199 case (DW2102_VOLTAGE_CTRL):
200 if (msg[0].len < 1) {
205 buf6[1] = msg[0].buf[0];
206 dw210x_op_rw(d->udev, 0xb2, 0, 0,
207 buf6, 2, DW210X_WRITE_MSG);
214 mutex_unlock(&d->i2c_mutex);
218 static int dw2102_serit_i2c_transfer(struct i2c_adapter *adap,
219 struct i2c_msg msg[], int num)
221 struct dvb_usb_device *d = i2c_get_adapdata(adap);
222 u8 buf6[] = {0, 0, 0, 0, 0, 0, 0};
226 if (mutex_lock_interruptible(&d->i2c_mutex) < 0)
231 if (msg[0].len != 1) {
232 warn("i2c rd: len=%d is not 1!\n",
238 if (2 + msg[1].len > sizeof(buf6)) {
239 warn("i2c rd: len=%d is too big!\n",
245 /* read si2109 register by number */
246 buf6[0] = msg[0].addr << 1;
247 buf6[1] = msg[0].len;
248 buf6[2] = msg[0].buf[0];
249 dw210x_op_rw(d->udev, 0xc2, 0, 0,
250 buf6, msg[0].len + 2, DW210X_WRITE_MSG);
251 /* read si2109 register */
252 dw210x_op_rw(d->udev, 0xc3, 0xd0, 0,
253 buf6, msg[1].len + 2, DW210X_READ_MSG);
254 memcpy(msg[1].buf, buf6 + 2, msg[1].len);
258 switch (msg[0].addr) {
260 if (2 + msg[0].len > sizeof(buf6)) {
261 warn("i2c wr: len=%d is too big!\n",
267 /* write to si2109 register */
268 buf6[0] = msg[0].addr << 1;
269 buf6[1] = msg[0].len;
270 memcpy(buf6 + 2, msg[0].buf, msg[0].len);
271 dw210x_op_rw(d->udev, 0xc2, 0, 0, buf6,
272 msg[0].len + 2, DW210X_WRITE_MSG);
274 case(DW2102_RC_QUERY):
275 dw210x_op_rw(d->udev, 0xb8, 0, 0,
276 buf6, 2, DW210X_READ_MSG);
277 msg[0].buf[0] = buf6[0];
278 msg[0].buf[1] = buf6[1];
280 case(DW2102_VOLTAGE_CTRL):
282 buf6[1] = msg[0].buf[0];
283 dw210x_op_rw(d->udev, 0xb2, 0, 0,
284 buf6, 2, DW210X_WRITE_MSG);
290 mutex_unlock(&d->i2c_mutex);
294 static int dw2102_earda_i2c_transfer(struct i2c_adapter *adap, struct i2c_msg msg[], int num)
296 struct dvb_usb_device *d = i2c_get_adapdata(adap);
301 if (mutex_lock_interruptible(&d->i2c_mutex) < 0)
307 /* first write first register number */
308 u8 ibuf[MAX_XFER_SIZE], obuf[3];
310 if (2 + msg[0].len != sizeof(obuf)) {
311 warn("i2c rd: len=%d is not 1!\n",
317 if (2 + msg[1].len > sizeof(ibuf)) {
318 warn("i2c rd: len=%d is too big!\n",
324 obuf[0] = msg[0].addr << 1;
325 obuf[1] = msg[0].len;
326 obuf[2] = msg[0].buf[0];
327 dw210x_op_rw(d->udev, 0xc2, 0, 0,
328 obuf, msg[0].len + 2, DW210X_WRITE_MSG);
329 /* second read registers */
330 dw210x_op_rw(d->udev, 0xc3, 0xd1 , 0,
331 ibuf, msg[1].len + 2, DW210X_READ_MSG);
332 memcpy(msg[1].buf, ibuf + 2, msg[1].len);
337 switch (msg[0].addr) {
339 /* write to register */
340 u8 obuf[MAX_XFER_SIZE];
342 if (2 + msg[0].len > sizeof(obuf)) {
343 warn("i2c wr: len=%d is too big!\n",
349 obuf[0] = msg[0].addr << 1;
350 obuf[1] = msg[0].len;
351 memcpy(obuf + 2, msg[0].buf, msg[0].len);
352 dw210x_op_rw(d->udev, 0xc2, 0, 0,
353 obuf, msg[0].len + 2, DW210X_WRITE_MSG);
358 u8 obuf[MAX_XFER_SIZE];
360 if (2 + msg[0].len > sizeof(obuf)) {
361 warn("i2c wr: len=%d is too big!\n",
367 obuf[0] = msg[0].addr << 1;
368 obuf[1] = msg[0].len;
369 memcpy(obuf + 2, msg[0].buf, msg[0].len);
370 dw210x_op_rw(d->udev, 0xc2, 0, 0,
371 obuf, msg[0].len + 2, DW210X_WRITE_MSG);
374 case(DW2102_RC_QUERY): {
376 dw210x_op_rw(d->udev, 0xb8, 0, 0,
377 ibuf, 2, DW210X_READ_MSG);
378 memcpy(msg[0].buf, ibuf , 2);
381 case(DW2102_VOLTAGE_CTRL): {
384 obuf[1] = msg[0].buf[0];
385 dw210x_op_rw(d->udev, 0xb2, 0, 0,
386 obuf, 2, DW210X_WRITE_MSG);
396 mutex_unlock(&d->i2c_mutex);
400 static int dw2104_i2c_transfer(struct i2c_adapter *adap, struct i2c_msg msg[], int num)
402 struct dvb_usb_device *d = i2c_get_adapdata(adap);
407 if (mutex_lock_interruptible(&d->i2c_mutex) < 0)
410 for (j = 0; j < num; j++) {
411 switch (msg[j].addr) {
412 case(DW2102_RC_QUERY): {
414 dw210x_op_rw(d->udev, 0xb8, 0, 0,
415 ibuf, 2, DW210X_READ_MSG);
416 memcpy(msg[j].buf, ibuf , 2);
419 case(DW2102_VOLTAGE_CTRL): {
422 obuf[1] = msg[j].buf[0];
423 dw210x_op_rw(d->udev, 0xb2, 0, 0,
424 obuf, 2, DW210X_WRITE_MSG);
429 case 0x68: ds3000, stv0903
430 case 0x60: ts2020, stv6110, stb6100 */
432 if (msg[j].flags == I2C_M_RD) {
434 u8 ibuf[MAX_XFER_SIZE];
436 if (2 + msg[j].len > sizeof(ibuf)) {
437 warn("i2c rd: len=%d is too big!\n",
443 dw210x_op_rw(d->udev, 0xc3,
444 (msg[j].addr << 1) + 1, 0,
445 ibuf, msg[j].len + 2,
447 memcpy(msg[j].buf, ibuf + 2, msg[j].len);
449 } else if (((msg[j].buf[0] == 0xb0) &&
450 (msg[j].addr == 0x68)) ||
451 ((msg[j].buf[0] == 0xf7) &&
452 (msg[j].addr == 0x55))) {
455 obuf[0] = msg[j].addr << 1;
456 obuf[1] = (msg[j].len > 15 ? 17 : msg[j].len);
457 obuf[2] = msg[j].buf[0];
458 len = msg[j].len - 1;
461 memcpy(obuf + 3, msg[j].buf + i,
462 (len > 16 ? 16 : len));
463 dw210x_op_rw(d->udev, 0xc2, 0, 0,
464 obuf, (len > 16 ? 16 : len) + 3,
470 /* write registers */
471 u8 obuf[MAX_XFER_SIZE];
473 if (2 + msg[j].len > sizeof(obuf)) {
474 warn("i2c wr: len=%d is too big!\n",
480 obuf[0] = msg[j].addr << 1;
481 obuf[1] = msg[j].len;
482 memcpy(obuf + 2, msg[j].buf, msg[j].len);
483 dw210x_op_rw(d->udev, 0xc2, 0, 0,
484 obuf, msg[j].len + 2,
495 mutex_unlock(&d->i2c_mutex);
499 static int dw3101_i2c_transfer(struct i2c_adapter *adap, struct i2c_msg msg[],
502 struct dvb_usb_device *d = i2c_get_adapdata(adap);
508 if (mutex_lock_interruptible(&d->i2c_mutex) < 0)
514 /* first write first register number */
515 u8 ibuf[MAX_XFER_SIZE], obuf[3];
517 if (2 + msg[0].len != sizeof(obuf)) {
518 warn("i2c rd: len=%d is not 1!\n",
523 if (2 + msg[1].len > sizeof(ibuf)) {
524 warn("i2c rd: len=%d is too big!\n",
529 obuf[0] = msg[0].addr << 1;
530 obuf[1] = msg[0].len;
531 obuf[2] = msg[0].buf[0];
532 dw210x_op_rw(d->udev, 0xc2, 0, 0,
533 obuf, msg[0].len + 2, DW210X_WRITE_MSG);
534 /* second read registers */
535 dw210x_op_rw(d->udev, 0xc3, 0x19 , 0,
536 ibuf, msg[1].len + 2, DW210X_READ_MSG);
537 memcpy(msg[1].buf, ibuf + 2, msg[1].len);
542 switch (msg[0].addr) {
545 /* write to register */
546 u8 obuf[MAX_XFER_SIZE];
548 if (2 + msg[0].len > sizeof(obuf)) {
549 warn("i2c wr: len=%d is too big!\n",
554 obuf[0] = msg[0].addr << 1;
555 obuf[1] = msg[0].len;
556 memcpy(obuf + 2, msg[0].buf, msg[0].len);
557 dw210x_op_rw(d->udev, 0xc2, 0, 0,
558 obuf, msg[0].len + 2, DW210X_WRITE_MSG);
561 case(DW2102_RC_QUERY): {
563 dw210x_op_rw(d->udev, 0xb8, 0, 0,
564 ibuf, 2, DW210X_READ_MSG);
565 memcpy(msg[0].buf, ibuf , 2);
573 for (i = 0; i < num; i++) {
574 deb_xfer("%02x:%02x: %s ", i, msg[i].addr,
575 msg[i].flags == 0 ? ">>>" : "<<<");
576 debug_dump(msg[i].buf, msg[i].len, deb_xfer);
581 mutex_unlock(&d->i2c_mutex);
585 static int s6x0_i2c_transfer(struct i2c_adapter *adap, struct i2c_msg msg[],
588 struct dvb_usb_device *d = i2c_get_adapdata(adap);
589 struct usb_device *udev;
595 if (mutex_lock_interruptible(&d->i2c_mutex) < 0)
598 for (j = 0; j < num; j++) {
599 switch (msg[j].addr) {
600 case (DW2102_RC_QUERY): {
602 dw210x_op_rw(d->udev, 0xb8, 0, 0,
603 ibuf, 5, DW210X_READ_MSG);
604 memcpy(msg[j].buf, ibuf + 3, 2);
607 case (DW2102_VOLTAGE_CTRL): {
611 obuf[1] = msg[j].buf[1];/* off-on */
612 dw210x_op_rw(d->udev, 0x8a, 0, 0,
613 obuf, 2, DW210X_WRITE_MSG);
615 obuf[1] = msg[j].buf[0];/* 13v-18v */
616 dw210x_op_rw(d->udev, 0x8a, 0, 0,
617 obuf, 2, DW210X_WRITE_MSG);
620 case (DW2102_LED_CTRL): {
624 obuf[1] = msg[j].buf[0];
625 dw210x_op_rw(d->udev, 0x8a, 0, 0,
626 obuf, 2, DW210X_WRITE_MSG);
631 case 0x68: ds3000, stv0903, rs2000
632 case 0x60: ts2020, stv6110, stb6100
635 if (msg[j].flags == I2C_M_RD) {
637 u8 ibuf[MAX_XFER_SIZE];
639 if (msg[j].len > sizeof(ibuf)) {
640 warn("i2c rd: len=%d is too big!\n",
646 dw210x_op_rw(d->udev, 0x91, 0, 0,
649 memcpy(msg[j].buf, ibuf, msg[j].len);
651 } else if ((msg[j].buf[0] == 0xb0) &&
652 (msg[j].addr == 0x68)) {
655 obuf[0] = (msg[j].len > 16 ?
656 18 : msg[j].len + 1);
657 obuf[1] = msg[j].addr << 1;
658 obuf[2] = msg[j].buf[0];
659 len = msg[j].len - 1;
662 memcpy(obuf + 3, msg[j].buf + i,
663 (len > 16 ? 16 : len));
664 dw210x_op_rw(d->udev, 0x80, 0, 0,
665 obuf, (len > 16 ? 16 : len) + 3,
670 } else if (j < (num - 1)) {
671 /* write register addr before read */
672 u8 obuf[MAX_XFER_SIZE];
674 if (2 + msg[j].len > sizeof(obuf)) {
675 warn("i2c wr: len=%d is too big!\n",
681 obuf[0] = msg[j + 1].len;
682 obuf[1] = (msg[j].addr << 1);
683 memcpy(obuf + 2, msg[j].buf, msg[j].len);
684 dw210x_op_rw(d->udev,
685 le16_to_cpu(udev->descriptor.idProduct) ==
686 0x7500 ? 0x92 : 0x90, 0, 0,
687 obuf, msg[j].len + 2,
691 /* write registers */
692 u8 obuf[MAX_XFER_SIZE];
694 if (2 + msg[j].len > sizeof(obuf)) {
695 warn("i2c wr: len=%d is too big!\n",
700 obuf[0] = msg[j].len + 1;
701 obuf[1] = (msg[j].addr << 1);
702 memcpy(obuf + 2, msg[j].buf, msg[j].len);
703 dw210x_op_rw(d->udev, 0x80, 0, 0,
704 obuf, msg[j].len + 2,
715 mutex_unlock(&d->i2c_mutex);
719 static int su3000_i2c_transfer(struct i2c_adapter *adap, struct i2c_msg msg[],
722 struct dvb_usb_device *d = i2c_get_adapdata(adap);
723 struct dw2102_state *state;
730 if (mutex_lock_interruptible(&d->i2c_mutex) < 0)
732 if (mutex_lock_interruptible(&d->data_mutex) < 0) {
733 mutex_unlock(&d->i2c_mutex);
739 switch (msg[0].addr) {
740 case SU3000_STREAM_CTRL:
741 state->data[0] = msg[0].buf[0] + 0x36;
744 if (dvb_usb_generic_rw(d, state->data, 3,
745 state->data, 0, 0) < 0)
746 err("i2c transfer failed.");
748 case DW2102_RC_QUERY:
749 state->data[0] = 0x10;
750 if (dvb_usb_generic_rw(d, state->data, 1,
751 state->data, 2, 0) < 0)
752 err("i2c transfer failed.");
753 msg[0].buf[1] = state->data[0];
754 msg[0].buf[0] = state->data[1];
757 if (3 + msg[0].len > sizeof(state->data)) {
758 warn("i2c wr: len=%d is too big!\n",
764 /* always i2c write*/
765 state->data[0] = 0x08;
766 state->data[1] = msg[0].addr;
767 state->data[2] = msg[0].len;
769 memcpy(&state->data[3], msg[0].buf, msg[0].len);
771 if (dvb_usb_generic_rw(d, state->data, msg[0].len + 3,
772 state->data, 1, 0) < 0)
773 err("i2c transfer failed.");
778 /* always i2c read */
779 if (4 + msg[0].len > sizeof(state->data)) {
780 warn("i2c rd: len=%d is too big!\n",
785 if (1 + msg[1].len > sizeof(state->data)) {
786 warn("i2c rd: len=%d is too big!\n",
792 state->data[0] = 0x09;
793 state->data[1] = msg[0].len;
794 state->data[2] = msg[1].len;
795 state->data[3] = msg[0].addr;
796 memcpy(&state->data[4], msg[0].buf, msg[0].len);
798 if (dvb_usb_generic_rw(d, state->data, msg[0].len + 4,
799 state->data, msg[1].len + 1, 0) < 0)
800 err("i2c transfer failed.");
802 memcpy(msg[1].buf, &state->data[1], msg[1].len);
805 warn("more than 2 i2c messages at a time is not handled yet.");
808 mutex_unlock(&d->data_mutex);
809 mutex_unlock(&d->i2c_mutex);
813 static u32 dw210x_i2c_func(struct i2c_adapter *adapter)
818 static struct i2c_algorithm dw2102_i2c_algo = {
819 .master_xfer = dw2102_i2c_transfer,
820 .functionality = dw210x_i2c_func,
823 static struct i2c_algorithm dw2102_serit_i2c_algo = {
824 .master_xfer = dw2102_serit_i2c_transfer,
825 .functionality = dw210x_i2c_func,
828 static struct i2c_algorithm dw2102_earda_i2c_algo = {
829 .master_xfer = dw2102_earda_i2c_transfer,
830 .functionality = dw210x_i2c_func,
833 static struct i2c_algorithm dw2104_i2c_algo = {
834 .master_xfer = dw2104_i2c_transfer,
835 .functionality = dw210x_i2c_func,
838 static struct i2c_algorithm dw3101_i2c_algo = {
839 .master_xfer = dw3101_i2c_transfer,
840 .functionality = dw210x_i2c_func,
843 static struct i2c_algorithm s6x0_i2c_algo = {
844 .master_xfer = s6x0_i2c_transfer,
845 .functionality = dw210x_i2c_func,
848 static struct i2c_algorithm su3000_i2c_algo = {
849 .master_xfer = su3000_i2c_transfer,
850 .functionality = dw210x_i2c_func,
853 static int dw210x_read_mac_address(struct dvb_usb_device *d, u8 mac[6])
857 u8 eeprom[256], eepromline[16];
859 for (i = 0; i < 256; i++) {
860 if (dw210x_op_rw(d->udev, 0xb6, 0xa0 , i, ibuf, 2, DW210X_READ_MSG) < 0) {
861 err("read eeprom failed.");
864 eepromline[i%16] = ibuf[0];
867 if ((i % 16) == 15) {
868 deb_xfer("%02x: ", i - 15);
869 debug_dump(eepromline, 16, deb_xfer);
873 memcpy(mac, eeprom + 8, 6);
877 static int s6x0_read_mac_address(struct dvb_usb_device *d, u8 mac[6])
880 u8 ibuf[] = { 0 }, obuf[] = { 0 };
881 u8 eeprom[256], eepromline[16];
882 struct i2c_msg msg[] = {
896 for (i = 0; i < 256; i++) {
898 ret = s6x0_i2c_transfer(&d->i2c_adap, msg, 2);
900 err("read eeprom failed.");
903 eepromline[i % 16] = ibuf[0];
907 if ((i % 16) == 15) {
908 deb_xfer("%02x: ", i - 15);
909 debug_dump(eepromline, 16, deb_xfer);
913 memcpy(mac, eeprom + 16, 6);
917 static int su3000_streaming_ctrl(struct dvb_usb_adapter *adap, int onoff)
919 static u8 command_start[] = {0x00};
920 static u8 command_stop[] = {0x01};
921 struct i2c_msg msg = {
922 .addr = SU3000_STREAM_CTRL,
924 .buf = onoff ? command_start : command_stop,
928 i2c_transfer(&adap->dev->i2c_adap, &msg, 1);
933 static int su3000_power_ctrl(struct dvb_usb_device *d, int i)
935 struct dw2102_state *state = (struct dw2102_state *)d->priv;
938 info("%s: %d, initialized %d", __func__, i, state->initialized);
940 if (i && !state->initialized) {
941 mutex_lock(&d->data_mutex);
943 state->data[0] = 0xde;
946 state->initialized = 1;
948 ret = dvb_usb_generic_rw(d, state->data, 2, NULL, 0, 0);
949 mutex_unlock(&d->data_mutex);
955 static int su3000_read_mac_address(struct dvb_usb_device *d, u8 mac[6])
958 u8 obuf[] = { 0x1f, 0xf0 };
960 struct i2c_msg msg[] = {
975 for (i = 0; i < 6; i++) {
977 if (i2c_transfer(&d->i2c_adap, msg, 2) != 2)
986 static int su3000_identify_state(struct usb_device *udev,
987 struct dvb_usb_device_properties *props,
988 struct dvb_usb_device_description **desc,
991 info("%s", __func__);
997 static int dw210x_set_voltage(struct dvb_frontend *fe,
998 enum fe_sec_voltage voltage)
1000 static u8 command_13v[] = {0x00, 0x01};
1001 static u8 command_18v[] = {0x01, 0x01};
1002 static u8 command_off[] = {0x00, 0x00};
1003 struct i2c_msg msg = {
1004 .addr = DW2102_VOLTAGE_CTRL,
1010 struct dvb_usb_adapter *udev_adap =
1011 (struct dvb_usb_adapter *)(fe->dvb->priv);
1012 if (voltage == SEC_VOLTAGE_18)
1013 msg.buf = command_18v;
1014 else if (voltage == SEC_VOLTAGE_13)
1015 msg.buf = command_13v;
1017 i2c_transfer(&udev_adap->dev->i2c_adap, &msg, 1);
1022 static int s660_set_voltage(struct dvb_frontend *fe,
1023 enum fe_sec_voltage voltage)
1025 struct dvb_usb_adapter *d =
1026 (struct dvb_usb_adapter *)(fe->dvb->priv);
1027 struct dw2102_state *st = (struct dw2102_state *)d->dev->priv;
1029 dw210x_set_voltage(fe, voltage);
1030 if (st->old_set_voltage)
1031 st->old_set_voltage(fe, voltage);
1036 static void dw210x_led_ctrl(struct dvb_frontend *fe, int offon)
1038 static u8 led_off[] = { 0 };
1039 static u8 led_on[] = { 1 };
1040 struct i2c_msg msg = {
1041 .addr = DW2102_LED_CTRL,
1046 struct dvb_usb_adapter *udev_adap =
1047 (struct dvb_usb_adapter *)(fe->dvb->priv);
1051 i2c_transfer(&udev_adap->dev->i2c_adap, &msg, 1);
1054 static int tt_s2_4600_read_status(struct dvb_frontend *fe,
1055 enum fe_status *status)
1057 struct dvb_usb_adapter *d =
1058 (struct dvb_usb_adapter *)(fe->dvb->priv);
1059 struct dw2102_state *st = (struct dw2102_state *)d->dev->priv;
1062 ret = st->fe_read_status(fe, status);
1064 /* resync slave fifo when signal change from unlock to lock */
1065 if ((*status & FE_HAS_LOCK) && (!st->last_lock))
1066 su3000_streaming_ctrl(d, 1);
1068 st->last_lock = (*status & FE_HAS_LOCK) ? 1 : 0;
1072 static struct stv0299_config sharp_z0194a_config = {
1073 .demod_address = 0x68,
1074 .inittab = sharp_z0194a_inittab,
1078 .lock_output = STV0299_LOCKOUTPUT_1,
1079 .volt13_op0_op1 = STV0299_VOLT13_OP1,
1080 .min_delay_ms = 100,
1081 .set_symbol_rate = sharp_z0194a_set_symbol_rate,
1084 static struct cx24116_config dw2104_config = {
1085 .demod_address = 0x55,
1086 .mpg_clk_pos_pol = 0x01,
1089 static struct si21xx_config serit_sp1511lhb_config = {
1090 .demod_address = 0x68,
1091 .min_delay_ms = 100,
1095 static struct tda10023_config dw3101_tda10023_config = {
1096 .demod_address = 0x0c,
1100 static struct mt312_config zl313_config = {
1101 .demod_address = 0x0e,
1104 static struct ds3000_config dw2104_ds3000_config = {
1105 .demod_address = 0x68,
1108 static struct ts2020_config dw2104_ts2020_config = {
1109 .tuner_address = 0x60,
1111 .frequency_div = 1060000,
1114 static struct ds3000_config s660_ds3000_config = {
1115 .demod_address = 0x68,
1117 .set_lock_led = dw210x_led_ctrl,
1120 static struct ts2020_config s660_ts2020_config = {
1121 .tuner_address = 0x60,
1123 .frequency_div = 1146000,
1126 static struct stv0900_config dw2104a_stv0900_config = {
1127 .demod_address = 0x6a,
1130 .clkmode = 3,/* 0-CLKI, 2-XTALI, else AUTO */
1131 .diseqc_mode = 2,/* 2/3 PWM */
1132 .tun1_maddress = 0,/* 0x60 */
1133 .tun1_adc = 0,/* 2 Vpp */
1137 static struct stb6100_config dw2104a_stb6100_config = {
1138 .tuner_address = 0x60,
1139 .refclock = 27000000,
1142 static struct stv0900_config dw2104_stv0900_config = {
1143 .demod_address = 0x68,
1149 .tun1_adc = 1,/* 1 Vpp */
1153 static struct stv6110_config dw2104_stv6110_config = {
1154 .i2c_address = 0x60,
1159 static struct stv0900_config prof_7500_stv0900_config = {
1160 .demod_address = 0x6a,
1163 .clkmode = 3,/* 0-CLKI, 2-XTALI, else AUTO */
1164 .diseqc_mode = 2,/* 2/3 PWM */
1165 .tun1_maddress = 0,/* 0x60 */
1166 .tun1_adc = 0,/* 2 Vpp */
1169 .set_lock_led = dw210x_led_ctrl,
1172 static struct ds3000_config su3000_ds3000_config = {
1173 .demod_address = 0x68,
1175 .set_lock_led = dw210x_led_ctrl,
1178 static struct cxd2820r_config cxd2820r_config = {
1179 .i2c_address = 0x6c, /* (0xd8 >> 1) */
1184 static struct tda18271_config tda18271_config = {
1185 .output_opt = TDA18271_OUTPUT_LT_OFF,
1186 .gate = TDA18271_GATE_DIGITAL,
1189 static u8 m88rs2000_inittab[] = {
1190 DEMOD_WRITE, 0x9a, 0x30,
1191 DEMOD_WRITE, 0x00, 0x01,
1192 WRITE_DELAY, 0x19, 0x00,
1193 DEMOD_WRITE, 0x00, 0x00,
1194 DEMOD_WRITE, 0x9a, 0xb0,
1195 DEMOD_WRITE, 0x81, 0xc1,
1196 DEMOD_WRITE, 0x81, 0x81,
1197 DEMOD_WRITE, 0x86, 0xc6,
1198 DEMOD_WRITE, 0x9a, 0x30,
1199 DEMOD_WRITE, 0xf0, 0x80,
1200 DEMOD_WRITE, 0xf1, 0xbf,
1201 DEMOD_WRITE, 0xb0, 0x45,
1202 DEMOD_WRITE, 0xb2, 0x01,
1203 DEMOD_WRITE, 0x9a, 0xb0,
1207 static struct m88rs2000_config s421_m88rs2000_config = {
1209 .inittab = m88rs2000_inittab,
1212 static int dw2104_frontend_attach(struct dvb_usb_adapter *d)
1214 struct dvb_tuner_ops *tuner_ops = NULL;
1216 if (demod_probe & 4) {
1217 d->fe_adap[0].fe = dvb_attach(stv0900_attach, &dw2104a_stv0900_config,
1218 &d->dev->i2c_adap, 0);
1219 if (d->fe_adap[0].fe != NULL) {
1220 if (dvb_attach(stb6100_attach, d->fe_adap[0].fe,
1221 &dw2104a_stb6100_config,
1222 &d->dev->i2c_adap)) {
1223 tuner_ops = &d->fe_adap[0].fe->ops.tuner_ops;
1224 tuner_ops->set_frequency = stb6100_set_freq;
1225 tuner_ops->get_frequency = stb6100_get_freq;
1226 tuner_ops->set_bandwidth = stb6100_set_bandw;
1227 tuner_ops->get_bandwidth = stb6100_get_bandw;
1228 d->fe_adap[0].fe->ops.set_voltage = dw210x_set_voltage;
1229 info("Attached STV0900+STB6100!");
1235 if (demod_probe & 2) {
1236 d->fe_adap[0].fe = dvb_attach(stv0900_attach, &dw2104_stv0900_config,
1237 &d->dev->i2c_adap, 0);
1238 if (d->fe_adap[0].fe != NULL) {
1239 if (dvb_attach(stv6110_attach, d->fe_adap[0].fe,
1240 &dw2104_stv6110_config,
1241 &d->dev->i2c_adap)) {
1242 d->fe_adap[0].fe->ops.set_voltage = dw210x_set_voltage;
1243 info("Attached STV0900+STV6110A!");
1249 if (demod_probe & 1) {
1250 d->fe_adap[0].fe = dvb_attach(cx24116_attach, &dw2104_config,
1252 if (d->fe_adap[0].fe != NULL) {
1253 d->fe_adap[0].fe->ops.set_voltage = dw210x_set_voltage;
1254 info("Attached cx24116!");
1259 d->fe_adap[0].fe = dvb_attach(ds3000_attach, &dw2104_ds3000_config,
1261 if (d->fe_adap[0].fe != NULL) {
1262 dvb_attach(ts2020_attach, d->fe_adap[0].fe,
1263 &dw2104_ts2020_config, &d->dev->i2c_adap);
1264 d->fe_adap[0].fe->ops.set_voltage = dw210x_set_voltage;
1265 info("Attached DS3000!");
1272 static struct dvb_usb_device_properties dw2102_properties;
1273 static struct dvb_usb_device_properties dw2104_properties;
1274 static struct dvb_usb_device_properties s6x0_properties;
1276 static int dw2102_frontend_attach(struct dvb_usb_adapter *d)
1278 if (dw2102_properties.i2c_algo == &dw2102_serit_i2c_algo) {
1279 /*dw2102_properties.adapter->tuner_attach = NULL;*/
1280 d->fe_adap[0].fe = dvb_attach(si21xx_attach, &serit_sp1511lhb_config,
1282 if (d->fe_adap[0].fe != NULL) {
1283 d->fe_adap[0].fe->ops.set_voltage = dw210x_set_voltage;
1284 info("Attached si21xx!");
1289 if (dw2102_properties.i2c_algo == &dw2102_earda_i2c_algo) {
1290 d->fe_adap[0].fe = dvb_attach(stv0288_attach, &earda_config,
1292 if (d->fe_adap[0].fe != NULL) {
1293 if (dvb_attach(stb6000_attach, d->fe_adap[0].fe, 0x61,
1294 &d->dev->i2c_adap)) {
1295 d->fe_adap[0].fe->ops.set_voltage = dw210x_set_voltage;
1296 info("Attached stv0288!");
1302 if (dw2102_properties.i2c_algo == &dw2102_i2c_algo) {
1303 /*dw2102_properties.adapter->tuner_attach = dw2102_tuner_attach;*/
1304 d->fe_adap[0].fe = dvb_attach(stv0299_attach, &sharp_z0194a_config,
1306 if (d->fe_adap[0].fe != NULL) {
1307 d->fe_adap[0].fe->ops.set_voltage = dw210x_set_voltage;
1308 info("Attached stv0299!");
1315 static int dw3101_frontend_attach(struct dvb_usb_adapter *d)
1317 d->fe_adap[0].fe = dvb_attach(tda10023_attach, &dw3101_tda10023_config,
1318 &d->dev->i2c_adap, 0x48);
1319 if (d->fe_adap[0].fe != NULL) {
1320 info("Attached tda10023!");
1326 static int zl100313_frontend_attach(struct dvb_usb_adapter *d)
1328 d->fe_adap[0].fe = dvb_attach(mt312_attach, &zl313_config,
1330 if (d->fe_adap[0].fe != NULL) {
1331 if (dvb_attach(zl10039_attach, d->fe_adap[0].fe, 0x60,
1332 &d->dev->i2c_adap)) {
1333 d->fe_adap[0].fe->ops.set_voltage = dw210x_set_voltage;
1334 info("Attached zl100313+zl10039!");
1342 static int stv0288_frontend_attach(struct dvb_usb_adapter *d)
1346 d->fe_adap[0].fe = dvb_attach(stv0288_attach, &earda_config,
1349 if (d->fe_adap[0].fe == NULL)
1352 if (NULL == dvb_attach(stb6000_attach, d->fe_adap[0].fe, 0x61, &d->dev->i2c_adap))
1355 d->fe_adap[0].fe->ops.set_voltage = dw210x_set_voltage;
1357 dw210x_op_rw(d->dev->udev, 0x8a, 0, 0, obuf, 2, DW210X_WRITE_MSG);
1359 info("Attached stv0288+stb6000!");
1365 static int ds3000_frontend_attach(struct dvb_usb_adapter *d)
1367 struct dw2102_state *st = d->dev->priv;
1370 d->fe_adap[0].fe = dvb_attach(ds3000_attach, &s660_ds3000_config,
1373 if (d->fe_adap[0].fe == NULL)
1376 dvb_attach(ts2020_attach, d->fe_adap[0].fe, &s660_ts2020_config,
1379 st->old_set_voltage = d->fe_adap[0].fe->ops.set_voltage;
1380 d->fe_adap[0].fe->ops.set_voltage = s660_set_voltage;
1382 dw210x_op_rw(d->dev->udev, 0x8a, 0, 0, obuf, 2, DW210X_WRITE_MSG);
1384 info("Attached ds3000+ts2020!");
1389 static int prof_7500_frontend_attach(struct dvb_usb_adapter *d)
1393 d->fe_adap[0].fe = dvb_attach(stv0900_attach, &prof_7500_stv0900_config,
1394 &d->dev->i2c_adap, 0);
1395 if (d->fe_adap[0].fe == NULL)
1398 d->fe_adap[0].fe->ops.set_voltage = dw210x_set_voltage;
1400 dw210x_op_rw(d->dev->udev, 0x8a, 0, 0, obuf, 2, DW210X_WRITE_MSG);
1402 info("Attached STV0900+STB6100A!");
1407 static int su3000_frontend_attach(struct dvb_usb_adapter *adap)
1409 struct dvb_usb_device *d = adap->dev;
1410 struct dw2102_state *state = d->priv;
1412 mutex_lock(&d->data_mutex);
1414 state->data[0] = 0xe;
1415 state->data[1] = 0x80;
1418 if (dvb_usb_generic_rw(d, state->data, 3, state->data, 1, 0) < 0)
1419 err("command 0x0e transfer failed.");
1421 state->data[0] = 0xe;
1422 state->data[1] = 0x02;
1425 if (dvb_usb_generic_rw(d, state->data, 3, state->data, 1, 0) < 0)
1426 err("command 0x0e transfer failed.");
1429 state->data[0] = 0xe;
1430 state->data[1] = 0x83;
1433 if (dvb_usb_generic_rw(d, state->data, 3, state->data, 1, 0) < 0)
1434 err("command 0x0e transfer failed.");
1436 state->data[0] = 0xe;
1437 state->data[1] = 0x83;
1440 if (dvb_usb_generic_rw(d, state->data, 3, state->data, 1, 0) < 0)
1441 err("command 0x0e transfer failed.");
1443 state->data[0] = 0x51;
1445 if (dvb_usb_generic_rw(d, state->data, 1, state->data, 1, 0) < 0)
1446 err("command 0x51 transfer failed.");
1448 mutex_unlock(&d->data_mutex);
1450 adap->fe_adap[0].fe = dvb_attach(ds3000_attach, &su3000_ds3000_config,
1452 if (adap->fe_adap[0].fe == NULL)
1455 if (dvb_attach(ts2020_attach, adap->fe_adap[0].fe,
1456 &dw2104_ts2020_config,
1458 info("Attached DS3000/TS2020!");
1462 info("Failed to attach DS3000/TS2020!");
1466 static int t220_frontend_attach(struct dvb_usb_adapter *adap)
1468 struct dvb_usb_device *d = adap->dev;
1469 struct dw2102_state *state = d->priv;
1471 mutex_lock(&d->data_mutex);
1473 state->data[0] = 0xe;
1474 state->data[1] = 0x87;
1475 state->data[2] = 0x0;
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] = 0xe;
1481 state->data[1] = 0x86;
1484 if (dvb_usb_generic_rw(d, state->data, 3, state->data, 1, 0) < 0)
1485 err("command 0x0e transfer failed.");
1487 state->data[0] = 0xe;
1488 state->data[1] = 0x80;
1491 if (dvb_usb_generic_rw(d, state->data, 3, state->data, 1, 0) < 0)
1492 err("command 0x0e transfer failed.");
1496 state->data[0] = 0xe;
1497 state->data[1] = 0x80;
1500 if (dvb_usb_generic_rw(d, state->data, 3, state->data, 1, 0) < 0)
1501 err("command 0x0e transfer failed.");
1503 state->data[0] = 0x51;
1505 if (dvb_usb_generic_rw(d, state->data, 1, state->data, 1, 0) < 0)
1506 err("command 0x51 transfer failed.");
1508 mutex_unlock(&d->data_mutex);
1510 adap->fe_adap[0].fe = dvb_attach(cxd2820r_attach, &cxd2820r_config,
1511 &d->i2c_adap, NULL);
1512 if (adap->fe_adap[0].fe != NULL) {
1513 if (dvb_attach(tda18271_attach, adap->fe_adap[0].fe, 0x60,
1514 &d->i2c_adap, &tda18271_config)) {
1515 info("Attached TDA18271HD/CXD2820R!");
1520 info("Failed to attach TDA18271HD/CXD2820R!");
1524 static int m88rs2000_frontend_attach(struct dvb_usb_adapter *adap)
1526 struct dvb_usb_device *d = adap->dev;
1527 struct dw2102_state *state = d->priv;
1529 mutex_lock(&d->data_mutex);
1531 state->data[0] = 0x51;
1533 if (dvb_usb_generic_rw(d, state->data, 1, state->data, 1, 0) < 0)
1534 err("command 0x51 transfer failed.");
1536 mutex_unlock(&d->data_mutex);
1538 adap->fe_adap[0].fe = dvb_attach(m88rs2000_attach,
1539 &s421_m88rs2000_config,
1542 if (adap->fe_adap[0].fe == NULL)
1545 if (dvb_attach(ts2020_attach, adap->fe_adap[0].fe,
1546 &dw2104_ts2020_config,
1548 info("Attached RS2000/TS2020!");
1552 info("Failed to attach RS2000/TS2020!");
1556 static int tt_s2_4600_frontend_attach(struct dvb_usb_adapter *adap)
1558 struct dvb_usb_device *d = adap->dev;
1559 struct dw2102_state *state = d->priv;
1560 struct i2c_adapter *i2c_adapter;
1561 struct i2c_client *client;
1562 struct i2c_board_info board_info;
1563 struct m88ds3103_platform_data m88ds3103_pdata = {};
1564 struct ts2020_config ts2020_config = {};
1566 mutex_lock(&d->data_mutex);
1568 state->data[0] = 0xe;
1569 state->data[1] = 0x80;
1570 state->data[2] = 0x0;
1572 if (dvb_usb_generic_rw(d, state->data, 3, state->data, 1, 0) < 0)
1573 err("command 0x0e transfer failed.");
1575 state->data[0] = 0xe;
1576 state->data[1] = 0x02;
1579 if (dvb_usb_generic_rw(d, state->data, 3, state->data, 1, 0) < 0)
1580 err("command 0x0e transfer failed.");
1583 state->data[0] = 0xe;
1584 state->data[1] = 0x83;
1587 if (dvb_usb_generic_rw(d, state->data, 3, state->data, 1, 0) < 0)
1588 err("command 0x0e transfer failed.");
1590 state->data[0] = 0xe;
1591 state->data[1] = 0x83;
1594 if (dvb_usb_generic_rw(d, state->data, 3, state->data, 1, 0) < 0)
1595 err("command 0x0e transfer failed.");
1597 state->data[0] = 0x51;
1599 if (dvb_usb_generic_rw(d, state->data, 1, state->data, 1, 0) < 0)
1600 err("command 0x51 transfer failed.");
1602 mutex_unlock(&d->data_mutex);
1605 m88ds3103_pdata.clk = 27000000;
1606 m88ds3103_pdata.i2c_wr_max = 33;
1607 m88ds3103_pdata.ts_mode = M88DS3103_TS_CI;
1608 m88ds3103_pdata.ts_clk = 16000;
1609 m88ds3103_pdata.ts_clk_pol = 0;
1610 m88ds3103_pdata.spec_inv = 0;
1611 m88ds3103_pdata.agc = 0x99;
1612 m88ds3103_pdata.agc_inv = 0;
1613 m88ds3103_pdata.clk_out = M88DS3103_CLOCK_OUT_ENABLED;
1614 m88ds3103_pdata.envelope_mode = 0;
1615 m88ds3103_pdata.lnb_hv_pol = 1;
1616 m88ds3103_pdata.lnb_en_pol = 0;
1617 memset(&board_info, 0, sizeof(board_info));
1618 strlcpy(board_info.type, "m88ds3103", I2C_NAME_SIZE);
1619 board_info.addr = 0x68;
1620 board_info.platform_data = &m88ds3103_pdata;
1621 request_module("m88ds3103");
1622 client = i2c_new_device(&d->i2c_adap, &board_info);
1623 if (client == NULL || client->dev.driver == NULL)
1625 if (!try_module_get(client->dev.driver->owner)) {
1626 i2c_unregister_device(client);
1629 adap->fe_adap[0].fe = m88ds3103_pdata.get_dvb_frontend(client);
1630 i2c_adapter = m88ds3103_pdata.get_i2c_adapter(client);
1632 state->i2c_client_demod = client;
1635 ts2020_config.fe = adap->fe_adap[0].fe;
1636 memset(&board_info, 0, sizeof(board_info));
1637 strlcpy(board_info.type, "ts2022", I2C_NAME_SIZE);
1638 board_info.addr = 0x60;
1639 board_info.platform_data = &ts2020_config;
1640 request_module("ts2020");
1641 client = i2c_new_device(i2c_adapter, &board_info);
1643 if (client == NULL || client->dev.driver == NULL) {
1644 dvb_frontend_detach(adap->fe_adap[0].fe);
1648 if (!try_module_get(client->dev.driver->owner)) {
1649 i2c_unregister_device(client);
1650 dvb_frontend_detach(adap->fe_adap[0].fe);
1654 /* delegate signal strength measurement to tuner */
1655 adap->fe_adap[0].fe->ops.read_signal_strength =
1656 adap->fe_adap[0].fe->ops.tuner_ops.get_rf_strength;
1658 state->i2c_client_tuner = client;
1660 /* hook fe: need to resync the slave fifo when signal locks */
1661 state->fe_read_status = adap->fe_adap[0].fe->ops.read_status;
1662 adap->fe_adap[0].fe->ops.read_status = tt_s2_4600_read_status;
1664 state->last_lock = 0;
1669 static int dw2102_tuner_attach(struct dvb_usb_adapter *adap)
1671 dvb_attach(dvb_pll_attach, adap->fe_adap[0].fe, 0x60,
1672 &adap->dev->i2c_adap, DVB_PLL_OPERA1);
1676 static int dw3101_tuner_attach(struct dvb_usb_adapter *adap)
1678 dvb_attach(dvb_pll_attach, adap->fe_adap[0].fe, 0x60,
1679 &adap->dev->i2c_adap, DVB_PLL_TUA6034);
1684 static int dw2102_rc_query(struct dvb_usb_device *d)
1687 struct i2c_msg msg = {
1688 .addr = DW2102_RC_QUERY,
1694 if (d->props.i2c_algo->master_xfer(&d->i2c_adap, &msg, 1) == 1) {
1695 if (msg.buf[0] != 0xff) {
1696 deb_rc("%s: rc code: %x, %x\n",
1697 __func__, key[0], key[1]);
1698 rc_keydown(d->rc_dev, RC_PROTO_UNKNOWN, key[0], 0);
1705 static int prof_rc_query(struct dvb_usb_device *d)
1708 struct i2c_msg msg = {
1709 .addr = DW2102_RC_QUERY,
1715 if (d->props.i2c_algo->master_xfer(&d->i2c_adap, &msg, 1) == 1) {
1716 if (msg.buf[0] != 0xff) {
1717 deb_rc("%s: rc code: %x, %x\n",
1718 __func__, key[0], key[1]);
1719 rc_keydown(d->rc_dev, RC_PROTO_UNKNOWN, key[0] ^ 0xff,
1727 static int su3000_rc_query(struct dvb_usb_device *d)
1730 struct i2c_msg msg = {
1731 .addr = DW2102_RC_QUERY,
1737 if (d->props.i2c_algo->master_xfer(&d->i2c_adap, &msg, 1) == 1) {
1738 if (msg.buf[0] != 0xff) {
1739 deb_rc("%s: rc code: %x, %x\n",
1740 __func__, key[0], key[1]);
1741 rc_keydown(d->rc_dev, RC_PROTO_RC5,
1742 RC_SCANCODE_RC5(key[1], key[0]), 0);
1749 enum dw2102_table_entry {
1761 TERRATEC_CINERGY_S2,
1767 TERRATEC_CINERGY_S2_R2,
1768 TERRATEC_CINERGY_S2_R3,
1769 TERRATEC_CINERGY_S2_R4,
1772 TECHNOTREND_S2_4600,
1775 TERRATEC_CINERGY_S2_BOX,
1779 static struct usb_device_id dw2102_table[] = {
1780 [CYPRESS_DW2102] = {USB_DEVICE(USB_VID_CYPRESS, USB_PID_DW2102)},
1781 [CYPRESS_DW2101] = {USB_DEVICE(USB_VID_CYPRESS, 0x2101)},
1782 [CYPRESS_DW2104] = {USB_DEVICE(USB_VID_CYPRESS, USB_PID_DW2104)},
1783 [TEVII_S650] = {USB_DEVICE(0x9022, USB_PID_TEVII_S650)},
1784 [TERRATEC_CINERGY_S] = {USB_DEVICE(USB_VID_TERRATEC, USB_PID_TERRATEC_CINERGY_S)},
1785 [CYPRESS_DW3101] = {USB_DEVICE(USB_VID_CYPRESS, USB_PID_DW3101)},
1786 [TEVII_S630] = {USB_DEVICE(0x9022, USB_PID_TEVII_S630)},
1787 [PROF_1100] = {USB_DEVICE(0x3011, USB_PID_PROF_1100)},
1788 [TEVII_S660] = {USB_DEVICE(0x9022, USB_PID_TEVII_S660)},
1789 [PROF_7500] = {USB_DEVICE(0x3034, 0x7500)},
1790 [GENIATECH_SU3000] = {USB_DEVICE(0x1f4d, 0x3000)},
1791 [TERRATEC_CINERGY_S2] = {USB_DEVICE(USB_VID_TERRATEC, USB_PID_TERRATEC_CINERGY_S2_R1)},
1792 [TEVII_S480_1] = {USB_DEVICE(0x9022, USB_PID_TEVII_S480_1)},
1793 [TEVII_S480_2] = {USB_DEVICE(0x9022, USB_PID_TEVII_S480_2)},
1794 [X3M_SPC1400HD] = {USB_DEVICE(0x1f4d, 0x3100)},
1795 [TEVII_S421] = {USB_DEVICE(0x9022, USB_PID_TEVII_S421)},
1796 [TEVII_S632] = {USB_DEVICE(0x9022, USB_PID_TEVII_S632)},
1797 [TERRATEC_CINERGY_S2_R2] = {USB_DEVICE(USB_VID_TERRATEC, USB_PID_TERRATEC_CINERGY_S2_R2)},
1798 [TERRATEC_CINERGY_S2_R3] = {USB_DEVICE(USB_VID_TERRATEC, USB_PID_TERRATEC_CINERGY_S2_R3)},
1799 [TERRATEC_CINERGY_S2_R4] = {USB_DEVICE(USB_VID_TERRATEC, USB_PID_TERRATEC_CINERGY_S2_R4)},
1800 [GOTVIEW_SAT_HD] = {USB_DEVICE(0x1FE1, USB_PID_GOTVIEW_SAT_HD)},
1801 [GENIATECH_T220] = {USB_DEVICE(0x1f4d, 0xD220)},
1802 [TECHNOTREND_S2_4600] = {USB_DEVICE(USB_VID_TECHNOTREND,
1803 USB_PID_TECHNOTREND_CONNECT_S2_4600)},
1804 [TEVII_S482_1] = {USB_DEVICE(0x9022, 0xd483)},
1805 [TEVII_S482_2] = {USB_DEVICE(0x9022, 0xd484)},
1806 [TERRATEC_CINERGY_S2_BOX] = {USB_DEVICE(USB_VID_TERRATEC, 0x0105)},
1807 [TEVII_S662] = {USB_DEVICE(0x9022, USB_PID_TEVII_S662)},
1811 MODULE_DEVICE_TABLE(usb, dw2102_table);
1813 static int dw2102_load_firmware(struct usb_device *dev,
1814 const struct firmware *frmwr)
1819 u8 reset16[] = {0, 0, 0, 0, 0, 0, 0};
1820 const struct firmware *fw;
1822 switch (le16_to_cpu(dev->descriptor.idProduct)) {
1824 ret = reject_firmware(&fw, DW2101_FIRMWARE, &dev->dev);
1826 err(err_str, DW2101_FIRMWARE);
1834 info("start downloading DW210X firmware");
1835 p = kmalloc(fw->size, GFP_KERNEL);
1838 dw210x_op_rw(dev, 0xa0, 0x7f92, 0, &reset, 1, DW210X_WRITE_MSG);
1839 dw210x_op_rw(dev, 0xa0, 0xe600, 0, &reset, 1, DW210X_WRITE_MSG);
1842 memcpy(p, fw->data, fw->size);
1843 for (i = 0; i < fw->size; i += 0x40) {
1845 if (dw210x_op_rw(dev, 0xa0, i, 0, b , 0x40,
1846 DW210X_WRITE_MSG) != 0x40) {
1847 err("error while transferring firmware");
1852 /* restart the CPU */
1854 if (ret || dw210x_op_rw(dev, 0xa0, 0x7f92, 0, &reset, 1,
1855 DW210X_WRITE_MSG) != 1) {
1856 err("could not restart the USB controller CPU.");
1859 if (ret || dw210x_op_rw(dev, 0xa0, 0xe600, 0, &reset, 1,
1860 DW210X_WRITE_MSG) != 1) {
1861 err("could not restart the USB controller CPU.");
1864 /* init registers */
1865 switch (le16_to_cpu(dev->descriptor.idProduct)) {
1866 case USB_PID_TEVII_S650:
1867 dw2104_properties.rc.core.rc_codes = RC_MAP_TEVII_NEC;
1869 case USB_PID_DW2104:
1871 dw210x_op_rw(dev, 0xc4, 0x0000, 0, &reset, 1,
1874 case USB_PID_DW3101:
1876 dw210x_op_rw(dev, 0xbf, 0x0040, 0, &reset, 0,
1879 case USB_PID_TERRATEC_CINERGY_S:
1880 case USB_PID_DW2102:
1881 dw210x_op_rw(dev, 0xbf, 0x0040, 0, &reset, 0,
1883 dw210x_op_rw(dev, 0xb9, 0x0000, 0, &reset16[0], 2,
1885 /* check STV0299 frontend */
1886 dw210x_op_rw(dev, 0xb5, 0, 0, &reset16[0], 2,
1888 if ((reset16[0] == 0xa1) || (reset16[0] == 0x80)) {
1889 dw2102_properties.i2c_algo = &dw2102_i2c_algo;
1890 dw2102_properties.adapter->fe[0].tuner_attach = &dw2102_tuner_attach;
1893 /* check STV0288 frontend */
1897 dw210x_op_rw(dev, 0xc2, 0, 0, &reset16[0], 3,
1899 dw210x_op_rw(dev, 0xc3, 0xd1, 0, &reset16[0], 3,
1901 if (reset16[2] == 0x11) {
1902 dw2102_properties.i2c_algo = &dw2102_earda_i2c_algo;
1908 dw210x_op_rw(dev, 0xbc, 0x0030, 0, &reset16[0], 2,
1910 dw210x_op_rw(dev, 0xba, 0x0000, 0, &reset16[0], 7,
1912 dw210x_op_rw(dev, 0xba, 0x0000, 0, &reset16[0], 7,
1914 dw210x_op_rw(dev, 0xb9, 0x0000, 0, &reset16[0], 2,
1923 if (le16_to_cpu(dev->descriptor.idProduct) == 0x2101)
1924 release_firmware(fw);
1928 static struct dvb_usb_device_properties dw2102_properties = {
1929 .caps = DVB_USB_IS_AN_I2C_ADAPTER,
1930 .usb_ctrl = DEVICE_SPECIFIC,
1931 .firmware = DW2102_FIRMWARE,
1934 .i2c_algo = &dw2102_serit_i2c_algo,
1938 .rc_codes = RC_MAP_DM1105_NEC,
1939 .module_name = "dw2102",
1940 .allowed_protos = RC_PROTO_BIT_NEC,
1941 .rc_query = dw2102_rc_query,
1944 .generic_bulk_ctrl_endpoint = 0x81,
1945 /* parameter for the MPEG2-data transfer */
1947 .download_firmware = dw2102_load_firmware,
1948 .read_mac_address = dw210x_read_mac_address,
1953 .frontend_attach = dw2102_frontend_attach,
1967 .num_device_descs = 3,
1969 {"DVBWorld DVB-S 2102 USB2.0",
1970 {&dw2102_table[CYPRESS_DW2102], NULL},
1973 {"DVBWorld DVB-S 2101 USB2.0",
1974 {&dw2102_table[CYPRESS_DW2101], NULL},
1977 {"TerraTec Cinergy S USB",
1978 {&dw2102_table[TERRATEC_CINERGY_S], NULL},
1984 static struct dvb_usb_device_properties dw2104_properties = {
1985 .caps = DVB_USB_IS_AN_I2C_ADAPTER,
1986 .usb_ctrl = DEVICE_SPECIFIC,
1987 .firmware = DW2104_FIRMWARE,
1990 .i2c_algo = &dw2104_i2c_algo,
1993 .rc_codes = RC_MAP_DM1105_NEC,
1994 .module_name = "dw2102",
1995 .allowed_protos = RC_PROTO_BIT_NEC,
1996 .rc_query = dw2102_rc_query,
1999 .generic_bulk_ctrl_endpoint = 0x81,
2000 /* parameter for the MPEG2-data transfer */
2002 .download_firmware = dw2102_load_firmware,
2003 .read_mac_address = dw210x_read_mac_address,
2008 .frontend_attach = dw2104_frontend_attach,
2022 .num_device_descs = 2,
2024 { "DVBWorld DW2104 USB2.0",
2025 {&dw2102_table[CYPRESS_DW2104], NULL},
2028 { "TeVii S650 USB2.0",
2029 {&dw2102_table[TEVII_S650], NULL},
2035 static struct dvb_usb_device_properties dw3101_properties = {
2036 .caps = DVB_USB_IS_AN_I2C_ADAPTER,
2037 .usb_ctrl = DEVICE_SPECIFIC,
2038 .firmware = DW3101_FIRMWARE,
2041 .i2c_algo = &dw3101_i2c_algo,
2044 .rc_codes = RC_MAP_DM1105_NEC,
2045 .module_name = "dw2102",
2046 .allowed_protos = RC_PROTO_BIT_NEC,
2047 .rc_query = dw2102_rc_query,
2050 .generic_bulk_ctrl_endpoint = 0x81,
2051 /* parameter for the MPEG2-data transfer */
2053 .download_firmware = dw2102_load_firmware,
2054 .read_mac_address = dw210x_read_mac_address,
2059 .frontend_attach = dw3101_frontend_attach,
2060 .tuner_attach = dw3101_tuner_attach,
2074 .num_device_descs = 1,
2076 { "DVBWorld DVB-C 3101 USB2.0",
2077 {&dw2102_table[CYPRESS_DW3101], NULL},
2083 static struct dvb_usb_device_properties s6x0_properties = {
2084 .caps = DVB_USB_IS_AN_I2C_ADAPTER,
2085 .usb_ctrl = DEVICE_SPECIFIC,
2086 .size_of_priv = sizeof(struct dw2102_state),
2087 .firmware = S630_FIRMWARE,
2090 .i2c_algo = &s6x0_i2c_algo,
2093 .rc_codes = RC_MAP_TEVII_NEC,
2094 .module_name = "dw2102",
2095 .allowed_protos = RC_PROTO_BIT_NEC,
2096 .rc_query = dw2102_rc_query,
2099 .generic_bulk_ctrl_endpoint = 0x81,
2101 .download_firmware = dw2102_load_firmware,
2102 .read_mac_address = s6x0_read_mac_address,
2107 .frontend_attach = zl100313_frontend_attach,
2121 .num_device_descs = 1,
2124 {&dw2102_table[TEVII_S630], NULL},
2130 static struct dvb_usb_device_properties p1100_properties = {
2131 .caps = DVB_USB_IS_AN_I2C_ADAPTER,
2132 .usb_ctrl = DEVICE_SPECIFIC,
2133 .size_of_priv = sizeof(struct dw2102_state),
2134 .firmware = P1100_FIRMWARE,
2137 .i2c_algo = &s6x0_i2c_algo,
2140 .rc_codes = RC_MAP_TBS_NEC,
2141 .module_name = "dw2102",
2142 .allowed_protos = RC_PROTO_BIT_NEC,
2143 .rc_query = prof_rc_query,
2146 .generic_bulk_ctrl_endpoint = 0x81,
2148 .download_firmware = dw2102_load_firmware,
2149 .read_mac_address = s6x0_read_mac_address,
2154 .frontend_attach = stv0288_frontend_attach,
2168 .num_device_descs = 1,
2171 {&dw2102_table[PROF_1100], NULL},
2177 static struct dvb_usb_device_properties s660_properties = {
2178 .caps = DVB_USB_IS_AN_I2C_ADAPTER,
2179 .usb_ctrl = DEVICE_SPECIFIC,
2180 .size_of_priv = sizeof(struct dw2102_state),
2181 .firmware = S660_FIRMWARE,
2184 .i2c_algo = &s6x0_i2c_algo,
2187 .rc_codes = RC_MAP_TEVII_NEC,
2188 .module_name = "dw2102",
2189 .allowed_protos = RC_PROTO_BIT_NEC,
2190 .rc_query = dw2102_rc_query,
2193 .generic_bulk_ctrl_endpoint = 0x81,
2195 .download_firmware = dw2102_load_firmware,
2196 .read_mac_address = s6x0_read_mac_address,
2201 .frontend_attach = ds3000_frontend_attach,
2215 .num_device_descs = 3,
2218 {&dw2102_table[TEVII_S660], NULL},
2221 {"TeVii S480.1 USB",
2222 {&dw2102_table[TEVII_S480_1], NULL},
2225 {"TeVii S480.2 USB",
2226 {&dw2102_table[TEVII_S480_2], NULL},
2232 static struct dvb_usb_device_properties p7500_properties = {
2233 .caps = DVB_USB_IS_AN_I2C_ADAPTER,
2234 .usb_ctrl = DEVICE_SPECIFIC,
2235 .size_of_priv = sizeof(struct dw2102_state),
2236 .firmware = P7500_FIRMWARE,
2239 .i2c_algo = &s6x0_i2c_algo,
2242 .rc_codes = RC_MAP_TBS_NEC,
2243 .module_name = "dw2102",
2244 .allowed_protos = RC_PROTO_BIT_NEC,
2245 .rc_query = prof_rc_query,
2248 .generic_bulk_ctrl_endpoint = 0x81,
2250 .download_firmware = dw2102_load_firmware,
2251 .read_mac_address = s6x0_read_mac_address,
2256 .frontend_attach = prof_7500_frontend_attach,
2270 .num_device_descs = 1,
2272 {"Prof 7500 USB DVB-S2",
2273 {&dw2102_table[PROF_7500], NULL},
2279 static struct dvb_usb_device_properties su3000_properties = {
2280 .caps = DVB_USB_IS_AN_I2C_ADAPTER,
2281 .usb_ctrl = DEVICE_SPECIFIC,
2282 .size_of_priv = sizeof(struct dw2102_state),
2283 .power_ctrl = su3000_power_ctrl,
2285 .identify_state = su3000_identify_state,
2286 .i2c_algo = &su3000_i2c_algo,
2290 .rc_codes = RC_MAP_SU3000,
2291 .module_name = "dw2102",
2292 .allowed_protos = RC_PROTO_BIT_RC5,
2293 .rc_query = su3000_rc_query,
2296 .read_mac_address = su3000_read_mac_address,
2298 .generic_bulk_ctrl_endpoint = 0x01,
2304 .streaming_ctrl = su3000_streaming_ctrl,
2305 .frontend_attach = su3000_frontend_attach,
2319 .num_device_descs = 6,
2321 { "SU3000HD DVB-S USB2.0",
2322 { &dw2102_table[GENIATECH_SU3000], NULL },
2325 { "Terratec Cinergy S2 USB HD",
2326 { &dw2102_table[TERRATEC_CINERGY_S2], NULL },
2329 { "X3M TV SPC1400HD PCI",
2330 { &dw2102_table[X3M_SPC1400HD], NULL },
2333 { "Terratec Cinergy S2 USB HD Rev.2",
2334 { &dw2102_table[TERRATEC_CINERGY_S2_R2], NULL },
2337 { "Terratec Cinergy S2 USB HD Rev.3",
2338 { &dw2102_table[TERRATEC_CINERGY_S2_R3], NULL },
2341 { "GOTVIEW Satellite HD",
2342 { &dw2102_table[GOTVIEW_SAT_HD], NULL },
2348 static struct dvb_usb_device_properties s421_properties = {
2349 .caps = DVB_USB_IS_AN_I2C_ADAPTER,
2350 .usb_ctrl = DEVICE_SPECIFIC,
2351 .size_of_priv = sizeof(struct dw2102_state),
2352 .power_ctrl = su3000_power_ctrl,
2354 .identify_state = su3000_identify_state,
2355 .i2c_algo = &su3000_i2c_algo,
2359 .rc_codes = RC_MAP_SU3000,
2360 .module_name = "dw2102",
2361 .allowed_protos = RC_PROTO_BIT_RC5,
2362 .rc_query = su3000_rc_query,
2365 .read_mac_address = su3000_read_mac_address,
2367 .generic_bulk_ctrl_endpoint = 0x01,
2373 .streaming_ctrl = su3000_streaming_ctrl,
2374 .frontend_attach = m88rs2000_frontend_attach,
2388 .num_device_descs = 2,
2391 { &dw2102_table[TEVII_S421], NULL },
2395 { &dw2102_table[TEVII_S632], NULL },
2401 static struct dvb_usb_device_properties t220_properties = {
2402 .caps = DVB_USB_IS_AN_I2C_ADAPTER,
2403 .usb_ctrl = DEVICE_SPECIFIC,
2404 .size_of_priv = sizeof(struct dw2102_state),
2405 .power_ctrl = su3000_power_ctrl,
2407 .identify_state = su3000_identify_state,
2408 .i2c_algo = &su3000_i2c_algo,
2412 .rc_codes = RC_MAP_SU3000,
2413 .module_name = "dw2102",
2414 .allowed_protos = RC_PROTO_BIT_RC5,
2415 .rc_query = su3000_rc_query,
2418 .read_mac_address = su3000_read_mac_address,
2420 .generic_bulk_ctrl_endpoint = 0x01,
2426 .streaming_ctrl = su3000_streaming_ctrl,
2427 .frontend_attach = t220_frontend_attach,
2441 .num_device_descs = 1,
2443 { "Geniatech T220 DVB-T/T2 USB2.0",
2444 { &dw2102_table[GENIATECH_T220], NULL },
2450 static struct dvb_usb_device_properties tt_s2_4600_properties = {
2451 .caps = DVB_USB_IS_AN_I2C_ADAPTER,
2452 .usb_ctrl = DEVICE_SPECIFIC,
2453 .size_of_priv = sizeof(struct dw2102_state),
2454 .power_ctrl = su3000_power_ctrl,
2456 .identify_state = su3000_identify_state,
2457 .i2c_algo = &su3000_i2c_algo,
2461 .rc_codes = RC_MAP_TT_1500,
2462 .module_name = "dw2102",
2463 .allowed_protos = RC_PROTO_BIT_RC5,
2464 .rc_query = su3000_rc_query,
2467 .read_mac_address = su3000_read_mac_address,
2469 .generic_bulk_ctrl_endpoint = 0x01,
2475 .streaming_ctrl = su3000_streaming_ctrl,
2476 .frontend_attach = tt_s2_4600_frontend_attach,
2490 .num_device_descs = 5,
2492 { "TechnoTrend TT-connect S2-4600",
2493 { &dw2102_table[TECHNOTREND_S2_4600], NULL },
2496 { "TeVii S482 (tuner 1)",
2497 { &dw2102_table[TEVII_S482_1], NULL },
2500 { "TeVii S482 (tuner 2)",
2501 { &dw2102_table[TEVII_S482_2], NULL },
2504 { "Terratec Cinergy S2 USB BOX",
2505 { &dw2102_table[TERRATEC_CINERGY_S2_BOX], NULL },
2509 { &dw2102_table[TEVII_S662], NULL },
2515 static int dw2102_probe(struct usb_interface *intf,
2516 const struct usb_device_id *id)
2518 if (!(dvb_usb_device_init(intf, &dw2102_properties,
2519 THIS_MODULE, NULL, adapter_nr) &&
2520 dvb_usb_device_init(intf, &dw2104_properties,
2521 THIS_MODULE, NULL, adapter_nr) &&
2522 dvb_usb_device_init(intf, &dw3101_properties,
2523 THIS_MODULE, NULL, adapter_nr) &&
2524 dvb_usb_device_init(intf, &s6x0_properties,
2525 THIS_MODULE, NULL, adapter_nr) &&
2526 dvb_usb_device_init(intf, &p1100_properties,
2527 THIS_MODULE, NULL, adapter_nr) &&
2528 dvb_usb_device_init(intf, &s660_properties,
2529 THIS_MODULE, NULL, adapter_nr) &&
2530 dvb_usb_device_init(intf, &p7500_properties,
2531 THIS_MODULE, NULL, adapter_nr) &&
2532 dvb_usb_device_init(intf, &s421_properties,
2533 THIS_MODULE, NULL, adapter_nr) &&
2534 dvb_usb_device_init(intf, &su3000_properties,
2535 THIS_MODULE, NULL, adapter_nr) &&
2536 dvb_usb_device_init(intf, &t220_properties,
2537 THIS_MODULE, NULL, adapter_nr) &&
2538 dvb_usb_device_init(intf, &tt_s2_4600_properties,
2539 THIS_MODULE, NULL, adapter_nr))) {
2547 static void dw2102_disconnect(struct usb_interface *intf)
2549 struct dvb_usb_device *d = usb_get_intfdata(intf);
2550 struct dw2102_state *st = (struct dw2102_state *)d->priv;
2551 struct i2c_client *client;
2553 /* remove I2C client for tuner */
2554 client = st->i2c_client_tuner;
2556 module_put(client->dev.driver->owner);
2557 i2c_unregister_device(client);
2560 /* remove I2C client for demodulator */
2561 client = st->i2c_client_demod;
2563 module_put(client->dev.driver->owner);
2564 i2c_unregister_device(client);
2567 dvb_usb_device_exit(intf);
2570 static struct usb_driver dw2102_driver = {
2572 .probe = dw2102_probe,
2573 .disconnect = dw2102_disconnect,
2574 .id_table = dw2102_table,
2577 module_usb_driver(dw2102_driver);
2579 MODULE_AUTHOR("Igor M. Liplianin (c) liplianin@me.by");
2580 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");
2581 MODULE_VERSION("0.1");
2582 MODULE_LICENSE("GPL");