Lines Matching full:sensor

3  * Driver for VGXY61 global shutter sensor family driver
480 static s32 get_pixel_rate(struct vgxy61_dev *sensor) in get_pixel_rate() argument
482 return div64_u64((u64)sensor->data_rate_in_mbps * sensor->nb_of_lane, in get_pixel_rate()
483 get_bpp_by_code(sensor->fmt.code)); in get_pixel_rate()
497 static unsigned int get_chunk_size(struct vgxy61_dev *sensor) in get_chunk_size() argument
499 struct i2c_adapter *adapter = sensor->i2c_client->adapter; in get_chunk_size()
510 static int vgxy61_write_array(struct vgxy61_dev *sensor, u32 reg, in vgxy61_write_array() argument
513 const unsigned int chunk_size = get_chunk_size(sensor); in vgxy61_write_array()
519 ret = regmap_bulk_write(sensor->regmap, CCI_REG_ADDR(reg), in vgxy61_write_array()
531 static int vgxy61_poll_reg(struct vgxy61_dev *sensor, u32 reg, u8 poll_val, in vgxy61_poll_reg() argument
541 false, sensor->regmap, reg, &val, NULL); in vgxy61_poll_reg()
544 static int vgxy61_wait_state(struct vgxy61_dev *sensor, int state, in vgxy61_wait_state() argument
547 return vgxy61_poll_reg(sensor, VGXY61_REG_SYSTEM_FSM, state, in vgxy61_wait_state()
551 static int vgxy61_check_bw(struct vgxy61_dev *sensor) in vgxy61_check_bw() argument
557 * is a mipi IP constant for the sensor. in vgxy61_check_bw()
560 unsigned int binning_scale = sensor->current_mode->crop.height / in vgxy61_check_bw()
561 sensor->current_mode->height; in vgxy61_check_bw()
562 u8 bpp = get_bpp_by_code(sensor->fmt.code); in vgxy61_check_bw()
567 line_rate = sensor->nb_of_lane * (u64)sensor->data_rate_in_mbps * in vgxy61_check_bw()
568 sensor->line_length; in vgxy61_check_bw()
569 max_bit_per_line = div64_u64(line_rate, sensor->pclk) - mipi_margin; in vgxy61_check_bw()
570 bit_per_line = (bpp * sensor->current_mode->width) / binning_scale; in vgxy61_check_bw()
575 static int vgxy61_apply_exposure(struct vgxy61_dev *sensor) in vgxy61_apply_exposure() argument
580 cci_write(sensor->regmap, VGXY61_REG_COARSE_EXPOSURE_SHORT, 0, &ret); in vgxy61_apply_exposure()
581 cci_write(sensor->regmap, VGXY61_REG_COARSE_EXPOSURE_LONG, in vgxy61_apply_exposure()
582 sensor->expo_long, &ret); in vgxy61_apply_exposure()
583 cci_write(sensor->regmap, VGXY61_REG_COARSE_EXPOSURE_SHORT, in vgxy61_apply_exposure()
584 sensor->expo_short, &ret); in vgxy61_apply_exposure()
589 static int vgxy61_get_regulators(struct vgxy61_dev *sensor) in vgxy61_get_regulators() argument
594 sensor->supplies[i].supply = vgxy61_supply_name[i]; in vgxy61_get_regulators()
596 return devm_regulator_bulk_get(&sensor->i2c_client->dev, in vgxy61_get_regulators()
598 sensor->supplies); in vgxy61_get_regulators()
601 static int vgxy61_apply_reset(struct vgxy61_dev *sensor) in vgxy61_apply_reset() argument
603 gpiod_set_value_cansleep(sensor->reset_gpio, 0); in vgxy61_apply_reset()
605 gpiod_set_value_cansleep(sensor->reset_gpio, 1); in vgxy61_apply_reset()
607 gpiod_set_value_cansleep(sensor->reset_gpio, 0); in vgxy61_apply_reset()
609 return vgxy61_wait_state(sensor, VGXY61_SYSTEM_FSM_SW_STBY, in vgxy61_apply_reset()
613 static void vgxy61_fill_framefmt(struct vgxy61_dev *sensor, in vgxy61_fill_framefmt() argument
631 struct vgxy61_dev *sensor = to_vgxy61_dev(sd); in vgxy61_try_fmt_internal() local
642 mode = v4l2_find_nearest_size(sensor->sensor_modes, in vgxy61_try_fmt_internal()
643 sensor->sensor_modes_nb, width, height, in vgxy61_try_fmt_internal()
648 vgxy61_fill_framefmt(sensor, mode, fmt, in vgxy61_try_fmt_internal()
658 struct vgxy61_dev *sensor = to_vgxy61_dev(sd); in vgxy61_get_selection() local
662 sel->r = sensor->current_mode->crop; in vgxy61_get_selection()
669 sel->r.width = sensor->sensor_width; in vgxy61_get_selection()
670 sel->r.height = sensor->sensor_height; in vgxy61_get_selection()
693 struct vgxy61_dev *sensor = to_vgxy61_dev(sd); in vgxy61_get_fmt() local
696 mutex_lock(&sensor->lock); in vgxy61_get_fmt()
701 fmt = &sensor->fmt; in vgxy61_get_fmt()
705 mutex_unlock(&sensor->lock); in vgxy61_get_fmt()
710 static u16 vgxy61_get_vblank_min(struct vgxy61_dev *sensor, in vgxy61_get_vblank_min() argument
714 sensor->current_mode->crop.height; in vgxy61_get_vblank_min()
716 u16 min_vblank_hdr = VGXY61_MIN_EXPOSURE + sensor->rot_term + 1; in vgxy61_get_vblank_min()
727 struct vgxy61_dev *sensor = to_vgxy61_dev(sd); in vgxy61_enum_frame_size() local
729 if (fse->index >= sensor->sensor_modes_nb) in vgxy61_enum_frame_size()
732 fse->min_width = sensor->sensor_modes[fse->index].width; in vgxy61_enum_frame_size()
734 fse->min_height = sensor->sensor_modes[fse->index].height; in vgxy61_enum_frame_size()
740 static int vgxy61_update_analog_gain(struct vgxy61_dev *sensor, u32 target) in vgxy61_update_analog_gain() argument
742 sensor->analog_gain = target; in vgxy61_update_analog_gain()
744 if (sensor->streaming) in vgxy61_update_analog_gain()
745 return cci_write(sensor->regmap, VGXY61_REG_ANALOG_GAIN, target, in vgxy61_update_analog_gain()
750 static int vgxy61_apply_digital_gain(struct vgxy61_dev *sensor, in vgxy61_apply_digital_gain() argument
760 cci_write(sensor->regmap, VGXY61_REG_DIGITAL_GAIN_LONG, digital_gain, in vgxy61_apply_digital_gain()
762 cci_write(sensor->regmap, VGXY61_REG_DIGITAL_GAIN_SHORT, digital_gain, in vgxy61_apply_digital_gain()
768 static int vgxy61_update_digital_gain(struct vgxy61_dev *sensor, u32 target) in vgxy61_update_digital_gain() argument
770 sensor->digital_gain = target; in vgxy61_update_digital_gain()
772 if (sensor->streaming) in vgxy61_update_digital_gain()
773 return vgxy61_apply_digital_gain(sensor, sensor->digital_gain); in vgxy61_update_digital_gain()
777 static int vgxy61_apply_patgen(struct vgxy61_dev *sensor, u32 index) in vgxy61_apply_patgen() argument
788 return cci_write(sensor->regmap, VGXY61_REG_PATGEN_CTRL, reg, NULL); in vgxy61_apply_patgen()
791 static int vgxy61_update_patgen(struct vgxy61_dev *sensor, u32 pattern) in vgxy61_update_patgen() argument
793 sensor->pattern = pattern; in vgxy61_update_patgen()
795 if (sensor->streaming) in vgxy61_update_patgen()
796 return vgxy61_apply_patgen(sensor, sensor->pattern); in vgxy61_update_patgen()
800 static int vgxy61_apply_gpiox_strobe_mode(struct vgxy61_dev *sensor, in vgxy61_apply_gpiox_strobe_mode() argument
810 return cci_update_bits(sensor->regmap, VGXY61_REG_SIGNALS_CTRL, in vgxy61_apply_gpiox_strobe_mode()
814 static int vgxy61_update_gpios_strobe_mode(struct vgxy61_dev *sensor, in vgxy61_update_gpios_strobe_mode() argument
822 sensor->strobe_mode = VGXY61_STROBE_ENABLED; in vgxy61_update_gpios_strobe_mode()
826 sensor->strobe_mode = VGXY61_STROBE_LONG; in vgxy61_update_gpios_strobe_mode()
834 if (!sensor->streaming) in vgxy61_update_gpios_strobe_mode()
838 ret = vgxy61_apply_gpiox_strobe_mode(sensor, in vgxy61_update_gpios_strobe_mode()
839 sensor->strobe_mode, in vgxy61_update_gpios_strobe_mode()
848 static int vgxy61_update_gpios_strobe_polarity(struct vgxy61_dev *sensor, in vgxy61_update_gpios_strobe_polarity() argument
853 if (sensor->streaming) in vgxy61_update_gpios_strobe_polarity()
856 cci_write(sensor->regmap, VGXY61_REG_GPIO_0_CTRL, polarity << 1, &ret); in vgxy61_update_gpios_strobe_polarity()
857 cci_write(sensor->regmap, VGXY61_REG_GPIO_1_CTRL, polarity << 1, &ret); in vgxy61_update_gpios_strobe_polarity()
858 cci_write(sensor->regmap, VGXY61_REG_GPIO_2_CTRL, polarity << 1, &ret); in vgxy61_update_gpios_strobe_polarity()
859 cci_write(sensor->regmap, VGXY61_REG_GPIO_3_CTRL, polarity << 1, &ret); in vgxy61_update_gpios_strobe_polarity()
860 cci_write(sensor->regmap, VGXY61_REG_SIGNALS_POLARITY_CTRL, polarity, in vgxy61_update_gpios_strobe_polarity()
866 static u32 vgxy61_get_expo_long_max(struct vgxy61_dev *sensor, in vgxy61_get_expo_long_max() argument
871 /* Apply sensor's rules of thumb */ in vgxy61_get_expo_long_max()
877 ((sensor->frame_length - sensor->current_mode->crop.height - in vgxy61_get_expo_long_max()
878 sensor->rot_term) * short_expo_ratio) - 1; in vgxy61_get_expo_long_max()
881 * Total exposition time must be less than frame length to avoid sensor in vgxy61_get_expo_long_max()
885 (((sensor->frame_length - VGXY61_EXPOS_ROT_TERM) * in vgxy61_get_expo_long_max()
890 * sensor crash in vgxy61_get_expo_long_max()
892 third_rot_max_expo = (sensor->frame_length / 71) * short_expo_ratio; in vgxy61_get_expo_long_max()
899 static int vgxy61_update_exposure(struct vgxy61_dev *sensor, u16 new_expo_long, in vgxy61_update_exposure() argument
902 struct i2c_client *client = sensor->i2c_client; in vgxy61_update_exposure()
919 vgxy61_get_expo_long_max(sensor, in vgxy61_update_exposure()
931 expo_long_max = vgxy61_get_expo_long_max(sensor, 1); in vgxy61_update_exposure()
943 expo_long_max = sensor->frame_length - VGXY61_EXPOS_ROT_TERM; in vgxy61_update_exposure()
961 sensor->expo_long = new_expo_long; in vgxy61_update_exposure()
962 sensor->expo_short = new_expo_short; in vgxy61_update_exposure()
963 sensor->expo_max = expo_long_max; in vgxy61_update_exposure()
964 sensor->expo_min = expo_long_min; in vgxy61_update_exposure()
966 if (sensor->streaming) in vgxy61_update_exposure()
967 return vgxy61_apply_exposure(sensor); in vgxy61_update_exposure()
971 static int vgxy61_apply_framelength(struct vgxy61_dev *sensor) in vgxy61_apply_framelength() argument
973 return cci_write(sensor->regmap, VGXY61_REG_FRAME_LENGTH, in vgxy61_apply_framelength()
974 sensor->frame_length, NULL); in vgxy61_apply_framelength()
977 static int vgxy61_update_vblank(struct vgxy61_dev *sensor, u16 vblank, in vgxy61_update_vblank() argument
982 sensor->vblank_min = vgxy61_get_vblank_min(sensor, hdr); in vgxy61_update_vblank()
983 sensor->vblank = max(sensor->vblank_min, vblank); in vgxy61_update_vblank()
984 sensor->frame_length = sensor->current_mode->crop.height + in vgxy61_update_vblank()
985 sensor->vblank; in vgxy61_update_vblank()
988 ret = vgxy61_update_exposure(sensor, sensor->expo_long, hdr); in vgxy61_update_vblank()
992 if (sensor->streaming) in vgxy61_update_vblank()
993 return vgxy61_apply_framelength(sensor); in vgxy61_update_vblank()
997 static int vgxy61_apply_hdr(struct vgxy61_dev *sensor, in vgxy61_apply_hdr() argument
1002 return cci_write(sensor->regmap, VGXY61_REG_HDR_CTRL, index2val[index], in vgxy61_apply_hdr()
1006 static int vgxy61_update_hdr(struct vgxy61_dev *sensor, in vgxy61_update_hdr() argument
1016 ret = vgxy61_update_vblank(sensor, sensor->vblank, index); in vgxy61_update_hdr()
1021 ret = vgxy61_update_gpios_strobe_mode(sensor, index); in vgxy61_update_hdr()
1025 sensor->hdr = index; in vgxy61_update_hdr()
1027 if (sensor->streaming) in vgxy61_update_hdr()
1028 return vgxy61_apply_hdr(sensor, sensor->hdr); in vgxy61_update_hdr()
1032 static int vgxy61_apply_settings(struct vgxy61_dev *sensor) in vgxy61_apply_settings() argument
1037 ret = vgxy61_apply_hdr(sensor, sensor->hdr); in vgxy61_apply_settings()
1041 ret = vgxy61_apply_framelength(sensor); in vgxy61_apply_settings()
1045 ret = vgxy61_apply_exposure(sensor); in vgxy61_apply_settings()
1049 ret = cci_write(sensor->regmap, VGXY61_REG_ANALOG_GAIN, in vgxy61_apply_settings()
1050 sensor->analog_gain, NULL); in vgxy61_apply_settings()
1053 ret = vgxy61_apply_digital_gain(sensor, sensor->digital_gain); in vgxy61_apply_settings()
1057 ret = cci_write(sensor->regmap, VGXY61_REG_ORIENTATION, in vgxy61_apply_settings()
1058 sensor->hflip | (sensor->vflip << 1), NULL); in vgxy61_apply_settings()
1062 ret = vgxy61_apply_patgen(sensor, sensor->pattern); in vgxy61_apply_settings()
1067 ret = vgxy61_apply_gpiox_strobe_mode(sensor, in vgxy61_apply_settings()
1068 sensor->strobe_mode, i); in vgxy61_apply_settings()
1076 static int vgxy61_stream_enable(struct vgxy61_dev *sensor) in vgxy61_stream_enable() argument
1078 struct i2c_client *client = v4l2_get_subdevdata(&sensor->sd); in vgxy61_stream_enable()
1079 const struct v4l2_rect *crop = &sensor->current_mode->crop; in vgxy61_stream_enable()
1082 ret = vgxy61_check_bw(sensor); in vgxy61_stream_enable()
1090 cci_write(sensor->regmap, VGXY61_REG_FORMAT_CTRL, in vgxy61_stream_enable()
1091 get_bpp_by_code(sensor->fmt.code), &ret); in vgxy61_stream_enable()
1092 cci_write(sensor->regmap, VGXY61_REG_OIF_ROI0_CTRL, in vgxy61_stream_enable()
1093 get_data_type_by_code(sensor->fmt.code), &ret); in vgxy61_stream_enable()
1095 cci_write(sensor->regmap, VGXY61_REG_READOUT_CTRL, in vgxy61_stream_enable()
1096 sensor->current_mode->bin_mode, &ret); in vgxy61_stream_enable()
1097 cci_write(sensor->regmap, VGXY61_REG_ROI0_START_H, crop->left, &ret); in vgxy61_stream_enable()
1098 cci_write(sensor->regmap, VGXY61_REG_ROI0_END_H, in vgxy61_stream_enable()
1100 cci_write(sensor->regmap, VGXY61_REG_ROI0_START_V, crop->top, &ret); in vgxy61_stream_enable()
1101 cci_write(sensor->regmap, VGXY61_REG_ROI0_END_V, in vgxy61_stream_enable()
1106 ret = vgxy61_apply_settings(sensor); in vgxy61_stream_enable()
1110 ret = cci_write(sensor->regmap, VGXY61_REG_STREAMING, in vgxy61_stream_enable()
1115 ret = vgxy61_poll_reg(sensor, VGXY61_REG_STREAMING, in vgxy61_stream_enable()
1120 ret = vgxy61_wait_state(sensor, VGXY61_SYSTEM_FSM_STREAMING, in vgxy61_stream_enable()
1126 __v4l2_ctrl_grab(sensor->vflip_ctrl, true); in vgxy61_stream_enable()
1127 __v4l2_ctrl_grab(sensor->hflip_ctrl, true); in vgxy61_stream_enable()
1136 static int vgxy61_stream_disable(struct vgxy61_dev *sensor) in vgxy61_stream_disable() argument
1138 struct i2c_client *client = v4l2_get_subdevdata(&sensor->sd); in vgxy61_stream_disable()
1141 ret = cci_write(sensor->regmap, VGXY61_REG_STREAMING, in vgxy61_stream_disable()
1146 ret = vgxy61_poll_reg(sensor, VGXY61_REG_STREAMING, in vgxy61_stream_disable()
1151 ret = vgxy61_wait_state(sensor, VGXY61_SYSTEM_FSM_SW_STBY, in vgxy61_stream_disable()
1156 __v4l2_ctrl_grab(sensor->vflip_ctrl, false); in vgxy61_stream_disable()
1157 __v4l2_ctrl_grab(sensor->hflip_ctrl, false); in vgxy61_stream_disable()
1169 struct vgxy61_dev *sensor = to_vgxy61_dev(sd); in vgxy61_s_stream() local
1172 mutex_lock(&sensor->lock); in vgxy61_s_stream()
1174 ret = enable ? vgxy61_stream_enable(sensor) : in vgxy61_s_stream()
1175 vgxy61_stream_disable(sensor); in vgxy61_s_stream()
1177 sensor->streaming = enable; in vgxy61_s_stream()
1179 mutex_unlock(&sensor->lock); in vgxy61_s_stream()
1188 struct vgxy61_dev *sensor = to_vgxy61_dev(sd); in vgxy61_set_fmt() local
1193 mutex_lock(&sensor->lock); in vgxy61_set_fmt()
1195 if (sensor->streaming) { in vgxy61_set_fmt()
1207 } else if (sensor->current_mode != new_mode || in vgxy61_set_fmt()
1208 sensor->fmt.code != format->format.code) { in vgxy61_set_fmt()
1209 fmt = &sensor->fmt; in vgxy61_set_fmt()
1212 sensor->current_mode = new_mode; in vgxy61_set_fmt()
1215 ret = vgxy61_update_vblank(sensor, in vgxy61_set_fmt()
1218 sensor->hdr); in vgxy61_set_fmt()
1221 __v4l2_ctrl_s_ctrl_int64(sensor->pixel_rate_ctrl, in vgxy61_set_fmt()
1222 get_pixel_rate(sensor)); in vgxy61_set_fmt()
1223 __v4l2_ctrl_modify_range(sensor->vblank_ctrl, in vgxy61_set_fmt()
1224 sensor->vblank_min, in vgxy61_set_fmt()
1226 1, sensor->vblank); in vgxy61_set_fmt()
1227 __v4l2_ctrl_s_ctrl(sensor->vblank_ctrl, sensor->vblank); in vgxy61_set_fmt()
1228 __v4l2_ctrl_modify_range(sensor->expo_ctrl, sensor->expo_min, in vgxy61_set_fmt()
1229 sensor->expo_max, 1, in vgxy61_set_fmt()
1230 sensor->expo_long); in vgxy61_set_fmt()
1234 mutex_unlock(&sensor->lock); in vgxy61_set_fmt()
1242 struct vgxy61_dev *sensor = to_vgxy61_dev(sd); in vgxy61_init_state() local
1245 vgxy61_fill_framefmt(sensor, sensor->current_mode, &fmt.format, in vgxy61_init_state()
1254 struct vgxy61_dev *sensor = to_vgxy61_dev(sd); in vgxy61_s_ctrl() local
1255 const struct vgxy61_mode_info *cur_mode = sensor->current_mode; in vgxy61_s_ctrl()
1260 ret = vgxy61_update_exposure(sensor, ctrl->val, sensor->hdr); in vgxy61_s_ctrl()
1261 ctrl->val = sensor->expo_long; in vgxy61_s_ctrl()
1264 ret = vgxy61_update_analog_gain(sensor, ctrl->val); in vgxy61_s_ctrl()
1267 ret = vgxy61_update_digital_gain(sensor, ctrl->val); in vgxy61_s_ctrl()
1271 if (sensor->streaming) { in vgxy61_s_ctrl()
1276 sensor->vflip = ctrl->val; in vgxy61_s_ctrl()
1278 sensor->hflip = ctrl->val; in vgxy61_s_ctrl()
1282 ret = vgxy61_update_patgen(sensor, ctrl->val); in vgxy61_s_ctrl()
1285 ret = vgxy61_update_hdr(sensor, ctrl->val); in vgxy61_s_ctrl()
1287 __v4l2_ctrl_modify_range(sensor->vblank_ctrl, in vgxy61_s_ctrl()
1288 sensor->vblank_min, in vgxy61_s_ctrl()
1290 1, sensor->vblank); in vgxy61_s_ctrl()
1291 __v4l2_ctrl_modify_range(sensor->expo_ctrl, sensor->expo_min, in vgxy61_s_ctrl()
1292 sensor->expo_max, 1, in vgxy61_s_ctrl()
1293 sensor->expo_long); in vgxy61_s_ctrl()
1296 ret = vgxy61_update_vblank(sensor, ctrl->val, sensor->hdr); in vgxy61_s_ctrl()
1298 __v4l2_ctrl_modify_range(sensor->expo_ctrl, sensor->expo_min, in vgxy61_s_ctrl()
1299 sensor->expo_max, 1, in vgxy61_s_ctrl()
1300 sensor->expo_long); in vgxy61_s_ctrl()
1314 static int vgxy61_init_controls(struct vgxy61_dev *sensor) in vgxy61_init_controls() argument
1317 struct v4l2_ctrl_handler *hdl = &sensor->ctrl_handler; in vgxy61_init_controls()
1318 const struct vgxy61_mode_info *cur_mode = sensor->current_mode; in vgxy61_init_controls()
1325 hdl->lock = &sensor->lock; in vgxy61_init_controls()
1327 sensor->analog_gain); in vgxy61_init_controls()
1329 sensor->digital_gain); in vgxy61_init_controls()
1334 sensor->line_length, 1, in vgxy61_init_controls()
1335 sensor->line_length - cur_mode->width); in vgxy61_init_controls()
1350 sensor->pixel_rate_ctrl = v4l2_ctrl_new_std(hdl, ops, in vgxy61_init_controls()
1353 get_pixel_rate(sensor)); in vgxy61_init_controls()
1354 if (sensor->pixel_rate_ctrl) in vgxy61_init_controls()
1355 sensor->pixel_rate_ctrl->flags |= V4L2_CTRL_FLAG_READ_ONLY; in vgxy61_init_controls()
1356 sensor->expo_ctrl = v4l2_ctrl_new_std(hdl, ops, V4L2_CID_EXPOSURE, in vgxy61_init_controls()
1357 sensor->expo_min, in vgxy61_init_controls()
1358 sensor->expo_max, 1, in vgxy61_init_controls()
1359 sensor->expo_long); in vgxy61_init_controls()
1360 sensor->vblank_ctrl = v4l2_ctrl_new_std(hdl, ops, V4L2_CID_VBLANK, in vgxy61_init_controls()
1361 sensor->vblank_min, in vgxy61_init_controls()
1363 1, sensor->vblank); in vgxy61_init_controls()
1364 sensor->vflip_ctrl = v4l2_ctrl_new_std(hdl, ops, V4L2_CID_VFLIP, in vgxy61_init_controls()
1365 0, 1, 1, sensor->vflip); in vgxy61_init_controls()
1366 sensor->hflip_ctrl = v4l2_ctrl_new_std(hdl, ops, V4L2_CID_HFLIP, in vgxy61_init_controls()
1367 0, 1, 1, sensor->hflip); in vgxy61_init_controls()
1374 ret = v4l2_fwnode_device_parse(&sensor->i2c_client->dev, &props); in vgxy61_init_controls()
1382 sensor->sd.ctrl_handler = hdl; in vgxy61_init_controls()
1421 static int vgxy61_tx_from_ep(struct vgxy61_dev *sensor, in vgxy61_tx_from_ep() argument
1425 struct i2c_client *client = sensor->i2c_client; in vgxy61_tx_from_ep()
1468 sensor->oif_ctrl = (polarities[4] << 15) + ((phy2log[4] - 1) << 13) + in vgxy61_tx_from_ep()
1474 sensor->nb_of_lane = l_nb; in vgxy61_tx_from_ep()
1482 dev_dbg(&client->dev, "oif_ctrl = 0x%04x\n", sensor->oif_ctrl); in vgxy61_tx_from_ep()
1494 static int vgxy61_configure(struct vgxy61_dev *sensor) in vgxy61_configure() argument
1501 compute_pll_parameters_by_freq(sensor->clk_freq, &prediv, &mult); in vgxy61_configure()
1502 sensor_freq = (mult * sensor->clk_freq) / prediv; in vgxy61_configure()
1504 sensor->data_rate_in_mbps = sensor_freq; in vgxy61_configure()
1506 sensor->pclk = sensor_freq / 5; in vgxy61_configure()
1508 cci_read(sensor->regmap, VGXY61_REG_LINE_LENGTH, &line_length, &ret); in vgxy61_configure()
1511 sensor->line_length = (u16)line_length; in vgxy61_configure()
1512 cci_write(sensor->regmap, VGXY61_REG_EXT_CLOCK, sensor->clk_freq, &ret); in vgxy61_configure()
1513 cci_write(sensor->regmap, VGXY61_REG_CLK_PLL_PREDIV, prediv, &ret); in vgxy61_configure()
1514 cci_write(sensor->regmap, VGXY61_REG_CLK_SYS_PLL_MULT, mult, &ret); in vgxy61_configure()
1515 cci_write(sensor->regmap, VGXY61_REG_OIF_CTRL, sensor->oif_ctrl, &ret); in vgxy61_configure()
1516 cci_write(sensor->regmap, VGXY61_REG_FRAME_CONTENT_CTRL, 0, &ret); in vgxy61_configure()
1517 cci_write(sensor->regmap, VGXY61_REG_BYPASS_CTRL, 4, &ret); in vgxy61_configure()
1520 vgxy61_update_gpios_strobe_polarity(sensor, sensor->gpios_polarity); in vgxy61_configure()
1522 cci_write(sensor->regmap, VGXY61_REG_PATGEN_LONG_DATA_GR, 0x800, &ret); in vgxy61_configure()
1523 cci_write(sensor->regmap, VGXY61_REG_PATGEN_LONG_DATA_R, 0x800, &ret); in vgxy61_configure()
1524 cci_write(sensor->regmap, VGXY61_REG_PATGEN_LONG_DATA_B, 0x800, &ret); in vgxy61_configure()
1525 cci_write(sensor->regmap, VGXY61_REG_PATGEN_LONG_DATA_GB, 0x800, &ret); in vgxy61_configure()
1526 cci_write(sensor->regmap, VGXY61_REG_PATGEN_SHORT_DATA_GR, 0x800, &ret); in vgxy61_configure()
1527 cci_write(sensor->regmap, VGXY61_REG_PATGEN_SHORT_DATA_R, 0x800, &ret); in vgxy61_configure()
1528 cci_write(sensor->regmap, VGXY61_REG_PATGEN_SHORT_DATA_B, 0x800, &ret); in vgxy61_configure()
1529 cci_write(sensor->regmap, VGXY61_REG_PATGEN_SHORT_DATA_GB, 0x800, &ret); in vgxy61_configure()
1536 static int vgxy61_patch(struct vgxy61_dev *sensor) in vgxy61_patch() argument
1538 struct i2c_client *client = sensor->i2c_client; in vgxy61_patch()
1542 ret = vgxy61_write_array(sensor, VGXY61_REG_FWPATCH_START_ADDR, in vgxy61_patch()
1544 cci_write(sensor->regmap, VGXY61_REG_STBY, 0x10, &ret); in vgxy61_patch()
1548 ret = vgxy61_poll_reg(sensor, VGXY61_REG_STBY, 0, VGXY61_TIMEOUT_MS); in vgxy61_patch()
1549 cci_read(sensor->regmap, VGXY61_REG_FWPATCH_REVISION, &patch, &ret); in vgxy61_patch()
1570 static int vgxy61_detect_cut_version(struct vgxy61_dev *sensor) in vgxy61_detect_cut_version() argument
1572 struct i2c_client *client = sensor->i2c_client; in vgxy61_detect_cut_version()
1576 ret = cci_read(sensor->regmap, VGXY61_REG_REVISION, &device_rev, NULL); in vgxy61_detect_cut_version()
1597 static int vgxy61_detect(struct vgxy61_dev *sensor) in vgxy61_detect() argument
1599 struct i2c_client *client = sensor->i2c_client; in vgxy61_detect()
1603 ret = cci_read(sensor->regmap, VGXY61_REG_MODEL_ID, &id, NULL); in vgxy61_detect()
1607 dev_warn(&client->dev, "Unsupported sensor id %x\n", (u16)id); in vgxy61_detect()
1610 dev_dbg(&client->dev, "detected sensor id = 0x%04x\n", (u16)id); in vgxy61_detect()
1611 sensor->id = id; in vgxy61_detect()
1613 ret = vgxy61_wait_state(sensor, VGXY61_SYSTEM_FSM_SW_STBY, in vgxy61_detect()
1618 ret = cci_read(sensor->regmap, VGXY61_REG_NVM, &st, NULL); in vgxy61_detect()
1624 ret = vgxy61_detect_cut_version(sensor); in vgxy61_detect()
1636 struct vgxy61_dev *sensor = to_vgxy61_dev(sd); in vgxy61_power_on() local
1640 sensor->supplies); in vgxy61_power_on()
1646 ret = clk_prepare_enable(sensor->xclk); in vgxy61_power_on()
1652 if (sensor->reset_gpio) { in vgxy61_power_on()
1653 ret = vgxy61_apply_reset(sensor); in vgxy61_power_on()
1655 dev_err(&client->dev, "sensor reset failed %d\n", ret); in vgxy61_power_on()
1660 ret = vgxy61_detect(sensor); in vgxy61_power_on()
1662 dev_err(&client->dev, "sensor detect failed %d\n", ret); in vgxy61_power_on()
1666 ret = vgxy61_patch(sensor); in vgxy61_power_on()
1668 dev_err(&client->dev, "sensor patch failed %d\n", ret); in vgxy61_power_on()
1672 ret = vgxy61_configure(sensor); in vgxy61_power_on()
1674 dev_err(&client->dev, "sensor configuration failed %d\n", ret); in vgxy61_power_on()
1681 clk_disable_unprepare(sensor->xclk); in vgxy61_power_on()
1684 sensor->supplies); in vgxy61_power_on()
1693 struct vgxy61_dev *sensor = to_vgxy61_dev(sd); in vgxy61_power_off() local
1695 clk_disable_unprepare(sensor->xclk); in vgxy61_power_off()
1697 sensor->supplies); in vgxy61_power_off()
1701 static void vgxy61_fill_sensor_param(struct vgxy61_dev *sensor) in vgxy61_fill_sensor_param() argument
1703 if (sensor->id == VG5761_MODEL_ID) { in vgxy61_fill_sensor_param()
1704 sensor->sensor_width = VGX761_WIDTH; in vgxy61_fill_sensor_param()
1705 sensor->sensor_height = VGX761_HEIGHT; in vgxy61_fill_sensor_param()
1706 sensor->sensor_modes = vgx761_mode_data; in vgxy61_fill_sensor_param()
1707 sensor->sensor_modes_nb = ARRAY_SIZE(vgx761_mode_data); in vgxy61_fill_sensor_param()
1708 sensor->default_mode = &vgx761_mode_data[VGX761_DEFAULT_MODE]; in vgxy61_fill_sensor_param()
1709 sensor->rot_term = VGX761_SHORT_ROT_TERM; in vgxy61_fill_sensor_param()
1710 } else if (sensor->id == VG5661_MODEL_ID) { in vgxy61_fill_sensor_param()
1711 sensor->sensor_width = VGX661_WIDTH; in vgxy61_fill_sensor_param()
1712 sensor->sensor_height = VGX661_HEIGHT; in vgxy61_fill_sensor_param()
1713 sensor->sensor_modes = vgx661_mode_data; in vgxy61_fill_sensor_param()
1714 sensor->sensor_modes_nb = ARRAY_SIZE(vgx661_mode_data); in vgxy61_fill_sensor_param()
1715 sensor->default_mode = &vgx661_mode_data[VGX661_DEFAULT_MODE]; in vgxy61_fill_sensor_param()
1716 sensor->rot_term = VGX661_SHORT_ROT_TERM; in vgxy61_fill_sensor_param()
1721 sensor->current_mode = sensor->default_mode; in vgxy61_fill_sensor_param()
1728 struct vgxy61_dev *sensor; in vgxy61_probe() local
1731 sensor = devm_kzalloc(dev, sizeof(*sensor), GFP_KERNEL); in vgxy61_probe()
1732 if (!sensor) in vgxy61_probe()
1735 sensor->i2c_client = client; in vgxy61_probe()
1736 sensor->streaming = false; in vgxy61_probe()
1737 sensor->hdr = VGXY61_NO_HDR; in vgxy61_probe()
1738 sensor->expo_long = 200; in vgxy61_probe()
1739 sensor->expo_short = 0; in vgxy61_probe()
1740 sensor->hflip = false; in vgxy61_probe()
1741 sensor->vflip = false; in vgxy61_probe()
1742 sensor->analog_gain = 0; in vgxy61_probe()
1743 sensor->digital_gain = 256; in vgxy61_probe()
1745 sensor->regmap = devm_cci_regmap_init_i2c(client, 16); in vgxy61_probe()
1746 if (IS_ERR(sensor->regmap)) { in vgxy61_probe()
1747 ret = PTR_ERR(sensor->regmap); in vgxy61_probe()
1757 ret = vgxy61_tx_from_ep(sensor, handle); in vgxy61_probe()
1764 sensor->xclk = devm_clk_get(dev, NULL); in vgxy61_probe()
1765 if (IS_ERR(sensor->xclk)) { in vgxy61_probe()
1767 return PTR_ERR(sensor->xclk); in vgxy61_probe()
1769 sensor->clk_freq = clk_get_rate(sensor->xclk); in vgxy61_probe()
1770 if (sensor->clk_freq < 6 * HZ_PER_MHZ || in vgxy61_probe()
1771 sensor->clk_freq > 27 * HZ_PER_MHZ) { in vgxy61_probe()
1773 sensor->clk_freq / HZ_PER_MHZ); in vgxy61_probe()
1776 sensor->gpios_polarity = in vgxy61_probe()
1779 v4l2_i2c_subdev_init(&sensor->sd, client, &vgxy61_subdev_ops); in vgxy61_probe()
1780 sensor->sd.internal_ops = &vgxy61_internal_ops; in vgxy61_probe()
1781 sensor->sd.flags |= V4L2_SUBDEV_FL_HAS_DEVNODE | in vgxy61_probe()
1783 sensor->pad.flags = MEDIA_PAD_FL_SOURCE; in vgxy61_probe()
1784 sensor->sd.entity.ops = &vgxy61_subdev_entity_ops; in vgxy61_probe()
1785 sensor->sd.entity.function = MEDIA_ENT_F_CAM_SENSOR; in vgxy61_probe()
1787 sensor->reset_gpio = devm_gpiod_get_optional(dev, "reset", in vgxy61_probe()
1790 ret = vgxy61_get_regulators(sensor); in vgxy61_probe()
1800 vgxy61_fill_sensor_param(sensor); in vgxy61_probe()
1801 vgxy61_fill_framefmt(sensor, sensor->current_mode, &sensor->fmt, in vgxy61_probe()
1804 mutex_init(&sensor->lock); in vgxy61_probe()
1806 ret = vgxy61_update_hdr(sensor, sensor->hdr); in vgxy61_probe()
1810 ret = vgxy61_init_controls(sensor); in vgxy61_probe()
1817 ret = media_entity_pads_init(&sensor->sd.entity, 1, &sensor->pad); in vgxy61_probe()
1828 ret = v4l2_async_register_subdev(&sensor->sd); in vgxy61_probe()
1844 media_entity_cleanup(&sensor->sd.entity); in vgxy61_probe()
1846 v4l2_ctrl_handler_free(sensor->sd.ctrl_handler); in vgxy61_probe()
1848 mutex_destroy(&sensor->lock); in vgxy61_probe()
1857 struct vgxy61_dev *sensor = to_vgxy61_dev(sd); in vgxy61_remove() local
1859 v4l2_async_unregister_subdev(&sensor->sd); in vgxy61_remove()
1860 mutex_destroy(&sensor->lock); in vgxy61_remove()
1861 media_entity_cleanup(&sensor->sd.entity); in vgxy61_remove()