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