videodev.c 55 KB

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