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(512, 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 512 */
179 memcpy(buff, wbuf, (wlen > 512) ? 512 : wlen);
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 > 512) ?
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 lme2510_state *lme_int = adap->dev->priv;
331 lme_int->lme_urb = usb_alloc_urb(0, GFP_ATOMIC);
333 if (lme_int->lme_urb == NULL)
336 lme_int->buffer = usb_alloc_coherent(adap->dev->udev, 5000, GFP_ATOMIC,
337 &lme_int->lme_urb->transfer_dma);
339 if (lme_int->buffer == NULL)
342 usb_fill_int_urb(lme_int->lme_urb,
344 usb_rcvintpipe(adap->dev->udev, 0xa),
347 lme2510_int_response,
351 lme_int->lme_urb->transfer_flags |= URB_NO_TRANSFER_DMA_MAP;
353 usb_submit_urb(lme_int->lme_urb, GFP_ATOMIC);
354 info("INT Interrupt Service Started");
359 static int lme2510_pid_filter_ctrl(struct dvb_usb_adapter *adap, int onoff)
361 struct lme2510_state *st = adap->dev->priv;
362 static u8 clear_pid_reg[] = LME_CLEAR_PID;
366 deb_info(1, "PID Clearing Filter");
368 ret = mutex_lock_interruptible(&adap->dev->i2c_mutex);
373 ret |= lme2510_usb_talk(adap->dev, clear_pid_reg,
374 sizeof(clear_pid_reg), rbuf, sizeof(rbuf));
378 mutex_unlock(&adap->dev->i2c_mutex);
383 static int lme2510_pid_filter(struct dvb_usb_adapter *adap, int index, u16 pid,
388 deb_info(3, "%s PID=%04x Index=%04x onoff=%02x", __func__,
393 ret = mutex_lock_interruptible(&adap->dev->i2c_mutex);
396 ret |= lme2510_enable_pid(adap->dev, index, pid);
397 mutex_unlock(&adap->dev->i2c_mutex);
405 static int lme2510_return_status(struct usb_device *dev)
410 data = kzalloc(10, GFP_KERNEL);
414 ret |= usb_control_msg(dev, usb_rcvctrlpipe(dev, 0),
415 0x06, 0x80, 0x0302, 0x00, data, 0x0006, 200);
416 info("Firmware Status: %x (%x)", ret , data[2]);
418 ret = (ret < 0) ? -ENODEV : data[2];
423 static int lme2510_msg(struct dvb_usb_device *d,
424 u8 *wbuf, int wlen, u8 *rbuf, int rlen)
427 struct lme2510_state *st = d->priv;
429 if (mutex_lock_interruptible(&d->i2c_mutex) < 0)
432 if (st->i2c_talk_onoff == 1) {
434 ret = lme2510_usb_talk(d, wbuf, wlen, rbuf, rlen);
436 switch (st->tuner_config) {
438 if (wbuf[2] == 0x1c) {
439 if (wbuf[3] == 0x0e) {
440 st->signal_lock = rbuf[1];
441 if ((st->stream_on & 1) &&
442 (st->signal_lock & 0x10)) {
443 lme2510_stream_restart(d);
444 st->i2c_talk_onoff = 0;
451 if (wbuf[2] == 0xd0) {
452 if (wbuf[3] == 0x24) {
453 st->signal_lock = rbuf[1];
454 if ((st->stream_on & 1) &&
455 (st->signal_lock & 0x8)) {
456 lme2510_stream_restart(d);
457 st->i2c_talk_onoff = 0;
460 if ((wbuf[3] != 0x6) & (wbuf[3] != 0x5))
465 if (wbuf[2] == 0xd0) {
466 if (wbuf[3] == 0x1b) {
467 st->signal_lock = rbuf[1];
468 if ((st->stream_on & 1) &&
469 (st->signal_lock & 0x8)) {
470 lme2510_stream_restart(d);
471 st->i2c_talk_onoff = 0;
480 switch (st->tuner_config) {
485 rbuf[1] = st->signal_lock;
489 rbuf[1] = st->signal_level;
493 rbuf[1] = st->signal_sn;
503 lme2510_usb_talk(d, wbuf, wlen, rbuf, rlen);
504 st->i2c_talk_onoff = 1;
512 rbuf[1] = (st->signal_level & 0x80)
513 ? 0 : (st->signal_level * 2);
517 rbuf[1] = st->signal_sn;
521 rbuf[1] = st->signal_lock;
530 lme2510_usb_talk(d, wbuf, wlen, rbuf, rlen);
531 st->i2c_talk_onoff = 1;
539 rbuf[1] = (st->signal_level & 0x80)
540 ? 0 : (st->signal_level * 2);
544 rbuf[1] = st->signal_sn;
548 rbuf[1] = st->signal_lock;
558 lme2510_usb_talk(d, wbuf, wlen, rbuf, rlen);
559 st->i2c_talk_onoff = 1;
567 deb_info(4, "I2C From Interrupt Message out(%02x) in(%02x)",
572 mutex_unlock(&d->i2c_mutex);
578 static int lme2510_i2c_xfer(struct i2c_adapter *adap, struct i2c_msg msg[],
581 struct dvb_usb_device *d = i2c_get_adapdata(adap);
582 struct lme2510_state *st = d->priv;
583 static u8 obuf[64], ibuf[512];
586 u8 gate = st->i2c_gate;
592 warn("more than 2 i2c messages"
593 "at a time is not handled yet. TODO.");
595 for (i = 0; i < num; i++) {
596 read_o = 1 & (msg[i].flags & I2C_M_RD);
597 read = i+1 < num && (msg[i+1].flags & I2C_M_RD);
599 gate = (msg[i].addr == st->i2c_tuner_addr)
600 ? (read) ? st->i2c_tuner_gate_r
601 : st->i2c_tuner_gate_w
603 obuf[0] = gate | (read << 7);
606 obuf[1] = (read) ? 2 : msg[i].len + 1;
608 obuf[1] = msg[i].len + read + 1;
610 obuf[2] = msg[i].addr;
615 memcpy(&obuf[3], msg[i].buf, msg[i].len);
616 obuf[msg[i].len+3] = msg[i+1].len;
620 memcpy(&obuf[3], msg[i].buf, msg[i].len);
624 if (lme2510_msg(d, obuf, len, ibuf, 512) < 0) {
625 deb_info(1, "i2c transfer failed.");
631 memcpy(msg[i].buf, &ibuf[1], msg[i].len);
633 memcpy(msg[i+1].buf, &ibuf[1], msg[i+1].len);
641 static u32 lme2510_i2c_func(struct i2c_adapter *adapter)
646 static struct i2c_algorithm lme2510_i2c_algo = {
647 .master_xfer = lme2510_i2c_xfer,
648 .functionality = lme2510_i2c_func,
651 /* Callbacks for DVB USB */
652 static int lme2510_identify_state(struct usb_device *udev,
653 struct dvb_usb_device_properties *props,
654 struct dvb_usb_device_description **desc,
661 static int lme2510_streaming_ctrl(struct dvb_usb_adapter *adap, int onoff)
663 struct lme2510_state *st = adap->dev->priv;
664 static u8 clear_reg_3[] = LME_CLEAR_PID;
666 int ret = 0, rlen = sizeof(rbuf);
668 deb_info(1, "STM (%02x)", onoff);
670 /* Streaming is started by FE_HAS_LOCK */
674 deb_info(1, "STM Steam Off");
675 /* mutex is here only to avoid collision with I2C */
676 if (mutex_lock_interruptible(&adap->dev->i2c_mutex) < 0)
679 ret = lme2510_usb_talk(adap->dev, clear_reg_3,
680 sizeof(clear_reg_3), rbuf, rlen);
682 st->i2c_talk_onoff = 1;
684 mutex_unlock(&adap->dev->i2c_mutex);
687 return (ret < 0) ? -ENODEV : 0;
690 static u8 check_sum(u8 *p, u8 len)
698 static int lme2510_download_firmware(struct usb_device *dev,
699 const struct firmware *fw)
703 u16 j, wlen, len_in, start, end;
704 u8 packet_size, dlen, i;
710 data = kzalloc(512, GFP_KERNEL);
712 info("FRM Could not start Firmware Download (Buffer allocation failed)");
716 info("FRM Starting Firmware Download");
718 for (i = 1; i < 3; i++) {
719 start = (i == 1) ? 0 : 512;
720 end = (i == 1) ? 512 : fw->size;
721 for (j = start; j < end; j += (packet_size+1)) {
722 fw_data = (u8 *)(fw->data + j);
723 if ((end - j) > packet_size) {
728 dlen = (u8)(end - j)-1;
731 memcpy(&data[2], fw_data, dlen+1);
732 wlen = (u8) dlen + 4;
733 data[wlen-1] = check_sum(fw_data, dlen+1);
734 deb_info(1, "Data S=%02x:E=%02x CS= %02x", data[3],
735 data[dlen+2], data[dlen+3]);
736 ret |= lme2510_bulk_write(dev, data, wlen, 1);
737 ret |= lme2510_bulk_read(dev, data, len_in , 1);
738 ret |= (data[0] == 0x88) ? 0 : -1;
742 usb_control_msg(dev, usb_rcvctrlpipe(dev, 0),
743 0x06, 0x80, 0x0200, 0x00, data, 0x0109, 1000);
749 ret |= lme2510_bulk_write(dev, data , len_in, 1); /*Resetting*/
750 ret |= lme2510_bulk_read(dev, data, len_in, 1);
754 info("FRM Firmware Download Failed (%04x)" , ret);
756 info("FRM Firmware Download Completed - Resetting Device");
759 return (ret < 0) ? -ENODEV : 0;
762 static void lme_coldreset(struct usb_device *dev)
769 info("FRM Firmware Cold Reset");
770 ret |= lme2510_bulk_write(dev, data , len_in, 1); /*Cold Resetting*/
771 ret |= lme2510_bulk_read(dev, data, len_in, 1);
776 static int lme_firmware_switch(struct usb_device *udev, int cold)
778 const struct firmware *fw = NULL;
779 const char fw_c_s7395[] = "dvb-usb-lme2510c-s7395.fw";
780 const char fw_c_lg[] = "dvb-usb-lme2510c-lg.fw";
781 const char fw_c_s0194[] = "dvb-usb-lme2510c-s0194.fw";
782 const char fw_lg[] = "dvb-usb-lme2510-lg.fw";
783 const char fw_s0194[] = "dvb-usb-lme2510-s0194.fw";
787 cold = (cold > 0) ? (cold & 1) : 0;
791 if (le16_to_cpu(udev->descriptor.idProduct) == 0x1122) {
792 switch (dvb_usb_lme2510_firmware) {
794 dvb_usb_lme2510_firmware = TUNER_S0194;
797 ret = request_firmware(&fw, fw_lme, &udev->dev);
802 dvb_usb_lme2510_firmware = TUNER_LG;
805 ret = request_firmware(&fw, fw_lme, &udev->dev);
808 info("FRM No Firmware Found - please install");
809 dvb_usb_lme2510_firmware = TUNER_DEFAULT;
815 switch (dvb_usb_lme2510_firmware) {
817 dvb_usb_lme2510_firmware = TUNER_S7395;
820 ret = request_firmware(&fw, fw_lme, &udev->dev);
825 dvb_usb_lme2510_firmware = TUNER_LG;
828 ret = request_firmware(&fw, fw_lme, &udev->dev);
831 dvb_usb_lme2510_firmware = TUNER_S0194;
834 ret = request_firmware(&fw, fw_lme, &udev->dev);
837 info("FRM No Firmware Found - please install");
838 dvb_usb_lme2510_firmware = TUNER_DEFAULT;
846 info("FRM Loading %s file", fw_lme);
847 ret = lme2510_download_firmware(udev, fw);
850 release_firmware(fw);
853 info("FRM Changing to %s firmware", fw_lme);
861 static int lme2510_kill_urb(struct usb_data_stream *stream)
865 for (i = 0; i < stream->urbs_submitted; i++) {
866 deb_info(3, "killing URB no. %d.", i);
868 usb_kill_urb(stream->urb_list[i]);
870 stream->urbs_submitted = 0;
875 static struct tda10086_config tda10086_config = {
876 .demod_address = 0x1c,
879 .xtal_freq = TDA10086_XTAL_16M,
882 static struct stv0288_config lme_config = {
883 .demod_address = 0xd0,
885 .inittab = s7395_inittab,
888 static struct ix2505v_config lme_tuner = {
889 .tuner_address = 0xc0,
892 .tuner_chargepump = 0x3,
895 static struct stv0299_config sharp_z0194_config = {
896 .demod_address = 0xd0,
897 .inittab = sharp_z0194a_inittab,
901 .lock_output = STV0299_LOCKOUTPUT_1,
902 .volt13_op0_op1 = STV0299_VOLT13_OP1,
904 .set_symbol_rate = sharp_z0194a_set_symbol_rate,
907 static int dm04_lme2510_set_voltage(struct dvb_frontend *fe,
908 fe_sec_voltage_t voltage)
910 struct dvb_usb_adapter *adap = fe->dvb->priv;
911 static u8 voltage_low[] = LME_VOLTAGE_L;
912 static u8 voltage_high[] = LME_VOLTAGE_H;
914 int ret = 0, len = 3, rlen = 1;
916 if (mutex_lock_interruptible(&adap->dev->i2c_mutex) < 0)
921 ret |= lme2510_usb_talk(adap->dev,
922 voltage_high, len, rbuf, rlen);
925 case SEC_VOLTAGE_OFF:
928 ret |= lme2510_usb_talk(adap->dev,
929 voltage_low, len, rbuf, rlen);
933 mutex_unlock(&adap->dev->i2c_mutex);
935 return (ret < 0) ? -ENODEV : 0;
938 static int lme_name(struct dvb_usb_adapter *adap)
940 struct lme2510_state *st = adap->dev->priv;
941 const char *desc = adap->dev->desc->name;
942 char *fe_name[] = {"", " LG TDQY-P001F", " SHARP:BS2F7HZ7395",
943 " SHARP:BS2F7HZ0194"};
944 char *name = adap->fe->ops.info.name;
946 strlcpy(name, desc, 128);
947 strlcat(name, fe_name[st->tuner_config], 128);
952 static int dm04_lme2510_frontend_attach(struct dvb_usb_adapter *adap)
954 struct lme2510_state *st = adap->dev->priv;
958 st->i2c_talk_onoff = 1;
961 adap->fe = dvb_attach(tda10086_attach, &tda10086_config,
962 &adap->dev->i2c_adap);
965 info("TUN Found Frontend TDA10086");
966 st->i2c_tuner_gate_w = 4;
967 st->i2c_tuner_gate_r = 4;
968 st->i2c_tuner_addr = 0xc0;
969 st->tuner_config = TUNER_LG;
970 if (dvb_usb_lme2510_firmware != TUNER_LG) {
971 dvb_usb_lme2510_firmware = TUNER_LG;
972 ret = lme_firmware_switch(adap->dev->udev, 1);
978 adap->fe = dvb_attach(stv0299_attach, &sharp_z0194_config,
979 &adap->dev->i2c_adap);
981 info("FE Found Stv0299");
982 st->i2c_tuner_gate_w = 4;
983 st->i2c_tuner_gate_r = 5;
984 st->i2c_tuner_addr = 0xc0;
985 st->tuner_config = TUNER_S0194;
986 if (dvb_usb_lme2510_firmware != TUNER_S0194) {
987 dvb_usb_lme2510_firmware = TUNER_S0194;
988 ret = lme_firmware_switch(adap->dev->udev, 1);
994 adap->fe = dvb_attach(stv0288_attach, &lme_config,
995 &adap->dev->i2c_adap);
997 info("FE Found Stv0288");
998 st->i2c_tuner_gate_w = 4;
999 st->i2c_tuner_gate_r = 5;
1000 st->i2c_tuner_addr = 0xc0;
1001 st->tuner_config = TUNER_S7395;
1002 if (dvb_usb_lme2510_firmware != TUNER_S7395) {
1003 dvb_usb_lme2510_firmware = TUNER_S7395;
1004 ret = lme_firmware_switch(adap->dev->udev, 1);
1007 info("DM04 Not Supported");
1014 dvb_frontend_detach(adap->fe);
1017 adap->dev->props.rc.core.rc_codes = NULL;
1021 adap->fe->ops.set_voltage = dm04_lme2510_set_voltage;
1022 ret = lme_name(adap);
1026 static int dm04_lme2510_tuner(struct dvb_usb_adapter *adap)
1028 struct lme2510_state *st = adap->dev->priv;
1029 char *tun_msg[] = {"", "TDA8263", "IX2505V", "DVB_PLL_OPERA"};
1032 switch (st->tuner_config) {
1034 if (dvb_attach(tda826x_attach, adap->fe, 0xc0,
1035 &adap->dev->i2c_adap, 1))
1036 ret = st->tuner_config;
1039 if (dvb_attach(ix2505v_attach , adap->fe, &lme_tuner,
1040 &adap->dev->i2c_adap))
1041 ret = st->tuner_config;
1044 if (dvb_attach(dvb_pll_attach , adap->fe, 0xc0,
1045 &adap->dev->i2c_adap, DVB_PLL_OPERA1))
1046 ret = st->tuner_config;
1053 info("TUN Found %s tuner", tun_msg[ret]);
1055 info("TUN No tuner found --- reseting device");
1056 lme_coldreset(adap->dev->udev);
1060 /* Start the Interrupt*/
1061 ret = lme2510_int_read(adap);
1063 info("INT Unable to start Interrupt Service");
1070 static int lme2510_powerup(struct dvb_usb_device *d, int onoff)
1072 struct lme2510_state *st = d->priv;
1073 static u8 lnb_on[] = LNB_ON;
1074 static u8 lnb_off[] = LNB_OFF;
1076 int ret, len = 3, rlen = 1;
1078 if (mutex_lock_interruptible(&d->i2c_mutex) < 0)
1082 ret = lme2510_usb_talk(d, lnb_on, len, rbuf, rlen);
1084 ret = lme2510_usb_talk(d, lnb_off, len, rbuf, rlen);
1086 st->i2c_talk_onoff = 1;
1088 mutex_unlock(&d->i2c_mutex);
1093 /* DVB USB Driver stuff */
1094 static struct dvb_usb_device_properties lme2510_properties;
1095 static struct dvb_usb_device_properties lme2510c_properties;
1097 static int lme2510_probe(struct usb_interface *intf,
1098 const struct usb_device_id *id)
1100 struct usb_device *udev = interface_to_usbdev(intf);
1103 usb_reset_configuration(udev);
1105 usb_set_interface(udev, intf->cur_altsetting->desc.bInterfaceNumber, 1);
1107 if (udev->speed != USB_SPEED_HIGH) {
1108 ret = usb_reset_device(udev);
1109 info("DEV Failed to connect in HIGH SPEED mode");
1113 if (lme2510_return_status(udev) == 0x44) {
1114 lme_firmware_switch(udev, 0);
1118 if (0 == dvb_usb_device_init(intf, &lme2510_properties,
1119 THIS_MODULE, NULL, adapter_nr)) {
1120 info("DEV registering device driver");
1123 if (0 == dvb_usb_device_init(intf, &lme2510c_properties,
1124 THIS_MODULE, NULL, adapter_nr)) {
1125 info("DEV registering device driver");
1129 info("DEV lme2510 Error");
1134 static struct usb_device_id lme2510_table[] = {
1135 { USB_DEVICE(0x3344, 0x1122) }, /* LME2510 */
1136 { USB_DEVICE(0x3344, 0x1120) }, /* LME2510C */
1137 {} /* Terminating entry */
1140 MODULE_DEVICE_TABLE(usb, lme2510_table);
1142 static struct dvb_usb_device_properties lme2510_properties = {
1143 .caps = DVB_USB_IS_AN_I2C_ADAPTER,
1144 .size_of_priv = sizeof(struct lme2510_state),
1148 .caps = DVB_USB_ADAP_HAS_PID_FILTER|
1149 DVB_USB_ADAP_NEED_PID_FILTERING|
1150 DVB_USB_ADAP_PID_FILTER_CAN_BE_TURNED_OFF,
1151 .streaming_ctrl = lme2510_streaming_ctrl,
1152 .pid_filter_count = 15,
1153 .pid_filter = lme2510_pid_filter,
1154 .pid_filter_ctrl = lme2510_pid_filter_ctrl,
1155 .frontend_attach = dm04_lme2510_frontend_attach,
1156 .tuner_attach = dm04_lme2510_tuner,
1157 /* parameter for the MPEG2-data transfer */
1172 .protocol = RC_TYPE_NEC,
1173 .module_name = "LME2510 Remote Control",
1174 .allowed_protos = RC_TYPE_NEC,
1175 .rc_codes = RC_MAP_LME2510,
1177 .power_ctrl = lme2510_powerup,
1178 .identify_state = lme2510_identify_state,
1179 .i2c_algo = &lme2510_i2c_algo,
1180 .generic_bulk_ctrl_endpoint = 0,
1181 .num_device_descs = 1,
1183 { "DM04_LME2510_DVB-S",
1184 { &lme2510_table[0], NULL },
1190 static struct dvb_usb_device_properties lme2510c_properties = {
1191 .caps = DVB_USB_IS_AN_I2C_ADAPTER,
1192 .size_of_priv = sizeof(struct lme2510_state),
1196 .caps = DVB_USB_ADAP_HAS_PID_FILTER|
1197 DVB_USB_ADAP_NEED_PID_FILTERING|
1198 DVB_USB_ADAP_PID_FILTER_CAN_BE_TURNED_OFF,
1199 .streaming_ctrl = lme2510_streaming_ctrl,
1200 .pid_filter_count = 15,
1201 .pid_filter = lme2510_pid_filter,
1202 .pid_filter_ctrl = lme2510_pid_filter_ctrl,
1203 .frontend_attach = dm04_lme2510_frontend_attach,
1204 .tuner_attach = dm04_lme2510_tuner,
1205 /* parameter for the MPEG2-data transfer */
1220 .protocol = RC_TYPE_NEC,
1221 .module_name = "LME2510 Remote Control",
1222 .allowed_protos = RC_TYPE_NEC,
1223 .rc_codes = RC_MAP_LME2510,
1225 .power_ctrl = lme2510_powerup,
1226 .identify_state = lme2510_identify_state,
1227 .i2c_algo = &lme2510_i2c_algo,
1228 .generic_bulk_ctrl_endpoint = 0,
1229 .num_device_descs = 1,
1231 { "DM04_LME2510C_DVB-S",
1232 { &lme2510_table[1], NULL },
1237 static void *lme2510_exit_int(struct dvb_usb_device *d)
1239 struct lme2510_state *st = d->priv;
1240 struct dvb_usb_adapter *adap = &d->adapter[0];
1241 void *buffer = NULL;
1244 lme2510_kill_urb(&adap->stream);
1245 adap->feedcount = 0;
1248 if (st->usb_buffer != NULL) {
1249 st->i2c_talk_onoff = 1;
1250 st->signal_lock = 0;
1251 st->signal_level = 0;
1253 buffer = st->usb_buffer;
1256 if (st->lme_urb != NULL) {
1257 usb_kill_urb(st->lme_urb);
1258 usb_free_coherent(d->udev, 5000, st->buffer,
1259 st->lme_urb->transfer_dma);
1260 info("Interrupt Service Stopped");
1266 static void lme2510_exit(struct usb_interface *intf)
1268 struct dvb_usb_device *d = usb_get_intfdata(intf);
1272 usb_buffer = lme2510_exit_int(d);
1273 dvb_usb_device_exit(intf);
1274 if (usb_buffer != NULL)
1279 static struct usb_driver lme2510_driver = {
1280 .name = "LME2510C_DVB-S",
1281 .probe = lme2510_probe,
1282 .disconnect = lme2510_exit,
1283 .id_table = lme2510_table,
1287 static int __init lme2510_module_init(void)
1289 int result = usb_register(&lme2510_driver);
1291 err("usb_register failed. Error number %d", result);
1298 static void __exit lme2510_module_exit(void)
1300 /* deregister this driver from the USB subsystem */
1301 usb_deregister(&lme2510_driver);
1304 module_init(lme2510_module_init);
1305 module_exit(lme2510_module_exit);
1307 MODULE_AUTHOR("Malcolm Priestley <tvboxspy@gmail.com>");
1308 MODULE_DESCRIPTION("LME2510(C) DVB-S USB2.0");
1309 MODULE_VERSION("1.88");
1310 MODULE_LICENSE("GPL");