v4l2-ioctl.c 54 KB

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