Lines Matching refs:imx334

124 struct imx334 {  struct
269 static inline struct imx334 *to_imx334(struct v4l2_subdev *subdev) in to_imx334()
271 return container_of(subdev, struct imx334, sd); in to_imx334()
285 static int imx334_read_reg(struct imx334 *imx334, u16 reg, u32 len, u32 *val) in imx334_read_reg() argument
287 struct i2c_client *client = v4l2_get_subdevdata(&imx334->sd); in imx334_read_reg()
330 static int imx334_write_reg(struct imx334 *imx334, u16 reg, u32 len, u32 val) in imx334_write_reg() argument
332 struct i2c_client *client = v4l2_get_subdevdata(&imx334->sd); in imx334_write_reg()
354 static int imx334_write_regs(struct imx334 *imx334, in imx334_write_regs() argument
361 ret = imx334_write_reg(imx334, regs[i].address, 1, regs[i].val); in imx334_write_regs()
376 static int imx334_update_controls(struct imx334 *imx334, in imx334_update_controls() argument
381 ret = __v4l2_ctrl_s_ctrl(imx334->link_freq_ctrl, mode->link_freq_idx); in imx334_update_controls()
385 ret = __v4l2_ctrl_s_ctrl(imx334->hblank_ctrl, mode->hblank); in imx334_update_controls()
389 return __v4l2_ctrl_modify_range(imx334->vblank_ctrl, mode->vblank_min, in imx334_update_controls()
401 static int imx334_update_exp_gain(struct imx334 *imx334, u32 exposure, u32 gain) in imx334_update_exp_gain() argument
406 lpfr = imx334->vblank + imx334->cur_mode->height; in imx334_update_exp_gain()
409 dev_dbg(imx334->dev, "Set long exp %u analog gain %u sh0 %u lpfr %u", in imx334_update_exp_gain()
412 ret = imx334_write_reg(imx334, IMX334_REG_HOLD, 1, 1); in imx334_update_exp_gain()
416 ret = imx334_write_reg(imx334, IMX334_REG_LPFR, 3, lpfr); in imx334_update_exp_gain()
420 ret = imx334_write_reg(imx334, IMX334_REG_SHUTTER, 3, shutter); in imx334_update_exp_gain()
424 ret = imx334_write_reg(imx334, IMX334_REG_AGAIN, 1, gain); in imx334_update_exp_gain()
427 imx334_write_reg(imx334, IMX334_REG_HOLD, 1, 0); in imx334_update_exp_gain()
446 struct imx334 *imx334 = in imx334_set_ctrl() local
447 container_of(ctrl->handler, struct imx334, ctrl_handler); in imx334_set_ctrl()
454 imx334->vblank = imx334->vblank_ctrl->val; in imx334_set_ctrl()
456 dev_dbg(imx334->dev, "Received vblank %u, new lpfr %u", in imx334_set_ctrl()
457 imx334->vblank, in imx334_set_ctrl()
458 imx334->vblank + imx334->cur_mode->height); in imx334_set_ctrl()
460 ret = __v4l2_ctrl_modify_range(imx334->exp_ctrl, in imx334_set_ctrl()
462 imx334->vblank + in imx334_set_ctrl()
463 imx334->cur_mode->height - in imx334_set_ctrl()
470 if (!pm_runtime_get_if_in_use(imx334->dev)) in imx334_set_ctrl()
474 analog_gain = imx334->again_ctrl->val; in imx334_set_ctrl()
476 dev_dbg(imx334->dev, "Received exp %u analog gain %u", in imx334_set_ctrl()
479 ret = imx334_update_exp_gain(imx334, exposure, analog_gain); in imx334_set_ctrl()
481 pm_runtime_put(imx334->dev); in imx334_set_ctrl()
485 dev_err(imx334->dev, "Invalid control %d", ctrl->id); in imx334_set_ctrl()
550 static void imx334_fill_pad_format(struct imx334 *imx334, in imx334_fill_pad_format() argument
576 struct imx334 *imx334 = to_imx334(sd); in imx334_get_pad_format() local
578 mutex_lock(&imx334->mutex); in imx334_get_pad_format()
586 imx334_fill_pad_format(imx334, imx334->cur_mode, fmt); in imx334_get_pad_format()
589 mutex_unlock(&imx334->mutex); in imx334_get_pad_format()
606 struct imx334 *imx334 = to_imx334(sd); in imx334_set_pad_format() local
610 mutex_lock(&imx334->mutex); in imx334_set_pad_format()
613 imx334_fill_pad_format(imx334, mode, fmt); in imx334_set_pad_format()
621 ret = imx334_update_controls(imx334, mode); in imx334_set_pad_format()
623 imx334->cur_mode = mode; in imx334_set_pad_format()
626 mutex_unlock(&imx334->mutex); in imx334_set_pad_format()
641 struct imx334 *imx334 = to_imx334(sd); in imx334_init_pad_cfg() local
645 imx334_fill_pad_format(imx334, &supported_mode, &fmt); in imx334_init_pad_cfg()
656 static int imx334_start_streaming(struct imx334 *imx334) in imx334_start_streaming() argument
662 reg_list = &imx334->cur_mode->reg_list; in imx334_start_streaming()
663 ret = imx334_write_regs(imx334, reg_list->regs, in imx334_start_streaming()
666 dev_err(imx334->dev, "fail to write initial registers"); in imx334_start_streaming()
671 ret = __v4l2_ctrl_handler_setup(imx334->sd.ctrl_handler); in imx334_start_streaming()
673 dev_err(imx334->dev, "fail to setup handler"); in imx334_start_streaming()
678 ret = imx334_write_reg(imx334, IMX334_REG_MODE_SELECT, in imx334_start_streaming()
681 dev_err(imx334->dev, "fail to start streaming"); in imx334_start_streaming()
694 static int imx334_stop_streaming(struct imx334 *imx334) in imx334_stop_streaming() argument
696 return imx334_write_reg(imx334, IMX334_REG_MODE_SELECT, in imx334_stop_streaming()
709 struct imx334 *imx334 = to_imx334(sd); in imx334_set_stream() local
712 mutex_lock(&imx334->mutex); in imx334_set_stream()
714 if (imx334->streaming == enable) { in imx334_set_stream()
715 mutex_unlock(&imx334->mutex); in imx334_set_stream()
720 ret = pm_runtime_resume_and_get(imx334->dev); in imx334_set_stream()
724 ret = imx334_start_streaming(imx334); in imx334_set_stream()
728 imx334_stop_streaming(imx334); in imx334_set_stream()
729 pm_runtime_put(imx334->dev); in imx334_set_stream()
732 imx334->streaming = enable; in imx334_set_stream()
734 mutex_unlock(&imx334->mutex); in imx334_set_stream()
739 pm_runtime_put(imx334->dev); in imx334_set_stream()
741 mutex_unlock(&imx334->mutex); in imx334_set_stream()
752 static int imx334_detect(struct imx334 *imx334) in imx334_detect() argument
757 ret = imx334_read_reg(imx334, IMX334_REG_ID, 2, &val); in imx334_detect()
762 dev_err(imx334->dev, "chip id mismatch: %x!=%x", in imx334_detect()
776 static int imx334_parse_hw_config(struct imx334 *imx334) in imx334_parse_hw_config() argument
778 struct fwnode_handle *fwnode = dev_fwnode(imx334->dev); in imx334_parse_hw_config()
791 imx334->reset_gpio = devm_gpiod_get_optional(imx334->dev, "reset", in imx334_parse_hw_config()
793 if (IS_ERR(imx334->reset_gpio)) { in imx334_parse_hw_config()
794 dev_err(imx334->dev, "failed to get reset gpio %ld", in imx334_parse_hw_config()
795 PTR_ERR(imx334->reset_gpio)); in imx334_parse_hw_config()
796 return PTR_ERR(imx334->reset_gpio); in imx334_parse_hw_config()
800 imx334->inclk = devm_clk_get(imx334->dev, NULL); in imx334_parse_hw_config()
801 if (IS_ERR(imx334->inclk)) { in imx334_parse_hw_config()
802 dev_err(imx334->dev, "could not get inclk"); in imx334_parse_hw_config()
803 return PTR_ERR(imx334->inclk); in imx334_parse_hw_config()
806 rate = clk_get_rate(imx334->inclk); in imx334_parse_hw_config()
808 dev_err(imx334->dev, "inclk frequency mismatch"); in imx334_parse_hw_config()
822 dev_err(imx334->dev, in imx334_parse_hw_config()
830 dev_err(imx334->dev, "no link frequencies defined"); in imx334_parse_hw_config()
874 struct imx334 *imx334 = to_imx334(sd); in imx334_power_on() local
877 gpiod_set_value_cansleep(imx334->reset_gpio, 1); in imx334_power_on()
879 ret = clk_prepare_enable(imx334->inclk); in imx334_power_on()
881 dev_err(imx334->dev, "fail to enable inclk"); in imx334_power_on()
890 gpiod_set_value_cansleep(imx334->reset_gpio, 0); in imx334_power_on()
904 struct imx334 *imx334 = to_imx334(sd); in imx334_power_off() local
906 gpiod_set_value_cansleep(imx334->reset_gpio, 0); in imx334_power_off()
908 clk_disable_unprepare(imx334->inclk); in imx334_power_off()
919 static int imx334_init_controls(struct imx334 *imx334) in imx334_init_controls() argument
921 struct v4l2_ctrl_handler *ctrl_hdlr = &imx334->ctrl_handler; in imx334_init_controls()
922 const struct imx334_mode *mode = imx334->cur_mode; in imx334_init_controls()
931 ctrl_hdlr->lock = &imx334->mutex; in imx334_init_controls()
935 imx334->exp_ctrl = v4l2_ctrl_new_std(ctrl_hdlr, in imx334_init_controls()
943 imx334->again_ctrl = v4l2_ctrl_new_std(ctrl_hdlr, in imx334_init_controls()
951 v4l2_ctrl_cluster(2, &imx334->exp_ctrl); in imx334_init_controls()
953 imx334->vblank_ctrl = v4l2_ctrl_new_std(ctrl_hdlr, in imx334_init_controls()
961 imx334->pclk_ctrl = v4l2_ctrl_new_std(ctrl_hdlr, in imx334_init_controls()
967 imx334->link_freq_ctrl = v4l2_ctrl_new_int_menu(ctrl_hdlr, in imx334_init_controls()
974 if (imx334->link_freq_ctrl) in imx334_init_controls()
975 imx334->link_freq_ctrl->flags |= V4L2_CTRL_FLAG_READ_ONLY; in imx334_init_controls()
977 imx334->hblank_ctrl = v4l2_ctrl_new_std(ctrl_hdlr, in imx334_init_controls()
983 if (imx334->hblank_ctrl) in imx334_init_controls()
984 imx334->hblank_ctrl->flags |= V4L2_CTRL_FLAG_READ_ONLY; in imx334_init_controls()
987 dev_err(imx334->dev, "control init failed: %d", in imx334_init_controls()
993 imx334->sd.ctrl_handler = ctrl_hdlr; in imx334_init_controls()
1006 struct imx334 *imx334; in imx334_probe() local
1009 imx334 = devm_kzalloc(&client->dev, sizeof(*imx334), GFP_KERNEL); in imx334_probe()
1010 if (!imx334) in imx334_probe()
1013 imx334->dev = &client->dev; in imx334_probe()
1016 v4l2_i2c_subdev_init(&imx334->sd, client, &imx334_subdev_ops); in imx334_probe()
1018 ret = imx334_parse_hw_config(imx334); in imx334_probe()
1020 dev_err(imx334->dev, "HW configuration is not supported"); in imx334_probe()
1024 mutex_init(&imx334->mutex); in imx334_probe()
1026 ret = imx334_power_on(imx334->dev); in imx334_probe()
1028 dev_err(imx334->dev, "failed to power-on the sensor"); in imx334_probe()
1033 ret = imx334_detect(imx334); in imx334_probe()
1035 dev_err(imx334->dev, "failed to find sensor: %d", ret); in imx334_probe()
1040 imx334->cur_mode = &supported_mode; in imx334_probe()
1041 imx334->vblank = imx334->cur_mode->vblank; in imx334_probe()
1043 ret = imx334_init_controls(imx334); in imx334_probe()
1045 dev_err(imx334->dev, "failed to init controls: %d", ret); in imx334_probe()
1050 imx334->sd.flags |= V4L2_SUBDEV_FL_HAS_DEVNODE; in imx334_probe()
1051 imx334->sd.entity.function = MEDIA_ENT_F_CAM_SENSOR; in imx334_probe()
1054 imx334->pad.flags = MEDIA_PAD_FL_SOURCE; in imx334_probe()
1055 ret = media_entity_pads_init(&imx334->sd.entity, 1, &imx334->pad); in imx334_probe()
1057 dev_err(imx334->dev, "failed to init entity pads: %d", ret); in imx334_probe()
1061 ret = v4l2_async_register_subdev_sensor(&imx334->sd); in imx334_probe()
1063 dev_err(imx334->dev, in imx334_probe()
1068 pm_runtime_set_active(imx334->dev); in imx334_probe()
1069 pm_runtime_enable(imx334->dev); in imx334_probe()
1070 pm_runtime_idle(imx334->dev); in imx334_probe()
1075 media_entity_cleanup(&imx334->sd.entity); in imx334_probe()
1077 v4l2_ctrl_handler_free(imx334->sd.ctrl_handler); in imx334_probe()
1079 imx334_power_off(imx334->dev); in imx334_probe()
1081 mutex_destroy(&imx334->mutex); in imx334_probe()
1095 struct imx334 *imx334 = to_imx334(sd); in imx334_remove() local
1104 mutex_destroy(&imx334->mutex); in imx334_remove()