Lines Matching refs:ov5670

1856 struct ov5670 {  struct
1889 #define to_ov5670(_sd) container_of(_sd, struct ov5670, sd) argument
1892 static int ov5670_read_reg(struct ov5670 *ov5670, u16 reg, unsigned int len, in ov5670_read_reg() argument
1895 struct i2c_client *client = v4l2_get_subdevdata(&ov5670->sd); in ov5670_read_reg()
1928 static int ov5670_write_reg(struct ov5670 *ov5670, u16 reg, unsigned int len, in ov5670_write_reg() argument
1931 struct i2c_client *client = v4l2_get_subdevdata(&ov5670->sd); in ov5670_write_reg()
1959 static int ov5670_write_regs(struct ov5670 *ov5670, in ov5670_write_regs() argument
1962 struct i2c_client *client = v4l2_get_subdevdata(&ov5670->sd); in ov5670_write_regs()
1967 ret = ov5670_write_reg(ov5670, regs[i].address, 1, regs[i].val); in ov5670_write_regs()
1981 static int ov5670_write_reg_list(struct ov5670 *ov5670, in ov5670_write_reg_list() argument
1984 return ov5670_write_regs(ov5670, r_list->regs, r_list->num_of_regs); in ov5670_write_reg_list()
1987 static int ov5670_update_digital_gain(struct ov5670 *ov5670, u32 d_gain) in ov5670_update_digital_gain() argument
1991 ret = ov5670_write_reg(ov5670, OV5670_REG_R_DGTL_GAIN, in ov5670_update_digital_gain()
1996 ret = ov5670_write_reg(ov5670, OV5670_REG_G_DGTL_GAIN, in ov5670_update_digital_gain()
2001 return ov5670_write_reg(ov5670, OV5670_REG_B_DGTL_GAIN, in ov5670_update_digital_gain()
2005 static int ov5670_enable_test_pattern(struct ov5670 *ov5670, u32 pattern) in ov5670_enable_test_pattern() argument
2011 ret = ov5670_write_reg(ov5670, OV5670_REG_TEST_PATTERN_CTRL, in ov5670_enable_test_pattern()
2016 ret = ov5670_read_reg(ov5670, OV5670_REG_TEST_PATTERN, in ov5670_enable_test_pattern()
2026 return ov5670_write_reg(ov5670, OV5670_REG_TEST_PATTERN, in ov5670_enable_test_pattern()
2033 struct ov5670 *ov5670 = container_of(ctrl->handler, in ov5670_set_ctrl() local
2034 struct ov5670, ctrl_handler); in ov5670_set_ctrl()
2035 struct i2c_client *client = v4l2_get_subdevdata(&ov5670->sd); in ov5670_set_ctrl()
2043 max = ov5670->cur_mode->height + ctrl->val - 8; in ov5670_set_ctrl()
2044 __v4l2_ctrl_modify_range(ov5670->exposure, in ov5670_set_ctrl()
2045 ov5670->exposure->minimum, max, in ov5670_set_ctrl()
2046 ov5670->exposure->step, max); in ov5670_set_ctrl()
2056 ret = ov5670_write_reg(ov5670, OV5670_REG_ANALOG_GAIN, in ov5670_set_ctrl()
2060 ret = ov5670_update_digital_gain(ov5670, ctrl->val); in ov5670_set_ctrl()
2064 ret = ov5670_write_reg(ov5670, OV5670_REG_EXPOSURE, in ov5670_set_ctrl()
2069 ret = ov5670_write_reg(ov5670, OV5670_REG_VTS, in ov5670_set_ctrl()
2071 ov5670->cur_mode->height + ctrl->val); in ov5670_set_ctrl()
2074 ret = ov5670_enable_test_pattern(ov5670, ctrl->val); in ov5670_set_ctrl()
2098 static int ov5670_init_controls(struct ov5670 *ov5670) in ov5670_init_controls() argument
2101 &ov5670->endpoint.bus.mipi_csi2; in ov5670_init_controls()
2102 struct i2c_client *client = v4l2_get_subdevdata(&ov5670->sd); in ov5670_init_controls()
2113 ctrl_hdlr = &ov5670->ctrl_handler; in ov5670_init_controls()
2118 ctrl_hdlr->lock = &ov5670->mutex; in ov5670_init_controls()
2119 ov5670->link_freq = v4l2_ctrl_new_int_menu(ctrl_hdlr, in ov5670_init_controls()
2123 if (ov5670->link_freq) in ov5670_init_controls()
2124 ov5670->link_freq->flags |= V4L2_CTRL_FLAG_READ_ONLY; in ov5670_init_controls()
2130 ov5670->pixel_rate = v4l2_ctrl_new_std(ctrl_hdlr, &ov5670_ctrl_ops, in ov5670_init_controls()
2137 vblank_max = OV5670_VTS_MAX - ov5670->cur_mode->height; in ov5670_init_controls()
2138 vblank_def = ov5670->cur_mode->vts_def - ov5670->cur_mode->height; in ov5670_init_controls()
2139 vblank_min = ov5670->cur_mode->vts_min - ov5670->cur_mode->height; in ov5670_init_controls()
2140 ov5670->vblank = v4l2_ctrl_new_std(ctrl_hdlr, &ov5670_ctrl_ops, in ov5670_init_controls()
2144 ov5670->hblank = v4l2_ctrl_new_std( in ov5670_init_controls()
2146 OV5670_FIXED_PPL - ov5670->cur_mode->width, in ov5670_init_controls()
2147 OV5670_FIXED_PPL - ov5670->cur_mode->width, 1, in ov5670_init_controls()
2148 OV5670_FIXED_PPL - ov5670->cur_mode->width); in ov5670_init_controls()
2149 if (ov5670->hblank) in ov5670_init_controls()
2150 ov5670->hblank->flags |= V4L2_CTRL_FLAG_READ_ONLY; in ov5670_init_controls()
2163 exposure_max = ov5670->cur_mode->vts_def - 8; in ov5670_init_controls()
2164 ov5670->exposure = v4l2_ctrl_new_std(ctrl_hdlr, &ov5670_ctrl_ops, in ov5670_init_controls()
2189 ov5670->sd.ctrl_handler = ctrl_hdlr; in ov5670_init_controls()
2261 static int ov5670_do_get_pad_format(struct ov5670 *ov5670, in ov5670_do_get_pad_format() argument
2269 ov5670_update_pad_format(ov5670->cur_mode, fmt); in ov5670_do_get_pad_format()
2278 struct ov5670 *ov5670 = to_ov5670(sd); in ov5670_get_pad_format() local
2281 mutex_lock(&ov5670->mutex); in ov5670_get_pad_format()
2282 ret = ov5670_do_get_pad_format(ov5670, sd_state, fmt); in ov5670_get_pad_format()
2283 mutex_unlock(&ov5670->mutex); in ov5670_get_pad_format()
2292 struct ov5670 *ov5670 = to_ov5670(sd); in ov5670_set_pad_format() local
2294 &ov5670->endpoint.bus.mipi_csi2; in ov5670_set_pad_format()
2302 mutex_lock(&ov5670->mutex); in ov5670_set_pad_format()
2314 ov5670->cur_mode = mode; in ov5670_set_pad_format()
2315 __v4l2_ctrl_s_ctrl(ov5670->link_freq, mode->link_freq_index); in ov5670_set_pad_format()
2322 ov5670->pixel_rate, in ov5670_set_pad_format()
2325 vblank_def = ov5670->cur_mode->vts_def - in ov5670_set_pad_format()
2326 ov5670->cur_mode->height; in ov5670_set_pad_format()
2328 ov5670->vblank, in ov5670_set_pad_format()
2329 ov5670->cur_mode->vts_min - ov5670->cur_mode->height, in ov5670_set_pad_format()
2330 OV5670_VTS_MAX - ov5670->cur_mode->height, 1, in ov5670_set_pad_format()
2332 __v4l2_ctrl_s_ctrl(ov5670->vblank, vblank_def); in ov5670_set_pad_format()
2333 h_blank = OV5670_FIXED_PPL - ov5670->cur_mode->width; in ov5670_set_pad_format()
2334 __v4l2_ctrl_modify_range(ov5670->hblank, h_blank, h_blank, 1, in ov5670_set_pad_format()
2338 mutex_unlock(&ov5670->mutex); in ov5670_set_pad_format()
2351 static int ov5670_identify_module(struct ov5670 *ov5670) in ov5670_identify_module() argument
2353 struct i2c_client *client = v4l2_get_subdevdata(&ov5670->sd); in ov5670_identify_module()
2357 if (ov5670->identified) in ov5670_identify_module()
2360 ret = ov5670_read_reg(ov5670, OV5670_REG_CHIP_ID, in ov5670_identify_module()
2371 ov5670->identified = true; in ov5670_identify_module()
2376 static int ov5670_mipi_configure(struct ov5670 *ov5670) in ov5670_mipi_configure() argument
2379 &ov5670->endpoint.bus.mipi_csi2; in ov5670_mipi_configure()
2382 return ov5670_write_reg(ov5670, OV5670_MIPI_SC_CTRL0_REG, in ov5670_mipi_configure()
2390 static int ov5670_start_streaming(struct ov5670 *ov5670) in ov5670_start_streaming() argument
2392 struct i2c_client *client = v4l2_get_subdevdata(&ov5670->sd); in ov5670_start_streaming()
2397 ret = ov5670_identify_module(ov5670); in ov5670_start_streaming()
2402 ret = ov5670_write_reg(ov5670, OV5670_REG_SOFTWARE_RST, in ov5670_start_streaming()
2411 link_freq_index = ov5670->cur_mode->link_freq_index; in ov5670_start_streaming()
2413 ret = ov5670_write_reg_list(ov5670, reg_list); in ov5670_start_streaming()
2420 reg_list = &ov5670->cur_mode->reg_list; in ov5670_start_streaming()
2421 ret = ov5670_write_reg_list(ov5670, reg_list); in ov5670_start_streaming()
2427 ret = ov5670_mipi_configure(ov5670); in ov5670_start_streaming()
2433 ret = __v4l2_ctrl_handler_setup(ov5670->sd.ctrl_handler); in ov5670_start_streaming()
2438 ret = ov5670_write_reg(ov5670, OV5670_REG_MODE_SELECT, in ov5670_start_streaming()
2448 static int ov5670_stop_streaming(struct ov5670 *ov5670) in ov5670_stop_streaming() argument
2450 struct i2c_client *client = v4l2_get_subdevdata(&ov5670->sd); in ov5670_stop_streaming()
2453 ret = ov5670_write_reg(ov5670, OV5670_REG_MODE_SELECT, in ov5670_stop_streaming()
2466 struct ov5670 *ov5670 = to_ov5670(sd); in ov5670_set_stream() local
2470 mutex_lock(&ov5670->mutex); in ov5670_set_stream()
2477 ret = ov5670_start_streaming(ov5670); in ov5670_set_stream()
2481 ret = ov5670_stop_streaming(ov5670); in ov5670_set_stream()
2490 mutex_unlock(&ov5670->mutex); in ov5670_set_stream()
2499 struct ov5670 *ov5670 = to_ov5670(sd); in ov5670_runtime_resume() local
2503 ret = clk_prepare_enable(ov5670->xvclk); in ov5670_runtime_resume()
2507 ret = regulator_bulk_enable(OV5670_NUM_SUPPLIES, ov5670->supplies); in ov5670_runtime_resume()
2509 clk_disable_unprepare(ov5670->xvclk); in ov5670_runtime_resume()
2513 gpiod_set_value_cansleep(ov5670->pwdn_gpio, 0); in ov5670_runtime_resume()
2514 gpiod_set_value_cansleep(ov5670->reset_gpio, 0); in ov5670_runtime_resume()
2528 struct ov5670 *ov5670 = to_ov5670(sd); in ov5670_runtime_suspend() local
2530 gpiod_set_value_cansleep(ov5670->reset_gpio, 1); in ov5670_runtime_suspend()
2531 gpiod_set_value_cansleep(ov5670->pwdn_gpio, 1); in ov5670_runtime_suspend()
2532 regulator_bulk_disable(OV5670_NUM_SUPPLIES, ov5670->supplies); in ov5670_runtime_suspend()
2533 clk_disable_unprepare(ov5670->xvclk); in ov5670_runtime_suspend()
2545 __ov5670_get_pad_crop(struct ov5670 *sensor, struct v4l2_subdev_state *state, in __ov5670_get_pad_crop()
2564 struct ov5670 *sensor = to_ov5670(subdev); in ov5670_get_selection()
2622 static int ov5670_regulators_probe(struct ov5670 *ov5670) in ov5670_regulators_probe() argument
2624 struct i2c_client *client = v4l2_get_subdevdata(&ov5670->sd); in ov5670_regulators_probe()
2628 ov5670->supplies[i].supply = ov5670_supply_names[i]; in ov5670_regulators_probe()
2631 ov5670->supplies); in ov5670_regulators_probe()
2634 static int ov5670_gpio_probe(struct ov5670 *ov5670) in ov5670_gpio_probe() argument
2636 struct i2c_client *client = v4l2_get_subdevdata(&ov5670->sd); in ov5670_gpio_probe()
2638 ov5670->pwdn_gpio = devm_gpiod_get_optional(&client->dev, "powerdown", in ov5670_gpio_probe()
2640 if (IS_ERR(ov5670->pwdn_gpio)) in ov5670_gpio_probe()
2641 return PTR_ERR(ov5670->pwdn_gpio); in ov5670_gpio_probe()
2643 ov5670->reset_gpio = devm_gpiod_get_optional(&client->dev, "reset", in ov5670_gpio_probe()
2645 if (IS_ERR(ov5670->reset_gpio)) in ov5670_gpio_probe()
2646 return PTR_ERR(ov5670->reset_gpio); in ov5670_gpio_probe()
2654 struct ov5670 *ov5670; in ov5670_probe() local
2659 ov5670 = devm_kzalloc(&client->dev, sizeof(*ov5670), GFP_KERNEL); in ov5670_probe()
2660 if (!ov5670) in ov5670_probe()
2663 ov5670->xvclk = devm_clk_get_optional(&client->dev, NULL); in ov5670_probe()
2664 if (!IS_ERR_OR_NULL(ov5670->xvclk)) in ov5670_probe()
2665 input_clk = clk_get_rate(ov5670->xvclk); in ov5670_probe()
2666 else if (!ov5670->xvclk || PTR_ERR(ov5670->xvclk) == -ENOENT) in ov5670_probe()
2670 return dev_err_probe(&client->dev, PTR_ERR(ov5670->xvclk), in ov5670_probe()
2680 v4l2_i2c_subdev_init(&ov5670->sd, client, &ov5670_subdev_ops); in ov5670_probe()
2681 ov5670->sd.internal_ops = &ov5670_internal_ops; in ov5670_probe()
2683 ret = ov5670_regulators_probe(ov5670); in ov5670_probe()
2687 ret = ov5670_gpio_probe(ov5670); in ov5670_probe()
2696 ov5670->endpoint.bus_type = V4L2_MBUS_CSI2_DPHY; in ov5670_probe()
2697 ov5670->endpoint.bus.mipi_csi2.num_data_lanes = 2; in ov5670_probe()
2699 ret = v4l2_fwnode_endpoint_alloc_parse(handle, &ov5670->endpoint); in ov5670_probe()
2713 ret = ov5670_identify_module(ov5670); in ov5670_probe()
2720 mutex_init(&ov5670->mutex); in ov5670_probe()
2723 ov5670->cur_mode = &supported_modes[0]; in ov5670_probe()
2725 ret = ov5670_init_controls(ov5670); in ov5670_probe()
2731 ov5670->sd.flags |= V4L2_SUBDEV_FL_HAS_DEVNODE | in ov5670_probe()
2733 ov5670->sd.entity.ops = &ov5670_subdev_entity_ops; in ov5670_probe()
2734 ov5670->sd.entity.function = MEDIA_ENT_F_CAM_SENSOR; in ov5670_probe()
2737 ov5670->pad.flags = MEDIA_PAD_FL_SOURCE; in ov5670_probe()
2738 ret = media_entity_pads_init(&ov5670->sd.entity, 1, &ov5670->pad); in ov5670_probe()
2750 ret = v4l2_async_register_subdev_sensor(&ov5670->sd); in ov5670_probe()
2763 media_entity_cleanup(&ov5670->sd.entity); in ov5670_probe()
2766 v4l2_ctrl_handler_free(ov5670->sd.ctrl_handler); in ov5670_probe()
2769 mutex_destroy(&ov5670->mutex); in ov5670_probe()
2776 v4l2_fwnode_endpoint_free(&ov5670->endpoint); in ov5670_probe()
2784 struct ov5670 *ov5670 = to_ov5670(sd); in ov5670_remove() local
2789 mutex_destroy(&ov5670->mutex); in ov5670_remove()
2794 v4l2_fwnode_endpoint_free(&ov5670->endpoint); in ov5670_remove()