Lines Matching +full:vddl +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 */
416 "VANA", /* Analog (2.8V) supply */
417 "VDIG", /* Digital Core (1.8V) supply */
418 "VDDL", /* IF (1.2V) supply */
427 * - no flip
428 * - h flip
429 * - v flip
430 * - h&v flips
445 * Initialisation delay between XCLR low->high and the moment when the sensor
458 * This start-up time can be optimized a bit more, if we start the writes
463 * This delay doesn't account for the power supply startup time. If needed,
465 * case of DT for regulator-fixed one should define the startup-delay-us
582 struct i2c_client *client = v4l2_get_subdevdata(&imx219->sd); in imx219_read_reg()
589 return -EINVAL; in imx219_read_reg()
592 msgs[0].addr = client->addr; in imx219_read_reg()
598 msgs[1].addr = client->addr; in imx219_read_reg()
601 msgs[1].buf = &data_buf[4 - len]; in imx219_read_reg()
603 ret = i2c_transfer(client->adapter, msgs, ARRAY_SIZE(msgs)); in imx219_read_reg()
605 return -EIO; in imx219_read_reg()
615 struct i2c_client *client = v4l2_get_subdevdata(&imx219->sd); in imx219_write_reg()
619 return -EINVAL; in imx219_write_reg()
622 put_unaligned_be32(val << (8 * (4 - len)), buf + 2); in imx219_write_reg()
624 return -EIO; in imx219_write_reg()
633 struct i2c_client *client = v4l2_get_subdevdata(&imx219->sd); in imx219_write_regs()
640 dev_err_ratelimited(&client->dev, in imx219_write_regs()
656 lockdep_assert_held(&imx219->mutex); in imx219_get_format_code()
665 i = (i & ~3) | (imx219->vflip->val ? 2 : 0) | in imx219_get_format_code()
666 (imx219->hflip->val ? 1 : 0); in imx219_get_format_code()
675 fmt = &imx219->fmt; in imx219_set_default_format()
676 fmt->code = MEDIA_BUS_FMT_SRGGB10_1X10; in imx219_set_default_format()
677 fmt->colorspace = V4L2_COLORSPACE_SRGB; in imx219_set_default_format()
678 fmt->ycbcr_enc = V4L2_MAP_YCBCR_ENC_DEFAULT(fmt->colorspace); in imx219_set_default_format()
679 fmt->quantization = V4L2_MAP_QUANTIZATION_DEFAULT(true, in imx219_set_default_format()
680 fmt->colorspace, in imx219_set_default_format()
681 fmt->ycbcr_enc); in imx219_set_default_format()
682 fmt->xfer_func = V4L2_MAP_XFER_FUNC_DEFAULT(fmt->colorspace); in imx219_set_default_format()
683 fmt->width = supported_modes[0].width; in imx219_set_default_format()
684 fmt->height = supported_modes[0].height; in imx219_set_default_format()
685 fmt->field = V4L2_FIELD_NONE; in imx219_set_default_format()
692 v4l2_subdev_get_try_format(sd, fh->state, 0); in imx219_open()
695 mutex_lock(&imx219->mutex); in imx219_open()
698 try_fmt->width = supported_modes[0].width; in imx219_open()
699 try_fmt->height = supported_modes[0].height; in imx219_open()
700 try_fmt->code = imx219_get_format_code(imx219, in imx219_open()
702 try_fmt->field = V4L2_FIELD_NONE; in imx219_open()
705 try_crop = v4l2_subdev_get_try_crop(sd, fh->state, 0); in imx219_open()
706 try_crop->top = IMX219_PIXEL_ARRAY_TOP; in imx219_open()
707 try_crop->left = IMX219_PIXEL_ARRAY_LEFT; in imx219_open()
708 try_crop->width = IMX219_PIXEL_ARRAY_WIDTH; in imx219_open()
709 try_crop->height = IMX219_PIXEL_ARRAY_HEIGHT; in imx219_open()
711 mutex_unlock(&imx219->mutex); in imx219_open()
719 container_of(ctrl->handler, struct imx219, ctrl_handler); in imx219_set_ctrl()
720 struct i2c_client *client = v4l2_get_subdevdata(&imx219->sd); in imx219_set_ctrl()
723 if (ctrl->id == V4L2_CID_VBLANK) { in imx219_set_ctrl()
727 exposure_max = imx219->mode->height + ctrl->val - 4; in imx219_set_ctrl()
730 __v4l2_ctrl_modify_range(imx219->exposure, in imx219_set_ctrl()
731 imx219->exposure->minimum, in imx219_set_ctrl()
732 exposure_max, imx219->exposure->step, in imx219_set_ctrl()
740 if (pm_runtime_get_if_in_use(&client->dev) == 0) in imx219_set_ctrl()
743 switch (ctrl->id) { in imx219_set_ctrl()
746 IMX219_REG_VALUE_08BIT, ctrl->val); in imx219_set_ctrl()
750 IMX219_REG_VALUE_16BIT, ctrl->val); in imx219_set_ctrl()
754 IMX219_REG_VALUE_16BIT, ctrl->val); in imx219_set_ctrl()
759 imx219_test_pattern_val[ctrl->val]); in imx219_set_ctrl()
764 imx219->hflip->val | in imx219_set_ctrl()
765 imx219->vflip->val << 1); in imx219_set_ctrl()
770 imx219->mode->height + ctrl->val); in imx219_set_ctrl()
774 IMX219_REG_VALUE_16BIT, ctrl->val); in imx219_set_ctrl()
778 IMX219_REG_VALUE_16BIT, ctrl->val); in imx219_set_ctrl()
782 IMX219_REG_VALUE_16BIT, ctrl->val); in imx219_set_ctrl()
786 IMX219_REG_VALUE_16BIT, ctrl->val); in imx219_set_ctrl()
789 dev_info(&client->dev, in imx219_set_ctrl()
791 ctrl->id, ctrl->val); in imx219_set_ctrl()
792 ret = -EINVAL; in imx219_set_ctrl()
796 pm_runtime_put(&client->dev); in imx219_set_ctrl()
811 if (code->index >= (ARRAY_SIZE(codes) / 4)) in imx219_enum_mbus_code()
812 return -EINVAL; in imx219_enum_mbus_code()
814 mutex_lock(&imx219->mutex); in imx219_enum_mbus_code()
815 code->code = imx219_get_format_code(imx219, codes[code->index * 4]); in imx219_enum_mbus_code()
816 mutex_unlock(&imx219->mutex); in imx219_enum_mbus_code()
828 if (fse->index >= ARRAY_SIZE(supported_modes)) in imx219_enum_frame_size()
829 return -EINVAL; in imx219_enum_frame_size()
831 mutex_lock(&imx219->mutex); in imx219_enum_frame_size()
832 code = imx219_get_format_code(imx219, fse->code); in imx219_enum_frame_size()
833 mutex_unlock(&imx219->mutex); in imx219_enum_frame_size()
834 if (fse->code != code) in imx219_enum_frame_size()
835 return -EINVAL; in imx219_enum_frame_size()
837 fse->min_width = supported_modes[fse->index].width; in imx219_enum_frame_size()
838 fse->max_width = fse->min_width; in imx219_enum_frame_size()
839 fse->min_height = supported_modes[fse->index].height; in imx219_enum_frame_size()
840 fse->max_height = fse->min_height; in imx219_enum_frame_size()
847 fmt->colorspace = V4L2_COLORSPACE_SRGB; in imx219_reset_colorspace()
848 fmt->ycbcr_enc = V4L2_MAP_YCBCR_ENC_DEFAULT(fmt->colorspace); in imx219_reset_colorspace()
849 fmt->quantization = V4L2_MAP_QUANTIZATION_DEFAULT(true, in imx219_reset_colorspace()
850 fmt->colorspace, in imx219_reset_colorspace()
851 fmt->ycbcr_enc); in imx219_reset_colorspace()
852 fmt->xfer_func = V4L2_MAP_XFER_FUNC_DEFAULT(fmt->colorspace); in imx219_reset_colorspace()
859 fmt->format.width = mode->width; in imx219_update_pad_format()
860 fmt->format.height = mode->height; in imx219_update_pad_format()
861 fmt->format.field = V4L2_FIELD_NONE; in imx219_update_pad_format()
862 imx219_reset_colorspace(&fmt->format); in imx219_update_pad_format()
869 if (fmt->which == V4L2_SUBDEV_FORMAT_TRY) { in __imx219_get_pad_format()
871 v4l2_subdev_get_try_format(&imx219->sd, sd_state, in __imx219_get_pad_format()
872 fmt->pad); in __imx219_get_pad_format()
874 try_fmt->code = imx219_get_format_code(imx219, try_fmt->code); in __imx219_get_pad_format()
875 fmt->format = *try_fmt; in __imx219_get_pad_format()
877 imx219_update_pad_format(imx219, imx219->mode, fmt); in __imx219_get_pad_format()
878 fmt->format.code = imx219_get_format_code(imx219, in __imx219_get_pad_format()
879 imx219->fmt.code); in __imx219_get_pad_format()
892 mutex_lock(&imx219->mutex); in imx219_get_pad_format()
894 mutex_unlock(&imx219->mutex); in imx219_get_pad_format()
909 mutex_lock(&imx219->mutex); in imx219_set_pad_format()
912 if (codes[i] == fmt->format.code) in imx219_set_pad_format()
918 fmt->format.code = imx219_get_format_code(imx219, codes[i]); in imx219_set_pad_format()
923 fmt->format.width, fmt->format.height); in imx219_set_pad_format()
925 if (fmt->which == V4L2_SUBDEV_FORMAT_TRY) { in imx219_set_pad_format()
926 framefmt = v4l2_subdev_get_try_format(sd, sd_state, fmt->pad); in imx219_set_pad_format()
927 *framefmt = fmt->format; in imx219_set_pad_format()
928 } else if (imx219->mode != mode || in imx219_set_pad_format()
929 imx219->fmt.code != fmt->format.code) { in imx219_set_pad_format()
930 imx219->fmt = fmt->format; in imx219_set_pad_format()
931 imx219->mode = mode; in imx219_set_pad_format()
933 __v4l2_ctrl_modify_range(imx219->vblank, IMX219_VBLANK_MIN, in imx219_set_pad_format()
934 IMX219_VTS_MAX - mode->height, 1, in imx219_set_pad_format()
935 mode->vts_def - mode->height); in imx219_set_pad_format()
936 __v4l2_ctrl_s_ctrl(imx219->vblank, in imx219_set_pad_format()
937 mode->vts_def - mode->height); in imx219_set_pad_format()
939 exposure_max = mode->vts_def - 4; in imx219_set_pad_format()
942 __v4l2_ctrl_modify_range(imx219->exposure, in imx219_set_pad_format()
943 imx219->exposure->minimum, in imx219_set_pad_format()
944 exposure_max, imx219->exposure->step, in imx219_set_pad_format()
948 * depends on mode->width only, and is not changeble in any in imx219_set_pad_format()
951 hblank = IMX219_PPL_DEFAULT - mode->width; in imx219_set_pad_format()
952 __v4l2_ctrl_modify_range(imx219->hblank, hblank, hblank, 1, in imx219_set_pad_format()
956 mutex_unlock(&imx219->mutex); in imx219_set_pad_format()
963 switch (imx219->fmt.code) { in imx219_set_framefmt()
979 return -EINVAL; in imx219_set_framefmt()
989 return v4l2_subdev_get_try_crop(&imx219->sd, sd_state, pad); in __imx219_get_pad_crop()
991 return &imx219->mode->crop; in __imx219_get_pad_crop()
1001 switch (sel->target) { in imx219_get_selection()
1005 mutex_lock(&imx219->mutex); in imx219_get_selection()
1006 sel->r = *__imx219_get_pad_crop(imx219, sd_state, sel->pad, in imx219_get_selection()
1007 sel->which); in imx219_get_selection()
1008 mutex_unlock(&imx219->mutex); in imx219_get_selection()
1014 sel->r.top = 0; in imx219_get_selection()
1015 sel->r.left = 0; in imx219_get_selection()
1016 sel->r.width = IMX219_NATIVE_WIDTH; in imx219_get_selection()
1017 sel->r.height = IMX219_NATIVE_HEIGHT; in imx219_get_selection()
1023 sel->r.top = IMX219_PIXEL_ARRAY_TOP; in imx219_get_selection()
1024 sel->r.left = IMX219_PIXEL_ARRAY_LEFT; in imx219_get_selection()
1025 sel->r.width = IMX219_PIXEL_ARRAY_WIDTH; in imx219_get_selection()
1026 sel->r.height = IMX219_PIXEL_ARRAY_HEIGHT; in imx219_get_selection()
1031 return -EINVAL; in imx219_get_selection()
1036 struct i2c_client *client = v4l2_get_subdevdata(&imx219->sd); in imx219_start_streaming()
1040 ret = pm_runtime_resume_and_get(&client->dev); in imx219_start_streaming()
1045 reg_list = &imx219->mode->reg_list; in imx219_start_streaming()
1046 ret = imx219_write_regs(imx219, reg_list->regs, reg_list->num_of_regs); in imx219_start_streaming()
1048 dev_err(&client->dev, "%s failed to set mode\n", __func__); in imx219_start_streaming()
1054 dev_err(&client->dev, "%s failed to set frame format: %d\n", in imx219_start_streaming()
1060 ret = __v4l2_ctrl_handler_setup(imx219->sd.ctrl_handler); in imx219_start_streaming()
1071 __v4l2_ctrl_grab(imx219->vflip, true); in imx219_start_streaming()
1072 __v4l2_ctrl_grab(imx219->hflip, true); in imx219_start_streaming()
1077 pm_runtime_put(&client->dev); in imx219_start_streaming()
1083 struct i2c_client *client = v4l2_get_subdevdata(&imx219->sd); in imx219_stop_streaming()
1090 dev_err(&client->dev, "%s failed to set stream\n", __func__); in imx219_stop_streaming()
1092 __v4l2_ctrl_grab(imx219->vflip, false); in imx219_stop_streaming()
1093 __v4l2_ctrl_grab(imx219->hflip, false); in imx219_stop_streaming()
1095 pm_runtime_put(&client->dev); in imx219_stop_streaming()
1103 mutex_lock(&imx219->mutex); in imx219_set_stream()
1104 if (imx219->streaming == enable) { in imx219_set_stream()
1105 mutex_unlock(&imx219->mutex); in imx219_set_stream()
1121 imx219->streaming = enable; in imx219_set_stream()
1123 mutex_unlock(&imx219->mutex); in imx219_set_stream()
1128 mutex_unlock(&imx219->mutex); in imx219_set_stream()
1141 imx219->supplies); in imx219_power_on()
1148 ret = clk_prepare_enable(imx219->xclk); in imx219_power_on()
1155 gpiod_set_value_cansleep(imx219->reset_gpio, 1); in imx219_power_on()
1162 regulator_bulk_disable(IMX219_NUM_SUPPLIES, imx219->supplies); in imx219_power_on()
1172 gpiod_set_value_cansleep(imx219->reset_gpio, 0); in imx219_power_off()
1173 regulator_bulk_disable(IMX219_NUM_SUPPLIES, imx219->supplies); in imx219_power_off()
1174 clk_disable_unprepare(imx219->xclk); in imx219_power_off()
1184 if (imx219->streaming) in imx219_suspend()
1196 if (imx219->streaming) { in imx219_resume()
1206 imx219->streaming = false; in imx219_resume()
1213 struct i2c_client *client = v4l2_get_subdevdata(&imx219->sd); in imx219_get_regulators()
1217 imx219->supplies[i].supply = imx219_supply_name[i]; in imx219_get_regulators()
1219 return devm_regulator_bulk_get(&client->dev, in imx219_get_regulators()
1221 imx219->supplies); in imx219_get_regulators()
1227 struct i2c_client *client = v4l2_get_subdevdata(&imx219->sd); in imx219_identify_module()
1234 dev_err(&client->dev, "failed to read chip id %x\n", in imx219_identify_module()
1240 dev_err(&client->dev, "chip id mismatch: %x!=%x\n", in imx219_identify_module()
1242 return -EIO; in imx219_identify_module()
1278 struct i2c_client *client = v4l2_get_subdevdata(&imx219->sd); in imx219_init_controls()
1280 unsigned int height = imx219->mode->height; in imx219_init_controls()
1285 ctrl_hdlr = &imx219->ctrl_handler; in imx219_init_controls()
1290 mutex_init(&imx219->mutex); in imx219_init_controls()
1291 ctrl_hdlr->lock = &imx219->mutex; in imx219_init_controls()
1294 imx219->pixel_rate = v4l2_ctrl_new_std(ctrl_hdlr, &imx219_ctrl_ops, in imx219_init_controls()
1300 imx219->link_freq = in imx219_init_controls()
1303 ARRAY_SIZE(imx219_link_freq_menu) - 1, 0, in imx219_init_controls()
1305 if (imx219->link_freq) in imx219_init_controls()
1306 imx219->link_freq->flags |= V4L2_CTRL_FLAG_READ_ONLY; in imx219_init_controls()
1309 imx219->vblank = v4l2_ctrl_new_std(ctrl_hdlr, &imx219_ctrl_ops, in imx219_init_controls()
1311 IMX219_VTS_MAX - height, 1, in imx219_init_controls()
1312 imx219->mode->vts_def - height); in imx219_init_controls()
1313 hblank = IMX219_PPL_DEFAULT - imx219->mode->width; in imx219_init_controls()
1314 imx219->hblank = v4l2_ctrl_new_std(ctrl_hdlr, &imx219_ctrl_ops, in imx219_init_controls()
1317 if (imx219->hblank) in imx219_init_controls()
1318 imx219->hblank->flags |= V4L2_CTRL_FLAG_READ_ONLY; in imx219_init_controls()
1319 exposure_max = imx219->mode->vts_def - 4; in imx219_init_controls()
1322 imx219->exposure = v4l2_ctrl_new_std(ctrl_hdlr, &imx219_ctrl_ops, in imx219_init_controls()
1336 imx219->hflip = v4l2_ctrl_new_std(ctrl_hdlr, &imx219_ctrl_ops, in imx219_init_controls()
1338 if (imx219->hflip) in imx219_init_controls()
1339 imx219->hflip->flags |= V4L2_CTRL_FLAG_MODIFY_LAYOUT; in imx219_init_controls()
1341 imx219->vflip = v4l2_ctrl_new_std(ctrl_hdlr, &imx219_ctrl_ops, in imx219_init_controls()
1343 if (imx219->vflip) in imx219_init_controls()
1344 imx219->vflip->flags |= V4L2_CTRL_FLAG_MODIFY_LAYOUT; in imx219_init_controls()
1348 ARRAY_SIZE(imx219_test_pattern_menu) - 1, in imx219_init_controls()
1366 if (ctrl_hdlr->error) { in imx219_init_controls()
1367 ret = ctrl_hdlr->error; in imx219_init_controls()
1368 dev_err(&client->dev, "%s control init failed (%d)\n", in imx219_init_controls()
1373 ret = v4l2_fwnode_device_parse(&client->dev, &props); in imx219_init_controls()
1382 imx219->sd.ctrl_handler = ctrl_hdlr; in imx219_init_controls()
1388 mutex_destroy(&imx219->mutex); in imx219_init_controls()
1395 v4l2_ctrl_handler_free(imx219->sd.ctrl_handler); in imx219_free_controls()
1396 mutex_destroy(&imx219->mutex); in imx219_free_controls()
1405 int ret = -EINVAL; in imx219_check_hwcfg()
1410 return -EINVAL; in imx219_check_hwcfg()
1426 dev_err(dev, "link-frequency property not found in DT\n"); in imx219_check_hwcfg()
1448 struct device *dev = &client->dev; in imx219_probe()
1452 imx219 = devm_kzalloc(&client->dev, sizeof(*imx219), GFP_KERNEL); in imx219_probe()
1454 return -ENOMEM; in imx219_probe()
1456 v4l2_i2c_subdev_init(&imx219->sd, client, &imx219_subdev_ops); in imx219_probe()
1460 return -EINVAL; in imx219_probe()
1463 imx219->xclk = devm_clk_get(dev, NULL); in imx219_probe()
1464 if (IS_ERR(imx219->xclk)) { in imx219_probe()
1466 return PTR_ERR(imx219->xclk); in imx219_probe()
1469 imx219->xclk_freq = clk_get_rate(imx219->xclk); in imx219_probe()
1470 if (imx219->xclk_freq != IMX219_XCLK_FREQ) { in imx219_probe()
1472 imx219->xclk_freq); in imx219_probe()
1473 return -EINVAL; in imx219_probe()
1483 imx219->reset_gpio = devm_gpiod_get_optional(dev, "reset", in imx219_probe()
1499 imx219->mode = &supported_modes[0]; in imx219_probe()
1501 /* sensor doesn't enter LP-11 state upon power up until and unless in imx219_probe()
1503 * streaming -> standby in imx219_probe()
1523 imx219->sd.internal_ops = &imx219_internal_ops; in imx219_probe()
1524 imx219->sd.flags |= V4L2_SUBDEV_FL_HAS_DEVNODE | in imx219_probe()
1526 imx219->sd.entity.function = MEDIA_ENT_F_CAM_SENSOR; in imx219_probe()
1529 imx219->pad.flags = MEDIA_PAD_FL_SOURCE; in imx219_probe()
1534 ret = media_entity_pads_init(&imx219->sd.entity, 1, &imx219->pad); in imx219_probe()
1540 ret = v4l2_async_register_subdev_sensor(&imx219->sd); in imx219_probe()
1542 dev_err(dev, "failed to register sensor sub-device: %d\n", ret); in imx219_probe()
1554 media_entity_cleanup(&imx219->sd.entity); in imx219_probe()
1571 media_entity_cleanup(&sd->entity); in imx219_remove()
1574 pm_runtime_disable(&client->dev); in imx219_remove()
1575 if (!pm_runtime_status_suspended(&client->dev)) in imx219_remove()
1576 imx219_power_off(&client->dev); in imx219_remove()
1577 pm_runtime_set_suspended(&client->dev); in imx219_remove()