Lines Matching refs:ov5670
1815 struct ov5670 {
1837 #define to_ov5670(_sd) container_of(_sd, struct ov5670, sd)
1840 static int ov5670_read_reg(struct ov5670 *ov5670, u16 reg, unsigned int len,
1843 struct i2c_client *client = v4l2_get_subdevdata(&ov5670->sd);
1876 static int ov5670_write_reg(struct ov5670 *ov5670, u16 reg, unsigned int len,
1879 struct i2c_client *client = v4l2_get_subdevdata(&ov5670->sd);
1907 static int ov5670_write_regs(struct ov5670 *ov5670,
1910 struct i2c_client *client = v4l2_get_subdevdata(&ov5670->sd);
1915 ret = ov5670_write_reg(ov5670, regs[i].address, 1, regs[i].val);
1929 static int ov5670_write_reg_list(struct ov5670 *ov5670,
1932 return ov5670_write_regs(ov5670, r_list->regs, r_list->num_of_regs);
1938 struct ov5670 *ov5670 = to_ov5670(sd);
1942 mutex_lock(&ov5670->mutex);
1945 try_fmt->width = ov5670->cur_mode->width;
1946 try_fmt->height = ov5670->cur_mode->height;
1951 mutex_unlock(&ov5670->mutex);
1956 static int ov5670_update_digital_gain(struct ov5670 *ov5670, u32 d_gain)
1960 ret = ov5670_write_reg(ov5670, OV5670_REG_R_DGTL_GAIN,
1965 ret = ov5670_write_reg(ov5670, OV5670_REG_G_DGTL_GAIN,
1970 return ov5670_write_reg(ov5670, OV5670_REG_B_DGTL_GAIN,
1974 static int ov5670_enable_test_pattern(struct ov5670 *ov5670, u32 pattern)
1980 ret = ov5670_write_reg(ov5670, OV5670_REG_TEST_PATTERN_CTRL,
1985 ret = ov5670_read_reg(ov5670, OV5670_REG_TEST_PATTERN,
1995 return ov5670_write_reg(ov5670, OV5670_REG_TEST_PATTERN,
2002 struct ov5670 *ov5670 = container_of(ctrl->handler,
2003 struct ov5670, ctrl_handler);
2004 struct i2c_client *client = v4l2_get_subdevdata(&ov5670->sd);
2012 max = ov5670->cur_mode->height + ctrl->val - 8;
2013 __v4l2_ctrl_modify_range(ov5670->exposure,
2014 ov5670->exposure->minimum, max,
2015 ov5670->exposure->step, max);
2025 ret = ov5670_write_reg(ov5670, OV5670_REG_ANALOG_GAIN,
2029 ret = ov5670_update_digital_gain(ov5670, ctrl->val);
2033 ret = ov5670_write_reg(ov5670, OV5670_REG_EXPOSURE,
2038 ret = ov5670_write_reg(ov5670, OV5670_REG_VTS,
2040 ov5670->cur_mode->height + ctrl->val);
2043 ret = ov5670_enable_test_pattern(ov5670, ctrl->val);
2061 static int ov5670_init_controls(struct ov5670 *ov5670)
2063 struct i2c_client *client = v4l2_get_subdevdata(&ov5670->sd);
2072 ctrl_hdlr = &ov5670->ctrl_handler;
2077 ctrl_hdlr->lock = &ov5670->mutex;
2078 ov5670->link_freq = v4l2_ctrl_new_int_menu(ctrl_hdlr,
2082 if (ov5670->link_freq)
2083 ov5670->link_freq->flags |= V4L2_CTRL_FLAG_READ_ONLY;
2086 ov5670->pixel_rate = v4l2_ctrl_new_std(ctrl_hdlr, &ov5670_ctrl_ops,
2093 vblank_max = OV5670_VTS_MAX - ov5670->cur_mode->height;
2094 vblank_def = ov5670->cur_mode->vts_def - ov5670->cur_mode->height;
2095 vblank_min = ov5670->cur_mode->vts_min - ov5670->cur_mode->height;
2096 ov5670->vblank = v4l2_ctrl_new_std(ctrl_hdlr, &ov5670_ctrl_ops,
2100 ov5670->hblank = v4l2_ctrl_new_std(
2102 OV5670_FIXED_PPL - ov5670->cur_mode->width,
2103 OV5670_FIXED_PPL - ov5670->cur_mode->width, 1,
2104 OV5670_FIXED_PPL - ov5670->cur_mode->width);
2105 if (ov5670->hblank)
2106 ov5670->hblank->flags |= V4L2_CTRL_FLAG_READ_ONLY;
2119 exposure_max = ov5670->cur_mode->vts_def - 8;
2120 ov5670->exposure = v4l2_ctrl_new_std(ctrl_hdlr, &ov5670_ctrl_ops,
2145 ov5670->sd.ctrl_handler = ctrl_hdlr;
2195 static int ov5670_do_get_pad_format(struct ov5670 *ov5670,
2200 fmt->format = *v4l2_subdev_get_try_format(&ov5670->sd, cfg,
2203 ov5670_update_pad_format(ov5670->cur_mode, fmt);
2212 struct ov5670 *ov5670 = to_ov5670(sd);
2215 mutex_lock(&ov5670->mutex);
2216 ret = ov5670_do_get_pad_format(ov5670, cfg, fmt);
2217 mutex_unlock(&ov5670->mutex);
2226 struct ov5670 *ov5670 = to_ov5670(sd);
2231 mutex_lock(&ov5670->mutex);
2243 ov5670->cur_mode = mode;
2244 __v4l2_ctrl_s_ctrl(ov5670->link_freq, mode->link_freq_index);
2246 ov5670->pixel_rate,
2249 vblank_def = ov5670->cur_mode->vts_def -
2250 ov5670->cur_mode->height;
2252 ov5670->vblank,
2253 ov5670->cur_mode->vts_min - ov5670->cur_mode->height,
2254 OV5670_VTS_MAX - ov5670->cur_mode->height, 1,
2256 __v4l2_ctrl_s_ctrl(ov5670->vblank, vblank_def);
2257 h_blank = OV5670_FIXED_PPL - ov5670->cur_mode->width;
2258 __v4l2_ctrl_modify_range(ov5670->hblank, h_blank, h_blank, 1,
2262 mutex_unlock(&ov5670->mutex);
2275 static int ov5670_start_streaming(struct ov5670 *ov5670)
2277 struct i2c_client *client = v4l2_get_subdevdata(&ov5670->sd);
2283 ret = ov5670_write_reg(ov5670, OV5670_REG_SOFTWARE_RST,
2292 link_freq_index = ov5670->cur_mode->link_freq_index;
2294 ret = ov5670_write_reg_list(ov5670, reg_list);
2301 reg_list = &ov5670->cur_mode->reg_list;
2302 ret = ov5670_write_reg_list(ov5670, reg_list);
2308 ret = __v4l2_ctrl_handler_setup(ov5670->sd.ctrl_handler);
2313 ret = ov5670_write_reg(ov5670, OV5670_REG_MODE_SELECT,
2323 static int ov5670_stop_streaming(struct ov5670 *ov5670)
2325 struct i2c_client *client = v4l2_get_subdevdata(&ov5670->sd);
2328 ret = ov5670_write_reg(ov5670, OV5670_REG_MODE_SELECT,
2341 struct ov5670 *ov5670 = to_ov5670(sd);
2345 mutex_lock(&ov5670->mutex);
2346 if (ov5670->streaming == enable)
2356 ret = ov5670_start_streaming(ov5670);
2360 ret = ov5670_stop_streaming(ov5670);
2363 ov5670->streaming = enable;
2370 mutex_unlock(&ov5670->mutex);
2379 struct ov5670 *ov5670 = to_ov5670(sd);
2381 if (ov5670->streaming)
2382 ov5670_stop_streaming(ov5670);
2391 struct ov5670 *ov5670 = to_ov5670(sd);
2394 if (ov5670->streaming) {
2395 ret = ov5670_start_streaming(ov5670);
2397 ov5670_stop_streaming(ov5670);
2406 static int ov5670_identify_module(struct ov5670 *ov5670)
2408 struct i2c_client *client = v4l2_get_subdevdata(&ov5670->sd);
2412 ret = ov5670_read_reg(ov5670, OV5670_REG_CHIP_ID,
2457 struct ov5670 *ov5670;
2466 ov5670 = devm_kzalloc(&client->dev, sizeof(*ov5670), GFP_KERNEL);
2467 if (!ov5670) {
2474 v4l2_i2c_subdev_init(&ov5670->sd, client, &ov5670_subdev_ops);
2477 ret = ov5670_identify_module(ov5670);
2483 mutex_init(&ov5670->mutex);
2486 ov5670->cur_mode = &supported_modes[0];
2488 ret = ov5670_init_controls(ov5670);
2494 ov5670->sd.internal_ops = &ov5670_internal_ops;
2495 ov5670->sd.flags |= V4L2_SUBDEV_FL_HAS_DEVNODE;
2496 ov5670->sd.entity.ops = &ov5670_subdev_entity_ops;
2497 ov5670->sd.entity.function = MEDIA_ENT_F_CAM_SENSOR;
2500 ov5670->pad.flags = MEDIA_PAD_FL_SOURCE;
2501 ret = media_entity_pads_init(&ov5670->sd.entity, 1, &ov5670->pad);
2508 ret = v4l2_async_register_subdev_sensor_common(&ov5670->sd);
2514 ov5670->streaming = false;
2527 media_entity_cleanup(&ov5670->sd.entity);
2530 v4l2_ctrl_handler_free(ov5670->sd.ctrl_handler);
2533 mutex_destroy(&ov5670->mutex);
2544 struct ov5670 *ov5670 = to_ov5670(sd);
2549 mutex_destroy(&ov5670->mutex);
2571 .name = "ov5670",
2583 MODULE_DESCRIPTION("Omnivision ov5670 sensor driver");