Lines Matching full: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 ret = ov8856_write_reg(ov8856, OV8856_REG_MODE_SELECT, in ov8856_identify_module()
1717 ret = ov8856_write_reg(ov8856, OV8856_OTP_MODE_CTRL, in ov8856_identify_module()
1724 ret = ov8856_write_reg(ov8856, OV8856_OTP_LOAD_CTRL, in ov8856_identify_module()
1732 ret = ov8856_read_reg(ov8856, OV8856_MODULE_REVISION, in ov8856_identify_module()
1739 dev_info(&client->dev, "OV8856 revision %x (%s) at address 0x%02x\n", in ov8856_identify_module()
1745 ret = ov8856_write_reg(ov8856, OV8856_REG_MODE_SELECT, in ov8856_identify_module()
1752 ov8856->identified = true; in ov8856_identify_module()
1757 static int ov8856_update_digital_gain(struct ov8856 *ov8856, u32 d_gain) in ov8856_update_digital_gain() argument
1759 return ov8856_write_reg(ov8856, OV8856_REG_DIGITAL_GAIN, in ov8856_update_digital_gain()
1763 static int ov8856_test_pattern(struct ov8856 *ov8856, u32 pattern) in ov8856_test_pattern() argument
1769 return ov8856_write_reg(ov8856, OV8856_REG_TEST_PATTERN, in ov8856_test_pattern()
1773 static int ov8856_set_ctrl_hflip(struct ov8856 *ov8856, u32 ctrl_val) in ov8856_set_ctrl_hflip() argument
1778 ret = ov8856_read_reg(ov8856, OV8856_REG_MIRROR_OPT_1, in ov8856_set_ctrl_hflip()
1783 ret = ov8856_write_reg(ov8856, OV8856_REG_MIRROR_OPT_1, in ov8856_set_ctrl_hflip()
1791 ret = ov8856_read_reg(ov8856, OV8856_REG_FORMAT2, in ov8856_set_ctrl_hflip()
1796 return ov8856_write_reg(ov8856, OV8856_REG_FORMAT2, in ov8856_set_ctrl_hflip()
1806 static int ov8856_set_ctrl_vflip(struct ov8856 *ov8856, u8 ctrl_val) in ov8856_set_ctrl_vflip() argument
1811 ret = ov8856_read_reg(ov8856, OV8856_REG_FLIP_OPT_1, in ov8856_set_ctrl_vflip()
1816 ret = ov8856_write_reg(ov8856, OV8856_REG_FLIP_OPT_1, in ov8856_set_ctrl_vflip()
1823 ret = ov8856_read_reg(ov8856, OV8856_REG_FLIP_OPT_2, in ov8856_set_ctrl_vflip()
1828 ret = ov8856_write_reg(ov8856, OV8856_REG_FLIP_OPT_2, in ov8856_set_ctrl_vflip()
1833 ret = ov8856_read_reg(ov8856, OV8856_REG_FLIP_OPT_3, in ov8856_set_ctrl_vflip()
1838 ret = ov8856_write_reg(ov8856, OV8856_REG_FLIP_OPT_3, in ov8856_set_ctrl_vflip()
1845 ret = ov8856_read_reg(ov8856, OV8856_REG_FORMAT1, in ov8856_set_ctrl_vflip()
1850 return ov8856_write_reg(ov8856, OV8856_REG_FORMAT1, in ov8856_set_ctrl_vflip()
1862 struct ov8856 *ov8856 = container_of(ctrl->handler, in ov8856_set_ctrl() local
1863 struct ov8856, ctrl_handler); in ov8856_set_ctrl()
1864 struct i2c_client *client = v4l2_get_subdevdata(&ov8856->sd); in ov8856_set_ctrl()
1871 exposure_max = ov8856->cur_mode->height + ctrl->val - in ov8856_set_ctrl()
1873 __v4l2_ctrl_modify_range(ov8856->exposure, in ov8856_set_ctrl()
1874 ov8856->exposure->minimum, in ov8856_set_ctrl()
1875 exposure_max, ov8856->exposure->step, in ov8856_set_ctrl()
1885 ret = ov8856_write_reg(ov8856, OV8856_REG_ANALOG_GAIN, in ov8856_set_ctrl()
1890 ret = ov8856_update_digital_gain(ov8856, ctrl->val); in ov8856_set_ctrl()
1895 ret = ov8856_write_reg(ov8856, OV8856_REG_EXPOSURE, in ov8856_set_ctrl()
1900 ret = ov8856_write_reg(ov8856, OV8856_REG_VTS, in ov8856_set_ctrl()
1902 ov8856->cur_mode->height + ctrl->val); in ov8856_set_ctrl()
1906 ret = ov8856_test_pattern(ov8856, ctrl->val); in ov8856_set_ctrl()
1910 ret = ov8856_set_ctrl_hflip(ov8856, ctrl->val); in ov8856_set_ctrl()
1914 ret = ov8856_set_ctrl_vflip(ov8856, ctrl->val); in ov8856_set_ctrl()
1931 static int ov8856_init_controls(struct ov8856 *ov8856) in ov8856_init_controls() argument
1937 ctrl_hdlr = &ov8856->ctrl_handler; in ov8856_init_controls()
1942 ctrl_hdlr->lock = &ov8856->mutex; in ov8856_init_controls()
1943 ov8856->link_freq = v4l2_ctrl_new_int_menu(ctrl_hdlr, &ov8856_ctrl_ops, in ov8856_init_controls()
1946 (ov8856->priv_lane->link_freq_menu_items) in ov8856_init_controls()
1948 0, ov8856->priv_lane->link_freq_menu_items); in ov8856_init_controls()
1949 if (ov8856->link_freq) in ov8856_init_controls()
1950 ov8856->link_freq->flags |= V4L2_CTRL_FLAG_READ_ONLY; in ov8856_init_controls()
1952 ov8856->pixel_rate = v4l2_ctrl_new_std(ctrl_hdlr, &ov8856_ctrl_ops, in ov8856_init_controls()
1954 to_rate(ov8856->priv_lane->link_freq_menu_items, in ov8856_init_controls()
1956 ov8856->cur_mode->data_lanes), 1, in ov8856_init_controls()
1957 to_rate(ov8856->priv_lane->link_freq_menu_items, in ov8856_init_controls()
1959 ov8856->cur_mode->data_lanes)); in ov8856_init_controls()
1960 ov8856->vblank = v4l2_ctrl_new_std(ctrl_hdlr, &ov8856_ctrl_ops, in ov8856_init_controls()
1962 ov8856->cur_mode->vts_min - ov8856->cur_mode->height, in ov8856_init_controls()
1963 OV8856_VTS_MAX - ov8856->cur_mode->height, 1, in ov8856_init_controls()
1964 ov8856->cur_mode->vts_def - in ov8856_init_controls()
1965 ov8856->cur_mode->height); in ov8856_init_controls()
1966 h_blank = to_pixels_per_line(ov8856->priv_lane->link_freq_menu_items, in ov8856_init_controls()
1967 ov8856->cur_mode->hts, in ov8856_init_controls()
1968 ov8856->cur_mode->link_freq_index, in ov8856_init_controls()
1969 ov8856->cur_mode->data_lanes) - in ov8856_init_controls()
1970 ov8856->cur_mode->width; in ov8856_init_controls()
1971 ov8856->hblank = v4l2_ctrl_new_std(ctrl_hdlr, &ov8856_ctrl_ops, in ov8856_init_controls()
1974 if (ov8856->hblank) in ov8856_init_controls()
1975 ov8856->hblank->flags |= V4L2_CTRL_FLAG_READ_ONLY; in ov8856_init_controls()
1983 exposure_max = ov8856->cur_mode->vts_def - OV8856_EXPOSURE_MAX_MARGIN; in ov8856_init_controls()
1984 ov8856->exposure = v4l2_ctrl_new_std(ctrl_hdlr, &ov8856_ctrl_ops, in ov8856_init_controls()
2000 ov8856->sd.ctrl_handler = ctrl_hdlr; in ov8856_init_controls()
2005 static void ov8856_update_pad_format(struct ov8856 *ov8856, in ov8856_update_pad_format() argument
2019 ov8856->cur_mbus_index = index; in ov8856_update_pad_format()
2023 static int ov8856_start_streaming(struct ov8856 *ov8856) in ov8856_start_streaming() argument
2025 struct i2c_client *client = v4l2_get_subdevdata(&ov8856->sd); in ov8856_start_streaming()
2029 ret = ov8856_identify_module(ov8856); in ov8856_start_streaming()
2033 link_freq_index = ov8856->cur_mode->link_freq_index; in ov8856_start_streaming()
2034 reg_list = &ov8856->priv_lane->link_freq_configs[link_freq_index].reg_list; in ov8856_start_streaming()
2036 ret = ov8856_write_reg_list(ov8856, reg_list); in ov8856_start_streaming()
2042 reg_list = &ov8856->cur_mode->reg_list; in ov8856_start_streaming()
2043 ret = ov8856_write_reg_list(ov8856, reg_list); in ov8856_start_streaming()
2049 reg_list = &bayer_offset_configs[ov8856->cur_mbus_index]; in ov8856_start_streaming()
2050 ret = ov8856_write_reg_list(ov8856, reg_list); in ov8856_start_streaming()
2056 ret = __v4l2_ctrl_handler_setup(ov8856->sd.ctrl_handler); in ov8856_start_streaming()
2060 ret = ov8856_write_reg(ov8856, OV8856_REG_MODE_SELECT, in ov8856_start_streaming()
2070 static void ov8856_stop_streaming(struct ov8856 *ov8856) in ov8856_stop_streaming() argument
2072 struct i2c_client *client = v4l2_get_subdevdata(&ov8856->sd); in ov8856_stop_streaming()
2074 if (ov8856_write_reg(ov8856, OV8856_REG_MODE_SELECT, in ov8856_stop_streaming()
2081 struct ov8856 *ov8856 = to_ov8856(sd); in ov8856_set_stream() local
2085 if (ov8856->streaming == enable) in ov8856_set_stream()
2088 mutex_lock(&ov8856->mutex); in ov8856_set_stream()
2092 mutex_unlock(&ov8856->mutex); in ov8856_set_stream()
2096 ret = ov8856_start_streaming(ov8856); in ov8856_set_stream()
2099 ov8856_stop_streaming(ov8856); in ov8856_set_stream()
2103 ov8856_stop_streaming(ov8856); in ov8856_set_stream()
2107 ov8856->streaming = enable; in ov8856_set_stream()
2108 mutex_unlock(&ov8856->mutex); in ov8856_set_stream()
2113 static int __ov8856_power_on(struct ov8856 *ov8856) in __ov8856_power_on() argument
2115 struct i2c_client *client = v4l2_get_subdevdata(&ov8856->sd); in __ov8856_power_on()
2121 ret = clk_prepare_enable(ov8856->xvclk); in __ov8856_power_on()
2127 if (ov8856->reset_gpio) { in __ov8856_power_on()
2128 gpiod_set_value_cansleep(ov8856->reset_gpio, 1); in __ov8856_power_on()
2133 ov8856->supplies); in __ov8856_power_on()
2139 gpiod_set_value_cansleep(ov8856->reset_gpio, 0); in __ov8856_power_on()
2145 gpiod_set_value_cansleep(ov8856->reset_gpio, 1); in __ov8856_power_on()
2146 clk_disable_unprepare(ov8856->xvclk); in __ov8856_power_on()
2151 static void __ov8856_power_off(struct ov8856 *ov8856) in __ov8856_power_off() argument
2153 struct i2c_client *client = v4l2_get_subdevdata(&ov8856->sd); in __ov8856_power_off()
2158 gpiod_set_value_cansleep(ov8856->reset_gpio, 1); in __ov8856_power_off()
2160 ov8856->supplies); in __ov8856_power_off()
2161 clk_disable_unprepare(ov8856->xvclk); in __ov8856_power_off()
2167 struct ov8856 *ov8856 = to_ov8856(sd); in ov8856_suspend() local
2169 mutex_lock(&ov8856->mutex); in ov8856_suspend()
2170 if (ov8856->streaming) in ov8856_suspend()
2171 ov8856_stop_streaming(ov8856); in ov8856_suspend()
2173 __ov8856_power_off(ov8856); in ov8856_suspend()
2174 mutex_unlock(&ov8856->mutex); in ov8856_suspend()
2182 struct ov8856 *ov8856 = to_ov8856(sd); in ov8856_resume() local
2185 mutex_lock(&ov8856->mutex); in ov8856_resume()
2187 __ov8856_power_on(ov8856); in ov8856_resume()
2188 if (ov8856->streaming) { in ov8856_resume()
2189 ret = ov8856_start_streaming(ov8856); in ov8856_resume()
2191 ov8856->streaming = false; in ov8856_resume()
2192 ov8856_stop_streaming(ov8856); in ov8856_resume()
2193 mutex_unlock(&ov8856->mutex); in ov8856_resume()
2198 mutex_unlock(&ov8856->mutex); in ov8856_resume()
2207 struct ov8856 *ov8856 = to_ov8856(sd); in ov8856_set_format() local
2211 mode = v4l2_find_nearest_size(ov8856->priv_lane->supported_modes, in ov8856_set_format()
2212 ov8856->modes_size, in ov8856_set_format()
2216 mutex_lock(&ov8856->mutex); in ov8856_set_format()
2217 ov8856_update_pad_format(ov8856, mode, &fmt->format); in ov8856_set_format()
2221 ov8856->cur_mode = mode; in ov8856_set_format()
2222 __v4l2_ctrl_s_ctrl(ov8856->link_freq, mode->link_freq_index); in ov8856_set_format()
2223 __v4l2_ctrl_s_ctrl_int64(ov8856->pixel_rate, in ov8856_set_format()
2224 to_rate(ov8856->priv_lane->link_freq_menu_items, in ov8856_set_format()
2226 ov8856->cur_mode->data_lanes)); in ov8856_set_format()
2230 __v4l2_ctrl_modify_range(ov8856->vblank, in ov8856_set_format()
2234 __v4l2_ctrl_s_ctrl(ov8856->vblank, vblank_def); in ov8856_set_format()
2235 h_blank = to_pixels_per_line(ov8856->priv_lane->link_freq_menu_items, in ov8856_set_format()
2238 ov8856->cur_mode->data_lanes) in ov8856_set_format()
2240 __v4l2_ctrl_modify_range(ov8856->hblank, h_blank, h_blank, 1, in ov8856_set_format()
2244 mutex_unlock(&ov8856->mutex); in ov8856_set_format()
2253 struct ov8856 *ov8856 = to_ov8856(sd); in ov8856_get_format() local
2255 mutex_lock(&ov8856->mutex); in ov8856_get_format()
2257 fmt->format = *v4l2_subdev_get_try_format(&ov8856->sd, in ov8856_get_format()
2261 ov8856_update_pad_format(ov8856, ov8856->cur_mode, &fmt->format); in ov8856_get_format()
2263 mutex_unlock(&ov8856->mutex); in ov8856_get_format()
2284 struct ov8856 *ov8856 = to_ov8856(sd); in ov8856_enum_frame_size() local
2287 if (fse->index >= ov8856->modes_size) in ov8856_enum_frame_size()
2296 fse->min_width = ov8856->priv_lane->supported_modes[fse->index].width; in ov8856_enum_frame_size()
2298 fse->min_height = ov8856->priv_lane->supported_modes[fse->index].height; in ov8856_enum_frame_size()
2306 struct ov8856 *ov8856 = to_ov8856(sd); in ov8856_open() local
2308 mutex_lock(&ov8856->mutex); in ov8856_open()
2309 ov8856_update_pad_format(ov8856, &ov8856->priv_lane->supported_modes[0], in ov8856_open()
2311 mutex_unlock(&ov8856->mutex); in ov8856_open()
2341 static int ov8856_get_hwcfg(struct ov8856 *ov8856, struct device *dev) in ov8856_get_hwcfg() argument
2360 ov8856->xvclk = devm_clk_get(dev, "xvclk"); in ov8856_get_hwcfg()
2361 if (IS_ERR(ov8856->xvclk)) { in ov8856_get_hwcfg()
2363 ov8856->xvclk); in ov8856_get_hwcfg()
2364 return PTR_ERR(ov8856->xvclk); in ov8856_get_hwcfg()
2367 clk_set_rate(ov8856->xvclk, xvclk_rate); in ov8856_get_hwcfg()
2368 xvclk_rate = clk_get_rate(ov8856->xvclk); in ov8856_get_hwcfg()
2370 ov8856->reset_gpio = devm_gpiod_get_optional(dev, "reset", in ov8856_get_hwcfg()
2372 if (IS_ERR(ov8856->reset_gpio)) in ov8856_get_hwcfg()
2373 return PTR_ERR(ov8856->reset_gpio); in ov8856_get_hwcfg()
2376 ov8856->supplies[i].supply = ov8856_supply_names[i]; in ov8856_get_hwcfg()
2380 ov8856->supplies); in ov8856_get_hwcfg()
2407 dev_dbg(dev, "Using %u data lanes\n", ov8856->cur_mode->data_lanes); in ov8856_get_hwcfg()
2410 ov8856->priv_lane = &lane_cfg_2; in ov8856_get_hwcfg()
2412 ov8856->priv_lane = &lane_cfg_4; in ov8856_get_hwcfg()
2414 ov8856->modes_size = ov8856_modes_num(ov8856); in ov8856_get_hwcfg()
2422 for (i = 0; i < ARRAY_SIZE(ov8856->priv_lane->link_freq_menu_items); i++) { in ov8856_get_hwcfg()
2424 if (ov8856->priv_lane->link_freq_menu_items[i] == in ov8856_get_hwcfg()
2431 ov8856->priv_lane->link_freq_menu_items[i]); in ov8856_get_hwcfg()
2446 struct ov8856 *ov8856 = to_ov8856(sd); in ov8856_remove() local
2452 mutex_destroy(&ov8856->mutex); in ov8856_remove()
2454 __ov8856_power_off(ov8856); in ov8856_remove()
2459 struct ov8856 *ov8856; in ov8856_probe() local
2463 ov8856 = devm_kzalloc(&client->dev, sizeof(*ov8856), GFP_KERNEL); in ov8856_probe()
2464 if (!ov8856) in ov8856_probe()
2467 ret = ov8856_get_hwcfg(ov8856, &client->dev); in ov8856_probe()
2474 v4l2_i2c_subdev_init(&ov8856->sd, client, &ov8856_subdev_ops); in ov8856_probe()
2478 ret = __ov8856_power_on(ov8856); in ov8856_probe()
2484 ret = ov8856_identify_module(ov8856); in ov8856_probe()
2491 mutex_init(&ov8856->mutex); in ov8856_probe()
2492 ov8856->cur_mode = &ov8856->priv_lane->supported_modes[0]; in ov8856_probe()
2493 ov8856->cur_mbus_index = ov8856->cur_mode->default_mbus_index; in ov8856_probe()
2494 ret = ov8856_init_controls(ov8856); in ov8856_probe()
2500 ov8856->sd.internal_ops = &ov8856_internal_ops; in ov8856_probe()
2501 ov8856->sd.flags |= V4L2_SUBDEV_FL_HAS_DEVNODE; in ov8856_probe()
2502 ov8856->sd.entity.ops = &ov8856_subdev_entity_ops; in ov8856_probe()
2503 ov8856->sd.entity.function = MEDIA_ENT_F_CAM_SENSOR; in ov8856_probe()
2504 ov8856->pad.flags = MEDIA_PAD_FL_SOURCE; in ov8856_probe()
2505 ret = media_entity_pads_init(&ov8856->sd.entity, 1, &ov8856->pad); in ov8856_probe()
2511 ret = v4l2_async_register_subdev_sensor(&ov8856->sd); in ov8856_probe()
2527 media_entity_cleanup(&ov8856->sd.entity); in ov8856_probe()
2530 v4l2_ctrl_handler_free(ov8856->sd.ctrl_handler); in ov8856_probe()
2531 mutex_destroy(&ov8856->mutex); in ov8856_probe()
2534 __ov8856_power_off(ov8856); in ov8856_probe()
2553 { .compatible = "ovti,ov8856" },
2560 .name = "ov8856",
2573 MODULE_DESCRIPTION("OmniVision OV8856 sensor driver");