Lines Matching full:ov9282
3 * OmniVision ov9282 Camera Sensor Driver
82 * OV9282 native and active pixel array size.
104 * struct ov9282_reg - ov9282 sensor register
114 * struct ov9282_reg_list - ov9282 sensor register list
124 * struct ov9282_mode - ov9282 sensor mode structure
149 * struct ov9282 - ov9282 sensor device structure
170 struct ov9282 { struct
439 * to_ov9282() - ov9282 V4L2 sub-device to ov9282 device.
440 * @subdev: pointer to ov9282 V4L2 sub-device
442 * Return: pointer to ov9282 device
444 static inline struct ov9282 *to_ov9282(struct v4l2_subdev *subdev) in to_ov9282()
446 return container_of(subdev, struct ov9282, sd); in to_ov9282()
451 * @ov9282: pointer to ov9282 device
458 static int ov9282_read_reg(struct ov9282 *ov9282, u16 reg, u32 len, u32 *val) in ov9282_read_reg() argument
460 struct i2c_client *client = v4l2_get_subdevdata(&ov9282->sd); in ov9282_read_reg()
494 * @ov9282: pointer to ov9282 device
501 static int ov9282_write_reg(struct ov9282 *ov9282, u16 reg, u32 len, u32 val) in ov9282_write_reg() argument
503 struct i2c_client *client = v4l2_get_subdevdata(&ov9282->sd); in ov9282_write_reg()
519 * @ov9282: pointer to ov9282 device
525 static int ov9282_write_regs(struct ov9282 *ov9282, in ov9282_write_regs() argument
532 ret = ov9282_write_reg(ov9282, regs[i].address, 1, regs[i].val); in ov9282_write_regs()
542 * @ov9282: pointer to ov9282 device
548 static int ov9282_update_controls(struct ov9282 *ov9282, in ov9282_update_controls() argument
556 ret = __v4l2_ctrl_s_ctrl(ov9282->link_freq_ctrl, mode->link_freq_idx); in ov9282_update_controls()
562 ret = __v4l2_ctrl_modify_range(ov9282->pixel_rate, pixel_rate, in ov9282_update_controls()
567 hblank_min = mode->hblank_min[ov9282->noncontinuous_clock ? 0 : 1]; in ov9282_update_controls()
568 ret = __v4l2_ctrl_modify_range(ov9282->hblank_ctrl, hblank_min, in ov9282_update_controls()
574 return __v4l2_ctrl_modify_range(ov9282->vblank_ctrl, mode->vblank_min, in ov9282_update_controls()
580 * @ov9282: pointer to ov9282 device
586 static int ov9282_update_exp_gain(struct ov9282 *ov9282, u32 exposure, u32 gain) in ov9282_update_exp_gain() argument
590 dev_dbg(ov9282->dev, "Set exp %u, analog gain %u", in ov9282_update_exp_gain()
593 ret = ov9282_write_reg(ov9282, OV9282_REG_HOLD, 1, 1); in ov9282_update_exp_gain()
597 ret = ov9282_write_reg(ov9282, OV9282_REG_EXPOSURE, 3, exposure << 4); in ov9282_update_exp_gain()
601 ret = ov9282_write_reg(ov9282, OV9282_REG_AGAIN, 1, gain); in ov9282_update_exp_gain()
604 ov9282_write_reg(ov9282, OV9282_REG_HOLD, 1, 0); in ov9282_update_exp_gain()
609 static int ov9282_set_ctrl_hflip(struct ov9282 *ov9282, int value) in ov9282_set_ctrl_hflip() argument
612 int ret = ov9282_read_reg(ov9282, OV9282_REG_TIMING_FORMAT_2, 1, in ov9282_set_ctrl_hflip()
622 return ov9282_write_reg(ov9282, OV9282_REG_TIMING_FORMAT_2, 1, in ov9282_set_ctrl_hflip()
626 static int ov9282_set_ctrl_vflip(struct ov9282 *ov9282, int value) in ov9282_set_ctrl_vflip() argument
629 int ret = ov9282_read_reg(ov9282, OV9282_REG_TIMING_FORMAT_1, 1, in ov9282_set_ctrl_vflip()
639 return ov9282_write_reg(ov9282, OV9282_REG_TIMING_FORMAT_1, 1, in ov9282_set_ctrl_vflip()
657 struct ov9282 *ov9282 = in ov9282_set_ctrl() local
658 container_of(ctrl->handler, struct ov9282, ctrl_handler); in ov9282_set_ctrl()
666 ov9282->vblank = ov9282->vblank_ctrl->val; in ov9282_set_ctrl()
668 dev_dbg(ov9282->dev, "Received vblank %u, new lpfr %u", in ov9282_set_ctrl()
669 ov9282->vblank, in ov9282_set_ctrl()
670 ov9282->vblank + ov9282->cur_mode->height); in ov9282_set_ctrl()
672 ret = __v4l2_ctrl_modify_range(ov9282->exp_ctrl, in ov9282_set_ctrl()
674 ov9282->vblank + in ov9282_set_ctrl()
675 ov9282->cur_mode->height - in ov9282_set_ctrl()
682 if (!pm_runtime_get_if_in_use(ov9282->dev)) in ov9282_set_ctrl()
688 analog_gain = ov9282->again_ctrl->val; in ov9282_set_ctrl()
690 dev_dbg(ov9282->dev, "Received exp %u, analog gain %u", in ov9282_set_ctrl()
693 ret = ov9282_update_exp_gain(ov9282, exposure, analog_gain); in ov9282_set_ctrl()
696 lpfr = ov9282->vblank + ov9282->cur_mode->height; in ov9282_set_ctrl()
697 ret = ov9282_write_reg(ov9282, OV9282_REG_LPFR, 2, lpfr); in ov9282_set_ctrl()
700 ret = ov9282_set_ctrl_hflip(ov9282, ctrl->val); in ov9282_set_ctrl()
703 ret = ov9282_set_ctrl_vflip(ov9282, ctrl->val); in ov9282_set_ctrl()
706 ret = ov9282_write_reg(ov9282, OV9282_REG_TIMING_HTS, 2, in ov9282_set_ctrl()
707 (ctrl->val + ov9282->cur_mode->width) >> 1); in ov9282_set_ctrl()
710 dev_err(ov9282->dev, "Invalid control %d", ctrl->id); in ov9282_set_ctrl()
714 pm_runtime_put(ov9282->dev); in ov9282_set_ctrl()
726 * @sd: pointer to ov9282 V4L2 sub-device structure
752 * @sd: pointer to ov9282 V4L2 sub-device structure
780 * @ov9282: pointer to ov9282 device
785 static void ov9282_fill_pad_format(struct ov9282 *ov9282, in ov9282_fill_pad_format() argument
802 * @sd: pointer to ov9282 V4L2 sub-device structure
812 struct ov9282 *ov9282 = to_ov9282(sd); in ov9282_get_pad_format() local
814 mutex_lock(&ov9282->mutex); in ov9282_get_pad_format()
822 ov9282_fill_pad_format(ov9282, ov9282->cur_mode, ov9282->code, in ov9282_get_pad_format()
826 mutex_unlock(&ov9282->mutex); in ov9282_get_pad_format()
833 * @sd: pointer to ov9282 V4L2 sub-device structure
843 struct ov9282 *ov9282 = to_ov9282(sd); in ov9282_set_pad_format() local
848 mutex_lock(&ov9282->mutex); in ov9282_set_pad_format()
860 ov9282_fill_pad_format(ov9282, mode, code, fmt); in ov9282_set_pad_format()
868 ret = ov9282_update_controls(ov9282, mode, fmt); in ov9282_set_pad_format()
870 ov9282->cur_mode = mode; in ov9282_set_pad_format()
871 ov9282->code = code; in ov9282_set_pad_format()
875 mutex_unlock(&ov9282->mutex); in ov9282_set_pad_format()
882 * @sd: pointer to ov9282 V4L2 sub-device structure
890 struct ov9282 *ov9282 = to_ov9282(sd); in ov9282_init_pad_cfg() local
894 ov9282_fill_pad_format(ov9282, &supported_modes[DEFAULT_MODE], in ov9282_init_pad_cfg()
895 ov9282->code, &fmt); in ov9282_init_pad_cfg()
901 __ov9282_get_pad_crop(struct ov9282 *ov9282, in __ov9282_get_pad_crop() argument
907 return v4l2_subdev_get_try_crop(&ov9282->sd, sd_state, pad); in __ov9282_get_pad_crop()
909 return &ov9282->cur_mode->crop; in __ov9282_get_pad_crop()
921 struct ov9282 *ov9282 = to_ov9282(sd); in ov9282_get_selection() local
923 mutex_lock(&ov9282->mutex); in ov9282_get_selection()
924 sel->r = *__ov9282_get_pad_crop(ov9282, sd_state, sel->pad, in ov9282_get_selection()
926 mutex_unlock(&ov9282->mutex); in ov9282_get_selection()
954 * @ov9282: pointer to ov9282 device
958 static int ov9282_start_streaming(struct ov9282 *ov9282) in ov9282_start_streaming() argument
974 ret = ov9282_write_regs(ov9282, common_regs_list.regs, in ov9282_start_streaming()
977 dev_err(ov9282->dev, "fail to write common registers"); in ov9282_start_streaming()
981 bitdepth_index = ov9282->code == MEDIA_BUS_FMT_Y10_1X10 ? 0 : 1; in ov9282_start_streaming()
982 ret = ov9282_write_regs(ov9282, bitdepth_regs[bitdepth_index], 2); in ov9282_start_streaming()
984 dev_err(ov9282->dev, "fail to write bitdepth regs"); in ov9282_start_streaming()
989 reg_list = &ov9282->cur_mode->reg_list; in ov9282_start_streaming()
990 ret = ov9282_write_regs(ov9282, reg_list->regs, reg_list->num_of_regs); in ov9282_start_streaming()
992 dev_err(ov9282->dev, "fail to write initial registers"); in ov9282_start_streaming()
997 ret = __v4l2_ctrl_handler_setup(ov9282->sd.ctrl_handler); in ov9282_start_streaming()
999 dev_err(ov9282->dev, "fail to setup handler"); in ov9282_start_streaming()
1004 ret = ov9282_write_reg(ov9282, OV9282_REG_MODE_SELECT, in ov9282_start_streaming()
1007 dev_err(ov9282->dev, "fail to start streaming"); in ov9282_start_streaming()
1016 * @ov9282: pointer to ov9282 device
1020 static int ov9282_stop_streaming(struct ov9282 *ov9282) in ov9282_stop_streaming() argument
1022 return ov9282_write_reg(ov9282, OV9282_REG_MODE_SELECT, in ov9282_stop_streaming()
1028 * @sd: pointer to ov9282 subdevice
1035 struct ov9282 *ov9282 = to_ov9282(sd); in ov9282_set_stream() local
1038 mutex_lock(&ov9282->mutex); in ov9282_set_stream()
1040 if (ov9282->streaming == enable) { in ov9282_set_stream()
1041 mutex_unlock(&ov9282->mutex); in ov9282_set_stream()
1046 ret = pm_runtime_resume_and_get(ov9282->dev); in ov9282_set_stream()
1050 ret = ov9282_start_streaming(ov9282); in ov9282_set_stream()
1054 ov9282_stop_streaming(ov9282); in ov9282_set_stream()
1055 pm_runtime_put(ov9282->dev); in ov9282_set_stream()
1058 ov9282->streaming = enable; in ov9282_set_stream()
1060 mutex_unlock(&ov9282->mutex); in ov9282_set_stream()
1065 pm_runtime_put(ov9282->dev); in ov9282_set_stream()
1067 mutex_unlock(&ov9282->mutex); in ov9282_set_stream()
1073 * ov9282_detect() - Detect ov9282 sensor
1074 * @ov9282: pointer to ov9282 device
1078 static int ov9282_detect(struct ov9282 *ov9282) in ov9282_detect() argument
1083 ret = ov9282_read_reg(ov9282, OV9282_REG_ID, 2, &val); in ov9282_detect()
1088 dev_err(ov9282->dev, "chip id mismatch: %x!=%x", in ov9282_detect()
1096 static int ov9282_configure_regulators(struct ov9282 *ov9282) in ov9282_configure_regulators() argument
1101 ov9282->supplies[i].supply = ov9282_supply_names[i]; in ov9282_configure_regulators()
1103 return devm_regulator_bulk_get(ov9282->dev, in ov9282_configure_regulators()
1105 ov9282->supplies); in ov9282_configure_regulators()
1110 * @ov9282: pointer to ov9282 device
1114 static int ov9282_parse_hw_config(struct ov9282 *ov9282) in ov9282_parse_hw_config() argument
1116 struct fwnode_handle *fwnode = dev_fwnode(ov9282->dev); in ov9282_parse_hw_config()
1129 ov9282->reset_gpio = devm_gpiod_get_optional(ov9282->dev, "reset", in ov9282_parse_hw_config()
1131 if (IS_ERR(ov9282->reset_gpio)) { in ov9282_parse_hw_config()
1132 dev_err(ov9282->dev, "failed to get reset gpio %ld", in ov9282_parse_hw_config()
1133 PTR_ERR(ov9282->reset_gpio)); in ov9282_parse_hw_config()
1134 return PTR_ERR(ov9282->reset_gpio); in ov9282_parse_hw_config()
1138 ov9282->inclk = devm_clk_get(ov9282->dev, NULL); in ov9282_parse_hw_config()
1139 if (IS_ERR(ov9282->inclk)) { in ov9282_parse_hw_config()
1140 dev_err(ov9282->dev, "could not get inclk"); in ov9282_parse_hw_config()
1141 return PTR_ERR(ov9282->inclk); in ov9282_parse_hw_config()
1144 ret = ov9282_configure_regulators(ov9282); in ov9282_parse_hw_config()
1146 return dev_err_probe(ov9282->dev, ret, in ov9282_parse_hw_config()
1149 rate = clk_get_rate(ov9282->inclk); in ov9282_parse_hw_config()
1151 dev_err(ov9282->dev, "inclk frequency mismatch"); in ov9282_parse_hw_config()
1164 ov9282->noncontinuous_clock = in ov9282_parse_hw_config()
1168 dev_err(ov9282->dev, in ov9282_parse_hw_config()
1176 dev_err(ov9282->dev, "no link frequencies defined"); in ov9282_parse_hw_config()
1227 struct ov9282 *ov9282 = to_ov9282(sd); in ov9282_power_on() local
1230 ret = regulator_bulk_enable(OV9282_NUM_SUPPLIES, ov9282->supplies); in ov9282_power_on()
1238 gpiod_set_value_cansleep(ov9282->reset_gpio, 1); in ov9282_power_on()
1240 ret = clk_prepare_enable(ov9282->inclk); in ov9282_power_on()
1242 dev_err(ov9282->dev, "fail to enable inclk"); in ov9282_power_on()
1248 ret = ov9282_write_reg(ov9282, OV9282_REG_MIPI_CTRL00, 1, in ov9282_power_on()
1249 ov9282->noncontinuous_clock ? in ov9282_power_on()
1252 dev_err(ov9282->dev, "fail to write MIPI_CTRL00"); in ov9282_power_on()
1259 clk_disable_unprepare(ov9282->inclk); in ov9282_power_on()
1261 gpiod_set_value_cansleep(ov9282->reset_gpio, 0); in ov9282_power_on()
1263 regulator_bulk_disable(OV9282_NUM_SUPPLIES, ov9282->supplies); in ov9282_power_on()
1277 struct ov9282 *ov9282 = to_ov9282(sd); in ov9282_power_off() local
1279 gpiod_set_value_cansleep(ov9282->reset_gpio, 0); in ov9282_power_off()
1281 clk_disable_unprepare(ov9282->inclk); in ov9282_power_off()
1283 regulator_bulk_disable(OV9282_NUM_SUPPLIES, ov9282->supplies); in ov9282_power_off()
1290 * @ov9282: pointer to ov9282 device
1294 static int ov9282_init_controls(struct ov9282 *ov9282) in ov9282_init_controls() argument
1296 struct v4l2_ctrl_handler *ctrl_hdlr = &ov9282->ctrl_handler; in ov9282_init_controls()
1297 const struct ov9282_mode *mode = ov9282->cur_mode; in ov9282_init_controls()
1308 ctrl_hdlr->lock = &ov9282->mutex; in ov9282_init_controls()
1312 ov9282->exp_ctrl = v4l2_ctrl_new_std(ctrl_hdlr, in ov9282_init_controls()
1320 ov9282->again_ctrl = v4l2_ctrl_new_std(ctrl_hdlr, in ov9282_init_controls()
1328 v4l2_ctrl_cluster(2, &ov9282->exp_ctrl); in ov9282_init_controls()
1330 ov9282->vblank_ctrl = v4l2_ctrl_new_std(ctrl_hdlr, in ov9282_init_controls()
1344 ov9282->pixel_rate = v4l2_ctrl_new_std(ctrl_hdlr, &ov9282_ctrl_ops, in ov9282_init_controls()
1350 ov9282->link_freq_ctrl = v4l2_ctrl_new_int_menu(ctrl_hdlr, in ov9282_init_controls()
1357 if (ov9282->link_freq_ctrl) in ov9282_init_controls()
1358 ov9282->link_freq_ctrl->flags |= V4L2_CTRL_FLAG_READ_ONLY; in ov9282_init_controls()
1360 hblank_min = mode->hblank_min[ov9282->noncontinuous_clock ? 0 : 1]; in ov9282_init_controls()
1361 ov9282->hblank_ctrl = v4l2_ctrl_new_std(ctrl_hdlr, in ov9282_init_controls()
1368 ret = v4l2_fwnode_device_parse(ov9282->dev, &props); in ov9282_init_controls()
1376 dev_err(ov9282->dev, "control init failed: %d", in ov9282_init_controls()
1382 ov9282->sd.ctrl_handler = ctrl_hdlr; in ov9282_init_controls()
1395 struct ov9282 *ov9282; in ov9282_probe() local
1398 ov9282 = devm_kzalloc(&client->dev, sizeof(*ov9282), GFP_KERNEL); in ov9282_probe()
1399 if (!ov9282) in ov9282_probe()
1402 ov9282->dev = &client->dev; in ov9282_probe()
1405 v4l2_i2c_subdev_init(&ov9282->sd, client, &ov9282_subdev_ops); in ov9282_probe()
1406 v4l2_i2c_subdev_set_name(&ov9282->sd, client, in ov9282_probe()
1407 device_get_match_data(ov9282->dev), NULL); in ov9282_probe()
1409 ret = ov9282_parse_hw_config(ov9282); in ov9282_probe()
1411 dev_err(ov9282->dev, "HW configuration is not supported"); in ov9282_probe()
1415 mutex_init(&ov9282->mutex); in ov9282_probe()
1417 ret = ov9282_power_on(ov9282->dev); in ov9282_probe()
1419 dev_err(ov9282->dev, "failed to power-on the sensor"); in ov9282_probe()
1424 ret = ov9282_detect(ov9282); in ov9282_probe()
1426 dev_err(ov9282->dev, "failed to find sensor: %d", ret); in ov9282_probe()
1431 ov9282->cur_mode = &supported_modes[DEFAULT_MODE]; in ov9282_probe()
1432 ov9282->code = MEDIA_BUS_FMT_Y10_1X10; in ov9282_probe()
1433 ov9282->vblank = ov9282->cur_mode->vblank; in ov9282_probe()
1435 ret = ov9282_init_controls(ov9282); in ov9282_probe()
1437 dev_err(ov9282->dev, "failed to init controls: %d", ret); in ov9282_probe()
1442 ov9282->sd.flags |= V4L2_SUBDEV_FL_HAS_DEVNODE | in ov9282_probe()
1444 ov9282->sd.entity.function = MEDIA_ENT_F_CAM_SENSOR; in ov9282_probe()
1447 ov9282->pad.flags = MEDIA_PAD_FL_SOURCE; in ov9282_probe()
1448 ret = media_entity_pads_init(&ov9282->sd.entity, 1, &ov9282->pad); in ov9282_probe()
1450 dev_err(ov9282->dev, "failed to init entity pads: %d", ret); in ov9282_probe()
1454 ret = v4l2_async_register_subdev_sensor(&ov9282->sd); in ov9282_probe()
1456 dev_err(ov9282->dev, in ov9282_probe()
1461 pm_runtime_set_active(ov9282->dev); in ov9282_probe()
1462 pm_runtime_enable(ov9282->dev); in ov9282_probe()
1463 pm_runtime_idle(ov9282->dev); in ov9282_probe()
1468 media_entity_cleanup(&ov9282->sd.entity); in ov9282_probe()
1470 v4l2_ctrl_handler_free(ov9282->sd.ctrl_handler); in ov9282_probe()
1472 ov9282_power_off(ov9282->dev); in ov9282_probe()
1474 mutex_destroy(&ov9282->mutex); in ov9282_probe()
1488 struct ov9282 *ov9282 = to_ov9282(sd); in ov9282_remove() local
1499 mutex_destroy(&ov9282->mutex); in ov9282_remove()
1508 { .compatible = "ovti,ov9282", .data = "ov9282" },
1518 .name = "ov9282",
1526 MODULE_DESCRIPTION("OmniVision ov9282 sensor driver");