Lines Matching full:imx334

3  * Sony imx334 sensor driver
78 * struct imx334_reg - imx334 sensor register
88 * struct imx334_reg_list - imx334 sensor register list
98 * struct imx334_mode - imx334 sensor mode structure
122 * struct imx334 - imx334 sensor device structure
142 struct imx334 { struct
512 * to_imx334() - imv334 V4L2 sub-device to imx334 device.
513 * @subdev: pointer to imx334 V4L2 sub-device
515 * Return: pointer to imx334 device
517 static inline struct imx334 *to_imx334(struct v4l2_subdev *subdev) in to_imx334()
519 return container_of(subdev, struct imx334, sd); in to_imx334()
524 * @imx334: pointer to imx334 device
533 static int imx334_read_reg(struct imx334 *imx334, u16 reg, u32 len, u32 *val) in imx334_read_reg() argument
535 struct i2c_client *client = v4l2_get_subdevdata(&imx334->sd); in imx334_read_reg()
569 * @imx334: pointer to imx334 device
578 static int imx334_write_reg(struct imx334 *imx334, u16 reg, u32 len, u32 val) in imx334_write_reg() argument
580 struct i2c_client *client = v4l2_get_subdevdata(&imx334->sd); in imx334_write_reg()
596 * @imx334: pointer to imx334 device
602 static int imx334_write_regs(struct imx334 *imx334, in imx334_write_regs() argument
609 ret = imx334_write_reg(imx334, regs[i].address, 1, regs[i].val); in imx334_write_regs()
619 * @imx334: pointer to imx334 device
624 static int imx334_update_controls(struct imx334 *imx334, in imx334_update_controls() argument
629 ret = __v4l2_ctrl_s_ctrl(imx334->link_freq_ctrl, mode->link_freq_idx); in imx334_update_controls()
633 ret = __v4l2_ctrl_modify_range(imx334->pclk_ctrl, mode->pclk, in imx334_update_controls()
638 ret = __v4l2_ctrl_modify_range(imx334->hblank_ctrl, mode->hblank, in imx334_update_controls()
643 ret = __v4l2_ctrl_modify_range(imx334->vblank_ctrl, mode->vblank_min, in imx334_update_controls()
648 return __v4l2_ctrl_s_ctrl(imx334->vblank_ctrl, mode->vblank); in imx334_update_controls()
653 * @imx334: pointer to imx334 device
659 static int imx334_update_exp_gain(struct imx334 *imx334, u32 exposure, u32 gain) in imx334_update_exp_gain() argument
664 lpfr = imx334->vblank + imx334->cur_mode->height; in imx334_update_exp_gain()
667 dev_dbg(imx334->dev, "Set long exp %u analog gain %u sh0 %u lpfr %u", in imx334_update_exp_gain()
670 ret = imx334_write_reg(imx334, IMX334_REG_HOLD, 1, 1); in imx334_update_exp_gain()
674 ret = imx334_write_reg(imx334, IMX334_REG_LPFR, 3, lpfr); in imx334_update_exp_gain()
678 ret = imx334_write_reg(imx334, IMX334_REG_SHUTTER, 3, shutter); in imx334_update_exp_gain()
682 ret = imx334_write_reg(imx334, IMX334_REG_AGAIN, 1, gain); in imx334_update_exp_gain()
685 imx334_write_reg(imx334, IMX334_REG_HOLD, 1, 0); in imx334_update_exp_gain()
704 struct imx334 *imx334 = in imx334_set_ctrl() local
705 container_of(ctrl->handler, struct imx334, ctrl_handler); in imx334_set_ctrl()
712 imx334->vblank = imx334->vblank_ctrl->val; in imx334_set_ctrl()
714 dev_dbg(imx334->dev, "Received vblank %u, new lpfr %u", in imx334_set_ctrl()
715 imx334->vblank, in imx334_set_ctrl()
716 imx334->vblank + imx334->cur_mode->height); in imx334_set_ctrl()
718 ret = __v4l2_ctrl_modify_range(imx334->exp_ctrl, in imx334_set_ctrl()
720 imx334->vblank + in imx334_set_ctrl()
721 imx334->cur_mode->height - in imx334_set_ctrl()
728 if (!pm_runtime_get_if_in_use(imx334->dev)) in imx334_set_ctrl()
732 analog_gain = imx334->again_ctrl->val; in imx334_set_ctrl()
734 dev_dbg(imx334->dev, "Received exp %u analog gain %u", in imx334_set_ctrl()
737 ret = imx334_update_exp_gain(imx334, exposure, analog_gain); in imx334_set_ctrl()
739 pm_runtime_put(imx334->dev); in imx334_set_ctrl()
749 imx334_write_reg(imx334, IMX334_TP_CLK_EN, 1, in imx334_set_ctrl()
751 imx334_write_reg(imx334, IMX334_DIG_CLP_MODE, 1, 0x0); in imx334_set_ctrl()
752 imx334_write_reg(imx334, IMX334_TPG_COLORW, 1, in imx334_set_ctrl()
754 imx334_write_reg(imx334, IMX334_REG_TP, 1, in imx334_set_ctrl()
756 imx334_write_reg(imx334, IMX334_TPG_EN_DOUT, 1, in imx334_set_ctrl()
759 imx334_write_reg(imx334, IMX334_DIG_CLP_MODE, 1, 0x1); in imx334_set_ctrl()
760 imx334_write_reg(imx334, IMX334_TP_CLK_EN, 1, in imx334_set_ctrl()
762 imx334_write_reg(imx334, IMX334_TPG_EN_DOUT, 1, in imx334_set_ctrl()
768 dev_err(imx334->dev, "Invalid control %d", ctrl->id); in imx334_set_ctrl()
780 static int imx334_get_format_code(struct imx334 *imx334, u32 code) in imx334_get_format_code() argument
794 * @sd: pointer to imx334 V4L2 sub-device structure
814 * @sd: pointer to imx334 V4L2 sub-device structure
824 struct imx334 *imx334 = to_imx334(sd); in imx334_enum_frame_size() local
830 code = imx334_get_format_code(imx334, fsize->code); in imx334_enum_frame_size()
846 * @imx334: pointer to imx334 device
850 static void imx334_fill_pad_format(struct imx334 *imx334, in imx334_fill_pad_format() argument
865 * @sd: pointer to imx334 V4L2 sub-device structure
875 struct imx334 *imx334 = to_imx334(sd); in imx334_get_pad_format() local
877 mutex_lock(&imx334->mutex); in imx334_get_pad_format()
885 fmt->format.code = imx334->cur_code; in imx334_get_pad_format()
886 imx334_fill_pad_format(imx334, imx334->cur_mode, fmt); in imx334_get_pad_format()
889 mutex_unlock(&imx334->mutex); in imx334_get_pad_format()
896 * @sd: pointer to imx334 V4L2 sub-device structure
906 struct imx334 *imx334 = to_imx334(sd); in imx334_set_pad_format() local
910 mutex_lock(&imx334->mutex); in imx334_set_pad_format()
917 imx334_fill_pad_format(imx334, mode, fmt); in imx334_set_pad_format()
918 fmt->format.code = imx334_get_format_code(imx334, fmt->format.code); in imx334_set_pad_format()
925 } else if (imx334->cur_mode != mode || imx334->cur_code != fmt->format.code) { in imx334_set_pad_format()
926 imx334->cur_code = fmt->format.code; in imx334_set_pad_format()
927 ret = imx334_update_controls(imx334, mode); in imx334_set_pad_format()
929 imx334->cur_mode = mode; in imx334_set_pad_format()
932 mutex_unlock(&imx334->mutex); in imx334_set_pad_format()
939 * @sd: pointer to imx334 V4L2 sub-device structure
947 struct imx334 *imx334 = to_imx334(sd); in imx334_init_state() local
952 mutex_lock(&imx334->mutex); in imx334_init_state()
954 imx334_fill_pad_format(imx334, imx334->cur_mode, &fmt); in imx334_init_state()
956 __v4l2_ctrl_modify_range(imx334->link_freq_ctrl, 0, in imx334_init_state()
957 __fls(imx334->link_freq_bitmap), in imx334_init_state()
958 ~(imx334->link_freq_bitmap), in imx334_init_state()
959 __ffs(imx334->link_freq_bitmap)); in imx334_init_state()
961 mutex_unlock(&imx334->mutex); in imx334_init_state()
966 static int imx334_set_framefmt(struct imx334 *imx334) in imx334_set_framefmt() argument
968 switch (imx334->cur_code) { in imx334_set_framefmt()
970 return imx334_write_regs(imx334, raw10_framefmt_regs, in imx334_set_framefmt()
974 return imx334_write_regs(imx334, raw12_framefmt_regs, in imx334_set_framefmt()
983 * @imx334: pointer to imx334 device
987 static int imx334_start_streaming(struct imx334 *imx334) in imx334_start_streaming() argument
993 reg_list = &imx334->cur_mode->reg_list; in imx334_start_streaming()
994 ret = imx334_write_regs(imx334, reg_list->regs, in imx334_start_streaming()
997 dev_err(imx334->dev, "fail to write initial registers"); in imx334_start_streaming()
1001 ret = imx334_set_framefmt(imx334); in imx334_start_streaming()
1003 dev_err(imx334->dev, "%s failed to set frame format: %d\n", in imx334_start_streaming()
1009 ret = __v4l2_ctrl_handler_setup(imx334->sd.ctrl_handler); in imx334_start_streaming()
1011 dev_err(imx334->dev, "fail to setup handler"); in imx334_start_streaming()
1016 ret = imx334_write_reg(imx334, IMX334_REG_MODE_SELECT, in imx334_start_streaming()
1019 dev_err(imx334->dev, "fail to start streaming"); in imx334_start_streaming()
1028 * @imx334: pointer to imx334 device
1032 static int imx334_stop_streaming(struct imx334 *imx334) in imx334_stop_streaming() argument
1034 return imx334_write_reg(imx334, IMX334_REG_MODE_SELECT, in imx334_stop_streaming()
1040 * @sd: pointer to imx334 subdevice
1047 struct imx334 *imx334 = to_imx334(sd); in imx334_set_stream() local
1050 mutex_lock(&imx334->mutex); in imx334_set_stream()
1053 ret = pm_runtime_resume_and_get(imx334->dev); in imx334_set_stream()
1057 ret = imx334_start_streaming(imx334); in imx334_set_stream()
1061 imx334_stop_streaming(imx334); in imx334_set_stream()
1062 pm_runtime_put(imx334->dev); in imx334_set_stream()
1065 mutex_unlock(&imx334->mutex); in imx334_set_stream()
1070 pm_runtime_put(imx334->dev); in imx334_set_stream()
1072 mutex_unlock(&imx334->mutex); in imx334_set_stream()
1078 * imx334_detect() - Detect imx334 sensor
1079 * @imx334: pointer to imx334 device
1083 static int imx334_detect(struct imx334 *imx334) in imx334_detect() argument
1088 ret = imx334_read_reg(imx334, IMX334_REG_ID, 2, &val); in imx334_detect()
1093 dev_err(imx334->dev, "chip id mismatch: %x!=%x", in imx334_detect()
1103 * @imx334: pointer to imx334 device
1107 static int imx334_parse_hw_config(struct imx334 *imx334) in imx334_parse_hw_config() argument
1109 struct fwnode_handle *fwnode = dev_fwnode(imx334->dev); in imx334_parse_hw_config()
1121 imx334->reset_gpio = devm_gpiod_get_optional(imx334->dev, "reset", in imx334_parse_hw_config()
1123 if (IS_ERR(imx334->reset_gpio)) { in imx334_parse_hw_config()
1124 dev_err(imx334->dev, "failed to get reset gpio %ld", in imx334_parse_hw_config()
1125 PTR_ERR(imx334->reset_gpio)); in imx334_parse_hw_config()
1126 return PTR_ERR(imx334->reset_gpio); in imx334_parse_hw_config()
1130 imx334->inclk = devm_clk_get(imx334->dev, NULL); in imx334_parse_hw_config()
1131 if (IS_ERR(imx334->inclk)) { in imx334_parse_hw_config()
1132 dev_err(imx334->dev, "could not get inclk"); in imx334_parse_hw_config()
1133 return PTR_ERR(imx334->inclk); in imx334_parse_hw_config()
1136 rate = clk_get_rate(imx334->inclk); in imx334_parse_hw_config()
1138 dev_err(imx334->dev, "inclk frequency mismatch"); in imx334_parse_hw_config()
1152 dev_err(imx334->dev, in imx334_parse_hw_config()
1159 ret = v4l2_link_freq_to_bitmap(imx334->dev, bus_cfg.link_frequencies, in imx334_parse_hw_config()
1162 &imx334->link_freq_bitmap); in imx334_parse_hw_config()
1200 struct imx334 *imx334 = to_imx334(sd); in imx334_power_on() local
1203 gpiod_set_value_cansleep(imx334->reset_gpio, 1); in imx334_power_on()
1205 ret = clk_prepare_enable(imx334->inclk); in imx334_power_on()
1207 dev_err(imx334->dev, "fail to enable inclk"); in imx334_power_on()
1216 gpiod_set_value_cansleep(imx334->reset_gpio, 0); in imx334_power_on()
1230 struct imx334 *imx334 = to_imx334(sd); in imx334_power_off() local
1232 gpiod_set_value_cansleep(imx334->reset_gpio, 0); in imx334_power_off()
1234 clk_disable_unprepare(imx334->inclk); in imx334_power_off()
1241 * @imx334: pointer to imx334 device
1245 static int imx334_init_controls(struct imx334 *imx334) in imx334_init_controls() argument
1247 struct v4l2_ctrl_handler *ctrl_hdlr = &imx334->ctrl_handler; in imx334_init_controls()
1248 const struct imx334_mode *mode = imx334->cur_mode; in imx334_init_controls()
1257 ctrl_hdlr->lock = &imx334->mutex; in imx334_init_controls()
1261 imx334->exp_ctrl = v4l2_ctrl_new_std(ctrl_hdlr, in imx334_init_controls()
1269 imx334->again_ctrl = v4l2_ctrl_new_std(ctrl_hdlr, in imx334_init_controls()
1277 v4l2_ctrl_cluster(2, &imx334->exp_ctrl); in imx334_init_controls()
1279 imx334->vblank_ctrl = v4l2_ctrl_new_std(ctrl_hdlr, in imx334_init_controls()
1287 imx334->pclk_ctrl = v4l2_ctrl_new_std(ctrl_hdlr, in imx334_init_controls()
1293 imx334->link_freq_ctrl = v4l2_ctrl_new_int_menu(ctrl_hdlr, in imx334_init_controls()
1296 __fls(imx334->link_freq_bitmap), in imx334_init_controls()
1297 __ffs(imx334->link_freq_bitmap), in imx334_init_controls()
1300 if (imx334->link_freq_ctrl) in imx334_init_controls()
1301 imx334->link_freq_ctrl->flags |= V4L2_CTRL_FLAG_READ_ONLY; in imx334_init_controls()
1303 imx334->hblank_ctrl = v4l2_ctrl_new_std(ctrl_hdlr, in imx334_init_controls()
1309 if (imx334->hblank_ctrl) in imx334_init_controls()
1310 imx334->hblank_ctrl->flags |= V4L2_CTRL_FLAG_READ_ONLY; in imx334_init_controls()
1318 dev_err(imx334->dev, "control init failed: %d", in imx334_init_controls()
1324 imx334->sd.ctrl_handler = ctrl_hdlr; in imx334_init_controls()
1337 struct imx334 *imx334; in imx334_probe() local
1340 imx334 = devm_kzalloc(&client->dev, sizeof(*imx334), GFP_KERNEL); in imx334_probe()
1341 if (!imx334) in imx334_probe()
1344 imx334->dev = &client->dev; in imx334_probe()
1347 v4l2_i2c_subdev_init(&imx334->sd, client, &imx334_subdev_ops); in imx334_probe()
1348 imx334->sd.internal_ops = &imx334_internal_ops; in imx334_probe()
1350 ret = imx334_parse_hw_config(imx334); in imx334_probe()
1352 dev_err(imx334->dev, "HW configuration is not supported"); in imx334_probe()
1356 mutex_init(&imx334->mutex); in imx334_probe()
1358 ret = imx334_power_on(imx334->dev); in imx334_probe()
1360 dev_err(imx334->dev, "failed to power-on the sensor"); in imx334_probe()
1365 ret = imx334_detect(imx334); in imx334_probe()
1367 dev_err(imx334->dev, "failed to find sensor: %d", ret); in imx334_probe()
1372 imx334->cur_mode = &supported_modes[__ffs(imx334->link_freq_bitmap)]; in imx334_probe()
1373 imx334->cur_code = imx334_mbus_codes[0]; in imx334_probe()
1374 imx334->vblank = imx334->cur_mode->vblank; in imx334_probe()
1376 ret = imx334_init_controls(imx334); in imx334_probe()
1378 dev_err(imx334->dev, "failed to init controls: %d", ret); in imx334_probe()
1383 imx334->sd.flags |= V4L2_SUBDEV_FL_HAS_DEVNODE; in imx334_probe()
1384 imx334->sd.entity.function = MEDIA_ENT_F_CAM_SENSOR; in imx334_probe()
1387 imx334->pad.flags = MEDIA_PAD_FL_SOURCE; in imx334_probe()
1388 ret = media_entity_pads_init(&imx334->sd.entity, 1, &imx334->pad); in imx334_probe()
1390 dev_err(imx334->dev, "failed to init entity pads: %d", ret); in imx334_probe()
1394 ret = v4l2_async_register_subdev_sensor(&imx334->sd); in imx334_probe()
1396 dev_err(imx334->dev, in imx334_probe()
1401 pm_runtime_set_active(imx334->dev); in imx334_probe()
1402 pm_runtime_enable(imx334->dev); in imx334_probe()
1403 pm_runtime_idle(imx334->dev); in imx334_probe()
1408 media_entity_cleanup(&imx334->sd.entity); in imx334_probe()
1410 v4l2_ctrl_handler_free(imx334->sd.ctrl_handler); in imx334_probe()
1412 imx334_power_off(imx334->dev); in imx334_probe()
1414 mutex_destroy(&imx334->mutex); in imx334_probe()
1428 struct imx334 *imx334 = to_imx334(sd); in imx334_remove() local
1437 mutex_destroy(&imx334->mutex); in imx334_remove()
1445 { .compatible = "sony,imx334" },
1455 .name = "imx334",
1463 MODULE_DESCRIPTION("Sony imx334 sensor driver");