Lines Matching defs:ov2740

324 struct ov2740 {
352 static inline struct ov2740 *to_ov2740(struct v4l2_subdev *subdev)
354 return container_of(subdev, struct ov2740, sd);
375 static int ov2740_read_reg(struct ov2740 *ov2740, u16 reg, u16 len, u32 *val)
377 struct i2c_client *client = v4l2_get_subdevdata(&ov2740->sd);
405 static int ov2740_write_reg(struct ov2740 *ov2740, u16 reg, u16 len, u32 val)
407 struct i2c_client *client = v4l2_get_subdevdata(&ov2740->sd);
424 static int ov2740_write_reg_list(struct ov2740 *ov2740,
427 struct i2c_client *client = v4l2_get_subdevdata(&ov2740->sd);
432 ret = ov2740_write_reg(ov2740, r_list->regs[i].address, 1,
445 static int ov2740_identify_module(struct ov2740 *ov2740)
447 struct i2c_client *client = v4l2_get_subdevdata(&ov2740->sd);
451 if (ov2740->identified)
454 ret = ov2740_read_reg(ov2740, OV2740_REG_CHIP_ID, 3, &val);
464 ov2740->identified = true;
469 static int ov2740_update_digital_gain(struct ov2740 *ov2740, u32 d_gain)
473 ret = ov2740_write_reg(ov2740, OV2740_REG_GROUP_ACCESS, 1,
478 ret = ov2740_write_reg(ov2740, OV2740_REG_MWB_R_GAIN, 2, d_gain);
482 ret = ov2740_write_reg(ov2740, OV2740_REG_MWB_G_GAIN, 2, d_gain);
486 ret = ov2740_write_reg(ov2740, OV2740_REG_MWB_B_GAIN, 2, d_gain);
490 ret = ov2740_write_reg(ov2740, OV2740_REG_GROUP_ACCESS, 1,
495 ret = ov2740_write_reg(ov2740, OV2740_REG_GROUP_ACCESS, 1,
500 static int ov2740_test_pattern(struct ov2740 *ov2740, u32 pattern)
506 return ov2740_write_reg(ov2740, OV2740_REG_TEST_PATTERN, 1, pattern);
511 struct ov2740 *ov2740 = container_of(ctrl->handler,
512 struct ov2740, ctrl_handler);
513 struct i2c_client *client = v4l2_get_subdevdata(&ov2740->sd);
520 exposure_max = ov2740->cur_mode->height + ctrl->val -
522 __v4l2_ctrl_modify_range(ov2740->exposure,
523 ov2740->exposure->minimum,
524 exposure_max, ov2740->exposure->step,
534 ret = ov2740_write_reg(ov2740, OV2740_REG_ANALOG_GAIN, 2,
539 ret = ov2740_update_digital_gain(ov2740, ctrl->val);
544 ret = ov2740_write_reg(ov2740, OV2740_REG_EXPOSURE, 3,
549 ret = ov2740_write_reg(ov2740, OV2740_REG_VTS, 2,
550 ov2740->cur_mode->height + ctrl->val);
554 ret = ov2740_test_pattern(ov2740, ctrl->val);
571 static int ov2740_init_controls(struct ov2740 *ov2740)
580 ctrl_hdlr = &ov2740->ctrl_handler;
585 ctrl_hdlr->lock = &ov2740->mutex;
586 cur_mode = ov2740->cur_mode;
589 ov2740->link_freq = v4l2_ctrl_new_int_menu(ctrl_hdlr, &ov2740_ctrl_ops,
593 if (ov2740->link_freq)
594 ov2740->link_freq->flags |= V4L2_CTRL_FLAG_READ_ONLY;
597 ov2740->pixel_rate = v4l2_ctrl_new_std(ctrl_hdlr, &ov2740_ctrl_ops,
604 ov2740->vblank = v4l2_ctrl_new_std(ctrl_hdlr, &ov2740_ctrl_ops,
610 ov2740->hblank = v4l2_ctrl_new_std(ctrl_hdlr, &ov2740_ctrl_ops,
613 if (ov2740->hblank)
614 ov2740->hblank->flags |= V4L2_CTRL_FLAG_READ_ONLY;
623 ov2740->exposure = v4l2_ctrl_new_std(ctrl_hdlr, &ov2740_ctrl_ops,
637 ov2740->sd.ctrl_handler = ctrl_hdlr;
654 struct ov2740 *ov2740 = to_ov2740(dev_get_drvdata(dev));
666 ret = ov2740_read_reg(ov2740, OV2740_REG_ISP_CTRL00, 1, &isp_ctrl00);
672 ret = ov2740_read_reg(ov2740, OV2740_REG_ISP_CTRL01, 1, &isp_ctrl01);
679 ret = ov2740_write_reg(ov2740, OV2740_REG_ISP_CTRL00, 1,
687 ret = ov2740_write_reg(ov2740, OV2740_REG_ISP_CTRL01, 1,
694 ret = ov2740_write_reg(ov2740, OV2740_REG_MODE_SELECT, 1,
714 ret = ov2740_write_reg(ov2740, OV2740_REG_MODE_SELECT, 1,
721 ret = ov2740_write_reg(ov2740, OV2740_REG_ISP_CTRL01, 1, isp_ctrl01);
727 ret = ov2740_write_reg(ov2740, OV2740_REG_ISP_CTRL00, 1, isp_ctrl00);
741 static int ov2740_start_streaming(struct ov2740 *ov2740)
743 struct i2c_client *client = v4l2_get_subdevdata(&ov2740->sd);
748 ret = ov2740_identify_module(ov2740);
752 if (ov2740->nvm)
753 ov2740_load_otp_data(ov2740->nvm);
755 link_freq_index = ov2740->cur_mode->link_freq_index;
757 ret = ov2740_write_reg_list(ov2740, reg_list);
763 reg_list = &ov2740->cur_mode->reg_list;
764 ret = ov2740_write_reg_list(ov2740, reg_list);
770 ret = __v4l2_ctrl_handler_setup(ov2740->sd.ctrl_handler);
774 ret = ov2740_write_reg(ov2740, OV2740_REG_MODE_SELECT, 1,
782 static void ov2740_stop_streaming(struct ov2740 *ov2740)
784 struct i2c_client *client = v4l2_get_subdevdata(&ov2740->sd);
786 if (ov2740_write_reg(ov2740, OV2740_REG_MODE_SELECT, 1,
793 struct ov2740 *ov2740 = to_ov2740(sd);
797 if (ov2740->streaming == enable)
800 mutex_lock(&ov2740->mutex);
804 mutex_unlock(&ov2740->mutex);
808 ret = ov2740_start_streaming(ov2740);
811 ov2740_stop_streaming(ov2740);
815 ov2740_stop_streaming(ov2740);
819 ov2740->streaming = enable;
820 mutex_unlock(&ov2740->mutex);
828 struct ov2740 *ov2740 = to_ov2740(sd);
830 mutex_lock(&ov2740->mutex);
831 if (ov2740->streaming)
832 ov2740_stop_streaming(ov2740);
834 mutex_unlock(&ov2740->mutex);
842 struct ov2740 *ov2740 = to_ov2740(sd);
845 mutex_lock(&ov2740->mutex);
846 if (!ov2740->streaming)
849 ret = ov2740_start_streaming(ov2740);
851 ov2740->streaming = false;
852 ov2740_stop_streaming(ov2740);
856 mutex_unlock(&ov2740->mutex);
864 struct ov2740 *ov2740 = to_ov2740(sd);
873 mutex_lock(&ov2740->mutex);
878 ov2740->cur_mode = mode;
879 __v4l2_ctrl_s_ctrl(ov2740->link_freq, mode->link_freq_index);
880 __v4l2_ctrl_s_ctrl_int64(ov2740->pixel_rate,
885 __v4l2_ctrl_modify_range(ov2740->vblank,
889 __v4l2_ctrl_s_ctrl(ov2740->vblank, vblank_def);
892 __v4l2_ctrl_modify_range(ov2740->hblank, h_blank, h_blank, 1,
895 mutex_unlock(&ov2740->mutex);
904 struct ov2740 *ov2740 = to_ov2740(sd);
906 mutex_lock(&ov2740->mutex);
908 fmt->format = *v4l2_subdev_get_try_format(&ov2740->sd,
912 ov2740_update_pad_format(ov2740->cur_mode, &fmt->format);
914 mutex_unlock(&ov2740->mutex);
951 struct ov2740 *ov2740 = to_ov2740(sd);
953 mutex_lock(&ov2740->mutex);
956 mutex_unlock(&ov2740->mutex);
1050 struct ov2740 *ov2740 = to_ov2740(sd);
1056 mutex_destroy(&ov2740->mutex);
1064 struct ov2740 *ov2740 = to_ov2740(dev_get_drvdata(dev));
1067 mutex_lock(&ov2740->mutex);
1085 mutex_unlock(&ov2740->mutex);
1090 struct ov2740 *ov2740)
1129 ov2740->nvm = nvm;
1136 struct ov2740 *ov2740;
1144 ov2740 = devm_kzalloc(&client->dev, sizeof(*ov2740), GFP_KERNEL);
1145 if (!ov2740)
1148 v4l2_i2c_subdev_init(&ov2740->sd, client, &ov2740_subdev_ops);
1151 ret = ov2740_identify_module(ov2740);
1156 mutex_init(&ov2740->mutex);
1157 ov2740->cur_mode = &supported_modes[0];
1158 ret = ov2740_init_controls(ov2740);
1164 ov2740->sd.internal_ops = &ov2740_internal_ops;
1165 ov2740->sd.flags |= V4L2_SUBDEV_FL_HAS_DEVNODE;
1166 ov2740->sd.entity.ops = &ov2740_subdev_entity_ops;
1167 ov2740->sd.entity.function = MEDIA_ENT_F_CAM_SENSOR;
1168 ov2740->pad.flags = MEDIA_PAD_FL_SOURCE;
1169 ret = media_entity_pads_init(&ov2740->sd.entity, 1, &ov2740->pad);
1175 ret = v4l2_async_register_subdev_sensor(&ov2740->sd);
1181 ret = ov2740_register_nvmem(client, ov2740);
1194 media_entity_cleanup(&ov2740->sd.entity);
1197 v4l2_ctrl_handler_free(ov2740->sd.ctrl_handler);
1198 mutex_destroy(&ov2740->mutex);
1214 .name = "ov2740",