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/admin-guide/media/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/driver-api/media/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];
344 /* Interrupt will also throw just BIT 0 as lock */
345 signal_lock
|= ibuf
[2] & BIT(0);
348 st
->lock_status
&= ~FE_HAS_LOCK
;
350 lme2510_update_stats(adap
);
352 debug_data_snipet(5, "INT Remote data snippet in", ibuf
);
355 debug_data_snipet(1, "INT Control data snippet", ibuf
);
358 debug_data_snipet(1, "INT Unknown data snippet", ibuf
);
363 usb_submit_urb(lme_urb
, GFP_ATOMIC
);
365 /* Interrupt urb is due every 48 msecs while streaming the buffer
366 * stores up to 4 periods if missed. Allow 200 msec for next interrupt.
368 st
->int_urb_due
= jiffies
+ msecs_to_jiffies(200);
371 static int lme2510_int_read(struct dvb_usb_adapter
*adap
)
373 struct dvb_usb_device
*d
= adap_to_d(adap
);
374 struct lme2510_state
*lme_int
= adap_to_priv(adap
);
375 struct usb_host_endpoint
*ep
;
377 lme_int
->lme_urb
= usb_alloc_urb(0, GFP_KERNEL
);
379 if (lme_int
->lme_urb
== NULL
)
382 usb_fill_int_urb(lme_int
->lme_urb
,
384 usb_rcvintpipe(d
->udev
, 0xa),
386 sizeof(lme_int
->int_buffer
),
387 lme2510_int_response
,
391 /* Quirk of pipe reporting PIPE_BULK but behaves as interrupt */
392 ep
= usb_pipe_endpoint(d
->udev
, lme_int
->lme_urb
->pipe
);
394 if (usb_endpoint_type(&ep
->desc
) == USB_ENDPOINT_XFER_BULK
)
395 lme_int
->lme_urb
->pipe
= usb_rcvbulkpipe(d
->udev
, 0xa);
397 usb_submit_urb(lme_int
->lme_urb
, GFP_KERNEL
);
398 info("INT Interrupt Service Started");
403 static int lme2510_pid_filter_ctrl(struct dvb_usb_adapter
*adap
, int onoff
)
405 struct dvb_usb_device
*d
= adap_to_d(adap
);
406 struct lme2510_state
*st
= adap_to_priv(adap
);
407 static u8 clear_pid_reg
[] = LME_ALL_PIDS
;
411 deb_info(1, "PID Clearing Filter");
413 mutex_lock(&d
->i2c_mutex
);
416 ret
|= lme2510_usb_talk(d
, clear_pid_reg
,
417 sizeof(clear_pid_reg
), rbuf
, sizeof(rbuf
));
424 mutex_unlock(&d
->i2c_mutex
);
432 static int lme2510_pid_filter(struct dvb_usb_adapter
*adap
, int index
, u16 pid
,
435 struct dvb_usb_device
*d
= adap_to_d(adap
);
438 deb_info(3, "%s PID=%04x Index=%04x onoff=%02x", __func__
,
442 mutex_lock(&d
->i2c_mutex
);
443 ret
|= lme2510_enable_pid(d
, index
, pid
);
444 mutex_unlock(&d
->i2c_mutex
);
452 static int lme2510_return_status(struct dvb_usb_device
*d
)
457 data
= kzalloc(6, GFP_KERNEL
);
461 ret
= usb_control_msg(d
->udev
, usb_rcvctrlpipe(d
->udev
, 0),
462 0x06, 0x80, 0x0302, 0x00,
469 info("Firmware Status: %6ph", data
);
475 static int lme2510_msg(struct dvb_usb_device
*d
,
476 u8
*wbuf
, int wlen
, u8
*rbuf
, int rlen
)
478 struct lme2510_state
*st
= d
->priv
;
480 st
->i2c_talk_onoff
= 1;
482 return lme2510_usb_talk(d
, wbuf
, wlen
, rbuf
, rlen
);
485 static int lme2510_i2c_xfer(struct i2c_adapter
*adap
, struct i2c_msg msg
[],
488 struct dvb_usb_device
*d
= i2c_get_adapdata(adap
);
489 struct lme2510_state
*st
= d
->priv
;
490 static u8 obuf
[64], ibuf
[64];
495 mutex_lock(&d
->i2c_mutex
);
497 for (i
= 0; i
< num
; i
++) {
498 read_o
= msg
[i
].flags
& I2C_M_RD
;
499 read
= i
+ 1 < num
&& msg
[i
+ 1].flags
& I2C_M_RD
;
501 gate
= (msg
[i
].addr
== st
->i2c_tuner_addr
)
502 ? (read
) ? st
->i2c_tuner_gate_r
503 : st
->i2c_tuner_gate_w
505 obuf
[0] = gate
| (read
<< 7);
508 obuf
[1] = (read
) ? 2 : msg
[i
].len
+ 1;
510 obuf
[1] = msg
[i
].len
+ read
+ 1;
512 obuf
[2] = msg
[i
].addr
<< 1;
518 memcpy(&obuf
[3], msg
[i
].buf
, msg
[i
].len
);
519 obuf
[msg
[i
].len
+3] = msg
[i
+1].len
;
523 memcpy(&obuf
[3], msg
[i
].buf
, msg
[i
].len
);
527 if (lme2510_msg(d
, obuf
, len
, ibuf
, 64) < 0) {
528 deb_info(1, "i2c transfer failed.");
529 mutex_unlock(&d
->i2c_mutex
);
535 memcpy(msg
[i
].buf
, &ibuf
[1], msg
[i
].len
);
537 memcpy(msg
[i
+1].buf
, &ibuf
[1], msg
[i
+1].len
);
543 mutex_unlock(&d
->i2c_mutex
);
547 static u32
lme2510_i2c_func(struct i2c_adapter
*adapter
)
552 static struct i2c_algorithm lme2510_i2c_algo
= {
553 .master_xfer
= lme2510_i2c_xfer
,
554 .functionality
= lme2510_i2c_func
,
557 static int lme2510_streaming_ctrl(struct dvb_frontend
*fe
, int onoff
)
559 struct dvb_usb_adapter
*adap
= fe_to_adap(fe
);
560 struct dvb_usb_device
*d
= adap_to_d(adap
);
561 struct lme2510_state
*st
= adap_to_priv(adap
);
562 static u8 clear_reg_3
[] = LME_ALL_PIDS
;
564 int ret
= 0, rlen
= sizeof(rbuf
);
566 deb_info(1, "STM (%02x)", onoff
);
568 /* Streaming is started by FE_HAS_LOCK */
572 deb_info(1, "STM Steam Off");
573 /* mutex is here only to avoid collision with I2C */
574 mutex_lock(&d
->i2c_mutex
);
576 ret
= lme2510_usb_talk(d
, clear_reg_3
,
577 sizeof(clear_reg_3
), rbuf
, rlen
);
579 st
->i2c_talk_onoff
= 1;
581 mutex_unlock(&d
->i2c_mutex
);
584 return (ret
< 0) ? -ENODEV
: 0;
587 static u8
check_sum(u8
*p
, u8 len
)
595 static int lme2510_download_firmware(struct dvb_usb_device
*d
,
596 const struct firmware
*fw
)
600 u16 j
, wlen
, len_in
, start
, end
;
601 u8 packet_size
, dlen
, i
;
607 data
= kzalloc(128, GFP_KERNEL
);
609 info("FRM Could not start Firmware Download"\
610 "(Buffer allocation failed)");
614 info("FRM Starting Firmware Download");
616 for (i
= 1; i
< 3; i
++) {
617 start
= (i
== 1) ? 0 : 512;
618 end
= (i
== 1) ? 512 : fw
->size
;
619 for (j
= start
; j
< end
; j
+= (packet_size
+1)) {
620 fw_data
= (u8
*)(fw
->data
+ j
);
621 if ((end
- j
) > packet_size
) {
626 dlen
= (u8
)(end
- j
)-1;
629 memcpy(&data
[2], fw_data
, dlen
+1);
630 wlen
= (u8
) dlen
+ 4;
631 data
[wlen
-1] = check_sum(fw_data
, dlen
+1);
632 deb_info(1, "Data S=%02x:E=%02x CS= %02x", data
[3],
633 data
[dlen
+2], data
[dlen
+3]);
634 lme2510_usb_talk(d
, data
, wlen
, data
, len_in
);
635 ret
|= (data
[0] == 0x88) ? 0 : -1;
642 lme2510_usb_talk(d
, data
, len_in
, data
, len_in
);
646 info("FRM Firmware Download Failed (%04x)" , ret
);
648 info("FRM Firmware Download Completed - Resetting Device");
651 return RECONNECTS_USB
;
654 static void lme_coldreset(struct dvb_usb_device
*d
)
658 info("FRM Firmware Cold Reset");
660 lme2510_usb_talk(d
, data
, sizeof(data
), data
, sizeof(data
));
665 static const char fw_c_s7395
[] = LME2510_C_S7395
;
666 static const char fw_c_lg
[] = LME2510_C_LG
;
667 static const char fw_c_s0194
[] = LME2510_C_S0194
;
668 static const char fw_c_rs2000
[] = LME2510_C_RS2000
;
669 static const char fw_lg
[] = LME2510_LG
;
670 static const char fw_s0194
[] = LME2510_S0194
;
672 static const char *lme_firmware_switch(struct dvb_usb_device
*d
, int cold
)
674 struct lme2510_state
*st
= d
->priv
;
675 struct usb_device
*udev
= d
->udev
;
676 const struct firmware
*fw
= NULL
;
680 cold
= (cold
> 0) ? (cold
& 1) : 0;
682 switch (le16_to_cpu(udev
->descriptor
.idProduct
)) {
684 switch (st
->dvb_usb_lme2510_firmware
) {
688 ret
= request_firmware(&fw
, fw_lme
, &udev
->dev
);
690 st
->dvb_usb_lme2510_firmware
= TUNER_S0194
;
697 ret
= request_firmware(&fw
, fw_lme
, &udev
->dev
);
699 st
->dvb_usb_lme2510_firmware
= TUNER_LG
;
702 st
->dvb_usb_lme2510_firmware
= TUNER_DEFAULT
;
707 switch (st
->dvb_usb_lme2510_firmware
) {
711 ret
= request_firmware(&fw
, fw_lme
, &udev
->dev
);
713 st
->dvb_usb_lme2510_firmware
= TUNER_S7395
;
720 ret
= request_firmware(&fw
, fw_lme
, &udev
->dev
);
722 st
->dvb_usb_lme2510_firmware
= TUNER_LG
;
728 ret
= request_firmware(&fw
, fw_lme
, &udev
->dev
);
730 st
->dvb_usb_lme2510_firmware
= TUNER_S0194
;
733 st
->dvb_usb_lme2510_firmware
= TUNER_DEFAULT
;
739 fw_lme
= fw_c_rs2000
;
740 st
->dvb_usb_lme2510_firmware
= TUNER_RS2000
;
746 release_firmware(fw
);
749 dvb_usb_lme2510_firmware
= st
->dvb_usb_lme2510_firmware
;
750 info("FRM Changing to %s firmware", fw_lme
);
758 static struct tda10086_config tda10086_config
= {
759 .demod_address
= 0x0e,
762 .xtal_freq
= TDA10086_XTAL_16M
,
765 static struct stv0288_config lme_config
= {
766 .demod_address
= 0x68,
768 .inittab
= s7395_inittab
,
771 static struct ix2505v_config lme_tuner
= {
772 .tuner_address
= 0x60,
775 .tuner_chargepump
= 0x3,
778 static struct stv0299_config sharp_z0194_config
= {
779 .demod_address
= 0x68,
780 .inittab
= sharp_z0194a_inittab
,
784 .lock_output
= STV0299_LOCKOUTPUT_1
,
785 .volt13_op0_op1
= STV0299_VOLT13_OP1
,
787 .set_symbol_rate
= sharp_z0194a_set_symbol_rate
,
790 static struct m88rs2000_config m88rs2000_config
= {
794 static struct ts2020_config ts2020_config
= {
795 .tuner_address
= 0x60,
800 static int dm04_lme2510_set_voltage(struct dvb_frontend
*fe
,
801 enum fe_sec_voltage voltage
)
803 struct dvb_usb_device
*d
= fe_to_d(fe
);
804 struct lme2510_state
*st
= fe_to_priv(fe
);
805 static u8 voltage_low
[] = LME_VOLTAGE_L
;
806 static u8 voltage_high
[] = LME_VOLTAGE_H
;
808 int ret
= 0, len
= 3, rlen
= 1;
810 mutex_lock(&d
->i2c_mutex
);
814 ret
|= lme2510_usb_talk(d
,
815 voltage_high
, len
, rbuf
, rlen
);
818 case SEC_VOLTAGE_OFF
:
821 ret
|= lme2510_usb_talk(d
,
822 voltage_low
, len
, rbuf
, rlen
);
826 mutex_unlock(&d
->i2c_mutex
);
828 if (st
->tuner_config
== TUNER_RS2000
)
829 if (st
->fe_set_voltage
)
830 st
->fe_set_voltage(fe
, voltage
);
833 return (ret
< 0) ? -ENODEV
: 0;
836 static int dm04_read_status(struct dvb_frontend
*fe
, enum fe_status
*status
)
838 struct dvb_usb_device
*d
= fe_to_d(fe
);
839 struct lme2510_state
*st
= d
->priv
;
842 if (st
->i2c_talk_onoff
) {
843 if (st
->fe_read_status
) {
844 ret
= st
->fe_read_status(fe
, status
);
849 st
->lock_status
= *status
;
851 if (*status
& FE_HAS_LOCK
&& st
->stream_on
) {
852 mutex_lock(&d
->i2c_mutex
);
854 st
->i2c_talk_onoff
= 0;
855 ret
= lme2510_stream_restart(d
);
857 mutex_unlock(&d
->i2c_mutex
);
863 /* Timeout of interrupt reached on RS2000 */
864 if (st
->tuner_config
== TUNER_RS2000
&&
865 time_after(jiffies
, st
->int_urb_due
))
866 st
->lock_status
&= ~FE_HAS_LOCK
;
868 *status
= st
->lock_status
;
870 if (!(*status
& FE_HAS_LOCK
)) {
871 struct dvb_usb_adapter
*adap
= fe_to_adap(fe
);
873 st
->i2c_talk_onoff
= 1;
875 lme2510_update_stats(adap
);
881 static int dm04_read_signal_strength(struct dvb_frontend
*fe
, u16
*strength
)
883 struct dtv_frontend_properties
*c
= &fe
->dtv_property_cache
;
884 struct lme2510_state
*st
= fe_to_priv(fe
);
886 if (st
->fe_read_signal_strength
&& !st
->stream_on
)
887 return st
->fe_read_signal_strength(fe
, strength
);
889 if (c
->strength
.stat
[0].scale
== FE_SCALE_RELATIVE
)
890 *strength
= (u16
)c
->strength
.stat
[0].uvalue
;
897 static int dm04_read_snr(struct dvb_frontend
*fe
, u16
*snr
)
899 struct dtv_frontend_properties
*c
= &fe
->dtv_property_cache
;
900 struct lme2510_state
*st
= fe_to_priv(fe
);
902 if (st
->fe_read_snr
&& !st
->stream_on
)
903 return st
->fe_read_snr(fe
, snr
);
905 if (c
->cnr
.stat
[0].scale
== FE_SCALE_RELATIVE
)
906 *snr
= (u16
)c
->cnr
.stat
[0].uvalue
;
913 static int dm04_read_ber(struct dvb_frontend
*fe
, u32
*ber
)
915 struct lme2510_state
*st
= fe_to_priv(fe
);
917 if (st
->fe_read_ber
&& !st
->stream_on
)
918 return st
->fe_read_ber(fe
, ber
);
925 static int dm04_read_ucblocks(struct dvb_frontend
*fe
, u32
*ucblocks
)
927 struct lme2510_state
*st
= fe_to_priv(fe
);
929 if (st
->fe_read_ucblocks
&& !st
->stream_on
)
930 return st
->fe_read_ucblocks(fe
, ucblocks
);
937 static int lme_name(struct dvb_usb_adapter
*adap
)
939 struct dvb_usb_device
*d
= adap_to_d(adap
);
940 struct lme2510_state
*st
= adap_to_priv(adap
);
941 const char *desc
= d
->name
;
942 static const char * const fe_name
[] = {
943 "", " LG TDQY-P001F", " SHARP:BS2F7HZ7395",
944 " SHARP:BS2F7HZ0194", " RS2000"};
945 char *name
= adap
->fe
[0]->ops
.info
.name
;
947 strscpy(name
, desc
, 128);
948 strlcat(name
, fe_name
[st
->tuner_config
], 128);
953 static int dm04_lme2510_frontend_attach(struct dvb_usb_adapter
*adap
)
955 struct dvb_usb_device
*d
= adap_to_d(adap
);
956 struct lme2510_state
*st
= d
->priv
;
959 st
->i2c_talk_onoff
= 1;
960 switch (le16_to_cpu(d
->udev
->descriptor
.idProduct
)) {
964 adap
->fe
[0] = dvb_attach(tda10086_attach
,
965 &tda10086_config
, &d
->i2c_adap
);
967 info("TUN Found Frontend TDA10086");
968 st
->i2c_tuner_gate_w
= 4;
969 st
->i2c_tuner_gate_r
= 4;
970 st
->i2c_tuner_addr
= 0x60;
971 st
->tuner_config
= TUNER_LG
;
972 if (st
->dvb_usb_lme2510_firmware
!= TUNER_LG
) {
973 st
->dvb_usb_lme2510_firmware
= TUNER_LG
;
974 ret
= lme_firmware_switch(d
, 1) ? 0 : -ENODEV
;
980 adap
->fe
[0] = dvb_attach(stv0299_attach
,
981 &sharp_z0194_config
, &d
->i2c_adap
);
983 info("FE Found Stv0299");
984 st
->i2c_tuner_gate_w
= 4;
985 st
->i2c_tuner_gate_r
= 5;
986 st
->i2c_tuner_addr
= 0x60;
987 st
->tuner_config
= TUNER_S0194
;
988 if (st
->dvb_usb_lme2510_firmware
!= TUNER_S0194
) {
989 st
->dvb_usb_lme2510_firmware
= TUNER_S0194
;
990 ret
= lme_firmware_switch(d
, 1) ? 0 : -ENODEV
;
996 adap
->fe
[0] = dvb_attach(stv0288_attach
, &lme_config
,
1000 info("FE Found Stv0288");
1001 st
->i2c_tuner_gate_w
= 4;
1002 st
->i2c_tuner_gate_r
= 5;
1003 st
->i2c_tuner_addr
= 0x60;
1004 st
->tuner_config
= TUNER_S7395
;
1005 if (st
->dvb_usb_lme2510_firmware
!= TUNER_S7395
) {
1006 st
->dvb_usb_lme2510_firmware
= TUNER_S7395
;
1007 ret
= lme_firmware_switch(d
, 1) ? 0 : -ENODEV
;
1014 adap
->fe
[0] = dvb_attach(m88rs2000_attach
,
1015 &m88rs2000_config
, &d
->i2c_adap
);
1018 info("FE Found M88RS2000");
1019 st
->i2c_tuner_gate_w
= 5;
1020 st
->i2c_tuner_gate_r
= 5;
1021 st
->i2c_tuner_addr
= 0x60;
1022 st
->tuner_config
= TUNER_RS2000
;
1023 st
->fe_set_voltage
=
1024 adap
->fe
[0]->ops
.set_voltage
;
1029 if (adap
->fe
[0] == NULL
) {
1030 info("DM04/QQBOX Not Powered up or not Supported");
1036 dvb_frontend_detach(adap
->fe
[0]);
1043 st
->fe_read_status
= adap
->fe
[0]->ops
.read_status
;
1044 st
->fe_read_signal_strength
= adap
->fe
[0]->ops
.read_signal_strength
;
1045 st
->fe_read_snr
= adap
->fe
[0]->ops
.read_snr
;
1046 st
->fe_read_ber
= adap
->fe
[0]->ops
.read_ber
;
1047 st
->fe_read_ucblocks
= adap
->fe
[0]->ops
.read_ucblocks
;
1049 adap
->fe
[0]->ops
.read_status
= dm04_read_status
;
1050 adap
->fe
[0]->ops
.read_signal_strength
= dm04_read_signal_strength
;
1051 adap
->fe
[0]->ops
.read_snr
= dm04_read_snr
;
1052 adap
->fe
[0]->ops
.read_ber
= dm04_read_ber
;
1053 adap
->fe
[0]->ops
.read_ucblocks
= dm04_read_ucblocks
;
1054 adap
->fe
[0]->ops
.set_voltage
= dm04_lme2510_set_voltage
;
1056 ret
= lme_name(adap
);
1060 static int dm04_lme2510_tuner(struct dvb_usb_adapter
*adap
)
1062 struct dvb_usb_device
*d
= adap_to_d(adap
);
1063 struct lme2510_state
*st
= adap_to_priv(adap
);
1064 static const char * const tun_msg
[] = {"", "TDA8263", "IX2505V", "DVB_PLL_OPERA", "RS2000"};
1067 switch (st
->tuner_config
) {
1069 if (dvb_attach(tda826x_attach
, adap
->fe
[0], 0x60,
1071 ret
= st
->tuner_config
;
1074 if (dvb_attach(ix2505v_attach
, adap
->fe
[0], &lme_tuner
,
1076 ret
= st
->tuner_config
;
1079 if (dvb_attach(dvb_pll_attach
, adap
->fe
[0], 0x60,
1080 &d
->i2c_adap
, DVB_PLL_OPERA1
))
1081 ret
= st
->tuner_config
;
1084 if (dvb_attach(ts2020_attach
, adap
->fe
[0],
1085 &ts2020_config
, &d
->i2c_adap
))
1086 ret
= st
->tuner_config
;
1093 info("TUN Found %s tuner", tun_msg
[ret
]);
1095 info("TUN No tuner found");
1099 /* Start the Interrupt*/
1100 ret
= lme2510_int_read(adap
);
1102 info("INT Unable to start Interrupt Service");
1109 static int lme2510_powerup(struct dvb_usb_device
*d
, int onoff
)
1111 struct lme2510_state
*st
= d
->priv
;
1112 static u8 lnb_on
[] = LNB_ON
;
1113 static u8 lnb_off
[] = LNB_OFF
;
1115 int ret
= 0, len
= 3, rlen
= 1;
1117 mutex_lock(&d
->i2c_mutex
);
1119 ret
= lme2510_usb_talk(d
, onoff
? lnb_on
: lnb_off
, len
, rbuf
, rlen
);
1121 st
->i2c_talk_onoff
= 1;
1123 mutex_unlock(&d
->i2c_mutex
);
1128 static int lme2510_identify_state(struct dvb_usb_device
*d
, const char **name
)
1130 struct lme2510_state
*st
= d
->priv
;
1133 usb_reset_configuration(d
->udev
);
1135 usb_set_interface(d
->udev
,
1136 d
->props
->bInterfaceNumber
, 1);
1138 st
->dvb_usb_lme2510_firmware
= dvb_usb_lme2510_firmware
;
1140 status
= lme2510_return_status(d
);
1141 if (status
== 0x44) {
1142 *name
= lme_firmware_switch(d
, 0);
1152 static int lme2510_get_stream_config(struct dvb_frontend
*fe
, u8
*ts_type
,
1153 struct usb_data_stream_properties
*stream
)
1155 struct dvb_usb_adapter
*adap
= fe_to_adap(fe
);
1156 struct dvb_usb_device
*d
;
1161 d
= adap_to_d(adap
);
1163 /* Turn PID filter on the fly by module option */
1164 if (pid_filter
== 2) {
1165 adap
->pid_filtering
= true;
1166 adap
->max_feed_count
= 15;
1169 if (!(le16_to_cpu(d
->udev
->descriptor
.idProduct
)
1171 stream
->endpoint
= 0x8;
1176 static int lme2510_get_rc_config(struct dvb_usb_device
*d
,
1177 struct dvb_usb_rc
*rc
)
1179 rc
->allowed_protos
= RC_PROTO_BIT_NEC32
;
1183 static void lme2510_exit(struct dvb_usb_device
*d
)
1185 struct lme2510_state
*st
= d
->priv
;
1188 usb_kill_urb(st
->lme_urb
);
1189 usb_free_urb(st
->lme_urb
);
1190 info("Interrupt Service Stopped");
1194 static struct dvb_usb_device_properties lme2510_props
= {
1195 .driver_name
= KBUILD_MODNAME
,
1196 .owner
= THIS_MODULE
,
1197 .bInterfaceNumber
= 0,
1198 .adapter_nr
= adapter_nr
,
1199 .size_of_priv
= sizeof(struct lme2510_state
),
1200 .generic_bulk_ctrl_endpoint
= 0x01,
1201 .generic_bulk_ctrl_endpoint_response
= 0x01,
1203 .download_firmware
= lme2510_download_firmware
,
1205 .power_ctrl
= lme2510_powerup
,
1206 .identify_state
= lme2510_identify_state
,
1207 .i2c_algo
= &lme2510_i2c_algo
,
1209 .frontend_attach
= dm04_lme2510_frontend_attach
,
1210 .tuner_attach
= dm04_lme2510_tuner
,
1211 .get_stream_config
= lme2510_get_stream_config
,
1212 .streaming_ctrl
= lme2510_streaming_ctrl
,
1214 .get_rc_config
= lme2510_get_rc_config
,
1216 .exit
= lme2510_exit
,
1220 .caps
= DVB_USB_ADAP_HAS_PID_FILTER
|
1221 DVB_USB_ADAP_PID_FILTER_CAN_BE_TURNED_OFF
,
1222 .pid_filter_count
= 15,
1223 .pid_filter
= lme2510_pid_filter
,
1224 .pid_filter_ctrl
= lme2510_pid_filter_ctrl
,
1226 DVB_USB_STREAM_BULK(0x86, 10, 4096),
1231 static const struct usb_device_id lme2510_id_table
[] = {
1232 { DVB_USB_DEVICE(0x3344, 0x1122, &lme2510_props
,
1233 "DM04_LME2510_DVB-S", RC_MAP_LME2510
) },
1234 { DVB_USB_DEVICE(0x3344, 0x1120, &lme2510_props
,
1235 "DM04_LME2510C_DVB-S", RC_MAP_LME2510
) },
1236 { DVB_USB_DEVICE(0x3344, 0x22f0, &lme2510_props
,
1237 "DM04_LME2510C_DVB-S RS2000", RC_MAP_LME2510
) },
1238 {} /* Terminating entry */
1241 MODULE_DEVICE_TABLE(usb
, lme2510_id_table
);
1243 static struct usb_driver lme2510_driver
= {
1244 .name
= KBUILD_MODNAME
,
1245 .probe
= dvb_usbv2_probe
,
1246 .disconnect
= dvb_usbv2_disconnect
,
1247 .id_table
= lme2510_id_table
,
1252 module_usb_driver(lme2510_driver
);
1254 MODULE_AUTHOR("Malcolm Priestley <tvboxspy@gmail.com>");
1255 MODULE_DESCRIPTION("LME2510(C) DVB-S USB2.0");
1256 MODULE_VERSION("2.07");
1257 MODULE_LICENSE("GPL");
1258 MODULE_FIRMWARE(LME2510_C_S7395
);
1259 MODULE_FIRMWARE(LME2510_C_LG
);
1260 MODULE_FIRMWARE(LME2510_C_S0194
);
1261 MODULE_FIRMWARE(LME2510_C_RS2000
);
1262 MODULE_FIRMWARE(LME2510_LG
);
1263 MODULE_FIRMWARE(LME2510_S0194
);