Lines Matching defs:ov5675

81 #define to_ov5675(_sd)			container_of(_sd, struct ov5675, sd)
495 struct ov5675 {
541 static int ov5675_read_reg(struct ov5675 *ov5675, u16 reg, u16 len, u32 *val)
543 struct i2c_client *client = v4l2_get_subdevdata(&ov5675->sd);
571 static int ov5675_write_reg(struct ov5675 *ov5675, u16 reg, u16 len, u32 val)
573 struct i2c_client *client = v4l2_get_subdevdata(&ov5675->sd);
587 static int ov5675_write_reg_list(struct ov5675 *ov5675,
590 struct i2c_client *client = v4l2_get_subdevdata(&ov5675->sd);
595 ret = ov5675_write_reg(ov5675, r_list->regs[i].address, 1,
608 static int ov5675_update_digital_gain(struct ov5675 *ov5675, u32 d_gain)
612 ret = ov5675_write_reg(ov5675, OV5675_REG_GROUP_ACCESS,
618 ret = ov5675_write_reg(ov5675, OV5675_REG_MWB_R_GAIN,
623 ret = ov5675_write_reg(ov5675, OV5675_REG_MWB_G_GAIN,
628 ret = ov5675_write_reg(ov5675, OV5675_REG_MWB_B_GAIN,
633 ret = ov5675_write_reg(ov5675, OV5675_REG_GROUP_ACCESS,
639 ret = ov5675_write_reg(ov5675, OV5675_REG_GROUP_ACCESS,
645 static int ov5675_test_pattern(struct ov5675 *ov5675, u32 pattern)
651 return ov5675_write_reg(ov5675, OV5675_REG_TEST_PATTERN,
659 static int ov5675_set_ctrl_hflip(struct ov5675 *ov5675, u32 ctrl_val)
664 ret = ov5675_read_reg(ov5675, OV5675_REG_FORMAT1,
669 return ov5675_write_reg(ov5675, OV5675_REG_FORMAT1,
674 static int ov5675_set_ctrl_vflip(struct ov5675 *ov5675, u8 ctrl_val)
679 ret = ov5675_read_reg(ov5675, OV5675_REG_FORMAT1,
684 ret = ov5675_write_reg(ov5675, OV5675_REG_FORMAT1,
691 ret = ov5675_read_reg(ov5675, OV5675_REG_FORMAT2,
697 return ov5675_write_reg(ov5675, OV5675_REG_FORMAT2,
704 struct ov5675 *ov5675 = container_of(ctrl->handler,
705 struct ov5675, ctrl_handler);
706 struct i2c_client *client = v4l2_get_subdevdata(&ov5675->sd);
713 exposure_max = ov5675->cur_mode->height + ctrl->val -
715 __v4l2_ctrl_modify_range(ov5675->exposure,
716 ov5675->exposure->minimum,
717 exposure_max, ov5675->exposure->step,
727 ret = ov5675_write_reg(ov5675, OV5675_REG_ANALOG_GAIN,
732 ret = ov5675_update_digital_gain(ov5675, ctrl->val);
738 * for ov5675, the unit of exposure is differnt from other
743 ret = ov5675_write_reg(ov5675, OV5675_REG_EXPOSURE,
748 ret = ov5675_write_reg(ov5675, OV5675_REG_VTS,
750 ov5675->cur_mode->height + ctrl->val +
755 ret = ov5675_test_pattern(ov5675, ctrl->val);
759 ov5675_set_ctrl_hflip(ov5675, ctrl->val);
763 ov5675_set_ctrl_vflip(ov5675, ctrl->val);
780 static int ov5675_init_controls(struct ov5675 *ov5675)
782 struct i2c_client *client = v4l2_get_subdevdata(&ov5675->sd);
788 ctrl_hdlr = &ov5675->ctrl_handler;
793 ctrl_hdlr->lock = &ov5675->mutex;
794 ov5675->link_freq = v4l2_ctrl_new_int_menu(ctrl_hdlr, &ov5675_ctrl_ops,
798 if (ov5675->link_freq)
799 ov5675->link_freq->flags |= V4L2_CTRL_FLAG_READ_ONLY;
801 ov5675->pixel_rate = v4l2_ctrl_new_std(ctrl_hdlr, &ov5675_ctrl_ops,
806 ov5675->vblank = v4l2_ctrl_new_std(ctrl_hdlr, &ov5675_ctrl_ops,
808 ov5675->cur_mode->vts_min - ov5675->cur_mode->height,
809 OV5675_VTS_MAX - ov5675->cur_mode->height, 1,
810 ov5675->cur_mode->vts_def - ov5675->cur_mode->height);
811 h_blank = to_pixels_per_line(ov5675->cur_mode->hts,
812 ov5675->cur_mode->link_freq_index) - ov5675->cur_mode->width;
813 ov5675->hblank = v4l2_ctrl_new_std(ctrl_hdlr, &ov5675_ctrl_ops,
816 if (ov5675->hblank)
817 ov5675->hblank->flags |= V4L2_CTRL_FLAG_READ_ONLY;
825 exposure_max = (ov5675->cur_mode->vts_def - OV5675_EXPOSURE_MAX_MARGIN);
826 ov5675->exposure = v4l2_ctrl_new_std(ctrl_hdlr, &ov5675_ctrl_ops,
854 ov5675->sd.ctrl_handler = ctrl_hdlr;
873 static int ov5675_identify_module(struct ov5675 *ov5675)
875 struct i2c_client *client = v4l2_get_subdevdata(&ov5675->sd);
879 if (ov5675->identified)
882 ret = ov5675_read_reg(ov5675, OV5675_REG_CHIP_ID,
893 ov5675->identified = true;
898 static int ov5675_start_streaming(struct ov5675 *ov5675)
900 struct i2c_client *client = v4l2_get_subdevdata(&ov5675->sd);
904 ret = ov5675_identify_module(ov5675);
908 link_freq_index = ov5675->cur_mode->link_freq_index;
910 ret = ov5675_write_reg_list(ov5675, reg_list);
916 reg_list = &ov5675->cur_mode->reg_list;
917 ret = ov5675_write_reg_list(ov5675, reg_list);
923 ret = __v4l2_ctrl_handler_setup(ov5675->sd.ctrl_handler);
927 ret = ov5675_write_reg(ov5675, OV5675_REG_MODE_SELECT,
937 static void ov5675_stop_streaming(struct ov5675 *ov5675)
939 struct i2c_client *client = v4l2_get_subdevdata(&ov5675->sd);
941 if (ov5675_write_reg(ov5675, OV5675_REG_MODE_SELECT,
948 struct ov5675 *ov5675 = to_ov5675(sd);
952 if (ov5675->streaming == enable)
955 mutex_lock(&ov5675->mutex);
959 mutex_unlock(&ov5675->mutex);
963 ret = ov5675_start_streaming(ov5675);
966 ov5675_stop_streaming(ov5675);
970 ov5675_stop_streaming(ov5675);
974 ov5675->streaming = enable;
975 mutex_unlock(&ov5675->mutex);
985 struct ov5675 *ov5675 = to_ov5675(sd);
989 clk_disable_unprepare(ov5675->xvclk);
990 gpiod_set_value_cansleep(ov5675->reset_gpio, 1);
991 regulator_bulk_disable(OV5675_NUM_SUPPLIES, ov5675->supplies);
1000 struct ov5675 *ov5675 = to_ov5675(sd);
1003 ret = clk_prepare_enable(ov5675->xvclk);
1009 gpiod_set_value_cansleep(ov5675->reset_gpio, 1);
1011 ret = regulator_bulk_enable(OV5675_NUM_SUPPLIES, ov5675->supplies);
1013 clk_disable_unprepare(ov5675->xvclk);
1022 gpiod_set_value_cansleep(ov5675->reset_gpio, 0);
1033 struct ov5675 *ov5675 = to_ov5675(sd);
1035 mutex_lock(&ov5675->mutex);
1036 if (ov5675->streaming)
1037 ov5675_stop_streaming(ov5675);
1039 mutex_unlock(&ov5675->mutex);
1047 struct ov5675 *ov5675 = to_ov5675(sd);
1050 mutex_lock(&ov5675->mutex);
1051 if (ov5675->streaming) {
1052 ret = ov5675_start_streaming(ov5675);
1054 ov5675->streaming = false;
1055 ov5675_stop_streaming(ov5675);
1056 mutex_unlock(&ov5675->mutex);
1061 mutex_unlock(&ov5675->mutex);
1070 struct ov5675 *ov5675 = to_ov5675(sd);
1079 mutex_lock(&ov5675->mutex);
1084 ov5675->cur_mode = mode;
1085 __v4l2_ctrl_s_ctrl(ov5675->link_freq, mode->link_freq_index);
1086 __v4l2_ctrl_s_ctrl_int64(ov5675->pixel_rate,
1091 __v4l2_ctrl_modify_range(ov5675->vblank,
1095 __v4l2_ctrl_s_ctrl(ov5675->vblank, vblank_def);
1098 __v4l2_ctrl_modify_range(ov5675->hblank, h_blank, h_blank, 1,
1102 mutex_unlock(&ov5675->mutex);
1111 struct ov5675 *ov5675 = to_ov5675(sd);
1113 mutex_lock(&ov5675->mutex);
1115 fmt->format = *v4l2_subdev_get_try_format(&ov5675->sd,
1119 ov5675_update_pad_format(ov5675->cur_mode, &fmt->format);
1121 mutex_unlock(&ov5675->mutex);
1183 struct ov5675 *ov5675 = to_ov5675(sd);
1185 mutex_lock(&ov5675->mutex);
1188 mutex_unlock(&ov5675->mutex);
1218 static int ov5675_get_hwcfg(struct ov5675 *ov5675, struct device *dev)
1232 ov5675->xvclk = devm_clk_get_optional(dev, NULL);
1233 if (IS_ERR(ov5675->xvclk))
1234 return dev_err_probe(dev, PTR_ERR(ov5675->xvclk),
1236 PTR_ERR(ov5675->xvclk));
1238 if (ov5675->xvclk) {
1239 xvclk_rate = clk_get_rate(ov5675->xvclk);
1256 ov5675->reset_gpio = devm_gpiod_get_optional(dev, "reset",
1258 if (IS_ERR(ov5675->reset_gpio)) {
1259 ret = PTR_ERR(ov5675->reset_gpio);
1265 ov5675->supplies[i].supply = ov5675_supply_names[i];
1268 ov5675->supplies);
1318 struct ov5675 *ov5675 = to_ov5675(sd);
1324 mutex_destroy(&ov5675->mutex);
1333 struct ov5675 *ov5675;
1337 ov5675 = devm_kzalloc(&client->dev, sizeof(*ov5675), GFP_KERNEL);
1338 if (!ov5675)
1341 ret = ov5675_get_hwcfg(ov5675, &client->dev);
1348 v4l2_i2c_subdev_init(&ov5675->sd, client, &ov5675_subdev_ops);
1358 ret = ov5675_identify_module(ov5675);
1365 mutex_init(&ov5675->mutex);
1366 ov5675->cur_mode = &supported_modes[0];
1367 ret = ov5675_init_controls(ov5675);
1373 ov5675->sd.internal_ops = &ov5675_internal_ops;
1374 ov5675->sd.flags |= V4L2_SUBDEV_FL_HAS_DEVNODE;
1375 ov5675->sd.entity.ops = &ov5675_subdev_entity_ops;
1376 ov5675->sd.entity.function = MEDIA_ENT_F_CAM_SENSOR;
1377 ov5675->pad.flags = MEDIA_PAD_FL_SOURCE;
1378 ret = media_entity_pads_init(&ov5675->sd.entity, 1, &ov5675->pad);
1384 ret = v4l2_async_register_subdev_sensor(&ov5675->sd);
1400 media_entity_cleanup(&ov5675->sd.entity);
1403 v4l2_ctrl_handler_free(ov5675->sd.ctrl_handler);
1404 mutex_destroy(&ov5675->mutex);
1426 { .compatible = "ovti,ov5675", },
1433 .name = "ov5675",