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/media/dvb-drivers/dvb-usb.rst 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 "/*(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'. /*(DEBLOBBED)*/"
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 if (msg[0].len < 1) {
138 /* read stv0299 register */
139 value = msg[0].buf[0];/* register */
140 for (i = 0; i < msg[1].len; i++) {
141 dw210x_op_rw(d->udev, 0xb5, value + i, 0,
142 buf6, 2, DW210X_READ_MSG);
143 msg[1].buf[i] = buf6[0];
147 switch (msg[0].addr) {
149 if (msg[0].len < 2) {
153 /* write to stv0299 register */
155 buf6[1] = msg[0].buf[0];
156 buf6[2] = msg[0].buf[1];
157 dw210x_op_rw(d->udev, 0xb2, 0, 0,
158 buf6, 3, DW210X_WRITE_MSG);
161 if (msg[0].flags == 0) {
162 if (msg[0].len < 4) {
166 /* write to tuner pll */
170 buf6[3] = msg[0].buf[0];
171 buf6[4] = msg[0].buf[1];
172 buf6[5] = msg[0].buf[2];
173 buf6[6] = msg[0].buf[3];
174 dw210x_op_rw(d->udev, 0xb2, 0, 0,
175 buf6, 7, DW210X_WRITE_MSG);
177 if (msg[0].len < 1) {
181 /* read from tuner */
182 dw210x_op_rw(d->udev, 0xb5, 0, 0,
183 buf6, 1, DW210X_READ_MSG);
184 msg[0].buf[0] = buf6[0];
187 case (DW2102_RC_QUERY):
188 if (msg[0].len < 2) {
192 dw210x_op_rw(d->udev, 0xb8, 0, 0,
193 buf6, 2, DW210X_READ_MSG);
194 msg[0].buf[0] = buf6[0];
195 msg[0].buf[1] = buf6[1];
197 case (DW2102_VOLTAGE_CTRL):
198 if (msg[0].len < 1) {
203 buf6[1] = msg[0].buf[0];
204 dw210x_op_rw(d->udev, 0xb2, 0, 0,
205 buf6, 2, DW210X_WRITE_MSG);
212 mutex_unlock(&d->i2c_mutex);
216 static int dw2102_serit_i2c_transfer(struct i2c_adapter *adap,
217 struct i2c_msg msg[], int num)
219 struct dvb_usb_device *d = i2c_get_adapdata(adap);
220 u8 buf6[] = {0, 0, 0, 0, 0, 0, 0};
224 if (mutex_lock_interruptible(&d->i2c_mutex) < 0)
229 if (msg[0].len != 1) {
230 warn("i2c rd: len=%d is not 1!\n",
236 if (2 + msg[1].len > sizeof(buf6)) {
237 warn("i2c rd: len=%d is too big!\n",
243 /* read si2109 register by number */
244 buf6[0] = msg[0].addr << 1;
245 buf6[1] = msg[0].len;
246 buf6[2] = msg[0].buf[0];
247 dw210x_op_rw(d->udev, 0xc2, 0, 0,
248 buf6, msg[0].len + 2, DW210X_WRITE_MSG);
249 /* read si2109 register */
250 dw210x_op_rw(d->udev, 0xc3, 0xd0, 0,
251 buf6, msg[1].len + 2, DW210X_READ_MSG);
252 memcpy(msg[1].buf, buf6 + 2, msg[1].len);
256 switch (msg[0].addr) {
258 if (2 + msg[0].len > sizeof(buf6)) {
259 warn("i2c wr: len=%d is too big!\n",
265 /* write to si2109 register */
266 buf6[0] = msg[0].addr << 1;
267 buf6[1] = msg[0].len;
268 memcpy(buf6 + 2, msg[0].buf, msg[0].len);
269 dw210x_op_rw(d->udev, 0xc2, 0, 0, buf6,
270 msg[0].len + 2, DW210X_WRITE_MSG);
272 case(DW2102_RC_QUERY):
273 dw210x_op_rw(d->udev, 0xb8, 0, 0,
274 buf6, 2, DW210X_READ_MSG);
275 msg[0].buf[0] = buf6[0];
276 msg[0].buf[1] = buf6[1];
278 case(DW2102_VOLTAGE_CTRL):
280 buf6[1] = msg[0].buf[0];
281 dw210x_op_rw(d->udev, 0xb2, 0, 0,
282 buf6, 2, DW210X_WRITE_MSG);
288 mutex_unlock(&d->i2c_mutex);
292 static int dw2102_earda_i2c_transfer(struct i2c_adapter *adap, struct i2c_msg msg[], int num)
294 struct dvb_usb_device *d = i2c_get_adapdata(adap);
299 if (mutex_lock_interruptible(&d->i2c_mutex) < 0)
305 /* first write first register number */
306 u8 ibuf[MAX_XFER_SIZE], obuf[3];
308 if (2 + msg[0].len != sizeof(obuf)) {
309 warn("i2c rd: len=%d is not 1!\n",
315 if (2 + msg[1].len > sizeof(ibuf)) {
316 warn("i2c rd: len=%d is too big!\n",
322 obuf[0] = msg[0].addr << 1;
323 obuf[1] = msg[0].len;
324 obuf[2] = msg[0].buf[0];
325 dw210x_op_rw(d->udev, 0xc2, 0, 0,
326 obuf, msg[0].len + 2, DW210X_WRITE_MSG);
327 /* second read registers */
328 dw210x_op_rw(d->udev, 0xc3, 0xd1 , 0,
329 ibuf, msg[1].len + 2, DW210X_READ_MSG);
330 memcpy(msg[1].buf, ibuf + 2, msg[1].len);
335 switch (msg[0].addr) {
337 /* write to register */
338 u8 obuf[MAX_XFER_SIZE];
340 if (2 + msg[0].len > sizeof(obuf)) {
341 warn("i2c wr: len=%d is too big!\n",
347 obuf[0] = msg[0].addr << 1;
348 obuf[1] = msg[0].len;
349 memcpy(obuf + 2, msg[0].buf, msg[0].len);
350 dw210x_op_rw(d->udev, 0xc2, 0, 0,
351 obuf, msg[0].len + 2, DW210X_WRITE_MSG);
356 u8 obuf[MAX_XFER_SIZE];
358 if (2 + msg[0].len > sizeof(obuf)) {
359 warn("i2c wr: len=%d is too big!\n",
365 obuf[0] = msg[0].addr << 1;
366 obuf[1] = msg[0].len;
367 memcpy(obuf + 2, msg[0].buf, msg[0].len);
368 dw210x_op_rw(d->udev, 0xc2, 0, 0,
369 obuf, msg[0].len + 2, DW210X_WRITE_MSG);
372 case(DW2102_RC_QUERY): {
374 dw210x_op_rw(d->udev, 0xb8, 0, 0,
375 ibuf, 2, DW210X_READ_MSG);
376 memcpy(msg[0].buf, ibuf , 2);
379 case(DW2102_VOLTAGE_CTRL): {
382 obuf[1] = msg[0].buf[0];
383 dw210x_op_rw(d->udev, 0xb2, 0, 0,
384 obuf, 2, DW210X_WRITE_MSG);
394 mutex_unlock(&d->i2c_mutex);
398 static int dw2104_i2c_transfer(struct i2c_adapter *adap, struct i2c_msg msg[], int num)
400 struct dvb_usb_device *d = i2c_get_adapdata(adap);
405 if (mutex_lock_interruptible(&d->i2c_mutex) < 0)
408 for (j = 0; j < num; j++) {
409 switch (msg[j].addr) {
410 case(DW2102_RC_QUERY): {
412 dw210x_op_rw(d->udev, 0xb8, 0, 0,
413 ibuf, 2, DW210X_READ_MSG);
414 memcpy(msg[j].buf, ibuf , 2);
417 case(DW2102_VOLTAGE_CTRL): {
420 obuf[1] = msg[j].buf[0];
421 dw210x_op_rw(d->udev, 0xb2, 0, 0,
422 obuf, 2, DW210X_WRITE_MSG);
427 case 0x68: ds3000, stv0903
428 case 0x60: ts2020, stv6110, stb6100 */
430 if (msg[j].flags == I2C_M_RD) {
432 u8 ibuf[MAX_XFER_SIZE];
434 if (2 + msg[j].len > sizeof(ibuf)) {
435 warn("i2c rd: len=%d is too big!\n",
441 dw210x_op_rw(d->udev, 0xc3,
442 (msg[j].addr << 1) + 1, 0,
443 ibuf, msg[j].len + 2,
445 memcpy(msg[j].buf, ibuf + 2, msg[j].len);
447 } else if (((msg[j].buf[0] == 0xb0) &&
448 (msg[j].addr == 0x68)) ||
449 ((msg[j].buf[0] == 0xf7) &&
450 (msg[j].addr == 0x55))) {
453 obuf[0] = msg[j].addr << 1;
454 obuf[1] = (msg[j].len > 15 ? 17 : msg[j].len);
455 obuf[2] = msg[j].buf[0];
456 len = msg[j].len - 1;
459 memcpy(obuf + 3, msg[j].buf + i,
460 (len > 16 ? 16 : len));
461 dw210x_op_rw(d->udev, 0xc2, 0, 0,
462 obuf, (len > 16 ? 16 : len) + 3,
468 /* write registers */
469 u8 obuf[MAX_XFER_SIZE];
471 if (2 + msg[j].len > sizeof(obuf)) {
472 warn("i2c wr: len=%d is too big!\n",
478 obuf[0] = msg[j].addr << 1;
479 obuf[1] = msg[j].len;
480 memcpy(obuf + 2, msg[j].buf, msg[j].len);
481 dw210x_op_rw(d->udev, 0xc2, 0, 0,
482 obuf, msg[j].len + 2,
493 mutex_unlock(&d->i2c_mutex);
497 static int dw3101_i2c_transfer(struct i2c_adapter *adap, struct i2c_msg msg[],
500 struct dvb_usb_device *d = i2c_get_adapdata(adap);
506 if (mutex_lock_interruptible(&d->i2c_mutex) < 0)
512 /* first write first register number */
513 u8 ibuf[MAX_XFER_SIZE], obuf[3];
515 if (2 + msg[0].len != sizeof(obuf)) {
516 warn("i2c rd: len=%d is not 1!\n",
521 if (2 + msg[1].len > sizeof(ibuf)) {
522 warn("i2c rd: len=%d is too big!\n",
527 obuf[0] = msg[0].addr << 1;
528 obuf[1] = msg[0].len;
529 obuf[2] = msg[0].buf[0];
530 dw210x_op_rw(d->udev, 0xc2, 0, 0,
531 obuf, msg[0].len + 2, DW210X_WRITE_MSG);
532 /* second read registers */
533 dw210x_op_rw(d->udev, 0xc3, 0x19 , 0,
534 ibuf, msg[1].len + 2, DW210X_READ_MSG);
535 memcpy(msg[1].buf, ibuf + 2, msg[1].len);
540 switch (msg[0].addr) {
543 /* write to register */
544 u8 obuf[MAX_XFER_SIZE];
546 if (2 + msg[0].len > sizeof(obuf)) {
547 warn("i2c wr: len=%d is too big!\n",
552 obuf[0] = msg[0].addr << 1;
553 obuf[1] = msg[0].len;
554 memcpy(obuf + 2, msg[0].buf, msg[0].len);
555 dw210x_op_rw(d->udev, 0xc2, 0, 0,
556 obuf, msg[0].len + 2, DW210X_WRITE_MSG);
559 case(DW2102_RC_QUERY): {
561 dw210x_op_rw(d->udev, 0xb8, 0, 0,
562 ibuf, 2, DW210X_READ_MSG);
563 memcpy(msg[0].buf, ibuf , 2);
571 for (i = 0; i < num; i++) {
572 deb_xfer("%02x:%02x: %s ", i, msg[i].addr,
573 msg[i].flags == 0 ? ">>>" : "<<<");
574 debug_dump(msg[i].buf, msg[i].len, deb_xfer);
579 mutex_unlock(&d->i2c_mutex);
583 static int s6x0_i2c_transfer(struct i2c_adapter *adap, struct i2c_msg msg[],
586 struct dvb_usb_device *d = i2c_get_adapdata(adap);
587 struct usb_device *udev;
593 if (mutex_lock_interruptible(&d->i2c_mutex) < 0)
596 for (j = 0; j < num; j++) {
597 switch (msg[j].addr) {
598 case (DW2102_RC_QUERY): {
600 dw210x_op_rw(d->udev, 0xb8, 0, 0,
601 ibuf, 5, DW210X_READ_MSG);
602 memcpy(msg[j].buf, ibuf + 3, 2);
605 case (DW2102_VOLTAGE_CTRL): {
609 obuf[1] = msg[j].buf[1];/* off-on */
610 dw210x_op_rw(d->udev, 0x8a, 0, 0,
611 obuf, 2, DW210X_WRITE_MSG);
613 obuf[1] = msg[j].buf[0];/* 13v-18v */
614 dw210x_op_rw(d->udev, 0x8a, 0, 0,
615 obuf, 2, DW210X_WRITE_MSG);
618 case (DW2102_LED_CTRL): {
622 obuf[1] = msg[j].buf[0];
623 dw210x_op_rw(d->udev, 0x8a, 0, 0,
624 obuf, 2, DW210X_WRITE_MSG);
629 case 0x68: ds3000, stv0903, rs2000
630 case 0x60: ts2020, stv6110, stb6100
633 if (msg[j].flags == I2C_M_RD) {
635 u8 ibuf[MAX_XFER_SIZE];
637 if (msg[j].len > sizeof(ibuf)) {
638 warn("i2c rd: len=%d is too big!\n",
644 dw210x_op_rw(d->udev, 0x91, 0, 0,
647 memcpy(msg[j].buf, ibuf, msg[j].len);
649 } else if ((msg[j].buf[0] == 0xb0) &&
650 (msg[j].addr == 0x68)) {
653 obuf[0] = (msg[j].len > 16 ?
654 18 : msg[j].len + 1);
655 obuf[1] = msg[j].addr << 1;
656 obuf[2] = msg[j].buf[0];
657 len = msg[j].len - 1;
660 memcpy(obuf + 3, msg[j].buf + i,
661 (len > 16 ? 16 : len));
662 dw210x_op_rw(d->udev, 0x80, 0, 0,
663 obuf, (len > 16 ? 16 : len) + 3,
668 } else if (j < (num - 1)) {
669 /* write register addr before read */
670 u8 obuf[MAX_XFER_SIZE];
672 if (2 + msg[j].len > sizeof(obuf)) {
673 warn("i2c wr: len=%d is too big!\n",
679 obuf[0] = msg[j + 1].len;
680 obuf[1] = (msg[j].addr << 1);
681 memcpy(obuf + 2, msg[j].buf, msg[j].len);
682 dw210x_op_rw(d->udev,
683 le16_to_cpu(udev->descriptor.idProduct) ==
684 0x7500 ? 0x92 : 0x90, 0, 0,
685 obuf, msg[j].len + 2,
689 /* write registers */
690 u8 obuf[MAX_XFER_SIZE];
692 if (2 + msg[j].len > sizeof(obuf)) {
693 warn("i2c wr: len=%d is too big!\n",
698 obuf[0] = msg[j].len + 1;
699 obuf[1] = (msg[j].addr << 1);
700 memcpy(obuf + 2, msg[j].buf, msg[j].len);
701 dw210x_op_rw(d->udev, 0x80, 0, 0,
702 obuf, msg[j].len + 2,
713 mutex_unlock(&d->i2c_mutex);
717 static int su3000_i2c_transfer(struct i2c_adapter *adap, struct i2c_msg msg[],
720 struct dvb_usb_device *d = i2c_get_adapdata(adap);
721 struct dw2102_state *state;
728 if (mutex_lock_interruptible(&d->i2c_mutex) < 0)
730 if (mutex_lock_interruptible(&d->data_mutex) < 0) {
731 mutex_unlock(&d->i2c_mutex);
737 switch (msg[0].addr) {
738 case SU3000_STREAM_CTRL:
739 state->data[0] = msg[0].buf[0] + 0x36;
742 if (dvb_usb_generic_rw(d, state->data, 3,
743 state->data, 0, 0) < 0)
744 err("i2c transfer failed.");
746 case DW2102_RC_QUERY:
747 state->data[0] = 0x10;
748 if (dvb_usb_generic_rw(d, state->data, 1,
749 state->data, 2, 0) < 0)
750 err("i2c transfer failed.");
751 msg[0].buf[1] = state->data[0];
752 msg[0].buf[0] = state->data[1];
755 if (3 + msg[0].len > sizeof(state->data)) {
756 warn("i2c wr: len=%d is too big!\n",
762 /* always i2c write*/
763 state->data[0] = 0x08;
764 state->data[1] = msg[0].addr;
765 state->data[2] = msg[0].len;
767 memcpy(&state->data[3], msg[0].buf, msg[0].len);
769 if (dvb_usb_generic_rw(d, state->data, msg[0].len + 3,
770 state->data, 1, 0) < 0)
771 err("i2c transfer failed.");
776 /* always i2c read */
777 if (4 + msg[0].len > sizeof(state->data)) {
778 warn("i2c rd: len=%d is too big!\n",
783 if (1 + msg[1].len > sizeof(state->data)) {
784 warn("i2c rd: len=%d is too big!\n",
790 state->data[0] = 0x09;
791 state->data[1] = msg[0].len;
792 state->data[2] = msg[1].len;
793 state->data[3] = msg[0].addr;
794 memcpy(&state->data[4], msg[0].buf, msg[0].len);
796 if (dvb_usb_generic_rw(d, state->data, msg[0].len + 4,
797 state->data, msg[1].len + 1, 0) < 0)
798 err("i2c transfer failed.");
800 memcpy(msg[1].buf, &state->data[1], msg[1].len);
803 warn("more than 2 i2c messages at a time is not handled yet.");
806 mutex_unlock(&d->data_mutex);
807 mutex_unlock(&d->i2c_mutex);
811 static u32 dw210x_i2c_func(struct i2c_adapter *adapter)
816 static struct i2c_algorithm dw2102_i2c_algo = {
817 .master_xfer = dw2102_i2c_transfer,
818 .functionality = dw210x_i2c_func,
821 static struct i2c_algorithm dw2102_serit_i2c_algo = {
822 .master_xfer = dw2102_serit_i2c_transfer,
823 .functionality = dw210x_i2c_func,
826 static struct i2c_algorithm dw2102_earda_i2c_algo = {
827 .master_xfer = dw2102_earda_i2c_transfer,
828 .functionality = dw210x_i2c_func,
831 static struct i2c_algorithm dw2104_i2c_algo = {
832 .master_xfer = dw2104_i2c_transfer,
833 .functionality = dw210x_i2c_func,
836 static struct i2c_algorithm dw3101_i2c_algo = {
837 .master_xfer = dw3101_i2c_transfer,
838 .functionality = dw210x_i2c_func,
841 static struct i2c_algorithm s6x0_i2c_algo = {
842 .master_xfer = s6x0_i2c_transfer,
843 .functionality = dw210x_i2c_func,
846 static struct i2c_algorithm su3000_i2c_algo = {
847 .master_xfer = su3000_i2c_transfer,
848 .functionality = dw210x_i2c_func,
851 static int dw210x_read_mac_address(struct dvb_usb_device *d, u8 mac[6])
855 u8 eeprom[256], eepromline[16];
857 for (i = 0; i < 256; i++) {
858 if (dw210x_op_rw(d->udev, 0xb6, 0xa0 , i, ibuf, 2, DW210X_READ_MSG) < 0) {
859 err("read eeprom failed.");
862 eepromline[i%16] = ibuf[0];
865 if ((i % 16) == 15) {
866 deb_xfer("%02x: ", i - 15);
867 debug_dump(eepromline, 16, deb_xfer);
871 memcpy(mac, eeprom + 8, 6);
875 static int s6x0_read_mac_address(struct dvb_usb_device *d, u8 mac[6])
878 u8 ibuf[] = { 0 }, obuf[] = { 0 };
879 u8 eeprom[256], eepromline[16];
880 struct i2c_msg msg[] = {
894 for (i = 0; i < 256; i++) {
896 ret = s6x0_i2c_transfer(&d->i2c_adap, msg, 2);
898 err("read eeprom failed.");
901 eepromline[i % 16] = ibuf[0];
905 if ((i % 16) == 15) {
906 deb_xfer("%02x: ", i - 15);
907 debug_dump(eepromline, 16, deb_xfer);
911 memcpy(mac, eeprom + 16, 6);
915 static int su3000_streaming_ctrl(struct dvb_usb_adapter *adap, int onoff)
917 static u8 command_start[] = {0x00};
918 static u8 command_stop[] = {0x01};
919 struct i2c_msg msg = {
920 .addr = SU3000_STREAM_CTRL,
922 .buf = onoff ? command_start : command_stop,
926 i2c_transfer(&adap->dev->i2c_adap, &msg, 1);
931 static int su3000_power_ctrl(struct dvb_usb_device *d, int i)
933 struct dw2102_state *state = (struct dw2102_state *)d->priv;
936 info("%s: %d, initialized %d", __func__, i, state->initialized);
938 if (i && !state->initialized) {
939 mutex_lock(&d->data_mutex);
941 state->data[0] = 0xde;
944 state->initialized = 1;
946 ret = dvb_usb_generic_rw(d, state->data, 2, NULL, 0, 0);
947 mutex_unlock(&d->data_mutex);
953 static int su3000_read_mac_address(struct dvb_usb_device *d, u8 mac[6])
956 u8 obuf[] = { 0x1f, 0xf0 };
958 struct i2c_msg msg[] = {
973 for (i = 0; i < 6; i++) {
975 if (i2c_transfer(&d->i2c_adap, msg, 2) != 2)
984 static int su3000_identify_state(struct usb_device *udev,
985 struct dvb_usb_device_properties *props,
986 struct dvb_usb_device_description **desc,
989 info("%s", __func__);
995 static int dw210x_set_voltage(struct dvb_frontend *fe,
996 enum fe_sec_voltage voltage)
998 static u8 command_13v[] = {0x00, 0x01};
999 static u8 command_18v[] = {0x01, 0x01};
1000 static u8 command_off[] = {0x00, 0x00};
1001 struct i2c_msg msg = {
1002 .addr = DW2102_VOLTAGE_CTRL,
1008 struct dvb_usb_adapter *udev_adap =
1009 (struct dvb_usb_adapter *)(fe->dvb->priv);
1010 if (voltage == SEC_VOLTAGE_18)
1011 msg.buf = command_18v;
1012 else if (voltage == SEC_VOLTAGE_13)
1013 msg.buf = command_13v;
1015 i2c_transfer(&udev_adap->dev->i2c_adap, &msg, 1);
1020 static int s660_set_voltage(struct dvb_frontend *fe,
1021 enum fe_sec_voltage voltage)
1023 struct dvb_usb_adapter *d =
1024 (struct dvb_usb_adapter *)(fe->dvb->priv);
1025 struct dw2102_state *st = (struct dw2102_state *)d->dev->priv;
1027 dw210x_set_voltage(fe, voltage);
1028 if (st->old_set_voltage)
1029 st->old_set_voltage(fe, voltage);
1034 static void dw210x_led_ctrl(struct dvb_frontend *fe, int offon)
1036 static u8 led_off[] = { 0 };
1037 static u8 led_on[] = { 1 };
1038 struct i2c_msg msg = {
1039 .addr = DW2102_LED_CTRL,
1044 struct dvb_usb_adapter *udev_adap =
1045 (struct dvb_usb_adapter *)(fe->dvb->priv);
1049 i2c_transfer(&udev_adap->dev->i2c_adap, &msg, 1);
1052 static int tt_s2_4600_read_status(struct dvb_frontend *fe,
1053 enum fe_status *status)
1055 struct dvb_usb_adapter *d =
1056 (struct dvb_usb_adapter *)(fe->dvb->priv);
1057 struct dw2102_state *st = (struct dw2102_state *)d->dev->priv;
1060 ret = st->fe_read_status(fe, status);
1062 /* resync slave fifo when signal change from unlock to lock */
1063 if ((*status & FE_HAS_LOCK) && (!st->last_lock))
1064 su3000_streaming_ctrl(d, 1);
1066 st->last_lock = (*status & FE_HAS_LOCK) ? 1 : 0;
1070 static struct stv0299_config sharp_z0194a_config = {
1071 .demod_address = 0x68,
1072 .inittab = sharp_z0194a_inittab,
1076 .lock_output = STV0299_LOCKOUTPUT_1,
1077 .volt13_op0_op1 = STV0299_VOLT13_OP1,
1078 .min_delay_ms = 100,
1079 .set_symbol_rate = sharp_z0194a_set_symbol_rate,
1082 static struct cx24116_config dw2104_config = {
1083 .demod_address = 0x55,
1084 .mpg_clk_pos_pol = 0x01,
1087 static struct si21xx_config serit_sp1511lhb_config = {
1088 .demod_address = 0x68,
1089 .min_delay_ms = 100,
1093 static struct tda10023_config dw3101_tda10023_config = {
1094 .demod_address = 0x0c,
1098 static struct mt312_config zl313_config = {
1099 .demod_address = 0x0e,
1102 static struct ds3000_config dw2104_ds3000_config = {
1103 .demod_address = 0x68,
1106 static struct ts2020_config dw2104_ts2020_config = {
1107 .tuner_address = 0x60,
1109 .frequency_div = 1060000,
1112 static struct ds3000_config s660_ds3000_config = {
1113 .demod_address = 0x68,
1115 .set_lock_led = dw210x_led_ctrl,
1118 static struct ts2020_config s660_ts2020_config = {
1119 .tuner_address = 0x60,
1121 .frequency_div = 1146000,
1124 static struct stv0900_config dw2104a_stv0900_config = {
1125 .demod_address = 0x6a,
1128 .clkmode = 3,/* 0-CLKI, 2-XTALI, else AUTO */
1129 .diseqc_mode = 2,/* 2/3 PWM */
1130 .tun1_maddress = 0,/* 0x60 */
1131 .tun1_adc = 0,/* 2 Vpp */
1135 static struct stb6100_config dw2104a_stb6100_config = {
1136 .tuner_address = 0x60,
1137 .refclock = 27000000,
1140 static struct stv0900_config dw2104_stv0900_config = {
1141 .demod_address = 0x68,
1147 .tun1_adc = 1,/* 1 Vpp */
1151 static struct stv6110_config dw2104_stv6110_config = {
1152 .i2c_address = 0x60,
1157 static struct stv0900_config prof_7500_stv0900_config = {
1158 .demod_address = 0x6a,
1161 .clkmode = 3,/* 0-CLKI, 2-XTALI, else AUTO */
1162 .diseqc_mode = 2,/* 2/3 PWM */
1163 .tun1_maddress = 0,/* 0x60 */
1164 .tun1_adc = 0,/* 2 Vpp */
1167 .set_lock_led = dw210x_led_ctrl,
1170 static struct ds3000_config su3000_ds3000_config = {
1171 .demod_address = 0x68,
1173 .set_lock_led = dw210x_led_ctrl,
1176 static struct cxd2820r_config cxd2820r_config = {
1177 .i2c_address = 0x6c, /* (0xd8 >> 1) */
1182 static struct tda18271_config tda18271_config = {
1183 .output_opt = TDA18271_OUTPUT_LT_OFF,
1184 .gate = TDA18271_GATE_DIGITAL,
1187 static u8 m88rs2000_inittab[] = {
1188 DEMOD_WRITE, 0x9a, 0x30,
1189 DEMOD_WRITE, 0x00, 0x01,
1190 WRITE_DELAY, 0x19, 0x00,
1191 DEMOD_WRITE, 0x00, 0x00,
1192 DEMOD_WRITE, 0x9a, 0xb0,
1193 DEMOD_WRITE, 0x81, 0xc1,
1194 DEMOD_WRITE, 0x81, 0x81,
1195 DEMOD_WRITE, 0x86, 0xc6,
1196 DEMOD_WRITE, 0x9a, 0x30,
1197 DEMOD_WRITE, 0xf0, 0x80,
1198 DEMOD_WRITE, 0xf1, 0xbf,
1199 DEMOD_WRITE, 0xb0, 0x45,
1200 DEMOD_WRITE, 0xb2, 0x01,
1201 DEMOD_WRITE, 0x9a, 0xb0,
1205 static struct m88rs2000_config s421_m88rs2000_config = {
1207 .inittab = m88rs2000_inittab,
1210 static int dw2104_frontend_attach(struct dvb_usb_adapter *d)
1212 struct dvb_tuner_ops *tuner_ops = NULL;
1214 if (demod_probe & 4) {
1215 d->fe_adap[0].fe = dvb_attach(stv0900_attach, &dw2104a_stv0900_config,
1216 &d->dev->i2c_adap, 0);
1217 if (d->fe_adap[0].fe != NULL) {
1218 if (dvb_attach(stb6100_attach, d->fe_adap[0].fe,
1219 &dw2104a_stb6100_config,
1220 &d->dev->i2c_adap)) {
1221 tuner_ops = &d->fe_adap[0].fe->ops.tuner_ops;
1222 tuner_ops->set_frequency = stb6100_set_freq;
1223 tuner_ops->get_frequency = stb6100_get_freq;
1224 tuner_ops->set_bandwidth = stb6100_set_bandw;
1225 tuner_ops->get_bandwidth = stb6100_get_bandw;
1226 d->fe_adap[0].fe->ops.set_voltage = dw210x_set_voltage;
1227 info("Attached STV0900+STB6100!");
1233 if (demod_probe & 2) {
1234 d->fe_adap[0].fe = dvb_attach(stv0900_attach, &dw2104_stv0900_config,
1235 &d->dev->i2c_adap, 0);
1236 if (d->fe_adap[0].fe != NULL) {
1237 if (dvb_attach(stv6110_attach, d->fe_adap[0].fe,
1238 &dw2104_stv6110_config,
1239 &d->dev->i2c_adap)) {
1240 d->fe_adap[0].fe->ops.set_voltage = dw210x_set_voltage;
1241 info("Attached STV0900+STV6110A!");
1247 if (demod_probe & 1) {
1248 d->fe_adap[0].fe = dvb_attach(cx24116_attach, &dw2104_config,
1250 if (d->fe_adap[0].fe != NULL) {
1251 d->fe_adap[0].fe->ops.set_voltage = dw210x_set_voltage;
1252 info("Attached cx24116!");
1257 d->fe_adap[0].fe = dvb_attach(ds3000_attach, &dw2104_ds3000_config,
1259 if (d->fe_adap[0].fe != NULL) {
1260 dvb_attach(ts2020_attach, d->fe_adap[0].fe,
1261 &dw2104_ts2020_config, &d->dev->i2c_adap);
1262 d->fe_adap[0].fe->ops.set_voltage = dw210x_set_voltage;
1263 info("Attached DS3000!");
1270 static struct dvb_usb_device_properties dw2102_properties;
1271 static struct dvb_usb_device_properties dw2104_properties;
1272 static struct dvb_usb_device_properties s6x0_properties;
1274 static int dw2102_frontend_attach(struct dvb_usb_adapter *d)
1276 if (dw2102_properties.i2c_algo == &dw2102_serit_i2c_algo) {
1277 /*dw2102_properties.adapter->tuner_attach = NULL;*/
1278 d->fe_adap[0].fe = dvb_attach(si21xx_attach, &serit_sp1511lhb_config,
1280 if (d->fe_adap[0].fe != NULL) {
1281 d->fe_adap[0].fe->ops.set_voltage = dw210x_set_voltage;
1282 info("Attached si21xx!");
1287 if (dw2102_properties.i2c_algo == &dw2102_earda_i2c_algo) {
1288 d->fe_adap[0].fe = dvb_attach(stv0288_attach, &earda_config,
1290 if (d->fe_adap[0].fe != NULL) {
1291 if (dvb_attach(stb6000_attach, d->fe_adap[0].fe, 0x61,
1292 &d->dev->i2c_adap)) {
1293 d->fe_adap[0].fe->ops.set_voltage = dw210x_set_voltage;
1294 info("Attached stv0288!");
1300 if (dw2102_properties.i2c_algo == &dw2102_i2c_algo) {
1301 /*dw2102_properties.adapter->tuner_attach = dw2102_tuner_attach;*/
1302 d->fe_adap[0].fe = dvb_attach(stv0299_attach, &sharp_z0194a_config,
1304 if (d->fe_adap[0].fe != NULL) {
1305 d->fe_adap[0].fe->ops.set_voltage = dw210x_set_voltage;
1306 info("Attached stv0299!");
1313 static int dw3101_frontend_attach(struct dvb_usb_adapter *d)
1315 d->fe_adap[0].fe = dvb_attach(tda10023_attach, &dw3101_tda10023_config,
1316 &d->dev->i2c_adap, 0x48);
1317 if (d->fe_adap[0].fe != NULL) {
1318 info("Attached tda10023!");
1324 static int zl100313_frontend_attach(struct dvb_usb_adapter *d)
1326 d->fe_adap[0].fe = dvb_attach(mt312_attach, &zl313_config,
1328 if (d->fe_adap[0].fe != NULL) {
1329 if (dvb_attach(zl10039_attach, d->fe_adap[0].fe, 0x60,
1330 &d->dev->i2c_adap)) {
1331 d->fe_adap[0].fe->ops.set_voltage = dw210x_set_voltage;
1332 info("Attached zl100313+zl10039!");
1340 static int stv0288_frontend_attach(struct dvb_usb_adapter *d)
1344 d->fe_adap[0].fe = dvb_attach(stv0288_attach, &earda_config,
1347 if (d->fe_adap[0].fe == NULL)
1350 if (NULL == dvb_attach(stb6000_attach, d->fe_adap[0].fe, 0x61, &d->dev->i2c_adap))
1353 d->fe_adap[0].fe->ops.set_voltage = dw210x_set_voltage;
1355 dw210x_op_rw(d->dev->udev, 0x8a, 0, 0, obuf, 2, DW210X_WRITE_MSG);
1357 info("Attached stv0288+stb6000!");
1363 static int ds3000_frontend_attach(struct dvb_usb_adapter *d)
1365 struct dw2102_state *st = d->dev->priv;
1368 d->fe_adap[0].fe = dvb_attach(ds3000_attach, &s660_ds3000_config,
1371 if (d->fe_adap[0].fe == NULL)
1374 dvb_attach(ts2020_attach, d->fe_adap[0].fe, &s660_ts2020_config,
1377 st->old_set_voltage = d->fe_adap[0].fe->ops.set_voltage;
1378 d->fe_adap[0].fe->ops.set_voltage = s660_set_voltage;
1380 dw210x_op_rw(d->dev->udev, 0x8a, 0, 0, obuf, 2, DW210X_WRITE_MSG);
1382 info("Attached ds3000+ts2020!");
1387 static int prof_7500_frontend_attach(struct dvb_usb_adapter *d)
1391 d->fe_adap[0].fe = dvb_attach(stv0900_attach, &prof_7500_stv0900_config,
1392 &d->dev->i2c_adap, 0);
1393 if (d->fe_adap[0].fe == NULL)
1396 d->fe_adap[0].fe->ops.set_voltage = dw210x_set_voltage;
1398 dw210x_op_rw(d->dev->udev, 0x8a, 0, 0, obuf, 2, DW210X_WRITE_MSG);
1400 info("Attached STV0900+STB6100A!");
1405 static int su3000_frontend_attach(struct dvb_usb_adapter *adap)
1407 struct dvb_usb_device *d = adap->dev;
1408 struct dw2102_state *state = d->priv;
1410 mutex_lock(&d->data_mutex);
1412 state->data[0] = 0xe;
1413 state->data[1] = 0x80;
1416 if (dvb_usb_generic_rw(d, state->data, 3, state->data, 1, 0) < 0)
1417 err("command 0x0e transfer failed.");
1419 state->data[0] = 0xe;
1420 state->data[1] = 0x02;
1423 if (dvb_usb_generic_rw(d, state->data, 3, state->data, 1, 0) < 0)
1424 err("command 0x0e transfer failed.");
1427 state->data[0] = 0xe;
1428 state->data[1] = 0x83;
1431 if (dvb_usb_generic_rw(d, state->data, 3, state->data, 1, 0) < 0)
1432 err("command 0x0e transfer failed.");
1434 state->data[0] = 0xe;
1435 state->data[1] = 0x83;
1438 if (dvb_usb_generic_rw(d, state->data, 3, state->data, 1, 0) < 0)
1439 err("command 0x0e transfer failed.");
1441 state->data[0] = 0x51;
1443 if (dvb_usb_generic_rw(d, state->data, 1, state->data, 1, 0) < 0)
1444 err("command 0x51 transfer failed.");
1446 mutex_unlock(&d->data_mutex);
1448 adap->fe_adap[0].fe = dvb_attach(ds3000_attach, &su3000_ds3000_config,
1450 if (adap->fe_adap[0].fe == NULL)
1453 if (dvb_attach(ts2020_attach, adap->fe_adap[0].fe,
1454 &dw2104_ts2020_config,
1456 info("Attached DS3000/TS2020!");
1460 info("Failed to attach DS3000/TS2020!");
1464 static int t220_frontend_attach(struct dvb_usb_adapter *adap)
1466 struct dvb_usb_device *d = adap->dev;
1467 struct dw2102_state *state = d->priv;
1469 mutex_lock(&d->data_mutex);
1471 state->data[0] = 0xe;
1472 state->data[1] = 0x87;
1473 state->data[2] = 0x0;
1475 if (dvb_usb_generic_rw(d, state->data, 3, state->data, 1, 0) < 0)
1476 err("command 0x0e transfer failed.");
1478 state->data[0] = 0xe;
1479 state->data[1] = 0x86;
1482 if (dvb_usb_generic_rw(d, state->data, 3, state->data, 1, 0) < 0)
1483 err("command 0x0e transfer failed.");
1485 state->data[0] = 0xe;
1486 state->data[1] = 0x80;
1489 if (dvb_usb_generic_rw(d, state->data, 3, state->data, 1, 0) < 0)
1490 err("command 0x0e transfer failed.");
1494 state->data[0] = 0xe;
1495 state->data[1] = 0x80;
1498 if (dvb_usb_generic_rw(d, state->data, 3, state->data, 1, 0) < 0)
1499 err("command 0x0e transfer failed.");
1501 state->data[0] = 0x51;
1503 if (dvb_usb_generic_rw(d, state->data, 1, state->data, 1, 0) < 0)
1504 err("command 0x51 transfer failed.");
1506 mutex_unlock(&d->data_mutex);
1508 adap->fe_adap[0].fe = dvb_attach(cxd2820r_attach, &cxd2820r_config,
1509 &d->i2c_adap, NULL);
1510 if (adap->fe_adap[0].fe != NULL) {
1511 if (dvb_attach(tda18271_attach, adap->fe_adap[0].fe, 0x60,
1512 &d->i2c_adap, &tda18271_config)) {
1513 info("Attached TDA18271HD/CXD2820R!");
1518 info("Failed to attach TDA18271HD/CXD2820R!");
1522 static int m88rs2000_frontend_attach(struct dvb_usb_adapter *adap)
1524 struct dvb_usb_device *d = adap->dev;
1525 struct dw2102_state *state = d->priv;
1527 mutex_lock(&d->data_mutex);
1529 state->data[0] = 0x51;
1531 if (dvb_usb_generic_rw(d, state->data, 1, state->data, 1, 0) < 0)
1532 err("command 0x51 transfer failed.");
1534 mutex_unlock(&d->data_mutex);
1536 adap->fe_adap[0].fe = dvb_attach(m88rs2000_attach,
1537 &s421_m88rs2000_config,
1540 if (adap->fe_adap[0].fe == NULL)
1543 if (dvb_attach(ts2020_attach, adap->fe_adap[0].fe,
1544 &dw2104_ts2020_config,
1546 info("Attached RS2000/TS2020!");
1550 info("Failed to attach RS2000/TS2020!");
1554 static int tt_s2_4600_frontend_attach(struct dvb_usb_adapter *adap)
1556 struct dvb_usb_device *d = adap->dev;
1557 struct dw2102_state *state = d->priv;
1558 struct i2c_adapter *i2c_adapter;
1559 struct i2c_client *client;
1560 struct i2c_board_info board_info;
1561 struct m88ds3103_platform_data m88ds3103_pdata = {};
1562 struct ts2020_config ts2020_config = {};
1564 mutex_lock(&d->data_mutex);
1566 state->data[0] = 0xe;
1567 state->data[1] = 0x80;
1568 state->data[2] = 0x0;
1570 if (dvb_usb_generic_rw(d, state->data, 3, state->data, 1, 0) < 0)
1571 err("command 0x0e transfer failed.");
1573 state->data[0] = 0xe;
1574 state->data[1] = 0x02;
1577 if (dvb_usb_generic_rw(d, state->data, 3, state->data, 1, 0) < 0)
1578 err("command 0x0e transfer failed.");
1581 state->data[0] = 0xe;
1582 state->data[1] = 0x83;
1585 if (dvb_usb_generic_rw(d, state->data, 3, state->data, 1, 0) < 0)
1586 err("command 0x0e transfer failed.");
1588 state->data[0] = 0xe;
1589 state->data[1] = 0x83;
1592 if (dvb_usb_generic_rw(d, state->data, 3, state->data, 1, 0) < 0)
1593 err("command 0x0e transfer failed.");
1595 state->data[0] = 0x51;
1597 if (dvb_usb_generic_rw(d, state->data, 1, state->data, 1, 0) < 0)
1598 err("command 0x51 transfer failed.");
1600 mutex_unlock(&d->data_mutex);
1603 m88ds3103_pdata.clk = 27000000;
1604 m88ds3103_pdata.i2c_wr_max = 33;
1605 m88ds3103_pdata.ts_mode = M88DS3103_TS_CI;
1606 m88ds3103_pdata.ts_clk = 16000;
1607 m88ds3103_pdata.ts_clk_pol = 0;
1608 m88ds3103_pdata.spec_inv = 0;
1609 m88ds3103_pdata.agc = 0x99;
1610 m88ds3103_pdata.agc_inv = 0;
1611 m88ds3103_pdata.clk_out = M88DS3103_CLOCK_OUT_ENABLED;
1612 m88ds3103_pdata.envelope_mode = 0;
1613 m88ds3103_pdata.lnb_hv_pol = 1;
1614 m88ds3103_pdata.lnb_en_pol = 0;
1615 memset(&board_info, 0, sizeof(board_info));
1616 strlcpy(board_info.type, "m88ds3103", I2C_NAME_SIZE);
1617 board_info.addr = 0x68;
1618 board_info.platform_data = &m88ds3103_pdata;
1619 request_module("m88ds3103");
1620 client = i2c_new_device(&d->i2c_adap, &board_info);
1621 if (client == NULL || client->dev.driver == NULL)
1623 if (!try_module_get(client->dev.driver->owner)) {
1624 i2c_unregister_device(client);
1627 adap->fe_adap[0].fe = m88ds3103_pdata.get_dvb_frontend(client);
1628 i2c_adapter = m88ds3103_pdata.get_i2c_adapter(client);
1630 state->i2c_client_demod = client;
1633 ts2020_config.fe = adap->fe_adap[0].fe;
1634 memset(&board_info, 0, sizeof(board_info));
1635 strlcpy(board_info.type, "ts2022", I2C_NAME_SIZE);
1636 board_info.addr = 0x60;
1637 board_info.platform_data = &ts2020_config;
1638 request_module("ts2020");
1639 client = i2c_new_device(i2c_adapter, &board_info);
1641 if (client == NULL || client->dev.driver == NULL) {
1642 dvb_frontend_detach(adap->fe_adap[0].fe);
1646 if (!try_module_get(client->dev.driver->owner)) {
1647 i2c_unregister_device(client);
1648 dvb_frontend_detach(adap->fe_adap[0].fe);
1652 /* delegate signal strength measurement to tuner */
1653 adap->fe_adap[0].fe->ops.read_signal_strength =
1654 adap->fe_adap[0].fe->ops.tuner_ops.get_rf_strength;
1656 state->i2c_client_tuner = client;
1658 /* hook fe: need to resync the slave fifo when signal locks */
1659 state->fe_read_status = adap->fe_adap[0].fe->ops.read_status;
1660 adap->fe_adap[0].fe->ops.read_status = tt_s2_4600_read_status;
1662 state->last_lock = 0;
1667 static int dw2102_tuner_attach(struct dvb_usb_adapter *adap)
1669 dvb_attach(dvb_pll_attach, adap->fe_adap[0].fe, 0x60,
1670 &adap->dev->i2c_adap, DVB_PLL_OPERA1);
1674 static int dw3101_tuner_attach(struct dvb_usb_adapter *adap)
1676 dvb_attach(dvb_pll_attach, adap->fe_adap[0].fe, 0x60,
1677 &adap->dev->i2c_adap, DVB_PLL_TUA6034);
1682 static int dw2102_rc_query(struct dvb_usb_device *d)
1685 struct i2c_msg msg = {
1686 .addr = DW2102_RC_QUERY,
1692 if (d->props.i2c_algo->master_xfer(&d->i2c_adap, &msg, 1) == 1) {
1693 if (msg.buf[0] != 0xff) {
1694 deb_rc("%s: rc code: %x, %x\n",
1695 __func__, key[0], key[1]);
1696 rc_keydown(d->rc_dev, RC_PROTO_UNKNOWN, key[0], 0);
1703 static int prof_rc_query(struct dvb_usb_device *d)
1706 struct i2c_msg msg = {
1707 .addr = DW2102_RC_QUERY,
1713 if (d->props.i2c_algo->master_xfer(&d->i2c_adap, &msg, 1) == 1) {
1714 if (msg.buf[0] != 0xff) {
1715 deb_rc("%s: rc code: %x, %x\n",
1716 __func__, key[0], key[1]);
1717 rc_keydown(d->rc_dev, RC_PROTO_UNKNOWN, key[0] ^ 0xff,
1725 static int su3000_rc_query(struct dvb_usb_device *d)
1728 struct i2c_msg msg = {
1729 .addr = DW2102_RC_QUERY,
1735 if (d->props.i2c_algo->master_xfer(&d->i2c_adap, &msg, 1) == 1) {
1736 if (msg.buf[0] != 0xff) {
1737 deb_rc("%s: rc code: %x, %x\n",
1738 __func__, key[0], key[1]);
1739 rc_keydown(d->rc_dev, RC_PROTO_RC5,
1740 RC_SCANCODE_RC5(key[1], key[0]), 0);
1747 enum dw2102_table_entry {
1759 TERRATEC_CINERGY_S2,
1765 TERRATEC_CINERGY_S2_R2,
1766 TERRATEC_CINERGY_S2_R3,
1767 TERRATEC_CINERGY_S2_R4,
1770 TECHNOTREND_S2_4600,
1773 TERRATEC_CINERGY_S2_BOX,
1777 static struct usb_device_id dw2102_table[] = {
1778 [CYPRESS_DW2102] = {USB_DEVICE(USB_VID_CYPRESS, USB_PID_DW2102)},
1779 [CYPRESS_DW2101] = {USB_DEVICE(USB_VID_CYPRESS, 0x2101)},
1780 [CYPRESS_DW2104] = {USB_DEVICE(USB_VID_CYPRESS, USB_PID_DW2104)},
1781 [TEVII_S650] = {USB_DEVICE(0x9022, USB_PID_TEVII_S650)},
1782 [TERRATEC_CINERGY_S] = {USB_DEVICE(USB_VID_TERRATEC, USB_PID_TERRATEC_CINERGY_S)},
1783 [CYPRESS_DW3101] = {USB_DEVICE(USB_VID_CYPRESS, USB_PID_DW3101)},
1784 [TEVII_S630] = {USB_DEVICE(0x9022, USB_PID_TEVII_S630)},
1785 [PROF_1100] = {USB_DEVICE(0x3011, USB_PID_PROF_1100)},
1786 [TEVII_S660] = {USB_DEVICE(0x9022, USB_PID_TEVII_S660)},
1787 [PROF_7500] = {USB_DEVICE(0x3034, 0x7500)},
1788 [GENIATECH_SU3000] = {USB_DEVICE(0x1f4d, 0x3000)},
1789 [TERRATEC_CINERGY_S2] = {USB_DEVICE(USB_VID_TERRATEC, USB_PID_TERRATEC_CINERGY_S2_R1)},
1790 [TEVII_S480_1] = {USB_DEVICE(0x9022, USB_PID_TEVII_S480_1)},
1791 [TEVII_S480_2] = {USB_DEVICE(0x9022, USB_PID_TEVII_S480_2)},
1792 [X3M_SPC1400HD] = {USB_DEVICE(0x1f4d, 0x3100)},
1793 [TEVII_S421] = {USB_DEVICE(0x9022, USB_PID_TEVII_S421)},
1794 [TEVII_S632] = {USB_DEVICE(0x9022, USB_PID_TEVII_S632)},
1795 [TERRATEC_CINERGY_S2_R2] = {USB_DEVICE(USB_VID_TERRATEC, USB_PID_TERRATEC_CINERGY_S2_R2)},
1796 [TERRATEC_CINERGY_S2_R3] = {USB_DEVICE(USB_VID_TERRATEC, USB_PID_TERRATEC_CINERGY_S2_R3)},
1797 [TERRATEC_CINERGY_S2_R4] = {USB_DEVICE(USB_VID_TERRATEC, USB_PID_TERRATEC_CINERGY_S2_R4)},
1798 [GOTVIEW_SAT_HD] = {USB_DEVICE(0x1FE1, USB_PID_GOTVIEW_SAT_HD)},
1799 [GENIATECH_T220] = {USB_DEVICE(0x1f4d, 0xD220)},
1800 [TECHNOTREND_S2_4600] = {USB_DEVICE(USB_VID_TECHNOTREND,
1801 USB_PID_TECHNOTREND_CONNECT_S2_4600)},
1802 [TEVII_S482_1] = {USB_DEVICE(0x9022, 0xd483)},
1803 [TEVII_S482_2] = {USB_DEVICE(0x9022, 0xd484)},
1804 [TERRATEC_CINERGY_S2_BOX] = {USB_DEVICE(USB_VID_TERRATEC, 0x0105)},
1805 [TEVII_S662] = {USB_DEVICE(0x9022, USB_PID_TEVII_S662)},
1809 MODULE_DEVICE_TABLE(usb, dw2102_table);
1811 static int dw2102_load_firmware(struct usb_device *dev,
1812 const struct firmware *frmwr)
1817 u8 reset16[] = {0, 0, 0, 0, 0, 0, 0};
1818 const struct firmware *fw;
1820 switch (le16_to_cpu(dev->descriptor.idProduct)) {
1822 ret = reject_firmware(&fw, DW2101_FIRMWARE, &dev->dev);
1824 err(err_str, DW2101_FIRMWARE);
1832 info("start downloading DW210X firmware");
1833 p = kmalloc(fw->size, GFP_KERNEL);
1836 dw210x_op_rw(dev, 0xa0, 0x7f92, 0, &reset, 1, DW210X_WRITE_MSG);
1837 dw210x_op_rw(dev, 0xa0, 0xe600, 0, &reset, 1, DW210X_WRITE_MSG);
1840 memcpy(p, fw->data, fw->size);
1841 for (i = 0; i < fw->size; i += 0x40) {
1843 if (dw210x_op_rw(dev, 0xa0, i, 0, b , 0x40,
1844 DW210X_WRITE_MSG) != 0x40) {
1845 err("error while transferring firmware");
1850 /* restart the CPU */
1852 if (ret || dw210x_op_rw(dev, 0xa0, 0x7f92, 0, &reset, 1,
1853 DW210X_WRITE_MSG) != 1) {
1854 err("could not restart the USB controller CPU.");
1857 if (ret || dw210x_op_rw(dev, 0xa0, 0xe600, 0, &reset, 1,
1858 DW210X_WRITE_MSG) != 1) {
1859 err("could not restart the USB controller CPU.");
1862 /* init registers */
1863 switch (le16_to_cpu(dev->descriptor.idProduct)) {
1864 case USB_PID_TEVII_S650:
1865 dw2104_properties.rc.core.rc_codes = RC_MAP_TEVII_NEC;
1867 case USB_PID_DW2104:
1869 dw210x_op_rw(dev, 0xc4, 0x0000, 0, &reset, 1,
1872 case USB_PID_DW3101:
1874 dw210x_op_rw(dev, 0xbf, 0x0040, 0, &reset, 0,
1877 case USB_PID_TERRATEC_CINERGY_S:
1878 case USB_PID_DW2102:
1879 dw210x_op_rw(dev, 0xbf, 0x0040, 0, &reset, 0,
1881 dw210x_op_rw(dev, 0xb9, 0x0000, 0, &reset16[0], 2,
1883 /* check STV0299 frontend */
1884 dw210x_op_rw(dev, 0xb5, 0, 0, &reset16[0], 2,
1886 if ((reset16[0] == 0xa1) || (reset16[0] == 0x80)) {
1887 dw2102_properties.i2c_algo = &dw2102_i2c_algo;
1888 dw2102_properties.adapter->fe[0].tuner_attach = &dw2102_tuner_attach;
1891 /* check STV0288 frontend */
1895 dw210x_op_rw(dev, 0xc2, 0, 0, &reset16[0], 3,
1897 dw210x_op_rw(dev, 0xc3, 0xd1, 0, &reset16[0], 3,
1899 if (reset16[2] == 0x11) {
1900 dw2102_properties.i2c_algo = &dw2102_earda_i2c_algo;
1906 dw210x_op_rw(dev, 0xbc, 0x0030, 0, &reset16[0], 2,
1908 dw210x_op_rw(dev, 0xba, 0x0000, 0, &reset16[0], 7,
1910 dw210x_op_rw(dev, 0xba, 0x0000, 0, &reset16[0], 7,
1912 dw210x_op_rw(dev, 0xb9, 0x0000, 0, &reset16[0], 2,
1921 if (le16_to_cpu(dev->descriptor.idProduct) == 0x2101)
1922 release_firmware(fw);
1926 static struct dvb_usb_device_properties dw2102_properties = {
1927 .caps = DVB_USB_IS_AN_I2C_ADAPTER,
1928 .usb_ctrl = DEVICE_SPECIFIC,
1929 .firmware = DW2102_FIRMWARE,
1932 .i2c_algo = &dw2102_serit_i2c_algo,
1936 .rc_codes = RC_MAP_DM1105_NEC,
1937 .module_name = "dw2102",
1938 .allowed_protos = RC_PROTO_BIT_NEC,
1939 .rc_query = dw2102_rc_query,
1942 .generic_bulk_ctrl_endpoint = 0x81,
1943 /* parameter for the MPEG2-data transfer */
1945 .download_firmware = dw2102_load_firmware,
1946 .read_mac_address = dw210x_read_mac_address,
1951 .frontend_attach = dw2102_frontend_attach,
1965 .num_device_descs = 3,
1967 {"DVBWorld DVB-S 2102 USB2.0",
1968 {&dw2102_table[CYPRESS_DW2102], NULL},
1971 {"DVBWorld DVB-S 2101 USB2.0",
1972 {&dw2102_table[CYPRESS_DW2101], NULL},
1975 {"TerraTec Cinergy S USB",
1976 {&dw2102_table[TERRATEC_CINERGY_S], NULL},
1982 static struct dvb_usb_device_properties dw2104_properties = {
1983 .caps = DVB_USB_IS_AN_I2C_ADAPTER,
1984 .usb_ctrl = DEVICE_SPECIFIC,
1985 .firmware = DW2104_FIRMWARE,
1988 .i2c_algo = &dw2104_i2c_algo,
1991 .rc_codes = RC_MAP_DM1105_NEC,
1992 .module_name = "dw2102",
1993 .allowed_protos = RC_PROTO_BIT_NEC,
1994 .rc_query = dw2102_rc_query,
1997 .generic_bulk_ctrl_endpoint = 0x81,
1998 /* parameter for the MPEG2-data transfer */
2000 .download_firmware = dw2102_load_firmware,
2001 .read_mac_address = dw210x_read_mac_address,
2006 .frontend_attach = dw2104_frontend_attach,
2020 .num_device_descs = 2,
2022 { "DVBWorld DW2104 USB2.0",
2023 {&dw2102_table[CYPRESS_DW2104], NULL},
2026 { "TeVii S650 USB2.0",
2027 {&dw2102_table[TEVII_S650], NULL},
2033 static struct dvb_usb_device_properties dw3101_properties = {
2034 .caps = DVB_USB_IS_AN_I2C_ADAPTER,
2035 .usb_ctrl = DEVICE_SPECIFIC,
2036 .firmware = DW3101_FIRMWARE,
2039 .i2c_algo = &dw3101_i2c_algo,
2042 .rc_codes = RC_MAP_DM1105_NEC,
2043 .module_name = "dw2102",
2044 .allowed_protos = RC_PROTO_BIT_NEC,
2045 .rc_query = dw2102_rc_query,
2048 .generic_bulk_ctrl_endpoint = 0x81,
2049 /* parameter for the MPEG2-data transfer */
2051 .download_firmware = dw2102_load_firmware,
2052 .read_mac_address = dw210x_read_mac_address,
2057 .frontend_attach = dw3101_frontend_attach,
2058 .tuner_attach = dw3101_tuner_attach,
2072 .num_device_descs = 1,
2074 { "DVBWorld DVB-C 3101 USB2.0",
2075 {&dw2102_table[CYPRESS_DW3101], NULL},
2081 static struct dvb_usb_device_properties s6x0_properties = {
2082 .caps = DVB_USB_IS_AN_I2C_ADAPTER,
2083 .usb_ctrl = DEVICE_SPECIFIC,
2084 .size_of_priv = sizeof(struct dw2102_state),
2085 .firmware = S630_FIRMWARE,
2088 .i2c_algo = &s6x0_i2c_algo,
2091 .rc_codes = RC_MAP_TEVII_NEC,
2092 .module_name = "dw2102",
2093 .allowed_protos = RC_PROTO_BIT_NEC,
2094 .rc_query = dw2102_rc_query,
2097 .generic_bulk_ctrl_endpoint = 0x81,
2099 .download_firmware = dw2102_load_firmware,
2100 .read_mac_address = s6x0_read_mac_address,
2105 .frontend_attach = zl100313_frontend_attach,
2119 .num_device_descs = 1,
2122 {&dw2102_table[TEVII_S630], NULL},
2128 static struct dvb_usb_device_properties p1100_properties = {
2129 .caps = DVB_USB_IS_AN_I2C_ADAPTER,
2130 .usb_ctrl = DEVICE_SPECIFIC,
2131 .size_of_priv = sizeof(struct dw2102_state),
2132 .firmware = P1100_FIRMWARE,
2135 .i2c_algo = &s6x0_i2c_algo,
2138 .rc_codes = RC_MAP_TBS_NEC,
2139 .module_name = "dw2102",
2140 .allowed_protos = RC_PROTO_BIT_NEC,
2141 .rc_query = prof_rc_query,
2144 .generic_bulk_ctrl_endpoint = 0x81,
2146 .download_firmware = dw2102_load_firmware,
2147 .read_mac_address = s6x0_read_mac_address,
2152 .frontend_attach = stv0288_frontend_attach,
2166 .num_device_descs = 1,
2169 {&dw2102_table[PROF_1100], NULL},
2175 static struct dvb_usb_device_properties s660_properties = {
2176 .caps = DVB_USB_IS_AN_I2C_ADAPTER,
2177 .usb_ctrl = DEVICE_SPECIFIC,
2178 .size_of_priv = sizeof(struct dw2102_state),
2179 .firmware = S660_FIRMWARE,
2182 .i2c_algo = &s6x0_i2c_algo,
2185 .rc_codes = RC_MAP_TEVII_NEC,
2186 .module_name = "dw2102",
2187 .allowed_protos = RC_PROTO_BIT_NEC,
2188 .rc_query = dw2102_rc_query,
2191 .generic_bulk_ctrl_endpoint = 0x81,
2193 .download_firmware = dw2102_load_firmware,
2194 .read_mac_address = s6x0_read_mac_address,
2199 .frontend_attach = ds3000_frontend_attach,
2213 .num_device_descs = 3,
2216 {&dw2102_table[TEVII_S660], NULL},
2219 {"TeVii S480.1 USB",
2220 {&dw2102_table[TEVII_S480_1], NULL},
2223 {"TeVii S480.2 USB",
2224 {&dw2102_table[TEVII_S480_2], NULL},
2230 static struct dvb_usb_device_properties p7500_properties = {
2231 .caps = DVB_USB_IS_AN_I2C_ADAPTER,
2232 .usb_ctrl = DEVICE_SPECIFIC,
2233 .size_of_priv = sizeof(struct dw2102_state),
2234 .firmware = P7500_FIRMWARE,
2237 .i2c_algo = &s6x0_i2c_algo,
2240 .rc_codes = RC_MAP_TBS_NEC,
2241 .module_name = "dw2102",
2242 .allowed_protos = RC_PROTO_BIT_NEC,
2243 .rc_query = prof_rc_query,
2246 .generic_bulk_ctrl_endpoint = 0x81,
2248 .download_firmware = dw2102_load_firmware,
2249 .read_mac_address = s6x0_read_mac_address,
2254 .frontend_attach = prof_7500_frontend_attach,
2268 .num_device_descs = 1,
2270 {"Prof 7500 USB DVB-S2",
2271 {&dw2102_table[PROF_7500], NULL},
2277 static struct dvb_usb_device_properties su3000_properties = {
2278 .caps = DVB_USB_IS_AN_I2C_ADAPTER,
2279 .usb_ctrl = DEVICE_SPECIFIC,
2280 .size_of_priv = sizeof(struct dw2102_state),
2281 .power_ctrl = su3000_power_ctrl,
2283 .identify_state = su3000_identify_state,
2284 .i2c_algo = &su3000_i2c_algo,
2288 .rc_codes = RC_MAP_SU3000,
2289 .module_name = "dw2102",
2290 .allowed_protos = RC_PROTO_BIT_RC5,
2291 .rc_query = su3000_rc_query,
2294 .read_mac_address = su3000_read_mac_address,
2296 .generic_bulk_ctrl_endpoint = 0x01,
2302 .streaming_ctrl = su3000_streaming_ctrl,
2303 .frontend_attach = su3000_frontend_attach,
2317 .num_device_descs = 6,
2319 { "SU3000HD DVB-S USB2.0",
2320 { &dw2102_table[GENIATECH_SU3000], NULL },
2323 { "Terratec Cinergy S2 USB HD",
2324 { &dw2102_table[TERRATEC_CINERGY_S2], NULL },
2327 { "X3M TV SPC1400HD PCI",
2328 { &dw2102_table[X3M_SPC1400HD], NULL },
2331 { "Terratec Cinergy S2 USB HD Rev.2",
2332 { &dw2102_table[TERRATEC_CINERGY_S2_R2], NULL },
2335 { "Terratec Cinergy S2 USB HD Rev.3",
2336 { &dw2102_table[TERRATEC_CINERGY_S2_R3], NULL },
2339 { "GOTVIEW Satellite HD",
2340 { &dw2102_table[GOTVIEW_SAT_HD], NULL },
2346 static struct dvb_usb_device_properties s421_properties = {
2347 .caps = DVB_USB_IS_AN_I2C_ADAPTER,
2348 .usb_ctrl = DEVICE_SPECIFIC,
2349 .size_of_priv = sizeof(struct dw2102_state),
2350 .power_ctrl = su3000_power_ctrl,
2352 .identify_state = su3000_identify_state,
2353 .i2c_algo = &su3000_i2c_algo,
2357 .rc_codes = RC_MAP_SU3000,
2358 .module_name = "dw2102",
2359 .allowed_protos = RC_PROTO_BIT_RC5,
2360 .rc_query = su3000_rc_query,
2363 .read_mac_address = su3000_read_mac_address,
2365 .generic_bulk_ctrl_endpoint = 0x01,
2371 .streaming_ctrl = su3000_streaming_ctrl,
2372 .frontend_attach = m88rs2000_frontend_attach,
2386 .num_device_descs = 2,
2389 { &dw2102_table[TEVII_S421], NULL },
2393 { &dw2102_table[TEVII_S632], NULL },
2399 static struct dvb_usb_device_properties t220_properties = {
2400 .caps = DVB_USB_IS_AN_I2C_ADAPTER,
2401 .usb_ctrl = DEVICE_SPECIFIC,
2402 .size_of_priv = sizeof(struct dw2102_state),
2403 .power_ctrl = su3000_power_ctrl,
2405 .identify_state = su3000_identify_state,
2406 .i2c_algo = &su3000_i2c_algo,
2410 .rc_codes = RC_MAP_SU3000,
2411 .module_name = "dw2102",
2412 .allowed_protos = RC_PROTO_BIT_RC5,
2413 .rc_query = su3000_rc_query,
2416 .read_mac_address = su3000_read_mac_address,
2418 .generic_bulk_ctrl_endpoint = 0x01,
2424 .streaming_ctrl = su3000_streaming_ctrl,
2425 .frontend_attach = t220_frontend_attach,
2439 .num_device_descs = 1,
2441 { "Geniatech T220 DVB-T/T2 USB2.0",
2442 { &dw2102_table[GENIATECH_T220], NULL },
2448 static struct dvb_usb_device_properties tt_s2_4600_properties = {
2449 .caps = DVB_USB_IS_AN_I2C_ADAPTER,
2450 .usb_ctrl = DEVICE_SPECIFIC,
2451 .size_of_priv = sizeof(struct dw2102_state),
2452 .power_ctrl = su3000_power_ctrl,
2454 .identify_state = su3000_identify_state,
2455 .i2c_algo = &su3000_i2c_algo,
2459 .rc_codes = RC_MAP_TT_1500,
2460 .module_name = "dw2102",
2461 .allowed_protos = RC_PROTO_BIT_RC5,
2462 .rc_query = su3000_rc_query,
2465 .read_mac_address = su3000_read_mac_address,
2467 .generic_bulk_ctrl_endpoint = 0x01,
2473 .streaming_ctrl = su3000_streaming_ctrl,
2474 .frontend_attach = tt_s2_4600_frontend_attach,
2488 .num_device_descs = 5,
2490 { "TechnoTrend TT-connect S2-4600",
2491 { &dw2102_table[TECHNOTREND_S2_4600], NULL },
2494 { "TeVii S482 (tuner 1)",
2495 { &dw2102_table[TEVII_S482_1], NULL },
2498 { "TeVii S482 (tuner 2)",
2499 { &dw2102_table[TEVII_S482_2], NULL },
2502 { "Terratec Cinergy S2 USB BOX",
2503 { &dw2102_table[TERRATEC_CINERGY_S2_BOX], NULL },
2507 { &dw2102_table[TEVII_S662], NULL },
2513 static int dw2102_probe(struct usb_interface *intf,
2514 const struct usb_device_id *id)
2516 if (!(dvb_usb_device_init(intf, &dw2102_properties,
2517 THIS_MODULE, NULL, adapter_nr) &&
2518 dvb_usb_device_init(intf, &dw2104_properties,
2519 THIS_MODULE, NULL, adapter_nr) &&
2520 dvb_usb_device_init(intf, &dw3101_properties,
2521 THIS_MODULE, NULL, adapter_nr) &&
2522 dvb_usb_device_init(intf, &s6x0_properties,
2523 THIS_MODULE, NULL, adapter_nr) &&
2524 dvb_usb_device_init(intf, &p1100_properties,
2525 THIS_MODULE, NULL, adapter_nr) &&
2526 dvb_usb_device_init(intf, &s660_properties,
2527 THIS_MODULE, NULL, adapter_nr) &&
2528 dvb_usb_device_init(intf, &p7500_properties,
2529 THIS_MODULE, NULL, adapter_nr) &&
2530 dvb_usb_device_init(intf, &s421_properties,
2531 THIS_MODULE, NULL, adapter_nr) &&
2532 dvb_usb_device_init(intf, &su3000_properties,
2533 THIS_MODULE, NULL, adapter_nr) &&
2534 dvb_usb_device_init(intf, &t220_properties,
2535 THIS_MODULE, NULL, adapter_nr) &&
2536 dvb_usb_device_init(intf, &tt_s2_4600_properties,
2537 THIS_MODULE, NULL, adapter_nr))) {
2545 static void dw2102_disconnect(struct usb_interface *intf)
2547 struct dvb_usb_device *d = usb_get_intfdata(intf);
2548 struct dw2102_state *st = (struct dw2102_state *)d->priv;
2549 struct i2c_client *client;
2551 /* remove I2C client for tuner */
2552 client = st->i2c_client_tuner;
2554 module_put(client->dev.driver->owner);
2555 i2c_unregister_device(client);
2558 /* remove I2C client for demodulator */
2559 client = st->i2c_client_demod;
2561 module_put(client->dev.driver->owner);
2562 i2c_unregister_device(client);
2565 dvb_usb_device_exit(intf);
2568 static struct usb_driver dw2102_driver = {
2570 .probe = dw2102_probe,
2571 .disconnect = dw2102_disconnect,
2572 .id_table = dw2102_table,
2575 module_usb_driver(dw2102_driver);
2577 MODULE_AUTHOR("Igor M. Liplianin (c) liplianin@me.by");
2578 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");
2579 MODULE_VERSION("0.1");
2580 MODULE_LICENSE("GPL");