videodev.c 39 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670
  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 HAVE_V4L1
  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. char *name_base;
  1377. switch(type)
  1378. {
  1379. case VFL_TYPE_GRABBER:
  1380. base=MINOR_VFL_TYPE_GRABBER_MIN;
  1381. end=MINOR_VFL_TYPE_GRABBER_MAX+1;
  1382. name_base = "video";
  1383. break;
  1384. case VFL_TYPE_VTX:
  1385. base=MINOR_VFL_TYPE_VTX_MIN;
  1386. end=MINOR_VFL_TYPE_VTX_MAX+1;
  1387. name_base = "vtx";
  1388. break;
  1389. case VFL_TYPE_VBI:
  1390. base=MINOR_VFL_TYPE_VBI_MIN;
  1391. end=MINOR_VFL_TYPE_VBI_MAX+1;
  1392. name_base = "vbi";
  1393. break;
  1394. case VFL_TYPE_RADIO:
  1395. base=MINOR_VFL_TYPE_RADIO_MIN;
  1396. end=MINOR_VFL_TYPE_RADIO_MAX+1;
  1397. name_base = "radio";
  1398. break;
  1399. default:
  1400. return -1;
  1401. }
  1402. /* pick a minor number */
  1403. mutex_lock(&videodev_lock);
  1404. if (nr >= 0 && nr < end-base) {
  1405. /* use the one the driver asked for */
  1406. i = base+nr;
  1407. if (NULL != video_device[i]) {
  1408. mutex_unlock(&videodev_lock);
  1409. return -ENFILE;
  1410. }
  1411. } else {
  1412. /* use first free */
  1413. for(i=base;i<end;i++)
  1414. if (NULL == video_device[i])
  1415. break;
  1416. if (i == end) {
  1417. mutex_unlock(&videodev_lock);
  1418. return -ENFILE;
  1419. }
  1420. }
  1421. video_device[i]=vfd;
  1422. vfd->minor=i;
  1423. mutex_unlock(&videodev_lock);
  1424. mutex_init(&vfd->lock);
  1425. /* sysfs class */
  1426. memset(&vfd->class_dev, 0x00, sizeof(vfd->class_dev));
  1427. if (vfd->dev)
  1428. vfd->class_dev.dev = vfd->dev;
  1429. vfd->class_dev.class = &video_class;
  1430. vfd->class_dev.devt = MKDEV(VIDEO_MAJOR, vfd->minor);
  1431. sprintf(vfd->devfs_name, "%s%d", name_base, i - base);
  1432. strlcpy(vfd->class_dev.class_id, vfd->devfs_name, BUS_ID_SIZE);
  1433. class_device_register(&vfd->class_dev);
  1434. class_device_create_file(&vfd->class_dev,
  1435. &class_device_attr_name);
  1436. #if 1
  1437. /* needed until all drivers are fixed */
  1438. if (!vfd->release)
  1439. printk(KERN_WARNING "videodev: \"%s\" has no release callback. "
  1440. "Please fix your driver for proper sysfs support, see "
  1441. "http://lwn.net/Articles/36850/\n", vfd->name);
  1442. #endif
  1443. return 0;
  1444. }
  1445. /**
  1446. * video_unregister_device - unregister a video4linux device
  1447. * @vfd: the device to unregister
  1448. *
  1449. * This unregisters the passed device and deassigns the minor
  1450. * number. Future open calls will be met with errors.
  1451. */
  1452. void video_unregister_device(struct video_device *vfd)
  1453. {
  1454. mutex_lock(&videodev_lock);
  1455. if(video_device[vfd->minor]!=vfd)
  1456. panic("videodev: bad unregister");
  1457. video_device[vfd->minor]=NULL;
  1458. class_device_unregister(&vfd->class_dev);
  1459. mutex_unlock(&videodev_lock);
  1460. }
  1461. /*
  1462. * Video fs operations
  1463. */
  1464. static struct file_operations video_fops=
  1465. {
  1466. .owner = THIS_MODULE,
  1467. .llseek = no_llseek,
  1468. .open = video_open,
  1469. };
  1470. /*
  1471. * Initialise video for linux
  1472. */
  1473. static int __init videodev_init(void)
  1474. {
  1475. int ret;
  1476. printk(KERN_INFO "Linux video capture interface: v2.00\n");
  1477. if (register_chrdev(VIDEO_MAJOR, VIDEO_NAME, &video_fops)) {
  1478. printk(KERN_WARNING "video_dev: unable to get major %d\n", VIDEO_MAJOR);
  1479. return -EIO;
  1480. }
  1481. ret = class_register(&video_class);
  1482. if (ret < 0) {
  1483. unregister_chrdev(VIDEO_MAJOR, VIDEO_NAME);
  1484. printk(KERN_WARNING "video_dev: class_register failed\n");
  1485. return -EIO;
  1486. }
  1487. return 0;
  1488. }
  1489. static void __exit videodev_exit(void)
  1490. {
  1491. class_unregister(&video_class);
  1492. unregister_chrdev(VIDEO_MAJOR, VIDEO_NAME);
  1493. }
  1494. module_init(videodev_init)
  1495. module_exit(videodev_exit)
  1496. EXPORT_SYMBOL(video_register_device);
  1497. EXPORT_SYMBOL(video_unregister_device);
  1498. EXPORT_SYMBOL(video_devdata);
  1499. EXPORT_SYMBOL(video_usercopy);
  1500. EXPORT_SYMBOL(video_exclusive_open);
  1501. EXPORT_SYMBOL(video_exclusive_release);
  1502. EXPORT_SYMBOL(video_ioctl2);
  1503. EXPORT_SYMBOL(video_device_alloc);
  1504. EXPORT_SYMBOL(video_device_release);
  1505. MODULE_AUTHOR("Alan Cox, Mauro Carvalho Chehab <mchehab@infradead.org>");
  1506. MODULE_DESCRIPTION("Device registrar for Video4Linux drivers v2");
  1507. MODULE_LICENSE("GPL");
  1508. /*
  1509. * Local variables:
  1510. * c-basic-offset: 8
  1511. * End:
  1512. */