GNU Linux-libre 4.19.295-gnu1
[releases.git] / drivers / media / usb / dvb-usb / dw2102.c
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,
4  *      Prof 1100, 7500,
5  *      Geniatech SU3000, T220,
6  *      TechnoTrend S2-4600,
7  *      Terratec Cinergy S2 cards
8  * Copyright (C) 2008-2012 Igor M. Liplianin (liplianin@me.by)
9  *
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.
13  *
14  * see Documentation/media/dvb-drivers/dvb-usb.rst for more information
15  */
16 #include <media/dvb-usb-ids.h>
17 #include "dw2102.h"
18 #include "si21xx.h"
19 #include "stv0299.h"
20 #include "z0194a.h"
21 #include "stv0288.h"
22 #include "stb6000.h"
23 #include "eds1547.h"
24 #include "cx24116.h"
25 #include "tda1002x.h"
26 #include "mt312.h"
27 #include "zl10039.h"
28 #include "ts2020.h"
29 #include "ds3000.h"
30 #include "stv0900.h"
31 #include "stv6110.h"
32 #include "stb6100.h"
33 #include "stb6100_proc.h"
34 #include "m88rs2000.h"
35 #include "tda18271.h"
36 #include "cxd2820r.h"
37 #include "m88ds3103.h"
38
39 /* Max transfer size done by I2C transfer functions */
40 #define MAX_XFER_SIZE  64
41
42
43 #define DW210X_READ_MSG 0
44 #define DW210X_WRITE_MSG 1
45
46 #define REG_1F_SYMBOLRATE_BYTE0 0x1f
47 #define REG_20_SYMBOLRATE_BYTE1 0x20
48 #define REG_21_SYMBOLRATE_BYTE2 0x21
49 /* on my own*/
50 #define DW2102_VOLTAGE_CTRL (0x1800)
51 #define SU3000_STREAM_CTRL (0x1900)
52 #define DW2102_RC_QUERY (0x1a00)
53 #define DW2102_LED_CTRL (0x1b00)
54
55 #define DW2101_FIRMWARE "/*(DEBLOBBED)*/"
56 #define DW2102_FIRMWARE "/*(DEBLOBBED)*/"
57 #define DW2104_FIRMWARE "/*(DEBLOBBED)*/"
58 #define DW3101_FIRMWARE "/*(DEBLOBBED)*/"
59 #define S630_FIRMWARE   "/*(DEBLOBBED)*/"
60 #define S660_FIRMWARE   "/*(DEBLOBBED)*/"
61 #define P1100_FIRMWARE  "/*(DEBLOBBED)*/"
62 #define P7500_FIRMWARE  "/*(DEBLOBBED)*/"
63
64 #define err_str "did not find the firmware file '%s'. /*(DEBLOBBED)*/"
65
66 struct dw2102_state {
67         u8 initialized;
68         u8 last_lock;
69         u8 data[MAX_XFER_SIZE + 4];
70         struct i2c_client *i2c_client_demod;
71         struct i2c_client *i2c_client_tuner;
72
73         /* fe hook functions*/
74         int (*old_set_voltage)(struct dvb_frontend *f, enum fe_sec_voltage v);
75         int (*fe_read_status)(struct dvb_frontend *fe,
76                               enum fe_status *status);
77 };
78
79 /* debug */
80 static int dvb_usb_dw2102_debug;
81 module_param_named(debug, dvb_usb_dw2102_debug, int, 0644);
82 MODULE_PARM_DESC(debug, "set debugging level (1=info 2=xfer 4=rc(or-able))."
83                                                 DVB_USB_DEBUG_STATUS);
84
85 /* demod probe */
86 static int demod_probe = 1;
87 module_param_named(demod, demod_probe, int, 0644);
88 MODULE_PARM_DESC(demod, "demod to probe (1=cx24116 2=stv0903+stv6110 4=stv0903+stb6100(or-able)).");
89
90 DVB_DEFINE_MOD_OPT_ADAPTER_NR(adapter_nr);
91
92 static int dw210x_op_rw(struct usb_device *dev, u8 request, u16 value,
93                         u16 index, u8 * data, u16 len, int flags)
94 {
95         int ret;
96         u8 *u8buf;
97         unsigned int pipe = (flags == DW210X_READ_MSG) ?
98                                 usb_rcvctrlpipe(dev, 0) : usb_sndctrlpipe(dev, 0);
99         u8 request_type = (flags == DW210X_READ_MSG) ? USB_DIR_IN : USB_DIR_OUT;
100
101         u8buf = kmalloc(len, GFP_KERNEL);
102         if (!u8buf)
103                 return -ENOMEM;
104
105
106         if (flags == DW210X_WRITE_MSG)
107                 memcpy(u8buf, data, len);
108         ret = usb_control_msg(dev, pipe, request, request_type | USB_TYPE_VENDOR,
109                                 value, index , u8buf, len, 2000);
110
111         if (flags == DW210X_READ_MSG)
112                 memcpy(data, u8buf, len);
113
114         kfree(u8buf);
115         return ret;
116 }
117
118 /* I2C */
119 static int dw2102_i2c_transfer(struct i2c_adapter *adap, struct i2c_msg msg[],
120                 int num)
121 {
122         struct dvb_usb_device *d = i2c_get_adapdata(adap);
123         int i = 0;
124         u8 buf6[] = {0x2c, 0x05, 0xc0, 0, 0, 0, 0};
125         u16 value;
126
127         if (!d)
128                 return -ENODEV;
129         if (mutex_lock_interruptible(&d->i2c_mutex) < 0)
130                 return -EAGAIN;
131
132         switch (num) {
133         case 2:
134                 if (msg[0].len < 1) {
135                         num = -EOPNOTSUPP;
136                         break;
137                 }
138                 /* read stv0299 register */
139                 value = msg[0].buf[0];/* register */
140                 for (i = 0; i < msg[1].len; i++) {
141                         dw210x_op_rw(d->udev, 0xb5, value + i, 0,
142                                         buf6, 2, DW210X_READ_MSG);
143                         msg[1].buf[i] = buf6[0];
144                 }
145                 break;
146         case 1:
147                 switch (msg[0].addr) {
148                 case 0x68:
149                         if (msg[0].len < 2) {
150                                 num = -EOPNOTSUPP;
151                                 break;
152                         }
153                         /* write to stv0299 register */
154                         buf6[0] = 0x2a;
155                         buf6[1] = msg[0].buf[0];
156                         buf6[2] = msg[0].buf[1];
157                         dw210x_op_rw(d->udev, 0xb2, 0, 0,
158                                         buf6, 3, DW210X_WRITE_MSG);
159                         break;
160                 case 0x60:
161                         if (msg[0].flags == 0) {
162                                 if (msg[0].len < 4) {
163                                         num = -EOPNOTSUPP;
164                                         break;
165                                 }
166                         /* write to tuner pll */
167                                 buf6[0] = 0x2c;
168                                 buf6[1] = 5;
169                                 buf6[2] = 0xc0;
170                                 buf6[3] = msg[0].buf[0];
171                                 buf6[4] = msg[0].buf[1];
172                                 buf6[5] = msg[0].buf[2];
173                                 buf6[6] = msg[0].buf[3];
174                                 dw210x_op_rw(d->udev, 0xb2, 0, 0,
175                                                 buf6, 7, DW210X_WRITE_MSG);
176                         } else {
177                                 if (msg[0].len < 1) {
178                                         num = -EOPNOTSUPP;
179                                         break;
180                                 }
181                         /* read from tuner */
182                                 dw210x_op_rw(d->udev, 0xb5, 0, 0,
183                                                 buf6, 1, DW210X_READ_MSG);
184                                 msg[0].buf[0] = buf6[0];
185                         }
186                         break;
187                 case (DW2102_RC_QUERY):
188                         if (msg[0].len < 2) {
189                                 num = -EOPNOTSUPP;
190                                 break;
191                         }
192                         dw210x_op_rw(d->udev, 0xb8, 0, 0,
193                                         buf6, 2, DW210X_READ_MSG);
194                         msg[0].buf[0] = buf6[0];
195                         msg[0].buf[1] = buf6[1];
196                         break;
197                 case (DW2102_VOLTAGE_CTRL):
198                         if (msg[0].len < 1) {
199                                 num = -EOPNOTSUPP;
200                                 break;
201                         }
202                         buf6[0] = 0x30;
203                         buf6[1] = msg[0].buf[0];
204                         dw210x_op_rw(d->udev, 0xb2, 0, 0,
205                                         buf6, 2, DW210X_WRITE_MSG);
206                         break;
207                 }
208
209                 break;
210         }
211
212         mutex_unlock(&d->i2c_mutex);
213         return num;
214 }
215
216 static int dw2102_serit_i2c_transfer(struct i2c_adapter *adap,
217                                                 struct i2c_msg msg[], int num)
218 {
219         struct dvb_usb_device *d = i2c_get_adapdata(adap);
220         u8 buf6[] = {0, 0, 0, 0, 0, 0, 0};
221
222         if (!d)
223                 return -ENODEV;
224         if (mutex_lock_interruptible(&d->i2c_mutex) < 0)
225                 return -EAGAIN;
226
227         switch (num) {
228         case 2:
229                 if (msg[0].len != 1) {
230                         warn("i2c rd: len=%d is not 1!\n",
231                              msg[0].len);
232                         num = -EOPNOTSUPP;
233                         break;
234                 }
235
236                 if (2 + msg[1].len > sizeof(buf6)) {
237                         warn("i2c rd: len=%d is too big!\n",
238                              msg[1].len);
239                         num = -EOPNOTSUPP;
240                         break;
241                 }
242
243                 /* read si2109 register by number */
244                 buf6[0] = msg[0].addr << 1;
245                 buf6[1] = msg[0].len;
246                 buf6[2] = msg[0].buf[0];
247                 dw210x_op_rw(d->udev, 0xc2, 0, 0,
248                                 buf6, msg[0].len + 2, DW210X_WRITE_MSG);
249                 /* read si2109 register */
250                 dw210x_op_rw(d->udev, 0xc3, 0xd0, 0,
251                                 buf6, msg[1].len + 2, DW210X_READ_MSG);
252                 memcpy(msg[1].buf, buf6 + 2, msg[1].len);
253
254                 break;
255         case 1:
256                 switch (msg[0].addr) {
257                 case 0x68:
258                         if (2 + msg[0].len > sizeof(buf6)) {
259                                 warn("i2c wr: len=%d is too big!\n",
260                                      msg[0].len);
261                                 num = -EOPNOTSUPP;
262                                 break;
263                         }
264
265                         /* write to si2109 register */
266                         buf6[0] = msg[0].addr << 1;
267                         buf6[1] = msg[0].len;
268                         memcpy(buf6 + 2, msg[0].buf, msg[0].len);
269                         dw210x_op_rw(d->udev, 0xc2, 0, 0, buf6,
270                                         msg[0].len + 2, DW210X_WRITE_MSG);
271                         break;
272                 case(DW2102_RC_QUERY):
273                         dw210x_op_rw(d->udev, 0xb8, 0, 0,
274                                         buf6, 2, DW210X_READ_MSG);
275                         msg[0].buf[0] = buf6[0];
276                         msg[0].buf[1] = buf6[1];
277                         break;
278                 case(DW2102_VOLTAGE_CTRL):
279                         buf6[0] = 0x30;
280                         buf6[1] = msg[0].buf[0];
281                         dw210x_op_rw(d->udev, 0xb2, 0, 0,
282                                         buf6, 2, DW210X_WRITE_MSG);
283                         break;
284                 }
285                 break;
286         }
287
288         mutex_unlock(&d->i2c_mutex);
289         return num;
290 }
291
292 static int dw2102_earda_i2c_transfer(struct i2c_adapter *adap, struct i2c_msg msg[], int num)
293 {
294         struct dvb_usb_device *d = i2c_get_adapdata(adap);
295         int ret;
296
297         if (!d)
298                 return -ENODEV;
299         if (mutex_lock_interruptible(&d->i2c_mutex) < 0)
300                 return -EAGAIN;
301
302         switch (num) {
303         case 2: {
304                 /* read */
305                 /* first write first register number */
306                 u8 ibuf[MAX_XFER_SIZE], obuf[3];
307
308                 if (2 + msg[0].len != sizeof(obuf)) {
309                         warn("i2c rd: len=%d is not 1!\n",
310                              msg[0].len);
311                         ret = -EOPNOTSUPP;
312                         goto unlock;
313                 }
314
315                 if (2 + msg[1].len > sizeof(ibuf)) {
316                         warn("i2c rd: len=%d is too big!\n",
317                              msg[1].len);
318                         ret = -EOPNOTSUPP;
319                         goto unlock;
320                 }
321
322                 obuf[0] = msg[0].addr << 1;
323                 obuf[1] = msg[0].len;
324                 obuf[2] = msg[0].buf[0];
325                 dw210x_op_rw(d->udev, 0xc2, 0, 0,
326                                 obuf, msg[0].len + 2, DW210X_WRITE_MSG);
327                 /* second read registers */
328                 dw210x_op_rw(d->udev, 0xc3, 0xd1 , 0,
329                                 ibuf, msg[1].len + 2, DW210X_READ_MSG);
330                 memcpy(msg[1].buf, ibuf + 2, msg[1].len);
331
332                 break;
333         }
334         case 1:
335                 switch (msg[0].addr) {
336                 case 0x68: {
337                         /* write to register */
338                         u8 obuf[MAX_XFER_SIZE];
339
340                         if (2 + msg[0].len > sizeof(obuf)) {
341                                 warn("i2c wr: len=%d is too big!\n",
342                                      msg[1].len);
343                                 ret = -EOPNOTSUPP;
344                                 goto unlock;
345                         }
346
347                         obuf[0] = msg[0].addr << 1;
348                         obuf[1] = msg[0].len;
349                         memcpy(obuf + 2, msg[0].buf, msg[0].len);
350                         dw210x_op_rw(d->udev, 0xc2, 0, 0,
351                                         obuf, msg[0].len + 2, DW210X_WRITE_MSG);
352                         break;
353                 }
354                 case 0x61: {
355                         /* write to tuner */
356                         u8 obuf[MAX_XFER_SIZE];
357
358                         if (2 + msg[0].len > sizeof(obuf)) {
359                                 warn("i2c wr: len=%d is too big!\n",
360                                      msg[1].len);
361                                 ret = -EOPNOTSUPP;
362                                 goto unlock;
363                         }
364
365                         obuf[0] = msg[0].addr << 1;
366                         obuf[1] = msg[0].len;
367                         memcpy(obuf + 2, msg[0].buf, msg[0].len);
368                         dw210x_op_rw(d->udev, 0xc2, 0, 0,
369                                         obuf, msg[0].len + 2, DW210X_WRITE_MSG);
370                         break;
371                 }
372                 case(DW2102_RC_QUERY): {
373                         u8 ibuf[2];
374                         dw210x_op_rw(d->udev, 0xb8, 0, 0,
375                                         ibuf, 2, DW210X_READ_MSG);
376                         memcpy(msg[0].buf, ibuf , 2);
377                         break;
378                 }
379                 case(DW2102_VOLTAGE_CTRL): {
380                         u8 obuf[2];
381                         obuf[0] = 0x30;
382                         obuf[1] = msg[0].buf[0];
383                         dw210x_op_rw(d->udev, 0xb2, 0, 0,
384                                         obuf, 2, DW210X_WRITE_MSG);
385                         break;
386                 }
387                 }
388
389                 break;
390         }
391         ret = num;
392
393 unlock:
394         mutex_unlock(&d->i2c_mutex);
395         return ret;
396 }
397
398 static int dw2104_i2c_transfer(struct i2c_adapter *adap, struct i2c_msg msg[], int num)
399 {
400         struct dvb_usb_device *d = i2c_get_adapdata(adap);
401         int len, i, j, ret;
402
403         if (!d)
404                 return -ENODEV;
405         if (mutex_lock_interruptible(&d->i2c_mutex) < 0)
406                 return -EAGAIN;
407
408         for (j = 0; j < num; j++) {
409                 switch (msg[j].addr) {
410                 case(DW2102_RC_QUERY): {
411                         u8 ibuf[2];
412                         dw210x_op_rw(d->udev, 0xb8, 0, 0,
413                                         ibuf, 2, DW210X_READ_MSG);
414                         memcpy(msg[j].buf, ibuf , 2);
415                         break;
416                 }
417                 case(DW2102_VOLTAGE_CTRL): {
418                         u8 obuf[2];
419                         obuf[0] = 0x30;
420                         obuf[1] = msg[j].buf[0];
421                         dw210x_op_rw(d->udev, 0xb2, 0, 0,
422                                         obuf, 2, DW210X_WRITE_MSG);
423                         break;
424                 }
425                 /*case 0x55: cx24116
426                 case 0x6a: stv0903
427                 case 0x68: ds3000, stv0903
428                 case 0x60: ts2020, stv6110, stb6100 */
429                 default: {
430                         if (msg[j].flags == I2C_M_RD) {
431                                 /* read registers */
432                                 u8  ibuf[MAX_XFER_SIZE];
433
434                                 if (2 + msg[j].len > sizeof(ibuf)) {
435                                         warn("i2c rd: len=%d is too big!\n",
436                                              msg[j].len);
437                                         ret = -EOPNOTSUPP;
438                                         goto unlock;
439                                 }
440
441                                 dw210x_op_rw(d->udev, 0xc3,
442                                                 (msg[j].addr << 1) + 1, 0,
443                                                 ibuf, msg[j].len + 2,
444                                                 DW210X_READ_MSG);
445                                 memcpy(msg[j].buf, ibuf + 2, msg[j].len);
446                                 mdelay(10);
447                         } else if (((msg[j].buf[0] == 0xb0) &&
448                                                 (msg[j].addr == 0x68)) ||
449                                                 ((msg[j].buf[0] == 0xf7) &&
450                                                 (msg[j].addr == 0x55))) {
451                                 /* write firmware */
452                                 u8 obuf[19];
453                                 obuf[0] = msg[j].addr << 1;
454                                 obuf[1] = (msg[j].len > 15 ? 17 : msg[j].len);
455                                 obuf[2] = msg[j].buf[0];
456                                 len = msg[j].len - 1;
457                                 i = 1;
458                                 do {
459                                         memcpy(obuf + 3, msg[j].buf + i,
460                                                         (len > 16 ? 16 : len));
461                                         dw210x_op_rw(d->udev, 0xc2, 0, 0,
462                                                 obuf, (len > 16 ? 16 : len) + 3,
463                                                 DW210X_WRITE_MSG);
464                                         i += 16;
465                                         len -= 16;
466                                 } while (len > 0);
467                         } else {
468                                 /* write registers */
469                                 u8 obuf[MAX_XFER_SIZE];
470
471                                 if (2 + msg[j].len > sizeof(obuf)) {
472                                         warn("i2c wr: len=%d is too big!\n",
473                                              msg[j].len);
474                                         ret = -EOPNOTSUPP;
475                                         goto unlock;
476                                 }
477
478                                 obuf[0] = msg[j].addr << 1;
479                                 obuf[1] = msg[j].len;
480                                 memcpy(obuf + 2, msg[j].buf, msg[j].len);
481                                 dw210x_op_rw(d->udev, 0xc2, 0, 0,
482                                                 obuf, msg[j].len + 2,
483                                                 DW210X_WRITE_MSG);
484                         }
485                         break;
486                 }
487                 }
488
489         }
490         ret = num;
491
492 unlock:
493         mutex_unlock(&d->i2c_mutex);
494         return ret;
495 }
496
497 static int dw3101_i2c_transfer(struct i2c_adapter *adap, struct i2c_msg msg[],
498                                                                 int num)
499 {
500         struct dvb_usb_device *d = i2c_get_adapdata(adap);
501         int ret;
502         int i;
503
504         if (!d)
505                 return -ENODEV;
506         if (mutex_lock_interruptible(&d->i2c_mutex) < 0)
507                 return -EAGAIN;
508
509         switch (num) {
510         case 2: {
511                 /* read */
512                 /* first write first register number */
513                 u8 ibuf[MAX_XFER_SIZE], obuf[3];
514
515                 if (2 + msg[0].len != sizeof(obuf)) {
516                         warn("i2c rd: len=%d is not 1!\n",
517                              msg[0].len);
518                         ret = -EOPNOTSUPP;
519                         goto unlock;
520                 }
521                 if (2 + msg[1].len > sizeof(ibuf)) {
522                         warn("i2c rd: len=%d is too big!\n",
523                              msg[1].len);
524                         ret = -EOPNOTSUPP;
525                         goto unlock;
526                 }
527                 obuf[0] = msg[0].addr << 1;
528                 obuf[1] = msg[0].len;
529                 obuf[2] = msg[0].buf[0];
530                 dw210x_op_rw(d->udev, 0xc2, 0, 0,
531                                 obuf, msg[0].len + 2, DW210X_WRITE_MSG);
532                 /* second read registers */
533                 dw210x_op_rw(d->udev, 0xc3, 0x19 , 0,
534                                 ibuf, msg[1].len + 2, DW210X_READ_MSG);
535                 memcpy(msg[1].buf, ibuf + 2, msg[1].len);
536
537                 break;
538         }
539         case 1:
540                 switch (msg[0].addr) {
541                 case 0x60:
542                 case 0x0c: {
543                         /* write to register */
544                         u8 obuf[MAX_XFER_SIZE];
545
546                         if (2 + msg[0].len > sizeof(obuf)) {
547                                 warn("i2c wr: len=%d is too big!\n",
548                                      msg[0].len);
549                                 ret = -EOPNOTSUPP;
550                                 goto unlock;
551                         }
552                         obuf[0] = msg[0].addr << 1;
553                         obuf[1] = msg[0].len;
554                         memcpy(obuf + 2, msg[0].buf, msg[0].len);
555                         dw210x_op_rw(d->udev, 0xc2, 0, 0,
556                                         obuf, msg[0].len + 2, DW210X_WRITE_MSG);
557                         break;
558                 }
559                 case(DW2102_RC_QUERY): {
560                         u8 ibuf[2];
561                         dw210x_op_rw(d->udev, 0xb8, 0, 0,
562                                         ibuf, 2, DW210X_READ_MSG);
563                         memcpy(msg[0].buf, ibuf , 2);
564                         break;
565                 }
566                 }
567
568                 break;
569         }
570
571         for (i = 0; i < num; i++) {
572                 deb_xfer("%02x:%02x: %s ", i, msg[i].addr,
573                                 msg[i].flags == 0 ? ">>>" : "<<<");
574                 debug_dump(msg[i].buf, msg[i].len, deb_xfer);
575         }
576         ret = num;
577
578 unlock:
579         mutex_unlock(&d->i2c_mutex);
580         return ret;
581 }
582
583 static int s6x0_i2c_transfer(struct i2c_adapter *adap, struct i2c_msg msg[],
584                                                                 int num)
585 {
586         struct dvb_usb_device *d = i2c_get_adapdata(adap);
587         struct usb_device *udev;
588         int len, i, j, ret;
589
590         if (!d)
591                 return -ENODEV;
592         udev = d->udev;
593         if (mutex_lock_interruptible(&d->i2c_mutex) < 0)
594                 return -EAGAIN;
595
596         for (j = 0; j < num; j++) {
597                 switch (msg[j].addr) {
598                 case (DW2102_RC_QUERY): {
599                         u8 ibuf[5];
600                         dw210x_op_rw(d->udev, 0xb8, 0, 0,
601                                         ibuf, 5, DW210X_READ_MSG);
602                         memcpy(msg[j].buf, ibuf + 3, 2);
603                         break;
604                 }
605                 case (DW2102_VOLTAGE_CTRL): {
606                         u8 obuf[2];
607
608                         obuf[0] = 1;
609                         obuf[1] = msg[j].buf[1];/* off-on */
610                         dw210x_op_rw(d->udev, 0x8a, 0, 0,
611                                         obuf, 2, DW210X_WRITE_MSG);
612                         obuf[0] = 3;
613                         obuf[1] = msg[j].buf[0];/* 13v-18v */
614                         dw210x_op_rw(d->udev, 0x8a, 0, 0,
615                                         obuf, 2, DW210X_WRITE_MSG);
616                         break;
617                 }
618                 case (DW2102_LED_CTRL): {
619                         u8 obuf[2];
620
621                         obuf[0] = 5;
622                         obuf[1] = msg[j].buf[0];
623                         dw210x_op_rw(d->udev, 0x8a, 0, 0,
624                                         obuf, 2, DW210X_WRITE_MSG);
625                         break;
626                 }
627                 /*case 0x55: cx24116
628                 case 0x6a: stv0903
629                 case 0x68: ds3000, stv0903, rs2000
630                 case 0x60: ts2020, stv6110, stb6100
631                 case 0xa0: eeprom */
632                 default: {
633                         if (msg[j].flags == I2C_M_RD) {
634                                 /* read registers */
635                                 u8 ibuf[MAX_XFER_SIZE];
636
637                                 if (msg[j].len > sizeof(ibuf)) {
638                                         warn("i2c rd: len=%d is too big!\n",
639                                              msg[j].len);
640                                         ret = -EOPNOTSUPP;
641                                         goto unlock;
642                                 }
643
644                                 dw210x_op_rw(d->udev, 0x91, 0, 0,
645                                                 ibuf, msg[j].len,
646                                                 DW210X_READ_MSG);
647                                 memcpy(msg[j].buf, ibuf, msg[j].len);
648                                 break;
649                         } else if ((msg[j].buf[0] == 0xb0) &&
650                                                 (msg[j].addr == 0x68)) {
651                                 /* write firmware */
652                                 u8 obuf[19];
653                                 obuf[0] = (msg[j].len > 16 ?
654                                                 18 : msg[j].len + 1);
655                                 obuf[1] = msg[j].addr << 1;
656                                 obuf[2] = msg[j].buf[0];
657                                 len = msg[j].len - 1;
658                                 i = 1;
659                                 do {
660                                         memcpy(obuf + 3, msg[j].buf + i,
661                                                         (len > 16 ? 16 : len));
662                                         dw210x_op_rw(d->udev, 0x80, 0, 0,
663                                                 obuf, (len > 16 ? 16 : len) + 3,
664                                                 DW210X_WRITE_MSG);
665                                         i += 16;
666                                         len -= 16;
667                                 } while (len > 0);
668                         } else if (j < (num - 1)) {
669                                 /* write register addr before read */
670                                 u8 obuf[MAX_XFER_SIZE];
671
672                                 if (2 + msg[j].len > sizeof(obuf)) {
673                                         warn("i2c wr: len=%d is too big!\n",
674                                              msg[j].len);
675                                         ret = -EOPNOTSUPP;
676                                         goto unlock;
677                                 }
678
679                                 obuf[0] = msg[j + 1].len;
680                                 obuf[1] = (msg[j].addr << 1);
681                                 memcpy(obuf + 2, msg[j].buf, msg[j].len);
682                                 dw210x_op_rw(d->udev,
683                                                 le16_to_cpu(udev->descriptor.idProduct) ==
684                                                 0x7500 ? 0x92 : 0x90, 0, 0,
685                                                 obuf, msg[j].len + 2,
686                                                 DW210X_WRITE_MSG);
687                                 break;
688                         } else {
689                                 /* write registers */
690                                 u8 obuf[MAX_XFER_SIZE];
691
692                                 if (2 + msg[j].len > sizeof(obuf)) {
693                                         warn("i2c wr: len=%d is too big!\n",
694                                              msg[j].len);
695                                         ret = -EOPNOTSUPP;
696                                         goto unlock;
697                                 }
698                                 obuf[0] = msg[j].len + 1;
699                                 obuf[1] = (msg[j].addr << 1);
700                                 memcpy(obuf + 2, msg[j].buf, msg[j].len);
701                                 dw210x_op_rw(d->udev, 0x80, 0, 0,
702                                                 obuf, msg[j].len + 2,
703                                                 DW210X_WRITE_MSG);
704                                 break;
705                         }
706                         break;
707                 }
708                 }
709         }
710         ret = num;
711
712 unlock:
713         mutex_unlock(&d->i2c_mutex);
714         return ret;
715 }
716
717 static int su3000_i2c_transfer(struct i2c_adapter *adap, struct i2c_msg msg[],
718                                                                 int num)
719 {
720         struct dvb_usb_device *d = i2c_get_adapdata(adap);
721         struct dw2102_state *state;
722
723         if (!d)
724                 return -ENODEV;
725
726         state = d->priv;
727
728         if (mutex_lock_interruptible(&d->i2c_mutex) < 0)
729                 return -EAGAIN;
730         if (mutex_lock_interruptible(&d->data_mutex) < 0) {
731                 mutex_unlock(&d->i2c_mutex);
732                 return -EAGAIN;
733         }
734
735         switch (num) {
736         case 1:
737                 switch (msg[0].addr) {
738                 case SU3000_STREAM_CTRL:
739                         state->data[0] = msg[0].buf[0] + 0x36;
740                         state->data[1] = 3;
741                         state->data[2] = 0;
742                         if (dvb_usb_generic_rw(d, state->data, 3,
743                                         state->data, 0, 0) < 0)
744                                 err("i2c transfer failed.");
745                         break;
746                 case DW2102_RC_QUERY:
747                         state->data[0] = 0x10;
748                         if (dvb_usb_generic_rw(d, state->data, 1,
749                                         state->data, 2, 0) < 0)
750                                 err("i2c transfer failed.");
751                         msg[0].buf[1] = state->data[0];
752                         msg[0].buf[0] = state->data[1];
753                         break;
754                 default:
755                         if (3 + msg[0].len > sizeof(state->data)) {
756                                 warn("i2c wr: len=%d is too big!\n",
757                                      msg[0].len);
758                                 num = -EOPNOTSUPP;
759                                 break;
760                         }
761
762                         /* always i2c write*/
763                         state->data[0] = 0x08;
764                         state->data[1] = msg[0].addr;
765                         state->data[2] = msg[0].len;
766
767                         memcpy(&state->data[3], msg[0].buf, msg[0].len);
768
769                         if (dvb_usb_generic_rw(d, state->data, msg[0].len + 3,
770                                                 state->data, 1, 0) < 0)
771                                 err("i2c transfer failed.");
772
773                 }
774                 break;
775         case 2:
776                 /* always i2c read */
777                 if (4 + msg[0].len > sizeof(state->data)) {
778                         warn("i2c rd: len=%d is too big!\n",
779                              msg[0].len);
780                         num = -EOPNOTSUPP;
781                         break;
782                 }
783                 if (1 + msg[1].len > sizeof(state->data)) {
784                         warn("i2c rd: len=%d is too big!\n",
785                              msg[1].len);
786                         num = -EOPNOTSUPP;
787                         break;
788                 }
789
790                 state->data[0] = 0x09;
791                 state->data[1] = msg[0].len;
792                 state->data[2] = msg[1].len;
793                 state->data[3] = msg[0].addr;
794                 memcpy(&state->data[4], msg[0].buf, msg[0].len);
795
796                 if (dvb_usb_generic_rw(d, state->data, msg[0].len + 4,
797                                         state->data, msg[1].len + 1, 0) < 0)
798                         err("i2c transfer failed.");
799
800                 memcpy(msg[1].buf, &state->data[1], msg[1].len);
801                 break;
802         default:
803                 warn("more than 2 i2c messages at a time is not handled yet.");
804                 break;
805         }
806         mutex_unlock(&d->data_mutex);
807         mutex_unlock(&d->i2c_mutex);
808         return num;
809 }
810
811 static u32 dw210x_i2c_func(struct i2c_adapter *adapter)
812 {
813         return I2C_FUNC_I2C;
814 }
815
816 static struct i2c_algorithm dw2102_i2c_algo = {
817         .master_xfer = dw2102_i2c_transfer,
818         .functionality = dw210x_i2c_func,
819 };
820
821 static struct i2c_algorithm dw2102_serit_i2c_algo = {
822         .master_xfer = dw2102_serit_i2c_transfer,
823         .functionality = dw210x_i2c_func,
824 };
825
826 static struct i2c_algorithm dw2102_earda_i2c_algo = {
827         .master_xfer = dw2102_earda_i2c_transfer,
828         .functionality = dw210x_i2c_func,
829 };
830
831 static struct i2c_algorithm dw2104_i2c_algo = {
832         .master_xfer = dw2104_i2c_transfer,
833         .functionality = dw210x_i2c_func,
834 };
835
836 static struct i2c_algorithm dw3101_i2c_algo = {
837         .master_xfer = dw3101_i2c_transfer,
838         .functionality = dw210x_i2c_func,
839 };
840
841 static struct i2c_algorithm s6x0_i2c_algo = {
842         .master_xfer = s6x0_i2c_transfer,
843         .functionality = dw210x_i2c_func,
844 };
845
846 static struct i2c_algorithm su3000_i2c_algo = {
847         .master_xfer = su3000_i2c_transfer,
848         .functionality = dw210x_i2c_func,
849 };
850
851 static int dw210x_read_mac_address(struct dvb_usb_device *d, u8 mac[6])
852 {
853         int i;
854         u8 ibuf[] = {0, 0};
855         u8 eeprom[256], eepromline[16];
856
857         for (i = 0; i < 256; i++) {
858                 if (dw210x_op_rw(d->udev, 0xb6, 0xa0 , i, ibuf, 2, DW210X_READ_MSG) < 0) {
859                         err("read eeprom failed.");
860                         return -1;
861                 } else {
862                         eepromline[i%16] = ibuf[0];
863                         eeprom[i] = ibuf[0];
864                 }
865                 if ((i % 16) == 15) {
866                         deb_xfer("%02x: ", i - 15);
867                         debug_dump(eepromline, 16, deb_xfer);
868                 }
869         }
870
871         memcpy(mac, eeprom + 8, 6);
872         return 0;
873 };
874
875 static int s6x0_read_mac_address(struct dvb_usb_device *d, u8 mac[6])
876 {
877         int i, ret;
878         u8 ibuf[] = { 0 }, obuf[] = { 0 };
879         u8 eeprom[256], eepromline[16];
880         struct i2c_msg msg[] = {
881                 {
882                         .addr = 0xa0 >> 1,
883                         .flags = 0,
884                         .buf = obuf,
885                         .len = 1,
886                 }, {
887                         .addr = 0xa0 >> 1,
888                         .flags = I2C_M_RD,
889                         .buf = ibuf,
890                         .len = 1,
891                 }
892         };
893
894         for (i = 0; i < 256; i++) {
895                 obuf[0] = i;
896                 ret = s6x0_i2c_transfer(&d->i2c_adap, msg, 2);
897                 if (ret != 2) {
898                         err("read eeprom failed.");
899                         return -1;
900                 } else {
901                         eepromline[i % 16] = ibuf[0];
902                         eeprom[i] = ibuf[0];
903                 }
904
905                 if ((i % 16) == 15) {
906                         deb_xfer("%02x: ", i - 15);
907                         debug_dump(eepromline, 16, deb_xfer);
908                 }
909         }
910
911         memcpy(mac, eeprom + 16, 6);
912         return 0;
913 };
914
915 static int su3000_streaming_ctrl(struct dvb_usb_adapter *adap, int onoff)
916 {
917         static u8 command_start[] = {0x00};
918         static u8 command_stop[] = {0x01};
919         struct i2c_msg msg = {
920                 .addr = SU3000_STREAM_CTRL,
921                 .flags = 0,
922                 .buf = onoff ? command_start : command_stop,
923                 .len = 1
924         };
925
926         i2c_transfer(&adap->dev->i2c_adap, &msg, 1);
927
928         return 0;
929 }
930
931 static int su3000_power_ctrl(struct dvb_usb_device *d, int i)
932 {
933         struct dw2102_state *state = (struct dw2102_state *)d->priv;
934         int ret = 0;
935
936         info("%s: %d, initialized %d", __func__, i, state->initialized);
937
938         if (i && !state->initialized) {
939                 mutex_lock(&d->data_mutex);
940
941                 state->data[0] = 0xde;
942                 state->data[1] = 0;
943
944                 state->initialized = 1;
945                 /* reset board */
946                 ret = dvb_usb_generic_rw(d, state->data, 2, NULL, 0, 0);
947                 mutex_unlock(&d->data_mutex);
948         }
949
950         return ret;
951 }
952
953 static int su3000_read_mac_address(struct dvb_usb_device *d, u8 mac[6])
954 {
955         int i;
956         u8 obuf[] = { 0x1f, 0xf0 };
957         u8 ibuf[] = { 0 };
958         struct i2c_msg msg[] = {
959                 {
960                         .addr = 0x51,
961                         .flags = 0,
962                         .buf = obuf,
963                         .len = 2,
964                 }, {
965                         .addr = 0x51,
966                         .flags = I2C_M_RD,
967                         .buf = ibuf,
968                         .len = 1,
969
970                 }
971         };
972
973         for (i = 0; i < 6; i++) {
974                 obuf[1] = 0xf0 + i;
975                 if (i2c_transfer(&d->i2c_adap, msg, 2) != 2)
976                         return -1;
977                 else
978                         mac[i] = ibuf[0];
979         }
980
981         return 0;
982 }
983
984 static int su3000_identify_state(struct usb_device *udev,
985                                  struct dvb_usb_device_properties *props,
986                                  struct dvb_usb_device_description **desc,
987                                  int *cold)
988 {
989         info("%s", __func__);
990
991         *cold = 0;
992         return 0;
993 }
994
995 static int dw210x_set_voltage(struct dvb_frontend *fe,
996                               enum fe_sec_voltage voltage)
997 {
998         static u8 command_13v[] = {0x00, 0x01};
999         static u8 command_18v[] = {0x01, 0x01};
1000         static u8 command_off[] = {0x00, 0x00};
1001         struct i2c_msg msg = {
1002                 .addr = DW2102_VOLTAGE_CTRL,
1003                 .flags = 0,
1004                 .buf = command_off,
1005                 .len = 2,
1006         };
1007
1008         struct dvb_usb_adapter *udev_adap =
1009                 (struct dvb_usb_adapter *)(fe->dvb->priv);
1010         if (voltage == SEC_VOLTAGE_18)
1011                 msg.buf = command_18v;
1012         else if (voltage == SEC_VOLTAGE_13)
1013                 msg.buf = command_13v;
1014
1015         i2c_transfer(&udev_adap->dev->i2c_adap, &msg, 1);
1016
1017         return 0;
1018 }
1019
1020 static int s660_set_voltage(struct dvb_frontend *fe,
1021                             enum fe_sec_voltage voltage)
1022 {
1023         struct dvb_usb_adapter *d =
1024                 (struct dvb_usb_adapter *)(fe->dvb->priv);
1025         struct dw2102_state *st = (struct dw2102_state *)d->dev->priv;
1026
1027         dw210x_set_voltage(fe, voltage);
1028         if (st->old_set_voltage)
1029                 st->old_set_voltage(fe, voltage);
1030
1031         return 0;
1032 }
1033
1034 static void dw210x_led_ctrl(struct dvb_frontend *fe, int offon)
1035 {
1036         static u8 led_off[] = { 0 };
1037         static u8 led_on[] = { 1 };
1038         struct i2c_msg msg = {
1039                 .addr = DW2102_LED_CTRL,
1040                 .flags = 0,
1041                 .buf = led_off,
1042                 .len = 1
1043         };
1044         struct dvb_usb_adapter *udev_adap =
1045                 (struct dvb_usb_adapter *)(fe->dvb->priv);
1046
1047         if (offon)
1048                 msg.buf = led_on;
1049         i2c_transfer(&udev_adap->dev->i2c_adap, &msg, 1);
1050 }
1051
1052 static int tt_s2_4600_read_status(struct dvb_frontend *fe,
1053                                   enum fe_status *status)
1054 {
1055         struct dvb_usb_adapter *d =
1056                 (struct dvb_usb_adapter *)(fe->dvb->priv);
1057         struct dw2102_state *st = (struct dw2102_state *)d->dev->priv;
1058         int ret;
1059
1060         ret = st->fe_read_status(fe, status);
1061
1062         /* resync slave fifo when signal change from unlock to lock */
1063         if ((*status & FE_HAS_LOCK) && (!st->last_lock))
1064                 su3000_streaming_ctrl(d, 1);
1065
1066         st->last_lock = (*status & FE_HAS_LOCK) ? 1 : 0;
1067         return ret;
1068 }
1069
1070 static struct stv0299_config sharp_z0194a_config = {
1071         .demod_address = 0x68,
1072         .inittab = sharp_z0194a_inittab,
1073         .mclk = 88000000UL,
1074         .invert = 1,
1075         .skip_reinit = 0,
1076         .lock_output = STV0299_LOCKOUTPUT_1,
1077         .volt13_op0_op1 = STV0299_VOLT13_OP1,
1078         .min_delay_ms = 100,
1079         .set_symbol_rate = sharp_z0194a_set_symbol_rate,
1080 };
1081
1082 static struct cx24116_config dw2104_config = {
1083         .demod_address = 0x55,
1084         .mpg_clk_pos_pol = 0x01,
1085 };
1086
1087 static struct si21xx_config serit_sp1511lhb_config = {
1088         .demod_address = 0x68,
1089         .min_delay_ms = 100,
1090
1091 };
1092
1093 static struct tda10023_config dw3101_tda10023_config = {
1094         .demod_address = 0x0c,
1095         .invert = 1,
1096 };
1097
1098 static struct mt312_config zl313_config = {
1099         .demod_address = 0x0e,
1100 };
1101
1102 static struct ds3000_config dw2104_ds3000_config = {
1103         .demod_address = 0x68,
1104 };
1105
1106 static struct ts2020_config dw2104_ts2020_config = {
1107         .tuner_address = 0x60,
1108         .clk_out_div = 1,
1109         .frequency_div = 1060000,
1110 };
1111
1112 static struct ds3000_config s660_ds3000_config = {
1113         .demod_address = 0x68,
1114         .ci_mode = 1,
1115         .set_lock_led = dw210x_led_ctrl,
1116 };
1117
1118 static struct ts2020_config s660_ts2020_config = {
1119         .tuner_address = 0x60,
1120         .clk_out_div = 1,
1121         .frequency_div = 1146000,
1122 };
1123
1124 static struct stv0900_config dw2104a_stv0900_config = {
1125         .demod_address = 0x6a,
1126         .demod_mode = 0,
1127         .xtal = 27000000,
1128         .clkmode = 3,/* 0-CLKI, 2-XTALI, else AUTO */
1129         .diseqc_mode = 2,/* 2/3 PWM */
1130         .tun1_maddress = 0,/* 0x60 */
1131         .tun1_adc = 0,/* 2 Vpp */
1132         .path1_mode = 3,
1133 };
1134
1135 static struct stb6100_config dw2104a_stb6100_config = {
1136         .tuner_address = 0x60,
1137         .refclock = 27000000,
1138 };
1139
1140 static struct stv0900_config dw2104_stv0900_config = {
1141         .demod_address = 0x68,
1142         .demod_mode = 0,
1143         .xtal = 8000000,
1144         .clkmode = 3,
1145         .diseqc_mode = 2,
1146         .tun1_maddress = 0,
1147         .tun1_adc = 1,/* 1 Vpp */
1148         .path1_mode = 3,
1149 };
1150
1151 static struct stv6110_config dw2104_stv6110_config = {
1152         .i2c_address = 0x60,
1153         .mclk = 16000000,
1154         .clk_div = 1,
1155 };
1156
1157 static struct stv0900_config prof_7500_stv0900_config = {
1158         .demod_address = 0x6a,
1159         .demod_mode = 0,
1160         .xtal = 27000000,
1161         .clkmode = 3,/* 0-CLKI, 2-XTALI, else AUTO */
1162         .diseqc_mode = 2,/* 2/3 PWM */
1163         .tun1_maddress = 0,/* 0x60 */
1164         .tun1_adc = 0,/* 2 Vpp */
1165         .path1_mode = 3,
1166         .tun1_type = 3,
1167         .set_lock_led = dw210x_led_ctrl,
1168 };
1169
1170 static struct ds3000_config su3000_ds3000_config = {
1171         .demod_address = 0x68,
1172         .ci_mode = 1,
1173         .set_lock_led = dw210x_led_ctrl,
1174 };
1175
1176 static struct cxd2820r_config cxd2820r_config = {
1177         .i2c_address = 0x6c, /* (0xd8 >> 1) */
1178         .ts_mode = 0x38,
1179         .ts_clock_inv = 1,
1180 };
1181
1182 static struct tda18271_config tda18271_config = {
1183         .output_opt = TDA18271_OUTPUT_LT_OFF,
1184         .gate = TDA18271_GATE_DIGITAL,
1185 };
1186
1187 static u8 m88rs2000_inittab[] = {
1188         DEMOD_WRITE, 0x9a, 0x30,
1189         DEMOD_WRITE, 0x00, 0x01,
1190         WRITE_DELAY, 0x19, 0x00,
1191         DEMOD_WRITE, 0x00, 0x00,
1192         DEMOD_WRITE, 0x9a, 0xb0,
1193         DEMOD_WRITE, 0x81, 0xc1,
1194         DEMOD_WRITE, 0x81, 0x81,
1195         DEMOD_WRITE, 0x86, 0xc6,
1196         DEMOD_WRITE, 0x9a, 0x30,
1197         DEMOD_WRITE, 0xf0, 0x80,
1198         DEMOD_WRITE, 0xf1, 0xbf,
1199         DEMOD_WRITE, 0xb0, 0x45,
1200         DEMOD_WRITE, 0xb2, 0x01,
1201         DEMOD_WRITE, 0x9a, 0xb0,
1202         0xff, 0xaa, 0xff
1203 };
1204
1205 static struct m88rs2000_config s421_m88rs2000_config = {
1206         .demod_addr = 0x68,
1207         .inittab = m88rs2000_inittab,
1208 };
1209
1210 static int dw2104_frontend_attach(struct dvb_usb_adapter *d)
1211 {
1212         struct dvb_tuner_ops *tuner_ops = NULL;
1213
1214         if (demod_probe & 4) {
1215                 d->fe_adap[0].fe = dvb_attach(stv0900_attach, &dw2104a_stv0900_config,
1216                                 &d->dev->i2c_adap, 0);
1217                 if (d->fe_adap[0].fe != NULL) {
1218                         if (dvb_attach(stb6100_attach, d->fe_adap[0].fe,
1219                                         &dw2104a_stb6100_config,
1220                                         &d->dev->i2c_adap)) {
1221                                 tuner_ops = &d->fe_adap[0].fe->ops.tuner_ops;
1222                                 tuner_ops->set_frequency = stb6100_set_freq;
1223                                 tuner_ops->get_frequency = stb6100_get_freq;
1224                                 tuner_ops->set_bandwidth = stb6100_set_bandw;
1225                                 tuner_ops->get_bandwidth = stb6100_get_bandw;
1226                                 d->fe_adap[0].fe->ops.set_voltage = dw210x_set_voltage;
1227                                 info("Attached STV0900+STB6100!");
1228                                 return 0;
1229                         }
1230                 }
1231         }
1232
1233         if (demod_probe & 2) {
1234                 d->fe_adap[0].fe = dvb_attach(stv0900_attach, &dw2104_stv0900_config,
1235                                 &d->dev->i2c_adap, 0);
1236                 if (d->fe_adap[0].fe != NULL) {
1237                         if (dvb_attach(stv6110_attach, d->fe_adap[0].fe,
1238                                         &dw2104_stv6110_config,
1239                                         &d->dev->i2c_adap)) {
1240                                 d->fe_adap[0].fe->ops.set_voltage = dw210x_set_voltage;
1241                                 info("Attached STV0900+STV6110A!");
1242                                 return 0;
1243                         }
1244                 }
1245         }
1246
1247         if (demod_probe & 1) {
1248                 d->fe_adap[0].fe = dvb_attach(cx24116_attach, &dw2104_config,
1249                                 &d->dev->i2c_adap);
1250                 if (d->fe_adap[0].fe != NULL) {
1251                         d->fe_adap[0].fe->ops.set_voltage = dw210x_set_voltage;
1252                         info("Attached cx24116!");
1253                         return 0;
1254                 }
1255         }
1256
1257         d->fe_adap[0].fe = dvb_attach(ds3000_attach, &dw2104_ds3000_config,
1258                         &d->dev->i2c_adap);
1259         if (d->fe_adap[0].fe != NULL) {
1260                 dvb_attach(ts2020_attach, d->fe_adap[0].fe,
1261                         &dw2104_ts2020_config, &d->dev->i2c_adap);
1262                 d->fe_adap[0].fe->ops.set_voltage = dw210x_set_voltage;
1263                 info("Attached DS3000!");
1264                 return 0;
1265         }
1266
1267         return -EIO;
1268 }
1269
1270 static struct dvb_usb_device_properties dw2102_properties;
1271 static struct dvb_usb_device_properties dw2104_properties;
1272 static struct dvb_usb_device_properties s6x0_properties;
1273
1274 static int dw2102_frontend_attach(struct dvb_usb_adapter *d)
1275 {
1276         if (dw2102_properties.i2c_algo == &dw2102_serit_i2c_algo) {
1277                 /*dw2102_properties.adapter->tuner_attach = NULL;*/
1278                 d->fe_adap[0].fe = dvb_attach(si21xx_attach, &serit_sp1511lhb_config,
1279                                         &d->dev->i2c_adap);
1280                 if (d->fe_adap[0].fe != NULL) {
1281                         d->fe_adap[0].fe->ops.set_voltage = dw210x_set_voltage;
1282                         info("Attached si21xx!");
1283                         return 0;
1284                 }
1285         }
1286
1287         if (dw2102_properties.i2c_algo == &dw2102_earda_i2c_algo) {
1288                 d->fe_adap[0].fe = dvb_attach(stv0288_attach, &earda_config,
1289                                         &d->dev->i2c_adap);
1290                 if (d->fe_adap[0].fe != NULL) {
1291                         if (dvb_attach(stb6000_attach, d->fe_adap[0].fe, 0x61,
1292                                         &d->dev->i2c_adap)) {
1293                                 d->fe_adap[0].fe->ops.set_voltage = dw210x_set_voltage;
1294                                 info("Attached stv0288!");
1295                                 return 0;
1296                         }
1297                 }
1298         }
1299
1300         if (dw2102_properties.i2c_algo == &dw2102_i2c_algo) {
1301                 /*dw2102_properties.adapter->tuner_attach = dw2102_tuner_attach;*/
1302                 d->fe_adap[0].fe = dvb_attach(stv0299_attach, &sharp_z0194a_config,
1303                                         &d->dev->i2c_adap);
1304                 if (d->fe_adap[0].fe != NULL) {
1305                         d->fe_adap[0].fe->ops.set_voltage = dw210x_set_voltage;
1306                         info("Attached stv0299!");
1307                         return 0;
1308                 }
1309         }
1310         return -EIO;
1311 }
1312
1313 static int dw3101_frontend_attach(struct dvb_usb_adapter *d)
1314 {
1315         d->fe_adap[0].fe = dvb_attach(tda10023_attach, &dw3101_tda10023_config,
1316                                 &d->dev->i2c_adap, 0x48);
1317         if (d->fe_adap[0].fe != NULL) {
1318                 info("Attached tda10023!");
1319                 return 0;
1320         }
1321         return -EIO;
1322 }
1323
1324 static int zl100313_frontend_attach(struct dvb_usb_adapter *d)
1325 {
1326         d->fe_adap[0].fe = dvb_attach(mt312_attach, &zl313_config,
1327                         &d->dev->i2c_adap);
1328         if (d->fe_adap[0].fe != NULL) {
1329                 if (dvb_attach(zl10039_attach, d->fe_adap[0].fe, 0x60,
1330                                 &d->dev->i2c_adap)) {
1331                         d->fe_adap[0].fe->ops.set_voltage = dw210x_set_voltage;
1332                         info("Attached zl100313+zl10039!");
1333                         return 0;
1334                 }
1335         }
1336
1337         return -EIO;
1338 }
1339
1340 static int stv0288_frontend_attach(struct dvb_usb_adapter *d)
1341 {
1342         u8 obuf[] = {7, 1};
1343
1344         d->fe_adap[0].fe = dvb_attach(stv0288_attach, &earda_config,
1345                         &d->dev->i2c_adap);
1346
1347         if (d->fe_adap[0].fe == NULL)
1348                 return -EIO;
1349
1350         if (NULL == dvb_attach(stb6000_attach, d->fe_adap[0].fe, 0x61, &d->dev->i2c_adap))
1351                 return -EIO;
1352
1353         d->fe_adap[0].fe->ops.set_voltage = dw210x_set_voltage;
1354
1355         dw210x_op_rw(d->dev->udev, 0x8a, 0, 0, obuf, 2, DW210X_WRITE_MSG);
1356
1357         info("Attached stv0288+stb6000!");
1358
1359         return 0;
1360
1361 }
1362
1363 static int ds3000_frontend_attach(struct dvb_usb_adapter *d)
1364 {
1365         struct dw2102_state *st = d->dev->priv;
1366         u8 obuf[] = {7, 1};
1367
1368         d->fe_adap[0].fe = dvb_attach(ds3000_attach, &s660_ds3000_config,
1369                         &d->dev->i2c_adap);
1370
1371         if (d->fe_adap[0].fe == NULL)
1372                 return -EIO;
1373
1374         dvb_attach(ts2020_attach, d->fe_adap[0].fe, &s660_ts2020_config,
1375                 &d->dev->i2c_adap);
1376
1377         st->old_set_voltage = d->fe_adap[0].fe->ops.set_voltage;
1378         d->fe_adap[0].fe->ops.set_voltage = s660_set_voltage;
1379
1380         dw210x_op_rw(d->dev->udev, 0x8a, 0, 0, obuf, 2, DW210X_WRITE_MSG);
1381
1382         info("Attached ds3000+ts2020!");
1383
1384         return 0;
1385 }
1386
1387 static int prof_7500_frontend_attach(struct dvb_usb_adapter *d)
1388 {
1389         u8 obuf[] = {7, 1};
1390
1391         d->fe_adap[0].fe = dvb_attach(stv0900_attach, &prof_7500_stv0900_config,
1392                                         &d->dev->i2c_adap, 0);
1393         if (d->fe_adap[0].fe == NULL)
1394                 return -EIO;
1395
1396         d->fe_adap[0].fe->ops.set_voltage = dw210x_set_voltage;
1397
1398         dw210x_op_rw(d->dev->udev, 0x8a, 0, 0, obuf, 2, DW210X_WRITE_MSG);
1399
1400         info("Attached STV0900+STB6100A!");
1401
1402         return 0;
1403 }
1404
1405 static int su3000_frontend_attach(struct dvb_usb_adapter *adap)
1406 {
1407         struct dvb_usb_device *d = adap->dev;
1408         struct dw2102_state *state = d->priv;
1409
1410         mutex_lock(&d->data_mutex);
1411
1412         state->data[0] = 0xe;
1413         state->data[1] = 0x80;
1414         state->data[2] = 0;
1415
1416         if (dvb_usb_generic_rw(d, state->data, 3, state->data, 1, 0) < 0)
1417                 err("command 0x0e transfer failed.");
1418
1419         state->data[0] = 0xe;
1420         state->data[1] = 0x02;
1421         state->data[2] = 1;
1422
1423         if (dvb_usb_generic_rw(d, state->data, 3, state->data, 1, 0) < 0)
1424                 err("command 0x0e transfer failed.");
1425         msleep(300);
1426
1427         state->data[0] = 0xe;
1428         state->data[1] = 0x83;
1429         state->data[2] = 0;
1430
1431         if (dvb_usb_generic_rw(d, state->data, 3, state->data, 1, 0) < 0)
1432                 err("command 0x0e transfer failed.");
1433
1434         state->data[0] = 0xe;
1435         state->data[1] = 0x83;
1436         state->data[2] = 1;
1437
1438         if (dvb_usb_generic_rw(d, state->data, 3, state->data, 1, 0) < 0)
1439                 err("command 0x0e transfer failed.");
1440
1441         state->data[0] = 0x51;
1442
1443         if (dvb_usb_generic_rw(d, state->data, 1, state->data, 1, 0) < 0)
1444                 err("command 0x51 transfer failed.");
1445
1446         mutex_unlock(&d->data_mutex);
1447
1448         adap->fe_adap[0].fe = dvb_attach(ds3000_attach, &su3000_ds3000_config,
1449                                         &d->i2c_adap);
1450         if (adap->fe_adap[0].fe == NULL)
1451                 return -EIO;
1452
1453         if (dvb_attach(ts2020_attach, adap->fe_adap[0].fe,
1454                                 &dw2104_ts2020_config,
1455                                 &d->i2c_adap)) {
1456                 info("Attached DS3000/TS2020!");
1457                 return 0;
1458         }
1459
1460         info("Failed to attach DS3000/TS2020!");
1461         return -EIO;
1462 }
1463
1464 static int t220_frontend_attach(struct dvb_usb_adapter *adap)
1465 {
1466         struct dvb_usb_device *d = adap->dev;
1467         struct dw2102_state *state = d->priv;
1468
1469         mutex_lock(&d->data_mutex);
1470
1471         state->data[0] = 0xe;
1472         state->data[1] = 0x87;
1473         state->data[2] = 0x0;
1474
1475         if (dvb_usb_generic_rw(d, state->data, 3, state->data, 1, 0) < 0)
1476                 err("command 0x0e transfer failed.");
1477
1478         state->data[0] = 0xe;
1479         state->data[1] = 0x86;
1480         state->data[2] = 1;
1481
1482         if (dvb_usb_generic_rw(d, state->data, 3, state->data, 1, 0) < 0)
1483                 err("command 0x0e transfer failed.");
1484
1485         state->data[0] = 0xe;
1486         state->data[1] = 0x80;
1487         state->data[2] = 0;
1488
1489         if (dvb_usb_generic_rw(d, state->data, 3, state->data, 1, 0) < 0)
1490                 err("command 0x0e transfer failed.");
1491
1492         msleep(50);
1493
1494         state->data[0] = 0xe;
1495         state->data[1] = 0x80;
1496         state->data[2] = 1;
1497
1498         if (dvb_usb_generic_rw(d, state->data, 3, state->data, 1, 0) < 0)
1499                 err("command 0x0e transfer failed.");
1500
1501         state->data[0] = 0x51;
1502
1503         if (dvb_usb_generic_rw(d, state->data, 1, state->data, 1, 0) < 0)
1504                 err("command 0x51 transfer failed.");
1505
1506         mutex_unlock(&d->data_mutex);
1507
1508         adap->fe_adap[0].fe = dvb_attach(cxd2820r_attach, &cxd2820r_config,
1509                                         &d->i2c_adap, NULL);
1510         if (adap->fe_adap[0].fe != NULL) {
1511                 if (dvb_attach(tda18271_attach, adap->fe_adap[0].fe, 0x60,
1512                                         &d->i2c_adap, &tda18271_config)) {
1513                         info("Attached TDA18271HD/CXD2820R!");
1514                         return 0;
1515                 }
1516         }
1517
1518         info("Failed to attach TDA18271HD/CXD2820R!");
1519         return -EIO;
1520 }
1521
1522 static int m88rs2000_frontend_attach(struct dvb_usb_adapter *adap)
1523 {
1524         struct dvb_usb_device *d = adap->dev;
1525         struct dw2102_state *state = d->priv;
1526
1527         mutex_lock(&d->data_mutex);
1528
1529         state->data[0] = 0x51;
1530
1531         if (dvb_usb_generic_rw(d, state->data, 1, state->data, 1, 0) < 0)
1532                 err("command 0x51 transfer failed.");
1533
1534         mutex_unlock(&d->data_mutex);
1535
1536         adap->fe_adap[0].fe = dvb_attach(m88rs2000_attach,
1537                                         &s421_m88rs2000_config,
1538                                         &d->i2c_adap);
1539
1540         if (adap->fe_adap[0].fe == NULL)
1541                 return -EIO;
1542
1543         if (dvb_attach(ts2020_attach, adap->fe_adap[0].fe,
1544                                 &dw2104_ts2020_config,
1545                                 &d->i2c_adap)) {
1546                 info("Attached RS2000/TS2020!");
1547                 return 0;
1548         }
1549
1550         info("Failed to attach RS2000/TS2020!");
1551         return -EIO;
1552 }
1553
1554 static int tt_s2_4600_frontend_attach(struct dvb_usb_adapter *adap)
1555 {
1556         struct dvb_usb_device *d = adap->dev;
1557         struct dw2102_state *state = d->priv;
1558         struct i2c_adapter *i2c_adapter;
1559         struct i2c_client *client;
1560         struct i2c_board_info board_info;
1561         struct m88ds3103_platform_data m88ds3103_pdata = {};
1562         struct ts2020_config ts2020_config = {};
1563
1564         mutex_lock(&d->data_mutex);
1565
1566         state->data[0] = 0xe;
1567         state->data[1] = 0x80;
1568         state->data[2] = 0x0;
1569
1570         if (dvb_usb_generic_rw(d, state->data, 3, state->data, 1, 0) < 0)
1571                 err("command 0x0e transfer failed.");
1572
1573         state->data[0] = 0xe;
1574         state->data[1] = 0x02;
1575         state->data[2] = 1;
1576
1577         if (dvb_usb_generic_rw(d, state->data, 3, state->data, 1, 0) < 0)
1578                 err("command 0x0e transfer failed.");
1579         msleep(300);
1580
1581         state->data[0] = 0xe;
1582         state->data[1] = 0x83;
1583         state->data[2] = 0;
1584
1585         if (dvb_usb_generic_rw(d, state->data, 3, state->data, 1, 0) < 0)
1586                 err("command 0x0e transfer failed.");
1587
1588         state->data[0] = 0xe;
1589         state->data[1] = 0x83;
1590         state->data[2] = 1;
1591
1592         if (dvb_usb_generic_rw(d, state->data, 3, state->data, 1, 0) < 0)
1593                 err("command 0x0e transfer failed.");
1594
1595         state->data[0] = 0x51;
1596
1597         if (dvb_usb_generic_rw(d, state->data, 1, state->data, 1, 0) < 0)
1598                 err("command 0x51 transfer failed.");
1599
1600         mutex_unlock(&d->data_mutex);
1601
1602         /* attach demod */
1603         m88ds3103_pdata.clk = 27000000;
1604         m88ds3103_pdata.i2c_wr_max = 33;
1605         m88ds3103_pdata.ts_mode = M88DS3103_TS_CI;
1606         m88ds3103_pdata.ts_clk = 16000;
1607         m88ds3103_pdata.ts_clk_pol = 0;
1608         m88ds3103_pdata.spec_inv = 0;
1609         m88ds3103_pdata.agc = 0x99;
1610         m88ds3103_pdata.agc_inv = 0;
1611         m88ds3103_pdata.clk_out = M88DS3103_CLOCK_OUT_ENABLED;
1612         m88ds3103_pdata.envelope_mode = 0;
1613         m88ds3103_pdata.lnb_hv_pol = 1;
1614         m88ds3103_pdata.lnb_en_pol = 0;
1615         memset(&board_info, 0, sizeof(board_info));
1616         strlcpy(board_info.type, "m88ds3103", I2C_NAME_SIZE);
1617         board_info.addr = 0x68;
1618         board_info.platform_data = &m88ds3103_pdata;
1619         request_module("m88ds3103");
1620         client = i2c_new_device(&d->i2c_adap, &board_info);
1621         if (client == NULL || client->dev.driver == NULL)
1622                 return -ENODEV;
1623         if (!try_module_get(client->dev.driver->owner)) {
1624                 i2c_unregister_device(client);
1625                 return -ENODEV;
1626         }
1627         adap->fe_adap[0].fe = m88ds3103_pdata.get_dvb_frontend(client);
1628         i2c_adapter = m88ds3103_pdata.get_i2c_adapter(client);
1629
1630         state->i2c_client_demod = client;
1631
1632         /* attach tuner */
1633         ts2020_config.fe = adap->fe_adap[0].fe;
1634         memset(&board_info, 0, sizeof(board_info));
1635         strlcpy(board_info.type, "ts2022", I2C_NAME_SIZE);
1636         board_info.addr = 0x60;
1637         board_info.platform_data = &ts2020_config;
1638         request_module("ts2020");
1639         client = i2c_new_device(i2c_adapter, &board_info);
1640
1641         if (client == NULL || client->dev.driver == NULL) {
1642                 dvb_frontend_detach(adap->fe_adap[0].fe);
1643                 return -ENODEV;
1644         }
1645
1646         if (!try_module_get(client->dev.driver->owner)) {
1647                 i2c_unregister_device(client);
1648                 dvb_frontend_detach(adap->fe_adap[0].fe);
1649                 return -ENODEV;
1650         }
1651
1652         /* delegate signal strength measurement to tuner */
1653         adap->fe_adap[0].fe->ops.read_signal_strength =
1654                         adap->fe_adap[0].fe->ops.tuner_ops.get_rf_strength;
1655
1656         state->i2c_client_tuner = client;
1657
1658         /* hook fe: need to resync the slave fifo when signal locks */
1659         state->fe_read_status = adap->fe_adap[0].fe->ops.read_status;
1660         adap->fe_adap[0].fe->ops.read_status = tt_s2_4600_read_status;
1661
1662         state->last_lock = 0;
1663
1664         return 0;
1665 }
1666
1667 static int dw2102_tuner_attach(struct dvb_usb_adapter *adap)
1668 {
1669         dvb_attach(dvb_pll_attach, adap->fe_adap[0].fe, 0x60,
1670                 &adap->dev->i2c_adap, DVB_PLL_OPERA1);
1671         return 0;
1672 }
1673
1674 static int dw3101_tuner_attach(struct dvb_usb_adapter *adap)
1675 {
1676         dvb_attach(dvb_pll_attach, adap->fe_adap[0].fe, 0x60,
1677                 &adap->dev->i2c_adap, DVB_PLL_TUA6034);
1678
1679         return 0;
1680 }
1681
1682 static int dw2102_rc_query(struct dvb_usb_device *d)
1683 {
1684         u8 key[2];
1685         struct i2c_msg msg = {
1686                 .addr = DW2102_RC_QUERY,
1687                 .flags = I2C_M_RD,
1688                 .buf = key,
1689                 .len = 2
1690         };
1691
1692         if (d->props.i2c_algo->master_xfer(&d->i2c_adap, &msg, 1) == 1) {
1693                 if (msg.buf[0] != 0xff) {
1694                         deb_rc("%s: rc code: %x, %x\n",
1695                                         __func__, key[0], key[1]);
1696                         rc_keydown(d->rc_dev, RC_PROTO_UNKNOWN, key[0], 0);
1697                 }
1698         }
1699
1700         return 0;
1701 }
1702
1703 static int prof_rc_query(struct dvb_usb_device *d)
1704 {
1705         u8 key[2];
1706         struct i2c_msg msg = {
1707                 .addr = DW2102_RC_QUERY,
1708                 .flags = I2C_M_RD,
1709                 .buf = key,
1710                 .len = 2
1711         };
1712
1713         if (d->props.i2c_algo->master_xfer(&d->i2c_adap, &msg, 1) == 1) {
1714                 if (msg.buf[0] != 0xff) {
1715                         deb_rc("%s: rc code: %x, %x\n",
1716                                         __func__, key[0], key[1]);
1717                         rc_keydown(d->rc_dev, RC_PROTO_UNKNOWN, key[0] ^ 0xff,
1718                                    0);
1719                 }
1720         }
1721
1722         return 0;
1723 }
1724
1725 static int su3000_rc_query(struct dvb_usb_device *d)
1726 {
1727         u8 key[2];
1728         struct i2c_msg msg = {
1729                 .addr = DW2102_RC_QUERY,
1730                 .flags = I2C_M_RD,
1731                 .buf = key,
1732                 .len = 2
1733         };
1734
1735         if (d->props.i2c_algo->master_xfer(&d->i2c_adap, &msg, 1) == 1) {
1736                 if (msg.buf[0] != 0xff) {
1737                         deb_rc("%s: rc code: %x, %x\n",
1738                                         __func__, key[0], key[1]);
1739                         rc_keydown(d->rc_dev, RC_PROTO_RC5,
1740                                    RC_SCANCODE_RC5(key[1], key[0]), 0);
1741                 }
1742         }
1743
1744         return 0;
1745 }
1746
1747 enum dw2102_table_entry {
1748         CYPRESS_DW2102,
1749         CYPRESS_DW2101,
1750         CYPRESS_DW2104,
1751         TEVII_S650,
1752         TERRATEC_CINERGY_S,
1753         CYPRESS_DW3101,
1754         TEVII_S630,
1755         PROF_1100,
1756         TEVII_S660,
1757         PROF_7500,
1758         GENIATECH_SU3000,
1759         TERRATEC_CINERGY_S2,
1760         TEVII_S480_1,
1761         TEVII_S480_2,
1762         X3M_SPC1400HD,
1763         TEVII_S421,
1764         TEVII_S632,
1765         TERRATEC_CINERGY_S2_R2,
1766         TERRATEC_CINERGY_S2_R3,
1767         TERRATEC_CINERGY_S2_R4,
1768         GOTVIEW_SAT_HD,
1769         GENIATECH_T220,
1770         TECHNOTREND_S2_4600,
1771         TEVII_S482_1,
1772         TEVII_S482_2,
1773         TERRATEC_CINERGY_S2_BOX,
1774         TEVII_S662
1775 };
1776
1777 static struct usb_device_id dw2102_table[] = {
1778         [CYPRESS_DW2102] = {USB_DEVICE(USB_VID_CYPRESS, USB_PID_DW2102)},
1779         [CYPRESS_DW2101] = {USB_DEVICE(USB_VID_CYPRESS, 0x2101)},
1780         [CYPRESS_DW2104] = {USB_DEVICE(USB_VID_CYPRESS, USB_PID_DW2104)},
1781         [TEVII_S650] = {USB_DEVICE(0x9022, USB_PID_TEVII_S650)},
1782         [TERRATEC_CINERGY_S] = {USB_DEVICE(USB_VID_TERRATEC, USB_PID_TERRATEC_CINERGY_S)},
1783         [CYPRESS_DW3101] = {USB_DEVICE(USB_VID_CYPRESS, USB_PID_DW3101)},
1784         [TEVII_S630] = {USB_DEVICE(0x9022, USB_PID_TEVII_S630)},
1785         [PROF_1100] = {USB_DEVICE(0x3011, USB_PID_PROF_1100)},
1786         [TEVII_S660] = {USB_DEVICE(0x9022, USB_PID_TEVII_S660)},
1787         [PROF_7500] = {USB_DEVICE(0x3034, 0x7500)},
1788         [GENIATECH_SU3000] = {USB_DEVICE(0x1f4d, 0x3000)},
1789         [TERRATEC_CINERGY_S2] = {USB_DEVICE(USB_VID_TERRATEC, USB_PID_TERRATEC_CINERGY_S2_R1)},
1790         [TEVII_S480_1] = {USB_DEVICE(0x9022, USB_PID_TEVII_S480_1)},
1791         [TEVII_S480_2] = {USB_DEVICE(0x9022, USB_PID_TEVII_S480_2)},
1792         [X3M_SPC1400HD] = {USB_DEVICE(0x1f4d, 0x3100)},
1793         [TEVII_S421] = {USB_DEVICE(0x9022, USB_PID_TEVII_S421)},
1794         [TEVII_S632] = {USB_DEVICE(0x9022, USB_PID_TEVII_S632)},
1795         [TERRATEC_CINERGY_S2_R2] = {USB_DEVICE(USB_VID_TERRATEC, USB_PID_TERRATEC_CINERGY_S2_R2)},
1796         [TERRATEC_CINERGY_S2_R3] = {USB_DEVICE(USB_VID_TERRATEC, USB_PID_TERRATEC_CINERGY_S2_R3)},
1797         [TERRATEC_CINERGY_S2_R4] = {USB_DEVICE(USB_VID_TERRATEC, USB_PID_TERRATEC_CINERGY_S2_R4)},
1798         [GOTVIEW_SAT_HD] = {USB_DEVICE(0x1FE1, USB_PID_GOTVIEW_SAT_HD)},
1799         [GENIATECH_T220] = {USB_DEVICE(0x1f4d, 0xD220)},
1800         [TECHNOTREND_S2_4600] = {USB_DEVICE(USB_VID_TECHNOTREND,
1801                 USB_PID_TECHNOTREND_CONNECT_S2_4600)},
1802         [TEVII_S482_1] = {USB_DEVICE(0x9022, 0xd483)},
1803         [TEVII_S482_2] = {USB_DEVICE(0x9022, 0xd484)},
1804         [TERRATEC_CINERGY_S2_BOX] = {USB_DEVICE(USB_VID_TERRATEC, 0x0105)},
1805         [TEVII_S662] = {USB_DEVICE(0x9022, USB_PID_TEVII_S662)},
1806         { }
1807 };
1808
1809 MODULE_DEVICE_TABLE(usb, dw2102_table);
1810
1811 static int dw2102_load_firmware(struct usb_device *dev,
1812                         const struct firmware *frmwr)
1813 {
1814         u8 *b, *p;
1815         int ret = 0, i;
1816         u8 reset;
1817         u8 reset16[] = {0, 0, 0, 0, 0, 0, 0};
1818         const struct firmware *fw;
1819
1820         switch (le16_to_cpu(dev->descriptor.idProduct)) {
1821         case 0x2101:
1822                 ret = reject_firmware(&fw, DW2101_FIRMWARE, &dev->dev);
1823                 if (ret != 0) {
1824                         err(err_str, DW2101_FIRMWARE);
1825                         return ret;
1826                 }
1827                 break;
1828         default:
1829                 fw = frmwr;
1830                 break;
1831         }
1832         info("start downloading DW210X firmware");
1833         p = kmalloc(fw->size, GFP_KERNEL);
1834         reset = 1;
1835         /*stop the CPU*/
1836         dw210x_op_rw(dev, 0xa0, 0x7f92, 0, &reset, 1, DW210X_WRITE_MSG);
1837         dw210x_op_rw(dev, 0xa0, 0xe600, 0, &reset, 1, DW210X_WRITE_MSG);
1838
1839         if (p != NULL) {
1840                 memcpy(p, fw->data, fw->size);
1841                 for (i = 0; i < fw->size; i += 0x40) {
1842                         b = (u8 *) p + i;
1843                         if (dw210x_op_rw(dev, 0xa0, i, 0, b , 0x40,
1844                                         DW210X_WRITE_MSG) != 0x40) {
1845                                 err("error while transferring firmware");
1846                                 ret = -EINVAL;
1847                                 break;
1848                         }
1849                 }
1850                 /* restart the CPU */
1851                 reset = 0;
1852                 if (ret || dw210x_op_rw(dev, 0xa0, 0x7f92, 0, &reset, 1,
1853                                         DW210X_WRITE_MSG) != 1) {
1854                         err("could not restart the USB controller CPU.");
1855                         ret = -EINVAL;
1856                 }
1857                 if (ret || dw210x_op_rw(dev, 0xa0, 0xe600, 0, &reset, 1,
1858                                         DW210X_WRITE_MSG) != 1) {
1859                         err("could not restart the USB controller CPU.");
1860                         ret = -EINVAL;
1861                 }
1862                 /* init registers */
1863                 switch (le16_to_cpu(dev->descriptor.idProduct)) {
1864                 case USB_PID_TEVII_S650:
1865                         dw2104_properties.rc.core.rc_codes = RC_MAP_TEVII_NEC;
1866                         /* fall through */
1867                 case USB_PID_DW2104:
1868                         reset = 1;
1869                         dw210x_op_rw(dev, 0xc4, 0x0000, 0, &reset, 1,
1870                                         DW210X_WRITE_MSG);
1871                         /* fall through */
1872                 case USB_PID_DW3101:
1873                         reset = 0;
1874                         dw210x_op_rw(dev, 0xbf, 0x0040, 0, &reset, 0,
1875                                         DW210X_WRITE_MSG);
1876                         break;
1877                 case USB_PID_TERRATEC_CINERGY_S:
1878                 case USB_PID_DW2102:
1879                         dw210x_op_rw(dev, 0xbf, 0x0040, 0, &reset, 0,
1880                                         DW210X_WRITE_MSG);
1881                         dw210x_op_rw(dev, 0xb9, 0x0000, 0, &reset16[0], 2,
1882                                         DW210X_READ_MSG);
1883                         /* check STV0299 frontend  */
1884                         dw210x_op_rw(dev, 0xb5, 0, 0, &reset16[0], 2,
1885                                         DW210X_READ_MSG);
1886                         if ((reset16[0] == 0xa1) || (reset16[0] == 0x80)) {
1887                                 dw2102_properties.i2c_algo = &dw2102_i2c_algo;
1888                                 dw2102_properties.adapter->fe[0].tuner_attach = &dw2102_tuner_attach;
1889                                 break;
1890                         } else {
1891                                 /* check STV0288 frontend  */
1892                                 reset16[0] = 0xd0;
1893                                 reset16[1] = 1;
1894                                 reset16[2] = 0;
1895                                 dw210x_op_rw(dev, 0xc2, 0, 0, &reset16[0], 3,
1896                                                 DW210X_WRITE_MSG);
1897                                 dw210x_op_rw(dev, 0xc3, 0xd1, 0, &reset16[0], 3,
1898                                                 DW210X_READ_MSG);
1899                                 if (reset16[2] == 0x11) {
1900                                         dw2102_properties.i2c_algo = &dw2102_earda_i2c_algo;
1901                                         break;
1902                                 }
1903                         }
1904                         /* fall through */
1905                 case 0x2101:
1906                         dw210x_op_rw(dev, 0xbc, 0x0030, 0, &reset16[0], 2,
1907                                         DW210X_READ_MSG);
1908                         dw210x_op_rw(dev, 0xba, 0x0000, 0, &reset16[0], 7,
1909                                         DW210X_READ_MSG);
1910                         dw210x_op_rw(dev, 0xba, 0x0000, 0, &reset16[0], 7,
1911                                         DW210X_READ_MSG);
1912                         dw210x_op_rw(dev, 0xb9, 0x0000, 0, &reset16[0], 2,
1913                                         DW210X_READ_MSG);
1914                         break;
1915                 }
1916
1917                 msleep(100);
1918                 kfree(p);
1919         }
1920
1921         if (le16_to_cpu(dev->descriptor.idProduct) == 0x2101)
1922                 release_firmware(fw);
1923         return ret;
1924 }
1925
1926 static struct dvb_usb_device_properties dw2102_properties = {
1927         .caps = DVB_USB_IS_AN_I2C_ADAPTER,
1928         .usb_ctrl = DEVICE_SPECIFIC,
1929         .firmware = DW2102_FIRMWARE,
1930         .no_reconnect = 1,
1931
1932         .i2c_algo = &dw2102_serit_i2c_algo,
1933
1934         .rc.core = {
1935                 .rc_interval = 150,
1936                 .rc_codes = RC_MAP_DM1105_NEC,
1937                 .module_name = "dw2102",
1938                 .allowed_protos   = RC_PROTO_BIT_NEC,
1939                 .rc_query = dw2102_rc_query,
1940         },
1941
1942         .generic_bulk_ctrl_endpoint = 0x81,
1943         /* parameter for the MPEG2-data transfer */
1944         .num_adapters = 1,
1945         .download_firmware = dw2102_load_firmware,
1946         .read_mac_address = dw210x_read_mac_address,
1947         .adapter = {
1948                 {
1949                 .num_frontends = 1,
1950                 .fe = {{
1951                         .frontend_attach = dw2102_frontend_attach,
1952                         .stream = {
1953                                 .type = USB_BULK,
1954                                 .count = 8,
1955                                 .endpoint = 0x82,
1956                                 .u = {
1957                                         .bulk = {
1958                                                 .buffersize = 4096,
1959                                         }
1960                                 }
1961                         },
1962                 }},
1963                 }
1964         },
1965         .num_device_descs = 3,
1966         .devices = {
1967                 {"DVBWorld DVB-S 2102 USB2.0",
1968                         {&dw2102_table[CYPRESS_DW2102], NULL},
1969                         {NULL},
1970                 },
1971                 {"DVBWorld DVB-S 2101 USB2.0",
1972                         {&dw2102_table[CYPRESS_DW2101], NULL},
1973                         {NULL},
1974                 },
1975                 {"TerraTec Cinergy S USB",
1976                         {&dw2102_table[TERRATEC_CINERGY_S], NULL},
1977                         {NULL},
1978                 },
1979         }
1980 };
1981
1982 static struct dvb_usb_device_properties dw2104_properties = {
1983         .caps = DVB_USB_IS_AN_I2C_ADAPTER,
1984         .usb_ctrl = DEVICE_SPECIFIC,
1985         .firmware = DW2104_FIRMWARE,
1986         .no_reconnect = 1,
1987
1988         .i2c_algo = &dw2104_i2c_algo,
1989         .rc.core = {
1990                 .rc_interval = 150,
1991                 .rc_codes = RC_MAP_DM1105_NEC,
1992                 .module_name = "dw2102",
1993                 .allowed_protos   = RC_PROTO_BIT_NEC,
1994                 .rc_query = dw2102_rc_query,
1995         },
1996
1997         .generic_bulk_ctrl_endpoint = 0x81,
1998         /* parameter for the MPEG2-data transfer */
1999         .num_adapters = 1,
2000         .download_firmware = dw2102_load_firmware,
2001         .read_mac_address = dw210x_read_mac_address,
2002         .adapter = {
2003                 {
2004                 .num_frontends = 1,
2005                 .fe = {{
2006                         .frontend_attach = dw2104_frontend_attach,
2007                         .stream = {
2008                                 .type = USB_BULK,
2009                                 .count = 8,
2010                                 .endpoint = 0x82,
2011                                 .u = {
2012                                         .bulk = {
2013                                                 .buffersize = 4096,
2014                                         }
2015                                 }
2016                         },
2017                 }},
2018                 }
2019         },
2020         .num_device_descs = 2,
2021         .devices = {
2022                 { "DVBWorld DW2104 USB2.0",
2023                         {&dw2102_table[CYPRESS_DW2104], NULL},
2024                         {NULL},
2025                 },
2026                 { "TeVii S650 USB2.0",
2027                         {&dw2102_table[TEVII_S650], NULL},
2028                         {NULL},
2029                 },
2030         }
2031 };
2032
2033 static struct dvb_usb_device_properties dw3101_properties = {
2034         .caps = DVB_USB_IS_AN_I2C_ADAPTER,
2035         .usb_ctrl = DEVICE_SPECIFIC,
2036         .firmware = DW3101_FIRMWARE,
2037         .no_reconnect = 1,
2038
2039         .i2c_algo = &dw3101_i2c_algo,
2040         .rc.core = {
2041                 .rc_interval = 150,
2042                 .rc_codes = RC_MAP_DM1105_NEC,
2043                 .module_name = "dw2102",
2044                 .allowed_protos   = RC_PROTO_BIT_NEC,
2045                 .rc_query = dw2102_rc_query,
2046         },
2047
2048         .generic_bulk_ctrl_endpoint = 0x81,
2049         /* parameter for the MPEG2-data transfer */
2050         .num_adapters = 1,
2051         .download_firmware = dw2102_load_firmware,
2052         .read_mac_address = dw210x_read_mac_address,
2053         .adapter = {
2054                 {
2055                 .num_frontends = 1,
2056                 .fe = {{
2057                         .frontend_attach = dw3101_frontend_attach,
2058                         .tuner_attach = dw3101_tuner_attach,
2059                         .stream = {
2060                                 .type = USB_BULK,
2061                                 .count = 8,
2062                                 .endpoint = 0x82,
2063                                 .u = {
2064                                         .bulk = {
2065                                                 .buffersize = 4096,
2066                                         }
2067                                 }
2068                         },
2069                 }},
2070                 }
2071         },
2072         .num_device_descs = 1,
2073         .devices = {
2074                 { "DVBWorld DVB-C 3101 USB2.0",
2075                         {&dw2102_table[CYPRESS_DW3101], NULL},
2076                         {NULL},
2077                 },
2078         }
2079 };
2080
2081 static struct dvb_usb_device_properties s6x0_properties = {
2082         .caps = DVB_USB_IS_AN_I2C_ADAPTER,
2083         .usb_ctrl = DEVICE_SPECIFIC,
2084         .size_of_priv = sizeof(struct dw2102_state),
2085         .firmware = S630_FIRMWARE,
2086         .no_reconnect = 1,
2087
2088         .i2c_algo = &s6x0_i2c_algo,
2089         .rc.core = {
2090                 .rc_interval = 150,
2091                 .rc_codes = RC_MAP_TEVII_NEC,
2092                 .module_name = "dw2102",
2093                 .allowed_protos   = RC_PROTO_BIT_NEC,
2094                 .rc_query = dw2102_rc_query,
2095         },
2096
2097         .generic_bulk_ctrl_endpoint = 0x81,
2098         .num_adapters = 1,
2099         .download_firmware = dw2102_load_firmware,
2100         .read_mac_address = s6x0_read_mac_address,
2101         .adapter = {
2102                 {
2103                 .num_frontends = 1,
2104                 .fe = {{
2105                         .frontend_attach = zl100313_frontend_attach,
2106                         .stream = {
2107                                 .type = USB_BULK,
2108                                 .count = 8,
2109                                 .endpoint = 0x82,
2110                                 .u = {
2111                                         .bulk = {
2112                                                 .buffersize = 4096,
2113                                         }
2114                                 }
2115                         },
2116                 }},
2117                 }
2118         },
2119         .num_device_descs = 1,
2120         .devices = {
2121                 {"TeVii S630 USB",
2122                         {&dw2102_table[TEVII_S630], NULL},
2123                         {NULL},
2124                 },
2125         }
2126 };
2127
2128 static struct dvb_usb_device_properties p1100_properties = {
2129         .caps = DVB_USB_IS_AN_I2C_ADAPTER,
2130         .usb_ctrl = DEVICE_SPECIFIC,
2131         .size_of_priv = sizeof(struct dw2102_state),
2132         .firmware = P1100_FIRMWARE,
2133         .no_reconnect = 1,
2134
2135         .i2c_algo = &s6x0_i2c_algo,
2136         .rc.core = {
2137                 .rc_interval = 150,
2138                 .rc_codes = RC_MAP_TBS_NEC,
2139                 .module_name = "dw2102",
2140                 .allowed_protos   = RC_PROTO_BIT_NEC,
2141                 .rc_query = prof_rc_query,
2142         },
2143
2144         .generic_bulk_ctrl_endpoint = 0x81,
2145         .num_adapters = 1,
2146         .download_firmware = dw2102_load_firmware,
2147         .read_mac_address = s6x0_read_mac_address,
2148         .adapter = {
2149                 {
2150                         .num_frontends = 1,
2151                         .fe = {{
2152                                 .frontend_attach = stv0288_frontend_attach,
2153                                 .stream = {
2154                                         .type = USB_BULK,
2155                                         .count = 8,
2156                                         .endpoint = 0x82,
2157                                         .u = {
2158                                                 .bulk = {
2159                                                         .buffersize = 4096,
2160                                                 }
2161                                         }
2162                                 },
2163                         } },
2164                 }
2165         },
2166         .num_device_descs = 1,
2167         .devices = {
2168                 {"Prof 1100 USB ",
2169                         {&dw2102_table[PROF_1100], NULL},
2170                         {NULL},
2171                 },
2172         }
2173 };
2174
2175 static struct dvb_usb_device_properties s660_properties = {
2176         .caps = DVB_USB_IS_AN_I2C_ADAPTER,
2177         .usb_ctrl = DEVICE_SPECIFIC,
2178         .size_of_priv = sizeof(struct dw2102_state),
2179         .firmware = S660_FIRMWARE,
2180         .no_reconnect = 1,
2181
2182         .i2c_algo = &s6x0_i2c_algo,
2183         .rc.core = {
2184                 .rc_interval = 150,
2185                 .rc_codes = RC_MAP_TEVII_NEC,
2186                 .module_name = "dw2102",
2187                 .allowed_protos   = RC_PROTO_BIT_NEC,
2188                 .rc_query = dw2102_rc_query,
2189         },
2190
2191         .generic_bulk_ctrl_endpoint = 0x81,
2192         .num_adapters = 1,
2193         .download_firmware = dw2102_load_firmware,
2194         .read_mac_address = s6x0_read_mac_address,
2195         .adapter = {
2196                 {
2197                         .num_frontends = 1,
2198                         .fe = {{
2199                                 .frontend_attach = ds3000_frontend_attach,
2200                                 .stream = {
2201                                         .type = USB_BULK,
2202                                         .count = 8,
2203                                         .endpoint = 0x82,
2204                                         .u = {
2205                                                 .bulk = {
2206                                                         .buffersize = 4096,
2207                                                 }
2208                                         }
2209                                 },
2210                         } },
2211                 }
2212         },
2213         .num_device_descs = 3,
2214         .devices = {
2215                 {"TeVii S660 USB",
2216                         {&dw2102_table[TEVII_S660], NULL},
2217                         {NULL},
2218                 },
2219                 {"TeVii S480.1 USB",
2220                         {&dw2102_table[TEVII_S480_1], NULL},
2221                         {NULL},
2222                 },
2223                 {"TeVii S480.2 USB",
2224                         {&dw2102_table[TEVII_S480_2], NULL},
2225                         {NULL},
2226                 },
2227         }
2228 };
2229
2230 static struct dvb_usb_device_properties p7500_properties = {
2231         .caps = DVB_USB_IS_AN_I2C_ADAPTER,
2232         .usb_ctrl = DEVICE_SPECIFIC,
2233         .size_of_priv = sizeof(struct dw2102_state),
2234         .firmware = P7500_FIRMWARE,
2235         .no_reconnect = 1,
2236
2237         .i2c_algo = &s6x0_i2c_algo,
2238         .rc.core = {
2239                 .rc_interval = 150,
2240                 .rc_codes = RC_MAP_TBS_NEC,
2241                 .module_name = "dw2102",
2242                 .allowed_protos   = RC_PROTO_BIT_NEC,
2243                 .rc_query = prof_rc_query,
2244         },
2245
2246         .generic_bulk_ctrl_endpoint = 0x81,
2247         .num_adapters = 1,
2248         .download_firmware = dw2102_load_firmware,
2249         .read_mac_address = s6x0_read_mac_address,
2250         .adapter = {
2251                 {
2252                         .num_frontends = 1,
2253                         .fe = {{
2254                                 .frontend_attach = prof_7500_frontend_attach,
2255                                 .stream = {
2256                                         .type = USB_BULK,
2257                                         .count = 8,
2258                                         .endpoint = 0x82,
2259                                         .u = {
2260                                                 .bulk = {
2261                                                         .buffersize = 4096,
2262                                                 }
2263                                         }
2264                                 },
2265                         } },
2266                 }
2267         },
2268         .num_device_descs = 1,
2269         .devices = {
2270                 {"Prof 7500 USB DVB-S2",
2271                         {&dw2102_table[PROF_7500], NULL},
2272                         {NULL},
2273                 },
2274         }
2275 };
2276
2277 static struct dvb_usb_device_properties su3000_properties = {
2278         .caps = DVB_USB_IS_AN_I2C_ADAPTER,
2279         .usb_ctrl = DEVICE_SPECIFIC,
2280         .size_of_priv = sizeof(struct dw2102_state),
2281         .power_ctrl = su3000_power_ctrl,
2282         .num_adapters = 1,
2283         .identify_state = su3000_identify_state,
2284         .i2c_algo = &su3000_i2c_algo,
2285
2286         .rc.core = {
2287                 .rc_interval = 150,
2288                 .rc_codes = RC_MAP_SU3000,
2289                 .module_name = "dw2102",
2290                 .allowed_protos   = RC_PROTO_BIT_RC5,
2291                 .rc_query = su3000_rc_query,
2292         },
2293
2294         .read_mac_address = su3000_read_mac_address,
2295
2296         .generic_bulk_ctrl_endpoint = 0x01,
2297
2298         .adapter = {
2299                 {
2300                 .num_frontends = 1,
2301                 .fe = {{
2302                         .streaming_ctrl   = su3000_streaming_ctrl,
2303                         .frontend_attach  = su3000_frontend_attach,
2304                         .stream = {
2305                                 .type = USB_BULK,
2306                                 .count = 8,
2307                                 .endpoint = 0x82,
2308                                 .u = {
2309                                         .bulk = {
2310                                                 .buffersize = 4096,
2311                                         }
2312                                 }
2313                         }
2314                 }},
2315                 }
2316         },
2317         .num_device_descs = 6,
2318         .devices = {
2319                 { "SU3000HD DVB-S USB2.0",
2320                         { &dw2102_table[GENIATECH_SU3000], NULL },
2321                         { NULL },
2322                 },
2323                 { "Terratec Cinergy S2 USB HD",
2324                         { &dw2102_table[TERRATEC_CINERGY_S2], NULL },
2325                         { NULL },
2326                 },
2327                 { "X3M TV SPC1400HD PCI",
2328                         { &dw2102_table[X3M_SPC1400HD], NULL },
2329                         { NULL },
2330                 },
2331                 { "Terratec Cinergy S2 USB HD Rev.2",
2332                         { &dw2102_table[TERRATEC_CINERGY_S2_R2], NULL },
2333                         { NULL },
2334                 },
2335                 { "Terratec Cinergy S2 USB HD Rev.3",
2336                         { &dw2102_table[TERRATEC_CINERGY_S2_R3], NULL },
2337                         { NULL },
2338                 },
2339                 { "GOTVIEW Satellite HD",
2340                         { &dw2102_table[GOTVIEW_SAT_HD], NULL },
2341                         { NULL },
2342                 },
2343         }
2344 };
2345
2346 static struct dvb_usb_device_properties s421_properties = {
2347         .caps = DVB_USB_IS_AN_I2C_ADAPTER,
2348         .usb_ctrl = DEVICE_SPECIFIC,
2349         .size_of_priv = sizeof(struct dw2102_state),
2350         .power_ctrl = su3000_power_ctrl,
2351         .num_adapters = 1,
2352         .identify_state = su3000_identify_state,
2353         .i2c_algo = &su3000_i2c_algo,
2354
2355         .rc.core = {
2356                 .rc_interval = 150,
2357                 .rc_codes = RC_MAP_SU3000,
2358                 .module_name = "dw2102",
2359                 .allowed_protos   = RC_PROTO_BIT_RC5,
2360                 .rc_query = su3000_rc_query,
2361         },
2362
2363         .read_mac_address = su3000_read_mac_address,
2364
2365         .generic_bulk_ctrl_endpoint = 0x01,
2366
2367         .adapter = {
2368                 {
2369                 .num_frontends = 1,
2370                 .fe = {{
2371                         .streaming_ctrl   = su3000_streaming_ctrl,
2372                         .frontend_attach  = m88rs2000_frontend_attach,
2373                         .stream = {
2374                                 .type = USB_BULK,
2375                                 .count = 8,
2376                                 .endpoint = 0x82,
2377                                 .u = {
2378                                         .bulk = {
2379                                                 .buffersize = 4096,
2380                                         }
2381                                 }
2382                         }
2383                 } },
2384                 }
2385         },
2386         .num_device_descs = 2,
2387         .devices = {
2388                 { "TeVii S421 PCI",
2389                         { &dw2102_table[TEVII_S421], NULL },
2390                         { NULL },
2391                 },
2392                 { "TeVii S632 USB",
2393                         { &dw2102_table[TEVII_S632], NULL },
2394                         { NULL },
2395                 },
2396         }
2397 };
2398
2399 static struct dvb_usb_device_properties t220_properties = {
2400         .caps = DVB_USB_IS_AN_I2C_ADAPTER,
2401         .usb_ctrl = DEVICE_SPECIFIC,
2402         .size_of_priv = sizeof(struct dw2102_state),
2403         .power_ctrl = su3000_power_ctrl,
2404         .num_adapters = 1,
2405         .identify_state = su3000_identify_state,
2406         .i2c_algo = &su3000_i2c_algo,
2407
2408         .rc.core = {
2409                 .rc_interval = 150,
2410                 .rc_codes = RC_MAP_SU3000,
2411                 .module_name = "dw2102",
2412                 .allowed_protos   = RC_PROTO_BIT_RC5,
2413                 .rc_query = su3000_rc_query,
2414         },
2415
2416         .read_mac_address = su3000_read_mac_address,
2417
2418         .generic_bulk_ctrl_endpoint = 0x01,
2419
2420         .adapter = {
2421                 {
2422                 .num_frontends = 1,
2423                 .fe = { {
2424                         .streaming_ctrl   = su3000_streaming_ctrl,
2425                         .frontend_attach  = t220_frontend_attach,
2426                         .stream = {
2427                                 .type = USB_BULK,
2428                                 .count = 8,
2429                                 .endpoint = 0x82,
2430                                 .u = {
2431                                         .bulk = {
2432                                                 .buffersize = 4096,
2433                                         }
2434                                 }
2435                         }
2436                 } },
2437                 }
2438         },
2439         .num_device_descs = 1,
2440         .devices = {
2441                 { "Geniatech T220 DVB-T/T2 USB2.0",
2442                         { &dw2102_table[GENIATECH_T220], NULL },
2443                         { NULL },
2444                 },
2445         }
2446 };
2447
2448 static struct dvb_usb_device_properties tt_s2_4600_properties = {
2449         .caps = DVB_USB_IS_AN_I2C_ADAPTER,
2450         .usb_ctrl = DEVICE_SPECIFIC,
2451         .size_of_priv = sizeof(struct dw2102_state),
2452         .power_ctrl = su3000_power_ctrl,
2453         .num_adapters = 1,
2454         .identify_state = su3000_identify_state,
2455         .i2c_algo = &su3000_i2c_algo,
2456
2457         .rc.core = {
2458                 .rc_interval = 250,
2459                 .rc_codes = RC_MAP_TT_1500,
2460                 .module_name = "dw2102",
2461                 .allowed_protos   = RC_PROTO_BIT_RC5,
2462                 .rc_query = su3000_rc_query,
2463         },
2464
2465         .read_mac_address = su3000_read_mac_address,
2466
2467         .generic_bulk_ctrl_endpoint = 0x01,
2468
2469         .adapter = {
2470                 {
2471                 .num_frontends = 1,
2472                 .fe = {{
2473                         .streaming_ctrl   = su3000_streaming_ctrl,
2474                         .frontend_attach  = tt_s2_4600_frontend_attach,
2475                         .stream = {
2476                                 .type = USB_BULK,
2477                                 .count = 8,
2478                                 .endpoint = 0x82,
2479                                 .u = {
2480                                         .bulk = {
2481                                                 .buffersize = 4096,
2482                                         }
2483                                 }
2484                         }
2485                 } },
2486                 }
2487         },
2488         .num_device_descs = 5,
2489         .devices = {
2490                 { "TechnoTrend TT-connect S2-4600",
2491                         { &dw2102_table[TECHNOTREND_S2_4600], NULL },
2492                         { NULL },
2493                 },
2494                 { "TeVii S482 (tuner 1)",
2495                         { &dw2102_table[TEVII_S482_1], NULL },
2496                         { NULL },
2497                 },
2498                 { "TeVii S482 (tuner 2)",
2499                         { &dw2102_table[TEVII_S482_2], NULL },
2500                         { NULL },
2501                 },
2502                 { "Terratec Cinergy S2 USB BOX",
2503                         { &dw2102_table[TERRATEC_CINERGY_S2_BOX], NULL },
2504                         { NULL },
2505                 },
2506                 { "TeVii S662",
2507                         { &dw2102_table[TEVII_S662], NULL },
2508                         { NULL },
2509                 },
2510         }
2511 };
2512
2513 static int dw2102_probe(struct usb_interface *intf,
2514                 const struct usb_device_id *id)
2515 {
2516         if (!(dvb_usb_device_init(intf, &dw2102_properties,
2517                                   THIS_MODULE, NULL, adapter_nr) &&
2518               dvb_usb_device_init(intf, &dw2104_properties,
2519                                   THIS_MODULE, NULL, adapter_nr) &&
2520               dvb_usb_device_init(intf, &dw3101_properties,
2521                                   THIS_MODULE, NULL, adapter_nr) &&
2522               dvb_usb_device_init(intf, &s6x0_properties,
2523                                   THIS_MODULE, NULL, adapter_nr) &&
2524               dvb_usb_device_init(intf, &p1100_properties,
2525                                   THIS_MODULE, NULL, adapter_nr) &&
2526               dvb_usb_device_init(intf, &s660_properties,
2527                                   THIS_MODULE, NULL, adapter_nr) &&
2528               dvb_usb_device_init(intf, &p7500_properties,
2529                                   THIS_MODULE, NULL, adapter_nr) &&
2530               dvb_usb_device_init(intf, &s421_properties,
2531                                   THIS_MODULE, NULL, adapter_nr) &&
2532               dvb_usb_device_init(intf, &su3000_properties,
2533                                   THIS_MODULE, NULL, adapter_nr) &&
2534               dvb_usb_device_init(intf, &t220_properties,
2535                                   THIS_MODULE, NULL, adapter_nr) &&
2536               dvb_usb_device_init(intf, &tt_s2_4600_properties,
2537                                   THIS_MODULE, NULL, adapter_nr))) {
2538
2539                 return 0;
2540         }
2541
2542         return -ENODEV;
2543 }
2544
2545 static void dw2102_disconnect(struct usb_interface *intf)
2546 {
2547         struct dvb_usb_device *d = usb_get_intfdata(intf);
2548         struct dw2102_state *st = (struct dw2102_state *)d->priv;
2549         struct i2c_client *client;
2550
2551         /* remove I2C client for tuner */
2552         client = st->i2c_client_tuner;
2553         if (client) {
2554                 module_put(client->dev.driver->owner);
2555                 i2c_unregister_device(client);
2556         }
2557
2558         /* remove I2C client for demodulator */
2559         client = st->i2c_client_demod;
2560         if (client) {
2561                 module_put(client->dev.driver->owner);
2562                 i2c_unregister_device(client);
2563         }
2564
2565         dvb_usb_device_exit(intf);
2566 }
2567
2568 static struct usb_driver dw2102_driver = {
2569         .name = "dw2102",
2570         .probe = dw2102_probe,
2571         .disconnect = dw2102_disconnect,
2572         .id_table = dw2102_table,
2573 };
2574
2575 module_usb_driver(dw2102_driver);
2576
2577 MODULE_AUTHOR("Igor M. Liplianin (c) liplianin@me.by");
2578 MODULE_DESCRIPTION("Driver for DVBWorld DVB-S 2101, 2102, DVB-S2 2104, DVB-C 3101 USB2.0, TeVii S421, S480, S482, S600, S630, S632, S650, TeVii S660, S662, Prof 1100, 7500 USB2.0, Geniatech SU3000, T220, TechnoTrend S2-4600, Terratec Cinergy S2 devices");
2579 MODULE_VERSION("0.1");
2580 MODULE_LICENSE("GPL");
2581 /*(DEBLOBBED)*/