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