Lines Matching defs:ov8856

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