videodev.c 53 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075
  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_cap)
  623. return (0);
  624. break;
  625. case V4L2_BUF_TYPE_VIDEO_OVERLAY:
  626. if (vfd->vidioc_try_fmt_overlay)
  627. return (0);
  628. break;
  629. case V4L2_BUF_TYPE_VBI_CAPTURE:
  630. if (vfd->vidioc_try_fmt_vbi)
  631. return (0);
  632. break;
  633. case V4L2_BUF_TYPE_SLICED_VBI_OUTPUT:
  634. if (vfd->vidioc_try_fmt_vbi_output)
  635. return (0);
  636. break;
  637. case V4L2_BUF_TYPE_SLICED_VBI_CAPTURE:
  638. if (vfd->vidioc_try_fmt_vbi_capture)
  639. return (0);
  640. break;
  641. case V4L2_BUF_TYPE_VIDEO_OUTPUT:
  642. if (vfd->vidioc_try_fmt_video_output)
  643. return (0);
  644. break;
  645. case V4L2_BUF_TYPE_VBI_OUTPUT:
  646. if (vfd->vidioc_try_fmt_vbi_output)
  647. return (0);
  648. break;
  649. case V4L2_BUF_TYPE_VIDEO_OUTPUT_OVERLAY:
  650. if (vfd->vidioc_try_fmt_output_overlay)
  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_cap)
  752. ret=vfd->vidioc_enum_fmt_cap(file, fh, f);
  753. break;
  754. case V4L2_BUF_TYPE_VIDEO_OVERLAY:
  755. if (vfd->vidioc_enum_fmt_overlay)
  756. ret=vfd->vidioc_enum_fmt_overlay(file, fh, f);
  757. break;
  758. case V4L2_BUF_TYPE_VBI_CAPTURE:
  759. if (vfd->vidioc_enum_fmt_vbi)
  760. ret=vfd->vidioc_enum_fmt_vbi(file, fh, f);
  761. break;
  762. case V4L2_BUF_TYPE_SLICED_VBI_OUTPUT:
  763. if (vfd->vidioc_enum_fmt_vbi_output)
  764. ret=vfd->vidioc_enum_fmt_vbi_output(file,
  765. fh, f);
  766. break;
  767. case V4L2_BUF_TYPE_SLICED_VBI_CAPTURE:
  768. if (vfd->vidioc_enum_fmt_vbi_capture)
  769. ret=vfd->vidioc_enum_fmt_vbi_capture(file,
  770. fh, f);
  771. break;
  772. case V4L2_BUF_TYPE_VIDEO_OUTPUT:
  773. if (vfd->vidioc_enum_fmt_video_output)
  774. ret=vfd->vidioc_enum_fmt_video_output(file,
  775. fh, f);
  776. break;
  777. case V4L2_BUF_TYPE_VBI_OUTPUT:
  778. if (vfd->vidioc_enum_fmt_vbi_output)
  779. ret=vfd->vidioc_enum_fmt_vbi_output(file,
  780. fh, f);
  781. break;
  782. case V4L2_BUF_TYPE_VIDEO_OUTPUT_OVERLAY:
  783. if (vfd->vidioc_enum_fmt_output_overlay)
  784. ret=vfd->vidioc_enum_fmt_output_overlay(file, fh, f);
  785. break;
  786. case V4L2_BUF_TYPE_PRIVATE:
  787. if (vfd->vidioc_enum_fmt_type_private)
  788. ret=vfd->vidioc_enum_fmt_type_private(file,
  789. fh, f);
  790. break;
  791. }
  792. if (!ret)
  793. dbgarg (cmd, "index=%d, type=%d, flags=%d, "
  794. "pixelformat=%c%c%c%c, description='%s'\n",
  795. f->index, f->type, f->flags,
  796. (f->pixelformat & 0xff),
  797. (f->pixelformat >> 8) & 0xff,
  798. (f->pixelformat >> 16) & 0xff,
  799. (f->pixelformat >> 24) & 0xff,
  800. f->description);
  801. break;
  802. }
  803. case VIDIOC_G_FMT:
  804. {
  805. struct v4l2_format *f = (struct v4l2_format *)arg;
  806. memset(f->fmt.raw_data, 0, sizeof(f->fmt.raw_data));
  807. /* FIXME: Should be one dump per type */
  808. dbgarg(cmd, "type=%s\n", prt_names(f->type, v4l2_type_names));
  809. switch (f->type) {
  810. case V4L2_BUF_TYPE_VIDEO_CAPTURE:
  811. if (vfd->vidioc_g_fmt_cap)
  812. ret=vfd->vidioc_g_fmt_cap(file, fh, f);
  813. if (!ret)
  814. v4l_print_pix_fmt(vfd,&f->fmt.pix);
  815. break;
  816. case V4L2_BUF_TYPE_VIDEO_OVERLAY:
  817. if (vfd->vidioc_g_fmt_overlay)
  818. ret=vfd->vidioc_g_fmt_overlay(file, fh, f);
  819. break;
  820. case V4L2_BUF_TYPE_VBI_CAPTURE:
  821. if (vfd->vidioc_g_fmt_vbi)
  822. ret=vfd->vidioc_g_fmt_vbi(file, fh, f);
  823. break;
  824. case V4L2_BUF_TYPE_SLICED_VBI_OUTPUT:
  825. if (vfd->vidioc_g_fmt_vbi_output)
  826. ret=vfd->vidioc_g_fmt_vbi_output(file, fh, f);
  827. break;
  828. case V4L2_BUF_TYPE_SLICED_VBI_CAPTURE:
  829. if (vfd->vidioc_g_fmt_vbi_capture)
  830. ret=vfd->vidioc_g_fmt_vbi_capture(file, fh, f);
  831. break;
  832. case V4L2_BUF_TYPE_VIDEO_OUTPUT:
  833. if (vfd->vidioc_g_fmt_video_output)
  834. ret=vfd->vidioc_g_fmt_video_output(file,
  835. fh, f);
  836. break;
  837. case V4L2_BUF_TYPE_VIDEO_OUTPUT_OVERLAY:
  838. if (vfd->vidioc_g_fmt_output_overlay)
  839. ret=vfd->vidioc_g_fmt_output_overlay(file, fh, f);
  840. break;
  841. case V4L2_BUF_TYPE_VBI_OUTPUT:
  842. if (vfd->vidioc_g_fmt_vbi_output)
  843. ret=vfd->vidioc_g_fmt_vbi_output(file, fh, f);
  844. break;
  845. case V4L2_BUF_TYPE_PRIVATE:
  846. if (vfd->vidioc_g_fmt_type_private)
  847. ret=vfd->vidioc_g_fmt_type_private(file,
  848. fh, f);
  849. break;
  850. }
  851. break;
  852. }
  853. case VIDIOC_S_FMT:
  854. {
  855. struct v4l2_format *f = (struct v4l2_format *)arg;
  856. /* FIXME: Should be one dump per type */
  857. dbgarg (cmd, "type=%s\n", prt_names(f->type,
  858. v4l2_type_names));
  859. switch (f->type) {
  860. case V4L2_BUF_TYPE_VIDEO_CAPTURE:
  861. v4l_print_pix_fmt(vfd,&f->fmt.pix);
  862. if (vfd->vidioc_s_fmt_cap)
  863. ret=vfd->vidioc_s_fmt_cap(file, fh, f);
  864. break;
  865. case V4L2_BUF_TYPE_VIDEO_OVERLAY:
  866. if (vfd->vidioc_s_fmt_overlay)
  867. ret=vfd->vidioc_s_fmt_overlay(file, fh, f);
  868. break;
  869. case V4L2_BUF_TYPE_VBI_CAPTURE:
  870. if (vfd->vidioc_s_fmt_vbi)
  871. ret=vfd->vidioc_s_fmt_vbi(file, fh, f);
  872. break;
  873. case V4L2_BUF_TYPE_SLICED_VBI_OUTPUT:
  874. if (vfd->vidioc_s_fmt_vbi_output)
  875. ret=vfd->vidioc_s_fmt_vbi_output(file, fh, f);
  876. break;
  877. case V4L2_BUF_TYPE_SLICED_VBI_CAPTURE:
  878. if (vfd->vidioc_s_fmt_vbi_capture)
  879. ret=vfd->vidioc_s_fmt_vbi_capture(file, fh, f);
  880. break;
  881. case V4L2_BUF_TYPE_VIDEO_OUTPUT:
  882. if (vfd->vidioc_s_fmt_video_output)
  883. ret=vfd->vidioc_s_fmt_video_output(file,
  884. fh, f);
  885. break;
  886. case V4L2_BUF_TYPE_VIDEO_OUTPUT_OVERLAY:
  887. if (vfd->vidioc_s_fmt_output_overlay)
  888. ret=vfd->vidioc_s_fmt_output_overlay(file, fh, f);
  889. break;
  890. case V4L2_BUF_TYPE_VBI_OUTPUT:
  891. if (vfd->vidioc_s_fmt_vbi_output)
  892. ret=vfd->vidioc_s_fmt_vbi_output(file,
  893. fh, f);
  894. break;
  895. case V4L2_BUF_TYPE_PRIVATE:
  896. if (vfd->vidioc_s_fmt_type_private)
  897. ret=vfd->vidioc_s_fmt_type_private(file,
  898. fh, f);
  899. break;
  900. }
  901. break;
  902. }
  903. case VIDIOC_TRY_FMT:
  904. {
  905. struct v4l2_format *f = (struct v4l2_format *)arg;
  906. /* FIXME: Should be one dump per type */
  907. dbgarg (cmd, "type=%s\n", prt_names(f->type,
  908. v4l2_type_names));
  909. switch (f->type) {
  910. case V4L2_BUF_TYPE_VIDEO_CAPTURE:
  911. if (vfd->vidioc_try_fmt_cap)
  912. ret=vfd->vidioc_try_fmt_cap(file, fh, f);
  913. if (!ret)
  914. v4l_print_pix_fmt(vfd,&f->fmt.pix);
  915. break;
  916. case V4L2_BUF_TYPE_VIDEO_OVERLAY:
  917. if (vfd->vidioc_try_fmt_overlay)
  918. ret=vfd->vidioc_try_fmt_overlay(file, fh, f);
  919. break;
  920. case V4L2_BUF_TYPE_VBI_CAPTURE:
  921. if (vfd->vidioc_try_fmt_vbi)
  922. ret=vfd->vidioc_try_fmt_vbi(file, fh, f);
  923. break;
  924. case V4L2_BUF_TYPE_SLICED_VBI_OUTPUT:
  925. if (vfd->vidioc_try_fmt_vbi_output)
  926. ret=vfd->vidioc_try_fmt_vbi_output(file,
  927. fh, f);
  928. break;
  929. case V4L2_BUF_TYPE_SLICED_VBI_CAPTURE:
  930. if (vfd->vidioc_try_fmt_vbi_capture)
  931. ret=vfd->vidioc_try_fmt_vbi_capture(file,
  932. fh, f);
  933. break;
  934. case V4L2_BUF_TYPE_VIDEO_OUTPUT:
  935. if (vfd->vidioc_try_fmt_video_output)
  936. ret=vfd->vidioc_try_fmt_video_output(file,
  937. fh, f);
  938. break;
  939. case V4L2_BUF_TYPE_VIDEO_OUTPUT_OVERLAY:
  940. if (vfd->vidioc_try_fmt_output_overlay)
  941. ret=vfd->vidioc_try_fmt_output_overlay(file, fh, f);
  942. break;
  943. case V4L2_BUF_TYPE_VBI_OUTPUT:
  944. if (vfd->vidioc_try_fmt_vbi_output)
  945. ret=vfd->vidioc_try_fmt_vbi_output(file,
  946. fh, f);
  947. break;
  948. case V4L2_BUF_TYPE_PRIVATE:
  949. if (vfd->vidioc_try_fmt_type_private)
  950. ret=vfd->vidioc_try_fmt_type_private(file,
  951. fh, f);
  952. break;
  953. }
  954. break;
  955. }
  956. /* FIXME: Those buf reqs could be handled here,
  957. with some changes on videobuf to allow its header to be included at
  958. videodev2.h or being merged at videodev2.
  959. */
  960. case VIDIOC_REQBUFS:
  961. {
  962. struct v4l2_requestbuffers *p=arg;
  963. if (!vfd->vidioc_reqbufs)
  964. break;
  965. ret = check_fmt (vfd, p->type);
  966. if (ret)
  967. break;
  968. ret=vfd->vidioc_reqbufs(file, fh, p);
  969. dbgarg (cmd, "count=%d, type=%s, memory=%s\n",
  970. p->count,
  971. prt_names(p->type, v4l2_type_names),
  972. prt_names(p->memory, v4l2_memory_names));
  973. break;
  974. }
  975. case VIDIOC_QUERYBUF:
  976. {
  977. struct v4l2_buffer *p=arg;
  978. if (!vfd->vidioc_querybuf)
  979. break;
  980. ret = check_fmt (vfd, p->type);
  981. if (ret)
  982. break;
  983. ret=vfd->vidioc_querybuf(file, fh, p);
  984. if (!ret)
  985. dbgbuf(cmd,vfd,p);
  986. break;
  987. }
  988. case VIDIOC_QBUF:
  989. {
  990. struct v4l2_buffer *p=arg;
  991. if (!vfd->vidioc_qbuf)
  992. break;
  993. ret = check_fmt (vfd, p->type);
  994. if (ret)
  995. break;
  996. ret=vfd->vidioc_qbuf(file, fh, p);
  997. if (!ret)
  998. dbgbuf(cmd,vfd,p);
  999. break;
  1000. }
  1001. case VIDIOC_DQBUF:
  1002. {
  1003. struct v4l2_buffer *p=arg;
  1004. if (!vfd->vidioc_dqbuf)
  1005. break;
  1006. ret = check_fmt (vfd, p->type);
  1007. if (ret)
  1008. break;
  1009. ret=vfd->vidioc_dqbuf(file, fh, p);
  1010. if (!ret)
  1011. dbgbuf(cmd,vfd,p);
  1012. break;
  1013. }
  1014. case VIDIOC_OVERLAY:
  1015. {
  1016. int *i = arg;
  1017. if (!vfd->vidioc_overlay)
  1018. break;
  1019. dbgarg (cmd, "value=%d\n",*i);
  1020. ret=vfd->vidioc_overlay(file, fh, *i);
  1021. break;
  1022. }
  1023. case VIDIOC_G_FBUF:
  1024. {
  1025. struct v4l2_framebuffer *p=arg;
  1026. if (!vfd->vidioc_g_fbuf)
  1027. break;
  1028. ret=vfd->vidioc_g_fbuf(file, fh, arg);
  1029. if (!ret) {
  1030. dbgarg (cmd, "capability=%d, flags=%d, base=0x%08lx\n",
  1031. p->capability,p->flags,
  1032. (unsigned long)p->base);
  1033. v4l_print_pix_fmt (vfd, &p->fmt);
  1034. }
  1035. break;
  1036. }
  1037. case VIDIOC_S_FBUF:
  1038. {
  1039. struct v4l2_framebuffer *p=arg;
  1040. if (!vfd->vidioc_s_fbuf)
  1041. break;
  1042. dbgarg (cmd, "capability=%d, flags=%d, base=0x%08lx\n",
  1043. p->capability,p->flags,(unsigned long)p->base);
  1044. v4l_print_pix_fmt (vfd, &p->fmt);
  1045. ret=vfd->vidioc_s_fbuf(file, fh, arg);
  1046. break;
  1047. }
  1048. case VIDIOC_STREAMON:
  1049. {
  1050. enum v4l2_buf_type i = *(int *)arg;
  1051. if (!vfd->vidioc_streamon)
  1052. break;
  1053. dbgarg(cmd, "type=%s\n", prt_names(i, v4l2_type_names));
  1054. ret=vfd->vidioc_streamon(file, fh,i);
  1055. break;
  1056. }
  1057. case VIDIOC_STREAMOFF:
  1058. {
  1059. enum v4l2_buf_type i = *(int *)arg;
  1060. if (!vfd->vidioc_streamoff)
  1061. break;
  1062. dbgarg(cmd, "type=%s\n", prt_names(i, v4l2_type_names));
  1063. ret=vfd->vidioc_streamoff(file, fh, i);
  1064. break;
  1065. }
  1066. /* ---------- tv norms ---------- */
  1067. case VIDIOC_ENUMSTD:
  1068. {
  1069. struct v4l2_standard *p = arg;
  1070. v4l2_std_id id = vfd->tvnorms, curr_id = 0;
  1071. unsigned int index = p->index, i, j = 0;
  1072. const char *descr = "";
  1073. /* Return norm array in a canonical way */
  1074. for (i = 0; i <= index && id; i++) {
  1075. /* last std value in the standards array is 0, so this
  1076. while always ends there since (id & 0) == 0. */
  1077. while ((id & standards[j].std) != standards[j].std)
  1078. j++;
  1079. curr_id = standards[j].std;
  1080. descr = standards[j].descr;
  1081. j++;
  1082. if (curr_id == 0)
  1083. break;
  1084. if (curr_id != V4L2_STD_PAL &&
  1085. curr_id != V4L2_STD_SECAM &&
  1086. curr_id != V4L2_STD_NTSC)
  1087. id &= ~curr_id;
  1088. }
  1089. if (i <= index)
  1090. return -EINVAL;
  1091. v4l2_video_std_construct(p, curr_id, descr);
  1092. p->index = index;
  1093. dbgarg(cmd, "index=%d, id=%Ld, name=%s, fps=%d/%d, "
  1094. "framelines=%d\n", p->index,
  1095. (unsigned long long)p->id, p->name,
  1096. p->frameperiod.numerator,
  1097. p->frameperiod.denominator,
  1098. p->framelines);
  1099. ret = 0;
  1100. break;
  1101. }
  1102. case VIDIOC_G_STD:
  1103. {
  1104. v4l2_std_id *id = arg;
  1105. *id = vfd->current_norm;
  1106. dbgarg (cmd, "value=%08Lx\n", (long long unsigned) *id);
  1107. ret=0;
  1108. break;
  1109. }
  1110. case VIDIOC_S_STD:
  1111. {
  1112. v4l2_std_id *id = arg,norm;
  1113. dbgarg (cmd, "value=%08Lx\n", (long long unsigned) *id);
  1114. norm = (*id) & vfd->tvnorms;
  1115. if ( vfd->tvnorms && !norm) /* Check if std is supported */
  1116. break;
  1117. /* Calls the specific handler */
  1118. if (vfd->vidioc_s_std)
  1119. ret=vfd->vidioc_s_std(file, fh, &norm);
  1120. else
  1121. ret=-EINVAL;
  1122. /* Updates standard information */
  1123. if (ret>=0)
  1124. vfd->current_norm=norm;
  1125. break;
  1126. }
  1127. case VIDIOC_QUERYSTD:
  1128. {
  1129. v4l2_std_id *p=arg;
  1130. if (!vfd->vidioc_querystd)
  1131. break;
  1132. ret=vfd->vidioc_querystd(file, fh, arg);
  1133. if (!ret)
  1134. dbgarg (cmd, "detected std=%08Lx\n",
  1135. (unsigned long long)*p);
  1136. break;
  1137. }
  1138. /* ------ input switching ---------- */
  1139. /* FIXME: Inputs can be handled inside videodev2 */
  1140. case VIDIOC_ENUMINPUT:
  1141. {
  1142. struct v4l2_input *p=arg;
  1143. int i=p->index;
  1144. if (!vfd->vidioc_enum_input)
  1145. break;
  1146. memset(p, 0, sizeof(*p));
  1147. p->index=i;
  1148. ret=vfd->vidioc_enum_input(file, fh, p);
  1149. if (!ret)
  1150. dbgarg (cmd, "index=%d, name=%s, type=%d, "
  1151. "audioset=%d, "
  1152. "tuner=%d, std=%08Lx, status=%d\n",
  1153. p->index,p->name,p->type,p->audioset,
  1154. p->tuner,
  1155. (unsigned long long)p->std,
  1156. p->status);
  1157. break;
  1158. }
  1159. case VIDIOC_G_INPUT:
  1160. {
  1161. unsigned int *i = arg;
  1162. if (!vfd->vidioc_g_input)
  1163. break;
  1164. ret=vfd->vidioc_g_input(file, fh, i);
  1165. if (!ret)
  1166. dbgarg (cmd, "value=%d\n",*i);
  1167. break;
  1168. }
  1169. case VIDIOC_S_INPUT:
  1170. {
  1171. unsigned int *i = arg;
  1172. if (!vfd->vidioc_s_input)
  1173. break;
  1174. dbgarg (cmd, "value=%d\n",*i);
  1175. ret=vfd->vidioc_s_input(file, fh, *i);
  1176. break;
  1177. }
  1178. /* ------ output switching ---------- */
  1179. case VIDIOC_G_OUTPUT:
  1180. {
  1181. unsigned int *i = arg;
  1182. if (!vfd->vidioc_g_output)
  1183. break;
  1184. ret=vfd->vidioc_g_output(file, fh, i);
  1185. if (!ret)
  1186. dbgarg (cmd, "value=%d\n",*i);
  1187. break;
  1188. }
  1189. case VIDIOC_S_OUTPUT:
  1190. {
  1191. unsigned int *i = arg;
  1192. if (!vfd->vidioc_s_output)
  1193. break;
  1194. dbgarg (cmd, "value=%d\n",*i);
  1195. ret=vfd->vidioc_s_output(file, fh, *i);
  1196. break;
  1197. }
  1198. /* --- controls ---------------------------------------------- */
  1199. case VIDIOC_QUERYCTRL:
  1200. {
  1201. struct v4l2_queryctrl *p=arg;
  1202. if (!vfd->vidioc_queryctrl)
  1203. break;
  1204. ret=vfd->vidioc_queryctrl(file, fh, p);
  1205. if (!ret)
  1206. dbgarg (cmd, "id=%d, type=%d, name=%s, "
  1207. "min/max=%d/%d,"
  1208. " step=%d, default=%d, flags=0x%08x\n",
  1209. p->id,p->type,p->name,p->minimum,
  1210. p->maximum,p->step,p->default_value,
  1211. p->flags);
  1212. break;
  1213. }
  1214. case VIDIOC_G_CTRL:
  1215. {
  1216. struct v4l2_control *p = arg;
  1217. if (!vfd->vidioc_g_ctrl)
  1218. break;
  1219. dbgarg(cmd, "Enum for index=%d\n", p->id);
  1220. ret=vfd->vidioc_g_ctrl(file, fh, p);
  1221. if (!ret)
  1222. dbgarg2 ( "id=%d, value=%d\n", p->id, p->value);
  1223. break;
  1224. }
  1225. case VIDIOC_S_CTRL:
  1226. {
  1227. struct v4l2_control *p = arg;
  1228. if (!vfd->vidioc_s_ctrl)
  1229. break;
  1230. dbgarg (cmd, "id=%d, value=%d\n", p->id, p->value);
  1231. ret=vfd->vidioc_s_ctrl(file, fh, p);
  1232. break;
  1233. }
  1234. case VIDIOC_G_EXT_CTRLS:
  1235. {
  1236. struct v4l2_ext_controls *p = arg;
  1237. if (vfd->vidioc_g_ext_ctrls) {
  1238. dbgarg(cmd, "count=%d\n", p->count);
  1239. ret=vfd->vidioc_g_ext_ctrls(file, fh, p);
  1240. }
  1241. break;
  1242. }
  1243. case VIDIOC_S_EXT_CTRLS:
  1244. {
  1245. struct v4l2_ext_controls *p = arg;
  1246. if (vfd->vidioc_s_ext_ctrls) {
  1247. dbgarg(cmd, "count=%d\n", p->count);
  1248. ret=vfd->vidioc_s_ext_ctrls(file, fh, p);
  1249. }
  1250. break;
  1251. }
  1252. case VIDIOC_TRY_EXT_CTRLS:
  1253. {
  1254. struct v4l2_ext_controls *p = arg;
  1255. if (vfd->vidioc_try_ext_ctrls) {
  1256. dbgarg(cmd, "count=%d\n", p->count);
  1257. ret=vfd->vidioc_try_ext_ctrls(file, fh, p);
  1258. }
  1259. break;
  1260. }
  1261. case VIDIOC_QUERYMENU:
  1262. {
  1263. struct v4l2_querymenu *p=arg;
  1264. if (!vfd->vidioc_querymenu)
  1265. break;
  1266. ret=vfd->vidioc_querymenu(file, fh, p);
  1267. if (!ret)
  1268. dbgarg (cmd, "id=%d, index=%d, name=%s\n",
  1269. p->id,p->index,p->name);
  1270. break;
  1271. }
  1272. /* --- audio ---------------------------------------------- */
  1273. case VIDIOC_ENUMAUDIO:
  1274. {
  1275. struct v4l2_audio *p=arg;
  1276. if (!vfd->vidioc_enumaudio)
  1277. break;
  1278. dbgarg(cmd, "Enum for index=%d\n", p->index);
  1279. ret=vfd->vidioc_enumaudio(file, fh, p);
  1280. if (!ret)
  1281. dbgarg2("index=%d, name=%s, capability=%d, "
  1282. "mode=%d\n",p->index,p->name,
  1283. p->capability, p->mode);
  1284. break;
  1285. }
  1286. case VIDIOC_G_AUDIO:
  1287. {
  1288. struct v4l2_audio *p=arg;
  1289. __u32 index=p->index;
  1290. if (!vfd->vidioc_g_audio)
  1291. break;
  1292. memset(p,0,sizeof(*p));
  1293. p->index=index;
  1294. dbgarg(cmd, "Get for index=%d\n", p->index);
  1295. ret=vfd->vidioc_g_audio(file, fh, p);
  1296. if (!ret)
  1297. dbgarg2("index=%d, name=%s, capability=%d, "
  1298. "mode=%d\n",p->index,
  1299. p->name,p->capability, p->mode);
  1300. break;
  1301. }
  1302. case VIDIOC_S_AUDIO:
  1303. {
  1304. struct v4l2_audio *p=arg;
  1305. if (!vfd->vidioc_s_audio)
  1306. break;
  1307. dbgarg(cmd, "index=%d, name=%s, capability=%d, "
  1308. "mode=%d\n", p->index, p->name,
  1309. p->capability, p->mode);
  1310. ret=vfd->vidioc_s_audio(file, fh, p);
  1311. break;
  1312. }
  1313. case VIDIOC_ENUMAUDOUT:
  1314. {
  1315. struct v4l2_audioout *p=arg;
  1316. if (!vfd->vidioc_enumaudout)
  1317. break;
  1318. dbgarg(cmd, "Enum for index=%d\n", p->index);
  1319. ret=vfd->vidioc_enumaudout(file, fh, p);
  1320. if (!ret)
  1321. dbgarg2("index=%d, name=%s, capability=%d, "
  1322. "mode=%d\n", p->index, p->name,
  1323. p->capability,p->mode);
  1324. break;
  1325. }
  1326. case VIDIOC_G_AUDOUT:
  1327. {
  1328. struct v4l2_audioout *p=arg;
  1329. if (!vfd->vidioc_g_audout)
  1330. break;
  1331. dbgarg(cmd, "Enum for index=%d\n", p->index);
  1332. ret=vfd->vidioc_g_audout(file, fh, p);
  1333. if (!ret)
  1334. dbgarg2("index=%d, name=%s, capability=%d, "
  1335. "mode=%d\n", p->index, p->name,
  1336. p->capability,p->mode);
  1337. break;
  1338. }
  1339. case VIDIOC_S_AUDOUT:
  1340. {
  1341. struct v4l2_audioout *p=arg;
  1342. if (!vfd->vidioc_s_audout)
  1343. break;
  1344. dbgarg(cmd, "index=%d, name=%s, capability=%d, "
  1345. "mode=%d\n", p->index, p->name,
  1346. p->capability,p->mode);
  1347. ret=vfd->vidioc_s_audout(file, fh, p);
  1348. break;
  1349. }
  1350. case VIDIOC_G_MODULATOR:
  1351. {
  1352. struct v4l2_modulator *p=arg;
  1353. if (!vfd->vidioc_g_modulator)
  1354. break;
  1355. ret=vfd->vidioc_g_modulator(file, fh, p);
  1356. if (!ret)
  1357. dbgarg(cmd, "index=%d, name=%s, "
  1358. "capability=%d, rangelow=%d,"
  1359. " rangehigh=%d, txsubchans=%d\n",
  1360. p->index, p->name,p->capability,
  1361. p->rangelow, p->rangehigh,
  1362. p->txsubchans);
  1363. break;
  1364. }
  1365. case VIDIOC_S_MODULATOR:
  1366. {
  1367. struct v4l2_modulator *p=arg;
  1368. if (!vfd->vidioc_s_modulator)
  1369. break;
  1370. dbgarg(cmd, "index=%d, name=%s, capability=%d, "
  1371. "rangelow=%d, rangehigh=%d, txsubchans=%d\n",
  1372. p->index, p->name,p->capability,p->rangelow,
  1373. p->rangehigh,p->txsubchans);
  1374. ret=vfd->vidioc_s_modulator(file, fh, p);
  1375. break;
  1376. }
  1377. case VIDIOC_G_CROP:
  1378. {
  1379. struct v4l2_crop *p=arg;
  1380. if (!vfd->vidioc_g_crop)
  1381. break;
  1382. ret=vfd->vidioc_g_crop(file, fh, p);
  1383. if (!ret) {
  1384. dbgarg(cmd, "type=%d\n", p->type);
  1385. dbgrect(vfd, "", &p->c);
  1386. }
  1387. break;
  1388. }
  1389. case VIDIOC_S_CROP:
  1390. {
  1391. struct v4l2_crop *p=arg;
  1392. if (!vfd->vidioc_s_crop)
  1393. break;
  1394. dbgarg(cmd, "type=%d\n", p->type);
  1395. dbgrect(vfd, "", &p->c);
  1396. ret=vfd->vidioc_s_crop(file, fh, p);
  1397. break;
  1398. }
  1399. case VIDIOC_CROPCAP:
  1400. {
  1401. struct v4l2_cropcap *p=arg;
  1402. /*FIXME: Should also show v4l2_fract pixelaspect */
  1403. if (!vfd->vidioc_cropcap)
  1404. break;
  1405. dbgarg(cmd, "type=%d\n", p->type);
  1406. dbgrect(vfd, "bounds ", &p->bounds);
  1407. dbgrect(vfd, "defrect ", &p->defrect);
  1408. ret=vfd->vidioc_cropcap(file, fh, p);
  1409. break;
  1410. }
  1411. case VIDIOC_G_JPEGCOMP:
  1412. {
  1413. struct v4l2_jpegcompression *p=arg;
  1414. if (!vfd->vidioc_g_jpegcomp)
  1415. break;
  1416. ret=vfd->vidioc_g_jpegcomp(file, fh, p);
  1417. if (!ret)
  1418. dbgarg (cmd, "quality=%d, APPn=%d, "
  1419. "APP_len=%d, COM_len=%d, "
  1420. "jpeg_markers=%d\n",
  1421. p->quality,p->APPn,p->APP_len,
  1422. p->COM_len,p->jpeg_markers);
  1423. break;
  1424. }
  1425. case VIDIOC_S_JPEGCOMP:
  1426. {
  1427. struct v4l2_jpegcompression *p=arg;
  1428. if (!vfd->vidioc_g_jpegcomp)
  1429. break;
  1430. dbgarg (cmd, "quality=%d, APPn=%d, APP_len=%d, "
  1431. "COM_len=%d, jpeg_markers=%d\n",
  1432. p->quality,p->APPn,p->APP_len,
  1433. p->COM_len,p->jpeg_markers);
  1434. ret=vfd->vidioc_s_jpegcomp(file, fh, p);
  1435. break;
  1436. }
  1437. case VIDIOC_G_ENC_INDEX:
  1438. {
  1439. struct v4l2_enc_idx *p=arg;
  1440. if (!vfd->vidioc_g_enc_index)
  1441. break;
  1442. ret=vfd->vidioc_g_enc_index(file, fh, p);
  1443. if (!ret)
  1444. dbgarg (cmd, "entries=%d, entries_cap=%d\n",
  1445. p->entries,p->entries_cap);
  1446. break;
  1447. }
  1448. case VIDIOC_ENCODER_CMD:
  1449. {
  1450. struct v4l2_encoder_cmd *p=arg;
  1451. if (!vfd->vidioc_encoder_cmd)
  1452. break;
  1453. ret=vfd->vidioc_encoder_cmd(file, fh, p);
  1454. if (!ret)
  1455. dbgarg (cmd, "cmd=%d, flags=%d\n",
  1456. p->cmd,p->flags);
  1457. break;
  1458. }
  1459. case VIDIOC_TRY_ENCODER_CMD:
  1460. {
  1461. struct v4l2_encoder_cmd *p=arg;
  1462. if (!vfd->vidioc_try_encoder_cmd)
  1463. break;
  1464. ret=vfd->vidioc_try_encoder_cmd(file, fh, p);
  1465. if (!ret)
  1466. dbgarg (cmd, "cmd=%d, flags=%d\n",
  1467. p->cmd,p->flags);
  1468. break;
  1469. }
  1470. case VIDIOC_G_PARM:
  1471. {
  1472. struct v4l2_streamparm *p=arg;
  1473. __u32 type=p->type;
  1474. memset(p,0,sizeof(*p));
  1475. p->type=type;
  1476. if (vfd->vidioc_g_parm) {
  1477. ret=vfd->vidioc_g_parm(file, fh, p);
  1478. } else {
  1479. struct v4l2_standard s;
  1480. if (p->type != V4L2_BUF_TYPE_VIDEO_CAPTURE)
  1481. return -EINVAL;
  1482. v4l2_video_std_construct(&s, vfd->current_norm,
  1483. v4l2_norm_to_name(vfd->current_norm));
  1484. p->parm.capture.timeperframe = s.frameperiod;
  1485. ret=0;
  1486. }
  1487. dbgarg (cmd, "type=%d\n", p->type);
  1488. break;
  1489. }
  1490. case VIDIOC_S_PARM:
  1491. {
  1492. struct v4l2_streamparm *p=arg;
  1493. if (!vfd->vidioc_s_parm)
  1494. break;
  1495. dbgarg (cmd, "type=%d\n", p->type);
  1496. ret=vfd->vidioc_s_parm(file, fh, p);
  1497. break;
  1498. }
  1499. case VIDIOC_G_TUNER:
  1500. {
  1501. struct v4l2_tuner *p=arg;
  1502. __u32 index=p->index;
  1503. if (!vfd->vidioc_g_tuner)
  1504. break;
  1505. memset(p,0,sizeof(*p));
  1506. p->index=index;
  1507. ret=vfd->vidioc_g_tuner(file, fh, p);
  1508. if (!ret)
  1509. dbgarg (cmd, "index=%d, name=%s, type=%d, "
  1510. "capability=%d, rangelow=%d, "
  1511. "rangehigh=%d, signal=%d, afc=%d, "
  1512. "rxsubchans=%d, audmode=%d\n",
  1513. p->index, p->name, p->type,
  1514. p->capability, p->rangelow,
  1515. p->rangehigh, p->rxsubchans,
  1516. p->audmode, p->signal, p->afc);
  1517. break;
  1518. }
  1519. case VIDIOC_S_TUNER:
  1520. {
  1521. struct v4l2_tuner *p=arg;
  1522. if (!vfd->vidioc_s_tuner)
  1523. break;
  1524. dbgarg (cmd, "index=%d, name=%s, type=%d, "
  1525. "capability=%d, rangelow=%d, rangehigh=%d, "
  1526. "signal=%d, afc=%d, rxsubchans=%d, "
  1527. "audmode=%d\n",p->index, p->name, p->type,
  1528. p->capability, p->rangelow,p->rangehigh,
  1529. p->rxsubchans, p->audmode, p->signal,
  1530. p->afc);
  1531. ret=vfd->vidioc_s_tuner(file, fh, p);
  1532. break;
  1533. }
  1534. case VIDIOC_G_FREQUENCY:
  1535. {
  1536. struct v4l2_frequency *p = arg;
  1537. if (!vfd->vidioc_g_frequency)
  1538. break;
  1539. memset(p->reserved, 0, sizeof(p->reserved));
  1540. ret = vfd->vidioc_g_frequency(file, fh, p);
  1541. if (!ret)
  1542. dbgarg(cmd, "tuner=%d, type=%d, frequency=%d\n",
  1543. p->tuner, p->type, p->frequency);
  1544. break;
  1545. }
  1546. case VIDIOC_S_FREQUENCY:
  1547. {
  1548. struct v4l2_frequency *p=arg;
  1549. if (!vfd->vidioc_s_frequency)
  1550. break;
  1551. dbgarg (cmd, "tuner=%d, type=%d, frequency=%d\n",
  1552. p->tuner,p->type,p->frequency);
  1553. ret=vfd->vidioc_s_frequency(file, fh, p);
  1554. break;
  1555. }
  1556. case VIDIOC_G_SLICED_VBI_CAP:
  1557. {
  1558. struct v4l2_sliced_vbi_cap *p=arg;
  1559. if (!vfd->vidioc_g_sliced_vbi_cap)
  1560. break;
  1561. ret=vfd->vidioc_g_sliced_vbi_cap(file, fh, p);
  1562. if (!ret)
  1563. dbgarg (cmd, "service_set=%d\n", p->service_set);
  1564. break;
  1565. }
  1566. case VIDIOC_LOG_STATUS:
  1567. {
  1568. if (!vfd->vidioc_log_status)
  1569. break;
  1570. ret=vfd->vidioc_log_status(file, fh);
  1571. break;
  1572. }
  1573. #ifdef CONFIG_VIDEO_ADV_DEBUG
  1574. case VIDIOC_DBG_G_REGISTER:
  1575. {
  1576. struct v4l2_register *p=arg;
  1577. if (!capable(CAP_SYS_ADMIN))
  1578. ret=-EPERM;
  1579. else if (vfd->vidioc_g_register)
  1580. ret=vfd->vidioc_g_register(file, fh, p);
  1581. break;
  1582. }
  1583. case VIDIOC_DBG_S_REGISTER:
  1584. {
  1585. struct v4l2_register *p=arg;
  1586. if (!capable(CAP_SYS_ADMIN))
  1587. ret=-EPERM;
  1588. else if (vfd->vidioc_s_register)
  1589. ret=vfd->vidioc_s_register(file, fh, p);
  1590. break;
  1591. }
  1592. #endif
  1593. case VIDIOC_G_CHIP_IDENT:
  1594. {
  1595. struct v4l2_chip_ident *p=arg;
  1596. if (!vfd->vidioc_g_chip_ident)
  1597. break;
  1598. ret=vfd->vidioc_g_chip_ident(file, fh, p);
  1599. if (!ret)
  1600. dbgarg (cmd, "chip_ident=%u, revision=0x%x\n", p->ident, p->revision);
  1601. break;
  1602. }
  1603. default:
  1604. {
  1605. if (!vfd->vidioc_default)
  1606. break;
  1607. ret = vfd->vidioc_default(file, fh, cmd, arg);
  1608. break;
  1609. }
  1610. case VIDIOC_S_HW_FREQ_SEEK:
  1611. {
  1612. struct v4l2_hw_freq_seek *p = arg;
  1613. if (!vfd->vidioc_s_hw_freq_seek)
  1614. break;
  1615. dbgarg(cmd,
  1616. "tuner=%d, type=%d, seek_upward=%d, wrap_around=%d\n",
  1617. p->tuner, p->type, p->seek_upward, p->wrap_around);
  1618. ret = vfd->vidioc_s_hw_freq_seek(file, fh, p);
  1619. break;
  1620. }
  1621. } /* switch */
  1622. if (vfd->debug & V4L2_DEBUG_IOCTL_ARG) {
  1623. if (ret<0) {
  1624. printk("%s: err: on ", vfd->name);
  1625. v4l_print_ioctl(vfd->name, cmd);
  1626. printk("\n");
  1627. }
  1628. }
  1629. return ret;
  1630. }
  1631. int video_ioctl2 (struct inode *inode, struct file *file,
  1632. unsigned int cmd, unsigned long arg)
  1633. {
  1634. char sbuf[128];
  1635. void *mbuf = NULL;
  1636. void *parg = NULL;
  1637. int err = -EINVAL;
  1638. int is_ext_ctrl;
  1639. size_t ctrls_size = 0;
  1640. void __user *user_ptr = NULL;
  1641. #ifdef __OLD_VIDIOC_
  1642. cmd = video_fix_command(cmd);
  1643. #endif
  1644. is_ext_ctrl = (cmd == VIDIOC_S_EXT_CTRLS || cmd == VIDIOC_G_EXT_CTRLS ||
  1645. cmd == VIDIOC_TRY_EXT_CTRLS);
  1646. /* Copy arguments into temp kernel buffer */
  1647. switch (_IOC_DIR(cmd)) {
  1648. case _IOC_NONE:
  1649. parg = NULL;
  1650. break;
  1651. case _IOC_READ:
  1652. case _IOC_WRITE:
  1653. case (_IOC_WRITE | _IOC_READ):
  1654. if (_IOC_SIZE(cmd) <= sizeof(sbuf)) {
  1655. parg = sbuf;
  1656. } else {
  1657. /* too big to allocate from stack */
  1658. mbuf = kmalloc(_IOC_SIZE(cmd),GFP_KERNEL);
  1659. if (NULL == mbuf)
  1660. return -ENOMEM;
  1661. parg = mbuf;
  1662. }
  1663. err = -EFAULT;
  1664. if (_IOC_DIR(cmd) & _IOC_WRITE)
  1665. if (copy_from_user(parg, (void __user *)arg, _IOC_SIZE(cmd)))
  1666. goto out;
  1667. break;
  1668. }
  1669. if (is_ext_ctrl) {
  1670. struct v4l2_ext_controls *p = parg;
  1671. /* In case of an error, tell the caller that it wasn't
  1672. a specific control that caused it. */
  1673. p->error_idx = p->count;
  1674. user_ptr = (void __user *)p->controls;
  1675. if (p->count) {
  1676. ctrls_size = sizeof(struct v4l2_ext_control) * p->count;
  1677. /* Note: v4l2_ext_controls fits in sbuf[] so mbuf is still NULL. */
  1678. mbuf = kmalloc(ctrls_size, GFP_KERNEL);
  1679. err = -ENOMEM;
  1680. if (NULL == mbuf)
  1681. goto out_ext_ctrl;
  1682. err = -EFAULT;
  1683. if (copy_from_user(mbuf, user_ptr, ctrls_size))
  1684. goto out_ext_ctrl;
  1685. p->controls = mbuf;
  1686. }
  1687. }
  1688. /* Handles IOCTL */
  1689. err = __video_do_ioctl(inode, file, cmd, parg);
  1690. if (err == -ENOIOCTLCMD)
  1691. err = -EINVAL;
  1692. if (is_ext_ctrl) {
  1693. struct v4l2_ext_controls *p = parg;
  1694. p->controls = (void *)user_ptr;
  1695. if (p->count && err == 0 && copy_to_user(user_ptr, mbuf, ctrls_size))
  1696. err = -EFAULT;
  1697. goto out_ext_ctrl;
  1698. }
  1699. if (err < 0)
  1700. goto out;
  1701. out_ext_ctrl:
  1702. /* Copy results into user buffer */
  1703. switch (_IOC_DIR(cmd))
  1704. {
  1705. case _IOC_READ:
  1706. case (_IOC_WRITE | _IOC_READ):
  1707. if (copy_to_user((void __user *)arg, parg, _IOC_SIZE(cmd)))
  1708. err = -EFAULT;
  1709. break;
  1710. }
  1711. out:
  1712. kfree(mbuf);
  1713. return err;
  1714. }
  1715. EXPORT_SYMBOL(video_ioctl2);
  1716. static const struct file_operations video_fops;
  1717. /**
  1718. * video_register_device - register video4linux devices
  1719. * @vfd: video device structure we want to register
  1720. * @type: type of device to register
  1721. * @nr: which device number (0 == /dev/video0, 1 == /dev/video1, ...
  1722. * -1 == first free)
  1723. *
  1724. * The registration code assigns minor numbers based on the type
  1725. * requested. -ENFILE is returned in all the device slots for this
  1726. * category are full. If not then the minor field is set and the
  1727. * driver initialize function is called (if non %NULL).
  1728. *
  1729. * Zero is returned on success.
  1730. *
  1731. * Valid types are
  1732. *
  1733. * %VFL_TYPE_GRABBER - A frame grabber
  1734. *
  1735. * %VFL_TYPE_VTX - A teletext device
  1736. *
  1737. * %VFL_TYPE_VBI - Vertical blank data (undecoded)
  1738. *
  1739. * %VFL_TYPE_RADIO - A radio card
  1740. */
  1741. int video_register_device(struct video_device *vfd, int type, int nr)
  1742. {
  1743. int i=0;
  1744. int base;
  1745. int end;
  1746. int ret;
  1747. char *name_base;
  1748. switch(type)
  1749. {
  1750. case VFL_TYPE_GRABBER:
  1751. base=MINOR_VFL_TYPE_GRABBER_MIN;
  1752. end=MINOR_VFL_TYPE_GRABBER_MAX+1;
  1753. name_base = "video";
  1754. break;
  1755. case VFL_TYPE_VTX:
  1756. base=MINOR_VFL_TYPE_VTX_MIN;
  1757. end=MINOR_VFL_TYPE_VTX_MAX+1;
  1758. name_base = "vtx";
  1759. break;
  1760. case VFL_TYPE_VBI:
  1761. base=MINOR_VFL_TYPE_VBI_MIN;
  1762. end=MINOR_VFL_TYPE_VBI_MAX+1;
  1763. name_base = "vbi";
  1764. break;
  1765. case VFL_TYPE_RADIO:
  1766. base=MINOR_VFL_TYPE_RADIO_MIN;
  1767. end=MINOR_VFL_TYPE_RADIO_MAX+1;
  1768. name_base = "radio";
  1769. break;
  1770. default:
  1771. printk(KERN_ERR "%s called with unknown type: %d\n",
  1772. __func__, type);
  1773. return -1;
  1774. }
  1775. /* pick a minor number */
  1776. mutex_lock(&videodev_lock);
  1777. if (nr >= 0 && nr < end-base) {
  1778. /* use the one the driver asked for */
  1779. i = base+nr;
  1780. if (NULL != video_device[i]) {
  1781. mutex_unlock(&videodev_lock);
  1782. return -ENFILE;
  1783. }
  1784. } else {
  1785. /* use first free */
  1786. for(i=base;i<end;i++)
  1787. if (NULL == video_device[i])
  1788. break;
  1789. if (i == end) {
  1790. mutex_unlock(&videodev_lock);
  1791. return -ENFILE;
  1792. }
  1793. }
  1794. video_device[i]=vfd;
  1795. vfd->minor=i;
  1796. mutex_unlock(&videodev_lock);
  1797. mutex_init(&vfd->lock);
  1798. /* sysfs class */
  1799. memset(&vfd->class_dev, 0x00, sizeof(vfd->class_dev));
  1800. if (vfd->dev)
  1801. vfd->class_dev.parent = vfd->dev;
  1802. vfd->class_dev.class = &video_class;
  1803. vfd->class_dev.devt = MKDEV(VIDEO_MAJOR, vfd->minor);
  1804. sprintf(vfd->class_dev.bus_id, "%s%d", name_base, i - base);
  1805. ret = device_register(&vfd->class_dev);
  1806. if (ret < 0) {
  1807. printk(KERN_ERR "%s: device_register failed\n",
  1808. __func__);
  1809. goto fail_minor;
  1810. }
  1811. #if 1
  1812. /* needed until all drivers are fixed */
  1813. if (!vfd->release)
  1814. printk(KERN_WARNING "videodev: \"%s\" has no release callback. "
  1815. "Please fix your driver for proper sysfs support, see "
  1816. "http://lwn.net/Articles/36850/\n", vfd->name);
  1817. #endif
  1818. return 0;
  1819. fail_minor:
  1820. mutex_lock(&videodev_lock);
  1821. video_device[vfd->minor] = NULL;
  1822. vfd->minor = -1;
  1823. mutex_unlock(&videodev_lock);
  1824. return ret;
  1825. }
  1826. EXPORT_SYMBOL(video_register_device);
  1827. /**
  1828. * video_unregister_device - unregister a video4linux device
  1829. * @vfd: the device to unregister
  1830. *
  1831. * This unregisters the passed device and deassigns the minor
  1832. * number. Future open calls will be met with errors.
  1833. */
  1834. void video_unregister_device(struct video_device *vfd)
  1835. {
  1836. mutex_lock(&videodev_lock);
  1837. if(video_device[vfd->minor]!=vfd)
  1838. panic("videodev: bad unregister");
  1839. video_device[vfd->minor]=NULL;
  1840. device_unregister(&vfd->class_dev);
  1841. mutex_unlock(&videodev_lock);
  1842. }
  1843. EXPORT_SYMBOL(video_unregister_device);
  1844. /*
  1845. * Video fs operations
  1846. */
  1847. static const struct file_operations video_fops=
  1848. {
  1849. .owner = THIS_MODULE,
  1850. .llseek = no_llseek,
  1851. .open = video_open,
  1852. };
  1853. /*
  1854. * Initialise video for linux
  1855. */
  1856. static int __init videodev_init(void)
  1857. {
  1858. int ret;
  1859. printk(KERN_INFO "Linux video capture interface: v2.00\n");
  1860. if (register_chrdev(VIDEO_MAJOR, VIDEO_NAME, &video_fops)) {
  1861. printk(KERN_WARNING "video_dev: unable to get major %d\n", VIDEO_MAJOR);
  1862. return -EIO;
  1863. }
  1864. ret = class_register(&video_class);
  1865. if (ret < 0) {
  1866. unregister_chrdev(VIDEO_MAJOR, VIDEO_NAME);
  1867. printk(KERN_WARNING "video_dev: class_register failed\n");
  1868. return -EIO;
  1869. }
  1870. return 0;
  1871. }
  1872. static void __exit videodev_exit(void)
  1873. {
  1874. class_unregister(&video_class);
  1875. unregister_chrdev(VIDEO_MAJOR, VIDEO_NAME);
  1876. }
  1877. module_init(videodev_init)
  1878. module_exit(videodev_exit)
  1879. MODULE_AUTHOR("Alan Cox, Mauro Carvalho Chehab <mchehab@infradead.org>");
  1880. MODULE_DESCRIPTION("Device registrar for Video4Linux drivers v2");
  1881. MODULE_LICENSE("GPL");
  1882. /*
  1883. * Local variables:
  1884. * c-basic-offset: 8
  1885. * End:
  1886. */