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

1 // SPDX-License-Identifier: GPL-2.0
24 #include <media/v4l2-ctrls.h>
25 #include <media/v4l2-device.h>
26 #include <media/v4l2-event.h>
27 #include <media/v4l2-fwnode.h>
28 #include <media/v4l2-mediabus.h>
66 /* HBLANK control - read only */
141 /* V-timing */
414 "VANA", /* Analog (2.8V) supply */
415 "VDIG", /* Digital Core (1.8V) supply */
416 "VDDL", /* IF (1.2V) supply */
425 * - no flip
426 * - h flip
427 * - v flip
428 * - h&v flips
443 * Initialisation delay between XCLR low->high and the moment when the sensor
456 * This start-up time can be optimized a bit more, if we start the writes
461 * This delay doesn't account for the power supply startup time. If needed,
463 * case of DT for regulator-fixed one should define the startup-delay-us
579 struct i2c_client *client = v4l2_get_subdevdata(&imx219->sd); in imx219_read_reg()
586 return -EINVAL; in imx219_read_reg()
589 msgs[0].addr = client->addr; in imx219_read_reg()
595 msgs[1].addr = client->addr; in imx219_read_reg()
598 msgs[1].buf = &data_buf[4 - len]; in imx219_read_reg()
600 ret = i2c_transfer(client->adapter, msgs, ARRAY_SIZE(msgs)); in imx219_read_reg()
602 return -EIO; in imx219_read_reg()
612 struct i2c_client *client = v4l2_get_subdevdata(&imx219->sd); in imx219_write_reg()
616 return -EINVAL; in imx219_write_reg()
619 put_unaligned_be32(val << (8 * (4 - len)), buf + 2); in imx219_write_reg()
621 return -EIO; in imx219_write_reg()
630 struct i2c_client *client = v4l2_get_subdevdata(&imx219->sd); in imx219_write_regs()
637 dev_err_ratelimited(&client->dev, in imx219_write_regs()
653 lockdep_assert_held(&imx219->mutex); in imx219_get_format_code()
662 i = (i & ~3) | (imx219->vflip->val ? 2 : 0) | in imx219_get_format_code()
663 (imx219->hflip->val ? 1 : 0); in imx219_get_format_code()
672 fmt = &imx219->fmt; in imx219_set_default_format()
673 fmt->code = MEDIA_BUS_FMT_SRGGB10_1X10; in imx219_set_default_format()
674 fmt->colorspace = V4L2_COLORSPACE_SRGB; in imx219_set_default_format()
675 fmt->ycbcr_enc = V4L2_MAP_YCBCR_ENC_DEFAULT(fmt->colorspace); in imx219_set_default_format()
676 fmt->quantization = V4L2_MAP_QUANTIZATION_DEFAULT(true, in imx219_set_default_format()
677 fmt->colorspace, in imx219_set_default_format()
678 fmt->ycbcr_enc); in imx219_set_default_format()
679 fmt->xfer_func = V4L2_MAP_XFER_FUNC_DEFAULT(fmt->colorspace); in imx219_set_default_format()
680 fmt->width = supported_modes[0].width; in imx219_set_default_format()
681 fmt->height = supported_modes[0].height; in imx219_set_default_format()
682 fmt->field = V4L2_FIELD_NONE; in imx219_set_default_format()
689 v4l2_subdev_get_try_format(sd, fh->pad, 0); in imx219_open()
692 mutex_lock(&imx219->mutex); in imx219_open()
695 try_fmt->width = supported_modes[0].width; in imx219_open()
696 try_fmt->height = supported_modes[0].height; in imx219_open()
697 try_fmt->code = imx219_get_format_code(imx219, in imx219_open()
699 try_fmt->field = V4L2_FIELD_NONE; in imx219_open()
702 try_crop = v4l2_subdev_get_try_crop(sd, fh->pad, 0); in imx219_open()
703 try_crop->top = IMX219_PIXEL_ARRAY_TOP; in imx219_open()
704 try_crop->left = IMX219_PIXEL_ARRAY_LEFT; in imx219_open()
705 try_crop->width = IMX219_PIXEL_ARRAY_WIDTH; in imx219_open()
706 try_crop->height = IMX219_PIXEL_ARRAY_HEIGHT; in imx219_open()
708 mutex_unlock(&imx219->mutex); in imx219_open()
716 container_of(ctrl->handler, struct imx219, ctrl_handler); in imx219_set_ctrl()
717 struct i2c_client *client = v4l2_get_subdevdata(&imx219->sd); in imx219_set_ctrl()
720 if (ctrl->id == V4L2_CID_VBLANK) { in imx219_set_ctrl()
724 exposure_max = imx219->mode->height + ctrl->val - 4; in imx219_set_ctrl()
727 __v4l2_ctrl_modify_range(imx219->exposure, in imx219_set_ctrl()
728 imx219->exposure->minimum, in imx219_set_ctrl()
729 exposure_max, imx219->exposure->step, in imx219_set_ctrl()
737 if (pm_runtime_get_if_in_use(&client->dev) == 0) in imx219_set_ctrl()
740 switch (ctrl->id) { in imx219_set_ctrl()
743 IMX219_REG_VALUE_08BIT, ctrl->val); in imx219_set_ctrl()
747 IMX219_REG_VALUE_16BIT, ctrl->val); in imx219_set_ctrl()
751 IMX219_REG_VALUE_16BIT, ctrl->val); in imx219_set_ctrl()
756 imx219_test_pattern_val[ctrl->val]); in imx219_set_ctrl()
761 imx219->hflip->val | in imx219_set_ctrl()
762 imx219->vflip->val << 1); in imx219_set_ctrl()
767 imx219->mode->height + ctrl->val); in imx219_set_ctrl()
771 IMX219_REG_VALUE_16BIT, ctrl->val); in imx219_set_ctrl()
775 IMX219_REG_VALUE_16BIT, ctrl->val); in imx219_set_ctrl()
779 IMX219_REG_VALUE_16BIT, ctrl->val); in imx219_set_ctrl()
783 IMX219_REG_VALUE_16BIT, ctrl->val); in imx219_set_ctrl()
786 dev_info(&client->dev, in imx219_set_ctrl()
788 ctrl->id, ctrl->val); in imx219_set_ctrl()
789 ret = -EINVAL; in imx219_set_ctrl()
793 pm_runtime_put(&client->dev); in imx219_set_ctrl()
808 if (code->index >= (ARRAY_SIZE(codes) / 4)) in imx219_enum_mbus_code()
809 return -EINVAL; in imx219_enum_mbus_code()
811 code->code = imx219_get_format_code(imx219, codes[code->index * 4]); in imx219_enum_mbus_code()
822 if (fse->index >= ARRAY_SIZE(supported_modes)) in imx219_enum_frame_size()
823 return -EINVAL; in imx219_enum_frame_size()
825 if (fse->code != imx219_get_format_code(imx219, fse->code)) in imx219_enum_frame_size()
826 return -EINVAL; in imx219_enum_frame_size()
828 fse->min_width = supported_modes[fse->index].width; in imx219_enum_frame_size()
829 fse->max_width = fse->min_width; in imx219_enum_frame_size()
830 fse->min_height = supported_modes[fse->index].height; in imx219_enum_frame_size()
831 fse->max_height = fse->min_height; in imx219_enum_frame_size()
838 fmt->colorspace = V4L2_COLORSPACE_SRGB; in imx219_reset_colorspace()
839 fmt->ycbcr_enc = V4L2_MAP_YCBCR_ENC_DEFAULT(fmt->colorspace); in imx219_reset_colorspace()
840 fmt->quantization = V4L2_MAP_QUANTIZATION_DEFAULT(true, in imx219_reset_colorspace()
841 fmt->colorspace, in imx219_reset_colorspace()
842 fmt->ycbcr_enc); in imx219_reset_colorspace()
843 fmt->xfer_func = V4L2_MAP_XFER_FUNC_DEFAULT(fmt->colorspace); in imx219_reset_colorspace()
850 fmt->format.width = mode->width; in imx219_update_pad_format()
851 fmt->format.height = mode->height; in imx219_update_pad_format()
852 fmt->format.field = V4L2_FIELD_NONE; in imx219_update_pad_format()
853 imx219_reset_colorspace(&fmt->format); in imx219_update_pad_format()
860 if (fmt->which == V4L2_SUBDEV_FORMAT_TRY) { in __imx219_get_pad_format()
862 v4l2_subdev_get_try_format(&imx219->sd, cfg, fmt->pad); in __imx219_get_pad_format()
864 try_fmt->code = imx219_get_format_code(imx219, try_fmt->code); in __imx219_get_pad_format()
865 fmt->format = *try_fmt; in __imx219_get_pad_format()
867 imx219_update_pad_format(imx219, imx219->mode, fmt); in __imx219_get_pad_format()
868 fmt->format.code = imx219_get_format_code(imx219, in __imx219_get_pad_format()
869 imx219->fmt.code); in __imx219_get_pad_format()
882 mutex_lock(&imx219->mutex); in imx219_get_pad_format()
884 mutex_unlock(&imx219->mutex); in imx219_get_pad_format()
899 mutex_lock(&imx219->mutex); in imx219_set_pad_format()
902 if (codes[i] == fmt->format.code) in imx219_set_pad_format()
908 fmt->format.code = imx219_get_format_code(imx219, codes[i]); in imx219_set_pad_format()
913 fmt->format.width, fmt->format.height); in imx219_set_pad_format()
915 if (fmt->which == V4L2_SUBDEV_FORMAT_TRY) { in imx219_set_pad_format()
916 framefmt = v4l2_subdev_get_try_format(sd, cfg, fmt->pad); in imx219_set_pad_format()
917 *framefmt = fmt->format; in imx219_set_pad_format()
918 } else if (imx219->mode != mode || in imx219_set_pad_format()
919 imx219->fmt.code != fmt->format.code) { in imx219_set_pad_format()
920 imx219->fmt = fmt->format; in imx219_set_pad_format()
921 imx219->mode = mode; in imx219_set_pad_format()
923 __v4l2_ctrl_modify_range(imx219->vblank, IMX219_VBLANK_MIN, in imx219_set_pad_format()
924 IMX219_VTS_MAX - mode->height, 1, in imx219_set_pad_format()
925 mode->vts_def - mode->height); in imx219_set_pad_format()
926 __v4l2_ctrl_s_ctrl(imx219->vblank, in imx219_set_pad_format()
927 mode->vts_def - mode->height); in imx219_set_pad_format()
929 exposure_max = mode->vts_def - 4; in imx219_set_pad_format()
932 __v4l2_ctrl_modify_range(imx219->exposure, in imx219_set_pad_format()
933 imx219->exposure->minimum, in imx219_set_pad_format()
934 exposure_max, imx219->exposure->step, in imx219_set_pad_format()
938 * depends on mode->width only, and is not changeble in any in imx219_set_pad_format()
941 hblank = IMX219_PPL_DEFAULT - mode->width; in imx219_set_pad_format()
942 __v4l2_ctrl_modify_range(imx219->hblank, hblank, hblank, 1, in imx219_set_pad_format()
946 mutex_unlock(&imx219->mutex); in imx219_set_pad_format()
953 switch (imx219->fmt.code) { in imx219_set_framefmt()
969 return -EINVAL; in imx219_set_framefmt()
978 return v4l2_subdev_get_try_crop(&imx219->sd, cfg, pad); in __imx219_get_pad_crop()
980 return &imx219->mode->crop; in __imx219_get_pad_crop()
990 switch (sel->target) { in imx219_get_selection()
994 mutex_lock(&imx219->mutex); in imx219_get_selection()
995 sel->r = *__imx219_get_pad_crop(imx219, cfg, sel->pad, in imx219_get_selection()
996 sel->which); in imx219_get_selection()
997 mutex_unlock(&imx219->mutex); in imx219_get_selection()
1003 sel->r.top = 0; in imx219_get_selection()
1004 sel->r.left = 0; in imx219_get_selection()
1005 sel->r.width = IMX219_NATIVE_WIDTH; in imx219_get_selection()
1006 sel->r.height = IMX219_NATIVE_HEIGHT; in imx219_get_selection()
1011 sel->r.top = IMX219_PIXEL_ARRAY_TOP; in imx219_get_selection()
1012 sel->r.left = IMX219_PIXEL_ARRAY_LEFT; in imx219_get_selection()
1013 sel->r.width = IMX219_PIXEL_ARRAY_WIDTH; in imx219_get_selection()
1014 sel->r.height = IMX219_PIXEL_ARRAY_HEIGHT; in imx219_get_selection()
1019 return -EINVAL; in imx219_get_selection()
1024 struct i2c_client *client = v4l2_get_subdevdata(&imx219->sd); in imx219_start_streaming()
1029 reg_list = &imx219->mode->reg_list; in imx219_start_streaming()
1030 ret = imx219_write_regs(imx219, reg_list->regs, reg_list->num_of_regs); in imx219_start_streaming()
1032 dev_err(&client->dev, "%s failed to set mode\n", __func__); in imx219_start_streaming()
1038 dev_err(&client->dev, "%s failed to set frame format: %d\n", in imx219_start_streaming()
1044 ret = __v4l2_ctrl_handler_setup(imx219->sd.ctrl_handler); in imx219_start_streaming()
1055 struct i2c_client *client = v4l2_get_subdevdata(&imx219->sd); in imx219_stop_streaming()
1062 dev_err(&client->dev, "%s failed to set stream\n", __func__); in imx219_stop_streaming()
1071 mutex_lock(&imx219->mutex); in imx219_set_stream()
1072 if (imx219->streaming == enable) { in imx219_set_stream()
1073 mutex_unlock(&imx219->mutex); in imx219_set_stream()
1078 ret = pm_runtime_get_sync(&client->dev); in imx219_set_stream()
1080 pm_runtime_put_noidle(&client->dev); in imx219_set_stream()
1093 pm_runtime_put(&client->dev); in imx219_set_stream()
1096 imx219->streaming = enable; in imx219_set_stream()
1099 __v4l2_ctrl_grab(imx219->vflip, enable); in imx219_set_stream()
1100 __v4l2_ctrl_grab(imx219->hflip, enable); in imx219_set_stream()
1102 mutex_unlock(&imx219->mutex); in imx219_set_stream()
1107 pm_runtime_put(&client->dev); in imx219_set_stream()
1109 mutex_unlock(&imx219->mutex); in imx219_set_stream()
1123 imx219->supplies); in imx219_power_on()
1125 dev_err(&client->dev, "%s: failed to enable regulators\n", in imx219_power_on()
1130 ret = clk_prepare_enable(imx219->xclk); in imx219_power_on()
1132 dev_err(&client->dev, "%s: failed to enable clock\n", in imx219_power_on()
1137 gpiod_set_value_cansleep(imx219->reset_gpio, 1); in imx219_power_on()
1144 regulator_bulk_disable(IMX219_NUM_SUPPLIES, imx219->supplies); in imx219_power_on()
1155 gpiod_set_value_cansleep(imx219->reset_gpio, 0); in imx219_power_off()
1156 regulator_bulk_disable(IMX219_NUM_SUPPLIES, imx219->supplies); in imx219_power_off()
1157 clk_disable_unprepare(imx219->xclk); in imx219_power_off()
1168 if (imx219->streaming) in imx219_suspend()
1181 if (imx219->streaming) { in imx219_resume()
1191 imx219->streaming = false; in imx219_resume()
1198 struct i2c_client *client = v4l2_get_subdevdata(&imx219->sd); in imx219_get_regulators()
1202 imx219->supplies[i].supply = imx219_supply_name[i]; in imx219_get_regulators()
1204 return devm_regulator_bulk_get(&client->dev, in imx219_get_regulators()
1206 imx219->supplies); in imx219_get_regulators()
1212 struct i2c_client *client = v4l2_get_subdevdata(&imx219->sd); in imx219_identify_module()
1219 dev_err(&client->dev, "failed to read chip id %x\n", in imx219_identify_module()
1225 dev_err(&client->dev, "chip id mismatch: %x!=%x\n", in imx219_identify_module()
1227 return -EIO; in imx219_identify_module()
1263 struct i2c_client *client = v4l2_get_subdevdata(&imx219->sd); in imx219_init_controls()
1265 unsigned int height = imx219->mode->height; in imx219_init_controls()
1270 ctrl_hdlr = &imx219->ctrl_handler; in imx219_init_controls()
1275 mutex_init(&imx219->mutex); in imx219_init_controls()
1276 ctrl_hdlr->lock = &imx219->mutex; in imx219_init_controls()
1279 imx219->pixel_rate = v4l2_ctrl_new_std(ctrl_hdlr, &imx219_ctrl_ops, in imx219_init_controls()
1286 imx219->vblank = v4l2_ctrl_new_std(ctrl_hdlr, &imx219_ctrl_ops, in imx219_init_controls()
1288 IMX219_VTS_MAX - height, 1, in imx219_init_controls()
1289 imx219->mode->vts_def - height); in imx219_init_controls()
1290 hblank = IMX219_PPL_DEFAULT - imx219->mode->width; in imx219_init_controls()
1291 imx219->hblank = v4l2_ctrl_new_std(ctrl_hdlr, &imx219_ctrl_ops, in imx219_init_controls()
1294 if (imx219->hblank) in imx219_init_controls()
1295 imx219->hblank->flags |= V4L2_CTRL_FLAG_READ_ONLY; in imx219_init_controls()
1296 exposure_max = imx219->mode->vts_def - 4; in imx219_init_controls()
1299 imx219->exposure = v4l2_ctrl_new_std(ctrl_hdlr, &imx219_ctrl_ops, in imx219_init_controls()
1313 imx219->hflip = v4l2_ctrl_new_std(ctrl_hdlr, &imx219_ctrl_ops, in imx219_init_controls()
1315 if (imx219->hflip) in imx219_init_controls()
1316 imx219->hflip->flags |= V4L2_CTRL_FLAG_MODIFY_LAYOUT; in imx219_init_controls()
1318 imx219->vflip = v4l2_ctrl_new_std(ctrl_hdlr, &imx219_ctrl_ops, in imx219_init_controls()
1320 if (imx219->vflip) in imx219_init_controls()
1321 imx219->vflip->flags |= V4L2_CTRL_FLAG_MODIFY_LAYOUT; in imx219_init_controls()
1325 ARRAY_SIZE(imx219_test_pattern_menu) - 1, in imx219_init_controls()
1343 if (ctrl_hdlr->error) { in imx219_init_controls()
1344 ret = ctrl_hdlr->error; in imx219_init_controls()
1345 dev_err(&client->dev, "%s control init failed (%d)\n", in imx219_init_controls()
1350 ret = v4l2_fwnode_device_parse(&client->dev, &props); in imx219_init_controls()
1359 imx219->sd.ctrl_handler = ctrl_hdlr; in imx219_init_controls()
1365 mutex_destroy(&imx219->mutex); in imx219_init_controls()
1372 v4l2_ctrl_handler_free(imx219->sd.ctrl_handler); in imx219_free_controls()
1373 mutex_destroy(&imx219->mutex); in imx219_free_controls()
1382 int ret = -EINVAL; in imx219_check_hwcfg()
1387 return -EINVAL; in imx219_check_hwcfg()
1403 dev_err(dev, "link-frequency property not found in DT\n"); in imx219_check_hwcfg()
1425 struct device *dev = &client->dev; in imx219_probe()
1429 imx219 = devm_kzalloc(&client->dev, sizeof(*imx219), GFP_KERNEL); in imx219_probe()
1431 return -ENOMEM; in imx219_probe()
1433 v4l2_i2c_subdev_init(&imx219->sd, client, &imx219_subdev_ops); in imx219_probe()
1437 return -EINVAL; in imx219_probe()
1440 imx219->xclk = devm_clk_get(dev, NULL); in imx219_probe()
1441 if (IS_ERR(imx219->xclk)) { in imx219_probe()
1443 return PTR_ERR(imx219->xclk); in imx219_probe()
1446 imx219->xclk_freq = clk_get_rate(imx219->xclk); in imx219_probe()
1447 if (imx219->xclk_freq != IMX219_XCLK_FREQ) { in imx219_probe()
1449 imx219->xclk_freq); in imx219_probe()
1450 return -EINVAL; in imx219_probe()
1460 imx219->reset_gpio = devm_gpiod_get_optional(dev, "reset", in imx219_probe()
1476 imx219->mode = &supported_modes[0]; in imx219_probe()
1478 /* sensor doesn't enter LP-11 state upon power up until and unless in imx219_probe()
1480 * streaming -> standby in imx219_probe()
1500 imx219->sd.internal_ops = &imx219_internal_ops; in imx219_probe()
1501 imx219->sd.flags |= V4L2_SUBDEV_FL_HAS_DEVNODE; in imx219_probe()
1502 imx219->sd.entity.function = MEDIA_ENT_F_CAM_SENSOR; in imx219_probe()
1505 imx219->pad.flags = MEDIA_PAD_FL_SOURCE; in imx219_probe()
1510 ret = media_entity_pads_init(&imx219->sd.entity, 1, &imx219->pad); in imx219_probe()
1516 ret = v4l2_async_register_subdev_sensor_common(&imx219->sd); in imx219_probe()
1518 dev_err(dev, "failed to register sensor sub-device: %d\n", ret); in imx219_probe()
1530 media_entity_cleanup(&imx219->sd.entity); in imx219_probe()
1547 media_entity_cleanup(&sd->entity); in imx219_remove()
1550 pm_runtime_disable(&client->dev); in imx219_remove()
1551 if (!pm_runtime_status_suspended(&client->dev)) in imx219_remove()
1552 imx219_power_off(&client->dev); in imx219_remove()
1553 pm_runtime_set_suspended(&client->dev); in imx219_remove()