Back to home page

OSCL-LXR

 
 

    


0001 // SPDX-License-Identifier: GPL-2.0-only
0002 /*
0003  * Samsung LSI S5C73M3 8M pixel camera driver
0004  *
0005  * Copyright (C) 2012, Samsung Electronics, Co., Ltd.
0006  * Sylwester Nawrocki <s.nawrocki@samsung.com>
0007  * Andrzej Hajda <a.hajda@samsung.com>
0008  */
0009 
0010 #include <linux/sizes.h>
0011 #include <linux/delay.h>
0012 #include <linux/firmware.h>
0013 #include <linux/gpio.h>
0014 #include <linux/i2c.h>
0015 #include <linux/init.h>
0016 #include <linux/media.h>
0017 #include <linux/module.h>
0018 #include <linux/regulator/consumer.h>
0019 #include <linux/slab.h>
0020 #include <linux/spi/spi.h>
0021 #include <linux/videodev2.h>
0022 #include <media/media-entity.h>
0023 #include <media/v4l2-ctrls.h>
0024 #include <media/v4l2-device.h>
0025 #include <media/v4l2-subdev.h>
0026 #include <media/v4l2-mediabus.h>
0027 #include <media/i2c/s5c73m3.h>
0028 
0029 #include "s5c73m3.h"
0030 
0031 static int s5c73m3_get_af_status(struct s5c73m3 *state, struct v4l2_ctrl *ctrl)
0032 {
0033     u16 reg = REG_AF_STATUS_UNFOCUSED;
0034 
0035     int ret = s5c73m3_read(state, REG_AF_STATUS, &reg);
0036 
0037     switch (reg) {
0038     case REG_CAF_STATUS_FIND_SEARCH_DIR:
0039     case REG_AF_STATUS_FOCUSING:
0040     case REG_CAF_STATUS_FOCUSING:
0041         ctrl->val = V4L2_AUTO_FOCUS_STATUS_BUSY;
0042         break;
0043     case REG_CAF_STATUS_FOCUSED:
0044     case REG_AF_STATUS_FOCUSED:
0045         ctrl->val = V4L2_AUTO_FOCUS_STATUS_REACHED;
0046         break;
0047     default:
0048         v4l2_info(&state->sensor_sd, "Unknown AF status %#x\n", reg);
0049         fallthrough;
0050     case REG_CAF_STATUS_UNFOCUSED:
0051     case REG_AF_STATUS_UNFOCUSED:
0052     case REG_AF_STATUS_INVALID:
0053         ctrl->val = V4L2_AUTO_FOCUS_STATUS_FAILED;
0054         break;
0055     }
0056 
0057     return ret;
0058 }
0059 
0060 static int s5c73m3_g_volatile_ctrl(struct v4l2_ctrl *ctrl)
0061 {
0062     struct v4l2_subdev *sd = ctrl_to_sensor_sd(ctrl);
0063     struct s5c73m3 *state = sensor_sd_to_s5c73m3(sd);
0064     int ret;
0065 
0066     if (state->power == 0)
0067         return -EBUSY;
0068 
0069     switch (ctrl->id) {
0070     case V4L2_CID_FOCUS_AUTO:
0071         ret = s5c73m3_get_af_status(state, state->ctrls.af_status);
0072         if (ret)
0073             return ret;
0074         break;
0075     }
0076 
0077     return 0;
0078 }
0079 
0080 static int s5c73m3_set_colorfx(struct s5c73m3 *state, int val)
0081 {
0082     static const unsigned short colorfx[][2] = {
0083         { V4L2_COLORFX_NONE,     COMM_IMAGE_EFFECT_NONE },
0084         { V4L2_COLORFX_BW,   COMM_IMAGE_EFFECT_MONO },
0085         { V4L2_COLORFX_SEPIA,    COMM_IMAGE_EFFECT_SEPIA },
0086         { V4L2_COLORFX_NEGATIVE, COMM_IMAGE_EFFECT_NEGATIVE },
0087         { V4L2_COLORFX_AQUA,     COMM_IMAGE_EFFECT_AQUA },
0088     };
0089     int i;
0090 
0091     for (i = 0; i < ARRAY_SIZE(colorfx); i++) {
0092         if (colorfx[i][0] != val)
0093             continue;
0094 
0095         v4l2_dbg(1, s5c73m3_dbg, &state->sensor_sd,
0096              "Setting %s color effect\n",
0097              v4l2_ctrl_get_menu(state->ctrls.colorfx->id)[i]);
0098 
0099         return s5c73m3_isp_command(state, COMM_IMAGE_EFFECT,
0100                      colorfx[i][1]);
0101     }
0102     return -EINVAL;
0103 }
0104 
0105 /* Set exposure metering/exposure bias */
0106 static int s5c73m3_set_exposure(struct s5c73m3 *state, int auto_exp)
0107 {
0108     struct v4l2_subdev *sd = &state->sensor_sd;
0109     struct s5c73m3_ctrls *ctrls = &state->ctrls;
0110     int ret = 0;
0111 
0112     if (ctrls->exposure_metering->is_new) {
0113         u16 metering;
0114 
0115         switch (ctrls->exposure_metering->val) {
0116         case V4L2_EXPOSURE_METERING_CENTER_WEIGHTED:
0117             metering = COMM_METERING_CENTER;
0118             break;
0119         case V4L2_EXPOSURE_METERING_SPOT:
0120             metering = COMM_METERING_SPOT;
0121             break;
0122         default:
0123             metering = COMM_METERING_AVERAGE;
0124             break;
0125         }
0126 
0127         ret = s5c73m3_isp_command(state, COMM_METERING, metering);
0128     }
0129 
0130     if (!ret && ctrls->exposure_bias->is_new) {
0131         u16 exp_bias = ctrls->exposure_bias->val;
0132         ret = s5c73m3_isp_command(state, COMM_EV, exp_bias);
0133     }
0134 
0135     v4l2_dbg(1, s5c73m3_dbg, sd,
0136          "%s: exposure bias: %#x, metering: %#x (%d)\n",  __func__,
0137          ctrls->exposure_bias->val, ctrls->exposure_metering->val, ret);
0138 
0139     return ret;
0140 }
0141 
0142 static int s5c73m3_set_white_balance(struct s5c73m3 *state, int val)
0143 {
0144     static const unsigned short wb[][2] = {
0145         { V4L2_WHITE_BALANCE_INCANDESCENT,  COMM_AWB_MODE_INCANDESCENT},
0146         { V4L2_WHITE_BALANCE_FLUORESCENT,   COMM_AWB_MODE_FLUORESCENT1},
0147         { V4L2_WHITE_BALANCE_FLUORESCENT_H, COMM_AWB_MODE_FLUORESCENT2},
0148         { V4L2_WHITE_BALANCE_CLOUDY,        COMM_AWB_MODE_CLOUDY},
0149         { V4L2_WHITE_BALANCE_DAYLIGHT,      COMM_AWB_MODE_DAYLIGHT},
0150         { V4L2_WHITE_BALANCE_AUTO,          COMM_AWB_MODE_AUTO},
0151     };
0152     int i;
0153 
0154     for (i = 0; i < ARRAY_SIZE(wb); i++) {
0155         if (wb[i][0] != val)
0156             continue;
0157 
0158         v4l2_dbg(1, s5c73m3_dbg, &state->sensor_sd,
0159              "Setting white balance to: %s\n",
0160              v4l2_ctrl_get_menu(state->ctrls.auto_wb->id)[i]);
0161 
0162         return s5c73m3_isp_command(state, COMM_AWB_MODE, wb[i][1]);
0163     }
0164 
0165     return -EINVAL;
0166 }
0167 
0168 static int s5c73m3_af_run(struct s5c73m3 *state, bool on)
0169 {
0170     struct s5c73m3_ctrls *c = &state->ctrls;
0171 
0172     if (!on)
0173         return s5c73m3_isp_command(state, COMM_AF_CON,
0174                             COMM_AF_CON_STOP);
0175 
0176     if (c->focus_auto->val)
0177         return s5c73m3_isp_command(state, COMM_AF_MODE,
0178                        COMM_AF_MODE_PREVIEW_CAF_START);
0179 
0180     return s5c73m3_isp_command(state, COMM_AF_CON, COMM_AF_CON_START);
0181 }
0182 
0183 static int s5c73m3_3a_lock(struct s5c73m3 *state, struct v4l2_ctrl *ctrl)
0184 {
0185     bool awb_lock = ctrl->val & V4L2_LOCK_WHITE_BALANCE;
0186     bool ae_lock = ctrl->val & V4L2_LOCK_EXPOSURE;
0187     bool af_lock = ctrl->val & V4L2_LOCK_FOCUS;
0188     int ret = 0;
0189 
0190     if ((ctrl->val ^ ctrl->cur.val) & V4L2_LOCK_EXPOSURE) {
0191         ret = s5c73m3_isp_command(state, COMM_AE_CON,
0192                 ae_lock ? COMM_AE_STOP : COMM_AE_START);
0193         if (ret)
0194             return ret;
0195     }
0196 
0197     if (((ctrl->val ^ ctrl->cur.val) & V4L2_LOCK_WHITE_BALANCE)
0198         && state->ctrls.auto_wb->val) {
0199         ret = s5c73m3_isp_command(state, COMM_AWB_CON,
0200             awb_lock ? COMM_AWB_STOP : COMM_AWB_START);
0201         if (ret)
0202             return ret;
0203     }
0204 
0205     if ((ctrl->val ^ ctrl->cur.val) & V4L2_LOCK_FOCUS)
0206         ret = s5c73m3_af_run(state, !af_lock);
0207 
0208     return ret;
0209 }
0210 
0211 static int s5c73m3_set_auto_focus(struct s5c73m3 *state, int caf)
0212 {
0213     struct s5c73m3_ctrls *c = &state->ctrls;
0214     int ret = 1;
0215 
0216     if (c->af_distance->is_new) {
0217         u16 mode = (c->af_distance->val == V4L2_AUTO_FOCUS_RANGE_MACRO)
0218                 ? COMM_AF_MODE_MACRO : COMM_AF_MODE_NORMAL;
0219         ret = s5c73m3_isp_command(state, COMM_AF_MODE, mode);
0220         if (ret != 0)
0221             return ret;
0222     }
0223 
0224     if (!ret || (c->focus_auto->is_new && c->focus_auto->val) ||
0225                             c->af_start->is_new)
0226         ret = s5c73m3_af_run(state, 1);
0227     else if ((c->focus_auto->is_new && !c->focus_auto->val) ||
0228                             c->af_stop->is_new)
0229         ret = s5c73m3_af_run(state, 0);
0230     else
0231         ret = 0;
0232 
0233     return ret;
0234 }
0235 
0236 static int s5c73m3_set_contrast(struct s5c73m3 *state, int val)
0237 {
0238     u16 reg = (val < 0) ? -val + 2 : val;
0239     return s5c73m3_isp_command(state, COMM_CONTRAST, reg);
0240 }
0241 
0242 static int s5c73m3_set_saturation(struct s5c73m3 *state, int val)
0243 {
0244     u16 reg = (val < 0) ? -val + 2 : val;
0245     return s5c73m3_isp_command(state, COMM_SATURATION, reg);
0246 }
0247 
0248 static int s5c73m3_set_sharpness(struct s5c73m3 *state, int val)
0249 {
0250     u16 reg = (val < 0) ? -val + 2 : val;
0251     return s5c73m3_isp_command(state, COMM_SHARPNESS, reg);
0252 }
0253 
0254 static int s5c73m3_set_iso(struct s5c73m3 *state, int val)
0255 {
0256     u32 iso;
0257 
0258     if (val == V4L2_ISO_SENSITIVITY_MANUAL)
0259         iso = state->ctrls.iso->val + 1;
0260     else
0261         iso = 0;
0262 
0263     return s5c73m3_isp_command(state, COMM_ISO, iso);
0264 }
0265 
0266 static int s5c73m3_set_stabilization(struct s5c73m3 *state, int val)
0267 {
0268     struct v4l2_subdev *sd = &state->sensor_sd;
0269 
0270     v4l2_dbg(1, s5c73m3_dbg, sd, "Image stabilization: %d\n", val);
0271 
0272     return s5c73m3_isp_command(state, COMM_FRAME_RATE, val ?
0273             COMM_FRAME_RATE_ANTI_SHAKE : COMM_FRAME_RATE_AUTO_SET);
0274 }
0275 
0276 static int s5c73m3_set_jpeg_quality(struct s5c73m3 *state, int quality)
0277 {
0278     int reg;
0279 
0280     if (quality <= 65)
0281         reg = COMM_IMAGE_QUALITY_NORMAL;
0282     else if (quality <= 75)
0283         reg = COMM_IMAGE_QUALITY_FINE;
0284     else
0285         reg = COMM_IMAGE_QUALITY_SUPERFINE;
0286 
0287     return s5c73m3_isp_command(state, COMM_IMAGE_QUALITY, reg);
0288 }
0289 
0290 static int s5c73m3_set_scene_program(struct s5c73m3 *state, int val)
0291 {
0292     static const unsigned short scene_lookup[] = {
0293         COMM_SCENE_MODE_NONE,        /* V4L2_SCENE_MODE_NONE */
0294         COMM_SCENE_MODE_AGAINST_LIGHT,/* V4L2_SCENE_MODE_BACKLIGHT */
0295         COMM_SCENE_MODE_BEACH,       /* V4L2_SCENE_MODE_BEACH_SNOW */
0296         COMM_SCENE_MODE_CANDLE,      /* V4L2_SCENE_MODE_CANDLE_LIGHT */
0297         COMM_SCENE_MODE_DAWN,        /* V4L2_SCENE_MODE_DAWN_DUSK */
0298         COMM_SCENE_MODE_FALL,        /* V4L2_SCENE_MODE_FALL_COLORS */
0299         COMM_SCENE_MODE_FIRE,        /* V4L2_SCENE_MODE_FIREWORKS */
0300         COMM_SCENE_MODE_LANDSCAPE,    /* V4L2_SCENE_MODE_LANDSCAPE */
0301         COMM_SCENE_MODE_NIGHT,       /* V4L2_SCENE_MODE_NIGHT */
0302         COMM_SCENE_MODE_INDOOR,      /* V4L2_SCENE_MODE_PARTY_INDOOR */
0303         COMM_SCENE_MODE_PORTRAIT,     /* V4L2_SCENE_MODE_PORTRAIT */
0304         COMM_SCENE_MODE_SPORTS,      /* V4L2_SCENE_MODE_SPORTS */
0305         COMM_SCENE_MODE_SUNSET,      /* V4L2_SCENE_MODE_SUNSET */
0306         COMM_SCENE_MODE_TEXT,        /* V4L2_SCENE_MODE_TEXT */
0307     };
0308 
0309     v4l2_dbg(1, s5c73m3_dbg, &state->sensor_sd, "Setting %s scene mode\n",
0310          v4l2_ctrl_get_menu(state->ctrls.scene_mode->id)[val]);
0311 
0312     return s5c73m3_isp_command(state, COMM_SCENE_MODE, scene_lookup[val]);
0313 }
0314 
0315 static int s5c73m3_set_power_line_freq(struct s5c73m3 *state, int val)
0316 {
0317     unsigned int pwr_line_freq = COMM_FLICKER_NONE;
0318 
0319     switch (val) {
0320     case V4L2_CID_POWER_LINE_FREQUENCY_DISABLED:
0321         pwr_line_freq = COMM_FLICKER_NONE;
0322         break;
0323     case V4L2_CID_POWER_LINE_FREQUENCY_50HZ:
0324         pwr_line_freq = COMM_FLICKER_AUTO_50HZ;
0325         break;
0326     case V4L2_CID_POWER_LINE_FREQUENCY_60HZ:
0327         pwr_line_freq = COMM_FLICKER_AUTO_60HZ;
0328         break;
0329     default:
0330     case V4L2_CID_POWER_LINE_FREQUENCY_AUTO:
0331         pwr_line_freq = COMM_FLICKER_NONE;
0332     }
0333 
0334     return s5c73m3_isp_command(state, COMM_FLICKER_MODE, pwr_line_freq);
0335 }
0336 
0337 static int s5c73m3_s_ctrl(struct v4l2_ctrl *ctrl)
0338 {
0339     struct v4l2_subdev *sd = ctrl_to_sensor_sd(ctrl);
0340     struct s5c73m3 *state = sensor_sd_to_s5c73m3(sd);
0341     int ret = 0;
0342 
0343     v4l2_dbg(1, s5c73m3_dbg, sd, "set_ctrl: %s, value: %d\n",
0344          ctrl->name, ctrl->val);
0345 
0346     mutex_lock(&state->lock);
0347     /*
0348      * If the device is not powered up by the host driver do
0349      * not apply any controls to H/W at this time. Instead
0350      * the controls will be restored right after power-up.
0351      */
0352     if (state->power == 0)
0353         goto unlock;
0354 
0355     if (ctrl->flags & V4L2_CTRL_FLAG_INACTIVE) {
0356         ret = -EINVAL;
0357         goto unlock;
0358     }
0359 
0360     switch (ctrl->id) {
0361     case V4L2_CID_3A_LOCK:
0362         ret = s5c73m3_3a_lock(state, ctrl);
0363         break;
0364 
0365     case V4L2_CID_AUTO_N_PRESET_WHITE_BALANCE:
0366         ret = s5c73m3_set_white_balance(state, ctrl->val);
0367         break;
0368 
0369     case V4L2_CID_CONTRAST:
0370         ret = s5c73m3_set_contrast(state, ctrl->val);
0371         break;
0372 
0373     case V4L2_CID_COLORFX:
0374         ret = s5c73m3_set_colorfx(state, ctrl->val);
0375         break;
0376 
0377     case V4L2_CID_EXPOSURE_AUTO:
0378         ret = s5c73m3_set_exposure(state, ctrl->val);
0379         break;
0380 
0381     case V4L2_CID_FOCUS_AUTO:
0382         ret = s5c73m3_set_auto_focus(state, ctrl->val);
0383         break;
0384 
0385     case V4L2_CID_IMAGE_STABILIZATION:
0386         ret = s5c73m3_set_stabilization(state, ctrl->val);
0387         break;
0388 
0389     case V4L2_CID_ISO_SENSITIVITY:
0390         ret = s5c73m3_set_iso(state, ctrl->val);
0391         break;
0392 
0393     case V4L2_CID_JPEG_COMPRESSION_QUALITY:
0394         ret = s5c73m3_set_jpeg_quality(state, ctrl->val);
0395         break;
0396 
0397     case V4L2_CID_POWER_LINE_FREQUENCY:
0398         ret = s5c73m3_set_power_line_freq(state, ctrl->val);
0399         break;
0400 
0401     case V4L2_CID_SATURATION:
0402         ret = s5c73m3_set_saturation(state, ctrl->val);
0403         break;
0404 
0405     case V4L2_CID_SCENE_MODE:
0406         ret = s5c73m3_set_scene_program(state, ctrl->val);
0407         break;
0408 
0409     case V4L2_CID_SHARPNESS:
0410         ret = s5c73m3_set_sharpness(state, ctrl->val);
0411         break;
0412 
0413     case V4L2_CID_WIDE_DYNAMIC_RANGE:
0414         ret = s5c73m3_isp_command(state, COMM_WDR, !!ctrl->val);
0415         break;
0416 
0417     case V4L2_CID_ZOOM_ABSOLUTE:
0418         ret = s5c73m3_isp_command(state, COMM_ZOOM_STEP, ctrl->val);
0419         break;
0420     }
0421 unlock:
0422     mutex_unlock(&state->lock);
0423     return ret;
0424 }
0425 
0426 static const struct v4l2_ctrl_ops s5c73m3_ctrl_ops = {
0427     .g_volatile_ctrl    = s5c73m3_g_volatile_ctrl,
0428     .s_ctrl         = s5c73m3_s_ctrl,
0429 };
0430 
0431 /* Supported manual ISO values */
0432 static const s64 iso_qmenu[] = {
0433     /* COMM_ISO: 0x0001...0x0004 */
0434     100, 200, 400, 800,
0435 };
0436 
0437 /* Supported exposure bias values (-2.0EV...+2.0EV) */
0438 static const s64 ev_bias_qmenu[] = {
0439     /* COMM_EV: 0x0000...0x0008 */
0440     -2000, -1500, -1000, -500, 0, 500, 1000, 1500, 2000
0441 };
0442 
0443 int s5c73m3_init_controls(struct s5c73m3 *state)
0444 {
0445     const struct v4l2_ctrl_ops *ops = &s5c73m3_ctrl_ops;
0446     struct s5c73m3_ctrls *ctrls = &state->ctrls;
0447     struct v4l2_ctrl_handler *hdl = &ctrls->handler;
0448 
0449     int ret = v4l2_ctrl_handler_init(hdl, 22);
0450     if (ret)
0451         return ret;
0452 
0453     /* White balance */
0454     ctrls->auto_wb = v4l2_ctrl_new_std_menu(hdl, ops,
0455             V4L2_CID_AUTO_N_PRESET_WHITE_BALANCE,
0456             9, ~0x15e, V4L2_WHITE_BALANCE_AUTO);
0457 
0458     /* Exposure (only automatic exposure) */
0459     ctrls->auto_exposure = v4l2_ctrl_new_std_menu(hdl, ops,
0460             V4L2_CID_EXPOSURE_AUTO, 0, ~0x01, V4L2_EXPOSURE_AUTO);
0461 
0462     ctrls->exposure_bias = v4l2_ctrl_new_int_menu(hdl, ops,
0463             V4L2_CID_AUTO_EXPOSURE_BIAS,
0464             ARRAY_SIZE(ev_bias_qmenu) - 1,
0465             ARRAY_SIZE(ev_bias_qmenu)/2 - 1,
0466             ev_bias_qmenu);
0467 
0468     ctrls->exposure_metering = v4l2_ctrl_new_std_menu(hdl, ops,
0469             V4L2_CID_EXPOSURE_METERING,
0470             2, ~0x7, V4L2_EXPOSURE_METERING_AVERAGE);
0471 
0472     /* Auto focus */
0473     ctrls->focus_auto = v4l2_ctrl_new_std(hdl, ops,
0474             V4L2_CID_FOCUS_AUTO, 0, 1, 1, 0);
0475 
0476     ctrls->af_start = v4l2_ctrl_new_std(hdl, ops,
0477             V4L2_CID_AUTO_FOCUS_START, 0, 1, 1, 0);
0478 
0479     ctrls->af_stop = v4l2_ctrl_new_std(hdl, ops,
0480             V4L2_CID_AUTO_FOCUS_STOP, 0, 1, 1, 0);
0481 
0482     ctrls->af_status = v4l2_ctrl_new_std(hdl, ops,
0483             V4L2_CID_AUTO_FOCUS_STATUS, 0,
0484             (V4L2_AUTO_FOCUS_STATUS_BUSY |
0485              V4L2_AUTO_FOCUS_STATUS_REACHED |
0486              V4L2_AUTO_FOCUS_STATUS_FAILED),
0487             0, V4L2_AUTO_FOCUS_STATUS_IDLE);
0488 
0489     ctrls->af_distance = v4l2_ctrl_new_std_menu(hdl, ops,
0490             V4L2_CID_AUTO_FOCUS_RANGE,
0491             V4L2_AUTO_FOCUS_RANGE_MACRO,
0492             ~(1 << V4L2_AUTO_FOCUS_RANGE_NORMAL |
0493               1 << V4L2_AUTO_FOCUS_RANGE_MACRO),
0494             V4L2_AUTO_FOCUS_RANGE_NORMAL);
0495     /* ISO sensitivity */
0496     ctrls->auto_iso = v4l2_ctrl_new_std_menu(hdl, ops,
0497             V4L2_CID_ISO_SENSITIVITY_AUTO, 1, 0,
0498             V4L2_ISO_SENSITIVITY_AUTO);
0499 
0500     ctrls->iso = v4l2_ctrl_new_int_menu(hdl, ops,
0501             V4L2_CID_ISO_SENSITIVITY, ARRAY_SIZE(iso_qmenu) - 1,
0502             ARRAY_SIZE(iso_qmenu)/2 - 1, iso_qmenu);
0503 
0504     ctrls->contrast = v4l2_ctrl_new_std(hdl, ops,
0505             V4L2_CID_CONTRAST, -2, 2, 1, 0);
0506 
0507     ctrls->saturation = v4l2_ctrl_new_std(hdl, ops,
0508             V4L2_CID_SATURATION, -2, 2, 1, 0);
0509 
0510     ctrls->sharpness = v4l2_ctrl_new_std(hdl, ops,
0511             V4L2_CID_SHARPNESS, -2, 2, 1, 0);
0512 
0513     ctrls->zoom = v4l2_ctrl_new_std(hdl, ops,
0514             V4L2_CID_ZOOM_ABSOLUTE, 0, 30, 1, 0);
0515 
0516     ctrls->colorfx = v4l2_ctrl_new_std_menu(hdl, ops, V4L2_CID_COLORFX,
0517             V4L2_COLORFX_AQUA, ~0x40f, V4L2_COLORFX_NONE);
0518 
0519     ctrls->wdr = v4l2_ctrl_new_std(hdl, ops,
0520             V4L2_CID_WIDE_DYNAMIC_RANGE, 0, 1, 1, 0);
0521 
0522     ctrls->stabilization = v4l2_ctrl_new_std(hdl, ops,
0523             V4L2_CID_IMAGE_STABILIZATION, 0, 1, 1, 0);
0524 
0525     v4l2_ctrl_new_std_menu(hdl, ops, V4L2_CID_POWER_LINE_FREQUENCY,
0526                    V4L2_CID_POWER_LINE_FREQUENCY_AUTO, 0,
0527                    V4L2_CID_POWER_LINE_FREQUENCY_AUTO);
0528 
0529     ctrls->jpeg_quality = v4l2_ctrl_new_std(hdl, ops,
0530             V4L2_CID_JPEG_COMPRESSION_QUALITY, 1, 100, 1, 80);
0531 
0532     ctrls->scene_mode = v4l2_ctrl_new_std_menu(hdl, ops,
0533             V4L2_CID_SCENE_MODE, V4L2_SCENE_MODE_TEXT, ~0x3fff,
0534             V4L2_SCENE_MODE_NONE);
0535 
0536     ctrls->aaa_lock = v4l2_ctrl_new_std(hdl, ops,
0537             V4L2_CID_3A_LOCK, 0, 0x7, 0, 0);
0538 
0539     if (hdl->error) {
0540         ret = hdl->error;
0541         v4l2_ctrl_handler_free(hdl);
0542         return ret;
0543     }
0544 
0545     v4l2_ctrl_auto_cluster(3, &ctrls->auto_exposure, 0, false);
0546     ctrls->auto_iso->flags |= V4L2_CTRL_FLAG_VOLATILE |
0547                 V4L2_CTRL_FLAG_UPDATE;
0548     v4l2_ctrl_auto_cluster(2, &ctrls->auto_iso, 0, false);
0549     ctrls->af_status->flags |= V4L2_CTRL_FLAG_VOLATILE;
0550     v4l2_ctrl_cluster(5, &ctrls->focus_auto);
0551 
0552     state->sensor_sd.ctrl_handler = hdl;
0553 
0554     return 0;
0555 }