Lines Matching full:ov2685
3 * ov2685 driver
88 struct ov2685 { struct
107 #define to_ov2685(sd) container_of(sd, struct ov2685, subdev) argument
346 struct ov2685 *ov2685 = to_ov2685(sd); in ov2685_set_fmt() local
350 ov2685_fill_fmt(ov2685->cur_mode, mbus_fmt); in ov2685_set_fmt()
359 struct ov2685 *ov2685 = to_ov2685(sd); in ov2685_get_fmt() local
362 ov2685_fill_fmt(ov2685->cur_mode, mbus_fmt); in ov2685_get_fmt()
399 __ov2685_get_pad_crop(struct ov2685 *ov2685, in __ov2685_get_pad_crop() argument
403 const struct ov2685_mode *mode = ov2685->cur_mode; in __ov2685_get_pad_crop()
419 struct ov2685 *ov2685 = to_ov2685(sd); in ov2685_get_selection() local
423 mutex_lock(&ov2685->mutex); in ov2685_get_selection()
424 sel->r = *__ov2685_get_pad_crop(ov2685, sd_state, sel->pad, in ov2685_get_selection()
426 mutex_unlock(&ov2685->mutex); in ov2685_get_selection()
451 static int __ov2685_power_on(struct ov2685 *ov2685) in __ov2685_power_on() argument
455 struct device *dev = &ov2685->client->dev; in __ov2685_power_on()
457 ret = clk_prepare_enable(ov2685->xvclk); in __ov2685_power_on()
463 gpiod_set_value_cansleep(ov2685->reset_gpio, 1); in __ov2685_power_on()
465 ret = regulator_bulk_enable(OV2685_NUM_SUPPLIES, ov2685->supplies); in __ov2685_power_on()
472 gpiod_set_value_cansleep(ov2685->reset_gpio, 0); in __ov2685_power_on()
477 /* HACK: ov2685 would output messy data after reset(R0103), in __ov2685_power_on()
480 ret = ov2685_write_array(ov2685->client, ov2685->cur_mode->reg_list); in __ov2685_power_on()
489 regulator_bulk_disable(OV2685_NUM_SUPPLIES, ov2685->supplies); in __ov2685_power_on()
491 clk_disable_unprepare(ov2685->xvclk); in __ov2685_power_on()
496 static void __ov2685_power_off(struct ov2685 *ov2685) in __ov2685_power_off() argument
502 clk_disable_unprepare(ov2685->xvclk); in __ov2685_power_off()
503 gpiod_set_value_cansleep(ov2685->reset_gpio, 1); in __ov2685_power_off()
504 regulator_bulk_disable(OV2685_NUM_SUPPLIES, ov2685->supplies); in __ov2685_power_off()
509 struct ov2685 *ov2685 = to_ov2685(sd); in ov2685_s_stream() local
510 struct i2c_client *client = ov2685->client; in ov2685_s_stream()
513 mutex_lock(&ov2685->mutex); in ov2685_s_stream()
516 ret = pm_runtime_resume_and_get(&ov2685->client->dev); in ov2685_s_stream()
520 ret = __v4l2_ctrl_handler_setup(&ov2685->ctrl_handler); in ov2685_s_stream()
534 pm_runtime_put(&ov2685->client->dev); in ov2685_s_stream()
538 mutex_unlock(&ov2685->mutex); in ov2685_s_stream()
545 struct ov2685 *ov2685 = to_ov2685(sd); in ov2685_open() local
548 mutex_lock(&ov2685->mutex); in ov2685_open()
554 mutex_unlock(&ov2685->mutex); in ov2685_open()
562 struct ov2685 *ov2685 = to_ov2685(sd); in ov2685_runtime_resume() local
564 return __ov2685_power_on(ov2685); in ov2685_runtime_resume()
570 struct ov2685 *ov2685 = to_ov2685(sd); in ov2685_runtime_suspend() local
572 __ov2685_power_off(ov2685); in ov2685_runtime_suspend()
584 struct ov2685 *ov2685 = container_of(ctrl->handler, in ov2685_set_ctrl() local
585 struct ov2685, ctrl_handler); in ov2685_set_ctrl()
586 struct i2c_client *client = ov2685->client; in ov2685_set_ctrl()
594 max_expo = ov2685->cur_mode->height + ctrl->val - 4; in ov2685_set_ctrl()
595 __v4l2_ctrl_modify_range(ov2685->exposure, in ov2685_set_ctrl()
596 ov2685->exposure->minimum, max_expo, in ov2685_set_ctrl()
597 ov2685->exposure->step, in ov2685_set_ctrl()
598 ov2685->exposure->default_value); in ov2685_set_ctrl()
607 ret = ov2685_write_reg(ov2685->client, OV2685_REG_EXPOSURE, in ov2685_set_ctrl()
611 ret = ov2685_write_reg(ov2685->client, OV2685_REG_GAIN, in ov2685_set_ctrl()
615 ret = ov2685_write_reg(ov2685->client, OV2685_REG_VTS, in ov2685_set_ctrl()
617 ctrl->val + ov2685->cur_mode->height); in ov2685_set_ctrl()
620 ret = ov2685_write_reg(ov2685->client, OV2685_REG_TEST_PATTERN, in ov2685_set_ctrl()
662 static int ov2685_initialize_controls(struct ov2685 *ov2685) in ov2685_initialize_controls() argument
672 handler = &ov2685->ctrl_handler; in ov2685_initialize_controls()
673 mode = ov2685->cur_mode; in ov2685_initialize_controls()
677 handler->lock = &ov2685->mutex; in ov2685_initialize_controls()
690 ov2685->hblank = v4l2_ctrl_new_std(handler, NULL, V4L2_CID_HBLANK, in ov2685_initialize_controls()
692 if (ov2685->hblank) in ov2685_initialize_controls()
693 ov2685->hblank->flags |= V4L2_CTRL_FLAG_READ_ONLY; in ov2685_initialize_controls()
695 ov2685->vblank = v4l2_ctrl_new_std(handler, &ov2685_ctrl_ops, in ov2685_initialize_controls()
701 ov2685->exposure = v4l2_ctrl_new_std(handler, &ov2685_ctrl_ops, in ov2685_initialize_controls()
706 ov2685->anal_gain = v4l2_ctrl_new_std(handler, &ov2685_ctrl_ops, in ov2685_initialize_controls()
711 ov2685->test_pattern = v4l2_ctrl_new_std_menu_items(handler, in ov2685_initialize_controls()
717 ret = v4l2_fwnode_device_parse(&ov2685->client->dev, &props); in ov2685_initialize_controls()
727 dev_err(&ov2685->client->dev, in ov2685_initialize_controls()
732 ov2685->subdev.ctrl_handler = handler; in ov2685_initialize_controls()
742 static int ov2685_check_sensor_id(struct ov2685 *ov2685, in ov2685_check_sensor_id() argument
745 struct device *dev = &ov2685->client->dev; in ov2685_check_sensor_id()
761 static int ov2685_configure_regulators(struct ov2685 *ov2685) in ov2685_configure_regulators() argument
766 ov2685->supplies[i].supply = ov2685_supply_names[i]; in ov2685_configure_regulators()
768 return devm_regulator_bulk_get(&ov2685->client->dev, in ov2685_configure_regulators()
770 ov2685->supplies); in ov2685_configure_regulators()
776 struct ov2685 *ov2685; in ov2685_probe() local
779 ov2685 = devm_kzalloc(dev, sizeof(*ov2685), GFP_KERNEL); in ov2685_probe()
780 if (!ov2685) in ov2685_probe()
783 ov2685->client = client; in ov2685_probe()
784 ov2685->cur_mode = &supported_modes[0]; in ov2685_probe()
786 ov2685->xvclk = devm_clk_get(dev, "xvclk"); in ov2685_probe()
787 if (IS_ERR(ov2685->xvclk)) { in ov2685_probe()
791 ret = clk_set_rate(ov2685->xvclk, OV2685_XVCLK_FREQ); in ov2685_probe()
796 if (clk_get_rate(ov2685->xvclk) != OV2685_XVCLK_FREQ) in ov2685_probe()
799 ov2685->reset_gpio = devm_gpiod_get_optional(dev, "reset", GPIOD_OUT_LOW); in ov2685_probe()
800 if (IS_ERR(ov2685->reset_gpio)) { in ov2685_probe()
805 ret = ov2685_configure_regulators(ov2685); in ov2685_probe()
811 mutex_init(&ov2685->mutex); in ov2685_probe()
812 v4l2_i2c_subdev_init(&ov2685->subdev, client, &ov2685_subdev_ops); in ov2685_probe()
813 ret = ov2685_initialize_controls(ov2685); in ov2685_probe()
817 ret = __ov2685_power_on(ov2685); in ov2685_probe()
821 ret = ov2685_check_sensor_id(ov2685, client); in ov2685_probe()
825 ov2685->subdev.internal_ops = &ov2685_internal_ops; in ov2685_probe()
826 ov2685->subdev.flags |= V4L2_SUBDEV_FL_HAS_DEVNODE; in ov2685_probe()
827 ov2685->pad.flags = MEDIA_PAD_FL_SOURCE; in ov2685_probe()
828 ov2685->subdev.entity.function = MEDIA_ENT_F_CAM_SENSOR; in ov2685_probe()
829 ret = media_entity_pads_init(&ov2685->subdev.entity, 1, &ov2685->pad); in ov2685_probe()
833 ret = v4l2_async_register_subdev(&ov2685->subdev); in ov2685_probe()
846 media_entity_cleanup(&ov2685->subdev.entity); in ov2685_probe()
848 __ov2685_power_off(ov2685); in ov2685_probe()
850 v4l2_ctrl_handler_free(&ov2685->ctrl_handler); in ov2685_probe()
852 mutex_destroy(&ov2685->mutex); in ov2685_probe()
860 struct ov2685 *ov2685 = to_ov2685(sd); in ov2685_remove() local
864 v4l2_ctrl_handler_free(&ov2685->ctrl_handler); in ov2685_remove()
865 mutex_destroy(&ov2685->mutex); in ov2685_remove()
869 __ov2685_power_off(ov2685); in ov2685_remove()
875 { .compatible = "ovti,ov2685" },
883 .name = "ov2685",
893 MODULE_DESCRIPTION("OmniVision ov2685 sensor driver");