tm6000-video.c 46 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927
  1. /*
  2. * tm6000-video.c - driver for TM5600/TM6000/TM6010 USB video capture devices
  3. *
  4. * Copyright (C) 2006-2007 Mauro Carvalho Chehab <mchehab@infradead.org>
  5. *
  6. * Copyright (C) 2007 Michel Ludwig <michel.ludwig@gmail.com>
  7. * - Fixed module load/unload
  8. *
  9. * This program is free software; you can redistribute it and/or modify
  10. * it under the terms of the GNU General Public License as published by
  11. * the Free Software Foundation version 2
  12. *
  13. * This program is distributed in the hope that it will be useful,
  14. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  15. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  16. * GNU General Public License for more details.
  17. *
  18. * You should have received a copy of the GNU General Public License
  19. * along with this program; if not, write to the Free Software
  20. * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  21. */
  22. #include <linux/module.h>
  23. #include <linux/delay.h>
  24. #include <linux/errno.h>
  25. #include <linux/fs.h>
  26. #include <linux/kernel.h>
  27. #include <linux/slab.h>
  28. #include <linux/mm.h>
  29. #include <linux/ioport.h>
  30. #include <linux/init.h>
  31. #include <linux/sched.h>
  32. #include <linux/random.h>
  33. #include <linux/usb.h>
  34. #include <linux/videodev2.h>
  35. #include <media/v4l2-ioctl.h>
  36. #include <media/tuner.h>
  37. #include <linux/interrupt.h>
  38. #include <linux/kthread.h>
  39. #include <linux/highmem.h>
  40. #include <linux/freezer.h>
  41. #include "tm6000-regs.h"
  42. #include "tm6000.h"
  43. #define BUFFER_TIMEOUT msecs_to_jiffies(2000) /* 2 seconds */
  44. /* Limits minimum and default number of buffers */
  45. #define TM6000_MIN_BUF 4
  46. #define TM6000_DEF_BUF 8
  47. #define TM6000_NUM_URB_BUF 8
  48. #define TM6000_MAX_ISO_PACKETS 46 /* Max number of ISO packets */
  49. /* Declare static vars that will be used as parameters */
  50. static unsigned int vid_limit = 16; /* Video memory limit, in Mb */
  51. static int video_nr = -1; /* /dev/videoN, -1 for autodetect */
  52. static int radio_nr = -1; /* /dev/radioN, -1 for autodetect */
  53. static int keep_urb; /* keep urb buffers allocated */
  54. /* Debug level */
  55. int tm6000_debug;
  56. EXPORT_SYMBOL_GPL(tm6000_debug);
  57. static const struct v4l2_queryctrl no_ctrl = {
  58. .name = "42",
  59. .flags = V4L2_CTRL_FLAG_DISABLED,
  60. };
  61. /* supported controls */
  62. static struct v4l2_queryctrl tm6000_qctrl[] = {
  63. {
  64. .id = V4L2_CID_BRIGHTNESS,
  65. .type = V4L2_CTRL_TYPE_INTEGER,
  66. .name = "Brightness",
  67. .minimum = 0,
  68. .maximum = 255,
  69. .step = 1,
  70. .default_value = 54,
  71. .flags = 0,
  72. }, {
  73. .id = V4L2_CID_CONTRAST,
  74. .type = V4L2_CTRL_TYPE_INTEGER,
  75. .name = "Contrast",
  76. .minimum = 0,
  77. .maximum = 255,
  78. .step = 0x1,
  79. .default_value = 119,
  80. .flags = 0,
  81. }, {
  82. .id = V4L2_CID_SATURATION,
  83. .type = V4L2_CTRL_TYPE_INTEGER,
  84. .name = "Saturation",
  85. .minimum = 0,
  86. .maximum = 255,
  87. .step = 0x1,
  88. .default_value = 112,
  89. .flags = 0,
  90. }, {
  91. .id = V4L2_CID_HUE,
  92. .type = V4L2_CTRL_TYPE_INTEGER,
  93. .name = "Hue",
  94. .minimum = -128,
  95. .maximum = 127,
  96. .step = 0x1,
  97. .default_value = 0,
  98. .flags = 0,
  99. },
  100. /* --- audio --- */
  101. {
  102. .id = V4L2_CID_AUDIO_MUTE,
  103. .name = "Mute",
  104. .minimum = 0,
  105. .maximum = 1,
  106. .type = V4L2_CTRL_TYPE_BOOLEAN,
  107. }, {
  108. .id = V4L2_CID_AUDIO_VOLUME,
  109. .name = "Volume",
  110. .minimum = -15,
  111. .maximum = 15,
  112. .step = 1,
  113. .default_value = 0,
  114. .type = V4L2_CTRL_TYPE_INTEGER,
  115. }
  116. };
  117. static const unsigned int CTRLS = ARRAY_SIZE(tm6000_qctrl);
  118. static int qctl_regs[ARRAY_SIZE(tm6000_qctrl)];
  119. static struct tm6000_fmt format[] = {
  120. {
  121. .name = "4:2:2, packed, YVY2",
  122. .fourcc = V4L2_PIX_FMT_YUYV,
  123. .depth = 16,
  124. }, {
  125. .name = "4:2:2, packed, UYVY",
  126. .fourcc = V4L2_PIX_FMT_UYVY,
  127. .depth = 16,
  128. }, {
  129. .name = "A/V + VBI mux packet",
  130. .fourcc = V4L2_PIX_FMT_TM6000,
  131. .depth = 16,
  132. }
  133. };
  134. static const struct v4l2_queryctrl *ctrl_by_id(unsigned int id)
  135. {
  136. unsigned int i;
  137. for (i = 0; i < CTRLS; i++)
  138. if (tm6000_qctrl[i].id == id)
  139. return tm6000_qctrl+i;
  140. return NULL;
  141. }
  142. /* ------------------------------------------------------------------
  143. * DMA and thread functions
  144. * ------------------------------------------------------------------
  145. */
  146. #define norm_maxw(a) 720
  147. #define norm_maxh(a) 576
  148. #define norm_minw(a) norm_maxw(a)
  149. #define norm_minh(a) norm_maxh(a)
  150. /*
  151. * video-buf generic routine to get the next available buffer
  152. */
  153. static inline void get_next_buf(struct tm6000_dmaqueue *dma_q,
  154. struct tm6000_buffer **buf)
  155. {
  156. struct tm6000_core *dev = container_of(dma_q, struct tm6000_core, vidq);
  157. if (list_empty(&dma_q->active)) {
  158. dprintk(dev, V4L2_DEBUG_QUEUE, "No active queue to serve\n");
  159. *buf = NULL;
  160. return;
  161. }
  162. *buf = list_entry(dma_q->active.next,
  163. struct tm6000_buffer, vb.queue);
  164. }
  165. /*
  166. * Announces that a buffer were filled and request the next
  167. */
  168. static inline void buffer_filled(struct tm6000_core *dev,
  169. struct tm6000_dmaqueue *dma_q,
  170. struct tm6000_buffer *buf)
  171. {
  172. /* Advice that buffer was filled */
  173. dprintk(dev, V4L2_DEBUG_ISOC, "[%p/%d] wakeup\n", buf, buf->vb.i);
  174. buf->vb.state = VIDEOBUF_DONE;
  175. buf->vb.field_count++;
  176. do_gettimeofday(&buf->vb.ts);
  177. list_del(&buf->vb.queue);
  178. wake_up(&buf->vb.done);
  179. }
  180. /*
  181. * Identify the tm5600/6000 buffer header type and properly handles
  182. */
  183. static int copy_streams(u8 *data, unsigned long len,
  184. struct urb *urb)
  185. {
  186. struct tm6000_dmaqueue *dma_q = urb->context;
  187. struct tm6000_core *dev = container_of(dma_q, struct tm6000_core, vidq);
  188. u8 *ptr = data, *endp = data+len;
  189. unsigned long header = 0;
  190. int rc = 0;
  191. unsigned int cmd, cpysize, pktsize, size, field, block, line, pos = 0;
  192. struct tm6000_buffer *vbuf = NULL;
  193. char *voutp = NULL;
  194. unsigned int linewidth;
  195. if (!dev->radio) {
  196. /* get video buffer */
  197. get_next_buf(dma_q, &vbuf);
  198. if (!vbuf)
  199. return rc;
  200. voutp = videobuf_to_vmalloc(&vbuf->vb);
  201. if (!voutp)
  202. return 0;
  203. }
  204. for (ptr = data; ptr < endp;) {
  205. if (!dev->isoc_ctl.cmd) {
  206. /* Header */
  207. if (dev->isoc_ctl.tmp_buf_len > 0) {
  208. /* from last urb or packet */
  209. header = dev->isoc_ctl.tmp_buf;
  210. if (4 - dev->isoc_ctl.tmp_buf_len > 0) {
  211. memcpy((u8 *)&header +
  212. dev->isoc_ctl.tmp_buf_len,
  213. ptr,
  214. 4 - dev->isoc_ctl.tmp_buf_len);
  215. ptr += 4 - dev->isoc_ctl.tmp_buf_len;
  216. }
  217. dev->isoc_ctl.tmp_buf_len = 0;
  218. } else {
  219. if (ptr + 3 >= endp) {
  220. /* have incomplete header */
  221. dev->isoc_ctl.tmp_buf_len = endp - ptr;
  222. memcpy(&dev->isoc_ctl.tmp_buf, ptr,
  223. dev->isoc_ctl.tmp_buf_len);
  224. return rc;
  225. }
  226. /* Seek for sync */
  227. for (; ptr < endp - 3; ptr++) {
  228. if (*(ptr + 3) == 0x47)
  229. break;
  230. }
  231. /* Get message header */
  232. header = *(unsigned long *)ptr;
  233. ptr += 4;
  234. }
  235. /* split the header fields */
  236. size = ((header & 0x7e) << 1);
  237. if (size > 0)
  238. size -= 4;
  239. block = (header >> 7) & 0xf;
  240. field = (header >> 11) & 0x1;
  241. line = (header >> 12) & 0x1ff;
  242. cmd = (header >> 21) & 0x7;
  243. /* Validates haeder fields */
  244. if (size > TM6000_URB_MSG_LEN)
  245. size = TM6000_URB_MSG_LEN;
  246. pktsize = TM6000_URB_MSG_LEN;
  247. /*
  248. * calculate position in buffer and change the buffer
  249. */
  250. switch (cmd) {
  251. case TM6000_URB_MSG_VIDEO:
  252. if (!dev->radio) {
  253. if ((dev->isoc_ctl.vfield != field) &&
  254. (field == 1)) {
  255. /*
  256. * Announces that a new buffer
  257. * were filled
  258. */
  259. buffer_filled(dev, dma_q, vbuf);
  260. dprintk(dev, V4L2_DEBUG_ISOC,
  261. "new buffer filled\n");
  262. get_next_buf(dma_q, &vbuf);
  263. if (!vbuf)
  264. return rc;
  265. voutp = videobuf_to_vmalloc(&vbuf->vb);
  266. if (!voutp)
  267. return rc;
  268. memset(voutp, 0, vbuf->vb.size);
  269. }
  270. linewidth = vbuf->vb.width << 1;
  271. pos = ((line << 1) - field - 1) *
  272. linewidth + block * TM6000_URB_MSG_LEN;
  273. /* Don't allow to write out of the buffer */
  274. if (pos + size > vbuf->vb.size)
  275. cmd = TM6000_URB_MSG_ERR;
  276. dev->isoc_ctl.vfield = field;
  277. }
  278. break;
  279. case TM6000_URB_MSG_VBI:
  280. break;
  281. case TM6000_URB_MSG_AUDIO:
  282. case TM6000_URB_MSG_PTS:
  283. size = pktsize; /* Size is always 180 bytes */
  284. break;
  285. }
  286. } else {
  287. /* Continue the last copy */
  288. cmd = dev->isoc_ctl.cmd;
  289. size = dev->isoc_ctl.size;
  290. pos = dev->isoc_ctl.pos;
  291. pktsize = dev->isoc_ctl.pktsize;
  292. field = dev->isoc_ctl.field;
  293. }
  294. cpysize = (endp - ptr > size) ? size : endp - ptr;
  295. if (cpysize) {
  296. /* copy data in different buffers */
  297. switch (cmd) {
  298. case TM6000_URB_MSG_VIDEO:
  299. /* Fills video buffer */
  300. if (vbuf)
  301. memcpy(&voutp[pos], ptr, cpysize);
  302. break;
  303. case TM6000_URB_MSG_AUDIO: {
  304. int i;
  305. for (i = 0; i < cpysize; i += 2)
  306. swab16s((u16 *)(ptr + i));
  307. tm6000_call_fillbuf(dev, TM6000_AUDIO, ptr, cpysize);
  308. break;
  309. }
  310. case TM6000_URB_MSG_VBI:
  311. /* Need some code to copy vbi buffer */
  312. break;
  313. case TM6000_URB_MSG_PTS: {
  314. /* Need some code to copy pts */
  315. u32 pts;
  316. pts = *(u32 *)ptr;
  317. dprintk(dev, V4L2_DEBUG_ISOC, "field %d, PTS %x",
  318. field, pts);
  319. break;
  320. }
  321. }
  322. }
  323. if (ptr + pktsize > endp) {
  324. /*
  325. * End of URB packet, but cmd processing is not
  326. * complete. Preserve the state for a next packet
  327. */
  328. dev->isoc_ctl.pos = pos + cpysize;
  329. dev->isoc_ctl.size = size - cpysize;
  330. dev->isoc_ctl.cmd = cmd;
  331. dev->isoc_ctl.field = field;
  332. dev->isoc_ctl.pktsize = pktsize - (endp - ptr);
  333. ptr += endp - ptr;
  334. } else {
  335. dev->isoc_ctl.cmd = 0;
  336. ptr += pktsize;
  337. }
  338. }
  339. return 0;
  340. }
  341. /*
  342. * Identify the tm5600/6000 buffer header type and properly handles
  343. */
  344. static int copy_multiplexed(u8 *ptr, unsigned long len,
  345. struct urb *urb)
  346. {
  347. struct tm6000_dmaqueue *dma_q = urb->context;
  348. struct tm6000_core *dev = container_of(dma_q, struct tm6000_core, vidq);
  349. unsigned int pos = dev->isoc_ctl.pos, cpysize;
  350. int rc = 1;
  351. struct tm6000_buffer *buf;
  352. char *outp = NULL;
  353. get_next_buf(dma_q, &buf);
  354. if (buf)
  355. outp = videobuf_to_vmalloc(&buf->vb);
  356. if (!outp)
  357. return 0;
  358. while (len > 0) {
  359. cpysize = min(len, buf->vb.size-pos);
  360. memcpy(&outp[pos], ptr, cpysize);
  361. pos += cpysize;
  362. ptr += cpysize;
  363. len -= cpysize;
  364. if (pos >= buf->vb.size) {
  365. pos = 0;
  366. /* Announces that a new buffer were filled */
  367. buffer_filled(dev, dma_q, buf);
  368. dprintk(dev, V4L2_DEBUG_ISOC, "new buffer filled\n");
  369. get_next_buf(dma_q, &buf);
  370. if (!buf)
  371. break;
  372. outp = videobuf_to_vmalloc(&(buf->vb));
  373. if (!outp)
  374. return rc;
  375. pos = 0;
  376. }
  377. }
  378. dev->isoc_ctl.pos = pos;
  379. return rc;
  380. }
  381. static inline void print_err_status(struct tm6000_core *dev,
  382. int packet, int status)
  383. {
  384. char *errmsg = "Unknown";
  385. switch (status) {
  386. case -ENOENT:
  387. errmsg = "unlinked synchronuously";
  388. break;
  389. case -ECONNRESET:
  390. errmsg = "unlinked asynchronuously";
  391. break;
  392. case -ENOSR:
  393. errmsg = "Buffer error (overrun)";
  394. break;
  395. case -EPIPE:
  396. errmsg = "Stalled (device not responding)";
  397. break;
  398. case -EOVERFLOW:
  399. errmsg = "Babble (bad cable?)";
  400. break;
  401. case -EPROTO:
  402. errmsg = "Bit-stuff error (bad cable?)";
  403. break;
  404. case -EILSEQ:
  405. errmsg = "CRC/Timeout (could be anything)";
  406. break;
  407. case -ETIME:
  408. errmsg = "Device does not respond";
  409. break;
  410. }
  411. if (packet < 0) {
  412. dprintk(dev, V4L2_DEBUG_QUEUE, "URB status %d [%s].\n",
  413. status, errmsg);
  414. } else {
  415. dprintk(dev, V4L2_DEBUG_QUEUE, "URB packet %d, status %d [%s].\n",
  416. packet, status, errmsg);
  417. }
  418. }
  419. /*
  420. * Controls the isoc copy of each urb packet
  421. */
  422. static inline int tm6000_isoc_copy(struct urb *urb)
  423. {
  424. struct tm6000_dmaqueue *dma_q = urb->context;
  425. struct tm6000_core *dev = container_of(dma_q, struct tm6000_core, vidq);
  426. int i, len = 0, rc = 1, status;
  427. char *p;
  428. if (urb->status < 0) {
  429. print_err_status(dev, -1, urb->status);
  430. return 0;
  431. }
  432. for (i = 0; i < urb->number_of_packets; i++) {
  433. status = urb->iso_frame_desc[i].status;
  434. if (status < 0) {
  435. print_err_status(dev, i, status);
  436. continue;
  437. }
  438. len = urb->iso_frame_desc[i].actual_length;
  439. if (len > 0) {
  440. p = urb->transfer_buffer + urb->iso_frame_desc[i].offset;
  441. if (!urb->iso_frame_desc[i].status) {
  442. if ((dev->fourcc) == V4L2_PIX_FMT_TM6000) {
  443. rc = copy_multiplexed(p, len, urb);
  444. if (rc <= 0)
  445. return rc;
  446. } else {
  447. copy_streams(p, len, urb);
  448. }
  449. }
  450. }
  451. }
  452. return rc;
  453. }
  454. /* ------------------------------------------------------------------
  455. * URB control
  456. * ------------------------------------------------------------------
  457. */
  458. /*
  459. * IRQ callback, called by URB callback
  460. */
  461. static void tm6000_irq_callback(struct urb *urb)
  462. {
  463. struct tm6000_dmaqueue *dma_q = urb->context;
  464. struct tm6000_core *dev = container_of(dma_q, struct tm6000_core, vidq);
  465. int i;
  466. switch (urb->status) {
  467. case 0:
  468. case -ETIMEDOUT:
  469. break;
  470. case -ECONNRESET:
  471. case -ENOENT:
  472. case -ESHUTDOWN:
  473. return;
  474. default:
  475. tm6000_err("urb completion error %d.\n", urb->status);
  476. break;
  477. }
  478. spin_lock(&dev->slock);
  479. tm6000_isoc_copy(urb);
  480. spin_unlock(&dev->slock);
  481. /* Reset urb buffers */
  482. for (i = 0; i < urb->number_of_packets; i++) {
  483. urb->iso_frame_desc[i].status = 0;
  484. urb->iso_frame_desc[i].actual_length = 0;
  485. }
  486. urb->status = usb_submit_urb(urb, GFP_ATOMIC);
  487. if (urb->status)
  488. tm6000_err("urb resubmit failed (error=%i)\n",
  489. urb->status);
  490. }
  491. /*
  492. * Allocate URB buffers
  493. */
  494. static int tm6000_alloc_urb_buffers(struct tm6000_core *dev)
  495. {
  496. int num_bufs = TM6000_NUM_URB_BUF;
  497. int i;
  498. if (dev->urb_buffer != NULL)
  499. return 0;
  500. dev->urb_buffer = kmalloc(sizeof(void *)*num_bufs, GFP_KERNEL);
  501. if (!dev->urb_buffer) {
  502. tm6000_err("cannot allocate memory for urb buffers\n");
  503. return -ENOMEM;
  504. }
  505. dev->urb_dma = kmalloc(sizeof(dma_addr_t *)*num_bufs, GFP_KERNEL);
  506. if (!dev->urb_dma) {
  507. tm6000_err("cannot allocate memory for urb dma pointers\n");
  508. return -ENOMEM;
  509. }
  510. for (i = 0; i < num_bufs; i++) {
  511. dev->urb_buffer[i] = usb_alloc_coherent(
  512. dev->udev, dev->urb_size,
  513. GFP_KERNEL, &dev->urb_dma[i]);
  514. if (!dev->urb_buffer[i]) {
  515. tm6000_err("unable to allocate %i bytes for transfer buffer %i\n",
  516. dev->urb_size, i);
  517. return -ENOMEM;
  518. }
  519. memset(dev->urb_buffer[i], 0, dev->urb_size);
  520. }
  521. return 0;
  522. }
  523. /*
  524. * Free URB buffers
  525. */
  526. static int tm6000_free_urb_buffers(struct tm6000_core *dev)
  527. {
  528. int i;
  529. if (dev->urb_buffer == NULL)
  530. return 0;
  531. for (i = 0; i < TM6000_NUM_URB_BUF; i++) {
  532. if (dev->urb_buffer[i]) {
  533. usb_free_coherent(dev->udev,
  534. dev->urb_size,
  535. dev->urb_buffer[i],
  536. dev->urb_dma[i]);
  537. dev->urb_buffer[i] = NULL;
  538. }
  539. }
  540. kfree(dev->urb_buffer);
  541. kfree(dev->urb_dma);
  542. dev->urb_buffer = NULL;
  543. dev->urb_dma = NULL;
  544. return 0;
  545. }
  546. /*
  547. * Stop and Deallocate URBs
  548. */
  549. static void tm6000_uninit_isoc(struct tm6000_core *dev)
  550. {
  551. struct urb *urb;
  552. int i;
  553. dev->isoc_ctl.buf = NULL;
  554. for (i = 0; i < dev->isoc_ctl.num_bufs; i++) {
  555. urb = dev->isoc_ctl.urb[i];
  556. if (urb) {
  557. usb_kill_urb(urb);
  558. usb_unlink_urb(urb);
  559. usb_free_urb(urb);
  560. dev->isoc_ctl.urb[i] = NULL;
  561. }
  562. dev->isoc_ctl.transfer_buffer[i] = NULL;
  563. }
  564. if (!keep_urb)
  565. tm6000_free_urb_buffers(dev);
  566. kfree(dev->isoc_ctl.urb);
  567. kfree(dev->isoc_ctl.transfer_buffer);
  568. dev->isoc_ctl.urb = NULL;
  569. dev->isoc_ctl.transfer_buffer = NULL;
  570. dev->isoc_ctl.num_bufs = 0;
  571. }
  572. /*
  573. * Assign URBs and start IRQ
  574. */
  575. static int tm6000_prepare_isoc(struct tm6000_core *dev)
  576. {
  577. struct tm6000_dmaqueue *dma_q = &dev->vidq;
  578. int i, j, sb_size, pipe, size, max_packets;
  579. int num_bufs = TM6000_NUM_URB_BUF;
  580. struct urb *urb;
  581. /* De-allocates all pending stuff */
  582. tm6000_uninit_isoc(dev);
  583. /* Stop interrupt USB pipe */
  584. tm6000_ir_int_stop(dev);
  585. usb_set_interface(dev->udev,
  586. dev->isoc_in.bInterfaceNumber,
  587. dev->isoc_in.bAlternateSetting);
  588. /* Start interrupt USB pipe */
  589. tm6000_ir_int_start(dev);
  590. pipe = usb_rcvisocpipe(dev->udev,
  591. dev->isoc_in.endp->desc.bEndpointAddress &
  592. USB_ENDPOINT_NUMBER_MASK);
  593. size = usb_maxpacket(dev->udev, pipe, usb_pipeout(pipe));
  594. if (size > dev->isoc_in.maxsize)
  595. size = dev->isoc_in.maxsize;
  596. dev->isoc_ctl.max_pkt_size = size;
  597. max_packets = TM6000_MAX_ISO_PACKETS;
  598. sb_size = max_packets * size;
  599. dev->urb_size = sb_size;
  600. dev->isoc_ctl.num_bufs = num_bufs;
  601. dev->isoc_ctl.urb = kmalloc(sizeof(void *)*num_bufs, GFP_KERNEL);
  602. if (!dev->isoc_ctl.urb) {
  603. tm6000_err("cannot alloc memory for usb buffers\n");
  604. return -ENOMEM;
  605. }
  606. dev->isoc_ctl.transfer_buffer = kmalloc(sizeof(void *)*num_bufs,
  607. GFP_KERNEL);
  608. if (!dev->isoc_ctl.transfer_buffer) {
  609. tm6000_err("cannot allocate memory for usbtransfer\n");
  610. kfree(dev->isoc_ctl.urb);
  611. return -ENOMEM;
  612. }
  613. dprintk(dev, V4L2_DEBUG_QUEUE, "Allocating %d x %d packets"
  614. " (%d bytes) of %d bytes each to handle %u size\n",
  615. max_packets, num_bufs, sb_size,
  616. dev->isoc_in.maxsize, size);
  617. if (!dev->urb_buffer && tm6000_alloc_urb_buffers(dev) < 0) {
  618. tm6000_err("cannot allocate memory for urb buffers\n");
  619. /* call free, as some buffers might have been allocated */
  620. tm6000_free_urb_buffers(dev);
  621. kfree(dev->isoc_ctl.urb);
  622. kfree(dev->isoc_ctl.transfer_buffer);
  623. return -ENOMEM;
  624. }
  625. /* allocate urbs and transfer buffers */
  626. for (i = 0; i < dev->isoc_ctl.num_bufs; i++) {
  627. urb = usb_alloc_urb(max_packets, GFP_KERNEL);
  628. if (!urb) {
  629. tm6000_err("cannot alloc isoc_ctl.urb %i\n", i);
  630. tm6000_uninit_isoc(dev);
  631. usb_free_urb(urb);
  632. return -ENOMEM;
  633. }
  634. dev->isoc_ctl.urb[i] = urb;
  635. urb->transfer_dma = dev->urb_dma[i];
  636. dev->isoc_ctl.transfer_buffer[i] = dev->urb_buffer[i];
  637. usb_fill_bulk_urb(urb, dev->udev, pipe,
  638. dev->isoc_ctl.transfer_buffer[i], sb_size,
  639. tm6000_irq_callback, dma_q);
  640. urb->interval = dev->isoc_in.endp->desc.bInterval;
  641. urb->number_of_packets = max_packets;
  642. urb->transfer_flags = URB_ISO_ASAP | URB_NO_TRANSFER_DMA_MAP;
  643. for (j = 0; j < max_packets; j++) {
  644. urb->iso_frame_desc[j].offset = size * j;
  645. urb->iso_frame_desc[j].length = size;
  646. }
  647. }
  648. return 0;
  649. }
  650. static int tm6000_start_thread(struct tm6000_core *dev)
  651. {
  652. struct tm6000_dmaqueue *dma_q = &dev->vidq;
  653. int i;
  654. dma_q->frame = 0;
  655. dma_q->ini_jiffies = jiffies;
  656. init_waitqueue_head(&dma_q->wq);
  657. /* submit urbs and enables IRQ */
  658. for (i = 0; i < dev->isoc_ctl.num_bufs; i++) {
  659. int rc = usb_submit_urb(dev->isoc_ctl.urb[i], GFP_ATOMIC);
  660. if (rc) {
  661. tm6000_err("submit of urb %i failed (error=%i)\n", i,
  662. rc);
  663. tm6000_uninit_isoc(dev);
  664. return rc;
  665. }
  666. }
  667. return 0;
  668. }
  669. /* ------------------------------------------------------------------
  670. * Videobuf operations
  671. * ------------------------------------------------------------------
  672. */
  673. static int
  674. buffer_setup(struct videobuf_queue *vq, unsigned int *count, unsigned int *size)
  675. {
  676. struct tm6000_fh *fh = vq->priv_data;
  677. *size = fh->fmt->depth * fh->width * fh->height >> 3;
  678. if (0 == *count)
  679. *count = TM6000_DEF_BUF;
  680. if (*count < TM6000_MIN_BUF)
  681. *count = TM6000_MIN_BUF;
  682. while (*size * *count > vid_limit * 1024 * 1024)
  683. (*count)--;
  684. return 0;
  685. }
  686. static void free_buffer(struct videobuf_queue *vq, struct tm6000_buffer *buf)
  687. {
  688. struct tm6000_fh *fh = vq->priv_data;
  689. struct tm6000_core *dev = fh->dev;
  690. unsigned long flags;
  691. if (in_interrupt())
  692. BUG();
  693. /* We used to wait for the buffer to finish here, but this didn't work
  694. because, as we were keeping the state as VIDEOBUF_QUEUED,
  695. videobuf_queue_cancel marked it as finished for us.
  696. (Also, it could wedge forever if the hardware was misconfigured.)
  697. This should be safe; by the time we get here, the buffer isn't
  698. queued anymore. If we ever start marking the buffers as
  699. VIDEOBUF_ACTIVE, it won't be, though.
  700. */
  701. spin_lock_irqsave(&dev->slock, flags);
  702. if (dev->isoc_ctl.buf == buf)
  703. dev->isoc_ctl.buf = NULL;
  704. spin_unlock_irqrestore(&dev->slock, flags);
  705. videobuf_vmalloc_free(&buf->vb);
  706. buf->vb.state = VIDEOBUF_NEEDS_INIT;
  707. }
  708. static int
  709. buffer_prepare(struct videobuf_queue *vq, struct videobuf_buffer *vb,
  710. enum v4l2_field field)
  711. {
  712. struct tm6000_fh *fh = vq->priv_data;
  713. struct tm6000_buffer *buf = container_of(vb, struct tm6000_buffer, vb);
  714. struct tm6000_core *dev = fh->dev;
  715. int rc = 0;
  716. BUG_ON(NULL == fh->fmt);
  717. /* FIXME: It assumes depth=2 */
  718. /* The only currently supported format is 16 bits/pixel */
  719. buf->vb.size = fh->fmt->depth*fh->width*fh->height >> 3;
  720. if (0 != buf->vb.baddr && buf->vb.bsize < buf->vb.size)
  721. return -EINVAL;
  722. if (buf->fmt != fh->fmt ||
  723. buf->vb.width != fh->width ||
  724. buf->vb.height != fh->height ||
  725. buf->vb.field != field) {
  726. buf->fmt = fh->fmt;
  727. buf->vb.width = fh->width;
  728. buf->vb.height = fh->height;
  729. buf->vb.field = field;
  730. buf->vb.state = VIDEOBUF_NEEDS_INIT;
  731. }
  732. if (VIDEOBUF_NEEDS_INIT == buf->vb.state) {
  733. rc = videobuf_iolock(vq, &buf->vb, NULL);
  734. if (rc != 0)
  735. goto fail;
  736. }
  737. if (!dev->isoc_ctl.num_bufs) {
  738. rc = tm6000_prepare_isoc(dev);
  739. if (rc < 0)
  740. goto fail;
  741. rc = tm6000_start_thread(dev);
  742. if (rc < 0)
  743. goto fail;
  744. }
  745. buf->vb.state = VIDEOBUF_PREPARED;
  746. return 0;
  747. fail:
  748. free_buffer(vq, buf);
  749. return rc;
  750. }
  751. static void
  752. buffer_queue(struct videobuf_queue *vq, struct videobuf_buffer *vb)
  753. {
  754. struct tm6000_buffer *buf = container_of(vb, struct tm6000_buffer, vb);
  755. struct tm6000_fh *fh = vq->priv_data;
  756. struct tm6000_core *dev = fh->dev;
  757. struct tm6000_dmaqueue *vidq = &dev->vidq;
  758. buf->vb.state = VIDEOBUF_QUEUED;
  759. list_add_tail(&buf->vb.queue, &vidq->active);
  760. }
  761. static void buffer_release(struct videobuf_queue *vq, struct videobuf_buffer *vb)
  762. {
  763. struct tm6000_buffer *buf = container_of(vb, struct tm6000_buffer, vb);
  764. free_buffer(vq, buf);
  765. }
  766. static struct videobuf_queue_ops tm6000_video_qops = {
  767. .buf_setup = buffer_setup,
  768. .buf_prepare = buffer_prepare,
  769. .buf_queue = buffer_queue,
  770. .buf_release = buffer_release,
  771. };
  772. /* ------------------------------------------------------------------
  773. * IOCTL handling
  774. * ------------------------------------------------------------------
  775. */
  776. static bool is_res_read(struct tm6000_core *dev, struct tm6000_fh *fh)
  777. {
  778. /* Is the current fh handling it? if so, that's OK */
  779. if (dev->resources == fh && dev->is_res_read)
  780. return true;
  781. return false;
  782. }
  783. static bool is_res_streaming(struct tm6000_core *dev, struct tm6000_fh *fh)
  784. {
  785. /* Is the current fh handling it? if so, that's OK */
  786. if (dev->resources == fh)
  787. return true;
  788. return false;
  789. }
  790. static bool res_get(struct tm6000_core *dev, struct tm6000_fh *fh,
  791. bool is_res_read)
  792. {
  793. /* Is the current fh handling it? if so, that's OK */
  794. if (dev->resources == fh && dev->is_res_read == is_res_read)
  795. return true;
  796. /* is it free? */
  797. if (dev->resources)
  798. return false;
  799. /* grab it */
  800. dev->resources = fh;
  801. dev->is_res_read = is_res_read;
  802. dprintk(dev, V4L2_DEBUG_RES_LOCK, "res: get\n");
  803. return true;
  804. }
  805. static void res_free(struct tm6000_core *dev, struct tm6000_fh *fh)
  806. {
  807. /* Is the current fh handling it? if so, that's OK */
  808. if (dev->resources != fh)
  809. return;
  810. dev->resources = NULL;
  811. dprintk(dev, V4L2_DEBUG_RES_LOCK, "res: put\n");
  812. }
  813. /* ------------------------------------------------------------------
  814. * IOCTL vidioc handling
  815. * ------------------------------------------------------------------
  816. */
  817. static int vidioc_querycap(struct file *file, void *priv,
  818. struct v4l2_capability *cap)
  819. {
  820. struct tm6000_core *dev = ((struct tm6000_fh *)priv)->dev;
  821. strlcpy(cap->driver, "tm6000", sizeof(cap->driver));
  822. strlcpy(cap->card, "Trident TVMaster TM5600/6000/6010", sizeof(cap->card));
  823. cap->capabilities = V4L2_CAP_VIDEO_CAPTURE |
  824. V4L2_CAP_STREAMING |
  825. V4L2_CAP_AUDIO |
  826. V4L2_CAP_READWRITE;
  827. if (dev->tuner_type != TUNER_ABSENT)
  828. cap->capabilities |= V4L2_CAP_TUNER;
  829. return 0;
  830. }
  831. static int vidioc_enum_fmt_vid_cap(struct file *file, void *priv,
  832. struct v4l2_fmtdesc *f)
  833. {
  834. if (unlikely(f->index >= ARRAY_SIZE(format)))
  835. return -EINVAL;
  836. strlcpy(f->description, format[f->index].name, sizeof(f->description));
  837. f->pixelformat = format[f->index].fourcc;
  838. return 0;
  839. }
  840. static int vidioc_g_fmt_vid_cap(struct file *file, void *priv,
  841. struct v4l2_format *f)
  842. {
  843. struct tm6000_fh *fh = priv;
  844. f->fmt.pix.width = fh->width;
  845. f->fmt.pix.height = fh->height;
  846. f->fmt.pix.field = fh->vb_vidq.field;
  847. f->fmt.pix.pixelformat = fh->fmt->fourcc;
  848. f->fmt.pix.bytesperline =
  849. (f->fmt.pix.width * fh->fmt->depth) >> 3;
  850. f->fmt.pix.sizeimage =
  851. f->fmt.pix.height * f->fmt.pix.bytesperline;
  852. return 0;
  853. }
  854. static struct tm6000_fmt *format_by_fourcc(unsigned int fourcc)
  855. {
  856. unsigned int i;
  857. for (i = 0; i < ARRAY_SIZE(format); i++)
  858. if (format[i].fourcc == fourcc)
  859. return format+i;
  860. return NULL;
  861. }
  862. static int vidioc_try_fmt_vid_cap(struct file *file, void *priv,
  863. struct v4l2_format *f)
  864. {
  865. struct tm6000_core *dev = ((struct tm6000_fh *)priv)->dev;
  866. struct tm6000_fmt *fmt;
  867. enum v4l2_field field;
  868. fmt = format_by_fourcc(f->fmt.pix.pixelformat);
  869. if (NULL == fmt) {
  870. dprintk(dev, V4L2_DEBUG_IOCTL_ARG, "Fourcc format (0x%08x)"
  871. " invalid.\n", f->fmt.pix.pixelformat);
  872. return -EINVAL;
  873. }
  874. field = f->fmt.pix.field;
  875. if (field == V4L2_FIELD_ANY)
  876. field = V4L2_FIELD_SEQ_TB;
  877. else if (V4L2_FIELD_INTERLACED != field) {
  878. dprintk(dev, V4L2_DEBUG_IOCTL_ARG, "Field type invalid.\n");
  879. return -EINVAL;
  880. }
  881. tm6000_get_std_res(dev);
  882. f->fmt.pix.width = dev->width;
  883. f->fmt.pix.height = dev->height;
  884. f->fmt.pix.width &= ~0x01;
  885. f->fmt.pix.field = field;
  886. f->fmt.pix.bytesperline =
  887. (f->fmt.pix.width * fmt->depth) >> 3;
  888. f->fmt.pix.sizeimage =
  889. f->fmt.pix.height * f->fmt.pix.bytesperline;
  890. return 0;
  891. }
  892. /*FIXME: This seems to be generic enough to be at videodev2 */
  893. static int vidioc_s_fmt_vid_cap(struct file *file, void *priv,
  894. struct v4l2_format *f)
  895. {
  896. struct tm6000_fh *fh = priv;
  897. struct tm6000_core *dev = fh->dev;
  898. int ret = vidioc_try_fmt_vid_cap(file, fh, f);
  899. if (ret < 0)
  900. return ret;
  901. fh->fmt = format_by_fourcc(f->fmt.pix.pixelformat);
  902. fh->width = f->fmt.pix.width;
  903. fh->height = f->fmt.pix.height;
  904. fh->vb_vidq.field = f->fmt.pix.field;
  905. fh->type = f->type;
  906. dev->fourcc = f->fmt.pix.pixelformat;
  907. tm6000_set_fourcc_format(dev);
  908. return 0;
  909. }
  910. static int vidioc_reqbufs(struct file *file, void *priv,
  911. struct v4l2_requestbuffers *p)
  912. {
  913. struct tm6000_fh *fh = priv;
  914. return videobuf_reqbufs(&fh->vb_vidq, p);
  915. }
  916. static int vidioc_querybuf(struct file *file, void *priv,
  917. struct v4l2_buffer *p)
  918. {
  919. struct tm6000_fh *fh = priv;
  920. return videobuf_querybuf(&fh->vb_vidq, p);
  921. }
  922. static int vidioc_qbuf(struct file *file, void *priv, struct v4l2_buffer *p)
  923. {
  924. struct tm6000_fh *fh = priv;
  925. return videobuf_qbuf(&fh->vb_vidq, p);
  926. }
  927. static int vidioc_dqbuf(struct file *file, void *priv, struct v4l2_buffer *p)
  928. {
  929. struct tm6000_fh *fh = priv;
  930. return videobuf_dqbuf(&fh->vb_vidq, p,
  931. file->f_flags & O_NONBLOCK);
  932. }
  933. static int vidioc_streamon(struct file *file, void *priv, enum v4l2_buf_type i)
  934. {
  935. struct tm6000_fh *fh = priv;
  936. struct tm6000_core *dev = fh->dev;
  937. if (fh->type != V4L2_BUF_TYPE_VIDEO_CAPTURE)
  938. return -EINVAL;
  939. if (i != fh->type)
  940. return -EINVAL;
  941. if (!res_get(dev, fh, false))
  942. return -EBUSY;
  943. return videobuf_streamon(&fh->vb_vidq);
  944. }
  945. static int vidioc_streamoff(struct file *file, void *priv, enum v4l2_buf_type i)
  946. {
  947. struct tm6000_fh *fh = priv;
  948. struct tm6000_core *dev = fh->dev;
  949. if (fh->type != V4L2_BUF_TYPE_VIDEO_CAPTURE)
  950. return -EINVAL;
  951. if (i != fh->type)
  952. return -EINVAL;
  953. videobuf_streamoff(&fh->vb_vidq);
  954. res_free(dev, fh);
  955. return 0;
  956. }
  957. static int vidioc_s_std(struct file *file, void *priv, v4l2_std_id *norm)
  958. {
  959. int rc = 0;
  960. struct tm6000_fh *fh = priv;
  961. struct tm6000_core *dev = fh->dev;
  962. dev->norm = *norm;
  963. rc = tm6000_init_analog_mode(dev);
  964. fh->width = dev->width;
  965. fh->height = dev->height;
  966. if (rc < 0)
  967. return rc;
  968. v4l2_device_call_all(&dev->v4l2_dev, 0, core, s_std, dev->norm);
  969. return 0;
  970. }
  971. static const char *iname[] = {
  972. [TM6000_INPUT_TV] = "Television",
  973. [TM6000_INPUT_COMPOSITE1] = "Composite 1",
  974. [TM6000_INPUT_COMPOSITE2] = "Composite 2",
  975. [TM6000_INPUT_SVIDEO] = "S-Video",
  976. };
  977. static int vidioc_enum_input(struct file *file, void *priv,
  978. struct v4l2_input *i)
  979. {
  980. struct tm6000_fh *fh = priv;
  981. struct tm6000_core *dev = fh->dev;
  982. unsigned int n;
  983. n = i->index;
  984. if (n >= 3)
  985. return -EINVAL;
  986. if (!dev->vinput[n].type)
  987. return -EINVAL;
  988. i->index = n;
  989. if (dev->vinput[n].type == TM6000_INPUT_TV)
  990. i->type = V4L2_INPUT_TYPE_TUNER;
  991. else
  992. i->type = V4L2_INPUT_TYPE_CAMERA;
  993. strcpy(i->name, iname[dev->vinput[n].type]);
  994. i->std = TM6000_STD;
  995. return 0;
  996. }
  997. static int vidioc_g_input(struct file *file, void *priv, unsigned int *i)
  998. {
  999. struct tm6000_fh *fh = priv;
  1000. struct tm6000_core *dev = fh->dev;
  1001. *i = dev->input;
  1002. return 0;
  1003. }
  1004. static int vidioc_s_input(struct file *file, void *priv, unsigned int i)
  1005. {
  1006. struct tm6000_fh *fh = priv;
  1007. struct tm6000_core *dev = fh->dev;
  1008. int rc = 0;
  1009. if (i >= 3)
  1010. return -EINVAL;
  1011. if (!dev->vinput[i].type)
  1012. return -EINVAL;
  1013. dev->input = i;
  1014. rc = vidioc_s_std(file, priv, &dev->vfd->current_norm);
  1015. return rc;
  1016. }
  1017. /* --- controls ---------------------------------------------- */
  1018. static int vidioc_queryctrl(struct file *file, void *priv,
  1019. struct v4l2_queryctrl *qc)
  1020. {
  1021. int i;
  1022. for (i = 0; i < ARRAY_SIZE(tm6000_qctrl); i++)
  1023. if (qc->id && qc->id == tm6000_qctrl[i].id) {
  1024. memcpy(qc, &(tm6000_qctrl[i]),
  1025. sizeof(*qc));
  1026. return 0;
  1027. }
  1028. return -EINVAL;
  1029. }
  1030. static int vidioc_g_ctrl(struct file *file, void *priv,
  1031. struct v4l2_control *ctrl)
  1032. {
  1033. struct tm6000_fh *fh = priv;
  1034. struct tm6000_core *dev = fh->dev;
  1035. int val;
  1036. /* FIXME: Probably, those won't work! Maybe we need shadow regs */
  1037. switch (ctrl->id) {
  1038. case V4L2_CID_CONTRAST:
  1039. val = tm6000_get_reg(dev, TM6010_REQ07_R08_LUMA_CONTRAST_ADJ, 0);
  1040. break;
  1041. case V4L2_CID_BRIGHTNESS:
  1042. val = tm6000_get_reg(dev, TM6010_REQ07_R09_LUMA_BRIGHTNESS_ADJ, 0);
  1043. return 0;
  1044. case V4L2_CID_SATURATION:
  1045. val = tm6000_get_reg(dev, TM6010_REQ07_R0A_CHROMA_SATURATION_ADJ, 0);
  1046. return 0;
  1047. case V4L2_CID_HUE:
  1048. val = tm6000_get_reg(dev, TM6010_REQ07_R0B_CHROMA_HUE_PHASE_ADJ, 0);
  1049. return 0;
  1050. case V4L2_CID_AUDIO_MUTE:
  1051. val = dev->ctl_mute;
  1052. return 0;
  1053. case V4L2_CID_AUDIO_VOLUME:
  1054. val = dev->ctl_volume;
  1055. return 0;
  1056. default:
  1057. return -EINVAL;
  1058. }
  1059. if (val < 0)
  1060. return val;
  1061. ctrl->value = val;
  1062. return 0;
  1063. }
  1064. static int vidioc_s_ctrl(struct file *file, void *priv,
  1065. struct v4l2_control *ctrl)
  1066. {
  1067. struct tm6000_fh *fh = priv;
  1068. struct tm6000_core *dev = fh->dev;
  1069. u8 val = ctrl->value;
  1070. switch (ctrl->id) {
  1071. case V4L2_CID_CONTRAST:
  1072. tm6000_set_reg(dev, TM6010_REQ07_R08_LUMA_CONTRAST_ADJ, val);
  1073. return 0;
  1074. case V4L2_CID_BRIGHTNESS:
  1075. tm6000_set_reg(dev, TM6010_REQ07_R09_LUMA_BRIGHTNESS_ADJ, val);
  1076. return 0;
  1077. case V4L2_CID_SATURATION:
  1078. tm6000_set_reg(dev, TM6010_REQ07_R0A_CHROMA_SATURATION_ADJ, val);
  1079. return 0;
  1080. case V4L2_CID_HUE:
  1081. tm6000_set_reg(dev, TM6010_REQ07_R0B_CHROMA_HUE_PHASE_ADJ, val);
  1082. return 0;
  1083. case V4L2_CID_AUDIO_MUTE:
  1084. dev->ctl_mute = val;
  1085. tm6000_tvaudio_set_mute(dev, val);
  1086. return 0;
  1087. case V4L2_CID_AUDIO_VOLUME:
  1088. dev->ctl_volume = val;
  1089. tm6000_set_volume(dev, val);
  1090. return 0;
  1091. }
  1092. return -EINVAL;
  1093. }
  1094. static int vidioc_g_tuner(struct file *file, void *priv,
  1095. struct v4l2_tuner *t)
  1096. {
  1097. struct tm6000_fh *fh = priv;
  1098. struct tm6000_core *dev = fh->dev;
  1099. if (unlikely(UNSET == dev->tuner_type))
  1100. return -EINVAL;
  1101. if (0 != t->index)
  1102. return -EINVAL;
  1103. strcpy(t->name, "Television");
  1104. t->type = V4L2_TUNER_ANALOG_TV;
  1105. t->capability = V4L2_TUNER_CAP_NORM;
  1106. t->rangehigh = 0xffffffffUL;
  1107. t->rxsubchans = V4L2_TUNER_SUB_STEREO;
  1108. v4l2_device_call_all(&dev->v4l2_dev, 0, tuner, g_tuner, t);
  1109. t->audmode = dev->amode;
  1110. return 0;
  1111. }
  1112. static int vidioc_s_tuner(struct file *file, void *priv,
  1113. struct v4l2_tuner *t)
  1114. {
  1115. struct tm6000_fh *fh = priv;
  1116. struct tm6000_core *dev = fh->dev;
  1117. if (UNSET == dev->tuner_type)
  1118. return -EINVAL;
  1119. if (0 != t->index)
  1120. return -EINVAL;
  1121. dev->amode = t->audmode;
  1122. dprintk(dev, 3, "audio mode: %x\n", t->audmode);
  1123. v4l2_device_call_all(&dev->v4l2_dev, 0, tuner, s_tuner, t);
  1124. return 0;
  1125. }
  1126. static int vidioc_g_frequency(struct file *file, void *priv,
  1127. struct v4l2_frequency *f)
  1128. {
  1129. struct tm6000_fh *fh = priv;
  1130. struct tm6000_core *dev = fh->dev;
  1131. if (unlikely(UNSET == dev->tuner_type))
  1132. return -EINVAL;
  1133. f->type = fh->radio ? V4L2_TUNER_RADIO : V4L2_TUNER_ANALOG_TV;
  1134. f->frequency = dev->freq;
  1135. v4l2_device_call_all(&dev->v4l2_dev, 0, tuner, g_frequency, f);
  1136. return 0;
  1137. }
  1138. static int vidioc_s_frequency(struct file *file, void *priv,
  1139. struct v4l2_frequency *f)
  1140. {
  1141. struct tm6000_fh *fh = priv;
  1142. struct tm6000_core *dev = fh->dev;
  1143. if (unlikely(UNSET == dev->tuner_type))
  1144. return -EINVAL;
  1145. if (unlikely(f->tuner != 0))
  1146. return -EINVAL;
  1147. if (0 == fh->radio && V4L2_TUNER_ANALOG_TV != f->type)
  1148. return -EINVAL;
  1149. if (1 == fh->radio && V4L2_TUNER_RADIO != f->type)
  1150. return -EINVAL;
  1151. dev->freq = f->frequency;
  1152. v4l2_device_call_all(&dev->v4l2_dev, 0, tuner, s_frequency, f);
  1153. return 0;
  1154. }
  1155. static int radio_querycap(struct file *file, void *priv,
  1156. struct v4l2_capability *cap)
  1157. {
  1158. struct tm6000_fh *fh = file->private_data;
  1159. struct tm6000_core *dev = fh->dev;
  1160. strcpy(cap->driver, "tm6000");
  1161. strlcpy(cap->card, dev->name, sizeof(dev->name));
  1162. sprintf(cap->bus_info, "USB%04x:%04x",
  1163. le16_to_cpu(dev->udev->descriptor.idVendor),
  1164. le16_to_cpu(dev->udev->descriptor.idProduct));
  1165. cap->version = dev->dev_type;
  1166. cap->capabilities = V4L2_CAP_TUNER |
  1167. V4L2_CAP_AUDIO |
  1168. V4L2_CAP_RADIO |
  1169. V4L2_CAP_READWRITE |
  1170. V4L2_CAP_STREAMING;
  1171. return 0;
  1172. }
  1173. static int radio_g_tuner(struct file *file, void *priv,
  1174. struct v4l2_tuner *t)
  1175. {
  1176. struct tm6000_fh *fh = file->private_data;
  1177. struct tm6000_core *dev = fh->dev;
  1178. if (0 != t->index)
  1179. return -EINVAL;
  1180. memset(t, 0, sizeof(*t));
  1181. strcpy(t->name, "Radio");
  1182. t->type = V4L2_TUNER_RADIO;
  1183. t->rxsubchans = V4L2_TUNER_SUB_STEREO;
  1184. v4l2_device_call_all(&dev->v4l2_dev, 0, tuner, g_tuner, t);
  1185. return 0;
  1186. }
  1187. static int radio_s_tuner(struct file *file, void *priv,
  1188. struct v4l2_tuner *t)
  1189. {
  1190. struct tm6000_fh *fh = file->private_data;
  1191. struct tm6000_core *dev = fh->dev;
  1192. if (0 != t->index)
  1193. return -EINVAL;
  1194. v4l2_device_call_all(&dev->v4l2_dev, 0, tuner, s_tuner, t);
  1195. return 0;
  1196. }
  1197. static int radio_enum_input(struct file *file, void *priv,
  1198. struct v4l2_input *i)
  1199. {
  1200. struct tm6000_fh *fh = priv;
  1201. struct tm6000_core *dev = fh->dev;
  1202. if (i->index != 0)
  1203. return -EINVAL;
  1204. if (!dev->rinput.type)
  1205. return -EINVAL;
  1206. strcpy(i->name, "Radio");
  1207. i->type = V4L2_INPUT_TYPE_TUNER;
  1208. return 0;
  1209. }
  1210. static int radio_g_input(struct file *filp, void *priv, unsigned int *i)
  1211. {
  1212. struct tm6000_fh *fh = priv;
  1213. struct tm6000_core *dev = fh->dev;
  1214. if (dev->input != 5)
  1215. return -EINVAL;
  1216. *i = dev->input - 5;
  1217. return 0;
  1218. }
  1219. static int radio_g_audio(struct file *file, void *priv,
  1220. struct v4l2_audio *a)
  1221. {
  1222. memset(a, 0, sizeof(*a));
  1223. strcpy(a->name, "Radio");
  1224. return 0;
  1225. }
  1226. static int radio_s_audio(struct file *file, void *priv,
  1227. const struct v4l2_audio *a)
  1228. {
  1229. return 0;
  1230. }
  1231. static int radio_s_input(struct file *filp, void *priv, unsigned int i)
  1232. {
  1233. struct tm6000_fh *fh = priv;
  1234. struct tm6000_core *dev = fh->dev;
  1235. if (i)
  1236. return -EINVAL;
  1237. if (!dev->rinput.type)
  1238. return -EINVAL;
  1239. dev->input = i + 5;
  1240. return 0;
  1241. }
  1242. static int radio_s_std(struct file *file, void *fh, v4l2_std_id *norm)
  1243. {
  1244. return 0;
  1245. }
  1246. static int radio_queryctrl(struct file *file, void *priv,
  1247. struct v4l2_queryctrl *c)
  1248. {
  1249. const struct v4l2_queryctrl *ctrl;
  1250. if (c->id < V4L2_CID_BASE ||
  1251. c->id >= V4L2_CID_LASTP1)
  1252. return -EINVAL;
  1253. if (c->id == V4L2_CID_AUDIO_MUTE) {
  1254. ctrl = ctrl_by_id(c->id);
  1255. *c = *ctrl;
  1256. } else
  1257. *c = no_ctrl;
  1258. return 0;
  1259. }
  1260. /* ------------------------------------------------------------------
  1261. File operations for the device
  1262. ------------------------------------------------------------------*/
  1263. static int __tm6000_open(struct file *file)
  1264. {
  1265. struct video_device *vdev = video_devdata(file);
  1266. struct tm6000_core *dev = video_drvdata(file);
  1267. struct tm6000_fh *fh;
  1268. enum v4l2_buf_type type = V4L2_BUF_TYPE_VIDEO_CAPTURE;
  1269. int i, rc;
  1270. int radio = 0;
  1271. dprintk(dev, V4L2_DEBUG_OPEN, "tm6000: open called (dev=%s)\n",
  1272. video_device_node_name(vdev));
  1273. switch (vdev->vfl_type) {
  1274. case VFL_TYPE_GRABBER:
  1275. type = V4L2_BUF_TYPE_VIDEO_CAPTURE;
  1276. break;
  1277. case VFL_TYPE_VBI:
  1278. type = V4L2_BUF_TYPE_VBI_CAPTURE;
  1279. break;
  1280. case VFL_TYPE_RADIO:
  1281. radio = 1;
  1282. break;
  1283. }
  1284. /* If more than one user, mutex should be added */
  1285. dev->users++;
  1286. dprintk(dev, V4L2_DEBUG_OPEN, "open dev=%s type=%s users=%d\n",
  1287. video_device_node_name(vdev), v4l2_type_names[type],
  1288. dev->users);
  1289. /* allocate + initialize per filehandle data */
  1290. fh = kzalloc(sizeof(*fh), GFP_KERNEL);
  1291. if (NULL == fh) {
  1292. dev->users--;
  1293. return -ENOMEM;
  1294. }
  1295. file->private_data = fh;
  1296. fh->dev = dev;
  1297. fh->radio = radio;
  1298. dev->radio = radio;
  1299. fh->type = type;
  1300. dev->fourcc = format[0].fourcc;
  1301. fh->fmt = format_by_fourcc(dev->fourcc);
  1302. tm6000_get_std_res(dev);
  1303. fh->width = dev->width;
  1304. fh->height = dev->height;
  1305. dprintk(dev, V4L2_DEBUG_OPEN, "Open: fh=0x%08lx, dev=0x%08lx, "
  1306. "dev->vidq=0x%08lx\n",
  1307. (unsigned long)fh, (unsigned long)dev,
  1308. (unsigned long)&dev->vidq);
  1309. dprintk(dev, V4L2_DEBUG_OPEN, "Open: list_empty "
  1310. "queued=%d\n", list_empty(&dev->vidq.queued));
  1311. dprintk(dev, V4L2_DEBUG_OPEN, "Open: list_empty "
  1312. "active=%d\n", list_empty(&dev->vidq.active));
  1313. /* initialize hardware on analog mode */
  1314. rc = tm6000_init_analog_mode(dev);
  1315. if (rc < 0)
  1316. return rc;
  1317. if (dev->mode != TM6000_MODE_ANALOG) {
  1318. /* Put all controls at a sane state */
  1319. for (i = 0; i < ARRAY_SIZE(tm6000_qctrl); i++)
  1320. qctl_regs[i] = tm6000_qctrl[i].default_value;
  1321. dev->mode = TM6000_MODE_ANALOG;
  1322. }
  1323. if (!fh->radio) {
  1324. videobuf_queue_vmalloc_init(&fh->vb_vidq, &tm6000_video_qops,
  1325. NULL, &dev->slock,
  1326. fh->type,
  1327. V4L2_FIELD_INTERLACED,
  1328. sizeof(struct tm6000_buffer), fh, &dev->lock);
  1329. } else {
  1330. dprintk(dev, V4L2_DEBUG_OPEN, "video_open: setting radio device\n");
  1331. dev->input = 5;
  1332. tm6000_set_audio_rinput(dev);
  1333. v4l2_device_call_all(&dev->v4l2_dev, 0, tuner, s_radio);
  1334. tm6000_prepare_isoc(dev);
  1335. tm6000_start_thread(dev);
  1336. }
  1337. return 0;
  1338. }
  1339. static int tm6000_open(struct file *file)
  1340. {
  1341. struct video_device *vdev = video_devdata(file);
  1342. int res;
  1343. mutex_lock(vdev->lock);
  1344. res = __tm6000_open(file);
  1345. mutex_unlock(vdev->lock);
  1346. return res;
  1347. }
  1348. static ssize_t
  1349. tm6000_read(struct file *file, char __user *data, size_t count, loff_t *pos)
  1350. {
  1351. struct tm6000_fh *fh = file->private_data;
  1352. struct tm6000_core *dev = fh->dev;
  1353. if (fh->type == V4L2_BUF_TYPE_VIDEO_CAPTURE) {
  1354. int res;
  1355. if (!res_get(fh->dev, fh, true))
  1356. return -EBUSY;
  1357. if (mutex_lock_interruptible(&dev->lock))
  1358. return -ERESTARTSYS;
  1359. res = videobuf_read_stream(&fh->vb_vidq, data, count, pos, 0,
  1360. file->f_flags & O_NONBLOCK);
  1361. mutex_unlock(&dev->lock);
  1362. return res;
  1363. }
  1364. return 0;
  1365. }
  1366. static unsigned int
  1367. __tm6000_poll(struct file *file, struct poll_table_struct *wait)
  1368. {
  1369. struct tm6000_fh *fh = file->private_data;
  1370. struct tm6000_buffer *buf;
  1371. if (V4L2_BUF_TYPE_VIDEO_CAPTURE != fh->type)
  1372. return POLLERR;
  1373. if (!!is_res_streaming(fh->dev, fh))
  1374. return POLLERR;
  1375. if (!is_res_read(fh->dev, fh)) {
  1376. /* streaming capture */
  1377. if (list_empty(&fh->vb_vidq.stream))
  1378. return POLLERR;
  1379. buf = list_entry(fh->vb_vidq.stream.next, struct tm6000_buffer, vb.stream);
  1380. } else {
  1381. /* read() capture */
  1382. return videobuf_poll_stream(file, &fh->vb_vidq, wait);
  1383. }
  1384. poll_wait(file, &buf->vb.done, wait);
  1385. if (buf->vb.state == VIDEOBUF_DONE ||
  1386. buf->vb.state == VIDEOBUF_ERROR)
  1387. return POLLIN | POLLRDNORM;
  1388. return 0;
  1389. }
  1390. static unsigned int tm6000_poll(struct file *file, struct poll_table_struct *wait)
  1391. {
  1392. struct tm6000_fh *fh = file->private_data;
  1393. struct tm6000_core *dev = fh->dev;
  1394. unsigned int res;
  1395. mutex_lock(&dev->lock);
  1396. res = __tm6000_poll(file, wait);
  1397. mutex_unlock(&dev->lock);
  1398. return res;
  1399. }
  1400. static int tm6000_release(struct file *file)
  1401. {
  1402. struct tm6000_fh *fh = file->private_data;
  1403. struct tm6000_core *dev = fh->dev;
  1404. struct video_device *vdev = video_devdata(file);
  1405. dprintk(dev, V4L2_DEBUG_OPEN, "tm6000: close called (dev=%s, users=%d)\n",
  1406. video_device_node_name(vdev), dev->users);
  1407. mutex_lock(&dev->lock);
  1408. dev->users--;
  1409. res_free(dev, fh);
  1410. if (!dev->users) {
  1411. tm6000_uninit_isoc(dev);
  1412. /* Stop interrupt USB pipe */
  1413. tm6000_ir_int_stop(dev);
  1414. usb_reset_configuration(dev->udev);
  1415. if (dev->int_in.endp)
  1416. usb_set_interface(dev->udev,
  1417. dev->isoc_in.bInterfaceNumber, 2);
  1418. else
  1419. usb_set_interface(dev->udev,
  1420. dev->isoc_in.bInterfaceNumber, 0);
  1421. /* Start interrupt USB pipe */
  1422. tm6000_ir_int_start(dev);
  1423. if (!fh->radio)
  1424. videobuf_mmap_free(&fh->vb_vidq);
  1425. }
  1426. kfree(fh);
  1427. mutex_unlock(&dev->lock);
  1428. return 0;
  1429. }
  1430. static int tm6000_mmap(struct file *file, struct vm_area_struct * vma)
  1431. {
  1432. struct tm6000_fh *fh = file->private_data;
  1433. struct tm6000_core *dev = fh->dev;
  1434. int res;
  1435. if (mutex_lock_interruptible(&dev->lock))
  1436. return -ERESTARTSYS;
  1437. res = videobuf_mmap_mapper(&fh->vb_vidq, vma);
  1438. mutex_unlock(&dev->lock);
  1439. return res;
  1440. }
  1441. static struct v4l2_file_operations tm6000_fops = {
  1442. .owner = THIS_MODULE,
  1443. .open = tm6000_open,
  1444. .release = tm6000_release,
  1445. .unlocked_ioctl = video_ioctl2, /* V4L2 ioctl handler */
  1446. .read = tm6000_read,
  1447. .poll = tm6000_poll,
  1448. .mmap = tm6000_mmap,
  1449. };
  1450. static const struct v4l2_ioctl_ops video_ioctl_ops = {
  1451. .vidioc_querycap = vidioc_querycap,
  1452. .vidioc_enum_fmt_vid_cap = vidioc_enum_fmt_vid_cap,
  1453. .vidioc_g_fmt_vid_cap = vidioc_g_fmt_vid_cap,
  1454. .vidioc_try_fmt_vid_cap = vidioc_try_fmt_vid_cap,
  1455. .vidioc_s_fmt_vid_cap = vidioc_s_fmt_vid_cap,
  1456. .vidioc_s_std = vidioc_s_std,
  1457. .vidioc_enum_input = vidioc_enum_input,
  1458. .vidioc_g_input = vidioc_g_input,
  1459. .vidioc_s_input = vidioc_s_input,
  1460. .vidioc_queryctrl = vidioc_queryctrl,
  1461. .vidioc_g_ctrl = vidioc_g_ctrl,
  1462. .vidioc_s_ctrl = vidioc_s_ctrl,
  1463. .vidioc_g_tuner = vidioc_g_tuner,
  1464. .vidioc_s_tuner = vidioc_s_tuner,
  1465. .vidioc_g_frequency = vidioc_g_frequency,
  1466. .vidioc_s_frequency = vidioc_s_frequency,
  1467. .vidioc_streamon = vidioc_streamon,
  1468. .vidioc_streamoff = vidioc_streamoff,
  1469. .vidioc_reqbufs = vidioc_reqbufs,
  1470. .vidioc_querybuf = vidioc_querybuf,
  1471. .vidioc_qbuf = vidioc_qbuf,
  1472. .vidioc_dqbuf = vidioc_dqbuf,
  1473. };
  1474. static struct video_device tm6000_template = {
  1475. .name = "tm6000",
  1476. .fops = &tm6000_fops,
  1477. .ioctl_ops = &video_ioctl_ops,
  1478. .release = video_device_release,
  1479. .tvnorms = TM6000_STD,
  1480. .current_norm = V4L2_STD_NTSC_M,
  1481. };
  1482. static const struct v4l2_file_operations radio_fops = {
  1483. .owner = THIS_MODULE,
  1484. .open = tm6000_open,
  1485. .release = tm6000_release,
  1486. .unlocked_ioctl = video_ioctl2,
  1487. };
  1488. static const struct v4l2_ioctl_ops radio_ioctl_ops = {
  1489. .vidioc_querycap = radio_querycap,
  1490. .vidioc_g_tuner = radio_g_tuner,
  1491. .vidioc_enum_input = radio_enum_input,
  1492. .vidioc_g_audio = radio_g_audio,
  1493. .vidioc_s_tuner = radio_s_tuner,
  1494. .vidioc_s_audio = radio_s_audio,
  1495. .vidioc_s_input = radio_s_input,
  1496. .vidioc_s_std = radio_s_std,
  1497. .vidioc_queryctrl = radio_queryctrl,
  1498. .vidioc_g_input = radio_g_input,
  1499. .vidioc_g_ctrl = vidioc_g_ctrl,
  1500. .vidioc_s_ctrl = vidioc_s_ctrl,
  1501. .vidioc_g_frequency = vidioc_g_frequency,
  1502. .vidioc_s_frequency = vidioc_s_frequency,
  1503. };
  1504. static struct video_device tm6000_radio_template = {
  1505. .name = "tm6000",
  1506. .fops = &radio_fops,
  1507. .ioctl_ops = &radio_ioctl_ops,
  1508. };
  1509. /* -----------------------------------------------------------------
  1510. * Initialization and module stuff
  1511. * ------------------------------------------------------------------
  1512. */
  1513. static struct video_device *vdev_init(struct tm6000_core *dev,
  1514. const struct video_device
  1515. *template, const char *type_name)
  1516. {
  1517. struct video_device *vfd;
  1518. vfd = video_device_alloc();
  1519. if (NULL == vfd)
  1520. return NULL;
  1521. *vfd = *template;
  1522. vfd->v4l2_dev = &dev->v4l2_dev;
  1523. vfd->release = video_device_release;
  1524. vfd->debug = tm6000_debug;
  1525. vfd->lock = &dev->lock;
  1526. snprintf(vfd->name, sizeof(vfd->name), "%s %s", dev->name, type_name);
  1527. video_set_drvdata(vfd, dev);
  1528. return vfd;
  1529. }
  1530. int tm6000_v4l2_register(struct tm6000_core *dev)
  1531. {
  1532. int ret = -1;
  1533. dev->vfd = vdev_init(dev, &tm6000_template, "video");
  1534. if (!dev->vfd) {
  1535. printk(KERN_INFO "%s: can't register video device\n",
  1536. dev->name);
  1537. return -ENOMEM;
  1538. }
  1539. /* init video dma queues */
  1540. INIT_LIST_HEAD(&dev->vidq.active);
  1541. INIT_LIST_HEAD(&dev->vidq.queued);
  1542. ret = video_register_device(dev->vfd, VFL_TYPE_GRABBER, video_nr);
  1543. if (ret < 0) {
  1544. printk(KERN_INFO "%s: can't register video device\n",
  1545. dev->name);
  1546. return ret;
  1547. }
  1548. printk(KERN_INFO "%s: registered device %s\n",
  1549. dev->name, video_device_node_name(dev->vfd));
  1550. if (dev->caps.has_radio) {
  1551. dev->radio_dev = vdev_init(dev, &tm6000_radio_template,
  1552. "radio");
  1553. if (!dev->radio_dev) {
  1554. printk(KERN_INFO "%s: can't register radio device\n",
  1555. dev->name);
  1556. ret = -ENXIO;
  1557. return ret; /* FIXME release resource */
  1558. }
  1559. ret = video_register_device(dev->radio_dev, VFL_TYPE_RADIO,
  1560. radio_nr);
  1561. if (ret < 0) {
  1562. printk(KERN_INFO "%s: can't register radio device\n",
  1563. dev->name);
  1564. return ret; /* FIXME release resource */
  1565. }
  1566. printk(KERN_INFO "%s: registered device %s\n",
  1567. dev->name, video_device_node_name(dev->radio_dev));
  1568. }
  1569. printk(KERN_INFO "Trident TVMaster TM5600/TM6000/TM6010 USB2 board (Load status: %d)\n", ret);
  1570. return ret;
  1571. }
  1572. int tm6000_v4l2_unregister(struct tm6000_core *dev)
  1573. {
  1574. video_unregister_device(dev->vfd);
  1575. /* if URB buffers are still allocated free them now */
  1576. tm6000_free_urb_buffers(dev);
  1577. if (dev->radio_dev) {
  1578. if (video_is_registered(dev->radio_dev))
  1579. video_unregister_device(dev->radio_dev);
  1580. else
  1581. video_device_release(dev->radio_dev);
  1582. dev->radio_dev = NULL;
  1583. }
  1584. return 0;
  1585. }
  1586. int tm6000_v4l2_exit(void)
  1587. {
  1588. return 0;
  1589. }
  1590. module_param(video_nr, int, 0);
  1591. MODULE_PARM_DESC(video_nr, "Allow changing video device number");
  1592. module_param_named(debug, tm6000_debug, int, 0444);
  1593. MODULE_PARM_DESC(debug, "activates debug info");
  1594. module_param(vid_limit, int, 0644);
  1595. MODULE_PARM_DESC(vid_limit, "capture memory limit in megabytes");
  1596. module_param(keep_urb, bool, 0);
  1597. MODULE_PARM_DESC(keep_urb, "Keep urb buffers allocated even when the device is closed by the user");