lmedm04.c 32 KB

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