videodev.c 55 KB

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