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