1 /* DVB USB compliant linux driver for
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
9 * MVB7395 (LME2510C+SHARP:BS2F7HZ7395)
10 * SHARP:BS2F7HZ7395 = (STV0288+Sharp IX2505V)
12 * MV001F (LME2510+LGTDQY-P001F)
13 * LG TDQY - P001F =(TDA8263 + TDA10086H)
15 * MVB0001F (LME2510C+LGTDQT-P001F)
17 * MV0194 (LME2510+SHARP:BS2F7HZ0194)
18 * SHARP:BS2F7HZ0194 = (STV0299+IX2410)
20 * MVB0194 (LME2510C+SHARP0194)
22 * LME2510C + M88RS2000
24 * For firmware see Documentation/dvb/lmedm04.txt
27 * 0xd0 - STV0288 - Demodulator
28 * 0xc0 - Sharp IX2505V - Tuner
30 * 0x1c - TDA10086 - Demodulator
31 * 0xc0 - TDA8263 - Tuner
33 * 0xd0 - STV0299 - Demodulator
34 * 0xc0 - IX2410 - Tuner
37 * VID = 3344 PID LME2510=1122 LME2510C=1120
39 * Copyright (C) 2010 Malcolm Priestley (tvboxspy@gmail.com)
40 * LME2510(C)(C) Leaguerme (Shenzhen) MicroElectronics Co., Ltd.
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.
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.
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.
56 * see Documentation/dvb/README.dvb-usb for more information
59 * LME2510: Non Intel USB chipsets fail to maintain High Speed on
62 * QQbox suffers from noise on LNB voltage.
64 * LME2510: SHARP:BS2F7HZ0194(MV0194) cannot cold reset and share system
65 * with other tuners. After a cold reset streaming will not start.
67 * M88RS2000 suffers from loss of lock.
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>
83 #include "m88rs2000.h"
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";
95 static int dvb_usb_lme2510_debug
;
96 #define lme_debug(var, level, args...) do { \
98 pr_debug(DVB_USB_LOG_PREFIX": " args); \
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)
107 module_param_named(debug
, dvb_usb_lme2510_debug
, int, 0644);
108 MODULE_PARM_DESC(debug
, "set debugging level (1=info (or-able)).");
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");
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");
119 DVB_DEFINE_MOD_OPT_ADAPTER_NR(adapter_nr
);
121 #define TUNER_DEFAULT 0x0
123 #define TUNER_S7395 0x2
124 #define TUNER_S0194 0x3
125 #define TUNER_RS2000 0x4
127 struct lme2510_state
{
128 unsigned long int_urb_due
;
129 enum fe_status lock_status
;
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
;
156 static int lme2510_bulk_write(struct usb_device
*dev
,
157 u8
*snd
, int len
, u8 pipe
)
161 ret
= usb_bulk_msg(dev
, usb_sndbulkpipe(dev
, pipe
),
162 snd
, len
, &actual_l
, 100);
166 static int lme2510_bulk_read(struct usb_device
*dev
,
167 u8
*rev
, int len
, u8 pipe
)
171 ret
= usb_bulk_msg(dev
, usb_rcvbulkpipe(dev
, pipe
),
172 rev
, len
, &actual_l
, 200);
176 static int lme2510_usb_talk(struct dvb_usb_device
*d
,
177 u8
*wbuf
, int wlen
, u8
*rbuf
, int rlen
)
179 struct lme2510_state
*st
= d
->priv
;
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");
190 buff
= st
->usb_buffer
;
192 ret
= mutex_lock_interruptible(&d
->usb_mutex
);
197 /* the read/write capped at 64 */
198 memcpy(buff
, wbuf
, (wlen
< 64) ? wlen
: 64);
200 ret
|= lme2510_bulk_write(d
->udev
, buff
, wlen
, 0x01);
202 ret
|= lme2510_bulk_read(d
->udev
, buff
, (rlen
< 64) ?
206 memcpy(rbuf
, buff
, rlen
);
208 mutex_unlock(&d
->usb_mutex
);
210 return (ret
< 0) ? -ENODEV
: 0;
213 static int lme2510_stream_restart(struct dvb_usb_device
*d
)
215 struct lme2510_state
*st
= d
->priv
;
216 u8 all_pids
[] = LME_ALL_PIDS
;
217 u8 stream_on
[] = LME_ST_ON_W
;
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
));
229 static int lme2510_enable_pid(struct dvb_usb_device
*d
, u8 index
, u16 pid_out
)
231 struct lme2510_state
*st
= d
->priv
;
232 static u8 pid_buff
[] = LME_ZERO_PID
;
234 u8 pid_no
= index
* 2;
235 u8 pid_len
= pid_no
+ 2;
237 deb_info(1, "PID Setting Pid %04x", pid_out
);
239 if (st
->pid_size
== 0)
240 ret
|= lme2510_stream_restart(d
);
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);
247 if (pid_len
> st
->pid_size
)
248 st
->pid_size
= pid_len
;
249 pid_buff
[7] = 0x80 + st
->pid_size
;
251 ret
|= lme2510_usb_talk(d
, pid_buff
,
252 sizeof(pid_buff
) , rbuf
, sizeof(rbuf
));
255 ret
|= lme2510_stream_restart(d
);
260 /* Convert range from 0x00-0xff to 0x0000-0xffff */
261 #define reg_to_16bits(x) ((x) | ((x) << 8))
263 static void lme2510_update_stats(struct dvb_usb_adapter
*adap
)
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;
273 c
= &fe
->dtv_property_cache
;
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
;
284 if (st
->i2c_talk_onoff
) {
286 c
->strength
.stat
[0].scale
= FE_SCALE_NOT_AVAILABLE
;
288 c
->cnr
.stat
[0].scale
= FE_SCALE_NOT_AVAILABLE
;
292 switch (st
->tuner_config
) {
294 s_tmp
= reg_to_16bits(0xff - st
->signal_level
);
295 c_tmp
= reg_to_16bits(0xff - st
->signal_sn
);
299 s_tmp
= 0xffff - (((st
->signal_level
* 2) << 8) * 5 / 4);
300 c_tmp
= reg_to_16bits((0xff - st
->signal_sn
- 0xa1) * 3);
303 s_tmp
= reg_to_16bits(st
->signal_level
);
304 c_tmp
= reg_to_16bits(st
->signal_sn
);
308 c
->strength
.stat
[0].scale
= FE_SCALE_RELATIVE
;
309 c
->strength
.stat
[0].uvalue
= (u64
)s_tmp
;
312 c
->cnr
.stat
[0].scale
= FE_SCALE_RELATIVE
;
313 c
->cnr
.stat
[0].uvalue
= (u64
)c_tmp
;
316 static void lme2510_int_response(struct urb
*lme_urb
)
318 struct dvb_usb_adapter
*adap
= lme_urb
->context
;
319 struct lme2510_state
*st
= adap_to_priv(adap
);
320 static u8
*ibuf
, *rbuf
;
325 switch (lme_urb
->status
) {
334 info("Error %x", lme_urb
->status
);
338 rbuf
= (u8
*) lme_urb
->transfer_buffer
;
340 offset
= ((lme_urb
->actual_length
/8) > 4)
341 ? 4 : (lme_urb
->actual_length
/8) ;
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]);
350 debug_data_snipet(1, "INT Remote data snipet", ibuf
);
351 if (!adap_to_d(adap
)->rc_dev
)
354 key
= RC_SCANCODE_NEC32(ibuf
[2] << 24 |
359 deb_info(1, "INT Key = 0x%08x", key
);
360 rc_keydown(adap_to_d(adap
)->rc_dev
, RC_TYPE_NEC
, key
, 0);
363 switch (st
->tuner_config
) {
365 signal_lock
= ibuf
[2] & BIT(5);
366 st
->signal_level
= ibuf
[4];
367 st
->signal_sn
= ibuf
[3];
368 st
->time_key
= ibuf
[7];
372 /* Tweak for earlier firmware*/
373 if (ibuf
[1] == 0x03) {
374 signal_lock
= ibuf
[2] & BIT(4);
375 st
->signal_level
= ibuf
[3];
376 st
->signal_sn
= ibuf
[4];
378 st
->signal_level
= ibuf
[4];
379 st
->signal_sn
= ibuf
[5];
383 signal_lock
= ibuf
[2] & 0xee;
384 st
->signal_level
= ibuf
[5];
385 st
->signal_sn
= ibuf
[4];
386 st
->time_key
= ibuf
[7];
391 /* Interrupt will also throw just BIT 0 as lock */
392 signal_lock
|= ibuf
[2] & BIT(0);
395 st
->lock_status
&= ~FE_HAS_LOCK
;
397 lme2510_update_stats(adap
);
399 debug_data_snipet(5, "INT Remote data snipet in", ibuf
);
402 debug_data_snipet(1, "INT Control data snipet", ibuf
);
405 debug_data_snipet(1, "INT Unknown data snipet", ibuf
);
410 usb_submit_urb(lme_urb
, GFP_ATOMIC
);
412 /* Interrupt urb is due every 48 msecs while streaming the buffer
413 * stores up to 4 periods if missed. Allow 200 msec for next interrupt.
415 st
->int_urb_due
= jiffies
+ msecs_to_jiffies(200);
418 static int lme2510_int_read(struct dvb_usb_adapter
*adap
)
420 struct dvb_usb_device
*d
= adap_to_d(adap
);
421 struct lme2510_state
*lme_int
= adap_to_priv(adap
);
422 struct usb_host_endpoint
*ep
;
424 lme_int
->lme_urb
= usb_alloc_urb(0, GFP_ATOMIC
);
426 if (lme_int
->lme_urb
== NULL
)
429 lme_int
->buffer
= usb_alloc_coherent(d
->udev
, 128, GFP_ATOMIC
,
430 &lme_int
->lme_urb
->transfer_dma
);
432 if (lme_int
->buffer
== NULL
)
435 usb_fill_int_urb(lme_int
->lme_urb
,
437 usb_rcvintpipe(d
->udev
, 0xa),
440 lme2510_int_response
,
444 /* Quirk of pipe reporting PIPE_BULK but behaves as interrupt */
445 ep
= usb_pipe_endpoint(d
->udev
, lme_int
->lme_urb
->pipe
);
447 if (usb_endpoint_type(&ep
->desc
) == USB_ENDPOINT_XFER_BULK
)
448 lme_int
->lme_urb
->pipe
= usb_rcvbulkpipe(d
->udev
, 0xa),
450 lme_int
->lme_urb
->transfer_flags
|= URB_NO_TRANSFER_DMA_MAP
;
452 usb_submit_urb(lme_int
->lme_urb
, GFP_ATOMIC
);
453 info("INT Interrupt Service Started");
458 static int lme2510_pid_filter_ctrl(struct dvb_usb_adapter
*adap
, int onoff
)
460 struct dvb_usb_device
*d
= adap_to_d(adap
);
461 struct lme2510_state
*st
= adap_to_priv(adap
);
462 static u8 clear_pid_reg
[] = LME_ALL_PIDS
;
466 deb_info(1, "PID Clearing Filter");
468 mutex_lock(&d
->i2c_mutex
);
471 ret
|= lme2510_usb_talk(d
, clear_pid_reg
,
472 sizeof(clear_pid_reg
), rbuf
, sizeof(rbuf
));
479 mutex_unlock(&d
->i2c_mutex
);
484 static int lme2510_pid_filter(struct dvb_usb_adapter
*adap
, int index
, u16 pid
,
487 struct dvb_usb_device
*d
= adap_to_d(adap
);
490 deb_info(3, "%s PID=%04x Index=%04x onoff=%02x", __func__
,
494 mutex_lock(&d
->i2c_mutex
);
495 ret
|= lme2510_enable_pid(d
, index
, pid
);
496 mutex_unlock(&d
->i2c_mutex
);
504 static int lme2510_return_status(struct dvb_usb_device
*d
)
509 data
= kzalloc(10, GFP_KERNEL
);
513 ret
|= usb_control_msg(d
->udev
, usb_rcvctrlpipe(d
->udev
, 0),
514 0x06, 0x80, 0x0302, 0x00, data
, 0x0006, 200);
515 info("Firmware Status: %x (%x)", ret
, data
[2]);
517 ret
= (ret
< 0) ? -ENODEV
: data
[2];
522 static int lme2510_msg(struct dvb_usb_device
*d
,
523 u8
*wbuf
, int wlen
, u8
*rbuf
, int rlen
)
525 struct lme2510_state
*st
= d
->priv
;
527 st
->i2c_talk_onoff
= 1;
529 return lme2510_usb_talk(d
, wbuf
, wlen
, rbuf
, rlen
);
532 static int lme2510_i2c_xfer(struct i2c_adapter
*adap
, struct i2c_msg msg
[],
535 struct dvb_usb_device
*d
= i2c_get_adapdata(adap
);
536 struct lme2510_state
*st
= d
->priv
;
537 static u8 obuf
[64], ibuf
[64];
540 u8 gate
= st
->i2c_gate
;
542 mutex_lock(&d
->i2c_mutex
);
547 for (i
= 0; i
< num
; i
++) {
548 read_o
= msg
[i
].flags
& I2C_M_RD
;
549 read
= i
+ 1 < num
&& msg
[i
+ 1].flags
& I2C_M_RD
;
551 gate
= (msg
[i
].addr
== st
->i2c_tuner_addr
)
552 ? (read
) ? st
->i2c_tuner_gate_r
553 : st
->i2c_tuner_gate_w
555 obuf
[0] = gate
| (read
<< 7);
558 obuf
[1] = (read
) ? 2 : msg
[i
].len
+ 1;
560 obuf
[1] = msg
[i
].len
+ read
+ 1;
562 obuf
[2] = msg
[i
].addr
<< 1;
568 memcpy(&obuf
[3], msg
[i
].buf
, msg
[i
].len
);
569 obuf
[msg
[i
].len
+3] = msg
[i
+1].len
;
573 memcpy(&obuf
[3], msg
[i
].buf
, msg
[i
].len
);
577 if (lme2510_msg(d
, obuf
, len
, ibuf
, 64) < 0) {
578 deb_info(1, "i2c transfer failed.");
579 mutex_unlock(&d
->i2c_mutex
);
585 memcpy(msg
[i
].buf
, &ibuf
[1], msg
[i
].len
);
587 memcpy(msg
[i
+1].buf
, &ibuf
[1], msg
[i
+1].len
);
593 mutex_unlock(&d
->i2c_mutex
);
597 static u32
lme2510_i2c_func(struct i2c_adapter
*adapter
)
602 static struct i2c_algorithm lme2510_i2c_algo
= {
603 .master_xfer
= lme2510_i2c_xfer
,
604 .functionality
= lme2510_i2c_func
,
607 static int lme2510_streaming_ctrl(struct dvb_frontend
*fe
, int onoff
)
609 struct dvb_usb_adapter
*adap
= fe_to_adap(fe
);
610 struct dvb_usb_device
*d
= adap_to_d(adap
);
611 struct lme2510_state
*st
= adap_to_priv(adap
);
612 static u8 clear_reg_3
[] = LME_ALL_PIDS
;
614 int ret
= 0, rlen
= sizeof(rbuf
);
616 deb_info(1, "STM (%02x)", onoff
);
618 /* Streaming is started by FE_HAS_LOCK */
622 deb_info(1, "STM Steam Off");
623 /* mutex is here only to avoid collision with I2C */
624 mutex_lock(&d
->i2c_mutex
);
626 ret
= lme2510_usb_talk(d
, clear_reg_3
,
627 sizeof(clear_reg_3
), rbuf
, rlen
);
629 st
->i2c_talk_onoff
= 1;
631 mutex_unlock(&d
->i2c_mutex
);
634 return (ret
< 0) ? -ENODEV
: 0;
637 static u8
check_sum(u8
*p
, u8 len
)
645 static int lme2510_download_firmware(struct dvb_usb_device
*d
,
646 const struct firmware
*fw
)
650 u16 j
, wlen
, len_in
, start
, end
;
651 u8 packet_size
, dlen
, i
;
657 data
= kzalloc(128, GFP_KERNEL
);
659 info("FRM Could not start Firmware Download"\
660 "(Buffer allocation failed)");
664 info("FRM Starting Firmware Download");
666 for (i
= 1; i
< 3; i
++) {
667 start
= (i
== 1) ? 0 : 512;
668 end
= (i
== 1) ? 512 : fw
->size
;
669 for (j
= start
; j
< end
; j
+= (packet_size
+1)) {
670 fw_data
= (u8
*)(fw
->data
+ j
);
671 if ((end
- j
) > packet_size
) {
676 dlen
= (u8
)(end
- j
)-1;
679 memcpy(&data
[2], fw_data
, dlen
+1);
680 wlen
= (u8
) dlen
+ 4;
681 data
[wlen
-1] = check_sum(fw_data
, dlen
+1);
682 deb_info(1, "Data S=%02x:E=%02x CS= %02x", data
[3],
683 data
[dlen
+2], data
[dlen
+3]);
684 lme2510_usb_talk(d
, data
, wlen
, data
, len_in
);
685 ret
|= (data
[0] == 0x88) ? 0 : -1;
692 lme2510_usb_talk(d
, data
, len_in
, data
, len_in
);
696 info("FRM Firmware Download Failed (%04x)" , ret
);
698 info("FRM Firmware Download Completed - Resetting Device");
701 return RECONNECTS_USB
;
704 static void lme_coldreset(struct dvb_usb_device
*d
)
708 info("FRM Firmware Cold Reset");
710 lme2510_usb_talk(d
, data
, sizeof(data
), data
, sizeof(data
));
715 static const char fw_c_s7395
[] = LME2510_C_S7395
;
716 static const char fw_c_lg
[] = LME2510_C_LG
;
717 static const char fw_c_s0194
[] = LME2510_C_S0194
;
718 static const char fw_c_rs2000
[] = LME2510_C_RS2000
;
719 static const char fw_lg
[] = LME2510_LG
;
720 static const char fw_s0194
[] = LME2510_S0194
;
722 static const char *lme_firmware_switch(struct dvb_usb_device
*d
, int cold
)
724 struct lme2510_state
*st
= d
->priv
;
725 struct usb_device
*udev
= d
->udev
;
726 const struct firmware
*fw
= NULL
;
730 cold
= (cold
> 0) ? (cold
& 1) : 0;
732 switch (le16_to_cpu(udev
->descriptor
.idProduct
)) {
734 switch (st
->dvb_usb_lme2510_firmware
) {
738 ret
= request_firmware(&fw
, fw_lme
, &udev
->dev
);
740 st
->dvb_usb_lme2510_firmware
= TUNER_S0194
;
747 ret
= request_firmware(&fw
, fw_lme
, &udev
->dev
);
749 st
->dvb_usb_lme2510_firmware
= TUNER_LG
;
752 st
->dvb_usb_lme2510_firmware
= TUNER_DEFAULT
;
757 switch (st
->dvb_usb_lme2510_firmware
) {
761 ret
= request_firmware(&fw
, fw_lme
, &udev
->dev
);
763 st
->dvb_usb_lme2510_firmware
= TUNER_S7395
;
770 ret
= request_firmware(&fw
, fw_lme
, &udev
->dev
);
772 st
->dvb_usb_lme2510_firmware
= TUNER_LG
;
778 ret
= request_firmware(&fw
, fw_lme
, &udev
->dev
);
780 st
->dvb_usb_lme2510_firmware
= TUNER_S0194
;
783 st
->dvb_usb_lme2510_firmware
= TUNER_DEFAULT
;
789 fw_lme
= fw_c_rs2000
;
790 st
->dvb_usb_lme2510_firmware
= TUNER_RS2000
;
796 release_firmware(fw
);
799 dvb_usb_lme2510_firmware
= st
->dvb_usb_lme2510_firmware
;
800 info("FRM Changing to %s firmware", fw_lme
);
808 static int lme2510_kill_urb(struct usb_data_stream
*stream
)
812 for (i
= 0; i
< stream
->urbs_submitted
; i
++) {
813 deb_info(3, "killing URB no. %d.", i
);
815 usb_kill_urb(stream
->urb_list
[i
]);
817 stream
->urbs_submitted
= 0;
822 static struct tda10086_config tda10086_config
= {
823 .demod_address
= 0x0e,
826 .xtal_freq
= TDA10086_XTAL_16M
,
829 static struct stv0288_config lme_config
= {
830 .demod_address
= 0x68,
832 .inittab
= s7395_inittab
,
835 static struct ix2505v_config lme_tuner
= {
836 .tuner_address
= 0x60,
839 .tuner_chargepump
= 0x3,
842 static struct stv0299_config sharp_z0194_config
= {
843 .demod_address
= 0x68,
844 .inittab
= sharp_z0194a_inittab
,
848 .lock_output
= STV0299_LOCKOUTPUT_1
,
849 .volt13_op0_op1
= STV0299_VOLT13_OP1
,
851 .set_symbol_rate
= sharp_z0194a_set_symbol_rate
,
854 static struct m88rs2000_config m88rs2000_config
= {
858 static struct ts2020_config ts2020_config
= {
859 .tuner_address
= 0x60,
864 static int dm04_lme2510_set_voltage(struct dvb_frontend
*fe
,
865 enum fe_sec_voltage voltage
)
867 struct dvb_usb_device
*d
= fe_to_d(fe
);
868 struct lme2510_state
*st
= fe_to_priv(fe
);
869 static u8 voltage_low
[] = LME_VOLTAGE_L
;
870 static u8 voltage_high
[] = LME_VOLTAGE_H
;
872 int ret
= 0, len
= 3, rlen
= 1;
874 mutex_lock(&d
->i2c_mutex
);
878 ret
|= lme2510_usb_talk(d
,
879 voltage_high
, len
, rbuf
, rlen
);
882 case SEC_VOLTAGE_OFF
:
885 ret
|= lme2510_usb_talk(d
,
886 voltage_low
, len
, rbuf
, rlen
);
890 mutex_unlock(&d
->i2c_mutex
);
892 if (st
->tuner_config
== TUNER_RS2000
)
893 if (st
->fe_set_voltage
)
894 st
->fe_set_voltage(fe
, voltage
);
897 return (ret
< 0) ? -ENODEV
: 0;
900 static int dm04_read_status(struct dvb_frontend
*fe
, enum fe_status
*status
)
902 struct dvb_usb_device
*d
= fe_to_d(fe
);
903 struct lme2510_state
*st
= d
->priv
;
906 if (st
->i2c_talk_onoff
) {
907 if (st
->fe_read_status
) {
908 ret
= st
->fe_read_status(fe
, status
);
913 st
->lock_status
= *status
;
915 if (*status
& FE_HAS_LOCK
&& st
->stream_on
) {
916 mutex_lock(&d
->i2c_mutex
);
918 st
->i2c_talk_onoff
= 0;
919 ret
= lme2510_stream_restart(d
);
921 mutex_unlock(&d
->i2c_mutex
);
927 /* Timeout of interrupt reached on RS2000 */
928 if (st
->tuner_config
== TUNER_RS2000
&&
929 time_after(jiffies
, st
->int_urb_due
))
930 st
->lock_status
&= ~FE_HAS_LOCK
;
932 *status
= st
->lock_status
;
934 if (!(*status
& FE_HAS_LOCK
)) {
935 struct dvb_usb_adapter
*adap
= fe_to_adap(fe
);
937 st
->i2c_talk_onoff
= 1;
939 lme2510_update_stats(adap
);
945 static int dm04_read_signal_strength(struct dvb_frontend
*fe
, u16
*strength
)
947 struct dtv_frontend_properties
*c
= &fe
->dtv_property_cache
;
948 struct lme2510_state
*st
= fe_to_priv(fe
);
950 if (st
->fe_read_signal_strength
&& !st
->stream_on
)
951 return st
->fe_read_signal_strength(fe
, strength
);
953 if (c
->strength
.stat
[0].scale
== FE_SCALE_RELATIVE
)
954 *strength
= (u16
)c
->strength
.stat
[0].uvalue
;
961 static int dm04_read_snr(struct dvb_frontend
*fe
, u16
*snr
)
963 struct dtv_frontend_properties
*c
= &fe
->dtv_property_cache
;
964 struct lme2510_state
*st
= fe_to_priv(fe
);
966 if (st
->fe_read_snr
&& !st
->stream_on
)
967 return st
->fe_read_snr(fe
, snr
);
969 if (c
->cnr
.stat
[0].scale
== FE_SCALE_RELATIVE
)
970 *snr
= (u16
)c
->cnr
.stat
[0].uvalue
;
977 static int dm04_read_ber(struct dvb_frontend
*fe
, u32
*ber
)
979 struct lme2510_state
*st
= fe_to_priv(fe
);
981 if (st
->fe_read_ber
&& !st
->stream_on
)
982 return st
->fe_read_ber(fe
, ber
);
989 static int dm04_read_ucblocks(struct dvb_frontend
*fe
, u32
*ucblocks
)
991 struct lme2510_state
*st
= fe_to_priv(fe
);
993 if (st
->fe_read_ucblocks
&& !st
->stream_on
)
994 return st
->fe_read_ucblocks(fe
, ucblocks
);
1001 static int lme_name(struct dvb_usb_adapter
*adap
)
1003 struct dvb_usb_device
*d
= adap_to_d(adap
);
1004 struct lme2510_state
*st
= adap_to_priv(adap
);
1005 const char *desc
= d
->name
;
1006 char *fe_name
[] = {"", " LG TDQY-P001F", " SHARP:BS2F7HZ7395",
1007 " SHARP:BS2F7HZ0194", " RS2000"};
1008 char *name
= adap
->fe
[0]->ops
.info
.name
;
1010 strlcpy(name
, desc
, 128);
1011 strlcat(name
, fe_name
[st
->tuner_config
], 128);
1016 static int dm04_lme2510_frontend_attach(struct dvb_usb_adapter
*adap
)
1018 struct dvb_usb_device
*d
= adap_to_d(adap
);
1019 struct lme2510_state
*st
= d
->priv
;
1022 st
->i2c_talk_onoff
= 1;
1023 switch (le16_to_cpu(d
->udev
->descriptor
.idProduct
)) {
1027 adap
->fe
[0] = dvb_attach(tda10086_attach
,
1028 &tda10086_config
, &d
->i2c_adap
);
1030 info("TUN Found Frontend TDA10086");
1031 st
->i2c_tuner_gate_w
= 4;
1032 st
->i2c_tuner_gate_r
= 4;
1033 st
->i2c_tuner_addr
= 0x60;
1034 st
->tuner_config
= TUNER_LG
;
1035 if (st
->dvb_usb_lme2510_firmware
!= TUNER_LG
) {
1036 st
->dvb_usb_lme2510_firmware
= TUNER_LG
;
1037 ret
= lme_firmware_switch(d
, 1) ? 0 : -ENODEV
;
1043 adap
->fe
[0] = dvb_attach(stv0299_attach
,
1044 &sharp_z0194_config
, &d
->i2c_adap
);
1046 info("FE Found Stv0299");
1047 st
->i2c_tuner_gate_w
= 4;
1048 st
->i2c_tuner_gate_r
= 5;
1049 st
->i2c_tuner_addr
= 0x60;
1050 st
->tuner_config
= TUNER_S0194
;
1051 if (st
->dvb_usb_lme2510_firmware
!= TUNER_S0194
) {
1052 st
->dvb_usb_lme2510_firmware
= TUNER_S0194
;
1053 ret
= lme_firmware_switch(d
, 1) ? 0 : -ENODEV
;
1059 adap
->fe
[0] = dvb_attach(stv0288_attach
, &lme_config
,
1063 info("FE Found Stv0288");
1064 st
->i2c_tuner_gate_w
= 4;
1065 st
->i2c_tuner_gate_r
= 5;
1066 st
->i2c_tuner_addr
= 0x60;
1067 st
->tuner_config
= TUNER_S7395
;
1068 if (st
->dvb_usb_lme2510_firmware
!= TUNER_S7395
) {
1069 st
->dvb_usb_lme2510_firmware
= TUNER_S7395
;
1070 ret
= lme_firmware_switch(d
, 1) ? 0 : -ENODEV
;
1076 adap
->fe
[0] = dvb_attach(m88rs2000_attach
,
1077 &m88rs2000_config
, &d
->i2c_adap
);
1080 info("FE Found M88RS2000");
1081 dvb_attach(ts2020_attach
, adap
->fe
[0], &ts2020_config
,
1083 st
->i2c_tuner_gate_w
= 5;
1084 st
->i2c_tuner_gate_r
= 5;
1085 st
->i2c_tuner_addr
= 0x60;
1086 st
->tuner_config
= TUNER_RS2000
;
1087 st
->fe_set_voltage
=
1088 adap
->fe
[0]->ops
.set_voltage
;
1093 if (adap
->fe
[0] == NULL
) {
1094 info("DM04/QQBOX Not Powered up or not Supported");
1100 dvb_frontend_detach(adap
->fe
[0]);
1107 st
->fe_read_status
= adap
->fe
[0]->ops
.read_status
;
1108 st
->fe_read_signal_strength
= adap
->fe
[0]->ops
.read_signal_strength
;
1109 st
->fe_read_snr
= adap
->fe
[0]->ops
.read_snr
;
1110 st
->fe_read_ber
= adap
->fe
[0]->ops
.read_ber
;
1111 st
->fe_read_ucblocks
= adap
->fe
[0]->ops
.read_ucblocks
;
1113 adap
->fe
[0]->ops
.read_status
= dm04_read_status
;
1114 adap
->fe
[0]->ops
.read_signal_strength
= dm04_read_signal_strength
;
1115 adap
->fe
[0]->ops
.read_snr
= dm04_read_snr
;
1116 adap
->fe
[0]->ops
.read_ber
= dm04_read_ber
;
1117 adap
->fe
[0]->ops
.read_ucblocks
= dm04_read_ucblocks
;
1118 adap
->fe
[0]->ops
.set_voltage
= dm04_lme2510_set_voltage
;
1120 ret
= lme_name(adap
);
1124 static int dm04_lme2510_tuner(struct dvb_usb_adapter
*adap
)
1126 struct dvb_usb_device
*d
= adap_to_d(adap
);
1127 struct lme2510_state
*st
= adap_to_priv(adap
);
1128 char *tun_msg
[] = {"", "TDA8263", "IX2505V", "DVB_PLL_OPERA", "RS2000"};
1131 switch (st
->tuner_config
) {
1133 if (dvb_attach(tda826x_attach
, adap
->fe
[0], 0x60,
1135 ret
= st
->tuner_config
;
1138 if (dvb_attach(ix2505v_attach
, adap
->fe
[0], &lme_tuner
,
1140 ret
= st
->tuner_config
;
1143 if (dvb_attach(dvb_pll_attach
, adap
->fe
[0], 0x60,
1144 &d
->i2c_adap
, DVB_PLL_OPERA1
))
1145 ret
= st
->tuner_config
;
1148 ret
= st
->tuner_config
;
1155 info("TUN Found %s tuner", tun_msg
[ret
]);
1157 info("TUN No tuner found --- resetting device");
1162 /* Start the Interrupt*/
1163 ret
= lme2510_int_read(adap
);
1165 info("INT Unable to start Interrupt Service");
1172 static int lme2510_powerup(struct dvb_usb_device
*d
, int onoff
)
1174 struct lme2510_state
*st
= d
->priv
;
1175 static u8 lnb_on
[] = LNB_ON
;
1176 static u8 lnb_off
[] = LNB_OFF
;
1178 int ret
= 0, len
= 3, rlen
= 1;
1180 mutex_lock(&d
->i2c_mutex
);
1183 ret
= lme2510_usb_talk(d
, lnb_on
, len
, rbuf
, rlen
);
1185 ret
= lme2510_usb_talk(d
, lnb_off
, len
, rbuf
, rlen
);
1187 st
->i2c_talk_onoff
= 1;
1189 mutex_unlock(&d
->i2c_mutex
);
1194 static int lme2510_get_adapter_count(struct dvb_usb_device
*d
)
1199 static int lme2510_identify_state(struct dvb_usb_device
*d
, const char **name
)
1201 struct lme2510_state
*st
= d
->priv
;
1203 usb_reset_configuration(d
->udev
);
1205 usb_set_interface(d
->udev
,
1206 d
->props
->bInterfaceNumber
, 1);
1208 st
->dvb_usb_lme2510_firmware
= dvb_usb_lme2510_firmware
;
1210 if (lme2510_return_status(d
) == 0x44) {
1211 *name
= lme_firmware_switch(d
, 0);
1218 static int lme2510_get_stream_config(struct dvb_frontend
*fe
, u8
*ts_type
,
1219 struct usb_data_stream_properties
*stream
)
1221 struct dvb_usb_adapter
*adap
= fe_to_adap(fe
);
1222 struct dvb_usb_device
*d
;
1227 d
= adap_to_d(adap
);
1229 /* Turn PID filter on the fly by module option */
1230 if (pid_filter
== 2) {
1231 adap
->pid_filtering
= true;
1232 adap
->max_feed_count
= 15;
1235 if (!(le16_to_cpu(d
->udev
->descriptor
.idProduct
)
1237 stream
->endpoint
= 0x8;
1242 static int lme2510_get_rc_config(struct dvb_usb_device
*d
,
1243 struct dvb_usb_rc
*rc
)
1245 rc
->allowed_protos
= RC_BIT_NEC
;
1249 static void *lme2510_exit_int(struct dvb_usb_device
*d
)
1251 struct lme2510_state
*st
= d
->priv
;
1252 struct dvb_usb_adapter
*adap
= &d
->adapter
[0];
1253 void *buffer
= NULL
;
1256 lme2510_kill_urb(&adap
->stream
);
1259 if (st
->usb_buffer
!= NULL
) {
1260 st
->i2c_talk_onoff
= 1;
1261 st
->signal_level
= 0;
1263 buffer
= st
->usb_buffer
;
1266 if (st
->lme_urb
!= NULL
) {
1267 usb_kill_urb(st
->lme_urb
);
1268 usb_free_coherent(d
->udev
, 128, st
->buffer
,
1269 st
->lme_urb
->transfer_dma
);
1270 info("Interrupt Service Stopped");
1276 static void lme2510_exit(struct dvb_usb_device
*d
)
1281 usb_buffer
= lme2510_exit_int(d
);
1286 static struct dvb_usb_device_properties lme2510_props
= {
1287 .driver_name
= KBUILD_MODNAME
,
1288 .owner
= THIS_MODULE
,
1289 .bInterfaceNumber
= 0,
1290 .adapter_nr
= adapter_nr
,
1291 .size_of_priv
= sizeof(struct lme2510_state
),
1293 .download_firmware
= lme2510_download_firmware
,
1295 .power_ctrl
= lme2510_powerup
,
1296 .identify_state
= lme2510_identify_state
,
1297 .i2c_algo
= &lme2510_i2c_algo
,
1299 .frontend_attach
= dm04_lme2510_frontend_attach
,
1300 .tuner_attach
= dm04_lme2510_tuner
,
1301 .get_stream_config
= lme2510_get_stream_config
,
1302 .get_adapter_count
= lme2510_get_adapter_count
,
1303 .streaming_ctrl
= lme2510_streaming_ctrl
,
1305 .get_rc_config
= lme2510_get_rc_config
,
1307 .exit
= lme2510_exit
,
1310 .caps
= DVB_USB_ADAP_HAS_PID_FILTER
|
1311 DVB_USB_ADAP_PID_FILTER_CAN_BE_TURNED_OFF
,
1312 .pid_filter_count
= 15,
1313 .pid_filter
= lme2510_pid_filter
,
1314 .pid_filter_ctrl
= lme2510_pid_filter_ctrl
,
1316 DVB_USB_STREAM_BULK(0x86, 10, 4096),
1323 static const struct usb_device_id lme2510_id_table
[] = {
1324 { DVB_USB_DEVICE(0x3344, 0x1122, &lme2510_props
,
1325 "DM04_LME2510_DVB-S", RC_MAP_LME2510
) },
1326 { DVB_USB_DEVICE(0x3344, 0x1120, &lme2510_props
,
1327 "DM04_LME2510C_DVB-S", RC_MAP_LME2510
) },
1328 { DVB_USB_DEVICE(0x3344, 0x22f0, &lme2510_props
,
1329 "DM04_LME2510C_DVB-S RS2000", RC_MAP_LME2510
) },
1330 {} /* Terminating entry */
1333 MODULE_DEVICE_TABLE(usb
, lme2510_id_table
);
1335 static struct usb_driver lme2510_driver
= {
1336 .name
= KBUILD_MODNAME
,
1337 .probe
= dvb_usbv2_probe
,
1338 .disconnect
= dvb_usbv2_disconnect
,
1339 .id_table
= lme2510_id_table
,
1344 module_usb_driver(lme2510_driver
);
1346 MODULE_AUTHOR("Malcolm Priestley <tvboxspy@gmail.com>");
1347 MODULE_DESCRIPTION("LME2510(C) DVB-S USB2.0");
1348 MODULE_VERSION("2.07");
1349 MODULE_LICENSE("GPL");
1350 MODULE_FIRMWARE(LME2510_C_S7395
);
1351 MODULE_FIRMWARE(LME2510_C_LG
);
1352 MODULE_FIRMWARE(LME2510_C_S0194
);
1353 MODULE_FIRMWARE(LME2510_C_RS2000
);
1354 MODULE_FIRMWARE(LME2510_LG
);
1355 MODULE_FIRMWARE(LME2510_S0194
);