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