dvb-ttusb-budget.c 43 KB

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