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.
52 * see Documentation/dvb/README.dvb-usb for more information
55 * LME2510: Non Intel USB chipsets fail to maintain High Speed on
58 * QQbox suffers from noise on LNB voltage.
60 * LME2510: SHARP:BS2F7HZ0194(MV0194) cannot cold reset and share system
61 * with other tuners. After a cold reset streaming will not start.
63 * M88RS2000 suffers from loss of lock.
65 #define DVB_USB_LOG_PREFIX "LME2510(C)"
66 #include <linux/usb.h>
67 #include <linux/usb/input.h>
68 #include <media/rc-core.h>
79 #include "m88rs2000.h"
83 #define LME2510_C_S7395 "dvb-usb-lme2510c-s7395.fw";
84 #define LME2510_C_LG "dvb-usb-lme2510c-lg.fw";
85 #define LME2510_C_S0194 "dvb-usb-lme2510c-s0194.fw";
86 #define LME2510_C_RS2000 "dvb-usb-lme2510c-rs2000.fw";
87 #define LME2510_LG "dvb-usb-lme2510-lg.fw";
88 #define LME2510_S0194 "dvb-usb-lme2510-s0194.fw";
91 static int dvb_usb_lme2510_debug
;
92 #define lme_debug(var, level, args...) do { \
94 pr_debug(DVB_USB_LOG_PREFIX": " args); \
96 #define deb_info(level, args...) lme_debug(dvb_usb_lme2510_debug, level, args)
97 #define debug_data_snipet(level, name, p) \
98 deb_info(level, name" (%8phN)", p);
99 #define info(args...) pr_info(DVB_USB_LOG_PREFIX": "args)
101 module_param_named(debug
, dvb_usb_lme2510_debug
, int, 0644);
102 MODULE_PARM_DESC(debug
, "set debugging level (1=info (or-able)).");
104 static int dvb_usb_lme2510_firmware
;
105 module_param_named(firmware
, dvb_usb_lme2510_firmware
, int, 0644);
106 MODULE_PARM_DESC(firmware
, "set default firmware 0=Sharp7395 1=LG");
108 static int pid_filter
;
109 module_param_named(pid
, pid_filter
, int, 0644);
110 MODULE_PARM_DESC(pid
, "set default 0=default 1=off 2=on");
113 DVB_DEFINE_MOD_OPT_ADAPTER_NR(adapter_nr
);
115 #define TUNER_DEFAULT 0x0
117 #define TUNER_S7395 0x2
118 #define TUNER_S0194 0x3
119 #define TUNER_RS2000 0x4
121 struct lme2510_state
{
122 unsigned long int_urb_due
;
123 enum fe_status lock_status
;
140 /* Frontend original calls */
141 int (*fe_read_status
)(struct dvb_frontend
*, enum fe_status
*);
142 int (*fe_read_signal_strength
)(struct dvb_frontend
*, u16
*);
143 int (*fe_read_snr
)(struct dvb_frontend
*, u16
*);
144 int (*fe_read_ber
)(struct dvb_frontend
*, u32
*);
145 int (*fe_read_ucblocks
)(struct dvb_frontend
*, u32
*);
146 int (*fe_set_voltage
)(struct dvb_frontend
*, enum fe_sec_voltage
);
147 u8 dvb_usb_lme2510_firmware
;
150 static int lme2510_bulk_write(struct usb_device
*dev
,
151 u8
*snd
, int len
, u8 pipe
)
155 return usb_bulk_msg(dev
, usb_sndbulkpipe(dev
, pipe
),
156 snd
, len
, &actual_l
, 100);
159 static int lme2510_bulk_read(struct usb_device
*dev
,
160 u8
*rev
, int len
, u8 pipe
)
164 return usb_bulk_msg(dev
, usb_rcvbulkpipe(dev
, pipe
),
165 rev
, len
, &actual_l
, 200);
168 static int lme2510_usb_talk(struct dvb_usb_device
*d
,
169 u8
*wbuf
, int wlen
, u8
*rbuf
, int rlen
)
171 struct lme2510_state
*st
= d
->priv
;
175 if (st
->usb_buffer
== NULL
) {
176 st
->usb_buffer
= kmalloc(64, GFP_KERNEL
);
177 if (st
->usb_buffer
== NULL
) {
178 info("MEM Error no memory");
182 buff
= st
->usb_buffer
;
184 ret
= mutex_lock_interruptible(&d
->usb_mutex
);
189 /* the read/write capped at 64 */
190 memcpy(buff
, wbuf
, (wlen
< 64) ? wlen
: 64);
192 ret
|= lme2510_bulk_write(d
->udev
, buff
, wlen
, 0x01);
194 ret
|= lme2510_bulk_read(d
->udev
, buff
, (rlen
< 64) ?
198 memcpy(rbuf
, buff
, rlen
);
200 mutex_unlock(&d
->usb_mutex
);
202 return (ret
< 0) ? -ENODEV
: 0;
205 static int lme2510_stream_restart(struct dvb_usb_device
*d
)
207 struct lme2510_state
*st
= d
->priv
;
208 u8 all_pids
[] = LME_ALL_PIDS
;
209 u8 stream_on
[] = LME_ST_ON_W
;
212 lme2510_usb_talk(d
, all_pids
, sizeof(all_pids
),
213 rbuff
, sizeof(rbuff
));
214 /*Restart Stream Command*/
215 return lme2510_usb_talk(d
, stream_on
, sizeof(stream_on
),
216 rbuff
, sizeof(rbuff
));
219 static int lme2510_enable_pid(struct dvb_usb_device
*d
, u8 index
, u16 pid_out
)
221 struct lme2510_state
*st
= d
->priv
;
222 static u8 pid_buff
[] = LME_ZERO_PID
;
224 u8 pid_no
= index
* 2;
225 u8 pid_len
= pid_no
+ 2;
227 deb_info(1, "PID Setting Pid %04x", pid_out
);
229 if (st
->pid_size
== 0)
230 ret
|= lme2510_stream_restart(d
);
232 pid_buff
[2] = pid_no
;
233 pid_buff
[3] = (u8
)pid_out
& 0xff;
234 pid_buff
[4] = pid_no
+ 1;
235 pid_buff
[5] = (u8
)(pid_out
>> 8);
237 if (pid_len
> st
->pid_size
)
238 st
->pid_size
= pid_len
;
239 pid_buff
[7] = 0x80 + st
->pid_size
;
241 ret
|= lme2510_usb_talk(d
, pid_buff
,
242 sizeof(pid_buff
) , rbuf
, sizeof(rbuf
));
245 ret
|= lme2510_stream_restart(d
);
250 /* Convert range from 0x00-0xff to 0x0000-0xffff */
251 #define reg_to_16bits(x) ((x) | ((x) << 8))
253 static void lme2510_update_stats(struct dvb_usb_adapter
*adap
)
255 struct lme2510_state
*st
= adap_to_priv(adap
);
256 struct dvb_frontend
*fe
= adap
->fe
[0];
257 struct dtv_frontend_properties
*c
;
258 u32 s_tmp
= 0, c_tmp
= 0;
263 c
= &fe
->dtv_property_cache
;
265 c
->block_count
.len
= 1;
266 c
->block_count
.stat
[0].scale
= FE_SCALE_NOT_AVAILABLE
;
267 c
->block_error
.len
= 1;
268 c
->block_error
.stat
[0].scale
= FE_SCALE_NOT_AVAILABLE
;
269 c
->post_bit_count
.len
= 1;
270 c
->post_bit_count
.stat
[0].scale
= FE_SCALE_NOT_AVAILABLE
;
271 c
->post_bit_error
.len
= 1;
272 c
->post_bit_error
.stat
[0].scale
= FE_SCALE_NOT_AVAILABLE
;
274 if (st
->i2c_talk_onoff
) {
276 c
->strength
.stat
[0].scale
= FE_SCALE_NOT_AVAILABLE
;
278 c
->cnr
.stat
[0].scale
= FE_SCALE_NOT_AVAILABLE
;
282 switch (st
->tuner_config
) {
284 s_tmp
= reg_to_16bits(0xff - st
->signal_level
);
285 c_tmp
= reg_to_16bits(0xff - st
->signal_sn
);
289 s_tmp
= 0xffff - (((st
->signal_level
* 2) << 8) * 5 / 4);
290 c_tmp
= reg_to_16bits((0xff - st
->signal_sn
- 0xa1) * 3);
293 s_tmp
= reg_to_16bits(st
->signal_level
);
294 c_tmp
= reg_to_16bits(st
->signal_sn
);
298 c
->strength
.stat
[0].scale
= FE_SCALE_RELATIVE
;
299 c
->strength
.stat
[0].uvalue
= (u64
)s_tmp
;
302 c
->cnr
.stat
[0].scale
= FE_SCALE_RELATIVE
;
303 c
->cnr
.stat
[0].uvalue
= (u64
)c_tmp
;
306 static void lme2510_int_response(struct urb
*lme_urb
)
308 struct dvb_usb_adapter
*adap
= lme_urb
->context
;
309 struct lme2510_state
*st
= adap_to_priv(adap
);
315 switch (lme_urb
->status
) {
324 info("Error %x", lme_urb
->status
);
328 rbuf
= (u8
*) lme_urb
->transfer_buffer
;
330 offset
= ((lme_urb
->actual_length
/8) > 4)
331 ? 4 : (lme_urb
->actual_length
/8) ;
333 for (i
= 0; i
< offset
; ++i
) {
334 ibuf
= (u8
*)&rbuf
[i
*8];
335 deb_info(5, "INT O/S C =%02x C/O=%02x Type =%02x%02x",
336 offset
, i
, ibuf
[0], ibuf
[1]);
340 debug_data_snipet(1, "INT Remote data snipet", ibuf
);
341 if (!adap_to_d(adap
)->rc_dev
)
344 key
= RC_SCANCODE_NEC32(ibuf
[2] << 24 |
349 deb_info(1, "INT Key = 0x%08x", key
);
350 rc_keydown(adap_to_d(adap
)->rc_dev
, RC_PROTO_NEC32
, key
,
354 switch (st
->tuner_config
) {
356 signal_lock
= ibuf
[2] & BIT(5);
357 st
->signal_level
= ibuf
[4];
358 st
->signal_sn
= ibuf
[3];
359 st
->time_key
= ibuf
[7];
363 /* Tweak for earlier firmware*/
364 if (ibuf
[1] == 0x03) {
365 signal_lock
= ibuf
[2] & BIT(4);
366 st
->signal_level
= ibuf
[3];
367 st
->signal_sn
= ibuf
[4];
369 st
->signal_level
= ibuf
[4];
370 st
->signal_sn
= ibuf
[5];
374 signal_lock
= ibuf
[2] & 0xee;
375 st
->signal_level
= ibuf
[5];
376 st
->signal_sn
= ibuf
[4];
377 st
->time_key
= ibuf
[7];
382 /* Interrupt will also throw just BIT 0 as lock */
383 signal_lock
|= ibuf
[2] & BIT(0);
386 st
->lock_status
&= ~FE_HAS_LOCK
;
388 lme2510_update_stats(adap
);
390 debug_data_snipet(5, "INT Remote data snipet in", ibuf
);
393 debug_data_snipet(1, "INT Control data snipet", ibuf
);
396 debug_data_snipet(1, "INT Unknown data snipet", ibuf
);
401 usb_submit_urb(lme_urb
, GFP_ATOMIC
);
403 /* Interrupt urb is due every 48 msecs while streaming the buffer
404 * stores up to 4 periods if missed. Allow 200 msec for next interrupt.
406 st
->int_urb_due
= jiffies
+ msecs_to_jiffies(200);
409 static int lme2510_int_read(struct dvb_usb_adapter
*adap
)
411 struct dvb_usb_device
*d
= adap_to_d(adap
);
412 struct lme2510_state
*lme_int
= adap_to_priv(adap
);
413 struct usb_host_endpoint
*ep
;
415 lme_int
->lme_urb
= usb_alloc_urb(0, GFP_ATOMIC
);
417 if (lme_int
->lme_urb
== NULL
)
420 lme_int
->buffer
= usb_alloc_coherent(d
->udev
, 128, GFP_ATOMIC
,
421 &lme_int
->lme_urb
->transfer_dma
);
423 if (lme_int
->buffer
== NULL
)
426 usb_fill_int_urb(lme_int
->lme_urb
,
428 usb_rcvintpipe(d
->udev
, 0xa),
431 lme2510_int_response
,
435 /* Quirk of pipe reporting PIPE_BULK but behaves as interrupt */
436 ep
= usb_pipe_endpoint(d
->udev
, lme_int
->lme_urb
->pipe
);
438 if (usb_endpoint_type(&ep
->desc
) == USB_ENDPOINT_XFER_BULK
)
439 lme_int
->lme_urb
->pipe
= usb_rcvbulkpipe(d
->udev
, 0xa),
441 lme_int
->lme_urb
->transfer_flags
|= URB_NO_TRANSFER_DMA_MAP
;
443 usb_submit_urb(lme_int
->lme_urb
, GFP_ATOMIC
);
444 info("INT Interrupt Service Started");
449 static int lme2510_pid_filter_ctrl(struct dvb_usb_adapter
*adap
, int onoff
)
451 struct dvb_usb_device
*d
= adap_to_d(adap
);
452 struct lme2510_state
*st
= adap_to_priv(adap
);
453 static u8 clear_pid_reg
[] = LME_ALL_PIDS
;
457 deb_info(1, "PID Clearing Filter");
459 mutex_lock(&d
->i2c_mutex
);
462 ret
|= lme2510_usb_talk(d
, clear_pid_reg
,
463 sizeof(clear_pid_reg
), rbuf
, sizeof(rbuf
));
470 mutex_unlock(&d
->i2c_mutex
);
475 static int lme2510_pid_filter(struct dvb_usb_adapter
*adap
, int index
, u16 pid
,
478 struct dvb_usb_device
*d
= adap_to_d(adap
);
481 deb_info(3, "%s PID=%04x Index=%04x onoff=%02x", __func__
,
485 mutex_lock(&d
->i2c_mutex
);
486 ret
|= lme2510_enable_pid(d
, index
, pid
);
487 mutex_unlock(&d
->i2c_mutex
);
495 static int lme2510_return_status(struct dvb_usb_device
*d
)
500 data
= kzalloc(6, GFP_KERNEL
);
504 ret
= usb_control_msg(d
->udev
, usb_rcvctrlpipe(d
->udev
, 0),
505 0x06, 0x80, 0x0302, 0x00,
512 info("Firmware Status: %6ph", data
);
518 static int lme2510_msg(struct dvb_usb_device
*d
,
519 u8
*wbuf
, int wlen
, u8
*rbuf
, int rlen
)
521 struct lme2510_state
*st
= d
->priv
;
523 st
->i2c_talk_onoff
= 1;
525 return lme2510_usb_talk(d
, wbuf
, wlen
, rbuf
, rlen
);
528 static int lme2510_i2c_xfer(struct i2c_adapter
*adap
, struct i2c_msg msg
[],
531 struct dvb_usb_device
*d
= i2c_get_adapdata(adap
);
532 struct lme2510_state
*st
= d
->priv
;
533 static u8 obuf
[64], ibuf
[64];
536 u8 gate
= st
->i2c_gate
;
538 mutex_lock(&d
->i2c_mutex
);
543 for (i
= 0; i
< num
; i
++) {
544 read_o
= msg
[i
].flags
& I2C_M_RD
;
545 read
= i
+ 1 < num
&& msg
[i
+ 1].flags
& I2C_M_RD
;
547 gate
= (msg
[i
].addr
== st
->i2c_tuner_addr
)
548 ? (read
) ? st
->i2c_tuner_gate_r
549 : st
->i2c_tuner_gate_w
551 obuf
[0] = gate
| (read
<< 7);
554 obuf
[1] = (read
) ? 2 : msg
[i
].len
+ 1;
556 obuf
[1] = msg
[i
].len
+ read
+ 1;
558 obuf
[2] = msg
[i
].addr
<< 1;
564 memcpy(&obuf
[3], msg
[i
].buf
, msg
[i
].len
);
565 obuf
[msg
[i
].len
+3] = msg
[i
+1].len
;
569 memcpy(&obuf
[3], msg
[i
].buf
, msg
[i
].len
);
573 if (lme2510_msg(d
, obuf
, len
, ibuf
, 64) < 0) {
574 deb_info(1, "i2c transfer failed.");
575 mutex_unlock(&d
->i2c_mutex
);
581 memcpy(msg
[i
].buf
, &ibuf
[1], msg
[i
].len
);
583 memcpy(msg
[i
+1].buf
, &ibuf
[1], msg
[i
+1].len
);
589 mutex_unlock(&d
->i2c_mutex
);
593 static u32
lme2510_i2c_func(struct i2c_adapter
*adapter
)
598 static struct i2c_algorithm lme2510_i2c_algo
= {
599 .master_xfer
= lme2510_i2c_xfer
,
600 .functionality
= lme2510_i2c_func
,
603 static int lme2510_streaming_ctrl(struct dvb_frontend
*fe
, int onoff
)
605 struct dvb_usb_adapter
*adap
= fe_to_adap(fe
);
606 struct dvb_usb_device
*d
= adap_to_d(adap
);
607 struct lme2510_state
*st
= adap_to_priv(adap
);
608 static u8 clear_reg_3
[] = LME_ALL_PIDS
;
610 int ret
= 0, rlen
= sizeof(rbuf
);
612 deb_info(1, "STM (%02x)", onoff
);
614 /* Streaming is started by FE_HAS_LOCK */
618 deb_info(1, "STM Steam Off");
619 /* mutex is here only to avoid collision with I2C */
620 mutex_lock(&d
->i2c_mutex
);
622 ret
= lme2510_usb_talk(d
, clear_reg_3
,
623 sizeof(clear_reg_3
), rbuf
, rlen
);
625 st
->i2c_talk_onoff
= 1;
627 mutex_unlock(&d
->i2c_mutex
);
630 return (ret
< 0) ? -ENODEV
: 0;
633 static u8
check_sum(u8
*p
, u8 len
)
641 static int lme2510_download_firmware(struct dvb_usb_device
*d
,
642 const struct firmware
*fw
)
646 u16 j
, wlen
, len_in
, start
, end
;
647 u8 packet_size
, dlen
, i
;
653 data
= kzalloc(128, GFP_KERNEL
);
655 info("FRM Could not start Firmware Download"\
656 "(Buffer allocation failed)");
660 info("FRM Starting Firmware Download");
662 for (i
= 1; i
< 3; i
++) {
663 start
= (i
== 1) ? 0 : 512;
664 end
= (i
== 1) ? 512 : fw
->size
;
665 for (j
= start
; j
< end
; j
+= (packet_size
+1)) {
666 fw_data
= (u8
*)(fw
->data
+ j
);
667 if ((end
- j
) > packet_size
) {
672 dlen
= (u8
)(end
- j
)-1;
675 memcpy(&data
[2], fw_data
, dlen
+1);
676 wlen
= (u8
) dlen
+ 4;
677 data
[wlen
-1] = check_sum(fw_data
, dlen
+1);
678 deb_info(1, "Data S=%02x:E=%02x CS= %02x", data
[3],
679 data
[dlen
+2], data
[dlen
+3]);
680 lme2510_usb_talk(d
, data
, wlen
, data
, len_in
);
681 ret
|= (data
[0] == 0x88) ? 0 : -1;
688 lme2510_usb_talk(d
, data
, len_in
, data
, len_in
);
692 info("FRM Firmware Download Failed (%04x)" , ret
);
694 info("FRM Firmware Download Completed - Resetting Device");
697 return RECONNECTS_USB
;
700 static void lme_coldreset(struct dvb_usb_device
*d
)
704 info("FRM Firmware Cold Reset");
706 lme2510_usb_talk(d
, data
, sizeof(data
), data
, sizeof(data
));
711 static const char fw_c_s7395
[] = LME2510_C_S7395
;
712 static const char fw_c_lg
[] = LME2510_C_LG
;
713 static const char fw_c_s0194
[] = LME2510_C_S0194
;
714 static const char fw_c_rs2000
[] = LME2510_C_RS2000
;
715 static const char fw_lg
[] = LME2510_LG
;
716 static const char fw_s0194
[] = LME2510_S0194
;
718 static const char *lme_firmware_switch(struct dvb_usb_device
*d
, int cold
)
720 struct lme2510_state
*st
= d
->priv
;
721 struct usb_device
*udev
= d
->udev
;
722 const struct firmware
*fw
= NULL
;
726 cold
= (cold
> 0) ? (cold
& 1) : 0;
728 switch (le16_to_cpu(udev
->descriptor
.idProduct
)) {
730 switch (st
->dvb_usb_lme2510_firmware
) {
734 ret
= request_firmware(&fw
, fw_lme
, &udev
->dev
);
736 st
->dvb_usb_lme2510_firmware
= TUNER_S0194
;
743 ret
= request_firmware(&fw
, fw_lme
, &udev
->dev
);
745 st
->dvb_usb_lme2510_firmware
= TUNER_LG
;
748 st
->dvb_usb_lme2510_firmware
= TUNER_DEFAULT
;
753 switch (st
->dvb_usb_lme2510_firmware
) {
757 ret
= request_firmware(&fw
, fw_lme
, &udev
->dev
);
759 st
->dvb_usb_lme2510_firmware
= TUNER_S7395
;
766 ret
= request_firmware(&fw
, fw_lme
, &udev
->dev
);
768 st
->dvb_usb_lme2510_firmware
= TUNER_LG
;
774 ret
= request_firmware(&fw
, fw_lme
, &udev
->dev
);
776 st
->dvb_usb_lme2510_firmware
= TUNER_S0194
;
779 st
->dvb_usb_lme2510_firmware
= TUNER_DEFAULT
;
785 fw_lme
= fw_c_rs2000
;
786 st
->dvb_usb_lme2510_firmware
= TUNER_RS2000
;
792 release_firmware(fw
);
795 dvb_usb_lme2510_firmware
= st
->dvb_usb_lme2510_firmware
;
796 info("FRM Changing to %s firmware", fw_lme
);
804 static int lme2510_kill_urb(struct usb_data_stream
*stream
)
808 for (i
= 0; i
< stream
->urbs_submitted
; i
++) {
809 deb_info(3, "killing URB no. %d.", i
);
811 usb_kill_urb(stream
->urb_list
[i
]);
813 stream
->urbs_submitted
= 0;
818 static struct tda10086_config tda10086_config
= {
819 .demod_address
= 0x0e,
822 .xtal_freq
= TDA10086_XTAL_16M
,
825 static struct stv0288_config lme_config
= {
826 .demod_address
= 0x68,
828 .inittab
= s7395_inittab
,
831 static struct ix2505v_config lme_tuner
= {
832 .tuner_address
= 0x60,
835 .tuner_chargepump
= 0x3,
838 static struct stv0299_config sharp_z0194_config
= {
839 .demod_address
= 0x68,
840 .inittab
= sharp_z0194a_inittab
,
844 .lock_output
= STV0299_LOCKOUTPUT_1
,
845 .volt13_op0_op1
= STV0299_VOLT13_OP1
,
847 .set_symbol_rate
= sharp_z0194a_set_symbol_rate
,
850 static struct m88rs2000_config m88rs2000_config
= {
854 static struct ts2020_config ts2020_config
= {
855 .tuner_address
= 0x60,
860 static int dm04_lme2510_set_voltage(struct dvb_frontend
*fe
,
861 enum fe_sec_voltage voltage
)
863 struct dvb_usb_device
*d
= fe_to_d(fe
);
864 struct lme2510_state
*st
= fe_to_priv(fe
);
865 static u8 voltage_low
[] = LME_VOLTAGE_L
;
866 static u8 voltage_high
[] = LME_VOLTAGE_H
;
868 int ret
= 0, len
= 3, rlen
= 1;
870 mutex_lock(&d
->i2c_mutex
);
874 ret
|= lme2510_usb_talk(d
,
875 voltage_high
, len
, rbuf
, rlen
);
878 case SEC_VOLTAGE_OFF
:
881 ret
|= lme2510_usb_talk(d
,
882 voltage_low
, len
, rbuf
, rlen
);
886 mutex_unlock(&d
->i2c_mutex
);
888 if (st
->tuner_config
== TUNER_RS2000
)
889 if (st
->fe_set_voltage
)
890 st
->fe_set_voltage(fe
, voltage
);
893 return (ret
< 0) ? -ENODEV
: 0;
896 static int dm04_read_status(struct dvb_frontend
*fe
, enum fe_status
*status
)
898 struct dvb_usb_device
*d
= fe_to_d(fe
);
899 struct lme2510_state
*st
= d
->priv
;
902 if (st
->i2c_talk_onoff
) {
903 if (st
->fe_read_status
) {
904 ret
= st
->fe_read_status(fe
, status
);
909 st
->lock_status
= *status
;
911 if (*status
& FE_HAS_LOCK
&& st
->stream_on
) {
912 mutex_lock(&d
->i2c_mutex
);
914 st
->i2c_talk_onoff
= 0;
915 ret
= lme2510_stream_restart(d
);
917 mutex_unlock(&d
->i2c_mutex
);
923 /* Timeout of interrupt reached on RS2000 */
924 if (st
->tuner_config
== TUNER_RS2000
&&
925 time_after(jiffies
, st
->int_urb_due
))
926 st
->lock_status
&= ~FE_HAS_LOCK
;
928 *status
= st
->lock_status
;
930 if (!(*status
& FE_HAS_LOCK
)) {
931 struct dvb_usb_adapter
*adap
= fe_to_adap(fe
);
933 st
->i2c_talk_onoff
= 1;
935 lme2510_update_stats(adap
);
941 static int dm04_read_signal_strength(struct dvb_frontend
*fe
, u16
*strength
)
943 struct dtv_frontend_properties
*c
= &fe
->dtv_property_cache
;
944 struct lme2510_state
*st
= fe_to_priv(fe
);
946 if (st
->fe_read_signal_strength
&& !st
->stream_on
)
947 return st
->fe_read_signal_strength(fe
, strength
);
949 if (c
->strength
.stat
[0].scale
== FE_SCALE_RELATIVE
)
950 *strength
= (u16
)c
->strength
.stat
[0].uvalue
;
957 static int dm04_read_snr(struct dvb_frontend
*fe
, u16
*snr
)
959 struct dtv_frontend_properties
*c
= &fe
->dtv_property_cache
;
960 struct lme2510_state
*st
= fe_to_priv(fe
);
962 if (st
->fe_read_snr
&& !st
->stream_on
)
963 return st
->fe_read_snr(fe
, snr
);
965 if (c
->cnr
.stat
[0].scale
== FE_SCALE_RELATIVE
)
966 *snr
= (u16
)c
->cnr
.stat
[0].uvalue
;
973 static int dm04_read_ber(struct dvb_frontend
*fe
, u32
*ber
)
975 struct lme2510_state
*st
= fe_to_priv(fe
);
977 if (st
->fe_read_ber
&& !st
->stream_on
)
978 return st
->fe_read_ber(fe
, ber
);
985 static int dm04_read_ucblocks(struct dvb_frontend
*fe
, u32
*ucblocks
)
987 struct lme2510_state
*st
= fe_to_priv(fe
);
989 if (st
->fe_read_ucblocks
&& !st
->stream_on
)
990 return st
->fe_read_ucblocks(fe
, ucblocks
);
997 static int lme_name(struct dvb_usb_adapter
*adap
)
999 struct dvb_usb_device
*d
= adap_to_d(adap
);
1000 struct lme2510_state
*st
= adap_to_priv(adap
);
1001 const char *desc
= d
->name
;
1002 static const char * const fe_name
[] = {
1003 "", " LG TDQY-P001F", " SHARP:BS2F7HZ7395",
1004 " SHARP:BS2F7HZ0194", " RS2000"};
1005 char *name
= adap
->fe
[0]->ops
.info
.name
;
1007 strlcpy(name
, desc
, 128);
1008 strlcat(name
, fe_name
[st
->tuner_config
], 128);
1013 static int dm04_lme2510_frontend_attach(struct dvb_usb_adapter
*adap
)
1015 struct dvb_usb_device
*d
= adap_to_d(adap
);
1016 struct lme2510_state
*st
= d
->priv
;
1019 st
->i2c_talk_onoff
= 1;
1020 switch (le16_to_cpu(d
->udev
->descriptor
.idProduct
)) {
1024 adap
->fe
[0] = dvb_attach(tda10086_attach
,
1025 &tda10086_config
, &d
->i2c_adap
);
1027 info("TUN Found Frontend TDA10086");
1028 st
->i2c_tuner_gate_w
= 4;
1029 st
->i2c_tuner_gate_r
= 4;
1030 st
->i2c_tuner_addr
= 0x60;
1031 st
->tuner_config
= TUNER_LG
;
1032 if (st
->dvb_usb_lme2510_firmware
!= TUNER_LG
) {
1033 st
->dvb_usb_lme2510_firmware
= TUNER_LG
;
1034 ret
= lme_firmware_switch(d
, 1) ? 0 : -ENODEV
;
1040 adap
->fe
[0] = dvb_attach(stv0299_attach
,
1041 &sharp_z0194_config
, &d
->i2c_adap
);
1043 info("FE Found Stv0299");
1044 st
->i2c_tuner_gate_w
= 4;
1045 st
->i2c_tuner_gate_r
= 5;
1046 st
->i2c_tuner_addr
= 0x60;
1047 st
->tuner_config
= TUNER_S0194
;
1048 if (st
->dvb_usb_lme2510_firmware
!= TUNER_S0194
) {
1049 st
->dvb_usb_lme2510_firmware
= TUNER_S0194
;
1050 ret
= lme_firmware_switch(d
, 1) ? 0 : -ENODEV
;
1056 adap
->fe
[0] = dvb_attach(stv0288_attach
, &lme_config
,
1060 info("FE Found Stv0288");
1061 st
->i2c_tuner_gate_w
= 4;
1062 st
->i2c_tuner_gate_r
= 5;
1063 st
->i2c_tuner_addr
= 0x60;
1064 st
->tuner_config
= TUNER_S7395
;
1065 if (st
->dvb_usb_lme2510_firmware
!= TUNER_S7395
) {
1066 st
->dvb_usb_lme2510_firmware
= TUNER_S7395
;
1067 ret
= lme_firmware_switch(d
, 1) ? 0 : -ENODEV
;
1074 adap
->fe
[0] = dvb_attach(m88rs2000_attach
,
1075 &m88rs2000_config
, &d
->i2c_adap
);
1078 info("FE Found M88RS2000");
1079 st
->i2c_tuner_gate_w
= 5;
1080 st
->i2c_tuner_gate_r
= 5;
1081 st
->i2c_tuner_addr
= 0x60;
1082 st
->tuner_config
= TUNER_RS2000
;
1083 st
->fe_set_voltage
=
1084 adap
->fe
[0]->ops
.set_voltage
;
1089 if (adap
->fe
[0] == NULL
) {
1090 info("DM04/QQBOX Not Powered up or not Supported");
1096 dvb_frontend_detach(adap
->fe
[0]);
1103 st
->fe_read_status
= adap
->fe
[0]->ops
.read_status
;
1104 st
->fe_read_signal_strength
= adap
->fe
[0]->ops
.read_signal_strength
;
1105 st
->fe_read_snr
= adap
->fe
[0]->ops
.read_snr
;
1106 st
->fe_read_ber
= adap
->fe
[0]->ops
.read_ber
;
1107 st
->fe_read_ucblocks
= adap
->fe
[0]->ops
.read_ucblocks
;
1109 adap
->fe
[0]->ops
.read_status
= dm04_read_status
;
1110 adap
->fe
[0]->ops
.read_signal_strength
= dm04_read_signal_strength
;
1111 adap
->fe
[0]->ops
.read_snr
= dm04_read_snr
;
1112 adap
->fe
[0]->ops
.read_ber
= dm04_read_ber
;
1113 adap
->fe
[0]->ops
.read_ucblocks
= dm04_read_ucblocks
;
1114 adap
->fe
[0]->ops
.set_voltage
= dm04_lme2510_set_voltage
;
1116 ret
= lme_name(adap
);
1120 static int dm04_lme2510_tuner(struct dvb_usb_adapter
*adap
)
1122 struct dvb_usb_device
*d
= adap_to_d(adap
);
1123 struct lme2510_state
*st
= adap_to_priv(adap
);
1124 static const char * const tun_msg
[] = {"", "TDA8263", "IX2505V", "DVB_PLL_OPERA", "RS2000"};
1127 switch (st
->tuner_config
) {
1129 if (dvb_attach(tda826x_attach
, adap
->fe
[0], 0x60,
1131 ret
= st
->tuner_config
;
1134 if (dvb_attach(ix2505v_attach
, adap
->fe
[0], &lme_tuner
,
1136 ret
= st
->tuner_config
;
1139 if (dvb_attach(dvb_pll_attach
, adap
->fe
[0], 0x60,
1140 &d
->i2c_adap
, DVB_PLL_OPERA1
))
1141 ret
= st
->tuner_config
;
1144 if (dvb_attach(ts2020_attach
, adap
->fe
[0],
1145 &ts2020_config
, &d
->i2c_adap
))
1146 ret
= st
->tuner_config
;
1153 info("TUN Found %s tuner", tun_msg
[ret
]);
1155 info("TUN No tuner found");
1159 /* Start the Interrupt*/
1160 ret
= lme2510_int_read(adap
);
1162 info("INT Unable to start Interrupt Service");
1169 static int lme2510_powerup(struct dvb_usb_device
*d
, int onoff
)
1171 struct lme2510_state
*st
= d
->priv
;
1172 static u8 lnb_on
[] = LNB_ON
;
1173 static u8 lnb_off
[] = LNB_OFF
;
1175 int ret
= 0, len
= 3, rlen
= 1;
1177 mutex_lock(&d
->i2c_mutex
);
1179 ret
= lme2510_usb_talk(d
, onoff
? lnb_on
: lnb_off
, len
, rbuf
, rlen
);
1181 st
->i2c_talk_onoff
= 1;
1183 mutex_unlock(&d
->i2c_mutex
);
1188 static int lme2510_get_adapter_count(struct dvb_usb_device
*d
)
1193 static int lme2510_identify_state(struct dvb_usb_device
*d
, const char **name
)
1195 struct lme2510_state
*st
= d
->priv
;
1198 usb_reset_configuration(d
->udev
);
1200 usb_set_interface(d
->udev
,
1201 d
->props
->bInterfaceNumber
, 1);
1203 st
->dvb_usb_lme2510_firmware
= dvb_usb_lme2510_firmware
;
1205 status
= lme2510_return_status(d
);
1206 if (status
== 0x44) {
1207 *name
= lme_firmware_switch(d
, 0);
1217 static int lme2510_get_stream_config(struct dvb_frontend
*fe
, u8
*ts_type
,
1218 struct usb_data_stream_properties
*stream
)
1220 struct dvb_usb_adapter
*adap
= fe_to_adap(fe
);
1221 struct dvb_usb_device
*d
;
1226 d
= adap_to_d(adap
);
1228 /* Turn PID filter on the fly by module option */
1229 if (pid_filter
== 2) {
1230 adap
->pid_filtering
= true;
1231 adap
->max_feed_count
= 15;
1234 if (!(le16_to_cpu(d
->udev
->descriptor
.idProduct
)
1236 stream
->endpoint
= 0x8;
1241 static int lme2510_get_rc_config(struct dvb_usb_device
*d
,
1242 struct dvb_usb_rc
*rc
)
1244 rc
->allowed_protos
= RC_PROTO_BIT_NEC32
;
1248 static void *lme2510_exit_int(struct dvb_usb_device
*d
)
1250 struct lme2510_state
*st
= d
->priv
;
1251 struct dvb_usb_adapter
*adap
= &d
->adapter
[0];
1252 void *buffer
= NULL
;
1255 lme2510_kill_urb(&adap
->stream
);
1258 if (st
->usb_buffer
!= NULL
) {
1259 st
->i2c_talk_onoff
= 1;
1260 st
->signal_level
= 0;
1262 buffer
= st
->usb_buffer
;
1265 if (st
->lme_urb
!= NULL
) {
1266 usb_kill_urb(st
->lme_urb
);
1267 usb_free_coherent(d
->udev
, 128, st
->buffer
,
1268 st
->lme_urb
->transfer_dma
);
1269 info("Interrupt Service Stopped");
1275 static void lme2510_exit(struct dvb_usb_device
*d
)
1280 usb_buffer
= lme2510_exit_int(d
);
1285 static struct dvb_usb_device_properties lme2510_props
= {
1286 .driver_name
= KBUILD_MODNAME
,
1287 .owner
= THIS_MODULE
,
1288 .bInterfaceNumber
= 0,
1289 .adapter_nr
= adapter_nr
,
1290 .size_of_priv
= sizeof(struct lme2510_state
),
1292 .download_firmware
= lme2510_download_firmware
,
1294 .power_ctrl
= lme2510_powerup
,
1295 .identify_state
= lme2510_identify_state
,
1296 .i2c_algo
= &lme2510_i2c_algo
,
1298 .frontend_attach
= dm04_lme2510_frontend_attach
,
1299 .tuner_attach
= dm04_lme2510_tuner
,
1300 .get_stream_config
= lme2510_get_stream_config
,
1301 .get_adapter_count
= lme2510_get_adapter_count
,
1302 .streaming_ctrl
= lme2510_streaming_ctrl
,
1304 .get_rc_config
= lme2510_get_rc_config
,
1306 .exit
= lme2510_exit
,
1309 .caps
= DVB_USB_ADAP_HAS_PID_FILTER
|
1310 DVB_USB_ADAP_PID_FILTER_CAN_BE_TURNED_OFF
,
1311 .pid_filter_count
= 15,
1312 .pid_filter
= lme2510_pid_filter
,
1313 .pid_filter_ctrl
= lme2510_pid_filter_ctrl
,
1315 DVB_USB_STREAM_BULK(0x86, 10, 4096),
1322 static const struct usb_device_id lme2510_id_table
[] = {
1323 { DVB_USB_DEVICE(0x3344, 0x1122, &lme2510_props
,
1324 "DM04_LME2510_DVB-S", RC_MAP_LME2510
) },
1325 { DVB_USB_DEVICE(0x3344, 0x1120, &lme2510_props
,
1326 "DM04_LME2510C_DVB-S", RC_MAP_LME2510
) },
1327 { DVB_USB_DEVICE(0x3344, 0x22f0, &lme2510_props
,
1328 "DM04_LME2510C_DVB-S RS2000", RC_MAP_LME2510
) },
1329 {} /* Terminating entry */
1332 MODULE_DEVICE_TABLE(usb
, lme2510_id_table
);
1334 static struct usb_driver lme2510_driver
= {
1335 .name
= KBUILD_MODNAME
,
1336 .probe
= dvb_usbv2_probe
,
1337 .disconnect
= dvb_usbv2_disconnect
,
1338 .id_table
= lme2510_id_table
,
1343 module_usb_driver(lme2510_driver
);
1345 MODULE_AUTHOR("Malcolm Priestley <tvboxspy@gmail.com>");
1346 MODULE_DESCRIPTION("LME2510(C) DVB-S USB2.0");
1347 MODULE_VERSION("2.07");
1348 MODULE_LICENSE("GPL");
1349 MODULE_FIRMWARE(LME2510_C_S7395
);
1350 MODULE_FIRMWARE(LME2510_C_LG
);
1351 MODULE_FIRMWARE(LME2510_C_S0194
);
1352 MODULE_FIRMWARE(LME2510_C_RS2000
);
1353 MODULE_FIRMWARE(LME2510_LG
);
1354 MODULE_FIRMWARE(LME2510_S0194
);