vivi.c 31 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301
  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. .compat_ioctl = v4l_compat_ioctl32,
  971. .mmap = vivi_mmap,
  972. .llseek = no_llseek,
  973. };
  974. static struct video_device vivi_template = {
  975. .name = "vivi",
  976. .type = VID_TYPE_CAPTURE,
  977. .fops = &vivi_fops,
  978. .minor = -1,
  979. .release = video_device_release,
  980. .vidioc_querycap = vidioc_querycap,
  981. .vidioc_enum_fmt_cap = vidioc_enum_fmt_cap,
  982. .vidioc_g_fmt_cap = vidioc_g_fmt_cap,
  983. .vidioc_try_fmt_cap = vidioc_try_fmt_cap,
  984. .vidioc_s_fmt_cap = vidioc_s_fmt_cap,
  985. .vidioc_reqbufs = vidioc_reqbufs,
  986. .vidioc_querybuf = vidioc_querybuf,
  987. .vidioc_qbuf = vidioc_qbuf,
  988. .vidioc_dqbuf = vidioc_dqbuf,
  989. .vidioc_s_std = vidioc_s_std,
  990. .vidioc_enum_input = vidioc_enum_input,
  991. .vidioc_g_input = vidioc_g_input,
  992. .vidioc_s_input = vidioc_s_input,
  993. .vidioc_queryctrl = vidioc_queryctrl,
  994. .vidioc_g_ctrl = vidioc_g_ctrl,
  995. .vidioc_s_ctrl = vidioc_s_ctrl,
  996. .vidioc_streamon = vidioc_streamon,
  997. .vidioc_streamoff = vidioc_streamoff,
  998. #ifdef CONFIG_VIDEO_V4L1_COMPAT
  999. .vidiocgmbuf = vidiocgmbuf,
  1000. #endif
  1001. .tvnorms = V4L2_STD_525_60,
  1002. .current_norm = V4L2_STD_NTSC_M,
  1003. };
  1004. /* -----------------------------------------------------------------
  1005. Initialization and module stuff
  1006. ------------------------------------------------------------------*/
  1007. static int __init vivi_init(void)
  1008. {
  1009. int ret = -ENOMEM, i;
  1010. struct vivi_dev *dev;
  1011. struct video_device *vfd;
  1012. for (i = 0; i < n_devs; i++) {
  1013. dev = kzalloc(sizeof(*dev), GFP_KERNEL);
  1014. if (NULL == dev)
  1015. break;
  1016. list_add_tail(&dev->vivi_devlist, &vivi_devlist);
  1017. /* init video dma queues */
  1018. INIT_LIST_HEAD(&dev->vidq.active);
  1019. INIT_LIST_HEAD(&dev->vidq.queued);
  1020. init_waitqueue_head(&dev->vidq.wq);
  1021. /* initialize locks */
  1022. mutex_init(&dev->lock);
  1023. spin_lock_init(&dev->slock);
  1024. dev->vidq.timeout.function = vivi_vid_timeout;
  1025. dev->vidq.timeout.data = (unsigned long)dev;
  1026. init_timer(&dev->vidq.timeout);
  1027. vfd = video_device_alloc();
  1028. if (NULL == vfd)
  1029. break;
  1030. *vfd = vivi_template;
  1031. ret = video_register_device(vfd, VFL_TYPE_GRABBER, video_nr);
  1032. if (ret < 0)
  1033. break;
  1034. snprintf(vfd->name, sizeof(vfd->name), "%s (%i)",
  1035. vivi_template.name, vfd->minor);
  1036. if (video_nr >= 0)
  1037. video_nr++;
  1038. dev->vfd = vfd;
  1039. }
  1040. if (ret < 0) {
  1041. vivi_release();
  1042. printk(KERN_INFO "Error %d while loading vivi driver\n", ret);
  1043. } else
  1044. printk(KERN_INFO "Video Technology Magazine Virtual Video "
  1045. "Capture Board successfully loaded.\n");
  1046. return ret;
  1047. }
  1048. static void __exit vivi_exit(void)
  1049. {
  1050. vivi_release();
  1051. }
  1052. module_init(vivi_init);
  1053. module_exit(vivi_exit);
  1054. MODULE_DESCRIPTION("Video Technology Magazine Virtual Video Capture Board");
  1055. MODULE_AUTHOR("Mauro Carvalho Chehab, Ted Walther and John Sokol");
  1056. MODULE_LICENSE("Dual BSD/GPL");
  1057. module_param(video_nr, int, 0);
  1058. MODULE_PARM_DESC(video_nr, "video iminor start number");
  1059. module_param(n_devs, int, 0);
  1060. MODULE_PARM_DESC(n_devs, "number of video devices to create");
  1061. module_param_named(debug, vivi_template.debug, int, 0444);
  1062. MODULE_PARM_DESC(debug, "activates debug info");
  1063. module_param(vid_limit, int, 0644);
  1064. MODULE_PARM_DESC(vid_limit, "capture memory limit in megabytes");