xref: /linux/drivers/media/usb/dvb-usb/dw2102.c (revision 6fd600d742744dc7ef7fc65ca26daa2b1163158a)
1a10e763bSThomas Gleixner // SPDX-License-Identifier: GPL-2.0-only
2786baecfSMauro Carvalho Chehab /* DVB USB framework compliant Linux driver for the
3786baecfSMauro Carvalho Chehab  *	DVBWorld DVB-S 2101, 2102, DVB-S2 2104, DVB-C 3101,
46ede20f9SOlli Salonen  *	TeVii S421, S480, S482, S600, S630, S632, S650, S660, S662,
5786baecfSMauro Carvalho Chehab  *	Prof 1100, 7500,
627254c36SOlli Salonen  *	Geniatech SU3000, T220,
76ede20f9SOlli Salonen  *	TechnoTrend S2-4600,
86ede20f9SOlli Salonen  *	Terratec Cinergy S2 cards
9955d00acSIgor M. Liplianin  * Copyright (C) 2008-2012 Igor M. Liplianin (liplianin@me.by)
10786baecfSMauro Carvalho Chehab  *
11577a7ad3SMauro Carvalho Chehab  * see Documentation/driver-api/media/drivers/dvb-usb.rst for more information
12786baecfSMauro Carvalho Chehab  */
13fada1935SMauro Carvalho Chehab #include <media/dvb-usb-ids.h>
14786baecfSMauro Carvalho Chehab #include "dw2102.h"
15786baecfSMauro Carvalho Chehab #include "si21xx.h"
16786baecfSMauro Carvalho Chehab #include "stv0299.h"
17786baecfSMauro Carvalho Chehab #include "z0194a.h"
18786baecfSMauro Carvalho Chehab #include "stv0288.h"
19786baecfSMauro Carvalho Chehab #include "stb6000.h"
20786baecfSMauro Carvalho Chehab #include "eds1547.h"
21786baecfSMauro Carvalho Chehab #include "cx24116.h"
22786baecfSMauro Carvalho Chehab #include "tda1002x.h"
23786baecfSMauro Carvalho Chehab #include "mt312.h"
24786baecfSMauro Carvalho Chehab #include "zl10039.h"
2573f0af44SKonstantin Dimitrov #include "ts2020.h"
26786baecfSMauro Carvalho Chehab #include "ds3000.h"
27786baecfSMauro Carvalho Chehab #include "stv0900.h"
28786baecfSMauro Carvalho Chehab #include "stv6110.h"
29786baecfSMauro Carvalho Chehab #include "stb6100.h"
30786baecfSMauro Carvalho Chehab #include "stb6100_proc.h"
31955d00acSIgor M. Liplianin #include "m88rs2000.h"
3251d882edSEvgeny Plehov #include "tda18271.h"
3351d882edSEvgeny Plehov #include "cxd2820r.h"
3427254c36SOlli Salonen #include "m88ds3103.h"
35786baecfSMauro Carvalho Chehab 
360065a79aSMauro Carvalho Chehab /* Max transfer size done by I2C transfer functions */
370065a79aSMauro Carvalho Chehab #define MAX_XFER_SIZE  64
380065a79aSMauro Carvalho Chehab 
39786baecfSMauro Carvalho Chehab #define DW210X_READ_MSG 0
40786baecfSMauro Carvalho Chehab #define DW210X_WRITE_MSG 1
41786baecfSMauro Carvalho Chehab 
42786baecfSMauro Carvalho Chehab #define REG_1F_SYMBOLRATE_BYTE0 0x1f
43786baecfSMauro Carvalho Chehab #define REG_20_SYMBOLRATE_BYTE1 0x20
44786baecfSMauro Carvalho Chehab #define REG_21_SYMBOLRATE_BYTE2 0x21
45786baecfSMauro Carvalho Chehab /* on my own*/
46786baecfSMauro Carvalho Chehab #define DW2102_VOLTAGE_CTRL (0x1800)
47786baecfSMauro Carvalho Chehab #define SU3000_STREAM_CTRL (0x1900)
48786baecfSMauro Carvalho Chehab #define DW2102_RC_QUERY (0x1a00)
49786baecfSMauro Carvalho Chehab #define DW2102_LED_CTRL (0x1b00)
50786baecfSMauro Carvalho Chehab 
516823627bSRémi Cardona #define DW2101_FIRMWARE "dvb-usb-dw2101.fw"
526823627bSRémi Cardona #define DW2102_FIRMWARE "dvb-usb-dw2102.fw"
536823627bSRémi Cardona #define DW2104_FIRMWARE "dvb-usb-dw2104.fw"
546823627bSRémi Cardona #define DW3101_FIRMWARE "dvb-usb-dw3101.fw"
556823627bSRémi Cardona #define S630_FIRMWARE	"dvb-usb-s630.fw"
566823627bSRémi Cardona #define S660_FIRMWARE	"dvb-usb-s660.fw"
576823627bSRémi Cardona #define P1100_FIRMWARE	"dvb-usb-p1100.fw"
586823627bSRémi Cardona #define P7500_FIRMWARE	"dvb-usb-p7500.fw"
596823627bSRémi Cardona 
60fe63a1a6SMauro Carvalho Chehab #define	err_str "did not find the firmware file '%s'. You can use <kernel_dir>/scripts/get_dvb_firmware to get the firmware"
61786baecfSMauro Carvalho Chehab 
622c4ffe27SOlli Salonen struct dw2102_state {
63786baecfSMauro Carvalho Chehab 	u8 initialized;
64356484caSOlli Salonen 	u8 last_lock;
65606142afSJonathan McDowell 	u8 data[MAX_XFER_SIZE + 4];
66f3c6abcaSOlli Salonen 	struct i2c_client *i2c_client_demod;
6770769b24SOlli Salonen 	struct i2c_client *i2c_client_tuner;
68356484caSOlli Salonen 
69356484caSOlli Salonen 	/* fe hook functions*/
700df289a2SMauro Carvalho Chehab 	int (*old_set_voltage)(struct dvb_frontend *f, enum fe_sec_voltage v);
71356484caSOlli Salonen 	int (*fe_read_status)(struct dvb_frontend *fe,
720df289a2SMauro Carvalho Chehab 			      enum fe_status *status);
73786baecfSMauro Carvalho Chehab };
74786baecfSMauro Carvalho Chehab 
75786baecfSMauro Carvalho Chehab /* debug */
76786baecfSMauro Carvalho Chehab static int dvb_usb_dw2102_debug;
77786baecfSMauro Carvalho Chehab module_param_named(debug, dvb_usb_dw2102_debug, int, 0644);
78786baecfSMauro Carvalho Chehab MODULE_PARM_DESC(debug, "set debugging level (1=info 2=xfer 4=rc(or-able))."
79786baecfSMauro Carvalho Chehab 						DVB_USB_DEBUG_STATUS);
80786baecfSMauro Carvalho Chehab 
81786baecfSMauro Carvalho Chehab /* demod probe */
82786baecfSMauro Carvalho Chehab static int demod_probe = 1;
83786baecfSMauro Carvalho Chehab module_param_named(demod, demod_probe, int, 0644);
84f319ed91SMauro Carvalho Chehab MODULE_PARM_DESC(demod, "demod to probe (1=cx24116 2=stv0903+stv6110 4=stv0903+stb6100(or-able)).");
85786baecfSMauro Carvalho Chehab 
86786baecfSMauro Carvalho Chehab DVB_DEFINE_MOD_OPT_ADAPTER_NR(adapter_nr);
87786baecfSMauro Carvalho Chehab 
dw210x_op_rw(struct usb_device * dev,u8 request,u16 value,u16 index,u8 * data,u16 len,int flags)88786baecfSMauro Carvalho Chehab static int dw210x_op_rw(struct usb_device *dev, u8 request, u16 value,
89786baecfSMauro Carvalho Chehab 			u16 index, u8 *data, u16 len, int flags)
90786baecfSMauro Carvalho Chehab {
91786baecfSMauro Carvalho Chehab 	int ret;
92786baecfSMauro Carvalho Chehab 	u8 *u8buf;
93786baecfSMauro Carvalho Chehab 	unsigned int pipe = (flags == DW210X_READ_MSG) ?
94786baecfSMauro Carvalho Chehab 				usb_rcvctrlpipe(dev, 0) : usb_sndctrlpipe(dev, 0);
95786baecfSMauro Carvalho Chehab 	u8 request_type = (flags == DW210X_READ_MSG) ? USB_DIR_IN : USB_DIR_OUT;
96786baecfSMauro Carvalho Chehab 
97786baecfSMauro Carvalho Chehab 	u8buf = kmalloc(len, GFP_KERNEL);
98786baecfSMauro Carvalho Chehab 	if (!u8buf)
99786baecfSMauro Carvalho Chehab 		return -ENOMEM;
100786baecfSMauro Carvalho Chehab 
101786baecfSMauro Carvalho Chehab 	if (flags == DW210X_WRITE_MSG)
102786baecfSMauro Carvalho Chehab 		memcpy(u8buf, data, len);
103786baecfSMauro Carvalho Chehab 	ret = usb_control_msg(dev, pipe, request, request_type | USB_TYPE_VENDOR,
104786baecfSMauro Carvalho Chehab 			      value, index, u8buf, len, 2000);
105786baecfSMauro Carvalho Chehab 
106786baecfSMauro Carvalho Chehab 	if (flags == DW210X_READ_MSG)
107786baecfSMauro Carvalho Chehab 		memcpy(data, u8buf, len);
108786baecfSMauro Carvalho Chehab 
109786baecfSMauro Carvalho Chehab 	kfree(u8buf);
110786baecfSMauro Carvalho Chehab 	return ret;
111786baecfSMauro Carvalho Chehab }
112786baecfSMauro Carvalho Chehab 
113786baecfSMauro Carvalho Chehab /* I2C */
dw2102_i2c_transfer(struct i2c_adapter * adap,struct i2c_msg msg[],int num)114786baecfSMauro Carvalho Chehab static int dw2102_i2c_transfer(struct i2c_adapter *adap, struct i2c_msg msg[],
115786baecfSMauro Carvalho Chehab 			       int num)
116786baecfSMauro Carvalho Chehab {
117786baecfSMauro Carvalho Chehab 	struct dvb_usb_device *d = i2c_get_adapdata(adap);
118786baecfSMauro Carvalho Chehab 	int i = 0;
119786baecfSMauro Carvalho Chehab 	u8 buf6[] = {0x2c, 0x05, 0xc0, 0, 0, 0, 0};
120786baecfSMauro Carvalho Chehab 	u16 value;
121786baecfSMauro Carvalho Chehab 
122786baecfSMauro Carvalho Chehab 	if (!d)
123786baecfSMauro Carvalho Chehab 		return -ENODEV;
124786baecfSMauro Carvalho Chehab 	if (mutex_lock_interruptible(&d->i2c_mutex) < 0)
125786baecfSMauro Carvalho Chehab 		return -EAGAIN;
126786baecfSMauro Carvalho Chehab 
127786baecfSMauro Carvalho Chehab 	switch (num) {
128786baecfSMauro Carvalho Chehab 	case 2:
1295ae544d9SZhang Shurong 		if (msg[0].len < 1) {
1305ae544d9SZhang Shurong 			num = -EOPNOTSUPP;
1315ae544d9SZhang Shurong 			break;
1325ae544d9SZhang Shurong 		}
133786baecfSMauro Carvalho Chehab 		/* read stv0299 register */
134786baecfSMauro Carvalho Chehab 		value = msg[0].buf[0];/* register */
135786baecfSMauro Carvalho Chehab 		for (i = 0; i < msg[1].len; i++) {
136786baecfSMauro Carvalho Chehab 			dw210x_op_rw(d->udev, 0xb5, value + i, 0,
137786baecfSMauro Carvalho Chehab 				     buf6, 2, DW210X_READ_MSG);
138786baecfSMauro Carvalho Chehab 			msg[1].buf[i] = buf6[0];
139786baecfSMauro Carvalho Chehab 		}
140786baecfSMauro Carvalho Chehab 		break;
141786baecfSMauro Carvalho Chehab 	case 1:
142786baecfSMauro Carvalho Chehab 		switch (msg[0].addr) {
143786baecfSMauro Carvalho Chehab 		case 0x68:
1445ae544d9SZhang Shurong 			if (msg[0].len < 2) {
1455ae544d9SZhang Shurong 				num = -EOPNOTSUPP;
1465ae544d9SZhang Shurong 				break;
1475ae544d9SZhang Shurong 			}
148786baecfSMauro Carvalho Chehab 			/* write to stv0299 register */
149786baecfSMauro Carvalho Chehab 			buf6[0] = 0x2a;
150786baecfSMauro Carvalho Chehab 			buf6[1] = msg[0].buf[0];
151786baecfSMauro Carvalho Chehab 			buf6[2] = msg[0].buf[1];
152786baecfSMauro Carvalho Chehab 			dw210x_op_rw(d->udev, 0xb2, 0, 0,
153786baecfSMauro Carvalho Chehab 				     buf6, 3, DW210X_WRITE_MSG);
154786baecfSMauro Carvalho Chehab 			break;
155786baecfSMauro Carvalho Chehab 		case 0x60:
156786baecfSMauro Carvalho Chehab 			if (msg[0].flags == 0) {
1575ae544d9SZhang Shurong 				if (msg[0].len < 4) {
1585ae544d9SZhang Shurong 					num = -EOPNOTSUPP;
1595ae544d9SZhang Shurong 					break;
1605ae544d9SZhang Shurong 				}
161786baecfSMauro Carvalho Chehab 			/* write to tuner pll */
162786baecfSMauro Carvalho Chehab 				buf6[0] = 0x2c;
163786baecfSMauro Carvalho Chehab 				buf6[1] = 5;
164786baecfSMauro Carvalho Chehab 				buf6[2] = 0xc0;
165786baecfSMauro Carvalho Chehab 				buf6[3] = msg[0].buf[0];
166786baecfSMauro Carvalho Chehab 				buf6[4] = msg[0].buf[1];
167786baecfSMauro Carvalho Chehab 				buf6[5] = msg[0].buf[2];
168786baecfSMauro Carvalho Chehab 				buf6[6] = msg[0].buf[3];
169786baecfSMauro Carvalho Chehab 				dw210x_op_rw(d->udev, 0xb2, 0, 0,
170786baecfSMauro Carvalho Chehab 					     buf6, 7, DW210X_WRITE_MSG);
171786baecfSMauro Carvalho Chehab 			} else {
1725ae544d9SZhang Shurong 				if (msg[0].len < 1) {
1735ae544d9SZhang Shurong 					num = -EOPNOTSUPP;
1745ae544d9SZhang Shurong 					break;
1755ae544d9SZhang Shurong 				}
176786baecfSMauro Carvalho Chehab 			/* read from tuner */
177786baecfSMauro Carvalho Chehab 				dw210x_op_rw(d->udev, 0xb5, 0, 0,
178786baecfSMauro Carvalho Chehab 					     buf6, 1, DW210X_READ_MSG);
179786baecfSMauro Carvalho Chehab 				msg[0].buf[0] = buf6[0];
180786baecfSMauro Carvalho Chehab 			}
181786baecfSMauro Carvalho Chehab 			break;
182786baecfSMauro Carvalho Chehab 		case (DW2102_RC_QUERY):
1835ae544d9SZhang Shurong 			if (msg[0].len < 2) {
1845ae544d9SZhang Shurong 				num = -EOPNOTSUPP;
1855ae544d9SZhang Shurong 				break;
1865ae544d9SZhang Shurong 			}
187786baecfSMauro Carvalho Chehab 			dw210x_op_rw(d->udev, 0xb8, 0, 0,
188786baecfSMauro Carvalho Chehab 				     buf6, 2, DW210X_READ_MSG);
189786baecfSMauro Carvalho Chehab 			msg[0].buf[0] = buf6[0];
190786baecfSMauro Carvalho Chehab 			msg[0].buf[1] = buf6[1];
191786baecfSMauro Carvalho Chehab 			break;
192786baecfSMauro Carvalho Chehab 		case (DW2102_VOLTAGE_CTRL):
1935ae544d9SZhang Shurong 			if (msg[0].len < 1) {
1945ae544d9SZhang Shurong 				num = -EOPNOTSUPP;
1955ae544d9SZhang Shurong 				break;
1965ae544d9SZhang Shurong 			}
197786baecfSMauro Carvalho Chehab 			buf6[0] = 0x30;
198786baecfSMauro Carvalho Chehab 			buf6[1] = msg[0].buf[0];
199786baecfSMauro Carvalho Chehab 			dw210x_op_rw(d->udev, 0xb2, 0, 0,
200786baecfSMauro Carvalho Chehab 				     buf6, 2, DW210X_WRITE_MSG);
201786baecfSMauro Carvalho Chehab 			break;
202786baecfSMauro Carvalho Chehab 		}
203786baecfSMauro Carvalho Chehab 
204786baecfSMauro Carvalho Chehab 		break;
205786baecfSMauro Carvalho Chehab 	}
206786baecfSMauro Carvalho Chehab 
207786baecfSMauro Carvalho Chehab 	mutex_unlock(&d->i2c_mutex);
208786baecfSMauro Carvalho Chehab 	return num;
209786baecfSMauro Carvalho Chehab }
210786baecfSMauro Carvalho Chehab 
dw2102_serit_i2c_transfer(struct i2c_adapter * adap,struct i2c_msg msg[],int num)211786baecfSMauro Carvalho Chehab static int dw2102_serit_i2c_transfer(struct i2c_adapter *adap,
212786baecfSMauro Carvalho Chehab 				     struct i2c_msg msg[], int num)
213786baecfSMauro Carvalho Chehab {
214786baecfSMauro Carvalho Chehab 	struct dvb_usb_device *d = i2c_get_adapdata(adap);
215786baecfSMauro Carvalho Chehab 	u8 buf6[] = {0, 0, 0, 0, 0, 0, 0};
216786baecfSMauro Carvalho Chehab 
217786baecfSMauro Carvalho Chehab 	if (!d)
218786baecfSMauro Carvalho Chehab 		return -ENODEV;
219786baecfSMauro Carvalho Chehab 	if (mutex_lock_interruptible(&d->i2c_mutex) < 0)
220786baecfSMauro Carvalho Chehab 		return -EAGAIN;
221786baecfSMauro Carvalho Chehab 
222786baecfSMauro Carvalho Chehab 	switch (num) {
223786baecfSMauro Carvalho Chehab 	case 2:
224950e252cSAlyssa Milburn 		if (msg[0].len != 1) {
225950e252cSAlyssa Milburn 			warn("i2c rd: len=%d is not 1!\n",
226950e252cSAlyssa Milburn 			     msg[0].len);
227950e252cSAlyssa Milburn 			num = -EOPNOTSUPP;
228950e252cSAlyssa Milburn 			break;
229950e252cSAlyssa Milburn 		}
230950e252cSAlyssa Milburn 
231950e252cSAlyssa Milburn 		if (2 + msg[1].len > sizeof(buf6)) {
232950e252cSAlyssa Milburn 			warn("i2c rd: len=%d is too big!\n",
233950e252cSAlyssa Milburn 			     msg[1].len);
234950e252cSAlyssa Milburn 			num = -EOPNOTSUPP;
235950e252cSAlyssa Milburn 			break;
236950e252cSAlyssa Milburn 		}
237950e252cSAlyssa Milburn 
238786baecfSMauro Carvalho Chehab 		/* read si2109 register by number */
239786baecfSMauro Carvalho Chehab 		buf6[0] = msg[0].addr << 1;
240786baecfSMauro Carvalho Chehab 		buf6[1] = msg[0].len;
241786baecfSMauro Carvalho Chehab 		buf6[2] = msg[0].buf[0];
242786baecfSMauro Carvalho Chehab 		dw210x_op_rw(d->udev, 0xc2, 0, 0,
243786baecfSMauro Carvalho Chehab 			     buf6, msg[0].len + 2, DW210X_WRITE_MSG);
244786baecfSMauro Carvalho Chehab 		/* read si2109 register */
245786baecfSMauro Carvalho Chehab 		dw210x_op_rw(d->udev, 0xc3, 0xd0, 0,
246786baecfSMauro Carvalho Chehab 			     buf6, msg[1].len + 2, DW210X_READ_MSG);
247786baecfSMauro Carvalho Chehab 		memcpy(msg[1].buf, buf6 + 2, msg[1].len);
248786baecfSMauro Carvalho Chehab 
249786baecfSMauro Carvalho Chehab 		break;
250786baecfSMauro Carvalho Chehab 	case 1:
251786baecfSMauro Carvalho Chehab 		switch (msg[0].addr) {
252786baecfSMauro Carvalho Chehab 		case 0x68:
253950e252cSAlyssa Milburn 			if (2 + msg[0].len > sizeof(buf6)) {
254950e252cSAlyssa Milburn 				warn("i2c wr: len=%d is too big!\n",
255950e252cSAlyssa Milburn 				     msg[0].len);
256950e252cSAlyssa Milburn 				num = -EOPNOTSUPP;
257950e252cSAlyssa Milburn 				break;
258950e252cSAlyssa Milburn 			}
259950e252cSAlyssa Milburn 
260786baecfSMauro Carvalho Chehab 			/* write to si2109 register */
261786baecfSMauro Carvalho Chehab 			buf6[0] = msg[0].addr << 1;
262786baecfSMauro Carvalho Chehab 			buf6[1] = msg[0].len;
263786baecfSMauro Carvalho Chehab 			memcpy(buf6 + 2, msg[0].buf, msg[0].len);
264786baecfSMauro Carvalho Chehab 			dw210x_op_rw(d->udev, 0xc2, 0, 0, buf6,
265786baecfSMauro Carvalho Chehab 				     msg[0].len + 2, DW210X_WRITE_MSG);
266786baecfSMauro Carvalho Chehab 			break;
267786baecfSMauro Carvalho Chehab 		case(DW2102_RC_QUERY):
268786baecfSMauro Carvalho Chehab 			dw210x_op_rw(d->udev, 0xb8, 0, 0,
269786baecfSMauro Carvalho Chehab 				     buf6, 2, DW210X_READ_MSG);
270786baecfSMauro Carvalho Chehab 			msg[0].buf[0] = buf6[0];
271786baecfSMauro Carvalho Chehab 			msg[0].buf[1] = buf6[1];
272786baecfSMauro Carvalho Chehab 			break;
273786baecfSMauro Carvalho Chehab 		case(DW2102_VOLTAGE_CTRL):
274786baecfSMauro Carvalho Chehab 			buf6[0] = 0x30;
275786baecfSMauro Carvalho Chehab 			buf6[1] = msg[0].buf[0];
276786baecfSMauro Carvalho Chehab 			dw210x_op_rw(d->udev, 0xb2, 0, 0,
277786baecfSMauro Carvalho Chehab 				     buf6, 2, DW210X_WRITE_MSG);
278786baecfSMauro Carvalho Chehab 			break;
279786baecfSMauro Carvalho Chehab 		}
280786baecfSMauro Carvalho Chehab 		break;
281786baecfSMauro Carvalho Chehab 	}
282786baecfSMauro Carvalho Chehab 
283786baecfSMauro Carvalho Chehab 	mutex_unlock(&d->i2c_mutex);
284786baecfSMauro Carvalho Chehab 	return num;
285786baecfSMauro Carvalho Chehab }
286786baecfSMauro Carvalho Chehab 
dw2102_earda_i2c_transfer(struct i2c_adapter * adap,struct i2c_msg msg[],int num)287786baecfSMauro Carvalho Chehab static int dw2102_earda_i2c_transfer(struct i2c_adapter *adap, struct i2c_msg msg[], int num)
288786baecfSMauro Carvalho Chehab {
289786baecfSMauro Carvalho Chehab 	struct dvb_usb_device *d = i2c_get_adapdata(adap);
290324ed533SDan Carpenter 	int ret;
291786baecfSMauro Carvalho Chehab 
292786baecfSMauro Carvalho Chehab 	if (!d)
293786baecfSMauro Carvalho Chehab 		return -ENODEV;
294786baecfSMauro Carvalho Chehab 	if (mutex_lock_interruptible(&d->i2c_mutex) < 0)
295786baecfSMauro Carvalho Chehab 		return -EAGAIN;
296786baecfSMauro Carvalho Chehab 
297786baecfSMauro Carvalho Chehab 	switch (num) {
298786baecfSMauro Carvalho Chehab 	case 2: {
299786baecfSMauro Carvalho Chehab 		/* read */
300786baecfSMauro Carvalho Chehab 		/* first write first register number */
3010065a79aSMauro Carvalho Chehab 		u8 ibuf[MAX_XFER_SIZE], obuf[3];
3020065a79aSMauro Carvalho Chehab 
303950e252cSAlyssa Milburn 		if (2 + msg[0].len != sizeof(obuf)) {
304950e252cSAlyssa Milburn 			warn("i2c rd: len=%d is not 1!\n",
305950e252cSAlyssa Milburn 			     msg[0].len);
306950e252cSAlyssa Milburn 			ret = -EOPNOTSUPP;
307950e252cSAlyssa Milburn 			goto unlock;
308950e252cSAlyssa Milburn 		}
309950e252cSAlyssa Milburn 
3100065a79aSMauro Carvalho Chehab 		if (2 + msg[1].len > sizeof(ibuf)) {
3110065a79aSMauro Carvalho Chehab 			warn("i2c rd: len=%d is too big!\n",
3120065a79aSMauro Carvalho Chehab 			     msg[1].len);
313324ed533SDan Carpenter 			ret = -EOPNOTSUPP;
314324ed533SDan Carpenter 			goto unlock;
3150065a79aSMauro Carvalho Chehab 		}
3160065a79aSMauro Carvalho Chehab 
317786baecfSMauro Carvalho Chehab 		obuf[0] = msg[0].addr << 1;
318786baecfSMauro Carvalho Chehab 		obuf[1] = msg[0].len;
319786baecfSMauro Carvalho Chehab 		obuf[2] = msg[0].buf[0];
320786baecfSMauro Carvalho Chehab 		dw210x_op_rw(d->udev, 0xc2, 0, 0,
321786baecfSMauro Carvalho Chehab 			     obuf, msg[0].len + 2, DW210X_WRITE_MSG);
322786baecfSMauro Carvalho Chehab 		/* second read registers */
323786baecfSMauro Carvalho Chehab 		dw210x_op_rw(d->udev, 0xc3, 0xd1, 0,
324786baecfSMauro Carvalho Chehab 			     ibuf, msg[1].len + 2, DW210X_READ_MSG);
325786baecfSMauro Carvalho Chehab 		memcpy(msg[1].buf, ibuf + 2, msg[1].len);
326786baecfSMauro Carvalho Chehab 
327786baecfSMauro Carvalho Chehab 		break;
328786baecfSMauro Carvalho Chehab 	}
329786baecfSMauro Carvalho Chehab 	case 1:
330786baecfSMauro Carvalho Chehab 		switch (msg[0].addr) {
331786baecfSMauro Carvalho Chehab 		case 0x68: {
332786baecfSMauro Carvalho Chehab 			/* write to register */
3330065a79aSMauro Carvalho Chehab 			u8 obuf[MAX_XFER_SIZE];
3340065a79aSMauro Carvalho Chehab 
3350065a79aSMauro Carvalho Chehab 			if (2 + msg[0].len > sizeof(obuf)) {
3360065a79aSMauro Carvalho Chehab 				warn("i2c wr: len=%d is too big!\n",
3370065a79aSMauro Carvalho Chehab 				     msg[1].len);
338324ed533SDan Carpenter 				ret = -EOPNOTSUPP;
339324ed533SDan Carpenter 				goto unlock;
3400065a79aSMauro Carvalho Chehab 			}
3410065a79aSMauro Carvalho Chehab 
342786baecfSMauro Carvalho Chehab 			obuf[0] = msg[0].addr << 1;
343786baecfSMauro Carvalho Chehab 			obuf[1] = msg[0].len;
344786baecfSMauro Carvalho Chehab 			memcpy(obuf + 2, msg[0].buf, msg[0].len);
345786baecfSMauro Carvalho Chehab 			dw210x_op_rw(d->udev, 0xc2, 0, 0,
346786baecfSMauro Carvalho Chehab 				     obuf, msg[0].len + 2, DW210X_WRITE_MSG);
347786baecfSMauro Carvalho Chehab 			break;
348786baecfSMauro Carvalho Chehab 		}
349786baecfSMauro Carvalho Chehab 		case 0x61: {
350786baecfSMauro Carvalho Chehab 			/* write to tuner */
3510065a79aSMauro Carvalho Chehab 			u8 obuf[MAX_XFER_SIZE];
3520065a79aSMauro Carvalho Chehab 
3530065a79aSMauro Carvalho Chehab 			if (2 + msg[0].len > sizeof(obuf)) {
3540065a79aSMauro Carvalho Chehab 				warn("i2c wr: len=%d is too big!\n",
3550065a79aSMauro Carvalho Chehab 				     msg[1].len);
356324ed533SDan Carpenter 				ret = -EOPNOTSUPP;
357324ed533SDan Carpenter 				goto unlock;
3580065a79aSMauro Carvalho Chehab 			}
3590065a79aSMauro Carvalho Chehab 
360786baecfSMauro Carvalho Chehab 			obuf[0] = msg[0].addr << 1;
361786baecfSMauro Carvalho Chehab 			obuf[1] = msg[0].len;
362786baecfSMauro Carvalho Chehab 			memcpy(obuf + 2, msg[0].buf, msg[0].len);
363786baecfSMauro Carvalho Chehab 			dw210x_op_rw(d->udev, 0xc2, 0, 0,
364786baecfSMauro Carvalho Chehab 				     obuf, msg[0].len + 2, DW210X_WRITE_MSG);
365786baecfSMauro Carvalho Chehab 			break;
366786baecfSMauro Carvalho Chehab 		}
367786baecfSMauro Carvalho Chehab 		case(DW2102_RC_QUERY): {
368786baecfSMauro Carvalho Chehab 			u8 ibuf[2];
369efc3e49dSMichael Bunk 
370786baecfSMauro Carvalho Chehab 			dw210x_op_rw(d->udev, 0xb8, 0, 0,
371786baecfSMauro Carvalho Chehab 				     ibuf, 2, DW210X_READ_MSG);
372786baecfSMauro Carvalho Chehab 			memcpy(msg[0].buf, ibuf, 2);
373786baecfSMauro Carvalho Chehab 			break;
374786baecfSMauro Carvalho Chehab 		}
375786baecfSMauro Carvalho Chehab 		case(DW2102_VOLTAGE_CTRL): {
376786baecfSMauro Carvalho Chehab 			u8 obuf[2];
377efc3e49dSMichael Bunk 
378786baecfSMauro Carvalho Chehab 			obuf[0] = 0x30;
379786baecfSMauro Carvalho Chehab 			obuf[1] = msg[0].buf[0];
380786baecfSMauro Carvalho Chehab 			dw210x_op_rw(d->udev, 0xb2, 0, 0,
381786baecfSMauro Carvalho Chehab 				     obuf, 2, DW210X_WRITE_MSG);
382786baecfSMauro Carvalho Chehab 			break;
383786baecfSMauro Carvalho Chehab 		}
384786baecfSMauro Carvalho Chehab 		}
385786baecfSMauro Carvalho Chehab 
386786baecfSMauro Carvalho Chehab 		break;
387786baecfSMauro Carvalho Chehab 	}
388324ed533SDan Carpenter 	ret = num;
389786baecfSMauro Carvalho Chehab 
390324ed533SDan Carpenter unlock:
391786baecfSMauro Carvalho Chehab 	mutex_unlock(&d->i2c_mutex);
392324ed533SDan Carpenter 	return ret;
393786baecfSMauro Carvalho Chehab }
394786baecfSMauro Carvalho Chehab 
dw2104_i2c_transfer(struct i2c_adapter * adap,struct i2c_msg msg[],int num)395786baecfSMauro Carvalho Chehab static int dw2104_i2c_transfer(struct i2c_adapter *adap, struct i2c_msg msg[], int num)
396786baecfSMauro Carvalho Chehab {
397786baecfSMauro Carvalho Chehab 	struct dvb_usb_device *d = i2c_get_adapdata(adap);
398324ed533SDan Carpenter 	int len, i, j, ret;
399786baecfSMauro Carvalho Chehab 
400786baecfSMauro Carvalho Chehab 	if (!d)
401786baecfSMauro Carvalho Chehab 		return -ENODEV;
402786baecfSMauro Carvalho Chehab 	if (mutex_lock_interruptible(&d->i2c_mutex) < 0)
403786baecfSMauro Carvalho Chehab 		return -EAGAIN;
404786baecfSMauro Carvalho Chehab 
405786baecfSMauro Carvalho Chehab 	for (j = 0; j < num; j++) {
406786baecfSMauro Carvalho Chehab 		switch (msg[j].addr) {
407786baecfSMauro Carvalho Chehab 		case(DW2102_RC_QUERY): {
408786baecfSMauro Carvalho Chehab 			u8 ibuf[2];
409efc3e49dSMichael Bunk 
410786baecfSMauro Carvalho Chehab 			dw210x_op_rw(d->udev, 0xb8, 0, 0,
411786baecfSMauro Carvalho Chehab 				     ibuf, 2, DW210X_READ_MSG);
412786baecfSMauro Carvalho Chehab 			memcpy(msg[j].buf, ibuf, 2);
413786baecfSMauro Carvalho Chehab 			break;
414786baecfSMauro Carvalho Chehab 		}
415786baecfSMauro Carvalho Chehab 		case(DW2102_VOLTAGE_CTRL): {
416786baecfSMauro Carvalho Chehab 			u8 obuf[2];
417efc3e49dSMichael Bunk 
418786baecfSMauro Carvalho Chehab 			obuf[0] = 0x30;
419786baecfSMauro Carvalho Chehab 			obuf[1] = msg[j].buf[0];
420786baecfSMauro Carvalho Chehab 			dw210x_op_rw(d->udev, 0xb2, 0, 0,
421786baecfSMauro Carvalho Chehab 				     obuf, 2, DW210X_WRITE_MSG);
422786baecfSMauro Carvalho Chehab 			break;
423786baecfSMauro Carvalho Chehab 		}
424786baecfSMauro Carvalho Chehab 		/* case 0x55: cx24116
425efc3e49dSMichael Bunk 		 * case 0x6a: stv0903
426efc3e49dSMichael Bunk 		 * case 0x68: ds3000, stv0903
427efc3e49dSMichael Bunk 		 * case 0x60: ts2020, stv6110, stb6100
428efc3e49dSMichael Bunk 		 */
429786baecfSMauro Carvalho Chehab 		default: {
430786baecfSMauro Carvalho Chehab 			if (msg[j].flags == I2C_M_RD) {
431786baecfSMauro Carvalho Chehab 				/* read registers */
4320065a79aSMauro Carvalho Chehab 				u8  ibuf[MAX_XFER_SIZE];
4330065a79aSMauro Carvalho Chehab 
4340065a79aSMauro Carvalho Chehab 				if (2 + msg[j].len > sizeof(ibuf)) {
4350065a79aSMauro Carvalho Chehab 					warn("i2c rd: len=%d is too big!\n",
4360065a79aSMauro Carvalho Chehab 					     msg[j].len);
437324ed533SDan Carpenter 					ret = -EOPNOTSUPP;
438324ed533SDan Carpenter 					goto unlock;
4390065a79aSMauro Carvalho Chehab 				}
4400065a79aSMauro Carvalho Chehab 
441786baecfSMauro Carvalho Chehab 				dw210x_op_rw(d->udev, 0xc3,
442786baecfSMauro Carvalho Chehab 					     (msg[j].addr << 1) + 1, 0,
443786baecfSMauro Carvalho Chehab 					     ibuf, msg[j].len + 2,
444786baecfSMauro Carvalho Chehab 					     DW210X_READ_MSG);
445786baecfSMauro Carvalho Chehab 				memcpy(msg[j].buf, ibuf + 2, msg[j].len);
446786baecfSMauro Carvalho Chehab 				mdelay(10);
4474a7d7351SMauro Carvalho Chehab 			} else if (((msg[j].buf[0] == 0xb0) && (msg[j].addr == 0x68)) ||
4484a7d7351SMauro Carvalho Chehab 				   ((msg[j].buf[0] == 0xf7) && (msg[j].addr == 0x55))) {
449786baecfSMauro Carvalho Chehab 				/* write firmware */
450786baecfSMauro Carvalho Chehab 				u8 obuf[19];
451efc3e49dSMichael Bunk 
452786baecfSMauro Carvalho Chehab 				obuf[0] = msg[j].addr << 1;
453786baecfSMauro Carvalho Chehab 				obuf[1] = (msg[j].len > 15 ? 17 : msg[j].len);
454786baecfSMauro Carvalho Chehab 				obuf[2] = msg[j].buf[0];
455786baecfSMauro Carvalho Chehab 				len = msg[j].len - 1;
456786baecfSMauro Carvalho Chehab 				i = 1;
457786baecfSMauro Carvalho Chehab 				do {
458786baecfSMauro Carvalho Chehab 					memcpy(obuf + 3, msg[j].buf + i,
459786baecfSMauro Carvalho Chehab 					       (len > 16 ? 16 : len));
460786baecfSMauro Carvalho Chehab 					dw210x_op_rw(d->udev, 0xc2, 0, 0,
461786baecfSMauro Carvalho Chehab 						     obuf, (len > 16 ? 16 : len) + 3,
462786baecfSMauro Carvalho Chehab 						     DW210X_WRITE_MSG);
463786baecfSMauro Carvalho Chehab 					i += 16;
464786baecfSMauro Carvalho Chehab 					len -= 16;
465786baecfSMauro Carvalho Chehab 				} while (len > 0);
466786baecfSMauro Carvalho Chehab 			} else {
467786baecfSMauro Carvalho Chehab 				/* write registers */
4680065a79aSMauro Carvalho Chehab 				u8 obuf[MAX_XFER_SIZE];
4690065a79aSMauro Carvalho Chehab 
4700065a79aSMauro Carvalho Chehab 				if (2 + msg[j].len > sizeof(obuf)) {
4710065a79aSMauro Carvalho Chehab 					warn("i2c wr: len=%d is too big!\n",
4720065a79aSMauro Carvalho Chehab 					     msg[j].len);
473324ed533SDan Carpenter 					ret = -EOPNOTSUPP;
474324ed533SDan Carpenter 					goto unlock;
4750065a79aSMauro Carvalho Chehab 				}
4760065a79aSMauro Carvalho Chehab 
477786baecfSMauro Carvalho Chehab 				obuf[0] = msg[j].addr << 1;
478786baecfSMauro Carvalho Chehab 				obuf[1] = msg[j].len;
479786baecfSMauro Carvalho Chehab 				memcpy(obuf + 2, msg[j].buf, msg[j].len);
480786baecfSMauro Carvalho Chehab 				dw210x_op_rw(d->udev, 0xc2, 0, 0,
481786baecfSMauro Carvalho Chehab 					     obuf, msg[j].len + 2,
482786baecfSMauro Carvalho Chehab 					     DW210X_WRITE_MSG);
483786baecfSMauro Carvalho Chehab 			}
484786baecfSMauro Carvalho Chehab 			break;
485786baecfSMauro Carvalho Chehab 		}
486786baecfSMauro Carvalho Chehab 		}
487786baecfSMauro Carvalho Chehab 	}
488324ed533SDan Carpenter 	ret = num;
489786baecfSMauro Carvalho Chehab 
490324ed533SDan Carpenter unlock:
491786baecfSMauro Carvalho Chehab 	mutex_unlock(&d->i2c_mutex);
492324ed533SDan Carpenter 	return ret;
493786baecfSMauro Carvalho Chehab }
494786baecfSMauro Carvalho Chehab 
dw3101_i2c_transfer(struct i2c_adapter * adap,struct i2c_msg msg[],int num)495786baecfSMauro Carvalho Chehab static int dw3101_i2c_transfer(struct i2c_adapter *adap, struct i2c_msg msg[],
496786baecfSMauro Carvalho Chehab 			       int num)
497786baecfSMauro Carvalho Chehab {
498786baecfSMauro Carvalho Chehab 	struct dvb_usb_device *d = i2c_get_adapdata(adap);
499324ed533SDan Carpenter 	int ret;
500786baecfSMauro Carvalho Chehab 	int i;
501786baecfSMauro Carvalho Chehab 
502786baecfSMauro Carvalho Chehab 	if (!d)
503786baecfSMauro Carvalho Chehab 		return -ENODEV;
504786baecfSMauro Carvalho Chehab 	if (mutex_lock_interruptible(&d->i2c_mutex) < 0)
505786baecfSMauro Carvalho Chehab 		return -EAGAIN;
506786baecfSMauro Carvalho Chehab 
507786baecfSMauro Carvalho Chehab 	switch (num) {
508786baecfSMauro Carvalho Chehab 	case 2: {
509786baecfSMauro Carvalho Chehab 		/* read */
510786baecfSMauro Carvalho Chehab 		/* first write first register number */
5110065a79aSMauro Carvalho Chehab 		u8 ibuf[MAX_XFER_SIZE], obuf[3];
5120065a79aSMauro Carvalho Chehab 
513950e252cSAlyssa Milburn 		if (2 + msg[0].len != sizeof(obuf)) {
514950e252cSAlyssa Milburn 			warn("i2c rd: len=%d is not 1!\n",
515950e252cSAlyssa Milburn 			     msg[0].len);
516950e252cSAlyssa Milburn 			ret = -EOPNOTSUPP;
517950e252cSAlyssa Milburn 			goto unlock;
518950e252cSAlyssa Milburn 		}
5190065a79aSMauro Carvalho Chehab 		if (2 + msg[1].len > sizeof(ibuf)) {
5200065a79aSMauro Carvalho Chehab 			warn("i2c rd: len=%d is too big!\n",
5210065a79aSMauro Carvalho Chehab 			     msg[1].len);
522324ed533SDan Carpenter 			ret = -EOPNOTSUPP;
523324ed533SDan Carpenter 			goto unlock;
5240065a79aSMauro Carvalho Chehab 		}
525786baecfSMauro Carvalho Chehab 		obuf[0] = msg[0].addr << 1;
526786baecfSMauro Carvalho Chehab 		obuf[1] = msg[0].len;
527786baecfSMauro Carvalho Chehab 		obuf[2] = msg[0].buf[0];
528786baecfSMauro Carvalho Chehab 		dw210x_op_rw(d->udev, 0xc2, 0, 0,
529786baecfSMauro Carvalho Chehab 			     obuf, msg[0].len + 2, DW210X_WRITE_MSG);
530786baecfSMauro Carvalho Chehab 		/* second read registers */
531786baecfSMauro Carvalho Chehab 		dw210x_op_rw(d->udev, 0xc3, 0x19, 0,
532786baecfSMauro Carvalho Chehab 			     ibuf, msg[1].len + 2, DW210X_READ_MSG);
533786baecfSMauro Carvalho Chehab 		memcpy(msg[1].buf, ibuf + 2, msg[1].len);
534786baecfSMauro Carvalho Chehab 
535786baecfSMauro Carvalho Chehab 		break;
536786baecfSMauro Carvalho Chehab 	}
537786baecfSMauro Carvalho Chehab 	case 1:
538786baecfSMauro Carvalho Chehab 		switch (msg[0].addr) {
539786baecfSMauro Carvalho Chehab 		case 0x60:
540786baecfSMauro Carvalho Chehab 		case 0x0c: {
541786baecfSMauro Carvalho Chehab 			/* write to register */
5420065a79aSMauro Carvalho Chehab 			u8 obuf[MAX_XFER_SIZE];
5430065a79aSMauro Carvalho Chehab 
5440065a79aSMauro Carvalho Chehab 			if (2 + msg[0].len > sizeof(obuf)) {
5450065a79aSMauro Carvalho Chehab 				warn("i2c wr: len=%d is too big!\n",
5460065a79aSMauro Carvalho Chehab 				     msg[0].len);
547324ed533SDan Carpenter 				ret = -EOPNOTSUPP;
548324ed533SDan Carpenter 				goto unlock;
5490065a79aSMauro Carvalho Chehab 			}
550786baecfSMauro Carvalho Chehab 			obuf[0] = msg[0].addr << 1;
551786baecfSMauro Carvalho Chehab 			obuf[1] = msg[0].len;
552786baecfSMauro Carvalho Chehab 			memcpy(obuf + 2, msg[0].buf, msg[0].len);
553786baecfSMauro Carvalho Chehab 			dw210x_op_rw(d->udev, 0xc2, 0, 0,
554786baecfSMauro Carvalho Chehab 				     obuf, msg[0].len + 2, DW210X_WRITE_MSG);
555786baecfSMauro Carvalho Chehab 			break;
556786baecfSMauro Carvalho Chehab 		}
557786baecfSMauro Carvalho Chehab 		case(DW2102_RC_QUERY): {
558786baecfSMauro Carvalho Chehab 			u8 ibuf[2];
559efc3e49dSMichael Bunk 
560786baecfSMauro Carvalho Chehab 			dw210x_op_rw(d->udev, 0xb8, 0, 0,
561786baecfSMauro Carvalho Chehab 				     ibuf, 2, DW210X_READ_MSG);
562786baecfSMauro Carvalho Chehab 			memcpy(msg[0].buf, ibuf, 2);
563786baecfSMauro Carvalho Chehab 			break;
564786baecfSMauro Carvalho Chehab 		}
565786baecfSMauro Carvalho Chehab 		}
566786baecfSMauro Carvalho Chehab 
567786baecfSMauro Carvalho Chehab 		break;
568786baecfSMauro Carvalho Chehab 	}
569786baecfSMauro Carvalho Chehab 
570786baecfSMauro Carvalho Chehab 	for (i = 0; i < num; i++) {
571786baecfSMauro Carvalho Chehab 		deb_xfer("%02x:%02x: %s ", i, msg[i].addr,
572786baecfSMauro Carvalho Chehab 			 msg[i].flags == 0 ? ">>>" : "<<<");
573786baecfSMauro Carvalho Chehab 		debug_dump(msg[i].buf, msg[i].len, deb_xfer);
574786baecfSMauro Carvalho Chehab 	}
575324ed533SDan Carpenter 	ret = num;
576786baecfSMauro Carvalho Chehab 
577324ed533SDan Carpenter unlock:
578786baecfSMauro Carvalho Chehab 	mutex_unlock(&d->i2c_mutex);
579324ed533SDan Carpenter 	return ret;
580786baecfSMauro Carvalho Chehab }
581786baecfSMauro Carvalho Chehab 
s6x0_i2c_transfer(struct i2c_adapter * adap,struct i2c_msg msg[],int num)582786baecfSMauro Carvalho Chehab static int s6x0_i2c_transfer(struct i2c_adapter *adap, struct i2c_msg msg[],
583786baecfSMauro Carvalho Chehab 			     int num)
584786baecfSMauro Carvalho Chehab {
585786baecfSMauro Carvalho Chehab 	struct dvb_usb_device *d = i2c_get_adapdata(adap);
586786baecfSMauro Carvalho Chehab 	struct usb_device *udev;
587324ed533SDan Carpenter 	int len, i, j, ret;
588786baecfSMauro Carvalho Chehab 
589786baecfSMauro Carvalho Chehab 	if (!d)
590786baecfSMauro Carvalho Chehab 		return -ENODEV;
591786baecfSMauro Carvalho Chehab 	udev = d->udev;
592786baecfSMauro Carvalho Chehab 	if (mutex_lock_interruptible(&d->i2c_mutex) < 0)
593786baecfSMauro Carvalho Chehab 		return -EAGAIN;
594786baecfSMauro Carvalho Chehab 
595786baecfSMauro Carvalho Chehab 	for (j = 0; j < num; j++) {
596786baecfSMauro Carvalho Chehab 		switch (msg[j].addr) {
597786baecfSMauro Carvalho Chehab 		case (DW2102_RC_QUERY): {
598786baecfSMauro Carvalho Chehab 			u8 ibuf[5];
599efc3e49dSMichael Bunk 
600786baecfSMauro Carvalho Chehab 			dw210x_op_rw(d->udev, 0xb8, 0, 0,
601786baecfSMauro Carvalho Chehab 				     ibuf, 5, DW210X_READ_MSG);
602786baecfSMauro Carvalho Chehab 			memcpy(msg[j].buf, ibuf + 3, 2);
603786baecfSMauro Carvalho Chehab 			break;
604786baecfSMauro Carvalho Chehab 		}
605786baecfSMauro Carvalho Chehab 		case (DW2102_VOLTAGE_CTRL): {
606786baecfSMauro Carvalho Chehab 			u8 obuf[2];
607786baecfSMauro Carvalho Chehab 
608786baecfSMauro Carvalho Chehab 			obuf[0] = 1;
609786baecfSMauro Carvalho Chehab 			obuf[1] = msg[j].buf[1];/* off-on */
610786baecfSMauro Carvalho Chehab 			dw210x_op_rw(d->udev, 0x8a, 0, 0,
611786baecfSMauro Carvalho Chehab 				     obuf, 2, DW210X_WRITE_MSG);
612786baecfSMauro Carvalho Chehab 			obuf[0] = 3;
613786baecfSMauro Carvalho Chehab 			obuf[1] = msg[j].buf[0];/* 13v-18v */
614786baecfSMauro Carvalho Chehab 			dw210x_op_rw(d->udev, 0x8a, 0, 0,
615786baecfSMauro Carvalho Chehab 				     obuf, 2, DW210X_WRITE_MSG);
616786baecfSMauro Carvalho Chehab 			break;
617786baecfSMauro Carvalho Chehab 		}
618786baecfSMauro Carvalho Chehab 		case (DW2102_LED_CTRL): {
619786baecfSMauro Carvalho Chehab 			u8 obuf[2];
620786baecfSMauro Carvalho Chehab 
621786baecfSMauro Carvalho Chehab 			obuf[0] = 5;
622786baecfSMauro Carvalho Chehab 			obuf[1] = msg[j].buf[0];
623786baecfSMauro Carvalho Chehab 			dw210x_op_rw(d->udev, 0x8a, 0, 0,
624786baecfSMauro Carvalho Chehab 				     obuf, 2, DW210X_WRITE_MSG);
625786baecfSMauro Carvalho Chehab 			break;
626786baecfSMauro Carvalho Chehab 		}
627786baecfSMauro Carvalho Chehab 		/* case 0x55: cx24116
628efc3e49dSMichael Bunk 		 * case 0x6a: stv0903
629efc3e49dSMichael Bunk 		 * case 0x68: ds3000, stv0903, rs2000
630efc3e49dSMichael Bunk 		 * case 0x60: ts2020, stv6110, stb6100
631efc3e49dSMichael Bunk 		 * case 0xa0: eeprom
632efc3e49dSMichael Bunk 		 */
633786baecfSMauro Carvalho Chehab 		default: {
634786baecfSMauro Carvalho Chehab 			if (msg[j].flags == I2C_M_RD) {
635786baecfSMauro Carvalho Chehab 				/* read registers */
6360065a79aSMauro Carvalho Chehab 				u8 ibuf[MAX_XFER_SIZE];
6370065a79aSMauro Carvalho Chehab 
6380065a79aSMauro Carvalho Chehab 				if (msg[j].len > sizeof(ibuf)) {
6390065a79aSMauro Carvalho Chehab 					warn("i2c rd: len=%d is too big!\n",
6400065a79aSMauro Carvalho Chehab 					     msg[j].len);
641324ed533SDan Carpenter 					ret = -EOPNOTSUPP;
642324ed533SDan Carpenter 					goto unlock;
6430065a79aSMauro Carvalho Chehab 				}
6440065a79aSMauro Carvalho Chehab 
645786baecfSMauro Carvalho Chehab 				dw210x_op_rw(d->udev, 0x91, 0, 0,
646786baecfSMauro Carvalho Chehab 					     ibuf, msg[j].len,
647786baecfSMauro Carvalho Chehab 						DW210X_READ_MSG);
648786baecfSMauro Carvalho Chehab 				memcpy(msg[j].buf, ibuf, msg[j].len);
649786baecfSMauro Carvalho Chehab 				break;
6504a7d7351SMauro Carvalho Chehab 			} else if ((msg[j].buf[0] == 0xb0) && (msg[j].addr == 0x68)) {
651786baecfSMauro Carvalho Chehab 				/* write firmware */
652786baecfSMauro Carvalho Chehab 				u8 obuf[19];
653efc3e49dSMichael Bunk 
654786baecfSMauro Carvalho Chehab 				obuf[0] = (msg[j].len > 16 ?
655786baecfSMauro Carvalho Chehab 						18 : msg[j].len + 1);
656786baecfSMauro Carvalho Chehab 				obuf[1] = msg[j].addr << 1;
657786baecfSMauro Carvalho Chehab 				obuf[2] = msg[j].buf[0];
658786baecfSMauro Carvalho Chehab 				len = msg[j].len - 1;
659786baecfSMauro Carvalho Chehab 				i = 1;
660786baecfSMauro Carvalho Chehab 				do {
661786baecfSMauro Carvalho Chehab 					memcpy(obuf + 3, msg[j].buf + i,
662786baecfSMauro Carvalho Chehab 					       (len > 16 ? 16 : len));
663786baecfSMauro Carvalho Chehab 					dw210x_op_rw(d->udev, 0x80, 0, 0,
664786baecfSMauro Carvalho Chehab 						     obuf, (len > 16 ? 16 : len) + 3,
665786baecfSMauro Carvalho Chehab 						     DW210X_WRITE_MSG);
666786baecfSMauro Carvalho Chehab 					i += 16;
667786baecfSMauro Carvalho Chehab 					len -= 16;
668786baecfSMauro Carvalho Chehab 				} while (len > 0);
669786baecfSMauro Carvalho Chehab 			} else if (j < (num - 1)) {
670786baecfSMauro Carvalho Chehab 				/* write register addr before read */
6710065a79aSMauro Carvalho Chehab 				u8 obuf[MAX_XFER_SIZE];
6720065a79aSMauro Carvalho Chehab 
6730065a79aSMauro Carvalho Chehab 				if (2 + msg[j].len > sizeof(obuf)) {
6740065a79aSMauro Carvalho Chehab 					warn("i2c wr: len=%d is too big!\n",
6750065a79aSMauro Carvalho Chehab 					     msg[j].len);
676324ed533SDan Carpenter 					ret = -EOPNOTSUPP;
677324ed533SDan Carpenter 					goto unlock;
6780065a79aSMauro Carvalho Chehab 				}
6790065a79aSMauro Carvalho Chehab 
680786baecfSMauro Carvalho Chehab 				obuf[0] = msg[j + 1].len;
681786baecfSMauro Carvalho Chehab 				obuf[1] = (msg[j].addr << 1);
682786baecfSMauro Carvalho Chehab 				memcpy(obuf + 2, msg[j].buf, msg[j].len);
683786baecfSMauro Carvalho Chehab 				dw210x_op_rw(d->udev,
6844a7d7351SMauro Carvalho Chehab 					     le16_to_cpu(udev->descriptor.idProduct) == 0x7500 ? 0x92 : 0x90,
6854a7d7351SMauro Carvalho Chehab 					     0, 0, obuf, msg[j].len + 2,
686786baecfSMauro Carvalho Chehab 					     DW210X_WRITE_MSG);
687786baecfSMauro Carvalho Chehab 				break;
688786baecfSMauro Carvalho Chehab 			} else {
689786baecfSMauro Carvalho Chehab 				/* write registers */
6900065a79aSMauro Carvalho Chehab 				u8 obuf[MAX_XFER_SIZE];
6910065a79aSMauro Carvalho Chehab 
6920065a79aSMauro Carvalho Chehab 				if (2 + msg[j].len > sizeof(obuf)) {
6930065a79aSMauro Carvalho Chehab 					warn("i2c wr: len=%d is too big!\n",
6940065a79aSMauro Carvalho Chehab 					     msg[j].len);
695324ed533SDan Carpenter 					ret = -EOPNOTSUPP;
696324ed533SDan Carpenter 					goto unlock;
6970065a79aSMauro Carvalho Chehab 				}
698786baecfSMauro Carvalho Chehab 				obuf[0] = msg[j].len + 1;
699786baecfSMauro Carvalho Chehab 				obuf[1] = (msg[j].addr << 1);
700786baecfSMauro Carvalho Chehab 				memcpy(obuf + 2, msg[j].buf, msg[j].len);
701786baecfSMauro Carvalho Chehab 				dw210x_op_rw(d->udev, 0x80, 0, 0,
702786baecfSMauro Carvalho Chehab 					     obuf, msg[j].len + 2,
703786baecfSMauro Carvalho Chehab 					     DW210X_WRITE_MSG);
704786baecfSMauro Carvalho Chehab 				break;
705786baecfSMauro Carvalho Chehab 			}
706786baecfSMauro Carvalho Chehab 			break;
707786baecfSMauro Carvalho Chehab 		}
708786baecfSMauro Carvalho Chehab 		}
709786baecfSMauro Carvalho Chehab 	}
710324ed533SDan Carpenter 	ret = num;
711786baecfSMauro Carvalho Chehab 
712324ed533SDan Carpenter unlock:
713786baecfSMauro Carvalho Chehab 	mutex_unlock(&d->i2c_mutex);
714324ed533SDan Carpenter 	return ret;
715786baecfSMauro Carvalho Chehab }
716786baecfSMauro Carvalho Chehab 
su3000_i2c_transfer(struct i2c_adapter * adap,struct i2c_msg msg[],int num)717786baecfSMauro Carvalho Chehab static int su3000_i2c_transfer(struct i2c_adapter *adap, struct i2c_msg msg[],
718786baecfSMauro Carvalho Chehab 			       int num)
719786baecfSMauro Carvalho Chehab {
720786baecfSMauro Carvalho Chehab 	struct dvb_usb_device *d = i2c_get_adapdata(adap);
721606142afSJonathan McDowell 	struct dw2102_state *state;
7220e148a52SMichael Bunk 	int j;
723786baecfSMauro Carvalho Chehab 
724786baecfSMauro Carvalho Chehab 	if (!d)
725786baecfSMauro Carvalho Chehab 		return -ENODEV;
726606142afSJonathan McDowell 
727606142afSJonathan McDowell 	state = d->priv;
728606142afSJonathan McDowell 
729786baecfSMauro Carvalho Chehab 	if (mutex_lock_interruptible(&d->i2c_mutex) < 0)
730786baecfSMauro Carvalho Chehab 		return -EAGAIN;
731606142afSJonathan McDowell 	if (mutex_lock_interruptible(&d->data_mutex) < 0) {
732606142afSJonathan McDowell 		mutex_unlock(&d->i2c_mutex);
733606142afSJonathan McDowell 		return -EAGAIN;
734606142afSJonathan McDowell 	}
735786baecfSMauro Carvalho Chehab 
7360e148a52SMichael Bunk 	j = 0;
7370e148a52SMichael Bunk 	while (j < num) {
7380e148a52SMichael Bunk 		switch (msg[j].addr) {
739786baecfSMauro Carvalho Chehab 		case SU3000_STREAM_CTRL:
7400e148a52SMichael Bunk 			state->data[0] = msg[j].buf[0] + 0x36;
741606142afSJonathan McDowell 			state->data[1] = 3;
742606142afSJonathan McDowell 			state->data[2] = 0;
743606142afSJonathan McDowell 			if (dvb_usb_generic_rw(d, state->data, 3,
744606142afSJonathan McDowell 					       state->data, 0, 0) < 0)
745786baecfSMauro Carvalho Chehab 				err("i2c transfer failed.");
746786baecfSMauro Carvalho Chehab 			break;
747786baecfSMauro Carvalho Chehab 		case DW2102_RC_QUERY:
748606142afSJonathan McDowell 			state->data[0] = 0x10;
749606142afSJonathan McDowell 			if (dvb_usb_generic_rw(d, state->data, 1,
750606142afSJonathan McDowell 					       state->data, 2, 0) < 0)
751786baecfSMauro Carvalho Chehab 				err("i2c transfer failed.");
7520e148a52SMichael Bunk 			msg[j].buf[1] = state->data[0];
7530e148a52SMichael Bunk 			msg[j].buf[0] = state->data[1];
754786baecfSMauro Carvalho Chehab 			break;
755786baecfSMauro Carvalho Chehab 		default:
7560e148a52SMichael Bunk 			/* if the current write msg is followed by a another
7570e148a52SMichael Bunk 			 * read msg to/from the same address
7580e148a52SMichael Bunk 			 */
7590e148a52SMichael Bunk 			if ((j + 1 < num) && (msg[j + 1].flags & I2C_M_RD) &&
7600e148a52SMichael Bunk 			    (msg[j].addr == msg[j + 1].addr)) {
7610e148a52SMichael Bunk 				/* join both i2c msgs to one usb read command */
7620e148a52SMichael Bunk 				if (4 + msg[j].len > sizeof(state->data)) {
7630e148a52SMichael Bunk 					warn("i2c combined wr/rd: write len=%d is too big!\n",
7640e148a52SMichael Bunk 					     msg[j].len);
765950e252cSAlyssa Milburn 					num = -EOPNOTSUPP;
766950e252cSAlyssa Milburn 					break;
767950e252cSAlyssa Milburn 				}
7680e148a52SMichael Bunk 				if (1 + msg[j + 1].len > sizeof(state->data)) {
7690e148a52SMichael Bunk 					warn("i2c combined wr/rd: read len=%d is too big!\n",
7700e148a52SMichael Bunk 					    msg[j + 1].len);
771950e252cSAlyssa Milburn 					num = -EOPNOTSUPP;
772950e252cSAlyssa Milburn 					break;
773950e252cSAlyssa Milburn 				}
774950e252cSAlyssa Milburn 
775606142afSJonathan McDowell 				state->data[0] = 0x09;
7760e148a52SMichael Bunk 				state->data[1] = msg[j].len;
7770e148a52SMichael Bunk 				state->data[2] = msg[j + 1].len;
7780e148a52SMichael Bunk 				state->data[3] = msg[j].addr;
7790e148a52SMichael Bunk 				memcpy(&state->data[4], msg[j].buf, msg[j].len);
780786baecfSMauro Carvalho Chehab 
7810e148a52SMichael Bunk 				if (dvb_usb_generic_rw(d, state->data, msg[j].len + 4,
7820e148a52SMichael Bunk 					state->data, msg[j + 1].len + 1, 0) < 0)
783786baecfSMauro Carvalho Chehab 					err("i2c transfer failed.");
784786baecfSMauro Carvalho Chehab 
7850e148a52SMichael Bunk 				memcpy(msg[j + 1].buf, &state->data[1], msg[j + 1].len);
7860e148a52SMichael Bunk 				j++;
787786baecfSMauro Carvalho Chehab 				break;
788786baecfSMauro Carvalho Chehab 			}
7890e148a52SMichael Bunk 
7900e148a52SMichael Bunk 			if (msg[j].flags & I2C_M_RD) {
7910e148a52SMichael Bunk 				/* single read */
792*1c73d0b2SMauro Carvalho Chehab 				if (4 + msg[j].len > sizeof(state->data)) {
7930e148a52SMichael Bunk 					warn("i2c rd: len=%d is too big!\n", msg[j].len);
7940e148a52SMichael Bunk 					num = -EOPNOTSUPP;
7950e148a52SMichael Bunk 					break;
7960e148a52SMichael Bunk 				}
7970e148a52SMichael Bunk 
7980e148a52SMichael Bunk 				state->data[0] = 0x09;
7990e148a52SMichael Bunk 				state->data[1] = 0;
8000e148a52SMichael Bunk 				state->data[2] = msg[j].len;
8010e148a52SMichael Bunk 				state->data[3] = msg[j].addr;
8020e148a52SMichael Bunk 				memcpy(&state->data[4], msg[j].buf, msg[j].len);
8030e148a52SMichael Bunk 
8040e148a52SMichael Bunk 				if (dvb_usb_generic_rw(d, state->data, 4,
8050e148a52SMichael Bunk 						       state->data, msg[j].len + 1, 0) < 0)
8060e148a52SMichael Bunk 					err("i2c transfer failed.");
8070e148a52SMichael Bunk 
8080e148a52SMichael Bunk 				memcpy(msg[j].buf, &state->data[1], msg[j].len);
8090e148a52SMichael Bunk 				break;
8100e148a52SMichael Bunk 			}
8110e148a52SMichael Bunk 
8120e148a52SMichael Bunk 			/* single write */
8130e148a52SMichael Bunk 			if (3 + msg[j].len > sizeof(state->data)) {
8140e148a52SMichael Bunk 				warn("i2c wr: len=%d is too big!\n", msg[j].len);
8150e148a52SMichael Bunk 				num = -EOPNOTSUPP;
8160e148a52SMichael Bunk 				break;
8170e148a52SMichael Bunk 			}
8180e148a52SMichael Bunk 
8190e148a52SMichael Bunk 			state->data[0] = 0x08;
8200e148a52SMichael Bunk 			state->data[1] = msg[j].addr;
8210e148a52SMichael Bunk 			state->data[2] = msg[j].len;
8220e148a52SMichael Bunk 
8230e148a52SMichael Bunk 			memcpy(&state->data[3], msg[j].buf, msg[j].len);
8240e148a52SMichael Bunk 
8250e148a52SMichael Bunk 			if (dvb_usb_generic_rw(d, state->data, msg[j].len + 3,
8260e148a52SMichael Bunk 					       state->data, 1, 0) < 0)
8270e148a52SMichael Bunk 				err("i2c transfer failed.");
8280e148a52SMichael Bunk 		} // switch
8290e148a52SMichael Bunk 		j++;
8300e148a52SMichael Bunk 
8310e148a52SMichael Bunk 	} // while
832606142afSJonathan McDowell 	mutex_unlock(&d->data_mutex);
833786baecfSMauro Carvalho Chehab 	mutex_unlock(&d->i2c_mutex);
834786baecfSMauro Carvalho Chehab 	return num;
835786baecfSMauro Carvalho Chehab }
836786baecfSMauro Carvalho Chehab 
dw210x_i2c_func(struct i2c_adapter * adapter)837786baecfSMauro Carvalho Chehab static u32 dw210x_i2c_func(struct i2c_adapter *adapter)
838786baecfSMauro Carvalho Chehab {
839786baecfSMauro Carvalho Chehab 	return I2C_FUNC_I2C;
840786baecfSMauro Carvalho Chehab }
841786baecfSMauro Carvalho Chehab 
842786baecfSMauro Carvalho Chehab static struct i2c_algorithm dw2102_i2c_algo = {
843786baecfSMauro Carvalho Chehab 	.master_xfer = dw2102_i2c_transfer,
844786baecfSMauro Carvalho Chehab 	.functionality = dw210x_i2c_func,
845786baecfSMauro Carvalho Chehab };
846786baecfSMauro Carvalho Chehab 
847786baecfSMauro Carvalho Chehab static struct i2c_algorithm dw2102_serit_i2c_algo = {
848786baecfSMauro Carvalho Chehab 	.master_xfer = dw2102_serit_i2c_transfer,
849786baecfSMauro Carvalho Chehab 	.functionality = dw210x_i2c_func,
850786baecfSMauro Carvalho Chehab };
851786baecfSMauro Carvalho Chehab 
852786baecfSMauro Carvalho Chehab static struct i2c_algorithm dw2102_earda_i2c_algo = {
853786baecfSMauro Carvalho Chehab 	.master_xfer = dw2102_earda_i2c_transfer,
854786baecfSMauro Carvalho Chehab 	.functionality = dw210x_i2c_func,
855786baecfSMauro Carvalho Chehab };
856786baecfSMauro Carvalho Chehab 
857786baecfSMauro Carvalho Chehab static struct i2c_algorithm dw2104_i2c_algo = {
858786baecfSMauro Carvalho Chehab 	.master_xfer = dw2104_i2c_transfer,
859786baecfSMauro Carvalho Chehab 	.functionality = dw210x_i2c_func,
860786baecfSMauro Carvalho Chehab };
861786baecfSMauro Carvalho Chehab 
862786baecfSMauro Carvalho Chehab static struct i2c_algorithm dw3101_i2c_algo = {
863786baecfSMauro Carvalho Chehab 	.master_xfer = dw3101_i2c_transfer,
864786baecfSMauro Carvalho Chehab 	.functionality = dw210x_i2c_func,
865786baecfSMauro Carvalho Chehab };
866786baecfSMauro Carvalho Chehab 
867786baecfSMauro Carvalho Chehab static struct i2c_algorithm s6x0_i2c_algo = {
868786baecfSMauro Carvalho Chehab 	.master_xfer = s6x0_i2c_transfer,
869786baecfSMauro Carvalho Chehab 	.functionality = dw210x_i2c_func,
870786baecfSMauro Carvalho Chehab };
871786baecfSMauro Carvalho Chehab 
872786baecfSMauro Carvalho Chehab static struct i2c_algorithm su3000_i2c_algo = {
873786baecfSMauro Carvalho Chehab 	.master_xfer = su3000_i2c_transfer,
874786baecfSMauro Carvalho Chehab 	.functionality = dw210x_i2c_func,
875786baecfSMauro Carvalho Chehab };
876786baecfSMauro Carvalho Chehab 
dw210x_read_mac_address(struct dvb_usb_device * d,u8 mac[6])877786baecfSMauro Carvalho Chehab static int dw210x_read_mac_address(struct dvb_usb_device *d, u8 mac[6])
878786baecfSMauro Carvalho Chehab {
879786baecfSMauro Carvalho Chehab 	int i;
880786baecfSMauro Carvalho Chehab 	u8 ibuf[] = {0, 0};
881786baecfSMauro Carvalho Chehab 	u8 eeprom[256], eepromline[16];
882786baecfSMauro Carvalho Chehab 
883786baecfSMauro Carvalho Chehab 	for (i = 0; i < 256; i++) {
884786baecfSMauro Carvalho Chehab 		if (dw210x_op_rw(d->udev, 0xb6, 0xa0, i, ibuf, 2, DW210X_READ_MSG) < 0) {
885786baecfSMauro Carvalho Chehab 			err("read eeprom failed.");
886b37d9c99SMauro Carvalho Chehab 			return -EIO;
887786baecfSMauro Carvalho Chehab 		} else {
888786baecfSMauro Carvalho Chehab 			eepromline[i % 16] = ibuf[0];
889786baecfSMauro Carvalho Chehab 			eeprom[i] = ibuf[0];
890786baecfSMauro Carvalho Chehab 		}
891786baecfSMauro Carvalho Chehab 		if ((i % 16) == 15) {
892786baecfSMauro Carvalho Chehab 			deb_xfer("%02x: ", i - 15);
893786baecfSMauro Carvalho Chehab 			debug_dump(eepromline, 16, deb_xfer);
894786baecfSMauro Carvalho Chehab 		}
895786baecfSMauro Carvalho Chehab 	}
896786baecfSMauro Carvalho Chehab 
897786baecfSMauro Carvalho Chehab 	memcpy(mac, eeprom + 8, 6);
898786baecfSMauro Carvalho Chehab 	return 0;
899786baecfSMauro Carvalho Chehab };
900786baecfSMauro Carvalho Chehab 
s6x0_read_mac_address(struct dvb_usb_device * d,u8 mac[6])901786baecfSMauro Carvalho Chehab static int s6x0_read_mac_address(struct dvb_usb_device *d, u8 mac[6])
902786baecfSMauro Carvalho Chehab {
903786baecfSMauro Carvalho Chehab 	int i, ret;
904786baecfSMauro Carvalho Chehab 	u8 ibuf[] = { 0 }, obuf[] = { 0 };
905786baecfSMauro Carvalho Chehab 	u8 eeprom[256], eepromline[16];
906786baecfSMauro Carvalho Chehab 	struct i2c_msg msg[] = {
907786baecfSMauro Carvalho Chehab 		{
908786baecfSMauro Carvalho Chehab 			.addr = 0xa0 >> 1,
909786baecfSMauro Carvalho Chehab 			.flags = 0,
910786baecfSMauro Carvalho Chehab 			.buf = obuf,
911786baecfSMauro Carvalho Chehab 			.len = 1,
912786baecfSMauro Carvalho Chehab 		}, {
913786baecfSMauro Carvalho Chehab 			.addr = 0xa0 >> 1,
914786baecfSMauro Carvalho Chehab 			.flags = I2C_M_RD,
915786baecfSMauro Carvalho Chehab 			.buf = ibuf,
916786baecfSMauro Carvalho Chehab 			.len = 1,
917786baecfSMauro Carvalho Chehab 		}
918786baecfSMauro Carvalho Chehab 	};
919786baecfSMauro Carvalho Chehab 
920786baecfSMauro Carvalho Chehab 	for (i = 0; i < 256; i++) {
921786baecfSMauro Carvalho Chehab 		obuf[0] = i;
922786baecfSMauro Carvalho Chehab 		ret = s6x0_i2c_transfer(&d->i2c_adap, msg, 2);
923786baecfSMauro Carvalho Chehab 		if (ret != 2) {
924786baecfSMauro Carvalho Chehab 			err("read eeprom failed.");
925b37d9c99SMauro Carvalho Chehab 			return -EIO;
926786baecfSMauro Carvalho Chehab 		} else {
927786baecfSMauro Carvalho Chehab 			eepromline[i % 16] = ibuf[0];
928786baecfSMauro Carvalho Chehab 			eeprom[i] = ibuf[0];
929786baecfSMauro Carvalho Chehab 		}
930786baecfSMauro Carvalho Chehab 
931786baecfSMauro Carvalho Chehab 		if ((i % 16) == 15) {
932786baecfSMauro Carvalho Chehab 			deb_xfer("%02x: ", i - 15);
933786baecfSMauro Carvalho Chehab 			debug_dump(eepromline, 16, deb_xfer);
934786baecfSMauro Carvalho Chehab 		}
935786baecfSMauro Carvalho Chehab 	}
936786baecfSMauro Carvalho Chehab 
937786baecfSMauro Carvalho Chehab 	memcpy(mac, eeprom + 16, 6);
938786baecfSMauro Carvalho Chehab 	return 0;
939786baecfSMauro Carvalho Chehab };
940786baecfSMauro Carvalho Chehab 
su3000_streaming_ctrl(struct dvb_usb_adapter * adap,int onoff)941786baecfSMauro Carvalho Chehab static int su3000_streaming_ctrl(struct dvb_usb_adapter *adap, int onoff)
942786baecfSMauro Carvalho Chehab {
943786baecfSMauro Carvalho Chehab 	static u8 command_start[] = {0x00};
944786baecfSMauro Carvalho Chehab 	static u8 command_stop[] = {0x01};
945786baecfSMauro Carvalho Chehab 	struct i2c_msg msg = {
946786baecfSMauro Carvalho Chehab 		.addr = SU3000_STREAM_CTRL,
947786baecfSMauro Carvalho Chehab 		.flags = 0,
948786baecfSMauro Carvalho Chehab 		.buf = onoff ? command_start : command_stop,
949786baecfSMauro Carvalho Chehab 		.len = 1
950786baecfSMauro Carvalho Chehab 	};
951786baecfSMauro Carvalho Chehab 
952786baecfSMauro Carvalho Chehab 	i2c_transfer(&adap->dev->i2c_adap, &msg, 1);
953786baecfSMauro Carvalho Chehab 
954786baecfSMauro Carvalho Chehab 	return 0;
955786baecfSMauro Carvalho Chehab }
956786baecfSMauro Carvalho Chehab 
su3000_power_ctrl(struct dvb_usb_device * d,int i)957786baecfSMauro Carvalho Chehab static int su3000_power_ctrl(struct dvb_usb_device *d, int i)
958786baecfSMauro Carvalho Chehab {
959663e7460SYu Zhe 	struct dw2102_state *state = d->priv;
960606142afSJonathan McDowell 	int ret = 0;
961786baecfSMauro Carvalho Chehab 
9620385443fSJonathan McDowell 	info("%s: %d, initialized %d", __func__, i, state->initialized);
963786baecfSMauro Carvalho Chehab 
964786baecfSMauro Carvalho Chehab 	if (i && !state->initialized) {
965606142afSJonathan McDowell 		mutex_lock(&d->data_mutex);
966606142afSJonathan McDowell 
967606142afSJonathan McDowell 		state->data[0] = 0xde;
968606142afSJonathan McDowell 		state->data[1] = 0;
969606142afSJonathan McDowell 
970786baecfSMauro Carvalho Chehab 		state->initialized = 1;
971786baecfSMauro Carvalho Chehab 		/* reset board */
972606142afSJonathan McDowell 		ret = dvb_usb_generic_rw(d, state->data, 2, NULL, 0, 0);
973606142afSJonathan McDowell 		mutex_unlock(&d->data_mutex);
974786baecfSMauro Carvalho Chehab 	}
975786baecfSMauro Carvalho Chehab 
976606142afSJonathan McDowell 	return ret;
977786baecfSMauro Carvalho Chehab }
978786baecfSMauro Carvalho Chehab 
su3000_read_mac_address(struct dvb_usb_device * d,u8 mac[6])979786baecfSMauro Carvalho Chehab static int su3000_read_mac_address(struct dvb_usb_device *d, u8 mac[6])
980786baecfSMauro Carvalho Chehab {
981786baecfSMauro Carvalho Chehab 	int i;
982786baecfSMauro Carvalho Chehab 	u8 obuf[] = { 0x1f, 0xf0 };
983786baecfSMauro Carvalho Chehab 	u8 ibuf[] = { 0 };
984786baecfSMauro Carvalho Chehab 	struct i2c_msg msg[] = {
985786baecfSMauro Carvalho Chehab 		{
986786baecfSMauro Carvalho Chehab 			.addr = 0x51,
987786baecfSMauro Carvalho Chehab 			.flags = 0,
988786baecfSMauro Carvalho Chehab 			.buf = obuf,
989786baecfSMauro Carvalho Chehab 			.len = 2,
990786baecfSMauro Carvalho Chehab 		}, {
991786baecfSMauro Carvalho Chehab 			.addr = 0x51,
992786baecfSMauro Carvalho Chehab 			.flags = I2C_M_RD,
993786baecfSMauro Carvalho Chehab 			.buf = ibuf,
994786baecfSMauro Carvalho Chehab 			.len = 1,
995786baecfSMauro Carvalho Chehab 		}
996786baecfSMauro Carvalho Chehab 	};
997786baecfSMauro Carvalho Chehab 
998786baecfSMauro Carvalho Chehab 	for (i = 0; i < 6; i++) {
999786baecfSMauro Carvalho Chehab 		obuf[1] = 0xf0 + i;
1000786baecfSMauro Carvalho Chehab 		if (i2c_transfer(&d->i2c_adap, msg, 2) != 2)
1001b37d9c99SMauro Carvalho Chehab 			return -EIO;
1002786baecfSMauro Carvalho Chehab 		else
1003786baecfSMauro Carvalho Chehab 			mac[i] = ibuf[0];
1004786baecfSMauro Carvalho Chehab 	}
1005786baecfSMauro Carvalho Chehab 
1006786baecfSMauro Carvalho Chehab 	return 0;
1007786baecfSMauro Carvalho Chehab }
1008786baecfSMauro Carvalho Chehab 
su3000_identify_state(struct usb_device * udev,const struct dvb_usb_device_properties * props,const struct dvb_usb_device_description ** desc,int * cold)1009786baecfSMauro Carvalho Chehab static int su3000_identify_state(struct usb_device *udev,
1010d27958dfSSean Young 				 const struct dvb_usb_device_properties *props,
1011d27958dfSSean Young 				 const struct dvb_usb_device_description **desc,
1012786baecfSMauro Carvalho Chehab 				 int *cold)
1013786baecfSMauro Carvalho Chehab {
1014786baecfSMauro Carvalho Chehab 	*cold = 0;
1015786baecfSMauro Carvalho Chehab 	return 0;
1016786baecfSMauro Carvalho Chehab }
1017786baecfSMauro Carvalho Chehab 
dw210x_set_voltage(struct dvb_frontend * fe,enum fe_sec_voltage voltage)10180df289a2SMauro Carvalho Chehab static int dw210x_set_voltage(struct dvb_frontend *fe,
10190df289a2SMauro Carvalho Chehab 			      enum fe_sec_voltage voltage)
1020786baecfSMauro Carvalho Chehab {
1021786baecfSMauro Carvalho Chehab 	static u8 command_13v[] = {0x00, 0x01};
1022786baecfSMauro Carvalho Chehab 	static u8 command_18v[] = {0x01, 0x01};
1023786baecfSMauro Carvalho Chehab 	static u8 command_off[] = {0x00, 0x00};
1024786baecfSMauro Carvalho Chehab 	struct i2c_msg msg = {
1025786baecfSMauro Carvalho Chehab 		.addr = DW2102_VOLTAGE_CTRL,
1026786baecfSMauro Carvalho Chehab 		.flags = 0,
1027786baecfSMauro Carvalho Chehab 		.buf = command_off,
1028786baecfSMauro Carvalho Chehab 		.len = 2,
1029786baecfSMauro Carvalho Chehab 	};
1030786baecfSMauro Carvalho Chehab 
1031663e7460SYu Zhe 	struct dvb_usb_adapter *udev_adap = fe->dvb->priv;
10324a7d7351SMauro Carvalho Chehab 
1033786baecfSMauro Carvalho Chehab 	if (voltage == SEC_VOLTAGE_18)
1034786baecfSMauro Carvalho Chehab 		msg.buf = command_18v;
1035786baecfSMauro Carvalho Chehab 	else if (voltage == SEC_VOLTAGE_13)
1036786baecfSMauro Carvalho Chehab 		msg.buf = command_13v;
1037786baecfSMauro Carvalho Chehab 
1038786baecfSMauro Carvalho Chehab 	i2c_transfer(&udev_adap->dev->i2c_adap, &msg, 1);
1039786baecfSMauro Carvalho Chehab 
1040786baecfSMauro Carvalho Chehab 	return 0;
1041786baecfSMauro Carvalho Chehab }
1042786baecfSMauro Carvalho Chehab 
s660_set_voltage(struct dvb_frontend * fe,enum fe_sec_voltage voltage)10430df289a2SMauro Carvalho Chehab static int s660_set_voltage(struct dvb_frontend *fe,
10440df289a2SMauro Carvalho Chehab 			    enum fe_sec_voltage voltage)
1045786baecfSMauro Carvalho Chehab {
1046663e7460SYu Zhe 	struct dvb_usb_adapter *d = fe->dvb->priv;
1047663e7460SYu Zhe 	struct dw2102_state *st = d->dev->priv;
1048786baecfSMauro Carvalho Chehab 
1049786baecfSMauro Carvalho Chehab 	dw210x_set_voltage(fe, voltage);
1050786baecfSMauro Carvalho Chehab 	if (st->old_set_voltage)
1051786baecfSMauro Carvalho Chehab 		st->old_set_voltage(fe, voltage);
1052786baecfSMauro Carvalho Chehab 
1053786baecfSMauro Carvalho Chehab 	return 0;
1054786baecfSMauro Carvalho Chehab }
1055786baecfSMauro Carvalho Chehab 
dw210x_led_ctrl(struct dvb_frontend * fe,int offon)1056786baecfSMauro Carvalho Chehab static void dw210x_led_ctrl(struct dvb_frontend *fe, int offon)
1057786baecfSMauro Carvalho Chehab {
1058786baecfSMauro Carvalho Chehab 	static u8 led_off[] = { 0 };
1059786baecfSMauro Carvalho Chehab 	static u8 led_on[] = { 1 };
1060786baecfSMauro Carvalho Chehab 	struct i2c_msg msg = {
1061786baecfSMauro Carvalho Chehab 		.addr = DW2102_LED_CTRL,
1062786baecfSMauro Carvalho Chehab 		.flags = 0,
1063786baecfSMauro Carvalho Chehab 		.buf = led_off,
1064786baecfSMauro Carvalho Chehab 		.len = 1
1065786baecfSMauro Carvalho Chehab 	};
1066663e7460SYu Zhe 	struct dvb_usb_adapter *udev_adap = fe->dvb->priv;
1067786baecfSMauro Carvalho Chehab 
1068786baecfSMauro Carvalho Chehab 	if (offon)
1069786baecfSMauro Carvalho Chehab 		msg.buf = led_on;
1070786baecfSMauro Carvalho Chehab 	i2c_transfer(&udev_adap->dev->i2c_adap, &msg, 1);
1071786baecfSMauro Carvalho Chehab }
1072786baecfSMauro Carvalho Chehab 
tt_s2_4600_read_status(struct dvb_frontend * fe,enum fe_status * status)10730df289a2SMauro Carvalho Chehab static int tt_s2_4600_read_status(struct dvb_frontend *fe,
10740df289a2SMauro Carvalho Chehab 				  enum fe_status *status)
1075356484caSOlli Salonen {
1076663e7460SYu Zhe 	struct dvb_usb_adapter *d = fe->dvb->priv;
1077663e7460SYu Zhe 	struct dw2102_state *st = d->dev->priv;
1078356484caSOlli Salonen 	int ret;
1079356484caSOlli Salonen 
1080356484caSOlli Salonen 	ret = st->fe_read_status(fe, status);
1081356484caSOlli Salonen 
1082356484caSOlli Salonen 	/* resync slave fifo when signal change from unlock to lock */
1083356484caSOlli Salonen 	if ((*status & FE_HAS_LOCK) && (!st->last_lock))
1084356484caSOlli Salonen 		su3000_streaming_ctrl(d, 1);
1085356484caSOlli Salonen 
1086356484caSOlli Salonen 	st->last_lock = (*status & FE_HAS_LOCK) ? 1 : 0;
1087356484caSOlli Salonen 	return ret;
1088356484caSOlli Salonen }
1089356484caSOlli Salonen 
1090786baecfSMauro Carvalho Chehab static struct stv0299_config sharp_z0194a_config = {
1091786baecfSMauro Carvalho Chehab 	.demod_address = 0x68,
1092786baecfSMauro Carvalho Chehab 	.inittab = sharp_z0194a_inittab,
1093786baecfSMauro Carvalho Chehab 	.mclk = 88000000UL,
1094786baecfSMauro Carvalho Chehab 	.invert = 1,
1095786baecfSMauro Carvalho Chehab 	.skip_reinit = 0,
1096786baecfSMauro Carvalho Chehab 	.lock_output = STV0299_LOCKOUTPUT_1,
1097786baecfSMauro Carvalho Chehab 	.volt13_op0_op1 = STV0299_VOLT13_OP1,
1098786baecfSMauro Carvalho Chehab 	.min_delay_ms = 100,
1099786baecfSMauro Carvalho Chehab 	.set_symbol_rate = sharp_z0194a_set_symbol_rate,
1100786baecfSMauro Carvalho Chehab };
1101786baecfSMauro Carvalho Chehab 
1102786baecfSMauro Carvalho Chehab static struct cx24116_config dw2104_config = {
1103786baecfSMauro Carvalho Chehab 	.demod_address = 0x55,
1104786baecfSMauro Carvalho Chehab 	.mpg_clk_pos_pol = 0x01,
1105786baecfSMauro Carvalho Chehab };
1106786baecfSMauro Carvalho Chehab 
1107786baecfSMauro Carvalho Chehab static struct si21xx_config serit_sp1511lhb_config = {
1108786baecfSMauro Carvalho Chehab 	.demod_address = 0x68,
1109786baecfSMauro Carvalho Chehab 	.min_delay_ms = 100,
1110786baecfSMauro Carvalho Chehab 
1111786baecfSMauro Carvalho Chehab };
1112786baecfSMauro Carvalho Chehab 
1113786baecfSMauro Carvalho Chehab static struct tda10023_config dw3101_tda10023_config = {
1114786baecfSMauro Carvalho Chehab 	.demod_address = 0x0c,
1115786baecfSMauro Carvalho Chehab 	.invert = 1,
1116786baecfSMauro Carvalho Chehab };
1117786baecfSMauro Carvalho Chehab 
1118786baecfSMauro Carvalho Chehab static struct mt312_config zl313_config = {
1119786baecfSMauro Carvalho Chehab 	.demod_address = 0x0e,
1120786baecfSMauro Carvalho Chehab };
1121786baecfSMauro Carvalho Chehab 
1122786baecfSMauro Carvalho Chehab static struct ds3000_config dw2104_ds3000_config = {
1123786baecfSMauro Carvalho Chehab 	.demod_address = 0x68,
1124786baecfSMauro Carvalho Chehab };
1125786baecfSMauro Carvalho Chehab 
112673f0af44SKonstantin Dimitrov static struct ts2020_config dw2104_ts2020_config = {
112773f0af44SKonstantin Dimitrov 	.tuner_address = 0x60,
1128b858c331SIgor M. Liplianin 	.clk_out_div = 1,
112903a67279SJohn Horan 	.frequency_div = 1060000,
113073f0af44SKonstantin Dimitrov };
113173f0af44SKonstantin Dimitrov 
113243385c8aSIgor M. Liplianin static struct ds3000_config s660_ds3000_config = {
113343385c8aSIgor M. Liplianin 	.demod_address = 0x68,
1134b858c331SIgor M. Liplianin 	.ci_mode = 1,
113543385c8aSIgor M. Liplianin 	.set_lock_led = dw210x_led_ctrl,
113643385c8aSIgor M. Liplianin };
113743385c8aSIgor M. Liplianin 
113803a67279SJohn Horan static struct ts2020_config s660_ts2020_config = {
113903a67279SJohn Horan 	.tuner_address = 0x60,
114003a67279SJohn Horan 	.clk_out_div = 1,
114103a67279SJohn Horan 	.frequency_div = 1146000,
114203a67279SJohn Horan };
114303a67279SJohn Horan 
1144786baecfSMauro Carvalho Chehab static struct stv0900_config dw2104a_stv0900_config = {
1145786baecfSMauro Carvalho Chehab 	.demod_address = 0x6a,
1146786baecfSMauro Carvalho Chehab 	.demod_mode = 0,
1147786baecfSMauro Carvalho Chehab 	.xtal = 27000000,
1148786baecfSMauro Carvalho Chehab 	.clkmode = 3,/* 0-CLKI, 2-XTALI, else AUTO */
1149786baecfSMauro Carvalho Chehab 	.diseqc_mode = 2,/* 2/3 PWM */
1150786baecfSMauro Carvalho Chehab 	.tun1_maddress = 0,/* 0x60 */
1151786baecfSMauro Carvalho Chehab 	.tun1_adc = 0,/* 2 Vpp */
1152786baecfSMauro Carvalho Chehab 	.path1_mode = 3,
1153786baecfSMauro Carvalho Chehab };
1154786baecfSMauro Carvalho Chehab 
1155786baecfSMauro Carvalho Chehab static struct stb6100_config dw2104a_stb6100_config = {
1156786baecfSMauro Carvalho Chehab 	.tuner_address = 0x60,
1157786baecfSMauro Carvalho Chehab 	.refclock = 27000000,
1158786baecfSMauro Carvalho Chehab };
1159786baecfSMauro Carvalho Chehab 
1160786baecfSMauro Carvalho Chehab static struct stv0900_config dw2104_stv0900_config = {
1161786baecfSMauro Carvalho Chehab 	.demod_address = 0x68,
1162786baecfSMauro Carvalho Chehab 	.demod_mode = 0,
1163786baecfSMauro Carvalho Chehab 	.xtal = 8000000,
1164786baecfSMauro Carvalho Chehab 	.clkmode = 3,
1165786baecfSMauro Carvalho Chehab 	.diseqc_mode = 2,
1166786baecfSMauro Carvalho Chehab 	.tun1_maddress = 0,
1167786baecfSMauro Carvalho Chehab 	.tun1_adc = 1,/* 1 Vpp */
1168786baecfSMauro Carvalho Chehab 	.path1_mode = 3,
1169786baecfSMauro Carvalho Chehab };
1170786baecfSMauro Carvalho Chehab 
1171786baecfSMauro Carvalho Chehab static struct stv6110_config dw2104_stv6110_config = {
1172786baecfSMauro Carvalho Chehab 	.i2c_address = 0x60,
1173786baecfSMauro Carvalho Chehab 	.mclk = 16000000,
1174786baecfSMauro Carvalho Chehab 	.clk_div = 1,
1175786baecfSMauro Carvalho Chehab };
1176786baecfSMauro Carvalho Chehab 
1177786baecfSMauro Carvalho Chehab static struct stv0900_config prof_7500_stv0900_config = {
1178786baecfSMauro Carvalho Chehab 	.demod_address = 0x6a,
1179786baecfSMauro Carvalho Chehab 	.demod_mode = 0,
1180786baecfSMauro Carvalho Chehab 	.xtal = 27000000,
1181786baecfSMauro Carvalho Chehab 	.clkmode = 3,/* 0-CLKI, 2-XTALI, else AUTO */
1182786baecfSMauro Carvalho Chehab 	.diseqc_mode = 2,/* 2/3 PWM */
1183786baecfSMauro Carvalho Chehab 	.tun1_maddress = 0,/* 0x60 */
1184786baecfSMauro Carvalho Chehab 	.tun1_adc = 0,/* 2 Vpp */
1185786baecfSMauro Carvalho Chehab 	.path1_mode = 3,
1186786baecfSMauro Carvalho Chehab 	.tun1_type = 3,
1187786baecfSMauro Carvalho Chehab 	.set_lock_led = dw210x_led_ctrl,
1188786baecfSMauro Carvalho Chehab };
1189786baecfSMauro Carvalho Chehab 
1190786baecfSMauro Carvalho Chehab static struct ds3000_config su3000_ds3000_config = {
1191786baecfSMauro Carvalho Chehab 	.demod_address = 0x68,
1192786baecfSMauro Carvalho Chehab 	.ci_mode = 1,
1193b858c331SIgor M. Liplianin 	.set_lock_led = dw210x_led_ctrl,
119473f0af44SKonstantin Dimitrov };
119573f0af44SKonstantin Dimitrov 
119651d882edSEvgeny Plehov static struct cxd2820r_config cxd2820r_config = {
119751d882edSEvgeny Plehov 	.i2c_address = 0x6c, /* (0xd8 >> 1) */
119851d882edSEvgeny Plehov 	.ts_mode = 0x38,
11997b71ef7eSCrazyCat 	.ts_clock_inv = 1,
120051d882edSEvgeny Plehov };
120151d882edSEvgeny Plehov 
120251d882edSEvgeny Plehov static struct tda18271_config tda18271_config = {
120351d882edSEvgeny Plehov 	.output_opt = TDA18271_OUTPUT_LT_OFF,
120451d882edSEvgeny Plehov 	.gate = TDA18271_GATE_DIGITAL,
120551d882edSEvgeny Plehov };
120651d882edSEvgeny Plehov 
1207955d00acSIgor M. Liplianin static u8 m88rs2000_inittab[] = {
1208955d00acSIgor M. Liplianin 	DEMOD_WRITE, 0x9a, 0x30,
1209955d00acSIgor M. Liplianin 	DEMOD_WRITE, 0x00, 0x01,
1210955d00acSIgor M. Liplianin 	WRITE_DELAY, 0x19, 0x00,
1211955d00acSIgor M. Liplianin 	DEMOD_WRITE, 0x00, 0x00,
1212955d00acSIgor M. Liplianin 	DEMOD_WRITE, 0x9a, 0xb0,
1213955d00acSIgor M. Liplianin 	DEMOD_WRITE, 0x81, 0xc1,
1214955d00acSIgor M. Liplianin 	DEMOD_WRITE, 0x81, 0x81,
1215955d00acSIgor M. Liplianin 	DEMOD_WRITE, 0x86, 0xc6,
1216955d00acSIgor M. Liplianin 	DEMOD_WRITE, 0x9a, 0x30,
1217955d00acSIgor M. Liplianin 	DEMOD_WRITE, 0xf0, 0x80,
1218955d00acSIgor M. Liplianin 	DEMOD_WRITE, 0xf1, 0xbf,
1219955d00acSIgor M. Liplianin 	DEMOD_WRITE, 0xb0, 0x45,
1220955d00acSIgor M. Liplianin 	DEMOD_WRITE, 0xb2, 0x01,
1221955d00acSIgor M. Liplianin 	DEMOD_WRITE, 0x9a, 0xb0,
1222955d00acSIgor M. Liplianin 	0xff, 0xaa, 0xff
1223955d00acSIgor M. Liplianin };
1224955d00acSIgor M. Liplianin 
1225955d00acSIgor M. Liplianin static struct m88rs2000_config s421_m88rs2000_config = {
1226955d00acSIgor M. Liplianin 	.demod_addr = 0x68,
1227955d00acSIgor M. Liplianin 	.inittab = m88rs2000_inittab,
1228955d00acSIgor M. Liplianin };
1229955d00acSIgor M. Liplianin 
dw2104_frontend_attach(struct dvb_usb_adapter * d)1230786baecfSMauro Carvalho Chehab static int dw2104_frontend_attach(struct dvb_usb_adapter *d)
1231786baecfSMauro Carvalho Chehab {
1232786baecfSMauro Carvalho Chehab 	struct dvb_tuner_ops *tuner_ops = NULL;
1233786baecfSMauro Carvalho Chehab 
1234786baecfSMauro Carvalho Chehab 	if (demod_probe & 4) {
1235786baecfSMauro Carvalho Chehab 		d->fe_adap[0].fe = dvb_attach(stv0900_attach, &dw2104a_stv0900_config,
1236786baecfSMauro Carvalho Chehab 					      &d->dev->i2c_adap, 0);
12374a7d7351SMauro Carvalho Chehab 		if (d->fe_adap[0].fe) {
1238786baecfSMauro Carvalho Chehab 			if (dvb_attach(stb6100_attach, d->fe_adap[0].fe,
1239786baecfSMauro Carvalho Chehab 				       &dw2104a_stb6100_config,
1240786baecfSMauro Carvalho Chehab 				       &d->dev->i2c_adap)) {
1241786baecfSMauro Carvalho Chehab 				tuner_ops = &d->fe_adap[0].fe->ops.tuner_ops;
1242786baecfSMauro Carvalho Chehab 				tuner_ops->set_frequency = stb6100_set_freq;
1243786baecfSMauro Carvalho Chehab 				tuner_ops->get_frequency = stb6100_get_freq;
1244786baecfSMauro Carvalho Chehab 				tuner_ops->set_bandwidth = stb6100_set_bandw;
1245786baecfSMauro Carvalho Chehab 				tuner_ops->get_bandwidth = stb6100_get_bandw;
1246786baecfSMauro Carvalho Chehab 				d->fe_adap[0].fe->ops.set_voltage = dw210x_set_voltage;
12470385443fSJonathan McDowell 				info("Attached STV0900+STB6100!");
1248786baecfSMauro Carvalho Chehab 				return 0;
1249786baecfSMauro Carvalho Chehab 			}
1250786baecfSMauro Carvalho Chehab 		}
1251786baecfSMauro Carvalho Chehab 	}
1252786baecfSMauro Carvalho Chehab 
1253786baecfSMauro Carvalho Chehab 	if (demod_probe & 2) {
1254786baecfSMauro Carvalho Chehab 		d->fe_adap[0].fe = dvb_attach(stv0900_attach, &dw2104_stv0900_config,
1255786baecfSMauro Carvalho Chehab 					      &d->dev->i2c_adap, 0);
12564a7d7351SMauro Carvalho Chehab 		if (d->fe_adap[0].fe) {
1257786baecfSMauro Carvalho Chehab 			if (dvb_attach(stv6110_attach, d->fe_adap[0].fe,
1258786baecfSMauro Carvalho Chehab 				       &dw2104_stv6110_config,
1259786baecfSMauro Carvalho Chehab 				       &d->dev->i2c_adap)) {
1260786baecfSMauro Carvalho Chehab 				d->fe_adap[0].fe->ops.set_voltage = dw210x_set_voltage;
12610385443fSJonathan McDowell 				info("Attached STV0900+STV6110A!");
1262786baecfSMauro Carvalho Chehab 				return 0;
1263786baecfSMauro Carvalho Chehab 			}
1264786baecfSMauro Carvalho Chehab 		}
1265786baecfSMauro Carvalho Chehab 	}
1266786baecfSMauro Carvalho Chehab 
1267786baecfSMauro Carvalho Chehab 	if (demod_probe & 1) {
1268786baecfSMauro Carvalho Chehab 		d->fe_adap[0].fe = dvb_attach(cx24116_attach, &dw2104_config,
1269786baecfSMauro Carvalho Chehab 					      &d->dev->i2c_adap);
12704a7d7351SMauro Carvalho Chehab 		if (d->fe_adap[0].fe) {
1271786baecfSMauro Carvalho Chehab 			d->fe_adap[0].fe->ops.set_voltage = dw210x_set_voltage;
12720385443fSJonathan McDowell 			info("Attached cx24116!");
1273786baecfSMauro Carvalho Chehab 			return 0;
1274786baecfSMauro Carvalho Chehab 		}
1275786baecfSMauro Carvalho Chehab 	}
1276786baecfSMauro Carvalho Chehab 
1277786baecfSMauro Carvalho Chehab 	d->fe_adap[0].fe = dvb_attach(ds3000_attach, &dw2104_ds3000_config,
1278786baecfSMauro Carvalho Chehab 				      &d->dev->i2c_adap);
12794a7d7351SMauro Carvalho Chehab 	if (d->fe_adap[0].fe) {
128073f0af44SKonstantin Dimitrov 		dvb_attach(ts2020_attach, d->fe_adap[0].fe,
128173f0af44SKonstantin Dimitrov 			   &dw2104_ts2020_config, &d->dev->i2c_adap);
1282786baecfSMauro Carvalho Chehab 		d->fe_adap[0].fe->ops.set_voltage = dw210x_set_voltage;
12830385443fSJonathan McDowell 		info("Attached DS3000!");
1284786baecfSMauro Carvalho Chehab 		return 0;
1285786baecfSMauro Carvalho Chehab 	}
1286786baecfSMauro Carvalho Chehab 
1287786baecfSMauro Carvalho Chehab 	return -EIO;
1288786baecfSMauro Carvalho Chehab }
1289786baecfSMauro Carvalho Chehab 
1290786baecfSMauro Carvalho Chehab static struct dvb_usb_device_properties dw2102_properties;
1291786baecfSMauro Carvalho Chehab static struct dvb_usb_device_properties dw2104_properties;
1292786baecfSMauro Carvalho Chehab static struct dvb_usb_device_properties s6x0_properties;
1293786baecfSMauro Carvalho Chehab 
dw2102_frontend_attach(struct dvb_usb_adapter * d)1294786baecfSMauro Carvalho Chehab static int dw2102_frontend_attach(struct dvb_usb_adapter *d)
1295786baecfSMauro Carvalho Chehab {
1296786baecfSMauro Carvalho Chehab 	if (dw2102_properties.i2c_algo == &dw2102_serit_i2c_algo) {
1297786baecfSMauro Carvalho Chehab 		/*dw2102_properties.adapter->tuner_attach = NULL;*/
1298786baecfSMauro Carvalho Chehab 		d->fe_adap[0].fe = dvb_attach(si21xx_attach, &serit_sp1511lhb_config,
1299786baecfSMauro Carvalho Chehab 					      &d->dev->i2c_adap);
13004a7d7351SMauro Carvalho Chehab 		if (d->fe_adap[0].fe) {
1301786baecfSMauro Carvalho Chehab 			d->fe_adap[0].fe->ops.set_voltage = dw210x_set_voltage;
13020385443fSJonathan McDowell 			info("Attached si21xx!");
1303786baecfSMauro Carvalho Chehab 			return 0;
1304786baecfSMauro Carvalho Chehab 		}
1305786baecfSMauro Carvalho Chehab 	}
1306786baecfSMauro Carvalho Chehab 
1307786baecfSMauro Carvalho Chehab 	if (dw2102_properties.i2c_algo == &dw2102_earda_i2c_algo) {
1308786baecfSMauro Carvalho Chehab 		d->fe_adap[0].fe = dvb_attach(stv0288_attach, &earda_config,
1309786baecfSMauro Carvalho Chehab 					      &d->dev->i2c_adap);
13104a7d7351SMauro Carvalho Chehab 		if (d->fe_adap[0].fe) {
1311786baecfSMauro Carvalho Chehab 			if (dvb_attach(stb6000_attach, d->fe_adap[0].fe, 0x61,
1312786baecfSMauro Carvalho Chehab 				       &d->dev->i2c_adap)) {
1313786baecfSMauro Carvalho Chehab 				d->fe_adap[0].fe->ops.set_voltage = dw210x_set_voltage;
13140385443fSJonathan McDowell 				info("Attached stv0288!");
1315786baecfSMauro Carvalho Chehab 				return 0;
1316786baecfSMauro Carvalho Chehab 			}
1317786baecfSMauro Carvalho Chehab 		}
1318786baecfSMauro Carvalho Chehab 	}
1319786baecfSMauro Carvalho Chehab 
1320786baecfSMauro Carvalho Chehab 	if (dw2102_properties.i2c_algo == &dw2102_i2c_algo) {
1321786baecfSMauro Carvalho Chehab 		/*dw2102_properties.adapter->tuner_attach = dw2102_tuner_attach;*/
1322786baecfSMauro Carvalho Chehab 		d->fe_adap[0].fe = dvb_attach(stv0299_attach, &sharp_z0194a_config,
1323786baecfSMauro Carvalho Chehab 					      &d->dev->i2c_adap);
13244a7d7351SMauro Carvalho Chehab 		if (d->fe_adap[0].fe) {
1325786baecfSMauro Carvalho Chehab 			d->fe_adap[0].fe->ops.set_voltage = dw210x_set_voltage;
13260385443fSJonathan McDowell 			info("Attached stv0299!");
1327786baecfSMauro Carvalho Chehab 			return 0;
1328786baecfSMauro Carvalho Chehab 		}
1329786baecfSMauro Carvalho Chehab 	}
1330786baecfSMauro Carvalho Chehab 	return -EIO;
1331786baecfSMauro Carvalho Chehab }
1332786baecfSMauro Carvalho Chehab 
dw3101_frontend_attach(struct dvb_usb_adapter * d)1333786baecfSMauro Carvalho Chehab static int dw3101_frontend_attach(struct dvb_usb_adapter *d)
1334786baecfSMauro Carvalho Chehab {
1335786baecfSMauro Carvalho Chehab 	d->fe_adap[0].fe = dvb_attach(tda10023_attach, &dw3101_tda10023_config,
1336786baecfSMauro Carvalho Chehab 				      &d->dev->i2c_adap, 0x48);
13374a7d7351SMauro Carvalho Chehab 	if (d->fe_adap[0].fe) {
13380385443fSJonathan McDowell 		info("Attached tda10023!");
1339786baecfSMauro Carvalho Chehab 		return 0;
1340786baecfSMauro Carvalho Chehab 	}
1341786baecfSMauro Carvalho Chehab 	return -EIO;
1342786baecfSMauro Carvalho Chehab }
1343786baecfSMauro Carvalho Chehab 
zl100313_frontend_attach(struct dvb_usb_adapter * d)1344786baecfSMauro Carvalho Chehab static int zl100313_frontend_attach(struct dvb_usb_adapter *d)
1345786baecfSMauro Carvalho Chehab {
1346786baecfSMauro Carvalho Chehab 	d->fe_adap[0].fe = dvb_attach(mt312_attach, &zl313_config,
1347786baecfSMauro Carvalho Chehab 				      &d->dev->i2c_adap);
13484a7d7351SMauro Carvalho Chehab 	if (d->fe_adap[0].fe) {
1349786baecfSMauro Carvalho Chehab 		if (dvb_attach(zl10039_attach, d->fe_adap[0].fe, 0x60,
1350786baecfSMauro Carvalho Chehab 			       &d->dev->i2c_adap)) {
1351786baecfSMauro Carvalho Chehab 			d->fe_adap[0].fe->ops.set_voltage = dw210x_set_voltage;
13520385443fSJonathan McDowell 			info("Attached zl100313+zl10039!");
1353786baecfSMauro Carvalho Chehab 			return 0;
1354786baecfSMauro Carvalho Chehab 		}
1355786baecfSMauro Carvalho Chehab 	}
1356786baecfSMauro Carvalho Chehab 
1357786baecfSMauro Carvalho Chehab 	return -EIO;
1358786baecfSMauro Carvalho Chehab }
1359786baecfSMauro Carvalho Chehab 
stv0288_frontend_attach(struct dvb_usb_adapter * d)1360786baecfSMauro Carvalho Chehab static int stv0288_frontend_attach(struct dvb_usb_adapter *d)
1361786baecfSMauro Carvalho Chehab {
1362786baecfSMauro Carvalho Chehab 	u8 obuf[] = {7, 1};
1363786baecfSMauro Carvalho Chehab 
1364786baecfSMauro Carvalho Chehab 	d->fe_adap[0].fe = dvb_attach(stv0288_attach, &earda_config,
1365786baecfSMauro Carvalho Chehab 				      &d->dev->i2c_adap);
1366786baecfSMauro Carvalho Chehab 
13674a7d7351SMauro Carvalho Chehab 	if (!d->fe_adap[0].fe)
1368786baecfSMauro Carvalho Chehab 		return -EIO;
1369786baecfSMauro Carvalho Chehab 
1370efc3e49dSMichael Bunk 	if (dvb_attach(stb6000_attach, d->fe_adap[0].fe, 0x61, &d->dev->i2c_adap) == NULL)
1371786baecfSMauro Carvalho Chehab 		return -EIO;
1372786baecfSMauro Carvalho Chehab 
1373786baecfSMauro Carvalho Chehab 	d->fe_adap[0].fe->ops.set_voltage = dw210x_set_voltage;
1374786baecfSMauro Carvalho Chehab 
1375786baecfSMauro Carvalho Chehab 	dw210x_op_rw(d->dev->udev, 0x8a, 0, 0, obuf, 2, DW210X_WRITE_MSG);
1376786baecfSMauro Carvalho Chehab 
13770385443fSJonathan McDowell 	info("Attached stv0288+stb6000!");
1378786baecfSMauro Carvalho Chehab 
1379786baecfSMauro Carvalho Chehab 	return 0;
1380786baecfSMauro Carvalho Chehab }
1381786baecfSMauro Carvalho Chehab 
ds3000_frontend_attach(struct dvb_usb_adapter * d)1382786baecfSMauro Carvalho Chehab static int ds3000_frontend_attach(struct dvb_usb_adapter *d)
1383786baecfSMauro Carvalho Chehab {
13842c4ffe27SOlli Salonen 	struct dw2102_state *st = d->dev->priv;
1385786baecfSMauro Carvalho Chehab 	u8 obuf[] = {7, 1};
1386786baecfSMauro Carvalho Chehab 
138743385c8aSIgor M. Liplianin 	d->fe_adap[0].fe = dvb_attach(ds3000_attach, &s660_ds3000_config,
1388786baecfSMauro Carvalho Chehab 				      &d->dev->i2c_adap);
1389786baecfSMauro Carvalho Chehab 
13904a7d7351SMauro Carvalho Chehab 	if (!d->fe_adap[0].fe)
1391786baecfSMauro Carvalho Chehab 		return -EIO;
1392786baecfSMauro Carvalho Chehab 
139303a67279SJohn Horan 	dvb_attach(ts2020_attach, d->fe_adap[0].fe, &s660_ts2020_config,
139473f0af44SKonstantin Dimitrov 		   &d->dev->i2c_adap);
139573f0af44SKonstantin Dimitrov 
1396786baecfSMauro Carvalho Chehab 	st->old_set_voltage = d->fe_adap[0].fe->ops.set_voltage;
1397786baecfSMauro Carvalho Chehab 	d->fe_adap[0].fe->ops.set_voltage = s660_set_voltage;
1398786baecfSMauro Carvalho Chehab 
1399786baecfSMauro Carvalho Chehab 	dw210x_op_rw(d->dev->udev, 0x8a, 0, 0, obuf, 2, DW210X_WRITE_MSG);
1400786baecfSMauro Carvalho Chehab 
14010385443fSJonathan McDowell 	info("Attached ds3000+ts2020!");
1402786baecfSMauro Carvalho Chehab 
1403786baecfSMauro Carvalho Chehab 	return 0;
1404786baecfSMauro Carvalho Chehab }
1405786baecfSMauro Carvalho Chehab 
prof_7500_frontend_attach(struct dvb_usb_adapter * d)1406786baecfSMauro Carvalho Chehab static int prof_7500_frontend_attach(struct dvb_usb_adapter *d)
1407786baecfSMauro Carvalho Chehab {
1408786baecfSMauro Carvalho Chehab 	u8 obuf[] = {7, 1};
1409786baecfSMauro Carvalho Chehab 
1410786baecfSMauro Carvalho Chehab 	d->fe_adap[0].fe = dvb_attach(stv0900_attach, &prof_7500_stv0900_config,
1411786baecfSMauro Carvalho Chehab 				      &d->dev->i2c_adap, 0);
14124a7d7351SMauro Carvalho Chehab 	if (!d->fe_adap[0].fe)
1413786baecfSMauro Carvalho Chehab 		return -EIO;
1414786baecfSMauro Carvalho Chehab 
1415786baecfSMauro Carvalho Chehab 	d->fe_adap[0].fe->ops.set_voltage = dw210x_set_voltage;
1416786baecfSMauro Carvalho Chehab 
1417786baecfSMauro Carvalho Chehab 	dw210x_op_rw(d->dev->udev, 0x8a, 0, 0, obuf, 2, DW210X_WRITE_MSG);
1418786baecfSMauro Carvalho Chehab 
14190385443fSJonathan McDowell 	info("Attached STV0900+STB6100A!");
1420786baecfSMauro Carvalho Chehab 
1421786baecfSMauro Carvalho Chehab 	return 0;
1422786baecfSMauro Carvalho Chehab }
1423786baecfSMauro Carvalho Chehab 
su3000_frontend_attach(struct dvb_usb_adapter * adap)1424606142afSJonathan McDowell static int su3000_frontend_attach(struct dvb_usb_adapter *adap)
1425786baecfSMauro Carvalho Chehab {
1426606142afSJonathan McDowell 	struct dvb_usb_device *d = adap->dev;
1427606142afSJonathan McDowell 	struct dw2102_state *state = d->priv;
1428786baecfSMauro Carvalho Chehab 
1429606142afSJonathan McDowell 	mutex_lock(&d->data_mutex);
1430606142afSJonathan McDowell 
1431606142afSJonathan McDowell 	state->data[0] = 0xe;
1432606142afSJonathan McDowell 	state->data[1] = 0x80;
1433606142afSJonathan McDowell 	state->data[2] = 0;
1434606142afSJonathan McDowell 
1435606142afSJonathan McDowell 	if (dvb_usb_generic_rw(d, state->data, 3, state->data, 1, 0) < 0)
1436786baecfSMauro Carvalho Chehab 		err("command 0x0e transfer failed.");
1437786baecfSMauro Carvalho Chehab 
1438606142afSJonathan McDowell 	state->data[0] = 0xe;
1439606142afSJonathan McDowell 	state->data[1] = 0x02;
1440606142afSJonathan McDowell 	state->data[2] = 1;
1441b858c331SIgor M. Liplianin 
1442606142afSJonathan McDowell 	if (dvb_usb_generic_rw(d, state->data, 3, state->data, 1, 0) < 0)
1443b858c331SIgor M. Liplianin 		err("command 0x0e transfer failed.");
1444b858c331SIgor M. Liplianin 	msleep(300);
1445b858c331SIgor M. Liplianin 
1446606142afSJonathan McDowell 	state->data[0] = 0xe;
1447606142afSJonathan McDowell 	state->data[1] = 0x83;
1448606142afSJonathan McDowell 	state->data[2] = 0;
1449786baecfSMauro Carvalho Chehab 
1450606142afSJonathan McDowell 	if (dvb_usb_generic_rw(d, state->data, 3, state->data, 1, 0) < 0)
1451786baecfSMauro Carvalho Chehab 		err("command 0x0e transfer failed.");
1452786baecfSMauro Carvalho Chehab 
1453606142afSJonathan McDowell 	state->data[0] = 0xe;
1454606142afSJonathan McDowell 	state->data[1] = 0x83;
1455606142afSJonathan McDowell 	state->data[2] = 1;
1456786baecfSMauro Carvalho Chehab 
1457606142afSJonathan McDowell 	if (dvb_usb_generic_rw(d, state->data, 3, state->data, 1, 0) < 0)
1458786baecfSMauro Carvalho Chehab 		err("command 0x0e transfer failed.");
1459786baecfSMauro Carvalho Chehab 
1460606142afSJonathan McDowell 	state->data[0] = 0x51;
1461786baecfSMauro Carvalho Chehab 
1462606142afSJonathan McDowell 	if (dvb_usb_generic_rw(d, state->data, 1, state->data, 1, 0) < 0)
1463786baecfSMauro Carvalho Chehab 		err("command 0x51 transfer failed.");
1464786baecfSMauro Carvalho Chehab 
1465606142afSJonathan McDowell 	mutex_unlock(&d->data_mutex);
1466606142afSJonathan McDowell 
1467606142afSJonathan McDowell 	adap->fe_adap[0].fe = dvb_attach(ds3000_attach, &su3000_ds3000_config,
1468606142afSJonathan McDowell 					 &d->i2c_adap);
14694a7d7351SMauro Carvalho Chehab 	if (!adap->fe_adap[0].fe)
1470786baecfSMauro Carvalho Chehab 		return -EIO;
1471786baecfSMauro Carvalho Chehab 
1472606142afSJonathan McDowell 	if (dvb_attach(ts2020_attach, adap->fe_adap[0].fe,
1473b858c331SIgor M. Liplianin 		       &dw2104_ts2020_config,
1474606142afSJonathan McDowell 				&d->i2c_adap)) {
14750385443fSJonathan McDowell 		info("Attached DS3000/TS2020!");
1476786baecfSMauro Carvalho Chehab 		return 0;
1477786baecfSMauro Carvalho Chehab 	}
1478786baecfSMauro Carvalho Chehab 
14790385443fSJonathan McDowell 	info("Failed to attach DS3000/TS2020!");
1480b858c331SIgor M. Liplianin 	return -EIO;
1481b858c331SIgor M. Liplianin }
1482b858c331SIgor M. Liplianin 
t220_frontend_attach(struct dvb_usb_adapter * adap)1483606142afSJonathan McDowell static int t220_frontend_attach(struct dvb_usb_adapter *adap)
148451d882edSEvgeny Plehov {
1485606142afSJonathan McDowell 	struct dvb_usb_device *d = adap->dev;
1486606142afSJonathan McDowell 	struct dw2102_state *state = d->priv;
148751d882edSEvgeny Plehov 
1488606142afSJonathan McDowell 	mutex_lock(&d->data_mutex);
1489606142afSJonathan McDowell 
1490606142afSJonathan McDowell 	state->data[0] = 0xe;
1491606142afSJonathan McDowell 	state->data[1] = 0x87;
1492606142afSJonathan McDowell 	state->data[2] = 0x0;
1493606142afSJonathan McDowell 
1494606142afSJonathan McDowell 	if (dvb_usb_generic_rw(d, state->data, 3, state->data, 1, 0) < 0)
149551d882edSEvgeny Plehov 		err("command 0x0e transfer failed.");
149651d882edSEvgeny Plehov 
1497606142afSJonathan McDowell 	state->data[0] = 0xe;
1498606142afSJonathan McDowell 	state->data[1] = 0x86;
1499606142afSJonathan McDowell 	state->data[2] = 1;
15007b71ef7eSCrazyCat 
1501606142afSJonathan McDowell 	if (dvb_usb_generic_rw(d, state->data, 3, state->data, 1, 0) < 0)
15027b71ef7eSCrazyCat 		err("command 0x0e transfer failed.");
15037b71ef7eSCrazyCat 
1504606142afSJonathan McDowell 	state->data[0] = 0xe;
1505606142afSJonathan McDowell 	state->data[1] = 0x80;
1506606142afSJonathan McDowell 	state->data[2] = 0;
150751d882edSEvgeny Plehov 
1508606142afSJonathan McDowell 	if (dvb_usb_generic_rw(d, state->data, 3, state->data, 1, 0) < 0)
150951d882edSEvgeny Plehov 		err("command 0x0e transfer failed.");
151051d882edSEvgeny Plehov 
15117b71ef7eSCrazyCat 	msleep(50);
151251d882edSEvgeny Plehov 
1513606142afSJonathan McDowell 	state->data[0] = 0xe;
1514606142afSJonathan McDowell 	state->data[1] = 0x80;
1515606142afSJonathan McDowell 	state->data[2] = 1;
151651d882edSEvgeny Plehov 
1517606142afSJonathan McDowell 	if (dvb_usb_generic_rw(d, state->data, 3, state->data, 1, 0) < 0)
151851d882edSEvgeny Plehov 		err("command 0x0e transfer failed.");
151951d882edSEvgeny Plehov 
1520606142afSJonathan McDowell 	state->data[0] = 0x51;
152151d882edSEvgeny Plehov 
1522606142afSJonathan McDowell 	if (dvb_usb_generic_rw(d, state->data, 1, state->data, 1, 0) < 0)
152351d882edSEvgeny Plehov 		err("command 0x51 transfer failed.");
152451d882edSEvgeny Plehov 
1525606142afSJonathan McDowell 	mutex_unlock(&d->data_mutex);
1526606142afSJonathan McDowell 
1527606142afSJonathan McDowell 	adap->fe_adap[0].fe = dvb_attach(cxd2820r_attach, &cxd2820r_config,
1528606142afSJonathan McDowell 					 &d->i2c_adap, NULL);
15294a7d7351SMauro Carvalho Chehab 	if (adap->fe_adap[0].fe) {
1530606142afSJonathan McDowell 		if (dvb_attach(tda18271_attach, adap->fe_adap[0].fe, 0x60,
1531606142afSJonathan McDowell 			       &d->i2c_adap, &tda18271_config)) {
15320385443fSJonathan McDowell 			info("Attached TDA18271HD/CXD2820R!");
153351d882edSEvgeny Plehov 			return 0;
153451d882edSEvgeny Plehov 		}
153551d882edSEvgeny Plehov 	}
153651d882edSEvgeny Plehov 
15370385443fSJonathan McDowell 	info("Failed to attach TDA18271HD/CXD2820R!");
153851d882edSEvgeny Plehov 	return -EIO;
153951d882edSEvgeny Plehov }
154051d882edSEvgeny Plehov 
m88rs2000_frontend_attach(struct dvb_usb_adapter * adap)1541606142afSJonathan McDowell static int m88rs2000_frontend_attach(struct dvb_usb_adapter *adap)
1542955d00acSIgor M. Liplianin {
1543606142afSJonathan McDowell 	struct dvb_usb_device *d = adap->dev;
1544606142afSJonathan McDowell 	struct dw2102_state *state = d->priv;
1545955d00acSIgor M. Liplianin 
1546606142afSJonathan McDowell 	mutex_lock(&d->data_mutex);
1547606142afSJonathan McDowell 
1548606142afSJonathan McDowell 	state->data[0] = 0x51;
1549606142afSJonathan McDowell 
1550606142afSJonathan McDowell 	if (dvb_usb_generic_rw(d, state->data, 1, state->data, 1, 0) < 0)
1551955d00acSIgor M. Liplianin 		err("command 0x51 transfer failed.");
1552955d00acSIgor M. Liplianin 
1553606142afSJonathan McDowell 	mutex_unlock(&d->data_mutex);
1554b858c331SIgor M. Liplianin 
1555606142afSJonathan McDowell 	adap->fe_adap[0].fe = dvb_attach(m88rs2000_attach,
1556606142afSJonathan McDowell 					 &s421_m88rs2000_config,
1557606142afSJonathan McDowell 					 &d->i2c_adap);
1558606142afSJonathan McDowell 
15594a7d7351SMauro Carvalho Chehab 	if (!adap->fe_adap[0].fe)
1560955d00acSIgor M. Liplianin 		return -EIO;
1561955d00acSIgor M. Liplianin 
1562606142afSJonathan McDowell 	if (dvb_attach(ts2020_attach, adap->fe_adap[0].fe,
1563b858c331SIgor M. Liplianin 		       &dw2104_ts2020_config,
1564606142afSJonathan McDowell 				&d->i2c_adap)) {
15650385443fSJonathan McDowell 		info("Attached RS2000/TS2020!");
1566955d00acSIgor M. Liplianin 		return 0;
1567955d00acSIgor M. Liplianin 	}
1568955d00acSIgor M. Liplianin 
15690385443fSJonathan McDowell 	info("Failed to attach RS2000/TS2020!");
1570b858c331SIgor M. Liplianin 	return -EIO;
1571b858c331SIgor M. Liplianin }
1572b858c331SIgor M. Liplianin 
tt_s2_4600_frontend_attach_probe_demod(struct dvb_usb_device * d,const int probe_addr)1573889968a4SBrad Love static int tt_s2_4600_frontend_attach_probe_demod(struct dvb_usb_device *d,
1574889968a4SBrad Love 						  const int probe_addr)
1575889968a4SBrad Love {
1576889968a4SBrad Love 	struct dw2102_state *state = d->priv;
1577889968a4SBrad Love 
1578889968a4SBrad Love 	state->data[0] = 0x9;
1579889968a4SBrad Love 	state->data[1] = 0x1;
1580889968a4SBrad Love 	state->data[2] = 0x1;
1581889968a4SBrad Love 	state->data[3] = probe_addr;
1582889968a4SBrad Love 	state->data[4] = 0x0;
1583889968a4SBrad Love 
1584889968a4SBrad Love 	if (dvb_usb_generic_rw(d, state->data, 5, state->data, 2, 0) < 0) {
1585889968a4SBrad Love 		err("i2c probe for address 0x%x failed.", probe_addr);
1586889968a4SBrad Love 		return 0;
1587889968a4SBrad Love 	}
1588889968a4SBrad Love 
1589889968a4SBrad Love 	if (state->data[0] != 8) /* fail(7) or error, no device at address */
1590889968a4SBrad Love 		return 0;
1591889968a4SBrad Love 
1592889968a4SBrad Love 	/* probing successful */
1593889968a4SBrad Love 	return 1;
1594889968a4SBrad Love }
1595889968a4SBrad Love 
tt_s2_4600_frontend_attach(struct dvb_usb_adapter * adap)159627254c36SOlli Salonen static int tt_s2_4600_frontend_attach(struct dvb_usb_adapter *adap)
159727254c36SOlli Salonen {
159827254c36SOlli Salonen 	struct dvb_usb_device *d = adap->dev;
159927254c36SOlli Salonen 	struct dw2102_state *state = d->priv;
160027254c36SOlli Salonen 	struct i2c_adapter *i2c_adapter;
160127254c36SOlli Salonen 	struct i2c_client *client;
1602f3c6abcaSOlli Salonen 	struct i2c_board_info board_info;
1603f3c6abcaSOlli Salonen 	struct m88ds3103_platform_data m88ds3103_pdata = {};
16040fecb6c0SAntti Palosaari 	struct ts2020_config ts2020_config = {};
1605889968a4SBrad Love 	int demod_addr;
160627254c36SOlli Salonen 
1607606142afSJonathan McDowell 	mutex_lock(&d->data_mutex);
1608606142afSJonathan McDowell 
1609606142afSJonathan McDowell 	state->data[0] = 0xe;
1610606142afSJonathan McDowell 	state->data[1] = 0x80;
1611606142afSJonathan McDowell 	state->data[2] = 0x0;
1612606142afSJonathan McDowell 
1613606142afSJonathan McDowell 	if (dvb_usb_generic_rw(d, state->data, 3, state->data, 1, 0) < 0)
161427254c36SOlli Salonen 		err("command 0x0e transfer failed.");
161527254c36SOlli Salonen 
1616606142afSJonathan McDowell 	state->data[0] = 0xe;
1617606142afSJonathan McDowell 	state->data[1] = 0x02;
1618606142afSJonathan McDowell 	state->data[2] = 1;
161927254c36SOlli Salonen 
1620606142afSJonathan McDowell 	if (dvb_usb_generic_rw(d, state->data, 3, state->data, 1, 0) < 0)
162127254c36SOlli Salonen 		err("command 0x0e transfer failed.");
162227254c36SOlli Salonen 	msleep(300);
162327254c36SOlli Salonen 
1624606142afSJonathan McDowell 	state->data[0] = 0xe;
1625606142afSJonathan McDowell 	state->data[1] = 0x83;
1626606142afSJonathan McDowell 	state->data[2] = 0;
162727254c36SOlli Salonen 
1628606142afSJonathan McDowell 	if (dvb_usb_generic_rw(d, state->data, 3, state->data, 1, 0) < 0)
162927254c36SOlli Salonen 		err("command 0x0e transfer failed.");
163027254c36SOlli Salonen 
1631606142afSJonathan McDowell 	state->data[0] = 0xe;
1632606142afSJonathan McDowell 	state->data[1] = 0x83;
1633606142afSJonathan McDowell 	state->data[2] = 1;
163427254c36SOlli Salonen 
1635606142afSJonathan McDowell 	if (dvb_usb_generic_rw(d, state->data, 3, state->data, 1, 0) < 0)
163627254c36SOlli Salonen 		err("command 0x0e transfer failed.");
163727254c36SOlli Salonen 
1638606142afSJonathan McDowell 	state->data[0] = 0x51;
163927254c36SOlli Salonen 
1640606142afSJonathan McDowell 	if (dvb_usb_generic_rw(d, state->data, 1, state->data, 1, 0) < 0)
164127254c36SOlli Salonen 		err("command 0x51 transfer failed.");
164227254c36SOlli Salonen 
1643889968a4SBrad Love 	/* probe for demodulator i2c address */
1644889968a4SBrad Love 	demod_addr = -1;
1645889968a4SBrad Love 	if (tt_s2_4600_frontend_attach_probe_demod(d, 0x68))
1646889968a4SBrad Love 		demod_addr = 0x68;
1647889968a4SBrad Love 	else if (tt_s2_4600_frontend_attach_probe_demod(d, 0x69))
1648889968a4SBrad Love 		demod_addr = 0x69;
1649889968a4SBrad Love 	else if (tt_s2_4600_frontend_attach_probe_demod(d, 0x6a))
1650889968a4SBrad Love 		demod_addr = 0x6a;
1651889968a4SBrad Love 
1652606142afSJonathan McDowell 	mutex_unlock(&d->data_mutex);
1653606142afSJonathan McDowell 
1654889968a4SBrad Love 	if (demod_addr < 0) {
1655889968a4SBrad Love 		err("probing for demodulator failed. Is the external power switched on?");
1656889968a4SBrad Love 		return -ENODEV;
1657889968a4SBrad Love 	}
1658889968a4SBrad Love 
1659f3c6abcaSOlli Salonen 	/* attach demod */
1660f3c6abcaSOlli Salonen 	m88ds3103_pdata.clk = 27000000;
1661f3c6abcaSOlli Salonen 	m88ds3103_pdata.i2c_wr_max = 33;
1662f3c6abcaSOlli Salonen 	m88ds3103_pdata.ts_mode = M88DS3103_TS_CI;
1663f3c6abcaSOlli Salonen 	m88ds3103_pdata.ts_clk = 16000;
1664f3c6abcaSOlli Salonen 	m88ds3103_pdata.ts_clk_pol = 0;
1665f3c6abcaSOlli Salonen 	m88ds3103_pdata.spec_inv = 0;
1666f3c6abcaSOlli Salonen 	m88ds3103_pdata.agc = 0x99;
1667f3c6abcaSOlli Salonen 	m88ds3103_pdata.agc_inv = 0;
1668f3c6abcaSOlli Salonen 	m88ds3103_pdata.clk_out = M88DS3103_CLOCK_OUT_ENABLED;
1669f3c6abcaSOlli Salonen 	m88ds3103_pdata.envelope_mode = 0;
1670f3c6abcaSOlli Salonen 	m88ds3103_pdata.lnb_hv_pol = 1;
1671f3c6abcaSOlli Salonen 	m88ds3103_pdata.lnb_en_pol = 0;
1672f3c6abcaSOlli Salonen 	memset(&board_info, 0, sizeof(board_info));
1673889968a4SBrad Love 	if (demod_addr == 0x6a)
1674889968a4SBrad Love 		strscpy(board_info.type, "m88ds3103b", I2C_NAME_SIZE);
1675889968a4SBrad Love 	else
1676c0decac1SMauro Carvalho Chehab 		strscpy(board_info.type, "m88ds3103", I2C_NAME_SIZE);
1677889968a4SBrad Love 	board_info.addr = demod_addr;
1678f3c6abcaSOlli Salonen 	board_info.platform_data = &m88ds3103_pdata;
1679f3c6abcaSOlli Salonen 	request_module("m88ds3103");
1680334f6aafSWolfram Sang 	client = i2c_new_client_device(&d->i2c_adap, &board_info);
1681334f6aafSWolfram Sang 	if (!i2c_client_has_driver(client))
168227254c36SOlli Salonen 		return -ENODEV;
1683f3c6abcaSOlli Salonen 	if (!try_module_get(client->dev.driver->owner)) {
1684f3c6abcaSOlli Salonen 		i2c_unregister_device(client);
1685f3c6abcaSOlli Salonen 		return -ENODEV;
1686f3c6abcaSOlli Salonen 	}
1687f3c6abcaSOlli Salonen 	adap->fe_adap[0].fe = m88ds3103_pdata.get_dvb_frontend(client);
1688f3c6abcaSOlli Salonen 	i2c_adapter = m88ds3103_pdata.get_i2c_adapter(client);
1689f3c6abcaSOlli Salonen 
1690f3c6abcaSOlli Salonen 	state->i2c_client_demod = client;
169127254c36SOlli Salonen 
169227254c36SOlli Salonen 	/* attach tuner */
16930fecb6c0SAntti Palosaari 	ts2020_config.fe = adap->fe_adap[0].fe;
1694f3c6abcaSOlli Salonen 	memset(&board_info, 0, sizeof(board_info));
1695c0decac1SMauro Carvalho Chehab 	strscpy(board_info.type, "ts2022", I2C_NAME_SIZE);
1696f3c6abcaSOlli Salonen 	board_info.addr = 0x60;
1697f3c6abcaSOlli Salonen 	board_info.platform_data = &ts2020_config;
16980fecb6c0SAntti Palosaari 	request_module("ts2020");
1699334f6aafSWolfram Sang 	client = i2c_new_client_device(i2c_adapter, &board_info);
170027254c36SOlli Salonen 
1701334f6aafSWolfram Sang 	if (!i2c_client_has_driver(client)) {
170227254c36SOlli Salonen 		dvb_frontend_detach(adap->fe_adap[0].fe);
170327254c36SOlli Salonen 		return -ENODEV;
170427254c36SOlli Salonen 	}
170527254c36SOlli Salonen 
170627254c36SOlli Salonen 	if (!try_module_get(client->dev.driver->owner)) {
170727254c36SOlli Salonen 		i2c_unregister_device(client);
170827254c36SOlli Salonen 		dvb_frontend_detach(adap->fe_adap[0].fe);
170927254c36SOlli Salonen 		return -ENODEV;
171027254c36SOlli Salonen 	}
171127254c36SOlli Salonen 
171227254c36SOlli Salonen 	/* delegate signal strength measurement to tuner */
171327254c36SOlli Salonen 	adap->fe_adap[0].fe->ops.read_signal_strength =
171427254c36SOlli Salonen 			adap->fe_adap[0].fe->ops.tuner_ops.get_rf_strength;
171527254c36SOlli Salonen 
171627254c36SOlli Salonen 	state->i2c_client_tuner = client;
171727254c36SOlli Salonen 
1718356484caSOlli Salonen 	/* hook fe: need to resync the slave fifo when signal locks */
1719356484caSOlli Salonen 	state->fe_read_status = adap->fe_adap[0].fe->ops.read_status;
1720356484caSOlli Salonen 	adap->fe_adap[0].fe->ops.read_status = tt_s2_4600_read_status;
1721356484caSOlli Salonen 
1722356484caSOlli Salonen 	state->last_lock = 0;
1723356484caSOlli Salonen 
172427254c36SOlli Salonen 	return 0;
172527254c36SOlli Salonen }
172627254c36SOlli Salonen 
dw2102_tuner_attach(struct dvb_usb_adapter * adap)1727786baecfSMauro Carvalho Chehab static int dw2102_tuner_attach(struct dvb_usb_adapter *adap)
1728786baecfSMauro Carvalho Chehab {
1729786baecfSMauro Carvalho Chehab 	dvb_attach(dvb_pll_attach, adap->fe_adap[0].fe, 0x60,
1730786baecfSMauro Carvalho Chehab 		   &adap->dev->i2c_adap, DVB_PLL_OPERA1);
1731786baecfSMauro Carvalho Chehab 	return 0;
1732786baecfSMauro Carvalho Chehab }
1733786baecfSMauro Carvalho Chehab 
dw3101_tuner_attach(struct dvb_usb_adapter * adap)1734786baecfSMauro Carvalho Chehab static int dw3101_tuner_attach(struct dvb_usb_adapter *adap)
1735786baecfSMauro Carvalho Chehab {
1736786baecfSMauro Carvalho Chehab 	dvb_attach(dvb_pll_attach, adap->fe_adap[0].fe, 0x60,
1737786baecfSMauro Carvalho Chehab 		   &adap->dev->i2c_adap, DVB_PLL_TUA6034);
1738786baecfSMauro Carvalho Chehab 
1739786baecfSMauro Carvalho Chehab 	return 0;
1740786baecfSMauro Carvalho Chehab }
1741786baecfSMauro Carvalho Chehab 
dw2102_rc_query(struct dvb_usb_device * d)1742a49de26aSEvgeny Plehov static int dw2102_rc_query(struct dvb_usb_device *d)
1743786baecfSMauro Carvalho Chehab {
1744786baecfSMauro Carvalho Chehab 	u8 key[2];
1745786baecfSMauro Carvalho Chehab 	struct i2c_msg msg = {
1746786baecfSMauro Carvalho Chehab 		.addr = DW2102_RC_QUERY,
1747786baecfSMauro Carvalho Chehab 		.flags = I2C_M_RD,
1748786baecfSMauro Carvalho Chehab 		.buf = key,
1749786baecfSMauro Carvalho Chehab 		.len = 2
1750786baecfSMauro Carvalho Chehab 	};
1751786baecfSMauro Carvalho Chehab 
1752786baecfSMauro Carvalho Chehab 	if (d->props.i2c_algo->master_xfer(&d->i2c_adap, &msg, 1) == 1) {
1753a49de26aSEvgeny Plehov 		if (msg.buf[0] != 0xff) {
1754a49de26aSEvgeny Plehov 			deb_rc("%s: rc code: %x, %x\n",
1755786baecfSMauro Carvalho Chehab 			       __func__, key[0], key[1]);
17566d741bfeSSean Young 			rc_keydown(d->rc_dev, RC_PROTO_UNKNOWN, key[0], 0);
1757a49de26aSEvgeny Plehov 		}
1758a49de26aSEvgeny Plehov 	}
1759786baecfSMauro Carvalho Chehab 
1760a49de26aSEvgeny Plehov 	return 0;
1761a49de26aSEvgeny Plehov }
1762a49de26aSEvgeny Plehov 
prof_rc_query(struct dvb_usb_device * d)1763a49de26aSEvgeny Plehov static int prof_rc_query(struct dvb_usb_device *d)
1764a49de26aSEvgeny Plehov {
1765a49de26aSEvgeny Plehov 	u8 key[2];
1766a49de26aSEvgeny Plehov 	struct i2c_msg msg = {
1767a49de26aSEvgeny Plehov 		.addr = DW2102_RC_QUERY,
1768a49de26aSEvgeny Plehov 		.flags = I2C_M_RD,
1769a49de26aSEvgeny Plehov 		.buf = key,
1770a49de26aSEvgeny Plehov 		.len = 2
1771a49de26aSEvgeny Plehov 	};
1772a49de26aSEvgeny Plehov 
1773a49de26aSEvgeny Plehov 	if (d->props.i2c_algo->master_xfer(&d->i2c_adap, &msg, 1) == 1) {
1774a49de26aSEvgeny Plehov 		if (msg.buf[0] != 0xff) {
1775a49de26aSEvgeny Plehov 			deb_rc("%s: rc code: %x, %x\n",
1776a49de26aSEvgeny Plehov 			       __func__, key[0], key[1]);
17776d741bfeSSean Young 			rc_keydown(d->rc_dev, RC_PROTO_UNKNOWN, key[0] ^ 0xff,
17786d741bfeSSean Young 				   0);
1779a49de26aSEvgeny Plehov 		}
1780a49de26aSEvgeny Plehov 	}
1781a49de26aSEvgeny Plehov 
1782a49de26aSEvgeny Plehov 	return 0;
1783a49de26aSEvgeny Plehov }
1784a49de26aSEvgeny Plehov 
su3000_rc_query(struct dvb_usb_device * d)1785a49de26aSEvgeny Plehov static int su3000_rc_query(struct dvb_usb_device *d)
1786a49de26aSEvgeny Plehov {
1787a49de26aSEvgeny Plehov 	u8 key[2];
1788a49de26aSEvgeny Plehov 	struct i2c_msg msg = {
1789a49de26aSEvgeny Plehov 		.addr = DW2102_RC_QUERY,
1790a49de26aSEvgeny Plehov 		.flags = I2C_M_RD,
1791a49de26aSEvgeny Plehov 		.buf = key,
1792a49de26aSEvgeny Plehov 		.len = 2
1793a49de26aSEvgeny Plehov 	};
1794a49de26aSEvgeny Plehov 
1795a49de26aSEvgeny Plehov 	if (d->props.i2c_algo->master_xfer(&d->i2c_adap, &msg, 1) == 1) {
1796a49de26aSEvgeny Plehov 		if (msg.buf[0] != 0xff) {
1797a49de26aSEvgeny Plehov 			deb_rc("%s: rc code: %x, %x\n",
1798a49de26aSEvgeny Plehov 			       __func__, key[0], key[1]);
17996d741bfeSSean Young 			rc_keydown(d->rc_dev, RC_PROTO_RC5,
1800120703f9SDavid Härdeman 				   RC_SCANCODE_RC5(key[1], key[0]), 0);
1801a49de26aSEvgeny Plehov 		}
1802786baecfSMauro Carvalho Chehab 	}
1803786baecfSMauro Carvalho Chehab 
1804786baecfSMauro Carvalho Chehab 	return 0;
1805786baecfSMauro Carvalho Chehab }
1806786baecfSMauro Carvalho Chehab 
1807786baecfSMauro Carvalho Chehab enum dw2102_table_entry {
1808786baecfSMauro Carvalho Chehab 	CYPRESS_DW2102,
1809786baecfSMauro Carvalho Chehab 	CYPRESS_DW2101,
1810786baecfSMauro Carvalho Chehab 	CYPRESS_DW2104,
1811786baecfSMauro Carvalho Chehab 	TEVII_S650,
1812786baecfSMauro Carvalho Chehab 	TERRATEC_CINERGY_S,
1813786baecfSMauro Carvalho Chehab 	CYPRESS_DW3101,
1814786baecfSMauro Carvalho Chehab 	TEVII_S630,
1815786baecfSMauro Carvalho Chehab 	PROF_1100,
1816786baecfSMauro Carvalho Chehab 	TEVII_S660,
1817786baecfSMauro Carvalho Chehab 	PROF_7500,
1818786baecfSMauro Carvalho Chehab 	GENIATECH_SU3000,
18199cd4bcfbSKai Muenz 	HAUPPAUGE_MAX_S2,
18202fa2002fSMauro Carvalho Chehab 	TERRATEC_CINERGY_S2_R1,
1821786baecfSMauro Carvalho Chehab 	TEVII_S480_1,
1822786baecfSMauro Carvalho Chehab 	TEVII_S480_2,
18232fa2002fSMauro Carvalho Chehab 	GENIATECH_X3M_SPC1400HD,
1824955d00acSIgor M. Liplianin 	TEVII_S421,
1825955d00acSIgor M. Liplianin 	TEVII_S632,
182644122dd6SIgor M. Liplianin 	TERRATEC_CINERGY_S2_R2,
182749438d97SOlli Salonen 	TERRATEC_CINERGY_S2_R3,
182869fd825cSEnrico Mioso 	TERRATEC_CINERGY_S2_R4,
1829528b1a1aSDirk Nehring 	TERRATEC_CINERGY_S2_1,
1830528b1a1aSDirk Nehring 	TERRATEC_CINERGY_S2_2,
1831f08e9f0dSAndrey Pavlenko 	GOTVIEW_SAT_HD,
183251d882edSEvgeny Plehov 	GENIATECH_T220,
18332fa2002fSMauro Carvalho Chehab 	TECHNOTREND_CONNECT_S2_4600,
183444767fc4SOlli Salonen 	TEVII_S482_1,
183544767fc4SOlli Salonen 	TEVII_S482_2,
18366ede20f9SOlli Salonen 	TEVII_S662
1837786baecfSMauro Carvalho Chehab };
1838786baecfSMauro Carvalho Chehab 
1839786baecfSMauro Carvalho Chehab static struct usb_device_id dw2102_table[] = {
18402fa2002fSMauro Carvalho Chehab 	DVB_USB_DEV(CYPRESS, CYPRESS_DW2102),
18412fa2002fSMauro Carvalho Chehab 	DVB_USB_DEV(CYPRESS, CYPRESS_DW2101),
18422fa2002fSMauro Carvalho Chehab 	DVB_USB_DEV(CYPRESS, CYPRESS_DW2104),
18432fa2002fSMauro Carvalho Chehab 	DVB_USB_DEV(TEVII, TEVII_S650),
18442fa2002fSMauro Carvalho Chehab 	DVB_USB_DEV(TERRATEC, TERRATEC_CINERGY_S),
18452fa2002fSMauro Carvalho Chehab 	DVB_USB_DEV(CYPRESS, CYPRESS_DW3101),
18462fa2002fSMauro Carvalho Chehab 	DVB_USB_DEV(TEVII, TEVII_S630),
18472fa2002fSMauro Carvalho Chehab 	DVB_USB_DEV(PROF_1, PROF_1100),
18482fa2002fSMauro Carvalho Chehab 	DVB_USB_DEV(TEVII, TEVII_S660),
18492fa2002fSMauro Carvalho Chehab 	DVB_USB_DEV(PROF_2, PROF_7500),
18502fa2002fSMauro Carvalho Chehab 	DVB_USB_DEV(GTEK, GENIATECH_SU3000),
18512fa2002fSMauro Carvalho Chehab 	DVB_USB_DEV(HAUPPAUGE, HAUPPAUGE_MAX_S2),
18522fa2002fSMauro Carvalho Chehab 	DVB_USB_DEV(TERRATEC, TERRATEC_CINERGY_S2_R1),
18532fa2002fSMauro Carvalho Chehab 	DVB_USB_DEV(TEVII, TEVII_S480_1),
18542fa2002fSMauro Carvalho Chehab 	DVB_USB_DEV(TEVII, TEVII_S480_2),
18552fa2002fSMauro Carvalho Chehab 	DVB_USB_DEV(GTEK, GENIATECH_X3M_SPC1400HD),
18562fa2002fSMauro Carvalho Chehab 	DVB_USB_DEV(TEVII, TEVII_S421),
18572fa2002fSMauro Carvalho Chehab 	DVB_USB_DEV(TEVII, TEVII_S632),
18582fa2002fSMauro Carvalho Chehab 	DVB_USB_DEV(TERRATEC, TERRATEC_CINERGY_S2_R2),
18592fa2002fSMauro Carvalho Chehab 	DVB_USB_DEV(TERRATEC, TERRATEC_CINERGY_S2_R3),
18602fa2002fSMauro Carvalho Chehab 	DVB_USB_DEV(TERRATEC, TERRATEC_CINERGY_S2_R4),
18612fa2002fSMauro Carvalho Chehab 	DVB_USB_DEV(TERRATEC_2, TERRATEC_CINERGY_S2_1),
18622fa2002fSMauro Carvalho Chehab 	DVB_USB_DEV(TERRATEC_2, TERRATEC_CINERGY_S2_2),
18632fa2002fSMauro Carvalho Chehab 	DVB_USB_DEV(GOTVIEW, GOTVIEW_SAT_HD),
18642fa2002fSMauro Carvalho Chehab 	DVB_USB_DEV(GTEK, GENIATECH_T220),
18652fa2002fSMauro Carvalho Chehab 	DVB_USB_DEV(TECHNOTREND, TECHNOTREND_CONNECT_S2_4600),
18662fa2002fSMauro Carvalho Chehab 	DVB_USB_DEV(TEVII, TEVII_S482_1),
18672fa2002fSMauro Carvalho Chehab 	DVB_USB_DEV(TEVII, TEVII_S482_2),
18682fa2002fSMauro Carvalho Chehab 	DVB_USB_DEV(TEVII, TEVII_S662),
1869786baecfSMauro Carvalho Chehab 	{ }
1870786baecfSMauro Carvalho Chehab };
1871786baecfSMauro Carvalho Chehab 
1872786baecfSMauro Carvalho Chehab MODULE_DEVICE_TABLE(usb, dw2102_table);
1873786baecfSMauro Carvalho Chehab 
dw2102_load_firmware(struct usb_device * dev,const struct firmware * frmwr)1874786baecfSMauro Carvalho Chehab static int dw2102_load_firmware(struct usb_device *dev,
1875786baecfSMauro Carvalho Chehab 				const struct firmware *frmwr)
1876786baecfSMauro Carvalho Chehab {
1877786baecfSMauro Carvalho Chehab 	u8 *b, *p;
1878786baecfSMauro Carvalho Chehab 	int ret = 0, i;
1879786baecfSMauro Carvalho Chehab 	u8 reset;
1880786baecfSMauro Carvalho Chehab 	u8 reset16[] = {0, 0, 0, 0, 0, 0, 0};
1881786baecfSMauro Carvalho Chehab 	const struct firmware *fw;
1882786baecfSMauro Carvalho Chehab 
18831ad5d064SHans Verkuil 	switch (le16_to_cpu(dev->descriptor.idProduct)) {
1884786baecfSMauro Carvalho Chehab 	case 0x2101:
18856823627bSRémi Cardona 		ret = request_firmware(&fw, DW2101_FIRMWARE, &dev->dev);
1886786baecfSMauro Carvalho Chehab 		if (ret != 0) {
18876823627bSRémi Cardona 			err(err_str, DW2101_FIRMWARE);
1888786baecfSMauro Carvalho Chehab 			return ret;
1889786baecfSMauro Carvalho Chehab 		}
1890786baecfSMauro Carvalho Chehab 		break;
1891786baecfSMauro Carvalho Chehab 	default:
1892786baecfSMauro Carvalho Chehab 		fw = frmwr;
1893786baecfSMauro Carvalho Chehab 		break;
1894786baecfSMauro Carvalho Chehab 	}
1895786baecfSMauro Carvalho Chehab 	info("start downloading DW210X firmware");
1896786baecfSMauro Carvalho Chehab 	p = kmalloc(fw->size, GFP_KERNEL);
1897786baecfSMauro Carvalho Chehab 	reset = 1;
1898786baecfSMauro Carvalho Chehab 	/*stop the CPU*/
1899786baecfSMauro Carvalho Chehab 	dw210x_op_rw(dev, 0xa0, 0x7f92, 0, &reset, 1, DW210X_WRITE_MSG);
1900786baecfSMauro Carvalho Chehab 	dw210x_op_rw(dev, 0xa0, 0xe600, 0, &reset, 1, DW210X_WRITE_MSG);
1901786baecfSMauro Carvalho Chehab 
19024a7d7351SMauro Carvalho Chehab 	if (p) {
1903786baecfSMauro Carvalho Chehab 		memcpy(p, fw->data, fw->size);
1904786baecfSMauro Carvalho Chehab 		for (i = 0; i < fw->size; i += 0x40) {
1905786baecfSMauro Carvalho Chehab 			b = (u8 *)p + i;
1906786baecfSMauro Carvalho Chehab 			if (dw210x_op_rw(dev, 0xa0, i, 0, b, 0x40,
1907786baecfSMauro Carvalho Chehab 					 DW210X_WRITE_MSG) != 0x40) {
1908786baecfSMauro Carvalho Chehab 				err("error while transferring firmware");
1909786baecfSMauro Carvalho Chehab 				ret = -EINVAL;
1910786baecfSMauro Carvalho Chehab 				break;
1911786baecfSMauro Carvalho Chehab 			}
1912786baecfSMauro Carvalho Chehab 		}
1913786baecfSMauro Carvalho Chehab 		/* restart the CPU */
1914786baecfSMauro Carvalho Chehab 		reset = 0;
1915786baecfSMauro Carvalho Chehab 		if (ret || dw210x_op_rw(dev, 0xa0, 0x7f92, 0, &reset, 1,
1916786baecfSMauro Carvalho Chehab 					DW210X_WRITE_MSG) != 1) {
1917786baecfSMauro Carvalho Chehab 			err("could not restart the USB controller CPU.");
1918786baecfSMauro Carvalho Chehab 			ret = -EINVAL;
1919786baecfSMauro Carvalho Chehab 		}
1920786baecfSMauro Carvalho Chehab 		if (ret || dw210x_op_rw(dev, 0xa0, 0xe600, 0, &reset, 1,
1921786baecfSMauro Carvalho Chehab 					DW210X_WRITE_MSG) != 1) {
1922786baecfSMauro Carvalho Chehab 			err("could not restart the USB controller CPU.");
1923786baecfSMauro Carvalho Chehab 			ret = -EINVAL;
1924786baecfSMauro Carvalho Chehab 		}
1925786baecfSMauro Carvalho Chehab 		/* init registers */
19261ad5d064SHans Verkuil 		switch (le16_to_cpu(dev->descriptor.idProduct)) {
1927786baecfSMauro Carvalho Chehab 		case USB_PID_TEVII_S650:
1928a49de26aSEvgeny Plehov 			dw2104_properties.rc.core.rc_codes = RC_MAP_TEVII_NEC;
1929df561f66SGustavo A. R. Silva 			fallthrough;
19302fa2002fSMauro Carvalho Chehab 		case USB_PID_CYPRESS_DW2104:
1931786baecfSMauro Carvalho Chehab 			reset = 1;
1932786baecfSMauro Carvalho Chehab 			dw210x_op_rw(dev, 0xc4, 0x0000, 0, &reset, 1,
1933786baecfSMauro Carvalho Chehab 				     DW210X_WRITE_MSG);
1934df561f66SGustavo A. R. Silva 			fallthrough;
19352fa2002fSMauro Carvalho Chehab 		case USB_PID_CYPRESS_DW3101:
1936786baecfSMauro Carvalho Chehab 			reset = 0;
1937786baecfSMauro Carvalho Chehab 			dw210x_op_rw(dev, 0xbf, 0x0040, 0, &reset, 0,
1938786baecfSMauro Carvalho Chehab 				     DW210X_WRITE_MSG);
1939786baecfSMauro Carvalho Chehab 			break;
1940e8364275SMauro Carvalho Chehab 		case USB_PID_TERRATEC_CINERGY_S:
19412fa2002fSMauro Carvalho Chehab 		case USB_PID_CYPRESS_DW2102:
1942786baecfSMauro Carvalho Chehab 			dw210x_op_rw(dev, 0xbf, 0x0040, 0, &reset, 0,
1943786baecfSMauro Carvalho Chehab 				     DW210X_WRITE_MSG);
1944786baecfSMauro Carvalho Chehab 			dw210x_op_rw(dev, 0xb9, 0x0000, 0, &reset16[0], 2,
1945786baecfSMauro Carvalho Chehab 				     DW210X_READ_MSG);
1946786baecfSMauro Carvalho Chehab 			/* check STV0299 frontend  */
1947786baecfSMauro Carvalho Chehab 			dw210x_op_rw(dev, 0xb5, 0, 0, &reset16[0], 2,
1948786baecfSMauro Carvalho Chehab 				     DW210X_READ_MSG);
1949786baecfSMauro Carvalho Chehab 			if ((reset16[0] == 0xa1) || (reset16[0] == 0x80)) {
1950786baecfSMauro Carvalho Chehab 				dw2102_properties.i2c_algo = &dw2102_i2c_algo;
1951786baecfSMauro Carvalho Chehab 				dw2102_properties.adapter->fe[0].tuner_attach = &dw2102_tuner_attach;
1952786baecfSMauro Carvalho Chehab 				break;
1953efc3e49dSMichael Bunk 			}
1954786baecfSMauro Carvalho Chehab 			/* check STV0288 frontend  */
1955786baecfSMauro Carvalho Chehab 			reset16[0] = 0xd0;
1956786baecfSMauro Carvalho Chehab 			reset16[1] = 1;
1957786baecfSMauro Carvalho Chehab 			reset16[2] = 0;
1958786baecfSMauro Carvalho Chehab 			dw210x_op_rw(dev, 0xc2, 0, 0, &reset16[0], 3,
1959786baecfSMauro Carvalho Chehab 				     DW210X_WRITE_MSG);
1960786baecfSMauro Carvalho Chehab 			dw210x_op_rw(dev, 0xc3, 0xd1, 0, &reset16[0], 3,
1961786baecfSMauro Carvalho Chehab 				     DW210X_READ_MSG);
1962786baecfSMauro Carvalho Chehab 			if (reset16[2] == 0x11) {
1963786baecfSMauro Carvalho Chehab 				dw2102_properties.i2c_algo = &dw2102_earda_i2c_algo;
1964786baecfSMauro Carvalho Chehab 				break;
1965786baecfSMauro Carvalho Chehab 			}
1966df561f66SGustavo A. R. Silva 			fallthrough;
1967786baecfSMauro Carvalho Chehab 		case 0x2101:
1968786baecfSMauro Carvalho Chehab 			dw210x_op_rw(dev, 0xbc, 0x0030, 0, &reset16[0], 2,
1969786baecfSMauro Carvalho Chehab 				     DW210X_READ_MSG);
1970786baecfSMauro Carvalho Chehab 			dw210x_op_rw(dev, 0xba, 0x0000, 0, &reset16[0], 7,
1971786baecfSMauro Carvalho Chehab 				     DW210X_READ_MSG);
1972786baecfSMauro Carvalho Chehab 			dw210x_op_rw(dev, 0xba, 0x0000, 0, &reset16[0], 7,
1973786baecfSMauro Carvalho Chehab 				     DW210X_READ_MSG);
1974786baecfSMauro Carvalho Chehab 			dw210x_op_rw(dev, 0xb9, 0x0000, 0, &reset16[0], 2,
1975786baecfSMauro Carvalho Chehab 				     DW210X_READ_MSG);
1976786baecfSMauro Carvalho Chehab 			break;
1977786baecfSMauro Carvalho Chehab 		}
1978786baecfSMauro Carvalho Chehab 
1979786baecfSMauro Carvalho Chehab 		msleep(100);
1980786baecfSMauro Carvalho Chehab 		kfree(p);
1981786baecfSMauro Carvalho Chehab 	}
19822a518f8eSSudip Mukherjee 
19832a518f8eSSudip Mukherjee 	if (le16_to_cpu(dev->descriptor.idProduct) == 0x2101)
19842a518f8eSSudip Mukherjee 		release_firmware(fw);
1985786baecfSMauro Carvalho Chehab 	return ret;
1986786baecfSMauro Carvalho Chehab }
1987786baecfSMauro Carvalho Chehab 
1988786baecfSMauro Carvalho Chehab static struct dvb_usb_device_properties dw2102_properties = {
1989786baecfSMauro Carvalho Chehab 	.caps = DVB_USB_IS_AN_I2C_ADAPTER,
1990786baecfSMauro Carvalho Chehab 	.usb_ctrl = DEVICE_SPECIFIC,
19916823627bSRémi Cardona 	.firmware = DW2102_FIRMWARE,
1992786baecfSMauro Carvalho Chehab 	.no_reconnect = 1,
1993786baecfSMauro Carvalho Chehab 
1994786baecfSMauro Carvalho Chehab 	.i2c_algo = &dw2102_serit_i2c_algo,
1995786baecfSMauro Carvalho Chehab 
1996a49de26aSEvgeny Plehov 	.rc.core = {
1997786baecfSMauro Carvalho Chehab 		.rc_interval = 150,
1998a49de26aSEvgeny Plehov 		.rc_codes = RC_MAP_DM1105_NEC,
1999a49de26aSEvgeny Plehov 		.module_name = "dw2102",
20006d741bfeSSean Young 		.allowed_protos   = RC_PROTO_BIT_NEC,
2001786baecfSMauro Carvalho Chehab 		.rc_query = dw2102_rc_query,
2002786baecfSMauro Carvalho Chehab 	},
2003786baecfSMauro Carvalho Chehab 
2004786baecfSMauro Carvalho Chehab 	.generic_bulk_ctrl_endpoint = 0x81,
2005786baecfSMauro Carvalho Chehab 	/* parameter for the MPEG2-data transfer */
2006786baecfSMauro Carvalho Chehab 	.num_adapters = 1,
2007786baecfSMauro Carvalho Chehab 	.download_firmware = dw2102_load_firmware,
2008786baecfSMauro Carvalho Chehab 	.read_mac_address = dw210x_read_mac_address,
2009786baecfSMauro Carvalho Chehab 	.adapter = {
2010786baecfSMauro Carvalho Chehab 		{
2011786baecfSMauro Carvalho Chehab 		.num_frontends = 1,
2012786baecfSMauro Carvalho Chehab 		.fe = {{
2013786baecfSMauro Carvalho Chehab 			.frontend_attach = dw2102_frontend_attach,
2014786baecfSMauro Carvalho Chehab 			.stream = {
2015786baecfSMauro Carvalho Chehab 				.type = USB_BULK,
2016786baecfSMauro Carvalho Chehab 				.count = 8,
2017786baecfSMauro Carvalho Chehab 				.endpoint = 0x82,
2018786baecfSMauro Carvalho Chehab 				.u = {
2019786baecfSMauro Carvalho Chehab 					.bulk = {
2020786baecfSMauro Carvalho Chehab 						.buffersize = 4096,
2021786baecfSMauro Carvalho Chehab 					}
2022786baecfSMauro Carvalho Chehab 				}
2023786baecfSMauro Carvalho Chehab 			},
2024786baecfSMauro Carvalho Chehab 		}},
2025786baecfSMauro Carvalho Chehab 		}
2026786baecfSMauro Carvalho Chehab 	},
2027786baecfSMauro Carvalho Chehab 	.num_device_descs = 3,
2028786baecfSMauro Carvalho Chehab 	.devices = {
2029786baecfSMauro Carvalho Chehab 		{"DVBWorld DVB-S 2102 USB2.0",
2030786baecfSMauro Carvalho Chehab 			{&dw2102_table[CYPRESS_DW2102], NULL},
2031786baecfSMauro Carvalho Chehab 			{NULL},
2032786baecfSMauro Carvalho Chehab 		},
2033786baecfSMauro Carvalho Chehab 		{"DVBWorld DVB-S 2101 USB2.0",
2034786baecfSMauro Carvalho Chehab 			{&dw2102_table[CYPRESS_DW2101], NULL},
2035786baecfSMauro Carvalho Chehab 			{NULL},
2036786baecfSMauro Carvalho Chehab 		},
2037786baecfSMauro Carvalho Chehab 		{"TerraTec Cinergy S USB",
2038786baecfSMauro Carvalho Chehab 			{&dw2102_table[TERRATEC_CINERGY_S], NULL},
2039786baecfSMauro Carvalho Chehab 			{NULL},
2040786baecfSMauro Carvalho Chehab 		},
2041786baecfSMauro Carvalho Chehab 	}
2042786baecfSMauro Carvalho Chehab };
2043786baecfSMauro Carvalho Chehab 
2044786baecfSMauro Carvalho Chehab static struct dvb_usb_device_properties dw2104_properties = {
2045786baecfSMauro Carvalho Chehab 	.caps = DVB_USB_IS_AN_I2C_ADAPTER,
2046786baecfSMauro Carvalho Chehab 	.usb_ctrl = DEVICE_SPECIFIC,
20476823627bSRémi Cardona 	.firmware = DW2104_FIRMWARE,
2048786baecfSMauro Carvalho Chehab 	.no_reconnect = 1,
2049786baecfSMauro Carvalho Chehab 
2050786baecfSMauro Carvalho Chehab 	.i2c_algo = &dw2104_i2c_algo,
2051a49de26aSEvgeny Plehov 	.rc.core = {
2052786baecfSMauro Carvalho Chehab 		.rc_interval = 150,
2053a49de26aSEvgeny Plehov 		.rc_codes = RC_MAP_DM1105_NEC,
2054a49de26aSEvgeny Plehov 		.module_name = "dw2102",
20556d741bfeSSean Young 		.allowed_protos   = RC_PROTO_BIT_NEC,
2056786baecfSMauro Carvalho Chehab 		.rc_query = dw2102_rc_query,
2057786baecfSMauro Carvalho Chehab 	},
2058786baecfSMauro Carvalho Chehab 
2059786baecfSMauro Carvalho Chehab 	.generic_bulk_ctrl_endpoint = 0x81,
2060786baecfSMauro Carvalho Chehab 	/* parameter for the MPEG2-data transfer */
2061786baecfSMauro Carvalho Chehab 	.num_adapters = 1,
2062786baecfSMauro Carvalho Chehab 	.download_firmware = dw2102_load_firmware,
2063786baecfSMauro Carvalho Chehab 	.read_mac_address = dw210x_read_mac_address,
2064786baecfSMauro Carvalho Chehab 	.adapter = {
2065786baecfSMauro Carvalho Chehab 		{
2066786baecfSMauro Carvalho Chehab 		.num_frontends = 1,
2067786baecfSMauro Carvalho Chehab 		.fe = {{
2068786baecfSMauro Carvalho Chehab 			.frontend_attach = dw2104_frontend_attach,
2069786baecfSMauro Carvalho Chehab 			.stream = {
2070786baecfSMauro Carvalho Chehab 				.type = USB_BULK,
2071786baecfSMauro Carvalho Chehab 				.count = 8,
2072786baecfSMauro Carvalho Chehab 				.endpoint = 0x82,
2073786baecfSMauro Carvalho Chehab 				.u = {
2074786baecfSMauro Carvalho Chehab 					.bulk = {
2075786baecfSMauro Carvalho Chehab 						.buffersize = 4096,
2076786baecfSMauro Carvalho Chehab 					}
2077786baecfSMauro Carvalho Chehab 				}
2078786baecfSMauro Carvalho Chehab 			},
2079786baecfSMauro Carvalho Chehab 		}},
2080786baecfSMauro Carvalho Chehab 		}
2081786baecfSMauro Carvalho Chehab 	},
2082786baecfSMauro Carvalho Chehab 	.num_device_descs = 2,
2083786baecfSMauro Carvalho Chehab 	.devices = {
2084786baecfSMauro Carvalho Chehab 		{ "DVBWorld DW2104 USB2.0",
2085786baecfSMauro Carvalho Chehab 			{&dw2102_table[CYPRESS_DW2104], NULL},
2086786baecfSMauro Carvalho Chehab 			{NULL},
2087786baecfSMauro Carvalho Chehab 		},
2088786baecfSMauro Carvalho Chehab 		{ "TeVii S650 USB2.0",
2089786baecfSMauro Carvalho Chehab 			{&dw2102_table[TEVII_S650], NULL},
2090786baecfSMauro Carvalho Chehab 			{NULL},
2091786baecfSMauro Carvalho Chehab 		},
2092786baecfSMauro Carvalho Chehab 	}
2093786baecfSMauro Carvalho Chehab };
2094786baecfSMauro Carvalho Chehab 
2095786baecfSMauro Carvalho Chehab static struct dvb_usb_device_properties dw3101_properties = {
2096786baecfSMauro Carvalho Chehab 	.caps = DVB_USB_IS_AN_I2C_ADAPTER,
2097786baecfSMauro Carvalho Chehab 	.usb_ctrl = DEVICE_SPECIFIC,
20986823627bSRémi Cardona 	.firmware = DW3101_FIRMWARE,
2099786baecfSMauro Carvalho Chehab 	.no_reconnect = 1,
2100786baecfSMauro Carvalho Chehab 
2101786baecfSMauro Carvalho Chehab 	.i2c_algo = &dw3101_i2c_algo,
2102a49de26aSEvgeny Plehov 	.rc.core = {
2103786baecfSMauro Carvalho Chehab 		.rc_interval = 150,
2104a49de26aSEvgeny Plehov 		.rc_codes = RC_MAP_DM1105_NEC,
2105a49de26aSEvgeny Plehov 		.module_name = "dw2102",
21066d741bfeSSean Young 		.allowed_protos   = RC_PROTO_BIT_NEC,
2107786baecfSMauro Carvalho Chehab 		.rc_query = dw2102_rc_query,
2108786baecfSMauro Carvalho Chehab 	},
2109786baecfSMauro Carvalho Chehab 
2110786baecfSMauro Carvalho Chehab 	.generic_bulk_ctrl_endpoint = 0x81,
2111786baecfSMauro Carvalho Chehab 	/* parameter for the MPEG2-data transfer */
2112786baecfSMauro Carvalho Chehab 	.num_adapters = 1,
2113786baecfSMauro Carvalho Chehab 	.download_firmware = dw2102_load_firmware,
2114786baecfSMauro Carvalho Chehab 	.read_mac_address = dw210x_read_mac_address,
2115786baecfSMauro Carvalho Chehab 	.adapter = {
2116786baecfSMauro Carvalho Chehab 		{
2117786baecfSMauro Carvalho Chehab 		.num_frontends = 1,
2118786baecfSMauro Carvalho Chehab 		.fe = {{
2119786baecfSMauro Carvalho Chehab 			.frontend_attach = dw3101_frontend_attach,
2120786baecfSMauro Carvalho Chehab 			.tuner_attach = dw3101_tuner_attach,
2121786baecfSMauro Carvalho Chehab 			.stream = {
2122786baecfSMauro Carvalho Chehab 				.type = USB_BULK,
2123786baecfSMauro Carvalho Chehab 				.count = 8,
2124786baecfSMauro Carvalho Chehab 				.endpoint = 0x82,
2125786baecfSMauro Carvalho Chehab 				.u = {
2126786baecfSMauro Carvalho Chehab 					.bulk = {
2127786baecfSMauro Carvalho Chehab 						.buffersize = 4096,
2128786baecfSMauro Carvalho Chehab 					}
2129786baecfSMauro Carvalho Chehab 				}
2130786baecfSMauro Carvalho Chehab 			},
2131786baecfSMauro Carvalho Chehab 		}},
2132786baecfSMauro Carvalho Chehab 		}
2133786baecfSMauro Carvalho Chehab 	},
2134786baecfSMauro Carvalho Chehab 	.num_device_descs = 1,
2135786baecfSMauro Carvalho Chehab 	.devices = {
2136786baecfSMauro Carvalho Chehab 		{ "DVBWorld DVB-C 3101 USB2.0",
2137786baecfSMauro Carvalho Chehab 			{&dw2102_table[CYPRESS_DW3101], NULL},
2138786baecfSMauro Carvalho Chehab 			{NULL},
2139786baecfSMauro Carvalho Chehab 		},
2140786baecfSMauro Carvalho Chehab 	}
2141786baecfSMauro Carvalho Chehab };
2142786baecfSMauro Carvalho Chehab 
2143786baecfSMauro Carvalho Chehab static struct dvb_usb_device_properties s6x0_properties = {
2144786baecfSMauro Carvalho Chehab 	.caps = DVB_USB_IS_AN_I2C_ADAPTER,
2145786baecfSMauro Carvalho Chehab 	.usb_ctrl = DEVICE_SPECIFIC,
21462c4ffe27SOlli Salonen 	.size_of_priv = sizeof(struct dw2102_state),
21476823627bSRémi Cardona 	.firmware = S630_FIRMWARE,
2148786baecfSMauro Carvalho Chehab 	.no_reconnect = 1,
2149786baecfSMauro Carvalho Chehab 
2150786baecfSMauro Carvalho Chehab 	.i2c_algo = &s6x0_i2c_algo,
2151a49de26aSEvgeny Plehov 	.rc.core = {
2152786baecfSMauro Carvalho Chehab 		.rc_interval = 150,
2153a49de26aSEvgeny Plehov 		.rc_codes = RC_MAP_TEVII_NEC,
2154a49de26aSEvgeny Plehov 		.module_name = "dw2102",
21556d741bfeSSean Young 		.allowed_protos   = RC_PROTO_BIT_NEC,
2156786baecfSMauro Carvalho Chehab 		.rc_query = dw2102_rc_query,
2157786baecfSMauro Carvalho Chehab 	},
2158786baecfSMauro Carvalho Chehab 
2159786baecfSMauro Carvalho Chehab 	.generic_bulk_ctrl_endpoint = 0x81,
2160786baecfSMauro Carvalho Chehab 	.num_adapters = 1,
2161786baecfSMauro Carvalho Chehab 	.download_firmware = dw2102_load_firmware,
2162786baecfSMauro Carvalho Chehab 	.read_mac_address = s6x0_read_mac_address,
2163786baecfSMauro Carvalho Chehab 	.adapter = {
2164786baecfSMauro Carvalho Chehab 		{
2165786baecfSMauro Carvalho Chehab 		.num_frontends = 1,
2166786baecfSMauro Carvalho Chehab 		.fe = {{
2167786baecfSMauro Carvalho Chehab 			.frontend_attach = zl100313_frontend_attach,
2168786baecfSMauro Carvalho Chehab 			.stream = {
2169786baecfSMauro Carvalho Chehab 				.type = USB_BULK,
2170786baecfSMauro Carvalho Chehab 				.count = 8,
2171786baecfSMauro Carvalho Chehab 				.endpoint = 0x82,
2172786baecfSMauro Carvalho Chehab 				.u = {
2173786baecfSMauro Carvalho Chehab 					.bulk = {
2174786baecfSMauro Carvalho Chehab 						.buffersize = 4096,
2175786baecfSMauro Carvalho Chehab 					}
2176786baecfSMauro Carvalho Chehab 				}
2177786baecfSMauro Carvalho Chehab 			},
2178786baecfSMauro Carvalho Chehab 		}},
2179786baecfSMauro Carvalho Chehab 		}
2180786baecfSMauro Carvalho Chehab 	},
2181786baecfSMauro Carvalho Chehab 	.num_device_descs = 1,
2182786baecfSMauro Carvalho Chehab 	.devices = {
2183786baecfSMauro Carvalho Chehab 		{"TeVii S630 USB",
2184786baecfSMauro Carvalho Chehab 			{&dw2102_table[TEVII_S630], NULL},
2185786baecfSMauro Carvalho Chehab 			{NULL},
2186786baecfSMauro Carvalho Chehab 		},
2187786baecfSMauro Carvalho Chehab 	}
2188786baecfSMauro Carvalho Chehab };
2189786baecfSMauro Carvalho Chehab 
2190589a9f0eSAnton Vasilyev static struct dvb_usb_device_properties p1100_properties = {
2191589a9f0eSAnton Vasilyev 	.caps = DVB_USB_IS_AN_I2C_ADAPTER,
2192589a9f0eSAnton Vasilyev 	.usb_ctrl = DEVICE_SPECIFIC,
2193589a9f0eSAnton Vasilyev 	.size_of_priv = sizeof(struct dw2102_state),
2194589a9f0eSAnton Vasilyev 	.firmware = P1100_FIRMWARE,
2195589a9f0eSAnton Vasilyev 	.no_reconnect = 1,
2196589a9f0eSAnton Vasilyev 
2197589a9f0eSAnton Vasilyev 	.i2c_algo = &s6x0_i2c_algo,
2198589a9f0eSAnton Vasilyev 	.rc.core = {
2199589a9f0eSAnton Vasilyev 		.rc_interval = 150,
2200589a9f0eSAnton Vasilyev 		.rc_codes = RC_MAP_TBS_NEC,
2201589a9f0eSAnton Vasilyev 		.module_name = "dw2102",
2202589a9f0eSAnton Vasilyev 		.allowed_protos   = RC_PROTO_BIT_NEC,
2203589a9f0eSAnton Vasilyev 		.rc_query = prof_rc_query,
2204589a9f0eSAnton Vasilyev 	},
2205589a9f0eSAnton Vasilyev 
2206589a9f0eSAnton Vasilyev 	.generic_bulk_ctrl_endpoint = 0x81,
2207589a9f0eSAnton Vasilyev 	.num_adapters = 1,
2208589a9f0eSAnton Vasilyev 	.download_firmware = dw2102_load_firmware,
2209589a9f0eSAnton Vasilyev 	.read_mac_address = s6x0_read_mac_address,
2210589a9f0eSAnton Vasilyev 	.adapter = {
2211589a9f0eSAnton Vasilyev 		{
2212589a9f0eSAnton Vasilyev 			.num_frontends = 1,
2213589a9f0eSAnton Vasilyev 			.fe = {{
2214589a9f0eSAnton Vasilyev 				.frontend_attach = stv0288_frontend_attach,
2215589a9f0eSAnton Vasilyev 				.stream = {
2216589a9f0eSAnton Vasilyev 					.type = USB_BULK,
2217589a9f0eSAnton Vasilyev 					.count = 8,
2218589a9f0eSAnton Vasilyev 					.endpoint = 0x82,
2219589a9f0eSAnton Vasilyev 					.u = {
2220589a9f0eSAnton Vasilyev 						.bulk = {
2221589a9f0eSAnton Vasilyev 							.buffersize = 4096,
2222589a9f0eSAnton Vasilyev 						}
2223589a9f0eSAnton Vasilyev 					}
2224589a9f0eSAnton Vasilyev 				},
2225589a9f0eSAnton Vasilyev 			} },
2226589a9f0eSAnton Vasilyev 		}
2227589a9f0eSAnton Vasilyev 	},
2228589a9f0eSAnton Vasilyev 	.num_device_descs = 1,
2229589a9f0eSAnton Vasilyev 	.devices = {
2230589a9f0eSAnton Vasilyev 		{"Prof 1100 USB ",
2231786baecfSMauro Carvalho Chehab 			{&dw2102_table[PROF_1100], NULL},
2232786baecfSMauro Carvalho Chehab 			{NULL},
2233589a9f0eSAnton Vasilyev 		},
2234589a9f0eSAnton Vasilyev 	}
2235786baecfSMauro Carvalho Chehab };
2236786baecfSMauro Carvalho Chehab 
2237589a9f0eSAnton Vasilyev static struct dvb_usb_device_properties s660_properties = {
2238589a9f0eSAnton Vasilyev 	.caps = DVB_USB_IS_AN_I2C_ADAPTER,
2239589a9f0eSAnton Vasilyev 	.usb_ctrl = DEVICE_SPECIFIC,
2240589a9f0eSAnton Vasilyev 	.size_of_priv = sizeof(struct dw2102_state),
2241589a9f0eSAnton Vasilyev 	.firmware = S660_FIRMWARE,
2242589a9f0eSAnton Vasilyev 	.no_reconnect = 1,
2243589a9f0eSAnton Vasilyev 
2244589a9f0eSAnton Vasilyev 	.i2c_algo = &s6x0_i2c_algo,
2245589a9f0eSAnton Vasilyev 	.rc.core = {
2246589a9f0eSAnton Vasilyev 		.rc_interval = 150,
2247589a9f0eSAnton Vasilyev 		.rc_codes = RC_MAP_TEVII_NEC,
2248589a9f0eSAnton Vasilyev 		.module_name = "dw2102",
2249589a9f0eSAnton Vasilyev 		.allowed_protos   = RC_PROTO_BIT_NEC,
2250589a9f0eSAnton Vasilyev 		.rc_query = dw2102_rc_query,
2251589a9f0eSAnton Vasilyev 	},
2252589a9f0eSAnton Vasilyev 
2253589a9f0eSAnton Vasilyev 	.generic_bulk_ctrl_endpoint = 0x81,
2254589a9f0eSAnton Vasilyev 	.num_adapters = 1,
2255589a9f0eSAnton Vasilyev 	.download_firmware = dw2102_load_firmware,
2256589a9f0eSAnton Vasilyev 	.read_mac_address = s6x0_read_mac_address,
2257589a9f0eSAnton Vasilyev 	.adapter = {
2258589a9f0eSAnton Vasilyev 		{
2259589a9f0eSAnton Vasilyev 			.num_frontends = 1,
2260589a9f0eSAnton Vasilyev 			.fe = {{
2261589a9f0eSAnton Vasilyev 				.frontend_attach = ds3000_frontend_attach,
2262589a9f0eSAnton Vasilyev 				.stream = {
2263589a9f0eSAnton Vasilyev 					.type = USB_BULK,
2264589a9f0eSAnton Vasilyev 					.count = 8,
2265589a9f0eSAnton Vasilyev 					.endpoint = 0x82,
2266589a9f0eSAnton Vasilyev 					.u = {
2267589a9f0eSAnton Vasilyev 						.bulk = {
2268589a9f0eSAnton Vasilyev 							.buffersize = 4096,
2269589a9f0eSAnton Vasilyev 						}
2270589a9f0eSAnton Vasilyev 					}
2271589a9f0eSAnton Vasilyev 				},
2272589a9f0eSAnton Vasilyev 			} },
2273589a9f0eSAnton Vasilyev 		}
2274589a9f0eSAnton Vasilyev 	},
2275589a9f0eSAnton Vasilyev 	.num_device_descs = 3,
2276589a9f0eSAnton Vasilyev 	.devices = {
2277589a9f0eSAnton Vasilyev 		{"TeVii S660 USB",
2278786baecfSMauro Carvalho Chehab 			{&dw2102_table[TEVII_S660], NULL},
2279786baecfSMauro Carvalho Chehab 			{NULL},
2280589a9f0eSAnton Vasilyev 		},
2281589a9f0eSAnton Vasilyev 		{"TeVii S480.1 USB",
2282786baecfSMauro Carvalho Chehab 			{&dw2102_table[TEVII_S480_1], NULL},
2283786baecfSMauro Carvalho Chehab 			{NULL},
2284589a9f0eSAnton Vasilyev 		},
2285589a9f0eSAnton Vasilyev 		{"TeVii S480.2 USB",
2286786baecfSMauro Carvalho Chehab 			{&dw2102_table[TEVII_S480_2], NULL},
2287786baecfSMauro Carvalho Chehab 			{NULL},
2288589a9f0eSAnton Vasilyev 		},
2289589a9f0eSAnton Vasilyev 	}
2290786baecfSMauro Carvalho Chehab };
2291786baecfSMauro Carvalho Chehab 
2292589a9f0eSAnton Vasilyev static struct dvb_usb_device_properties p7500_properties = {
2293589a9f0eSAnton Vasilyev 	.caps = DVB_USB_IS_AN_I2C_ADAPTER,
2294589a9f0eSAnton Vasilyev 	.usb_ctrl = DEVICE_SPECIFIC,
2295589a9f0eSAnton Vasilyev 	.size_of_priv = sizeof(struct dw2102_state),
2296589a9f0eSAnton Vasilyev 	.firmware = P7500_FIRMWARE,
2297589a9f0eSAnton Vasilyev 	.no_reconnect = 1,
2298589a9f0eSAnton Vasilyev 
2299589a9f0eSAnton Vasilyev 	.i2c_algo = &s6x0_i2c_algo,
2300589a9f0eSAnton Vasilyev 	.rc.core = {
2301589a9f0eSAnton Vasilyev 		.rc_interval = 150,
2302589a9f0eSAnton Vasilyev 		.rc_codes = RC_MAP_TBS_NEC,
2303589a9f0eSAnton Vasilyev 		.module_name = "dw2102",
2304589a9f0eSAnton Vasilyev 		.allowed_protos   = RC_PROTO_BIT_NEC,
2305589a9f0eSAnton Vasilyev 		.rc_query = prof_rc_query,
2306589a9f0eSAnton Vasilyev 	},
2307589a9f0eSAnton Vasilyev 
2308589a9f0eSAnton Vasilyev 	.generic_bulk_ctrl_endpoint = 0x81,
2309589a9f0eSAnton Vasilyev 	.num_adapters = 1,
2310589a9f0eSAnton Vasilyev 	.download_firmware = dw2102_load_firmware,
2311589a9f0eSAnton Vasilyev 	.read_mac_address = s6x0_read_mac_address,
2312589a9f0eSAnton Vasilyev 	.adapter = {
2313589a9f0eSAnton Vasilyev 		{
2314589a9f0eSAnton Vasilyev 			.num_frontends = 1,
2315589a9f0eSAnton Vasilyev 			.fe = {{
2316589a9f0eSAnton Vasilyev 				.frontend_attach = prof_7500_frontend_attach,
2317589a9f0eSAnton Vasilyev 				.stream = {
2318589a9f0eSAnton Vasilyev 					.type = USB_BULK,
2319589a9f0eSAnton Vasilyev 					.count = 8,
2320589a9f0eSAnton Vasilyev 					.endpoint = 0x82,
2321589a9f0eSAnton Vasilyev 					.u = {
2322589a9f0eSAnton Vasilyev 						.bulk = {
2323589a9f0eSAnton Vasilyev 							.buffersize = 4096,
2324589a9f0eSAnton Vasilyev 						}
2325589a9f0eSAnton Vasilyev 					}
2326589a9f0eSAnton Vasilyev 				},
2327589a9f0eSAnton Vasilyev 			} },
2328589a9f0eSAnton Vasilyev 		}
2329589a9f0eSAnton Vasilyev 	},
2330589a9f0eSAnton Vasilyev 	.num_device_descs = 1,
2331589a9f0eSAnton Vasilyev 	.devices = {
2332589a9f0eSAnton Vasilyev 		{"Prof 7500 USB DVB-S2",
2333786baecfSMauro Carvalho Chehab 			{&dw2102_table[PROF_7500], NULL},
2334786baecfSMauro Carvalho Chehab 			{NULL},
2335589a9f0eSAnton Vasilyev 		},
2336589a9f0eSAnton Vasilyev 	}
2337955d00acSIgor M. Liplianin };
2338955d00acSIgor M. Liplianin 
2339786baecfSMauro Carvalho Chehab static struct dvb_usb_device_properties su3000_properties = {
2340786baecfSMauro Carvalho Chehab 	.caps = DVB_USB_IS_AN_I2C_ADAPTER,
2341786baecfSMauro Carvalho Chehab 	.usb_ctrl = DEVICE_SPECIFIC,
23422c4ffe27SOlli Salonen 	.size_of_priv = sizeof(struct dw2102_state),
2343786baecfSMauro Carvalho Chehab 	.power_ctrl = su3000_power_ctrl,
2344786baecfSMauro Carvalho Chehab 	.num_adapters = 1,
2345786baecfSMauro Carvalho Chehab 	.identify_state	= su3000_identify_state,
2346786baecfSMauro Carvalho Chehab 	.i2c_algo = &su3000_i2c_algo,
2347786baecfSMauro Carvalho Chehab 
2348a49de26aSEvgeny Plehov 	.rc.core = {
2349786baecfSMauro Carvalho Chehab 		.rc_interval = 150,
2350a49de26aSEvgeny Plehov 		.rc_codes = RC_MAP_SU3000,
2351a49de26aSEvgeny Plehov 		.module_name = "dw2102",
23526d741bfeSSean Young 		.allowed_protos   = RC_PROTO_BIT_RC5,
2353a49de26aSEvgeny Plehov 		.rc_query = su3000_rc_query,
2354786baecfSMauro Carvalho Chehab 	},
2355786baecfSMauro Carvalho Chehab 
2356786baecfSMauro Carvalho Chehab 	.read_mac_address = su3000_read_mac_address,
2357786baecfSMauro Carvalho Chehab 
2358786baecfSMauro Carvalho Chehab 	.generic_bulk_ctrl_endpoint = 0x01,
2359786baecfSMauro Carvalho Chehab 
2360786baecfSMauro Carvalho Chehab 	.adapter = {
2361786baecfSMauro Carvalho Chehab 		{
2362786baecfSMauro Carvalho Chehab 		.num_frontends = 1,
2363786baecfSMauro Carvalho Chehab 		.fe = {{
2364786baecfSMauro Carvalho Chehab 			.streaming_ctrl   = su3000_streaming_ctrl,
2365786baecfSMauro Carvalho Chehab 			.frontend_attach  = su3000_frontend_attach,
2366786baecfSMauro Carvalho Chehab 			.stream = {
2367786baecfSMauro Carvalho Chehab 				.type = USB_BULK,
2368786baecfSMauro Carvalho Chehab 				.count = 8,
2369786baecfSMauro Carvalho Chehab 				.endpoint = 0x82,
2370786baecfSMauro Carvalho Chehab 				.u = {
2371786baecfSMauro Carvalho Chehab 					.bulk = {
2372786baecfSMauro Carvalho Chehab 						.buffersize = 4096,
2373786baecfSMauro Carvalho Chehab 					}
2374786baecfSMauro Carvalho Chehab 				}
2375786baecfSMauro Carvalho Chehab 			}
2376786baecfSMauro Carvalho Chehab 		}},
2377786baecfSMauro Carvalho Chehab 		}
2378786baecfSMauro Carvalho Chehab 	},
23799cd4bcfbSKai Muenz 	.num_device_descs = 9,
2380786baecfSMauro Carvalho Chehab 	.devices = {
2381786baecfSMauro Carvalho Chehab 		{ "SU3000HD DVB-S USB2.0",
2382786baecfSMauro Carvalho Chehab 			{ &dw2102_table[GENIATECH_SU3000], NULL },
2383786baecfSMauro Carvalho Chehab 			{ NULL },
2384786baecfSMauro Carvalho Chehab 		},
23859cd4bcfbSKai Muenz 		{ "Hauppauge MAX S2 or WinTV NOVA HD USB2.0",
23869cd4bcfbSKai Muenz 			{ &dw2102_table[HAUPPAUGE_MAX_S2], NULL },
23879cd4bcfbSKai Muenz 			{ NULL },
23889cd4bcfbSKai Muenz 		},
2389786baecfSMauro Carvalho Chehab 		{ "Terratec Cinergy S2 USB HD",
23902fa2002fSMauro Carvalho Chehab 			{ &dw2102_table[TERRATEC_CINERGY_S2_R1], NULL },
2391786baecfSMauro Carvalho Chehab 			{ NULL },
2392786baecfSMauro Carvalho Chehab 		},
2393786baecfSMauro Carvalho Chehab 		{ "X3M TV SPC1400HD PCI",
23942fa2002fSMauro Carvalho Chehab 			{ &dw2102_table[GENIATECH_X3M_SPC1400HD], NULL },
2395786baecfSMauro Carvalho Chehab 			{ NULL },
2396786baecfSMauro Carvalho Chehab 		},
239744122dd6SIgor M. Liplianin 		{ "Terratec Cinergy S2 USB HD Rev.2",
239844122dd6SIgor M. Liplianin 			{ &dw2102_table[TERRATEC_CINERGY_S2_R2], NULL },
239944122dd6SIgor M. Liplianin 			{ NULL },
240044122dd6SIgor M. Liplianin 		},
240149438d97SOlli Salonen 		{ "Terratec Cinergy S2 USB HD Rev.3",
240249438d97SOlli Salonen 			{ &dw2102_table[TERRATEC_CINERGY_S2_R3], NULL },
240349438d97SOlli Salonen 			{ NULL },
240449438d97SOlli Salonen 		},
2405528b1a1aSDirk Nehring 		{ "Terratec Cinergy S2 PCIe Dual Port 1",
2406528b1a1aSDirk Nehring 			{ &dw2102_table[TERRATEC_CINERGY_S2_1], NULL },
2407528b1a1aSDirk Nehring 			{ NULL },
2408528b1a1aSDirk Nehring 		},
2409528b1a1aSDirk Nehring 		{ "Terratec Cinergy S2 PCIe Dual Port 2",
2410528b1a1aSDirk Nehring 			{ &dw2102_table[TERRATEC_CINERGY_S2_2], NULL },
2411528b1a1aSDirk Nehring 			{ NULL },
2412528b1a1aSDirk Nehring 		},
2413f08e9f0dSAndrey Pavlenko 		{ "GOTVIEW Satellite HD",
2414f08e9f0dSAndrey Pavlenko 			{ &dw2102_table[GOTVIEW_SAT_HD], NULL },
2415f08e9f0dSAndrey Pavlenko 			{ NULL },
2416f08e9f0dSAndrey Pavlenko 		},
2417786baecfSMauro Carvalho Chehab 	}
2418786baecfSMauro Carvalho Chehab };
2419786baecfSMauro Carvalho Chehab 
2420589a9f0eSAnton Vasilyev static struct dvb_usb_device_properties s421_properties = {
2421589a9f0eSAnton Vasilyev 	.caps = DVB_USB_IS_AN_I2C_ADAPTER,
2422589a9f0eSAnton Vasilyev 	.usb_ctrl = DEVICE_SPECIFIC,
2423589a9f0eSAnton Vasilyev 	.size_of_priv = sizeof(struct dw2102_state),
2424589a9f0eSAnton Vasilyev 	.power_ctrl = su3000_power_ctrl,
2425589a9f0eSAnton Vasilyev 	.num_adapters = 1,
2426589a9f0eSAnton Vasilyev 	.identify_state	= su3000_identify_state,
2427589a9f0eSAnton Vasilyev 	.i2c_algo = &su3000_i2c_algo,
2428589a9f0eSAnton Vasilyev 
2429589a9f0eSAnton Vasilyev 	.rc.core = {
2430589a9f0eSAnton Vasilyev 		.rc_interval = 150,
2431589a9f0eSAnton Vasilyev 		.rc_codes = RC_MAP_SU3000,
2432589a9f0eSAnton Vasilyev 		.module_name = "dw2102",
2433589a9f0eSAnton Vasilyev 		.allowed_protos   = RC_PROTO_BIT_RC5,
2434589a9f0eSAnton Vasilyev 		.rc_query = su3000_rc_query,
2435589a9f0eSAnton Vasilyev 	},
2436589a9f0eSAnton Vasilyev 
2437589a9f0eSAnton Vasilyev 	.read_mac_address = su3000_read_mac_address,
2438589a9f0eSAnton Vasilyev 
2439589a9f0eSAnton Vasilyev 	.generic_bulk_ctrl_endpoint = 0x01,
2440589a9f0eSAnton Vasilyev 
2441589a9f0eSAnton Vasilyev 	.adapter = {
2442589a9f0eSAnton Vasilyev 		{
2443589a9f0eSAnton Vasilyev 		.num_frontends = 1,
2444589a9f0eSAnton Vasilyev 		.fe = {{
2445589a9f0eSAnton Vasilyev 			.streaming_ctrl   = su3000_streaming_ctrl,
2446589a9f0eSAnton Vasilyev 			.frontend_attach  = m88rs2000_frontend_attach,
2447589a9f0eSAnton Vasilyev 			.stream = {
2448589a9f0eSAnton Vasilyev 				.type = USB_BULK,
2449589a9f0eSAnton Vasilyev 				.count = 8,
2450589a9f0eSAnton Vasilyev 				.endpoint = 0x82,
2451589a9f0eSAnton Vasilyev 				.u = {
2452589a9f0eSAnton Vasilyev 					.bulk = {
2453589a9f0eSAnton Vasilyev 						.buffersize = 4096,
2454589a9f0eSAnton Vasilyev 					}
2455589a9f0eSAnton Vasilyev 				}
2456589a9f0eSAnton Vasilyev 			}
2457589a9f0eSAnton Vasilyev 		} },
2458589a9f0eSAnton Vasilyev 		}
2459589a9f0eSAnton Vasilyev 	},
2460589a9f0eSAnton Vasilyev 	.num_device_descs = 2,
2461589a9f0eSAnton Vasilyev 	.devices = {
2462589a9f0eSAnton Vasilyev 		{ "TeVii S421 PCI",
2463589a9f0eSAnton Vasilyev 			{ &dw2102_table[TEVII_S421], NULL },
2464589a9f0eSAnton Vasilyev 			{ NULL },
2465589a9f0eSAnton Vasilyev 		},
2466589a9f0eSAnton Vasilyev 		{ "TeVii S632 USB",
2467589a9f0eSAnton Vasilyev 			{ &dw2102_table[TEVII_S632], NULL },
2468589a9f0eSAnton Vasilyev 			{ NULL },
2469589a9f0eSAnton Vasilyev 		},
2470589a9f0eSAnton Vasilyev 	}
2471589a9f0eSAnton Vasilyev };
2472589a9f0eSAnton Vasilyev 
247351d882edSEvgeny Plehov static struct dvb_usb_device_properties t220_properties = {
247451d882edSEvgeny Plehov 	.caps = DVB_USB_IS_AN_I2C_ADAPTER,
247551d882edSEvgeny Plehov 	.usb_ctrl = DEVICE_SPECIFIC,
24762c4ffe27SOlli Salonen 	.size_of_priv = sizeof(struct dw2102_state),
247751d882edSEvgeny Plehov 	.power_ctrl = su3000_power_ctrl,
247851d882edSEvgeny Plehov 	.num_adapters = 1,
247951d882edSEvgeny Plehov 	.identify_state	= su3000_identify_state,
248051d882edSEvgeny Plehov 	.i2c_algo = &su3000_i2c_algo,
248151d882edSEvgeny Plehov 
2482a49de26aSEvgeny Plehov 	.rc.core = {
248351d882edSEvgeny Plehov 		.rc_interval = 150,
2484a49de26aSEvgeny Plehov 		.rc_codes = RC_MAP_SU3000,
2485a49de26aSEvgeny Plehov 		.module_name = "dw2102",
24866d741bfeSSean Young 		.allowed_protos   = RC_PROTO_BIT_RC5,
2487a49de26aSEvgeny Plehov 		.rc_query = su3000_rc_query,
248851d882edSEvgeny Plehov 	},
248951d882edSEvgeny Plehov 
249051d882edSEvgeny Plehov 	.read_mac_address = su3000_read_mac_address,
249151d882edSEvgeny Plehov 
249251d882edSEvgeny Plehov 	.generic_bulk_ctrl_endpoint = 0x01,
249351d882edSEvgeny Plehov 
249451d882edSEvgeny Plehov 	.adapter = {
249551d882edSEvgeny Plehov 		{
249651d882edSEvgeny Plehov 		.num_frontends = 1,
249751d882edSEvgeny Plehov 		.fe = { {
249851d882edSEvgeny Plehov 			.streaming_ctrl   = su3000_streaming_ctrl,
249951d882edSEvgeny Plehov 			.frontend_attach  = t220_frontend_attach,
250051d882edSEvgeny Plehov 			.stream = {
250151d882edSEvgeny Plehov 				.type = USB_BULK,
250251d882edSEvgeny Plehov 				.count = 8,
250351d882edSEvgeny Plehov 				.endpoint = 0x82,
250451d882edSEvgeny Plehov 				.u = {
250551d882edSEvgeny Plehov 					.bulk = {
250651d882edSEvgeny Plehov 						.buffersize = 4096,
250751d882edSEvgeny Plehov 					}
250851d882edSEvgeny Plehov 				}
250951d882edSEvgeny Plehov 			}
251051d882edSEvgeny Plehov 		} },
251151d882edSEvgeny Plehov 		}
251251d882edSEvgeny Plehov 	},
251351d882edSEvgeny Plehov 	.num_device_descs = 1,
251451d882edSEvgeny Plehov 	.devices = {
251551d882edSEvgeny Plehov 		{ "Geniatech T220 DVB-T/T2 USB2.0",
251651d882edSEvgeny Plehov 			{ &dw2102_table[GENIATECH_T220], NULL },
251751d882edSEvgeny Plehov 			{ NULL },
251851d882edSEvgeny Plehov 		},
251951d882edSEvgeny Plehov 	}
252051d882edSEvgeny Plehov };
252151d882edSEvgeny Plehov 
252227254c36SOlli Salonen static struct dvb_usb_device_properties tt_s2_4600_properties = {
252327254c36SOlli Salonen 	.caps = DVB_USB_IS_AN_I2C_ADAPTER,
252427254c36SOlli Salonen 	.usb_ctrl = DEVICE_SPECIFIC,
252527254c36SOlli Salonen 	.size_of_priv = sizeof(struct dw2102_state),
252627254c36SOlli Salonen 	.power_ctrl = su3000_power_ctrl,
252727254c36SOlli Salonen 	.num_adapters = 1,
252827254c36SOlli Salonen 	.identify_state	= su3000_identify_state,
252927254c36SOlli Salonen 	.i2c_algo = &su3000_i2c_algo,
253027254c36SOlli Salonen 
253127254c36SOlli Salonen 	.rc.core = {
253227254c36SOlli Salonen 		.rc_interval = 250,
253327254c36SOlli Salonen 		.rc_codes = RC_MAP_TT_1500,
253427254c36SOlli Salonen 		.module_name = "dw2102",
25356d741bfeSSean Young 		.allowed_protos   = RC_PROTO_BIT_RC5,
253627254c36SOlli Salonen 		.rc_query = su3000_rc_query,
253727254c36SOlli Salonen 	},
253827254c36SOlli Salonen 
253927254c36SOlli Salonen 	.read_mac_address = su3000_read_mac_address,
254027254c36SOlli Salonen 
254127254c36SOlli Salonen 	.generic_bulk_ctrl_endpoint = 0x01,
254227254c36SOlli Salonen 
254327254c36SOlli Salonen 	.adapter = {
254427254c36SOlli Salonen 		{
254527254c36SOlli Salonen 		.num_frontends = 1,
254627254c36SOlli Salonen 		.fe = {{
254727254c36SOlli Salonen 			.streaming_ctrl   = su3000_streaming_ctrl,
254827254c36SOlli Salonen 			.frontend_attach  = tt_s2_4600_frontend_attach,
254927254c36SOlli Salonen 			.stream = {
255027254c36SOlli Salonen 				.type = USB_BULK,
255127254c36SOlli Salonen 				.count = 8,
255227254c36SOlli Salonen 				.endpoint = 0x82,
255327254c36SOlli Salonen 				.u = {
255427254c36SOlli Salonen 					.bulk = {
255527254c36SOlli Salonen 						.buffersize = 4096,
255627254c36SOlli Salonen 					}
255727254c36SOlli Salonen 				}
255827254c36SOlli Salonen 			}
255927254c36SOlli Salonen 		} },
256027254c36SOlli Salonen 		}
256127254c36SOlli Salonen 	},
25626ede20f9SOlli Salonen 	.num_device_descs = 5,
256327254c36SOlli Salonen 	.devices = {
256427254c36SOlli Salonen 		{ "TechnoTrend TT-connect S2-4600",
25652fa2002fSMauro Carvalho Chehab 			{ &dw2102_table[TECHNOTREND_CONNECT_S2_4600], NULL },
256627254c36SOlli Salonen 			{ NULL },
256727254c36SOlli Salonen 		},
256844767fc4SOlli Salonen 		{ "TeVii S482 (tuner 1)",
256944767fc4SOlli Salonen 			{ &dw2102_table[TEVII_S482_1], NULL },
257044767fc4SOlli Salonen 			{ NULL },
257144767fc4SOlli Salonen 		},
257244767fc4SOlli Salonen 		{ "TeVii S482 (tuner 2)",
257344767fc4SOlli Salonen 			{ &dw2102_table[TEVII_S482_2], NULL },
257444767fc4SOlli Salonen 			{ NULL },
257544767fc4SOlli Salonen 		},
257693b66420SPhilipp Zabel 		{ "Terratec Cinergy S2 USB BOX",
2577bd693f68SMichael Bunk 			{ &dw2102_table[TERRATEC_CINERGY_S2_R4], NULL },
257893b66420SPhilipp Zabel 			{ NULL },
257993b66420SPhilipp Zabel 		},
25806ede20f9SOlli Salonen 		{ "TeVii S662",
25816ede20f9SOlli Salonen 			{ &dw2102_table[TEVII_S662], NULL },
25826ede20f9SOlli Salonen 			{ NULL },
25836ede20f9SOlli Salonen 		},
258427254c36SOlli Salonen 	}
258527254c36SOlli Salonen };
258627254c36SOlli Salonen 
dw2102_probe(struct usb_interface * intf,const struct usb_device_id * id)2587786baecfSMauro Carvalho Chehab static int dw2102_probe(struct usb_interface *intf,
2588786baecfSMauro Carvalho Chehab 			const struct usb_device_id *id)
2589786baecfSMauro Carvalho Chehab {
2590589a9f0eSAnton Vasilyev 	if (!(dvb_usb_device_init(intf, &dw2102_properties,
2591589a9f0eSAnton Vasilyev 				  THIS_MODULE, NULL, adapter_nr) &&
2592589a9f0eSAnton Vasilyev 	      dvb_usb_device_init(intf, &dw2104_properties,
2593589a9f0eSAnton Vasilyev 				  THIS_MODULE, NULL, adapter_nr) &&
2594589a9f0eSAnton Vasilyev 	      dvb_usb_device_init(intf, &dw3101_properties,
2595589a9f0eSAnton Vasilyev 				  THIS_MODULE, NULL, adapter_nr) &&
2596589a9f0eSAnton Vasilyev 	      dvb_usb_device_init(intf, &s6x0_properties,
2597589a9f0eSAnton Vasilyev 				  THIS_MODULE, NULL, adapter_nr) &&
2598589a9f0eSAnton Vasilyev 	      dvb_usb_device_init(intf, &p1100_properties,
2599589a9f0eSAnton Vasilyev 				  THIS_MODULE, NULL, adapter_nr) &&
2600589a9f0eSAnton Vasilyev 	      dvb_usb_device_init(intf, &s660_properties,
2601589a9f0eSAnton Vasilyev 				  THIS_MODULE, NULL, adapter_nr) &&
2602589a9f0eSAnton Vasilyev 	      dvb_usb_device_init(intf, &p7500_properties,
2603589a9f0eSAnton Vasilyev 				  THIS_MODULE, NULL, adapter_nr) &&
2604589a9f0eSAnton Vasilyev 	      dvb_usb_device_init(intf, &s421_properties,
2605589a9f0eSAnton Vasilyev 				  THIS_MODULE, NULL, adapter_nr) &&
2606589a9f0eSAnton Vasilyev 	      dvb_usb_device_init(intf, &su3000_properties,
2607589a9f0eSAnton Vasilyev 				  THIS_MODULE, NULL, adapter_nr) &&
2608589a9f0eSAnton Vasilyev 	      dvb_usb_device_init(intf, &t220_properties,
2609589a9f0eSAnton Vasilyev 				  THIS_MODULE, NULL, adapter_nr) &&
2610589a9f0eSAnton Vasilyev 	      dvb_usb_device_init(intf, &tt_s2_4600_properties,
2611589a9f0eSAnton Vasilyev 				  THIS_MODULE, NULL, adapter_nr))) {
2612786baecfSMauro Carvalho Chehab 		return 0;
2613299c7007SAnton Vasilyev 	}
2614786baecfSMauro Carvalho Chehab 
2615589a9f0eSAnton Vasilyev 	return -ENODEV;
2616786baecfSMauro Carvalho Chehab }
2617786baecfSMauro Carvalho Chehab 
dw2102_disconnect(struct usb_interface * intf)261870769b24SOlli Salonen static void dw2102_disconnect(struct usb_interface *intf)
261970769b24SOlli Salonen {
262070769b24SOlli Salonen 	struct dvb_usb_device *d = usb_get_intfdata(intf);
2621663e7460SYu Zhe 	struct dw2102_state *st = d->priv;
262270769b24SOlli Salonen 	struct i2c_client *client;
262370769b24SOlli Salonen 
262470769b24SOlli Salonen 	/* remove I2C client for tuner */
262570769b24SOlli Salonen 	client = st->i2c_client_tuner;
262670769b24SOlli Salonen 	if (client) {
262770769b24SOlli Salonen 		module_put(client->dev.driver->owner);
262870769b24SOlli Salonen 		i2c_unregister_device(client);
262970769b24SOlli Salonen 	}
263070769b24SOlli Salonen 
2631f3c6abcaSOlli Salonen 	/* remove I2C client for demodulator */
2632f3c6abcaSOlli Salonen 	client = st->i2c_client_demod;
2633f3c6abcaSOlli Salonen 	if (client) {
2634f3c6abcaSOlli Salonen 		module_put(client->dev.driver->owner);
2635f3c6abcaSOlli Salonen 		i2c_unregister_device(client);
2636f3c6abcaSOlli Salonen 	}
2637f3c6abcaSOlli Salonen 
263870769b24SOlli Salonen 	dvb_usb_device_exit(intf);
263970769b24SOlli Salonen }
264070769b24SOlli Salonen 
2641786baecfSMauro Carvalho Chehab static struct usb_driver dw2102_driver = {
2642786baecfSMauro Carvalho Chehab 	.name = "dw2102",
2643786baecfSMauro Carvalho Chehab 	.probe = dw2102_probe,
264470769b24SOlli Salonen 	.disconnect = dw2102_disconnect,
2645786baecfSMauro Carvalho Chehab 	.id_table = dw2102_table,
2646786baecfSMauro Carvalho Chehab };
2647786baecfSMauro Carvalho Chehab 
2648786baecfSMauro Carvalho Chehab module_usb_driver(dw2102_driver);
2649786baecfSMauro Carvalho Chehab 
2650786baecfSMauro Carvalho Chehab MODULE_AUTHOR("Igor M. Liplianin (c) liplianin@me.by");
2651f319ed91SMauro Carvalho Chehab 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");
2652786baecfSMauro Carvalho Chehab MODULE_VERSION("0.1");
2653786baecfSMauro Carvalho Chehab MODULE_LICENSE("GPL");
26546823627bSRémi Cardona MODULE_FIRMWARE(DW2101_FIRMWARE);
26556823627bSRémi Cardona MODULE_FIRMWARE(DW2102_FIRMWARE);
26566823627bSRémi Cardona MODULE_FIRMWARE(DW2104_FIRMWARE);
26576823627bSRémi Cardona MODULE_FIRMWARE(DW3101_FIRMWARE);
26586823627bSRémi Cardona MODULE_FIRMWARE(S630_FIRMWARE);
26596823627bSRémi Cardona MODULE_FIRMWARE(S660_FIRMWARE);
26606823627bSRémi Cardona MODULE_FIRMWARE(P1100_FIRMWARE);
26616823627bSRémi Cardona MODULE_FIRMWARE(P7500_FIRMWARE);
2662