dvb-ttusb-budget.c 43 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820
  1. /*
  2. * TTUSB DVB driver
  3. *
  4. * Copyright (c) 2002 Holger Waechtler <holger@convergence.de>
  5. * Copyright (c) 2003 Felix Domke <tmbinc@elitedvb.net>
  6. *
  7. * This program is free software; you can redistribute it and/or
  8. * modify it under the terms of the GNU General Public License as
  9. * published by the Free Software Foundation; either version 2 of
  10. * the License, or (at your option) any later version.
  11. */
  12. #include <linux/init.h>
  13. #include <linux/slab.h>
  14. #include <linux/wait.h>
  15. #include <linux/fs.h>
  16. #include <linux/module.h>
  17. #include <linux/usb.h>
  18. #include <linux/delay.h>
  19. #include <linux/time.h>
  20. #include <linux/errno.h>
  21. #include <linux/jiffies.h>
  22. #include <linux/mutex.h>
  23. #include <linux/firmware.h>
  24. #include "dvb_frontend.h"
  25. #include "dmxdev.h"
  26. #include "dvb_demux.h"
  27. #include "dvb_net.h"
  28. #include "ves1820.h"
  29. #include "cx22700.h"
  30. #include "tda1004x.h"
  31. #include "stv0299.h"
  32. #include "tda8083.h"
  33. #include "stv0297.h"
  34. #include "lnbp21.h"
  35. #include <linux/dvb/frontend.h>
  36. #include <linux/dvb/dmx.h>
  37. #include <linux/pci.h>
  38. /*
  39. TTUSB_HWSECTIONS:
  40. the DSP supports filtering in hardware, however, since the "muxstream"
  41. is a bit braindead (no matching channel masks or no matching filter mask),
  42. we won't support this - yet. it doesn't event support negative filters,
  43. so the best way is maybe to keep TTUSB_HWSECTIONS undef'd and just
  44. parse TS data. USB bandwidth will be a problem when having large
  45. datastreams, especially for dvb-net, but hey, that's not my problem.
  46. TTUSB_DISEQC, TTUSB_TONE:
  47. let the STC do the diseqc/tone stuff. this isn't supported at least with
  48. my TTUSB, so let it undef'd unless you want to implement another
  49. frontend. never tested.
  50. debug:
  51. define it to > 3 for really hardcore debugging. you probably don't want
  52. this unless the device doesn't load at all. > 2 for bandwidth statistics.
  53. */
  54. static int debug;
  55. module_param(debug, int, 0644);
  56. MODULE_PARM_DESC(debug, "Turn on/off debugging (default:off).");
  57. DVB_DEFINE_MOD_OPT_ADAPTER_NR(adapter_nr);
  58. #define dprintk(x...) do { if (debug) printk(KERN_DEBUG x); } while (0)
  59. #define ISO_BUF_COUNT 4
  60. #define FRAMES_PER_ISO_BUF 4
  61. #define ISO_FRAME_SIZE 912
  62. #define TTUSB_MAXCHANNEL 32
  63. #ifdef TTUSB_HWSECTIONS
  64. #define TTUSB_MAXFILTER 16 /* ??? */
  65. #endif
  66. #define TTUSB_REV_2_2 0x22
  67. #define TTUSB_BUDGET_NAME "ttusb_stc_fw"
  68. /**
  69. * since we're casting (struct ttusb*) <-> (struct dvb_demux*) around
  70. * the dvb_demux field must be the first in struct!!
  71. */
  72. struct ttusb {
  73. struct dvb_demux dvb_demux;
  74. struct dmxdev dmxdev;
  75. struct dvb_net dvbnet;
  76. /* and one for USB access. */
  77. struct mutex semi2c;
  78. struct mutex semusb;
  79. struct dvb_adapter adapter;
  80. struct usb_device *dev;
  81. struct i2c_adapter i2c_adap;
  82. int disconnecting;
  83. int iso_streaming;
  84. unsigned int bulk_out_pipe;
  85. unsigned int bulk_in_pipe;
  86. unsigned int isoc_in_pipe;
  87. void *iso_buffer;
  88. dma_addr_t iso_dma_handle;
  89. struct urb *iso_urb[ISO_BUF_COUNT];
  90. int running_feed_count;
  91. int last_channel;
  92. int last_filter;
  93. u8 c; /* transaction counter, wraps around... */
  94. enum fe_sec_tone_mode tone;
  95. enum fe_sec_voltage voltage;
  96. int mux_state; // 0..2 - MuxSyncWord, 3 - nMuxPacks, 4 - muxpack
  97. u8 mux_npacks;
  98. u8 muxpack[256 + 8];
  99. int muxpack_ptr, muxpack_len;
  100. int insync;
  101. int cc; /* MuxCounter - will increment on EVERY MUX PACKET */
  102. /* (including stuffing. yes. really.) */
  103. u8 last_result[32];
  104. int revision;
  105. struct dvb_frontend* fe;
  106. };
  107. /* ugly workaround ... don't know why it's necessary to read */
  108. /* all result codes. */
  109. static int ttusb_cmd(struct ttusb *ttusb,
  110. const u8 * data, int len, int needresult)
  111. {
  112. int actual_len;
  113. int err;
  114. int i;
  115. if (debug >= 3) {
  116. printk(KERN_DEBUG ">");
  117. for (i = 0; i < len; ++i)
  118. printk(KERN_CONT " %02x", data[i]);
  119. printk(KERN_CONT "\n");
  120. }
  121. if (mutex_lock_interruptible(&ttusb->semusb) < 0)
  122. return -EAGAIN;
  123. err = usb_bulk_msg(ttusb->dev, ttusb->bulk_out_pipe,
  124. (u8 *) data, len, &actual_len, 1000);
  125. if (err != 0) {
  126. dprintk("%s: usb_bulk_msg(send) failed, err == %i!\n",
  127. __func__, err);
  128. mutex_unlock(&ttusb->semusb);
  129. return err;
  130. }
  131. if (actual_len != len) {
  132. dprintk("%s: only wrote %d of %d bytes\n", __func__,
  133. actual_len, len);
  134. mutex_unlock(&ttusb->semusb);
  135. return -1;
  136. }
  137. err = usb_bulk_msg(ttusb->dev, ttusb->bulk_in_pipe,
  138. ttusb->last_result, 32, &actual_len, 1000);
  139. if (err != 0) {
  140. printk("%s: failed, receive error %d\n", __func__,
  141. err);
  142. mutex_unlock(&ttusb->semusb);
  143. return err;
  144. }
  145. if (debug >= 3) {
  146. actual_len = ttusb->last_result[3] + 4;
  147. printk(KERN_DEBUG "<");
  148. for (i = 0; i < actual_len; ++i)
  149. printk(KERN_CONT " %02x", ttusb->last_result[i]);
  150. printk(KERN_CONT "\n");
  151. }
  152. if (!needresult)
  153. mutex_unlock(&ttusb->semusb);
  154. return 0;
  155. }
  156. static int ttusb_result(struct ttusb *ttusb, u8 * data, int len)
  157. {
  158. memcpy(data, ttusb->last_result, len);
  159. mutex_unlock(&ttusb->semusb);
  160. return 0;
  161. }
  162. static int ttusb_i2c_msg(struct ttusb *ttusb,
  163. u8 addr, u8 * snd_buf, u8 snd_len, u8 * rcv_buf,
  164. u8 rcv_len)
  165. {
  166. u8 b[0x28];
  167. u8 id = ++ttusb->c;
  168. int i, err;
  169. if (snd_len > 0x28 - 7 || rcv_len > 0x20 - 7)
  170. return -EINVAL;
  171. b[0] = 0xaa;
  172. b[1] = id;
  173. b[2] = 0x31;
  174. b[3] = snd_len + 3;
  175. b[4] = addr << 1;
  176. b[5] = snd_len;
  177. b[6] = rcv_len;
  178. for (i = 0; i < snd_len; i++)
  179. b[7 + i] = snd_buf[i];
  180. err = ttusb_cmd(ttusb, b, snd_len + 7, 1);
  181. if (err)
  182. return -EREMOTEIO;
  183. err = ttusb_result(ttusb, b, 0x20);
  184. /* check if the i2c transaction was successful */
  185. if ((snd_len != b[5]) || (rcv_len != b[6])) return -EREMOTEIO;
  186. if (rcv_len > 0) {
  187. if (err || b[0] != 0x55 || b[1] != id) {
  188. dprintk
  189. ("%s: usb_bulk_msg(recv) failed, err == %i, id == %02x, b == ",
  190. __func__, err, id);
  191. return -EREMOTEIO;
  192. }
  193. for (i = 0; i < rcv_len; i++)
  194. rcv_buf[i] = b[7 + i];
  195. }
  196. return rcv_len;
  197. }
  198. static int master_xfer(struct i2c_adapter* adapter, struct i2c_msg *msg, int num)
  199. {
  200. struct ttusb *ttusb = i2c_get_adapdata(adapter);
  201. int i = 0;
  202. int inc;
  203. if (mutex_lock_interruptible(&ttusb->semi2c) < 0)
  204. return -EAGAIN;
  205. while (i < num) {
  206. u8 addr, snd_len, rcv_len, *snd_buf, *rcv_buf;
  207. int err;
  208. if (num > i + 1 && (msg[i + 1].flags & I2C_M_RD)) {
  209. addr = msg[i].addr;
  210. snd_buf = msg[i].buf;
  211. snd_len = msg[i].len;
  212. rcv_buf = msg[i + 1].buf;
  213. rcv_len = msg[i + 1].len;
  214. inc = 2;
  215. } else {
  216. addr = msg[i].addr;
  217. snd_buf = msg[i].buf;
  218. snd_len = msg[i].len;
  219. rcv_buf = NULL;
  220. rcv_len = 0;
  221. inc = 1;
  222. }
  223. err = ttusb_i2c_msg(ttusb, addr,
  224. snd_buf, snd_len, rcv_buf, rcv_len);
  225. if (err < rcv_len) {
  226. dprintk("%s: i == %i\n", __func__, i);
  227. break;
  228. }
  229. i += inc;
  230. }
  231. mutex_unlock(&ttusb->semi2c);
  232. return i;
  233. }
  234. static int ttusb_boot_dsp(struct ttusb *ttusb)
  235. {
  236. const struct firmware *fw;
  237. int i, err;
  238. u8 b[40];
  239. err = request_firmware(&fw, "ttusb-budget/dspbootcode.bin",
  240. &ttusb->dev->dev);
  241. if (err) {
  242. printk(KERN_ERR "ttusb-budget: failed to request firmware\n");
  243. return err;
  244. }
  245. /* BootBlock */
  246. b[0] = 0xaa;
  247. b[2] = 0x13;
  248. b[3] = 28;
  249. /* upload dsp code in 32 byte steps (36 didn't work for me ...) */
  250. /* 32 is max packet size, no messages should be splitted. */
  251. for (i = 0; i < fw->size; i += 28) {
  252. memcpy(&b[4], &fw->data[i], 28);
  253. b[1] = ++ttusb->c;
  254. err = ttusb_cmd(ttusb, b, 32, 0);
  255. if (err)
  256. goto done;
  257. }
  258. /* last block ... */
  259. b[1] = ++ttusb->c;
  260. b[2] = 0x13;
  261. b[3] = 0;
  262. err = ttusb_cmd(ttusb, b, 4, 0);
  263. if (err)
  264. goto done;
  265. /* BootEnd */
  266. b[1] = ++ttusb->c;
  267. b[2] = 0x14;
  268. b[3] = 0;
  269. err = ttusb_cmd(ttusb, b, 4, 0);
  270. done:
  271. release_firmware(fw);
  272. if (err) {
  273. dprintk("%s: usb_bulk_msg() failed, return value %i!\n",
  274. __func__, err);
  275. }
  276. return err;
  277. }
  278. static int ttusb_set_channel(struct ttusb *ttusb, int chan_id, int filter_type,
  279. int pid)
  280. {
  281. int err;
  282. /* SetChannel */
  283. u8 b[] = { 0xaa, ++ttusb->c, 0x22, 4, chan_id, filter_type,
  284. (pid >> 8) & 0xff, pid & 0xff
  285. };
  286. err = ttusb_cmd(ttusb, b, sizeof(b), 0);
  287. return err;
  288. }
  289. static int ttusb_del_channel(struct ttusb *ttusb, int channel_id)
  290. {
  291. int err;
  292. /* DelChannel */
  293. u8 b[] = { 0xaa, ++ttusb->c, 0x23, 1, channel_id };
  294. err = ttusb_cmd(ttusb, b, sizeof(b), 0);
  295. return err;
  296. }
  297. #ifdef TTUSB_HWSECTIONS
  298. static int ttusb_set_filter(struct ttusb *ttusb, int filter_id,
  299. int associated_chan, u8 filter[8], u8 mask[8])
  300. {
  301. int err;
  302. /* SetFilter */
  303. u8 b[] = { 0xaa, 0, 0x24, 0x1a, filter_id, associated_chan,
  304. filter[0], filter[1], filter[2], filter[3],
  305. filter[4], filter[5], filter[6], filter[7],
  306. filter[8], filter[9], filter[10], filter[11],
  307. mask[0], mask[1], mask[2], mask[3],
  308. mask[4], mask[5], mask[6], mask[7],
  309. mask[8], mask[9], mask[10], mask[11]
  310. };
  311. err = ttusb_cmd(ttusb, b, sizeof(b), 0);
  312. return err;
  313. }
  314. static int ttusb_del_filter(struct ttusb *ttusb, int filter_id)
  315. {
  316. int err;
  317. /* DelFilter */
  318. u8 b[] = { 0xaa, ++ttusb->c, 0x25, 1, filter_id };
  319. err = ttusb_cmd(ttusb, b, sizeof(b), 0);
  320. return err;
  321. }
  322. #endif
  323. static int ttusb_init_controller(struct ttusb *ttusb)
  324. {
  325. u8 b0[] = { 0xaa, ++ttusb->c, 0x15, 1, 0 };
  326. u8 b1[] = { 0xaa, ++ttusb->c, 0x15, 1, 1 };
  327. u8 b2[] = { 0xaa, ++ttusb->c, 0x32, 1, 0 };
  328. /* i2c write read: 5 bytes, addr 0x10, 0x02 bytes write, 1 bytes read. */
  329. u8 b3[] =
  330. { 0xaa, ++ttusb->c, 0x31, 5, 0x10, 0x02, 0x01, 0x00, 0x1e };
  331. u8 b4[] =
  332. { 0x55, ttusb->c, 0x31, 4, 0x10, 0x02, 0x01, 0x00, 0x1e };
  333. u8 get_version[] = { 0xaa, ++ttusb->c, 0x17, 5, 0, 0, 0, 0, 0 };
  334. u8 get_dsp_version[0x20] =
  335. { 0xaa, ++ttusb->c, 0x26, 28, 0, 0, 0, 0, 0 };
  336. int err;
  337. /* reset board */
  338. if ((err = ttusb_cmd(ttusb, b0, sizeof(b0), 0)))
  339. return err;
  340. /* reset board (again?) */
  341. if ((err = ttusb_cmd(ttusb, b1, sizeof(b1), 0)))
  342. return err;
  343. ttusb_boot_dsp(ttusb);
  344. /* set i2c bit rate */
  345. if ((err = ttusb_cmd(ttusb, b2, sizeof(b2), 0)))
  346. return err;
  347. if ((err = ttusb_cmd(ttusb, b3, sizeof(b3), 1)))
  348. return err;
  349. err = ttusb_result(ttusb, b4, sizeof(b4));
  350. if ((err = ttusb_cmd(ttusb, get_version, sizeof(get_version), 1)))
  351. return err;
  352. if ((err = ttusb_result(ttusb, get_version, sizeof(get_version))))
  353. return err;
  354. dprintk("%s: stc-version: %c%c%c%c%c\n", __func__,
  355. get_version[4], get_version[5], get_version[6],
  356. get_version[7], get_version[8]);
  357. if (memcmp(get_version + 4, "V 0.0", 5) &&
  358. memcmp(get_version + 4, "V 1.1", 5) &&
  359. memcmp(get_version + 4, "V 2.1", 5) &&
  360. memcmp(get_version + 4, "V 2.2", 5)) {
  361. printk
  362. ("%s: unknown STC version %c%c%c%c%c, please report!\n",
  363. __func__, get_version[4], get_version[5],
  364. get_version[6], get_version[7], get_version[8]);
  365. }
  366. ttusb->revision = ((get_version[6] - '0') << 4) |
  367. (get_version[8] - '0');
  368. err =
  369. ttusb_cmd(ttusb, get_dsp_version, sizeof(get_dsp_version), 1);
  370. if (err)
  371. return err;
  372. err =
  373. ttusb_result(ttusb, get_dsp_version, sizeof(get_dsp_version));
  374. if (err)
  375. return err;
  376. printk("%s: dsp-version: %c%c%c\n", __func__,
  377. get_dsp_version[4], get_dsp_version[5], get_dsp_version[6]);
  378. return 0;
  379. }
  380. #ifdef TTUSB_DISEQC
  381. static int ttusb_send_diseqc(struct dvb_frontend* fe,
  382. const struct dvb_diseqc_master_cmd *cmd)
  383. {
  384. struct ttusb* ttusb = (struct ttusb*) fe->dvb->priv;
  385. u8 b[12] = { 0xaa, ++ttusb->c, 0x18 };
  386. int err;
  387. b[3] = 4 + 2 + cmd->msg_len;
  388. b[4] = 0xFF; /* send diseqc master, not burst */
  389. b[5] = cmd->msg_len;
  390. memcpy(b + 5, cmd->msg, cmd->msg_len);
  391. /* Diseqc */
  392. if ((err = ttusb_cmd(ttusb, b, 4 + b[3], 0))) {
  393. dprintk("%s: usb_bulk_msg() failed, return value %i!\n",
  394. __func__, err);
  395. }
  396. return err;
  397. }
  398. #endif
  399. static int ttusb_update_lnb(struct ttusb *ttusb)
  400. {
  401. u8 b[] = { 0xaa, ++ttusb->c, 0x16, 5, /*power: */ 1,
  402. ttusb->voltage == SEC_VOLTAGE_18 ? 0 : 1,
  403. ttusb->tone == SEC_TONE_ON ? 1 : 0, 1, 1
  404. };
  405. int err;
  406. /* SetLNB */
  407. if ((err = ttusb_cmd(ttusb, b, sizeof(b), 0))) {
  408. dprintk("%s: usb_bulk_msg() failed, return value %i!\n",
  409. __func__, err);
  410. }
  411. return err;
  412. }
  413. static int ttusb_set_voltage(struct dvb_frontend *fe,
  414. enum fe_sec_voltage voltage)
  415. {
  416. struct ttusb* ttusb = (struct ttusb*) fe->dvb->priv;
  417. ttusb->voltage = voltage;
  418. return ttusb_update_lnb(ttusb);
  419. }
  420. #ifdef TTUSB_TONE
  421. static int ttusb_set_tone(struct dvb_frontend *fe, enum fe_sec_tone_mode tone)
  422. {
  423. struct ttusb* ttusb = (struct ttusb*) fe->dvb->priv;
  424. ttusb->tone = tone;
  425. return ttusb_update_lnb(ttusb);
  426. }
  427. #endif
  428. #if 0
  429. static void ttusb_set_led_freq(struct ttusb *ttusb, u8 freq)
  430. {
  431. u8 b[] = { 0xaa, ++ttusb->c, 0x19, 1, freq };
  432. int err, actual_len;
  433. err = ttusb_cmd(ttusb, b, sizeof(b), 0);
  434. if (err) {
  435. dprintk("%s: usb_bulk_msg() failed, return value %i!\n",
  436. __func__, err);
  437. }
  438. }
  439. #endif
  440. /*****************************************************************************/
  441. #ifdef TTUSB_HWSECTIONS
  442. static void ttusb_handle_ts_data(struct ttusb_channel *channel,
  443. const u8 * data, int len);
  444. static void ttusb_handle_sec_data(struct ttusb_channel *channel,
  445. const u8 * data, int len);
  446. #endif
  447. static int numpkt, numts, numstuff, numsec, numinvalid;
  448. static unsigned long lastj;
  449. static void ttusb_process_muxpack(struct ttusb *ttusb, const u8 * muxpack,
  450. int len)
  451. {
  452. u16 csum = 0, cc;
  453. int i;
  454. if (len < 4 || len & 0x1) {
  455. pr_warn("%s: muxpack has invalid len %d\n", __func__, len);
  456. numinvalid++;
  457. return;
  458. }
  459. for (i = 0; i < len; i += 2)
  460. csum ^= le16_to_cpup((__le16 *) (muxpack + i));
  461. if (csum) {
  462. printk("%s: muxpack with incorrect checksum, ignoring\n",
  463. __func__);
  464. numinvalid++;
  465. return;
  466. }
  467. cc = (muxpack[len - 4] << 8) | muxpack[len - 3];
  468. cc &= 0x7FFF;
  469. if ((cc != ttusb->cc) && (ttusb->cc != -1))
  470. printk("%s: cc discontinuity (%d frames missing)\n",
  471. __func__, (cc - ttusb->cc) & 0x7FFF);
  472. ttusb->cc = (cc + 1) & 0x7FFF;
  473. if (muxpack[0] & 0x80) {
  474. #ifdef TTUSB_HWSECTIONS
  475. /* section data */
  476. int pusi = muxpack[0] & 0x40;
  477. int channel = muxpack[0] & 0x1F;
  478. int payload = muxpack[1];
  479. const u8 *data = muxpack + 2;
  480. /* check offset flag */
  481. if (muxpack[0] & 0x20)
  482. data++;
  483. ttusb_handle_sec_data(ttusb->channel + channel, data,
  484. payload);
  485. data += payload;
  486. if ((!!(ttusb->muxpack[0] & 0x20)) ^
  487. !!(ttusb->muxpack[1] & 1))
  488. data++;
  489. #warning TODO: pusi
  490. printk("cc: %04x\n", (data[0] << 8) | data[1]);
  491. #endif
  492. numsec++;
  493. } else if (muxpack[0] == 0x47) {
  494. #ifdef TTUSB_HWSECTIONS
  495. /* we have TS data here! */
  496. int pid = ((muxpack[1] & 0x0F) << 8) | muxpack[2];
  497. int channel;
  498. for (channel = 0; channel < TTUSB_MAXCHANNEL; ++channel)
  499. if (ttusb->channel[channel].active
  500. && (pid == ttusb->channel[channel].pid))
  501. ttusb_handle_ts_data(ttusb->channel +
  502. channel, muxpack,
  503. 188);
  504. #endif
  505. numts++;
  506. dvb_dmx_swfilter_packets(&ttusb->dvb_demux, muxpack, 1);
  507. } else if (muxpack[0] != 0) {
  508. numinvalid++;
  509. printk("illegal muxpack type %02x\n", muxpack[0]);
  510. } else
  511. numstuff++;
  512. }
  513. static void ttusb_process_frame(struct ttusb *ttusb, u8 * data, int len)
  514. {
  515. int maxwork = 1024;
  516. while (len) {
  517. if (!(maxwork--)) {
  518. printk("%s: too much work\n", __func__);
  519. break;
  520. }
  521. switch (ttusb->mux_state) {
  522. case 0:
  523. case 1:
  524. case 2:
  525. len--;
  526. if (*data++ == 0xAA)
  527. ++ttusb->mux_state;
  528. else {
  529. ttusb->mux_state = 0;
  530. if (ttusb->insync) {
  531. dprintk("%s: %02x\n",
  532. __func__, data[-1]);
  533. printk(KERN_INFO "%s: lost sync.\n",
  534. __func__);
  535. ttusb->insync = 0;
  536. }
  537. }
  538. break;
  539. case 3:
  540. ttusb->insync = 1;
  541. len--;
  542. ttusb->mux_npacks = *data++;
  543. ++ttusb->mux_state;
  544. ttusb->muxpack_ptr = 0;
  545. /* maximum bytes, until we know the length */
  546. ttusb->muxpack_len = 2;
  547. break;
  548. case 4:
  549. {
  550. int avail;
  551. avail = len;
  552. if (avail >
  553. (ttusb->muxpack_len -
  554. ttusb->muxpack_ptr))
  555. avail =
  556. ttusb->muxpack_len -
  557. ttusb->muxpack_ptr;
  558. memcpy(ttusb->muxpack + ttusb->muxpack_ptr,
  559. data, avail);
  560. ttusb->muxpack_ptr += avail;
  561. BUG_ON(ttusb->muxpack_ptr > 264);
  562. data += avail;
  563. len -= avail;
  564. /* determine length */
  565. if (ttusb->muxpack_ptr == 2) {
  566. if (ttusb->muxpack[0] & 0x80) {
  567. ttusb->muxpack_len =
  568. ttusb->muxpack[1] + 2;
  569. if (ttusb->
  570. muxpack[0] & 0x20)
  571. ttusb->
  572. muxpack_len++;
  573. if ((!!
  574. (ttusb->
  575. muxpack[0] & 0x20)) ^
  576. !!(ttusb->
  577. muxpack[1] & 1))
  578. ttusb->
  579. muxpack_len++;
  580. ttusb->muxpack_len += 4;
  581. } else if (ttusb->muxpack[0] ==
  582. 0x47)
  583. ttusb->muxpack_len =
  584. 188 + 4;
  585. else if (ttusb->muxpack[0] == 0x00)
  586. ttusb->muxpack_len =
  587. ttusb->muxpack[1] + 2 +
  588. 4;
  589. else {
  590. dprintk
  591. ("%s: invalid state: first byte is %x\n",
  592. __func__,
  593. ttusb->muxpack[0]);
  594. ttusb->mux_state = 0;
  595. }
  596. }
  597. /**
  598. * if length is valid and we reached the end:
  599. * goto next muxpack
  600. */
  601. if ((ttusb->muxpack_ptr >= 2) &&
  602. (ttusb->muxpack_ptr ==
  603. ttusb->muxpack_len)) {
  604. ttusb_process_muxpack(ttusb,
  605. ttusb->
  606. muxpack,
  607. ttusb->
  608. muxpack_ptr);
  609. ttusb->muxpack_ptr = 0;
  610. /* maximum bytes, until we know the length */
  611. ttusb->muxpack_len = 2;
  612. /**
  613. * no muxpacks left?
  614. * return to search-sync state
  615. */
  616. if (!ttusb->mux_npacks--) {
  617. ttusb->mux_state = 0;
  618. break;
  619. }
  620. }
  621. break;
  622. }
  623. default:
  624. BUG();
  625. break;
  626. }
  627. }
  628. }
  629. static void ttusb_iso_irq(struct urb *urb)
  630. {
  631. struct ttusb *ttusb = urb->context;
  632. struct usb_iso_packet_descriptor *d;
  633. u8 *data;
  634. int len, i;
  635. if (!ttusb->iso_streaming)
  636. return;
  637. #if 0
  638. printk("%s: status %d, errcount == %d, length == %i\n",
  639. __func__,
  640. urb->status, urb->error_count, urb->actual_length);
  641. #endif
  642. if (!urb->status) {
  643. for (i = 0; i < urb->number_of_packets; ++i) {
  644. numpkt++;
  645. if (time_after_eq(jiffies, lastj + HZ)) {
  646. dprintk("frames/s: %lu (ts: %d, stuff %d, "
  647. "sec: %d, invalid: %d, all: %d)\n",
  648. numpkt * HZ / (jiffies - lastj),
  649. numts, numstuff, numsec, numinvalid,
  650. numts + numstuff + numsec + numinvalid);
  651. numts = numstuff = numsec = numinvalid = 0;
  652. lastj = jiffies;
  653. numpkt = 0;
  654. }
  655. d = &urb->iso_frame_desc[i];
  656. data = urb->transfer_buffer + d->offset;
  657. len = d->actual_length;
  658. d->actual_length = 0;
  659. d->status = 0;
  660. ttusb_process_frame(ttusb, data, len);
  661. }
  662. }
  663. usb_submit_urb(urb, GFP_ATOMIC);
  664. }
  665. static void ttusb_free_iso_urbs(struct ttusb *ttusb)
  666. {
  667. int i;
  668. for (i = 0; i < ISO_BUF_COUNT; i++)
  669. usb_free_urb(ttusb->iso_urb[i]);
  670. pci_free_consistent(NULL,
  671. ISO_FRAME_SIZE * FRAMES_PER_ISO_BUF *
  672. ISO_BUF_COUNT, ttusb->iso_buffer,
  673. ttusb->iso_dma_handle);
  674. }
  675. static int ttusb_alloc_iso_urbs(struct ttusb *ttusb)
  676. {
  677. int i;
  678. ttusb->iso_buffer = pci_zalloc_consistent(NULL,
  679. ISO_FRAME_SIZE * FRAMES_PER_ISO_BUF * ISO_BUF_COUNT,
  680. &ttusb->iso_dma_handle);
  681. if (!ttusb->iso_buffer) {
  682. dprintk("%s: pci_alloc_consistent - not enough memory\n",
  683. __func__);
  684. return -ENOMEM;
  685. }
  686. for (i = 0; i < ISO_BUF_COUNT; i++) {
  687. struct urb *urb;
  688. if (!
  689. (urb =
  690. usb_alloc_urb(FRAMES_PER_ISO_BUF, GFP_ATOMIC))) {
  691. ttusb_free_iso_urbs(ttusb);
  692. return -ENOMEM;
  693. }
  694. ttusb->iso_urb[i] = urb;
  695. }
  696. return 0;
  697. }
  698. static void ttusb_stop_iso_xfer(struct ttusb *ttusb)
  699. {
  700. int i;
  701. for (i = 0; i < ISO_BUF_COUNT; i++)
  702. usb_kill_urb(ttusb->iso_urb[i]);
  703. ttusb->iso_streaming = 0;
  704. }
  705. static int ttusb_start_iso_xfer(struct ttusb *ttusb)
  706. {
  707. int i, j, err, buffer_offset = 0;
  708. if (ttusb->iso_streaming) {
  709. printk("%s: iso xfer already running!\n", __func__);
  710. return 0;
  711. }
  712. ttusb->cc = -1;
  713. ttusb->insync = 0;
  714. ttusb->mux_state = 0;
  715. for (i = 0; i < ISO_BUF_COUNT; i++) {
  716. int frame_offset = 0;
  717. struct urb *urb = ttusb->iso_urb[i];
  718. urb->dev = ttusb->dev;
  719. urb->context = ttusb;
  720. urb->complete = ttusb_iso_irq;
  721. urb->pipe = ttusb->isoc_in_pipe;
  722. urb->transfer_flags = URB_ISO_ASAP;
  723. urb->interval = 1;
  724. urb->number_of_packets = FRAMES_PER_ISO_BUF;
  725. urb->transfer_buffer_length =
  726. ISO_FRAME_SIZE * FRAMES_PER_ISO_BUF;
  727. urb->transfer_buffer = ttusb->iso_buffer + buffer_offset;
  728. buffer_offset += ISO_FRAME_SIZE * FRAMES_PER_ISO_BUF;
  729. for (j = 0; j < FRAMES_PER_ISO_BUF; j++) {
  730. urb->iso_frame_desc[j].offset = frame_offset;
  731. urb->iso_frame_desc[j].length = ISO_FRAME_SIZE;
  732. frame_offset += ISO_FRAME_SIZE;
  733. }
  734. }
  735. for (i = 0; i < ISO_BUF_COUNT; i++) {
  736. if ((err = usb_submit_urb(ttusb->iso_urb[i], GFP_ATOMIC))) {
  737. ttusb_stop_iso_xfer(ttusb);
  738. printk
  739. ("%s: failed urb submission (%i: err = %i)!\n",
  740. __func__, i, err);
  741. return err;
  742. }
  743. }
  744. ttusb->iso_streaming = 1;
  745. return 0;
  746. }
  747. #ifdef TTUSB_HWSECTIONS
  748. static void ttusb_handle_ts_data(struct dvb_demux_feed *dvbdmxfeed, const u8 * data,
  749. int len)
  750. {
  751. dvbdmxfeed->cb.ts(data, len, 0, 0, &dvbdmxfeed->feed.ts, 0);
  752. }
  753. static void ttusb_handle_sec_data(struct dvb_demux_feed *dvbdmxfeed, const u8 * data,
  754. int len)
  755. {
  756. // struct dvb_demux_feed *dvbdmxfeed = channel->dvbdmxfeed;
  757. #error TODO: handle ugly stuff
  758. // dvbdmxfeed->cb.sec(data, len, 0, 0, &dvbdmxfeed->feed.sec, 0);
  759. }
  760. #endif
  761. static int ttusb_start_feed(struct dvb_demux_feed *dvbdmxfeed)
  762. {
  763. struct ttusb *ttusb = (struct ttusb *) dvbdmxfeed->demux;
  764. int feed_type = 1;
  765. dprintk("ttusb_start_feed\n");
  766. switch (dvbdmxfeed->type) {
  767. case DMX_TYPE_TS:
  768. break;
  769. case DMX_TYPE_SEC:
  770. break;
  771. default:
  772. return -EINVAL;
  773. }
  774. if (dvbdmxfeed->type == DMX_TYPE_TS) {
  775. switch (dvbdmxfeed->pes_type) {
  776. case DMX_PES_VIDEO:
  777. case DMX_PES_AUDIO:
  778. case DMX_PES_TELETEXT:
  779. case DMX_PES_PCR:
  780. case DMX_PES_OTHER:
  781. break;
  782. default:
  783. return -EINVAL;
  784. }
  785. }
  786. #ifdef TTUSB_HWSECTIONS
  787. #error TODO: allocate filters
  788. if (dvbdmxfeed->type == DMX_TYPE_TS) {
  789. feed_type = 1;
  790. } else if (dvbdmxfeed->type == DMX_TYPE_SEC) {
  791. feed_type = 2;
  792. }
  793. #endif
  794. ttusb_set_channel(ttusb, dvbdmxfeed->index, feed_type, dvbdmxfeed->pid);
  795. if (0 == ttusb->running_feed_count++)
  796. ttusb_start_iso_xfer(ttusb);
  797. return 0;
  798. }
  799. static int ttusb_stop_feed(struct dvb_demux_feed *dvbdmxfeed)
  800. {
  801. struct ttusb *ttusb = (struct ttusb *) dvbdmxfeed->demux;
  802. ttusb_del_channel(ttusb, dvbdmxfeed->index);
  803. if (--ttusb->running_feed_count == 0)
  804. ttusb_stop_iso_xfer(ttusb);
  805. return 0;
  806. }
  807. static int ttusb_setup_interfaces(struct ttusb *ttusb)
  808. {
  809. usb_set_interface(ttusb->dev, 1, 1);
  810. ttusb->bulk_out_pipe = usb_sndbulkpipe(ttusb->dev, 1);
  811. ttusb->bulk_in_pipe = usb_rcvbulkpipe(ttusb->dev, 1);
  812. ttusb->isoc_in_pipe = usb_rcvisocpipe(ttusb->dev, 2);
  813. return 0;
  814. }
  815. #if 0
  816. static u8 stc_firmware[8192];
  817. static int stc_open(struct inode *inode, struct file *file)
  818. {
  819. struct ttusb *ttusb = file->private_data;
  820. int addr;
  821. for (addr = 0; addr < 8192; addr += 16) {
  822. u8 snd_buf[2] = { addr >> 8, addr & 0xFF };
  823. ttusb_i2c_msg(ttusb, 0x50, snd_buf, 2, stc_firmware + addr,
  824. 16);
  825. }
  826. return 0;
  827. }
  828. static ssize_t stc_read(struct file *file, char *buf, size_t count,
  829. loff_t *offset)
  830. {
  831. return simple_read_from_buffer(buf, count, offset, stc_firmware, 8192);
  832. }
  833. static int stc_release(struct inode *inode, struct file *file)
  834. {
  835. return 0;
  836. }
  837. static const struct file_operations stc_fops = {
  838. .owner = THIS_MODULE,
  839. .read = stc_read,
  840. .open = stc_open,
  841. .release = stc_release,
  842. };
  843. #endif
  844. static u32 functionality(struct i2c_adapter *adapter)
  845. {
  846. return I2C_FUNC_I2C;
  847. }
  848. static int alps_tdmb7_tuner_set_params(struct dvb_frontend *fe)
  849. {
  850. struct dtv_frontend_properties *p = &fe->dtv_property_cache;
  851. struct ttusb* ttusb = (struct ttusb*) fe->dvb->priv;
  852. u8 data[4];
  853. struct i2c_msg msg = {.addr=0x61, .flags=0, .buf=data, .len=sizeof(data) };
  854. u32 div;
  855. div = (p->frequency + 36166667) / 166667;
  856. data[0] = (div >> 8) & 0x7f;
  857. data[1] = div & 0xff;
  858. data[2] = ((div >> 10) & 0x60) | 0x85;
  859. data[3] = p->frequency < 592000000 ? 0x40 : 0x80;
  860. if (fe->ops.i2c_gate_ctrl)
  861. fe->ops.i2c_gate_ctrl(fe, 1);
  862. if (i2c_transfer(&ttusb->i2c_adap, &msg, 1) != 1) return -EIO;
  863. return 0;
  864. }
  865. static struct cx22700_config alps_tdmb7_config = {
  866. .demod_address = 0x43,
  867. };
  868. static int philips_tdm1316l_tuner_init(struct dvb_frontend* fe)
  869. {
  870. struct ttusb* ttusb = (struct ttusb*) fe->dvb->priv;
  871. static u8 td1316_init[] = { 0x0b, 0xf5, 0x85, 0xab };
  872. static u8 disable_mc44BC374c[] = { 0x1d, 0x74, 0xa0, 0x68 };
  873. struct i2c_msg tuner_msg = { .addr=0x60, .flags=0, .buf=td1316_init, .len=sizeof(td1316_init) };
  874. // setup PLL configuration
  875. if (fe->ops.i2c_gate_ctrl)
  876. fe->ops.i2c_gate_ctrl(fe, 1);
  877. if (i2c_transfer(&ttusb->i2c_adap, &tuner_msg, 1) != 1) return -EIO;
  878. msleep(1);
  879. // disable the mc44BC374c (do not check for errors)
  880. tuner_msg.addr = 0x65;
  881. tuner_msg.buf = disable_mc44BC374c;
  882. tuner_msg.len = sizeof(disable_mc44BC374c);
  883. if (fe->ops.i2c_gate_ctrl)
  884. fe->ops.i2c_gate_ctrl(fe, 1);
  885. if (i2c_transfer(&ttusb->i2c_adap, &tuner_msg, 1) != 1) {
  886. i2c_transfer(&ttusb->i2c_adap, &tuner_msg, 1);
  887. }
  888. return 0;
  889. }
  890. static int philips_tdm1316l_tuner_set_params(struct dvb_frontend *fe)
  891. {
  892. struct dtv_frontend_properties *p = &fe->dtv_property_cache;
  893. struct ttusb* ttusb = (struct ttusb*) fe->dvb->priv;
  894. u8 tuner_buf[4];
  895. struct i2c_msg tuner_msg = {.addr=0x60, .flags=0, .buf=tuner_buf, .len=sizeof(tuner_buf) };
  896. int tuner_frequency = 0;
  897. u8 band, cp, filter;
  898. // determine charge pump
  899. tuner_frequency = p->frequency + 36130000;
  900. if (tuner_frequency < 87000000) return -EINVAL;
  901. else if (tuner_frequency < 130000000) cp = 3;
  902. else if (tuner_frequency < 160000000) cp = 5;
  903. else if (tuner_frequency < 200000000) cp = 6;
  904. else if (tuner_frequency < 290000000) cp = 3;
  905. else if (tuner_frequency < 420000000) cp = 5;
  906. else if (tuner_frequency < 480000000) cp = 6;
  907. else if (tuner_frequency < 620000000) cp = 3;
  908. else if (tuner_frequency < 830000000) cp = 5;
  909. else if (tuner_frequency < 895000000) cp = 7;
  910. else return -EINVAL;
  911. // determine band
  912. if (p->frequency < 49000000)
  913. return -EINVAL;
  914. else if (p->frequency < 159000000)
  915. band = 1;
  916. else if (p->frequency < 444000000)
  917. band = 2;
  918. else if (p->frequency < 861000000)
  919. band = 4;
  920. else return -EINVAL;
  921. // setup PLL filter
  922. switch (p->bandwidth_hz) {
  923. case 6000000:
  924. tda1004x_writereg(fe, 0x0C, 0);
  925. filter = 0;
  926. break;
  927. case 7000000:
  928. tda1004x_writereg(fe, 0x0C, 0);
  929. filter = 0;
  930. break;
  931. case 8000000:
  932. tda1004x_writereg(fe, 0x0C, 0xFF);
  933. filter = 1;
  934. break;
  935. default:
  936. return -EINVAL;
  937. }
  938. // calculate divisor
  939. // ((36130000+((1000000/6)/2)) + Finput)/(1000000/6)
  940. tuner_frequency = (((p->frequency / 1000) * 6) + 217280) / 1000;
  941. // setup tuner buffer
  942. tuner_buf[0] = tuner_frequency >> 8;
  943. tuner_buf[1] = tuner_frequency & 0xff;
  944. tuner_buf[2] = 0xca;
  945. tuner_buf[3] = (cp << 5) | (filter << 3) | band;
  946. if (fe->ops.i2c_gate_ctrl)
  947. fe->ops.i2c_gate_ctrl(fe, 1);
  948. if (i2c_transfer(&ttusb->i2c_adap, &tuner_msg, 1) != 1)
  949. return -EIO;
  950. msleep(1);
  951. return 0;
  952. }
  953. static int philips_tdm1316l_request_firmware(struct dvb_frontend* fe, const struct firmware **fw, char* name)
  954. {
  955. struct ttusb* ttusb = (struct ttusb*) fe->dvb->priv;
  956. return request_firmware(fw, name, &ttusb->dev->dev);
  957. }
  958. static struct tda1004x_config philips_tdm1316l_config = {
  959. .demod_address = 0x8,
  960. .invert = 1,
  961. .invert_oclk = 0,
  962. .request_firmware = philips_tdm1316l_request_firmware,
  963. };
  964. static u8 alps_bsbe1_inittab[] = {
  965. 0x01, 0x15,
  966. 0x02, 0x30,
  967. 0x03, 0x00,
  968. 0x04, 0x7d, /* F22FR = 0x7d, F22 = f_VCO / 128 / 0x7d = 22 kHz */
  969. 0x05, 0x35, /* I2CT = 0, SCLT = 1, SDAT = 1 */
  970. 0x06, 0x40, /* DAC not used, set to high impendance mode */
  971. 0x07, 0x00, /* DAC LSB */
  972. 0x08, 0x40, /* DiSEqC off, LNB power on OP2/LOCK pin on */
  973. 0x09, 0x00, /* FIFO */
  974. 0x0c, 0x51, /* OP1 ctl = Normal, OP1 val = 1 (LNB Power ON) */
  975. 0x0d, 0x82, /* DC offset compensation = ON, beta_agc1 = 2 */
  976. 0x0e, 0x23, /* alpha_tmg = 2, beta_tmg = 3 */
  977. 0x10, 0x3f, // AGC2 0x3d
  978. 0x11, 0x84,
  979. 0x12, 0xb9,
  980. 0x15, 0xc9, // lock detector threshold
  981. 0x16, 0x00,
  982. 0x17, 0x00,
  983. 0x18, 0x00,
  984. 0x19, 0x00,
  985. 0x1a, 0x00,
  986. 0x1f, 0x50,
  987. 0x20, 0x00,
  988. 0x21, 0x00,
  989. 0x22, 0x00,
  990. 0x23, 0x00,
  991. 0x28, 0x00, // out imp: normal out type: parallel FEC mode:0
  992. 0x29, 0x1e, // 1/2 threshold
  993. 0x2a, 0x14, // 2/3 threshold
  994. 0x2b, 0x0f, // 3/4 threshold
  995. 0x2c, 0x09, // 5/6 threshold
  996. 0x2d, 0x05, // 7/8 threshold
  997. 0x2e, 0x01,
  998. 0x31, 0x1f, // test all FECs
  999. 0x32, 0x19, // viterbi and synchro search
  1000. 0x33, 0xfc, // rs control
  1001. 0x34, 0x93, // error control
  1002. 0x0f, 0x92,
  1003. 0xff, 0xff
  1004. };
  1005. static u8 alps_bsru6_inittab[] = {
  1006. 0x01, 0x15,
  1007. 0x02, 0x30,
  1008. 0x03, 0x00,
  1009. 0x04, 0x7d, /* F22FR = 0x7d, F22 = f_VCO / 128 / 0x7d = 22 kHz */
  1010. 0x05, 0x35, /* I2CT = 0, SCLT = 1, SDAT = 1 */
  1011. 0x06, 0x40, /* DAC not used, set to high impendance mode */
  1012. 0x07, 0x00, /* DAC LSB */
  1013. 0x08, 0x40, /* DiSEqC off, LNB power on OP2/LOCK pin on */
  1014. 0x09, 0x00, /* FIFO */
  1015. 0x0c, 0x51, /* OP1 ctl = Normal, OP1 val = 1 (LNB Power ON) */
  1016. 0x0d, 0x82, /* DC offset compensation = ON, beta_agc1 = 2 */
  1017. 0x0e, 0x23, /* alpha_tmg = 2, beta_tmg = 3 */
  1018. 0x10, 0x3f, // AGC2 0x3d
  1019. 0x11, 0x84,
  1020. 0x12, 0xb9,
  1021. 0x15, 0xc9, // lock detector threshold
  1022. 0x16, 0x00,
  1023. 0x17, 0x00,
  1024. 0x18, 0x00,
  1025. 0x19, 0x00,
  1026. 0x1a, 0x00,
  1027. 0x1f, 0x50,
  1028. 0x20, 0x00,
  1029. 0x21, 0x00,
  1030. 0x22, 0x00,
  1031. 0x23, 0x00,
  1032. 0x28, 0x00, // out imp: normal out type: parallel FEC mode:0
  1033. 0x29, 0x1e, // 1/2 threshold
  1034. 0x2a, 0x14, // 2/3 threshold
  1035. 0x2b, 0x0f, // 3/4 threshold
  1036. 0x2c, 0x09, // 5/6 threshold
  1037. 0x2d, 0x05, // 7/8 threshold
  1038. 0x2e, 0x01,
  1039. 0x31, 0x1f, // test all FECs
  1040. 0x32, 0x19, // viterbi and synchro search
  1041. 0x33, 0xfc, // rs control
  1042. 0x34, 0x93, // error control
  1043. 0x0f, 0x52,
  1044. 0xff, 0xff
  1045. };
  1046. static int alps_stv0299_set_symbol_rate(struct dvb_frontend *fe, u32 srate, u32 ratio)
  1047. {
  1048. u8 aclk = 0;
  1049. u8 bclk = 0;
  1050. if (srate < 1500000) {
  1051. aclk = 0xb7;
  1052. bclk = 0x47;
  1053. } else if (srate < 3000000) {
  1054. aclk = 0xb7;
  1055. bclk = 0x4b;
  1056. } else if (srate < 7000000) {
  1057. aclk = 0xb7;
  1058. bclk = 0x4f;
  1059. } else if (srate < 14000000) {
  1060. aclk = 0xb7;
  1061. bclk = 0x53;
  1062. } else if (srate < 30000000) {
  1063. aclk = 0xb6;
  1064. bclk = 0x53;
  1065. } else if (srate < 45000000) {
  1066. aclk = 0xb4;
  1067. bclk = 0x51;
  1068. }
  1069. stv0299_writereg(fe, 0x13, aclk);
  1070. stv0299_writereg(fe, 0x14, bclk);
  1071. stv0299_writereg(fe, 0x1f, (ratio >> 16) & 0xff);
  1072. stv0299_writereg(fe, 0x20, (ratio >> 8) & 0xff);
  1073. stv0299_writereg(fe, 0x21, (ratio) & 0xf0);
  1074. return 0;
  1075. }
  1076. static int philips_tsa5059_tuner_set_params(struct dvb_frontend *fe)
  1077. {
  1078. struct dtv_frontend_properties *p = &fe->dtv_property_cache;
  1079. struct ttusb* ttusb = (struct ttusb*) fe->dvb->priv;
  1080. u8 buf[4];
  1081. u32 div;
  1082. struct i2c_msg msg = {.addr = 0x61,.flags = 0,.buf = buf,.len = sizeof(buf) };
  1083. if ((p->frequency < 950000) || (p->frequency > 2150000))
  1084. return -EINVAL;
  1085. div = (p->frequency + (125 - 1)) / 125; /* round correctly */
  1086. buf[0] = (div >> 8) & 0x7f;
  1087. buf[1] = div & 0xff;
  1088. buf[2] = 0x80 | ((div & 0x18000) >> 10) | 4;
  1089. buf[3] = 0xC4;
  1090. if (p->frequency > 1530000)
  1091. buf[3] = 0xC0;
  1092. /* BSBE1 wants XCE bit set */
  1093. if (ttusb->revision == TTUSB_REV_2_2)
  1094. buf[3] |= 0x20;
  1095. if (fe->ops.i2c_gate_ctrl)
  1096. fe->ops.i2c_gate_ctrl(fe, 1);
  1097. if (i2c_transfer(&ttusb->i2c_adap, &msg, 1) != 1)
  1098. return -EIO;
  1099. return 0;
  1100. }
  1101. static struct stv0299_config alps_stv0299_config = {
  1102. .demod_address = 0x68,
  1103. .inittab = alps_bsru6_inittab,
  1104. .mclk = 88000000UL,
  1105. .invert = 1,
  1106. .skip_reinit = 0,
  1107. .lock_output = STV0299_LOCKOUTPUT_1,
  1108. .volt13_op0_op1 = STV0299_VOLT13_OP1,
  1109. .min_delay_ms = 100,
  1110. .set_symbol_rate = alps_stv0299_set_symbol_rate,
  1111. };
  1112. static int ttusb_novas_grundig_29504_491_tuner_set_params(struct dvb_frontend *fe)
  1113. {
  1114. struct dtv_frontend_properties *p = &fe->dtv_property_cache;
  1115. struct ttusb* ttusb = (struct ttusb*) fe->dvb->priv;
  1116. u8 buf[4];
  1117. u32 div;
  1118. struct i2c_msg msg = {.addr = 0x61,.flags = 0,.buf = buf,.len = sizeof(buf) };
  1119. div = p->frequency / 125;
  1120. buf[0] = (div >> 8) & 0x7f;
  1121. buf[1] = div & 0xff;
  1122. buf[2] = 0x8e;
  1123. buf[3] = 0x00;
  1124. if (fe->ops.i2c_gate_ctrl)
  1125. fe->ops.i2c_gate_ctrl(fe, 1);
  1126. if (i2c_transfer(&ttusb->i2c_adap, &msg, 1) != 1)
  1127. return -EIO;
  1128. return 0;
  1129. }
  1130. static struct tda8083_config ttusb_novas_grundig_29504_491_config = {
  1131. .demod_address = 0x68,
  1132. };
  1133. static int alps_tdbe2_tuner_set_params(struct dvb_frontend *fe)
  1134. {
  1135. struct dtv_frontend_properties *p = &fe->dtv_property_cache;
  1136. struct ttusb* ttusb = fe->dvb->priv;
  1137. u32 div;
  1138. u8 data[4];
  1139. struct i2c_msg msg = { .addr = 0x62, .flags = 0, .buf = data, .len = sizeof(data) };
  1140. div = (p->frequency + 35937500 + 31250) / 62500;
  1141. data[0] = (div >> 8) & 0x7f;
  1142. data[1] = div & 0xff;
  1143. data[2] = 0x85 | ((div >> 10) & 0x60);
  1144. data[3] = (p->frequency < 174000000 ? 0x88 : p->frequency < 470000000 ? 0x84 : 0x81);
  1145. if (fe->ops.i2c_gate_ctrl)
  1146. fe->ops.i2c_gate_ctrl(fe, 1);
  1147. if (i2c_transfer (&ttusb->i2c_adap, &msg, 1) != 1)
  1148. return -EIO;
  1149. return 0;
  1150. }
  1151. static struct ves1820_config alps_tdbe2_config = {
  1152. .demod_address = 0x09,
  1153. .xin = 57840000UL,
  1154. .invert = 1,
  1155. .selagc = VES1820_SELAGC_SIGNAMPERR,
  1156. };
  1157. static u8 read_pwm(struct ttusb* ttusb)
  1158. {
  1159. u8 b = 0xff;
  1160. u8 pwm;
  1161. struct i2c_msg msg[] = { { .addr = 0x50,.flags = 0,.buf = &b,.len = 1 },
  1162. { .addr = 0x50,.flags = I2C_M_RD,.buf = &pwm,.len = 1} };
  1163. if ((i2c_transfer(&ttusb->i2c_adap, msg, 2) != 2) || (pwm == 0xff))
  1164. pwm = 0x48;
  1165. return pwm;
  1166. }
  1167. static int dvbc_philips_tdm1316l_tuner_set_params(struct dvb_frontend *fe)
  1168. {
  1169. struct dtv_frontend_properties *p = &fe->dtv_property_cache;
  1170. struct ttusb *ttusb = (struct ttusb *) fe->dvb->priv;
  1171. u8 tuner_buf[5];
  1172. struct i2c_msg tuner_msg = {.addr = 0x60,
  1173. .flags = 0,
  1174. .buf = tuner_buf,
  1175. .len = sizeof(tuner_buf) };
  1176. int tuner_frequency = 0;
  1177. u8 band, cp, filter;
  1178. // determine charge pump
  1179. tuner_frequency = p->frequency;
  1180. if (tuner_frequency < 87000000) {return -EINVAL;}
  1181. else if (tuner_frequency < 130000000) {cp = 3; band = 1;}
  1182. else if (tuner_frequency < 160000000) {cp = 5; band = 1;}
  1183. else if (tuner_frequency < 200000000) {cp = 6; band = 1;}
  1184. else if (tuner_frequency < 290000000) {cp = 3; band = 2;}
  1185. else if (tuner_frequency < 420000000) {cp = 5; band = 2;}
  1186. else if (tuner_frequency < 480000000) {cp = 6; band = 2;}
  1187. else if (tuner_frequency < 620000000) {cp = 3; band = 4;}
  1188. else if (tuner_frequency < 830000000) {cp = 5; band = 4;}
  1189. else if (tuner_frequency < 895000000) {cp = 7; band = 4;}
  1190. else {return -EINVAL;}
  1191. // assume PLL filter should always be 8MHz for the moment.
  1192. filter = 1;
  1193. // calculate divisor
  1194. // (Finput + Fif)/Fref; Fif = 36125000 Hz, Fref = 62500 Hz
  1195. tuner_frequency = ((p->frequency + 36125000) / 62500);
  1196. // setup tuner buffer
  1197. tuner_buf[0] = tuner_frequency >> 8;
  1198. tuner_buf[1] = tuner_frequency & 0xff;
  1199. tuner_buf[2] = 0xc8;
  1200. tuner_buf[3] = (cp << 5) | (filter << 3) | band;
  1201. tuner_buf[4] = 0x80;
  1202. if (fe->ops.i2c_gate_ctrl)
  1203. fe->ops.i2c_gate_ctrl(fe, 1);
  1204. if (i2c_transfer(&ttusb->i2c_adap, &tuner_msg, 1) != 1) {
  1205. printk("dvb-ttusb-budget: dvbc_philips_tdm1316l_pll_set Error 1\n");
  1206. return -EIO;
  1207. }
  1208. msleep(50);
  1209. if (fe->ops.i2c_gate_ctrl)
  1210. fe->ops.i2c_gate_ctrl(fe, 1);
  1211. if (i2c_transfer(&ttusb->i2c_adap, &tuner_msg, 1) != 1) {
  1212. printk("dvb-ttusb-budget: dvbc_philips_tdm1316l_pll_set Error 2\n");
  1213. return -EIO;
  1214. }
  1215. msleep(1);
  1216. return 0;
  1217. }
  1218. static u8 dvbc_philips_tdm1316l_inittab[] = {
  1219. 0x80, 0x21,
  1220. 0x80, 0x20,
  1221. 0x81, 0x01,
  1222. 0x81, 0x00,
  1223. 0x00, 0x09,
  1224. 0x01, 0x69,
  1225. 0x03, 0x00,
  1226. 0x04, 0x00,
  1227. 0x07, 0x00,
  1228. 0x08, 0x00,
  1229. 0x20, 0x00,
  1230. 0x21, 0x40,
  1231. 0x22, 0x00,
  1232. 0x23, 0x00,
  1233. 0x24, 0x40,
  1234. 0x25, 0x88,
  1235. 0x30, 0xff,
  1236. 0x31, 0x00,
  1237. 0x32, 0xff,
  1238. 0x33, 0x00,
  1239. 0x34, 0x50,
  1240. 0x35, 0x7f,
  1241. 0x36, 0x00,
  1242. 0x37, 0x20,
  1243. 0x38, 0x00,
  1244. 0x40, 0x1c,
  1245. 0x41, 0xff,
  1246. 0x42, 0x29,
  1247. 0x43, 0x20,
  1248. 0x44, 0xff,
  1249. 0x45, 0x00,
  1250. 0x46, 0x00,
  1251. 0x49, 0x04,
  1252. 0x4a, 0xff,
  1253. 0x4b, 0x7f,
  1254. 0x52, 0x30,
  1255. 0x55, 0xae,
  1256. 0x56, 0x47,
  1257. 0x57, 0xe1,
  1258. 0x58, 0x3a,
  1259. 0x5a, 0x1e,
  1260. 0x5b, 0x34,
  1261. 0x60, 0x00,
  1262. 0x63, 0x00,
  1263. 0x64, 0x00,
  1264. 0x65, 0x00,
  1265. 0x66, 0x00,
  1266. 0x67, 0x00,
  1267. 0x68, 0x00,
  1268. 0x69, 0x00,
  1269. 0x6a, 0x02,
  1270. 0x6b, 0x00,
  1271. 0x70, 0xff,
  1272. 0x71, 0x00,
  1273. 0x72, 0x00,
  1274. 0x73, 0x00,
  1275. 0x74, 0x0c,
  1276. 0x80, 0x00,
  1277. 0x81, 0x00,
  1278. 0x82, 0x00,
  1279. 0x83, 0x00,
  1280. 0x84, 0x04,
  1281. 0x85, 0x80,
  1282. 0x86, 0x24,
  1283. 0x87, 0x78,
  1284. 0x88, 0x00,
  1285. 0x89, 0x00,
  1286. 0x90, 0x01,
  1287. 0x91, 0x01,
  1288. 0xa0, 0x00,
  1289. 0xa1, 0x00,
  1290. 0xa2, 0x00,
  1291. 0xb0, 0x91,
  1292. 0xb1, 0x0b,
  1293. 0xc0, 0x4b,
  1294. 0xc1, 0x00,
  1295. 0xc2, 0x00,
  1296. 0xd0, 0x00,
  1297. 0xd1, 0x00,
  1298. 0xd2, 0x00,
  1299. 0xd3, 0x00,
  1300. 0xd4, 0x00,
  1301. 0xd5, 0x00,
  1302. 0xde, 0x00,
  1303. 0xdf, 0x00,
  1304. 0x61, 0x38,
  1305. 0x62, 0x0a,
  1306. 0x53, 0x13,
  1307. 0x59, 0x08,
  1308. 0x55, 0x00,
  1309. 0x56, 0x40,
  1310. 0x57, 0x08,
  1311. 0x58, 0x3d,
  1312. 0x88, 0x10,
  1313. 0xa0, 0x00,
  1314. 0xa0, 0x00,
  1315. 0xa0, 0x00,
  1316. 0xa0, 0x04,
  1317. 0xff, 0xff,
  1318. };
  1319. static struct stv0297_config dvbc_philips_tdm1316l_config = {
  1320. .demod_address = 0x1c,
  1321. .inittab = dvbc_philips_tdm1316l_inittab,
  1322. .invert = 0,
  1323. };
  1324. static void frontend_init(struct ttusb* ttusb)
  1325. {
  1326. switch(le16_to_cpu(ttusb->dev->descriptor.idProduct)) {
  1327. case 0x1003: // Hauppauge/TT Nova-USB-S budget (stv0299/ALPS BSRU6|BSBE1(tsa5059))
  1328. // try the stv0299 based first
  1329. ttusb->fe = dvb_attach(stv0299_attach, &alps_stv0299_config, &ttusb->i2c_adap);
  1330. if (ttusb->fe != NULL) {
  1331. ttusb->fe->ops.tuner_ops.set_params = philips_tsa5059_tuner_set_params;
  1332. if(ttusb->revision == TTUSB_REV_2_2) { // ALPS BSBE1
  1333. alps_stv0299_config.inittab = alps_bsbe1_inittab;
  1334. dvb_attach(lnbp21_attach, ttusb->fe, &ttusb->i2c_adap, 0, 0);
  1335. } else { // ALPS BSRU6
  1336. ttusb->fe->ops.set_voltage = ttusb_set_voltage;
  1337. }
  1338. break;
  1339. }
  1340. // Grundig 29504-491
  1341. ttusb->fe = dvb_attach(tda8083_attach, &ttusb_novas_grundig_29504_491_config, &ttusb->i2c_adap);
  1342. if (ttusb->fe != NULL) {
  1343. ttusb->fe->ops.tuner_ops.set_params = ttusb_novas_grundig_29504_491_tuner_set_params;
  1344. ttusb->fe->ops.set_voltage = ttusb_set_voltage;
  1345. break;
  1346. }
  1347. break;
  1348. case 0x1004: // Hauppauge/TT DVB-C budget (ves1820/ALPS TDBE2(sp5659))
  1349. ttusb->fe = dvb_attach(ves1820_attach, &alps_tdbe2_config, &ttusb->i2c_adap, read_pwm(ttusb));
  1350. if (ttusb->fe != NULL) {
  1351. ttusb->fe->ops.tuner_ops.set_params = alps_tdbe2_tuner_set_params;
  1352. break;
  1353. }
  1354. ttusb->fe = dvb_attach(stv0297_attach, &dvbc_philips_tdm1316l_config, &ttusb->i2c_adap);
  1355. if (ttusb->fe != NULL) {
  1356. ttusb->fe->ops.tuner_ops.set_params = dvbc_philips_tdm1316l_tuner_set_params;
  1357. break;
  1358. }
  1359. break;
  1360. case 0x1005: // Hauppauge/TT Nova-USB-t budget (tda10046/Philips td1316(tda6651tt) OR cx22700/ALPS TDMB7(??))
  1361. // try the ALPS TDMB7 first
  1362. ttusb->fe = dvb_attach(cx22700_attach, &alps_tdmb7_config, &ttusb->i2c_adap);
  1363. if (ttusb->fe != NULL) {
  1364. ttusb->fe->ops.tuner_ops.set_params = alps_tdmb7_tuner_set_params;
  1365. break;
  1366. }
  1367. // Philips td1316
  1368. ttusb->fe = dvb_attach(tda10046_attach, &philips_tdm1316l_config, &ttusb->i2c_adap);
  1369. if (ttusb->fe != NULL) {
  1370. ttusb->fe->ops.tuner_ops.init = philips_tdm1316l_tuner_init;
  1371. ttusb->fe->ops.tuner_ops.set_params = philips_tdm1316l_tuner_set_params;
  1372. break;
  1373. }
  1374. break;
  1375. }
  1376. if (ttusb->fe == NULL) {
  1377. printk("dvb-ttusb-budget: A frontend driver was not found for device [%04x:%04x]\n",
  1378. le16_to_cpu(ttusb->dev->descriptor.idVendor),
  1379. le16_to_cpu(ttusb->dev->descriptor.idProduct));
  1380. } else {
  1381. if (dvb_register_frontend(&ttusb->adapter, ttusb->fe)) {
  1382. printk("dvb-ttusb-budget: Frontend registration failed!\n");
  1383. dvb_frontend_detach(ttusb->fe);
  1384. ttusb->fe = NULL;
  1385. }
  1386. }
  1387. }
  1388. static struct i2c_algorithm ttusb_dec_algo = {
  1389. .master_xfer = master_xfer,
  1390. .functionality = functionality,
  1391. };
  1392. static int ttusb_probe(struct usb_interface *intf, const struct usb_device_id *id)
  1393. {
  1394. struct usb_device *udev;
  1395. struct ttusb *ttusb;
  1396. int result;
  1397. dprintk("%s: TTUSB DVB connected\n", __func__);
  1398. udev = interface_to_usbdev(intf);
  1399. if (intf->altsetting->desc.bInterfaceNumber != 1) return -ENODEV;
  1400. if (!(ttusb = kzalloc(sizeof(struct ttusb), GFP_KERNEL)))
  1401. return -ENOMEM;
  1402. ttusb->dev = udev;
  1403. ttusb->c = 0;
  1404. ttusb->mux_state = 0;
  1405. mutex_init(&ttusb->semi2c);
  1406. mutex_lock(&ttusb->semi2c);
  1407. mutex_init(&ttusb->semusb);
  1408. ttusb_setup_interfaces(ttusb);
  1409. result = ttusb_alloc_iso_urbs(ttusb);
  1410. if (result < 0) {
  1411. dprintk("%s: ttusb_alloc_iso_urbs - failed\n", __func__);
  1412. mutex_unlock(&ttusb->semi2c);
  1413. kfree(ttusb);
  1414. return result;
  1415. }
  1416. if (ttusb_init_controller(ttusb))
  1417. printk("ttusb_init_controller: error\n");
  1418. mutex_unlock(&ttusb->semi2c);
  1419. result = dvb_register_adapter(&ttusb->adapter,
  1420. "Technotrend/Hauppauge Nova-USB",
  1421. THIS_MODULE, &udev->dev, adapter_nr);
  1422. if (result < 0) {
  1423. ttusb_free_iso_urbs(ttusb);
  1424. kfree(ttusb);
  1425. return result;
  1426. }
  1427. ttusb->adapter.priv = ttusb;
  1428. /* i2c */
  1429. memset(&ttusb->i2c_adap, 0, sizeof(struct i2c_adapter));
  1430. strcpy(ttusb->i2c_adap.name, "TTUSB DEC");
  1431. i2c_set_adapdata(&ttusb->i2c_adap, ttusb);
  1432. ttusb->i2c_adap.algo = &ttusb_dec_algo;
  1433. ttusb->i2c_adap.algo_data = NULL;
  1434. ttusb->i2c_adap.dev.parent = &udev->dev;
  1435. result = i2c_add_adapter(&ttusb->i2c_adap);
  1436. if (result)
  1437. goto err_unregister_adapter;
  1438. memset(&ttusb->dvb_demux, 0, sizeof(ttusb->dvb_demux));
  1439. ttusb->dvb_demux.dmx.capabilities =
  1440. DMX_TS_FILTERING | DMX_SECTION_FILTERING;
  1441. ttusb->dvb_demux.priv = NULL;
  1442. #ifdef TTUSB_HWSECTIONS
  1443. ttusb->dvb_demux.filternum = TTUSB_MAXFILTER;
  1444. #else
  1445. ttusb->dvb_demux.filternum = 32;
  1446. #endif
  1447. ttusb->dvb_demux.feednum = TTUSB_MAXCHANNEL;
  1448. ttusb->dvb_demux.start_feed = ttusb_start_feed;
  1449. ttusb->dvb_demux.stop_feed = ttusb_stop_feed;
  1450. ttusb->dvb_demux.write_to_decoder = NULL;
  1451. result = dvb_dmx_init(&ttusb->dvb_demux);
  1452. if (result < 0) {
  1453. printk("ttusb_dvb: dvb_dmx_init failed (errno = %d)\n", result);
  1454. result = -ENODEV;
  1455. goto err_i2c_del_adapter;
  1456. }
  1457. //FIXME dmxdev (nur WAS?)
  1458. ttusb->dmxdev.filternum = ttusb->dvb_demux.filternum;
  1459. ttusb->dmxdev.demux = &ttusb->dvb_demux.dmx;
  1460. ttusb->dmxdev.capabilities = 0;
  1461. result = dvb_dmxdev_init(&ttusb->dmxdev, &ttusb->adapter);
  1462. if (result < 0) {
  1463. printk("ttusb_dvb: dvb_dmxdev_init failed (errno = %d)\n",
  1464. result);
  1465. result = -ENODEV;
  1466. goto err_release_dmx;
  1467. }
  1468. if (dvb_net_init(&ttusb->adapter, &ttusb->dvbnet, &ttusb->dvb_demux.dmx)) {
  1469. printk("ttusb_dvb: dvb_net_init failed!\n");
  1470. result = -ENODEV;
  1471. goto err_release_dmxdev;
  1472. }
  1473. usb_set_intfdata(intf, (void *) ttusb);
  1474. frontend_init(ttusb);
  1475. return 0;
  1476. err_release_dmxdev:
  1477. dvb_dmxdev_release(&ttusb->dmxdev);
  1478. err_release_dmx:
  1479. dvb_dmx_release(&ttusb->dvb_demux);
  1480. err_i2c_del_adapter:
  1481. i2c_del_adapter(&ttusb->i2c_adap);
  1482. err_unregister_adapter:
  1483. dvb_unregister_adapter (&ttusb->adapter);
  1484. ttusb_free_iso_urbs(ttusb);
  1485. kfree(ttusb);
  1486. return result;
  1487. }
  1488. static void ttusb_disconnect(struct usb_interface *intf)
  1489. {
  1490. struct ttusb *ttusb = usb_get_intfdata(intf);
  1491. usb_set_intfdata(intf, NULL);
  1492. ttusb->disconnecting = 1;
  1493. ttusb_stop_iso_xfer(ttusb);
  1494. ttusb->dvb_demux.dmx.close(&ttusb->dvb_demux.dmx);
  1495. dvb_net_release(&ttusb->dvbnet);
  1496. dvb_dmxdev_release(&ttusb->dmxdev);
  1497. dvb_dmx_release(&ttusb->dvb_demux);
  1498. if (ttusb->fe != NULL) {
  1499. dvb_unregister_frontend(ttusb->fe);
  1500. dvb_frontend_detach(ttusb->fe);
  1501. }
  1502. i2c_del_adapter(&ttusb->i2c_adap);
  1503. dvb_unregister_adapter(&ttusb->adapter);
  1504. ttusb_free_iso_urbs(ttusb);
  1505. kfree(ttusb);
  1506. dprintk("%s: TTUSB DVB disconnected\n", __func__);
  1507. }
  1508. static struct usb_device_id ttusb_table[] = {
  1509. {USB_DEVICE(0xb48, 0x1003)},
  1510. {USB_DEVICE(0xb48, 0x1004)},
  1511. {USB_DEVICE(0xb48, 0x1005)},
  1512. {}
  1513. };
  1514. MODULE_DEVICE_TABLE(usb, ttusb_table);
  1515. static struct usb_driver ttusb_driver = {
  1516. .name = "ttusb",
  1517. .probe = ttusb_probe,
  1518. .disconnect = ttusb_disconnect,
  1519. .id_table = ttusb_table,
  1520. };
  1521. module_usb_driver(ttusb_driver);
  1522. MODULE_AUTHOR("Holger Waechtler <holger@convergence.de>");
  1523. MODULE_DESCRIPTION("TTUSB DVB Driver");
  1524. MODULE_LICENSE("GPL");
  1525. MODULE_FIRMWARE("ttusb-budget/dspbootcode.bin");