vivid-ctrls.c 50 KB

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