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", __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", __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!");
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!");
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!");
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!");
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!");
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!");
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!");
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!");
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!");
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!");
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!");
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!");
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!");
1360 info("Failed to attach DS3000/TS2020!");
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!");
1410 info("Failed to attach TDA18271HD/CXD2820R!");
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!");
1435 info("Failed to attach RS2000/TS2020!");
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,
1644 TERRATEC_CINERGY_S2_R3,
1647 TECHNOTREND_S2_4600,
1650 TERRATEC_CINERGY_S2_BOX,
1654 static struct usb_device_id dw2102_table[] = {
1655 [CYPRESS_DW2102] = {USB_DEVICE(USB_VID_CYPRESS, USB_PID_DW2102)},
1656 [CYPRESS_DW2101] = {USB_DEVICE(USB_VID_CYPRESS, 0x2101)},
1657 [CYPRESS_DW2104] = {USB_DEVICE(USB_VID_CYPRESS, USB_PID_DW2104)},
1658 [TEVII_S650] = {USB_DEVICE(0x9022, USB_PID_TEVII_S650)},
1659 [TERRATEC_CINERGY_S] = {USB_DEVICE(USB_VID_TERRATEC, USB_PID_TERRATEC_CINERGY_S)},
1660 [CYPRESS_DW3101] = {USB_DEVICE(USB_VID_CYPRESS, USB_PID_DW3101)},
1661 [TEVII_S630] = {USB_DEVICE(0x9022, USB_PID_TEVII_S630)},
1662 [PROF_1100] = {USB_DEVICE(0x3011, USB_PID_PROF_1100)},
1663 [TEVII_S660] = {USB_DEVICE(0x9022, USB_PID_TEVII_S660)},
1664 [PROF_7500] = {USB_DEVICE(0x3034, 0x7500)},
1665 [GENIATECH_SU3000] = {USB_DEVICE(0x1f4d, 0x3000)},
1666 [TERRATEC_CINERGY_S2] = {USB_DEVICE(USB_VID_TERRATEC, USB_PID_TERRATEC_CINERGY_S2_R1)},
1667 [TEVII_S480_1] = {USB_DEVICE(0x9022, USB_PID_TEVII_S480_1)},
1668 [TEVII_S480_2] = {USB_DEVICE(0x9022, USB_PID_TEVII_S480_2)},
1669 [X3M_SPC1400HD] = {USB_DEVICE(0x1f4d, 0x3100)},
1670 [TEVII_S421] = {USB_DEVICE(0x9022, USB_PID_TEVII_S421)},
1671 [TEVII_S632] = {USB_DEVICE(0x9022, USB_PID_TEVII_S632)},
1672 [TERRATEC_CINERGY_S2_R2] = {USB_DEVICE(USB_VID_TERRATEC, USB_PID_TERRATEC_CINERGY_S2_R2)},
1673 [TERRATEC_CINERGY_S2_R3] = {USB_DEVICE(USB_VID_TERRATEC, USB_PID_TERRATEC_CINERGY_S2_R3)},
1674 [GOTVIEW_SAT_HD] = {USB_DEVICE(0x1FE1, USB_PID_GOTVIEW_SAT_HD)},
1675 [GENIATECH_T220] = {USB_DEVICE(0x1f4d, 0xD220)},
1676 [TECHNOTREND_S2_4600] = {USB_DEVICE(USB_VID_TECHNOTREND,
1677 USB_PID_TECHNOTREND_CONNECT_S2_4600)},
1678 [TEVII_S482_1] = {USB_DEVICE(0x9022, 0xd483)},
1679 [TEVII_S482_2] = {USB_DEVICE(0x9022, 0xd484)},
1680 [TERRATEC_CINERGY_S2_BOX] = {USB_DEVICE(USB_VID_TERRATEC, 0x0105)},
1681 [TEVII_S662] = {USB_DEVICE(0x9022, USB_PID_TEVII_S662)},
1685 MODULE_DEVICE_TABLE(usb, dw2102_table);
1687 static int dw2102_load_firmware(struct usb_device *dev,
1688 const struct firmware *frmwr)
1693 u8 reset16[] = {0, 0, 0, 0, 0, 0, 0};
1694 const struct firmware *fw;
1696 switch (le16_to_cpu(dev->descriptor.idProduct)) {
1698 ret = request_firmware(&fw, DW2101_FIRMWARE, &dev->dev);
1700 err(err_str, DW2101_FIRMWARE);
1708 info("start downloading DW210X firmware");
1709 p = kmalloc(fw->size, GFP_KERNEL);
1712 dw210x_op_rw(dev, 0xa0, 0x7f92, 0, &reset, 1, DW210X_WRITE_MSG);
1713 dw210x_op_rw(dev, 0xa0, 0xe600, 0, &reset, 1, DW210X_WRITE_MSG);
1716 memcpy(p, fw->data, fw->size);
1717 for (i = 0; i < fw->size; i += 0x40) {
1719 if (dw210x_op_rw(dev, 0xa0, i, 0, b , 0x40,
1720 DW210X_WRITE_MSG) != 0x40) {
1721 err("error while transferring firmware");
1726 /* restart the CPU */
1728 if (ret || dw210x_op_rw(dev, 0xa0, 0x7f92, 0, &reset, 1,
1729 DW210X_WRITE_MSG) != 1) {
1730 err("could not restart the USB controller CPU.");
1733 if (ret || dw210x_op_rw(dev, 0xa0, 0xe600, 0, &reset, 1,
1734 DW210X_WRITE_MSG) != 1) {
1735 err("could not restart the USB controller CPU.");
1738 /* init registers */
1739 switch (le16_to_cpu(dev->descriptor.idProduct)) {
1740 case USB_PID_TEVII_S650:
1741 dw2104_properties.rc.core.rc_codes = RC_MAP_TEVII_NEC;
1742 case USB_PID_DW2104:
1744 dw210x_op_rw(dev, 0xc4, 0x0000, 0, &reset, 1,
1746 /* break omitted intentionally */
1747 case USB_PID_DW3101:
1749 dw210x_op_rw(dev, 0xbf, 0x0040, 0, &reset, 0,
1752 case USB_PID_TERRATEC_CINERGY_S:
1753 case USB_PID_DW2102:
1754 dw210x_op_rw(dev, 0xbf, 0x0040, 0, &reset, 0,
1756 dw210x_op_rw(dev, 0xb9, 0x0000, 0, &reset16[0], 2,
1758 /* check STV0299 frontend */
1759 dw210x_op_rw(dev, 0xb5, 0, 0, &reset16[0], 2,
1761 if ((reset16[0] == 0xa1) || (reset16[0] == 0x80)) {
1762 dw2102_properties.i2c_algo = &dw2102_i2c_algo;
1763 dw2102_properties.adapter->fe[0].tuner_attach = &dw2102_tuner_attach;
1766 /* check STV0288 frontend */
1770 dw210x_op_rw(dev, 0xc2, 0, 0, &reset16[0], 3,
1772 dw210x_op_rw(dev, 0xc3, 0xd1, 0, &reset16[0], 3,
1774 if (reset16[2] == 0x11) {
1775 dw2102_properties.i2c_algo = &dw2102_earda_i2c_algo;
1780 dw210x_op_rw(dev, 0xbc, 0x0030, 0, &reset16[0], 2,
1782 dw210x_op_rw(dev, 0xba, 0x0000, 0, &reset16[0], 7,
1784 dw210x_op_rw(dev, 0xba, 0x0000, 0, &reset16[0], 7,
1786 dw210x_op_rw(dev, 0xb9, 0x0000, 0, &reset16[0], 2,
1795 if (le16_to_cpu(dev->descriptor.idProduct) == 0x2101)
1796 release_firmware(fw);
1800 static struct dvb_usb_device_properties dw2102_properties = {
1801 .caps = DVB_USB_IS_AN_I2C_ADAPTER,
1802 .usb_ctrl = DEVICE_SPECIFIC,
1803 .firmware = DW2102_FIRMWARE,
1806 .i2c_algo = &dw2102_serit_i2c_algo,
1810 .rc_codes = RC_MAP_DM1105_NEC,
1811 .module_name = "dw2102",
1812 .allowed_protos = RC_BIT_NEC,
1813 .rc_query = dw2102_rc_query,
1816 .generic_bulk_ctrl_endpoint = 0x81,
1817 /* parameter for the MPEG2-data transfer */
1819 .download_firmware = dw2102_load_firmware,
1820 .read_mac_address = dw210x_read_mac_address,
1825 .frontend_attach = dw2102_frontend_attach,
1839 .num_device_descs = 3,
1841 {"DVBWorld DVB-S 2102 USB2.0",
1842 {&dw2102_table[CYPRESS_DW2102], NULL},
1845 {"DVBWorld DVB-S 2101 USB2.0",
1846 {&dw2102_table[CYPRESS_DW2101], NULL},
1849 {"TerraTec Cinergy S USB",
1850 {&dw2102_table[TERRATEC_CINERGY_S], NULL},
1856 static struct dvb_usb_device_properties dw2104_properties = {
1857 .caps = DVB_USB_IS_AN_I2C_ADAPTER,
1858 .usb_ctrl = DEVICE_SPECIFIC,
1859 .firmware = DW2104_FIRMWARE,
1862 .i2c_algo = &dw2104_i2c_algo,
1865 .rc_codes = RC_MAP_DM1105_NEC,
1866 .module_name = "dw2102",
1867 .allowed_protos = RC_BIT_NEC,
1868 .rc_query = dw2102_rc_query,
1871 .generic_bulk_ctrl_endpoint = 0x81,
1872 /* parameter for the MPEG2-data transfer */
1874 .download_firmware = dw2102_load_firmware,
1875 .read_mac_address = dw210x_read_mac_address,
1880 .frontend_attach = dw2104_frontend_attach,
1894 .num_device_descs = 2,
1896 { "DVBWorld DW2104 USB2.0",
1897 {&dw2102_table[CYPRESS_DW2104], NULL},
1900 { "TeVii S650 USB2.0",
1901 {&dw2102_table[TEVII_S650], NULL},
1907 static struct dvb_usb_device_properties dw3101_properties = {
1908 .caps = DVB_USB_IS_AN_I2C_ADAPTER,
1909 .usb_ctrl = DEVICE_SPECIFIC,
1910 .firmware = DW3101_FIRMWARE,
1913 .i2c_algo = &dw3101_i2c_algo,
1916 .rc_codes = RC_MAP_DM1105_NEC,
1917 .module_name = "dw2102",
1918 .allowed_protos = RC_BIT_NEC,
1919 .rc_query = dw2102_rc_query,
1922 .generic_bulk_ctrl_endpoint = 0x81,
1923 /* parameter for the MPEG2-data transfer */
1925 .download_firmware = dw2102_load_firmware,
1926 .read_mac_address = dw210x_read_mac_address,
1931 .frontend_attach = dw3101_frontend_attach,
1932 .tuner_attach = dw3101_tuner_attach,
1946 .num_device_descs = 1,
1948 { "DVBWorld DVB-C 3101 USB2.0",
1949 {&dw2102_table[CYPRESS_DW3101], NULL},
1955 static struct dvb_usb_device_properties s6x0_properties = {
1956 .caps = DVB_USB_IS_AN_I2C_ADAPTER,
1957 .usb_ctrl = DEVICE_SPECIFIC,
1958 .size_of_priv = sizeof(struct dw2102_state),
1959 .firmware = S630_FIRMWARE,
1962 .i2c_algo = &s6x0_i2c_algo,
1965 .rc_codes = RC_MAP_TEVII_NEC,
1966 .module_name = "dw2102",
1967 .allowed_protos = RC_BIT_NEC,
1968 .rc_query = dw2102_rc_query,
1971 .generic_bulk_ctrl_endpoint = 0x81,
1973 .download_firmware = dw2102_load_firmware,
1974 .read_mac_address = s6x0_read_mac_address,
1979 .frontend_attach = zl100313_frontend_attach,
1993 .num_device_descs = 1,
1996 {&dw2102_table[TEVII_S630], NULL},
2002 static struct dvb_usb_device_properties *p1100;
2003 static struct dvb_usb_device_description d1100 = {
2005 {&dw2102_table[PROF_1100], NULL},
2009 static struct dvb_usb_device_properties *s660;
2010 static struct dvb_usb_device_description d660 = {
2012 {&dw2102_table[TEVII_S660], NULL},
2016 static struct dvb_usb_device_description d480_1 = {
2018 {&dw2102_table[TEVII_S480_1], NULL},
2022 static struct dvb_usb_device_description d480_2 = {
2024 {&dw2102_table[TEVII_S480_2], NULL},
2028 static struct dvb_usb_device_properties *p7500;
2029 static struct dvb_usb_device_description d7500 = {
2030 "Prof 7500 USB DVB-S2",
2031 {&dw2102_table[PROF_7500], NULL},
2035 static struct dvb_usb_device_properties *s421;
2036 static struct dvb_usb_device_description d421 = {
2038 {&dw2102_table[TEVII_S421], NULL},
2042 static struct dvb_usb_device_description d632 = {
2044 {&dw2102_table[TEVII_S632], NULL},
2048 static struct dvb_usb_device_properties su3000_properties = {
2049 .caps = DVB_USB_IS_AN_I2C_ADAPTER,
2050 .usb_ctrl = DEVICE_SPECIFIC,
2051 .size_of_priv = sizeof(struct dw2102_state),
2052 .power_ctrl = su3000_power_ctrl,
2054 .identify_state = su3000_identify_state,
2055 .i2c_algo = &su3000_i2c_algo,
2059 .rc_codes = RC_MAP_SU3000,
2060 .module_name = "dw2102",
2061 .allowed_protos = RC_BIT_RC5,
2062 .rc_query = su3000_rc_query,
2065 .read_mac_address = su3000_read_mac_address,
2067 .generic_bulk_ctrl_endpoint = 0x01,
2073 .streaming_ctrl = su3000_streaming_ctrl,
2074 .frontend_attach = su3000_frontend_attach,
2088 .num_device_descs = 6,
2090 { "SU3000HD DVB-S USB2.0",
2091 { &dw2102_table[GENIATECH_SU3000], NULL },
2094 { "Terratec Cinergy S2 USB HD",
2095 { &dw2102_table[TERRATEC_CINERGY_S2], NULL },
2098 { "X3M TV SPC1400HD PCI",
2099 { &dw2102_table[X3M_SPC1400HD], NULL },
2102 { "Terratec Cinergy S2 USB HD Rev.2",
2103 { &dw2102_table[TERRATEC_CINERGY_S2_R2], NULL },
2106 { "Terratec Cinergy S2 USB HD Rev.3",
2107 { &dw2102_table[TERRATEC_CINERGY_S2_R3], NULL },
2110 { "GOTVIEW Satellite HD",
2111 { &dw2102_table[GOTVIEW_SAT_HD], NULL },
2117 static struct dvb_usb_device_properties t220_properties = {
2118 .caps = DVB_USB_IS_AN_I2C_ADAPTER,
2119 .usb_ctrl = DEVICE_SPECIFIC,
2120 .size_of_priv = sizeof(struct dw2102_state),
2121 .power_ctrl = su3000_power_ctrl,
2123 .identify_state = su3000_identify_state,
2124 .i2c_algo = &su3000_i2c_algo,
2128 .rc_codes = RC_MAP_SU3000,
2129 .module_name = "dw2102",
2130 .allowed_protos = RC_BIT_RC5,
2131 .rc_query = su3000_rc_query,
2134 .read_mac_address = su3000_read_mac_address,
2136 .generic_bulk_ctrl_endpoint = 0x01,
2142 .streaming_ctrl = su3000_streaming_ctrl,
2143 .frontend_attach = t220_frontend_attach,
2157 .num_device_descs = 1,
2159 { "Geniatech T220 DVB-T/T2 USB2.0",
2160 { &dw2102_table[GENIATECH_T220], NULL },
2166 static struct dvb_usb_device_properties tt_s2_4600_properties = {
2167 .caps = DVB_USB_IS_AN_I2C_ADAPTER,
2168 .usb_ctrl = DEVICE_SPECIFIC,
2169 .size_of_priv = sizeof(struct dw2102_state),
2170 .power_ctrl = su3000_power_ctrl,
2172 .identify_state = su3000_identify_state,
2173 .i2c_algo = &su3000_i2c_algo,
2177 .rc_codes = RC_MAP_TT_1500,
2178 .module_name = "dw2102",
2179 .allowed_protos = RC_BIT_RC5,
2180 .rc_query = su3000_rc_query,
2183 .read_mac_address = su3000_read_mac_address,
2185 .generic_bulk_ctrl_endpoint = 0x01,
2191 .streaming_ctrl = su3000_streaming_ctrl,
2192 .frontend_attach = tt_s2_4600_frontend_attach,
2206 .num_device_descs = 5,
2208 { "TechnoTrend TT-connect S2-4600",
2209 { &dw2102_table[TECHNOTREND_S2_4600], NULL },
2212 { "TeVii S482 (tuner 1)",
2213 { &dw2102_table[TEVII_S482_1], NULL },
2216 { "TeVii S482 (tuner 2)",
2217 { &dw2102_table[TEVII_S482_2], NULL },
2220 { "Terratec Cinergy S2 USB BOX",
2221 { &dw2102_table[TERRATEC_CINERGY_S2_BOX], NULL },
2225 { &dw2102_table[TEVII_S662], NULL },
2231 static int dw2102_probe(struct usb_interface *intf,
2232 const struct usb_device_id *id)
2234 p1100 = kmemdup(&s6x0_properties,
2235 sizeof(struct dvb_usb_device_properties), GFP_KERNEL);
2238 /* copy default structure */
2239 /* fill only different fields */
2240 p1100->firmware = P1100_FIRMWARE;
2241 p1100->devices[0] = d1100;
2242 p1100->rc.core.rc_query = prof_rc_query;
2243 p1100->rc.core.rc_codes = RC_MAP_TBS_NEC;
2244 p1100->adapter->fe[0].frontend_attach = stv0288_frontend_attach;
2246 s660 = kmemdup(&s6x0_properties,
2247 sizeof(struct dvb_usb_device_properties), GFP_KERNEL);
2252 s660->firmware = S660_FIRMWARE;
2253 s660->num_device_descs = 3;
2254 s660->devices[0] = d660;
2255 s660->devices[1] = d480_1;
2256 s660->devices[2] = d480_2;
2257 s660->adapter->fe[0].frontend_attach = ds3000_frontend_attach;
2259 p7500 = kmemdup(&s6x0_properties,
2260 sizeof(struct dvb_usb_device_properties), GFP_KERNEL);
2266 p7500->firmware = P7500_FIRMWARE;
2267 p7500->devices[0] = d7500;
2268 p7500->rc.core.rc_query = prof_rc_query;
2269 p7500->rc.core.rc_codes = RC_MAP_TBS_NEC;
2270 p7500->adapter->fe[0].frontend_attach = prof_7500_frontend_attach;
2273 s421 = kmemdup(&su3000_properties,
2274 sizeof(struct dvb_usb_device_properties), GFP_KERNEL);
2281 s421->num_device_descs = 2;
2282 s421->devices[0] = d421;
2283 s421->devices[1] = d632;
2284 s421->adapter->fe[0].frontend_attach = m88rs2000_frontend_attach;
2286 if (0 == dvb_usb_device_init(intf, &dw2102_properties,
2287 THIS_MODULE, NULL, adapter_nr) ||
2288 0 == dvb_usb_device_init(intf, &dw2104_properties,
2289 THIS_MODULE, NULL, adapter_nr) ||
2290 0 == dvb_usb_device_init(intf, &dw3101_properties,
2291 THIS_MODULE, NULL, adapter_nr) ||
2292 0 == dvb_usb_device_init(intf, &s6x0_properties,
2293 THIS_MODULE, NULL, adapter_nr) ||
2294 0 == dvb_usb_device_init(intf, p1100,
2295 THIS_MODULE, NULL, adapter_nr) ||
2296 0 == dvb_usb_device_init(intf, s660,
2297 THIS_MODULE, NULL, adapter_nr) ||
2298 0 == dvb_usb_device_init(intf, p7500,
2299 THIS_MODULE, NULL, adapter_nr) ||
2300 0 == dvb_usb_device_init(intf, s421,
2301 THIS_MODULE, NULL, adapter_nr) ||
2302 0 == dvb_usb_device_init(intf, &su3000_properties,
2303 THIS_MODULE, NULL, adapter_nr) ||
2304 0 == dvb_usb_device_init(intf, &t220_properties,
2305 THIS_MODULE, NULL, adapter_nr) ||
2306 0 == dvb_usb_device_init(intf, &tt_s2_4600_properties,
2307 THIS_MODULE, NULL, adapter_nr))
2313 static void dw2102_disconnect(struct usb_interface *intf)
2315 struct dvb_usb_device *d = usb_get_intfdata(intf);
2316 struct dw2102_state *st = (struct dw2102_state *)d->priv;
2317 struct i2c_client *client;
2319 /* remove I2C client for tuner */
2320 client = st->i2c_client_tuner;
2322 module_put(client->dev.driver->owner);
2323 i2c_unregister_device(client);
2326 /* remove I2C client for demodulator */
2327 client = st->i2c_client_demod;
2329 module_put(client->dev.driver->owner);
2330 i2c_unregister_device(client);
2333 dvb_usb_device_exit(intf);
2336 static struct usb_driver dw2102_driver = {
2338 .probe = dw2102_probe,
2339 .disconnect = dw2102_disconnect,
2340 .id_table = dw2102_table,
2343 module_usb_driver(dw2102_driver);
2345 MODULE_AUTHOR("Igor M. Liplianin (c) liplianin@me.by");
2346 MODULE_DESCRIPTION("Driver for DVBWorld DVB-S 2101, 2102, DVB-S2 2104,"
2347 " DVB-C 3101 USB2.0,"
2348 " TeVii S421, S480, S482, S600, S630, S632, S650,"
2349 " TeVii S660, S662, Prof 1100, 7500 USB2.0,"
2350 " Geniatech SU3000, T220,"
2351 " TechnoTrend S2-4600, Terratec Cinergy S2 devices");
2352 MODULE_VERSION("0.1");
2353 MODULE_LICENSE("GPL");
2354 MODULE_FIRMWARE(DW2101_FIRMWARE);
2355 MODULE_FIRMWARE(DW2102_FIRMWARE);
2356 MODULE_FIRMWARE(DW2104_FIRMWARE);
2357 MODULE_FIRMWARE(DW3101_FIRMWARE);
2358 MODULE_FIRMWARE(S630_FIRMWARE);
2359 MODULE_FIRMWARE(S660_FIRMWARE);
2360 MODULE_FIRMWARE(P1100_FIRMWARE);
2361 MODULE_FIRMWARE(P7500_FIRMWARE);