Lines Matching +full:v +full:- +full:bit
1 // SPDX-License-Identifier: GPL-2.0-or-later
16 #include <media/v4l2-ctrls.h>
17 #include <media/v4l2-device.h>
18 #include <media/v4l2-fwnode.h>
19 #include <media/v4l2-image-sizes.h>
20 #include <media/v4l2-mediabus.h>
31 #define OV5648_SW_STANDBY_STREAM_ON BIT(0)
34 #define OV5648_SW_RESET_RESET BIT(0)
52 #define OV5648_PAD_PK_PD_DATO_EN BIT(7)
55 #define OV5648_PAD_PK_FREX_N BIT(1)
58 #define OV5648_A_PWC_PK_O0_BP_REGULATOR_N BIT(3)
64 #define OV5648_MIPI_SC_CTRL0_MIPI_LANES(v) (((v) << 5) & GENMASK(7, 5)) argument
65 #define OV5648_MIPI_SC_CTRL0_PHY_HS_TX_PD BIT(4)
66 #define OV5648_MIPI_SC_CTRL0_PHY_LP_RX_PD BIT(3)
67 #define OV5648_MIPI_SC_CTRL0_MIPI_EN BIT(2)
68 #define OV5648_MIPI_SC_CTRL0_MIPI_SUSP BIT(1)
69 #define OV5648_MIPI_SC_CTRL0_LANE_DIS_OP BIT(0)
76 #define OV5648_PLL_CTRL0_PLL_CHARGE_PUMP(v) (((v) << 4) & GENMASK(6, 4)) argument
77 #define OV5648_PLL_CTRL0_BITS(v) ((v) & GENMASK(3, 0)) argument
79 #define OV5648_PLL_CTRL1_SYS_DIV(v) (((v) << 4) & GENMASK(7, 4)) argument
80 #define OV5648_PLL_CTRL1_MIPI_DIV(v) ((v) & GENMASK(3, 0)) argument
82 #define OV5648_PLL_MUL(v) ((v) & GENMASK(7, 0)) argument
84 #define OV5648_PLL_DIV_ROOT_DIV(v) ((((v) - 1) << 4) & BIT(4)) argument
85 #define OV5648_PLL_DIV_PLL_PRE_DIV(v) ((v) & GENMASK(3, 0)) argument
91 #define OV5648_PLLS_MUL(v) ((v) & GENMASK(4, 0)) argument
93 #define OV5648_PLLS_CTRL_PLL_CHARGE_PUMP(v) (((v) << 4) & GENMASK(6, 4)) argument
94 #define OV5648_PLLS_CTRL_SYS_DIV(v) ((v) & GENMASK(3, 0)) argument
96 #define OV5648_PLLS_DIV_PLLS_PRE_DIV(v) (((v) << 4) & GENMASK(5, 4)) argument
97 #define OV5648_PLLS_DIV_PLLS_DIV_R(v) ((((v) - 1) << 2) & BIT(2)) argument
98 #define OV5648_PLLS_DIV_PLLS_SEL_DIV(v) ((v) & GENMASK(1, 0)) argument
101 #define OV5648_SRB_CTRL_SCLK_DIV(v) (((v) << 2) & GENMASK(3, 2)) argument
102 #define OV5648_SRB_CTRL_RESET_ARBITER_EN BIT(1)
103 #define OV5648_SRB_CTRL_SCLK_ARBITER_EN BIT(0)
120 #define OV5648_EXPOSURE_CTRL_HH(v) (((v) & GENMASK(19, 16)) >> 16) argument
121 #define OV5648_EXPOSURE_CTRL_HH_VALUE(v) (((v) << 16) & GENMASK(19, 16)) argument
123 #define OV5648_EXPOSURE_CTRL_H(v) (((v) & GENMASK(15, 8)) >> 8) argument
124 #define OV5648_EXPOSURE_CTRL_H_VALUE(v) (((v) << 8) & GENMASK(15, 8)) argument
126 #define OV5648_EXPOSURE_CTRL_L(v) ((v) & GENMASK(7, 0)) argument
127 #define OV5648_EXPOSURE_CTRL_L_VALUE(v) ((v) & GENMASK(7, 0)) argument
129 #define OV5648_MANUAL_CTRL_FRAME_DELAY(v) (((v) << 4) & GENMASK(5, 4)) argument
130 #define OV5648_MANUAL_CTRL_AGC_MANUAL_EN BIT(1)
131 #define OV5648_MANUAL_CTRL_AEC_MANUAL_EN BIT(0)
133 #define OV5648_GAIN_CTRL_H(v) (((v) & GENMASK(9, 8)) >> 8) argument
134 #define OV5648_GAIN_CTRL_H_VALUE(v) (((v) << 8) & GENMASK(9, 8)) argument
136 #define OV5648_GAIN_CTRL_L(v) ((v) & GENMASK(7, 0)) argument
137 #define OV5648_GAIN_CTRL_L_VALUE(v) ((v) & GENMASK(7, 0)) argument
143 #define OV5648_AEC_CTRL0_DEBUG BIT(6)
144 #define OV5648_AEC_CTRL0_DEBAND_EN BIT(5)
145 #define OV5648_AEC_CTRL0_DEBAND_LOW_LIMIT_EN BIT(4)
146 #define OV5648_AEC_CTRL0_START_SEL_EN BIT(3)
147 #define OV5648_AEC_CTRL0_NIGHT_MODE_EN BIT(2)
148 #define OV5648_AEC_CTRL0_FREEZE_EN BIT(0)
217 #define OV5648_CROP_START_X_H(v) (((v) & GENMASK(11, 8)) >> 8) argument
219 #define OV5648_CROP_START_X_L(v) ((v) & GENMASK(7, 0)) argument
221 #define OV5648_CROP_START_Y_H(v) (((v) & GENMASK(11, 8)) >> 8) argument
223 #define OV5648_CROP_START_Y_L(v) ((v) & GENMASK(7, 0)) argument
225 #define OV5648_CROP_END_X_H(v) (((v) & GENMASK(11, 8)) >> 8) argument
227 #define OV5648_CROP_END_X_L(v) ((v) & GENMASK(7, 0)) argument
229 #define OV5648_CROP_END_Y_H(v) (((v) & GENMASK(11, 8)) >> 8) argument
231 #define OV5648_CROP_END_Y_L(v) ((v) & GENMASK(7, 0)) argument
233 #define OV5648_OUTPUT_SIZE_X_H(v) (((v) & GENMASK(11, 8)) >> 8) argument
235 #define OV5648_OUTPUT_SIZE_X_L(v) ((v) & GENMASK(7, 0)) argument
237 #define OV5648_OUTPUT_SIZE_Y_H(v) (((v) & GENMASK(11, 8)) >> 8) argument
239 #define OV5648_OUTPUT_SIZE_Y_L(v) ((v) & GENMASK(7, 0)) argument
241 #define OV5648_HTS_H(v) (((v) & GENMASK(12, 8)) >> 8) argument
243 #define OV5648_HTS_L(v) ((v) & GENMASK(7, 0)) argument
245 #define OV5648_VTS_H(v) (((v) & GENMASK(15, 8)) >> 8) argument
247 #define OV5648_VTS_L(v) ((v) & GENMASK(7, 0)) argument
249 #define OV5648_OFFSET_X_H(v) (((v) & GENMASK(11, 8)) >> 8) argument
251 #define OV5648_OFFSET_X_L(v) ((v) & GENMASK(7, 0)) argument
253 #define OV5648_OFFSET_Y_H(v) (((v) & GENMASK(11, 8)) >> 8) argument
255 #define OV5648_OFFSET_Y_L(v) ((v) & GENMASK(7, 0)) argument
257 #define OV5648_SUB_INC_X_ODD(v) (((v) << 4) & GENMASK(7, 4)) argument
258 #define OV5648_SUB_INC_X_EVEN(v) ((v) & GENMASK(3, 0)) argument
260 #define OV5648_SUB_INC_Y_ODD(v) (((v) << 4) & GENMASK(7, 4)) argument
261 #define OV5648_SUB_INC_Y_EVEN(v) ((v) & GENMASK(3, 0)) argument
263 #define OV5648_HSYNCST_H(v) (((v) >> 8) & 0xf) argument
265 #define OV5648_HSYNCST_L(v) ((v) & GENMASK(7, 0)) argument
267 #define OV5648_HSYNCW_H(v) (((v) >> 8) & 0xf) argument
269 #define OV5648_HSYNCW_L(v) ((v) & GENMASK(7, 0)) argument
272 #define OV5648_TC20_DEBUG BIT(6)
273 #define OV5648_TC20_FLIP_VERT_ISP_EN BIT(2)
274 #define OV5648_TC20_FLIP_VERT_SENSOR_EN BIT(1)
275 #define OV5648_TC20_BINNING_VERT_EN BIT(0)
277 #define OV5648_TC21_FLIP_HORZ_ISP_EN BIT(2)
278 #define OV5648_TC21_FLIP_HORZ_SENSOR_EN BIT(1)
279 #define OV5648_TC21_BINNING_HORZ_EN BIT(0)
291 #define OV5648_FREX_MODE_SEL_FREX_SA1 BIT(4)
292 #define OV5648_FREX_MODE_SEL_FX1_FM_EN BIT(3)
293 #define OV5648_FREX_MODE_SEL_FREX_INV BIT(2)
318 #define OV5648_BLC_CTRL1_START_LINE(v) ((v) & GENMASK(5, 0)) argument
320 #define OV5648_BLC_CTRL2_AUTO_EN BIT(6)
321 #define OV5648_BLC_CTRL2_RESET_FRAME_NUM(v) ((v) & GENMASK(5, 0)) argument
324 #define OV5648_BLC_LINE_NUM(v) ((v) & GENMASK(7, 0)) argument
326 #define OV5648_BLC_CTRL5_UPDATE_EN BIT(1)
335 /* MIPI CSI-2 */
338 #define OV5648_MIPI_CTRL0_CLK_LANE_AUTOGATE BIT(5)
339 #define OV5648_MIPI_CTRL0_LANE_SYNC_EN BIT(4)
341 #define OV5648_MIPI_CTRL0_LANE_SELECT_LANE2 BIT(3)
343 #define OV5648_MIPI_CTRL0_IDLE_LP11 BIT(2)
393 #define OV5648_ISP_CTRL0_BLACK_CORRECT_EN BIT(2)
394 #define OV5648_ISP_CTRL0_WHITE_CORRECT_EN BIT(1)
396 #define OV5648_ISP_CTRL1_AWB_EN BIT(0)
398 #define OV5648_ISP_CTRL2_WIN_EN BIT(6)
399 #define OV5648_ISP_CTRL2_OTP_EN BIT(1)
400 #define OV5648_ISP_CTRL2_AWB_GAIN_EN BIT(0)
402 #define OV5648_ISP_CTRL3_BUF_EN BIT(3)
403 #define OV5648_ISP_CTRL3_BIN_MAN_SET BIT(2)
404 #define OV5648_ISP_CTRL3_BIN_AUTO_EN BIT(1)
434 #define OV5648_ISP_CTRL3D_PATTERN_EN BIT(7)
435 #define OV5648_ISP_CTRL3D_ROLLING_BAR_EN BIT(6)
436 #define OV5648_ISP_CTRL3D_TRANSPARENT_MODE BIT(5)
437 #define OV5648_ISP_CTRL3D_SQUARES_BW_MODE BIT(4)
445 #define OV5648_ISP_CTRL4B_POST_BIN_H_EN BIT(5)
446 #define OV5648_ISP_CTRL4B_POST_BIN_V_EN BIT(4)
465 #define OV5648_AWB_CTRL_FAST_AWB BIT(6)
466 #define OV5648_AWB_CTRL_GAIN_FREEZE_EN BIT(5)
467 #define OV5648_AWB_CTRL_SUM_FREEZE_EN BIT(4)
468 #define OV5648_AWB_CTRL_GAIN_MANUAL_EN BIT(3)
476 #define OV5648_GAIN_RED_MAN_H(v) (((v) & GENMASK(11, 8)) >> 8) argument
478 #define OV5648_GAIN_RED_MAN_L(v) ((v) & GENMASK(7, 0)) argument
480 #define OV5648_GAIN_GREEN_MAN_H(v) (((v) & GENMASK(11, 8)) >> 8) argument
482 #define OV5648_GAIN_GREEN_MAN_L(v) ((v) & GENMASK(7, 0)) argument
484 #define OV5648_GAIN_BLUE_MAN_H(v) (((v) & GENMASK(11, 8)) >> 8) argument
486 #define OV5648_GAIN_BLUE_MAN_L(v) ((v) & GENMASK(7, 0)) argument
499 (&container_of((c)->handler, struct ov5648_sensor, \
500 ctrls.handler)->subdev)
513 * +-< XVCLK
515 * +-+ pll_pre_div (0x3037 [3:0], special values: 5: 1.5, 7: 2.5)
517 * +-+ pll_mul (0x3036 [7:0])
519 * +-+ sys_div (0x3035 [7:4])
521 * +-+ mipi_div (0x3035 [3:0])
523 * | +-> MIPI_SCLK
525 * | +-+ mipi_phy_div (2)
527 * | +-> MIPI_CLK
529 * +-+ root_div (0x3037 [4])
531 * +-+ bit_div (0x3034 [3:0], 8 bits: 2, 10 bits: 2.5, other: 1)
533 * +-+ sclk_div (0x3106 [3:2])
535 * +-> SCLK
537 * +-+ mipi_div (0x3035, 1: PCLK = SCLK)
539 * +-> PCLK
554 * +-< XVCLK
556 * +-+ plls_pre_div (0x303d [5:4], special values: 0: 1, 1: 1.5)
558 * +-+ plls_div_r (0x303d [2])
560 * +-+ plls_mul (0x303b [4:0])
562 * +-+ sys_div (0x303c [3:0])
564 * +-+ sel_div (0x303d [1:0], special values: 0: 1, 3: 2.5)
566 * +-> ADCLK
578 * General formulas for (array-centered) mode calculation:
579 * - photo_array_width = 2624
580 * - crop_start_x = (photo_array_width - output_size_x) / 2
581 * - crop_end_x = crop_start_x + offset_x + output_size_x - 1
583 * - photo_array_height = 1956
584 * - crop_start_y = (photo_array_height - output_size_y) / 2
585 * - crop_end_y = crop_start_y + offset_y + output_size_y - 1
609 /* 8-bit frame interval followed by 10-bit frame interval. */
612 /* 8-bit config followed by 10-bit config. */
969 struct i2c_client *client = sensor->i2c_client; in ov5648_read()
974 dev_dbg(&client->dev, "i2c send error at address %#04x\n", in ov5648_read()
981 dev_dbg(&client->dev, "i2c recv error at address %#04x\n", in ov5648_read()
992 struct i2c_client *client = sensor->i2c_client; in ov5648_write()
997 dev_dbg(&client->dev, "i2c send error at address %#04x\n", in ov5648_write()
1076 dev_err(sensor->dev, in ov5648_chip_id_check()
1079 return -EINVAL; in ov5648_chip_id_check()
1116 &sensor->endpoint.bus.mipi_csi2; in ov5648_mipi_configure()
1117 unsigned int lanes_count = bus_mipi_csi2->num_data_lanes; in ov5648_mipi_configure()
1186 /* Enable buffering and auto-binning. */ in ov5648_isp_configure()
1202 /* Enable post-binning filters. */ in ov5648_isp_configure()
1209 /* Disable debanding and night mode. Debug bit seems necessary. */ in ov5648_isp_configure()
1226 xvclk_rate = clk_get_rate(sensor->xvclk); in ov5648_mode_pll1_rate()
1227 pll1_rate = xvclk_rate * config->pll_mul; in ov5648_mode_pll1_rate()
1229 switch (config->pll_pre_div) { in ov5648_mode_pll1_rate()
1239 pll1_rate /= config->pll_pre_div; in ov5648_mode_pll1_rate()
1258 config = mode->pll1_config[0]; in ov5648_mode_pll1_configure()
1262 config = mode->pll1_config[1]; in ov5648_mode_pll1_configure()
1266 return -EINVAL; in ov5648_mode_pll1_configure()
1274 OV5648_PLL_DIV_ROOT_DIV(config->root_div) | in ov5648_mode_pll1_configure()
1275 OV5648_PLL_DIV_PLL_PRE_DIV(config->pll_pre_div)); in ov5648_mode_pll1_configure()
1280 OV5648_PLL_MUL(config->pll_mul)); in ov5648_mode_pll1_configure()
1285 OV5648_PLL_CTRL1_SYS_DIV(config->sys_div) | in ov5648_mode_pll1_configure()
1286 OV5648_PLL_CTRL1_MIPI_DIV(config->mipi_div)); in ov5648_mode_pll1_configure()
1291 OV5648_SRB_CTRL_SCLK_DIV(config->sclk_div) | in ov5648_mode_pll1_configure()
1298 const struct ov5648_pll2_config *config = mode->pll2_config; in ov5648_mode_pll2_configure()
1302 OV5648_PLLS_DIV_PLLS_PRE_DIV(config->plls_pre_div) | in ov5648_mode_pll2_configure()
1303 OV5648_PLLS_DIV_PLLS_DIV_R(config->plls_div_r) | in ov5648_mode_pll2_configure()
1304 OV5648_PLLS_DIV_PLLS_SEL_DIV(config->sel_div)); in ov5648_mode_pll2_configure()
1309 OV5648_PLLS_MUL(config->plls_mul)); in ov5648_mode_pll2_configure()
1315 OV5648_PLLS_CTRL_SYS_DIV(config->sys_div)); in ov5648_mode_pll2_configure()
1326 OV5648_CROP_START_X_H(mode->crop_start_x)); in ov5648_mode_configure()
1331 OV5648_CROP_START_X_L(mode->crop_start_x)); in ov5648_mode_configure()
1338 OV5648_OFFSET_X_H(mode->offset_x)); in ov5648_mode_configure()
1343 OV5648_OFFSET_X_L(mode->offset_x)); in ov5648_mode_configure()
1350 OV5648_OUTPUT_SIZE_X_H(mode->output_size_x)); in ov5648_mode_configure()
1355 OV5648_OUTPUT_SIZE_X_L(mode->output_size_x)); in ov5648_mode_configure()
1362 OV5648_CROP_END_X_H(mode->crop_end_x)); in ov5648_mode_configure()
1367 OV5648_CROP_END_X_L(mode->crop_end_x)); in ov5648_mode_configure()
1373 ret = ov5648_write(sensor, OV5648_HTS_H_REG, OV5648_HTS_H(mode->hts)); in ov5648_mode_configure()
1377 ret = ov5648_write(sensor, OV5648_HTS_L_REG, OV5648_HTS_L(mode->hts)); in ov5648_mode_configure()
1384 OV5648_CROP_START_Y_H(mode->crop_start_y)); in ov5648_mode_configure()
1389 OV5648_CROP_START_Y_L(mode->crop_start_y)); in ov5648_mode_configure()
1396 OV5648_OFFSET_Y_H(mode->offset_y)); in ov5648_mode_configure()
1401 OV5648_OFFSET_Y_L(mode->offset_y)); in ov5648_mode_configure()
1408 OV5648_OUTPUT_SIZE_Y_H(mode->output_size_y)); in ov5648_mode_configure()
1413 OV5648_OUTPUT_SIZE_Y_L(mode->output_size_y)); in ov5648_mode_configure()
1420 OV5648_CROP_END_Y_H(mode->crop_end_y)); in ov5648_mode_configure()
1425 OV5648_CROP_END_Y_L(mode->crop_end_y)); in ov5648_mode_configure()
1431 ret = ov5648_write(sensor, OV5648_VTS_H_REG, OV5648_VTS_H(mode->vts)); in ov5648_mode_configure()
1435 ret = ov5648_write(sensor, OV5648_VTS_L_REG, OV5648_VTS_L(mode->vts)); in ov5648_mode_configure()
1442 * A debug bit is enabled by default and needs to be cleared for in ov5648_mode_configure()
1448 mode->binning_y ? OV5648_TC20_BINNING_VERT_EN : in ov5648_mode_configure()
1455 mode->binning_x ? OV5648_TC21_BINNING_HORZ_EN : in ov5648_mode_configure()
1461 OV5648_SUB_INC_X_ODD(mode->inc_x_odd) | in ov5648_mode_configure()
1462 OV5648_SUB_INC_X_EVEN(mode->inc_x_even)); in ov5648_mode_configure()
1467 OV5648_SUB_INC_Y_ODD(mode->inc_y_odd) | in ov5648_mode_configure()
1468 OV5648_SUB_INC_Y_EVEN(mode->inc_y_even)); in ov5648_mode_configure()
1484 if (mode->register_values) { in ov5648_mode_configure()
1485 ret = ov5648_write_sequence(sensor, mode->register_values, in ov5648_mode_configure()
1486 mode->register_values_count); in ov5648_mode_configure()
1503 config = mode->pll1_config[0]; in ov5648_mode_mipi_clk_rate()
1506 config = mode->pll1_config[1]; in ov5648_mode_mipi_clk_rate()
1514 return pll1_rate / config->sys_div / config->mipi_div / 2; in ov5648_mode_mipi_clk_rate()
1529 struct ov5648_ctrls *ctrls = &sensor->ctrls; in ov5648_exposure_configure()
1532 if (ctrls->exposure_auto->val != V4L2_EXPOSURE_MANUAL) in ov5648_exposure_configure()
1533 return -EINVAL; in ov5648_exposure_configure()
1585 struct ov5648_ctrls *ctrls = &sensor->ctrls; in ov5648_gain_configure()
1588 if (ctrls->gain_auto->val) in ov5648_gain_configure()
1589 return -EINVAL; in ov5648_gain_configure()
1631 struct ov5648_ctrls *ctrls = &sensor->ctrls; in ov5648_white_balance_configure()
1634 if (ctrls->white_balance_auto->val) in ov5648_white_balance_configure()
1635 return -EINVAL; in ov5648_white_balance_configure()
1682 return -EINVAL; in ov5648_test_pattern_configure()
1694 struct ov5648_ctrls *ctrls = &sensor->ctrls; in ov5648_state_mipi_configure()
1696 &sensor->endpoint.bus.mipi_csi2; in ov5648_state_mipi_configure()
1705 return -EINVAL; in ov5648_state_mipi_configure()
1714 for (j = 0; j < sensor->endpoint.nr_of_link_frequencies; j++) { in ov5648_state_mipi_configure()
1715 u64 freq = sensor->endpoint.link_frequencies[j]; in ov5648_state_mipi_configure()
1722 dev_err(sensor->dev, in ov5648_state_mipi_configure()
1725 } else if (j == sensor->endpoint.nr_of_link_frequencies) { in ov5648_state_mipi_configure()
1726 dev_err(sensor->dev, in ov5648_state_mipi_configure()
1727 "failed to find %lu clk rate in endpoint link-frequencies\n", in ov5648_state_mipi_configure()
1730 __v4l2_ctrl_s_ctrl(ctrls->link_freq, i); in ov5648_state_mipi_configure()
1741 return -EINVAL; in ov5648_state_mipi_configure()
1744 lanes_count = bus_mipi_csi2->num_data_lanes; in ov5648_state_mipi_configure()
1747 __v4l2_ctrl_s_ctrl_int64(ctrls->pixel_rate, mipi_pixel_rate); in ov5648_state_mipi_configure()
1758 if (sensor->state.streaming) in ov5648_state_configure()
1759 return -EBUSY; in ov5648_state_configure()
1762 if (pm_runtime_enabled(sensor->dev) && in ov5648_state_configure()
1763 !pm_runtime_suspended(sensor->dev)) { in ov5648_state_configure()
1773 sensor->state.mode = mode; in ov5648_state_configure()
1774 sensor->state.mbus_code = mbus_code; in ov5648_state_configure()
1783 mutex_lock(&sensor->mutex); in ov5648_state_init()
1786 mutex_unlock(&sensor->mutex); in ov5648_state_init()
1799 dev_err(sensor->dev, "failed to perform sw reset\n"); in ov5648_sensor_init()
1805 dev_err(sensor->dev, "failed to set sensor standby\n"); in ov5648_sensor_init()
1811 dev_err(sensor->dev, "failed to check sensor chip id\n"); in ov5648_sensor_init()
1815 ret = ov5648_avdd_internal_power(sensor, !sensor->avdd); in ov5648_sensor_init()
1817 dev_err(sensor->dev, "failed to set internal avdd power\n"); in ov5648_sensor_init()
1824 dev_err(sensor->dev, "failed to write init sequence\n"); in ov5648_sensor_init()
1830 dev_err(sensor->dev, "failed to configure pad\n"); in ov5648_sensor_init()
1836 dev_err(sensor->dev, "failed to configure MIPI\n"); in ov5648_sensor_init()
1842 dev_err(sensor->dev, "failed to configure ISP\n"); in ov5648_sensor_init()
1848 dev_err(sensor->dev, "failed to configure black level\n"); in ov5648_sensor_init()
1853 ret = ov5648_state_configure(sensor, sensor->state.mode, in ov5648_sensor_init()
1854 sensor->state.mbus_code); in ov5648_sensor_init()
1856 dev_err(sensor->dev, "failed to configure state\n"); in ov5648_sensor_init()
1870 * - power-down GPIO must be active (low) during power-on; in ov5648_sensor_power()
1871 * - reset GPIO state does not matter during power-on; in ov5648_sensor_power()
1872 * - XVCLK must be provided 1 ms before register access; in ov5648_sensor_power()
1873 * - 10 ms are needed between power-down deassert and register access. in ov5648_sensor_power()
1876 /* Note that regulator-and-GPIO-based power is untested. */ in ov5648_sensor_power()
1878 gpiod_set_value_cansleep(sensor->reset, 1); in ov5648_sensor_power()
1879 gpiod_set_value_cansleep(sensor->powerdown, 1); in ov5648_sensor_power()
1881 ret = regulator_enable(sensor->dovdd); in ov5648_sensor_power()
1883 dev_err(sensor->dev, in ov5648_sensor_power()
1888 if (sensor->avdd) { in ov5648_sensor_power()
1889 ret = regulator_enable(sensor->avdd); in ov5648_sensor_power()
1891 dev_err(sensor->dev, in ov5648_sensor_power()
1897 ret = regulator_enable(sensor->dvdd); in ov5648_sensor_power()
1899 dev_err(sensor->dev, in ov5648_sensor_power()
1907 ret = clk_prepare_enable(sensor->xvclk); in ov5648_sensor_power()
1909 dev_err(sensor->dev, "failed to enable XVCLK clock\n"); in ov5648_sensor_power()
1913 gpiod_set_value_cansleep(sensor->reset, 0); in ov5648_sensor_power()
1914 gpiod_set_value_cansleep(sensor->powerdown, 0); in ov5648_sensor_power()
1919 gpiod_set_value_cansleep(sensor->powerdown, 1); in ov5648_sensor_power()
1920 gpiod_set_value_cansleep(sensor->reset, 1); in ov5648_sensor_power()
1922 clk_disable_unprepare(sensor->xvclk); in ov5648_sensor_power()
1924 regulator_disable(sensor->dvdd); in ov5648_sensor_power()
1926 if (sensor->avdd) in ov5648_sensor_power()
1927 regulator_disable(sensor->avdd); in ov5648_sensor_power()
1929 regulator_disable(sensor->dovdd); in ov5648_sensor_power()
1941 struct ov5648_ctrls *ctrls = &sensor->ctrls; in ov5648_g_volatile_ctrl()
1944 switch (ctrl->id) { in ov5648_g_volatile_ctrl()
1946 ret = ov5648_exposure_value(sensor, &ctrls->exposure->val); in ov5648_g_volatile_ctrl()
1951 ret = ov5648_gain_value(sensor, &ctrls->gain->val); in ov5648_g_volatile_ctrl()
1956 return -EINVAL; in ov5648_g_volatile_ctrl()
1966 struct ov5648_ctrls *ctrls = &sensor->ctrls; in ov5648_s_ctrl()
1972 if (pm_runtime_suspended(sensor->dev)) in ov5648_s_ctrl()
1975 switch (ctrl->id) { in ov5648_s_ctrl()
1977 enable = ctrl->val == V4L2_EXPOSURE_AUTO; in ov5648_s_ctrl()
1983 if (!enable && ctrls->exposure->is_new) { in ov5648_s_ctrl()
1985 ctrls->exposure->val); in ov5648_s_ctrl()
1991 enable = !!ctrl->val; in ov5648_s_ctrl()
1998 ret = ov5648_gain_configure(sensor, ctrls->gain->val); in ov5648_s_ctrl()
2004 enable = !!ctrl->val; in ov5648_s_ctrl()
2012 ctrls->red_balance->val, in ov5648_s_ctrl()
2013 ctrls->blue_balance->val); in ov5648_s_ctrl()
2019 enable = !!ctrl->val; in ov5648_s_ctrl()
2022 enable = !!ctrl->val; in ov5648_s_ctrl()
2025 index = (unsigned int)ctrl->val; in ov5648_s_ctrl()
2028 return -EINVAL; in ov5648_s_ctrl()
2041 struct ov5648_ctrls *ctrls = &sensor->ctrls; in ov5648_ctrls_init()
2042 struct v4l2_ctrl_handler *handler = &ctrls->handler; in ov5648_ctrls_init()
2049 handler->lock = &sensor->mutex; in ov5648_ctrls_init()
2053 ctrls->exposure_auto = v4l2_ctrl_new_std_menu(handler, ops, in ov5648_ctrls_init()
2058 ctrls->exposure = v4l2_ctrl_new_std(handler, ops, V4L2_CID_EXPOSURE, in ov5648_ctrls_init()
2061 v4l2_ctrl_auto_cluster(2, &ctrls->exposure_auto, 1, true); in ov5648_ctrls_init()
2065 ctrls->gain_auto = in ov5648_ctrls_init()
2068 ctrls->gain = v4l2_ctrl_new_std(handler, ops, V4L2_CID_GAIN, 16, 1023, in ov5648_ctrls_init()
2071 v4l2_ctrl_auto_cluster(2, &ctrls->gain_auto, 0, true); in ov5648_ctrls_init()
2075 ctrls->white_balance_auto = in ov5648_ctrls_init()
2079 ctrls->red_balance = v4l2_ctrl_new_std(handler, ops, in ov5648_ctrls_init()
2083 ctrls->blue_balance = v4l2_ctrl_new_std(handler, ops, in ov5648_ctrls_init()
2087 v4l2_ctrl_auto_cluster(3, &ctrls->white_balance_auto, 0, false); in ov5648_ctrls_init()
2097 ARRAY_SIZE(ov5648_test_pattern_menu) - 1, in ov5648_ctrls_init()
2100 /* MIPI CSI-2 */ in ov5648_ctrls_init()
2102 ctrls->link_freq = in ov5648_ctrls_init()
2104 ARRAY_SIZE(ov5648_link_freq_menu) - 1, in ov5648_ctrls_init()
2107 ctrls->pixel_rate = in ov5648_ctrls_init()
2111 if (handler->error) { in ov5648_ctrls_init()
2112 ret = handler->error; in ov5648_ctrls_init()
2116 ctrls->exposure->flags |= V4L2_CTRL_FLAG_VOLATILE; in ov5648_ctrls_init()
2117 ctrls->gain->flags |= V4L2_CTRL_FLAG_VOLATILE; in ov5648_ctrls_init()
2119 ctrls->link_freq->flags |= V4L2_CTRL_FLAG_READ_ONLY; in ov5648_ctrls_init()
2120 ctrls->pixel_rate->flags |= V4L2_CTRL_FLAG_READ_ONLY; in ov5648_ctrls_init()
2122 sensor->subdev.ctrl_handler = handler; in ov5648_ctrls_init()
2137 struct ov5648_state *state = &sensor->state; in ov5648_s_stream()
2141 ret = pm_runtime_resume_and_get(sensor->dev); in ov5648_s_stream()
2146 mutex_lock(&sensor->mutex); in ov5648_s_stream()
2148 mutex_unlock(&sensor->mutex); in ov5648_s_stream()
2153 state->streaming = !!enable; in ov5648_s_stream()
2156 pm_runtime_put(sensor->dev); in ov5648_s_stream()
2168 mutex_lock(&sensor->mutex); in ov5648_g_frame_interval()
2170 mode = sensor->state.mode; in ov5648_g_frame_interval()
2172 switch (sensor->state.mbus_code) { in ov5648_g_frame_interval()
2174 interval->interval = mode->frame_interval[0]; in ov5648_g_frame_interval()
2177 interval->interval = mode->frame_interval[1]; in ov5648_g_frame_interval()
2180 ret = -EINVAL; in ov5648_g_frame_interval()
2183 mutex_unlock(&sensor->mutex); in ov5648_g_frame_interval()
2200 if (code_enum->index >= ARRAY_SIZE(ov5648_mbus_codes)) in ov5648_enum_mbus_code()
2201 return -EINVAL; in ov5648_enum_mbus_code()
2203 code_enum->code = ov5648_mbus_codes[code_enum->index]; in ov5648_enum_mbus_code()
2212 mbus_format->width = mode->output_size_x; in ov5648_mbus_format_fill()
2213 mbus_format->height = mode->output_size_y; in ov5648_mbus_format_fill()
2214 mbus_format->code = mbus_code; in ov5648_mbus_format_fill()
2216 mbus_format->field = V4L2_FIELD_NONE; in ov5648_mbus_format_fill()
2217 mbus_format->colorspace = V4L2_COLORSPACE_RAW; in ov5648_mbus_format_fill()
2218 mbus_format->ycbcr_enc = in ov5648_mbus_format_fill()
2219 V4L2_MAP_YCBCR_ENC_DEFAULT(mbus_format->colorspace); in ov5648_mbus_format_fill()
2220 mbus_format->quantization = V4L2_QUANTIZATION_FULL_RANGE; in ov5648_mbus_format_fill()
2221 mbus_format->xfer_func = in ov5648_mbus_format_fill()
2222 V4L2_MAP_XFER_FUNC_DEFAULT(mbus_format->colorspace); in ov5648_mbus_format_fill()
2230 struct v4l2_mbus_framefmt *mbus_format = &format->format; in ov5648_get_fmt()
2232 mutex_lock(&sensor->mutex); in ov5648_get_fmt()
2234 if (format->which == V4L2_SUBDEV_FORMAT_TRY) in ov5648_get_fmt()
2236 format->pad); in ov5648_get_fmt()
2238 ov5648_mbus_format_fill(mbus_format, sensor->state.mbus_code, in ov5648_get_fmt()
2239 sensor->state.mode); in ov5648_get_fmt()
2241 mutex_unlock(&sensor->mutex); in ov5648_get_fmt()
2251 struct v4l2_mbus_framefmt *mbus_format = &format->format; in ov5648_set_fmt()
2257 mutex_lock(&sensor->mutex); in ov5648_set_fmt()
2259 if (sensor->state.streaming) { in ov5648_set_fmt()
2260 ret = -EBUSY; in ov5648_set_fmt()
2266 if (ov5648_mbus_codes[index] == mbus_format->code) { in ov5648_set_fmt()
2267 mbus_code = mbus_format->code; in ov5648_set_fmt()
2279 mbus_format->width, mbus_format->height); in ov5648_set_fmt()
2281 ret = -EINVAL; in ov5648_set_fmt()
2287 if (format->which == V4L2_SUBDEV_FORMAT_TRY) in ov5648_set_fmt()
2288 *v4l2_subdev_get_try_format(subdev, sd_state, format->pad) = in ov5648_set_fmt()
2290 else if (sensor->state.mode != mode || in ov5648_set_fmt()
2291 sensor->state.mbus_code != mbus_code) in ov5648_set_fmt()
2295 mutex_unlock(&sensor->mutex); in ov5648_set_fmt()
2306 if (size_enum->index >= ARRAY_SIZE(ov5648_modes)) in ov5648_enum_frame_size()
2307 return -EINVAL; in ov5648_enum_frame_size()
2309 mode = &ov5648_modes[size_enum->index]; in ov5648_enum_frame_size()
2311 size_enum->min_width = size_enum->max_width = mode->output_size_x; in ov5648_enum_frame_size()
2312 size_enum->min_height = size_enum->max_height = mode->output_size_y; in ov5648_enum_frame_size()
2325 if (interval_enum->index > 0) in ov5648_enum_frame_interval()
2326 return -EINVAL; in ov5648_enum_frame_interval()
2336 if (mode->output_size_x == interval_enum->width && in ov5648_enum_frame_interval()
2337 mode->output_size_y == interval_enum->height) { in ov5648_enum_frame_interval()
2338 if (interval_index == interval_enum->index) in ov5648_enum_frame_interval()
2346 return -EINVAL; in ov5648_enum_frame_interval()
2348 switch (interval_enum->code) { in ov5648_enum_frame_interval()
2350 interval_enum->interval = mode->frame_interval[0]; in ov5648_enum_frame_interval()
2353 interval_enum->interval = mode->frame_interval[1]; in ov5648_enum_frame_interval()
2356 return -EINVAL; in ov5648_enum_frame_interval()
2380 struct ov5648_state *state = &sensor->state; in ov5648_suspend()
2383 mutex_lock(&sensor->mutex); in ov5648_suspend()
2385 if (state->streaming) { in ov5648_suspend()
2396 mutex_unlock(&sensor->mutex); in ov5648_suspend()
2406 struct ov5648_state *state = &sensor->state; in ov5648_resume()
2409 mutex_lock(&sensor->mutex); in ov5648_resume()
2419 ret = __v4l2_ctrl_handler_setup(&sensor->ctrls.handler); in ov5648_resume()
2423 if (state->streaming) { in ov5648_resume()
2435 mutex_unlock(&sensor->mutex); in ov5648_resume()
2442 struct device *dev = &client->dev; in ov5648_probe()
2452 return -ENOMEM; in ov5648_probe()
2454 sensor->dev = dev; in ov5648_probe()
2455 sensor->i2c_client = client; in ov5648_probe()
2462 return -EINVAL; in ov5648_probe()
2465 sensor->endpoint.bus_type = V4L2_MBUS_CSI2_DPHY; in ov5648_probe()
2467 ret = v4l2_fwnode_endpoint_alloc_parse(handle, &sensor->endpoint); in ov5648_probe()
2476 sensor->powerdown = devm_gpiod_get_optional(dev, "powerdown", in ov5648_probe()
2478 if (IS_ERR(sensor->powerdown)) { in ov5648_probe()
2479 ret = PTR_ERR(sensor->powerdown); in ov5648_probe()
2483 sensor->reset = devm_gpiod_get_optional(dev, "reset", GPIOD_OUT_HIGH); in ov5648_probe()
2484 if (IS_ERR(sensor->reset)) { in ov5648_probe()
2485 ret = PTR_ERR(sensor->reset); in ov5648_probe()
2492 sensor->dvdd = devm_regulator_get(dev, "dvdd"); in ov5648_probe()
2493 if (IS_ERR(sensor->dvdd)) { in ov5648_probe()
2495 ret = PTR_ERR(sensor->dvdd); in ov5648_probe()
2500 sensor->dovdd = devm_regulator_get(dev, "dovdd"); in ov5648_probe()
2501 if (IS_ERR(sensor->dovdd)) { in ov5648_probe()
2503 ret = PTR_ERR(sensor->dovdd); in ov5648_probe()
2508 sensor->avdd = devm_regulator_get_optional(dev, "avdd"); in ov5648_probe()
2509 if (IS_ERR(sensor->avdd)) { in ov5648_probe()
2511 sensor->avdd = NULL; in ov5648_probe()
2516 sensor->xvclk = devm_clk_get(dev, NULL); in ov5648_probe()
2517 if (IS_ERR(sensor->xvclk)) { in ov5648_probe()
2519 ret = PTR_ERR(sensor->xvclk); in ov5648_probe()
2523 rate = clk_get_rate(sensor->xvclk); in ov5648_probe()
2526 ret = -EINVAL; in ov5648_probe()
2532 subdev = &sensor->subdev; in ov5648_probe()
2535 subdev->flags |= V4L2_SUBDEV_FL_HAS_DEVNODE; in ov5648_probe()
2536 subdev->entity.function = MEDIA_ENT_F_CAM_SENSOR; in ov5648_probe()
2538 pad = &sensor->pad; in ov5648_probe()
2539 pad->flags = MEDIA_PAD_FL_SOURCE; in ov5648_probe()
2541 ret = media_entity_pads_init(&subdev->entity, 1, pad); in ov5648_probe()
2547 mutex_init(&sensor->mutex); in ov5648_probe()
2561 pm_runtime_enable(sensor->dev); in ov5648_probe()
2562 pm_runtime_set_suspended(sensor->dev); in ov5648_probe()
2573 pm_runtime_disable(sensor->dev); in ov5648_probe()
2576 v4l2_ctrl_handler_free(&sensor->ctrls.handler); in ov5648_probe()
2579 mutex_destroy(&sensor->mutex); in ov5648_probe()
2582 media_entity_cleanup(&sensor->subdev.entity); in ov5648_probe()
2585 v4l2_fwnode_endpoint_free(&sensor->endpoint); in ov5648_probe()
2596 pm_runtime_disable(sensor->dev); in ov5648_remove()
2597 v4l2_ctrl_handler_free(&sensor->ctrls.handler); in ov5648_remove()
2598 mutex_destroy(&sensor->mutex); in ov5648_remove()
2599 media_entity_cleanup(&subdev->entity); in ov5648_remove()