1 /* DVB USB compliant linux driver for
3 * DM04/QQBOX DVB-S USB BOX LME2510C + SHARP:BS2F7HZ7395
4 * LME2510C + LG TDQY-P001F
5 * LME2510C + BS2F7HZ0194
6 * LME2510 + LG TDQY-P001F
7 * LME2510 + BS2F7HZ0194
9 * MVB7395 (LME2510C+SHARP:BS2F7HZ7395)
10 * SHARP:BS2F7HZ7395 = (STV0288+Sharp IX2505V)
12 * MV001F (LME2510+LGTDQY-P001F)
13 * LG TDQY - P001F =(TDA8263 + TDA10086H)
15 * MVB0001F (LME2510C+LGTDQT-P001F)
17 * MV0194 (LME2510+SHARP:BS2F7HZ0194)
18 * SHARP:BS2F7HZ0194 = (STV0299+IX2410)
20 * MVB0194 (LME2510C+SHARP0194)
22 * LME2510C + M88RS2000
24 * For firmware see Documentation/dvb/lmedm04.txt
27 * 0xd0 - STV0288 - Demodulator
28 * 0xc0 - Sharp IX2505V - Tuner
30 * 0x1c - TDA10086 - Demodulator
31 * 0xc0 - TDA8263 - Tuner
33 * 0xd0 - STV0299 - Demodulator
34 * 0xc0 - IX2410 - Tuner
37 * VID = 3344 PID LME2510=1122 LME2510C=1120
39 * Copyright (C) 2010 Malcolm Priestley (tvboxspy@gmail.com)
40 * LME2510(C)(C) Leaguerme (Shenzhen) MicroElectronics Co., Ltd.
42 * This program is free software; you can redistribute it and/or modify
43 * it under the terms of the GNU General Public License Version 2, as
44 * published by the Free Software Foundation.
46 * This program is distributed in the hope that it will be useful,
47 * but WITHOUT ANY WARRANTY; without even the implied warranty of
48 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
49 * GNU General Public License for more details.
51 * You should have received a copy of the GNU General Public License
52 * along with this program; if not, write to the Free Software
53 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
56 * see Documentation/dvb/README.dvb-usb for more information
59 * LME2510: Non Intel USB chipsets fail to maintain High Speed on
62 * QQbox suffers from noise on LNB voltage.
64 * LME2510: SHARP:BS2F7HZ0194(MV0194) cannot cold reset and share system
65 * with other tuners. After a cold reset streaming will not start.
67 * M88RS2000 suffers from loss of lock.
69 #define DVB_USB_LOG_PREFIX "LME2510(C)"
70 #include <linux/usb.h>
71 #include <linux/usb/input.h>
72 #include <media/rc-core.h>
83 #include "m88rs2000.h"
86 #define LME2510_C_S7395 "dvb-usb-lme2510c-s7395.fw";
87 #define LME2510_C_LG "dvb-usb-lme2510c-lg.fw";
88 #define LME2510_C_S0194 "dvb-usb-lme2510c-s0194.fw";
89 #define LME2510_C_RS2000 "dvb-usb-lme2510c-rs2000.fw";
90 #define LME2510_LG "dvb-usb-lme2510-lg.fw";
91 #define LME2510_S0194 "dvb-usb-lme2510-s0194.fw";
94 static int dvb_usb_lme2510_debug;
95 #define lme_debug(var, level, args...) do { \
97 pr_debug(DVB_USB_LOG_PREFIX": " args); \
99 #define deb_info(level, args...) lme_debug(dvb_usb_lme2510_debug, level, args)
100 #define debug_data_snipet(level, name, p) \
101 deb_info(level, name" (%02x%02x%02x%02x%02x%02x%02x%02x)", \
102 *p, *(p+1), *(p+2), *(p+3), *(p+4), \
103 *(p+5), *(p+6), *(p+7));
104 #define info(args...) pr_info(DVB_USB_LOG_PREFIX": "args)
106 module_param_named(debug, dvb_usb_lme2510_debug, int, 0644);
107 MODULE_PARM_DESC(debug, "set debugging level (1=info (or-able)).");
109 static int dvb_usb_lme2510_firmware;
110 module_param_named(firmware, dvb_usb_lme2510_firmware, int, 0644);
111 MODULE_PARM_DESC(firmware, "set default firmware 0=Sharp7395 1=LG");
113 static int pid_filter;
114 module_param_named(pid, pid_filter, int, 0644);
115 MODULE_PARM_DESC(pid, "set default 0=default 1=off 2=on");
118 DVB_DEFINE_MOD_OPT_ADAPTER_NR(adapter_nr);
120 #define TUNER_DEFAULT 0x0
122 #define TUNER_S7395 0x2
123 #define TUNER_S0194 0x3
124 #define TUNER_RS2000 0x4
126 struct lme2510_state {
146 int (*fe_set_voltage)(struct dvb_frontend *, fe_sec_voltage_t);
147 u8 dvb_usb_lme2510_firmware;
150 static int lme2510_bulk_write(struct usb_device *dev,
151 u8 *snd, int len, u8 pipe)
155 ret = usb_bulk_msg(dev, usb_sndbulkpipe(dev, pipe),
156 snd, len , &actual_l, 100);
160 static int lme2510_bulk_read(struct usb_device *dev,
161 u8 *rev, int len, u8 pipe)
165 ret = usb_bulk_msg(dev, usb_rcvbulkpipe(dev, pipe),
166 rev, len , &actual_l, 200);
170 static int lme2510_usb_talk(struct dvb_usb_device *d,
171 u8 *wbuf, int wlen, u8 *rbuf, int rlen)
173 struct lme2510_state *st = d->priv;
177 if (st->usb_buffer == NULL) {
178 st->usb_buffer = kmalloc(64, GFP_KERNEL);
179 if (st->usb_buffer == NULL) {
180 info("MEM Error no memory");
184 buff = st->usb_buffer;
186 ret = mutex_lock_interruptible(&d->usb_mutex);
191 /* the read/write capped at 64 */
192 memcpy(buff, wbuf, (wlen < 64) ? wlen : 64);
194 ret |= lme2510_bulk_write(d->udev, buff, wlen , 0x01);
196 ret |= lme2510_bulk_read(d->udev, buff, (rlen < 64) ?
200 memcpy(rbuf, buff, rlen);
202 mutex_unlock(&d->usb_mutex);
204 return (ret < 0) ? -ENODEV : 0;
207 static int lme2510_stream_restart(struct dvb_usb_device *d)
209 struct lme2510_state *st = d->priv;
210 u8 all_pids[] = LME_ALL_PIDS;
211 u8 stream_on[] = LME_ST_ON_W;
215 ret = lme2510_usb_talk(d, all_pids, sizeof(all_pids),
216 rbuff, sizeof(rbuff));
217 /*Restart Stream Command*/
218 ret = lme2510_usb_talk(d, stream_on, sizeof(stream_on),
219 rbuff, sizeof(rbuff));
223 static int lme2510_enable_pid(struct dvb_usb_device *d, u8 index, u16 pid_out)
225 struct lme2510_state *st = d->priv;
226 static u8 pid_buff[] = LME_ZERO_PID;
228 u8 pid_no = index * 2;
229 u8 pid_len = pid_no + 2;
231 deb_info(1, "PID Setting Pid %04x", pid_out);
233 if (st->pid_size == 0)
234 ret |= lme2510_stream_restart(d);
236 pid_buff[2] = pid_no;
237 pid_buff[3] = (u8)pid_out & 0xff;
238 pid_buff[4] = pid_no + 1;
239 pid_buff[5] = (u8)(pid_out >> 8);
241 if (pid_len > st->pid_size)
242 st->pid_size = pid_len;
243 pid_buff[7] = 0x80 + st->pid_size;
245 ret |= lme2510_usb_talk(d, pid_buff ,
246 sizeof(pid_buff) , rbuf, sizeof(rbuf));
249 ret |= lme2510_stream_restart(d);
254 static void lme2510_int_response(struct urb *lme_urb)
256 struct dvb_usb_adapter *adap = lme_urb->context;
257 struct lme2510_state *st = adap_to_priv(adap);
258 static u8 *ibuf, *rbuf;
262 switch (lme_urb->status) {
271 info("Error %x", lme_urb->status);
275 rbuf = (u8 *) lme_urb->transfer_buffer;
277 offset = ((lme_urb->actual_length/8) > 4)
278 ? 4 : (lme_urb->actual_length/8) ;
280 for (i = 0; i < offset; ++i) {
281 ibuf = (u8 *)&rbuf[i*8];
282 deb_info(5, "INT O/S C =%02x C/O=%02x Type =%02x%02x",
283 offset, i, ibuf[0], ibuf[1]);
287 debug_data_snipet(1, "INT Remote data snipet", ibuf);
288 if ((ibuf[4] + ibuf[5]) == 0xff) {
291 ? (ibuf[3] ^ 0xff) << 8 : 0;
292 key += (ibuf[2] ^ 0xff) << 16;
293 deb_info(1, "INT Key =%08x", key);
294 if (adap_to_d(adap)->rc_dev != NULL)
295 rc_keydown(adap_to_d(adap)->rc_dev,
300 switch (st->tuner_config) {
303 st->signal_lock = ibuf[2];
304 st->signal_level = ibuf[4];
305 st->signal_sn = ibuf[3];
306 st->time_key = ibuf[7];
310 /* Tweak for earlier firmware*/
311 if (ibuf[1] == 0x03) {
313 st->signal_lock = ibuf[2];
314 st->signal_level = ibuf[3];
315 st->signal_sn = ibuf[4];
317 st->signal_level = ibuf[4];
318 st->signal_sn = ibuf[5];
320 (st->signal_lock & 0xf7) +
321 ((ibuf[2] & 0x01) << 0x03);
325 if (ibuf[1] == 0x3 && ibuf[6] == 0xff)
326 st->signal_lock = 0xff;
328 st->signal_lock = 0x00;
329 st->signal_level = ibuf[5];
330 st->signal_sn = ibuf[4];
331 st->time_key = ibuf[7];
335 debug_data_snipet(5, "INT Remote data snipet in", ibuf);
338 debug_data_snipet(1, "INT Control data snipet", ibuf);
341 debug_data_snipet(1, "INT Unknown data snipet", ibuf);
345 usb_submit_urb(lme_urb, GFP_ATOMIC);
348 static int lme2510_int_read(struct dvb_usb_adapter *adap)
350 struct dvb_usb_device *d = adap_to_d(adap);
351 struct lme2510_state *lme_int = adap_to_priv(adap);
353 lme_int->lme_urb = usb_alloc_urb(0, GFP_ATOMIC);
355 if (lme_int->lme_urb == NULL)
358 lme_int->buffer = usb_alloc_coherent(d->udev, 128, GFP_ATOMIC,
359 &lme_int->lme_urb->transfer_dma);
361 if (lme_int->buffer == NULL)
364 usb_fill_int_urb(lme_int->lme_urb,
366 usb_rcvintpipe(d->udev, 0xa),
369 lme2510_int_response,
373 lme_int->lme_urb->transfer_flags |= URB_NO_TRANSFER_DMA_MAP;
375 usb_submit_urb(lme_int->lme_urb, GFP_ATOMIC);
376 info("INT Interrupt Service Started");
381 static int lme2510_pid_filter_ctrl(struct dvb_usb_adapter *adap, int onoff)
383 struct dvb_usb_device *d = adap_to_d(adap);
384 struct lme2510_state *st = adap_to_priv(adap);
385 static u8 clear_pid_reg[] = LME_ALL_PIDS;
389 deb_info(1, "PID Clearing Filter");
391 mutex_lock(&d->i2c_mutex);
394 ret |= lme2510_usb_talk(d, clear_pid_reg,
395 sizeof(clear_pid_reg), rbuf, sizeof(rbuf));
402 mutex_unlock(&d->i2c_mutex);
407 static int lme2510_pid_filter(struct dvb_usb_adapter *adap, int index, u16 pid,
410 struct dvb_usb_device *d = adap_to_d(adap);
413 deb_info(3, "%s PID=%04x Index=%04x onoff=%02x", __func__,
417 mutex_lock(&d->i2c_mutex);
418 ret |= lme2510_enable_pid(d, index, pid);
419 mutex_unlock(&d->i2c_mutex);
427 static int lme2510_return_status(struct dvb_usb_device *d)
432 data = kzalloc(10, GFP_KERNEL);
436 ret |= usb_control_msg(d->udev, usb_rcvctrlpipe(d->udev, 0),
437 0x06, 0x80, 0x0302, 0x00, data, 0x0006, 200);
438 info("Firmware Status: %x (%x)", ret , data[2]);
440 ret = (ret < 0) ? -ENODEV : data[2];
445 static int lme2510_msg(struct dvb_usb_device *d,
446 u8 *wbuf, int wlen, u8 *rbuf, int rlen)
449 struct lme2510_state *st = d->priv;
451 if (st->i2c_talk_onoff == 1) {
453 ret = lme2510_usb_talk(d, wbuf, wlen, rbuf, rlen);
455 switch (st->tuner_config) {
457 if (wbuf[2] == 0x1c) {
458 if (wbuf[3] == 0x0e) {
459 st->signal_lock = rbuf[1];
460 if ((st->stream_on & 1) &&
461 (st->signal_lock & 0x10)) {
462 lme2510_stream_restart(d);
463 st->i2c_talk_onoff = 0;
470 if (wbuf[2] == 0xd0) {
471 if (wbuf[3] == 0x24) {
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;
482 if (wbuf[2] == 0xd0) {
483 if (wbuf[3] == 0x1b) {
484 st->signal_lock = rbuf[1];
485 if ((st->stream_on & 1) &&
486 (st->signal_lock & 0x8)) {
487 lme2510_stream_restart(d);
488 st->i2c_talk_onoff = 0;
498 /* TODO rewrite this section */
499 switch (st->tuner_config) {
504 rbuf[1] = st->signal_lock;
508 rbuf[1] = st->signal_level;
512 rbuf[1] = st->signal_sn;
522 lme2510_usb_talk(d, wbuf, wlen, rbuf, rlen);
523 st->i2c_talk_onoff = 1;
531 rbuf[1] = (st->signal_level & 0x80)
532 ? 0 : (st->signal_level * 2);
536 rbuf[1] = st->signal_sn;
540 rbuf[1] = st->signal_lock;
549 lme2510_usb_talk(d, wbuf, wlen, rbuf, rlen);
550 st->i2c_talk_onoff = 1;
558 rbuf[1] = (st->signal_level & 0x80)
559 ? 0 : (st->signal_level * 2);
563 rbuf[1] = st->signal_sn;
567 rbuf[1] = st->signal_lock;
577 lme2510_usb_talk(d, wbuf, wlen, rbuf, rlen);
578 st->i2c_talk_onoff = 1;
587 if (st->last_key == st->time_key) {
589 if (st->key_timeout > 5)
593 st->last_key = st->time_key;
596 lme2510_usb_talk(d, wbuf, wlen, rbuf, rlen);
597 st->i2c_talk_onoff = 1;
604 deb_info(4, "I2C From Interrupt Message out(%02x) in(%02x)",
613 static int lme2510_i2c_xfer(struct i2c_adapter *adap, struct i2c_msg msg[],
616 struct dvb_usb_device *d = i2c_get_adapdata(adap);
617 struct lme2510_state *st = d->priv;
618 static u8 obuf[64], ibuf[64];
621 u8 gate = st->i2c_gate;
623 mutex_lock(&d->i2c_mutex);
628 for (i = 0; i < num; i++) {
629 read_o = 1 & (msg[i].flags & I2C_M_RD);
630 read = i+1 < num && (msg[i+1].flags & I2C_M_RD);
632 gate = (msg[i].addr == st->i2c_tuner_addr)
633 ? (read) ? st->i2c_tuner_gate_r
634 : st->i2c_tuner_gate_w
636 obuf[0] = gate | (read << 7);
639 obuf[1] = (read) ? 2 : msg[i].len + 1;
641 obuf[1] = msg[i].len + read + 1;
643 obuf[2] = msg[i].addr;
648 memcpy(&obuf[3], msg[i].buf, msg[i].len);
649 obuf[msg[i].len+3] = msg[i+1].len;
653 memcpy(&obuf[3], msg[i].buf, msg[i].len);
657 if (lme2510_msg(d, obuf, len, ibuf, 64) < 0) {
658 deb_info(1, "i2c transfer failed.");
659 mutex_unlock(&d->i2c_mutex);
665 memcpy(msg[i].buf, &ibuf[1], msg[i].len);
667 memcpy(msg[i+1].buf, &ibuf[1], msg[i+1].len);
673 mutex_unlock(&d->i2c_mutex);
677 static u32 lme2510_i2c_func(struct i2c_adapter *adapter)
682 static struct i2c_algorithm lme2510_i2c_algo = {
683 .master_xfer = lme2510_i2c_xfer,
684 .functionality = lme2510_i2c_func,
687 static int lme2510_streaming_ctrl(struct dvb_frontend *fe, int onoff)
689 struct dvb_usb_adapter *adap = fe_to_adap(fe);
690 struct dvb_usb_device *d = adap_to_d(adap);
691 struct lme2510_state *st = adap_to_priv(adap);
692 static u8 clear_reg_3[] = LME_ALL_PIDS;
694 int ret = 0, rlen = sizeof(rbuf);
696 deb_info(1, "STM (%02x)", onoff);
698 /* Streaming is started by FE_HAS_LOCK */
702 deb_info(1, "STM Steam Off");
703 /* mutex is here only to avoid collision with I2C */
704 mutex_lock(&d->i2c_mutex);
706 ret = lme2510_usb_talk(d, clear_reg_3,
707 sizeof(clear_reg_3), rbuf, rlen);
709 st->i2c_talk_onoff = 1;
711 mutex_unlock(&d->i2c_mutex);
714 return (ret < 0) ? -ENODEV : 0;
717 static u8 check_sum(u8 *p, u8 len)
725 static int lme2510_download_firmware(struct dvb_usb_device *d,
726 const struct firmware *fw)
730 u16 j, wlen, len_in, start, end;
731 u8 packet_size, dlen, i;
737 data = kzalloc(128, GFP_KERNEL);
739 info("FRM Could not start Firmware Download"\
740 "(Buffer allocation failed)");
744 info("FRM Starting Firmware Download");
746 for (i = 1; i < 3; i++) {
747 start = (i == 1) ? 0 : 512;
748 end = (i == 1) ? 512 : fw->size;
749 for (j = start; j < end; j += (packet_size+1)) {
750 fw_data = (u8 *)(fw->data + j);
751 if ((end - j) > packet_size) {
756 dlen = (u8)(end - j)-1;
759 memcpy(&data[2], fw_data, dlen+1);
760 wlen = (u8) dlen + 4;
761 data[wlen-1] = check_sum(fw_data, dlen+1);
762 deb_info(1, "Data S=%02x:E=%02x CS= %02x", data[3],
763 data[dlen+2], data[dlen+3]);
764 lme2510_usb_talk(d, data, wlen, data, len_in);
765 ret |= (data[0] == 0x88) ? 0 : -1;
772 lme2510_usb_talk(d, data, len_in, data, len_in);
776 info("FRM Firmware Download Failed (%04x)" , ret);
778 info("FRM Firmware Download Completed - Resetting Device");
781 return RECONNECTS_USB;
784 static void lme_coldreset(struct dvb_usb_device *d)
788 info("FRM Firmware Cold Reset");
790 lme2510_usb_talk(d, data, sizeof(data), data, sizeof(data));
795 static const char fw_c_s7395[] = LME2510_C_S7395;
796 static const char fw_c_lg[] = LME2510_C_LG;
797 static const char fw_c_s0194[] = LME2510_C_S0194;
798 static const char fw_c_rs2000[] = LME2510_C_RS2000;
799 static const char fw_lg[] = LME2510_LG;
800 static const char fw_s0194[] = LME2510_S0194;
802 const char *lme_firmware_switch(struct dvb_usb_device *d, int cold)
804 struct lme2510_state *st = d->priv;
805 struct usb_device *udev = d->udev;
806 const struct firmware *fw = NULL;
810 cold = (cold > 0) ? (cold & 1) : 0;
812 switch (le16_to_cpu(udev->descriptor.idProduct)) {
814 switch (st->dvb_usb_lme2510_firmware) {
816 st->dvb_usb_lme2510_firmware = TUNER_S0194;
819 ret = request_firmware(&fw, fw_lme, &udev->dev);
824 st->dvb_usb_lme2510_firmware = TUNER_LG;
827 ret = request_firmware(&fw, fw_lme, &udev->dev);
830 st->dvb_usb_lme2510_firmware = TUNER_DEFAULT;
835 switch (st->dvb_usb_lme2510_firmware) {
837 st->dvb_usb_lme2510_firmware = TUNER_S7395;
840 ret = request_firmware(&fw, fw_lme, &udev->dev);
845 st->dvb_usb_lme2510_firmware = TUNER_LG;
848 ret = request_firmware(&fw, fw_lme, &udev->dev);
851 st->dvb_usb_lme2510_firmware = TUNER_S0194;
854 ret = request_firmware(&fw, fw_lme, &udev->dev);
857 st->dvb_usb_lme2510_firmware = TUNER_DEFAULT;
863 fw_lme = fw_c_rs2000;
864 st->dvb_usb_lme2510_firmware = TUNER_RS2000;
870 release_firmware(fw);
873 dvb_usb_lme2510_firmware = st->dvb_usb_lme2510_firmware;
874 info("FRM Changing to %s firmware", fw_lme);
882 static int lme2510_kill_urb(struct usb_data_stream *stream)
886 for (i = 0; i < stream->urbs_submitted; i++) {
887 deb_info(3, "killing URB no. %d.", i);
889 usb_kill_urb(stream->urb_list[i]);
891 stream->urbs_submitted = 0;
896 static struct tda10086_config tda10086_config = {
897 .demod_address = 0x1c,
900 .xtal_freq = TDA10086_XTAL_16M,
903 static struct stv0288_config lme_config = {
904 .demod_address = 0xd0,
906 .inittab = s7395_inittab,
909 static struct ix2505v_config lme_tuner = {
910 .tuner_address = 0xc0,
913 .tuner_chargepump = 0x3,
916 static struct stv0299_config sharp_z0194_config = {
917 .demod_address = 0xd0,
918 .inittab = sharp_z0194a_inittab,
922 .lock_output = STV0299_LOCKOUTPUT_1,
923 .volt13_op0_op1 = STV0299_VOLT13_OP1,
925 .set_symbol_rate = sharp_z0194a_set_symbol_rate,
928 static int dm04_rs2000_set_ts_param(struct dvb_frontend *fe,
931 struct dvb_usb_adapter *adap = fe_to_adap(fe);
932 struct dvb_usb_device *d = adap_to_d(adap);
933 struct lme2510_state *st = d->priv;
935 mutex_lock(&d->i2c_mutex);
936 if ((st->i2c_talk_onoff == 1) && (st->stream_on & 1)) {
937 st->i2c_talk_onoff = 0;
938 lme2510_stream_restart(d);
940 mutex_unlock(&d->i2c_mutex);
945 static struct m88rs2000_config m88rs2000_config = {
948 .set_ts_params = dm04_rs2000_set_ts_param,
951 static int dm04_lme2510_set_voltage(struct dvb_frontend *fe,
952 fe_sec_voltage_t voltage)
954 struct dvb_usb_device *d = fe_to_d(fe);
955 struct lme2510_state *st = fe_to_priv(fe);
956 static u8 voltage_low[] = LME_VOLTAGE_L;
957 static u8 voltage_high[] = LME_VOLTAGE_H;
959 int ret = 0, len = 3, rlen = 1;
961 mutex_lock(&d->i2c_mutex);
965 ret |= lme2510_usb_talk(d,
966 voltage_high, len, rbuf, rlen);
969 case SEC_VOLTAGE_OFF:
972 ret |= lme2510_usb_talk(d,
973 voltage_low, len, rbuf, rlen);
977 mutex_unlock(&d->i2c_mutex);
979 if (st->tuner_config == TUNER_RS2000)
980 if (st->fe_set_voltage)
981 st->fe_set_voltage(fe, voltage);
984 return (ret < 0) ? -ENODEV : 0;
987 static int dm04_rs2000_read_signal_strength(struct dvb_frontend *fe,
990 struct lme2510_state *st = fe_to_priv(fe);
992 *strength = (u16)((u32)st->signal_level * 0xffff / 0xff);
997 static int dm04_rs2000_read_snr(struct dvb_frontend *fe, u16 *snr)
999 struct lme2510_state *st = fe_to_priv(fe);
1001 *snr = (u16)((u32)st->signal_sn * 0xffff / 0x7f);
1006 static int dm04_read_ber(struct dvb_frontend *fe, u32 *ber)
1013 static int dm04_read_ucblocks(struct dvb_frontend *fe, u32 *ucblocks)
1020 static int lme_name(struct dvb_usb_adapter *adap)
1022 struct dvb_usb_device *d = adap_to_d(adap);
1023 struct lme2510_state *st = adap_to_priv(adap);
1024 const char *desc = d->name;
1025 char *fe_name[] = {"", " LG TDQY-P001F", " SHARP:BS2F7HZ7395",
1026 " SHARP:BS2F7HZ0194", " RS2000"};
1027 char *name = adap->fe[0]->ops.info.name;
1029 strlcpy(name, desc, 128);
1030 strlcat(name, fe_name[st->tuner_config], 128);
1035 static int dm04_lme2510_frontend_attach(struct dvb_usb_adapter *adap)
1037 struct dvb_usb_device *d = adap_to_d(adap);
1038 struct lme2510_state *st = d->priv;
1041 st->i2c_talk_onoff = 1;
1042 switch (le16_to_cpu(d->udev->descriptor.idProduct)) {
1046 adap->fe[0] = dvb_attach(tda10086_attach,
1047 &tda10086_config, &d->i2c_adap);
1049 info("TUN Found Frontend TDA10086");
1050 st->i2c_tuner_gate_w = 4;
1051 st->i2c_tuner_gate_r = 4;
1052 st->i2c_tuner_addr = 0xc0;
1053 st->tuner_config = TUNER_LG;
1054 if (st->dvb_usb_lme2510_firmware != TUNER_LG) {
1055 st->dvb_usb_lme2510_firmware = TUNER_LG;
1056 ret = lme_firmware_switch(d, 1) ? 0 : -ENODEV;
1062 adap->fe[0] = dvb_attach(stv0299_attach,
1063 &sharp_z0194_config, &d->i2c_adap);
1065 info("FE Found Stv0299");
1066 st->i2c_tuner_gate_w = 4;
1067 st->i2c_tuner_gate_r = 5;
1068 st->i2c_tuner_addr = 0xc0;
1069 st->tuner_config = TUNER_S0194;
1070 if (st->dvb_usb_lme2510_firmware != TUNER_S0194) {
1071 st->dvb_usb_lme2510_firmware = TUNER_S0194;
1072 ret = lme_firmware_switch(d, 1) ? 0 : -ENODEV;
1078 adap->fe[0] = dvb_attach(stv0288_attach, &lme_config,
1082 info("FE Found Stv0288");
1083 st->i2c_tuner_gate_w = 4;
1084 st->i2c_tuner_gate_r = 5;
1085 st->i2c_tuner_addr = 0xc0;
1086 st->tuner_config = TUNER_S7395;
1087 if (st->dvb_usb_lme2510_firmware != TUNER_S7395) {
1088 st->dvb_usb_lme2510_firmware = TUNER_S7395;
1089 ret = lme_firmware_switch(d, 1) ? 0 : -ENODEV;
1095 adap->fe[0] = dvb_attach(m88rs2000_attach,
1096 &m88rs2000_config, &d->i2c_adap);
1099 info("FE Found M88RS2000");
1100 st->i2c_tuner_gate_w = 5;
1101 st->i2c_tuner_gate_r = 5;
1102 st->i2c_tuner_addr = 0xc0;
1103 st->tuner_config = TUNER_RS2000;
1104 st->fe_set_voltage =
1105 adap->fe[0]->ops.set_voltage;
1107 adap->fe[0]->ops.read_signal_strength =
1108 dm04_rs2000_read_signal_strength;
1109 adap->fe[0]->ops.read_snr =
1110 dm04_rs2000_read_snr;
1111 adap->fe[0]->ops.read_ber =
1113 adap->fe[0]->ops.read_ucblocks =
1119 if (adap->fe[0] == NULL) {
1120 info("DM04/QQBOX Not Powered up or not Supported");
1126 dvb_frontend_detach(adap->fe[0]);
1133 adap->fe[0]->ops.set_voltage = dm04_lme2510_set_voltage;
1134 ret = lme_name(adap);
1138 static int dm04_lme2510_tuner(struct dvb_usb_adapter *adap)
1140 struct dvb_usb_device *d = adap_to_d(adap);
1141 struct lme2510_state *st = adap_to_priv(adap);
1142 char *tun_msg[] = {"", "TDA8263", "IX2505V", "DVB_PLL_OPERA", "RS2000"};
1145 switch (st->tuner_config) {
1147 if (dvb_attach(tda826x_attach, adap->fe[0], 0xc0,
1149 ret = st->tuner_config;
1152 if (dvb_attach(ix2505v_attach , adap->fe[0], &lme_tuner,
1154 ret = st->tuner_config;
1157 if (dvb_attach(dvb_pll_attach , adap->fe[0], 0xc0,
1158 &d->i2c_adap, DVB_PLL_OPERA1))
1159 ret = st->tuner_config;
1162 ret = st->tuner_config;
1169 info("TUN Found %s tuner", tun_msg[ret]);
1171 info("TUN No tuner found --- resetting device");
1176 /* Start the Interrupt*/
1177 ret = lme2510_int_read(adap);
1179 info("INT Unable to start Interrupt Service");
1186 static int lme2510_powerup(struct dvb_usb_device *d, int onoff)
1188 struct lme2510_state *st = d->priv;
1189 static u8 lnb_on[] = LNB_ON;
1190 static u8 lnb_off[] = LNB_OFF;
1192 int ret = 0, len = 3, rlen = 1;
1194 mutex_lock(&d->i2c_mutex);
1197 ret = lme2510_usb_talk(d, lnb_on, len, rbuf, rlen);
1199 ret = lme2510_usb_talk(d, lnb_off, len, rbuf, rlen);
1201 st->i2c_talk_onoff = 1;
1203 mutex_unlock(&d->i2c_mutex);
1208 static int lme2510_get_adapter_count(struct dvb_usb_device *d)
1213 static int lme2510_identify_state(struct dvb_usb_device *d, const char **name)
1215 struct lme2510_state *st = d->priv;
1217 usb_reset_configuration(d->udev);
1219 usb_set_interface(d->udev,
1220 d->intf->cur_altsetting->desc.bInterfaceNumber, 1);
1222 st->dvb_usb_lme2510_firmware = dvb_usb_lme2510_firmware;
1224 if (lme2510_return_status(d) == 0x44) {
1225 *name = lme_firmware_switch(d, 0);
1232 static int lme2510_get_stream_config(struct dvb_frontend *fe, u8 *ts_type,
1233 struct usb_data_stream_properties *stream)
1235 struct dvb_usb_adapter *adap = fe_to_adap(fe);
1236 struct dvb_usb_device *d = adap_to_d(adap);
1240 /* Turn PID filter on the fly by module option */
1241 if (pid_filter == 2) {
1242 adap->pid_filtering = 1;
1243 adap->max_feed_count = 15;
1246 if (!(le16_to_cpu(d->udev->descriptor.idProduct)
1248 stream->endpoint = 0x8;
1253 static int lme2510_get_rc_config(struct dvb_usb_device *d,
1254 struct dvb_usb_rc *rc)
1256 rc->allowed_protos = RC_TYPE_NEC;
1260 static void *lme2510_exit_int(struct dvb_usb_device *d)
1262 struct lme2510_state *st = d->priv;
1263 struct dvb_usb_adapter *adap = &d->adapter[0];
1264 void *buffer = NULL;
1267 lme2510_kill_urb(&adap->stream);
1270 if (st->usb_buffer != NULL) {
1271 st->i2c_talk_onoff = 1;
1272 st->signal_lock = 0;
1273 st->signal_level = 0;
1275 buffer = st->usb_buffer;
1278 if (st->lme_urb != NULL) {
1279 usb_kill_urb(st->lme_urb);
1280 usb_free_coherent(d->udev, 128, st->buffer,
1281 st->lme_urb->transfer_dma);
1282 info("Interrupt Service Stopped");
1288 static void lme2510_exit(struct dvb_usb_device *d)
1293 usb_buffer = lme2510_exit_int(d);
1294 if (usb_buffer != NULL)
1299 static struct dvb_usb_device_properties lme2510_props = {
1300 .driver_name = KBUILD_MODNAME,
1301 .owner = THIS_MODULE,
1302 .bInterfaceNumber = 0,
1303 .adapter_nr = adapter_nr,
1304 .size_of_priv = sizeof(struct lme2510_state),
1306 .download_firmware = lme2510_download_firmware,
1308 .power_ctrl = lme2510_powerup,
1309 .identify_state = lme2510_identify_state,
1310 .i2c_algo = &lme2510_i2c_algo,
1312 .frontend_attach = dm04_lme2510_frontend_attach,
1313 .tuner_attach = dm04_lme2510_tuner,
1314 .get_stream_config = lme2510_get_stream_config,
1315 .get_adapter_count = lme2510_get_adapter_count,
1316 .streaming_ctrl = lme2510_streaming_ctrl,
1318 .get_rc_config = lme2510_get_rc_config,
1320 .exit = lme2510_exit,
1323 .caps = DVB_USB_ADAP_HAS_PID_FILTER|
1324 DVB_USB_ADAP_PID_FILTER_CAN_BE_TURNED_OFF,
1325 .pid_filter_count = 15,
1326 .pid_filter = lme2510_pid_filter,
1327 .pid_filter_ctrl = lme2510_pid_filter_ctrl,
1329 DVB_USB_STREAM_BULK(0x86, 10, 4096),
1336 static const struct usb_device_id lme2510_id_table[] = {
1337 { DVB_USB_DEVICE(0x3344, 0x1122, &lme2510_props,
1338 "DM04_LME2510_DVB-S", RC_MAP_LME2510) },
1339 { DVB_USB_DEVICE(0x3344, 0x1120, &lme2510_props,
1340 "DM04_LME2510C_DVB-S", RC_MAP_LME2510) },
1341 { DVB_USB_DEVICE(0x3344, 0x22f0, &lme2510_props,
1342 "DM04_LME2510C_DVB-S RS2000", RC_MAP_LME2510) },
1343 {} /* Terminating entry */
1346 MODULE_DEVICE_TABLE(usb, lme2510_id_table);
1348 static struct usb_driver lme2510_driver = {
1349 .name = KBUILD_MODNAME,
1350 .probe = dvb_usbv2_probe,
1351 .disconnect = dvb_usbv2_disconnect,
1352 .id_table = lme2510_id_table,
1357 module_usb_driver(lme2510_driver);
1359 MODULE_AUTHOR("Malcolm Priestley <tvboxspy@gmail.com>");
1360 MODULE_DESCRIPTION("LME2510(C) DVB-S USB2.0");
1361 MODULE_VERSION("2.06");
1362 MODULE_LICENSE("GPL");
1363 MODULE_FIRMWARE(LME2510_C_S7395);
1364 MODULE_FIRMWARE(LME2510_C_LG);
1365 MODULE_FIRMWARE(LME2510_C_S0194);
1366 MODULE_FIRMWARE(LME2510_C_RS2000);
1367 MODULE_FIRMWARE(LME2510_LG);
1368 MODULE_FIRMWARE(LME2510_S0194);