Lines Matching full:ov2685
3 * ov2685 driver
88 struct ov2685 { struct
108 #define to_ov2685(sd) container_of(sd, struct ov2685, subdev) argument
347 struct ov2685 *ov2685 = to_ov2685(sd); in ov2685_set_fmt() local
351 ov2685_fill_fmt(ov2685->cur_mode, mbus_fmt); in ov2685_set_fmt()
360 struct ov2685 *ov2685 = to_ov2685(sd); in ov2685_get_fmt() local
363 ov2685_fill_fmt(ov2685->cur_mode, mbus_fmt); in ov2685_get_fmt()
400 __ov2685_get_pad_crop(struct ov2685 *ov2685, in __ov2685_get_pad_crop() argument
404 const struct ov2685_mode *mode = ov2685->cur_mode; in __ov2685_get_pad_crop()
408 return v4l2_subdev_get_try_crop(&ov2685->subdev, state, pad); in __ov2685_get_pad_crop()
420 struct ov2685 *ov2685 = to_ov2685(sd); in ov2685_get_selection() local
424 mutex_lock(&ov2685->mutex); in ov2685_get_selection()
425 sel->r = *__ov2685_get_pad_crop(ov2685, sd_state, sel->pad, in ov2685_get_selection()
427 mutex_unlock(&ov2685->mutex); in ov2685_get_selection()
452 static int __ov2685_power_on(struct ov2685 *ov2685) in __ov2685_power_on() argument
456 struct device *dev = &ov2685->client->dev; in __ov2685_power_on()
458 ret = clk_prepare_enable(ov2685->xvclk); in __ov2685_power_on()
464 gpiod_set_value_cansleep(ov2685->reset_gpio, 1); in __ov2685_power_on()
466 ret = regulator_bulk_enable(OV2685_NUM_SUPPLIES, ov2685->supplies); in __ov2685_power_on()
473 gpiod_set_value_cansleep(ov2685->reset_gpio, 0); in __ov2685_power_on()
478 /* HACK: ov2685 would output messy data after reset(R0103), in __ov2685_power_on()
481 ret = ov2685_write_array(ov2685->client, ov2685->cur_mode->reg_list); in __ov2685_power_on()
490 regulator_bulk_disable(OV2685_NUM_SUPPLIES, ov2685->supplies); in __ov2685_power_on()
492 clk_disable_unprepare(ov2685->xvclk); in __ov2685_power_on()
497 static void __ov2685_power_off(struct ov2685 *ov2685) in __ov2685_power_off() argument
503 clk_disable_unprepare(ov2685->xvclk); in __ov2685_power_off()
504 gpiod_set_value_cansleep(ov2685->reset_gpio, 1); in __ov2685_power_off()
505 regulator_bulk_disable(OV2685_NUM_SUPPLIES, ov2685->supplies); in __ov2685_power_off()
510 struct ov2685 *ov2685 = to_ov2685(sd); in ov2685_s_stream() local
511 struct i2c_client *client = ov2685->client; in ov2685_s_stream()
514 mutex_lock(&ov2685->mutex); in ov2685_s_stream()
517 if (on == ov2685->streaming) in ov2685_s_stream()
521 ret = pm_runtime_resume_and_get(&ov2685->client->dev); in ov2685_s_stream()
525 ret = __v4l2_ctrl_handler_setup(&ov2685->ctrl_handler); in ov2685_s_stream()
539 pm_runtime_put(&ov2685->client->dev); in ov2685_s_stream()
542 ov2685->streaming = on; in ov2685_s_stream()
545 mutex_unlock(&ov2685->mutex); in ov2685_s_stream()
553 struct ov2685 *ov2685 = to_ov2685(sd); in ov2685_open() local
556 mutex_lock(&ov2685->mutex); in ov2685_open()
562 mutex_unlock(&ov2685->mutex); in ov2685_open()
571 struct ov2685 *ov2685 = to_ov2685(sd); in ov2685_runtime_resume() local
573 return __ov2685_power_on(ov2685); in ov2685_runtime_resume()
579 struct ov2685 *ov2685 = to_ov2685(sd); in ov2685_runtime_suspend() local
581 __ov2685_power_off(ov2685); in ov2685_runtime_suspend()
593 struct ov2685 *ov2685 = container_of(ctrl->handler, in ov2685_set_ctrl() local
594 struct ov2685, ctrl_handler); in ov2685_set_ctrl()
595 struct i2c_client *client = ov2685->client; in ov2685_set_ctrl()
603 max_expo = ov2685->cur_mode->height + ctrl->val - 4; in ov2685_set_ctrl()
604 __v4l2_ctrl_modify_range(ov2685->exposure, in ov2685_set_ctrl()
605 ov2685->exposure->minimum, max_expo, in ov2685_set_ctrl()
606 ov2685->exposure->step, in ov2685_set_ctrl()
607 ov2685->exposure->default_value); in ov2685_set_ctrl()
616 ret = ov2685_write_reg(ov2685->client, OV2685_REG_EXPOSURE, in ov2685_set_ctrl()
620 ret = ov2685_write_reg(ov2685->client, OV2685_REG_GAIN, in ov2685_set_ctrl()
624 ret = ov2685_write_reg(ov2685->client, OV2685_REG_VTS, in ov2685_set_ctrl()
626 ctrl->val + ov2685->cur_mode->height); in ov2685_set_ctrl()
629 ret = ov2685_write_reg(ov2685->client, OV2685_REG_TEST_PATTERN, in ov2685_set_ctrl()
673 static int ov2685_initialize_controls(struct ov2685 *ov2685) in ov2685_initialize_controls() argument
683 handler = &ov2685->ctrl_handler; in ov2685_initialize_controls()
684 mode = ov2685->cur_mode; in ov2685_initialize_controls()
688 handler->lock = &ov2685->mutex; in ov2685_initialize_controls()
701 ov2685->hblank = v4l2_ctrl_new_std(handler, NULL, V4L2_CID_HBLANK, in ov2685_initialize_controls()
703 if (ov2685->hblank) in ov2685_initialize_controls()
704 ov2685->hblank->flags |= V4L2_CTRL_FLAG_READ_ONLY; in ov2685_initialize_controls()
706 ov2685->vblank = v4l2_ctrl_new_std(handler, &ov2685_ctrl_ops, in ov2685_initialize_controls()
712 ov2685->exposure = v4l2_ctrl_new_std(handler, &ov2685_ctrl_ops, in ov2685_initialize_controls()
717 ov2685->anal_gain = v4l2_ctrl_new_std(handler, &ov2685_ctrl_ops, in ov2685_initialize_controls()
722 ov2685->test_pattern = v4l2_ctrl_new_std_menu_items(handler, in ov2685_initialize_controls()
728 ret = v4l2_fwnode_device_parse(&ov2685->client->dev, &props); in ov2685_initialize_controls()
738 dev_err(&ov2685->client->dev, in ov2685_initialize_controls()
743 ov2685->subdev.ctrl_handler = handler; in ov2685_initialize_controls()
753 static int ov2685_check_sensor_id(struct ov2685 *ov2685, in ov2685_check_sensor_id() argument
756 struct device *dev = &ov2685->client->dev; in ov2685_check_sensor_id()
772 static int ov2685_configure_regulators(struct ov2685 *ov2685) in ov2685_configure_regulators() argument
777 ov2685->supplies[i].supply = ov2685_supply_names[i]; in ov2685_configure_regulators()
779 return devm_regulator_bulk_get(&ov2685->client->dev, in ov2685_configure_regulators()
781 ov2685->supplies); in ov2685_configure_regulators()
787 struct ov2685 *ov2685; in ov2685_probe() local
790 ov2685 = devm_kzalloc(dev, sizeof(*ov2685), GFP_KERNEL); in ov2685_probe()
791 if (!ov2685) in ov2685_probe()
794 ov2685->client = client; in ov2685_probe()
795 ov2685->cur_mode = &supported_modes[0]; in ov2685_probe()
797 ov2685->xvclk = devm_clk_get(dev, "xvclk"); in ov2685_probe()
798 if (IS_ERR(ov2685->xvclk)) { in ov2685_probe()
802 ret = clk_set_rate(ov2685->xvclk, OV2685_XVCLK_FREQ); in ov2685_probe()
807 if (clk_get_rate(ov2685->xvclk) != OV2685_XVCLK_FREQ) in ov2685_probe()
810 ov2685->reset_gpio = devm_gpiod_get_optional(dev, "reset", GPIOD_OUT_LOW); in ov2685_probe()
811 if (IS_ERR(ov2685->reset_gpio)) { in ov2685_probe()
816 ret = ov2685_configure_regulators(ov2685); in ov2685_probe()
822 mutex_init(&ov2685->mutex); in ov2685_probe()
823 v4l2_i2c_subdev_init(&ov2685->subdev, client, &ov2685_subdev_ops); in ov2685_probe()
824 ret = ov2685_initialize_controls(ov2685); in ov2685_probe()
828 ret = __ov2685_power_on(ov2685); in ov2685_probe()
832 ret = ov2685_check_sensor_id(ov2685, client); in ov2685_probe()
837 ov2685->subdev.internal_ops = &ov2685_internal_ops; in ov2685_probe()
838 ov2685->subdev.flags |= V4L2_SUBDEV_FL_HAS_DEVNODE; in ov2685_probe()
841 ov2685->pad.flags = MEDIA_PAD_FL_SOURCE; in ov2685_probe()
842 ov2685->subdev.entity.function = MEDIA_ENT_F_CAM_SENSOR; in ov2685_probe()
843 ret = media_entity_pads_init(&ov2685->subdev.entity, 1, &ov2685->pad); in ov2685_probe()
848 ret = v4l2_async_register_subdev(&ov2685->subdev); in ov2685_probe()
862 media_entity_cleanup(&ov2685->subdev.entity); in ov2685_probe()
865 __ov2685_power_off(ov2685); in ov2685_probe()
867 v4l2_ctrl_handler_free(&ov2685->ctrl_handler); in ov2685_probe()
869 mutex_destroy(&ov2685->mutex); in ov2685_probe()
877 struct ov2685 *ov2685 = to_ov2685(sd); in ov2685_remove() local
883 v4l2_ctrl_handler_free(&ov2685->ctrl_handler); in ov2685_remove()
884 mutex_destroy(&ov2685->mutex); in ov2685_remove()
888 __ov2685_power_off(ov2685); in ov2685_remove()
894 { .compatible = "ovti,ov2685" },
902 .name = "ov2685",
912 MODULE_DESCRIPTION("OmniVision ov2685 sensor driver");