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