videodev.c 55 KB

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