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 "dvb-usb-dw2101.fw"
56 #define DW2102_FIRMWARE "dvb-usb-dw2102.fw"
57 #define DW2104_FIRMWARE "dvb-usb-dw2104.fw"
58 #define DW3101_FIRMWARE "dvb-usb-dw3101.fw"
59 #define S630_FIRMWARE "dvb-usb-s630.fw"
60 #define S660_FIRMWARE "dvb-usb-s660.fw"
61 #define P1100_FIRMWARE "dvb-usb-p1100.fw"
62 #define P7500_FIRMWARE "dvb-usb-p7500.fw"
64 #define err_str "did not find the firmware file. (%s) " \
65 "Please see linux/Documentation/dvb/ for more details " \
66 "on firmware-problems."
71 struct i2c_client *i2c_client_demod;
72 struct i2c_client *i2c_client_tuner;
74 /* fe hook functions*/
75 int (*old_set_voltage)(struct dvb_frontend *f, enum fe_sec_voltage v);
76 int (*fe_read_status)(struct dvb_frontend *fe,
77 enum fe_status *status);
81 static int dvb_usb_dw2102_debug;
82 module_param_named(debug, dvb_usb_dw2102_debug, int, 0644);
83 MODULE_PARM_DESC(debug, "set debugging level (1=info 2=xfer 4=rc(or-able))."
84 DVB_USB_DEBUG_STATUS);
87 static int demod_probe = 1;
88 module_param_named(demod, demod_probe, int, 0644);
89 MODULE_PARM_DESC(demod, "demod to probe (1=cx24116 2=stv0903+stv6110 "
90 "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 /* read stv0299 register */
137 value = msg[0].buf[0];/* register */
138 for (i = 0; i < msg[1].len; i++) {
139 dw210x_op_rw(d->udev, 0xb5, value + i, 0,
140 buf6, 2, DW210X_READ_MSG);
141 msg[1].buf[i] = buf6[0];
145 switch (msg[0].addr) {
147 /* write to stv0299 register */
149 buf6[1] = msg[0].buf[0];
150 buf6[2] = msg[0].buf[1];
151 dw210x_op_rw(d->udev, 0xb2, 0, 0,
152 buf6, 3, DW210X_WRITE_MSG);
155 if (msg[0].flags == 0) {
156 /* write to tuner pll */
160 buf6[3] = msg[0].buf[0];
161 buf6[4] = msg[0].buf[1];
162 buf6[5] = msg[0].buf[2];
163 buf6[6] = msg[0].buf[3];
164 dw210x_op_rw(d->udev, 0xb2, 0, 0,
165 buf6, 7, DW210X_WRITE_MSG);
167 /* read from tuner */
168 dw210x_op_rw(d->udev, 0xb5, 0, 0,
169 buf6, 1, DW210X_READ_MSG);
170 msg[0].buf[0] = buf6[0];
173 case (DW2102_RC_QUERY):
174 dw210x_op_rw(d->udev, 0xb8, 0, 0,
175 buf6, 2, DW210X_READ_MSG);
176 msg[0].buf[0] = buf6[0];
177 msg[0].buf[1] = buf6[1];
179 case (DW2102_VOLTAGE_CTRL):
181 buf6[1] = msg[0].buf[0];
182 dw210x_op_rw(d->udev, 0xb2, 0, 0,
183 buf6, 2, DW210X_WRITE_MSG);
190 mutex_unlock(&d->i2c_mutex);
194 static int dw2102_serit_i2c_transfer(struct i2c_adapter *adap,
195 struct i2c_msg msg[], int num)
197 struct dvb_usb_device *d = i2c_get_adapdata(adap);
198 u8 buf6[] = {0, 0, 0, 0, 0, 0, 0};
202 if (mutex_lock_interruptible(&d->i2c_mutex) < 0)
207 /* read si2109 register by number */
208 buf6[0] = msg[0].addr << 1;
209 buf6[1] = msg[0].len;
210 buf6[2] = msg[0].buf[0];
211 dw210x_op_rw(d->udev, 0xc2, 0, 0,
212 buf6, msg[0].len + 2, DW210X_WRITE_MSG);
213 /* read si2109 register */
214 dw210x_op_rw(d->udev, 0xc3, 0xd0, 0,
215 buf6, msg[1].len + 2, DW210X_READ_MSG);
216 memcpy(msg[1].buf, buf6 + 2, msg[1].len);
220 switch (msg[0].addr) {
222 /* write to si2109 register */
223 buf6[0] = msg[0].addr << 1;
224 buf6[1] = msg[0].len;
225 memcpy(buf6 + 2, msg[0].buf, msg[0].len);
226 dw210x_op_rw(d->udev, 0xc2, 0, 0, buf6,
227 msg[0].len + 2, DW210X_WRITE_MSG);
229 case(DW2102_RC_QUERY):
230 dw210x_op_rw(d->udev, 0xb8, 0, 0,
231 buf6, 2, DW210X_READ_MSG);
232 msg[0].buf[0] = buf6[0];
233 msg[0].buf[1] = buf6[1];
235 case(DW2102_VOLTAGE_CTRL):
237 buf6[1] = msg[0].buf[0];
238 dw210x_op_rw(d->udev, 0xb2, 0, 0,
239 buf6, 2, DW210X_WRITE_MSG);
245 mutex_unlock(&d->i2c_mutex);
249 static int dw2102_earda_i2c_transfer(struct i2c_adapter *adap, struct i2c_msg msg[], int num)
251 struct dvb_usb_device *d = i2c_get_adapdata(adap);
256 if (mutex_lock_interruptible(&d->i2c_mutex) < 0)
262 /* first write first register number */
263 u8 ibuf[MAX_XFER_SIZE], obuf[3];
265 if (2 + msg[1].len > sizeof(ibuf)) {
266 warn("i2c rd: len=%d is too big!\n",
272 obuf[0] = msg[0].addr << 1;
273 obuf[1] = msg[0].len;
274 obuf[2] = msg[0].buf[0];
275 dw210x_op_rw(d->udev, 0xc2, 0, 0,
276 obuf, msg[0].len + 2, DW210X_WRITE_MSG);
277 /* second read registers */
278 dw210x_op_rw(d->udev, 0xc3, 0xd1 , 0,
279 ibuf, msg[1].len + 2, DW210X_READ_MSG);
280 memcpy(msg[1].buf, ibuf + 2, msg[1].len);
285 switch (msg[0].addr) {
287 /* write to register */
288 u8 obuf[MAX_XFER_SIZE];
290 if (2 + msg[0].len > sizeof(obuf)) {
291 warn("i2c wr: len=%d is too big!\n",
297 obuf[0] = msg[0].addr << 1;
298 obuf[1] = msg[0].len;
299 memcpy(obuf + 2, msg[0].buf, msg[0].len);
300 dw210x_op_rw(d->udev, 0xc2, 0, 0,
301 obuf, msg[0].len + 2, DW210X_WRITE_MSG);
306 u8 obuf[MAX_XFER_SIZE];
308 if (2 + msg[0].len > sizeof(obuf)) {
309 warn("i2c wr: len=%d is too big!\n",
315 obuf[0] = msg[0].addr << 1;
316 obuf[1] = msg[0].len;
317 memcpy(obuf + 2, msg[0].buf, msg[0].len);
318 dw210x_op_rw(d->udev, 0xc2, 0, 0,
319 obuf, msg[0].len + 2, DW210X_WRITE_MSG);
322 case(DW2102_RC_QUERY): {
324 dw210x_op_rw(d->udev, 0xb8, 0, 0,
325 ibuf, 2, DW210X_READ_MSG);
326 memcpy(msg[0].buf, ibuf , 2);
329 case(DW2102_VOLTAGE_CTRL): {
332 obuf[1] = msg[0].buf[0];
333 dw210x_op_rw(d->udev, 0xb2, 0, 0,
334 obuf, 2, DW210X_WRITE_MSG);
344 mutex_unlock(&d->i2c_mutex);
348 static int dw2104_i2c_transfer(struct i2c_adapter *adap, struct i2c_msg msg[], int num)
350 struct dvb_usb_device *d = i2c_get_adapdata(adap);
355 if (mutex_lock_interruptible(&d->i2c_mutex) < 0)
358 for (j = 0; j < num; j++) {
359 switch (msg[j].addr) {
360 case(DW2102_RC_QUERY): {
362 dw210x_op_rw(d->udev, 0xb8, 0, 0,
363 ibuf, 2, DW210X_READ_MSG);
364 memcpy(msg[j].buf, ibuf , 2);
367 case(DW2102_VOLTAGE_CTRL): {
370 obuf[1] = msg[j].buf[0];
371 dw210x_op_rw(d->udev, 0xb2, 0, 0,
372 obuf, 2, DW210X_WRITE_MSG);
377 case 0x68: ds3000, stv0903
378 case 0x60: ts2020, stv6110, stb6100 */
380 if (msg[j].flags == I2C_M_RD) {
382 u8 ibuf[MAX_XFER_SIZE];
384 if (2 + msg[j].len > sizeof(ibuf)) {
385 warn("i2c rd: len=%d is too big!\n",
391 dw210x_op_rw(d->udev, 0xc3,
392 (msg[j].addr << 1) + 1, 0,
393 ibuf, msg[j].len + 2,
395 memcpy(msg[j].buf, ibuf + 2, msg[j].len);
397 } else if (((msg[j].buf[0] == 0xb0) &&
398 (msg[j].addr == 0x68)) ||
399 ((msg[j].buf[0] == 0xf7) &&
400 (msg[j].addr == 0x55))) {
403 obuf[0] = msg[j].addr << 1;
404 obuf[1] = (msg[j].len > 15 ? 17 : msg[j].len);
405 obuf[2] = msg[j].buf[0];
406 len = msg[j].len - 1;
409 memcpy(obuf + 3, msg[j].buf + i,
410 (len > 16 ? 16 : len));
411 dw210x_op_rw(d->udev, 0xc2, 0, 0,
412 obuf, (len > 16 ? 16 : len) + 3,
418 /* write registers */
419 u8 obuf[MAX_XFER_SIZE];
421 if (2 + msg[j].len > sizeof(obuf)) {
422 warn("i2c wr: len=%d is too big!\n",
428 obuf[0] = msg[j].addr << 1;
429 obuf[1] = msg[j].len;
430 memcpy(obuf + 2, msg[j].buf, msg[j].len);
431 dw210x_op_rw(d->udev, 0xc2, 0, 0,
432 obuf, msg[j].len + 2,
443 mutex_unlock(&d->i2c_mutex);
447 static int dw3101_i2c_transfer(struct i2c_adapter *adap, struct i2c_msg msg[],
450 struct dvb_usb_device *d = i2c_get_adapdata(adap);
456 if (mutex_lock_interruptible(&d->i2c_mutex) < 0)
462 /* first write first register number */
463 u8 ibuf[MAX_XFER_SIZE], obuf[3];
465 if (2 + msg[1].len > sizeof(ibuf)) {
466 warn("i2c rd: len=%d is too big!\n",
471 obuf[0] = msg[0].addr << 1;
472 obuf[1] = msg[0].len;
473 obuf[2] = msg[0].buf[0];
474 dw210x_op_rw(d->udev, 0xc2, 0, 0,
475 obuf, msg[0].len + 2, DW210X_WRITE_MSG);
476 /* second read registers */
477 dw210x_op_rw(d->udev, 0xc3, 0x19 , 0,
478 ibuf, msg[1].len + 2, DW210X_READ_MSG);
479 memcpy(msg[1].buf, ibuf + 2, msg[1].len);
484 switch (msg[0].addr) {
487 /* write to register */
488 u8 obuf[MAX_XFER_SIZE];
490 if (2 + msg[0].len > sizeof(obuf)) {
491 warn("i2c wr: len=%d is too big!\n",
496 obuf[0] = msg[0].addr << 1;
497 obuf[1] = msg[0].len;
498 memcpy(obuf + 2, msg[0].buf, msg[0].len);
499 dw210x_op_rw(d->udev, 0xc2, 0, 0,
500 obuf, msg[0].len + 2, DW210X_WRITE_MSG);
503 case(DW2102_RC_QUERY): {
505 dw210x_op_rw(d->udev, 0xb8, 0, 0,
506 ibuf, 2, DW210X_READ_MSG);
507 memcpy(msg[0].buf, ibuf , 2);
515 for (i = 0; i < num; i++) {
516 deb_xfer("%02x:%02x: %s ", i, msg[i].addr,
517 msg[i].flags == 0 ? ">>>" : "<<<");
518 debug_dump(msg[i].buf, msg[i].len, deb_xfer);
523 mutex_unlock(&d->i2c_mutex);
527 static int s6x0_i2c_transfer(struct i2c_adapter *adap, struct i2c_msg msg[],
530 struct dvb_usb_device *d = i2c_get_adapdata(adap);
531 struct usb_device *udev;
537 if (mutex_lock_interruptible(&d->i2c_mutex) < 0)
540 for (j = 0; j < num; j++) {
541 switch (msg[j].addr) {
542 case (DW2102_RC_QUERY): {
544 dw210x_op_rw(d->udev, 0xb8, 0, 0,
545 ibuf, 5, DW210X_READ_MSG);
546 memcpy(msg[j].buf, ibuf + 3, 2);
549 case (DW2102_VOLTAGE_CTRL): {
553 obuf[1] = msg[j].buf[1];/* off-on */
554 dw210x_op_rw(d->udev, 0x8a, 0, 0,
555 obuf, 2, DW210X_WRITE_MSG);
557 obuf[1] = msg[j].buf[0];/* 13v-18v */
558 dw210x_op_rw(d->udev, 0x8a, 0, 0,
559 obuf, 2, DW210X_WRITE_MSG);
562 case (DW2102_LED_CTRL): {
566 obuf[1] = msg[j].buf[0];
567 dw210x_op_rw(d->udev, 0x8a, 0, 0,
568 obuf, 2, DW210X_WRITE_MSG);
573 case 0x68: ds3000, stv0903, rs2000
574 case 0x60: ts2020, stv6110, stb6100
577 if (msg[j].flags == I2C_M_RD) {
579 u8 ibuf[MAX_XFER_SIZE];
581 if (msg[j].len > sizeof(ibuf)) {
582 warn("i2c rd: len=%d is too big!\n",
588 dw210x_op_rw(d->udev, 0x91, 0, 0,
591 memcpy(msg[j].buf, ibuf, msg[j].len);
593 } else if ((msg[j].buf[0] == 0xb0) &&
594 (msg[j].addr == 0x68)) {
597 obuf[0] = (msg[j].len > 16 ?
598 18 : msg[j].len + 1);
599 obuf[1] = msg[j].addr << 1;
600 obuf[2] = msg[j].buf[0];
601 len = msg[j].len - 1;
604 memcpy(obuf + 3, msg[j].buf + i,
605 (len > 16 ? 16 : len));
606 dw210x_op_rw(d->udev, 0x80, 0, 0,
607 obuf, (len > 16 ? 16 : len) + 3,
612 } else if (j < (num - 1)) {
613 /* write register addr before read */
614 u8 obuf[MAX_XFER_SIZE];
616 if (2 + msg[j].len > sizeof(obuf)) {
617 warn("i2c wr: len=%d is too big!\n",
623 obuf[0] = msg[j + 1].len;
624 obuf[1] = (msg[j].addr << 1);
625 memcpy(obuf + 2, msg[j].buf, msg[j].len);
626 dw210x_op_rw(d->udev,
627 le16_to_cpu(udev->descriptor.idProduct) ==
628 0x7500 ? 0x92 : 0x90, 0, 0,
629 obuf, msg[j].len + 2,
633 /* write registers */
634 u8 obuf[MAX_XFER_SIZE];
636 if (2 + msg[j].len > sizeof(obuf)) {
637 warn("i2c wr: len=%d is too big!\n",
642 obuf[0] = msg[j].len + 1;
643 obuf[1] = (msg[j].addr << 1);
644 memcpy(obuf + 2, msg[j].buf, msg[j].len);
645 dw210x_op_rw(d->udev, 0x80, 0, 0,
646 obuf, msg[j].len + 2,
657 mutex_unlock(&d->i2c_mutex);
661 static int su3000_i2c_transfer(struct i2c_adapter *adap, struct i2c_msg msg[],
664 struct dvb_usb_device *d = i2c_get_adapdata(adap);
665 u8 obuf[0x40], ibuf[0x40];
669 if (mutex_lock_interruptible(&d->i2c_mutex) < 0)
674 switch (msg[0].addr) {
675 case SU3000_STREAM_CTRL:
676 obuf[0] = msg[0].buf[0] + 0x36;
679 if (dvb_usb_generic_rw(d, obuf, 3, ibuf, 0, 0) < 0)
680 err("i2c transfer failed.");
682 case DW2102_RC_QUERY:
684 if (dvb_usb_generic_rw(d, obuf, 1, ibuf, 2, 0) < 0)
685 err("i2c transfer failed.");
686 msg[0].buf[1] = ibuf[0];
687 msg[0].buf[0] = ibuf[1];
690 /* always i2c write*/
692 obuf[1] = msg[0].addr;
693 obuf[2] = msg[0].len;
695 memcpy(&obuf[3], msg[0].buf, msg[0].len);
697 if (dvb_usb_generic_rw(d, obuf, msg[0].len + 3,
699 err("i2c transfer failed.");
704 /* always i2c read */
706 obuf[1] = msg[0].len;
707 obuf[2] = msg[1].len;
708 obuf[3] = msg[0].addr;
709 memcpy(&obuf[4], msg[0].buf, msg[0].len);
711 if (dvb_usb_generic_rw(d, obuf, msg[0].len + 4,
712 ibuf, msg[1].len + 1, 0) < 0)
713 err("i2c transfer failed.");
715 memcpy(msg[1].buf, &ibuf[1], msg[1].len);
718 warn("more than 2 i2c messages at a time is not handled yet.");
721 mutex_unlock(&d->i2c_mutex);
725 static u32 dw210x_i2c_func(struct i2c_adapter *adapter)
730 static struct i2c_algorithm dw2102_i2c_algo = {
731 .master_xfer = dw2102_i2c_transfer,
732 .functionality = dw210x_i2c_func,
735 static struct i2c_algorithm dw2102_serit_i2c_algo = {
736 .master_xfer = dw2102_serit_i2c_transfer,
737 .functionality = dw210x_i2c_func,
740 static struct i2c_algorithm dw2102_earda_i2c_algo = {
741 .master_xfer = dw2102_earda_i2c_transfer,
742 .functionality = dw210x_i2c_func,
745 static struct i2c_algorithm dw2104_i2c_algo = {
746 .master_xfer = dw2104_i2c_transfer,
747 .functionality = dw210x_i2c_func,
750 static struct i2c_algorithm dw3101_i2c_algo = {
751 .master_xfer = dw3101_i2c_transfer,
752 .functionality = dw210x_i2c_func,
755 static struct i2c_algorithm s6x0_i2c_algo = {
756 .master_xfer = s6x0_i2c_transfer,
757 .functionality = dw210x_i2c_func,
760 static struct i2c_algorithm su3000_i2c_algo = {
761 .master_xfer = su3000_i2c_transfer,
762 .functionality = dw210x_i2c_func,
765 static int dw210x_read_mac_address(struct dvb_usb_device *d, u8 mac[6])
769 u8 eeprom[256], eepromline[16];
771 for (i = 0; i < 256; i++) {
772 if (dw210x_op_rw(d->udev, 0xb6, 0xa0 , i, ibuf, 2, DW210X_READ_MSG) < 0) {
773 err("read eeprom failed.");
776 eepromline[i%16] = ibuf[0];
779 if ((i % 16) == 15) {
780 deb_xfer("%02x: ", i - 15);
781 debug_dump(eepromline, 16, deb_xfer);
785 memcpy(mac, eeprom + 8, 6);
789 static int s6x0_read_mac_address(struct dvb_usb_device *d, u8 mac[6])
792 u8 ibuf[] = { 0 }, obuf[] = { 0 };
793 u8 eeprom[256], eepromline[16];
794 struct i2c_msg msg[] = {
808 for (i = 0; i < 256; i++) {
810 ret = s6x0_i2c_transfer(&d->i2c_adap, msg, 2);
812 err("read eeprom failed.");
815 eepromline[i % 16] = ibuf[0];
819 if ((i % 16) == 15) {
820 deb_xfer("%02x: ", i - 15);
821 debug_dump(eepromline, 16, deb_xfer);
825 memcpy(mac, eeprom + 16, 6);
829 static int su3000_streaming_ctrl(struct dvb_usb_adapter *adap, int onoff)
831 static u8 command_start[] = {0x00};
832 static u8 command_stop[] = {0x01};
833 struct i2c_msg msg = {
834 .addr = SU3000_STREAM_CTRL,
836 .buf = onoff ? command_start : command_stop,
840 i2c_transfer(&adap->dev->i2c_adap, &msg, 1);
845 static int su3000_power_ctrl(struct dvb_usb_device *d, int i)
847 struct dw2102_state *state = (struct dw2102_state *)d->priv;
848 u8 obuf[] = {0xde, 0};
850 info("%s: %d, initialized %d\n", __func__, i, state->initialized);
852 if (i && !state->initialized) {
853 state->initialized = 1;
855 dvb_usb_generic_rw(d, obuf, 2, NULL, 0, 0);
861 static int su3000_read_mac_address(struct dvb_usb_device *d, u8 mac[6])
864 u8 obuf[] = { 0x1f, 0xf0 };
866 struct i2c_msg msg[] = {
881 for (i = 0; i < 6; i++) {
883 if (i2c_transfer(&d->i2c_adap, msg, 2) != 2)
892 static int su3000_identify_state(struct usb_device *udev,
893 struct dvb_usb_device_properties *props,
894 struct dvb_usb_device_description **desc,
897 info("%s\n", __func__);
903 static int dw210x_set_voltage(struct dvb_frontend *fe,
904 enum fe_sec_voltage voltage)
906 static u8 command_13v[] = {0x00, 0x01};
907 static u8 command_18v[] = {0x01, 0x01};
908 static u8 command_off[] = {0x00, 0x00};
909 struct i2c_msg msg = {
910 .addr = DW2102_VOLTAGE_CTRL,
916 struct dvb_usb_adapter *udev_adap =
917 (struct dvb_usb_adapter *)(fe->dvb->priv);
918 if (voltage == SEC_VOLTAGE_18)
919 msg.buf = command_18v;
920 else if (voltage == SEC_VOLTAGE_13)
921 msg.buf = command_13v;
923 i2c_transfer(&udev_adap->dev->i2c_adap, &msg, 1);
928 static int s660_set_voltage(struct dvb_frontend *fe,
929 enum fe_sec_voltage voltage)
931 struct dvb_usb_adapter *d =
932 (struct dvb_usb_adapter *)(fe->dvb->priv);
933 struct dw2102_state *st = (struct dw2102_state *)d->dev->priv;
935 dw210x_set_voltage(fe, voltage);
936 if (st->old_set_voltage)
937 st->old_set_voltage(fe, voltage);
942 static void dw210x_led_ctrl(struct dvb_frontend *fe, int offon)
944 static u8 led_off[] = { 0 };
945 static u8 led_on[] = { 1 };
946 struct i2c_msg msg = {
947 .addr = DW2102_LED_CTRL,
952 struct dvb_usb_adapter *udev_adap =
953 (struct dvb_usb_adapter *)(fe->dvb->priv);
957 i2c_transfer(&udev_adap->dev->i2c_adap, &msg, 1);
960 static int tt_s2_4600_read_status(struct dvb_frontend *fe,
961 enum fe_status *status)
963 struct dvb_usb_adapter *d =
964 (struct dvb_usb_adapter *)(fe->dvb->priv);
965 struct dw2102_state *st = (struct dw2102_state *)d->dev->priv;
968 ret = st->fe_read_status(fe, status);
970 /* resync slave fifo when signal change from unlock to lock */
971 if ((*status & FE_HAS_LOCK) && (!st->last_lock))
972 su3000_streaming_ctrl(d, 1);
974 st->last_lock = (*status & FE_HAS_LOCK) ? 1 : 0;
978 static struct stv0299_config sharp_z0194a_config = {
979 .demod_address = 0x68,
980 .inittab = sharp_z0194a_inittab,
984 .lock_output = STV0299_LOCKOUTPUT_1,
985 .volt13_op0_op1 = STV0299_VOLT13_OP1,
987 .set_symbol_rate = sharp_z0194a_set_symbol_rate,
990 static struct cx24116_config dw2104_config = {
991 .demod_address = 0x55,
992 .mpg_clk_pos_pol = 0x01,
995 static struct si21xx_config serit_sp1511lhb_config = {
996 .demod_address = 0x68,
1001 static struct tda10023_config dw3101_tda10023_config = {
1002 .demod_address = 0x0c,
1006 static struct mt312_config zl313_config = {
1007 .demod_address = 0x0e,
1010 static struct ds3000_config dw2104_ds3000_config = {
1011 .demod_address = 0x68,
1014 static struct ts2020_config dw2104_ts2020_config = {
1015 .tuner_address = 0x60,
1017 .frequency_div = 1060000,
1020 static struct ds3000_config s660_ds3000_config = {
1021 .demod_address = 0x68,
1023 .set_lock_led = dw210x_led_ctrl,
1026 static struct ts2020_config s660_ts2020_config = {
1027 .tuner_address = 0x60,
1029 .frequency_div = 1146000,
1032 static struct stv0900_config dw2104a_stv0900_config = {
1033 .demod_address = 0x6a,
1036 .clkmode = 3,/* 0-CLKI, 2-XTALI, else AUTO */
1037 .diseqc_mode = 2,/* 2/3 PWM */
1038 .tun1_maddress = 0,/* 0x60 */
1039 .tun1_adc = 0,/* 2 Vpp */
1043 static struct stb6100_config dw2104a_stb6100_config = {
1044 .tuner_address = 0x60,
1045 .refclock = 27000000,
1048 static struct stv0900_config dw2104_stv0900_config = {
1049 .demod_address = 0x68,
1055 .tun1_adc = 1,/* 1 Vpp */
1059 static struct stv6110_config dw2104_stv6110_config = {
1060 .i2c_address = 0x60,
1065 static struct stv0900_config prof_7500_stv0900_config = {
1066 .demod_address = 0x6a,
1069 .clkmode = 3,/* 0-CLKI, 2-XTALI, else AUTO */
1070 .diseqc_mode = 2,/* 2/3 PWM */
1071 .tun1_maddress = 0,/* 0x60 */
1072 .tun1_adc = 0,/* 2 Vpp */
1075 .set_lock_led = dw210x_led_ctrl,
1078 static struct ds3000_config su3000_ds3000_config = {
1079 .demod_address = 0x68,
1081 .set_lock_led = dw210x_led_ctrl,
1084 static struct cxd2820r_config cxd2820r_config = {
1085 .i2c_address = 0x6c, /* (0xd8 >> 1) */
1090 static struct tda18271_config tda18271_config = {
1091 .output_opt = TDA18271_OUTPUT_LT_OFF,
1092 .gate = TDA18271_GATE_DIGITAL,
1095 static u8 m88rs2000_inittab[] = {
1096 DEMOD_WRITE, 0x9a, 0x30,
1097 DEMOD_WRITE, 0x00, 0x01,
1098 WRITE_DELAY, 0x19, 0x00,
1099 DEMOD_WRITE, 0x00, 0x00,
1100 DEMOD_WRITE, 0x9a, 0xb0,
1101 DEMOD_WRITE, 0x81, 0xc1,
1102 DEMOD_WRITE, 0x81, 0x81,
1103 DEMOD_WRITE, 0x86, 0xc6,
1104 DEMOD_WRITE, 0x9a, 0x30,
1105 DEMOD_WRITE, 0xf0, 0x80,
1106 DEMOD_WRITE, 0xf1, 0xbf,
1107 DEMOD_WRITE, 0xb0, 0x45,
1108 DEMOD_WRITE, 0xb2, 0x01,
1109 DEMOD_WRITE, 0x9a, 0xb0,
1113 static struct m88rs2000_config s421_m88rs2000_config = {
1115 .inittab = m88rs2000_inittab,
1118 static int dw2104_frontend_attach(struct dvb_usb_adapter *d)
1120 struct dvb_tuner_ops *tuner_ops = NULL;
1122 if (demod_probe & 4) {
1123 d->fe_adap[0].fe = dvb_attach(stv0900_attach, &dw2104a_stv0900_config,
1124 &d->dev->i2c_adap, 0);
1125 if (d->fe_adap[0].fe != NULL) {
1126 if (dvb_attach(stb6100_attach, d->fe_adap[0].fe,
1127 &dw2104a_stb6100_config,
1128 &d->dev->i2c_adap)) {
1129 tuner_ops = &d->fe_adap[0].fe->ops.tuner_ops;
1130 tuner_ops->set_frequency = stb6100_set_freq;
1131 tuner_ops->get_frequency = stb6100_get_freq;
1132 tuner_ops->set_bandwidth = stb6100_set_bandw;
1133 tuner_ops->get_bandwidth = stb6100_get_bandw;
1134 d->fe_adap[0].fe->ops.set_voltage = dw210x_set_voltage;
1135 info("Attached STV0900+STB6100!\n");
1141 if (demod_probe & 2) {
1142 d->fe_adap[0].fe = dvb_attach(stv0900_attach, &dw2104_stv0900_config,
1143 &d->dev->i2c_adap, 0);
1144 if (d->fe_adap[0].fe != NULL) {
1145 if (dvb_attach(stv6110_attach, d->fe_adap[0].fe,
1146 &dw2104_stv6110_config,
1147 &d->dev->i2c_adap)) {
1148 d->fe_adap[0].fe->ops.set_voltage = dw210x_set_voltage;
1149 info("Attached STV0900+STV6110A!\n");
1155 if (demod_probe & 1) {
1156 d->fe_adap[0].fe = dvb_attach(cx24116_attach, &dw2104_config,
1158 if (d->fe_adap[0].fe != NULL) {
1159 d->fe_adap[0].fe->ops.set_voltage = dw210x_set_voltage;
1160 info("Attached cx24116!\n");
1165 d->fe_adap[0].fe = dvb_attach(ds3000_attach, &dw2104_ds3000_config,
1167 if (d->fe_adap[0].fe != NULL) {
1168 dvb_attach(ts2020_attach, d->fe_adap[0].fe,
1169 &dw2104_ts2020_config, &d->dev->i2c_adap);
1170 d->fe_adap[0].fe->ops.set_voltage = dw210x_set_voltage;
1171 info("Attached DS3000!\n");
1178 static struct dvb_usb_device_properties dw2102_properties;
1179 static struct dvb_usb_device_properties dw2104_properties;
1180 static struct dvb_usb_device_properties s6x0_properties;
1182 static int dw2102_frontend_attach(struct dvb_usb_adapter *d)
1184 if (dw2102_properties.i2c_algo == &dw2102_serit_i2c_algo) {
1185 /*dw2102_properties.adapter->tuner_attach = NULL;*/
1186 d->fe_adap[0].fe = dvb_attach(si21xx_attach, &serit_sp1511lhb_config,
1188 if (d->fe_adap[0].fe != NULL) {
1189 d->fe_adap[0].fe->ops.set_voltage = dw210x_set_voltage;
1190 info("Attached si21xx!\n");
1195 if (dw2102_properties.i2c_algo == &dw2102_earda_i2c_algo) {
1196 d->fe_adap[0].fe = dvb_attach(stv0288_attach, &earda_config,
1198 if (d->fe_adap[0].fe != NULL) {
1199 if (dvb_attach(stb6000_attach, d->fe_adap[0].fe, 0x61,
1200 &d->dev->i2c_adap)) {
1201 d->fe_adap[0].fe->ops.set_voltage = dw210x_set_voltage;
1202 info("Attached stv0288!\n");
1208 if (dw2102_properties.i2c_algo == &dw2102_i2c_algo) {
1209 /*dw2102_properties.adapter->tuner_attach = dw2102_tuner_attach;*/
1210 d->fe_adap[0].fe = dvb_attach(stv0299_attach, &sharp_z0194a_config,
1212 if (d->fe_adap[0].fe != NULL) {
1213 d->fe_adap[0].fe->ops.set_voltage = dw210x_set_voltage;
1214 info("Attached stv0299!\n");
1221 static int dw3101_frontend_attach(struct dvb_usb_adapter *d)
1223 d->fe_adap[0].fe = dvb_attach(tda10023_attach, &dw3101_tda10023_config,
1224 &d->dev->i2c_adap, 0x48);
1225 if (d->fe_adap[0].fe != NULL) {
1226 info("Attached tda10023!\n");
1232 static int zl100313_frontend_attach(struct dvb_usb_adapter *d)
1234 d->fe_adap[0].fe = dvb_attach(mt312_attach, &zl313_config,
1236 if (d->fe_adap[0].fe != NULL) {
1237 if (dvb_attach(zl10039_attach, d->fe_adap[0].fe, 0x60,
1238 &d->dev->i2c_adap)) {
1239 d->fe_adap[0].fe->ops.set_voltage = dw210x_set_voltage;
1240 info("Attached zl100313+zl10039!\n");
1248 static int stv0288_frontend_attach(struct dvb_usb_adapter *d)
1252 d->fe_adap[0].fe = dvb_attach(stv0288_attach, &earda_config,
1255 if (d->fe_adap[0].fe == NULL)
1258 if (NULL == dvb_attach(stb6000_attach, d->fe_adap[0].fe, 0x61, &d->dev->i2c_adap))
1261 d->fe_adap[0].fe->ops.set_voltage = dw210x_set_voltage;
1263 dw210x_op_rw(d->dev->udev, 0x8a, 0, 0, obuf, 2, DW210X_WRITE_MSG);
1265 info("Attached stv0288+stb6000!\n");
1271 static int ds3000_frontend_attach(struct dvb_usb_adapter *d)
1273 struct dw2102_state *st = d->dev->priv;
1276 d->fe_adap[0].fe = dvb_attach(ds3000_attach, &s660_ds3000_config,
1279 if (d->fe_adap[0].fe == NULL)
1282 dvb_attach(ts2020_attach, d->fe_adap[0].fe, &s660_ts2020_config,
1285 st->old_set_voltage = d->fe_adap[0].fe->ops.set_voltage;
1286 d->fe_adap[0].fe->ops.set_voltage = s660_set_voltage;
1288 dw210x_op_rw(d->dev->udev, 0x8a, 0, 0, obuf, 2, DW210X_WRITE_MSG);
1290 info("Attached ds3000+ts2020!\n");
1295 static int prof_7500_frontend_attach(struct dvb_usb_adapter *d)
1299 d->fe_adap[0].fe = dvb_attach(stv0900_attach, &prof_7500_stv0900_config,
1300 &d->dev->i2c_adap, 0);
1301 if (d->fe_adap[0].fe == NULL)
1304 d->fe_adap[0].fe->ops.set_voltage = dw210x_set_voltage;
1306 dw210x_op_rw(d->dev->udev, 0x8a, 0, 0, obuf, 2, DW210X_WRITE_MSG);
1308 info("Attached STV0900+STB6100A!\n");
1313 static int su3000_frontend_attach(struct dvb_usb_adapter *d)
1315 u8 obuf[3] = { 0xe, 0x80, 0 };
1318 if (dvb_usb_generic_rw(d->dev, obuf, 3, ibuf, 1, 0) < 0)
1319 err("command 0x0e transfer failed.");
1325 if (dvb_usb_generic_rw(d->dev, obuf, 3, ibuf, 1, 0) < 0)
1326 err("command 0x0e transfer failed.");
1333 if (dvb_usb_generic_rw(d->dev, obuf, 3, ibuf, 1, 0) < 0)
1334 err("command 0x0e transfer failed.");
1340 if (dvb_usb_generic_rw(d->dev, obuf, 3, ibuf, 1, 0) < 0)
1341 err("command 0x0e transfer failed.");
1345 if (dvb_usb_generic_rw(d->dev, obuf, 1, ibuf, 1, 0) < 0)
1346 err("command 0x51 transfer failed.");
1348 d->fe_adap[0].fe = dvb_attach(ds3000_attach, &su3000_ds3000_config,
1350 if (d->fe_adap[0].fe == NULL)
1353 if (dvb_attach(ts2020_attach, d->fe_adap[0].fe,
1354 &dw2104_ts2020_config,
1355 &d->dev->i2c_adap)) {
1356 info("Attached DS3000/TS2020!\n");
1360 info("Failed to attach DS3000/TS2020!\n");
1364 static int t220_frontend_attach(struct dvb_usb_adapter *d)
1366 u8 obuf[3] = { 0xe, 0x87, 0 };
1369 if (dvb_usb_generic_rw(d->dev, obuf, 3, ibuf, 1, 0) < 0)
1370 err("command 0x0e transfer failed.");
1376 if (dvb_usb_generic_rw(d->dev, obuf, 3, ibuf, 1, 0) < 0)
1377 err("command 0x0e transfer failed.");
1383 if (dvb_usb_generic_rw(d->dev, obuf, 3, ibuf, 1, 0) < 0)
1384 err("command 0x0e transfer failed.");
1392 if (dvb_usb_generic_rw(d->dev, obuf, 3, ibuf, 1, 0) < 0)
1393 err("command 0x0e transfer failed.");
1397 if (dvb_usb_generic_rw(d->dev, obuf, 1, ibuf, 1, 0) < 0)
1398 err("command 0x51 transfer failed.");
1400 d->fe_adap[0].fe = dvb_attach(cxd2820r_attach, &cxd2820r_config,
1401 &d->dev->i2c_adap, NULL);
1402 if (d->fe_adap[0].fe != NULL) {
1403 if (dvb_attach(tda18271_attach, d->fe_adap[0].fe, 0x60,
1404 &d->dev->i2c_adap, &tda18271_config)) {
1405 info("Attached TDA18271HD/CXD2820R!\n");
1410 info("Failed to attach TDA18271HD/CXD2820R!\n");
1414 static int m88rs2000_frontend_attach(struct dvb_usb_adapter *d)
1416 u8 obuf[] = { 0x51 };
1419 if (dvb_usb_generic_rw(d->dev, obuf, 1, ibuf, 1, 0) < 0)
1420 err("command 0x51 transfer failed.");
1422 d->fe_adap[0].fe = dvb_attach(m88rs2000_attach, &s421_m88rs2000_config,
1425 if (d->fe_adap[0].fe == NULL)
1428 if (dvb_attach(ts2020_attach, d->fe_adap[0].fe,
1429 &dw2104_ts2020_config,
1430 &d->dev->i2c_adap)) {
1431 info("Attached RS2000/TS2020!\n");
1435 info("Failed to attach RS2000/TS2020!\n");
1439 static int tt_s2_4600_frontend_attach(struct dvb_usb_adapter *adap)
1441 struct dvb_usb_device *d = adap->dev;
1442 struct dw2102_state *state = d->priv;
1443 u8 obuf[3] = { 0xe, 0x80, 0 };
1445 struct i2c_adapter *i2c_adapter;
1446 struct i2c_client *client;
1447 struct i2c_board_info board_info;
1448 struct m88ds3103_platform_data m88ds3103_pdata = {};
1449 struct ts2020_config ts2020_config = {};
1451 if (dvb_usb_generic_rw(d, obuf, 3, ibuf, 1, 0) < 0)
1452 err("command 0x0e transfer failed.");
1458 if (dvb_usb_generic_rw(d, obuf, 3, ibuf, 1, 0) < 0)
1459 err("command 0x0e transfer failed.");
1466 if (dvb_usb_generic_rw(d, obuf, 3, ibuf, 1, 0) < 0)
1467 err("command 0x0e transfer failed.");
1473 if (dvb_usb_generic_rw(d, obuf, 3, ibuf, 1, 0) < 0)
1474 err("command 0x0e transfer failed.");
1478 if (dvb_usb_generic_rw(d, obuf, 1, ibuf, 1, 0) < 0)
1479 err("command 0x51 transfer failed.");
1482 m88ds3103_pdata.clk = 27000000;
1483 m88ds3103_pdata.i2c_wr_max = 33;
1484 m88ds3103_pdata.ts_mode = M88DS3103_TS_CI;
1485 m88ds3103_pdata.ts_clk = 16000;
1486 m88ds3103_pdata.ts_clk_pol = 0;
1487 m88ds3103_pdata.spec_inv = 0;
1488 m88ds3103_pdata.agc = 0x99;
1489 m88ds3103_pdata.agc_inv = 0;
1490 m88ds3103_pdata.clk_out = M88DS3103_CLOCK_OUT_ENABLED;
1491 m88ds3103_pdata.envelope_mode = 0;
1492 m88ds3103_pdata.lnb_hv_pol = 1;
1493 m88ds3103_pdata.lnb_en_pol = 0;
1494 memset(&board_info, 0, sizeof(board_info));
1495 strlcpy(board_info.type, "m88ds3103", I2C_NAME_SIZE);
1496 board_info.addr = 0x68;
1497 board_info.platform_data = &m88ds3103_pdata;
1498 request_module("m88ds3103");
1499 client = i2c_new_device(&d->i2c_adap, &board_info);
1500 if (client == NULL || client->dev.driver == NULL)
1502 if (!try_module_get(client->dev.driver->owner)) {
1503 i2c_unregister_device(client);
1506 adap->fe_adap[0].fe = m88ds3103_pdata.get_dvb_frontend(client);
1507 i2c_adapter = m88ds3103_pdata.get_i2c_adapter(client);
1509 state->i2c_client_demod = client;
1512 ts2020_config.fe = adap->fe_adap[0].fe;
1513 memset(&board_info, 0, sizeof(board_info));
1514 strlcpy(board_info.type, "ts2022", I2C_NAME_SIZE);
1515 board_info.addr = 0x60;
1516 board_info.platform_data = &ts2020_config;
1517 request_module("ts2020");
1518 client = i2c_new_device(i2c_adapter, &board_info);
1520 if (client == NULL || client->dev.driver == NULL) {
1521 dvb_frontend_detach(adap->fe_adap[0].fe);
1525 if (!try_module_get(client->dev.driver->owner)) {
1526 i2c_unregister_device(client);
1527 dvb_frontend_detach(adap->fe_adap[0].fe);
1531 /* delegate signal strength measurement to tuner */
1532 adap->fe_adap[0].fe->ops.read_signal_strength =
1533 adap->fe_adap[0].fe->ops.tuner_ops.get_rf_strength;
1535 state->i2c_client_tuner = client;
1537 /* hook fe: need to resync the slave fifo when signal locks */
1538 state->fe_read_status = adap->fe_adap[0].fe->ops.read_status;
1539 adap->fe_adap[0].fe->ops.read_status = tt_s2_4600_read_status;
1541 state->last_lock = 0;
1546 static int dw2102_tuner_attach(struct dvb_usb_adapter *adap)
1548 dvb_attach(dvb_pll_attach, adap->fe_adap[0].fe, 0x60,
1549 &adap->dev->i2c_adap, DVB_PLL_OPERA1);
1553 static int dw3101_tuner_attach(struct dvb_usb_adapter *adap)
1555 dvb_attach(dvb_pll_attach, adap->fe_adap[0].fe, 0x60,
1556 &adap->dev->i2c_adap, DVB_PLL_TUA6034);
1561 static int dw2102_rc_query(struct dvb_usb_device *d)
1564 struct i2c_msg msg = {
1565 .addr = DW2102_RC_QUERY,
1571 if (d->props.i2c_algo->master_xfer(&d->i2c_adap, &msg, 1) == 1) {
1572 if (msg.buf[0] != 0xff) {
1573 deb_rc("%s: rc code: %x, %x\n",
1574 __func__, key[0], key[1]);
1575 rc_keydown(d->rc_dev, RC_TYPE_UNKNOWN, key[0], 0);
1582 static int prof_rc_query(struct dvb_usb_device *d)
1585 struct i2c_msg msg = {
1586 .addr = DW2102_RC_QUERY,
1592 if (d->props.i2c_algo->master_xfer(&d->i2c_adap, &msg, 1) == 1) {
1593 if (msg.buf[0] != 0xff) {
1594 deb_rc("%s: rc code: %x, %x\n",
1595 __func__, key[0], key[1]);
1596 rc_keydown(d->rc_dev, RC_TYPE_UNKNOWN, key[0]^0xff, 0);
1603 static int su3000_rc_query(struct dvb_usb_device *d)
1606 struct i2c_msg msg = {
1607 .addr = DW2102_RC_QUERY,
1613 if (d->props.i2c_algo->master_xfer(&d->i2c_adap, &msg, 1) == 1) {
1614 if (msg.buf[0] != 0xff) {
1615 deb_rc("%s: rc code: %x, %x\n",
1616 __func__, key[0], key[1]);
1617 rc_keydown(d->rc_dev, RC_TYPE_RC5,
1618 RC_SCANCODE_RC5(key[1], key[0]), 0);
1625 enum dw2102_table_entry {
1637 TERRATEC_CINERGY_S2,
1643 TERRATEC_CINERGY_S2_R2,
1646 TECHNOTREND_S2_4600,
1649 TERRATEC_CINERGY_S2_BOX,
1653 static struct usb_device_id dw2102_table[] = {
1654 [CYPRESS_DW2102] = {USB_DEVICE(USB_VID_CYPRESS, USB_PID_DW2102)},
1655 [CYPRESS_DW2101] = {USB_DEVICE(USB_VID_CYPRESS, 0x2101)},
1656 [CYPRESS_DW2104] = {USB_DEVICE(USB_VID_CYPRESS, USB_PID_DW2104)},
1657 [TEVII_S650] = {USB_DEVICE(0x9022, USB_PID_TEVII_S650)},
1658 [TERRATEC_CINERGY_S] = {USB_DEVICE(USB_VID_TERRATEC, USB_PID_TERRATEC_CINERGY_S)},
1659 [CYPRESS_DW3101] = {USB_DEVICE(USB_VID_CYPRESS, USB_PID_DW3101)},
1660 [TEVII_S630] = {USB_DEVICE(0x9022, USB_PID_TEVII_S630)},
1661 [PROF_1100] = {USB_DEVICE(0x3011, USB_PID_PROF_1100)},
1662 [TEVII_S660] = {USB_DEVICE(0x9022, USB_PID_TEVII_S660)},
1663 [PROF_7500] = {USB_DEVICE(0x3034, 0x7500)},
1664 [GENIATECH_SU3000] = {USB_DEVICE(0x1f4d, 0x3000)},
1665 [TERRATEC_CINERGY_S2] = {USB_DEVICE(USB_VID_TERRATEC, USB_PID_TERRATEC_CINERGY_S2_R1)},
1666 [TEVII_S480_1] = {USB_DEVICE(0x9022, USB_PID_TEVII_S480_1)},
1667 [TEVII_S480_2] = {USB_DEVICE(0x9022, USB_PID_TEVII_S480_2)},
1668 [X3M_SPC1400HD] = {USB_DEVICE(0x1f4d, 0x3100)},
1669 [TEVII_S421] = {USB_DEVICE(0x9022, USB_PID_TEVII_S421)},
1670 [TEVII_S632] = {USB_DEVICE(0x9022, USB_PID_TEVII_S632)},
1671 [TERRATEC_CINERGY_S2_R2] = {USB_DEVICE(USB_VID_TERRATEC, USB_PID_TERRATEC_CINERGY_S2_R2)},
1672 [GOTVIEW_SAT_HD] = {USB_DEVICE(0x1FE1, USB_PID_GOTVIEW_SAT_HD)},
1673 [GENIATECH_T220] = {USB_DEVICE(0x1f4d, 0xD220)},
1674 [TECHNOTREND_S2_4600] = {USB_DEVICE(USB_VID_TECHNOTREND,
1675 USB_PID_TECHNOTREND_CONNECT_S2_4600)},
1676 [TEVII_S482_1] = {USB_DEVICE(0x9022, 0xd483)},
1677 [TEVII_S482_2] = {USB_DEVICE(0x9022, 0xd484)},
1678 [TERRATEC_CINERGY_S2_BOX] = {USB_DEVICE(USB_VID_TERRATEC, 0x0105)},
1679 [TEVII_S662] = {USB_DEVICE(0x9022, USB_PID_TEVII_S662)},
1683 MODULE_DEVICE_TABLE(usb, dw2102_table);
1685 static int dw2102_load_firmware(struct usb_device *dev,
1686 const struct firmware *frmwr)
1691 u8 reset16[] = {0, 0, 0, 0, 0, 0, 0};
1692 const struct firmware *fw;
1694 switch (le16_to_cpu(dev->descriptor.idProduct)) {
1696 ret = request_firmware(&fw, DW2101_FIRMWARE, &dev->dev);
1698 err(err_str, DW2101_FIRMWARE);
1706 info("start downloading DW210X firmware");
1707 p = kmalloc(fw->size, GFP_KERNEL);
1710 dw210x_op_rw(dev, 0xa0, 0x7f92, 0, &reset, 1, DW210X_WRITE_MSG);
1711 dw210x_op_rw(dev, 0xa0, 0xe600, 0, &reset, 1, DW210X_WRITE_MSG);
1714 memcpy(p, fw->data, fw->size);
1715 for (i = 0; i < fw->size; i += 0x40) {
1717 if (dw210x_op_rw(dev, 0xa0, i, 0, b , 0x40,
1718 DW210X_WRITE_MSG) != 0x40) {
1719 err("error while transferring firmware");
1724 /* restart the CPU */
1726 if (ret || dw210x_op_rw(dev, 0xa0, 0x7f92, 0, &reset, 1,
1727 DW210X_WRITE_MSG) != 1) {
1728 err("could not restart the USB controller CPU.");
1731 if (ret || dw210x_op_rw(dev, 0xa0, 0xe600, 0, &reset, 1,
1732 DW210X_WRITE_MSG) != 1) {
1733 err("could not restart the USB controller CPU.");
1736 /* init registers */
1737 switch (le16_to_cpu(dev->descriptor.idProduct)) {
1738 case USB_PID_TEVII_S650:
1739 dw2104_properties.rc.core.rc_codes = RC_MAP_TEVII_NEC;
1740 case USB_PID_DW2104:
1742 dw210x_op_rw(dev, 0xc4, 0x0000, 0, &reset, 1,
1744 /* break omitted intentionally */
1745 case USB_PID_DW3101:
1747 dw210x_op_rw(dev, 0xbf, 0x0040, 0, &reset, 0,
1750 case USB_PID_TERRATEC_CINERGY_S:
1751 case USB_PID_DW2102:
1752 dw210x_op_rw(dev, 0xbf, 0x0040, 0, &reset, 0,
1754 dw210x_op_rw(dev, 0xb9, 0x0000, 0, &reset16[0], 2,
1756 /* check STV0299 frontend */
1757 dw210x_op_rw(dev, 0xb5, 0, 0, &reset16[0], 2,
1759 if ((reset16[0] == 0xa1) || (reset16[0] == 0x80)) {
1760 dw2102_properties.i2c_algo = &dw2102_i2c_algo;
1761 dw2102_properties.adapter->fe[0].tuner_attach = &dw2102_tuner_attach;
1764 /* check STV0288 frontend */
1768 dw210x_op_rw(dev, 0xc2, 0, 0, &reset16[0], 3,
1770 dw210x_op_rw(dev, 0xc3, 0xd1, 0, &reset16[0], 3,
1772 if (reset16[2] == 0x11) {
1773 dw2102_properties.i2c_algo = &dw2102_earda_i2c_algo;
1778 dw210x_op_rw(dev, 0xbc, 0x0030, 0, &reset16[0], 2,
1780 dw210x_op_rw(dev, 0xba, 0x0000, 0, &reset16[0], 7,
1782 dw210x_op_rw(dev, 0xba, 0x0000, 0, &reset16[0], 7,
1784 dw210x_op_rw(dev, 0xb9, 0x0000, 0, &reset16[0], 2,
1793 if (le16_to_cpu(dev->descriptor.idProduct) == 0x2101)
1794 release_firmware(fw);
1798 static struct dvb_usb_device_properties dw2102_properties = {
1799 .caps = DVB_USB_IS_AN_I2C_ADAPTER,
1800 .usb_ctrl = DEVICE_SPECIFIC,
1801 .firmware = DW2102_FIRMWARE,
1804 .i2c_algo = &dw2102_serit_i2c_algo,
1808 .rc_codes = RC_MAP_DM1105_NEC,
1809 .module_name = "dw2102",
1810 .allowed_protos = RC_BIT_NEC,
1811 .rc_query = dw2102_rc_query,
1814 .generic_bulk_ctrl_endpoint = 0x81,
1815 /* parameter for the MPEG2-data transfer */
1817 .download_firmware = dw2102_load_firmware,
1818 .read_mac_address = dw210x_read_mac_address,
1823 .frontend_attach = dw2102_frontend_attach,
1837 .num_device_descs = 3,
1839 {"DVBWorld DVB-S 2102 USB2.0",
1840 {&dw2102_table[CYPRESS_DW2102], NULL},
1843 {"DVBWorld DVB-S 2101 USB2.0",
1844 {&dw2102_table[CYPRESS_DW2101], NULL},
1847 {"TerraTec Cinergy S USB",
1848 {&dw2102_table[TERRATEC_CINERGY_S], NULL},
1854 static struct dvb_usb_device_properties dw2104_properties = {
1855 .caps = DVB_USB_IS_AN_I2C_ADAPTER,
1856 .usb_ctrl = DEVICE_SPECIFIC,
1857 .firmware = DW2104_FIRMWARE,
1860 .i2c_algo = &dw2104_i2c_algo,
1863 .rc_codes = RC_MAP_DM1105_NEC,
1864 .module_name = "dw2102",
1865 .allowed_protos = RC_BIT_NEC,
1866 .rc_query = dw2102_rc_query,
1869 .generic_bulk_ctrl_endpoint = 0x81,
1870 /* parameter for the MPEG2-data transfer */
1872 .download_firmware = dw2102_load_firmware,
1873 .read_mac_address = dw210x_read_mac_address,
1878 .frontend_attach = dw2104_frontend_attach,
1892 .num_device_descs = 2,
1894 { "DVBWorld DW2104 USB2.0",
1895 {&dw2102_table[CYPRESS_DW2104], NULL},
1898 { "TeVii S650 USB2.0",
1899 {&dw2102_table[TEVII_S650], NULL},
1905 static struct dvb_usb_device_properties dw3101_properties = {
1906 .caps = DVB_USB_IS_AN_I2C_ADAPTER,
1907 .usb_ctrl = DEVICE_SPECIFIC,
1908 .firmware = DW3101_FIRMWARE,
1911 .i2c_algo = &dw3101_i2c_algo,
1914 .rc_codes = RC_MAP_DM1105_NEC,
1915 .module_name = "dw2102",
1916 .allowed_protos = RC_BIT_NEC,
1917 .rc_query = dw2102_rc_query,
1920 .generic_bulk_ctrl_endpoint = 0x81,
1921 /* parameter for the MPEG2-data transfer */
1923 .download_firmware = dw2102_load_firmware,
1924 .read_mac_address = dw210x_read_mac_address,
1929 .frontend_attach = dw3101_frontend_attach,
1930 .tuner_attach = dw3101_tuner_attach,
1944 .num_device_descs = 1,
1946 { "DVBWorld DVB-C 3101 USB2.0",
1947 {&dw2102_table[CYPRESS_DW3101], NULL},
1953 static struct dvb_usb_device_properties s6x0_properties = {
1954 .caps = DVB_USB_IS_AN_I2C_ADAPTER,
1955 .usb_ctrl = DEVICE_SPECIFIC,
1956 .size_of_priv = sizeof(struct dw2102_state),
1957 .firmware = S630_FIRMWARE,
1960 .i2c_algo = &s6x0_i2c_algo,
1963 .rc_codes = RC_MAP_TEVII_NEC,
1964 .module_name = "dw2102",
1965 .allowed_protos = RC_BIT_NEC,
1966 .rc_query = dw2102_rc_query,
1969 .generic_bulk_ctrl_endpoint = 0x81,
1971 .download_firmware = dw2102_load_firmware,
1972 .read_mac_address = s6x0_read_mac_address,
1977 .frontend_attach = zl100313_frontend_attach,
1991 .num_device_descs = 1,
1994 {&dw2102_table[TEVII_S630], NULL},
2000 static struct dvb_usb_device_properties *p1100;
2001 static struct dvb_usb_device_description d1100 = {
2003 {&dw2102_table[PROF_1100], NULL},
2007 static struct dvb_usb_device_properties *s660;
2008 static struct dvb_usb_device_description d660 = {
2010 {&dw2102_table[TEVII_S660], NULL},
2014 static struct dvb_usb_device_description d480_1 = {
2016 {&dw2102_table[TEVII_S480_1], NULL},
2020 static struct dvb_usb_device_description d480_2 = {
2022 {&dw2102_table[TEVII_S480_2], NULL},
2026 static struct dvb_usb_device_properties *p7500;
2027 static struct dvb_usb_device_description d7500 = {
2028 "Prof 7500 USB DVB-S2",
2029 {&dw2102_table[PROF_7500], NULL},
2033 static struct dvb_usb_device_properties *s421;
2034 static struct dvb_usb_device_description d421 = {
2036 {&dw2102_table[TEVII_S421], NULL},
2040 static struct dvb_usb_device_description d632 = {
2042 {&dw2102_table[TEVII_S632], NULL},
2046 static struct dvb_usb_device_properties su3000_properties = {
2047 .caps = DVB_USB_IS_AN_I2C_ADAPTER,
2048 .usb_ctrl = DEVICE_SPECIFIC,
2049 .size_of_priv = sizeof(struct dw2102_state),
2050 .power_ctrl = su3000_power_ctrl,
2052 .identify_state = su3000_identify_state,
2053 .i2c_algo = &su3000_i2c_algo,
2057 .rc_codes = RC_MAP_SU3000,
2058 .module_name = "dw2102",
2059 .allowed_protos = RC_BIT_RC5,
2060 .rc_query = su3000_rc_query,
2063 .read_mac_address = su3000_read_mac_address,
2065 .generic_bulk_ctrl_endpoint = 0x01,
2071 .streaming_ctrl = su3000_streaming_ctrl,
2072 .frontend_attach = su3000_frontend_attach,
2086 .num_device_descs = 5,
2088 { "SU3000HD DVB-S USB2.0",
2089 { &dw2102_table[GENIATECH_SU3000], NULL },
2092 { "Terratec Cinergy S2 USB HD",
2093 { &dw2102_table[TERRATEC_CINERGY_S2], NULL },
2096 { "X3M TV SPC1400HD PCI",
2097 { &dw2102_table[X3M_SPC1400HD], NULL },
2100 { "Terratec Cinergy S2 USB HD Rev.2",
2101 { &dw2102_table[TERRATEC_CINERGY_S2_R2], NULL },
2104 { "GOTVIEW Satellite HD",
2105 { &dw2102_table[GOTVIEW_SAT_HD], NULL },
2111 static struct dvb_usb_device_properties t220_properties = {
2112 .caps = DVB_USB_IS_AN_I2C_ADAPTER,
2113 .usb_ctrl = DEVICE_SPECIFIC,
2114 .size_of_priv = sizeof(struct dw2102_state),
2115 .power_ctrl = su3000_power_ctrl,
2117 .identify_state = su3000_identify_state,
2118 .i2c_algo = &su3000_i2c_algo,
2122 .rc_codes = RC_MAP_SU3000,
2123 .module_name = "dw2102",
2124 .allowed_protos = RC_BIT_RC5,
2125 .rc_query = su3000_rc_query,
2128 .read_mac_address = su3000_read_mac_address,
2130 .generic_bulk_ctrl_endpoint = 0x01,
2136 .streaming_ctrl = su3000_streaming_ctrl,
2137 .frontend_attach = t220_frontend_attach,
2151 .num_device_descs = 1,
2153 { "Geniatech T220 DVB-T/T2 USB2.0",
2154 { &dw2102_table[GENIATECH_T220], NULL },
2160 static struct dvb_usb_device_properties tt_s2_4600_properties = {
2161 .caps = DVB_USB_IS_AN_I2C_ADAPTER,
2162 .usb_ctrl = DEVICE_SPECIFIC,
2163 .size_of_priv = sizeof(struct dw2102_state),
2164 .power_ctrl = su3000_power_ctrl,
2166 .identify_state = su3000_identify_state,
2167 .i2c_algo = &su3000_i2c_algo,
2171 .rc_codes = RC_MAP_TT_1500,
2172 .module_name = "dw2102",
2173 .allowed_protos = RC_BIT_RC5,
2174 .rc_query = su3000_rc_query,
2177 .read_mac_address = su3000_read_mac_address,
2179 .generic_bulk_ctrl_endpoint = 0x01,
2185 .streaming_ctrl = su3000_streaming_ctrl,
2186 .frontend_attach = tt_s2_4600_frontend_attach,
2200 .num_device_descs = 5,
2202 { "TechnoTrend TT-connect S2-4600",
2203 { &dw2102_table[TECHNOTREND_S2_4600], NULL },
2206 { "TeVii S482 (tuner 1)",
2207 { &dw2102_table[TEVII_S482_1], NULL },
2210 { "TeVii S482 (tuner 2)",
2211 { &dw2102_table[TEVII_S482_2], NULL },
2214 { "Terratec Cinergy S2 USB BOX",
2215 { &dw2102_table[TERRATEC_CINERGY_S2_BOX], NULL },
2219 { &dw2102_table[TEVII_S662], NULL },
2225 static int dw2102_probe(struct usb_interface *intf,
2226 const struct usb_device_id *id)
2228 p1100 = kmemdup(&s6x0_properties,
2229 sizeof(struct dvb_usb_device_properties), GFP_KERNEL);
2232 /* copy default structure */
2233 /* fill only different fields */
2234 p1100->firmware = P1100_FIRMWARE;
2235 p1100->devices[0] = d1100;
2236 p1100->rc.core.rc_query = prof_rc_query;
2237 p1100->rc.core.rc_codes = RC_MAP_TBS_NEC;
2238 p1100->adapter->fe[0].frontend_attach = stv0288_frontend_attach;
2240 s660 = kmemdup(&s6x0_properties,
2241 sizeof(struct dvb_usb_device_properties), GFP_KERNEL);
2246 s660->firmware = S660_FIRMWARE;
2247 s660->num_device_descs = 3;
2248 s660->devices[0] = d660;
2249 s660->devices[1] = d480_1;
2250 s660->devices[2] = d480_2;
2251 s660->adapter->fe[0].frontend_attach = ds3000_frontend_attach;
2253 p7500 = kmemdup(&s6x0_properties,
2254 sizeof(struct dvb_usb_device_properties), GFP_KERNEL);
2260 p7500->firmware = P7500_FIRMWARE;
2261 p7500->devices[0] = d7500;
2262 p7500->rc.core.rc_query = prof_rc_query;
2263 p7500->rc.core.rc_codes = RC_MAP_TBS_NEC;
2264 p7500->adapter->fe[0].frontend_attach = prof_7500_frontend_attach;
2267 s421 = kmemdup(&su3000_properties,
2268 sizeof(struct dvb_usb_device_properties), GFP_KERNEL);
2275 s421->num_device_descs = 2;
2276 s421->devices[0] = d421;
2277 s421->devices[1] = d632;
2278 s421->adapter->fe[0].frontend_attach = m88rs2000_frontend_attach;
2280 if (0 == dvb_usb_device_init(intf, &dw2102_properties,
2281 THIS_MODULE, NULL, adapter_nr) ||
2282 0 == dvb_usb_device_init(intf, &dw2104_properties,
2283 THIS_MODULE, NULL, adapter_nr) ||
2284 0 == dvb_usb_device_init(intf, &dw3101_properties,
2285 THIS_MODULE, NULL, adapter_nr) ||
2286 0 == dvb_usb_device_init(intf, &s6x0_properties,
2287 THIS_MODULE, NULL, adapter_nr) ||
2288 0 == dvb_usb_device_init(intf, p1100,
2289 THIS_MODULE, NULL, adapter_nr) ||
2290 0 == dvb_usb_device_init(intf, s660,
2291 THIS_MODULE, NULL, adapter_nr) ||
2292 0 == dvb_usb_device_init(intf, p7500,
2293 THIS_MODULE, NULL, adapter_nr) ||
2294 0 == dvb_usb_device_init(intf, s421,
2295 THIS_MODULE, NULL, adapter_nr) ||
2296 0 == dvb_usb_device_init(intf, &su3000_properties,
2297 THIS_MODULE, NULL, adapter_nr) ||
2298 0 == dvb_usb_device_init(intf, &t220_properties,
2299 THIS_MODULE, NULL, adapter_nr) ||
2300 0 == dvb_usb_device_init(intf, &tt_s2_4600_properties,
2301 THIS_MODULE, NULL, adapter_nr))
2307 static void dw2102_disconnect(struct usb_interface *intf)
2309 struct dvb_usb_device *d = usb_get_intfdata(intf);
2310 struct dw2102_state *st = (struct dw2102_state *)d->priv;
2311 struct i2c_client *client;
2313 /* remove I2C client for tuner */
2314 client = st->i2c_client_tuner;
2316 module_put(client->dev.driver->owner);
2317 i2c_unregister_device(client);
2320 /* remove I2C client for demodulator */
2321 client = st->i2c_client_demod;
2323 module_put(client->dev.driver->owner);
2324 i2c_unregister_device(client);
2327 dvb_usb_device_exit(intf);
2330 static struct usb_driver dw2102_driver = {
2332 .probe = dw2102_probe,
2333 .disconnect = dw2102_disconnect,
2334 .id_table = dw2102_table,
2337 module_usb_driver(dw2102_driver);
2339 MODULE_AUTHOR("Igor M. Liplianin (c) liplianin@me.by");
2340 MODULE_DESCRIPTION("Driver for DVBWorld DVB-S 2101, 2102, DVB-S2 2104,"
2341 " DVB-C 3101 USB2.0,"
2342 " TeVii S421, S480, S482, S600, S630, S632, S650,"
2343 " TeVii S660, S662, Prof 1100, 7500 USB2.0,"
2344 " Geniatech SU3000, T220,"
2345 " TechnoTrend S2-4600, Terratec Cinergy S2 devices");
2346 MODULE_VERSION("0.1");
2347 MODULE_LICENSE("GPL");
2348 MODULE_FIRMWARE(DW2101_FIRMWARE);
2349 MODULE_FIRMWARE(DW2102_FIRMWARE);
2350 MODULE_FIRMWARE(DW2104_FIRMWARE);
2351 MODULE_FIRMWARE(DW3101_FIRMWARE);
2352 MODULE_FIRMWARE(S630_FIRMWARE);
2353 MODULE_FIRMWARE(S660_FIRMWARE);
2354 MODULE_FIRMWARE(P1100_FIRMWARE);
2355 MODULE_FIRMWARE(P7500_FIRMWARE);