Lines Matching +full:vdig +full:- +full:supply

1 // SPDX-License-Identifier: GPL-2.0
25 #include <media/v4l2-cci.h>
26 #include <media/v4l2-ctrls.h>
27 #include <media/v4l2-device.h>
28 #include <media/v4l2-event.h>
29 #include <media/v4l2-fwnode.h>
30 #include <media/v4l2-mediabus.h>
88 /* HBLANK control - read only */
177 /* V-timing */
190 /* To Access Addresses 3000-5fff, send the following commands */
317 "VANA", /* Analog (2.8V) supply */
318 "VDIG", /* Digital Core (1.8V) supply */
319 "VDDL", /* IF (1.2V) supply */
328 * - no flip
329 * - h flip
330 * - v flip
331 * - h&v flips
346 * Initialisation delay between XCLR low->high and the moment when the sensor
359 * This start-up time can be optimized a bit more, if we start the writes
364 * This delay doesn't account for the power supply startup time. If needed,
366 * case of DT for regulator-fixed one should define the startup-delay-us
492 i = (i & ~3) | (imx219->vflip->val ? 2 : 0) | in imx219_get_format_code()
493 (imx219->hflip->val ? 1 : 0); in imx219_get_format_code()
501 container_of(ctrl->handler, struct imx219, ctrl_handler); in imx219_set_ctrl()
502 struct i2c_client *client = v4l2_get_subdevdata(&imx219->sd); in imx219_set_ctrl()
505 if (ctrl->id == V4L2_CID_VBLANK) { in imx219_set_ctrl()
509 exposure_max = imx219->mode->height + ctrl->val - 4; in imx219_set_ctrl()
512 __v4l2_ctrl_modify_range(imx219->exposure, in imx219_set_ctrl()
513 imx219->exposure->minimum, in imx219_set_ctrl()
514 exposure_max, imx219->exposure->step, in imx219_set_ctrl()
522 if (pm_runtime_get_if_in_use(&client->dev) == 0) in imx219_set_ctrl()
525 switch (ctrl->id) { in imx219_set_ctrl()
527 cci_write(imx219->regmap, IMX219_REG_ANALOG_GAIN, in imx219_set_ctrl()
528 ctrl->val, &ret); in imx219_set_ctrl()
531 cci_write(imx219->regmap, IMX219_REG_EXPOSURE, in imx219_set_ctrl()
532 ctrl->val, &ret); in imx219_set_ctrl()
535 cci_write(imx219->regmap, IMX219_REG_DIGITAL_GAIN, in imx219_set_ctrl()
536 ctrl->val, &ret); in imx219_set_ctrl()
539 cci_write(imx219->regmap, IMX219_REG_TEST_PATTERN, in imx219_set_ctrl()
540 imx219_test_pattern_val[ctrl->val], &ret); in imx219_set_ctrl()
544 cci_write(imx219->regmap, IMX219_REG_ORIENTATION, in imx219_set_ctrl()
545 imx219->hflip->val | imx219->vflip->val << 1, &ret); in imx219_set_ctrl()
548 cci_write(imx219->regmap, IMX219_REG_VTS, in imx219_set_ctrl()
549 imx219->mode->height + ctrl->val, &ret); in imx219_set_ctrl()
552 cci_write(imx219->regmap, IMX219_REG_TESTP_RED, in imx219_set_ctrl()
553 ctrl->val, &ret); in imx219_set_ctrl()
556 cci_write(imx219->regmap, IMX219_REG_TESTP_GREENR, in imx219_set_ctrl()
557 ctrl->val, &ret); in imx219_set_ctrl()
560 cci_write(imx219->regmap, IMX219_REG_TESTP_BLUE, in imx219_set_ctrl()
561 ctrl->val, &ret); in imx219_set_ctrl()
564 cci_write(imx219->regmap, IMX219_REG_TESTP_GREENB, in imx219_set_ctrl()
565 ctrl->val, &ret); in imx219_set_ctrl()
568 dev_info(&client->dev, in imx219_set_ctrl()
570 ctrl->id, ctrl->val); in imx219_set_ctrl()
571 ret = -EINVAL; in imx219_set_ctrl()
575 pm_runtime_put(&client->dev); in imx219_set_ctrl()
589 fmt->code = imx219_get_format_code(imx219, code); in imx219_update_pad_format()
590 fmt->width = mode->width; in imx219_update_pad_format()
591 fmt->height = mode->height; in imx219_update_pad_format()
592 fmt->field = V4L2_FIELD_NONE; in imx219_update_pad_format()
593 fmt->colorspace = V4L2_COLORSPACE_RAW; in imx219_update_pad_format()
594 fmt->quantization = V4L2_QUANTIZATION_FULL_RANGE; in imx219_update_pad_format()
595 fmt->xfer_func = V4L2_XFER_FUNC_NONE; in imx219_update_pad_format()
612 crop->top = IMX219_PIXEL_ARRAY_TOP; in imx219_init_cfg()
613 crop->left = IMX219_PIXEL_ARRAY_LEFT; in imx219_init_cfg()
614 crop->width = IMX219_PIXEL_ARRAY_WIDTH; in imx219_init_cfg()
615 crop->height = IMX219_PIXEL_ARRAY_HEIGHT; in imx219_init_cfg()
626 if (code->index >= (ARRAY_SIZE(imx219_mbus_formats) / 4)) in imx219_enum_mbus_code()
627 return -EINVAL; in imx219_enum_mbus_code()
629 code->code = imx219_get_format_code(imx219, imx219_mbus_formats[code->index * 4]); in imx219_enum_mbus_code()
641 if (fse->index >= ARRAY_SIZE(supported_modes)) in imx219_enum_frame_size()
642 return -EINVAL; in imx219_enum_frame_size()
644 code = imx219_get_format_code(imx219, fse->code); in imx219_enum_frame_size()
645 if (fse->code != code) in imx219_enum_frame_size()
646 return -EINVAL; in imx219_enum_frame_size()
648 fse->min_width = supported_modes[fse->index].width; in imx219_enum_frame_size()
649 fse->max_width = fse->min_width; in imx219_enum_frame_size()
650 fse->min_height = supported_modes[fse->index].height; in imx219_enum_frame_size()
651 fse->max_height = fse->min_height; in imx219_enum_frame_size()
669 fmt->format.width, fmt->format.height); in imx219_set_pad_format()
671 imx219_update_pad_format(imx219, mode, &fmt->format, fmt->format.code); in imx219_set_pad_format()
676 *format = fmt->format; in imx219_set_pad_format()
677 *crop = mode->crop; in imx219_set_pad_format()
679 if (fmt->which == V4L2_SUBDEV_FORMAT_ACTIVE) { in imx219_set_pad_format()
680 imx219->mode = mode; in imx219_set_pad_format()
682 __v4l2_ctrl_modify_range(imx219->vblank, IMX219_VBLANK_MIN, in imx219_set_pad_format()
683 IMX219_VTS_MAX - mode->height, 1, in imx219_set_pad_format()
684 mode->vts_def - mode->height); in imx219_set_pad_format()
685 __v4l2_ctrl_s_ctrl(imx219->vblank, in imx219_set_pad_format()
686 mode->vts_def - mode->height); in imx219_set_pad_format()
688 exposure_max = mode->vts_def - 4; in imx219_set_pad_format()
691 __v4l2_ctrl_modify_range(imx219->exposure, in imx219_set_pad_format()
692 imx219->exposure->minimum, in imx219_set_pad_format()
693 exposure_max, imx219->exposure->step, in imx219_set_pad_format()
697 * depends on mode->width only, and is not changeble in any in imx219_set_pad_format()
700 hblank = IMX219_PPL_DEFAULT - mode->width; in imx219_set_pad_format()
701 __v4l2_ctrl_modify_range(imx219->hblank, hblank, hblank, 1, in imx219_set_pad_format()
711 switch (format->code) { in imx219_set_framefmt()
716 return cci_multi_reg_write(imx219->regmap, raw8_framefmt_regs, in imx219_set_framefmt()
723 return cci_multi_reg_write(imx219->regmap, raw10_framefmt_regs, in imx219_set_framefmt()
727 return -EINVAL; in imx219_set_framefmt()
733 if (!imx219->mode->binning) in imx219_set_binning()
734 return cci_write(imx219->regmap, IMX219_REG_BINNING_MODE, in imx219_set_binning()
737 switch (format->code) { in imx219_set_binning()
742 return cci_write(imx219->regmap, IMX219_REG_BINNING_MODE, in imx219_set_binning()
749 return cci_write(imx219->regmap, IMX219_REG_BINNING_MODE, in imx219_set_binning()
753 return -EINVAL; in imx219_set_binning()
760 switch (sel->target) { in imx219_get_selection()
762 sel->r = *v4l2_subdev_get_pad_crop(sd, sd_state, 0); in imx219_get_selection()
767 sel->r.top = 0; in imx219_get_selection()
768 sel->r.left = 0; in imx219_get_selection()
769 sel->r.width = IMX219_NATIVE_WIDTH; in imx219_get_selection()
770 sel->r.height = IMX219_NATIVE_HEIGHT; in imx219_get_selection()
776 sel->r.top = IMX219_PIXEL_ARRAY_TOP; in imx219_get_selection()
777 sel->r.left = IMX219_PIXEL_ARRAY_LEFT; in imx219_get_selection()
778 sel->r.width = IMX219_PIXEL_ARRAY_WIDTH; in imx219_get_selection()
779 sel->r.height = IMX219_PIXEL_ARRAY_HEIGHT; in imx219_get_selection()
784 return -EINVAL; in imx219_get_selection()
789 return cci_write(imx219->regmap, IMX219_REG_CSI_LANE_MODE, in imx219_configure_lanes()
790 imx219->lanes == 2 ? IMX219_CSI_2_LANE_MODE : in imx219_configure_lanes()
797 struct i2c_client *client = v4l2_get_subdevdata(&imx219->sd); in imx219_start_streaming()
802 ret = pm_runtime_resume_and_get(&client->dev); in imx219_start_streaming()
807 ret = cci_multi_reg_write(imx219->regmap, imx219_common_regs, in imx219_start_streaming()
810 dev_err(&client->dev, "%s failed to send mfg header\n", __func__); in imx219_start_streaming()
817 dev_err(&client->dev, "%s failed to configure lanes\n", __func__); in imx219_start_streaming()
822 reg_list = &imx219->mode->reg_list; in imx219_start_streaming()
823 ret = cci_multi_reg_write(imx219->regmap, reg_list->regs, in imx219_start_streaming()
824 reg_list->num_of_regs, NULL); in imx219_start_streaming()
826 dev_err(&client->dev, "%s failed to set mode\n", __func__); in imx219_start_streaming()
830 format = v4l2_subdev_get_pad_format(&imx219->sd, state, 0); in imx219_start_streaming()
833 dev_err(&client->dev, "%s failed to set frame format: %d\n", in imx219_start_streaming()
840 dev_err(&client->dev, "%s failed to set binning: %d\n", in imx219_start_streaming()
846 ret = __v4l2_ctrl_handler_setup(imx219->sd.ctrl_handler); in imx219_start_streaming()
851 ret = cci_write(imx219->regmap, IMX219_REG_MODE_SELECT, in imx219_start_streaming()
857 __v4l2_ctrl_grab(imx219->vflip, true); in imx219_start_streaming()
858 __v4l2_ctrl_grab(imx219->hflip, true); in imx219_start_streaming()
863 pm_runtime_put(&client->dev); in imx219_start_streaming()
869 struct i2c_client *client = v4l2_get_subdevdata(&imx219->sd); in imx219_stop_streaming()
873 ret = cci_write(imx219->regmap, IMX219_REG_MODE_SELECT, in imx219_stop_streaming()
876 dev_err(&client->dev, "%s failed to set stream\n", __func__); in imx219_stop_streaming()
878 __v4l2_ctrl_grab(imx219->vflip, false); in imx219_stop_streaming()
879 __v4l2_ctrl_grab(imx219->hflip, false); in imx219_stop_streaming()
881 pm_runtime_put(&client->dev); in imx219_stop_streaming()
892 if (imx219->streaming == enable) in imx219_set_stream()
907 imx219->streaming = enable; in imx219_set_stream()
922 imx219->supplies); in imx219_power_on()
929 ret = clk_prepare_enable(imx219->xclk); in imx219_power_on()
936 gpiod_set_value_cansleep(imx219->reset_gpio, 1); in imx219_power_on()
943 regulator_bulk_disable(IMX219_NUM_SUPPLIES, imx219->supplies); in imx219_power_on()
953 gpiod_set_value_cansleep(imx219->reset_gpio, 0); in imx219_power_off()
954 regulator_bulk_disable(IMX219_NUM_SUPPLIES, imx219->supplies); in imx219_power_off()
955 clk_disable_unprepare(imx219->xclk); in imx219_power_off()
965 if (imx219->streaming) in imx219_suspend()
978 if (imx219->streaming) { in imx219_resume()
990 imx219->streaming = false; in imx219_resume()
997 struct i2c_client *client = v4l2_get_subdevdata(&imx219->sd); in imx219_get_regulators()
1001 imx219->supplies[i].supply = imx219_supply_name[i]; in imx219_get_regulators()
1003 return devm_regulator_bulk_get(&client->dev, in imx219_get_regulators()
1005 imx219->supplies); in imx219_get_regulators()
1011 struct i2c_client *client = v4l2_get_subdevdata(&imx219->sd); in imx219_identify_module()
1015 ret = cci_read(imx219->regmap, IMX219_REG_CHIP_ID, &val, NULL); in imx219_identify_module()
1017 dev_err(&client->dev, "failed to read chip id %x\n", in imx219_identify_module()
1023 dev_err(&client->dev, "chip id mismatch: %x!=%llx\n", in imx219_identify_module()
1025 return -EIO; in imx219_identify_module()
1058 return (imx219->lanes == 2) ? IMX219_PIXEL_RATE : IMX219_PIXEL_RATE_4LANE; in imx219_get_pixel_rate()
1064 struct i2c_client *client = v4l2_get_subdevdata(&imx219->sd); in imx219_init_controls()
1066 unsigned int height = imx219->mode->height; in imx219_init_controls()
1071 ctrl_hdlr = &imx219->ctrl_handler; in imx219_init_controls()
1077 imx219->pixel_rate = v4l2_ctrl_new_std(ctrl_hdlr, &imx219_ctrl_ops, in imx219_init_controls()
1083 imx219->link_freq = in imx219_init_controls()
1086 ARRAY_SIZE(imx219_link_freq_menu) - 1, 0, in imx219_init_controls()
1087 (imx219->lanes == 2) ? imx219_link_freq_menu : in imx219_init_controls()
1089 if (imx219->link_freq) in imx219_init_controls()
1090 imx219->link_freq->flags |= V4L2_CTRL_FLAG_READ_ONLY; in imx219_init_controls()
1093 imx219->vblank = v4l2_ctrl_new_std(ctrl_hdlr, &imx219_ctrl_ops, in imx219_init_controls()
1095 IMX219_VTS_MAX - height, 1, in imx219_init_controls()
1096 imx219->mode->vts_def - height); in imx219_init_controls()
1097 hblank = IMX219_PPL_DEFAULT - imx219->mode->width; in imx219_init_controls()
1098 imx219->hblank = v4l2_ctrl_new_std(ctrl_hdlr, &imx219_ctrl_ops, in imx219_init_controls()
1101 if (imx219->hblank) in imx219_init_controls()
1102 imx219->hblank->flags |= V4L2_CTRL_FLAG_READ_ONLY; in imx219_init_controls()
1103 exposure_max = imx219->mode->vts_def - 4; in imx219_init_controls()
1106 imx219->exposure = v4l2_ctrl_new_std(ctrl_hdlr, &imx219_ctrl_ops, in imx219_init_controls()
1120 imx219->hflip = v4l2_ctrl_new_std(ctrl_hdlr, &imx219_ctrl_ops, in imx219_init_controls()
1122 if (imx219->hflip) in imx219_init_controls()
1123 imx219->hflip->flags |= V4L2_CTRL_FLAG_MODIFY_LAYOUT; in imx219_init_controls()
1125 imx219->vflip = v4l2_ctrl_new_std(ctrl_hdlr, &imx219_ctrl_ops, in imx219_init_controls()
1127 if (imx219->vflip) in imx219_init_controls()
1128 imx219->vflip->flags |= V4L2_CTRL_FLAG_MODIFY_LAYOUT; in imx219_init_controls()
1132 ARRAY_SIZE(imx219_test_pattern_menu) - 1, in imx219_init_controls()
1150 if (ctrl_hdlr->error) { in imx219_init_controls()
1151 ret = ctrl_hdlr->error; in imx219_init_controls()
1152 dev_err(&client->dev, "%s control init failed (%d)\n", in imx219_init_controls()
1157 ret = v4l2_fwnode_device_parse(&client->dev, &props); in imx219_init_controls()
1166 imx219->sd.ctrl_handler = ctrl_hdlr; in imx219_init_controls()
1178 v4l2_ctrl_handler_free(imx219->sd.ctrl_handler); in imx219_free_controls()
1187 int ret = -EINVAL; in imx219_check_hwcfg()
1192 return -EINVAL; in imx219_check_hwcfg()
1206 imx219->lanes = ep_cfg.bus.mipi_csi2.num_data_lanes; in imx219_check_hwcfg()
1210 dev_err(dev, "link-frequency property not found in DT\n"); in imx219_check_hwcfg()
1215 (ep_cfg.link_frequencies[0] != ((imx219->lanes == 2) ? in imx219_check_hwcfg()
1233 struct device *dev = &client->dev; in imx219_probe()
1237 imx219 = devm_kzalloc(&client->dev, sizeof(*imx219), GFP_KERNEL); in imx219_probe()
1239 return -ENOMEM; in imx219_probe()
1241 v4l2_i2c_subdev_init(&imx219->sd, client, &imx219_subdev_ops); in imx219_probe()
1245 return -EINVAL; in imx219_probe()
1247 imx219->regmap = devm_cci_regmap_init_i2c(client, 16); in imx219_probe()
1248 if (IS_ERR(imx219->regmap)) { in imx219_probe()
1249 ret = PTR_ERR(imx219->regmap); in imx219_probe()
1255 imx219->xclk = devm_clk_get(dev, NULL); in imx219_probe()
1256 if (IS_ERR(imx219->xclk)) { in imx219_probe()
1258 return PTR_ERR(imx219->xclk); in imx219_probe()
1261 imx219->xclk_freq = clk_get_rate(imx219->xclk); in imx219_probe()
1262 if (imx219->xclk_freq != IMX219_XCLK_FREQ) { in imx219_probe()
1264 imx219->xclk_freq); in imx219_probe()
1265 return -EINVAL; in imx219_probe()
1275 imx219->reset_gpio = devm_gpiod_get_optional(dev, "reset", in imx219_probe()
1291 imx219->mode = &supported_modes[0]; in imx219_probe()
1293 /* sensor doesn't enter LP-11 state upon power up until and unless in imx219_probe()
1295 * streaming -> standby in imx219_probe()
1297 ret = cci_write(imx219->regmap, IMX219_REG_MODE_SELECT, in imx219_probe()
1305 ret = cci_write(imx219->regmap, IMX219_REG_MODE_SELECT, in imx219_probe()
1317 imx219->sd.flags |= V4L2_SUBDEV_FL_HAS_DEVNODE | in imx219_probe()
1319 imx219->sd.entity.function = MEDIA_ENT_F_CAM_SENSOR; in imx219_probe()
1322 imx219->pad.flags = MEDIA_PAD_FL_SOURCE; in imx219_probe()
1324 ret = media_entity_pads_init(&imx219->sd.entity, 1, &imx219->pad); in imx219_probe()
1330 imx219->sd.state_lock = imx219->ctrl_handler.lock; in imx219_probe()
1331 ret = v4l2_subdev_init_finalize(&imx219->sd); in imx219_probe()
1337 ret = v4l2_async_register_subdev_sensor(&imx219->sd); in imx219_probe()
1339 dev_err(dev, "failed to register sensor sub-device: %d\n", ret); in imx219_probe()
1351 v4l2_subdev_cleanup(&imx219->sd); in imx219_probe()
1354 media_entity_cleanup(&imx219->sd.entity); in imx219_probe()
1372 media_entity_cleanup(&sd->entity); in imx219_remove()
1375 pm_runtime_disable(&client->dev); in imx219_remove()
1376 if (!pm_runtime_status_suspended(&client->dev)) in imx219_remove()
1377 imx219_power_off(&client->dev); in imx219_remove()
1378 pm_runtime_set_suspended(&client->dev); in imx219_remove()