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 * For firmware see Documentation/dvb/lmedm04.txt
25 * 0xd0 - STV0288 - Demodulator
26 * 0xc0 - Sharp IX2505V - Tuner
28 * 0x1c - TDA10086 - Demodulator
29 * 0xc0 - TDA8263 - Tuner
31 * 0xd0 - STV0299 - Demodulator
32 * 0xc0 - IX2410 - Tuner
35 * VID = 3344 PID LME2510=1122 LME2510C=1120
37 * Copyright (C) 2010 Malcolm Priestley (tvboxspy@gmail.com)
38 * LME2510(C)(C) Leaguerme (Shenzhen) MicroElectronics Co., Ltd.
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.
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.
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.
54 * see Documentation/dvb/README.dvb-usb for more information
57 * LME2510: Non Intel USB chipsets fail to maintain High Speed on
60 * QQbox suffers from noise on LNB voltage.
62 * LME2510: SHARP:BS2F7HZ0194(MV0194) cannot cold reset and share system
63 * with other tuners. After a cold reset streaming will not start.
66 #define DVB_USB_LOG_PREFIX "LME2510(C)"
67 #include <linux/usb.h>
68 #include <linux/usb/input.h>
69 #include <media/rc-core.h>
80 #include "m88rs2000.h"
85 static int dvb_usb_lme2510_debug
;
86 #define l_dprintk(var, level, args...) do { \
88 printk(KERN_DEBUG DVB_USB_LOG_PREFIX ": " args); \
91 #define deb_info(level, args...) l_dprintk(dvb_usb_lme2510_debug, level, args)
92 #define debug_data_snipet(level, name, p) \
93 deb_info(level, name" (%02x%02x%02x%02x%02x%02x%02x%02x)", \
94 *p, *(p+1), *(p+2), *(p+3), *(p+4), \
95 *(p+5), *(p+6), *(p+7));
98 module_param_named(debug
, dvb_usb_lme2510_debug
, int, 0644);
99 MODULE_PARM_DESC(debug
, "set debugging level (1=info (or-able))."
100 DVB_USB_DEBUG_STATUS
);
102 static int dvb_usb_lme2510_firmware
;
103 module_param_named(firmware
, dvb_usb_lme2510_firmware
, int, 0644);
104 MODULE_PARM_DESC(firmware
, "set default firmware 0=Sharp7395 1=LG");
106 static int pid_filter
;
107 module_param_named(pid
, pid_filter
, int, 0644);
108 MODULE_PARM_DESC(pid
, "set default 0=default 1=off 2=on");
111 DVB_DEFINE_MOD_OPT_ADAPTER_NR(adapter_nr
);
113 #define TUNER_DEFAULT 0x0
115 #define TUNER_S7395 0x2
116 #define TUNER_S0194 0x3
117 #define TUNER_RS2000 0x4
119 struct lme2510_state
{
142 static int lme2510_bulk_write(struct usb_device
*dev
,
143 u8
*snd
, int len
, u8 pipe
)
147 ret
= usb_bulk_msg(dev
, usb_sndbulkpipe(dev
, pipe
),
148 snd
, len
, &actual_l
, 100);
152 static int lme2510_bulk_read(struct usb_device
*dev
,
153 u8
*rev
, int len
, u8 pipe
)
157 ret
= usb_bulk_msg(dev
, usb_rcvbulkpipe(dev
, pipe
),
158 rev
, len
, &actual_l
, 200);
162 static int lme2510_usb_talk(struct dvb_usb_device
*d
,
163 u8
*wbuf
, int wlen
, u8
*rbuf
, int rlen
)
165 struct lme2510_state
*st
= d
->priv
;
169 if (st
->usb_buffer
== NULL
) {
170 st
->usb_buffer
= kmalloc(64, GFP_KERNEL
);
171 if (st
->usb_buffer
== NULL
) {
172 info("MEM Error no memory");
176 buff
= st
->usb_buffer
;
178 ret
= mutex_lock_interruptible(&d
->usb_mutex
);
183 /* the read/write capped at 64 */
184 memcpy(buff
, wbuf
, (wlen
< 64) ? wlen
: 64);
186 ret
|= lme2510_bulk_write(d
->udev
, buff
, wlen
, 0x01);
188 ret
|= lme2510_bulk_read(d
->udev
, buff
, (rlen
< 64) ?
192 memcpy(rbuf
, buff
, rlen
);
194 mutex_unlock(&d
->usb_mutex
);
196 return (ret
< 0) ? -ENODEV
: 0;
199 static int lme2510_stream_restart(struct dvb_usb_device
*d
)
201 struct lme2510_state
*st
= d
->priv
;
202 u8 all_pids
[] = LME_ALL_PIDS
;
203 u8 stream_on
[] = LME_ST_ON_W
;
207 ret
= lme2510_usb_talk(d
, all_pids
, sizeof(all_pids
),
208 rbuff
, sizeof(rbuff
));
209 /*Restart Stream Command*/
210 ret
= lme2510_usb_talk(d
, stream_on
, sizeof(stream_on
),
211 rbuff
, sizeof(rbuff
));
215 static int lme2510_enable_pid(struct dvb_usb_device
*d
, u8 index
, u16 pid_out
)
217 struct lme2510_state
*st
= d
->priv
;
218 static u8 pid_buff
[] = LME_ZERO_PID
;
220 u8 pid_no
= index
* 2;
221 u8 pid_len
= pid_no
+ 2;
223 deb_info(1, "PID Setting Pid %04x", pid_out
);
225 if (st
->pid_size
== 0)
226 ret
|= lme2510_stream_restart(d
);
228 pid_buff
[2] = pid_no
;
229 pid_buff
[3] = (u8
)pid_out
& 0xff;
230 pid_buff
[4] = pid_no
+ 1;
231 pid_buff
[5] = (u8
)(pid_out
>> 8);
233 if (pid_len
> st
->pid_size
)
234 st
->pid_size
= pid_len
;
235 pid_buff
[7] = 0x80 + st
->pid_size
;
237 ret
|= lme2510_usb_talk(d
, pid_buff
,
238 sizeof(pid_buff
) , rbuf
, sizeof(rbuf
));
241 ret
|= lme2510_stream_restart(d
);
246 static void lme2510_int_response(struct urb
*lme_urb
)
248 struct dvb_usb_adapter
*adap
= lme_urb
->context
;
249 struct lme2510_state
*st
= adap
->dev
->priv
;
250 static u8
*ibuf
, *rbuf
;
254 switch (lme_urb
->status
) {
263 info("Error %x", lme_urb
->status
);
267 rbuf
= (u8
*) lme_urb
->transfer_buffer
;
269 offset
= ((lme_urb
->actual_length
/8) > 4)
270 ? 4 : (lme_urb
->actual_length
/8) ;
272 for (i
= 0; i
< offset
; ++i
) {
273 ibuf
= (u8
*)&rbuf
[i
*8];
274 deb_info(5, "INT O/S C =%02x C/O=%02x Type =%02x%02x",
275 offset
, i
, ibuf
[0], ibuf
[1]);
279 debug_data_snipet(1, "INT Remote data snipet", ibuf
);
280 if ((ibuf
[4] + ibuf
[5]) == 0xff) {
283 ? (ibuf
[3] ^ 0xff) << 8 : 0;
284 key
+= (ibuf
[2] ^ 0xff) << 16;
285 deb_info(1, "INT Key =%08x", key
);
286 if (adap
->dev
->rc_dev
!= NULL
)
287 rc_keydown(adap
->dev
->rc_dev
, key
, 0);
291 switch (st
->tuner_config
) {
294 st
->signal_lock
= ibuf
[2];
295 st
->signal_level
= ibuf
[4];
296 st
->signal_sn
= ibuf
[3];
297 st
->time_key
= ibuf
[7];
301 /* Tweak for earlier firmware*/
302 if (ibuf
[1] == 0x03) {
304 st
->signal_lock
= ibuf
[2];
305 st
->signal_level
= ibuf
[3];
306 st
->signal_sn
= ibuf
[4];
308 st
->signal_level
= ibuf
[4];
309 st
->signal_sn
= ibuf
[5];
311 (st
->signal_lock
& 0xf7) +
312 ((ibuf
[2] & 0x01) << 0x03);
317 st
->signal_lock
= 0xff;
319 st
->signal_lock
= 0xf0;
320 st
->signal_level
= ibuf
[4];
321 st
->signal_sn
= ibuf
[5];
322 st
->time_key
= ibuf
[7];
326 debug_data_snipet(5, "INT Remote data snipet in", ibuf
);
329 debug_data_snipet(1, "INT Control data snipet", ibuf
);
332 debug_data_snipet(1, "INT Unknown data snipet", ibuf
);
336 usb_submit_urb(lme_urb
, GFP_ATOMIC
);
339 static int lme2510_int_read(struct dvb_usb_adapter
*adap
)
341 struct lme2510_state
*lme_int
= adap
->dev
->priv
;
343 lme_int
->lme_urb
= usb_alloc_urb(0, GFP_ATOMIC
);
345 if (lme_int
->lme_urb
== NULL
)
348 lme_int
->buffer
= usb_alloc_coherent(adap
->dev
->udev
, 128, GFP_ATOMIC
,
349 &lme_int
->lme_urb
->transfer_dma
);
351 if (lme_int
->buffer
== NULL
)
354 usb_fill_int_urb(lme_int
->lme_urb
,
356 usb_rcvintpipe(adap
->dev
->udev
, 0xa),
359 lme2510_int_response
,
363 lme_int
->lme_urb
->transfer_flags
|= URB_NO_TRANSFER_DMA_MAP
;
365 usb_submit_urb(lme_int
->lme_urb
, GFP_ATOMIC
);
366 info("INT Interrupt Service Started");
371 static int lme2510_pid_filter_ctrl(struct dvb_usb_adapter
*adap
, int onoff
)
373 struct lme2510_state
*st
= adap
->dev
->priv
;
374 static u8 clear_pid_reg
[] = LME_ALL_PIDS
;
378 deb_info(1, "PID Clearing Filter");
380 mutex_lock(&adap
->dev
->i2c_mutex
);
383 ret
|= lme2510_usb_talk(adap
->dev
, clear_pid_reg
,
384 sizeof(clear_pid_reg
), rbuf
, sizeof(rbuf
));
391 mutex_unlock(&adap
->dev
->i2c_mutex
);
396 static int lme2510_pid_filter(struct dvb_usb_adapter
*adap
, int index
, u16 pid
,
401 deb_info(3, "%s PID=%04x Index=%04x onoff=%02x", __func__
,
405 mutex_lock(&adap
->dev
->i2c_mutex
);
406 ret
|= lme2510_enable_pid(adap
->dev
, index
, pid
);
407 mutex_unlock(&adap
->dev
->i2c_mutex
);
415 static int lme2510_return_status(struct usb_device
*dev
)
420 data
= kzalloc(10, GFP_KERNEL
);
424 ret
|= usb_control_msg(dev
, usb_rcvctrlpipe(dev
, 0),
425 0x06, 0x80, 0x0302, 0x00, data
, 0x0006, 200);
426 info("Firmware Status: %x (%x)", ret
, data
[2]);
428 ret
= (ret
< 0) ? -ENODEV
: data
[2];
433 static int lme2510_msg(struct dvb_usb_device
*d
,
434 u8
*wbuf
, int wlen
, u8
*rbuf
, int rlen
)
437 struct lme2510_state
*st
= d
->priv
;
439 if (st
->i2c_talk_onoff
== 1) {
441 ret
= lme2510_usb_talk(d
, wbuf
, wlen
, rbuf
, rlen
);
443 switch (st
->tuner_config
) {
445 if (wbuf
[2] == 0x1c) {
446 if (wbuf
[3] == 0x0e) {
447 st
->signal_lock
= rbuf
[1];
448 if ((st
->stream_on
& 1) &&
449 (st
->signal_lock
& 0x10)) {
450 lme2510_stream_restart(d
);
451 st
->i2c_talk_onoff
= 0;
458 if (wbuf
[2] == 0xd0) {
459 if (wbuf
[3] == 0x24) {
460 st
->signal_lock
= rbuf
[1];
461 if ((st
->stream_on
& 1) &&
462 (st
->signal_lock
& 0x8)) {
463 lme2510_stream_restart(d
);
464 st
->i2c_talk_onoff
= 0;
470 if (wbuf
[2] == 0xd0) {
471 if (wbuf
[3] == 0x1b) {
472 st
->signal_lock
= rbuf
[1];
473 if ((st
->stream_on
& 1) &&
474 (st
->signal_lock
& 0x8)) {
475 lme2510_stream_restart(d
);
476 st
->i2c_talk_onoff
= 0;
486 /* TODO rewrite this section */
487 switch (st
->tuner_config
) {
492 rbuf
[1] = st
->signal_lock
;
496 rbuf
[1] = st
->signal_level
;
500 rbuf
[1] = st
->signal_sn
;
510 lme2510_usb_talk(d
, wbuf
, wlen
, rbuf
, rlen
);
511 st
->i2c_talk_onoff
= 1;
519 rbuf
[1] = (st
->signal_level
& 0x80)
520 ? 0 : (st
->signal_level
* 2);
524 rbuf
[1] = st
->signal_sn
;
528 rbuf
[1] = st
->signal_lock
;
537 lme2510_usb_talk(d
, wbuf
, wlen
, rbuf
, rlen
);
538 st
->i2c_talk_onoff
= 1;
546 rbuf
[1] = (st
->signal_level
& 0x80)
547 ? 0 : (st
->signal_level
* 2);
551 rbuf
[1] = st
->signal_sn
;
555 rbuf
[1] = st
->signal_lock
;
565 lme2510_usb_talk(d
, wbuf
, wlen
, rbuf
, rlen
);
566 st
->i2c_talk_onoff
= 1;
575 if (st
->last_key
== st
->time_key
) {
577 if (st
->key_timeout
> 5)
581 st
->last_key
= st
->time_key
;
584 lme2510_usb_talk(d
, wbuf
, wlen
, rbuf
, rlen
);
585 st
->i2c_talk_onoff
= 1;
592 deb_info(4, "I2C From Interrupt Message out(%02x) in(%02x)",
601 static int lme2510_i2c_xfer(struct i2c_adapter
*adap
, struct i2c_msg msg
[],
604 struct dvb_usb_device
*d
= i2c_get_adapdata(adap
);
605 struct lme2510_state
*st
= d
->priv
;
606 static u8 obuf
[64], ibuf
[64];
609 u8 gate
= st
->i2c_gate
;
611 mutex_lock(&d
->i2c_mutex
);
617 warn("more than 2 i2c messages"
618 "at a time is not handled yet. TODO.");
620 for (i
= 0; i
< num
; i
++) {
621 read_o
= 1 & (msg
[i
].flags
& I2C_M_RD
);
622 read
= i
+1 < num
&& (msg
[i
+1].flags
& I2C_M_RD
);
624 gate
= (msg
[i
].addr
== st
->i2c_tuner_addr
)
625 ? (read
) ? st
->i2c_tuner_gate_r
626 : st
->i2c_tuner_gate_w
628 obuf
[0] = gate
| (read
<< 7);
631 obuf
[1] = (read
) ? 2 : msg
[i
].len
+ 1;
633 obuf
[1] = msg
[i
].len
+ read
+ 1;
635 obuf
[2] = msg
[i
].addr
;
640 memcpy(&obuf
[3], msg
[i
].buf
, msg
[i
].len
);
641 obuf
[msg
[i
].len
+3] = msg
[i
+1].len
;
645 memcpy(&obuf
[3], msg
[i
].buf
, msg
[i
].len
);
649 if (lme2510_msg(d
, obuf
, len
, ibuf
, 64) < 0) {
650 deb_info(1, "i2c transfer failed.");
651 mutex_unlock(&d
->i2c_mutex
);
657 memcpy(msg
[i
].buf
, &ibuf
[1], msg
[i
].len
);
659 memcpy(msg
[i
+1].buf
, &ibuf
[1], msg
[i
+1].len
);
665 mutex_unlock(&d
->i2c_mutex
);
669 static u32
lme2510_i2c_func(struct i2c_adapter
*adapter
)
674 static struct i2c_algorithm lme2510_i2c_algo
= {
675 .master_xfer
= lme2510_i2c_xfer
,
676 .functionality
= lme2510_i2c_func
,
679 /* Callbacks for DVB USB */
680 static int lme2510_identify_state(struct usb_device
*udev
,
681 struct dvb_usb_device_properties
*props
,
682 struct dvb_usb_device_description
**desc
,
686 props
->adapter
[0].fe
[0].caps
&=
687 ~DVB_USB_ADAP_NEED_PID_FILTERING
;
692 static int lme2510_streaming_ctrl(struct dvb_usb_adapter
*adap
, int onoff
)
694 struct lme2510_state
*st
= adap
->dev
->priv
;
695 static u8 clear_reg_3
[] = LME_ALL_PIDS
;
697 int ret
= 0, rlen
= sizeof(rbuf
);
699 deb_info(1, "STM (%02x)", onoff
);
701 /* Streaming is started by FE_HAS_LOCK */
705 deb_info(1, "STM Steam Off");
706 /* mutex is here only to avoid collision with I2C */
707 mutex_lock(&adap
->dev
->i2c_mutex
);
709 ret
= lme2510_usb_talk(adap
->dev
, clear_reg_3
,
710 sizeof(clear_reg_3
), rbuf
, rlen
);
712 st
->i2c_talk_onoff
= 1;
714 mutex_unlock(&adap
->dev
->i2c_mutex
);
717 return (ret
< 0) ? -ENODEV
: 0;
720 static u8
check_sum(u8
*p
, u8 len
)
728 static int lme2510_download_firmware(struct usb_device
*dev
,
729 const struct firmware
*fw
)
733 u16 j
, wlen
, len_in
, start
, end
;
734 u8 packet_size
, dlen
, i
;
740 data
= kzalloc(512, GFP_KERNEL
);
742 info("FRM Could not start Firmware Download (Buffer allocation failed)");
746 info("FRM Starting Firmware Download");
748 for (i
= 1; i
< 3; i
++) {
749 start
= (i
== 1) ? 0 : 512;
750 end
= (i
== 1) ? 512 : fw
->size
;
751 for (j
= start
; j
< end
; j
+= (packet_size
+1)) {
752 fw_data
= (u8
*)(fw
->data
+ j
);
753 if ((end
- j
) > packet_size
) {
758 dlen
= (u8
)(end
- j
)-1;
761 memcpy(&data
[2], fw_data
, dlen
+1);
762 wlen
= (u8
) dlen
+ 4;
763 data
[wlen
-1] = check_sum(fw_data
, dlen
+1);
764 deb_info(1, "Data S=%02x:E=%02x CS= %02x", data
[3],
765 data
[dlen
+2], data
[dlen
+3]);
766 ret
|= lme2510_bulk_write(dev
, data
, wlen
, 1);
767 ret
|= lme2510_bulk_read(dev
, data
, len_in
, 1);
768 ret
|= (data
[0] == 0x88) ? 0 : -1;
772 usb_control_msg(dev
, usb_rcvctrlpipe(dev
, 0),
773 0x06, 0x80, 0x0200, 0x00, data
, 0x0109, 1000);
779 ret
|= lme2510_bulk_write(dev
, data
, len_in
, 1); /*Resetting*/
780 ret
|= lme2510_bulk_read(dev
, data
, len_in
, 1);
784 info("FRM Firmware Download Failed (%04x)" , ret
);
786 info("FRM Firmware Download Completed - Resetting Device");
789 return (ret
< 0) ? -ENODEV
: 0;
792 static void lme_coldreset(struct usb_device
*dev
)
799 info("FRM Firmware Cold Reset");
800 ret
|= lme2510_bulk_write(dev
, data
, len_in
, 1); /*Cold Resetting*/
801 ret
|= lme2510_bulk_read(dev
, data
, len_in
, 1);
806 static int lme_firmware_switch(struct usb_device
*udev
, int cold
)
808 const struct firmware
*fw
= NULL
;
809 const char fw_c_s7395
[] = "dvb-usb-lme2510c-s7395.fw";
810 const char fw_c_lg
[] = "dvb-usb-lme2510c-lg.fw";
811 const char fw_c_s0194
[] = "dvb-usb-lme2510c-s0194.fw";
812 const char fw_c_rs2000
[] = "dvb-usb-lme2510c-rs2000.fw";
813 const char fw_lg
[] = "dvb-usb-lme2510-lg.fw";
814 const char fw_s0194
[] = "dvb-usb-lme2510-s0194.fw";
816 int ret
= 0, cold_fw
;
818 cold
= (cold
> 0) ? (cold
& 1) : 0;
822 switch (le16_to_cpu(udev
->descriptor
.idProduct
)) {
824 switch (dvb_usb_lme2510_firmware
) {
826 dvb_usb_lme2510_firmware
= TUNER_S0194
;
829 ret
= request_firmware(&fw
, fw_lme
, &udev
->dev
);
834 dvb_usb_lme2510_firmware
= TUNER_LG
;
837 ret
= request_firmware(&fw
, fw_lme
, &udev
->dev
);
840 info("FRM No Firmware Found - please install");
841 dvb_usb_lme2510_firmware
= TUNER_DEFAULT
;
848 switch (dvb_usb_lme2510_firmware
) {
850 dvb_usb_lme2510_firmware
= TUNER_S7395
;
853 ret
= request_firmware(&fw
, fw_lme
, &udev
->dev
);
858 dvb_usb_lme2510_firmware
= TUNER_LG
;
861 ret
= request_firmware(&fw
, fw_lme
, &udev
->dev
);
864 dvb_usb_lme2510_firmware
= TUNER_S0194
;
867 ret
= request_firmware(&fw
, fw_lme
, &udev
->dev
);
870 info("FRM No Firmware Found - please install");
871 dvb_usb_lme2510_firmware
= TUNER_DEFAULT
;
878 fw_lme
= fw_c_rs2000
;
879 ret
= request_firmware(&fw
, fw_lme
, &udev
->dev
);
880 dvb_usb_lme2510_firmware
= TUNER_RS2000
;
883 info("FRM No Firmware Found - please install");
892 info("FRM Loading %s file", fw_lme
);
893 ret
= lme2510_download_firmware(udev
, fw
);
896 release_firmware(fw
);
899 info("FRM Changing to %s firmware", fw_lme
);
907 static int lme2510_kill_urb(struct usb_data_stream
*stream
)
911 for (i
= 0; i
< stream
->urbs_submitted
; i
++) {
912 deb_info(3, "killing URB no. %d.", i
);
914 usb_kill_urb(stream
->urb_list
[i
]);
916 stream
->urbs_submitted
= 0;
921 static struct tda10086_config tda10086_config
= {
922 .demod_address
= 0x1c,
925 .xtal_freq
= TDA10086_XTAL_16M
,
928 static struct stv0288_config lme_config
= {
929 .demod_address
= 0xd0,
931 .inittab
= s7395_inittab
,
934 static struct ix2505v_config lme_tuner
= {
935 .tuner_address
= 0xc0,
938 .tuner_chargepump
= 0x3,
941 static struct stv0299_config sharp_z0194_config
= {
942 .demod_address
= 0xd0,
943 .inittab
= sharp_z0194a_inittab
,
947 .lock_output
= STV0299_LOCKOUTPUT_1
,
948 .volt13_op0_op1
= STV0299_VOLT13_OP1
,
950 .set_symbol_rate
= sharp_z0194a_set_symbol_rate
,
953 static int dm04_rs2000_set_ts_param(struct dvb_frontend
*fe
,
956 struct dvb_usb_adapter
*adap
= fe
->dvb
->priv
;
957 struct dvb_usb_device
*d
= adap
->dev
;
958 struct lme2510_state
*st
= d
->priv
;
960 mutex_lock(&d
->i2c_mutex
);
961 if ((st
->i2c_talk_onoff
== 1) && (st
->stream_on
& 1)) {
962 st
->i2c_talk_onoff
= 0;
963 lme2510_stream_restart(d
);
965 mutex_unlock(&d
->i2c_mutex
);
970 static struct m88rs2000_config m88rs2000_config
= {
973 .set_ts_params
= dm04_rs2000_set_ts_param
,
976 static int dm04_lme2510_set_voltage(struct dvb_frontend
*fe
,
977 fe_sec_voltage_t voltage
)
979 struct dvb_usb_adapter
*adap
= fe
->dvb
->priv
;
980 static u8 voltage_low
[] = LME_VOLTAGE_L
;
981 static u8 voltage_high
[] = LME_VOLTAGE_H
;
983 int ret
= 0, len
= 3, rlen
= 1;
985 mutex_lock(&adap
->dev
->i2c_mutex
);
989 ret
|= lme2510_usb_talk(adap
->dev
,
990 voltage_high
, len
, rbuf
, rlen
);
993 case SEC_VOLTAGE_OFF
:
996 ret
|= lme2510_usb_talk(adap
->dev
,
997 voltage_low
, len
, rbuf
, rlen
);
1001 mutex_unlock(&adap
->dev
->i2c_mutex
);
1003 return (ret
< 0) ? -ENODEV
: 0;
1006 static int dm04_rs2000_read_signal_strength(struct dvb_frontend
*fe
,
1009 struct dvb_usb_adapter
*adap
= fe
->dvb
->priv
;
1010 struct lme2510_state
*st
= adap
->dev
->priv
;
1012 *strength
= (u16
)((u32
)st
->signal_level
* 0xffff / 0x7f);
1016 static int dm04_rs2000_read_snr(struct dvb_frontend
*fe
, u16
*snr
)
1018 struct dvb_usb_adapter
*adap
= fe
->dvb
->priv
;
1019 struct lme2510_state
*st
= adap
->dev
->priv
;
1021 *snr
= (u16
)((u32
)st
->signal_sn
* 0xffff / 0xff);
1025 static int lme_name(struct dvb_usb_adapter
*adap
)
1027 struct lme2510_state
*st
= adap
->dev
->priv
;
1028 const char *desc
= adap
->dev
->desc
->name
;
1029 char *fe_name
[] = {"", " LG TDQY-P001F", " SHARP:BS2F7HZ7395",
1030 " SHARP:BS2F7HZ0194", " RS2000"};
1031 char *name
= adap
->fe_adap
[0].fe
->ops
.info
.name
;
1033 strlcpy(name
, desc
, 128);
1034 strlcat(name
, fe_name
[st
->tuner_config
], 128);
1039 static int dm04_lme2510_frontend_attach(struct dvb_usb_adapter
*adap
)
1041 struct lme2510_state
*st
= adap
->dev
->priv
;
1045 st
->i2c_talk_onoff
= 1;
1046 switch (le16_to_cpu(adap
->dev
->udev
->descriptor
.idProduct
)) {
1050 adap
->fe_adap
[0].fe
= dvb_attach(tda10086_attach
,
1051 &tda10086_config
, &adap
->dev
->i2c_adap
);
1052 if (adap
->fe_adap
[0].fe
) {
1053 info("TUN Found Frontend TDA10086");
1054 st
->i2c_tuner_gate_w
= 4;
1055 st
->i2c_tuner_gate_r
= 4;
1056 st
->i2c_tuner_addr
= 0xc0;
1057 st
->tuner_config
= TUNER_LG
;
1058 if (dvb_usb_lme2510_firmware
!= TUNER_LG
) {
1059 dvb_usb_lme2510_firmware
= TUNER_LG
;
1060 ret
= lme_firmware_switch(adap
->dev
->udev
, 1);
1066 adap
->fe_adap
[0].fe
= dvb_attach(stv0299_attach
,
1067 &sharp_z0194_config
, &adap
->dev
->i2c_adap
);
1068 if (adap
->fe_adap
[0].fe
) {
1069 info("FE Found Stv0299");
1070 st
->i2c_tuner_gate_w
= 4;
1071 st
->i2c_tuner_gate_r
= 5;
1072 st
->i2c_tuner_addr
= 0xc0;
1073 st
->tuner_config
= TUNER_S0194
;
1074 if (dvb_usb_lme2510_firmware
!= TUNER_S0194
) {
1075 dvb_usb_lme2510_firmware
= TUNER_S0194
;
1076 ret
= lme_firmware_switch(adap
->dev
->udev
, 1);
1082 adap
->fe_adap
[0].fe
= dvb_attach(stv0288_attach
, &lme_config
,
1083 &adap
->dev
->i2c_adap
);
1085 if (adap
->fe_adap
[0].fe
) {
1086 info("FE Found Stv0288");
1087 st
->i2c_tuner_gate_w
= 4;
1088 st
->i2c_tuner_gate_r
= 5;
1089 st
->i2c_tuner_addr
= 0xc0;
1090 st
->tuner_config
= TUNER_S7395
;
1091 if (dvb_usb_lme2510_firmware
!= TUNER_S7395
) {
1092 dvb_usb_lme2510_firmware
= TUNER_S7395
;
1093 ret
= lme_firmware_switch(adap
->dev
->udev
, 1);
1099 adap
->fe_adap
[0].fe
= dvb_attach(m88rs2000_attach
,
1100 &m88rs2000_config
, &adap
->dev
->i2c_adap
);
1102 if (adap
->fe_adap
[0].fe
) {
1103 info("FE Found M88RS2000");
1104 st
->i2c_tuner_gate_w
= 5;
1105 st
->i2c_tuner_gate_r
= 5;
1106 st
->i2c_tuner_addr
= 0xc0;
1107 st
->tuner_config
= TUNER_RS2000
;
1108 adap
->fe_adap
[0].fe
->ops
.read_signal_strength
=
1109 dm04_rs2000_read_signal_strength
;
1110 adap
->fe_adap
[0].fe
->ops
.read_snr
=
1111 dm04_rs2000_read_snr
;
1116 if (adap
->fe_adap
[0].fe
== NULL
) {
1117 info("DM04/QQBOX Not Powered up or not Supported");
1122 if (adap
->fe_adap
[0].fe
) {
1123 dvb_frontend_detach(adap
->fe_adap
[0].fe
);
1124 adap
->fe_adap
[0].fe
= NULL
;
1126 adap
->dev
->props
.rc
.core
.rc_codes
= NULL
;
1130 adap
->fe_adap
[0].fe
->ops
.set_voltage
= dm04_lme2510_set_voltage
;
1131 ret
= lme_name(adap
);
1135 static int dm04_lme2510_tuner(struct dvb_usb_adapter
*adap
)
1137 struct lme2510_state
*st
= adap
->dev
->priv
;
1138 char *tun_msg
[] = {"", "TDA8263", "IX2505V", "DVB_PLL_OPERA", "RS2000"};
1141 switch (st
->tuner_config
) {
1143 if (dvb_attach(tda826x_attach
, adap
->fe_adap
[0].fe
, 0xc0,
1144 &adap
->dev
->i2c_adap
, 1))
1145 ret
= st
->tuner_config
;
1148 if (dvb_attach(ix2505v_attach
, adap
->fe_adap
[0].fe
, &lme_tuner
,
1149 &adap
->dev
->i2c_adap
))
1150 ret
= st
->tuner_config
;
1153 if (dvb_attach(dvb_pll_attach
, adap
->fe_adap
[0].fe
, 0xc0,
1154 &adap
->dev
->i2c_adap
, DVB_PLL_OPERA1
))
1155 ret
= st
->tuner_config
;
1158 ret
= st
->tuner_config
;
1165 info("TUN Found %s tuner", tun_msg
[ret
]);
1167 info("TUN No tuner found --- resetting device");
1168 lme_coldreset(adap
->dev
->udev
);
1172 /* Start the Interrupt*/
1173 ret
= lme2510_int_read(adap
);
1175 info("INT Unable to start Interrupt Service");
1182 static int lme2510_powerup(struct dvb_usb_device
*d
, int onoff
)
1184 struct lme2510_state
*st
= d
->priv
;
1185 static u8 lnb_on
[] = LNB_ON
;
1186 static u8 lnb_off
[] = LNB_OFF
;
1188 int ret
= 0, len
= 3, rlen
= 1;
1190 mutex_lock(&d
->i2c_mutex
);
1193 ret
= lme2510_usb_talk(d
, lnb_on
, len
, rbuf
, rlen
);
1195 ret
= lme2510_usb_talk(d
, lnb_off
, len
, rbuf
, rlen
);
1197 st
->i2c_talk_onoff
= 1;
1199 mutex_unlock(&d
->i2c_mutex
);
1204 /* DVB USB Driver stuff */
1205 static struct dvb_usb_device_properties lme2510_properties
;
1206 static struct dvb_usb_device_properties lme2510c_properties
;
1208 static int lme2510_probe(struct usb_interface
*intf
,
1209 const struct usb_device_id
*id
)
1211 struct usb_device
*udev
= interface_to_usbdev(intf
);
1213 usb_reset_configuration(udev
);
1215 usb_set_interface(udev
, intf
->cur_altsetting
->desc
.bInterfaceNumber
, 1);
1217 if (udev
->speed
!= USB_SPEED_HIGH
) {
1218 usb_reset_device(udev
);
1219 info("DEV Failed to connect in HIGH SPEED mode");
1223 if (lme2510_return_status(udev
) == 0x44) {
1224 lme_firmware_switch(udev
, 0);
1228 if (0 == dvb_usb_device_init(intf
, &lme2510_properties
,
1229 THIS_MODULE
, NULL
, adapter_nr
)) {
1230 info("DEV registering device driver");
1233 if (0 == dvb_usb_device_init(intf
, &lme2510c_properties
,
1234 THIS_MODULE
, NULL
, adapter_nr
)) {
1235 info("DEV registering device driver");
1239 info("DEV lme2510 Error");
1244 static struct usb_device_id lme2510_table
[] = {
1245 { USB_DEVICE(0x3344, 0x1122) }, /* LME2510 */
1246 { USB_DEVICE(0x3344, 0x1120) }, /* LME2510C */
1247 { USB_DEVICE(0x3344, 0x22f0) }, /* LME2510C RS2000 */
1248 {} /* Terminating entry */
1251 MODULE_DEVICE_TABLE(usb
, lme2510_table
);
1253 static struct dvb_usb_device_properties lme2510_properties
= {
1254 .caps
= DVB_USB_IS_AN_I2C_ADAPTER
,
1255 .size_of_priv
= sizeof(struct lme2510_state
),
1261 .caps
= DVB_USB_ADAP_HAS_PID_FILTER
|
1262 DVB_USB_ADAP_NEED_PID_FILTERING
|
1263 DVB_USB_ADAP_PID_FILTER_CAN_BE_TURNED_OFF
,
1264 .streaming_ctrl
= lme2510_streaming_ctrl
,
1265 .pid_filter_count
= 32,
1266 .pid_filter
= lme2510_pid_filter
,
1267 .pid_filter_ctrl
= lme2510_pid_filter_ctrl
,
1268 .frontend_attach
= dm04_lme2510_frontend_attach
,
1269 .tuner_attach
= dm04_lme2510_tuner
,
1270 /* parameter for the MPEG2-data transfer */
1286 .protocol
= RC_TYPE_NEC
,
1287 .module_name
= "LME2510 Remote Control",
1288 .allowed_protos
= RC_TYPE_NEC
,
1289 .rc_codes
= RC_MAP_LME2510
,
1291 .power_ctrl
= lme2510_powerup
,
1292 .identify_state
= lme2510_identify_state
,
1293 .i2c_algo
= &lme2510_i2c_algo
,
1294 .generic_bulk_ctrl_endpoint
= 0,
1295 .num_device_descs
= 1,
1297 { "DM04_LME2510_DVB-S",
1298 { &lme2510_table
[0], NULL
},
1304 static struct dvb_usb_device_properties lme2510c_properties
= {
1305 .caps
= DVB_USB_IS_AN_I2C_ADAPTER
,
1306 .size_of_priv
= sizeof(struct lme2510_state
),
1312 .caps
= DVB_USB_ADAP_HAS_PID_FILTER
|
1313 DVB_USB_ADAP_NEED_PID_FILTERING
|
1314 DVB_USB_ADAP_PID_FILTER_CAN_BE_TURNED_OFF
,
1315 .streaming_ctrl
= lme2510_streaming_ctrl
,
1316 .pid_filter_count
= 32,
1317 .pid_filter
= lme2510_pid_filter
,
1318 .pid_filter_ctrl
= lme2510_pid_filter_ctrl
,
1319 .frontend_attach
= dm04_lme2510_frontend_attach
,
1320 .tuner_attach
= dm04_lme2510_tuner
,
1321 /* parameter for the MPEG2-data transfer */
1337 .protocol
= RC_TYPE_NEC
,
1338 .module_name
= "LME2510 Remote Control",
1339 .allowed_protos
= RC_TYPE_NEC
,
1340 .rc_codes
= RC_MAP_LME2510
,
1342 .power_ctrl
= lme2510_powerup
,
1343 .identify_state
= lme2510_identify_state
,
1344 .i2c_algo
= &lme2510_i2c_algo
,
1345 .generic_bulk_ctrl_endpoint
= 0,
1346 .num_device_descs
= 2,
1348 { "DM04_LME2510C_DVB-S",
1349 { &lme2510_table
[1], NULL
},
1351 { "DM04_LME2510C_DVB-S RS2000",
1352 { &lme2510_table
[2], NULL
},
1357 static void *lme2510_exit_int(struct dvb_usb_device
*d
)
1359 struct lme2510_state
*st
= d
->priv
;
1360 struct dvb_usb_adapter
*adap
= &d
->adapter
[0];
1361 void *buffer
= NULL
;
1364 lme2510_kill_urb(&adap
->fe_adap
[0].stream
);
1365 adap
->feedcount
= 0;
1368 if (st
->usb_buffer
!= NULL
) {
1369 st
->i2c_talk_onoff
= 1;
1370 st
->signal_lock
= 0;
1371 st
->signal_level
= 0;
1373 buffer
= st
->usb_buffer
;
1376 if (st
->lme_urb
!= NULL
) {
1377 usb_kill_urb(st
->lme_urb
);
1378 usb_free_coherent(d
->udev
, 128, st
->buffer
,
1379 st
->lme_urb
->transfer_dma
);
1380 info("Interrupt Service Stopped");
1386 static void lme2510_exit(struct usb_interface
*intf
)
1388 struct dvb_usb_device
*d
= usb_get_intfdata(intf
);
1392 usb_buffer
= lme2510_exit_int(d
);
1393 dvb_usb_device_exit(intf
);
1394 if (usb_buffer
!= NULL
)
1399 static struct usb_driver lme2510_driver
= {
1400 .name
= "LME2510C_DVB-S",
1401 .probe
= lme2510_probe
,
1402 .disconnect
= lme2510_exit
,
1403 .id_table
= lme2510_table
,
1406 module_usb_driver(lme2510_driver
);
1408 MODULE_AUTHOR("Malcolm Priestley <tvboxspy@gmail.com>");
1409 MODULE_DESCRIPTION("LME2510(C) DVB-S USB2.0");
1410 MODULE_VERSION("1.99");
1411 MODULE_LICENSE("GPL");