Lines Matching full:imx274
3 * imx274.c - IMX274 CMOS Image Sensor driver
96 #define DRIVER_NAME "IMX274"
99 * IMX274 register definitions
135 * imx274 I2C operation related structure
155 * Parameters for each imx274 readout mode.
180 * imx274 test pattern related structure
216 * imx274 mode1(refer to datasheet) register configuration with
257 * imx274 mode3(refer to datasheet) register configuration with
297 * imx274 mode5(refer to datasheet) register configuration with
336 * imx274 first step register configuration for
393 * imx274 second step register configuration for
403 * imx274 third step register configuration for
413 * imx274 register configuration for stopping stream
421 * imx274 disable test pattern register configuration
432 * imx274 test pattern register configuration
476 * struct imx274_ctrls - imx274 ctrl structure
492 * struct stim274 - imx274 device structure
496 * @ctrls: imx274 control structure
731 * imx274 datasheet, it should wait 10ms or more here. in imx274_start_stream()
741 * imx274 datasheet, it should wait 7ms or more here. in imx274_start_stream()
771 * imx274_s_ctrl - This is used to set the imx274 V4L2 controls
774 * This function is used to set the V4L2 controls for the imx274 sensor.
781 struct stimx274 *imx274 = to_imx274(sd); in imx274_s_ctrl() local
784 dev_dbg(&imx274->client->dev, in imx274_s_ctrl()
790 dev_dbg(&imx274->client->dev, in imx274_s_ctrl()
792 ret = imx274_set_exposure(imx274, ctrl->val); in imx274_s_ctrl()
796 dev_dbg(&imx274->client->dev, in imx274_s_ctrl()
798 ret = imx274_set_gain(imx274, ctrl); in imx274_s_ctrl()
802 dev_dbg(&imx274->client->dev, in imx274_s_ctrl()
804 ret = imx274_set_vflip(imx274, ctrl->val); in imx274_s_ctrl()
808 dev_dbg(&imx274->client->dev, in imx274_s_ctrl()
810 ret = imx274_set_test_pattern(imx274, ctrl->val); in imx274_s_ctrl()
817 static int imx274_binning_goodness(struct stimx274 *imx274, in imx274_binning_goodness() argument
821 struct device *dev = &imx274->client->dev; in imx274_binning_goodness()
861 * Must be called with imx274->lock locked.
863 * @imx274: The device object
872 static int __imx274_change_compose(struct stimx274 *imx274, in __imx274_change_compose() argument
879 struct device *dev = &imx274->client->dev; in __imx274_change_compose()
890 cur_crop = &imx274->crop; in __imx274_change_compose()
891 tgt_fmt = &imx274->format; in __imx274_change_compose()
898 imx274, in __imx274_change_compose()
913 imx274->mode = best_mode; in __imx274_change_compose()
939 struct stimx274 *imx274 = to_imx274(sd); in imx274_get_fmt() local
941 mutex_lock(&imx274->lock); in imx274_get_fmt()
942 fmt->format = imx274->format; in imx274_get_fmt()
943 mutex_unlock(&imx274->lock); in imx274_get_fmt()
962 struct stimx274 *imx274 = to_imx274(sd); in imx274_set_fmt() local
965 mutex_lock(&imx274->lock); in imx274_set_fmt()
967 err = __imx274_change_compose(imx274, cfg, format->which, in imx274_set_fmt()
982 imx274->format = *fmt; in imx274_set_fmt()
985 mutex_unlock(&imx274->lock); in imx274_set_fmt()
994 struct stimx274 *imx274 = to_imx274(sd); in imx274_get_selection() local
1014 src_crop = &imx274->crop; in imx274_get_selection()
1015 src_fmt = &imx274->format; in imx274_get_selection()
1018 mutex_lock(&imx274->lock); in imx274_get_selection()
1040 mutex_unlock(&imx274->lock); in imx274_get_selection()
1045 static int imx274_set_selection_crop(struct stimx274 *imx274, in imx274_set_selection_crop() argument
1085 tgt_crop = &imx274->crop; in imx274_set_selection_crop()
1087 mutex_lock(&imx274->lock); in imx274_set_selection_crop()
1097 __imx274_change_compose(imx274, cfg, sel->which, in imx274_set_selection_crop()
1101 mutex_unlock(&imx274->lock); in imx274_set_selection_crop()
1110 struct stimx274 *imx274 = to_imx274(sd); in imx274_set_selection() local
1116 return imx274_set_selection_crop(imx274, cfg, sel); in imx274_set_selection()
1121 mutex_lock(&imx274->lock); in imx274_set_selection()
1122 err = __imx274_change_compose(imx274, cfg, sel->which, in imx274_set_selection()
1125 mutex_unlock(&imx274->lock); in imx274_set_selection()
1142 static int imx274_apply_trimming(struct stimx274 *imx274) in imx274_apply_trimming() argument
1153 h_start = imx274->crop.left + 12; in imx274_apply_trimming()
1154 h_end = h_start + imx274->crop.width; in imx274_apply_trimming()
1159 hmax = max_t(u32, 260, (imx274->crop.width) / 16 + 23); in imx274_apply_trimming()
1162 v_pos = imx274->ctrls.vflip->cur.val ? in imx274_apply_trimming()
1163 (-imx274->crop.top / 2) : (imx274->crop.top / 2); in imx274_apply_trimming()
1164 v_cut = (IMX274_MAX_HEIGHT - imx274->crop.height) / 2; in imx274_apply_trimming()
1165 write_v_size = imx274->crop.height + 22; in imx274_apply_trimming()
1166 y_out_size = imx274->crop.height + 14; in imx274_apply_trimming()
1168 err = imx274_write_mbreg(imx274, IMX274_HMAX_REG_LSB, hmax, 2); in imx274_apply_trimming()
1170 err = imx274_write_mbreg(imx274, IMX274_HTRIM_EN_REG, 1, 1); in imx274_apply_trimming()
1172 err = imx274_write_mbreg(imx274, IMX274_HTRIM_START_REG_LSB, in imx274_apply_trimming()
1175 err = imx274_write_mbreg(imx274, IMX274_HTRIM_END_REG_LSB, in imx274_apply_trimming()
1178 err = imx274_write_mbreg(imx274, IMX274_VWIDCUTEN_REG, 1, 1); in imx274_apply_trimming()
1180 err = imx274_write_mbreg(imx274, IMX274_VWIDCUT_REG_LSB, in imx274_apply_trimming()
1183 err = imx274_write_mbreg(imx274, IMX274_VWINPOS_REG_LSB, in imx274_apply_trimming()
1186 err = imx274_write_mbreg(imx274, IMX274_WRITE_VSIZE_REG_LSB, in imx274_apply_trimming()
1189 err = imx274_write_mbreg(imx274, IMX274_Y_OUT_SIZE_REG_LSB, in imx274_apply_trimming()
1207 struct stimx274 *imx274 = to_imx274(sd); in imx274_g_frame_interval() local
1209 fi->interval = imx274->frame_interval; in imx274_g_frame_interval()
1210 dev_dbg(&imx274->client->dev, "%s frame rate = %d / %d\n", in imx274_g_frame_interval()
1211 __func__, imx274->frame_interval.numerator, in imx274_g_frame_interval()
1212 imx274->frame_interval.denominator); in imx274_g_frame_interval()
1229 struct stimx274 *imx274 = to_imx274(sd); in imx274_s_frame_interval() local
1230 struct v4l2_ctrl *ctrl = imx274->ctrls.exposure; in imx274_s_frame_interval()
1234 mutex_lock(&imx274->lock); in imx274_s_frame_interval()
1235 ret = imx274_set_frame_interval(imx274, fi->interval); in imx274_s_frame_interval()
1238 fi->interval = imx274->frame_interval; in imx274_s_frame_interval()
1249 dev_err(&imx274->client->dev, in imx274_s_frame_interval()
1255 imx274_set_exposure(imx274, ctrl->val); in imx274_s_frame_interval()
1257 dev_dbg(&imx274->client->dev, "set frame interval to %uus\n", in imx274_s_frame_interval()
1263 mutex_unlock(&imx274->lock); in imx274_s_frame_interval()
1316 * imx274 sensor.
1322 struct stimx274 *imx274 = to_imx274(sd); in imx274_s_stream() local
1325 dev_dbg(&imx274->client->dev, "%s : %s, mode index = %td\n", __func__, in imx274_s_stream()
1327 imx274->mode - &imx274_modes[0]); in imx274_s_stream()
1329 mutex_lock(&imx274->lock); in imx274_s_stream()
1333 ret = imx274_mode_regs(imx274); in imx274_s_stream()
1337 ret = imx274_apply_trimming(imx274); in imx274_s_stream()
1347 ret = imx274_set_frame_interval(imx274, in imx274_s_stream()
1348 imx274->frame_interval); in imx274_s_stream()
1353 ret = __v4l2_ctrl_s_ctrl(imx274->ctrls.exposure, in imx274_s_stream()
1354 imx274->ctrls.exposure->val); in imx274_s_stream()
1359 ret = imx274_start_stream(imx274); in imx274_s_stream()
1364 ret = imx274_write_table(imx274, imx274_stop); in imx274_s_stream()
1369 mutex_unlock(&imx274->lock); in imx274_s_stream()
1370 dev_dbg(&imx274->client->dev, "%s : Done\n", __func__); in imx274_s_stream()
1374 mutex_unlock(&imx274->lock); in imx274_s_stream()
1375 dev_err(&imx274->client->dev, "s_stream failed\n"); in imx274_s_stream()
1463 * The caller should hold the mutex lock imx274->lock if necessary
1505 /* convert to register value, refer to imx274 datasheet */ in imx274_set_gain()
1575 * The caller should hold the mutex lock imx274->lock if necessary
1631 * The caller should hold the mutex lock imx274->lock if necessary
1719 * The caller should hold the mutex lock imx274->lock if necessary
1815 { .compatible = "sony,imx274" },
1821 { "IMX274", 0 },
1829 struct stimx274 *imx274; in imx274_probe() local
1832 /* initialize imx274 */ in imx274_probe()
1833 imx274 = devm_kzalloc(&client->dev, sizeof(*imx274), GFP_KERNEL); in imx274_probe()
1834 if (!imx274) in imx274_probe()
1837 mutex_init(&imx274->lock); in imx274_probe()
1840 imx274->mode = &imx274_modes[IMX274_DEFAULT_BINNING]; in imx274_probe()
1841 imx274->crop.width = IMX274_MAX_WIDTH; in imx274_probe()
1842 imx274->crop.height = IMX274_MAX_HEIGHT; in imx274_probe()
1843 imx274->format.width = imx274->crop.width / imx274->mode->bin_ratio; in imx274_probe()
1844 imx274->format.height = imx274->crop.height / imx274->mode->bin_ratio; in imx274_probe()
1845 imx274->format.field = V4L2_FIELD_NONE; in imx274_probe()
1846 imx274->format.code = MEDIA_BUS_FMT_SRGGB10_1X10; in imx274_probe()
1847 imx274->format.colorspace = V4L2_COLORSPACE_SRGB; in imx274_probe()
1848 imx274->frame_interval.numerator = 1; in imx274_probe()
1849 imx274->frame_interval.denominator = IMX274_DEF_FRAME_RATE; in imx274_probe()
1852 imx274->regmap = devm_regmap_init_i2c(client, &imx274_regmap_config); in imx274_probe()
1853 if (IS_ERR(imx274->regmap)) { in imx274_probe()
1855 "regmap init failed: %ld\n", PTR_ERR(imx274->regmap)); in imx274_probe()
1861 imx274->client = client; in imx274_probe()
1862 sd = &imx274->sd; in imx274_probe()
1867 imx274->pad.flags = MEDIA_PAD_FL_SOURCE; in imx274_probe()
1869 ret = media_entity_pads_init(&sd->entity, 1, &imx274->pad); in imx274_probe()
1877 imx274->reset_gpio = devm_gpiod_get_optional(&client->dev, "reset", in imx274_probe()
1879 if (IS_ERR(imx274->reset_gpio)) { in imx274_probe()
1880 if (PTR_ERR(imx274->reset_gpio) != -EPROBE_DEFER) in imx274_probe()
1882 ret = PTR_ERR(imx274->reset_gpio); in imx274_probe()
1887 imx274_reset(imx274, 1); in imx274_probe()
1890 ret = v4l2_ctrl_handler_init(&imx274->ctrls.handler, 4); in imx274_probe()
1897 imx274->ctrls.handler.lock = &imx274->lock; in imx274_probe()
1900 imx274->ctrls.test_pattern = v4l2_ctrl_new_std_menu_items( in imx274_probe()
1901 &imx274->ctrls.handler, &imx274_ctrl_ops, in imx274_probe()
1905 imx274->ctrls.gain = v4l2_ctrl_new_std( in imx274_probe()
1906 &imx274->ctrls.handler, in imx274_probe()
1912 imx274->ctrls.exposure = v4l2_ctrl_new_std( in imx274_probe()
1913 &imx274->ctrls.handler, in imx274_probe()
1919 imx274->ctrls.vflip = v4l2_ctrl_new_std( in imx274_probe()
1920 &imx274->ctrls.handler, in imx274_probe()
1924 imx274->sd.ctrl_handler = &imx274->ctrls.handler; in imx274_probe()
1925 if (imx274->ctrls.handler.error) { in imx274_probe()
1926 ret = imx274->ctrls.handler.error; in imx274_probe()
1931 ret = v4l2_ctrl_handler_setup(&imx274->ctrls.handler); in imx274_probe()
1939 ret = imx274_load_default(imx274); in imx274_probe()
1956 dev_info(&client->dev, "imx274 : imx274 probe success !\n"); in imx274_probe()
1960 v4l2_ctrl_handler_free(&imx274->ctrls.handler); in imx274_probe()
1964 mutex_destroy(&imx274->lock); in imx274_probe()
1971 struct stimx274 *imx274 = to_imx274(sd); in imx274_remove() local
1974 imx274_write_table(imx274, imx274_stop); in imx274_remove()
1977 v4l2_ctrl_handler_free(&imx274->ctrls.handler); in imx274_remove()
1979 mutex_destroy(&imx274->lock); in imx274_remove()
1996 MODULE_DESCRIPTION("IMX274 CMOS Image Sensor driver");