videodev.c 53 KB

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