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