Lines Matching refs:ov8856

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