1 // SPDX-License-Identifier: GPL-2.0-only
2 /* DVB USB compliant linux driver for
4 * DM04/QQBOX DVB-S USB BOX LME2510C + SHARP:BS2F7HZ7395
5 * LME2510C + LG TDQY-P001F
6 * LME2510C + BS2F7HZ0194
7 * LME2510 + LG TDQY-P001F
8 * LME2510 + BS2F7HZ0194
10 * MVB7395 (LME2510C+SHARP:BS2F7HZ7395)
11 * SHARP:BS2F7HZ7395 = (STV0288+Sharp IX2505V)
13 * MV001F (LME2510+LGTDQY-P001F)
14 * LG TDQY - P001F =(TDA8263 + TDA10086H)
16 * MVB0001F (LME2510C+LGTDQT-P001F)
18 * MV0194 (LME2510+SHARP:BS2F7HZ0194)
19 * SHARP:BS2F7HZ0194 = (STV0299+IX2410)
21 * MVB0194 (LME2510C+SHARP0194)
23 * LME2510C + M88RS2000
25 * For firmware see Documentation/media/dvb-drivers/lmedm04.rst
28 * 0xd0 - STV0288 - Demodulator
29 * 0xc0 - Sharp IX2505V - Tuner
31 * 0x1c - TDA10086 - Demodulator
32 * 0xc0 - TDA8263 - Tuner
34 * 0xd0 - STV0299 - Demodulator
35 * 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 * see Documentation/media/dvb-drivers/dvb-usb.rst for more information
45 * LME2510: Non Intel USB chipsets fail to maintain High Speed on
48 * QQbox suffers from noise on LNB voltage.
50 * LME2510: SHARP:BS2F7HZ0194(MV0194) cannot cold reset and share system
51 * with other tuners. After a cold reset streaming will not start.
53 * M88RS2000 suffers from loss of lock.
55 #define DVB_USB_LOG_PREFIX "LME2510(C)"
56 #include <linux/usb.h>
57 #include <linux/usb/input.h>
58 #include <media/rc-core.h>
69 #include "m88rs2000.h"
73 #define LME2510_C_S7395 "dvb-usb-lme2510c-s7395.fw";
74 #define LME2510_C_LG "dvb-usb-lme2510c-lg.fw";
75 #define LME2510_C_S0194 "dvb-usb-lme2510c-s0194.fw";
76 #define LME2510_C_RS2000 "dvb-usb-lme2510c-rs2000.fw";
77 #define LME2510_LG "dvb-usb-lme2510-lg.fw";
78 #define LME2510_S0194 "dvb-usb-lme2510-s0194.fw";
81 static int dvb_usb_lme2510_debug
;
82 #define lme_debug(var, level, args...) do { \
84 pr_debug(DVB_USB_LOG_PREFIX": " args); \
86 #define deb_info(level, args...) lme_debug(dvb_usb_lme2510_debug, level, args)
87 #define debug_data_snipet(level, name, p) \
88 deb_info(level, name" (%8phN)", p);
89 #define info(args...) pr_info(DVB_USB_LOG_PREFIX": "args)
91 module_param_named(debug
, dvb_usb_lme2510_debug
, int, 0644);
92 MODULE_PARM_DESC(debug
, "set debugging level (1=info (or-able)).");
94 static int dvb_usb_lme2510_firmware
;
95 module_param_named(firmware
, dvb_usb_lme2510_firmware
, int, 0644);
96 MODULE_PARM_DESC(firmware
, "set default firmware 0=Sharp7395 1=LG");
98 static int pid_filter
;
99 module_param_named(pid
, pid_filter
, int, 0644);
100 MODULE_PARM_DESC(pid
, "set default 0=default 1=off 2=on");
103 DVB_DEFINE_MOD_OPT_ADAPTER_NR(adapter_nr
);
105 #define TUNER_DEFAULT 0x0
107 #define TUNER_S7395 0x2
108 #define TUNER_S0194 0x3
109 #define TUNER_RS2000 0x4
111 struct lme2510_state
{
112 unsigned long int_urb_due
;
113 enum fe_status lock_status
;
130 /* Frontend original calls */
131 int (*fe_read_status
)(struct dvb_frontend
*, enum fe_status
*);
132 int (*fe_read_signal_strength
)(struct dvb_frontend
*, u16
*);
133 int (*fe_read_snr
)(struct dvb_frontend
*, u16
*);
134 int (*fe_read_ber
)(struct dvb_frontend
*, u32
*);
135 int (*fe_read_ucblocks
)(struct dvb_frontend
*, u32
*);
136 int (*fe_set_voltage
)(struct dvb_frontend
*, enum fe_sec_voltage
);
137 u8 dvb_usb_lme2510_firmware
;
140 static int lme2510_usb_talk(struct dvb_usb_device
*d
,
141 u8
*wbuf
, int wlen
, u8
*rbuf
, int rlen
)
143 struct lme2510_state
*st
= d
->priv
;
146 if (max(wlen
, rlen
) > sizeof(st
->usb_buffer
))
149 ret
= mutex_lock_interruptible(&d
->usb_mutex
);
153 memcpy(st
->usb_buffer
, wbuf
, wlen
);
155 ret
= dvb_usbv2_generic_rw_locked(d
, st
->usb_buffer
, wlen
,
156 st
->usb_buffer
, rlen
);
159 memcpy(rbuf
, st
->usb_buffer
, rlen
);
161 mutex_unlock(&d
->usb_mutex
);
166 static int lme2510_stream_restart(struct dvb_usb_device
*d
)
168 struct lme2510_state
*st
= d
->priv
;
169 u8 all_pids
[] = LME_ALL_PIDS
;
170 u8 stream_on
[] = LME_ST_ON_W
;
173 lme2510_usb_talk(d
, all_pids
, sizeof(all_pids
),
174 rbuff
, sizeof(rbuff
));
175 /*Restart Stream Command*/
176 return lme2510_usb_talk(d
, stream_on
, sizeof(stream_on
),
177 rbuff
, sizeof(rbuff
));
180 static int lme2510_enable_pid(struct dvb_usb_device
*d
, u8 index
, u16 pid_out
)
182 struct lme2510_state
*st
= d
->priv
;
183 static u8 pid_buff
[] = LME_ZERO_PID
;
185 u8 pid_no
= index
* 2;
186 u8 pid_len
= pid_no
+ 2;
188 deb_info(1, "PID Setting Pid %04x", pid_out
);
190 if (st
->pid_size
== 0)
191 ret
|= lme2510_stream_restart(d
);
193 pid_buff
[2] = pid_no
;
194 pid_buff
[3] = (u8
)pid_out
& 0xff;
195 pid_buff
[4] = pid_no
+ 1;
196 pid_buff
[5] = (u8
)(pid_out
>> 8);
198 if (pid_len
> st
->pid_size
)
199 st
->pid_size
= pid_len
;
200 pid_buff
[7] = 0x80 + st
->pid_size
;
202 ret
|= lme2510_usb_talk(d
, pid_buff
,
203 sizeof(pid_buff
) , rbuf
, sizeof(rbuf
));
206 ret
|= lme2510_stream_restart(d
);
211 /* Convert range from 0x00-0xff to 0x0000-0xffff */
212 #define reg_to_16bits(x) ((x) | ((x) << 8))
214 static void lme2510_update_stats(struct dvb_usb_adapter
*adap
)
216 struct lme2510_state
*st
= adap_to_priv(adap
);
217 struct dvb_frontend
*fe
= adap
->fe
[0];
218 struct dtv_frontend_properties
*c
;
219 u32 s_tmp
= 0, c_tmp
= 0;
224 c
= &fe
->dtv_property_cache
;
226 c
->block_count
.len
= 1;
227 c
->block_count
.stat
[0].scale
= FE_SCALE_NOT_AVAILABLE
;
228 c
->block_error
.len
= 1;
229 c
->block_error
.stat
[0].scale
= FE_SCALE_NOT_AVAILABLE
;
230 c
->post_bit_count
.len
= 1;
231 c
->post_bit_count
.stat
[0].scale
= FE_SCALE_NOT_AVAILABLE
;
232 c
->post_bit_error
.len
= 1;
233 c
->post_bit_error
.stat
[0].scale
= FE_SCALE_NOT_AVAILABLE
;
235 if (st
->i2c_talk_onoff
) {
237 c
->strength
.stat
[0].scale
= FE_SCALE_NOT_AVAILABLE
;
239 c
->cnr
.stat
[0].scale
= FE_SCALE_NOT_AVAILABLE
;
243 switch (st
->tuner_config
) {
245 s_tmp
= reg_to_16bits(0xff - st
->signal_level
);
246 c_tmp
= reg_to_16bits(0xff - st
->signal_sn
);
250 s_tmp
= 0xffff - (((st
->signal_level
* 2) << 8) * 5 / 4);
251 c_tmp
= reg_to_16bits((0xff - st
->signal_sn
- 0xa1) * 3);
254 s_tmp
= reg_to_16bits(st
->signal_level
);
255 c_tmp
= reg_to_16bits(st
->signal_sn
);
259 c
->strength
.stat
[0].scale
= FE_SCALE_RELATIVE
;
260 c
->strength
.stat
[0].uvalue
= (u64
)s_tmp
;
263 c
->cnr
.stat
[0].scale
= FE_SCALE_RELATIVE
;
264 c
->cnr
.stat
[0].uvalue
= (u64
)c_tmp
;
267 static void lme2510_int_response(struct urb
*lme_urb
)
269 struct dvb_usb_adapter
*adap
= lme_urb
->context
;
270 struct lme2510_state
*st
= adap_to_priv(adap
);
276 switch (lme_urb
->status
) {
285 info("Error %x", lme_urb
->status
);
289 rbuf
= (u8
*) lme_urb
->transfer_buffer
;
291 offset
= ((lme_urb
->actual_length
/8) > 4)
292 ? 4 : (lme_urb
->actual_length
/8) ;
294 for (i
= 0; i
< offset
; ++i
) {
295 ibuf
= (u8
*)&rbuf
[i
*8];
296 deb_info(5, "INT O/S C =%02x C/O=%02x Type =%02x%02x",
297 offset
, i
, ibuf
[0], ibuf
[1]);
301 debug_data_snipet(1, "INT Remote data snippet", ibuf
);
302 if (!adap_to_d(adap
)->rc_dev
)
305 key
= RC_SCANCODE_NEC32(ibuf
[2] << 24 |
310 deb_info(1, "INT Key = 0x%08x", key
);
311 rc_keydown(adap_to_d(adap
)->rc_dev
, RC_PROTO_NEC32
, key
,
315 switch (st
->tuner_config
) {
317 signal_lock
= ibuf
[2] & BIT(5);
318 st
->signal_level
= ibuf
[4];
319 st
->signal_sn
= ibuf
[3];
320 st
->time_key
= ibuf
[7];
324 /* Tweak for earlier firmware*/
325 if (ibuf
[1] == 0x03) {
326 signal_lock
= ibuf
[2] & BIT(4);
327 st
->signal_level
= ibuf
[3];
328 st
->signal_sn
= ibuf
[4];
330 st
->signal_level
= ibuf
[4];
331 st
->signal_sn
= ibuf
[5];
335 signal_lock
= ibuf
[2] & 0xee;
336 st
->signal_level
= ibuf
[5];
337 st
->signal_sn
= ibuf
[4];
338 st
->time_key
= ibuf
[7];
343 /* Interrupt will also throw just BIT 0 as lock */
344 signal_lock
|= ibuf
[2] & BIT(0);
347 st
->lock_status
&= ~FE_HAS_LOCK
;
349 lme2510_update_stats(adap
);
351 debug_data_snipet(5, "INT Remote data snippet in", ibuf
);
354 debug_data_snipet(1, "INT Control data snippet", ibuf
);
357 debug_data_snipet(1, "INT Unknown data snippet", ibuf
);
362 usb_submit_urb(lme_urb
, GFP_ATOMIC
);
364 /* Interrupt urb is due every 48 msecs while streaming the buffer
365 * stores up to 4 periods if missed. Allow 200 msec for next interrupt.
367 st
->int_urb_due
= jiffies
+ msecs_to_jiffies(200);
370 static int lme2510_int_read(struct dvb_usb_adapter
*adap
)
372 struct dvb_usb_device
*d
= adap_to_d(adap
);
373 struct lme2510_state
*lme_int
= adap_to_priv(adap
);
374 struct usb_host_endpoint
*ep
;
376 lme_int
->lme_urb
= usb_alloc_urb(0, GFP_ATOMIC
);
378 if (lme_int
->lme_urb
== NULL
)
381 usb_fill_int_urb(lme_int
->lme_urb
,
383 usb_rcvintpipe(d
->udev
, 0xa),
385 sizeof(lme_int
->int_buffer
),
386 lme2510_int_response
,
390 /* Quirk of pipe reporting PIPE_BULK but behaves as interrupt */
391 ep
= usb_pipe_endpoint(d
->udev
, lme_int
->lme_urb
->pipe
);
393 if (usb_endpoint_type(&ep
->desc
) == USB_ENDPOINT_XFER_BULK
)
394 lme_int
->lme_urb
->pipe
= usb_rcvbulkpipe(d
->udev
, 0xa),
396 usb_submit_urb(lme_int
->lme_urb
, GFP_ATOMIC
);
397 info("INT Interrupt Service Started");
402 static int lme2510_pid_filter_ctrl(struct dvb_usb_adapter
*adap
, int onoff
)
404 struct dvb_usb_device
*d
= adap_to_d(adap
);
405 struct lme2510_state
*st
= adap_to_priv(adap
);
406 static u8 clear_pid_reg
[] = LME_ALL_PIDS
;
410 deb_info(1, "PID Clearing Filter");
412 mutex_lock(&d
->i2c_mutex
);
415 ret
|= lme2510_usb_talk(d
, clear_pid_reg
,
416 sizeof(clear_pid_reg
), rbuf
, sizeof(rbuf
));
423 mutex_unlock(&d
->i2c_mutex
);
428 static int lme2510_pid_filter(struct dvb_usb_adapter
*adap
, int index
, u16 pid
,
431 struct dvb_usb_device
*d
= adap_to_d(adap
);
434 deb_info(3, "%s PID=%04x Index=%04x onoff=%02x", __func__
,
438 mutex_lock(&d
->i2c_mutex
);
439 ret
|= lme2510_enable_pid(d
, index
, pid
);
440 mutex_unlock(&d
->i2c_mutex
);
448 static int lme2510_return_status(struct dvb_usb_device
*d
)
453 data
= kzalloc(6, GFP_KERNEL
);
457 ret
= usb_control_msg(d
->udev
, usb_rcvctrlpipe(d
->udev
, 0),
458 0x06, 0x80, 0x0302, 0x00,
465 info("Firmware Status: %6ph", data
);
471 static int lme2510_msg(struct dvb_usb_device
*d
,
472 u8
*wbuf
, int wlen
, u8
*rbuf
, int rlen
)
474 struct lme2510_state
*st
= d
->priv
;
476 st
->i2c_talk_onoff
= 1;
478 return lme2510_usb_talk(d
, wbuf
, wlen
, rbuf
, rlen
);
481 static int lme2510_i2c_xfer(struct i2c_adapter
*adap
, struct i2c_msg msg
[],
484 struct dvb_usb_device
*d
= i2c_get_adapdata(adap
);
485 struct lme2510_state
*st
= d
->priv
;
486 static u8 obuf
[64], ibuf
[64];
489 u8 gate
= st
->i2c_gate
;
491 mutex_lock(&d
->i2c_mutex
);
496 for (i
= 0; i
< num
; i
++) {
497 read_o
= msg
[i
].flags
& I2C_M_RD
;
498 read
= i
+ 1 < num
&& msg
[i
+ 1].flags
& I2C_M_RD
;
500 gate
= (msg
[i
].addr
== st
->i2c_tuner_addr
)
501 ? (read
) ? st
->i2c_tuner_gate_r
502 : st
->i2c_tuner_gate_w
504 obuf
[0] = gate
| (read
<< 7);
507 obuf
[1] = (read
) ? 2 : msg
[i
].len
+ 1;
509 obuf
[1] = msg
[i
].len
+ read
+ 1;
511 obuf
[2] = msg
[i
].addr
<< 1;
517 memcpy(&obuf
[3], msg
[i
].buf
, msg
[i
].len
);
518 obuf
[msg
[i
].len
+3] = msg
[i
+1].len
;
522 memcpy(&obuf
[3], msg
[i
].buf
, msg
[i
].len
);
526 if (lme2510_msg(d
, obuf
, len
, ibuf
, 64) < 0) {
527 deb_info(1, "i2c transfer failed.");
528 mutex_unlock(&d
->i2c_mutex
);
534 memcpy(msg
[i
].buf
, &ibuf
[1], msg
[i
].len
);
536 memcpy(msg
[i
+1].buf
, &ibuf
[1], msg
[i
+1].len
);
542 mutex_unlock(&d
->i2c_mutex
);
546 static u32
lme2510_i2c_func(struct i2c_adapter
*adapter
)
551 static struct i2c_algorithm lme2510_i2c_algo
= {
552 .master_xfer
= lme2510_i2c_xfer
,
553 .functionality
= lme2510_i2c_func
,
556 static int lme2510_streaming_ctrl(struct dvb_frontend
*fe
, int onoff
)
558 struct dvb_usb_adapter
*adap
= fe_to_adap(fe
);
559 struct dvb_usb_device
*d
= adap_to_d(adap
);
560 struct lme2510_state
*st
= adap_to_priv(adap
);
561 static u8 clear_reg_3
[] = LME_ALL_PIDS
;
563 int ret
= 0, rlen
= sizeof(rbuf
);
565 deb_info(1, "STM (%02x)", onoff
);
567 /* Streaming is started by FE_HAS_LOCK */
571 deb_info(1, "STM Steam Off");
572 /* mutex is here only to avoid collision with I2C */
573 mutex_lock(&d
->i2c_mutex
);
575 ret
= lme2510_usb_talk(d
, clear_reg_3
,
576 sizeof(clear_reg_3
), rbuf
, rlen
);
578 st
->i2c_talk_onoff
= 1;
580 mutex_unlock(&d
->i2c_mutex
);
583 return (ret
< 0) ? -ENODEV
: 0;
586 static u8
check_sum(u8
*p
, u8 len
)
594 static int lme2510_download_firmware(struct dvb_usb_device
*d
,
595 const struct firmware
*fw
)
599 u16 j
, wlen
, len_in
, start
, end
;
600 u8 packet_size
, dlen
, i
;
606 data
= kzalloc(128, GFP_KERNEL
);
608 info("FRM Could not start Firmware Download"\
609 "(Buffer allocation failed)");
613 info("FRM Starting Firmware Download");
615 for (i
= 1; i
< 3; i
++) {
616 start
= (i
== 1) ? 0 : 512;
617 end
= (i
== 1) ? 512 : fw
->size
;
618 for (j
= start
; j
< end
; j
+= (packet_size
+1)) {
619 fw_data
= (u8
*)(fw
->data
+ j
);
620 if ((end
- j
) > packet_size
) {
625 dlen
= (u8
)(end
- j
)-1;
628 memcpy(&data
[2], fw_data
, dlen
+1);
629 wlen
= (u8
) dlen
+ 4;
630 data
[wlen
-1] = check_sum(fw_data
, dlen
+1);
631 deb_info(1, "Data S=%02x:E=%02x CS= %02x", data
[3],
632 data
[dlen
+2], data
[dlen
+3]);
633 lme2510_usb_talk(d
, data
, wlen
, data
, len_in
);
634 ret
|= (data
[0] == 0x88) ? 0 : -1;
641 lme2510_usb_talk(d
, data
, len_in
, data
, len_in
);
645 info("FRM Firmware Download Failed (%04x)" , ret
);
647 info("FRM Firmware Download Completed - Resetting Device");
650 return RECONNECTS_USB
;
653 static void lme_coldreset(struct dvb_usb_device
*d
)
657 info("FRM Firmware Cold Reset");
659 lme2510_usb_talk(d
, data
, sizeof(data
), data
, sizeof(data
));
664 static const char fw_c_s7395
[] = LME2510_C_S7395
;
665 static const char fw_c_lg
[] = LME2510_C_LG
;
666 static const char fw_c_s0194
[] = LME2510_C_S0194
;
667 static const char fw_c_rs2000
[] = LME2510_C_RS2000
;
668 static const char fw_lg
[] = LME2510_LG
;
669 static const char fw_s0194
[] = LME2510_S0194
;
671 static const char *lme_firmware_switch(struct dvb_usb_device
*d
, int cold
)
673 struct lme2510_state
*st
= d
->priv
;
674 struct usb_device
*udev
= d
->udev
;
675 const struct firmware
*fw
= NULL
;
679 cold
= (cold
> 0) ? (cold
& 1) : 0;
681 switch (le16_to_cpu(udev
->descriptor
.idProduct
)) {
683 switch (st
->dvb_usb_lme2510_firmware
) {
687 ret
= request_firmware(&fw
, fw_lme
, &udev
->dev
);
689 st
->dvb_usb_lme2510_firmware
= TUNER_S0194
;
696 ret
= request_firmware(&fw
, fw_lme
, &udev
->dev
);
698 st
->dvb_usb_lme2510_firmware
= TUNER_LG
;
701 st
->dvb_usb_lme2510_firmware
= TUNER_DEFAULT
;
706 switch (st
->dvb_usb_lme2510_firmware
) {
710 ret
= request_firmware(&fw
, fw_lme
, &udev
->dev
);
712 st
->dvb_usb_lme2510_firmware
= TUNER_S7395
;
719 ret
= request_firmware(&fw
, fw_lme
, &udev
->dev
);
721 st
->dvb_usb_lme2510_firmware
= TUNER_LG
;
727 ret
= request_firmware(&fw
, fw_lme
, &udev
->dev
);
729 st
->dvb_usb_lme2510_firmware
= TUNER_S0194
;
732 st
->dvb_usb_lme2510_firmware
= TUNER_DEFAULT
;
738 fw_lme
= fw_c_rs2000
;
739 st
->dvb_usb_lme2510_firmware
= TUNER_RS2000
;
745 release_firmware(fw
);
748 dvb_usb_lme2510_firmware
= st
->dvb_usb_lme2510_firmware
;
749 info("FRM Changing to %s firmware", fw_lme
);
757 static int lme2510_kill_urb(struct usb_data_stream
*stream
)
761 for (i
= 0; i
< stream
->urbs_submitted
; i
++) {
762 deb_info(3, "killing URB no. %d.", i
);
764 usb_kill_urb(stream
->urb_list
[i
]);
766 stream
->urbs_submitted
= 0;
771 static struct tda10086_config tda10086_config
= {
772 .demod_address
= 0x0e,
775 .xtal_freq
= TDA10086_XTAL_16M
,
778 static struct stv0288_config lme_config
= {
779 .demod_address
= 0x68,
781 .inittab
= s7395_inittab
,
784 static struct ix2505v_config lme_tuner
= {
785 .tuner_address
= 0x60,
788 .tuner_chargepump
= 0x3,
791 static struct stv0299_config sharp_z0194_config
= {
792 .demod_address
= 0x68,
793 .inittab
= sharp_z0194a_inittab
,
797 .lock_output
= STV0299_LOCKOUTPUT_1
,
798 .volt13_op0_op1
= STV0299_VOLT13_OP1
,
800 .set_symbol_rate
= sharp_z0194a_set_symbol_rate
,
803 static struct m88rs2000_config m88rs2000_config
= {
807 static struct ts2020_config ts2020_config
= {
808 .tuner_address
= 0x60,
813 static int dm04_lme2510_set_voltage(struct dvb_frontend
*fe
,
814 enum fe_sec_voltage voltage
)
816 struct dvb_usb_device
*d
= fe_to_d(fe
);
817 struct lme2510_state
*st
= fe_to_priv(fe
);
818 static u8 voltage_low
[] = LME_VOLTAGE_L
;
819 static u8 voltage_high
[] = LME_VOLTAGE_H
;
821 int ret
= 0, len
= 3, rlen
= 1;
823 mutex_lock(&d
->i2c_mutex
);
827 ret
|= lme2510_usb_talk(d
,
828 voltage_high
, len
, rbuf
, rlen
);
831 case SEC_VOLTAGE_OFF
:
834 ret
|= lme2510_usb_talk(d
,
835 voltage_low
, len
, rbuf
, rlen
);
839 mutex_unlock(&d
->i2c_mutex
);
841 if (st
->tuner_config
== TUNER_RS2000
)
842 if (st
->fe_set_voltage
)
843 st
->fe_set_voltage(fe
, voltage
);
846 return (ret
< 0) ? -ENODEV
: 0;
849 static int dm04_read_status(struct dvb_frontend
*fe
, enum fe_status
*status
)
851 struct dvb_usb_device
*d
= fe_to_d(fe
);
852 struct lme2510_state
*st
= d
->priv
;
855 if (st
->i2c_talk_onoff
) {
856 if (st
->fe_read_status
) {
857 ret
= st
->fe_read_status(fe
, status
);
862 st
->lock_status
= *status
;
864 if (*status
& FE_HAS_LOCK
&& st
->stream_on
) {
865 mutex_lock(&d
->i2c_mutex
);
867 st
->i2c_talk_onoff
= 0;
868 ret
= lme2510_stream_restart(d
);
870 mutex_unlock(&d
->i2c_mutex
);
876 /* Timeout of interrupt reached on RS2000 */
877 if (st
->tuner_config
== TUNER_RS2000
&&
878 time_after(jiffies
, st
->int_urb_due
))
879 st
->lock_status
&= ~FE_HAS_LOCK
;
881 *status
= st
->lock_status
;
883 if (!(*status
& FE_HAS_LOCK
)) {
884 struct dvb_usb_adapter
*adap
= fe_to_adap(fe
);
886 st
->i2c_talk_onoff
= 1;
888 lme2510_update_stats(adap
);
894 static int dm04_read_signal_strength(struct dvb_frontend
*fe
, u16
*strength
)
896 struct dtv_frontend_properties
*c
= &fe
->dtv_property_cache
;
897 struct lme2510_state
*st
= fe_to_priv(fe
);
899 if (st
->fe_read_signal_strength
&& !st
->stream_on
)
900 return st
->fe_read_signal_strength(fe
, strength
);
902 if (c
->strength
.stat
[0].scale
== FE_SCALE_RELATIVE
)
903 *strength
= (u16
)c
->strength
.stat
[0].uvalue
;
910 static int dm04_read_snr(struct dvb_frontend
*fe
, u16
*snr
)
912 struct dtv_frontend_properties
*c
= &fe
->dtv_property_cache
;
913 struct lme2510_state
*st
= fe_to_priv(fe
);
915 if (st
->fe_read_snr
&& !st
->stream_on
)
916 return st
->fe_read_snr(fe
, snr
);
918 if (c
->cnr
.stat
[0].scale
== FE_SCALE_RELATIVE
)
919 *snr
= (u16
)c
->cnr
.stat
[0].uvalue
;
926 static int dm04_read_ber(struct dvb_frontend
*fe
, u32
*ber
)
928 struct lme2510_state
*st
= fe_to_priv(fe
);
930 if (st
->fe_read_ber
&& !st
->stream_on
)
931 return st
->fe_read_ber(fe
, ber
);
938 static int dm04_read_ucblocks(struct dvb_frontend
*fe
, u32
*ucblocks
)
940 struct lme2510_state
*st
= fe_to_priv(fe
);
942 if (st
->fe_read_ucblocks
&& !st
->stream_on
)
943 return st
->fe_read_ucblocks(fe
, ucblocks
);
950 static int lme_name(struct dvb_usb_adapter
*adap
)
952 struct dvb_usb_device
*d
= adap_to_d(adap
);
953 struct lme2510_state
*st
= adap_to_priv(adap
);
954 const char *desc
= d
->name
;
955 static const char * const fe_name
[] = {
956 "", " LG TDQY-P001F", " SHARP:BS2F7HZ7395",
957 " SHARP:BS2F7HZ0194", " RS2000"};
958 char *name
= adap
->fe
[0]->ops
.info
.name
;
960 strscpy(name
, desc
, 128);
961 strlcat(name
, fe_name
[st
->tuner_config
], 128);
966 static int dm04_lme2510_frontend_attach(struct dvb_usb_adapter
*adap
)
968 struct dvb_usb_device
*d
= adap_to_d(adap
);
969 struct lme2510_state
*st
= d
->priv
;
972 st
->i2c_talk_onoff
= 1;
973 switch (le16_to_cpu(d
->udev
->descriptor
.idProduct
)) {
977 adap
->fe
[0] = dvb_attach(tda10086_attach
,
978 &tda10086_config
, &d
->i2c_adap
);
980 info("TUN Found Frontend TDA10086");
981 st
->i2c_tuner_gate_w
= 4;
982 st
->i2c_tuner_gate_r
= 4;
983 st
->i2c_tuner_addr
= 0x60;
984 st
->tuner_config
= TUNER_LG
;
985 if (st
->dvb_usb_lme2510_firmware
!= TUNER_LG
) {
986 st
->dvb_usb_lme2510_firmware
= TUNER_LG
;
987 ret
= lme_firmware_switch(d
, 1) ? 0 : -ENODEV
;
993 adap
->fe
[0] = dvb_attach(stv0299_attach
,
994 &sharp_z0194_config
, &d
->i2c_adap
);
996 info("FE Found Stv0299");
997 st
->i2c_tuner_gate_w
= 4;
998 st
->i2c_tuner_gate_r
= 5;
999 st
->i2c_tuner_addr
= 0x60;
1000 st
->tuner_config
= TUNER_S0194
;
1001 if (st
->dvb_usb_lme2510_firmware
!= TUNER_S0194
) {
1002 st
->dvb_usb_lme2510_firmware
= TUNER_S0194
;
1003 ret
= lme_firmware_switch(d
, 1) ? 0 : -ENODEV
;
1009 adap
->fe
[0] = dvb_attach(stv0288_attach
, &lme_config
,
1013 info("FE Found Stv0288");
1014 st
->i2c_tuner_gate_w
= 4;
1015 st
->i2c_tuner_gate_r
= 5;
1016 st
->i2c_tuner_addr
= 0x60;
1017 st
->tuner_config
= TUNER_S7395
;
1018 if (st
->dvb_usb_lme2510_firmware
!= TUNER_S7395
) {
1019 st
->dvb_usb_lme2510_firmware
= TUNER_S7395
;
1020 ret
= lme_firmware_switch(d
, 1) ? 0 : -ENODEV
;
1027 adap
->fe
[0] = dvb_attach(m88rs2000_attach
,
1028 &m88rs2000_config
, &d
->i2c_adap
);
1031 info("FE Found M88RS2000");
1032 st
->i2c_tuner_gate_w
= 5;
1033 st
->i2c_tuner_gate_r
= 5;
1034 st
->i2c_tuner_addr
= 0x60;
1035 st
->tuner_config
= TUNER_RS2000
;
1036 st
->fe_set_voltage
=
1037 adap
->fe
[0]->ops
.set_voltage
;
1042 if (adap
->fe
[0] == NULL
) {
1043 info("DM04/QQBOX Not Powered up or not Supported");
1049 dvb_frontend_detach(adap
->fe
[0]);
1056 st
->fe_read_status
= adap
->fe
[0]->ops
.read_status
;
1057 st
->fe_read_signal_strength
= adap
->fe
[0]->ops
.read_signal_strength
;
1058 st
->fe_read_snr
= adap
->fe
[0]->ops
.read_snr
;
1059 st
->fe_read_ber
= adap
->fe
[0]->ops
.read_ber
;
1060 st
->fe_read_ucblocks
= adap
->fe
[0]->ops
.read_ucblocks
;
1062 adap
->fe
[0]->ops
.read_status
= dm04_read_status
;
1063 adap
->fe
[0]->ops
.read_signal_strength
= dm04_read_signal_strength
;
1064 adap
->fe
[0]->ops
.read_snr
= dm04_read_snr
;
1065 adap
->fe
[0]->ops
.read_ber
= dm04_read_ber
;
1066 adap
->fe
[0]->ops
.read_ucblocks
= dm04_read_ucblocks
;
1067 adap
->fe
[0]->ops
.set_voltage
= dm04_lme2510_set_voltage
;
1069 ret
= lme_name(adap
);
1073 static int dm04_lme2510_tuner(struct dvb_usb_adapter
*adap
)
1075 struct dvb_usb_device
*d
= adap_to_d(adap
);
1076 struct lme2510_state
*st
= adap_to_priv(adap
);
1077 static const char * const tun_msg
[] = {"", "TDA8263", "IX2505V", "DVB_PLL_OPERA", "RS2000"};
1080 switch (st
->tuner_config
) {
1082 if (dvb_attach(tda826x_attach
, adap
->fe
[0], 0x60,
1084 ret
= st
->tuner_config
;
1087 if (dvb_attach(ix2505v_attach
, adap
->fe
[0], &lme_tuner
,
1089 ret
= st
->tuner_config
;
1092 if (dvb_attach(dvb_pll_attach
, adap
->fe
[0], 0x60,
1093 &d
->i2c_adap
, DVB_PLL_OPERA1
))
1094 ret
= st
->tuner_config
;
1097 if (dvb_attach(ts2020_attach
, adap
->fe
[0],
1098 &ts2020_config
, &d
->i2c_adap
))
1099 ret
= st
->tuner_config
;
1106 info("TUN Found %s tuner", tun_msg
[ret
]);
1108 info("TUN No tuner found");
1112 /* Start the Interrupt*/
1113 ret
= lme2510_int_read(adap
);
1115 info("INT Unable to start Interrupt Service");
1122 static int lme2510_powerup(struct dvb_usb_device
*d
, int onoff
)
1124 struct lme2510_state
*st
= d
->priv
;
1125 static u8 lnb_on
[] = LNB_ON
;
1126 static u8 lnb_off
[] = LNB_OFF
;
1128 int ret
= 0, len
= 3, rlen
= 1;
1130 mutex_lock(&d
->i2c_mutex
);
1132 ret
= lme2510_usb_talk(d
, onoff
? lnb_on
: lnb_off
, len
, rbuf
, rlen
);
1134 st
->i2c_talk_onoff
= 1;
1136 mutex_unlock(&d
->i2c_mutex
);
1141 static int lme2510_get_adapter_count(struct dvb_usb_device
*d
)
1146 static int lme2510_identify_state(struct dvb_usb_device
*d
, const char **name
)
1148 struct lme2510_state
*st
= d
->priv
;
1151 usb_reset_configuration(d
->udev
);
1153 usb_set_interface(d
->udev
,
1154 d
->props
->bInterfaceNumber
, 1);
1156 st
->dvb_usb_lme2510_firmware
= dvb_usb_lme2510_firmware
;
1158 status
= lme2510_return_status(d
);
1159 if (status
== 0x44) {
1160 *name
= lme_firmware_switch(d
, 0);
1170 static int lme2510_get_stream_config(struct dvb_frontend
*fe
, u8
*ts_type
,
1171 struct usb_data_stream_properties
*stream
)
1173 struct dvb_usb_adapter
*adap
= fe_to_adap(fe
);
1174 struct dvb_usb_device
*d
;
1179 d
= adap_to_d(adap
);
1181 /* Turn PID filter on the fly by module option */
1182 if (pid_filter
== 2) {
1183 adap
->pid_filtering
= true;
1184 adap
->max_feed_count
= 15;
1187 if (!(le16_to_cpu(d
->udev
->descriptor
.idProduct
)
1189 stream
->endpoint
= 0x8;
1194 static int lme2510_get_rc_config(struct dvb_usb_device
*d
,
1195 struct dvb_usb_rc
*rc
)
1197 rc
->allowed_protos
= RC_PROTO_BIT_NEC32
;
1201 static void lme2510_exit(struct dvb_usb_device
*d
)
1203 struct lme2510_state
*st
= d
->priv
;
1204 struct dvb_usb_adapter
*adap
= &d
->adapter
[0];
1207 lme2510_kill_urb(&adap
->stream
);
1211 usb_kill_urb(st
->lme_urb
);
1212 usb_free_urb(st
->lme_urb
);
1213 info("Interrupt Service Stopped");
1217 static struct dvb_usb_device_properties lme2510_props
= {
1218 .driver_name
= KBUILD_MODNAME
,
1219 .owner
= THIS_MODULE
,
1220 .bInterfaceNumber
= 0,
1221 .adapter_nr
= adapter_nr
,
1222 .size_of_priv
= sizeof(struct lme2510_state
),
1223 .generic_bulk_ctrl_endpoint
= 0x01,
1224 .generic_bulk_ctrl_endpoint_response
= 0x01,
1226 .download_firmware
= lme2510_download_firmware
,
1228 .power_ctrl
= lme2510_powerup
,
1229 .identify_state
= lme2510_identify_state
,
1230 .i2c_algo
= &lme2510_i2c_algo
,
1232 .frontend_attach
= dm04_lme2510_frontend_attach
,
1233 .tuner_attach
= dm04_lme2510_tuner
,
1234 .get_stream_config
= lme2510_get_stream_config
,
1235 .get_adapter_count
= lme2510_get_adapter_count
,
1236 .streaming_ctrl
= lme2510_streaming_ctrl
,
1238 .get_rc_config
= lme2510_get_rc_config
,
1240 .exit
= lme2510_exit
,
1243 .caps
= DVB_USB_ADAP_HAS_PID_FILTER
|
1244 DVB_USB_ADAP_PID_FILTER_CAN_BE_TURNED_OFF
,
1245 .pid_filter_count
= 15,
1246 .pid_filter
= lme2510_pid_filter
,
1247 .pid_filter_ctrl
= lme2510_pid_filter_ctrl
,
1249 DVB_USB_STREAM_BULK(0x86, 10, 4096),
1256 static const struct usb_device_id lme2510_id_table
[] = {
1257 { DVB_USB_DEVICE(0x3344, 0x1122, &lme2510_props
,
1258 "DM04_LME2510_DVB-S", RC_MAP_LME2510
) },
1259 { DVB_USB_DEVICE(0x3344, 0x1120, &lme2510_props
,
1260 "DM04_LME2510C_DVB-S", RC_MAP_LME2510
) },
1261 { DVB_USB_DEVICE(0x3344, 0x22f0, &lme2510_props
,
1262 "DM04_LME2510C_DVB-S RS2000", RC_MAP_LME2510
) },
1263 {} /* Terminating entry */
1266 MODULE_DEVICE_TABLE(usb
, lme2510_id_table
);
1268 static struct usb_driver lme2510_driver
= {
1269 .name
= KBUILD_MODNAME
,
1270 .probe
= dvb_usbv2_probe
,
1271 .disconnect
= dvb_usbv2_disconnect
,
1272 .id_table
= lme2510_id_table
,
1277 module_usb_driver(lme2510_driver
);
1279 MODULE_AUTHOR("Malcolm Priestley <tvboxspy@gmail.com>");
1280 MODULE_DESCRIPTION("LME2510(C) DVB-S USB2.0");
1281 MODULE_VERSION("2.07");
1282 MODULE_LICENSE("GPL");
1283 MODULE_FIRMWARE(LME2510_C_S7395
);
1284 MODULE_FIRMWARE(LME2510_C_LG
);
1285 MODULE_FIRMWARE(LME2510_C_S0194
);
1286 MODULE_FIRMWARE(LME2510_C_RS2000
);
1287 MODULE_FIRMWARE(LME2510_LG
);
1288 MODULE_FIRMWARE(LME2510_S0194
);