Lines Matching defs:ov9282

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