Lines Matching +full:vana +full:- +full:supply

1 // SPDX-License-Identifier: GPL-2.0
20 #include <media/mipi-csi2.h>
21 #include <media/v4l2-async.h>
22 #include <media/v4l2-ctrls.h>
23 #include <media/v4l2-device.h>
24 #include <media/v4l2-fwnode.h>
25 #include <media/v4l2-subdev.h>
209 "VANA",
465 * Freq range is [6Mhz-27Mhz] already checked. in compute_pll_parameters_by_freq()
466 * Output of divider should be in [6Mhz-12Mhz[. in compute_pll_parameters_by_freq()
484 return div64_u64((u64)sensor->data_rate_in_mbps * sensor->nb_of_lane, in get_pixel_rate()
485 get_bpp_by_code(sensor->fmt.code)); in get_pixel_rate()
495 return &container_of(ctrl->handler, struct vgxy61_dev, in ctrl_to_sd()
496 ctrl_handler)->sd; in ctrl_to_sd()
501 struct i2c_adapter *adapter = sensor->i2c_client->adapter; in get_chunk_size()
504 if (adapter->quirks && adapter->quirks->max_write_len) in get_chunk_size()
505 max_write_len = adapter->quirks->max_write_len - 2; in get_chunk_size()
515 struct i2c_client *client = sensor->i2c_client; in vgxy61_read_multiple()
522 return -EINVAL; in vgxy61_read_multiple()
526 msg[0].addr = client->addr; in vgxy61_read_multiple()
527 msg[0].flags = client->flags; in vgxy61_read_multiple()
531 msg[1].addr = client->addr; in vgxy61_read_multiple()
532 msg[1].flags = client->flags | I2C_M_RD; in vgxy61_read_multiple()
536 ret = i2c_transfer(client->adapter, msg, 2); in vgxy61_read_multiple()
538 dev_dbg(&client->dev, "%s: %x i2c_transfer, reg: %x => %d\n", in vgxy61_read_multiple()
539 __func__, client->addr, reg, ret); in vgxy61_read_multiple()
555 struct i2c_client *client = sensor->i2c_client; in vgxy61_write_multiple()
565 return -EINVAL; in vgxy61_write_multiple()
571 msg.addr = client->addr; in vgxy61_write_multiple()
572 msg.flags = client->flags; in vgxy61_write_multiple()
576 ret = i2c_transfer(client->adapter, &msg, 1); in vgxy61_write_multiple()
578 dev_dbg(&client->dev, "%s: i2c_transfer, reg: %x => %d\n", in vgxy61_write_multiple()
600 nb -= sz; in vgxy61_write_array()
644 unsigned int binning_scale = sensor->current_mode->crop.height / in vgxy61_check_bw()
645 sensor->current_mode->height; in vgxy61_check_bw()
646 u8 bpp = get_bpp_by_code(sensor->fmt.code); in vgxy61_check_bw()
651 line_rate = sensor->nb_of_lane * (u64)sensor->data_rate_in_mbps * in vgxy61_check_bw()
652 sensor->line_length; in vgxy61_check_bw()
653 max_bit_per_line = div64_u64(line_rate, sensor->pclk) - mipi_margin; in vgxy61_check_bw()
654 bit_per_line = (bpp * sensor->current_mode->width) / binning_scale; in vgxy61_check_bw()
656 return bit_per_line > max_bit_per_line ? -EINVAL : 0; in vgxy61_check_bw()
666 sensor->expo_long, &ret); in vgxy61_apply_exposure()
668 sensor->expo_short, &ret); in vgxy61_apply_exposure()
678 sensor->supplies[i].supply = vgxy61_supply_name[i]; in vgxy61_get_regulators()
680 return devm_regulator_bulk_get(&sensor->i2c_client->dev, in vgxy61_get_regulators()
682 sensor->supplies); in vgxy61_get_regulators()
687 gpiod_set_value_cansleep(sensor->reset_gpio, 0); in vgxy61_apply_reset()
689 gpiod_set_value_cansleep(sensor->reset_gpio, 1); in vgxy61_apply_reset()
691 gpiod_set_value_cansleep(sensor->reset_gpio, 0); in vgxy61_apply_reset()
701 fmt->code = code; in vgxy61_fill_framefmt()
702 fmt->width = mode->width; in vgxy61_fill_framefmt()
703 fmt->height = mode->height; in vgxy61_fill_framefmt()
704 fmt->colorspace = V4L2_COLORSPACE_RAW; in vgxy61_fill_framefmt()
705 fmt->field = V4L2_FIELD_NONE; in vgxy61_fill_framefmt()
706 fmt->ycbcr_enc = V4L2_YCBCR_ENC_DEFAULT; in vgxy61_fill_framefmt()
707 fmt->quantization = V4L2_QUANTIZATION_DEFAULT; in vgxy61_fill_framefmt()
708 fmt->xfer_func = V4L2_XFER_FUNC_DEFAULT; in vgxy61_fill_framefmt()
716 const struct vgxy61_mode_info *mode = sensor->sensor_modes; in vgxy61_try_fmt_internal()
720 if (vgxy61_supported_codes[index].code == fmt->code) in vgxy61_try_fmt_internal()
726 mode = v4l2_find_nearest_size(sensor->sensor_modes, in vgxy61_try_fmt_internal()
727 sensor->sensor_modes_nb, width, height, in vgxy61_try_fmt_internal()
728 fmt->width, fmt->height); in vgxy61_try_fmt_internal()
744 switch (sel->target) { in vgxy61_get_selection()
746 sel->r = sensor->current_mode->crop; in vgxy61_get_selection()
751 sel->r.top = 0; in vgxy61_get_selection()
752 sel->r.left = 0; in vgxy61_get_selection()
753 sel->r.width = sensor->sensor_width; in vgxy61_get_selection()
754 sel->r.height = sensor->sensor_height; in vgxy61_get_selection()
758 return -EINVAL; in vgxy61_get_selection()
765 if (code->index >= ARRAY_SIZE(vgxy61_supported_codes)) in vgxy61_enum_mbus_code()
766 return -EINVAL; in vgxy61_enum_mbus_code()
768 code->code = vgxy61_supported_codes[code->index].code; in vgxy61_enum_mbus_code()
780 mutex_lock(&sensor->lock); in vgxy61_get_fmt()
782 if (format->which == V4L2_SUBDEV_FORMAT_TRY) in vgxy61_get_fmt()
783 fmt = v4l2_subdev_get_try_format(&sensor->sd, sd_state, in vgxy61_get_fmt()
784 format->pad); in vgxy61_get_fmt()
786 fmt = &sensor->fmt; in vgxy61_get_fmt()
788 format->format = *fmt; in vgxy61_get_fmt()
790 mutex_unlock(&sensor->lock); in vgxy61_get_fmt()
798 u16 min_vblank = VGXY61_MIN_FRAME_LENGTH - in vgxy61_get_vblank_min()
799 sensor->current_mode->crop.height; in vgxy61_get_vblank_min()
801 u16 min_vblank_hdr = VGXY61_MIN_EXPOSURE + sensor->rot_term + 1; in vgxy61_get_vblank_min()
814 if (fse->index >= sensor->sensor_modes_nb) in vgxy61_enum_frame_size()
815 return -EINVAL; in vgxy61_enum_frame_size()
817 fse->min_width = sensor->sensor_modes[fse->index].width; in vgxy61_enum_frame_size()
818 fse->max_width = fse->min_width; in vgxy61_enum_frame_size()
819 fse->min_height = sensor->sensor_modes[fse->index].height; in vgxy61_enum_frame_size()
820 fse->max_height = fse->min_height; in vgxy61_enum_frame_size()
827 sensor->analog_gain = target; in vgxy61_update_analog_gain()
829 if (sensor->streaming) in vgxy61_update_analog_gain()
855 sensor->digital_gain = target; in vgxy61_update_digital_gain()
857 if (sensor->streaming) in vgxy61_update_digital_gain()
858 return vgxy61_apply_digital_gain(sensor, sensor->digital_gain); in vgxy61_update_digital_gain()
878 sensor->pattern = pattern; in vgxy61_update_patgen()
880 if (sensor->streaming) in vgxy61_update_patgen()
881 return vgxy61_apply_patgen(sensor, sensor->pattern); in vgxy61_update_patgen()
909 sensor->strobe_mode = VGXY61_STROBE_ENABLED; in vgxy61_update_gpios_strobe_mode()
913 sensor->strobe_mode = VGXY61_STROBE_LONG; in vgxy61_update_gpios_strobe_mode()
921 if (!sensor->streaming) in vgxy61_update_gpios_strobe_mode()
926 sensor->strobe_mode, in vgxy61_update_gpios_strobe_mode()
940 if (sensor->streaming) in vgxy61_update_gpios_strobe_polarity()
941 return -EBUSY; in vgxy61_update_gpios_strobe_polarity()
964 ((sensor->frame_length - sensor->current_mode->crop.height - in vgxy61_get_expo_long_max()
965 sensor->rot_term) * short_expo_ratio) - 1; in vgxy61_get_expo_long_max()
972 (((sensor->frame_length - VGXY61_EXPOS_ROT_TERM) * in vgxy61_get_expo_long_max()
973 short_expo_ratio) / (short_expo_ratio + 1)) - 1; in vgxy61_get_expo_long_max()
979 third_rot_max_expo = (sensor->frame_length / 71) * short_expo_ratio; in vgxy61_get_expo_long_max()
989 struct i2c_client *client = sensor->i2c_client; in vgxy61_update_exposure()
1030 expo_long_max = sensor->frame_length - VGXY61_EXPOS_ROT_TERM; in vgxy61_update_exposure()
1042 dev_warn(&client->dev, "Exposure %d too high, clamping to %d\n", in vgxy61_update_exposure()
1048 sensor->expo_long = new_expo_long; in vgxy61_update_exposure()
1049 sensor->expo_short = new_expo_short; in vgxy61_update_exposure()
1050 sensor->expo_max = expo_long_max; in vgxy61_update_exposure()
1051 sensor->expo_min = expo_long_min; in vgxy61_update_exposure()
1053 if (sensor->streaming) in vgxy61_update_exposure()
1061 sensor->frame_length, NULL); in vgxy61_apply_framelength()
1069 sensor->vblank_min = vgxy61_get_vblank_min(sensor, hdr); in vgxy61_update_vblank()
1070 sensor->vblank = max(sensor->vblank_min, vblank); in vgxy61_update_vblank()
1071 sensor->frame_length = sensor->current_mode->crop.height + in vgxy61_update_vblank()
1072 sensor->vblank; in vgxy61_update_vblank()
1075 ret = vgxy61_update_exposure(sensor, sensor->expo_long, hdr); in vgxy61_update_vblank()
1079 if (sensor->streaming) in vgxy61_update_vblank()
1103 ret = vgxy61_update_vblank(sensor, sensor->vblank, index); in vgxy61_update_hdr()
1112 sensor->hdr = index; in vgxy61_update_hdr()
1114 if (sensor->streaming) in vgxy61_update_hdr()
1115 return vgxy61_apply_hdr(sensor, sensor->hdr); in vgxy61_update_hdr()
1124 ret = vgxy61_apply_hdr(sensor, sensor->hdr); in vgxy61_apply_settings()
1137 sensor->analog_gain, NULL); in vgxy61_apply_settings()
1140 ret = vgxy61_apply_digital_gain(sensor, sensor->digital_gain); in vgxy61_apply_settings()
1145 sensor->hflip | (sensor->vflip << 1), NULL); in vgxy61_apply_settings()
1149 ret = vgxy61_apply_patgen(sensor, sensor->pattern); in vgxy61_apply_settings()
1155 sensor->strobe_mode, i); in vgxy61_apply_settings()
1165 struct i2c_client *client = v4l2_get_subdevdata(&sensor->sd); in vgxy61_stream_enable()
1166 const struct v4l2_rect *crop = &sensor->current_mode->crop; in vgxy61_stream_enable()
1173 ret = pm_runtime_get_sync(&client->dev); in vgxy61_stream_enable()
1175 pm_runtime_put_autosuspend(&client->dev); in vgxy61_stream_enable()
1183 get_bpp_by_code(sensor->fmt.code), &ret); in vgxy61_stream_enable()
1185 get_data_type_by_code(sensor->fmt.code), &ret); in vgxy61_stream_enable()
1188 sensor->current_mode->bin_mode, &ret); in vgxy61_stream_enable()
1189 vgxy61_write_reg(sensor, VGXY61_REG_ROI0_START_H, crop->left, &ret); in vgxy61_stream_enable()
1191 crop->left + crop->width - 1, &ret); in vgxy61_stream_enable()
1192 vgxy61_write_reg(sensor, VGXY61_REG_ROI0_START_V, crop->top, &ret); in vgxy61_stream_enable()
1194 crop->top + crop->height - 1, &ret); in vgxy61_stream_enable()
1218 __v4l2_ctrl_grab(sensor->vflip_ctrl, true); in vgxy61_stream_enable()
1219 __v4l2_ctrl_grab(sensor->hflip_ctrl, true); in vgxy61_stream_enable()
1224 pm_runtime_put(&client->dev); in vgxy61_stream_enable()
1230 struct i2c_client *client = v4l2_get_subdevdata(&sensor->sd); in vgxy61_stream_disable()
1248 __v4l2_ctrl_grab(sensor->vflip_ctrl, false); in vgxy61_stream_disable()
1249 __v4l2_ctrl_grab(sensor->hflip_ctrl, false); in vgxy61_stream_disable()
1254 pm_runtime_put(&client->dev); in vgxy61_stream_disable()
1264 mutex_lock(&sensor->lock); in vgxy61_s_stream()
1269 sensor->streaming = enable; in vgxy61_s_stream()
1271 mutex_unlock(&sensor->lock); in vgxy61_s_stream()
1285 mutex_lock(&sensor->lock); in vgxy61_set_fmt()
1287 if (sensor->streaming) { in vgxy61_set_fmt()
1288 ret = -EBUSY; in vgxy61_set_fmt()
1292 ret = vgxy61_try_fmt_internal(sd, &format->format, &new_mode); in vgxy61_set_fmt()
1296 if (format->which == V4L2_SUBDEV_FORMAT_TRY) { in vgxy61_set_fmt()
1298 *fmt = format->format; in vgxy61_set_fmt()
1299 } else if (sensor->current_mode != new_mode || in vgxy61_set_fmt()
1300 sensor->fmt.code != format->format.code) { in vgxy61_set_fmt()
1301 fmt = &sensor->fmt; in vgxy61_set_fmt()
1302 *fmt = format->format; in vgxy61_set_fmt()
1304 sensor->current_mode = new_mode; in vgxy61_set_fmt()
1308 VGXY61_FRAME_LENGTH_DEF - in vgxy61_set_fmt()
1309 new_mode->crop.height, in vgxy61_set_fmt()
1310 sensor->hdr); in vgxy61_set_fmt()
1313 __v4l2_ctrl_s_ctrl_int64(sensor->pixel_rate_ctrl, in vgxy61_set_fmt()
1315 __v4l2_ctrl_modify_range(sensor->vblank_ctrl, in vgxy61_set_fmt()
1316 sensor->vblank_min, in vgxy61_set_fmt()
1317 0xffff - new_mode->crop.height, in vgxy61_set_fmt()
1318 1, sensor->vblank); in vgxy61_set_fmt()
1319 __v4l2_ctrl_s_ctrl(sensor->vblank_ctrl, sensor->vblank); in vgxy61_set_fmt()
1320 __v4l2_ctrl_modify_range(sensor->expo_ctrl, sensor->expo_min, in vgxy61_set_fmt()
1321 sensor->expo_max, 1, in vgxy61_set_fmt()
1322 sensor->expo_long); in vgxy61_set_fmt()
1326 mutex_unlock(&sensor->lock); in vgxy61_set_fmt()
1337 vgxy61_fill_framefmt(sensor, sensor->current_mode, &fmt.format, in vgxy61_init_cfg()
1347 const struct vgxy61_mode_info *cur_mode = sensor->current_mode; in vgxy61_s_ctrl()
1350 switch (ctrl->id) { in vgxy61_s_ctrl()
1352 ret = vgxy61_update_exposure(sensor, ctrl->val, sensor->hdr); in vgxy61_s_ctrl()
1353 ctrl->val = sensor->expo_long; in vgxy61_s_ctrl()
1356 ret = vgxy61_update_analog_gain(sensor, ctrl->val); in vgxy61_s_ctrl()
1359 ret = vgxy61_update_digital_gain(sensor, ctrl->val); in vgxy61_s_ctrl()
1363 if (sensor->streaming) { in vgxy61_s_ctrl()
1364 ret = -EBUSY; in vgxy61_s_ctrl()
1367 if (ctrl->id == V4L2_CID_VFLIP) in vgxy61_s_ctrl()
1368 sensor->vflip = ctrl->val; in vgxy61_s_ctrl()
1369 if (ctrl->id == V4L2_CID_HFLIP) in vgxy61_s_ctrl()
1370 sensor->hflip = ctrl->val; in vgxy61_s_ctrl()
1374 ret = vgxy61_update_patgen(sensor, ctrl->val); in vgxy61_s_ctrl()
1377 ret = vgxy61_update_hdr(sensor, ctrl->val); in vgxy61_s_ctrl()
1379 __v4l2_ctrl_modify_range(sensor->vblank_ctrl, in vgxy61_s_ctrl()
1380 sensor->vblank_min, in vgxy61_s_ctrl()
1381 0xffff - cur_mode->crop.height, in vgxy61_s_ctrl()
1382 1, sensor->vblank); in vgxy61_s_ctrl()
1383 __v4l2_ctrl_modify_range(sensor->expo_ctrl, sensor->expo_min, in vgxy61_s_ctrl()
1384 sensor->expo_max, 1, in vgxy61_s_ctrl()
1385 sensor->expo_long); in vgxy61_s_ctrl()
1388 ret = vgxy61_update_vblank(sensor, ctrl->val, sensor->hdr); in vgxy61_s_ctrl()
1390 __v4l2_ctrl_modify_range(sensor->expo_ctrl, sensor->expo_min, in vgxy61_s_ctrl()
1391 sensor->expo_max, 1, in vgxy61_s_ctrl()
1392 sensor->expo_long); in vgxy61_s_ctrl()
1395 ret = -EINVAL; in vgxy61_s_ctrl()
1409 struct v4l2_ctrl_handler *hdl = &sensor->ctrl_handler; in vgxy61_init_controls()
1410 const struct vgxy61_mode_info *cur_mode = sensor->current_mode; in vgxy61_init_controls()
1416 hdl->lock = &sensor->lock; in vgxy61_init_controls()
1418 sensor->analog_gain); in vgxy61_init_controls()
1420 sensor->digital_gain); in vgxy61_init_controls()
1422 ARRAY_SIZE(vgxy61_test_pattern_menu) - 1, in vgxy61_init_controls()
1425 sensor->line_length, 1, in vgxy61_init_controls()
1426 sensor->line_length - cur_mode->width); in vgxy61_init_controls()
1428 ctrl->flags |= V4L2_CTRL_FLAG_READ_ONLY; in vgxy61_init_controls()
1430 ARRAY_SIZE(link_freq) - 1, 0, link_freq); in vgxy61_init_controls()
1432 ctrl->flags |= V4L2_CTRL_FLAG_READ_ONLY; in vgxy61_init_controls()
1434 ARRAY_SIZE(vgxy61_hdr_mode_menu) - 1, 0, in vgxy61_init_controls()
1441 sensor->pixel_rate_ctrl = v4l2_ctrl_new_std(hdl, ops, in vgxy61_init_controls()
1445 if (sensor->pixel_rate_ctrl) in vgxy61_init_controls()
1446 sensor->pixel_rate_ctrl->flags |= V4L2_CTRL_FLAG_READ_ONLY; in vgxy61_init_controls()
1447 sensor->expo_ctrl = v4l2_ctrl_new_std(hdl, ops, V4L2_CID_EXPOSURE, in vgxy61_init_controls()
1448 sensor->expo_min, in vgxy61_init_controls()
1449 sensor->expo_max, 1, in vgxy61_init_controls()
1450 sensor->expo_long); in vgxy61_init_controls()
1451 sensor->vblank_ctrl = v4l2_ctrl_new_std(hdl, ops, V4L2_CID_VBLANK, in vgxy61_init_controls()
1452 sensor->vblank_min, in vgxy61_init_controls()
1453 0xffff - cur_mode->crop.height, in vgxy61_init_controls()
1454 1, sensor->vblank); in vgxy61_init_controls()
1455 sensor->vflip_ctrl = v4l2_ctrl_new_std(hdl, ops, V4L2_CID_VFLIP, in vgxy61_init_controls()
1456 0, 1, 1, sensor->vflip); in vgxy61_init_controls()
1457 sensor->hflip_ctrl = v4l2_ctrl_new_std(hdl, ops, V4L2_CID_HFLIP, in vgxy61_init_controls()
1458 0, 1, 1, sensor->hflip); in vgxy61_init_controls()
1460 if (hdl->error) { in vgxy61_init_controls()
1461 ret = hdl->error; in vgxy61_init_controls()
1465 sensor->sd.ctrl_handler = hdl; in vgxy61_init_controls()
1499 struct i2c_client *client = sensor->i2c_client; in vgxy61_tx_from_ep()
1509 return -EINVAL; in vgxy61_tx_from_ep()
1513 dev_err(&client->dev, "invalid data lane number %d\n", l_nb); in vgxy61_tx_from_ep()
1521 log2phy[l] = ep.bus.mipi_csi2.data_lanes[l - 1]; in vgxy61_tx_from_ep()
1539 dev_err(&client->dev, "clk lane must be map to physical lane 0\n"); in vgxy61_tx_from_ep()
1542 sensor->oif_ctrl = (polarities[4] << 15) + ((phy2log[4] - 1) << 13) + in vgxy61_tx_from_ep()
1543 (polarities[3] << 12) + ((phy2log[3] - 1) << 10) + in vgxy61_tx_from_ep()
1544 (polarities[2] << 9) + ((phy2log[2] - 1) << 7) + in vgxy61_tx_from_ep()
1545 (polarities[1] << 6) + ((phy2log[1] - 1) << 4) + in vgxy61_tx_from_ep()
1548 sensor->nb_of_lane = l_nb; in vgxy61_tx_from_ep()
1550 dev_dbg(&client->dev, "tx uses %d lanes", l_nb); in vgxy61_tx_from_ep()
1552 dev_dbg(&client->dev, "log2phy[%d] = %d\n", i, log2phy[i]); in vgxy61_tx_from_ep()
1553 dev_dbg(&client->dev, "phy2log[%d] = %d\n", i, phy2log[i]); in vgxy61_tx_from_ep()
1554 dev_dbg(&client->dev, "polarity[%d] = %d\n", i, polarities[i]); in vgxy61_tx_from_ep()
1556 dev_dbg(&client->dev, "oif_ctrl = 0x%04x\n", sensor->oif_ctrl); in vgxy61_tx_from_ep()
1565 return -EINVAL; in vgxy61_tx_from_ep()
1575 compute_pll_parameters_by_freq(sensor->clk_freq, &prediv, &mult); in vgxy61_configure()
1576 sensor_freq = (mult * sensor->clk_freq) / prediv; in vgxy61_configure()
1578 sensor->data_rate_in_mbps = sensor_freq; in vgxy61_configure()
1580 sensor->pclk = sensor_freq / 5; in vgxy61_configure()
1585 sensor->line_length = line_length; in vgxy61_configure()
1586 vgxy61_write_reg(sensor, VGXY61_REG_EXT_CLOCK, sensor->clk_freq, &ret); in vgxy61_configure()
1589 vgxy61_write_reg(sensor, VGXY61_REG_OIF_CTRL, sensor->oif_ctrl, &ret); in vgxy61_configure()
1594 vgxy61_update_gpios_strobe_polarity(sensor, sensor->gpios_polarity); in vgxy61_configure()
1612 struct i2c_client *client = sensor->i2c_client; in vgxy61_patch()
1635 dev_err(&client->dev, "bad patch version expected %d.%d.%d got %d.%d.%d\n", in vgxy61_patch()
1640 return -ENODEV; in vgxy61_patch()
1642 dev_dbg(&client->dev, "patch %d.%d.%d applied\n", in vgxy61_patch()
1650 struct i2c_client *client = sensor->i2c_client; in vgxy61_detect_cut_version()
1659 dev_dbg(&client->dev, "Cut1 detected\n"); in vgxy61_detect_cut_version()
1660 dev_err(&client->dev, "Cut1 not supported by this driver\n"); in vgxy61_detect_cut_version()
1661 return -ENODEV; in vgxy61_detect_cut_version()
1663 dev_dbg(&client->dev, "Cut2 detected\n"); in vgxy61_detect_cut_version()
1666 dev_dbg(&client->dev, "Cut3 detected\n"); in vgxy61_detect_cut_version()
1669 dev_err(&client->dev, "Unable to detect cut version\n"); in vgxy61_detect_cut_version()
1670 return -ENODEV; in vgxy61_detect_cut_version()
1676 struct i2c_client *client = sensor->i2c_client; in vgxy61_detect()
1684 dev_warn(&client->dev, "Unsupported sensor id %x\n", id); in vgxy61_detect()
1685 return -ENODEV; in vgxy61_detect()
1687 dev_dbg(&client->dev, "detected sensor id = 0x%04x\n", id); in vgxy61_detect()
1688 sensor->id = id; in vgxy61_detect()
1699 dev_warn(&client->dev, "Bad nvm state got %d\n", st); in vgxy61_detect()
1717 sensor->supplies); in vgxy61_power_on()
1719 dev_err(&client->dev, "failed to enable regulators %d\n", ret); in vgxy61_power_on()
1723 ret = clk_prepare_enable(sensor->xclk); in vgxy61_power_on()
1725 dev_err(&client->dev, "failed to enable clock %d\n", ret); in vgxy61_power_on()
1729 if (sensor->reset_gpio) { in vgxy61_power_on()
1732 dev_err(&client->dev, "sensor reset failed %d\n", ret); in vgxy61_power_on()
1739 dev_err(&client->dev, "sensor detect failed %d\n", ret); in vgxy61_power_on()
1745 dev_err(&client->dev, "sensor patch failed %d\n", ret); in vgxy61_power_on()
1751 dev_err(&client->dev, "sensor configuration failed %d\n", ret); in vgxy61_power_on()
1758 clk_disable_unprepare(sensor->xclk); in vgxy61_power_on()
1761 sensor->supplies); in vgxy61_power_on()
1772 clk_disable_unprepare(sensor->xclk); in vgxy61_power_off()
1774 sensor->supplies); in vgxy61_power_off()
1780 if (sensor->id == VG5761_MODEL_ID) { in vgxy61_fill_sensor_param()
1781 sensor->sensor_width = VGX761_WIDTH; in vgxy61_fill_sensor_param()
1782 sensor->sensor_height = VGX761_HEIGHT; in vgxy61_fill_sensor_param()
1783 sensor->sensor_modes = vgx761_mode_data; in vgxy61_fill_sensor_param()
1784 sensor->sensor_modes_nb = ARRAY_SIZE(vgx761_mode_data); in vgxy61_fill_sensor_param()
1785 sensor->default_mode = &vgx761_mode_data[VGX761_DEFAULT_MODE]; in vgxy61_fill_sensor_param()
1786 sensor->rot_term = VGX761_SHORT_ROT_TERM; in vgxy61_fill_sensor_param()
1787 } else if (sensor->id == VG5661_MODEL_ID) { in vgxy61_fill_sensor_param()
1788 sensor->sensor_width = VGX661_WIDTH; in vgxy61_fill_sensor_param()
1789 sensor->sensor_height = VGX661_HEIGHT; in vgxy61_fill_sensor_param()
1790 sensor->sensor_modes = vgx661_mode_data; in vgxy61_fill_sensor_param()
1791 sensor->sensor_modes_nb = ARRAY_SIZE(vgx661_mode_data); in vgxy61_fill_sensor_param()
1792 sensor->default_mode = &vgx661_mode_data[VGX661_DEFAULT_MODE]; in vgxy61_fill_sensor_param()
1793 sensor->rot_term = VGX661_SHORT_ROT_TERM; in vgxy61_fill_sensor_param()
1798 sensor->current_mode = sensor->default_mode; in vgxy61_fill_sensor_param()
1803 struct device *dev = &client->dev; in vgxy61_probe()
1810 return -ENOMEM; in vgxy61_probe()
1812 sensor->i2c_client = client; in vgxy61_probe()
1813 sensor->streaming = false; in vgxy61_probe()
1814 sensor->hdr = VGXY61_NO_HDR; in vgxy61_probe()
1815 sensor->expo_long = 200; in vgxy61_probe()
1816 sensor->expo_short = 0; in vgxy61_probe()
1817 sensor->hflip = false; in vgxy61_probe()
1818 sensor->vflip = false; in vgxy61_probe()
1819 sensor->analog_gain = 0; in vgxy61_probe()
1820 sensor->digital_gain = 256; in vgxy61_probe()
1825 return -EINVAL; in vgxy61_probe()
1835 sensor->xclk = devm_clk_get(dev, NULL); in vgxy61_probe()
1836 if (IS_ERR(sensor->xclk)) { in vgxy61_probe()
1838 return PTR_ERR(sensor->xclk); in vgxy61_probe()
1840 sensor->clk_freq = clk_get_rate(sensor->xclk); in vgxy61_probe()
1841 if (sensor->clk_freq < 6 * HZ_PER_MHZ || in vgxy61_probe()
1842 sensor->clk_freq > 27 * HZ_PER_MHZ) { in vgxy61_probe()
1843 dev_err(dev, "Only 6Mhz-27Mhz clock range supported. provide %lu MHz\n", in vgxy61_probe()
1844 sensor->clk_freq / HZ_PER_MHZ); in vgxy61_probe()
1845 return -EINVAL; in vgxy61_probe()
1847 sensor->gpios_polarity = in vgxy61_probe()
1848 device_property_read_bool(dev, "st,strobe-gpios-polarity"); in vgxy61_probe()
1850 v4l2_i2c_subdev_init(&sensor->sd, client, &vgxy61_subdev_ops); in vgxy61_probe()
1851 sensor->sd.flags |= V4L2_SUBDEV_FL_HAS_DEVNODE; in vgxy61_probe()
1852 sensor->pad.flags = MEDIA_PAD_FL_SOURCE; in vgxy61_probe()
1853 sensor->sd.entity.ops = &vgxy61_subdev_entity_ops; in vgxy61_probe()
1854 sensor->sd.entity.function = MEDIA_ENT_F_CAM_SENSOR; in vgxy61_probe()
1856 sensor->reset_gpio = devm_gpiod_get_optional(dev, "reset", in vgxy61_probe()
1861 dev_err(&client->dev, "failed to get regulators %d\n", ret); in vgxy61_probe()
1870 vgxy61_fill_framefmt(sensor, sensor->current_mode, &sensor->fmt, in vgxy61_probe()
1873 mutex_init(&sensor->lock); in vgxy61_probe()
1875 ret = vgxy61_update_hdr(sensor, sensor->hdr); in vgxy61_probe()
1881 dev_err(&client->dev, "controls initialization failed %d\n", in vgxy61_probe()
1886 ret = media_entity_pads_init(&sensor->sd.entity, 1, &sensor->pad); in vgxy61_probe()
1888 dev_err(&client->dev, "pads init failed %d\n", ret); in vgxy61_probe()
1897 ret = v4l2_async_register_subdev(&sensor->sd); in vgxy61_probe()
1899 dev_err(&client->dev, "async subdev register failed %d\n", ret); in vgxy61_probe()
1903 pm_runtime_set_autosuspend_delay(&client->dev, 1000); in vgxy61_probe()
1904 pm_runtime_use_autosuspend(&client->dev); in vgxy61_probe()
1906 dev_dbg(&client->dev, "vgxy61 probe successfully\n"); in vgxy61_probe()
1911 pm_runtime_disable(&client->dev); in vgxy61_probe()
1912 pm_runtime_set_suspended(&client->dev); in vgxy61_probe()
1913 media_entity_cleanup(&sensor->sd.entity); in vgxy61_probe()
1915 v4l2_ctrl_handler_free(sensor->sd.ctrl_handler); in vgxy61_probe()
1917 mutex_destroy(&sensor->lock); in vgxy61_probe()
1928 v4l2_async_unregister_subdev(&sensor->sd); in vgxy61_remove()
1929 mutex_destroy(&sensor->lock); in vgxy61_remove()
1930 media_entity_cleanup(&sensor->sd.entity); in vgxy61_remove()
1932 pm_runtime_disable(&client->dev); in vgxy61_remove()
1933 if (!pm_runtime_status_suspended(&client->dev)) in vgxy61_remove()
1934 vgxy61_power_off(&client->dev); in vgxy61_remove()
1935 pm_runtime_set_suspended(&client->dev); in vgxy61_remove()
1939 { .compatible = "st,st-vgxy61" },
1950 .name = "st-vgxy61",