Lines Matching full:ov8856
81 #define to_ov8856(_sd) container_of(_sd, struct ov8856, sd)
1016 struct ov8856 { struct
1060 static int ov8856_read_reg(struct ov8856 *ov8856, u16 reg, u16 len, u32 *val) in ov8856_read_reg() argument
1062 struct i2c_client *client = v4l2_get_subdevdata(&ov8856->sd); in ov8856_read_reg()
1090 static int ov8856_write_reg(struct ov8856 *ov8856, u16 reg, u16 len, u32 val) in ov8856_write_reg() argument
1092 struct i2c_client *client = v4l2_get_subdevdata(&ov8856->sd); in ov8856_write_reg()
1106 static int ov8856_write_reg_list(struct ov8856 *ov8856, in ov8856_write_reg_list() argument
1109 struct i2c_client *client = v4l2_get_subdevdata(&ov8856->sd); in ov8856_write_reg_list()
1114 ret = ov8856_write_reg(ov8856, r_list->regs[i].address, 1, in ov8856_write_reg_list()
1127 static int ov8856_update_digital_gain(struct ov8856 *ov8856, u32 d_gain) in ov8856_update_digital_gain() argument
1131 ret = ov8856_write_reg(ov8856, OV8856_REG_MWB_R_GAIN, in ov8856_update_digital_gain()
1136 ret = ov8856_write_reg(ov8856, OV8856_REG_MWB_G_GAIN, in ov8856_update_digital_gain()
1141 return ov8856_write_reg(ov8856, OV8856_REG_MWB_B_GAIN, in ov8856_update_digital_gain()
1145 static int ov8856_test_pattern(struct ov8856 *ov8856, u32 pattern) in ov8856_test_pattern() argument
1151 return ov8856_write_reg(ov8856, OV8856_REG_TEST_PATTERN, in ov8856_test_pattern()
1157 struct ov8856 *ov8856 = container_of(ctrl->handler, in ov8856_set_ctrl() local
1158 struct ov8856, ctrl_handler); in ov8856_set_ctrl()
1159 struct i2c_client *client = v4l2_get_subdevdata(&ov8856->sd); in ov8856_set_ctrl()
1166 exposure_max = ov8856->cur_mode->height + ctrl->val - in ov8856_set_ctrl()
1168 __v4l2_ctrl_modify_range(ov8856->exposure, in ov8856_set_ctrl()
1169 ov8856->exposure->minimum, in ov8856_set_ctrl()
1170 exposure_max, ov8856->exposure->step, in ov8856_set_ctrl()
1180 ret = ov8856_write_reg(ov8856, OV8856_REG_ANALOG_GAIN, in ov8856_set_ctrl()
1185 ret = ov8856_update_digital_gain(ov8856, ctrl->val); in ov8856_set_ctrl()
1190 ret = ov8856_write_reg(ov8856, OV8856_REG_EXPOSURE, in ov8856_set_ctrl()
1195 ret = ov8856_write_reg(ov8856, OV8856_REG_VTS, in ov8856_set_ctrl()
1197 ov8856->cur_mode->height + ctrl->val); in ov8856_set_ctrl()
1201 ret = ov8856_test_pattern(ov8856, ctrl->val); in ov8856_set_ctrl()
1218 static int ov8856_init_controls(struct ov8856 *ov8856) in ov8856_init_controls() argument
1224 ctrl_hdlr = &ov8856->ctrl_handler; in ov8856_init_controls()
1229 ctrl_hdlr->lock = &ov8856->mutex; in ov8856_init_controls()
1230 ov8856->link_freq = v4l2_ctrl_new_int_menu(ctrl_hdlr, &ov8856_ctrl_ops, in ov8856_init_controls()
1234 if (ov8856->link_freq) in ov8856_init_controls()
1235 ov8856->link_freq->flags |= V4L2_CTRL_FLAG_READ_ONLY; in ov8856_init_controls()
1237 ov8856->pixel_rate = v4l2_ctrl_new_std(ctrl_hdlr, &ov8856_ctrl_ops, in ov8856_init_controls()
1242 ov8856->vblank = v4l2_ctrl_new_std(ctrl_hdlr, &ov8856_ctrl_ops, in ov8856_init_controls()
1244 ov8856->cur_mode->vts_min - ov8856->cur_mode->height, in ov8856_init_controls()
1245 OV8856_VTS_MAX - ov8856->cur_mode->height, 1, in ov8856_init_controls()
1246 ov8856->cur_mode->vts_def - ov8856->cur_mode->height); in ov8856_init_controls()
1247 h_blank = to_pixels_per_line(ov8856->cur_mode->hts, in ov8856_init_controls()
1248 ov8856->cur_mode->link_freq_index) - ov8856->cur_mode->width; in ov8856_init_controls()
1249 ov8856->hblank = v4l2_ctrl_new_std(ctrl_hdlr, &ov8856_ctrl_ops, in ov8856_init_controls()
1252 if (ov8856->hblank) in ov8856_init_controls()
1253 ov8856->hblank->flags |= V4L2_CTRL_FLAG_READ_ONLY; in ov8856_init_controls()
1261 exposure_max = ov8856->cur_mode->vts_def - OV8856_EXPOSURE_MAX_MARGIN; in ov8856_init_controls()
1262 ov8856->exposure = v4l2_ctrl_new_std(ctrl_hdlr, &ov8856_ctrl_ops, in ov8856_init_controls()
1274 ov8856->sd.ctrl_handler = ctrl_hdlr; in ov8856_init_controls()
1288 static int ov8856_start_streaming(struct ov8856 *ov8856) in ov8856_start_streaming() argument
1290 struct i2c_client *client = v4l2_get_subdevdata(&ov8856->sd); in ov8856_start_streaming()
1294 link_freq_index = ov8856->cur_mode->link_freq_index; in ov8856_start_streaming()
1296 ret = ov8856_write_reg_list(ov8856, reg_list); in ov8856_start_streaming()
1302 reg_list = &ov8856->cur_mode->reg_list; in ov8856_start_streaming()
1303 ret = ov8856_write_reg_list(ov8856, reg_list); in ov8856_start_streaming()
1309 ret = __v4l2_ctrl_handler_setup(ov8856->sd.ctrl_handler); in ov8856_start_streaming()
1313 ret = ov8856_write_reg(ov8856, OV8856_REG_MODE_SELECT, in ov8856_start_streaming()
1323 static void ov8856_stop_streaming(struct ov8856 *ov8856) in ov8856_stop_streaming() argument
1325 struct i2c_client *client = v4l2_get_subdevdata(&ov8856->sd); in ov8856_stop_streaming()
1327 if (ov8856_write_reg(ov8856, OV8856_REG_MODE_SELECT, in ov8856_stop_streaming()
1334 struct ov8856 *ov8856 = to_ov8856(sd); in ov8856_set_stream() local
1338 if (ov8856->streaming == enable) in ov8856_set_stream()
1341 mutex_lock(&ov8856->mutex); in ov8856_set_stream()
1346 mutex_unlock(&ov8856->mutex); in ov8856_set_stream()
1350 ret = ov8856_start_streaming(ov8856); in ov8856_set_stream()
1353 ov8856_stop_streaming(ov8856); in ov8856_set_stream()
1357 ov8856_stop_streaming(ov8856); in ov8856_set_stream()
1361 ov8856->streaming = enable; in ov8856_set_stream()
1362 mutex_unlock(&ov8856->mutex); in ov8856_set_stream()
1367 static int __ov8856_power_on(struct ov8856 *ov8856) in __ov8856_power_on() argument
1369 struct i2c_client *client = v4l2_get_subdevdata(&ov8856->sd); in __ov8856_power_on()
1375 ret = clk_prepare_enable(ov8856->xvclk); in __ov8856_power_on()
1381 if (ov8856->reset_gpio) { in __ov8856_power_on()
1382 gpiod_set_value_cansleep(ov8856->reset_gpio, 1); in __ov8856_power_on()
1387 ov8856->supplies); in __ov8856_power_on()
1393 gpiod_set_value_cansleep(ov8856->reset_gpio, 0); in __ov8856_power_on()
1399 gpiod_set_value_cansleep(ov8856->reset_gpio, 1); in __ov8856_power_on()
1400 clk_disable_unprepare(ov8856->xvclk); in __ov8856_power_on()
1405 static void __ov8856_power_off(struct ov8856 *ov8856) in __ov8856_power_off() argument
1407 struct i2c_client *client = v4l2_get_subdevdata(&ov8856->sd); in __ov8856_power_off()
1412 gpiod_set_value_cansleep(ov8856->reset_gpio, 1); in __ov8856_power_off()
1414 ov8856->supplies); in __ov8856_power_off()
1415 clk_disable_unprepare(ov8856->xvclk); in __ov8856_power_off()
1422 struct ov8856 *ov8856 = to_ov8856(sd); in ov8856_suspend() local
1424 mutex_lock(&ov8856->mutex); in ov8856_suspend()
1425 if (ov8856->streaming) in ov8856_suspend()
1426 ov8856_stop_streaming(ov8856); in ov8856_suspend()
1428 __ov8856_power_off(ov8856); in ov8856_suspend()
1429 mutex_unlock(&ov8856->mutex); in ov8856_suspend()
1438 struct ov8856 *ov8856 = to_ov8856(sd); in ov8856_resume() local
1441 mutex_lock(&ov8856->mutex); in ov8856_resume()
1443 __ov8856_power_on(ov8856); in ov8856_resume()
1444 if (ov8856->streaming) { in ov8856_resume()
1445 ret = ov8856_start_streaming(ov8856); in ov8856_resume()
1447 ov8856->streaming = false; in ov8856_resume()
1448 ov8856_stop_streaming(ov8856); in ov8856_resume()
1449 mutex_unlock(&ov8856->mutex); in ov8856_resume()
1454 mutex_unlock(&ov8856->mutex); in ov8856_resume()
1463 struct ov8856 *ov8856 = to_ov8856(sd); in ov8856_set_format() local
1472 mutex_lock(&ov8856->mutex); in ov8856_set_format()
1477 ov8856->cur_mode = mode; in ov8856_set_format()
1478 __v4l2_ctrl_s_ctrl(ov8856->link_freq, mode->link_freq_index); in ov8856_set_format()
1479 __v4l2_ctrl_s_ctrl_int64(ov8856->pixel_rate, in ov8856_set_format()
1484 __v4l2_ctrl_modify_range(ov8856->vblank, in ov8856_set_format()
1488 __v4l2_ctrl_s_ctrl(ov8856->vblank, vblank_def); in ov8856_set_format()
1491 __v4l2_ctrl_modify_range(ov8856->hblank, h_blank, h_blank, 1, in ov8856_set_format()
1495 mutex_unlock(&ov8856->mutex); in ov8856_set_format()
1504 struct ov8856 *ov8856 = to_ov8856(sd); in ov8856_get_format() local
1506 mutex_lock(&ov8856->mutex); in ov8856_get_format()
1508 fmt->format = *v4l2_subdev_get_try_format(&ov8856->sd, cfg, in ov8856_get_format()
1511 ov8856_update_pad_format(ov8856->cur_mode, &fmt->format); in ov8856_get_format()
1513 mutex_unlock(&ov8856->mutex); in ov8856_get_format()
1551 struct ov8856 *ov8856 = to_ov8856(sd); in ov8856_open() local
1553 mutex_lock(&ov8856->mutex); in ov8856_open()
1556 mutex_unlock(&ov8856->mutex); in ov8856_open()
1585 static int ov8856_identify_module(struct ov8856 *ov8856) in ov8856_identify_module() argument
1587 struct i2c_client *client = v4l2_get_subdevdata(&ov8856->sd); in ov8856_identify_module()
1591 ret = ov8856_read_reg(ov8856, OV8856_REG_CHIP_ID, in ov8856_identify_module()
1602 ret = ov8856_write_reg(ov8856, OV8856_REG_MODE_SELECT, in ov8856_identify_module()
1607 ret = ov8856_write_reg(ov8856, OV8856_OTP_MODE_CTRL, in ov8856_identify_module()
1614 ret = ov8856_write_reg(ov8856, OV8856_OTP_LOAD_CTRL, in ov8856_identify_module()
1622 ret = ov8856_read_reg(ov8856, OV8856_MODULE_REVISION, in ov8856_identify_module()
1629 dev_info(&client->dev, "OV8856 revision %x (%s) at address 0x%02x\n", in ov8856_identify_module()
1635 ret = ov8856_write_reg(ov8856, OV8856_REG_MODE_SELECT, in ov8856_identify_module()
1645 static int ov8856_get_hwcfg(struct ov8856 *ov8856, struct device *dev) in ov8856_get_hwcfg() argument
1664 ov8856->xvclk = devm_clk_get(dev, "xvclk"); in ov8856_get_hwcfg()
1665 if (IS_ERR(ov8856->xvclk)) { in ov8856_get_hwcfg()
1667 ov8856->xvclk); in ov8856_get_hwcfg()
1668 return PTR_ERR(ov8856->xvclk); in ov8856_get_hwcfg()
1671 clk_set_rate(ov8856->xvclk, xvclk_rate); in ov8856_get_hwcfg()
1672 xvclk_rate = clk_get_rate(ov8856->xvclk); in ov8856_get_hwcfg()
1679 ov8856->reset_gpio = devm_gpiod_get_optional(dev, "reset", in ov8856_get_hwcfg()
1681 if (IS_ERR(ov8856->reset_gpio)) in ov8856_get_hwcfg()
1682 return PTR_ERR(ov8856->reset_gpio); in ov8856_get_hwcfg()
1685 ov8856->supplies[i].supply = ov8856_supply_names[i]; in ov8856_get_hwcfg()
1688 ov8856->supplies); in ov8856_get_hwcfg()
1738 struct ov8856 *ov8856 = to_ov8856(sd); in ov8856_remove() local
1744 mutex_destroy(&ov8856->mutex); in ov8856_remove()
1746 __ov8856_power_off(ov8856); in ov8856_remove()
1753 struct ov8856 *ov8856; in ov8856_probe() local
1756 ov8856 = devm_kzalloc(&client->dev, sizeof(*ov8856), GFP_KERNEL); in ov8856_probe()
1757 if (!ov8856) in ov8856_probe()
1760 ret = ov8856_get_hwcfg(ov8856, &client->dev); in ov8856_probe()
1767 v4l2_i2c_subdev_init(&ov8856->sd, client, &ov8856_subdev_ops); in ov8856_probe()
1769 ret = __ov8856_power_on(ov8856); in ov8856_probe()
1775 ret = ov8856_identify_module(ov8856); in ov8856_probe()
1781 mutex_init(&ov8856->mutex); in ov8856_probe()
1782 ov8856->cur_mode = &supported_modes[0]; in ov8856_probe()
1783 ret = ov8856_init_controls(ov8856); in ov8856_probe()
1789 ov8856->sd.internal_ops = &ov8856_internal_ops; in ov8856_probe()
1790 ov8856->sd.flags |= V4L2_SUBDEV_FL_HAS_DEVNODE; in ov8856_probe()
1791 ov8856->sd.entity.ops = &ov8856_subdev_entity_ops; in ov8856_probe()
1792 ov8856->sd.entity.function = MEDIA_ENT_F_CAM_SENSOR; in ov8856_probe()
1793 ov8856->pad.flags = MEDIA_PAD_FL_SOURCE; in ov8856_probe()
1794 ret = media_entity_pads_init(&ov8856->sd.entity, 1, &ov8856->pad); in ov8856_probe()
1800 ret = v4l2_async_register_subdev_sensor_common(&ov8856->sd); in ov8856_probe()
1818 media_entity_cleanup(&ov8856->sd.entity); in ov8856_probe()
1821 v4l2_ctrl_handler_free(ov8856->sd.ctrl_handler); in ov8856_probe()
1822 mutex_destroy(&ov8856->mutex); in ov8856_probe()
1825 __ov8856_power_off(ov8856); in ov8856_probe()
1844 { .compatible = "ovti,ov8856" },
1851 .name = "ov8856",
1863 MODULE_DESCRIPTION("OmniVision OV8856 sensor driver");