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