xref: /linux/drivers/media/usb/dvb-usb/dw2102.c (revision fada1935590f66dc6784981e0d557ca09013c847)
1786baecfSMauro Carvalho Chehab /* DVB USB framework compliant Linux driver for the
2786baecfSMauro Carvalho Chehab  *	DVBWorld DVB-S 2101, 2102, DVB-S2 2104, DVB-C 3101,
36ede20f9SOlli Salonen  *	TeVii S421, S480, S482, S600, S630, S632, S650, S660, S662,
4786baecfSMauro Carvalho Chehab  *	Prof 1100, 7500,
527254c36SOlli Salonen  *	Geniatech SU3000, T220,
66ede20f9SOlli Salonen  *	TechnoTrend S2-4600,
76ede20f9SOlli Salonen  *	Terratec Cinergy S2 cards
8955d00acSIgor M. Liplianin  * Copyright (C) 2008-2012 Igor M. Liplianin (liplianin@me.by)
9786baecfSMauro Carvalho Chehab  *
10786baecfSMauro Carvalho Chehab  *	This program is free software; you can redistribute it and/or modify it
11786baecfSMauro Carvalho Chehab  *	under the terms of the GNU General Public License as published by the
12786baecfSMauro Carvalho Chehab  *	Free Software Foundation, version 2.
13786baecfSMauro Carvalho Chehab  *
14786baecfSMauro Carvalho Chehab  * see Documentation/dvb/README.dvb-usb for more information
15786baecfSMauro Carvalho Chehab  */
16*fada1935SMauro Carvalho Chehab #include <media/dvb-usb-ids.h>
17786baecfSMauro Carvalho Chehab #include "dw2102.h"
18786baecfSMauro Carvalho Chehab #include "si21xx.h"
19786baecfSMauro Carvalho Chehab #include "stv0299.h"
20786baecfSMauro Carvalho Chehab #include "z0194a.h"
21786baecfSMauro Carvalho Chehab #include "stv0288.h"
22786baecfSMauro Carvalho Chehab #include "stb6000.h"
23786baecfSMauro Carvalho Chehab #include "eds1547.h"
24786baecfSMauro Carvalho Chehab #include "cx24116.h"
25786baecfSMauro Carvalho Chehab #include "tda1002x.h"
26786baecfSMauro Carvalho Chehab #include "mt312.h"
27786baecfSMauro Carvalho Chehab #include "zl10039.h"
2873f0af44SKonstantin Dimitrov #include "ts2020.h"
29786baecfSMauro Carvalho Chehab #include "ds3000.h"
30786baecfSMauro Carvalho Chehab #include "stv0900.h"
31786baecfSMauro Carvalho Chehab #include "stv6110.h"
32786baecfSMauro Carvalho Chehab #include "stb6100.h"
33786baecfSMauro Carvalho Chehab #include "stb6100_proc.h"
34955d00acSIgor M. Liplianin #include "m88rs2000.h"
3551d882edSEvgeny Plehov #include "tda18271.h"
3651d882edSEvgeny Plehov #include "cxd2820r.h"
3727254c36SOlli Salonen #include "m88ds3103.h"
38786baecfSMauro Carvalho Chehab 
390065a79aSMauro Carvalho Chehab /* Max transfer size done by I2C transfer functions */
400065a79aSMauro Carvalho Chehab #define MAX_XFER_SIZE  64
410065a79aSMauro Carvalho Chehab 
42f08e9f0dSAndrey Pavlenko 
43786baecfSMauro Carvalho Chehab #define DW210X_READ_MSG 0
44786baecfSMauro Carvalho Chehab #define DW210X_WRITE_MSG 1
45786baecfSMauro Carvalho Chehab 
46786baecfSMauro Carvalho Chehab #define REG_1F_SYMBOLRATE_BYTE0 0x1f
47786baecfSMauro Carvalho Chehab #define REG_20_SYMBOLRATE_BYTE1 0x20
48786baecfSMauro Carvalho Chehab #define REG_21_SYMBOLRATE_BYTE2 0x21
49786baecfSMauro Carvalho Chehab /* on my own*/
50786baecfSMauro Carvalho Chehab #define DW2102_VOLTAGE_CTRL (0x1800)
51786baecfSMauro Carvalho Chehab #define SU3000_STREAM_CTRL (0x1900)
52786baecfSMauro Carvalho Chehab #define DW2102_RC_QUERY (0x1a00)
53786baecfSMauro Carvalho Chehab #define DW2102_LED_CTRL (0x1b00)
54786baecfSMauro Carvalho Chehab 
556823627bSRémi Cardona #define DW2101_FIRMWARE "dvb-usb-dw2101.fw"
566823627bSRémi Cardona #define DW2102_FIRMWARE "dvb-usb-dw2102.fw"
576823627bSRémi Cardona #define DW2104_FIRMWARE "dvb-usb-dw2104.fw"
586823627bSRémi Cardona #define DW3101_FIRMWARE "dvb-usb-dw3101.fw"
596823627bSRémi Cardona #define S630_FIRMWARE   "dvb-usb-s630.fw"
606823627bSRémi Cardona #define S660_FIRMWARE   "dvb-usb-s660.fw"
616823627bSRémi Cardona #define P1100_FIRMWARE  "dvb-usb-p1100.fw"
626823627bSRémi Cardona #define P7500_FIRMWARE  "dvb-usb-p7500.fw"
636823627bSRémi Cardona 
64786baecfSMauro Carvalho Chehab #define	err_str "did not find the firmware file. (%s) " \
65786baecfSMauro Carvalho Chehab 		"Please see linux/Documentation/dvb/ for more details " \
66786baecfSMauro Carvalho Chehab 		"on firmware-problems."
67786baecfSMauro Carvalho Chehab 
682c4ffe27SOlli Salonen struct dw2102_state {
69786baecfSMauro Carvalho Chehab 	u8 initialized;
70356484caSOlli Salonen 	u8 last_lock;
71606142afSJonathan McDowell 	u8 data[MAX_XFER_SIZE + 4];
72f3c6abcaSOlli Salonen 	struct i2c_client *i2c_client_demod;
7370769b24SOlli Salonen 	struct i2c_client *i2c_client_tuner;
74356484caSOlli Salonen 
75356484caSOlli Salonen 	/* fe hook functions*/
760df289a2SMauro Carvalho Chehab 	int (*old_set_voltage)(struct dvb_frontend *f, enum fe_sec_voltage v);
77356484caSOlli Salonen 	int (*fe_read_status)(struct dvb_frontend *fe,
780df289a2SMauro Carvalho Chehab 			      enum fe_status *status);
79786baecfSMauro Carvalho Chehab };
80786baecfSMauro Carvalho Chehab 
81786baecfSMauro Carvalho Chehab /* debug */
82786baecfSMauro Carvalho Chehab static int dvb_usb_dw2102_debug;
83786baecfSMauro Carvalho Chehab module_param_named(debug, dvb_usb_dw2102_debug, int, 0644);
84786baecfSMauro Carvalho Chehab MODULE_PARM_DESC(debug, "set debugging level (1=info 2=xfer 4=rc(or-able))."
85786baecfSMauro Carvalho Chehab 						DVB_USB_DEBUG_STATUS);
86786baecfSMauro Carvalho Chehab 
87786baecfSMauro Carvalho Chehab /* demod probe */
88786baecfSMauro Carvalho Chehab static int demod_probe = 1;
89786baecfSMauro Carvalho Chehab module_param_named(demod, demod_probe, int, 0644);
90f319ed91SMauro Carvalho Chehab MODULE_PARM_DESC(demod, "demod to probe (1=cx24116 2=stv0903+stv6110 4=stv0903+stb6100(or-able)).");
91786baecfSMauro Carvalho Chehab 
92786baecfSMauro Carvalho Chehab DVB_DEFINE_MOD_OPT_ADAPTER_NR(adapter_nr);
93786baecfSMauro Carvalho Chehab 
94786baecfSMauro Carvalho Chehab static int dw210x_op_rw(struct usb_device *dev, u8 request, u16 value,
95786baecfSMauro Carvalho Chehab 			u16 index, u8 * data, u16 len, int flags)
96786baecfSMauro Carvalho Chehab {
97786baecfSMauro Carvalho Chehab 	int ret;
98786baecfSMauro Carvalho Chehab 	u8 *u8buf;
99786baecfSMauro Carvalho Chehab 	unsigned int pipe = (flags == DW210X_READ_MSG) ?
100786baecfSMauro Carvalho Chehab 				usb_rcvctrlpipe(dev, 0) : usb_sndctrlpipe(dev, 0);
101786baecfSMauro Carvalho Chehab 	u8 request_type = (flags == DW210X_READ_MSG) ? USB_DIR_IN : USB_DIR_OUT;
102786baecfSMauro Carvalho Chehab 
103786baecfSMauro Carvalho Chehab 	u8buf = kmalloc(len, GFP_KERNEL);
104786baecfSMauro Carvalho Chehab 	if (!u8buf)
105786baecfSMauro Carvalho Chehab 		return -ENOMEM;
106786baecfSMauro Carvalho Chehab 
107786baecfSMauro Carvalho Chehab 
108786baecfSMauro Carvalho Chehab 	if (flags == DW210X_WRITE_MSG)
109786baecfSMauro Carvalho Chehab 		memcpy(u8buf, data, len);
110786baecfSMauro Carvalho Chehab 	ret = usb_control_msg(dev, pipe, request, request_type | USB_TYPE_VENDOR,
111786baecfSMauro Carvalho Chehab 				value, index , u8buf, len, 2000);
112786baecfSMauro Carvalho Chehab 
113786baecfSMauro Carvalho Chehab 	if (flags == DW210X_READ_MSG)
114786baecfSMauro Carvalho Chehab 		memcpy(data, u8buf, len);
115786baecfSMauro Carvalho Chehab 
116786baecfSMauro Carvalho Chehab 	kfree(u8buf);
117786baecfSMauro Carvalho Chehab 	return ret;
118786baecfSMauro Carvalho Chehab }
119786baecfSMauro Carvalho Chehab 
120786baecfSMauro Carvalho Chehab /* I2C */
121786baecfSMauro Carvalho Chehab static int dw2102_i2c_transfer(struct i2c_adapter *adap, struct i2c_msg msg[],
122786baecfSMauro Carvalho Chehab 		int num)
123786baecfSMauro Carvalho Chehab {
124786baecfSMauro Carvalho Chehab 	struct dvb_usb_device *d = i2c_get_adapdata(adap);
125786baecfSMauro Carvalho Chehab 	int i = 0;
126786baecfSMauro Carvalho Chehab 	u8 buf6[] = {0x2c, 0x05, 0xc0, 0, 0, 0, 0};
127786baecfSMauro Carvalho Chehab 	u16 value;
128786baecfSMauro Carvalho Chehab 
129786baecfSMauro Carvalho Chehab 	if (!d)
130786baecfSMauro Carvalho Chehab 		return -ENODEV;
131786baecfSMauro Carvalho Chehab 	if (mutex_lock_interruptible(&d->i2c_mutex) < 0)
132786baecfSMauro Carvalho Chehab 		return -EAGAIN;
133786baecfSMauro Carvalho Chehab 
134786baecfSMauro Carvalho Chehab 	switch (num) {
135786baecfSMauro Carvalho Chehab 	case 2:
136786baecfSMauro Carvalho Chehab 		/* read stv0299 register */
137786baecfSMauro Carvalho Chehab 		value = msg[0].buf[0];/* register */
138786baecfSMauro Carvalho Chehab 		for (i = 0; i < msg[1].len; i++) {
139786baecfSMauro Carvalho Chehab 			dw210x_op_rw(d->udev, 0xb5, value + i, 0,
140786baecfSMauro Carvalho Chehab 					buf6, 2, DW210X_READ_MSG);
141786baecfSMauro Carvalho Chehab 			msg[1].buf[i] = buf6[0];
142786baecfSMauro Carvalho Chehab 		}
143786baecfSMauro Carvalho Chehab 		break;
144786baecfSMauro Carvalho Chehab 	case 1:
145786baecfSMauro Carvalho Chehab 		switch (msg[0].addr) {
146786baecfSMauro Carvalho Chehab 		case 0x68:
147786baecfSMauro Carvalho Chehab 			/* write to stv0299 register */
148786baecfSMauro Carvalho Chehab 			buf6[0] = 0x2a;
149786baecfSMauro Carvalho Chehab 			buf6[1] = msg[0].buf[0];
150786baecfSMauro Carvalho Chehab 			buf6[2] = msg[0].buf[1];
151786baecfSMauro Carvalho Chehab 			dw210x_op_rw(d->udev, 0xb2, 0, 0,
152786baecfSMauro Carvalho Chehab 					buf6, 3, DW210X_WRITE_MSG);
153786baecfSMauro Carvalho Chehab 			break;
154786baecfSMauro Carvalho Chehab 		case 0x60:
155786baecfSMauro Carvalho Chehab 			if (msg[0].flags == 0) {
156786baecfSMauro Carvalho Chehab 			/* write to tuner pll */
157786baecfSMauro Carvalho Chehab 				buf6[0] = 0x2c;
158786baecfSMauro Carvalho Chehab 				buf6[1] = 5;
159786baecfSMauro Carvalho Chehab 				buf6[2] = 0xc0;
160786baecfSMauro Carvalho Chehab 				buf6[3] = msg[0].buf[0];
161786baecfSMauro Carvalho Chehab 				buf6[4] = msg[0].buf[1];
162786baecfSMauro Carvalho Chehab 				buf6[5] = msg[0].buf[2];
163786baecfSMauro Carvalho Chehab 				buf6[6] = msg[0].buf[3];
164786baecfSMauro Carvalho Chehab 				dw210x_op_rw(d->udev, 0xb2, 0, 0,
165786baecfSMauro Carvalho Chehab 						buf6, 7, DW210X_WRITE_MSG);
166786baecfSMauro Carvalho Chehab 			} else {
167786baecfSMauro Carvalho Chehab 			/* read from tuner */
168786baecfSMauro Carvalho Chehab 				dw210x_op_rw(d->udev, 0xb5, 0, 0,
169786baecfSMauro Carvalho Chehab 						buf6, 1, DW210X_READ_MSG);
170786baecfSMauro Carvalho Chehab 				msg[0].buf[0] = buf6[0];
171786baecfSMauro Carvalho Chehab 			}
172786baecfSMauro Carvalho Chehab 			break;
173786baecfSMauro Carvalho Chehab 		case (DW2102_RC_QUERY):
174786baecfSMauro Carvalho Chehab 			dw210x_op_rw(d->udev, 0xb8, 0, 0,
175786baecfSMauro Carvalho Chehab 					buf6, 2, DW210X_READ_MSG);
176786baecfSMauro Carvalho Chehab 			msg[0].buf[0] = buf6[0];
177786baecfSMauro Carvalho Chehab 			msg[0].buf[1] = buf6[1];
178786baecfSMauro Carvalho Chehab 			break;
179786baecfSMauro Carvalho Chehab 		case (DW2102_VOLTAGE_CTRL):
180786baecfSMauro Carvalho Chehab 			buf6[0] = 0x30;
181786baecfSMauro Carvalho Chehab 			buf6[1] = msg[0].buf[0];
182786baecfSMauro Carvalho Chehab 			dw210x_op_rw(d->udev, 0xb2, 0, 0,
183786baecfSMauro Carvalho Chehab 					buf6, 2, DW210X_WRITE_MSG);
184786baecfSMauro Carvalho Chehab 			break;
185786baecfSMauro Carvalho Chehab 		}
186786baecfSMauro Carvalho Chehab 
187786baecfSMauro Carvalho Chehab 		break;
188786baecfSMauro Carvalho Chehab 	}
189786baecfSMauro Carvalho Chehab 
190786baecfSMauro Carvalho Chehab 	mutex_unlock(&d->i2c_mutex);
191786baecfSMauro Carvalho Chehab 	return num;
192786baecfSMauro Carvalho Chehab }
193786baecfSMauro Carvalho Chehab 
194786baecfSMauro Carvalho Chehab static int dw2102_serit_i2c_transfer(struct i2c_adapter *adap,
195786baecfSMauro Carvalho Chehab 						struct i2c_msg msg[], int num)
196786baecfSMauro Carvalho Chehab {
197786baecfSMauro Carvalho Chehab 	struct dvb_usb_device *d = i2c_get_adapdata(adap);
198786baecfSMauro Carvalho Chehab 	u8 buf6[] = {0, 0, 0, 0, 0, 0, 0};
199786baecfSMauro Carvalho Chehab 
200786baecfSMauro Carvalho Chehab 	if (!d)
201786baecfSMauro Carvalho Chehab 		return -ENODEV;
202786baecfSMauro Carvalho Chehab 	if (mutex_lock_interruptible(&d->i2c_mutex) < 0)
203786baecfSMauro Carvalho Chehab 		return -EAGAIN;
204786baecfSMauro Carvalho Chehab 
205786baecfSMauro Carvalho Chehab 	switch (num) {
206786baecfSMauro Carvalho Chehab 	case 2:
207950e252cSAlyssa Milburn 		if (msg[0].len != 1) {
208950e252cSAlyssa Milburn 			warn("i2c rd: len=%d is not 1!\n",
209950e252cSAlyssa Milburn 			     msg[0].len);
210950e252cSAlyssa Milburn 			num = -EOPNOTSUPP;
211950e252cSAlyssa Milburn 			break;
212950e252cSAlyssa Milburn 		}
213950e252cSAlyssa Milburn 
214950e252cSAlyssa Milburn 		if (2 + msg[1].len > sizeof(buf6)) {
215950e252cSAlyssa Milburn 			warn("i2c rd: len=%d is too big!\n",
216950e252cSAlyssa Milburn 			     msg[1].len);
217950e252cSAlyssa Milburn 			num = -EOPNOTSUPP;
218950e252cSAlyssa Milburn 			break;
219950e252cSAlyssa Milburn 		}
220950e252cSAlyssa Milburn 
221786baecfSMauro Carvalho Chehab 		/* read si2109 register by number */
222786baecfSMauro Carvalho Chehab 		buf6[0] = msg[0].addr << 1;
223786baecfSMauro Carvalho Chehab 		buf6[1] = msg[0].len;
224786baecfSMauro Carvalho Chehab 		buf6[2] = msg[0].buf[0];
225786baecfSMauro Carvalho Chehab 		dw210x_op_rw(d->udev, 0xc2, 0, 0,
226786baecfSMauro Carvalho Chehab 				buf6, msg[0].len + 2, DW210X_WRITE_MSG);
227786baecfSMauro Carvalho Chehab 		/* read si2109 register */
228786baecfSMauro Carvalho Chehab 		dw210x_op_rw(d->udev, 0xc3, 0xd0, 0,
229786baecfSMauro Carvalho Chehab 				buf6, msg[1].len + 2, DW210X_READ_MSG);
230786baecfSMauro Carvalho Chehab 		memcpy(msg[1].buf, buf6 + 2, msg[1].len);
231786baecfSMauro Carvalho Chehab 
232786baecfSMauro Carvalho Chehab 		break;
233786baecfSMauro Carvalho Chehab 	case 1:
234786baecfSMauro Carvalho Chehab 		switch (msg[0].addr) {
235786baecfSMauro Carvalho Chehab 		case 0x68:
236950e252cSAlyssa Milburn 			if (2 + msg[0].len > sizeof(buf6)) {
237950e252cSAlyssa Milburn 				warn("i2c wr: len=%d is too big!\n",
238950e252cSAlyssa Milburn 				     msg[0].len);
239950e252cSAlyssa Milburn 				num = -EOPNOTSUPP;
240950e252cSAlyssa Milburn 				break;
241950e252cSAlyssa Milburn 			}
242950e252cSAlyssa Milburn 
243786baecfSMauro Carvalho Chehab 			/* write to si2109 register */
244786baecfSMauro Carvalho Chehab 			buf6[0] = msg[0].addr << 1;
245786baecfSMauro Carvalho Chehab 			buf6[1] = msg[0].len;
246786baecfSMauro Carvalho Chehab 			memcpy(buf6 + 2, msg[0].buf, msg[0].len);
247786baecfSMauro Carvalho Chehab 			dw210x_op_rw(d->udev, 0xc2, 0, 0, buf6,
248786baecfSMauro Carvalho Chehab 					msg[0].len + 2, DW210X_WRITE_MSG);
249786baecfSMauro Carvalho Chehab 			break;
250786baecfSMauro Carvalho Chehab 		case(DW2102_RC_QUERY):
251786baecfSMauro Carvalho Chehab 			dw210x_op_rw(d->udev, 0xb8, 0, 0,
252786baecfSMauro Carvalho Chehab 					buf6, 2, DW210X_READ_MSG);
253786baecfSMauro Carvalho Chehab 			msg[0].buf[0] = buf6[0];
254786baecfSMauro Carvalho Chehab 			msg[0].buf[1] = buf6[1];
255786baecfSMauro Carvalho Chehab 			break;
256786baecfSMauro Carvalho Chehab 		case(DW2102_VOLTAGE_CTRL):
257786baecfSMauro Carvalho Chehab 			buf6[0] = 0x30;
258786baecfSMauro Carvalho Chehab 			buf6[1] = msg[0].buf[0];
259786baecfSMauro Carvalho Chehab 			dw210x_op_rw(d->udev, 0xb2, 0, 0,
260786baecfSMauro Carvalho Chehab 					buf6, 2, DW210X_WRITE_MSG);
261786baecfSMauro Carvalho Chehab 			break;
262786baecfSMauro Carvalho Chehab 		}
263786baecfSMauro Carvalho Chehab 		break;
264786baecfSMauro Carvalho Chehab 	}
265786baecfSMauro Carvalho Chehab 
266786baecfSMauro Carvalho Chehab 	mutex_unlock(&d->i2c_mutex);
267786baecfSMauro Carvalho Chehab 	return num;
268786baecfSMauro Carvalho Chehab }
269786baecfSMauro Carvalho Chehab 
270786baecfSMauro Carvalho Chehab static int dw2102_earda_i2c_transfer(struct i2c_adapter *adap, struct i2c_msg msg[], int num)
271786baecfSMauro Carvalho Chehab {
272786baecfSMauro Carvalho Chehab 	struct dvb_usb_device *d = i2c_get_adapdata(adap);
273324ed533SDan Carpenter 	int ret;
274786baecfSMauro Carvalho Chehab 
275786baecfSMauro Carvalho Chehab 	if (!d)
276786baecfSMauro Carvalho Chehab 		return -ENODEV;
277786baecfSMauro Carvalho Chehab 	if (mutex_lock_interruptible(&d->i2c_mutex) < 0)
278786baecfSMauro Carvalho Chehab 		return -EAGAIN;
279786baecfSMauro Carvalho Chehab 
280786baecfSMauro Carvalho Chehab 	switch (num) {
281786baecfSMauro Carvalho Chehab 	case 2: {
282786baecfSMauro Carvalho Chehab 		/* read */
283786baecfSMauro Carvalho Chehab 		/* first write first register number */
2840065a79aSMauro Carvalho Chehab 		u8 ibuf[MAX_XFER_SIZE], obuf[3];
2850065a79aSMauro Carvalho Chehab 
286950e252cSAlyssa Milburn 		if (2 + msg[0].len != sizeof(obuf)) {
287950e252cSAlyssa Milburn 			warn("i2c rd: len=%d is not 1!\n",
288950e252cSAlyssa Milburn 			     msg[0].len);
289950e252cSAlyssa Milburn 			ret = -EOPNOTSUPP;
290950e252cSAlyssa Milburn 			goto unlock;
291950e252cSAlyssa Milburn 		}
292950e252cSAlyssa Milburn 
2930065a79aSMauro Carvalho Chehab 		if (2 + msg[1].len > sizeof(ibuf)) {
2940065a79aSMauro Carvalho Chehab 			warn("i2c rd: len=%d is too big!\n",
2950065a79aSMauro Carvalho Chehab 			     msg[1].len);
296324ed533SDan Carpenter 			ret = -EOPNOTSUPP;
297324ed533SDan Carpenter 			goto unlock;
2980065a79aSMauro Carvalho Chehab 		}
2990065a79aSMauro Carvalho Chehab 
300786baecfSMauro Carvalho Chehab 		obuf[0] = msg[0].addr << 1;
301786baecfSMauro Carvalho Chehab 		obuf[1] = msg[0].len;
302786baecfSMauro Carvalho Chehab 		obuf[2] = msg[0].buf[0];
303786baecfSMauro Carvalho Chehab 		dw210x_op_rw(d->udev, 0xc2, 0, 0,
304786baecfSMauro Carvalho Chehab 				obuf, msg[0].len + 2, DW210X_WRITE_MSG);
305786baecfSMauro Carvalho Chehab 		/* second read registers */
306786baecfSMauro Carvalho Chehab 		dw210x_op_rw(d->udev, 0xc3, 0xd1 , 0,
307786baecfSMauro Carvalho Chehab 				ibuf, msg[1].len + 2, DW210X_READ_MSG);
308786baecfSMauro Carvalho Chehab 		memcpy(msg[1].buf, ibuf + 2, msg[1].len);
309786baecfSMauro Carvalho Chehab 
310786baecfSMauro Carvalho Chehab 		break;
311786baecfSMauro Carvalho Chehab 	}
312786baecfSMauro Carvalho Chehab 	case 1:
313786baecfSMauro Carvalho Chehab 		switch (msg[0].addr) {
314786baecfSMauro Carvalho Chehab 		case 0x68: {
315786baecfSMauro Carvalho Chehab 			/* write to register */
3160065a79aSMauro Carvalho Chehab 			u8 obuf[MAX_XFER_SIZE];
3170065a79aSMauro Carvalho Chehab 
3180065a79aSMauro Carvalho Chehab 			if (2 + msg[0].len > sizeof(obuf)) {
3190065a79aSMauro Carvalho Chehab 				warn("i2c wr: len=%d is too big!\n",
3200065a79aSMauro Carvalho Chehab 				     msg[1].len);
321324ed533SDan Carpenter 				ret = -EOPNOTSUPP;
322324ed533SDan Carpenter 				goto unlock;
3230065a79aSMauro Carvalho Chehab 			}
3240065a79aSMauro Carvalho Chehab 
325786baecfSMauro Carvalho Chehab 			obuf[0] = msg[0].addr << 1;
326786baecfSMauro Carvalho Chehab 			obuf[1] = msg[0].len;
327786baecfSMauro Carvalho Chehab 			memcpy(obuf + 2, msg[0].buf, msg[0].len);
328786baecfSMauro Carvalho Chehab 			dw210x_op_rw(d->udev, 0xc2, 0, 0,
329786baecfSMauro Carvalho Chehab 					obuf, msg[0].len + 2, DW210X_WRITE_MSG);
330786baecfSMauro Carvalho Chehab 			break;
331786baecfSMauro Carvalho Chehab 		}
332786baecfSMauro Carvalho Chehab 		case 0x61: {
333786baecfSMauro Carvalho Chehab 			/* write to tuner */
3340065a79aSMauro Carvalho Chehab 			u8 obuf[MAX_XFER_SIZE];
3350065a79aSMauro Carvalho Chehab 
3360065a79aSMauro Carvalho Chehab 			if (2 + msg[0].len > sizeof(obuf)) {
3370065a79aSMauro Carvalho Chehab 				warn("i2c wr: len=%d is too big!\n",
3380065a79aSMauro Carvalho Chehab 				     msg[1].len);
339324ed533SDan Carpenter 				ret = -EOPNOTSUPP;
340324ed533SDan Carpenter 				goto unlock;
3410065a79aSMauro Carvalho Chehab 			}
3420065a79aSMauro Carvalho Chehab 
343786baecfSMauro Carvalho Chehab 			obuf[0] = msg[0].addr << 1;
344786baecfSMauro Carvalho Chehab 			obuf[1] = msg[0].len;
345786baecfSMauro Carvalho Chehab 			memcpy(obuf + 2, msg[0].buf, msg[0].len);
346786baecfSMauro Carvalho Chehab 			dw210x_op_rw(d->udev, 0xc2, 0, 0,
347786baecfSMauro Carvalho Chehab 					obuf, msg[0].len + 2, DW210X_WRITE_MSG);
348786baecfSMauro Carvalho Chehab 			break;
349786baecfSMauro Carvalho Chehab 		}
350786baecfSMauro Carvalho Chehab 		case(DW2102_RC_QUERY): {
351786baecfSMauro Carvalho Chehab 			u8 ibuf[2];
352786baecfSMauro Carvalho Chehab 			dw210x_op_rw(d->udev, 0xb8, 0, 0,
353786baecfSMauro Carvalho Chehab 					ibuf, 2, DW210X_READ_MSG);
354786baecfSMauro Carvalho Chehab 			memcpy(msg[0].buf, ibuf , 2);
355786baecfSMauro Carvalho Chehab 			break;
356786baecfSMauro Carvalho Chehab 		}
357786baecfSMauro Carvalho Chehab 		case(DW2102_VOLTAGE_CTRL): {
358786baecfSMauro Carvalho Chehab 			u8 obuf[2];
359786baecfSMauro Carvalho Chehab 			obuf[0] = 0x30;
360786baecfSMauro Carvalho Chehab 			obuf[1] = msg[0].buf[0];
361786baecfSMauro Carvalho Chehab 			dw210x_op_rw(d->udev, 0xb2, 0, 0,
362786baecfSMauro Carvalho Chehab 					obuf, 2, DW210X_WRITE_MSG);
363786baecfSMauro Carvalho Chehab 			break;
364786baecfSMauro Carvalho Chehab 		}
365786baecfSMauro Carvalho Chehab 		}
366786baecfSMauro Carvalho Chehab 
367786baecfSMauro Carvalho Chehab 		break;
368786baecfSMauro Carvalho Chehab 	}
369324ed533SDan Carpenter 	ret = num;
370786baecfSMauro Carvalho Chehab 
371324ed533SDan Carpenter unlock:
372786baecfSMauro Carvalho Chehab 	mutex_unlock(&d->i2c_mutex);
373324ed533SDan Carpenter 	return ret;
374786baecfSMauro Carvalho Chehab }
375786baecfSMauro Carvalho Chehab 
376786baecfSMauro Carvalho Chehab static int dw2104_i2c_transfer(struct i2c_adapter *adap, struct i2c_msg msg[], int num)
377786baecfSMauro Carvalho Chehab {
378786baecfSMauro Carvalho Chehab 	struct dvb_usb_device *d = i2c_get_adapdata(adap);
379324ed533SDan Carpenter 	int len, i, j, ret;
380786baecfSMauro Carvalho Chehab 
381786baecfSMauro Carvalho Chehab 	if (!d)
382786baecfSMauro Carvalho Chehab 		return -ENODEV;
383786baecfSMauro Carvalho Chehab 	if (mutex_lock_interruptible(&d->i2c_mutex) < 0)
384786baecfSMauro Carvalho Chehab 		return -EAGAIN;
385786baecfSMauro Carvalho Chehab 
386786baecfSMauro Carvalho Chehab 	for (j = 0; j < num; j++) {
387786baecfSMauro Carvalho Chehab 		switch (msg[j].addr) {
388786baecfSMauro Carvalho Chehab 		case(DW2102_RC_QUERY): {
389786baecfSMauro Carvalho Chehab 			u8 ibuf[2];
390786baecfSMauro Carvalho Chehab 			dw210x_op_rw(d->udev, 0xb8, 0, 0,
391786baecfSMauro Carvalho Chehab 					ibuf, 2, DW210X_READ_MSG);
392786baecfSMauro Carvalho Chehab 			memcpy(msg[j].buf, ibuf , 2);
393786baecfSMauro Carvalho Chehab 			break;
394786baecfSMauro Carvalho Chehab 		}
395786baecfSMauro Carvalho Chehab 		case(DW2102_VOLTAGE_CTRL): {
396786baecfSMauro Carvalho Chehab 			u8 obuf[2];
397786baecfSMauro Carvalho Chehab 			obuf[0] = 0x30;
398786baecfSMauro Carvalho Chehab 			obuf[1] = msg[j].buf[0];
399786baecfSMauro Carvalho Chehab 			dw210x_op_rw(d->udev, 0xb2, 0, 0,
400786baecfSMauro Carvalho Chehab 					obuf, 2, DW210X_WRITE_MSG);
401786baecfSMauro Carvalho Chehab 			break;
402786baecfSMauro Carvalho Chehab 		}
403786baecfSMauro Carvalho Chehab 		/*case 0x55: cx24116
404786baecfSMauro Carvalho Chehab 		case 0x6a: stv0903
405786baecfSMauro Carvalho Chehab 		case 0x68: ds3000, stv0903
406786baecfSMauro Carvalho Chehab 		case 0x60: ts2020, stv6110, stb6100 */
407786baecfSMauro Carvalho Chehab 		default: {
408786baecfSMauro Carvalho Chehab 			if (msg[j].flags == I2C_M_RD) {
409786baecfSMauro Carvalho Chehab 				/* read registers */
4100065a79aSMauro Carvalho Chehab 				u8  ibuf[MAX_XFER_SIZE];
4110065a79aSMauro Carvalho Chehab 
4120065a79aSMauro Carvalho Chehab 				if (2 + msg[j].len > sizeof(ibuf)) {
4130065a79aSMauro Carvalho Chehab 					warn("i2c rd: len=%d is too big!\n",
4140065a79aSMauro Carvalho Chehab 					     msg[j].len);
415324ed533SDan Carpenter 					ret = -EOPNOTSUPP;
416324ed533SDan Carpenter 					goto unlock;
4170065a79aSMauro Carvalho Chehab 				}
4180065a79aSMauro Carvalho Chehab 
419786baecfSMauro Carvalho Chehab 				dw210x_op_rw(d->udev, 0xc3,
420786baecfSMauro Carvalho Chehab 						(msg[j].addr << 1) + 1, 0,
421786baecfSMauro Carvalho Chehab 						ibuf, msg[j].len + 2,
422786baecfSMauro Carvalho Chehab 						DW210X_READ_MSG);
423786baecfSMauro Carvalho Chehab 				memcpy(msg[j].buf, ibuf + 2, msg[j].len);
424786baecfSMauro Carvalho Chehab 				mdelay(10);
425786baecfSMauro Carvalho Chehab 			} else if (((msg[j].buf[0] == 0xb0) &&
426786baecfSMauro Carvalho Chehab 						(msg[j].addr == 0x68)) ||
427786baecfSMauro Carvalho Chehab 						((msg[j].buf[0] == 0xf7) &&
428786baecfSMauro Carvalho Chehab 						(msg[j].addr == 0x55))) {
429786baecfSMauro Carvalho Chehab 				/* write firmware */
430786baecfSMauro Carvalho Chehab 				u8 obuf[19];
431786baecfSMauro Carvalho Chehab 				obuf[0] = msg[j].addr << 1;
432786baecfSMauro Carvalho Chehab 				obuf[1] = (msg[j].len > 15 ? 17 : msg[j].len);
433786baecfSMauro Carvalho Chehab 				obuf[2] = msg[j].buf[0];
434786baecfSMauro Carvalho Chehab 				len = msg[j].len - 1;
435786baecfSMauro Carvalho Chehab 				i = 1;
436786baecfSMauro Carvalho Chehab 				do {
437786baecfSMauro Carvalho Chehab 					memcpy(obuf + 3, msg[j].buf + i,
438786baecfSMauro Carvalho Chehab 							(len > 16 ? 16 : len));
439786baecfSMauro Carvalho Chehab 					dw210x_op_rw(d->udev, 0xc2, 0, 0,
440786baecfSMauro Carvalho Chehab 						obuf, (len > 16 ? 16 : len) + 3,
441786baecfSMauro Carvalho Chehab 						DW210X_WRITE_MSG);
442786baecfSMauro Carvalho Chehab 					i += 16;
443786baecfSMauro Carvalho Chehab 					len -= 16;
444786baecfSMauro Carvalho Chehab 				} while (len > 0);
445786baecfSMauro Carvalho Chehab 			} else {
446786baecfSMauro Carvalho Chehab 				/* write registers */
4470065a79aSMauro Carvalho Chehab 				u8 obuf[MAX_XFER_SIZE];
4480065a79aSMauro Carvalho Chehab 
4490065a79aSMauro Carvalho Chehab 				if (2 + msg[j].len > sizeof(obuf)) {
4500065a79aSMauro Carvalho Chehab 					warn("i2c wr: len=%d is too big!\n",
4510065a79aSMauro Carvalho Chehab 					     msg[j].len);
452324ed533SDan Carpenter 					ret = -EOPNOTSUPP;
453324ed533SDan Carpenter 					goto unlock;
4540065a79aSMauro Carvalho Chehab 				}
4550065a79aSMauro Carvalho Chehab 
456786baecfSMauro Carvalho Chehab 				obuf[0] = msg[j].addr << 1;
457786baecfSMauro Carvalho Chehab 				obuf[1] = msg[j].len;
458786baecfSMauro Carvalho Chehab 				memcpy(obuf + 2, msg[j].buf, msg[j].len);
459786baecfSMauro Carvalho Chehab 				dw210x_op_rw(d->udev, 0xc2, 0, 0,
460786baecfSMauro Carvalho Chehab 						obuf, msg[j].len + 2,
461786baecfSMauro Carvalho Chehab 						DW210X_WRITE_MSG);
462786baecfSMauro Carvalho Chehab 			}
463786baecfSMauro Carvalho Chehab 			break;
464786baecfSMauro Carvalho Chehab 		}
465786baecfSMauro Carvalho Chehab 		}
466786baecfSMauro Carvalho Chehab 
467786baecfSMauro Carvalho Chehab 	}
468324ed533SDan Carpenter 	ret = num;
469786baecfSMauro Carvalho Chehab 
470324ed533SDan Carpenter unlock:
471786baecfSMauro Carvalho Chehab 	mutex_unlock(&d->i2c_mutex);
472324ed533SDan Carpenter 	return ret;
473786baecfSMauro Carvalho Chehab }
474786baecfSMauro Carvalho Chehab 
475786baecfSMauro Carvalho Chehab static int dw3101_i2c_transfer(struct i2c_adapter *adap, struct i2c_msg msg[],
476786baecfSMauro Carvalho Chehab 								int num)
477786baecfSMauro Carvalho Chehab {
478786baecfSMauro Carvalho Chehab 	struct dvb_usb_device *d = i2c_get_adapdata(adap);
479324ed533SDan Carpenter 	int ret;
480786baecfSMauro Carvalho Chehab 	int i;
481786baecfSMauro Carvalho Chehab 
482786baecfSMauro Carvalho Chehab 	if (!d)
483786baecfSMauro Carvalho Chehab 		return -ENODEV;
484786baecfSMauro Carvalho Chehab 	if (mutex_lock_interruptible(&d->i2c_mutex) < 0)
485786baecfSMauro Carvalho Chehab 		return -EAGAIN;
486786baecfSMauro Carvalho Chehab 
487786baecfSMauro Carvalho Chehab 	switch (num) {
488786baecfSMauro Carvalho Chehab 	case 2: {
489786baecfSMauro Carvalho Chehab 		/* read */
490786baecfSMauro Carvalho Chehab 		/* first write first register number */
4910065a79aSMauro Carvalho Chehab 		u8 ibuf[MAX_XFER_SIZE], obuf[3];
4920065a79aSMauro Carvalho Chehab 
493950e252cSAlyssa Milburn 		if (2 + msg[0].len != sizeof(obuf)) {
494950e252cSAlyssa Milburn 			warn("i2c rd: len=%d is not 1!\n",
495950e252cSAlyssa Milburn 			     msg[0].len);
496950e252cSAlyssa Milburn 			ret = -EOPNOTSUPP;
497950e252cSAlyssa Milburn 			goto unlock;
498950e252cSAlyssa Milburn 		}
4990065a79aSMauro Carvalho Chehab 		if (2 + msg[1].len > sizeof(ibuf)) {
5000065a79aSMauro Carvalho Chehab 			warn("i2c rd: len=%d is too big!\n",
5010065a79aSMauro Carvalho Chehab 			     msg[1].len);
502324ed533SDan Carpenter 			ret = -EOPNOTSUPP;
503324ed533SDan Carpenter 			goto unlock;
5040065a79aSMauro Carvalho Chehab 		}
505786baecfSMauro Carvalho Chehab 		obuf[0] = msg[0].addr << 1;
506786baecfSMauro Carvalho Chehab 		obuf[1] = msg[0].len;
507786baecfSMauro Carvalho Chehab 		obuf[2] = msg[0].buf[0];
508786baecfSMauro Carvalho Chehab 		dw210x_op_rw(d->udev, 0xc2, 0, 0,
509786baecfSMauro Carvalho Chehab 				obuf, msg[0].len + 2, DW210X_WRITE_MSG);
510786baecfSMauro Carvalho Chehab 		/* second read registers */
511786baecfSMauro Carvalho Chehab 		dw210x_op_rw(d->udev, 0xc3, 0x19 , 0,
512786baecfSMauro Carvalho Chehab 				ibuf, msg[1].len + 2, DW210X_READ_MSG);
513786baecfSMauro Carvalho Chehab 		memcpy(msg[1].buf, ibuf + 2, msg[1].len);
514786baecfSMauro Carvalho Chehab 
515786baecfSMauro Carvalho Chehab 		break;
516786baecfSMauro Carvalho Chehab 	}
517786baecfSMauro Carvalho Chehab 	case 1:
518786baecfSMauro Carvalho Chehab 		switch (msg[0].addr) {
519786baecfSMauro Carvalho Chehab 		case 0x60:
520786baecfSMauro Carvalho Chehab 		case 0x0c: {
521786baecfSMauro Carvalho Chehab 			/* write to register */
5220065a79aSMauro Carvalho Chehab 			u8 obuf[MAX_XFER_SIZE];
5230065a79aSMauro Carvalho Chehab 
5240065a79aSMauro Carvalho Chehab 			if (2 + msg[0].len > sizeof(obuf)) {
5250065a79aSMauro Carvalho Chehab 				warn("i2c wr: len=%d is too big!\n",
5260065a79aSMauro Carvalho Chehab 				     msg[0].len);
527324ed533SDan Carpenter 				ret = -EOPNOTSUPP;
528324ed533SDan Carpenter 				goto unlock;
5290065a79aSMauro Carvalho Chehab 			}
530786baecfSMauro Carvalho Chehab 			obuf[0] = msg[0].addr << 1;
531786baecfSMauro Carvalho Chehab 			obuf[1] = msg[0].len;
532786baecfSMauro Carvalho Chehab 			memcpy(obuf + 2, msg[0].buf, msg[0].len);
533786baecfSMauro Carvalho Chehab 			dw210x_op_rw(d->udev, 0xc2, 0, 0,
534786baecfSMauro Carvalho Chehab 					obuf, msg[0].len + 2, DW210X_WRITE_MSG);
535786baecfSMauro Carvalho Chehab 			break;
536786baecfSMauro Carvalho Chehab 		}
537786baecfSMauro Carvalho Chehab 		case(DW2102_RC_QUERY): {
538786baecfSMauro Carvalho Chehab 			u8 ibuf[2];
539786baecfSMauro Carvalho Chehab 			dw210x_op_rw(d->udev, 0xb8, 0, 0,
540786baecfSMauro Carvalho Chehab 					ibuf, 2, DW210X_READ_MSG);
541786baecfSMauro Carvalho Chehab 			memcpy(msg[0].buf, ibuf , 2);
542786baecfSMauro Carvalho Chehab 			break;
543786baecfSMauro Carvalho Chehab 		}
544786baecfSMauro Carvalho Chehab 		}
545786baecfSMauro Carvalho Chehab 
546786baecfSMauro Carvalho Chehab 		break;
547786baecfSMauro Carvalho Chehab 	}
548786baecfSMauro Carvalho Chehab 
549786baecfSMauro Carvalho Chehab 	for (i = 0; i < num; i++) {
550786baecfSMauro Carvalho Chehab 		deb_xfer("%02x:%02x: %s ", i, msg[i].addr,
551786baecfSMauro Carvalho Chehab 				msg[i].flags == 0 ? ">>>" : "<<<");
552786baecfSMauro Carvalho Chehab 		debug_dump(msg[i].buf, msg[i].len, deb_xfer);
553786baecfSMauro Carvalho Chehab 	}
554324ed533SDan Carpenter 	ret = num;
555786baecfSMauro Carvalho Chehab 
556324ed533SDan Carpenter unlock:
557786baecfSMauro Carvalho Chehab 	mutex_unlock(&d->i2c_mutex);
558324ed533SDan Carpenter 	return ret;
559786baecfSMauro Carvalho Chehab }
560786baecfSMauro Carvalho Chehab 
561786baecfSMauro Carvalho Chehab static int s6x0_i2c_transfer(struct i2c_adapter *adap, struct i2c_msg msg[],
562786baecfSMauro Carvalho Chehab 								int num)
563786baecfSMauro Carvalho Chehab {
564786baecfSMauro Carvalho Chehab 	struct dvb_usb_device *d = i2c_get_adapdata(adap);
565786baecfSMauro Carvalho Chehab 	struct usb_device *udev;
566324ed533SDan Carpenter 	int len, i, j, ret;
567786baecfSMauro Carvalho Chehab 
568786baecfSMauro Carvalho Chehab 	if (!d)
569786baecfSMauro Carvalho Chehab 		return -ENODEV;
570786baecfSMauro Carvalho Chehab 	udev = d->udev;
571786baecfSMauro Carvalho Chehab 	if (mutex_lock_interruptible(&d->i2c_mutex) < 0)
572786baecfSMauro Carvalho Chehab 		return -EAGAIN;
573786baecfSMauro Carvalho Chehab 
574786baecfSMauro Carvalho Chehab 	for (j = 0; j < num; j++) {
575786baecfSMauro Carvalho Chehab 		switch (msg[j].addr) {
576786baecfSMauro Carvalho Chehab 		case (DW2102_RC_QUERY): {
577786baecfSMauro Carvalho Chehab 			u8 ibuf[5];
578786baecfSMauro Carvalho Chehab 			dw210x_op_rw(d->udev, 0xb8, 0, 0,
579786baecfSMauro Carvalho Chehab 					ibuf, 5, DW210X_READ_MSG);
580786baecfSMauro Carvalho Chehab 			memcpy(msg[j].buf, ibuf + 3, 2);
581786baecfSMauro Carvalho Chehab 			break;
582786baecfSMauro Carvalho Chehab 		}
583786baecfSMauro Carvalho Chehab 		case (DW2102_VOLTAGE_CTRL): {
584786baecfSMauro Carvalho Chehab 			u8 obuf[2];
585786baecfSMauro Carvalho Chehab 
586786baecfSMauro Carvalho Chehab 			obuf[0] = 1;
587786baecfSMauro Carvalho Chehab 			obuf[1] = msg[j].buf[1];/* off-on */
588786baecfSMauro Carvalho Chehab 			dw210x_op_rw(d->udev, 0x8a, 0, 0,
589786baecfSMauro Carvalho Chehab 					obuf, 2, DW210X_WRITE_MSG);
590786baecfSMauro Carvalho Chehab 			obuf[0] = 3;
591786baecfSMauro Carvalho Chehab 			obuf[1] = msg[j].buf[0];/* 13v-18v */
592786baecfSMauro Carvalho Chehab 			dw210x_op_rw(d->udev, 0x8a, 0, 0,
593786baecfSMauro Carvalho Chehab 					obuf, 2, DW210X_WRITE_MSG);
594786baecfSMauro Carvalho Chehab 			break;
595786baecfSMauro Carvalho Chehab 		}
596786baecfSMauro Carvalho Chehab 		case (DW2102_LED_CTRL): {
597786baecfSMauro Carvalho Chehab 			u8 obuf[2];
598786baecfSMauro Carvalho Chehab 
599786baecfSMauro Carvalho Chehab 			obuf[0] = 5;
600786baecfSMauro Carvalho Chehab 			obuf[1] = msg[j].buf[0];
601786baecfSMauro Carvalho Chehab 			dw210x_op_rw(d->udev, 0x8a, 0, 0,
602786baecfSMauro Carvalho Chehab 					obuf, 2, DW210X_WRITE_MSG);
603786baecfSMauro Carvalho Chehab 			break;
604786baecfSMauro Carvalho Chehab 		}
605786baecfSMauro Carvalho Chehab 		/*case 0x55: cx24116
606786baecfSMauro Carvalho Chehab 		case 0x6a: stv0903
607955d00acSIgor M. Liplianin 		case 0x68: ds3000, stv0903, rs2000
608786baecfSMauro Carvalho Chehab 		case 0x60: ts2020, stv6110, stb6100
609786baecfSMauro Carvalho Chehab 		case 0xa0: eeprom */
610786baecfSMauro Carvalho Chehab 		default: {
611786baecfSMauro Carvalho Chehab 			if (msg[j].flags == I2C_M_RD) {
612786baecfSMauro Carvalho Chehab 				/* read registers */
6130065a79aSMauro Carvalho Chehab 				u8 ibuf[MAX_XFER_SIZE];
6140065a79aSMauro Carvalho Chehab 
6150065a79aSMauro Carvalho Chehab 				if (msg[j].len > sizeof(ibuf)) {
6160065a79aSMauro Carvalho Chehab 					warn("i2c rd: len=%d is too big!\n",
6170065a79aSMauro Carvalho Chehab 					     msg[j].len);
618324ed533SDan Carpenter 					ret = -EOPNOTSUPP;
619324ed533SDan Carpenter 					goto unlock;
6200065a79aSMauro Carvalho Chehab 				}
6210065a79aSMauro Carvalho Chehab 
622786baecfSMauro Carvalho Chehab 				dw210x_op_rw(d->udev, 0x91, 0, 0,
623786baecfSMauro Carvalho Chehab 						ibuf, msg[j].len,
624786baecfSMauro Carvalho Chehab 						DW210X_READ_MSG);
625786baecfSMauro Carvalho Chehab 				memcpy(msg[j].buf, ibuf, msg[j].len);
626786baecfSMauro Carvalho Chehab 				break;
627786baecfSMauro Carvalho Chehab 			} else if ((msg[j].buf[0] == 0xb0) &&
628786baecfSMauro Carvalho Chehab 						(msg[j].addr == 0x68)) {
629786baecfSMauro Carvalho Chehab 				/* write firmware */
630786baecfSMauro Carvalho Chehab 				u8 obuf[19];
631786baecfSMauro Carvalho Chehab 				obuf[0] = (msg[j].len > 16 ?
632786baecfSMauro Carvalho Chehab 						18 : msg[j].len + 1);
633786baecfSMauro Carvalho Chehab 				obuf[1] = msg[j].addr << 1;
634786baecfSMauro Carvalho Chehab 				obuf[2] = msg[j].buf[0];
635786baecfSMauro Carvalho Chehab 				len = msg[j].len - 1;
636786baecfSMauro Carvalho Chehab 				i = 1;
637786baecfSMauro Carvalho Chehab 				do {
638786baecfSMauro Carvalho Chehab 					memcpy(obuf + 3, msg[j].buf + i,
639786baecfSMauro Carvalho Chehab 							(len > 16 ? 16 : len));
640786baecfSMauro Carvalho Chehab 					dw210x_op_rw(d->udev, 0x80, 0, 0,
641786baecfSMauro Carvalho Chehab 						obuf, (len > 16 ? 16 : len) + 3,
642786baecfSMauro Carvalho Chehab 						DW210X_WRITE_MSG);
643786baecfSMauro Carvalho Chehab 					i += 16;
644786baecfSMauro Carvalho Chehab 					len -= 16;
645786baecfSMauro Carvalho Chehab 				} while (len > 0);
646786baecfSMauro Carvalho Chehab 			} else if (j < (num - 1)) {
647786baecfSMauro Carvalho Chehab 				/* write register addr before read */
6480065a79aSMauro Carvalho Chehab 				u8 obuf[MAX_XFER_SIZE];
6490065a79aSMauro Carvalho Chehab 
6500065a79aSMauro Carvalho Chehab 				if (2 + msg[j].len > sizeof(obuf)) {
6510065a79aSMauro Carvalho Chehab 					warn("i2c wr: len=%d is too big!\n",
6520065a79aSMauro Carvalho Chehab 					     msg[j].len);
653324ed533SDan Carpenter 					ret = -EOPNOTSUPP;
654324ed533SDan Carpenter 					goto unlock;
6550065a79aSMauro Carvalho Chehab 				}
6560065a79aSMauro Carvalho Chehab 
657786baecfSMauro Carvalho Chehab 				obuf[0] = msg[j + 1].len;
658786baecfSMauro Carvalho Chehab 				obuf[1] = (msg[j].addr << 1);
659786baecfSMauro Carvalho Chehab 				memcpy(obuf + 2, msg[j].buf, msg[j].len);
660786baecfSMauro Carvalho Chehab 				dw210x_op_rw(d->udev,
6611ad5d064SHans Verkuil 						le16_to_cpu(udev->descriptor.idProduct) ==
662786baecfSMauro Carvalho Chehab 						0x7500 ? 0x92 : 0x90, 0, 0,
663786baecfSMauro Carvalho Chehab 						obuf, msg[j].len + 2,
664786baecfSMauro Carvalho Chehab 						DW210X_WRITE_MSG);
665786baecfSMauro Carvalho Chehab 				break;
666786baecfSMauro Carvalho Chehab 			} else {
667786baecfSMauro Carvalho Chehab 				/* write registers */
6680065a79aSMauro Carvalho Chehab 				u8 obuf[MAX_XFER_SIZE];
6690065a79aSMauro Carvalho Chehab 
6700065a79aSMauro Carvalho Chehab 				if (2 + msg[j].len > sizeof(obuf)) {
6710065a79aSMauro Carvalho Chehab 					warn("i2c wr: len=%d is too big!\n",
6720065a79aSMauro Carvalho Chehab 					     msg[j].len);
673324ed533SDan Carpenter 					ret = -EOPNOTSUPP;
674324ed533SDan Carpenter 					goto unlock;
6750065a79aSMauro Carvalho Chehab 				}
676786baecfSMauro Carvalho Chehab 				obuf[0] = msg[j].len + 1;
677786baecfSMauro Carvalho Chehab 				obuf[1] = (msg[j].addr << 1);
678786baecfSMauro Carvalho Chehab 				memcpy(obuf + 2, msg[j].buf, msg[j].len);
679786baecfSMauro Carvalho Chehab 				dw210x_op_rw(d->udev, 0x80, 0, 0,
680786baecfSMauro Carvalho Chehab 						obuf, msg[j].len + 2,
681786baecfSMauro Carvalho Chehab 						DW210X_WRITE_MSG);
682786baecfSMauro Carvalho Chehab 				break;
683786baecfSMauro Carvalho Chehab 			}
684786baecfSMauro Carvalho Chehab 			break;
685786baecfSMauro Carvalho Chehab 		}
686786baecfSMauro Carvalho Chehab 		}
687786baecfSMauro Carvalho Chehab 	}
688324ed533SDan Carpenter 	ret = num;
689786baecfSMauro Carvalho Chehab 
690324ed533SDan Carpenter unlock:
691786baecfSMauro Carvalho Chehab 	mutex_unlock(&d->i2c_mutex);
692324ed533SDan Carpenter 	return ret;
693786baecfSMauro Carvalho Chehab }
694786baecfSMauro Carvalho Chehab 
695786baecfSMauro Carvalho Chehab static int su3000_i2c_transfer(struct i2c_adapter *adap, struct i2c_msg msg[],
696786baecfSMauro Carvalho Chehab 								int num)
697786baecfSMauro Carvalho Chehab {
698786baecfSMauro Carvalho Chehab 	struct dvb_usb_device *d = i2c_get_adapdata(adap);
699606142afSJonathan McDowell 	struct dw2102_state *state;
700786baecfSMauro Carvalho Chehab 
701786baecfSMauro Carvalho Chehab 	if (!d)
702786baecfSMauro Carvalho Chehab 		return -ENODEV;
703606142afSJonathan McDowell 
704606142afSJonathan McDowell 	state = d->priv;
705606142afSJonathan McDowell 
706786baecfSMauro Carvalho Chehab 	if (mutex_lock_interruptible(&d->i2c_mutex) < 0)
707786baecfSMauro Carvalho Chehab 		return -EAGAIN;
708606142afSJonathan McDowell 	if (mutex_lock_interruptible(&d->data_mutex) < 0) {
709606142afSJonathan McDowell 		mutex_unlock(&d->i2c_mutex);
710606142afSJonathan McDowell 		return -EAGAIN;
711606142afSJonathan McDowell 	}
712786baecfSMauro Carvalho Chehab 
713786baecfSMauro Carvalho Chehab 	switch (num) {
714786baecfSMauro Carvalho Chehab 	case 1:
715786baecfSMauro Carvalho Chehab 		switch (msg[0].addr) {
716786baecfSMauro Carvalho Chehab 		case SU3000_STREAM_CTRL:
717606142afSJonathan McDowell 			state->data[0] = msg[0].buf[0] + 0x36;
718606142afSJonathan McDowell 			state->data[1] = 3;
719606142afSJonathan McDowell 			state->data[2] = 0;
720606142afSJonathan McDowell 			if (dvb_usb_generic_rw(d, state->data, 3,
721606142afSJonathan McDowell 					state->data, 0, 0) < 0)
722786baecfSMauro Carvalho Chehab 				err("i2c transfer failed.");
723786baecfSMauro Carvalho Chehab 			break;
724786baecfSMauro Carvalho Chehab 		case DW2102_RC_QUERY:
725606142afSJonathan McDowell 			state->data[0] = 0x10;
726606142afSJonathan McDowell 			if (dvb_usb_generic_rw(d, state->data, 1,
727606142afSJonathan McDowell 					state->data, 2, 0) < 0)
728786baecfSMauro Carvalho Chehab 				err("i2c transfer failed.");
729606142afSJonathan McDowell 			msg[0].buf[1] = state->data[0];
730606142afSJonathan McDowell 			msg[0].buf[0] = state->data[1];
731786baecfSMauro Carvalho Chehab 			break;
732786baecfSMauro Carvalho Chehab 		default:
733950e252cSAlyssa Milburn 			if (3 + msg[0].len > sizeof(state->data)) {
734950e252cSAlyssa Milburn 				warn("i2c wr: len=%d is too big!\n",
735950e252cSAlyssa Milburn 				     msg[0].len);
736950e252cSAlyssa Milburn 				num = -EOPNOTSUPP;
737950e252cSAlyssa Milburn 				break;
738950e252cSAlyssa Milburn 			}
739950e252cSAlyssa Milburn 
740786baecfSMauro Carvalho Chehab 			/* always i2c write*/
741606142afSJonathan McDowell 			state->data[0] = 0x08;
742606142afSJonathan McDowell 			state->data[1] = msg[0].addr;
743606142afSJonathan McDowell 			state->data[2] = msg[0].len;
744786baecfSMauro Carvalho Chehab 
745606142afSJonathan McDowell 			memcpy(&state->data[3], msg[0].buf, msg[0].len);
746786baecfSMauro Carvalho Chehab 
747606142afSJonathan McDowell 			if (dvb_usb_generic_rw(d, state->data, msg[0].len + 3,
748606142afSJonathan McDowell 						state->data, 1, 0) < 0)
749786baecfSMauro Carvalho Chehab 				err("i2c transfer failed.");
750786baecfSMauro Carvalho Chehab 
751786baecfSMauro Carvalho Chehab 		}
752786baecfSMauro Carvalho Chehab 		break;
753786baecfSMauro Carvalho Chehab 	case 2:
754786baecfSMauro Carvalho Chehab 		/* always i2c read */
755950e252cSAlyssa Milburn 		if (4 + msg[0].len > sizeof(state->data)) {
756950e252cSAlyssa Milburn 			warn("i2c rd: len=%d is too big!\n",
757950e252cSAlyssa Milburn 			     msg[0].len);
758950e252cSAlyssa Milburn 			num = -EOPNOTSUPP;
759950e252cSAlyssa Milburn 			break;
760950e252cSAlyssa Milburn 		}
761950e252cSAlyssa Milburn 		if (1 + msg[1].len > sizeof(state->data)) {
762950e252cSAlyssa Milburn 			warn("i2c rd: len=%d is too big!\n",
763950e252cSAlyssa Milburn 			     msg[1].len);
764950e252cSAlyssa Milburn 			num = -EOPNOTSUPP;
765950e252cSAlyssa Milburn 			break;
766950e252cSAlyssa Milburn 		}
767950e252cSAlyssa Milburn 
768606142afSJonathan McDowell 		state->data[0] = 0x09;
769606142afSJonathan McDowell 		state->data[1] = msg[0].len;
770606142afSJonathan McDowell 		state->data[2] = msg[1].len;
771606142afSJonathan McDowell 		state->data[3] = msg[0].addr;
772606142afSJonathan McDowell 		memcpy(&state->data[4], msg[0].buf, msg[0].len);
773786baecfSMauro Carvalho Chehab 
774606142afSJonathan McDowell 		if (dvb_usb_generic_rw(d, state->data, msg[0].len + 4,
775606142afSJonathan McDowell 					state->data, msg[1].len + 1, 0) < 0)
776786baecfSMauro Carvalho Chehab 			err("i2c transfer failed.");
777786baecfSMauro Carvalho Chehab 
778606142afSJonathan McDowell 		memcpy(msg[1].buf, &state->data[1], msg[1].len);
779786baecfSMauro Carvalho Chehab 		break;
780786baecfSMauro Carvalho Chehab 	default:
781786baecfSMauro Carvalho Chehab 		warn("more than 2 i2c messages at a time is not handled yet.");
782786baecfSMauro Carvalho Chehab 		break;
783786baecfSMauro Carvalho Chehab 	}
784606142afSJonathan McDowell 	mutex_unlock(&d->data_mutex);
785786baecfSMauro Carvalho Chehab 	mutex_unlock(&d->i2c_mutex);
786786baecfSMauro Carvalho Chehab 	return num;
787786baecfSMauro Carvalho Chehab }
788786baecfSMauro Carvalho Chehab 
789786baecfSMauro Carvalho Chehab static u32 dw210x_i2c_func(struct i2c_adapter *adapter)
790786baecfSMauro Carvalho Chehab {
791786baecfSMauro Carvalho Chehab 	return I2C_FUNC_I2C;
792786baecfSMauro Carvalho Chehab }
793786baecfSMauro Carvalho Chehab 
794786baecfSMauro Carvalho Chehab static struct i2c_algorithm dw2102_i2c_algo = {
795786baecfSMauro Carvalho Chehab 	.master_xfer = dw2102_i2c_transfer,
796786baecfSMauro Carvalho Chehab 	.functionality = dw210x_i2c_func,
797786baecfSMauro Carvalho Chehab };
798786baecfSMauro Carvalho Chehab 
799786baecfSMauro Carvalho Chehab static struct i2c_algorithm dw2102_serit_i2c_algo = {
800786baecfSMauro Carvalho Chehab 	.master_xfer = dw2102_serit_i2c_transfer,
801786baecfSMauro Carvalho Chehab 	.functionality = dw210x_i2c_func,
802786baecfSMauro Carvalho Chehab };
803786baecfSMauro Carvalho Chehab 
804786baecfSMauro Carvalho Chehab static struct i2c_algorithm dw2102_earda_i2c_algo = {
805786baecfSMauro Carvalho Chehab 	.master_xfer = dw2102_earda_i2c_transfer,
806786baecfSMauro Carvalho Chehab 	.functionality = dw210x_i2c_func,
807786baecfSMauro Carvalho Chehab };
808786baecfSMauro Carvalho Chehab 
809786baecfSMauro Carvalho Chehab static struct i2c_algorithm dw2104_i2c_algo = {
810786baecfSMauro Carvalho Chehab 	.master_xfer = dw2104_i2c_transfer,
811786baecfSMauro Carvalho Chehab 	.functionality = dw210x_i2c_func,
812786baecfSMauro Carvalho Chehab };
813786baecfSMauro Carvalho Chehab 
814786baecfSMauro Carvalho Chehab static struct i2c_algorithm dw3101_i2c_algo = {
815786baecfSMauro Carvalho Chehab 	.master_xfer = dw3101_i2c_transfer,
816786baecfSMauro Carvalho Chehab 	.functionality = dw210x_i2c_func,
817786baecfSMauro Carvalho Chehab };
818786baecfSMauro Carvalho Chehab 
819786baecfSMauro Carvalho Chehab static struct i2c_algorithm s6x0_i2c_algo = {
820786baecfSMauro Carvalho Chehab 	.master_xfer = s6x0_i2c_transfer,
821786baecfSMauro Carvalho Chehab 	.functionality = dw210x_i2c_func,
822786baecfSMauro Carvalho Chehab };
823786baecfSMauro Carvalho Chehab 
824786baecfSMauro Carvalho Chehab static struct i2c_algorithm su3000_i2c_algo = {
825786baecfSMauro Carvalho Chehab 	.master_xfer = su3000_i2c_transfer,
826786baecfSMauro Carvalho Chehab 	.functionality = dw210x_i2c_func,
827786baecfSMauro Carvalho Chehab };
828786baecfSMauro Carvalho Chehab 
829786baecfSMauro Carvalho Chehab static int dw210x_read_mac_address(struct dvb_usb_device *d, u8 mac[6])
830786baecfSMauro Carvalho Chehab {
831786baecfSMauro Carvalho Chehab 	int i;
832786baecfSMauro Carvalho Chehab 	u8 ibuf[] = {0, 0};
833786baecfSMauro Carvalho Chehab 	u8 eeprom[256], eepromline[16];
834786baecfSMauro Carvalho Chehab 
835786baecfSMauro Carvalho Chehab 	for (i = 0; i < 256; i++) {
836786baecfSMauro Carvalho Chehab 		if (dw210x_op_rw(d->udev, 0xb6, 0xa0 , i, ibuf, 2, DW210X_READ_MSG) < 0) {
837786baecfSMauro Carvalho Chehab 			err("read eeprom failed.");
838786baecfSMauro Carvalho Chehab 			return -1;
839786baecfSMauro Carvalho Chehab 		} else {
840786baecfSMauro Carvalho Chehab 			eepromline[i%16] = ibuf[0];
841786baecfSMauro Carvalho Chehab 			eeprom[i] = ibuf[0];
842786baecfSMauro Carvalho Chehab 		}
843786baecfSMauro Carvalho Chehab 		if ((i % 16) == 15) {
844786baecfSMauro Carvalho Chehab 			deb_xfer("%02x: ", i - 15);
845786baecfSMauro Carvalho Chehab 			debug_dump(eepromline, 16, deb_xfer);
846786baecfSMauro Carvalho Chehab 		}
847786baecfSMauro Carvalho Chehab 	}
848786baecfSMauro Carvalho Chehab 
849786baecfSMauro Carvalho Chehab 	memcpy(mac, eeprom + 8, 6);
850786baecfSMauro Carvalho Chehab 	return 0;
851786baecfSMauro Carvalho Chehab };
852786baecfSMauro Carvalho Chehab 
853786baecfSMauro Carvalho Chehab static int s6x0_read_mac_address(struct dvb_usb_device *d, u8 mac[6])
854786baecfSMauro Carvalho Chehab {
855786baecfSMauro Carvalho Chehab 	int i, ret;
856786baecfSMauro Carvalho Chehab 	u8 ibuf[] = { 0 }, obuf[] = { 0 };
857786baecfSMauro Carvalho Chehab 	u8 eeprom[256], eepromline[16];
858786baecfSMauro Carvalho Chehab 	struct i2c_msg msg[] = {
859786baecfSMauro Carvalho Chehab 		{
860786baecfSMauro Carvalho Chehab 			.addr = 0xa0 >> 1,
861786baecfSMauro Carvalho Chehab 			.flags = 0,
862786baecfSMauro Carvalho Chehab 			.buf = obuf,
863786baecfSMauro Carvalho Chehab 			.len = 1,
864786baecfSMauro Carvalho Chehab 		}, {
865786baecfSMauro Carvalho Chehab 			.addr = 0xa0 >> 1,
866786baecfSMauro Carvalho Chehab 			.flags = I2C_M_RD,
867786baecfSMauro Carvalho Chehab 			.buf = ibuf,
868786baecfSMauro Carvalho Chehab 			.len = 1,
869786baecfSMauro Carvalho Chehab 		}
870786baecfSMauro Carvalho Chehab 	};
871786baecfSMauro Carvalho Chehab 
872786baecfSMauro Carvalho Chehab 	for (i = 0; i < 256; i++) {
873786baecfSMauro Carvalho Chehab 		obuf[0] = i;
874786baecfSMauro Carvalho Chehab 		ret = s6x0_i2c_transfer(&d->i2c_adap, msg, 2);
875786baecfSMauro Carvalho Chehab 		if (ret != 2) {
876786baecfSMauro Carvalho Chehab 			err("read eeprom failed.");
877786baecfSMauro Carvalho Chehab 			return -1;
878786baecfSMauro Carvalho Chehab 		} else {
879786baecfSMauro Carvalho Chehab 			eepromline[i % 16] = ibuf[0];
880786baecfSMauro Carvalho Chehab 			eeprom[i] = ibuf[0];
881786baecfSMauro Carvalho Chehab 		}
882786baecfSMauro Carvalho Chehab 
883786baecfSMauro Carvalho Chehab 		if ((i % 16) == 15) {
884786baecfSMauro Carvalho Chehab 			deb_xfer("%02x: ", i - 15);
885786baecfSMauro Carvalho Chehab 			debug_dump(eepromline, 16, deb_xfer);
886786baecfSMauro Carvalho Chehab 		}
887786baecfSMauro Carvalho Chehab 	}
888786baecfSMauro Carvalho Chehab 
889786baecfSMauro Carvalho Chehab 	memcpy(mac, eeprom + 16, 6);
890786baecfSMauro Carvalho Chehab 	return 0;
891786baecfSMauro Carvalho Chehab };
892786baecfSMauro Carvalho Chehab 
893786baecfSMauro Carvalho Chehab static int su3000_streaming_ctrl(struct dvb_usb_adapter *adap, int onoff)
894786baecfSMauro Carvalho Chehab {
895786baecfSMauro Carvalho Chehab 	static u8 command_start[] = {0x00};
896786baecfSMauro Carvalho Chehab 	static u8 command_stop[] = {0x01};
897786baecfSMauro Carvalho Chehab 	struct i2c_msg msg = {
898786baecfSMauro Carvalho Chehab 		.addr = SU3000_STREAM_CTRL,
899786baecfSMauro Carvalho Chehab 		.flags = 0,
900786baecfSMauro Carvalho Chehab 		.buf = onoff ? command_start : command_stop,
901786baecfSMauro Carvalho Chehab 		.len = 1
902786baecfSMauro Carvalho Chehab 	};
903786baecfSMauro Carvalho Chehab 
904786baecfSMauro Carvalho Chehab 	i2c_transfer(&adap->dev->i2c_adap, &msg, 1);
905786baecfSMauro Carvalho Chehab 
906786baecfSMauro Carvalho Chehab 	return 0;
907786baecfSMauro Carvalho Chehab }
908786baecfSMauro Carvalho Chehab 
909786baecfSMauro Carvalho Chehab static int su3000_power_ctrl(struct dvb_usb_device *d, int i)
910786baecfSMauro Carvalho Chehab {
9112c4ffe27SOlli Salonen 	struct dw2102_state *state = (struct dw2102_state *)d->priv;
912606142afSJonathan McDowell 	int ret = 0;
913786baecfSMauro Carvalho Chehab 
9140385443fSJonathan McDowell 	info("%s: %d, initialized %d", __func__, i, state->initialized);
915786baecfSMauro Carvalho Chehab 
916786baecfSMauro Carvalho Chehab 	if (i && !state->initialized) {
917606142afSJonathan McDowell 		mutex_lock(&d->data_mutex);
918606142afSJonathan McDowell 
919606142afSJonathan McDowell 		state->data[0] = 0xde;
920606142afSJonathan McDowell 		state->data[1] = 0;
921606142afSJonathan McDowell 
922786baecfSMauro Carvalho Chehab 		state->initialized = 1;
923786baecfSMauro Carvalho Chehab 		/* reset board */
924606142afSJonathan McDowell 		ret = dvb_usb_generic_rw(d, state->data, 2, NULL, 0, 0);
925606142afSJonathan McDowell 		mutex_unlock(&d->data_mutex);
926786baecfSMauro Carvalho Chehab 	}
927786baecfSMauro Carvalho Chehab 
928606142afSJonathan McDowell 	return ret;
929786baecfSMauro Carvalho Chehab }
930786baecfSMauro Carvalho Chehab 
931786baecfSMauro Carvalho Chehab static int su3000_read_mac_address(struct dvb_usb_device *d, u8 mac[6])
932786baecfSMauro Carvalho Chehab {
933786baecfSMauro Carvalho Chehab 	int i;
934786baecfSMauro Carvalho Chehab 	u8 obuf[] = { 0x1f, 0xf0 };
935786baecfSMauro Carvalho Chehab 	u8 ibuf[] = { 0 };
936786baecfSMauro Carvalho Chehab 	struct i2c_msg msg[] = {
937786baecfSMauro Carvalho Chehab 		{
938786baecfSMauro Carvalho Chehab 			.addr = 0x51,
939786baecfSMauro Carvalho Chehab 			.flags = 0,
940786baecfSMauro Carvalho Chehab 			.buf = obuf,
941786baecfSMauro Carvalho Chehab 			.len = 2,
942786baecfSMauro Carvalho Chehab 		}, {
943786baecfSMauro Carvalho Chehab 			.addr = 0x51,
944786baecfSMauro Carvalho Chehab 			.flags = I2C_M_RD,
945786baecfSMauro Carvalho Chehab 			.buf = ibuf,
946786baecfSMauro Carvalho Chehab 			.len = 1,
947786baecfSMauro Carvalho Chehab 
948786baecfSMauro Carvalho Chehab 		}
949786baecfSMauro Carvalho Chehab 	};
950786baecfSMauro Carvalho Chehab 
951786baecfSMauro Carvalho Chehab 	for (i = 0; i < 6; i++) {
952786baecfSMauro Carvalho Chehab 		obuf[1] = 0xf0 + i;
953786baecfSMauro Carvalho Chehab 		if (i2c_transfer(&d->i2c_adap, msg, 2) != 2)
954786baecfSMauro Carvalho Chehab 			break;
955786baecfSMauro Carvalho Chehab 		else
956786baecfSMauro Carvalho Chehab 			mac[i] = ibuf[0];
957786baecfSMauro Carvalho Chehab 	}
958786baecfSMauro Carvalho Chehab 
959786baecfSMauro Carvalho Chehab 	return 0;
960786baecfSMauro Carvalho Chehab }
961786baecfSMauro Carvalho Chehab 
962786baecfSMauro Carvalho Chehab static int su3000_identify_state(struct usb_device *udev,
963786baecfSMauro Carvalho Chehab 				 struct dvb_usb_device_properties *props,
964786baecfSMauro Carvalho Chehab 				 struct dvb_usb_device_description **desc,
965786baecfSMauro Carvalho Chehab 				 int *cold)
966786baecfSMauro Carvalho Chehab {
9670385443fSJonathan McDowell 	info("%s", __func__);
968786baecfSMauro Carvalho Chehab 
969786baecfSMauro Carvalho Chehab 	*cold = 0;
970786baecfSMauro Carvalho Chehab 	return 0;
971786baecfSMauro Carvalho Chehab }
972786baecfSMauro Carvalho Chehab 
9730df289a2SMauro Carvalho Chehab static int dw210x_set_voltage(struct dvb_frontend *fe,
9740df289a2SMauro Carvalho Chehab 			      enum fe_sec_voltage voltage)
975786baecfSMauro Carvalho Chehab {
976786baecfSMauro Carvalho Chehab 	static u8 command_13v[] = {0x00, 0x01};
977786baecfSMauro Carvalho Chehab 	static u8 command_18v[] = {0x01, 0x01};
978786baecfSMauro Carvalho Chehab 	static u8 command_off[] = {0x00, 0x00};
979786baecfSMauro Carvalho Chehab 	struct i2c_msg msg = {
980786baecfSMauro Carvalho Chehab 		.addr = DW2102_VOLTAGE_CTRL,
981786baecfSMauro Carvalho Chehab 		.flags = 0,
982786baecfSMauro Carvalho Chehab 		.buf = command_off,
983786baecfSMauro Carvalho Chehab 		.len = 2,
984786baecfSMauro Carvalho Chehab 	};
985786baecfSMauro Carvalho Chehab 
986786baecfSMauro Carvalho Chehab 	struct dvb_usb_adapter *udev_adap =
987786baecfSMauro Carvalho Chehab 		(struct dvb_usb_adapter *)(fe->dvb->priv);
988786baecfSMauro Carvalho Chehab 	if (voltage == SEC_VOLTAGE_18)
989786baecfSMauro Carvalho Chehab 		msg.buf = command_18v;
990786baecfSMauro Carvalho Chehab 	else if (voltage == SEC_VOLTAGE_13)
991786baecfSMauro Carvalho Chehab 		msg.buf = command_13v;
992786baecfSMauro Carvalho Chehab 
993786baecfSMauro Carvalho Chehab 	i2c_transfer(&udev_adap->dev->i2c_adap, &msg, 1);
994786baecfSMauro Carvalho Chehab 
995786baecfSMauro Carvalho Chehab 	return 0;
996786baecfSMauro Carvalho Chehab }
997786baecfSMauro Carvalho Chehab 
9980df289a2SMauro Carvalho Chehab static int s660_set_voltage(struct dvb_frontend *fe,
9990df289a2SMauro Carvalho Chehab 			    enum fe_sec_voltage voltage)
1000786baecfSMauro Carvalho Chehab {
1001786baecfSMauro Carvalho Chehab 	struct dvb_usb_adapter *d =
1002786baecfSMauro Carvalho Chehab 		(struct dvb_usb_adapter *)(fe->dvb->priv);
10032c4ffe27SOlli Salonen 	struct dw2102_state *st = (struct dw2102_state *)d->dev->priv;
1004786baecfSMauro Carvalho Chehab 
1005786baecfSMauro Carvalho Chehab 	dw210x_set_voltage(fe, voltage);
1006786baecfSMauro Carvalho Chehab 	if (st->old_set_voltage)
1007786baecfSMauro Carvalho Chehab 		st->old_set_voltage(fe, voltage);
1008786baecfSMauro Carvalho Chehab 
1009786baecfSMauro Carvalho Chehab 	return 0;
1010786baecfSMauro Carvalho Chehab }
1011786baecfSMauro Carvalho Chehab 
1012786baecfSMauro Carvalho Chehab static void dw210x_led_ctrl(struct dvb_frontend *fe, int offon)
1013786baecfSMauro Carvalho Chehab {
1014786baecfSMauro Carvalho Chehab 	static u8 led_off[] = { 0 };
1015786baecfSMauro Carvalho Chehab 	static u8 led_on[] = { 1 };
1016786baecfSMauro Carvalho Chehab 	struct i2c_msg msg = {
1017786baecfSMauro Carvalho Chehab 		.addr = DW2102_LED_CTRL,
1018786baecfSMauro Carvalho Chehab 		.flags = 0,
1019786baecfSMauro Carvalho Chehab 		.buf = led_off,
1020786baecfSMauro Carvalho Chehab 		.len = 1
1021786baecfSMauro Carvalho Chehab 	};
1022786baecfSMauro Carvalho Chehab 	struct dvb_usb_adapter *udev_adap =
1023786baecfSMauro Carvalho Chehab 		(struct dvb_usb_adapter *)(fe->dvb->priv);
1024786baecfSMauro Carvalho Chehab 
1025786baecfSMauro Carvalho Chehab 	if (offon)
1026786baecfSMauro Carvalho Chehab 		msg.buf = led_on;
1027786baecfSMauro Carvalho Chehab 	i2c_transfer(&udev_adap->dev->i2c_adap, &msg, 1);
1028786baecfSMauro Carvalho Chehab }
1029786baecfSMauro Carvalho Chehab 
10300df289a2SMauro Carvalho Chehab static int tt_s2_4600_read_status(struct dvb_frontend *fe,
10310df289a2SMauro Carvalho Chehab 				  enum fe_status *status)
1032356484caSOlli Salonen {
1033356484caSOlli Salonen 	struct dvb_usb_adapter *d =
1034356484caSOlli Salonen 		(struct dvb_usb_adapter *)(fe->dvb->priv);
1035356484caSOlli Salonen 	struct dw2102_state *st = (struct dw2102_state *)d->dev->priv;
1036356484caSOlli Salonen 	int ret;
1037356484caSOlli Salonen 
1038356484caSOlli Salonen 	ret = st->fe_read_status(fe, status);
1039356484caSOlli Salonen 
1040356484caSOlli Salonen 	/* resync slave fifo when signal change from unlock to lock */
1041356484caSOlli Salonen 	if ((*status & FE_HAS_LOCK) && (!st->last_lock))
1042356484caSOlli Salonen 		su3000_streaming_ctrl(d, 1);
1043356484caSOlli Salonen 
1044356484caSOlli Salonen 	st->last_lock = (*status & FE_HAS_LOCK) ? 1 : 0;
1045356484caSOlli Salonen 	return ret;
1046356484caSOlli Salonen }
1047356484caSOlli Salonen 
1048786baecfSMauro Carvalho Chehab static struct stv0299_config sharp_z0194a_config = {
1049786baecfSMauro Carvalho Chehab 	.demod_address = 0x68,
1050786baecfSMauro Carvalho Chehab 	.inittab = sharp_z0194a_inittab,
1051786baecfSMauro Carvalho Chehab 	.mclk = 88000000UL,
1052786baecfSMauro Carvalho Chehab 	.invert = 1,
1053786baecfSMauro Carvalho Chehab 	.skip_reinit = 0,
1054786baecfSMauro Carvalho Chehab 	.lock_output = STV0299_LOCKOUTPUT_1,
1055786baecfSMauro Carvalho Chehab 	.volt13_op0_op1 = STV0299_VOLT13_OP1,
1056786baecfSMauro Carvalho Chehab 	.min_delay_ms = 100,
1057786baecfSMauro Carvalho Chehab 	.set_symbol_rate = sharp_z0194a_set_symbol_rate,
1058786baecfSMauro Carvalho Chehab };
1059786baecfSMauro Carvalho Chehab 
1060786baecfSMauro Carvalho Chehab static struct cx24116_config dw2104_config = {
1061786baecfSMauro Carvalho Chehab 	.demod_address = 0x55,
1062786baecfSMauro Carvalho Chehab 	.mpg_clk_pos_pol = 0x01,
1063786baecfSMauro Carvalho Chehab };
1064786baecfSMauro Carvalho Chehab 
1065786baecfSMauro Carvalho Chehab static struct si21xx_config serit_sp1511lhb_config = {
1066786baecfSMauro Carvalho Chehab 	.demod_address = 0x68,
1067786baecfSMauro Carvalho Chehab 	.min_delay_ms = 100,
1068786baecfSMauro Carvalho Chehab 
1069786baecfSMauro Carvalho Chehab };
1070786baecfSMauro Carvalho Chehab 
1071786baecfSMauro Carvalho Chehab static struct tda10023_config dw3101_tda10023_config = {
1072786baecfSMauro Carvalho Chehab 	.demod_address = 0x0c,
1073786baecfSMauro Carvalho Chehab 	.invert = 1,
1074786baecfSMauro Carvalho Chehab };
1075786baecfSMauro Carvalho Chehab 
1076786baecfSMauro Carvalho Chehab static struct mt312_config zl313_config = {
1077786baecfSMauro Carvalho Chehab 	.demod_address = 0x0e,
1078786baecfSMauro Carvalho Chehab };
1079786baecfSMauro Carvalho Chehab 
1080786baecfSMauro Carvalho Chehab static struct ds3000_config dw2104_ds3000_config = {
1081786baecfSMauro Carvalho Chehab 	.demod_address = 0x68,
1082786baecfSMauro Carvalho Chehab };
1083786baecfSMauro Carvalho Chehab 
108473f0af44SKonstantin Dimitrov static struct ts2020_config dw2104_ts2020_config = {
108573f0af44SKonstantin Dimitrov 	.tuner_address = 0x60,
1086b858c331SIgor M. Liplianin 	.clk_out_div = 1,
108703a67279SJohn Horan 	.frequency_div = 1060000,
108873f0af44SKonstantin Dimitrov };
108973f0af44SKonstantin Dimitrov 
109043385c8aSIgor M. Liplianin static struct ds3000_config s660_ds3000_config = {
109143385c8aSIgor M. Liplianin 	.demod_address = 0x68,
1092b858c331SIgor M. Liplianin 	.ci_mode = 1,
109343385c8aSIgor M. Liplianin 	.set_lock_led = dw210x_led_ctrl,
109443385c8aSIgor M. Liplianin };
109543385c8aSIgor M. Liplianin 
109603a67279SJohn Horan static struct ts2020_config s660_ts2020_config = {
109703a67279SJohn Horan 	.tuner_address = 0x60,
109803a67279SJohn Horan 	.clk_out_div = 1,
109903a67279SJohn Horan 	.frequency_div = 1146000,
110003a67279SJohn Horan };
110103a67279SJohn Horan 
1102786baecfSMauro Carvalho Chehab static struct stv0900_config dw2104a_stv0900_config = {
1103786baecfSMauro Carvalho Chehab 	.demod_address = 0x6a,
1104786baecfSMauro Carvalho Chehab 	.demod_mode = 0,
1105786baecfSMauro Carvalho Chehab 	.xtal = 27000000,
1106786baecfSMauro Carvalho Chehab 	.clkmode = 3,/* 0-CLKI, 2-XTALI, else AUTO */
1107786baecfSMauro Carvalho Chehab 	.diseqc_mode = 2,/* 2/3 PWM */
1108786baecfSMauro Carvalho Chehab 	.tun1_maddress = 0,/* 0x60 */
1109786baecfSMauro Carvalho Chehab 	.tun1_adc = 0,/* 2 Vpp */
1110786baecfSMauro Carvalho Chehab 	.path1_mode = 3,
1111786baecfSMauro Carvalho Chehab };
1112786baecfSMauro Carvalho Chehab 
1113786baecfSMauro Carvalho Chehab static struct stb6100_config dw2104a_stb6100_config = {
1114786baecfSMauro Carvalho Chehab 	.tuner_address = 0x60,
1115786baecfSMauro Carvalho Chehab 	.refclock = 27000000,
1116786baecfSMauro Carvalho Chehab };
1117786baecfSMauro Carvalho Chehab 
1118786baecfSMauro Carvalho Chehab static struct stv0900_config dw2104_stv0900_config = {
1119786baecfSMauro Carvalho Chehab 	.demod_address = 0x68,
1120786baecfSMauro Carvalho Chehab 	.demod_mode = 0,
1121786baecfSMauro Carvalho Chehab 	.xtal = 8000000,
1122786baecfSMauro Carvalho Chehab 	.clkmode = 3,
1123786baecfSMauro Carvalho Chehab 	.diseqc_mode = 2,
1124786baecfSMauro Carvalho Chehab 	.tun1_maddress = 0,
1125786baecfSMauro Carvalho Chehab 	.tun1_adc = 1,/* 1 Vpp */
1126786baecfSMauro Carvalho Chehab 	.path1_mode = 3,
1127786baecfSMauro Carvalho Chehab };
1128786baecfSMauro Carvalho Chehab 
1129786baecfSMauro Carvalho Chehab static struct stv6110_config dw2104_stv6110_config = {
1130786baecfSMauro Carvalho Chehab 	.i2c_address = 0x60,
1131786baecfSMauro Carvalho Chehab 	.mclk = 16000000,
1132786baecfSMauro Carvalho Chehab 	.clk_div = 1,
1133786baecfSMauro Carvalho Chehab };
1134786baecfSMauro Carvalho Chehab 
1135786baecfSMauro Carvalho Chehab static struct stv0900_config prof_7500_stv0900_config = {
1136786baecfSMauro Carvalho Chehab 	.demod_address = 0x6a,
1137786baecfSMauro Carvalho Chehab 	.demod_mode = 0,
1138786baecfSMauro Carvalho Chehab 	.xtal = 27000000,
1139786baecfSMauro Carvalho Chehab 	.clkmode = 3,/* 0-CLKI, 2-XTALI, else AUTO */
1140786baecfSMauro Carvalho Chehab 	.diseqc_mode = 2,/* 2/3 PWM */
1141786baecfSMauro Carvalho Chehab 	.tun1_maddress = 0,/* 0x60 */
1142786baecfSMauro Carvalho Chehab 	.tun1_adc = 0,/* 2 Vpp */
1143786baecfSMauro Carvalho Chehab 	.path1_mode = 3,
1144786baecfSMauro Carvalho Chehab 	.tun1_type = 3,
1145786baecfSMauro Carvalho Chehab 	.set_lock_led = dw210x_led_ctrl,
1146786baecfSMauro Carvalho Chehab };
1147786baecfSMauro Carvalho Chehab 
1148786baecfSMauro Carvalho Chehab static struct ds3000_config su3000_ds3000_config = {
1149786baecfSMauro Carvalho Chehab 	.demod_address = 0x68,
1150786baecfSMauro Carvalho Chehab 	.ci_mode = 1,
1151b858c331SIgor M. Liplianin 	.set_lock_led = dw210x_led_ctrl,
115273f0af44SKonstantin Dimitrov };
115373f0af44SKonstantin Dimitrov 
115451d882edSEvgeny Plehov static struct cxd2820r_config cxd2820r_config = {
115551d882edSEvgeny Plehov 	.i2c_address = 0x6c, /* (0xd8 >> 1) */
115651d882edSEvgeny Plehov 	.ts_mode = 0x38,
11577b71ef7eSCrazyCat 	.ts_clock_inv = 1,
115851d882edSEvgeny Plehov };
115951d882edSEvgeny Plehov 
116051d882edSEvgeny Plehov static struct tda18271_config tda18271_config = {
116151d882edSEvgeny Plehov 	.output_opt = TDA18271_OUTPUT_LT_OFF,
116251d882edSEvgeny Plehov 	.gate = TDA18271_GATE_DIGITAL,
116351d882edSEvgeny Plehov };
116451d882edSEvgeny Plehov 
1165955d00acSIgor M. Liplianin static u8 m88rs2000_inittab[] = {
1166955d00acSIgor M. Liplianin 	DEMOD_WRITE, 0x9a, 0x30,
1167955d00acSIgor M. Liplianin 	DEMOD_WRITE, 0x00, 0x01,
1168955d00acSIgor M. Liplianin 	WRITE_DELAY, 0x19, 0x00,
1169955d00acSIgor M. Liplianin 	DEMOD_WRITE, 0x00, 0x00,
1170955d00acSIgor M. Liplianin 	DEMOD_WRITE, 0x9a, 0xb0,
1171955d00acSIgor M. Liplianin 	DEMOD_WRITE, 0x81, 0xc1,
1172955d00acSIgor M. Liplianin 	DEMOD_WRITE, 0x81, 0x81,
1173955d00acSIgor M. Liplianin 	DEMOD_WRITE, 0x86, 0xc6,
1174955d00acSIgor M. Liplianin 	DEMOD_WRITE, 0x9a, 0x30,
1175955d00acSIgor M. Liplianin 	DEMOD_WRITE, 0xf0, 0x80,
1176955d00acSIgor M. Liplianin 	DEMOD_WRITE, 0xf1, 0xbf,
1177955d00acSIgor M. Liplianin 	DEMOD_WRITE, 0xb0, 0x45,
1178955d00acSIgor M. Liplianin 	DEMOD_WRITE, 0xb2, 0x01,
1179955d00acSIgor M. Liplianin 	DEMOD_WRITE, 0x9a, 0xb0,
1180955d00acSIgor M. Liplianin 	0xff, 0xaa, 0xff
1181955d00acSIgor M. Liplianin };
1182955d00acSIgor M. Liplianin 
1183955d00acSIgor M. Liplianin static struct m88rs2000_config s421_m88rs2000_config = {
1184955d00acSIgor M. Liplianin 	.demod_addr = 0x68,
1185955d00acSIgor M. Liplianin 	.inittab = m88rs2000_inittab,
1186955d00acSIgor M. Liplianin };
1187955d00acSIgor M. Liplianin 
1188786baecfSMauro Carvalho Chehab static int dw2104_frontend_attach(struct dvb_usb_adapter *d)
1189786baecfSMauro Carvalho Chehab {
1190786baecfSMauro Carvalho Chehab 	struct dvb_tuner_ops *tuner_ops = NULL;
1191786baecfSMauro Carvalho Chehab 
1192786baecfSMauro Carvalho Chehab 	if (demod_probe & 4) {
1193786baecfSMauro Carvalho Chehab 		d->fe_adap[0].fe = dvb_attach(stv0900_attach, &dw2104a_stv0900_config,
1194786baecfSMauro Carvalho Chehab 				&d->dev->i2c_adap, 0);
1195786baecfSMauro Carvalho Chehab 		if (d->fe_adap[0].fe != NULL) {
1196786baecfSMauro Carvalho Chehab 			if (dvb_attach(stb6100_attach, d->fe_adap[0].fe,
1197786baecfSMauro Carvalho Chehab 					&dw2104a_stb6100_config,
1198786baecfSMauro Carvalho Chehab 					&d->dev->i2c_adap)) {
1199786baecfSMauro Carvalho Chehab 				tuner_ops = &d->fe_adap[0].fe->ops.tuner_ops;
1200786baecfSMauro Carvalho Chehab 				tuner_ops->set_frequency = stb6100_set_freq;
1201786baecfSMauro Carvalho Chehab 				tuner_ops->get_frequency = stb6100_get_freq;
1202786baecfSMauro Carvalho Chehab 				tuner_ops->set_bandwidth = stb6100_set_bandw;
1203786baecfSMauro Carvalho Chehab 				tuner_ops->get_bandwidth = stb6100_get_bandw;
1204786baecfSMauro Carvalho Chehab 				d->fe_adap[0].fe->ops.set_voltage = dw210x_set_voltage;
12050385443fSJonathan McDowell 				info("Attached STV0900+STB6100!");
1206786baecfSMauro Carvalho Chehab 				return 0;
1207786baecfSMauro Carvalho Chehab 			}
1208786baecfSMauro Carvalho Chehab 		}
1209786baecfSMauro Carvalho Chehab 	}
1210786baecfSMauro Carvalho Chehab 
1211786baecfSMauro Carvalho Chehab 	if (demod_probe & 2) {
1212786baecfSMauro Carvalho Chehab 		d->fe_adap[0].fe = dvb_attach(stv0900_attach, &dw2104_stv0900_config,
1213786baecfSMauro Carvalho Chehab 				&d->dev->i2c_adap, 0);
1214786baecfSMauro Carvalho Chehab 		if (d->fe_adap[0].fe != NULL) {
1215786baecfSMauro Carvalho Chehab 			if (dvb_attach(stv6110_attach, d->fe_adap[0].fe,
1216786baecfSMauro Carvalho Chehab 					&dw2104_stv6110_config,
1217786baecfSMauro Carvalho Chehab 					&d->dev->i2c_adap)) {
1218786baecfSMauro Carvalho Chehab 				d->fe_adap[0].fe->ops.set_voltage = dw210x_set_voltage;
12190385443fSJonathan McDowell 				info("Attached STV0900+STV6110A!");
1220786baecfSMauro Carvalho Chehab 				return 0;
1221786baecfSMauro Carvalho Chehab 			}
1222786baecfSMauro Carvalho Chehab 		}
1223786baecfSMauro Carvalho Chehab 	}
1224786baecfSMauro Carvalho Chehab 
1225786baecfSMauro Carvalho Chehab 	if (demod_probe & 1) {
1226786baecfSMauro Carvalho Chehab 		d->fe_adap[0].fe = dvb_attach(cx24116_attach, &dw2104_config,
1227786baecfSMauro Carvalho Chehab 				&d->dev->i2c_adap);
1228786baecfSMauro Carvalho Chehab 		if (d->fe_adap[0].fe != NULL) {
1229786baecfSMauro Carvalho Chehab 			d->fe_adap[0].fe->ops.set_voltage = dw210x_set_voltage;
12300385443fSJonathan McDowell 			info("Attached cx24116!");
1231786baecfSMauro Carvalho Chehab 			return 0;
1232786baecfSMauro Carvalho Chehab 		}
1233786baecfSMauro Carvalho Chehab 	}
1234786baecfSMauro Carvalho Chehab 
1235786baecfSMauro Carvalho Chehab 	d->fe_adap[0].fe = dvb_attach(ds3000_attach, &dw2104_ds3000_config,
1236786baecfSMauro Carvalho Chehab 			&d->dev->i2c_adap);
1237786baecfSMauro Carvalho Chehab 	if (d->fe_adap[0].fe != NULL) {
123873f0af44SKonstantin Dimitrov 		dvb_attach(ts2020_attach, d->fe_adap[0].fe,
123973f0af44SKonstantin Dimitrov 			&dw2104_ts2020_config, &d->dev->i2c_adap);
1240786baecfSMauro Carvalho Chehab 		d->fe_adap[0].fe->ops.set_voltage = dw210x_set_voltage;
12410385443fSJonathan McDowell 		info("Attached DS3000!");
1242786baecfSMauro Carvalho Chehab 		return 0;
1243786baecfSMauro Carvalho Chehab 	}
1244786baecfSMauro Carvalho Chehab 
1245786baecfSMauro Carvalho Chehab 	return -EIO;
1246786baecfSMauro Carvalho Chehab }
1247786baecfSMauro Carvalho Chehab 
1248786baecfSMauro Carvalho Chehab static struct dvb_usb_device_properties dw2102_properties;
1249786baecfSMauro Carvalho Chehab static struct dvb_usb_device_properties dw2104_properties;
1250786baecfSMauro Carvalho Chehab static struct dvb_usb_device_properties s6x0_properties;
1251786baecfSMauro Carvalho Chehab 
1252786baecfSMauro Carvalho Chehab static int dw2102_frontend_attach(struct dvb_usb_adapter *d)
1253786baecfSMauro Carvalho Chehab {
1254786baecfSMauro Carvalho Chehab 	if (dw2102_properties.i2c_algo == &dw2102_serit_i2c_algo) {
1255786baecfSMauro Carvalho Chehab 		/*dw2102_properties.adapter->tuner_attach = NULL;*/
1256786baecfSMauro Carvalho Chehab 		d->fe_adap[0].fe = dvb_attach(si21xx_attach, &serit_sp1511lhb_config,
1257786baecfSMauro Carvalho Chehab 					&d->dev->i2c_adap);
1258786baecfSMauro Carvalho Chehab 		if (d->fe_adap[0].fe != NULL) {
1259786baecfSMauro Carvalho Chehab 			d->fe_adap[0].fe->ops.set_voltage = dw210x_set_voltage;
12600385443fSJonathan McDowell 			info("Attached si21xx!");
1261786baecfSMauro Carvalho Chehab 			return 0;
1262786baecfSMauro Carvalho Chehab 		}
1263786baecfSMauro Carvalho Chehab 	}
1264786baecfSMauro Carvalho Chehab 
1265786baecfSMauro Carvalho Chehab 	if (dw2102_properties.i2c_algo == &dw2102_earda_i2c_algo) {
1266786baecfSMauro Carvalho Chehab 		d->fe_adap[0].fe = dvb_attach(stv0288_attach, &earda_config,
1267786baecfSMauro Carvalho Chehab 					&d->dev->i2c_adap);
1268786baecfSMauro Carvalho Chehab 		if (d->fe_adap[0].fe != NULL) {
1269786baecfSMauro Carvalho Chehab 			if (dvb_attach(stb6000_attach, d->fe_adap[0].fe, 0x61,
1270786baecfSMauro Carvalho Chehab 					&d->dev->i2c_adap)) {
1271786baecfSMauro Carvalho Chehab 				d->fe_adap[0].fe->ops.set_voltage = dw210x_set_voltage;
12720385443fSJonathan McDowell 				info("Attached stv0288!");
1273786baecfSMauro Carvalho Chehab 				return 0;
1274786baecfSMauro Carvalho Chehab 			}
1275786baecfSMauro Carvalho Chehab 		}
1276786baecfSMauro Carvalho Chehab 	}
1277786baecfSMauro Carvalho Chehab 
1278786baecfSMauro Carvalho Chehab 	if (dw2102_properties.i2c_algo == &dw2102_i2c_algo) {
1279786baecfSMauro Carvalho Chehab 		/*dw2102_properties.adapter->tuner_attach = dw2102_tuner_attach;*/
1280786baecfSMauro Carvalho Chehab 		d->fe_adap[0].fe = dvb_attach(stv0299_attach, &sharp_z0194a_config,
1281786baecfSMauro Carvalho Chehab 					&d->dev->i2c_adap);
1282786baecfSMauro Carvalho Chehab 		if (d->fe_adap[0].fe != NULL) {
1283786baecfSMauro Carvalho Chehab 			d->fe_adap[0].fe->ops.set_voltage = dw210x_set_voltage;
12840385443fSJonathan McDowell 			info("Attached stv0299!");
1285786baecfSMauro Carvalho Chehab 			return 0;
1286786baecfSMauro Carvalho Chehab 		}
1287786baecfSMauro Carvalho Chehab 	}
1288786baecfSMauro Carvalho Chehab 	return -EIO;
1289786baecfSMauro Carvalho Chehab }
1290786baecfSMauro Carvalho Chehab 
1291786baecfSMauro Carvalho Chehab static int dw3101_frontend_attach(struct dvb_usb_adapter *d)
1292786baecfSMauro Carvalho Chehab {
1293786baecfSMauro Carvalho Chehab 	d->fe_adap[0].fe = dvb_attach(tda10023_attach, &dw3101_tda10023_config,
1294786baecfSMauro Carvalho Chehab 				&d->dev->i2c_adap, 0x48);
1295786baecfSMauro Carvalho Chehab 	if (d->fe_adap[0].fe != NULL) {
12960385443fSJonathan McDowell 		info("Attached tda10023!");
1297786baecfSMauro Carvalho Chehab 		return 0;
1298786baecfSMauro Carvalho Chehab 	}
1299786baecfSMauro Carvalho Chehab 	return -EIO;
1300786baecfSMauro Carvalho Chehab }
1301786baecfSMauro Carvalho Chehab 
1302786baecfSMauro Carvalho Chehab static int zl100313_frontend_attach(struct dvb_usb_adapter *d)
1303786baecfSMauro Carvalho Chehab {
1304786baecfSMauro Carvalho Chehab 	d->fe_adap[0].fe = dvb_attach(mt312_attach, &zl313_config,
1305786baecfSMauro Carvalho Chehab 			&d->dev->i2c_adap);
1306786baecfSMauro Carvalho Chehab 	if (d->fe_adap[0].fe != NULL) {
1307786baecfSMauro Carvalho Chehab 		if (dvb_attach(zl10039_attach, d->fe_adap[0].fe, 0x60,
1308786baecfSMauro Carvalho Chehab 				&d->dev->i2c_adap)) {
1309786baecfSMauro Carvalho Chehab 			d->fe_adap[0].fe->ops.set_voltage = dw210x_set_voltage;
13100385443fSJonathan McDowell 			info("Attached zl100313+zl10039!");
1311786baecfSMauro Carvalho Chehab 			return 0;
1312786baecfSMauro Carvalho Chehab 		}
1313786baecfSMauro Carvalho Chehab 	}
1314786baecfSMauro Carvalho Chehab 
1315786baecfSMauro Carvalho Chehab 	return -EIO;
1316786baecfSMauro Carvalho Chehab }
1317786baecfSMauro Carvalho Chehab 
1318786baecfSMauro Carvalho Chehab static int stv0288_frontend_attach(struct dvb_usb_adapter *d)
1319786baecfSMauro Carvalho Chehab {
1320786baecfSMauro Carvalho Chehab 	u8 obuf[] = {7, 1};
1321786baecfSMauro Carvalho Chehab 
1322786baecfSMauro Carvalho Chehab 	d->fe_adap[0].fe = dvb_attach(stv0288_attach, &earda_config,
1323786baecfSMauro Carvalho Chehab 			&d->dev->i2c_adap);
1324786baecfSMauro Carvalho Chehab 
1325786baecfSMauro Carvalho Chehab 	if (d->fe_adap[0].fe == NULL)
1326786baecfSMauro Carvalho Chehab 		return -EIO;
1327786baecfSMauro Carvalho Chehab 
1328786baecfSMauro Carvalho Chehab 	if (NULL == dvb_attach(stb6000_attach, d->fe_adap[0].fe, 0x61, &d->dev->i2c_adap))
1329786baecfSMauro Carvalho Chehab 		return -EIO;
1330786baecfSMauro Carvalho Chehab 
1331786baecfSMauro Carvalho Chehab 	d->fe_adap[0].fe->ops.set_voltage = dw210x_set_voltage;
1332786baecfSMauro Carvalho Chehab 
1333786baecfSMauro Carvalho Chehab 	dw210x_op_rw(d->dev->udev, 0x8a, 0, 0, obuf, 2, DW210X_WRITE_MSG);
1334786baecfSMauro Carvalho Chehab 
13350385443fSJonathan McDowell 	info("Attached stv0288+stb6000!");
1336786baecfSMauro Carvalho Chehab 
1337786baecfSMauro Carvalho Chehab 	return 0;
1338786baecfSMauro Carvalho Chehab 
1339786baecfSMauro Carvalho Chehab }
1340786baecfSMauro Carvalho Chehab 
1341786baecfSMauro Carvalho Chehab static int ds3000_frontend_attach(struct dvb_usb_adapter *d)
1342786baecfSMauro Carvalho Chehab {
13432c4ffe27SOlli Salonen 	struct dw2102_state *st = d->dev->priv;
1344786baecfSMauro Carvalho Chehab 	u8 obuf[] = {7, 1};
1345786baecfSMauro Carvalho Chehab 
134643385c8aSIgor M. Liplianin 	d->fe_adap[0].fe = dvb_attach(ds3000_attach, &s660_ds3000_config,
1347786baecfSMauro Carvalho Chehab 			&d->dev->i2c_adap);
1348786baecfSMauro Carvalho Chehab 
1349786baecfSMauro Carvalho Chehab 	if (d->fe_adap[0].fe == NULL)
1350786baecfSMauro Carvalho Chehab 		return -EIO;
1351786baecfSMauro Carvalho Chehab 
135203a67279SJohn Horan 	dvb_attach(ts2020_attach, d->fe_adap[0].fe, &s660_ts2020_config,
135373f0af44SKonstantin Dimitrov 		&d->dev->i2c_adap);
135473f0af44SKonstantin Dimitrov 
1355786baecfSMauro Carvalho Chehab 	st->old_set_voltage = d->fe_adap[0].fe->ops.set_voltage;
1356786baecfSMauro Carvalho Chehab 	d->fe_adap[0].fe->ops.set_voltage = s660_set_voltage;
1357786baecfSMauro Carvalho Chehab 
1358786baecfSMauro Carvalho Chehab 	dw210x_op_rw(d->dev->udev, 0x8a, 0, 0, obuf, 2, DW210X_WRITE_MSG);
1359786baecfSMauro Carvalho Chehab 
13600385443fSJonathan McDowell 	info("Attached ds3000+ts2020!");
1361786baecfSMauro Carvalho Chehab 
1362786baecfSMauro Carvalho Chehab 	return 0;
1363786baecfSMauro Carvalho Chehab }
1364786baecfSMauro Carvalho Chehab 
1365786baecfSMauro Carvalho Chehab static int prof_7500_frontend_attach(struct dvb_usb_adapter *d)
1366786baecfSMauro Carvalho Chehab {
1367786baecfSMauro Carvalho Chehab 	u8 obuf[] = {7, 1};
1368786baecfSMauro Carvalho Chehab 
1369786baecfSMauro Carvalho Chehab 	d->fe_adap[0].fe = dvb_attach(stv0900_attach, &prof_7500_stv0900_config,
1370786baecfSMauro Carvalho Chehab 					&d->dev->i2c_adap, 0);
1371786baecfSMauro Carvalho Chehab 	if (d->fe_adap[0].fe == NULL)
1372786baecfSMauro Carvalho Chehab 		return -EIO;
1373786baecfSMauro Carvalho Chehab 
1374786baecfSMauro Carvalho Chehab 	d->fe_adap[0].fe->ops.set_voltage = dw210x_set_voltage;
1375786baecfSMauro Carvalho Chehab 
1376786baecfSMauro Carvalho Chehab 	dw210x_op_rw(d->dev->udev, 0x8a, 0, 0, obuf, 2, DW210X_WRITE_MSG);
1377786baecfSMauro Carvalho Chehab 
13780385443fSJonathan McDowell 	info("Attached STV0900+STB6100A!");
1379786baecfSMauro Carvalho Chehab 
1380786baecfSMauro Carvalho Chehab 	return 0;
1381786baecfSMauro Carvalho Chehab }
1382786baecfSMauro Carvalho Chehab 
1383606142afSJonathan McDowell static int su3000_frontend_attach(struct dvb_usb_adapter *adap)
1384786baecfSMauro Carvalho Chehab {
1385606142afSJonathan McDowell 	struct dvb_usb_device *d = adap->dev;
1386606142afSJonathan McDowell 	struct dw2102_state *state = d->priv;
1387786baecfSMauro Carvalho Chehab 
1388606142afSJonathan McDowell 	mutex_lock(&d->data_mutex);
1389606142afSJonathan McDowell 
1390606142afSJonathan McDowell 	state->data[0] = 0xe;
1391606142afSJonathan McDowell 	state->data[1] = 0x80;
1392606142afSJonathan McDowell 	state->data[2] = 0;
1393606142afSJonathan McDowell 
1394606142afSJonathan McDowell 	if (dvb_usb_generic_rw(d, state->data, 3, state->data, 1, 0) < 0)
1395786baecfSMauro Carvalho Chehab 		err("command 0x0e transfer failed.");
1396786baecfSMauro Carvalho Chehab 
1397606142afSJonathan McDowell 	state->data[0] = 0xe;
1398606142afSJonathan McDowell 	state->data[1] = 0x02;
1399606142afSJonathan McDowell 	state->data[2] = 1;
1400b858c331SIgor M. Liplianin 
1401606142afSJonathan McDowell 	if (dvb_usb_generic_rw(d, state->data, 3, state->data, 1, 0) < 0)
1402b858c331SIgor M. Liplianin 		err("command 0x0e transfer failed.");
1403b858c331SIgor M. Liplianin 	msleep(300);
1404b858c331SIgor M. Liplianin 
1405606142afSJonathan McDowell 	state->data[0] = 0xe;
1406606142afSJonathan McDowell 	state->data[1] = 0x83;
1407606142afSJonathan McDowell 	state->data[2] = 0;
1408786baecfSMauro Carvalho Chehab 
1409606142afSJonathan McDowell 	if (dvb_usb_generic_rw(d, state->data, 3, state->data, 1, 0) < 0)
1410786baecfSMauro Carvalho Chehab 		err("command 0x0e transfer failed.");
1411786baecfSMauro Carvalho Chehab 
1412606142afSJonathan McDowell 	state->data[0] = 0xe;
1413606142afSJonathan McDowell 	state->data[1] = 0x83;
1414606142afSJonathan McDowell 	state->data[2] = 1;
1415786baecfSMauro Carvalho Chehab 
1416606142afSJonathan McDowell 	if (dvb_usb_generic_rw(d, state->data, 3, state->data, 1, 0) < 0)
1417786baecfSMauro Carvalho Chehab 		err("command 0x0e transfer failed.");
1418786baecfSMauro Carvalho Chehab 
1419606142afSJonathan McDowell 	state->data[0] = 0x51;
1420786baecfSMauro Carvalho Chehab 
1421606142afSJonathan McDowell 	if (dvb_usb_generic_rw(d, state->data, 1, state->data, 1, 0) < 0)
1422786baecfSMauro Carvalho Chehab 		err("command 0x51 transfer failed.");
1423786baecfSMauro Carvalho Chehab 
1424606142afSJonathan McDowell 	mutex_unlock(&d->data_mutex);
1425606142afSJonathan McDowell 
1426606142afSJonathan McDowell 	adap->fe_adap[0].fe = dvb_attach(ds3000_attach, &su3000_ds3000_config,
1427606142afSJonathan McDowell 					&d->i2c_adap);
1428606142afSJonathan McDowell 	if (adap->fe_adap[0].fe == NULL)
1429786baecfSMauro Carvalho Chehab 		return -EIO;
1430786baecfSMauro Carvalho Chehab 
1431606142afSJonathan McDowell 	if (dvb_attach(ts2020_attach, adap->fe_adap[0].fe,
1432b858c331SIgor M. Liplianin 				&dw2104_ts2020_config,
1433606142afSJonathan McDowell 				&d->i2c_adap)) {
14340385443fSJonathan McDowell 		info("Attached DS3000/TS2020!");
1435786baecfSMauro Carvalho Chehab 		return 0;
1436786baecfSMauro Carvalho Chehab 	}
1437786baecfSMauro Carvalho Chehab 
14380385443fSJonathan McDowell 	info("Failed to attach DS3000/TS2020!");
1439b858c331SIgor M. Liplianin 	return -EIO;
1440b858c331SIgor M. Liplianin }
1441b858c331SIgor M. Liplianin 
1442606142afSJonathan McDowell static int t220_frontend_attach(struct dvb_usb_adapter *adap)
144351d882edSEvgeny Plehov {
1444606142afSJonathan McDowell 	struct dvb_usb_device *d = adap->dev;
1445606142afSJonathan McDowell 	struct dw2102_state *state = d->priv;
144651d882edSEvgeny Plehov 
1447606142afSJonathan McDowell 	mutex_lock(&d->data_mutex);
1448606142afSJonathan McDowell 
1449606142afSJonathan McDowell 	state->data[0] = 0xe;
1450606142afSJonathan McDowell 	state->data[1] = 0x87;
1451606142afSJonathan McDowell 	state->data[2] = 0x0;
1452606142afSJonathan McDowell 
1453606142afSJonathan McDowell 	if (dvb_usb_generic_rw(d, state->data, 3, state->data, 1, 0) < 0)
145451d882edSEvgeny Plehov 		err("command 0x0e transfer failed.");
145551d882edSEvgeny Plehov 
1456606142afSJonathan McDowell 	state->data[0] = 0xe;
1457606142afSJonathan McDowell 	state->data[1] = 0x86;
1458606142afSJonathan McDowell 	state->data[2] = 1;
14597b71ef7eSCrazyCat 
1460606142afSJonathan McDowell 	if (dvb_usb_generic_rw(d, state->data, 3, state->data, 1, 0) < 0)
14617b71ef7eSCrazyCat 		err("command 0x0e transfer failed.");
14627b71ef7eSCrazyCat 
1463606142afSJonathan McDowell 	state->data[0] = 0xe;
1464606142afSJonathan McDowell 	state->data[1] = 0x80;
1465606142afSJonathan McDowell 	state->data[2] = 0;
146651d882edSEvgeny Plehov 
1467606142afSJonathan McDowell 	if (dvb_usb_generic_rw(d, state->data, 3, state->data, 1, 0) < 0)
146851d882edSEvgeny Plehov 		err("command 0x0e transfer failed.");
146951d882edSEvgeny Plehov 
14707b71ef7eSCrazyCat 	msleep(50);
147151d882edSEvgeny Plehov 
1472606142afSJonathan McDowell 	state->data[0] = 0xe;
1473606142afSJonathan McDowell 	state->data[1] = 0x80;
1474606142afSJonathan McDowell 	state->data[2] = 1;
147551d882edSEvgeny Plehov 
1476606142afSJonathan McDowell 	if (dvb_usb_generic_rw(d, state->data, 3, state->data, 1, 0) < 0)
147751d882edSEvgeny Plehov 		err("command 0x0e transfer failed.");
147851d882edSEvgeny Plehov 
1479606142afSJonathan McDowell 	state->data[0] = 0x51;
148051d882edSEvgeny Plehov 
1481606142afSJonathan McDowell 	if (dvb_usb_generic_rw(d, state->data, 1, state->data, 1, 0) < 0)
148251d882edSEvgeny Plehov 		err("command 0x51 transfer failed.");
148351d882edSEvgeny Plehov 
1484606142afSJonathan McDowell 	mutex_unlock(&d->data_mutex);
1485606142afSJonathan McDowell 
1486606142afSJonathan McDowell 	adap->fe_adap[0].fe = dvb_attach(cxd2820r_attach, &cxd2820r_config,
1487606142afSJonathan McDowell 					&d->i2c_adap, NULL);
1488606142afSJonathan McDowell 	if (adap->fe_adap[0].fe != NULL) {
1489606142afSJonathan McDowell 		if (dvb_attach(tda18271_attach, adap->fe_adap[0].fe, 0x60,
1490606142afSJonathan McDowell 					&d->i2c_adap, &tda18271_config)) {
14910385443fSJonathan McDowell 			info("Attached TDA18271HD/CXD2820R!");
149251d882edSEvgeny Plehov 			return 0;
149351d882edSEvgeny Plehov 		}
149451d882edSEvgeny Plehov 	}
149551d882edSEvgeny Plehov 
14960385443fSJonathan McDowell 	info("Failed to attach TDA18271HD/CXD2820R!");
149751d882edSEvgeny Plehov 	return -EIO;
149851d882edSEvgeny Plehov }
149951d882edSEvgeny Plehov 
1500606142afSJonathan McDowell static int m88rs2000_frontend_attach(struct dvb_usb_adapter *adap)
1501955d00acSIgor M. Liplianin {
1502606142afSJonathan McDowell 	struct dvb_usb_device *d = adap->dev;
1503606142afSJonathan McDowell 	struct dw2102_state *state = d->priv;
1504955d00acSIgor M. Liplianin 
1505606142afSJonathan McDowell 	mutex_lock(&d->data_mutex);
1506606142afSJonathan McDowell 
1507606142afSJonathan McDowell 	state->data[0] = 0x51;
1508606142afSJonathan McDowell 
1509606142afSJonathan McDowell 	if (dvb_usb_generic_rw(d, state->data, 1, state->data, 1, 0) < 0)
1510955d00acSIgor M. Liplianin 		err("command 0x51 transfer failed.");
1511955d00acSIgor M. Liplianin 
1512606142afSJonathan McDowell 	mutex_unlock(&d->data_mutex);
1513b858c331SIgor M. Liplianin 
1514606142afSJonathan McDowell 	adap->fe_adap[0].fe = dvb_attach(m88rs2000_attach,
1515606142afSJonathan McDowell 					&s421_m88rs2000_config,
1516606142afSJonathan McDowell 					&d->i2c_adap);
1517606142afSJonathan McDowell 
1518606142afSJonathan McDowell 	if (adap->fe_adap[0].fe == NULL)
1519955d00acSIgor M. Liplianin 		return -EIO;
1520955d00acSIgor M. Liplianin 
1521606142afSJonathan McDowell 	if (dvb_attach(ts2020_attach, adap->fe_adap[0].fe,
1522b858c331SIgor M. Liplianin 				&dw2104_ts2020_config,
1523606142afSJonathan McDowell 				&d->i2c_adap)) {
15240385443fSJonathan McDowell 		info("Attached RS2000/TS2020!");
1525955d00acSIgor M. Liplianin 		return 0;
1526955d00acSIgor M. Liplianin 	}
1527955d00acSIgor M. Liplianin 
15280385443fSJonathan McDowell 	info("Failed to attach RS2000/TS2020!");
1529b858c331SIgor M. Liplianin 	return -EIO;
1530b858c331SIgor M. Liplianin }
1531b858c331SIgor M. Liplianin 
153227254c36SOlli Salonen static int tt_s2_4600_frontend_attach(struct dvb_usb_adapter *adap)
153327254c36SOlli Salonen {
153427254c36SOlli Salonen 	struct dvb_usb_device *d = adap->dev;
153527254c36SOlli Salonen 	struct dw2102_state *state = d->priv;
153627254c36SOlli Salonen 	struct i2c_adapter *i2c_adapter;
153727254c36SOlli Salonen 	struct i2c_client *client;
1538f3c6abcaSOlli Salonen 	struct i2c_board_info board_info;
1539f3c6abcaSOlli Salonen 	struct m88ds3103_platform_data m88ds3103_pdata = {};
15400fecb6c0SAntti Palosaari 	struct ts2020_config ts2020_config = {};
154127254c36SOlli Salonen 
1542606142afSJonathan McDowell 	mutex_lock(&d->data_mutex);
1543606142afSJonathan McDowell 
1544606142afSJonathan McDowell 	state->data[0] = 0xe;
1545606142afSJonathan McDowell 	state->data[1] = 0x80;
1546606142afSJonathan McDowell 	state->data[2] = 0x0;
1547606142afSJonathan McDowell 
1548606142afSJonathan McDowell 	if (dvb_usb_generic_rw(d, state->data, 3, state->data, 1, 0) < 0)
154927254c36SOlli Salonen 		err("command 0x0e transfer failed.");
155027254c36SOlli Salonen 
1551606142afSJonathan McDowell 	state->data[0] = 0xe;
1552606142afSJonathan McDowell 	state->data[1] = 0x02;
1553606142afSJonathan McDowell 	state->data[2] = 1;
155427254c36SOlli Salonen 
1555606142afSJonathan McDowell 	if (dvb_usb_generic_rw(d, state->data, 3, state->data, 1, 0) < 0)
155627254c36SOlli Salonen 		err("command 0x0e transfer failed.");
155727254c36SOlli Salonen 	msleep(300);
155827254c36SOlli Salonen 
1559606142afSJonathan McDowell 	state->data[0] = 0xe;
1560606142afSJonathan McDowell 	state->data[1] = 0x83;
1561606142afSJonathan McDowell 	state->data[2] = 0;
156227254c36SOlli Salonen 
1563606142afSJonathan McDowell 	if (dvb_usb_generic_rw(d, state->data, 3, state->data, 1, 0) < 0)
156427254c36SOlli Salonen 		err("command 0x0e transfer failed.");
156527254c36SOlli Salonen 
1566606142afSJonathan McDowell 	state->data[0] = 0xe;
1567606142afSJonathan McDowell 	state->data[1] = 0x83;
1568606142afSJonathan McDowell 	state->data[2] = 1;
156927254c36SOlli Salonen 
1570606142afSJonathan McDowell 	if (dvb_usb_generic_rw(d, state->data, 3, state->data, 1, 0) < 0)
157127254c36SOlli Salonen 		err("command 0x0e transfer failed.");
157227254c36SOlli Salonen 
1573606142afSJonathan McDowell 	state->data[0] = 0x51;
157427254c36SOlli Salonen 
1575606142afSJonathan McDowell 	if (dvb_usb_generic_rw(d, state->data, 1, state->data, 1, 0) < 0)
157627254c36SOlli Salonen 		err("command 0x51 transfer failed.");
157727254c36SOlli Salonen 
1578606142afSJonathan McDowell 	mutex_unlock(&d->data_mutex);
1579606142afSJonathan McDowell 
1580f3c6abcaSOlli Salonen 	/* attach demod */
1581f3c6abcaSOlli Salonen 	m88ds3103_pdata.clk = 27000000;
1582f3c6abcaSOlli Salonen 	m88ds3103_pdata.i2c_wr_max = 33;
1583f3c6abcaSOlli Salonen 	m88ds3103_pdata.ts_mode = M88DS3103_TS_CI;
1584f3c6abcaSOlli Salonen 	m88ds3103_pdata.ts_clk = 16000;
1585f3c6abcaSOlli Salonen 	m88ds3103_pdata.ts_clk_pol = 0;
1586f3c6abcaSOlli Salonen 	m88ds3103_pdata.spec_inv = 0;
1587f3c6abcaSOlli Salonen 	m88ds3103_pdata.agc = 0x99;
1588f3c6abcaSOlli Salonen 	m88ds3103_pdata.agc_inv = 0;
1589f3c6abcaSOlli Salonen 	m88ds3103_pdata.clk_out = M88DS3103_CLOCK_OUT_ENABLED;
1590f3c6abcaSOlli Salonen 	m88ds3103_pdata.envelope_mode = 0;
1591f3c6abcaSOlli Salonen 	m88ds3103_pdata.lnb_hv_pol = 1;
1592f3c6abcaSOlli Salonen 	m88ds3103_pdata.lnb_en_pol = 0;
1593f3c6abcaSOlli Salonen 	memset(&board_info, 0, sizeof(board_info));
1594f3c6abcaSOlli Salonen 	strlcpy(board_info.type, "m88ds3103", I2C_NAME_SIZE);
1595f3c6abcaSOlli Salonen 	board_info.addr = 0x68;
1596f3c6abcaSOlli Salonen 	board_info.platform_data = &m88ds3103_pdata;
1597f3c6abcaSOlli Salonen 	request_module("m88ds3103");
1598f3c6abcaSOlli Salonen 	client = i2c_new_device(&d->i2c_adap, &board_info);
1599f3c6abcaSOlli Salonen 	if (client == NULL || client->dev.driver == NULL)
160027254c36SOlli Salonen 		return -ENODEV;
1601f3c6abcaSOlli Salonen 	if (!try_module_get(client->dev.driver->owner)) {
1602f3c6abcaSOlli Salonen 		i2c_unregister_device(client);
1603f3c6abcaSOlli Salonen 		return -ENODEV;
1604f3c6abcaSOlli Salonen 	}
1605f3c6abcaSOlli Salonen 	adap->fe_adap[0].fe = m88ds3103_pdata.get_dvb_frontend(client);
1606f3c6abcaSOlli Salonen 	i2c_adapter = m88ds3103_pdata.get_i2c_adapter(client);
1607f3c6abcaSOlli Salonen 
1608f3c6abcaSOlli Salonen 	state->i2c_client_demod = client;
160927254c36SOlli Salonen 
161027254c36SOlli Salonen 	/* attach tuner */
16110fecb6c0SAntti Palosaari 	ts2020_config.fe = adap->fe_adap[0].fe;
1612f3c6abcaSOlli Salonen 	memset(&board_info, 0, sizeof(board_info));
1613f3c6abcaSOlli Salonen 	strlcpy(board_info.type, "ts2022", I2C_NAME_SIZE);
1614f3c6abcaSOlli Salonen 	board_info.addr = 0x60;
1615f3c6abcaSOlli Salonen 	board_info.platform_data = &ts2020_config;
16160fecb6c0SAntti Palosaari 	request_module("ts2020");
1617f3c6abcaSOlli Salonen 	client = i2c_new_device(i2c_adapter, &board_info);
161827254c36SOlli Salonen 
161927254c36SOlli Salonen 	if (client == NULL || client->dev.driver == NULL) {
162027254c36SOlli Salonen 		dvb_frontend_detach(adap->fe_adap[0].fe);
162127254c36SOlli Salonen 		return -ENODEV;
162227254c36SOlli Salonen 	}
162327254c36SOlli Salonen 
162427254c36SOlli Salonen 	if (!try_module_get(client->dev.driver->owner)) {
162527254c36SOlli Salonen 		i2c_unregister_device(client);
162627254c36SOlli Salonen 		dvb_frontend_detach(adap->fe_adap[0].fe);
162727254c36SOlli Salonen 		return -ENODEV;
162827254c36SOlli Salonen 	}
162927254c36SOlli Salonen 
163027254c36SOlli Salonen 	/* delegate signal strength measurement to tuner */
163127254c36SOlli Salonen 	adap->fe_adap[0].fe->ops.read_signal_strength =
163227254c36SOlli Salonen 			adap->fe_adap[0].fe->ops.tuner_ops.get_rf_strength;
163327254c36SOlli Salonen 
163427254c36SOlli Salonen 	state->i2c_client_tuner = client;
163527254c36SOlli Salonen 
1636356484caSOlli Salonen 	/* hook fe: need to resync the slave fifo when signal locks */
1637356484caSOlli Salonen 	state->fe_read_status = adap->fe_adap[0].fe->ops.read_status;
1638356484caSOlli Salonen 	adap->fe_adap[0].fe->ops.read_status = tt_s2_4600_read_status;
1639356484caSOlli Salonen 
1640356484caSOlli Salonen 	state->last_lock = 0;
1641356484caSOlli Salonen 
164227254c36SOlli Salonen 	return 0;
164327254c36SOlli Salonen }
164427254c36SOlli Salonen 
1645786baecfSMauro Carvalho Chehab static int dw2102_tuner_attach(struct dvb_usb_adapter *adap)
1646786baecfSMauro Carvalho Chehab {
1647786baecfSMauro Carvalho Chehab 	dvb_attach(dvb_pll_attach, adap->fe_adap[0].fe, 0x60,
1648786baecfSMauro Carvalho Chehab 		&adap->dev->i2c_adap, DVB_PLL_OPERA1);
1649786baecfSMauro Carvalho Chehab 	return 0;
1650786baecfSMauro Carvalho Chehab }
1651786baecfSMauro Carvalho Chehab 
1652786baecfSMauro Carvalho Chehab static int dw3101_tuner_attach(struct dvb_usb_adapter *adap)
1653786baecfSMauro Carvalho Chehab {
1654786baecfSMauro Carvalho Chehab 	dvb_attach(dvb_pll_attach, adap->fe_adap[0].fe, 0x60,
1655786baecfSMauro Carvalho Chehab 		&adap->dev->i2c_adap, DVB_PLL_TUA6034);
1656786baecfSMauro Carvalho Chehab 
1657786baecfSMauro Carvalho Chehab 	return 0;
1658786baecfSMauro Carvalho Chehab }
1659786baecfSMauro Carvalho Chehab 
1660a49de26aSEvgeny Plehov static int dw2102_rc_query(struct dvb_usb_device *d)
1661786baecfSMauro Carvalho Chehab {
1662786baecfSMauro Carvalho Chehab 	u8 key[2];
1663786baecfSMauro Carvalho Chehab 	struct i2c_msg msg = {
1664786baecfSMauro Carvalho Chehab 		.addr = DW2102_RC_QUERY,
1665786baecfSMauro Carvalho Chehab 		.flags = I2C_M_RD,
1666786baecfSMauro Carvalho Chehab 		.buf = key,
1667786baecfSMauro Carvalho Chehab 		.len = 2
1668786baecfSMauro Carvalho Chehab 	};
1669786baecfSMauro Carvalho Chehab 
1670786baecfSMauro Carvalho Chehab 	if (d->props.i2c_algo->master_xfer(&d->i2c_adap, &msg, 1) == 1) {
1671a49de26aSEvgeny Plehov 		if (msg.buf[0] != 0xff) {
1672a49de26aSEvgeny Plehov 			deb_rc("%s: rc code: %x, %x\n",
1673786baecfSMauro Carvalho Chehab 					__func__, key[0], key[1]);
16746d741bfeSSean Young 			rc_keydown(d->rc_dev, RC_PROTO_UNKNOWN, key[0], 0);
1675a49de26aSEvgeny Plehov 		}
1676a49de26aSEvgeny Plehov 	}
1677786baecfSMauro Carvalho Chehab 
1678a49de26aSEvgeny Plehov 	return 0;
1679a49de26aSEvgeny Plehov }
1680a49de26aSEvgeny Plehov 
1681a49de26aSEvgeny Plehov static int prof_rc_query(struct dvb_usb_device *d)
1682a49de26aSEvgeny Plehov {
1683a49de26aSEvgeny Plehov 	u8 key[2];
1684a49de26aSEvgeny Plehov 	struct i2c_msg msg = {
1685a49de26aSEvgeny Plehov 		.addr = DW2102_RC_QUERY,
1686a49de26aSEvgeny Plehov 		.flags = I2C_M_RD,
1687a49de26aSEvgeny Plehov 		.buf = key,
1688a49de26aSEvgeny Plehov 		.len = 2
1689a49de26aSEvgeny Plehov 	};
1690a49de26aSEvgeny Plehov 
1691a49de26aSEvgeny Plehov 	if (d->props.i2c_algo->master_xfer(&d->i2c_adap, &msg, 1) == 1) {
1692a49de26aSEvgeny Plehov 		if (msg.buf[0] != 0xff) {
1693a49de26aSEvgeny Plehov 			deb_rc("%s: rc code: %x, %x\n",
1694a49de26aSEvgeny Plehov 					__func__, key[0], key[1]);
16956d741bfeSSean Young 			rc_keydown(d->rc_dev, RC_PROTO_UNKNOWN, key[0] ^ 0xff,
16966d741bfeSSean Young 				   0);
1697a49de26aSEvgeny Plehov 		}
1698a49de26aSEvgeny Plehov 	}
1699a49de26aSEvgeny Plehov 
1700a49de26aSEvgeny Plehov 	return 0;
1701a49de26aSEvgeny Plehov }
1702a49de26aSEvgeny Plehov 
1703a49de26aSEvgeny Plehov static int su3000_rc_query(struct dvb_usb_device *d)
1704a49de26aSEvgeny Plehov {
1705a49de26aSEvgeny Plehov 	u8 key[2];
1706a49de26aSEvgeny Plehov 	struct i2c_msg msg = {
1707a49de26aSEvgeny Plehov 		.addr = DW2102_RC_QUERY,
1708a49de26aSEvgeny Plehov 		.flags = I2C_M_RD,
1709a49de26aSEvgeny Plehov 		.buf = key,
1710a49de26aSEvgeny Plehov 		.len = 2
1711a49de26aSEvgeny Plehov 	};
1712a49de26aSEvgeny Plehov 
1713a49de26aSEvgeny Plehov 	if (d->props.i2c_algo->master_xfer(&d->i2c_adap, &msg, 1) == 1) {
1714a49de26aSEvgeny Plehov 		if (msg.buf[0] != 0xff) {
1715a49de26aSEvgeny Plehov 			deb_rc("%s: rc code: %x, %x\n",
1716a49de26aSEvgeny Plehov 					__func__, key[0], key[1]);
17176d741bfeSSean Young 			rc_keydown(d->rc_dev, RC_PROTO_RC5,
1718120703f9SDavid Härdeman 				   RC_SCANCODE_RC5(key[1], key[0]), 0);
1719a49de26aSEvgeny Plehov 		}
1720786baecfSMauro Carvalho Chehab 	}
1721786baecfSMauro Carvalho Chehab 
1722786baecfSMauro Carvalho Chehab 	return 0;
1723786baecfSMauro Carvalho Chehab }
1724786baecfSMauro Carvalho Chehab 
1725786baecfSMauro Carvalho Chehab enum dw2102_table_entry {
1726786baecfSMauro Carvalho Chehab 	CYPRESS_DW2102,
1727786baecfSMauro Carvalho Chehab 	CYPRESS_DW2101,
1728786baecfSMauro Carvalho Chehab 	CYPRESS_DW2104,
1729786baecfSMauro Carvalho Chehab 	TEVII_S650,
1730786baecfSMauro Carvalho Chehab 	TERRATEC_CINERGY_S,
1731786baecfSMauro Carvalho Chehab 	CYPRESS_DW3101,
1732786baecfSMauro Carvalho Chehab 	TEVII_S630,
1733786baecfSMauro Carvalho Chehab 	PROF_1100,
1734786baecfSMauro Carvalho Chehab 	TEVII_S660,
1735786baecfSMauro Carvalho Chehab 	PROF_7500,
1736786baecfSMauro Carvalho Chehab 	GENIATECH_SU3000,
1737786baecfSMauro Carvalho Chehab 	TERRATEC_CINERGY_S2,
1738786baecfSMauro Carvalho Chehab 	TEVII_S480_1,
1739786baecfSMauro Carvalho Chehab 	TEVII_S480_2,
1740786baecfSMauro Carvalho Chehab 	X3M_SPC1400HD,
1741955d00acSIgor M. Liplianin 	TEVII_S421,
1742955d00acSIgor M. Liplianin 	TEVII_S632,
174344122dd6SIgor M. Liplianin 	TERRATEC_CINERGY_S2_R2,
174449438d97SOlli Salonen 	TERRATEC_CINERGY_S2_R3,
174569fd825cSEnrico Mioso 	TERRATEC_CINERGY_S2_R4,
1746f08e9f0dSAndrey Pavlenko 	GOTVIEW_SAT_HD,
174751d882edSEvgeny Plehov 	GENIATECH_T220,
174827254c36SOlli Salonen 	TECHNOTREND_S2_4600,
174944767fc4SOlli Salonen 	TEVII_S482_1,
175044767fc4SOlli Salonen 	TEVII_S482_2,
175193b66420SPhilipp Zabel 	TERRATEC_CINERGY_S2_BOX,
17526ede20f9SOlli Salonen 	TEVII_S662
1753786baecfSMauro Carvalho Chehab };
1754786baecfSMauro Carvalho Chehab 
1755786baecfSMauro Carvalho Chehab static struct usb_device_id dw2102_table[] = {
1756786baecfSMauro Carvalho Chehab 	[CYPRESS_DW2102] = {USB_DEVICE(USB_VID_CYPRESS, USB_PID_DW2102)},
1757786baecfSMauro Carvalho Chehab 	[CYPRESS_DW2101] = {USB_DEVICE(USB_VID_CYPRESS, 0x2101)},
1758786baecfSMauro Carvalho Chehab 	[CYPRESS_DW2104] = {USB_DEVICE(USB_VID_CYPRESS, USB_PID_DW2104)},
1759786baecfSMauro Carvalho Chehab 	[TEVII_S650] = {USB_DEVICE(0x9022, USB_PID_TEVII_S650)},
1760e8364275SMauro Carvalho Chehab 	[TERRATEC_CINERGY_S] = {USB_DEVICE(USB_VID_TERRATEC, USB_PID_TERRATEC_CINERGY_S)},
1761786baecfSMauro Carvalho Chehab 	[CYPRESS_DW3101] = {USB_DEVICE(USB_VID_CYPRESS, USB_PID_DW3101)},
1762786baecfSMauro Carvalho Chehab 	[TEVII_S630] = {USB_DEVICE(0x9022, USB_PID_TEVII_S630)},
1763786baecfSMauro Carvalho Chehab 	[PROF_1100] = {USB_DEVICE(0x3011, USB_PID_PROF_1100)},
1764786baecfSMauro Carvalho Chehab 	[TEVII_S660] = {USB_DEVICE(0x9022, USB_PID_TEVII_S660)},
1765786baecfSMauro Carvalho Chehab 	[PROF_7500] = {USB_DEVICE(0x3034, 0x7500)},
1766786baecfSMauro Carvalho Chehab 	[GENIATECH_SU3000] = {USB_DEVICE(0x1f4d, 0x3000)},
1767a561d768SMauro Carvalho Chehab 	[TERRATEC_CINERGY_S2] = {USB_DEVICE(USB_VID_TERRATEC, USB_PID_TERRATEC_CINERGY_S2_R1)},
1768786baecfSMauro Carvalho Chehab 	[TEVII_S480_1] = {USB_DEVICE(0x9022, USB_PID_TEVII_S480_1)},
1769786baecfSMauro Carvalho Chehab 	[TEVII_S480_2] = {USB_DEVICE(0x9022, USB_PID_TEVII_S480_2)},
1770786baecfSMauro Carvalho Chehab 	[X3M_SPC1400HD] = {USB_DEVICE(0x1f4d, 0x3100)},
1771955d00acSIgor M. Liplianin 	[TEVII_S421] = {USB_DEVICE(0x9022, USB_PID_TEVII_S421)},
1772955d00acSIgor M. Liplianin 	[TEVII_S632] = {USB_DEVICE(0x9022, USB_PID_TEVII_S632)},
1773a561d768SMauro Carvalho Chehab 	[TERRATEC_CINERGY_S2_R2] = {USB_DEVICE(USB_VID_TERRATEC, USB_PID_TERRATEC_CINERGY_S2_R2)},
177449438d97SOlli Salonen 	[TERRATEC_CINERGY_S2_R3] = {USB_DEVICE(USB_VID_TERRATEC, USB_PID_TERRATEC_CINERGY_S2_R3)},
177569fd825cSEnrico Mioso 	[TERRATEC_CINERGY_S2_R4] = {USB_DEVICE(USB_VID_TERRATEC, USB_PID_TERRATEC_CINERGY_S2_R4)},
1776f08e9f0dSAndrey Pavlenko 	[GOTVIEW_SAT_HD] = {USB_DEVICE(0x1FE1, USB_PID_GOTVIEW_SAT_HD)},
177751d882edSEvgeny Plehov 	[GENIATECH_T220] = {USB_DEVICE(0x1f4d, 0xD220)},
177827254c36SOlli Salonen 	[TECHNOTREND_S2_4600] = {USB_DEVICE(USB_VID_TECHNOTREND,
177927254c36SOlli Salonen 		USB_PID_TECHNOTREND_CONNECT_S2_4600)},
178044767fc4SOlli Salonen 	[TEVII_S482_1] = {USB_DEVICE(0x9022, 0xd483)},
178144767fc4SOlli Salonen 	[TEVII_S482_2] = {USB_DEVICE(0x9022, 0xd484)},
178293b66420SPhilipp Zabel 	[TERRATEC_CINERGY_S2_BOX] = {USB_DEVICE(USB_VID_TERRATEC, 0x0105)},
17836ede20f9SOlli Salonen 	[TEVII_S662] = {USB_DEVICE(0x9022, USB_PID_TEVII_S662)},
1784786baecfSMauro Carvalho Chehab 	{ }
1785786baecfSMauro Carvalho Chehab };
1786786baecfSMauro Carvalho Chehab 
1787786baecfSMauro Carvalho Chehab MODULE_DEVICE_TABLE(usb, dw2102_table);
1788786baecfSMauro Carvalho Chehab 
1789786baecfSMauro Carvalho Chehab static int dw2102_load_firmware(struct usb_device *dev,
1790786baecfSMauro Carvalho Chehab 			const struct firmware *frmwr)
1791786baecfSMauro Carvalho Chehab {
1792786baecfSMauro Carvalho Chehab 	u8 *b, *p;
1793786baecfSMauro Carvalho Chehab 	int ret = 0, i;
1794786baecfSMauro Carvalho Chehab 	u8 reset;
1795786baecfSMauro Carvalho Chehab 	u8 reset16[] = {0, 0, 0, 0, 0, 0, 0};
1796786baecfSMauro Carvalho Chehab 	const struct firmware *fw;
1797786baecfSMauro Carvalho Chehab 
17981ad5d064SHans Verkuil 	switch (le16_to_cpu(dev->descriptor.idProduct)) {
1799786baecfSMauro Carvalho Chehab 	case 0x2101:
18006823627bSRémi Cardona 		ret = request_firmware(&fw, DW2101_FIRMWARE, &dev->dev);
1801786baecfSMauro Carvalho Chehab 		if (ret != 0) {
18026823627bSRémi Cardona 			err(err_str, DW2101_FIRMWARE);
1803786baecfSMauro Carvalho Chehab 			return ret;
1804786baecfSMauro Carvalho Chehab 		}
1805786baecfSMauro Carvalho Chehab 		break;
1806786baecfSMauro Carvalho Chehab 	default:
1807786baecfSMauro Carvalho Chehab 		fw = frmwr;
1808786baecfSMauro Carvalho Chehab 		break;
1809786baecfSMauro Carvalho Chehab 	}
1810786baecfSMauro Carvalho Chehab 	info("start downloading DW210X firmware");
1811786baecfSMauro Carvalho Chehab 	p = kmalloc(fw->size, GFP_KERNEL);
1812786baecfSMauro Carvalho Chehab 	reset = 1;
1813786baecfSMauro Carvalho Chehab 	/*stop the CPU*/
1814786baecfSMauro Carvalho Chehab 	dw210x_op_rw(dev, 0xa0, 0x7f92, 0, &reset, 1, DW210X_WRITE_MSG);
1815786baecfSMauro Carvalho Chehab 	dw210x_op_rw(dev, 0xa0, 0xe600, 0, &reset, 1, DW210X_WRITE_MSG);
1816786baecfSMauro Carvalho Chehab 
1817786baecfSMauro Carvalho Chehab 	if (p != NULL) {
1818786baecfSMauro Carvalho Chehab 		memcpy(p, fw->data, fw->size);
1819786baecfSMauro Carvalho Chehab 		for (i = 0; i < fw->size; i += 0x40) {
1820786baecfSMauro Carvalho Chehab 			b = (u8 *) p + i;
1821786baecfSMauro Carvalho Chehab 			if (dw210x_op_rw(dev, 0xa0, i, 0, b , 0x40,
1822786baecfSMauro Carvalho Chehab 					DW210X_WRITE_MSG) != 0x40) {
1823786baecfSMauro Carvalho Chehab 				err("error while transferring firmware");
1824786baecfSMauro Carvalho Chehab 				ret = -EINVAL;
1825786baecfSMauro Carvalho Chehab 				break;
1826786baecfSMauro Carvalho Chehab 			}
1827786baecfSMauro Carvalho Chehab 		}
1828786baecfSMauro Carvalho Chehab 		/* restart the CPU */
1829786baecfSMauro Carvalho Chehab 		reset = 0;
1830786baecfSMauro Carvalho Chehab 		if (ret || dw210x_op_rw(dev, 0xa0, 0x7f92, 0, &reset, 1,
1831786baecfSMauro Carvalho Chehab 					DW210X_WRITE_MSG) != 1) {
1832786baecfSMauro Carvalho Chehab 			err("could not restart the USB controller CPU.");
1833786baecfSMauro Carvalho Chehab 			ret = -EINVAL;
1834786baecfSMauro Carvalho Chehab 		}
1835786baecfSMauro Carvalho Chehab 		if (ret || dw210x_op_rw(dev, 0xa0, 0xe600, 0, &reset, 1,
1836786baecfSMauro Carvalho Chehab 					DW210X_WRITE_MSG) != 1) {
1837786baecfSMauro Carvalho Chehab 			err("could not restart the USB controller CPU.");
1838786baecfSMauro Carvalho Chehab 			ret = -EINVAL;
1839786baecfSMauro Carvalho Chehab 		}
1840786baecfSMauro Carvalho Chehab 		/* init registers */
18411ad5d064SHans Verkuil 		switch (le16_to_cpu(dev->descriptor.idProduct)) {
1842786baecfSMauro Carvalho Chehab 		case USB_PID_TEVII_S650:
1843a49de26aSEvgeny Plehov 			dw2104_properties.rc.core.rc_codes = RC_MAP_TEVII_NEC;
184406eeefe8SMauro Carvalho Chehab 			/* fall through */
1845786baecfSMauro Carvalho Chehab 		case USB_PID_DW2104:
1846786baecfSMauro Carvalho Chehab 			reset = 1;
1847786baecfSMauro Carvalho Chehab 			dw210x_op_rw(dev, 0xc4, 0x0000, 0, &reset, 1,
1848786baecfSMauro Carvalho Chehab 					DW210X_WRITE_MSG);
184906eeefe8SMauro Carvalho Chehab 			/* fall through */
1850786baecfSMauro Carvalho Chehab 		case USB_PID_DW3101:
1851786baecfSMauro Carvalho Chehab 			reset = 0;
1852786baecfSMauro Carvalho Chehab 			dw210x_op_rw(dev, 0xbf, 0x0040, 0, &reset, 0,
1853786baecfSMauro Carvalho Chehab 					DW210X_WRITE_MSG);
1854786baecfSMauro Carvalho Chehab 			break;
1855e8364275SMauro Carvalho Chehab 		case USB_PID_TERRATEC_CINERGY_S:
1856786baecfSMauro Carvalho Chehab 		case USB_PID_DW2102:
1857786baecfSMauro Carvalho Chehab 			dw210x_op_rw(dev, 0xbf, 0x0040, 0, &reset, 0,
1858786baecfSMauro Carvalho Chehab 					DW210X_WRITE_MSG);
1859786baecfSMauro Carvalho Chehab 			dw210x_op_rw(dev, 0xb9, 0x0000, 0, &reset16[0], 2,
1860786baecfSMauro Carvalho Chehab 					DW210X_READ_MSG);
1861786baecfSMauro Carvalho Chehab 			/* check STV0299 frontend  */
1862786baecfSMauro Carvalho Chehab 			dw210x_op_rw(dev, 0xb5, 0, 0, &reset16[0], 2,
1863786baecfSMauro Carvalho Chehab 					DW210X_READ_MSG);
1864786baecfSMauro Carvalho Chehab 			if ((reset16[0] == 0xa1) || (reset16[0] == 0x80)) {
1865786baecfSMauro Carvalho Chehab 				dw2102_properties.i2c_algo = &dw2102_i2c_algo;
1866786baecfSMauro Carvalho Chehab 				dw2102_properties.adapter->fe[0].tuner_attach = &dw2102_tuner_attach;
1867786baecfSMauro Carvalho Chehab 				break;
1868786baecfSMauro Carvalho Chehab 			} else {
1869786baecfSMauro Carvalho Chehab 				/* check STV0288 frontend  */
1870786baecfSMauro Carvalho Chehab 				reset16[0] = 0xd0;
1871786baecfSMauro Carvalho Chehab 				reset16[1] = 1;
1872786baecfSMauro Carvalho Chehab 				reset16[2] = 0;
1873786baecfSMauro Carvalho Chehab 				dw210x_op_rw(dev, 0xc2, 0, 0, &reset16[0], 3,
1874786baecfSMauro Carvalho Chehab 						DW210X_WRITE_MSG);
1875786baecfSMauro Carvalho Chehab 				dw210x_op_rw(dev, 0xc3, 0xd1, 0, &reset16[0], 3,
1876786baecfSMauro Carvalho Chehab 						DW210X_READ_MSG);
1877786baecfSMauro Carvalho Chehab 				if (reset16[2] == 0x11) {
1878786baecfSMauro Carvalho Chehab 					dw2102_properties.i2c_algo = &dw2102_earda_i2c_algo;
1879786baecfSMauro Carvalho Chehab 					break;
1880786baecfSMauro Carvalho Chehab 				}
1881786baecfSMauro Carvalho Chehab 			}
188206eeefe8SMauro Carvalho Chehab 			/* fall through */
1883786baecfSMauro Carvalho Chehab 		case 0x2101:
1884786baecfSMauro Carvalho Chehab 			dw210x_op_rw(dev, 0xbc, 0x0030, 0, &reset16[0], 2,
1885786baecfSMauro Carvalho Chehab 					DW210X_READ_MSG);
1886786baecfSMauro Carvalho Chehab 			dw210x_op_rw(dev, 0xba, 0x0000, 0, &reset16[0], 7,
1887786baecfSMauro Carvalho Chehab 					DW210X_READ_MSG);
1888786baecfSMauro Carvalho Chehab 			dw210x_op_rw(dev, 0xba, 0x0000, 0, &reset16[0], 7,
1889786baecfSMauro Carvalho Chehab 					DW210X_READ_MSG);
1890786baecfSMauro Carvalho Chehab 			dw210x_op_rw(dev, 0xb9, 0x0000, 0, &reset16[0], 2,
1891786baecfSMauro Carvalho Chehab 					DW210X_READ_MSG);
1892786baecfSMauro Carvalho Chehab 			break;
1893786baecfSMauro Carvalho Chehab 		}
1894786baecfSMauro Carvalho Chehab 
1895786baecfSMauro Carvalho Chehab 		msleep(100);
1896786baecfSMauro Carvalho Chehab 		kfree(p);
1897786baecfSMauro Carvalho Chehab 	}
18982a518f8eSSudip Mukherjee 
18992a518f8eSSudip Mukherjee 	if (le16_to_cpu(dev->descriptor.idProduct) == 0x2101)
19002a518f8eSSudip Mukherjee 		release_firmware(fw);
1901786baecfSMauro Carvalho Chehab 	return ret;
1902786baecfSMauro Carvalho Chehab }
1903786baecfSMauro Carvalho Chehab 
1904786baecfSMauro Carvalho Chehab static struct dvb_usb_device_properties dw2102_properties = {
1905786baecfSMauro Carvalho Chehab 	.caps = DVB_USB_IS_AN_I2C_ADAPTER,
1906786baecfSMauro Carvalho Chehab 	.usb_ctrl = DEVICE_SPECIFIC,
19076823627bSRémi Cardona 	.firmware = DW2102_FIRMWARE,
1908786baecfSMauro Carvalho Chehab 	.no_reconnect = 1,
1909786baecfSMauro Carvalho Chehab 
1910786baecfSMauro Carvalho Chehab 	.i2c_algo = &dw2102_serit_i2c_algo,
1911786baecfSMauro Carvalho Chehab 
1912a49de26aSEvgeny Plehov 	.rc.core = {
1913786baecfSMauro Carvalho Chehab 		.rc_interval = 150,
1914a49de26aSEvgeny Plehov 		.rc_codes = RC_MAP_DM1105_NEC,
1915a49de26aSEvgeny Plehov 		.module_name = "dw2102",
19166d741bfeSSean Young 		.allowed_protos   = RC_PROTO_BIT_NEC,
1917786baecfSMauro Carvalho Chehab 		.rc_query = dw2102_rc_query,
1918786baecfSMauro Carvalho Chehab 	},
1919786baecfSMauro Carvalho Chehab 
1920786baecfSMauro Carvalho Chehab 	.generic_bulk_ctrl_endpoint = 0x81,
1921786baecfSMauro Carvalho Chehab 	/* parameter for the MPEG2-data transfer */
1922786baecfSMauro Carvalho Chehab 	.num_adapters = 1,
1923786baecfSMauro Carvalho Chehab 	.download_firmware = dw2102_load_firmware,
1924786baecfSMauro Carvalho Chehab 	.read_mac_address = dw210x_read_mac_address,
1925786baecfSMauro Carvalho Chehab 	.adapter = {
1926786baecfSMauro Carvalho Chehab 		{
1927786baecfSMauro Carvalho Chehab 		.num_frontends = 1,
1928786baecfSMauro Carvalho Chehab 		.fe = {{
1929786baecfSMauro Carvalho Chehab 			.frontend_attach = dw2102_frontend_attach,
1930786baecfSMauro Carvalho Chehab 			.stream = {
1931786baecfSMauro Carvalho Chehab 				.type = USB_BULK,
1932786baecfSMauro Carvalho Chehab 				.count = 8,
1933786baecfSMauro Carvalho Chehab 				.endpoint = 0x82,
1934786baecfSMauro Carvalho Chehab 				.u = {
1935786baecfSMauro Carvalho Chehab 					.bulk = {
1936786baecfSMauro Carvalho Chehab 						.buffersize = 4096,
1937786baecfSMauro Carvalho Chehab 					}
1938786baecfSMauro Carvalho Chehab 				}
1939786baecfSMauro Carvalho Chehab 			},
1940786baecfSMauro Carvalho Chehab 		}},
1941786baecfSMauro Carvalho Chehab 		}
1942786baecfSMauro Carvalho Chehab 	},
1943786baecfSMauro Carvalho Chehab 	.num_device_descs = 3,
1944786baecfSMauro Carvalho Chehab 	.devices = {
1945786baecfSMauro Carvalho Chehab 		{"DVBWorld DVB-S 2102 USB2.0",
1946786baecfSMauro Carvalho Chehab 			{&dw2102_table[CYPRESS_DW2102], NULL},
1947786baecfSMauro Carvalho Chehab 			{NULL},
1948786baecfSMauro Carvalho Chehab 		},
1949786baecfSMauro Carvalho Chehab 		{"DVBWorld DVB-S 2101 USB2.0",
1950786baecfSMauro Carvalho Chehab 			{&dw2102_table[CYPRESS_DW2101], NULL},
1951786baecfSMauro Carvalho Chehab 			{NULL},
1952786baecfSMauro Carvalho Chehab 		},
1953786baecfSMauro Carvalho Chehab 		{"TerraTec Cinergy S USB",
1954786baecfSMauro Carvalho Chehab 			{&dw2102_table[TERRATEC_CINERGY_S], NULL},
1955786baecfSMauro Carvalho Chehab 			{NULL},
1956786baecfSMauro Carvalho Chehab 		},
1957786baecfSMauro Carvalho Chehab 	}
1958786baecfSMauro Carvalho Chehab };
1959786baecfSMauro Carvalho Chehab 
1960786baecfSMauro Carvalho Chehab static struct dvb_usb_device_properties dw2104_properties = {
1961786baecfSMauro Carvalho Chehab 	.caps = DVB_USB_IS_AN_I2C_ADAPTER,
1962786baecfSMauro Carvalho Chehab 	.usb_ctrl = DEVICE_SPECIFIC,
19636823627bSRémi Cardona 	.firmware = DW2104_FIRMWARE,
1964786baecfSMauro Carvalho Chehab 	.no_reconnect = 1,
1965786baecfSMauro Carvalho Chehab 
1966786baecfSMauro Carvalho Chehab 	.i2c_algo = &dw2104_i2c_algo,
1967a49de26aSEvgeny Plehov 	.rc.core = {
1968786baecfSMauro Carvalho Chehab 		.rc_interval = 150,
1969a49de26aSEvgeny Plehov 		.rc_codes = RC_MAP_DM1105_NEC,
1970a49de26aSEvgeny Plehov 		.module_name = "dw2102",
19716d741bfeSSean Young 		.allowed_protos   = RC_PROTO_BIT_NEC,
1972786baecfSMauro Carvalho Chehab 		.rc_query = dw2102_rc_query,
1973786baecfSMauro Carvalho Chehab 	},
1974786baecfSMauro Carvalho Chehab 
1975786baecfSMauro Carvalho Chehab 	.generic_bulk_ctrl_endpoint = 0x81,
1976786baecfSMauro Carvalho Chehab 	/* parameter for the MPEG2-data transfer */
1977786baecfSMauro Carvalho Chehab 	.num_adapters = 1,
1978786baecfSMauro Carvalho Chehab 	.download_firmware = dw2102_load_firmware,
1979786baecfSMauro Carvalho Chehab 	.read_mac_address = dw210x_read_mac_address,
1980786baecfSMauro Carvalho Chehab 	.adapter = {
1981786baecfSMauro Carvalho Chehab 		{
1982786baecfSMauro Carvalho Chehab 		.num_frontends = 1,
1983786baecfSMauro Carvalho Chehab 		.fe = {{
1984786baecfSMauro Carvalho Chehab 			.frontend_attach = dw2104_frontend_attach,
1985786baecfSMauro Carvalho Chehab 			.stream = {
1986786baecfSMauro Carvalho Chehab 				.type = USB_BULK,
1987786baecfSMauro Carvalho Chehab 				.count = 8,
1988786baecfSMauro Carvalho Chehab 				.endpoint = 0x82,
1989786baecfSMauro Carvalho Chehab 				.u = {
1990786baecfSMauro Carvalho Chehab 					.bulk = {
1991786baecfSMauro Carvalho Chehab 						.buffersize = 4096,
1992786baecfSMauro Carvalho Chehab 					}
1993786baecfSMauro Carvalho Chehab 				}
1994786baecfSMauro Carvalho Chehab 			},
1995786baecfSMauro Carvalho Chehab 		}},
1996786baecfSMauro Carvalho Chehab 		}
1997786baecfSMauro Carvalho Chehab 	},
1998786baecfSMauro Carvalho Chehab 	.num_device_descs = 2,
1999786baecfSMauro Carvalho Chehab 	.devices = {
2000786baecfSMauro Carvalho Chehab 		{ "DVBWorld DW2104 USB2.0",
2001786baecfSMauro Carvalho Chehab 			{&dw2102_table[CYPRESS_DW2104], NULL},
2002786baecfSMauro Carvalho Chehab 			{NULL},
2003786baecfSMauro Carvalho Chehab 		},
2004786baecfSMauro Carvalho Chehab 		{ "TeVii S650 USB2.0",
2005786baecfSMauro Carvalho Chehab 			{&dw2102_table[TEVII_S650], NULL},
2006786baecfSMauro Carvalho Chehab 			{NULL},
2007786baecfSMauro Carvalho Chehab 		},
2008786baecfSMauro Carvalho Chehab 	}
2009786baecfSMauro Carvalho Chehab };
2010786baecfSMauro Carvalho Chehab 
2011786baecfSMauro Carvalho Chehab static struct dvb_usb_device_properties dw3101_properties = {
2012786baecfSMauro Carvalho Chehab 	.caps = DVB_USB_IS_AN_I2C_ADAPTER,
2013786baecfSMauro Carvalho Chehab 	.usb_ctrl = DEVICE_SPECIFIC,
20146823627bSRémi Cardona 	.firmware = DW3101_FIRMWARE,
2015786baecfSMauro Carvalho Chehab 	.no_reconnect = 1,
2016786baecfSMauro Carvalho Chehab 
2017786baecfSMauro Carvalho Chehab 	.i2c_algo = &dw3101_i2c_algo,
2018a49de26aSEvgeny Plehov 	.rc.core = {
2019786baecfSMauro Carvalho Chehab 		.rc_interval = 150,
2020a49de26aSEvgeny Plehov 		.rc_codes = RC_MAP_DM1105_NEC,
2021a49de26aSEvgeny Plehov 		.module_name = "dw2102",
20226d741bfeSSean Young 		.allowed_protos   = RC_PROTO_BIT_NEC,
2023786baecfSMauro Carvalho Chehab 		.rc_query = dw2102_rc_query,
2024786baecfSMauro Carvalho Chehab 	},
2025786baecfSMauro Carvalho Chehab 
2026786baecfSMauro Carvalho Chehab 	.generic_bulk_ctrl_endpoint = 0x81,
2027786baecfSMauro Carvalho Chehab 	/* parameter for the MPEG2-data transfer */
2028786baecfSMauro Carvalho Chehab 	.num_adapters = 1,
2029786baecfSMauro Carvalho Chehab 	.download_firmware = dw2102_load_firmware,
2030786baecfSMauro Carvalho Chehab 	.read_mac_address = dw210x_read_mac_address,
2031786baecfSMauro Carvalho Chehab 	.adapter = {
2032786baecfSMauro Carvalho Chehab 		{
2033786baecfSMauro Carvalho Chehab 		.num_frontends = 1,
2034786baecfSMauro Carvalho Chehab 		.fe = {{
2035786baecfSMauro Carvalho Chehab 			.frontend_attach = dw3101_frontend_attach,
2036786baecfSMauro Carvalho Chehab 			.tuner_attach = dw3101_tuner_attach,
2037786baecfSMauro Carvalho Chehab 			.stream = {
2038786baecfSMauro Carvalho Chehab 				.type = USB_BULK,
2039786baecfSMauro Carvalho Chehab 				.count = 8,
2040786baecfSMauro Carvalho Chehab 				.endpoint = 0x82,
2041786baecfSMauro Carvalho Chehab 				.u = {
2042786baecfSMauro Carvalho Chehab 					.bulk = {
2043786baecfSMauro Carvalho Chehab 						.buffersize = 4096,
2044786baecfSMauro Carvalho Chehab 					}
2045786baecfSMauro Carvalho Chehab 				}
2046786baecfSMauro Carvalho Chehab 			},
2047786baecfSMauro Carvalho Chehab 		}},
2048786baecfSMauro Carvalho Chehab 		}
2049786baecfSMauro Carvalho Chehab 	},
2050786baecfSMauro Carvalho Chehab 	.num_device_descs = 1,
2051786baecfSMauro Carvalho Chehab 	.devices = {
2052786baecfSMauro Carvalho Chehab 		{ "DVBWorld DVB-C 3101 USB2.0",
2053786baecfSMauro Carvalho Chehab 			{&dw2102_table[CYPRESS_DW3101], NULL},
2054786baecfSMauro Carvalho Chehab 			{NULL},
2055786baecfSMauro Carvalho Chehab 		},
2056786baecfSMauro Carvalho Chehab 	}
2057786baecfSMauro Carvalho Chehab };
2058786baecfSMauro Carvalho Chehab 
2059786baecfSMauro Carvalho Chehab static struct dvb_usb_device_properties s6x0_properties = {
2060786baecfSMauro Carvalho Chehab 	.caps = DVB_USB_IS_AN_I2C_ADAPTER,
2061786baecfSMauro Carvalho Chehab 	.usb_ctrl = DEVICE_SPECIFIC,
20622c4ffe27SOlli Salonen 	.size_of_priv = sizeof(struct dw2102_state),
20636823627bSRémi Cardona 	.firmware = S630_FIRMWARE,
2064786baecfSMauro Carvalho Chehab 	.no_reconnect = 1,
2065786baecfSMauro Carvalho Chehab 
2066786baecfSMauro Carvalho Chehab 	.i2c_algo = &s6x0_i2c_algo,
2067a49de26aSEvgeny Plehov 	.rc.core = {
2068786baecfSMauro Carvalho Chehab 		.rc_interval = 150,
2069a49de26aSEvgeny Plehov 		.rc_codes = RC_MAP_TEVII_NEC,
2070a49de26aSEvgeny Plehov 		.module_name = "dw2102",
20716d741bfeSSean Young 		.allowed_protos   = RC_PROTO_BIT_NEC,
2072786baecfSMauro Carvalho Chehab 		.rc_query = dw2102_rc_query,
2073786baecfSMauro Carvalho Chehab 	},
2074786baecfSMauro Carvalho Chehab 
2075786baecfSMauro Carvalho Chehab 	.generic_bulk_ctrl_endpoint = 0x81,
2076786baecfSMauro Carvalho Chehab 	.num_adapters = 1,
2077786baecfSMauro Carvalho Chehab 	.download_firmware = dw2102_load_firmware,
2078786baecfSMauro Carvalho Chehab 	.read_mac_address = s6x0_read_mac_address,
2079786baecfSMauro Carvalho Chehab 	.adapter = {
2080786baecfSMauro Carvalho Chehab 		{
2081786baecfSMauro Carvalho Chehab 		.num_frontends = 1,
2082786baecfSMauro Carvalho Chehab 		.fe = {{
2083786baecfSMauro Carvalho Chehab 			.frontend_attach = zl100313_frontend_attach,
2084786baecfSMauro Carvalho Chehab 			.stream = {
2085786baecfSMauro Carvalho Chehab 				.type = USB_BULK,
2086786baecfSMauro Carvalho Chehab 				.count = 8,
2087786baecfSMauro Carvalho Chehab 				.endpoint = 0x82,
2088786baecfSMauro Carvalho Chehab 				.u = {
2089786baecfSMauro Carvalho Chehab 					.bulk = {
2090786baecfSMauro Carvalho Chehab 						.buffersize = 4096,
2091786baecfSMauro Carvalho Chehab 					}
2092786baecfSMauro Carvalho Chehab 				}
2093786baecfSMauro Carvalho Chehab 			},
2094786baecfSMauro Carvalho Chehab 		}},
2095786baecfSMauro Carvalho Chehab 		}
2096786baecfSMauro Carvalho Chehab 	},
2097786baecfSMauro Carvalho Chehab 	.num_device_descs = 1,
2098786baecfSMauro Carvalho Chehab 	.devices = {
2099786baecfSMauro Carvalho Chehab 		{"TeVii S630 USB",
2100786baecfSMauro Carvalho Chehab 			{&dw2102_table[TEVII_S630], NULL},
2101786baecfSMauro Carvalho Chehab 			{NULL},
2102786baecfSMauro Carvalho Chehab 		},
2103786baecfSMauro Carvalho Chehab 	}
2104786baecfSMauro Carvalho Chehab };
2105786baecfSMauro Carvalho Chehab 
21061ad5d064SHans Verkuil static struct dvb_usb_device_properties *p1100;
2107651ac129SBhumika Goyal static const struct dvb_usb_device_description d1100 = {
2108786baecfSMauro Carvalho Chehab 	"Prof 1100 USB ",
2109786baecfSMauro Carvalho Chehab 	{&dw2102_table[PROF_1100], NULL},
2110786baecfSMauro Carvalho Chehab 	{NULL},
2111786baecfSMauro Carvalho Chehab };
2112786baecfSMauro Carvalho Chehab 
21131ad5d064SHans Verkuil static struct dvb_usb_device_properties *s660;
2114651ac129SBhumika Goyal static const struct dvb_usb_device_description d660 = {
2115786baecfSMauro Carvalho Chehab 	"TeVii S660 USB",
2116786baecfSMauro Carvalho Chehab 	{&dw2102_table[TEVII_S660], NULL},
2117786baecfSMauro Carvalho Chehab 	{NULL},
2118786baecfSMauro Carvalho Chehab };
2119786baecfSMauro Carvalho Chehab 
2120651ac129SBhumika Goyal static const struct dvb_usb_device_description d480_1 = {
2121786baecfSMauro Carvalho Chehab 	"TeVii S480.1 USB",
2122786baecfSMauro Carvalho Chehab 	{&dw2102_table[TEVII_S480_1], NULL},
2123786baecfSMauro Carvalho Chehab 	{NULL},
2124786baecfSMauro Carvalho Chehab };
2125786baecfSMauro Carvalho Chehab 
2126651ac129SBhumika Goyal static const struct dvb_usb_device_description d480_2 = {
2127786baecfSMauro Carvalho Chehab 	"TeVii S480.2 USB",
2128786baecfSMauro Carvalho Chehab 	{&dw2102_table[TEVII_S480_2], NULL},
2129786baecfSMauro Carvalho Chehab 	{NULL},
2130786baecfSMauro Carvalho Chehab };
2131786baecfSMauro Carvalho Chehab 
21321ad5d064SHans Verkuil static struct dvb_usb_device_properties *p7500;
2133651ac129SBhumika Goyal static const struct dvb_usb_device_description d7500 = {
2134786baecfSMauro Carvalho Chehab 	"Prof 7500 USB DVB-S2",
2135786baecfSMauro Carvalho Chehab 	{&dw2102_table[PROF_7500], NULL},
2136786baecfSMauro Carvalho Chehab 	{NULL},
2137786baecfSMauro Carvalho Chehab };
2138786baecfSMauro Carvalho Chehab 
21391ad5d064SHans Verkuil static struct dvb_usb_device_properties *s421;
2140651ac129SBhumika Goyal static const struct dvb_usb_device_description d421 = {
2141955d00acSIgor M. Liplianin 	"TeVii S421 PCI",
2142955d00acSIgor M. Liplianin 	{&dw2102_table[TEVII_S421], NULL},
2143955d00acSIgor M. Liplianin 	{NULL},
2144955d00acSIgor M. Liplianin };
2145955d00acSIgor M. Liplianin 
2146651ac129SBhumika Goyal static const struct dvb_usb_device_description d632 = {
2147955d00acSIgor M. Liplianin 	"TeVii S632 USB",
2148955d00acSIgor M. Liplianin 	{&dw2102_table[TEVII_S632], NULL},
2149955d00acSIgor M. Liplianin 	{NULL},
2150955d00acSIgor M. Liplianin };
2151955d00acSIgor M. Liplianin 
2152786baecfSMauro Carvalho Chehab static struct dvb_usb_device_properties su3000_properties = {
2153786baecfSMauro Carvalho Chehab 	.caps = DVB_USB_IS_AN_I2C_ADAPTER,
2154786baecfSMauro Carvalho Chehab 	.usb_ctrl = DEVICE_SPECIFIC,
21552c4ffe27SOlli Salonen 	.size_of_priv = sizeof(struct dw2102_state),
2156786baecfSMauro Carvalho Chehab 	.power_ctrl = su3000_power_ctrl,
2157786baecfSMauro Carvalho Chehab 	.num_adapters = 1,
2158786baecfSMauro Carvalho Chehab 	.identify_state	= su3000_identify_state,
2159786baecfSMauro Carvalho Chehab 	.i2c_algo = &su3000_i2c_algo,
2160786baecfSMauro Carvalho Chehab 
2161a49de26aSEvgeny Plehov 	.rc.core = {
2162786baecfSMauro Carvalho Chehab 		.rc_interval = 150,
2163a49de26aSEvgeny Plehov 		.rc_codes = RC_MAP_SU3000,
2164a49de26aSEvgeny Plehov 		.module_name = "dw2102",
21656d741bfeSSean Young 		.allowed_protos   = RC_PROTO_BIT_RC5,
2166a49de26aSEvgeny Plehov 		.rc_query = su3000_rc_query,
2167786baecfSMauro Carvalho Chehab 	},
2168786baecfSMauro Carvalho Chehab 
2169786baecfSMauro Carvalho Chehab 	.read_mac_address = su3000_read_mac_address,
2170786baecfSMauro Carvalho Chehab 
2171786baecfSMauro Carvalho Chehab 	.generic_bulk_ctrl_endpoint = 0x01,
2172786baecfSMauro Carvalho Chehab 
2173786baecfSMauro Carvalho Chehab 	.adapter = {
2174786baecfSMauro Carvalho Chehab 		{
2175786baecfSMauro Carvalho Chehab 		.num_frontends = 1,
2176786baecfSMauro Carvalho Chehab 		.fe = {{
2177786baecfSMauro Carvalho Chehab 			.streaming_ctrl   = su3000_streaming_ctrl,
2178786baecfSMauro Carvalho Chehab 			.frontend_attach  = su3000_frontend_attach,
2179786baecfSMauro Carvalho Chehab 			.stream = {
2180786baecfSMauro Carvalho Chehab 				.type = USB_BULK,
2181786baecfSMauro Carvalho Chehab 				.count = 8,
2182786baecfSMauro Carvalho Chehab 				.endpoint = 0x82,
2183786baecfSMauro Carvalho Chehab 				.u = {
2184786baecfSMauro Carvalho Chehab 					.bulk = {
2185786baecfSMauro Carvalho Chehab 						.buffersize = 4096,
2186786baecfSMauro Carvalho Chehab 					}
2187786baecfSMauro Carvalho Chehab 				}
2188786baecfSMauro Carvalho Chehab 			}
2189786baecfSMauro Carvalho Chehab 		}},
2190786baecfSMauro Carvalho Chehab 		}
2191786baecfSMauro Carvalho Chehab 	},
219249438d97SOlli Salonen 	.num_device_descs = 6,
2193786baecfSMauro Carvalho Chehab 	.devices = {
2194786baecfSMauro Carvalho Chehab 		{ "SU3000HD DVB-S USB2.0",
2195786baecfSMauro Carvalho Chehab 			{ &dw2102_table[GENIATECH_SU3000], NULL },
2196786baecfSMauro Carvalho Chehab 			{ NULL },
2197786baecfSMauro Carvalho Chehab 		},
2198786baecfSMauro Carvalho Chehab 		{ "Terratec Cinergy S2 USB HD",
2199786baecfSMauro Carvalho Chehab 			{ &dw2102_table[TERRATEC_CINERGY_S2], NULL },
2200786baecfSMauro Carvalho Chehab 			{ NULL },
2201786baecfSMauro Carvalho Chehab 		},
2202786baecfSMauro Carvalho Chehab 		{ "X3M TV SPC1400HD PCI",
2203786baecfSMauro Carvalho Chehab 			{ &dw2102_table[X3M_SPC1400HD], NULL },
2204786baecfSMauro Carvalho Chehab 			{ NULL },
2205786baecfSMauro Carvalho Chehab 		},
220644122dd6SIgor M. Liplianin 		{ "Terratec Cinergy S2 USB HD Rev.2",
220744122dd6SIgor M. Liplianin 			{ &dw2102_table[TERRATEC_CINERGY_S2_R2], NULL },
220844122dd6SIgor M. Liplianin 			{ NULL },
220944122dd6SIgor M. Liplianin 		},
221049438d97SOlli Salonen 		{ "Terratec Cinergy S2 USB HD Rev.3",
221149438d97SOlli Salonen 			{ &dw2102_table[TERRATEC_CINERGY_S2_R3], NULL },
221249438d97SOlli Salonen 			{ NULL },
221349438d97SOlli Salonen 		},
2214f08e9f0dSAndrey Pavlenko 		{ "GOTVIEW Satellite HD",
2215f08e9f0dSAndrey Pavlenko 			{ &dw2102_table[GOTVIEW_SAT_HD], NULL },
2216f08e9f0dSAndrey Pavlenko 			{ NULL },
2217f08e9f0dSAndrey Pavlenko 		},
2218786baecfSMauro Carvalho Chehab 	}
2219786baecfSMauro Carvalho Chehab };
2220786baecfSMauro Carvalho Chehab 
222151d882edSEvgeny Plehov static struct dvb_usb_device_properties t220_properties = {
222251d882edSEvgeny Plehov 	.caps = DVB_USB_IS_AN_I2C_ADAPTER,
222351d882edSEvgeny Plehov 	.usb_ctrl = DEVICE_SPECIFIC,
22242c4ffe27SOlli Salonen 	.size_of_priv = sizeof(struct dw2102_state),
222551d882edSEvgeny Plehov 	.power_ctrl = su3000_power_ctrl,
222651d882edSEvgeny Plehov 	.num_adapters = 1,
222751d882edSEvgeny Plehov 	.identify_state	= su3000_identify_state,
222851d882edSEvgeny Plehov 	.i2c_algo = &su3000_i2c_algo,
222951d882edSEvgeny Plehov 
2230a49de26aSEvgeny Plehov 	.rc.core = {
223151d882edSEvgeny Plehov 		.rc_interval = 150,
2232a49de26aSEvgeny Plehov 		.rc_codes = RC_MAP_SU3000,
2233a49de26aSEvgeny Plehov 		.module_name = "dw2102",
22346d741bfeSSean Young 		.allowed_protos   = RC_PROTO_BIT_RC5,
2235a49de26aSEvgeny Plehov 		.rc_query = su3000_rc_query,
223651d882edSEvgeny Plehov 	},
223751d882edSEvgeny Plehov 
223851d882edSEvgeny Plehov 	.read_mac_address = su3000_read_mac_address,
223951d882edSEvgeny Plehov 
224051d882edSEvgeny Plehov 	.generic_bulk_ctrl_endpoint = 0x01,
224151d882edSEvgeny Plehov 
224251d882edSEvgeny Plehov 	.adapter = {
224351d882edSEvgeny Plehov 		{
224451d882edSEvgeny Plehov 		.num_frontends = 1,
224551d882edSEvgeny Plehov 		.fe = { {
224651d882edSEvgeny Plehov 			.streaming_ctrl   = su3000_streaming_ctrl,
224751d882edSEvgeny Plehov 			.frontend_attach  = t220_frontend_attach,
224851d882edSEvgeny Plehov 			.stream = {
224951d882edSEvgeny Plehov 				.type = USB_BULK,
225051d882edSEvgeny Plehov 				.count = 8,
225151d882edSEvgeny Plehov 				.endpoint = 0x82,
225251d882edSEvgeny Plehov 				.u = {
225351d882edSEvgeny Plehov 					.bulk = {
225451d882edSEvgeny Plehov 						.buffersize = 4096,
225551d882edSEvgeny Plehov 					}
225651d882edSEvgeny Plehov 				}
225751d882edSEvgeny Plehov 			}
225851d882edSEvgeny Plehov 		} },
225951d882edSEvgeny Plehov 		}
226051d882edSEvgeny Plehov 	},
226151d882edSEvgeny Plehov 	.num_device_descs = 1,
226251d882edSEvgeny Plehov 	.devices = {
226351d882edSEvgeny Plehov 		{ "Geniatech T220 DVB-T/T2 USB2.0",
226451d882edSEvgeny Plehov 			{ &dw2102_table[GENIATECH_T220], NULL },
226551d882edSEvgeny Plehov 			{ NULL },
226651d882edSEvgeny Plehov 		},
226751d882edSEvgeny Plehov 	}
226851d882edSEvgeny Plehov };
226951d882edSEvgeny Plehov 
227027254c36SOlli Salonen static struct dvb_usb_device_properties tt_s2_4600_properties = {
227127254c36SOlli Salonen 	.caps = DVB_USB_IS_AN_I2C_ADAPTER,
227227254c36SOlli Salonen 	.usb_ctrl = DEVICE_SPECIFIC,
227327254c36SOlli Salonen 	.size_of_priv = sizeof(struct dw2102_state),
227427254c36SOlli Salonen 	.power_ctrl = su3000_power_ctrl,
227527254c36SOlli Salonen 	.num_adapters = 1,
227627254c36SOlli Salonen 	.identify_state	= su3000_identify_state,
227727254c36SOlli Salonen 	.i2c_algo = &su3000_i2c_algo,
227827254c36SOlli Salonen 
227927254c36SOlli Salonen 	.rc.core = {
228027254c36SOlli Salonen 		.rc_interval = 250,
228127254c36SOlli Salonen 		.rc_codes = RC_MAP_TT_1500,
228227254c36SOlli Salonen 		.module_name = "dw2102",
22836d741bfeSSean Young 		.allowed_protos   = RC_PROTO_BIT_RC5,
228427254c36SOlli Salonen 		.rc_query = su3000_rc_query,
228527254c36SOlli Salonen 	},
228627254c36SOlli Salonen 
228727254c36SOlli Salonen 	.read_mac_address = su3000_read_mac_address,
228827254c36SOlli Salonen 
228927254c36SOlli Salonen 	.generic_bulk_ctrl_endpoint = 0x01,
229027254c36SOlli Salonen 
229127254c36SOlli Salonen 	.adapter = {
229227254c36SOlli Salonen 		{
229327254c36SOlli Salonen 		.num_frontends = 1,
229427254c36SOlli Salonen 		.fe = {{
229527254c36SOlli Salonen 			.streaming_ctrl   = su3000_streaming_ctrl,
229627254c36SOlli Salonen 			.frontend_attach  = tt_s2_4600_frontend_attach,
229727254c36SOlli Salonen 			.stream = {
229827254c36SOlli Salonen 				.type = USB_BULK,
229927254c36SOlli Salonen 				.count = 8,
230027254c36SOlli Salonen 				.endpoint = 0x82,
230127254c36SOlli Salonen 				.u = {
230227254c36SOlli Salonen 					.bulk = {
230327254c36SOlli Salonen 						.buffersize = 4096,
230427254c36SOlli Salonen 					}
230527254c36SOlli Salonen 				}
230627254c36SOlli Salonen 			}
230727254c36SOlli Salonen 		} },
230827254c36SOlli Salonen 		}
230927254c36SOlli Salonen 	},
23106ede20f9SOlli Salonen 	.num_device_descs = 5,
231127254c36SOlli Salonen 	.devices = {
231227254c36SOlli Salonen 		{ "TechnoTrend TT-connect S2-4600",
231327254c36SOlli Salonen 			{ &dw2102_table[TECHNOTREND_S2_4600], NULL },
231427254c36SOlli Salonen 			{ NULL },
231527254c36SOlli Salonen 		},
231644767fc4SOlli Salonen 		{ "TeVii S482 (tuner 1)",
231744767fc4SOlli Salonen 			{ &dw2102_table[TEVII_S482_1], NULL },
231844767fc4SOlli Salonen 			{ NULL },
231944767fc4SOlli Salonen 		},
232044767fc4SOlli Salonen 		{ "TeVii S482 (tuner 2)",
232144767fc4SOlli Salonen 			{ &dw2102_table[TEVII_S482_2], NULL },
232244767fc4SOlli Salonen 			{ NULL },
232344767fc4SOlli Salonen 		},
232493b66420SPhilipp Zabel 		{ "Terratec Cinergy S2 USB BOX",
232593b66420SPhilipp Zabel 			{ &dw2102_table[TERRATEC_CINERGY_S2_BOX], NULL },
232693b66420SPhilipp Zabel 			{ NULL },
232793b66420SPhilipp Zabel 		},
23286ede20f9SOlli Salonen 		{ "TeVii S662",
23296ede20f9SOlli Salonen 			{ &dw2102_table[TEVII_S662], NULL },
23306ede20f9SOlli Salonen 			{ NULL },
23316ede20f9SOlli Salonen 		},
233227254c36SOlli Salonen 	}
233327254c36SOlli Salonen };
233427254c36SOlli Salonen 
2335786baecfSMauro Carvalho Chehab static int dw2102_probe(struct usb_interface *intf,
2336786baecfSMauro Carvalho Chehab 		const struct usb_device_id *id)
2337786baecfSMauro Carvalho Chehab {
2338be90cc8eSAnton Vasilyev 	int retval = -ENOMEM;
2339786baecfSMauro Carvalho Chehab 	p1100 = kmemdup(&s6x0_properties,
2340786baecfSMauro Carvalho Chehab 			sizeof(struct dvb_usb_device_properties), GFP_KERNEL);
2341786baecfSMauro Carvalho Chehab 	if (!p1100)
2342be90cc8eSAnton Vasilyev 		goto err0;
2343be90cc8eSAnton Vasilyev 
2344786baecfSMauro Carvalho Chehab 	/* copy default structure */
2345786baecfSMauro Carvalho Chehab 	/* fill only different fields */
23466823627bSRémi Cardona 	p1100->firmware = P1100_FIRMWARE;
2347786baecfSMauro Carvalho Chehab 	p1100->devices[0] = d1100;
2348a49de26aSEvgeny Plehov 	p1100->rc.core.rc_query = prof_rc_query;
2349a49de26aSEvgeny Plehov 	p1100->rc.core.rc_codes = RC_MAP_TBS_NEC;
2350786baecfSMauro Carvalho Chehab 	p1100->adapter->fe[0].frontend_attach = stv0288_frontend_attach;
2351786baecfSMauro Carvalho Chehab 
2352786baecfSMauro Carvalho Chehab 	s660 = kmemdup(&s6x0_properties,
2353786baecfSMauro Carvalho Chehab 		       sizeof(struct dvb_usb_device_properties), GFP_KERNEL);
2354be90cc8eSAnton Vasilyev 	if (!s660)
2355be90cc8eSAnton Vasilyev 		goto err1;
2356be90cc8eSAnton Vasilyev 
23576823627bSRémi Cardona 	s660->firmware = S660_FIRMWARE;
2358786baecfSMauro Carvalho Chehab 	s660->num_device_descs = 3;
2359786baecfSMauro Carvalho Chehab 	s660->devices[0] = d660;
2360786baecfSMauro Carvalho Chehab 	s660->devices[1] = d480_1;
2361786baecfSMauro Carvalho Chehab 	s660->devices[2] = d480_2;
2362786baecfSMauro Carvalho Chehab 	s660->adapter->fe[0].frontend_attach = ds3000_frontend_attach;
2363786baecfSMauro Carvalho Chehab 
2364786baecfSMauro Carvalho Chehab 	p7500 = kmemdup(&s6x0_properties,
2365786baecfSMauro Carvalho Chehab 			sizeof(struct dvb_usb_device_properties), GFP_KERNEL);
2366be90cc8eSAnton Vasilyev 	if (!p7500)
2367be90cc8eSAnton Vasilyev 		goto err2;
2368be90cc8eSAnton Vasilyev 
23696823627bSRémi Cardona 	p7500->firmware = P7500_FIRMWARE;
2370786baecfSMauro Carvalho Chehab 	p7500->devices[0] = d7500;
2371a49de26aSEvgeny Plehov 	p7500->rc.core.rc_query = prof_rc_query;
2372a49de26aSEvgeny Plehov 	p7500->rc.core.rc_codes = RC_MAP_TBS_NEC;
2373786baecfSMauro Carvalho Chehab 	p7500->adapter->fe[0].frontend_attach = prof_7500_frontend_attach;
2374786baecfSMauro Carvalho Chehab 
2375955d00acSIgor M. Liplianin 
2376955d00acSIgor M. Liplianin 	s421 = kmemdup(&su3000_properties,
2377955d00acSIgor M. Liplianin 		       sizeof(struct dvb_usb_device_properties), GFP_KERNEL);
2378be90cc8eSAnton Vasilyev 	if (!s421)
2379be90cc8eSAnton Vasilyev 		goto err3;
2380be90cc8eSAnton Vasilyev 
2381955d00acSIgor M. Liplianin 	s421->num_device_descs = 2;
2382955d00acSIgor M. Liplianin 	s421->devices[0] = d421;
2383955d00acSIgor M. Liplianin 	s421->devices[1] = d632;
2384955d00acSIgor M. Liplianin 	s421->adapter->fe[0].frontend_attach = m88rs2000_frontend_attach;
2385955d00acSIgor M. Liplianin 
2386786baecfSMauro Carvalho Chehab 	if (0 == dvb_usb_device_init(intf, &dw2102_properties,
2387786baecfSMauro Carvalho Chehab 			THIS_MODULE, NULL, adapter_nr) ||
2388786baecfSMauro Carvalho Chehab 	    0 == dvb_usb_device_init(intf, &dw2104_properties,
2389786baecfSMauro Carvalho Chehab 			THIS_MODULE, NULL, adapter_nr) ||
2390786baecfSMauro Carvalho Chehab 	    0 == dvb_usb_device_init(intf, &dw3101_properties,
2391786baecfSMauro Carvalho Chehab 			THIS_MODULE, NULL, adapter_nr) ||
2392786baecfSMauro Carvalho Chehab 	    0 == dvb_usb_device_init(intf, &s6x0_properties,
2393786baecfSMauro Carvalho Chehab 			THIS_MODULE, NULL, adapter_nr) ||
2394786baecfSMauro Carvalho Chehab 	    0 == dvb_usb_device_init(intf, p1100,
2395786baecfSMauro Carvalho Chehab 			THIS_MODULE, NULL, adapter_nr) ||
2396786baecfSMauro Carvalho Chehab 	    0 == dvb_usb_device_init(intf, s660,
2397786baecfSMauro Carvalho Chehab 			THIS_MODULE, NULL, adapter_nr) ||
2398786baecfSMauro Carvalho Chehab 	    0 == dvb_usb_device_init(intf, p7500,
2399786baecfSMauro Carvalho Chehab 			THIS_MODULE, NULL, adapter_nr) ||
2400955d00acSIgor M. Liplianin 	    0 == dvb_usb_device_init(intf, s421,
2401955d00acSIgor M. Liplianin 			THIS_MODULE, NULL, adapter_nr) ||
2402786baecfSMauro Carvalho Chehab 	    0 == dvb_usb_device_init(intf, &su3000_properties,
240351d882edSEvgeny Plehov 			 THIS_MODULE, NULL, adapter_nr) ||
240451d882edSEvgeny Plehov 	    0 == dvb_usb_device_init(intf, &t220_properties,
240527254c36SOlli Salonen 			 THIS_MODULE, NULL, adapter_nr) ||
240627254c36SOlli Salonen 	    0 == dvb_usb_device_init(intf, &tt_s2_4600_properties,
2407786baecfSMauro Carvalho Chehab 			 THIS_MODULE, NULL, adapter_nr))
2408786baecfSMauro Carvalho Chehab 		return 0;
2409786baecfSMauro Carvalho Chehab 
2410be90cc8eSAnton Vasilyev 	retval = -ENODEV;
2411be90cc8eSAnton Vasilyev 	kfree(s421);
2412be90cc8eSAnton Vasilyev err3:
2413be90cc8eSAnton Vasilyev 	kfree(p7500);
2414be90cc8eSAnton Vasilyev err2:
2415be90cc8eSAnton Vasilyev 	kfree(s660);
2416be90cc8eSAnton Vasilyev err1:
2417be90cc8eSAnton Vasilyev 	kfree(p1100);
2418be90cc8eSAnton Vasilyev err0:
2419be90cc8eSAnton Vasilyev 	return retval;
2420786baecfSMauro Carvalho Chehab }
2421786baecfSMauro Carvalho Chehab 
242270769b24SOlli Salonen static void dw2102_disconnect(struct usb_interface *intf)
242370769b24SOlli Salonen {
242470769b24SOlli Salonen 	struct dvb_usb_device *d = usb_get_intfdata(intf);
242570769b24SOlli Salonen 	struct dw2102_state *st = (struct dw2102_state *)d->priv;
242670769b24SOlli Salonen 	struct i2c_client *client;
242770769b24SOlli Salonen 
242870769b24SOlli Salonen 	/* remove I2C client for tuner */
242970769b24SOlli Salonen 	client = st->i2c_client_tuner;
243070769b24SOlli Salonen 	if (client) {
243170769b24SOlli Salonen 		module_put(client->dev.driver->owner);
243270769b24SOlli Salonen 		i2c_unregister_device(client);
243370769b24SOlli Salonen 	}
243470769b24SOlli Salonen 
2435f3c6abcaSOlli Salonen 	/* remove I2C client for demodulator */
2436f3c6abcaSOlli Salonen 	client = st->i2c_client_demod;
2437f3c6abcaSOlli Salonen 	if (client) {
2438f3c6abcaSOlli Salonen 		module_put(client->dev.driver->owner);
2439f3c6abcaSOlli Salonen 		i2c_unregister_device(client);
2440f3c6abcaSOlli Salonen 	}
2441f3c6abcaSOlli Salonen 
244270769b24SOlli Salonen 	dvb_usb_device_exit(intf);
244370769b24SOlli Salonen }
244470769b24SOlli Salonen 
2445786baecfSMauro Carvalho Chehab static struct usb_driver dw2102_driver = {
2446786baecfSMauro Carvalho Chehab 	.name = "dw2102",
2447786baecfSMauro Carvalho Chehab 	.probe = dw2102_probe,
244870769b24SOlli Salonen 	.disconnect = dw2102_disconnect,
2449786baecfSMauro Carvalho Chehab 	.id_table = dw2102_table,
2450786baecfSMauro Carvalho Chehab };
2451786baecfSMauro Carvalho Chehab 
2452786baecfSMauro Carvalho Chehab module_usb_driver(dw2102_driver);
2453786baecfSMauro Carvalho Chehab 
2454786baecfSMauro Carvalho Chehab MODULE_AUTHOR("Igor M. Liplianin (c) liplianin@me.by");
2455f319ed91SMauro 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");
2456786baecfSMauro Carvalho Chehab MODULE_VERSION("0.1");
2457786baecfSMauro Carvalho Chehab MODULE_LICENSE("GPL");
24586823627bSRémi Cardona MODULE_FIRMWARE(DW2101_FIRMWARE);
24596823627bSRémi Cardona MODULE_FIRMWARE(DW2102_FIRMWARE);
24606823627bSRémi Cardona MODULE_FIRMWARE(DW2104_FIRMWARE);
24616823627bSRémi Cardona MODULE_FIRMWARE(DW3101_FIRMWARE);
24626823627bSRémi Cardona MODULE_FIRMWARE(S630_FIRMWARE);
24636823627bSRémi Cardona MODULE_FIRMWARE(S660_FIRMWARE);
24646823627bSRémi Cardona MODULE_FIRMWARE(P1100_FIRMWARE);
24656823627bSRémi Cardona MODULE_FIRMWARE(P7500_FIRMWARE);
2466