dvb-ttusb-budget.c 43 KB

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