xref: /linux/drivers/media/usb/dvb-usb/dw2102.c (revision 955d00ac7a193e9c29a897cd5d731a84e3850217)
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,
3*955d00acSIgor M. Liplianin  *	TeVii S600, S630, S650, S660, S480, S421, S632
4786baecfSMauro Carvalho Chehab  *	Prof 1100, 7500,
5786baecfSMauro Carvalho Chehab  *	Geniatech SU3000 Cards
6*955d00acSIgor M. Liplianin  * Copyright (C) 2008-2012 Igor M. Liplianin (liplianin@me.by)
7786baecfSMauro Carvalho Chehab  *
8786baecfSMauro Carvalho Chehab  *	This program is free software; you can redistribute it and/or modify it
9786baecfSMauro Carvalho Chehab  *	under the terms of the GNU General Public License as published by the
10786baecfSMauro Carvalho Chehab  *	Free Software Foundation, version 2.
11786baecfSMauro Carvalho Chehab  *
12786baecfSMauro Carvalho Chehab  * see Documentation/dvb/README.dvb-usb for more information
13786baecfSMauro Carvalho Chehab  */
14786baecfSMauro Carvalho Chehab #include "dw2102.h"
15786baecfSMauro Carvalho Chehab #include "si21xx.h"
16786baecfSMauro Carvalho Chehab #include "stv0299.h"
17786baecfSMauro Carvalho Chehab #include "z0194a.h"
18786baecfSMauro Carvalho Chehab #include "stv0288.h"
19786baecfSMauro Carvalho Chehab #include "stb6000.h"
20786baecfSMauro Carvalho Chehab #include "eds1547.h"
21786baecfSMauro Carvalho Chehab #include "cx24116.h"
22786baecfSMauro Carvalho Chehab #include "tda1002x.h"
23786baecfSMauro Carvalho Chehab #include "mt312.h"
24786baecfSMauro Carvalho Chehab #include "zl10039.h"
2573f0af44SKonstantin Dimitrov #include "ts2020.h"
26786baecfSMauro Carvalho Chehab #include "ds3000.h"
27786baecfSMauro Carvalho Chehab #include "stv0900.h"
28786baecfSMauro Carvalho Chehab #include "stv6110.h"
29786baecfSMauro Carvalho Chehab #include "stb6100.h"
30786baecfSMauro Carvalho Chehab #include "stb6100_proc.h"
31*955d00acSIgor M. Liplianin #include "m88rs2000.h"
32786baecfSMauro Carvalho Chehab 
33786baecfSMauro Carvalho Chehab #ifndef USB_PID_DW2102
34786baecfSMauro Carvalho Chehab #define USB_PID_DW2102 0x2102
35786baecfSMauro Carvalho Chehab #endif
36786baecfSMauro Carvalho Chehab 
37786baecfSMauro Carvalho Chehab #ifndef USB_PID_DW2104
38786baecfSMauro Carvalho Chehab #define USB_PID_DW2104 0x2104
39786baecfSMauro Carvalho Chehab #endif
40786baecfSMauro Carvalho Chehab 
41786baecfSMauro Carvalho Chehab #ifndef USB_PID_DW3101
42786baecfSMauro Carvalho Chehab #define USB_PID_DW3101 0x3101
43786baecfSMauro Carvalho Chehab #endif
44786baecfSMauro Carvalho Chehab 
45786baecfSMauro Carvalho Chehab #ifndef USB_PID_CINERGY_S
46786baecfSMauro Carvalho Chehab #define USB_PID_CINERGY_S 0x0064
47786baecfSMauro Carvalho Chehab #endif
48786baecfSMauro Carvalho Chehab 
49786baecfSMauro Carvalho Chehab #ifndef USB_PID_TEVII_S630
50786baecfSMauro Carvalho Chehab #define USB_PID_TEVII_S630 0xd630
51786baecfSMauro Carvalho Chehab #endif
52786baecfSMauro Carvalho Chehab 
53786baecfSMauro Carvalho Chehab #ifndef USB_PID_TEVII_S650
54786baecfSMauro Carvalho Chehab #define USB_PID_TEVII_S650 0xd650
55786baecfSMauro Carvalho Chehab #endif
56786baecfSMauro Carvalho Chehab 
57786baecfSMauro Carvalho Chehab #ifndef USB_PID_TEVII_S660
58786baecfSMauro Carvalho Chehab #define USB_PID_TEVII_S660 0xd660
59786baecfSMauro Carvalho Chehab #endif
60786baecfSMauro Carvalho Chehab 
61786baecfSMauro Carvalho Chehab #ifndef USB_PID_TEVII_S480_1
62786baecfSMauro Carvalho Chehab #define USB_PID_TEVII_S480_1 0xd481
63786baecfSMauro Carvalho Chehab #endif
64786baecfSMauro Carvalho Chehab 
65786baecfSMauro Carvalho Chehab #ifndef USB_PID_TEVII_S480_2
66786baecfSMauro Carvalho Chehab #define USB_PID_TEVII_S480_2 0xd482
67786baecfSMauro Carvalho Chehab #endif
68786baecfSMauro Carvalho Chehab 
69786baecfSMauro Carvalho Chehab #ifndef USB_PID_PROF_1100
70786baecfSMauro Carvalho Chehab #define USB_PID_PROF_1100 0xb012
71786baecfSMauro Carvalho Chehab #endif
72786baecfSMauro Carvalho Chehab 
73*955d00acSIgor M. Liplianin #ifndef USB_PID_TEVII_S421
74*955d00acSIgor M. Liplianin #define USB_PID_TEVII_S421 0xd421
75*955d00acSIgor M. Liplianin #endif
76*955d00acSIgor M. Liplianin 
77*955d00acSIgor M. Liplianin #ifndef USB_PID_TEVII_S632
78*955d00acSIgor M. Liplianin #define USB_PID_TEVII_S632 0xd632
79*955d00acSIgor M. Liplianin #endif
80*955d00acSIgor M. Liplianin 
81786baecfSMauro Carvalho Chehab #define DW210X_READ_MSG 0
82786baecfSMauro Carvalho Chehab #define DW210X_WRITE_MSG 1
83786baecfSMauro Carvalho Chehab 
84786baecfSMauro Carvalho Chehab #define REG_1F_SYMBOLRATE_BYTE0 0x1f
85786baecfSMauro Carvalho Chehab #define REG_20_SYMBOLRATE_BYTE1 0x20
86786baecfSMauro Carvalho Chehab #define REG_21_SYMBOLRATE_BYTE2 0x21
87786baecfSMauro Carvalho Chehab /* on my own*/
88786baecfSMauro Carvalho Chehab #define DW2102_VOLTAGE_CTRL (0x1800)
89786baecfSMauro Carvalho Chehab #define SU3000_STREAM_CTRL (0x1900)
90786baecfSMauro Carvalho Chehab #define DW2102_RC_QUERY (0x1a00)
91786baecfSMauro Carvalho Chehab #define DW2102_LED_CTRL (0x1b00)
92786baecfSMauro Carvalho Chehab 
936823627bSRémi Cardona #define DW2101_FIRMWARE "dvb-usb-dw2101.fw"
946823627bSRémi Cardona #define DW2102_FIRMWARE "dvb-usb-dw2102.fw"
956823627bSRémi Cardona #define DW2104_FIRMWARE "dvb-usb-dw2104.fw"
966823627bSRémi Cardona #define DW3101_FIRMWARE "dvb-usb-dw3101.fw"
976823627bSRémi Cardona #define S630_FIRMWARE   "dvb-usb-s630.fw"
986823627bSRémi Cardona #define S660_FIRMWARE   "dvb-usb-s660.fw"
996823627bSRémi Cardona #define P1100_FIRMWARE  "dvb-usb-p1100.fw"
1006823627bSRémi Cardona #define P7500_FIRMWARE  "dvb-usb-p7500.fw"
1016823627bSRémi Cardona 
102786baecfSMauro Carvalho Chehab #define	err_str "did not find the firmware file. (%s) " \
103786baecfSMauro Carvalho Chehab 		"Please see linux/Documentation/dvb/ for more details " \
104786baecfSMauro Carvalho Chehab 		"on firmware-problems."
105786baecfSMauro Carvalho Chehab 
106786baecfSMauro Carvalho Chehab struct rc_map_dvb_usb_table_table {
107786baecfSMauro Carvalho Chehab 	struct rc_map_table *rc_keys;
108786baecfSMauro Carvalho Chehab 	int rc_keys_size;
109786baecfSMauro Carvalho Chehab };
110786baecfSMauro Carvalho Chehab 
111786baecfSMauro Carvalho Chehab struct su3000_state {
112786baecfSMauro Carvalho Chehab 	u8 initialized;
113786baecfSMauro Carvalho Chehab };
114786baecfSMauro Carvalho Chehab 
115786baecfSMauro Carvalho Chehab struct s6x0_state {
116786baecfSMauro Carvalho Chehab 	int (*old_set_voltage)(struct dvb_frontend *f, fe_sec_voltage_t v);
117786baecfSMauro Carvalho Chehab };
118786baecfSMauro Carvalho Chehab 
119786baecfSMauro Carvalho Chehab /* debug */
120786baecfSMauro Carvalho Chehab static int dvb_usb_dw2102_debug;
121786baecfSMauro Carvalho Chehab module_param_named(debug, dvb_usb_dw2102_debug, int, 0644);
122786baecfSMauro Carvalho Chehab MODULE_PARM_DESC(debug, "set debugging level (1=info 2=xfer 4=rc(or-able))."
123786baecfSMauro Carvalho Chehab 						DVB_USB_DEBUG_STATUS);
124786baecfSMauro Carvalho Chehab 
125786baecfSMauro Carvalho Chehab /* keymaps */
126786baecfSMauro Carvalho Chehab static int ir_keymap;
127786baecfSMauro Carvalho Chehab module_param_named(keymap, ir_keymap, int, 0644);
128786baecfSMauro Carvalho Chehab MODULE_PARM_DESC(keymap, "set keymap 0=default 1=dvbworld 2=tevii 3=tbs  ..."
129786baecfSMauro Carvalho Chehab 			" 256=none");
130786baecfSMauro Carvalho Chehab 
131786baecfSMauro Carvalho Chehab /* demod probe */
132786baecfSMauro Carvalho Chehab static int demod_probe = 1;
133786baecfSMauro Carvalho Chehab module_param_named(demod, demod_probe, int, 0644);
134786baecfSMauro Carvalho Chehab MODULE_PARM_DESC(demod, "demod to probe (1=cx24116 2=stv0903+stv6110 "
135786baecfSMauro Carvalho Chehab 			"4=stv0903+stb6100(or-able)).");
136786baecfSMauro Carvalho Chehab 
137786baecfSMauro Carvalho Chehab DVB_DEFINE_MOD_OPT_ADAPTER_NR(adapter_nr);
138786baecfSMauro Carvalho Chehab 
139786baecfSMauro Carvalho Chehab static int dw210x_op_rw(struct usb_device *dev, u8 request, u16 value,
140786baecfSMauro Carvalho Chehab 			u16 index, u8 * data, u16 len, int flags)
141786baecfSMauro Carvalho Chehab {
142786baecfSMauro Carvalho Chehab 	int ret;
143786baecfSMauro Carvalho Chehab 	u8 *u8buf;
144786baecfSMauro Carvalho Chehab 	unsigned int pipe = (flags == DW210X_READ_MSG) ?
145786baecfSMauro Carvalho Chehab 				usb_rcvctrlpipe(dev, 0) : usb_sndctrlpipe(dev, 0);
146786baecfSMauro Carvalho Chehab 	u8 request_type = (flags == DW210X_READ_MSG) ? USB_DIR_IN : USB_DIR_OUT;
147786baecfSMauro Carvalho Chehab 
148786baecfSMauro Carvalho Chehab 	u8buf = kmalloc(len, GFP_KERNEL);
149786baecfSMauro Carvalho Chehab 	if (!u8buf)
150786baecfSMauro Carvalho Chehab 		return -ENOMEM;
151786baecfSMauro Carvalho Chehab 
152786baecfSMauro Carvalho Chehab 
153786baecfSMauro Carvalho Chehab 	if (flags == DW210X_WRITE_MSG)
154786baecfSMauro Carvalho Chehab 		memcpy(u8buf, data, len);
155786baecfSMauro Carvalho Chehab 	ret = usb_control_msg(dev, pipe, request, request_type | USB_TYPE_VENDOR,
156786baecfSMauro Carvalho Chehab 				value, index , u8buf, len, 2000);
157786baecfSMauro Carvalho Chehab 
158786baecfSMauro Carvalho Chehab 	if (flags == DW210X_READ_MSG)
159786baecfSMauro Carvalho Chehab 		memcpy(data, u8buf, len);
160786baecfSMauro Carvalho Chehab 
161786baecfSMauro Carvalho Chehab 	kfree(u8buf);
162786baecfSMauro Carvalho Chehab 	return ret;
163786baecfSMauro Carvalho Chehab }
164786baecfSMauro Carvalho Chehab 
165786baecfSMauro Carvalho Chehab /* I2C */
166786baecfSMauro Carvalho Chehab static int dw2102_i2c_transfer(struct i2c_adapter *adap, struct i2c_msg msg[],
167786baecfSMauro Carvalho Chehab 		int num)
168786baecfSMauro Carvalho Chehab {
169786baecfSMauro Carvalho Chehab 	struct dvb_usb_device *d = i2c_get_adapdata(adap);
170786baecfSMauro Carvalho Chehab 	int i = 0;
171786baecfSMauro Carvalho Chehab 	u8 buf6[] = {0x2c, 0x05, 0xc0, 0, 0, 0, 0};
172786baecfSMauro Carvalho Chehab 	u16 value;
173786baecfSMauro Carvalho Chehab 
174786baecfSMauro Carvalho Chehab 	if (!d)
175786baecfSMauro Carvalho Chehab 		return -ENODEV;
176786baecfSMauro Carvalho Chehab 	if (mutex_lock_interruptible(&d->i2c_mutex) < 0)
177786baecfSMauro Carvalho Chehab 		return -EAGAIN;
178786baecfSMauro Carvalho Chehab 
179786baecfSMauro Carvalho Chehab 	switch (num) {
180786baecfSMauro Carvalho Chehab 	case 2:
181786baecfSMauro Carvalho Chehab 		/* read stv0299 register */
182786baecfSMauro Carvalho Chehab 		value = msg[0].buf[0];/* register */
183786baecfSMauro Carvalho Chehab 		for (i = 0; i < msg[1].len; i++) {
184786baecfSMauro Carvalho Chehab 			dw210x_op_rw(d->udev, 0xb5, value + i, 0,
185786baecfSMauro Carvalho Chehab 					buf6, 2, DW210X_READ_MSG);
186786baecfSMauro Carvalho Chehab 			msg[1].buf[i] = buf6[0];
187786baecfSMauro Carvalho Chehab 		}
188786baecfSMauro Carvalho Chehab 		break;
189786baecfSMauro Carvalho Chehab 	case 1:
190786baecfSMauro Carvalho Chehab 		switch (msg[0].addr) {
191786baecfSMauro Carvalho Chehab 		case 0x68:
192786baecfSMauro Carvalho Chehab 			/* write to stv0299 register */
193786baecfSMauro Carvalho Chehab 			buf6[0] = 0x2a;
194786baecfSMauro Carvalho Chehab 			buf6[1] = msg[0].buf[0];
195786baecfSMauro Carvalho Chehab 			buf6[2] = msg[0].buf[1];
196786baecfSMauro Carvalho Chehab 			dw210x_op_rw(d->udev, 0xb2, 0, 0,
197786baecfSMauro Carvalho Chehab 					buf6, 3, DW210X_WRITE_MSG);
198786baecfSMauro Carvalho Chehab 			break;
199786baecfSMauro Carvalho Chehab 		case 0x60:
200786baecfSMauro Carvalho Chehab 			if (msg[0].flags == 0) {
201786baecfSMauro Carvalho Chehab 			/* write to tuner pll */
202786baecfSMauro Carvalho Chehab 				buf6[0] = 0x2c;
203786baecfSMauro Carvalho Chehab 				buf6[1] = 5;
204786baecfSMauro Carvalho Chehab 				buf6[2] = 0xc0;
205786baecfSMauro Carvalho Chehab 				buf6[3] = msg[0].buf[0];
206786baecfSMauro Carvalho Chehab 				buf6[4] = msg[0].buf[1];
207786baecfSMauro Carvalho Chehab 				buf6[5] = msg[0].buf[2];
208786baecfSMauro Carvalho Chehab 				buf6[6] = msg[0].buf[3];
209786baecfSMauro Carvalho Chehab 				dw210x_op_rw(d->udev, 0xb2, 0, 0,
210786baecfSMauro Carvalho Chehab 						buf6, 7, DW210X_WRITE_MSG);
211786baecfSMauro Carvalho Chehab 			} else {
212786baecfSMauro Carvalho Chehab 			/* read from tuner */
213786baecfSMauro Carvalho Chehab 				dw210x_op_rw(d->udev, 0xb5, 0, 0,
214786baecfSMauro Carvalho Chehab 						buf6, 1, DW210X_READ_MSG);
215786baecfSMauro Carvalho Chehab 				msg[0].buf[0] = buf6[0];
216786baecfSMauro Carvalho Chehab 			}
217786baecfSMauro Carvalho Chehab 			break;
218786baecfSMauro Carvalho Chehab 		case (DW2102_RC_QUERY):
219786baecfSMauro Carvalho Chehab 			dw210x_op_rw(d->udev, 0xb8, 0, 0,
220786baecfSMauro Carvalho Chehab 					buf6, 2, DW210X_READ_MSG);
221786baecfSMauro Carvalho Chehab 			msg[0].buf[0] = buf6[0];
222786baecfSMauro Carvalho Chehab 			msg[0].buf[1] = buf6[1];
223786baecfSMauro Carvalho Chehab 			break;
224786baecfSMauro Carvalho Chehab 		case (DW2102_VOLTAGE_CTRL):
225786baecfSMauro Carvalho Chehab 			buf6[0] = 0x30;
226786baecfSMauro Carvalho Chehab 			buf6[1] = msg[0].buf[0];
227786baecfSMauro Carvalho Chehab 			dw210x_op_rw(d->udev, 0xb2, 0, 0,
228786baecfSMauro Carvalho Chehab 					buf6, 2, DW210X_WRITE_MSG);
229786baecfSMauro Carvalho Chehab 			break;
230786baecfSMauro Carvalho Chehab 		}
231786baecfSMauro Carvalho Chehab 
232786baecfSMauro Carvalho Chehab 		break;
233786baecfSMauro Carvalho Chehab 	}
234786baecfSMauro Carvalho Chehab 
235786baecfSMauro Carvalho Chehab 	mutex_unlock(&d->i2c_mutex);
236786baecfSMauro Carvalho Chehab 	return num;
237786baecfSMauro Carvalho Chehab }
238786baecfSMauro Carvalho Chehab 
239786baecfSMauro Carvalho Chehab static int dw2102_serit_i2c_transfer(struct i2c_adapter *adap,
240786baecfSMauro Carvalho Chehab 						struct i2c_msg msg[], int num)
241786baecfSMauro Carvalho Chehab {
242786baecfSMauro Carvalho Chehab 	struct dvb_usb_device *d = i2c_get_adapdata(adap);
243786baecfSMauro Carvalho Chehab 	u8 buf6[] = {0, 0, 0, 0, 0, 0, 0};
244786baecfSMauro Carvalho Chehab 
245786baecfSMauro Carvalho Chehab 	if (!d)
246786baecfSMauro Carvalho Chehab 		return -ENODEV;
247786baecfSMauro Carvalho Chehab 	if (mutex_lock_interruptible(&d->i2c_mutex) < 0)
248786baecfSMauro Carvalho Chehab 		return -EAGAIN;
249786baecfSMauro Carvalho Chehab 
250786baecfSMauro Carvalho Chehab 	switch (num) {
251786baecfSMauro Carvalho Chehab 	case 2:
252786baecfSMauro Carvalho Chehab 		/* read si2109 register by number */
253786baecfSMauro Carvalho Chehab 		buf6[0] = msg[0].addr << 1;
254786baecfSMauro Carvalho Chehab 		buf6[1] = msg[0].len;
255786baecfSMauro Carvalho Chehab 		buf6[2] = msg[0].buf[0];
256786baecfSMauro Carvalho Chehab 		dw210x_op_rw(d->udev, 0xc2, 0, 0,
257786baecfSMauro Carvalho Chehab 				buf6, msg[0].len + 2, DW210X_WRITE_MSG);
258786baecfSMauro Carvalho Chehab 		/* read si2109 register */
259786baecfSMauro Carvalho Chehab 		dw210x_op_rw(d->udev, 0xc3, 0xd0, 0,
260786baecfSMauro Carvalho Chehab 				buf6, msg[1].len + 2, DW210X_READ_MSG);
261786baecfSMauro Carvalho Chehab 		memcpy(msg[1].buf, buf6 + 2, msg[1].len);
262786baecfSMauro Carvalho Chehab 
263786baecfSMauro Carvalho Chehab 		break;
264786baecfSMauro Carvalho Chehab 	case 1:
265786baecfSMauro Carvalho Chehab 		switch (msg[0].addr) {
266786baecfSMauro Carvalho Chehab 		case 0x68:
267786baecfSMauro Carvalho Chehab 			/* write to si2109 register */
268786baecfSMauro Carvalho Chehab 			buf6[0] = msg[0].addr << 1;
269786baecfSMauro Carvalho Chehab 			buf6[1] = msg[0].len;
270786baecfSMauro Carvalho Chehab 			memcpy(buf6 + 2, msg[0].buf, msg[0].len);
271786baecfSMauro Carvalho Chehab 			dw210x_op_rw(d->udev, 0xc2, 0, 0, buf6,
272786baecfSMauro Carvalho Chehab 					msg[0].len + 2, DW210X_WRITE_MSG);
273786baecfSMauro Carvalho Chehab 			break;
274786baecfSMauro Carvalho Chehab 		case(DW2102_RC_QUERY):
275786baecfSMauro Carvalho Chehab 			dw210x_op_rw(d->udev, 0xb8, 0, 0,
276786baecfSMauro Carvalho Chehab 					buf6, 2, DW210X_READ_MSG);
277786baecfSMauro Carvalho Chehab 			msg[0].buf[0] = buf6[0];
278786baecfSMauro Carvalho Chehab 			msg[0].buf[1] = buf6[1];
279786baecfSMauro Carvalho Chehab 			break;
280786baecfSMauro Carvalho Chehab 		case(DW2102_VOLTAGE_CTRL):
281786baecfSMauro Carvalho Chehab 			buf6[0] = 0x30;
282786baecfSMauro Carvalho Chehab 			buf6[1] = msg[0].buf[0];
283786baecfSMauro Carvalho Chehab 			dw210x_op_rw(d->udev, 0xb2, 0, 0,
284786baecfSMauro Carvalho Chehab 					buf6, 2, DW210X_WRITE_MSG);
285786baecfSMauro Carvalho Chehab 			break;
286786baecfSMauro Carvalho Chehab 		}
287786baecfSMauro Carvalho Chehab 		break;
288786baecfSMauro Carvalho Chehab 	}
289786baecfSMauro Carvalho Chehab 
290786baecfSMauro Carvalho Chehab 	mutex_unlock(&d->i2c_mutex);
291786baecfSMauro Carvalho Chehab 	return num;
292786baecfSMauro Carvalho Chehab }
293786baecfSMauro Carvalho Chehab 
294786baecfSMauro Carvalho Chehab static int dw2102_earda_i2c_transfer(struct i2c_adapter *adap, struct i2c_msg msg[], int num)
295786baecfSMauro Carvalho Chehab {
296786baecfSMauro Carvalho Chehab 	struct dvb_usb_device *d = i2c_get_adapdata(adap);
297786baecfSMauro Carvalho Chehab 
298786baecfSMauro Carvalho Chehab 	if (!d)
299786baecfSMauro Carvalho Chehab 		return -ENODEV;
300786baecfSMauro Carvalho Chehab 	if (mutex_lock_interruptible(&d->i2c_mutex) < 0)
301786baecfSMauro Carvalho Chehab 		return -EAGAIN;
302786baecfSMauro Carvalho Chehab 
303786baecfSMauro Carvalho Chehab 	switch (num) {
304786baecfSMauro Carvalho Chehab 	case 2: {
305786baecfSMauro Carvalho Chehab 		/* read */
306786baecfSMauro Carvalho Chehab 		/* first write first register number */
307786baecfSMauro Carvalho Chehab 		u8 ibuf[msg[1].len + 2], obuf[3];
308786baecfSMauro Carvalho Chehab 		obuf[0] = msg[0].addr << 1;
309786baecfSMauro Carvalho Chehab 		obuf[1] = msg[0].len;
310786baecfSMauro Carvalho Chehab 		obuf[2] = msg[0].buf[0];
311786baecfSMauro Carvalho Chehab 		dw210x_op_rw(d->udev, 0xc2, 0, 0,
312786baecfSMauro Carvalho Chehab 				obuf, msg[0].len + 2, DW210X_WRITE_MSG);
313786baecfSMauro Carvalho Chehab 		/* second read registers */
314786baecfSMauro Carvalho Chehab 		dw210x_op_rw(d->udev, 0xc3, 0xd1 , 0,
315786baecfSMauro Carvalho Chehab 				ibuf, msg[1].len + 2, DW210X_READ_MSG);
316786baecfSMauro Carvalho Chehab 		memcpy(msg[1].buf, ibuf + 2, msg[1].len);
317786baecfSMauro Carvalho Chehab 
318786baecfSMauro Carvalho Chehab 		break;
319786baecfSMauro Carvalho Chehab 	}
320786baecfSMauro Carvalho Chehab 	case 1:
321786baecfSMauro Carvalho Chehab 		switch (msg[0].addr) {
322786baecfSMauro Carvalho Chehab 		case 0x68: {
323786baecfSMauro Carvalho Chehab 			/* write to register */
324786baecfSMauro Carvalho Chehab 			u8 obuf[msg[0].len + 2];
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 */
334786baecfSMauro Carvalho Chehab 			u8 obuf[msg[0].len + 2];
335786baecfSMauro Carvalho Chehab 			obuf[0] = msg[0].addr << 1;
336786baecfSMauro Carvalho Chehab 			obuf[1] = msg[0].len;
337786baecfSMauro Carvalho Chehab 			memcpy(obuf + 2, msg[0].buf, msg[0].len);
338786baecfSMauro Carvalho Chehab 			dw210x_op_rw(d->udev, 0xc2, 0, 0,
339786baecfSMauro Carvalho Chehab 					obuf, msg[0].len + 2, DW210X_WRITE_MSG);
340786baecfSMauro Carvalho Chehab 			break;
341786baecfSMauro Carvalho Chehab 		}
342786baecfSMauro Carvalho Chehab 		case(DW2102_RC_QUERY): {
343786baecfSMauro Carvalho Chehab 			u8 ibuf[2];
344786baecfSMauro Carvalho Chehab 			dw210x_op_rw(d->udev, 0xb8, 0, 0,
345786baecfSMauro Carvalho Chehab 					ibuf, 2, DW210X_READ_MSG);
346786baecfSMauro Carvalho Chehab 			memcpy(msg[0].buf, ibuf , 2);
347786baecfSMauro Carvalho Chehab 			break;
348786baecfSMauro Carvalho Chehab 		}
349786baecfSMauro Carvalho Chehab 		case(DW2102_VOLTAGE_CTRL): {
350786baecfSMauro Carvalho Chehab 			u8 obuf[2];
351786baecfSMauro Carvalho Chehab 			obuf[0] = 0x30;
352786baecfSMauro Carvalho Chehab 			obuf[1] = msg[0].buf[0];
353786baecfSMauro Carvalho Chehab 			dw210x_op_rw(d->udev, 0xb2, 0, 0,
354786baecfSMauro Carvalho Chehab 					obuf, 2, DW210X_WRITE_MSG);
355786baecfSMauro Carvalho Chehab 			break;
356786baecfSMauro Carvalho Chehab 		}
357786baecfSMauro Carvalho Chehab 		}
358786baecfSMauro Carvalho Chehab 
359786baecfSMauro Carvalho Chehab 		break;
360786baecfSMauro Carvalho Chehab 	}
361786baecfSMauro Carvalho Chehab 
362786baecfSMauro Carvalho Chehab 	mutex_unlock(&d->i2c_mutex);
363786baecfSMauro Carvalho Chehab 	return num;
364786baecfSMauro Carvalho Chehab }
365786baecfSMauro Carvalho Chehab 
366786baecfSMauro Carvalho Chehab static int dw2104_i2c_transfer(struct i2c_adapter *adap, struct i2c_msg msg[], int num)
367786baecfSMauro Carvalho Chehab {
368786baecfSMauro Carvalho Chehab 	struct dvb_usb_device *d = i2c_get_adapdata(adap);
369786baecfSMauro Carvalho Chehab 	int len, i, j;
370786baecfSMauro Carvalho Chehab 
371786baecfSMauro Carvalho Chehab 	if (!d)
372786baecfSMauro Carvalho Chehab 		return -ENODEV;
373786baecfSMauro Carvalho Chehab 	if (mutex_lock_interruptible(&d->i2c_mutex) < 0)
374786baecfSMauro Carvalho Chehab 		return -EAGAIN;
375786baecfSMauro Carvalho Chehab 
376786baecfSMauro Carvalho Chehab 	for (j = 0; j < num; j++) {
377786baecfSMauro Carvalho Chehab 		switch (msg[j].addr) {
378786baecfSMauro Carvalho Chehab 		case(DW2102_RC_QUERY): {
379786baecfSMauro Carvalho Chehab 			u8 ibuf[2];
380786baecfSMauro Carvalho Chehab 			dw210x_op_rw(d->udev, 0xb8, 0, 0,
381786baecfSMauro Carvalho Chehab 					ibuf, 2, DW210X_READ_MSG);
382786baecfSMauro Carvalho Chehab 			memcpy(msg[j].buf, ibuf , 2);
383786baecfSMauro Carvalho Chehab 			break;
384786baecfSMauro Carvalho Chehab 		}
385786baecfSMauro Carvalho Chehab 		case(DW2102_VOLTAGE_CTRL): {
386786baecfSMauro Carvalho Chehab 			u8 obuf[2];
387786baecfSMauro Carvalho Chehab 			obuf[0] = 0x30;
388786baecfSMauro Carvalho Chehab 			obuf[1] = msg[j].buf[0];
389786baecfSMauro Carvalho Chehab 			dw210x_op_rw(d->udev, 0xb2, 0, 0,
390786baecfSMauro Carvalho Chehab 					obuf, 2, DW210X_WRITE_MSG);
391786baecfSMauro Carvalho Chehab 			break;
392786baecfSMauro Carvalho Chehab 		}
393786baecfSMauro Carvalho Chehab 		/*case 0x55: cx24116
394786baecfSMauro Carvalho Chehab 		case 0x6a: stv0903
395786baecfSMauro Carvalho Chehab 		case 0x68: ds3000, stv0903
396786baecfSMauro Carvalho Chehab 		case 0x60: ts2020, stv6110, stb6100 */
397786baecfSMauro Carvalho Chehab 		default: {
398786baecfSMauro Carvalho Chehab 			if (msg[j].flags == I2C_M_RD) {
399786baecfSMauro Carvalho Chehab 				/* read registers */
400786baecfSMauro Carvalho Chehab 				u8  ibuf[msg[j].len + 2];
401786baecfSMauro Carvalho Chehab 				dw210x_op_rw(d->udev, 0xc3,
402786baecfSMauro Carvalho Chehab 						(msg[j].addr << 1) + 1, 0,
403786baecfSMauro Carvalho Chehab 						ibuf, msg[j].len + 2,
404786baecfSMauro Carvalho Chehab 						DW210X_READ_MSG);
405786baecfSMauro Carvalho Chehab 				memcpy(msg[j].buf, ibuf + 2, msg[j].len);
406786baecfSMauro Carvalho Chehab 			mdelay(10);
407786baecfSMauro Carvalho Chehab 			} else if (((msg[j].buf[0] == 0xb0) &&
408786baecfSMauro Carvalho Chehab 						(msg[j].addr == 0x68)) ||
409786baecfSMauro Carvalho Chehab 						((msg[j].buf[0] == 0xf7) &&
410786baecfSMauro Carvalho Chehab 						(msg[j].addr == 0x55))) {
411786baecfSMauro Carvalho Chehab 				/* write firmware */
412786baecfSMauro Carvalho Chehab 				u8 obuf[19];
413786baecfSMauro Carvalho Chehab 				obuf[0] = msg[j].addr << 1;
414786baecfSMauro Carvalho Chehab 				obuf[1] = (msg[j].len > 15 ? 17 : msg[j].len);
415786baecfSMauro Carvalho Chehab 				obuf[2] = msg[j].buf[0];
416786baecfSMauro Carvalho Chehab 				len = msg[j].len - 1;
417786baecfSMauro Carvalho Chehab 				i = 1;
418786baecfSMauro Carvalho Chehab 				do {
419786baecfSMauro Carvalho Chehab 					memcpy(obuf + 3, msg[j].buf + i,
420786baecfSMauro Carvalho Chehab 							(len > 16 ? 16 : len));
421786baecfSMauro Carvalho Chehab 					dw210x_op_rw(d->udev, 0xc2, 0, 0,
422786baecfSMauro Carvalho Chehab 						obuf, (len > 16 ? 16 : len) + 3,
423786baecfSMauro Carvalho Chehab 						DW210X_WRITE_MSG);
424786baecfSMauro Carvalho Chehab 					i += 16;
425786baecfSMauro Carvalho Chehab 					len -= 16;
426786baecfSMauro Carvalho Chehab 				} while (len > 0);
427786baecfSMauro Carvalho Chehab 			} else {
428786baecfSMauro Carvalho Chehab 				/* write registers */
429786baecfSMauro Carvalho Chehab 				u8 obuf[msg[j].len + 2];
430786baecfSMauro Carvalho Chehab 				obuf[0] = msg[j].addr << 1;
431786baecfSMauro Carvalho Chehab 				obuf[1] = msg[j].len;
432786baecfSMauro Carvalho Chehab 				memcpy(obuf + 2, msg[j].buf, msg[j].len);
433786baecfSMauro Carvalho Chehab 				dw210x_op_rw(d->udev, 0xc2, 0, 0,
434786baecfSMauro Carvalho Chehab 						obuf, msg[j].len + 2,
435786baecfSMauro Carvalho Chehab 						DW210X_WRITE_MSG);
436786baecfSMauro Carvalho Chehab 			}
437786baecfSMauro Carvalho Chehab 			break;
438786baecfSMauro Carvalho Chehab 		}
439786baecfSMauro Carvalho Chehab 		}
440786baecfSMauro Carvalho Chehab 
441786baecfSMauro Carvalho Chehab 	}
442786baecfSMauro Carvalho Chehab 
443786baecfSMauro Carvalho Chehab 	mutex_unlock(&d->i2c_mutex);
444786baecfSMauro Carvalho Chehab 	return num;
445786baecfSMauro Carvalho Chehab }
446786baecfSMauro Carvalho Chehab 
447786baecfSMauro Carvalho Chehab static int dw3101_i2c_transfer(struct i2c_adapter *adap, struct i2c_msg msg[],
448786baecfSMauro Carvalho Chehab 								int num)
449786baecfSMauro Carvalho Chehab {
450786baecfSMauro Carvalho Chehab 	struct dvb_usb_device *d = i2c_get_adapdata(adap);
451786baecfSMauro Carvalho Chehab 	int i;
452786baecfSMauro Carvalho Chehab 
453786baecfSMauro Carvalho Chehab 	if (!d)
454786baecfSMauro Carvalho Chehab 		return -ENODEV;
455786baecfSMauro Carvalho Chehab 	if (mutex_lock_interruptible(&d->i2c_mutex) < 0)
456786baecfSMauro Carvalho Chehab 		return -EAGAIN;
457786baecfSMauro Carvalho Chehab 
458786baecfSMauro Carvalho Chehab 	switch (num) {
459786baecfSMauro Carvalho Chehab 	case 2: {
460786baecfSMauro Carvalho Chehab 		/* read */
461786baecfSMauro Carvalho Chehab 		/* first write first register number */
462786baecfSMauro Carvalho Chehab 		u8 ibuf[msg[1].len + 2], obuf[3];
463786baecfSMauro Carvalho Chehab 		obuf[0] = msg[0].addr << 1;
464786baecfSMauro Carvalho Chehab 		obuf[1] = msg[0].len;
465786baecfSMauro Carvalho Chehab 		obuf[2] = msg[0].buf[0];
466786baecfSMauro Carvalho Chehab 		dw210x_op_rw(d->udev, 0xc2, 0, 0,
467786baecfSMauro Carvalho Chehab 				obuf, msg[0].len + 2, DW210X_WRITE_MSG);
468786baecfSMauro Carvalho Chehab 		/* second read registers */
469786baecfSMauro Carvalho Chehab 		dw210x_op_rw(d->udev, 0xc3, 0x19 , 0,
470786baecfSMauro Carvalho Chehab 				ibuf, msg[1].len + 2, DW210X_READ_MSG);
471786baecfSMauro Carvalho Chehab 		memcpy(msg[1].buf, ibuf + 2, msg[1].len);
472786baecfSMauro Carvalho Chehab 
473786baecfSMauro Carvalho Chehab 		break;
474786baecfSMauro Carvalho Chehab 	}
475786baecfSMauro Carvalho Chehab 	case 1:
476786baecfSMauro Carvalho Chehab 		switch (msg[0].addr) {
477786baecfSMauro Carvalho Chehab 		case 0x60:
478786baecfSMauro Carvalho Chehab 		case 0x0c: {
479786baecfSMauro Carvalho Chehab 			/* write to register */
480786baecfSMauro Carvalho Chehab 			u8 obuf[msg[0].len + 2];
481786baecfSMauro Carvalho Chehab 			obuf[0] = msg[0].addr << 1;
482786baecfSMauro Carvalho Chehab 			obuf[1] = msg[0].len;
483786baecfSMauro Carvalho Chehab 			memcpy(obuf + 2, msg[0].buf, msg[0].len);
484786baecfSMauro Carvalho Chehab 			dw210x_op_rw(d->udev, 0xc2, 0, 0,
485786baecfSMauro Carvalho Chehab 					obuf, msg[0].len + 2, DW210X_WRITE_MSG);
486786baecfSMauro Carvalho Chehab 			break;
487786baecfSMauro Carvalho Chehab 		}
488786baecfSMauro Carvalho Chehab 		case(DW2102_RC_QUERY): {
489786baecfSMauro Carvalho Chehab 			u8 ibuf[2];
490786baecfSMauro Carvalho Chehab 			dw210x_op_rw(d->udev, 0xb8, 0, 0,
491786baecfSMauro Carvalho Chehab 					ibuf, 2, DW210X_READ_MSG);
492786baecfSMauro Carvalho Chehab 			memcpy(msg[0].buf, ibuf , 2);
493786baecfSMauro Carvalho Chehab 			break;
494786baecfSMauro Carvalho Chehab 		}
495786baecfSMauro Carvalho Chehab 		}
496786baecfSMauro Carvalho Chehab 
497786baecfSMauro Carvalho Chehab 		break;
498786baecfSMauro Carvalho Chehab 	}
499786baecfSMauro Carvalho Chehab 
500786baecfSMauro Carvalho Chehab 	for (i = 0; i < num; i++) {
501786baecfSMauro Carvalho Chehab 		deb_xfer("%02x:%02x: %s ", i, msg[i].addr,
502786baecfSMauro Carvalho Chehab 				msg[i].flags == 0 ? ">>>" : "<<<");
503786baecfSMauro Carvalho Chehab 		debug_dump(msg[i].buf, msg[i].len, deb_xfer);
504786baecfSMauro Carvalho Chehab 	}
505786baecfSMauro Carvalho Chehab 
506786baecfSMauro Carvalho Chehab 	mutex_unlock(&d->i2c_mutex);
507786baecfSMauro Carvalho Chehab 	return num;
508786baecfSMauro Carvalho Chehab }
509786baecfSMauro Carvalho Chehab 
510786baecfSMauro Carvalho Chehab static int s6x0_i2c_transfer(struct i2c_adapter *adap, struct i2c_msg msg[],
511786baecfSMauro Carvalho Chehab 								int num)
512786baecfSMauro Carvalho Chehab {
513786baecfSMauro Carvalho Chehab 	struct dvb_usb_device *d = i2c_get_adapdata(adap);
514786baecfSMauro Carvalho Chehab 	struct usb_device *udev;
515786baecfSMauro Carvalho Chehab 	int len, i, j;
516786baecfSMauro Carvalho Chehab 
517786baecfSMauro Carvalho Chehab 	if (!d)
518786baecfSMauro Carvalho Chehab 		return -ENODEV;
519786baecfSMauro Carvalho Chehab 	udev = d->udev;
520786baecfSMauro Carvalho Chehab 	if (mutex_lock_interruptible(&d->i2c_mutex) < 0)
521786baecfSMauro Carvalho Chehab 		return -EAGAIN;
522786baecfSMauro Carvalho Chehab 
523786baecfSMauro Carvalho Chehab 	for (j = 0; j < num; j++) {
524786baecfSMauro Carvalho Chehab 		switch (msg[j].addr) {
525786baecfSMauro Carvalho Chehab 		case (DW2102_RC_QUERY): {
526786baecfSMauro Carvalho Chehab 			u8 ibuf[5];
527786baecfSMauro Carvalho Chehab 			dw210x_op_rw(d->udev, 0xb8, 0, 0,
528786baecfSMauro Carvalho Chehab 					ibuf, 5, DW210X_READ_MSG);
529786baecfSMauro Carvalho Chehab 			memcpy(msg[j].buf, ibuf + 3, 2);
530786baecfSMauro Carvalho Chehab 			break;
531786baecfSMauro Carvalho Chehab 		}
532786baecfSMauro Carvalho Chehab 		case (DW2102_VOLTAGE_CTRL): {
533786baecfSMauro Carvalho Chehab 			u8 obuf[2];
534786baecfSMauro Carvalho Chehab 
535786baecfSMauro Carvalho Chehab 			obuf[0] = 1;
536786baecfSMauro Carvalho Chehab 			obuf[1] = msg[j].buf[1];/* off-on */
537786baecfSMauro Carvalho Chehab 			dw210x_op_rw(d->udev, 0x8a, 0, 0,
538786baecfSMauro Carvalho Chehab 					obuf, 2, DW210X_WRITE_MSG);
539786baecfSMauro Carvalho Chehab 			obuf[0] = 3;
540786baecfSMauro Carvalho Chehab 			obuf[1] = msg[j].buf[0];/* 13v-18v */
541786baecfSMauro Carvalho Chehab 			dw210x_op_rw(d->udev, 0x8a, 0, 0,
542786baecfSMauro Carvalho Chehab 					obuf, 2, DW210X_WRITE_MSG);
543786baecfSMauro Carvalho Chehab 			break;
544786baecfSMauro Carvalho Chehab 		}
545786baecfSMauro Carvalho Chehab 		case (DW2102_LED_CTRL): {
546786baecfSMauro Carvalho Chehab 			u8 obuf[2];
547786baecfSMauro Carvalho Chehab 
548786baecfSMauro Carvalho Chehab 			obuf[0] = 5;
549786baecfSMauro Carvalho Chehab 			obuf[1] = msg[j].buf[0];
550786baecfSMauro Carvalho Chehab 			dw210x_op_rw(d->udev, 0x8a, 0, 0,
551786baecfSMauro Carvalho Chehab 					obuf, 2, DW210X_WRITE_MSG);
552786baecfSMauro Carvalho Chehab 			break;
553786baecfSMauro Carvalho Chehab 		}
554786baecfSMauro Carvalho Chehab 		/*case 0x55: cx24116
555786baecfSMauro Carvalho Chehab 		case 0x6a: stv0903
556*955d00acSIgor M. Liplianin 		case 0x68: ds3000, stv0903, rs2000
557786baecfSMauro Carvalho Chehab 		case 0x60: ts2020, stv6110, stb6100
558786baecfSMauro Carvalho Chehab 		case 0xa0: eeprom */
559786baecfSMauro Carvalho Chehab 		default: {
560786baecfSMauro Carvalho Chehab 			if (msg[j].flags == I2C_M_RD) {
561786baecfSMauro Carvalho Chehab 				/* read registers */
562786baecfSMauro Carvalho Chehab 				u8 ibuf[msg[j].len];
563786baecfSMauro Carvalho Chehab 				dw210x_op_rw(d->udev, 0x91, 0, 0,
564786baecfSMauro Carvalho Chehab 						ibuf, msg[j].len,
565786baecfSMauro Carvalho Chehab 						DW210X_READ_MSG);
566786baecfSMauro Carvalho Chehab 				memcpy(msg[j].buf, ibuf, msg[j].len);
567786baecfSMauro Carvalho Chehab 				break;
568786baecfSMauro Carvalho Chehab 			} else if ((msg[j].buf[0] == 0xb0) &&
569786baecfSMauro Carvalho Chehab 						(msg[j].addr == 0x68)) {
570786baecfSMauro Carvalho Chehab 				/* write firmware */
571786baecfSMauro Carvalho Chehab 				u8 obuf[19];
572786baecfSMauro Carvalho Chehab 				obuf[0] = (msg[j].len > 16 ?
573786baecfSMauro Carvalho Chehab 						18 : msg[j].len + 1);
574786baecfSMauro Carvalho Chehab 				obuf[1] = msg[j].addr << 1;
575786baecfSMauro Carvalho Chehab 				obuf[2] = msg[j].buf[0];
576786baecfSMauro Carvalho Chehab 				len = msg[j].len - 1;
577786baecfSMauro Carvalho Chehab 				i = 1;
578786baecfSMauro Carvalho Chehab 				do {
579786baecfSMauro Carvalho Chehab 					memcpy(obuf + 3, msg[j].buf + i,
580786baecfSMauro Carvalho Chehab 							(len > 16 ? 16 : len));
581786baecfSMauro Carvalho Chehab 					dw210x_op_rw(d->udev, 0x80, 0, 0,
582786baecfSMauro Carvalho Chehab 						obuf, (len > 16 ? 16 : len) + 3,
583786baecfSMauro Carvalho Chehab 						DW210X_WRITE_MSG);
584786baecfSMauro Carvalho Chehab 					i += 16;
585786baecfSMauro Carvalho Chehab 					len -= 16;
586786baecfSMauro Carvalho Chehab 				} while (len > 0);
587786baecfSMauro Carvalho Chehab 			} else if (j < (num - 1)) {
588786baecfSMauro Carvalho Chehab 				/* write register addr before read */
589786baecfSMauro Carvalho Chehab 				u8 obuf[msg[j].len + 2];
590786baecfSMauro Carvalho Chehab 				obuf[0] = msg[j + 1].len;
591786baecfSMauro Carvalho Chehab 				obuf[1] = (msg[j].addr << 1);
592786baecfSMauro Carvalho Chehab 				memcpy(obuf + 2, msg[j].buf, msg[j].len);
593786baecfSMauro Carvalho Chehab 				dw210x_op_rw(d->udev,
594786baecfSMauro Carvalho Chehab 						udev->descriptor.idProduct ==
595786baecfSMauro Carvalho Chehab 						0x7500 ? 0x92 : 0x90, 0, 0,
596786baecfSMauro Carvalho Chehab 						obuf, msg[j].len + 2,
597786baecfSMauro Carvalho Chehab 						DW210X_WRITE_MSG);
598786baecfSMauro Carvalho Chehab 				break;
599786baecfSMauro Carvalho Chehab 			} else {
600786baecfSMauro Carvalho Chehab 				/* write registers */
601786baecfSMauro Carvalho Chehab 				u8 obuf[msg[j].len + 2];
602786baecfSMauro Carvalho Chehab 				obuf[0] = msg[j].len + 1;
603786baecfSMauro Carvalho Chehab 				obuf[1] = (msg[j].addr << 1);
604786baecfSMauro Carvalho Chehab 				memcpy(obuf + 2, msg[j].buf, msg[j].len);
605786baecfSMauro Carvalho Chehab 				dw210x_op_rw(d->udev, 0x80, 0, 0,
606786baecfSMauro Carvalho Chehab 						obuf, msg[j].len + 2,
607786baecfSMauro Carvalho Chehab 						DW210X_WRITE_MSG);
608786baecfSMauro Carvalho Chehab 				break;
609786baecfSMauro Carvalho Chehab 			}
610786baecfSMauro Carvalho Chehab 			break;
611786baecfSMauro Carvalho Chehab 		}
612786baecfSMauro Carvalho Chehab 		}
613786baecfSMauro Carvalho Chehab 	}
614786baecfSMauro Carvalho Chehab 
615786baecfSMauro Carvalho Chehab 	mutex_unlock(&d->i2c_mutex);
616786baecfSMauro Carvalho Chehab 	return num;
617786baecfSMauro Carvalho Chehab }
618786baecfSMauro Carvalho Chehab 
619786baecfSMauro Carvalho Chehab static int su3000_i2c_transfer(struct i2c_adapter *adap, struct i2c_msg msg[],
620786baecfSMauro Carvalho Chehab 								int num)
621786baecfSMauro Carvalho Chehab {
622786baecfSMauro Carvalho Chehab 	struct dvb_usb_device *d = i2c_get_adapdata(adap);
623786baecfSMauro Carvalho Chehab 	u8 obuf[0x40], ibuf[0x40];
624786baecfSMauro Carvalho Chehab 
625786baecfSMauro Carvalho Chehab 	if (!d)
626786baecfSMauro Carvalho Chehab 		return -ENODEV;
627786baecfSMauro Carvalho Chehab 	if (mutex_lock_interruptible(&d->i2c_mutex) < 0)
628786baecfSMauro Carvalho Chehab 		return -EAGAIN;
629786baecfSMauro Carvalho Chehab 
630786baecfSMauro Carvalho Chehab 	switch (num) {
631786baecfSMauro Carvalho Chehab 	case 1:
632786baecfSMauro Carvalho Chehab 		switch (msg[0].addr) {
633786baecfSMauro Carvalho Chehab 		case SU3000_STREAM_CTRL:
634786baecfSMauro Carvalho Chehab 			obuf[0] = msg[0].buf[0] + 0x36;
635786baecfSMauro Carvalho Chehab 			obuf[1] = 3;
636786baecfSMauro Carvalho Chehab 			obuf[2] = 0;
637786baecfSMauro Carvalho Chehab 			if (dvb_usb_generic_rw(d, obuf, 3, ibuf, 0, 0) < 0)
638786baecfSMauro Carvalho Chehab 				err("i2c transfer failed.");
639786baecfSMauro Carvalho Chehab 			break;
640786baecfSMauro Carvalho Chehab 		case DW2102_RC_QUERY:
641786baecfSMauro Carvalho Chehab 			obuf[0] = 0x10;
642786baecfSMauro Carvalho Chehab 			if (dvb_usb_generic_rw(d, obuf, 1, ibuf, 2, 0) < 0)
643786baecfSMauro Carvalho Chehab 				err("i2c transfer failed.");
644786baecfSMauro Carvalho Chehab 			msg[0].buf[1] = ibuf[0];
645786baecfSMauro Carvalho Chehab 			msg[0].buf[0] = ibuf[1];
646786baecfSMauro Carvalho Chehab 			break;
647786baecfSMauro Carvalho Chehab 		default:
648786baecfSMauro Carvalho Chehab 			/* always i2c write*/
649786baecfSMauro Carvalho Chehab 			obuf[0] = 0x08;
650786baecfSMauro Carvalho Chehab 			obuf[1] = msg[0].addr;
651786baecfSMauro Carvalho Chehab 			obuf[2] = msg[0].len;
652786baecfSMauro Carvalho Chehab 
653786baecfSMauro Carvalho Chehab 			memcpy(&obuf[3], msg[0].buf, msg[0].len);
654786baecfSMauro Carvalho Chehab 
655786baecfSMauro Carvalho Chehab 			if (dvb_usb_generic_rw(d, obuf, msg[0].len + 3,
656786baecfSMauro Carvalho Chehab 						ibuf, 1, 0) < 0)
657786baecfSMauro Carvalho Chehab 				err("i2c transfer failed.");
658786baecfSMauro Carvalho Chehab 
659786baecfSMauro Carvalho Chehab 		}
660786baecfSMauro Carvalho Chehab 		break;
661786baecfSMauro Carvalho Chehab 	case 2:
662786baecfSMauro Carvalho Chehab 		/* always i2c read */
663786baecfSMauro Carvalho Chehab 		obuf[0] = 0x09;
664786baecfSMauro Carvalho Chehab 		obuf[1] = msg[0].len;
665786baecfSMauro Carvalho Chehab 		obuf[2] = msg[1].len;
666786baecfSMauro Carvalho Chehab 		obuf[3] = msg[0].addr;
667786baecfSMauro Carvalho Chehab 		memcpy(&obuf[4], msg[0].buf, msg[0].len);
668786baecfSMauro Carvalho Chehab 
669786baecfSMauro Carvalho Chehab 		if (dvb_usb_generic_rw(d, obuf, msg[0].len + 4,
670786baecfSMauro Carvalho Chehab 					ibuf, msg[1].len + 1, 0) < 0)
671786baecfSMauro Carvalho Chehab 			err("i2c transfer failed.");
672786baecfSMauro Carvalho Chehab 
673786baecfSMauro Carvalho Chehab 		memcpy(msg[1].buf, &ibuf[1], msg[1].len);
674786baecfSMauro Carvalho Chehab 		break;
675786baecfSMauro Carvalho Chehab 	default:
676786baecfSMauro Carvalho Chehab 		warn("more than 2 i2c messages at a time is not handled yet.");
677786baecfSMauro Carvalho Chehab 		break;
678786baecfSMauro Carvalho Chehab 	}
679786baecfSMauro Carvalho Chehab 	mutex_unlock(&d->i2c_mutex);
680786baecfSMauro Carvalho Chehab 	return num;
681786baecfSMauro Carvalho Chehab }
682786baecfSMauro Carvalho Chehab 
683786baecfSMauro Carvalho Chehab static u32 dw210x_i2c_func(struct i2c_adapter *adapter)
684786baecfSMauro Carvalho Chehab {
685786baecfSMauro Carvalho Chehab 	return I2C_FUNC_I2C;
686786baecfSMauro Carvalho Chehab }
687786baecfSMauro Carvalho Chehab 
688786baecfSMauro Carvalho Chehab static struct i2c_algorithm dw2102_i2c_algo = {
689786baecfSMauro Carvalho Chehab 	.master_xfer = dw2102_i2c_transfer,
690786baecfSMauro Carvalho Chehab 	.functionality = dw210x_i2c_func,
691786baecfSMauro Carvalho Chehab };
692786baecfSMauro Carvalho Chehab 
693786baecfSMauro Carvalho Chehab static struct i2c_algorithm dw2102_serit_i2c_algo = {
694786baecfSMauro Carvalho Chehab 	.master_xfer = dw2102_serit_i2c_transfer,
695786baecfSMauro Carvalho Chehab 	.functionality = dw210x_i2c_func,
696786baecfSMauro Carvalho Chehab };
697786baecfSMauro Carvalho Chehab 
698786baecfSMauro Carvalho Chehab static struct i2c_algorithm dw2102_earda_i2c_algo = {
699786baecfSMauro Carvalho Chehab 	.master_xfer = dw2102_earda_i2c_transfer,
700786baecfSMauro Carvalho Chehab 	.functionality = dw210x_i2c_func,
701786baecfSMauro Carvalho Chehab };
702786baecfSMauro Carvalho Chehab 
703786baecfSMauro Carvalho Chehab static struct i2c_algorithm dw2104_i2c_algo = {
704786baecfSMauro Carvalho Chehab 	.master_xfer = dw2104_i2c_transfer,
705786baecfSMauro Carvalho Chehab 	.functionality = dw210x_i2c_func,
706786baecfSMauro Carvalho Chehab };
707786baecfSMauro Carvalho Chehab 
708786baecfSMauro Carvalho Chehab static struct i2c_algorithm dw3101_i2c_algo = {
709786baecfSMauro Carvalho Chehab 	.master_xfer = dw3101_i2c_transfer,
710786baecfSMauro Carvalho Chehab 	.functionality = dw210x_i2c_func,
711786baecfSMauro Carvalho Chehab };
712786baecfSMauro Carvalho Chehab 
713786baecfSMauro Carvalho Chehab static struct i2c_algorithm s6x0_i2c_algo = {
714786baecfSMauro Carvalho Chehab 	.master_xfer = s6x0_i2c_transfer,
715786baecfSMauro Carvalho Chehab 	.functionality = dw210x_i2c_func,
716786baecfSMauro Carvalho Chehab };
717786baecfSMauro Carvalho Chehab 
718786baecfSMauro Carvalho Chehab static struct i2c_algorithm su3000_i2c_algo = {
719786baecfSMauro Carvalho Chehab 	.master_xfer = su3000_i2c_transfer,
720786baecfSMauro Carvalho Chehab 	.functionality = dw210x_i2c_func,
721786baecfSMauro Carvalho Chehab };
722786baecfSMauro Carvalho Chehab 
723786baecfSMauro Carvalho Chehab static int dw210x_read_mac_address(struct dvb_usb_device *d, u8 mac[6])
724786baecfSMauro Carvalho Chehab {
725786baecfSMauro Carvalho Chehab 	int i;
726786baecfSMauro Carvalho Chehab 	u8 ibuf[] = {0, 0};
727786baecfSMauro Carvalho Chehab 	u8 eeprom[256], eepromline[16];
728786baecfSMauro Carvalho Chehab 
729786baecfSMauro Carvalho Chehab 	for (i = 0; i < 256; i++) {
730786baecfSMauro Carvalho Chehab 		if (dw210x_op_rw(d->udev, 0xb6, 0xa0 , i, ibuf, 2, DW210X_READ_MSG) < 0) {
731786baecfSMauro Carvalho Chehab 			err("read eeprom failed.");
732786baecfSMauro Carvalho Chehab 			return -1;
733786baecfSMauro Carvalho Chehab 		} else {
734786baecfSMauro Carvalho Chehab 			eepromline[i%16] = ibuf[0];
735786baecfSMauro Carvalho Chehab 			eeprom[i] = ibuf[0];
736786baecfSMauro Carvalho Chehab 		}
737786baecfSMauro Carvalho Chehab 		if ((i % 16) == 15) {
738786baecfSMauro Carvalho Chehab 			deb_xfer("%02x: ", i - 15);
739786baecfSMauro Carvalho Chehab 			debug_dump(eepromline, 16, deb_xfer);
740786baecfSMauro Carvalho Chehab 		}
741786baecfSMauro Carvalho Chehab 	}
742786baecfSMauro Carvalho Chehab 
743786baecfSMauro Carvalho Chehab 	memcpy(mac, eeprom + 8, 6);
744786baecfSMauro Carvalho Chehab 	return 0;
745786baecfSMauro Carvalho Chehab };
746786baecfSMauro Carvalho Chehab 
747786baecfSMauro Carvalho Chehab static int s6x0_read_mac_address(struct dvb_usb_device *d, u8 mac[6])
748786baecfSMauro Carvalho Chehab {
749786baecfSMauro Carvalho Chehab 	int i, ret;
750786baecfSMauro Carvalho Chehab 	u8 ibuf[] = { 0 }, obuf[] = { 0 };
751786baecfSMauro Carvalho Chehab 	u8 eeprom[256], eepromline[16];
752786baecfSMauro Carvalho Chehab 	struct i2c_msg msg[] = {
753786baecfSMauro Carvalho Chehab 		{
754786baecfSMauro Carvalho Chehab 			.addr = 0xa0 >> 1,
755786baecfSMauro Carvalho Chehab 			.flags = 0,
756786baecfSMauro Carvalho Chehab 			.buf = obuf,
757786baecfSMauro Carvalho Chehab 			.len = 1,
758786baecfSMauro Carvalho Chehab 		}, {
759786baecfSMauro Carvalho Chehab 			.addr = 0xa0 >> 1,
760786baecfSMauro Carvalho Chehab 			.flags = I2C_M_RD,
761786baecfSMauro Carvalho Chehab 			.buf = ibuf,
762786baecfSMauro Carvalho Chehab 			.len = 1,
763786baecfSMauro Carvalho Chehab 		}
764786baecfSMauro Carvalho Chehab 	};
765786baecfSMauro Carvalho Chehab 
766786baecfSMauro Carvalho Chehab 	for (i = 0; i < 256; i++) {
767786baecfSMauro Carvalho Chehab 		obuf[0] = i;
768786baecfSMauro Carvalho Chehab 		ret = s6x0_i2c_transfer(&d->i2c_adap, msg, 2);
769786baecfSMauro Carvalho Chehab 		if (ret != 2) {
770786baecfSMauro Carvalho Chehab 			err("read eeprom failed.");
771786baecfSMauro Carvalho Chehab 			return -1;
772786baecfSMauro Carvalho Chehab 		} else {
773786baecfSMauro Carvalho Chehab 			eepromline[i % 16] = ibuf[0];
774786baecfSMauro Carvalho Chehab 			eeprom[i] = ibuf[0];
775786baecfSMauro Carvalho Chehab 		}
776786baecfSMauro Carvalho Chehab 
777786baecfSMauro Carvalho Chehab 		if ((i % 16) == 15) {
778786baecfSMauro Carvalho Chehab 			deb_xfer("%02x: ", i - 15);
779786baecfSMauro Carvalho Chehab 			debug_dump(eepromline, 16, deb_xfer);
780786baecfSMauro Carvalho Chehab 		}
781786baecfSMauro Carvalho Chehab 	}
782786baecfSMauro Carvalho Chehab 
783786baecfSMauro Carvalho Chehab 	memcpy(mac, eeprom + 16, 6);
784786baecfSMauro Carvalho Chehab 	return 0;
785786baecfSMauro Carvalho Chehab };
786786baecfSMauro Carvalho Chehab 
787786baecfSMauro Carvalho Chehab static int su3000_streaming_ctrl(struct dvb_usb_adapter *adap, int onoff)
788786baecfSMauro Carvalho Chehab {
789786baecfSMauro Carvalho Chehab 	static u8 command_start[] = {0x00};
790786baecfSMauro Carvalho Chehab 	static u8 command_stop[] = {0x01};
791786baecfSMauro Carvalho Chehab 	struct i2c_msg msg = {
792786baecfSMauro Carvalho Chehab 		.addr = SU3000_STREAM_CTRL,
793786baecfSMauro Carvalho Chehab 		.flags = 0,
794786baecfSMauro Carvalho Chehab 		.buf = onoff ? command_start : command_stop,
795786baecfSMauro Carvalho Chehab 		.len = 1
796786baecfSMauro Carvalho Chehab 	};
797786baecfSMauro Carvalho Chehab 
798786baecfSMauro Carvalho Chehab 	i2c_transfer(&adap->dev->i2c_adap, &msg, 1);
799786baecfSMauro Carvalho Chehab 
800786baecfSMauro Carvalho Chehab 	return 0;
801786baecfSMauro Carvalho Chehab }
802786baecfSMauro Carvalho Chehab 
803786baecfSMauro Carvalho Chehab static int su3000_power_ctrl(struct dvb_usb_device *d, int i)
804786baecfSMauro Carvalho Chehab {
805786baecfSMauro Carvalho Chehab 	struct su3000_state *state = (struct su3000_state *)d->priv;
806786baecfSMauro Carvalho Chehab 	u8 obuf[] = {0xde, 0};
807786baecfSMauro Carvalho Chehab 
808786baecfSMauro Carvalho Chehab 	info("%s: %d, initialized %d\n", __func__, i, state->initialized);
809786baecfSMauro Carvalho Chehab 
810786baecfSMauro Carvalho Chehab 	if (i && !state->initialized) {
811786baecfSMauro Carvalho Chehab 		state->initialized = 1;
812786baecfSMauro Carvalho Chehab 		/* reset board */
813786baecfSMauro Carvalho Chehab 		dvb_usb_generic_rw(d, obuf, 2, NULL, 0, 0);
814786baecfSMauro Carvalho Chehab 	}
815786baecfSMauro Carvalho Chehab 
816786baecfSMauro Carvalho Chehab 	return 0;
817786baecfSMauro Carvalho Chehab }
818786baecfSMauro Carvalho Chehab 
819786baecfSMauro Carvalho Chehab static int su3000_read_mac_address(struct dvb_usb_device *d, u8 mac[6])
820786baecfSMauro Carvalho Chehab {
821786baecfSMauro Carvalho Chehab 	int i;
822786baecfSMauro Carvalho Chehab 	u8 obuf[] = { 0x1f, 0xf0 };
823786baecfSMauro Carvalho Chehab 	u8 ibuf[] = { 0 };
824786baecfSMauro Carvalho Chehab 	struct i2c_msg msg[] = {
825786baecfSMauro Carvalho Chehab 		{
826786baecfSMauro Carvalho Chehab 			.addr = 0x51,
827786baecfSMauro Carvalho Chehab 			.flags = 0,
828786baecfSMauro Carvalho Chehab 			.buf = obuf,
829786baecfSMauro Carvalho Chehab 			.len = 2,
830786baecfSMauro Carvalho Chehab 		}, {
831786baecfSMauro Carvalho Chehab 			.addr = 0x51,
832786baecfSMauro Carvalho Chehab 			.flags = I2C_M_RD,
833786baecfSMauro Carvalho Chehab 			.buf = ibuf,
834786baecfSMauro Carvalho Chehab 			.len = 1,
835786baecfSMauro Carvalho Chehab 
836786baecfSMauro Carvalho Chehab 		}
837786baecfSMauro Carvalho Chehab 	};
838786baecfSMauro Carvalho Chehab 
839786baecfSMauro Carvalho Chehab 	for (i = 0; i < 6; i++) {
840786baecfSMauro Carvalho Chehab 		obuf[1] = 0xf0 + i;
841786baecfSMauro Carvalho Chehab 		if (i2c_transfer(&d->i2c_adap, msg, 2) != 2)
842786baecfSMauro Carvalho Chehab 			break;
843786baecfSMauro Carvalho Chehab 		else
844786baecfSMauro Carvalho Chehab 			mac[i] = ibuf[0];
845786baecfSMauro Carvalho Chehab 
846786baecfSMauro Carvalho Chehab 		debug_dump(mac, 6, printk);
847786baecfSMauro Carvalho Chehab 	}
848786baecfSMauro Carvalho Chehab 
849786baecfSMauro Carvalho Chehab 	return 0;
850786baecfSMauro Carvalho Chehab }
851786baecfSMauro Carvalho Chehab 
852786baecfSMauro Carvalho Chehab static int su3000_identify_state(struct usb_device *udev,
853786baecfSMauro Carvalho Chehab 				 struct dvb_usb_device_properties *props,
854786baecfSMauro Carvalho Chehab 				 struct dvb_usb_device_description **desc,
855786baecfSMauro Carvalho Chehab 				 int *cold)
856786baecfSMauro Carvalho Chehab {
857786baecfSMauro Carvalho Chehab 	info("%s\n", __func__);
858786baecfSMauro Carvalho Chehab 
859786baecfSMauro Carvalho Chehab 	*cold = 0;
860786baecfSMauro Carvalho Chehab 	return 0;
861786baecfSMauro Carvalho Chehab }
862786baecfSMauro Carvalho Chehab 
863786baecfSMauro Carvalho Chehab static int dw210x_set_voltage(struct dvb_frontend *fe, fe_sec_voltage_t voltage)
864786baecfSMauro Carvalho Chehab {
865786baecfSMauro Carvalho Chehab 	static u8 command_13v[] = {0x00, 0x01};
866786baecfSMauro Carvalho Chehab 	static u8 command_18v[] = {0x01, 0x01};
867786baecfSMauro Carvalho Chehab 	static u8 command_off[] = {0x00, 0x00};
868786baecfSMauro Carvalho Chehab 	struct i2c_msg msg = {
869786baecfSMauro Carvalho Chehab 		.addr = DW2102_VOLTAGE_CTRL,
870786baecfSMauro Carvalho Chehab 		.flags = 0,
871786baecfSMauro Carvalho Chehab 		.buf = command_off,
872786baecfSMauro Carvalho Chehab 		.len = 2,
873786baecfSMauro Carvalho Chehab 	};
874786baecfSMauro Carvalho Chehab 
875786baecfSMauro Carvalho Chehab 	struct dvb_usb_adapter *udev_adap =
876786baecfSMauro Carvalho Chehab 		(struct dvb_usb_adapter *)(fe->dvb->priv);
877786baecfSMauro Carvalho Chehab 	if (voltage == SEC_VOLTAGE_18)
878786baecfSMauro Carvalho Chehab 		msg.buf = command_18v;
879786baecfSMauro Carvalho Chehab 	else if (voltage == SEC_VOLTAGE_13)
880786baecfSMauro Carvalho Chehab 		msg.buf = command_13v;
881786baecfSMauro Carvalho Chehab 
882786baecfSMauro Carvalho Chehab 	i2c_transfer(&udev_adap->dev->i2c_adap, &msg, 1);
883786baecfSMauro Carvalho Chehab 
884786baecfSMauro Carvalho Chehab 	return 0;
885786baecfSMauro Carvalho Chehab }
886786baecfSMauro Carvalho Chehab 
887786baecfSMauro Carvalho Chehab static int s660_set_voltage(struct dvb_frontend *fe, fe_sec_voltage_t voltage)
888786baecfSMauro Carvalho Chehab {
889786baecfSMauro Carvalho Chehab 	struct dvb_usb_adapter *d =
890786baecfSMauro Carvalho Chehab 		(struct dvb_usb_adapter *)(fe->dvb->priv);
891786baecfSMauro Carvalho Chehab 	struct s6x0_state *st = (struct s6x0_state *)d->dev->priv;
892786baecfSMauro Carvalho Chehab 
893786baecfSMauro Carvalho Chehab 	dw210x_set_voltage(fe, voltage);
894786baecfSMauro Carvalho Chehab 	if (st->old_set_voltage)
895786baecfSMauro Carvalho Chehab 		st->old_set_voltage(fe, voltage);
896786baecfSMauro Carvalho Chehab 
897786baecfSMauro Carvalho Chehab 	return 0;
898786baecfSMauro Carvalho Chehab }
899786baecfSMauro Carvalho Chehab 
900786baecfSMauro Carvalho Chehab static void dw210x_led_ctrl(struct dvb_frontend *fe, int offon)
901786baecfSMauro Carvalho Chehab {
902786baecfSMauro Carvalho Chehab 	static u8 led_off[] = { 0 };
903786baecfSMauro Carvalho Chehab 	static u8 led_on[] = { 1 };
904786baecfSMauro Carvalho Chehab 	struct i2c_msg msg = {
905786baecfSMauro Carvalho Chehab 		.addr = DW2102_LED_CTRL,
906786baecfSMauro Carvalho Chehab 		.flags = 0,
907786baecfSMauro Carvalho Chehab 		.buf = led_off,
908786baecfSMauro Carvalho Chehab 		.len = 1
909786baecfSMauro Carvalho Chehab 	};
910786baecfSMauro Carvalho Chehab 	struct dvb_usb_adapter *udev_adap =
911786baecfSMauro Carvalho Chehab 		(struct dvb_usb_adapter *)(fe->dvb->priv);
912786baecfSMauro Carvalho Chehab 
913786baecfSMauro Carvalho Chehab 	if (offon)
914786baecfSMauro Carvalho Chehab 		msg.buf = led_on;
915786baecfSMauro Carvalho Chehab 	i2c_transfer(&udev_adap->dev->i2c_adap, &msg, 1);
916786baecfSMauro Carvalho Chehab }
917786baecfSMauro Carvalho Chehab 
918786baecfSMauro Carvalho Chehab static struct stv0299_config sharp_z0194a_config = {
919786baecfSMauro Carvalho Chehab 	.demod_address = 0x68,
920786baecfSMauro Carvalho Chehab 	.inittab = sharp_z0194a_inittab,
921786baecfSMauro Carvalho Chehab 	.mclk = 88000000UL,
922786baecfSMauro Carvalho Chehab 	.invert = 1,
923786baecfSMauro Carvalho Chehab 	.skip_reinit = 0,
924786baecfSMauro Carvalho Chehab 	.lock_output = STV0299_LOCKOUTPUT_1,
925786baecfSMauro Carvalho Chehab 	.volt13_op0_op1 = STV0299_VOLT13_OP1,
926786baecfSMauro Carvalho Chehab 	.min_delay_ms = 100,
927786baecfSMauro Carvalho Chehab 	.set_symbol_rate = sharp_z0194a_set_symbol_rate,
928786baecfSMauro Carvalho Chehab };
929786baecfSMauro Carvalho Chehab 
930786baecfSMauro Carvalho Chehab static struct cx24116_config dw2104_config = {
931786baecfSMauro Carvalho Chehab 	.demod_address = 0x55,
932786baecfSMauro Carvalho Chehab 	.mpg_clk_pos_pol = 0x01,
933786baecfSMauro Carvalho Chehab };
934786baecfSMauro Carvalho Chehab 
935786baecfSMauro Carvalho Chehab static struct si21xx_config serit_sp1511lhb_config = {
936786baecfSMauro Carvalho Chehab 	.demod_address = 0x68,
937786baecfSMauro Carvalho Chehab 	.min_delay_ms = 100,
938786baecfSMauro Carvalho Chehab 
939786baecfSMauro Carvalho Chehab };
940786baecfSMauro Carvalho Chehab 
941786baecfSMauro Carvalho Chehab static struct tda10023_config dw3101_tda10023_config = {
942786baecfSMauro Carvalho Chehab 	.demod_address = 0x0c,
943786baecfSMauro Carvalho Chehab 	.invert = 1,
944786baecfSMauro Carvalho Chehab };
945786baecfSMauro Carvalho Chehab 
946786baecfSMauro Carvalho Chehab static struct mt312_config zl313_config = {
947786baecfSMauro Carvalho Chehab 	.demod_address = 0x0e,
948786baecfSMauro Carvalho Chehab };
949786baecfSMauro Carvalho Chehab 
950786baecfSMauro Carvalho Chehab static struct ds3000_config dw2104_ds3000_config = {
951786baecfSMauro Carvalho Chehab 	.demod_address = 0x68,
952786baecfSMauro Carvalho Chehab };
953786baecfSMauro Carvalho Chehab 
95473f0af44SKonstantin Dimitrov static struct ts2020_config dw2104_ts2020_config  = {
95573f0af44SKonstantin Dimitrov 	.tuner_address = 0x60,
95673f0af44SKonstantin Dimitrov };
95773f0af44SKonstantin Dimitrov 
958786baecfSMauro Carvalho Chehab static struct stv0900_config dw2104a_stv0900_config = {
959786baecfSMauro Carvalho Chehab 	.demod_address = 0x6a,
960786baecfSMauro Carvalho Chehab 	.demod_mode = 0,
961786baecfSMauro Carvalho Chehab 	.xtal = 27000000,
962786baecfSMauro Carvalho Chehab 	.clkmode = 3,/* 0-CLKI, 2-XTALI, else AUTO */
963786baecfSMauro Carvalho Chehab 	.diseqc_mode = 2,/* 2/3 PWM */
964786baecfSMauro Carvalho Chehab 	.tun1_maddress = 0,/* 0x60 */
965786baecfSMauro Carvalho Chehab 	.tun1_adc = 0,/* 2 Vpp */
966786baecfSMauro Carvalho Chehab 	.path1_mode = 3,
967786baecfSMauro Carvalho Chehab };
968786baecfSMauro Carvalho Chehab 
969786baecfSMauro Carvalho Chehab static struct stb6100_config dw2104a_stb6100_config = {
970786baecfSMauro Carvalho Chehab 	.tuner_address = 0x60,
971786baecfSMauro Carvalho Chehab 	.refclock = 27000000,
972786baecfSMauro Carvalho Chehab };
973786baecfSMauro Carvalho Chehab 
974786baecfSMauro Carvalho Chehab static struct stv0900_config dw2104_stv0900_config = {
975786baecfSMauro Carvalho Chehab 	.demod_address = 0x68,
976786baecfSMauro Carvalho Chehab 	.demod_mode = 0,
977786baecfSMauro Carvalho Chehab 	.xtal = 8000000,
978786baecfSMauro Carvalho Chehab 	.clkmode = 3,
979786baecfSMauro Carvalho Chehab 	.diseqc_mode = 2,
980786baecfSMauro Carvalho Chehab 	.tun1_maddress = 0,
981786baecfSMauro Carvalho Chehab 	.tun1_adc = 1,/* 1 Vpp */
982786baecfSMauro Carvalho Chehab 	.path1_mode = 3,
983786baecfSMauro Carvalho Chehab };
984786baecfSMauro Carvalho Chehab 
985786baecfSMauro Carvalho Chehab static struct stv6110_config dw2104_stv6110_config = {
986786baecfSMauro Carvalho Chehab 	.i2c_address = 0x60,
987786baecfSMauro Carvalho Chehab 	.mclk = 16000000,
988786baecfSMauro Carvalho Chehab 	.clk_div = 1,
989786baecfSMauro Carvalho Chehab };
990786baecfSMauro Carvalho Chehab 
991786baecfSMauro Carvalho Chehab static struct stv0900_config prof_7500_stv0900_config = {
992786baecfSMauro Carvalho Chehab 	.demod_address = 0x6a,
993786baecfSMauro Carvalho Chehab 	.demod_mode = 0,
994786baecfSMauro Carvalho Chehab 	.xtal = 27000000,
995786baecfSMauro Carvalho Chehab 	.clkmode = 3,/* 0-CLKI, 2-XTALI, else AUTO */
996786baecfSMauro Carvalho Chehab 	.diseqc_mode = 2,/* 2/3 PWM */
997786baecfSMauro Carvalho Chehab 	.tun1_maddress = 0,/* 0x60 */
998786baecfSMauro Carvalho Chehab 	.tun1_adc = 0,/* 2 Vpp */
999786baecfSMauro Carvalho Chehab 	.path1_mode = 3,
1000786baecfSMauro Carvalho Chehab 	.tun1_type = 3,
1001786baecfSMauro Carvalho Chehab 	.set_lock_led = dw210x_led_ctrl,
1002786baecfSMauro Carvalho Chehab };
1003786baecfSMauro Carvalho Chehab 
1004786baecfSMauro Carvalho Chehab static struct ds3000_config su3000_ds3000_config = {
1005786baecfSMauro Carvalho Chehab 	.demod_address = 0x68,
1006786baecfSMauro Carvalho Chehab 	.ci_mode = 1,
1007786baecfSMauro Carvalho Chehab };
1008786baecfSMauro Carvalho Chehab 
100973f0af44SKonstantin Dimitrov static struct ts2020_config su3000_ts2020_config  = {
101073f0af44SKonstantin Dimitrov 	.tuner_address = 0x60,
101173f0af44SKonstantin Dimitrov };
101273f0af44SKonstantin Dimitrov 
1013*955d00acSIgor M. Liplianin static u8 m88rs2000_inittab[] = {
1014*955d00acSIgor M. Liplianin 	DEMOD_WRITE, 0x9a, 0x30,
1015*955d00acSIgor M. Liplianin 	DEMOD_WRITE, 0x00, 0x01,
1016*955d00acSIgor M. Liplianin 	WRITE_DELAY, 0x19, 0x00,
1017*955d00acSIgor M. Liplianin 	DEMOD_WRITE, 0x00, 0x00,
1018*955d00acSIgor M. Liplianin 	DEMOD_WRITE, 0x9a, 0xb0,
1019*955d00acSIgor M. Liplianin 	DEMOD_WRITE, 0x81, 0xc1,
1020*955d00acSIgor M. Liplianin 	TUNER_WRITE, 0x42, 0x73,
1021*955d00acSIgor M. Liplianin 	TUNER_WRITE, 0x05, 0x07,
1022*955d00acSIgor M. Liplianin 	TUNER_WRITE, 0x20, 0x27,
1023*955d00acSIgor M. Liplianin 	TUNER_WRITE, 0x07, 0x02,
1024*955d00acSIgor M. Liplianin 	TUNER_WRITE, 0x11, 0xff,
1025*955d00acSIgor M. Liplianin 	TUNER_WRITE, 0x60, 0xf9,
1026*955d00acSIgor M. Liplianin 	TUNER_WRITE, 0x08, 0x01,
1027*955d00acSIgor M. Liplianin 	TUNER_WRITE, 0x00, 0x41,
1028*955d00acSIgor M. Liplianin 	DEMOD_WRITE, 0x81, 0x81,
1029*955d00acSIgor M. Liplianin 	DEMOD_WRITE, 0x86, 0xc6,
1030*955d00acSIgor M. Liplianin 	DEMOD_WRITE, 0x9a, 0x30,
1031*955d00acSIgor M. Liplianin 	DEMOD_WRITE, 0xf0, 0x80,
1032*955d00acSIgor M. Liplianin 	DEMOD_WRITE, 0xf1, 0xbf,
1033*955d00acSIgor M. Liplianin 	DEMOD_WRITE, 0xb0, 0x45,
1034*955d00acSIgor M. Liplianin 	DEMOD_WRITE, 0xb2, 0x01,
1035*955d00acSIgor M. Liplianin 	DEMOD_WRITE, 0x9a, 0xb0,
1036*955d00acSIgor M. Liplianin 	0xff, 0xaa, 0xff
1037*955d00acSIgor M. Liplianin };
1038*955d00acSIgor M. Liplianin 
1039*955d00acSIgor M. Liplianin static struct m88rs2000_config s421_m88rs2000_config = {
1040*955d00acSIgor M. Liplianin 	.demod_addr = 0x68,
1041*955d00acSIgor M. Liplianin 	.tuner_addr = 0x60,
1042*955d00acSIgor M. Liplianin 	.inittab = m88rs2000_inittab,
1043*955d00acSIgor M. Liplianin };
1044*955d00acSIgor M. Liplianin 
1045786baecfSMauro Carvalho Chehab static int dw2104_frontend_attach(struct dvb_usb_adapter *d)
1046786baecfSMauro Carvalho Chehab {
1047786baecfSMauro Carvalho Chehab 	struct dvb_tuner_ops *tuner_ops = NULL;
1048786baecfSMauro Carvalho Chehab 
1049786baecfSMauro Carvalho Chehab 	if (demod_probe & 4) {
1050786baecfSMauro Carvalho Chehab 		d->fe_adap[0].fe = dvb_attach(stv0900_attach, &dw2104a_stv0900_config,
1051786baecfSMauro Carvalho Chehab 				&d->dev->i2c_adap, 0);
1052786baecfSMauro Carvalho Chehab 		if (d->fe_adap[0].fe != NULL) {
1053786baecfSMauro Carvalho Chehab 			if (dvb_attach(stb6100_attach, d->fe_adap[0].fe,
1054786baecfSMauro Carvalho Chehab 					&dw2104a_stb6100_config,
1055786baecfSMauro Carvalho Chehab 					&d->dev->i2c_adap)) {
1056786baecfSMauro Carvalho Chehab 				tuner_ops = &d->fe_adap[0].fe->ops.tuner_ops;
1057786baecfSMauro Carvalho Chehab 				tuner_ops->set_frequency = stb6100_set_freq;
1058786baecfSMauro Carvalho Chehab 				tuner_ops->get_frequency = stb6100_get_freq;
1059786baecfSMauro Carvalho Chehab 				tuner_ops->set_bandwidth = stb6100_set_bandw;
1060786baecfSMauro Carvalho Chehab 				tuner_ops->get_bandwidth = stb6100_get_bandw;
1061786baecfSMauro Carvalho Chehab 				d->fe_adap[0].fe->ops.set_voltage = dw210x_set_voltage;
1062786baecfSMauro Carvalho Chehab 				info("Attached STV0900+STB6100!\n");
1063786baecfSMauro Carvalho Chehab 				return 0;
1064786baecfSMauro Carvalho Chehab 			}
1065786baecfSMauro Carvalho Chehab 		}
1066786baecfSMauro Carvalho Chehab 	}
1067786baecfSMauro Carvalho Chehab 
1068786baecfSMauro Carvalho Chehab 	if (demod_probe & 2) {
1069786baecfSMauro Carvalho Chehab 		d->fe_adap[0].fe = dvb_attach(stv0900_attach, &dw2104_stv0900_config,
1070786baecfSMauro Carvalho Chehab 				&d->dev->i2c_adap, 0);
1071786baecfSMauro Carvalho Chehab 		if (d->fe_adap[0].fe != NULL) {
1072786baecfSMauro Carvalho Chehab 			if (dvb_attach(stv6110_attach, d->fe_adap[0].fe,
1073786baecfSMauro Carvalho Chehab 					&dw2104_stv6110_config,
1074786baecfSMauro Carvalho Chehab 					&d->dev->i2c_adap)) {
1075786baecfSMauro Carvalho Chehab 				d->fe_adap[0].fe->ops.set_voltage = dw210x_set_voltage;
1076786baecfSMauro Carvalho Chehab 				info("Attached STV0900+STV6110A!\n");
1077786baecfSMauro Carvalho Chehab 				return 0;
1078786baecfSMauro Carvalho Chehab 			}
1079786baecfSMauro Carvalho Chehab 		}
1080786baecfSMauro Carvalho Chehab 	}
1081786baecfSMauro Carvalho Chehab 
1082786baecfSMauro Carvalho Chehab 	if (demod_probe & 1) {
1083786baecfSMauro Carvalho Chehab 		d->fe_adap[0].fe = dvb_attach(cx24116_attach, &dw2104_config,
1084786baecfSMauro Carvalho Chehab 				&d->dev->i2c_adap);
1085786baecfSMauro Carvalho Chehab 		if (d->fe_adap[0].fe != NULL) {
1086786baecfSMauro Carvalho Chehab 			d->fe_adap[0].fe->ops.set_voltage = dw210x_set_voltage;
1087786baecfSMauro Carvalho Chehab 			info("Attached cx24116!\n");
1088786baecfSMauro Carvalho Chehab 			return 0;
1089786baecfSMauro Carvalho Chehab 		}
1090786baecfSMauro Carvalho Chehab 	}
1091786baecfSMauro Carvalho Chehab 
1092786baecfSMauro Carvalho Chehab 	d->fe_adap[0].fe = dvb_attach(ds3000_attach, &dw2104_ds3000_config,
1093786baecfSMauro Carvalho Chehab 			&d->dev->i2c_adap);
1094786baecfSMauro Carvalho Chehab 	if (d->fe_adap[0].fe != NULL) {
109573f0af44SKonstantin Dimitrov 		dvb_attach(ts2020_attach, d->fe_adap[0].fe,
109673f0af44SKonstantin Dimitrov 			&dw2104_ts2020_config, &d->dev->i2c_adap);
1097786baecfSMauro Carvalho Chehab 		d->fe_adap[0].fe->ops.set_voltage = dw210x_set_voltage;
1098786baecfSMauro Carvalho Chehab 		info("Attached DS3000!\n");
1099786baecfSMauro Carvalho Chehab 		return 0;
1100786baecfSMauro Carvalho Chehab 	}
1101786baecfSMauro Carvalho Chehab 
1102786baecfSMauro Carvalho Chehab 	return -EIO;
1103786baecfSMauro Carvalho Chehab }
1104786baecfSMauro Carvalho Chehab 
1105786baecfSMauro Carvalho Chehab static struct dvb_usb_device_properties dw2102_properties;
1106786baecfSMauro Carvalho Chehab static struct dvb_usb_device_properties dw2104_properties;
1107786baecfSMauro Carvalho Chehab static struct dvb_usb_device_properties s6x0_properties;
1108786baecfSMauro Carvalho Chehab 
1109786baecfSMauro Carvalho Chehab static int dw2102_frontend_attach(struct dvb_usb_adapter *d)
1110786baecfSMauro Carvalho Chehab {
1111786baecfSMauro Carvalho Chehab 	if (dw2102_properties.i2c_algo == &dw2102_serit_i2c_algo) {
1112786baecfSMauro Carvalho Chehab 		/*dw2102_properties.adapter->tuner_attach = NULL;*/
1113786baecfSMauro Carvalho Chehab 		d->fe_adap[0].fe = dvb_attach(si21xx_attach, &serit_sp1511lhb_config,
1114786baecfSMauro Carvalho Chehab 					&d->dev->i2c_adap);
1115786baecfSMauro Carvalho Chehab 		if (d->fe_adap[0].fe != NULL) {
1116786baecfSMauro Carvalho Chehab 			d->fe_adap[0].fe->ops.set_voltage = dw210x_set_voltage;
1117786baecfSMauro Carvalho Chehab 			info("Attached si21xx!\n");
1118786baecfSMauro Carvalho Chehab 			return 0;
1119786baecfSMauro Carvalho Chehab 		}
1120786baecfSMauro Carvalho Chehab 	}
1121786baecfSMauro Carvalho Chehab 
1122786baecfSMauro Carvalho Chehab 	if (dw2102_properties.i2c_algo == &dw2102_earda_i2c_algo) {
1123786baecfSMauro Carvalho Chehab 		d->fe_adap[0].fe = dvb_attach(stv0288_attach, &earda_config,
1124786baecfSMauro Carvalho Chehab 					&d->dev->i2c_adap);
1125786baecfSMauro Carvalho Chehab 		if (d->fe_adap[0].fe != NULL) {
1126786baecfSMauro Carvalho Chehab 			if (dvb_attach(stb6000_attach, d->fe_adap[0].fe, 0x61,
1127786baecfSMauro Carvalho Chehab 					&d->dev->i2c_adap)) {
1128786baecfSMauro Carvalho Chehab 				d->fe_adap[0].fe->ops.set_voltage = dw210x_set_voltage;
1129786baecfSMauro Carvalho Chehab 				info("Attached stv0288!\n");
1130786baecfSMauro Carvalho Chehab 				return 0;
1131786baecfSMauro Carvalho Chehab 			}
1132786baecfSMauro Carvalho Chehab 		}
1133786baecfSMauro Carvalho Chehab 	}
1134786baecfSMauro Carvalho Chehab 
1135786baecfSMauro Carvalho Chehab 	if (dw2102_properties.i2c_algo == &dw2102_i2c_algo) {
1136786baecfSMauro Carvalho Chehab 		/*dw2102_properties.adapter->tuner_attach = dw2102_tuner_attach;*/
1137786baecfSMauro Carvalho Chehab 		d->fe_adap[0].fe = dvb_attach(stv0299_attach, &sharp_z0194a_config,
1138786baecfSMauro Carvalho Chehab 					&d->dev->i2c_adap);
1139786baecfSMauro Carvalho Chehab 		if (d->fe_adap[0].fe != NULL) {
1140786baecfSMauro Carvalho Chehab 			d->fe_adap[0].fe->ops.set_voltage = dw210x_set_voltage;
1141786baecfSMauro Carvalho Chehab 			info("Attached stv0299!\n");
1142786baecfSMauro Carvalho Chehab 			return 0;
1143786baecfSMauro Carvalho Chehab 		}
1144786baecfSMauro Carvalho Chehab 	}
1145786baecfSMauro Carvalho Chehab 	return -EIO;
1146786baecfSMauro Carvalho Chehab }
1147786baecfSMauro Carvalho Chehab 
1148786baecfSMauro Carvalho Chehab static int dw3101_frontend_attach(struct dvb_usb_adapter *d)
1149786baecfSMauro Carvalho Chehab {
1150786baecfSMauro Carvalho Chehab 	d->fe_adap[0].fe = dvb_attach(tda10023_attach, &dw3101_tda10023_config,
1151786baecfSMauro Carvalho Chehab 				&d->dev->i2c_adap, 0x48);
1152786baecfSMauro Carvalho Chehab 	if (d->fe_adap[0].fe != NULL) {
1153786baecfSMauro Carvalho Chehab 		info("Attached tda10023!\n");
1154786baecfSMauro Carvalho Chehab 		return 0;
1155786baecfSMauro Carvalho Chehab 	}
1156786baecfSMauro Carvalho Chehab 	return -EIO;
1157786baecfSMauro Carvalho Chehab }
1158786baecfSMauro Carvalho Chehab 
1159786baecfSMauro Carvalho Chehab static int zl100313_frontend_attach(struct dvb_usb_adapter *d)
1160786baecfSMauro Carvalho Chehab {
1161786baecfSMauro Carvalho Chehab 	d->fe_adap[0].fe = dvb_attach(mt312_attach, &zl313_config,
1162786baecfSMauro Carvalho Chehab 			&d->dev->i2c_adap);
1163786baecfSMauro Carvalho Chehab 	if (d->fe_adap[0].fe != NULL) {
1164786baecfSMauro Carvalho Chehab 		if (dvb_attach(zl10039_attach, d->fe_adap[0].fe, 0x60,
1165786baecfSMauro Carvalho Chehab 				&d->dev->i2c_adap)) {
1166786baecfSMauro Carvalho Chehab 			d->fe_adap[0].fe->ops.set_voltage = dw210x_set_voltage;
1167786baecfSMauro Carvalho Chehab 			info("Attached zl100313+zl10039!\n");
1168786baecfSMauro Carvalho Chehab 			return 0;
1169786baecfSMauro Carvalho Chehab 		}
1170786baecfSMauro Carvalho Chehab 	}
1171786baecfSMauro Carvalho Chehab 
1172786baecfSMauro Carvalho Chehab 	return -EIO;
1173786baecfSMauro Carvalho Chehab }
1174786baecfSMauro Carvalho Chehab 
1175786baecfSMauro Carvalho Chehab static int stv0288_frontend_attach(struct dvb_usb_adapter *d)
1176786baecfSMauro Carvalho Chehab {
1177786baecfSMauro Carvalho Chehab 	u8 obuf[] = {7, 1};
1178786baecfSMauro Carvalho Chehab 
1179786baecfSMauro Carvalho Chehab 	d->fe_adap[0].fe = dvb_attach(stv0288_attach, &earda_config,
1180786baecfSMauro Carvalho Chehab 			&d->dev->i2c_adap);
1181786baecfSMauro Carvalho Chehab 
1182786baecfSMauro Carvalho Chehab 	if (d->fe_adap[0].fe == NULL)
1183786baecfSMauro Carvalho Chehab 		return -EIO;
1184786baecfSMauro Carvalho Chehab 
1185786baecfSMauro Carvalho Chehab 	if (NULL == dvb_attach(stb6000_attach, d->fe_adap[0].fe, 0x61, &d->dev->i2c_adap))
1186786baecfSMauro Carvalho Chehab 		return -EIO;
1187786baecfSMauro Carvalho Chehab 
1188786baecfSMauro Carvalho Chehab 	d->fe_adap[0].fe->ops.set_voltage = dw210x_set_voltage;
1189786baecfSMauro Carvalho Chehab 
1190786baecfSMauro Carvalho Chehab 	dw210x_op_rw(d->dev->udev, 0x8a, 0, 0, obuf, 2, DW210X_WRITE_MSG);
1191786baecfSMauro Carvalho Chehab 
1192786baecfSMauro Carvalho Chehab 	info("Attached stv0288+stb6000!\n");
1193786baecfSMauro Carvalho Chehab 
1194786baecfSMauro Carvalho Chehab 	return 0;
1195786baecfSMauro Carvalho Chehab 
1196786baecfSMauro Carvalho Chehab }
1197786baecfSMauro Carvalho Chehab 
1198786baecfSMauro Carvalho Chehab static int ds3000_frontend_attach(struct dvb_usb_adapter *d)
1199786baecfSMauro Carvalho Chehab {
1200786baecfSMauro Carvalho Chehab 	struct s6x0_state *st = (struct s6x0_state *)d->dev->priv;
1201786baecfSMauro Carvalho Chehab 	u8 obuf[] = {7, 1};
1202786baecfSMauro Carvalho Chehab 
1203786baecfSMauro Carvalho Chehab 	d->fe_adap[0].fe = dvb_attach(ds3000_attach, &dw2104_ds3000_config,
1204786baecfSMauro Carvalho Chehab 			&d->dev->i2c_adap);
1205786baecfSMauro Carvalho Chehab 
1206786baecfSMauro Carvalho Chehab 	if (d->fe_adap[0].fe == NULL)
1207786baecfSMauro Carvalho Chehab 		return -EIO;
1208786baecfSMauro Carvalho Chehab 
120973f0af44SKonstantin Dimitrov 	dvb_attach(ts2020_attach, d->fe_adap[0].fe, &dw2104_ts2020_config,
121073f0af44SKonstantin Dimitrov 		&d->dev->i2c_adap);
121173f0af44SKonstantin Dimitrov 
1212786baecfSMauro Carvalho Chehab 	st->old_set_voltage = d->fe_adap[0].fe->ops.set_voltage;
1213786baecfSMauro Carvalho Chehab 	d->fe_adap[0].fe->ops.set_voltage = s660_set_voltage;
1214786baecfSMauro Carvalho Chehab 
1215786baecfSMauro Carvalho Chehab 	dw210x_op_rw(d->dev->udev, 0x8a, 0, 0, obuf, 2, DW210X_WRITE_MSG);
1216786baecfSMauro Carvalho Chehab 
1217786baecfSMauro Carvalho Chehab 	info("Attached ds3000+ds2020!\n");
1218786baecfSMauro Carvalho Chehab 
1219786baecfSMauro Carvalho Chehab 	return 0;
1220786baecfSMauro Carvalho Chehab }
1221786baecfSMauro Carvalho Chehab 
1222786baecfSMauro Carvalho Chehab static int prof_7500_frontend_attach(struct dvb_usb_adapter *d)
1223786baecfSMauro Carvalho Chehab {
1224786baecfSMauro Carvalho Chehab 	u8 obuf[] = {7, 1};
1225786baecfSMauro Carvalho Chehab 
1226786baecfSMauro Carvalho Chehab 	d->fe_adap[0].fe = dvb_attach(stv0900_attach, &prof_7500_stv0900_config,
1227786baecfSMauro Carvalho Chehab 					&d->dev->i2c_adap, 0);
1228786baecfSMauro Carvalho Chehab 	if (d->fe_adap[0].fe == NULL)
1229786baecfSMauro Carvalho Chehab 		return -EIO;
1230786baecfSMauro Carvalho Chehab 
1231786baecfSMauro Carvalho Chehab 	d->fe_adap[0].fe->ops.set_voltage = dw210x_set_voltage;
1232786baecfSMauro Carvalho Chehab 
1233786baecfSMauro Carvalho Chehab 	dw210x_op_rw(d->dev->udev, 0x8a, 0, 0, obuf, 2, DW210X_WRITE_MSG);
1234786baecfSMauro Carvalho Chehab 
1235786baecfSMauro Carvalho Chehab 	info("Attached STV0900+STB6100A!\n");
1236786baecfSMauro Carvalho Chehab 
1237786baecfSMauro Carvalho Chehab 	return 0;
1238786baecfSMauro Carvalho Chehab }
1239786baecfSMauro Carvalho Chehab 
1240786baecfSMauro Carvalho Chehab static int su3000_frontend_attach(struct dvb_usb_adapter *d)
1241786baecfSMauro Carvalho Chehab {
1242786baecfSMauro Carvalho Chehab 	u8 obuf[3] = { 0xe, 0x80, 0 };
1243786baecfSMauro Carvalho Chehab 	u8 ibuf[] = { 0 };
1244786baecfSMauro Carvalho Chehab 
1245786baecfSMauro Carvalho Chehab 	if (dvb_usb_generic_rw(d->dev, obuf, 3, ibuf, 1, 0) < 0)
1246786baecfSMauro Carvalho Chehab 		err("command 0x0e transfer failed.");
1247786baecfSMauro Carvalho Chehab 
1248786baecfSMauro Carvalho Chehab 	obuf[0] = 0xe;
1249786baecfSMauro Carvalho Chehab 	obuf[1] = 0x83;
1250786baecfSMauro Carvalho Chehab 	obuf[2] = 0;
1251786baecfSMauro Carvalho Chehab 
1252786baecfSMauro Carvalho Chehab 	if (dvb_usb_generic_rw(d->dev, obuf, 3, ibuf, 1, 0) < 0)
1253786baecfSMauro Carvalho Chehab 		err("command 0x0e transfer failed.");
1254786baecfSMauro Carvalho Chehab 
1255786baecfSMauro Carvalho Chehab 	obuf[0] = 0xe;
1256786baecfSMauro Carvalho Chehab 	obuf[1] = 0x83;
1257786baecfSMauro Carvalho Chehab 	obuf[2] = 1;
1258786baecfSMauro Carvalho Chehab 
1259786baecfSMauro Carvalho Chehab 	if (dvb_usb_generic_rw(d->dev, obuf, 3, ibuf, 1, 0) < 0)
1260786baecfSMauro Carvalho Chehab 		err("command 0x0e transfer failed.");
1261786baecfSMauro Carvalho Chehab 
1262786baecfSMauro Carvalho Chehab 	obuf[0] = 0x51;
1263786baecfSMauro Carvalho Chehab 
1264786baecfSMauro Carvalho Chehab 	if (dvb_usb_generic_rw(d->dev, obuf, 1, ibuf, 1, 0) < 0)
1265786baecfSMauro Carvalho Chehab 		err("command 0x51 transfer failed.");
1266786baecfSMauro Carvalho Chehab 
1267786baecfSMauro Carvalho Chehab 	d->fe_adap[0].fe = dvb_attach(ds3000_attach, &su3000_ds3000_config,
1268786baecfSMauro Carvalho Chehab 					&d->dev->i2c_adap);
1269786baecfSMauro Carvalho Chehab 	if (d->fe_adap[0].fe == NULL)
1270786baecfSMauro Carvalho Chehab 		return -EIO;
1271786baecfSMauro Carvalho Chehab 
127273f0af44SKonstantin Dimitrov 	dvb_attach(ts2020_attach, d->fe_adap[0].fe, &su3000_ts2020_config,
127373f0af44SKonstantin Dimitrov 		&d->dev->i2c_adap);
127473f0af44SKonstantin Dimitrov 
1275786baecfSMauro Carvalho Chehab 	info("Attached DS3000!\n");
1276786baecfSMauro Carvalho Chehab 
1277786baecfSMauro Carvalho Chehab 	return 0;
1278786baecfSMauro Carvalho Chehab }
1279786baecfSMauro Carvalho Chehab 
1280*955d00acSIgor M. Liplianin static int m88rs2000_frontend_attach(struct dvb_usb_adapter *d)
1281*955d00acSIgor M. Liplianin {
1282*955d00acSIgor M. Liplianin 	u8 obuf[] = { 0x51 };
1283*955d00acSIgor M. Liplianin 	u8 ibuf[] = { 0 };
1284*955d00acSIgor M. Liplianin 
1285*955d00acSIgor M. Liplianin 	if (dvb_usb_generic_rw(d->dev, obuf, 1, ibuf, 1, 0) < 0)
1286*955d00acSIgor M. Liplianin 		err("command 0x51 transfer failed.");
1287*955d00acSIgor M. Liplianin 
1288*955d00acSIgor M. Liplianin 	d->fe_adap[0].fe = dvb_attach(m88rs2000_attach, &s421_m88rs2000_config,
1289*955d00acSIgor M. Liplianin 					&d->dev->i2c_adap);
1290*955d00acSIgor M. Liplianin 	if (d->fe_adap[0].fe == NULL)
1291*955d00acSIgor M. Liplianin 		return -EIO;
1292*955d00acSIgor M. Liplianin 
1293*955d00acSIgor M. Liplianin 	info("Attached m88rs2000!\n");
1294*955d00acSIgor M. Liplianin 
1295*955d00acSIgor M. Liplianin 	return 0;
1296*955d00acSIgor M. Liplianin }
1297*955d00acSIgor M. Liplianin 
1298786baecfSMauro Carvalho Chehab static int dw2102_tuner_attach(struct dvb_usb_adapter *adap)
1299786baecfSMauro Carvalho Chehab {
1300786baecfSMauro Carvalho Chehab 	dvb_attach(dvb_pll_attach, adap->fe_adap[0].fe, 0x60,
1301786baecfSMauro Carvalho Chehab 		&adap->dev->i2c_adap, DVB_PLL_OPERA1);
1302786baecfSMauro Carvalho Chehab 	return 0;
1303786baecfSMauro Carvalho Chehab }
1304786baecfSMauro Carvalho Chehab 
1305786baecfSMauro Carvalho Chehab static int dw3101_tuner_attach(struct dvb_usb_adapter *adap)
1306786baecfSMauro Carvalho Chehab {
1307786baecfSMauro Carvalho Chehab 	dvb_attach(dvb_pll_attach, adap->fe_adap[0].fe, 0x60,
1308786baecfSMauro Carvalho Chehab 		&adap->dev->i2c_adap, DVB_PLL_TUA6034);
1309786baecfSMauro Carvalho Chehab 
1310786baecfSMauro Carvalho Chehab 	return 0;
1311786baecfSMauro Carvalho Chehab }
1312786baecfSMauro Carvalho Chehab 
1313786baecfSMauro Carvalho Chehab static struct rc_map_table rc_map_dw210x_table[] = {
1314786baecfSMauro Carvalho Chehab 	{ 0xf80a, KEY_POWER2 },		/*power*/
1315786baecfSMauro Carvalho Chehab 	{ 0xf80c, KEY_MUTE },		/*mute*/
1316786baecfSMauro Carvalho Chehab 	{ 0xf811, KEY_1 },
1317786baecfSMauro Carvalho Chehab 	{ 0xf812, KEY_2 },
1318786baecfSMauro Carvalho Chehab 	{ 0xf813, KEY_3 },
1319786baecfSMauro Carvalho Chehab 	{ 0xf814, KEY_4 },
1320786baecfSMauro Carvalho Chehab 	{ 0xf815, KEY_5 },
1321786baecfSMauro Carvalho Chehab 	{ 0xf816, KEY_6 },
1322786baecfSMauro Carvalho Chehab 	{ 0xf817, KEY_7 },
1323786baecfSMauro Carvalho Chehab 	{ 0xf818, KEY_8 },
1324786baecfSMauro Carvalho Chehab 	{ 0xf819, KEY_9 },
1325786baecfSMauro Carvalho Chehab 	{ 0xf810, KEY_0 },
1326786baecfSMauro Carvalho Chehab 	{ 0xf81c, KEY_CHANNELUP },	/*ch+*/
1327786baecfSMauro Carvalho Chehab 	{ 0xf80f, KEY_CHANNELDOWN },	/*ch-*/
1328786baecfSMauro Carvalho Chehab 	{ 0xf81a, KEY_VOLUMEUP },	/*vol+*/
1329786baecfSMauro Carvalho Chehab 	{ 0xf80e, KEY_VOLUMEDOWN },	/*vol-*/
1330786baecfSMauro Carvalho Chehab 	{ 0xf804, KEY_RECORD },		/*rec*/
1331786baecfSMauro Carvalho Chehab 	{ 0xf809, KEY_FAVORITES },	/*fav*/
1332786baecfSMauro Carvalho Chehab 	{ 0xf808, KEY_REWIND },		/*rewind*/
1333786baecfSMauro Carvalho Chehab 	{ 0xf807, KEY_FASTFORWARD },	/*fast*/
1334786baecfSMauro Carvalho Chehab 	{ 0xf80b, KEY_PAUSE },		/*pause*/
1335786baecfSMauro Carvalho Chehab 	{ 0xf802, KEY_ESC },		/*cancel*/
1336786baecfSMauro Carvalho Chehab 	{ 0xf803, KEY_TAB },		/*tab*/
1337786baecfSMauro Carvalho Chehab 	{ 0xf800, KEY_UP },		/*up*/
1338786baecfSMauro Carvalho Chehab 	{ 0xf81f, KEY_OK },		/*ok*/
1339786baecfSMauro Carvalho Chehab 	{ 0xf801, KEY_DOWN },		/*down*/
1340786baecfSMauro Carvalho Chehab 	{ 0xf805, KEY_CAMERA },		/*cap*/
1341786baecfSMauro Carvalho Chehab 	{ 0xf806, KEY_STOP },		/*stop*/
1342786baecfSMauro Carvalho Chehab 	{ 0xf840, KEY_ZOOM },		/*full*/
1343786baecfSMauro Carvalho Chehab 	{ 0xf81e, KEY_TV },		/*tvmode*/
1344786baecfSMauro Carvalho Chehab 	{ 0xf81b, KEY_LAST },		/*recall*/
1345786baecfSMauro Carvalho Chehab };
1346786baecfSMauro Carvalho Chehab 
1347786baecfSMauro Carvalho Chehab static struct rc_map_table rc_map_tevii_table[] = {
1348786baecfSMauro Carvalho Chehab 	{ 0xf80a, KEY_POWER },
1349786baecfSMauro Carvalho Chehab 	{ 0xf80c, KEY_MUTE },
1350786baecfSMauro Carvalho Chehab 	{ 0xf811, KEY_1 },
1351786baecfSMauro Carvalho Chehab 	{ 0xf812, KEY_2 },
1352786baecfSMauro Carvalho Chehab 	{ 0xf813, KEY_3 },
1353786baecfSMauro Carvalho Chehab 	{ 0xf814, KEY_4 },
1354786baecfSMauro Carvalho Chehab 	{ 0xf815, KEY_5 },
1355786baecfSMauro Carvalho Chehab 	{ 0xf816, KEY_6 },
1356786baecfSMauro Carvalho Chehab 	{ 0xf817, KEY_7 },
1357786baecfSMauro Carvalho Chehab 	{ 0xf818, KEY_8 },
1358786baecfSMauro Carvalho Chehab 	{ 0xf819, KEY_9 },
1359786baecfSMauro Carvalho Chehab 	{ 0xf810, KEY_0 },
1360786baecfSMauro Carvalho Chehab 	{ 0xf81c, KEY_MENU },
1361786baecfSMauro Carvalho Chehab 	{ 0xf80f, KEY_VOLUMEDOWN },
1362786baecfSMauro Carvalho Chehab 	{ 0xf81a, KEY_LAST },
1363786baecfSMauro Carvalho Chehab 	{ 0xf80e, KEY_OPEN },
1364786baecfSMauro Carvalho Chehab 	{ 0xf804, KEY_RECORD },
1365786baecfSMauro Carvalho Chehab 	{ 0xf809, KEY_VOLUMEUP },
1366786baecfSMauro Carvalho Chehab 	{ 0xf808, KEY_CHANNELUP },
1367786baecfSMauro Carvalho Chehab 	{ 0xf807, KEY_PVR },
1368786baecfSMauro Carvalho Chehab 	{ 0xf80b, KEY_TIME },
1369786baecfSMauro Carvalho Chehab 	{ 0xf802, KEY_RIGHT },
1370786baecfSMauro Carvalho Chehab 	{ 0xf803, KEY_LEFT },
1371786baecfSMauro Carvalho Chehab 	{ 0xf800, KEY_UP },
1372786baecfSMauro Carvalho Chehab 	{ 0xf81f, KEY_OK },
1373786baecfSMauro Carvalho Chehab 	{ 0xf801, KEY_DOWN },
1374786baecfSMauro Carvalho Chehab 	{ 0xf805, KEY_TUNER },
1375786baecfSMauro Carvalho Chehab 	{ 0xf806, KEY_CHANNELDOWN },
1376786baecfSMauro Carvalho Chehab 	{ 0xf840, KEY_PLAYPAUSE },
1377786baecfSMauro Carvalho Chehab 	{ 0xf81e, KEY_REWIND },
1378786baecfSMauro Carvalho Chehab 	{ 0xf81b, KEY_FAVORITES },
1379786baecfSMauro Carvalho Chehab 	{ 0xf81d, KEY_BACK },
1380786baecfSMauro Carvalho Chehab 	{ 0xf84d, KEY_FASTFORWARD },
1381786baecfSMauro Carvalho Chehab 	{ 0xf844, KEY_EPG },
1382786baecfSMauro Carvalho Chehab 	{ 0xf84c, KEY_INFO },
1383786baecfSMauro Carvalho Chehab 	{ 0xf841, KEY_AB },
1384786baecfSMauro Carvalho Chehab 	{ 0xf843, KEY_AUDIO },
1385786baecfSMauro Carvalho Chehab 	{ 0xf845, KEY_SUBTITLE },
1386786baecfSMauro Carvalho Chehab 	{ 0xf84a, KEY_LIST },
1387786baecfSMauro Carvalho Chehab 	{ 0xf846, KEY_F1 },
1388786baecfSMauro Carvalho Chehab 	{ 0xf847, KEY_F2 },
1389786baecfSMauro Carvalho Chehab 	{ 0xf85e, KEY_F3 },
1390786baecfSMauro Carvalho Chehab 	{ 0xf85c, KEY_F4 },
1391786baecfSMauro Carvalho Chehab 	{ 0xf852, KEY_F5 },
1392786baecfSMauro Carvalho Chehab 	{ 0xf85a, KEY_F6 },
1393786baecfSMauro Carvalho Chehab 	{ 0xf856, KEY_MODE },
1394786baecfSMauro Carvalho Chehab 	{ 0xf858, KEY_SWITCHVIDEOMODE },
1395786baecfSMauro Carvalho Chehab };
1396786baecfSMauro Carvalho Chehab 
1397786baecfSMauro Carvalho Chehab static struct rc_map_table rc_map_tbs_table[] = {
1398786baecfSMauro Carvalho Chehab 	{ 0xf884, KEY_POWER },
1399786baecfSMauro Carvalho Chehab 	{ 0xf894, KEY_MUTE },
1400786baecfSMauro Carvalho Chehab 	{ 0xf887, KEY_1 },
1401786baecfSMauro Carvalho Chehab 	{ 0xf886, KEY_2 },
1402786baecfSMauro Carvalho Chehab 	{ 0xf885, KEY_3 },
1403786baecfSMauro Carvalho Chehab 	{ 0xf88b, KEY_4 },
1404786baecfSMauro Carvalho Chehab 	{ 0xf88a, KEY_5 },
1405786baecfSMauro Carvalho Chehab 	{ 0xf889, KEY_6 },
1406786baecfSMauro Carvalho Chehab 	{ 0xf88f, KEY_7 },
1407786baecfSMauro Carvalho Chehab 	{ 0xf88e, KEY_8 },
1408786baecfSMauro Carvalho Chehab 	{ 0xf88d, KEY_9 },
1409786baecfSMauro Carvalho Chehab 	{ 0xf892, KEY_0 },
1410786baecfSMauro Carvalho Chehab 	{ 0xf896, KEY_CHANNELUP },
1411786baecfSMauro Carvalho Chehab 	{ 0xf891, KEY_CHANNELDOWN },
1412786baecfSMauro Carvalho Chehab 	{ 0xf893, KEY_VOLUMEUP },
1413786baecfSMauro Carvalho Chehab 	{ 0xf88c, KEY_VOLUMEDOWN },
1414786baecfSMauro Carvalho Chehab 	{ 0xf883, KEY_RECORD },
1415786baecfSMauro Carvalho Chehab 	{ 0xf898, KEY_PAUSE  },
1416786baecfSMauro Carvalho Chehab 	{ 0xf899, KEY_OK },
1417786baecfSMauro Carvalho Chehab 	{ 0xf89a, KEY_SHUFFLE },
1418786baecfSMauro Carvalho Chehab 	{ 0xf881, KEY_UP },
1419786baecfSMauro Carvalho Chehab 	{ 0xf890, KEY_LEFT },
1420786baecfSMauro Carvalho Chehab 	{ 0xf882, KEY_RIGHT },
1421786baecfSMauro Carvalho Chehab 	{ 0xf888, KEY_DOWN },
1422786baecfSMauro Carvalho Chehab 	{ 0xf895, KEY_FAVORITES },
1423786baecfSMauro Carvalho Chehab 	{ 0xf897, KEY_SUBTITLE },
1424786baecfSMauro Carvalho Chehab 	{ 0xf89d, KEY_ZOOM },
1425786baecfSMauro Carvalho Chehab 	{ 0xf89f, KEY_EXIT },
1426786baecfSMauro Carvalho Chehab 	{ 0xf89e, KEY_MENU },
1427786baecfSMauro Carvalho Chehab 	{ 0xf89c, KEY_EPG },
1428786baecfSMauro Carvalho Chehab 	{ 0xf880, KEY_PREVIOUS },
1429786baecfSMauro Carvalho Chehab 	{ 0xf89b, KEY_MODE }
1430786baecfSMauro Carvalho Chehab };
1431786baecfSMauro Carvalho Chehab 
1432786baecfSMauro Carvalho Chehab static struct rc_map_table rc_map_su3000_table[] = {
1433786baecfSMauro Carvalho Chehab 	{ 0x25, KEY_POWER },	/* right-bottom Red */
1434786baecfSMauro Carvalho Chehab 	{ 0x0a, KEY_MUTE },	/* -/-- */
1435786baecfSMauro Carvalho Chehab 	{ 0x01, KEY_1 },
1436786baecfSMauro Carvalho Chehab 	{ 0x02, KEY_2 },
1437786baecfSMauro Carvalho Chehab 	{ 0x03, KEY_3 },
1438786baecfSMauro Carvalho Chehab 	{ 0x04, KEY_4 },
1439786baecfSMauro Carvalho Chehab 	{ 0x05, KEY_5 },
1440786baecfSMauro Carvalho Chehab 	{ 0x06, KEY_6 },
1441786baecfSMauro Carvalho Chehab 	{ 0x07, KEY_7 },
1442786baecfSMauro Carvalho Chehab 	{ 0x08, KEY_8 },
1443786baecfSMauro Carvalho Chehab 	{ 0x09, KEY_9 },
1444786baecfSMauro Carvalho Chehab 	{ 0x00, KEY_0 },
1445786baecfSMauro Carvalho Chehab 	{ 0x20, KEY_UP },	/* CH+ */
1446786baecfSMauro Carvalho Chehab 	{ 0x21, KEY_DOWN },	/* CH+ */
1447786baecfSMauro Carvalho Chehab 	{ 0x12, KEY_VOLUMEUP },	/* Brightness Up */
1448786baecfSMauro Carvalho Chehab 	{ 0x13, KEY_VOLUMEDOWN },/* Brightness Down */
1449786baecfSMauro Carvalho Chehab 	{ 0x1f, KEY_RECORD },
1450786baecfSMauro Carvalho Chehab 	{ 0x17, KEY_PLAY },
1451786baecfSMauro Carvalho Chehab 	{ 0x16, KEY_PAUSE },
1452786baecfSMauro Carvalho Chehab 	{ 0x0b, KEY_STOP },
1453786baecfSMauro Carvalho Chehab 	{ 0x27, KEY_FASTFORWARD },/* >> */
1454786baecfSMauro Carvalho Chehab 	{ 0x26, KEY_REWIND },	/* << */
1455786baecfSMauro Carvalho Chehab 	{ 0x0d, KEY_OK },	/* Mute */
1456786baecfSMauro Carvalho Chehab 	{ 0x11, KEY_LEFT },	/* VOL- */
1457786baecfSMauro Carvalho Chehab 	{ 0x10, KEY_RIGHT },	/* VOL+ */
1458786baecfSMauro Carvalho Chehab 	{ 0x29, KEY_BACK },	/* button under 9 */
1459786baecfSMauro Carvalho Chehab 	{ 0x2c, KEY_MENU },	/* TTX */
1460786baecfSMauro Carvalho Chehab 	{ 0x2b, KEY_EPG },	/* EPG */
1461786baecfSMauro Carvalho Chehab 	{ 0x1e, KEY_RED },	/* OSD */
1462786baecfSMauro Carvalho Chehab 	{ 0x0e, KEY_GREEN },	/* Window */
1463786baecfSMauro Carvalho Chehab 	{ 0x2d, KEY_YELLOW },	/* button under << */
1464786baecfSMauro Carvalho Chehab 	{ 0x0f, KEY_BLUE },	/* bottom yellow button */
1465786baecfSMauro Carvalho Chehab 	{ 0x14, KEY_AUDIO },	/* Snapshot */
1466786baecfSMauro Carvalho Chehab 	{ 0x38, KEY_TV },	/* TV/Radio */
1467786baecfSMauro Carvalho Chehab 	{ 0x0c, KEY_ESC }	/* upper Red button */
1468786baecfSMauro Carvalho Chehab };
1469786baecfSMauro Carvalho Chehab 
1470786baecfSMauro Carvalho Chehab static struct rc_map_dvb_usb_table_table keys_tables[] = {
1471786baecfSMauro Carvalho Chehab 	{ rc_map_dw210x_table, ARRAY_SIZE(rc_map_dw210x_table) },
1472786baecfSMauro Carvalho Chehab 	{ rc_map_tevii_table, ARRAY_SIZE(rc_map_tevii_table) },
1473786baecfSMauro Carvalho Chehab 	{ rc_map_tbs_table, ARRAY_SIZE(rc_map_tbs_table) },
1474786baecfSMauro Carvalho Chehab 	{ rc_map_su3000_table, ARRAY_SIZE(rc_map_su3000_table) },
1475786baecfSMauro Carvalho Chehab };
1476786baecfSMauro Carvalho Chehab 
1477786baecfSMauro Carvalho Chehab static int dw2102_rc_query(struct dvb_usb_device *d, u32 *event, int *state)
1478786baecfSMauro Carvalho Chehab {
1479786baecfSMauro Carvalho Chehab 	struct rc_map_table *keymap = d->props.rc.legacy.rc_map_table;
1480786baecfSMauro Carvalho Chehab 	int keymap_size = d->props.rc.legacy.rc_map_size;
1481786baecfSMauro Carvalho Chehab 	u8 key[2];
1482786baecfSMauro Carvalho Chehab 	struct i2c_msg msg = {
1483786baecfSMauro Carvalho Chehab 		.addr = DW2102_RC_QUERY,
1484786baecfSMauro Carvalho Chehab 		.flags = I2C_M_RD,
1485786baecfSMauro Carvalho Chehab 		.buf = key,
1486786baecfSMauro Carvalho Chehab 		.len = 2
1487786baecfSMauro Carvalho Chehab 	};
1488786baecfSMauro Carvalho Chehab 	int i;
1489786baecfSMauro Carvalho Chehab 	/* override keymap */
1490786baecfSMauro Carvalho Chehab 	if ((ir_keymap > 0) && (ir_keymap <= ARRAY_SIZE(keys_tables))) {
1491786baecfSMauro Carvalho Chehab 		keymap = keys_tables[ir_keymap - 1].rc_keys ;
1492786baecfSMauro Carvalho Chehab 		keymap_size = keys_tables[ir_keymap - 1].rc_keys_size;
1493786baecfSMauro Carvalho Chehab 	} else if (ir_keymap > ARRAY_SIZE(keys_tables))
1494786baecfSMauro Carvalho Chehab 		return 0; /* none */
1495786baecfSMauro Carvalho Chehab 
1496786baecfSMauro Carvalho Chehab 	*state = REMOTE_NO_KEY_PRESSED;
1497786baecfSMauro Carvalho Chehab 	if (d->props.i2c_algo->master_xfer(&d->i2c_adap, &msg, 1) == 1) {
1498786baecfSMauro Carvalho Chehab 		for (i = 0; i < keymap_size ; i++) {
1499786baecfSMauro Carvalho Chehab 			if (rc5_data(&keymap[i]) == msg.buf[0]) {
1500786baecfSMauro Carvalho Chehab 				*state = REMOTE_KEY_PRESSED;
1501786baecfSMauro Carvalho Chehab 				*event = keymap[i].keycode;
1502786baecfSMauro Carvalho Chehab 				break;
1503786baecfSMauro Carvalho Chehab 			}
1504786baecfSMauro Carvalho Chehab 
1505786baecfSMauro Carvalho Chehab 		}
1506786baecfSMauro Carvalho Chehab 
1507786baecfSMauro Carvalho Chehab 		if ((*state) == REMOTE_KEY_PRESSED)
1508786baecfSMauro Carvalho Chehab 			deb_rc("%s: found rc key: %x, %x, event: %x\n",
1509786baecfSMauro Carvalho Chehab 					__func__, key[0], key[1], (*event));
1510786baecfSMauro Carvalho Chehab 		else if (key[0] != 0xff)
1511786baecfSMauro Carvalho Chehab 			deb_rc("%s: unknown rc key: %x, %x\n",
1512786baecfSMauro Carvalho Chehab 					__func__, key[0], key[1]);
1513786baecfSMauro Carvalho Chehab 
1514786baecfSMauro Carvalho Chehab 	}
1515786baecfSMauro Carvalho Chehab 
1516786baecfSMauro Carvalho Chehab 	return 0;
1517786baecfSMauro Carvalho Chehab }
1518786baecfSMauro Carvalho Chehab 
1519786baecfSMauro Carvalho Chehab enum dw2102_table_entry {
1520786baecfSMauro Carvalho Chehab 	CYPRESS_DW2102,
1521786baecfSMauro Carvalho Chehab 	CYPRESS_DW2101,
1522786baecfSMauro Carvalho Chehab 	CYPRESS_DW2104,
1523786baecfSMauro Carvalho Chehab 	TEVII_S650,
1524786baecfSMauro Carvalho Chehab 	TERRATEC_CINERGY_S,
1525786baecfSMauro Carvalho Chehab 	CYPRESS_DW3101,
1526786baecfSMauro Carvalho Chehab 	TEVII_S630,
1527786baecfSMauro Carvalho Chehab 	PROF_1100,
1528786baecfSMauro Carvalho Chehab 	TEVII_S660,
1529786baecfSMauro Carvalho Chehab 	PROF_7500,
1530786baecfSMauro Carvalho Chehab 	GENIATECH_SU3000,
1531786baecfSMauro Carvalho Chehab 	TERRATEC_CINERGY_S2,
1532786baecfSMauro Carvalho Chehab 	TEVII_S480_1,
1533786baecfSMauro Carvalho Chehab 	TEVII_S480_2,
1534786baecfSMauro Carvalho Chehab 	X3M_SPC1400HD,
1535*955d00acSIgor M. Liplianin 	TEVII_S421,
1536*955d00acSIgor M. Liplianin 	TEVII_S632,
1537786baecfSMauro Carvalho Chehab };
1538786baecfSMauro Carvalho Chehab 
1539786baecfSMauro Carvalho Chehab static struct usb_device_id dw2102_table[] = {
1540786baecfSMauro Carvalho Chehab 	[CYPRESS_DW2102] = {USB_DEVICE(USB_VID_CYPRESS, USB_PID_DW2102)},
1541786baecfSMauro Carvalho Chehab 	[CYPRESS_DW2101] = {USB_DEVICE(USB_VID_CYPRESS, 0x2101)},
1542786baecfSMauro Carvalho Chehab 	[CYPRESS_DW2104] = {USB_DEVICE(USB_VID_CYPRESS, USB_PID_DW2104)},
1543786baecfSMauro Carvalho Chehab 	[TEVII_S650] = {USB_DEVICE(0x9022, USB_PID_TEVII_S650)},
1544786baecfSMauro Carvalho Chehab 	[TERRATEC_CINERGY_S] = {USB_DEVICE(USB_VID_TERRATEC, USB_PID_CINERGY_S)},
1545786baecfSMauro Carvalho Chehab 	[CYPRESS_DW3101] = {USB_DEVICE(USB_VID_CYPRESS, USB_PID_DW3101)},
1546786baecfSMauro Carvalho Chehab 	[TEVII_S630] = {USB_DEVICE(0x9022, USB_PID_TEVII_S630)},
1547786baecfSMauro Carvalho Chehab 	[PROF_1100] = {USB_DEVICE(0x3011, USB_PID_PROF_1100)},
1548786baecfSMauro Carvalho Chehab 	[TEVII_S660] = {USB_DEVICE(0x9022, USB_PID_TEVII_S660)},
1549786baecfSMauro Carvalho Chehab 	[PROF_7500] = {USB_DEVICE(0x3034, 0x7500)},
1550786baecfSMauro Carvalho Chehab 	[GENIATECH_SU3000] = {USB_DEVICE(0x1f4d, 0x3000)},
1551786baecfSMauro Carvalho Chehab 	[TERRATEC_CINERGY_S2] = {USB_DEVICE(USB_VID_TERRATEC, 0x00a8)},
1552786baecfSMauro Carvalho Chehab 	[TEVII_S480_1] = {USB_DEVICE(0x9022, USB_PID_TEVII_S480_1)},
1553786baecfSMauro Carvalho Chehab 	[TEVII_S480_2] = {USB_DEVICE(0x9022, USB_PID_TEVII_S480_2)},
1554786baecfSMauro Carvalho Chehab 	[X3M_SPC1400HD] = {USB_DEVICE(0x1f4d, 0x3100)},
1555*955d00acSIgor M. Liplianin 	[TEVII_S421] = {USB_DEVICE(0x9022, USB_PID_TEVII_S421)},
1556*955d00acSIgor M. Liplianin 	[TEVII_S632] = {USB_DEVICE(0x9022, USB_PID_TEVII_S632)},
1557786baecfSMauro Carvalho Chehab 	{ }
1558786baecfSMauro Carvalho Chehab };
1559786baecfSMauro Carvalho Chehab 
1560786baecfSMauro Carvalho Chehab MODULE_DEVICE_TABLE(usb, dw2102_table);
1561786baecfSMauro Carvalho Chehab 
1562786baecfSMauro Carvalho Chehab static int dw2102_load_firmware(struct usb_device *dev,
1563786baecfSMauro Carvalho Chehab 			const struct firmware *frmwr)
1564786baecfSMauro Carvalho Chehab {
1565786baecfSMauro Carvalho Chehab 	u8 *b, *p;
1566786baecfSMauro Carvalho Chehab 	int ret = 0, i;
1567786baecfSMauro Carvalho Chehab 	u8 reset;
1568786baecfSMauro Carvalho Chehab 	u8 reset16[] = {0, 0, 0, 0, 0, 0, 0};
1569786baecfSMauro Carvalho Chehab 	const struct firmware *fw;
1570786baecfSMauro Carvalho Chehab 
1571786baecfSMauro Carvalho Chehab 	switch (dev->descriptor.idProduct) {
1572786baecfSMauro Carvalho Chehab 	case 0x2101:
15736823627bSRémi Cardona 		ret = request_firmware(&fw, DW2101_FIRMWARE, &dev->dev);
1574786baecfSMauro Carvalho Chehab 		if (ret != 0) {
15756823627bSRémi Cardona 			err(err_str, DW2101_FIRMWARE);
1576786baecfSMauro Carvalho Chehab 			return ret;
1577786baecfSMauro Carvalho Chehab 		}
1578786baecfSMauro Carvalho Chehab 		break;
1579786baecfSMauro Carvalho Chehab 	default:
1580786baecfSMauro Carvalho Chehab 		fw = frmwr;
1581786baecfSMauro Carvalho Chehab 		break;
1582786baecfSMauro Carvalho Chehab 	}
1583786baecfSMauro Carvalho Chehab 	info("start downloading DW210X firmware");
1584786baecfSMauro Carvalho Chehab 	p = kmalloc(fw->size, GFP_KERNEL);
1585786baecfSMauro Carvalho Chehab 	reset = 1;
1586786baecfSMauro Carvalho Chehab 	/*stop the CPU*/
1587786baecfSMauro Carvalho Chehab 	dw210x_op_rw(dev, 0xa0, 0x7f92, 0, &reset, 1, DW210X_WRITE_MSG);
1588786baecfSMauro Carvalho Chehab 	dw210x_op_rw(dev, 0xa0, 0xe600, 0, &reset, 1, DW210X_WRITE_MSG);
1589786baecfSMauro Carvalho Chehab 
1590786baecfSMauro Carvalho Chehab 	if (p != NULL) {
1591786baecfSMauro Carvalho Chehab 		memcpy(p, fw->data, fw->size);
1592786baecfSMauro Carvalho Chehab 		for (i = 0; i < fw->size; i += 0x40) {
1593786baecfSMauro Carvalho Chehab 			b = (u8 *) p + i;
1594786baecfSMauro Carvalho Chehab 			if (dw210x_op_rw(dev, 0xa0, i, 0, b , 0x40,
1595786baecfSMauro Carvalho Chehab 					DW210X_WRITE_MSG) != 0x40) {
1596786baecfSMauro Carvalho Chehab 				err("error while transferring firmware");
1597786baecfSMauro Carvalho Chehab 				ret = -EINVAL;
1598786baecfSMauro Carvalho Chehab 				break;
1599786baecfSMauro Carvalho Chehab 			}
1600786baecfSMauro Carvalho Chehab 		}
1601786baecfSMauro Carvalho Chehab 		/* restart the CPU */
1602786baecfSMauro Carvalho Chehab 		reset = 0;
1603786baecfSMauro Carvalho Chehab 		if (ret || dw210x_op_rw(dev, 0xa0, 0x7f92, 0, &reset, 1,
1604786baecfSMauro Carvalho Chehab 					DW210X_WRITE_MSG) != 1) {
1605786baecfSMauro Carvalho Chehab 			err("could not restart the USB controller CPU.");
1606786baecfSMauro Carvalho Chehab 			ret = -EINVAL;
1607786baecfSMauro Carvalho Chehab 		}
1608786baecfSMauro Carvalho Chehab 		if (ret || dw210x_op_rw(dev, 0xa0, 0xe600, 0, &reset, 1,
1609786baecfSMauro Carvalho Chehab 					DW210X_WRITE_MSG) != 1) {
1610786baecfSMauro Carvalho Chehab 			err("could not restart the USB controller CPU.");
1611786baecfSMauro Carvalho Chehab 			ret = -EINVAL;
1612786baecfSMauro Carvalho Chehab 		}
1613786baecfSMauro Carvalho Chehab 		/* init registers */
1614786baecfSMauro Carvalho Chehab 		switch (dev->descriptor.idProduct) {
1615786baecfSMauro Carvalho Chehab 		case USB_PID_TEVII_S650:
1616786baecfSMauro Carvalho Chehab 			dw2104_properties.rc.legacy.rc_map_table = rc_map_tevii_table;
1617786baecfSMauro Carvalho Chehab 			dw2104_properties.rc.legacy.rc_map_size =
1618786baecfSMauro Carvalho Chehab 					ARRAY_SIZE(rc_map_tevii_table);
1619786baecfSMauro Carvalho Chehab 		case USB_PID_DW2104:
1620786baecfSMauro Carvalho Chehab 			reset = 1;
1621786baecfSMauro Carvalho Chehab 			dw210x_op_rw(dev, 0xc4, 0x0000, 0, &reset, 1,
1622786baecfSMauro Carvalho Chehab 					DW210X_WRITE_MSG);
1623786baecfSMauro Carvalho Chehab 			/* break omitted intentionally */
1624786baecfSMauro Carvalho Chehab 		case USB_PID_DW3101:
1625786baecfSMauro Carvalho Chehab 			reset = 0;
1626786baecfSMauro Carvalho Chehab 			dw210x_op_rw(dev, 0xbf, 0x0040, 0, &reset, 0,
1627786baecfSMauro Carvalho Chehab 					DW210X_WRITE_MSG);
1628786baecfSMauro Carvalho Chehab 			break;
1629786baecfSMauro Carvalho Chehab 		case USB_PID_CINERGY_S:
1630786baecfSMauro Carvalho Chehab 		case USB_PID_DW2102:
1631786baecfSMauro Carvalho Chehab 			dw210x_op_rw(dev, 0xbf, 0x0040, 0, &reset, 0,
1632786baecfSMauro Carvalho Chehab 					DW210X_WRITE_MSG);
1633786baecfSMauro Carvalho Chehab 			dw210x_op_rw(dev, 0xb9, 0x0000, 0, &reset16[0], 2,
1634786baecfSMauro Carvalho Chehab 					DW210X_READ_MSG);
1635786baecfSMauro Carvalho Chehab 			/* check STV0299 frontend  */
1636786baecfSMauro Carvalho Chehab 			dw210x_op_rw(dev, 0xb5, 0, 0, &reset16[0], 2,
1637786baecfSMauro Carvalho Chehab 					DW210X_READ_MSG);
1638786baecfSMauro Carvalho Chehab 			if ((reset16[0] == 0xa1) || (reset16[0] == 0x80)) {
1639786baecfSMauro Carvalho Chehab 				dw2102_properties.i2c_algo = &dw2102_i2c_algo;
1640786baecfSMauro Carvalho Chehab 				dw2102_properties.adapter->fe[0].tuner_attach = &dw2102_tuner_attach;
1641786baecfSMauro Carvalho Chehab 				break;
1642786baecfSMauro Carvalho Chehab 			} else {
1643786baecfSMauro Carvalho Chehab 				/* check STV0288 frontend  */
1644786baecfSMauro Carvalho Chehab 				reset16[0] = 0xd0;
1645786baecfSMauro Carvalho Chehab 				reset16[1] = 1;
1646786baecfSMauro Carvalho Chehab 				reset16[2] = 0;
1647786baecfSMauro Carvalho Chehab 				dw210x_op_rw(dev, 0xc2, 0, 0, &reset16[0], 3,
1648786baecfSMauro Carvalho Chehab 						DW210X_WRITE_MSG);
1649786baecfSMauro Carvalho Chehab 				dw210x_op_rw(dev, 0xc3, 0xd1, 0, &reset16[0], 3,
1650786baecfSMauro Carvalho Chehab 						DW210X_READ_MSG);
1651786baecfSMauro Carvalho Chehab 				if (reset16[2] == 0x11) {
1652786baecfSMauro Carvalho Chehab 					dw2102_properties.i2c_algo = &dw2102_earda_i2c_algo;
1653786baecfSMauro Carvalho Chehab 					break;
1654786baecfSMauro Carvalho Chehab 				}
1655786baecfSMauro Carvalho Chehab 			}
1656786baecfSMauro Carvalho Chehab 		case 0x2101:
1657786baecfSMauro Carvalho Chehab 			dw210x_op_rw(dev, 0xbc, 0x0030, 0, &reset16[0], 2,
1658786baecfSMauro Carvalho Chehab 					DW210X_READ_MSG);
1659786baecfSMauro Carvalho Chehab 			dw210x_op_rw(dev, 0xba, 0x0000, 0, &reset16[0], 7,
1660786baecfSMauro Carvalho Chehab 					DW210X_READ_MSG);
1661786baecfSMauro Carvalho Chehab 			dw210x_op_rw(dev, 0xba, 0x0000, 0, &reset16[0], 7,
1662786baecfSMauro Carvalho Chehab 					DW210X_READ_MSG);
1663786baecfSMauro Carvalho Chehab 			dw210x_op_rw(dev, 0xb9, 0x0000, 0, &reset16[0], 2,
1664786baecfSMauro Carvalho Chehab 					DW210X_READ_MSG);
1665786baecfSMauro Carvalho Chehab 			break;
1666786baecfSMauro Carvalho Chehab 		}
1667786baecfSMauro Carvalho Chehab 
1668786baecfSMauro Carvalho Chehab 		msleep(100);
1669786baecfSMauro Carvalho Chehab 		kfree(p);
1670786baecfSMauro Carvalho Chehab 	}
1671786baecfSMauro Carvalho Chehab 	return ret;
1672786baecfSMauro Carvalho Chehab }
1673786baecfSMauro Carvalho Chehab 
1674786baecfSMauro Carvalho Chehab static struct dvb_usb_device_properties dw2102_properties = {
1675786baecfSMauro Carvalho Chehab 	.caps = DVB_USB_IS_AN_I2C_ADAPTER,
1676786baecfSMauro Carvalho Chehab 	.usb_ctrl = DEVICE_SPECIFIC,
16776823627bSRémi Cardona 	.firmware = DW2102_FIRMWARE,
1678786baecfSMauro Carvalho Chehab 	.no_reconnect = 1,
1679786baecfSMauro Carvalho Chehab 
1680786baecfSMauro Carvalho Chehab 	.i2c_algo = &dw2102_serit_i2c_algo,
1681786baecfSMauro Carvalho Chehab 
1682786baecfSMauro Carvalho Chehab 	.rc.legacy = {
1683786baecfSMauro Carvalho Chehab 		.rc_map_table = rc_map_dw210x_table,
1684786baecfSMauro Carvalho Chehab 		.rc_map_size = ARRAY_SIZE(rc_map_dw210x_table),
1685786baecfSMauro Carvalho Chehab 		.rc_interval = 150,
1686786baecfSMauro Carvalho Chehab 		.rc_query = dw2102_rc_query,
1687786baecfSMauro Carvalho Chehab 	},
1688786baecfSMauro Carvalho Chehab 
1689786baecfSMauro Carvalho Chehab 	.generic_bulk_ctrl_endpoint = 0x81,
1690786baecfSMauro Carvalho Chehab 	/* parameter for the MPEG2-data transfer */
1691786baecfSMauro Carvalho Chehab 	.num_adapters = 1,
1692786baecfSMauro Carvalho Chehab 	.download_firmware = dw2102_load_firmware,
1693786baecfSMauro Carvalho Chehab 	.read_mac_address = dw210x_read_mac_address,
1694786baecfSMauro Carvalho Chehab 	.adapter = {
1695786baecfSMauro Carvalho Chehab 		{
1696786baecfSMauro Carvalho Chehab 		.num_frontends = 1,
1697786baecfSMauro Carvalho Chehab 		.fe = {{
1698786baecfSMauro Carvalho Chehab 			.frontend_attach = dw2102_frontend_attach,
1699786baecfSMauro Carvalho Chehab 			.stream = {
1700786baecfSMauro Carvalho Chehab 				.type = USB_BULK,
1701786baecfSMauro Carvalho Chehab 				.count = 8,
1702786baecfSMauro Carvalho Chehab 				.endpoint = 0x82,
1703786baecfSMauro Carvalho Chehab 				.u = {
1704786baecfSMauro Carvalho Chehab 					.bulk = {
1705786baecfSMauro Carvalho Chehab 						.buffersize = 4096,
1706786baecfSMauro Carvalho Chehab 					}
1707786baecfSMauro Carvalho Chehab 				}
1708786baecfSMauro Carvalho Chehab 			},
1709786baecfSMauro Carvalho Chehab 		}},
1710786baecfSMauro Carvalho Chehab 		}
1711786baecfSMauro Carvalho Chehab 	},
1712786baecfSMauro Carvalho Chehab 	.num_device_descs = 3,
1713786baecfSMauro Carvalho Chehab 	.devices = {
1714786baecfSMauro Carvalho Chehab 		{"DVBWorld DVB-S 2102 USB2.0",
1715786baecfSMauro Carvalho Chehab 			{&dw2102_table[CYPRESS_DW2102], NULL},
1716786baecfSMauro Carvalho Chehab 			{NULL},
1717786baecfSMauro Carvalho Chehab 		},
1718786baecfSMauro Carvalho Chehab 		{"DVBWorld DVB-S 2101 USB2.0",
1719786baecfSMauro Carvalho Chehab 			{&dw2102_table[CYPRESS_DW2101], NULL},
1720786baecfSMauro Carvalho Chehab 			{NULL},
1721786baecfSMauro Carvalho Chehab 		},
1722786baecfSMauro Carvalho Chehab 		{"TerraTec Cinergy S USB",
1723786baecfSMauro Carvalho Chehab 			{&dw2102_table[TERRATEC_CINERGY_S], NULL},
1724786baecfSMauro Carvalho Chehab 			{NULL},
1725786baecfSMauro Carvalho Chehab 		},
1726786baecfSMauro Carvalho Chehab 	}
1727786baecfSMauro Carvalho Chehab };
1728786baecfSMauro Carvalho Chehab 
1729786baecfSMauro Carvalho Chehab static struct dvb_usb_device_properties dw2104_properties = {
1730786baecfSMauro Carvalho Chehab 	.caps = DVB_USB_IS_AN_I2C_ADAPTER,
1731786baecfSMauro Carvalho Chehab 	.usb_ctrl = DEVICE_SPECIFIC,
17326823627bSRémi Cardona 	.firmware = DW2104_FIRMWARE,
1733786baecfSMauro Carvalho Chehab 	.no_reconnect = 1,
1734786baecfSMauro Carvalho Chehab 
1735786baecfSMauro Carvalho Chehab 	.i2c_algo = &dw2104_i2c_algo,
1736786baecfSMauro Carvalho Chehab 	.rc.legacy = {
1737786baecfSMauro Carvalho Chehab 		.rc_map_table = rc_map_dw210x_table,
1738786baecfSMauro Carvalho Chehab 		.rc_map_size = ARRAY_SIZE(rc_map_dw210x_table),
1739786baecfSMauro Carvalho Chehab 		.rc_interval = 150,
1740786baecfSMauro Carvalho Chehab 		.rc_query = dw2102_rc_query,
1741786baecfSMauro Carvalho Chehab 	},
1742786baecfSMauro Carvalho Chehab 
1743786baecfSMauro Carvalho Chehab 	.generic_bulk_ctrl_endpoint = 0x81,
1744786baecfSMauro Carvalho Chehab 	/* parameter for the MPEG2-data transfer */
1745786baecfSMauro Carvalho Chehab 	.num_adapters = 1,
1746786baecfSMauro Carvalho Chehab 	.download_firmware = dw2102_load_firmware,
1747786baecfSMauro Carvalho Chehab 	.read_mac_address = dw210x_read_mac_address,
1748786baecfSMauro Carvalho Chehab 	.adapter = {
1749786baecfSMauro Carvalho Chehab 		{
1750786baecfSMauro Carvalho Chehab 		.num_frontends = 1,
1751786baecfSMauro Carvalho Chehab 		.fe = {{
1752786baecfSMauro Carvalho Chehab 			.frontend_attach = dw2104_frontend_attach,
1753786baecfSMauro Carvalho Chehab 			.stream = {
1754786baecfSMauro Carvalho Chehab 				.type = USB_BULK,
1755786baecfSMauro Carvalho Chehab 				.count = 8,
1756786baecfSMauro Carvalho Chehab 				.endpoint = 0x82,
1757786baecfSMauro Carvalho Chehab 				.u = {
1758786baecfSMauro Carvalho Chehab 					.bulk = {
1759786baecfSMauro Carvalho Chehab 						.buffersize = 4096,
1760786baecfSMauro Carvalho Chehab 					}
1761786baecfSMauro Carvalho Chehab 				}
1762786baecfSMauro Carvalho Chehab 			},
1763786baecfSMauro Carvalho Chehab 		}},
1764786baecfSMauro Carvalho Chehab 		}
1765786baecfSMauro Carvalho Chehab 	},
1766786baecfSMauro Carvalho Chehab 	.num_device_descs = 2,
1767786baecfSMauro Carvalho Chehab 	.devices = {
1768786baecfSMauro Carvalho Chehab 		{ "DVBWorld DW2104 USB2.0",
1769786baecfSMauro Carvalho Chehab 			{&dw2102_table[CYPRESS_DW2104], NULL},
1770786baecfSMauro Carvalho Chehab 			{NULL},
1771786baecfSMauro Carvalho Chehab 		},
1772786baecfSMauro Carvalho Chehab 		{ "TeVii S650 USB2.0",
1773786baecfSMauro Carvalho Chehab 			{&dw2102_table[TEVII_S650], NULL},
1774786baecfSMauro Carvalho Chehab 			{NULL},
1775786baecfSMauro Carvalho Chehab 		},
1776786baecfSMauro Carvalho Chehab 	}
1777786baecfSMauro Carvalho Chehab };
1778786baecfSMauro Carvalho Chehab 
1779786baecfSMauro Carvalho Chehab static struct dvb_usb_device_properties dw3101_properties = {
1780786baecfSMauro Carvalho Chehab 	.caps = DVB_USB_IS_AN_I2C_ADAPTER,
1781786baecfSMauro Carvalho Chehab 	.usb_ctrl = DEVICE_SPECIFIC,
17826823627bSRémi Cardona 	.firmware = DW3101_FIRMWARE,
1783786baecfSMauro Carvalho Chehab 	.no_reconnect = 1,
1784786baecfSMauro Carvalho Chehab 
1785786baecfSMauro Carvalho Chehab 	.i2c_algo = &dw3101_i2c_algo,
1786786baecfSMauro Carvalho Chehab 	.rc.legacy = {
1787786baecfSMauro Carvalho Chehab 		.rc_map_table = rc_map_dw210x_table,
1788786baecfSMauro Carvalho Chehab 		.rc_map_size = ARRAY_SIZE(rc_map_dw210x_table),
1789786baecfSMauro Carvalho Chehab 		.rc_interval = 150,
1790786baecfSMauro Carvalho Chehab 		.rc_query = dw2102_rc_query,
1791786baecfSMauro Carvalho Chehab 	},
1792786baecfSMauro Carvalho Chehab 
1793786baecfSMauro Carvalho Chehab 	.generic_bulk_ctrl_endpoint = 0x81,
1794786baecfSMauro Carvalho Chehab 	/* parameter for the MPEG2-data transfer */
1795786baecfSMauro Carvalho Chehab 	.num_adapters = 1,
1796786baecfSMauro Carvalho Chehab 	.download_firmware = dw2102_load_firmware,
1797786baecfSMauro Carvalho Chehab 	.read_mac_address = dw210x_read_mac_address,
1798786baecfSMauro Carvalho Chehab 	.adapter = {
1799786baecfSMauro Carvalho Chehab 		{
1800786baecfSMauro Carvalho Chehab 		.num_frontends = 1,
1801786baecfSMauro Carvalho Chehab 		.fe = {{
1802786baecfSMauro Carvalho Chehab 			.frontend_attach = dw3101_frontend_attach,
1803786baecfSMauro Carvalho Chehab 			.tuner_attach = dw3101_tuner_attach,
1804786baecfSMauro Carvalho Chehab 			.stream = {
1805786baecfSMauro Carvalho Chehab 				.type = USB_BULK,
1806786baecfSMauro Carvalho Chehab 				.count = 8,
1807786baecfSMauro Carvalho Chehab 				.endpoint = 0x82,
1808786baecfSMauro Carvalho Chehab 				.u = {
1809786baecfSMauro Carvalho Chehab 					.bulk = {
1810786baecfSMauro Carvalho Chehab 						.buffersize = 4096,
1811786baecfSMauro Carvalho Chehab 					}
1812786baecfSMauro Carvalho Chehab 				}
1813786baecfSMauro Carvalho Chehab 			},
1814786baecfSMauro Carvalho Chehab 		}},
1815786baecfSMauro Carvalho Chehab 		}
1816786baecfSMauro Carvalho Chehab 	},
1817786baecfSMauro Carvalho Chehab 	.num_device_descs = 1,
1818786baecfSMauro Carvalho Chehab 	.devices = {
1819786baecfSMauro Carvalho Chehab 		{ "DVBWorld DVB-C 3101 USB2.0",
1820786baecfSMauro Carvalho Chehab 			{&dw2102_table[CYPRESS_DW3101], NULL},
1821786baecfSMauro Carvalho Chehab 			{NULL},
1822786baecfSMauro Carvalho Chehab 		},
1823786baecfSMauro Carvalho Chehab 	}
1824786baecfSMauro Carvalho Chehab };
1825786baecfSMauro Carvalho Chehab 
1826786baecfSMauro Carvalho Chehab static struct dvb_usb_device_properties s6x0_properties = {
1827786baecfSMauro Carvalho Chehab 	.caps = DVB_USB_IS_AN_I2C_ADAPTER,
1828786baecfSMauro Carvalho Chehab 	.usb_ctrl = DEVICE_SPECIFIC,
1829786baecfSMauro Carvalho Chehab 	.size_of_priv = sizeof(struct s6x0_state),
18306823627bSRémi Cardona 	.firmware = S630_FIRMWARE,
1831786baecfSMauro Carvalho Chehab 	.no_reconnect = 1,
1832786baecfSMauro Carvalho Chehab 
1833786baecfSMauro Carvalho Chehab 	.i2c_algo = &s6x0_i2c_algo,
1834786baecfSMauro Carvalho Chehab 	.rc.legacy = {
1835786baecfSMauro Carvalho Chehab 		.rc_map_table = rc_map_tevii_table,
1836786baecfSMauro Carvalho Chehab 		.rc_map_size = ARRAY_SIZE(rc_map_tevii_table),
1837786baecfSMauro Carvalho Chehab 		.rc_interval = 150,
1838786baecfSMauro Carvalho Chehab 		.rc_query = dw2102_rc_query,
1839786baecfSMauro Carvalho Chehab 	},
1840786baecfSMauro Carvalho Chehab 
1841786baecfSMauro Carvalho Chehab 	.generic_bulk_ctrl_endpoint = 0x81,
1842786baecfSMauro Carvalho Chehab 	.num_adapters = 1,
1843786baecfSMauro Carvalho Chehab 	.download_firmware = dw2102_load_firmware,
1844786baecfSMauro Carvalho Chehab 	.read_mac_address = s6x0_read_mac_address,
1845786baecfSMauro Carvalho Chehab 	.adapter = {
1846786baecfSMauro Carvalho Chehab 		{
1847786baecfSMauro Carvalho Chehab 		.num_frontends = 1,
1848786baecfSMauro Carvalho Chehab 		.fe = {{
1849786baecfSMauro Carvalho Chehab 			.frontend_attach = zl100313_frontend_attach,
1850786baecfSMauro Carvalho Chehab 			.stream = {
1851786baecfSMauro Carvalho Chehab 				.type = USB_BULK,
1852786baecfSMauro Carvalho Chehab 				.count = 8,
1853786baecfSMauro Carvalho Chehab 				.endpoint = 0x82,
1854786baecfSMauro Carvalho Chehab 				.u = {
1855786baecfSMauro Carvalho Chehab 					.bulk = {
1856786baecfSMauro Carvalho Chehab 						.buffersize = 4096,
1857786baecfSMauro Carvalho Chehab 					}
1858786baecfSMauro Carvalho Chehab 				}
1859786baecfSMauro Carvalho Chehab 			},
1860786baecfSMauro Carvalho Chehab 		}},
1861786baecfSMauro Carvalho Chehab 		}
1862786baecfSMauro Carvalho Chehab 	},
1863786baecfSMauro Carvalho Chehab 	.num_device_descs = 1,
1864786baecfSMauro Carvalho Chehab 	.devices = {
1865786baecfSMauro Carvalho Chehab 		{"TeVii S630 USB",
1866786baecfSMauro Carvalho Chehab 			{&dw2102_table[TEVII_S630], NULL},
1867786baecfSMauro Carvalho Chehab 			{NULL},
1868786baecfSMauro Carvalho Chehab 		},
1869786baecfSMauro Carvalho Chehab 	}
1870786baecfSMauro Carvalho Chehab };
1871786baecfSMauro Carvalho Chehab 
1872786baecfSMauro Carvalho Chehab struct dvb_usb_device_properties *p1100;
1873786baecfSMauro Carvalho Chehab static struct dvb_usb_device_description d1100 = {
1874786baecfSMauro Carvalho Chehab 	"Prof 1100 USB ",
1875786baecfSMauro Carvalho Chehab 	{&dw2102_table[PROF_1100], NULL},
1876786baecfSMauro Carvalho Chehab 	{NULL},
1877786baecfSMauro Carvalho Chehab };
1878786baecfSMauro Carvalho Chehab 
1879786baecfSMauro Carvalho Chehab struct dvb_usb_device_properties *s660;
1880786baecfSMauro Carvalho Chehab static struct dvb_usb_device_description d660 = {
1881786baecfSMauro Carvalho Chehab 	"TeVii S660 USB",
1882786baecfSMauro Carvalho Chehab 	{&dw2102_table[TEVII_S660], NULL},
1883786baecfSMauro Carvalho Chehab 	{NULL},
1884786baecfSMauro Carvalho Chehab };
1885786baecfSMauro Carvalho Chehab 
1886786baecfSMauro Carvalho Chehab static struct dvb_usb_device_description d480_1 = {
1887786baecfSMauro Carvalho Chehab 	"TeVii S480.1 USB",
1888786baecfSMauro Carvalho Chehab 	{&dw2102_table[TEVII_S480_1], NULL},
1889786baecfSMauro Carvalho Chehab 	{NULL},
1890786baecfSMauro Carvalho Chehab };
1891786baecfSMauro Carvalho Chehab 
1892786baecfSMauro Carvalho Chehab static struct dvb_usb_device_description d480_2 = {
1893786baecfSMauro Carvalho Chehab 	"TeVii S480.2 USB",
1894786baecfSMauro Carvalho Chehab 	{&dw2102_table[TEVII_S480_2], NULL},
1895786baecfSMauro Carvalho Chehab 	{NULL},
1896786baecfSMauro Carvalho Chehab };
1897786baecfSMauro Carvalho Chehab 
1898786baecfSMauro Carvalho Chehab struct dvb_usb_device_properties *p7500;
1899786baecfSMauro Carvalho Chehab static struct dvb_usb_device_description d7500 = {
1900786baecfSMauro Carvalho Chehab 	"Prof 7500 USB DVB-S2",
1901786baecfSMauro Carvalho Chehab 	{&dw2102_table[PROF_7500], NULL},
1902786baecfSMauro Carvalho Chehab 	{NULL},
1903786baecfSMauro Carvalho Chehab };
1904786baecfSMauro Carvalho Chehab 
1905*955d00acSIgor M. Liplianin struct dvb_usb_device_properties *s421;
1906*955d00acSIgor M. Liplianin static struct dvb_usb_device_description d421 = {
1907*955d00acSIgor M. Liplianin 	"TeVii S421 PCI",
1908*955d00acSIgor M. Liplianin 	{&dw2102_table[TEVII_S421], NULL},
1909*955d00acSIgor M. Liplianin 	{NULL},
1910*955d00acSIgor M. Liplianin };
1911*955d00acSIgor M. Liplianin 
1912*955d00acSIgor M. Liplianin static struct dvb_usb_device_description d632 = {
1913*955d00acSIgor M. Liplianin 	"TeVii S632 USB",
1914*955d00acSIgor M. Liplianin 	{&dw2102_table[TEVII_S632], NULL},
1915*955d00acSIgor M. Liplianin 	{NULL},
1916*955d00acSIgor M. Liplianin };
1917*955d00acSIgor M. Liplianin 
1918786baecfSMauro Carvalho Chehab static struct dvb_usb_device_properties su3000_properties = {
1919786baecfSMauro Carvalho Chehab 	.caps = DVB_USB_IS_AN_I2C_ADAPTER,
1920786baecfSMauro Carvalho Chehab 	.usb_ctrl = DEVICE_SPECIFIC,
1921786baecfSMauro Carvalho Chehab 	.size_of_priv = sizeof(struct su3000_state),
1922786baecfSMauro Carvalho Chehab 	.power_ctrl = su3000_power_ctrl,
1923786baecfSMauro Carvalho Chehab 	.num_adapters = 1,
1924786baecfSMauro Carvalho Chehab 	.identify_state	= su3000_identify_state,
1925786baecfSMauro Carvalho Chehab 	.i2c_algo = &su3000_i2c_algo,
1926786baecfSMauro Carvalho Chehab 
1927786baecfSMauro Carvalho Chehab 	.rc.legacy = {
1928786baecfSMauro Carvalho Chehab 		.rc_map_table = rc_map_su3000_table,
1929786baecfSMauro Carvalho Chehab 		.rc_map_size = ARRAY_SIZE(rc_map_su3000_table),
1930786baecfSMauro Carvalho Chehab 		.rc_interval = 150,
1931786baecfSMauro Carvalho Chehab 		.rc_query = dw2102_rc_query,
1932786baecfSMauro Carvalho Chehab 	},
1933786baecfSMauro Carvalho Chehab 
1934786baecfSMauro Carvalho Chehab 	.read_mac_address = su3000_read_mac_address,
1935786baecfSMauro Carvalho Chehab 
1936786baecfSMauro Carvalho Chehab 	.generic_bulk_ctrl_endpoint = 0x01,
1937786baecfSMauro Carvalho Chehab 
1938786baecfSMauro Carvalho Chehab 	.adapter = {
1939786baecfSMauro Carvalho Chehab 		{
1940786baecfSMauro Carvalho Chehab 		.num_frontends = 1,
1941786baecfSMauro Carvalho Chehab 		.fe = {{
1942786baecfSMauro Carvalho Chehab 			.streaming_ctrl   = su3000_streaming_ctrl,
1943786baecfSMauro Carvalho Chehab 			.frontend_attach  = su3000_frontend_attach,
1944786baecfSMauro Carvalho Chehab 			.stream = {
1945786baecfSMauro Carvalho Chehab 				.type = USB_BULK,
1946786baecfSMauro Carvalho Chehab 				.count = 8,
1947786baecfSMauro Carvalho Chehab 				.endpoint = 0x82,
1948786baecfSMauro Carvalho Chehab 				.u = {
1949786baecfSMauro Carvalho Chehab 					.bulk = {
1950786baecfSMauro Carvalho Chehab 						.buffersize = 4096,
1951786baecfSMauro Carvalho Chehab 					}
1952786baecfSMauro Carvalho Chehab 				}
1953786baecfSMauro Carvalho Chehab 			}
1954786baecfSMauro Carvalho Chehab 		}},
1955786baecfSMauro Carvalho Chehab 		}
1956786baecfSMauro Carvalho Chehab 	},
1957786baecfSMauro Carvalho Chehab 	.num_device_descs = 3,
1958786baecfSMauro Carvalho Chehab 	.devices = {
1959786baecfSMauro Carvalho Chehab 		{ "SU3000HD DVB-S USB2.0",
1960786baecfSMauro Carvalho Chehab 			{ &dw2102_table[GENIATECH_SU3000], NULL },
1961786baecfSMauro Carvalho Chehab 			{ NULL },
1962786baecfSMauro Carvalho Chehab 		},
1963786baecfSMauro Carvalho Chehab 		{ "Terratec Cinergy S2 USB HD",
1964786baecfSMauro Carvalho Chehab 			{ &dw2102_table[TERRATEC_CINERGY_S2], NULL },
1965786baecfSMauro Carvalho Chehab 			{ NULL },
1966786baecfSMauro Carvalho Chehab 		},
1967786baecfSMauro Carvalho Chehab 		{ "X3M TV SPC1400HD PCI",
1968786baecfSMauro Carvalho Chehab 			{ &dw2102_table[X3M_SPC1400HD], NULL },
1969786baecfSMauro Carvalho Chehab 			{ NULL },
1970786baecfSMauro Carvalho Chehab 		},
1971786baecfSMauro Carvalho Chehab 	}
1972786baecfSMauro Carvalho Chehab };
1973786baecfSMauro Carvalho Chehab 
1974786baecfSMauro Carvalho Chehab static int dw2102_probe(struct usb_interface *intf,
1975786baecfSMauro Carvalho Chehab 		const struct usb_device_id *id)
1976786baecfSMauro Carvalho Chehab {
1977786baecfSMauro Carvalho Chehab 	p1100 = kmemdup(&s6x0_properties,
1978786baecfSMauro Carvalho Chehab 			sizeof(struct dvb_usb_device_properties), GFP_KERNEL);
1979786baecfSMauro Carvalho Chehab 	if (!p1100)
1980786baecfSMauro Carvalho Chehab 		return -ENOMEM;
1981786baecfSMauro Carvalho Chehab 	/* copy default structure */
1982786baecfSMauro Carvalho Chehab 	/* fill only different fields */
19836823627bSRémi Cardona 	p1100->firmware = P1100_FIRMWARE;
1984786baecfSMauro Carvalho Chehab 	p1100->devices[0] = d1100;
1985786baecfSMauro Carvalho Chehab 	p1100->rc.legacy.rc_map_table = rc_map_tbs_table;
1986786baecfSMauro Carvalho Chehab 	p1100->rc.legacy.rc_map_size = ARRAY_SIZE(rc_map_tbs_table);
1987786baecfSMauro Carvalho Chehab 	p1100->adapter->fe[0].frontend_attach = stv0288_frontend_attach;
1988786baecfSMauro Carvalho Chehab 
1989786baecfSMauro Carvalho Chehab 	s660 = kmemdup(&s6x0_properties,
1990786baecfSMauro Carvalho Chehab 		       sizeof(struct dvb_usb_device_properties), GFP_KERNEL);
1991786baecfSMauro Carvalho Chehab 	if (!s660) {
1992786baecfSMauro Carvalho Chehab 		kfree(p1100);
1993786baecfSMauro Carvalho Chehab 		return -ENOMEM;
1994786baecfSMauro Carvalho Chehab 	}
19956823627bSRémi Cardona 	s660->firmware = S660_FIRMWARE;
1996786baecfSMauro Carvalho Chehab 	s660->num_device_descs = 3;
1997786baecfSMauro Carvalho Chehab 	s660->devices[0] = d660;
1998786baecfSMauro Carvalho Chehab 	s660->devices[1] = d480_1;
1999786baecfSMauro Carvalho Chehab 	s660->devices[2] = d480_2;
2000786baecfSMauro Carvalho Chehab 	s660->adapter->fe[0].frontend_attach = ds3000_frontend_attach;
2001786baecfSMauro Carvalho Chehab 
2002786baecfSMauro Carvalho Chehab 	p7500 = kmemdup(&s6x0_properties,
2003786baecfSMauro Carvalho Chehab 			sizeof(struct dvb_usb_device_properties), GFP_KERNEL);
2004786baecfSMauro Carvalho Chehab 	if (!p7500) {
2005786baecfSMauro Carvalho Chehab 		kfree(p1100);
2006786baecfSMauro Carvalho Chehab 		kfree(s660);
2007786baecfSMauro Carvalho Chehab 		return -ENOMEM;
2008786baecfSMauro Carvalho Chehab 	}
20096823627bSRémi Cardona 	p7500->firmware = P7500_FIRMWARE;
2010786baecfSMauro Carvalho Chehab 	p7500->devices[0] = d7500;
2011786baecfSMauro Carvalho Chehab 	p7500->rc.legacy.rc_map_table = rc_map_tbs_table;
2012786baecfSMauro Carvalho Chehab 	p7500->rc.legacy.rc_map_size = ARRAY_SIZE(rc_map_tbs_table);
2013786baecfSMauro Carvalho Chehab 	p7500->adapter->fe[0].frontend_attach = prof_7500_frontend_attach;
2014786baecfSMauro Carvalho Chehab 
2015*955d00acSIgor M. Liplianin 
2016*955d00acSIgor M. Liplianin 	s421 = kmemdup(&su3000_properties,
2017*955d00acSIgor M. Liplianin 		       sizeof(struct dvb_usb_device_properties), GFP_KERNEL);
2018*955d00acSIgor M. Liplianin 	if (!s421) {
2019*955d00acSIgor M. Liplianin 		kfree(p1100);
2020*955d00acSIgor M. Liplianin 		kfree(s660);
2021*955d00acSIgor M. Liplianin 		kfree(p7500);
2022*955d00acSIgor M. Liplianin 		return -ENOMEM;
2023*955d00acSIgor M. Liplianin 	}
2024*955d00acSIgor M. Liplianin 	s421->num_device_descs = 2;
2025*955d00acSIgor M. Liplianin 	s421->devices[0] = d421;
2026*955d00acSIgor M. Liplianin 	s421->devices[1] = d632;
2027*955d00acSIgor M. Liplianin 	s421->adapter->fe[0].frontend_attach = m88rs2000_frontend_attach;
2028*955d00acSIgor M. Liplianin 
2029786baecfSMauro Carvalho Chehab 	if (0 == dvb_usb_device_init(intf, &dw2102_properties,
2030786baecfSMauro Carvalho Chehab 			THIS_MODULE, NULL, adapter_nr) ||
2031786baecfSMauro Carvalho Chehab 	    0 == dvb_usb_device_init(intf, &dw2104_properties,
2032786baecfSMauro Carvalho Chehab 			THIS_MODULE, NULL, adapter_nr) ||
2033786baecfSMauro Carvalho Chehab 	    0 == dvb_usb_device_init(intf, &dw3101_properties,
2034786baecfSMauro Carvalho Chehab 			THIS_MODULE, NULL, adapter_nr) ||
2035786baecfSMauro Carvalho Chehab 	    0 == dvb_usb_device_init(intf, &s6x0_properties,
2036786baecfSMauro Carvalho Chehab 			THIS_MODULE, NULL, adapter_nr) ||
2037786baecfSMauro Carvalho Chehab 	    0 == dvb_usb_device_init(intf, p1100,
2038786baecfSMauro Carvalho Chehab 			THIS_MODULE, NULL, adapter_nr) ||
2039786baecfSMauro Carvalho Chehab 	    0 == dvb_usb_device_init(intf, s660,
2040786baecfSMauro Carvalho Chehab 			THIS_MODULE, NULL, adapter_nr) ||
2041786baecfSMauro Carvalho Chehab 	    0 == dvb_usb_device_init(intf, p7500,
2042786baecfSMauro Carvalho Chehab 			THIS_MODULE, NULL, adapter_nr) ||
2043*955d00acSIgor M. Liplianin 	    0 == dvb_usb_device_init(intf, s421,
2044*955d00acSIgor M. Liplianin 			THIS_MODULE, NULL, adapter_nr) ||
2045786baecfSMauro Carvalho Chehab 	    0 == dvb_usb_device_init(intf, &su3000_properties,
2046786baecfSMauro Carvalho Chehab 				     THIS_MODULE, NULL, adapter_nr))
2047786baecfSMauro Carvalho Chehab 		return 0;
2048786baecfSMauro Carvalho Chehab 
2049786baecfSMauro Carvalho Chehab 	return -ENODEV;
2050786baecfSMauro Carvalho Chehab }
2051786baecfSMauro Carvalho Chehab 
2052786baecfSMauro Carvalho Chehab static struct usb_driver dw2102_driver = {
2053786baecfSMauro Carvalho Chehab 	.name = "dw2102",
2054786baecfSMauro Carvalho Chehab 	.probe = dw2102_probe,
2055786baecfSMauro Carvalho Chehab 	.disconnect = dvb_usb_device_exit,
2056786baecfSMauro Carvalho Chehab 	.id_table = dw2102_table,
2057786baecfSMauro Carvalho Chehab };
2058786baecfSMauro Carvalho Chehab 
2059786baecfSMauro Carvalho Chehab module_usb_driver(dw2102_driver);
2060786baecfSMauro Carvalho Chehab 
2061786baecfSMauro Carvalho Chehab MODULE_AUTHOR("Igor M. Liplianin (c) liplianin@me.by");
2062786baecfSMauro Carvalho Chehab MODULE_DESCRIPTION("Driver for DVBWorld DVB-S 2101, 2102, DVB-S2 2104,"
2063786baecfSMauro Carvalho Chehab 			" DVB-C 3101 USB2.0,"
2064*955d00acSIgor M. Liplianin 			" TeVii S600, S630, S650, S660, S480, S421, S632"
2065786baecfSMauro Carvalho Chehab 			" Prof 1100, 7500 USB2.0,"
2066786baecfSMauro Carvalho Chehab 			" Geniatech SU3000 devices");
2067786baecfSMauro Carvalho Chehab MODULE_VERSION("0.1");
2068786baecfSMauro Carvalho Chehab MODULE_LICENSE("GPL");
20696823627bSRémi Cardona MODULE_FIRMWARE(DW2101_FIRMWARE);
20706823627bSRémi Cardona MODULE_FIRMWARE(DW2102_FIRMWARE);
20716823627bSRémi Cardona MODULE_FIRMWARE(DW2104_FIRMWARE);
20726823627bSRémi Cardona MODULE_FIRMWARE(DW3101_FIRMWARE);
20736823627bSRémi Cardona MODULE_FIRMWARE(S630_FIRMWARE);
20746823627bSRémi Cardona MODULE_FIRMWARE(S660_FIRMWARE);
20756823627bSRémi Cardona MODULE_FIRMWARE(P1100_FIRMWARE);
20766823627bSRémi Cardona MODULE_FIRMWARE(P7500_FIRMWARE);
2077