Lines Matching +full:gain +full:- +full:scaling +full:- +full:n

1 // SPDX-License-Identifier: GPL-2.0-or-later
3 * Copyright (C) 2011-2013 Freescale Semiconductor, Inc. All Rights Reserved.
4 * Copyright (C) 2014-2017 Mentor Graphics Inc.
8 #include <linux/clk-provider.h>
22 #include <media/v4l2-async.h>
23 #include <media/v4l2-ctrls.h>
24 #include <media/v4l2-device.h>
25 #include <media/v4l2-event.h>
26 #include <media/v4l2-fwnode.h>
27 #include <media/v4l2-subdev.h>
167 * MIPI CSI-2 link frequencies.
339 * to set the MIPI CSI-2 virtual channel.
344 "MIPI CSI-2 virtual channel (0..3), default 0");
363 * Image size upper 1280 * 960 are SCALING
367 SCALING, enumerator
380 /* Visibile crop: from analog crop top-left corner. */
424 struct v4l2_ctrl *gain; member
477 return &container_of(ctrl->handler, struct ov5640_dev, in ctrl_to_sd()
478 ctrls.handler)->sd; in ctrl_to_sd()
483 return sensor->ep.bus_type == V4L2_MBUS_CSI2_DPHY; in ov5640_is_csi2()
512 return format->bpp; in ov5640_code_to_bpp()
517 * entries that set the register to their power-on default values,
1051 .dn_mode = SCALING,
1096 .dn_mode = SCALING,
1145 return &mode->csi2_timings; in ov5640_timings()
1147 return &mode->dvp_timings; in ov5640_timings()
1152 struct i2c_client *client = sensor->i2c_client; in ov5640_init_slave_id()
1157 if (client->addr == OV5640_DEFAULT_SLAVE_ID) in ov5640_init_slave_id()
1162 buf[2] = client->addr << 1; in ov5640_init_slave_id()
1169 ret = i2c_transfer(client->adapter, &msg, 1); in ov5640_init_slave_id()
1171 dev_err(&client->dev, "%s: failed with %d\n", __func__, ret); in ov5640_init_slave_id()
1180 struct i2c_client *client = sensor->i2c_client; in ov5640_write_reg()
1189 msg.addr = client->addr; in ov5640_write_reg()
1190 msg.flags = client->flags; in ov5640_write_reg()
1194 ret = i2c_transfer(client->adapter, &msg, 1); in ov5640_write_reg()
1196 dev_err(&client->dev, "%s: error: reg=%x, val=%x\n", in ov5640_write_reg()
1206 struct i2c_client *client = sensor->i2c_client; in ov5640_read_reg()
1214 msg[0].addr = client->addr; in ov5640_read_reg()
1215 msg[0].flags = client->flags; in ov5640_read_reg()
1219 msg[1].addr = client->addr; in ov5640_read_reg()
1220 msg[1].flags = client->flags | I2C_M_RD; in ov5640_read_reg()
1224 ret = i2c_transfer(client->adapter, msg, 2); in ov5640_read_reg()
1226 dev_err(&client->dev, "%s: error: reg=%x\n", in ov5640_read_reg()
1284 * +--------------+
1286 * +-+------------+
1287 * | +----------+
1288 * +->| PLL1 | - reg 0x3036, for the multiplier
1289 * +-+--------+ - reg 0x3037, bits 0-3 for the pre-divider
1290 * | +--------------+
1291 * +->| System Clock | - reg 0x3035, bits 4-7
1292 * +-+------------+
1293 * | +--------------+
1294 * +->| MIPI Divider | - reg 0x3035, bits 0-3
1295 * | +-+------------+
1296 * | +----------------> MIPI SCLK
1297 * | + +-----+
1298 * | +->| / 2 |-------> MIPI BIT CLK
1299 * | +-----+
1300 * | +--------------+
1301 * +->| PLL Root Div | - reg 0x3037, bit 4
1302 * +-+------------+
1303 * | +---------+
1304 * +->| Bit Div | - reg 0x3034, bits 0-3
1305 * +-+-------+
1306 * | +-------------+
1307 * +->| SCLK Div | - reg 0x3108, bits 0-1
1308 * | +-+-----------+
1309 * | +---------------> SCLK
1310 * | +-------------+
1311 * +->| SCLK 2X Div | - reg 0x3108, bits 2-3
1312 * | +-+-----------+
1313 * | +---------------> SCLK 2X
1314 * | +-------------+
1315 * +->| PCLK Div | - reg 0x3108, bits 4-5
1316 * ++------------+
1317 * + +-----------+
1318 * +->| P_DIV | - reg 0x3035, bits 0-3
1319 * +-----+-----+
1320 * +------------> PCLK
1323 * - the PLL pre-divider output rate should be in the 4-27MHz range
1324 * - the PLL multiplier output rate should be in the 500-1000MHz range
1325 * - PCLK >= SCLK * 2 in YUV, >= SCLK in Raw or JPEG
1352 * We only supports 8-bit formats at the moment
1380 unsigned long sysclk = sensor->xclk_freq / pll_prediv * pll_mult; in ov5640_compute_sys_clk()
1431 if (abs(rate - _rate) < abs(rate - best)) { in ov5640_calc_sys_clk()
1451 * ov5640_set_mipi_pclk() - Calculate the clock tree configuration values
1452 * for the MIPI CSI-2 output.
1466 link_freq = sensor->current_link_freq; in ov5640_set_mipi_pclk()
1469 * - mipi_div - Additional divider for the MIPI lane clock. in ov5640_set_mipi_pclk()
1483 * Adjust PLL parameters to maintain the MIPI_SCLK-to-PCLK ratio. in ov5640_set_mipi_pclk()
1485 * - root_div = 2 (fixed) in ov5640_set_mipi_pclk()
1486 * - bit_div : MIPI 8-bit = 2; MIPI 10-bit = 2.5 in ov5640_set_mipi_pclk()
1487 * - pclk_div = 1 (fixed) in ov5640_set_mipi_pclk()
1488 * - p_div = (2 lanes ? mipi_div : 2 * mipi_div) in ov5640_set_mipi_pclk()
1493 * - 2 lanes: MIPI_SCLK = (4 or 5) * PCLK in ov5640_set_mipi_pclk()
1494 * - 1 lanes: MIPI_SCLK = (8 or 10) * PCLK in ov5640_set_mipi_pclk()
1502 * - YUV: PCLK >= 2 * SCLK in ov5640_set_mipi_pclk()
1503 * - RAW or JPEG: PCLK >= SCLK in ov5640_set_mipi_pclk()
1504 * - sclk2x_div = sclk_div / 2 in ov5640_set_mipi_pclk()
1510 * Set the pixel clock period expressed in ns with 1-bit decimal in ov5640_set_mipi_pclk()
1515 * actual definition is 2 * 8-bit sample period. in ov5640_set_mipi_pclk()
1519 num_lanes = sensor->ep.bus.mipi_csi2.num_data_lanes; in ov5640_set_mipi_pclk()
1552 const struct ov5640_mode_info *mode = sensor->current_mode; in ov5640_calc_pixel_rate()
1553 const struct ov5640_timings *timings = &mode->dvp_timings; in ov5640_calc_pixel_rate()
1556 rate = timings->htot * (timings->crop.height + timings->vblank_def); in ov5640_calc_pixel_rate()
1557 rate *= ov5640_framerates[sensor->current_fr]; in ov5640_calc_pixel_rate()
1586 rate *= ov5640_code_to_bpp(sensor, sensor->fmt.code); in ov5640_set_dvp_pclk()
1587 rate /= sensor->ep.bus.parallel.bus_width; in ov5640_set_dvp_pclk()
1615 0x1f, prediv | ((pll_rdiv - 1) << 4)); in ov5640_set_dvp_pclk()
1640 ret = ov5640_write_reg16(sensor, OV5640_REG_VFIFO_HSIZE, mode->width); in ov5640_set_jpeg_timings()
1644 return ov5640_write_reg16(sensor, OV5640_REG_VFIFO_VSIZE, mode->height); in ov5640_set_jpeg_timings()
1656 if (sensor->fmt.code == MEDIA_BUS_FMT_JPEG_1X8) { in ov5640_set_timings()
1663 analog_crop = &timings->analog_crop; in ov5640_set_timings()
1664 crop = &timings->crop; in ov5640_set_timings()
1667 analog_crop->left); in ov5640_set_timings()
1672 analog_crop->top); in ov5640_set_timings()
1677 analog_crop->left + analog_crop->width - 1); in ov5640_set_timings()
1682 analog_crop->top + analog_crop->height - 1); in ov5640_set_timings()
1686 ret = ov5640_write_reg16(sensor, OV5640_REG_TIMING_HOFFS, crop->left); in ov5640_set_timings()
1690 ret = ov5640_write_reg16(sensor, OV5640_REG_TIMING_VOFFS, crop->top); in ov5640_set_timings()
1694 ret = ov5640_write_reg16(sensor, OV5640_REG_TIMING_DVPHO, mode->width); in ov5640_set_timings()
1698 ret = ov5640_write_reg16(sensor, OV5640_REG_TIMING_DVPVO, mode->height); in ov5640_set_timings()
1702 ret = ov5640_write_reg16(sensor, OV5640_REG_TIMING_HTS, timings->htot); in ov5640_set_timings()
1707 mode->height + timings->vblank_def); in ov5640_set_timings()
1724 delay_ms = regs->delay_ms; in ov5640_load_regs()
1725 reg_addr = regs->reg_addr; in ov5640_load_regs()
1726 val = regs->val; in ov5640_load_regs()
1727 mask = regs->mask; in ov5640_load_regs()
1730 if (regs->reg_addr == OV5640_REG_SYS_CTRL0 && in ov5640_load_regs()
1799 u16 gain; in ov5640_get_gain() local
1802 ret = ov5640_read_reg16(sensor, OV5640_REG_AEC_PK_REAL_GAIN, &gain); in ov5640_get_gain()
1806 return gain & 0x3ff; in ov5640_get_gain()
1809 static int ov5640_set_gain(struct ov5640_dev *sensor, int gain) in ov5640_set_gain() argument
1812 (u16)gain & 0x3ff); in ov5640_set_gain()
1861 u32 xvclk = sensor->xclk_freq / 10000; in ov5640_get_sysclk()
1900 return -EINVAL; in ov5640_get_sysclk()
2001 return -EINVAL; in ov5640_set_bandingfilter()
2002 sensor->prev_sysclk = ret; in ov5640_set_bandingfilter()
2008 return -EINVAL; in ov5640_set_bandingfilter()
2009 sensor->prev_hts = ret; in ov5640_set_bandingfilter()
2019 band_step60 = sensor->prev_sysclk * 100 / sensor->prev_hts * 100 / 120; in ov5640_set_bandingfilter()
2024 return -EINVAL; in ov5640_set_bandingfilter()
2025 max_band60 = (int)((prev_vts - 4) / band_step60); in ov5640_set_bandingfilter()
2031 band_step50 = sensor->prev_sysclk * 100 / sensor->prev_hts; in ov5640_set_bandingfilter()
2036 return -EINVAL; in ov5640_set_bandingfilter()
2037 max_band50 = (int)((prev_vts - 4) / band_step50); in ov5640_set_bandingfilter()
2047 sensor->ae_low = target * 23 / 25; /* 0.92 */ in ov5640_set_ae_target()
2048 sensor->ae_high = target * 27 / 25; /* 1.08 */ in ov5640_set_ae_target()
2050 fast_high = sensor->ae_high << 1; in ov5640_set_ae_target()
2054 fast_low = sensor->ae_low >> 1; in ov5640_set_ae_target()
2056 ret = ov5640_write_reg(sensor, OV5640_REG_AEC_CTRL0F, sensor->ae_high); in ov5640_set_ae_target()
2059 ret = ov5640_write_reg(sensor, OV5640_REG_AEC_CTRL10, sensor->ae_low); in ov5640_set_ae_target()
2062 ret = ov5640_write_reg(sensor, OV5640_REG_AEC_CTRL1B, sensor->ae_high); in ov5640_set_ae_target()
2065 ret = ov5640_write_reg(sensor, OV5640_REG_AEC_CTRL1E, sensor->ae_low); in ov5640_set_ae_target()
2092 * - [0]: Horizontal binning enable in ov5640_set_binning()
2100 * - [0]: Undocumented, but hardcoded init sequences in ov5640_set_binning()
2109 struct i2c_client *client = sensor->i2c_client; in ov5640_set_virtual_channel()
2114 dev_err(&client->dev, in ov5640_set_virtual_channel()
2115 "%s: wrong virtual_channel parameter, expected (0..3), got %d\n", in ov5640_set_virtual_channel()
2117 return -EINVAL; in ov5640_set_virtual_channel()
2139 (mode->width != width || mode->height != height))) in ov5640_find_mode()
2146 * sensor changes between scaling and subsampling, go through
2160 if (!mode->reg_data) in ov5640_set_mode_exposure_calc()
2161 return -EINVAL; in ov5640_set_mode_exposure_calc()
2171 if (ret && mode->id != OV5640_MODE_720P_1280_720 && in ov5640_set_mode_exposure_calc()
2172 mode->id != OV5640_MODE_1080P_1920_1080) in ov5640_set_mode_exposure_calc()
2175 /* read preview gain */ in ov5640_set_mode_exposure_calc()
2192 ov5640_load_regs(sensor, mode->reg_data, mode->reg_data_size); in ov5640_set_mode_exposure_calc()
2206 return -EINVAL; in ov5640_set_mode_exposure_calc()
2213 return -EINVAL; in ov5640_set_mode_exposure_calc()
2230 if (!sensor->prev_sysclk) { in ov5640_set_mode_exposure_calc()
2235 return -EINVAL; in ov5640_set_mode_exposure_calc()
2236 sensor->prev_sysclk = ret; in ov5640_set_mode_exposure_calc()
2240 return -EINVAL; in ov5640_set_mode_exposure_calc()
2242 cap_maxband = (int)((cap_vts - 4) / cap_bandfilt); in ov5640_set_mode_exposure_calc()
2245 if (average > sensor->ae_low && average < sensor->ae_high) { in ov5640_set_mode_exposure_calc()
2249 cap_sysclk / sensor->prev_sysclk * in ov5640_set_mode_exposure_calc()
2250 sensor->prev_hts / cap_hts * in ov5640_set_mode_exposure_calc()
2251 sensor->ae_target / average; in ov5640_set_mode_exposure_calc()
2255 cap_sysclk / sensor->prev_sysclk * in ov5640_set_mode_exposure_calc()
2256 sensor->prev_hts / cap_hts; in ov5640_set_mode_exposure_calc()
2259 /* gain to shutter */ in ov5640_set_mode_exposure_calc()
2274 return -EINVAL; in ov5640_set_mode_exposure_calc()
2278 /* 1/100 < (cap_shutter = n/100) =< max */ in ov5640_set_mode_exposure_calc()
2283 return -EINVAL; in ov5640_set_mode_exposure_calc()
2289 /* set capture gain */ in ov5640_set_mode_exposure_calc()
2295 if (cap_shutter > (cap_vts - 4)) { in ov5640_set_mode_exposure_calc()
2307 * if sensor changes inside scaling or subsampling
2313 if (!mode->reg_data) in ov5640_set_mode_direct()
2314 return -EINVAL; in ov5640_set_mode_direct()
2317 ov5640_load_regs(sensor, mode->reg_data, mode->reg_data_size); in ov5640_set_mode_direct()
2323 const struct ov5640_mode_info *mode = sensor->current_mode; in ov5640_set_mode()
2324 const struct ov5640_mode_info *orig_mode = sensor->last_mode; in ov5640_set_mode()
2326 bool auto_gain = sensor->ctrls.auto_gain->val == 1; in ov5640_set_mode()
2327 bool auto_exp = sensor->ctrls.auto_exp->val == V4L2_EXPOSURE_AUTO; in ov5640_set_mode()
2330 dn_mode = mode->dn_mode; in ov5640_set_mode()
2331 orig_dn_mode = orig_mode->dn_mode; in ov5640_set_mode()
2333 /* auto gain and exposure must be turned off when changing modes */ in ov5640_set_mode()
2353 if ((dn_mode == SUBSAMPLING && orig_dn_mode == SCALING) || in ov5640_set_mode()
2354 (dn_mode == SCALING && orig_dn_mode == SUBSAMPLING)) { in ov5640_set_mode()
2356 * change between subsampling and scaling in ov5640_set_mode()
2362 * change inside subsampling or scaling in ov5640_set_mode()
2370 /* restore auto gain and exposure */ in ov5640_set_mode()
2376 ret = ov5640_set_binning(sensor, dn_mode != SCALING); in ov5640_set_mode()
2379 ret = ov5640_set_ae_target(sensor, sensor->ae_target); in ov5640_set_mode()
2392 sensor->pending_mode_change = false; in ov5640_set_mode()
2393 sensor->last_mode = mode; in ov5640_set_mode()
2410 /* restore the last set video mode after chip power-on */
2430 return ov5640_set_framefmt(sensor, &sensor->fmt); in ov5640_restore_mode()
2435 gpiod_set_value_cansleep(sensor->pwdn_gpio, enable ? 0 : 1); in ov5640_power()
2454 if (sensor->pwdn_gpio) { in ov5640_powerup_sequence()
2455 gpiod_set_value_cansleep(sensor->reset_gpio, 1); in ov5640_powerup_sequence()
2463 gpiod_set_value_cansleep(sensor->reset_gpio, 0); in ov5640_powerup_sequence()
2481 struct i2c_client *client = sensor->i2c_client; in ov5640_set_power_on()
2484 ret = clk_prepare_enable(sensor->xclk); in ov5640_set_power_on()
2486 dev_err(&client->dev, "%s: failed to enable clock\n", in ov5640_set_power_on()
2492 sensor->supplies); in ov5640_set_power_on()
2494 dev_err(&client->dev, "%s: failed to enable regulators\n", in ov5640_set_power_on()
2509 regulator_bulk_disable(OV5640_NUM_SUPPLIES, sensor->supplies); in ov5640_set_power_on()
2511 clk_disable_unprepare(sensor->xclk); in ov5640_set_power_on()
2518 regulator_bulk_disable(OV5640_NUM_SUPPLIES, sensor->supplies); in ov5640_set_power_off()
2519 clk_disable_unprepare(sensor->xclk); in ov5640_set_power_off()
2579 unsigned int flags = sensor->ep.bus.parallel.flags; in ov5640_set_power_dvp()
2580 bool bt656 = sensor->ep.bus_type == V4L2_MBUS_BT656; in ov5640_set_power_dvp()
2607 * - VSYNC: active high in ov5640_set_power_dvp()
2608 * - HREF: active low in ov5640_set_power_dvp()
2609 * - PCLK: active low in ov5640_set_power_dvp()
2618 * - [7]: SYNC code selection (0: auto generate sync code, in ov5640_set_power_dvp()
2619 * 1: sync code from regs 0x4732-0x4735) in ov5640_set_power_dvp()
2620 * - [6]: f value in CCIR656 SYNC code when fixed f value in ov5640_set_power_dvp()
2621 * - [5]: Fixed f value in ov5640_set_power_dvp()
2622 * - [4:3]: Blank toggle data options (00: data=1'h040/1'h200, in ov5640_set_power_dvp()
2623 * 01: data from regs 0x4736-0x4738, 10: always keep 0) in ov5640_set_power_dvp()
2624 * - [1]: Clip data disable in ov5640_set_power_dvp()
2625 * - [0]: CCIR656 mode enable in ov5640_set_power_dvp()
2629 * - CCIR656 mode enable in ov5640_set_power_dvp()
2630 * - auto generation of sync codes in ov5640_set_power_dvp()
2631 * - blank toggle data 1'h040/1'h200 in ov5640_set_power_dvp()
2632 * - clip reserved data (0x00 & 0xff changed to 0x01 & 0xfe) in ov5640_set_power_dvp()
2643 * - [5]: PCLK polarity (0: active low, 1: active high) in ov5640_set_power_dvp()
2644 * - [1]: HREF polarity (0: active low, 1: active high) in ov5640_set_power_dvp()
2645 * - [0]: VSYNC polarity (mismatch here between in ov5640_set_power_dvp()
2679 * - 6: VSYNC output enable in ov5640_set_power_dvp()
2680 * - 5: HREF output enable in ov5640_set_power_dvp()
2681 * - 4: PCLK output enable in ov5640_set_power_dvp()
2682 * - [3:0]: D[9:6] output enable in ov5640_set_power_dvp()
2693 * - [7:2]: D[5:0] output enable in ov5640_set_power_dvp()
2712 if (sensor->ep.bus_type == V4L2_MBUS_CSI2_DPHY) in ov5640_set_power()
2745 /* --------------- Subdev Operations --------------- */
2757 maxfps = ov5640_framerates[mode->max_fps]; in ov5640_try_frame_interval()
2759 if (fi->numerator == 0) { in ov5640_try_frame_interval()
2760 fi->denominator = maxfps; in ov5640_try_frame_interval()
2761 fi->numerator = 1; in ov5640_try_frame_interval()
2762 rate = mode->max_fps; in ov5640_try_frame_interval()
2766 fps = clamp_val(DIV_ROUND_CLOSEST(fi->denominator, fi->numerator), in ov5640_try_frame_interval()
2773 if (abs(curr_fps - fps) < abs(best_fps - fps)) { in ov5640_try_frame_interval()
2779 fi->numerator = 1; in ov5640_try_frame_interval()
2780 fi->denominator = best_fps; in ov5640_try_frame_interval()
2783 mode = ov5640_find_mode(sensor, mode->width, mode->height, false); in ov5640_try_frame_interval()
2784 return mode ? rate : -EINVAL; in ov5640_try_frame_interval()
2794 if (format->pad != 0) in ov5640_get_fmt()
2795 return -EINVAL; in ov5640_get_fmt()
2797 mutex_lock(&sensor->lock); in ov5640_get_fmt()
2799 if (format->which == V4L2_SUBDEV_FORMAT_TRY) in ov5640_get_fmt()
2800 fmt = v4l2_subdev_state_get_format(sd_state, format->pad); in ov5640_get_fmt()
2802 fmt = &sensor->fmt; in ov5640_get_fmt()
2804 format->format = *fmt; in ov5640_get_fmt()
2806 mutex_unlock(&sensor->lock); in ov5640_get_fmt()
2820 mode = ov5640_find_mode(sensor, fmt->width, fmt->height, true); in ov5640_try_fmt_internal()
2822 return -EINVAL; in ov5640_try_fmt_internal()
2824 pixfmt = ov5640_code_to_pixfmt(sensor, fmt->code); in ov5640_try_fmt_internal()
2825 bpp = pixfmt->bpp; in ov5640_try_fmt_internal()
2829 * - 8bpp modes work for resolution >= 1280x720 in ov5640_try_fmt_internal()
2830 * - 24bpp modes work resolution < 1280x720 in ov5640_try_fmt_internal()
2832 if (bpp == 8 && mode->width < 1280) in ov5640_try_fmt_internal()
2834 else if (bpp == 24 && mode->width > 1024) in ov5640_try_fmt_internal()
2837 fmt->width = mode->width; in ov5640_try_fmt_internal()
2838 fmt->height = mode->height; in ov5640_try_fmt_internal()
2843 fmt->code = pixfmt->code; in ov5640_try_fmt_internal()
2844 fmt->colorspace = pixfmt->colorspace; in ov5640_try_fmt_internal()
2845 fmt->ycbcr_enc = V4L2_MAP_YCBCR_ENC_DEFAULT(fmt->colorspace); in ov5640_try_fmt_internal()
2846 fmt->quantization = V4L2_QUANTIZATION_FULL_RANGE; in ov5640_try_fmt_internal()
2847 fmt->xfer_func = V4L2_MAP_XFER_FUNC_DEFAULT(fmt->colorspace); in ov5640_try_fmt_internal()
2854 const struct ov5640_mode_info *mode = sensor->current_mode; in __v4l2_ctrl_vblank_update()
2856 __v4l2_ctrl_modify_range(sensor->ctrls.vblank, OV5640_MIN_VBLANK, in __v4l2_ctrl_vblank_update()
2857 OV5640_MAX_VTS - mode->height, 1, vblank); in __v4l2_ctrl_vblank_update()
2859 __v4l2_ctrl_s_ctrl(sensor->ctrls.vblank, vblank); in __v4l2_ctrl_vblank_update()
2864 const struct ov5640_mode_info *mode = sensor->current_mode; in ov5640_update_pixel_rate()
2865 enum ov5640_pixel_rate_id pixel_rate_id = mode->pixel_rate; in ov5640_update_pixel_rate()
2866 struct v4l2_mbus_framefmt *fmt = &sensor->fmt; in ov5640_update_pixel_rate()
2883 __v4l2_ctrl_s_ctrl_int64(sensor->ctrls.pixel_rate, in ov5640_update_pixel_rate()
2886 __v4l2_ctrl_vblank_update(sensor, timings->vblank_def); in ov5640_update_pixel_rate()
2892 * The MIPI CSI-2 link frequency should comply with the CSI-2 in ov5640_update_pixel_rate()
2898 num_lanes = sensor->ep.bus.mipi_csi2.num_data_lanes; in ov5640_update_pixel_rate()
2899 bpp = ov5640_code_to_bpp(sensor, fmt->code); in ov5640_update_pixel_rate()
2906 sensor->current_link_freq = link_freq; in ov5640_update_pixel_rate()
2927 __v4l2_ctrl_s_ctrl_int64(sensor->ctrls.pixel_rate, pixel_rate); in ov5640_update_pixel_rate()
2928 __v4l2_ctrl_s_ctrl(sensor->ctrls.link_freq, i); in ov5640_update_pixel_rate()
2930 hblank = timings->htot - mode->width; in ov5640_update_pixel_rate()
2931 __v4l2_ctrl_modify_range(sensor->ctrls.hblank, in ov5640_update_pixel_rate()
2934 vblank = timings->vblank_def; in ov5640_update_pixel_rate()
2937 exposure_max = timings->crop.height + vblank - 4; in ov5640_update_pixel_rate()
2938 exposure_val = clamp_t(s32, sensor->ctrls.exposure->val, in ov5640_update_pixel_rate()
2939 sensor->ctrls.exposure->minimum, in ov5640_update_pixel_rate()
2942 __v4l2_ctrl_modify_range(sensor->ctrls.exposure, in ov5640_update_pixel_rate()
2943 sensor->ctrls.exposure->minimum, in ov5640_update_pixel_rate()
2955 struct v4l2_mbus_framefmt *mbus_fmt = &format->format; in ov5640_set_fmt()
2958 if (format->pad != 0) in ov5640_set_fmt()
2959 return -EINVAL; in ov5640_set_fmt()
2961 mutex_lock(&sensor->lock); in ov5640_set_fmt()
2963 if (sensor->streaming) { in ov5640_set_fmt()
2964 ret = -EBUSY; in ov5640_set_fmt()
2972 if (format->which == V4L2_SUBDEV_FORMAT_TRY) { in ov5640_set_fmt()
2977 if (new_mode != sensor->current_mode) { in ov5640_set_fmt()
2978 sensor->current_fr = new_mode->def_fps; in ov5640_set_fmt()
2979 sensor->current_mode = new_mode; in ov5640_set_fmt()
2980 sensor->pending_mode_change = true; in ov5640_set_fmt()
2982 if (mbus_fmt->code != sensor->fmt.code) in ov5640_set_fmt()
2983 sensor->pending_fmt_change = true; in ov5640_set_fmt()
2986 sensor->fmt = *mbus_fmt; in ov5640_set_fmt()
2991 mutex_unlock(&sensor->lock); in ov5640_set_fmt()
3000 const struct ov5640_mode_info *mode = sensor->current_mode; in ov5640_get_selection()
3003 switch (sel->target) { in ov5640_get_selection()
3005 mutex_lock(&sensor->lock); in ov5640_get_selection()
3007 sel->r = timings->analog_crop; in ov5640_get_selection()
3008 mutex_unlock(&sensor->lock); in ov5640_get_selection()
3015 sel->r.top = 0; in ov5640_get_selection()
3016 sel->r.left = 0; in ov5640_get_selection()
3017 sel->r.width = OV5640_NATIVE_WIDTH; in ov5640_get_selection()
3018 sel->r.height = OV5640_NATIVE_HEIGHT; in ov5640_get_selection()
3023 sel->r.top = OV5640_PIXEL_ARRAY_TOP; in ov5640_get_selection()
3024 sel->r.left = OV5640_PIXEL_ARRAY_LEFT; in ov5640_get_selection()
3025 sel->r.width = OV5640_PIXEL_ARRAY_WIDTH; in ov5640_get_selection()
3026 sel->r.height = OV5640_PIXEL_ARRAY_HEIGHT; in ov5640_get_selection()
3031 return -EINVAL; in ov5640_get_selection()
3037 bool is_jpeg = format->code == MEDIA_BUS_FMT_JPEG_1X8; in ov5640_set_framefmt()
3041 pixfmt = ov5640_code_to_pixfmt(sensor, format->code); in ov5640_set_framefmt()
3045 pixfmt->ctrl00); in ov5640_set_framefmt()
3051 pixfmt->mux); in ov5640_set_framefmt()
3057 * - [5]: JPEG enable in ov5640_set_framefmt()
3066 * - [4]: Reset JFIFO in ov5640_set_framefmt()
3067 * - [3]: Reset SFIFO in ov5640_set_framefmt()
3068 * - [2]: Reset JPEG in ov5640_set_framefmt()
3078 * - [5]: Enable JPEG 2x clock in ov5640_set_framefmt()
3079 * - [3]: Enable JPEG clock in ov5640_set_framefmt()
3157 u16 red = (u16)sensor->ctrls.red_balance->val; in ov5640_set_ctrl_white_balance()
3158 u16 blue = (u16)sensor->ctrls.blue_balance->val; in ov5640_set_ctrl_white_balance()
3172 struct ov5640_ctrls *ctrls = &sensor->ctrls; in ov5640_set_ctrl_exposure()
3176 if (ctrls->auto_exp->is_new) { in ov5640_set_ctrl_exposure()
3182 if (!auto_exp && ctrls->exposure->is_new) { in ov5640_set_ctrl_exposure()
3195 if (ctrls->exposure->val < max_exp) in ov5640_set_ctrl_exposure()
3196 ret = ov5640_set_exposure(sensor, ctrls->exposure->val); in ov5640_set_ctrl_exposure()
3204 struct ov5640_ctrls *ctrls = &sensor->ctrls; in ov5640_set_ctrl_gain()
3207 if (ctrls->auto_gain->is_new) { in ov5640_set_ctrl_gain()
3213 if (!auto_gain && ctrls->gain->is_new) in ov5640_set_ctrl_gain()
3214 ret = ov5640_set_gain(sensor, ctrls->gain->val); in ov5640_set_ctrl_gain()
3284 * - [2]: ISP mirror in ov5640_set_ctrl_hflip()
3285 * - [1]: Sensor mirror in ov5640_set_ctrl_hflip()
3289 (!(value ^ sensor->upside_down)) ? in ov5640_set_ctrl_hflip()
3299 * - [2]: ISP vflip in ov5640_set_ctrl_vflip()
3300 * - [1]: Sensor vflip in ov5640_set_ctrl_vflip()
3304 (value ^ sensor->upside_down) ? in ov5640_set_ctrl_vflip()
3310 const struct ov5640_mode_info *mode = sensor->current_mode; in ov5640_set_ctrl_vblank()
3314 mode->height + value); in ov5640_set_ctrl_vblank()
3325 if (!pm_runtime_get_if_in_use(&sensor->i2c_client->dev)) in ov5640_g_volatile_ctrl()
3328 switch (ctrl->id) { in ov5640_g_volatile_ctrl()
3333 sensor->ctrls.gain->val = val; in ov5640_g_volatile_ctrl()
3339 sensor->ctrls.exposure->val = val; in ov5640_g_volatile_ctrl()
3343 pm_runtime_mark_last_busy(&sensor->i2c_client->dev); in ov5640_g_volatile_ctrl()
3344 pm_runtime_put_autosuspend(&sensor->i2c_client->dev); in ov5640_g_volatile_ctrl()
3353 const struct ov5640_mode_info *mode = sensor->current_mode; in ov5640_s_ctrl()
3360 switch (ctrl->id) { in ov5640_s_ctrl()
3364 exp_max = mode->height + ctrl->val - 4; in ov5640_s_ctrl()
3365 __v4l2_ctrl_modify_range(sensor->ctrls.exposure, in ov5640_s_ctrl()
3366 sensor->ctrls.exposure->minimum, in ov5640_s_ctrl()
3367 exp_max, sensor->ctrls.exposure->step, in ov5640_s_ctrl()
3368 timings->vblank_def); in ov5640_s_ctrl()
3377 if (!pm_runtime_get_if_in_use(&sensor->i2c_client->dev)) in ov5640_s_ctrl()
3380 switch (ctrl->id) { in ov5640_s_ctrl()
3382 ret = ov5640_set_ctrl_gain(sensor, ctrl->val); in ov5640_s_ctrl()
3385 ret = ov5640_set_ctrl_exposure(sensor, ctrl->val); in ov5640_s_ctrl()
3388 ret = ov5640_set_ctrl_white_balance(sensor, ctrl->val); in ov5640_s_ctrl()
3391 ret = ov5640_set_ctrl_hue(sensor, ctrl->val); in ov5640_s_ctrl()
3394 ret = ov5640_set_ctrl_contrast(sensor, ctrl->val); in ov5640_s_ctrl()
3397 ret = ov5640_set_ctrl_saturation(sensor, ctrl->val); in ov5640_s_ctrl()
3400 ret = ov5640_set_ctrl_test_pattern(sensor, ctrl->val); in ov5640_s_ctrl()
3403 ret = ov5640_set_ctrl_light_freq(sensor, ctrl->val); in ov5640_s_ctrl()
3406 ret = ov5640_set_ctrl_hflip(sensor, ctrl->val); in ov5640_s_ctrl()
3409 ret = ov5640_set_ctrl_vflip(sensor, ctrl->val); in ov5640_s_ctrl()
3412 ret = ov5640_set_ctrl_vblank(sensor, ctrl->val); in ov5640_s_ctrl()
3415 ret = -EINVAL; in ov5640_s_ctrl()
3419 pm_runtime_mark_last_busy(&sensor->i2c_client->dev); in ov5640_s_ctrl()
3420 pm_runtime_put_autosuspend(&sensor->i2c_client->dev); in ov5640_s_ctrl()
3432 const struct ov5640_mode_info *mode = sensor->current_mode; in ov5640_init_controls()
3434 struct ov5640_ctrls *ctrls = &sensor->ctrls; in ov5640_init_controls()
3435 struct v4l2_ctrl_handler *hdl = &ctrls->handler; in ov5640_init_controls()
3445 hdl->lock = &sensor->lock; in ov5640_init_controls()
3448 ctrls->pixel_rate = v4l2_ctrl_new_std(hdl, ops, V4L2_CID_PIXEL_RATE, in ov5640_init_controls()
3449 ov5640_pixel_rates[OV5640_NUM_PIXEL_RATES - 1], in ov5640_init_controls()
3451 ov5640_pixel_rates[mode->pixel_rate]); in ov5640_init_controls()
3453 ctrls->link_freq = v4l2_ctrl_new_int_menu(hdl, ops, in ov5640_init_controls()
3455 ARRAY_SIZE(ov5640_csi2_link_freqs) - 1, in ov5640_init_controls()
3460 hblank = timings->htot - mode->width; in ov5640_init_controls()
3461 ctrls->hblank = v4l2_ctrl_new_std(hdl, ops, V4L2_CID_HBLANK, hblank, in ov5640_init_controls()
3464 max_vblank = OV5640_MAX_VTS - mode->height; in ov5640_init_controls()
3465 ctrls->vblank = v4l2_ctrl_new_std(hdl, ops, V4L2_CID_VBLANK, in ov5640_init_controls()
3467 1, timings->vblank_def); in ov5640_init_controls()
3470 ctrls->auto_wb = v4l2_ctrl_new_std(hdl, ops, in ov5640_init_controls()
3473 ctrls->blue_balance = v4l2_ctrl_new_std(hdl, ops, V4L2_CID_BLUE_BALANCE, in ov5640_init_controls()
3475 ctrls->red_balance = v4l2_ctrl_new_std(hdl, ops, V4L2_CID_RED_BALANCE, in ov5640_init_controls()
3478 ctrls->auto_exp = v4l2_ctrl_new_std_menu(hdl, ops, in ov5640_init_controls()
3482 ctrls->exposure = v4l2_ctrl_new_std(hdl, ops, V4L2_CID_EXPOSURE, in ov5640_init_controls()
3484 /* Auto/manual gain */ in ov5640_init_controls()
3485 ctrls->auto_gain = v4l2_ctrl_new_std(hdl, ops, V4L2_CID_AUTOGAIN, in ov5640_init_controls()
3487 ctrls->gain = v4l2_ctrl_new_std(hdl, ops, V4L2_CID_ANALOGUE_GAIN, in ov5640_init_controls()
3490 ctrls->saturation = v4l2_ctrl_new_std(hdl, ops, V4L2_CID_SATURATION, in ov5640_init_controls()
3492 ctrls->hue = v4l2_ctrl_new_std(hdl, ops, V4L2_CID_HUE, in ov5640_init_controls()
3494 ctrls->contrast = v4l2_ctrl_new_std(hdl, ops, V4L2_CID_CONTRAST, in ov5640_init_controls()
3496 ctrls->test_pattern = in ov5640_init_controls()
3498 ARRAY_SIZE(test_pattern_menu) - 1, in ov5640_init_controls()
3500 ctrls->hflip = v4l2_ctrl_new_std(hdl, ops, V4L2_CID_HFLIP, in ov5640_init_controls()
3502 ctrls->vflip = v4l2_ctrl_new_std(hdl, ops, V4L2_CID_VFLIP, in ov5640_init_controls()
3505 ctrls->light_freq = in ov5640_init_controls()
3511 if (hdl->error) { in ov5640_init_controls()
3512 ret = hdl->error; in ov5640_init_controls()
3516 ret = v4l2_fwnode_device_parse(&sensor->i2c_client->dev, &props); in ov5640_init_controls()
3521 sensor->upside_down = true; in ov5640_init_controls()
3527 ctrls->pixel_rate->flags |= V4L2_CTRL_FLAG_READ_ONLY; in ov5640_init_controls()
3528 ctrls->link_freq->flags |= V4L2_CTRL_FLAG_READ_ONLY; in ov5640_init_controls()
3529 ctrls->hblank->flags |= V4L2_CTRL_FLAG_READ_ONLY; in ov5640_init_controls()
3530 ctrls->gain->flags |= V4L2_CTRL_FLAG_VOLATILE; in ov5640_init_controls()
3531 ctrls->exposure->flags |= V4L2_CTRL_FLAG_VOLATILE; in ov5640_init_controls()
3533 v4l2_ctrl_auto_cluster(3, &ctrls->auto_wb, 0, false); in ov5640_init_controls()
3534 v4l2_ctrl_auto_cluster(2, &ctrls->auto_gain, 0, true); in ov5640_init_controls()
3535 v4l2_ctrl_auto_cluster(2, &ctrls->auto_exp, 1, true); in ov5640_init_controls()
3537 sensor->sd.ctrl_handler = hdl; in ov5640_init_controls()
3550 u32 bpp = ov5640_code_to_bpp(sensor, fse->code); in ov5640_enum_frame_size()
3551 unsigned int index = fse->index; in ov5640_enum_frame_size()
3553 if (fse->pad != 0) in ov5640_enum_frame_size()
3554 return -EINVAL; in ov5640_enum_frame_size()
3556 return -EINVAL; in ov5640_enum_frame_size()
3558 /* Only low-resolution modes are supported for 24bpp formats. */ in ov5640_enum_frame_size()
3560 return -EINVAL; in ov5640_enum_frame_size()
3567 return -EINVAL; in ov5640_enum_frame_size()
3569 fse->min_width = ov5640_mode_data[index].width; in ov5640_enum_frame_size()
3570 fse->max_width = fse->min_width; in ov5640_enum_frame_size()
3571 fse->min_height = ov5640_mode_data[index].height; in ov5640_enum_frame_size()
3572 fse->max_height = fse->min_height; in ov5640_enum_frame_size()
3587 if (fie->pad != 0) in ov5640_enum_frame_interval()
3588 return -EINVAL; in ov5640_enum_frame_interval()
3589 if (fie->index >= OV5640_NUM_FRAMERATES) in ov5640_enum_frame_interval()
3590 return -EINVAL; in ov5640_enum_frame_interval()
3592 mode = ov5640_find_mode(sensor, fie->width, fie->height, false); in ov5640_enum_frame_interval()
3594 return -EINVAL; in ov5640_enum_frame_interval()
3597 tpf.denominator = ov5640_framerates[fie->index]; in ov5640_enum_frame_interval()
3601 return -EINVAL; in ov5640_enum_frame_interval()
3603 fie->interval = tpf; in ov5640_enum_frame_interval()
3617 if (fi->which != V4L2_SUBDEV_FORMAT_ACTIVE) in ov5640_get_frame_interval()
3618 return -EINVAL; in ov5640_get_frame_interval()
3620 mutex_lock(&sensor->lock); in ov5640_get_frame_interval()
3621 fi->interval = sensor->frame_interval; in ov5640_get_frame_interval()
3622 mutex_unlock(&sensor->lock); in ov5640_get_frame_interval()
3639 if (fi->which != V4L2_SUBDEV_FORMAT_ACTIVE) in ov5640_set_frame_interval()
3640 return -EINVAL; in ov5640_set_frame_interval()
3642 if (fi->pad != 0) in ov5640_set_frame_interval()
3643 return -EINVAL; in ov5640_set_frame_interval()
3645 mutex_lock(&sensor->lock); in ov5640_set_frame_interval()
3647 if (sensor->streaming) { in ov5640_set_frame_interval()
3648 ret = -EBUSY; in ov5640_set_frame_interval()
3652 mode = sensor->current_mode; in ov5640_set_frame_interval()
3654 frame_rate = ov5640_try_frame_interval(sensor, &fi->interval, mode); in ov5640_set_frame_interval()
3657 fi->interval = sensor->frame_interval; in ov5640_set_frame_interval()
3661 mode = ov5640_find_mode(sensor, mode->width, mode->height, true); in ov5640_set_frame_interval()
3663 ret = -EINVAL; in ov5640_set_frame_interval()
3667 if (ov5640_framerates[frame_rate] > ov5640_framerates[mode->max_fps]) { in ov5640_set_frame_interval()
3668 ret = -EINVAL; in ov5640_set_frame_interval()
3672 if (mode != sensor->current_mode || in ov5640_set_frame_interval()
3673 frame_rate != sensor->current_fr) { in ov5640_set_frame_interval()
3674 sensor->current_fr = frame_rate; in ov5640_set_frame_interval()
3675 sensor->frame_interval = fi->interval; in ov5640_set_frame_interval()
3676 sensor->current_mode = mode; in ov5640_set_frame_interval()
3677 sensor->pending_mode_change = true; in ov5640_set_frame_interval()
3682 mutex_unlock(&sensor->lock); in ov5640_set_frame_interval()
3696 num_formats = ARRAY_SIZE(ov5640_csi2_formats) - 1; in ov5640_enum_mbus_code()
3699 num_formats = ARRAY_SIZE(ov5640_dvp_formats) - 1; in ov5640_enum_mbus_code()
3702 if (code->index >= num_formats) in ov5640_enum_mbus_code()
3703 return -EINVAL; in ov5640_enum_mbus_code()
3705 code->code = formats[code->index].code; in ov5640_enum_mbus_code()
3716 ret = pm_runtime_resume_and_get(&sensor->i2c_client->dev); in ov5640_s_stream()
3720 ret = v4l2_ctrl_handler_setup(&sensor->ctrls.handler); in ov5640_s_stream()
3722 pm_runtime_put(&sensor->i2c_client->dev); in ov5640_s_stream()
3727 mutex_lock(&sensor->lock); in ov5640_s_stream()
3729 if (sensor->streaming == !enable) { in ov5640_s_stream()
3730 if (enable && sensor->pending_mode_change) { in ov5640_s_stream()
3736 if (enable && sensor->pending_fmt_change) { in ov5640_s_stream()
3737 ret = ov5640_set_framefmt(sensor, &sensor->fmt); in ov5640_s_stream()
3740 sensor->pending_fmt_change = false; in ov5640_s_stream()
3749 sensor->streaming = enable; in ov5640_s_stream()
3753 mutex_unlock(&sensor->lock); in ov5640_s_stream()
3756 pm_runtime_mark_last_busy(&sensor->i2c_client->dev); in ov5640_s_stream()
3757 pm_runtime_put_autosuspend(&sensor->i2c_client->dev); in ov5640_s_stream()
3774 crop->left = OV5640_PIXEL_ARRAY_LEFT; in ov5640_init_state()
3775 crop->top = OV5640_PIXEL_ARRAY_TOP; in ov5640_init_state()
3776 crop->width = OV5640_PIXEL_ARRAY_WIDTH; in ov5640_init_state()
3777 crop->height = OV5640_PIXEL_ARRAY_HEIGHT; in ov5640_init_state()
3818 sensor->supplies[i].supply = ov5640_supply_name[i]; in ov5640_get_regulators()
3820 return devm_regulator_bulk_get(&sensor->i2c_client->dev, in ov5640_get_regulators()
3822 sensor->supplies); in ov5640_get_regulators()
3827 struct i2c_client *client = sensor->i2c_client; in ov5640_check_chip_id()
3833 dev_err(&client->dev, "%s: failed to read chip identifier\n", in ov5640_check_chip_id()
3839 dev_err(&client->dev, "%s: wrong chip identifier, expected 0x5640, got 0x%x\n", in ov5640_check_chip_id()
3841 return -ENXIO; in ov5640_check_chip_id()
3849 struct device *dev = &client->dev; in ov5640_probe()
3856 return -ENOMEM; in ov5640_probe()
3858 sensor->i2c_client = client; in ov5640_probe()
3862 * YUV422 UYVY VGA(30FPS in parallel mode, 60 in MIPI CSI-2 mode) in ov5640_probe()
3864 sensor->frame_interval.numerator = 1; in ov5640_probe()
3865 sensor->frame_interval.denominator = ov5640_framerates[OV5640_30_FPS]; in ov5640_probe()
3866 sensor->current_fr = OV5640_30_FPS; in ov5640_probe()
3867 sensor->current_mode = in ov5640_probe()
3869 sensor->last_mode = sensor->current_mode; in ov5640_probe()
3870 sensor->current_link_freq = in ov5640_probe()
3873 sensor->ae_target = 52; in ov5640_probe()
3875 endpoint = fwnode_graph_get_next_endpoint(dev_fwnode(&client->dev), in ov5640_probe()
3878 dev_err(dev, "endpoint node not found\n"); in ov5640_probe()
3879 return -EINVAL; in ov5640_probe()
3882 ret = v4l2_fwnode_endpoint_parse(endpoint, &sensor->ep); in ov5640_probe()
3885 dev_err(dev, "Could not parse endpoint\n"); in ov5640_probe()
3889 if (sensor->ep.bus_type != V4L2_MBUS_PARALLEL && in ov5640_probe()
3890 sensor->ep.bus_type != V4L2_MBUS_CSI2_DPHY && in ov5640_probe()
3891 sensor->ep.bus_type != V4L2_MBUS_BT656) { in ov5640_probe()
3892 dev_err(dev, "Unsupported bus type %d\n", sensor->ep.bus_type); in ov5640_probe()
3893 return -EINVAL; in ov5640_probe()
3896 sensor->fmt = ov5640_is_csi2(sensor) ? ov5640_csi2_default_fmt : in ov5640_probe()
3900 sensor->xclk = devm_clk_get(dev, "xclk"); in ov5640_probe()
3901 if (IS_ERR(sensor->xclk)) { in ov5640_probe()
3902 dev_err(dev, "failed to get xclk\n"); in ov5640_probe()
3903 return PTR_ERR(sensor->xclk); in ov5640_probe()
3906 sensor->xclk_freq = clk_get_rate(sensor->xclk); in ov5640_probe()
3907 if (sensor->xclk_freq < OV5640_XCLK_MIN || in ov5640_probe()
3908 sensor->xclk_freq > OV5640_XCLK_MAX) { in ov5640_probe()
3909 dev_err(dev, "xclk frequency out of range: %d Hz\n", in ov5640_probe()
3910 sensor->xclk_freq); in ov5640_probe()
3911 return -EINVAL; in ov5640_probe()
3915 sensor->pwdn_gpio = devm_gpiod_get_optional(dev, "powerdown", in ov5640_probe()
3917 if (IS_ERR(sensor->pwdn_gpio)) in ov5640_probe()
3918 return PTR_ERR(sensor->pwdn_gpio); in ov5640_probe()
3921 sensor->reset_gpio = devm_gpiod_get_optional(dev, "reset", in ov5640_probe()
3923 if (IS_ERR(sensor->reset_gpio)) in ov5640_probe()
3924 return PTR_ERR(sensor->reset_gpio); in ov5640_probe()
3926 v4l2_i2c_subdev_init(&sensor->sd, client, &ov5640_subdev_ops); in ov5640_probe()
3927 sensor->sd.internal_ops = &ov5640_internal_ops; in ov5640_probe()
3929 sensor->sd.flags |= V4L2_SUBDEV_FL_HAS_DEVNODE | in ov5640_probe()
3931 sensor->pad.flags = MEDIA_PAD_FL_SOURCE; in ov5640_probe()
3932 sensor->sd.entity.function = MEDIA_ENT_F_CAM_SENSOR; in ov5640_probe()
3933 ret = media_entity_pads_init(&sensor->sd.entity, 1, &sensor->pad); in ov5640_probe()
3941 mutex_init(&sensor->lock); in ov5640_probe()
3949 dev_err(dev, "failed to power on\n"); in ov5640_probe()
3961 ret = v4l2_async_register_subdev_sensor(&sensor->sd); in ov5640_probe()
3977 v4l2_ctrl_handler_free(&sensor->ctrls.handler); in ov5640_probe()
3979 media_entity_cleanup(&sensor->sd.entity); in ov5640_probe()
3980 mutex_destroy(&sensor->lock); in ov5640_probe()
3988 struct device *dev = &client->dev; in ov5640_remove()
3995 v4l2_async_unregister_subdev(&sensor->sd); in ov5640_remove()
3996 media_entity_cleanup(&sensor->sd.entity); in ov5640_remove()
3997 v4l2_ctrl_handler_free(&sensor->ctrls.handler); in ov5640_remove()
3998 mutex_destroy(&sensor->lock); in ov5640_remove()