Lines Matching refs:ov9282

169 struct ov9282 {  struct
442 static inline struct ov9282 *to_ov9282(struct v4l2_subdev *subdev) in to_ov9282()
444 return container_of(subdev, struct ov9282, sd); in to_ov9282()
456 static int ov9282_read_reg(struct ov9282 *ov9282, u16 reg, u32 len, u32 *val) in ov9282_read_reg() argument
458 struct i2c_client *client = v4l2_get_subdevdata(&ov9282->sd); in ov9282_read_reg()
499 static int ov9282_write_reg(struct ov9282 *ov9282, u16 reg, u32 len, u32 val) in ov9282_write_reg() argument
501 struct i2c_client *client = v4l2_get_subdevdata(&ov9282->sd); in ov9282_write_reg()
523 static int ov9282_write_regs(struct ov9282 *ov9282, in ov9282_write_regs() argument
530 ret = ov9282_write_reg(ov9282, regs[i].address, 1, regs[i].val); in ov9282_write_regs()
546 static int ov9282_update_controls(struct ov9282 *ov9282, in ov9282_update_controls() argument
554 ret = __v4l2_ctrl_s_ctrl(ov9282->link_freq_ctrl, mode->link_freq_idx); in ov9282_update_controls()
560 ret = __v4l2_ctrl_modify_range(ov9282->pixel_rate, pixel_rate, in ov9282_update_controls()
565 hblank_min = mode->hblank_min[ov9282->noncontinuous_clock ? 0 : 1]; in ov9282_update_controls()
566 ret = __v4l2_ctrl_modify_range(ov9282->hblank_ctrl, hblank_min, in ov9282_update_controls()
572 return __v4l2_ctrl_modify_range(ov9282->vblank_ctrl, mode->vblank_min, in ov9282_update_controls()
584 static int ov9282_update_exp_gain(struct ov9282 *ov9282, u32 exposure, u32 gain) in ov9282_update_exp_gain() argument
588 dev_dbg(ov9282->dev, "Set exp %u, analog gain %u", in ov9282_update_exp_gain()
591 ret = ov9282_write_reg(ov9282, OV9282_REG_HOLD, 1, 1); in ov9282_update_exp_gain()
595 ret = ov9282_write_reg(ov9282, OV9282_REG_EXPOSURE, 3, exposure << 4); in ov9282_update_exp_gain()
599 ret = ov9282_write_reg(ov9282, OV9282_REG_AGAIN, 1, gain); in ov9282_update_exp_gain()
602 ov9282_write_reg(ov9282, OV9282_REG_HOLD, 1, 0); in ov9282_update_exp_gain()
607 static int ov9282_set_ctrl_hflip(struct ov9282 *ov9282, int value) in ov9282_set_ctrl_hflip() argument
610 int ret = ov9282_read_reg(ov9282, OV9282_REG_TIMING_FORMAT_2, 1, in ov9282_set_ctrl_hflip()
620 return ov9282_write_reg(ov9282, OV9282_REG_TIMING_FORMAT_2, 1, in ov9282_set_ctrl_hflip()
624 static int ov9282_set_ctrl_vflip(struct ov9282 *ov9282, int value) in ov9282_set_ctrl_vflip() argument
627 int ret = ov9282_read_reg(ov9282, OV9282_REG_TIMING_FORMAT_1, 1, in ov9282_set_ctrl_vflip()
637 return ov9282_write_reg(ov9282, OV9282_REG_TIMING_FORMAT_1, 1, in ov9282_set_ctrl_vflip()
655 struct ov9282 *ov9282 = in ov9282_set_ctrl() local
656 container_of(ctrl->handler, struct ov9282, ctrl_handler); in ov9282_set_ctrl()
664 ov9282->vblank = ov9282->vblank_ctrl->val; in ov9282_set_ctrl()
666 dev_dbg(ov9282->dev, "Received vblank %u, new lpfr %u", in ov9282_set_ctrl()
667 ov9282->vblank, in ov9282_set_ctrl()
668 ov9282->vblank + ov9282->cur_mode->height); in ov9282_set_ctrl()
670 ret = __v4l2_ctrl_modify_range(ov9282->exp_ctrl, in ov9282_set_ctrl()
672 ov9282->vblank + in ov9282_set_ctrl()
673 ov9282->cur_mode->height - in ov9282_set_ctrl()
680 if (!pm_runtime_get_if_in_use(ov9282->dev)) in ov9282_set_ctrl()
686 analog_gain = ov9282->again_ctrl->val; in ov9282_set_ctrl()
688 dev_dbg(ov9282->dev, "Received exp %u, analog gain %u", in ov9282_set_ctrl()
691 ret = ov9282_update_exp_gain(ov9282, exposure, analog_gain); in ov9282_set_ctrl()
694 lpfr = ov9282->vblank + ov9282->cur_mode->height; in ov9282_set_ctrl()
695 ret = ov9282_write_reg(ov9282, OV9282_REG_LPFR, 2, lpfr); in ov9282_set_ctrl()
698 ret = ov9282_set_ctrl_hflip(ov9282, ctrl->val); in ov9282_set_ctrl()
701 ret = ov9282_set_ctrl_vflip(ov9282, ctrl->val); in ov9282_set_ctrl()
704 ret = ov9282_write_reg(ov9282, OV9282_REG_TIMING_HTS, 2, in ov9282_set_ctrl()
705 (ctrl->val + ov9282->cur_mode->width) >> 1); in ov9282_set_ctrl()
708 dev_err(ov9282->dev, "Invalid control %d", ctrl->id); in ov9282_set_ctrl()
712 pm_runtime_put(ov9282->dev); in ov9282_set_ctrl()
783 static void ov9282_fill_pad_format(struct ov9282 *ov9282, in ov9282_fill_pad_format() argument
810 struct ov9282 *ov9282 = to_ov9282(sd); in ov9282_get_pad_format() local
812 mutex_lock(&ov9282->mutex); in ov9282_get_pad_format()
820 ov9282_fill_pad_format(ov9282, ov9282->cur_mode, ov9282->code, in ov9282_get_pad_format()
824 mutex_unlock(&ov9282->mutex); in ov9282_get_pad_format()
841 struct ov9282 *ov9282 = to_ov9282(sd); in ov9282_set_pad_format() local
846 mutex_lock(&ov9282->mutex); in ov9282_set_pad_format()
858 ov9282_fill_pad_format(ov9282, mode, code, fmt); in ov9282_set_pad_format()
866 ret = ov9282_update_controls(ov9282, mode, fmt); in ov9282_set_pad_format()
868 ov9282->cur_mode = mode; in ov9282_set_pad_format()
869 ov9282->code = code; in ov9282_set_pad_format()
873 mutex_unlock(&ov9282->mutex); in ov9282_set_pad_format()
888 struct ov9282 *ov9282 = to_ov9282(sd); in ov9282_init_state() local
892 ov9282_fill_pad_format(ov9282, &supported_modes[DEFAULT_MODE], in ov9282_init_state()
893 ov9282->code, &fmt); in ov9282_init_state()
899 __ov9282_get_pad_crop(struct ov9282 *ov9282, in __ov9282_get_pad_crop() argument
907 return &ov9282->cur_mode->crop; in __ov9282_get_pad_crop()
919 struct ov9282 *ov9282 = to_ov9282(sd); in ov9282_get_selection() local
921 mutex_lock(&ov9282->mutex); in ov9282_get_selection()
922 sel->r = *__ov9282_get_pad_crop(ov9282, sd_state, sel->pad, in ov9282_get_selection()
924 mutex_unlock(&ov9282->mutex); in ov9282_get_selection()
956 static int ov9282_start_streaming(struct ov9282 *ov9282) in ov9282_start_streaming() argument
972 ret = ov9282_write_regs(ov9282, common_regs_list.regs, in ov9282_start_streaming()
975 dev_err(ov9282->dev, "fail to write common registers"); in ov9282_start_streaming()
979 bitdepth_index = ov9282->code == MEDIA_BUS_FMT_Y10_1X10 ? 0 : 1; in ov9282_start_streaming()
980 ret = ov9282_write_regs(ov9282, bitdepth_regs[bitdepth_index], 2); in ov9282_start_streaming()
982 dev_err(ov9282->dev, "fail to write bitdepth regs"); in ov9282_start_streaming()
987 reg_list = &ov9282->cur_mode->reg_list; in ov9282_start_streaming()
988 ret = ov9282_write_regs(ov9282, reg_list->regs, reg_list->num_of_regs); in ov9282_start_streaming()
990 dev_err(ov9282->dev, "fail to write initial registers"); in ov9282_start_streaming()
995 ret = __v4l2_ctrl_handler_setup(ov9282->sd.ctrl_handler); in ov9282_start_streaming()
997 dev_err(ov9282->dev, "fail to setup handler"); in ov9282_start_streaming()
1002 ret = ov9282_write_reg(ov9282, OV9282_REG_MODE_SELECT, in ov9282_start_streaming()
1005 dev_err(ov9282->dev, "fail to start streaming"); in ov9282_start_streaming()
1018 static int ov9282_stop_streaming(struct ov9282 *ov9282) in ov9282_stop_streaming() argument
1020 return ov9282_write_reg(ov9282, OV9282_REG_MODE_SELECT, in ov9282_stop_streaming()
1033 struct ov9282 *ov9282 = to_ov9282(sd); in ov9282_set_stream() local
1036 mutex_lock(&ov9282->mutex); in ov9282_set_stream()
1039 ret = pm_runtime_resume_and_get(ov9282->dev); in ov9282_set_stream()
1043 ret = ov9282_start_streaming(ov9282); in ov9282_set_stream()
1047 ov9282_stop_streaming(ov9282); in ov9282_set_stream()
1048 pm_runtime_put(ov9282->dev); in ov9282_set_stream()
1051 mutex_unlock(&ov9282->mutex); in ov9282_set_stream()
1056 pm_runtime_put(ov9282->dev); in ov9282_set_stream()
1058 mutex_unlock(&ov9282->mutex); in ov9282_set_stream()
1069 static int ov9282_detect(struct ov9282 *ov9282) in ov9282_detect() argument
1074 ret = ov9282_read_reg(ov9282, OV9282_REG_ID, 2, &val); in ov9282_detect()
1079 dev_err(ov9282->dev, "chip id mismatch: %x!=%x", in ov9282_detect()
1087 static int ov9282_configure_regulators(struct ov9282 *ov9282) in ov9282_configure_regulators() argument
1092 ov9282->supplies[i].supply = ov9282_supply_names[i]; in ov9282_configure_regulators()
1094 return devm_regulator_bulk_get(ov9282->dev, in ov9282_configure_regulators()
1096 ov9282->supplies); in ov9282_configure_regulators()
1105 static int ov9282_parse_hw_config(struct ov9282 *ov9282) in ov9282_parse_hw_config() argument
1107 struct fwnode_handle *fwnode = dev_fwnode(ov9282->dev); in ov9282_parse_hw_config()
1120 ov9282->reset_gpio = devm_gpiod_get_optional(ov9282->dev, "reset", in ov9282_parse_hw_config()
1122 if (IS_ERR(ov9282->reset_gpio)) { in ov9282_parse_hw_config()
1123 dev_err(ov9282->dev, "failed to get reset gpio %ld", in ov9282_parse_hw_config()
1124 PTR_ERR(ov9282->reset_gpio)); in ov9282_parse_hw_config()
1125 return PTR_ERR(ov9282->reset_gpio); in ov9282_parse_hw_config()
1129 ov9282->inclk = devm_clk_get(ov9282->dev, NULL); in ov9282_parse_hw_config()
1130 if (IS_ERR(ov9282->inclk)) { in ov9282_parse_hw_config()
1131 dev_err(ov9282->dev, "could not get inclk"); in ov9282_parse_hw_config()
1132 return PTR_ERR(ov9282->inclk); in ov9282_parse_hw_config()
1135 ret = ov9282_configure_regulators(ov9282); in ov9282_parse_hw_config()
1137 return dev_err_probe(ov9282->dev, ret, in ov9282_parse_hw_config()
1140 rate = clk_get_rate(ov9282->inclk); in ov9282_parse_hw_config()
1142 dev_err(ov9282->dev, "inclk frequency mismatch"); in ov9282_parse_hw_config()
1155 ov9282->noncontinuous_clock = in ov9282_parse_hw_config()
1159 dev_err(ov9282->dev, in ov9282_parse_hw_config()
1167 dev_err(ov9282->dev, "no link frequencies defined"); in ov9282_parse_hw_config()
1221 struct ov9282 *ov9282 = to_ov9282(sd); in ov9282_power_on() local
1224 ret = regulator_bulk_enable(OV9282_NUM_SUPPLIES, ov9282->supplies); in ov9282_power_on()
1232 gpiod_set_value_cansleep(ov9282->reset_gpio, 1); in ov9282_power_on()
1234 ret = clk_prepare_enable(ov9282->inclk); in ov9282_power_on()
1236 dev_err(ov9282->dev, "fail to enable inclk"); in ov9282_power_on()
1242 ret = ov9282_write_reg(ov9282, OV9282_REG_MIPI_CTRL00, 1, in ov9282_power_on()
1243 ov9282->noncontinuous_clock ? in ov9282_power_on()
1246 dev_err(ov9282->dev, "fail to write MIPI_CTRL00"); in ov9282_power_on()
1253 clk_disable_unprepare(ov9282->inclk); in ov9282_power_on()
1255 gpiod_set_value_cansleep(ov9282->reset_gpio, 0); in ov9282_power_on()
1257 regulator_bulk_disable(OV9282_NUM_SUPPLIES, ov9282->supplies); in ov9282_power_on()
1271 struct ov9282 *ov9282 = to_ov9282(sd); in ov9282_power_off() local
1273 gpiod_set_value_cansleep(ov9282->reset_gpio, 0); in ov9282_power_off()
1275 clk_disable_unprepare(ov9282->inclk); in ov9282_power_off()
1277 regulator_bulk_disable(OV9282_NUM_SUPPLIES, ov9282->supplies); in ov9282_power_off()
1288 static int ov9282_init_controls(struct ov9282 *ov9282) in ov9282_init_controls() argument
1290 struct v4l2_ctrl_handler *ctrl_hdlr = &ov9282->ctrl_handler; in ov9282_init_controls()
1291 const struct ov9282_mode *mode = ov9282->cur_mode; in ov9282_init_controls()
1302 ctrl_hdlr->lock = &ov9282->mutex; in ov9282_init_controls()
1306 ov9282->exp_ctrl = v4l2_ctrl_new_std(ctrl_hdlr, in ov9282_init_controls()
1314 ov9282->again_ctrl = v4l2_ctrl_new_std(ctrl_hdlr, in ov9282_init_controls()
1322 v4l2_ctrl_cluster(2, &ov9282->exp_ctrl); in ov9282_init_controls()
1324 ov9282->vblank_ctrl = v4l2_ctrl_new_std(ctrl_hdlr, in ov9282_init_controls()
1338 ov9282->pixel_rate = v4l2_ctrl_new_std(ctrl_hdlr, &ov9282_ctrl_ops, in ov9282_init_controls()
1344 ov9282->link_freq_ctrl = v4l2_ctrl_new_int_menu(ctrl_hdlr, in ov9282_init_controls()
1351 if (ov9282->link_freq_ctrl) in ov9282_init_controls()
1352 ov9282->link_freq_ctrl->flags |= V4L2_CTRL_FLAG_READ_ONLY; in ov9282_init_controls()
1354 hblank_min = mode->hblank_min[ov9282->noncontinuous_clock ? 0 : 1]; in ov9282_init_controls()
1355 ov9282->hblank_ctrl = v4l2_ctrl_new_std(ctrl_hdlr, in ov9282_init_controls()
1362 ret = v4l2_fwnode_device_parse(ov9282->dev, &props); in ov9282_init_controls()
1370 dev_err(ov9282->dev, "control init failed: %d", in ov9282_init_controls()
1376 ov9282->sd.ctrl_handler = ctrl_hdlr; in ov9282_init_controls()
1389 struct ov9282 *ov9282; in ov9282_probe() local
1392 ov9282 = devm_kzalloc(&client->dev, sizeof(*ov9282), GFP_KERNEL); in ov9282_probe()
1393 if (!ov9282) in ov9282_probe()
1396 ov9282->dev = &client->dev; in ov9282_probe()
1399 v4l2_i2c_subdev_init(&ov9282->sd, client, &ov9282_subdev_ops); in ov9282_probe()
1400 ov9282->sd.internal_ops = &ov9282_internal_ops; in ov9282_probe()
1401 v4l2_i2c_subdev_set_name(&ov9282->sd, client, in ov9282_probe()
1402 device_get_match_data(ov9282->dev), NULL); in ov9282_probe()
1404 ret = ov9282_parse_hw_config(ov9282); in ov9282_probe()
1406 dev_err(ov9282->dev, "HW configuration is not supported"); in ov9282_probe()
1410 mutex_init(&ov9282->mutex); in ov9282_probe()
1412 ret = ov9282_power_on(ov9282->dev); in ov9282_probe()
1414 dev_err(ov9282->dev, "failed to power-on the sensor"); in ov9282_probe()
1419 ret = ov9282_detect(ov9282); in ov9282_probe()
1421 dev_err(ov9282->dev, "failed to find sensor: %d", ret); in ov9282_probe()
1426 ov9282->cur_mode = &supported_modes[DEFAULT_MODE]; in ov9282_probe()
1427 ov9282->code = MEDIA_BUS_FMT_Y10_1X10; in ov9282_probe()
1428 ov9282->vblank = ov9282->cur_mode->vblank; in ov9282_probe()
1430 ret = ov9282_init_controls(ov9282); in ov9282_probe()
1432 dev_err(ov9282->dev, "failed to init controls: %d", ret); in ov9282_probe()
1437 ov9282->sd.flags |= V4L2_SUBDEV_FL_HAS_DEVNODE | in ov9282_probe()
1439 ov9282->sd.entity.function = MEDIA_ENT_F_CAM_SENSOR; in ov9282_probe()
1442 ov9282->pad.flags = MEDIA_PAD_FL_SOURCE; in ov9282_probe()
1443 ret = media_entity_pads_init(&ov9282->sd.entity, 1, &ov9282->pad); in ov9282_probe()
1445 dev_err(ov9282->dev, "failed to init entity pads: %d", ret); in ov9282_probe()
1449 ret = v4l2_async_register_subdev_sensor(&ov9282->sd); in ov9282_probe()
1451 dev_err(ov9282->dev, in ov9282_probe()
1456 pm_runtime_set_active(ov9282->dev); in ov9282_probe()
1457 pm_runtime_enable(ov9282->dev); in ov9282_probe()
1458 pm_runtime_idle(ov9282->dev); in ov9282_probe()
1463 media_entity_cleanup(&ov9282->sd.entity); in ov9282_probe()
1465 v4l2_ctrl_handler_free(ov9282->sd.ctrl_handler); in ov9282_probe()
1467 ov9282_power_off(ov9282->dev); in ov9282_probe()
1469 mutex_destroy(&ov9282->mutex); in ov9282_probe()
1483 struct ov9282 *ov9282 = to_ov9282(sd); in ov9282_remove() local
1494 mutex_destroy(&ov9282->mutex); in ov9282_remove()