1 /* DVB USB compliant linux driver for
2  *
3  * DM04/QQBOX DVB-S USB BOX	LME2510C + SHARP:BS2F7HZ7395
4  *				LME2510C + LG TDQY-P001F
5  *				LME2510C + BS2F7HZ0194
6  *				LME2510 + LG TDQY-P001F
7  *				LME2510 + BS2F7HZ0194
8  *
9  * MVB7395 (LME2510C+SHARP:BS2F7HZ7395)
10  * SHARP:BS2F7HZ7395 = (STV0288+Sharp IX2505V)
11  *
12  * MV001F (LME2510+LGTDQY-P001F)
13  * LG TDQY - P001F =(TDA8263 + TDA10086H)
14  *
15  * MVB0001F (LME2510C+LGTDQT-P001F)
16  *
17  * MV0194 (LME2510+SHARP:BS2F7HZ0194)
18  * SHARP:BS2F7HZ0194 = (STV0299+IX2410)
19  *
20  * MVB0194 (LME2510C+SHARP0194)
21  *
22  * LME2510C + M88RS2000
23  *
24  * For firmware see Documentation/dvb/lmedm04.txt
25  *
26  * I2C addresses:
27  * 0xd0 - STV0288	- Demodulator
28  * 0xc0 - Sharp IX2505V	- Tuner
29  * --
30  * 0x1c - TDA10086   - Demodulator
31  * 0xc0 - TDA8263    - Tuner
32  * --
33  * 0xd0 - STV0299	- Demodulator
34  * 0xc0 - IX2410	- Tuner
35  *
36  *
37  * VID = 3344  PID LME2510=1122 LME2510C=1120
38  *
39  * Copyright (C) 2010 Malcolm Priestley (tvboxspy@gmail.com)
40  * LME2510(C)(C) Leaguerme (Shenzhen) MicroElectronics Co., Ltd.
41  *
42  * This program is free software; you can redistribute it and/or modify
43  * it under the terms of the GNU General Public License Version 2, as
44  * published by the Free Software Foundation.
45  *
46  * This program is distributed in the hope that it will be useful,
47  * but WITHOUT ANY WARRANTY; without even the implied warranty of
48  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
49  * GNU General Public License for more details.
50  *
51  * You should have received a copy of the GNU General Public License
52  * along with this program; if not, write to the Free Software
53  * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
54  *
55  *
56  * see Documentation/dvb/README.dvb-usb for more information
57  *
58  * Known Issues :
59  *	LME2510: Non Intel USB chipsets fail to maintain High Speed on
60  * Boot or Hot Plug.
61  *
62  * QQbox suffers from noise on LNB voltage.
63  *
64  *	LME2510: SHARP:BS2F7HZ0194(MV0194) cannot cold reset and share system
65  * with other tuners. After a cold reset streaming will not start.
66  *
67  * M88RS2000 suffers from loss of lock.
68  */
69 #define DVB_USB_LOG_PREFIX "LME2510(C)"
70 #include <linux/usb.h>
71 #include <linux/usb/input.h>
72 #include <media/rc-core.h>
73 
74 #include "dvb_usb.h"
75 #include "lmedm04.h"
76 #include "tda826x.h"
77 #include "tda10086.h"
78 #include "stv0288.h"
79 #include "ix2505v.h"
80 #include "stv0299.h"
81 #include "dvb-pll.h"
82 #include "z0194a.h"
83 #include "m88rs2000.h"
84 #include "ts2020.h"
85 
86 
87 #define LME2510_C_S7395	"dvb-usb-lme2510c-s7395.fw";
88 #define LME2510_C_LG	"dvb-usb-lme2510c-lg.fw";
89 #define LME2510_C_S0194	"dvb-usb-lme2510c-s0194.fw";
90 #define LME2510_C_RS2000 "dvb-usb-lme2510c-rs2000.fw";
91 #define LME2510_LG	"dvb-usb-lme2510-lg.fw";
92 #define LME2510_S0194	"dvb-usb-lme2510-s0194.fw";
93 
94 /* debug */
95 static int dvb_usb_lme2510_debug;
96 #define lme_debug(var, level, args...) do { \
97 	if ((var >= level)) \
98 		pr_debug(DVB_USB_LOG_PREFIX": " args); \
99 } while (0)
100 #define deb_info(level, args...) lme_debug(dvb_usb_lme2510_debug, level, args)
101 #define debug_data_snipet(level, name, p) \
102 	 deb_info(level, name" (%02x%02x%02x%02x%02x%02x%02x%02x)", \
103 		*p, *(p+1), *(p+2), *(p+3), *(p+4), \
104 			*(p+5), *(p+6), *(p+7));
105 #define info(args...) pr_info(DVB_USB_LOG_PREFIX": "args)
106 
107 module_param_named(debug, dvb_usb_lme2510_debug, int, 0644);
108 MODULE_PARM_DESC(debug, "set debugging level (1=info (or-able)).");
109 
110 static int dvb_usb_lme2510_firmware;
111 module_param_named(firmware, dvb_usb_lme2510_firmware, int, 0644);
112 MODULE_PARM_DESC(firmware, "set default firmware 0=Sharp7395 1=LG");
113 
114 static int pid_filter;
115 module_param_named(pid, pid_filter, int, 0644);
116 MODULE_PARM_DESC(pid, "set default 0=default 1=off 2=on");
117 
118 
119 DVB_DEFINE_MOD_OPT_ADAPTER_NR(adapter_nr);
120 
121 #define TUNER_DEFAULT	0x0
122 #define TUNER_LG	0x1
123 #define TUNER_S7395	0x2
124 #define TUNER_S0194	0x3
125 #define TUNER_RS2000	0x4
126 
127 struct lme2510_state {
128 	unsigned long int_urb_due;
129 	enum fe_status lock_status;
130 	u8 id;
131 	u8 tuner_config;
132 	u8 signal_level;
133 	u8 signal_sn;
134 	u8 time_key;
135 	u8 i2c_talk_onoff;
136 	u8 i2c_gate;
137 	u8 i2c_tuner_gate_w;
138 	u8 i2c_tuner_gate_r;
139 	u8 i2c_tuner_addr;
140 	u8 stream_on;
141 	u8 pid_size;
142 	u8 pid_off;
143 	void *buffer;
144 	struct urb *lme_urb;
145 	void *usb_buffer;
146 	/* Frontend original calls */
147 	int (*fe_read_status)(struct dvb_frontend *, enum fe_status *);
148 	int (*fe_read_signal_strength)(struct dvb_frontend *, u16 *);
149 	int (*fe_read_snr)(struct dvb_frontend *, u16 *);
150 	int (*fe_read_ber)(struct dvb_frontend *, u32 *);
151 	int (*fe_read_ucblocks)(struct dvb_frontend *, u32 *);
152 	int (*fe_set_voltage)(struct dvb_frontend *, enum fe_sec_voltage);
153 	u8 dvb_usb_lme2510_firmware;
154 };
155 
156 static int lme2510_bulk_write(struct usb_device *dev,
157 				u8 *snd, int len, u8 pipe)
158 {
159 	int ret, actual_l;
160 
161 	ret = usb_bulk_msg(dev, usb_sndbulkpipe(dev, pipe),
162 				snd, len , &actual_l, 100);
163 	return ret;
164 }
165 
166 static int lme2510_bulk_read(struct usb_device *dev,
167 				u8 *rev, int len, u8 pipe)
168 {
169 	int ret, actual_l;
170 
171 	ret = usb_bulk_msg(dev, usb_rcvbulkpipe(dev, pipe),
172 				 rev, len , &actual_l, 200);
173 	return ret;
174 }
175 
176 static int lme2510_usb_talk(struct dvb_usb_device *d,
177 		u8 *wbuf, int wlen, u8 *rbuf, int rlen)
178 {
179 	struct lme2510_state *st = d->priv;
180 	u8 *buff;
181 	int ret = 0;
182 
183 	if (st->usb_buffer == NULL) {
184 		st->usb_buffer = kmalloc(64, GFP_KERNEL);
185 		if (st->usb_buffer == NULL) {
186 			info("MEM Error no memory");
187 			return -ENOMEM;
188 		}
189 	}
190 	buff = st->usb_buffer;
191 
192 	ret = mutex_lock_interruptible(&d->usb_mutex);
193 
194 	if (ret < 0)
195 		return -EAGAIN;
196 
197 	/* the read/write capped at 64 */
198 	memcpy(buff, wbuf, (wlen < 64) ? wlen : 64);
199 
200 	ret |= lme2510_bulk_write(d->udev, buff, wlen , 0x01);
201 
202 	ret |= lme2510_bulk_read(d->udev, buff, (rlen < 64) ?
203 			rlen : 64 , 0x01);
204 
205 	if (rlen > 0)
206 		memcpy(rbuf, buff, rlen);
207 
208 	mutex_unlock(&d->usb_mutex);
209 
210 	return (ret < 0) ? -ENODEV : 0;
211 }
212 
213 static int lme2510_stream_restart(struct dvb_usb_device *d)
214 {
215 	struct lme2510_state *st = d->priv;
216 	u8 all_pids[] = LME_ALL_PIDS;
217 	u8 stream_on[] = LME_ST_ON_W;
218 	int ret;
219 	u8 rbuff[1];
220 	if (st->pid_off)
221 		ret = lme2510_usb_talk(d, all_pids, sizeof(all_pids),
222 			rbuff, sizeof(rbuff));
223 	/*Restart Stream Command*/
224 	ret = lme2510_usb_talk(d, stream_on, sizeof(stream_on),
225 			rbuff, sizeof(rbuff));
226 	return ret;
227 }
228 
229 static int lme2510_enable_pid(struct dvb_usb_device *d, u8 index, u16 pid_out)
230 {
231 	struct lme2510_state *st = d->priv;
232 	static u8 pid_buff[] = LME_ZERO_PID;
233 	static u8 rbuf[1];
234 	u8 pid_no = index * 2;
235 	u8 pid_len = pid_no + 2;
236 	int ret = 0;
237 	deb_info(1, "PID Setting Pid %04x", pid_out);
238 
239 	if (st->pid_size == 0)
240 		ret |= lme2510_stream_restart(d);
241 
242 	pid_buff[2] = pid_no;
243 	pid_buff[3] = (u8)pid_out & 0xff;
244 	pid_buff[4] = pid_no + 1;
245 	pid_buff[5] = (u8)(pid_out >> 8);
246 
247 	if (pid_len > st->pid_size)
248 		st->pid_size = pid_len;
249 	pid_buff[7] = 0x80 + st->pid_size;
250 
251 	ret |= lme2510_usb_talk(d, pid_buff ,
252 		sizeof(pid_buff) , rbuf, sizeof(rbuf));
253 
254 	if (st->stream_on)
255 		ret |= lme2510_stream_restart(d);
256 
257 	return ret;
258 }
259 
260 /* Convert range from 0x00-0xff to 0x0000-0xffff */
261 #define reg_to_16bits(x)	((x) | ((x) << 8))
262 
263 static void lme2510_update_stats(struct dvb_usb_adapter *adap)
264 {
265 	struct lme2510_state *st = adap_to_priv(adap);
266 	struct dvb_frontend *fe = adap->fe[0];
267 	struct dtv_frontend_properties *c;
268 	u32 s_tmp = 0, c_tmp = 0;
269 
270 	if (!fe)
271 		return;
272 
273 	c = &fe->dtv_property_cache;
274 
275 	c->block_count.len = 1;
276 	c->block_count.stat[0].scale = FE_SCALE_NOT_AVAILABLE;
277 	c->block_error.len = 1;
278 	c->block_error.stat[0].scale = FE_SCALE_NOT_AVAILABLE;
279 	c->post_bit_count.len = 1;
280 	c->post_bit_count.stat[0].scale = FE_SCALE_NOT_AVAILABLE;
281 	c->post_bit_error.len = 1;
282 	c->post_bit_error.stat[0].scale = FE_SCALE_NOT_AVAILABLE;
283 
284 	if (st->i2c_talk_onoff) {
285 		c->strength.len = 1;
286 		c->strength.stat[0].scale = FE_SCALE_NOT_AVAILABLE;
287 		c->cnr.len = 1;
288 		c->cnr.stat[0].scale = FE_SCALE_NOT_AVAILABLE;
289 		return;
290 	}
291 
292 	switch (st->tuner_config) {
293 	case TUNER_LG:
294 		s_tmp = reg_to_16bits(0xff - st->signal_level);
295 		c_tmp = reg_to_16bits(0xff - st->signal_sn);
296 		break;
297 	case TUNER_S7395:
298 	case TUNER_S0194:
299 		s_tmp = 0xffff - (((st->signal_level * 2) << 8) * 5 / 4);
300 		c_tmp = reg_to_16bits((0xff - st->signal_sn - 0xa1) * 3);
301 		break;
302 	case TUNER_RS2000:
303 		s_tmp = reg_to_16bits(st->signal_level);
304 		c_tmp = reg_to_16bits(st->signal_sn);
305 	}
306 
307 	c->strength.len = 1;
308 	c->strength.stat[0].scale = FE_SCALE_RELATIVE;
309 	c->strength.stat[0].uvalue = (u64)s_tmp;
310 
311 	c->cnr.len = 1;
312 	c->cnr.stat[0].scale = FE_SCALE_RELATIVE;
313 	c->cnr.stat[0].uvalue = (u64)c_tmp;
314 }
315 
316 static void lme2510_int_response(struct urb *lme_urb)
317 {
318 	struct dvb_usb_adapter *adap = lme_urb->context;
319 	struct lme2510_state *st = adap_to_priv(adap);
320 	static u8 *ibuf, *rbuf;
321 	int i = 0, offset;
322 	u32 key;
323 	u8 signal_lock = 0;
324 
325 	switch (lme_urb->status) {
326 	case 0:
327 	case -ETIMEDOUT:
328 		break;
329 	case -ECONNRESET:
330 	case -ENOENT:
331 	case -ESHUTDOWN:
332 		return;
333 	default:
334 		info("Error %x", lme_urb->status);
335 		break;
336 	}
337 
338 	rbuf = (u8 *) lme_urb->transfer_buffer;
339 
340 	offset = ((lme_urb->actual_length/8) > 4)
341 			? 4 : (lme_urb->actual_length/8) ;
342 
343 	for (i = 0; i < offset; ++i) {
344 		ibuf = (u8 *)&rbuf[i*8];
345 		deb_info(5, "INT O/S C =%02x C/O=%02x Type =%02x%02x",
346 		offset, i, ibuf[0], ibuf[1]);
347 
348 		switch (ibuf[0]) {
349 		case 0xaa:
350 			debug_data_snipet(1, "INT Remote data snipet", ibuf);
351 			if ((ibuf[4] + ibuf[5]) == 0xff) {
352 				key = RC_SCANCODE_NECX((ibuf[2] ^ 0xff) << 8 |
353 						       (ibuf[3] > 0) ? (ibuf[3] ^ 0xff) : 0,
354 						       ibuf[5]);
355 				deb_info(1, "INT Key =%08x", key);
356 				if (adap_to_d(adap)->rc_dev != NULL)
357 					rc_keydown(adap_to_d(adap)->rc_dev,
358 						   RC_TYPE_NEC, key, 0);
359 			}
360 			break;
361 		case 0xbb:
362 			switch (st->tuner_config) {
363 			case TUNER_LG:
364 				signal_lock = ibuf[2] & BIT(5);
365 				st->signal_level = ibuf[4];
366 				st->signal_sn = ibuf[3];
367 				st->time_key = ibuf[7];
368 				break;
369 			case TUNER_S7395:
370 			case TUNER_S0194:
371 				/* Tweak for earlier firmware*/
372 				if (ibuf[1] == 0x03) {
373 					signal_lock = ibuf[2] & BIT(4);
374 					st->signal_level = ibuf[3];
375 					st->signal_sn = ibuf[4];
376 				} else {
377 					st->signal_level = ibuf[4];
378 					st->signal_sn = ibuf[5];
379 				}
380 				break;
381 			case TUNER_RS2000:
382 				signal_lock = ibuf[2] & 0xee;
383 				st->signal_level = ibuf[5];
384 				st->signal_sn = ibuf[4];
385 				st->time_key = ibuf[7];
386 			default:
387 				break;
388 			}
389 
390 			/* Interrupt will also throw just BIT 0 as lock */
391 			signal_lock |= ibuf[2] & BIT(0);
392 
393 			if (!signal_lock)
394 				st->lock_status &= ~FE_HAS_LOCK;
395 
396 			lme2510_update_stats(adap);
397 
398 			debug_data_snipet(5, "INT Remote data snipet in", ibuf);
399 		break;
400 		case 0xcc:
401 			debug_data_snipet(1, "INT Control data snipet", ibuf);
402 			break;
403 		default:
404 			debug_data_snipet(1, "INT Unknown data snipet", ibuf);
405 		break;
406 		}
407 	}
408 
409 	usb_submit_urb(lme_urb, GFP_ATOMIC);
410 
411 	/* Interrupt urb is due every 48 msecs while streaming the buffer
412 	 * stores up to 4 periods if missed. Allow 200 msec for next interrupt.
413 	 */
414 	st->int_urb_due = jiffies + msecs_to_jiffies(200);
415 }
416 
417 static int lme2510_int_read(struct dvb_usb_adapter *adap)
418 {
419 	struct dvb_usb_device *d = adap_to_d(adap);
420 	struct lme2510_state *lme_int = adap_to_priv(adap);
421 	struct usb_host_endpoint *ep;
422 
423 	lme_int->lme_urb = usb_alloc_urb(0, GFP_ATOMIC);
424 
425 	if (lme_int->lme_urb == NULL)
426 			return -ENOMEM;
427 
428 	lme_int->buffer = usb_alloc_coherent(d->udev, 128, GFP_ATOMIC,
429 					&lme_int->lme_urb->transfer_dma);
430 
431 	if (lme_int->buffer == NULL)
432 			return -ENOMEM;
433 
434 	usb_fill_int_urb(lme_int->lme_urb,
435 				d->udev,
436 				usb_rcvintpipe(d->udev, 0xa),
437 				lme_int->buffer,
438 				128,
439 				lme2510_int_response,
440 				adap,
441 				8);
442 
443 	/* Quirk of pipe reporting PIPE_BULK but behaves as interrupt */
444 	ep = usb_pipe_endpoint(d->udev, lme_int->lme_urb->pipe);
445 
446 	if (usb_endpoint_type(&ep->desc) == USB_ENDPOINT_XFER_BULK)
447 		lme_int->lme_urb->pipe = usb_rcvbulkpipe(d->udev, 0xa),
448 
449 	lme_int->lme_urb->transfer_flags |= URB_NO_TRANSFER_DMA_MAP;
450 
451 	usb_submit_urb(lme_int->lme_urb, GFP_ATOMIC);
452 	info("INT Interrupt Service Started");
453 
454 	return 0;
455 }
456 
457 static int lme2510_pid_filter_ctrl(struct dvb_usb_adapter *adap, int onoff)
458 {
459 	struct dvb_usb_device *d = adap_to_d(adap);
460 	struct lme2510_state *st = adap_to_priv(adap);
461 	static u8 clear_pid_reg[] = LME_ALL_PIDS;
462 	static u8 rbuf[1];
463 	int ret = 0;
464 
465 	deb_info(1, "PID Clearing Filter");
466 
467 	mutex_lock(&d->i2c_mutex);
468 
469 	if (!onoff) {
470 		ret |= lme2510_usb_talk(d, clear_pid_reg,
471 			sizeof(clear_pid_reg), rbuf, sizeof(rbuf));
472 		st->pid_off = true;
473 	} else
474 		st->pid_off = false;
475 
476 	st->pid_size = 0;
477 
478 	mutex_unlock(&d->i2c_mutex);
479 
480 	return 0;
481 }
482 
483 static int lme2510_pid_filter(struct dvb_usb_adapter *adap, int index, u16 pid,
484 	int onoff)
485 {
486 	struct dvb_usb_device *d = adap_to_d(adap);
487 	int ret = 0;
488 
489 	deb_info(3, "%s PID=%04x Index=%04x onoff=%02x", __func__,
490 		pid, index, onoff);
491 
492 	if (onoff) {
493 		mutex_lock(&d->i2c_mutex);
494 		ret |= lme2510_enable_pid(d, index, pid);
495 		mutex_unlock(&d->i2c_mutex);
496 	}
497 
498 
499 	return ret;
500 }
501 
502 
503 static int lme2510_return_status(struct dvb_usb_device *d)
504 {
505 	int ret = 0;
506 	u8 *data;
507 
508 	data = kzalloc(10, GFP_KERNEL);
509 	if (!data)
510 		return -ENOMEM;
511 
512 	ret |= usb_control_msg(d->udev, usb_rcvctrlpipe(d->udev, 0),
513 			0x06, 0x80, 0x0302, 0x00, data, 0x0006, 200);
514 	info("Firmware Status: %x (%x)", ret , data[2]);
515 
516 	ret = (ret < 0) ? -ENODEV : data[2];
517 	kfree(data);
518 	return ret;
519 }
520 
521 static int lme2510_msg(struct dvb_usb_device *d,
522 		u8 *wbuf, int wlen, u8 *rbuf, int rlen)
523 {
524 	struct lme2510_state *st = d->priv;
525 
526 	st->i2c_talk_onoff = 1;
527 
528 	return lme2510_usb_talk(d, wbuf, wlen, rbuf, rlen);
529 }
530 
531 static int lme2510_i2c_xfer(struct i2c_adapter *adap, struct i2c_msg msg[],
532 				 int num)
533 {
534 	struct dvb_usb_device *d = i2c_get_adapdata(adap);
535 	struct lme2510_state *st = d->priv;
536 	static u8 obuf[64], ibuf[64];
537 	int i, read, read_o;
538 	u16 len;
539 	u8 gate = st->i2c_gate;
540 
541 	mutex_lock(&d->i2c_mutex);
542 
543 	if (gate == 0)
544 		gate = 5;
545 
546 	for (i = 0; i < num; i++) {
547 		read_o = msg[i].flags & I2C_M_RD;
548 		read = i + 1 < num && msg[i + 1].flags & I2C_M_RD;
549 		read |= read_o;
550 		gate = (msg[i].addr == st->i2c_tuner_addr)
551 			? (read)	? st->i2c_tuner_gate_r
552 					: st->i2c_tuner_gate_w
553 			: st->i2c_gate;
554 		obuf[0] = gate | (read << 7);
555 
556 		if (gate == 5)
557 			obuf[1] = (read) ? 2 : msg[i].len + 1;
558 		else
559 			obuf[1] = msg[i].len + read + 1;
560 
561 		obuf[2] = msg[i].addr << 1;
562 
563 		if (read) {
564 			if (read_o)
565 				len = 3;
566 			else {
567 				memcpy(&obuf[3], msg[i].buf, msg[i].len);
568 				obuf[msg[i].len+3] = msg[i+1].len;
569 				len = msg[i].len+4;
570 			}
571 		} else {
572 			memcpy(&obuf[3], msg[i].buf, msg[i].len);
573 			len = msg[i].len+3;
574 		}
575 
576 		if (lme2510_msg(d, obuf, len, ibuf, 64) < 0) {
577 			deb_info(1, "i2c transfer failed.");
578 			mutex_unlock(&d->i2c_mutex);
579 			return -EAGAIN;
580 		}
581 
582 		if (read) {
583 			if (read_o)
584 				memcpy(msg[i].buf, &ibuf[1], msg[i].len);
585 			else {
586 				memcpy(msg[i+1].buf, &ibuf[1], msg[i+1].len);
587 				i++;
588 			}
589 		}
590 	}
591 
592 	mutex_unlock(&d->i2c_mutex);
593 	return i;
594 }
595 
596 static u32 lme2510_i2c_func(struct i2c_adapter *adapter)
597 {
598 	return I2C_FUNC_I2C;
599 }
600 
601 static struct i2c_algorithm lme2510_i2c_algo = {
602 	.master_xfer   = lme2510_i2c_xfer,
603 	.functionality = lme2510_i2c_func,
604 };
605 
606 static int lme2510_streaming_ctrl(struct dvb_frontend *fe, int onoff)
607 {
608 	struct dvb_usb_adapter *adap = fe_to_adap(fe);
609 	struct dvb_usb_device *d = adap_to_d(adap);
610 	struct lme2510_state *st = adap_to_priv(adap);
611 	static u8 clear_reg_3[] = LME_ALL_PIDS;
612 	static u8 rbuf[1];
613 	int ret = 0, rlen = sizeof(rbuf);
614 
615 	deb_info(1, "STM  (%02x)", onoff);
616 
617 	/* Streaming is started by FE_HAS_LOCK */
618 	if (onoff == 1)
619 		st->stream_on = 1;
620 	else {
621 		deb_info(1, "STM Steam Off");
622 		/* mutex is here only to avoid collision with I2C */
623 		mutex_lock(&d->i2c_mutex);
624 
625 		ret = lme2510_usb_talk(d, clear_reg_3,
626 				sizeof(clear_reg_3), rbuf, rlen);
627 		st->stream_on = 0;
628 		st->i2c_talk_onoff = 1;
629 
630 		mutex_unlock(&d->i2c_mutex);
631 	}
632 
633 	return (ret < 0) ? -ENODEV : 0;
634 }
635 
636 static u8 check_sum(u8 *p, u8 len)
637 {
638 	u8 sum = 0;
639 	while (len--)
640 		sum += *p++;
641 	return sum;
642 }
643 
644 static int lme2510_download_firmware(struct dvb_usb_device *d,
645 					const struct firmware *fw)
646 {
647 	int ret = 0;
648 	u8 *data;
649 	u16 j, wlen, len_in, start, end;
650 	u8 packet_size, dlen, i;
651 	u8 *fw_data;
652 
653 	packet_size = 0x31;
654 	len_in = 1;
655 
656 	data = kzalloc(128, GFP_KERNEL);
657 	if (!data) {
658 		info("FRM Could not start Firmware Download"\
659 			"(Buffer allocation failed)");
660 		return -ENOMEM;
661 	}
662 
663 	info("FRM Starting Firmware Download");
664 
665 	for (i = 1; i < 3; i++) {
666 		start = (i == 1) ? 0 : 512;
667 		end = (i == 1) ? 512 : fw->size;
668 		for (j = start; j < end; j += (packet_size+1)) {
669 			fw_data = (u8 *)(fw->data + j);
670 			if ((end - j) > packet_size) {
671 				data[0] = i;
672 				dlen = packet_size;
673 			} else {
674 				data[0] = i | 0x80;
675 				dlen = (u8)(end - j)-1;
676 			}
677 			data[1] = dlen;
678 			memcpy(&data[2], fw_data, dlen+1);
679 			wlen = (u8) dlen + 4;
680 			data[wlen-1] = check_sum(fw_data, dlen+1);
681 			deb_info(1, "Data S=%02x:E=%02x CS= %02x", data[3],
682 				data[dlen+2], data[dlen+3]);
683 			lme2510_usb_talk(d, data, wlen, data, len_in);
684 			ret |= (data[0] == 0x88) ? 0 : -1;
685 		}
686 	}
687 
688 	data[0] = 0x8a;
689 	len_in = 1;
690 	msleep(2000);
691 	lme2510_usb_talk(d, data, len_in, data, len_in);
692 	msleep(400);
693 
694 	if (ret < 0)
695 		info("FRM Firmware Download Failed (%04x)" , ret);
696 	else
697 		info("FRM Firmware Download Completed - Resetting Device");
698 
699 	kfree(data);
700 	return RECONNECTS_USB;
701 }
702 
703 static void lme_coldreset(struct dvb_usb_device *d)
704 {
705 	u8 data[1] = {0};
706 	data[0] = 0x0a;
707 	info("FRM Firmware Cold Reset");
708 
709 	lme2510_usb_talk(d, data, sizeof(data), data, sizeof(data));
710 
711 	return;
712 }
713 
714 static const char fw_c_s7395[] = LME2510_C_S7395;
715 static const char fw_c_lg[] = LME2510_C_LG;
716 static const char fw_c_s0194[] = LME2510_C_S0194;
717 static const char fw_c_rs2000[] = LME2510_C_RS2000;
718 static const char fw_lg[] = LME2510_LG;
719 static const char fw_s0194[] = LME2510_S0194;
720 
721 static const char *lme_firmware_switch(struct dvb_usb_device *d, int cold)
722 {
723 	struct lme2510_state *st = d->priv;
724 	struct usb_device *udev = d->udev;
725 	const struct firmware *fw = NULL;
726 	const char *fw_lme;
727 	int ret = 0;
728 
729 	cold = (cold > 0) ? (cold & 1) : 0;
730 
731 	switch (le16_to_cpu(udev->descriptor.idProduct)) {
732 	case 0x1122:
733 		switch (st->dvb_usb_lme2510_firmware) {
734 		default:
735 		case TUNER_S0194:
736 			fw_lme = fw_s0194;
737 			ret = request_firmware(&fw, fw_lme, &udev->dev);
738 			if (ret == 0) {
739 				st->dvb_usb_lme2510_firmware = TUNER_S0194;
740 				cold = 0;
741 				break;
742 			}
743 			/* fall through */
744 		case TUNER_LG:
745 			fw_lme = fw_lg;
746 			ret = request_firmware(&fw, fw_lme, &udev->dev);
747 			if (ret == 0) {
748 				st->dvb_usb_lme2510_firmware = TUNER_LG;
749 				break;
750 			}
751 			st->dvb_usb_lme2510_firmware = TUNER_DEFAULT;
752 			break;
753 		}
754 		break;
755 	case 0x1120:
756 		switch (st->dvb_usb_lme2510_firmware) {
757 		default:
758 		case TUNER_S7395:
759 			fw_lme = fw_c_s7395;
760 			ret = request_firmware(&fw, fw_lme, &udev->dev);
761 			if (ret == 0) {
762 				st->dvb_usb_lme2510_firmware = TUNER_S7395;
763 				cold = 0;
764 				break;
765 			}
766 			/* fall through */
767 		case TUNER_LG:
768 			fw_lme = fw_c_lg;
769 			ret = request_firmware(&fw, fw_lme, &udev->dev);
770 			if (ret == 0) {
771 				st->dvb_usb_lme2510_firmware = TUNER_LG;
772 				break;
773 			}
774 			/* fall through */
775 		case TUNER_S0194:
776 			fw_lme = fw_c_s0194;
777 			ret = request_firmware(&fw, fw_lme, &udev->dev);
778 			if (ret == 0) {
779 				st->dvb_usb_lme2510_firmware = TUNER_S0194;
780 				break;
781 			}
782 			st->dvb_usb_lme2510_firmware = TUNER_DEFAULT;
783 			cold = 0;
784 			break;
785 		}
786 		break;
787 	case 0x22f0:
788 		fw_lme = fw_c_rs2000;
789 		st->dvb_usb_lme2510_firmware = TUNER_RS2000;
790 		break;
791 	default:
792 		fw_lme = fw_c_s7395;
793 	}
794 
795 	release_firmware(fw);
796 
797 	if (cold) {
798 		dvb_usb_lme2510_firmware = st->dvb_usb_lme2510_firmware;
799 		info("FRM Changing to %s firmware", fw_lme);
800 		lme_coldreset(d);
801 		return NULL;
802 	}
803 
804 	return fw_lme;
805 }
806 
807 static int lme2510_kill_urb(struct usb_data_stream *stream)
808 {
809 	int i;
810 
811 	for (i = 0; i < stream->urbs_submitted; i++) {
812 		deb_info(3, "killing URB no. %d.", i);
813 		/* stop the URB */
814 		usb_kill_urb(stream->urb_list[i]);
815 	}
816 	stream->urbs_submitted = 0;
817 
818 	return 0;
819 }
820 
821 static struct tda10086_config tda10086_config = {
822 	.demod_address = 0x0e,
823 	.invert = 0,
824 	.diseqc_tone = 1,
825 	.xtal_freq = TDA10086_XTAL_16M,
826 };
827 
828 static struct stv0288_config lme_config = {
829 	.demod_address = 0x68,
830 	.min_delay_ms = 15,
831 	.inittab = s7395_inittab,
832 };
833 
834 static struct ix2505v_config lme_tuner = {
835 	.tuner_address = 0x60,
836 	.min_delay_ms = 100,
837 	.tuner_gain = 0x0,
838 	.tuner_chargepump = 0x3,
839 };
840 
841 static struct stv0299_config sharp_z0194_config = {
842 	.demod_address = 0x68,
843 	.inittab = sharp_z0194a_inittab,
844 	.mclk = 88000000UL,
845 	.invert = 0,
846 	.skip_reinit = 0,
847 	.lock_output = STV0299_LOCKOUTPUT_1,
848 	.volt13_op0_op1 = STV0299_VOLT13_OP1,
849 	.min_delay_ms = 100,
850 	.set_symbol_rate = sharp_z0194a_set_symbol_rate,
851 };
852 
853 static struct m88rs2000_config m88rs2000_config = {
854 	.demod_addr = 0x68
855 };
856 
857 static struct ts2020_config ts2020_config = {
858 	.tuner_address = 0x60,
859 	.clk_out_div = 7,
860 	.dont_poll = true
861 };
862 
863 static int dm04_lme2510_set_voltage(struct dvb_frontend *fe,
864 				    enum fe_sec_voltage voltage)
865 {
866 	struct dvb_usb_device *d = fe_to_d(fe);
867 	struct lme2510_state *st = fe_to_priv(fe);
868 	static u8 voltage_low[] = LME_VOLTAGE_L;
869 	static u8 voltage_high[] = LME_VOLTAGE_H;
870 	static u8 rbuf[1];
871 	int ret = 0, len = 3, rlen = 1;
872 
873 	mutex_lock(&d->i2c_mutex);
874 
875 	switch (voltage) {
876 	case SEC_VOLTAGE_18:
877 		ret |= lme2510_usb_talk(d,
878 			voltage_high, len, rbuf, rlen);
879 		break;
880 
881 	case SEC_VOLTAGE_OFF:
882 	case SEC_VOLTAGE_13:
883 	default:
884 		ret |= lme2510_usb_talk(d,
885 				voltage_low, len, rbuf, rlen);
886 		break;
887 	}
888 
889 	mutex_unlock(&d->i2c_mutex);
890 
891 	if (st->tuner_config == TUNER_RS2000)
892 		if (st->fe_set_voltage)
893 			st->fe_set_voltage(fe, voltage);
894 
895 
896 	return (ret < 0) ? -ENODEV : 0;
897 }
898 
899 static int dm04_read_status(struct dvb_frontend *fe, enum fe_status *status)
900 {
901 	struct dvb_usb_device *d = fe_to_d(fe);
902 	struct lme2510_state *st = d->priv;
903 	int ret = 0;
904 
905 	if (st->i2c_talk_onoff) {
906 		if (st->fe_read_status) {
907 			ret = st->fe_read_status(fe, status);
908 			if (ret < 0)
909 				return ret;
910 		}
911 
912 		st->lock_status = *status;
913 
914 		if (*status & FE_HAS_LOCK && st->stream_on) {
915 			mutex_lock(&d->i2c_mutex);
916 
917 			st->i2c_talk_onoff = 0;
918 			ret = lme2510_stream_restart(d);
919 
920 			mutex_unlock(&d->i2c_mutex);
921 		}
922 
923 		return ret;
924 	}
925 
926 	/* Timeout of interrupt reached on RS2000 */
927 	if (st->tuner_config == TUNER_RS2000 &&
928 	    time_after(jiffies, st->int_urb_due))
929 		st->lock_status &= ~FE_HAS_LOCK;
930 
931 	*status = st->lock_status;
932 
933 	if (!(*status & FE_HAS_LOCK)) {
934 		struct dvb_usb_adapter *adap = fe_to_adap(fe);
935 
936 		st->i2c_talk_onoff = 1;
937 
938 		lme2510_update_stats(adap);
939 	}
940 
941 	return ret;
942 }
943 
944 static int dm04_read_signal_strength(struct dvb_frontend *fe, u16 *strength)
945 {
946 	struct dtv_frontend_properties *c = &fe->dtv_property_cache;
947 	struct lme2510_state *st = fe_to_priv(fe);
948 
949 	if (st->fe_read_signal_strength && !st->stream_on)
950 		return st->fe_read_signal_strength(fe, strength);
951 
952 	if (c->strength.stat[0].scale == FE_SCALE_RELATIVE)
953 		*strength = (u16)c->strength.stat[0].uvalue;
954 	else
955 		*strength = 0;
956 
957 	return 0;
958 }
959 
960 static int dm04_read_snr(struct dvb_frontend *fe, u16 *snr)
961 {
962 	struct dtv_frontend_properties *c = &fe->dtv_property_cache;
963 	struct lme2510_state *st = fe_to_priv(fe);
964 
965 	if (st->fe_read_snr && !st->stream_on)
966 		return st->fe_read_snr(fe, snr);
967 
968 	if (c->cnr.stat[0].scale == FE_SCALE_RELATIVE)
969 		*snr = (u16)c->cnr.stat[0].uvalue;
970 	else
971 		*snr = 0;
972 
973 	return 0;
974 }
975 
976 static int dm04_read_ber(struct dvb_frontend *fe, u32 *ber)
977 {
978 	struct lme2510_state *st = fe_to_priv(fe);
979 
980 	if (st->fe_read_ber && !st->stream_on)
981 		return st->fe_read_ber(fe, ber);
982 
983 	*ber = 0;
984 
985 	return 0;
986 }
987 
988 static int dm04_read_ucblocks(struct dvb_frontend *fe, u32 *ucblocks)
989 {
990 	struct lme2510_state *st = fe_to_priv(fe);
991 
992 	if (st->fe_read_ucblocks && !st->stream_on)
993 		return st->fe_read_ucblocks(fe, ucblocks);
994 
995 	*ucblocks = 0;
996 
997 	return 0;
998 }
999 
1000 static int lme_name(struct dvb_usb_adapter *adap)
1001 {
1002 	struct dvb_usb_device *d = adap_to_d(adap);
1003 	struct lme2510_state *st = adap_to_priv(adap);
1004 	const char *desc = d->name;
1005 	char *fe_name[] = {"", " LG TDQY-P001F", " SHARP:BS2F7HZ7395",
1006 				" SHARP:BS2F7HZ0194", " RS2000"};
1007 	char *name = adap->fe[0]->ops.info.name;
1008 
1009 	strlcpy(name, desc, 128);
1010 	strlcat(name, fe_name[st->tuner_config], 128);
1011 
1012 	return 0;
1013 }
1014 
1015 static int dm04_lme2510_frontend_attach(struct dvb_usb_adapter *adap)
1016 {
1017 	struct dvb_usb_device *d = adap_to_d(adap);
1018 	struct lme2510_state *st = d->priv;
1019 	int ret = 0;
1020 
1021 	st->i2c_talk_onoff = 1;
1022 	switch (le16_to_cpu(d->udev->descriptor.idProduct)) {
1023 	case 0x1122:
1024 	case 0x1120:
1025 		st->i2c_gate = 4;
1026 		adap->fe[0] = dvb_attach(tda10086_attach,
1027 			&tda10086_config, &d->i2c_adap);
1028 		if (adap->fe[0]) {
1029 			info("TUN Found Frontend TDA10086");
1030 			st->i2c_tuner_gate_w = 4;
1031 			st->i2c_tuner_gate_r = 4;
1032 			st->i2c_tuner_addr = 0x60;
1033 			st->tuner_config = TUNER_LG;
1034 			if (st->dvb_usb_lme2510_firmware != TUNER_LG) {
1035 				st->dvb_usb_lme2510_firmware = TUNER_LG;
1036 				ret = lme_firmware_switch(d, 1) ? 0 : -ENODEV;
1037 			}
1038 			break;
1039 		}
1040 
1041 		st->i2c_gate = 4;
1042 		adap->fe[0] = dvb_attach(stv0299_attach,
1043 				&sharp_z0194_config, &d->i2c_adap);
1044 		if (adap->fe[0]) {
1045 			info("FE Found Stv0299");
1046 			st->i2c_tuner_gate_w = 4;
1047 			st->i2c_tuner_gate_r = 5;
1048 			st->i2c_tuner_addr = 0x60;
1049 			st->tuner_config = TUNER_S0194;
1050 			if (st->dvb_usb_lme2510_firmware != TUNER_S0194) {
1051 				st->dvb_usb_lme2510_firmware = TUNER_S0194;
1052 				ret = lme_firmware_switch(d, 1) ? 0 : -ENODEV;
1053 			}
1054 			break;
1055 		}
1056 
1057 		st->i2c_gate = 5;
1058 		adap->fe[0] = dvb_attach(stv0288_attach, &lme_config,
1059 			&d->i2c_adap);
1060 
1061 		if (adap->fe[0]) {
1062 			info("FE Found Stv0288");
1063 			st->i2c_tuner_gate_w = 4;
1064 			st->i2c_tuner_gate_r = 5;
1065 			st->i2c_tuner_addr = 0x60;
1066 			st->tuner_config = TUNER_S7395;
1067 			if (st->dvb_usb_lme2510_firmware != TUNER_S7395) {
1068 				st->dvb_usb_lme2510_firmware = TUNER_S7395;
1069 				ret = lme_firmware_switch(d, 1) ? 0 : -ENODEV;
1070 			}
1071 			break;
1072 		}
1073 	case 0x22f0:
1074 		st->i2c_gate = 5;
1075 		adap->fe[0] = dvb_attach(m88rs2000_attach,
1076 			&m88rs2000_config, &d->i2c_adap);
1077 
1078 		if (adap->fe[0]) {
1079 			info("FE Found M88RS2000");
1080 			dvb_attach(ts2020_attach, adap->fe[0], &ts2020_config,
1081 					&d->i2c_adap);
1082 			st->i2c_tuner_gate_w = 5;
1083 			st->i2c_tuner_gate_r = 5;
1084 			st->i2c_tuner_addr = 0x60;
1085 			st->tuner_config = TUNER_RS2000;
1086 			st->fe_set_voltage =
1087 				adap->fe[0]->ops.set_voltage;
1088 		}
1089 		break;
1090 	}
1091 
1092 	if (adap->fe[0] == NULL) {
1093 		info("DM04/QQBOX Not Powered up or not Supported");
1094 		return -ENODEV;
1095 	}
1096 
1097 	if (ret) {
1098 		if (adap->fe[0]) {
1099 			dvb_frontend_detach(adap->fe[0]);
1100 			adap->fe[0] = NULL;
1101 		}
1102 		d->rc_map = NULL;
1103 		return -ENODEV;
1104 	}
1105 
1106 	st->fe_read_status = adap->fe[0]->ops.read_status;
1107 	st->fe_read_signal_strength = adap->fe[0]->ops.read_signal_strength;
1108 	st->fe_read_snr = adap->fe[0]->ops.read_snr;
1109 	st->fe_read_ber = adap->fe[0]->ops.read_ber;
1110 	st->fe_read_ucblocks = adap->fe[0]->ops.read_ucblocks;
1111 
1112 	adap->fe[0]->ops.read_status = dm04_read_status;
1113 	adap->fe[0]->ops.read_signal_strength = dm04_read_signal_strength;
1114 	adap->fe[0]->ops.read_snr = dm04_read_snr;
1115 	adap->fe[0]->ops.read_ber = dm04_read_ber;
1116 	adap->fe[0]->ops.read_ucblocks = dm04_read_ucblocks;
1117 	adap->fe[0]->ops.set_voltage = dm04_lme2510_set_voltage;
1118 
1119 	ret = lme_name(adap);
1120 	return ret;
1121 }
1122 
1123 static int dm04_lme2510_tuner(struct dvb_usb_adapter *adap)
1124 {
1125 	struct dvb_usb_device *d = adap_to_d(adap);
1126 	struct lme2510_state *st = adap_to_priv(adap);
1127 	char *tun_msg[] = {"", "TDA8263", "IX2505V", "DVB_PLL_OPERA", "RS2000"};
1128 	int ret = 0;
1129 
1130 	switch (st->tuner_config) {
1131 	case TUNER_LG:
1132 		if (dvb_attach(tda826x_attach, adap->fe[0], 0x60,
1133 			&d->i2c_adap, 1))
1134 			ret = st->tuner_config;
1135 		break;
1136 	case TUNER_S7395:
1137 		if (dvb_attach(ix2505v_attach , adap->fe[0], &lme_tuner,
1138 			&d->i2c_adap))
1139 			ret = st->tuner_config;
1140 		break;
1141 	case TUNER_S0194:
1142 		if (dvb_attach(dvb_pll_attach , adap->fe[0], 0x60,
1143 			&d->i2c_adap, DVB_PLL_OPERA1))
1144 			ret = st->tuner_config;
1145 		break;
1146 	case TUNER_RS2000:
1147 		ret = st->tuner_config;
1148 		break;
1149 	default:
1150 		break;
1151 	}
1152 
1153 	if (ret)
1154 		info("TUN Found %s tuner", tun_msg[ret]);
1155 	else {
1156 		info("TUN No tuner found --- resetting device");
1157 		lme_coldreset(d);
1158 		return -ENODEV;
1159 	}
1160 
1161 	/* Start the Interrupt*/
1162 	ret = lme2510_int_read(adap);
1163 	if (ret < 0) {
1164 		info("INT Unable to start Interrupt Service");
1165 		return -ENODEV;
1166 	}
1167 
1168 	return ret;
1169 }
1170 
1171 static int lme2510_powerup(struct dvb_usb_device *d, int onoff)
1172 {
1173 	struct lme2510_state *st = d->priv;
1174 	static u8 lnb_on[] = LNB_ON;
1175 	static u8 lnb_off[] = LNB_OFF;
1176 	static u8 rbuf[1];
1177 	int ret = 0, len = 3, rlen = 1;
1178 
1179 	mutex_lock(&d->i2c_mutex);
1180 
1181 	if (onoff)
1182 		ret = lme2510_usb_talk(d, lnb_on, len, rbuf, rlen);
1183 	else
1184 		ret = lme2510_usb_talk(d, lnb_off, len, rbuf, rlen);
1185 
1186 	st->i2c_talk_onoff = 1;
1187 
1188 	mutex_unlock(&d->i2c_mutex);
1189 
1190 	return ret;
1191 }
1192 
1193 static int lme2510_get_adapter_count(struct dvb_usb_device *d)
1194 {
1195 	return 1;
1196 }
1197 
1198 static int lme2510_identify_state(struct dvb_usb_device *d, const char **name)
1199 {
1200 	struct lme2510_state *st = d->priv;
1201 
1202 	usb_reset_configuration(d->udev);
1203 
1204 	usb_set_interface(d->udev,
1205 		d->props->bInterfaceNumber, 1);
1206 
1207 	st->dvb_usb_lme2510_firmware = dvb_usb_lme2510_firmware;
1208 
1209 	if (lme2510_return_status(d) == 0x44) {
1210 		*name = lme_firmware_switch(d, 0);
1211 		return COLD;
1212 	}
1213 
1214 	return 0;
1215 }
1216 
1217 static int lme2510_get_stream_config(struct dvb_frontend *fe, u8 *ts_type,
1218 		struct usb_data_stream_properties *stream)
1219 {
1220 	struct dvb_usb_adapter *adap = fe_to_adap(fe);
1221 	struct dvb_usb_device *d;
1222 
1223 	if (adap == NULL)
1224 		return 0;
1225 
1226 	d = adap_to_d(adap);
1227 
1228 	/* Turn PID filter on the fly by module option */
1229 	if (pid_filter == 2) {
1230 		adap->pid_filtering  = true;
1231 		adap->max_feed_count = 15;
1232 	}
1233 
1234 	if (!(le16_to_cpu(d->udev->descriptor.idProduct)
1235 		== 0x1122))
1236 		stream->endpoint = 0x8;
1237 
1238 	return 0;
1239 }
1240 
1241 static int lme2510_get_rc_config(struct dvb_usb_device *d,
1242 	struct dvb_usb_rc *rc)
1243 {
1244 	rc->allowed_protos = RC_BIT_NEC;
1245 	return 0;
1246 }
1247 
1248 static void *lme2510_exit_int(struct dvb_usb_device *d)
1249 {
1250 	struct lme2510_state *st = d->priv;
1251 	struct dvb_usb_adapter *adap = &d->adapter[0];
1252 	void *buffer = NULL;
1253 
1254 	if (adap != NULL) {
1255 		lme2510_kill_urb(&adap->stream);
1256 	}
1257 
1258 	if (st->usb_buffer != NULL) {
1259 		st->i2c_talk_onoff = 1;
1260 		st->signal_level = 0;
1261 		st->signal_sn = 0;
1262 		buffer = st->usb_buffer;
1263 	}
1264 
1265 	if (st->lme_urb != NULL) {
1266 		usb_kill_urb(st->lme_urb);
1267 		usb_free_coherent(d->udev, 128, st->buffer,
1268 				  st->lme_urb->transfer_dma);
1269 		info("Interrupt Service Stopped");
1270 	}
1271 
1272 	return buffer;
1273 }
1274 
1275 static void lme2510_exit(struct dvb_usb_device *d)
1276 {
1277 	void *usb_buffer;
1278 
1279 	if (d != NULL) {
1280 		usb_buffer = lme2510_exit_int(d);
1281 		kfree(usb_buffer);
1282 	}
1283 }
1284 
1285 static struct dvb_usb_device_properties lme2510_props = {
1286 	.driver_name = KBUILD_MODNAME,
1287 	.owner = THIS_MODULE,
1288 	.bInterfaceNumber = 0,
1289 	.adapter_nr = adapter_nr,
1290 	.size_of_priv = sizeof(struct lme2510_state),
1291 
1292 	.download_firmware = lme2510_download_firmware,
1293 
1294 	.power_ctrl       = lme2510_powerup,
1295 	.identify_state   = lme2510_identify_state,
1296 	.i2c_algo         = &lme2510_i2c_algo,
1297 
1298 	.frontend_attach  = dm04_lme2510_frontend_attach,
1299 	.tuner_attach = dm04_lme2510_tuner,
1300 	.get_stream_config = lme2510_get_stream_config,
1301 	.get_adapter_count = lme2510_get_adapter_count,
1302 	.streaming_ctrl   = lme2510_streaming_ctrl,
1303 
1304 	.get_rc_config = lme2510_get_rc_config,
1305 
1306 	.exit = lme2510_exit,
1307 	.adapter = {
1308 		{
1309 			.caps = DVB_USB_ADAP_HAS_PID_FILTER|
1310 				DVB_USB_ADAP_PID_FILTER_CAN_BE_TURNED_OFF,
1311 			.pid_filter_count = 15,
1312 			.pid_filter = lme2510_pid_filter,
1313 			.pid_filter_ctrl  = lme2510_pid_filter_ctrl,
1314 			.stream =
1315 			DVB_USB_STREAM_BULK(0x86, 10, 4096),
1316 		},
1317 		{
1318 		}
1319 	},
1320 };
1321 
1322 static const struct usb_device_id lme2510_id_table[] = {
1323 	{	DVB_USB_DEVICE(0x3344, 0x1122, &lme2510_props,
1324 		"DM04_LME2510_DVB-S", RC_MAP_LME2510)	},
1325 	{	DVB_USB_DEVICE(0x3344, 0x1120, &lme2510_props,
1326 		"DM04_LME2510C_DVB-S", RC_MAP_LME2510)	},
1327 	{	DVB_USB_DEVICE(0x3344, 0x22f0, &lme2510_props,
1328 		"DM04_LME2510C_DVB-S RS2000", RC_MAP_LME2510)	},
1329 	{}		/* Terminating entry */
1330 };
1331 
1332 MODULE_DEVICE_TABLE(usb, lme2510_id_table);
1333 
1334 static struct usb_driver lme2510_driver = {
1335 	.name		= KBUILD_MODNAME,
1336 	.probe		= dvb_usbv2_probe,
1337 	.disconnect	= dvb_usbv2_disconnect,
1338 	.id_table	= lme2510_id_table,
1339 	.no_dynamic_id = 1,
1340 	.soft_unbind = 1,
1341 };
1342 
1343 module_usb_driver(lme2510_driver);
1344 
1345 MODULE_AUTHOR("Malcolm Priestley <tvboxspy@gmail.com>");
1346 MODULE_DESCRIPTION("LME2510(C) DVB-S USB2.0");
1347 MODULE_VERSION("2.06");
1348 MODULE_LICENSE("GPL");
1349 MODULE_FIRMWARE(LME2510_C_S7395);
1350 MODULE_FIRMWARE(LME2510_C_LG);
1351 MODULE_FIRMWARE(LME2510_C_S0194);
1352 MODULE_FIRMWARE(LME2510_C_RS2000);
1353 MODULE_FIRMWARE(LME2510_LG);
1354 MODULE_FIRMWARE(LME2510_S0194);
1355 
1356