lmedm04.c 31 KB

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