]>
Commit | Line | Data |
---|---|---|
d2f918bb MP |
1 | /* DVB USB compliant linux driver for |
2 | * | |
3 | * DM04/QQBOX DVB-S USB BOX LME2510C + SHARP:BS2F7HZ7395 | |
ab599a6d | 4 | * LME2510C + LG TDQY-P001F |
9d4540c9 | 5 | * LME2510C + BS2F7HZ0194 |
ab599a6d | 6 | * LME2510 + LG TDQY-P001F |
9d4540c9 | 7 | * LME2510 + BS2F7HZ0194 |
d2f918bb MP |
8 | * |
9 | * MVB7395 (LME2510C+SHARP:BS2F7HZ7395) | |
10 | * SHARP:BS2F7HZ7395 = (STV0288+Sharp IX2505V) | |
11 | * | |
ab599a6d | 12 | * MV001F (LME2510+LGTDQY-P001F) |
d2f918bb MP |
13 | * LG TDQY - P001F =(TDA8263 + TDA10086H) |
14 | * | |
ab599a6d MP |
15 | * MVB0001F (LME2510C+LGTDQT-P001F) |
16 | * | |
9d4540c9 MP |
17 | * MV0194 (LME2510+SHARP:BS2F7HZ0194) |
18 | * SHARP:BS2F7HZ0194 = (STV0299+IX2410) | |
19 | * | |
20 | * MVB0194 (LME2510C+SHARP0194) | |
21 | * | |
e41543a2 MP |
22 | * LME2510C + M88RS2000 |
23 | * | |
d2f918bb MP |
24 | * For firmware see Documentation/dvb/lmedm04.txt |
25 | * | |
26 | * I2C addresses: | |
27 | * 0xd0 - STV0288 - Demodulator | |
28 | * 0xc0 - Sharp IX2505V - Tuner | |
9d4540c9 | 29 | * -- |
d2f918bb MP |
30 | * 0x1c - TDA10086 - Demodulator |
31 | * 0xc0 - TDA8263 - Tuner | |
9d4540c9 MP |
32 | * -- |
33 | * 0xd0 - STV0299 - Demodulator | |
34 | * 0xc0 - IX2410 - Tuner | |
d2f918bb MP |
35 | * |
36 | * | |
37 | * VID = 3344 PID LME2510=1122 LME2510C=1120 | |
38 | * | |
39 | * Copyright (C) 2010 Malcolm Priestley (tvboxspy@gmail.com) | |
40 | * LME2510(C)(C) Leaguerme (Shenzhen) MicroElectronics Co., Ltd. | |
41 | * | |
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. | |
45 | * | |
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. | |
50 | * | |
d2f918bb MP |
51 | * |
52 | * see Documentation/dvb/README.dvb-usb for more information | |
53 | * | |
54 | * Known Issues : | |
55 | * LME2510: Non Intel USB chipsets fail to maintain High Speed on | |
56 | * Boot or Hot Plug. | |
57 | * | |
ab599a6d | 58 | * QQbox suffers from noise on LNB voltage. |
d2f918bb | 59 | * |
9d4540c9 MP |
60 | * LME2510: SHARP:BS2F7HZ0194(MV0194) cannot cold reset and share system |
61 | * with other tuners. After a cold reset streaming will not start. | |
62 | * | |
e41543a2 | 63 | * M88RS2000 suffers from loss of lock. |
d2f918bb MP |
64 | */ |
65 | #define DVB_USB_LOG_PREFIX "LME2510(C)" | |
66 | #include <linux/usb.h> | |
67 | #include <linux/usb/input.h> | |
6bda9644 | 68 | #include <media/rc-core.h> |
d2f918bb | 69 | |
e41543a2 | 70 | #include "dvb_usb.h" |
d2f918bb MP |
71 | #include "lmedm04.h" |
72 | #include "tda826x.h" | |
73 | #include "tda10086.h" | |
74 | #include "stv0288.h" | |
75 | #include "ix2505v.h" | |
9d4540c9 MP |
76 | #include "stv0299.h" |
77 | #include "dvb-pll.h" | |
78 | #include "z0194a.h" | |
4f3b7fed | 79 | #include "m88rs2000.h" |
b858c331 | 80 | #include "ts2020.h" |
d2f918bb MP |
81 | |
82 | ||
e41543a2 MP |
83 | #define LME2510_C_S7395 "dvb-usb-lme2510c-s7395.fw"; |
84 | #define LME2510_C_LG "dvb-usb-lme2510c-lg.fw"; | |
85 | #define LME2510_C_S0194 "dvb-usb-lme2510c-s0194.fw"; | |
86 | #define LME2510_C_RS2000 "dvb-usb-lme2510c-rs2000.fw"; | |
87 | #define LME2510_LG "dvb-usb-lme2510-lg.fw"; | |
88 | #define LME2510_S0194 "dvb-usb-lme2510-s0194.fw"; | |
d2f918bb MP |
89 | |
90 | /* debug */ | |
91 | static int dvb_usb_lme2510_debug; | |
e41543a2 | 92 | #define lme_debug(var, level, args...) do { \ |
d2f918bb | 93 | if ((var >= level)) \ |
e41543a2 | 94 | pr_debug(DVB_USB_LOG_PREFIX": " args); \ |
d2f918bb | 95 | } while (0) |
e41543a2 | 96 | #define deb_info(level, args...) lme_debug(dvb_usb_lme2510_debug, level, args) |
d2f918bb | 97 | #define debug_data_snipet(level, name, p) \ |
3a3402d3 | 98 | deb_info(level, name" (%8phN)", p); |
e41543a2 | 99 | #define info(args...) pr_info(DVB_USB_LOG_PREFIX": "args) |
d2f918bb MP |
100 | |
101 | module_param_named(debug, dvb_usb_lme2510_debug, int, 0644); | |
e41543a2 | 102 | MODULE_PARM_DESC(debug, "set debugging level (1=info (or-able))."); |
d2f918bb | 103 | |
ab599a6d MP |
104 | static int dvb_usb_lme2510_firmware; |
105 | module_param_named(firmware, dvb_usb_lme2510_firmware, int, 0644); | |
106 | MODULE_PARM_DESC(firmware, "set default firmware 0=Sharp7395 1=LG"); | |
107 | ||
eb02d857 MP |
108 | static int pid_filter; |
109 | module_param_named(pid, pid_filter, int, 0644); | |
88495030 | 110 | MODULE_PARM_DESC(pid, "set default 0=default 1=off 2=on"); |
ab599a6d | 111 | |
4f3b7fed | 112 | |
d2f918bb | 113 | DVB_DEFINE_MOD_OPT_ADAPTER_NR(adapter_nr); |
9d4540c9 MP |
114 | |
115 | #define TUNER_DEFAULT 0x0 | |
ab599a6d MP |
116 | #define TUNER_LG 0x1 |
117 | #define TUNER_S7395 0x2 | |
9d4540c9 | 118 | #define TUNER_S0194 0x3 |
4f3b7fed | 119 | #define TUNER_RS2000 0x4 |
d2f918bb MP |
120 | |
121 | struct lme2510_state { | |
3a370222 | 122 | unsigned long int_urb_due; |
0df289a2 | 123 | enum fe_status lock_status; |
d2f918bb MP |
124 | u8 id; |
125 | u8 tuner_config; | |
d2f918bb MP |
126 | u8 signal_level; |
127 | u8 signal_sn; | |
128 | u8 time_key; | |
129 | u8 i2c_talk_onoff; | |
130 | u8 i2c_gate; | |
131 | u8 i2c_tuner_gate_w; | |
132 | u8 i2c_tuner_gate_r; | |
133 | u8 i2c_tuner_addr; | |
ab599a6d | 134 | u8 stream_on; |
449a0bad | 135 | u8 pid_size; |
4f3b7fed | 136 | u8 pid_off; |
d2f918bb MP |
137 | void *buffer; |
138 | struct urb *lme_urb; | |
139 | void *usb_buffer; | |
743ab6a1 | 140 | /* Frontend original calls */ |
0df289a2 | 141 | int (*fe_read_status)(struct dvb_frontend *, enum fe_status *); |
87169013 MP |
142 | int (*fe_read_signal_strength)(struct dvb_frontend *, u16 *); |
143 | int (*fe_read_snr)(struct dvb_frontend *, u16 *); | |
144 | int (*fe_read_ber)(struct dvb_frontend *, u32 *); | |
145 | int (*fe_read_ucblocks)(struct dvb_frontend *, u32 *); | |
0df289a2 | 146 | int (*fe_set_voltage)(struct dvb_frontend *, enum fe_sec_voltage); |
e41543a2 | 147 | u8 dvb_usb_lme2510_firmware; |
d2f918bb MP |
148 | }; |
149 | ||
150 | static int lme2510_bulk_write(struct usb_device *dev, | |
151 | u8 *snd, int len, u8 pipe) | |
152 | { | |
29a8d979 | 153 | int actual_l; |
ab599a6d | 154 | |
29a8d979 MY |
155 | return usb_bulk_msg(dev, usb_sndbulkpipe(dev, pipe), |
156 | snd, len, &actual_l, 100); | |
d2f918bb MP |
157 | } |
158 | ||
159 | static int lme2510_bulk_read(struct usb_device *dev, | |
160 | u8 *rev, int len, u8 pipe) | |
161 | { | |
29a8d979 | 162 | int actual_l; |
d2f918bb | 163 | |
29a8d979 MY |
164 | return usb_bulk_msg(dev, usb_rcvbulkpipe(dev, pipe), |
165 | rev, len, &actual_l, 200); | |
d2f918bb MP |
166 | } |
167 | ||
168 | static int lme2510_usb_talk(struct dvb_usb_device *d, | |
169 | u8 *wbuf, int wlen, u8 *rbuf, int rlen) | |
170 | { | |
171 | struct lme2510_state *st = d->priv; | |
172 | u8 *buff; | |
173 | int ret = 0; | |
174 | ||
175 | if (st->usb_buffer == NULL) { | |
810fda9b | 176 | st->usb_buffer = kmalloc(64, GFP_KERNEL); |
d2f918bb MP |
177 | if (st->usb_buffer == NULL) { |
178 | info("MEM Error no memory"); | |
179 | return -ENOMEM; | |
180 | } | |
181 | } | |
182 | buff = st->usb_buffer; | |
183 | ||
d2f918bb MP |
184 | ret = mutex_lock_interruptible(&d->usb_mutex); |
185 | ||
186 | if (ret < 0) | |
187 | return -EAGAIN; | |
188 | ||
810fda9b | 189 | /* the read/write capped at 64 */ |
190 | memcpy(buff, wbuf, (wlen < 64) ? wlen : 64); | |
a760d638 | 191 | |
ab599a6d MP |
192 | ret |= lme2510_bulk_write(d->udev, buff, wlen , 0x01); |
193 | ||
810fda9b | 194 | ret |= lme2510_bulk_read(d->udev, buff, (rlen < 64) ? |
195 | rlen : 64 , 0x01); | |
d2f918bb MP |
196 | |
197 | if (rlen > 0) | |
198 | memcpy(rbuf, buff, rlen); | |
199 | ||
200 | mutex_unlock(&d->usb_mutex); | |
201 | ||
202 | return (ret < 0) ? -ENODEV : 0; | |
203 | } | |
204 | ||
f23e6616 MP |
205 | static int lme2510_stream_restart(struct dvb_usb_device *d) |
206 | { | |
4f3b7fed MP |
207 | struct lme2510_state *st = d->priv; |
208 | u8 all_pids[] = LME_ALL_PIDS; | |
209 | u8 stream_on[] = LME_ST_ON_W; | |
ab599a6d | 210 | int ret; |
4f3b7fed MP |
211 | u8 rbuff[1]; |
212 | if (st->pid_off) | |
213 | ret = lme2510_usb_talk(d, all_pids, sizeof(all_pids), | |
214 | rbuff, sizeof(rbuff)); | |
ab599a6d | 215 | /*Restart Stream Command*/ |
f23e6616 | 216 | ret = lme2510_usb_talk(d, stream_on, sizeof(stream_on), |
ab599a6d MP |
217 | rbuff, sizeof(rbuff)); |
218 | return ret; | |
219 | } | |
d2f918bb | 220 | |
eb02d857 MP |
221 | static int lme2510_enable_pid(struct dvb_usb_device *d, u8 index, u16 pid_out) |
222 | { | |
223 | struct lme2510_state *st = d->priv; | |
224 | static u8 pid_buff[] = LME_ZERO_PID; | |
225 | static u8 rbuf[1]; | |
226 | u8 pid_no = index * 2; | |
449a0bad | 227 | u8 pid_len = pid_no + 2; |
eb02d857 MP |
228 | int ret = 0; |
229 | deb_info(1, "PID Setting Pid %04x", pid_out); | |
230 | ||
449a0bad MP |
231 | if (st->pid_size == 0) |
232 | ret |= lme2510_stream_restart(d); | |
233 | ||
eb02d857 MP |
234 | pid_buff[2] = pid_no; |
235 | pid_buff[3] = (u8)pid_out & 0xff; | |
236 | pid_buff[4] = pid_no + 1; | |
237 | pid_buff[5] = (u8)(pid_out >> 8); | |
238 | ||
449a0bad MP |
239 | if (pid_len > st->pid_size) |
240 | st->pid_size = pid_len; | |
241 | pid_buff[7] = 0x80 + st->pid_size; | |
eb02d857 MP |
242 | |
243 | ret |= lme2510_usb_talk(d, pid_buff , | |
244 | sizeof(pid_buff) , rbuf, sizeof(rbuf)); | |
245 | ||
449a0bad | 246 | if (st->stream_on) |
eb02d857 MP |
247 | ret |= lme2510_stream_restart(d); |
248 | ||
eb02d857 MP |
249 | return ret; |
250 | } | |
251 | ||
faebbd8f MCC |
252 | /* Convert range from 0x00-0xff to 0x0000-0xffff */ |
253 | #define reg_to_16bits(x) ((x) | ((x) << 8)) | |
254 | ||
48c91aad MP |
255 | static void lme2510_update_stats(struct dvb_usb_adapter *adap) |
256 | { | |
257 | struct lme2510_state *st = adap_to_priv(adap); | |
258 | struct dvb_frontend *fe = adap->fe[0]; | |
259 | struct dtv_frontend_properties *c; | |
5ae65db5 | 260 | u32 s_tmp = 0, c_tmp = 0; |
48c91aad MP |
261 | |
262 | if (!fe) | |
263 | return; | |
264 | ||
265 | c = &fe->dtv_property_cache; | |
266 | ||
267 | c->block_count.len = 1; | |
268 | c->block_count.stat[0].scale = FE_SCALE_NOT_AVAILABLE; | |
269 | c->block_error.len = 1; | |
270 | c->block_error.stat[0].scale = FE_SCALE_NOT_AVAILABLE; | |
271 | c->post_bit_count.len = 1; | |
272 | c->post_bit_count.stat[0].scale = FE_SCALE_NOT_AVAILABLE; | |
273 | c->post_bit_error.len = 1; | |
274 | c->post_bit_error.stat[0].scale = FE_SCALE_NOT_AVAILABLE; | |
275 | ||
276 | if (st->i2c_talk_onoff) { | |
277 | c->strength.len = 1; | |
278 | c->strength.stat[0].scale = FE_SCALE_NOT_AVAILABLE; | |
279 | c->cnr.len = 1; | |
280 | c->cnr.stat[0].scale = FE_SCALE_NOT_AVAILABLE; | |
281 | return; | |
282 | } | |
283 | ||
284 | switch (st->tuner_config) { | |
285 | case TUNER_LG: | |
faebbd8f MCC |
286 | s_tmp = reg_to_16bits(0xff - st->signal_level); |
287 | c_tmp = reg_to_16bits(0xff - st->signal_sn); | |
48c91aad | 288 | break; |
48c91aad MP |
289 | case TUNER_S7395: |
290 | case TUNER_S0194: | |
291 | s_tmp = 0xffff - (((st->signal_level * 2) << 8) * 5 / 4); | |
faebbd8f | 292 | c_tmp = reg_to_16bits((0xff - st->signal_sn - 0xa1) * 3); |
48c91aad MP |
293 | break; |
294 | case TUNER_RS2000: | |
faebbd8f MCC |
295 | s_tmp = reg_to_16bits(st->signal_level); |
296 | c_tmp = reg_to_16bits(st->signal_sn); | |
48c91aad MP |
297 | } |
298 | ||
299 | c->strength.len = 1; | |
300 | c->strength.stat[0].scale = FE_SCALE_RELATIVE; | |
5ae65db5 | 301 | c->strength.stat[0].uvalue = (u64)s_tmp; |
48c91aad MP |
302 | |
303 | c->cnr.len = 1; | |
304 | c->cnr.stat[0].scale = FE_SCALE_RELATIVE; | |
5ae65db5 | 305 | c->cnr.stat[0].uvalue = (u64)c_tmp; |
48c91aad MP |
306 | } |
307 | ||
d2f918bb MP |
308 | static void lme2510_int_response(struct urb *lme_urb) |
309 | { | |
310 | struct dvb_usb_adapter *adap = lme_urb->context; | |
e41543a2 | 311 | struct lme2510_state *st = adap_to_priv(adap); |
75759e31 | 312 | u8 *ibuf, *rbuf; |
d2f918bb | 313 | int i = 0, offset; |
616a4b83 | 314 | u32 key; |
743ab6a1 | 315 | u8 signal_lock = 0; |
d2f918bb MP |
316 | |
317 | switch (lme_urb->status) { | |
318 | case 0: | |
319 | case -ETIMEDOUT: | |
320 | break; | |
321 | case -ECONNRESET: | |
322 | case -ENOENT: | |
323 | case -ESHUTDOWN: | |
324 | return; | |
325 | default: | |
326 | info("Error %x", lme_urb->status); | |
327 | break; | |
328 | } | |
329 | ||
330 | rbuf = (u8 *) lme_urb->transfer_buffer; | |
331 | ||
332 | offset = ((lme_urb->actual_length/8) > 4) | |
333 | ? 4 : (lme_urb->actual_length/8) ; | |
334 | ||
d2f918bb MP |
335 | for (i = 0; i < offset; ++i) { |
336 | ibuf = (u8 *)&rbuf[i*8]; | |
337 | deb_info(5, "INT O/S C =%02x C/O=%02x Type =%02x%02x", | |
338 | offset, i, ibuf[0], ibuf[1]); | |
339 | ||
340 | switch (ibuf[0]) { | |
341 | case 0xaa: | |
616a4b83 | 342 | debug_data_snipet(1, "INT Remote data snipet", ibuf); |
f459aec2 DH |
343 | if (!adap_to_d(adap)->rc_dev) |
344 | break; | |
345 | ||
346 | key = RC_SCANCODE_NEC32(ibuf[2] << 24 | | |
347 | ibuf[3] << 16 | | |
348 | ibuf[4] << 8 | | |
349 | ibuf[5]); | |
350 | ||
351 | deb_info(1, "INT Key = 0x%08x", key); | |
2ceeca04 SY |
352 | rc_keydown(adap_to_d(adap)->rc_dev, RC_TYPE_NEC32, key, |
353 | 0); | |
d2f918bb MP |
354 | break; |
355 | case 0xbb: | |
356 | switch (st->tuner_config) { | |
357 | case TUNER_LG: | |
743ab6a1 | 358 | signal_lock = ibuf[2] & BIT(5); |
d2f918bb MP |
359 | st->signal_level = ibuf[4]; |
360 | st->signal_sn = ibuf[3]; | |
361 | st->time_key = ibuf[7]; | |
362 | break; | |
363 | case TUNER_S7395: | |
9d4540c9 | 364 | case TUNER_S0194: |
d2f918bb MP |
365 | /* Tweak for earlier firmware*/ |
366 | if (ibuf[1] == 0x03) { | |
743ab6a1 | 367 | signal_lock = ibuf[2] & BIT(4); |
d2f918bb | 368 | st->signal_level = ibuf[3]; |
ab599a6d | 369 | st->signal_sn = ibuf[4]; |
d2f918bb MP |
370 | } else { |
371 | st->signal_level = ibuf[4]; | |
372 | st->signal_sn = ibuf[5]; | |
373 | } | |
374 | break; | |
4f3b7fed | 375 | case TUNER_RS2000: |
743ab6a1 | 376 | signal_lock = ibuf[2] & 0xee; |
e41543a2 MP |
377 | st->signal_level = ibuf[5]; |
378 | st->signal_sn = ibuf[4]; | |
4f3b7fed | 379 | st->time_key = ibuf[7]; |
d2f918bb MP |
380 | default: |
381 | break; | |
382 | } | |
743ab6a1 MP |
383 | |
384 | /* Interrupt will also throw just BIT 0 as lock */ | |
385 | signal_lock |= ibuf[2] & BIT(0); | |
386 | ||
387 | if (!signal_lock) | |
388 | st->lock_status &= ~FE_HAS_LOCK; | |
389 | ||
48c91aad MP |
390 | lme2510_update_stats(adap); |
391 | ||
d2f918bb MP |
392 | debug_data_snipet(5, "INT Remote data snipet in", ibuf); |
393 | break; | |
394 | case 0xcc: | |
395 | debug_data_snipet(1, "INT Control data snipet", ibuf); | |
396 | break; | |
397 | default: | |
398 | debug_data_snipet(1, "INT Unknown data snipet", ibuf); | |
399 | break; | |
400 | } | |
401 | } | |
3a370222 | 402 | |
d2f918bb | 403 | usb_submit_urb(lme_urb, GFP_ATOMIC); |
3a370222 | 404 | |
cfcd7b82 MP |
405 | /* Interrupt urb is due every 48 msecs while streaming the buffer |
406 | * stores up to 4 periods if missed. Allow 200 msec for next interrupt. | |
407 | */ | |
408 | st->int_urb_due = jiffies + msecs_to_jiffies(200); | |
d2f918bb MP |
409 | } |
410 | ||
411 | static int lme2510_int_read(struct dvb_usb_adapter *adap) | |
412 | { | |
e41543a2 MP |
413 | struct dvb_usb_device *d = adap_to_d(adap); |
414 | struct lme2510_state *lme_int = adap_to_priv(adap); | |
15e1ce33 | 415 | struct usb_host_endpoint *ep; |
d2f918bb MP |
416 | |
417 | lme_int->lme_urb = usb_alloc_urb(0, GFP_ATOMIC); | |
418 | ||
419 | if (lme_int->lme_urb == NULL) | |
420 | return -ENOMEM; | |
421 | ||
e41543a2 | 422 | lme_int->buffer = usb_alloc_coherent(d->udev, 128, GFP_ATOMIC, |
d2f918bb MP |
423 | &lme_int->lme_urb->transfer_dma); |
424 | ||
425 | if (lme_int->buffer == NULL) | |
426 | return -ENOMEM; | |
427 | ||
428 | usb_fill_int_urb(lme_int->lme_urb, | |
e41543a2 MP |
429 | d->udev, |
430 | usb_rcvintpipe(d->udev, 0xa), | |
d2f918bb | 431 | lme_int->buffer, |
95c21c41 | 432 | 128, |
d2f918bb MP |
433 | lme2510_int_response, |
434 | adap, | |
95c21c41 | 435 | 8); |
d2f918bb | 436 | |
15e1ce33 MP |
437 | /* Quirk of pipe reporting PIPE_BULK but behaves as interrupt */ |
438 | ep = usb_pipe_endpoint(d->udev, lme_int->lme_urb->pipe); | |
439 | ||
440 | if (usb_endpoint_type(&ep->desc) == USB_ENDPOINT_XFER_BULK) | |
441 | lme_int->lme_urb->pipe = usb_rcvbulkpipe(d->udev, 0xa), | |
442 | ||
d2f918bb MP |
443 | lme_int->lme_urb->transfer_flags |= URB_NO_TRANSFER_DMA_MAP; |
444 | ||
445 | usb_submit_urb(lme_int->lme_urb, GFP_ATOMIC); | |
25985edc | 446 | info("INT Interrupt Service Started"); |
d2f918bb MP |
447 | |
448 | return 0; | |
449 | } | |
450 | ||
eb02d857 MP |
451 | static int lme2510_pid_filter_ctrl(struct dvb_usb_adapter *adap, int onoff) |
452 | { | |
e41543a2 MP |
453 | struct dvb_usb_device *d = adap_to_d(adap); |
454 | struct lme2510_state *st = adap_to_priv(adap); | |
4f3b7fed | 455 | static u8 clear_pid_reg[] = LME_ALL_PIDS; |
eb02d857 | 456 | static u8 rbuf[1]; |
b7dc4cd1 | 457 | int ret = 0; |
eb02d857 MP |
458 | |
459 | deb_info(1, "PID Clearing Filter"); | |
460 | ||
e41543a2 | 461 | mutex_lock(&d->i2c_mutex); |
eb02d857 | 462 | |
4f3b7fed | 463 | if (!onoff) { |
e41543a2 | 464 | ret |= lme2510_usb_talk(d, clear_pid_reg, |
eb02d857 | 465 | sizeof(clear_pid_reg), rbuf, sizeof(rbuf)); |
4f3b7fed MP |
466 | st->pid_off = true; |
467 | } else | |
468 | st->pid_off = false; | |
eb02d857 | 469 | |
449a0bad MP |
470 | st->pid_size = 0; |
471 | ||
e41543a2 | 472 | mutex_unlock(&d->i2c_mutex); |
eb02d857 MP |
473 | |
474 | return 0; | |
475 | } | |
476 | ||
477 | static int lme2510_pid_filter(struct dvb_usb_adapter *adap, int index, u16 pid, | |
478 | int onoff) | |
479 | { | |
e41543a2 | 480 | struct dvb_usb_device *d = adap_to_d(adap); |
eb02d857 MP |
481 | int ret = 0; |
482 | ||
483 | deb_info(3, "%s PID=%04x Index=%04x onoff=%02x", __func__, | |
484 | pid, index, onoff); | |
485 | ||
4c316b55 | 486 | if (onoff) { |
e41543a2 MP |
487 | mutex_lock(&d->i2c_mutex); |
488 | ret |= lme2510_enable_pid(d, index, pid); | |
489 | mutex_unlock(&d->i2c_mutex); | |
449a0bad MP |
490 | } |
491 | ||
eb02d857 MP |
492 | |
493 | return ret; | |
494 | } | |
495 | ||
496 | ||
e41543a2 | 497 | static int lme2510_return_status(struct dvb_usb_device *d) |
d2f918bb MP |
498 | { |
499 | int ret = 0; | |
945b8766 FM |
500 | u8 *data; |
501 | ||
502 | data = kzalloc(10, GFP_KERNEL); | |
503 | if (!data) | |
504 | return -ENOMEM; | |
ab599a6d | 505 | |
e41543a2 | 506 | ret |= usb_control_msg(d->udev, usb_rcvctrlpipe(d->udev, 0), |
d2f918bb MP |
507 | 0x06, 0x80, 0x0302, 0x00, data, 0x0006, 200); |
508 | info("Firmware Status: %x (%x)", ret , data[2]); | |
509 | ||
945b8766 FM |
510 | ret = (ret < 0) ? -ENODEV : data[2]; |
511 | kfree(data); | |
512 | return ret; | |
d2f918bb MP |
513 | } |
514 | ||
515 | static int lme2510_msg(struct dvb_usb_device *d, | |
516 | u8 *wbuf, int wlen, u8 *rbuf, int rlen) | |
517 | { | |
d2f918bb MP |
518 | struct lme2510_state *st = d->priv; |
519 | ||
743ab6a1 | 520 | st->i2c_talk_onoff = 1; |
d2f918bb | 521 | |
743ab6a1 | 522 | return lme2510_usb_talk(d, wbuf, wlen, rbuf, rlen); |
d2f918bb MP |
523 | } |
524 | ||
d2f918bb MP |
525 | static int lme2510_i2c_xfer(struct i2c_adapter *adap, struct i2c_msg msg[], |
526 | int num) | |
527 | { | |
528 | struct dvb_usb_device *d = i2c_get_adapdata(adap); | |
529 | struct lme2510_state *st = d->priv; | |
810fda9b | 530 | static u8 obuf[64], ibuf[64]; |
d2f918bb MP |
531 | int i, read, read_o; |
532 | u16 len; | |
533 | u8 gate = st->i2c_gate; | |
534 | ||
4f3b7fed MP |
535 | mutex_lock(&d->i2c_mutex); |
536 | ||
d2f918bb MP |
537 | if (gate == 0) |
538 | gate = 5; | |
539 | ||
d2f918bb | 540 | for (i = 0; i < num; i++) { |
71dc98be MP |
541 | read_o = msg[i].flags & I2C_M_RD; |
542 | read = i + 1 < num && msg[i + 1].flags & I2C_M_RD; | |
d2f918bb MP |
543 | read |= read_o; |
544 | gate = (msg[i].addr == st->i2c_tuner_addr) | |
545 | ? (read) ? st->i2c_tuner_gate_r | |
546 | : st->i2c_tuner_gate_w | |
547 | : st->i2c_gate; | |
548 | obuf[0] = gate | (read << 7); | |
549 | ||
550 | if (gate == 5) | |
551 | obuf[1] = (read) ? 2 : msg[i].len + 1; | |
552 | else | |
553 | obuf[1] = msg[i].len + read + 1; | |
554 | ||
71dc98be MP |
555 | obuf[2] = msg[i].addr << 1; |
556 | ||
d2f918bb MP |
557 | if (read) { |
558 | if (read_o) | |
559 | len = 3; | |
560 | else { | |
561 | memcpy(&obuf[3], msg[i].buf, msg[i].len); | |
562 | obuf[msg[i].len+3] = msg[i+1].len; | |
563 | len = msg[i].len+4; | |
564 | } | |
565 | } else { | |
566 | memcpy(&obuf[3], msg[i].buf, msg[i].len); | |
567 | len = msg[i].len+3; | |
568 | } | |
569 | ||
810fda9b | 570 | if (lme2510_msg(d, obuf, len, ibuf, 64) < 0) { |
d2f918bb | 571 | deb_info(1, "i2c transfer failed."); |
4f3b7fed | 572 | mutex_unlock(&d->i2c_mutex); |
d2f918bb MP |
573 | return -EAGAIN; |
574 | } | |
575 | ||
576 | if (read) { | |
577 | if (read_o) | |
578 | memcpy(msg[i].buf, &ibuf[1], msg[i].len); | |
579 | else { | |
580 | memcpy(msg[i+1].buf, &ibuf[1], msg[i+1].len); | |
581 | i++; | |
582 | } | |
583 | } | |
584 | } | |
4f3b7fed MP |
585 | |
586 | mutex_unlock(&d->i2c_mutex); | |
d2f918bb MP |
587 | return i; |
588 | } | |
589 | ||
590 | static u32 lme2510_i2c_func(struct i2c_adapter *adapter) | |
591 | { | |
592 | return I2C_FUNC_I2C; | |
593 | } | |
594 | ||
595 | static struct i2c_algorithm lme2510_i2c_algo = { | |
596 | .master_xfer = lme2510_i2c_xfer, | |
597 | .functionality = lme2510_i2c_func, | |
598 | }; | |
599 | ||
e41543a2 | 600 | static int lme2510_streaming_ctrl(struct dvb_frontend *fe, int onoff) |
d2f918bb | 601 | { |
e41543a2 MP |
602 | struct dvb_usb_adapter *adap = fe_to_adap(fe); |
603 | struct dvb_usb_device *d = adap_to_d(adap); | |
604 | struct lme2510_state *st = adap_to_priv(adap); | |
4f3b7fed | 605 | static u8 clear_reg_3[] = LME_ALL_PIDS; |
d2f918bb | 606 | static u8 rbuf[1]; |
f23e6616 | 607 | int ret = 0, rlen = sizeof(rbuf); |
d2f918bb MP |
608 | |
609 | deb_info(1, "STM (%02x)", onoff); | |
610 | ||
f23e6616 MP |
611 | /* Streaming is started by FE_HAS_LOCK */ |
612 | if (onoff == 1) | |
ab599a6d | 613 | st->stream_on = 1; |
f23e6616 | 614 | else { |
d2f918bb | 615 | deb_info(1, "STM Steam Off"); |
f23e6616 | 616 | /* mutex is here only to avoid collision with I2C */ |
e41543a2 | 617 | mutex_lock(&d->i2c_mutex); |
f23e6616 | 618 | |
e41543a2 | 619 | ret = lme2510_usb_talk(d, clear_reg_3, |
d2f918bb | 620 | sizeof(clear_reg_3), rbuf, rlen); |
ab599a6d | 621 | st->stream_on = 0; |
d2f918bb | 622 | st->i2c_talk_onoff = 1; |
f23e6616 | 623 | |
e41543a2 | 624 | mutex_unlock(&d->i2c_mutex); |
d2f918bb MP |
625 | } |
626 | ||
627 | return (ret < 0) ? -ENODEV : 0; | |
628 | } | |
629 | ||
d2f918bb MP |
630 | static u8 check_sum(u8 *p, u8 len) |
631 | { | |
632 | u8 sum = 0; | |
633 | while (len--) | |
634 | sum += *p++; | |
635 | return sum; | |
636 | } | |
637 | ||
e41543a2 | 638 | static int lme2510_download_firmware(struct dvb_usb_device *d, |
d2f918bb MP |
639 | const struct firmware *fw) |
640 | { | |
641 | int ret = 0; | |
945b8766 | 642 | u8 *data; |
d2f918bb MP |
643 | u16 j, wlen, len_in, start, end; |
644 | u8 packet_size, dlen, i; | |
645 | u8 *fw_data; | |
646 | ||
647 | packet_size = 0x31; | |
648 | len_in = 1; | |
649 | ||
e41543a2 | 650 | data = kzalloc(128, GFP_KERNEL); |
945b8766 | 651 | if (!data) { |
e41543a2 MP |
652 | info("FRM Could not start Firmware Download"\ |
653 | "(Buffer allocation failed)"); | |
945b8766 FM |
654 | return -ENOMEM; |
655 | } | |
d2f918bb MP |
656 | |
657 | info("FRM Starting Firmware Download"); | |
658 | ||
659 | for (i = 1; i < 3; i++) { | |
660 | start = (i == 1) ? 0 : 512; | |
661 | end = (i == 1) ? 512 : fw->size; | |
662 | for (j = start; j < end; j += (packet_size+1)) { | |
663 | fw_data = (u8 *)(fw->data + j); | |
664 | if ((end - j) > packet_size) { | |
665 | data[0] = i; | |
666 | dlen = packet_size; | |
667 | } else { | |
668 | data[0] = i | 0x80; | |
669 | dlen = (u8)(end - j)-1; | |
670 | } | |
b9f7b73c FM |
671 | data[1] = dlen; |
672 | memcpy(&data[2], fw_data, dlen+1); | |
673 | wlen = (u8) dlen + 4; | |
674 | data[wlen-1] = check_sum(fw_data, dlen+1); | |
675 | deb_info(1, "Data S=%02x:E=%02x CS= %02x", data[3], | |
d2f918bb | 676 | data[dlen+2], data[dlen+3]); |
e41543a2 | 677 | lme2510_usb_talk(d, data, wlen, data, len_in); |
b9f7b73c | 678 | ret |= (data[0] == 0x88) ? 0 : -1; |
d2f918bb MP |
679 | } |
680 | } | |
f23e6616 | 681 | |
d2f918bb MP |
682 | data[0] = 0x8a; |
683 | len_in = 1; | |
684 | msleep(2000); | |
e41543a2 | 685 | lme2510_usb_talk(d, data, len_in, data, len_in); |
d2f918bb MP |
686 | msleep(400); |
687 | ||
688 | if (ret < 0) | |
689 | info("FRM Firmware Download Failed (%04x)" , ret); | |
690 | else | |
691 | info("FRM Firmware Download Completed - Resetting Device"); | |
692 | ||
945b8766 | 693 | kfree(data); |
e41543a2 | 694 | return RECONNECTS_USB; |
d2f918bb MP |
695 | } |
696 | ||
e41543a2 | 697 | static void lme_coldreset(struct dvb_usb_device *d) |
ab599a6d | 698 | { |
e41543a2 | 699 | u8 data[1] = {0}; |
ab599a6d | 700 | data[0] = 0x0a; |
ab599a6d | 701 | info("FRM Firmware Cold Reset"); |
e41543a2 MP |
702 | |
703 | lme2510_usb_talk(d, data, sizeof(data), data, sizeof(data)); | |
f23e6616 | 704 | |
ab599a6d MP |
705 | return; |
706 | } | |
707 | ||
e41543a2 MP |
708 | static const char fw_c_s7395[] = LME2510_C_S7395; |
709 | static const char fw_c_lg[] = LME2510_C_LG; | |
710 | static const char fw_c_s0194[] = LME2510_C_S0194; | |
711 | static const char fw_c_rs2000[] = LME2510_C_RS2000; | |
712 | static const char fw_lg[] = LME2510_LG; | |
713 | static const char fw_s0194[] = LME2510_S0194; | |
714 | ||
1885fd2d | 715 | static const char *lme_firmware_switch(struct dvb_usb_device *d, int cold) |
ab599a6d | 716 | { |
e41543a2 MP |
717 | struct lme2510_state *st = d->priv; |
718 | struct usb_device *udev = d->udev; | |
ab599a6d | 719 | const struct firmware *fw = NULL; |
9d4540c9 | 720 | const char *fw_lme; |
e41543a2 | 721 | int ret = 0; |
ab599a6d | 722 | |
f23e6616 MP |
723 | cold = (cold > 0) ? (cold & 1) : 0; |
724 | ||
4f3b7fed MP |
725 | switch (le16_to_cpu(udev->descriptor.idProduct)) { |
726 | case 0x1122: | |
e41543a2 | 727 | switch (st->dvb_usb_lme2510_firmware) { |
9d4540c9 | 728 | default: |
9d4540c9 MP |
729 | case TUNER_S0194: |
730 | fw_lme = fw_s0194; | |
731 | ret = request_firmware(&fw, fw_lme, &udev->dev); | |
732 | if (ret == 0) { | |
504febc3 | 733 | st->dvb_usb_lme2510_firmware = TUNER_S0194; |
30bd3b56 | 734 | cold = 0; |
9d4540c9 MP |
735 | break; |
736 | } | |
504febc3 | 737 | /* fall through */ |
9d4540c9 MP |
738 | case TUNER_LG: |
739 | fw_lme = fw_lg; | |
740 | ret = request_firmware(&fw, fw_lme, &udev->dev); | |
504febc3 MCC |
741 | if (ret == 0) { |
742 | st->dvb_usb_lme2510_firmware = TUNER_LG; | |
9d4540c9 | 743 | break; |
504febc3 | 744 | } |
e41543a2 | 745 | st->dvb_usb_lme2510_firmware = TUNER_DEFAULT; |
ab599a6d MP |
746 | break; |
747 | } | |
4f3b7fed MP |
748 | break; |
749 | case 0x1120: | |
e41543a2 | 750 | switch (st->dvb_usb_lme2510_firmware) { |
9d4540c9 | 751 | default: |
9d4540c9 MP |
752 | case TUNER_S7395: |
753 | fw_lme = fw_c_s7395; | |
754 | ret = request_firmware(&fw, fw_lme, &udev->dev); | |
30bd3b56 | 755 | if (ret == 0) { |
504febc3 | 756 | st->dvb_usb_lme2510_firmware = TUNER_S7395; |
30bd3b56 | 757 | cold = 0; |
9d4540c9 | 758 | break; |
30bd3b56 | 759 | } |
504febc3 | 760 | /* fall through */ |
9d4540c9 MP |
761 | case TUNER_LG: |
762 | fw_lme = fw_c_lg; | |
763 | ret = request_firmware(&fw, fw_lme, &udev->dev); | |
504febc3 MCC |
764 | if (ret == 0) { |
765 | st->dvb_usb_lme2510_firmware = TUNER_LG; | |
9d4540c9 | 766 | break; |
504febc3 MCC |
767 | } |
768 | /* fall through */ | |
9d4540c9 MP |
769 | case TUNER_S0194: |
770 | fw_lme = fw_c_s0194; | |
771 | ret = request_firmware(&fw, fw_lme, &udev->dev); | |
504febc3 MCC |
772 | if (ret == 0) { |
773 | st->dvb_usb_lme2510_firmware = TUNER_S0194; | |
9d4540c9 | 774 | break; |
504febc3 | 775 | } |
e41543a2 | 776 | st->dvb_usb_lme2510_firmware = TUNER_DEFAULT; |
ab599a6d | 777 | cold = 0; |
ab599a6d MP |
778 | break; |
779 | } | |
4f3b7fed MP |
780 | break; |
781 | case 0x22f0: | |
782 | fw_lme = fw_c_rs2000; | |
e41543a2 | 783 | st->dvb_usb_lme2510_firmware = TUNER_RS2000; |
4f3b7fed MP |
784 | break; |
785 | default: | |
786 | fw_lme = fw_c_s7395; | |
ab599a6d | 787 | } |
f23e6616 | 788 | |
30bd3b56 MP |
789 | release_firmware(fw); |
790 | ||
75aecc3a | 791 | if (cold) { |
e41543a2 | 792 | dvb_usb_lme2510_firmware = st->dvb_usb_lme2510_firmware; |
9d4540c9 | 793 | info("FRM Changing to %s firmware", fw_lme); |
e41543a2 MP |
794 | lme_coldreset(d); |
795 | return NULL; | |
75aecc3a | 796 | } |
f23e6616 | 797 | |
e41543a2 | 798 | return fw_lme; |
ab599a6d | 799 | } |
d2f918bb MP |
800 | |
801 | static int lme2510_kill_urb(struct usb_data_stream *stream) | |
802 | { | |
803 | int i; | |
f23e6616 | 804 | |
d2f918bb MP |
805 | for (i = 0; i < stream->urbs_submitted; i++) { |
806 | deb_info(3, "killing URB no. %d.", i); | |
d2f918bb MP |
807 | /* stop the URB */ |
808 | usb_kill_urb(stream->urb_list[i]); | |
809 | } | |
810 | stream->urbs_submitted = 0; | |
f23e6616 | 811 | |
d2f918bb MP |
812 | return 0; |
813 | } | |
814 | ||
815 | static struct tda10086_config tda10086_config = { | |
71dc98be | 816 | .demod_address = 0x0e, |
d2f918bb MP |
817 | .invert = 0, |
818 | .diseqc_tone = 1, | |
819 | .xtal_freq = TDA10086_XTAL_16M, | |
820 | }; | |
821 | ||
822 | static struct stv0288_config lme_config = { | |
71dc98be | 823 | .demod_address = 0x68, |
d2f918bb MP |
824 | .min_delay_ms = 15, |
825 | .inittab = s7395_inittab, | |
826 | }; | |
827 | ||
828 | static struct ix2505v_config lme_tuner = { | |
71dc98be | 829 | .tuner_address = 0x60, |
d2f918bb MP |
830 | .min_delay_ms = 100, |
831 | .tuner_gain = 0x0, | |
832 | .tuner_chargepump = 0x3, | |
833 | }; | |
834 | ||
9d4540c9 | 835 | static struct stv0299_config sharp_z0194_config = { |
71dc98be | 836 | .demod_address = 0x68, |
9d4540c9 MP |
837 | .inittab = sharp_z0194a_inittab, |
838 | .mclk = 88000000UL, | |
839 | .invert = 0, | |
840 | .skip_reinit = 0, | |
841 | .lock_output = STV0299_LOCKOUTPUT_1, | |
842 | .volt13_op0_op1 = STV0299_VOLT13_OP1, | |
843 | .min_delay_ms = 100, | |
844 | .set_symbol_rate = sharp_z0194a_set_symbol_rate, | |
845 | }; | |
846 | ||
4f3b7fed | 847 | static struct m88rs2000_config m88rs2000_config = { |
743ab6a1 | 848 | .demod_addr = 0x68 |
4f3b7fed MP |
849 | }; |
850 | ||
b858c331 IL |
851 | static struct ts2020_config ts2020_config = { |
852 | .tuner_address = 0x60, | |
853 | .clk_out_div = 7, | |
9e8715c9 | 854 | .dont_poll = true |
b858c331 IL |
855 | }; |
856 | ||
d2f918bb | 857 | static int dm04_lme2510_set_voltage(struct dvb_frontend *fe, |
0df289a2 | 858 | enum fe_sec_voltage voltage) |
d2f918bb | 859 | { |
e41543a2 MP |
860 | struct dvb_usb_device *d = fe_to_d(fe); |
861 | struct lme2510_state *st = fe_to_priv(fe); | |
862 | static u8 voltage_low[] = LME_VOLTAGE_L; | |
d2f918bb | 863 | static u8 voltage_high[] = LME_VOLTAGE_H; |
d2f918bb MP |
864 | static u8 rbuf[1]; |
865 | int ret = 0, len = 3, rlen = 1; | |
866 | ||
e41543a2 | 867 | mutex_lock(&d->i2c_mutex); |
d2f918bb | 868 | |
ab599a6d MP |
869 | switch (voltage) { |
870 | case SEC_VOLTAGE_18: | |
e41543a2 | 871 | ret |= lme2510_usb_talk(d, |
ab599a6d | 872 | voltage_high, len, rbuf, rlen); |
d2f918bb MP |
873 | break; |
874 | ||
ab599a6d | 875 | case SEC_VOLTAGE_OFF: |
ab599a6d MP |
876 | case SEC_VOLTAGE_13: |
877 | default: | |
e41543a2 | 878 | ret |= lme2510_usb_talk(d, |
d2f918bb MP |
879 | voltage_low, len, rbuf, rlen); |
880 | break; | |
f23e6616 | 881 | } |
d2f918bb | 882 | |
e41543a2 MP |
883 | mutex_unlock(&d->i2c_mutex); |
884 | ||
885 | if (st->tuner_config == TUNER_RS2000) | |
886 | if (st->fe_set_voltage) | |
887 | st->fe_set_voltage(fe, voltage); | |
888 | ||
d2f918bb | 889 | |
d2f918bb MP |
890 | return (ret < 0) ? -ENODEV : 0; |
891 | } | |
892 | ||
0df289a2 | 893 | static int dm04_read_status(struct dvb_frontend *fe, enum fe_status *status) |
743ab6a1 MP |
894 | { |
895 | struct dvb_usb_device *d = fe_to_d(fe); | |
896 | struct lme2510_state *st = d->priv; | |
897 | int ret = 0; | |
898 | ||
899 | if (st->i2c_talk_onoff) { | |
900 | if (st->fe_read_status) { | |
901 | ret = st->fe_read_status(fe, status); | |
902 | if (ret < 0) | |
903 | return ret; | |
904 | } | |
905 | ||
906 | st->lock_status = *status; | |
907 | ||
908 | if (*status & FE_HAS_LOCK && st->stream_on) { | |
909 | mutex_lock(&d->i2c_mutex); | |
910 | ||
911 | st->i2c_talk_onoff = 0; | |
912 | ret = lme2510_stream_restart(d); | |
913 | ||
914 | mutex_unlock(&d->i2c_mutex); | |
915 | } | |
916 | ||
917 | return ret; | |
918 | } | |
919 | ||
920 | /* Timeout of interrupt reached on RS2000 */ | |
921 | if (st->tuner_config == TUNER_RS2000 && | |
922 | time_after(jiffies, st->int_urb_due)) | |
923 | st->lock_status &= ~FE_HAS_LOCK; | |
924 | ||
925 | *status = st->lock_status; | |
926 | ||
48c91aad MP |
927 | if (!(*status & FE_HAS_LOCK)) { |
928 | struct dvb_usb_adapter *adap = fe_to_adap(fe); | |
929 | ||
743ab6a1 MP |
930 | st->i2c_talk_onoff = 1; |
931 | ||
48c91aad MP |
932 | lme2510_update_stats(adap); |
933 | } | |
934 | ||
743ab6a1 MP |
935 | return ret; |
936 | } | |
937 | ||
d8bad1e2 | 938 | static int dm04_read_signal_strength(struct dvb_frontend *fe, u16 *strength) |
4f3b7fed | 939 | { |
48c91aad | 940 | struct dtv_frontend_properties *c = &fe->dtv_property_cache; |
e41543a2 MP |
941 | struct lme2510_state *st = fe_to_priv(fe); |
942 | ||
87169013 MP |
943 | if (st->fe_read_signal_strength && !st->stream_on) |
944 | return st->fe_read_signal_strength(fe, strength); | |
945 | ||
48c91aad MP |
946 | if (c->strength.stat[0].scale == FE_SCALE_RELATIVE) |
947 | *strength = (u16)c->strength.stat[0].uvalue; | |
948 | else | |
949 | *strength = 0; | |
4f3b7fed | 950 | |
4f3b7fed MP |
951 | return 0; |
952 | } | |
953 | ||
d8bad1e2 | 954 | static int dm04_read_snr(struct dvb_frontend *fe, u16 *snr) |
4f3b7fed | 955 | { |
48c91aad | 956 | struct dtv_frontend_properties *c = &fe->dtv_property_cache; |
e41543a2 MP |
957 | struct lme2510_state *st = fe_to_priv(fe); |
958 | ||
87169013 MP |
959 | if (st->fe_read_snr && !st->stream_on) |
960 | return st->fe_read_snr(fe, snr); | |
961 | ||
48c91aad MP |
962 | if (c->cnr.stat[0].scale == FE_SCALE_RELATIVE) |
963 | *snr = (u16)c->cnr.stat[0].uvalue; | |
964 | else | |
965 | *snr = 0; | |
e41543a2 MP |
966 | |
967 | return 0; | |
968 | } | |
969 | ||
970 | static int dm04_read_ber(struct dvb_frontend *fe, u32 *ber) | |
971 | { | |
87169013 MP |
972 | struct lme2510_state *st = fe_to_priv(fe); |
973 | ||
974 | if (st->fe_read_ber && !st->stream_on) | |
975 | return st->fe_read_ber(fe, ber); | |
976 | ||
e41543a2 MP |
977 | *ber = 0; |
978 | ||
979 | return 0; | |
980 | } | |
981 | ||
982 | static int dm04_read_ucblocks(struct dvb_frontend *fe, u32 *ucblocks) | |
983 | { | |
87169013 MP |
984 | struct lme2510_state *st = fe_to_priv(fe); |
985 | ||
986 | if (st->fe_read_ucblocks && !st->stream_on) | |
987 | return st->fe_read_ucblocks(fe, ucblocks); | |
988 | ||
e41543a2 | 989 | *ucblocks = 0; |
4f3b7fed | 990 | |
4f3b7fed MP |
991 | return 0; |
992 | } | |
993 | ||
75aecc3a MP |
994 | static int lme_name(struct dvb_usb_adapter *adap) |
995 | { | |
e41543a2 MP |
996 | struct dvb_usb_device *d = adap_to_d(adap); |
997 | struct lme2510_state *st = adap_to_priv(adap); | |
998 | const char *desc = d->name; | |
bfe17178 RV |
999 | static const char * const fe_name[] = { |
1000 | "", " LG TDQY-P001F", " SHARP:BS2F7HZ7395", | |
1001 | " SHARP:BS2F7HZ0194", " RS2000"}; | |
e41543a2 | 1002 | char *name = adap->fe[0]->ops.info.name; |
75aecc3a MP |
1003 | |
1004 | strlcpy(name, desc, 128); | |
1005 | strlcat(name, fe_name[st->tuner_config], 128); | |
1006 | ||
1007 | return 0; | |
1008 | } | |
1009 | ||
d2f918bb MP |
1010 | static int dm04_lme2510_frontend_attach(struct dvb_usb_adapter *adap) |
1011 | { | |
e41543a2 MP |
1012 | struct dvb_usb_device *d = adap_to_d(adap); |
1013 | struct lme2510_state *st = d->priv; | |
75aecc3a | 1014 | int ret = 0; |
d2f918bb MP |
1015 | |
1016 | st->i2c_talk_onoff = 1; | |
e41543a2 | 1017 | switch (le16_to_cpu(d->udev->descriptor.idProduct)) { |
4f3b7fed MP |
1018 | case 0x1122: |
1019 | case 0x1120: | |
1020 | st->i2c_gate = 4; | |
e41543a2 MP |
1021 | adap->fe[0] = dvb_attach(tda10086_attach, |
1022 | &tda10086_config, &d->i2c_adap); | |
1023 | if (adap->fe[0]) { | |
4f3b7fed MP |
1024 | info("TUN Found Frontend TDA10086"); |
1025 | st->i2c_tuner_gate_w = 4; | |
1026 | st->i2c_tuner_gate_r = 4; | |
71dc98be | 1027 | st->i2c_tuner_addr = 0x60; |
4f3b7fed | 1028 | st->tuner_config = TUNER_LG; |
e41543a2 MP |
1029 | if (st->dvb_usb_lme2510_firmware != TUNER_LG) { |
1030 | st->dvb_usb_lme2510_firmware = TUNER_LG; | |
1031 | ret = lme_firmware_switch(d, 1) ? 0 : -ENODEV; | |
4f3b7fed MP |
1032 | } |
1033 | break; | |
1034 | } | |
d2f918bb | 1035 | |
4f3b7fed | 1036 | st->i2c_gate = 4; |
e41543a2 MP |
1037 | adap->fe[0] = dvb_attach(stv0299_attach, |
1038 | &sharp_z0194_config, &d->i2c_adap); | |
1039 | if (adap->fe[0]) { | |
4f3b7fed MP |
1040 | info("FE Found Stv0299"); |
1041 | st->i2c_tuner_gate_w = 4; | |
1042 | st->i2c_tuner_gate_r = 5; | |
71dc98be | 1043 | st->i2c_tuner_addr = 0x60; |
4f3b7fed | 1044 | st->tuner_config = TUNER_S0194; |
e41543a2 MP |
1045 | if (st->dvb_usb_lme2510_firmware != TUNER_S0194) { |
1046 | st->dvb_usb_lme2510_firmware = TUNER_S0194; | |
1047 | ret = lme_firmware_switch(d, 1) ? 0 : -ENODEV; | |
4f3b7fed MP |
1048 | } |
1049 | break; | |
9d4540c9 | 1050 | } |
9d4540c9 | 1051 | |
4f3b7fed | 1052 | st->i2c_gate = 5; |
e41543a2 MP |
1053 | adap->fe[0] = dvb_attach(stv0288_attach, &lme_config, |
1054 | &d->i2c_adap); | |
4f3b7fed | 1055 | |
e41543a2 | 1056 | if (adap->fe[0]) { |
4f3b7fed MP |
1057 | info("FE Found Stv0288"); |
1058 | st->i2c_tuner_gate_w = 4; | |
1059 | st->i2c_tuner_gate_r = 5; | |
71dc98be | 1060 | st->i2c_tuner_addr = 0x60; |
4f3b7fed | 1061 | st->tuner_config = TUNER_S7395; |
e41543a2 MP |
1062 | if (st->dvb_usb_lme2510_firmware != TUNER_S7395) { |
1063 | st->dvb_usb_lme2510_firmware = TUNER_S7395; | |
1064 | ret = lme_firmware_switch(d, 1) ? 0 : -ENODEV; | |
4f3b7fed MP |
1065 | } |
1066 | break; | |
9d4540c9 | 1067 | } |
4f3b7fed MP |
1068 | case 0x22f0: |
1069 | st->i2c_gate = 5; | |
e41543a2 MP |
1070 | adap->fe[0] = dvb_attach(m88rs2000_attach, |
1071 | &m88rs2000_config, &d->i2c_adap); | |
f23e6616 | 1072 | |
e41543a2 | 1073 | if (adap->fe[0]) { |
4f3b7fed | 1074 | info("FE Found M88RS2000"); |
b858c331 IL |
1075 | dvb_attach(ts2020_attach, adap->fe[0], &ts2020_config, |
1076 | &d->i2c_adap); | |
4f3b7fed MP |
1077 | st->i2c_tuner_gate_w = 5; |
1078 | st->i2c_tuner_gate_r = 5; | |
71dc98be | 1079 | st->i2c_tuner_addr = 0x60; |
4f3b7fed | 1080 | st->tuner_config = TUNER_RS2000; |
e41543a2 MP |
1081 | st->fe_set_voltage = |
1082 | adap->fe[0]->ops.set_voltage; | |
d2f918bb | 1083 | } |
4f3b7fed | 1084 | break; |
75aecc3a MP |
1085 | } |
1086 | ||
e41543a2 MP |
1087 | if (adap->fe[0] == NULL) { |
1088 | info("DM04/QQBOX Not Powered up or not Supported"); | |
1089 | return -ENODEV; | |
4f3b7fed | 1090 | } |
9d4540c9 | 1091 | |
4f3b7fed | 1092 | if (ret) { |
e41543a2 MP |
1093 | if (adap->fe[0]) { |
1094 | dvb_frontend_detach(adap->fe[0]); | |
1095 | adap->fe[0] = NULL; | |
616a4b83 | 1096 | } |
e41543a2 | 1097 | d->rc_map = NULL; |
75aecc3a | 1098 | return -ENODEV; |
d2f918bb MP |
1099 | } |
1100 | ||
743ab6a1 | 1101 | st->fe_read_status = adap->fe[0]->ops.read_status; |
87169013 MP |
1102 | st->fe_read_signal_strength = adap->fe[0]->ops.read_signal_strength; |
1103 | st->fe_read_snr = adap->fe[0]->ops.read_snr; | |
1104 | st->fe_read_ber = adap->fe[0]->ops.read_ber; | |
1105 | st->fe_read_ucblocks = adap->fe[0]->ops.read_ucblocks; | |
743ab6a1 MP |
1106 | |
1107 | adap->fe[0]->ops.read_status = dm04_read_status; | |
d8bad1e2 MP |
1108 | adap->fe[0]->ops.read_signal_strength = dm04_read_signal_strength; |
1109 | adap->fe[0]->ops.read_snr = dm04_read_snr; | |
1110 | adap->fe[0]->ops.read_ber = dm04_read_ber; | |
1111 | adap->fe[0]->ops.read_ucblocks = dm04_read_ucblocks; | |
e41543a2 | 1112 | adap->fe[0]->ops.set_voltage = dm04_lme2510_set_voltage; |
d8bad1e2 | 1113 | |
75aecc3a | 1114 | ret = lme_name(adap); |
75aecc3a MP |
1115 | return ret; |
1116 | } | |
1117 | ||
1118 | static int dm04_lme2510_tuner(struct dvb_usb_adapter *adap) | |
1119 | { | |
e41543a2 MP |
1120 | struct dvb_usb_device *d = adap_to_d(adap); |
1121 | struct lme2510_state *st = adap_to_priv(adap); | |
bfe17178 | 1122 | static const char * const tun_msg[] = {"", "TDA8263", "IX2505V", "DVB_PLL_OPERA", "RS2000"}; |
75aecc3a MP |
1123 | int ret = 0; |
1124 | ||
1125 | switch (st->tuner_config) { | |
1126 | case TUNER_LG: | |
71dc98be | 1127 | if (dvb_attach(tda826x_attach, adap->fe[0], 0x60, |
e41543a2 | 1128 | &d->i2c_adap, 1)) |
75aecc3a MP |
1129 | ret = st->tuner_config; |
1130 | break; | |
1131 | case TUNER_S7395: | |
e41543a2 MP |
1132 | if (dvb_attach(ix2505v_attach , adap->fe[0], &lme_tuner, |
1133 | &d->i2c_adap)) | |
75aecc3a MP |
1134 | ret = st->tuner_config; |
1135 | break; | |
9d4540c9 | 1136 | case TUNER_S0194: |
71dc98be | 1137 | if (dvb_attach(dvb_pll_attach , adap->fe[0], 0x60, |
e41543a2 | 1138 | &d->i2c_adap, DVB_PLL_OPERA1)) |
9d4540c9 MP |
1139 | ret = st->tuner_config; |
1140 | break; | |
4f3b7fed MP |
1141 | case TUNER_RS2000: |
1142 | ret = st->tuner_config; | |
1143 | break; | |
75aecc3a MP |
1144 | default: |
1145 | break; | |
1146 | } | |
1147 | ||
1148 | if (ret) | |
1149 | info("TUN Found %s tuner", tun_msg[ret]); | |
1150 | else { | |
0d616ca3 | 1151 | info("TUN No tuner found --- resetting device"); |
e41543a2 | 1152 | lme_coldreset(d); |
75aecc3a MP |
1153 | return -ENODEV; |
1154 | } | |
1155 | ||
616a4b83 MP |
1156 | /* Start the Interrupt*/ |
1157 | ret = lme2510_int_read(adap); | |
1158 | if (ret < 0) { | |
1159 | info("INT Unable to start Interrupt Service"); | |
1160 | return -ENODEV; | |
1161 | } | |
75aecc3a MP |
1162 | |
1163 | return ret; | |
d2f918bb MP |
1164 | } |
1165 | ||
1166 | static int lme2510_powerup(struct dvb_usb_device *d, int onoff) | |
1167 | { | |
1168 | struct lme2510_state *st = d->priv; | |
f23e6616 MP |
1169 | static u8 lnb_on[] = LNB_ON; |
1170 | static u8 lnb_off[] = LNB_OFF; | |
1171 | static u8 rbuf[1]; | |
4f3b7fed | 1172 | int ret = 0, len = 3, rlen = 1; |
f23e6616 | 1173 | |
4f3b7fed | 1174 | mutex_lock(&d->i2c_mutex); |
f23e6616 | 1175 | |
974eadf1 | 1176 | ret = lme2510_usb_talk(d, onoff ? lnb_on : lnb_off, len, rbuf, rlen); |
f23e6616 | 1177 | |
d2f918bb | 1178 | st->i2c_talk_onoff = 1; |
f23e6616 MP |
1179 | |
1180 | mutex_unlock(&d->i2c_mutex); | |
1181 | ||
1182 | return ret; | |
d2f918bb MP |
1183 | } |
1184 | ||
e41543a2 | 1185 | static int lme2510_get_adapter_count(struct dvb_usb_device *d) |
d2f918bb | 1186 | { |
e41543a2 MP |
1187 | return 1; |
1188 | } | |
d2f918bb | 1189 | |
e41543a2 MP |
1190 | static int lme2510_identify_state(struct dvb_usb_device *d, const char **name) |
1191 | { | |
1192 | struct lme2510_state *st = d->priv; | |
d2f918bb | 1193 | |
e41543a2 | 1194 | usb_reset_configuration(d->udev); |
d2f918bb | 1195 | |
e41543a2 | 1196 | usb_set_interface(d->udev, |
e42efde4 | 1197 | d->props->bInterfaceNumber, 1); |
d2f918bb | 1198 | |
e41543a2 | 1199 | st->dvb_usb_lme2510_firmware = dvb_usb_lme2510_firmware; |
ab599a6d | 1200 | |
e41543a2 MP |
1201 | if (lme2510_return_status(d) == 0x44) { |
1202 | *name = lme_firmware_switch(d, 0); | |
1203 | return COLD; | |
d2f918bb MP |
1204 | } |
1205 | ||
e41543a2 | 1206 | return 0; |
d2f918bb MP |
1207 | } |
1208 | ||
e41543a2 MP |
1209 | static int lme2510_get_stream_config(struct dvb_frontend *fe, u8 *ts_type, |
1210 | struct usb_data_stream_properties *stream) | |
1211 | { | |
1212 | struct dvb_usb_adapter *adap = fe_to_adap(fe); | |
06f950f4 | 1213 | struct dvb_usb_device *d; |
d2f918bb | 1214 | |
e41543a2 MP |
1215 | if (adap == NULL) |
1216 | return 0; | |
06f950f4 SS |
1217 | |
1218 | d = adap_to_d(adap); | |
1219 | ||
e41543a2 MP |
1220 | /* Turn PID filter on the fly by module option */ |
1221 | if (pid_filter == 2) { | |
235d89ec | 1222 | adap->pid_filtering = true; |
e41543a2 | 1223 | adap->max_feed_count = 15; |
d2f918bb | 1224 | } |
d2f918bb | 1225 | |
e41543a2 MP |
1226 | if (!(le16_to_cpu(d->udev->descriptor.idProduct) |
1227 | == 0x1122)) | |
1228 | stream->endpoint = 0x8; | |
d2f918bb | 1229 | |
e41543a2 MP |
1230 | return 0; |
1231 | } | |
1232 | ||
1233 | static int lme2510_get_rc_config(struct dvb_usb_device *d, | |
1234 | struct dvb_usb_rc *rc) | |
1235 | { | |
2ceeca04 | 1236 | rc->allowed_protos = RC_BIT_NEC32; |
e41543a2 MP |
1237 | return 0; |
1238 | } | |
d2f918bb | 1239 | |
a760d638 | 1240 | static void *lme2510_exit_int(struct dvb_usb_device *d) |
d2f918bb MP |
1241 | { |
1242 | struct lme2510_state *st = d->priv; | |
ab599a6d MP |
1243 | struct dvb_usb_adapter *adap = &d->adapter[0]; |
1244 | void *buffer = NULL; | |
1245 | ||
1246 | if (adap != NULL) { | |
e41543a2 | 1247 | lme2510_kill_urb(&adap->stream); |
ab599a6d MP |
1248 | } |
1249 | ||
616a4b83 | 1250 | if (st->usb_buffer != NULL) { |
ab599a6d | 1251 | st->i2c_talk_onoff = 1; |
d2f918bb MP |
1252 | st->signal_level = 0; |
1253 | st->signal_sn = 0; | |
ab599a6d | 1254 | buffer = st->usb_buffer; |
616a4b83 MP |
1255 | } |
1256 | ||
1257 | if (st->lme_urb != NULL) { | |
d2f918bb | 1258 | usb_kill_urb(st->lme_urb); |
95c21c41 | 1259 | usb_free_coherent(d->udev, 128, st->buffer, |
d2f918bb | 1260 | st->lme_urb->transfer_dma); |
25985edc | 1261 | info("Interrupt Service Stopped"); |
d2f918bb | 1262 | } |
616a4b83 | 1263 | |
ab599a6d | 1264 | return buffer; |
d2f918bb MP |
1265 | } |
1266 | ||
e41543a2 | 1267 | static void lme2510_exit(struct dvb_usb_device *d) |
d2f918bb | 1268 | { |
ab599a6d MP |
1269 | void *usb_buffer; |
1270 | ||
d2f918bb | 1271 | if (d != NULL) { |
ab599a6d | 1272 | usb_buffer = lme2510_exit_int(d); |
72873e51 | 1273 | kfree(usb_buffer); |
d2f918bb | 1274 | } |
d2f918bb MP |
1275 | } |
1276 | ||
e41543a2 MP |
1277 | static struct dvb_usb_device_properties lme2510_props = { |
1278 | .driver_name = KBUILD_MODNAME, | |
1279 | .owner = THIS_MODULE, | |
1280 | .bInterfaceNumber = 0, | |
1281 | .adapter_nr = adapter_nr, | |
1282 | .size_of_priv = sizeof(struct lme2510_state), | |
1283 | ||
1284 | .download_firmware = lme2510_download_firmware, | |
1285 | ||
1286 | .power_ctrl = lme2510_powerup, | |
1287 | .identify_state = lme2510_identify_state, | |
1288 | .i2c_algo = &lme2510_i2c_algo, | |
1289 | ||
1290 | .frontend_attach = dm04_lme2510_frontend_attach, | |
1291 | .tuner_attach = dm04_lme2510_tuner, | |
1292 | .get_stream_config = lme2510_get_stream_config, | |
1293 | .get_adapter_count = lme2510_get_adapter_count, | |
1294 | .streaming_ctrl = lme2510_streaming_ctrl, | |
1295 | ||
1296 | .get_rc_config = lme2510_get_rc_config, | |
1297 | ||
1298 | .exit = lme2510_exit, | |
1299 | .adapter = { | |
1300 | { | |
1301 | .caps = DVB_USB_ADAP_HAS_PID_FILTER| | |
1302 | DVB_USB_ADAP_PID_FILTER_CAN_BE_TURNED_OFF, | |
1303 | .pid_filter_count = 15, | |
1304 | .pid_filter = lme2510_pid_filter, | |
1305 | .pid_filter_ctrl = lme2510_pid_filter_ctrl, | |
1306 | .stream = | |
1307 | DVB_USB_STREAM_BULK(0x86, 10, 4096), | |
1308 | }, | |
1309 | { | |
1310 | } | |
1311 | }, | |
1312 | }; | |
1313 | ||
1314 | static const struct usb_device_id lme2510_id_table[] = { | |
1315 | { DVB_USB_DEVICE(0x3344, 0x1122, &lme2510_props, | |
1316 | "DM04_LME2510_DVB-S", RC_MAP_LME2510) }, | |
1317 | { DVB_USB_DEVICE(0x3344, 0x1120, &lme2510_props, | |
1318 | "DM04_LME2510C_DVB-S", RC_MAP_LME2510) }, | |
1319 | { DVB_USB_DEVICE(0x3344, 0x22f0, &lme2510_props, | |
1320 | "DM04_LME2510C_DVB-S RS2000", RC_MAP_LME2510) }, | |
1321 | {} /* Terminating entry */ | |
1322 | }; | |
1323 | ||
1324 | MODULE_DEVICE_TABLE(usb, lme2510_id_table); | |
1325 | ||
d2f918bb | 1326 | static struct usb_driver lme2510_driver = { |
e41543a2 MP |
1327 | .name = KBUILD_MODNAME, |
1328 | .probe = dvb_usbv2_probe, | |
1329 | .disconnect = dvb_usbv2_disconnect, | |
1330 | .id_table = lme2510_id_table, | |
1331 | .no_dynamic_id = 1, | |
1332 | .soft_unbind = 1, | |
d2f918bb MP |
1333 | }; |
1334 | ||
ecb3b2b3 | 1335 | module_usb_driver(lme2510_driver); |
d2f918bb MP |
1336 | |
1337 | MODULE_AUTHOR("Malcolm Priestley <tvboxspy@gmail.com>"); | |
75aecc3a | 1338 | MODULE_DESCRIPTION("LME2510(C) DVB-S USB2.0"); |
f459aec2 | 1339 | MODULE_VERSION("2.07"); |
d2f918bb | 1340 | MODULE_LICENSE("GPL"); |
e41543a2 MP |
1341 | MODULE_FIRMWARE(LME2510_C_S7395); |
1342 | MODULE_FIRMWARE(LME2510_C_LG); | |
1343 | MODULE_FIRMWARE(LME2510_C_S0194); | |
1344 | MODULE_FIRMWARE(LME2510_C_RS2000); | |
1345 | MODULE_FIRMWARE(LME2510_LG); | |
1346 | MODULE_FIRMWARE(LME2510_S0194); | |
1347 |