1 /* DVB USB compliant linux driver for
3 * DM04/QQBOX DVB-S USB BOX LME2510C + SHARP:BS2F7HZ7395
4 * LME2510C + LG TDQY-P001F
5 * LME2510C + BS2F7HZ0194
6 * LME2510 + LG TDQY-P001F
7 * LME2510 + BS2F7HZ0194
9 * MVB7395 (LME2510C+SHARP:BS2F7HZ7395)
10 * SHARP:BS2F7HZ7395 = (STV0288+Sharp IX2505V)
12 * MV001F (LME2510+LGTDQY-P001F)
13 * LG TDQY - P001F =(TDA8263 + TDA10086H)
15 * MVB0001F (LME2510C+LGTDQT-P001F)
17 * MV0194 (LME2510+SHARP:BS2F7HZ0194)
18 * SHARP:BS2F7HZ0194 = (STV0299+IX2410)
20 * MVB0194 (LME2510C+SHARP0194)
22 * For firmware see Documentation/dvb/lmedm04.txt
25 * 0xd0 - STV0288 - Demodulator
26 * 0xc0 - Sharp IX2505V - Tuner
28 * 0x1c - TDA10086 - Demodulator
29 * 0xc0 - TDA8263 - Tuner
31 * 0xd0 - STV0299 - Demodulator
32 * 0xc0 - IX2410 - Tuner
35 * VID = 3344 PID LME2510=1122 LME2510C=1120
37 * Copyright (C) 2010 Malcolm Priestley (tvboxspy@gmail.com)
38 * LME2510(C)(C) Leaguerme (Shenzhen) MicroElectronics Co., Ltd.
40 * This program is free software; you can redistribute it and/or modify
41 * it under the terms of the GNU General Public License Version 2, as
42 * published by the Free Software Foundation.
44 * This program is distributed in the hope that it will be useful,
45 * but WITHOUT ANY WARRANTY; without even the implied warranty of
46 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
47 * GNU General Public License for more details.
49 * You should have received a copy of the GNU General Public License
50 * along with this program; if not, write to the Free Software
51 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
54 * see Documentation/dvb/README.dvb-usb for more information
57 * LME2510: Non Intel USB chipsets fail to maintain High Speed on
60 * QQbox suffers from noise on LNB voltage.
62 * LME2510: SHARP:BS2F7HZ0194(MV0194) cannot cold reset and share system
63 * with other tuners. After a cold reset streaming will not start.
66 #define DVB_USB_LOG_PREFIX "LME2510(C)"
67 #include <linux/usb.h>
68 #include <linux/usb/input.h>
69 #include <media/rc-core.h>
84 static int dvb_usb_lme2510_debug;
85 #define l_dprintk(var, level, args...) do { \
87 printk(KERN_DEBUG DVB_USB_LOG_PREFIX ": " args); \
90 #define deb_info(level, args...) l_dprintk(dvb_usb_lme2510_debug, level, args)
91 #define debug_data_snipet(level, name, p) \
92 deb_info(level, name" (%02x%02x%02x%02x%02x%02x%02x%02x)", \
93 *p, *(p+1), *(p+2), *(p+3), *(p+4), \
94 *(p+5), *(p+6), *(p+7));
97 module_param_named(debug, dvb_usb_lme2510_debug, int, 0644);
98 MODULE_PARM_DESC(debug, "set debugging level (1=info (or-able))."
99 DVB_USB_DEBUG_STATUS);
101 static int dvb_usb_lme2510_firmware;
102 module_param_named(firmware, dvb_usb_lme2510_firmware, int, 0644);
103 MODULE_PARM_DESC(firmware, "set default firmware 0=Sharp7395 1=LG");
105 static int pid_filter;
106 module_param_named(pid, pid_filter, int, 0644);
107 MODULE_PARM_DESC(pid, "set default 0=on 1=off");
110 DVB_DEFINE_MOD_OPT_ADAPTER_NR(adapter_nr);
112 #define TUNER_DEFAULT 0x0
114 #define TUNER_S7395 0x2
115 #define TUNER_S0194 0x3
117 struct lme2510_state {
137 static int lme2510_bulk_write(struct usb_device *dev,
138 u8 *snd, int len, u8 pipe)
142 ret = usb_bulk_msg(dev, usb_sndbulkpipe(dev, pipe),
143 snd, len , &actual_l, 100);
147 static int lme2510_bulk_read(struct usb_device *dev,
148 u8 *rev, int len, u8 pipe)
152 ret = usb_bulk_msg(dev, usb_rcvbulkpipe(dev, pipe),
153 rev, len , &actual_l, 200);
157 static int lme2510_usb_talk(struct dvb_usb_device *d,
158 u8 *wbuf, int wlen, u8 *rbuf, int rlen)
160 struct lme2510_state *st = d->priv;
164 if (st->usb_buffer == NULL) {
165 st->usb_buffer = kmalloc(64, GFP_KERNEL);
166 if (st->usb_buffer == NULL) {
167 info("MEM Error no memory");
171 buff = st->usb_buffer;
173 ret = mutex_lock_interruptible(&d->usb_mutex);
178 /* the read/write capped at 64 */
179 memcpy(buff, wbuf, (wlen < 64) ? wlen : 64);
181 ret |= usb_clear_halt(d->udev, usb_sndbulkpipe(d->udev, 0x01));
183 ret |= lme2510_bulk_write(d->udev, buff, wlen , 0x01);
187 ret |= usb_clear_halt(d->udev, usb_rcvbulkpipe(d->udev, 0x01));
189 ret |= lme2510_bulk_read(d->udev, buff, (rlen < 64) ?
193 memcpy(rbuf, buff, rlen);
195 mutex_unlock(&d->usb_mutex);
197 return (ret < 0) ? -ENODEV : 0;
200 static int lme2510_stream_restart(struct dvb_usb_device *d)
202 static u8 stream_on[] = LME_ST_ON_W;
205 /*Restart Stream Command*/
206 ret = lme2510_usb_talk(d, stream_on, sizeof(stream_on),
207 rbuff, sizeof(rbuff));
211 static int lme2510_enable_pid(struct dvb_usb_device *d, u8 index, u16 pid_out)
213 struct lme2510_state *st = d->priv;
214 static u8 pid_buff[] = LME_ZERO_PID;
216 u8 pid_no = index * 2;
217 u8 pid_len = pid_no + 2;
219 deb_info(1, "PID Setting Pid %04x", pid_out);
221 if (st->pid_size == 0)
222 ret |= lme2510_stream_restart(d);
224 pid_buff[2] = pid_no;
225 pid_buff[3] = (u8)pid_out & 0xff;
226 pid_buff[4] = pid_no + 1;
227 pid_buff[5] = (u8)(pid_out >> 8);
229 if (pid_len > st->pid_size)
230 st->pid_size = pid_len;
231 pid_buff[7] = 0x80 + st->pid_size;
233 ret |= lme2510_usb_talk(d, pid_buff ,
234 sizeof(pid_buff) , rbuf, sizeof(rbuf));
237 ret |= lme2510_stream_restart(d);
242 static void lme2510_int_response(struct urb *lme_urb)
244 struct dvb_usb_adapter *adap = lme_urb->context;
245 struct lme2510_state *st = adap->dev->priv;
246 static u8 *ibuf, *rbuf;
250 switch (lme_urb->status) {
259 info("Error %x", lme_urb->status);
263 rbuf = (u8 *) lme_urb->transfer_buffer;
265 offset = ((lme_urb->actual_length/8) > 4)
266 ? 4 : (lme_urb->actual_length/8) ;
268 for (i = 0; i < offset; ++i) {
269 ibuf = (u8 *)&rbuf[i*8];
270 deb_info(5, "INT O/S C =%02x C/O=%02x Type =%02x%02x",
271 offset, i, ibuf[0], ibuf[1]);
275 debug_data_snipet(1, "INT Remote data snipet", ibuf);
276 if ((ibuf[4] + ibuf[5]) == 0xff) {
279 ? (ibuf[3] ^ 0xff) << 8 : 0;
280 key += (ibuf[2] ^ 0xff) << 16;
281 deb_info(1, "INT Key =%08x", key);
282 if (adap->dev->rc_dev != NULL)
283 rc_keydown(adap->dev->rc_dev, key, 0);
287 switch (st->tuner_config) {
290 st->signal_lock = ibuf[2];
291 st->signal_level = ibuf[4];
292 st->signal_sn = ibuf[3];
293 st->time_key = ibuf[7];
297 /* Tweak for earlier firmware*/
298 if (ibuf[1] == 0x03) {
300 st->signal_lock = ibuf[2];
301 st->signal_level = ibuf[3];
302 st->signal_sn = ibuf[4];
304 st->signal_level = ibuf[4];
305 st->signal_sn = ibuf[5];
307 (st->signal_lock & 0xf7) +
308 ((ibuf[2] & 0x01) << 0x03);
314 debug_data_snipet(5, "INT Remote data snipet in", ibuf);
317 debug_data_snipet(1, "INT Control data snipet", ibuf);
320 debug_data_snipet(1, "INT Unknown data snipet", ibuf);
324 usb_submit_urb(lme_urb, GFP_ATOMIC);
327 static int lme2510_int_read(struct dvb_usb_adapter *adap)
329 struct dvb_usb_device *d = adap->dev;
330 struct lme2510_state *lme_int = adap->dev->priv;
331 struct usb_host_endpoint *ep;
333 lme_int->lme_urb = usb_alloc_urb(0, GFP_ATOMIC);
335 if (lme_int->lme_urb == NULL)
338 lme_int->buffer = usb_alloc_coherent(adap->dev->udev, 128, GFP_ATOMIC,
339 &lme_int->lme_urb->transfer_dma);
341 if (lme_int->buffer == NULL)
344 usb_fill_int_urb(lme_int->lme_urb,
346 usb_rcvintpipe(adap->dev->udev, 0xa),
349 lme2510_int_response,
353 /* Quirk of pipe reporting PIPE_BULK but behaves as interrupt */
354 ep = usb_pipe_endpoint(d->udev, lme_int->lme_urb->pipe);
356 if (usb_endpoint_type(&ep->desc) == USB_ENDPOINT_XFER_BULK)
357 lme_int->lme_urb->pipe = usb_rcvbulkpipe(d->udev, 0xa),
359 lme_int->lme_urb->transfer_flags |= URB_NO_TRANSFER_DMA_MAP;
361 usb_submit_urb(lme_int->lme_urb, GFP_ATOMIC);
362 info("INT Interrupt Service Started");
367 static int lme2510_pid_filter_ctrl(struct dvb_usb_adapter *adap, int onoff)
369 struct lme2510_state *st = adap->dev->priv;
370 static u8 clear_pid_reg[] = LME_CLEAR_PID;
374 deb_info(1, "PID Clearing Filter");
376 ret = mutex_lock_interruptible(&adap->dev->i2c_mutex);
381 ret |= lme2510_usb_talk(adap->dev, clear_pid_reg,
382 sizeof(clear_pid_reg), rbuf, sizeof(rbuf));
386 mutex_unlock(&adap->dev->i2c_mutex);
391 static int lme2510_pid_filter(struct dvb_usb_adapter *adap, int index, u16 pid,
396 deb_info(3, "%s PID=%04x Index=%04x onoff=%02x", __func__,
401 ret = mutex_lock_interruptible(&adap->dev->i2c_mutex);
404 ret |= lme2510_enable_pid(adap->dev, index, pid);
405 mutex_unlock(&adap->dev->i2c_mutex);
413 static int lme2510_return_status(struct usb_device *dev)
418 data = kzalloc(10, GFP_KERNEL);
422 ret |= usb_control_msg(dev, usb_rcvctrlpipe(dev, 0),
423 0x06, 0x80, 0x0302, 0x00, data, 0x0006, 200);
424 info("Firmware Status: %x (%x)", ret , data[2]);
426 ret = (ret < 0) ? -ENODEV : data[2];
431 static int lme2510_msg(struct dvb_usb_device *d,
432 u8 *wbuf, int wlen, u8 *rbuf, int rlen)
435 struct lme2510_state *st = d->priv;
437 if (mutex_lock_interruptible(&d->i2c_mutex) < 0)
440 if (st->i2c_talk_onoff == 1) {
442 ret = lme2510_usb_talk(d, wbuf, wlen, rbuf, rlen);
444 switch (st->tuner_config) {
446 if (wbuf[2] == 0x1c) {
447 if (wbuf[3] == 0x0e) {
448 st->signal_lock = rbuf[1];
449 if ((st->stream_on & 1) &&
450 (st->signal_lock & 0x10)) {
451 lme2510_stream_restart(d);
452 st->i2c_talk_onoff = 0;
459 if (wbuf[2] == 0xd0) {
460 if (wbuf[3] == 0x24) {
461 st->signal_lock = rbuf[1];
462 if ((st->stream_on & 1) &&
463 (st->signal_lock & 0x8)) {
464 lme2510_stream_restart(d);
465 st->i2c_talk_onoff = 0;
468 if ((wbuf[3] != 0x6) & (wbuf[3] != 0x5))
473 if (wbuf[2] == 0xd0) {
474 if (wbuf[3] == 0x1b) {
475 st->signal_lock = rbuf[1];
476 if ((st->stream_on & 1) &&
477 (st->signal_lock & 0x8)) {
478 lme2510_stream_restart(d);
479 st->i2c_talk_onoff = 0;
488 switch (st->tuner_config) {
493 rbuf[1] = st->signal_lock;
497 rbuf[1] = st->signal_level;
501 rbuf[1] = st->signal_sn;
511 lme2510_usb_talk(d, wbuf, wlen, rbuf, rlen);
512 st->i2c_talk_onoff = 1;
520 rbuf[1] = (st->signal_level & 0x80)
521 ? 0 : (st->signal_level * 2);
525 rbuf[1] = st->signal_sn;
529 rbuf[1] = st->signal_lock;
538 lme2510_usb_talk(d, wbuf, wlen, rbuf, rlen);
539 st->i2c_talk_onoff = 1;
547 rbuf[1] = (st->signal_level & 0x80)
548 ? 0 : (st->signal_level * 2);
552 rbuf[1] = st->signal_sn;
556 rbuf[1] = st->signal_lock;
566 lme2510_usb_talk(d, wbuf, wlen, rbuf, rlen);
567 st->i2c_talk_onoff = 1;
575 deb_info(4, "I2C From Interrupt Message out(%02x) in(%02x)",
580 mutex_unlock(&d->i2c_mutex);
586 static int lme2510_i2c_xfer(struct i2c_adapter *adap, struct i2c_msg msg[],
589 struct dvb_usb_device *d = i2c_get_adapdata(adap);
590 struct lme2510_state *st = d->priv;
591 static u8 obuf[64], ibuf[64];
594 u8 gate = st->i2c_gate;
600 warn("more than 2 i2c messages"
601 "at a time is not handled yet. TODO.");
603 for (i = 0; i < num; i++) {
604 read_o = 1 & (msg[i].flags & I2C_M_RD);
605 read = i+1 < num && (msg[i+1].flags & I2C_M_RD);
607 gate = (msg[i].addr == st->i2c_tuner_addr)
608 ? (read) ? st->i2c_tuner_gate_r
609 : st->i2c_tuner_gate_w
611 obuf[0] = gate | (read << 7);
614 obuf[1] = (read) ? 2 : msg[i].len + 1;
616 obuf[1] = msg[i].len + read + 1;
618 obuf[2] = msg[i].addr;
623 memcpy(&obuf[3], msg[i].buf, msg[i].len);
624 obuf[msg[i].len+3] = msg[i+1].len;
628 memcpy(&obuf[3], msg[i].buf, msg[i].len);
632 if (lme2510_msg(d, obuf, len, ibuf, 64) < 0) {
633 deb_info(1, "i2c transfer failed.");
639 memcpy(msg[i].buf, &ibuf[1], msg[i].len);
641 memcpy(msg[i+1].buf, &ibuf[1], msg[i+1].len);
649 static u32 lme2510_i2c_func(struct i2c_adapter *adapter)
654 static struct i2c_algorithm lme2510_i2c_algo = {
655 .master_xfer = lme2510_i2c_xfer,
656 .functionality = lme2510_i2c_func,
659 /* Callbacks for DVB USB */
660 static int lme2510_identify_state(struct usb_device *udev,
661 struct dvb_usb_device_properties *props,
662 struct dvb_usb_device_description **desc,
669 static int lme2510_streaming_ctrl(struct dvb_usb_adapter *adap, int onoff)
671 struct lme2510_state *st = adap->dev->priv;
672 static u8 clear_reg_3[] = LME_CLEAR_PID;
674 int ret = 0, rlen = sizeof(rbuf);
676 deb_info(1, "STM (%02x)", onoff);
678 /* Streaming is started by FE_HAS_LOCK */
682 deb_info(1, "STM Steam Off");
683 /* mutex is here only to avoid collision with I2C */
684 if (mutex_lock_interruptible(&adap->dev->i2c_mutex) < 0)
687 ret = lme2510_usb_talk(adap->dev, clear_reg_3,
688 sizeof(clear_reg_3), rbuf, rlen);
690 st->i2c_talk_onoff = 1;
692 mutex_unlock(&adap->dev->i2c_mutex);
695 return (ret < 0) ? -ENODEV : 0;
698 static u8 check_sum(u8 *p, u8 len)
706 static int lme2510_download_firmware(struct usb_device *dev,
707 const struct firmware *fw)
711 u16 j, wlen, len_in, start, end;
712 u8 packet_size, dlen, i;
718 data = kzalloc(512, GFP_KERNEL);
720 info("FRM Could not start Firmware Download (Buffer allocation failed)");
724 info("FRM Starting Firmware Download");
726 for (i = 1; i < 3; i++) {
727 start = (i == 1) ? 0 : 512;
728 end = (i == 1) ? 512 : fw->size;
729 for (j = start; j < end; j += (packet_size+1)) {
730 fw_data = (u8 *)(fw->data + j);
731 if ((end - j) > packet_size) {
736 dlen = (u8)(end - j)-1;
739 memcpy(&data[2], fw_data, dlen+1);
740 wlen = (u8) dlen + 4;
741 data[wlen-1] = check_sum(fw_data, dlen+1);
742 deb_info(1, "Data S=%02x:E=%02x CS= %02x", data[3],
743 data[dlen+2], data[dlen+3]);
744 ret |= lme2510_bulk_write(dev, data, wlen, 1);
745 ret |= lme2510_bulk_read(dev, data, len_in , 1);
746 ret |= (data[0] == 0x88) ? 0 : -1;
750 usb_control_msg(dev, usb_rcvctrlpipe(dev, 0),
751 0x06, 0x80, 0x0200, 0x00, data, 0x0109, 1000);
757 ret |= lme2510_bulk_write(dev, data , len_in, 1); /*Resetting*/
758 ret |= lme2510_bulk_read(dev, data, len_in, 1);
762 info("FRM Firmware Download Failed (%04x)" , ret);
764 info("FRM Firmware Download Completed - Resetting Device");
767 return (ret < 0) ? -ENODEV : 0;
770 static void lme_coldreset(struct usb_device *dev)
777 info("FRM Firmware Cold Reset");
778 ret |= lme2510_bulk_write(dev, data , len_in, 1); /*Cold Resetting*/
779 ret |= lme2510_bulk_read(dev, data, len_in, 1);
784 static int lme_firmware_switch(struct usb_device *udev, int cold)
786 const struct firmware *fw = NULL;
787 const char fw_c_s7395[] = "dvb-usb-lme2510c-s7395.fw";
788 const char fw_c_lg[] = "dvb-usb-lme2510c-lg.fw";
789 const char fw_c_s0194[] = "dvb-usb-lme2510c-s0194.fw";
790 const char fw_lg[] = "dvb-usb-lme2510-lg.fw";
791 const char fw_s0194[] = "dvb-usb-lme2510-s0194.fw";
795 cold = (cold > 0) ? (cold & 1) : 0;
799 if (le16_to_cpu(udev->descriptor.idProduct) == 0x1122) {
800 switch (dvb_usb_lme2510_firmware) {
802 dvb_usb_lme2510_firmware = TUNER_S0194;
805 ret = request_firmware(&fw, fw_lme, &udev->dev);
810 dvb_usb_lme2510_firmware = TUNER_LG;
813 ret = request_firmware(&fw, fw_lme, &udev->dev);
816 info("FRM No Firmware Found - please install");
817 dvb_usb_lme2510_firmware = TUNER_DEFAULT;
823 switch (dvb_usb_lme2510_firmware) {
825 dvb_usb_lme2510_firmware = TUNER_S7395;
828 ret = request_firmware(&fw, fw_lme, &udev->dev);
833 dvb_usb_lme2510_firmware = TUNER_LG;
836 ret = request_firmware(&fw, fw_lme, &udev->dev);
839 dvb_usb_lme2510_firmware = TUNER_S0194;
842 ret = request_firmware(&fw, fw_lme, &udev->dev);
845 info("FRM No Firmware Found - please install");
846 dvb_usb_lme2510_firmware = TUNER_DEFAULT;
854 info("FRM Loading %s file", fw_lme);
855 ret = lme2510_download_firmware(udev, fw);
858 release_firmware(fw);
861 info("FRM Changing to %s firmware", fw_lme);
869 static int lme2510_kill_urb(struct usb_data_stream *stream)
873 for (i = 0; i < stream->urbs_submitted; i++) {
874 deb_info(3, "killing URB no. %d.", i);
876 usb_kill_urb(stream->urb_list[i]);
878 stream->urbs_submitted = 0;
883 static struct tda10086_config tda10086_config = {
884 .demod_address = 0x1c,
887 .xtal_freq = TDA10086_XTAL_16M,
890 static struct stv0288_config lme_config = {
891 .demod_address = 0xd0,
893 .inittab = s7395_inittab,
896 static struct ix2505v_config lme_tuner = {
897 .tuner_address = 0xc0,
900 .tuner_chargepump = 0x3,
903 static struct stv0299_config sharp_z0194_config = {
904 .demod_address = 0xd0,
905 .inittab = sharp_z0194a_inittab,
909 .lock_output = STV0299_LOCKOUTPUT_1,
910 .volt13_op0_op1 = STV0299_VOLT13_OP1,
912 .set_symbol_rate = sharp_z0194a_set_symbol_rate,
915 static int dm04_lme2510_set_voltage(struct dvb_frontend *fe,
916 fe_sec_voltage_t voltage)
918 struct dvb_usb_adapter *adap = fe->dvb->priv;
919 static u8 voltage_low[] = LME_VOLTAGE_L;
920 static u8 voltage_high[] = LME_VOLTAGE_H;
922 int ret = 0, len = 3, rlen = 1;
924 if (mutex_lock_interruptible(&adap->dev->i2c_mutex) < 0)
929 ret |= lme2510_usb_talk(adap->dev,
930 voltage_high, len, rbuf, rlen);
933 case SEC_VOLTAGE_OFF:
936 ret |= lme2510_usb_talk(adap->dev,
937 voltage_low, len, rbuf, rlen);
941 mutex_unlock(&adap->dev->i2c_mutex);
943 return (ret < 0) ? -ENODEV : 0;
946 static int lme_name(struct dvb_usb_adapter *adap)
948 struct lme2510_state *st = adap->dev->priv;
949 const char *desc = adap->dev->desc->name;
950 char *fe_name[] = {"", " LG TDQY-P001F", " SHARP:BS2F7HZ7395",
951 " SHARP:BS2F7HZ0194"};
952 char *name = adap->fe_adap[0].fe->ops.info.name;
954 strlcpy(name, desc, 128);
955 strlcat(name, fe_name[st->tuner_config], 128);
960 static int dm04_lme2510_frontend_attach(struct dvb_usb_adapter *adap)
962 struct lme2510_state *st = adap->dev->priv;
966 st->i2c_talk_onoff = 1;
969 adap->fe_adap[0].fe = dvb_attach(tda10086_attach, &tda10086_config,
970 &adap->dev->i2c_adap);
972 if (adap->fe_adap[0].fe) {
973 info("TUN Found Frontend TDA10086");
974 st->i2c_tuner_gate_w = 4;
975 st->i2c_tuner_gate_r = 4;
976 st->i2c_tuner_addr = 0xc0;
977 st->tuner_config = TUNER_LG;
978 if (dvb_usb_lme2510_firmware != TUNER_LG) {
979 dvb_usb_lme2510_firmware = TUNER_LG;
980 ret = lme_firmware_switch(adap->dev->udev, 1);
986 adap->fe_adap[0].fe = dvb_attach(stv0299_attach, &sharp_z0194_config,
987 &adap->dev->i2c_adap);
988 if (adap->fe_adap[0].fe) {
989 info("FE Found Stv0299");
990 st->i2c_tuner_gate_w = 4;
991 st->i2c_tuner_gate_r = 5;
992 st->i2c_tuner_addr = 0xc0;
993 st->tuner_config = TUNER_S0194;
994 if (dvb_usb_lme2510_firmware != TUNER_S0194) {
995 dvb_usb_lme2510_firmware = TUNER_S0194;
996 ret = lme_firmware_switch(adap->dev->udev, 1);
1002 adap->fe_adap[0].fe = dvb_attach(stv0288_attach, &lme_config,
1003 &adap->dev->i2c_adap);
1004 if (adap->fe_adap[0].fe) {
1005 info("FE Found Stv0288");
1006 st->i2c_tuner_gate_w = 4;
1007 st->i2c_tuner_gate_r = 5;
1008 st->i2c_tuner_addr = 0xc0;
1009 st->tuner_config = TUNER_S7395;
1010 if (dvb_usb_lme2510_firmware != TUNER_S7395) {
1011 dvb_usb_lme2510_firmware = TUNER_S7395;
1012 ret = lme_firmware_switch(adap->dev->udev, 1);
1015 info("DM04 Not Supported");
1021 if (adap->fe_adap[0].fe) {
1022 dvb_frontend_detach(adap->fe_adap[0].fe);
1023 adap->fe_adap[0].fe = NULL;
1025 adap->dev->props.rc.core.rc_codes = NULL;
1029 adap->fe_adap[0].fe->ops.set_voltage = dm04_lme2510_set_voltage;
1030 ret = lme_name(adap);
1034 static int dm04_lme2510_tuner(struct dvb_usb_adapter *adap)
1036 struct lme2510_state *st = adap->dev->priv;
1037 char *tun_msg[] = {"", "TDA8263", "IX2505V", "DVB_PLL_OPERA"};
1040 switch (st->tuner_config) {
1042 if (dvb_attach(tda826x_attach, adap->fe_adap[0].fe, 0xc0,
1043 &adap->dev->i2c_adap, 1))
1044 ret = st->tuner_config;
1047 if (dvb_attach(ix2505v_attach , adap->fe_adap[0].fe, &lme_tuner,
1048 &adap->dev->i2c_adap))
1049 ret = st->tuner_config;
1052 if (dvb_attach(dvb_pll_attach , adap->fe_adap[0].fe, 0xc0,
1053 &adap->dev->i2c_adap, DVB_PLL_OPERA1))
1054 ret = st->tuner_config;
1061 info("TUN Found %s tuner", tun_msg[ret]);
1063 info("TUN No tuner found --- reseting device");
1064 lme_coldreset(adap->dev->udev);
1068 /* Start the Interrupt*/
1069 ret = lme2510_int_read(adap);
1071 info("INT Unable to start Interrupt Service");
1078 static int lme2510_powerup(struct dvb_usb_device *d, int onoff)
1080 struct lme2510_state *st = d->priv;
1081 static u8 lnb_on[] = LNB_ON;
1082 static u8 lnb_off[] = LNB_OFF;
1084 int ret, len = 3, rlen = 1;
1086 if (mutex_lock_interruptible(&d->i2c_mutex) < 0)
1090 ret = lme2510_usb_talk(d, lnb_on, len, rbuf, rlen);
1092 ret = lme2510_usb_talk(d, lnb_off, len, rbuf, rlen);
1094 st->i2c_talk_onoff = 1;
1096 mutex_unlock(&d->i2c_mutex);
1101 /* DVB USB Driver stuff */
1102 static struct dvb_usb_device_properties lme2510_properties;
1103 static struct dvb_usb_device_properties lme2510c_properties;
1105 static int lme2510_probe(struct usb_interface *intf,
1106 const struct usb_device_id *id)
1108 struct usb_device *udev = interface_to_usbdev(intf);
1111 usb_reset_configuration(udev);
1113 usb_set_interface(udev, intf->cur_altsetting->desc.bInterfaceNumber, 1);
1115 if (udev->speed != USB_SPEED_HIGH) {
1116 ret = usb_reset_device(udev);
1117 info("DEV Failed to connect in HIGH SPEED mode");
1121 if (lme2510_return_status(udev) == 0x44) {
1122 lme_firmware_switch(udev, 0);
1126 if (0 == dvb_usb_device_init(intf, &lme2510_properties,
1127 THIS_MODULE, NULL, adapter_nr)) {
1128 info("DEV registering device driver");
1131 if (0 == dvb_usb_device_init(intf, &lme2510c_properties,
1132 THIS_MODULE, NULL, adapter_nr)) {
1133 info("DEV registering device driver");
1137 info("DEV lme2510 Error");
1142 static struct usb_device_id lme2510_table[] = {
1143 { USB_DEVICE(0x3344, 0x1122) }, /* LME2510 */
1144 { USB_DEVICE(0x3344, 0x1120) }, /* LME2510C */
1145 {} /* Terminating entry */
1148 MODULE_DEVICE_TABLE(usb, lme2510_table);
1150 static struct dvb_usb_device_properties lme2510_properties = {
1151 .caps = DVB_USB_IS_AN_I2C_ADAPTER,
1152 .size_of_priv = sizeof(struct lme2510_state),
1158 .caps = DVB_USB_ADAP_HAS_PID_FILTER|
1159 DVB_USB_ADAP_NEED_PID_FILTERING|
1160 DVB_USB_ADAP_PID_FILTER_CAN_BE_TURNED_OFF,
1161 .streaming_ctrl = lme2510_streaming_ctrl,
1162 .pid_filter_count = 15,
1163 .pid_filter = lme2510_pid_filter,
1164 .pid_filter_ctrl = lme2510_pid_filter_ctrl,
1165 .frontend_attach = dm04_lme2510_frontend_attach,
1166 .tuner_attach = dm04_lme2510_tuner,
1167 /* parameter for the MPEG2-data transfer */
1183 .protocol = RC_TYPE_NEC,
1184 .module_name = "LME2510 Remote Control",
1185 .allowed_protos = RC_TYPE_NEC,
1186 .rc_codes = RC_MAP_LME2510,
1188 .power_ctrl = lme2510_powerup,
1189 .identify_state = lme2510_identify_state,
1190 .i2c_algo = &lme2510_i2c_algo,
1191 .generic_bulk_ctrl_endpoint = 0,
1192 .num_device_descs = 1,
1194 { "DM04_LME2510_DVB-S",
1195 { &lme2510_table[0], NULL },
1201 static struct dvb_usb_device_properties lme2510c_properties = {
1202 .caps = DVB_USB_IS_AN_I2C_ADAPTER,
1203 .size_of_priv = sizeof(struct lme2510_state),
1209 .caps = DVB_USB_ADAP_HAS_PID_FILTER|
1210 DVB_USB_ADAP_NEED_PID_FILTERING|
1211 DVB_USB_ADAP_PID_FILTER_CAN_BE_TURNED_OFF,
1212 .streaming_ctrl = lme2510_streaming_ctrl,
1213 .pid_filter_count = 15,
1214 .pid_filter = lme2510_pid_filter,
1215 .pid_filter_ctrl = lme2510_pid_filter_ctrl,
1216 .frontend_attach = dm04_lme2510_frontend_attach,
1217 .tuner_attach = dm04_lme2510_tuner,
1218 /* parameter for the MPEG2-data transfer */
1234 .protocol = RC_TYPE_NEC,
1235 .module_name = "LME2510 Remote Control",
1236 .allowed_protos = RC_TYPE_NEC,
1237 .rc_codes = RC_MAP_LME2510,
1239 .power_ctrl = lme2510_powerup,
1240 .identify_state = lme2510_identify_state,
1241 .i2c_algo = &lme2510_i2c_algo,
1242 .generic_bulk_ctrl_endpoint = 0,
1243 .num_device_descs = 1,
1245 { "DM04_LME2510C_DVB-S",
1246 { &lme2510_table[1], NULL },
1251 static void *lme2510_exit_int(struct dvb_usb_device *d)
1253 struct lme2510_state *st = d->priv;
1254 struct dvb_usb_adapter *adap = &d->adapter[0];
1255 void *buffer = NULL;
1258 lme2510_kill_urb(&adap->fe_adap[0].stream);
1259 adap->feedcount = 0;
1262 if (st->usb_buffer != NULL) {
1263 st->i2c_talk_onoff = 1;
1264 st->signal_lock = 0;
1265 st->signal_level = 0;
1267 buffer = st->usb_buffer;
1270 if (st->lme_urb != NULL) {
1271 usb_kill_urb(st->lme_urb);
1272 usb_free_coherent(d->udev, 128, st->buffer,
1273 st->lme_urb->transfer_dma);
1274 info("Interrupt Service Stopped");
1280 static void lme2510_exit(struct usb_interface *intf)
1282 struct dvb_usb_device *d = usb_get_intfdata(intf);
1286 usb_buffer = lme2510_exit_int(d);
1287 dvb_usb_device_exit(intf);
1288 if (usb_buffer != NULL)
1293 static struct usb_driver lme2510_driver = {
1294 .name = "LME2510C_DVB-S",
1295 .probe = lme2510_probe,
1296 .disconnect = lme2510_exit,
1297 .id_table = lme2510_table,
1301 static int __init lme2510_module_init(void)
1303 int result = usb_register(&lme2510_driver);
1305 err("usb_register failed. Error number %d", result);
1312 static void __exit lme2510_module_exit(void)
1314 /* deregister this driver from the USB subsystem */
1315 usb_deregister(&lme2510_driver);
1318 module_init(lme2510_module_init);
1319 module_exit(lme2510_module_exit);
1321 MODULE_AUTHOR("Malcolm Priestley <tvboxspy@gmail.com>");
1322 MODULE_DESCRIPTION("LME2510(C) DVB-S USB2.0");
1323 MODULE_VERSION("1.90");
1324 MODULE_LICENSE("GPL");