Lines Matching full:ov8856

103 #define to_ov8856(_sd)			container_of(_sd, struct ov8856, sd)
1416 struct ov8856 { struct
1589 static unsigned int ov8856_modes_num(const struct ov8856 *ov8856) in ov8856_modes_num() argument
1593 for (i = 0; i < ARRAY_SIZE(ov8856->priv_lane->supported_modes); i++) { in ov8856_modes_num()
1594 if (ov8856->priv_lane->supported_modes[i].width == 0) in ov8856_modes_num()
1622 static int ov8856_read_reg(struct ov8856 *ov8856, u16 reg, u16 len, u32 *val) in ov8856_read_reg() argument
1624 struct i2c_client *client = v4l2_get_subdevdata(&ov8856->sd); in ov8856_read_reg()
1652 static int ov8856_write_reg(struct ov8856 *ov8856, u16 reg, u16 len, u32 val) in ov8856_write_reg() argument
1654 struct i2c_client *client = v4l2_get_subdevdata(&ov8856->sd); in ov8856_write_reg()
1668 static int ov8856_write_reg_list(struct ov8856 *ov8856, in ov8856_write_reg_list() argument
1671 struct i2c_client *client = v4l2_get_subdevdata(&ov8856->sd); in ov8856_write_reg_list()
1676 ret = ov8856_write_reg(ov8856, r_list->regs[i].address, 1, in ov8856_write_reg_list()
1689 static int ov8856_identify_module(struct ov8856 *ov8856) in ov8856_identify_module() argument
1691 struct i2c_client *client = v4l2_get_subdevdata(&ov8856->sd); in ov8856_identify_module()
1695 if (ov8856->identified) in ov8856_identify_module()
1698 ret = ov8856_read_reg(ov8856, OV8856_REG_CHIP_ID, in ov8856_identify_module()
1709 ov8856->identified = true; in ov8856_identify_module()
1714 static int ov8856_update_digital_gain(struct ov8856 *ov8856, u32 d_gain) in ov8856_update_digital_gain() argument
1716 return ov8856_write_reg(ov8856, OV8856_REG_DIGITAL_GAIN, in ov8856_update_digital_gain()
1720 static int ov8856_test_pattern(struct ov8856 *ov8856, u32 pattern) in ov8856_test_pattern() argument
1726 return ov8856_write_reg(ov8856, OV8856_REG_TEST_PATTERN, in ov8856_test_pattern()
1730 static int ov8856_set_ctrl_hflip(struct ov8856 *ov8856, u32 ctrl_val) in ov8856_set_ctrl_hflip() argument
1735 ret = ov8856_read_reg(ov8856, OV8856_REG_MIRROR_OPT_1, in ov8856_set_ctrl_hflip()
1740 ret = ov8856_write_reg(ov8856, OV8856_REG_MIRROR_OPT_1, in ov8856_set_ctrl_hflip()
1748 ret = ov8856_read_reg(ov8856, OV8856_REG_FORMAT2, in ov8856_set_ctrl_hflip()
1753 return ov8856_write_reg(ov8856, OV8856_REG_FORMAT2, in ov8856_set_ctrl_hflip()
1763 static int ov8856_set_ctrl_vflip(struct ov8856 *ov8856, u8 ctrl_val) in ov8856_set_ctrl_vflip() argument
1768 ret = ov8856_read_reg(ov8856, OV8856_REG_FLIP_OPT_1, in ov8856_set_ctrl_vflip()
1773 ret = ov8856_write_reg(ov8856, OV8856_REG_FLIP_OPT_1, in ov8856_set_ctrl_vflip()
1780 ret = ov8856_read_reg(ov8856, OV8856_REG_FLIP_OPT_2, in ov8856_set_ctrl_vflip()
1785 ret = ov8856_write_reg(ov8856, OV8856_REG_FLIP_OPT_2, in ov8856_set_ctrl_vflip()
1790 ret = ov8856_read_reg(ov8856, OV8856_REG_FLIP_OPT_3, in ov8856_set_ctrl_vflip()
1795 ret = ov8856_write_reg(ov8856, OV8856_REG_FLIP_OPT_3, in ov8856_set_ctrl_vflip()
1802 ret = ov8856_read_reg(ov8856, OV8856_REG_FORMAT1, in ov8856_set_ctrl_vflip()
1807 return ov8856_write_reg(ov8856, OV8856_REG_FORMAT1, in ov8856_set_ctrl_vflip()
1819 struct ov8856 *ov8856 = container_of(ctrl->handler, in ov8856_set_ctrl() local
1820 struct ov8856, ctrl_handler); in ov8856_set_ctrl()
1821 struct i2c_client *client = v4l2_get_subdevdata(&ov8856->sd); in ov8856_set_ctrl()
1828 exposure_max = ov8856->cur_mode->height + ctrl->val - in ov8856_set_ctrl()
1830 __v4l2_ctrl_modify_range(ov8856->exposure, in ov8856_set_ctrl()
1831 ov8856->exposure->minimum, in ov8856_set_ctrl()
1832 exposure_max, ov8856->exposure->step, in ov8856_set_ctrl()
1842 ret = ov8856_write_reg(ov8856, OV8856_REG_ANALOG_GAIN, in ov8856_set_ctrl()
1847 ret = ov8856_update_digital_gain(ov8856, ctrl->val); in ov8856_set_ctrl()
1852 ret = ov8856_write_reg(ov8856, OV8856_REG_EXPOSURE, in ov8856_set_ctrl()
1857 ret = ov8856_write_reg(ov8856, OV8856_REG_VTS, in ov8856_set_ctrl()
1859 ov8856->cur_mode->height + ctrl->val); in ov8856_set_ctrl()
1863 ret = ov8856_test_pattern(ov8856, ctrl->val); in ov8856_set_ctrl()
1867 ret = ov8856_set_ctrl_hflip(ov8856, ctrl->val); in ov8856_set_ctrl()
1871 ret = ov8856_set_ctrl_vflip(ov8856, ctrl->val); in ov8856_set_ctrl()
1888 static int ov8856_init_controls(struct ov8856 *ov8856) in ov8856_init_controls() argument
1894 ctrl_hdlr = &ov8856->ctrl_handler; in ov8856_init_controls()
1899 ctrl_hdlr->lock = &ov8856->mutex; in ov8856_init_controls()
1900 ov8856->link_freq = v4l2_ctrl_new_int_menu(ctrl_hdlr, &ov8856_ctrl_ops, in ov8856_init_controls()
1903 (ov8856->priv_lane->link_freq_menu_items) in ov8856_init_controls()
1905 0, ov8856->priv_lane->link_freq_menu_items); in ov8856_init_controls()
1906 if (ov8856->link_freq) in ov8856_init_controls()
1907 ov8856->link_freq->flags |= V4L2_CTRL_FLAG_READ_ONLY; in ov8856_init_controls()
1909 ov8856->pixel_rate = v4l2_ctrl_new_std(ctrl_hdlr, &ov8856_ctrl_ops, in ov8856_init_controls()
1911 to_rate(ov8856->priv_lane->link_freq_menu_items, in ov8856_init_controls()
1913 ov8856->cur_mode->data_lanes), 1, in ov8856_init_controls()
1914 to_rate(ov8856->priv_lane->link_freq_menu_items, in ov8856_init_controls()
1916 ov8856->cur_mode->data_lanes)); in ov8856_init_controls()
1917 ov8856->vblank = v4l2_ctrl_new_std(ctrl_hdlr, &ov8856_ctrl_ops, in ov8856_init_controls()
1919 ov8856->cur_mode->vts_min - ov8856->cur_mode->height, in ov8856_init_controls()
1920 OV8856_VTS_MAX - ov8856->cur_mode->height, 1, in ov8856_init_controls()
1921 ov8856->cur_mode->vts_def - in ov8856_init_controls()
1922 ov8856->cur_mode->height); in ov8856_init_controls()
1923 h_blank = to_pixels_per_line(ov8856->priv_lane->link_freq_menu_items, in ov8856_init_controls()
1924 ov8856->cur_mode->hts, in ov8856_init_controls()
1925 ov8856->cur_mode->link_freq_index, in ov8856_init_controls()
1926 ov8856->cur_mode->data_lanes) - in ov8856_init_controls()
1927 ov8856->cur_mode->width; in ov8856_init_controls()
1928 ov8856->hblank = v4l2_ctrl_new_std(ctrl_hdlr, &ov8856_ctrl_ops, in ov8856_init_controls()
1931 if (ov8856->hblank) in ov8856_init_controls()
1932 ov8856->hblank->flags |= V4L2_CTRL_FLAG_READ_ONLY; in ov8856_init_controls()
1940 exposure_max = ov8856->cur_mode->vts_def - OV8856_EXPOSURE_MAX_MARGIN; in ov8856_init_controls()
1941 ov8856->exposure = v4l2_ctrl_new_std(ctrl_hdlr, &ov8856_ctrl_ops, in ov8856_init_controls()
1957 ov8856->sd.ctrl_handler = ctrl_hdlr; in ov8856_init_controls()
1962 static void ov8856_update_pad_format(struct ov8856 *ov8856, in ov8856_update_pad_format() argument
1976 ov8856->cur_mbus_index = index; in ov8856_update_pad_format()
1980 static int ov8856_start_streaming(struct ov8856 *ov8856) in ov8856_start_streaming() argument
1982 struct i2c_client *client = v4l2_get_subdevdata(&ov8856->sd); in ov8856_start_streaming()
1986 ret = ov8856_identify_module(ov8856); in ov8856_start_streaming()
1990 link_freq_index = ov8856->cur_mode->link_freq_index; in ov8856_start_streaming()
1991 reg_list = &ov8856->priv_lane->link_freq_configs[link_freq_index].reg_list; in ov8856_start_streaming()
1993 ret = ov8856_write_reg_list(ov8856, reg_list); in ov8856_start_streaming()
1999 reg_list = &ov8856->cur_mode->reg_list; in ov8856_start_streaming()
2000 ret = ov8856_write_reg_list(ov8856, reg_list); in ov8856_start_streaming()
2006 reg_list = &bayer_offset_configs[ov8856->cur_mbus_index]; in ov8856_start_streaming()
2007 ret = ov8856_write_reg_list(ov8856, reg_list); in ov8856_start_streaming()
2013 ret = __v4l2_ctrl_handler_setup(ov8856->sd.ctrl_handler); in ov8856_start_streaming()
2017 ret = ov8856_write_reg(ov8856, OV8856_REG_MODE_SELECT, in ov8856_start_streaming()
2027 static void ov8856_stop_streaming(struct ov8856 *ov8856) in ov8856_stop_streaming() argument
2029 struct i2c_client *client = v4l2_get_subdevdata(&ov8856->sd); in ov8856_stop_streaming()
2031 if (ov8856_write_reg(ov8856, OV8856_REG_MODE_SELECT, in ov8856_stop_streaming()
2038 struct ov8856 *ov8856 = to_ov8856(sd); in ov8856_set_stream() local
2042 mutex_lock(&ov8856->mutex); in ov8856_set_stream()
2046 mutex_unlock(&ov8856->mutex); in ov8856_set_stream()
2050 ret = ov8856_start_streaming(ov8856); in ov8856_set_stream()
2053 ov8856_stop_streaming(ov8856); in ov8856_set_stream()
2057 ov8856_stop_streaming(ov8856); in ov8856_set_stream()
2061 mutex_unlock(&ov8856->mutex); in ov8856_set_stream()
2069 struct ov8856 *ov8856 = to_ov8856(sd); in ov8856_power_on() local
2075 ret = clk_prepare_enable(ov8856->xvclk); in ov8856_power_on()
2081 if (ov8856->reset_gpio) { in ov8856_power_on()
2082 gpiod_set_value_cansleep(ov8856->reset_gpio, 1); in ov8856_power_on()
2087 ov8856->supplies); in ov8856_power_on()
2093 gpiod_set_value_cansleep(ov8856->reset_gpio, 0); in ov8856_power_on()
2099 gpiod_set_value_cansleep(ov8856->reset_gpio, 1); in ov8856_power_on()
2100 clk_disable_unprepare(ov8856->xvclk); in ov8856_power_on()
2108 struct ov8856 *ov8856 = to_ov8856(sd); in ov8856_power_off() local
2113 gpiod_set_value_cansleep(ov8856->reset_gpio, 1); in ov8856_power_off()
2115 ov8856->supplies); in ov8856_power_off()
2116 clk_disable_unprepare(ov8856->xvclk); in ov8856_power_off()
2125 struct ov8856 *ov8856 = to_ov8856(sd); in ov8856_set_format() local
2129 mode = v4l2_find_nearest_size(ov8856->priv_lane->supported_modes, in ov8856_set_format()
2130 ov8856->modes_size, in ov8856_set_format()
2134 mutex_lock(&ov8856->mutex); in ov8856_set_format()
2135 ov8856_update_pad_format(ov8856, mode, &fmt->format); in ov8856_set_format()
2139 ov8856->cur_mode = mode; in ov8856_set_format()
2140 __v4l2_ctrl_s_ctrl(ov8856->link_freq, mode->link_freq_index); in ov8856_set_format()
2141 __v4l2_ctrl_s_ctrl_int64(ov8856->pixel_rate, in ov8856_set_format()
2142 to_rate(ov8856->priv_lane->link_freq_menu_items, in ov8856_set_format()
2144 ov8856->cur_mode->data_lanes)); in ov8856_set_format()
2148 __v4l2_ctrl_modify_range(ov8856->vblank, in ov8856_set_format()
2152 __v4l2_ctrl_s_ctrl(ov8856->vblank, vblank_def); in ov8856_set_format()
2153 h_blank = to_pixels_per_line(ov8856->priv_lane->link_freq_menu_items, in ov8856_set_format()
2156 ov8856->cur_mode->data_lanes) in ov8856_set_format()
2158 __v4l2_ctrl_modify_range(ov8856->hblank, h_blank, h_blank, 1, in ov8856_set_format()
2162 mutex_unlock(&ov8856->mutex); in ov8856_set_format()
2171 struct ov8856 *ov8856 = to_ov8856(sd); in ov8856_get_format() local
2173 mutex_lock(&ov8856->mutex); in ov8856_get_format()
2178 ov8856_update_pad_format(ov8856, ov8856->cur_mode, &fmt->format); in ov8856_get_format()
2180 mutex_unlock(&ov8856->mutex); in ov8856_get_format()
2201 struct ov8856 *ov8856 = to_ov8856(sd); in ov8856_enum_frame_size() local
2204 if (fse->index >= ov8856->modes_size) in ov8856_enum_frame_size()
2213 fse->min_width = ov8856->priv_lane->supported_modes[fse->index].width; in ov8856_enum_frame_size()
2215 fse->min_height = ov8856->priv_lane->supported_modes[fse->index].height; in ov8856_enum_frame_size()
2223 struct ov8856 *ov8856 = to_ov8856(sd); in ov8856_open() local
2225 mutex_lock(&ov8856->mutex); in ov8856_open()
2226 ov8856_update_pad_format(ov8856, &ov8856->priv_lane->supported_modes[0], in ov8856_open()
2228 mutex_unlock(&ov8856->mutex); in ov8856_open()
2258 static int ov8856_get_hwcfg(struct ov8856 *ov8856, struct device *dev) in ov8856_get_hwcfg() argument
2277 ov8856->xvclk = devm_clk_get(dev, "xvclk"); in ov8856_get_hwcfg()
2278 if (IS_ERR(ov8856->xvclk)) { in ov8856_get_hwcfg()
2280 ov8856->xvclk); in ov8856_get_hwcfg()
2281 return PTR_ERR(ov8856->xvclk); in ov8856_get_hwcfg()
2284 clk_set_rate(ov8856->xvclk, xvclk_rate); in ov8856_get_hwcfg()
2285 xvclk_rate = clk_get_rate(ov8856->xvclk); in ov8856_get_hwcfg()
2287 ov8856->reset_gpio = devm_gpiod_get_optional(dev, "reset", in ov8856_get_hwcfg()
2289 if (IS_ERR(ov8856->reset_gpio)) in ov8856_get_hwcfg()
2290 return PTR_ERR(ov8856->reset_gpio); in ov8856_get_hwcfg()
2293 ov8856->supplies[i].supply = ov8856_supply_names[i]; in ov8856_get_hwcfg()
2297 ov8856->supplies); in ov8856_get_hwcfg()
2324 dev_dbg(dev, "Using %u data lanes\n", ov8856->cur_mode->data_lanes); in ov8856_get_hwcfg()
2327 ov8856->priv_lane = &lane_cfg_2; in ov8856_get_hwcfg()
2329 ov8856->priv_lane = &lane_cfg_4; in ov8856_get_hwcfg()
2331 ov8856->modes_size = ov8856_modes_num(ov8856); in ov8856_get_hwcfg()
2339 for (i = 0; i < ARRAY_SIZE(ov8856->priv_lane->link_freq_menu_items); i++) { in ov8856_get_hwcfg()
2341 if (ov8856->priv_lane->link_freq_menu_items[i] == in ov8856_get_hwcfg()
2348 ov8856->priv_lane->link_freq_menu_items[i]); in ov8856_get_hwcfg()
2363 struct ov8856 *ov8856 = to_ov8856(sd); in ov8856_remove() local
2369 mutex_destroy(&ov8856->mutex); in ov8856_remove()
2376 struct ov8856 *ov8856; in ov8856_probe() local
2380 ov8856 = devm_kzalloc(&client->dev, sizeof(*ov8856), GFP_KERNEL); in ov8856_probe()
2381 if (!ov8856) in ov8856_probe()
2384 ret = ov8856_get_hwcfg(ov8856, &client->dev); in ov8856_probe()
2391 v4l2_i2c_subdev_init(&ov8856->sd, client, &ov8856_subdev_ops); in ov8856_probe()
2401 ret = ov8856_identify_module(ov8856); in ov8856_probe()
2408 mutex_init(&ov8856->mutex); in ov8856_probe()
2409 ov8856->cur_mode = &ov8856->priv_lane->supported_modes[0]; in ov8856_probe()
2410 ov8856->cur_mbus_index = ov8856->cur_mode->default_mbus_index; in ov8856_probe()
2411 ret = ov8856_init_controls(ov8856); in ov8856_probe()
2417 ov8856->sd.internal_ops = &ov8856_internal_ops; in ov8856_probe()
2418 ov8856->sd.flags |= V4L2_SUBDEV_FL_HAS_DEVNODE; in ov8856_probe()
2419 ov8856->sd.entity.ops = &ov8856_subdev_entity_ops; in ov8856_probe()
2420 ov8856->sd.entity.function = MEDIA_ENT_F_CAM_SENSOR; in ov8856_probe()
2421 ov8856->pad.flags = MEDIA_PAD_FL_SOURCE; in ov8856_probe()
2422 ret = media_entity_pads_init(&ov8856->sd.entity, 1, &ov8856->pad); in ov8856_probe()
2428 ret = v4l2_async_register_subdev_sensor(&ov8856->sd); in ov8856_probe()
2444 media_entity_cleanup(&ov8856->sd.entity); in ov8856_probe()
2447 v4l2_ctrl_handler_free(ov8856->sd.ctrl_handler); in ov8856_probe()
2448 mutex_destroy(&ov8856->mutex); in ov8856_probe()
2470 { .compatible = "ovti,ov8856" },
2477 .name = "ov8856",
2490 MODULE_DESCRIPTION("OmniVision OV8856 sensor driver");