Lines Matching refs:imx335
131 struct imx335 { struct
270 static inline struct imx335 *to_imx335(struct v4l2_subdev *subdev) in to_imx335()
272 return container_of(subdev, struct imx335, sd); in to_imx335()
286 static int imx335_read_reg(struct imx335 *imx335, u16 reg, u32 len, u32 *val) in imx335_read_reg() argument
288 struct i2c_client *client = v4l2_get_subdevdata(&imx335->sd); in imx335_read_reg()
331 static int imx335_write_reg(struct imx335 *imx335, u16 reg, u32 len, u32 val) in imx335_write_reg() argument
333 struct i2c_client *client = v4l2_get_subdevdata(&imx335->sd); in imx335_write_reg()
355 static int imx335_write_regs(struct imx335 *imx335, in imx335_write_regs() argument
362 ret = imx335_write_reg(imx335, regs[i].address, 1, regs[i].val); in imx335_write_regs()
377 static int imx335_update_controls(struct imx335 *imx335, in imx335_update_controls() argument
382 ret = __v4l2_ctrl_s_ctrl(imx335->link_freq_ctrl, mode->link_freq_idx); in imx335_update_controls()
386 ret = __v4l2_ctrl_s_ctrl(imx335->hblank_ctrl, mode->hblank); in imx335_update_controls()
390 return __v4l2_ctrl_modify_range(imx335->vblank_ctrl, mode->vblank_min, in imx335_update_controls()
402 static int imx335_update_exp_gain(struct imx335 *imx335, u32 exposure, u32 gain) in imx335_update_exp_gain() argument
407 lpfr = imx335->vblank + imx335->cur_mode->height; in imx335_update_exp_gain()
410 dev_dbg(imx335->dev, "Set exp %u, analog gain %u, shutter %u, lpfr %u", in imx335_update_exp_gain()
413 ret = imx335_write_reg(imx335, IMX335_REG_HOLD, 1, 1); in imx335_update_exp_gain()
417 ret = imx335_write_reg(imx335, IMX335_REG_LPFR, 3, lpfr); in imx335_update_exp_gain()
421 ret = imx335_write_reg(imx335, IMX335_REG_SHUTTER, 3, shutter); in imx335_update_exp_gain()
425 ret = imx335_write_reg(imx335, IMX335_REG_AGAIN, 2, gain); in imx335_update_exp_gain()
428 imx335_write_reg(imx335, IMX335_REG_HOLD, 1, 0); in imx335_update_exp_gain()
447 struct imx335 *imx335 = in imx335_set_ctrl() local
448 container_of(ctrl->handler, struct imx335, ctrl_handler); in imx335_set_ctrl()
455 imx335->vblank = imx335->vblank_ctrl->val; in imx335_set_ctrl()
457 dev_dbg(imx335->dev, "Received vblank %u, new lpfr %u", in imx335_set_ctrl()
458 imx335->vblank, in imx335_set_ctrl()
459 imx335->vblank + imx335->cur_mode->height); in imx335_set_ctrl()
461 ret = __v4l2_ctrl_modify_range(imx335->exp_ctrl, in imx335_set_ctrl()
463 imx335->vblank + in imx335_set_ctrl()
464 imx335->cur_mode->height - in imx335_set_ctrl()
470 if (!pm_runtime_get_if_in_use(imx335->dev)) in imx335_set_ctrl()
474 analog_gain = imx335->again_ctrl->val; in imx335_set_ctrl()
476 dev_dbg(imx335->dev, "Received exp %u, analog gain %u", in imx335_set_ctrl()
479 ret = imx335_update_exp_gain(imx335, exposure, analog_gain); in imx335_set_ctrl()
481 pm_runtime_put(imx335->dev); in imx335_set_ctrl()
485 dev_err(imx335->dev, "Invalid control %d", ctrl->id); in imx335_set_ctrl()
550 static void imx335_fill_pad_format(struct imx335 *imx335, in imx335_fill_pad_format() argument
576 struct imx335 *imx335 = to_imx335(sd); in imx335_get_pad_format() local
578 mutex_lock(&imx335->mutex); in imx335_get_pad_format()
586 imx335_fill_pad_format(imx335, imx335->cur_mode, fmt); in imx335_get_pad_format()
589 mutex_unlock(&imx335->mutex); in imx335_get_pad_format()
606 struct imx335 *imx335 = to_imx335(sd); in imx335_set_pad_format() local
610 mutex_lock(&imx335->mutex); in imx335_set_pad_format()
613 imx335_fill_pad_format(imx335, mode, fmt); in imx335_set_pad_format()
621 ret = imx335_update_controls(imx335, mode); in imx335_set_pad_format()
623 imx335->cur_mode = mode; in imx335_set_pad_format()
626 mutex_unlock(&imx335->mutex); in imx335_set_pad_format()
641 struct imx335 *imx335 = to_imx335(sd); in imx335_init_pad_cfg() local
645 imx335_fill_pad_format(imx335, &supported_mode, &fmt); in imx335_init_pad_cfg()
656 static int imx335_start_streaming(struct imx335 *imx335) in imx335_start_streaming() argument
662 reg_list = &imx335->cur_mode->reg_list; in imx335_start_streaming()
663 ret = imx335_write_regs(imx335, reg_list->regs, in imx335_start_streaming()
666 dev_err(imx335->dev, "fail to write initial registers"); in imx335_start_streaming()
671 ret = __v4l2_ctrl_handler_setup(imx335->sd.ctrl_handler); in imx335_start_streaming()
673 dev_err(imx335->dev, "fail to setup handler"); in imx335_start_streaming()
678 ret = imx335_write_reg(imx335, IMX335_REG_MODE_SELECT, in imx335_start_streaming()
681 dev_err(imx335->dev, "fail to start streaming"); in imx335_start_streaming()
697 static int imx335_stop_streaming(struct imx335 *imx335) in imx335_stop_streaming() argument
699 return imx335_write_reg(imx335, IMX335_REG_MODE_SELECT, in imx335_stop_streaming()
712 struct imx335 *imx335 = to_imx335(sd); in imx335_set_stream() local
715 mutex_lock(&imx335->mutex); in imx335_set_stream()
717 if (imx335->streaming == enable) { in imx335_set_stream()
718 mutex_unlock(&imx335->mutex); in imx335_set_stream()
723 ret = pm_runtime_resume_and_get(imx335->dev); in imx335_set_stream()
727 ret = imx335_start_streaming(imx335); in imx335_set_stream()
731 imx335_stop_streaming(imx335); in imx335_set_stream()
732 pm_runtime_put(imx335->dev); in imx335_set_stream()
735 imx335->streaming = enable; in imx335_set_stream()
737 mutex_unlock(&imx335->mutex); in imx335_set_stream()
742 pm_runtime_put(imx335->dev); in imx335_set_stream()
744 mutex_unlock(&imx335->mutex); in imx335_set_stream()
755 static int imx335_detect(struct imx335 *imx335) in imx335_detect() argument
760 ret = imx335_read_reg(imx335, IMX335_REG_ID, 2, &val); in imx335_detect()
765 dev_err(imx335->dev, "chip id mismatch: %x!=%x", in imx335_detect()
779 static int imx335_parse_hw_config(struct imx335 *imx335) in imx335_parse_hw_config() argument
781 struct fwnode_handle *fwnode = dev_fwnode(imx335->dev); in imx335_parse_hw_config()
794 imx335->reset_gpio = devm_gpiod_get_optional(imx335->dev, "reset", in imx335_parse_hw_config()
796 if (IS_ERR(imx335->reset_gpio)) { in imx335_parse_hw_config()
797 dev_err(imx335->dev, "failed to get reset gpio %ld", in imx335_parse_hw_config()
798 PTR_ERR(imx335->reset_gpio)); in imx335_parse_hw_config()
799 return PTR_ERR(imx335->reset_gpio); in imx335_parse_hw_config()
803 imx335->supplies[i].supply = imx335_supply_name[i]; in imx335_parse_hw_config()
805 ret = devm_regulator_bulk_get(imx335->dev, in imx335_parse_hw_config()
807 imx335->supplies); in imx335_parse_hw_config()
809 dev_err(imx335->dev, "Failed to get regulators\n"); in imx335_parse_hw_config()
814 imx335->inclk = devm_clk_get(imx335->dev, NULL); in imx335_parse_hw_config()
815 if (IS_ERR(imx335->inclk)) { in imx335_parse_hw_config()
816 dev_err(imx335->dev, "could not get inclk"); in imx335_parse_hw_config()
817 return PTR_ERR(imx335->inclk); in imx335_parse_hw_config()
820 rate = clk_get_rate(imx335->inclk); in imx335_parse_hw_config()
822 dev_err(imx335->dev, "inclk frequency mismatch"); in imx335_parse_hw_config()
836 dev_err(imx335->dev, in imx335_parse_hw_config()
844 dev_err(imx335->dev, "no link frequencies defined"); in imx335_parse_hw_config()
888 struct imx335 *imx335 = to_imx335(sd); in imx335_power_on() local
892 imx335->supplies); in imx335_power_on()
901 gpiod_set_value_cansleep(imx335->reset_gpio, 0); in imx335_power_on()
903 ret = clk_prepare_enable(imx335->inclk); in imx335_power_on()
905 dev_err(imx335->dev, "fail to enable inclk"); in imx335_power_on()
914 gpiod_set_value_cansleep(imx335->reset_gpio, 1); in imx335_power_on()
915 regulator_bulk_disable(ARRAY_SIZE(imx335_supply_name), imx335->supplies); in imx335_power_on()
929 struct imx335 *imx335 = to_imx335(sd); in imx335_power_off() local
931 gpiod_set_value_cansleep(imx335->reset_gpio, 1); in imx335_power_off()
932 clk_disable_unprepare(imx335->inclk); in imx335_power_off()
933 regulator_bulk_disable(ARRAY_SIZE(imx335_supply_name), imx335->supplies); in imx335_power_off()
944 static int imx335_init_controls(struct imx335 *imx335) in imx335_init_controls() argument
946 struct v4l2_ctrl_handler *ctrl_hdlr = &imx335->ctrl_handler; in imx335_init_controls()
947 const struct imx335_mode *mode = imx335->cur_mode; in imx335_init_controls()
956 ctrl_hdlr->lock = &imx335->mutex; in imx335_init_controls()
960 imx335->exp_ctrl = v4l2_ctrl_new_std(ctrl_hdlr, in imx335_init_controls()
968 imx335->again_ctrl = v4l2_ctrl_new_std(ctrl_hdlr, in imx335_init_controls()
976 v4l2_ctrl_cluster(2, &imx335->exp_ctrl); in imx335_init_controls()
978 imx335->vblank_ctrl = v4l2_ctrl_new_std(ctrl_hdlr, in imx335_init_controls()
986 imx335->pclk_ctrl = v4l2_ctrl_new_std(ctrl_hdlr, in imx335_init_controls()
992 imx335->link_freq_ctrl = v4l2_ctrl_new_int_menu(ctrl_hdlr, in imx335_init_controls()
999 if (imx335->link_freq_ctrl) in imx335_init_controls()
1000 imx335->link_freq_ctrl->flags |= V4L2_CTRL_FLAG_READ_ONLY; in imx335_init_controls()
1002 imx335->hblank_ctrl = v4l2_ctrl_new_std(ctrl_hdlr, in imx335_init_controls()
1008 if (imx335->hblank_ctrl) in imx335_init_controls()
1009 imx335->hblank_ctrl->flags |= V4L2_CTRL_FLAG_READ_ONLY; in imx335_init_controls()
1012 dev_err(imx335->dev, "control init failed: %d", in imx335_init_controls()
1018 imx335->sd.ctrl_handler = ctrl_hdlr; in imx335_init_controls()
1031 struct imx335 *imx335; in imx335_probe() local
1034 imx335 = devm_kzalloc(&client->dev, sizeof(*imx335), GFP_KERNEL); in imx335_probe()
1035 if (!imx335) in imx335_probe()
1038 imx335->dev = &client->dev; in imx335_probe()
1041 v4l2_i2c_subdev_init(&imx335->sd, client, &imx335_subdev_ops); in imx335_probe()
1043 ret = imx335_parse_hw_config(imx335); in imx335_probe()
1045 dev_err(imx335->dev, "HW configuration is not supported"); in imx335_probe()
1049 mutex_init(&imx335->mutex); in imx335_probe()
1051 ret = imx335_power_on(imx335->dev); in imx335_probe()
1053 dev_err(imx335->dev, "failed to power-on the sensor"); in imx335_probe()
1058 ret = imx335_detect(imx335); in imx335_probe()
1060 dev_err(imx335->dev, "failed to find sensor: %d", ret); in imx335_probe()
1065 imx335->cur_mode = &supported_mode; in imx335_probe()
1066 imx335->vblank = imx335->cur_mode->vblank; in imx335_probe()
1068 ret = imx335_init_controls(imx335); in imx335_probe()
1070 dev_err(imx335->dev, "failed to init controls: %d", ret); in imx335_probe()
1075 imx335->sd.flags |= V4L2_SUBDEV_FL_HAS_DEVNODE; in imx335_probe()
1076 imx335->sd.entity.function = MEDIA_ENT_F_CAM_SENSOR; in imx335_probe()
1079 imx335->pad.flags = MEDIA_PAD_FL_SOURCE; in imx335_probe()
1080 ret = media_entity_pads_init(&imx335->sd.entity, 1, &imx335->pad); in imx335_probe()
1082 dev_err(imx335->dev, "failed to init entity pads: %d", ret); in imx335_probe()
1086 ret = v4l2_async_register_subdev_sensor(&imx335->sd); in imx335_probe()
1088 dev_err(imx335->dev, in imx335_probe()
1093 pm_runtime_set_active(imx335->dev); in imx335_probe()
1094 pm_runtime_enable(imx335->dev); in imx335_probe()
1095 pm_runtime_idle(imx335->dev); in imx335_probe()
1100 media_entity_cleanup(&imx335->sd.entity); in imx335_probe()
1102 v4l2_ctrl_handler_free(imx335->sd.ctrl_handler); in imx335_probe()
1104 imx335_power_off(imx335->dev); in imx335_probe()
1106 mutex_destroy(&imx335->mutex); in imx335_probe()
1120 struct imx335 *imx335 = to_imx335(sd); in imx335_remove() local
1131 mutex_destroy(&imx335->mutex); in imx335_remove()