vivid-ctrls.c 52 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706
  1. /*
  2. * vivid-ctrls.c - control support functions.
  3. *
  4. * Copyright 2014 Cisco Systems, Inc. and/or its affiliates. All rights reserved.
  5. *
  6. * This program is free software; you may redistribute it and/or modify
  7. * it under the terms of the GNU General Public License as published by
  8. * the Free Software Foundation; version 2 of the License.
  9. *
  10. * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
  11. * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
  12. * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
  13. * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
  14. * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
  15. * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
  16. * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
  17. * SOFTWARE.
  18. */
  19. #include <linux/errno.h>
  20. #include <linux/kernel.h>
  21. #include <linux/videodev2.h>
  22. #include <media/v4l2-event.h>
  23. #include <media/v4l2-common.h>
  24. #include "vivid-core.h"
  25. #include "vivid-vid-cap.h"
  26. #include "vivid-vid-out.h"
  27. #include "vivid-vid-common.h"
  28. #include "vivid-radio-common.h"
  29. #include "vivid-osd.h"
  30. #include "vivid-ctrls.h"
  31. #define VIVID_CID_CUSTOM_BASE (V4L2_CID_USER_BASE | 0xf000)
  32. #define VIVID_CID_BUTTON (VIVID_CID_CUSTOM_BASE + 0)
  33. #define VIVID_CID_BOOLEAN (VIVID_CID_CUSTOM_BASE + 1)
  34. #define VIVID_CID_INTEGER (VIVID_CID_CUSTOM_BASE + 2)
  35. #define VIVID_CID_INTEGER64 (VIVID_CID_CUSTOM_BASE + 3)
  36. #define VIVID_CID_MENU (VIVID_CID_CUSTOM_BASE + 4)
  37. #define VIVID_CID_STRING (VIVID_CID_CUSTOM_BASE + 5)
  38. #define VIVID_CID_BITMASK (VIVID_CID_CUSTOM_BASE + 6)
  39. #define VIVID_CID_INTMENU (VIVID_CID_CUSTOM_BASE + 7)
  40. #define VIVID_CID_U32_ARRAY (VIVID_CID_CUSTOM_BASE + 8)
  41. #define VIVID_CID_U16_MATRIX (VIVID_CID_CUSTOM_BASE + 9)
  42. #define VIVID_CID_U8_4D_ARRAY (VIVID_CID_CUSTOM_BASE + 10)
  43. #define VIVID_CID_VIVID_BASE (0x00f00000 | 0xf000)
  44. #define VIVID_CID_VIVID_CLASS (0x00f00000 | 1)
  45. #define VIVID_CID_TEST_PATTERN (VIVID_CID_VIVID_BASE + 0)
  46. #define VIVID_CID_OSD_TEXT_MODE (VIVID_CID_VIVID_BASE + 1)
  47. #define VIVID_CID_HOR_MOVEMENT (VIVID_CID_VIVID_BASE + 2)
  48. #define VIVID_CID_VERT_MOVEMENT (VIVID_CID_VIVID_BASE + 3)
  49. #define VIVID_CID_SHOW_BORDER (VIVID_CID_VIVID_BASE + 4)
  50. #define VIVID_CID_SHOW_SQUARE (VIVID_CID_VIVID_BASE + 5)
  51. #define VIVID_CID_INSERT_SAV (VIVID_CID_VIVID_BASE + 6)
  52. #define VIVID_CID_INSERT_EAV (VIVID_CID_VIVID_BASE + 7)
  53. #define VIVID_CID_VBI_CAP_INTERLACED (VIVID_CID_VIVID_BASE + 8)
  54. #define VIVID_CID_HFLIP (VIVID_CID_VIVID_BASE + 20)
  55. #define VIVID_CID_VFLIP (VIVID_CID_VIVID_BASE + 21)
  56. #define VIVID_CID_STD_ASPECT_RATIO (VIVID_CID_VIVID_BASE + 22)
  57. #define VIVID_CID_DV_TIMINGS_ASPECT_RATIO (VIVID_CID_VIVID_BASE + 23)
  58. #define VIVID_CID_TSTAMP_SRC (VIVID_CID_VIVID_BASE + 24)
  59. #define VIVID_CID_COLORSPACE (VIVID_CID_VIVID_BASE + 25)
  60. #define VIVID_CID_XFER_FUNC (VIVID_CID_VIVID_BASE + 26)
  61. #define VIVID_CID_YCBCR_ENC (VIVID_CID_VIVID_BASE + 27)
  62. #define VIVID_CID_QUANTIZATION (VIVID_CID_VIVID_BASE + 28)
  63. #define VIVID_CID_LIMITED_RGB_RANGE (VIVID_CID_VIVID_BASE + 29)
  64. #define VIVID_CID_ALPHA_MODE (VIVID_CID_VIVID_BASE + 30)
  65. #define VIVID_CID_HAS_CROP_CAP (VIVID_CID_VIVID_BASE + 31)
  66. #define VIVID_CID_HAS_COMPOSE_CAP (VIVID_CID_VIVID_BASE + 32)
  67. #define VIVID_CID_HAS_SCALER_CAP (VIVID_CID_VIVID_BASE + 33)
  68. #define VIVID_CID_HAS_CROP_OUT (VIVID_CID_VIVID_BASE + 34)
  69. #define VIVID_CID_HAS_COMPOSE_OUT (VIVID_CID_VIVID_BASE + 35)
  70. #define VIVID_CID_HAS_SCALER_OUT (VIVID_CID_VIVID_BASE + 36)
  71. #define VIVID_CID_LOOP_VIDEO (VIVID_CID_VIVID_BASE + 37)
  72. #define VIVID_CID_SEQ_WRAP (VIVID_CID_VIVID_BASE + 38)
  73. #define VIVID_CID_TIME_WRAP (VIVID_CID_VIVID_BASE + 39)
  74. #define VIVID_CID_MAX_EDID_BLOCKS (VIVID_CID_VIVID_BASE + 40)
  75. #define VIVID_CID_PERCENTAGE_FILL (VIVID_CID_VIVID_BASE + 41)
  76. #define VIVID_CID_REDUCED_FPS (VIVID_CID_VIVID_BASE + 42)
  77. #define VIVID_CID_STD_SIGNAL_MODE (VIVID_CID_VIVID_BASE + 60)
  78. #define VIVID_CID_STANDARD (VIVID_CID_VIVID_BASE + 61)
  79. #define VIVID_CID_DV_TIMINGS_SIGNAL_MODE (VIVID_CID_VIVID_BASE + 62)
  80. #define VIVID_CID_DV_TIMINGS (VIVID_CID_VIVID_BASE + 63)
  81. #define VIVID_CID_PERC_DROPPED (VIVID_CID_VIVID_BASE + 64)
  82. #define VIVID_CID_DISCONNECT (VIVID_CID_VIVID_BASE + 65)
  83. #define VIVID_CID_DQBUF_ERROR (VIVID_CID_VIVID_BASE + 66)
  84. #define VIVID_CID_QUEUE_SETUP_ERROR (VIVID_CID_VIVID_BASE + 67)
  85. #define VIVID_CID_BUF_PREPARE_ERROR (VIVID_CID_VIVID_BASE + 68)
  86. #define VIVID_CID_START_STR_ERROR (VIVID_CID_VIVID_BASE + 69)
  87. #define VIVID_CID_QUEUE_ERROR (VIVID_CID_VIVID_BASE + 70)
  88. #define VIVID_CID_CLEAR_FB (VIVID_CID_VIVID_BASE + 71)
  89. #define VIVID_CID_RADIO_SEEK_MODE (VIVID_CID_VIVID_BASE + 90)
  90. #define VIVID_CID_RADIO_SEEK_PROG_LIM (VIVID_CID_VIVID_BASE + 91)
  91. #define VIVID_CID_RADIO_RX_RDS_RBDS (VIVID_CID_VIVID_BASE + 92)
  92. #define VIVID_CID_RADIO_RX_RDS_BLOCKIO (VIVID_CID_VIVID_BASE + 93)
  93. #define VIVID_CID_RADIO_TX_RDS_BLOCKIO (VIVID_CID_VIVID_BASE + 94)
  94. #define VIVID_CID_SDR_CAP_FM_DEVIATION (VIVID_CID_VIVID_BASE + 110)
  95. /* General User Controls */
  96. static int vivid_user_gen_s_ctrl(struct v4l2_ctrl *ctrl)
  97. {
  98. struct vivid_dev *dev = container_of(ctrl->handler, struct vivid_dev, ctrl_hdl_user_gen);
  99. switch (ctrl->id) {
  100. case VIVID_CID_DISCONNECT:
  101. v4l2_info(&dev->v4l2_dev, "disconnect\n");
  102. clear_bit(V4L2_FL_REGISTERED, &dev->vid_cap_dev.flags);
  103. clear_bit(V4L2_FL_REGISTERED, &dev->vid_out_dev.flags);
  104. clear_bit(V4L2_FL_REGISTERED, &dev->vbi_cap_dev.flags);
  105. clear_bit(V4L2_FL_REGISTERED, &dev->vbi_out_dev.flags);
  106. clear_bit(V4L2_FL_REGISTERED, &dev->sdr_cap_dev.flags);
  107. clear_bit(V4L2_FL_REGISTERED, &dev->radio_rx_dev.flags);
  108. clear_bit(V4L2_FL_REGISTERED, &dev->radio_tx_dev.flags);
  109. break;
  110. case VIVID_CID_CLEAR_FB:
  111. vivid_clear_fb(dev);
  112. break;
  113. case VIVID_CID_BUTTON:
  114. dev->button_pressed = 30;
  115. break;
  116. }
  117. return 0;
  118. }
  119. static const struct v4l2_ctrl_ops vivid_user_gen_ctrl_ops = {
  120. .s_ctrl = vivid_user_gen_s_ctrl,
  121. };
  122. static const struct v4l2_ctrl_config vivid_ctrl_button = {
  123. .ops = &vivid_user_gen_ctrl_ops,
  124. .id = VIVID_CID_BUTTON,
  125. .name = "Button",
  126. .type = V4L2_CTRL_TYPE_BUTTON,
  127. };
  128. static const struct v4l2_ctrl_config vivid_ctrl_boolean = {
  129. .ops = &vivid_user_gen_ctrl_ops,
  130. .id = VIVID_CID_BOOLEAN,
  131. .name = "Boolean",
  132. .type = V4L2_CTRL_TYPE_BOOLEAN,
  133. .min = 0,
  134. .max = 1,
  135. .step = 1,
  136. .def = 1,
  137. };
  138. static const struct v4l2_ctrl_config vivid_ctrl_int32 = {
  139. .ops = &vivid_user_gen_ctrl_ops,
  140. .id = VIVID_CID_INTEGER,
  141. .name = "Integer 32 Bits",
  142. .type = V4L2_CTRL_TYPE_INTEGER,
  143. .min = 0xffffffff80000000ULL,
  144. .max = 0x7fffffff,
  145. .step = 1,
  146. };
  147. static const struct v4l2_ctrl_config vivid_ctrl_int64 = {
  148. .ops = &vivid_user_gen_ctrl_ops,
  149. .id = VIVID_CID_INTEGER64,
  150. .name = "Integer 64 Bits",
  151. .type = V4L2_CTRL_TYPE_INTEGER64,
  152. .min = 0x8000000000000000ULL,
  153. .max = 0x7fffffffffffffffLL,
  154. .step = 1,
  155. };
  156. static const struct v4l2_ctrl_config vivid_ctrl_u32_array = {
  157. .ops = &vivid_user_gen_ctrl_ops,
  158. .id = VIVID_CID_U32_ARRAY,
  159. .name = "U32 1 Element Array",
  160. .type = V4L2_CTRL_TYPE_U32,
  161. .def = 0x18,
  162. .min = 0x10,
  163. .max = 0x20000,
  164. .step = 1,
  165. .dims = { 1 },
  166. };
  167. static const struct v4l2_ctrl_config vivid_ctrl_u16_matrix = {
  168. .ops = &vivid_user_gen_ctrl_ops,
  169. .id = VIVID_CID_U16_MATRIX,
  170. .name = "U16 8x16 Matrix",
  171. .type = V4L2_CTRL_TYPE_U16,
  172. .def = 0x18,
  173. .min = 0x10,
  174. .max = 0x2000,
  175. .step = 1,
  176. .dims = { 8, 16 },
  177. };
  178. static const struct v4l2_ctrl_config vivid_ctrl_u8_4d_array = {
  179. .ops = &vivid_user_gen_ctrl_ops,
  180. .id = VIVID_CID_U8_4D_ARRAY,
  181. .name = "U8 2x3x4x5 Array",
  182. .type = V4L2_CTRL_TYPE_U8,
  183. .def = 0x18,
  184. .min = 0x10,
  185. .max = 0x20,
  186. .step = 1,
  187. .dims = { 2, 3, 4, 5 },
  188. };
  189. static const char * const vivid_ctrl_menu_strings[] = {
  190. "Menu Item 0 (Skipped)",
  191. "Menu Item 1",
  192. "Menu Item 2 (Skipped)",
  193. "Menu Item 3",
  194. "Menu Item 4",
  195. "Menu Item 5 (Skipped)",
  196. NULL,
  197. };
  198. static const struct v4l2_ctrl_config vivid_ctrl_menu = {
  199. .ops = &vivid_user_gen_ctrl_ops,
  200. .id = VIVID_CID_MENU,
  201. .name = "Menu",
  202. .type = V4L2_CTRL_TYPE_MENU,
  203. .min = 1,
  204. .max = 4,
  205. .def = 3,
  206. .menu_skip_mask = 0x04,
  207. .qmenu = vivid_ctrl_menu_strings,
  208. };
  209. static const struct v4l2_ctrl_config vivid_ctrl_string = {
  210. .ops = &vivid_user_gen_ctrl_ops,
  211. .id = VIVID_CID_STRING,
  212. .name = "String",
  213. .type = V4L2_CTRL_TYPE_STRING,
  214. .min = 2,
  215. .max = 4,
  216. .step = 1,
  217. };
  218. static const struct v4l2_ctrl_config vivid_ctrl_bitmask = {
  219. .ops = &vivid_user_gen_ctrl_ops,
  220. .id = VIVID_CID_BITMASK,
  221. .name = "Bitmask",
  222. .type = V4L2_CTRL_TYPE_BITMASK,
  223. .def = 0x80002000,
  224. .min = 0,
  225. .max = 0x80402010,
  226. .step = 0,
  227. };
  228. static const s64 vivid_ctrl_int_menu_values[] = {
  229. 1, 1, 2, 3, 5, 8, 13, 21, 42,
  230. };
  231. static const struct v4l2_ctrl_config vivid_ctrl_int_menu = {
  232. .ops = &vivid_user_gen_ctrl_ops,
  233. .id = VIVID_CID_INTMENU,
  234. .name = "Integer Menu",
  235. .type = V4L2_CTRL_TYPE_INTEGER_MENU,
  236. .min = 1,
  237. .max = 8,
  238. .def = 4,
  239. .menu_skip_mask = 0x02,
  240. .qmenu_int = vivid_ctrl_int_menu_values,
  241. };
  242. static const struct v4l2_ctrl_config vivid_ctrl_disconnect = {
  243. .ops = &vivid_user_gen_ctrl_ops,
  244. .id = VIVID_CID_DISCONNECT,
  245. .name = "Disconnect",
  246. .type = V4L2_CTRL_TYPE_BUTTON,
  247. };
  248. static const struct v4l2_ctrl_config vivid_ctrl_clear_fb = {
  249. .ops = &vivid_user_gen_ctrl_ops,
  250. .id = VIVID_CID_CLEAR_FB,
  251. .name = "Clear Framebuffer",
  252. .type = V4L2_CTRL_TYPE_BUTTON,
  253. };
  254. /* Video User Controls */
  255. static int vivid_user_vid_g_volatile_ctrl(struct v4l2_ctrl *ctrl)
  256. {
  257. struct vivid_dev *dev = container_of(ctrl->handler, struct vivid_dev, ctrl_hdl_user_vid);
  258. switch (ctrl->id) {
  259. case V4L2_CID_AUTOGAIN:
  260. dev->gain->val = dev->jiffies_vid_cap & 0xff;
  261. break;
  262. }
  263. return 0;
  264. }
  265. static int vivid_user_vid_s_ctrl(struct v4l2_ctrl *ctrl)
  266. {
  267. struct vivid_dev *dev = container_of(ctrl->handler, struct vivid_dev, ctrl_hdl_user_vid);
  268. switch (ctrl->id) {
  269. case V4L2_CID_BRIGHTNESS:
  270. dev->input_brightness[dev->input] = ctrl->val - dev->input * 128;
  271. tpg_s_brightness(&dev->tpg, dev->input_brightness[dev->input]);
  272. break;
  273. case V4L2_CID_CONTRAST:
  274. tpg_s_contrast(&dev->tpg, ctrl->val);
  275. break;
  276. case V4L2_CID_SATURATION:
  277. tpg_s_saturation(&dev->tpg, ctrl->val);
  278. break;
  279. case V4L2_CID_HUE:
  280. tpg_s_hue(&dev->tpg, ctrl->val);
  281. break;
  282. case V4L2_CID_HFLIP:
  283. dev->hflip = ctrl->val;
  284. tpg_s_hflip(&dev->tpg, dev->sensor_hflip ^ dev->hflip);
  285. break;
  286. case V4L2_CID_VFLIP:
  287. dev->vflip = ctrl->val;
  288. tpg_s_vflip(&dev->tpg, dev->sensor_vflip ^ dev->vflip);
  289. break;
  290. case V4L2_CID_ALPHA_COMPONENT:
  291. tpg_s_alpha_component(&dev->tpg, ctrl->val);
  292. break;
  293. }
  294. return 0;
  295. }
  296. static const struct v4l2_ctrl_ops vivid_user_vid_ctrl_ops = {
  297. .g_volatile_ctrl = vivid_user_vid_g_volatile_ctrl,
  298. .s_ctrl = vivid_user_vid_s_ctrl,
  299. };
  300. /* Video Capture Controls */
  301. static int vivid_vid_cap_s_ctrl(struct v4l2_ctrl *ctrl)
  302. {
  303. static const u32 colorspaces[] = {
  304. V4L2_COLORSPACE_SMPTE170M,
  305. V4L2_COLORSPACE_REC709,
  306. V4L2_COLORSPACE_SRGB,
  307. V4L2_COLORSPACE_ADOBERGB,
  308. V4L2_COLORSPACE_BT2020,
  309. V4L2_COLORSPACE_DCI_P3,
  310. V4L2_COLORSPACE_SMPTE240M,
  311. V4L2_COLORSPACE_470_SYSTEM_M,
  312. V4L2_COLORSPACE_470_SYSTEM_BG,
  313. };
  314. struct vivid_dev *dev = container_of(ctrl->handler, struct vivid_dev, ctrl_hdl_vid_cap);
  315. unsigned i;
  316. switch (ctrl->id) {
  317. case VIVID_CID_TEST_PATTERN:
  318. vivid_update_quality(dev);
  319. tpg_s_pattern(&dev->tpg, ctrl->val);
  320. break;
  321. case VIVID_CID_COLORSPACE:
  322. tpg_s_colorspace(&dev->tpg, colorspaces[ctrl->val]);
  323. vivid_send_source_change(dev, TV);
  324. vivid_send_source_change(dev, SVID);
  325. vivid_send_source_change(dev, HDMI);
  326. vivid_send_source_change(dev, WEBCAM);
  327. break;
  328. case VIVID_CID_XFER_FUNC:
  329. tpg_s_xfer_func(&dev->tpg, ctrl->val);
  330. vivid_send_source_change(dev, TV);
  331. vivid_send_source_change(dev, SVID);
  332. vivid_send_source_change(dev, HDMI);
  333. vivid_send_source_change(dev, WEBCAM);
  334. break;
  335. case VIVID_CID_YCBCR_ENC:
  336. tpg_s_ycbcr_enc(&dev->tpg, ctrl->val);
  337. vivid_send_source_change(dev, TV);
  338. vivid_send_source_change(dev, SVID);
  339. vivid_send_source_change(dev, HDMI);
  340. vivid_send_source_change(dev, WEBCAM);
  341. break;
  342. case VIVID_CID_QUANTIZATION:
  343. tpg_s_quantization(&dev->tpg, ctrl->val);
  344. vivid_send_source_change(dev, TV);
  345. vivid_send_source_change(dev, SVID);
  346. vivid_send_source_change(dev, HDMI);
  347. vivid_send_source_change(dev, WEBCAM);
  348. break;
  349. case V4L2_CID_DV_RX_RGB_RANGE:
  350. if (!vivid_is_hdmi_cap(dev))
  351. break;
  352. tpg_s_rgb_range(&dev->tpg, ctrl->val);
  353. break;
  354. case VIVID_CID_LIMITED_RGB_RANGE:
  355. tpg_s_real_rgb_range(&dev->tpg, ctrl->val ?
  356. V4L2_DV_RGB_RANGE_LIMITED : V4L2_DV_RGB_RANGE_FULL);
  357. break;
  358. case VIVID_CID_ALPHA_MODE:
  359. tpg_s_alpha_mode(&dev->tpg, ctrl->val);
  360. break;
  361. case VIVID_CID_HOR_MOVEMENT:
  362. tpg_s_mv_hor_mode(&dev->tpg, ctrl->val);
  363. break;
  364. case VIVID_CID_VERT_MOVEMENT:
  365. tpg_s_mv_vert_mode(&dev->tpg, ctrl->val);
  366. break;
  367. case VIVID_CID_OSD_TEXT_MODE:
  368. dev->osd_mode = ctrl->val;
  369. break;
  370. case VIVID_CID_PERCENTAGE_FILL:
  371. tpg_s_perc_fill(&dev->tpg, ctrl->val);
  372. for (i = 0; i < VIDEO_MAX_FRAME; i++)
  373. dev->must_blank[i] = ctrl->val < 100;
  374. break;
  375. case VIVID_CID_INSERT_SAV:
  376. tpg_s_insert_sav(&dev->tpg, ctrl->val);
  377. break;
  378. case VIVID_CID_INSERT_EAV:
  379. tpg_s_insert_eav(&dev->tpg, ctrl->val);
  380. break;
  381. case VIVID_CID_HFLIP:
  382. dev->sensor_hflip = ctrl->val;
  383. tpg_s_hflip(&dev->tpg, dev->sensor_hflip ^ dev->hflip);
  384. break;
  385. case VIVID_CID_VFLIP:
  386. dev->sensor_vflip = ctrl->val;
  387. tpg_s_vflip(&dev->tpg, dev->sensor_vflip ^ dev->vflip);
  388. break;
  389. case VIVID_CID_REDUCED_FPS:
  390. dev->reduced_fps = ctrl->val;
  391. vivid_update_format_cap(dev, true);
  392. break;
  393. case VIVID_CID_HAS_CROP_CAP:
  394. dev->has_crop_cap = ctrl->val;
  395. vivid_update_format_cap(dev, true);
  396. break;
  397. case VIVID_CID_HAS_COMPOSE_CAP:
  398. dev->has_compose_cap = ctrl->val;
  399. vivid_update_format_cap(dev, true);
  400. break;
  401. case VIVID_CID_HAS_SCALER_CAP:
  402. dev->has_scaler_cap = ctrl->val;
  403. vivid_update_format_cap(dev, true);
  404. break;
  405. case VIVID_CID_SHOW_BORDER:
  406. tpg_s_show_border(&dev->tpg, ctrl->val);
  407. break;
  408. case VIVID_CID_SHOW_SQUARE:
  409. tpg_s_show_square(&dev->tpg, ctrl->val);
  410. break;
  411. case VIVID_CID_STD_ASPECT_RATIO:
  412. dev->std_aspect_ratio = ctrl->val;
  413. tpg_s_video_aspect(&dev->tpg, vivid_get_video_aspect(dev));
  414. break;
  415. case VIVID_CID_DV_TIMINGS_SIGNAL_MODE:
  416. dev->dv_timings_signal_mode = dev->ctrl_dv_timings_signal_mode->val;
  417. if (dev->dv_timings_signal_mode == SELECTED_DV_TIMINGS)
  418. dev->query_dv_timings = dev->ctrl_dv_timings->val;
  419. v4l2_ctrl_activate(dev->ctrl_dv_timings,
  420. dev->dv_timings_signal_mode == SELECTED_DV_TIMINGS);
  421. vivid_update_quality(dev);
  422. vivid_send_source_change(dev, HDMI);
  423. break;
  424. case VIVID_CID_DV_TIMINGS_ASPECT_RATIO:
  425. dev->dv_timings_aspect_ratio = ctrl->val;
  426. tpg_s_video_aspect(&dev->tpg, vivid_get_video_aspect(dev));
  427. break;
  428. case VIVID_CID_TSTAMP_SRC:
  429. dev->tstamp_src_is_soe = ctrl->val;
  430. dev->vb_vid_cap_q.timestamp_flags &= ~V4L2_BUF_FLAG_TSTAMP_SRC_MASK;
  431. if (dev->tstamp_src_is_soe)
  432. dev->vb_vid_cap_q.timestamp_flags |= V4L2_BUF_FLAG_TSTAMP_SRC_SOE;
  433. break;
  434. case VIVID_CID_MAX_EDID_BLOCKS:
  435. dev->edid_max_blocks = ctrl->val;
  436. if (dev->edid_blocks > dev->edid_max_blocks)
  437. dev->edid_blocks = dev->edid_max_blocks;
  438. break;
  439. }
  440. return 0;
  441. }
  442. static const struct v4l2_ctrl_ops vivid_vid_cap_ctrl_ops = {
  443. .s_ctrl = vivid_vid_cap_s_ctrl,
  444. };
  445. static const char * const vivid_ctrl_hor_movement_strings[] = {
  446. "Move Left Fast",
  447. "Move Left",
  448. "Move Left Slow",
  449. "No Movement",
  450. "Move Right Slow",
  451. "Move Right",
  452. "Move Right Fast",
  453. NULL,
  454. };
  455. static const struct v4l2_ctrl_config vivid_ctrl_hor_movement = {
  456. .ops = &vivid_vid_cap_ctrl_ops,
  457. .id = VIVID_CID_HOR_MOVEMENT,
  458. .name = "Horizontal Movement",
  459. .type = V4L2_CTRL_TYPE_MENU,
  460. .max = TPG_MOVE_POS_FAST,
  461. .def = TPG_MOVE_NONE,
  462. .qmenu = vivid_ctrl_hor_movement_strings,
  463. };
  464. static const char * const vivid_ctrl_vert_movement_strings[] = {
  465. "Move Up Fast",
  466. "Move Up",
  467. "Move Up Slow",
  468. "No Movement",
  469. "Move Down Slow",
  470. "Move Down",
  471. "Move Down Fast",
  472. NULL,
  473. };
  474. static const struct v4l2_ctrl_config vivid_ctrl_vert_movement = {
  475. .ops = &vivid_vid_cap_ctrl_ops,
  476. .id = VIVID_CID_VERT_MOVEMENT,
  477. .name = "Vertical Movement",
  478. .type = V4L2_CTRL_TYPE_MENU,
  479. .max = TPG_MOVE_POS_FAST,
  480. .def = TPG_MOVE_NONE,
  481. .qmenu = vivid_ctrl_vert_movement_strings,
  482. };
  483. static const struct v4l2_ctrl_config vivid_ctrl_show_border = {
  484. .ops = &vivid_vid_cap_ctrl_ops,
  485. .id = VIVID_CID_SHOW_BORDER,
  486. .name = "Show Border",
  487. .type = V4L2_CTRL_TYPE_BOOLEAN,
  488. .max = 1,
  489. .step = 1,
  490. };
  491. static const struct v4l2_ctrl_config vivid_ctrl_show_square = {
  492. .ops = &vivid_vid_cap_ctrl_ops,
  493. .id = VIVID_CID_SHOW_SQUARE,
  494. .name = "Show Square",
  495. .type = V4L2_CTRL_TYPE_BOOLEAN,
  496. .max = 1,
  497. .step = 1,
  498. };
  499. static const char * const vivid_ctrl_osd_mode_strings[] = {
  500. "All",
  501. "Counters Only",
  502. "None",
  503. NULL,
  504. };
  505. static const struct v4l2_ctrl_config vivid_ctrl_osd_mode = {
  506. .ops = &vivid_vid_cap_ctrl_ops,
  507. .id = VIVID_CID_OSD_TEXT_MODE,
  508. .name = "OSD Text Mode",
  509. .type = V4L2_CTRL_TYPE_MENU,
  510. .max = ARRAY_SIZE(vivid_ctrl_osd_mode_strings) - 2,
  511. .qmenu = vivid_ctrl_osd_mode_strings,
  512. };
  513. static const struct v4l2_ctrl_config vivid_ctrl_perc_fill = {
  514. .ops = &vivid_vid_cap_ctrl_ops,
  515. .id = VIVID_CID_PERCENTAGE_FILL,
  516. .name = "Fill Percentage of Frame",
  517. .type = V4L2_CTRL_TYPE_INTEGER,
  518. .min = 0,
  519. .max = 100,
  520. .def = 100,
  521. .step = 1,
  522. };
  523. static const struct v4l2_ctrl_config vivid_ctrl_insert_sav = {
  524. .ops = &vivid_vid_cap_ctrl_ops,
  525. .id = VIVID_CID_INSERT_SAV,
  526. .name = "Insert SAV Code in Image",
  527. .type = V4L2_CTRL_TYPE_BOOLEAN,
  528. .max = 1,
  529. .step = 1,
  530. };
  531. static const struct v4l2_ctrl_config vivid_ctrl_insert_eav = {
  532. .ops = &vivid_vid_cap_ctrl_ops,
  533. .id = VIVID_CID_INSERT_EAV,
  534. .name = "Insert EAV Code in Image",
  535. .type = V4L2_CTRL_TYPE_BOOLEAN,
  536. .max = 1,
  537. .step = 1,
  538. };
  539. static const struct v4l2_ctrl_config vivid_ctrl_hflip = {
  540. .ops = &vivid_vid_cap_ctrl_ops,
  541. .id = VIVID_CID_HFLIP,
  542. .name = "Sensor Flipped Horizontally",
  543. .type = V4L2_CTRL_TYPE_BOOLEAN,
  544. .max = 1,
  545. .step = 1,
  546. };
  547. static const struct v4l2_ctrl_config vivid_ctrl_vflip = {
  548. .ops = &vivid_vid_cap_ctrl_ops,
  549. .id = VIVID_CID_VFLIP,
  550. .name = "Sensor Flipped Vertically",
  551. .type = V4L2_CTRL_TYPE_BOOLEAN,
  552. .max = 1,
  553. .step = 1,
  554. };
  555. static const struct v4l2_ctrl_config vivid_ctrl_reduced_fps = {
  556. .ops = &vivid_vid_cap_ctrl_ops,
  557. .id = VIVID_CID_REDUCED_FPS,
  558. .name = "Reduced Framerate",
  559. .type = V4L2_CTRL_TYPE_BOOLEAN,
  560. .max = 1,
  561. .step = 1,
  562. };
  563. static const struct v4l2_ctrl_config vivid_ctrl_has_crop_cap = {
  564. .ops = &vivid_vid_cap_ctrl_ops,
  565. .id = VIVID_CID_HAS_CROP_CAP,
  566. .name = "Enable Capture Cropping",
  567. .type = V4L2_CTRL_TYPE_BOOLEAN,
  568. .max = 1,
  569. .def = 1,
  570. .step = 1,
  571. };
  572. static const struct v4l2_ctrl_config vivid_ctrl_has_compose_cap = {
  573. .ops = &vivid_vid_cap_ctrl_ops,
  574. .id = VIVID_CID_HAS_COMPOSE_CAP,
  575. .name = "Enable Capture Composing",
  576. .type = V4L2_CTRL_TYPE_BOOLEAN,
  577. .max = 1,
  578. .def = 1,
  579. .step = 1,
  580. };
  581. static const struct v4l2_ctrl_config vivid_ctrl_has_scaler_cap = {
  582. .ops = &vivid_vid_cap_ctrl_ops,
  583. .id = VIVID_CID_HAS_SCALER_CAP,
  584. .name = "Enable Capture Scaler",
  585. .type = V4L2_CTRL_TYPE_BOOLEAN,
  586. .max = 1,
  587. .def = 1,
  588. .step = 1,
  589. };
  590. static const char * const vivid_ctrl_tstamp_src_strings[] = {
  591. "End of Frame",
  592. "Start of Exposure",
  593. NULL,
  594. };
  595. static const struct v4l2_ctrl_config vivid_ctrl_tstamp_src = {
  596. .ops = &vivid_vid_cap_ctrl_ops,
  597. .id = VIVID_CID_TSTAMP_SRC,
  598. .name = "Timestamp Source",
  599. .type = V4L2_CTRL_TYPE_MENU,
  600. .max = ARRAY_SIZE(vivid_ctrl_tstamp_src_strings) - 2,
  601. .qmenu = vivid_ctrl_tstamp_src_strings,
  602. };
  603. static const struct v4l2_ctrl_config vivid_ctrl_std_aspect_ratio = {
  604. .ops = &vivid_vid_cap_ctrl_ops,
  605. .id = VIVID_CID_STD_ASPECT_RATIO,
  606. .name = "Standard Aspect Ratio",
  607. .type = V4L2_CTRL_TYPE_MENU,
  608. .min = 1,
  609. .max = 4,
  610. .def = 1,
  611. .qmenu = tpg_aspect_strings,
  612. };
  613. static const char * const vivid_ctrl_dv_timings_signal_mode_strings[] = {
  614. "Current DV Timings",
  615. "No Signal",
  616. "No Lock",
  617. "Out of Range",
  618. "Selected DV Timings",
  619. "Cycle Through All DV Timings",
  620. "Custom DV Timings",
  621. NULL,
  622. };
  623. static const struct v4l2_ctrl_config vivid_ctrl_dv_timings_signal_mode = {
  624. .ops = &vivid_vid_cap_ctrl_ops,
  625. .id = VIVID_CID_DV_TIMINGS_SIGNAL_MODE,
  626. .name = "DV Timings Signal Mode",
  627. .type = V4L2_CTRL_TYPE_MENU,
  628. .max = 5,
  629. .qmenu = vivid_ctrl_dv_timings_signal_mode_strings,
  630. };
  631. static const struct v4l2_ctrl_config vivid_ctrl_dv_timings_aspect_ratio = {
  632. .ops = &vivid_vid_cap_ctrl_ops,
  633. .id = VIVID_CID_DV_TIMINGS_ASPECT_RATIO,
  634. .name = "DV Timings Aspect Ratio",
  635. .type = V4L2_CTRL_TYPE_MENU,
  636. .max = 3,
  637. .qmenu = tpg_aspect_strings,
  638. };
  639. static const struct v4l2_ctrl_config vivid_ctrl_max_edid_blocks = {
  640. .ops = &vivid_vid_cap_ctrl_ops,
  641. .id = VIVID_CID_MAX_EDID_BLOCKS,
  642. .name = "Maximum EDID Blocks",
  643. .type = V4L2_CTRL_TYPE_INTEGER,
  644. .min = 1,
  645. .max = 256,
  646. .def = 2,
  647. .step = 1,
  648. };
  649. static const char * const vivid_ctrl_colorspace_strings[] = {
  650. "SMPTE 170M",
  651. "Rec. 709",
  652. "sRGB",
  653. "AdobeRGB",
  654. "BT.2020",
  655. "DCI-P3",
  656. "SMPTE 240M",
  657. "470 System M",
  658. "470 System BG",
  659. NULL,
  660. };
  661. static const struct v4l2_ctrl_config vivid_ctrl_colorspace = {
  662. .ops = &vivid_vid_cap_ctrl_ops,
  663. .id = VIVID_CID_COLORSPACE,
  664. .name = "Colorspace",
  665. .type = V4L2_CTRL_TYPE_MENU,
  666. .max = ARRAY_SIZE(vivid_ctrl_colorspace_strings) - 2,
  667. .def = 2,
  668. .qmenu = vivid_ctrl_colorspace_strings,
  669. };
  670. static const char * const vivid_ctrl_xfer_func_strings[] = {
  671. "Default",
  672. "Rec. 709",
  673. "sRGB",
  674. "AdobeRGB",
  675. "SMPTE 240M",
  676. "None",
  677. "DCI-P3",
  678. "SMPTE 2084",
  679. NULL,
  680. };
  681. static const struct v4l2_ctrl_config vivid_ctrl_xfer_func = {
  682. .ops = &vivid_vid_cap_ctrl_ops,
  683. .id = VIVID_CID_XFER_FUNC,
  684. .name = "Transfer Function",
  685. .type = V4L2_CTRL_TYPE_MENU,
  686. .max = ARRAY_SIZE(vivid_ctrl_xfer_func_strings) - 2,
  687. .qmenu = vivid_ctrl_xfer_func_strings,
  688. };
  689. static const char * const vivid_ctrl_ycbcr_enc_strings[] = {
  690. "Default",
  691. "ITU-R 601",
  692. "Rec. 709",
  693. "xvYCC 601",
  694. "xvYCC 709",
  695. "",
  696. "BT.2020",
  697. "BT.2020 Constant Luminance",
  698. "SMPTE 240M",
  699. NULL,
  700. };
  701. static const struct v4l2_ctrl_config vivid_ctrl_ycbcr_enc = {
  702. .ops = &vivid_vid_cap_ctrl_ops,
  703. .id = VIVID_CID_YCBCR_ENC,
  704. .name = "Y'CbCr Encoding",
  705. .type = V4L2_CTRL_TYPE_MENU,
  706. .menu_skip_mask = 1 << 5,
  707. .max = ARRAY_SIZE(vivid_ctrl_ycbcr_enc_strings) - 2,
  708. .qmenu = vivid_ctrl_ycbcr_enc_strings,
  709. };
  710. static const char * const vivid_ctrl_quantization_strings[] = {
  711. "Default",
  712. "Full Range",
  713. "Limited Range",
  714. NULL,
  715. };
  716. static const struct v4l2_ctrl_config vivid_ctrl_quantization = {
  717. .ops = &vivid_vid_cap_ctrl_ops,
  718. .id = VIVID_CID_QUANTIZATION,
  719. .name = "Quantization",
  720. .type = V4L2_CTRL_TYPE_MENU,
  721. .max = ARRAY_SIZE(vivid_ctrl_quantization_strings) - 2,
  722. .qmenu = vivid_ctrl_quantization_strings,
  723. };
  724. static const struct v4l2_ctrl_config vivid_ctrl_alpha_mode = {
  725. .ops = &vivid_vid_cap_ctrl_ops,
  726. .id = VIVID_CID_ALPHA_MODE,
  727. .name = "Apply Alpha To Red Only",
  728. .type = V4L2_CTRL_TYPE_BOOLEAN,
  729. .max = 1,
  730. .step = 1,
  731. };
  732. static const struct v4l2_ctrl_config vivid_ctrl_limited_rgb_range = {
  733. .ops = &vivid_vid_cap_ctrl_ops,
  734. .id = VIVID_CID_LIMITED_RGB_RANGE,
  735. .name = "Limited RGB Range (16-235)",
  736. .type = V4L2_CTRL_TYPE_BOOLEAN,
  737. .max = 1,
  738. .step = 1,
  739. };
  740. /* Video Loop Control */
  741. static int vivid_loop_cap_s_ctrl(struct v4l2_ctrl *ctrl)
  742. {
  743. struct vivid_dev *dev = container_of(ctrl->handler, struct vivid_dev, ctrl_hdl_loop_cap);
  744. switch (ctrl->id) {
  745. case VIVID_CID_LOOP_VIDEO:
  746. dev->loop_video = ctrl->val;
  747. vivid_update_quality(dev);
  748. vivid_send_source_change(dev, SVID);
  749. vivid_send_source_change(dev, HDMI);
  750. break;
  751. }
  752. return 0;
  753. }
  754. static const struct v4l2_ctrl_ops vivid_loop_cap_ctrl_ops = {
  755. .s_ctrl = vivid_loop_cap_s_ctrl,
  756. };
  757. static const struct v4l2_ctrl_config vivid_ctrl_loop_video = {
  758. .ops = &vivid_loop_cap_ctrl_ops,
  759. .id = VIVID_CID_LOOP_VIDEO,
  760. .name = "Loop Video",
  761. .type = V4L2_CTRL_TYPE_BOOLEAN,
  762. .max = 1,
  763. .step = 1,
  764. };
  765. /* VBI Capture Control */
  766. static int vivid_vbi_cap_s_ctrl(struct v4l2_ctrl *ctrl)
  767. {
  768. struct vivid_dev *dev = container_of(ctrl->handler, struct vivid_dev, ctrl_hdl_vbi_cap);
  769. switch (ctrl->id) {
  770. case VIVID_CID_VBI_CAP_INTERLACED:
  771. dev->vbi_cap_interlaced = ctrl->val;
  772. break;
  773. }
  774. return 0;
  775. }
  776. static const struct v4l2_ctrl_ops vivid_vbi_cap_ctrl_ops = {
  777. .s_ctrl = vivid_vbi_cap_s_ctrl,
  778. };
  779. static const struct v4l2_ctrl_config vivid_ctrl_vbi_cap_interlaced = {
  780. .ops = &vivid_vbi_cap_ctrl_ops,
  781. .id = VIVID_CID_VBI_CAP_INTERLACED,
  782. .name = "Interlaced VBI Format",
  783. .type = V4L2_CTRL_TYPE_BOOLEAN,
  784. .max = 1,
  785. .step = 1,
  786. };
  787. /* Video Output Controls */
  788. static int vivid_vid_out_s_ctrl(struct v4l2_ctrl *ctrl)
  789. {
  790. struct vivid_dev *dev = container_of(ctrl->handler, struct vivid_dev, ctrl_hdl_vid_out);
  791. struct v4l2_bt_timings *bt = &dev->dv_timings_out.bt;
  792. switch (ctrl->id) {
  793. case VIVID_CID_HAS_CROP_OUT:
  794. dev->has_crop_out = ctrl->val;
  795. vivid_update_format_out(dev);
  796. break;
  797. case VIVID_CID_HAS_COMPOSE_OUT:
  798. dev->has_compose_out = ctrl->val;
  799. vivid_update_format_out(dev);
  800. break;
  801. case VIVID_CID_HAS_SCALER_OUT:
  802. dev->has_scaler_out = ctrl->val;
  803. vivid_update_format_out(dev);
  804. break;
  805. case V4L2_CID_DV_TX_MODE:
  806. dev->dvi_d_out = ctrl->val == V4L2_DV_TX_MODE_DVI_D;
  807. if (!vivid_is_hdmi_out(dev))
  808. break;
  809. if (!dev->dvi_d_out && (bt->flags & V4L2_DV_FL_IS_CE_VIDEO)) {
  810. if (bt->width == 720 && bt->height <= 576)
  811. dev->colorspace_out = V4L2_COLORSPACE_SMPTE170M;
  812. else
  813. dev->colorspace_out = V4L2_COLORSPACE_REC709;
  814. dev->quantization_out = V4L2_QUANTIZATION_DEFAULT;
  815. } else {
  816. dev->colorspace_out = V4L2_COLORSPACE_SRGB;
  817. dev->quantization_out = dev->dvi_d_out ?
  818. V4L2_QUANTIZATION_LIM_RANGE :
  819. V4L2_QUANTIZATION_DEFAULT;
  820. }
  821. if (dev->loop_video)
  822. vivid_send_source_change(dev, HDMI);
  823. break;
  824. }
  825. return 0;
  826. }
  827. static const struct v4l2_ctrl_ops vivid_vid_out_ctrl_ops = {
  828. .s_ctrl = vivid_vid_out_s_ctrl,
  829. };
  830. static const struct v4l2_ctrl_config vivid_ctrl_has_crop_out = {
  831. .ops = &vivid_vid_out_ctrl_ops,
  832. .id = VIVID_CID_HAS_CROP_OUT,
  833. .name = "Enable Output Cropping",
  834. .type = V4L2_CTRL_TYPE_BOOLEAN,
  835. .max = 1,
  836. .def = 1,
  837. .step = 1,
  838. };
  839. static const struct v4l2_ctrl_config vivid_ctrl_has_compose_out = {
  840. .ops = &vivid_vid_out_ctrl_ops,
  841. .id = VIVID_CID_HAS_COMPOSE_OUT,
  842. .name = "Enable Output Composing",
  843. .type = V4L2_CTRL_TYPE_BOOLEAN,
  844. .max = 1,
  845. .def = 1,
  846. .step = 1,
  847. };
  848. static const struct v4l2_ctrl_config vivid_ctrl_has_scaler_out = {
  849. .ops = &vivid_vid_out_ctrl_ops,
  850. .id = VIVID_CID_HAS_SCALER_OUT,
  851. .name = "Enable Output Scaler",
  852. .type = V4L2_CTRL_TYPE_BOOLEAN,
  853. .max = 1,
  854. .def = 1,
  855. .step = 1,
  856. };
  857. /* Streaming Controls */
  858. static int vivid_streaming_s_ctrl(struct v4l2_ctrl *ctrl)
  859. {
  860. struct vivid_dev *dev = container_of(ctrl->handler, struct vivid_dev, ctrl_hdl_streaming);
  861. u64 rem;
  862. switch (ctrl->id) {
  863. case VIVID_CID_DQBUF_ERROR:
  864. dev->dqbuf_error = true;
  865. break;
  866. case VIVID_CID_PERC_DROPPED:
  867. dev->perc_dropped_buffers = ctrl->val;
  868. break;
  869. case VIVID_CID_QUEUE_SETUP_ERROR:
  870. dev->queue_setup_error = true;
  871. break;
  872. case VIVID_CID_BUF_PREPARE_ERROR:
  873. dev->buf_prepare_error = true;
  874. break;
  875. case VIVID_CID_START_STR_ERROR:
  876. dev->start_streaming_error = true;
  877. break;
  878. case VIVID_CID_QUEUE_ERROR:
  879. if (vb2_start_streaming_called(&dev->vb_vid_cap_q))
  880. vb2_queue_error(&dev->vb_vid_cap_q);
  881. if (vb2_start_streaming_called(&dev->vb_vbi_cap_q))
  882. vb2_queue_error(&dev->vb_vbi_cap_q);
  883. if (vb2_start_streaming_called(&dev->vb_vid_out_q))
  884. vb2_queue_error(&dev->vb_vid_out_q);
  885. if (vb2_start_streaming_called(&dev->vb_vbi_out_q))
  886. vb2_queue_error(&dev->vb_vbi_out_q);
  887. if (vb2_start_streaming_called(&dev->vb_sdr_cap_q))
  888. vb2_queue_error(&dev->vb_sdr_cap_q);
  889. break;
  890. case VIVID_CID_SEQ_WRAP:
  891. dev->seq_wrap = ctrl->val;
  892. break;
  893. case VIVID_CID_TIME_WRAP:
  894. dev->time_wrap = ctrl->val;
  895. if (ctrl->val == 0) {
  896. dev->time_wrap_offset = 0;
  897. break;
  898. }
  899. /*
  900. * We want to set the time 16 seconds before the 32 bit tv_sec
  901. * value of struct timeval would wrap around. So first we
  902. * calculate ktime_get_ns() % ((1 << 32) * NSEC_PER_SEC), and
  903. * then we set the offset to ((1 << 32) - 16) * NSEC_PER_SEC).
  904. */
  905. div64_u64_rem(ktime_get_ns(),
  906. 0x100000000ULL * NSEC_PER_SEC, &rem);
  907. dev->time_wrap_offset =
  908. (0x100000000ULL - 16) * NSEC_PER_SEC - rem;
  909. break;
  910. }
  911. return 0;
  912. }
  913. static const struct v4l2_ctrl_ops vivid_streaming_ctrl_ops = {
  914. .s_ctrl = vivid_streaming_s_ctrl,
  915. };
  916. static const struct v4l2_ctrl_config vivid_ctrl_dqbuf_error = {
  917. .ops = &vivid_streaming_ctrl_ops,
  918. .id = VIVID_CID_DQBUF_ERROR,
  919. .name = "Inject V4L2_BUF_FLAG_ERROR",
  920. .type = V4L2_CTRL_TYPE_BUTTON,
  921. };
  922. static const struct v4l2_ctrl_config vivid_ctrl_perc_dropped = {
  923. .ops = &vivid_streaming_ctrl_ops,
  924. .id = VIVID_CID_PERC_DROPPED,
  925. .name = "Percentage of Dropped Buffers",
  926. .type = V4L2_CTRL_TYPE_INTEGER,
  927. .min = 0,
  928. .max = 100,
  929. .step = 1,
  930. };
  931. static const struct v4l2_ctrl_config vivid_ctrl_queue_setup_error = {
  932. .ops = &vivid_streaming_ctrl_ops,
  933. .id = VIVID_CID_QUEUE_SETUP_ERROR,
  934. .name = "Inject VIDIOC_REQBUFS Error",
  935. .type = V4L2_CTRL_TYPE_BUTTON,
  936. };
  937. static const struct v4l2_ctrl_config vivid_ctrl_buf_prepare_error = {
  938. .ops = &vivid_streaming_ctrl_ops,
  939. .id = VIVID_CID_BUF_PREPARE_ERROR,
  940. .name = "Inject VIDIOC_QBUF Error",
  941. .type = V4L2_CTRL_TYPE_BUTTON,
  942. };
  943. static const struct v4l2_ctrl_config vivid_ctrl_start_streaming_error = {
  944. .ops = &vivid_streaming_ctrl_ops,
  945. .id = VIVID_CID_START_STR_ERROR,
  946. .name = "Inject VIDIOC_STREAMON Error",
  947. .type = V4L2_CTRL_TYPE_BUTTON,
  948. };
  949. static const struct v4l2_ctrl_config vivid_ctrl_queue_error = {
  950. .ops = &vivid_streaming_ctrl_ops,
  951. .id = VIVID_CID_QUEUE_ERROR,
  952. .name = "Inject Fatal Streaming Error",
  953. .type = V4L2_CTRL_TYPE_BUTTON,
  954. };
  955. static const struct v4l2_ctrl_config vivid_ctrl_seq_wrap = {
  956. .ops = &vivid_streaming_ctrl_ops,
  957. .id = VIVID_CID_SEQ_WRAP,
  958. .name = "Wrap Sequence Number",
  959. .type = V4L2_CTRL_TYPE_BOOLEAN,
  960. .max = 1,
  961. .step = 1,
  962. };
  963. static const struct v4l2_ctrl_config vivid_ctrl_time_wrap = {
  964. .ops = &vivid_streaming_ctrl_ops,
  965. .id = VIVID_CID_TIME_WRAP,
  966. .name = "Wrap Timestamp",
  967. .type = V4L2_CTRL_TYPE_BOOLEAN,
  968. .max = 1,
  969. .step = 1,
  970. };
  971. /* SDTV Capture Controls */
  972. static int vivid_sdtv_cap_s_ctrl(struct v4l2_ctrl *ctrl)
  973. {
  974. struct vivid_dev *dev = container_of(ctrl->handler, struct vivid_dev, ctrl_hdl_sdtv_cap);
  975. switch (ctrl->id) {
  976. case VIVID_CID_STD_SIGNAL_MODE:
  977. dev->std_signal_mode = dev->ctrl_std_signal_mode->val;
  978. if (dev->std_signal_mode == SELECTED_STD)
  979. dev->query_std = vivid_standard[dev->ctrl_standard->val];
  980. v4l2_ctrl_activate(dev->ctrl_standard, dev->std_signal_mode == SELECTED_STD);
  981. vivid_update_quality(dev);
  982. vivid_send_source_change(dev, TV);
  983. vivid_send_source_change(dev, SVID);
  984. break;
  985. }
  986. return 0;
  987. }
  988. static const struct v4l2_ctrl_ops vivid_sdtv_cap_ctrl_ops = {
  989. .s_ctrl = vivid_sdtv_cap_s_ctrl,
  990. };
  991. static const char * const vivid_ctrl_std_signal_mode_strings[] = {
  992. "Current Standard",
  993. "No Signal",
  994. "No Lock",
  995. "",
  996. "Selected Standard",
  997. "Cycle Through All Standards",
  998. NULL,
  999. };
  1000. static const struct v4l2_ctrl_config vivid_ctrl_std_signal_mode = {
  1001. .ops = &vivid_sdtv_cap_ctrl_ops,
  1002. .id = VIVID_CID_STD_SIGNAL_MODE,
  1003. .name = "Standard Signal Mode",
  1004. .type = V4L2_CTRL_TYPE_MENU,
  1005. .max = ARRAY_SIZE(vivid_ctrl_std_signal_mode_strings) - 2,
  1006. .menu_skip_mask = 1 << 3,
  1007. .qmenu = vivid_ctrl_std_signal_mode_strings,
  1008. };
  1009. static const struct v4l2_ctrl_config vivid_ctrl_standard = {
  1010. .ops = &vivid_sdtv_cap_ctrl_ops,
  1011. .id = VIVID_CID_STANDARD,
  1012. .name = "Standard",
  1013. .type = V4L2_CTRL_TYPE_MENU,
  1014. .max = 14,
  1015. .qmenu = vivid_ctrl_standard_strings,
  1016. };
  1017. /* Radio Receiver Controls */
  1018. static int vivid_radio_rx_s_ctrl(struct v4l2_ctrl *ctrl)
  1019. {
  1020. struct vivid_dev *dev = container_of(ctrl->handler, struct vivid_dev, ctrl_hdl_radio_rx);
  1021. switch (ctrl->id) {
  1022. case VIVID_CID_RADIO_SEEK_MODE:
  1023. dev->radio_rx_hw_seek_mode = ctrl->val;
  1024. break;
  1025. case VIVID_CID_RADIO_SEEK_PROG_LIM:
  1026. dev->radio_rx_hw_seek_prog_lim = ctrl->val;
  1027. break;
  1028. case VIVID_CID_RADIO_RX_RDS_RBDS:
  1029. dev->rds_gen.use_rbds = ctrl->val;
  1030. break;
  1031. case VIVID_CID_RADIO_RX_RDS_BLOCKIO:
  1032. dev->radio_rx_rds_controls = ctrl->val;
  1033. dev->radio_rx_caps &= ~V4L2_CAP_READWRITE;
  1034. dev->radio_rx_rds_use_alternates = false;
  1035. if (!dev->radio_rx_rds_controls) {
  1036. dev->radio_rx_caps |= V4L2_CAP_READWRITE;
  1037. __v4l2_ctrl_s_ctrl(dev->radio_rx_rds_pty, 0);
  1038. __v4l2_ctrl_s_ctrl(dev->radio_rx_rds_ta, 0);
  1039. __v4l2_ctrl_s_ctrl(dev->radio_rx_rds_tp, 0);
  1040. __v4l2_ctrl_s_ctrl(dev->radio_rx_rds_ms, 0);
  1041. __v4l2_ctrl_s_ctrl_string(dev->radio_rx_rds_psname, "");
  1042. __v4l2_ctrl_s_ctrl_string(dev->radio_rx_rds_radiotext, "");
  1043. }
  1044. v4l2_ctrl_activate(dev->radio_rx_rds_pty, dev->radio_rx_rds_controls);
  1045. v4l2_ctrl_activate(dev->radio_rx_rds_psname, dev->radio_rx_rds_controls);
  1046. v4l2_ctrl_activate(dev->radio_rx_rds_radiotext, dev->radio_rx_rds_controls);
  1047. v4l2_ctrl_activate(dev->radio_rx_rds_ta, dev->radio_rx_rds_controls);
  1048. v4l2_ctrl_activate(dev->radio_rx_rds_tp, dev->radio_rx_rds_controls);
  1049. v4l2_ctrl_activate(dev->radio_rx_rds_ms, dev->radio_rx_rds_controls);
  1050. dev->radio_rx_dev.device_caps = dev->radio_rx_caps;
  1051. break;
  1052. case V4L2_CID_RDS_RECEPTION:
  1053. dev->radio_rx_rds_enabled = ctrl->val;
  1054. break;
  1055. }
  1056. return 0;
  1057. }
  1058. static const struct v4l2_ctrl_ops vivid_radio_rx_ctrl_ops = {
  1059. .s_ctrl = vivid_radio_rx_s_ctrl,
  1060. };
  1061. static const char * const vivid_ctrl_radio_rds_mode_strings[] = {
  1062. "Block I/O",
  1063. "Controls",
  1064. NULL,
  1065. };
  1066. static const struct v4l2_ctrl_config vivid_ctrl_radio_rx_rds_blockio = {
  1067. .ops = &vivid_radio_rx_ctrl_ops,
  1068. .id = VIVID_CID_RADIO_RX_RDS_BLOCKIO,
  1069. .name = "RDS Rx I/O Mode",
  1070. .type = V4L2_CTRL_TYPE_MENU,
  1071. .qmenu = vivid_ctrl_radio_rds_mode_strings,
  1072. .max = 1,
  1073. };
  1074. static const struct v4l2_ctrl_config vivid_ctrl_radio_rx_rds_rbds = {
  1075. .ops = &vivid_radio_rx_ctrl_ops,
  1076. .id = VIVID_CID_RADIO_RX_RDS_RBDS,
  1077. .name = "Generate RBDS Instead of RDS",
  1078. .type = V4L2_CTRL_TYPE_BOOLEAN,
  1079. .max = 1,
  1080. .step = 1,
  1081. };
  1082. static const char * const vivid_ctrl_radio_hw_seek_mode_strings[] = {
  1083. "Bounded",
  1084. "Wrap Around",
  1085. "Both",
  1086. NULL,
  1087. };
  1088. static const struct v4l2_ctrl_config vivid_ctrl_radio_hw_seek_mode = {
  1089. .ops = &vivid_radio_rx_ctrl_ops,
  1090. .id = VIVID_CID_RADIO_SEEK_MODE,
  1091. .name = "Radio HW Seek Mode",
  1092. .type = V4L2_CTRL_TYPE_MENU,
  1093. .max = 2,
  1094. .qmenu = vivid_ctrl_radio_hw_seek_mode_strings,
  1095. };
  1096. static const struct v4l2_ctrl_config vivid_ctrl_radio_hw_seek_prog_lim = {
  1097. .ops = &vivid_radio_rx_ctrl_ops,
  1098. .id = VIVID_CID_RADIO_SEEK_PROG_LIM,
  1099. .name = "Radio Programmable HW Seek",
  1100. .type = V4L2_CTRL_TYPE_BOOLEAN,
  1101. .max = 1,
  1102. .step = 1,
  1103. };
  1104. /* Radio Transmitter Controls */
  1105. static int vivid_radio_tx_s_ctrl(struct v4l2_ctrl *ctrl)
  1106. {
  1107. struct vivid_dev *dev = container_of(ctrl->handler, struct vivid_dev, ctrl_hdl_radio_tx);
  1108. switch (ctrl->id) {
  1109. case VIVID_CID_RADIO_TX_RDS_BLOCKIO:
  1110. dev->radio_tx_rds_controls = ctrl->val;
  1111. dev->radio_tx_caps &= ~V4L2_CAP_READWRITE;
  1112. if (!dev->radio_tx_rds_controls)
  1113. dev->radio_tx_caps |= V4L2_CAP_READWRITE;
  1114. dev->radio_tx_dev.device_caps = dev->radio_tx_caps;
  1115. break;
  1116. case V4L2_CID_RDS_TX_PTY:
  1117. if (dev->radio_rx_rds_controls)
  1118. v4l2_ctrl_s_ctrl(dev->radio_rx_rds_pty, ctrl->val);
  1119. break;
  1120. case V4L2_CID_RDS_TX_PS_NAME:
  1121. if (dev->radio_rx_rds_controls)
  1122. v4l2_ctrl_s_ctrl_string(dev->radio_rx_rds_psname, ctrl->p_new.p_char);
  1123. break;
  1124. case V4L2_CID_RDS_TX_RADIO_TEXT:
  1125. if (dev->radio_rx_rds_controls)
  1126. v4l2_ctrl_s_ctrl_string(dev->radio_rx_rds_radiotext, ctrl->p_new.p_char);
  1127. break;
  1128. case V4L2_CID_RDS_TX_TRAFFIC_ANNOUNCEMENT:
  1129. if (dev->radio_rx_rds_controls)
  1130. v4l2_ctrl_s_ctrl(dev->radio_rx_rds_ta, ctrl->val);
  1131. break;
  1132. case V4L2_CID_RDS_TX_TRAFFIC_PROGRAM:
  1133. if (dev->radio_rx_rds_controls)
  1134. v4l2_ctrl_s_ctrl(dev->radio_rx_rds_tp, ctrl->val);
  1135. break;
  1136. case V4L2_CID_RDS_TX_MUSIC_SPEECH:
  1137. if (dev->radio_rx_rds_controls)
  1138. v4l2_ctrl_s_ctrl(dev->radio_rx_rds_ms, ctrl->val);
  1139. break;
  1140. }
  1141. return 0;
  1142. }
  1143. static const struct v4l2_ctrl_ops vivid_radio_tx_ctrl_ops = {
  1144. .s_ctrl = vivid_radio_tx_s_ctrl,
  1145. };
  1146. static const struct v4l2_ctrl_config vivid_ctrl_radio_tx_rds_blockio = {
  1147. .ops = &vivid_radio_tx_ctrl_ops,
  1148. .id = VIVID_CID_RADIO_TX_RDS_BLOCKIO,
  1149. .name = "RDS Tx I/O Mode",
  1150. .type = V4L2_CTRL_TYPE_MENU,
  1151. .qmenu = vivid_ctrl_radio_rds_mode_strings,
  1152. .max = 1,
  1153. .def = 1,
  1154. };
  1155. /* SDR Capture Controls */
  1156. static int vivid_sdr_cap_s_ctrl(struct v4l2_ctrl *ctrl)
  1157. {
  1158. struct vivid_dev *dev = container_of(ctrl->handler, struct vivid_dev, ctrl_hdl_sdr_cap);
  1159. switch (ctrl->id) {
  1160. case VIVID_CID_SDR_CAP_FM_DEVIATION:
  1161. dev->sdr_fm_deviation = ctrl->val;
  1162. break;
  1163. }
  1164. return 0;
  1165. }
  1166. static const struct v4l2_ctrl_ops vivid_sdr_cap_ctrl_ops = {
  1167. .s_ctrl = vivid_sdr_cap_s_ctrl,
  1168. };
  1169. static const struct v4l2_ctrl_config vivid_ctrl_sdr_cap_fm_deviation = {
  1170. .ops = &vivid_sdr_cap_ctrl_ops,
  1171. .id = VIVID_CID_SDR_CAP_FM_DEVIATION,
  1172. .name = "FM Deviation",
  1173. .type = V4L2_CTRL_TYPE_INTEGER,
  1174. .min = 100,
  1175. .max = 200000,
  1176. .def = 75000,
  1177. .step = 1,
  1178. };
  1179. static const struct v4l2_ctrl_config vivid_ctrl_class = {
  1180. .ops = &vivid_user_gen_ctrl_ops,
  1181. .flags = V4L2_CTRL_FLAG_READ_ONLY | V4L2_CTRL_FLAG_WRITE_ONLY,
  1182. .id = VIVID_CID_VIVID_CLASS,
  1183. .name = "Vivid Controls",
  1184. .type = V4L2_CTRL_TYPE_CTRL_CLASS,
  1185. };
  1186. int vivid_create_controls(struct vivid_dev *dev, bool show_ccs_cap,
  1187. bool show_ccs_out, bool no_error_inj,
  1188. bool has_sdtv, bool has_hdmi)
  1189. {
  1190. struct v4l2_ctrl_handler *hdl_user_gen = &dev->ctrl_hdl_user_gen;
  1191. struct v4l2_ctrl_handler *hdl_user_vid = &dev->ctrl_hdl_user_vid;
  1192. struct v4l2_ctrl_handler *hdl_user_aud = &dev->ctrl_hdl_user_aud;
  1193. struct v4l2_ctrl_handler *hdl_streaming = &dev->ctrl_hdl_streaming;
  1194. struct v4l2_ctrl_handler *hdl_sdtv_cap = &dev->ctrl_hdl_sdtv_cap;
  1195. struct v4l2_ctrl_handler *hdl_loop_cap = &dev->ctrl_hdl_loop_cap;
  1196. struct v4l2_ctrl_handler *hdl_vid_cap = &dev->ctrl_hdl_vid_cap;
  1197. struct v4l2_ctrl_handler *hdl_vid_out = &dev->ctrl_hdl_vid_out;
  1198. struct v4l2_ctrl_handler *hdl_vbi_cap = &dev->ctrl_hdl_vbi_cap;
  1199. struct v4l2_ctrl_handler *hdl_vbi_out = &dev->ctrl_hdl_vbi_out;
  1200. struct v4l2_ctrl_handler *hdl_radio_rx = &dev->ctrl_hdl_radio_rx;
  1201. struct v4l2_ctrl_handler *hdl_radio_tx = &dev->ctrl_hdl_radio_tx;
  1202. struct v4l2_ctrl_handler *hdl_sdr_cap = &dev->ctrl_hdl_sdr_cap;
  1203. struct v4l2_ctrl_config vivid_ctrl_dv_timings = {
  1204. .ops = &vivid_vid_cap_ctrl_ops,
  1205. .id = VIVID_CID_DV_TIMINGS,
  1206. .name = "DV Timings",
  1207. .type = V4L2_CTRL_TYPE_MENU,
  1208. };
  1209. int i;
  1210. v4l2_ctrl_handler_init(hdl_user_gen, 10);
  1211. v4l2_ctrl_new_custom(hdl_user_gen, &vivid_ctrl_class, NULL);
  1212. v4l2_ctrl_handler_init(hdl_user_vid, 9);
  1213. v4l2_ctrl_new_custom(hdl_user_vid, &vivid_ctrl_class, NULL);
  1214. v4l2_ctrl_handler_init(hdl_user_aud, 2);
  1215. v4l2_ctrl_new_custom(hdl_user_aud, &vivid_ctrl_class, NULL);
  1216. v4l2_ctrl_handler_init(hdl_streaming, 8);
  1217. v4l2_ctrl_new_custom(hdl_streaming, &vivid_ctrl_class, NULL);
  1218. v4l2_ctrl_handler_init(hdl_sdtv_cap, 2);
  1219. v4l2_ctrl_new_custom(hdl_sdtv_cap, &vivid_ctrl_class, NULL);
  1220. v4l2_ctrl_handler_init(hdl_loop_cap, 1);
  1221. v4l2_ctrl_new_custom(hdl_loop_cap, &vivid_ctrl_class, NULL);
  1222. v4l2_ctrl_handler_init(hdl_vid_cap, 55);
  1223. v4l2_ctrl_new_custom(hdl_vid_cap, &vivid_ctrl_class, NULL);
  1224. v4l2_ctrl_handler_init(hdl_vid_out, 26);
  1225. if (!no_error_inj)
  1226. v4l2_ctrl_new_custom(hdl_vid_out, &vivid_ctrl_class, NULL);
  1227. v4l2_ctrl_handler_init(hdl_vbi_cap, 21);
  1228. v4l2_ctrl_new_custom(hdl_vbi_cap, &vivid_ctrl_class, NULL);
  1229. v4l2_ctrl_handler_init(hdl_vbi_out, 19);
  1230. if (!no_error_inj)
  1231. v4l2_ctrl_new_custom(hdl_vbi_out, &vivid_ctrl_class, NULL);
  1232. v4l2_ctrl_handler_init(hdl_radio_rx, 17);
  1233. v4l2_ctrl_new_custom(hdl_radio_rx, &vivid_ctrl_class, NULL);
  1234. v4l2_ctrl_handler_init(hdl_radio_tx, 17);
  1235. v4l2_ctrl_new_custom(hdl_radio_tx, &vivid_ctrl_class, NULL);
  1236. v4l2_ctrl_handler_init(hdl_sdr_cap, 19);
  1237. v4l2_ctrl_new_custom(hdl_sdr_cap, &vivid_ctrl_class, NULL);
  1238. /* User Controls */
  1239. dev->volume = v4l2_ctrl_new_std(hdl_user_aud, NULL,
  1240. V4L2_CID_AUDIO_VOLUME, 0, 255, 1, 200);
  1241. dev->mute = v4l2_ctrl_new_std(hdl_user_aud, NULL,
  1242. V4L2_CID_AUDIO_MUTE, 0, 1, 1, 0);
  1243. if (dev->has_vid_cap) {
  1244. dev->brightness = v4l2_ctrl_new_std(hdl_user_vid, &vivid_user_vid_ctrl_ops,
  1245. V4L2_CID_BRIGHTNESS, 0, 255, 1, 128);
  1246. for (i = 0; i < MAX_INPUTS; i++)
  1247. dev->input_brightness[i] = 128;
  1248. dev->contrast = v4l2_ctrl_new_std(hdl_user_vid, &vivid_user_vid_ctrl_ops,
  1249. V4L2_CID_CONTRAST, 0, 255, 1, 128);
  1250. dev->saturation = v4l2_ctrl_new_std(hdl_user_vid, &vivid_user_vid_ctrl_ops,
  1251. V4L2_CID_SATURATION, 0, 255, 1, 128);
  1252. dev->hue = v4l2_ctrl_new_std(hdl_user_vid, &vivid_user_vid_ctrl_ops,
  1253. V4L2_CID_HUE, -128, 128, 1, 0);
  1254. v4l2_ctrl_new_std(hdl_user_vid, &vivid_user_vid_ctrl_ops,
  1255. V4L2_CID_HFLIP, 0, 1, 1, 0);
  1256. v4l2_ctrl_new_std(hdl_user_vid, &vivid_user_vid_ctrl_ops,
  1257. V4L2_CID_VFLIP, 0, 1, 1, 0);
  1258. dev->autogain = v4l2_ctrl_new_std(hdl_user_vid, &vivid_user_vid_ctrl_ops,
  1259. V4L2_CID_AUTOGAIN, 0, 1, 1, 1);
  1260. dev->gain = v4l2_ctrl_new_std(hdl_user_vid, &vivid_user_vid_ctrl_ops,
  1261. V4L2_CID_GAIN, 0, 255, 1, 100);
  1262. dev->alpha = v4l2_ctrl_new_std(hdl_user_vid, &vivid_user_vid_ctrl_ops,
  1263. V4L2_CID_ALPHA_COMPONENT, 0, 255, 1, 0);
  1264. }
  1265. dev->button = v4l2_ctrl_new_custom(hdl_user_gen, &vivid_ctrl_button, NULL);
  1266. dev->int32 = v4l2_ctrl_new_custom(hdl_user_gen, &vivid_ctrl_int32, NULL);
  1267. dev->int64 = v4l2_ctrl_new_custom(hdl_user_gen, &vivid_ctrl_int64, NULL);
  1268. dev->boolean = v4l2_ctrl_new_custom(hdl_user_gen, &vivid_ctrl_boolean, NULL);
  1269. dev->menu = v4l2_ctrl_new_custom(hdl_user_gen, &vivid_ctrl_menu, NULL);
  1270. dev->string = v4l2_ctrl_new_custom(hdl_user_gen, &vivid_ctrl_string, NULL);
  1271. dev->bitmask = v4l2_ctrl_new_custom(hdl_user_gen, &vivid_ctrl_bitmask, NULL);
  1272. dev->int_menu = v4l2_ctrl_new_custom(hdl_user_gen, &vivid_ctrl_int_menu, NULL);
  1273. v4l2_ctrl_new_custom(hdl_user_gen, &vivid_ctrl_u32_array, NULL);
  1274. v4l2_ctrl_new_custom(hdl_user_gen, &vivid_ctrl_u16_matrix, NULL);
  1275. v4l2_ctrl_new_custom(hdl_user_gen, &vivid_ctrl_u8_4d_array, NULL);
  1276. if (dev->has_vid_cap) {
  1277. /* Image Processing Controls */
  1278. struct v4l2_ctrl_config vivid_ctrl_test_pattern = {
  1279. .ops = &vivid_vid_cap_ctrl_ops,
  1280. .id = VIVID_CID_TEST_PATTERN,
  1281. .name = "Test Pattern",
  1282. .type = V4L2_CTRL_TYPE_MENU,
  1283. .max = TPG_PAT_NOISE,
  1284. .qmenu = tpg_pattern_strings,
  1285. };
  1286. dev->test_pattern = v4l2_ctrl_new_custom(hdl_vid_cap,
  1287. &vivid_ctrl_test_pattern, NULL);
  1288. v4l2_ctrl_new_custom(hdl_vid_cap, &vivid_ctrl_perc_fill, NULL);
  1289. v4l2_ctrl_new_custom(hdl_vid_cap, &vivid_ctrl_hor_movement, NULL);
  1290. v4l2_ctrl_new_custom(hdl_vid_cap, &vivid_ctrl_vert_movement, NULL);
  1291. v4l2_ctrl_new_custom(hdl_vid_cap, &vivid_ctrl_osd_mode, NULL);
  1292. v4l2_ctrl_new_custom(hdl_vid_cap, &vivid_ctrl_show_border, NULL);
  1293. v4l2_ctrl_new_custom(hdl_vid_cap, &vivid_ctrl_show_square, NULL);
  1294. v4l2_ctrl_new_custom(hdl_vid_cap, &vivid_ctrl_hflip, NULL);
  1295. v4l2_ctrl_new_custom(hdl_vid_cap, &vivid_ctrl_vflip, NULL);
  1296. v4l2_ctrl_new_custom(hdl_vid_cap, &vivid_ctrl_insert_sav, NULL);
  1297. v4l2_ctrl_new_custom(hdl_vid_cap, &vivid_ctrl_insert_eav, NULL);
  1298. v4l2_ctrl_new_custom(hdl_vid_cap, &vivid_ctrl_reduced_fps, NULL);
  1299. if (show_ccs_cap) {
  1300. dev->ctrl_has_crop_cap = v4l2_ctrl_new_custom(hdl_vid_cap,
  1301. &vivid_ctrl_has_crop_cap, NULL);
  1302. dev->ctrl_has_compose_cap = v4l2_ctrl_new_custom(hdl_vid_cap,
  1303. &vivid_ctrl_has_compose_cap, NULL);
  1304. dev->ctrl_has_scaler_cap = v4l2_ctrl_new_custom(hdl_vid_cap,
  1305. &vivid_ctrl_has_scaler_cap, NULL);
  1306. }
  1307. v4l2_ctrl_new_custom(hdl_vid_cap, &vivid_ctrl_tstamp_src, NULL);
  1308. dev->colorspace = v4l2_ctrl_new_custom(hdl_vid_cap,
  1309. &vivid_ctrl_colorspace, NULL);
  1310. v4l2_ctrl_new_custom(hdl_vid_cap, &vivid_ctrl_xfer_func, NULL);
  1311. v4l2_ctrl_new_custom(hdl_vid_cap, &vivid_ctrl_ycbcr_enc, NULL);
  1312. v4l2_ctrl_new_custom(hdl_vid_cap, &vivid_ctrl_quantization, NULL);
  1313. v4l2_ctrl_new_custom(hdl_vid_cap, &vivid_ctrl_alpha_mode, NULL);
  1314. }
  1315. if (dev->has_vid_out && show_ccs_out) {
  1316. dev->ctrl_has_crop_out = v4l2_ctrl_new_custom(hdl_vid_out,
  1317. &vivid_ctrl_has_crop_out, NULL);
  1318. dev->ctrl_has_compose_out = v4l2_ctrl_new_custom(hdl_vid_out,
  1319. &vivid_ctrl_has_compose_out, NULL);
  1320. dev->ctrl_has_scaler_out = v4l2_ctrl_new_custom(hdl_vid_out,
  1321. &vivid_ctrl_has_scaler_out, NULL);
  1322. }
  1323. /*
  1324. * Testing this driver with v4l2-compliance will trigger the error
  1325. * injection controls, and after that nothing will work as expected.
  1326. * So we have a module option to drop these error injecting controls
  1327. * allowing us to run v4l2_compliance again.
  1328. */
  1329. if (!no_error_inj) {
  1330. v4l2_ctrl_new_custom(hdl_user_gen, &vivid_ctrl_disconnect, NULL);
  1331. v4l2_ctrl_new_custom(hdl_streaming, &vivid_ctrl_dqbuf_error, NULL);
  1332. v4l2_ctrl_new_custom(hdl_streaming, &vivid_ctrl_perc_dropped, NULL);
  1333. v4l2_ctrl_new_custom(hdl_streaming, &vivid_ctrl_queue_setup_error, NULL);
  1334. v4l2_ctrl_new_custom(hdl_streaming, &vivid_ctrl_buf_prepare_error, NULL);
  1335. v4l2_ctrl_new_custom(hdl_streaming, &vivid_ctrl_start_streaming_error, NULL);
  1336. v4l2_ctrl_new_custom(hdl_streaming, &vivid_ctrl_queue_error, NULL);
  1337. v4l2_ctrl_new_custom(hdl_streaming, &vivid_ctrl_seq_wrap, NULL);
  1338. v4l2_ctrl_new_custom(hdl_streaming, &vivid_ctrl_time_wrap, NULL);
  1339. }
  1340. if (has_sdtv && (dev->has_vid_cap || dev->has_vbi_cap)) {
  1341. if (dev->has_vid_cap)
  1342. v4l2_ctrl_new_custom(hdl_vid_cap, &vivid_ctrl_std_aspect_ratio, NULL);
  1343. dev->ctrl_std_signal_mode = v4l2_ctrl_new_custom(hdl_sdtv_cap,
  1344. &vivid_ctrl_std_signal_mode, NULL);
  1345. dev->ctrl_standard = v4l2_ctrl_new_custom(hdl_sdtv_cap,
  1346. &vivid_ctrl_standard, NULL);
  1347. if (dev->ctrl_std_signal_mode)
  1348. v4l2_ctrl_cluster(2, &dev->ctrl_std_signal_mode);
  1349. if (dev->has_raw_vbi_cap)
  1350. v4l2_ctrl_new_custom(hdl_vbi_cap, &vivid_ctrl_vbi_cap_interlaced, NULL);
  1351. }
  1352. if (has_hdmi && dev->has_vid_cap) {
  1353. dev->ctrl_dv_timings_signal_mode = v4l2_ctrl_new_custom(hdl_vid_cap,
  1354. &vivid_ctrl_dv_timings_signal_mode, NULL);
  1355. vivid_ctrl_dv_timings.max = dev->query_dv_timings_size - 1;
  1356. vivid_ctrl_dv_timings.qmenu =
  1357. (const char * const *)dev->query_dv_timings_qmenu;
  1358. dev->ctrl_dv_timings = v4l2_ctrl_new_custom(hdl_vid_cap,
  1359. &vivid_ctrl_dv_timings, NULL);
  1360. if (dev->ctrl_dv_timings_signal_mode)
  1361. v4l2_ctrl_cluster(2, &dev->ctrl_dv_timings_signal_mode);
  1362. v4l2_ctrl_new_custom(hdl_vid_cap, &vivid_ctrl_dv_timings_aspect_ratio, NULL);
  1363. v4l2_ctrl_new_custom(hdl_vid_cap, &vivid_ctrl_max_edid_blocks, NULL);
  1364. dev->real_rgb_range_cap = v4l2_ctrl_new_custom(hdl_vid_cap,
  1365. &vivid_ctrl_limited_rgb_range, NULL);
  1366. dev->rgb_range_cap = v4l2_ctrl_new_std_menu(hdl_vid_cap,
  1367. &vivid_vid_cap_ctrl_ops,
  1368. V4L2_CID_DV_RX_RGB_RANGE, V4L2_DV_RGB_RANGE_FULL,
  1369. 0, V4L2_DV_RGB_RANGE_AUTO);
  1370. }
  1371. if (has_hdmi && dev->has_vid_out) {
  1372. /*
  1373. * We aren't doing anything with this at the moment, but
  1374. * HDMI outputs typically have this controls.
  1375. */
  1376. dev->ctrl_tx_rgb_range = v4l2_ctrl_new_std_menu(hdl_vid_out, NULL,
  1377. V4L2_CID_DV_TX_RGB_RANGE, V4L2_DV_RGB_RANGE_FULL,
  1378. 0, V4L2_DV_RGB_RANGE_AUTO);
  1379. dev->ctrl_tx_mode = v4l2_ctrl_new_std_menu(hdl_vid_out, NULL,
  1380. V4L2_CID_DV_TX_MODE, V4L2_DV_TX_MODE_HDMI,
  1381. 0, V4L2_DV_TX_MODE_HDMI);
  1382. }
  1383. if ((dev->has_vid_cap && dev->has_vid_out) ||
  1384. (dev->has_vbi_cap && dev->has_vbi_out))
  1385. v4l2_ctrl_new_custom(hdl_loop_cap, &vivid_ctrl_loop_video, NULL);
  1386. if (dev->has_fb)
  1387. v4l2_ctrl_new_custom(hdl_user_gen, &vivid_ctrl_clear_fb, NULL);
  1388. if (dev->has_radio_rx) {
  1389. v4l2_ctrl_new_custom(hdl_radio_rx, &vivid_ctrl_radio_hw_seek_mode, NULL);
  1390. v4l2_ctrl_new_custom(hdl_radio_rx, &vivid_ctrl_radio_hw_seek_prog_lim, NULL);
  1391. v4l2_ctrl_new_custom(hdl_radio_rx, &vivid_ctrl_radio_rx_rds_blockio, NULL);
  1392. v4l2_ctrl_new_custom(hdl_radio_rx, &vivid_ctrl_radio_rx_rds_rbds, NULL);
  1393. v4l2_ctrl_new_std(hdl_radio_rx, &vivid_radio_rx_ctrl_ops,
  1394. V4L2_CID_RDS_RECEPTION, 0, 1, 1, 1);
  1395. dev->radio_rx_rds_pty = v4l2_ctrl_new_std(hdl_radio_rx,
  1396. &vivid_radio_rx_ctrl_ops,
  1397. V4L2_CID_RDS_RX_PTY, 0, 31, 1, 0);
  1398. dev->radio_rx_rds_psname = v4l2_ctrl_new_std(hdl_radio_rx,
  1399. &vivid_radio_rx_ctrl_ops,
  1400. V4L2_CID_RDS_RX_PS_NAME, 0, 8, 8, 0);
  1401. dev->radio_rx_rds_radiotext = v4l2_ctrl_new_std(hdl_radio_rx,
  1402. &vivid_radio_rx_ctrl_ops,
  1403. V4L2_CID_RDS_RX_RADIO_TEXT, 0, 64, 64, 0);
  1404. dev->radio_rx_rds_ta = v4l2_ctrl_new_std(hdl_radio_rx,
  1405. &vivid_radio_rx_ctrl_ops,
  1406. V4L2_CID_RDS_RX_TRAFFIC_ANNOUNCEMENT, 0, 1, 1, 0);
  1407. dev->radio_rx_rds_tp = v4l2_ctrl_new_std(hdl_radio_rx,
  1408. &vivid_radio_rx_ctrl_ops,
  1409. V4L2_CID_RDS_RX_TRAFFIC_PROGRAM, 0, 1, 1, 0);
  1410. dev->radio_rx_rds_ms = v4l2_ctrl_new_std(hdl_radio_rx,
  1411. &vivid_radio_rx_ctrl_ops,
  1412. V4L2_CID_RDS_RX_MUSIC_SPEECH, 0, 1, 1, 1);
  1413. }
  1414. if (dev->has_radio_tx) {
  1415. v4l2_ctrl_new_custom(hdl_radio_tx,
  1416. &vivid_ctrl_radio_tx_rds_blockio, NULL);
  1417. dev->radio_tx_rds_pi = v4l2_ctrl_new_std(hdl_radio_tx,
  1418. &vivid_radio_tx_ctrl_ops,
  1419. V4L2_CID_RDS_TX_PI, 0, 0xffff, 1, 0x8088);
  1420. dev->radio_tx_rds_pty = v4l2_ctrl_new_std(hdl_radio_tx,
  1421. &vivid_radio_tx_ctrl_ops,
  1422. V4L2_CID_RDS_TX_PTY, 0, 31, 1, 3);
  1423. dev->radio_tx_rds_psname = v4l2_ctrl_new_std(hdl_radio_tx,
  1424. &vivid_radio_tx_ctrl_ops,
  1425. V4L2_CID_RDS_TX_PS_NAME, 0, 8, 8, 0);
  1426. if (dev->radio_tx_rds_psname)
  1427. v4l2_ctrl_s_ctrl_string(dev->radio_tx_rds_psname, "VIVID-TX");
  1428. dev->radio_tx_rds_radiotext = v4l2_ctrl_new_std(hdl_radio_tx,
  1429. &vivid_radio_tx_ctrl_ops,
  1430. V4L2_CID_RDS_TX_RADIO_TEXT, 0, 64 * 2, 64, 0);
  1431. if (dev->radio_tx_rds_radiotext)
  1432. v4l2_ctrl_s_ctrl_string(dev->radio_tx_rds_radiotext,
  1433. "This is a VIVID default Radio Text template text, change at will");
  1434. dev->radio_tx_rds_mono_stereo = v4l2_ctrl_new_std(hdl_radio_tx,
  1435. &vivid_radio_tx_ctrl_ops,
  1436. V4L2_CID_RDS_TX_MONO_STEREO, 0, 1, 1, 1);
  1437. dev->radio_tx_rds_art_head = v4l2_ctrl_new_std(hdl_radio_tx,
  1438. &vivid_radio_tx_ctrl_ops,
  1439. V4L2_CID_RDS_TX_ARTIFICIAL_HEAD, 0, 1, 1, 0);
  1440. dev->radio_tx_rds_compressed = v4l2_ctrl_new_std(hdl_radio_tx,
  1441. &vivid_radio_tx_ctrl_ops,
  1442. V4L2_CID_RDS_TX_COMPRESSED, 0, 1, 1, 0);
  1443. dev->radio_tx_rds_dyn_pty = v4l2_ctrl_new_std(hdl_radio_tx,
  1444. &vivid_radio_tx_ctrl_ops,
  1445. V4L2_CID_RDS_TX_DYNAMIC_PTY, 0, 1, 1, 0);
  1446. dev->radio_tx_rds_ta = v4l2_ctrl_new_std(hdl_radio_tx,
  1447. &vivid_radio_tx_ctrl_ops,
  1448. V4L2_CID_RDS_TX_TRAFFIC_ANNOUNCEMENT, 0, 1, 1, 0);
  1449. dev->radio_tx_rds_tp = v4l2_ctrl_new_std(hdl_radio_tx,
  1450. &vivid_radio_tx_ctrl_ops,
  1451. V4L2_CID_RDS_TX_TRAFFIC_PROGRAM, 0, 1, 1, 1);
  1452. dev->radio_tx_rds_ms = v4l2_ctrl_new_std(hdl_radio_tx,
  1453. &vivid_radio_tx_ctrl_ops,
  1454. V4L2_CID_RDS_TX_MUSIC_SPEECH, 0, 1, 1, 1);
  1455. }
  1456. if (dev->has_sdr_cap) {
  1457. v4l2_ctrl_new_custom(hdl_sdr_cap,
  1458. &vivid_ctrl_sdr_cap_fm_deviation, NULL);
  1459. }
  1460. if (hdl_user_gen->error)
  1461. return hdl_user_gen->error;
  1462. if (hdl_user_vid->error)
  1463. return hdl_user_vid->error;
  1464. if (hdl_user_aud->error)
  1465. return hdl_user_aud->error;
  1466. if (hdl_streaming->error)
  1467. return hdl_streaming->error;
  1468. if (hdl_sdr_cap->error)
  1469. return hdl_sdr_cap->error;
  1470. if (hdl_loop_cap->error)
  1471. return hdl_loop_cap->error;
  1472. if (dev->autogain)
  1473. v4l2_ctrl_auto_cluster(2, &dev->autogain, 0, true);
  1474. if (dev->has_vid_cap) {
  1475. v4l2_ctrl_add_handler(hdl_vid_cap, hdl_user_gen, NULL);
  1476. v4l2_ctrl_add_handler(hdl_vid_cap, hdl_user_vid, NULL);
  1477. v4l2_ctrl_add_handler(hdl_vid_cap, hdl_user_aud, NULL);
  1478. v4l2_ctrl_add_handler(hdl_vid_cap, hdl_streaming, NULL);
  1479. v4l2_ctrl_add_handler(hdl_vid_cap, hdl_sdtv_cap, NULL);
  1480. v4l2_ctrl_add_handler(hdl_vid_cap, hdl_loop_cap, NULL);
  1481. if (hdl_vid_cap->error)
  1482. return hdl_vid_cap->error;
  1483. dev->vid_cap_dev.ctrl_handler = hdl_vid_cap;
  1484. }
  1485. if (dev->has_vid_out) {
  1486. v4l2_ctrl_add_handler(hdl_vid_out, hdl_user_gen, NULL);
  1487. v4l2_ctrl_add_handler(hdl_vid_out, hdl_user_aud, NULL);
  1488. v4l2_ctrl_add_handler(hdl_vid_out, hdl_streaming, NULL);
  1489. if (hdl_vid_out->error)
  1490. return hdl_vid_out->error;
  1491. dev->vid_out_dev.ctrl_handler = hdl_vid_out;
  1492. }
  1493. if (dev->has_vbi_cap) {
  1494. v4l2_ctrl_add_handler(hdl_vbi_cap, hdl_user_gen, NULL);
  1495. v4l2_ctrl_add_handler(hdl_vbi_cap, hdl_streaming, NULL);
  1496. v4l2_ctrl_add_handler(hdl_vbi_cap, hdl_sdtv_cap, NULL);
  1497. v4l2_ctrl_add_handler(hdl_vbi_cap, hdl_loop_cap, NULL);
  1498. if (hdl_vbi_cap->error)
  1499. return hdl_vbi_cap->error;
  1500. dev->vbi_cap_dev.ctrl_handler = hdl_vbi_cap;
  1501. }
  1502. if (dev->has_vbi_out) {
  1503. v4l2_ctrl_add_handler(hdl_vbi_out, hdl_user_gen, NULL);
  1504. v4l2_ctrl_add_handler(hdl_vbi_out, hdl_streaming, NULL);
  1505. if (hdl_vbi_out->error)
  1506. return hdl_vbi_out->error;
  1507. dev->vbi_out_dev.ctrl_handler = hdl_vbi_out;
  1508. }
  1509. if (dev->has_radio_rx) {
  1510. v4l2_ctrl_add_handler(hdl_radio_rx, hdl_user_gen, NULL);
  1511. v4l2_ctrl_add_handler(hdl_radio_rx, hdl_user_aud, NULL);
  1512. if (hdl_radio_rx->error)
  1513. return hdl_radio_rx->error;
  1514. dev->radio_rx_dev.ctrl_handler = hdl_radio_rx;
  1515. }
  1516. if (dev->has_radio_tx) {
  1517. v4l2_ctrl_add_handler(hdl_radio_tx, hdl_user_gen, NULL);
  1518. v4l2_ctrl_add_handler(hdl_radio_tx, hdl_user_aud, NULL);
  1519. if (hdl_radio_tx->error)
  1520. return hdl_radio_tx->error;
  1521. dev->radio_tx_dev.ctrl_handler = hdl_radio_tx;
  1522. }
  1523. if (dev->has_sdr_cap) {
  1524. v4l2_ctrl_add_handler(hdl_sdr_cap, hdl_user_gen, NULL);
  1525. v4l2_ctrl_add_handler(hdl_sdr_cap, hdl_streaming, NULL);
  1526. if (hdl_sdr_cap->error)
  1527. return hdl_sdr_cap->error;
  1528. dev->sdr_cap_dev.ctrl_handler = hdl_sdr_cap;
  1529. }
  1530. return 0;
  1531. }
  1532. void vivid_free_controls(struct vivid_dev *dev)
  1533. {
  1534. v4l2_ctrl_handler_free(&dev->ctrl_hdl_vid_cap);
  1535. v4l2_ctrl_handler_free(&dev->ctrl_hdl_vid_out);
  1536. v4l2_ctrl_handler_free(&dev->ctrl_hdl_vbi_cap);
  1537. v4l2_ctrl_handler_free(&dev->ctrl_hdl_vbi_out);
  1538. v4l2_ctrl_handler_free(&dev->ctrl_hdl_radio_rx);
  1539. v4l2_ctrl_handler_free(&dev->ctrl_hdl_radio_tx);
  1540. v4l2_ctrl_handler_free(&dev->ctrl_hdl_sdr_cap);
  1541. v4l2_ctrl_handler_free(&dev->ctrl_hdl_user_gen);
  1542. v4l2_ctrl_handler_free(&dev->ctrl_hdl_user_vid);
  1543. v4l2_ctrl_handler_free(&dev->ctrl_hdl_user_aud);
  1544. v4l2_ctrl_handler_free(&dev->ctrl_hdl_streaming);
  1545. v4l2_ctrl_handler_free(&dev->ctrl_hdl_sdtv_cap);
  1546. v4l2_ctrl_handler_free(&dev->ctrl_hdl_loop_cap);
  1547. }