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