videodev.c 39 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675
  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 <linux/devfs_fs_kernel.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_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\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);
  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=0x%08x, field=%s, "
  329. "bytesperline=%d sizeimage=%d, colorspace=%d\n",
  330. fmt->width,fmt->height,fmt->pixelformat,
  331. prt_names(fmt->field,v4l2_field_names_FIXME),
  332. fmt->bytesperline,fmt->sizeimage,fmt->colorspace);
  333. };
  334. static int check_fmt (struct video_device *vfd, enum v4l2_buf_type type)
  335. {
  336. switch (type) {
  337. case V4L2_BUF_TYPE_VIDEO_CAPTURE:
  338. if (vfd->vidioc_try_fmt_cap)
  339. return (0);
  340. break;
  341. case V4L2_BUF_TYPE_VIDEO_OVERLAY:
  342. if (vfd->vidioc_try_fmt_overlay)
  343. return (0);
  344. break;
  345. case V4L2_BUF_TYPE_VBI_CAPTURE:
  346. if (vfd->vidioc_try_fmt_vbi)
  347. return (0);
  348. break;
  349. case V4L2_BUF_TYPE_SLICED_VBI_OUTPUT:
  350. if (vfd->vidioc_try_fmt_vbi_output)
  351. return (0);
  352. break;
  353. case V4L2_BUF_TYPE_SLICED_VBI_CAPTURE:
  354. if (vfd->vidioc_try_fmt_vbi_capture)
  355. return (0);
  356. break;
  357. case V4L2_BUF_TYPE_VIDEO_OUTPUT:
  358. if (vfd->vidioc_try_fmt_video_output)
  359. return (0);
  360. break;
  361. case V4L2_BUF_TYPE_VBI_OUTPUT:
  362. if (vfd->vidioc_try_fmt_vbi_output)
  363. return (0);
  364. break;
  365. case V4L2_BUF_TYPE_PRIVATE:
  366. if (vfd->vidioc_try_fmt_type_private)
  367. return (0);
  368. break;
  369. }
  370. return (-EINVAL);
  371. }
  372. static int __video_do_ioctl(struct inode *inode, struct file *file,
  373. unsigned int cmd, void *arg)
  374. {
  375. struct video_device *vfd = video_devdata(file);
  376. void *fh = file->private_data;
  377. int ret = -EINVAL;
  378. if ( (vfd->debug & V4L2_DEBUG_IOCTL) &&
  379. !(vfd->debug | V4L2_DEBUG_IOCTL_ARG)) {
  380. v4l_print_ioctl(vfd->name, cmd);
  381. }
  382. switch(cmd) {
  383. /* --- capabilities ------------------------------------------ */
  384. case VIDIOC_QUERYCAP:
  385. {
  386. struct v4l2_capability *cap = (struct v4l2_capability*)arg;
  387. memset(cap, 0, sizeof(*cap));
  388. if (!vfd->vidioc_querycap)
  389. break;
  390. ret=vfd->vidioc_querycap(file, fh, cap);
  391. if (!ret)
  392. dbgarg (cmd, "driver=%s, card=%s, bus=%s, "
  393. "version=0x%08x, "
  394. "capabilities=0x%08x\n",
  395. cap->driver,cap->card,cap->bus_info,
  396. cap->version,
  397. cap->capabilities);
  398. break;
  399. }
  400. /* --- priority ------------------------------------------ */
  401. case VIDIOC_G_PRIORITY:
  402. {
  403. enum v4l2_priority *p=arg;
  404. if (!vfd->vidioc_g_priority)
  405. break;
  406. ret=vfd->vidioc_g_priority(file, fh, p);
  407. if (!ret)
  408. dbgarg(cmd, "priority is %d\n", *p);
  409. break;
  410. }
  411. case VIDIOC_S_PRIORITY:
  412. {
  413. enum v4l2_priority *p=arg;
  414. if (!vfd->vidioc_s_priority)
  415. break;
  416. dbgarg(cmd, "setting priority to %d\n", *p);
  417. ret=vfd->vidioc_s_priority(file, fh, *p);
  418. break;
  419. }
  420. /* --- capture ioctls ---------------------------------------- */
  421. case VIDIOC_ENUM_FMT:
  422. {
  423. struct v4l2_fmtdesc *f = arg;
  424. enum v4l2_buf_type type;
  425. unsigned int index;
  426. index = f->index;
  427. type = f->type;
  428. memset(f,0,sizeof(*f));
  429. f->index = index;
  430. f->type = type;
  431. switch (type) {
  432. case V4L2_BUF_TYPE_VIDEO_CAPTURE:
  433. if (vfd->vidioc_enum_fmt_cap)
  434. ret=vfd->vidioc_enum_fmt_cap(file, fh, f);
  435. break;
  436. case V4L2_BUF_TYPE_VIDEO_OVERLAY:
  437. if (vfd->vidioc_enum_fmt_overlay)
  438. ret=vfd->vidioc_enum_fmt_overlay(file, fh, f);
  439. break;
  440. case V4L2_BUF_TYPE_VBI_CAPTURE:
  441. if (vfd->vidioc_enum_fmt_vbi)
  442. ret=vfd->vidioc_enum_fmt_vbi(file, fh, f);
  443. break;
  444. case V4L2_BUF_TYPE_SLICED_VBI_OUTPUT:
  445. if (vfd->vidioc_enum_fmt_vbi_output)
  446. ret=vfd->vidioc_enum_fmt_vbi_output(file,
  447. fh, f);
  448. break;
  449. case V4L2_BUF_TYPE_SLICED_VBI_CAPTURE:
  450. if (vfd->vidioc_enum_fmt_vbi_capture)
  451. ret=vfd->vidioc_enum_fmt_vbi_capture(file,
  452. fh, f);
  453. break;
  454. case V4L2_BUF_TYPE_VIDEO_OUTPUT:
  455. if (vfd->vidioc_enum_fmt_video_output)
  456. ret=vfd->vidioc_enum_fmt_video_output(file,
  457. fh, f);
  458. break;
  459. case V4L2_BUF_TYPE_VBI_OUTPUT:
  460. if (vfd->vidioc_enum_fmt_vbi_output)
  461. ret=vfd->vidioc_enum_fmt_vbi_output(file,
  462. fh, f);
  463. break;
  464. case V4L2_BUF_TYPE_PRIVATE:
  465. if (vfd->vidioc_enum_fmt_type_private)
  466. ret=vfd->vidioc_enum_fmt_type_private(file,
  467. fh, f);
  468. break;
  469. }
  470. if (!ret)
  471. dbgarg (cmd, "index=%d, type=%d, flags=%d, "
  472. "description=%s,"
  473. " pixelformat=0x%8x\n",
  474. f->index, f->type, f->flags,
  475. f->description,
  476. f->pixelformat);
  477. break;
  478. }
  479. case VIDIOC_G_FMT:
  480. {
  481. struct v4l2_format *f = (struct v4l2_format *)arg;
  482. enum v4l2_buf_type type=f->type;
  483. memset(&f->fmt.pix,0,sizeof(f->fmt.pix));
  484. f->type=type;
  485. /* FIXME: Should be one dump per type */
  486. dbgarg (cmd, "type=%s\n", prt_names(type,
  487. v4l2_type_names_FIXME));
  488. switch (type) {
  489. case V4L2_BUF_TYPE_VIDEO_CAPTURE:
  490. if (vfd->vidioc_g_fmt_cap)
  491. ret=vfd->vidioc_g_fmt_cap(file, fh, f);
  492. if (!ret)
  493. v4l_print_pix_fmt(vfd,&f->fmt.pix);
  494. break;
  495. case V4L2_BUF_TYPE_VIDEO_OVERLAY:
  496. if (vfd->vidioc_g_fmt_overlay)
  497. ret=vfd->vidioc_g_fmt_overlay(file, fh, f);
  498. break;
  499. case V4L2_BUF_TYPE_VBI_CAPTURE:
  500. if (vfd->vidioc_g_fmt_vbi)
  501. ret=vfd->vidioc_g_fmt_vbi(file, fh, f);
  502. break;
  503. case V4L2_BUF_TYPE_SLICED_VBI_OUTPUT:
  504. if (vfd->vidioc_g_fmt_vbi_output)
  505. ret=vfd->vidioc_g_fmt_vbi_output(file, fh, f);
  506. break;
  507. case V4L2_BUF_TYPE_SLICED_VBI_CAPTURE:
  508. if (vfd->vidioc_g_fmt_vbi_capture)
  509. ret=vfd->vidioc_g_fmt_vbi_capture(file, fh, f);
  510. break;
  511. case V4L2_BUF_TYPE_VIDEO_OUTPUT:
  512. if (vfd->vidioc_g_fmt_video_output)
  513. ret=vfd->vidioc_g_fmt_video_output(file,
  514. fh, f);
  515. break;
  516. case V4L2_BUF_TYPE_VBI_OUTPUT:
  517. if (vfd->vidioc_g_fmt_vbi_output)
  518. ret=vfd->vidioc_g_fmt_vbi_output(file, fh, f);
  519. break;
  520. case V4L2_BUF_TYPE_PRIVATE:
  521. if (vfd->vidioc_g_fmt_type_private)
  522. ret=vfd->vidioc_g_fmt_type_private(file,
  523. fh, f);
  524. break;
  525. }
  526. break;
  527. }
  528. case VIDIOC_S_FMT:
  529. {
  530. struct v4l2_format *f = (struct v4l2_format *)arg;
  531. /* FIXME: Should be one dump per type */
  532. dbgarg (cmd, "type=%s\n", prt_names(f->type,
  533. v4l2_type_names_FIXME));
  534. switch (f->type) {
  535. case V4L2_BUF_TYPE_VIDEO_CAPTURE:
  536. v4l_print_pix_fmt(vfd,&f->fmt.pix);
  537. if (vfd->vidioc_s_fmt_cap)
  538. ret=vfd->vidioc_s_fmt_cap(file, fh, f);
  539. break;
  540. case V4L2_BUF_TYPE_VIDEO_OVERLAY:
  541. if (vfd->vidioc_s_fmt_overlay)
  542. ret=vfd->vidioc_s_fmt_overlay(file, fh, f);
  543. break;
  544. case V4L2_BUF_TYPE_VBI_CAPTURE:
  545. if (vfd->vidioc_s_fmt_vbi)
  546. ret=vfd->vidioc_s_fmt_vbi(file, fh, f);
  547. break;
  548. case V4L2_BUF_TYPE_SLICED_VBI_OUTPUT:
  549. if (vfd->vidioc_s_fmt_vbi_output)
  550. ret=vfd->vidioc_s_fmt_vbi_output(file, fh, f);
  551. break;
  552. case V4L2_BUF_TYPE_SLICED_VBI_CAPTURE:
  553. if (vfd->vidioc_s_fmt_vbi_capture)
  554. ret=vfd->vidioc_s_fmt_vbi_capture(file, fh, f);
  555. break;
  556. case V4L2_BUF_TYPE_VIDEO_OUTPUT:
  557. if (vfd->vidioc_s_fmt_video_output)
  558. ret=vfd->vidioc_s_fmt_video_output(file,
  559. fh, f);
  560. break;
  561. case V4L2_BUF_TYPE_VBI_OUTPUT:
  562. if (vfd->vidioc_s_fmt_vbi_output)
  563. ret=vfd->vidioc_s_fmt_vbi_output(file,
  564. fh, f);
  565. break;
  566. case V4L2_BUF_TYPE_PRIVATE:
  567. if (vfd->vidioc_s_fmt_type_private)
  568. ret=vfd->vidioc_s_fmt_type_private(file,
  569. fh, f);
  570. break;
  571. }
  572. break;
  573. }
  574. case VIDIOC_TRY_FMT:
  575. {
  576. struct v4l2_format *f = (struct v4l2_format *)arg;
  577. /* FIXME: Should be one dump per type */
  578. dbgarg (cmd, "type=%s\n", prt_names(f->type,
  579. v4l2_type_names_FIXME));
  580. switch (f->type) {
  581. case V4L2_BUF_TYPE_VIDEO_CAPTURE:
  582. if (vfd->vidioc_try_fmt_cap)
  583. ret=vfd->vidioc_try_fmt_cap(file, fh, f);
  584. if (!ret)
  585. v4l_print_pix_fmt(vfd,&f->fmt.pix);
  586. break;
  587. case V4L2_BUF_TYPE_VIDEO_OVERLAY:
  588. if (vfd->vidioc_try_fmt_overlay)
  589. ret=vfd->vidioc_try_fmt_overlay(file, fh, f);
  590. break;
  591. case V4L2_BUF_TYPE_VBI_CAPTURE:
  592. if (vfd->vidioc_try_fmt_vbi)
  593. ret=vfd->vidioc_try_fmt_vbi(file, fh, f);
  594. break;
  595. case V4L2_BUF_TYPE_SLICED_VBI_OUTPUT:
  596. if (vfd->vidioc_try_fmt_vbi_output)
  597. ret=vfd->vidioc_try_fmt_vbi_output(file,
  598. fh, f);
  599. break;
  600. case V4L2_BUF_TYPE_SLICED_VBI_CAPTURE:
  601. if (vfd->vidioc_try_fmt_vbi_capture)
  602. ret=vfd->vidioc_try_fmt_vbi_capture(file,
  603. fh, f);
  604. break;
  605. case V4L2_BUF_TYPE_VIDEO_OUTPUT:
  606. if (vfd->vidioc_try_fmt_video_output)
  607. ret=vfd->vidioc_try_fmt_video_output(file,
  608. fh, f);
  609. break;
  610. case V4L2_BUF_TYPE_VBI_OUTPUT:
  611. if (vfd->vidioc_try_fmt_vbi_output)
  612. ret=vfd->vidioc_try_fmt_vbi_output(file,
  613. fh, f);
  614. break;
  615. case V4L2_BUF_TYPE_PRIVATE:
  616. if (vfd->vidioc_try_fmt_type_private)
  617. ret=vfd->vidioc_try_fmt_type_private(file,
  618. fh, f);
  619. break;
  620. }
  621. break;
  622. }
  623. /* FIXME: Those buf reqs could be handled here,
  624. with some changes on videobuf to allow its header to be included at
  625. videodev2.h or being merged at videodev2.
  626. */
  627. case VIDIOC_REQBUFS:
  628. {
  629. struct v4l2_requestbuffers *p=arg;
  630. if (!vfd->vidioc_reqbufs)
  631. break;
  632. ret = check_fmt (vfd, p->type);
  633. if (ret)
  634. break;
  635. ret=vfd->vidioc_reqbufs(file, fh, p);
  636. dbgarg (cmd, "count=%d, type=%s, memory=%s\n",
  637. p->count,
  638. prt_names(p->type,v4l2_type_names_FIXME),
  639. prt_names(p->memory,v4l2_memory_names));
  640. break;
  641. }
  642. case VIDIOC_QUERYBUF:
  643. {
  644. struct v4l2_buffer *p=arg;
  645. if (!vfd->vidioc_querybuf)
  646. break;
  647. ret = check_fmt (vfd, p->type);
  648. if (ret)
  649. break;
  650. ret=vfd->vidioc_querybuf(file, fh, p);
  651. if (!ret)
  652. dbgbuf(cmd,vfd,p);
  653. break;
  654. }
  655. case VIDIOC_QBUF:
  656. {
  657. struct v4l2_buffer *p=arg;
  658. if (!vfd->vidioc_qbuf)
  659. break;
  660. ret = check_fmt (vfd, p->type);
  661. if (ret)
  662. break;
  663. ret=vfd->vidioc_qbuf(file, fh, p);
  664. if (!ret)
  665. dbgbuf(cmd,vfd,p);
  666. break;
  667. }
  668. case VIDIOC_DQBUF:
  669. {
  670. struct v4l2_buffer *p=arg;
  671. if (!vfd->vidioc_qbuf)
  672. break;
  673. ret = check_fmt (vfd, p->type);
  674. if (ret)
  675. break;
  676. ret=vfd->vidioc_qbuf(file, fh, p);
  677. if (!ret)
  678. dbgbuf(cmd,vfd,p);
  679. break;
  680. }
  681. case VIDIOC_OVERLAY:
  682. {
  683. int *i = arg;
  684. if (!vfd->vidioc_overlay)
  685. break;
  686. dbgarg (cmd, "value=%d\n",*i);
  687. ret=vfd->vidioc_overlay(file, fh, *i);
  688. break;
  689. }
  690. #ifdef HAVE_V4L1
  691. /* --- streaming capture ------------------------------------- */
  692. case VIDIOCGMBUF:
  693. {
  694. struct video_mbuf *p=arg;
  695. memset(p,0,sizeof(p));
  696. if (!vfd->vidiocgmbuf)
  697. break;
  698. ret=vfd->vidiocgmbuf(file, fh, p);
  699. if (!ret)
  700. dbgarg (cmd, "size=%d, frames=%d, offsets=0x%08lx\n",
  701. p->size, p->frames,
  702. (unsigned long)p->offsets);
  703. break;
  704. }
  705. #endif
  706. case VIDIOC_G_FBUF:
  707. {
  708. struct v4l2_framebuffer *p=arg;
  709. if (!vfd->vidioc_g_fbuf)
  710. break;
  711. ret=vfd->vidioc_g_fbuf(file, fh, arg);
  712. if (!ret) {
  713. dbgarg (cmd, "capability=%d, flags=%d, base=0x%08lx\n",
  714. p->capability,p->flags,
  715. (unsigned long)p->base);
  716. v4l_print_pix_fmt (vfd, &p->fmt);
  717. }
  718. break;
  719. }
  720. case VIDIOC_S_FBUF:
  721. {
  722. struct v4l2_framebuffer *p=arg;
  723. if (!vfd->vidioc_s_fbuf)
  724. break;
  725. dbgarg (cmd, "capability=%d, flags=%d, base=0x%08lx\n",
  726. p->capability,p->flags,(unsigned long)p->base);
  727. v4l_print_pix_fmt (vfd, &p->fmt);
  728. ret=vfd->vidioc_s_fbuf(file, fh, arg);
  729. break;
  730. }
  731. case VIDIOC_STREAMON:
  732. {
  733. enum v4l2_buf_type i = *(int *)arg;
  734. if (!vfd->vidioc_streamon)
  735. break;
  736. dbgarg (cmd, "type=%s\n", prt_names(i,v4l2_type_names_FIXME));
  737. ret=vfd->vidioc_streamon(file, fh,i);
  738. break;
  739. }
  740. case VIDIOC_STREAMOFF:
  741. {
  742. enum v4l2_buf_type i = *(int *)arg;
  743. if (!vfd->vidioc_streamoff)
  744. break;
  745. dbgarg (cmd, "type=%s\n", prt_names(i,v4l2_type_names_FIXME));
  746. ret=vfd->vidioc_streamoff(file, fh, i);
  747. break;
  748. }
  749. /* ---------- tv norms ---------- */
  750. case VIDIOC_ENUMSTD:
  751. {
  752. struct v4l2_standard *p = arg;
  753. unsigned int index = p->index;
  754. if (!vfd->tvnormsize) {
  755. printk (KERN_WARNING "%s: no TV norms defined!\n",
  756. vfd->name);
  757. break;
  758. }
  759. if (index<=0 || index >= vfd->tvnormsize) {
  760. ret=-EINVAL;
  761. break;
  762. }
  763. v4l2_video_std_construct(p, vfd->tvnorms[p->index].id,
  764. vfd->tvnorms[p->index].name);
  765. p->index = index;
  766. dbgarg (cmd, "index=%d, id=%Ld, name=%s, fps=%d/%d, "
  767. "framelines=%d\n", p->index,
  768. (unsigned long long)p->id, p->name,
  769. p->frameperiod.numerator,
  770. p->frameperiod.denominator,
  771. p->framelines);
  772. ret=0;
  773. break;
  774. }
  775. case VIDIOC_G_STD:
  776. {
  777. v4l2_std_id *id = arg;
  778. *id = vfd->current_norm;
  779. dbgarg (cmd, "value=%Lu\n", (long long unsigned) *id);
  780. ret=0;
  781. break;
  782. }
  783. case VIDIOC_S_STD:
  784. {
  785. v4l2_std_id *id = arg;
  786. unsigned int i;
  787. if (!vfd->tvnormsize) {
  788. printk (KERN_WARNING "%s: no TV norms defined!\n",
  789. vfd->name);
  790. break;
  791. }
  792. dbgarg (cmd, "value=%Lu\n", (long long unsigned) *id);
  793. /* First search for exact match */
  794. for (i = 0; i < vfd->tvnormsize; i++)
  795. if (*id == vfd->tvnorms[i].id)
  796. break;
  797. /* Then for a generic video std that contains desired std */
  798. if (i == vfd->tvnormsize)
  799. for (i = 0; i < vfd->tvnormsize; i++)
  800. if (*id & vfd->tvnorms[i].id)
  801. break;
  802. if (i == vfd->tvnormsize) {
  803. break;
  804. }
  805. /* Calls the specific handler */
  806. if (vfd->vidioc_s_std)
  807. ret=vfd->vidioc_s_std(file, fh, i);
  808. else
  809. ret=-EINVAL;
  810. /* Updates standard information */
  811. if (!ret)
  812. vfd->current_norm=*id;
  813. break;
  814. }
  815. case VIDIOC_QUERYSTD:
  816. {
  817. v4l2_std_id *p=arg;
  818. if (!vfd->vidioc_querystd)
  819. break;
  820. ret=vfd->vidioc_querystd(file, fh, arg);
  821. if (!ret)
  822. dbgarg (cmd, "detected std=%Lu\n",
  823. (unsigned long long)*p);
  824. break;
  825. }
  826. /* ------ input switching ---------- */
  827. /* FIXME: Inputs can be handled inside videodev2 */
  828. case VIDIOC_ENUMINPUT:
  829. {
  830. struct v4l2_input *p=arg;
  831. int i=p->index;
  832. if (!vfd->vidioc_enum_input)
  833. break;
  834. memset(p, 0, sizeof(*p));
  835. p->index=i;
  836. ret=vfd->vidioc_enum_input(file, fh, p);
  837. if (!ret)
  838. dbgarg (cmd, "index=%d, name=%s, type=%d, "
  839. "audioset=%d, "
  840. "tuner=%d, std=%Ld, status=%d\n",
  841. p->index,p->name,p->type,p->audioset,
  842. p->tuner,
  843. (unsigned long long)p->std,
  844. p->status);
  845. break;
  846. }
  847. case VIDIOC_G_INPUT:
  848. {
  849. unsigned int *i = arg;
  850. if (!vfd->vidioc_g_input)
  851. break;
  852. ret=vfd->vidioc_g_input(file, fh, i);
  853. if (!ret)
  854. dbgarg (cmd, "value=%d\n",*i);
  855. break;
  856. }
  857. case VIDIOC_S_INPUT:
  858. {
  859. unsigned int *i = arg;
  860. if (!vfd->vidioc_s_input)
  861. break;
  862. dbgarg (cmd, "value=%d\n",*i);
  863. ret=vfd->vidioc_s_input(file, fh, *i);
  864. break;
  865. }
  866. /* ------ output switching ---------- */
  867. case VIDIOC_G_OUTPUT:
  868. {
  869. unsigned int *i = arg;
  870. if (!vfd->vidioc_g_output)
  871. break;
  872. ret=vfd->vidioc_g_output(file, fh, i);
  873. if (!ret)
  874. dbgarg (cmd, "value=%d\n",*i);
  875. break;
  876. }
  877. case VIDIOC_S_OUTPUT:
  878. {
  879. unsigned int *i = arg;
  880. if (!vfd->vidioc_s_output)
  881. break;
  882. dbgarg (cmd, "value=%d\n",*i);
  883. ret=vfd->vidioc_s_output(file, fh, *i);
  884. break;
  885. }
  886. /* --- controls ---------------------------------------------- */
  887. case VIDIOC_QUERYCTRL:
  888. {
  889. struct v4l2_queryctrl *p=arg;
  890. if (!vfd->vidioc_queryctrl)
  891. break;
  892. ret=vfd->vidioc_queryctrl(file, fh, p);
  893. if (!ret)
  894. dbgarg (cmd, "id=%d, type=%d, name=%s, "
  895. "min/max=%d/%d,"
  896. " step=%d, default=%d, flags=0x%08x\n",
  897. p->id,p->type,p->name,p->minimum,
  898. p->maximum,p->step,p->default_value,
  899. p->flags);
  900. break;
  901. }
  902. case VIDIOC_G_CTRL:
  903. {
  904. struct v4l2_control *p = arg;
  905. if (!vfd->vidioc_g_ctrl)
  906. break;
  907. dbgarg(cmd, "Enum for index=%d\n", p->id);
  908. ret=vfd->vidioc_g_ctrl(file, fh, p);
  909. if (!ret)
  910. dbgarg2 ( "id=%d, value=%d\n", p->id, p->value);
  911. break;
  912. }
  913. case VIDIOC_S_CTRL:
  914. {
  915. struct v4l2_control *p = arg;
  916. if (!vfd->vidioc_s_ctrl)
  917. break;
  918. dbgarg (cmd, "id=%d, value=%d\n", p->id, p->value);
  919. ret=vfd->vidioc_s_ctrl(file, fh, p);
  920. break;
  921. }
  922. case VIDIOC_G_EXT_CTRLS:
  923. {
  924. struct v4l2_ext_controls *p = arg;
  925. if (vfd->vidioc_g_ext_ctrls) {
  926. dbgarg(cmd, "count=%d\n", p->count);
  927. ret=vfd->vidioc_g_ext_ctrls(file, fh, p);
  928. }
  929. break;
  930. }
  931. case VIDIOC_S_EXT_CTRLS:
  932. {
  933. struct v4l2_ext_controls *p = arg;
  934. if (vfd->vidioc_s_ext_ctrls) {
  935. dbgarg(cmd, "count=%d\n", p->count);
  936. ret=vfd->vidioc_s_ext_ctrls(file, fh, p);
  937. }
  938. break;
  939. }
  940. case VIDIOC_TRY_EXT_CTRLS:
  941. {
  942. struct v4l2_ext_controls *p = arg;
  943. if (vfd->vidioc_try_ext_ctrls) {
  944. dbgarg(cmd, "count=%d\n", p->count);
  945. ret=vfd->vidioc_try_ext_ctrls(file, fh, p);
  946. }
  947. break;
  948. }
  949. case VIDIOC_QUERYMENU:
  950. {
  951. struct v4l2_querymenu *p=arg;
  952. if (!vfd->vidioc_querymenu)
  953. break;
  954. ret=vfd->vidioc_querymenu(file, fh, p);
  955. if (!ret)
  956. dbgarg (cmd, "id=%d, index=%d, name=%s\n",
  957. p->id,p->index,p->name);
  958. break;
  959. }
  960. /* --- audio ---------------------------------------------- */
  961. case VIDIOC_ENUMAUDIO:
  962. {
  963. struct v4l2_audio *p=arg;
  964. if (!vfd->vidioc_enumaudio)
  965. break;
  966. dbgarg(cmd, "Enum for index=%d\n", p->index);
  967. ret=vfd->vidioc_enumaudio(file, fh, p);
  968. if (!ret)
  969. dbgarg2("index=%d, name=%s, capability=%d, "
  970. "mode=%d\n",p->index,p->name,
  971. p->capability, p->mode);
  972. break;
  973. }
  974. case VIDIOC_G_AUDIO:
  975. {
  976. struct v4l2_audio *p=arg;
  977. if (!vfd->vidioc_g_audio)
  978. break;
  979. dbgarg(cmd, "Get for index=%d\n", p->index);
  980. ret=vfd->vidioc_g_audio(file, fh, p);
  981. if (!ret)
  982. dbgarg2("index=%d, name=%s, capability=%d, "
  983. "mode=%d\n",p->index,
  984. p->name,p->capability, p->mode);
  985. break;
  986. }
  987. case VIDIOC_S_AUDIO:
  988. {
  989. struct v4l2_audio *p=arg;
  990. if (!vfd->vidioc_s_audio)
  991. break;
  992. dbgarg(cmd, "index=%d, name=%s, capability=%d, "
  993. "mode=%d\n", p->index, p->name,
  994. p->capability, p->mode);
  995. ret=vfd->vidioc_s_audio(file, fh, p);
  996. break;
  997. }
  998. case VIDIOC_ENUMAUDOUT:
  999. {
  1000. struct v4l2_audioout *p=arg;
  1001. if (!vfd->vidioc_enumaudout)
  1002. break;
  1003. dbgarg(cmd, "Enum for index=%d\n", p->index);
  1004. ret=vfd->vidioc_enumaudout(file, fh, p);
  1005. if (!ret)
  1006. dbgarg2("index=%d, name=%s, capability=%d, "
  1007. "mode=%d\n", p->index, p->name,
  1008. p->capability,p->mode);
  1009. break;
  1010. }
  1011. case VIDIOC_G_AUDOUT:
  1012. {
  1013. struct v4l2_audioout *p=arg;
  1014. if (!vfd->vidioc_g_audout)
  1015. break;
  1016. dbgarg(cmd, "Enum for index=%d\n", p->index);
  1017. ret=vfd->vidioc_g_audout(file, fh, p);
  1018. if (!ret)
  1019. dbgarg2("index=%d, name=%s, capability=%d, "
  1020. "mode=%d\n", p->index, p->name,
  1021. p->capability,p->mode);
  1022. break;
  1023. }
  1024. case VIDIOC_S_AUDOUT:
  1025. {
  1026. struct v4l2_audioout *p=arg;
  1027. if (!vfd->vidioc_s_audout)
  1028. break;
  1029. dbgarg(cmd, "index=%d, name=%s, capability=%d, "
  1030. "mode=%d\n", p->index, p->name,
  1031. p->capability,p->mode);
  1032. ret=vfd->vidioc_s_audout(file, fh, p);
  1033. break;
  1034. }
  1035. case VIDIOC_G_MODULATOR:
  1036. {
  1037. struct v4l2_modulator *p=arg;
  1038. if (!vfd->vidioc_g_modulator)
  1039. break;
  1040. ret=vfd->vidioc_g_modulator(file, fh, p);
  1041. if (!ret)
  1042. dbgarg(cmd, "index=%d, name=%s, "
  1043. "capability=%d, rangelow=%d,"
  1044. " rangehigh=%d, txsubchans=%d\n",
  1045. p->index, p->name,p->capability,
  1046. p->rangelow, p->rangehigh,
  1047. p->txsubchans);
  1048. break;
  1049. }
  1050. case VIDIOC_S_MODULATOR:
  1051. {
  1052. struct v4l2_modulator *p=arg;
  1053. if (!vfd->vidioc_s_modulator)
  1054. break;
  1055. dbgarg(cmd, "index=%d, name=%s, capability=%d, "
  1056. "rangelow=%d, rangehigh=%d, txsubchans=%d\n",
  1057. p->index, p->name,p->capability,p->rangelow,
  1058. p->rangehigh,p->txsubchans);
  1059. ret=vfd->vidioc_s_modulator(file, fh, p);
  1060. break;
  1061. }
  1062. case VIDIOC_G_CROP:
  1063. {
  1064. struct v4l2_crop *p=arg;
  1065. if (!vfd->vidioc_g_crop)
  1066. break;
  1067. ret=vfd->vidioc_g_crop(file, fh, p);
  1068. if (!ret) {
  1069. dbgarg(cmd, "type=%d\n", p->type);
  1070. dbgrect(vfd, "", &p->c);
  1071. }
  1072. break;
  1073. }
  1074. case VIDIOC_S_CROP:
  1075. {
  1076. struct v4l2_crop *p=arg;
  1077. if (!vfd->vidioc_s_crop)
  1078. break;
  1079. dbgarg(cmd, "type=%d\n", p->type);
  1080. dbgrect(vfd, "", &p->c);
  1081. ret=vfd->vidioc_s_crop(file, fh, p);
  1082. break;
  1083. }
  1084. case VIDIOC_CROPCAP:
  1085. {
  1086. struct v4l2_cropcap *p=arg;
  1087. /*FIXME: Should also show v4l2_fract pixelaspect */
  1088. if (!vfd->vidioc_cropcap)
  1089. break;
  1090. dbgarg(cmd, "type=%d\n", p->type);
  1091. dbgrect(vfd, "bounds ", &p->bounds);
  1092. dbgrect(vfd, "defrect ", &p->defrect);
  1093. ret=vfd->vidioc_cropcap(file, fh, p);
  1094. break;
  1095. }
  1096. case VIDIOC_G_MPEGCOMP:
  1097. {
  1098. struct v4l2_mpeg_compression *p=arg;
  1099. /*FIXME: Several fields not shown */
  1100. if (!vfd->vidioc_g_mpegcomp)
  1101. break;
  1102. ret=vfd->vidioc_g_mpegcomp(file, fh, p);
  1103. if (!ret)
  1104. dbgarg (cmd, "ts_pid_pmt=%d, ts_pid_audio=%d,"
  1105. " ts_pid_video=%d, ts_pid_pcr=%d, "
  1106. "ps_size=%d, au_sample_rate=%d, "
  1107. "au_pesid=%c, vi_frame_rate=%d, "
  1108. "vi_frames_per_gop=%d, "
  1109. "vi_bframes_count=%d, vi_pesid=%c\n",
  1110. p->ts_pid_pmt,p->ts_pid_audio,
  1111. p->ts_pid_video,p->ts_pid_pcr,
  1112. p->ps_size, p->au_sample_rate,
  1113. p->au_pesid, p->vi_frame_rate,
  1114. p->vi_frames_per_gop,
  1115. p->vi_bframes_count, p->vi_pesid);
  1116. break;
  1117. }
  1118. case VIDIOC_S_MPEGCOMP:
  1119. {
  1120. struct v4l2_mpeg_compression *p=arg;
  1121. /*FIXME: Several fields not shown */
  1122. if (!vfd->vidioc_s_mpegcomp)
  1123. break;
  1124. dbgarg (cmd, "ts_pid_pmt=%d, ts_pid_audio=%d, "
  1125. "ts_pid_video=%d, ts_pid_pcr=%d, ps_size=%d, "
  1126. "au_sample_rate=%d, au_pesid=%c, "
  1127. "vi_frame_rate=%d, vi_frames_per_gop=%d, "
  1128. "vi_bframes_count=%d, vi_pesid=%c\n",
  1129. p->ts_pid_pmt,p->ts_pid_audio, p->ts_pid_video,
  1130. p->ts_pid_pcr, p->ps_size, p->au_sample_rate,
  1131. p->au_pesid, p->vi_frame_rate,
  1132. p->vi_frames_per_gop, p->vi_bframes_count,
  1133. p->vi_pesid);
  1134. ret=vfd->vidioc_s_mpegcomp(file, fh, p);
  1135. break;
  1136. }
  1137. case VIDIOC_G_JPEGCOMP:
  1138. {
  1139. struct v4l2_jpegcompression *p=arg;
  1140. if (!vfd->vidioc_g_jpegcomp)
  1141. break;
  1142. ret=vfd->vidioc_g_jpegcomp(file, fh, p);
  1143. if (!ret)
  1144. dbgarg (cmd, "quality=%d, APPn=%d, "
  1145. "APP_len=%d, COM_len=%d, "
  1146. "jpeg_markers=%d\n",
  1147. p->quality,p->APPn,p->APP_len,
  1148. p->COM_len,p->jpeg_markers);
  1149. break;
  1150. }
  1151. case VIDIOC_S_JPEGCOMP:
  1152. {
  1153. struct v4l2_jpegcompression *p=arg;
  1154. if (!vfd->vidioc_g_jpegcomp)
  1155. break;
  1156. dbgarg (cmd, "quality=%d, APPn=%d, APP_len=%d, "
  1157. "COM_len=%d, jpeg_markers=%d\n",
  1158. p->quality,p->APPn,p->APP_len,
  1159. p->COM_len,p->jpeg_markers);
  1160. ret=vfd->vidioc_s_jpegcomp(file, fh, p);
  1161. break;
  1162. }
  1163. case VIDIOC_G_PARM:
  1164. {
  1165. struct v4l2_streamparm *p=arg;
  1166. if (!vfd->vidioc_g_parm)
  1167. break;
  1168. ret=vfd->vidioc_g_parm(file, fh, p);
  1169. dbgarg (cmd, "type=%d\n", p->type);
  1170. break;
  1171. }
  1172. case VIDIOC_S_PARM:
  1173. {
  1174. struct v4l2_streamparm *p=arg;
  1175. if (!vfd->vidioc_s_parm)
  1176. break;
  1177. dbgarg (cmd, "type=%d\n", p->type);
  1178. ret=vfd->vidioc_s_parm(file, fh, p);
  1179. break;
  1180. }
  1181. case VIDIOC_G_TUNER:
  1182. {
  1183. struct v4l2_tuner *p=arg;
  1184. if (!vfd->vidioc_g_tuner)
  1185. break;
  1186. ret=vfd->vidioc_g_tuner(file, fh, p);
  1187. if (!ret)
  1188. dbgarg (cmd, "index=%d, name=%s, type=%d, "
  1189. "capability=%d, rangelow=%d, "
  1190. "rangehigh=%d, signal=%d, afc=%d, "
  1191. "rxsubchans=%d, audmode=%d\n",
  1192. p->index, p->name, p->type,
  1193. p->capability, p->rangelow,
  1194. p->rangehigh, p->rxsubchans,
  1195. p->audmode, p->signal, p->afc);
  1196. break;
  1197. }
  1198. case VIDIOC_S_TUNER:
  1199. {
  1200. struct v4l2_tuner *p=arg;
  1201. if (!vfd->vidioc_s_tuner)
  1202. break;
  1203. dbgarg (cmd, "index=%d, name=%s, type=%d, "
  1204. "capability=%d, rangelow=%d, rangehigh=%d, "
  1205. "signal=%d, afc=%d, rxsubchans=%d, "
  1206. "audmode=%d\n",p->index, p->name, p->type,
  1207. p->capability, p->rangelow,p->rangehigh,
  1208. p->rxsubchans, p->audmode, p->signal,
  1209. p->afc);
  1210. ret=vfd->vidioc_s_tuner(file, fh, p);
  1211. break;
  1212. }
  1213. case VIDIOC_G_FREQUENCY:
  1214. {
  1215. struct v4l2_frequency *p=arg;
  1216. if (!vfd->vidioc_g_frequency)
  1217. break;
  1218. ret=vfd->vidioc_g_frequency(file, fh, p);
  1219. if (!ret)
  1220. dbgarg (cmd, "tuner=%d, type=%d, frequency=%d\n",
  1221. p->tuner,p->type,p->frequency);
  1222. break;
  1223. }
  1224. case VIDIOC_S_FREQUENCY:
  1225. {
  1226. struct v4l2_frequency *p=arg;
  1227. if (!vfd->vidioc_s_frequency)
  1228. break;
  1229. dbgarg (cmd, "tuner=%d, type=%d, frequency=%d\n",
  1230. p->tuner,p->type,p->frequency);
  1231. ret=vfd->vidioc_s_frequency(file, fh, p);
  1232. break;
  1233. }
  1234. case VIDIOC_G_SLICED_VBI_CAP:
  1235. {
  1236. struct v4l2_sliced_vbi_cap *p=arg;
  1237. if (!vfd->vidioc_g_sliced_vbi_cap)
  1238. break;
  1239. ret=vfd->vidioc_g_sliced_vbi_cap(file, fh, p);
  1240. if (!ret)
  1241. dbgarg (cmd, "service_set=%d\n", p->service_set);
  1242. break;
  1243. }
  1244. case VIDIOC_LOG_STATUS:
  1245. {
  1246. if (!vfd->vidioc_log_status)
  1247. break;
  1248. ret=vfd->vidioc_log_status(file, fh);
  1249. break;
  1250. }
  1251. /* --- Others --------------------------------------------- */
  1252. default:
  1253. ret=v4l_compat_translate_ioctl(inode,file,cmd,arg,__video_do_ioctl);
  1254. }
  1255. if (vfd->debug & V4L2_DEBUG_IOCTL_ARG) {
  1256. if (ret<0) {
  1257. printk ("%s: err:\n", vfd->name);
  1258. v4l_print_ioctl(vfd->name, cmd);
  1259. }
  1260. }
  1261. return ret;
  1262. }
  1263. int video_ioctl2 (struct inode *inode, struct file *file,
  1264. unsigned int cmd, unsigned long arg)
  1265. {
  1266. char sbuf[128];
  1267. void *mbuf = NULL;
  1268. void *parg = NULL;
  1269. int err = -EINVAL;
  1270. int is_ext_ctrl;
  1271. size_t ctrls_size = 0;
  1272. void __user *user_ptr = NULL;
  1273. #ifdef __OLD_VIDIOC_
  1274. cmd = video_fix_command(cmd);
  1275. #endif
  1276. is_ext_ctrl = (cmd == VIDIOC_S_EXT_CTRLS || cmd == VIDIOC_G_EXT_CTRLS ||
  1277. cmd == VIDIOC_TRY_EXT_CTRLS);
  1278. /* Copy arguments into temp kernel buffer */
  1279. switch (_IOC_DIR(cmd)) {
  1280. case _IOC_NONE:
  1281. parg = NULL;
  1282. break;
  1283. case _IOC_READ:
  1284. case _IOC_WRITE:
  1285. case (_IOC_WRITE | _IOC_READ):
  1286. if (_IOC_SIZE(cmd) <= sizeof(sbuf)) {
  1287. parg = sbuf;
  1288. } else {
  1289. /* too big to allocate from stack */
  1290. mbuf = kmalloc(_IOC_SIZE(cmd),GFP_KERNEL);
  1291. if (NULL == mbuf)
  1292. return -ENOMEM;
  1293. parg = mbuf;
  1294. }
  1295. err = -EFAULT;
  1296. if (_IOC_DIR(cmd) & _IOC_WRITE)
  1297. if (copy_from_user(parg, (void __user *)arg, _IOC_SIZE(cmd)))
  1298. goto out;
  1299. break;
  1300. }
  1301. if (is_ext_ctrl) {
  1302. struct v4l2_ext_controls *p = parg;
  1303. /* In case of an error, tell the caller that it wasn't
  1304. a specific control that caused it. */
  1305. p->error_idx = p->count;
  1306. user_ptr = (void __user *)p->controls;
  1307. if (p->count) {
  1308. ctrls_size = sizeof(struct v4l2_ext_control) * p->count;
  1309. /* Note: v4l2_ext_controls fits in sbuf[] so mbuf is still NULL. */
  1310. mbuf = kmalloc(ctrls_size, GFP_KERNEL);
  1311. err = -ENOMEM;
  1312. if (NULL == mbuf)
  1313. goto out_ext_ctrl;
  1314. err = -EFAULT;
  1315. if (copy_from_user(mbuf, user_ptr, ctrls_size))
  1316. goto out_ext_ctrl;
  1317. p->controls = mbuf;
  1318. }
  1319. }
  1320. /* Handles IOCTL */
  1321. err = __video_do_ioctl(inode, file, cmd, parg);
  1322. if (err == -ENOIOCTLCMD)
  1323. err = -EINVAL;
  1324. if (is_ext_ctrl) {
  1325. struct v4l2_ext_controls *p = parg;
  1326. p->controls = (void *)user_ptr;
  1327. if (p->count && err == 0 && copy_to_user(user_ptr, mbuf, ctrls_size))
  1328. err = -EFAULT;
  1329. goto out_ext_ctrl;
  1330. }
  1331. if (err < 0)
  1332. goto out;
  1333. out_ext_ctrl:
  1334. /* Copy results into user buffer */
  1335. switch (_IOC_DIR(cmd))
  1336. {
  1337. case _IOC_READ:
  1338. case (_IOC_WRITE | _IOC_READ):
  1339. if (copy_to_user((void __user *)arg, parg, _IOC_SIZE(cmd)))
  1340. err = -EFAULT;
  1341. break;
  1342. }
  1343. out:
  1344. kfree(mbuf);
  1345. return err;
  1346. }
  1347. static struct file_operations video_fops;
  1348. /**
  1349. * video_register_device - register video4linux devices
  1350. * @vfd: video device structure we want to register
  1351. * @type: type of device to register
  1352. * @nr: which device number (0 == /dev/video0, 1 == /dev/video1, ...
  1353. * -1 == first free)
  1354. *
  1355. * The registration code assigns minor numbers based on the type
  1356. * requested. -ENFILE is returned in all the device slots for this
  1357. * category are full. If not then the minor field is set and the
  1358. * driver initialize function is called (if non %NULL).
  1359. *
  1360. * Zero is returned on success.
  1361. *
  1362. * Valid types are
  1363. *
  1364. * %VFL_TYPE_GRABBER - A frame grabber
  1365. *
  1366. * %VFL_TYPE_VTX - A teletext device
  1367. *
  1368. * %VFL_TYPE_VBI - Vertical blank data (undecoded)
  1369. *
  1370. * %VFL_TYPE_RADIO - A radio card
  1371. */
  1372. int video_register_device(struct video_device *vfd, int type, int nr)
  1373. {
  1374. int i=0;
  1375. int base;
  1376. int end;
  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. return -1;
  1402. }
  1403. /* pick a minor number */
  1404. mutex_lock(&videodev_lock);
  1405. if (nr >= 0 && nr < end-base) {
  1406. /* use the one the driver asked for */
  1407. i = base+nr;
  1408. if (NULL != video_device[i]) {
  1409. mutex_unlock(&videodev_lock);
  1410. return -ENFILE;
  1411. }
  1412. } else {
  1413. /* use first free */
  1414. for(i=base;i<end;i++)
  1415. if (NULL == video_device[i])
  1416. break;
  1417. if (i == end) {
  1418. mutex_unlock(&videodev_lock);
  1419. return -ENFILE;
  1420. }
  1421. }
  1422. video_device[i]=vfd;
  1423. vfd->minor=i;
  1424. mutex_unlock(&videodev_lock);
  1425. sprintf(vfd->devfs_name, "v4l/%s%d", name_base, i - base);
  1426. devfs_mk_cdev(MKDEV(VIDEO_MAJOR, vfd->minor),
  1427. S_IFCHR | S_IRUSR | S_IWUSR, vfd->devfs_name);
  1428. mutex_init(&vfd->lock);
  1429. /* sysfs class */
  1430. memset(&vfd->class_dev, 0x00, sizeof(vfd->class_dev));
  1431. if (vfd->dev)
  1432. vfd->class_dev.dev = vfd->dev;
  1433. vfd->class_dev.class = &video_class;
  1434. vfd->class_dev.devt = MKDEV(VIDEO_MAJOR, vfd->minor);
  1435. strlcpy(vfd->class_dev.class_id, vfd->devfs_name + 4, BUS_ID_SIZE);
  1436. class_device_register(&vfd->class_dev);
  1437. class_device_create_file(&vfd->class_dev,
  1438. &class_device_attr_name);
  1439. #if 1
  1440. /* needed until all drivers are fixed */
  1441. if (!vfd->release)
  1442. printk(KERN_WARNING "videodev: \"%s\" has no release callback. "
  1443. "Please fix your driver for proper sysfs support, see "
  1444. "http://lwn.net/Articles/36850/\n", vfd->name);
  1445. #endif
  1446. return 0;
  1447. }
  1448. /**
  1449. * video_unregister_device - unregister a video4linux device
  1450. * @vfd: the device to unregister
  1451. *
  1452. * This unregisters the passed device and deassigns the minor
  1453. * number. Future open calls will be met with errors.
  1454. */
  1455. void video_unregister_device(struct video_device *vfd)
  1456. {
  1457. mutex_lock(&videodev_lock);
  1458. if(video_device[vfd->minor]!=vfd)
  1459. panic("videodev: bad unregister");
  1460. devfs_remove(vfd->devfs_name);
  1461. video_device[vfd->minor]=NULL;
  1462. class_device_unregister(&vfd->class_dev);
  1463. mutex_unlock(&videodev_lock);
  1464. }
  1465. /*
  1466. * Video fs operations
  1467. */
  1468. static struct file_operations video_fops=
  1469. {
  1470. .owner = THIS_MODULE,
  1471. .llseek = no_llseek,
  1472. .open = video_open,
  1473. };
  1474. /*
  1475. * Initialise video for linux
  1476. */
  1477. static int __init videodev_init(void)
  1478. {
  1479. int ret;
  1480. printk(KERN_INFO "Linux video capture interface: v2.00\n");
  1481. if (register_chrdev(VIDEO_MAJOR, VIDEO_NAME, &video_fops)) {
  1482. printk(KERN_WARNING "video_dev: unable to get major %d\n", VIDEO_MAJOR);
  1483. return -EIO;
  1484. }
  1485. ret = class_register(&video_class);
  1486. if (ret < 0) {
  1487. unregister_chrdev(VIDEO_MAJOR, VIDEO_NAME);
  1488. printk(KERN_WARNING "video_dev: class_register failed\n");
  1489. return -EIO;
  1490. }
  1491. return 0;
  1492. }
  1493. static void __exit videodev_exit(void)
  1494. {
  1495. class_unregister(&video_class);
  1496. unregister_chrdev(VIDEO_MAJOR, VIDEO_NAME);
  1497. }
  1498. module_init(videodev_init)
  1499. module_exit(videodev_exit)
  1500. EXPORT_SYMBOL(video_register_device);
  1501. EXPORT_SYMBOL(video_unregister_device);
  1502. EXPORT_SYMBOL(video_devdata);
  1503. EXPORT_SYMBOL(video_usercopy);
  1504. EXPORT_SYMBOL(video_exclusive_open);
  1505. EXPORT_SYMBOL(video_exclusive_release);
  1506. EXPORT_SYMBOL(video_ioctl2);
  1507. EXPORT_SYMBOL(video_device_alloc);
  1508. EXPORT_SYMBOL(video_device_release);
  1509. MODULE_AUTHOR("Alan Cox, Mauro Carvalho Chehab <mchehab@infradead.org>");
  1510. MODULE_DESCRIPTION("Device registrar for Video4Linux drivers v2");
  1511. MODULE_LICENSE("GPL");
  1512. /*
  1513. * Local variables:
  1514. * c-basic-offset: 8
  1515. * End:
  1516. */