Lines Matching full:imx258
80 /* IMX258 native and active pixel array size. */
647 struct imx258 { struct
683 static inline struct imx258 *to_imx258(struct v4l2_subdev *_sd) in to_imx258() argument
685 return container_of(_sd, struct imx258, sd); in to_imx258()
689 static u32 imx258_get_format_code(const struct imx258 *imx258) in imx258_get_format_code() argument
693 lockdep_assert_held(&imx258->mutex); in imx258_get_format_code()
695 i = (imx258->vflip->val ? 2 : 0) | in imx258_get_format_code()
696 (imx258->hflip->val ? 1 : 0); in imx258_get_format_code()
704 struct imx258 *imx258 = to_imx258(sd); in imx258_open() local
712 try_fmt->code = imx258_get_format_code(imx258); in imx258_open()
725 static int imx258_update_digital_gain(struct imx258 *imx258, u32 val) in imx258_update_digital_gain() argument
729 cci_write(imx258->regmap, IMX258_REG_GR_DIGITAL_GAIN, val, &ret); in imx258_update_digital_gain()
730 cci_write(imx258->regmap, IMX258_REG_GB_DIGITAL_GAIN, val, &ret); in imx258_update_digital_gain()
731 cci_write(imx258->regmap, IMX258_REG_R_DIGITAL_GAIN, val, &ret); in imx258_update_digital_gain()
732 cci_write(imx258->regmap, IMX258_REG_B_DIGITAL_GAIN, val, &ret); in imx258_update_digital_gain()
737 static void imx258_adjust_exposure_range(struct imx258 *imx258) in imx258_adjust_exposure_range() argument
742 exposure_max = imx258->cur_mode->height + imx258->vblank->val - in imx258_adjust_exposure_range()
744 exposure_def = min(exposure_max, imx258->exposure->val); in imx258_adjust_exposure_range()
745 __v4l2_ctrl_modify_range(imx258->exposure, imx258->exposure->minimum, in imx258_adjust_exposure_range()
746 exposure_max, imx258->exposure->step, in imx258_adjust_exposure_range()
752 struct imx258 *imx258 = in imx258_set_ctrl() local
753 container_of(ctrl->handler, struct imx258, ctrl_handler); in imx258_set_ctrl()
754 struct i2c_client *client = v4l2_get_subdevdata(&imx258->sd); in imx258_set_ctrl()
762 imx258_adjust_exposure_range(imx258); in imx258_set_ctrl()
773 ret = cci_write(imx258->regmap, IMX258_REG_ANALOG_GAIN, in imx258_set_ctrl()
777 ret = cci_write(imx258->regmap, IMX258_REG_EXPOSURE, in imx258_set_ctrl()
781 ret = imx258_update_digital_gain(imx258, ctrl->val); in imx258_set_ctrl()
784 ret = cci_write(imx258->regmap, IMX258_REG_TEST_PATTERN, in imx258_set_ctrl()
789 ret = cci_write(imx258->regmap, IMX258_REG_HDR, in imx258_set_ctrl()
792 ret = cci_write(imx258->regmap, IMX258_REG_HDR, in imx258_set_ctrl()
796 ret = cci_write(imx258->regmap, IMX258_REG_HDR_RATIO, in imx258_set_ctrl()
801 ret = cci_write(imx258->regmap, IMX258_REG_FRM_LENGTH_LINES, in imx258_set_ctrl()
802 imx258->cur_mode->height + ctrl->val, NULL); in imx258_set_ctrl()
806 ret = cci_write(imx258->regmap, REG_MIRROR_FLIP_CONTROL, in imx258_set_ctrl()
807 (imx258->hflip->val ? in imx258_set_ctrl()
809 (imx258->vflip->val ? in imx258_set_ctrl()
834 struct imx258 *imx258 = to_imx258(sd); in imx258_enum_mbus_code() local
840 code->code = imx258_get_format_code(imx258); in imx258_enum_mbus_code()
849 struct imx258 *imx258 = to_imx258(sd); in imx258_enum_frame_size() local
853 if (fse->code != imx258_get_format_code(imx258)) in imx258_enum_frame_size()
864 static void imx258_update_pad_format(struct imx258 *imx258, in imx258_update_pad_format() argument
870 fmt->format.code = imx258_get_format_code(imx258); in imx258_update_pad_format()
874 static int __imx258_get_pad_format(struct imx258 *imx258, in __imx258_get_pad_format() argument
882 imx258_update_pad_format(imx258, imx258->cur_mode, fmt); in __imx258_get_pad_format()
891 struct imx258 *imx258 = to_imx258(sd); in imx258_get_pad_format() local
894 mutex_lock(&imx258->mutex); in imx258_get_pad_format()
895 ret = __imx258_get_pad_format(imx258, sd_state, fmt); in imx258_get_pad_format()
896 mutex_unlock(&imx258->mutex); in imx258_get_pad_format()
905 struct imx258 *imx258 = to_imx258(sd); in imx258_set_pad_format() local
916 mutex_lock(&imx258->mutex); in imx258_set_pad_format()
918 fmt->format.code = imx258_get_format_code(imx258); in imx258_set_pad_format()
923 imx258_update_pad_format(imx258, mode, fmt); in imx258_set_pad_format()
928 imx258->cur_mode = mode; in imx258_set_pad_format()
929 __v4l2_ctrl_s_ctrl(imx258->link_freq, mode->link_freq_index); in imx258_set_pad_format()
931 link_freq = imx258->link_freq_menu_items[mode->link_freq_index]; in imx258_set_pad_format()
933 &imx258->link_freq_configs[mode->link_freq_index]; in imx258_set_pad_format()
935 link_cfg = &link_freq_cfgs->link_cfg[imx258->lane_mode_idx]; in imx258_set_pad_format()
937 __v4l2_ctrl_modify_range(imx258->pixel_rate, pixel_rate, in imx258_set_pad_format()
940 vblank_def = imx258->cur_mode->vts_def - in imx258_set_pad_format()
941 imx258->cur_mode->height; in imx258_set_pad_format()
942 vblank_min = imx258->cur_mode->vts_min - in imx258_set_pad_format()
943 imx258->cur_mode->height; in imx258_set_pad_format()
945 imx258->vblank, vblank_min, in imx258_set_pad_format()
946 IMX258_VTS_MAX - imx258->cur_mode->height, 1, in imx258_set_pad_format()
948 __v4l2_ctrl_s_ctrl(imx258->vblank, vblank_def); in imx258_set_pad_format()
950 imx258->link_freq_configs[mode->link_freq_index].pixels_per_line in imx258_set_pad_format()
951 - imx258->cur_mode->width; in imx258_set_pad_format()
952 __v4l2_ctrl_modify_range(imx258->hblank, h_blank, in imx258_set_pad_format()
956 mutex_unlock(&imx258->mutex); in imx258_set_pad_format()
962 __imx258_get_pad_crop(struct imx258 *imx258, in __imx258_get_pad_crop() argument
970 return &imx258->cur_mode->crop; in __imx258_get_pad_crop()
982 struct imx258 *imx258 = to_imx258(sd); in imx258_get_selection() local
984 mutex_lock(&imx258->mutex); in imx258_get_selection()
985 sel->r = *__imx258_get_pad_crop(imx258, sd_state, sel->pad, in imx258_get_selection()
987 mutex_unlock(&imx258->mutex); in imx258_get_selection()
1014 static int imx258_start_streaming(struct imx258 *imx258) in imx258_start_streaming() argument
1016 struct i2c_client *client = v4l2_get_subdevdata(&imx258->sd); in imx258_start_streaming()
1021 ret = cci_write(imx258->regmap, IMX258_REG_RESET, 0x01, NULL); in imx258_start_streaming()
1031 link_freq_index = imx258->cur_mode->link_freq_index; in imx258_start_streaming()
1032 link_freq_cfg = &imx258->link_freq_configs[link_freq_index]; in imx258_start_streaming()
1034 reg_list = &link_freq_cfg->link_cfg[imx258->lane_mode_idx].reg_list; in imx258_start_streaming()
1035 ret = cci_multi_reg_write(imx258->regmap, reg_list->regs, reg_list->num_of_regs, NULL); in imx258_start_streaming()
1041 ret = cci_multi_reg_write(imx258->regmap, mode_common_regs, in imx258_start_streaming()
1048 ret = cci_multi_reg_write(imx258->regmap, imx258->variant_cfg->regs, in imx258_start_streaming()
1049 imx258->variant_cfg->num_regs, NULL); in imx258_start_streaming()
1056 ret = cci_write(imx258->regmap, IMX258_CLK_BLANK_STOP, in imx258_start_streaming()
1057 !!(imx258->csi2_flags & V4L2_MBUS_CSI2_NONCONTINUOUS_CLOCK), in imx258_start_streaming()
1065 reg_list = &imx258->cur_mode->reg_list; in imx258_start_streaming()
1066 ret = cci_multi_reg_write(imx258->regmap, reg_list->regs, reg_list->num_of_regs, NULL); in imx258_start_streaming()
1073 ret = __v4l2_ctrl_handler_setup(imx258->sd.ctrl_handler); in imx258_start_streaming()
1078 return cci_write(imx258->regmap, IMX258_REG_MODE_SELECT, in imx258_start_streaming()
1083 static int imx258_stop_streaming(struct imx258 *imx258) in imx258_stop_streaming() argument
1085 struct i2c_client *client = v4l2_get_subdevdata(&imx258->sd); in imx258_stop_streaming()
1089 ret = cci_write(imx258->regmap, IMX258_REG_MODE_SELECT, in imx258_stop_streaming()
1104 struct imx258 *imx258 = to_imx258(sd); in imx258_power_on() local
1108 imx258->supplies); in imx258_power_on()
1115 ret = clk_prepare_enable(imx258->clk); in imx258_power_on()
1118 regulator_bulk_disable(IMX258_NUM_SUPPLIES, imx258->supplies); in imx258_power_on()
1127 struct imx258 *imx258 = to_imx258(sd); in imx258_power_off() local
1129 clk_disable_unprepare(imx258->clk); in imx258_power_off()
1130 regulator_bulk_disable(IMX258_NUM_SUPPLIES, imx258->supplies); in imx258_power_off()
1137 struct imx258 *imx258 = to_imx258(sd); in imx258_set_stream() local
1141 mutex_lock(&imx258->mutex); in imx258_set_stream()
1152 ret = imx258_start_streaming(imx258); in imx258_set_stream()
1156 imx258_stop_streaming(imx258); in imx258_set_stream()
1160 mutex_unlock(&imx258->mutex); in imx258_set_stream()
1167 mutex_unlock(&imx258->mutex); in imx258_set_stream()
1173 static int imx258_identify_module(struct imx258 *imx258) in imx258_identify_module() argument
1175 struct i2c_client *client = v4l2_get_subdevdata(&imx258->sd); in imx258_identify_module()
1179 ret = cci_read(imx258->regmap, IMX258_REG_CHIP_ID, in imx258_identify_module()
1218 static int imx258_init_controls(struct imx258 *imx258) in imx258_init_controls() argument
1220 struct i2c_client *client = v4l2_get_subdevdata(&imx258->sd); in imx258_init_controls()
1230 ctrl_hdlr = &imx258->ctrl_handler; in imx258_init_controls()
1235 mutex_init(&imx258->mutex); in imx258_init_controls()
1236 ctrl_hdlr->lock = &imx258->mutex; in imx258_init_controls()
1237 imx258->link_freq = v4l2_ctrl_new_int_menu(ctrl_hdlr, in imx258_init_controls()
1242 imx258->link_freq_menu_items); in imx258_init_controls()
1244 if (imx258->link_freq) in imx258_init_controls()
1245 imx258->link_freq->flags |= V4L2_CTRL_FLAG_READ_ONLY; in imx258_init_controls()
1247 imx258->hflip = v4l2_ctrl_new_std(ctrl_hdlr, &imx258_ctrl_ops, in imx258_init_controls()
1249 if (imx258->hflip) in imx258_init_controls()
1250 imx258->hflip->flags |= V4L2_CTRL_FLAG_MODIFY_LAYOUT; in imx258_init_controls()
1252 imx258->vflip = v4l2_ctrl_new_std(ctrl_hdlr, &imx258_ctrl_ops, in imx258_init_controls()
1254 if (imx258->vflip) in imx258_init_controls()
1255 imx258->vflip->flags |= V4L2_CTRL_FLAG_MODIFY_LAYOUT; in imx258_init_controls()
1257 link_freq_cfgs = &imx258->link_freq_configs[0]; in imx258_init_controls()
1258 link_cfg = link_freq_cfgs[imx258->lane_mode_idx].link_cfg; in imx258_init_controls()
1259 pixel_rate = link_freq_to_pixel_rate(imx258->link_freq_menu_items[0], in imx258_init_controls()
1263 imx258->pixel_rate = v4l2_ctrl_new_std(ctrl_hdlr, &imx258_ctrl_ops, in imx258_init_controls()
1268 vblank_def = imx258->cur_mode->vts_def - imx258->cur_mode->height; in imx258_init_controls()
1269 vblank_min = imx258->cur_mode->vts_min - imx258->cur_mode->height; in imx258_init_controls()
1270 imx258->vblank = v4l2_ctrl_new_std( in imx258_init_controls()
1273 IMX258_VTS_MAX - imx258->cur_mode->height, 1, in imx258_init_controls()
1276 imx258->hblank = v4l2_ctrl_new_std( in imx258_init_controls()
1278 IMX258_PPL_DEFAULT - imx258->cur_mode->width, in imx258_init_controls()
1279 IMX258_PPL_DEFAULT - imx258->cur_mode->width, in imx258_init_controls()
1281 IMX258_PPL_DEFAULT - imx258->cur_mode->width); in imx258_init_controls()
1283 if (imx258->hblank) in imx258_init_controls()
1284 imx258->hblank->flags |= V4L2_CTRL_FLAG_READ_ONLY; in imx258_init_controls()
1286 imx258->exposure = v4l2_ctrl_new_std( in imx258_init_controls()
1325 imx258->sd.ctrl_handler = ctrl_hdlr; in imx258_init_controls()
1331 mutex_destroy(&imx258->mutex); in imx258_init_controls()
1336 static void imx258_free_controls(struct imx258 *imx258) in imx258_free_controls() argument
1338 v4l2_ctrl_handler_free(imx258->sd.ctrl_handler); in imx258_free_controls()
1339 mutex_destroy(&imx258->mutex); in imx258_free_controls()
1342 static int imx258_get_regulators(struct imx258 *imx258, in imx258_get_regulators() argument
1348 imx258->supplies[i].supply = imx258_supply_name[i]; in imx258_get_regulators()
1351 IMX258_NUM_SUPPLIES, imx258->supplies); in imx258_get_regulators()
1356 struct imx258 *imx258; in imx258_probe() local
1364 imx258 = devm_kzalloc(&client->dev, sizeof(*imx258), GFP_KERNEL); in imx258_probe()
1365 if (!imx258) in imx258_probe()
1368 imx258->regmap = devm_cci_regmap_init_i2c(client, 16); in imx258_probe()
1369 if (IS_ERR(imx258->regmap)) { in imx258_probe()
1370 ret = PTR_ERR(imx258->regmap); in imx258_probe()
1375 ret = imx258_get_regulators(imx258, client); in imx258_probe()
1380 imx258->clk = devm_clk_get_optional(&client->dev, NULL); in imx258_probe()
1381 if (IS_ERR(imx258->clk)) in imx258_probe()
1382 return dev_err_probe(&client->dev, PTR_ERR(imx258->clk), in imx258_probe()
1384 if (!imx258->clk) { in imx258_probe()
1390 val = clk_get_rate(imx258->clk); in imx258_probe()
1395 imx258->link_freq_configs = link_freq_configs_19_2; in imx258_probe()
1396 imx258->link_freq_menu_items = link_freq_menu_items_19_2; in imx258_probe()
1399 imx258->link_freq_configs = link_freq_configs_24; in imx258_probe()
1400 imx258->link_freq_menu_items = link_freq_menu_items_24; in imx258_probe()
1424 imx258->link_freq_menu_items, in imx258_probe()
1426 &imx258->link_freq_bitmap); in imx258_probe()
1435 imx258->lane_mode_idx = IMX258_2_LANE_MODE; in imx258_probe()
1438 imx258->lane_mode_idx = IMX258_4_LANE_MODE; in imx258_probe()
1447 imx258->csi2_flags = ep.bus.mipi_csi2.flags; in imx258_probe()
1449 imx258->variant_cfg = device_get_match_data(&client->dev); in imx258_probe()
1450 if (!imx258->variant_cfg) in imx258_probe()
1451 imx258->variant_cfg = &imx258_cfg; in imx258_probe()
1454 v4l2_i2c_subdev_init(&imx258->sd, client, &imx258_subdev_ops); in imx258_probe()
1462 ret = imx258_identify_module(imx258); in imx258_probe()
1467 imx258->cur_mode = &supported_modes[0]; in imx258_probe()
1469 ret = imx258_init_controls(imx258); in imx258_probe()
1474 imx258->sd.internal_ops = &imx258_internal_ops; in imx258_probe()
1475 imx258->sd.flags |= V4L2_SUBDEV_FL_HAS_DEVNODE; in imx258_probe()
1476 imx258->sd.entity.function = MEDIA_ENT_F_CAM_SENSOR; in imx258_probe()
1479 imx258->pad.flags = MEDIA_PAD_FL_SOURCE; in imx258_probe()
1481 ret = media_entity_pads_init(&imx258->sd.entity, 1, &imx258->pad); in imx258_probe()
1485 ret = v4l2_async_register_subdev_sensor(&imx258->sd); in imx258_probe()
1497 media_entity_cleanup(&imx258->sd.entity); in imx258_probe()
1500 imx258_free_controls(imx258); in imx258_probe()
1514 struct imx258 *imx258 = to_imx258(sd); in imx258_remove() local
1518 imx258_free_controls(imx258); in imx258_remove()
1540 { .compatible = "sony,imx258", .data = &imx258_cfg },
1541 { .compatible = "sony,imx258-pdaf", .data = &imx258_pdaf_cfg },
1548 .name = "imx258",
1562 MODULE_DESCRIPTION("Sony IMX258 sensor driver");