vivi.c 31 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300
  1. /*
  2. * Virtual Video driver - This code emulates a real video device with v4l2 api
  3. *
  4. * Copyright (c) 2006 by:
  5. * Mauro Carvalho Chehab <mchehab--a.t--infradead.org>
  6. * Ted Walther <ted--a.t--enumera.com>
  7. * John Sokol <sokol--a.t--videotechnology.com>
  8. * http://v4l.videotechnology.com/
  9. *
  10. * This program is free software; you can redistribute it and/or modify
  11. * it under the terms of the BSD Licence, GNU General Public License
  12. * as published by the Free Software Foundation; either version 2 of the
  13. * License, or (at your option) any later version
  14. */
  15. #include <linux/module.h>
  16. #include <linux/delay.h>
  17. #include <linux/errno.h>
  18. #include <linux/fs.h>
  19. #include <linux/kernel.h>
  20. #include <linux/slab.h>
  21. #include <linux/mm.h>
  22. #include <linux/ioport.h>
  23. #include <linux/init.h>
  24. #include <linux/sched.h>
  25. #include <linux/pci.h>
  26. #include <linux/random.h>
  27. #include <linux/version.h>
  28. #include <linux/mutex.h>
  29. #include <linux/videodev2.h>
  30. #include <linux/dma-mapping.h>
  31. #ifdef CONFIG_VIDEO_V4L1_COMPAT
  32. /* Include V4L1 specific functions. Should be removed soon */
  33. #include <linux/videodev.h>
  34. #endif
  35. #include <linux/interrupt.h>
  36. #include <media/videobuf-vmalloc.h>
  37. #include <media/v4l2-common.h>
  38. #include <linux/kthread.h>
  39. #include <linux/highmem.h>
  40. #include <linux/freezer.h>
  41. /* Wake up at about 30 fps */
  42. #define WAKE_NUMERATOR 30
  43. #define WAKE_DENOMINATOR 1001
  44. #define BUFFER_TIMEOUT msecs_to_jiffies(500) /* 0.5 seconds */
  45. #include "font.h"
  46. #define VIVI_MAJOR_VERSION 0
  47. #define VIVI_MINOR_VERSION 4
  48. #define VIVI_RELEASE 0
  49. #define VIVI_VERSION \
  50. KERNEL_VERSION(VIVI_MAJOR_VERSION, VIVI_MINOR_VERSION, VIVI_RELEASE)
  51. /* Declare static vars that will be used as parameters */
  52. static unsigned int vid_limit = 16; /* Video memory limit, in Mb */
  53. static int video_nr = -1; /* /dev/videoN, -1 for autodetect */
  54. static int n_devs = 1; /* Number of virtual devices */
  55. /* supported controls */
  56. static struct v4l2_queryctrl vivi_qctrl[] = {
  57. {
  58. .id = V4L2_CID_AUDIO_VOLUME,
  59. .name = "Volume",
  60. .minimum = 0,
  61. .maximum = 65535,
  62. .step = 65535/100,
  63. .default_value = 65535,
  64. .flags = 0,
  65. .type = V4L2_CTRL_TYPE_INTEGER,
  66. }, {
  67. .id = V4L2_CID_BRIGHTNESS,
  68. .type = V4L2_CTRL_TYPE_INTEGER,
  69. .name = "Brightness",
  70. .minimum = 0,
  71. .maximum = 255,
  72. .step = 1,
  73. .default_value = 127,
  74. .flags = 0,
  75. }, {
  76. .id = V4L2_CID_CONTRAST,
  77. .type = V4L2_CTRL_TYPE_INTEGER,
  78. .name = "Contrast",
  79. .minimum = 0,
  80. .maximum = 255,
  81. .step = 0x1,
  82. .default_value = 0x10,
  83. .flags = 0,
  84. }, {
  85. .id = V4L2_CID_SATURATION,
  86. .type = V4L2_CTRL_TYPE_INTEGER,
  87. .name = "Saturation",
  88. .minimum = 0,
  89. .maximum = 255,
  90. .step = 0x1,
  91. .default_value = 127,
  92. .flags = 0,
  93. }, {
  94. .id = V4L2_CID_HUE,
  95. .type = V4L2_CTRL_TYPE_INTEGER,
  96. .name = "Hue",
  97. .minimum = -128,
  98. .maximum = 127,
  99. .step = 0x1,
  100. .default_value = 0,
  101. .flags = 0,
  102. }
  103. };
  104. static int qctl_regs[ARRAY_SIZE(vivi_qctrl)];
  105. #define dprintk(dev, level, fmt, arg...) \
  106. do { \
  107. if (dev->vfd->debug >= (level)) \
  108. printk(KERN_DEBUG "vivi: " fmt , ## arg); \
  109. } while (0)
  110. /* ------------------------------------------------------------------
  111. Basic structures
  112. ------------------------------------------------------------------*/
  113. struct vivi_fmt {
  114. char *name;
  115. u32 fourcc; /* v4l2 format id */
  116. int depth;
  117. };
  118. static struct vivi_fmt format = {
  119. .name = "4:2:2, packed, YUYV",
  120. .fourcc = V4L2_PIX_FMT_YUYV,
  121. .depth = 16,
  122. };
  123. struct sg_to_addr {
  124. int pos;
  125. struct scatterlist *sg;
  126. };
  127. /* buffer for one video frame */
  128. struct vivi_buffer {
  129. /* common v4l buffer stuff -- must be first */
  130. struct videobuf_buffer vb;
  131. struct vivi_fmt *fmt;
  132. };
  133. struct vivi_dmaqueue {
  134. struct list_head active;
  135. struct list_head queued;
  136. struct timer_list timeout;
  137. /* thread for generating video stream*/
  138. struct task_struct *kthread;
  139. wait_queue_head_t wq;
  140. /* Counters to control fps rate */
  141. int frame;
  142. int ini_jiffies;
  143. };
  144. static LIST_HEAD(vivi_devlist);
  145. struct vivi_dev {
  146. struct list_head vivi_devlist;
  147. struct mutex lock;
  148. spinlock_t slock;
  149. int users;
  150. /* various device info */
  151. struct video_device *vfd;
  152. struct vivi_dmaqueue vidq;
  153. /* Several counters */
  154. int h, m, s, ms;
  155. unsigned long jiffies;
  156. char timestr[13];
  157. int mv_count; /* Controls bars movement */
  158. };
  159. struct vivi_fh {
  160. struct vivi_dev *dev;
  161. /* video capture */
  162. struct vivi_fmt *fmt;
  163. unsigned int width, height;
  164. struct videobuf_queue vb_vidq;
  165. enum v4l2_buf_type type;
  166. };
  167. /* ------------------------------------------------------------------
  168. DMA and thread functions
  169. ------------------------------------------------------------------*/
  170. /* Bars and Colors should match positions */
  171. enum colors {
  172. WHITE,
  173. AMBAR,
  174. CYAN,
  175. GREEN,
  176. MAGENTA,
  177. RED,
  178. BLUE,
  179. BLACK,
  180. };
  181. static u8 bars[8][3] = {
  182. /* R G B */
  183. {204, 204, 204}, /* white */
  184. {208, 208, 0}, /* ambar */
  185. { 0, 206, 206}, /* cyan */
  186. { 0, 239, 0}, /* green */
  187. {239, 0, 239}, /* magenta */
  188. {205, 0, 0}, /* red */
  189. { 0, 0, 255}, /* blue */
  190. { 0, 0, 0}, /* black */
  191. };
  192. #define TO_Y(r, g, b) \
  193. (((16829 * r + 33039 * g + 6416 * b + 32768) >> 16) + 16)
  194. /* RGB to V(Cr) Color transform */
  195. #define TO_V(r, g, b) \
  196. (((28784 * r - 24103 * g - 4681 * b + 32768) >> 16) + 128)
  197. /* RGB to U(Cb) Color transform */
  198. #define TO_U(r, g, b) \
  199. (((-9714 * r - 19070 * g + 28784 * b + 32768) >> 16) + 128)
  200. #define TSTAMP_MIN_Y 24
  201. #define TSTAMP_MAX_Y TSTAMP_MIN_Y+15
  202. #define TSTAMP_MIN_X 64
  203. static void gen_line(char *basep, int inipos, int wmax,
  204. int hmax, int line, int count, char *timestr)
  205. {
  206. int w, i, j, y;
  207. int pos = inipos;
  208. char *p, *s;
  209. u8 chr, r, g, b, color;
  210. /* We will just duplicate the second pixel at the packet */
  211. wmax /= 2;
  212. /* Generate a standard color bar pattern */
  213. for (w = 0; w < wmax; w++) {
  214. int colorpos = ((w + count) * 8/(wmax + 1)) % 8;
  215. r = bars[colorpos][0];
  216. g = bars[colorpos][1];
  217. b = bars[colorpos][2];
  218. for (color = 0; color < 4; color++) {
  219. p = basep + pos;
  220. switch (color) {
  221. case 0:
  222. case 2:
  223. *p = TO_Y(r, g, b); /* Luma */
  224. break;
  225. case 1:
  226. *p = TO_U(r, g, b); /* Cb */
  227. break;
  228. case 3:
  229. *p = TO_V(r, g, b); /* Cr */
  230. break;
  231. }
  232. pos++;
  233. }
  234. }
  235. /* Checks if it is possible to show timestamp */
  236. if (TSTAMP_MAX_Y >= hmax)
  237. goto end;
  238. if (TSTAMP_MIN_X + strlen(timestr) >= wmax)
  239. goto end;
  240. /* Print stream time */
  241. if (line >= TSTAMP_MIN_Y && line <= TSTAMP_MAX_Y) {
  242. j = TSTAMP_MIN_X;
  243. for (s = timestr; *s; s++) {
  244. chr = rom8x16_bits[(*s-0x30)*16+line-TSTAMP_MIN_Y];
  245. for (i = 0; i < 7; i++) {
  246. if (chr & 1 << (7 - i)) {
  247. /* Font color*/
  248. r = 0;
  249. g = 198;
  250. b = 0;
  251. } else {
  252. /* Background color */
  253. r = bars[BLACK][0];
  254. g = bars[BLACK][1];
  255. b = bars[BLACK][2];
  256. }
  257. pos = inipos + j * 2;
  258. for (color = 0; color < 4; color++) {
  259. p = basep + pos;
  260. y = TO_Y(r, g, b);
  261. switch (color) {
  262. case 0:
  263. case 2:
  264. *p = TO_Y(r, g, b); /* Luma */
  265. break;
  266. case 1:
  267. *p = TO_U(r, g, b); /* Cb */
  268. break;
  269. case 3:
  270. *p = TO_V(r, g, b); /* Cr */
  271. break;
  272. }
  273. pos++;
  274. }
  275. j++;
  276. }
  277. }
  278. }
  279. end:
  280. return;
  281. }
  282. static void vivi_fillbuff(struct vivi_dev *dev, struct vivi_buffer *buf)
  283. {
  284. int h , pos = 0;
  285. int hmax = buf->vb.height;
  286. int wmax = buf->vb.width;
  287. struct timeval ts;
  288. char *tmpbuf = kmalloc(wmax * 2, GFP_KERNEL);
  289. void *vbuf = videobuf_to_vmalloc(&buf->vb);
  290. if (!tmpbuf)
  291. return;
  292. for (h = 0; h < hmax; h++) {
  293. gen_line(tmpbuf, 0, wmax, hmax, h, dev->mv_count,
  294. dev->timestr);
  295. /* FIXME: replacing to __copy_to_user */
  296. if (copy_to_user(vbuf + pos, tmpbuf, wmax * 2) != 0)
  297. dprintk(dev, 2, "vivifill copy_to_user failed.\n");
  298. pos += wmax*2;
  299. }
  300. dev->mv_count++;
  301. kfree(tmpbuf);
  302. /* Updates stream time */
  303. dev->ms += jiffies_to_msecs(jiffies-dev->jiffies);
  304. dev->jiffies = jiffies;
  305. if (dev->ms >= 1000) {
  306. dev->ms -= 1000;
  307. dev->s++;
  308. if (dev->s >= 60) {
  309. dev->s -= 60;
  310. dev->m++;
  311. if (dev->m > 60) {
  312. dev->m -= 60;
  313. dev->h++;
  314. if (dev->h > 24)
  315. dev->h -= 24;
  316. }
  317. }
  318. }
  319. sprintf(dev->timestr, "%02d:%02d:%02d:%03d",
  320. dev->h, dev->m, dev->s, dev->ms);
  321. dprintk(dev, 2, "vivifill at %s: Buffer 0x%08lx size= %d\n",
  322. dev->timestr, (unsigned long)tmpbuf, pos);
  323. /* Advice that buffer was filled */
  324. buf->vb.state = VIDEOBUF_DONE;
  325. buf->vb.field_count++;
  326. do_gettimeofday(&ts);
  327. buf->vb.ts = ts;
  328. list_del(&buf->vb.queue);
  329. wake_up(&buf->vb.done);
  330. }
  331. static int restart_video_queue(struct vivi_dmaqueue *dma_q);
  332. static void vivi_thread_tick(struct vivi_dmaqueue *dma_q)
  333. {
  334. struct vivi_buffer *buf;
  335. struct vivi_dev *dev = container_of(dma_q, struct vivi_dev, vidq);
  336. int bc;
  337. spin_lock(&dev->slock);
  338. /* Announces videobuf that all went ok */
  339. for (bc = 0;; bc++) {
  340. if (list_empty(&dma_q->active)) {
  341. dprintk(dev, 1, "No active queue to serve\n");
  342. break;
  343. }
  344. buf = list_entry(dma_q->active.next,
  345. struct vivi_buffer, vb.queue);
  346. /* Nobody is waiting something to be done, just return */
  347. if (!waitqueue_active(&buf->vb.done)) {
  348. mod_timer(&dma_q->timeout, jiffies+BUFFER_TIMEOUT);
  349. spin_unlock(&dev->slock);
  350. return;
  351. }
  352. do_gettimeofday(&buf->vb.ts);
  353. dprintk(dev, 2, "[%p/%d] wakeup\n", buf, buf->vb. i);
  354. /* Fill buffer */
  355. vivi_fillbuff(dev, buf);
  356. if (list_empty(&dma_q->active)) {
  357. del_timer(&dma_q->timeout);
  358. } else {
  359. mod_timer(&dma_q->timeout, jiffies + BUFFER_TIMEOUT);
  360. }
  361. }
  362. if (bc != 1)
  363. dprintk(dev, 1, "%s: %d buffers handled (should be 1)\n",
  364. __FUNCTION__, bc);
  365. spin_unlock(&dev->slock);
  366. }
  367. #define frames_to_ms(frames) \
  368. ((frames * WAKE_NUMERATOR * 1000) / WAKE_DENOMINATOR)
  369. static void vivi_sleep(struct vivi_dmaqueue *dma_q)
  370. {
  371. struct vivi_dev *dev = container_of(dma_q, struct vivi_dev, vidq);
  372. int timeout, running_time;
  373. DECLARE_WAITQUEUE(wait, current);
  374. dprintk(dev, 1, "%s dma_q=0x%08lx\n", __FUNCTION__,
  375. (unsigned long)dma_q);
  376. add_wait_queue(&dma_q->wq, &wait);
  377. if (kthread_should_stop())
  378. goto stop_task;
  379. running_time = jiffies - dma_q->ini_jiffies;
  380. dma_q->frame++;
  381. /* Calculate time to wake up */
  382. timeout = msecs_to_jiffies(frames_to_ms(dma_q->frame)) - running_time;
  383. if (timeout > msecs_to_jiffies(frames_to_ms(2)) || timeout <= 0) {
  384. int old = dma_q->frame;
  385. int nframes;
  386. dma_q->frame = (jiffies_to_msecs(running_time) /
  387. frames_to_ms(1)) + 1;
  388. timeout = msecs_to_jiffies(frames_to_ms(dma_q->frame))
  389. - running_time;
  390. if (unlikely (timeout <= 0))
  391. timeout = 1;
  392. nframes = (dma_q->frame > old)?
  393. dma_q->frame - old : old - dma_q->frame;
  394. dprintk(dev, 1, "%ld: %s %d frames. "
  395. "Current frame is %d. Will sleep for %d jiffies\n",
  396. jiffies,
  397. (dma_q->frame > old)? "Underrun, losed" : "Overrun of",
  398. nframes, dma_q->frame, timeout);
  399. } else
  400. dprintk(dev, 1, "will sleep for %d jiffies\n", timeout);
  401. vivi_thread_tick(dma_q);
  402. schedule_timeout_interruptible(timeout);
  403. stop_task:
  404. remove_wait_queue(&dma_q->wq, &wait);
  405. try_to_freeze();
  406. }
  407. static int vivi_thread(void *data)
  408. {
  409. struct vivi_dmaqueue *dma_q = data;
  410. struct vivi_dev *dev = container_of(dma_q, struct vivi_dev, vidq);
  411. dprintk(dev, 1, "thread started\n");
  412. mod_timer(&dma_q->timeout, jiffies+BUFFER_TIMEOUT);
  413. set_freezable();
  414. for (;;) {
  415. vivi_sleep(dma_q);
  416. if (kthread_should_stop())
  417. break;
  418. }
  419. dprintk(dev, 1, "thread: exit\n");
  420. return 0;
  421. }
  422. static int vivi_start_thread(struct vivi_dmaqueue *dma_q)
  423. {
  424. struct vivi_dev *dev = container_of(dma_q, struct vivi_dev, vidq);
  425. dma_q->frame = 0;
  426. dma_q->ini_jiffies = jiffies;
  427. dprintk(dev, 1, "%s\n", __FUNCTION__);
  428. dma_q->kthread = kthread_run(vivi_thread, dma_q, "vivi");
  429. if (IS_ERR(dma_q->kthread)) {
  430. printk(KERN_ERR "vivi: kernel_thread() failed\n");
  431. return PTR_ERR(dma_q->kthread);
  432. }
  433. /* Wakes thread */
  434. wake_up_interruptible(&dma_q->wq);
  435. dprintk(dev, 1, "returning from %s\n", __FUNCTION__);
  436. return 0;
  437. }
  438. static void vivi_stop_thread(struct vivi_dmaqueue *dma_q)
  439. {
  440. struct vivi_dev *dev = container_of(dma_q, struct vivi_dev, vidq);
  441. dprintk(dev, 1, "%s\n", __FUNCTION__);
  442. /* shutdown control thread */
  443. if (dma_q->kthread) {
  444. kthread_stop(dma_q->kthread);
  445. dma_q->kthread = NULL;
  446. }
  447. }
  448. static int restart_video_queue(struct vivi_dmaqueue *dma_q)
  449. {
  450. struct vivi_dev *dev = container_of(dma_q, struct vivi_dev, vidq);
  451. struct vivi_buffer *buf, *prev;
  452. dprintk(dev, 1, "%s dma_q=0x%08lx\n", __FUNCTION__,
  453. (unsigned long)dma_q);
  454. if (!list_empty(&dma_q->active)) {
  455. buf = list_entry(dma_q->active.next,
  456. struct vivi_buffer, vb.queue);
  457. dprintk(dev, 2, "restart_queue [%p/%d]: restart dma\n",
  458. buf, buf->vb.i);
  459. dprintk(dev, 1, "Restarting video dma\n");
  460. vivi_stop_thread(dma_q);
  461. /* cancel all outstanding capture / vbi requests */
  462. list_for_each_entry_safe(buf, prev, &dma_q->active, vb.queue) {
  463. list_del(&buf->vb.queue);
  464. buf->vb.state = VIDEOBUF_ERROR;
  465. wake_up(&buf->vb.done);
  466. }
  467. mod_timer(&dma_q->timeout, jiffies+BUFFER_TIMEOUT);
  468. return 0;
  469. }
  470. prev = NULL;
  471. for (;;) {
  472. if (list_empty(&dma_q->queued))
  473. return 0;
  474. buf = list_entry(dma_q->queued.next,
  475. struct vivi_buffer, vb.queue);
  476. if (NULL == prev) {
  477. list_del(&buf->vb.queue);
  478. list_add_tail(&buf->vb.queue, &dma_q->active);
  479. dprintk(dev, 1, "Restarting video dma\n");
  480. vivi_stop_thread(dma_q);
  481. vivi_start_thread(dma_q);
  482. buf->vb.state = VIDEOBUF_ACTIVE;
  483. mod_timer(&dma_q->timeout, jiffies+BUFFER_TIMEOUT);
  484. dprintk(dev, 2,
  485. "[%p/%d] restart_queue - first active\n",
  486. buf, buf->vb.i);
  487. } else if (prev->vb.width == buf->vb.width &&
  488. prev->vb.height == buf->vb.height &&
  489. prev->fmt == buf->fmt) {
  490. list_del(&buf->vb.queue);
  491. list_add_tail(&buf->vb.queue, &dma_q->active);
  492. buf->vb.state = VIDEOBUF_ACTIVE;
  493. dprintk(dev, 2,
  494. "[%p/%d] restart_queue - move to active\n",
  495. buf, buf->vb.i);
  496. } else {
  497. return 0;
  498. }
  499. prev = buf;
  500. }
  501. }
  502. static void vivi_vid_timeout(unsigned long data)
  503. {
  504. struct vivi_dev *dev = (struct vivi_dev *)data;
  505. struct vivi_dmaqueue *vidq = &dev->vidq;
  506. struct vivi_buffer *buf;
  507. spin_lock(&dev->slock);
  508. while (!list_empty(&vidq->active)) {
  509. buf = list_entry(vidq->active.next,
  510. struct vivi_buffer, vb.queue);
  511. list_del(&buf->vb.queue);
  512. buf->vb.state = VIDEOBUF_ERROR;
  513. wake_up(&buf->vb.done);
  514. printk(KERN_INFO "vivi/0: [%p/%d] timeout\n", buf, buf->vb.i);
  515. }
  516. restart_video_queue(vidq);
  517. spin_unlock(&dev->slock);
  518. }
  519. /* ------------------------------------------------------------------
  520. Videobuf operations
  521. ------------------------------------------------------------------*/
  522. static int
  523. buffer_setup(struct videobuf_queue *vq, unsigned int *count, unsigned int *size)
  524. {
  525. struct vivi_fh *fh = vq->priv_data;
  526. struct vivi_dev *dev = fh->dev;
  527. *size = fh->width*fh->height*2;
  528. if (0 == *count)
  529. *count = 32;
  530. while (*size * *count > vid_limit * 1024 * 1024)
  531. (*count)--;
  532. dprintk(dev, 1, "%s, count=%d, size=%d\n", __FUNCTION__,
  533. *count, *size);
  534. return 0;
  535. }
  536. static void free_buffer(struct videobuf_queue *vq, struct vivi_buffer *buf)
  537. {
  538. struct vivi_fh *fh = vq->priv_data;
  539. struct vivi_dev *dev = fh->dev;
  540. dprintk(dev, 1, "%s\n", __FUNCTION__);
  541. if (in_interrupt())
  542. BUG();
  543. videobuf_waiton(&buf->vb, 0, 0);
  544. videobuf_vmalloc_free(&buf->vb);
  545. buf->vb.state = VIDEOBUF_NEEDS_INIT;
  546. }
  547. #define norm_maxw() 1024
  548. #define norm_maxh() 768
  549. static int
  550. buffer_prepare(struct videobuf_queue *vq, struct videobuf_buffer *vb,
  551. enum v4l2_field field)
  552. {
  553. struct vivi_fh *fh = vq->priv_data;
  554. struct vivi_dev *dev = fh->dev;
  555. struct vivi_buffer *buf = container_of(vb, struct vivi_buffer, vb);
  556. int rc, init_buffer = 0;
  557. dprintk(dev, 1, "%s, field=%d\n", __FUNCTION__, field);
  558. BUG_ON(NULL == fh->fmt);
  559. if (fh->width < 48 || fh->width > norm_maxw() ||
  560. fh->height < 32 || fh->height > norm_maxh())
  561. return -EINVAL;
  562. buf->vb.size = fh->width*fh->height*2;
  563. if (0 != buf->vb.baddr && buf->vb.bsize < buf->vb.size)
  564. return -EINVAL;
  565. if (buf->fmt != fh->fmt ||
  566. buf->vb.width != fh->width ||
  567. buf->vb.height != fh->height ||
  568. buf->vb.field != field) {
  569. buf->fmt = fh->fmt;
  570. buf->vb.width = fh->width;
  571. buf->vb.height = fh->height;
  572. buf->vb.field = field;
  573. init_buffer = 1;
  574. }
  575. if (VIDEOBUF_NEEDS_INIT == buf->vb.state) {
  576. rc = videobuf_iolock(vq, &buf->vb, NULL);
  577. if (rc < 0)
  578. goto fail;
  579. }
  580. buf->vb.state = VIDEOBUF_PREPARED;
  581. return 0;
  582. fail:
  583. free_buffer(vq, buf);
  584. return rc;
  585. }
  586. static void
  587. buffer_queue(struct videobuf_queue *vq, struct videobuf_buffer *vb)
  588. {
  589. struct vivi_buffer *buf = container_of(vb, struct vivi_buffer, vb);
  590. struct vivi_fh *fh = vq->priv_data;
  591. struct vivi_dev *dev = fh->dev;
  592. struct vivi_dmaqueue *vidq = &dev->vidq;
  593. struct vivi_buffer *prev;
  594. if (!list_empty(&vidq->queued)) {
  595. dprintk(dev, 1, "adding vb queue=0x%08lx\n",
  596. (unsigned long)&buf->vb.queue);
  597. list_add_tail(&buf->vb.queue, &vidq->queued);
  598. buf->vb.state = VIDEOBUF_QUEUED;
  599. dprintk(dev, 2, "[%p/%d] buffer_queue - append to queued\n",
  600. buf, buf->vb.i);
  601. } else if (list_empty(&vidq->active)) {
  602. list_add_tail(&buf->vb.queue, &vidq->active);
  603. buf->vb.state = VIDEOBUF_ACTIVE;
  604. mod_timer(&vidq->timeout, jiffies+BUFFER_TIMEOUT);
  605. dprintk(dev, 2, "[%p/%d] buffer_queue - first active\n",
  606. buf, buf->vb.i);
  607. vivi_start_thread(vidq);
  608. } else {
  609. prev = list_entry(vidq->active.prev,
  610. struct vivi_buffer, vb.queue);
  611. if (prev->vb.width == buf->vb.width &&
  612. prev->vb.height == buf->vb.height &&
  613. prev->fmt == buf->fmt) {
  614. list_add_tail(&buf->vb.queue, &vidq->active);
  615. buf->vb.state = VIDEOBUF_ACTIVE;
  616. dprintk(dev, 2,
  617. "[%p/%d] buffer_queue - append to active\n",
  618. buf, buf->vb.i);
  619. } else {
  620. list_add_tail(&buf->vb.queue, &vidq->queued);
  621. buf->vb.state = VIDEOBUF_QUEUED;
  622. dprintk(dev, 2,
  623. "[%p/%d] buffer_queue - first queued\n",
  624. buf, buf->vb.i);
  625. }
  626. }
  627. }
  628. static void buffer_release(struct videobuf_queue *vq,
  629. struct videobuf_buffer *vb)
  630. {
  631. struct vivi_buffer *buf = container_of(vb, struct vivi_buffer, vb);
  632. struct vivi_fh *fh = vq->priv_data;
  633. struct vivi_dev *dev = (struct vivi_dev *)fh->dev;
  634. struct vivi_dmaqueue *vidq = &dev->vidq;
  635. dprintk(dev, 1, "%s\n", __FUNCTION__);
  636. vivi_stop_thread(vidq);
  637. free_buffer(vq, buf);
  638. }
  639. static struct videobuf_queue_ops vivi_video_qops = {
  640. .buf_setup = buffer_setup,
  641. .buf_prepare = buffer_prepare,
  642. .buf_queue = buffer_queue,
  643. .buf_release = buffer_release,
  644. };
  645. /* ------------------------------------------------------------------
  646. IOCTL vidioc handling
  647. ------------------------------------------------------------------*/
  648. static int vidioc_querycap(struct file *file, void *priv,
  649. struct v4l2_capability *cap)
  650. {
  651. strcpy(cap->driver, "vivi");
  652. strcpy(cap->card, "vivi");
  653. cap->version = VIVI_VERSION;
  654. cap->capabilities = V4L2_CAP_VIDEO_CAPTURE |
  655. V4L2_CAP_STREAMING |
  656. V4L2_CAP_READWRITE;
  657. return 0;
  658. }
  659. static int vidioc_enum_fmt_cap(struct file *file, void *priv,
  660. struct v4l2_fmtdesc *f)
  661. {
  662. if (f->index > 0)
  663. return -EINVAL;
  664. strlcpy(f->description, format.name, sizeof(f->description));
  665. f->pixelformat = format.fourcc;
  666. return 0;
  667. }
  668. static int vidioc_g_fmt_cap(struct file *file, void *priv,
  669. struct v4l2_format *f)
  670. {
  671. struct vivi_fh *fh = priv;
  672. f->fmt.pix.width = fh->width;
  673. f->fmt.pix.height = fh->height;
  674. f->fmt.pix.field = fh->vb_vidq.field;
  675. f->fmt.pix.pixelformat = fh->fmt->fourcc;
  676. f->fmt.pix.bytesperline =
  677. (f->fmt.pix.width * fh->fmt->depth) >> 3;
  678. f->fmt.pix.sizeimage =
  679. f->fmt.pix.height * f->fmt.pix.bytesperline;
  680. return (0);
  681. }
  682. static int vidioc_try_fmt_cap(struct file *file, void *priv,
  683. struct v4l2_format *f)
  684. {
  685. struct vivi_fh *fh = priv;
  686. struct vivi_dev *dev = fh->dev;
  687. struct vivi_fmt *fmt;
  688. enum v4l2_field field;
  689. unsigned int maxw, maxh;
  690. if (format.fourcc != f->fmt.pix.pixelformat) {
  691. dprintk(dev, 1, "Fourcc format (0x%08x) invalid. "
  692. "Driver accepts only 0x%08x\n",
  693. f->fmt.pix.pixelformat, format.fourcc);
  694. return -EINVAL;
  695. }
  696. fmt = &format;
  697. field = f->fmt.pix.field;
  698. if (field == V4L2_FIELD_ANY) {
  699. field = V4L2_FIELD_INTERLACED;
  700. } else if (V4L2_FIELD_INTERLACED != field) {
  701. dprintk(dev, 1, "Field type invalid.\n");
  702. return -EINVAL;
  703. }
  704. maxw = norm_maxw();
  705. maxh = norm_maxh();
  706. f->fmt.pix.field = field;
  707. if (f->fmt.pix.height < 32)
  708. f->fmt.pix.height = 32;
  709. if (f->fmt.pix.height > maxh)
  710. f->fmt.pix.height = maxh;
  711. if (f->fmt.pix.width < 48)
  712. f->fmt.pix.width = 48;
  713. if (f->fmt.pix.width > maxw)
  714. f->fmt.pix.width = maxw;
  715. f->fmt.pix.width &= ~0x03;
  716. f->fmt.pix.bytesperline =
  717. (f->fmt.pix.width * fmt->depth) >> 3;
  718. f->fmt.pix.sizeimage =
  719. f->fmt.pix.height * f->fmt.pix.bytesperline;
  720. return 0;
  721. }
  722. /*FIXME: This seems to be generic enough to be at videodev2 */
  723. static int vidioc_s_fmt_cap(struct file *file, void *priv,
  724. struct v4l2_format *f)
  725. {
  726. struct vivi_fh *fh = priv;
  727. int ret = vidioc_try_fmt_cap(file, fh, f);
  728. if (ret < 0)
  729. return (ret);
  730. fh->fmt = &format;
  731. fh->width = f->fmt.pix.width;
  732. fh->height = f->fmt.pix.height;
  733. fh->vb_vidq.field = f->fmt.pix.field;
  734. fh->type = f->type;
  735. return (0);
  736. }
  737. static int vidioc_reqbufs(struct file *file, void *priv,
  738. struct v4l2_requestbuffers *p)
  739. {
  740. struct vivi_fh *fh = priv;
  741. return (videobuf_reqbufs(&fh->vb_vidq, p));
  742. }
  743. static int vidioc_querybuf(struct file *file, void *priv, struct v4l2_buffer *p)
  744. {
  745. struct vivi_fh *fh = priv;
  746. return (videobuf_querybuf(&fh->vb_vidq, p));
  747. }
  748. static int vidioc_qbuf(struct file *file, void *priv, struct v4l2_buffer *p)
  749. {
  750. struct vivi_fh *fh = priv;
  751. return (videobuf_qbuf(&fh->vb_vidq, p));
  752. }
  753. static int vidioc_dqbuf(struct file *file, void *priv, struct v4l2_buffer *p)
  754. {
  755. struct vivi_fh *fh = priv;
  756. return (videobuf_dqbuf(&fh->vb_vidq, p,
  757. file->f_flags & O_NONBLOCK));
  758. }
  759. #ifdef CONFIG_VIDEO_V4L1_COMPAT
  760. static int vidiocgmbuf(struct file *file, void *priv, struct video_mbuf *mbuf)
  761. {
  762. struct vivi_fh *fh = priv;
  763. return videobuf_cgmbuf(&fh->vb_vidq, mbuf, 8);
  764. }
  765. #endif
  766. static int vidioc_streamon(struct file *file, void *priv, enum v4l2_buf_type i)
  767. {
  768. struct vivi_fh *fh = priv;
  769. if (fh->type != V4L2_BUF_TYPE_VIDEO_CAPTURE)
  770. return -EINVAL;
  771. if (i != fh->type)
  772. return -EINVAL;
  773. return videobuf_streamon(&fh->vb_vidq);
  774. }
  775. static int vidioc_streamoff(struct file *file, void *priv, enum v4l2_buf_type i)
  776. {
  777. struct vivi_fh *fh = priv;
  778. if (fh->type != V4L2_BUF_TYPE_VIDEO_CAPTURE)
  779. return -EINVAL;
  780. if (i != fh->type)
  781. return -EINVAL;
  782. return videobuf_streamoff(&fh->vb_vidq);
  783. }
  784. static int vidioc_s_std(struct file *file, void *priv, v4l2_std_id *i)
  785. {
  786. return 0;
  787. }
  788. /* only one input in this sample driver */
  789. static int vidioc_enum_input(struct file *file, void *priv,
  790. struct v4l2_input *inp)
  791. {
  792. if (inp->index != 0)
  793. return -EINVAL;
  794. inp->type = V4L2_INPUT_TYPE_CAMERA;
  795. inp->std = V4L2_STD_525_60;
  796. strcpy(inp->name, "Camera");
  797. return (0);
  798. }
  799. static int vidioc_g_input(struct file *file, void *priv, unsigned int *i)
  800. {
  801. *i = 0;
  802. return (0);
  803. }
  804. static int vidioc_s_input(struct file *file, void *priv, unsigned int i)
  805. {
  806. if (i > 0)
  807. return -EINVAL;
  808. return (0);
  809. }
  810. /* --- controls ---------------------------------------------- */
  811. static int vidioc_queryctrl(struct file *file, void *priv,
  812. struct v4l2_queryctrl *qc)
  813. {
  814. int i;
  815. for (i = 0; i < ARRAY_SIZE(vivi_qctrl); i++)
  816. if (qc->id && qc->id == vivi_qctrl[i].id) {
  817. memcpy(qc, &(vivi_qctrl[i]),
  818. sizeof(*qc));
  819. return (0);
  820. }
  821. return -EINVAL;
  822. }
  823. static int vidioc_g_ctrl(struct file *file, void *priv,
  824. struct v4l2_control *ctrl)
  825. {
  826. int i;
  827. for (i = 0; i < ARRAY_SIZE(vivi_qctrl); i++)
  828. if (ctrl->id == vivi_qctrl[i].id) {
  829. ctrl->value = qctl_regs[i];
  830. return (0);
  831. }
  832. return -EINVAL;
  833. }
  834. static int vidioc_s_ctrl(struct file *file, void *priv,
  835. struct v4l2_control *ctrl)
  836. {
  837. int i;
  838. for (i = 0; i < ARRAY_SIZE(vivi_qctrl); i++)
  839. if (ctrl->id == vivi_qctrl[i].id) {
  840. if (ctrl->value < vivi_qctrl[i].minimum
  841. || ctrl->value > vivi_qctrl[i].maximum) {
  842. return (-ERANGE);
  843. }
  844. qctl_regs[i] = ctrl->value;
  845. return (0);
  846. }
  847. return -EINVAL;
  848. }
  849. /* ------------------------------------------------------------------
  850. File operations for the device
  851. ------------------------------------------------------------------*/
  852. #define line_buf_size(norm) (norm_maxw(norm)*(format.depth+7)/8)
  853. static int vivi_open(struct inode *inode, struct file *file)
  854. {
  855. int minor = iminor(inode);
  856. struct vivi_dev *dev;
  857. struct vivi_fh *fh;
  858. int i;
  859. printk(KERN_DEBUG "vivi: open called (minor=%d)\n", minor);
  860. list_for_each_entry(dev, &vivi_devlist, vivi_devlist)
  861. if (dev->vfd->minor == minor)
  862. goto found;
  863. return -ENODEV;
  864. found:
  865. /* If more than one user, mutex should be added */
  866. dev->users++;
  867. dprintk(dev, 1, "open minor=%d type=%s users=%d\n", minor,
  868. v4l2_type_names[V4L2_BUF_TYPE_VIDEO_CAPTURE], dev->users);
  869. /* allocate + initialize per filehandle data */
  870. fh = kzalloc(sizeof(*fh), GFP_KERNEL);
  871. if (NULL == fh) {
  872. dev->users--;
  873. return -ENOMEM;
  874. }
  875. file->private_data = fh;
  876. fh->dev = dev;
  877. fh->type = V4L2_BUF_TYPE_VIDEO_CAPTURE;
  878. fh->fmt = &format;
  879. fh->width = 640;
  880. fh->height = 480;
  881. /* Put all controls at a sane state */
  882. for (i = 0; i < ARRAY_SIZE(vivi_qctrl); i++)
  883. qctl_regs[i] = vivi_qctrl[i].default_value;
  884. /* Resets frame counters */
  885. dev->h = 0;
  886. dev->m = 0;
  887. dev->s = 0;
  888. dev->ms = 0;
  889. dev->mv_count = 0;
  890. dev->jiffies = jiffies;
  891. sprintf(dev->timestr, "%02d:%02d:%02d:%03d",
  892. dev->h, dev->m, dev->s, dev->ms);
  893. videobuf_queue_vmalloc_init(&fh->vb_vidq, &vivi_video_qops,
  894. NULL, &dev->slock, fh->type, V4L2_FIELD_INTERLACED,
  895. sizeof(struct vivi_buffer), fh);
  896. return 0;
  897. }
  898. static ssize_t
  899. vivi_read(struct file *file, char __user *data, size_t count, loff_t *ppos)
  900. {
  901. struct vivi_fh *fh = file->private_data;
  902. if (fh->type == V4L2_BUF_TYPE_VIDEO_CAPTURE) {
  903. return videobuf_read_stream(&fh->vb_vidq, data, count, ppos, 0,
  904. file->f_flags & O_NONBLOCK);
  905. }
  906. return 0;
  907. }
  908. static unsigned int
  909. vivi_poll(struct file *file, struct poll_table_struct *wait)
  910. {
  911. struct vivi_fh *fh = file->private_data;
  912. struct vivi_dev *dev = fh->dev;
  913. struct videobuf_queue *q = &fh->vb_vidq;
  914. dprintk(dev, 1, "%s\n", __FUNCTION__);
  915. if (V4L2_BUF_TYPE_VIDEO_CAPTURE != fh->type)
  916. return POLLERR;
  917. return videobuf_poll_stream(file, q, wait);
  918. }
  919. static int vivi_close(struct inode *inode, struct file *file)
  920. {
  921. struct vivi_fh *fh = file->private_data;
  922. struct vivi_dev *dev = fh->dev;
  923. struct vivi_dmaqueue *vidq = &dev->vidq;
  924. int minor = iminor(inode);
  925. vivi_stop_thread(vidq);
  926. videobuf_stop(&fh->vb_vidq);
  927. videobuf_mmap_free(&fh->vb_vidq);
  928. kfree(fh);
  929. dev->users--;
  930. dprintk(dev, 1, "close called (minor=%d, users=%d)\n",
  931. minor, dev->users);
  932. return 0;
  933. }
  934. static int vivi_release(void)
  935. {
  936. struct vivi_dev *dev;
  937. struct list_head *list;
  938. while (!list_empty(&vivi_devlist)) {
  939. list = vivi_devlist.next;
  940. list_del(list);
  941. dev = list_entry(list, struct vivi_dev, vivi_devlist);
  942. if (-1 != dev->vfd->minor)
  943. video_unregister_device(dev->vfd);
  944. else
  945. video_device_release(dev->vfd);
  946. kfree(dev);
  947. }
  948. return 0;
  949. }
  950. static int vivi_mmap(struct file *file, struct vm_area_struct *vma)
  951. {
  952. struct vivi_fh *fh = file->private_data;
  953. struct vivi_dev *dev = fh->dev;
  954. int ret;
  955. dprintk(dev, 1, "mmap called, vma=0x%08lx\n", (unsigned long)vma);
  956. ret = videobuf_mmap_mapper(&fh->vb_vidq, vma);
  957. dprintk(dev, 1, "vma start=0x%08lx, size=%ld, ret=%d\n",
  958. (unsigned long)vma->vm_start,
  959. (unsigned long)vma->vm_end-(unsigned long)vma->vm_start,
  960. ret);
  961. return ret;
  962. }
  963. static const struct file_operations vivi_fops = {
  964. .owner = THIS_MODULE,
  965. .open = vivi_open,
  966. .release = vivi_close,
  967. .read = vivi_read,
  968. .poll = vivi_poll,
  969. .ioctl = video_ioctl2, /* V4L2 ioctl handler */
  970. .mmap = vivi_mmap,
  971. .llseek = no_llseek,
  972. };
  973. static struct video_device vivi_template = {
  974. .name = "vivi",
  975. .type = VID_TYPE_CAPTURE,
  976. .fops = &vivi_fops,
  977. .minor = -1,
  978. .release = video_device_release,
  979. .vidioc_querycap = vidioc_querycap,
  980. .vidioc_enum_fmt_cap = vidioc_enum_fmt_cap,
  981. .vidioc_g_fmt_cap = vidioc_g_fmt_cap,
  982. .vidioc_try_fmt_cap = vidioc_try_fmt_cap,
  983. .vidioc_s_fmt_cap = vidioc_s_fmt_cap,
  984. .vidioc_reqbufs = vidioc_reqbufs,
  985. .vidioc_querybuf = vidioc_querybuf,
  986. .vidioc_qbuf = vidioc_qbuf,
  987. .vidioc_dqbuf = vidioc_dqbuf,
  988. .vidioc_s_std = vidioc_s_std,
  989. .vidioc_enum_input = vidioc_enum_input,
  990. .vidioc_g_input = vidioc_g_input,
  991. .vidioc_s_input = vidioc_s_input,
  992. .vidioc_queryctrl = vidioc_queryctrl,
  993. .vidioc_g_ctrl = vidioc_g_ctrl,
  994. .vidioc_s_ctrl = vidioc_s_ctrl,
  995. .vidioc_streamon = vidioc_streamon,
  996. .vidioc_streamoff = vidioc_streamoff,
  997. #ifdef CONFIG_VIDEO_V4L1_COMPAT
  998. .vidiocgmbuf = vidiocgmbuf,
  999. #endif
  1000. .tvnorms = V4L2_STD_525_60,
  1001. .current_norm = V4L2_STD_NTSC_M,
  1002. };
  1003. /* -----------------------------------------------------------------
  1004. Initialization and module stuff
  1005. ------------------------------------------------------------------*/
  1006. static int __init vivi_init(void)
  1007. {
  1008. int ret = -ENOMEM, i;
  1009. struct vivi_dev *dev;
  1010. struct video_device *vfd;
  1011. for (i = 0; i < n_devs; i++) {
  1012. dev = kzalloc(sizeof(*dev), GFP_KERNEL);
  1013. if (NULL == dev)
  1014. break;
  1015. list_add_tail(&dev->vivi_devlist, &vivi_devlist);
  1016. /* init video dma queues */
  1017. INIT_LIST_HEAD(&dev->vidq.active);
  1018. INIT_LIST_HEAD(&dev->vidq.queued);
  1019. init_waitqueue_head(&dev->vidq.wq);
  1020. /* initialize locks */
  1021. mutex_init(&dev->lock);
  1022. spin_lock_init(&dev->slock);
  1023. dev->vidq.timeout.function = vivi_vid_timeout;
  1024. dev->vidq.timeout.data = (unsigned long)dev;
  1025. init_timer(&dev->vidq.timeout);
  1026. vfd = video_device_alloc();
  1027. if (NULL == vfd)
  1028. break;
  1029. *vfd = vivi_template;
  1030. ret = video_register_device(vfd, VFL_TYPE_GRABBER, video_nr);
  1031. if (ret < 0)
  1032. break;
  1033. snprintf(vfd->name, sizeof(vfd->name), "%s (%i)",
  1034. vivi_template.name, vfd->minor);
  1035. if (video_nr >= 0)
  1036. video_nr++;
  1037. dev->vfd = vfd;
  1038. }
  1039. if (ret < 0) {
  1040. vivi_release();
  1041. printk(KERN_INFO "Error %d while loading vivi driver\n", ret);
  1042. } else
  1043. printk(KERN_INFO "Video Technology Magazine Virtual Video "
  1044. "Capture Board successfully loaded.\n");
  1045. return ret;
  1046. }
  1047. static void __exit vivi_exit(void)
  1048. {
  1049. vivi_release();
  1050. }
  1051. module_init(vivi_init);
  1052. module_exit(vivi_exit);
  1053. MODULE_DESCRIPTION("Video Technology Magazine Virtual Video Capture Board");
  1054. MODULE_AUTHOR("Mauro Carvalho Chehab, Ted Walther and John Sokol");
  1055. MODULE_LICENSE("Dual BSD/GPL");
  1056. module_param(video_nr, int, 0);
  1057. MODULE_PARM_DESC(video_nr, "video iminor start number");
  1058. module_param(n_devs, int, 0);
  1059. MODULE_PARM_DESC(n_devs, "number of video devices to create");
  1060. module_param_named(debug, vivi_template.debug, int, 0444);
  1061. MODULE_PARM_DESC(debug, "activates debug info");
  1062. module_param(vid_limit, int, 0644);
  1063. MODULE_PARM_DESC(vid_limit, "capture memory limit in megabytes");