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));
210 static int lme2510_remote_keypress(struct dvb_usb_adapter *adap, u32 keypress)
212 struct dvb_usb_device *d = adap->dev;
214 deb_info(1, "INT Key Keypress =%04x", keypress);
217 rc_keydown(d->rc_dev, keypress, 0);
222 static int lme2510_enable_pid(struct dvb_usb_device *d, u8 index, u16 pid_out)
224 struct lme2510_state *st = d->priv;
225 static u8 pid_buff[] = LME_ZERO_PID;
227 u8 pid_no = index * 2;
228 u8 pid_len = pid_no + 2;
230 deb_info(1, "PID Setting Pid %04x", pid_out);
232 if (st->pid_size == 0)
233 ret |= lme2510_stream_restart(d);
235 pid_buff[2] = pid_no;
236 pid_buff[3] = (u8)pid_out & 0xff;
237 pid_buff[4] = pid_no + 1;
238 pid_buff[5] = (u8)(pid_out >> 8);
240 if (pid_len > st->pid_size)
241 st->pid_size = pid_len;
242 pid_buff[7] = 0x80 + st->pid_size;
244 ret |= lme2510_usb_talk(d, pid_buff ,
245 sizeof(pid_buff) , rbuf, sizeof(rbuf));
248 ret |= lme2510_stream_restart(d);
253 static void lme2510_int_response(struct urb *lme_urb)
255 struct dvb_usb_adapter *adap = lme_urb->context;
256 struct lme2510_state *st = adap->dev->priv;
257 static u8 *ibuf, *rbuf;
260 switch (lme_urb->status) {
269 info("Error %x", lme_urb->status);
273 rbuf = (u8 *) lme_urb->transfer_buffer;
275 offset = ((lme_urb->actual_length/8) > 4)
276 ? 4 : (lme_urb->actual_length/8) ;
278 for (i = 0; i < offset; ++i) {
279 ibuf = (u8 *)&rbuf[i*8];
280 deb_info(5, "INT O/S C =%02x C/O=%02x Type =%02x%02x",
281 offset, i, ibuf[0], ibuf[1]);
285 debug_data_snipet(1, "INT Remote data snipet in", ibuf);
286 lme2510_remote_keypress(adap,
287 (u32)(ibuf[2] << 24) + (ibuf[3] << 16) +
288 (ibuf[4] << 8) + ibuf[5]);
291 switch (st->tuner_config) {
294 st->signal_lock = ibuf[2];
295 st->signal_level = ibuf[4];
296 st->signal_sn = ibuf[3];
297 st->time_key = ibuf[7];
301 /* Tweak for earlier firmware*/
302 if (ibuf[1] == 0x03) {
304 st->signal_lock = ibuf[2];
305 st->signal_level = ibuf[3];
306 st->signal_sn = ibuf[4];
308 st->signal_level = ibuf[4];
309 st->signal_sn = ibuf[5];
311 (st->signal_lock & 0xf7) +
312 ((ibuf[2] & 0x01) << 0x03);
318 debug_data_snipet(5, "INT Remote data snipet in", ibuf);
321 debug_data_snipet(1, "INT Control data snipet", ibuf);
324 debug_data_snipet(1, "INT Unknown data snipet", ibuf);
328 usb_submit_urb(lme_urb, GFP_ATOMIC);
331 static int lme2510_int_read(struct dvb_usb_adapter *adap)
333 struct lme2510_state *lme_int = adap->dev->priv;
335 lme_int->lme_urb = usb_alloc_urb(0, GFP_ATOMIC);
337 if (lme_int->lme_urb == NULL)
340 lme_int->buffer = usb_alloc_coherent(adap->dev->udev, 5000, GFP_ATOMIC,
341 &lme_int->lme_urb->transfer_dma);
343 if (lme_int->buffer == NULL)
346 usb_fill_int_urb(lme_int->lme_urb,
348 usb_rcvintpipe(adap->dev->udev, 0xa),
351 lme2510_int_response,
355 lme_int->lme_urb->transfer_flags |= URB_NO_TRANSFER_DMA_MAP;
357 usb_submit_urb(lme_int->lme_urb, GFP_ATOMIC);
358 info("INT Interrupt Service Started");
363 static int lme2510_pid_filter_ctrl(struct dvb_usb_adapter *adap, int onoff)
365 struct lme2510_state *st = adap->dev->priv;
366 static u8 clear_pid_reg[] = LME_CLEAR_PID;
370 deb_info(1, "PID Clearing Filter");
372 ret = mutex_lock_interruptible(&adap->dev->i2c_mutex);
377 ret |= lme2510_usb_talk(adap->dev, clear_pid_reg,
378 sizeof(clear_pid_reg), rbuf, sizeof(rbuf));
382 mutex_unlock(&adap->dev->i2c_mutex);
387 static int lme2510_pid_filter(struct dvb_usb_adapter *adap, int index, u16 pid,
392 deb_info(3, "%s PID=%04x Index=%04x onoff=%02x", __func__,
397 ret = mutex_lock_interruptible(&adap->dev->i2c_mutex);
400 ret |= lme2510_enable_pid(adap->dev, index, pid);
401 mutex_unlock(&adap->dev->i2c_mutex);
409 static int lme2510_return_status(struct usb_device *dev)
414 data = kzalloc(10, GFP_KERNEL);
418 ret |= usb_control_msg(dev, usb_rcvctrlpipe(dev, 0),
419 0x06, 0x80, 0x0302, 0x00, data, 0x0006, 200);
420 info("Firmware Status: %x (%x)", ret , data[2]);
422 ret = (ret < 0) ? -ENODEV : data[2];
427 static int lme2510_msg(struct dvb_usb_device *d,
428 u8 *wbuf, int wlen, u8 *rbuf, int rlen)
431 struct lme2510_state *st = d->priv;
433 if (mutex_lock_interruptible(&d->i2c_mutex) < 0)
436 if (st->i2c_talk_onoff == 1) {
438 ret = lme2510_usb_talk(d, wbuf, wlen, rbuf, rlen);
440 switch (st->tuner_config) {
442 if (wbuf[2] == 0x1c) {
443 if (wbuf[3] == 0x0e) {
444 st->signal_lock = rbuf[1];
445 if ((st->stream_on & 1) &&
446 (st->signal_lock & 0x10)) {
447 lme2510_stream_restart(d);
448 st->i2c_talk_onoff = 0;
455 if (wbuf[2] == 0xd0) {
456 if (wbuf[3] == 0x24) {
457 st->signal_lock = rbuf[1];
458 if ((st->stream_on & 1) &&
459 (st->signal_lock & 0x8)) {
460 lme2510_stream_restart(d);
461 st->i2c_talk_onoff = 0;
464 if ((wbuf[3] != 0x6) & (wbuf[3] != 0x5))
469 if (wbuf[2] == 0xd0) {
470 if (wbuf[3] == 0x1b) {
471 st->signal_lock = rbuf[1];
472 if ((st->stream_on & 1) &&
473 (st->signal_lock & 0x8)) {
474 lme2510_stream_restart(d);
475 st->i2c_talk_onoff = 0;
484 switch (st->tuner_config) {
489 rbuf[1] = st->signal_lock;
493 rbuf[1] = st->signal_level;
497 rbuf[1] = st->signal_sn;
507 lme2510_usb_talk(d, wbuf, wlen, rbuf, rlen);
508 st->i2c_talk_onoff = 1;
516 rbuf[1] = (st->signal_level & 0x80)
517 ? 0 : (st->signal_level * 2);
521 rbuf[1] = st->signal_sn;
525 rbuf[1] = st->signal_lock;
534 lme2510_usb_talk(d, wbuf, wlen, rbuf, rlen);
535 st->i2c_talk_onoff = 1;
543 rbuf[1] = (st->signal_level & 0x80)
544 ? 0 : (st->signal_level * 2);
548 rbuf[1] = st->signal_sn;
552 rbuf[1] = st->signal_lock;
562 lme2510_usb_talk(d, wbuf, wlen, rbuf, rlen);
563 st->i2c_talk_onoff = 1;
571 deb_info(4, "I2C From Interrupt Message out(%02x) in(%02x)",
576 mutex_unlock(&d->i2c_mutex);
582 static int lme2510_i2c_xfer(struct i2c_adapter *adap, struct i2c_msg msg[],
585 struct dvb_usb_device *d = i2c_get_adapdata(adap);
586 struct lme2510_state *st = d->priv;
587 static u8 obuf[64], ibuf[512];
590 u8 gate = st->i2c_gate;
596 warn("more than 2 i2c messages"
597 "at a time is not handled yet. TODO.");
599 for (i = 0; i < num; i++) {
600 read_o = 1 & (msg[i].flags & I2C_M_RD);
601 read = i+1 < num && (msg[i+1].flags & I2C_M_RD);
603 gate = (msg[i].addr == st->i2c_tuner_addr)
604 ? (read) ? st->i2c_tuner_gate_r
605 : st->i2c_tuner_gate_w
607 obuf[0] = gate | (read << 7);
610 obuf[1] = (read) ? 2 : msg[i].len + 1;
612 obuf[1] = msg[i].len + read + 1;
614 obuf[2] = msg[i].addr;
619 memcpy(&obuf[3], msg[i].buf, msg[i].len);
620 obuf[msg[i].len+3] = msg[i+1].len;
624 memcpy(&obuf[3], msg[i].buf, msg[i].len);
628 if (lme2510_msg(d, obuf, len, ibuf, 512) < 0) {
629 deb_info(1, "i2c transfer failed.");
635 memcpy(msg[i].buf, &ibuf[1], msg[i].len);
637 memcpy(msg[i+1].buf, &ibuf[1], msg[i+1].len);
645 static u32 lme2510_i2c_func(struct i2c_adapter *adapter)
650 static struct i2c_algorithm lme2510_i2c_algo = {
651 .master_xfer = lme2510_i2c_xfer,
652 .functionality = lme2510_i2c_func,
655 /* Callbacks for DVB USB */
656 static int lme2510_identify_state(struct usb_device *udev,
657 struct dvb_usb_device_properties *props,
658 struct dvb_usb_device_description **desc,
665 static int lme2510_streaming_ctrl(struct dvb_usb_adapter *adap, int onoff)
667 struct lme2510_state *st = adap->dev->priv;
668 static u8 clear_reg_3[] = LME_CLEAR_PID;
670 int ret = 0, rlen = sizeof(rbuf);
672 deb_info(1, "STM (%02x)", onoff);
674 /* Streaming is started by FE_HAS_LOCK */
678 deb_info(1, "STM Steam Off");
679 /* mutex is here only to avoid collision with I2C */
680 if (mutex_lock_interruptible(&adap->dev->i2c_mutex) < 0)
683 ret = lme2510_usb_talk(adap->dev, clear_reg_3,
684 sizeof(clear_reg_3), rbuf, rlen);
686 st->i2c_talk_onoff = 1;
688 mutex_unlock(&adap->dev->i2c_mutex);
691 return (ret < 0) ? -ENODEV : 0;
694 static int lme2510_int_service(struct dvb_usb_adapter *adap)
696 struct dvb_usb_device *d = adap->dev;
700 info("STA Configuring Remote");
702 rc = rc_allocate_device();
706 usb_make_path(d->udev, d->rc_phys, sizeof(d->rc_phys));
707 strlcat(d->rc_phys, "/ir0", sizeof(d->rc_phys));
709 rc->input_name = "LME2510 Remote Control";
710 rc->input_phys = d->rc_phys;
711 rc->map_name = RC_MAP_LME2510;
712 rc->driver_name = "LME 2510";
713 usb_to_input_id(d->udev, &rc->input_id);
715 ret = rc_register_device(rc);
722 /* Start the Interrupt */
723 ret = lme2510_int_read(adap);
725 rc_unregister_device(rc);
726 info("INT Unable to start Interrupt Service");
733 static u8 check_sum(u8 *p, u8 len)
741 static int lme2510_download_firmware(struct usb_device *dev,
742 const struct firmware *fw)
746 u16 j, wlen, len_in, start, end;
747 u8 packet_size, dlen, i;
753 data = kzalloc(512, GFP_KERNEL);
755 info("FRM Could not start Firmware Download (Buffer allocation failed)");
759 info("FRM Starting Firmware Download");
761 for (i = 1; i < 3; i++) {
762 start = (i == 1) ? 0 : 512;
763 end = (i == 1) ? 512 : fw->size;
764 for (j = start; j < end; j += (packet_size+1)) {
765 fw_data = (u8 *)(fw->data + j);
766 if ((end - j) > packet_size) {
771 dlen = (u8)(end - j)-1;
774 memcpy(&data[2], fw_data, dlen+1);
775 wlen = (u8) dlen + 4;
776 data[wlen-1] = check_sum(fw_data, dlen+1);
777 deb_info(1, "Data S=%02x:E=%02x CS= %02x", data[3],
778 data[dlen+2], data[dlen+3]);
779 ret |= lme2510_bulk_write(dev, data, wlen, 1);
780 ret |= lme2510_bulk_read(dev, data, len_in , 1);
781 ret |= (data[0] == 0x88) ? 0 : -1;
785 usb_control_msg(dev, usb_rcvctrlpipe(dev, 0),
786 0x06, 0x80, 0x0200, 0x00, data, 0x0109, 1000);
792 ret |= lme2510_bulk_write(dev, data , len_in, 1); /*Resetting*/
793 ret |= lme2510_bulk_read(dev, data, len_in, 1);
797 info("FRM Firmware Download Failed (%04x)" , ret);
799 info("FRM Firmware Download Completed - Resetting Device");
802 return (ret < 0) ? -ENODEV : 0;
805 static void lme_coldreset(struct usb_device *dev)
812 info("FRM Firmware Cold Reset");
813 ret |= lme2510_bulk_write(dev, data , len_in, 1); /*Cold Resetting*/
814 ret |= lme2510_bulk_read(dev, data, len_in, 1);
819 static int lme_firmware_switch(struct usb_device *udev, int cold)
821 const struct firmware *fw = NULL;
822 const char fw_c_s7395[] = "dvb-usb-lme2510c-s7395.fw";
823 const char fw_c_lg[] = "dvb-usb-lme2510c-lg.fw";
824 const char fw_c_s0194[] = "dvb-usb-lme2510c-s0194.fw";
825 const char fw_lg[] = "dvb-usb-lme2510-lg.fw";
826 const char fw_s0194[] = "dvb-usb-lme2510-s0194.fw";
830 cold = (cold > 0) ? (cold & 1) : 0;
834 if (udev->descriptor.idProduct == 0x1122) {
835 switch (dvb_usb_lme2510_firmware) {
837 dvb_usb_lme2510_firmware = TUNER_S0194;
840 ret = request_firmware(&fw, fw_lme, &udev->dev);
845 dvb_usb_lme2510_firmware = TUNER_LG;
848 ret = request_firmware(&fw, fw_lme, &udev->dev);
851 info("FRM No Firmware Found - please install");
852 dvb_usb_lme2510_firmware = TUNER_DEFAULT;
858 switch (dvb_usb_lme2510_firmware) {
860 dvb_usb_lme2510_firmware = TUNER_S7395;
863 ret = request_firmware(&fw, fw_lme, &udev->dev);
868 dvb_usb_lme2510_firmware = TUNER_LG;
871 ret = request_firmware(&fw, fw_lme, &udev->dev);
874 dvb_usb_lme2510_firmware = TUNER_S0194;
877 ret = request_firmware(&fw, fw_lme, &udev->dev);
880 info("FRM No Firmware Found - please install");
881 dvb_usb_lme2510_firmware = TUNER_DEFAULT;
889 info("FRM Loading %s file", fw_lme);
890 ret = lme2510_download_firmware(udev, fw);
893 release_firmware(fw);
896 info("FRM Changing to %s firmware", fw_lme);
904 static int lme2510_kill_urb(struct usb_data_stream *stream)
908 for (i = 0; i < stream->urbs_submitted; i++) {
909 deb_info(3, "killing URB no. %d.", i);
911 usb_kill_urb(stream->urb_list[i]);
913 stream->urbs_submitted = 0;
918 static struct tda10086_config tda10086_config = {
919 .demod_address = 0x1c,
922 .xtal_freq = TDA10086_XTAL_16M,
925 static struct stv0288_config lme_config = {
926 .demod_address = 0xd0,
928 .inittab = s7395_inittab,
931 static struct ix2505v_config lme_tuner = {
932 .tuner_address = 0xc0,
935 .tuner_chargepump = 0x3,
938 static struct stv0299_config sharp_z0194_config = {
939 .demod_address = 0xd0,
940 .inittab = sharp_z0194a_inittab,
944 .lock_output = STV0299_LOCKOUTPUT_1,
945 .volt13_op0_op1 = STV0299_VOLT13_OP1,
947 .set_symbol_rate = sharp_z0194a_set_symbol_rate,
950 static int dm04_lme2510_set_voltage(struct dvb_frontend *fe,
951 fe_sec_voltage_t voltage)
953 struct dvb_usb_adapter *adap = fe->dvb->priv;
954 static u8 voltage_low[] = LME_VOLTAGE_L;
955 static u8 voltage_high[] = LME_VOLTAGE_H;
957 int ret = 0, len = 3, rlen = 1;
959 if (mutex_lock_interruptible(&adap->dev->i2c_mutex) < 0)
964 ret |= lme2510_usb_talk(adap->dev,
965 voltage_high, len, rbuf, rlen);
968 case SEC_VOLTAGE_OFF:
971 ret |= lme2510_usb_talk(adap->dev,
972 voltage_low, len, rbuf, rlen);
976 mutex_unlock(&adap->dev->i2c_mutex);
978 return (ret < 0) ? -ENODEV : 0;
981 static int lme_name(struct dvb_usb_adapter *adap)
983 struct lme2510_state *st = adap->dev->priv;
984 const char *desc = adap->dev->desc->name;
985 char *fe_name[] = {"", " LG TDQY-P001F", " SHARP:BS2F7HZ7395",
986 " SHARP:BS2F7HZ0194"};
987 char *name = adap->fe->ops.info.name;
989 strlcpy(name, desc, 128);
990 strlcat(name, fe_name[st->tuner_config], 128);
995 static int dm04_lme2510_frontend_attach(struct dvb_usb_adapter *adap)
997 struct lme2510_state *st = adap->dev->priv;
1001 st->i2c_talk_onoff = 1;
1004 adap->fe = dvb_attach(tda10086_attach, &tda10086_config,
1005 &adap->dev->i2c_adap);
1008 info("TUN Found Frontend TDA10086");
1009 st->i2c_tuner_gate_w = 4;
1010 st->i2c_tuner_gate_r = 4;
1011 st->i2c_tuner_addr = 0xc0;
1012 st->tuner_config = TUNER_LG;
1013 if (dvb_usb_lme2510_firmware != TUNER_LG) {
1014 dvb_usb_lme2510_firmware = TUNER_LG;
1015 ret = lme_firmware_switch(adap->dev->udev, 1);
1021 adap->fe = dvb_attach(stv0299_attach, &sharp_z0194_config,
1022 &adap->dev->i2c_adap);
1024 info("FE Found Stv0299");
1025 st->i2c_tuner_gate_w = 4;
1026 st->i2c_tuner_gate_r = 5;
1027 st->i2c_tuner_addr = 0xc0;
1028 st->tuner_config = TUNER_S0194;
1029 if (dvb_usb_lme2510_firmware != TUNER_S0194) {
1030 dvb_usb_lme2510_firmware = TUNER_S0194;
1031 ret = lme_firmware_switch(adap->dev->udev, 1);
1037 adap->fe = dvb_attach(stv0288_attach, &lme_config,
1038 &adap->dev->i2c_adap);
1040 info("FE Found Stv0288");
1041 st->i2c_tuner_gate_w = 4;
1042 st->i2c_tuner_gate_r = 5;
1043 st->i2c_tuner_addr = 0xc0;
1044 st->tuner_config = TUNER_S7395;
1045 if (dvb_usb_lme2510_firmware != TUNER_S7395) {
1046 dvb_usb_lme2510_firmware = TUNER_S7395;
1047 ret = lme_firmware_switch(adap->dev->udev, 1);
1050 info("DM04 Not Supported");
1061 adap->fe->ops.set_voltage = dm04_lme2510_set_voltage;
1062 ret = lme_name(adap);
1066 static int dm04_lme2510_tuner(struct dvb_usb_adapter *adap)
1068 struct lme2510_state *st = adap->dev->priv;
1069 char *tun_msg[] = {"", "TDA8263", "IX2505V", "DVB_PLL_OPERA"};
1072 switch (st->tuner_config) {
1074 if (dvb_attach(tda826x_attach, adap->fe, 0xc0,
1075 &adap->dev->i2c_adap, 1))
1076 ret = st->tuner_config;
1079 if (dvb_attach(ix2505v_attach , adap->fe, &lme_tuner,
1080 &adap->dev->i2c_adap))
1081 ret = st->tuner_config;
1084 if (dvb_attach(dvb_pll_attach , adap->fe, 0xc0,
1085 &adap->dev->i2c_adap, DVB_PLL_OPERA1))
1086 ret = st->tuner_config;
1093 info("TUN Found %s tuner", tun_msg[ret]);
1095 info("TUN No tuner found --- reseting device");
1096 lme_coldreset(adap->dev->udev);
1100 /* Start the Interrupt & Remote*/
1101 ret = lme2510_int_service(adap);
1106 static int lme2510_powerup(struct dvb_usb_device *d, int onoff)
1108 struct lme2510_state *st = d->priv;
1109 static u8 lnb_on[] = LNB_ON;
1110 static u8 lnb_off[] = LNB_OFF;
1112 int ret, len = 3, rlen = 1;
1114 if (mutex_lock_interruptible(&d->i2c_mutex) < 0)
1118 ret = lme2510_usb_talk(d, lnb_on, len, rbuf, rlen);
1120 ret = lme2510_usb_talk(d, lnb_off, len, rbuf, rlen);
1122 st->i2c_talk_onoff = 1;
1124 mutex_unlock(&d->i2c_mutex);
1129 /* DVB USB Driver stuff */
1130 static struct dvb_usb_device_properties lme2510_properties;
1131 static struct dvb_usb_device_properties lme2510c_properties;
1133 static int lme2510_probe(struct usb_interface *intf,
1134 const struct usb_device_id *id)
1136 struct usb_device *udev = interface_to_usbdev(intf);
1139 usb_reset_configuration(udev);
1141 usb_set_interface(udev, intf->cur_altsetting->desc.bInterfaceNumber, 1);
1143 if (udev->speed != USB_SPEED_HIGH) {
1144 ret = usb_reset_device(udev);
1145 info("DEV Failed to connect in HIGH SPEED mode");
1149 if (lme2510_return_status(udev) == 0x44) {
1150 lme_firmware_switch(udev, 0);
1154 if (0 == dvb_usb_device_init(intf, &lme2510_properties,
1155 THIS_MODULE, NULL, adapter_nr)) {
1156 info("DEV registering device driver");
1159 if (0 == dvb_usb_device_init(intf, &lme2510c_properties,
1160 THIS_MODULE, NULL, adapter_nr)) {
1161 info("DEV registering device driver");
1165 info("DEV lme2510 Error");
1170 static struct usb_device_id lme2510_table[] = {
1171 { USB_DEVICE(0x3344, 0x1122) }, /* LME2510 */
1172 { USB_DEVICE(0x3344, 0x1120) }, /* LME2510C */
1173 {} /* Terminating entry */
1176 MODULE_DEVICE_TABLE(usb, lme2510_table);
1178 static struct dvb_usb_device_properties lme2510_properties = {
1179 .caps = DVB_USB_IS_AN_I2C_ADAPTER,
1180 .size_of_priv = sizeof(struct lme2510_state),
1184 .caps = DVB_USB_ADAP_HAS_PID_FILTER|
1185 DVB_USB_ADAP_NEED_PID_FILTERING|
1186 DVB_USB_ADAP_PID_FILTER_CAN_BE_TURNED_OFF,
1187 .streaming_ctrl = lme2510_streaming_ctrl,
1188 .pid_filter_count = 15,
1189 .pid_filter = lme2510_pid_filter,
1190 .pid_filter_ctrl = lme2510_pid_filter_ctrl,
1191 .frontend_attach = dm04_lme2510_frontend_attach,
1192 .tuner_attach = dm04_lme2510_tuner,
1193 /* parameter for the MPEG2-data transfer */
1207 .power_ctrl = lme2510_powerup,
1208 .identify_state = lme2510_identify_state,
1209 .i2c_algo = &lme2510_i2c_algo,
1210 .generic_bulk_ctrl_endpoint = 0,
1211 .num_device_descs = 1,
1213 { "DM04_LME2510_DVB-S",
1214 { &lme2510_table[0], NULL },
1220 static struct dvb_usb_device_properties lme2510c_properties = {
1221 .caps = DVB_USB_IS_AN_I2C_ADAPTER,
1222 .size_of_priv = sizeof(struct lme2510_state),
1226 .caps = DVB_USB_ADAP_HAS_PID_FILTER|
1227 DVB_USB_ADAP_NEED_PID_FILTERING|
1228 DVB_USB_ADAP_PID_FILTER_CAN_BE_TURNED_OFF,
1229 .streaming_ctrl = lme2510_streaming_ctrl,
1230 .pid_filter_count = 15,
1231 .pid_filter = lme2510_pid_filter,
1232 .pid_filter_ctrl = lme2510_pid_filter_ctrl,
1233 .frontend_attach = dm04_lme2510_frontend_attach,
1234 .tuner_attach = dm04_lme2510_tuner,
1235 /* parameter for the MPEG2-data transfer */
1249 .power_ctrl = lme2510_powerup,
1250 .identify_state = lme2510_identify_state,
1251 .i2c_algo = &lme2510_i2c_algo,
1252 .generic_bulk_ctrl_endpoint = 0,
1253 .num_device_descs = 1,
1255 { "DM04_LME2510C_DVB-S",
1256 { &lme2510_table[1], NULL },
1261 static void *lme2510_exit_int(struct dvb_usb_device *d)
1263 struct lme2510_state *st = d->priv;
1264 struct dvb_usb_adapter *adap = &d->adapter[0];
1265 void *buffer = NULL;
1268 lme2510_kill_urb(&adap->stream);
1269 adap->feedcount = 0;
1272 if (st->lme_urb != NULL) {
1273 st->i2c_talk_onoff = 1;
1274 st->signal_lock = 0;
1275 st->signal_level = 0;
1277 buffer = st->usb_buffer;
1278 usb_kill_urb(st->lme_urb);
1279 usb_free_coherent(d->udev, 5000, st->buffer,
1280 st->lme_urb->transfer_dma);
1281 info("Interrupt Service Stopped");
1282 rc_unregister_device(d->rc_dev);
1283 info("Remote Stopped");
1288 static void lme2510_exit(struct usb_interface *intf)
1290 struct dvb_usb_device *d = usb_get_intfdata(intf);
1294 usb_buffer = lme2510_exit_int(d);
1295 dvb_usb_device_exit(intf);
1300 static struct usb_driver lme2510_driver = {
1301 .name = "LME2510C_DVB-S",
1302 .probe = lme2510_probe,
1303 .disconnect = lme2510_exit,
1304 .id_table = lme2510_table,
1308 static int __init lme2510_module_init(void)
1310 int result = usb_register(&lme2510_driver);
1312 err("usb_register failed. Error number %d", result);
1319 static void __exit lme2510_module_exit(void)
1321 /* deregister this driver from the USB subsystem */
1322 usb_deregister(&lme2510_driver);
1325 module_init(lme2510_module_init);
1326 module_exit(lme2510_module_exit);
1328 MODULE_AUTHOR("Malcolm Priestley <tvboxspy@gmail.com>");
1329 MODULE_DESCRIPTION("LME2510(C) DVB-S USB2.0");
1330 MODULE_VERSION("1.86");
1331 MODULE_LICENSE("GPL");