videodev.c 39 KB

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