videodev.c 40 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718
  1. /*
  2. * Video capture interface for Linux version 2
  3. *
  4. * A generic video device interface for the LINUX operating system
  5. * using a set of device structures/vectors for low level operations.
  6. *
  7. * This program is free software; you can redistribute it and/or
  8. * modify it under the terms of the GNU General Public License
  9. * as published by the Free Software Foundation; either version
  10. * 2 of the License, or (at your option) any later version.
  11. *
  12. * Authors: Alan Cox, <alan@redhat.com> (version 1)
  13. * Mauro Carvalho Chehab <mchehab@infradead.org> (version 2)
  14. *
  15. * Fixes: 20000516 Claudio Matsuoka <claudio@conectiva.com>
  16. * - Added procfs support
  17. */
  18. #define dbgarg(cmd, fmt, arg...) \
  19. if (vfd->debug & V4L2_DEBUG_IOCTL_ARG) { \
  20. printk (KERN_DEBUG "%s: ", vfd->name); \
  21. v4l_printk_ioctl(cmd); \
  22. printk (KERN_DEBUG "%s: " fmt, vfd->name, ## arg); \
  23. }
  24. #define dbgarg2(fmt, arg...) \
  25. if (vfd->debug & V4L2_DEBUG_IOCTL_ARG) \
  26. printk (KERN_DEBUG "%s: " fmt, vfd->name, ## arg);
  27. #include <linux/module.h>
  28. #include <linux/types.h>
  29. #include <linux/kernel.h>
  30. #include <linux/sched.h>
  31. #include <linux/smp_lock.h>
  32. #include <linux/mm.h>
  33. #include <linux/string.h>
  34. #include <linux/errno.h>
  35. #include <linux/init.h>
  36. #include <linux/kmod.h>
  37. #include <linux/slab.h>
  38. #include <asm/uaccess.h>
  39. #include <asm/system.h>
  40. #define __OLD_VIDIOC_ /* To allow fixing old calls*/
  41. #include <linux/videodev2.h>
  42. #ifdef CONFIG_VIDEO_V4L1
  43. #include <linux/videodev.h>
  44. #endif
  45. #include <media/v4l2-common.h>
  46. #define VIDEO_NUM_DEVICES 256
  47. #define VIDEO_NAME "video4linux"
  48. /*
  49. * sysfs stuff
  50. */
  51. static ssize_t show_name(struct class_device *cd, char *buf)
  52. {
  53. struct video_device *vfd = container_of(cd, struct video_device,
  54. class_dev);
  55. return sprintf(buf,"%.*s\n",(int)sizeof(vfd->name),vfd->name);
  56. }
  57. static CLASS_DEVICE_ATTR(name, S_IRUGO, show_name, NULL);
  58. struct video_device *video_device_alloc(void)
  59. {
  60. struct video_device *vfd;
  61. vfd = kzalloc(sizeof(*vfd),GFP_KERNEL);
  62. return vfd;
  63. }
  64. void video_device_release(struct video_device *vfd)
  65. {
  66. kfree(vfd);
  67. }
  68. static void video_release(struct class_device *cd)
  69. {
  70. struct video_device *vfd = container_of(cd, struct video_device,
  71. class_dev);
  72. #if 1
  73. /* needed until all drivers are fixed */
  74. if (!vfd->release)
  75. return;
  76. #endif
  77. vfd->release(vfd);
  78. }
  79. static struct class video_class = {
  80. .name = VIDEO_NAME,
  81. .release = video_release,
  82. };
  83. /*
  84. * Active devices
  85. */
  86. static struct video_device *video_device[VIDEO_NUM_DEVICES];
  87. static DEFINE_MUTEX(videodev_lock);
  88. struct video_device* video_devdata(struct file *file)
  89. {
  90. return video_device[iminor(file->f_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_dqbuf)
  672. break;
  673. ret = check_fmt (vfd, p->type);
  674. if (ret)
  675. break;
  676. ret=vfd->vidioc_dqbuf(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 CONFIG_VIDEO_V4L1_COMPAT
  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. ret=vfd->vidioc_g_parm(file, fh, p);
  1168. } else {
  1169. struct v4l2_standard s;
  1170. int i;
  1171. if (!vfd->tvnormsize) {
  1172. printk (KERN_WARNING "%s: no TV norms defined!\n",
  1173. vfd->name);
  1174. break;
  1175. }
  1176. if (p->type != V4L2_BUF_TYPE_VIDEO_CAPTURE)
  1177. return -EINVAL;
  1178. for (i = 0; i < vfd->tvnormsize; i++)
  1179. if (vfd->tvnorms[i].id == vfd->current_norm)
  1180. break;
  1181. if (i >= vfd->tvnormsize)
  1182. return -EINVAL;
  1183. v4l2_video_std_construct(&s, vfd->current_norm,
  1184. vfd->tvnorms[i].name);
  1185. memset(p,0,sizeof(*p));
  1186. p->parm.capture.timeperframe = s.frameperiod;
  1187. ret=0;
  1188. }
  1189. dbgarg (cmd, "type=%d\n", p->type);
  1190. break;
  1191. }
  1192. case VIDIOC_S_PARM:
  1193. {
  1194. struct v4l2_streamparm *p=arg;
  1195. if (!vfd->vidioc_s_parm)
  1196. break;
  1197. dbgarg (cmd, "type=%d\n", p->type);
  1198. ret=vfd->vidioc_s_parm(file, fh, p);
  1199. break;
  1200. }
  1201. case VIDIOC_G_TUNER:
  1202. {
  1203. struct v4l2_tuner *p=arg;
  1204. if (!vfd->vidioc_g_tuner)
  1205. break;
  1206. ret=vfd->vidioc_g_tuner(file, fh, p);
  1207. if (!ret)
  1208. dbgarg (cmd, "index=%d, name=%s, type=%d, "
  1209. "capability=%d, rangelow=%d, "
  1210. "rangehigh=%d, signal=%d, afc=%d, "
  1211. "rxsubchans=%d, audmode=%d\n",
  1212. p->index, p->name, p->type,
  1213. p->capability, p->rangelow,
  1214. p->rangehigh, p->rxsubchans,
  1215. p->audmode, p->signal, p->afc);
  1216. break;
  1217. }
  1218. case VIDIOC_S_TUNER:
  1219. {
  1220. struct v4l2_tuner *p=arg;
  1221. if (!vfd->vidioc_s_tuner)
  1222. break;
  1223. dbgarg (cmd, "index=%d, name=%s, type=%d, "
  1224. "capability=%d, rangelow=%d, rangehigh=%d, "
  1225. "signal=%d, afc=%d, rxsubchans=%d, "
  1226. "audmode=%d\n",p->index, p->name, p->type,
  1227. p->capability, p->rangelow,p->rangehigh,
  1228. p->rxsubchans, p->audmode, p->signal,
  1229. p->afc);
  1230. ret=vfd->vidioc_s_tuner(file, fh, p);
  1231. break;
  1232. }
  1233. case VIDIOC_G_FREQUENCY:
  1234. {
  1235. struct v4l2_frequency *p=arg;
  1236. if (!vfd->vidioc_g_frequency)
  1237. break;
  1238. ret=vfd->vidioc_g_frequency(file, fh, p);
  1239. if (!ret)
  1240. dbgarg (cmd, "tuner=%d, type=%d, frequency=%d\n",
  1241. p->tuner,p->type,p->frequency);
  1242. break;
  1243. }
  1244. case VIDIOC_S_FREQUENCY:
  1245. {
  1246. struct v4l2_frequency *p=arg;
  1247. if (!vfd->vidioc_s_frequency)
  1248. break;
  1249. dbgarg (cmd, "tuner=%d, type=%d, frequency=%d\n",
  1250. p->tuner,p->type,p->frequency);
  1251. ret=vfd->vidioc_s_frequency(file, fh, p);
  1252. break;
  1253. }
  1254. case VIDIOC_G_SLICED_VBI_CAP:
  1255. {
  1256. struct v4l2_sliced_vbi_cap *p=arg;
  1257. if (!vfd->vidioc_g_sliced_vbi_cap)
  1258. break;
  1259. ret=vfd->vidioc_g_sliced_vbi_cap(file, fh, p);
  1260. if (!ret)
  1261. dbgarg (cmd, "service_set=%d\n", p->service_set);
  1262. break;
  1263. }
  1264. case VIDIOC_LOG_STATUS:
  1265. {
  1266. if (!vfd->vidioc_log_status)
  1267. break;
  1268. ret=vfd->vidioc_log_status(file, fh);
  1269. break;
  1270. }
  1271. /* --- Others --------------------------------------------- */
  1272. default:
  1273. ret=v4l_compat_translate_ioctl(inode,file,cmd,arg,__video_do_ioctl);
  1274. }
  1275. if (vfd->debug & V4L2_DEBUG_IOCTL_ARG) {
  1276. if (ret<0) {
  1277. printk ("%s: err:\n", vfd->name);
  1278. v4l_print_ioctl(vfd->name, cmd);
  1279. }
  1280. }
  1281. return ret;
  1282. }
  1283. int video_ioctl2 (struct inode *inode, struct file *file,
  1284. unsigned int cmd, unsigned long arg)
  1285. {
  1286. char sbuf[128];
  1287. void *mbuf = NULL;
  1288. void *parg = NULL;
  1289. int err = -EINVAL;
  1290. int is_ext_ctrl;
  1291. size_t ctrls_size = 0;
  1292. void __user *user_ptr = NULL;
  1293. #ifdef __OLD_VIDIOC_
  1294. cmd = video_fix_command(cmd);
  1295. #endif
  1296. is_ext_ctrl = (cmd == VIDIOC_S_EXT_CTRLS || cmd == VIDIOC_G_EXT_CTRLS ||
  1297. cmd == VIDIOC_TRY_EXT_CTRLS);
  1298. /* Copy arguments into temp kernel buffer */
  1299. switch (_IOC_DIR(cmd)) {
  1300. case _IOC_NONE:
  1301. parg = NULL;
  1302. break;
  1303. case _IOC_READ:
  1304. case _IOC_WRITE:
  1305. case (_IOC_WRITE | _IOC_READ):
  1306. if (_IOC_SIZE(cmd) <= sizeof(sbuf)) {
  1307. parg = sbuf;
  1308. } else {
  1309. /* too big to allocate from stack */
  1310. mbuf = kmalloc(_IOC_SIZE(cmd),GFP_KERNEL);
  1311. if (NULL == mbuf)
  1312. return -ENOMEM;
  1313. parg = mbuf;
  1314. }
  1315. err = -EFAULT;
  1316. if (_IOC_DIR(cmd) & _IOC_WRITE)
  1317. if (copy_from_user(parg, (void __user *)arg, _IOC_SIZE(cmd)))
  1318. goto out;
  1319. break;
  1320. }
  1321. if (is_ext_ctrl) {
  1322. struct v4l2_ext_controls *p = parg;
  1323. /* In case of an error, tell the caller that it wasn't
  1324. a specific control that caused it. */
  1325. p->error_idx = p->count;
  1326. user_ptr = (void __user *)p->controls;
  1327. if (p->count) {
  1328. ctrls_size = sizeof(struct v4l2_ext_control) * p->count;
  1329. /* Note: v4l2_ext_controls fits in sbuf[] so mbuf is still NULL. */
  1330. mbuf = kmalloc(ctrls_size, GFP_KERNEL);
  1331. err = -ENOMEM;
  1332. if (NULL == mbuf)
  1333. goto out_ext_ctrl;
  1334. err = -EFAULT;
  1335. if (copy_from_user(mbuf, user_ptr, ctrls_size))
  1336. goto out_ext_ctrl;
  1337. p->controls = mbuf;
  1338. }
  1339. }
  1340. /* Handles IOCTL */
  1341. err = __video_do_ioctl(inode, file, cmd, parg);
  1342. if (err == -ENOIOCTLCMD)
  1343. err = -EINVAL;
  1344. if (is_ext_ctrl) {
  1345. struct v4l2_ext_controls *p = parg;
  1346. p->controls = (void *)user_ptr;
  1347. if (p->count && err == 0 && copy_to_user(user_ptr, mbuf, ctrls_size))
  1348. err = -EFAULT;
  1349. goto out_ext_ctrl;
  1350. }
  1351. if (err < 0)
  1352. goto out;
  1353. out_ext_ctrl:
  1354. /* Copy results into user buffer */
  1355. switch (_IOC_DIR(cmd))
  1356. {
  1357. case _IOC_READ:
  1358. case (_IOC_WRITE | _IOC_READ):
  1359. if (copy_to_user((void __user *)arg, parg, _IOC_SIZE(cmd)))
  1360. err = -EFAULT;
  1361. break;
  1362. }
  1363. out:
  1364. kfree(mbuf);
  1365. return err;
  1366. }
  1367. static struct file_operations video_fops;
  1368. /**
  1369. * video_register_device - register video4linux devices
  1370. * @vfd: video device structure we want to register
  1371. * @type: type of device to register
  1372. * @nr: which device number (0 == /dev/video0, 1 == /dev/video1, ...
  1373. * -1 == first free)
  1374. *
  1375. * The registration code assigns minor numbers based on the type
  1376. * requested. -ENFILE is returned in all the device slots for this
  1377. * category are full. If not then the minor field is set and the
  1378. * driver initialize function is called (if non %NULL).
  1379. *
  1380. * Zero is returned on success.
  1381. *
  1382. * Valid types are
  1383. *
  1384. * %VFL_TYPE_GRABBER - A frame grabber
  1385. *
  1386. * %VFL_TYPE_VTX - A teletext device
  1387. *
  1388. * %VFL_TYPE_VBI - Vertical blank data (undecoded)
  1389. *
  1390. * %VFL_TYPE_RADIO - A radio card
  1391. */
  1392. int video_register_device(struct video_device *vfd, int type, int nr)
  1393. {
  1394. int i=0;
  1395. int base;
  1396. int end;
  1397. int ret;
  1398. char *name_base;
  1399. switch(type)
  1400. {
  1401. case VFL_TYPE_GRABBER:
  1402. base=MINOR_VFL_TYPE_GRABBER_MIN;
  1403. end=MINOR_VFL_TYPE_GRABBER_MAX+1;
  1404. name_base = "video";
  1405. break;
  1406. case VFL_TYPE_VTX:
  1407. base=MINOR_VFL_TYPE_VTX_MIN;
  1408. end=MINOR_VFL_TYPE_VTX_MAX+1;
  1409. name_base = "vtx";
  1410. break;
  1411. case VFL_TYPE_VBI:
  1412. base=MINOR_VFL_TYPE_VBI_MIN;
  1413. end=MINOR_VFL_TYPE_VBI_MAX+1;
  1414. name_base = "vbi";
  1415. break;
  1416. case VFL_TYPE_RADIO:
  1417. base=MINOR_VFL_TYPE_RADIO_MIN;
  1418. end=MINOR_VFL_TYPE_RADIO_MAX+1;
  1419. name_base = "radio";
  1420. break;
  1421. default:
  1422. printk(KERN_ERR "%s called with unknown type: %d\n",
  1423. __FUNCTION__, type);
  1424. return -1;
  1425. }
  1426. /* pick a minor number */
  1427. mutex_lock(&videodev_lock);
  1428. if (nr >= 0 && nr < end-base) {
  1429. /* use the one the driver asked for */
  1430. i = base+nr;
  1431. if (NULL != video_device[i]) {
  1432. mutex_unlock(&videodev_lock);
  1433. return -ENFILE;
  1434. }
  1435. } else {
  1436. /* use first free */
  1437. for(i=base;i<end;i++)
  1438. if (NULL == video_device[i])
  1439. break;
  1440. if (i == end) {
  1441. mutex_unlock(&videodev_lock);
  1442. return -ENFILE;
  1443. }
  1444. }
  1445. video_device[i]=vfd;
  1446. vfd->minor=i;
  1447. mutex_unlock(&videodev_lock);
  1448. mutex_init(&vfd->lock);
  1449. /* sysfs class */
  1450. memset(&vfd->class_dev, 0x00, sizeof(vfd->class_dev));
  1451. if (vfd->dev)
  1452. vfd->class_dev.dev = vfd->dev;
  1453. vfd->class_dev.class = &video_class;
  1454. vfd->class_dev.devt = MKDEV(VIDEO_MAJOR, vfd->minor);
  1455. sprintf(vfd->class_dev.class_id, "%s%d", name_base, i - base);
  1456. ret = class_device_register(&vfd->class_dev);
  1457. if (ret < 0) {
  1458. printk(KERN_ERR "%s: class_device_register failed\n",
  1459. __FUNCTION__);
  1460. goto fail_minor;
  1461. }
  1462. ret = class_device_create_file(&vfd->class_dev, &class_device_attr_name);
  1463. if (ret < 0) {
  1464. printk(KERN_ERR "%s: class_device_create_file 'name' failed\n",
  1465. __FUNCTION__);
  1466. goto fail_classdev;
  1467. }
  1468. #if 1
  1469. /* needed until all drivers are fixed */
  1470. if (!vfd->release)
  1471. printk(KERN_WARNING "videodev: \"%s\" has no release callback. "
  1472. "Please fix your driver for proper sysfs support, see "
  1473. "http://lwn.net/Articles/36850/\n", vfd->name);
  1474. #endif
  1475. return 0;
  1476. fail_classdev:
  1477. class_device_unregister(&vfd->class_dev);
  1478. fail_minor:
  1479. mutex_lock(&videodev_lock);
  1480. video_device[vfd->minor] = NULL;
  1481. vfd->minor = -1;
  1482. mutex_unlock(&videodev_lock);
  1483. return ret;
  1484. }
  1485. /**
  1486. * video_unregister_device - unregister a video4linux device
  1487. * @vfd: the device to unregister
  1488. *
  1489. * This unregisters the passed device and deassigns the minor
  1490. * number. Future open calls will be met with errors.
  1491. */
  1492. void video_unregister_device(struct video_device *vfd)
  1493. {
  1494. mutex_lock(&videodev_lock);
  1495. if(video_device[vfd->minor]!=vfd)
  1496. panic("videodev: bad unregister");
  1497. video_device[vfd->minor]=NULL;
  1498. class_device_unregister(&vfd->class_dev);
  1499. mutex_unlock(&videodev_lock);
  1500. }
  1501. /*
  1502. * Video fs operations
  1503. */
  1504. static struct file_operations video_fops=
  1505. {
  1506. .owner = THIS_MODULE,
  1507. .llseek = no_llseek,
  1508. .open = video_open,
  1509. };
  1510. /*
  1511. * Initialise video for linux
  1512. */
  1513. static int __init videodev_init(void)
  1514. {
  1515. int ret;
  1516. printk(KERN_INFO "Linux video capture interface: v2.00\n");
  1517. if (register_chrdev(VIDEO_MAJOR, VIDEO_NAME, &video_fops)) {
  1518. printk(KERN_WARNING "video_dev: unable to get major %d\n", VIDEO_MAJOR);
  1519. return -EIO;
  1520. }
  1521. ret = class_register(&video_class);
  1522. if (ret < 0) {
  1523. unregister_chrdev(VIDEO_MAJOR, VIDEO_NAME);
  1524. printk(KERN_WARNING "video_dev: class_register failed\n");
  1525. return -EIO;
  1526. }
  1527. return 0;
  1528. }
  1529. static void __exit videodev_exit(void)
  1530. {
  1531. class_unregister(&video_class);
  1532. unregister_chrdev(VIDEO_MAJOR, VIDEO_NAME);
  1533. }
  1534. module_init(videodev_init)
  1535. module_exit(videodev_exit)
  1536. EXPORT_SYMBOL(video_register_device);
  1537. EXPORT_SYMBOL(video_unregister_device);
  1538. EXPORT_SYMBOL(video_devdata);
  1539. EXPORT_SYMBOL(video_usercopy);
  1540. EXPORT_SYMBOL(video_exclusive_open);
  1541. EXPORT_SYMBOL(video_exclusive_release);
  1542. EXPORT_SYMBOL(video_ioctl2);
  1543. EXPORT_SYMBOL(video_device_alloc);
  1544. EXPORT_SYMBOL(video_device_release);
  1545. MODULE_AUTHOR("Alan Cox, Mauro Carvalho Chehab <mchehab@infradead.org>");
  1546. MODULE_DESCRIPTION("Device registrar for Video4Linux drivers v2");
  1547. MODULE_LICENSE("GPL");
  1548. /*
  1549. * Local variables:
  1550. * c-basic-offset: 8
  1551. * End:
  1552. */