vivid-ctrls.c 51 KB

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