videodev.c 56 KB

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