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