vivi.c 31 KB

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