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