Lines Matching refs:ov5670

1856 struct ov5670 {
1891 #define to_ov5670(_sd) container_of(_sd, struct ov5670, sd)
1894 static int ov5670_read_reg(struct ov5670 *ov5670, u16 reg, unsigned int len,
1897 struct i2c_client *client = v4l2_get_subdevdata(&ov5670->sd);
1930 static int ov5670_write_reg(struct ov5670 *ov5670, u16 reg, unsigned int len,
1933 struct i2c_client *client = v4l2_get_subdevdata(&ov5670->sd);
1961 static int ov5670_write_regs(struct ov5670 *ov5670,
1964 struct i2c_client *client = v4l2_get_subdevdata(&ov5670->sd);
1969 ret = ov5670_write_reg(ov5670, regs[i].address, 1, regs[i].val);
1983 static int ov5670_write_reg_list(struct ov5670 *ov5670,
1986 return ov5670_write_regs(ov5670, r_list->regs, r_list->num_of_regs);
1989 static int ov5670_update_digital_gain(struct ov5670 *ov5670, u32 d_gain)
1993 ret = ov5670_write_reg(ov5670, OV5670_REG_R_DGTL_GAIN,
1998 ret = ov5670_write_reg(ov5670, OV5670_REG_G_DGTL_GAIN,
2003 return ov5670_write_reg(ov5670, OV5670_REG_B_DGTL_GAIN,
2007 static int ov5670_enable_test_pattern(struct ov5670 *ov5670, u32 pattern)
2013 ret = ov5670_write_reg(ov5670, OV5670_REG_TEST_PATTERN_CTRL,
2018 ret = ov5670_read_reg(ov5670, OV5670_REG_TEST_PATTERN,
2028 return ov5670_write_reg(ov5670, OV5670_REG_TEST_PATTERN,
2035 struct ov5670 *ov5670 = container_of(ctrl->handler,
2036 struct ov5670, ctrl_handler);
2037 struct i2c_client *client = v4l2_get_subdevdata(&ov5670->sd);
2045 max = ov5670->cur_mode->height + ctrl->val - 8;
2046 __v4l2_ctrl_modify_range(ov5670->exposure,
2047 ov5670->exposure->minimum, max,
2048 ov5670->exposure->step, max);
2058 ret = ov5670_write_reg(ov5670, OV5670_REG_ANALOG_GAIN,
2062 ret = ov5670_update_digital_gain(ov5670, ctrl->val);
2066 ret = ov5670_write_reg(ov5670, OV5670_REG_EXPOSURE,
2071 ret = ov5670_write_reg(ov5670, OV5670_REG_VTS,
2073 ov5670->cur_mode->height + ctrl->val);
2076 ret = ov5670_enable_test_pattern(ov5670, ctrl->val);
2100 static int ov5670_init_controls(struct ov5670 *ov5670)
2103 &ov5670->endpoint.bus.mipi_csi2;
2104 struct i2c_client *client = v4l2_get_subdevdata(&ov5670->sd);
2115 ctrl_hdlr = &ov5670->ctrl_handler;
2120 ctrl_hdlr->lock = &ov5670->mutex;
2121 ov5670->link_freq = v4l2_ctrl_new_int_menu(ctrl_hdlr,
2125 if (ov5670->link_freq)
2126 ov5670->link_freq->flags |= V4L2_CTRL_FLAG_READ_ONLY;
2132 ov5670->pixel_rate = v4l2_ctrl_new_std(ctrl_hdlr, &ov5670_ctrl_ops,
2139 vblank_max = OV5670_VTS_MAX - ov5670->cur_mode->height;
2140 vblank_def = ov5670->cur_mode->vts_def - ov5670->cur_mode->height;
2141 vblank_min = ov5670->cur_mode->vts_min - ov5670->cur_mode->height;
2142 ov5670->vblank = v4l2_ctrl_new_std(ctrl_hdlr, &ov5670_ctrl_ops,
2146 ov5670->hblank = v4l2_ctrl_new_std(
2148 OV5670_FIXED_PPL - ov5670->cur_mode->width,
2149 OV5670_FIXED_PPL - ov5670->cur_mode->width, 1,
2150 OV5670_FIXED_PPL - ov5670->cur_mode->width);
2151 if (ov5670->hblank)
2152 ov5670->hblank->flags |= V4L2_CTRL_FLAG_READ_ONLY;
2165 exposure_max = ov5670->cur_mode->vts_def - 8;
2166 ov5670->exposure = v4l2_ctrl_new_std(ctrl_hdlr, &ov5670_ctrl_ops,
2191 ov5670->sd.ctrl_handler = ctrl_hdlr;
2263 static int ov5670_do_get_pad_format(struct ov5670 *ov5670,
2268 fmt->format = *v4l2_subdev_get_try_format(&ov5670->sd,
2272 ov5670_update_pad_format(ov5670->cur_mode, fmt);
2281 struct ov5670 *ov5670 = to_ov5670(sd);
2284 mutex_lock(&ov5670->mutex);
2285 ret = ov5670_do_get_pad_format(ov5670, sd_state, fmt);
2286 mutex_unlock(&ov5670->mutex);
2295 struct ov5670 *ov5670 = to_ov5670(sd);
2297 &ov5670->endpoint.bus.mipi_csi2;
2305 mutex_lock(&ov5670->mutex);
2317 ov5670->cur_mode = mode;
2318 __v4l2_ctrl_s_ctrl(ov5670->link_freq, mode->link_freq_index);
2325 ov5670->pixel_rate,
2328 vblank_def = ov5670->cur_mode->vts_def -
2329 ov5670->cur_mode->height;
2331 ov5670->vblank,
2332 ov5670->cur_mode->vts_min - ov5670->cur_mode->height,
2333 OV5670_VTS_MAX - ov5670->cur_mode->height, 1,
2335 __v4l2_ctrl_s_ctrl(ov5670->vblank, vblank_def);
2336 h_blank = OV5670_FIXED_PPL - ov5670->cur_mode->width;
2337 __v4l2_ctrl_modify_range(ov5670->hblank, h_blank, h_blank, 1,
2341 mutex_unlock(&ov5670->mutex);
2354 static int ov5670_identify_module(struct ov5670 *ov5670)
2356 struct i2c_client *client = v4l2_get_subdevdata(&ov5670->sd);
2360 if (ov5670->identified)
2363 ret = ov5670_read_reg(ov5670, OV5670_REG_CHIP_ID,
2374 ov5670->identified = true;
2379 static int ov5670_mipi_configure(struct ov5670 *ov5670)
2382 &ov5670->endpoint.bus.mipi_csi2;
2385 return ov5670_write_reg(ov5670, OV5670_MIPI_SC_CTRL0_REG,
2393 static int ov5670_start_streaming(struct ov5670 *ov5670)
2395 struct i2c_client *client = v4l2_get_subdevdata(&ov5670->sd);
2400 ret = ov5670_identify_module(ov5670);
2405 ret = ov5670_write_reg(ov5670, OV5670_REG_SOFTWARE_RST,
2414 link_freq_index = ov5670->cur_mode->link_freq_index;
2416 ret = ov5670_write_reg_list(ov5670, reg_list);
2423 reg_list = &ov5670->cur_mode->reg_list;
2424 ret = ov5670_write_reg_list(ov5670, reg_list);
2430 ret = ov5670_mipi_configure(ov5670);
2436 ret = __v4l2_ctrl_handler_setup(ov5670->sd.ctrl_handler);
2441 ret = ov5670_write_reg(ov5670, OV5670_REG_MODE_SELECT,
2451 static int ov5670_stop_streaming(struct ov5670 *ov5670)
2453 struct i2c_client *client = v4l2_get_subdevdata(&ov5670->sd);
2456 ret = ov5670_write_reg(ov5670, OV5670_REG_MODE_SELECT,
2469 struct ov5670 *ov5670 = to_ov5670(sd);
2473 mutex_lock(&ov5670->mutex);
2474 if (ov5670->streaming == enable)
2482 ret = ov5670_start_streaming(ov5670);
2486 ret = ov5670_stop_streaming(ov5670);
2489 ov5670->streaming = enable;
2496 mutex_unlock(&ov5670->mutex);
2505 struct ov5670 *ov5670 = to_ov5670(sd);
2509 ret = clk_prepare_enable(ov5670->xvclk);
2513 ret = regulator_bulk_enable(OV5670_NUM_SUPPLIES, ov5670->supplies);
2515 clk_disable_unprepare(ov5670->xvclk);
2519 gpiod_set_value_cansleep(ov5670->pwdn_gpio, 0);
2520 gpiod_set_value_cansleep(ov5670->reset_gpio, 0);
2534 struct ov5670 *ov5670 = to_ov5670(sd);
2536 gpiod_set_value_cansleep(ov5670->reset_gpio, 1);
2537 gpiod_set_value_cansleep(ov5670->pwdn_gpio, 1);
2538 regulator_bulk_disable(OV5670_NUM_SUPPLIES, ov5670->supplies);
2539 clk_disable_unprepare(ov5670->xvclk);
2547 struct ov5670 *ov5670 = to_ov5670(sd);
2549 if (ov5670->streaming)
2550 ov5670_stop_streaming(ov5670);
2558 struct ov5670 *ov5670 = to_ov5670(sd);
2561 if (ov5670->streaming) {
2562 ret = ov5670_start_streaming(ov5670);
2564 ov5670_stop_streaming(ov5670);
2579 __ov5670_get_pad_crop(struct ov5670 *sensor, struct v4l2_subdev_state *state,
2598 struct ov5670 *sensor = to_ov5670(subdev);
2653 static int ov5670_regulators_probe(struct ov5670 *ov5670)
2655 struct i2c_client *client = v4l2_get_subdevdata(&ov5670->sd);
2659 ov5670->supplies[i].supply = ov5670_supply_names[i];
2662 ov5670->supplies);
2665 static int ov5670_gpio_probe(struct ov5670 *ov5670)
2667 struct i2c_client *client = v4l2_get_subdevdata(&ov5670->sd);
2669 ov5670->pwdn_gpio = devm_gpiod_get_optional(&client->dev, "powerdown",
2671 if (IS_ERR(ov5670->pwdn_gpio))
2672 return PTR_ERR(ov5670->pwdn_gpio);
2674 ov5670->reset_gpio = devm_gpiod_get_optional(&client->dev, "reset",
2676 if (IS_ERR(ov5670->reset_gpio))
2677 return PTR_ERR(ov5670->reset_gpio);
2685 struct ov5670 *ov5670;
2690 ov5670 = devm_kzalloc(&client->dev, sizeof(*ov5670), GFP_KERNEL);
2691 if (!ov5670)
2694 ov5670->xvclk = devm_clk_get_optional(&client->dev, NULL);
2695 if (!IS_ERR_OR_NULL(ov5670->xvclk))
2696 input_clk = clk_get_rate(ov5670->xvclk);
2697 else if (!ov5670->xvclk || PTR_ERR(ov5670->xvclk) == -ENOENT)
2701 return dev_err_probe(&client->dev, PTR_ERR(ov5670->xvclk),
2711 v4l2_i2c_subdev_init(&ov5670->sd, client, &ov5670_subdev_ops);
2713 ret = ov5670_regulators_probe(ov5670);
2717 ret = ov5670_gpio_probe(ov5670);
2726 ov5670->endpoint.bus_type = V4L2_MBUS_CSI2_DPHY;
2727 ov5670->endpoint.bus.mipi_csi2.num_data_lanes = 2;
2729 ret = v4l2_fwnode_endpoint_alloc_parse(handle, &ov5670->endpoint);
2743 ret = ov5670_identify_module(ov5670);
2750 mutex_init(&ov5670->mutex);
2753 ov5670->cur_mode = &supported_modes[0];
2755 ret = ov5670_init_controls(ov5670);
2761 ov5670->sd.flags |= V4L2_SUBDEV_FL_HAS_DEVNODE |
2763 ov5670->sd.entity.ops = &ov5670_subdev_entity_ops;
2764 ov5670->sd.entity.function = MEDIA_ENT_F_CAM_SENSOR;
2767 ov5670->pad.flags = MEDIA_PAD_FL_SOURCE;
2768 ret = media_entity_pads_init(&ov5670->sd.entity, 1, &ov5670->pad);
2774 ov5670->streaming = false;
2782 ret = v4l2_async_register_subdev_sensor(&ov5670->sd);
2795 media_entity_cleanup(&ov5670->sd.entity);
2798 v4l2_ctrl_handler_free(ov5670->sd.ctrl_handler);
2801 mutex_destroy(&ov5670->mutex);
2808 v4l2_fwnode_endpoint_free(&ov5670->endpoint);
2816 struct ov5670 *ov5670 = to_ov5670(sd);
2821 mutex_destroy(&ov5670->mutex);
2826 v4l2_fwnode_endpoint_free(&ov5670->endpoint);
2844 { .compatible = "ovti,ov5670" },
2851 .name = "ov5670",
2865 MODULE_DESCRIPTION("Omnivision ov5670 sensor driver");