[media] dw2102: Prof 7500: Lock LED implemented
[pandora-kernel.git] / drivers / media / dvb / 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 S600, S630, S650,
4 *       Prof 1100, 7500,
5  *      Geniatech SU3000 Cards
6 * Copyright (C) 2008,2009 Igor M. Liplianin (liplianin@me.by)
7 *
8 *       This program is free software; you can redistribute it and/or modify it
9 *       under the terms of the GNU General Public License as published by the
10 *       Free Software Foundation, version 2.
11 *
12 * see Documentation/dvb/README.dvb-usb for more information
13 */
14 #include "dw2102.h"
15 #include "si21xx.h"
16 #include "stv0299.h"
17 #include "z0194a.h"
18 #include "stv0288.h"
19 #include "stb6000.h"
20 #include "eds1547.h"
21 #include "cx24116.h"
22 #include "tda1002x.h"
23 #include "mt312.h"
24 #include "zl10039.h"
25 #include "ds3000.h"
26 #include "stv0900.h"
27 #include "stv6110.h"
28 #include "stb6100.h"
29 #include "stb6100_proc.h"
30
31 #ifndef USB_PID_DW2102
32 #define USB_PID_DW2102 0x2102
33 #endif
34
35 #ifndef USB_PID_DW2104
36 #define USB_PID_DW2104 0x2104
37 #endif
38
39 #ifndef USB_PID_DW3101
40 #define USB_PID_DW3101 0x3101
41 #endif
42
43 #ifndef USB_PID_CINERGY_S
44 #define USB_PID_CINERGY_S 0x0064
45 #endif
46
47 #ifndef USB_PID_TEVII_S630
48 #define USB_PID_TEVII_S630 0xd630
49 #endif
50
51 #ifndef USB_PID_TEVII_S650
52 #define USB_PID_TEVII_S650 0xd650
53 #endif
54
55 #ifndef USB_PID_TEVII_S660
56 #define USB_PID_TEVII_S660 0xd660
57 #endif
58
59 #ifndef USB_PID_PROF_1100
60 #define USB_PID_PROF_1100 0xb012
61 #endif
62
63 #define DW210X_READ_MSG 0
64 #define DW210X_WRITE_MSG 1
65
66 #define REG_1F_SYMBOLRATE_BYTE0 0x1f
67 #define REG_20_SYMBOLRATE_BYTE1 0x20
68 #define REG_21_SYMBOLRATE_BYTE2 0x21
69 /* on my own*/
70 #define DW2102_VOLTAGE_CTRL (0x1800)
71 #define SU3000_STREAM_CTRL (0x1900)
72 #define DW2102_RC_QUERY (0x1a00)
73 #define DW2102_LED_CTRL (0x1b00)
74
75 #define err_str "did not find the firmware file. (%s) " \
76                 "Please see linux/Documentation/dvb/ for more details " \
77                 "on firmware-problems."
78
79 struct rc_map_dvb_usb_table_table {
80         struct rc_map_table *rc_keys;
81         int rc_keys_size;
82 };
83
84 struct su3000_state {
85         u8 initialized;
86 };
87
88 /* debug */
89 static int dvb_usb_dw2102_debug;
90 module_param_named(debug, dvb_usb_dw2102_debug, int, 0644);
91 MODULE_PARM_DESC(debug, "set debugging level (1=info 2=xfer 4=rc(or-able))."
92                                                 DVB_USB_DEBUG_STATUS);
93
94 /* keymaps */
95 static int ir_keymap;
96 module_param_named(keymap, ir_keymap, int, 0644);
97 MODULE_PARM_DESC(keymap, "set keymap 0=default 1=dvbworld 2=tevii 3=tbs  ..."
98                         " 256=none");
99
100 /* demod probe */
101 static int demod_probe = 1;
102 module_param_named(demod, demod_probe, int, 0644);
103 MODULE_PARM_DESC(demod, "demod to probe (1=cx24116 2=stv0903+stv6110 "
104                         "4=stv0903+stb6100(or-able)).");
105
106 DVB_DEFINE_MOD_OPT_ADAPTER_NR(adapter_nr);
107
108 static int dw210x_op_rw(struct usb_device *dev, u8 request, u16 value,
109                         u16 index, u8 * data, u16 len, int flags)
110 {
111         int ret;
112         u8 u8buf[len];
113
114         unsigned int pipe = (flags == DW210X_READ_MSG) ?
115                                 usb_rcvctrlpipe(dev, 0) : usb_sndctrlpipe(dev, 0);
116         u8 request_type = (flags == DW210X_READ_MSG) ? USB_DIR_IN : USB_DIR_OUT;
117
118         if (flags == DW210X_WRITE_MSG)
119                 memcpy(u8buf, data, len);
120         ret = usb_control_msg(dev, pipe, request, request_type | USB_TYPE_VENDOR,
121                                 value, index , u8buf, len, 2000);
122
123         if (flags == DW210X_READ_MSG)
124                 memcpy(data, u8buf, len);
125         return ret;
126 }
127
128 /* I2C */
129 static int dw2102_i2c_transfer(struct i2c_adapter *adap, struct i2c_msg msg[],
130                 int num)
131 {
132         struct dvb_usb_device *d = i2c_get_adapdata(adap);
133         int i = 0, ret = 0;
134         u8 buf6[] = {0x2c, 0x05, 0xc0, 0, 0, 0, 0};
135         u16 value;
136
137         if (!d)
138                 return -ENODEV;
139         if (mutex_lock_interruptible(&d->i2c_mutex) < 0)
140                 return -EAGAIN;
141
142         switch (num) {
143         case 2:
144                 /* read stv0299 register */
145                 value = msg[0].buf[0];/* register */
146                 for (i = 0; i < msg[1].len; i++) {
147                         value = value + i;
148                         ret = dw210x_op_rw(d->udev, 0xb5, value, 0,
149                                         buf6, 2, DW210X_READ_MSG);
150                         msg[1].buf[i] = buf6[0];
151                 }
152                 break;
153         case 1:
154                 switch (msg[0].addr) {
155                 case 0x68:
156                         /* write to stv0299 register */
157                         buf6[0] = 0x2a;
158                         buf6[1] = msg[0].buf[0];
159                         buf6[2] = msg[0].buf[1];
160                         ret = dw210x_op_rw(d->udev, 0xb2, 0, 0,
161                                         buf6, 3, DW210X_WRITE_MSG);
162                         break;
163                 case 0x60:
164                         if (msg[0].flags == 0) {
165                         /* write to tuner pll */
166                                 buf6[0] = 0x2c;
167                                 buf6[1] = 5;
168                                 buf6[2] = 0xc0;
169                                 buf6[3] = msg[0].buf[0];
170                                 buf6[4] = msg[0].buf[1];
171                                 buf6[5] = msg[0].buf[2];
172                                 buf6[6] = msg[0].buf[3];
173                                 ret = dw210x_op_rw(d->udev, 0xb2, 0, 0,
174                                                 buf6, 7, DW210X_WRITE_MSG);
175                         } else {
176                         /* read from tuner */
177                                 ret = dw210x_op_rw(d->udev, 0xb5, 0, 0,
178                                                 buf6, 1, DW210X_READ_MSG);
179                                 msg[0].buf[0] = buf6[0];
180                         }
181                         break;
182                 case (DW2102_RC_QUERY):
183                         ret  = dw210x_op_rw(d->udev, 0xb8, 0, 0,
184                                         buf6, 2, DW210X_READ_MSG);
185                         msg[0].buf[0] = buf6[0];
186                         msg[0].buf[1] = buf6[1];
187                         break;
188                 case (DW2102_VOLTAGE_CTRL):
189                         buf6[0] = 0x30;
190                         buf6[1] = msg[0].buf[0];
191                         ret = dw210x_op_rw(d->udev, 0xb2, 0, 0,
192                                         buf6, 2, DW210X_WRITE_MSG);
193                         break;
194                 }
195
196                 break;
197         }
198
199         mutex_unlock(&d->i2c_mutex);
200         return num;
201 }
202
203 static int dw2102_serit_i2c_transfer(struct i2c_adapter *adap,
204                                                 struct i2c_msg msg[], int num)
205 {
206         struct dvb_usb_device *d = i2c_get_adapdata(adap);
207         int ret = 0;
208         u8 buf6[] = {0, 0, 0, 0, 0, 0, 0};
209
210         if (!d)
211                 return -ENODEV;
212         if (mutex_lock_interruptible(&d->i2c_mutex) < 0)
213                 return -EAGAIN;
214
215         switch (num) {
216         case 2:
217                 /* read si2109 register by number */
218                 buf6[0] = msg[0].addr << 1;
219                 buf6[1] = msg[0].len;
220                 buf6[2] = msg[0].buf[0];
221                 ret = dw210x_op_rw(d->udev, 0xc2, 0, 0,
222                                 buf6, msg[0].len + 2, DW210X_WRITE_MSG);
223                 /* read si2109 register */
224                 ret = dw210x_op_rw(d->udev, 0xc3, 0xd0, 0,
225                                 buf6, msg[1].len + 2, DW210X_READ_MSG);
226                 memcpy(msg[1].buf, buf6 + 2, msg[1].len);
227
228                 break;
229         case 1:
230                 switch (msg[0].addr) {
231                 case 0x68:
232                         /* write to si2109 register */
233                         buf6[0] = msg[0].addr << 1;
234                         buf6[1] = msg[0].len;
235                         memcpy(buf6 + 2, msg[0].buf, msg[0].len);
236                         ret = dw210x_op_rw(d->udev, 0xc2, 0, 0, buf6,
237                                         msg[0].len + 2, DW210X_WRITE_MSG);
238                         break;
239                 case(DW2102_RC_QUERY):
240                         ret  = dw210x_op_rw(d->udev, 0xb8, 0, 0,
241                                         buf6, 2, DW210X_READ_MSG);
242                         msg[0].buf[0] = buf6[0];
243                         msg[0].buf[1] = buf6[1];
244                         break;
245                 case(DW2102_VOLTAGE_CTRL):
246                         buf6[0] = 0x30;
247                         buf6[1] = msg[0].buf[0];
248                         ret = dw210x_op_rw(d->udev, 0xb2, 0, 0,
249                                         buf6, 2, DW210X_WRITE_MSG);
250                         break;
251                 }
252                 break;
253         }
254
255         mutex_unlock(&d->i2c_mutex);
256         return num;
257 }
258
259 static int dw2102_earda_i2c_transfer(struct i2c_adapter *adap, struct i2c_msg msg[], int num)
260 {
261         struct dvb_usb_device *d = i2c_get_adapdata(adap);
262         int ret = 0;
263
264         if (!d)
265                 return -ENODEV;
266         if (mutex_lock_interruptible(&d->i2c_mutex) < 0)
267                 return -EAGAIN;
268
269         switch (num) {
270         case 2: {
271                 /* read */
272                 /* first write first register number */
273                 u8 ibuf[msg[1].len + 2], obuf[3];
274                 obuf[0] = msg[0].addr << 1;
275                 obuf[1] = msg[0].len;
276                 obuf[2] = msg[0].buf[0];
277                 ret = dw210x_op_rw(d->udev, 0xc2, 0, 0,
278                                 obuf, msg[0].len + 2, DW210X_WRITE_MSG);
279                 /* second read registers */
280                 ret = dw210x_op_rw(d->udev, 0xc3, 0xd1 , 0,
281                                 ibuf, msg[1].len + 2, DW210X_READ_MSG);
282                 memcpy(msg[1].buf, ibuf + 2, msg[1].len);
283
284                 break;
285         }
286         case 1:
287                 switch (msg[0].addr) {
288                 case 0x68: {
289                         /* write to register */
290                         u8 obuf[msg[0].len + 2];
291                         obuf[0] = msg[0].addr << 1;
292                         obuf[1] = msg[0].len;
293                         memcpy(obuf + 2, msg[0].buf, msg[0].len);
294                         ret = dw210x_op_rw(d->udev, 0xc2, 0, 0,
295                                         obuf, msg[0].len + 2, DW210X_WRITE_MSG);
296                         break;
297                 }
298                 case 0x61: {
299                         /* write to tuner */
300                         u8 obuf[msg[0].len + 2];
301                         obuf[0] = msg[0].addr << 1;
302                         obuf[1] = msg[0].len;
303                         memcpy(obuf + 2, msg[0].buf, msg[0].len);
304                         ret = dw210x_op_rw(d->udev, 0xc2, 0, 0,
305                                         obuf, msg[0].len + 2, DW210X_WRITE_MSG);
306                         break;
307                 }
308                 case(DW2102_RC_QUERY): {
309                         u8 ibuf[2];
310                         ret  = dw210x_op_rw(d->udev, 0xb8, 0, 0,
311                                         ibuf, 2, DW210X_READ_MSG);
312                         memcpy(msg[0].buf, ibuf , 2);
313                         break;
314                 }
315                 case(DW2102_VOLTAGE_CTRL): {
316                         u8 obuf[2];
317                         obuf[0] = 0x30;
318                         obuf[1] = msg[0].buf[0];
319                         ret = dw210x_op_rw(d->udev, 0xb2, 0, 0,
320                                         obuf, 2, DW210X_WRITE_MSG);
321                         break;
322                 }
323                 }
324
325                 break;
326         }
327
328         mutex_unlock(&d->i2c_mutex);
329         return num;
330 }
331
332 static int dw2104_i2c_transfer(struct i2c_adapter *adap, struct i2c_msg msg[], int num)
333 {
334         struct dvb_usb_device *d = i2c_get_adapdata(adap);
335         int ret = 0;
336         int len, i, j;
337
338         if (!d)
339                 return -ENODEV;
340         if (mutex_lock_interruptible(&d->i2c_mutex) < 0)
341                 return -EAGAIN;
342
343         for (j = 0; j < num; j++) {
344                 switch (msg[j].addr) {
345                 case(DW2102_RC_QUERY): {
346                         u8 ibuf[2];
347                         ret  = dw210x_op_rw(d->udev, 0xb8, 0, 0,
348                                         ibuf, 2, DW210X_READ_MSG);
349                         memcpy(msg[j].buf, ibuf , 2);
350                         break;
351                 }
352                 case(DW2102_VOLTAGE_CTRL): {
353                         u8 obuf[2];
354                         obuf[0] = 0x30;
355                         obuf[1] = msg[j].buf[0];
356                         ret = dw210x_op_rw(d->udev, 0xb2, 0, 0,
357                                         obuf, 2, DW210X_WRITE_MSG);
358                         break;
359                 }
360                 /*case 0x55: cx24116
361                 case 0x6a: stv0903
362                 case 0x68: ds3000, stv0903
363                 case 0x60: ts2020, stv6110, stb6100 */
364                 default: {
365                         if (msg[j].flags == I2C_M_RD) {
366                                 /* read registers */
367                                 u8  ibuf[msg[j].len + 2];
368                                 ret = dw210x_op_rw(d->udev, 0xc3,
369                                                 (msg[j].addr << 1) + 1, 0,
370                                                 ibuf, msg[j].len + 2,
371                                                 DW210X_READ_MSG);
372                                 memcpy(msg[j].buf, ibuf + 2, msg[j].len);
373                         mdelay(10);
374                         } else if (((msg[j].buf[0] == 0xb0) &&
375                                                 (msg[j].addr == 0x68)) ||
376                                                 ((msg[j].buf[0] == 0xf7) &&
377                                                 (msg[j].addr == 0x55))) {
378                                 /* write firmware */
379                                 u8 obuf[19];
380                                 obuf[0] = msg[j].addr << 1;
381                                 obuf[1] = (msg[j].len > 15 ? 17 : msg[j].len);
382                                 obuf[2] = msg[j].buf[0];
383                                 len = msg[j].len - 1;
384                                 i = 1;
385                                 do {
386                                         memcpy(obuf + 3, msg[j].buf + i,
387                                                         (len > 16 ? 16 : len));
388                                         ret = dw210x_op_rw(d->udev, 0xc2, 0, 0,
389                                                 obuf, (len > 16 ? 16 : len) + 3,
390                                                 DW210X_WRITE_MSG);
391                                         i += 16;
392                                         len -= 16;
393                                 } while (len > 0);
394                         } else {
395                                 /* write registers */
396                                 u8 obuf[msg[j].len + 2];
397                                 obuf[0] = msg[j].addr << 1;
398                                 obuf[1] = msg[j].len;
399                                 memcpy(obuf + 2, msg[j].buf, msg[j].len);
400                                 ret = dw210x_op_rw(d->udev, 0xc2, 0, 0,
401                                                 obuf, msg[j].len + 2,
402                                                 DW210X_WRITE_MSG);
403                         }
404                         break;
405                 }
406                 }
407
408         }
409
410         mutex_unlock(&d->i2c_mutex);
411         return num;
412 }
413
414 static int dw3101_i2c_transfer(struct i2c_adapter *adap, struct i2c_msg msg[],
415                                                                 int num)
416 {
417         struct dvb_usb_device *d = i2c_get_adapdata(adap);
418         int ret = 0, i;
419
420         if (!d)
421                 return -ENODEV;
422         if (mutex_lock_interruptible(&d->i2c_mutex) < 0)
423                 return -EAGAIN;
424
425         switch (num) {
426         case 2: {
427                 /* read */
428                 /* first write first register number */
429                 u8 ibuf[msg[1].len + 2], obuf[3];
430                 obuf[0] = msg[0].addr << 1;
431                 obuf[1] = msg[0].len;
432                 obuf[2] = msg[0].buf[0];
433                 ret = dw210x_op_rw(d->udev, 0xc2, 0, 0,
434                                 obuf, msg[0].len + 2, DW210X_WRITE_MSG);
435                 /* second read registers */
436                 ret = dw210x_op_rw(d->udev, 0xc3, 0x19 , 0,
437                                 ibuf, msg[1].len + 2, DW210X_READ_MSG);
438                 memcpy(msg[1].buf, ibuf + 2, msg[1].len);
439
440                 break;
441         }
442         case 1:
443                 switch (msg[0].addr) {
444                 case 0x60:
445                 case 0x0c: {
446                         /* write to register */
447                         u8 obuf[msg[0].len + 2];
448                         obuf[0] = msg[0].addr << 1;
449                         obuf[1] = msg[0].len;
450                         memcpy(obuf + 2, msg[0].buf, msg[0].len);
451                         ret = dw210x_op_rw(d->udev, 0xc2, 0, 0,
452                                         obuf, msg[0].len + 2, DW210X_WRITE_MSG);
453                         break;
454                 }
455                 case(DW2102_RC_QUERY): {
456                         u8 ibuf[2];
457                         ret  = dw210x_op_rw(d->udev, 0xb8, 0, 0,
458                                         ibuf, 2, DW210X_READ_MSG);
459                         memcpy(msg[0].buf, ibuf , 2);
460                         break;
461                 }
462                 }
463
464                 break;
465         }
466
467         for (i = 0; i < num; i++) {
468                 deb_xfer("%02x:%02x: %s ", i, msg[i].addr,
469                                 msg[i].flags == 0 ? ">>>" : "<<<");
470                 debug_dump(msg[i].buf, msg[i].len, deb_xfer);
471         }
472
473         mutex_unlock(&d->i2c_mutex);
474         return num;
475 }
476
477 static int s6x0_i2c_transfer(struct i2c_adapter *adap, struct i2c_msg msg[],
478                                                                 int num)
479 {
480         struct dvb_usb_device *d = i2c_get_adapdata(adap);
481         struct usb_device *udev;
482         int ret = 0;
483         int len, i, j;
484
485         if (!d)
486                 return -ENODEV;
487         udev = d->udev;
488         if (mutex_lock_interruptible(&d->i2c_mutex) < 0)
489                 return -EAGAIN;
490
491         for (j = 0; j < num; j++) {
492                 switch (msg[j].addr) {
493                 case (DW2102_RC_QUERY): {
494                         u8 ibuf[4];
495                         ret  = dw210x_op_rw(d->udev, 0xb8, 0, 0,
496                                         ibuf, 4, DW210X_READ_MSG);
497                         memcpy(msg[j].buf, ibuf + 1, 2);
498                         break;
499                 }
500                 case (DW2102_VOLTAGE_CTRL): {
501                         u8 obuf[2];
502
503                         obuf[0] = 1;
504                         obuf[1] = msg[j].buf[1];/* off-on */
505                         ret = dw210x_op_rw(d->udev, 0x8a, 0, 0,
506                                         obuf, 2, DW210X_WRITE_MSG);
507                         obuf[0] = 3;
508                         obuf[1] = msg[j].buf[0];/* 13v-18v */
509                         ret = dw210x_op_rw(d->udev, 0x8a, 0, 0,
510                                         obuf, 2, DW210X_WRITE_MSG);
511                         break;
512                 }
513                 case (DW2102_LED_CTRL): {
514                         u8 obuf[2];
515
516                         obuf[0] = 5;
517                         obuf[1] = msg[j].buf[0];
518                         ret = dw210x_op_rw(d->udev, 0x8a, 0, 0,
519                                         obuf, 2, DW210X_WRITE_MSG);
520                         break;
521                 }
522                 /*case 0x55: cx24116
523                 case 0x6a: stv0903
524                 case 0x68: ds3000, stv0903
525                 case 0x60: ts2020, stv6110, stb6100
526                 case 0xa0: eeprom */
527                 default: {
528                         if (msg[j].flags == I2C_M_RD) {
529                                 /* read registers */
530                                 u8 ibuf[msg[j].len];
531                                 ret = dw210x_op_rw(d->udev, 0x91, 0, 0,
532                                                 ibuf, msg[j].len,
533                                                 DW210X_READ_MSG);
534                                 memcpy(msg[j].buf, ibuf, msg[j].len);
535                                 break;
536                         } else if ((msg[j].buf[0] == 0xb0) &&
537                                                 (msg[j].addr == 0x68)) {
538                                 /* write firmware */
539                                 u8 obuf[19];
540                                 obuf[0] = (msg[j].len > 16 ?
541                                                 18 : msg[j].len + 1);
542                                 obuf[1] = msg[j].addr << 1;
543                                 obuf[2] = msg[j].buf[0];
544                                 len = msg[j].len - 1;
545                                 i = 1;
546                                 do {
547                                         memcpy(obuf + 3, msg[j].buf + i,
548                                                         (len > 16 ? 16 : len));
549                                         ret = dw210x_op_rw(d->udev, 0x80, 0, 0,
550                                                 obuf, (len > 16 ? 16 : len) + 3,
551                                                 DW210X_WRITE_MSG);
552                                         i += 16;
553                                         len -= 16;
554                                 } while (len > 0);
555                         } else if ((udev->descriptor.idProduct == 0x7500)
556                                         && (j < (num - 1))) {
557                                 /* write register addr before read */
558                                 u8 obuf[msg[j].len + 2];
559                                 obuf[0] = msg[j + 1].len;
560                                 obuf[1] = (msg[j].addr << 1);
561                                 memcpy(obuf + 2, msg[j].buf, msg[j].len);
562                                 ret = dw210x_op_rw(d->udev, 0x92, 0, 0,
563                                                 obuf, msg[j].len + 2,
564                                                 DW210X_WRITE_MSG);
565                                 break;
566                         } else {
567                                 /* write registers */
568                                 u8 obuf[msg[j].len + 2];
569                                 obuf[0] = msg[j].len + 1;
570                                 obuf[1] = (msg[j].addr << 1);
571                                 memcpy(obuf + 2, msg[j].buf, msg[j].len);
572                                 ret = dw210x_op_rw(d->udev,
573                                                 (num > 1 ? 0x90 : 0x80), 0, 0,
574                                                 obuf, msg[j].len + 2,
575                                                 DW210X_WRITE_MSG);
576                                 break;
577                         }
578                         break;
579                 }
580                 }
581
582                 msleep(3);
583         }
584
585         mutex_unlock(&d->i2c_mutex);
586         return num;
587 }
588
589 static int su3000_i2c_transfer(struct i2c_adapter *adap, struct i2c_msg msg[],
590                                                                 int num)
591 {
592         struct dvb_usb_device *d = i2c_get_adapdata(adap);
593         u8 obuf[0x40], ibuf[0x40];
594
595         if (!d)
596                 return -ENODEV;
597         if (mutex_lock_interruptible(&d->i2c_mutex) < 0)
598                 return -EAGAIN;
599
600         switch (num) {
601         case 1:
602                 switch (msg[0].addr) {
603                 case SU3000_STREAM_CTRL:
604                         obuf[0] = msg[0].buf[0] + 0x36;
605                         obuf[1] = 3;
606                         obuf[2] = 0;
607                         if (dvb_usb_generic_rw(d, obuf, 3, ibuf, 0, 0) < 0)
608                                 err("i2c transfer failed.");
609                         break;
610                 case DW2102_RC_QUERY:
611                         obuf[0] = 0x10;
612                         if (dvb_usb_generic_rw(d, obuf, 1, ibuf, 2, 0) < 0)
613                                 err("i2c transfer failed.");
614                         msg[0].buf[1] = ibuf[0];
615                         msg[0].buf[0] = ibuf[1];
616                         break;
617                 default:
618                         /* always i2c write*/
619                         obuf[0] = 0x08;
620                         obuf[1] = msg[0].addr;
621                         obuf[2] = msg[0].len;
622
623                         memcpy(&obuf[3], msg[0].buf, msg[0].len);
624
625                         if (dvb_usb_generic_rw(d, obuf, msg[0].len + 3,
626                                                 ibuf, 1, 0) < 0)
627                                 err("i2c transfer failed.");
628
629                 }
630                 break;
631         case 2:
632                 /* always i2c read */
633                 obuf[0] = 0x09;
634                 obuf[1] = msg[0].len;
635                 obuf[2] = msg[1].len;
636                 obuf[3] = msg[0].addr;
637                 memcpy(&obuf[4], msg[0].buf, msg[0].len);
638
639                 if (dvb_usb_generic_rw(d, obuf, msg[0].len + 4,
640                                         ibuf, msg[1].len + 1, 0) < 0)
641                         err("i2c transfer failed.");
642
643                 memcpy(msg[1].buf, &ibuf[1], msg[1].len);
644                 break;
645         default:
646                 warn("more than 2 i2c messages at a time is not handled yet.");
647                 break;
648         }
649         mutex_unlock(&d->i2c_mutex);
650         return num;
651 }
652
653 static u32 dw210x_i2c_func(struct i2c_adapter *adapter)
654 {
655         return I2C_FUNC_I2C;
656 }
657
658 static struct i2c_algorithm dw2102_i2c_algo = {
659         .master_xfer = dw2102_i2c_transfer,
660         .functionality = dw210x_i2c_func,
661 };
662
663 static struct i2c_algorithm dw2102_serit_i2c_algo = {
664         .master_xfer = dw2102_serit_i2c_transfer,
665         .functionality = dw210x_i2c_func,
666 };
667
668 static struct i2c_algorithm dw2102_earda_i2c_algo = {
669         .master_xfer = dw2102_earda_i2c_transfer,
670         .functionality = dw210x_i2c_func,
671 };
672
673 static struct i2c_algorithm dw2104_i2c_algo = {
674         .master_xfer = dw2104_i2c_transfer,
675         .functionality = dw210x_i2c_func,
676 };
677
678 static struct i2c_algorithm dw3101_i2c_algo = {
679         .master_xfer = dw3101_i2c_transfer,
680         .functionality = dw210x_i2c_func,
681 };
682
683 static struct i2c_algorithm s6x0_i2c_algo = {
684         .master_xfer = s6x0_i2c_transfer,
685         .functionality = dw210x_i2c_func,
686 };
687
688 static struct i2c_algorithm su3000_i2c_algo = {
689         .master_xfer = su3000_i2c_transfer,
690         .functionality = dw210x_i2c_func,
691 };
692
693 static int dw210x_read_mac_address(struct dvb_usb_device *d, u8 mac[6])
694 {
695         int i;
696         u8 ibuf[] = {0, 0};
697         u8 eeprom[256], eepromline[16];
698
699         for (i = 0; i < 256; i++) {
700                 if (dw210x_op_rw(d->udev, 0xb6, 0xa0 , i, ibuf, 2, DW210X_READ_MSG) < 0) {
701                         err("read eeprom failed.");
702                         return -1;
703                 } else {
704                         eepromline[i%16] = ibuf[0];
705                         eeprom[i] = ibuf[0];
706                 }
707                 if ((i % 16) == 15) {
708                         deb_xfer("%02x: ", i - 15);
709                         debug_dump(eepromline, 16, deb_xfer);
710                 }
711         }
712
713         memcpy(mac, eeprom + 8, 6);
714         return 0;
715 };
716
717 static int s6x0_read_mac_address(struct dvb_usb_device *d, u8 mac[6])
718 {
719         int i, ret;
720         u8 ibuf[] = { 0 }, obuf[] = { 0 };
721         u8 eeprom[256], eepromline[16];
722         struct i2c_msg msg[] = {
723                 {
724                         .addr = 0xa0 >> 1,
725                         .flags = 0,
726                         .buf = obuf,
727                         .len = 1,
728                 }, {
729                         .addr = 0xa0 >> 1,
730                         .flags = I2C_M_RD,
731                         .buf = ibuf,
732                         .len = 1,
733                 }
734         };
735
736         for (i = 0; i < 256; i++) {
737                 obuf[0] = i;
738                 ret = s6x0_i2c_transfer(&d->i2c_adap, msg, 2);
739                 if (ret != 2) {
740                         err("read eeprom failed.");
741                         return -1;
742                 } else {
743                         eepromline[i % 16] = ibuf[0];
744                         eeprom[i] = ibuf[0];
745                 }
746
747                 if ((i % 16) == 15) {
748                         deb_xfer("%02x: ", i - 15);
749                         debug_dump(eepromline, 16, deb_xfer);
750                 }
751         }
752
753         memcpy(mac, eeprom + 16, 6);
754         return 0;
755 };
756
757 static int su3000_streaming_ctrl(struct dvb_usb_adapter *adap, int onoff)
758 {
759         static u8 command_start[] = {0x00};
760         static u8 command_stop[] = {0x01};
761         struct i2c_msg msg = {
762                 .addr = SU3000_STREAM_CTRL,
763                 .flags = 0,
764                 .buf = onoff ? command_start : command_stop,
765                 .len = 1
766         };
767
768         i2c_transfer(&adap->dev->i2c_adap, &msg, 1);
769
770         return 0;
771 }
772
773 static int su3000_power_ctrl(struct dvb_usb_device *d, int i)
774 {
775         struct su3000_state *state = (struct su3000_state *)d->priv;
776         u8 obuf[] = {0xde, 0};
777
778         info("%s: %d, initialized %d\n", __func__, i, state->initialized);
779
780         if (i && !state->initialized) {
781                 state->initialized = 1;
782                 /* reset board */
783                 dvb_usb_generic_rw(d, obuf, 2, NULL, 0, 0);
784         }
785
786         return 0;
787 }
788
789 static int su3000_read_mac_address(struct dvb_usb_device *d, u8 mac[6])
790 {
791         int i;
792         u8 obuf[] = { 0x1f, 0xf0 };
793         u8 ibuf[] = { 0 };
794         struct i2c_msg msg[] = {
795                 {
796                         .addr = 0x51,
797                         .flags = 0,
798                         .buf = obuf,
799                         .len = 2,
800                 }, {
801                         .addr = 0x51,
802                         .flags = I2C_M_RD,
803                         .buf = ibuf,
804                         .len = 1,
805
806                 }
807         };
808
809         for (i = 0; i < 6; i++) {
810                 obuf[1] = 0xf0 + i;
811                 if (i2c_transfer(&d->i2c_adap, msg, 2) != 2)
812                         break;
813                 else
814                         mac[i] = ibuf[0];
815
816                 debug_dump(mac, 6, printk);
817         }
818
819         return 0;
820 }
821
822 static int su3000_identify_state(struct usb_device *udev,
823                                  struct dvb_usb_device_properties *props,
824                                  struct dvb_usb_device_description **desc,
825                                  int *cold)
826 {
827         info("%s\n", __func__);
828
829         *cold = 0;
830         return 0;
831 }
832
833 static int dw210x_set_voltage(struct dvb_frontend *fe, fe_sec_voltage_t voltage)
834 {
835         static u8 command_13v[] = {0x00, 0x01};
836         static u8 command_18v[] = {0x01, 0x01};
837         static u8 command_off[] = {0x00, 0x00};
838         struct i2c_msg msg = {
839                 .addr = DW2102_VOLTAGE_CTRL,
840                 .flags = 0,
841                 .buf = command_off,
842                 .len = 2,
843         };
844
845         struct dvb_usb_adapter *udev_adap =
846                 (struct dvb_usb_adapter *)(fe->dvb->priv);
847         if (voltage == SEC_VOLTAGE_18)
848                 msg.buf = command_18v;
849         else if (voltage == SEC_VOLTAGE_13)
850                 msg.buf = command_13v;
851
852         i2c_transfer(&udev_adap->dev->i2c_adap, &msg, 1);
853
854         return 0;
855 }
856
857 static void dw210x_led_ctrl(struct dvb_frontend *fe, int offon)
858 {
859         static u8 led_off[] = { 0 };
860         static u8 led_on[] = { 1 };
861         struct i2c_msg msg = {
862                 .addr = DW2102_LED_CTRL,
863                 .flags = 0,
864                 .buf = led_off,
865                 .len = 1
866         };
867         struct dvb_usb_adapter *udev_adap =
868                 (struct dvb_usb_adapter *)(fe->dvb->priv);
869
870         if (offon)
871                 msg.buf = led_on;
872         i2c_transfer(&udev_adap->dev->i2c_adap, &msg, 1);
873 }
874
875 static struct stv0299_config sharp_z0194a_config = {
876         .demod_address = 0x68,
877         .inittab = sharp_z0194a_inittab,
878         .mclk = 88000000UL,
879         .invert = 1,
880         .skip_reinit = 0,
881         .lock_output = STV0299_LOCKOUTPUT_1,
882         .volt13_op0_op1 = STV0299_VOLT13_OP1,
883         .min_delay_ms = 100,
884         .set_symbol_rate = sharp_z0194a_set_symbol_rate,
885 };
886
887 static struct cx24116_config dw2104_config = {
888         .demod_address = 0x55,
889         .mpg_clk_pos_pol = 0x01,
890 };
891
892 static struct si21xx_config serit_sp1511lhb_config = {
893         .demod_address = 0x68,
894         .min_delay_ms = 100,
895
896 };
897
898 static struct tda10023_config dw3101_tda10023_config = {
899         .demod_address = 0x0c,
900         .invert = 1,
901 };
902
903 static struct mt312_config zl313_config = {
904         .demod_address = 0x0e,
905 };
906
907 static struct ds3000_config dw2104_ds3000_config = {
908         .demod_address = 0x68,
909 };
910
911 static struct stv0900_config dw2104a_stv0900_config = {
912         .demod_address = 0x6a,
913         .demod_mode = 0,
914         .xtal = 27000000,
915         .clkmode = 3,/* 0-CLKI, 2-XTALI, else AUTO */
916         .diseqc_mode = 2,/* 2/3 PWM */
917         .tun1_maddress = 0,/* 0x60 */
918         .tun1_adc = 0,/* 2 Vpp */
919         .path1_mode = 3,
920 };
921
922 static struct stb6100_config dw2104a_stb6100_config = {
923         .tuner_address = 0x60,
924         .refclock = 27000000,
925 };
926
927 static struct stv0900_config dw2104_stv0900_config = {
928         .demod_address = 0x68,
929         .demod_mode = 0,
930         .xtal = 8000000,
931         .clkmode = 3,
932         .diseqc_mode = 2,
933         .tun1_maddress = 0,
934         .tun1_adc = 1,/* 1 Vpp */
935         .path1_mode = 3,
936 };
937
938 static struct stv6110_config dw2104_stv6110_config = {
939         .i2c_address = 0x60,
940         .mclk = 16000000,
941         .clk_div = 1,
942 };
943
944 static struct stv0900_config prof_7500_stv0900_config = {
945         .demod_address = 0x6a,
946         .demod_mode = 0,
947         .xtal = 27000000,
948         .clkmode = 3,/* 0-CLKI, 2-XTALI, else AUTO */
949         .diseqc_mode = 2,/* 2/3 PWM */
950         .tun1_maddress = 0,/* 0x60 */
951         .tun1_adc = 0,/* 2 Vpp */
952         .path1_mode = 3,
953         .tun1_type = 3,
954         .set_lock_led = dw210x_led_ctrl,
955 };
956
957 static struct ds3000_config su3000_ds3000_config = {
958         .demod_address = 0x68,
959         .ci_mode = 1,
960 };
961
962 static int dw2104_frontend_attach(struct dvb_usb_adapter *d)
963 {
964         struct dvb_tuner_ops *tuner_ops = NULL;
965
966         if (demod_probe & 4) {
967                 d->fe = dvb_attach(stv0900_attach, &dw2104a_stv0900_config,
968                                 &d->dev->i2c_adap, 0);
969                 if (d->fe != NULL) {
970                         if (dvb_attach(stb6100_attach, d->fe,
971                                         &dw2104a_stb6100_config,
972                                         &d->dev->i2c_adap)) {
973                                 tuner_ops = &d->fe->ops.tuner_ops;
974                                 tuner_ops->set_frequency = stb6100_set_freq;
975                                 tuner_ops->get_frequency = stb6100_get_freq;
976                                 tuner_ops->set_bandwidth = stb6100_set_bandw;
977                                 tuner_ops->get_bandwidth = stb6100_get_bandw;
978                                 d->fe->ops.set_voltage = dw210x_set_voltage;
979                                 info("Attached STV0900+STB6100!\n");
980                                 return 0;
981                         }
982                 }
983         }
984
985         if (demod_probe & 2) {
986                 d->fe = dvb_attach(stv0900_attach, &dw2104_stv0900_config,
987                                 &d->dev->i2c_adap, 0);
988                 if (d->fe != NULL) {
989                         if (dvb_attach(stv6110_attach, d->fe,
990                                         &dw2104_stv6110_config,
991                                         &d->dev->i2c_adap)) {
992                                 d->fe->ops.set_voltage = dw210x_set_voltage;
993                                 info("Attached STV0900+STV6110A!\n");
994                                 return 0;
995                         }
996                 }
997         }
998
999         if (demod_probe & 1) {
1000                 d->fe = dvb_attach(cx24116_attach, &dw2104_config,
1001                                 &d->dev->i2c_adap);
1002                 if (d->fe != NULL) {
1003                         d->fe->ops.set_voltage = dw210x_set_voltage;
1004                         info("Attached cx24116!\n");
1005                         return 0;
1006                 }
1007         }
1008
1009         d->fe = dvb_attach(ds3000_attach, &dw2104_ds3000_config,
1010                         &d->dev->i2c_adap);
1011         if (d->fe != NULL) {
1012                 d->fe->ops.set_voltage = dw210x_set_voltage;
1013                 info("Attached DS3000!\n");
1014                 return 0;
1015         }
1016
1017         return -EIO;
1018 }
1019
1020 static struct dvb_usb_device_properties dw2102_properties;
1021 static struct dvb_usb_device_properties dw2104_properties;
1022 static struct dvb_usb_device_properties s6x0_properties;
1023
1024 static int dw2102_frontend_attach(struct dvb_usb_adapter *d)
1025 {
1026         if (dw2102_properties.i2c_algo == &dw2102_serit_i2c_algo) {
1027                 /*dw2102_properties.adapter->tuner_attach = NULL;*/
1028                 d->fe = dvb_attach(si21xx_attach, &serit_sp1511lhb_config,
1029                                         &d->dev->i2c_adap);
1030                 if (d->fe != NULL) {
1031                         d->fe->ops.set_voltage = dw210x_set_voltage;
1032                         info("Attached si21xx!\n");
1033                         return 0;
1034                 }
1035         }
1036
1037         if (dw2102_properties.i2c_algo == &dw2102_earda_i2c_algo) {
1038                 d->fe = dvb_attach(stv0288_attach, &earda_config,
1039                                         &d->dev->i2c_adap);
1040                 if (d->fe != NULL) {
1041                         if (dvb_attach(stb6000_attach, d->fe, 0x61,
1042                                         &d->dev->i2c_adap)) {
1043                                 d->fe->ops.set_voltage = dw210x_set_voltage;
1044                                 info("Attached stv0288!\n");
1045                                 return 0;
1046                         }
1047                 }
1048         }
1049
1050         if (dw2102_properties.i2c_algo == &dw2102_i2c_algo) {
1051                 /*dw2102_properties.adapter->tuner_attach = dw2102_tuner_attach;*/
1052                 d->fe = dvb_attach(stv0299_attach, &sharp_z0194a_config,
1053                                         &d->dev->i2c_adap);
1054                 if (d->fe != NULL) {
1055                         d->fe->ops.set_voltage = dw210x_set_voltage;
1056                         info("Attached stv0299!\n");
1057                         return 0;
1058                 }
1059         }
1060         return -EIO;
1061 }
1062
1063 static int dw3101_frontend_attach(struct dvb_usb_adapter *d)
1064 {
1065         d->fe = dvb_attach(tda10023_attach, &dw3101_tda10023_config,
1066                                 &d->dev->i2c_adap, 0x48);
1067         if (d->fe != NULL) {
1068                 info("Attached tda10023!\n");
1069                 return 0;
1070         }
1071         return -EIO;
1072 }
1073
1074 static int zl100313_frontend_attach(struct dvb_usb_adapter *d)
1075 {
1076         d->fe = dvb_attach(mt312_attach, &zl313_config,
1077                         &d->dev->i2c_adap);
1078         if (d->fe != NULL) {
1079                 if (dvb_attach(zl10039_attach, d->fe, 0x60,
1080                                 &d->dev->i2c_adap)) {
1081                         d->fe->ops.set_voltage = dw210x_set_voltage;
1082                         info("Attached zl100313+zl10039!\n");
1083                         return 0;
1084                 }
1085         }
1086
1087         return -EIO;
1088 }
1089
1090 static int stv0288_frontend_attach(struct dvb_usb_adapter *d)
1091 {
1092         d->fe = dvb_attach(stv0288_attach, &earda_config,
1093                         &d->dev->i2c_adap);
1094         if (d->fe != NULL) {
1095                 if (dvb_attach(stb6000_attach, d->fe, 0x61,
1096                                 &d->dev->i2c_adap)) {
1097                         d->fe->ops.set_voltage = dw210x_set_voltage;
1098                         info("Attached stv0288+stb6000!\n");
1099                         return 0;
1100                 }
1101         }
1102
1103         return -EIO;
1104 }
1105
1106 static int ds3000_frontend_attach(struct dvb_usb_adapter *d)
1107 {
1108         d->fe = dvb_attach(ds3000_attach, &dw2104_ds3000_config,
1109                         &d->dev->i2c_adap);
1110         if (d->fe != NULL) {
1111                 d->fe->ops.set_voltage = dw210x_set_voltage;
1112                 info("Attached ds3000+ds2020!\n");
1113                 return 0;
1114         }
1115
1116         return -EIO;
1117 }
1118
1119 static int prof_7500_frontend_attach(struct dvb_usb_adapter *d)
1120 {
1121         d->fe = dvb_attach(stv0900_attach, &prof_7500_stv0900_config,
1122                                         &d->dev->i2c_adap, 0);
1123         if (d->fe == NULL)
1124                 return -EIO;
1125         d->fe->ops.set_voltage = dw210x_set_voltage;
1126
1127         info("Attached STV0900+STB6100A!\n");
1128
1129         return 0;
1130 }
1131
1132 static int su3000_frontend_attach(struct dvb_usb_adapter *d)
1133 {
1134         u8 obuf[3] = { 0xe, 0x80, 0 };
1135         u8 ibuf[] = { 0 };
1136
1137         if (dvb_usb_generic_rw(d->dev, obuf, 3, ibuf, 1, 0) < 0)
1138                 err("command 0x0e transfer failed.");
1139
1140         obuf[0] = 0xe;
1141         obuf[1] = 0x83;
1142         obuf[2] = 0;
1143
1144         if (dvb_usb_generic_rw(d->dev, obuf, 3, ibuf, 1, 0) < 0)
1145                 err("command 0x0e transfer failed.");
1146
1147         obuf[0] = 0xe;
1148         obuf[1] = 0x83;
1149         obuf[2] = 1;
1150
1151         if (dvb_usb_generic_rw(d->dev, obuf, 3, ibuf, 1, 0) < 0)
1152                 err("command 0x0e transfer failed.");
1153
1154         obuf[0] = 0x51;
1155
1156         if (dvb_usb_generic_rw(d->dev, obuf, 1, ibuf, 1, 0) < 0)
1157                 err("command 0x51 transfer failed.");
1158
1159         d->fe = dvb_attach(ds3000_attach, &su3000_ds3000_config,
1160                                         &d->dev->i2c_adap);
1161         if (d->fe == NULL)
1162                 return -EIO;
1163
1164         info("Attached DS3000!\n");
1165
1166         return 0;
1167 }
1168
1169 static int dw2102_tuner_attach(struct dvb_usb_adapter *adap)
1170 {
1171         dvb_attach(dvb_pll_attach, adap->fe, 0x60,
1172                 &adap->dev->i2c_adap, DVB_PLL_OPERA1);
1173         return 0;
1174 }
1175
1176 static int dw3101_tuner_attach(struct dvb_usb_adapter *adap)
1177 {
1178         dvb_attach(dvb_pll_attach, adap->fe, 0x60,
1179                 &adap->dev->i2c_adap, DVB_PLL_TUA6034);
1180
1181         return 0;
1182 }
1183
1184 static struct rc_map_table rc_map_dw210x_table[] = {
1185         { 0xf80a, KEY_Q },              /*power*/
1186         { 0xf80c, KEY_M },              /*mute*/
1187         { 0xf811, KEY_1 },
1188         { 0xf812, KEY_2 },
1189         { 0xf813, KEY_3 },
1190         { 0xf814, KEY_4 },
1191         { 0xf815, KEY_5 },
1192         { 0xf816, KEY_6 },
1193         { 0xf817, KEY_7 },
1194         { 0xf818, KEY_8 },
1195         { 0xf819, KEY_9 },
1196         { 0xf810, KEY_0 },
1197         { 0xf81c, KEY_PAGEUP }, /*ch+*/
1198         { 0xf80f, KEY_PAGEDOWN },       /*ch-*/
1199         { 0xf81a, KEY_O },              /*vol+*/
1200         { 0xf80e, KEY_Z },              /*vol-*/
1201         { 0xf804, KEY_R },              /*rec*/
1202         { 0xf809, KEY_D },              /*fav*/
1203         { 0xf808, KEY_BACKSPACE },      /*rewind*/
1204         { 0xf807, KEY_A },              /*fast*/
1205         { 0xf80b, KEY_P },              /*pause*/
1206         { 0xf802, KEY_ESC },    /*cancel*/
1207         { 0xf803, KEY_G },              /*tab*/
1208         { 0xf800, KEY_UP },             /*up*/
1209         { 0xf81f, KEY_ENTER },  /*ok*/
1210         { 0xf801, KEY_DOWN },   /*down*/
1211         { 0xf805, KEY_C },              /*cap*/
1212         { 0xf806, KEY_S },              /*stop*/
1213         { 0xf840, KEY_F },              /*full*/
1214         { 0xf81e, KEY_W },              /*tvmode*/
1215         { 0xf81b, KEY_B },              /*recall*/
1216 };
1217
1218 static struct rc_map_table rc_map_tevii_table[] = {
1219         { 0xf80a, KEY_POWER },
1220         { 0xf80c, KEY_MUTE },
1221         { 0xf811, KEY_1 },
1222         { 0xf812, KEY_2 },
1223         { 0xf813, KEY_3 },
1224         { 0xf814, KEY_4 },
1225         { 0xf815, KEY_5 },
1226         { 0xf816, KEY_6 },
1227         { 0xf817, KEY_7 },
1228         { 0xf818, KEY_8 },
1229         { 0xf819, KEY_9 },
1230         { 0xf810, KEY_0 },
1231         { 0xf81c, KEY_MENU },
1232         { 0xf80f, KEY_VOLUMEDOWN },
1233         { 0xf81a, KEY_LAST },
1234         { 0xf80e, KEY_OPEN },
1235         { 0xf804, KEY_RECORD },
1236         { 0xf809, KEY_VOLUMEUP },
1237         { 0xf808, KEY_CHANNELUP },
1238         { 0xf807, KEY_PVR },
1239         { 0xf80b, KEY_TIME },
1240         { 0xf802, KEY_RIGHT },
1241         { 0xf803, KEY_LEFT },
1242         { 0xf800, KEY_UP },
1243         { 0xf81f, KEY_OK },
1244         { 0xf801, KEY_DOWN },
1245         { 0xf805, KEY_TUNER },
1246         { 0xf806, KEY_CHANNELDOWN },
1247         { 0xf840, KEY_PLAYPAUSE },
1248         { 0xf81e, KEY_REWIND },
1249         { 0xf81b, KEY_FAVORITES },
1250         { 0xf81d, KEY_BACK },
1251         { 0xf84d, KEY_FASTFORWARD },
1252         { 0xf844, KEY_EPG },
1253         { 0xf84c, KEY_INFO },
1254         { 0xf841, KEY_AB },
1255         { 0xf843, KEY_AUDIO },
1256         { 0xf845, KEY_SUBTITLE },
1257         { 0xf84a, KEY_LIST },
1258         { 0xf846, KEY_F1 },
1259         { 0xf847, KEY_F2 },
1260         { 0xf85e, KEY_F3 },
1261         { 0xf85c, KEY_F4 },
1262         { 0xf852, KEY_F5 },
1263         { 0xf85a, KEY_F6 },
1264         { 0xf856, KEY_MODE },
1265         { 0xf858, KEY_SWITCHVIDEOMODE },
1266 };
1267
1268 static struct rc_map_table rc_map_tbs_table[] = {
1269         { 0xf884, KEY_POWER },
1270         { 0xf894, KEY_MUTE },
1271         { 0xf887, KEY_1 },
1272         { 0xf886, KEY_2 },
1273         { 0xf885, KEY_3 },
1274         { 0xf88b, KEY_4 },
1275         { 0xf88a, KEY_5 },
1276         { 0xf889, KEY_6 },
1277         { 0xf88f, KEY_7 },
1278         { 0xf88e, KEY_8 },
1279         { 0xf88d, KEY_9 },
1280         { 0xf892, KEY_0 },
1281         { 0xf896, KEY_CHANNELUP },
1282         { 0xf891, KEY_CHANNELDOWN },
1283         { 0xf893, KEY_VOLUMEUP },
1284         { 0xf88c, KEY_VOLUMEDOWN },
1285         { 0xf883, KEY_RECORD },
1286         { 0xf898, KEY_PAUSE  },
1287         { 0xf899, KEY_OK },
1288         { 0xf89a, KEY_SHUFFLE },
1289         { 0xf881, KEY_UP },
1290         { 0xf890, KEY_LEFT },
1291         { 0xf882, KEY_RIGHT },
1292         { 0xf888, KEY_DOWN },
1293         { 0xf895, KEY_FAVORITES },
1294         { 0xf897, KEY_SUBTITLE },
1295         { 0xf89d, KEY_ZOOM },
1296         { 0xf89f, KEY_EXIT },
1297         { 0xf89e, KEY_MENU },
1298         { 0xf89c, KEY_EPG },
1299         { 0xf880, KEY_PREVIOUS },
1300         { 0xf89b, KEY_MODE }
1301 };
1302
1303 static struct rc_map_table rc_map_su3000_table[] = {
1304         { 0x25, KEY_POWER },    /* right-bottom Red */
1305         { 0x0a, KEY_MUTE },     /* -/-- */
1306         { 0x01, KEY_1 },
1307         { 0x02, KEY_2 },
1308         { 0x03, KEY_3 },
1309         { 0x04, KEY_4 },
1310         { 0x05, KEY_5 },
1311         { 0x06, KEY_6 },
1312         { 0x07, KEY_7 },
1313         { 0x08, KEY_8 },
1314         { 0x09, KEY_9 },
1315         { 0x00, KEY_0 },
1316         { 0x20, KEY_UP },       /* CH+ */
1317         { 0x21, KEY_DOWN },     /* CH+ */
1318         { 0x12, KEY_VOLUMEUP }, /* Brightness Up */
1319         { 0x13, KEY_VOLUMEDOWN },/* Brightness Down */
1320         { 0x1f, KEY_RECORD },
1321         { 0x17, KEY_PLAY },
1322         { 0x16, KEY_PAUSE },
1323         { 0x0b, KEY_STOP },
1324         { 0x27, KEY_FASTFORWARD },/* >> */
1325         { 0x26, KEY_REWIND },   /* << */
1326         { 0x0d, KEY_OK },       /* Mute */
1327         { 0x11, KEY_LEFT },     /* VOL- */
1328         { 0x10, KEY_RIGHT },    /* VOL+ */
1329         { 0x29, KEY_BACK },     /* button under 9 */
1330         { 0x2c, KEY_MENU },     /* TTX */
1331         { 0x2b, KEY_EPG },      /* EPG */
1332         { 0x1e, KEY_RED },      /* OSD */
1333         { 0x0e, KEY_GREEN },    /* Window */
1334         { 0x2d, KEY_YELLOW },   /* button under << */
1335         { 0x0f, KEY_BLUE },     /* bottom yellow button */
1336         { 0x14, KEY_AUDIO },    /* Snapshot */
1337         { 0x38, KEY_TV },       /* TV/Radio */
1338         { 0x0c, KEY_ESC }       /* upper Red buttton */
1339 };
1340
1341 static struct rc_map_dvb_usb_table_table keys_tables[] = {
1342         { rc_map_dw210x_table, ARRAY_SIZE(rc_map_dw210x_table) },
1343         { rc_map_tevii_table, ARRAY_SIZE(rc_map_tevii_table) },
1344         { rc_map_tbs_table, ARRAY_SIZE(rc_map_tbs_table) },
1345         { rc_map_su3000_table, ARRAY_SIZE(rc_map_su3000_table) },
1346 };
1347
1348 static int dw2102_rc_query(struct dvb_usb_device *d, u32 *event, int *state)
1349 {
1350         struct rc_map_table *keymap = d->props.rc.legacy.rc_map_table;
1351         int keymap_size = d->props.rc.legacy.rc_map_size;
1352         u8 key[2];
1353         struct i2c_msg msg = {
1354                 .addr = DW2102_RC_QUERY,
1355                 .flags = I2C_M_RD,
1356                 .buf = key,
1357                 .len = 2
1358         };
1359         int i;
1360         /* override keymap */
1361         if ((ir_keymap > 0) && (ir_keymap <= ARRAY_SIZE(keys_tables))) {
1362                 keymap = keys_tables[ir_keymap - 1].rc_keys ;
1363                 keymap_size = keys_tables[ir_keymap - 1].rc_keys_size;
1364         } else if (ir_keymap > ARRAY_SIZE(keys_tables))
1365                 return 0; /* none */
1366
1367         *state = REMOTE_NO_KEY_PRESSED;
1368         if (d->props.i2c_algo->master_xfer(&d->i2c_adap, &msg, 1) == 1) {
1369                 for (i = 0; i < keymap_size ; i++) {
1370                         if (rc5_data(&keymap[i]) == msg.buf[0]) {
1371                                 *state = REMOTE_KEY_PRESSED;
1372                                 *event = keymap[i].keycode;
1373                                 break;
1374                         }
1375
1376                 }
1377
1378                 if ((*state) == REMOTE_KEY_PRESSED)
1379                         deb_rc("%s: found rc key: %x, %x, event: %x\n",
1380                                         __func__, key[0], key[1], (*event));
1381                 else if (key[0] != 0xff)
1382                         deb_rc("%s: unknown rc key: %x, %x\n",
1383                                         __func__, key[0], key[1]);
1384
1385         }
1386
1387         return 0;
1388 }
1389
1390 static struct usb_device_id dw2102_table[] = {
1391         {USB_DEVICE(USB_VID_CYPRESS, USB_PID_DW2102)},
1392         {USB_DEVICE(USB_VID_CYPRESS, 0x2101)},
1393         {USB_DEVICE(USB_VID_CYPRESS, USB_PID_DW2104)},
1394         {USB_DEVICE(0x9022, USB_PID_TEVII_S650)},
1395         {USB_DEVICE(USB_VID_TERRATEC, USB_PID_CINERGY_S)},
1396         {USB_DEVICE(USB_VID_CYPRESS, USB_PID_DW3101)},
1397         {USB_DEVICE(0x9022, USB_PID_TEVII_S630)},
1398         {USB_DEVICE(0x3011, USB_PID_PROF_1100)},
1399         {USB_DEVICE(0x9022, USB_PID_TEVII_S660)},
1400         {USB_DEVICE(0x3034, 0x7500)},
1401         {USB_DEVICE(0x1f4d, 0x3000)},
1402         {USB_DEVICE(USB_VID_TERRATEC, 0x00a8)},
1403         { }
1404 };
1405
1406 MODULE_DEVICE_TABLE(usb, dw2102_table);
1407
1408 static int dw2102_load_firmware(struct usb_device *dev,
1409                         const struct firmware *frmwr)
1410 {
1411         u8 *b, *p;
1412         int ret = 0, i;
1413         u8 reset;
1414         u8 reset16[] = {0, 0, 0, 0, 0, 0, 0};
1415         const struct firmware *fw;
1416         const char *fw_2101 = "dvb-usb-dw2101.fw";
1417
1418         switch (dev->descriptor.idProduct) {
1419         case 0x2101:
1420                 ret = request_firmware(&fw, fw_2101, &dev->dev);
1421                 if (ret != 0) {
1422                         err(err_str, fw_2101);
1423                         return ret;
1424                 }
1425                 break;
1426         default:
1427                 fw = frmwr;
1428                 break;
1429         }
1430         info("start downloading DW210X firmware");
1431         p = kmalloc(fw->size, GFP_KERNEL);
1432         reset = 1;
1433         /*stop the CPU*/
1434         dw210x_op_rw(dev, 0xa0, 0x7f92, 0, &reset, 1, DW210X_WRITE_MSG);
1435         dw210x_op_rw(dev, 0xa0, 0xe600, 0, &reset, 1, DW210X_WRITE_MSG);
1436
1437         if (p != NULL) {
1438                 memcpy(p, fw->data, fw->size);
1439                 for (i = 0; i < fw->size; i += 0x40) {
1440                         b = (u8 *) p + i;
1441                         if (dw210x_op_rw(dev, 0xa0, i, 0, b , 0x40,
1442                                         DW210X_WRITE_MSG) != 0x40) {
1443                                 err("error while transferring firmware");
1444                                 ret = -EINVAL;
1445                                 break;
1446                         }
1447                 }
1448                 /* restart the CPU */
1449                 reset = 0;
1450                 if (ret || dw210x_op_rw(dev, 0xa0, 0x7f92, 0, &reset, 1,
1451                                         DW210X_WRITE_MSG) != 1) {
1452                         err("could not restart the USB controller CPU.");
1453                         ret = -EINVAL;
1454                 }
1455                 if (ret || dw210x_op_rw(dev, 0xa0, 0xe600, 0, &reset, 1,
1456                                         DW210X_WRITE_MSG) != 1) {
1457                         err("could not restart the USB controller CPU.");
1458                         ret = -EINVAL;
1459                 }
1460                 /* init registers */
1461                 switch (dev->descriptor.idProduct) {
1462                 case USB_PID_PROF_1100:
1463                         s6x0_properties.rc.legacy.rc_map_table = rc_map_tbs_table;
1464                         s6x0_properties.rc.legacy.rc_map_size =
1465                                         ARRAY_SIZE(rc_map_tbs_table);
1466                         break;
1467                 case USB_PID_TEVII_S650:
1468                         dw2104_properties.rc.legacy.rc_map_table = rc_map_tevii_table;
1469                         dw2104_properties.rc.legacy.rc_map_size =
1470                                         ARRAY_SIZE(rc_map_tevii_table);
1471                 case USB_PID_DW2104:
1472                         reset = 1;
1473                         dw210x_op_rw(dev, 0xc4, 0x0000, 0, &reset, 1,
1474                                         DW210X_WRITE_MSG);
1475                         /* break omitted intentionally */
1476                 case USB_PID_DW3101:
1477                         reset = 0;
1478                         dw210x_op_rw(dev, 0xbf, 0x0040, 0, &reset, 0,
1479                                         DW210X_WRITE_MSG);
1480                         break;
1481                 case USB_PID_CINERGY_S:
1482                 case USB_PID_DW2102:
1483                         dw210x_op_rw(dev, 0xbf, 0x0040, 0, &reset, 0,
1484                                         DW210X_WRITE_MSG);
1485                         dw210x_op_rw(dev, 0xb9, 0x0000, 0, &reset16[0], 2,
1486                                         DW210X_READ_MSG);
1487                         /* check STV0299 frontend  */
1488                         dw210x_op_rw(dev, 0xb5, 0, 0, &reset16[0], 2,
1489                                         DW210X_READ_MSG);
1490                         if ((reset16[0] == 0xa1) || (reset16[0] == 0x80)) {
1491                                 dw2102_properties.i2c_algo = &dw2102_i2c_algo;
1492                                 dw2102_properties.adapter->tuner_attach = &dw2102_tuner_attach;
1493                                 break;
1494                         } else {
1495                                 /* check STV0288 frontend  */
1496                                 reset16[0] = 0xd0;
1497                                 reset16[1] = 1;
1498                                 reset16[2] = 0;
1499                                 dw210x_op_rw(dev, 0xc2, 0, 0, &reset16[0], 3,
1500                                                 DW210X_WRITE_MSG);
1501                                 dw210x_op_rw(dev, 0xc3, 0xd1, 0, &reset16[0], 3,
1502                                                 DW210X_READ_MSG);
1503                                 if (reset16[2] == 0x11) {
1504                                         dw2102_properties.i2c_algo = &dw2102_earda_i2c_algo;
1505                                         break;
1506                                 }
1507                         }
1508                 case 0x2101:
1509                         dw210x_op_rw(dev, 0xbc, 0x0030, 0, &reset16[0], 2,
1510                                         DW210X_READ_MSG);
1511                         dw210x_op_rw(dev, 0xba, 0x0000, 0, &reset16[0], 7,
1512                                         DW210X_READ_MSG);
1513                         dw210x_op_rw(dev, 0xba, 0x0000, 0, &reset16[0], 7,
1514                                         DW210X_READ_MSG);
1515                         dw210x_op_rw(dev, 0xb9, 0x0000, 0, &reset16[0], 2,
1516                                         DW210X_READ_MSG);
1517                         break;
1518                 }
1519
1520                 msleep(100);
1521                 kfree(p);
1522         }
1523         return ret;
1524 }
1525
1526 static struct dvb_usb_device_properties dw2102_properties = {
1527         .caps = DVB_USB_IS_AN_I2C_ADAPTER,
1528         .usb_ctrl = DEVICE_SPECIFIC,
1529         .firmware = "dvb-usb-dw2102.fw",
1530         .no_reconnect = 1,
1531
1532         .i2c_algo = &dw2102_serit_i2c_algo,
1533
1534         .rc.legacy = {
1535                 .rc_map_table = rc_map_dw210x_table,
1536                 .rc_map_size = ARRAY_SIZE(rc_map_dw210x_table),
1537                 .rc_interval = 150,
1538                 .rc_query = dw2102_rc_query,
1539         },
1540
1541         .generic_bulk_ctrl_endpoint = 0x81,
1542         /* parameter for the MPEG2-data transfer */
1543         .num_adapters = 1,
1544         .download_firmware = dw2102_load_firmware,
1545         .read_mac_address = dw210x_read_mac_address,
1546         .adapter = {
1547                 {
1548                         .frontend_attach = dw2102_frontend_attach,
1549                         .streaming_ctrl = NULL,
1550                         .tuner_attach = NULL,
1551                         .stream = {
1552                                 .type = USB_BULK,
1553                                 .count = 8,
1554                                 .endpoint = 0x82,
1555                                 .u = {
1556                                         .bulk = {
1557                                                 .buffersize = 4096,
1558                                         }
1559                                 }
1560                         },
1561                 }
1562         },
1563         .num_device_descs = 3,
1564         .devices = {
1565                 {"DVBWorld DVB-S 2102 USB2.0",
1566                         {&dw2102_table[0], NULL},
1567                         {NULL},
1568                 },
1569                 {"DVBWorld DVB-S 2101 USB2.0",
1570                         {&dw2102_table[1], NULL},
1571                         {NULL},
1572                 },
1573                 {"TerraTec Cinergy S USB",
1574                         {&dw2102_table[4], NULL},
1575                         {NULL},
1576                 },
1577         }
1578 };
1579
1580 static struct dvb_usb_device_properties dw2104_properties = {
1581         .caps = DVB_USB_IS_AN_I2C_ADAPTER,
1582         .usb_ctrl = DEVICE_SPECIFIC,
1583         .firmware = "dvb-usb-dw2104.fw",
1584         .no_reconnect = 1,
1585
1586         .i2c_algo = &dw2104_i2c_algo,
1587         .rc.legacy = {
1588                 .rc_map_table = rc_map_dw210x_table,
1589                 .rc_map_size = ARRAY_SIZE(rc_map_dw210x_table),
1590                 .rc_interval = 150,
1591                 .rc_query = dw2102_rc_query,
1592         },
1593
1594         .generic_bulk_ctrl_endpoint = 0x81,
1595         /* parameter for the MPEG2-data transfer */
1596         .num_adapters = 1,
1597         .download_firmware = dw2102_load_firmware,
1598         .read_mac_address = dw210x_read_mac_address,
1599         .adapter = {
1600                 {
1601                         .frontend_attach = dw2104_frontend_attach,
1602                         .streaming_ctrl = NULL,
1603                         /*.tuner_attach = dw2104_tuner_attach,*/
1604                         .stream = {
1605                                 .type = USB_BULK,
1606                                 .count = 8,
1607                                 .endpoint = 0x82,
1608                                 .u = {
1609                                         .bulk = {
1610                                                 .buffersize = 4096,
1611                                         }
1612                                 }
1613                         },
1614                 }
1615         },
1616         .num_device_descs = 2,
1617         .devices = {
1618                 { "DVBWorld DW2104 USB2.0",
1619                         {&dw2102_table[2], NULL},
1620                         {NULL},
1621                 },
1622                 { "TeVii S650 USB2.0",
1623                         {&dw2102_table[3], NULL},
1624                         {NULL},
1625                 },
1626         }
1627 };
1628
1629 static struct dvb_usb_device_properties dw3101_properties = {
1630         .caps = DVB_USB_IS_AN_I2C_ADAPTER,
1631         .usb_ctrl = DEVICE_SPECIFIC,
1632         .firmware = "dvb-usb-dw3101.fw",
1633         .no_reconnect = 1,
1634
1635         .i2c_algo = &dw3101_i2c_algo,
1636         .rc.legacy = {
1637                 .rc_map_table = rc_map_dw210x_table,
1638                 .rc_map_size = ARRAY_SIZE(rc_map_dw210x_table),
1639                 .rc_interval = 150,
1640                 .rc_query = dw2102_rc_query,
1641         },
1642
1643         .generic_bulk_ctrl_endpoint = 0x81,
1644         /* parameter for the MPEG2-data transfer */
1645         .num_adapters = 1,
1646         .download_firmware = dw2102_load_firmware,
1647         .read_mac_address = dw210x_read_mac_address,
1648         .adapter = {
1649                 {
1650                         .frontend_attach = dw3101_frontend_attach,
1651                         .streaming_ctrl = NULL,
1652                         .tuner_attach = dw3101_tuner_attach,
1653                         .stream = {
1654                                 .type = USB_BULK,
1655                                 .count = 8,
1656                                 .endpoint = 0x82,
1657                                 .u = {
1658                                         .bulk = {
1659                                                 .buffersize = 4096,
1660                                         }
1661                                 }
1662                         },
1663                 }
1664         },
1665         .num_device_descs = 1,
1666         .devices = {
1667                 { "DVBWorld DVB-C 3101 USB2.0",
1668                         {&dw2102_table[5], NULL},
1669                         {NULL},
1670                 },
1671         }
1672 };
1673
1674 static struct dvb_usb_device_properties s6x0_properties = {
1675         .caps = DVB_USB_IS_AN_I2C_ADAPTER,
1676         .usb_ctrl = DEVICE_SPECIFIC,
1677         .firmware = "dvb-usb-s630.fw",
1678         .no_reconnect = 1,
1679
1680         .i2c_algo = &s6x0_i2c_algo,
1681         .rc.legacy = {
1682                 .rc_map_table = rc_map_tevii_table,
1683                 .rc_map_size = ARRAY_SIZE(rc_map_tevii_table),
1684                 .rc_interval = 150,
1685                 .rc_query = dw2102_rc_query,
1686         },
1687
1688         .generic_bulk_ctrl_endpoint = 0x81,
1689         .num_adapters = 1,
1690         .download_firmware = dw2102_load_firmware,
1691         .read_mac_address = s6x0_read_mac_address,
1692         .adapter = {
1693                 {
1694                         .frontend_attach = zl100313_frontend_attach,
1695                         .streaming_ctrl = NULL,
1696                         .tuner_attach = NULL,
1697                         .stream = {
1698                                 .type = USB_BULK,
1699                                 .count = 8,
1700                                 .endpoint = 0x82,
1701                                 .u = {
1702                                         .bulk = {
1703                                                 .buffersize = 4096,
1704                                         }
1705                                 }
1706                         },
1707                 }
1708         },
1709         .num_device_descs = 1,
1710         .devices = {
1711                 {"TeVii S630 USB",
1712                         {&dw2102_table[6], NULL},
1713                         {NULL},
1714                 },
1715         }
1716 };
1717
1718 struct dvb_usb_device_properties *p1100;
1719 static struct dvb_usb_device_description d1100 = {
1720         "Prof 1100 USB ",
1721         {&dw2102_table[7], NULL},
1722         {NULL},
1723 };
1724
1725 struct dvb_usb_device_properties *s660;
1726 static struct dvb_usb_device_description d660 = {
1727         "TeVii S660 USB",
1728         {&dw2102_table[8], NULL},
1729         {NULL},
1730 };
1731
1732 struct dvb_usb_device_properties *p7500;
1733 static struct dvb_usb_device_description d7500 = {
1734         "Prof 7500 USB DVB-S2",
1735         {&dw2102_table[9], NULL},
1736         {NULL},
1737 };
1738
1739 static struct dvb_usb_device_properties su3000_properties = {
1740         .caps = DVB_USB_IS_AN_I2C_ADAPTER,
1741         .usb_ctrl = DEVICE_SPECIFIC,
1742         .size_of_priv = sizeof(struct su3000_state),
1743         .power_ctrl = su3000_power_ctrl,
1744         .num_adapters = 1,
1745         .identify_state = su3000_identify_state,
1746         .i2c_algo = &su3000_i2c_algo,
1747
1748         .rc.legacy = {
1749                 .rc_map_table = rc_map_su3000_table,
1750                 .rc_map_size = ARRAY_SIZE(rc_map_su3000_table),
1751                 .rc_interval = 150,
1752                 .rc_query = dw2102_rc_query,
1753         },
1754
1755         .read_mac_address = su3000_read_mac_address,
1756
1757         .generic_bulk_ctrl_endpoint = 0x01,
1758
1759         .adapter = {
1760                 {
1761                         .streaming_ctrl   = su3000_streaming_ctrl,
1762                         .frontend_attach  = su3000_frontend_attach,
1763                         .stream = {
1764                                 .type = USB_BULK,
1765                                 .count = 8,
1766                                 .endpoint = 0x82,
1767                                 .u = {
1768                                         .bulk = {
1769                                                 .buffersize = 4096,
1770                                         }
1771                                 }
1772                         }
1773                 }
1774         },
1775         .num_device_descs = 2,
1776         .devices = {
1777                 { "SU3000HD DVB-S USB2.0",
1778                         { &dw2102_table[10], NULL },
1779                         { NULL },
1780                 },
1781                 { "Terratec Cinergy S2 USB HD",
1782                         { &dw2102_table[11], NULL },
1783                         { NULL },
1784                 },
1785         }
1786 };
1787
1788 static int dw2102_probe(struct usb_interface *intf,
1789                 const struct usb_device_id *id)
1790 {
1791         p1100 = kzalloc(sizeof(struct dvb_usb_device_properties), GFP_KERNEL);
1792         if (!p1100)
1793                 return -ENOMEM;
1794         /* copy default structure */
1795         memcpy(p1100, &s6x0_properties,
1796                         sizeof(struct dvb_usb_device_properties));
1797         /* fill only different fields */
1798         p1100->firmware = "dvb-usb-p1100.fw";
1799         p1100->devices[0] = d1100;
1800         p1100->rc.legacy.rc_map_table = rc_map_tbs_table;
1801         p1100->rc.legacy.rc_map_size = ARRAY_SIZE(rc_map_tbs_table);
1802         p1100->adapter->frontend_attach = stv0288_frontend_attach;
1803
1804         s660 = kzalloc(sizeof(struct dvb_usb_device_properties), GFP_KERNEL);
1805         if (!s660) {
1806                 kfree(p1100);
1807                 return -ENOMEM;
1808         }
1809         memcpy(s660, &s6x0_properties,
1810                         sizeof(struct dvb_usb_device_properties));
1811         s660->firmware = "dvb-usb-s660.fw";
1812         s660->devices[0] = d660;
1813         s660->adapter->frontend_attach = ds3000_frontend_attach;
1814
1815         p7500 = kzalloc(sizeof(struct dvb_usb_device_properties), GFP_KERNEL);
1816         if (!p7500) {
1817                 kfree(p1100);
1818                 kfree(s660);
1819                 return -ENOMEM;
1820         }
1821         memcpy(p7500, &s6x0_properties,
1822                         sizeof(struct dvb_usb_device_properties));
1823         p7500->firmware = "dvb-usb-p7500.fw";
1824         p7500->devices[0] = d7500;
1825         p7500->rc.legacy.rc_map_table = rc_map_tbs_table;
1826         p7500->rc.legacy.rc_map_size = ARRAY_SIZE(rc_map_tbs_table);
1827         p7500->adapter->frontend_attach = prof_7500_frontend_attach;
1828
1829         if (0 == dvb_usb_device_init(intf, &dw2102_properties,
1830                         THIS_MODULE, NULL, adapter_nr) ||
1831             0 == dvb_usb_device_init(intf, &dw2104_properties,
1832                         THIS_MODULE, NULL, adapter_nr) ||
1833             0 == dvb_usb_device_init(intf, &dw3101_properties,
1834                         THIS_MODULE, NULL, adapter_nr) ||
1835             0 == dvb_usb_device_init(intf, &s6x0_properties,
1836                         THIS_MODULE, NULL, adapter_nr) ||
1837             0 == dvb_usb_device_init(intf, p1100,
1838                         THIS_MODULE, NULL, adapter_nr) ||
1839             0 == dvb_usb_device_init(intf, s660,
1840                         THIS_MODULE, NULL, adapter_nr) ||
1841             0 == dvb_usb_device_init(intf, p7500,
1842                         THIS_MODULE, NULL, adapter_nr) ||
1843             0 == dvb_usb_device_init(intf, &su3000_properties,
1844                                      THIS_MODULE, NULL, adapter_nr))
1845                 return 0;
1846
1847         return -ENODEV;
1848 }
1849
1850 static struct usb_driver dw2102_driver = {
1851         .name = "dw2102",
1852         .probe = dw2102_probe,
1853         .disconnect = dvb_usb_device_exit,
1854         .id_table = dw2102_table,
1855 };
1856
1857 static int __init dw2102_module_init(void)
1858 {
1859         int ret =  usb_register(&dw2102_driver);
1860         if (ret)
1861                 err("usb_register failed. Error number %d", ret);
1862
1863         return ret;
1864 }
1865
1866 static void __exit dw2102_module_exit(void)
1867 {
1868         usb_deregister(&dw2102_driver);
1869 }
1870
1871 module_init(dw2102_module_init);
1872 module_exit(dw2102_module_exit);
1873
1874 MODULE_AUTHOR("Igor M. Liplianin (c) liplianin@me.by");
1875 MODULE_DESCRIPTION("Driver for DVBWorld DVB-S 2101, 2102, DVB-S2 2104,"
1876                                 " DVB-C 3101 USB2.0,"
1877                                 " TeVii S600, S630, S650, S660 USB2.0,"
1878                                 " Prof 1100, 7500 USB2.0,"
1879                                 " Geniatech SU3000 devices");
1880 MODULE_VERSION("0.1");
1881 MODULE_LICENSE("GPL");