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