Lines Matching full:imx412

3  * Sony imx412 Camera Sensor Driver
60 * struct imx412_reg - imx412 sensor register
70 * struct imx412_reg_list - imx412 sensor register list
80 * struct imx412_mode - imx412 sensor mode structure
112 * struct imx412 - imx412 sensor device structure
131 struct imx412 { struct
410 * to_imx412() - imx412 V4L2 sub-device to imx412 device.
411 * @subdev: pointer to imx412 V4L2 sub-device
413 * Return: pointer to imx412 device
415 static inline struct imx412 *to_imx412(struct v4l2_subdev *subdev) in to_imx412()
417 return container_of(subdev, struct imx412, sd); in to_imx412()
422 * @imx412: pointer to imx412 device
429 static int imx412_read_reg(struct imx412 *imx412, u16 reg, u32 len, u32 *val) in imx412_read_reg() argument
431 struct i2c_client *client = v4l2_get_subdevdata(&imx412->sd); in imx412_read_reg()
465 * @imx412: pointer to imx412 device
472 static int imx412_write_reg(struct imx412 *imx412, u16 reg, u32 len, u32 val) in imx412_write_reg() argument
474 struct i2c_client *client = v4l2_get_subdevdata(&imx412->sd); in imx412_write_reg()
490 * @imx412: pointer to imx412 device
496 static int imx412_write_regs(struct imx412 *imx412, in imx412_write_regs() argument
503 ret = imx412_write_reg(imx412, regs[i].address, 1, regs[i].val); in imx412_write_regs()
513 * @imx412: pointer to imx412 device
518 static int imx412_update_controls(struct imx412 *imx412, in imx412_update_controls() argument
523 ret = __v4l2_ctrl_s_ctrl(imx412->link_freq_ctrl, mode->link_freq_idx); in imx412_update_controls()
527 ret = __v4l2_ctrl_s_ctrl(imx412->hblank_ctrl, mode->hblank); in imx412_update_controls()
531 return __v4l2_ctrl_modify_range(imx412->vblank_ctrl, mode->vblank_min, in imx412_update_controls()
537 * @imx412: pointer to imx412 device
543 static int imx412_update_exp_gain(struct imx412 *imx412, u32 exposure, u32 gain) in imx412_update_exp_gain() argument
548 lpfr = imx412->vblank + imx412->cur_mode->height; in imx412_update_exp_gain()
550 dev_dbg(imx412->dev, "Set exp %u, analog gain %u, lpfr %u", in imx412_update_exp_gain()
553 ret = imx412_write_reg(imx412, IMX412_REG_HOLD, 1, 1); in imx412_update_exp_gain()
557 ret = imx412_write_reg(imx412, IMX412_REG_LPFR, 2, lpfr); in imx412_update_exp_gain()
561 ret = imx412_write_reg(imx412, IMX412_REG_EXPOSURE_CIT, 2, exposure); in imx412_update_exp_gain()
565 ret = imx412_write_reg(imx412, IMX412_REG_AGAIN, 2, gain); in imx412_update_exp_gain()
568 imx412_write_reg(imx412, IMX412_REG_HOLD, 1, 0); in imx412_update_exp_gain()
587 struct imx412 *imx412 = in imx412_set_ctrl() local
588 container_of(ctrl->handler, struct imx412, ctrl_handler); in imx412_set_ctrl()
595 imx412->vblank = imx412->vblank_ctrl->val; in imx412_set_ctrl()
597 dev_dbg(imx412->dev, "Received vblank %u, new lpfr %u", in imx412_set_ctrl()
598 imx412->vblank, in imx412_set_ctrl()
599 imx412->vblank + imx412->cur_mode->height); in imx412_set_ctrl()
601 ret = __v4l2_ctrl_modify_range(imx412->exp_ctrl, in imx412_set_ctrl()
603 imx412->vblank + in imx412_set_ctrl()
604 imx412->cur_mode->height - in imx412_set_ctrl()
610 if (!pm_runtime_get_if_in_use(imx412->dev)) in imx412_set_ctrl()
614 analog_gain = imx412->again_ctrl->val; in imx412_set_ctrl()
616 dev_dbg(imx412->dev, "Received exp %u, analog gain %u", in imx412_set_ctrl()
619 ret = imx412_update_exp_gain(imx412, exposure, analog_gain); in imx412_set_ctrl()
621 pm_runtime_put(imx412->dev); in imx412_set_ctrl()
625 dev_err(imx412->dev, "Invalid control %d", ctrl->id); in imx412_set_ctrl()
639 * @sd: pointer to imx412 V4L2 sub-device structure
659 * @sd: pointer to imx412 V4L2 sub-device structure
686 * @imx412: pointer to imx412 device
690 static void imx412_fill_pad_format(struct imx412 *imx412, in imx412_fill_pad_format() argument
706 * @sd: pointer to imx412 V4L2 sub-device structure
716 struct imx412 *imx412 = to_imx412(sd); in imx412_get_pad_format() local
718 mutex_lock(&imx412->mutex); in imx412_get_pad_format()
726 imx412_fill_pad_format(imx412, imx412->cur_mode, fmt); in imx412_get_pad_format()
729 mutex_unlock(&imx412->mutex); in imx412_get_pad_format()
736 * @sd: pointer to imx412 V4L2 sub-device structure
746 struct imx412 *imx412 = to_imx412(sd); in imx412_set_pad_format() local
750 mutex_lock(&imx412->mutex); in imx412_set_pad_format()
753 imx412_fill_pad_format(imx412, mode, fmt); in imx412_set_pad_format()
761 ret = imx412_update_controls(imx412, mode); in imx412_set_pad_format()
763 imx412->cur_mode = mode; in imx412_set_pad_format()
766 mutex_unlock(&imx412->mutex); in imx412_set_pad_format()
773 * @sd: pointer to imx412 V4L2 sub-device structure
781 struct imx412 *imx412 = to_imx412(sd); in imx412_init_state() local
785 imx412_fill_pad_format(imx412, &supported_mode, &fmt); in imx412_init_state()
792 * @imx412: pointer to imx412 device
796 static int imx412_start_streaming(struct imx412 *imx412) in imx412_start_streaming() argument
802 reg_list = &imx412->cur_mode->reg_list; in imx412_start_streaming()
803 ret = imx412_write_regs(imx412, reg_list->regs, in imx412_start_streaming()
806 dev_err(imx412->dev, "fail to write initial registers"); in imx412_start_streaming()
811 ret = __v4l2_ctrl_handler_setup(imx412->sd.ctrl_handler); in imx412_start_streaming()
813 dev_err(imx412->dev, "fail to setup handler"); in imx412_start_streaming()
821 ret = imx412_write_reg(imx412, IMX412_REG_MODE_SELECT, in imx412_start_streaming()
824 dev_err(imx412->dev, "fail to start streaming"); in imx412_start_streaming()
833 * @imx412: pointer to imx412 device
837 static int imx412_stop_streaming(struct imx412 *imx412) in imx412_stop_streaming() argument
839 return imx412_write_reg(imx412, IMX412_REG_MODE_SELECT, in imx412_stop_streaming()
845 * @sd: pointer to imx412 subdevice
852 struct imx412 *imx412 = to_imx412(sd); in imx412_set_stream() local
855 mutex_lock(&imx412->mutex); in imx412_set_stream()
858 ret = pm_runtime_resume_and_get(imx412->dev); in imx412_set_stream()
862 ret = imx412_start_streaming(imx412); in imx412_set_stream()
866 imx412_stop_streaming(imx412); in imx412_set_stream()
867 pm_runtime_put(imx412->dev); in imx412_set_stream()
870 mutex_unlock(&imx412->mutex); in imx412_set_stream()
875 pm_runtime_put(imx412->dev); in imx412_set_stream()
877 mutex_unlock(&imx412->mutex); in imx412_set_stream()
883 * imx412_detect() - Detect imx412 sensor
884 * @imx412: pointer to imx412 device
888 static int imx412_detect(struct imx412 *imx412) in imx412_detect() argument
893 ret = imx412_read_reg(imx412, IMX412_REG_ID, 2, &val); in imx412_detect()
898 dev_err(imx412->dev, "chip id mismatch: %x!=%x", in imx412_detect()
908 * @imx412: pointer to imx412 device
912 static int imx412_parse_hw_config(struct imx412 *imx412) in imx412_parse_hw_config() argument
914 struct fwnode_handle *fwnode = dev_fwnode(imx412->dev); in imx412_parse_hw_config()
927 imx412->reset_gpio = devm_gpiod_get_optional(imx412->dev, "reset", in imx412_parse_hw_config()
929 if (IS_ERR(imx412->reset_gpio)) { in imx412_parse_hw_config()
930 dev_err(imx412->dev, "failed to get reset gpio %ld", in imx412_parse_hw_config()
931 PTR_ERR(imx412->reset_gpio)); in imx412_parse_hw_config()
932 return PTR_ERR(imx412->reset_gpio); in imx412_parse_hw_config()
936 imx412->inclk = devm_clk_get(imx412->dev, NULL); in imx412_parse_hw_config()
937 if (IS_ERR(imx412->inclk)) { in imx412_parse_hw_config()
938 dev_err(imx412->dev, "could not get inclk"); in imx412_parse_hw_config()
939 return PTR_ERR(imx412->inclk); in imx412_parse_hw_config()
942 rate = clk_get_rate(imx412->inclk); in imx412_parse_hw_config()
944 dev_err(imx412->dev, "inclk frequency mismatch"); in imx412_parse_hw_config()
950 imx412->supplies[i].supply = imx412_supply_names[i]; in imx412_parse_hw_config()
952 ret = devm_regulator_bulk_get(imx412->dev, in imx412_parse_hw_config()
954 imx412->supplies); in imx412_parse_hw_config()
968 dev_err(imx412->dev, in imx412_parse_hw_config()
976 dev_err(imx412->dev, "no link frequencies defined"); in imx412_parse_hw_config()
1023 struct imx412 *imx412 = to_imx412(sd); in imx412_power_on() local
1027 imx412->supplies); in imx412_power_on()
1033 gpiod_set_value_cansleep(imx412->reset_gpio, 0); in imx412_power_on()
1035 ret = clk_prepare_enable(imx412->inclk); in imx412_power_on()
1037 dev_err(imx412->dev, "fail to enable inclk"); in imx412_power_on()
1046 gpiod_set_value_cansleep(imx412->reset_gpio, 1); in imx412_power_on()
1048 imx412->supplies); in imx412_power_on()
1062 struct imx412 *imx412 = to_imx412(sd); in imx412_power_off() local
1064 clk_disable_unprepare(imx412->inclk); in imx412_power_off()
1066 gpiod_set_value_cansleep(imx412->reset_gpio, 1); in imx412_power_off()
1069 imx412->supplies); in imx412_power_off()
1076 * @imx412: pointer to imx412 device
1080 static int imx412_init_controls(struct imx412 *imx412) in imx412_init_controls() argument
1082 struct v4l2_ctrl_handler *ctrl_hdlr = &imx412->ctrl_handler; in imx412_init_controls()
1083 const struct imx412_mode *mode = imx412->cur_mode; in imx412_init_controls()
1092 ctrl_hdlr->lock = &imx412->mutex; in imx412_init_controls()
1096 imx412->exp_ctrl = v4l2_ctrl_new_std(ctrl_hdlr, in imx412_init_controls()
1104 imx412->again_ctrl = v4l2_ctrl_new_std(ctrl_hdlr, in imx412_init_controls()
1112 v4l2_ctrl_cluster(2, &imx412->exp_ctrl); in imx412_init_controls()
1114 imx412->vblank_ctrl = v4l2_ctrl_new_std(ctrl_hdlr, in imx412_init_controls()
1122 imx412->pclk_ctrl = v4l2_ctrl_new_std(ctrl_hdlr, in imx412_init_controls()
1128 imx412->link_freq_ctrl = v4l2_ctrl_new_int_menu(ctrl_hdlr, in imx412_init_controls()
1135 if (imx412->link_freq_ctrl) in imx412_init_controls()
1136 imx412->link_freq_ctrl->flags |= V4L2_CTRL_FLAG_READ_ONLY; in imx412_init_controls()
1138 imx412->hblank_ctrl = v4l2_ctrl_new_std(ctrl_hdlr, in imx412_init_controls()
1144 if (imx412->hblank_ctrl) in imx412_init_controls()
1145 imx412->hblank_ctrl->flags |= V4L2_CTRL_FLAG_READ_ONLY; in imx412_init_controls()
1148 dev_err(imx412->dev, "control init failed: %d", in imx412_init_controls()
1154 imx412->sd.ctrl_handler = ctrl_hdlr; in imx412_init_controls()
1167 struct imx412 *imx412; in imx412_probe() local
1171 imx412 = devm_kzalloc(&client->dev, sizeof(*imx412), GFP_KERNEL); in imx412_probe()
1172 if (!imx412) in imx412_probe()
1175 imx412->dev = &client->dev; in imx412_probe()
1181 v4l2_i2c_subdev_init(&imx412->sd, client, &imx412_subdev_ops); in imx412_probe()
1182 imx412->sd.internal_ops = &imx412_internal_ops; in imx412_probe()
1184 ret = imx412_parse_hw_config(imx412); in imx412_probe()
1186 dev_err(imx412->dev, "HW configuration is not supported"); in imx412_probe()
1190 mutex_init(&imx412->mutex); in imx412_probe()
1192 ret = imx412_power_on(imx412->dev); in imx412_probe()
1194 dev_err(imx412->dev, "failed to power-on the sensor"); in imx412_probe()
1199 ret = imx412_detect(imx412); in imx412_probe()
1201 dev_err(imx412->dev, "failed to find sensor: %d", ret); in imx412_probe()
1206 imx412->cur_mode = &supported_mode; in imx412_probe()
1207 imx412->vblank = imx412->cur_mode->vblank; in imx412_probe()
1209 ret = imx412_init_controls(imx412); in imx412_probe()
1211 dev_err(imx412->dev, "failed to init controls: %d", ret); in imx412_probe()
1216 imx412->sd.flags |= V4L2_SUBDEV_FL_HAS_DEVNODE; in imx412_probe()
1217 imx412->sd.entity.function = MEDIA_ENT_F_CAM_SENSOR; in imx412_probe()
1219 v4l2_i2c_subdev_set_name(&imx412->sd, client, name, NULL); in imx412_probe()
1222 imx412->pad.flags = MEDIA_PAD_FL_SOURCE; in imx412_probe()
1223 ret = media_entity_pads_init(&imx412->sd.entity, 1, &imx412->pad); in imx412_probe()
1225 dev_err(imx412->dev, "failed to init entity pads: %d", ret); in imx412_probe()
1229 ret = v4l2_async_register_subdev_sensor(&imx412->sd); in imx412_probe()
1231 dev_err(imx412->dev, in imx412_probe()
1236 pm_runtime_set_active(imx412->dev); in imx412_probe()
1237 pm_runtime_enable(imx412->dev); in imx412_probe()
1238 pm_runtime_idle(imx412->dev); in imx412_probe()
1243 media_entity_cleanup(&imx412->sd.entity); in imx412_probe()
1245 v4l2_ctrl_handler_free(imx412->sd.ctrl_handler); in imx412_probe()
1247 imx412_power_off(imx412->dev); in imx412_probe()
1249 mutex_destroy(&imx412->mutex); in imx412_probe()
1263 struct imx412 *imx412 = to_imx412(sd); in imx412_remove() local
1274 mutex_destroy(&imx412->mutex); in imx412_remove()
1282 { .compatible = "sony,imx412", .data = "imx412" },
1293 .name = "imx412",
1301 MODULE_DESCRIPTION("Sony imx412 sensor driver");