Lines Matching full:ov8856
102 #define to_ov8856(_sd) container_of(_sd, struct ov8856, sd)
1383 struct ov8856 { struct
1547 static unsigned int ov8856_modes_num(const struct ov8856 *ov8856) in ov8856_modes_num() argument
1551 for (i = 0; i < ARRAY_SIZE(ov8856->priv_lane->supported_modes); i++) { in ov8856_modes_num()
1552 if (ov8856->priv_lane->supported_modes[i].width == 0) in ov8856_modes_num()
1580 static int ov8856_read_reg(struct ov8856 *ov8856, u16 reg, u16 len, u32 *val) in ov8856_read_reg() argument
1582 struct i2c_client *client = v4l2_get_subdevdata(&ov8856->sd); in ov8856_read_reg()
1610 static int ov8856_write_reg(struct ov8856 *ov8856, u16 reg, u16 len, u32 val) in ov8856_write_reg() argument
1612 struct i2c_client *client = v4l2_get_subdevdata(&ov8856->sd); in ov8856_write_reg()
1626 static int ov8856_write_reg_list(struct ov8856 *ov8856, in ov8856_write_reg_list() argument
1629 struct i2c_client *client = v4l2_get_subdevdata(&ov8856->sd); in ov8856_write_reg_list()
1634 ret = ov8856_write_reg(ov8856, r_list->regs[i].address, 1, in ov8856_write_reg_list()
1647 static int ov8856_update_digital_gain(struct ov8856 *ov8856, u32 d_gain) in ov8856_update_digital_gain() argument
1651 ret = ov8856_write_reg(ov8856, OV8856_REG_MWB_R_GAIN, in ov8856_update_digital_gain()
1656 ret = ov8856_write_reg(ov8856, OV8856_REG_MWB_G_GAIN, in ov8856_update_digital_gain()
1661 return ov8856_write_reg(ov8856, OV8856_REG_MWB_B_GAIN, in ov8856_update_digital_gain()
1665 static int ov8856_test_pattern(struct ov8856 *ov8856, u32 pattern) in ov8856_test_pattern() argument
1671 return ov8856_write_reg(ov8856, OV8856_REG_TEST_PATTERN, in ov8856_test_pattern()
1675 static int ov8856_set_ctrl_hflip(struct ov8856 *ov8856, u32 ctrl_val) in ov8856_set_ctrl_hflip() argument
1680 ret = ov8856_read_reg(ov8856, OV8856_REG_MIRROR_OPT_1, in ov8856_set_ctrl_hflip()
1685 ret = ov8856_write_reg(ov8856, OV8856_REG_MIRROR_OPT_1, in ov8856_set_ctrl_hflip()
1693 ret = ov8856_read_reg(ov8856, OV8856_REG_FORMAT2, in ov8856_set_ctrl_hflip()
1698 return ov8856_write_reg(ov8856, OV8856_REG_FORMAT2, in ov8856_set_ctrl_hflip()
1708 static int ov8856_set_ctrl_vflip(struct ov8856 *ov8856, u8 ctrl_val) in ov8856_set_ctrl_vflip() argument
1713 ret = ov8856_read_reg(ov8856, OV8856_REG_FLIP_OPT_1, in ov8856_set_ctrl_vflip()
1718 ret = ov8856_write_reg(ov8856, OV8856_REG_FLIP_OPT_1, in ov8856_set_ctrl_vflip()
1725 ret = ov8856_read_reg(ov8856, OV8856_REG_FLIP_OPT_2, in ov8856_set_ctrl_vflip()
1730 ret = ov8856_write_reg(ov8856, OV8856_REG_FLIP_OPT_2, in ov8856_set_ctrl_vflip()
1735 ret = ov8856_read_reg(ov8856, OV8856_REG_FLIP_OPT_3, in ov8856_set_ctrl_vflip()
1740 ret = ov8856_write_reg(ov8856, OV8856_REG_FLIP_OPT_3, in ov8856_set_ctrl_vflip()
1747 ret = ov8856_read_reg(ov8856, OV8856_REG_FORMAT1, in ov8856_set_ctrl_vflip()
1752 return ov8856_write_reg(ov8856, OV8856_REG_FORMAT1, in ov8856_set_ctrl_vflip()
1764 struct ov8856 *ov8856 = container_of(ctrl->handler, in ov8856_set_ctrl() local
1765 struct ov8856, ctrl_handler); in ov8856_set_ctrl()
1766 struct i2c_client *client = v4l2_get_subdevdata(&ov8856->sd); in ov8856_set_ctrl()
1773 exposure_max = ov8856->cur_mode->height + ctrl->val - in ov8856_set_ctrl()
1775 __v4l2_ctrl_modify_range(ov8856->exposure, in ov8856_set_ctrl()
1776 ov8856->exposure->minimum, in ov8856_set_ctrl()
1777 exposure_max, ov8856->exposure->step, in ov8856_set_ctrl()
1787 ret = ov8856_write_reg(ov8856, OV8856_REG_ANALOG_GAIN, in ov8856_set_ctrl()
1792 ret = ov8856_update_digital_gain(ov8856, ctrl->val); in ov8856_set_ctrl()
1797 ret = ov8856_write_reg(ov8856, OV8856_REG_EXPOSURE, in ov8856_set_ctrl()
1802 ret = ov8856_write_reg(ov8856, OV8856_REG_VTS, in ov8856_set_ctrl()
1804 ov8856->cur_mode->height + ctrl->val); in ov8856_set_ctrl()
1808 ret = ov8856_test_pattern(ov8856, ctrl->val); in ov8856_set_ctrl()
1812 ret = ov8856_set_ctrl_hflip(ov8856, ctrl->val); in ov8856_set_ctrl()
1816 ret = ov8856_set_ctrl_vflip(ov8856, ctrl->val); in ov8856_set_ctrl()
1833 static int ov8856_init_controls(struct ov8856 *ov8856) in ov8856_init_controls() argument
1839 ctrl_hdlr = &ov8856->ctrl_handler; in ov8856_init_controls()
1844 ctrl_hdlr->lock = &ov8856->mutex; in ov8856_init_controls()
1845 ov8856->link_freq = v4l2_ctrl_new_int_menu(ctrl_hdlr, &ov8856_ctrl_ops, in ov8856_init_controls()
1848 (ov8856->priv_lane->link_freq_menu_items) in ov8856_init_controls()
1850 0, ov8856->priv_lane->link_freq_menu_items); in ov8856_init_controls()
1851 if (ov8856->link_freq) in ov8856_init_controls()
1852 ov8856->link_freq->flags |= V4L2_CTRL_FLAG_READ_ONLY; in ov8856_init_controls()
1854 ov8856->pixel_rate = v4l2_ctrl_new_std(ctrl_hdlr, &ov8856_ctrl_ops, in ov8856_init_controls()
1856 to_rate(ov8856->priv_lane->link_freq_menu_items, in ov8856_init_controls()
1858 ov8856->cur_mode->data_lanes), 1, in ov8856_init_controls()
1859 to_rate(ov8856->priv_lane->link_freq_menu_items, in ov8856_init_controls()
1861 ov8856->cur_mode->data_lanes)); in ov8856_init_controls()
1862 ov8856->vblank = v4l2_ctrl_new_std(ctrl_hdlr, &ov8856_ctrl_ops, in ov8856_init_controls()
1864 ov8856->cur_mode->vts_min - ov8856->cur_mode->height, in ov8856_init_controls()
1865 OV8856_VTS_MAX - ov8856->cur_mode->height, 1, in ov8856_init_controls()
1866 ov8856->cur_mode->vts_def - in ov8856_init_controls()
1867 ov8856->cur_mode->height); in ov8856_init_controls()
1868 h_blank = to_pixels_per_line(ov8856->priv_lane->link_freq_menu_items, in ov8856_init_controls()
1869 ov8856->cur_mode->hts, in ov8856_init_controls()
1870 ov8856->cur_mode->link_freq_index, in ov8856_init_controls()
1871 ov8856->cur_mode->data_lanes) - in ov8856_init_controls()
1872 ov8856->cur_mode->width; in ov8856_init_controls()
1873 ov8856->hblank = v4l2_ctrl_new_std(ctrl_hdlr, &ov8856_ctrl_ops, in ov8856_init_controls()
1876 if (ov8856->hblank) in ov8856_init_controls()
1877 ov8856->hblank->flags |= V4L2_CTRL_FLAG_READ_ONLY; in ov8856_init_controls()
1885 exposure_max = ov8856->cur_mode->vts_def - OV8856_EXPOSURE_MAX_MARGIN; in ov8856_init_controls()
1886 ov8856->exposure = v4l2_ctrl_new_std(ctrl_hdlr, &ov8856_ctrl_ops, in ov8856_init_controls()
1902 ov8856->sd.ctrl_handler = ctrl_hdlr; in ov8856_init_controls()
1916 static int ov8856_start_streaming(struct ov8856 *ov8856) in ov8856_start_streaming() argument
1918 struct i2c_client *client = v4l2_get_subdevdata(&ov8856->sd); in ov8856_start_streaming()
1922 link_freq_index = ov8856->cur_mode->link_freq_index; in ov8856_start_streaming()
1923 reg_list = &ov8856->priv_lane->link_freq_configs[link_freq_index].reg_list; in ov8856_start_streaming()
1925 ret = ov8856_write_reg_list(ov8856, reg_list); in ov8856_start_streaming()
1931 reg_list = &ov8856->cur_mode->reg_list; in ov8856_start_streaming()
1932 ret = ov8856_write_reg_list(ov8856, reg_list); in ov8856_start_streaming()
1938 ret = __v4l2_ctrl_handler_setup(ov8856->sd.ctrl_handler); in ov8856_start_streaming()
1942 ret = ov8856_write_reg(ov8856, OV8856_REG_MODE_SELECT, in ov8856_start_streaming()
1952 static void ov8856_stop_streaming(struct ov8856 *ov8856) in ov8856_stop_streaming() argument
1954 struct i2c_client *client = v4l2_get_subdevdata(&ov8856->sd); in ov8856_stop_streaming()
1956 if (ov8856_write_reg(ov8856, OV8856_REG_MODE_SELECT, in ov8856_stop_streaming()
1963 struct ov8856 *ov8856 = to_ov8856(sd); in ov8856_set_stream() local
1967 if (ov8856->streaming == enable) in ov8856_set_stream()
1970 mutex_lock(&ov8856->mutex); in ov8856_set_stream()
1974 mutex_unlock(&ov8856->mutex); in ov8856_set_stream()
1978 ret = ov8856_start_streaming(ov8856); in ov8856_set_stream()
1981 ov8856_stop_streaming(ov8856); in ov8856_set_stream()
1985 ov8856_stop_streaming(ov8856); in ov8856_set_stream()
1989 ov8856->streaming = enable; in ov8856_set_stream()
1990 mutex_unlock(&ov8856->mutex); in ov8856_set_stream()
1995 static int __ov8856_power_on(struct ov8856 *ov8856) in __ov8856_power_on() argument
1997 struct i2c_client *client = v4l2_get_subdevdata(&ov8856->sd); in __ov8856_power_on()
2003 ret = clk_prepare_enable(ov8856->xvclk); in __ov8856_power_on()
2009 if (ov8856->reset_gpio) { in __ov8856_power_on()
2010 gpiod_set_value_cansleep(ov8856->reset_gpio, 1); in __ov8856_power_on()
2015 ov8856->supplies); in __ov8856_power_on()
2021 gpiod_set_value_cansleep(ov8856->reset_gpio, 0); in __ov8856_power_on()
2027 gpiod_set_value_cansleep(ov8856->reset_gpio, 1); in __ov8856_power_on()
2028 clk_disable_unprepare(ov8856->xvclk); in __ov8856_power_on()
2033 static void __ov8856_power_off(struct ov8856 *ov8856) in __ov8856_power_off() argument
2035 struct i2c_client *client = v4l2_get_subdevdata(&ov8856->sd); in __ov8856_power_off()
2040 gpiod_set_value_cansleep(ov8856->reset_gpio, 1); in __ov8856_power_off()
2042 ov8856->supplies); in __ov8856_power_off()
2043 clk_disable_unprepare(ov8856->xvclk); in __ov8856_power_off()
2049 struct ov8856 *ov8856 = to_ov8856(sd); in ov8856_suspend() local
2051 mutex_lock(&ov8856->mutex); in ov8856_suspend()
2052 if (ov8856->streaming) in ov8856_suspend()
2053 ov8856_stop_streaming(ov8856); in ov8856_suspend()
2055 __ov8856_power_off(ov8856); in ov8856_suspend()
2056 mutex_unlock(&ov8856->mutex); in ov8856_suspend()
2064 struct ov8856 *ov8856 = to_ov8856(sd); in ov8856_resume() local
2067 mutex_lock(&ov8856->mutex); in ov8856_resume()
2069 __ov8856_power_on(ov8856); in ov8856_resume()
2070 if (ov8856->streaming) { in ov8856_resume()
2071 ret = ov8856_start_streaming(ov8856); in ov8856_resume()
2073 ov8856->streaming = false; in ov8856_resume()
2074 ov8856_stop_streaming(ov8856); in ov8856_resume()
2075 mutex_unlock(&ov8856->mutex); in ov8856_resume()
2080 mutex_unlock(&ov8856->mutex); in ov8856_resume()
2089 struct ov8856 *ov8856 = to_ov8856(sd); in ov8856_set_format() local
2093 mode = v4l2_find_nearest_size(ov8856->priv_lane->supported_modes, in ov8856_set_format()
2094 ov8856->modes_size, in ov8856_set_format()
2098 mutex_lock(&ov8856->mutex); in ov8856_set_format()
2103 ov8856->cur_mode = mode; in ov8856_set_format()
2104 __v4l2_ctrl_s_ctrl(ov8856->link_freq, mode->link_freq_index); in ov8856_set_format()
2105 __v4l2_ctrl_s_ctrl_int64(ov8856->pixel_rate, in ov8856_set_format()
2106 to_rate(ov8856->priv_lane->link_freq_menu_items, in ov8856_set_format()
2108 ov8856->cur_mode->data_lanes)); in ov8856_set_format()
2112 __v4l2_ctrl_modify_range(ov8856->vblank, in ov8856_set_format()
2116 __v4l2_ctrl_s_ctrl(ov8856->vblank, vblank_def); in ov8856_set_format()
2117 h_blank = to_pixels_per_line(ov8856->priv_lane->link_freq_menu_items, in ov8856_set_format()
2120 ov8856->cur_mode->data_lanes) in ov8856_set_format()
2122 __v4l2_ctrl_modify_range(ov8856->hblank, h_blank, h_blank, 1, in ov8856_set_format()
2126 mutex_unlock(&ov8856->mutex); in ov8856_set_format()
2135 struct ov8856 *ov8856 = to_ov8856(sd); in ov8856_get_format() local
2137 mutex_lock(&ov8856->mutex); in ov8856_get_format()
2139 fmt->format = *v4l2_subdev_get_try_format(&ov8856->sd, in ov8856_get_format()
2143 ov8856_update_pad_format(ov8856->cur_mode, &fmt->format); in ov8856_get_format()
2145 mutex_unlock(&ov8856->mutex); in ov8856_get_format()
2167 struct ov8856 *ov8856 = to_ov8856(sd); in ov8856_enum_frame_size() local
2169 if (fse->index >= ov8856->modes_size) in ov8856_enum_frame_size()
2175 fse->min_width = ov8856->priv_lane->supported_modes[fse->index].width; in ov8856_enum_frame_size()
2177 fse->min_height = ov8856->priv_lane->supported_modes[fse->index].height; in ov8856_enum_frame_size()
2185 struct ov8856 *ov8856 = to_ov8856(sd); in ov8856_open() local
2187 mutex_lock(&ov8856->mutex); in ov8856_open()
2188 ov8856_update_pad_format(&ov8856->priv_lane->supported_modes[0], in ov8856_open()
2190 mutex_unlock(&ov8856->mutex); in ov8856_open()
2219 static int ov8856_identify_module(struct ov8856 *ov8856) in ov8856_identify_module() argument
2221 struct i2c_client *client = v4l2_get_subdevdata(&ov8856->sd); in ov8856_identify_module()
2225 ret = ov8856_read_reg(ov8856, OV8856_REG_CHIP_ID, in ov8856_identify_module()
2236 ret = ov8856_write_reg(ov8856, OV8856_REG_MODE_SELECT, in ov8856_identify_module()
2241 ret = ov8856_write_reg(ov8856, OV8856_OTP_MODE_CTRL, in ov8856_identify_module()
2248 ret = ov8856_write_reg(ov8856, OV8856_OTP_LOAD_CTRL, in ov8856_identify_module()
2256 ret = ov8856_read_reg(ov8856, OV8856_MODULE_REVISION, in ov8856_identify_module()
2263 dev_info(&client->dev, "OV8856 revision %x (%s) at address 0x%02x\n", in ov8856_identify_module()
2269 ret = ov8856_write_reg(ov8856, OV8856_REG_MODE_SELECT, in ov8856_identify_module()
2279 static int ov8856_get_hwcfg(struct ov8856 *ov8856, struct device *dev) in ov8856_get_hwcfg() argument
2298 ov8856->xvclk = devm_clk_get(dev, "xvclk"); in ov8856_get_hwcfg()
2299 if (IS_ERR(ov8856->xvclk)) { in ov8856_get_hwcfg()
2301 ov8856->xvclk); in ov8856_get_hwcfg()
2302 return PTR_ERR(ov8856->xvclk); in ov8856_get_hwcfg()
2305 clk_set_rate(ov8856->xvclk, xvclk_rate); in ov8856_get_hwcfg()
2306 xvclk_rate = clk_get_rate(ov8856->xvclk); in ov8856_get_hwcfg()
2308 ov8856->reset_gpio = devm_gpiod_get_optional(dev, "reset", in ov8856_get_hwcfg()
2310 if (IS_ERR(ov8856->reset_gpio)) in ov8856_get_hwcfg()
2311 return PTR_ERR(ov8856->reset_gpio); in ov8856_get_hwcfg()
2314 ov8856->supplies[i].supply = ov8856_supply_names[i]; in ov8856_get_hwcfg()
2318 ov8856->supplies); in ov8856_get_hwcfg()
2345 dev_dbg(dev, "Using %u data lanes\n", ov8856->cur_mode->data_lanes); in ov8856_get_hwcfg()
2348 ov8856->priv_lane = &lane_cfg_2; in ov8856_get_hwcfg()
2350 ov8856->priv_lane = &lane_cfg_4; in ov8856_get_hwcfg()
2352 ov8856->modes_size = ov8856_modes_num(ov8856); in ov8856_get_hwcfg()
2360 for (i = 0; i < ARRAY_SIZE(ov8856->priv_lane->link_freq_menu_items); i++) { in ov8856_get_hwcfg()
2362 if (ov8856->priv_lane->link_freq_menu_items[i] == in ov8856_get_hwcfg()
2369 ov8856->priv_lane->link_freq_menu_items[i]); in ov8856_get_hwcfg()
2384 struct ov8856 *ov8856 = to_ov8856(sd); in ov8856_remove() local
2390 mutex_destroy(&ov8856->mutex); in ov8856_remove()
2392 __ov8856_power_off(ov8856); in ov8856_remove()
2399 struct ov8856 *ov8856; in ov8856_probe() local
2402 ov8856 = devm_kzalloc(&client->dev, sizeof(*ov8856), GFP_KERNEL); in ov8856_probe()
2403 if (!ov8856) in ov8856_probe()
2406 ret = ov8856_get_hwcfg(ov8856, &client->dev); in ov8856_probe()
2413 v4l2_i2c_subdev_init(&ov8856->sd, client, &ov8856_subdev_ops); in ov8856_probe()
2415 ret = __ov8856_power_on(ov8856); in ov8856_probe()
2421 ret = ov8856_identify_module(ov8856); in ov8856_probe()
2427 mutex_init(&ov8856->mutex); in ov8856_probe()
2428 ov8856->cur_mode = &ov8856->priv_lane->supported_modes[0]; in ov8856_probe()
2429 ret = ov8856_init_controls(ov8856); in ov8856_probe()
2435 ov8856->sd.internal_ops = &ov8856_internal_ops; in ov8856_probe()
2436 ov8856->sd.flags |= V4L2_SUBDEV_FL_HAS_DEVNODE; in ov8856_probe()
2437 ov8856->sd.entity.ops = &ov8856_subdev_entity_ops; in ov8856_probe()
2438 ov8856->sd.entity.function = MEDIA_ENT_F_CAM_SENSOR; in ov8856_probe()
2439 ov8856->pad.flags = MEDIA_PAD_FL_SOURCE; in ov8856_probe()
2440 ret = media_entity_pads_init(&ov8856->sd.entity, 1, &ov8856->pad); in ov8856_probe()
2446 ret = v4l2_async_register_subdev_sensor(&ov8856->sd); in ov8856_probe()
2464 media_entity_cleanup(&ov8856->sd.entity); in ov8856_probe()
2467 v4l2_ctrl_handler_free(ov8856->sd.ctrl_handler); in ov8856_probe()
2468 mutex_destroy(&ov8856->mutex); in ov8856_probe()
2471 __ov8856_power_off(ov8856); in ov8856_probe()
2490 { .compatible = "ovti,ov8856" },
2497 .name = "ov8856",
2509 MODULE_DESCRIPTION("OmniVision OV8856 sensor driver");