Lines Matching +full:bias +full:- +full:ctrl +full:- +full:value

1 // SPDX-License-Identifier: GPL-2.0-only
21 #include <media/media-entity.h>
22 #include <media/v4l2-ctrls.h>
23 #include <media/v4l2-device.h>
24 #include <media/v4l2-subdev.h>
25 #include <media/v4l2-mediabus.h>
29 static int s5c73m3_get_af_status(struct s5c73m3 *state, struct v4l2_ctrl *ctrl) in s5c73m3_get_af_status() argument
39 ctrl->val = V4L2_AUTO_FOCUS_STATUS_BUSY; in s5c73m3_get_af_status()
43 ctrl->val = V4L2_AUTO_FOCUS_STATUS_REACHED; in s5c73m3_get_af_status()
46 v4l2_info(&state->sensor_sd, "Unknown AF status %#x\n", reg); in s5c73m3_get_af_status()
51 ctrl->val = V4L2_AUTO_FOCUS_STATUS_FAILED; in s5c73m3_get_af_status()
58 static int s5c73m3_g_volatile_ctrl(struct v4l2_ctrl *ctrl) in s5c73m3_g_volatile_ctrl() argument
60 struct v4l2_subdev *sd = ctrl_to_sensor_sd(ctrl); in s5c73m3_g_volatile_ctrl()
64 if (state->power == 0) in s5c73m3_g_volatile_ctrl()
65 return -EBUSY; in s5c73m3_g_volatile_ctrl()
67 switch (ctrl->id) { in s5c73m3_g_volatile_ctrl()
69 ret = s5c73m3_get_af_status(state, state->ctrls.af_status); in s5c73m3_g_volatile_ctrl()
93 v4l2_dbg(1, s5c73m3_dbg, &state->sensor_sd, in s5c73m3_set_colorfx()
95 v4l2_ctrl_get_menu(state->ctrls.colorfx->id)[i]); in s5c73m3_set_colorfx()
100 return -EINVAL; in s5c73m3_set_colorfx()
103 /* Set exposure metering/exposure bias */
106 struct v4l2_subdev *sd = &state->sensor_sd; in s5c73m3_set_exposure()
107 struct s5c73m3_ctrls *ctrls = &state->ctrls; in s5c73m3_set_exposure()
110 if (ctrls->exposure_metering->is_new) { in s5c73m3_set_exposure()
113 switch (ctrls->exposure_metering->val) { in s5c73m3_set_exposure()
128 if (!ret && ctrls->exposure_bias->is_new) { in s5c73m3_set_exposure()
129 u16 exp_bias = ctrls->exposure_bias->val; in s5c73m3_set_exposure()
134 "%s: exposure bias: %#x, metering: %#x (%d)\n", __func__, in s5c73m3_set_exposure()
135 ctrls->exposure_bias->val, ctrls->exposure_metering->val, ret); in s5c73m3_set_exposure()
156 v4l2_dbg(1, s5c73m3_dbg, &state->sensor_sd, in s5c73m3_set_white_balance()
158 v4l2_ctrl_get_menu(state->ctrls.auto_wb->id)[i]); in s5c73m3_set_white_balance()
163 return -EINVAL; in s5c73m3_set_white_balance()
168 struct s5c73m3_ctrls *c = &state->ctrls; in s5c73m3_af_run()
174 if (c->focus_auto->val) in s5c73m3_af_run()
181 static int s5c73m3_3a_lock(struct s5c73m3 *state, struct v4l2_ctrl *ctrl) in s5c73m3_3a_lock() argument
183 bool awb_lock = ctrl->val & V4L2_LOCK_WHITE_BALANCE; in s5c73m3_3a_lock()
184 bool ae_lock = ctrl->val & V4L2_LOCK_EXPOSURE; in s5c73m3_3a_lock()
185 bool af_lock = ctrl->val & V4L2_LOCK_FOCUS; in s5c73m3_3a_lock()
188 if ((ctrl->val ^ ctrl->cur.val) & V4L2_LOCK_EXPOSURE) { in s5c73m3_3a_lock()
195 if (((ctrl->val ^ ctrl->cur.val) & V4L2_LOCK_WHITE_BALANCE) in s5c73m3_3a_lock()
196 && state->ctrls.auto_wb->val) { in s5c73m3_3a_lock()
203 if ((ctrl->val ^ ctrl->cur.val) & V4L2_LOCK_FOCUS) in s5c73m3_3a_lock()
211 struct s5c73m3_ctrls *c = &state->ctrls; in s5c73m3_set_auto_focus()
214 if (c->af_distance->is_new) { in s5c73m3_set_auto_focus()
215 u16 mode = (c->af_distance->val == V4L2_AUTO_FOCUS_RANGE_MACRO) in s5c73m3_set_auto_focus()
222 if (!ret || (c->focus_auto->is_new && c->focus_auto->val) || in s5c73m3_set_auto_focus()
223 c->af_start->is_new) in s5c73m3_set_auto_focus()
225 else if ((c->focus_auto->is_new && !c->focus_auto->val) || in s5c73m3_set_auto_focus()
226 c->af_stop->is_new) in s5c73m3_set_auto_focus()
236 u16 reg = (val < 0) ? -val + 2 : val; in s5c73m3_set_contrast()
242 u16 reg = (val < 0) ? -val + 2 : val; in s5c73m3_set_saturation()
248 u16 reg = (val < 0) ? -val + 2 : val; in s5c73m3_set_sharpness()
257 iso = state->ctrls.iso->val + 1; in s5c73m3_set_iso()
266 struct v4l2_subdev *sd = &state->sensor_sd; in s5c73m3_set_stabilization()
307 v4l2_dbg(1, s5c73m3_dbg, &state->sensor_sd, "Setting %s scene mode\n", in s5c73m3_set_scene_program()
308 v4l2_ctrl_get_menu(state->ctrls.scene_mode->id)[val]); in s5c73m3_set_scene_program()
335 static int s5c73m3_s_ctrl(struct v4l2_ctrl *ctrl) in s5c73m3_s_ctrl() argument
337 struct v4l2_subdev *sd = ctrl_to_sensor_sd(ctrl); in s5c73m3_s_ctrl()
341 v4l2_dbg(1, s5c73m3_dbg, sd, "set_ctrl: %s, value: %d\n", in s5c73m3_s_ctrl()
342 ctrl->name, ctrl->val); in s5c73m3_s_ctrl()
344 mutex_lock(&state->lock); in s5c73m3_s_ctrl()
348 * the controls will be restored right after power-up. in s5c73m3_s_ctrl()
350 if (state->power == 0) in s5c73m3_s_ctrl()
353 if (ctrl->flags & V4L2_CTRL_FLAG_INACTIVE) { in s5c73m3_s_ctrl()
354 ret = -EINVAL; in s5c73m3_s_ctrl()
358 switch (ctrl->id) { in s5c73m3_s_ctrl()
360 ret = s5c73m3_3a_lock(state, ctrl); in s5c73m3_s_ctrl()
364 ret = s5c73m3_set_white_balance(state, ctrl->val); in s5c73m3_s_ctrl()
368 ret = s5c73m3_set_contrast(state, ctrl->val); in s5c73m3_s_ctrl()
372 ret = s5c73m3_set_colorfx(state, ctrl->val); in s5c73m3_s_ctrl()
376 ret = s5c73m3_set_exposure(state, ctrl->val); in s5c73m3_s_ctrl()
380 ret = s5c73m3_set_auto_focus(state, ctrl->val); in s5c73m3_s_ctrl()
384 ret = s5c73m3_set_stabilization(state, ctrl->val); in s5c73m3_s_ctrl()
388 ret = s5c73m3_set_iso(state, ctrl->val); in s5c73m3_s_ctrl()
392 ret = s5c73m3_set_jpeg_quality(state, ctrl->val); in s5c73m3_s_ctrl()
396 ret = s5c73m3_set_power_line_freq(state, ctrl->val); in s5c73m3_s_ctrl()
400 ret = s5c73m3_set_saturation(state, ctrl->val); in s5c73m3_s_ctrl()
404 ret = s5c73m3_set_scene_program(state, ctrl->val); in s5c73m3_s_ctrl()
408 ret = s5c73m3_set_sharpness(state, ctrl->val); in s5c73m3_s_ctrl()
412 ret = s5c73m3_isp_command(state, COMM_WDR, !!ctrl->val); in s5c73m3_s_ctrl()
416 ret = s5c73m3_isp_command(state, COMM_ZOOM_STEP, ctrl->val); in s5c73m3_s_ctrl()
420 mutex_unlock(&state->lock); in s5c73m3_s_ctrl()
435 /* Supported exposure bias values (-2.0EV...+2.0EV) */
438 -2000, -1500, -1000, -500, 0, 500, 1000, 1500, 2000
444 struct s5c73m3_ctrls *ctrls = &state->ctrls; in s5c73m3_init_controls()
445 struct v4l2_ctrl_handler *hdl = &ctrls->handler; in s5c73m3_init_controls()
452 ctrls->auto_wb = v4l2_ctrl_new_std_menu(hdl, ops, in s5c73m3_init_controls()
457 ctrls->auto_exposure = v4l2_ctrl_new_std_menu(hdl, ops, in s5c73m3_init_controls()
460 ctrls->exposure_bias = v4l2_ctrl_new_int_menu(hdl, ops, in s5c73m3_init_controls()
462 ARRAY_SIZE(ev_bias_qmenu) - 1, in s5c73m3_init_controls()
463 ARRAY_SIZE(ev_bias_qmenu)/2 - 1, in s5c73m3_init_controls()
466 ctrls->exposure_metering = v4l2_ctrl_new_std_menu(hdl, ops, in s5c73m3_init_controls()
471 ctrls->focus_auto = v4l2_ctrl_new_std(hdl, ops, in s5c73m3_init_controls()
474 ctrls->af_start = v4l2_ctrl_new_std(hdl, ops, in s5c73m3_init_controls()
477 ctrls->af_stop = v4l2_ctrl_new_std(hdl, ops, in s5c73m3_init_controls()
480 ctrls->af_status = v4l2_ctrl_new_std(hdl, ops, in s5c73m3_init_controls()
487 ctrls->af_distance = v4l2_ctrl_new_std_menu(hdl, ops, in s5c73m3_init_controls()
494 ctrls->auto_iso = v4l2_ctrl_new_std_menu(hdl, ops, in s5c73m3_init_controls()
498 ctrls->iso = v4l2_ctrl_new_int_menu(hdl, ops, in s5c73m3_init_controls()
499 V4L2_CID_ISO_SENSITIVITY, ARRAY_SIZE(iso_qmenu) - 1, in s5c73m3_init_controls()
500 ARRAY_SIZE(iso_qmenu)/2 - 1, iso_qmenu); in s5c73m3_init_controls()
502 ctrls->contrast = v4l2_ctrl_new_std(hdl, ops, in s5c73m3_init_controls()
503 V4L2_CID_CONTRAST, -2, 2, 1, 0); in s5c73m3_init_controls()
505 ctrls->saturation = v4l2_ctrl_new_std(hdl, ops, in s5c73m3_init_controls()
506 V4L2_CID_SATURATION, -2, 2, 1, 0); in s5c73m3_init_controls()
508 ctrls->sharpness = v4l2_ctrl_new_std(hdl, ops, in s5c73m3_init_controls()
509 V4L2_CID_SHARPNESS, -2, 2, 1, 0); in s5c73m3_init_controls()
511 ctrls->zoom = v4l2_ctrl_new_std(hdl, ops, in s5c73m3_init_controls()
514 ctrls->colorfx = v4l2_ctrl_new_std_menu(hdl, ops, V4L2_CID_COLORFX, in s5c73m3_init_controls()
517 ctrls->wdr = v4l2_ctrl_new_std(hdl, ops, in s5c73m3_init_controls()
520 ctrls->stabilization = v4l2_ctrl_new_std(hdl, ops, in s5c73m3_init_controls()
527 ctrls->jpeg_quality = v4l2_ctrl_new_std(hdl, ops, in s5c73m3_init_controls()
530 ctrls->scene_mode = v4l2_ctrl_new_std_menu(hdl, ops, in s5c73m3_init_controls()
534 ctrls->aaa_lock = v4l2_ctrl_new_std(hdl, ops, in s5c73m3_init_controls()
537 if (hdl->error) { in s5c73m3_init_controls()
538 ret = hdl->error; in s5c73m3_init_controls()
543 v4l2_ctrl_auto_cluster(3, &ctrls->auto_exposure, 0, false); in s5c73m3_init_controls()
544 ctrls->auto_iso->flags |= V4L2_CTRL_FLAG_VOLATILE | in s5c73m3_init_controls()
546 v4l2_ctrl_auto_cluster(2, &ctrls->auto_iso, 0, false); in s5c73m3_init_controls()
547 ctrls->af_status->flags |= V4L2_CTRL_FLAG_VOLATILE; in s5c73m3_init_controls()
548 v4l2_ctrl_cluster(5, &ctrls->focus_auto); in s5c73m3_init_controls()
550 state->sensor_sd.ctrl_handler = hdl; in s5c73m3_init_controls()