Lines Matching defs:ov8856

103 #define to_ov8856(_sd)			container_of(_sd, struct ov8856, sd)
1416 struct ov8856 {
1592 static unsigned int ov8856_modes_num(const struct ov8856 *ov8856)
1596 for (i = 0; i < ARRAY_SIZE(ov8856->priv_lane->supported_modes); i++) {
1597 if (ov8856->priv_lane->supported_modes[i].width == 0)
1625 static int ov8856_read_reg(struct ov8856 *ov8856, u16 reg, u16 len, u32 *val)
1627 struct i2c_client *client = v4l2_get_subdevdata(&ov8856->sd);
1655 static int ov8856_write_reg(struct ov8856 *ov8856, u16 reg, u16 len, u32 val)
1657 struct i2c_client *client = v4l2_get_subdevdata(&ov8856->sd);
1671 static int ov8856_write_reg_list(struct ov8856 *ov8856,
1674 struct i2c_client *client = v4l2_get_subdevdata(&ov8856->sd);
1679 ret = ov8856_write_reg(ov8856, r_list->regs[i].address, 1,
1692 static int ov8856_identify_module(struct ov8856 *ov8856)
1694 struct i2c_client *client = v4l2_get_subdevdata(&ov8856->sd);
1698 if (ov8856->identified)
1701 ret = ov8856_read_reg(ov8856, OV8856_REG_CHIP_ID,
1712 ov8856->identified = true;
1717 static int ov8856_update_digital_gain(struct ov8856 *ov8856, u32 d_gain)
1719 return ov8856_write_reg(ov8856, OV8856_REG_DIGITAL_GAIN,
1723 static int ov8856_test_pattern(struct ov8856 *ov8856, u32 pattern)
1729 return ov8856_write_reg(ov8856, OV8856_REG_TEST_PATTERN,
1733 static int ov8856_set_ctrl_hflip(struct ov8856 *ov8856, u32 ctrl_val)
1738 ret = ov8856_read_reg(ov8856, OV8856_REG_MIRROR_OPT_1,
1743 ret = ov8856_write_reg(ov8856, OV8856_REG_MIRROR_OPT_1,
1751 ret = ov8856_read_reg(ov8856, OV8856_REG_FORMAT2,
1756 return ov8856_write_reg(ov8856, OV8856_REG_FORMAT2,
1766 static int ov8856_set_ctrl_vflip(struct ov8856 *ov8856, u8 ctrl_val)
1771 ret = ov8856_read_reg(ov8856, OV8856_REG_FLIP_OPT_1,
1776 ret = ov8856_write_reg(ov8856, OV8856_REG_FLIP_OPT_1,
1783 ret = ov8856_read_reg(ov8856, OV8856_REG_FLIP_OPT_2,
1788 ret = ov8856_write_reg(ov8856, OV8856_REG_FLIP_OPT_2,
1793 ret = ov8856_read_reg(ov8856, OV8856_REG_FLIP_OPT_3,
1798 ret = ov8856_write_reg(ov8856, OV8856_REG_FLIP_OPT_3,
1805 ret = ov8856_read_reg(ov8856, OV8856_REG_FORMAT1,
1810 return ov8856_write_reg(ov8856, OV8856_REG_FORMAT1,
1822 struct ov8856 *ov8856 = container_of(ctrl->handler,
1823 struct ov8856, ctrl_handler);
1824 struct i2c_client *client = v4l2_get_subdevdata(&ov8856->sd);
1831 exposure_max = ov8856->cur_mode->height + ctrl->val -
1833 __v4l2_ctrl_modify_range(ov8856->exposure,
1834 ov8856->exposure->minimum,
1835 exposure_max, ov8856->exposure->step,
1845 ret = ov8856_write_reg(ov8856, OV8856_REG_ANALOG_GAIN,
1850 ret = ov8856_update_digital_gain(ov8856, ctrl->val);
1855 ret = ov8856_write_reg(ov8856, OV8856_REG_EXPOSURE,
1860 ret = ov8856_write_reg(ov8856, OV8856_REG_VTS,
1862 ov8856->cur_mode->height + ctrl->val);
1866 ret = ov8856_test_pattern(ov8856, ctrl->val);
1870 ret = ov8856_set_ctrl_hflip(ov8856, ctrl->val);
1874 ret = ov8856_set_ctrl_vflip(ov8856, ctrl->val);
1891 static int ov8856_init_controls(struct ov8856 *ov8856)
1897 ctrl_hdlr = &ov8856->ctrl_handler;
1902 ctrl_hdlr->lock = &ov8856->mutex;
1903 ov8856->link_freq = v4l2_ctrl_new_int_menu(ctrl_hdlr, &ov8856_ctrl_ops,
1906 (ov8856->priv_lane->link_freq_menu_items)
1908 0, ov8856->priv_lane->link_freq_menu_items);
1909 if (ov8856->link_freq)
1910 ov8856->link_freq->flags |= V4L2_CTRL_FLAG_READ_ONLY;
1912 ov8856->pixel_rate = v4l2_ctrl_new_std(ctrl_hdlr, &ov8856_ctrl_ops,
1914 to_rate(ov8856->priv_lane->link_freq_menu_items,
1916 ov8856->cur_mode->data_lanes), 1,
1917 to_rate(ov8856->priv_lane->link_freq_menu_items,
1919 ov8856->cur_mode->data_lanes));
1920 ov8856->vblank = v4l2_ctrl_new_std(ctrl_hdlr, &ov8856_ctrl_ops,
1922 ov8856->cur_mode->vts_min - ov8856->cur_mode->height,
1923 OV8856_VTS_MAX - ov8856->cur_mode->height, 1,
1924 ov8856->cur_mode->vts_def -
1925 ov8856->cur_mode->height);
1926 h_blank = to_pixels_per_line(ov8856->priv_lane->link_freq_menu_items,
1927 ov8856->cur_mode->hts,
1928 ov8856->cur_mode->link_freq_index,
1929 ov8856->cur_mode->data_lanes) -
1930 ov8856->cur_mode->width;
1931 ov8856->hblank = v4l2_ctrl_new_std(ctrl_hdlr, &ov8856_ctrl_ops,
1934 if (ov8856->hblank)
1935 ov8856->hblank->flags |= V4L2_CTRL_FLAG_READ_ONLY;
1943 exposure_max = ov8856->cur_mode->vts_def - OV8856_EXPOSURE_MAX_MARGIN;
1944 ov8856->exposure = v4l2_ctrl_new_std(ctrl_hdlr, &ov8856_ctrl_ops,
1960 ov8856->sd.ctrl_handler = ctrl_hdlr;
1965 static void ov8856_update_pad_format(struct ov8856 *ov8856,
1979 ov8856->cur_mbus_index = index;
1983 static int ov8856_start_streaming(struct ov8856 *ov8856)
1985 struct i2c_client *client = v4l2_get_subdevdata(&ov8856->sd);
1989 ret = ov8856_identify_module(ov8856);
1993 link_freq_index = ov8856->cur_mode->link_freq_index;
1994 reg_list = &ov8856->priv_lane->link_freq_configs[link_freq_index].reg_list;
1996 ret = ov8856_write_reg_list(ov8856, reg_list);
2002 reg_list = &ov8856->cur_mode->reg_list;
2003 ret = ov8856_write_reg_list(ov8856, reg_list);
2009 reg_list = &bayer_offset_configs[ov8856->cur_mbus_index];
2010 ret = ov8856_write_reg_list(ov8856, reg_list);
2016 ret = __v4l2_ctrl_handler_setup(ov8856->sd.ctrl_handler);
2020 ret = ov8856_write_reg(ov8856, OV8856_REG_MODE_SELECT,
2030 static void ov8856_stop_streaming(struct ov8856 *ov8856)
2032 struct i2c_client *client = v4l2_get_subdevdata(&ov8856->sd);
2034 if (ov8856_write_reg(ov8856, OV8856_REG_MODE_SELECT,
2041 struct ov8856 *ov8856 = to_ov8856(sd);
2045 if (ov8856->streaming == enable)
2048 mutex_lock(&ov8856->mutex);
2052 mutex_unlock(&ov8856->mutex);
2056 ret = ov8856_start_streaming(ov8856);
2059 ov8856_stop_streaming(ov8856);
2063 ov8856_stop_streaming(ov8856);
2067 ov8856->streaming = enable;
2068 mutex_unlock(&ov8856->mutex);
2076 struct ov8856 *ov8856 = to_ov8856(sd);
2082 ret = clk_prepare_enable(ov8856->xvclk);
2088 if (ov8856->reset_gpio) {
2089 gpiod_set_value_cansleep(ov8856->reset_gpio, 1);
2094 ov8856->supplies);
2100 gpiod_set_value_cansleep(ov8856->reset_gpio, 0);
2106 gpiod_set_value_cansleep(ov8856->reset_gpio, 1);
2107 clk_disable_unprepare(ov8856->xvclk);
2115 struct ov8856 *ov8856 = to_ov8856(sd);
2120 gpiod_set_value_cansleep(ov8856->reset_gpio, 1);
2122 ov8856->supplies);
2123 clk_disable_unprepare(ov8856->xvclk);
2131 struct ov8856 *ov8856 = to_ov8856(sd);
2133 mutex_lock(&ov8856->mutex);
2134 if (ov8856->streaming)
2135 ov8856_stop_streaming(ov8856);
2138 mutex_unlock(&ov8856->mutex);
2146 struct ov8856 *ov8856 = to_ov8856(sd);
2149 mutex_lock(&ov8856->mutex);
2152 if (ov8856->streaming) {
2153 ret = ov8856_start_streaming(ov8856);
2155 ov8856->streaming = false;
2156 ov8856_stop_streaming(ov8856);
2157 mutex_unlock(&ov8856->mutex);
2162 mutex_unlock(&ov8856->mutex);
2171 struct ov8856 *ov8856 = to_ov8856(sd);
2175 mode = v4l2_find_nearest_size(ov8856->priv_lane->supported_modes,
2176 ov8856->modes_size,
2180 mutex_lock(&ov8856->mutex);
2181 ov8856_update_pad_format(ov8856, mode, &fmt->format);
2185 ov8856->cur_mode = mode;
2186 __v4l2_ctrl_s_ctrl(ov8856->link_freq, mode->link_freq_index);
2187 __v4l2_ctrl_s_ctrl_int64(ov8856->pixel_rate,
2188 to_rate(ov8856->priv_lane->link_freq_menu_items,
2190 ov8856->cur_mode->data_lanes));
2194 __v4l2_ctrl_modify_range(ov8856->vblank,
2198 __v4l2_ctrl_s_ctrl(ov8856->vblank, vblank_def);
2199 h_blank = to_pixels_per_line(ov8856->priv_lane->link_freq_menu_items,
2202 ov8856->cur_mode->data_lanes)
2204 __v4l2_ctrl_modify_range(ov8856->hblank, h_blank, h_blank, 1,
2208 mutex_unlock(&ov8856->mutex);
2217 struct ov8856 *ov8856 = to_ov8856(sd);
2219 mutex_lock(&ov8856->mutex);
2221 fmt->format = *v4l2_subdev_get_try_format(&ov8856->sd,
2225 ov8856_update_pad_format(ov8856, ov8856->cur_mode, &fmt->format);
2227 mutex_unlock(&ov8856->mutex);
2248 struct ov8856 *ov8856 = to_ov8856(sd);
2251 if (fse->index >= ov8856->modes_size)
2260 fse->min_width = ov8856->priv_lane->supported_modes[fse->index].width;
2262 fse->min_height = ov8856->priv_lane->supported_modes[fse->index].height;
2270 struct ov8856 *ov8856 = to_ov8856(sd);
2272 mutex_lock(&ov8856->mutex);
2273 ov8856_update_pad_format(ov8856, &ov8856->priv_lane->supported_modes[0],
2275 mutex_unlock(&ov8856->mutex);
2305 static int ov8856_get_hwcfg(struct ov8856 *ov8856, struct device *dev)
2324 ov8856->xvclk = devm_clk_get(dev, "xvclk");
2325 if (IS_ERR(ov8856->xvclk)) {
2327 ov8856->xvclk);
2328 return PTR_ERR(ov8856->xvclk);
2331 clk_set_rate(ov8856->xvclk, xvclk_rate);
2332 xvclk_rate = clk_get_rate(ov8856->xvclk);
2334 ov8856->reset_gpio = devm_gpiod_get_optional(dev, "reset",
2336 if (IS_ERR(ov8856->reset_gpio))
2337 return PTR_ERR(ov8856->reset_gpio);
2340 ov8856->supplies[i].supply = ov8856_supply_names[i];
2344 ov8856->supplies);
2371 dev_dbg(dev, "Using %u data lanes\n", ov8856->cur_mode->data_lanes);
2374 ov8856->priv_lane = &lane_cfg_2;
2376 ov8856->priv_lane = &lane_cfg_4;
2378 ov8856->modes_size = ov8856_modes_num(ov8856);
2386 for (i = 0; i < ARRAY_SIZE(ov8856->priv_lane->link_freq_menu_items); i++) {
2388 if (ov8856->priv_lane->link_freq_menu_items[i] ==
2395 ov8856->priv_lane->link_freq_menu_items[i]);
2410 struct ov8856 *ov8856 = to_ov8856(sd);
2416 mutex_destroy(&ov8856->mutex);
2423 struct ov8856 *ov8856;
2427 ov8856 = devm_kzalloc(&client->dev, sizeof(*ov8856), GFP_KERNEL);
2428 if (!ov8856)
2431 ret = ov8856_get_hwcfg(ov8856, &client->dev);
2438 v4l2_i2c_subdev_init(&ov8856->sd, client, &ov8856_subdev_ops);
2448 ret = ov8856_identify_module(ov8856);
2455 mutex_init(&ov8856->mutex);
2456 ov8856->cur_mode = &ov8856->priv_lane->supported_modes[0];
2457 ov8856->cur_mbus_index = ov8856->cur_mode->default_mbus_index;
2458 ret = ov8856_init_controls(ov8856);
2464 ov8856->sd.internal_ops = &ov8856_internal_ops;
2465 ov8856->sd.flags |= V4L2_SUBDEV_FL_HAS_DEVNODE;
2466 ov8856->sd.entity.ops = &ov8856_subdev_entity_ops;
2467 ov8856->sd.entity.function = MEDIA_ENT_F_CAM_SENSOR;
2468 ov8856->pad.flags = MEDIA_PAD_FL_SOURCE;
2469 ret = media_entity_pads_init(&ov8856->sd.entity, 1, &ov8856->pad);
2475 ret = v4l2_async_register_subdev_sensor(&ov8856->sd);
2491 media_entity_cleanup(&ov8856->sd.entity);
2494 v4l2_ctrl_handler_free(ov8856->sd.ctrl_handler);
2495 mutex_destroy(&ov8856->mutex);
2518 { .compatible = "ovti,ov8856" },
2525 .name = "ov8856",