videodev.c 55 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188
  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(" " fmt, ## 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/mm.h>
  31. #include <linux/string.h>
  32. #include <linux/errno.h>
  33. #include <linux/init.h>
  34. #include <linux/kmod.h>
  35. #include <linux/slab.h>
  36. #include <linux/smp_lock.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. #include <linux/video_decoder.h>
  46. #define VIDEO_NUM_DEVICES 256
  47. #define VIDEO_NAME "video4linux"
  48. struct std_descr {
  49. v4l2_std_id std;
  50. const char *descr;
  51. };
  52. static const struct std_descr standards[] = {
  53. { V4L2_STD_NTSC, "NTSC" },
  54. { V4L2_STD_NTSC_M, "NTSC-M" },
  55. { V4L2_STD_NTSC_M_JP, "NTSC-M-JP" },
  56. { V4L2_STD_NTSC_M_KR, "NTSC-M-KR" },
  57. { V4L2_STD_NTSC_443, "NTSC-443" },
  58. { V4L2_STD_PAL, "PAL" },
  59. { V4L2_STD_PAL_BG, "PAL-BG" },
  60. { V4L2_STD_PAL_B, "PAL-B" },
  61. { V4L2_STD_PAL_B1, "PAL-B1" },
  62. { V4L2_STD_PAL_G, "PAL-G" },
  63. { V4L2_STD_PAL_H, "PAL-H" },
  64. { V4L2_STD_PAL_I, "PAL-I" },
  65. { V4L2_STD_PAL_DK, "PAL-DK" },
  66. { V4L2_STD_PAL_D, "PAL-D" },
  67. { V4L2_STD_PAL_D1, "PAL-D1" },
  68. { V4L2_STD_PAL_K, "PAL-K" },
  69. { V4L2_STD_PAL_M, "PAL-M" },
  70. { V4L2_STD_PAL_N, "PAL-N" },
  71. { V4L2_STD_PAL_Nc, "PAL-Nc" },
  72. { V4L2_STD_PAL_60, "PAL-60" },
  73. { V4L2_STD_SECAM, "SECAM" },
  74. { V4L2_STD_SECAM_B, "SECAM-B" },
  75. { V4L2_STD_SECAM_G, "SECAM-G" },
  76. { V4L2_STD_SECAM_H, "SECAM-H" },
  77. { V4L2_STD_SECAM_DK, "SECAM-DK" },
  78. { V4L2_STD_SECAM_D, "SECAM-D" },
  79. { V4L2_STD_SECAM_K, "SECAM-K" },
  80. { V4L2_STD_SECAM_K1, "SECAM-K1" },
  81. { V4L2_STD_SECAM_L, "SECAM-L" },
  82. { V4L2_STD_SECAM_LC, "SECAM-Lc" },
  83. { 0, "Unknown" }
  84. };
  85. /* video4linux standard ID conversion to standard name
  86. */
  87. const char *v4l2_norm_to_name(v4l2_std_id id)
  88. {
  89. u32 myid = id;
  90. int i;
  91. /* HACK: ppc32 architecture doesn't have __ucmpdi2 function to handle
  92. 64 bit comparations. So, on that architecture, with some gcc
  93. variants, compilation fails. Currently, the max value is 30bit wide.
  94. */
  95. BUG_ON(myid != id);
  96. for (i = 0; standards[i].std; i++)
  97. if (myid == standards[i].std)
  98. break;
  99. return standards[i].descr;
  100. }
  101. EXPORT_SYMBOL(v4l2_norm_to_name);
  102. /* Fill in the fields of a v4l2_standard structure according to the
  103. 'id' and 'transmission' parameters. Returns negative on error. */
  104. int v4l2_video_std_construct(struct v4l2_standard *vs,
  105. int id, const char *name)
  106. {
  107. u32 index = vs->index;
  108. memset(vs, 0, sizeof(struct v4l2_standard));
  109. vs->index = index;
  110. vs->id = id;
  111. if (id & V4L2_STD_525_60) {
  112. vs->frameperiod.numerator = 1001;
  113. vs->frameperiod.denominator = 30000;
  114. vs->framelines = 525;
  115. } else {
  116. vs->frameperiod.numerator = 1;
  117. vs->frameperiod.denominator = 25;
  118. vs->framelines = 625;
  119. }
  120. strlcpy(vs->name, name, sizeof(vs->name));
  121. return 0;
  122. }
  123. EXPORT_SYMBOL(v4l2_video_std_construct);
  124. /* ----------------------------------------------------------------- */
  125. /* some arrays for pretty-printing debug messages of enum types */
  126. char *v4l2_field_names[] = {
  127. [V4L2_FIELD_ANY] = "any",
  128. [V4L2_FIELD_NONE] = "none",
  129. [V4L2_FIELD_TOP] = "top",
  130. [V4L2_FIELD_BOTTOM] = "bottom",
  131. [V4L2_FIELD_INTERLACED] = "interlaced",
  132. [V4L2_FIELD_SEQ_TB] = "seq-tb",
  133. [V4L2_FIELD_SEQ_BT] = "seq-bt",
  134. [V4L2_FIELD_ALTERNATE] = "alternate",
  135. [V4L2_FIELD_INTERLACED_TB] = "interlaced-tb",
  136. [V4L2_FIELD_INTERLACED_BT] = "interlaced-bt",
  137. };
  138. EXPORT_SYMBOL(v4l2_field_names);
  139. char *v4l2_type_names[] = {
  140. [V4L2_BUF_TYPE_VIDEO_CAPTURE] = "video-cap",
  141. [V4L2_BUF_TYPE_VIDEO_OVERLAY] = "video-over",
  142. [V4L2_BUF_TYPE_VIDEO_OUTPUT] = "video-out",
  143. [V4L2_BUF_TYPE_VBI_CAPTURE] = "vbi-cap",
  144. [V4L2_BUF_TYPE_VBI_OUTPUT] = "vbi-out",
  145. [V4L2_BUF_TYPE_SLICED_VBI_CAPTURE] = "sliced-vbi-cap",
  146. [V4L2_BUF_TYPE_SLICED_VBI_OUTPUT] = "sliced-vbi-out",
  147. [V4L2_BUF_TYPE_VIDEO_OUTPUT_OVERLAY] = "video-out-over",
  148. };
  149. EXPORT_SYMBOL(v4l2_type_names);
  150. static char *v4l2_memory_names[] = {
  151. [V4L2_MEMORY_MMAP] = "mmap",
  152. [V4L2_MEMORY_USERPTR] = "userptr",
  153. [V4L2_MEMORY_OVERLAY] = "overlay",
  154. };
  155. #define prt_names(a, arr) ((((a) >= 0) && ((a) < ARRAY_SIZE(arr))) ? \
  156. arr[a] : "unknown")
  157. /* ------------------------------------------------------------------ */
  158. /* debug help functions */
  159. #ifdef CONFIG_VIDEO_V4L1_COMPAT
  160. static const char *v4l1_ioctls[] = {
  161. [_IOC_NR(VIDIOCGCAP)] = "VIDIOCGCAP",
  162. [_IOC_NR(VIDIOCGCHAN)] = "VIDIOCGCHAN",
  163. [_IOC_NR(VIDIOCSCHAN)] = "VIDIOCSCHAN",
  164. [_IOC_NR(VIDIOCGTUNER)] = "VIDIOCGTUNER",
  165. [_IOC_NR(VIDIOCSTUNER)] = "VIDIOCSTUNER",
  166. [_IOC_NR(VIDIOCGPICT)] = "VIDIOCGPICT",
  167. [_IOC_NR(VIDIOCSPICT)] = "VIDIOCSPICT",
  168. [_IOC_NR(VIDIOCCAPTURE)] = "VIDIOCCAPTURE",
  169. [_IOC_NR(VIDIOCGWIN)] = "VIDIOCGWIN",
  170. [_IOC_NR(VIDIOCSWIN)] = "VIDIOCSWIN",
  171. [_IOC_NR(VIDIOCGFBUF)] = "VIDIOCGFBUF",
  172. [_IOC_NR(VIDIOCSFBUF)] = "VIDIOCSFBUF",
  173. [_IOC_NR(VIDIOCKEY)] = "VIDIOCKEY",
  174. [_IOC_NR(VIDIOCGFREQ)] = "VIDIOCGFREQ",
  175. [_IOC_NR(VIDIOCSFREQ)] = "VIDIOCSFREQ",
  176. [_IOC_NR(VIDIOCGAUDIO)] = "VIDIOCGAUDIO",
  177. [_IOC_NR(VIDIOCSAUDIO)] = "VIDIOCSAUDIO",
  178. [_IOC_NR(VIDIOCSYNC)] = "VIDIOCSYNC",
  179. [_IOC_NR(VIDIOCMCAPTURE)] = "VIDIOCMCAPTURE",
  180. [_IOC_NR(VIDIOCGMBUF)] = "VIDIOCGMBUF",
  181. [_IOC_NR(VIDIOCGUNIT)] = "VIDIOCGUNIT",
  182. [_IOC_NR(VIDIOCGCAPTURE)] = "VIDIOCGCAPTURE",
  183. [_IOC_NR(VIDIOCSCAPTURE)] = "VIDIOCSCAPTURE",
  184. [_IOC_NR(VIDIOCSPLAYMODE)] = "VIDIOCSPLAYMODE",
  185. [_IOC_NR(VIDIOCSWRITEMODE)] = "VIDIOCSWRITEMODE",
  186. [_IOC_NR(VIDIOCGPLAYINFO)] = "VIDIOCGPLAYINFO",
  187. [_IOC_NR(VIDIOCSMICROCODE)] = "VIDIOCSMICROCODE",
  188. [_IOC_NR(VIDIOCGVBIFMT)] = "VIDIOCGVBIFMT",
  189. [_IOC_NR(VIDIOCSVBIFMT)] = "VIDIOCSVBIFMT"
  190. };
  191. #define V4L1_IOCTLS ARRAY_SIZE(v4l1_ioctls)
  192. #endif
  193. static const char *v4l2_ioctls[] = {
  194. [_IOC_NR(VIDIOC_QUERYCAP)] = "VIDIOC_QUERYCAP",
  195. [_IOC_NR(VIDIOC_RESERVED)] = "VIDIOC_RESERVED",
  196. [_IOC_NR(VIDIOC_ENUM_FMT)] = "VIDIOC_ENUM_FMT",
  197. [_IOC_NR(VIDIOC_G_FMT)] = "VIDIOC_G_FMT",
  198. [_IOC_NR(VIDIOC_S_FMT)] = "VIDIOC_S_FMT",
  199. [_IOC_NR(VIDIOC_REQBUFS)] = "VIDIOC_REQBUFS",
  200. [_IOC_NR(VIDIOC_QUERYBUF)] = "VIDIOC_QUERYBUF",
  201. [_IOC_NR(VIDIOC_G_FBUF)] = "VIDIOC_G_FBUF",
  202. [_IOC_NR(VIDIOC_S_FBUF)] = "VIDIOC_S_FBUF",
  203. [_IOC_NR(VIDIOC_OVERLAY)] = "VIDIOC_OVERLAY",
  204. [_IOC_NR(VIDIOC_QBUF)] = "VIDIOC_QBUF",
  205. [_IOC_NR(VIDIOC_DQBUF)] = "VIDIOC_DQBUF",
  206. [_IOC_NR(VIDIOC_STREAMON)] = "VIDIOC_STREAMON",
  207. [_IOC_NR(VIDIOC_STREAMOFF)] = "VIDIOC_STREAMOFF",
  208. [_IOC_NR(VIDIOC_G_PARM)] = "VIDIOC_G_PARM",
  209. [_IOC_NR(VIDIOC_S_PARM)] = "VIDIOC_S_PARM",
  210. [_IOC_NR(VIDIOC_G_STD)] = "VIDIOC_G_STD",
  211. [_IOC_NR(VIDIOC_S_STD)] = "VIDIOC_S_STD",
  212. [_IOC_NR(VIDIOC_ENUMSTD)] = "VIDIOC_ENUMSTD",
  213. [_IOC_NR(VIDIOC_ENUMINPUT)] = "VIDIOC_ENUMINPUT",
  214. [_IOC_NR(VIDIOC_G_CTRL)] = "VIDIOC_G_CTRL",
  215. [_IOC_NR(VIDIOC_S_CTRL)] = "VIDIOC_S_CTRL",
  216. [_IOC_NR(VIDIOC_G_TUNER)] = "VIDIOC_G_TUNER",
  217. [_IOC_NR(VIDIOC_S_TUNER)] = "VIDIOC_S_TUNER",
  218. [_IOC_NR(VIDIOC_G_AUDIO)] = "VIDIOC_G_AUDIO",
  219. [_IOC_NR(VIDIOC_S_AUDIO)] = "VIDIOC_S_AUDIO",
  220. [_IOC_NR(VIDIOC_QUERYCTRL)] = "VIDIOC_QUERYCTRL",
  221. [_IOC_NR(VIDIOC_QUERYMENU)] = "VIDIOC_QUERYMENU",
  222. [_IOC_NR(VIDIOC_G_INPUT)] = "VIDIOC_G_INPUT",
  223. [_IOC_NR(VIDIOC_S_INPUT)] = "VIDIOC_S_INPUT",
  224. [_IOC_NR(VIDIOC_G_OUTPUT)] = "VIDIOC_G_OUTPUT",
  225. [_IOC_NR(VIDIOC_S_OUTPUT)] = "VIDIOC_S_OUTPUT",
  226. [_IOC_NR(VIDIOC_ENUMOUTPUT)] = "VIDIOC_ENUMOUTPUT",
  227. [_IOC_NR(VIDIOC_G_AUDOUT)] = "VIDIOC_G_AUDOUT",
  228. [_IOC_NR(VIDIOC_S_AUDOUT)] = "VIDIOC_S_AUDOUT",
  229. [_IOC_NR(VIDIOC_G_MODULATOR)] = "VIDIOC_G_MODULATOR",
  230. [_IOC_NR(VIDIOC_S_MODULATOR)] = "VIDIOC_S_MODULATOR",
  231. [_IOC_NR(VIDIOC_G_FREQUENCY)] = "VIDIOC_G_FREQUENCY",
  232. [_IOC_NR(VIDIOC_S_FREQUENCY)] = "VIDIOC_S_FREQUENCY",
  233. [_IOC_NR(VIDIOC_CROPCAP)] = "VIDIOC_CROPCAP",
  234. [_IOC_NR(VIDIOC_G_CROP)] = "VIDIOC_G_CROP",
  235. [_IOC_NR(VIDIOC_S_CROP)] = "VIDIOC_S_CROP",
  236. [_IOC_NR(VIDIOC_G_JPEGCOMP)] = "VIDIOC_G_JPEGCOMP",
  237. [_IOC_NR(VIDIOC_S_JPEGCOMP)] = "VIDIOC_S_JPEGCOMP",
  238. [_IOC_NR(VIDIOC_QUERYSTD)] = "VIDIOC_QUERYSTD",
  239. [_IOC_NR(VIDIOC_TRY_FMT)] = "VIDIOC_TRY_FMT",
  240. [_IOC_NR(VIDIOC_ENUMAUDIO)] = "VIDIOC_ENUMAUDIO",
  241. [_IOC_NR(VIDIOC_ENUMAUDOUT)] = "VIDIOC_ENUMAUDOUT",
  242. [_IOC_NR(VIDIOC_G_PRIORITY)] = "VIDIOC_G_PRIORITY",
  243. [_IOC_NR(VIDIOC_S_PRIORITY)] = "VIDIOC_S_PRIORITY",
  244. [_IOC_NR(VIDIOC_G_SLICED_VBI_CAP)] = "VIDIOC_G_SLICED_VBI_CAP",
  245. [_IOC_NR(VIDIOC_LOG_STATUS)] = "VIDIOC_LOG_STATUS",
  246. [_IOC_NR(VIDIOC_G_EXT_CTRLS)] = "VIDIOC_G_EXT_CTRLS",
  247. [_IOC_NR(VIDIOC_S_EXT_CTRLS)] = "VIDIOC_S_EXT_CTRLS",
  248. [_IOC_NR(VIDIOC_TRY_EXT_CTRLS)] = "VIDIOC_TRY_EXT_CTRLS",
  249. #if 1
  250. [_IOC_NR(VIDIOC_ENUM_FRAMESIZES)] = "VIDIOC_ENUM_FRAMESIZES",
  251. [_IOC_NR(VIDIOC_ENUM_FRAMEINTERVALS)] = "VIDIOC_ENUM_FRAMEINTERVALS",
  252. [_IOC_NR(VIDIOC_G_ENC_INDEX)] = "VIDIOC_G_ENC_INDEX",
  253. [_IOC_NR(VIDIOC_ENCODER_CMD)] = "VIDIOC_ENCODER_CMD",
  254. [_IOC_NR(VIDIOC_TRY_ENCODER_CMD)] = "VIDIOC_TRY_ENCODER_CMD",
  255. [_IOC_NR(VIDIOC_DBG_S_REGISTER)] = "VIDIOC_DBG_S_REGISTER",
  256. [_IOC_NR(VIDIOC_DBG_G_REGISTER)] = "VIDIOC_DBG_G_REGISTER",
  257. [_IOC_NR(VIDIOC_G_CHIP_IDENT)] = "VIDIOC_G_CHIP_IDENT",
  258. [_IOC_NR(VIDIOC_S_HW_FREQ_SEEK)] = "VIDIOC_S_HW_FREQ_SEEK",
  259. #endif
  260. };
  261. #define V4L2_IOCTLS ARRAY_SIZE(v4l2_ioctls)
  262. static const char *v4l2_int_ioctls[] = {
  263. #ifdef CONFIG_VIDEO_V4L1_COMPAT
  264. [_IOC_NR(DECODER_GET_CAPABILITIES)] = "DECODER_GET_CAPABILITIES",
  265. [_IOC_NR(DECODER_GET_STATUS)] = "DECODER_GET_STATUS",
  266. [_IOC_NR(DECODER_SET_NORM)] = "DECODER_SET_NORM",
  267. [_IOC_NR(DECODER_SET_INPUT)] = "DECODER_SET_INPUT",
  268. [_IOC_NR(DECODER_SET_OUTPUT)] = "DECODER_SET_OUTPUT",
  269. [_IOC_NR(DECODER_ENABLE_OUTPUT)] = "DECODER_ENABLE_OUTPUT",
  270. [_IOC_NR(DECODER_SET_PICTURE)] = "DECODER_SET_PICTURE",
  271. [_IOC_NR(DECODER_SET_GPIO)] = "DECODER_SET_GPIO",
  272. [_IOC_NR(DECODER_INIT)] = "DECODER_INIT",
  273. [_IOC_NR(DECODER_SET_VBI_BYPASS)] = "DECODER_SET_VBI_BYPASS",
  274. [_IOC_NR(DECODER_DUMP)] = "DECODER_DUMP",
  275. #endif
  276. [_IOC_NR(AUDC_SET_RADIO)] = "AUDC_SET_RADIO",
  277. [_IOC_NR(TUNER_SET_TYPE_ADDR)] = "TUNER_SET_TYPE_ADDR",
  278. [_IOC_NR(TUNER_SET_STANDBY)] = "TUNER_SET_STANDBY",
  279. [_IOC_NR(TUNER_SET_CONFIG)] = "TUNER_SET_CONFIG",
  280. [_IOC_NR(VIDIOC_INT_S_TUNER_MODE)] = "VIDIOC_INT_S_TUNER_MODE",
  281. [_IOC_NR(VIDIOC_INT_RESET)] = "VIDIOC_INT_RESET",
  282. [_IOC_NR(VIDIOC_INT_AUDIO_CLOCK_FREQ)] = "VIDIOC_INT_AUDIO_CLOCK_FREQ",
  283. [_IOC_NR(VIDIOC_INT_DECODE_VBI_LINE)] = "VIDIOC_INT_DECODE_VBI_LINE",
  284. [_IOC_NR(VIDIOC_INT_S_VBI_DATA)] = "VIDIOC_INT_S_VBI_DATA",
  285. [_IOC_NR(VIDIOC_INT_G_VBI_DATA)] = "VIDIOC_INT_G_VBI_DATA",
  286. [_IOC_NR(VIDIOC_INT_I2S_CLOCK_FREQ)] = "VIDIOC_INT_I2S_CLOCK_FREQ",
  287. [_IOC_NR(VIDIOC_INT_S_STANDBY)] = "VIDIOC_INT_S_STANDBY",
  288. [_IOC_NR(VIDIOC_INT_S_AUDIO_ROUTING)] = "VIDIOC_INT_S_AUDIO_ROUTING",
  289. [_IOC_NR(VIDIOC_INT_G_AUDIO_ROUTING)] = "VIDIOC_INT_G_AUDIO_ROUTING",
  290. [_IOC_NR(VIDIOC_INT_S_VIDEO_ROUTING)] = "VIDIOC_INT_S_VIDEO_ROUTING",
  291. [_IOC_NR(VIDIOC_INT_G_VIDEO_ROUTING)] = "VIDIOC_INT_G_VIDEO_ROUTING",
  292. [_IOC_NR(VIDIOC_INT_S_CRYSTAL_FREQ)] = "VIDIOC_INT_S_CRYSTAL_FREQ",
  293. [_IOC_NR(VIDIOC_INT_INIT)] = "VIDIOC_INT_INIT",
  294. [_IOC_NR(VIDIOC_INT_G_STD_OUTPUT)] = "VIDIOC_INT_G_STD_OUTPUT",
  295. [_IOC_NR(VIDIOC_INT_S_STD_OUTPUT)] = "VIDIOC_INT_S_STD_OUTPUT",
  296. };
  297. #define V4L2_INT_IOCTLS ARRAY_SIZE(v4l2_int_ioctls)
  298. /* Common ioctl debug function. This function can be used by
  299. external ioctl messages as well as internal V4L ioctl */
  300. void v4l_printk_ioctl(unsigned int cmd)
  301. {
  302. char *dir, *type;
  303. switch (_IOC_TYPE(cmd)) {
  304. case 'd':
  305. if (_IOC_NR(cmd) >= V4L2_INT_IOCTLS) {
  306. type = "v4l2_int";
  307. break;
  308. }
  309. printk("%s", v4l2_int_ioctls[_IOC_NR(cmd)]);
  310. return;
  311. #ifdef CONFIG_VIDEO_V4L1_COMPAT
  312. case 'v':
  313. if (_IOC_NR(cmd) >= V4L1_IOCTLS) {
  314. type = "v4l1";
  315. break;
  316. }
  317. printk("%s", v4l1_ioctls[_IOC_NR(cmd)]);
  318. return;
  319. #endif
  320. case 'V':
  321. if (_IOC_NR(cmd) >= V4L2_IOCTLS) {
  322. type = "v4l2";
  323. break;
  324. }
  325. printk("%s", v4l2_ioctls[_IOC_NR(cmd)]);
  326. return;
  327. default:
  328. type = "unknown";
  329. }
  330. switch (_IOC_DIR(cmd)) {
  331. case _IOC_NONE: dir = "--"; break;
  332. case _IOC_READ: dir = "r-"; break;
  333. case _IOC_WRITE: dir = "-w"; break;
  334. case _IOC_READ | _IOC_WRITE: dir = "rw"; break;
  335. default: dir = "*ERR*"; break;
  336. }
  337. printk("%s ioctl '%c', dir=%s, #%d (0x%08x)",
  338. type, _IOC_TYPE(cmd), dir, _IOC_NR(cmd), cmd);
  339. }
  340. EXPORT_SYMBOL(v4l_printk_ioctl);
  341. /*
  342. * sysfs stuff
  343. */
  344. static ssize_t show_index(struct device *cd,
  345. struct device_attribute *attr, char *buf)
  346. {
  347. struct video_device *vfd = container_of(cd, struct video_device,
  348. class_dev);
  349. return sprintf(buf, "%i\n", vfd->index);
  350. }
  351. static ssize_t show_name(struct device *cd,
  352. struct device_attribute *attr, char *buf)
  353. {
  354. struct video_device *vfd = container_of(cd, struct video_device,
  355. class_dev);
  356. return sprintf(buf, "%.*s\n", (int)sizeof(vfd->name), vfd->name);
  357. }
  358. struct video_device *video_device_alloc(void)
  359. {
  360. struct video_device *vfd;
  361. vfd = kzalloc(sizeof(*vfd),GFP_KERNEL);
  362. return vfd;
  363. }
  364. EXPORT_SYMBOL(video_device_alloc);
  365. void video_device_release(struct video_device *vfd)
  366. {
  367. kfree(vfd);
  368. }
  369. EXPORT_SYMBOL(video_device_release);
  370. static void video_release(struct device *cd)
  371. {
  372. struct video_device *vfd = container_of(cd, struct video_device,
  373. class_dev);
  374. #if 1
  375. /* needed until all drivers are fixed */
  376. if (!vfd->release)
  377. return;
  378. #endif
  379. vfd->release(vfd);
  380. }
  381. static struct device_attribute video_device_attrs[] = {
  382. __ATTR(name, S_IRUGO, show_name, NULL),
  383. __ATTR(index, S_IRUGO, show_index, NULL),
  384. __ATTR_NULL
  385. };
  386. static struct class video_class = {
  387. .name = VIDEO_NAME,
  388. .dev_attrs = video_device_attrs,
  389. .dev_release = video_release,
  390. };
  391. /*
  392. * Active devices
  393. */
  394. static struct video_device *video_device[VIDEO_NUM_DEVICES];
  395. static DEFINE_MUTEX(videodev_lock);
  396. struct video_device* video_devdata(struct file *file)
  397. {
  398. return video_device[iminor(file->f_path.dentry->d_inode)];
  399. }
  400. EXPORT_SYMBOL(video_devdata);
  401. /*
  402. * Open a video device - FIXME: Obsoleted
  403. */
  404. static int video_open(struct inode *inode, struct file *file)
  405. {
  406. unsigned int minor = iminor(inode);
  407. int err = 0;
  408. struct video_device *vfl;
  409. const struct file_operations *old_fops;
  410. if(minor>=VIDEO_NUM_DEVICES)
  411. return -ENODEV;
  412. lock_kernel();
  413. mutex_lock(&videodev_lock);
  414. vfl=video_device[minor];
  415. if(vfl==NULL) {
  416. mutex_unlock(&videodev_lock);
  417. request_module("char-major-%d-%d", VIDEO_MAJOR, minor);
  418. mutex_lock(&videodev_lock);
  419. vfl=video_device[minor];
  420. if (vfl==NULL) {
  421. mutex_unlock(&videodev_lock);
  422. unlock_kernel();
  423. return -ENODEV;
  424. }
  425. }
  426. old_fops = file->f_op;
  427. file->f_op = fops_get(vfl->fops);
  428. if(file->f_op->open)
  429. err = file->f_op->open(inode,file);
  430. if (err) {
  431. fops_put(file->f_op);
  432. file->f_op = fops_get(old_fops);
  433. }
  434. fops_put(old_fops);
  435. mutex_unlock(&videodev_lock);
  436. unlock_kernel();
  437. return err;
  438. }
  439. /*
  440. * helper function -- handles userspace copying for ioctl arguments
  441. */
  442. #ifdef __OLD_VIDIOC_
  443. static unsigned int
  444. video_fix_command(unsigned int cmd)
  445. {
  446. switch (cmd) {
  447. case VIDIOC_OVERLAY_OLD:
  448. cmd = VIDIOC_OVERLAY;
  449. break;
  450. case VIDIOC_S_PARM_OLD:
  451. cmd = VIDIOC_S_PARM;
  452. break;
  453. case VIDIOC_S_CTRL_OLD:
  454. cmd = VIDIOC_S_CTRL;
  455. break;
  456. case VIDIOC_G_AUDIO_OLD:
  457. cmd = VIDIOC_G_AUDIO;
  458. break;
  459. case VIDIOC_G_AUDOUT_OLD:
  460. cmd = VIDIOC_G_AUDOUT;
  461. break;
  462. case VIDIOC_CROPCAP_OLD:
  463. cmd = VIDIOC_CROPCAP;
  464. break;
  465. }
  466. return cmd;
  467. }
  468. #endif
  469. /*
  470. * Obsolete usercopy function - Should be removed soon
  471. */
  472. int
  473. video_usercopy(struct inode *inode, struct file *file,
  474. unsigned int cmd, unsigned long arg,
  475. int (*func)(struct inode *inode, struct file *file,
  476. unsigned int cmd, void *arg))
  477. {
  478. char sbuf[128];
  479. void *mbuf = NULL;
  480. void *parg = NULL;
  481. int err = -EINVAL;
  482. int is_ext_ctrl;
  483. size_t ctrls_size = 0;
  484. void __user *user_ptr = NULL;
  485. #ifdef __OLD_VIDIOC_
  486. cmd = video_fix_command(cmd);
  487. #endif
  488. is_ext_ctrl = (cmd == VIDIOC_S_EXT_CTRLS || cmd == VIDIOC_G_EXT_CTRLS ||
  489. cmd == VIDIOC_TRY_EXT_CTRLS);
  490. /* Copy arguments into temp kernel buffer */
  491. switch (_IOC_DIR(cmd)) {
  492. case _IOC_NONE:
  493. parg = NULL;
  494. break;
  495. case _IOC_READ:
  496. case _IOC_WRITE:
  497. case (_IOC_WRITE | _IOC_READ):
  498. if (_IOC_SIZE(cmd) <= sizeof(sbuf)) {
  499. parg = sbuf;
  500. } else {
  501. /* too big to allocate from stack */
  502. mbuf = kmalloc(_IOC_SIZE(cmd),GFP_KERNEL);
  503. if (NULL == mbuf)
  504. return -ENOMEM;
  505. parg = mbuf;
  506. }
  507. err = -EFAULT;
  508. if (_IOC_DIR(cmd) & _IOC_WRITE)
  509. if (copy_from_user(parg, (void __user *)arg, _IOC_SIZE(cmd)))
  510. goto out;
  511. break;
  512. }
  513. if (is_ext_ctrl) {
  514. struct v4l2_ext_controls *p = parg;
  515. /* In case of an error, tell the caller that it wasn't
  516. a specific control that caused it. */
  517. p->error_idx = p->count;
  518. user_ptr = (void __user *)p->controls;
  519. if (p->count) {
  520. ctrls_size = sizeof(struct v4l2_ext_control) * p->count;
  521. /* Note: v4l2_ext_controls fits in sbuf[] so mbuf is still NULL. */
  522. mbuf = kmalloc(ctrls_size, GFP_KERNEL);
  523. err = -ENOMEM;
  524. if (NULL == mbuf)
  525. goto out_ext_ctrl;
  526. err = -EFAULT;
  527. if (copy_from_user(mbuf, user_ptr, ctrls_size))
  528. goto out_ext_ctrl;
  529. p->controls = mbuf;
  530. }
  531. }
  532. /* call driver */
  533. err = func(inode, file, cmd, parg);
  534. if (err == -ENOIOCTLCMD)
  535. err = -EINVAL;
  536. if (is_ext_ctrl) {
  537. struct v4l2_ext_controls *p = parg;
  538. p->controls = (void *)user_ptr;
  539. if (p->count && err == 0 && copy_to_user(user_ptr, mbuf, ctrls_size))
  540. err = -EFAULT;
  541. goto out_ext_ctrl;
  542. }
  543. if (err < 0)
  544. goto out;
  545. out_ext_ctrl:
  546. /* Copy results into user buffer */
  547. switch (_IOC_DIR(cmd))
  548. {
  549. case _IOC_READ:
  550. case (_IOC_WRITE | _IOC_READ):
  551. if (copy_to_user((void __user *)arg, parg, _IOC_SIZE(cmd)))
  552. err = -EFAULT;
  553. break;
  554. }
  555. out:
  556. kfree(mbuf);
  557. return err;
  558. }
  559. EXPORT_SYMBOL(video_usercopy);
  560. /*
  561. * open/release helper functions -- handle exclusive opens
  562. * Should be removed soon
  563. */
  564. int video_exclusive_open(struct inode *inode, struct file *file)
  565. {
  566. struct video_device *vfl = video_devdata(file);
  567. int retval = 0;
  568. mutex_lock(&vfl->lock);
  569. if (vfl->users) {
  570. retval = -EBUSY;
  571. } else {
  572. vfl->users++;
  573. }
  574. mutex_unlock(&vfl->lock);
  575. return retval;
  576. }
  577. EXPORT_SYMBOL(video_exclusive_open);
  578. int video_exclusive_release(struct inode *inode, struct file *file)
  579. {
  580. struct video_device *vfl = video_devdata(file);
  581. vfl->users--;
  582. return 0;
  583. }
  584. EXPORT_SYMBOL(video_exclusive_release);
  585. static void dbgbuf(unsigned int cmd, struct video_device *vfd,
  586. struct v4l2_buffer *p)
  587. {
  588. struct v4l2_timecode *tc=&p->timecode;
  589. dbgarg (cmd, "%02ld:%02d:%02d.%08ld index=%d, type=%s, "
  590. "bytesused=%d, flags=0x%08d, "
  591. "field=%0d, sequence=%d, memory=%s, offset/userptr=0x%08lx, length=%d\n",
  592. (p->timestamp.tv_sec/3600),
  593. (int)(p->timestamp.tv_sec/60)%60,
  594. (int)(p->timestamp.tv_sec%60),
  595. p->timestamp.tv_usec,
  596. p->index,
  597. prt_names(p->type, v4l2_type_names),
  598. p->bytesused, p->flags,
  599. p->field, p->sequence,
  600. prt_names(p->memory, v4l2_memory_names),
  601. p->m.userptr, p->length);
  602. dbgarg2 ("timecode= %02d:%02d:%02d type=%d, "
  603. "flags=0x%08d, frames=%d, userbits=0x%08x\n",
  604. tc->hours,tc->minutes,tc->seconds,
  605. tc->type, tc->flags, tc->frames, *(__u32 *) tc->userbits);
  606. }
  607. static inline void dbgrect(struct video_device *vfd, char *s,
  608. struct v4l2_rect *r)
  609. {
  610. dbgarg2 ("%sRect start at %dx%d, size= %dx%d\n", s, r->left, r->top,
  611. r->width, r->height);
  612. };
  613. static inline void v4l_print_pix_fmt (struct video_device *vfd,
  614. struct v4l2_pix_format *fmt)
  615. {
  616. dbgarg2 ("width=%d, height=%d, format=%c%c%c%c, field=%s, "
  617. "bytesperline=%d sizeimage=%d, colorspace=%d\n",
  618. fmt->width,fmt->height,
  619. (fmt->pixelformat & 0xff),
  620. (fmt->pixelformat >> 8) & 0xff,
  621. (fmt->pixelformat >> 16) & 0xff,
  622. (fmt->pixelformat >> 24) & 0xff,
  623. prt_names(fmt->field, v4l2_field_names),
  624. fmt->bytesperline, fmt->sizeimage, fmt->colorspace);
  625. };
  626. static int check_fmt (struct video_device *vfd, enum v4l2_buf_type type)
  627. {
  628. switch (type) {
  629. case V4L2_BUF_TYPE_VIDEO_CAPTURE:
  630. if (vfd->vidioc_try_fmt_vid_cap)
  631. return (0);
  632. break;
  633. case V4L2_BUF_TYPE_VIDEO_OVERLAY:
  634. if (vfd->vidioc_try_fmt_vid_overlay)
  635. return (0);
  636. break;
  637. case V4L2_BUF_TYPE_VIDEO_OUTPUT:
  638. if (vfd->vidioc_try_fmt_vid_out)
  639. return (0);
  640. break;
  641. case V4L2_BUF_TYPE_VIDEO_OUTPUT_OVERLAY:
  642. if (vfd->vidioc_try_fmt_vid_out_overlay)
  643. return (0);
  644. break;
  645. case V4L2_BUF_TYPE_VBI_CAPTURE:
  646. if (vfd->vidioc_try_fmt_vbi_cap)
  647. return (0);
  648. break;
  649. case V4L2_BUF_TYPE_VBI_OUTPUT:
  650. if (vfd->vidioc_try_fmt_vbi_out)
  651. return (0);
  652. break;
  653. case V4L2_BUF_TYPE_SLICED_VBI_CAPTURE:
  654. if (vfd->vidioc_try_fmt_sliced_vbi_cap)
  655. return (0);
  656. break;
  657. case V4L2_BUF_TYPE_SLICED_VBI_OUTPUT:
  658. if (vfd->vidioc_try_fmt_sliced_vbi_out)
  659. return (0);
  660. break;
  661. case V4L2_BUF_TYPE_PRIVATE:
  662. if (vfd->vidioc_try_fmt_type_private)
  663. return (0);
  664. break;
  665. }
  666. return (-EINVAL);
  667. }
  668. static int __video_do_ioctl(struct inode *inode, struct file *file,
  669. unsigned int cmd, void *arg)
  670. {
  671. struct video_device *vfd = video_devdata(file);
  672. void *fh = file->private_data;
  673. int ret = -EINVAL;
  674. if ( (vfd->debug & V4L2_DEBUG_IOCTL) &&
  675. !(vfd->debug & V4L2_DEBUG_IOCTL_ARG)) {
  676. v4l_print_ioctl(vfd->name, cmd);
  677. printk("\n");
  678. }
  679. #ifdef CONFIG_VIDEO_V4L1_COMPAT
  680. /***********************************************************
  681. Handles calls to the obsoleted V4L1 API
  682. Due to the nature of VIDIOCGMBUF, each driver that supports
  683. V4L1 should implement its own handler for this ioctl.
  684. ***********************************************************/
  685. /* --- streaming capture ------------------------------------- */
  686. if (cmd == VIDIOCGMBUF) {
  687. struct video_mbuf *p=arg;
  688. memset(p, 0, sizeof(*p));
  689. if (!vfd->vidiocgmbuf)
  690. return ret;
  691. ret=vfd->vidiocgmbuf(file, fh, p);
  692. if (!ret)
  693. dbgarg (cmd, "size=%d, frames=%d, offsets=0x%08lx\n",
  694. p->size, p->frames,
  695. (unsigned long)p->offsets);
  696. return ret;
  697. }
  698. /********************************************************
  699. All other V4L1 calls are handled by v4l1_compat module.
  700. Those calls will be translated into V4L2 calls, and
  701. __video_do_ioctl will be called again, with one or more
  702. V4L2 ioctls.
  703. ********************************************************/
  704. if (_IOC_TYPE(cmd)=='v')
  705. return v4l_compat_translate_ioctl(inode,file,cmd,arg,
  706. __video_do_ioctl);
  707. #endif
  708. switch(cmd) {
  709. /* --- capabilities ------------------------------------------ */
  710. case VIDIOC_QUERYCAP:
  711. {
  712. struct v4l2_capability *cap = (struct v4l2_capability*)arg;
  713. memset(cap, 0, sizeof(*cap));
  714. if (!vfd->vidioc_querycap)
  715. break;
  716. ret=vfd->vidioc_querycap(file, fh, cap);
  717. if (!ret)
  718. dbgarg (cmd, "driver=%s, card=%s, bus=%s, "
  719. "version=0x%08x, "
  720. "capabilities=0x%08x\n",
  721. cap->driver,cap->card,cap->bus_info,
  722. cap->version,
  723. cap->capabilities);
  724. break;
  725. }
  726. /* --- priority ------------------------------------------ */
  727. case VIDIOC_G_PRIORITY:
  728. {
  729. enum v4l2_priority *p=arg;
  730. if (!vfd->vidioc_g_priority)
  731. break;
  732. ret=vfd->vidioc_g_priority(file, fh, p);
  733. if (!ret)
  734. dbgarg(cmd, "priority is %d\n", *p);
  735. break;
  736. }
  737. case VIDIOC_S_PRIORITY:
  738. {
  739. enum v4l2_priority *p=arg;
  740. if (!vfd->vidioc_s_priority)
  741. break;
  742. dbgarg(cmd, "setting priority to %d\n", *p);
  743. ret=vfd->vidioc_s_priority(file, fh, *p);
  744. break;
  745. }
  746. /* --- capture ioctls ---------------------------------------- */
  747. case VIDIOC_ENUM_FMT:
  748. {
  749. struct v4l2_fmtdesc *f = arg;
  750. enum v4l2_buf_type type;
  751. unsigned int index;
  752. index = f->index;
  753. type = f->type;
  754. memset(f,0,sizeof(*f));
  755. f->index = index;
  756. f->type = type;
  757. switch (type) {
  758. case V4L2_BUF_TYPE_VIDEO_CAPTURE:
  759. if (vfd->vidioc_enum_fmt_vid_cap)
  760. ret = vfd->vidioc_enum_fmt_vid_cap(file, fh, f);
  761. break;
  762. case V4L2_BUF_TYPE_VIDEO_OVERLAY:
  763. if (vfd->vidioc_enum_fmt_vid_overlay)
  764. ret = vfd->vidioc_enum_fmt_vid_overlay(file,
  765. fh, f);
  766. break;
  767. #if 1
  768. /* V4L2_BUF_TYPE_VBI_CAPTURE should not support VIDIOC_ENUM_FMT
  769. * according to the spec. The bttv and saa7134 drivers support
  770. * it though, so just warn that this is deprecated and will be
  771. * removed in the near future. */
  772. case V4L2_BUF_TYPE_VBI_CAPTURE:
  773. if (vfd->vidioc_enum_fmt_vbi_cap) {
  774. printk(KERN_WARNING "vidioc_enum_fmt_vbi_cap will be removed in 2.6.28!\n");
  775. ret = vfd->vidioc_enum_fmt_vbi_cap(file, fh, f);
  776. }
  777. break;
  778. #endif
  779. case V4L2_BUF_TYPE_VIDEO_OUTPUT:
  780. if (vfd->vidioc_enum_fmt_vid_out)
  781. ret = vfd->vidioc_enum_fmt_vid_out(file, fh, f);
  782. break;
  783. case V4L2_BUF_TYPE_PRIVATE:
  784. if (vfd->vidioc_enum_fmt_type_private)
  785. ret = vfd->vidioc_enum_fmt_type_private(file,
  786. fh, f);
  787. break;
  788. default:
  789. break;
  790. }
  791. if (!ret)
  792. dbgarg (cmd, "index=%d, type=%d, flags=%d, "
  793. "pixelformat=%c%c%c%c, description='%s'\n",
  794. f->index, f->type, f->flags,
  795. (f->pixelformat & 0xff),
  796. (f->pixelformat >> 8) & 0xff,
  797. (f->pixelformat >> 16) & 0xff,
  798. (f->pixelformat >> 24) & 0xff,
  799. f->description);
  800. break;
  801. }
  802. case VIDIOC_G_FMT:
  803. {
  804. struct v4l2_format *f = (struct v4l2_format *)arg;
  805. memset(f->fmt.raw_data, 0, sizeof(f->fmt.raw_data));
  806. /* FIXME: Should be one dump per type */
  807. dbgarg(cmd, "type=%s\n", prt_names(f->type, v4l2_type_names));
  808. switch (f->type) {
  809. case V4L2_BUF_TYPE_VIDEO_CAPTURE:
  810. if (vfd->vidioc_g_fmt_vid_cap)
  811. ret = vfd->vidioc_g_fmt_vid_cap(file, fh, f);
  812. if (!ret)
  813. v4l_print_pix_fmt(vfd,&f->fmt.pix);
  814. break;
  815. case V4L2_BUF_TYPE_VIDEO_OVERLAY:
  816. if (vfd->vidioc_g_fmt_vid_overlay)
  817. ret = vfd->vidioc_g_fmt_vid_overlay(file,
  818. fh, f);
  819. break;
  820. case V4L2_BUF_TYPE_VIDEO_OUTPUT:
  821. if (vfd->vidioc_g_fmt_vid_out)
  822. ret = vfd->vidioc_g_fmt_vid_out(file, fh, f);
  823. break;
  824. case V4L2_BUF_TYPE_VIDEO_OUTPUT_OVERLAY:
  825. if (vfd->vidioc_g_fmt_vid_out_overlay)
  826. ret = vfd->vidioc_g_fmt_vid_out_overlay(file,
  827. fh, f);
  828. break;
  829. case V4L2_BUF_TYPE_VBI_CAPTURE:
  830. if (vfd->vidioc_g_fmt_vbi_cap)
  831. ret = vfd->vidioc_g_fmt_vbi_cap(file, fh, f);
  832. break;
  833. case V4L2_BUF_TYPE_VBI_OUTPUT:
  834. if (vfd->vidioc_g_fmt_vbi_out)
  835. ret = vfd->vidioc_g_fmt_vbi_out(file, fh, f);
  836. break;
  837. case V4L2_BUF_TYPE_SLICED_VBI_CAPTURE:
  838. if (vfd->vidioc_g_fmt_sliced_vbi_cap)
  839. ret = vfd->vidioc_g_fmt_sliced_vbi_cap(file,
  840. fh, f);
  841. break;
  842. case V4L2_BUF_TYPE_SLICED_VBI_OUTPUT:
  843. if (vfd->vidioc_g_fmt_sliced_vbi_out)
  844. ret = vfd->vidioc_g_fmt_sliced_vbi_out(file,
  845. fh, f);
  846. break;
  847. case V4L2_BUF_TYPE_PRIVATE:
  848. if (vfd->vidioc_g_fmt_type_private)
  849. ret = vfd->vidioc_g_fmt_type_private(file,
  850. fh, f);
  851. break;
  852. }
  853. break;
  854. }
  855. case VIDIOC_S_FMT:
  856. {
  857. struct v4l2_format *f = (struct v4l2_format *)arg;
  858. /* FIXME: Should be one dump per type */
  859. dbgarg (cmd, "type=%s\n", prt_names(f->type,
  860. v4l2_type_names));
  861. switch (f->type) {
  862. case V4L2_BUF_TYPE_VIDEO_CAPTURE:
  863. v4l_print_pix_fmt(vfd,&f->fmt.pix);
  864. if (vfd->vidioc_s_fmt_vid_cap)
  865. ret = vfd->vidioc_s_fmt_vid_cap(file, fh, f);
  866. break;
  867. case V4L2_BUF_TYPE_VIDEO_OVERLAY:
  868. if (vfd->vidioc_s_fmt_vid_overlay)
  869. ret = vfd->vidioc_s_fmt_vid_overlay(file,
  870. fh, f);
  871. break;
  872. case V4L2_BUF_TYPE_VIDEO_OUTPUT:
  873. if (vfd->vidioc_s_fmt_vid_out)
  874. ret = vfd->vidioc_s_fmt_vid_out(file, fh, f);
  875. break;
  876. case V4L2_BUF_TYPE_VIDEO_OUTPUT_OVERLAY:
  877. if (vfd->vidioc_s_fmt_vid_out_overlay)
  878. ret = vfd->vidioc_s_fmt_vid_out_overlay(file,
  879. fh, f);
  880. break;
  881. case V4L2_BUF_TYPE_VBI_CAPTURE:
  882. if (vfd->vidioc_s_fmt_vbi_cap)
  883. ret = vfd->vidioc_s_fmt_vbi_cap(file, fh, f);
  884. break;
  885. case V4L2_BUF_TYPE_VBI_OUTPUT:
  886. if (vfd->vidioc_s_fmt_vbi_out)
  887. ret = vfd->vidioc_s_fmt_vbi_out(file, fh, f);
  888. break;
  889. case V4L2_BUF_TYPE_SLICED_VBI_CAPTURE:
  890. if (vfd->vidioc_s_fmt_sliced_vbi_cap)
  891. ret = vfd->vidioc_s_fmt_sliced_vbi_cap(file,
  892. fh, f);
  893. break;
  894. case V4L2_BUF_TYPE_SLICED_VBI_OUTPUT:
  895. if (vfd->vidioc_s_fmt_sliced_vbi_out)
  896. ret = vfd->vidioc_s_fmt_sliced_vbi_out(file,
  897. fh, f);
  898. break;
  899. case V4L2_BUF_TYPE_PRIVATE:
  900. if (vfd->vidioc_s_fmt_type_private)
  901. ret = vfd->vidioc_s_fmt_type_private(file,
  902. fh, f);
  903. break;
  904. }
  905. break;
  906. }
  907. case VIDIOC_TRY_FMT:
  908. {
  909. struct v4l2_format *f = (struct v4l2_format *)arg;
  910. /* FIXME: Should be one dump per type */
  911. dbgarg (cmd, "type=%s\n", prt_names(f->type,
  912. v4l2_type_names));
  913. switch (f->type) {
  914. case V4L2_BUF_TYPE_VIDEO_CAPTURE:
  915. if (vfd->vidioc_try_fmt_vid_cap)
  916. ret = vfd->vidioc_try_fmt_vid_cap(file, fh, f);
  917. if (!ret)
  918. v4l_print_pix_fmt(vfd,&f->fmt.pix);
  919. break;
  920. case V4L2_BUF_TYPE_VIDEO_OVERLAY:
  921. if (vfd->vidioc_try_fmt_vid_overlay)
  922. ret = vfd->vidioc_try_fmt_vid_overlay(file,
  923. fh, f);
  924. break;
  925. case V4L2_BUF_TYPE_VIDEO_OUTPUT:
  926. if (vfd->vidioc_try_fmt_vid_out)
  927. ret = vfd->vidioc_try_fmt_vid_out(file, fh, f);
  928. break;
  929. case V4L2_BUF_TYPE_VIDEO_OUTPUT_OVERLAY:
  930. if (vfd->vidioc_try_fmt_vid_out_overlay)
  931. ret = vfd->vidioc_try_fmt_vid_out_overlay(file,
  932. fh, f);
  933. break;
  934. case V4L2_BUF_TYPE_VBI_CAPTURE:
  935. if (vfd->vidioc_try_fmt_vbi_cap)
  936. ret = vfd->vidioc_try_fmt_vbi_cap(file, fh, f);
  937. break;
  938. case V4L2_BUF_TYPE_VBI_OUTPUT:
  939. if (vfd->vidioc_try_fmt_vbi_out)
  940. ret = vfd->vidioc_try_fmt_vbi_out(file, fh, f);
  941. break;
  942. case V4L2_BUF_TYPE_SLICED_VBI_CAPTURE:
  943. if (vfd->vidioc_try_fmt_sliced_vbi_cap)
  944. ret = vfd->vidioc_try_fmt_sliced_vbi_cap(file,
  945. fh, f);
  946. break;
  947. case V4L2_BUF_TYPE_SLICED_VBI_OUTPUT:
  948. if (vfd->vidioc_try_fmt_sliced_vbi_out)
  949. ret = vfd->vidioc_try_fmt_sliced_vbi_out(file,
  950. fh, f);
  951. break;
  952. case V4L2_BUF_TYPE_PRIVATE:
  953. if (vfd->vidioc_try_fmt_type_private)
  954. ret = vfd->vidioc_try_fmt_type_private(file,
  955. fh, f);
  956. break;
  957. }
  958. break;
  959. }
  960. /* FIXME: Those buf reqs could be handled here,
  961. with some changes on videobuf to allow its header to be included at
  962. videodev2.h or being merged at videodev2.
  963. */
  964. case VIDIOC_REQBUFS:
  965. {
  966. struct v4l2_requestbuffers *p=arg;
  967. if (!vfd->vidioc_reqbufs)
  968. break;
  969. ret = check_fmt (vfd, p->type);
  970. if (ret)
  971. break;
  972. ret=vfd->vidioc_reqbufs(file, fh, p);
  973. dbgarg (cmd, "count=%d, type=%s, memory=%s\n",
  974. p->count,
  975. prt_names(p->type, v4l2_type_names),
  976. prt_names(p->memory, v4l2_memory_names));
  977. break;
  978. }
  979. case VIDIOC_QUERYBUF:
  980. {
  981. struct v4l2_buffer *p=arg;
  982. if (!vfd->vidioc_querybuf)
  983. break;
  984. ret = check_fmt (vfd, p->type);
  985. if (ret)
  986. break;
  987. ret=vfd->vidioc_querybuf(file, fh, p);
  988. if (!ret)
  989. dbgbuf(cmd,vfd,p);
  990. break;
  991. }
  992. case VIDIOC_QBUF:
  993. {
  994. struct v4l2_buffer *p=arg;
  995. if (!vfd->vidioc_qbuf)
  996. break;
  997. ret = check_fmt (vfd, p->type);
  998. if (ret)
  999. break;
  1000. ret=vfd->vidioc_qbuf(file, fh, p);
  1001. if (!ret)
  1002. dbgbuf(cmd,vfd,p);
  1003. break;
  1004. }
  1005. case VIDIOC_DQBUF:
  1006. {
  1007. struct v4l2_buffer *p=arg;
  1008. if (!vfd->vidioc_dqbuf)
  1009. break;
  1010. ret = check_fmt (vfd, p->type);
  1011. if (ret)
  1012. break;
  1013. ret=vfd->vidioc_dqbuf(file, fh, p);
  1014. if (!ret)
  1015. dbgbuf(cmd,vfd,p);
  1016. break;
  1017. }
  1018. case VIDIOC_OVERLAY:
  1019. {
  1020. int *i = arg;
  1021. if (!vfd->vidioc_overlay)
  1022. break;
  1023. dbgarg (cmd, "value=%d\n",*i);
  1024. ret=vfd->vidioc_overlay(file, fh, *i);
  1025. break;
  1026. }
  1027. case VIDIOC_G_FBUF:
  1028. {
  1029. struct v4l2_framebuffer *p=arg;
  1030. if (!vfd->vidioc_g_fbuf)
  1031. break;
  1032. ret=vfd->vidioc_g_fbuf(file, fh, arg);
  1033. if (!ret) {
  1034. dbgarg (cmd, "capability=%d, flags=%d, base=0x%08lx\n",
  1035. p->capability,p->flags,
  1036. (unsigned long)p->base);
  1037. v4l_print_pix_fmt (vfd, &p->fmt);
  1038. }
  1039. break;
  1040. }
  1041. case VIDIOC_S_FBUF:
  1042. {
  1043. struct v4l2_framebuffer *p=arg;
  1044. if (!vfd->vidioc_s_fbuf)
  1045. break;
  1046. dbgarg (cmd, "capability=%d, flags=%d, base=0x%08lx\n",
  1047. p->capability,p->flags,(unsigned long)p->base);
  1048. v4l_print_pix_fmt (vfd, &p->fmt);
  1049. ret=vfd->vidioc_s_fbuf(file, fh, arg);
  1050. break;
  1051. }
  1052. case VIDIOC_STREAMON:
  1053. {
  1054. enum v4l2_buf_type i = *(int *)arg;
  1055. if (!vfd->vidioc_streamon)
  1056. break;
  1057. dbgarg(cmd, "type=%s\n", prt_names(i, v4l2_type_names));
  1058. ret=vfd->vidioc_streamon(file, fh,i);
  1059. break;
  1060. }
  1061. case VIDIOC_STREAMOFF:
  1062. {
  1063. enum v4l2_buf_type i = *(int *)arg;
  1064. if (!vfd->vidioc_streamoff)
  1065. break;
  1066. dbgarg(cmd, "type=%s\n", prt_names(i, v4l2_type_names));
  1067. ret=vfd->vidioc_streamoff(file, fh, i);
  1068. break;
  1069. }
  1070. /* ---------- tv norms ---------- */
  1071. case VIDIOC_ENUMSTD:
  1072. {
  1073. struct v4l2_standard *p = arg;
  1074. v4l2_std_id id = vfd->tvnorms, curr_id = 0;
  1075. unsigned int index = p->index, i, j = 0;
  1076. const char *descr = "";
  1077. /* Return norm array in a canonical way */
  1078. for (i = 0; i <= index && id; i++) {
  1079. /* last std value in the standards array is 0, so this
  1080. while always ends there since (id & 0) == 0. */
  1081. while ((id & standards[j].std) != standards[j].std)
  1082. j++;
  1083. curr_id = standards[j].std;
  1084. descr = standards[j].descr;
  1085. j++;
  1086. if (curr_id == 0)
  1087. break;
  1088. if (curr_id != V4L2_STD_PAL &&
  1089. curr_id != V4L2_STD_SECAM &&
  1090. curr_id != V4L2_STD_NTSC)
  1091. id &= ~curr_id;
  1092. }
  1093. if (i <= index)
  1094. return -EINVAL;
  1095. v4l2_video_std_construct(p, curr_id, descr);
  1096. p->index = index;
  1097. dbgarg(cmd, "index=%d, id=%Ld, name=%s, fps=%d/%d, "
  1098. "framelines=%d\n", p->index,
  1099. (unsigned long long)p->id, p->name,
  1100. p->frameperiod.numerator,
  1101. p->frameperiod.denominator,
  1102. p->framelines);
  1103. ret = 0;
  1104. break;
  1105. }
  1106. case VIDIOC_G_STD:
  1107. {
  1108. v4l2_std_id *id = arg;
  1109. ret = 0;
  1110. /* Calls the specific handler */
  1111. if (vfd->vidioc_g_std)
  1112. ret = vfd->vidioc_g_std(file, fh, id);
  1113. else
  1114. *id = vfd->current_norm;
  1115. if (!ret)
  1116. dbgarg(cmd, "value=%08Lx\n", (long long unsigned)*id);
  1117. break;
  1118. }
  1119. case VIDIOC_S_STD:
  1120. {
  1121. v4l2_std_id *id = arg,norm;
  1122. dbgarg (cmd, "value=%08Lx\n", (long long unsigned) *id);
  1123. norm = (*id) & vfd->tvnorms;
  1124. if ( vfd->tvnorms && !norm) /* Check if std is supported */
  1125. break;
  1126. /* Calls the specific handler */
  1127. if (vfd->vidioc_s_std)
  1128. ret=vfd->vidioc_s_std(file, fh, &norm);
  1129. else
  1130. ret=-EINVAL;
  1131. /* Updates standard information */
  1132. if (ret>=0)
  1133. vfd->current_norm=norm;
  1134. break;
  1135. }
  1136. case VIDIOC_QUERYSTD:
  1137. {
  1138. v4l2_std_id *p=arg;
  1139. if (!vfd->vidioc_querystd)
  1140. break;
  1141. ret=vfd->vidioc_querystd(file, fh, arg);
  1142. if (!ret)
  1143. dbgarg (cmd, "detected std=%08Lx\n",
  1144. (unsigned long long)*p);
  1145. break;
  1146. }
  1147. /* ------ input switching ---------- */
  1148. /* FIXME: Inputs can be handled inside videodev2 */
  1149. case VIDIOC_ENUMINPUT:
  1150. {
  1151. struct v4l2_input *p=arg;
  1152. int i=p->index;
  1153. if (!vfd->vidioc_enum_input)
  1154. break;
  1155. memset(p, 0, sizeof(*p));
  1156. p->index=i;
  1157. ret=vfd->vidioc_enum_input(file, fh, p);
  1158. if (!ret)
  1159. dbgarg (cmd, "index=%d, name=%s, type=%d, "
  1160. "audioset=%d, "
  1161. "tuner=%d, std=%08Lx, status=%d\n",
  1162. p->index,p->name,p->type,p->audioset,
  1163. p->tuner,
  1164. (unsigned long long)p->std,
  1165. p->status);
  1166. break;
  1167. }
  1168. case VIDIOC_G_INPUT:
  1169. {
  1170. unsigned int *i = arg;
  1171. if (!vfd->vidioc_g_input)
  1172. break;
  1173. ret=vfd->vidioc_g_input(file, fh, i);
  1174. if (!ret)
  1175. dbgarg (cmd, "value=%d\n",*i);
  1176. break;
  1177. }
  1178. case VIDIOC_S_INPUT:
  1179. {
  1180. unsigned int *i = arg;
  1181. if (!vfd->vidioc_s_input)
  1182. break;
  1183. dbgarg (cmd, "value=%d\n",*i);
  1184. ret=vfd->vidioc_s_input(file, fh, *i);
  1185. break;
  1186. }
  1187. /* ------ output switching ---------- */
  1188. case VIDIOC_ENUMOUTPUT:
  1189. {
  1190. struct v4l2_output *p = arg;
  1191. int i = p->index;
  1192. if (!vfd->vidioc_enum_output)
  1193. break;
  1194. memset(p, 0, sizeof(*p));
  1195. p->index = i;
  1196. ret = vfd->vidioc_enum_output(file, fh, p);
  1197. if (!ret)
  1198. dbgarg(cmd, "index=%d, name=%s, type=%d, "
  1199. "audioset=%d, "
  1200. "modulator=%d, std=%08Lx\n",
  1201. p->index, p->name, p->type, p->audioset,
  1202. p->modulator, (unsigned long long)p->std);
  1203. break;
  1204. }
  1205. case VIDIOC_G_OUTPUT:
  1206. {
  1207. unsigned int *i = arg;
  1208. if (!vfd->vidioc_g_output)
  1209. break;
  1210. ret=vfd->vidioc_g_output(file, fh, i);
  1211. if (!ret)
  1212. dbgarg (cmd, "value=%d\n",*i);
  1213. break;
  1214. }
  1215. case VIDIOC_S_OUTPUT:
  1216. {
  1217. unsigned int *i = arg;
  1218. if (!vfd->vidioc_s_output)
  1219. break;
  1220. dbgarg (cmd, "value=%d\n",*i);
  1221. ret=vfd->vidioc_s_output(file, fh, *i);
  1222. break;
  1223. }
  1224. /* --- controls ---------------------------------------------- */
  1225. case VIDIOC_QUERYCTRL:
  1226. {
  1227. struct v4l2_queryctrl *p=arg;
  1228. if (!vfd->vidioc_queryctrl)
  1229. break;
  1230. ret=vfd->vidioc_queryctrl(file, fh, p);
  1231. if (!ret)
  1232. dbgarg (cmd, "id=%d, type=%d, name=%s, "
  1233. "min/max=%d/%d,"
  1234. " step=%d, default=%d, flags=0x%08x\n",
  1235. p->id,p->type,p->name,p->minimum,
  1236. p->maximum,p->step,p->default_value,
  1237. p->flags);
  1238. break;
  1239. }
  1240. case VIDIOC_G_CTRL:
  1241. {
  1242. struct v4l2_control *p = arg;
  1243. if (!vfd->vidioc_g_ctrl)
  1244. break;
  1245. dbgarg(cmd, "Enum for index=%d\n", p->id);
  1246. ret=vfd->vidioc_g_ctrl(file, fh, p);
  1247. if (!ret)
  1248. dbgarg2 ( "id=%d, value=%d\n", p->id, p->value);
  1249. break;
  1250. }
  1251. case VIDIOC_S_CTRL:
  1252. {
  1253. struct v4l2_control *p = arg;
  1254. if (!vfd->vidioc_s_ctrl)
  1255. break;
  1256. dbgarg (cmd, "id=%d, value=%d\n", p->id, p->value);
  1257. ret=vfd->vidioc_s_ctrl(file, fh, p);
  1258. break;
  1259. }
  1260. case VIDIOC_G_EXT_CTRLS:
  1261. {
  1262. struct v4l2_ext_controls *p = arg;
  1263. if (vfd->vidioc_g_ext_ctrls) {
  1264. dbgarg(cmd, "count=%d\n", p->count);
  1265. ret=vfd->vidioc_g_ext_ctrls(file, fh, p);
  1266. }
  1267. break;
  1268. }
  1269. case VIDIOC_S_EXT_CTRLS:
  1270. {
  1271. struct v4l2_ext_controls *p = arg;
  1272. if (vfd->vidioc_s_ext_ctrls) {
  1273. dbgarg(cmd, "count=%d\n", p->count);
  1274. ret=vfd->vidioc_s_ext_ctrls(file, fh, p);
  1275. }
  1276. break;
  1277. }
  1278. case VIDIOC_TRY_EXT_CTRLS:
  1279. {
  1280. struct v4l2_ext_controls *p = arg;
  1281. if (vfd->vidioc_try_ext_ctrls) {
  1282. dbgarg(cmd, "count=%d\n", p->count);
  1283. ret=vfd->vidioc_try_ext_ctrls(file, fh, p);
  1284. }
  1285. break;
  1286. }
  1287. case VIDIOC_QUERYMENU:
  1288. {
  1289. struct v4l2_querymenu *p=arg;
  1290. if (!vfd->vidioc_querymenu)
  1291. break;
  1292. ret=vfd->vidioc_querymenu(file, fh, p);
  1293. if (!ret)
  1294. dbgarg (cmd, "id=%d, index=%d, name=%s\n",
  1295. p->id,p->index,p->name);
  1296. break;
  1297. }
  1298. /* --- audio ---------------------------------------------- */
  1299. case VIDIOC_ENUMAUDIO:
  1300. {
  1301. struct v4l2_audio *p=arg;
  1302. if (!vfd->vidioc_enumaudio)
  1303. break;
  1304. dbgarg(cmd, "Enum for index=%d\n", p->index);
  1305. ret=vfd->vidioc_enumaudio(file, fh, p);
  1306. if (!ret)
  1307. dbgarg2("index=%d, name=%s, capability=%d, "
  1308. "mode=%d\n",p->index,p->name,
  1309. p->capability, p->mode);
  1310. break;
  1311. }
  1312. case VIDIOC_G_AUDIO:
  1313. {
  1314. struct v4l2_audio *p=arg;
  1315. __u32 index=p->index;
  1316. if (!vfd->vidioc_g_audio)
  1317. break;
  1318. memset(p,0,sizeof(*p));
  1319. p->index=index;
  1320. dbgarg(cmd, "Get for index=%d\n", p->index);
  1321. ret=vfd->vidioc_g_audio(file, fh, p);
  1322. if (!ret)
  1323. dbgarg2("index=%d, name=%s, capability=%d, "
  1324. "mode=%d\n",p->index,
  1325. p->name,p->capability, p->mode);
  1326. break;
  1327. }
  1328. case VIDIOC_S_AUDIO:
  1329. {
  1330. struct v4l2_audio *p=arg;
  1331. if (!vfd->vidioc_s_audio)
  1332. break;
  1333. dbgarg(cmd, "index=%d, name=%s, capability=%d, "
  1334. "mode=%d\n", p->index, p->name,
  1335. p->capability, p->mode);
  1336. ret=vfd->vidioc_s_audio(file, fh, p);
  1337. break;
  1338. }
  1339. case VIDIOC_ENUMAUDOUT:
  1340. {
  1341. struct v4l2_audioout *p=arg;
  1342. if (!vfd->vidioc_enumaudout)
  1343. break;
  1344. dbgarg(cmd, "Enum for index=%d\n", p->index);
  1345. ret=vfd->vidioc_enumaudout(file, fh, p);
  1346. if (!ret)
  1347. dbgarg2("index=%d, name=%s, capability=%d, "
  1348. "mode=%d\n", p->index, p->name,
  1349. p->capability,p->mode);
  1350. break;
  1351. }
  1352. case VIDIOC_G_AUDOUT:
  1353. {
  1354. struct v4l2_audioout *p=arg;
  1355. if (!vfd->vidioc_g_audout)
  1356. break;
  1357. dbgarg(cmd, "Enum for index=%d\n", p->index);
  1358. ret=vfd->vidioc_g_audout(file, fh, p);
  1359. if (!ret)
  1360. dbgarg2("index=%d, name=%s, capability=%d, "
  1361. "mode=%d\n", p->index, p->name,
  1362. p->capability,p->mode);
  1363. break;
  1364. }
  1365. case VIDIOC_S_AUDOUT:
  1366. {
  1367. struct v4l2_audioout *p=arg;
  1368. if (!vfd->vidioc_s_audout)
  1369. break;
  1370. dbgarg(cmd, "index=%d, name=%s, capability=%d, "
  1371. "mode=%d\n", p->index, p->name,
  1372. p->capability,p->mode);
  1373. ret=vfd->vidioc_s_audout(file, fh, p);
  1374. break;
  1375. }
  1376. case VIDIOC_G_MODULATOR:
  1377. {
  1378. struct v4l2_modulator *p=arg;
  1379. if (!vfd->vidioc_g_modulator)
  1380. break;
  1381. ret=vfd->vidioc_g_modulator(file, fh, p);
  1382. if (!ret)
  1383. dbgarg(cmd, "index=%d, name=%s, "
  1384. "capability=%d, rangelow=%d,"
  1385. " rangehigh=%d, txsubchans=%d\n",
  1386. p->index, p->name,p->capability,
  1387. p->rangelow, p->rangehigh,
  1388. p->txsubchans);
  1389. break;
  1390. }
  1391. case VIDIOC_S_MODULATOR:
  1392. {
  1393. struct v4l2_modulator *p=arg;
  1394. if (!vfd->vidioc_s_modulator)
  1395. break;
  1396. dbgarg(cmd, "index=%d, name=%s, capability=%d, "
  1397. "rangelow=%d, rangehigh=%d, txsubchans=%d\n",
  1398. p->index, p->name,p->capability,p->rangelow,
  1399. p->rangehigh,p->txsubchans);
  1400. ret=vfd->vidioc_s_modulator(file, fh, p);
  1401. break;
  1402. }
  1403. case VIDIOC_G_CROP:
  1404. {
  1405. struct v4l2_crop *p=arg;
  1406. if (!vfd->vidioc_g_crop)
  1407. break;
  1408. ret=vfd->vidioc_g_crop(file, fh, p);
  1409. if (!ret) {
  1410. dbgarg(cmd, "type=%d\n", p->type);
  1411. dbgrect(vfd, "", &p->c);
  1412. }
  1413. break;
  1414. }
  1415. case VIDIOC_S_CROP:
  1416. {
  1417. struct v4l2_crop *p=arg;
  1418. if (!vfd->vidioc_s_crop)
  1419. break;
  1420. dbgarg(cmd, "type=%d\n", p->type);
  1421. dbgrect(vfd, "", &p->c);
  1422. ret=vfd->vidioc_s_crop(file, fh, p);
  1423. break;
  1424. }
  1425. case VIDIOC_CROPCAP:
  1426. {
  1427. struct v4l2_cropcap *p=arg;
  1428. /*FIXME: Should also show v4l2_fract pixelaspect */
  1429. if (!vfd->vidioc_cropcap)
  1430. break;
  1431. dbgarg(cmd, "type=%d\n", p->type);
  1432. dbgrect(vfd, "bounds ", &p->bounds);
  1433. dbgrect(vfd, "defrect ", &p->defrect);
  1434. ret=vfd->vidioc_cropcap(file, fh, p);
  1435. break;
  1436. }
  1437. case VIDIOC_G_JPEGCOMP:
  1438. {
  1439. struct v4l2_jpegcompression *p=arg;
  1440. if (!vfd->vidioc_g_jpegcomp)
  1441. break;
  1442. ret=vfd->vidioc_g_jpegcomp(file, fh, p);
  1443. if (!ret)
  1444. dbgarg (cmd, "quality=%d, APPn=%d, "
  1445. "APP_len=%d, COM_len=%d, "
  1446. "jpeg_markers=%d\n",
  1447. p->quality,p->APPn,p->APP_len,
  1448. p->COM_len,p->jpeg_markers);
  1449. break;
  1450. }
  1451. case VIDIOC_S_JPEGCOMP:
  1452. {
  1453. struct v4l2_jpegcompression *p=arg;
  1454. if (!vfd->vidioc_g_jpegcomp)
  1455. break;
  1456. dbgarg (cmd, "quality=%d, APPn=%d, APP_len=%d, "
  1457. "COM_len=%d, jpeg_markers=%d\n",
  1458. p->quality,p->APPn,p->APP_len,
  1459. p->COM_len,p->jpeg_markers);
  1460. ret=vfd->vidioc_s_jpegcomp(file, fh, p);
  1461. break;
  1462. }
  1463. case VIDIOC_G_ENC_INDEX:
  1464. {
  1465. struct v4l2_enc_idx *p=arg;
  1466. if (!vfd->vidioc_g_enc_index)
  1467. break;
  1468. ret=vfd->vidioc_g_enc_index(file, fh, p);
  1469. if (!ret)
  1470. dbgarg (cmd, "entries=%d, entries_cap=%d\n",
  1471. p->entries,p->entries_cap);
  1472. break;
  1473. }
  1474. case VIDIOC_ENCODER_CMD:
  1475. {
  1476. struct v4l2_encoder_cmd *p=arg;
  1477. if (!vfd->vidioc_encoder_cmd)
  1478. break;
  1479. ret=vfd->vidioc_encoder_cmd(file, fh, p);
  1480. if (!ret)
  1481. dbgarg (cmd, "cmd=%d, flags=%d\n",
  1482. p->cmd,p->flags);
  1483. break;
  1484. }
  1485. case VIDIOC_TRY_ENCODER_CMD:
  1486. {
  1487. struct v4l2_encoder_cmd *p=arg;
  1488. if (!vfd->vidioc_try_encoder_cmd)
  1489. break;
  1490. ret=vfd->vidioc_try_encoder_cmd(file, fh, p);
  1491. if (!ret)
  1492. dbgarg (cmd, "cmd=%d, flags=%d\n",
  1493. p->cmd,p->flags);
  1494. break;
  1495. }
  1496. case VIDIOC_G_PARM:
  1497. {
  1498. struct v4l2_streamparm *p=arg;
  1499. __u32 type=p->type;
  1500. memset(p,0,sizeof(*p));
  1501. p->type=type;
  1502. if (vfd->vidioc_g_parm) {
  1503. ret=vfd->vidioc_g_parm(file, fh, p);
  1504. } else {
  1505. struct v4l2_standard s;
  1506. if (p->type != V4L2_BUF_TYPE_VIDEO_CAPTURE)
  1507. return -EINVAL;
  1508. v4l2_video_std_construct(&s, vfd->current_norm,
  1509. v4l2_norm_to_name(vfd->current_norm));
  1510. p->parm.capture.timeperframe = s.frameperiod;
  1511. ret=0;
  1512. }
  1513. dbgarg (cmd, "type=%d\n", p->type);
  1514. break;
  1515. }
  1516. case VIDIOC_S_PARM:
  1517. {
  1518. struct v4l2_streamparm *p=arg;
  1519. if (!vfd->vidioc_s_parm)
  1520. break;
  1521. dbgarg (cmd, "type=%d\n", p->type);
  1522. ret=vfd->vidioc_s_parm(file, fh, p);
  1523. break;
  1524. }
  1525. case VIDIOC_G_TUNER:
  1526. {
  1527. struct v4l2_tuner *p=arg;
  1528. __u32 index=p->index;
  1529. if (!vfd->vidioc_g_tuner)
  1530. break;
  1531. memset(p,0,sizeof(*p));
  1532. p->index=index;
  1533. ret=vfd->vidioc_g_tuner(file, fh, p);
  1534. if (!ret)
  1535. dbgarg (cmd, "index=%d, name=%s, type=%d, "
  1536. "capability=%d, rangelow=%d, "
  1537. "rangehigh=%d, signal=%d, afc=%d, "
  1538. "rxsubchans=%d, audmode=%d\n",
  1539. p->index, p->name, p->type,
  1540. p->capability, p->rangelow,
  1541. p->rangehigh, p->rxsubchans,
  1542. p->audmode, p->signal, p->afc);
  1543. break;
  1544. }
  1545. case VIDIOC_S_TUNER:
  1546. {
  1547. struct v4l2_tuner *p=arg;
  1548. if (!vfd->vidioc_s_tuner)
  1549. break;
  1550. dbgarg (cmd, "index=%d, name=%s, type=%d, "
  1551. "capability=%d, rangelow=%d, rangehigh=%d, "
  1552. "signal=%d, afc=%d, rxsubchans=%d, "
  1553. "audmode=%d\n",p->index, p->name, p->type,
  1554. p->capability, p->rangelow,p->rangehigh,
  1555. p->rxsubchans, p->audmode, p->signal,
  1556. p->afc);
  1557. ret=vfd->vidioc_s_tuner(file, fh, p);
  1558. break;
  1559. }
  1560. case VIDIOC_G_FREQUENCY:
  1561. {
  1562. struct v4l2_frequency *p = arg;
  1563. if (!vfd->vidioc_g_frequency)
  1564. break;
  1565. memset(p->reserved, 0, sizeof(p->reserved));
  1566. ret = vfd->vidioc_g_frequency(file, fh, p);
  1567. if (!ret)
  1568. dbgarg(cmd, "tuner=%d, type=%d, frequency=%d\n",
  1569. p->tuner, p->type, p->frequency);
  1570. break;
  1571. }
  1572. case VIDIOC_S_FREQUENCY:
  1573. {
  1574. struct v4l2_frequency *p=arg;
  1575. if (!vfd->vidioc_s_frequency)
  1576. break;
  1577. dbgarg (cmd, "tuner=%d, type=%d, frequency=%d\n",
  1578. p->tuner,p->type,p->frequency);
  1579. ret=vfd->vidioc_s_frequency(file, fh, p);
  1580. break;
  1581. }
  1582. case VIDIOC_G_SLICED_VBI_CAP:
  1583. {
  1584. struct v4l2_sliced_vbi_cap *p=arg;
  1585. if (!vfd->vidioc_g_sliced_vbi_cap)
  1586. break;
  1587. ret=vfd->vidioc_g_sliced_vbi_cap(file, fh, p);
  1588. if (!ret)
  1589. dbgarg (cmd, "service_set=%d\n", p->service_set);
  1590. break;
  1591. }
  1592. case VIDIOC_LOG_STATUS:
  1593. {
  1594. if (!vfd->vidioc_log_status)
  1595. break;
  1596. ret=vfd->vidioc_log_status(file, fh);
  1597. break;
  1598. }
  1599. #ifdef CONFIG_VIDEO_ADV_DEBUG
  1600. case VIDIOC_DBG_G_REGISTER:
  1601. {
  1602. struct v4l2_register *p=arg;
  1603. if (!capable(CAP_SYS_ADMIN))
  1604. ret=-EPERM;
  1605. else if (vfd->vidioc_g_register)
  1606. ret=vfd->vidioc_g_register(file, fh, p);
  1607. break;
  1608. }
  1609. case VIDIOC_DBG_S_REGISTER:
  1610. {
  1611. struct v4l2_register *p=arg;
  1612. if (!capable(CAP_SYS_ADMIN))
  1613. ret=-EPERM;
  1614. else if (vfd->vidioc_s_register)
  1615. ret=vfd->vidioc_s_register(file, fh, p);
  1616. break;
  1617. }
  1618. #endif
  1619. case VIDIOC_G_CHIP_IDENT:
  1620. {
  1621. struct v4l2_chip_ident *p=arg;
  1622. if (!vfd->vidioc_g_chip_ident)
  1623. break;
  1624. ret=vfd->vidioc_g_chip_ident(file, fh, p);
  1625. if (!ret)
  1626. dbgarg (cmd, "chip_ident=%u, revision=0x%x\n", p->ident, p->revision);
  1627. break;
  1628. }
  1629. default:
  1630. {
  1631. if (!vfd->vidioc_default)
  1632. break;
  1633. ret = vfd->vidioc_default(file, fh, cmd, arg);
  1634. break;
  1635. }
  1636. case VIDIOC_S_HW_FREQ_SEEK:
  1637. {
  1638. struct v4l2_hw_freq_seek *p = arg;
  1639. if (!vfd->vidioc_s_hw_freq_seek)
  1640. break;
  1641. dbgarg(cmd,
  1642. "tuner=%d, type=%d, seek_upward=%d, wrap_around=%d\n",
  1643. p->tuner, p->type, p->seek_upward, p->wrap_around);
  1644. ret = vfd->vidioc_s_hw_freq_seek(file, fh, p);
  1645. break;
  1646. }
  1647. } /* switch */
  1648. if (vfd->debug & V4L2_DEBUG_IOCTL_ARG) {
  1649. if (ret<0) {
  1650. printk("%s: err: on ", vfd->name);
  1651. v4l_print_ioctl(vfd->name, cmd);
  1652. printk("\n");
  1653. }
  1654. }
  1655. return ret;
  1656. }
  1657. int video_ioctl2 (struct inode *inode, struct file *file,
  1658. unsigned int cmd, unsigned long arg)
  1659. {
  1660. char sbuf[128];
  1661. void *mbuf = NULL;
  1662. void *parg = NULL;
  1663. int err = -EINVAL;
  1664. int is_ext_ctrl;
  1665. size_t ctrls_size = 0;
  1666. void __user *user_ptr = NULL;
  1667. #ifdef __OLD_VIDIOC_
  1668. cmd = video_fix_command(cmd);
  1669. #endif
  1670. is_ext_ctrl = (cmd == VIDIOC_S_EXT_CTRLS || cmd == VIDIOC_G_EXT_CTRLS ||
  1671. cmd == VIDIOC_TRY_EXT_CTRLS);
  1672. /* Copy arguments into temp kernel buffer */
  1673. switch (_IOC_DIR(cmd)) {
  1674. case _IOC_NONE:
  1675. parg = NULL;
  1676. break;
  1677. case _IOC_READ:
  1678. case _IOC_WRITE:
  1679. case (_IOC_WRITE | _IOC_READ):
  1680. if (_IOC_SIZE(cmd) <= sizeof(sbuf)) {
  1681. parg = sbuf;
  1682. } else {
  1683. /* too big to allocate from stack */
  1684. mbuf = kmalloc(_IOC_SIZE(cmd),GFP_KERNEL);
  1685. if (NULL == mbuf)
  1686. return -ENOMEM;
  1687. parg = mbuf;
  1688. }
  1689. err = -EFAULT;
  1690. if (_IOC_DIR(cmd) & _IOC_WRITE)
  1691. if (copy_from_user(parg, (void __user *)arg, _IOC_SIZE(cmd)))
  1692. goto out;
  1693. break;
  1694. }
  1695. if (is_ext_ctrl) {
  1696. struct v4l2_ext_controls *p = parg;
  1697. /* In case of an error, tell the caller that it wasn't
  1698. a specific control that caused it. */
  1699. p->error_idx = p->count;
  1700. user_ptr = (void __user *)p->controls;
  1701. if (p->count) {
  1702. ctrls_size = sizeof(struct v4l2_ext_control) * p->count;
  1703. /* Note: v4l2_ext_controls fits in sbuf[] so mbuf is still NULL. */
  1704. mbuf = kmalloc(ctrls_size, GFP_KERNEL);
  1705. err = -ENOMEM;
  1706. if (NULL == mbuf)
  1707. goto out_ext_ctrl;
  1708. err = -EFAULT;
  1709. if (copy_from_user(mbuf, user_ptr, ctrls_size))
  1710. goto out_ext_ctrl;
  1711. p->controls = mbuf;
  1712. }
  1713. }
  1714. /* Handles IOCTL */
  1715. err = __video_do_ioctl(inode, file, cmd, parg);
  1716. if (err == -ENOIOCTLCMD)
  1717. err = -EINVAL;
  1718. if (is_ext_ctrl) {
  1719. struct v4l2_ext_controls *p = parg;
  1720. p->controls = (void *)user_ptr;
  1721. if (p->count && err == 0 && copy_to_user(user_ptr, mbuf, ctrls_size))
  1722. err = -EFAULT;
  1723. goto out_ext_ctrl;
  1724. }
  1725. if (err < 0)
  1726. goto out;
  1727. out_ext_ctrl:
  1728. /* Copy results into user buffer */
  1729. switch (_IOC_DIR(cmd))
  1730. {
  1731. case _IOC_READ:
  1732. case (_IOC_WRITE | _IOC_READ):
  1733. if (copy_to_user((void __user *)arg, parg, _IOC_SIZE(cmd)))
  1734. err = -EFAULT;
  1735. break;
  1736. }
  1737. out:
  1738. kfree(mbuf);
  1739. return err;
  1740. }
  1741. EXPORT_SYMBOL(video_ioctl2);
  1742. struct index_info {
  1743. struct device *dev;
  1744. unsigned int used[VIDEO_NUM_DEVICES];
  1745. };
  1746. static int __fill_index_info(struct device *cd, void *data)
  1747. {
  1748. struct index_info *info = data;
  1749. struct video_device *vfd = container_of(cd, struct video_device,
  1750. class_dev);
  1751. if (info->dev == vfd->dev)
  1752. info->used[vfd->index] = 1;
  1753. return 0;
  1754. }
  1755. /**
  1756. * assign_index - assign stream number based on parent device
  1757. * @vdev: video_device to assign index number to, vdev->dev should be assigned
  1758. * @num: -1 if auto assign, requested number otherwise
  1759. *
  1760. *
  1761. * returns -ENFILE if num is already in use, a free index number if
  1762. * successful.
  1763. */
  1764. static int get_index(struct video_device *vdev, int num)
  1765. {
  1766. struct index_info *info;
  1767. int i;
  1768. int ret = 0;
  1769. if (num >= VIDEO_NUM_DEVICES)
  1770. return -EINVAL;
  1771. info = kzalloc(sizeof(*info), GFP_KERNEL);
  1772. if (!info)
  1773. return -ENOMEM;
  1774. info->dev = vdev->dev;
  1775. ret = class_for_each_device(&video_class, info,
  1776. __fill_index_info);
  1777. if (ret < 0)
  1778. goto out;
  1779. if (num >= 0) {
  1780. if (!info->used[num])
  1781. ret = num;
  1782. else
  1783. ret = -ENFILE;
  1784. goto out;
  1785. }
  1786. for (i = 0; i < VIDEO_NUM_DEVICES; i++) {
  1787. if (info->used[i])
  1788. continue;
  1789. ret = i;
  1790. goto out;
  1791. }
  1792. out:
  1793. kfree(info);
  1794. return ret;
  1795. }
  1796. static const struct file_operations video_fops;
  1797. int video_register_device(struct video_device *vfd, int type, int nr)
  1798. {
  1799. return video_register_device_index(vfd, type, nr, -1);
  1800. }
  1801. EXPORT_SYMBOL(video_register_device);
  1802. /**
  1803. * video_register_device - register video4linux devices
  1804. * @vfd: video device structure we want to register
  1805. * @type: type of device to register
  1806. * @nr: which device number (0 == /dev/video0, 1 == /dev/video1, ...
  1807. * -1 == first free)
  1808. *
  1809. * The registration code assigns minor numbers based on the type
  1810. * requested. -ENFILE is returned in all the device slots for this
  1811. * category are full. If not then the minor field is set and the
  1812. * driver initialize function is called (if non %NULL).
  1813. *
  1814. * Zero is returned on success.
  1815. *
  1816. * Valid types are
  1817. *
  1818. * %VFL_TYPE_GRABBER - A frame grabber
  1819. *
  1820. * %VFL_TYPE_VTX - A teletext device
  1821. *
  1822. * %VFL_TYPE_VBI - Vertical blank data (undecoded)
  1823. *
  1824. * %VFL_TYPE_RADIO - A radio card
  1825. */
  1826. int video_register_device_index(struct video_device *vfd, int type, int nr,
  1827. int index)
  1828. {
  1829. int i=0;
  1830. int base;
  1831. int end;
  1832. int ret;
  1833. char *name_base;
  1834. switch(type)
  1835. {
  1836. case VFL_TYPE_GRABBER:
  1837. base=MINOR_VFL_TYPE_GRABBER_MIN;
  1838. end=MINOR_VFL_TYPE_GRABBER_MAX+1;
  1839. name_base = "video";
  1840. break;
  1841. case VFL_TYPE_VTX:
  1842. base=MINOR_VFL_TYPE_VTX_MIN;
  1843. end=MINOR_VFL_TYPE_VTX_MAX+1;
  1844. name_base = "vtx";
  1845. break;
  1846. case VFL_TYPE_VBI:
  1847. base=MINOR_VFL_TYPE_VBI_MIN;
  1848. end=MINOR_VFL_TYPE_VBI_MAX+1;
  1849. name_base = "vbi";
  1850. break;
  1851. case VFL_TYPE_RADIO:
  1852. base=MINOR_VFL_TYPE_RADIO_MIN;
  1853. end=MINOR_VFL_TYPE_RADIO_MAX+1;
  1854. name_base = "radio";
  1855. break;
  1856. default:
  1857. printk(KERN_ERR "%s called with unknown type: %d\n",
  1858. __func__, type);
  1859. return -1;
  1860. }
  1861. /* pick a minor number */
  1862. mutex_lock(&videodev_lock);
  1863. if (nr >= 0 && nr < end-base) {
  1864. /* use the one the driver asked for */
  1865. i = base+nr;
  1866. if (NULL != video_device[i]) {
  1867. mutex_unlock(&videodev_lock);
  1868. return -ENFILE;
  1869. }
  1870. } else {
  1871. /* use first free */
  1872. for(i=base;i<end;i++)
  1873. if (NULL == video_device[i])
  1874. break;
  1875. if (i == end) {
  1876. mutex_unlock(&videodev_lock);
  1877. return -ENFILE;
  1878. }
  1879. }
  1880. video_device[i]=vfd;
  1881. vfd->minor=i;
  1882. ret = get_index(vfd, index);
  1883. if (ret < 0) {
  1884. printk(KERN_ERR "%s: get_index failed\n",
  1885. __func__);
  1886. goto fail_minor;
  1887. }
  1888. vfd->index = ret;
  1889. mutex_unlock(&videodev_lock);
  1890. mutex_init(&vfd->lock);
  1891. /* sysfs class */
  1892. memset(&vfd->class_dev, 0x00, sizeof(vfd->class_dev));
  1893. if (vfd->dev)
  1894. vfd->class_dev.parent = vfd->dev;
  1895. vfd->class_dev.class = &video_class;
  1896. vfd->class_dev.devt = MKDEV(VIDEO_MAJOR, vfd->minor);
  1897. sprintf(vfd->class_dev.bus_id, "%s%d", name_base, i - base);
  1898. ret = device_register(&vfd->class_dev);
  1899. if (ret < 0) {
  1900. printk(KERN_ERR "%s: device_register failed\n",
  1901. __func__);
  1902. goto fail_minor;
  1903. }
  1904. #if 1
  1905. /* needed until all drivers are fixed */
  1906. if (!vfd->release)
  1907. printk(KERN_WARNING "videodev: \"%s\" has no release callback. "
  1908. "Please fix your driver for proper sysfs support, see "
  1909. "http://lwn.net/Articles/36850/\n", vfd->name);
  1910. #endif
  1911. return 0;
  1912. fail_minor:
  1913. mutex_lock(&videodev_lock);
  1914. video_device[vfd->minor] = NULL;
  1915. vfd->minor = -1;
  1916. mutex_unlock(&videodev_lock);
  1917. return ret;
  1918. }
  1919. EXPORT_SYMBOL(video_register_device_index);
  1920. /**
  1921. * video_unregister_device - unregister a video4linux device
  1922. * @vfd: the device to unregister
  1923. *
  1924. * This unregisters the passed device and deassigns the minor
  1925. * number. Future open calls will be met with errors.
  1926. */
  1927. void video_unregister_device(struct video_device *vfd)
  1928. {
  1929. mutex_lock(&videodev_lock);
  1930. if(video_device[vfd->minor]!=vfd)
  1931. panic("videodev: bad unregister");
  1932. video_device[vfd->minor]=NULL;
  1933. device_unregister(&vfd->class_dev);
  1934. mutex_unlock(&videodev_lock);
  1935. }
  1936. EXPORT_SYMBOL(video_unregister_device);
  1937. /*
  1938. * Video fs operations
  1939. */
  1940. static const struct file_operations video_fops=
  1941. {
  1942. .owner = THIS_MODULE,
  1943. .llseek = no_llseek,
  1944. .open = video_open,
  1945. };
  1946. /*
  1947. * Initialise video for linux
  1948. */
  1949. static int __init videodev_init(void)
  1950. {
  1951. int ret;
  1952. printk(KERN_INFO "Linux video capture interface: v2.00\n");
  1953. if (register_chrdev(VIDEO_MAJOR, VIDEO_NAME, &video_fops)) {
  1954. printk(KERN_WARNING "video_dev: unable to get major %d\n", VIDEO_MAJOR);
  1955. return -EIO;
  1956. }
  1957. ret = class_register(&video_class);
  1958. if (ret < 0) {
  1959. unregister_chrdev(VIDEO_MAJOR, VIDEO_NAME);
  1960. printk(KERN_WARNING "video_dev: class_register failed\n");
  1961. return -EIO;
  1962. }
  1963. return 0;
  1964. }
  1965. static void __exit videodev_exit(void)
  1966. {
  1967. class_unregister(&video_class);
  1968. unregister_chrdev(VIDEO_MAJOR, VIDEO_NAME);
  1969. }
  1970. module_init(videodev_init)
  1971. module_exit(videodev_exit)
  1972. MODULE_AUTHOR("Alan Cox, Mauro Carvalho Chehab <mchehab@infradead.org>");
  1973. MODULE_DESCRIPTION("Device registrar for Video4Linux drivers v2");
  1974. MODULE_LICENSE("GPL");
  1975. /*
  1976. * Local variables:
  1977. * c-basic-offset: 8
  1978. * End:
  1979. */