lmedm04.c 31 KB

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