Lines Matching full:ov5670

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