Lines Matching full:ov5675
81 #define to_ov5675(_sd) container_of(_sd, struct ov5675, sd)
495 struct ov5675 { struct
538 static int ov5675_read_reg(struct ov5675 *ov5675, u16 reg, u16 len, u32 *val) in ov5675_read_reg() argument
540 struct i2c_client *client = v4l2_get_subdevdata(&ov5675->sd); in ov5675_read_reg()
568 static int ov5675_write_reg(struct ov5675 *ov5675, u16 reg, u16 len, u32 val) in ov5675_write_reg() argument
570 struct i2c_client *client = v4l2_get_subdevdata(&ov5675->sd); in ov5675_write_reg()
584 static int ov5675_write_reg_list(struct ov5675 *ov5675, in ov5675_write_reg_list() argument
587 struct i2c_client *client = v4l2_get_subdevdata(&ov5675->sd); in ov5675_write_reg_list()
592 ret = ov5675_write_reg(ov5675, r_list->regs[i].address, 1, in ov5675_write_reg_list()
605 static int ov5675_update_digital_gain(struct ov5675 *ov5675, u32 d_gain) in ov5675_update_digital_gain() argument
609 ret = ov5675_write_reg(ov5675, OV5675_REG_GROUP_ACCESS, in ov5675_update_digital_gain()
615 ret = ov5675_write_reg(ov5675, OV5675_REG_MWB_R_GAIN, in ov5675_update_digital_gain()
620 ret = ov5675_write_reg(ov5675, OV5675_REG_MWB_G_GAIN, in ov5675_update_digital_gain()
625 ret = ov5675_write_reg(ov5675, OV5675_REG_MWB_B_GAIN, in ov5675_update_digital_gain()
630 ret = ov5675_write_reg(ov5675, OV5675_REG_GROUP_ACCESS, in ov5675_update_digital_gain()
636 ret = ov5675_write_reg(ov5675, OV5675_REG_GROUP_ACCESS, in ov5675_update_digital_gain()
642 static int ov5675_test_pattern(struct ov5675 *ov5675, u32 pattern) in ov5675_test_pattern() argument
648 return ov5675_write_reg(ov5675, OV5675_REG_TEST_PATTERN, in ov5675_test_pattern()
653 * OV5675 supports keeping the pixel order by mirror and flip function
656 static int ov5675_set_ctrl_hflip(struct ov5675 *ov5675, u32 ctrl_val) in ov5675_set_ctrl_hflip() argument
661 ret = ov5675_read_reg(ov5675, OV5675_REG_FORMAT1, in ov5675_set_ctrl_hflip()
666 return ov5675_write_reg(ov5675, OV5675_REG_FORMAT1, in ov5675_set_ctrl_hflip()
671 static int ov5675_set_ctrl_vflip(struct ov5675 *ov5675, u8 ctrl_val) in ov5675_set_ctrl_vflip() argument
676 ret = ov5675_read_reg(ov5675, OV5675_REG_FORMAT1, in ov5675_set_ctrl_vflip()
681 ret = ov5675_write_reg(ov5675, OV5675_REG_FORMAT1, in ov5675_set_ctrl_vflip()
688 ret = ov5675_read_reg(ov5675, OV5675_REG_FORMAT2, in ov5675_set_ctrl_vflip()
694 return ov5675_write_reg(ov5675, OV5675_REG_FORMAT2, in ov5675_set_ctrl_vflip()
701 struct ov5675 *ov5675 = container_of(ctrl->handler, in ov5675_set_ctrl() local
702 struct ov5675, ctrl_handler); in ov5675_set_ctrl()
703 struct i2c_client *client = v4l2_get_subdevdata(&ov5675->sd); in ov5675_set_ctrl()
710 exposure_max = ov5675->cur_mode->height + ctrl->val - in ov5675_set_ctrl()
712 __v4l2_ctrl_modify_range(ov5675->exposure, in ov5675_set_ctrl()
713 ov5675->exposure->minimum, in ov5675_set_ctrl()
714 exposure_max, ov5675->exposure->step, in ov5675_set_ctrl()
724 ret = ov5675_write_reg(ov5675, OV5675_REG_ANALOG_GAIN, in ov5675_set_ctrl()
729 ret = ov5675_update_digital_gain(ov5675, ctrl->val); in ov5675_set_ctrl()
735 * for ov5675, the unit of exposure is differnt from other in ov5675_set_ctrl()
740 ret = ov5675_write_reg(ov5675, OV5675_REG_EXPOSURE, in ov5675_set_ctrl()
745 ret = ov5675_write_reg(ov5675, OV5675_REG_VTS, in ov5675_set_ctrl()
747 ov5675->cur_mode->height + ctrl->val + in ov5675_set_ctrl()
752 ret = ov5675_test_pattern(ov5675, ctrl->val); in ov5675_set_ctrl()
756 ov5675_set_ctrl_hflip(ov5675, ctrl->val); in ov5675_set_ctrl()
760 ov5675_set_ctrl_vflip(ov5675, ctrl->val); in ov5675_set_ctrl()
777 static int ov5675_init_controls(struct ov5675 *ov5675) in ov5675_init_controls() argument
779 struct i2c_client *client = v4l2_get_subdevdata(&ov5675->sd); in ov5675_init_controls()
785 ctrl_hdlr = &ov5675->ctrl_handler; in ov5675_init_controls()
790 ctrl_hdlr->lock = &ov5675->mutex; in ov5675_init_controls()
791 ov5675->link_freq = v4l2_ctrl_new_int_menu(ctrl_hdlr, &ov5675_ctrl_ops, in ov5675_init_controls()
795 if (ov5675->link_freq) in ov5675_init_controls()
796 ov5675->link_freq->flags |= V4L2_CTRL_FLAG_READ_ONLY; in ov5675_init_controls()
798 ov5675->pixel_rate = v4l2_ctrl_new_std(ctrl_hdlr, &ov5675_ctrl_ops, in ov5675_init_controls()
803 ov5675->vblank = v4l2_ctrl_new_std(ctrl_hdlr, &ov5675_ctrl_ops, in ov5675_init_controls()
805 ov5675->cur_mode->vts_min - ov5675->cur_mode->height, in ov5675_init_controls()
806 OV5675_VTS_MAX - ov5675->cur_mode->height, 1, in ov5675_init_controls()
807 ov5675->cur_mode->vts_def - ov5675->cur_mode->height); in ov5675_init_controls()
808 h_blank = to_pixels_per_line(ov5675->cur_mode->hts, in ov5675_init_controls()
809 ov5675->cur_mode->link_freq_index) - ov5675->cur_mode->width; in ov5675_init_controls()
810 ov5675->hblank = v4l2_ctrl_new_std(ctrl_hdlr, &ov5675_ctrl_ops, in ov5675_init_controls()
813 if (ov5675->hblank) in ov5675_init_controls()
814 ov5675->hblank->flags |= V4L2_CTRL_FLAG_READ_ONLY; in ov5675_init_controls()
822 exposure_max = (ov5675->cur_mode->vts_def - OV5675_EXPOSURE_MAX_MARGIN); in ov5675_init_controls()
823 ov5675->exposure = v4l2_ctrl_new_std(ctrl_hdlr, &ov5675_ctrl_ops, in ov5675_init_controls()
851 ov5675->sd.ctrl_handler = ctrl_hdlr; in ov5675_init_controls()
870 static int ov5675_identify_module(struct ov5675 *ov5675) in ov5675_identify_module() argument
872 struct i2c_client *client = v4l2_get_subdevdata(&ov5675->sd); in ov5675_identify_module()
876 if (ov5675->identified) in ov5675_identify_module()
879 ret = ov5675_read_reg(ov5675, OV5675_REG_CHIP_ID, in ov5675_identify_module()
890 ov5675->identified = true; in ov5675_identify_module()
895 static int ov5675_start_streaming(struct ov5675 *ov5675) in ov5675_start_streaming() argument
897 struct i2c_client *client = v4l2_get_subdevdata(&ov5675->sd); in ov5675_start_streaming()
901 ret = ov5675_identify_module(ov5675); in ov5675_start_streaming()
905 link_freq_index = ov5675->cur_mode->link_freq_index; in ov5675_start_streaming()
907 ret = ov5675_write_reg_list(ov5675, reg_list); in ov5675_start_streaming()
913 reg_list = &ov5675->cur_mode->reg_list; in ov5675_start_streaming()
914 ret = ov5675_write_reg_list(ov5675, reg_list); in ov5675_start_streaming()
920 ret = __v4l2_ctrl_handler_setup(ov5675->sd.ctrl_handler); in ov5675_start_streaming()
924 ret = ov5675_write_reg(ov5675, OV5675_REG_MODE_SELECT, in ov5675_start_streaming()
934 static void ov5675_stop_streaming(struct ov5675 *ov5675) in ov5675_stop_streaming() argument
936 struct i2c_client *client = v4l2_get_subdevdata(&ov5675->sd); in ov5675_stop_streaming()
938 if (ov5675_write_reg(ov5675, OV5675_REG_MODE_SELECT, in ov5675_stop_streaming()
945 struct ov5675 *ov5675 = to_ov5675(sd); in ov5675_set_stream() local
949 mutex_lock(&ov5675->mutex); in ov5675_set_stream()
953 mutex_unlock(&ov5675->mutex); in ov5675_set_stream()
957 ret = ov5675_start_streaming(ov5675); in ov5675_set_stream()
960 ov5675_stop_streaming(ov5675); in ov5675_set_stream()
964 ov5675_stop_streaming(ov5675); in ov5675_set_stream()
968 mutex_unlock(&ov5675->mutex); in ov5675_set_stream()
976 struct ov5675 *ov5675 = to_ov5675(sd); in ov5675_power_off() local
980 clk_disable_unprepare(ov5675->xvclk); in ov5675_power_off()
981 gpiod_set_value_cansleep(ov5675->reset_gpio, 1); in ov5675_power_off()
982 regulator_bulk_disable(OV5675_NUM_SUPPLIES, ov5675->supplies); in ov5675_power_off()
990 struct ov5675 *ov5675 = to_ov5675(sd); in ov5675_power_on() local
993 ret = clk_prepare_enable(ov5675->xvclk); in ov5675_power_on()
999 gpiod_set_value_cansleep(ov5675->reset_gpio, 1); in ov5675_power_on()
1001 ret = regulator_bulk_enable(OV5675_NUM_SUPPLIES, ov5675->supplies); in ov5675_power_on()
1003 clk_disable_unprepare(ov5675->xvclk); in ov5675_power_on()
1012 gpiod_set_value_cansleep(ov5675->reset_gpio, 0); in ov5675_power_on()
1027 struct ov5675 *ov5675 = to_ov5675(sd); in ov5675_set_format() local
1036 mutex_lock(&ov5675->mutex); in ov5675_set_format()
1041 ov5675->cur_mode = mode; in ov5675_set_format()
1042 __v4l2_ctrl_s_ctrl(ov5675->link_freq, mode->link_freq_index); in ov5675_set_format()
1043 __v4l2_ctrl_s_ctrl_int64(ov5675->pixel_rate, in ov5675_set_format()
1048 __v4l2_ctrl_modify_range(ov5675->vblank, in ov5675_set_format()
1052 __v4l2_ctrl_s_ctrl(ov5675->vblank, vblank_def); in ov5675_set_format()
1055 __v4l2_ctrl_modify_range(ov5675->hblank, h_blank, h_blank, 1, in ov5675_set_format()
1059 mutex_unlock(&ov5675->mutex); in ov5675_set_format()
1068 struct ov5675 *ov5675 = to_ov5675(sd); in ov5675_get_format() local
1070 mutex_lock(&ov5675->mutex); in ov5675_get_format()
1075 ov5675_update_pad_format(ov5675->cur_mode, &fmt->format); in ov5675_get_format()
1077 mutex_unlock(&ov5675->mutex); in ov5675_get_format()
1139 struct ov5675 *ov5675 = to_ov5675(sd); in ov5675_open() local
1141 mutex_lock(&ov5675->mutex); in ov5675_open()
1144 mutex_unlock(&ov5675->mutex); in ov5675_open()
1174 static int ov5675_get_hwcfg(struct ov5675 *ov5675, struct device *dev) in ov5675_get_hwcfg() argument
1188 ov5675->xvclk = devm_clk_get_optional(dev, NULL); in ov5675_get_hwcfg()
1189 if (IS_ERR(ov5675->xvclk)) in ov5675_get_hwcfg()
1190 return dev_err_probe(dev, PTR_ERR(ov5675->xvclk), in ov5675_get_hwcfg()
1192 PTR_ERR(ov5675->xvclk)); in ov5675_get_hwcfg()
1194 if (ov5675->xvclk) { in ov5675_get_hwcfg()
1195 xvclk_rate = clk_get_rate(ov5675->xvclk); in ov5675_get_hwcfg()
1212 ov5675->reset_gpio = devm_gpiod_get_optional(dev, "reset", in ov5675_get_hwcfg()
1214 if (IS_ERR(ov5675->reset_gpio)) { in ov5675_get_hwcfg()
1215 ret = PTR_ERR(ov5675->reset_gpio); in ov5675_get_hwcfg()
1221 ov5675->supplies[i].supply = ov5675_supply_names[i]; in ov5675_get_hwcfg()
1224 ov5675->supplies); in ov5675_get_hwcfg()
1274 struct ov5675 *ov5675 = to_ov5675(sd); in ov5675_remove() local
1280 mutex_destroy(&ov5675->mutex); in ov5675_remove()
1289 struct ov5675 *ov5675; in ov5675_probe() local
1293 ov5675 = devm_kzalloc(&client->dev, sizeof(*ov5675), GFP_KERNEL); in ov5675_probe()
1294 if (!ov5675) in ov5675_probe()
1297 ret = ov5675_get_hwcfg(ov5675, &client->dev); in ov5675_probe()
1304 v4l2_i2c_subdev_init(&ov5675->sd, client, &ov5675_subdev_ops); in ov5675_probe()
1314 ret = ov5675_identify_module(ov5675); in ov5675_probe()
1321 mutex_init(&ov5675->mutex); in ov5675_probe()
1322 ov5675->cur_mode = &supported_modes[0]; in ov5675_probe()
1323 ret = ov5675_init_controls(ov5675); in ov5675_probe()
1329 ov5675->sd.internal_ops = &ov5675_internal_ops; in ov5675_probe()
1330 ov5675->sd.flags |= V4L2_SUBDEV_FL_HAS_DEVNODE; in ov5675_probe()
1331 ov5675->sd.entity.ops = &ov5675_subdev_entity_ops; in ov5675_probe()
1332 ov5675->sd.entity.function = MEDIA_ENT_F_CAM_SENSOR; in ov5675_probe()
1333 ov5675->pad.flags = MEDIA_PAD_FL_SOURCE; in ov5675_probe()
1334 ret = media_entity_pads_init(&ov5675->sd.entity, 1, &ov5675->pad); in ov5675_probe()
1340 ret = v4l2_async_register_subdev_sensor(&ov5675->sd); in ov5675_probe()
1356 media_entity_cleanup(&ov5675->sd.entity); in ov5675_probe()
1359 v4l2_ctrl_handler_free(ov5675->sd.ctrl_handler); in ov5675_probe()
1360 mutex_destroy(&ov5675->mutex); in ov5675_probe()
1381 { .compatible = "ovti,ov5675", },
1388 .name = "ov5675",
1401 MODULE_DESCRIPTION("OmniVision OV5675 sensor driver");