v4l2-ioctl.c 63 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423
  1. /*
  2. * Video capture interface for Linux version 2
  3. *
  4. * A generic framework to process V4L2 ioctl commands.
  5. *
  6. * This program is free software; you can redistribute it and/or
  7. * modify it under the terms of the GNU General Public License
  8. * as published by the Free Software Foundation; either version
  9. * 2 of the License, or (at your option) any later version.
  10. *
  11. * Authors: Alan Cox, <alan@lxorguk.ukuu.org.uk> (version 1)
  12. * Mauro Carvalho Chehab <mchehab@infradead.org> (version 2)
  13. */
  14. #include <linux/module.h>
  15. #include <linux/slab.h>
  16. #include <linux/types.h>
  17. #include <linux/kernel.h>
  18. #include <linux/version.h>
  19. #include <linux/videodev2.h>
  20. #include <media/v4l2-common.h>
  21. #include <media/v4l2-ioctl.h>
  22. #include <media/v4l2-ctrls.h>
  23. #include <media/v4l2-fh.h>
  24. #include <media/v4l2-event.h>
  25. #include <media/v4l2-device.h>
  26. #include <media/v4l2-chip-ident.h>
  27. #define dbgarg(cmd, fmt, arg...) \
  28. do { \
  29. if (vfd->debug & V4L2_DEBUG_IOCTL_ARG) { \
  30. printk(KERN_DEBUG "%s: ", vfd->name); \
  31. v4l_printk_ioctl(cmd); \
  32. printk(" " fmt, ## arg); \
  33. } \
  34. } while (0)
  35. #define dbgarg2(fmt, arg...) \
  36. do { \
  37. if (vfd->debug & V4L2_DEBUG_IOCTL_ARG) \
  38. printk(KERN_DEBUG "%s: " fmt, vfd->name, ## arg);\
  39. } while (0)
  40. #define dbgarg3(fmt, arg...) \
  41. do { \
  42. if (vfd->debug & V4L2_DEBUG_IOCTL_ARG) \
  43. printk(KERN_CONT "%s: " fmt, vfd->name, ## arg);\
  44. } while (0)
  45. /* Zero out the end of the struct pointed to by p. Everything after, but
  46. * not including, the specified field is cleared. */
  47. #define CLEAR_AFTER_FIELD(p, field) \
  48. memset((u8 *)(p) + offsetof(typeof(*(p)), field) + sizeof((p)->field), \
  49. 0, sizeof(*(p)) - offsetof(typeof(*(p)), field) - sizeof((p)->field))
  50. struct std_descr {
  51. v4l2_std_id std;
  52. const char *descr;
  53. };
  54. static const struct std_descr standards[] = {
  55. { V4L2_STD_NTSC, "NTSC" },
  56. { V4L2_STD_NTSC_M, "NTSC-M" },
  57. { V4L2_STD_NTSC_M_JP, "NTSC-M-JP" },
  58. { V4L2_STD_NTSC_M_KR, "NTSC-M-KR" },
  59. { V4L2_STD_NTSC_443, "NTSC-443" },
  60. { V4L2_STD_PAL, "PAL" },
  61. { V4L2_STD_PAL_BG, "PAL-BG" },
  62. { V4L2_STD_PAL_B, "PAL-B" },
  63. { V4L2_STD_PAL_B1, "PAL-B1" },
  64. { V4L2_STD_PAL_G, "PAL-G" },
  65. { V4L2_STD_PAL_H, "PAL-H" },
  66. { V4L2_STD_PAL_I, "PAL-I" },
  67. { V4L2_STD_PAL_DK, "PAL-DK" },
  68. { V4L2_STD_PAL_D, "PAL-D" },
  69. { V4L2_STD_PAL_D1, "PAL-D1" },
  70. { V4L2_STD_PAL_K, "PAL-K" },
  71. { V4L2_STD_PAL_M, "PAL-M" },
  72. { V4L2_STD_PAL_N, "PAL-N" },
  73. { V4L2_STD_PAL_Nc, "PAL-Nc" },
  74. { V4L2_STD_PAL_60, "PAL-60" },
  75. { V4L2_STD_SECAM, "SECAM" },
  76. { V4L2_STD_SECAM_B, "SECAM-B" },
  77. { V4L2_STD_SECAM_G, "SECAM-G" },
  78. { V4L2_STD_SECAM_H, "SECAM-H" },
  79. { V4L2_STD_SECAM_DK, "SECAM-DK" },
  80. { V4L2_STD_SECAM_D, "SECAM-D" },
  81. { V4L2_STD_SECAM_K, "SECAM-K" },
  82. { V4L2_STD_SECAM_K1, "SECAM-K1" },
  83. { V4L2_STD_SECAM_L, "SECAM-L" },
  84. { V4L2_STD_SECAM_LC, "SECAM-Lc" },
  85. { 0, "Unknown" }
  86. };
  87. /* video4linux standard ID conversion to standard name
  88. */
  89. const char *v4l2_norm_to_name(v4l2_std_id id)
  90. {
  91. u32 myid = id;
  92. int i;
  93. /* HACK: ppc32 architecture doesn't have __ucmpdi2 function to handle
  94. 64 bit comparations. So, on that architecture, with some gcc
  95. variants, compilation fails. Currently, the max value is 30bit wide.
  96. */
  97. BUG_ON(myid != id);
  98. for (i = 0; standards[i].std; i++)
  99. if (myid == standards[i].std)
  100. break;
  101. return standards[i].descr;
  102. }
  103. EXPORT_SYMBOL(v4l2_norm_to_name);
  104. /* Returns frame period for the given standard */
  105. void v4l2_video_std_frame_period(int id, struct v4l2_fract *frameperiod)
  106. {
  107. if (id & V4L2_STD_525_60) {
  108. frameperiod->numerator = 1001;
  109. frameperiod->denominator = 30000;
  110. } else {
  111. frameperiod->numerator = 1;
  112. frameperiod->denominator = 25;
  113. }
  114. }
  115. EXPORT_SYMBOL(v4l2_video_std_frame_period);
  116. /* Fill in the fields of a v4l2_standard structure according to the
  117. 'id' and 'transmission' parameters. Returns negative on error. */
  118. int v4l2_video_std_construct(struct v4l2_standard *vs,
  119. int id, const char *name)
  120. {
  121. vs->id = id;
  122. v4l2_video_std_frame_period(id, &vs->frameperiod);
  123. vs->framelines = (id & V4L2_STD_525_60) ? 525 : 625;
  124. strlcpy(vs->name, name, sizeof(vs->name));
  125. return 0;
  126. }
  127. EXPORT_SYMBOL(v4l2_video_std_construct);
  128. /* ----------------------------------------------------------------- */
  129. /* some arrays for pretty-printing debug messages of enum types */
  130. const char *v4l2_field_names[] = {
  131. [V4L2_FIELD_ANY] = "any",
  132. [V4L2_FIELD_NONE] = "none",
  133. [V4L2_FIELD_TOP] = "top",
  134. [V4L2_FIELD_BOTTOM] = "bottom",
  135. [V4L2_FIELD_INTERLACED] = "interlaced",
  136. [V4L2_FIELD_SEQ_TB] = "seq-tb",
  137. [V4L2_FIELD_SEQ_BT] = "seq-bt",
  138. [V4L2_FIELD_ALTERNATE] = "alternate",
  139. [V4L2_FIELD_INTERLACED_TB] = "interlaced-tb",
  140. [V4L2_FIELD_INTERLACED_BT] = "interlaced-bt",
  141. };
  142. EXPORT_SYMBOL(v4l2_field_names);
  143. const char *v4l2_type_names[] = {
  144. [V4L2_BUF_TYPE_VIDEO_CAPTURE] = "vid-cap",
  145. [V4L2_BUF_TYPE_VIDEO_OVERLAY] = "vid-overlay",
  146. [V4L2_BUF_TYPE_VIDEO_OUTPUT] = "vid-out",
  147. [V4L2_BUF_TYPE_VBI_CAPTURE] = "vbi-cap",
  148. [V4L2_BUF_TYPE_VBI_OUTPUT] = "vbi-out",
  149. [V4L2_BUF_TYPE_SLICED_VBI_CAPTURE] = "sliced-vbi-cap",
  150. [V4L2_BUF_TYPE_SLICED_VBI_OUTPUT] = "sliced-vbi-out",
  151. [V4L2_BUF_TYPE_VIDEO_OUTPUT_OVERLAY] = "vid-out-overlay",
  152. [V4L2_BUF_TYPE_VIDEO_CAPTURE_MPLANE] = "vid-cap-mplane",
  153. [V4L2_BUF_TYPE_VIDEO_OUTPUT_MPLANE] = "vid-out-mplane",
  154. };
  155. EXPORT_SYMBOL(v4l2_type_names);
  156. static const char *v4l2_memory_names[] = {
  157. [V4L2_MEMORY_MMAP] = "mmap",
  158. [V4L2_MEMORY_USERPTR] = "userptr",
  159. [V4L2_MEMORY_OVERLAY] = "overlay",
  160. };
  161. #define prt_names(a, arr) ((((a) >= 0) && ((a) < ARRAY_SIZE(arr))) ? \
  162. arr[a] : "unknown")
  163. /* ------------------------------------------------------------------ */
  164. /* debug help functions */
  165. static const char *v4l2_ioctls[] = {
  166. [_IOC_NR(VIDIOC_QUERYCAP)] = "VIDIOC_QUERYCAP",
  167. [_IOC_NR(VIDIOC_RESERVED)] = "VIDIOC_RESERVED",
  168. [_IOC_NR(VIDIOC_ENUM_FMT)] = "VIDIOC_ENUM_FMT",
  169. [_IOC_NR(VIDIOC_G_FMT)] = "VIDIOC_G_FMT",
  170. [_IOC_NR(VIDIOC_S_FMT)] = "VIDIOC_S_FMT",
  171. [_IOC_NR(VIDIOC_REQBUFS)] = "VIDIOC_REQBUFS",
  172. [_IOC_NR(VIDIOC_QUERYBUF)] = "VIDIOC_QUERYBUF",
  173. [_IOC_NR(VIDIOC_G_FBUF)] = "VIDIOC_G_FBUF",
  174. [_IOC_NR(VIDIOC_S_FBUF)] = "VIDIOC_S_FBUF",
  175. [_IOC_NR(VIDIOC_OVERLAY)] = "VIDIOC_OVERLAY",
  176. [_IOC_NR(VIDIOC_QBUF)] = "VIDIOC_QBUF",
  177. [_IOC_NR(VIDIOC_DQBUF)] = "VIDIOC_DQBUF",
  178. [_IOC_NR(VIDIOC_STREAMON)] = "VIDIOC_STREAMON",
  179. [_IOC_NR(VIDIOC_STREAMOFF)] = "VIDIOC_STREAMOFF",
  180. [_IOC_NR(VIDIOC_G_PARM)] = "VIDIOC_G_PARM",
  181. [_IOC_NR(VIDIOC_S_PARM)] = "VIDIOC_S_PARM",
  182. [_IOC_NR(VIDIOC_G_STD)] = "VIDIOC_G_STD",
  183. [_IOC_NR(VIDIOC_S_STD)] = "VIDIOC_S_STD",
  184. [_IOC_NR(VIDIOC_ENUMSTD)] = "VIDIOC_ENUMSTD",
  185. [_IOC_NR(VIDIOC_ENUMINPUT)] = "VIDIOC_ENUMINPUT",
  186. [_IOC_NR(VIDIOC_G_CTRL)] = "VIDIOC_G_CTRL",
  187. [_IOC_NR(VIDIOC_S_CTRL)] = "VIDIOC_S_CTRL",
  188. [_IOC_NR(VIDIOC_G_TUNER)] = "VIDIOC_G_TUNER",
  189. [_IOC_NR(VIDIOC_S_TUNER)] = "VIDIOC_S_TUNER",
  190. [_IOC_NR(VIDIOC_G_AUDIO)] = "VIDIOC_G_AUDIO",
  191. [_IOC_NR(VIDIOC_S_AUDIO)] = "VIDIOC_S_AUDIO",
  192. [_IOC_NR(VIDIOC_QUERYCTRL)] = "VIDIOC_QUERYCTRL",
  193. [_IOC_NR(VIDIOC_QUERYMENU)] = "VIDIOC_QUERYMENU",
  194. [_IOC_NR(VIDIOC_G_INPUT)] = "VIDIOC_G_INPUT",
  195. [_IOC_NR(VIDIOC_S_INPUT)] = "VIDIOC_S_INPUT",
  196. [_IOC_NR(VIDIOC_G_OUTPUT)] = "VIDIOC_G_OUTPUT",
  197. [_IOC_NR(VIDIOC_S_OUTPUT)] = "VIDIOC_S_OUTPUT",
  198. [_IOC_NR(VIDIOC_ENUMOUTPUT)] = "VIDIOC_ENUMOUTPUT",
  199. [_IOC_NR(VIDIOC_G_AUDOUT)] = "VIDIOC_G_AUDOUT",
  200. [_IOC_NR(VIDIOC_S_AUDOUT)] = "VIDIOC_S_AUDOUT",
  201. [_IOC_NR(VIDIOC_G_MODULATOR)] = "VIDIOC_G_MODULATOR",
  202. [_IOC_NR(VIDIOC_S_MODULATOR)] = "VIDIOC_S_MODULATOR",
  203. [_IOC_NR(VIDIOC_G_FREQUENCY)] = "VIDIOC_G_FREQUENCY",
  204. [_IOC_NR(VIDIOC_S_FREQUENCY)] = "VIDIOC_S_FREQUENCY",
  205. [_IOC_NR(VIDIOC_CROPCAP)] = "VIDIOC_CROPCAP",
  206. [_IOC_NR(VIDIOC_G_CROP)] = "VIDIOC_G_CROP",
  207. [_IOC_NR(VIDIOC_S_CROP)] = "VIDIOC_S_CROP",
  208. [_IOC_NR(VIDIOC_G_JPEGCOMP)] = "VIDIOC_G_JPEGCOMP",
  209. [_IOC_NR(VIDIOC_S_JPEGCOMP)] = "VIDIOC_S_JPEGCOMP",
  210. [_IOC_NR(VIDIOC_QUERYSTD)] = "VIDIOC_QUERYSTD",
  211. [_IOC_NR(VIDIOC_TRY_FMT)] = "VIDIOC_TRY_FMT",
  212. [_IOC_NR(VIDIOC_ENUMAUDIO)] = "VIDIOC_ENUMAUDIO",
  213. [_IOC_NR(VIDIOC_ENUMAUDOUT)] = "VIDIOC_ENUMAUDOUT",
  214. [_IOC_NR(VIDIOC_G_PRIORITY)] = "VIDIOC_G_PRIORITY",
  215. [_IOC_NR(VIDIOC_S_PRIORITY)] = "VIDIOC_S_PRIORITY",
  216. [_IOC_NR(VIDIOC_G_SLICED_VBI_CAP)] = "VIDIOC_G_SLICED_VBI_CAP",
  217. [_IOC_NR(VIDIOC_LOG_STATUS)] = "VIDIOC_LOG_STATUS",
  218. [_IOC_NR(VIDIOC_G_EXT_CTRLS)] = "VIDIOC_G_EXT_CTRLS",
  219. [_IOC_NR(VIDIOC_S_EXT_CTRLS)] = "VIDIOC_S_EXT_CTRLS",
  220. [_IOC_NR(VIDIOC_TRY_EXT_CTRLS)] = "VIDIOC_TRY_EXT_CTRLS",
  221. #if 1
  222. [_IOC_NR(VIDIOC_ENUM_FRAMESIZES)] = "VIDIOC_ENUM_FRAMESIZES",
  223. [_IOC_NR(VIDIOC_ENUM_FRAMEINTERVALS)] = "VIDIOC_ENUM_FRAMEINTERVALS",
  224. [_IOC_NR(VIDIOC_G_ENC_INDEX)] = "VIDIOC_G_ENC_INDEX",
  225. [_IOC_NR(VIDIOC_ENCODER_CMD)] = "VIDIOC_ENCODER_CMD",
  226. [_IOC_NR(VIDIOC_TRY_ENCODER_CMD)] = "VIDIOC_TRY_ENCODER_CMD",
  227. [_IOC_NR(VIDIOC_DBG_S_REGISTER)] = "VIDIOC_DBG_S_REGISTER",
  228. [_IOC_NR(VIDIOC_DBG_G_REGISTER)] = "VIDIOC_DBG_G_REGISTER",
  229. [_IOC_NR(VIDIOC_DBG_G_CHIP_IDENT)] = "VIDIOC_DBG_G_CHIP_IDENT",
  230. [_IOC_NR(VIDIOC_S_HW_FREQ_SEEK)] = "VIDIOC_S_HW_FREQ_SEEK",
  231. #endif
  232. [_IOC_NR(VIDIOC_ENUM_DV_PRESETS)] = "VIDIOC_ENUM_DV_PRESETS",
  233. [_IOC_NR(VIDIOC_S_DV_PRESET)] = "VIDIOC_S_DV_PRESET",
  234. [_IOC_NR(VIDIOC_G_DV_PRESET)] = "VIDIOC_G_DV_PRESET",
  235. [_IOC_NR(VIDIOC_QUERY_DV_PRESET)] = "VIDIOC_QUERY_DV_PRESET",
  236. [_IOC_NR(VIDIOC_S_DV_TIMINGS)] = "VIDIOC_S_DV_TIMINGS",
  237. [_IOC_NR(VIDIOC_G_DV_TIMINGS)] = "VIDIOC_G_DV_TIMINGS",
  238. [_IOC_NR(VIDIOC_DQEVENT)] = "VIDIOC_DQEVENT",
  239. [_IOC_NR(VIDIOC_SUBSCRIBE_EVENT)] = "VIDIOC_SUBSCRIBE_EVENT",
  240. [_IOC_NR(VIDIOC_UNSUBSCRIBE_EVENT)] = "VIDIOC_UNSUBSCRIBE_EVENT",
  241. };
  242. #define V4L2_IOCTLS ARRAY_SIZE(v4l2_ioctls)
  243. /* Common ioctl debug function. This function can be used by
  244. external ioctl messages as well as internal V4L ioctl */
  245. void v4l_printk_ioctl(unsigned int cmd)
  246. {
  247. char *dir, *type;
  248. switch (_IOC_TYPE(cmd)) {
  249. case 'd':
  250. type = "v4l2_int";
  251. break;
  252. case 'V':
  253. if (_IOC_NR(cmd) >= V4L2_IOCTLS) {
  254. type = "v4l2";
  255. break;
  256. }
  257. printk("%s", v4l2_ioctls[_IOC_NR(cmd)]);
  258. return;
  259. default:
  260. type = "unknown";
  261. }
  262. switch (_IOC_DIR(cmd)) {
  263. case _IOC_NONE: dir = "--"; break;
  264. case _IOC_READ: dir = "r-"; break;
  265. case _IOC_WRITE: dir = "-w"; break;
  266. case _IOC_READ | _IOC_WRITE: dir = "rw"; break;
  267. default: dir = "*ERR*"; break;
  268. }
  269. printk("%s ioctl '%c', dir=%s, #%d (0x%08x)",
  270. type, _IOC_TYPE(cmd), dir, _IOC_NR(cmd), cmd);
  271. }
  272. EXPORT_SYMBOL(v4l_printk_ioctl);
  273. static void dbgbuf(unsigned int cmd, struct video_device *vfd,
  274. struct v4l2_buffer *p)
  275. {
  276. struct v4l2_timecode *tc = &p->timecode;
  277. struct v4l2_plane *plane;
  278. int i;
  279. dbgarg(cmd, "%02ld:%02d:%02d.%08ld index=%d, type=%s, "
  280. "flags=0x%08d, field=%0d, sequence=%d, memory=%s\n",
  281. p->timestamp.tv_sec / 3600,
  282. (int)(p->timestamp.tv_sec / 60) % 60,
  283. (int)(p->timestamp.tv_sec % 60),
  284. (long)p->timestamp.tv_usec,
  285. p->index,
  286. prt_names(p->type, v4l2_type_names),
  287. p->flags, p->field, p->sequence,
  288. prt_names(p->memory, v4l2_memory_names));
  289. if (V4L2_TYPE_IS_MULTIPLANAR(p->type) && p->m.planes) {
  290. for (i = 0; i < p->length; ++i) {
  291. plane = &p->m.planes[i];
  292. dbgarg2("plane %d: bytesused=%d, data_offset=0x%08x "
  293. "offset/userptr=0x%08lx, length=%d\n",
  294. i, plane->bytesused, plane->data_offset,
  295. plane->m.userptr, plane->length);
  296. }
  297. } else {
  298. dbgarg2("bytesused=%d, offset/userptr=0x%08lx, length=%d\n",
  299. p->bytesused, p->m.userptr, p->length);
  300. }
  301. dbgarg2("timecode=%02d:%02d:%02d type=%d, "
  302. "flags=0x%08d, frames=%d, userbits=0x%08x\n",
  303. tc->hours, tc->minutes, tc->seconds,
  304. tc->type, tc->flags, tc->frames, *(__u32 *)tc->userbits);
  305. }
  306. static inline void dbgrect(struct video_device *vfd, char *s,
  307. struct v4l2_rect *r)
  308. {
  309. dbgarg2("%sRect start at %dx%d, size=%dx%d\n", s, r->left, r->top,
  310. r->width, r->height);
  311. };
  312. static inline void v4l_print_pix_fmt(struct video_device *vfd,
  313. struct v4l2_pix_format *fmt)
  314. {
  315. dbgarg2("width=%d, height=%d, format=%c%c%c%c, field=%s, "
  316. "bytesperline=%d sizeimage=%d, colorspace=%d\n",
  317. fmt->width, fmt->height,
  318. (fmt->pixelformat & 0xff),
  319. (fmt->pixelformat >> 8) & 0xff,
  320. (fmt->pixelformat >> 16) & 0xff,
  321. (fmt->pixelformat >> 24) & 0xff,
  322. prt_names(fmt->field, v4l2_field_names),
  323. fmt->bytesperline, fmt->sizeimage, fmt->colorspace);
  324. };
  325. static inline void v4l_print_pix_fmt_mplane(struct video_device *vfd,
  326. struct v4l2_pix_format_mplane *fmt)
  327. {
  328. int i;
  329. dbgarg2("width=%d, height=%d, format=%c%c%c%c, field=%s, "
  330. "colorspace=%d, num_planes=%d\n",
  331. fmt->width, fmt->height,
  332. (fmt->pixelformat & 0xff),
  333. (fmt->pixelformat >> 8) & 0xff,
  334. (fmt->pixelformat >> 16) & 0xff,
  335. (fmt->pixelformat >> 24) & 0xff,
  336. prt_names(fmt->field, v4l2_field_names),
  337. fmt->colorspace, fmt->num_planes);
  338. for (i = 0; i < fmt->num_planes; ++i)
  339. dbgarg2("plane %d: bytesperline=%d sizeimage=%d\n", i,
  340. fmt->plane_fmt[i].bytesperline,
  341. fmt->plane_fmt[i].sizeimage);
  342. }
  343. static inline void v4l_print_ext_ctrls(unsigned int cmd,
  344. struct video_device *vfd, struct v4l2_ext_controls *c, int show_vals)
  345. {
  346. __u32 i;
  347. if (!(vfd->debug & V4L2_DEBUG_IOCTL_ARG))
  348. return;
  349. dbgarg(cmd, "");
  350. printk(KERN_CONT "class=0x%x", c->ctrl_class);
  351. for (i = 0; i < c->count; i++) {
  352. if (show_vals && !c->controls[i].size)
  353. printk(KERN_CONT " id/val=0x%x/0x%x",
  354. c->controls[i].id, c->controls[i].value);
  355. else
  356. printk(KERN_CONT " id=0x%x,size=%u",
  357. c->controls[i].id, c->controls[i].size);
  358. }
  359. printk(KERN_CONT "\n");
  360. };
  361. static inline int check_ext_ctrls(struct v4l2_ext_controls *c, int allow_priv)
  362. {
  363. __u32 i;
  364. /* zero the reserved fields */
  365. c->reserved[0] = c->reserved[1] = 0;
  366. for (i = 0; i < c->count; i++)
  367. c->controls[i].reserved2[0] = 0;
  368. /* V4L2_CID_PRIVATE_BASE cannot be used as control class
  369. when using extended controls.
  370. Only when passed in through VIDIOC_G_CTRL and VIDIOC_S_CTRL
  371. is it allowed for backwards compatibility.
  372. */
  373. if (!allow_priv && c->ctrl_class == V4L2_CID_PRIVATE_BASE)
  374. return 0;
  375. /* Check that all controls are from the same control class. */
  376. for (i = 0; i < c->count; i++) {
  377. if (V4L2_CTRL_ID2CLASS(c->controls[i].id) != c->ctrl_class) {
  378. c->error_idx = i;
  379. return 0;
  380. }
  381. }
  382. return 1;
  383. }
  384. static int check_fmt(const struct v4l2_ioctl_ops *ops, enum v4l2_buf_type type)
  385. {
  386. if (ops == NULL)
  387. return -EINVAL;
  388. switch (type) {
  389. case V4L2_BUF_TYPE_VIDEO_CAPTURE:
  390. if (ops->vidioc_g_fmt_vid_cap ||
  391. ops->vidioc_g_fmt_vid_cap_mplane)
  392. return 0;
  393. break;
  394. case V4L2_BUF_TYPE_VIDEO_CAPTURE_MPLANE:
  395. if (ops->vidioc_g_fmt_vid_cap_mplane)
  396. return 0;
  397. break;
  398. case V4L2_BUF_TYPE_VIDEO_OVERLAY:
  399. if (ops->vidioc_g_fmt_vid_overlay)
  400. return 0;
  401. break;
  402. case V4L2_BUF_TYPE_VIDEO_OUTPUT:
  403. if (ops->vidioc_g_fmt_vid_out ||
  404. ops->vidioc_g_fmt_vid_out_mplane)
  405. return 0;
  406. break;
  407. case V4L2_BUF_TYPE_VIDEO_OUTPUT_MPLANE:
  408. if (ops->vidioc_g_fmt_vid_out_mplane)
  409. return 0;
  410. break;
  411. case V4L2_BUF_TYPE_VIDEO_OUTPUT_OVERLAY:
  412. if (ops->vidioc_g_fmt_vid_out_overlay)
  413. return 0;
  414. break;
  415. case V4L2_BUF_TYPE_VBI_CAPTURE:
  416. if (ops->vidioc_g_fmt_vbi_cap)
  417. return 0;
  418. break;
  419. case V4L2_BUF_TYPE_VBI_OUTPUT:
  420. if (ops->vidioc_g_fmt_vbi_out)
  421. return 0;
  422. break;
  423. case V4L2_BUF_TYPE_SLICED_VBI_CAPTURE:
  424. if (ops->vidioc_g_fmt_sliced_vbi_cap)
  425. return 0;
  426. break;
  427. case V4L2_BUF_TYPE_SLICED_VBI_OUTPUT:
  428. if (ops->vidioc_g_fmt_sliced_vbi_out)
  429. return 0;
  430. break;
  431. case V4L2_BUF_TYPE_PRIVATE:
  432. if (ops->vidioc_g_fmt_type_private)
  433. return 0;
  434. break;
  435. }
  436. return -EINVAL;
  437. }
  438. /**
  439. * fmt_sp_to_mp() - Convert a single-plane format to its multi-planar 1-plane
  440. * equivalent
  441. */
  442. static int fmt_sp_to_mp(const struct v4l2_format *f_sp,
  443. struct v4l2_format *f_mp)
  444. {
  445. struct v4l2_pix_format_mplane *pix_mp = &f_mp->fmt.pix_mp;
  446. const struct v4l2_pix_format *pix = &f_sp->fmt.pix;
  447. if (f_sp->type == V4L2_BUF_TYPE_VIDEO_CAPTURE)
  448. f_mp->type = V4L2_BUF_TYPE_VIDEO_CAPTURE_MPLANE;
  449. else if (f_sp->type == V4L2_BUF_TYPE_VIDEO_OUTPUT)
  450. f_mp->type = V4L2_BUF_TYPE_VIDEO_OUTPUT_MPLANE;
  451. else
  452. return -EINVAL;
  453. pix_mp->width = pix->width;
  454. pix_mp->height = pix->height;
  455. pix_mp->pixelformat = pix->pixelformat;
  456. pix_mp->field = pix->field;
  457. pix_mp->colorspace = pix->colorspace;
  458. pix_mp->num_planes = 1;
  459. pix_mp->plane_fmt[0].sizeimage = pix->sizeimage;
  460. pix_mp->plane_fmt[0].bytesperline = pix->bytesperline;
  461. return 0;
  462. }
  463. /**
  464. * fmt_mp_to_sp() - Convert a multi-planar 1-plane format to its single-planar
  465. * equivalent
  466. */
  467. static int fmt_mp_to_sp(const struct v4l2_format *f_mp,
  468. struct v4l2_format *f_sp)
  469. {
  470. const struct v4l2_pix_format_mplane *pix_mp = &f_mp->fmt.pix_mp;
  471. struct v4l2_pix_format *pix = &f_sp->fmt.pix;
  472. if (f_mp->type == V4L2_BUF_TYPE_VIDEO_CAPTURE_MPLANE)
  473. f_sp->type = V4L2_BUF_TYPE_VIDEO_CAPTURE;
  474. else if (f_mp->type == V4L2_BUF_TYPE_VIDEO_OUTPUT_MPLANE)
  475. f_sp->type = V4L2_BUF_TYPE_VIDEO_OUTPUT;
  476. else
  477. return -EINVAL;
  478. pix->width = pix_mp->width;
  479. pix->height = pix_mp->height;
  480. pix->pixelformat = pix_mp->pixelformat;
  481. pix->field = pix_mp->field;
  482. pix->colorspace = pix_mp->colorspace;
  483. pix->sizeimage = pix_mp->plane_fmt[0].sizeimage;
  484. pix->bytesperline = pix_mp->plane_fmt[0].bytesperline;
  485. return 0;
  486. }
  487. static long __video_do_ioctl(struct file *file,
  488. unsigned int cmd, void *arg)
  489. {
  490. struct video_device *vfd = video_devdata(file);
  491. const struct v4l2_ioctl_ops *ops = vfd->ioctl_ops;
  492. void *fh = file->private_data;
  493. struct v4l2_fh *vfh = NULL;
  494. struct v4l2_format f_copy;
  495. int use_fh_prio = 0;
  496. long ret = -ENOTTY;
  497. if (ops == NULL) {
  498. printk(KERN_WARNING "videodev: \"%s\" has no ioctl_ops.\n",
  499. vfd->name);
  500. return ret;
  501. }
  502. if ((vfd->debug & V4L2_DEBUG_IOCTL) &&
  503. !(vfd->debug & V4L2_DEBUG_IOCTL_ARG)) {
  504. v4l_print_ioctl(vfd->name, cmd);
  505. printk(KERN_CONT "\n");
  506. }
  507. if (test_bit(V4L2_FL_USES_V4L2_FH, &vfd->flags)) {
  508. vfh = file->private_data;
  509. use_fh_prio = test_bit(V4L2_FL_USE_FH_PRIO, &vfd->flags);
  510. }
  511. if (use_fh_prio) {
  512. switch (cmd) {
  513. case VIDIOC_S_CTRL:
  514. case VIDIOC_S_STD:
  515. case VIDIOC_S_INPUT:
  516. case VIDIOC_S_OUTPUT:
  517. case VIDIOC_S_TUNER:
  518. case VIDIOC_S_FREQUENCY:
  519. case VIDIOC_S_FMT:
  520. case VIDIOC_S_CROP:
  521. case VIDIOC_S_AUDIO:
  522. case VIDIOC_S_AUDOUT:
  523. case VIDIOC_S_EXT_CTRLS:
  524. case VIDIOC_S_FBUF:
  525. case VIDIOC_S_PRIORITY:
  526. case VIDIOC_S_DV_PRESET:
  527. case VIDIOC_S_DV_TIMINGS:
  528. case VIDIOC_S_JPEGCOMP:
  529. case VIDIOC_S_MODULATOR:
  530. case VIDIOC_S_PARM:
  531. case VIDIOC_S_HW_FREQ_SEEK:
  532. case VIDIOC_ENCODER_CMD:
  533. case VIDIOC_OVERLAY:
  534. case VIDIOC_REQBUFS:
  535. case VIDIOC_STREAMON:
  536. case VIDIOC_STREAMOFF:
  537. ret = v4l2_prio_check(vfd->prio, vfh->prio);
  538. if (ret)
  539. goto exit_prio;
  540. ret = -EINVAL;
  541. break;
  542. }
  543. }
  544. switch (cmd) {
  545. /* --- capabilities ------------------------------------------ */
  546. case VIDIOC_QUERYCAP:
  547. {
  548. struct v4l2_capability *cap = (struct v4l2_capability *)arg;
  549. if (!ops->vidioc_querycap)
  550. break;
  551. cap->version = LINUX_VERSION_CODE;
  552. ret = ops->vidioc_querycap(file, fh, cap);
  553. if (!ret)
  554. dbgarg(cmd, "driver=%s, card=%s, bus=%s, "
  555. "version=0x%08x, "
  556. "capabilities=0x%08x\n",
  557. cap->driver, cap->card, cap->bus_info,
  558. cap->version,
  559. cap->capabilities);
  560. break;
  561. }
  562. /* --- priority ------------------------------------------ */
  563. case VIDIOC_G_PRIORITY:
  564. {
  565. enum v4l2_priority *p = arg;
  566. if (ops->vidioc_g_priority) {
  567. ret = ops->vidioc_g_priority(file, fh, p);
  568. } else if (use_fh_prio) {
  569. *p = v4l2_prio_max(&vfd->v4l2_dev->prio);
  570. ret = 0;
  571. }
  572. if (!ret)
  573. dbgarg(cmd, "priority is %d\n", *p);
  574. break;
  575. }
  576. case VIDIOC_S_PRIORITY:
  577. {
  578. enum v4l2_priority *p = arg;
  579. if (!ops->vidioc_s_priority && !use_fh_prio)
  580. break;
  581. dbgarg(cmd, "setting priority to %d\n", *p);
  582. if (ops->vidioc_s_priority)
  583. ret = ops->vidioc_s_priority(file, fh, *p);
  584. else
  585. ret = v4l2_prio_change(&vfd->v4l2_dev->prio, &vfh->prio, *p);
  586. break;
  587. }
  588. /* --- capture ioctls ---------------------------------------- */
  589. case VIDIOC_ENUM_FMT:
  590. {
  591. struct v4l2_fmtdesc *f = arg;
  592. switch (f->type) {
  593. case V4L2_BUF_TYPE_VIDEO_CAPTURE:
  594. if (ops->vidioc_enum_fmt_vid_cap)
  595. ret = ops->vidioc_enum_fmt_vid_cap(file, fh, f);
  596. break;
  597. case V4L2_BUF_TYPE_VIDEO_CAPTURE_MPLANE:
  598. if (ops->vidioc_enum_fmt_vid_cap_mplane)
  599. ret = ops->vidioc_enum_fmt_vid_cap_mplane(file,
  600. fh, f);
  601. break;
  602. case V4L2_BUF_TYPE_VIDEO_OVERLAY:
  603. if (ops->vidioc_enum_fmt_vid_overlay)
  604. ret = ops->vidioc_enum_fmt_vid_overlay(file,
  605. fh, f);
  606. break;
  607. case V4L2_BUF_TYPE_VIDEO_OUTPUT:
  608. if (ops->vidioc_enum_fmt_vid_out)
  609. ret = ops->vidioc_enum_fmt_vid_out(file, fh, f);
  610. break;
  611. case V4L2_BUF_TYPE_VIDEO_OUTPUT_MPLANE:
  612. if (ops->vidioc_enum_fmt_vid_out_mplane)
  613. ret = ops->vidioc_enum_fmt_vid_out_mplane(file,
  614. fh, f);
  615. break;
  616. case V4L2_BUF_TYPE_PRIVATE:
  617. if (ops->vidioc_enum_fmt_type_private)
  618. ret = ops->vidioc_enum_fmt_type_private(file,
  619. fh, f);
  620. break;
  621. default:
  622. break;
  623. }
  624. if (!ret)
  625. dbgarg(cmd, "index=%d, type=%d, flags=%d, "
  626. "pixelformat=%c%c%c%c, description='%s'\n",
  627. f->index, f->type, f->flags,
  628. (f->pixelformat & 0xff),
  629. (f->pixelformat >> 8) & 0xff,
  630. (f->pixelformat >> 16) & 0xff,
  631. (f->pixelformat >> 24) & 0xff,
  632. f->description);
  633. break;
  634. }
  635. case VIDIOC_G_FMT:
  636. {
  637. struct v4l2_format *f = (struct v4l2_format *)arg;
  638. /* FIXME: Should be one dump per type */
  639. dbgarg(cmd, "type=%s\n", prt_names(f->type, v4l2_type_names));
  640. switch (f->type) {
  641. case V4L2_BUF_TYPE_VIDEO_CAPTURE:
  642. if (ops->vidioc_g_fmt_vid_cap) {
  643. ret = ops->vidioc_g_fmt_vid_cap(file, fh, f);
  644. } else if (ops->vidioc_g_fmt_vid_cap_mplane) {
  645. if (fmt_sp_to_mp(f, &f_copy))
  646. break;
  647. ret = ops->vidioc_g_fmt_vid_cap_mplane(file, fh,
  648. &f_copy);
  649. if (ret)
  650. break;
  651. /* Driver is currently in multi-planar format,
  652. * we can't return it in single-planar API*/
  653. if (f_copy.fmt.pix_mp.num_planes > 1) {
  654. ret = -EBUSY;
  655. break;
  656. }
  657. ret = fmt_mp_to_sp(&f_copy, f);
  658. }
  659. if (!ret)
  660. v4l_print_pix_fmt(vfd, &f->fmt.pix);
  661. break;
  662. case V4L2_BUF_TYPE_VIDEO_CAPTURE_MPLANE:
  663. if (ops->vidioc_g_fmt_vid_cap_mplane) {
  664. ret = ops->vidioc_g_fmt_vid_cap_mplane(file,
  665. fh, f);
  666. } else if (ops->vidioc_g_fmt_vid_cap) {
  667. if (fmt_mp_to_sp(f, &f_copy))
  668. break;
  669. ret = ops->vidioc_g_fmt_vid_cap(file,
  670. fh, &f_copy);
  671. if (ret)
  672. break;
  673. ret = fmt_sp_to_mp(&f_copy, f);
  674. }
  675. if (!ret)
  676. v4l_print_pix_fmt_mplane(vfd, &f->fmt.pix_mp);
  677. break;
  678. case V4L2_BUF_TYPE_VIDEO_OVERLAY:
  679. if (ops->vidioc_g_fmt_vid_overlay)
  680. ret = ops->vidioc_g_fmt_vid_overlay(file,
  681. fh, f);
  682. break;
  683. case V4L2_BUF_TYPE_VIDEO_OUTPUT:
  684. if (ops->vidioc_g_fmt_vid_out) {
  685. ret = ops->vidioc_g_fmt_vid_out(file, fh, f);
  686. } else if (ops->vidioc_g_fmt_vid_out_mplane) {
  687. if (fmt_sp_to_mp(f, &f_copy))
  688. break;
  689. ret = ops->vidioc_g_fmt_vid_out_mplane(file, fh,
  690. &f_copy);
  691. if (ret)
  692. break;
  693. /* Driver is currently in multi-planar format,
  694. * we can't return it in single-planar API*/
  695. if (f_copy.fmt.pix_mp.num_planes > 1) {
  696. ret = -EBUSY;
  697. break;
  698. }
  699. ret = fmt_mp_to_sp(&f_copy, f);
  700. }
  701. if (!ret)
  702. v4l_print_pix_fmt(vfd, &f->fmt.pix);
  703. break;
  704. case V4L2_BUF_TYPE_VIDEO_OUTPUT_MPLANE:
  705. if (ops->vidioc_g_fmt_vid_out_mplane) {
  706. ret = ops->vidioc_g_fmt_vid_out_mplane(file,
  707. fh, f);
  708. } else if (ops->vidioc_g_fmt_vid_out) {
  709. if (fmt_mp_to_sp(f, &f_copy))
  710. break;
  711. ret = ops->vidioc_g_fmt_vid_out(file,
  712. fh, &f_copy);
  713. if (ret)
  714. break;
  715. ret = fmt_sp_to_mp(&f_copy, f);
  716. }
  717. if (!ret)
  718. v4l_print_pix_fmt_mplane(vfd, &f->fmt.pix_mp);
  719. break;
  720. case V4L2_BUF_TYPE_VIDEO_OUTPUT_OVERLAY:
  721. if (ops->vidioc_g_fmt_vid_out_overlay)
  722. ret = ops->vidioc_g_fmt_vid_out_overlay(file,
  723. fh, f);
  724. break;
  725. case V4L2_BUF_TYPE_VBI_CAPTURE:
  726. if (ops->vidioc_g_fmt_vbi_cap)
  727. ret = ops->vidioc_g_fmt_vbi_cap(file, fh, f);
  728. break;
  729. case V4L2_BUF_TYPE_VBI_OUTPUT:
  730. if (ops->vidioc_g_fmt_vbi_out)
  731. ret = ops->vidioc_g_fmt_vbi_out(file, fh, f);
  732. break;
  733. case V4L2_BUF_TYPE_SLICED_VBI_CAPTURE:
  734. if (ops->vidioc_g_fmt_sliced_vbi_cap)
  735. ret = ops->vidioc_g_fmt_sliced_vbi_cap(file,
  736. fh, f);
  737. break;
  738. case V4L2_BUF_TYPE_SLICED_VBI_OUTPUT:
  739. if (ops->vidioc_g_fmt_sliced_vbi_out)
  740. ret = ops->vidioc_g_fmt_sliced_vbi_out(file,
  741. fh, f);
  742. break;
  743. case V4L2_BUF_TYPE_PRIVATE:
  744. if (ops->vidioc_g_fmt_type_private)
  745. ret = ops->vidioc_g_fmt_type_private(file,
  746. fh, f);
  747. break;
  748. }
  749. break;
  750. }
  751. case VIDIOC_S_FMT:
  752. {
  753. struct v4l2_format *f = (struct v4l2_format *)arg;
  754. /* FIXME: Should be one dump per type */
  755. dbgarg(cmd, "type=%s\n", prt_names(f->type, v4l2_type_names));
  756. switch (f->type) {
  757. case V4L2_BUF_TYPE_VIDEO_CAPTURE:
  758. CLEAR_AFTER_FIELD(f, fmt.pix);
  759. v4l_print_pix_fmt(vfd, &f->fmt.pix);
  760. if (ops->vidioc_s_fmt_vid_cap) {
  761. ret = ops->vidioc_s_fmt_vid_cap(file, fh, f);
  762. } else if (ops->vidioc_s_fmt_vid_cap_mplane) {
  763. if (fmt_sp_to_mp(f, &f_copy))
  764. break;
  765. ret = ops->vidioc_s_fmt_vid_cap_mplane(file, fh,
  766. &f_copy);
  767. if (ret)
  768. break;
  769. if (f_copy.fmt.pix_mp.num_planes > 1) {
  770. /* Drivers shouldn't adjust from 1-plane
  771. * to more than 1-plane formats */
  772. ret = -EBUSY;
  773. WARN_ON(1);
  774. break;
  775. }
  776. ret = fmt_mp_to_sp(&f_copy, f);
  777. }
  778. break;
  779. case V4L2_BUF_TYPE_VIDEO_CAPTURE_MPLANE:
  780. CLEAR_AFTER_FIELD(f, fmt.pix_mp);
  781. v4l_print_pix_fmt_mplane(vfd, &f->fmt.pix_mp);
  782. if (ops->vidioc_s_fmt_vid_cap_mplane) {
  783. ret = ops->vidioc_s_fmt_vid_cap_mplane(file,
  784. fh, f);
  785. } else if (ops->vidioc_s_fmt_vid_cap &&
  786. f->fmt.pix_mp.num_planes == 1) {
  787. if (fmt_mp_to_sp(f, &f_copy))
  788. break;
  789. ret = ops->vidioc_s_fmt_vid_cap(file,
  790. fh, &f_copy);
  791. if (ret)
  792. break;
  793. ret = fmt_sp_to_mp(&f_copy, f);
  794. }
  795. break;
  796. case V4L2_BUF_TYPE_VIDEO_OVERLAY:
  797. CLEAR_AFTER_FIELD(f, fmt.win);
  798. if (ops->vidioc_s_fmt_vid_overlay)
  799. ret = ops->vidioc_s_fmt_vid_overlay(file,
  800. fh, f);
  801. break;
  802. case V4L2_BUF_TYPE_VIDEO_OUTPUT:
  803. CLEAR_AFTER_FIELD(f, fmt.pix);
  804. v4l_print_pix_fmt(vfd, &f->fmt.pix);
  805. if (ops->vidioc_s_fmt_vid_out) {
  806. ret = ops->vidioc_s_fmt_vid_out(file, fh, f);
  807. } else if (ops->vidioc_s_fmt_vid_out_mplane) {
  808. if (fmt_sp_to_mp(f, &f_copy))
  809. break;
  810. ret = ops->vidioc_s_fmt_vid_out_mplane(file, fh,
  811. &f_copy);
  812. if (ret)
  813. break;
  814. if (f_copy.fmt.pix_mp.num_planes > 1) {
  815. /* Drivers shouldn't adjust from 1-plane
  816. * to more than 1-plane formats */
  817. ret = -EBUSY;
  818. WARN_ON(1);
  819. break;
  820. }
  821. ret = fmt_mp_to_sp(&f_copy, f);
  822. }
  823. break;
  824. case V4L2_BUF_TYPE_VIDEO_OUTPUT_MPLANE:
  825. CLEAR_AFTER_FIELD(f, fmt.pix_mp);
  826. v4l_print_pix_fmt_mplane(vfd, &f->fmt.pix_mp);
  827. if (ops->vidioc_s_fmt_vid_out_mplane) {
  828. ret = ops->vidioc_s_fmt_vid_out_mplane(file,
  829. fh, f);
  830. } else if (ops->vidioc_s_fmt_vid_out &&
  831. f->fmt.pix_mp.num_planes == 1) {
  832. if (fmt_mp_to_sp(f, &f_copy))
  833. break;
  834. ret = ops->vidioc_s_fmt_vid_out(file,
  835. fh, &f_copy);
  836. if (ret)
  837. break;
  838. ret = fmt_mp_to_sp(&f_copy, f);
  839. }
  840. break;
  841. case V4L2_BUF_TYPE_VIDEO_OUTPUT_OVERLAY:
  842. CLEAR_AFTER_FIELD(f, fmt.win);
  843. if (ops->vidioc_s_fmt_vid_out_overlay)
  844. ret = ops->vidioc_s_fmt_vid_out_overlay(file,
  845. fh, f);
  846. break;
  847. case V4L2_BUF_TYPE_VBI_CAPTURE:
  848. CLEAR_AFTER_FIELD(f, fmt.vbi);
  849. if (ops->vidioc_s_fmt_vbi_cap)
  850. ret = ops->vidioc_s_fmt_vbi_cap(file, fh, f);
  851. break;
  852. case V4L2_BUF_TYPE_VBI_OUTPUT:
  853. CLEAR_AFTER_FIELD(f, fmt.vbi);
  854. if (ops->vidioc_s_fmt_vbi_out)
  855. ret = ops->vidioc_s_fmt_vbi_out(file, fh, f);
  856. break;
  857. case V4L2_BUF_TYPE_SLICED_VBI_CAPTURE:
  858. CLEAR_AFTER_FIELD(f, fmt.sliced);
  859. if (ops->vidioc_s_fmt_sliced_vbi_cap)
  860. ret = ops->vidioc_s_fmt_sliced_vbi_cap(file,
  861. fh, f);
  862. break;
  863. case V4L2_BUF_TYPE_SLICED_VBI_OUTPUT:
  864. CLEAR_AFTER_FIELD(f, fmt.sliced);
  865. if (ops->vidioc_s_fmt_sliced_vbi_out)
  866. ret = ops->vidioc_s_fmt_sliced_vbi_out(file,
  867. fh, f);
  868. break;
  869. case V4L2_BUF_TYPE_PRIVATE:
  870. /* CLEAR_AFTER_FIELD(f, fmt.raw_data); <- does nothing */
  871. if (ops->vidioc_s_fmt_type_private)
  872. ret = ops->vidioc_s_fmt_type_private(file,
  873. fh, f);
  874. break;
  875. }
  876. break;
  877. }
  878. case VIDIOC_TRY_FMT:
  879. {
  880. struct v4l2_format *f = (struct v4l2_format *)arg;
  881. /* FIXME: Should be one dump per type */
  882. dbgarg(cmd, "type=%s\n", prt_names(f->type,
  883. v4l2_type_names));
  884. switch (f->type) {
  885. case V4L2_BUF_TYPE_VIDEO_CAPTURE:
  886. CLEAR_AFTER_FIELD(f, fmt.pix);
  887. if (ops->vidioc_try_fmt_vid_cap) {
  888. ret = ops->vidioc_try_fmt_vid_cap(file, fh, f);
  889. } else if (ops->vidioc_try_fmt_vid_cap_mplane) {
  890. if (fmt_sp_to_mp(f, &f_copy))
  891. break;
  892. ret = ops->vidioc_try_fmt_vid_cap_mplane(file,
  893. fh, &f_copy);
  894. if (ret)
  895. break;
  896. if (f_copy.fmt.pix_mp.num_planes > 1) {
  897. /* Drivers shouldn't adjust from 1-plane
  898. * to more than 1-plane formats */
  899. ret = -EBUSY;
  900. WARN_ON(1);
  901. break;
  902. }
  903. ret = fmt_mp_to_sp(&f_copy, f);
  904. }
  905. if (!ret)
  906. v4l_print_pix_fmt(vfd, &f->fmt.pix);
  907. break;
  908. case V4L2_BUF_TYPE_VIDEO_CAPTURE_MPLANE:
  909. CLEAR_AFTER_FIELD(f, fmt.pix_mp);
  910. if (ops->vidioc_try_fmt_vid_cap_mplane) {
  911. ret = ops->vidioc_try_fmt_vid_cap_mplane(file,
  912. fh, f);
  913. } else if (ops->vidioc_try_fmt_vid_cap &&
  914. f->fmt.pix_mp.num_planes == 1) {
  915. if (fmt_mp_to_sp(f, &f_copy))
  916. break;
  917. ret = ops->vidioc_try_fmt_vid_cap(file,
  918. fh, &f_copy);
  919. if (ret)
  920. break;
  921. ret = fmt_sp_to_mp(&f_copy, f);
  922. }
  923. if (!ret)
  924. v4l_print_pix_fmt_mplane(vfd, &f->fmt.pix_mp);
  925. break;
  926. case V4L2_BUF_TYPE_VIDEO_OVERLAY:
  927. CLEAR_AFTER_FIELD(f, fmt.win);
  928. if (ops->vidioc_try_fmt_vid_overlay)
  929. ret = ops->vidioc_try_fmt_vid_overlay(file,
  930. fh, f);
  931. break;
  932. case V4L2_BUF_TYPE_VIDEO_OUTPUT:
  933. CLEAR_AFTER_FIELD(f, fmt.pix);
  934. if (ops->vidioc_try_fmt_vid_out) {
  935. ret = ops->vidioc_try_fmt_vid_out(file, fh, f);
  936. } else if (ops->vidioc_try_fmt_vid_out_mplane) {
  937. if (fmt_sp_to_mp(f, &f_copy))
  938. break;
  939. ret = ops->vidioc_try_fmt_vid_out_mplane(file,
  940. fh, &f_copy);
  941. if (ret)
  942. break;
  943. if (f_copy.fmt.pix_mp.num_planes > 1) {
  944. /* Drivers shouldn't adjust from 1-plane
  945. * to more than 1-plane formats */
  946. ret = -EBUSY;
  947. WARN_ON(1);
  948. break;
  949. }
  950. ret = fmt_mp_to_sp(&f_copy, f);
  951. }
  952. if (!ret)
  953. v4l_print_pix_fmt(vfd, &f->fmt.pix);
  954. break;
  955. case V4L2_BUF_TYPE_VIDEO_OUTPUT_MPLANE:
  956. CLEAR_AFTER_FIELD(f, fmt.pix_mp);
  957. if (ops->vidioc_try_fmt_vid_out_mplane) {
  958. ret = ops->vidioc_try_fmt_vid_out_mplane(file,
  959. fh, f);
  960. } else if (ops->vidioc_try_fmt_vid_out &&
  961. f->fmt.pix_mp.num_planes == 1) {
  962. if (fmt_mp_to_sp(f, &f_copy))
  963. break;
  964. ret = ops->vidioc_try_fmt_vid_out(file,
  965. fh, &f_copy);
  966. if (ret)
  967. break;
  968. ret = fmt_sp_to_mp(&f_copy, f);
  969. }
  970. if (!ret)
  971. v4l_print_pix_fmt_mplane(vfd, &f->fmt.pix_mp);
  972. break;
  973. case V4L2_BUF_TYPE_VIDEO_OUTPUT_OVERLAY:
  974. CLEAR_AFTER_FIELD(f, fmt.win);
  975. if (ops->vidioc_try_fmt_vid_out_overlay)
  976. ret = ops->vidioc_try_fmt_vid_out_overlay(file,
  977. fh, f);
  978. break;
  979. case V4L2_BUF_TYPE_VBI_CAPTURE:
  980. CLEAR_AFTER_FIELD(f, fmt.vbi);
  981. if (ops->vidioc_try_fmt_vbi_cap)
  982. ret = ops->vidioc_try_fmt_vbi_cap(file, fh, f);
  983. break;
  984. case V4L2_BUF_TYPE_VBI_OUTPUT:
  985. CLEAR_AFTER_FIELD(f, fmt.vbi);
  986. if (ops->vidioc_try_fmt_vbi_out)
  987. ret = ops->vidioc_try_fmt_vbi_out(file, fh, f);
  988. break;
  989. case V4L2_BUF_TYPE_SLICED_VBI_CAPTURE:
  990. CLEAR_AFTER_FIELD(f, fmt.sliced);
  991. if (ops->vidioc_try_fmt_sliced_vbi_cap)
  992. ret = ops->vidioc_try_fmt_sliced_vbi_cap(file,
  993. fh, f);
  994. break;
  995. case V4L2_BUF_TYPE_SLICED_VBI_OUTPUT:
  996. CLEAR_AFTER_FIELD(f, fmt.sliced);
  997. if (ops->vidioc_try_fmt_sliced_vbi_out)
  998. ret = ops->vidioc_try_fmt_sliced_vbi_out(file,
  999. fh, f);
  1000. break;
  1001. case V4L2_BUF_TYPE_PRIVATE:
  1002. /* CLEAR_AFTER_FIELD(f, fmt.raw_data); <- does nothing */
  1003. if (ops->vidioc_try_fmt_type_private)
  1004. ret = ops->vidioc_try_fmt_type_private(file,
  1005. fh, f);
  1006. break;
  1007. }
  1008. break;
  1009. }
  1010. /* FIXME: Those buf reqs could be handled here,
  1011. with some changes on videobuf to allow its header to be included at
  1012. videodev2.h or being merged at videodev2.
  1013. */
  1014. case VIDIOC_REQBUFS:
  1015. {
  1016. struct v4l2_requestbuffers *p = arg;
  1017. if (!ops->vidioc_reqbufs)
  1018. break;
  1019. ret = check_fmt(ops, p->type);
  1020. if (ret)
  1021. break;
  1022. if (p->type < V4L2_BUF_TYPE_PRIVATE)
  1023. CLEAR_AFTER_FIELD(p, memory);
  1024. ret = ops->vidioc_reqbufs(file, fh, p);
  1025. dbgarg(cmd, "count=%d, type=%s, memory=%s\n",
  1026. p->count,
  1027. prt_names(p->type, v4l2_type_names),
  1028. prt_names(p->memory, v4l2_memory_names));
  1029. break;
  1030. }
  1031. case VIDIOC_QUERYBUF:
  1032. {
  1033. struct v4l2_buffer *p = arg;
  1034. if (!ops->vidioc_querybuf)
  1035. break;
  1036. ret = check_fmt(ops, p->type);
  1037. if (ret)
  1038. break;
  1039. ret = ops->vidioc_querybuf(file, fh, p);
  1040. if (!ret)
  1041. dbgbuf(cmd, vfd, p);
  1042. break;
  1043. }
  1044. case VIDIOC_QBUF:
  1045. {
  1046. struct v4l2_buffer *p = arg;
  1047. if (!ops->vidioc_qbuf)
  1048. break;
  1049. ret = check_fmt(ops, p->type);
  1050. if (ret)
  1051. break;
  1052. ret = ops->vidioc_qbuf(file, fh, p);
  1053. if (!ret)
  1054. dbgbuf(cmd, vfd, p);
  1055. break;
  1056. }
  1057. case VIDIOC_DQBUF:
  1058. {
  1059. struct v4l2_buffer *p = arg;
  1060. if (!ops->vidioc_dqbuf)
  1061. break;
  1062. ret = check_fmt(ops, p->type);
  1063. if (ret)
  1064. break;
  1065. ret = ops->vidioc_dqbuf(file, fh, p);
  1066. if (!ret)
  1067. dbgbuf(cmd, vfd, p);
  1068. break;
  1069. }
  1070. case VIDIOC_OVERLAY:
  1071. {
  1072. int *i = arg;
  1073. if (!ops->vidioc_overlay)
  1074. break;
  1075. dbgarg(cmd, "value=%d\n", *i);
  1076. ret = ops->vidioc_overlay(file, fh, *i);
  1077. break;
  1078. }
  1079. case VIDIOC_G_FBUF:
  1080. {
  1081. struct v4l2_framebuffer *p = arg;
  1082. if (!ops->vidioc_g_fbuf)
  1083. break;
  1084. ret = ops->vidioc_g_fbuf(file, fh, arg);
  1085. if (!ret) {
  1086. dbgarg(cmd, "capability=0x%x, flags=%d, base=0x%08lx\n",
  1087. p->capability, p->flags,
  1088. (unsigned long)p->base);
  1089. v4l_print_pix_fmt(vfd, &p->fmt);
  1090. }
  1091. break;
  1092. }
  1093. case VIDIOC_S_FBUF:
  1094. {
  1095. struct v4l2_framebuffer *p = arg;
  1096. if (!ops->vidioc_s_fbuf)
  1097. break;
  1098. dbgarg(cmd, "capability=0x%x, flags=%d, base=0x%08lx\n",
  1099. p->capability, p->flags, (unsigned long)p->base);
  1100. v4l_print_pix_fmt(vfd, &p->fmt);
  1101. ret = ops->vidioc_s_fbuf(file, fh, arg);
  1102. break;
  1103. }
  1104. case VIDIOC_STREAMON:
  1105. {
  1106. enum v4l2_buf_type i = *(int *)arg;
  1107. if (!ops->vidioc_streamon)
  1108. break;
  1109. dbgarg(cmd, "type=%s\n", prt_names(i, v4l2_type_names));
  1110. ret = ops->vidioc_streamon(file, fh, i);
  1111. break;
  1112. }
  1113. case VIDIOC_STREAMOFF:
  1114. {
  1115. enum v4l2_buf_type i = *(int *)arg;
  1116. if (!ops->vidioc_streamoff)
  1117. break;
  1118. dbgarg(cmd, "type=%s\n", prt_names(i, v4l2_type_names));
  1119. ret = ops->vidioc_streamoff(file, fh, i);
  1120. break;
  1121. }
  1122. /* ---------- tv norms ---------- */
  1123. case VIDIOC_ENUMSTD:
  1124. {
  1125. struct v4l2_standard *p = arg;
  1126. v4l2_std_id id = vfd->tvnorms, curr_id = 0;
  1127. unsigned int index = p->index, i, j = 0;
  1128. const char *descr = "";
  1129. /* Return norm array in a canonical way */
  1130. for (i = 0; i <= index && id; i++) {
  1131. /* last std value in the standards array is 0, so this
  1132. while always ends there since (id & 0) == 0. */
  1133. while ((id & standards[j].std) != standards[j].std)
  1134. j++;
  1135. curr_id = standards[j].std;
  1136. descr = standards[j].descr;
  1137. j++;
  1138. if (curr_id == 0)
  1139. break;
  1140. if (curr_id != V4L2_STD_PAL &&
  1141. curr_id != V4L2_STD_SECAM &&
  1142. curr_id != V4L2_STD_NTSC)
  1143. id &= ~curr_id;
  1144. }
  1145. if (i <= index)
  1146. break;
  1147. v4l2_video_std_construct(p, curr_id, descr);
  1148. dbgarg(cmd, "index=%d, id=0x%Lx, name=%s, fps=%d/%d, "
  1149. "framelines=%d\n", p->index,
  1150. (unsigned long long)p->id, p->name,
  1151. p->frameperiod.numerator,
  1152. p->frameperiod.denominator,
  1153. p->framelines);
  1154. ret = 0;
  1155. break;
  1156. }
  1157. case VIDIOC_G_STD:
  1158. {
  1159. v4l2_std_id *id = arg;
  1160. ret = 0;
  1161. /* Calls the specific handler */
  1162. if (ops->vidioc_g_std)
  1163. ret = ops->vidioc_g_std(file, fh, id);
  1164. else if (vfd->current_norm)
  1165. *id = vfd->current_norm;
  1166. else
  1167. ret = -EINVAL;
  1168. if (!ret)
  1169. dbgarg(cmd, "std=0x%08Lx\n", (long long unsigned)*id);
  1170. break;
  1171. }
  1172. case VIDIOC_S_STD:
  1173. {
  1174. v4l2_std_id *id = arg, norm;
  1175. dbgarg(cmd, "std=%08Lx\n", (long long unsigned)*id);
  1176. norm = (*id) & vfd->tvnorms;
  1177. if (vfd->tvnorms && !norm) /* Check if std is supported */
  1178. break;
  1179. /* Calls the specific handler */
  1180. if (ops->vidioc_s_std)
  1181. ret = ops->vidioc_s_std(file, fh, &norm);
  1182. else
  1183. ret = -EINVAL;
  1184. /* Updates standard information */
  1185. if (ret >= 0)
  1186. vfd->current_norm = norm;
  1187. break;
  1188. }
  1189. case VIDIOC_QUERYSTD:
  1190. {
  1191. v4l2_std_id *p = arg;
  1192. if (!ops->vidioc_querystd)
  1193. break;
  1194. ret = ops->vidioc_querystd(file, fh, arg);
  1195. if (!ret)
  1196. dbgarg(cmd, "detected std=%08Lx\n",
  1197. (unsigned long long)*p);
  1198. break;
  1199. }
  1200. /* ------ input switching ---------- */
  1201. /* FIXME: Inputs can be handled inside videodev2 */
  1202. case VIDIOC_ENUMINPUT:
  1203. {
  1204. struct v4l2_input *p = arg;
  1205. /*
  1206. * We set the flags for CAP_PRESETS, CAP_CUSTOM_TIMINGS &
  1207. * CAP_STD here based on ioctl handler provided by the
  1208. * driver. If the driver doesn't support these
  1209. * for a specific input, it must override these flags.
  1210. */
  1211. if (ops->vidioc_s_std)
  1212. p->capabilities |= V4L2_IN_CAP_STD;
  1213. if (ops->vidioc_s_dv_preset)
  1214. p->capabilities |= V4L2_IN_CAP_PRESETS;
  1215. if (ops->vidioc_s_dv_timings)
  1216. p->capabilities |= V4L2_IN_CAP_CUSTOM_TIMINGS;
  1217. if (!ops->vidioc_enum_input)
  1218. break;
  1219. ret = ops->vidioc_enum_input(file, fh, p);
  1220. if (!ret)
  1221. dbgarg(cmd, "index=%d, name=%s, type=%d, "
  1222. "audioset=%d, "
  1223. "tuner=%d, std=%08Lx, status=%d\n",
  1224. p->index, p->name, p->type, p->audioset,
  1225. p->tuner,
  1226. (unsigned long long)p->std,
  1227. p->status);
  1228. break;
  1229. }
  1230. case VIDIOC_G_INPUT:
  1231. {
  1232. unsigned int *i = arg;
  1233. if (!ops->vidioc_g_input)
  1234. break;
  1235. ret = ops->vidioc_g_input(file, fh, i);
  1236. if (!ret)
  1237. dbgarg(cmd, "value=%d\n", *i);
  1238. break;
  1239. }
  1240. case VIDIOC_S_INPUT:
  1241. {
  1242. unsigned int *i = arg;
  1243. if (!ops->vidioc_s_input)
  1244. break;
  1245. dbgarg(cmd, "value=%d\n", *i);
  1246. ret = ops->vidioc_s_input(file, fh, *i);
  1247. break;
  1248. }
  1249. /* ------ output switching ---------- */
  1250. case VIDIOC_ENUMOUTPUT:
  1251. {
  1252. struct v4l2_output *p = arg;
  1253. if (!ops->vidioc_enum_output)
  1254. break;
  1255. /*
  1256. * We set the flags for CAP_PRESETS, CAP_CUSTOM_TIMINGS &
  1257. * CAP_STD here based on ioctl handler provided by the
  1258. * driver. If the driver doesn't support these
  1259. * for a specific output, it must override these flags.
  1260. */
  1261. if (ops->vidioc_s_std)
  1262. p->capabilities |= V4L2_OUT_CAP_STD;
  1263. if (ops->vidioc_s_dv_preset)
  1264. p->capabilities |= V4L2_OUT_CAP_PRESETS;
  1265. if (ops->vidioc_s_dv_timings)
  1266. p->capabilities |= V4L2_OUT_CAP_CUSTOM_TIMINGS;
  1267. ret = ops->vidioc_enum_output(file, fh, p);
  1268. if (!ret)
  1269. dbgarg(cmd, "index=%d, name=%s, type=%d, "
  1270. "audioset=0x%x, "
  1271. "modulator=%d, std=0x%08Lx\n",
  1272. p->index, p->name, p->type, p->audioset,
  1273. p->modulator, (unsigned long long)p->std);
  1274. break;
  1275. }
  1276. case VIDIOC_G_OUTPUT:
  1277. {
  1278. unsigned int *i = arg;
  1279. if (!ops->vidioc_g_output)
  1280. break;
  1281. ret = ops->vidioc_g_output(file, fh, i);
  1282. if (!ret)
  1283. dbgarg(cmd, "value=%d\n", *i);
  1284. break;
  1285. }
  1286. case VIDIOC_S_OUTPUT:
  1287. {
  1288. unsigned int *i = arg;
  1289. if (!ops->vidioc_s_output)
  1290. break;
  1291. dbgarg(cmd, "value=%d\n", *i);
  1292. ret = ops->vidioc_s_output(file, fh, *i);
  1293. break;
  1294. }
  1295. /* --- controls ---------------------------------------------- */
  1296. case VIDIOC_QUERYCTRL:
  1297. {
  1298. struct v4l2_queryctrl *p = arg;
  1299. if (vfh && vfh->ctrl_handler)
  1300. ret = v4l2_queryctrl(vfh->ctrl_handler, p);
  1301. else if (vfd->ctrl_handler)
  1302. ret = v4l2_queryctrl(vfd->ctrl_handler, p);
  1303. else if (ops->vidioc_queryctrl)
  1304. ret = ops->vidioc_queryctrl(file, fh, p);
  1305. else
  1306. break;
  1307. if (!ret)
  1308. dbgarg(cmd, "id=0x%x, type=%d, name=%s, min/max=%d/%d, "
  1309. "step=%d, default=%d, flags=0x%08x\n",
  1310. p->id, p->type, p->name,
  1311. p->minimum, p->maximum,
  1312. p->step, p->default_value, p->flags);
  1313. else
  1314. dbgarg(cmd, "id=0x%x\n", p->id);
  1315. break;
  1316. }
  1317. case VIDIOC_G_CTRL:
  1318. {
  1319. struct v4l2_control *p = arg;
  1320. if (vfh && vfh->ctrl_handler)
  1321. ret = v4l2_g_ctrl(vfh->ctrl_handler, p);
  1322. else if (vfd->ctrl_handler)
  1323. ret = v4l2_g_ctrl(vfd->ctrl_handler, p);
  1324. else if (ops->vidioc_g_ctrl)
  1325. ret = ops->vidioc_g_ctrl(file, fh, p);
  1326. else if (ops->vidioc_g_ext_ctrls) {
  1327. struct v4l2_ext_controls ctrls;
  1328. struct v4l2_ext_control ctrl;
  1329. ctrls.ctrl_class = V4L2_CTRL_ID2CLASS(p->id);
  1330. ctrls.count = 1;
  1331. ctrls.controls = &ctrl;
  1332. ctrl.id = p->id;
  1333. ctrl.value = p->value;
  1334. if (check_ext_ctrls(&ctrls, 1)) {
  1335. ret = ops->vidioc_g_ext_ctrls(file, fh, &ctrls);
  1336. if (ret == 0)
  1337. p->value = ctrl.value;
  1338. }
  1339. } else
  1340. break;
  1341. if (!ret)
  1342. dbgarg(cmd, "id=0x%x, value=%d\n", p->id, p->value);
  1343. else
  1344. dbgarg(cmd, "id=0x%x\n", p->id);
  1345. break;
  1346. }
  1347. case VIDIOC_S_CTRL:
  1348. {
  1349. struct v4l2_control *p = arg;
  1350. struct v4l2_ext_controls ctrls;
  1351. struct v4l2_ext_control ctrl;
  1352. if (!(vfh && vfh->ctrl_handler) && !vfd->ctrl_handler &&
  1353. !ops->vidioc_s_ctrl && !ops->vidioc_s_ext_ctrls)
  1354. break;
  1355. dbgarg(cmd, "id=0x%x, value=%d\n", p->id, p->value);
  1356. if (vfh && vfh->ctrl_handler) {
  1357. ret = v4l2_s_ctrl(vfh, vfh->ctrl_handler, p);
  1358. break;
  1359. }
  1360. if (vfd->ctrl_handler) {
  1361. ret = v4l2_s_ctrl(NULL, vfd->ctrl_handler, p);
  1362. break;
  1363. }
  1364. if (ops->vidioc_s_ctrl) {
  1365. ret = ops->vidioc_s_ctrl(file, fh, p);
  1366. break;
  1367. }
  1368. if (!ops->vidioc_s_ext_ctrls)
  1369. break;
  1370. ctrls.ctrl_class = V4L2_CTRL_ID2CLASS(p->id);
  1371. ctrls.count = 1;
  1372. ctrls.controls = &ctrl;
  1373. ctrl.id = p->id;
  1374. ctrl.value = p->value;
  1375. if (check_ext_ctrls(&ctrls, 1))
  1376. ret = ops->vidioc_s_ext_ctrls(file, fh, &ctrls);
  1377. break;
  1378. }
  1379. case VIDIOC_G_EXT_CTRLS:
  1380. {
  1381. struct v4l2_ext_controls *p = arg;
  1382. p->error_idx = p->count;
  1383. if (vfh && vfh->ctrl_handler)
  1384. ret = v4l2_g_ext_ctrls(vfh->ctrl_handler, p);
  1385. else if (vfd->ctrl_handler)
  1386. ret = v4l2_g_ext_ctrls(vfd->ctrl_handler, p);
  1387. else if (ops->vidioc_g_ext_ctrls && check_ext_ctrls(p, 0))
  1388. ret = ops->vidioc_g_ext_ctrls(file, fh, p);
  1389. else
  1390. break;
  1391. v4l_print_ext_ctrls(cmd, vfd, p, !ret);
  1392. break;
  1393. }
  1394. case VIDIOC_S_EXT_CTRLS:
  1395. {
  1396. struct v4l2_ext_controls *p = arg;
  1397. p->error_idx = p->count;
  1398. if (!(vfh && vfh->ctrl_handler) && !vfd->ctrl_handler &&
  1399. !ops->vidioc_s_ext_ctrls)
  1400. break;
  1401. v4l_print_ext_ctrls(cmd, vfd, p, 1);
  1402. if (vfh && vfh->ctrl_handler)
  1403. ret = v4l2_s_ext_ctrls(vfh, vfh->ctrl_handler, p);
  1404. else if (vfd->ctrl_handler)
  1405. ret = v4l2_s_ext_ctrls(NULL, vfd->ctrl_handler, p);
  1406. else if (check_ext_ctrls(p, 0))
  1407. ret = ops->vidioc_s_ext_ctrls(file, fh, p);
  1408. break;
  1409. }
  1410. case VIDIOC_TRY_EXT_CTRLS:
  1411. {
  1412. struct v4l2_ext_controls *p = arg;
  1413. p->error_idx = p->count;
  1414. if (!(vfh && vfh->ctrl_handler) && !vfd->ctrl_handler &&
  1415. !ops->vidioc_try_ext_ctrls)
  1416. break;
  1417. v4l_print_ext_ctrls(cmd, vfd, p, 1);
  1418. if (vfh && vfh->ctrl_handler)
  1419. ret = v4l2_try_ext_ctrls(vfh->ctrl_handler, p);
  1420. else if (vfd->ctrl_handler)
  1421. ret = v4l2_try_ext_ctrls(vfd->ctrl_handler, p);
  1422. else if (check_ext_ctrls(p, 0))
  1423. ret = ops->vidioc_try_ext_ctrls(file, fh, p);
  1424. break;
  1425. }
  1426. case VIDIOC_QUERYMENU:
  1427. {
  1428. struct v4l2_querymenu *p = arg;
  1429. if (vfh && vfh->ctrl_handler)
  1430. ret = v4l2_querymenu(vfh->ctrl_handler, p);
  1431. else if (vfd->ctrl_handler)
  1432. ret = v4l2_querymenu(vfd->ctrl_handler, p);
  1433. else if (ops->vidioc_querymenu)
  1434. ret = ops->vidioc_querymenu(file, fh, p);
  1435. else
  1436. break;
  1437. if (!ret)
  1438. dbgarg(cmd, "id=0x%x, index=%d, name=%s\n",
  1439. p->id, p->index, p->name);
  1440. else
  1441. dbgarg(cmd, "id=0x%x, index=%d\n",
  1442. p->id, p->index);
  1443. break;
  1444. }
  1445. /* --- audio ---------------------------------------------- */
  1446. case VIDIOC_ENUMAUDIO:
  1447. {
  1448. struct v4l2_audio *p = arg;
  1449. if (!ops->vidioc_enumaudio)
  1450. break;
  1451. ret = ops->vidioc_enumaudio(file, fh, p);
  1452. if (!ret)
  1453. dbgarg(cmd, "index=%d, name=%s, capability=0x%x, "
  1454. "mode=0x%x\n", p->index, p->name,
  1455. p->capability, p->mode);
  1456. else
  1457. dbgarg(cmd, "index=%d\n", p->index);
  1458. break;
  1459. }
  1460. case VIDIOC_G_AUDIO:
  1461. {
  1462. struct v4l2_audio *p = arg;
  1463. if (!ops->vidioc_g_audio)
  1464. break;
  1465. ret = ops->vidioc_g_audio(file, fh, p);
  1466. if (!ret)
  1467. dbgarg(cmd, "index=%d, name=%s, capability=0x%x, "
  1468. "mode=0x%x\n", p->index,
  1469. p->name, p->capability, p->mode);
  1470. else
  1471. dbgarg(cmd, "index=%d\n", p->index);
  1472. break;
  1473. }
  1474. case VIDIOC_S_AUDIO:
  1475. {
  1476. struct v4l2_audio *p = arg;
  1477. if (!ops->vidioc_s_audio)
  1478. break;
  1479. dbgarg(cmd, "index=%d, name=%s, capability=0x%x, "
  1480. "mode=0x%x\n", p->index, p->name,
  1481. p->capability, p->mode);
  1482. ret = ops->vidioc_s_audio(file, fh, p);
  1483. break;
  1484. }
  1485. case VIDIOC_ENUMAUDOUT:
  1486. {
  1487. struct v4l2_audioout *p = arg;
  1488. if (!ops->vidioc_enumaudout)
  1489. break;
  1490. dbgarg(cmd, "Enum for index=%d\n", p->index);
  1491. ret = ops->vidioc_enumaudout(file, fh, p);
  1492. if (!ret)
  1493. dbgarg2("index=%d, name=%s, capability=%d, "
  1494. "mode=%d\n", p->index, p->name,
  1495. p->capability, p->mode);
  1496. break;
  1497. }
  1498. case VIDIOC_G_AUDOUT:
  1499. {
  1500. struct v4l2_audioout *p = arg;
  1501. if (!ops->vidioc_g_audout)
  1502. break;
  1503. ret = ops->vidioc_g_audout(file, fh, p);
  1504. if (!ret)
  1505. dbgarg2("index=%d, name=%s, capability=%d, "
  1506. "mode=%d\n", p->index, p->name,
  1507. p->capability, p->mode);
  1508. break;
  1509. }
  1510. case VIDIOC_S_AUDOUT:
  1511. {
  1512. struct v4l2_audioout *p = arg;
  1513. if (!ops->vidioc_s_audout)
  1514. break;
  1515. dbgarg(cmd, "index=%d, name=%s, capability=%d, "
  1516. "mode=%d\n", p->index, p->name,
  1517. p->capability, p->mode);
  1518. ret = ops->vidioc_s_audout(file, fh, p);
  1519. break;
  1520. }
  1521. case VIDIOC_G_MODULATOR:
  1522. {
  1523. struct v4l2_modulator *p = arg;
  1524. if (!ops->vidioc_g_modulator)
  1525. break;
  1526. ret = ops->vidioc_g_modulator(file, fh, p);
  1527. if (!ret)
  1528. dbgarg(cmd, "index=%d, name=%s, "
  1529. "capability=%d, rangelow=%d,"
  1530. " rangehigh=%d, txsubchans=%d\n",
  1531. p->index, p->name, p->capability,
  1532. p->rangelow, p->rangehigh,
  1533. p->txsubchans);
  1534. break;
  1535. }
  1536. case VIDIOC_S_MODULATOR:
  1537. {
  1538. struct v4l2_modulator *p = arg;
  1539. if (!ops->vidioc_s_modulator)
  1540. break;
  1541. dbgarg(cmd, "index=%d, name=%s, capability=%d, "
  1542. "rangelow=%d, rangehigh=%d, txsubchans=%d\n",
  1543. p->index, p->name, p->capability, p->rangelow,
  1544. p->rangehigh, p->txsubchans);
  1545. ret = ops->vidioc_s_modulator(file, fh, p);
  1546. break;
  1547. }
  1548. case VIDIOC_G_CROP:
  1549. {
  1550. struct v4l2_crop *p = arg;
  1551. if (!ops->vidioc_g_crop)
  1552. break;
  1553. dbgarg(cmd, "type=%s\n", prt_names(p->type, v4l2_type_names));
  1554. ret = ops->vidioc_g_crop(file, fh, p);
  1555. if (!ret)
  1556. dbgrect(vfd, "", &p->c);
  1557. break;
  1558. }
  1559. case VIDIOC_S_CROP:
  1560. {
  1561. struct v4l2_crop *p = arg;
  1562. if (!ops->vidioc_s_crop)
  1563. break;
  1564. dbgarg(cmd, "type=%s\n", prt_names(p->type, v4l2_type_names));
  1565. dbgrect(vfd, "", &p->c);
  1566. ret = ops->vidioc_s_crop(file, fh, p);
  1567. break;
  1568. }
  1569. case VIDIOC_CROPCAP:
  1570. {
  1571. struct v4l2_cropcap *p = arg;
  1572. /*FIXME: Should also show v4l2_fract pixelaspect */
  1573. if (!ops->vidioc_cropcap)
  1574. break;
  1575. dbgarg(cmd, "type=%s\n", prt_names(p->type, v4l2_type_names));
  1576. ret = ops->vidioc_cropcap(file, fh, p);
  1577. if (!ret) {
  1578. dbgrect(vfd, "bounds ", &p->bounds);
  1579. dbgrect(vfd, "defrect ", &p->defrect);
  1580. }
  1581. break;
  1582. }
  1583. case VIDIOC_G_JPEGCOMP:
  1584. {
  1585. struct v4l2_jpegcompression *p = arg;
  1586. if (!ops->vidioc_g_jpegcomp)
  1587. break;
  1588. ret = ops->vidioc_g_jpegcomp(file, fh, p);
  1589. if (!ret)
  1590. dbgarg(cmd, "quality=%d, APPn=%d, "
  1591. "APP_len=%d, COM_len=%d, "
  1592. "jpeg_markers=%d\n",
  1593. p->quality, p->APPn, p->APP_len,
  1594. p->COM_len, p->jpeg_markers);
  1595. break;
  1596. }
  1597. case VIDIOC_S_JPEGCOMP:
  1598. {
  1599. struct v4l2_jpegcompression *p = arg;
  1600. if (!ops->vidioc_g_jpegcomp)
  1601. break;
  1602. dbgarg(cmd, "quality=%d, APPn=%d, APP_len=%d, "
  1603. "COM_len=%d, jpeg_markers=%d\n",
  1604. p->quality, p->APPn, p->APP_len,
  1605. p->COM_len, p->jpeg_markers);
  1606. ret = ops->vidioc_s_jpegcomp(file, fh, p);
  1607. break;
  1608. }
  1609. case VIDIOC_G_ENC_INDEX:
  1610. {
  1611. struct v4l2_enc_idx *p = arg;
  1612. if (!ops->vidioc_g_enc_index)
  1613. break;
  1614. ret = ops->vidioc_g_enc_index(file, fh, p);
  1615. if (!ret)
  1616. dbgarg(cmd, "entries=%d, entries_cap=%d\n",
  1617. p->entries, p->entries_cap);
  1618. break;
  1619. }
  1620. case VIDIOC_ENCODER_CMD:
  1621. {
  1622. struct v4l2_encoder_cmd *p = arg;
  1623. if (!ops->vidioc_encoder_cmd)
  1624. break;
  1625. ret = ops->vidioc_encoder_cmd(file, fh, p);
  1626. if (!ret)
  1627. dbgarg(cmd, "cmd=%d, flags=%x\n", p->cmd, p->flags);
  1628. break;
  1629. }
  1630. case VIDIOC_TRY_ENCODER_CMD:
  1631. {
  1632. struct v4l2_encoder_cmd *p = arg;
  1633. if (!ops->vidioc_try_encoder_cmd)
  1634. break;
  1635. ret = ops->vidioc_try_encoder_cmd(file, fh, p);
  1636. if (!ret)
  1637. dbgarg(cmd, "cmd=%d, flags=%x\n", p->cmd, p->flags);
  1638. break;
  1639. }
  1640. case VIDIOC_G_PARM:
  1641. {
  1642. struct v4l2_streamparm *p = arg;
  1643. if (ops->vidioc_g_parm) {
  1644. ret = check_fmt(ops, p->type);
  1645. if (ret)
  1646. break;
  1647. ret = ops->vidioc_g_parm(file, fh, p);
  1648. } else {
  1649. v4l2_std_id std = vfd->current_norm;
  1650. if (p->type != V4L2_BUF_TYPE_VIDEO_CAPTURE)
  1651. break;
  1652. ret = 0;
  1653. if (ops->vidioc_g_std)
  1654. ret = ops->vidioc_g_std(file, fh, &std);
  1655. else if (std == 0)
  1656. ret = -EINVAL;
  1657. if (ret == 0)
  1658. v4l2_video_std_frame_period(std,
  1659. &p->parm.capture.timeperframe);
  1660. }
  1661. dbgarg(cmd, "type=%d\n", p->type);
  1662. break;
  1663. }
  1664. case VIDIOC_S_PARM:
  1665. {
  1666. struct v4l2_streamparm *p = arg;
  1667. if (!ops->vidioc_s_parm)
  1668. break;
  1669. ret = check_fmt(ops, p->type);
  1670. if (ret)
  1671. break;
  1672. dbgarg(cmd, "type=%d\n", p->type);
  1673. ret = ops->vidioc_s_parm(file, fh, p);
  1674. break;
  1675. }
  1676. case VIDIOC_G_TUNER:
  1677. {
  1678. struct v4l2_tuner *p = arg;
  1679. if (!ops->vidioc_g_tuner)
  1680. break;
  1681. p->type = (vfd->vfl_type == VFL_TYPE_RADIO) ?
  1682. V4L2_TUNER_RADIO : V4L2_TUNER_ANALOG_TV;
  1683. ret = ops->vidioc_g_tuner(file, fh, p);
  1684. if (!ret)
  1685. dbgarg(cmd, "index=%d, name=%s, type=%d, "
  1686. "capability=0x%x, rangelow=%d, "
  1687. "rangehigh=%d, signal=%d, afc=%d, "
  1688. "rxsubchans=0x%x, audmode=%d\n",
  1689. p->index, p->name, p->type,
  1690. p->capability, p->rangelow,
  1691. p->rangehigh, p->signal, p->afc,
  1692. p->rxsubchans, p->audmode);
  1693. break;
  1694. }
  1695. case VIDIOC_S_TUNER:
  1696. {
  1697. struct v4l2_tuner *p = arg;
  1698. if (!ops->vidioc_s_tuner)
  1699. break;
  1700. p->type = (vfd->vfl_type == VFL_TYPE_RADIO) ?
  1701. V4L2_TUNER_RADIO : V4L2_TUNER_ANALOG_TV;
  1702. dbgarg(cmd, "index=%d, name=%s, type=%d, "
  1703. "capability=0x%x, rangelow=%d, "
  1704. "rangehigh=%d, signal=%d, afc=%d, "
  1705. "rxsubchans=0x%x, audmode=%d\n",
  1706. p->index, p->name, p->type,
  1707. p->capability, p->rangelow,
  1708. p->rangehigh, p->signal, p->afc,
  1709. p->rxsubchans, p->audmode);
  1710. ret = ops->vidioc_s_tuner(file, fh, p);
  1711. break;
  1712. }
  1713. case VIDIOC_G_FREQUENCY:
  1714. {
  1715. struct v4l2_frequency *p = arg;
  1716. if (!ops->vidioc_g_frequency)
  1717. break;
  1718. p->type = (vfd->vfl_type == VFL_TYPE_RADIO) ?
  1719. V4L2_TUNER_RADIO : V4L2_TUNER_ANALOG_TV;
  1720. ret = ops->vidioc_g_frequency(file, fh, p);
  1721. if (!ret)
  1722. dbgarg(cmd, "tuner=%d, type=%d, frequency=%d\n",
  1723. p->tuner, p->type, p->frequency);
  1724. break;
  1725. }
  1726. case VIDIOC_S_FREQUENCY:
  1727. {
  1728. struct v4l2_frequency *p = arg;
  1729. if (!ops->vidioc_s_frequency)
  1730. break;
  1731. dbgarg(cmd, "tuner=%d, type=%d, frequency=%d\n",
  1732. p->tuner, p->type, p->frequency);
  1733. ret = ops->vidioc_s_frequency(file, fh, p);
  1734. break;
  1735. }
  1736. case VIDIOC_G_SLICED_VBI_CAP:
  1737. {
  1738. struct v4l2_sliced_vbi_cap *p = arg;
  1739. if (!ops->vidioc_g_sliced_vbi_cap)
  1740. break;
  1741. /* Clear up to type, everything after type is zerod already */
  1742. memset(p, 0, offsetof(struct v4l2_sliced_vbi_cap, type));
  1743. dbgarg(cmd, "type=%s\n", prt_names(p->type, v4l2_type_names));
  1744. ret = ops->vidioc_g_sliced_vbi_cap(file, fh, p);
  1745. if (!ret)
  1746. dbgarg2("service_set=%d\n", p->service_set);
  1747. break;
  1748. }
  1749. case VIDIOC_LOG_STATUS:
  1750. {
  1751. if (!ops->vidioc_log_status)
  1752. break;
  1753. ret = ops->vidioc_log_status(file, fh);
  1754. break;
  1755. }
  1756. #ifdef CONFIG_VIDEO_ADV_DEBUG
  1757. case VIDIOC_DBG_G_REGISTER:
  1758. {
  1759. struct v4l2_dbg_register *p = arg;
  1760. if (ops->vidioc_g_register) {
  1761. if (!capable(CAP_SYS_ADMIN))
  1762. ret = -EPERM;
  1763. else
  1764. ret = ops->vidioc_g_register(file, fh, p);
  1765. }
  1766. break;
  1767. }
  1768. case VIDIOC_DBG_S_REGISTER:
  1769. {
  1770. struct v4l2_dbg_register *p = arg;
  1771. if (ops->vidioc_s_register) {
  1772. if (!capable(CAP_SYS_ADMIN))
  1773. ret = -EPERM;
  1774. else
  1775. ret = ops->vidioc_s_register(file, fh, p);
  1776. }
  1777. break;
  1778. }
  1779. #endif
  1780. case VIDIOC_DBG_G_CHIP_IDENT:
  1781. {
  1782. struct v4l2_dbg_chip_ident *p = arg;
  1783. if (!ops->vidioc_g_chip_ident)
  1784. break;
  1785. p->ident = V4L2_IDENT_NONE;
  1786. p->revision = 0;
  1787. ret = ops->vidioc_g_chip_ident(file, fh, p);
  1788. if (!ret)
  1789. dbgarg(cmd, "chip_ident=%u, revision=0x%x\n", p->ident, p->revision);
  1790. break;
  1791. }
  1792. case VIDIOC_S_HW_FREQ_SEEK:
  1793. {
  1794. struct v4l2_hw_freq_seek *p = arg;
  1795. enum v4l2_tuner_type type;
  1796. if (!ops->vidioc_s_hw_freq_seek)
  1797. break;
  1798. type = (vfd->vfl_type == VFL_TYPE_RADIO) ?
  1799. V4L2_TUNER_RADIO : V4L2_TUNER_ANALOG_TV;
  1800. dbgarg(cmd,
  1801. "tuner=%u, type=%u, seek_upward=%u, wrap_around=%u, spacing=%u\n",
  1802. p->tuner, p->type, p->seek_upward, p->wrap_around, p->spacing);
  1803. if (p->type != type)
  1804. ret = -EINVAL;
  1805. else
  1806. ret = ops->vidioc_s_hw_freq_seek(file, fh, p);
  1807. break;
  1808. }
  1809. case VIDIOC_ENUM_FRAMESIZES:
  1810. {
  1811. struct v4l2_frmsizeenum *p = arg;
  1812. if (!ops->vidioc_enum_framesizes)
  1813. break;
  1814. ret = ops->vidioc_enum_framesizes(file, fh, p);
  1815. dbgarg(cmd,
  1816. "index=%d, pixelformat=%c%c%c%c, type=%d ",
  1817. p->index,
  1818. (p->pixel_format & 0xff),
  1819. (p->pixel_format >> 8) & 0xff,
  1820. (p->pixel_format >> 16) & 0xff,
  1821. (p->pixel_format >> 24) & 0xff,
  1822. p->type);
  1823. switch (p->type) {
  1824. case V4L2_FRMSIZE_TYPE_DISCRETE:
  1825. dbgarg3("width = %d, height=%d\n",
  1826. p->discrete.width, p->discrete.height);
  1827. break;
  1828. case V4L2_FRMSIZE_TYPE_STEPWISE:
  1829. dbgarg3("min %dx%d, max %dx%d, step %dx%d\n",
  1830. p->stepwise.min_width, p->stepwise.min_height,
  1831. p->stepwise.step_width, p->stepwise.step_height,
  1832. p->stepwise.max_width, p->stepwise.max_height);
  1833. break;
  1834. case V4L2_FRMSIZE_TYPE_CONTINUOUS:
  1835. dbgarg3("continuous\n");
  1836. break;
  1837. default:
  1838. dbgarg3("- Unknown type!\n");
  1839. }
  1840. break;
  1841. }
  1842. case VIDIOC_ENUM_FRAMEINTERVALS:
  1843. {
  1844. struct v4l2_frmivalenum *p = arg;
  1845. if (!ops->vidioc_enum_frameintervals)
  1846. break;
  1847. ret = ops->vidioc_enum_frameintervals(file, fh, p);
  1848. dbgarg(cmd,
  1849. "index=%d, pixelformat=%d, width=%d, height=%d, type=%d ",
  1850. p->index, p->pixel_format,
  1851. p->width, p->height, p->type);
  1852. switch (p->type) {
  1853. case V4L2_FRMIVAL_TYPE_DISCRETE:
  1854. dbgarg2("fps=%d/%d\n",
  1855. p->discrete.numerator,
  1856. p->discrete.denominator);
  1857. break;
  1858. case V4L2_FRMIVAL_TYPE_STEPWISE:
  1859. dbgarg2("min=%d/%d, max=%d/%d, step=%d/%d\n",
  1860. p->stepwise.min.numerator,
  1861. p->stepwise.min.denominator,
  1862. p->stepwise.max.numerator,
  1863. p->stepwise.max.denominator,
  1864. p->stepwise.step.numerator,
  1865. p->stepwise.step.denominator);
  1866. break;
  1867. case V4L2_FRMIVAL_TYPE_CONTINUOUS:
  1868. dbgarg2("continuous\n");
  1869. break;
  1870. default:
  1871. dbgarg2("- Unknown type!\n");
  1872. }
  1873. break;
  1874. }
  1875. case VIDIOC_ENUM_DV_PRESETS:
  1876. {
  1877. struct v4l2_dv_enum_preset *p = arg;
  1878. if (!ops->vidioc_enum_dv_presets)
  1879. break;
  1880. ret = ops->vidioc_enum_dv_presets(file, fh, p);
  1881. if (!ret)
  1882. dbgarg(cmd,
  1883. "index=%d, preset=%d, name=%s, width=%d,"
  1884. " height=%d ",
  1885. p->index, p->preset, p->name, p->width,
  1886. p->height);
  1887. break;
  1888. }
  1889. case VIDIOC_S_DV_PRESET:
  1890. {
  1891. struct v4l2_dv_preset *p = arg;
  1892. if (!ops->vidioc_s_dv_preset)
  1893. break;
  1894. dbgarg(cmd, "preset=%d\n", p->preset);
  1895. ret = ops->vidioc_s_dv_preset(file, fh, p);
  1896. break;
  1897. }
  1898. case VIDIOC_G_DV_PRESET:
  1899. {
  1900. struct v4l2_dv_preset *p = arg;
  1901. if (!ops->vidioc_g_dv_preset)
  1902. break;
  1903. ret = ops->vidioc_g_dv_preset(file, fh, p);
  1904. if (!ret)
  1905. dbgarg(cmd, "preset=%d\n", p->preset);
  1906. break;
  1907. }
  1908. case VIDIOC_QUERY_DV_PRESET:
  1909. {
  1910. struct v4l2_dv_preset *p = arg;
  1911. if (!ops->vidioc_query_dv_preset)
  1912. break;
  1913. ret = ops->vidioc_query_dv_preset(file, fh, p);
  1914. if (!ret)
  1915. dbgarg(cmd, "preset=%d\n", p->preset);
  1916. break;
  1917. }
  1918. case VIDIOC_S_DV_TIMINGS:
  1919. {
  1920. struct v4l2_dv_timings *p = arg;
  1921. if (!ops->vidioc_s_dv_timings)
  1922. break;
  1923. switch (p->type) {
  1924. case V4L2_DV_BT_656_1120:
  1925. dbgarg2("bt-656/1120:interlaced=%d, pixelclock=%lld,"
  1926. " width=%d, height=%d, polarities=%x,"
  1927. " hfrontporch=%d, hsync=%d, hbackporch=%d,"
  1928. " vfrontporch=%d, vsync=%d, vbackporch=%d,"
  1929. " il_vfrontporch=%d, il_vsync=%d,"
  1930. " il_vbackporch=%d\n",
  1931. p->bt.interlaced, p->bt.pixelclock,
  1932. p->bt.width, p->bt.height, p->bt.polarities,
  1933. p->bt.hfrontporch, p->bt.hsync,
  1934. p->bt.hbackporch, p->bt.vfrontporch,
  1935. p->bt.vsync, p->bt.vbackporch,
  1936. p->bt.il_vfrontporch, p->bt.il_vsync,
  1937. p->bt.il_vbackporch);
  1938. ret = ops->vidioc_s_dv_timings(file, fh, p);
  1939. break;
  1940. default:
  1941. dbgarg2("Unknown type %d!\n", p->type);
  1942. break;
  1943. }
  1944. break;
  1945. }
  1946. case VIDIOC_G_DV_TIMINGS:
  1947. {
  1948. struct v4l2_dv_timings *p = arg;
  1949. if (!ops->vidioc_g_dv_timings)
  1950. break;
  1951. ret = ops->vidioc_g_dv_timings(file, fh, p);
  1952. if (!ret) {
  1953. switch (p->type) {
  1954. case V4L2_DV_BT_656_1120:
  1955. dbgarg2("bt-656/1120:interlaced=%d,"
  1956. " pixelclock=%lld,"
  1957. " width=%d, height=%d, polarities=%x,"
  1958. " hfrontporch=%d, hsync=%d,"
  1959. " hbackporch=%d, vfrontporch=%d,"
  1960. " vsync=%d, vbackporch=%d,"
  1961. " il_vfrontporch=%d, il_vsync=%d,"
  1962. " il_vbackporch=%d\n",
  1963. p->bt.interlaced, p->bt.pixelclock,
  1964. p->bt.width, p->bt.height,
  1965. p->bt.polarities, p->bt.hfrontporch,
  1966. p->bt.hsync, p->bt.hbackporch,
  1967. p->bt.vfrontporch, p->bt.vsync,
  1968. p->bt.vbackporch, p->bt.il_vfrontporch,
  1969. p->bt.il_vsync, p->bt.il_vbackporch);
  1970. break;
  1971. default:
  1972. dbgarg2("Unknown type %d!\n", p->type);
  1973. break;
  1974. }
  1975. }
  1976. break;
  1977. }
  1978. case VIDIOC_DQEVENT:
  1979. {
  1980. struct v4l2_event *ev = arg;
  1981. if (!ops->vidioc_subscribe_event)
  1982. break;
  1983. ret = v4l2_event_dequeue(fh, ev, file->f_flags & O_NONBLOCK);
  1984. if (ret < 0) {
  1985. dbgarg(cmd, "no pending events?");
  1986. break;
  1987. }
  1988. dbgarg(cmd,
  1989. "pending=%d, type=0x%8.8x, sequence=%d, "
  1990. "timestamp=%lu.%9.9lu ",
  1991. ev->pending, ev->type, ev->sequence,
  1992. ev->timestamp.tv_sec, ev->timestamp.tv_nsec);
  1993. break;
  1994. }
  1995. case VIDIOC_SUBSCRIBE_EVENT:
  1996. {
  1997. struct v4l2_event_subscription *sub = arg;
  1998. if (!ops->vidioc_subscribe_event)
  1999. break;
  2000. ret = ops->vidioc_subscribe_event(fh, sub);
  2001. if (ret < 0) {
  2002. dbgarg(cmd, "failed, ret=%ld", ret);
  2003. break;
  2004. }
  2005. dbgarg(cmd, "type=0x%8.8x", sub->type);
  2006. break;
  2007. }
  2008. case VIDIOC_UNSUBSCRIBE_EVENT:
  2009. {
  2010. struct v4l2_event_subscription *sub = arg;
  2011. if (!ops->vidioc_unsubscribe_event)
  2012. break;
  2013. ret = ops->vidioc_unsubscribe_event(fh, sub);
  2014. if (ret < 0) {
  2015. dbgarg(cmd, "failed, ret=%ld", ret);
  2016. break;
  2017. }
  2018. dbgarg(cmd, "type=0x%8.8x", sub->type);
  2019. break;
  2020. }
  2021. default:
  2022. {
  2023. bool valid_prio = true;
  2024. if (!ops->vidioc_default)
  2025. break;
  2026. if (use_fh_prio)
  2027. valid_prio = v4l2_prio_check(vfd->prio, vfh->prio) >= 0;
  2028. ret = ops->vidioc_default(file, fh, valid_prio, cmd, arg);
  2029. break;
  2030. }
  2031. } /* switch */
  2032. exit_prio:
  2033. if (vfd->debug & V4L2_DEBUG_IOCTL_ARG) {
  2034. if (ret < 0) {
  2035. v4l_print_ioctl(vfd->name, cmd);
  2036. printk(KERN_CONT " error %ld\n", ret);
  2037. }
  2038. }
  2039. return ret;
  2040. }
  2041. /* In some cases, only a few fields are used as input, i.e. when the app sets
  2042. * "index" and then the driver fills in the rest of the structure for the thing
  2043. * with that index. We only need to copy up the first non-input field. */
  2044. static unsigned long cmd_input_size(unsigned int cmd)
  2045. {
  2046. /* Size of structure up to and including 'field' */
  2047. #define CMDINSIZE(cmd, type, field) \
  2048. case VIDIOC_##cmd: \
  2049. return offsetof(struct v4l2_##type, field) + \
  2050. sizeof(((struct v4l2_##type *)0)->field);
  2051. switch (cmd) {
  2052. CMDINSIZE(ENUM_FMT, fmtdesc, type);
  2053. CMDINSIZE(G_FMT, format, type);
  2054. CMDINSIZE(QUERYBUF, buffer, length);
  2055. CMDINSIZE(G_PARM, streamparm, type);
  2056. CMDINSIZE(ENUMSTD, standard, index);
  2057. CMDINSIZE(ENUMINPUT, input, index);
  2058. CMDINSIZE(G_CTRL, control, id);
  2059. CMDINSIZE(G_TUNER, tuner, index);
  2060. CMDINSIZE(QUERYCTRL, queryctrl, id);
  2061. CMDINSIZE(QUERYMENU, querymenu, index);
  2062. CMDINSIZE(ENUMOUTPUT, output, index);
  2063. CMDINSIZE(G_MODULATOR, modulator, index);
  2064. CMDINSIZE(G_FREQUENCY, frequency, tuner);
  2065. CMDINSIZE(CROPCAP, cropcap, type);
  2066. CMDINSIZE(G_CROP, crop, type);
  2067. CMDINSIZE(ENUMAUDIO, audio, index);
  2068. CMDINSIZE(ENUMAUDOUT, audioout, index);
  2069. CMDINSIZE(ENCODER_CMD, encoder_cmd, flags);
  2070. CMDINSIZE(TRY_ENCODER_CMD, encoder_cmd, flags);
  2071. CMDINSIZE(G_SLICED_VBI_CAP, sliced_vbi_cap, type);
  2072. CMDINSIZE(ENUM_FRAMESIZES, frmsizeenum, pixel_format);
  2073. CMDINSIZE(ENUM_FRAMEINTERVALS, frmivalenum, height);
  2074. default:
  2075. return _IOC_SIZE(cmd);
  2076. }
  2077. }
  2078. static int check_array_args(unsigned int cmd, void *parg, size_t *array_size,
  2079. void * __user *user_ptr, void ***kernel_ptr)
  2080. {
  2081. int ret = 0;
  2082. switch (cmd) {
  2083. case VIDIOC_QUERYBUF:
  2084. case VIDIOC_QBUF:
  2085. case VIDIOC_DQBUF: {
  2086. struct v4l2_buffer *buf = parg;
  2087. if (V4L2_TYPE_IS_MULTIPLANAR(buf->type) && buf->length > 0) {
  2088. if (buf->length > VIDEO_MAX_PLANES) {
  2089. ret = -EINVAL;
  2090. break;
  2091. }
  2092. *user_ptr = (void __user *)buf->m.planes;
  2093. *kernel_ptr = (void *)&buf->m.planes;
  2094. *array_size = sizeof(struct v4l2_plane) * buf->length;
  2095. ret = 1;
  2096. }
  2097. break;
  2098. }
  2099. case VIDIOC_S_EXT_CTRLS:
  2100. case VIDIOC_G_EXT_CTRLS:
  2101. case VIDIOC_TRY_EXT_CTRLS: {
  2102. struct v4l2_ext_controls *ctrls = parg;
  2103. if (ctrls->count != 0) {
  2104. *user_ptr = (void __user *)ctrls->controls;
  2105. *kernel_ptr = (void *)&ctrls->controls;
  2106. *array_size = sizeof(struct v4l2_ext_control)
  2107. * ctrls->count;
  2108. ret = 1;
  2109. }
  2110. break;
  2111. }
  2112. }
  2113. return ret;
  2114. }
  2115. long
  2116. video_usercopy(struct file *file, unsigned int cmd, unsigned long arg,
  2117. v4l2_kioctl func)
  2118. {
  2119. char sbuf[128];
  2120. void *mbuf = NULL;
  2121. void *parg = (void *)arg;
  2122. long err = -EINVAL;
  2123. bool has_array_args;
  2124. size_t array_size = 0;
  2125. void __user *user_ptr = NULL;
  2126. void **kernel_ptr = NULL;
  2127. /* Copy arguments into temp kernel buffer */
  2128. if (_IOC_DIR(cmd) != _IOC_NONE) {
  2129. if (_IOC_SIZE(cmd) <= sizeof(sbuf)) {
  2130. parg = sbuf;
  2131. } else {
  2132. /* too big to allocate from stack */
  2133. mbuf = kmalloc(_IOC_SIZE(cmd), GFP_KERNEL);
  2134. if (NULL == mbuf)
  2135. return -ENOMEM;
  2136. parg = mbuf;
  2137. }
  2138. err = -EFAULT;
  2139. if (_IOC_DIR(cmd) & _IOC_WRITE) {
  2140. unsigned long n = cmd_input_size(cmd);
  2141. if (copy_from_user(parg, (void __user *)arg, n))
  2142. goto out;
  2143. /* zero out anything we don't copy from userspace */
  2144. if (n < _IOC_SIZE(cmd))
  2145. memset((u8 *)parg + n, 0, _IOC_SIZE(cmd) - n);
  2146. } else {
  2147. /* read-only ioctl */
  2148. memset(parg, 0, _IOC_SIZE(cmd));
  2149. }
  2150. }
  2151. err = check_array_args(cmd, parg, &array_size, &user_ptr, &kernel_ptr);
  2152. if (err < 0)
  2153. goto out;
  2154. has_array_args = err;
  2155. if (has_array_args) {
  2156. /*
  2157. * When adding new types of array args, make sure that the
  2158. * parent argument to ioctl (which contains the pointer to the
  2159. * array) fits into sbuf (so that mbuf will still remain
  2160. * unused up to here).
  2161. */
  2162. mbuf = kmalloc(array_size, GFP_KERNEL);
  2163. err = -ENOMEM;
  2164. if (NULL == mbuf)
  2165. goto out_array_args;
  2166. err = -EFAULT;
  2167. if (copy_from_user(mbuf, user_ptr, array_size))
  2168. goto out_array_args;
  2169. *kernel_ptr = mbuf;
  2170. }
  2171. /* Handles IOCTL */
  2172. err = func(file, cmd, parg);
  2173. if (err == -ENOIOCTLCMD)
  2174. err = -EINVAL;
  2175. if (has_array_args) {
  2176. *kernel_ptr = user_ptr;
  2177. if (copy_to_user(user_ptr, mbuf, array_size))
  2178. err = -EFAULT;
  2179. goto out_array_args;
  2180. }
  2181. if (err < 0)
  2182. goto out;
  2183. out_array_args:
  2184. /* Copy results into user buffer */
  2185. switch (_IOC_DIR(cmd)) {
  2186. case _IOC_READ:
  2187. case (_IOC_WRITE | _IOC_READ):
  2188. if (copy_to_user((void __user *)arg, parg, _IOC_SIZE(cmd)))
  2189. err = -EFAULT;
  2190. break;
  2191. }
  2192. out:
  2193. kfree(mbuf);
  2194. return err;
  2195. }
  2196. EXPORT_SYMBOL(video_usercopy);
  2197. long video_ioctl2(struct file *file,
  2198. unsigned int cmd, unsigned long arg)
  2199. {
  2200. return video_usercopy(file, cmd, arg, __video_do_ioctl);
  2201. }
  2202. EXPORT_SYMBOL(video_ioctl2);