Lines Matching refs:dev_vcm

354 static unsigned int dw9714_move_time(struct dw9714_device *dev_vcm,  in dw9714_move_time()  argument
357 struct i2c_client *client = v4l2_get_subdevdata(&dev_vcm->sd); in dw9714_move_time()
367 if (dev_vcm->adcanced_mode) { in dw9714_move_time()
369 sac_prescl = 1 << dev_vcm->sac_prescl; in dw9714_move_time()
370 move_time_ms = (((381 + 3 * dev_vcm->sac_time)) * sac_prescl + 99) / 100; in dw9714_move_time()
372 } else if (dev_vcm->dlc_enable) { in dw9714_move_time()
373 step_case = dev_vcm->mclk & 0x3; in dw9714_move_time()
377 if (dw9714_dlc_time_table[i].t_src == dev_vcm->t_src) in dw9714_move_time()
381 step_case = dev_vcm->step_mode & 0x3; in dw9714_move_time()
385 if (dw9714_lsc_time_table[i].t_src == dev_vcm->t_src) in dw9714_move_time()
416 codes_per_step = (dev_vcm->step_mode & 0x0c) >> 2; in dw9714_move_time()
420 if (!dev_vcm->dlc_enable) { in dw9714_move_time()
432 static int dw9714_get_dac(struct dw9714_device *dev_vcm, unsigned int *cur_dac) in dw9714_get_dac() argument
434 struct i2c_client *client = v4l2_get_subdevdata(&dev_vcm->sd); in dw9714_get_dac()
440 if (dev_vcm->adcanced_mode) { in dw9714_get_dac()
463 static int dw9714_set_dac(struct dw9714_device *dev_vcm, in dw9714_set_dac() argument
466 struct i2c_client *client = v4l2_get_subdevdata(&dev_vcm->sd); in dw9714_set_dac()
469 if (dev_vcm->adcanced_mode) { in dw9714_set_dac()
502 lsb = (((dest_dac & 0x0FU) << 4U) | dev_vcm->step_mode); in dw9714_set_dac()
515 static int dw9714_get_pos(struct dw9714_device *dev_vcm, in dw9714_get_pos() argument
518 struct i2c_client *client = v4l2_get_subdevdata(&dev_vcm->sd); in dw9714_get_pos()
522 range = dev_vcm->rated_current - dev_vcm->start_current; in dw9714_get_pos()
523 ret = dw9714_get_dac(dev_vcm, &dac); in dw9714_get_pos()
525 if (dac <= dev_vcm->start_current) { in dw9714_get_pos()
526 position = dev_vcm->max_logicalpos; in dw9714_get_pos()
527 } else if ((dac > dev_vcm->start_current) && in dw9714_get_pos()
528 (dac <= dev_vcm->rated_current)) { in dw9714_get_pos()
529 position = (dac - dev_vcm->start_current) * dev_vcm->max_logicalpos / range; in dw9714_get_pos()
530 position = dev_vcm->max_logicalpos - position; in dw9714_get_pos()
546 static int dw9714_set_pos(struct dw9714_device *dev_vcm, in dw9714_set_pos() argument
549 struct i2c_client *client = v4l2_get_subdevdata(&dev_vcm->sd); in dw9714_set_pos()
554 range = dev_vcm->rated_current - dev_vcm->start_current; in dw9714_set_pos()
555 if (dest_pos >= dev_vcm->max_logicalpos) in dw9714_set_pos()
556 position = dev_vcm->start_current; in dw9714_set_pos()
558 position = dev_vcm->start_current + in dw9714_set_pos()
559 (range * (dev_vcm->max_logicalpos - dest_pos) / dev_vcm->max_logicalpos); in dw9714_set_pos()
564 dev_vcm->current_lens_pos = position; in dw9714_set_pos()
565 dev_vcm->current_related_pos = dest_pos; in dw9714_set_pos()
567 ret = dw9714_set_dac(dev_vcm, position); in dw9714_set_pos()
575 struct dw9714_device *dev_vcm = to_dw9714_vcm(ctrl); in dw9714_get_ctrl() local
578 return dw9714_get_pos(dev_vcm, &ctrl->val); in dw9714_get_ctrl()
585 struct dw9714_device *dev_vcm = to_dw9714_vcm(ctrl); in dw9714_set_ctrl() local
586 struct i2c_client *client = v4l2_get_subdevdata(&dev_vcm->sd); in dw9714_set_ctrl()
593 if (dest_pos > dev_vcm->max_logicalpos) { in dw9714_set_ctrl()
596 __func__, dest_pos, dev_vcm->max_logicalpos); in dw9714_set_ctrl()
600 move_pos = dev_vcm->current_related_pos - dest_pos; in dw9714_set_ctrl()
604 ret = dw9714_set_pos(dev_vcm, dest_pos); in dw9714_set_ctrl()
605 if (dev_vcm->dlc_enable || dev_vcm->adcanced_mode) in dw9714_set_ctrl()
606 dev_vcm->move_ms = dev_vcm->vcm_movefull_t; in dw9714_set_ctrl()
608 dev_vcm->move_ms = in dw9714_set_ctrl()
609 ((dev_vcm->vcm_movefull_t * (uint32_t)move_pos) / in dw9714_set_ctrl()
610 dev_vcm->max_logicalpos); in dw9714_set_ctrl()
614 dest_pos, dev_vcm->current_lens_pos, dev_vcm->move_ms); in dw9714_set_ctrl()
616 dev_vcm->start_move_tv = ns_to_kernel_old_timeval(ktime_get_ns()); in dw9714_set_ctrl()
617 mv_us = dev_vcm->start_move_tv.tv_usec + in dw9714_set_ctrl()
618 dev_vcm->move_ms * 1000; in dw9714_set_ctrl()
620 dev_vcm->end_move_tv.tv_sec = in dw9714_set_ctrl()
621 dev_vcm->start_move_tv.tv_sec + 1; in dw9714_set_ctrl()
622 dev_vcm->end_move_tv.tv_usec = mv_us - 1000000; in dw9714_set_ctrl()
624 dev_vcm->end_move_tv.tv_sec = in dw9714_set_ctrl()
625 dev_vcm->start_move_tv.tv_sec; in dw9714_set_ctrl()
626 dev_vcm->end_move_tv.tv_usec = mv_us; in dw9714_set_ctrl()
726 struct dw9714_device *dev_vcm = sd_to_dw9714_vcm(sd); in dw9714_open() local
741 __func__, dev_vcm->current_lens_pos, dev_vcm->current_related_pos); in dw9714_open()
742 move_time = 1000 * dw9714_move_time(dev_vcm, DW9714_GRADUAL_MOVELENS_STEPS); in dw9714_open()
743 while (dac <= dev_vcm->current_lens_pos) { in dw9714_open()
744 dw9714_set_dac(dev_vcm, dac); in dw9714_open()
747 if (dac >= dev_vcm->current_lens_pos) in dw9714_open()
751 if (dac > dev_vcm->current_lens_pos) { in dw9714_open()
752 dac = dev_vcm->current_lens_pos; in dw9714_open()
753 dw9714_set_dac(dev_vcm, dac); in dw9714_open()
761 struct dw9714_device *dev_vcm = sd_to_dw9714_vcm(sd); in dw9714_close() local
763 int dac = dev_vcm->current_lens_pos; in dw9714_close()
767 __func__, dev_vcm->current_lens_pos, dev_vcm->current_related_pos); in dw9714_close()
768 move_time = 1000 * dw9714_move_time(dev_vcm, DW9714_GRADUAL_MOVELENS_STEPS); in dw9714_close()
770 dw9714_set_dac(dev_vcm, dac); in dw9714_close()
779 dw9714_set_dac(dev_vcm, dac); in dw9714_close()
792 static void dw9714_update_vcm_cfg(struct dw9714_device *dev_vcm) in dw9714_update_vcm_cfg() argument
794 struct i2c_client *client = v4l2_get_subdevdata(&dev_vcm->sd); in dw9714_update_vcm_cfg()
796 if (dev_vcm->max_current == 0) { in dw9714_update_vcm_cfg()
801 dev_vcm->start_current = dev_vcm->vcm_cfg.start_ma * in dw9714_update_vcm_cfg()
802 DW9714_MAX_REG / dev_vcm->max_current; in dw9714_update_vcm_cfg()
803 dev_vcm->rated_current = dev_vcm->vcm_cfg.rated_ma * in dw9714_update_vcm_cfg()
804 DW9714_MAX_REG / dev_vcm->max_current; in dw9714_update_vcm_cfg()
805 dev_vcm->step_mode = dev_vcm->vcm_cfg.step_mode; in dw9714_update_vcm_cfg()
809 dev_vcm->vcm_cfg.start_ma, in dw9714_update_vcm_cfg()
810 dev_vcm->vcm_cfg.rated_ma, in dw9714_update_vcm_cfg()
811 dev_vcm->vcm_cfg.step_mode, in dw9714_update_vcm_cfg()
812 dev_vcm->max_current); in dw9714_update_vcm_cfg()
817 struct dw9714_device *dev_vcm = sd_to_dw9714_vcm(sd); in dw9714_ioctl() local
827 vcm_tim->vcm_start_t.tv_sec = dev_vcm->start_move_tv.tv_sec; in dw9714_ioctl()
829 dev_vcm->start_move_tv.tv_usec; in dw9714_ioctl()
830 vcm_tim->vcm_end_t.tv_sec = dev_vcm->end_move_tv.tv_sec; in dw9714_ioctl()
831 vcm_tim->vcm_end_t.tv_usec = dev_vcm->end_move_tv.tv_usec; in dw9714_ioctl()
841 vcm_cfg->start_ma = dev_vcm->vcm_cfg.start_ma; in dw9714_ioctl()
842 vcm_cfg->rated_ma = dev_vcm->vcm_cfg.rated_ma; in dw9714_ioctl()
843 vcm_cfg->step_mode = dev_vcm->vcm_cfg.step_mode; in dw9714_ioctl()
847 dev_vcm->vcm_cfg.start_ma = vcm_cfg->start_ma; in dw9714_ioctl()
848 dev_vcm->vcm_cfg.rated_ma = vcm_cfg->rated_ma; in dw9714_ioctl()
849 dev_vcm->vcm_cfg.step_mode = vcm_cfg->step_mode; in dw9714_ioctl()
850 dw9714_update_vcm_cfg(dev_vcm); in dw9714_ioctl()
855 dev_vcm->max_logicalpos = max_logicalpos; in dw9714_ioctl()
856 __v4l2_ctrl_modify_range(dev_vcm->focus, in dw9714_ioctl()
857 0, dev_vcm->max_logicalpos, 1, dev_vcm->max_logicalpos); in dw9714_ioctl()
947 static int dw9714_init_controls(struct dw9714_device *dev_vcm) in dw9714_init_controls() argument
949 struct v4l2_ctrl_handler *hdl = &dev_vcm->ctrls_vcm; in dw9714_init_controls()
954 dev_vcm->focus = v4l2_ctrl_new_std(hdl, ops, V4L2_CID_FOCUS_ABSOLUTE, in dw9714_init_controls()
955 0, dev_vcm->max_logicalpos, 1, dev_vcm->max_logicalpos); in dw9714_init_controls()
958 dev_err(dev_vcm->sd.dev, "%s fail error: 0x%x\n", in dw9714_init_controls()
960 dev_vcm->sd.ctrl_handler = hdl; in dw9714_init_controls()
973 struct dw9714_device *dev_vcm = sd_to_dw9714_vcm(sd); in set_dacval() local
979 dw9714_set_dac(dev_vcm, val); in set_dacval()
989 struct dw9714_device *dev_vcm = sd_to_dw9714_vcm(sd); in get_dacval() local
992 dw9714_get_dac(dev_vcm, &dac); in get_dacval()
1106 struct dw9714_device *dev_vcm) in dw9714_parse_dt_property() argument
1113 (unsigned int *)&dev_vcm->max_current)) { in dw9714_parse_dt_property()
1114 dev_vcm->max_current = DW9714_MAX_CURRENT; in dw9714_parse_dt_property()
1119 if (dev_vcm->max_current == 0) in dw9714_parse_dt_property()
1120 dev_vcm->max_current = DW9714_MAX_CURRENT; in dw9714_parse_dt_property()
1124 (unsigned int *)&dev_vcm->vcm_cfg.start_ma)) { in dw9714_parse_dt_property()
1125 dev_vcm->vcm_cfg.start_ma = DW9714_DEFAULT_START_CURRENT; in dw9714_parse_dt_property()
1132 (unsigned int *)&dev_vcm->vcm_cfg.rated_ma)) { in dw9714_parse_dt_property()
1133 dev_vcm->vcm_cfg.rated_ma = DW9714_DEFAULT_RATED_CURRENT; in dw9714_parse_dt_property()
1140 (unsigned int *)&dev_vcm->vcm_cfg.step_mode)) { in dw9714_parse_dt_property()
1141 dev_vcm->vcm_cfg.step_mode = DW9714_DEFAULT_STEP_MODE; in dw9714_parse_dt_property()
1148 (unsigned int *)&dev_vcm->dlc_enable)) { in dw9714_parse_dt_property()
1149 dev_vcm->dlc_enable = DW9714_DEFAULT_DLC_EN; in dw9714_parse_dt_property()
1156 (unsigned int *)&dev_vcm->mclk)) { in dw9714_parse_dt_property()
1157 dev_vcm->mclk = DW9714_DEFAULT_MCLK; in dw9714_parse_dt_property()
1164 (unsigned int *)&dev_vcm->t_src)) { in dw9714_parse_dt_property()
1165 dev_vcm->t_src = DW9714_DEFAULT_T_SRC; in dw9714_parse_dt_property()
1172 (unsigned int *)&dev_vcm->adcanced_mode)) { in dw9714_parse_dt_property()
1173 dev_vcm->adcanced_mode = DW9714_DEFAULT_ADVMODE; in dw9714_parse_dt_property()
1180 (unsigned int *)&dev_vcm->sac_mode)) { in dw9714_parse_dt_property()
1181 dev_vcm->sac_mode = DW9714_DEFAULT_SAC_MODE; in dw9714_parse_dt_property()
1188 (unsigned int *)&dev_vcm->sac_time)) { in dw9714_parse_dt_property()
1189 dev_vcm->sac_time = DW9714_DEFAULT_SAC_TIME; in dw9714_parse_dt_property()
1196 (unsigned int *)&dev_vcm->sac_prescl)) { in dw9714_parse_dt_property()
1197 dev_vcm->sac_prescl = DW9714_DEFAULT_SAC_PRESCL; in dw9714_parse_dt_property()
1204 (unsigned int *)&dev_vcm->nrc_en)) { in dw9714_parse_dt_property()
1205 dev_vcm->nrc_en = DW9714_DEFAULT_NRC_EN; in dw9714_parse_dt_property()
1212 (unsigned int *)&dev_vcm->nrc_mode)) { in dw9714_parse_dt_property()
1213 dev_vcm->nrc_mode = DW9714_DEFAULT_NRC_MODE; in dw9714_parse_dt_property()
1220 (unsigned int *)&dev_vcm->nrc_preset)) { in dw9714_parse_dt_property()
1221 dev_vcm->nrc_preset = DW9714_DEFAULT_NRC_PRESET; in dw9714_parse_dt_property()
1228 (unsigned int *)&dev_vcm->nrc_infl)) { in dw9714_parse_dt_property()
1229 dev_vcm->nrc_infl = DW9714_DEFAULT_NRC_INFL; in dw9714_parse_dt_property()
1236 (unsigned int *)&dev_vcm->nrc_time)) { in dw9714_parse_dt_property()
1237 dev_vcm->nrc_time = DW9714_DEFAULT_NRC_TIME; in dw9714_parse_dt_property()
1243 dev_vcm->xsd_gpio = devm_gpiod_get(&client->dev, "xsd", GPIOD_OUT_HIGH); in dw9714_parse_dt_property()
1244 if (IS_ERR(dev_vcm->xsd_gpio)) in dw9714_parse_dt_property()
1248 &dev_vcm->module_index); in dw9714_parse_dt_property()
1250 &dev_vcm->module_facing); in dw9714_parse_dt_property()
1257 dev_vcm->client = client; in dw9714_parse_dt_property()
1258 ret = dw9714_configure_regulator(dev_vcm); in dw9714_parse_dt_property()
1265 dev_vcm->max_current, in dw9714_parse_dt_property()
1266 dev_vcm->start_current, in dw9714_parse_dt_property()
1267 dev_vcm->rated_current, in dw9714_parse_dt_property()
1268 dev_vcm->dlc_enable, in dw9714_parse_dt_property()
1269 dev_vcm->t_src, in dw9714_parse_dt_property()
1270 dev_vcm->mclk); in dw9714_parse_dt_property()
1274 dev_vcm->adcanced_mode, in dw9714_parse_dt_property()
1275 dev_vcm->sac_mode, in dw9714_parse_dt_property()
1276 dev_vcm->sac_time, in dw9714_parse_dt_property()
1277 dev_vcm->sac_prescl, in dw9714_parse_dt_property()
1278 dev_vcm->nrc_en, in dw9714_parse_dt_property()
1279 dev_vcm->nrc_mode, in dw9714_parse_dt_property()
1280 dev_vcm->nrc_preset, in dw9714_parse_dt_property()
1281 dev_vcm->nrc_infl, in dw9714_parse_dt_property()
1282 dev_vcm->nrc_time); in dw9714_parse_dt_property()
1380 struct dw9714_device *dev_vcm = sd_to_dw9714_vcm(sd); in dw9714_vcm_suspend() local
1382 dw9714_set_power(dev_vcm, false); in dw9714_vcm_suspend()
1390 struct dw9714_device *dev_vcm = sd_to_dw9714_vcm(sd); in dw9714_vcm_resume() local
1392 dw9714_set_power(dev_vcm, true); in dw9714_vcm_resume()