videodev.c 42 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771
  1. /*
  2. * Video capture interface for Linux version 2
  3. *
  4. * A generic video device interface for the LINUX operating system
  5. * using a set of device structures/vectors for low level operations.
  6. *
  7. * This program is free software; you can redistribute it and/or
  8. * modify it under the terms of the GNU General Public License
  9. * as published by the Free Software Foundation; either version
  10. * 2 of the License, or (at your option) any later version.
  11. *
  12. * Authors: Alan Cox, <alan@redhat.com> (version 1)
  13. * Mauro Carvalho Chehab <mchehab@infradead.org> (version 2)
  14. *
  15. * Fixes: 20000516 Claudio Matsuoka <claudio@conectiva.com>
  16. * - Added procfs support
  17. */
  18. #define dbgarg(cmd, fmt, arg...) \
  19. if (vfd->debug & V4L2_DEBUG_IOCTL_ARG) { \
  20. printk (KERN_DEBUG "%s: ", vfd->name); \
  21. v4l_printk_ioctl(cmd); \
  22. printk (KERN_DEBUG "%s: " fmt, vfd->name, ## arg); \
  23. }
  24. #define dbgarg2(fmt, arg...) \
  25. if (vfd->debug & V4L2_DEBUG_IOCTL_ARG) \
  26. printk (KERN_DEBUG "%s: " fmt, vfd->name, ## arg);
  27. #include <linux/module.h>
  28. #include <linux/types.h>
  29. #include <linux/kernel.h>
  30. #include <linux/sched.h>
  31. #include <linux/smp_lock.h>
  32. #include <linux/mm.h>
  33. #include <linux/string.h>
  34. #include <linux/errno.h>
  35. #include <linux/init.h>
  36. #include <linux/kmod.h>
  37. #include <linux/slab.h>
  38. #include <asm/uaccess.h>
  39. #include <asm/system.h>
  40. #define __OLD_VIDIOC_ /* To allow fixing old calls*/
  41. #include <linux/videodev2.h>
  42. #ifdef CONFIG_VIDEO_V4L1
  43. #include <linux/videodev.h>
  44. #endif
  45. #include <media/v4l2-common.h>
  46. #define VIDEO_NUM_DEVICES 256
  47. #define VIDEO_NAME "video4linux"
  48. /*
  49. * sysfs stuff
  50. */
  51. static ssize_t show_name(struct class_device *cd, char *buf)
  52. {
  53. struct video_device *vfd = container_of(cd, struct video_device,
  54. class_dev);
  55. return sprintf(buf,"%.*s\n",(int)sizeof(vfd->name),vfd->name);
  56. }
  57. static CLASS_DEVICE_ATTR(name, S_IRUGO, show_name, NULL);
  58. struct video_device *video_device_alloc(void)
  59. {
  60. struct video_device *vfd;
  61. vfd = kzalloc(sizeof(*vfd),GFP_KERNEL);
  62. return vfd;
  63. }
  64. void video_device_release(struct video_device *vfd)
  65. {
  66. kfree(vfd);
  67. }
  68. static void video_release(struct class_device *cd)
  69. {
  70. struct video_device *vfd = container_of(cd, struct video_device,
  71. class_dev);
  72. #if 1
  73. /* needed until all drivers are fixed */
  74. if (!vfd->release)
  75. return;
  76. #endif
  77. vfd->release(vfd);
  78. }
  79. static struct class video_class = {
  80. .name = VIDEO_NAME,
  81. .release = video_release,
  82. };
  83. /*
  84. * Active devices
  85. */
  86. static struct video_device *video_device[VIDEO_NUM_DEVICES];
  87. static DEFINE_MUTEX(videodev_lock);
  88. struct video_device* video_devdata(struct file *file)
  89. {
  90. return video_device[iminor(file->f_path.dentry->d_inode)];
  91. }
  92. /*
  93. * Open a video device - FIXME: Obsoleted
  94. */
  95. static int video_open(struct inode *inode, struct file *file)
  96. {
  97. unsigned int minor = iminor(inode);
  98. int err = 0;
  99. struct video_device *vfl;
  100. const struct file_operations *old_fops;
  101. if(minor>=VIDEO_NUM_DEVICES)
  102. return -ENODEV;
  103. mutex_lock(&videodev_lock);
  104. vfl=video_device[minor];
  105. if(vfl==NULL) {
  106. mutex_unlock(&videodev_lock);
  107. request_module("char-major-%d-%d", VIDEO_MAJOR, minor);
  108. mutex_lock(&videodev_lock);
  109. vfl=video_device[minor];
  110. if (vfl==NULL) {
  111. mutex_unlock(&videodev_lock);
  112. return -ENODEV;
  113. }
  114. }
  115. old_fops = file->f_op;
  116. file->f_op = fops_get(vfl->fops);
  117. if(file->f_op->open)
  118. err = file->f_op->open(inode,file);
  119. if (err) {
  120. fops_put(file->f_op);
  121. file->f_op = fops_get(old_fops);
  122. }
  123. fops_put(old_fops);
  124. mutex_unlock(&videodev_lock);
  125. return err;
  126. }
  127. /*
  128. * helper function -- handles userspace copying for ioctl arguments
  129. */
  130. #ifdef __OLD_VIDIOC_
  131. static unsigned int
  132. video_fix_command(unsigned int cmd)
  133. {
  134. switch (cmd) {
  135. case VIDIOC_OVERLAY_OLD:
  136. cmd = VIDIOC_OVERLAY;
  137. break;
  138. case VIDIOC_S_PARM_OLD:
  139. cmd = VIDIOC_S_PARM;
  140. break;
  141. case VIDIOC_S_CTRL_OLD:
  142. cmd = VIDIOC_S_CTRL;
  143. break;
  144. case VIDIOC_G_AUDIO_OLD:
  145. cmd = VIDIOC_G_AUDIO;
  146. break;
  147. case VIDIOC_G_AUDOUT_OLD:
  148. cmd = VIDIOC_G_AUDOUT;
  149. break;
  150. case VIDIOC_CROPCAP_OLD:
  151. cmd = VIDIOC_CROPCAP;
  152. break;
  153. }
  154. return cmd;
  155. }
  156. #endif
  157. /*
  158. * Obsolete usercopy function - Should be removed soon
  159. */
  160. int
  161. video_usercopy(struct inode *inode, struct file *file,
  162. unsigned int cmd, unsigned long arg,
  163. int (*func)(struct inode *inode, struct file *file,
  164. unsigned int cmd, void *arg))
  165. {
  166. char sbuf[128];
  167. void *mbuf = NULL;
  168. void *parg = NULL;
  169. int err = -EINVAL;
  170. int is_ext_ctrl;
  171. size_t ctrls_size = 0;
  172. void __user *user_ptr = NULL;
  173. #ifdef __OLD_VIDIOC_
  174. cmd = video_fix_command(cmd);
  175. #endif
  176. is_ext_ctrl = (cmd == VIDIOC_S_EXT_CTRLS || cmd == VIDIOC_G_EXT_CTRLS ||
  177. cmd == VIDIOC_TRY_EXT_CTRLS);
  178. /* Copy arguments into temp kernel buffer */
  179. switch (_IOC_DIR(cmd)) {
  180. case _IOC_NONE:
  181. parg = NULL;
  182. break;
  183. case _IOC_READ:
  184. case _IOC_WRITE:
  185. case (_IOC_WRITE | _IOC_READ):
  186. if (_IOC_SIZE(cmd) <= sizeof(sbuf)) {
  187. parg = sbuf;
  188. } else {
  189. /* too big to allocate from stack */
  190. mbuf = kmalloc(_IOC_SIZE(cmd),GFP_KERNEL);
  191. if (NULL == mbuf)
  192. return -ENOMEM;
  193. parg = mbuf;
  194. }
  195. err = -EFAULT;
  196. if (_IOC_DIR(cmd) & _IOC_WRITE)
  197. if (copy_from_user(parg, (void __user *)arg, _IOC_SIZE(cmd)))
  198. goto out;
  199. break;
  200. }
  201. if (is_ext_ctrl) {
  202. struct v4l2_ext_controls *p = parg;
  203. /* In case of an error, tell the caller that it wasn't
  204. a specific control that caused it. */
  205. p->error_idx = p->count;
  206. user_ptr = (void __user *)p->controls;
  207. if (p->count) {
  208. ctrls_size = sizeof(struct v4l2_ext_control) * p->count;
  209. /* Note: v4l2_ext_controls fits in sbuf[] so mbuf is still NULL. */
  210. mbuf = kmalloc(ctrls_size, GFP_KERNEL);
  211. err = -ENOMEM;
  212. if (NULL == mbuf)
  213. goto out_ext_ctrl;
  214. err = -EFAULT;
  215. if (copy_from_user(mbuf, user_ptr, ctrls_size))
  216. goto out_ext_ctrl;
  217. p->controls = mbuf;
  218. }
  219. }
  220. /* call driver */
  221. err = func(inode, file, cmd, parg);
  222. if (err == -ENOIOCTLCMD)
  223. err = -EINVAL;
  224. if (is_ext_ctrl) {
  225. struct v4l2_ext_controls *p = parg;
  226. p->controls = (void *)user_ptr;
  227. if (p->count && err == 0 && copy_to_user(user_ptr, mbuf, ctrls_size))
  228. err = -EFAULT;
  229. goto out_ext_ctrl;
  230. }
  231. if (err < 0)
  232. goto out;
  233. out_ext_ctrl:
  234. /* Copy results into user buffer */
  235. switch (_IOC_DIR(cmd))
  236. {
  237. case _IOC_READ:
  238. case (_IOC_WRITE | _IOC_READ):
  239. if (copy_to_user((void __user *)arg, parg, _IOC_SIZE(cmd)))
  240. err = -EFAULT;
  241. break;
  242. }
  243. out:
  244. kfree(mbuf);
  245. return err;
  246. }
  247. /*
  248. * open/release helper functions -- handle exclusive opens
  249. * Should be removed soon
  250. */
  251. int video_exclusive_open(struct inode *inode, struct file *file)
  252. {
  253. struct video_device *vfl = video_devdata(file);
  254. int retval = 0;
  255. mutex_lock(&vfl->lock);
  256. if (vfl->users) {
  257. retval = -EBUSY;
  258. } else {
  259. vfl->users++;
  260. }
  261. mutex_unlock(&vfl->lock);
  262. return retval;
  263. }
  264. int video_exclusive_release(struct inode *inode, struct file *file)
  265. {
  266. struct video_device *vfl = video_devdata(file);
  267. vfl->users--;
  268. return 0;
  269. }
  270. static char *v4l2_memory_names[] = {
  271. [V4L2_MEMORY_MMAP] = "mmap",
  272. [V4L2_MEMORY_USERPTR] = "userptr",
  273. [V4L2_MEMORY_OVERLAY] = "overlay",
  274. };
  275. /* FIXME: Those stuff are replicated also on v4l2-common.c */
  276. static char *v4l2_type_names_FIXME[] = {
  277. [V4L2_BUF_TYPE_VIDEO_CAPTURE] = "video-cap",
  278. [V4L2_BUF_TYPE_VIDEO_OVERLAY] = "video-over",
  279. [V4L2_BUF_TYPE_VIDEO_OUTPUT] = "video-out",
  280. [V4L2_BUF_TYPE_VBI_CAPTURE] = "vbi-cap",
  281. [V4L2_BUF_TYPE_VBI_OUTPUT] = "vbi-out",
  282. [V4L2_BUF_TYPE_SLICED_VBI_OUTPUT] = "sliced-vbi-out",
  283. [V4L2_BUF_TYPE_SLICED_VBI_CAPTURE] = "sliced-vbi-capture",
  284. [V4L2_BUF_TYPE_PRIVATE] = "private",
  285. };
  286. static char *v4l2_field_names_FIXME[] = {
  287. [V4L2_FIELD_ANY] = "any",
  288. [V4L2_FIELD_NONE] = "none",
  289. [V4L2_FIELD_TOP] = "top",
  290. [V4L2_FIELD_BOTTOM] = "bottom",
  291. [V4L2_FIELD_INTERLACED] = "interlaced",
  292. [V4L2_FIELD_SEQ_TB] = "seq-tb",
  293. [V4L2_FIELD_SEQ_BT] = "seq-bt",
  294. [V4L2_FIELD_ALTERNATE] = "alternate",
  295. };
  296. #define prt_names(a,arr) (((a)>=0)&&((a)<ARRAY_SIZE(arr)))?arr[a]:"unknown"
  297. static void dbgbuf(unsigned int cmd, struct video_device *vfd,
  298. struct v4l2_buffer *p)
  299. {
  300. struct v4l2_timecode *tc=&p->timecode;
  301. dbgarg (cmd, "%02ld:%02d:%02d.%08ld index=%d, type=%s, "
  302. "bytesused=%d, flags=0x%08d, "
  303. "field=%0d, sequence=%d, memory=%s, offset/userptr=0x%08lx, length=%d\n",
  304. (p->timestamp.tv_sec/3600),
  305. (int)(p->timestamp.tv_sec/60)%60,
  306. (int)(p->timestamp.tv_sec%60),
  307. p->timestamp.tv_usec,
  308. p->index,
  309. prt_names(p->type,v4l2_type_names_FIXME),
  310. p->bytesused,p->flags,
  311. p->field,p->sequence,
  312. prt_names(p->memory,v4l2_memory_names),
  313. p->m.userptr, p->length);
  314. dbgarg2 ("timecode= %02d:%02d:%02d type=%d, "
  315. "flags=0x%08d, frames=%d, userbits=0x%08x\n",
  316. tc->hours,tc->minutes,tc->seconds,
  317. tc->type, tc->flags, tc->frames, *(__u32 *) tc->userbits);
  318. }
  319. static inline void dbgrect(struct video_device *vfd, char *s,
  320. struct v4l2_rect *r)
  321. {
  322. dbgarg2 ("%sRect start at %dx%d, size= %dx%d\n", s, r->left, r->top,
  323. r->width, r->height);
  324. };
  325. static inline void v4l_print_pix_fmt (struct video_device *vfd,
  326. struct v4l2_pix_format *fmt)
  327. {
  328. dbgarg2 ("width=%d, height=%d, format=%c%c%c%c, field=%s, "
  329. "bytesperline=%d sizeimage=%d, colorspace=%d\n",
  330. fmt->width,fmt->height,
  331. (fmt->pixelformat & 0xff),
  332. (fmt->pixelformat >> 8) & 0xff,
  333. (fmt->pixelformat >> 16) & 0xff,
  334. (fmt->pixelformat >> 24) & 0xff,
  335. prt_names(fmt->field,v4l2_field_names_FIXME),
  336. fmt->bytesperline,fmt->sizeimage,fmt->colorspace);
  337. };
  338. static int check_fmt (struct video_device *vfd, enum v4l2_buf_type type)
  339. {
  340. switch (type) {
  341. case V4L2_BUF_TYPE_VIDEO_CAPTURE:
  342. if (vfd->vidioc_try_fmt_cap)
  343. return (0);
  344. break;
  345. case V4L2_BUF_TYPE_VIDEO_OVERLAY:
  346. if (vfd->vidioc_try_fmt_overlay)
  347. return (0);
  348. break;
  349. case V4L2_BUF_TYPE_VBI_CAPTURE:
  350. if (vfd->vidioc_try_fmt_vbi)
  351. return (0);
  352. break;
  353. case V4L2_BUF_TYPE_SLICED_VBI_OUTPUT:
  354. if (vfd->vidioc_try_fmt_vbi_output)
  355. return (0);
  356. break;
  357. case V4L2_BUF_TYPE_SLICED_VBI_CAPTURE:
  358. if (vfd->vidioc_try_fmt_vbi_capture)
  359. return (0);
  360. break;
  361. case V4L2_BUF_TYPE_VIDEO_OUTPUT:
  362. if (vfd->vidioc_try_fmt_video_output)
  363. return (0);
  364. break;
  365. case V4L2_BUF_TYPE_VBI_OUTPUT:
  366. if (vfd->vidioc_try_fmt_vbi_output)
  367. return (0);
  368. break;
  369. case V4L2_BUF_TYPE_PRIVATE:
  370. if (vfd->vidioc_try_fmt_type_private)
  371. return (0);
  372. break;
  373. }
  374. return (-EINVAL);
  375. }
  376. static int __video_do_ioctl(struct inode *inode, struct file *file,
  377. unsigned int cmd, void *arg)
  378. {
  379. struct video_device *vfd = video_devdata(file);
  380. void *fh = file->private_data;
  381. int ret = -EINVAL;
  382. if ( (vfd->debug & V4L2_DEBUG_IOCTL) &&
  383. !(vfd->debug | V4L2_DEBUG_IOCTL_ARG)) {
  384. v4l_print_ioctl(vfd->name, cmd);
  385. }
  386. if (_IOC_TYPE(cmd)=='v')
  387. return v4l_compat_translate_ioctl(inode,file,cmd,arg,
  388. __video_do_ioctl);
  389. switch(cmd) {
  390. /* --- capabilities ------------------------------------------ */
  391. case VIDIOC_QUERYCAP:
  392. {
  393. struct v4l2_capability *cap = (struct v4l2_capability*)arg;
  394. memset(cap, 0, sizeof(*cap));
  395. if (!vfd->vidioc_querycap)
  396. break;
  397. ret=vfd->vidioc_querycap(file, fh, cap);
  398. if (!ret)
  399. dbgarg (cmd, "driver=%s, card=%s, bus=%s, "
  400. "version=0x%08x, "
  401. "capabilities=0x%08x\n",
  402. cap->driver,cap->card,cap->bus_info,
  403. cap->version,
  404. cap->capabilities);
  405. break;
  406. }
  407. /* --- priority ------------------------------------------ */
  408. case VIDIOC_G_PRIORITY:
  409. {
  410. enum v4l2_priority *p=arg;
  411. if (!vfd->vidioc_g_priority)
  412. break;
  413. ret=vfd->vidioc_g_priority(file, fh, p);
  414. if (!ret)
  415. dbgarg(cmd, "priority is %d\n", *p);
  416. break;
  417. }
  418. case VIDIOC_S_PRIORITY:
  419. {
  420. enum v4l2_priority *p=arg;
  421. if (!vfd->vidioc_s_priority)
  422. break;
  423. dbgarg(cmd, "setting priority to %d\n", *p);
  424. ret=vfd->vidioc_s_priority(file, fh, *p);
  425. break;
  426. }
  427. /* --- capture ioctls ---------------------------------------- */
  428. case VIDIOC_ENUM_FMT:
  429. {
  430. struct v4l2_fmtdesc *f = arg;
  431. enum v4l2_buf_type type;
  432. unsigned int index;
  433. index = f->index;
  434. type = f->type;
  435. memset(f,0,sizeof(*f));
  436. f->index = index;
  437. f->type = type;
  438. switch (type) {
  439. case V4L2_BUF_TYPE_VIDEO_CAPTURE:
  440. if (vfd->vidioc_enum_fmt_cap)
  441. ret=vfd->vidioc_enum_fmt_cap(file, fh, f);
  442. break;
  443. case V4L2_BUF_TYPE_VIDEO_OVERLAY:
  444. if (vfd->vidioc_enum_fmt_overlay)
  445. ret=vfd->vidioc_enum_fmt_overlay(file, fh, f);
  446. break;
  447. case V4L2_BUF_TYPE_VBI_CAPTURE:
  448. if (vfd->vidioc_enum_fmt_vbi)
  449. ret=vfd->vidioc_enum_fmt_vbi(file, fh, f);
  450. break;
  451. case V4L2_BUF_TYPE_SLICED_VBI_OUTPUT:
  452. if (vfd->vidioc_enum_fmt_vbi_output)
  453. ret=vfd->vidioc_enum_fmt_vbi_output(file,
  454. fh, f);
  455. break;
  456. case V4L2_BUF_TYPE_SLICED_VBI_CAPTURE:
  457. if (vfd->vidioc_enum_fmt_vbi_capture)
  458. ret=vfd->vidioc_enum_fmt_vbi_capture(file,
  459. fh, f);
  460. break;
  461. case V4L2_BUF_TYPE_VIDEO_OUTPUT:
  462. if (vfd->vidioc_enum_fmt_video_output)
  463. ret=vfd->vidioc_enum_fmt_video_output(file,
  464. fh, f);
  465. break;
  466. case V4L2_BUF_TYPE_VBI_OUTPUT:
  467. if (vfd->vidioc_enum_fmt_vbi_output)
  468. ret=vfd->vidioc_enum_fmt_vbi_output(file,
  469. fh, f);
  470. break;
  471. case V4L2_BUF_TYPE_PRIVATE:
  472. if (vfd->vidioc_enum_fmt_type_private)
  473. ret=vfd->vidioc_enum_fmt_type_private(file,
  474. fh, f);
  475. break;
  476. }
  477. if (!ret)
  478. dbgarg (cmd, "index=%d, type=%d, flags=%d, "
  479. "pixelformat=%c%c%c%c, description='%s'\n",
  480. f->index, f->type, f->flags,
  481. (f->pixelformat & 0xff),
  482. (f->pixelformat >> 8) & 0xff,
  483. (f->pixelformat >> 16) & 0xff,
  484. (f->pixelformat >> 24) & 0xff,
  485. f->description);
  486. break;
  487. }
  488. case VIDIOC_G_FMT:
  489. {
  490. struct v4l2_format *f = (struct v4l2_format *)arg;
  491. enum v4l2_buf_type type=f->type;
  492. memset(&f->fmt.pix,0,sizeof(f->fmt.pix));
  493. f->type=type;
  494. /* FIXME: Should be one dump per type */
  495. dbgarg (cmd, "type=%s\n", prt_names(type,
  496. v4l2_type_names_FIXME));
  497. switch (type) {
  498. case V4L2_BUF_TYPE_VIDEO_CAPTURE:
  499. if (vfd->vidioc_g_fmt_cap)
  500. ret=vfd->vidioc_g_fmt_cap(file, fh, f);
  501. if (!ret)
  502. v4l_print_pix_fmt(vfd,&f->fmt.pix);
  503. break;
  504. case V4L2_BUF_TYPE_VIDEO_OVERLAY:
  505. if (vfd->vidioc_g_fmt_overlay)
  506. ret=vfd->vidioc_g_fmt_overlay(file, fh, f);
  507. break;
  508. case V4L2_BUF_TYPE_VBI_CAPTURE:
  509. if (vfd->vidioc_g_fmt_vbi)
  510. ret=vfd->vidioc_g_fmt_vbi(file, fh, f);
  511. break;
  512. case V4L2_BUF_TYPE_SLICED_VBI_OUTPUT:
  513. if (vfd->vidioc_g_fmt_vbi_output)
  514. ret=vfd->vidioc_g_fmt_vbi_output(file, fh, f);
  515. break;
  516. case V4L2_BUF_TYPE_SLICED_VBI_CAPTURE:
  517. if (vfd->vidioc_g_fmt_vbi_capture)
  518. ret=vfd->vidioc_g_fmt_vbi_capture(file, fh, f);
  519. break;
  520. case V4L2_BUF_TYPE_VIDEO_OUTPUT:
  521. if (vfd->vidioc_g_fmt_video_output)
  522. ret=vfd->vidioc_g_fmt_video_output(file,
  523. fh, f);
  524. break;
  525. case V4L2_BUF_TYPE_VBI_OUTPUT:
  526. if (vfd->vidioc_g_fmt_vbi_output)
  527. ret=vfd->vidioc_g_fmt_vbi_output(file, fh, f);
  528. break;
  529. case V4L2_BUF_TYPE_PRIVATE:
  530. if (vfd->vidioc_g_fmt_type_private)
  531. ret=vfd->vidioc_g_fmt_type_private(file,
  532. fh, f);
  533. break;
  534. }
  535. break;
  536. }
  537. case VIDIOC_S_FMT:
  538. {
  539. struct v4l2_format *f = (struct v4l2_format *)arg;
  540. /* FIXME: Should be one dump per type */
  541. dbgarg (cmd, "type=%s\n", prt_names(f->type,
  542. v4l2_type_names_FIXME));
  543. switch (f->type) {
  544. case V4L2_BUF_TYPE_VIDEO_CAPTURE:
  545. v4l_print_pix_fmt(vfd,&f->fmt.pix);
  546. if (vfd->vidioc_s_fmt_cap)
  547. ret=vfd->vidioc_s_fmt_cap(file, fh, f);
  548. break;
  549. case V4L2_BUF_TYPE_VIDEO_OVERLAY:
  550. if (vfd->vidioc_s_fmt_overlay)
  551. ret=vfd->vidioc_s_fmt_overlay(file, fh, f);
  552. break;
  553. case V4L2_BUF_TYPE_VBI_CAPTURE:
  554. if (vfd->vidioc_s_fmt_vbi)
  555. ret=vfd->vidioc_s_fmt_vbi(file, fh, f);
  556. break;
  557. case V4L2_BUF_TYPE_SLICED_VBI_OUTPUT:
  558. if (vfd->vidioc_s_fmt_vbi_output)
  559. ret=vfd->vidioc_s_fmt_vbi_output(file, fh, f);
  560. break;
  561. case V4L2_BUF_TYPE_SLICED_VBI_CAPTURE:
  562. if (vfd->vidioc_s_fmt_vbi_capture)
  563. ret=vfd->vidioc_s_fmt_vbi_capture(file, fh, f);
  564. break;
  565. case V4L2_BUF_TYPE_VIDEO_OUTPUT:
  566. if (vfd->vidioc_s_fmt_video_output)
  567. ret=vfd->vidioc_s_fmt_video_output(file,
  568. fh, f);
  569. break;
  570. case V4L2_BUF_TYPE_VBI_OUTPUT:
  571. if (vfd->vidioc_s_fmt_vbi_output)
  572. ret=vfd->vidioc_s_fmt_vbi_output(file,
  573. fh, f);
  574. break;
  575. case V4L2_BUF_TYPE_PRIVATE:
  576. if (vfd->vidioc_s_fmt_type_private)
  577. ret=vfd->vidioc_s_fmt_type_private(file,
  578. fh, f);
  579. break;
  580. }
  581. break;
  582. }
  583. case VIDIOC_TRY_FMT:
  584. {
  585. struct v4l2_format *f = (struct v4l2_format *)arg;
  586. /* FIXME: Should be one dump per type */
  587. dbgarg (cmd, "type=%s\n", prt_names(f->type,
  588. v4l2_type_names_FIXME));
  589. switch (f->type) {
  590. case V4L2_BUF_TYPE_VIDEO_CAPTURE:
  591. if (vfd->vidioc_try_fmt_cap)
  592. ret=vfd->vidioc_try_fmt_cap(file, fh, f);
  593. if (!ret)
  594. v4l_print_pix_fmt(vfd,&f->fmt.pix);
  595. break;
  596. case V4L2_BUF_TYPE_VIDEO_OVERLAY:
  597. if (vfd->vidioc_try_fmt_overlay)
  598. ret=vfd->vidioc_try_fmt_overlay(file, fh, f);
  599. break;
  600. case V4L2_BUF_TYPE_VBI_CAPTURE:
  601. if (vfd->vidioc_try_fmt_vbi)
  602. ret=vfd->vidioc_try_fmt_vbi(file, fh, f);
  603. break;
  604. case V4L2_BUF_TYPE_SLICED_VBI_OUTPUT:
  605. if (vfd->vidioc_try_fmt_vbi_output)
  606. ret=vfd->vidioc_try_fmt_vbi_output(file,
  607. fh, f);
  608. break;
  609. case V4L2_BUF_TYPE_SLICED_VBI_CAPTURE:
  610. if (vfd->vidioc_try_fmt_vbi_capture)
  611. ret=vfd->vidioc_try_fmt_vbi_capture(file,
  612. fh, f);
  613. break;
  614. case V4L2_BUF_TYPE_VIDEO_OUTPUT:
  615. if (vfd->vidioc_try_fmt_video_output)
  616. ret=vfd->vidioc_try_fmt_video_output(file,
  617. fh, f);
  618. break;
  619. case V4L2_BUF_TYPE_VBI_OUTPUT:
  620. if (vfd->vidioc_try_fmt_vbi_output)
  621. ret=vfd->vidioc_try_fmt_vbi_output(file,
  622. fh, f);
  623. break;
  624. case V4L2_BUF_TYPE_PRIVATE:
  625. if (vfd->vidioc_try_fmt_type_private)
  626. ret=vfd->vidioc_try_fmt_type_private(file,
  627. fh, f);
  628. break;
  629. }
  630. break;
  631. }
  632. /* FIXME: Those buf reqs could be handled here,
  633. with some changes on videobuf to allow its header to be included at
  634. videodev2.h or being merged at videodev2.
  635. */
  636. case VIDIOC_REQBUFS:
  637. {
  638. struct v4l2_requestbuffers *p=arg;
  639. if (!vfd->vidioc_reqbufs)
  640. break;
  641. ret = check_fmt (vfd, p->type);
  642. if (ret)
  643. break;
  644. ret=vfd->vidioc_reqbufs(file, fh, p);
  645. dbgarg (cmd, "count=%d, type=%s, memory=%s\n",
  646. p->count,
  647. prt_names(p->type,v4l2_type_names_FIXME),
  648. prt_names(p->memory,v4l2_memory_names));
  649. break;
  650. }
  651. case VIDIOC_QUERYBUF:
  652. {
  653. struct v4l2_buffer *p=arg;
  654. if (!vfd->vidioc_querybuf)
  655. break;
  656. ret = check_fmt (vfd, p->type);
  657. if (ret)
  658. break;
  659. ret=vfd->vidioc_querybuf(file, fh, p);
  660. if (!ret)
  661. dbgbuf(cmd,vfd,p);
  662. break;
  663. }
  664. case VIDIOC_QBUF:
  665. {
  666. struct v4l2_buffer *p=arg;
  667. if (!vfd->vidioc_qbuf)
  668. break;
  669. ret = check_fmt (vfd, p->type);
  670. if (ret)
  671. break;
  672. ret=vfd->vidioc_qbuf(file, fh, p);
  673. if (!ret)
  674. dbgbuf(cmd,vfd,p);
  675. break;
  676. }
  677. case VIDIOC_DQBUF:
  678. {
  679. struct v4l2_buffer *p=arg;
  680. if (!vfd->vidioc_dqbuf)
  681. break;
  682. ret = check_fmt (vfd, p->type);
  683. if (ret)
  684. break;
  685. ret=vfd->vidioc_dqbuf(file, fh, p);
  686. if (!ret)
  687. dbgbuf(cmd,vfd,p);
  688. break;
  689. }
  690. case VIDIOC_OVERLAY:
  691. {
  692. int *i = arg;
  693. if (!vfd->vidioc_overlay)
  694. break;
  695. dbgarg (cmd, "value=%d\n",*i);
  696. ret=vfd->vidioc_overlay(file, fh, *i);
  697. break;
  698. }
  699. #ifdef CONFIG_VIDEO_V4L1_COMPAT
  700. /* --- streaming capture ------------------------------------- */
  701. case VIDIOCGMBUF:
  702. {
  703. struct video_mbuf *p=arg;
  704. memset(p,0,sizeof(p));
  705. if (!vfd->vidiocgmbuf)
  706. break;
  707. ret=vfd->vidiocgmbuf(file, fh, p);
  708. if (!ret)
  709. dbgarg (cmd, "size=%d, frames=%d, offsets=0x%08lx\n",
  710. p->size, p->frames,
  711. (unsigned long)p->offsets);
  712. break;
  713. }
  714. #endif
  715. case VIDIOC_G_FBUF:
  716. {
  717. struct v4l2_framebuffer *p=arg;
  718. if (!vfd->vidioc_g_fbuf)
  719. break;
  720. ret=vfd->vidioc_g_fbuf(file, fh, arg);
  721. if (!ret) {
  722. dbgarg (cmd, "capability=%d, flags=%d, base=0x%08lx\n",
  723. p->capability,p->flags,
  724. (unsigned long)p->base);
  725. v4l_print_pix_fmt (vfd, &p->fmt);
  726. }
  727. break;
  728. }
  729. case VIDIOC_S_FBUF:
  730. {
  731. struct v4l2_framebuffer *p=arg;
  732. if (!vfd->vidioc_s_fbuf)
  733. break;
  734. dbgarg (cmd, "capability=%d, flags=%d, base=0x%08lx\n",
  735. p->capability,p->flags,(unsigned long)p->base);
  736. v4l_print_pix_fmt (vfd, &p->fmt);
  737. ret=vfd->vidioc_s_fbuf(file, fh, arg);
  738. break;
  739. }
  740. case VIDIOC_STREAMON:
  741. {
  742. enum v4l2_buf_type i = *(int *)arg;
  743. if (!vfd->vidioc_streamon)
  744. break;
  745. dbgarg (cmd, "type=%s\n", prt_names(i,v4l2_type_names_FIXME));
  746. ret=vfd->vidioc_streamon(file, fh,i);
  747. break;
  748. }
  749. case VIDIOC_STREAMOFF:
  750. {
  751. enum v4l2_buf_type i = *(int *)arg;
  752. if (!vfd->vidioc_streamoff)
  753. break;
  754. dbgarg (cmd, "type=%s\n", prt_names(i,v4l2_type_names_FIXME));
  755. ret=vfd->vidioc_streamoff(file, fh, i);
  756. break;
  757. }
  758. /* ---------- tv norms ---------- */
  759. case VIDIOC_ENUMSTD:
  760. {
  761. struct v4l2_standard *p = arg;
  762. v4l2_std_id id = vfd->tvnorms,curr_id=0;
  763. unsigned int index = p->index,i;
  764. if (index<0) {
  765. ret=-EINVAL;
  766. break;
  767. }
  768. /* Return norm array on a canonical way */
  769. for (i=0;i<= index && id; i++) {
  770. if ( (id & V4L2_STD_PAL) == V4L2_STD_PAL) {
  771. curr_id = V4L2_STD_PAL;
  772. } else if ( (id & V4L2_STD_PAL_BG) == V4L2_STD_PAL_BG) {
  773. curr_id = V4L2_STD_PAL_BG;
  774. } else if ( (id & V4L2_STD_PAL_DK) == V4L2_STD_PAL_DK) {
  775. curr_id = V4L2_STD_PAL_DK;
  776. } else if ( (id & V4L2_STD_PAL_B) == V4L2_STD_PAL_B) {
  777. curr_id = V4L2_STD_PAL_B;
  778. } else if ( (id & V4L2_STD_PAL_B1) == V4L2_STD_PAL_B1) {
  779. curr_id = V4L2_STD_PAL_B1;
  780. } else if ( (id & V4L2_STD_PAL_G) == V4L2_STD_PAL_G) {
  781. curr_id = V4L2_STD_PAL_G;
  782. } else if ( (id & V4L2_STD_PAL_H) == V4L2_STD_PAL_H) {
  783. curr_id = V4L2_STD_PAL_H;
  784. } else if ( (id & V4L2_STD_PAL_I) == V4L2_STD_PAL_I) {
  785. curr_id = V4L2_STD_PAL_I;
  786. } else if ( (id & V4L2_STD_PAL_D) == V4L2_STD_PAL_D) {
  787. curr_id = V4L2_STD_PAL_D;
  788. } else if ( (id & V4L2_STD_PAL_D1) == V4L2_STD_PAL_D1) {
  789. curr_id = V4L2_STD_PAL_D1;
  790. } else if ( (id & V4L2_STD_PAL_K) == V4L2_STD_PAL_K) {
  791. curr_id = V4L2_STD_PAL_K;
  792. } else if ( (id & V4L2_STD_PAL_M) == V4L2_STD_PAL_M) {
  793. curr_id = V4L2_STD_PAL_M;
  794. } else if ( (id & V4L2_STD_PAL_N) == V4L2_STD_PAL_N) {
  795. curr_id = V4L2_STD_PAL_N;
  796. } else if ( (id & V4L2_STD_PAL_Nc) == V4L2_STD_PAL_Nc) {
  797. curr_id = V4L2_STD_PAL_Nc;
  798. } else if ( (id & V4L2_STD_PAL_60) == V4L2_STD_PAL_60) {
  799. curr_id = V4L2_STD_PAL_60;
  800. } else if ( (id & V4L2_STD_NTSC) == V4L2_STD_NTSC) {
  801. curr_id = V4L2_STD_NTSC;
  802. } else if ( (id & V4L2_STD_NTSC_M) == V4L2_STD_NTSC_M) {
  803. curr_id = V4L2_STD_NTSC_M;
  804. } else if ( (id & V4L2_STD_NTSC_M_JP) == V4L2_STD_NTSC_M_JP) {
  805. curr_id = V4L2_STD_NTSC_M_JP;
  806. } else if ( (id & V4L2_STD_NTSC_443) == V4L2_STD_NTSC_443) {
  807. curr_id = V4L2_STD_NTSC_443;
  808. } else if ( (id & V4L2_STD_NTSC_M_KR) == V4L2_STD_NTSC_M_KR) {
  809. curr_id = V4L2_STD_NTSC_M_KR;
  810. } else if ( (id & V4L2_STD_SECAM) == V4L2_STD_SECAM) {
  811. curr_id = V4L2_STD_SECAM;
  812. } else if ( (id & V4L2_STD_SECAM_DK) == V4L2_STD_SECAM_DK) {
  813. curr_id = V4L2_STD_SECAM_DK;
  814. } else if ( (id & V4L2_STD_SECAM_B) == V4L2_STD_SECAM_B) {
  815. curr_id = V4L2_STD_SECAM_B;
  816. } else if ( (id & V4L2_STD_SECAM_D) == V4L2_STD_SECAM_D) {
  817. curr_id = V4L2_STD_SECAM_D;
  818. } else if ( (id & V4L2_STD_SECAM_G) == V4L2_STD_SECAM_G) {
  819. curr_id = V4L2_STD_SECAM_G;
  820. } else if ( (id & V4L2_STD_SECAM_H) == V4L2_STD_SECAM_H) {
  821. curr_id = V4L2_STD_SECAM_H;
  822. } else if ( (id & V4L2_STD_SECAM_K) == V4L2_STD_SECAM_K) {
  823. curr_id = V4L2_STD_SECAM_K;
  824. } else if ( (id & V4L2_STD_SECAM_K1) == V4L2_STD_SECAM_K1) {
  825. curr_id = V4L2_STD_SECAM_K1;
  826. } else if ( (id & V4L2_STD_SECAM_L) == V4L2_STD_SECAM_L) {
  827. curr_id = V4L2_STD_SECAM_L;
  828. } else if ( (id & V4L2_STD_SECAM_LC) == V4L2_STD_SECAM_LC) {
  829. curr_id = V4L2_STD_SECAM_LC;
  830. } else {
  831. break;
  832. }
  833. id &= ~curr_id;
  834. }
  835. if (i<=index)
  836. return -EINVAL;
  837. v4l2_video_std_construct(p, curr_id,v4l2_norm_to_name(curr_id));
  838. p->index = index;
  839. dbgarg (cmd, "index=%d, id=%Ld, name=%s, fps=%d/%d, "
  840. "framelines=%d\n", p->index,
  841. (unsigned long long)p->id, p->name,
  842. p->frameperiod.numerator,
  843. p->frameperiod.denominator,
  844. p->framelines);
  845. ret=0;
  846. break;
  847. }
  848. case VIDIOC_G_STD:
  849. {
  850. v4l2_std_id *id = arg;
  851. *id = vfd->current_norm;
  852. dbgarg (cmd, "value=%Lu\n", (long long unsigned) *id);
  853. ret=0;
  854. break;
  855. }
  856. case VIDIOC_S_STD:
  857. {
  858. v4l2_std_id *id = arg,norm;
  859. dbgarg (cmd, "value=%Lu\n", (long long unsigned) *id);
  860. norm = (*id) & vfd->tvnorms;
  861. if ( vfd->tvnorms && !norm) /* Check if std is supported */
  862. break;
  863. /* Calls the specific handler */
  864. if (vfd->vidioc_s_std)
  865. ret=vfd->vidioc_s_std(file, fh, &norm);
  866. else
  867. ret=-EINVAL;
  868. /* Updates standard information */
  869. if (ret>=0)
  870. vfd->current_norm=norm;
  871. break;
  872. }
  873. case VIDIOC_QUERYSTD:
  874. {
  875. v4l2_std_id *p=arg;
  876. if (!vfd->vidioc_querystd)
  877. break;
  878. ret=vfd->vidioc_querystd(file, fh, arg);
  879. if (!ret)
  880. dbgarg (cmd, "detected std=%Lu\n",
  881. (unsigned long long)*p);
  882. break;
  883. }
  884. /* ------ input switching ---------- */
  885. /* FIXME: Inputs can be handled inside videodev2 */
  886. case VIDIOC_ENUMINPUT:
  887. {
  888. struct v4l2_input *p=arg;
  889. int i=p->index;
  890. if (!vfd->vidioc_enum_input)
  891. break;
  892. memset(p, 0, sizeof(*p));
  893. p->index=i;
  894. ret=vfd->vidioc_enum_input(file, fh, p);
  895. if (!ret)
  896. dbgarg (cmd, "index=%d, name=%s, type=%d, "
  897. "audioset=%d, "
  898. "tuner=%d, std=%Ld, status=%d\n",
  899. p->index,p->name,p->type,p->audioset,
  900. p->tuner,
  901. (unsigned long long)p->std,
  902. p->status);
  903. break;
  904. }
  905. case VIDIOC_G_INPUT:
  906. {
  907. unsigned int *i = arg;
  908. if (!vfd->vidioc_g_input)
  909. break;
  910. ret=vfd->vidioc_g_input(file, fh, i);
  911. if (!ret)
  912. dbgarg (cmd, "value=%d\n",*i);
  913. break;
  914. }
  915. case VIDIOC_S_INPUT:
  916. {
  917. unsigned int *i = arg;
  918. if (!vfd->vidioc_s_input)
  919. break;
  920. dbgarg (cmd, "value=%d\n",*i);
  921. ret=vfd->vidioc_s_input(file, fh, *i);
  922. break;
  923. }
  924. /* ------ output switching ---------- */
  925. case VIDIOC_G_OUTPUT:
  926. {
  927. unsigned int *i = arg;
  928. if (!vfd->vidioc_g_output)
  929. break;
  930. ret=vfd->vidioc_g_output(file, fh, i);
  931. if (!ret)
  932. dbgarg (cmd, "value=%d\n",*i);
  933. break;
  934. }
  935. case VIDIOC_S_OUTPUT:
  936. {
  937. unsigned int *i = arg;
  938. if (!vfd->vidioc_s_output)
  939. break;
  940. dbgarg (cmd, "value=%d\n",*i);
  941. ret=vfd->vidioc_s_output(file, fh, *i);
  942. break;
  943. }
  944. /* --- controls ---------------------------------------------- */
  945. case VIDIOC_QUERYCTRL:
  946. {
  947. struct v4l2_queryctrl *p=arg;
  948. if (!vfd->vidioc_queryctrl)
  949. break;
  950. ret=vfd->vidioc_queryctrl(file, fh, p);
  951. if (!ret)
  952. dbgarg (cmd, "id=%d, type=%d, name=%s, "
  953. "min/max=%d/%d,"
  954. " step=%d, default=%d, flags=0x%08x\n",
  955. p->id,p->type,p->name,p->minimum,
  956. p->maximum,p->step,p->default_value,
  957. p->flags);
  958. break;
  959. }
  960. case VIDIOC_G_CTRL:
  961. {
  962. struct v4l2_control *p = arg;
  963. if (!vfd->vidioc_g_ctrl)
  964. break;
  965. dbgarg(cmd, "Enum for index=%d\n", p->id);
  966. ret=vfd->vidioc_g_ctrl(file, fh, p);
  967. if (!ret)
  968. dbgarg2 ( "id=%d, value=%d\n", p->id, p->value);
  969. break;
  970. }
  971. case VIDIOC_S_CTRL:
  972. {
  973. struct v4l2_control *p = arg;
  974. if (!vfd->vidioc_s_ctrl)
  975. break;
  976. dbgarg (cmd, "id=%d, value=%d\n", p->id, p->value);
  977. ret=vfd->vidioc_s_ctrl(file, fh, p);
  978. break;
  979. }
  980. case VIDIOC_G_EXT_CTRLS:
  981. {
  982. struct v4l2_ext_controls *p = arg;
  983. if (vfd->vidioc_g_ext_ctrls) {
  984. dbgarg(cmd, "count=%d\n", p->count);
  985. ret=vfd->vidioc_g_ext_ctrls(file, fh, p);
  986. }
  987. break;
  988. }
  989. case VIDIOC_S_EXT_CTRLS:
  990. {
  991. struct v4l2_ext_controls *p = arg;
  992. if (vfd->vidioc_s_ext_ctrls) {
  993. dbgarg(cmd, "count=%d\n", p->count);
  994. ret=vfd->vidioc_s_ext_ctrls(file, fh, p);
  995. }
  996. break;
  997. }
  998. case VIDIOC_TRY_EXT_CTRLS:
  999. {
  1000. struct v4l2_ext_controls *p = arg;
  1001. if (vfd->vidioc_try_ext_ctrls) {
  1002. dbgarg(cmd, "count=%d\n", p->count);
  1003. ret=vfd->vidioc_try_ext_ctrls(file, fh, p);
  1004. }
  1005. break;
  1006. }
  1007. case VIDIOC_QUERYMENU:
  1008. {
  1009. struct v4l2_querymenu *p=arg;
  1010. if (!vfd->vidioc_querymenu)
  1011. break;
  1012. ret=vfd->vidioc_querymenu(file, fh, p);
  1013. if (!ret)
  1014. dbgarg (cmd, "id=%d, index=%d, name=%s\n",
  1015. p->id,p->index,p->name);
  1016. break;
  1017. }
  1018. /* --- audio ---------------------------------------------- */
  1019. case VIDIOC_ENUMAUDIO:
  1020. {
  1021. struct v4l2_audio *p=arg;
  1022. if (!vfd->vidioc_enumaudio)
  1023. break;
  1024. dbgarg(cmd, "Enum for index=%d\n", p->index);
  1025. ret=vfd->vidioc_enumaudio(file, fh, p);
  1026. if (!ret)
  1027. dbgarg2("index=%d, name=%s, capability=%d, "
  1028. "mode=%d\n",p->index,p->name,
  1029. p->capability, p->mode);
  1030. break;
  1031. }
  1032. case VIDIOC_G_AUDIO:
  1033. {
  1034. struct v4l2_audio *p=arg;
  1035. __u32 index=p->index;
  1036. if (!vfd->vidioc_g_audio)
  1037. break;
  1038. memset(p,0,sizeof(*p));
  1039. p->index=index;
  1040. dbgarg(cmd, "Get for index=%d\n", p->index);
  1041. ret=vfd->vidioc_g_audio(file, fh, p);
  1042. if (!ret)
  1043. dbgarg2("index=%d, name=%s, capability=%d, "
  1044. "mode=%d\n",p->index,
  1045. p->name,p->capability, p->mode);
  1046. break;
  1047. }
  1048. case VIDIOC_S_AUDIO:
  1049. {
  1050. struct v4l2_audio *p=arg;
  1051. if (!vfd->vidioc_s_audio)
  1052. break;
  1053. dbgarg(cmd, "index=%d, name=%s, capability=%d, "
  1054. "mode=%d\n", p->index, p->name,
  1055. p->capability, p->mode);
  1056. ret=vfd->vidioc_s_audio(file, fh, p);
  1057. break;
  1058. }
  1059. case VIDIOC_ENUMAUDOUT:
  1060. {
  1061. struct v4l2_audioout *p=arg;
  1062. if (!vfd->vidioc_enumaudout)
  1063. break;
  1064. dbgarg(cmd, "Enum for index=%d\n", p->index);
  1065. ret=vfd->vidioc_enumaudout(file, fh, p);
  1066. if (!ret)
  1067. dbgarg2("index=%d, name=%s, capability=%d, "
  1068. "mode=%d\n", p->index, p->name,
  1069. p->capability,p->mode);
  1070. break;
  1071. }
  1072. case VIDIOC_G_AUDOUT:
  1073. {
  1074. struct v4l2_audioout *p=arg;
  1075. if (!vfd->vidioc_g_audout)
  1076. break;
  1077. dbgarg(cmd, "Enum for index=%d\n", p->index);
  1078. ret=vfd->vidioc_g_audout(file, fh, p);
  1079. if (!ret)
  1080. dbgarg2("index=%d, name=%s, capability=%d, "
  1081. "mode=%d\n", p->index, p->name,
  1082. p->capability,p->mode);
  1083. break;
  1084. }
  1085. case VIDIOC_S_AUDOUT:
  1086. {
  1087. struct v4l2_audioout *p=arg;
  1088. if (!vfd->vidioc_s_audout)
  1089. break;
  1090. dbgarg(cmd, "index=%d, name=%s, capability=%d, "
  1091. "mode=%d\n", p->index, p->name,
  1092. p->capability,p->mode);
  1093. ret=vfd->vidioc_s_audout(file, fh, p);
  1094. break;
  1095. }
  1096. case VIDIOC_G_MODULATOR:
  1097. {
  1098. struct v4l2_modulator *p=arg;
  1099. if (!vfd->vidioc_g_modulator)
  1100. break;
  1101. ret=vfd->vidioc_g_modulator(file, fh, p);
  1102. if (!ret)
  1103. dbgarg(cmd, "index=%d, name=%s, "
  1104. "capability=%d, rangelow=%d,"
  1105. " rangehigh=%d, txsubchans=%d\n",
  1106. p->index, p->name,p->capability,
  1107. p->rangelow, p->rangehigh,
  1108. p->txsubchans);
  1109. break;
  1110. }
  1111. case VIDIOC_S_MODULATOR:
  1112. {
  1113. struct v4l2_modulator *p=arg;
  1114. if (!vfd->vidioc_s_modulator)
  1115. break;
  1116. dbgarg(cmd, "index=%d, name=%s, capability=%d, "
  1117. "rangelow=%d, rangehigh=%d, txsubchans=%d\n",
  1118. p->index, p->name,p->capability,p->rangelow,
  1119. p->rangehigh,p->txsubchans);
  1120. ret=vfd->vidioc_s_modulator(file, fh, p);
  1121. break;
  1122. }
  1123. case VIDIOC_G_CROP:
  1124. {
  1125. struct v4l2_crop *p=arg;
  1126. if (!vfd->vidioc_g_crop)
  1127. break;
  1128. ret=vfd->vidioc_g_crop(file, fh, p);
  1129. if (!ret) {
  1130. dbgarg(cmd, "type=%d\n", p->type);
  1131. dbgrect(vfd, "", &p->c);
  1132. }
  1133. break;
  1134. }
  1135. case VIDIOC_S_CROP:
  1136. {
  1137. struct v4l2_crop *p=arg;
  1138. if (!vfd->vidioc_s_crop)
  1139. break;
  1140. dbgarg(cmd, "type=%d\n", p->type);
  1141. dbgrect(vfd, "", &p->c);
  1142. ret=vfd->vidioc_s_crop(file, fh, p);
  1143. break;
  1144. }
  1145. case VIDIOC_CROPCAP:
  1146. {
  1147. struct v4l2_cropcap *p=arg;
  1148. /*FIXME: Should also show v4l2_fract pixelaspect */
  1149. if (!vfd->vidioc_cropcap)
  1150. break;
  1151. dbgarg(cmd, "type=%d\n", p->type);
  1152. dbgrect(vfd, "bounds ", &p->bounds);
  1153. dbgrect(vfd, "defrect ", &p->defrect);
  1154. ret=vfd->vidioc_cropcap(file, fh, p);
  1155. break;
  1156. }
  1157. case VIDIOC_G_MPEGCOMP:
  1158. {
  1159. struct v4l2_mpeg_compression *p=arg;
  1160. /*FIXME: Several fields not shown */
  1161. if (!vfd->vidioc_g_mpegcomp)
  1162. break;
  1163. ret=vfd->vidioc_g_mpegcomp(file, fh, p);
  1164. if (!ret)
  1165. dbgarg (cmd, "ts_pid_pmt=%d, ts_pid_audio=%d,"
  1166. " ts_pid_video=%d, ts_pid_pcr=%d, "
  1167. "ps_size=%d, au_sample_rate=%d, "
  1168. "au_pesid=%c, vi_frame_rate=%d, "
  1169. "vi_frames_per_gop=%d, "
  1170. "vi_bframes_count=%d, vi_pesid=%c\n",
  1171. p->ts_pid_pmt,p->ts_pid_audio,
  1172. p->ts_pid_video,p->ts_pid_pcr,
  1173. p->ps_size, p->au_sample_rate,
  1174. p->au_pesid, p->vi_frame_rate,
  1175. p->vi_frames_per_gop,
  1176. p->vi_bframes_count, p->vi_pesid);
  1177. break;
  1178. }
  1179. case VIDIOC_S_MPEGCOMP:
  1180. {
  1181. struct v4l2_mpeg_compression *p=arg;
  1182. /*FIXME: Several fields not shown */
  1183. if (!vfd->vidioc_s_mpegcomp)
  1184. break;
  1185. dbgarg (cmd, "ts_pid_pmt=%d, ts_pid_audio=%d, "
  1186. "ts_pid_video=%d, ts_pid_pcr=%d, ps_size=%d, "
  1187. "au_sample_rate=%d, au_pesid=%c, "
  1188. "vi_frame_rate=%d, vi_frames_per_gop=%d, "
  1189. "vi_bframes_count=%d, vi_pesid=%c\n",
  1190. p->ts_pid_pmt,p->ts_pid_audio, p->ts_pid_video,
  1191. p->ts_pid_pcr, p->ps_size, p->au_sample_rate,
  1192. p->au_pesid, p->vi_frame_rate,
  1193. p->vi_frames_per_gop, p->vi_bframes_count,
  1194. p->vi_pesid);
  1195. ret=vfd->vidioc_s_mpegcomp(file, fh, p);
  1196. break;
  1197. }
  1198. case VIDIOC_G_JPEGCOMP:
  1199. {
  1200. struct v4l2_jpegcompression *p=arg;
  1201. if (!vfd->vidioc_g_jpegcomp)
  1202. break;
  1203. ret=vfd->vidioc_g_jpegcomp(file, fh, p);
  1204. if (!ret)
  1205. dbgarg (cmd, "quality=%d, APPn=%d, "
  1206. "APP_len=%d, COM_len=%d, "
  1207. "jpeg_markers=%d\n",
  1208. p->quality,p->APPn,p->APP_len,
  1209. p->COM_len,p->jpeg_markers);
  1210. break;
  1211. }
  1212. case VIDIOC_S_JPEGCOMP:
  1213. {
  1214. struct v4l2_jpegcompression *p=arg;
  1215. if (!vfd->vidioc_g_jpegcomp)
  1216. break;
  1217. dbgarg (cmd, "quality=%d, APPn=%d, APP_len=%d, "
  1218. "COM_len=%d, jpeg_markers=%d\n",
  1219. p->quality,p->APPn,p->APP_len,
  1220. p->COM_len,p->jpeg_markers);
  1221. ret=vfd->vidioc_s_jpegcomp(file, fh, p);
  1222. break;
  1223. }
  1224. case VIDIOC_G_PARM:
  1225. {
  1226. struct v4l2_streamparm *p=arg;
  1227. if (vfd->vidioc_g_parm) {
  1228. ret=vfd->vidioc_g_parm(file, fh, p);
  1229. } else {
  1230. struct v4l2_standard s;
  1231. if (p->type != V4L2_BUF_TYPE_VIDEO_CAPTURE)
  1232. return -EINVAL;
  1233. v4l2_video_std_construct(&s, vfd->current_norm,
  1234. v4l2_norm_to_name(vfd->current_norm));
  1235. memset(p,0,sizeof(*p));
  1236. p->parm.capture.timeperframe = s.frameperiod;
  1237. ret=0;
  1238. }
  1239. dbgarg (cmd, "type=%d\n", p->type);
  1240. break;
  1241. }
  1242. case VIDIOC_S_PARM:
  1243. {
  1244. struct v4l2_streamparm *p=arg;
  1245. if (!vfd->vidioc_s_parm)
  1246. break;
  1247. dbgarg (cmd, "type=%d\n", p->type);
  1248. ret=vfd->vidioc_s_parm(file, fh, p);
  1249. break;
  1250. }
  1251. case VIDIOC_G_TUNER:
  1252. {
  1253. struct v4l2_tuner *p=arg;
  1254. __u32 index=p->index;
  1255. if (!vfd->vidioc_g_tuner)
  1256. break;
  1257. memset(p,0,sizeof(*p));
  1258. p->index=index;
  1259. ret=vfd->vidioc_g_tuner(file, fh, p);
  1260. if (!ret)
  1261. dbgarg (cmd, "index=%d, name=%s, type=%d, "
  1262. "capability=%d, rangelow=%d, "
  1263. "rangehigh=%d, signal=%d, afc=%d, "
  1264. "rxsubchans=%d, audmode=%d\n",
  1265. p->index, p->name, p->type,
  1266. p->capability, p->rangelow,
  1267. p->rangehigh, p->rxsubchans,
  1268. p->audmode, p->signal, p->afc);
  1269. break;
  1270. }
  1271. case VIDIOC_S_TUNER:
  1272. {
  1273. struct v4l2_tuner *p=arg;
  1274. if (!vfd->vidioc_s_tuner)
  1275. break;
  1276. dbgarg (cmd, "index=%d, name=%s, type=%d, "
  1277. "capability=%d, rangelow=%d, rangehigh=%d, "
  1278. "signal=%d, afc=%d, rxsubchans=%d, "
  1279. "audmode=%d\n",p->index, p->name, p->type,
  1280. p->capability, p->rangelow,p->rangehigh,
  1281. p->rxsubchans, p->audmode, p->signal,
  1282. p->afc);
  1283. ret=vfd->vidioc_s_tuner(file, fh, p);
  1284. break;
  1285. }
  1286. case VIDIOC_G_FREQUENCY:
  1287. {
  1288. struct v4l2_frequency *p=arg;
  1289. if (!vfd->vidioc_g_frequency)
  1290. break;
  1291. memset(p,0,sizeof(*p));
  1292. ret=vfd->vidioc_g_frequency(file, fh, p);
  1293. if (!ret)
  1294. dbgarg (cmd, "tuner=%d, type=%d, frequency=%d\n",
  1295. p->tuner,p->type,p->frequency);
  1296. break;
  1297. }
  1298. case VIDIOC_S_FREQUENCY:
  1299. {
  1300. struct v4l2_frequency *p=arg;
  1301. if (!vfd->vidioc_s_frequency)
  1302. break;
  1303. dbgarg (cmd, "tuner=%d, type=%d, frequency=%d\n",
  1304. p->tuner,p->type,p->frequency);
  1305. ret=vfd->vidioc_s_frequency(file, fh, p);
  1306. break;
  1307. }
  1308. case VIDIOC_G_SLICED_VBI_CAP:
  1309. {
  1310. struct v4l2_sliced_vbi_cap *p=arg;
  1311. if (!vfd->vidioc_g_sliced_vbi_cap)
  1312. break;
  1313. ret=vfd->vidioc_g_sliced_vbi_cap(file, fh, p);
  1314. if (!ret)
  1315. dbgarg (cmd, "service_set=%d\n", p->service_set);
  1316. break;
  1317. }
  1318. case VIDIOC_LOG_STATUS:
  1319. {
  1320. if (!vfd->vidioc_log_status)
  1321. break;
  1322. ret=vfd->vidioc_log_status(file, fh);
  1323. break;
  1324. }
  1325. } /* switch */
  1326. if (vfd->debug & V4L2_DEBUG_IOCTL_ARG) {
  1327. if (ret<0) {
  1328. printk ("%s: err:\n", vfd->name);
  1329. v4l_print_ioctl(vfd->name, cmd);
  1330. }
  1331. }
  1332. return ret;
  1333. }
  1334. int video_ioctl2 (struct inode *inode, struct file *file,
  1335. unsigned int cmd, unsigned long arg)
  1336. {
  1337. char sbuf[128];
  1338. void *mbuf = NULL;
  1339. void *parg = NULL;
  1340. int err = -EINVAL;
  1341. int is_ext_ctrl;
  1342. size_t ctrls_size = 0;
  1343. void __user *user_ptr = NULL;
  1344. #ifdef __OLD_VIDIOC_
  1345. cmd = video_fix_command(cmd);
  1346. #endif
  1347. is_ext_ctrl = (cmd == VIDIOC_S_EXT_CTRLS || cmd == VIDIOC_G_EXT_CTRLS ||
  1348. cmd == VIDIOC_TRY_EXT_CTRLS);
  1349. /* Copy arguments into temp kernel buffer */
  1350. switch (_IOC_DIR(cmd)) {
  1351. case _IOC_NONE:
  1352. parg = NULL;
  1353. break;
  1354. case _IOC_READ:
  1355. case _IOC_WRITE:
  1356. case (_IOC_WRITE | _IOC_READ):
  1357. if (_IOC_SIZE(cmd) <= sizeof(sbuf)) {
  1358. parg = sbuf;
  1359. } else {
  1360. /* too big to allocate from stack */
  1361. mbuf = kmalloc(_IOC_SIZE(cmd),GFP_KERNEL);
  1362. if (NULL == mbuf)
  1363. return -ENOMEM;
  1364. parg = mbuf;
  1365. }
  1366. err = -EFAULT;
  1367. if (_IOC_DIR(cmd) & _IOC_WRITE)
  1368. if (copy_from_user(parg, (void __user *)arg, _IOC_SIZE(cmd)))
  1369. goto out;
  1370. break;
  1371. }
  1372. if (is_ext_ctrl) {
  1373. struct v4l2_ext_controls *p = parg;
  1374. /* In case of an error, tell the caller that it wasn't
  1375. a specific control that caused it. */
  1376. p->error_idx = p->count;
  1377. user_ptr = (void __user *)p->controls;
  1378. if (p->count) {
  1379. ctrls_size = sizeof(struct v4l2_ext_control) * p->count;
  1380. /* Note: v4l2_ext_controls fits in sbuf[] so mbuf is still NULL. */
  1381. mbuf = kmalloc(ctrls_size, GFP_KERNEL);
  1382. err = -ENOMEM;
  1383. if (NULL == mbuf)
  1384. goto out_ext_ctrl;
  1385. err = -EFAULT;
  1386. if (copy_from_user(mbuf, user_ptr, ctrls_size))
  1387. goto out_ext_ctrl;
  1388. p->controls = mbuf;
  1389. }
  1390. }
  1391. /* Handles IOCTL */
  1392. err = __video_do_ioctl(inode, file, cmd, parg);
  1393. if (err == -ENOIOCTLCMD)
  1394. err = -EINVAL;
  1395. if (is_ext_ctrl) {
  1396. struct v4l2_ext_controls *p = parg;
  1397. p->controls = (void *)user_ptr;
  1398. if (p->count && err == 0 && copy_to_user(user_ptr, mbuf, ctrls_size))
  1399. err = -EFAULT;
  1400. goto out_ext_ctrl;
  1401. }
  1402. if (err < 0)
  1403. goto out;
  1404. out_ext_ctrl:
  1405. /* Copy results into user buffer */
  1406. switch (_IOC_DIR(cmd))
  1407. {
  1408. case _IOC_READ:
  1409. case (_IOC_WRITE | _IOC_READ):
  1410. if (copy_to_user((void __user *)arg, parg, _IOC_SIZE(cmd)))
  1411. err = -EFAULT;
  1412. break;
  1413. }
  1414. out:
  1415. kfree(mbuf);
  1416. return err;
  1417. }
  1418. static struct file_operations video_fops;
  1419. /**
  1420. * video_register_device - register video4linux devices
  1421. * @vfd: video device structure we want to register
  1422. * @type: type of device to register
  1423. * @nr: which device number (0 == /dev/video0, 1 == /dev/video1, ...
  1424. * -1 == first free)
  1425. *
  1426. * The registration code assigns minor numbers based on the type
  1427. * requested. -ENFILE is returned in all the device slots for this
  1428. * category are full. If not then the minor field is set and the
  1429. * driver initialize function is called (if non %NULL).
  1430. *
  1431. * Zero is returned on success.
  1432. *
  1433. * Valid types are
  1434. *
  1435. * %VFL_TYPE_GRABBER - A frame grabber
  1436. *
  1437. * %VFL_TYPE_VTX - A teletext device
  1438. *
  1439. * %VFL_TYPE_VBI - Vertical blank data (undecoded)
  1440. *
  1441. * %VFL_TYPE_RADIO - A radio card
  1442. */
  1443. int video_register_device(struct video_device *vfd, int type, int nr)
  1444. {
  1445. int i=0;
  1446. int base;
  1447. int end;
  1448. int ret;
  1449. char *name_base;
  1450. switch(type)
  1451. {
  1452. case VFL_TYPE_GRABBER:
  1453. base=MINOR_VFL_TYPE_GRABBER_MIN;
  1454. end=MINOR_VFL_TYPE_GRABBER_MAX+1;
  1455. name_base = "video";
  1456. break;
  1457. case VFL_TYPE_VTX:
  1458. base=MINOR_VFL_TYPE_VTX_MIN;
  1459. end=MINOR_VFL_TYPE_VTX_MAX+1;
  1460. name_base = "vtx";
  1461. break;
  1462. case VFL_TYPE_VBI:
  1463. base=MINOR_VFL_TYPE_VBI_MIN;
  1464. end=MINOR_VFL_TYPE_VBI_MAX+1;
  1465. name_base = "vbi";
  1466. break;
  1467. case VFL_TYPE_RADIO:
  1468. base=MINOR_VFL_TYPE_RADIO_MIN;
  1469. end=MINOR_VFL_TYPE_RADIO_MAX+1;
  1470. name_base = "radio";
  1471. break;
  1472. default:
  1473. printk(KERN_ERR "%s called with unknown type: %d\n",
  1474. __FUNCTION__, type);
  1475. return -1;
  1476. }
  1477. /* pick a minor number */
  1478. mutex_lock(&videodev_lock);
  1479. if (nr >= 0 && nr < end-base) {
  1480. /* use the one the driver asked for */
  1481. i = base+nr;
  1482. if (NULL != video_device[i]) {
  1483. mutex_unlock(&videodev_lock);
  1484. return -ENFILE;
  1485. }
  1486. } else {
  1487. /* use first free */
  1488. for(i=base;i<end;i++)
  1489. if (NULL == video_device[i])
  1490. break;
  1491. if (i == end) {
  1492. mutex_unlock(&videodev_lock);
  1493. return -ENFILE;
  1494. }
  1495. }
  1496. video_device[i]=vfd;
  1497. vfd->minor=i;
  1498. mutex_unlock(&videodev_lock);
  1499. mutex_init(&vfd->lock);
  1500. /* sysfs class */
  1501. memset(&vfd->class_dev, 0x00, sizeof(vfd->class_dev));
  1502. if (vfd->dev)
  1503. vfd->class_dev.dev = vfd->dev;
  1504. vfd->class_dev.class = &video_class;
  1505. vfd->class_dev.devt = MKDEV(VIDEO_MAJOR, vfd->minor);
  1506. sprintf(vfd->class_dev.class_id, "%s%d", name_base, i - base);
  1507. ret = class_device_register(&vfd->class_dev);
  1508. if (ret < 0) {
  1509. printk(KERN_ERR "%s: class_device_register failed\n",
  1510. __FUNCTION__);
  1511. goto fail_minor;
  1512. }
  1513. ret = class_device_create_file(&vfd->class_dev, &class_device_attr_name);
  1514. if (ret < 0) {
  1515. printk(KERN_ERR "%s: class_device_create_file 'name' failed\n",
  1516. __FUNCTION__);
  1517. goto fail_classdev;
  1518. }
  1519. #if 1
  1520. /* needed until all drivers are fixed */
  1521. if (!vfd->release)
  1522. printk(KERN_WARNING "videodev: \"%s\" has no release callback. "
  1523. "Please fix your driver for proper sysfs support, see "
  1524. "http://lwn.net/Articles/36850/\n", vfd->name);
  1525. #endif
  1526. return 0;
  1527. fail_classdev:
  1528. class_device_unregister(&vfd->class_dev);
  1529. fail_minor:
  1530. mutex_lock(&videodev_lock);
  1531. video_device[vfd->minor] = NULL;
  1532. vfd->minor = -1;
  1533. mutex_unlock(&videodev_lock);
  1534. return ret;
  1535. }
  1536. /**
  1537. * video_unregister_device - unregister a video4linux device
  1538. * @vfd: the device to unregister
  1539. *
  1540. * This unregisters the passed device and deassigns the minor
  1541. * number. Future open calls will be met with errors.
  1542. */
  1543. void video_unregister_device(struct video_device *vfd)
  1544. {
  1545. mutex_lock(&videodev_lock);
  1546. if(video_device[vfd->minor]!=vfd)
  1547. panic("videodev: bad unregister");
  1548. video_device[vfd->minor]=NULL;
  1549. class_device_unregister(&vfd->class_dev);
  1550. mutex_unlock(&videodev_lock);
  1551. }
  1552. /*
  1553. * Video fs operations
  1554. */
  1555. static struct file_operations video_fops=
  1556. {
  1557. .owner = THIS_MODULE,
  1558. .llseek = no_llseek,
  1559. .open = video_open,
  1560. };
  1561. /*
  1562. * Initialise video for linux
  1563. */
  1564. static int __init videodev_init(void)
  1565. {
  1566. int ret;
  1567. printk(KERN_INFO "Linux video capture interface: v2.00\n");
  1568. if (register_chrdev(VIDEO_MAJOR, VIDEO_NAME, &video_fops)) {
  1569. printk(KERN_WARNING "video_dev: unable to get major %d\n", VIDEO_MAJOR);
  1570. return -EIO;
  1571. }
  1572. ret = class_register(&video_class);
  1573. if (ret < 0) {
  1574. unregister_chrdev(VIDEO_MAJOR, VIDEO_NAME);
  1575. printk(KERN_WARNING "video_dev: class_register failed\n");
  1576. return -EIO;
  1577. }
  1578. return 0;
  1579. }
  1580. static void __exit videodev_exit(void)
  1581. {
  1582. class_unregister(&video_class);
  1583. unregister_chrdev(VIDEO_MAJOR, VIDEO_NAME);
  1584. }
  1585. module_init(videodev_init)
  1586. module_exit(videodev_exit)
  1587. EXPORT_SYMBOL(video_register_device);
  1588. EXPORT_SYMBOL(video_unregister_device);
  1589. EXPORT_SYMBOL(video_devdata);
  1590. EXPORT_SYMBOL(video_usercopy);
  1591. EXPORT_SYMBOL(video_exclusive_open);
  1592. EXPORT_SYMBOL(video_exclusive_release);
  1593. EXPORT_SYMBOL(video_ioctl2);
  1594. EXPORT_SYMBOL(video_device_alloc);
  1595. EXPORT_SYMBOL(video_device_release);
  1596. MODULE_AUTHOR("Alan Cox, Mauro Carvalho Chehab <mchehab@infradead.org>");
  1597. MODULE_DESCRIPTION("Device registrar for Video4Linux drivers v2");
  1598. MODULE_LICENSE("GPL");
  1599. /*
  1600. * Local variables:
  1601. * c-basic-offset: 8
  1602. * End:
  1603. */