videodev.c 43 KB

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