videodev.c 55 KB

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