vivi.c 31 KB

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