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