dvb-ttusb-budget.c 43 KB

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