Lines Matching full:imx274

3  * imx274.c - IMX274 CMOS Image Sensor driver
96 #define DRIVER_NAME "IMX274"
99 * IMX274 register definitions
144 * imx274 I2C operation related structure
158 * Parameters for each imx274 readout mode.
185 * imx274 test pattern related structure
221 * imx274 mode1(refer to datasheet) register configuration with
262 * imx274 mode3(refer to datasheet) register configuration with
302 * imx274 mode5(refer to datasheet) register configuration with
342 * imx274 mode6(refer to datasheet) register configuration with
381 * imx274 first step register configuration for
438 * imx274 second step register configuration for
448 * imx274 third step register configuration for
458 * imx274 register configuration for stopping stream
466 * imx274 disable test pattern register configuration
477 * imx274 test pattern register configuration
534 * struct imx274_ctrls - imx274 ctrl structure
550 * struct stim274 - imx274 device structure
554 * @ctrls: imx274 control structure
799 * imx274 datasheet, it should wait 10ms or more here. in imx274_start_stream()
809 * imx274 datasheet, it should wait 7ms or more here. in imx274_start_stream()
842 struct stimx274 *imx274 = to_imx274(sd); in imx274_power_on() local
846 imx274_reset(imx274, 0); in imx274_power_on()
848 ret = clk_prepare_enable(imx274->inck); in imx274_power_on()
850 dev_err(&imx274->client->dev, in imx274_power_on()
855 ret = regulator_bulk_enable(IMX274_NUM_SUPPLIES, imx274->supplies); in imx274_power_on()
857 dev_err(&imx274->client->dev, in imx274_power_on()
863 imx274_reset(imx274, 1); in imx274_power_on()
868 clk_disable_unprepare(imx274->inck); in imx274_power_on()
876 struct stimx274 *imx274 = to_imx274(sd); in imx274_power_off() local
878 imx274_reset(imx274, 0); in imx274_power_off()
880 regulator_bulk_disable(IMX274_NUM_SUPPLIES, imx274->supplies); in imx274_power_off()
882 clk_disable_unprepare(imx274->inck); in imx274_power_off()
887 static int imx274_regulators_get(struct device *dev, struct stimx274 *imx274) in imx274_regulators_get() argument
892 imx274->supplies[i].supply = imx274_supply_names[i]; in imx274_regulators_get()
895 imx274->supplies); in imx274_regulators_get()
899 * imx274_s_ctrl - This is used to set the imx274 V4L2 controls
902 * This function is used to set the V4L2 controls for the imx274 sensor.
909 struct stimx274 *imx274 = to_imx274(sd); in imx274_s_ctrl() local
912 if (!pm_runtime_get_if_in_use(&imx274->client->dev)) in imx274_s_ctrl()
915 dev_dbg(&imx274->client->dev, in imx274_s_ctrl()
921 dev_dbg(&imx274->client->dev, in imx274_s_ctrl()
923 ret = imx274_set_exposure(imx274, ctrl->val); in imx274_s_ctrl()
927 dev_dbg(&imx274->client->dev, in imx274_s_ctrl()
929 ret = imx274_set_gain(imx274, ctrl); in imx274_s_ctrl()
933 dev_dbg(&imx274->client->dev, in imx274_s_ctrl()
935 ret = imx274_set_vflip(imx274, ctrl->val); in imx274_s_ctrl()
939 dev_dbg(&imx274->client->dev, in imx274_s_ctrl()
941 ret = imx274_set_test_pattern(imx274, ctrl->val); in imx274_s_ctrl()
945 pm_runtime_put(&imx274->client->dev); in imx274_s_ctrl()
950 static int imx274_binning_goodness(struct stimx274 *imx274, in imx274_binning_goodness() argument
954 struct device *dev = &imx274->client->dev; in imx274_binning_goodness()
995 * Must be called with imx274->lock locked.
997 * @imx274: The device object
1006 static int __imx274_change_compose(struct stimx274 *imx274, in __imx274_change_compose() argument
1013 struct device *dev = &imx274->client->dev; in __imx274_change_compose()
1024 cur_crop = &imx274->crop; in __imx274_change_compose()
1025 tgt_fmt = &imx274->format; in __imx274_change_compose()
1033 imx274, in __imx274_change_compose()
1048 imx274->mode = best_mode; in __imx274_change_compose()
1074 struct stimx274 *imx274 = to_imx274(sd); in imx274_get_fmt() local
1076 mutex_lock(&imx274->lock); in imx274_get_fmt()
1077 fmt->format = imx274->format; in imx274_get_fmt()
1078 mutex_unlock(&imx274->lock); in imx274_get_fmt()
1097 struct stimx274 *imx274 = to_imx274(sd); in imx274_set_fmt() local
1100 mutex_lock(&imx274->lock); in imx274_set_fmt()
1102 err = __imx274_change_compose(imx274, sd_state, format->which, in imx274_set_fmt()
1117 imx274->format = *fmt; in imx274_set_fmt()
1120 mutex_unlock(&imx274->lock); in imx274_set_fmt()
1129 struct stimx274 *imx274 = to_imx274(sd); in imx274_get_selection() local
1149 src_crop = &imx274->crop; in imx274_get_selection()
1150 src_fmt = &imx274->format; in imx274_get_selection()
1153 mutex_lock(&imx274->lock); in imx274_get_selection()
1175 mutex_unlock(&imx274->lock); in imx274_get_selection()
1180 static int imx274_set_selection_crop(struct stimx274 *imx274, in imx274_set_selection_crop() argument
1220 tgt_crop = &imx274->crop; in imx274_set_selection_crop()
1222 mutex_lock(&imx274->lock); in imx274_set_selection_crop()
1232 __imx274_change_compose(imx274, sd_state, sel->which, in imx274_set_selection_crop()
1236 mutex_unlock(&imx274->lock); in imx274_set_selection_crop()
1245 struct stimx274 *imx274 = to_imx274(sd); in imx274_set_selection() local
1251 return imx274_set_selection_crop(imx274, sd_state, sel); in imx274_set_selection()
1256 mutex_lock(&imx274->lock); in imx274_set_selection()
1257 err = __imx274_change_compose(imx274, sd_state, sel->which, in imx274_set_selection()
1260 mutex_unlock(&imx274->lock); in imx274_set_selection()
1277 static int imx274_apply_trimming(struct stimx274 *imx274) in imx274_apply_trimming() argument
1288 h_start = imx274->crop.left + 12; in imx274_apply_trimming()
1289 h_end = h_start + imx274->crop.width; in imx274_apply_trimming()
1294 hmax = max_t(u32, 260, (imx274->crop.width) / 16 + 23); in imx274_apply_trimming()
1297 v_pos = imx274->ctrls.vflip->cur.val ? in imx274_apply_trimming()
1298 (-imx274->crop.top / 2) : (imx274->crop.top / 2); in imx274_apply_trimming()
1299 v_cut = (IMX274_MAX_HEIGHT - imx274->crop.height) / 2; in imx274_apply_trimming()
1300 write_v_size = imx274->crop.height + 22; in imx274_apply_trimming()
1301 y_out_size = imx274->crop.height; in imx274_apply_trimming()
1303 err = imx274_write_mbreg(imx274, IMX274_HMAX_REG_LSB, hmax, 2); in imx274_apply_trimming()
1305 err = imx274_write_mbreg(imx274, IMX274_HTRIM_EN_REG, 1, 1); in imx274_apply_trimming()
1307 err = imx274_write_mbreg(imx274, IMX274_HTRIM_START_REG_LSB, in imx274_apply_trimming()
1310 err = imx274_write_mbreg(imx274, IMX274_HTRIM_END_REG_LSB, in imx274_apply_trimming()
1313 err = imx274_write_mbreg(imx274, IMX274_VWIDCUTEN_REG, 1, 1); in imx274_apply_trimming()
1315 err = imx274_write_mbreg(imx274, IMX274_VWIDCUT_REG_LSB, in imx274_apply_trimming()
1318 err = imx274_write_mbreg(imx274, IMX274_VWINPOS_REG_LSB, in imx274_apply_trimming()
1321 err = imx274_write_mbreg(imx274, IMX274_WRITE_VSIZE_REG_LSB, in imx274_apply_trimming()
1324 err = imx274_write_mbreg(imx274, IMX274_Y_OUT_SIZE_REG_LSB, in imx274_apply_trimming()
1334 struct stimx274 *imx274 = to_imx274(sd); in imx274_get_frame_interval() local
1343 fi->interval = imx274->frame_interval; in imx274_get_frame_interval()
1344 dev_dbg(&imx274->client->dev, "%s frame rate = %d / %d\n", in imx274_get_frame_interval()
1345 __func__, imx274->frame_interval.numerator, in imx274_get_frame_interval()
1346 imx274->frame_interval.denominator); in imx274_get_frame_interval()
1355 struct stimx274 *imx274 = to_imx274(sd); in imx274_set_frame_interval() local
1356 struct v4l2_ctrl *ctrl = imx274->ctrls.exposure; in imx274_set_frame_interval()
1367 ret = pm_runtime_resume_and_get(&imx274->client->dev); in imx274_set_frame_interval()
1371 mutex_lock(&imx274->lock); in imx274_set_frame_interval()
1372 ret = __imx274_set_frame_interval(imx274, fi->interval); in imx274_set_frame_interval()
1375 fi->interval = imx274->frame_interval; in imx274_set_frame_interval()
1387 dev_err(&imx274->client->dev, in imx274_set_frame_interval()
1393 imx274_set_exposure(imx274, ctrl->val); in imx274_set_frame_interval()
1395 dev_dbg(&imx274->client->dev, "set frame interval to %uus\n", in imx274_set_frame_interval()
1401 mutex_unlock(&imx274->lock); in imx274_set_frame_interval()
1402 pm_runtime_put(&imx274->client->dev); in imx274_set_frame_interval()
1430 * imx274 sensor.
1436 struct stimx274 *imx274 = to_imx274(sd); in imx274_s_stream() local
1439 dev_dbg(&imx274->client->dev, "%s : %s, mode index = %td\n", __func__, in imx274_s_stream()
1441 imx274->mode - &imx274_modes[0]); in imx274_s_stream()
1443 mutex_lock(&imx274->lock); in imx274_s_stream()
1446 ret = pm_runtime_resume_and_get(&imx274->client->dev); in imx274_s_stream()
1448 mutex_unlock(&imx274->lock); in imx274_s_stream()
1453 ret = imx274_mode_regs(imx274); in imx274_s_stream()
1457 ret = imx274_apply_trimming(imx274); in imx274_s_stream()
1467 ret = __imx274_set_frame_interval(imx274, in imx274_s_stream()
1468 imx274->frame_interval); in imx274_s_stream()
1473 ret = imx274_start_stream(imx274); in imx274_s_stream()
1478 ret = imx274_write_table(imx274, imx274_stop); in imx274_s_stream()
1482 pm_runtime_put(&imx274->client->dev); in imx274_s_stream()
1485 mutex_unlock(&imx274->lock); in imx274_s_stream()
1486 dev_dbg(&imx274->client->dev, "%s : Done\n", __func__); in imx274_s_stream()
1490 pm_runtime_put(&imx274->client->dev); in imx274_s_stream()
1491 mutex_unlock(&imx274->lock); in imx274_s_stream()
1492 dev_err(&imx274->client->dev, "s_stream failed\n"); in imx274_s_stream()
1580 * The caller should hold the mutex lock imx274->lock if necessary
1622 /* convert to register value, refer to imx274 datasheet */ in imx274_set_gain()
1692 * The caller should hold the mutex lock imx274->lock if necessary
1748 * The caller should hold the mutex lock imx274->lock if necessary
1836 * The caller should hold the mutex lock imx274->lock if necessary
1946 { .compatible = "sony,imx274" },
1952 { "IMX274" },
1995 struct stimx274 *imx274; in imx274_probe() local
1999 /* initialize imx274 */ in imx274_probe()
2000 imx274 = devm_kzalloc(dev, sizeof(*imx274), GFP_KERNEL); in imx274_probe()
2001 if (!imx274) in imx274_probe()
2004 mutex_init(&imx274->lock); in imx274_probe()
2010 imx274->inck = devm_clk_get_optional(dev, "inck"); in imx274_probe()
2011 if (IS_ERR(imx274->inck)) in imx274_probe()
2012 return PTR_ERR(imx274->inck); in imx274_probe()
2014 ret = imx274_regulators_get(dev, imx274); in imx274_probe()
2021 imx274->mode = &imx274_modes[0]; in imx274_probe()
2022 imx274->crop.width = IMX274_MAX_WIDTH; in imx274_probe()
2023 imx274->crop.height = IMX274_MAX_HEIGHT; in imx274_probe()
2024 imx274->format.width = imx274->crop.width / imx274->mode->wbin_ratio; in imx274_probe()
2025 imx274->format.height = imx274->crop.height / imx274->mode->hbin_ratio; in imx274_probe()
2026 imx274->format.field = V4L2_FIELD_NONE; in imx274_probe()
2027 imx274->format.code = MEDIA_BUS_FMT_SRGGB10_1X10; in imx274_probe()
2028 imx274->format.colorspace = V4L2_COLORSPACE_SRGB; in imx274_probe()
2029 imx274->frame_interval.numerator = 1; in imx274_probe()
2030 imx274->frame_interval.denominator = IMX274_DEF_FRAME_RATE; in imx274_probe()
2033 imx274->regmap = devm_regmap_init_i2c(client, &imx274_regmap_config); in imx274_probe()
2034 if (IS_ERR(imx274->regmap)) { in imx274_probe()
2036 "regmap init failed: %ld\n", PTR_ERR(imx274->regmap)); in imx274_probe()
2042 imx274->client = client; in imx274_probe()
2043 sd = &imx274->sd; in imx274_probe()
2048 imx274->pad.flags = MEDIA_PAD_FL_SOURCE; in imx274_probe()
2050 ret = media_entity_pads_init(&sd->entity, 1, &imx274->pad); in imx274_probe()
2058 imx274->reset_gpio = devm_gpiod_get_optional(dev, "reset", in imx274_probe()
2060 if (IS_ERR(imx274->reset_gpio)) { in imx274_probe()
2061 ret = dev_err_probe(dev, PTR_ERR(imx274->reset_gpio), in imx274_probe()
2069 dev_err(dev, "%s : imx274 power on failed\n", __func__); in imx274_probe()
2074 ret = v4l2_ctrl_handler_init(&imx274->ctrls.handler, 4); in imx274_probe()
2080 imx274->ctrls.handler.lock = &imx274->lock; in imx274_probe()
2083 imx274->ctrls.test_pattern = v4l2_ctrl_new_std_menu_items( in imx274_probe()
2084 &imx274->ctrls.handler, &imx274_ctrl_ops, in imx274_probe()
2088 imx274->ctrls.gain = v4l2_ctrl_new_std( in imx274_probe()
2089 &imx274->ctrls.handler, in imx274_probe()
2095 imx274->ctrls.exposure = v4l2_ctrl_new_std( in imx274_probe()
2096 &imx274->ctrls.handler, in imx274_probe()
2102 imx274->ctrls.vflip = v4l2_ctrl_new_std( in imx274_probe()
2103 &imx274->ctrls.handler, in imx274_probe()
2107 imx274->sd.ctrl_handler = &imx274->ctrls.handler; in imx274_probe()
2108 if (imx274->ctrls.handler.error) { in imx274_probe()
2109 ret = imx274->ctrls.handler.error; in imx274_probe()
2114 imx274_load_default(imx274); in imx274_probe()
2128 dev_info(dev, "imx274 : imx274 probe success !\n"); in imx274_probe()
2132 v4l2_ctrl_handler_free(&imx274->ctrls.handler); in imx274_probe()
2138 mutex_destroy(&imx274->lock); in imx274_probe()
2145 struct stimx274 *imx274 = to_imx274(sd); in imx274_remove() local
2153 v4l2_ctrl_handler_free(&imx274->ctrls.handler); in imx274_remove()
2156 mutex_destroy(&imx274->lock); in imx274_remove()
2177 MODULE_DESCRIPTION("IMX274 CMOS Image Sensor driver");