videodev.c 43 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788
  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_PARM:
  1224. {
  1225. struct v4l2_streamparm *p=arg;
  1226. if (vfd->vidioc_g_parm) {
  1227. ret=vfd->vidioc_g_parm(file, fh, p);
  1228. } else {
  1229. struct v4l2_standard s;
  1230. if (p->type != V4L2_BUF_TYPE_VIDEO_CAPTURE)
  1231. return -EINVAL;
  1232. v4l2_video_std_construct(&s, vfd->current_norm,
  1233. v4l2_norm_to_name(vfd->current_norm));
  1234. memset(p,0,sizeof(*p));
  1235. p->parm.capture.timeperframe = s.frameperiod;
  1236. ret=0;
  1237. }
  1238. dbgarg (cmd, "type=%d\n", p->type);
  1239. break;
  1240. }
  1241. case VIDIOC_S_PARM:
  1242. {
  1243. struct v4l2_streamparm *p=arg;
  1244. if (!vfd->vidioc_s_parm)
  1245. break;
  1246. dbgarg (cmd, "type=%d\n", p->type);
  1247. ret=vfd->vidioc_s_parm(file, fh, p);
  1248. break;
  1249. }
  1250. case VIDIOC_G_TUNER:
  1251. {
  1252. struct v4l2_tuner *p=arg;
  1253. __u32 index=p->index;
  1254. if (!vfd->vidioc_g_tuner)
  1255. break;
  1256. memset(p,0,sizeof(*p));
  1257. p->index=index;
  1258. ret=vfd->vidioc_g_tuner(file, fh, p);
  1259. if (!ret)
  1260. dbgarg (cmd, "index=%d, name=%s, type=%d, "
  1261. "capability=%d, rangelow=%d, "
  1262. "rangehigh=%d, signal=%d, afc=%d, "
  1263. "rxsubchans=%d, audmode=%d\n",
  1264. p->index, p->name, p->type,
  1265. p->capability, p->rangelow,
  1266. p->rangehigh, p->rxsubchans,
  1267. p->audmode, p->signal, p->afc);
  1268. break;
  1269. }
  1270. case VIDIOC_S_TUNER:
  1271. {
  1272. struct v4l2_tuner *p=arg;
  1273. if (!vfd->vidioc_s_tuner)
  1274. break;
  1275. dbgarg (cmd, "index=%d, name=%s, type=%d, "
  1276. "capability=%d, rangelow=%d, rangehigh=%d, "
  1277. "signal=%d, afc=%d, rxsubchans=%d, "
  1278. "audmode=%d\n",p->index, p->name, p->type,
  1279. p->capability, p->rangelow,p->rangehigh,
  1280. p->rxsubchans, p->audmode, p->signal,
  1281. p->afc);
  1282. ret=vfd->vidioc_s_tuner(file, fh, p);
  1283. break;
  1284. }
  1285. case VIDIOC_G_FREQUENCY:
  1286. {
  1287. struct v4l2_frequency *p=arg;
  1288. if (!vfd->vidioc_g_frequency)
  1289. break;
  1290. memset(p,0,sizeof(*p));
  1291. ret=vfd->vidioc_g_frequency(file, fh, p);
  1292. if (!ret)
  1293. dbgarg (cmd, "tuner=%d, type=%d, frequency=%d\n",
  1294. p->tuner,p->type,p->frequency);
  1295. break;
  1296. }
  1297. case VIDIOC_S_FREQUENCY:
  1298. {
  1299. struct v4l2_frequency *p=arg;
  1300. if (!vfd->vidioc_s_frequency)
  1301. break;
  1302. dbgarg (cmd, "tuner=%d, type=%d, frequency=%d\n",
  1303. p->tuner,p->type,p->frequency);
  1304. ret=vfd->vidioc_s_frequency(file, fh, p);
  1305. break;
  1306. }
  1307. case VIDIOC_G_SLICED_VBI_CAP:
  1308. {
  1309. struct v4l2_sliced_vbi_cap *p=arg;
  1310. if (!vfd->vidioc_g_sliced_vbi_cap)
  1311. break;
  1312. ret=vfd->vidioc_g_sliced_vbi_cap(file, fh, p);
  1313. if (!ret)
  1314. dbgarg (cmd, "service_set=%d\n", p->service_set);
  1315. break;
  1316. }
  1317. case VIDIOC_LOG_STATUS:
  1318. {
  1319. if (!vfd->vidioc_log_status)
  1320. break;
  1321. ret=vfd->vidioc_log_status(file, fh);
  1322. break;
  1323. }
  1324. #ifdef CONFIG_VIDEO_ADV_DEBUG
  1325. case VIDIOC_DBG_G_REGISTER:
  1326. {
  1327. struct v4l2_register *p=arg;
  1328. if (vfd->vidioc_g_register)
  1329. ret=vfd->vidioc_g_register(file, fh, p);
  1330. break;
  1331. }
  1332. case VIDIOC_DBG_S_REGISTER:
  1333. {
  1334. struct v4l2_register *p=arg;
  1335. if (!capable(CAP_SYS_ADMIN))
  1336. ret=-EPERM;
  1337. else if (vfd->vidioc_s_register)
  1338. ret=vfd->vidioc_s_register(file, fh, p);
  1339. break;
  1340. }
  1341. #endif
  1342. } /* switch */
  1343. if (vfd->debug & V4L2_DEBUG_IOCTL_ARG) {
  1344. if (ret<0) {
  1345. printk ("%s: err:\n", vfd->name);
  1346. v4l_print_ioctl(vfd->name, cmd);
  1347. }
  1348. }
  1349. return ret;
  1350. }
  1351. int video_ioctl2 (struct inode *inode, struct file *file,
  1352. unsigned int cmd, unsigned long arg)
  1353. {
  1354. char sbuf[128];
  1355. void *mbuf = NULL;
  1356. void *parg = NULL;
  1357. int err = -EINVAL;
  1358. int is_ext_ctrl;
  1359. size_t ctrls_size = 0;
  1360. void __user *user_ptr = NULL;
  1361. #ifdef __OLD_VIDIOC_
  1362. cmd = video_fix_command(cmd);
  1363. #endif
  1364. is_ext_ctrl = (cmd == VIDIOC_S_EXT_CTRLS || cmd == VIDIOC_G_EXT_CTRLS ||
  1365. cmd == VIDIOC_TRY_EXT_CTRLS);
  1366. /* Copy arguments into temp kernel buffer */
  1367. switch (_IOC_DIR(cmd)) {
  1368. case _IOC_NONE:
  1369. parg = NULL;
  1370. break;
  1371. case _IOC_READ:
  1372. case _IOC_WRITE:
  1373. case (_IOC_WRITE | _IOC_READ):
  1374. if (_IOC_SIZE(cmd) <= sizeof(sbuf)) {
  1375. parg = sbuf;
  1376. } else {
  1377. /* too big to allocate from stack */
  1378. mbuf = kmalloc(_IOC_SIZE(cmd),GFP_KERNEL);
  1379. if (NULL == mbuf)
  1380. return -ENOMEM;
  1381. parg = mbuf;
  1382. }
  1383. err = -EFAULT;
  1384. if (_IOC_DIR(cmd) & _IOC_WRITE)
  1385. if (copy_from_user(parg, (void __user *)arg, _IOC_SIZE(cmd)))
  1386. goto out;
  1387. break;
  1388. }
  1389. if (is_ext_ctrl) {
  1390. struct v4l2_ext_controls *p = parg;
  1391. /* In case of an error, tell the caller that it wasn't
  1392. a specific control that caused it. */
  1393. p->error_idx = p->count;
  1394. user_ptr = (void __user *)p->controls;
  1395. if (p->count) {
  1396. ctrls_size = sizeof(struct v4l2_ext_control) * p->count;
  1397. /* Note: v4l2_ext_controls fits in sbuf[] so mbuf is still NULL. */
  1398. mbuf = kmalloc(ctrls_size, GFP_KERNEL);
  1399. err = -ENOMEM;
  1400. if (NULL == mbuf)
  1401. goto out_ext_ctrl;
  1402. err = -EFAULT;
  1403. if (copy_from_user(mbuf, user_ptr, ctrls_size))
  1404. goto out_ext_ctrl;
  1405. p->controls = mbuf;
  1406. }
  1407. }
  1408. /* Handles IOCTL */
  1409. err = __video_do_ioctl(inode, file, cmd, parg);
  1410. if (err == -ENOIOCTLCMD)
  1411. err = -EINVAL;
  1412. if (is_ext_ctrl) {
  1413. struct v4l2_ext_controls *p = parg;
  1414. p->controls = (void *)user_ptr;
  1415. if (p->count && err == 0 && copy_to_user(user_ptr, mbuf, ctrls_size))
  1416. err = -EFAULT;
  1417. goto out_ext_ctrl;
  1418. }
  1419. if (err < 0)
  1420. goto out;
  1421. out_ext_ctrl:
  1422. /* Copy results into user buffer */
  1423. switch (_IOC_DIR(cmd))
  1424. {
  1425. case _IOC_READ:
  1426. case (_IOC_WRITE | _IOC_READ):
  1427. if (copy_to_user((void __user *)arg, parg, _IOC_SIZE(cmd)))
  1428. err = -EFAULT;
  1429. break;
  1430. }
  1431. out:
  1432. kfree(mbuf);
  1433. return err;
  1434. }
  1435. static const struct file_operations video_fops;
  1436. /**
  1437. * video_register_device - register video4linux devices
  1438. * @vfd: video device structure we want to register
  1439. * @type: type of device to register
  1440. * @nr: which device number (0 == /dev/video0, 1 == /dev/video1, ...
  1441. * -1 == first free)
  1442. *
  1443. * The registration code assigns minor numbers based on the type
  1444. * requested. -ENFILE is returned in all the device slots for this
  1445. * category are full. If not then the minor field is set and the
  1446. * driver initialize function is called (if non %NULL).
  1447. *
  1448. * Zero is returned on success.
  1449. *
  1450. * Valid types are
  1451. *
  1452. * %VFL_TYPE_GRABBER - A frame grabber
  1453. *
  1454. * %VFL_TYPE_VTX - A teletext device
  1455. *
  1456. * %VFL_TYPE_VBI - Vertical blank data (undecoded)
  1457. *
  1458. * %VFL_TYPE_RADIO - A radio card
  1459. */
  1460. int video_register_device(struct video_device *vfd, int type, int nr)
  1461. {
  1462. int i=0;
  1463. int base;
  1464. int end;
  1465. int ret;
  1466. char *name_base;
  1467. switch(type)
  1468. {
  1469. case VFL_TYPE_GRABBER:
  1470. base=MINOR_VFL_TYPE_GRABBER_MIN;
  1471. end=MINOR_VFL_TYPE_GRABBER_MAX+1;
  1472. name_base = "video";
  1473. break;
  1474. case VFL_TYPE_VTX:
  1475. base=MINOR_VFL_TYPE_VTX_MIN;
  1476. end=MINOR_VFL_TYPE_VTX_MAX+1;
  1477. name_base = "vtx";
  1478. break;
  1479. case VFL_TYPE_VBI:
  1480. base=MINOR_VFL_TYPE_VBI_MIN;
  1481. end=MINOR_VFL_TYPE_VBI_MAX+1;
  1482. name_base = "vbi";
  1483. break;
  1484. case VFL_TYPE_RADIO:
  1485. base=MINOR_VFL_TYPE_RADIO_MIN;
  1486. end=MINOR_VFL_TYPE_RADIO_MAX+1;
  1487. name_base = "radio";
  1488. break;
  1489. default:
  1490. printk(KERN_ERR "%s called with unknown type: %d\n",
  1491. __FUNCTION__, type);
  1492. return -1;
  1493. }
  1494. /* pick a minor number */
  1495. mutex_lock(&videodev_lock);
  1496. if (nr >= 0 && nr < end-base) {
  1497. /* use the one the driver asked for */
  1498. i = base+nr;
  1499. if (NULL != video_device[i]) {
  1500. mutex_unlock(&videodev_lock);
  1501. return -ENFILE;
  1502. }
  1503. } else {
  1504. /* use first free */
  1505. for(i=base;i<end;i++)
  1506. if (NULL == video_device[i])
  1507. break;
  1508. if (i == end) {
  1509. mutex_unlock(&videodev_lock);
  1510. return -ENFILE;
  1511. }
  1512. }
  1513. video_device[i]=vfd;
  1514. vfd->minor=i;
  1515. mutex_unlock(&videodev_lock);
  1516. mutex_init(&vfd->lock);
  1517. /* sysfs class */
  1518. memset(&vfd->class_dev, 0x00, sizeof(vfd->class_dev));
  1519. if (vfd->dev)
  1520. vfd->class_dev.dev = vfd->dev;
  1521. vfd->class_dev.class = &video_class;
  1522. vfd->class_dev.devt = MKDEV(VIDEO_MAJOR, vfd->minor);
  1523. sprintf(vfd->class_dev.class_id, "%s%d", name_base, i - base);
  1524. ret = class_device_register(&vfd->class_dev);
  1525. if (ret < 0) {
  1526. printk(KERN_ERR "%s: class_device_register failed\n",
  1527. __FUNCTION__);
  1528. goto fail_minor;
  1529. }
  1530. ret = class_device_create_file(&vfd->class_dev, &class_device_attr_name);
  1531. if (ret < 0) {
  1532. printk(KERN_ERR "%s: class_device_create_file 'name' failed\n",
  1533. __FUNCTION__);
  1534. goto fail_classdev;
  1535. }
  1536. #if 1
  1537. /* needed until all drivers are fixed */
  1538. if (!vfd->release)
  1539. printk(KERN_WARNING "videodev: \"%s\" has no release callback. "
  1540. "Please fix your driver for proper sysfs support, see "
  1541. "http://lwn.net/Articles/36850/\n", vfd->name);
  1542. #endif
  1543. return 0;
  1544. fail_classdev:
  1545. class_device_unregister(&vfd->class_dev);
  1546. fail_minor:
  1547. mutex_lock(&videodev_lock);
  1548. video_device[vfd->minor] = NULL;
  1549. vfd->minor = -1;
  1550. mutex_unlock(&videodev_lock);
  1551. return ret;
  1552. }
  1553. /**
  1554. * video_unregister_device - unregister a video4linux device
  1555. * @vfd: the device to unregister
  1556. *
  1557. * This unregisters the passed device and deassigns the minor
  1558. * number. Future open calls will be met with errors.
  1559. */
  1560. void video_unregister_device(struct video_device *vfd)
  1561. {
  1562. mutex_lock(&videodev_lock);
  1563. if(video_device[vfd->minor]!=vfd)
  1564. panic("videodev: bad unregister");
  1565. video_device[vfd->minor]=NULL;
  1566. class_device_unregister(&vfd->class_dev);
  1567. mutex_unlock(&videodev_lock);
  1568. }
  1569. /*
  1570. * Video fs operations
  1571. */
  1572. static const struct file_operations video_fops=
  1573. {
  1574. .owner = THIS_MODULE,
  1575. .llseek = no_llseek,
  1576. .open = video_open,
  1577. };
  1578. /*
  1579. * Initialise video for linux
  1580. */
  1581. static int __init videodev_init(void)
  1582. {
  1583. int ret;
  1584. printk(KERN_INFO "Linux video capture interface: v2.00\n");
  1585. if (register_chrdev(VIDEO_MAJOR, VIDEO_NAME, &video_fops)) {
  1586. printk(KERN_WARNING "video_dev: unable to get major %d\n", VIDEO_MAJOR);
  1587. return -EIO;
  1588. }
  1589. ret = class_register(&video_class);
  1590. if (ret < 0) {
  1591. unregister_chrdev(VIDEO_MAJOR, VIDEO_NAME);
  1592. printk(KERN_WARNING "video_dev: class_register failed\n");
  1593. return -EIO;
  1594. }
  1595. return 0;
  1596. }
  1597. static void __exit videodev_exit(void)
  1598. {
  1599. class_unregister(&video_class);
  1600. unregister_chrdev(VIDEO_MAJOR, VIDEO_NAME);
  1601. }
  1602. module_init(videodev_init)
  1603. module_exit(videodev_exit)
  1604. EXPORT_SYMBOL(video_register_device);
  1605. EXPORT_SYMBOL(video_unregister_device);
  1606. EXPORT_SYMBOL(video_devdata);
  1607. EXPORT_SYMBOL(video_usercopy);
  1608. EXPORT_SYMBOL(video_exclusive_open);
  1609. EXPORT_SYMBOL(video_exclusive_release);
  1610. EXPORT_SYMBOL(video_ioctl2);
  1611. EXPORT_SYMBOL(video_device_alloc);
  1612. EXPORT_SYMBOL(video_device_release);
  1613. MODULE_AUTHOR("Alan Cox, Mauro Carvalho Chehab <mchehab@infradead.org>");
  1614. MODULE_DESCRIPTION("Device registrar for Video4Linux drivers v2");
  1615. MODULE_LICENSE("GPL");
  1616. /*
  1617. * Local variables:
  1618. * c-basic-offset: 8
  1619. * End:
  1620. */