s5c73m3-ctrls.c 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563
  1. /*
  2. * Samsung LSI S5C73M3 8M pixel camera driver
  3. *
  4. * Copyright (C) 2012, Samsung Electronics, Co., Ltd.
  5. * Sylwester Nawrocki <s.nawrocki@samsung.com>
  6. * Andrzej Hajda <a.hajda@samsung.com>
  7. *
  8. * This program is free software; you can redistribute it and/or
  9. * modify it under the terms of the GNU General Public License
  10. * version 2 as published by the Free Software Foundation.
  11. *
  12. * This program is distributed in the hope that it will be useful,
  13. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  14. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  15. * GNU General Public License for more details.
  16. */
  17. #include <linux/sizes.h>
  18. #include <linux/delay.h>
  19. #include <linux/firmware.h>
  20. #include <linux/gpio.h>
  21. #include <linux/i2c.h>
  22. #include <linux/init.h>
  23. #include <linux/media.h>
  24. #include <linux/module.h>
  25. #include <linux/regulator/consumer.h>
  26. #include <linux/slab.h>
  27. #include <linux/spi/spi.h>
  28. #include <linux/videodev2.h>
  29. #include <media/media-entity.h>
  30. #include <media/v4l2-ctrls.h>
  31. #include <media/v4l2-device.h>
  32. #include <media/v4l2-subdev.h>
  33. #include <media/v4l2-mediabus.h>
  34. #include <media/s5c73m3.h>
  35. #include "s5c73m3.h"
  36. static int s5c73m3_get_af_status(struct s5c73m3 *state, struct v4l2_ctrl *ctrl)
  37. {
  38. u16 reg = REG_AF_STATUS_UNFOCUSED;
  39. int ret = s5c73m3_read(state, REG_AF_STATUS, &reg);
  40. switch (reg) {
  41. case REG_CAF_STATUS_FIND_SEARCH_DIR:
  42. case REG_AF_STATUS_FOCUSING:
  43. case REG_CAF_STATUS_FOCUSING:
  44. ctrl->val = V4L2_AUTO_FOCUS_STATUS_BUSY;
  45. break;
  46. case REG_CAF_STATUS_FOCUSED:
  47. case REG_AF_STATUS_FOCUSED:
  48. ctrl->val = V4L2_AUTO_FOCUS_STATUS_REACHED;
  49. break;
  50. default:
  51. v4l2_info(&state->sensor_sd, "Unknown AF status %#x\n", reg);
  52. /* Fall through */
  53. case REG_CAF_STATUS_UNFOCUSED:
  54. case REG_AF_STATUS_UNFOCUSED:
  55. case REG_AF_STATUS_INVALID:
  56. ctrl->val = V4L2_AUTO_FOCUS_STATUS_FAILED;
  57. break;
  58. }
  59. return ret;
  60. }
  61. static int s5c73m3_g_volatile_ctrl(struct v4l2_ctrl *ctrl)
  62. {
  63. struct v4l2_subdev *sd = ctrl_to_sensor_sd(ctrl);
  64. struct s5c73m3 *state = sensor_sd_to_s5c73m3(sd);
  65. int ret;
  66. if (state->power == 0)
  67. return -EBUSY;
  68. switch (ctrl->id) {
  69. case V4L2_CID_FOCUS_AUTO:
  70. ret = s5c73m3_get_af_status(state, state->ctrls.af_status);
  71. if (ret)
  72. return ret;
  73. break;
  74. }
  75. return 0;
  76. }
  77. static int s5c73m3_set_colorfx(struct s5c73m3 *state, int val)
  78. {
  79. static const unsigned short colorfx[][2] = {
  80. { V4L2_COLORFX_NONE, COMM_IMAGE_EFFECT_NONE },
  81. { V4L2_COLORFX_BW, COMM_IMAGE_EFFECT_MONO },
  82. { V4L2_COLORFX_SEPIA, COMM_IMAGE_EFFECT_SEPIA },
  83. { V4L2_COLORFX_NEGATIVE, COMM_IMAGE_EFFECT_NEGATIVE },
  84. { V4L2_COLORFX_AQUA, COMM_IMAGE_EFFECT_AQUA },
  85. };
  86. int i;
  87. for (i = 0; i < ARRAY_SIZE(colorfx); i++) {
  88. if (colorfx[i][0] != val)
  89. continue;
  90. v4l2_dbg(1, s5c73m3_dbg, &state->sensor_sd,
  91. "Setting %s color effect\n",
  92. v4l2_ctrl_get_menu(state->ctrls.colorfx->id)[i]);
  93. return s5c73m3_isp_command(state, COMM_IMAGE_EFFECT,
  94. colorfx[i][1]);
  95. }
  96. return -EINVAL;
  97. }
  98. /* Set exposure metering/exposure bias */
  99. static int s5c73m3_set_exposure(struct s5c73m3 *state, int auto_exp)
  100. {
  101. struct v4l2_subdev *sd = &state->sensor_sd;
  102. struct s5c73m3_ctrls *ctrls = &state->ctrls;
  103. int ret = 0;
  104. if (ctrls->exposure_metering->is_new) {
  105. u16 metering;
  106. switch (ctrls->exposure_metering->val) {
  107. case V4L2_EXPOSURE_METERING_CENTER_WEIGHTED:
  108. metering = COMM_METERING_CENTER;
  109. break;
  110. case V4L2_EXPOSURE_METERING_SPOT:
  111. metering = COMM_METERING_SPOT;
  112. break;
  113. default:
  114. metering = COMM_METERING_AVERAGE;
  115. break;
  116. }
  117. ret = s5c73m3_isp_command(state, COMM_METERING, metering);
  118. }
  119. if (!ret && ctrls->exposure_bias->is_new) {
  120. u16 exp_bias = ctrls->exposure_bias->val;
  121. ret = s5c73m3_isp_command(state, COMM_EV, exp_bias);
  122. }
  123. v4l2_dbg(1, s5c73m3_dbg, sd,
  124. "%s: exposure bias: %#x, metering: %#x (%d)\n", __func__,
  125. ctrls->exposure_bias->val, ctrls->exposure_metering->val, ret);
  126. return ret;
  127. }
  128. static int s5c73m3_set_white_balance(struct s5c73m3 *state, int val)
  129. {
  130. static const unsigned short wb[][2] = {
  131. { V4L2_WHITE_BALANCE_INCANDESCENT, COMM_AWB_MODE_INCANDESCENT},
  132. { V4L2_WHITE_BALANCE_FLUORESCENT, COMM_AWB_MODE_FLUORESCENT1},
  133. { V4L2_WHITE_BALANCE_FLUORESCENT_H, COMM_AWB_MODE_FLUORESCENT2},
  134. { V4L2_WHITE_BALANCE_CLOUDY, COMM_AWB_MODE_CLOUDY},
  135. { V4L2_WHITE_BALANCE_DAYLIGHT, COMM_AWB_MODE_DAYLIGHT},
  136. { V4L2_WHITE_BALANCE_AUTO, COMM_AWB_MODE_AUTO},
  137. };
  138. int i;
  139. for (i = 0; i < ARRAY_SIZE(wb); i++) {
  140. if (wb[i][0] != val)
  141. continue;
  142. v4l2_dbg(1, s5c73m3_dbg, &state->sensor_sd,
  143. "Setting white balance to: %s\n",
  144. v4l2_ctrl_get_menu(state->ctrls.auto_wb->id)[i]);
  145. return s5c73m3_isp_command(state, COMM_AWB_MODE, wb[i][1]);
  146. }
  147. return -EINVAL;
  148. }
  149. static int s5c73m3_af_run(struct s5c73m3 *state, bool on)
  150. {
  151. struct s5c73m3_ctrls *c = &state->ctrls;
  152. if (!on)
  153. return s5c73m3_isp_command(state, COMM_AF_CON,
  154. COMM_AF_CON_STOP);
  155. if (c->focus_auto->val)
  156. return s5c73m3_isp_command(state, COMM_AF_MODE,
  157. COMM_AF_MODE_PREVIEW_CAF_START);
  158. return s5c73m3_isp_command(state, COMM_AF_CON, COMM_AF_CON_START);
  159. }
  160. static int s5c73m3_3a_lock(struct s5c73m3 *state, struct v4l2_ctrl *ctrl)
  161. {
  162. bool awb_lock = ctrl->val & V4L2_LOCK_WHITE_BALANCE;
  163. bool ae_lock = ctrl->val & V4L2_LOCK_EXPOSURE;
  164. bool af_lock = ctrl->val & V4L2_LOCK_FOCUS;
  165. int ret = 0;
  166. if ((ctrl->val ^ ctrl->cur.val) & V4L2_LOCK_EXPOSURE) {
  167. ret = s5c73m3_isp_command(state, COMM_AE_CON,
  168. ae_lock ? COMM_AE_STOP : COMM_AE_START);
  169. if (ret)
  170. return ret;
  171. }
  172. if (((ctrl->val ^ ctrl->cur.val) & V4L2_LOCK_WHITE_BALANCE)
  173. && state->ctrls.auto_wb->val) {
  174. ret = s5c73m3_isp_command(state, COMM_AWB_CON,
  175. awb_lock ? COMM_AWB_STOP : COMM_AWB_START);
  176. if (ret)
  177. return ret;
  178. }
  179. if ((ctrl->val ^ ctrl->cur.val) & V4L2_LOCK_FOCUS)
  180. ret = s5c73m3_af_run(state, !af_lock);
  181. return ret;
  182. }
  183. static int s5c73m3_set_auto_focus(struct s5c73m3 *state, int caf)
  184. {
  185. struct s5c73m3_ctrls *c = &state->ctrls;
  186. int ret = 1;
  187. if (c->af_distance->is_new) {
  188. u16 mode = (c->af_distance->val == V4L2_AUTO_FOCUS_RANGE_MACRO)
  189. ? COMM_AF_MODE_MACRO : COMM_AF_MODE_NORMAL;
  190. ret = s5c73m3_isp_command(state, COMM_AF_MODE, mode);
  191. if (ret != 0)
  192. return ret;
  193. }
  194. if (!ret || (c->focus_auto->is_new && c->focus_auto->val) ||
  195. c->af_start->is_new)
  196. ret = s5c73m3_af_run(state, 1);
  197. else if ((c->focus_auto->is_new && !c->focus_auto->val) ||
  198. c->af_stop->is_new)
  199. ret = s5c73m3_af_run(state, 0);
  200. else
  201. ret = 0;
  202. return ret;
  203. }
  204. static int s5c73m3_set_contrast(struct s5c73m3 *state, int val)
  205. {
  206. u16 reg = (val < 0) ? -val + 2 : val;
  207. return s5c73m3_isp_command(state, COMM_CONTRAST, reg);
  208. }
  209. static int s5c73m3_set_saturation(struct s5c73m3 *state, int val)
  210. {
  211. u16 reg = (val < 0) ? -val + 2 : val;
  212. return s5c73m3_isp_command(state, COMM_SATURATION, reg);
  213. }
  214. static int s5c73m3_set_sharpness(struct s5c73m3 *state, int val)
  215. {
  216. u16 reg = (val < 0) ? -val + 2 : val;
  217. return s5c73m3_isp_command(state, COMM_SHARPNESS, reg);
  218. }
  219. static int s5c73m3_set_iso(struct s5c73m3 *state, int val)
  220. {
  221. u32 iso;
  222. if (val == V4L2_ISO_SENSITIVITY_MANUAL)
  223. iso = state->ctrls.iso->val + 1;
  224. else
  225. iso = 0;
  226. return s5c73m3_isp_command(state, COMM_ISO, iso);
  227. }
  228. static int s5c73m3_set_stabilization(struct s5c73m3 *state, int val)
  229. {
  230. struct v4l2_subdev *sd = &state->sensor_sd;
  231. v4l2_dbg(1, s5c73m3_dbg, sd, "Image stabilization: %d\n", val);
  232. return s5c73m3_isp_command(state, COMM_FRAME_RATE, val ?
  233. COMM_FRAME_RATE_ANTI_SHAKE : COMM_FRAME_RATE_AUTO_SET);
  234. }
  235. static int s5c73m3_set_jpeg_quality(struct s5c73m3 *state, int quality)
  236. {
  237. int reg;
  238. if (quality <= 65)
  239. reg = COMM_IMAGE_QUALITY_NORMAL;
  240. else if (quality <= 75)
  241. reg = COMM_IMAGE_QUALITY_FINE;
  242. else
  243. reg = COMM_IMAGE_QUALITY_SUPERFINE;
  244. return s5c73m3_isp_command(state, COMM_IMAGE_QUALITY, reg);
  245. }
  246. static int s5c73m3_set_scene_program(struct s5c73m3 *state, int val)
  247. {
  248. static const unsigned short scene_lookup[] = {
  249. COMM_SCENE_MODE_NONE, /* V4L2_SCENE_MODE_NONE */
  250. COMM_SCENE_MODE_AGAINST_LIGHT,/* V4L2_SCENE_MODE_BACKLIGHT */
  251. COMM_SCENE_MODE_BEACH, /* V4L2_SCENE_MODE_BEACH_SNOW */
  252. COMM_SCENE_MODE_CANDLE, /* V4L2_SCENE_MODE_CANDLE_LIGHT */
  253. COMM_SCENE_MODE_DAWN, /* V4L2_SCENE_MODE_DAWN_DUSK */
  254. COMM_SCENE_MODE_FALL, /* V4L2_SCENE_MODE_FALL_COLORS */
  255. COMM_SCENE_MODE_FIRE, /* V4L2_SCENE_MODE_FIREWORKS */
  256. COMM_SCENE_MODE_LANDSCAPE, /* V4L2_SCENE_MODE_LANDSCAPE */
  257. COMM_SCENE_MODE_NIGHT, /* V4L2_SCENE_MODE_NIGHT */
  258. COMM_SCENE_MODE_INDOOR, /* V4L2_SCENE_MODE_PARTY_INDOOR */
  259. COMM_SCENE_MODE_PORTRAIT, /* V4L2_SCENE_MODE_PORTRAIT */
  260. COMM_SCENE_MODE_SPORTS, /* V4L2_SCENE_MODE_SPORTS */
  261. COMM_SCENE_MODE_SUNSET, /* V4L2_SCENE_MODE_SUNSET */
  262. COMM_SCENE_MODE_TEXT, /* V4L2_SCENE_MODE_TEXT */
  263. };
  264. v4l2_dbg(1, s5c73m3_dbg, &state->sensor_sd, "Setting %s scene mode\n",
  265. v4l2_ctrl_get_menu(state->ctrls.scene_mode->id)[val]);
  266. return s5c73m3_isp_command(state, COMM_SCENE_MODE, scene_lookup[val]);
  267. }
  268. static int s5c73m3_set_power_line_freq(struct s5c73m3 *state, int val)
  269. {
  270. unsigned int pwr_line_freq = COMM_FLICKER_NONE;
  271. switch (val) {
  272. case V4L2_CID_POWER_LINE_FREQUENCY_DISABLED:
  273. pwr_line_freq = COMM_FLICKER_NONE;
  274. break;
  275. case V4L2_CID_POWER_LINE_FREQUENCY_50HZ:
  276. pwr_line_freq = COMM_FLICKER_AUTO_50HZ;
  277. break;
  278. case V4L2_CID_POWER_LINE_FREQUENCY_60HZ:
  279. pwr_line_freq = COMM_FLICKER_AUTO_60HZ;
  280. break;
  281. default:
  282. case V4L2_CID_POWER_LINE_FREQUENCY_AUTO:
  283. pwr_line_freq = COMM_FLICKER_NONE;
  284. }
  285. return s5c73m3_isp_command(state, COMM_FLICKER_MODE, pwr_line_freq);
  286. }
  287. static int s5c73m3_s_ctrl(struct v4l2_ctrl *ctrl)
  288. {
  289. struct v4l2_subdev *sd = ctrl_to_sensor_sd(ctrl);
  290. struct s5c73m3 *state = sensor_sd_to_s5c73m3(sd);
  291. int ret = 0;
  292. v4l2_dbg(1, s5c73m3_dbg, sd, "set_ctrl: %s, value: %d\n",
  293. ctrl->name, ctrl->val);
  294. mutex_lock(&state->lock);
  295. /*
  296. * If the device is not powered up by the host driver do
  297. * not apply any controls to H/W at this time. Instead
  298. * the controls will be restored right after power-up.
  299. */
  300. if (state->power == 0)
  301. goto unlock;
  302. if (ctrl->flags & V4L2_CTRL_FLAG_INACTIVE) {
  303. ret = -EINVAL;
  304. goto unlock;
  305. }
  306. switch (ctrl->id) {
  307. case V4L2_CID_3A_LOCK:
  308. ret = s5c73m3_3a_lock(state, ctrl);
  309. break;
  310. case V4L2_CID_AUTO_N_PRESET_WHITE_BALANCE:
  311. ret = s5c73m3_set_white_balance(state, ctrl->val);
  312. break;
  313. case V4L2_CID_CONTRAST:
  314. ret = s5c73m3_set_contrast(state, ctrl->val);
  315. break;
  316. case V4L2_CID_COLORFX:
  317. ret = s5c73m3_set_colorfx(state, ctrl->val);
  318. break;
  319. case V4L2_CID_EXPOSURE_AUTO:
  320. ret = s5c73m3_set_exposure(state, ctrl->val);
  321. break;
  322. case V4L2_CID_FOCUS_AUTO:
  323. ret = s5c73m3_set_auto_focus(state, ctrl->val);
  324. break;
  325. case V4L2_CID_IMAGE_STABILIZATION:
  326. ret = s5c73m3_set_stabilization(state, ctrl->val);
  327. break;
  328. case V4L2_CID_ISO_SENSITIVITY:
  329. ret = s5c73m3_set_iso(state, ctrl->val);
  330. break;
  331. case V4L2_CID_JPEG_COMPRESSION_QUALITY:
  332. ret = s5c73m3_set_jpeg_quality(state, ctrl->val);
  333. break;
  334. case V4L2_CID_POWER_LINE_FREQUENCY:
  335. ret = s5c73m3_set_power_line_freq(state, ctrl->val);
  336. break;
  337. case V4L2_CID_SATURATION:
  338. ret = s5c73m3_set_saturation(state, ctrl->val);
  339. break;
  340. case V4L2_CID_SCENE_MODE:
  341. ret = s5c73m3_set_scene_program(state, ctrl->val);
  342. break;
  343. case V4L2_CID_SHARPNESS:
  344. ret = s5c73m3_set_sharpness(state, ctrl->val);
  345. break;
  346. case V4L2_CID_WIDE_DYNAMIC_RANGE:
  347. ret = s5c73m3_isp_command(state, COMM_WDR, !!ctrl->val);
  348. break;
  349. case V4L2_CID_ZOOM_ABSOLUTE:
  350. ret = s5c73m3_isp_command(state, COMM_ZOOM_STEP, ctrl->val);
  351. break;
  352. }
  353. unlock:
  354. mutex_unlock(&state->lock);
  355. return ret;
  356. }
  357. static const struct v4l2_ctrl_ops s5c73m3_ctrl_ops = {
  358. .g_volatile_ctrl = s5c73m3_g_volatile_ctrl,
  359. .s_ctrl = s5c73m3_s_ctrl,
  360. };
  361. /* Supported manual ISO values */
  362. static const s64 iso_qmenu[] = {
  363. /* COMM_ISO: 0x0001...0x0004 */
  364. 100, 200, 400, 800,
  365. };
  366. /* Supported exposure bias values (-2.0EV...+2.0EV) */
  367. static const s64 ev_bias_qmenu[] = {
  368. /* COMM_EV: 0x0000...0x0008 */
  369. -2000, -1500, -1000, -500, 0, 500, 1000, 1500, 2000
  370. };
  371. int s5c73m3_init_controls(struct s5c73m3 *state)
  372. {
  373. const struct v4l2_ctrl_ops *ops = &s5c73m3_ctrl_ops;
  374. struct s5c73m3_ctrls *ctrls = &state->ctrls;
  375. struct v4l2_ctrl_handler *hdl = &ctrls->handler;
  376. int ret = v4l2_ctrl_handler_init(hdl, 22);
  377. if (ret)
  378. return ret;
  379. /* White balance */
  380. ctrls->auto_wb = v4l2_ctrl_new_std_menu(hdl, ops,
  381. V4L2_CID_AUTO_N_PRESET_WHITE_BALANCE,
  382. 9, ~0x15e, V4L2_WHITE_BALANCE_AUTO);
  383. /* Exposure (only automatic exposure) */
  384. ctrls->auto_exposure = v4l2_ctrl_new_std_menu(hdl, ops,
  385. V4L2_CID_EXPOSURE_AUTO, 0, ~0x01, V4L2_EXPOSURE_AUTO);
  386. ctrls->exposure_bias = v4l2_ctrl_new_int_menu(hdl, ops,
  387. V4L2_CID_AUTO_EXPOSURE_BIAS,
  388. ARRAY_SIZE(ev_bias_qmenu) - 1,
  389. ARRAY_SIZE(ev_bias_qmenu)/2 - 1,
  390. ev_bias_qmenu);
  391. ctrls->exposure_metering = v4l2_ctrl_new_std_menu(hdl, ops,
  392. V4L2_CID_EXPOSURE_METERING,
  393. 2, ~0x7, V4L2_EXPOSURE_METERING_AVERAGE);
  394. /* Auto focus */
  395. ctrls->focus_auto = v4l2_ctrl_new_std(hdl, ops,
  396. V4L2_CID_FOCUS_AUTO, 0, 1, 1, 0);
  397. ctrls->af_start = v4l2_ctrl_new_std(hdl, ops,
  398. V4L2_CID_AUTO_FOCUS_START, 0, 1, 1, 0);
  399. ctrls->af_stop = v4l2_ctrl_new_std(hdl, ops,
  400. V4L2_CID_AUTO_FOCUS_STOP, 0, 1, 1, 0);
  401. ctrls->af_status = v4l2_ctrl_new_std(hdl, ops,
  402. V4L2_CID_AUTO_FOCUS_STATUS, 0,
  403. (V4L2_AUTO_FOCUS_STATUS_BUSY |
  404. V4L2_AUTO_FOCUS_STATUS_REACHED |
  405. V4L2_AUTO_FOCUS_STATUS_FAILED),
  406. 0, V4L2_AUTO_FOCUS_STATUS_IDLE);
  407. ctrls->af_distance = v4l2_ctrl_new_std_menu(hdl, ops,
  408. V4L2_CID_AUTO_FOCUS_RANGE,
  409. V4L2_AUTO_FOCUS_RANGE_MACRO,
  410. ~(1 << V4L2_AUTO_FOCUS_RANGE_NORMAL |
  411. 1 << V4L2_AUTO_FOCUS_RANGE_MACRO),
  412. V4L2_AUTO_FOCUS_RANGE_NORMAL);
  413. /* ISO sensitivity */
  414. ctrls->auto_iso = v4l2_ctrl_new_std_menu(hdl, ops,
  415. V4L2_CID_ISO_SENSITIVITY_AUTO, 1, 0,
  416. V4L2_ISO_SENSITIVITY_AUTO);
  417. ctrls->iso = v4l2_ctrl_new_int_menu(hdl, ops,
  418. V4L2_CID_ISO_SENSITIVITY, ARRAY_SIZE(iso_qmenu) - 1,
  419. ARRAY_SIZE(iso_qmenu)/2 - 1, iso_qmenu);
  420. ctrls->contrast = v4l2_ctrl_new_std(hdl, ops,
  421. V4L2_CID_CONTRAST, -2, 2, 1, 0);
  422. ctrls->saturation = v4l2_ctrl_new_std(hdl, ops,
  423. V4L2_CID_SATURATION, -2, 2, 1, 0);
  424. ctrls->sharpness = v4l2_ctrl_new_std(hdl, ops,
  425. V4L2_CID_SHARPNESS, -2, 2, 1, 0);
  426. ctrls->zoom = v4l2_ctrl_new_std(hdl, ops,
  427. V4L2_CID_ZOOM_ABSOLUTE, 0, 30, 1, 0);
  428. ctrls->colorfx = v4l2_ctrl_new_std_menu(hdl, ops, V4L2_CID_COLORFX,
  429. V4L2_COLORFX_AQUA, ~0x40f, V4L2_COLORFX_NONE);
  430. ctrls->wdr = v4l2_ctrl_new_std(hdl, ops,
  431. V4L2_CID_WIDE_DYNAMIC_RANGE, 0, 1, 1, 0);
  432. ctrls->stabilization = v4l2_ctrl_new_std(hdl, ops,
  433. V4L2_CID_IMAGE_STABILIZATION, 0, 1, 1, 0);
  434. v4l2_ctrl_new_std_menu(hdl, ops, V4L2_CID_POWER_LINE_FREQUENCY,
  435. V4L2_CID_POWER_LINE_FREQUENCY_AUTO, 0,
  436. V4L2_CID_POWER_LINE_FREQUENCY_AUTO);
  437. ctrls->jpeg_quality = v4l2_ctrl_new_std(hdl, ops,
  438. V4L2_CID_JPEG_COMPRESSION_QUALITY, 1, 100, 1, 80);
  439. ctrls->scene_mode = v4l2_ctrl_new_std_menu(hdl, ops,
  440. V4L2_CID_SCENE_MODE, V4L2_SCENE_MODE_TEXT, ~0x3fff,
  441. V4L2_SCENE_MODE_NONE);
  442. ctrls->aaa_lock = v4l2_ctrl_new_std(hdl, ops,
  443. V4L2_CID_3A_LOCK, 0, 0x7, 0, 0);
  444. if (hdl->error) {
  445. ret = hdl->error;
  446. v4l2_ctrl_handler_free(hdl);
  447. return ret;
  448. }
  449. v4l2_ctrl_auto_cluster(3, &ctrls->auto_exposure, 0, false);
  450. ctrls->auto_iso->flags |= V4L2_CTRL_FLAG_VOLATILE |
  451. V4L2_CTRL_FLAG_UPDATE;
  452. v4l2_ctrl_auto_cluster(2, &ctrls->auto_iso, 0, false);
  453. ctrls->af_status->flags |= V4L2_CTRL_FLAG_VOLATILE;
  454. v4l2_ctrl_cluster(6, &ctrls->focus_auto);
  455. state->sensor_sd.ctrl_handler = hdl;
  456. return 0;
  457. }